KickJava   Java API By Example, From Geeks To Geeks.

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


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.gui;
28
29 import javax.swing.Box JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31
32 import org.objectweb.openccm.corba.trader.QueryPoliciesHelper;
33 import org.objectweb.openccm.corba.trader.SpecifiedServiceTypesWrapper;
34 import org.objectweb.openccm.explorer.CosTrading.Queries;
35 import org.objectweb.openccm.explorer.menu.LabelBox;
36 import org.omg.CosTradingRepos.ServiceTypeRepository;
37 import org.omg.CosTradingRepos.ServiceTypeRepositoryHelper;
38 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.SpecifiedServiceTypes;
39
40 /**
41  * Panel used to display what needs to be set for creating a query.
42  */

43 public class AddQueryPanel extends JPanel JavaDoc {
44     
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The query label. */
52     protected LabelBox ql_;
53
54     /** The available service types combo box. */
55     protected AvailableServiceTypesBox st_;
56
57     /** The constraint label and field. */
58     protected LabelBox const_;
59
60     /** The preference label and field. */
61     protected LabelBox pref_;
62
63     /** The advanced params box. */
64     protected Box JavaDoc advanced_box_;
65
66     /** The Queries wrapper object. */
67     protected Queries queries_;
68
69     /** A table for changed values from the initial policies. */
70     protected java.util.Map JavaDoc changed_policy_val_;
71
72     // ==================================================================
73
//
74
// Constructors.
75
//
76
// ==================================================================
77

78     /**
79      * Default constructor.
80      *
81      * @param queries The queries wrapper object in which the new
82      * query will be added.
83      */

84     public AddQueryPanel(Queries queries) {
85         // Init internal fields
86
queries_ = queries;
87         changed_policy_val_ = new java.util.HashMap JavaDoc();
88
89         // Creates the first pane.
90
JPanel JavaDoc basic_pane = new JPanel JavaDoc();
91         basic_pane.add(create_basic_pane_box(queries.getSize()));
92
93         // Creates the second pane.
94
JPanel JavaDoc advanced_pane = new JPanel JavaDoc();
95         advanced_pane.add(create_advanced_box());
96
97         // Adding them into the tabbed pane.
98
javax.swing.JTabbedPane JavaDoc tab = new javax.swing.JTabbedPane JavaDoc();
99         tab.addTab("Basic info", basic_pane);
100         tab.addTab("Advanced info", advanced_pane);
101
102         add(tab);
103     }
104
105     // ==================================================================
106
//
107
// Internal methods.
108
//
109
// ==================================================================
110

111     /**
112      * Creates a new box containing all mandatory values to create a
113      * simple trading query. This box contains all information related to the
114      * <code>Lookup::query</code> method's parameters.
115      *
116      * @param query_number The number of query to use in the query default label.
117      *
118      * @return The box containing all mandatory values to create a
119      * simple trading query.
120      */

121     protected Box JavaDoc create_basic_pane_box(int query_number) {
122         Box JavaDoc b = Box.createVerticalBox();
123         b.add(Box.createVerticalGlue());
124             
125         // Creates and adds the query label box.
126
ql_ = new LabelBox("Query Label:", "query " + query_number);
127         ql_.setToolTipText("The name of the query.");
128         b.add(ql_);
129
130         b.add(Box.createVerticalStrut(10));
131
132         // Creates a specified service types to use in order to list
133
// available service types in the service type repository.
134
SpecifiedServiceTypes sst = SpecifiedServiceTypesWrapper.create_all();
135
136         // Retrieves the list of available service types and, creates and adds the realted combo box.
137
ServiceTypeRepository str = ServiceTypeRepositoryHelper.narrow(queries_.getLookup().type_repos());
138         st_ = new AvailableServiceTypesBox("Service type name:", str.list_types(sst));
139         //const_.setToolTipText("The type name of service offers to search.");
140
b.add(st_);
141
142         b.add(Box.createVerticalStrut(10));
143
144         // Creates and adds the constraint label box.
145
const_ = new LabelBox("Constraint to apply:", "TRUE");
146         const_.setToolTipText("Select a set of service offers.");
147         b.add(const_);
148
149         b.add(Box.createVerticalStrut(10));
150
151         // Creates and adds the preference label box.
152
pref_ = new LabelBox("Preference to apply:", "first");
153         pref_.setToolTipText("The preferences can determine the order used to return matched offers.");
154         b.add(pref_);
155         b.add(Box.createVerticalGlue());
156             
157         return b;
158     }
159
160     /**
161      * Creates a new box containing all advanced values used to create
162      * a more complex trading query. This box contains all information
163      * related to the <code>Lookup::query</code> policies.
164      *
165      * @return The box containing all advanced values to create a more
166      * complex trading query.
167      */

168     protected Box JavaDoc create_advanced_box() {
169         org.omg.CosTrading.Lookup look = queries_.getLookup();
170         advanced_box_ = Box.createVerticalBox();
171
172         // Creates all box for the various standard policies
173

174         // search_card
175
LabelBox search_card = new LabelBox("Search cardinality: ", String.valueOf(look.def_search_card()));
176         search_card.addActionListener(new ChangedTextActionListener(changed_policy_val_)
177             {
178                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
179                     changed_policy_val_.put("search_card", e.getActionCommand());
180                 }
181             });
182         search_card.setToolTipText("Nominated upper bound of offers to be searched.");
183             
184         // match_card
185
LabelBox match_card = new LabelBox("Matching cardinality: ", String.valueOf(look.def_match_card()));
186         match_card.addActionListener(new ChangedTextActionListener(changed_policy_val_)
187             {
188                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
189                     changed_policy_val_.put("match_card", e.getActionCommand());
190                 }
191             });
192         match_card.setToolTipText("Nominated upper bound of offers to be ordered.");
193             
194         // return_card
195
LabelBox return_card = new LabelBox("Return cardinality: ", String.valueOf(look.def_return_card()));
196         return_card.addActionListener(new ChangedTextActionListener(changed_policy_val_)
197             {
198                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
199                     changed_policy_val_.put("return_card", e.getActionCommand());
200                 }
201             });
202         return_card.setToolTipText("Nominated upper bound of ordered offers to be returned.");
203             
204         // hop_count
205
LabelBox hop_count = new LabelBox("Hop count: ", String.valueOf(look.def_hop_count()));
206         hop_count.addActionListener(new ChangedTextActionListener(changed_policy_val_)
207             {
208                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
209                     changed_policy_val_.put("hop_count", e.getActionCommand());
210                 }
211             });
212         hop_count.setToolTipText("Nominated upper bound of depth of links to be traversed.");
213             
214         // link_follow_rule
215
FollowOptionBox link_follow_rule = new FollowOptionBox("Link follow rule: ", look.def_follow_policy());
216         link_follow_rule.addItemListener(new ChangedItemListener(changed_policy_val_)
217             {
218                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
219                     if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED)
220                         changed_policy_val_.put("link_follow_rule", e.getItem());
221                 }
222             });
223         link_follow_rule.setToolTipText("Nominated link follow behavior.");
224             
225         // starting_trader
226
LabelBox starting_trader = new LabelBox("Starting trader path: ");
227         starting_trader.addActionListener(new ChangedTextActionListener(changed_policy_val_)
228             {
229                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
230                     changed_policy_val_.put("starting_trader", e.getActionCommand());
231                 }
232             });
233         starting_trader.setToolTipText("An importer scopes its search by nominating that the query operation starts at a remote trader.");
234             
235         // request_id
236
LabelBox request_id = new LabelBox("Request id: ");
237         request_id.addActionListener(new ChangedTextActionListener(changed_policy_val_)
238             {
239                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
240                     changed_policy_val_.put("request_id", e.getActionCommand());
241                 }
242             });
243         request_id.setToolTipText("An identifier for the query operation.");
244             
245         // exact_type_match
246
BooleanBox exact_type_match = new BooleanBox("Exact type matching: ", false);
247         exact_type_match.addItemListener(new ChangedItemListener(changed_policy_val_)
248             {
249                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
250                     if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED)
251                         changed_policy_val_.put("exact_type_match", e.getItem());
252                 }
253             });
254         exact_type_match.setToolTipText("If offers of exactly the service type specified by the importer are considered.");
255             
256         // use_modifiable_properties
257
BooleanBox use_modifiable_properties = new BooleanBox("Use modifiable properties: ");
258         use_modifiable_properties.addItemListener(new ChangedItemListener(changed_policy_val_)
259             {
260                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
261                     if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED)
262                         changed_policy_val_.put("use_modifiable_properties", e.getItem());
263                 }
264             });
265         use_modifiable_properties.setToolTipText("Whether to consider offers with modifiable properties in the search.");
266             
267         // use_dynamic_properties
268
BooleanBox use_dynamic_properties = new BooleanBox("Use dynamic properties: ");
269         use_dynamic_properties.addItemListener(new ChangedItemListener(changed_policy_val_)
270             {
271                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
272                     if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED)
273                         changed_policy_val_.put("use_dynamic_properties", e.getItem());
274                 }
275             });
276         use_dynamic_properties.setToolTipText("Whether to consider offers with dynamic properties in the search.");
277             
278         // use_proxy_offers
279
BooleanBox use_proxy_offers = new BooleanBox("Use proxy offers: ");
280         use_proxy_offers.addItemListener(new ChangedItemListener(changed_policy_val_)
281             {
282                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
283                     if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED)
284                         changed_policy_val_.put("use_proxy_offers", e.getItem());
285                 }
286             });
287         use_proxy_offers.setToolTipText("Whether to consider proxy offers in the search.");
288
289
290         // Adding this boxes to the main box.
291
advanced_box_.add(Box.createVerticalGlue());
292         advanced_box_.add(search_card);
293         advanced_box_.add(Box.createVerticalStrut(10));
294         advanced_box_.add(match_card);
295         advanced_box_.add(Box.createVerticalStrut(10));
296         advanced_box_.add(return_card);
297         advanced_box_.add(Box.createVerticalStrut(10));
298         advanced_box_.add(hop_count);
299         advanced_box_.add(Box.createVerticalStrut(10));
300         advanced_box_.add(link_follow_rule);
301         advanced_box_.add(Box.createVerticalStrut(10));
302         advanced_box_.add(starting_trader);
303         advanced_box_.add(Box.createVerticalStrut(10));
304         advanced_box_.add(request_id);
305         advanced_box_.add(Box.createVerticalStrut(10));
306         advanced_box_.add(exact_type_match);
307         advanced_box_.add(Box.createVerticalStrut(10));
308         advanced_box_.add(use_modifiable_properties);
309         advanced_box_.add(Box.createVerticalStrut(10));
310         advanced_box_.add(use_dynamic_properties);
311         advanced_box_.add(Box.createVerticalStrut(10));
312         advanced_box_.add(use_proxy_offers);
313         advanced_box_.add(Box.createVerticalGlue());
314             
315         return advanced_box_;
316     }
317
318     // ==================================================================
319
//
320
// Public methods.
321
//
322
// ==================================================================
323

