1 26 27 package org.objectweb.openccm.explorer.CosTrading.gui; 28 29 import javax.swing.Box ; 30 import javax.swing.JPanel ; 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 43 public class AddQueryPanel extends JPanel { 44 45 51 52 protected LabelBox ql_; 53 54 55 protected AvailableServiceTypesBox st_; 56 57 58 protected LabelBox const_; 59 60 61 protected LabelBox pref_; 62 63 64 protected Box advanced_box_; 65 66 67 protected Queries queries_; 68 69 70 protected java.util.Map changed_policy_val_; 71 72 78 84 public AddQueryPanel(Queries queries) { 85 queries_ = queries; 87 changed_policy_val_ = new java.util.HashMap (); 88 89 JPanel basic_pane = new JPanel (); 91 basic_pane.add(create_basic_pane_box(queries.getSize())); 92 93 JPanel advanced_pane = new JPanel (); 95 advanced_pane.add(create_advanced_box()); 96 97 javax.swing.JTabbedPane tab = new javax.swing.JTabbedPane (); 99 tab.addTab("Basic info", basic_pane); 100 tab.addTab("Advanced info", advanced_pane); 101 102 add(tab); 103 } 104 105 111 121 protected Box create_basic_pane_box(int query_number) { 122 Box b = Box.createVerticalBox(); 123 b.add(Box.createVerticalGlue()); 124 125 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 SpecifiedServiceTypes sst = SpecifiedServiceTypesWrapper.create_all(); 135 136 ServiceTypeRepository str = ServiceTypeRepositoryHelper.narrow(queries_.getLookup().type_repos()); 138 st_ = new AvailableServiceTypesBox("Service type name:", str.list_types(sst)); 139 b.add(st_); 141 142 b.add(Box.createVerticalStrut(10)); 143 144 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 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 168 protected Box create_advanced_box() { 169 org.omg.CosTrading.Lookup look = queries_.getLookup(); 170 advanced_box_ = Box.createVerticalBox(); 171 172 174 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 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 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 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 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 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 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 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 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 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 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 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 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 e) { 240 changed_policy_val_.put("request_id", e.getActionCommand()); 241 } 242 }); 243 request_id.setToolTipText("An identifier for the query operation."); 244 245 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 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 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 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 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 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 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 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 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 324 329 public String getQueryLabel() { 330 return ql_.getLabel(); 331 } 332 333 338 public String getServiceTypeName() { 339 return st_.getTypeName(); 340 } 341 342 347 public String getConstraint() { 348 return const_.getLabel(); 349 } 350 351 356 public String getPref() { 357 return pref_.getLabel(); 358 } 359 360 365 public org.omg.CosTrading.Policy[] getPolicies() { 366 java.util.List result = new java.util.LinkedList (); 367 for (java.util.Iterator iter = changed_policy_val_.keySet().iterator(); iter.hasNext() ; ) { 368 String changed = (String ) iter.next(); 369 org.omg.CosTrading.Policy p = QueryPoliciesHelper.construct_policy(changed, (String )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 381 384 protected abstract class ChangedTextActionListener 385 implements java.awt.event.ActionListener { 386 protected java.util.Map map_; 387 public ChangedTextActionListener(java.util.Map map) {map_ = map;} 388 public abstract void actionPerformed(java.awt.event.ActionEvent e); 389 } 390 391 394 protected abstract class ChangedItemListener 395 implements java.awt.event.ItemListener { 396 protected java.util.Map map_; 397 public ChangedItemListener(java.util.Map map) {map_ = map;} 398 public abstract void itemStateChanged(java.awt.event.ItemEvent e); 399 } 400 401 } 402 | Popular Tags |