1 23 24 package org.objectweb.fractal.gui.dialog.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.dialog.model.DialogModel; 29 import org.objectweb.fractal.gui.dialog.view.DialogViewListener; 30 import org.objectweb.fractal.gui.model.ClientInterface; 31 import org.objectweb.fractal.gui.model.Component; 32 import org.objectweb.fractal.gui.model.Configuration; 33 import org.objectweb.fractal.gui.model.Factory; 34 import org.objectweb.fractal.gui.model.ServerInterface; 35 import org.objectweb.fractal.gui.model.IllegalOperationException; 36 import org.objectweb.fractal.gui.selection.model.Selection; 37 38 import javax.swing.JOptionPane ; 39 40 44 45 public class BasicDialogController implements 46 DialogViewListener, 47 BindingController 48 { 49 50 56 57 public final static String CONFIGURATION_BINDING = "configuration"; 58 59 64 65 public final static String SELECTION_BINDING = "selection"; 66 67 73 74 public final static String DIALOG_MODEL_BINDING = "dialog-model"; 75 76 81 82 public final static String FACTORY_BINDING = "configuration-factory"; 83 84 87 88 private Configuration configuration; 89 90 93 94 private Selection selection; 95 96 99 100 private DialogModel model; 101 102 105 106 private Factory factory; 107 108 111 112 public BasicDialogController () { 113 } 114 115 119 public String [] listFc () { 120 return new String [] { 121 CONFIGURATION_BINDING, 122 SELECTION_BINDING, 123 DIALOG_MODEL_BINDING, 124 FACTORY_BINDING 125 }; 126 } 127 128 public Object lookupFc (final String clientItfName) { 129 if (CONFIGURATION_BINDING.equals(clientItfName)) { 130 return configuration; 131 } else if (SELECTION_BINDING.equals(clientItfName)) { 132 return selection; 133 } else if (DIALOG_MODEL_BINDING.equals(clientItfName)) { 134 return model; 135 } else if (FACTORY_BINDING.equals(clientItfName)) { 136 return factory; 137 } 138 return null; 139 } 140 141 public void bindFc ( 142 final String clientItfName, 143 final Object serverItf) 144 { 145 if (CONFIGURATION_BINDING.equals(clientItfName)) { 146 configuration = (Configuration) serverItf; 147 } else if (SELECTION_BINDING.equals(clientItfName)) { 148 selection = (Selection)serverItf; 149 } else if (DIALOG_MODEL_BINDING.equals(clientItfName)) { 150 model = (DialogModel) serverItf; 151 } else if (FACTORY_BINDING.equals(clientItfName)) { 152 factory = (Factory) serverItf; 153 } 154 } 155 156 public void unbindFc (final String clientItfName) { 157 if (CONFIGURATION_BINDING.equals(clientItfName)) { 158 configuration = null; 159 } else if (SELECTION_BINDING.equals(clientItfName)) { 160 selection = null; 161 } else if (DIALOG_MODEL_BINDING.equals(clientItfName)) { 162 model = null; 163 } else if (FACTORY_BINDING.equals(clientItfName)) { 164 factory = null; 165 } 166 } 167 168 172 public void addClientInterfaceButtonClicked () { 173 Component component = configuration.getRootComponent(); 174 ClientInterface i = factory.createClientInterface(component); 175 component.addClientInterface(i); 176 } 177 178 public void removeClientInterfaceButtonClicked () { 179 try { 180 ClientInterface i = (ClientInterface)selection.getSelection(); 181 i.getOwner().removeClientInterface(i); 182 selection.clearSelection(); 183 } catch (IllegalOperationException ioe) { 184 JOptionPane.showMessageDialog( 185 null, ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 186 } 187 } 188 189 public void addServerInterfaceButtonClicked () { 190 Component component = configuration.getRootComponent(); 191 ServerInterface i = factory.createServerInterface(component); 192 component.addServerInterface(i); 193 } 194 195 public void removeServerInterfaceButtonClicked () { 196 try { 197 ServerInterface i = (ServerInterface)selection.getSelection(); 198 i.getOwner().removeServerInterface(i); 199 selection.clearSelection(); 200 } catch (IllegalOperationException ioe) { 201 JOptionPane.showMessageDialog( 202 null, ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 203 } 204 } 205 206 public void addAttributeButtonClicked () { 207 Component component = configuration.getRootComponent(); 208 int index = component.getAttributeNames().size(); 209 component.setAttribute("attribute " + index, "empty"); 210 } 211 212 public void removeAttributeButtonClicked () { 213 Component component = configuration.getRootComponent(); 214 int index = model.getAttributesTableSelectionModel().getMinSelectionIndex(); 215 String name = (String )component.getAttributeNames().get(index); 216 component.setAttribute(name, null); 217 } 218 } 219 | Popular Tags |