1 26 27 package org.objectweb.openccm.explorer.CosTrading; 28 29 import java.awt.Component ; 30 import java.awt.event.ActionEvent ; 31 32 import javax.swing.JOptionPane ; 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 46 public class AddLink implements MenuItem { 47 48 54 60 66 72 protected void fatalError(String message) { 73 JOptionPane.showMessageDialog(null, message, "Error on add", JOptionPane.ERROR_MESSAGE); 74 } 75 76 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 ae = (ActionEvent )e.getEvent(); 92 93 int result = 94 JOptionPane.showOptionDialog( 95 (Component ) 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 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 |