1 23 24 package org.objectweb.fractal.gui.admin.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.model.Component; 29 import org.objectweb.fractal.swing.AbstractAction; 30 import org.objectweb.fractal.gui.admin.model.AdminModel; 31 import org.objectweb.fractal.gui.selection.model.Selection; 32 import org.objectweb.fractal.gui.selection.model.SelectionListener; 33 34 import java.awt.event.ActionEvent ; 35 import java.net.URL ; 36 37 import javax.swing.ImageIcon ; 38 import javax.swing.KeyStroke ; 39 import javax.swing.JOptionPane ; 40 41 44 45 public class DeleteInstanceAction extends AbstractAction 46 implements BindingController, SelectionListener 47 { 48 49 53 54 public final static String ADMIN_MODEL_BINDING = "admin-model"; 55 56 59 60 public final static String SELECTION_BINDING = "selection"; 61 62 65 66 private AdminModel adminmodel; 67 68 71 72 private Selection selection; 73 74 75 78 79 public DeleteInstanceAction () { 80 putValue(NAME, "Delete Instance"); 81 putValue(SHORT_DESCRIPTION, "DeleteInstance"); 82 URL url = getClass().getResource( 83 "/org/objectweb/fractal/gui/resources/empty.gif"); 84 putValue(SMALL_ICON, new ImageIcon (url)); 85 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control shift D")); 86 } 87 88 92 public String [] listFc () { 93 return new String [] { 94 ADMIN_MODEL_BINDING, 95 SELECTION_BINDING 96 }; 97 } 98 99 public Object lookupFc (final String clientItfName) { 100 if (ADMIN_MODEL_BINDING.equals(clientItfName)) { 101 return adminmodel; 102 } else if (SELECTION_BINDING.equals(clientItfName)) { 103 return selection; 104 } 105 return null; 106 } 107 108 public void bindFc (final String clientItfName, final Object serverItf) { 109 if (ADMIN_MODEL_BINDING.equals(clientItfName)) { 110 adminmodel = (AdminModel)serverItf; 111 } else if (SELECTION_BINDING.equals(clientItfName)) { 112 selection = (Selection)serverItf; 113 } 114 } 115 116 public void unbindFc (final String clientItfName) { 117 if (ADMIN_MODEL_BINDING.equals(clientItfName)) { 118 adminmodel = null; 119 } else if (SELECTION_BINDING.equals(clientItfName)) { 120 selection = null; 121 } 122 } 123 124 128 public void selectionChanged () { 129 Object o = selection.getSelection(); 130 if (o instanceof Component) { 131 setEnabled (true); 132 } else { 133 setEnabled(false); 134 } 135 } 136 137 141 public void actionPerformed (final ActionEvent e) { 142 Object o = selection.getSelection(); 143 if (o instanceof Component) { 144 Component c = (Component)o; 145 try { 146 adminmodel.deleteInstance (c); 147 } catch (Exception ex) { 148 JOptionPane.showMessageDialog ( 149 null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 150 } 151 } 152 } 153 } 154 | Popular Tags |