⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch13s101.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
📖 第 1 页 / 共 3 页
字号:
       and not the Java AWT!</p><p>The AWT provides you with the following opportunities: </p><div class="orderedlist"><ol type="1"><li><p><a name="d0e11594"></a>Customizers for your Beans</p></li><li><p><a name="d0e11597"></a>Property Editors to edit or select properties</p></li></ol></div><p>       This seems to be simple but combining them together with the Java Bean Support and ordinary Swing coding
       leads to advanced GUIs like the actual version of EJX used in jBoss (I am not taking about the lack of User
       guidance but about the abilities of the GUI to display and edit the data). </p><p> 
       My biggest problem to understand EJX/AWT was that you have to deal with EJX, AWT, Java Bean Support,
       XML and Swing coding. Therefore I started from the simplest example to understand each component, its
       function and how to use it. In the "Getting-Started" How To I showed how to create an EJX plugin and then
       create a basic Bean GUI. Now I go a step further to dynamically manage GUI components, use of more BeanInfo
       features and to edit properties with the AWT property editors. So let's start it! </p></div><div class="section"><a name="d0e11604"></a><div class="titlepage"><div><h4 class="title"><a name="d0e11604"></a>    Tabbed Panes and Editors</h4></div></div><div class="section"><a name="d0e11607"></a><div class="titlepage"><div><h5 class="title"><a name="d0e11607"></a>Goals</h5></div></div><p>       From the last example of the first How To create and remove GUI Components (Tabbed Panes) dynamically and
       edit the properties of the data instance with the AWT editors. </p></div><div class="section"><a name="d0e11612"></a><div class="titlepage"><div><h5 class="title"><a name="d0e11612"></a>Design</h5></div></div><p>       First of all I want correct I mistake in the previous example. In the MainPane class it is said that getComponent()
       is implemented because of BeanContextChildComponentProxy which is not implemented in the class but it works
       because the caller does not relay on this fact. But in this example I fixed this. The question but still remains why
       it should (will maybe be explained later). </p><p>       This example is really not a good example how to use EJX but it shows how to use EJX/AWT. The idea is to use
       a tabbed pane to display different views in our EJX frame. In addition the user can create and remove the tabbed
       pane as long as there is at least one left. And last but not least the user should be able to select a value through
       an editor instead of a plain input field. </p><p>       As we saw in the last example the initial GUI component to show the plugin is created in the ResourceManager
       on the getComponent() call which is called by the BeanContext structure we use. But instead of create a Panel
       which just keeps the GUI of the plugin we create now a viewer of the plugin to display itself. This makes the
       design more flexible because it is now defined in the Viewer instead of the ResourceManager where it does not
       belong. Now the viewer is an inner class because it is so closely related to its outer component that it makes
       sense to be there. </p><p>       The construct following is a little bit ugly and should not be MADE this way but it is enough for us. 
       The ResourceManager getComponent() now calls the MainPane's getComponent() method and this instantiate its
       viewer and returns this Viewer as the GUI component to be shown. </p><p>       When the users now hits the create a new Tab or remove this tab the appropriate method is called (by the
       BeanContext) and it will create a new MainPane instance and adds its also created Viewer instance as a new
       Tab to the tabbed pan or remove the actual shown tab from the tabbed pane. 
       As you can see above the buttons we have a text input field and a drop down box letting the user select between
       two items. Both are AWT editors. </p></div><div class="section"><a name="d0e11625"></a><div class="titlepage"><div><h5 class="title"><a name="d0e11625"></a>Implementation</h5></div></div><p>       First lets have a look at the changes in the ResourceManager where the getComponent() just instanciate the
       MainPane and returns its GUI component.</p><pre class="programlisting">              public Component getComponent() { 
	         // Create the Property Container and return its GUI component
                 return new MainPane().getComponent(); 
	      } 
	      </pre><p>       Now let's look at the new BeanInfo description of the MainPane: </p><pre class="programlisting">    
              &lt;bean class="com.madplanet.tabbedEditor.MainPane"
              displayname="Tab Pane and Editor's Main Pane"
              iconcolor16="/images/container.gif"&gt; &lt;property
              name="FirstProperty" class="java.lang.String"
              displayname="First Property"
              propertyeditor="com.dreambean.awt.editors.TextEditor"/&gt;
              &lt;property name="SecondProperty"
              class="java.lang.String" displayname="Second
              Property"
              propertyeditor="com.madplanet.tabbedEditor.editors.SecondPropertyEditor"/&gt;
              &lt;method name="createTab" displayname="Create a new
              Tab"&gt; &lt;parameter displayname="Title"/&gt; &lt;/method&gt;
              &lt;method name="removeTab" displayname="Remove this
              Tab"&gt; &lt;/method&gt; &lt;/bean&gt; 
              </pre><p>       As you can see there are property editors settings for the first and second property and the second
       property uses its own editors. In addition you have methods listed which appears as buttons in the
       GUI because we use the GenericCustomizer. </p><p>       The new editor is just a simple subclass of the AWT TagsEditor defining what items it has to show and to what
       value the item relate to (you can use any Java Object you like): </p><pre class="programlisting">              package com.madplanet.tabbedEditor.editors; 
              import com.dreambean.awt.editors.TagsEditor; 
              /** * Editor to select the Second Property in a DD - editor */
              public class SecondPropertyEditor extends TagsEditor
              { // Constructors
              --------------------------------------------------
                public SecondPropertyEditor() { 
            		super(new String[] {"First Selection","Second Selection"}, 
         		new Object []{"First", "Second"}); 
	        } 
	      } </pre><p>       And as "Grande Finale" we come to the heart of the plugin to the MainPane class. </p><p>                The new viewer class is an inner class to the MainPane and creates a GUI to display the
                instance of its outer class instance. It keeps a list of outer class instances to find the
                index of the tab to be removed. The setObject() creates a new tab and memorize the given
                outer class. The removeTab() looks for the given outer instance and removes its related
                tab (by this index). </p><pre class="programlisting">                      public class Viewer extends JTabbedPane implements Customizer { // Attributes
                      ---------------------------------------------------
                      private Vector mDataObjectList = new Vector(); // Customizer implementation
                      ------------------------------------
                      public void setObject( Object pDataObject ) { 
				// Init UI
    	                  addTab( "Main", new GenericCustomizer( pDataObject ) );
	                  mDataObjectList.addElement( pDataObject ); 
			  } 
			  /** * Removes the given Tab with the given Data Object * from the
                      Tabbed Pane * * @param pDataObject Tab with this Data
                      Object has to be removed if found **/ 

			  public void removeTab(Object pDataObject ) { 
				int lIndex = mDataObjectList.indexOf(
                         pDataObject ); 
				if( lIndex &gt;= 0 ) { 
					remove( lIndex );
     		            mDataObjectList.removeElementAt( lIndex ); 
				} 
			  } 
			 } </pre><p>                These are the new methods (already defined in the BeanInfo see above) which are called if
                the appropriate button is pressed. </p><pre class="programlisting">                      public void createTab( String pTitle ) throws Exception { 
			    System.out.println("Create new Tab with title: " + pTitle);
				MainPane lNewPane = new MainPane();
                        lNewPane.mCustomizer = mCustomizer;
                        lNewPane.mCustomizer.setObject(
                        lNewPane ); 
			  } 
			  public void removeTab() {
     	                 System.out.println( "Remove this tab"); 
				 ( (Viewer) mCustomizer ).removeTab(this ); 
			  }
                      </pre></div></div><div class="section"><a name="d0e11652"></a><div class="titlepage"><div><h4 class="title"><a name="d0e11652"></a> Remarks</h4></div></div><p> 
       This is more ore less EJX and AWT. But it does not end here. The power of EJX lays in the BeanContext and
       how you combine EJX, BeanContext and AWT. You maybe think what's about XML and we will come to XML
       soon but (in my opinion) this is not a core part of EJX and AWT just use it but just as the name of the EJX base
       classes said they manage resources (or earlier just files). Therefore it must be a way do deal with resources and
       especially with XML resources. </p></div></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch13s98.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s98.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch13s126.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s126.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -