1 23 24 package org.objectweb.fractal.gui.dialog.model; 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.Configuration; 31 import org.objectweb.fractal.gui.model.ConfigurationListener; 32 import org.objectweb.fractal.gui.model.Interface; 33 import org.objectweb.fractal.gui.model.ServerInterface; 34 import org.objectweb.fractal.gui.selection.model.Selection; 35 import org.objectweb.fractal.gui.selection.model.SelectionListener; 36 37 import javax.swing.DefaultListSelectionModel ; 38 import javax.swing.ListSelectionModel ; 39 import javax.swing.table.TableModel ; 40 import javax.swing.text.Document ; 41 42 47 48 public class BasicDialogModel implements 49 DialogModel, 50 ConfigurationListener, 51 SelectionListener, 52 BindingController 53 { 54 55 60 61 public final static String CONFIGURATION_BINDING = "configuration"; 62 63 68 69 public final static String SELECTION_BINDING = "selection"; 70 71 74 75 private Configuration configuration; 76 77 80 81 private Selection selection; 82 83 86 87 private InterfaceTableModel[] itfTableModel; 88 89 92 93 private InterfaceTableSelectionModel[] itfTableSelectionModel; 94 95 98 99 private AttributeTableModel attrTableModel; 100 101 104 105 private ListSelectionModel attrTableSelectionModel; 106 107 110 111 private TextFieldModel nameFieldModel; 112 113 116 117 private TextFieldModel typeFieldModel; 118 119 122 123 private TextFieldModel implementationFieldModel; 124 125 128 129 private TextFieldModel attrControllerFieldModel; 130 131 135 136 private TextFieldModel tmplControllerDescFieldModel; 137 138 141 142 private TextFieldModel compControllerDescFieldModel; 143 144 147 148 public BasicDialogModel () { 149 itfTableModel = new InterfaceTableModel[2]; 150 itfTableSelectionModel = new InterfaceTableSelectionModel[2]; 151 for (int i = 0; i < 2; ++i) { 152 itfTableModel[i] = new InterfaceTableModel(i == 0); 153 itfTableSelectionModel[i] = new InterfaceTableSelectionModel(i == 0); 154 } 155 156 attrTableModel = new AttributeTableModel(); 157 attrTableSelectionModel = new DefaultListSelectionModel (); 158 attrTableSelectionModel.setSelectionMode( 159 ListSelectionModel.SINGLE_SELECTION); 160 161 nameFieldModel = new TextFieldModel(TextFieldModel.NAME); 162 typeFieldModel = new TextFieldModel(TextFieldModel.TYPE); 163 implementationFieldModel = 164 new TextFieldModel(TextFieldModel.IMPLEMENTATION); 165 attrControllerFieldModel = 166 new TextFieldModel(TextFieldModel.ATTRIBUTE_CONTROLLER); 167 tmplControllerDescFieldModel = 168 new TextFieldModel(TextFieldModel.TEMPLATE_CONTROLLER_DESC); 169 compControllerDescFieldModel = 170 new TextFieldModel(TextFieldModel.COMPONENT_CONTROLLER_DESC); 171 } 172 173 177 public String [] listFc () { 178 return new String [] { 179 CONFIGURATION_BINDING, 180 SELECTION_BINDING 181 }; 182 } 183 184 public Object lookupFc (final String clientItfName) { 185 if (CONFIGURATION_BINDING.equals(clientItfName)) { 186 return configuration; 187 } else if (SELECTION_BINDING.equals(clientItfName)) { 188 return selection; 189 } 190 return null; 191 } 192 193 public void bindFc ( 194 final String clientItfName, 195 final Object serverItf) 196 { 197 if (CONFIGURATION_BINDING.equals(clientItfName)) { 198 configuration = (Configuration) serverItf; 199 } else if (SELECTION_BINDING.equals(clientItfName)) { 200 selection = (Selection)serverItf; 201 for (int i = 0; i < itfTableSelectionModel.length; ++i) { 202 itfTableSelectionModel[i].setSelection(selection); 203 } 204 } 205 } 206 207 public void unbindFc (final String clientItfName) { 208 if (CONFIGURATION_BINDING.equals(clientItfName)) { 209 configuration = null; 210 } else if (SELECTION_BINDING.equals(clientItfName)) { 211 selection = null; 212 for (int i = 0; i < itfTableSelectionModel.length; ++i) { 213 itfTableSelectionModel[i].setSelection(null); 214 } 215 } 216 } 217 218 222 public TableModel getClientInterfacesTableModel () { 223 return itfTableModel[0]; 224 } 225 226 public ListSelectionModel getClientInterfacesTableSelectionModel() { 227 return itfTableSelectionModel[0]; 228 } 229 230 public TableModel getServerInterfacesTableModel() { 231 return itfTableModel[1]; 232 } 233 234 public InterfaceTableSelectionModel getServerInterfacesTableSelectionModel() { 235 return itfTableSelectionModel[1]; 236 } 237 238 public TableModel getAttributesTableModel() { 239 return attrTableModel; 240 } 241 242 public ListSelectionModel getAttributesTableSelectionModel() { 243 return attrTableSelectionModel; 244 } 245 246 public Document getNameFieldModel() { 247 return nameFieldModel; 248 } 249 250 public Document getTypeFieldModel() { 251 return typeFieldModel; 252 } 253 254 public Document getImplementationFieldModel() { 255 return implementationFieldModel; 256 } 257 258 public Document getAttrControllerFieldModel() { 259 return attrControllerFieldModel; 260 } 261 262 public Document getTmplControllerDescFieldModel() { 263 return tmplControllerDescFieldModel; 264 } 265 266 public Document getCompControllerDescFieldModel() { 267 return compControllerDescFieldModel; 268 } 269 270 274 public void changeCountChanged (Component component, long changeCount) { 275 } 277 278 public void rootComponentChanged (final Component oldValue) { 279 final Component root = configuration.getRootComponent(); 280 for (int i = 0; i < itfTableModel.length; ++i) { 281 itfTableModel[i].setComponentModel(root); 282 itfTableSelectionModel[i].setComponentModel(root); 283 } 284 285 attrTableModel.setComponentModel(root); 286 287 nameFieldModel.setComponentModel(root); 288 typeFieldModel.setComponentModel(root); 289 implementationFieldModel.setComponentModel(root); 290 attrControllerFieldModel.setComponentModel(root); 291 tmplControllerDescFieldModel.setComponentModel(root); 292 compControllerDescFieldModel.setComponentModel(root); 293 } 294 295 public void nameChanged (final Component component, final String oldValue) { 296 if (component == configuration.getRootComponent()) { 297 nameFieldModel.componentTextChanged(component.getName()); 298 } 299 } 300 301 public void typeChanged (final Component component, final String oldValue) { 302 if (component == configuration.getRootComponent()) { 303 typeFieldModel.componentTextChanged(component.getType()); 304 } 305 } 306 307 public void implementationChanged ( 308 final Component component, 309 final String oldValue) 310 { 311 if (component == configuration.getRootComponent()) { 312 implementationFieldModel.componentTextChanged( 313 component.getImplementation()); 314 } 315 } 316 317 public void interfaceNameChanged (final Interface i, final String oldValue) { 318 interfaceChanged(i); 319 } 320 321 public void interfaceSignatureChanged ( 322 final Interface i, 323 final String oldValue) 324 { 325 interfaceChanged(i); 326 } 327 328 public void interfaceContingencyChanged ( 329 final Interface i, 330 final boolean oldValue) 331 { 332 interfaceChanged(i); 333 } 334 335 public void interfaceCardinalityChanged ( 336 final Interface i, 337 final boolean oldValue) 338 { 339 interfaceChanged(i); 340 } 341 342 347 348 private void interfaceChanged (final Interface i) { 349 if (i.getOwner() == configuration.getRootComponent()) { 350 if (i instanceof ClientInterface) { 351 itfTableModel[0].interfaceChanged(i); 352 } else { 353 itfTableModel[1].interfaceChanged(i); 354 } 355 } 356 } 357 358 public void clientInterfaceAdded ( 359 final Component component, 360 final ClientInterface i, 361 final int index) 362 { 363 if (component == configuration.getRootComponent()) { 364 itfTableModel[0].interfaceAdded(i, index); 365 } 366 } 367 368 public void clientInterfaceRemoved ( 369 final Component component, 370 final ClientInterface i, 371 final int index) 372 { 373 if (component == configuration.getRootComponent()) { 374 itfTableModel[0].interfaceRemoved(i, index); 375 } 376 } 377 378 public void serverInterfaceAdded ( 379 final Component component, 380 final ServerInterface i, 381 final int index) 382 { 383 if (component == configuration.getRootComponent()) { 384 itfTableModel[1].interfaceAdded(i, index); 385 } 386 } 387 388 public void serverInterfaceRemoved ( 389 final Component component, 390 final ServerInterface i, 391 final int index) 392 { 393 if (component == configuration.getRootComponent()) { 394 itfTableModel[1].interfaceRemoved(i, index); 395 } 396 } 397 398 public void interfaceBound ( 399 final ClientInterface citf, 400 final ServerInterface sitf) 401 { 402 if (citf.getOwner() == configuration.getRootComponent()) { 403 } 405 } 406 407 public void interfaceRebound ( 408 final ClientInterface citf, 409 final ServerInterface oldSitf) 410 { 411 if (citf.getOwner() == configuration.getRootComponent()) { 412 } 414 } 415 416 public void interfaceUnbound ( 417 final ClientInterface citf, 418 final ServerInterface sitf) 419 { 420 if (citf.getOwner() == configuration.getRootComponent()) { 421 } 423 } 424 425 public void attributeControllerChanged ( 426 final Component component, 427 final String oldValue) 428 { 429 if (component == configuration.getRootComponent()) { 430 attrControllerFieldModel.componentTextChanged( 431 component.getAttributeController()); 432 } 433 } 434 435 public void attributeChanged ( 436 final Component component, 437 final String attributeName, 438 final String oldValue) 439 { 440 if (component == configuration.getRootComponent()) { 441 attrTableModel.attributeChanged(attributeName, oldValue); 442 } 443 } 444 445 public void templateControllerDescriptorChanged ( 446 final Component component, 447 final String oldValue) 448 { 449 if (component == configuration.getRootComponent()) { 450 tmplControllerDescFieldModel.componentTextChanged( 451 component.getTemplateControllerDescriptor()); 452 } 453 } 454 455 public void componentControllerDescriptorChanged ( 456 final Component component, 457 final String oldValue) 458 { 459 if (component == configuration.getRootComponent()) { 460 compControllerDescFieldModel.componentTextChanged( 461 component.getComponentControllerDescriptor()); 462 } 463 } 464 465 public void subComponentAdded ( 466 final Component parent, 467 final Component child, 468 final int index) 469 { 470 } 472 473 public void subComponentRemoved ( 474 final Component parent, 475 final Component child, 476 final int index) 477 { 478 } 480 481 485 public void selectionChanged () { 486 Object o = selection.getSelection(); 487 if (o != null) { 488 if (o instanceof Interface) { 489 o = ((Interface)o).getOwner(); 490 } 491 configuration.setRootComponent((Component)o); 492 } 493 for (int i = 0; i < itfTableSelectionModel.length; ++i) { 494 itfTableSelectionModel[i].selectionChanged(); 495 } 496 } 497 } 498 | Popular Tags |