KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CosNaming > RenameBinding


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
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 package org.objectweb.openccm.explorer.CosNaming;
27
28 import org.objectweb.util.explorer.api.Entry;
29 import org.objectweb.util.explorer.api.MenuItem;
30 import org.objectweb.util.explorer.api.MenuItemTreeView;
31 import org.objectweb.util.explorer.api.Tree;
32 import org.objectweb.util.explorer.api.TreeView;
33 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
34 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
35 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
36 import org.objectweb.util.explorer.swing.gui.lib.LabelBox;
37 import org.omg.CosNaming.NamingContextExt JavaDoc;
38
39 /**
40  * Renamed the binding.
41  *
42  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
43  * @version 0.1
44  */

45 public class RenameBinding
46   implements MenuItem, DialogAction
47 {
48
49     //==================================================================
50
//
51
// Internal states.
52
//
53
//==================================================================
54

55     protected LabelBox bindingName_ = null;
56     
57     protected String JavaDoc currentBindingName_ = null;
58     
59     protected org.omg.CORBA.Object JavaDoc bindingObject_ = null;
60
61     protected NamingContextExt JavaDoc naming_ = null;
62
63     protected Tree tree_ = null;
64
65     //==================================================================
66
//
67
// No constructor.
68
//
69
//==================================================================
70

71     //==================================================================
72
//
73
// Internal methods.
74
//
75
//==================================================================
76

77     /**
78      * Binds the object into the current NameService
79      */

80     protected void bind(NamingContextExt JavaDoc naming, String JavaDoc id, org.omg.CORBA.Object JavaDoc o) {
81         try {
82             naming.rebind(naming.to_name(id), o);
83         } catch (org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc e) {
84             System.out.println(getClass().getName() + " : Object Not Found Exception !");
85         } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc e) {
86             System.out.println(getClass().getName() + " : CannotProceed Exception");
87         } catch (org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc e) {
88             System.out.println(getClass().getName() + " : InvalidName Exception");
89         }
90     }
91
92     //==================================================================
93
//
94
// Public methods for MenuItem interface.
95
//
96
//==================================================================
97

98     /* (non-Javadoc)
99      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.TreeView)
100      */

101     public int getStatus(TreeView arg0){
102         return MenuItem.ENABLED_STATUS;
103     }
104
105     /* (non-Javadoc)
106      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
107      */

108     public void actionPerformed(MenuItemTreeView tv) throws Exception JavaDoc {
109         Entry entry = tv.getSelectedEntry();
110         currentBindingName_ = entry.getName().toString();
111         naming_ = (NamingContextExt JavaDoc) tv.getParentObject();
112         bindingObject_ = (org.omg.CORBA.Object JavaDoc)tv.getSelectedObject();
113         tree_ = tv.getTree();
114         
115         DialogBox dialog = new DefaultDialogBox("Rename this binding");
116         bindingName_ = new LabelBox("Binding name",currentBindingName_,true);
117         dialog.addElementBox(bindingName_);
118         dialog.setValidateAction(this);
119         dialog.show();
120     }
121
122     //==================================================================
123
//
124
// Public methods for DialogAction interface.
125
//
126
//==================================================================
127

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

131     public void executeAction() throws Exception JavaDoc {
132         String JavaDoc newName = bindingName_.getLabel();
133         if(!newName.equals(currentBindingName_)){
134             naming_.rebind(naming_.to_name(newName), bindingObject_);
135             naming_.unbind(naming_.to_name(currentBindingName_));
136             tree_.renameSelectedNode(currentBindingName_, newName);
137         }
138     }
139 }
140
Popular Tags