KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > 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.1 2004/04/28 15:04:14 moroy Exp $
27  ====================================================================*/

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

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

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

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

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

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

103     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc{
104         
105         cc_ = (ContextContainer)e.getSelectedObject();
106         TreeProvider treeProvider = new DefaultTreeProvider();
107         DynamicTree tree = treeProvider.createDynamicTree(e);
108            
109         DialogBox dialog = new DefaultDialogBox("Create a new Instance");
110         createBox(dialog, tree);
111         dialog.setValidateAction(this);
112         dialog.show();
113     }
114     
115     /**
116      * @see org.objectweb.util.browser.api.MenuItem#isActive(org.objectweb.util.browser.gui.common.TreeView)
117      */

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

128     /**
129      * Executes an action
130      */

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