KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CosTrading > gui > AddLinkPanel


1 /*===========================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 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.gui;
28
29 import java.io.BufferedReader JavaDoc;
30 import java.io.FileReader JavaDoc;
31
32 import javax.swing.Box JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34
35 import org.objectweb.openccm.explorer.menu.BrowserPanel;
36 import org.objectweb.openccm.explorer.menu.OpenCCMBrowserConstants;
37 import org.omg.CORBA.ORB JavaDoc;
38 import org.omg.CosTrading.FollowOption;
39 import org.omg.CosTrading.Lookup;
40 import org.omg.CosTrading.LookupHelper;
41
42 /**
43  * Panel used to display what needs to be set for
44  * creating a link.
45  */

46 public class AddLinkPanel
47      extends JPanel JavaDoc
48 {
49
50     // ==================================================================
51
//
52
// Internal state.
53
//
54
// ==================================================================
55

56     /** The browser panel for Lookup reference. */
57     protected BrowserPanel lbp_;
58
59     /** The box to select default follow rule. */
60     protected FollowOptionBox def_;
61
62     /** The box to select limiting follow rule. */
63     protected FollowOptionBox limit_;
64
65     // ==================================================================
66
//
67
// Constructors.
68
//
69
// ==================================================================
70

71     /**
72      * Default constructor.
73      */

74     public AddLinkPanel() {
75         Box JavaDoc b = Box.createVerticalBox();
76         b.add(Box.createVerticalGlue());
77             
78         // Creates the browser panel.
79
lbp_ = new BrowserPanel("Link Name: ", "Choose an IOR File: ", OpenCCMBrowserConstants.IOR_FILE_CHOOSER);
80         b.add(lbp_);
81
82         b.add(Box.createVerticalStrut(10));
83
84         // Creates the def combo box
85
def_ = new FollowOptionBox("Default Follow Link Rule: ");
86         b.add(def_);
87
88         b.add(Box.createVerticalStrut(10));
89
90         // Creates the limit combo box
91
limit_ = new FollowOptionBox("Limiting Follow Link Rule: ");
92         b.add(limit_);
93
94         b.add(Box.createVerticalGlue());
95             
96         add(b);
97     }
98
99     // ==================================================================
100
//
101
// Internal methods.
102
//
103
// ==================================================================
104

105     // ==================================================================
106
//
107
// Public methods.
108
//
109
// ==================================================================
110

111     /**
112      * Returns the new link name.
113      *
114      * @return The new link name.
115      */

116     public String JavaDoc getName() {
117         return lbp_.getLabel();
118     }
119
120     /**
121      * Returns the new link targeted trader.
122      *
123      * @return The new link targeted trader.
124      */

125     public Lookup getLookupRef() {
126         Lookup ref = null;
127         if (lbp_.getFile() != null) {
128             java.io.File JavaDoc file = lbp_.getFile();
129             String JavaDoc ior = null;
130             try {
131                 BufferedReader JavaDoc in = new BufferedReader JavaDoc(new FileReader JavaDoc(file));
132                 ior = in.readLine();
133             } catch (java.io.FileNotFoundException JavaDoc err) {
134                 System.err.println(file + ": File not found !");
135             } catch (java.io.IOException JavaDoc err) {
136                 System.err.println(file + ": Error while reading !");
137             }
138             if (ior != null && ior.startsWith("IOR:")) {
139                 ORB JavaDoc orb = org.objectweb.openccm.corba.TheORB.getORB();
140                 ref = LookupHelper.narrow(orb.string_to_object(ior));
141             }
142         } else if (lbp_.getSelectedObject() != null) {
143             ref = (Lookup)lbp_.getSelectedObject();
144         }
145         return ref;
146     }
147
148     /**
149      * Returns the new link def pass on option.
150      *
151      * @return The new link def pass on option.
152      */

153     public FollowOption getDefPassOn() {
154         return def_.getOption();
155     }
156
157     /**
158      * Returns the new link limiting option.
159      *
160      * @return The new link limiting option.
161      */

162     public FollowOption getLimiting() {
163         return limit_.getOption();
164     }
165 }
166
167
Popular Tags