KickJava   Java API By Example, From Geeks To Geeks.

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


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: CreateInstanceAction.java,v 1.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

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

50 public class CreateInstanceAction
51   implements MenuItem, DialogAction
52 {
53     
54     //==================================================================
55
//
56
// Internal states.
57
//
58
//==================================================================
59

60     /** The selected type. */
61     protected TreeChooserBox type_;
62     
63     /** The controller desc (String with Julia). */
64     protected LabelBox name_, controllerDesc_, contentDesc_;
65     
66     /** The ContextContainer where adding the type. */
67     protected ContextContainer cc_;
68     
69     //==================================================================
70
//
71
// No constructor.
72
//
73
//==================================================================
74

75     //==================================================================
76
//
77
// Internal methods.
78
//
79
//==================================================================
80

81     /**
82      * Create a box containing all the box to specify all the params.
83      */

84     protected void createBox(DialogBox dialogBox, Component treeComponent) {
85         name_ = new LabelBox("Name");
86         dialogBox.addElementBox(name_);
87         type_ = new TreeChooserBox("Type", treeComponent);
88         dialogBox.addElementBox(type_);
89         controllerDesc_ = new LabelBox("Controller Desc");
90         dialogBox.addElementBox(controllerDesc_);
91         contentDesc_ = new LabelBox("Content Desc");
92         dialogBox.addElementBox(contentDesc_);
93     }
94     
95     //==================================================================
96
//
97
// Public methods for ExtendedActionListener interface.
98
//
99
//==================================================================
100

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

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

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

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

130     public void executeAction() throws Exception JavaDoc {
131         Type type = null;
132         if(type_.getObject()!=null && Type.class.isAssignableFrom(type_.getObject().getClass())) {
133            type = (Type)type_.getObject();
134         } else {
135            throw new Exception JavaDoc("You must select an org.objectweb.fractal.api.Type object !");
136         }
137         String JavaDoc name = name_.getLabel();
138         String JavaDoc controllerDesc = controllerDesc_.getLabel();
139         String JavaDoc contentDesc = contentDesc_.getLabel();
140         GenericFactory gf = FcExplorer.getGenericFactory(FcExplorer.getBootstrapComponent());
141         cc_.addEntry(name, gf.newFcInstance(type, controllerDesc, contentDesc));
142     }
143 }
Popular Tags