1 19 20 package org.objectweb.jac.aspects.gui; 21 22 import java.util.Arrays ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Vector ; 28 import org.apache.log4j.Logger; 29 import org.objectweb.jac.aspects.integrity.RoleWrapper; 30 import org.objectweb.jac.aspects.session.SessionAC; 31 import org.objectweb.jac.core.Collaboration; 32 import org.objectweb.jac.core.Interaction; 33 import org.objectweb.jac.core.ObjectRepository; 34 import org.objectweb.jac.core.Wrappee; 35 import org.objectweb.jac.core.Wrapping; 36 import org.objectweb.jac.core.rtti.AbstractMethodItem; 37 import org.objectweb.jac.core.rtti.ClassItem; 38 import org.objectweb.jac.core.rtti.ClassRepository; 39 import org.objectweb.jac.core.rtti.CollectionItem; 40 import org.objectweb.jac.core.rtti.FieldItem; 41 import org.objectweb.jac.core.rtti.MemberItem; 42 import org.objectweb.jac.core.rtti.MethodItem; 43 import org.objectweb.jac.core.rtti.NamingConventions; 44 import org.objectweb.jac.core.rtti.RttiAC; 45 import org.objectweb.jac.util.ExtArrays; 46 import org.objectweb.jac.util.Strings; 47 48 53 54 public class EventHandler implements FieldUpdate { 55 static Logger logger = Logger.getLogger("gui.events"); 56 static Logger loggerDnd = Logger.getLogger("gui.dnd"); 57 static Logger loggerAssoc = Logger.getLogger("associations"); 58 59 static EventHandler singleton = new EventHandler(); 60 61 public static EventHandler get() { 62 return singleton; 63 } 64 65 73 74 public void onSelection( 75 DisplayContext context, 76 MemberItem container, 77 Object selectedObject, 78 FieldItem field, 79 Object extraOption) 80 { 81 onSelection( 82 context, 83 container, 84 selectedObject, 85 field, 86 extraOption, 87 false); 88 } 89 90 98 99 public void onView( 100 DisplayContext context, 101 MemberItem container, 102 Object selectedObject, 103 FieldItem field, 104 Object extraOption) 105 { 106 onSelection( 107 context, 108 container, 109 selectedObject, 110 field, 111 extraOption, 112 true); 113 } 114 115 129 public void onSelection( 130 DisplayContext context, 131 MemberItem container, 132 Object selectedObject, 133 FieldItem field, 134 Object extraOption, 135 boolean forceView) 136 { 137 logger.debug("onSelection(" 138 + (container != null ? container.getLongName() : "null") + "," 139 + Strings.hex(selectedObject) 140 + ",field="+ (field != null ? field.getLongName() : "null") 141 + ",force=" + forceView + ")"); 142 CustomizedDisplay display = context.getDisplay(); 143 ViewFactory factory = display.getFactory(); 144 CustomizedView customizedView = context.getCustomizedView(); 145 146 Collaboration.get().addAttribute(GuiAC.DISPLAY_CONTEXT, context); 147 148 if (container instanceof CollectionItem) { 150 if (GuiAC.isChoiceView((CollectionItem) container) 151 && !GuiAC.isExternalChoiceView((CollectionItem) container)) { 152 display.refresh(); 153 return; 154 } 155 } 156 157 MethodItem handler = null; 158 FieldItem targetField = null; 159 if (container != null) { 160 handler = GuiAC.getSelectionHandler(container); 161 targetField = 162 (FieldItem) container.getAttribute(GuiAC.SELECTION_TARGET); 163 } 164 165 if (customizedView == null && handler == null && targetField == null) { 166 if (forceView) { 167 logger.debug("showing in dialog mode " + "(customizedView==null)"); 168 display.show(selectedObject); 169 } else { 170 logger.debug("onSelection aborted " + "(customizedView==null)"); 171 display.refresh(); 172 } 173 return; 174 } 175 176 if (handler != null) { 177 try { 178 logger.debug("invoking selectionHandler " + handler); 179 Object result = 180 handler.invokeStatic( 181 new Object [] { context, container, selectedObject }); 182 if (handler.getType() != void.class && result != null) { 183 if (handler.getType() == HandlerResult.class) { 184 handleResult(context,(HandlerResult)result); 185 } else { 186 onSelection(context, null, result, null, null); 187 } 188 } 189 } catch (Exception e) { 190 logger.error( 191 "gui: invocation of event handler " + handler 192 + " for onSelection failed with " + e); 193 e.printStackTrace(); 194 } 195 } 196 197 if (targetField != null) { 198 selectedObject = targetField.getThroughAccessor(selectedObject); 199 logger.debug("selected target -> " + selectedObject); 200 } 201 202 if (customizedView == null) 203 return; 204 CustomizedGUI customized = customizedView.getCustomizedGUI(); 205 List targets = customized.getFieldTargets(container); 206 logger.debug("targets=" + targets); 207 208 if (targets != null) { 209 Iterator it = targets.iterator(); 210 while (it.hasNext()) { 211 Target target = (Target) it.next(); 213 logger.debug("target.path = " + target.panePath); 214 224 225 String paneId = target.panePath; 226 CompositeView targetView = 227 (CompositeView) customizedView.getView(paneId); 228 229 if (selectedObject != null) { 230 231 Collaboration.get().addAttribute( 232 GuiAC.SMALL_VIEW, 233 container.getAttribute(GuiAC.SMALL_TARGET_CONTAINER)); 234 try { 235 View view = 237 invalidatePane( 238 factory, 239 context, 240 targetView, 241 target.viewType, 242 target.viewParams, 243 selectedObject, 244 extraOption); 245 246 if (field != null && view != null) 247 setFocus(view, field, extraOption); 248 249 } finally { 250 Collaboration.get().removeAttribute(GuiAC.SMALL_VIEW); 251 } 252 } 253 maybeInvalidatePane(factory, context, customizedView, paneId); 255 } 256 display.refresh(); 257 } else if (forceView) { 258 if (container != null 259 && container.getAttribute(GuiAC.NEW_WINDOW) != null) { 260 display.openView(selectedObject); 261 } else { 262 display.show(selectedObject); 263 } 264 } 265 266 } 267 268 public void handleResult(DisplayContext context, HandlerResult hres) { 269 CustomizedView customizedView = context.getCustomizedView(); 270 CustomizedDisplay display = context.getDisplay(); 271 DisplayContext newContext = 272 new DisplayContext( 273 display, 274 hres.target != null 275 ? hres.target 276 : customizedView); 277 if (hres.target != null) 278 customizedView = hres.target; 279 onSelection( 280 newContext, 281 (CollectionItem) hres.container, 282 hres.object, 283 hres.field, 284 hres.extraOption); 285 } 286 287 292 public void maybeInvalidatePane( 293 ViewFactory factory, 294 DisplayContext context, 295 CustomizedView customizedView, 296 String selectedPaneID) 297 { 298 CustomizedGUI customized = customizedView.getCustomizedGUI(); 299 String invalidPaneID = customized.getInvalidPane(selectedPaneID); 300 logger.debug("invalidPane " + selectedPaneID + " -> " + invalidPaneID); 301 if (invalidPaneID != null) { 302 invalidatePane( 303 factory, 304 context, 305 (CompositeView) customizedView.getView(invalidPaneID), 306 "Empty", 307 ExtArrays.emptyStringArray, 308 null, 309 null); 310 } 311 } 312 313 322 public void setFocus(View top, FieldItem field, Object option) { 323 logger.debug("setFocus " + top + "," + field.getLongName() + "," + option); 324 if (top instanceof CompositeView) { 325 Iterator it = ((CompositeView) top).getViews().iterator(); 326 while (it.hasNext()) { 327 View view = (View) it.next(); 328 if (view instanceof TabsView) { 329 String [] categories = GuiAC.getCategories(field); 330 if (categories != null && categories.length > 0) { 331 ((TabsView) view).select(categories[0]); 332 setFocus( 333 ((CompositeView) view).getView(categories[0]), 334 field, 335 option); 336 } 337 } else { 338 setFocus(view, field, option); 339 } 340 } 341 } else if (top instanceof FieldEditor) { 342 FieldEditor editor = (FieldEditor) top; 343 if (editor.getField().equals(field)) { 344 editor.getContext().getCustomizedView().requestFocus(); 345 editor.onSetFocus(option); 346 } 347 } 348 } 349 350 354 386 387 393 View invalidatePane( 394 ViewFactory factory, 395 DisplayContext context, 396 CompositeView panel, 397 String viewType, 398 String [] viewParams, 399 Object selectedObject, 400 Object extraInfo) 401 { 402 logger.debug("invalidatePane("+panel+"," 403 +viewType+Arrays.asList(viewParams)+ ","+selectedObject+")"); 404 Collection comps = panel.getViews(); 405 View view = null; 406 Object [] parameters; 408 if (selectedObject != null) { 409 parameters = ExtArrays.add(selectedObject, viewParams); 410 } else { 411 parameters = viewParams; 412 } 413 if (!panel.containsView(viewType, parameters)) { 414 logger.debug("new view " + viewType + ", extraInfo=" + extraInfo); 415 view = 416 factory.createView( 417 "target[?]", 418 viewType, 419 parameters, 420 context); 421 if (extraInfo instanceof CollectionPosition && 422 GuiAC.hasSetNavBar( 423 context.getCustomizedView().getCustomizedGUI(), 424 ((CollectionPosition)extraInfo).getCollection())) 425 { 426 view.setParentView( 427 view = 428 factory.createView( 429 "collectionItemView", 430 "CollectionItemView", 431 new Object [] { 432 view, 433 extraInfo, 434 viewType, 435 viewParams, 436 null }, 437 context)); 438 } 439 logger.debug("new view CREATED"); 440 panel.addView(view, GuiAC.toString(selectedObject)); 441 442 } else { 443 Iterator i = comps.iterator(); 444 while (i.hasNext()) { 445 view = (View) i.next(); 446 if (view.equalsView(viewType,parameters)) { 447 return view; 448 } 449 } 450 return null; 451 } 452 453 return view; 454 } 455 456 459 public static void initAutocreatedObject( 460 Object created, 461 Object substance, 462 FieldItem role) 463 { 464 FieldItem oppositeRole = 465 (FieldItem) role.getAttribute(RttiAC.OPPOSITE_ROLE); 466 logger.debug("oppositeRole = " + oppositeRole); 467 if (oppositeRole != null) { 468 RoleWrapper.disableRoleUpdate(oppositeRole); 469 try { 470 if (oppositeRole instanceof CollectionItem) { 471 ((CollectionItem) oppositeRole).addThroughAdder( 472 created, 473 substance); 474 } else { 475 oppositeRole.setThroughWriter(created, substance); 476 } 477 } catch (Exception e) { 478 logger.error( 479 "initAutocreatedObject(created=" + created 480 + ",substance=" + substance 481 + "role=" + role 482 + "): " + e); 483 } finally { 484 RoleWrapper.enableRoleUpdate(oppositeRole); 485 } 486 } 487 } 488 489 497 public void onNodeSelection( 498 DisplayContext context, 499 AbstractNode node, 500 boolean forceView) 501 { 502 logger.debug("onNodeSelection " + node); 503 AbstractNode parentNode = (AbstractNode) node.getParent(); 504 if (parentNode != null) { 505 onNodeSelection(context, parentNode, false); 507 } 508 if (node instanceof ObjectNode) { 509 onSelection( 510 context, 511 ((ObjectNode) node).getRelation(), 512 node.getUserObject(), 513 null, 514 null, 515 forceView); 516 } else if (node instanceof RootNode) { 517 onSelection( 518 context, 519 null, 520 node.getUserObject(), 521 null, 522 null, 523 forceView); 524 } 525 } 526 527 536 public void onInvokeDirect( 537 DisplayContext context, 538 Object substance, 539 AbstractMethodItem method, 540 Object [] parameters) 541 { 542 Collaboration.get().addAttribute(GuiAC.DISPLAY_CONTEXT, context); 543 method.invoke(substance, parameters); 544 } 545 546 556 public InvokeThread onInvoke( 557 DisplayContext context, 558 InvokeEvent invoke) 559 { 560 return onInvoke(context, invoke, null, null); 561 } 562 563 575 public InvokeThread onInvoke( 576 DisplayContext context, 577 InvokeEvent invoke, 578 String [] attrNames, 579 Object [] attrValues) 580 { 581 return onInvoke(context, invoke, true, attrNames, attrValues); 582 } 583 584 598 public InvokeThread onInvoke( 599 DisplayContext context, 600 InvokeEvent invoke, 601 boolean askFormParameters, 602 String [] attrNames, 603 Object [] attrValues) 604 { 605 logger.debug("onInvoke(" + context + "," + invoke + ")"); 606 CustomizedDisplay display = context.getDisplay(); 607 if (attrNames == null) 608 attrNames = ExtArrays.emptyStringArray; 609 if (attrValues == null) 610 attrValues = ExtArrays.emptyStringArray; 611 Class [] parameterTypes = invoke.getMethod().getParameterTypes(); 612 int parametersLeft = parameterTypes.length; 613 Object [] parameters = invoke.getParameters(); 614 if (parameters == null) { 615 parameters = new Object [parameterTypes.length]; 616 } else if (parameters.length < parameterTypes.length) { 617 parametersLeft -= parameters.length; 620 Object [] tmp = new Object [parameterTypes.length]; 621 System.arraycopy( 622 parameters, 623 0, 624 tmp, 625 parameterTypes.length - parameters.length, 626 parameters.length); 627 parameters = tmp; 628 } 629 if (parameters.length > 0 630 && parameterTypes[0] == DisplayContext.class) { 631 parametersLeft--; 632 parameters[0] = context; 633 } 634 invoke.setParameters(parameters); 635 Object sid = Collaboration.get().getAttribute(SessionAC.SESSION_ID); 637 if (parametersLeft == 0) { 638 logger.debug("Invoking " + invoke); 639 String [] names = new String [2 + attrNames.length]; 640 Object [] values = new Object [2 + attrNames.length]; 641 names[0] = GuiAC.DISPLAY_CONTEXT; 642 values[0] = context; 643 names[1] = SessionAC.SESSION_ID; 644 values[1] = sid; 645 System.arraycopy(attrNames, 0, names, 2, attrNames.length); 646 System.arraycopy(attrValues, 0, values, 2, attrNames.length); 647 return 648 InvokeThread.run( 649 invoke, 650 null, 651 null, 652 names, 653 values); 654 } else { 655 logger.debug("Invoking " + invoke + 657 " (ask for parameters is on, " 658 + parametersLeft + " parameters left)"); 659 660 String [] names = new String [4 + attrNames.length]; 661 Object [] values = new Object [4 + attrNames.length]; 662 names[0] = GuiAC.DISPLAY_CONTEXT; 663 values[0] = context; 664 names[1] = SessionAC.SESSION_ID; 665 values[1] = sid; 666 names[2] = GuiAC.ASK_FOR_PARAMETERS; 667 names[3] = GuiAC.INVOKED_METHOD; 668 if (ExtArrays.indexOf(parameters, null) != -1 && askFormParameters) { 670 values[2] = invoke.getMethod().getConcreteMethod(); 671 values[3] = invoke.getMethod(); 672 } 673 674 System.arraycopy(attrNames, 0, names, 4, attrNames.length); 675 System.arraycopy(attrValues, 0, values, 4, attrNames.length); 676 return 677 InvokeThread.run( 678 invoke, 679 null, 680 null, 681 names, 682 values); 683 } 684 } 685 686 692 public Object onInvokeSynchronous( 693 DisplayContext context, 694 InvokeEvent invoke) 695 { 696 logger.debug("onInvokeSynchronous(" + context + "," + invoke + ")"); 697 CustomizedDisplay display = context.getDisplay(); 698 Class [] parameterTypes = invoke.getMethod().getParameterTypes(); 699 int parametersLeft = parameterTypes.length; 700 Object [] parameters = invoke.getParameters(); 701 if (parameters == null) { 702 parameters = new Object [parameterTypes.length]; 703 } else if (parameters.length < parameterTypes.length) { 704 parametersLeft -= parameters.length; 707 Object [] tmp = new Object [parameterTypes.length]; 708 System.arraycopy( 709 parameters, 710 0, 711 tmp, 712 parameterTypes.length - parameters.length, 713 parameters.length); 714 parameters = tmp; 715 } 716 if (parameters.length > 0 717 && parameterTypes[0] == DisplayContext.class) { 718 parametersLeft--; 719 parameters[0] = context; 720 } 721 722 String [] names; 723 Object [] values; 724 725 Object sid = Collaboration.get().getAttribute(SessionAC.SESSION_ID); 727 if (parametersLeft == 0) { 728 logger.debug("Invoking " + invoke); 729 names = 730 new String [] { GuiAC.DISPLAY_CONTEXT, SessionAC.SESSION_ID }; 731 values = new Object [] { context, sid }; 732 } else { 733 logger.debug("Invoking " + invoke 735 + " (ask for parameters is on, " 736 + parametersLeft + " parameters left)"); 737 names = 738 new String [] { 739 GuiAC.DISPLAY_CONTEXT, 740 SessionAC.SESSION_ID, 741 GuiAC.ASK_FOR_PARAMETERS }; 742 values = new Object [] { context, sid, invoke.getMethod() }; 743 } 744 745 invoke.setParameters(parameters); 746 InvokeThread thread = 747 new InvokeThread( 748 invoke, 749 null, 750 null, 751 names, 752 values); 753 thread.start(); 754 return thread.getReturnValue(); 755 } 756 757 763 public void onAddToCollection( 764 DisplayContext context, 765 AddEvent add) 766 { 767 onAddToCollection(context, add, false); 768 } 769 770 778 public void onAddToCollection( 779 DisplayContext context, 780 AddEvent add, 781 boolean noAutoCreate) 782 { 783 logger.debug("onAddToCollection "+add 784 + "; noAutoCreate=" + noAutoCreate); 785 CollectionItem collection = add.getCollection(); 786 MethodItem addMethod = collection.getAdder(); 787 Collaboration collab = Collaboration.get(); 788 FieldItem oppositeRole = 789 (FieldItem) collection.getAttribute(RttiAC.OPPOSITE_ROLE); 790 loggerAssoc.debug("opposite_role = " + oppositeRole); 791 if (oppositeRole instanceof CollectionItem) { 792 loggerAssoc.debug("Ignoring collection oppositeRole " + oppositeRole); 793 oppositeRole = null; 794 } 795 796 try { 797 if (addMethod != null) { 798 logger.debug("Invoking add method " + addMethod.getName() 799 + " on collection owner"); 800 801 if (noAutoCreate) { 802 ClassItem type = 803 ClassRepository.get().getClass( 804 addMethod.getParameterTypes()[0]); 805 onInvoke( 806 context, 807 new InvokeEvent( 808 add.getSource(), 809 add.getSubstance(), 810 addMethod), 811 new String [] { GuiAC.NO_AUTO_CREATE, GuiAC.VIEW }, 812 new Object [] { type, this }); 813 } else { 814 onInvoke( 815 context, 816 new InvokeEvent( 817 add.getSource(), 818 add.getSubstance(), 819 addMethod), 820 new String [] { GuiAC.VIEW, GuiAC.OPPOSITE_ROLE }, 821 new Object [] { this, oppositeRole }); 822 } 823 } else { 824 logger.debug("No adder for " + collection); 825 context.getDisplay().refresh(); 826 847 } 848 } finally { 849 collab.removeAttribute(GuiAC.OPPOSITE_ROLE); 850 } 851 } 852 853 861 public void onRemoveFromCollection( 862 DisplayContext context, 863 RemoveEvent remove, 864 boolean askFormParameters) 865 { 866 CollectionItem collection = remove.getCollection(); 867 Object selected = remove.getRemoved(); 868 MethodItem remover = collection.getRemover(); 869 if (remover != null) { 870 logger.debug("Invoking remove method " 871 + remover.getName() 872 + " on collection owner"); 873 874 if (collection.isMap() && selected instanceof Map.Entry ) { 875 selected = ((Map.Entry ) selected).getKey(); 878 } 879 880 try { 881 if (selected != null) 882 onInvoke( 883 context, 884 new InvokeEvent( 885 remove.getSource(), 886 remove.getSubstance(), 887 remover, 888 new Object [] {selected}), 889 false, 890 ExtArrays.emptyStringArray, 891 ExtArrays.emptyObjectArray); 892 else 893 onInvoke( 894 context, 895 new InvokeEvent( 896 remove.getSource(), 897 remove.getSubstance(), 898 remover, 899 new Object [] {selected}), 900 askFormParameters, 901 ExtArrays.emptyStringArray, 902 ExtArrays.emptyObjectArray); 903 904 907 CustomizedView customizedView = context.getCustomizedView(); 908 if (customizedView != null) { 909 CustomizedGUI customized = 910 customizedView.getCustomizedGUI(); 911 List targets = customized.getFieldTargets(collection); 912 913 if (targets != null) { 914 Iterator it = targets.iterator(); 915 while (it.hasNext()) { 916 Target target = (Target) it.next(); 917 CompositeView targetView = 918 (CompositeView) customizedView.getView( 919 target.panePath); 920 if (targetView == null) 921 continue; 922 923 Object [] parameters = new Object [] {selected}; 924 Iterator it2 = targetView.getViews().iterator(); 925 while (it2.hasNext()) { 926 View view = (View) it2.next(); 927 928 View view2 = null; 929 if (view 930 instanceof AbstractCollectionItemView) { 931 view2 = view; 932 view = 933 ((AbstractCollectionItemView) view) 934 .getView(); 935 } 936 937 if (view.equalsView(view.getType(),parameters)) { 938 if (view2 != null) { 939 view.close(true); 940 view = view2; 941 } 942 ((CompositeView)view.getParentView()) 943 .removeView(view,true); 944 view.close(true); 946 947 it2 = targetView.getViews().iterator(); 948 } 949 } 950 } 951 } 952 } 953 } catch (Exception e) { 954 logger.error( 955 "failed to remove " 956 + ((selected != null) ? selected : "element") 957 + " from collection"); 958 e.printStackTrace(); 959 } 960 } else { 961 context.getDisplay().showError( 962 "Cannot Remove", 963 "No remover method available for collection " + collection); 964 } 966 } 967 968 977 public Object onCreateObject( 978 DisplayContext context, 979 ClassItem cli, 980 Object substance, 981 FieldItem field) 982 { 983 logger.debug("onCreateObject(" + cli.getName() + "," + field + ")"); 984 985 Vector classes = new Vector (cli.getChildren()); 986 classes.add(cli); 987 988 Object newInstance = null; 989 try { 990 991 Collaboration collab = Collaboration.get(); 992 993 Object fieldChoice = field!=null ? field.getAttribute(GuiAC.FIELD_CHOICE) : null; 994 if (fieldChoice instanceof CollectionItem) { 995 CollectionItem choice = (CollectionItem)fieldChoice; 996 collab.addAttribute(GuiAC.AUTOCREATE_REASON, 997 new Interaction(null, 998 (Wrappee)choice.getSubstance(substance), 999 choice.getAdder(),new Object [1])); 1000 try { 1001 newInstance = cli.newInstance(); 1002 } finally { 1003 collab.removeAttribute(GuiAC.AUTOCREATE_REASON); 1004 } 1005 onInvokeDirect( 1006 context, 1007 choice.getSubstance(substance), 1008 choice.getAdder(), 1009 new Object [] {newInstance}); 1010 } else { 1011 newInstance = cli.newInstance(); 1012 } 1013 1014 if (substance != null && field != null) { 1015 MethodItem init = GuiAC.getInitiliazer(field); 1016 if (init != null) { 1017 init.invoke(substance, new Object [] { newInstance }); 1018 } 1019 } 1020 1021 FieldItem oppositeRole = setOppositeRole(field); 1022 collab.addAttribute(GuiAC.AUTO_CREATION, Boolean.TRUE); 1024 try { 1025 boolean ok = 1026 context.getDisplay().showModal( 1027 newInstance, 1028 "Object", 1029 new String [] {GuiAC.AUTOCREATE_VIEW}, 1030 "New " + NamingConventions.getShortClassName(cli), 1031 "Fill the needed information and validate.", 1032 context.getWindow(), 1033 true, 1034 true, 1035 false); 1036 1037 if (!ok) { 1038 logger.debug("Creation of " + cli.getName() + " cancelled"); 1039 ObjectRepository.delete((Wrappee) newInstance); 1040 newInstance = null; 1041 } 1042 } finally { 1043 if (oppositeRole != null) 1044 collab.removeAttribute(GuiAC.OPPOSITE_ROLE); 1045 collab.removeAttribute(GuiAC.AUTO_CREATION); 1047 } 1048 } catch (Exception e) { 1049 logger.error("onCreateObject("+cli.getName()+","+ 1050 substance+","+field+") failed",e); 1051 } 1052 return newInstance; 1053 } 1054 1055 public void onDropObject( 1056 DisplayContext context, 1057 Object target, 1058 Object droppedObject, 1059 Object source, 1060 boolean copy) 1061 { 1062 logger.debug("onDropObject(" + target + "," + droppedObject + ")"); 1063 ClassItem cli = ClassRepository.get().getClass(target); 1064 Class objectType = droppedObject.getClass(); 1065 CollectionItem[] cols = cli.getCollections(); 1066 for (int i = 0; i < cols.length; i++) { 1067 CollectionItem c = cols[i]; 1068 loggerDnd.debug("checking collection " + c); 1069 MethodItem adder = c.getAdder(); 1070 if (adder != null) { 1071 loggerDnd.debug("types(" + adder.getParameterTypes()[0] + "," + objectType + ")"); 1072 if (adder.getParameterTypes()[0] == objectType) { 1073 if (!copy && GuiAC.isRemovable(c) && GuiAC.isAddable(c)) { 1074 loggerDnd.debug("moving object..."); 1075 c.removeThroughRemover(source, droppedObject); 1076 c.addThroughAdder(target, droppedObject); 1077 } else if ( 1078 copy && GuiAC.isRemovable(c) && GuiAC.isAddable(c)) { 1079 loggerDnd.debug("copying object..."); 1080 Wrapping.clone(droppedObject); 1081 c.addThroughAdder(target, droppedObject); 1082 } 1083 } 1084 } 1085 } 1086 } 1087 1088 public void fieldUpdated( 1089 Object substance, 1090 FieldItem field, 1091 Object value, 1092 Object param) 1093 { 1094 CompositeView view = (CompositeView) param; 1095 logger.debug("rebuilding view " + view); 1096 view.removeAllViews(false); 1097 GenericFactory.fillObjectView( 1098 view, 1099 ClassRepository.get().getClass(substance), 1100 "default", 1101 substance); 1102 } 1103 1104 public static FieldItem setOppositeRole(FieldItem field) { 1105 if (field!=null) { 1106 FieldItem oppositeRole = 1107 (FieldItem)field.getAttribute(RttiAC.OPPOSITE_ROLE); 1108 if (oppositeRole instanceof CollectionItem) { 1109 loggerAssoc.debug("Ignoring collection oppositeRole of "+ 1110 field.getLongName() + ": "+oppositeRole); 1111 return null; 1112 } else { 1113 loggerAssoc.debug("opposite_role of "+field.getLongName()+" = " + oppositeRole); 1114 Collaboration.get().addAttribute(GuiAC.OPPOSITE_ROLE, oppositeRole); 1115 return oppositeRole; 1116 } 1117 } else { 1118 return null; 1119 } 1120 } 1121} 1122 | Popular Tags |