KickJava   Java API By Example, From Geeks To Geeks.

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


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.DropAction;
29 import org.objectweb.util.explorer.api.DropTreeView;
30 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
31 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
32 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
33 import org.objectweb.util.explorer.swing.gui.lib.LabelBox;
34 import org.omg.CosNaming.NamingContextExt JavaDoc;
35
36 /**
37  * This action binds an object into the NameService using the Drag&Drop mechanism.
38  * If the name is already bound in the context, it replaces it.
39  *
40  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
41  *
42  * @version 0.1
43  */

44 public class BindObjectOnDropAction
45     implements DropAction, DialogAction {
46
47     //==================================================================
48
//
49
// Internal states.
50
//
51
//==================================================================
52

53     protected NamingContextExt JavaDoc namingContext_;
54
55     protected LabelBox name_;
56
57     protected org.omg.CORBA.Object JavaDoc object_ = null;
58
59     //==================================================================
60
//
61
// No constructor.
62
//
63
//==================================================================
64

65     //==================================================================
66
//
67
// No internal method.
68
//
69
//==================================================================
70

71     //==================================================================
72
//
73
// Public methods for DropAction interface.
74
//
75
//==================================================================
76

77     /* (non-Javadoc)
78      * @see org.objectweb.util.explorer.api.DropAction#execute(org.objectweb.util.explorer.api.DropTreeView)
79      */

80     public void execute(DropTreeView dropTreeView) throws Exception JavaDoc {
81         namingContext_ = (NamingContextExt JavaDoc)dropTreeView.getSelectedObject();
82         String JavaDoc name = dropTreeView.getDragSourceEntry().getName().toString();
83         Object JavaDoc dragObject = dropTreeView.getDragSourceObject();
84         
85         if(org.omg.CORBA.Object JavaDoc.class.isAssignableFrom(dragObject.getClass())){
86             object_ = (org.omg.CORBA.Object JavaDoc)dragObject;
87         } else {
88             throw new Exception JavaDoc("You must select a org.omg.CORBA.Object \n Found : " + dragObject.getClass().getName());
89         }
90         if(object_ != null) {
91             DialogBox dialog = new DefaultDialogBox("Binds a new object into the NameService");
92             name_ = new LabelBox("Object name",name);
93             dialog.addElementBox(name_);
94             dialog.setValidateAction(this);
95             dialog.show();
96         }
97        
98     }
99
100     //==================================================================
101
//
102
// Public methods for DialogAction interface.
103
//
104
//==================================================================
105

106     /* (non-Javadoc)
107      * @see org.objectweb.util.explorer.swing.gui.api.DialogAction#executeAction()
108      */

109     public void executeAction() throws Exception JavaDoc {
110         namingContext_.rebind(namingContext_.to_name(name_.getLabel()),object_);
111     }
112
113 }
Popular Tags