324     /**
325      * Returns the choosed query label.
326      *
327      * @return The choosed query label.
328      */

329     public String JavaDoc getQueryLabel() {
330         return ql_.getLabel();
331     }
332
333     /**
334      * Returns the choosed trading service type.
335      *
336      * @return The choosed trading service type.
337      */

338     public String JavaDoc getServiceTypeName() {
339         return st_.getTypeName();
340     }
341
342     /**
343      * Returns the choosed constraint.
344      *
345      * @return The choosed constraint.
346      */

347     public String JavaDoc getConstraint() {
348         return const_.getLabel();
349     }
350
351     /**
352      * Returns the choosed preference.
353      *
354      * @return The choosed preference.
355      */

356     public String JavaDoc getPref() {
357         return pref_.getLabel();
358     }
359
360     /**
361      * Returns the modified policies.
362      *
363      * @return The modified policies.
364      */

365     public org.omg.CosTrading.Policy[] getPolicies() {
366         java.util.List JavaDoc result = new java.util.LinkedList JavaDoc();
367         for (java.util.Iterator JavaDoc iter = changed_policy_val_.keySet().iterator(); iter.hasNext() ; ) {
368             String JavaDoc changed = (String JavaDoc) iter.next();
369             org.omg.CosTrading.Policy p = QueryPoliciesHelper.construct_policy(changed, (String JavaDoc)changed_policy_val_.get(changed));
370             if (p != null) result.add(p);
371         }
372         return (org.omg.CosTrading.Policy[])result.toArray(new org.omg.CosTrading.Policy[0]);
373     }
374
375     // ==================================================================
376
//
377
// Intenal classes.
378
//
379
// ==================================================================
380

381     /**
382      * Abstract class for internal TextActionListener.
383      */

384     protected abstract class ChangedTextActionListener
385         implements java.awt.event.ActionListener JavaDoc {
386         protected java.util.Map JavaDoc map_;
387         public ChangedTextActionListener(java.util.Map JavaDoc map) {map_ = map;}
388         public abstract void actionPerformed(java.awt.event.ActionEvent JavaDoc e);
389     }
390     
391     /**
392      * Abstract class for internal TextActionListener.
393      */

394     protected abstract class ChangedItemListener
395         implements java.awt.event.ItemListener JavaDoc {
396         protected java.util.Map JavaDoc map_;
397         public ChangedItemListener(java.util.Map JavaDoc map) {map_ = map;}
398         public abstract void itemStateChanged(java.awt.event.ItemEvent JavaDoc e);
399     }
400     
401 }
402
Popular Tags