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 StopAction extends AbstractAction 46 implements BindingController, SelectionListener 47 { 48 49 53 54 public final static String ADMIN_MODEL_BINDING = "admin-model"; 55 56 60 61 public final static String SELECTION_BINDING = "selection"; 62 63 66 67 private AdminModel adminmodel; 68 69 72 73 private Selection selection; 74 75 78 79 public StopAction () { 80 putValue(NAME, "Stop"); 81 putValue(SHORT_DESCRIPTION, "Stop"); 82 URL url = getClass().getResource( 83 "/org/objectweb/fractal/gui/resources/stop.gif"); 84 putValue(SMALL_ICON, new ImageIcon (url)); 85 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F12")); 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 { 118 if (ADMIN_MODEL_BINDING.equals(clientItfName)) { 119 adminmodel = null; 120 } else if (SELECTION_BINDING.equals(clientItfName)) { 121 selection = null; 122 } 123 } 124 125 129 public void selectionChanged () { 130 Object o = selection.getSelection(); 131 if (o instanceof Component) { 132 setEnabled (true); 133 } else { 134 setEnabled(false); 135 } 136 } 137 138 142 public void actionPerformed (final ActionEvent e) { 143 Object o = selection.getSelection(); 144 try { 145 if (o instanceof Component) { 146 Component c = (Component)o; 147 148 org.objectweb.fractal.api.Component ci = adminmodel.getInstance(c); 149 if (ci == null) { 150 JOptionPane.showMessageDialog (null, 151 "The instance you want stop doesn't exist!", 152 "Alert ...", JOptionPane.ERROR_MESSAGE); 153 return; 154 } 155 156 if (!adminmodel.isStarted(c)) { 157 JOptionPane.showMessageDialog (null, 158 "Instance not started!", 159 "Alert ...", JOptionPane.ERROR_MESSAGE); 160 return; 161 } 162 adminmodel.stop(c); 163 } 164 } catch (Exception ex) { 165 JOptionPane.showMessageDialog( 166 null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 167 return; 168 } 169 } 170 } 171 | Popular Tags |