1 23 24 package org.objectweb.fractal.gui.admin.model; 25 26 import org.objectweb.fractal.adl.Factory; 27 import org.objectweb.fractal.adl.FactoryFactory; 28 import org.objectweb.fractal.api.control.BindingController; 29 import org.objectweb.fractal.api.control.ContentController; 30 import org.objectweb.fractal.api.control.LifeCycleController; 31 import org.objectweb.fractal.api.control.AttributeController; 32 import org.objectweb.fractal.api.control.NameController; 33 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 34 import org.objectweb.fractal.api.NoSuchInterfaceException; 35 36 import org.objectweb.fractal.util.Fractal; 37 38 import org.objectweb.fractal.gui.model.Binding; 39 import org.objectweb.fractal.gui.model.ClientInterface; 40 import org.objectweb.fractal.gui.model.Component; 41 import org.objectweb.fractal.gui.model.Configuration; 42 import org.objectweb.fractal.gui.model.ConfigurationListener; 43 import org.objectweb.fractal.gui.model.IllegalOperationException; 44 import org.objectweb.fractal.gui.model.Interface; 45 import org.objectweb.fractal.gui.model.ServerInterface; 46 import org.objectweb.fractal.gui.model.VetoableConfigurationListener; 47 import org.objectweb.fractal.gui.repository.api.Storage; 48 import org.objectweb.fractal.gui.repository.api.Repository; 49 import org.objectweb.fractal.gui.admin.model.AdminModelListener; 50 51 import java.util.HashMap ; 52 import java.util.HashSet ; 53 import java.util.Map ; 54 import java.util.Set ; 55 import java.util.WeakHashMap ; 56 import java.util.List ; 57 58 import java.lang.reflect.Method ; 59 60 import java.awt.*; 61 import java.awt.event.*; 62 import javax.swing.*; 63 import javax.swing.border.*; 64 import java.awt.FontMetrics ; 65 import javax.swing.JOptionPane ; 66 67 68 public class BasicAdminModel implements 69 BindingController, 70 AdminModel, 71 VetoableConfigurationListener, 72 ConfigurationListener 73 { 74 75 79 80 public final static String CONFIGURATION_BINDING = "configuration"; 81 82 86 87 public final static String STORAGE_BINDING = "storage"; 88 89 93 94 public final static String REPOSITORY_BINDING = "repository"; 95 96 99 100 public final static String ADMIN_MODEL_LISTENER_BINDING = "admin-model-listener"; 101 102 105 106 private Configuration configuration; 107 108 111 112 private Storage storage; 113 114 117 118 private Repository repository; 119 120 123 124 private AdminModelListener adminlistener; 125 126 129 130 private Map instances; 131 132 private int range = -1; 133 134 public BasicAdminModel () { 135 instances = new WeakHashMap (); 136 } 137 138 142 public String [] listFc () { 143 return new String [] { 144 CONFIGURATION_BINDING, 145 STORAGE_BINDING, 146 ADMIN_MODEL_LISTENER_BINDING, 147 REPOSITORY_BINDING 148 }; 149 } 150 151 public Object lookupFc (final String clientItfName) { 152 if (CONFIGURATION_BINDING.equals(clientItfName)) { 153 return configuration; 154 } else if (STORAGE_BINDING.equals(clientItfName)) { 155 return storage; 156 } else if (ADMIN_MODEL_LISTENER_BINDING.equals(clientItfName)) { 157 return adminlistener; 158 } else if (REPOSITORY_BINDING.equals(clientItfName)) { 159 return repository; 160 } 161 return null; 162 } 163 164 public void bindFc (final String clientItfName, final Object serverItf) { 165 if (CONFIGURATION_BINDING.equals(clientItfName)) { 166 configuration = (Configuration)serverItf; 167 } else if (STORAGE_BINDING.equals(clientItfName)) { 168 storage = (Storage)serverItf; 169 } else if (ADMIN_MODEL_LISTENER_BINDING.equals(clientItfName)) { 170 adminlistener = (AdminModelListener)serverItf; 171 } else if (REPOSITORY_BINDING.equals(clientItfName)) { 172 repository = (Repository)serverItf; 173 } 174 } 175 176 public void unbindFc (final String clientItfName) { 177 if (CONFIGURATION_BINDING.equals(clientItfName)) { 178 configuration = null; 179 } else if (STORAGE_BINDING.equals(clientItfName)) { 180 storage = null; 181 } else if (ADMIN_MODEL_LISTENER_BINDING.equals(clientItfName)) { 182 adminlistener = null; 183 } else if (REPOSITORY_BINDING.equals(clientItfName)) { 184 repository = null; 185 } 186 } 187 188 192 public org.objectweb.fractal.api.Component getInstance (final Component model) { 193 if (!configuration.getRootComponent().contains(model)) { 194 return null; 195 } 196 return (org.objectweb.fractal.api.Component)instances.get(model); 197 } 198 199 201 public org.objectweb.fractal.api.Component createInstance ( 202 final Component model, 203 final org.objectweb.fractal.api.Component bootstrapComponent) throws Exception 204 { 205 if (!configuration.getRootComponent().contains (model)) { 206 return null; 207 } 208 if (getInstance(model) != null) { 209 throw new IllegalOperationException ( 210 "Instance already created !"); 211 } 212 213 storage.open ("tmp"); 215 try { 216 String root = repository.storeComponent (model, null, "inline"); 217 } catch (Exception ex) { 218 throw new IllegalOperationException (ex.getMessage()); 219 } finally { 220 storage.close(); 221 } 222 223 Factory f = FactoryFactory.getFactory( 224 "org.objectweb.fractal.gui.admin.model.TmpFactory", 225 FactoryFactory.FRACTAL_BACKEND, new HashMap ()); 226 227 org.objectweb.fractal.api.Component comp; 228 229 try { 230 Map ctxt = new HashMap (); 231 ctxt.put("bootstrap", bootstrapComponent); 232 comp = (org.objectweb.fractal.api.Component)f.newComponent(model.getType(), ctxt); 233 addInstance(model, comp); 234 if (model.getParent() != null && getInstance(model.getParent()) != null) { 235 subComponentAdded(model.getParent(), model, 0); 236 } 237 } catch (Exception ex) { 238 ex.printStackTrace(); 239 throw new IllegalOperationException ( 240 "No instance created : maybe, the exec. dir is no correct or missing"); 241 } 242 243 adminlistener.componentCreated(model); 244 return comp; 245 } 246 247 249 private void addInstance ( 250 final Component model, 251 final org.objectweb.fractal.api.Component instance) throws Exception 252 { 253 Component c = model; 254 if (model.getMasterComponent() != null) { 255 c = model.getMasterComponent(); 256 } 257 instances.put(c, instance); 258 List slaves = c.getSlaveComponents(); 259 for (int i = 0; i < slaves.size(); ++i) { 260 instances.put(slaves.get(i), instance); 261 } 262 263 List subComponents = model.getSubComponents(); 264 if (subComponents.size() > 0) { 265 ContentController cc = Fractal.getContentController(instance); 266 org.objectweb.fractal.api.Component[] subCi = cc.getFcSubComponents(); 267 268 for (int i = 0; i < subComponents.size(); ++i) { 269 Component subC = (Component)subComponents.get(i); 270 Set s = new HashSet (); 271 if (subC.getMasterComponent() != null) { 272 s.add(subC.getMasterComponent().getName()); 273 List l = subC.getMasterComponent().getSlaveComponents(); 274 for (int j = 0; j < l.size(); ++j) { 275 s.add(((Component)l.get(j)).getName()); 276 } 277 } else { 278 s.add(subC.getName()); 279 List l = subC.getSlaveComponents(); 280 for (int j = 0; j < l.size(); ++j) { 281 s.add(((Component)l.get(j)).getName()); 282 } 283 } 284 285 org.objectweb.fractal.api.Component subM = null; 286 for (int j = 0; j < subCi.length; ++j) { 287 org.objectweb.fractal.api.Component sci = subCi[j]; 288 if (s.contains(Fractal.getNameController(sci).getFcName())) { 289 subM = sci; 290 break; 291 } 292 } 293 294 if (subM == null) { 295 throw new Exception ("No instance for sub component '" + subC.getName() + "' " + s); 296 } 297 298 addInstance(subC, subM); 299 } 300 } 301 } 302 303 305 public void deleteInstance (final Component model) { 306 if (!configuration.getRootComponent().contains(model)) { 307 return; 308 } 309 if (getInstance(model) == null) { 310 throw new IllegalOperationException( 311 "Instance does not exist"); 312 } 313 if (isStarted(model)) { 314 throw new IllegalOperationException( 315 "Cannot delete an instance which is started"); 316 } 317 318 if (model.getParent() != null) { 319 if (isStarted(model.getParent())) { 320 throw new IllegalOperationException( 321 "Cannot delete an instance whose parent is started"); 322 } 323 324 org.objectweb.fractal.api.Component p = getInstance(model.getParent()); 325 org.objectweb.fractal.api.Component c = getInstance(model); 326 327 subComponentRemoved(model.getParent(), model, 0); 328 } 329 330 removeInstance(model); 331 332 adminlistener.componentDeleted(model); 333 } 334 335 private void removeInstance (final Component model) { 336 Component c = model; 337 if (model.getMasterComponent() != null) { 338 c = model.getMasterComponent(); 339 } 340 instances.remove(c); 341 List slaves = c.getSlaveComponents(); 342 for (int i = 0; i < slaves.size(); ++i) { 343 instances.remove(slaves.get(i)); 344 } 345 346 List subComponents = model.getSubComponents(); 347 for (int i = 0; i < subComponents.size(); ++i) { 348 removeInstance((Component)subComponents.get(i)); 349 } 350 } 351 352 354 public boolean isStarted (final Component model) { 355 org.objectweb.fractal.api.Component ci = getInstance(model); 356 if (ci != null) { 357 try { 358 LifeCycleController lc = Fractal.getLifeCycleController(ci); 359 return lc.getFcState().equals("STARTED"); 360 } catch (NoSuchInterfaceException e) { 361 return true; 362 } 363 } 364 return false; 365 } 366 367 369 public void start (final Component model) { 370 org.objectweb.fractal.api.Component ci = getInstance(model); 371 372 if (ci != null) { 373 try { 374 LifeCycleController lc = Fractal.getLifeCycleController(ci); 375 if (lc != null) { 376 lc.startFc(); 377 378 List lser = model.getServerInterfaces(); 380 415 } 416 adminlistener.componentStarted(model); 417 } catch (NoSuchInterfaceException e) { 418 } catch (IllegalLifeCycleException e) { 419 avert ("Cannot start this instance"); 421 } 422 } 423 } 424 425 427 public void stop (final Component model) { 428 org.objectweb.fractal.api.Component ci = getInstance(model); 429 if (ci != null) { 430 try { 431 LifeCycleController lc = Fractal.getLifeCycleController(ci); 432 if (lc != null) { 433 lc.stopFc(); 434 435 List lser = model.getServerInterfaces(); 437 468 } 469 adminlistener.componentStopped(model); 470 } catch (NoSuchInterfaceException e) { 471 } catch (IllegalLifeCycleException e) { 472 throw new IllegalOperationException ( 473 "Cannot stop this instance"); 474 } 475 } 476 } 477 478 482 public void canChangeRootComponent () { 483 } 485 486 public void canChangeName (final Component component) { 487 } 489 490 public void canChangeType (final Component component) { 491 } 493 494 public void canChangeImplementation (final Component component) { 495 org.objectweb.fractal.api.Component ci = getInstance(component); 496 if (ci != null) { 497 avert ("Cannot change the implementation of an instanciated component"); 499 } 500 } 501 502 public void canChangeInterfaceName (final Interface i) { 503 org.objectweb.fractal.api.Component ci = getInstance(i.getOwner()); 504 if (ci != null) { 505 avert ("Cannot change the name of an interface of an instanciated component"); 507 } 508 } 509 510 public void canChangeInterfaceSignature (final Interface i) { 511 org.objectweb.fractal.api.Component ci = getInstance(i.getOwner()); 512 if (ci != null) { 513 avert ("Cannot change the signature of an interface of an instanciated component"); 515 } 516 } 517 518 public void canChangeInterfaceContingency (final Interface i) { 519 org.objectweb.fractal.api.Component ci = getInstance(i.getOwner()); 520 if (ci != null) { 521 avert ("Cannot change the contingency of an interface of an instanciated component"); 523 } 524 } 525 526 public void canChangeInterfaceCardinality (final Interface i) { 527 org.objectweb.fractal.api.Component ci = getInstance(i.getOwner()); 528 if (ci != null) { 529 avert ("Cannot change the cardinality of an interface of an instanciated component"); 531 } 532 } 533 534 public void canAddClientInterface ( 535 final Component component, 536 final ClientInterface i) 537 { 538 org.objectweb.fractal.api.Component ci = getInstance(component); 539 if (ci != null) { 540 if (i.getMasterCollectionInterface() == null) { 541 avert ("Cannot add an interface to an instanciated component"); 543 } 544 } 545 } 546 547 public void canRemoveClientInterface ( 548 final Component component, 549 final ClientInterface i) 550 { 551 org.objectweb.fractal.api.Component ci = getInstance(component); 552 if (ci != null) { 553 if (i.getMasterCollectionInterface() == null) { 554 avert ("Cannot remove an interface from an instanciated component"); 556 } 557 } 558 } 559 560 public void canAddServerInterface ( 561 final Component component, 562 final ServerInterface i) 563 { 564 org.objectweb.fractal.api.Component ci = getInstance(component); 565 if (ci != null) { 566 if (i.getMasterCollectionInterface() == null) { 567 avert ("Cannot add an interface to an instanciated component"); 569 } 570 } 571 } 572 573 public void canRemoveServerInterface ( 574 final Component component, 575 final ServerInterface i) 576 { 577 org.objectweb.fractal.api.Component ci = getInstance(component); 578 if (ci != null) { 579 if (i.getMasterCollectionInterface() == null) { 580 avert ("Cannot remove an interface from an instanciated component"); 582 } 583 } 584 } 585 586 public void canBindInterface (final ClientInterface citf) { 587 if (isStarted(citf.getOwner())) { 588 } 591 } 592 593 public void canRebindInterface (final ClientInterface citf) { 594 if (isStarted(citf.getOwner())) { 595 avert ("Cannot rebind a client interface of a started component"); 597 } 598 } 599 600 public void canUnbindInterface (final ClientInterface citf) { 601 if (isStarted(citf.getOwner())) { 602 avert ("Cannot unbind a client interface of a started component"); 604 } 605 } 606 607 public void canChangeAttributeController (final Component component) { 608 org.objectweb.fractal.api.Component ci = getInstance(component); 609 if (ci != null) { 610 avert ("Cannot change the attribute controller " 612 +"of an instanciated component"); 613 } 614 } 615 616 public void canChangeAttribute ( 617 final Component component, 618 final String attributeName) 619 { 620 } 622 623 public void canChangeTemplateControllerDescriptor ( 624 final Component component) 625 { 626 org.objectweb.fractal.api.Component ci = getInstance(component); 627 if (ci != null) { 628 avert ("Cannot change the template controller descriptor" 630 +" of an instanciated component"); 631 } 632 } 633 634 public void canChangeComponentControllerDescriptor ( 635 final Component component) 636 { 637 org.objectweb.fractal.api.Component ci = getInstance(component); 638 if (ci != null) { 639 avert ("Cannot change the controller descriptor " 641 +"of an instanciated component"); 642 } 643 } 644 645 public void canAddSubComponent ( 646 final Component parent, 647 final Component child) 648 { 649 if (isStarted(parent) && getInstance(child) != null) { 650 avert ("Cannot add an instantiated sub component in a started component"); 652 } 653 } 654 655 public void canRemoveSubComponent ( 656 final Component parent, 657 final Component child) 658 { 659 if (isStarted(parent) && getInstance(child) != null) { 660 avert ("Cannot remove an instantiated sub component from a started component"); 662 } 663 } 664 665 669 public void changeCountChanged (final Component component, long changeCount) { 670 } 672 673 public void rootComponentChanged (final Component oldValue) { 674 } 676 677 public void nameChanged (final Component component, final String oldValue) { 678 org.objectweb.fractal.api.Component ci = getInstance(component); 679 if (ci != null) { 680 try { 681 NameController nc = Fractal.getNameController(ci); 682 nc.setFcName(component.getName()); 683 } catch (NoSuchInterfaceException e) { 684 avert (e.getMessage()); 685 } 686 } 687 } 688 689 public void typeChanged (final Component component, final String oldValue) { 690 } 692 693 public void implementationChanged ( 694 final Component component, 695 final String oldValue) 696 { 697 } 699 700 public void interfaceNameChanged (final Interface i, final String oldValue) { 701 } 703 704 public void interfaceSignatureChanged ( 705 final Interface i, 706 final String oldValue) 707 { 708 } 710 711 public void interfaceContingencyChanged ( 712 final Interface i, 713 final boolean oldValue) 714 { 715 } 717 718 public void interfaceCardinalityChanged ( 719 final Interface i, 720 final boolean oldValue) 721 { 722 } 724 725 public void clientInterfaceAdded ( 726 final Component component, 727 final ClientInterface i, 728 final int index) 729 { 730 Binding b = i.getBinding(); 732 if (b != null) { 733 interfaceBound(i, b.getServerInterface()); 734 } 735 } 736 737 public void clientInterfaceRemoved ( 738 final Component component, 739 final ClientInterface i, 740 final int index) 741 { 742 Binding b = i.getBinding(); 744 if (b != null) { 745 interfaceUnbound(i, b.getServerInterface()); 746 } 747 } 748 749 public void serverInterfaceAdded ( 750 final Component component, 751 final ServerInterface i, 752 final int index) 753 { 754 } 756 757 public void serverInterfaceRemoved ( 758 final Component component, 759 final ServerInterface i, 760 final int index) 761 { 762 } 764 765 public void interfaceBound ( 766 final ClientInterface citf, 767 final ServerInterface sitf) 768 { 769 org.objectweb.fractal.api.Component ci = getInstance(citf.getOwner()); 770 org.objectweb.fractal.api.Component si = getInstance(sitf.getOwner()); 771 if (ci != null && si != null) { 772 BindingController bc; 773 try { 774 bc = Fractal.getBindingController(ci); 775 Object itf; 776 if (sitf.isInternal()) { 777 itf = Fractal.getContentController(si).getFcInternalInterface(sitf.getName()); 778 } else { 779 itf = si.getFcInterface(sitf.getName()); 780 } 781 bc.bindFc (citf.getName(), itf); 782 } catch (Exception e) { 783 avert (e.getMessage()); 784 return; 785 } 786 } 787 } 788 789 public void interfaceRebound ( 790 final ClientInterface citf, 791 final ServerInterface oldSitf) 792 { 793 org.objectweb.fractal.api.Component ci = getInstance(citf.getOwner()); 794 interfaceUnbound(citf, oldSitf); 795 interfaceBound(citf, citf.getBinding().getServerInterface()); 796 } 797 798 public void interfaceUnbound ( 799 final ClientInterface citf, 800 final ServerInterface sitf) 801 { 802 org.objectweb.fractal.api.Component ci = getInstance(citf.getOwner()); 803 org.objectweb.fractal.api.Component si = getInstance(sitf.getOwner()); 804 if (ci != null && si != null) { 805 BindingController bc; 806 try { 807 bc = Fractal.getBindingController(ci); 808 bc.unbindFc (citf.getName()); 809 } catch (Exception e) { 810 avert (e.getMessage()); 811 } 812 } 813 } 814 815 public void attributeControllerChanged ( 816 final Component component, 817 final String oldValue) 818 { 819 } 821 822 public void attributeChanged ( 823 final Component component, 824 final String attributeName, 825 final String oldValue) 826 { 827 org.objectweb.fractal.api.Component ci = getInstance(component); 828 if (ci != null) { 829 try { 830 AttributeController ac = (AttributeController)ci.getFcInterface( 831 "attribute-controller"); 832 if (ac != null) { 833 Class acc = ac.getClass(); 834 835 String attrName = Character.toUpperCase(attributeName.charAt(0)) + attributeName.substring(1); 836 String getterName = "get" + attrName; 837 String setterName = "set" + attrName; 838 Method getter = acc.getMethod (getterName, new Class [0]); 839 Method setter = acc.getMethod (setterName, new Class [] { 840 getter.getReturnType() 841 }); 842 843 Class attrType = getter.getReturnType(); 844 String v = component.getAttribute(attributeName); 845 Object value; 846 if (attrType.equals(String .class)) { 847 value = v; 848 } else if (attrType.isPrimitive()) { 849 if (attrType.equals(Integer.TYPE)) { 850 value = Integer.valueOf(v); 851 } else if (attrType.equals(Long.TYPE)) { 852 value = Long.valueOf(v); 853 } else if (attrType.equals(Float.TYPE)) { 854 value = Float.valueOf(v); 855 } else if (attrType.equals(Double.TYPE)) { 856 value = Double.valueOf(v); 857 } else if (attrType.equals(Byte.TYPE)) { 858 value = Byte.valueOf(v); 859 } else if (attrType.equals(Character.TYPE)) { 860 if (v.length() != 1) { 861 avert ("Bad char value: " + v); 862 return; 863 } 864 value = new Character (v.charAt(0)); 865 } else if (attrType.equals(Short.TYPE)) { 866 value = Short.valueOf(v); 867 } else if (attrType.equals(Boolean.TYPE)) { 868 if (!v.equals("true") && 869 !v.equals("false")) 870 { 871 avert ("Bad boolean value: " + v); 872 return; 873 } 874 value = new Boolean (v.equals("true")); 875 } else { 876 avert ("Unexpected case"); 877 return; 878 } 879 } else { 880 avert ("Unsupported attribute type: " + attrType); 881 return; 882 } 883 setter.invoke(ac, new Object []{value}); 884 } 885 } catch (Exception ex) { 886 avert (ex.getMessage()); 887 } 888 } 889 } 890 891 public void templateControllerDescriptorChanged ( 892 final Component component, 893 final String oldValue) 894 { 895 } 897 898 public void componentControllerDescriptorChanged ( 899 final Component component, 900 final String oldValue) 901 { 902 } 904 905 public void subComponentAdded ( 906 final Component parent, 907 final Component child, 908 final int index) 909 { 910 org.objectweb.fractal.api.Component pi = getInstance(parent); 911 org.objectweb.fractal.api.Component ci = getInstance(child); 912 if (pi != null && ci != null) { 913 try { 914 ContentController cc = Fractal.getContentController(pi); 915 cc.addFcSubComponent(ci); 916 List itfs = child.getClientInterfaces(); 917 for (int i = 0; i < itfs.size(); ++i) { 918 Binding b = ((ClientInterface)itfs.get(i)).getBinding(); 919 if (b != null) { 920 addBinding(b, parent, child); 921 } 922 } 923 itfs = child.getServerInterfaces(); 924 for (int i = 0; i < itfs.size(); ++i) { 925 List bs = ((ServerInterface)itfs.get(i)).getBindings(); 926 for (int j = 0; j < bs.size(); ++j) { 927 Binding b = (Binding)bs.get(j); 928 addBinding(b, parent, child); 929 } 930 } 931 } catch (Exception e) { 932 avert(e.getMessage()); 933 } 934 } 935 } 936 937 private void addBinding (Binding b, Component parent, Component child) throws Exception { 938 Component c = b.getClientInterface().getOwner(); 939 org.objectweb.fractal.api.Component ci = getInstance(c); 940 String citf = b.getClientInterface().getName(); 941 Component s = b.getServerInterface().getOwner(); 942 if ((child == s || parent == s || parent == s.getParent()) && 943 (child == c || parent == c || parent == c.getParent())) 944 { 945 org.objectweb.fractal.api.Component si = getInstance(s); 946 Object sitf; 947 if (b.getServerInterface().isInternal()) { 948 sitf = Fractal.getContentController(si).getFcInternalInterface( 949 b.getServerInterface().getName()); 950 } else { 951 sitf = si.getFcInterface(b.getServerInterface().getName()); 952 } 953 Fractal.getBindingController(ci).bindFc(citf, sitf); 954 } 955 } 956 957 public void subComponentRemoved ( 958 final Component parent, 959 final Component child, 960 final int index) 961 { 962 org.objectweb.fractal.api.Component pi = getInstance(parent); 963 org.objectweb.fractal.api.Component ci = (org.objectweb.fractal.api.Component)instances.get(child); 964 if (pi != null && ci != null) { 965 try { 966 List itfs = child.getClientInterfaces(); 967 for (int i = 0; i < itfs.size(); ++i) { 968 Binding b = ((ClientInterface)itfs.get(i)).getBinding(); 969 if (b != null) { 970 removeBinding(b, parent, child); 971 } 972 } 973 itfs = child.getServerInterfaces(); 974 for (int i = 0; i < itfs.size(); ++i) { 975 List bs = ((ServerInterface)itfs.get(i)).getBindings(); 976 for (int j = 0; j < bs.size(); ++j) { 977 Binding b = (Binding)bs.get(j); 978 removeBinding(b, parent, child); 979 } 980 } 981 982 ContentController cc; 983 cc = Fractal.getContentController(pi); 984 cc.removeFcSubComponent(ci); 985 } catch (Exception e) { 986 e.printStackTrace(); 987 avert (e.getMessage()); 988 } 989 } 990 } 991 992 private void removeBinding (Binding b, Component parent, Component child) throws Exception { 993 Component c = b.getClientInterface().getOwner(); 994 org.objectweb.fractal.api.Component ci = 995 (org.objectweb.fractal.api.Component)instances.get(c); 996 Component s = b.getServerInterface().getOwner(); 997 if ((child == s || parent == s || parent == s.getParent()) && 998 (child == c || parent == c || parent == c.getParent())) 999 { 1000 Fractal.getBindingController(ci).unbindFc(b.getClientInterface().getName()); 1001 } 1002 } 1003 1004 private void avert (String motif) { 1005 JOptionPane.showMessageDialog ( 1006 null, motif, "Error", JOptionPane.ERROR_MESSAGE); 1007 throw new IllegalOperationException(motif); 1008 } 1009 1010 1013 1014 1017 static public final Font fnta13 = new Font ("Arial", Font.PLAIN, 13); 1018 1019 class FrameChoiceBox extends JDialog implements ActionListener { 1020 JPanel panel = new JPanel(); 1021 JButton [] unit; 1022 1023 protected void processWindowEvent(WindowEvent e) { 1024 if (e.getID() == WindowEvent.WINDOW_CLOSING) { cancel(); } 1025 super.processWindowEvent(e); 1026 } 1027 1028 void cancel() { range = -1; dispose(); } 1029 1030 public void actionPerformed (ActionEvent e) { 1031 range = -1; 1032 for (int i = 0; i < unit.length; i++) { 1033 if (e.getActionCommand().equals(unit[i].getText())) { 1034 range = i; break; 1035 } 1036 } 1037 dispose(); 1038 } 1039 1040 public FrameChoiceBox (String titre, String [] items) { 1041 unit = new JButton [items.length]; 1042 enableEvents (AWTEvent.WINDOW_EVENT_MASK); 1043 Dimension dim = new Dimension (300, 20+items.length*25); 1044 1045 try { 1046 this.setTitle(titre); 1047 Container cp = getContentPane (); 1048 cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS)); 1049 setResizable(true); 1050 1051 Color curcol = Color.lightGray; 1052 for (int i = 0; i < items.length; i++) { 1053 unit[i] = new JButton (items[i]); 1054 unit[i].setPreferredSize(new Dimension(150, 20)); 1055 unit[i].setFont(fnta13); 1056 FontMetrics fm = unit[i].getFontMetrics(fnta13); 1057 int d = 0; 1058 for (int z = 0; z < items[i].length(); z++) 1059 d = d + fm.charWidth(items[i].charAt(z)); 1060 unit[i].setBorder(new EmptyBorder (2, 1, 2, 70-d)); 1061 unit[i].setBackground(curcol); 1062 unit[i].setForeground(Color.black); 1063 unit[i].addActionListener(this); 1064 cp.add(unit[i]); 1065 } 1066 setModal(true); 1067 this.setSize(dim); 1068 this.setLocation(300, 300); 1069 pack (); 1070 show (); 1071 } 1072 catch(Exception e) { e.printStackTrace(); } 1073 } 1074 } 1075} 1077 | Popular Tags |