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 StartAction 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 StartAction () { 80 putValue(NAME, "Start"); 81 putValue(SHORT_DESCRIPTION, "Start"); 82 URL url = getClass().getResource( 83 "/org/objectweb/fractal/gui/resources/run.gif"); 84 putValue(SMALL_ICON, new ImageIcon (url)); 85 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F11")); 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 try { 144 if (o instanceof Component) { 145 Component c = (Component)o; 146 147 org.objectweb.fractal.api.Component ci = adminmodel.getInstance(c); 148 if (ci == null) { 149 JOptionPane.showMessageDialog (null, 150 "You must create an instance before starting it!", 151 "Alert ...", JOptionPane.ERROR_MESSAGE); 152 return; 153 } 154 adminmodel.start(c); 155 } 156 } catch (Exception ex) { 157 JOptionPane.showMessageDialog( 158 null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 159 return; 160 } 161 } 162 } 163 | Popular Tags |