KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CosTrading > AddLink


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): Sylvain Leblanc.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.openccm.explorer.CosTrading;
28
29 import java.awt.Component JavaDoc;
30 import java.awt.event.ActionEvent JavaDoc;
31
32 import javax.swing.JOptionPane JavaDoc;
33
34 import org.objectweb.openccm.explorer.CosTrading.gui.AddLinkPanel;
35 import org.objectweb.util.explorer.api.MenuItem;
36 import org.objectweb.util.explorer.api.MenuItemTreeView;
37 import org.objectweb.util.explorer.api.TreeView;
38 import org.omg.CosTrading.Link;
39
40 /**
41  * This action adds a new link between two traders.
42  *
43  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
44  * @version 0.1
45  */

46 public class AddLink implements MenuItem {
47
48     // ==================================================================
49
//
50
// Internal state.
51
//
52
// ==================================================================
53

54     // ==================================================================
55
//
56
// Constructors.
57
//
58
// ==================================================================
59

60     // ==================================================================
61
//
62
// Internal methods.
63
//
64
// ==================================================================
65

66     /**
67      * Used to treat an error while evaluating the query. Common
68      * action is to display an error message.
69      *
70      * @param message The error message to display.
71      */

72     protected void fatalError(String JavaDoc message) {
73         JOptionPane.showMessageDialog(null, message, "Error on add", JOptionPane.ERROR_MESSAGE);
74     }
75
76     // ==================================================================
77
//
78
// Public methods.
79
//
80
// ==================================================================
81

82     public int getStatus(TreeView arg0){
83         return MenuItem.ENABLED_STATUS;
84     }
85
86     public void actionPerformed(MenuItemTreeView e) {
87
88         Link link_ref = (Link) e.getSelectedObject();
89         AddLinkPanel lp = new AddLinkPanel();
90
91         ActionEvent JavaDoc ae = (ActionEvent JavaDoc)e.getEvent();
92         
93         int result =
94             JOptionPane.showOptionDialog(
95                 (Component JavaDoc) ae.getSource(),
96                 lp,
97                 "Create a new link",
98                 JOptionPane.OK_CANCEL_OPTION,
99                 JOptionPane.PLAIN_MESSAGE,
100                 null,
101                 null,
102                 null);
103
104         if (result == 0) {
105             String JavaDoc name = lp.getName();
106             org.omg.CosTrading.Lookup look_ref = lp.getLookupRef();
107             org.omg.CosTrading.FollowOption def_pass_on = lp.getDefPassOn();
108             org.omg.CosTrading.FollowOption limiting = lp.getLimiting();
109             
110             if (name != null && name.length() > 0 )
111                 try {
112                     link_ref.add_link(name, look_ref, def_pass_on, limiting);
113                 } catch (org.omg.CosTrading.LinkPackage.IllegalLinkName ex) {
114                     fatalError("Invalid name !");
115                 } catch (org.omg.CosTrading.LinkPackage.DuplicateLinkName ex) {
116                     fatalError("Invalid name !");
117                 } catch (org.omg.CosTrading.InvalidLookupRef ex) {
118                     fatalError("Invalid ref !");
119                 } catch (org.omg.CosTrading.LinkPackage.DefaultFollowTooPermissive ex) {
120                     fatalError("Default follow rule too permissive !");
121                 } catch (org.omg.CosTrading.LinkPackage.LimitingFollowTooPermissive ex) {
122                     fatalError("Limiting follow rule too permissive !");
123                 }
124             else
125                 fatalError("Invalid parameters !");
126         }
127     }
128 }
129
Popular Tags