KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > menu > CreateComponentTypeAction


1 /*====================================================================
2  
3  Objectweb Browser Framework
4  Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5  Contact: openccm@objectweb.org
6  
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or any later version.
11  
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16  
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  USA
21  
22  Initial developer(s): Jerome Moroy.
23  Contributor(s): ______________________________________.
24  
25  ---------------------------------------------------------------------
26  $Id: CreateComponentTypeAction.java,v 1.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.fractal.explorer.menu;
30
31 import java.util.List JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 import org.objectweb.fractal.api.Component;
35 import org.objectweb.fractal.api.type.InterfaceType;
36 import org.objectweb.fractal.api.type.TypeFactory;
37 import org.objectweb.fractal.explorer.FcExplorer;
38 import org.objectweb.util.explorer.api.MenuItem;
39 import org.objectweb.util.explorer.api.MenuItemTreeView;
40 import org.objectweb.util.explorer.api.TreeView;
41 import org.objectweb.util.explorer.core.common.api.ContextContainer;
42 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
43 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
44 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
45 import org.objectweb.util.explorer.swing.gui.lib.ExtendedTreeChooserBox;
46 import org.objectweb.util.explorer.swing.gui.lib.LabelBox;
47
48 /**
49  * This action allows to create a new component type.
50  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
51  * @version 0.1
52  */

53 public class CreateComponentTypeAction
54   implements MenuItem,
55              DialogAction
56 {
57     //==================================================================
58
//
59
// Internal states.
60
//
61
//==================================================================
62

63     /** The label box. */
64     protected LabelBox name_;
65     
66     /** The tree chooser box. */
67     protected ExtendedTreeChooserBox extendedTreeChooserBox_;
68     
69     /** The context container to use. */
70     protected ContextContainer cc_;
71     
72     //==================================================================
73
//
74
// No constructor.
75
//
76
//==================================================================
77

78     //==================================================================
79
//
80
// Internal methods.
81
//
82
//==================================================================
83

84     /**
85      * Create a box containing all the box to specify all the params.
86      */

87     protected void createBox(DialogBox dialogBox, Component treeComponent) {
88         name_= new LabelBox("Name");
89         dialogBox.addElementBox(name_);
90         extendedTreeChooserBox_ = new ExtendedTreeChooserBox("Interface Type",treeComponent, dialogBox);
91         dialogBox.addElementBox(extendedTreeChooserBox_);
92     }
93     
94     //==================================================================
95
//
96
// Public methods for MenuItem interface.
97
//
98
//==================================================================
99

100     /* (non-Javadoc)
101      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
102      */

103     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc {
104         cc_ = (ContextContainer)e.getSelectedObject();
105         
106         DialogBox dialog = new DefaultDialogBox("Create a new component type");
107         createBox(dialog, e.getTree().duplicate());
108         dialog.setValidateAction(this);
109         dialog.show();
110     }
111     
112     /* (non-Javadoc)
113      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.TreeView)
114      */

115     public int getStatus(TreeView treeView) {
116         return MenuItem.ENABLED_STATUS;
117     }
118     
119     //==================================================================
120
//
121
// Public methods for DialogAction interface.
122
//
123
//==================================================================
124

125     /* (non-Javadoc)
126      * @see org.objectweb.util.explorer.swing.gui.api.DialogAction#executeAction()
127      */

128     public void executeAction() throws Exception JavaDoc {
129         TypeFactory typeFactory = FcExplorer.getTypeFactory(FcExplorer.getBootstrapComponent());
130         String JavaDoc name = name_.getLabel();
131         List JavaDoc l = new Vector JavaDoc();
132         Object JavaDoc[] objects = extendedTreeChooserBox_.getObjects();
133         for (int i=0 ; i < objects.length ; i++) {
134             if (objects[i] != null && objects[i] instanceof InterfaceType) {
135                 l.add((InterfaceType)objects[i]);
136             }
137         }
138         cc_.addEntry(name,typeFactory.createFcType((InterfaceType[])l.toArray(new InterfaceType[0])));
139     }
140     
141 }
Popular Tags