1 package SOFA.SOFAnode.Made.TIR.Access.TIRBrowser; 2 3 import java.awt.Component ; 4 import java.awt.event.ActionEvent ; 5 import java.awt.event.ActionListener ; 6 import java.awt.event.MouseAdapter ; 7 import java.awt.event.MouseEvent ; 8 import java.rmi.RemoteException ; 9 10 import javax.swing.ImageIcon ; 11 import javax.swing.JMenuItem ; 12 import javax.swing.JOptionPane ; 13 import javax.swing.JPopupMenu ; 14 import javax.swing.JScrollPane ; 15 import javax.swing.JSplitPane ; 16 import javax.swing.JTable ; 17 import javax.swing.JTree ; 18 import javax.swing.event.TreeExpansionEvent ; 19 import javax.swing.event.TreeSelectionEvent ; 20 import javax.swing.event.TreeSelectionListener ; 21 import javax.swing.event.TreeWillExpandListener ; 22 import javax.swing.table.AbstractTableModel ; 23 import javax.swing.tree.DefaultMutableTreeNode ; 24 import javax.swing.tree.DefaultTreeCellRenderer ; 25 import javax.swing.tree.DefaultTreeModel ; 26 import javax.swing.tree.ExpandVetoException ; 27 28 import SOFA.SOFAnode.Made.TIR.ArchitectureDef; 29 import SOFA.SOFAnode.Made.TIR.ArrayDef; 30 import SOFA.SOFAnode.Made.TIR.AttrMode; 31 import SOFA.SOFAnode.Made.TIR.AttributeDef; 32 import SOFA.SOFAnode.Made.TIR.BindDef; 33 import SOFA.SOFAnode.Made.TIR.CDLType; 34 import SOFA.SOFAnode.Made.TIR.Contained; 35 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 36 import SOFA.SOFAnode.Made.TIR.EnumDef; 37 import SOFA.SOFAnode.Made.TIR.EnumMember; 38 import SOFA.SOFAnode.Made.TIR.FrameDef; 39 import SOFA.SOFAnode.Made.TIR.Identification; 40 import SOFA.SOFAnode.Made.TIR.InstDef; 41 import SOFA.SOFAnode.Made.TIR.InstMode; 42 import SOFA.SOFAnode.Made.TIR.InterfaceDef; 43 import SOFA.SOFAnode.Made.TIR.ManageProfiles; 44 import SOFA.SOFAnode.Made.TIR.PrimitiveDef; 45 import SOFA.SOFAnode.Made.TIR.PrimitiveKind; 46 import SOFA.SOFAnode.Made.TIR.ProfileDef; 47 import SOFA.SOFAnode.Made.TIR.Repository; 48 import SOFA.SOFAnode.Made.TIR.SequenceDef; 49 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 50 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 51 import SOFA.SOFAnode.Made.TIR.TIRException; 52 import SOFA.SOFAnode.Made.TIR.TIRObject; 53 import SOFA.SOFAnode.Made.TIR.TypedefDef; 54 import SOFA.SOFAnode.Made.TIR.WorkRepository; 55 56 57 public class TIRBrowser extends JSplitPane { 58 JTable prop; 59 JScrollPane propScroll; 60 TreeBrowser tree; 61 JScrollPane treeScroll; 62 MyTableModel tableModel; 63 64 public TIRBrowser(String host, String port, Repository rep) { 65 super(JSplitPane.VERTICAL_SPLIT); 66 tableModel = new MyTableModel(host, port); 67 tree = new TreeBrowser(new RootNode(host+":"+port, rep), tableModel); 68 prop = new JTable (tableModel); 69 treeScroll = new JScrollPane (tree); 70 propScroll = new JScrollPane (prop); 71 setTopComponent(treeScroll); 72 setBottomComponent(propScroll); 73 } 74 } 75 76 class TreeBrowser extends JTree { 77 DefaultMutableTreeNode root; 78 MyTableModel model; 79 80 public TreeBrowser(DefaultMutableTreeNode root, MyTableModel tablemodel) { 81 super(root); 82 model = tablemodel; 83 this.root = root; 84 setCellRenderer(new TreeBrowserRenderer()); 85 putClientProperty("JTree.lineStyle", "Angled"); 86 87 addTreeWillExpandListener(new TreeWillExpandListener () { 88 public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { 89 Object obj = event.getPath().getLastPathComponent(); 90 if (obj instanceof TIRObjectNode) { 91 TIRObjectNode o = (TIRObjectNode) obj; 92 if (!o.hasContent()) { 93 o.loadContent(); 94 } 95 } 96 if (obj instanceof ProfilesNode) { 97 ProfilesNode o = (ProfilesNode) obj; 98 if (!o.hasContent()) { 99 o.loadContent(); 100 } 101 } 102 if (obj instanceof ProfileNode) { 103 ProfileNode o = (ProfileNode) obj; 104 if (!o.hasContent()) { 105 o.loadContent(); 106 } 107 } 108 } 109 public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { 110 ; 111 } 112 } 113 ); 114 115 addTreeSelectionListener(new SelListener(model)); 116 117 addMouseListener(new TIRMouseAdapter(this)); 118 119 120 } 121 122 public void clearTP() { 123 clearToggledPaths(); 124 } 125 126 class TIRMouseAdapter extends MouseAdapter { 127 TreeBrowser tree; 128 129 public TIRMouseAdapter(TreeBrowser t) { 130 tree = t; 131 } 132 133 public void mousePressed(MouseEvent e) { 134 int selRow = tree.getRowForLocation(e.getX(), e.getY()); 135 javax.swing.tree.TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); 136 if(selRow != -1) { 137 if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK)==java.awt.event.InputEvent.BUTTON3_MASK) { 138 tree.setSelectionRow(selRow); 139 Object obj = selPath.getLastPathComponent(); 140 158 if (obj instanceof BaseNode) { 159 String [] names = ((BaseNode) obj).getMenuNames(); 160 if (names != null) { 161 TreeActionListener alistener = new TreeActionListener((BaseNode)obj, tree, selPath); 162 JPopupMenu menu = new JPopupMenu (); 163 for (int i=0; i<names.length; i++) { 164 JMenuItem item = new JMenuItem (names[i]); 165 item.addActionListener(alistener); 166 menu.add(item); 167 } 168 menu.show(tree, e.getX(), e.getY()); 169 } 170 } 171 } 172 } 173 } 174 } 175 176 class TreeActionListener implements ActionListener { 177 BaseNode node; 178 javax.swing.tree.TreePath selPath; 179 JTree tree; 180 181 public TreeActionListener(BaseNode node, JTree tree, javax.swing.tree.TreePath selPath) { 182 this.node = node; 183 this.tree = tree; 184 this.selPath = selPath; 185 } 186 public void actionPerformed(ActionEvent e) { 187 node.performAction(e.getActionCommand(), tree, selPath); 188 } 189 } 190 191 192 193 class SelListener implements TreeSelectionListener { 194 MyTableModel model; 195 public SelListener(MyTableModel m) { model = m; } 196 public void valueChanged(TreeSelectionEvent event) { 197 Object obj = event.getPath().getLastPathComponent(); 198 if (obj instanceof TIRObjectNode) { 199 TIRObjectNode o = (TIRObjectNode) obj; 200 model.setObj(o.obj); 201 } 202 if (obj instanceof RootNode) { 203 RootNode o = (RootNode) obj; 204 model.setObj(o.rep); 205 } 206 } 207 } 208 209 210 } 211 212 class TreeBrowserRenderer extends DefaultTreeCellRenderer { 213 class NodeDecoration { 214 ImageIcon openIcon; 215 ImageIcon closeIcon; 216 String toolTip; 217 public NodeDecoration(String oi, String ci, String tt) { 218 closeIcon = new ImageIcon (ClassLoader.getSystemResource(ci)); 219 openIcon = new ImageIcon (ClassLoader.getSystemResource(oi)); 220 toolTip = tt; 221 } 222 } 223 224 class NodeDecorationStore extends java.util.Hashtable { 225 public static final String ID = "id"; 226 227 public void add(int dk, NodeDecoration nd) { 228 put (new Integer (dk), nd); 229 } 230 231 public void addSpecial(String dk, NodeDecoration nd) { 232 put (dk, nd); 233 } 234 235 public NodeDecoration getND(int dk) { 236 return (NodeDecoration) get(new Integer (dk)); 237 } 238 239 public NodeDecoration getNDSpecial(String dk) { 240 return (NodeDecoration) get(dk); 241 } 242 } 243 244 NodeDecorationStore nd; 245 246 public TreeBrowserRenderer() { 247 nd = new NodeDecorationStore(); 248 nd.add(DefinitionKind.dk_Module, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ModuleOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ModuleCloseIcon.gif",null)); 249 nd.add(DefinitionKind.dk_AModule, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ModuleOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ModuleCloseIcon.gif",null)); 250 nd.add(DefinitionKind.dk_Provider, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ProviderOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ProviderCloseIcon.gif",null)); 251 nd.add(DefinitionKind.dk_Frame, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/FrameOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/FrameCloseIcon.gif",null)); 252 254 nd.add(DefinitionKind.dk_Architecture, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ArchitectureOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ArchitectureCloseIcon.gif",null)); 255 nd.add(DefinitionKind.dk_Repository, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/RepOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/RepCloseIcon.gif",null)); 256 nd.add(DefinitionKind.dk_Interface, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/InterfaceOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/InterfaceCloseIcon.gif",null)); 257 nd.add(DefinitionKind.dk_Attribute, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointCloseIcon.gif",null)); 258 nd.add(DefinitionKind.dk_Operation, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointCloseIcon.gif",null)); 259 nd.add(DefinitionKind.dk_Struct, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointCloseIcon.gif",null)); 260 nd.add(DefinitionKind.dk_Exception, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ExcepOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ExcepCloseIcon.gif",null)); 261 nd.add(DefinitionKind.dk_Union, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointCloseIcon.gif",null)); 262 nd.add(DefinitionKind.dk_Enum, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/PointCloseIcon.gif",null)); 263 nd.add(DefinitionKind.dk_Bind, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/BindOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/BindCloseIcon.gif",null)); 264 nd.add(DefinitionKind.dk_Inst, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/InstOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/InstCloseIcon.gif",null)); 265 nd.add(DefinitionKind.dk_StructMember, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/MemberOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/MemberCloseIcon.gif",null)); 266 nd.add(DefinitionKind.dk_UnionMember, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/MemberOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/MemberCloseIcon.gif",null)); 267 nd.add(DefinitionKind.dk_Typedef, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/TypedefOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/TypedefCloseIcon.gif",null)); 268 nd.add(DefinitionKind.dk_Constant, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ConstantOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ConstantCloseIcon.gif",null)); 269 nd.add(DefinitionKind.dk_Provides, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ProvidesOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ProvidesCloseIcon.gif",null)); 270 nd.add(DefinitionKind.dk_Requires, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/RequiresOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/RequiresCloseIcon.gif",null)); 271 nd.add(DefinitionKind.dk_Property, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/MemberOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/MemberCloseIcon.gif",null)); 272 nd.add(DefinitionKind.dk_Profile, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ProfileOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/ProfileCloseIcon.gif",null)); 273 nd.addSpecial(NodeDecorationStore.ID, new NodeDecoration("SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/IDOpenIcon.gif","SOFA/SOFAnode/Made/TIR/Access/TIRBrowser/images/IDCloseIcon.gif",null)); 274 } 275 276 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { 277 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 278 if (value instanceof TIRObjectNode) { 279 TIRObjectNode node = (TIRObjectNode) value; 280 int dk = 0; 281 try { 282 dk = node.obj.get_def_kind().value(); 283 } catch (java.rmi.RemoteException e) {} 284 NodeDecoration n = nd.getND(dk); 285 if (n != null) { 286 if (expanded) 287 setIcon(n.openIcon); 288 else 289 setIcon(n.closeIcon); 290 } 291 } 292 if (value instanceof RootNode) { 293 NodeDecoration n = nd.getND(DefinitionKind.dk_Repository); 294 if (n != null) { 295 if (expanded) 296 setIcon(n.openIcon); 297 else 298 setIcon(n.closeIcon); 299 } 300 } 301 if (value instanceof ProfileNode) { 302 NodeDecoration n = nd.getND(DefinitionKind.dk_Profile); 303 if (n != null) { 304 if (expanded) 305 setIcon(n.openIcon); 306 else 307 setIcon(n.closeIcon); 308 } 309 } 310 if (value instanceof IDNode) { 311 NodeDecoration n = nd.getNDSpecial(NodeDecorationStore.ID); 312 if (n != null) { 313 if (expanded) 314 setIcon(n.openIcon); 315 else 316 setIcon(n.closeIcon); 317 } 318 } 319 320 return this; 321 } 322 } 323 324 325 class BaseNode extends DefaultMutableTreeNode { 326 public BaseNode() { 327 super(); 328 } 329 public BaseNode(String s) { 330 super(s); 331 } 332 public String [] getMenuNames() { 333 return null; 334 } 335 public void performAction(String actionCommand, JTree tree, javax.swing.tree.TreePath selPath) { 336 337 } 338 } 339 340 341 class RootNode extends BaseNode { 342 Repository rep; 343 Repository backRep; 344 boolean hasContent; 345 int repDefKind; 346 347 public RootNode(String url, Repository r) { 348 super(url); 349 rep = r; 350 backRep = r; 351 repDefKind = DefinitionKind.dk_Repository; 352 setAllowsChildren(true); 353 hasContent = false; 354 loadSubnodes(); 355 } 356 357 public void loadSubnodes() { 358 if (hasContent) { 359 removeAllChildren(); 360 } 361 try { 362 Contained[] cnt = rep.contents(null); 363 for (int i=0;i<cnt.length;i++) { 364 add(new TIRObjectNode(cnt[i])); 365 } 366 add(new ProfilesNode(rep.getProfiles())); 367 hasContent = true; 368 } catch (TIRException e) { 369 JOptionPane.showMessageDialog(null, "alert", "TIRException occured", JOptionPane.ERROR_MESSAGE); 370 } catch (RemoteException e) { 371 JOptionPane.showMessageDialog(null, "alert", "RemoteException occured", JOptionPane.ERROR_MESSAGE); 372 } 373 } 374 375 public String [] getMenuNames() { 376 if (repDefKind == DefinitionKind.dk_Repository) { 377 String [] s = { "Open work repository", "Reload" }; 378 return s; 379 } else { 380 String [] s = { "Commit", "Abort" }; 381 return s; 382 } 383 } 384 385 public void performAction(String actionCommand, JTree tree, javax.swing.tree.TreePath selPath) { 386 if (actionCommand.compareTo("Reload")==0) { 387 tree.collapsePath(selPath); 388 399 loadSubnodes(); 400 ((DefaultTreeModel )tree.getModel()).reload(); 401 } else if (actionCommand.compareTo("Open work repository")==0) { 402 tree.collapsePath(selPath); 403 try { 404 WorkRepository wr = rep.beginChanges(null); 405 rep = wr; 406 repDefKind = DefinitionKind.dk_WorkRepository; 407 loadSubnodes(); 408 ((DefaultTreeModel )tree.getModel()).reload(); 409 } catch (RemoteException e) { 410 JOptionPane.showMessageDialog(tree, "alert", "Exception occured:\n"+e.getMessage(), JOptionPane.ERROR_MESSAGE); 411 } catch (TIRExceptCreate e) { 412 JOptionPane.showMessageDialog(tree, "alert", "Exception occured:\n"+e.getMessage(), JOptionPane.ERROR_MESSAGE); 413 } catch (TIRExceptLock e) { 414 JOptionPane.showMessageDialog(tree, "alert", "Exception occured:\n"+e.getMessage(), JOptionPane.ERROR_MESSAGE); 415 } 416 } else if (actionCommand.compareTo("Abort")==0) { 417 tree.collapsePath(selPath); 418 try { 419 ((WorkRepository) rep).abort(); 420 rep = backRep; 421 loadSubnodes(); 422 ((DefaultTreeModel )tree.getModel()).reload(); 423 } catch (RemoteException e) { 424 JOptionPane.showMessageDialog(tree, "alert", "Exception occured:\n"+e.getMessage(), JOptionPane.ERROR_MESSAGE); 425 } 426 } 427 } 428 } 429 430 class TIRObjectNode extends BaseNode { 431 Contained obj; 432 String label; 433 boolean hasCont; 434 435 public TIRObjectNode(Contained o) { 436 hasCont = false; 437 obj = o; 438 if (obj instanceof SOFA.SOFAnode.Made.TIR.Container) { 439 setAllowsChildren(true); 440 add (new DefaultMutableTreeNode ("Loading...")); 441 } 442 try { 443 setTIRLabel(); 444 } catch (RemoteException e) { 445 JOptionPane.showMessageDialog(null, "alert", "RemoteException occured", JOptionPane.ERROR_MESSAGE); 446 } 447 } 448 449 public boolean hasContent() { 450 return hasCont; 451 } 452 453 public void removeContent() { 454 if (obj instanceof SOFA.SOFAnode.Made.TIR.Container) { 455 removeAllChildren(); 456 setAllowsChildren(true); 457 add (new DefaultMutableTreeNode ("Loading...")); 458 hasCont = false; 459 } 460 } 461 462 public void loadContent() { 463 if (obj instanceof SOFA.SOFAnode.Made.TIR.Container) { 464 removeAllChildren(); 465 try { 466 Contained cnt[] = ((SOFA.SOFAnode.Made.TIR.Container) obj).contents(null); 467 for (int i=0;i<cnt.length;i++) { 468 add(new TIRObjectNode(cnt[i])); 469 } 470 hasCont = true; 471 } catch (TIRException e) { 472 JOptionPane.showMessageDialog(null, "alert", "TIRException occured", JOptionPane.ERROR_MESSAGE); 473 } catch (RemoteException e) { 474 JOptionPane.showMessageDialog(null, "alert", "RemoteException occured", JOptionPane.ERROR_MESSAGE); 475 } 476 } 477 } 478 479 protected void setTIRLabel() throws RemoteException { 480 Identification id; 481 DefinitionKind dk = obj.get_def_kind(); 482 switch (dk.value()) { 483 case DefinitionKind.dk_CDLRepository: 484 setUserObject("CDL"); 485 break; 486 case DefinitionKind.dk_AModule: 487 case DefinitionKind.dk_Provider: 488 case DefinitionKind.dk_Module: 489 id = obj.get_identification(); 490 label = kind2string(dk)+" "+id.name(); 491 setUserObject(label); 492 break; 493 default: 494 id = obj.get_identification(); 495 label = kind2string(dk)+" "+id.name()+"?"+id.version(); 496 setUserObject(label); 497 } 498 } 499 500 public static String kind2string(DefinitionKind dk) throws RemoteException { 501 switch (dk.value()) { 502 case DefinitionKind.dk_Attribute : return ("Attribute"); 503 case DefinitionKind.dk_Constant : return ("Constant"); 504 case DefinitionKind.dk_Exception : return ("Exception"); 505 case DefinitionKind.dk_Interface : return ("Interface"); 506 case DefinitionKind.dk_Module : return ("Module"); 507 case DefinitionKind.dk_Operation : return ("Operation"); 508 case DefinitionKind.dk_Typedef : return ("Typedef"); 509 case DefinitionKind.dk_Struct : return ("Struct"); 510 case DefinitionKind.dk_Union : return ("Union"); 511 case DefinitionKind.dk_Enum : return ("Enum"); 512 case DefinitionKind.dk_Primitive : return ("Primitive"); 513 case DefinitionKind.dk_String : return ("String"); 514 case DefinitionKind.dk_Sequence : return ("Sequence"); 515 case DefinitionKind.dk_Array : return ("Array"); 516 case DefinitionKind.dk_Repository : return ("Repository"); 517 case DefinitionKind.dk_Frame : return ("Frame"); 519 case DefinitionKind.dk_Architecture : return ("Architecture"); 520 case DefinitionKind.dk_Provides : return ("Provides"); 521 case DefinitionKind.dk_Requires : return ("Requires"); 522 case DefinitionKind.dk_Property : return ("Property"); 523 case DefinitionKind.dk_Implements : return ("Implements"); 525 case DefinitionKind.dk_Inst : return ("Inst"); 526 case DefinitionKind.dk_Bind : return ("Bind"); 527 case DefinitionKind.dk_Protocol : return ("Protocol"); 528 case DefinitionKind.dk_StructMember : return ("StructMember"); 529 case DefinitionKind.dk_EnumMember : return ("EnumMember"); 530 case DefinitionKind.dk_UnionMember : return ("UnionMember"); 531 case DefinitionKind.dk_Expression : return ("Expression"); 532 case DefinitionKind.dk_ProtocolOper : return ("ProtocolOper"); 533 case DefinitionKind.dk_ValueGen : return ("ValueGen"); 534 case DefinitionKind.dk_ValueGenElem : return ("ValueGenOper"); 535 case DefinitionKind.dk_BindOper : return ("BindOper"); 536 case DefinitionKind.dk_Provider : return ("Provider"); 537 case DefinitionKind.dk_AModule : return ("AModule"); 538 case DefinitionKind.dk_Wstring : return ("Wstring"); 539 case DefinitionKind.dk_Fixed : return ("Fixed"); 540 case DefinitionKind.dk_CDLRepository: return ("CDLRepository"); 541 case DefinitionKind.dk_WorkRepository : return ("WorkRepository"); 542 } 543 return ""; 544 } 545 546 public static String prim2string(PrimitiveKind p) throws RemoteException { 547 switch (p.value()) { 548 case PrimitiveKind.pk_void: return "void"; 549 case PrimitiveKind.pk_short: return "short"; 550 case PrimitiveKind.pk_long: return "long"; 551 case PrimitiveKind.pk_longlong: return "longlong"; 552 case PrimitiveKind.pk_ushort: return "ushort"; 553 case PrimitiveKind.pk_ulong: return "ulong"; 554 case PrimitiveKind.pk_ulonglong: return "ulonglong"; 555 case PrimitiveKind.pk_float: return "float"; 556 case PrimitiveKind.pk_double: return "double"; 557 case PrimitiveKind.pk_longdouble: return "longdouble"; 558 case PrimitiveKind.pk_boolean: return "boolean"; 559 case PrimitiveKind.pk_char: return "char"; 560 case PrimitiveKind.pk_wchar: return "wchar"; 561 case PrimitiveKind.pk_octet: return "octet"; 562 case PrimitiveKind.pk_object: return "object"; 563 case PrimitiveKind.pk_string: return "string"; 564 case PrimitiveKind.pk_wstring: return "wstring"; 565 case PrimitiveKind.pk_any: return "any"; 566 } 567 return ""; 568 } 569 570 public String [] getMenuNames() { 571 try { 572 DefinitionKind dk = obj.get_def_kind(); 573 switch (dk.value()) { 574 case DefinitionKind.dk_Architecture: 575 String [] s = { "Generate code" }; 576 return s; 577 } 578 return null; 579 } catch (Exception e) { return null; } 580 } 581 582 public void performAction(String actionCommand, JTree tree, javax.swing.tree.TreePath selPath) { 583 if (actionCommand.compareTo("Generate code")==0) { 584 RunCodeGenDialog dd = new RunCodeGenDialog(tree); 585 dd.pack(); 586 ArchitectureDef[] archs = new ArchitectureDef [1]; 587 archs[0] = (ArchitectureDef) obj; 588 dd.setVisible(true); 589 dd.repaint(); 590 try { 591 SOFA.SOFAnode.Made.CodeGen.Generator g = new SOFA.SOFAnode.Made.CodeGen.Generator((Repository) obj.get_containing_repository(), archs); 592 g.generate(); 593 dd.setVisible(false); 594 } catch (Exception ex) { 595 JOptionPane.showMessageDialog(null, "alert", "Exception occured:\n"+ex.getMessage(), JOptionPane.ERROR_MESSAGE); 596 } 597 } 598 } 599 600 } 601 602 class ProfilesNode extends BaseNode { 603 ManageProfiles mp; 604 boolean hasCont; 605 606 public ProfilesNode(ManageProfiles m) { 607 super("Profiles"); 608 mp = m; 609 hasCont = false; 610 setAllowsChildren(true); 611 add (new DefaultMutableTreeNode ("Loading...")); 612 } 613 614 public boolean hasContent() { 615 return hasCont; 616 } 617 618 public void removeContent() { 619 removeAllChildren(); 620 setAllowsChildren(true); 621 add (new DefaultMutableTreeNode ("Loading...")); 622 hasCont = false; 623 } 624 625 public void loadContent() { 626 removeAllChildren(); 627 try { 628 ProfileDef[] cnt = mp.all_profiles(); 629 for (int i=0;i<cnt.length;i++) { 630 add(new ProfileNode(cnt[i])); 631 } 632 hasCont = true; 633 } catch (TIRException e) { 634 JOptionPane.showMessageDialog(null, "alert", "TIRException occured", JOptionPane.ERROR_MESSAGE); 635 } catch (RemoteException e) { 636 JOptionPane.showMessageDialog(null, "alert", "RemoteException occured", JOptionPane.ERROR_MESSAGE); 637 } 638 } 639 } 640 641 class ProfileNode extends BaseNode { 642 ProfileDef pr; 643 boolean hasCont; 644 645 public ProfileNode(ProfileDef p) { 646 pr = p; 647 hasCont = false; 648 try { 649 setUserObject(pr.name()); 650 } catch (RemoteException e) { 651 JOptionPane.showMessageDialog(null, "alert", "RemoteException occured", JOptionPane.ERROR_MESSAGE); 652 } 653 setAllowsChildren(true); 654 add (new DefaultMutableTreeNode ("Loading...")); 655 } 656 657 public boolean hasContent() { 658 return hasCont; 659 } 660 661 public void loadContent() { 662 removeAllChildren(); 663 try { 664 Identification[] cnt = pr.contents(); 665 for (int i=0;i<cnt.length;i++) { 666 add(new IDNode(cnt[i])); 667 } 668 hasCont = true; 669 } catch (TIRException e) { 670 JOptionPane.showMessageDialog(null, "alert", "TIRException occured", JOptionPane.ERROR_MESSAGE); 671 } catch (RemoteException e) { 672 JOptionPane.showMessageDialog(null, "alert", "RemoteException occured", JOptionPane.ERROR_MESSAGE); 673 } 674 } 675 } 676 677 class IDNode extends BaseNode { 678 Identification id; 679 boolean hasCont; 680 681 public IDNode(Identification p) { 682 id = p; 683 try { 684 setUserObject(id.absolute_name().name()+"?"+id.version()); 685 } catch (RemoteException e) { 686 JOptionPane.showMessageDialog(null, "alert", "RemoteException occured", JOptionPane.ERROR_MESSAGE); 687 } 688 setAllowsChildren(false); 689 } 690 } 691 692 class MyTableModel extends AbstractTableModel { 693 final String [] columnNames = {"Property", "Value"}; 694 695 TIRObject obj; 696 Object [][] data; 697 int rows; 698 String host, port; 699 SOFA.SOFAnode.Made.CodeGen.JavaMapping jm = new SOFA.SOFAnode.Made.CodeGen.JavaMapping(); 700 SOFA.SOFAnode.Made.CodeGen.IDLMapping im = new SOFA.SOFAnode.Made.CodeGen.IDLMapping(); 701 702 public MyTableModel(String host, String port) { 703 super(); 704 this.host = host; 705 this.port = port; 706 } 707 708 private void setData(int i,String s1, String s2) { 709 data[i][0] = s1; 710 data[i][1] = s2; 711 } 712 713 private String cdlType2String(CDLType t) throws RemoteException { 714 StringBuffer sb = new StringBuffer (); 715 if (t instanceof Contained) { 716 Identification id = ((Contained) t).get_identification(); 717 sb.append(id.absolute_name().name()); 718 sb.append("?"); 719 sb.append(id.version()); 720 } else { 721 switch (((TIRObject)t).get_def_kind().value()) { 722 case DefinitionKind.dk_Primitive: 723 sb.append(TIRObjectNode.prim2string(((PrimitiveDef)t).kind())); 724 break; 725 case DefinitionKind.dk_Array: 726 sb.append(cdlType2String(((ArrayDef)t).element_type())); 727 sb.append("[]"); 728 break; 729 case DefinitionKind.dk_Sequence: 730 sb.append("sequence < "); 731 sb.append(cdlType2String(((SequenceDef)t).element_type())); 732 sb.append(" >"); 733 break; 734 case DefinitionKind.dk_String: 735 sb.append("string"); 736 break; 737 case DefinitionKind.dk_Wstring: 738 sb.append("wstring"); 739 break; 740 } 741 } 742 return sb.toString(); 743 } 744 745 public void setObj(TIRObject obj) { 746 int i; 747 rows = 0; 748 this.obj = obj; 749 if (data==null) { 750 int len = 15; 751 data = new Object [len][]; 752 for (i=0;i<len;i++) 753 data[i] = new Object [2]; 754 } 755 try { 756 int dk = obj.get_def_kind().value(); 757 setData(rows,"Kind", TIRObjectNode.kind2string(obj.get_def_kind())); 758 rows++; 759 760 if (dk == DefinitionKind.dk_Repository || dk == DefinitionKind.dk_WorkRepository) { 761 setData(rows,"Host", host); 762 setData(rows+1,"Port", port); 763 rows += 2; 764 } 765 if (dk == DefinitionKind.dk_CDLRepository) { 766 setData(rows,"Name","CDLRepository"); 767 rows++; 768 } else if (obj instanceof Contained) { 769 Identification id = null; 770 if (obj instanceof Contained) 771 id = ((Contained) obj).get_identification(); 772 setData(rows,"Name",id.name()); 773 rows++; 774 if (!moduleType(dk)) { 775 setData(rows,"Version", id.version()); 776 rows++; 777 } 778 StringBuffer sb; 779 switch (dk) { 780 case DefinitionKind.dk_Typedef: 781 setData(rows, "Original type", cdlType2String(((TypedefDef)obj).original_type())); 782 rows++; 783 break; 784 case DefinitionKind.dk_Architecture: 785 setData(rows, "System", (new Boolean (((ArchitectureDef) obj).is_system())).toString()); 786 rows++; 787 setData(rows, "Frame", cdlType2String(((ArchitectureDef) obj).frame()) ); 788 rows++; 789 break; 790 case DefinitionKind.dk_Attribute: 791 setData(rows, "Type", cdlType2String(((AttributeDef) obj).type())); 792 rows++; 793 if (((AttributeDef)obj).mode().value() == AttrMode.ATTR_NORMAL) 794 setData(rows, "Mode", "normal"); 795 else 796 setData(rows, "Mode", "read-only"); 797 rows++; 798 break; 799 case DefinitionKind.dk_Enum: 800 EnumMember[] memb = ((EnumDef)obj).members(); 801 String em = ""; 802 for (i=0;i<memb.length;i++) { 803 em += memb[i].name(); 804 if (i!=memb.length-1) 805 em+=", "; 806 } 807 setData(rows, "Members", em); 808 rows++; 809 break; 810 case DefinitionKind.dk_Frame: 811 setData(rows, "System", (new Boolean (((FrameDef) obj).is_system())).toString()); 812 rows++; 813 break; 814 case DefinitionKind.dk_Inst: 815 setData(rows, "Type", cdlType2String(((InstDef) obj).type())); 816 rows++; 817 if (((InstDef)obj).mode().value() == InstMode.NORMAL) 818 setData(rows, "Mode", "normal"); 819 else 820 setData(rows, "Mode", "auto"); 821 rows++; 822 break; 823 case DefinitionKind.dk_Interface: 824 InterfaceDef[] base = ((InterfaceDef) obj).base_interfaces(); 825 sb = new StringBuffer (); 826 for (i=0;i<base.length;i++) { 827 sb.append(cdlType2String(base[i])); 828 if (i!=base.length-1) 829 sb.append(", "); 830 } 831 setData(rows, "Base Interfaces", sb.toString()); 832 rows++; 833 sb = null; 834 break; 835 case DefinitionKind.dk_Bind: 836 setData(rows, "Using", ((BindDef) obj).using()); 837 rows++; 838 break; 839 } 840 852 } 853 } catch (java.rmi.RemoteException e) { 854 rows=1; 855 data[0][0] = "Error"; 856 data[0][1] = "RemoteException occured"; 857 } catch (TIRException e) { 858 rows=1; 859 data[0][0] = "Error"; 860 data[0][1] = "TIRException occured"; 861 } 862 fireTableStructureChanged(); 863 } 864 865 private boolean moduleType(int dk) { 866 if (dk==DefinitionKind.dk_Module || 867 dk==DefinitionKind.dk_AModule || 868 dk==DefinitionKind.dk_Provider 869 ) 870 return true; 871 else 872 return false; 873 } 874 875 public int getColumnCount() { 876 return 2; 877 } 878 879 public int getRowCount() { 880 return rows; 881 } 882 883 public String getColumnName(int col) { 884 return columnNames[col]; 885 } 886 887 public Object getValueAt(int row, int col) { 888 return data[row][col]; 889 } 890 891 public boolean isCellEditable(int row, int col) { 892 return false; 893 } 894 895 } 896 | Popular Tags |