KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > 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.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.type.TypeFactory;
32 import org.objectweb.fractal.explorer.FcExplorer;
33 import org.objectweb.util.explorer.api.MenuItem;
34 import org.objectweb.util.explorer.api.MenuItemTreeView;
35 import org.objectweb.util.explorer.api.TreeView;
36 import org.objectweb.util.explorer.core.common.api.ContextContainer;
37 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
38 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
39 import org.objectweb.util.explorer.swing.gui.lib.BooleanBox;
40 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
41 import org.objectweb.util.explorer.swing.gui.lib.LabelBox;
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     /* (non-Javadoc)
105      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
106      */

107     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc {
108         typeFactory_ = FcExplorer.getTypeFactory(FcExplorer.getBootstrapComponent());
109         cc_ = (ContextContainer)e.getSelectedObject();
110         DialogBox dialog = new DefaultDialogBox("Create a new interface type");
111         createBox(dialog);
112         dialog.setValidateAction(this);
113         dialog.show();
114     }
115     
116     /* (non-Javadoc)
117      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.TreeView)
118      */

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

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

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