KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > menu > CreateInterfaceTypeAction


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: CreateInterfaceTypeAction.java,v 1.1 2004/04/20 16:37:27 moroy Exp $
27  ====================================================================*/

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

48 public class CreateInterfaceTypeAction
49   implements MenuItem,
50              DialogAction
51 {
52     //==================================================================
53
//
54
// Internal states.
55
//
56
//==================================================================
57

58     /** The boolean boxes. */
59     protected BooleanBox isClientBox_, isOptionalBox_, isCollectionBox_;
60     
61     /** The label boxes. */
62     protected LabelBox nameBox_, signatureBox_;
63     
64     /** The context container where adding the type. */
65     protected ContextContainer cc_;
66     
67     /** The type factory used to create a type. */
68     protected TypeFactory typeFactory_;
69     
70     //==================================================================
71
//
72
// No constructor.
73
//
74
//==================================================================
75

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

82     /**
83      * Creates a box containing all the box to specify all the params
84      */

85     protected void createBox(DialogBox dialogBox) {
86         nameBox_ = new LabelBox("Name");
87         dialogBox.addElementBox(nameBox_);
88         signatureBox_ = new LabelBox("Signature");
89         dialogBox.addElementBox(signatureBox_);
90         isClientBox_ = new BooleanBox("Type","Client","Server",true);
91         dialogBox.addElementBox(isClientBox_);
92         isOptionalBox_ = new BooleanBox("Contingency","Optional","Mandatory",true);
93         dialogBox.addElementBox(isOptionalBox_);
94         isCollectionBox_ = new BooleanBox("Cardinality","Collection","Single",true);
95         dialogBox.addElementBox(isCollectionBox_);
96     }
97     
98     //==================================================================
99
//
100
// Public methods for ExtendedActionListener interface.
101
//
102
//==================================================================
103

104     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc {
105         typeFactory_ = FcBrowser.getTypeFactory(FcBrowser.getBootstrapComponent());
106         cc_ = (ContextContainer)e.getSelectedObject();
107         DialogBox dialog = new DefaultDialogBox("Create a new interface type");
108         createBox(dialog);
109         dialog.setValidateAction(this);
110         dialog.show();
111     }
112     
113     /**
114      * @see org.objectweb.util.browser.api.MenuItem#isActive(org.objectweb.util.browser.gui.common.TreeView)
115      */

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

126     /**
127      * Executes an action.
128      */

129     public void executeAction() throws Exception JavaDoc {
130         String JavaDoc name = nameBox_.getLabel();
131         String JavaDoc signature = signatureBox_.getLabel();
132         boolean isClient = isClientBox_.getValue();
133         boolean isOptional = isOptionalBox_.getValue();
134         boolean isCollection = isCollectionBox_.getValue();
135         cc_.addEntry(name,typeFactory_.createFcItfType(name,signature,isClient,isOptional,isCollection));
136     }
137     
138 }
Popular Tags