1 23 24 package org.objectweb.fractal.gui.menu.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.model.ClientInterface; 29 import org.objectweb.fractal.gui.model.Component; 30 import org.objectweb.fractal.gui.model.Interface; 31 import org.objectweb.fractal.gui.model.ServerInterface; 32 import org.objectweb.fractal.gui.model.IllegalOperationException; 33 import org.objectweb.fractal.gui.selection.model.Selection; 34 import org.objectweb.fractal.gui.selection.model.SelectionListener; 35 import org.objectweb.fractal.swing.AbstractAction; 36 37 import java.awt.event.ActionEvent ; 38 import java.net.URL ; 39 40 import javax.swing.ImageIcon ; 41 import javax.swing.JOptionPane ; 42 import javax.swing.KeyStroke ; 43 44 49 50 public class DeleteAction extends AbstractAction implements 51 SelectionListener, 52 BindingController 53 { 54 55 59 60 public final static String SELECTION_BINDING = "selection"; 61 62 65 66 private Selection selection; 67 68 71 72 public DeleteAction () { 73 putValue(NAME, "Delete"); 74 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("DELETE")); 75 putValue(SHORT_DESCRIPTION, "Delete"); 76 URL url = getClass().getResource( 77 "/org/objectweb/fractal/gui/resources/edittrash.gif"); 78 putValue(SMALL_ICON, new ImageIcon (url)); 79 setEnabled(false); 80 } 81 82 86 public String [] listFc () { 87 return new String [] { SELECTION_BINDING }; 88 } 89 90 public Object lookupFc (final String clientItfName) { 91 if (SELECTION_BINDING.equals(clientItfName)) { 92 return selection; 93 } 94 return null; 95 } 96 97 public void bindFc ( 98 final String clientItfName, 99 final Object serverItf) 100 { 101 if (SELECTION_BINDING.equals(clientItfName)) { 102 selection = (Selection)serverItf; 103 } 104 } 105 106 public void unbindFc (final String clientItfName) { 107 if (SELECTION_BINDING.equals(clientItfName)) { 108 selection = null; 109 } 110 } 111 112 116 public void selectionChanged () { 117 boolean enabled = false; 118 Object o = selection.getSelection(); 119 if (o instanceof Component) { 120 Component c = (Component)o; 121 enabled = c.getParent() != null; 122 } else if (o instanceof Interface) { 123 enabled = true; 124 } 125 setEnabled(enabled); 126 } 127 128 132 public void actionPerformed (final ActionEvent e) { 133 Object o = selection.getSelection(); 134 try { 135 if (o instanceof Component) { 136 Component c = (Component)o; 137 c.getParent().removeSubComponent(c); 138 } else if (o instanceof Interface) { 139 Interface i = (Interface)o; 140 if (i.isInternal()) { 141 i = i.getComplementaryInterface(); 142 } 143 if (i instanceof ClientInterface) { 144 i.getOwner().removeClientInterface((ClientInterface)i); 145 } else { 146 i.getOwner().removeServerInterface((ServerInterface)i); 147 } 148 } 149 selection.clearSelection(); 150 } catch (IllegalOperationException ioe) { 151 JOptionPane.showMessageDialog( 152 null, ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 153 } 154 } 155 } 156 | Popular Tags |