User: andreas
Date: 00/10/24 23:19:14
Added: examples/tabbed.editor/src/com/madplanet/tabbedEditor
MainPane.java ResourceManagerFactoryImpl.java
ResourceManagerImpl.java
Log:
Added the new EJX/AWT example showing how to create
and manage a simple EJX/AWT GUI and how to use AWT
editors.
Revision Changes Path
1.1
ejx/examples/tabbed.editor/src/com/madplanet/tabbedEditor/MainPane.java
Index: MainPane.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package com.madplanet.tabbedEditor;
import java.awt.BorderLayout;
import java.awt.Component;
import java.beans.Customizer;
import java.beans.beancontext.BeanContextSupport;
import java.beans.beancontext.BeanContextChildComponentProxy;
import java.util.Vector;
import javax.swing.JTabbedPane;
import com.dreambean.awt.GenericCustomizer;
/**
* Class containing the Bean Context Support and
* the viewer GUI component.
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
* @version $Revision: 1.1 $
**/
public class MainPane
extends BeanContextSupport
implements BeanContextChildComponentProxy
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// There is only one Customizer for all the instances
private Customizer mCustomizer;
private String mFirstProperty = "";
private String mSecondProperty = "";
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
public MainPane() {
super();
}
// Public --------------------------------------------------------
/*
* There are the properties the Main Pane offer and which can
* then be set by GUI component defined by the Bean Context
* ATTENTION: All the properties in the BeanInfo XML file need
* here a public getter and setter method with the appropriate
* type.
*/
public String getFirstProperty() {
return mFirstProperty;
}
public void setFirstProperty( String pToSet ) {
mFirstProperty = pToSet;
}
public String getSecondProperty() {
return mSecondProperty;
}
public void setSecondProperty( String pToSet ) {
mSecondProperty = pToSet;
}
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 );
}
// BeanContextChildComponentProxy implementation -----------------
/**
* Creates and returns the GUI component which is used to display
* the properties and information of this instance by a Generic
* Customiser.
*
* @return GUI Component displaying this instances
* properties
**/
public Component getComponent() {
if( mCustomizer == null ) {
mCustomizer = new Viewer();
mCustomizer.setObject( this );
}
return (Component) mCustomizer;
}
/**
* Displays the component of the outer class
**/
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 >= 0 ) {
remove( lIndex );
mDataObjectList.removeElementAt( lIndex );
}
}
}
}
1.1
ejx/examples/tabbed.editor/src/com/madplanet/tabbedEditor/ResourceManagerFactoryImpl.java
Index: ResourceManagerFactoryImpl.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package com.madplanet.tabbedEditor;
import java.io.File;
import java.net.URL;
import javax.swing.filechooser.FileFilter;
import com.dreambean.ejx.ResourceManager;
import com.dreambean.ejx.ResourceManagerFactory;
/**
* ResourceManagerFactory implemenation which allows EJX
* plugin to select an existing file or create one in the
* given directory.
* <BR>
* The purpose of this class is to deliver a file filter to
* select a file and to create a file manage implemenation
* when the file is selected or a directory to put the new
* file into.
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
* @version $Revision: 1.1 $
**/
public class ResourceManagerFactoryImpl
extends FileFilter
implements ResourceManagerFactory
{
// Public --------------------------------------------------------
// FileFilter implementation -------------------------------------
public boolean accept(File f)
{
return f.getName().equals( "tabbed.editor.xml" ) || f.isDirectory();
}
public String getDescription() {
return toString();
}
// ResourceManagerFactory implementation -----------------------------
public ResourceManager createResourceManager() {
return new ResourceManagerImpl( this );
}
public FileFilter getFileFilter() {
return this;
}
public String toString() {
return "Tab Pane and Editor";
}
}
1.1
ejx/examples/tabbed.editor/src/com/madplanet/tabbedEditor/ResourceManagerImpl.java
Index: ResourceManagerImpl.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package com.madplanet.tabbedEditor;
import java.awt.BorderLayout;
import java.awt.Component;
import java.beans.beancontext.BeanContextServicesSupport;
import java.net.URL;
import javax.swing.JTabbedPane;
import com.dreambean.ejx.ResourceManager;
import com.dreambean.ejx.ResourceManagerFactory;
/**
* ResourceManager handles the load and save of a given file
* and create a new GUI component to display in EJX
* when EJX is asking for.
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
* @version $Revision: 1.1 $
**/
public class ResourceManagerImpl
extends BeanContextServicesSupport
implements ResourceManager
{
// Attributes ----------------------------------------------------
/** The factory which created this instance **/
private ResourceManagerFactory mFactory;
// Constructors --------------------------------------------------
/**
* Creates this file manager and store the Factory created
* this instance
*
* @param pCaller File Manager Factory
created this instance
**/
ResourceManagerImpl( ResourceManagerFactory pCaller ) {
mFactory = pCaller;
}
// Public --------------------------------------------------------
// ResourceManager implementation ------------------------------------
public boolean isChanged() {
return true;
}
public void createNew() {
}
public void load( URL pResource )
throws Exception
{
}
public void save( URL pResource )
throws Exception
{
}
public URL getResource() {
return null;
}
public void setResource( URL pResource ) {
}
public ResourceManagerFactory getFactory() {
return mFactory;
}
// BeanContextChildComponentProxy implementation -----------------
public Component getComponent() {
// Create the Property Container and return its GUI component
return new MainPane().getComponent();
}
}