You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2018/12/29 17:12:12 UTC

[royale-asjs] branch develop updated: refactor "showContent" to a property called "selectedContent" so users can set up in MXML

This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new d611e68  refactor "showContent" to a property called "selectedContent" so users can set up in MXML
d611e68 is described below

commit d611e68a7fd590212871b45b2dbc6953b28c5005
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Sat Dec 29 18:12:04 2018 +0100

    refactor "showContent" to a property called "selectedContent" so users can set up in MXML
---
 .../TourDeJewel/src/main/royale/MainContent.mxml   |  8 ++---
 .../src/main/royale/TabBarPlayGround.mxml          |  6 ++--
 .../ExampleAndSourceCodeTabbedSectionContent.as    |  4 +--
 .../apache/royale/jewel/ApplicationMainContent.as  | 36 ++++++++++++++++++++--
 .../org/apache/royale/jewel/TabBarContent.as       | 34 ++++++++++++++++++--
 .../main/royale/org/apache/royale/jewel/Wizard.as  |  8 ++---
 .../org/apache/royale/jewel/WizardContent.as       | 36 ++++++++++++++++++++--
 7 files changed, 109 insertions(+), 23 deletions(-)

diff --git a/examples/royale/TourDeJewel/src/main/royale/MainContent.mxml b/examples/royale/TourDeJewel/src/main/royale/MainContent.mxml
index 9abc6fa..b06eff2 100644
--- a/examples/royale/TourDeJewel/src/main/royale/MainContent.mxml
+++ b/examples/royale/TourDeJewel/src/main/royale/MainContent.mxml
@@ -31,7 +31,7 @@ limitations under the License.
             private function changeHandler(event:Event):void
             {
                 var item:NavigationLinkVO = (event.target as Navigation).selectedItem as NavigationLinkVO;
-                main.showContent(item.href);
+                main.selectedContent = item.href;
                 if(!drawer.fixed)
                     drawer.close();
             }
@@ -44,7 +44,7 @@ limitations under the License.
 
             private function goToHome():void
             {
-                main.showContent("welcome_panel");
+                main.selectedContent = "welcome_panel";
             }
         ]]>
     </fx:Script>
@@ -113,8 +113,8 @@ limitations under the License.
         </j:TopAppBarRow>
     </j:TopAppBar>
 
-    <j:ApplicationMainContent id="main" hasTopAppBar="true" className="mainContent">
-        <local:WelcomeSection name="welcome_panel" isSelected="true"/>
+    <j:ApplicationMainContent id="main" hasTopAppBar="true" className="mainContent" selectedContent = "welcome_panel">
+        <local:WelcomeSection name="welcome_panel"/>
         <local:AlertPlayGround name="alert_panel"/>
         <local:ButtonPlayGround name="button_panel"/>
         <local:ImagePlayGround name="image_panel"/>
diff --git a/examples/royale/TourDeJewel/src/main/royale/TabBarPlayGround.mxml b/examples/royale/TourDeJewel/src/main/royale/TabBarPlayGround.mxml
index 014e53f..32c1ef4 100644
--- a/examples/royale/TourDeJewel/src/main/royale/TabBarPlayGround.mxml
+++ b/examples/royale/TourDeJewel/src/main/royale/TabBarPlayGround.mxml
@@ -31,7 +31,7 @@ limitations under the License.
             private function changeHandler(event:Event):void
             {
                 var item:TabBarButtonVO = (event.target as TabBar).selectedItem as TabBarButtonVO;
-                tabcontent.showContent(item.href);
+                tabcontent.selectedContent = item.href;
             }
 
             private var _tabBarNavigation:ArrayList = new ArrayList([
@@ -62,8 +62,8 @@ limitations under the License.
 						<js:ConstantBinding sourcePropertyName="tabBarNavigation" destinationPropertyName="dataProvider"/>
 					</j:beads>
 				</j:TabBar>
-				<j:TabBarContent id="tabcontent">
-					<j:SectionContent name="tab1" isSelected="true">
+				<j:TabBarContent id="tabcontent" selectedContent="tab1">
+					<j:SectionContent name="tab1">
 						<j:Label text="Tab 1"/>
 					</j:SectionContent>
 					<j:SectionContent name="tab2">
diff --git a/examples/royale/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as b/examples/royale/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as
index f9555b3..2cb8e5b 100644
--- a/examples/royale/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as
+++ b/examples/royale/TourDeJewel/src/main/royale/components/ExampleAndSourceCodeTabbedSectionContent.as
@@ -51,7 +51,6 @@ package components
 
             exampleTab = new SectionContent();
             exampleTab.name = "exampleTab";
-            exampleTab.isSelected = true;
             contentArea = exampleTab;
 
             addEventListener("initComplete", initCompleteHandler);
@@ -111,6 +110,7 @@ package components
             tabcontent = new TabBarContent();
             tabcontent.addElement(exampleTab);
             tabcontent.addElement(sourceCodeTab);
+            tabcontent.selectedContent = "exampleTab";
             $addElement(tabcontent);
             
             service = new GitHubService();
@@ -121,7 +121,7 @@ package components
         private function changeHandler(event:Event):void
         {
             var item:TabBarButtonVO = (event.target as TabBar).selectedItem as TabBarButtonVO;
-            tabcontent.showContent(item.href);
+            tabcontent.selectedContent = item.href;
             if(sourceCodeTab.isSelected && sourceCodeMXMLText.text == "")
             {
                 service.getContent();
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/ApplicationMainContent.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/ApplicationMainContent.as
index d3e82f6..23fae29 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/ApplicationMainContent.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/ApplicationMainContent.as
@@ -82,6 +82,7 @@ package org.apache.royale.jewel
             }
 		}
 
+		private var _selectedContent:String;
 		/**
 		 *  shows a concrete content and hides the rest
 		 * 
@@ -92,15 +93,29 @@ package org.apache.royale.jewel
 		 *  @playerversion AIR 2.6
 		 *  @productversion Royale 0.9.4
 		 */
-        public function showContent(name:String):void
+		public function get selectedContent():String
         {
+			return _selectedContent;
+		}
+        public function set selectedContent(name:String):void
+        {
+			if(_selectedContent != name)
+			{
+				_selectedContent = name;
+			 
+				selectContent();
+			}
+        }
+
+		public function selectContent():void
+		{
 			try
 			{
 				for (var i:int = 0; i < numElements; i++)
 				{
 					var content:ISelectableContent = getElementAt(i) as ISelectableContent;
 					
-					if(content.name == name)
+					if(content.name == _selectedContent)
 					{
 						content.isSelected = true;
 					}
@@ -114,7 +129,7 @@ package org.apache.royale.jewel
 			{
 				throw new Error ("One or more content in ApplicationMainContent is not implementing ISelectableContent interface.");	
 			}
-        }
+		}
 
         /**
          * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
@@ -124,5 +139,20 @@ package org.apache.royale.jewel
         {
 			return addElementToWrapper(this, 'main');
         }
+
+		/**
+		 *  The method called when added to a parent.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 */
+		override public function addedToParent():void
+		{
+			super.addedToParent();
+			
+			selectContent();
+		}
 	}
 }
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/TabBarContent.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/TabBarContent.as
index 6b2dd44..7359542 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/TabBarContent.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/TabBarContent.as
@@ -53,6 +53,7 @@ package org.apache.royale.jewel
             typeNames = "jewel tabbarcontent";
 		}
 
