1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import java.util.ArrayList ; 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Set ; 18 19 import org.eclipse.compare.structuremergeviewer.IDiffElement; 20 import org.eclipse.core.resources.*; 21 import org.eclipse.core.runtime.*; 22 import org.eclipse.core.runtime.jobs.Job; 23 import org.eclipse.jface.util.IPropertyChangeListener; 24 import org.eclipse.jface.util.PropertyChangeEvent; 25 import org.eclipse.jface.viewers.*; 26 import org.eclipse.swt.SWTException; 27 import org.eclipse.swt.events.TreeEvent; 28 import org.eclipse.swt.events.TreeListener; 29 import org.eclipse.swt.widgets.Tree; 30 import org.eclipse.team.core.ITeamStatus; 31 import org.eclipse.team.core.synchronize.*; 32 import org.eclipse.team.internal.core.TeamPlugin; 33 import org.eclipse.team.internal.ui.*; 34 import org.eclipse.team.ui.synchronize.*; 35 36 41 public abstract class AbstractSynchronizeModelProvider implements ISynchronizeModelProvider, ISyncInfoSetChangeListener, TreeListener { 42 43 47 public static final String P_VIEWER_EXPANSION_STATE = TeamUIPlugin.ID + ".P_VIEWER_EXPANSION_STATE"; 49 53 public static final String P_VIEWER_SELECTION_STATE = TeamUIPlugin.ID + ".P_VIEWER_SELECTION_STATE"; 55 59 public static final String P_VIEWER_CHECKED_STATE = TeamUIPlugin.ID + ".P_VIEWER_CHECKED_STATE"; 61 private ISynchronizeModelElement root; 62 63 private ISynchronizePageConfiguration configuration; 64 65 private SyncInfoSet set; 66 67 private SynchronizeModelUpdateHandler updateHandler; 68 69 private boolean disposed = false; 70 71 private SynchronizePageActionGroup actionGroup; 72 73 private ListenerList listeners; 74 75 private static final boolean DEBUG = false; 76 77 84 protected AbstractSynchronizeModelProvider(AbstractSynchronizeModelProvider parentProvider, ISynchronizeModelElement parentNode, ISynchronizePageConfiguration configuration, SyncInfoSet set) { 85 Assert.isNotNull(set); 86 Assert.isNotNull(parentNode); 87 this.root = parentNode; 88 this.set = set; 89 this.configuration = configuration; 90 if (parentProvider == null) { 91 updateHandler = new SynchronizeModelUpdateHandler(this); 94 getTree().addTreeListener(this); 95 } else { 96 updateHandler = parentProvider.updateHandler; 98 set.addSyncSetChangedListener(this); 99 } 100 } 101 102 private Tree getTree() { 103 return ((Tree)((AbstractTreeViewer)getViewer()).getControl()); 104 } 105 106 111 protected AbstractSynchronizeModelProvider(ISynchronizePageConfiguration configuration, SyncInfoSet set) { 112 this(null, new UnchangedResourceModelElement(null, ResourcesPlugin.getWorkspace().getRoot()) { 113 116 public boolean hasChildren() { 117 return true; 118 } 119 }, configuration, set); 120 SynchronizePageActionGroup actionGroup = getActionGroup(); 122 if (actionGroup != null) { 123 configuration.addActionContribution(actionGroup); 124 } 125 } 126 127 141 public final synchronized SynchronizePageActionGroup getActionGroup() { 142 if (actionGroup == null) { 143 actionGroup = createActionGroup(); 144 } 145 return actionGroup; 146 } 147 148 153 protected SynchronizePageActionGroup createActionGroup() { 154 return null; 155 } 156 157 164 public SyncInfoSet getSyncInfoSet() { 165 return set; 166 } 167 168 174 public ISynchronizeModelElement getModelRoot() { 175 return root; 176 } 177 178 183 public ISynchronizePageConfiguration getConfiguration() { 184 return configuration; 185 } 186 187 192 public StructuredViewer getViewer() { 193 ISynchronizePage page = configuration.getPage(); 194 if (page == null) return null; 195 Viewer viewer = page.getViewer(); 196 if (viewer instanceof AbstractTreeViewer) { 197 return (AbstractTreeViewer)viewer; 198 } 199 return null; 200 } 201 202 205 public ISynchronizeModelElement prepareInput(IProgressMonitor monitor) { 206 if (isRootProvider()) { 209 updateHandler.connect(monitor); 210 } else { 211 getSyncInfoSet().connect(this, monitor); 212 } 213 return getModelRoot(); 214 } 215 216 225 public String calculateProblemMarker(ISynchronizeModelElement element) { 226 IResource resource = element.getResource(); 227 String property = null; 228 if (resource != null && resource.exists()) { 229 try { 230 IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, getLogicalModelDepth(resource)); 231 for (int i = 0; i < markers.length; i++) { 232 IMarker marker = markers[i]; 233 try { 234 Integer severity = (Integer ) marker.getAttribute(IMarker.SEVERITY); 235 if (severity != null) { 236 if (severity.intValue() == IMarker.SEVERITY_ERROR) { 237 property = ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY; 238 break; 239 } else if (severity.intValue() == IMarker.SEVERITY_WARNING) { 240 property = ISynchronizeModelElement.PROPAGATED_WARNING_MARKER_PROPERTY; 241 } 243 } 244 } catch (CoreException e) { 245 if (!resource.exists()) { 246 property = null; 248 break; 249 } 250 if (marker.exists()) { 253 TeamPlugin.log(e); 254 } 255 } 256 } 257 } catch (CoreException e) { 258 if (resource.isAccessible() 261 && e.getStatus().getCode() != IResourceStatus.RESOURCE_NOT_FOUND 262 && e.getStatus().getCode() != IResourceStatus.PROJECT_NOT_OPEN) { 263 TeamPlugin.log(e); 264 } 265 } 266 } else if (resource == null) { 267 IDiffElement[] children = element.getChildren(); 269 for (int i = 0; i < children.length; i++) { 270 IDiffElement child = children[i]; 271 if (child instanceof ISynchronizeModelElement) { 272 ISynchronizeModelElement childElement = (ISynchronizeModelElement)child; 273 if (childElement.getProperty(ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY)) { 274 property = ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY; 275 break; 276 } else if (childElement.getProperty(ISynchronizeModelElement.PROPAGATED_WARNING_MARKER_PROPERTY)) { 277 property = ISynchronizeModelElement.PROPAGATED_WARNING_MARKER_PROPERTY; 278 } 280 281 } 282 } 283 } 284 return property; 285 } 286 287 292 protected int getLogicalModelDepth(IResource resource) { 293 return IResource.DEPTH_INFINITE; 294 } 295 296 302 protected void queueForLabelUpdate(ISynchronizeModelElement diffNode) { 303 updateHandler.queueForLabelUpdate(diffNode); 304 } 305 306 310 protected void reset() { 311 if(isRootProvider() && hasViewerState()) { 313 saveViewerState(); 314 } 315 316 clearModelObjects(getModelRoot()); 318 319 buildModelObjects(getModelRoot()); 321 322 ISynchronizeModelElement root = getModelRoot(); 324 if(root instanceof SynchronizeModelElement) { 325 ((SynchronizeModelElement)root).fireChanges(); 326 } 327 328 if (Utils.canUpdateViewer(getViewer())) { 329 refreshModelRoot(); 332 } else { 333 if (!updateHandler.isPerformingBackgroundUpdate()) { 336 Utils.asyncExec(new Runnable () { 337 public void run() { 338 refreshModelRoot(); 339 } 340 }, getViewer()); 341 } 342 } 343 } 344 345 private void refreshModelRoot() { 346 StructuredViewer viewer = getViewer(); 347 if (viewer != null && !viewer.getControl().isDisposed()) { 348 try { 349 viewer.getControl().setRedraw(false); 350 if (isRootProvider() || getModelRoot().getParent() == null) { 351 viewer.refresh(); 353 } else { 354 addToViewer(getModelRoot()); 358 } 359 if (isRootProvider()) 361 restoreViewerState(); 362 } finally { 363 viewer.getControl().setRedraw(true); 364 } 365 } 366 } 367 368 373 protected abstract IDiffElement[] buildModelObjects(ISynchronizeModelElement node); 374 375 379 protected abstract boolean hasViewerState(); 380 381 386 protected IResource[] getExpandedResources() { 387 Set expanded = new HashSet (); 388 IResource[] savedExpansionState = getCachedResources(P_VIEWER_EXPANSION_STATE); 389 for (int i = 0; i < savedExpansionState.length; i++) { 390 IResource resource = savedExpansionState[i]; 391 expanded.add(resource); 392 } 393 StructuredViewer viewer = getViewer(); 394 Object [] objects = ((AbstractTreeViewer) viewer).getVisibleExpandedElements(); 395 IResource[] currentExpansionState = getResources(objects); 396 for (int i = 0; i < currentExpansionState.length; i++) { 397 IResource resource = currentExpansionState[i]; 398 expanded.add(resource); 399 } 400 return (IResource[]) expanded.toArray(new IResource[expanded.size()]); 401 } 402 403 408 protected IResource[] getSelectedResources() { 409 StructuredViewer viewer = getViewer(); 410 return getResources(((IStructuredSelection) viewer.getSelection()).toArray()); 411 } 412 413 418 protected IResource[] getCheckedResources() { 419 StructuredViewer viewer = getViewer(); 420 if (viewer instanceof CheckboxTreeViewer){ 421 return getResources(((CheckboxTreeViewer)viewer).getCheckedElements()); 422 } 423 424 return new IResource[0]; 425 } 426 427 432 protected void expandResources(IResource[] resources) { 433 Set expandedElements = new HashSet (); 434 StructuredViewer viewer = getViewer(); 435 for (int j = 0; j < resources.length; j++) { 436 IResource resource = resources[j]; 437 ISynchronizeModelElement[] elements = getModelObjects(resource); 438 if (elements.length == 1) { 440 for (int i = 0; i < elements.length; i++) { 441 ISynchronizeModelElement element = elements[i]; 442 while (element != null) { 444 expandedElements.add(element); 445 element = (ISynchronizeModelElement)element.getParent(); 446 } 447 } 448 } 449 } 450 if (!expandedElements.isEmpty()) 451 ((AbstractTreeViewer) viewer).setExpandedElements(expandedElements.toArray()); 452 } 453 454 protected IResource[] getResources(Object [] objects) { 455 Set result = new HashSet (); 456 if (objects.length > 0) { 457 for (int i = 0; i < objects.length; i++) { 458 if (objects[i] instanceof ISynchronizeModelElement) { 459 IResource resource = ((ISynchronizeModelElement)objects[i]).getResource(); 460 if(resource != null) 461 result.add(resource); 462 } 463 } 464 } 465 return (IResource[]) result.toArray(new IResource[result.size()]); 466 } 467 468 private void clearResourceCache(String configProperty) { 469 getConfiguration().setProperty(configProperty, null); 470 } 471 472 private void cacheResources(IResource[] resources, String configProperty) { 473 if (resources.length > 0) { 474 ISynchronizePageConfiguration config = getConfiguration(); 475 ArrayList paths = new ArrayList (); 476 for (int i = 0; i < resources.length; i++) { 477 IResource resource = resources[i]; 478 String path = resource.getFullPath().toString(); 479 if (resource.getType() != IResource.FILE && path.charAt(path.length() - 1) != IPath.SEPARATOR) { 480 path += IPath.SEPARATOR; 483 } 484 paths.add(path); 485 } 486 config.setProperty(configProperty, paths); 487 } else { 488 clearResourceCache(configProperty); 489 } 490 } 491 492 private IResource[] getCachedResources(String configProperty) { 493 List paths = (List )getConfiguration().getProperty(configProperty); 494 if (paths == null) 495 return new IResource[0]; 496 IContainer container = ResourcesPlugin.getWorkspace().getRoot(); 497 ArrayList resources = new ArrayList (); 498 for (Iterator it = paths.iterator(); it.hasNext();) { 499 String path = (String ) it.next(); 500 IResource resource = getResourceForPath(container, path); 501 if (resource != null) { 502 resources.add(resource); 503 } 504 } 505 return (IResource[]) resources.toArray(new IResource[resources.size()]); 506 } 507 508 511 protected void saveViewerState() { 512 final StructuredViewer viewer = getViewer(); 514 if (viewer != null && !viewer.getControl().isDisposed() && viewer instanceof AbstractTreeViewer) { 515 517 final boolean storeChecks = ((SynchronizePageConfiguration)configuration).getViewerStyle() == SynchronizePageConfiguration.CHECKBOX; 518 final IResource[][] expandedResources = new IResource[1][0]; 519 final IResource[][] selectedResources = new IResource[1][0]; 520 final IResource[][] checkedResources = new IResource[1][0]; 521 viewer.getControl().getDisplay().syncExec(new Runnable () { 522 public void run() { 523 if (viewer != null && !viewer.getControl().isDisposed()) { 524 expandedResources[0] = getExpandedResources(); 525 selectedResources[0] = getSelectedResources(); 526 if (storeChecks) 527 checkedResources [0] = getCheckedResources(); 528 } 529 } 530 }); 531 532 cacheResources(expandedResources[0], P_VIEWER_EXPANSION_STATE); 534 cacheResources(selectedResources[0], P_VIEWER_SELECTION_STATE); 535 if (storeChecks) 536 cacheResources(checkedResources[0], P_VIEWER_CHECKED_STATE); 537 } 538 } 539 540 544 protected void restoreViewerState() { 545 final StructuredViewer viewer = getViewer(); 547 if (viewer != null && !viewer.getControl().isDisposed() && viewer instanceof AbstractTreeViewer) { 548 IResource[] resourcesToExpand = getCachedResources(P_VIEWER_EXPANSION_STATE); 549 IResource[] resourcesToSelect = getCachedResources(P_VIEWER_SELECTION_STATE); 550 if (((SynchronizePageConfiguration)configuration).getViewerStyle() == SynchronizePageConfiguration.CHECKBOX){ 551 IResource[] resourcesToCheck = getCachedResources(P_VIEWER_CHECKED_STATE); 552 checkResources(resourcesToCheck); 553 } 554 expandResources(resourcesToExpand); 555 selectResources(resourcesToSelect); 556 } 557 } 558 559 563 protected void selectResources(IResource[] resourcesToSelect) { 564 StructuredViewer viewer = getViewer(); 565 final ArrayList selectedElements = new ArrayList (); 566 for (int i = 0; i < resourcesToSelect.length; i++) { 567 IResource resource = resourcesToSelect[i]; 568 ISynchronizeModelElement[] elements = getModelObjects(resource); 569 if (elements.length == 1) { 571 selectedElements.add(elements[0]); 572 } 573 } 574 if (!selectedElements.isEmpty()) 575 viewer.setSelection(new StructuredSelection(selectedElements)); 576 } 577 578 582 protected void checkResources(IResource[] resourcesToCheck) { 583 Set checkedElements = new HashSet (); 584 StructuredViewer viewer = getViewer(); 585 if (!(viewer instanceof CheckboxTreeViewer)) 586 return; 587 588 for (int j = 0; j < resourcesToCheck.length; j++) { 589 IResource resource = resourcesToCheck[j]; 590 if (resource.getType() != IResource.FILE) 591 continue; 592 593 ISynchronizeModelElement[] elements = getModelObjects(resource); 594 if (elements.length == 1) { 596 for (int i = 0; i < elements.length; i++) { 597 ISynchronizeModelElement element = elements[i]; 598 checkedElements.add(element); 599 } 600 } 601 } 602 if (!checkedElements.isEmpty()) 603 ((CheckboxTreeViewer) viewer).setCheckedElements(checkedElements.toArray()); 604 } 605 606 611 private IResource getResourceForPath(IContainer container, String path) { 612 IResource resource = container.findMember(path, true ); 613 if (resource == null) { 614 try { 615 if (path.endsWith(Character.toString(IPath.SEPARATOR))) { 619 resource = container.getFolder(new Path(null, path)); 620 } else { 621 resource = container.getFile(new Path(null, path)); 622 } 623 } catch (IllegalArgumentException e) { 624 } 626 } 627 return resource; 628 } 629 630 633 public void treeCollapsed(TreeEvent e) { 634 clearResourceCache(P_VIEWER_EXPANSION_STATE); 635 } 636 637 640 public void treeExpanded(TreeEvent e) { 641 clearResourceCache(P_VIEWER_EXPANSION_STATE); 642 } 643 644 649 protected abstract ISynchronizeModelElement[] getModelObjects(IResource resource); 650 651 654 public void saveState() { 655 saveViewerState(); 656 } 657 658 665 protected void propogateConflictState(ISynchronizeModelElement element, boolean clear) { 666 boolean isConflict = clear ? false : isConflicting(element); 667 boolean wasConflict = element.getProperty(ISynchronizeModelElement.PROPAGATED_CONFLICT_PROPERTY); 668 if (isConflict != wasConflict) { 670 element.setPropertyToRoot(ISynchronizeModelElement.PROPAGATED_CONFLICT_PROPERTY, isConflict); 671 updateHandler.updateParentLabels(element); 672 } 673 } 674 675 680 protected boolean isConflicting(ISynchronizeModelElement element) { 681 return (element.getKind() & SyncInfo.DIRECTION_MASK) == SyncInfo.CONFLICTING; 682 } 683 684 687 public void dispose() { 688 if (isRootProvider()) { 691 updateHandler.dispose(); 692 getTree().removeTreeListener(this); 693 } else { 694 set.removeSyncSetChangedListener(this); 695 } 696 if (actionGroup != null) { 697 Utils.syncExec(new Runnable () { 698 public void run() { 699 actionGroup.dispose(); 700 } 701 }, getViewer()); 702 } 703 this.disposed = true; 704 } 705 706 private boolean isRootProvider() { 707 return updateHandler.getProvider() == this; 708 } 709 710 714 public boolean isDisposed() { 715 return disposed; 716 } 717 718 726 public abstract ISynchronizeModelElement[] getClosestExistingParents(IResource resource); 727 728 736 protected void handleChanges(ISyncInfoTreeChangeEvent event, IProgressMonitor monitor) { 737 handleResourceChanges(event); 738 handleResourceRemovals(event); 739 handleResourceAdditions(event); 740 } 741 742 748 protected abstract void handleResourceAdditions(ISyncInfoTreeChangeEvent event); 749 750 756 protected abstract void handleResourceChanges(ISyncInfoTreeChangeEvent event); 757 758 764 protected abstract void handleResourceRemovals(ISyncInfoTreeChangeEvent event); 765 766 769 public void syncInfoChanged(final ISyncInfoSetChangeEvent event, final IProgressMonitor monitor) { 770 if (! (event instanceof ISyncInfoTreeChangeEvent)) { 771 reset(); 772 } else { 773 updateHandler.runViewUpdate(new Runnable () { 774 public void run() { 775 handleChanges((ISyncInfoTreeChangeEvent)event, monitor); 776 } 777 }, true ); 778 } 779 } 780 781 784 public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { 785 787 } 788 789 792 public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) { 793 reset(); 794 } 795 796 protected void addToViewer(ISynchronizeModelElement node) { 797 if (DEBUG) { 798 System.out.println("Adding model element " + node.getName()); } 800 propogateConflictState(node, false); 801 String property = calculateProblemMarker(node); 805 if (property != null) { 806 node.setProperty(property, true); 807 propogateMarkerPropertyToParent(node, property); 810 } 811 if (Utils.canUpdateViewer(getViewer())) { 812 doAdd((SynchronizeModelElement)node.getParent(), node); 813 } 814 updateHandler.nodeAdded(node, this); 815 } 816 817 821 private void propogateMarkerPropertyToParent(ISynchronizeModelElement node, String property) { 822 ISynchronizeModelElement parent = (ISynchronizeModelElement)node.getParent(); 823 if (parent != null 824 && !parent.getProperty(property) 825 && !parent.getProperty(ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY)) { 826 parent.setProperty(property, true); 827 propogateMarkerPropertyToParent(parent, property); 828 } 829 } 830 831 837 protected void removeFromViewer(ISynchronizeModelElement[] nodes) { 838 List rootsToClear = new ArrayList (); 839 for (int i = 0; i < nodes.length; i++) { 840 ISynchronizeModelElement node = nodes[i]; 841 if (DEBUG) { 842 System.out.println("Removing model element " + node.getName()); } 844 ISynchronizeModelElement rootToClear = getRootToClear(node); 845 if (DEBUG && rootToClear != node) { 846 System.out.println("Removing parent element " + rootToClear.getName()); } 848 propogateConflictState(rootToClear, true ); 849 clearModelObjects(rootToClear); 850 rootsToClear.add(rootToClear); 851 } 852 ISynchronizeModelElement[] roots = (ISynchronizeModelElement[]) rootsToClear.toArray(new ISynchronizeModelElement[rootsToClear.size()]); 853 if (Utils.canUpdateViewer(getViewer())) { 854 doRemove(roots); 855 } 856 for (int i = 0; i < roots.length; i++) { 857 ISynchronizeModelElement element = roots[i]; 858 updateHandler.nodeRemoved(element, this); 859 } 860 } 861 862 869 protected final void clearModelObjects(ISynchronizeModelElement node) { 870 ISynchronizeModelElement rootToClear = getRootToClear(node); 874 recursiveClearModelObjects(rootToClear); 876 if (node == getModelRoot()) { 877 IDiffElement[] children = node.getChildren(); 878 for (int i = 0; i < children.length; i++) { 879 IDiffElement element = children[i]; 880 ((SynchronizeModelElement)node).remove(element); 881 } 882 } else { 883 SynchronizeModelElement parent = ((SynchronizeModelElement)node.getParent()); 884 if (parent != null) parent.remove(node); 885 } 886 } 887 888 892 protected void recursiveClearModelObjects(ISynchronizeModelElement node) { 893 IDiffElement[] children = node.getChildren(); 895 for (int i = 0; i < children.length; i++) { 896 IDiffElement element = children[i]; 897 if (element instanceof ISynchronizeModelElement) { 898 ISynchronizeModelElement sme = (ISynchronizeModelElement) element; 899 ISynchronizeModelProvider provider = getProvider(sme); 900 if (provider != null && provider instanceof AbstractSynchronizeModelProvider) { 901 ((AbstractSynchronizeModelProvider)provider).recursiveClearModelObjects(sme); 902 } else { 903 recursiveClearModelObjects(sme); 904 } 905 } 906 } 907 if (node != getModelRoot()) 909 updateHandler.modelObjectCleared(node); 910 } 911 912 916 private ISynchronizeModelElement getRootToClear(ISynchronizeModelElement node) { 917 if (node == getModelRoot()) return node; 918 ISynchronizeModelElement parent = (ISynchronizeModelElement)node.getParent(); 919 if (parent != null && parent != getModelRoot() && !isOutOfSync(parent) && parent.getChildren().length == 1) { 920 return getRootToClear(parent); 921 } 922 return node; 923 } 924 925 928 protected boolean isOutOfSync(ISynchronizeModelElement node) { 929 SyncInfo info = Utils.getSyncInfo(node); 930 return (info != null && info.getKind() != SyncInfo.IN_SYNC); 931 } 932 933 protected boolean isOutOfSync(IResource resource) { 934 SyncInfo info = getSyncInfoSet().getSyncInfo(resource); 935 return (info != null && info.getKind() != SyncInfo.IN_SYNC); 936 } 937 938 945 protected ISynchronizeModelProvider getProvider(ISynchronizeModelElement element) { 946 return this; 947 } 948 949 954 protected void doAdd(ISynchronizeModelElement parent, ISynchronizeModelElement element) { 955 updateHandler.doAdd(parent, element); 956 } 957 958 962 protected void doRemove(ISynchronizeModelElement[] elements) { 963 AbstractTreeViewer viewer = (AbstractTreeViewer)getViewer(); 964 try { 965 viewer.remove(elements); 966 } catch (SWTException e) { 967 TeamUIPlugin.log(IStatus.ERROR, "An error occurred removing elements from the synchronize view", e); } 970 if (DEBUG) { 971 for (int i = 0; i < elements.length; i++) { 972 ISynchronizeModelElement element = elements[i]; 973 System.out.println("Removing view item " + element.getName()); } 975 } 976 } 977 978 985 protected void nodeAdded(ISynchronizeModelElement node, AbstractSynchronizeModelProvider provider) { 986 } 988 989 997 protected void nodeRemoved(ISynchronizeModelElement node, AbstractSynchronizeModelProvider provider) { 998 } 1000 1001 1008 public void modelObjectCleared(ISynchronizeModelElement node) { 1009 } 1011 1012 public void addPropertyChangeListener(IPropertyChangeListener listener) { 1013 synchronized (this) { 1014 if (listeners == null) { 1015 listeners = new ListenerList(ListenerList.IDENTITY); 1016 } 1017 listeners.add(listener); 1018 } 1019 1020 } 1021 public void removePropertyChangeListener(IPropertyChangeListener listener) { 1022 if (listeners != null) { 1023 synchronized (this) { 1024 listeners.remove(listener); 1025 if (listeners.isEmpty()) { 1026 listeners = null; 1027 } 1028 } 1029 } 1030 } 1031 1032 protected void firePropertyChange(String key, Object oldValue, Object newValue) { 1033 Object [] allListeners; 1034 synchronized(this) { 1035 allListeners = listeners.getListeners(); 1036 } 1037 final PropertyChangeEvent event = new PropertyChangeEvent(this, key, oldValue, newValue); 1038 for (int i = 0; i < allListeners.length; i++) { 1039 final IPropertyChangeListener listener = (IPropertyChangeListener)allListeners[i]; 1040 SafeRunner.run(new ISafeRunnable() { 1041 public void handleException(Throwable exception) { 1042 } 1044 public void run() throws Exception { 1045 listener.propertyChange(event); 1046 } 1047 }); 1048 } 1049 } 1050 1051 1057 public void waitUntilDone(IProgressMonitor monitor) { 1058 monitor.worked(1); 1059 while(updateHandler.getEventHandlerJob().getState() != Job.NONE) { 1061 monitor.worked(1); 1062 try { 1063 Thread.sleep(10); 1064 } catch (InterruptedException e) { 1065 } 1066 Policy.checkCanceled(monitor); 1067 } 1068 monitor.worked(1); 1069 } 1070 1071 1074 public String toString() { 1075 ISynchronizeModelElement element = getModelRoot(); 1076 String name = getClass().getName(); 1077 int index = name.lastIndexOf("."); if (index != -1) { 1079 name = name.substring(index + 1); 1080 } 1081 String name2 = element.getName(); 1082 if (name2.length() == 0) { 1083 name2 = "/"; } 1085 return name + ": " + name2; } 1087 1088 1096 public void performUpdate(IWorkspaceRunnable runnable, boolean preserveExpansion, boolean runInUIThread) { 1097 updateHandler.performUpdate(runnable, preserveExpansion, runInUIThread); 1098 } 1099} 1100 | Popular Tags |