+		private var _selectedContent:String;
 		/**
 		 *  shows a concrete content and hides the rest
 		 * 
@@ -63,15 +64,29 @@ package org.apache.royale.jewel
 		 *  @playerversion AIR 2.6
 		 *  @productversion Royale 0.9.4
 		 */
-        public function showContent(name:String):void
+		public function get selectedContent():String
         {
+			return _selectedContent;
+		}
+        public function set selectedContent(name:String):void
+        {
+			if(_selectedContent != name)
+			{
+				_selectedContent = name;
+
+				selectContent();
+			}
+		}
+
+		public function selectContent():void
+		{
 			try
 			{
 				for (var i:int = 0; i < numElements; i++)
 				{
 					var content:ISelectableContent = getElementAt(i) as ISelectableContent;
 					
-					if(content.name == name)
+					if(content.name == _selectedContent)
 					{
 						content.isSelected = true;
 					}
@@ -95,5 +110,20 @@ package org.apache.royale.jewel
         {
 			return addElementToWrapper(this, 'div');
         }
+
+		/**
+		 *  The method called when added to a parent.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 */
+		override public function addedToParent():void
+		{
+			super.addedToParent();
+			
+			selectContent();
+		}
 	}
 }
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Wizard.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Wizard.as
index ab0626c..848b5b2 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Wizard.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Wizard.as
@@ -82,15 +82,11 @@ package org.apache.royale.jewel
 		 * 
 		 * @param steName, that is the "id" of the content (the WizardPage) to activate
 		 * 
-		 * @see org.apache.royale.jewel.WizardContent.showContent
+		 * @see org.apache.royale.jewel.WizardContent.selectedContent
 		 */
 		public function showPage(stepName:String):void
 		{
-			// if(currentStep.name != stepName)
-			// {
-			// 	currentStep = findStepByName(stepName);
-			// }
-			content.showContent(stepName);
+			content.selectedContent = stepName;
 		}
 
 		public function findStepByName(name:String):WizardStep
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/WizardContent.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/WizardContent.as
index 3e52fbe..e7b1831 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/WizardContent.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/WizardContent.as
@@ -54,6 +54,7 @@ package org.apache.royale.jewel
             typeNames = "jewel wizardcontent";
 		}
 
+		private var _selectedContent:String;
 		/**
 		 *  shows a concrete content and hides the rest
 		 * 
@@ -64,15 +65,29 @@ package org.apache.royale.jewel
 		 *  @playerversion AIR 2.6
 		 *  @productversion Royale 0.9.4
 		 */
-        public function showContent(name:String):void
+		public function get selectedContent():String
         {
+			return _selectedContent;
+		}
+        public function set selectedContent(name:String):void
+        {
+			if(_selectedContent != name)
+			{
+				_selectedContent = name;
+
+				selectContent();
+			}
+		}
+
+		public function selectContent():void
+		{	
 			try
 			{
 				for (var i:int = 0; i < numElements; i++)
 				{
 					var content:ISelectableContent = getElementAt(i) as ISelectableContent;
 					
-					if(content.name == name)
+					if(content.name == _selectedContent)
 					{
 						content.isSelected = true;
 					}
@@ -84,7 +99,7 @@ package org.apache.royale.jewel
 			}
 			catch (error:Error)
 			{
-				throw new Error ("One or more content in TabBarContent is not implementing ISelectableContent interface.");	
+				throw new Error ("One or more content in WizardContent is not implementing ISelectableContent interface.");	
 			}
         }
 
@@ -96,5 +111,20 @@ package org.apache.royale.jewel
         {
 			return addElementToWrapper(this, 'div');
         }
+
+		/**
+		 *  The method called when added to a parent.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 */
+		override public function addedToParent():void
+		{
+			super.addedToParent();
+			
+			selectContent();
+		}
 	}
 }