diff options
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java')
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java | 946 |
1 files changed, 473 insertions, 473 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java index a2616f7d8..c570a8ba8 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java @@ -97,11 +97,11 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo private boolean disposed = false; - private SynchronizePageActionGroup actionGroup; + private SynchronizePageActionGroup actionGroup; - private ListenerList<IPropertyChangeListener> listeners; + private ListenerList<IPropertyChangeListener> listeners; - private static final boolean DEBUG = false; + private static final boolean DEBUG = false; /** * Constructor for creating a sub-provider @@ -117,22 +117,22 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo this.set = set; this.configuration = configuration; if (parentProvider == null) { - // The update handler will register for sync change events - // with the sync set when the handler is activated - updateHandler = new SynchronizeModelUpdateHandler(this); - getTree().addTreeListener(this); + // The update handler will register for sync change events + // with the sync set when the handler is activated + updateHandler = new SynchronizeModelUpdateHandler(this); + getTree().addTreeListener(this); } else { - // We will use the parent's update handler and register for changes with the given set - updateHandler = parentProvider.updateHandler; - set.addSyncSetChangedListener(this); + // We will use the parent's update handler and register for changes with the given set + updateHandler = parentProvider.updateHandler; + set.addSyncSetChangedListener(this); } } private Tree getTree() { - return ((Tree)((AbstractTreeViewer)getViewer()).getControl()); - } + return ((Tree)((AbstractTreeViewer)getViewer()).getControl()); + } - /** + /** * Constructor for creating a root model provider. * @param configuration the sync page configuration * @param set the sync info set from which the model is built @@ -150,41 +150,41 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo // Register the action group for this provider, since it is the root provider SynchronizePageActionGroup actionGroup = getActionGroup(); if (actionGroup != null) { - configuration.addActionContribution(actionGroup); + configuration.addActionContribution(actionGroup); } } /** * Return the action group for this provider or <code>null</code> - * if there are no actions associated with this provider. The action - * group will be registered with the configuration if this is - * the root provider. If this provider is a sub-provider, it - * is up to the parent provider to register the action group. - * <p> - * The action group for a provider is created by calling the - * <code>createdActionGroup</code> method. If this method returns - * a non-null group, it is cached so it can be disposed - * when the provider is disposed. - * @return the action group for this provider or <code>null</code> - * if there are no actions associated with this provider - */ - public final synchronized SynchronizePageActionGroup getActionGroup() { - if (actionGroup == null) { - actionGroup = createActionGroup(); - } - return actionGroup; - } - - /** - * Create the action group for this provider. By default, - * a <code>null</code> is returned. Subclasses may override. - * @return the action group for this provider or <code>null</code> - */ - protected SynchronizePageActionGroup createActionGroup() { - return null; - } - - /** + * if there are no actions associated with this provider. The action + * group will be registered with the configuration if this is + * the root provider. If this provider is a sub-provider, it + * is up to the parent provider to register the action group. + * <p> + * The action group for a provider is created by calling the + * <code>createdActionGroup</code> method. If this method returns + * a non-null group, it is cached so it can be disposed + * when the provider is disposed. + * @return the action group for this provider or <code>null</code> + * if there are no actions associated with this provider + */ + public final synchronized SynchronizePageActionGroup getActionGroup() { + if (actionGroup == null) { + actionGroup = createActionGroup(); + } + return actionGroup; + } + + /** + * Create the action group for this provider. By default, + * a <code>null</code> is returned. Subclasses may override. + * @return the action group for this provider or <code>null</code> + */ + protected SynchronizePageActionGroup createActionGroup() { + return null; + } + + /** * Return the set that contains the elements this provider is using as * a basis for creating a presentation model. This cannot be null. * @@ -225,9 +225,9 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo public StructuredViewer getViewer() { ISynchronizePage page = configuration.getPage(); if (page == null) return null; - Viewer viewer = page.getViewer(); + Viewer viewer = page.getViewer(); if (viewer instanceof AbstractTreeViewer) { - return (AbstractTreeViewer)viewer; + return (AbstractTreeViewer)viewer; } return null; } @@ -239,11 +239,11 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo public ISynchronizeModelElement prepareInput(IProgressMonitor monitor) { // Connect to the sync set which will register us as a listener and give us a reset event // in a background thread - if (isRootProvider()) { - updateHandler.connect(monitor); - } else { - getSyncInfoSet().connect(this, monitor); - } + if (isRootProvider()) { + updateHandler.connect(monitor); + } else { + getSyncInfoSet().connect(this, monitor); + } return getModelRoot(); } @@ -298,22 +298,22 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo } } } else if (resource == null) { - // For non-resource elements, show the same propogaqted marker as the children - IDiffElement[] children = element.getChildren(); - for (int i = 0; i < children.length; i++) { - IDiffElement child = children[i]; - if (child instanceof ISynchronizeModelElement) { - ISynchronizeModelElement childElement = (ISynchronizeModelElement)child; - if (childElement.getProperty(ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY)) { - property = ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY; - break; - } else if (childElement.getProperty(ISynchronizeModelElement.PROPAGATED_WARNING_MARKER_PROPERTY)) { + // For non-resource elements, show the same propogaqted marker as the children + IDiffElement[] children = element.getChildren(); + for (int i = 0; i < children.length; i++) { + IDiffElement child = children[i]; + if (child instanceof ISynchronizeModelElement) { + ISynchronizeModelElement childElement = (ISynchronizeModelElement)child; + if (childElement.getProperty(ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY)) { + property = ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY; + break; + } else if (childElement.getProperty(ISynchronizeModelElement.PROPAGATED_WARNING_MARKER_PROPERTY)) { property = ISynchronizeModelElement.PROPAGATED_WARNING_MARKER_PROPERTY; // Keep going because there may be errors on other resources } - } - } + } + } } return property; } @@ -337,10 +337,10 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo updateHandler.queueForLabelUpdate(diffNode); } - /** - * Throw away any old state associated with this provider and - * rebuild the model from scratch. - */ + /** + * Throw away any old state associated with this provider and + * rebuild the model from scratch. + */ protected void reset() { // save expansion state if(isRootProvider() && hasViewerState()) { @@ -360,40 +360,40 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo } if (Utils.canUpdateViewer(getViewer())) { - // If we can update the viewer, that means that the view was updated - // when the model was rebuilt. - refreshModelRoot(); + // If we can update the viewer, that means that the view was updated + // when the model was rebuilt. + refreshModelRoot(); } else { - // Only refresh the view if there is now background update in - // progress. If there is, the background update will refresh - if (!updateHandler.isPerformingBackgroundUpdate()) { + // Only refresh the view if there is now background update in + // progress. If there is, the background update will refresh + if (!updateHandler.isPerformingBackgroundUpdate()) { Utils.asyncExec((Runnable) () -> refreshModelRoot(), getViewer()); - } + } } } - private void refreshModelRoot() { - StructuredViewer viewer = getViewer(); + private void refreshModelRoot() { + StructuredViewer viewer = getViewer(); if (viewer != null && !viewer.getControl().isDisposed()) { try { viewer.getControl().setRedraw(false); if (isRootProvider() || getModelRoot().getParent() == null) { - // Refresh the entire view - viewer.refresh(); + // Refresh the entire view + viewer.refresh(); } else { - // Only refresh the model root bu also ensure that - // the parents of the model root and the model root - // itself are added to the view - addToViewer(getModelRoot()); + // Only refresh the model root bu also ensure that + // the parents of the model root and the model root + // itself are added to the view + addToViewer(getModelRoot()); } // restore expansion state if (isRootProvider()) - restoreViewerState(); + restoreViewerState(); } finally { viewer.getControl().setRedraw(true); } } - } + } /** * For each node create children based on the contents of @@ -404,85 +404,85 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo /** * Returns whether the viewer has state to be saved. - * @return whether the viewer has state to be saved - */ - protected abstract boolean hasViewerState(); - - /* - * Return all the resources that are expanded in the page. - * This method should only be called in the UI thread - * after validating that the viewer is still valid. - */ - protected IResource[] getExpandedResources() { - Set<IResource> expanded = new HashSet<>(); - IResource[] savedExpansionState = getCachedResources(P_VIEWER_EXPANSION_STATE); - for (int i = 0; i < savedExpansionState.length; i++) { - IResource resource = savedExpansionState[i]; - expanded.add(resource); - } - StructuredViewer viewer = getViewer(); - Object[] objects = ((AbstractTreeViewer) viewer).getVisibleExpandedElements(); - IResource[] currentExpansionState = getResources(objects); - for (int i = 0; i < currentExpansionState.length; i++) { - IResource resource = currentExpansionState[i]; - expanded.add(resource); - } - return expanded.toArray(new IResource[expanded.size()]); - } - - /* - * Return all the resources that are selected in the page. - * This method should only be called in the UI thread - * after validating that the viewer is still valid. - */ - protected IResource[] getSelectedResources() { - StructuredViewer viewer = getViewer(); - return getResources(viewer.getStructuredSelection().toArray()); - } - - /* - * Return all the resources that are checked in the page. - * This method should only be called in the UI thread - * after validating that the viewer is still valid. - */ - protected IResource[] getCheckedResources() { - StructuredViewer viewer = getViewer(); - if (viewer instanceof CheckboxTreeViewer){ - return getResources(((CheckboxTreeViewer)viewer).getCheckedElements()); - } - - return new IResource[0]; - } - - /* - * Expand the resources if they appear in the page. - * This method should only be called in the UI thread - * after validating that the viewer is still valid. - */ - protected void expandResources(IResource[] resources) { - Set<ISynchronizeModelElement> expandedElements = new HashSet<>(); - StructuredViewer viewer = getViewer(); - for (int j = 0; j < resources.length; j++) { - IResource resource = resources[j]; + * @return whether the viewer has state to be saved + */ + protected abstract boolean hasViewerState(); + + /* + * Return all the resources that are expanded in the page. + * This method should only be called in the UI thread + * after validating that the viewer is still valid. + */ + protected IResource[] getExpandedResources() { + Set<IResource> expanded = new HashSet<>(); + IResource[] savedExpansionState = getCachedResources(P_VIEWER_EXPANSION_STATE); + for (int i = 0; i < savedExpansionState.length; i++) { + IResource resource = savedExpansionState[i]; + expanded.add(resource); + } + StructuredViewer viewer = getViewer(); + Object[] objects = ((AbstractTreeViewer) viewer).getVisibleExpandedElements(); + IResource[] currentExpansionState = getResources(objects); + for (int i = 0; i < currentExpansionState.length; i++) { + IResource resource = currentExpansionState[i]; + expanded.add(resource); + } + return expanded.toArray(new IResource[expanded.size()]); + } + + /* + * Return all the resources that are selected in the page. + * This method should only be called in the UI thread + * after validating that the viewer is still valid. + */ + protected IResource[] getSelectedResources() { + StructuredViewer viewer = getViewer(); + return getResources(viewer.getStructuredSelection().toArray()); + } + + /* + * Return all the resources that are checked in the page. + * This method should only be called in the UI thread + * after validating that the viewer is still valid. + */ + protected IResource[] getCheckedResources() { + StructuredViewer viewer = getViewer(); + if (viewer instanceof CheckboxTreeViewer){ + return getResources(((CheckboxTreeViewer)viewer).getCheckedElements()); + } + + return new IResource[0]; + } + + /* + * Expand the resources if they appear in the page. + * This method should only be called in the UI thread + * after validating that the viewer is still valid. + */ + protected void expandResources(IResource[] resources) { + Set<ISynchronizeModelElement> expandedElements = new HashSet<>(); + StructuredViewer viewer = getViewer(); + for (int j = 0; j < resources.length; j++) { + IResource resource = resources[j]; ISynchronizeModelElement[] elements = getModelObjects(resource); - // Only expand when there is one element per resource - if (elements.length == 1) { - for (int i = 0; i < elements.length; i++) { - ISynchronizeModelElement element = elements[i]; - // Add all parents of the element to the expansion set - while (element != null) { - expandedElements.add(element); - element = (ISynchronizeModelElement)element.getParent(); - } - } - } + // Only expand when there is one element per resource + if (elements.length == 1) { + for (int i = 0; i < elements.length; i++) { + ISynchronizeModelElement element = elements[i]; + // Add all parents of the element to the expansion set + while (element != null) { + expandedElements.add(element); + element = (ISynchronizeModelElement)element.getParent(); + } + } + } } - if (!expandedElements.isEmpty()) - ((AbstractTreeViewer) viewer).setExpandedElements(expandedElements.toArray()); - } + if (!expandedElements.isEmpty()) + ((AbstractTreeViewer) viewer).setExpandedElements(expandedElements.toArray()); + } - protected IResource[] getResources(Object[] objects) { - Set<IResource> result = new HashSet<>(); + protected IResource[] getResources(Object[] objects) { + Set<IResource> result = new HashSet<>(); if (objects.length > 0) { for (int i = 0; i < objects.length; i++) { if (objects[i] instanceof ISynchronizeModelElement) { @@ -493,13 +493,13 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo } } return result.toArray(new IResource[result.size()]); - } + } - private void clearResourceCache(String configProperty) { - getConfiguration().setProperty(configProperty, null); - } + private void clearResourceCache(String configProperty) { + getConfiguration().setProperty(configProperty, null); + } - private void cacheResources(IResource[] resources, String configProperty) { + private void cacheResources(IResource[] resources, String configProperty) { if (resources.length > 0) { ISynchronizePageConfiguration config = getConfiguration(); ArrayList<String> paths = new ArrayList<>(); @@ -507,40 +507,40 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo IResource resource = resources[i]; String path = resource.getFullPath().toString(); if (resource.getType() != IResource.FILE && path.charAt(path.length() - 1) != IPath.SEPARATOR) { - // Include a trailing slash on folders and projects. - // It is used when recreating cached resources that don't exist locally - path += IPath.SEPARATOR; + // Include a trailing slash on folders and projects. + // It is used when recreating cached resources that don't exist locally + path += IPath.SEPARATOR; } - paths.add(path); + paths.add(path); } config.setProperty(configProperty, paths); } else { - clearResourceCache(configProperty); + clearResourceCache(configProperty); } - } + } - private IResource[] getCachedResources(String configProperty) { - List paths = (List)getConfiguration().getProperty(configProperty); - if (paths == null) - return new IResource[0]; + private IResource[] getCachedResources(String configProperty) { + List paths = (List)getConfiguration().getProperty(configProperty); + if (paths == null) + return new IResource[0]; IContainer container = ResourcesPlugin.getWorkspace().getRoot(); ArrayList<IResource> resources = new ArrayList<>(); for (Iterator it = paths.iterator(); it.hasNext();) { String path = (String) it.next(); IResource resource = getResourceForPath(container, path); if (resource != null) { - resources.add(resource); + resources.add(resource); } } return resources.toArray(new IResource[resources.size()]); - } + } - /** - * Save the viewer state (expansion and selection) - */ + /** + * Save the viewer state (expansion and selection) + */ protected void saveViewerState() { // save visible expanded elements and selection - final StructuredViewer viewer = getViewer(); + final StructuredViewer viewer = getViewer(); if (viewer != null && !viewer.getControl().isDisposed() && viewer instanceof AbstractTreeViewer) { //check to see if we should store the checked states of the tree @@ -550,10 +550,10 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo final IResource[][] checkedResources = new IResource[1][0]; viewer.getControl().getDisplay().syncExec(() -> { if (viewer != null && !viewer.getControl().isDisposed()) { - expandedResources[0] = getExpandedResources(); - selectedResources[0] = getSelectedResources(); - if (storeChecks) - checkedResources [0] = getCheckedResources(); + expandedResources[0] = getExpandedResources(); + selectedResources[0] = getSelectedResources(); + if (storeChecks) + checkedResources [0] = getCheckedResources(); } }); @@ -571,15 +571,15 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo */ protected void restoreViewerState() { // restore expansion state and selection state - final StructuredViewer viewer = getViewer(); + final StructuredViewer viewer = getViewer(); if (viewer != null && !viewer.getControl().isDisposed() && viewer instanceof AbstractTreeViewer) { - IResource[] resourcesToExpand = getCachedResources(P_VIEWER_EXPANSION_STATE); - IResource[] resourcesToSelect = getCachedResources(P_VIEWER_SELECTION_STATE); - if (((SynchronizePageConfiguration)configuration).getViewerStyle() == SynchronizePageConfiguration.CHECKBOX){ - IResource[] resourcesToCheck = getCachedResources(P_VIEWER_CHECKED_STATE); - checkResources(resourcesToCheck); - } - expandResources(resourcesToExpand); + IResource[] resourcesToExpand = getCachedResources(P_VIEWER_EXPANSION_STATE); + IResource[] resourcesToSelect = getCachedResources(P_VIEWER_SELECTION_STATE); + if (((SynchronizePageConfiguration)configuration).getViewerStyle() == SynchronizePageConfiguration.CHECKBOX){ + IResource[] resourcesToCheck = getCachedResources(P_VIEWER_CHECKED_STATE); + checkResources(resourcesToCheck); + } + expandResources(resourcesToExpand); selectResources(resourcesToSelect); } } @@ -588,96 +588,96 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo * Select the given resources in the view. This method can * only be invoked from the UI thread. */ - protected void selectResources(IResource[] resourcesToSelect) { - StructuredViewer viewer = getViewer(); - final ArrayList<ISynchronizeModelElement> selectedElements = new ArrayList<>(); - for (int i = 0; i < resourcesToSelect.length; i++) { - IResource resource = resourcesToSelect[i]; - ISynchronizeModelElement[] elements = getModelObjects(resource); - // Only preserve the selection if there is one element for the resource - if (elements.length == 1) { - selectedElements.add(elements[0]); - } - } - if (!selectedElements.isEmpty()) - viewer.setSelection(new StructuredSelection(selectedElements)); - } - - /* + protected void selectResources(IResource[] resourcesToSelect) { + StructuredViewer viewer = getViewer(); + final ArrayList<ISynchronizeModelElement> selectedElements = new ArrayList<>(); + for (int i = 0; i < resourcesToSelect.length; i++) { + IResource resource = resourcesToSelect[i]; + ISynchronizeModelElement[] elements = getModelObjects(resource); + // Only preserve the selection if there is one element for the resource + if (elements.length == 1) { + selectedElements.add(elements[0]); + } + } + if (!selectedElements.isEmpty()) + viewer.setSelection(new StructuredSelection(selectedElements)); + } + + /* * Check the given resources in the view. This method can * only be invoked from the UI thread. */ - protected void checkResources(IResource[] resourcesToCheck) { - Set<ISynchronizeModelElement> checkedElements = new HashSet<>(); - StructuredViewer viewer = getViewer(); - if (!(viewer instanceof CheckboxTreeViewer)) - return; - - for (int j = 0; j < resourcesToCheck.length; j++) { - IResource resource = resourcesToCheck[j]; - if (resource.getType() != IResource.FILE) - continue; - - ISynchronizeModelElement[] elements = getModelObjects(resource); - // Only expand when there is one element per resource - if (elements.length == 1) { - for (int i = 0; i < elements.length; i++) { - ISynchronizeModelElement element = elements[i]; - checkedElements.add(element); - } - } - } - if (!checkedElements.isEmpty()) - ((CheckboxTreeViewer) viewer).setCheckedElements(checkedElements.toArray()); - } - - /* - * Convert a path to a resource by first looking in the resource - * tree and, if that fails, by using the path format to create - * a handle. - */ - private IResource getResourceForPath(IContainer container, String path) { - IResource resource = container.findMember(path, true /* include phantoms */); - if (resource == null) { - try { - // The resource doesn't have an entry on the resources tree - // but may still appear in the view so try to deduce the type - // from the path - if (path.endsWith(Character.toString(IPath.SEPARATOR))) { - resource = container.getFolder(new Path(null, path)); - } else { - resource = container.getFile(new Path(null, path)); - } - } catch (IllegalArgumentException e) { - // Couldn't get a resource handle so ignore - } - } - return resource; - } - - @Override + protected void checkResources(IResource[] resourcesToCheck) { + Set<ISynchronizeModelElement> checkedElements = new HashSet<>(); + StructuredViewer viewer = getViewer(); + if (!(viewer instanceof CheckboxTreeViewer)) + return; + + for (int j = 0; j < resourcesToCheck.length; j++) { + IResource resource = resourcesToCheck[j]; + if (resource.getType() != IResource.FILE) + continue; + + ISynchronizeModelElement[] elements = getModelObjects(resource); + // Only expand when there is one element per resource + if (elements.length == 1) { + for (int i = 0; i < elements.length; i++) { + ISynchronizeModelElement element = elements[i]; + checkedElements.add(element); + } + } + } + if (!checkedElements.isEmpty()) + ((CheckboxTreeViewer) viewer).setCheckedElements(checkedElements.toArray()); + } + + /* + * Convert a path to a resource by first looking in the resource + * tree and, if that fails, by using the path format to create + * a handle. + */ + private IResource getResourceForPath(IContainer container, String path) { + IResource resource = container.findMember(path, true /* include phantoms */); + if (resource == null) { + try { + // The resource doesn't have an entry on the resources tree + // but may still appear in the view so try to deduce the type + // from the path + if (path.endsWith(Character.toString(IPath.SEPARATOR))) { + resource = container.getFolder(new Path(null, path)); + } else { + resource = container.getFile(new Path(null, path)); + } + } catch (IllegalArgumentException e) { + // Couldn't get a resource handle so ignore + } + } + return resource; + } + + @Override public void treeCollapsed(TreeEvent e) { - clearResourceCache(P_VIEWER_EXPANSION_STATE); - } + clearResourceCache(P_VIEWER_EXPANSION_STATE); + } - @Override + @Override public void treeExpanded(TreeEvent e) { - clearResourceCache(P_VIEWER_EXPANSION_STATE); - } + clearResourceCache(P_VIEWER_EXPANSION_STATE); + } - /** + /** * Return all the model objects in this provider that represent the given resource - * @param resource the resource - * @return the model objects for the resource - */ - protected abstract ISynchronizeModelElement[] getModelObjects(IResource resource); + * @param resource the resource + * @return the model objects for the resource + */ + protected abstract ISynchronizeModelElement[] getModelObjects(IResource resource); @Override public void saveState() { saveViewerState(); } - /** + /** * Method invoked when a sync element is added or removed or its state changes. * This method can be invoked from the UI thread or a background thread. * @param element synchronize element @@ -708,41 +708,41 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo */ @Override public void dispose() { - // Only dispose the update handler if it is - // directly associated with this provider - if (isRootProvider()) { - updateHandler.dispose(); - getTree().removeTreeListener(this); - } else { - set.removeSyncSetChangedListener(this); - } - if (actionGroup != null) { - Utils.syncExec((Runnable) () -> actionGroup.dispose(), getViewer()); - } + // Only dispose the update handler if it is + // directly associated with this provider + if (isRootProvider()) { + updateHandler.dispose(); + getTree().removeTreeListener(this); + } else { + set.removeSyncSetChangedListener(this); + } + if (actionGroup != null) { + Utils.syncExec((Runnable) () -> actionGroup.dispose(), getViewer()); + } this.disposed = true; } - private boolean isRootProvider() { - return updateHandler.getProvider() == this; - } + private boolean isRootProvider() { + return updateHandler.getProvider() == this; + } - /** + /** * Return whether this provide has been disposed. - * @return whether this provide has been disposed - */ + * @return whether this provide has been disposed + */ public boolean isDisposed() { - return disposed; - } - - /** - * Return the closest parent elements that represents a model element that - * could contains the given resource. Multiple elements need only be returned - * if two or more logical views are being shown and each view has an element - * that could contain the resource. - * @param resource the resource - * @return one or more lowest level parents that could contain the resource - */ - public abstract ISynchronizeModelElement[] getClosestExistingParents(IResource resource); + return disposed; + } + + /** + * Return the closest parent elements that represents a model element that + * could contains the given resource. Multiple elements need only be returned + * if two or more logical views are being shown and each view has an element + * that could contain the resource. + * @param resource the resource + * @return one or more lowest level parents that could contain the resource + */ + public abstract ISynchronizeModelElement[] getClosestExistingParents(IResource resource); /** * Handle the changes made to the viewer's <code>SyncInfoSet</code>. @@ -758,7 +758,7 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo handleResourceAdditions(event); } - /** + /** * Update the viewer for the sync set additions in the provided event. This * method is invoked by <code>handleChanges(ISyncInfoSetChangeEvent)</code>. * Subclasses may override. @@ -782,30 +782,30 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo */ protected abstract void handleResourceRemovals(ISyncInfoTreeChangeEvent event); - @Override + @Override public void syncInfoChanged(final ISyncInfoSetChangeEvent event, final IProgressMonitor monitor) { if (! (event instanceof ISyncInfoTreeChangeEvent)) { reset(); } else { - updateHandler.runViewUpdate(() -> handleChanges((ISyncInfoTreeChangeEvent)event, monitor), true /* preserve expansion */); + updateHandler.runViewUpdate(() -> handleChanges((ISyncInfoTreeChangeEvent)event, monitor), true /* preserve expansion */); } - } + } - @Override + @Override public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { - // Not handled + // Not handled - } + } - @Override + @Override public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) { - reset(); - } + reset(); + } protected void addToViewer(ISynchronizeModelElement node) { - if (DEBUG) { - System.out.println("Adding model element " + node.getName()); //$NON-NLS-1$ - } + if (DEBUG) { + System.out.println("Adding model element " + node.getName()); //$NON-NLS-1$ + } propogateConflictState(node, false); // Set the marker property on this node. // There is no need to propagate this to the parents @@ -824,50 +824,50 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo } /* - * Propagate the marker property to the parent if it is not already there. - * Only propagate warnings if the parent isn't an error already. - */ - private void propogateMarkerPropertyToParent(ISynchronizeModelElement node, String property) { - ISynchronizeModelElement parent = (ISynchronizeModelElement)node.getParent(); - if (parent != null - && !parent.getProperty(property) - && !parent.getProperty(ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY)) { - parent.setProperty(property, true); - propogateMarkerPropertyToParent(parent, property); - } - } - - /** + * Propagate the marker property to the parent if it is not already there. + * Only propagate warnings if the parent isn't an error already. + */ + private void propogateMarkerPropertyToParent(ISynchronizeModelElement node, String property) { + ISynchronizeModelElement parent = (ISynchronizeModelElement)node.getParent(); + if (parent != null + && !parent.getProperty(property) + && !parent.getProperty(ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY)) { + parent.setProperty(property, true); + propogateMarkerPropertyToParent(parent, property); + } + } + + /** * Remove any traces of the model element and any of it's descendants in the * hierarchy defined by the content provider from the content provider and * the viewer it is associated with. * @param nodes the model elements to remove */ protected void removeFromViewer(ISynchronizeModelElement[] nodes) { - List<ISynchronizeModelElement> rootsToClear = new ArrayList<>(); - for (int i = 0; i < nodes.length; i++) { - ISynchronizeModelElement node = nodes[i]; - if (DEBUG) { - System.out.println("Removing model element " + node.getName()); //$NON-NLS-1$ - } + List<ISynchronizeModelElement> rootsToClear = new ArrayList<>(); + for (int i = 0; i < nodes.length; i++) { + ISynchronizeModelElement node = nodes[i]; + if (DEBUG) { + System.out.println("Removing model element " + node.getName()); //$NON-NLS-1$ + } ISynchronizeModelElement rootToClear= getRootToClear(node); if (DEBUG) { if (rootToClear != node) { System.out.println("Removing parent element " + rootToClear.getName()); //$NON-NLS-1$ } - } + } propogateConflictState(rootToClear, true /* clear the conflict */); clearModelObjects(rootToClear); rootsToClear.add(rootToClear); - } - ISynchronizeModelElement[] roots = rootsToClear.toArray(new ISynchronizeModelElement[rootsToClear.size()]); + } + ISynchronizeModelElement[] roots = rootsToClear.toArray(new ISynchronizeModelElement[rootsToClear.size()]); if (Utils.canUpdateViewer(getViewer())) { doRemove(roots); } for (int i = 0; i < roots.length; i++) { - ISynchronizeModelElement element = roots[i]; + ISynchronizeModelElement element = roots[i]; updateHandler.nodeRemoved(element, this); - } + } } /** @@ -878,92 +878,92 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo * @param node the root node */ protected final void clearModelObjects(ISynchronizeModelElement node) { - // When clearing model objects, any parents of the node - // That are not out-of-sync, not the model root and that would - // be empty as a result of this clear, should also be cleared. - ISynchronizeModelElement rootToClear = getRootToClear(node); - // Recursively clear the nodes from the root - recursiveClearModelObjects(rootToClear); - if (node == getModelRoot()) { - IDiffElement[] children = node.getChildren(); - for (int i = 0; i < children.length; i++) { - IDiffElement element = children[i]; - ((SynchronizeModelElement)node).remove(element); - } - } else { - SynchronizeModelElement parent = ((SynchronizeModelElement)node.getParent()); - if (parent != null) parent.remove(node); - } + // When clearing model objects, any parents of the node + // That are not out-of-sync, not the model root and that would + // be empty as a result of this clear, should also be cleared. + ISynchronizeModelElement rootToClear = getRootToClear(node); + // Recursively clear the nodes from the root + recursiveClearModelObjects(rootToClear); + if (node == getModelRoot()) { + IDiffElement[] children = node.getChildren(); + for (int i = 0; i < children.length; i++) { + IDiffElement element = children[i]; + ((SynchronizeModelElement)node).remove(element); + } + } else { + SynchronizeModelElement parent = ((SynchronizeModelElement)node.getParent()); + if (parent != null) parent.remove(node); + } } /** * Method that subclasses can override when clearing model objects. - * @param node the node to be cleared recursively - */ - protected void recursiveClearModelObjects(ISynchronizeModelElement node) { - // Clear all the children of the node + * @param node the node to be cleared recursively + */ + protected void recursiveClearModelObjects(ISynchronizeModelElement node) { + // Clear all the children of the node IDiffElement[] children = node.getChildren(); for (int i = 0; i < children.length; i++) { IDiffElement element = children[i]; if (element instanceof ISynchronizeModelElement) { - ISynchronizeModelElement sme = (ISynchronizeModelElement) element; - ISynchronizeModelProvider provider = getProvider(sme); - if (provider != null && provider instanceof AbstractSynchronizeModelProvider) { - ((AbstractSynchronizeModelProvider)provider).recursiveClearModelObjects(sme); - } else { - recursiveClearModelObjects(sme); - } + ISynchronizeModelElement sme = (ISynchronizeModelElement) element; + ISynchronizeModelProvider provider = getProvider(sme); + if (provider != null && provider instanceof AbstractSynchronizeModelProvider) { + ((AbstractSynchronizeModelProvider)provider).recursiveClearModelObjects(sme); + } else { + recursiveClearModelObjects(sme); + } } } // Notify the update handler that the node has been cleared if (node != getModelRoot()) updateHandler.modelObjectCleared(node); - } - - /* - * Remove to root should only remove to the root of the provider and not the - * diff tree. - */ - private ISynchronizeModelElement getRootToClear(ISynchronizeModelElement node) { - if (node == getModelRoot()) return node; - ISynchronizeModelElement parent = (ISynchronizeModelElement)node.getParent(); + } + + /* + * Remove to root should only remove to the root of the provider and not the + * diff tree. + */ + private ISynchronizeModelElement getRootToClear(ISynchronizeModelElement node) { + if (node == getModelRoot()) return node; + ISynchronizeModelElement parent = (ISynchronizeModelElement)node.getParent(); if (parent != null && parent != getModelRoot() && !isOutOfSync(parent) && parent.getChildren().length == 1) { - return getRootToClear(parent); + return getRootToClear(parent); } return node; - } - - /* - * Return whether the node represents an out-of-sync resource. - */ - protected boolean isOutOfSync(ISynchronizeModelElement node) { - SyncInfo info = Utils.getSyncInfo(node); - return (info != null && info.getKind() != SyncInfo.IN_SYNC); - } - - protected boolean isOutOfSync(IResource resource) { - SyncInfo info = getSyncInfoSet().getSyncInfo(resource); - return (info != null && info.getKind() != SyncInfo.IN_SYNC); - } - - /** + } + + /* + * Return whether the node represents an out-of-sync resource. + */ + protected boolean isOutOfSync(ISynchronizeModelElement node) { + SyncInfo info = Utils.getSyncInfo(node); + return (info != null && info.getKind() != SyncInfo.IN_SYNC); + } + + protected boolean isOutOfSync(IResource resource) { + SyncInfo info = getSyncInfoSet().getSyncInfo(resource); + return (info != null && info.getKind() != SyncInfo.IN_SYNC); + } + + /** * Return the provider that created and manages the given * model element. The default is to return the receiver. * Subclasses may override. - * @param element the synchronize model element - * @return the provider that created the element - */ - protected ISynchronizeModelProvider getProvider(ISynchronizeModelElement element) { - return this; - } - - /** - * Add the element to the viewer. - * @param parent the parent of the element which is already added to the viewer - * @param element the element to be added to the viewer - */ + * @param element the synchronize model element + * @return the provider that created the element + */ + protected ISynchronizeModelProvider getProvider(ISynchronizeModelElement element) { + return this; + } + + /** + * Add the element to the viewer. + * @param parent the parent of the element which is already added to the viewer + * @param element the element to be added to the viewer + */ protected void doAdd(ISynchronizeModelElement parent, ISynchronizeModelElement element) { - updateHandler.doAdd(parent, element); + updateHandler.doAdd(parent, element); } /** @@ -973,17 +973,17 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo protected void doRemove(ISynchronizeModelElement[] elements) { AbstractTreeViewer viewer = (AbstractTreeViewer)getViewer(); try { - viewer.remove(elements); - } catch (SWTException e) { - // The remove failed due to an SWT exception. Log it and continue - TeamUIPlugin.log(IStatus.ERROR, "An error occurred removing elements from the synchronize view", e); //$NON-NLS-1$ - } - if (DEBUG) { - for (int i = 0; i < elements.length; i++) { - ISynchronizeModelElement element = elements[i]; - System.out.println("Removing view item " + element.getName()); //$NON-NLS-1$ - } - } + viewer.remove(elements); + } catch (SWTException e) { + // The remove failed due to an SWT exception. Log it and continue + TeamUIPlugin.log(IStatus.ERROR, "An error occurred removing elements from the synchronize view", e); //$NON-NLS-1$ + } + if (DEBUG) { + for (int i = 0; i < elements.length; i++) { + ISynchronizeModelElement element = elements[i]; + System.out.println("Removing view item " + element.getName()); //$NON-NLS-1$ + } + } } /** @@ -994,7 +994,7 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo * @param provider the provider that added the node */ protected void nodeAdded(ISynchronizeModelElement node, AbstractSynchronizeModelProvider provider) { - // Default is to do nothing + // Default is to do nothing } /** @@ -1006,46 +1006,46 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo * @param node */ protected void nodeRemoved(ISynchronizeModelElement node, AbstractSynchronizeModelProvider provider) { - // Default is to do nothing + // Default is to do nothing } - /** + /** * This is a callback from the model update handler that gets invoked * when a node is cleared from the model. It is only invoked for the * root level model provider. This callback is deep in the sense that * a callback is sent for each node that is cleared. - * @param node the node that was cleared. - */ - public void modelObjectCleared(ISynchronizeModelElement node) { - // Default is to do nothing - } + * @param node the node that was cleared. + */ + public void modelObjectCleared(ISynchronizeModelElement node) { + // Default is to do nothing + } - @Override + @Override public void addPropertyChangeListener(IPropertyChangeListener listener) { - synchronized (this) { - if (listeners == null) { - listeners = new ListenerList<>(ListenerList.IDENTITY); - } - listeners.add(listener); - } - - } - @Override + synchronized (this) { + if (listeners == null) { + listeners = new ListenerList<>(ListenerList.IDENTITY); + } + listeners.add(listener); + } + + } + @Override public void removePropertyChangeListener(IPropertyChangeListener listener) { - if (listeners != null) { - synchronized (this) { - listeners.remove(listener); - if (listeners.isEmpty()) { - listeners = null; - } - } - } - } + if (listeners != null) { + synchronized (this) { + listeners.remove(listener); + if (listeners.isEmpty()) { + listeners = null; + } + } + } + } protected void firePropertyChange(String key, Object oldValue, Object newValue) { Object[] allListeners; synchronized(this) { - allListeners = listeners.getListeners(); + allListeners = listeners.getListeners(); } final PropertyChangeEvent event = new PropertyChangeEvent(this, key, oldValue, newValue); for (int i = 0; i < allListeners.length; i++) { @@ -1063,13 +1063,13 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo } } - /** - * Wait until the provider is done processing any events and - * the page content are up-to-date. - * This method is for testing purposes only. - * @param monitor - */ - public void waitUntilDone(IProgressMonitor monitor) { + /** + * Wait until the provider is done processing any events and + * the page content are up-to-date. + * This method is for testing purposes only. + * @param monitor + */ + public void waitUntilDone(IProgressMonitor monitor) { monitor.worked(1); // wait for the event handler to process changes. while(updateHandler.getEventHandlerJob().getState() != Job.NONE) { @@ -1081,32 +1081,32 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo Policy.checkCanceled(monitor); } monitor.worked(1); - } + } - @Override + @Override public String toString() { - ISynchronizeModelElement element = getModelRoot(); - String name = getClass().getName(); - int index = name.lastIndexOf("."); //$NON-NLS-1$ - if (index != -1) { - name = name.substring(index + 1); - } - String name2 = element.getName(); - if (name2.length() == 0) { - name2 = "/"; //$NON-NLS-1$ - } - return name + ": " + name2; //$NON-NLS-1$ - } - - /** - * Execute a runnable which performs an update of the model being displayed - * by this provider. The runnable should be executed in a thread-safe manner - * which results in the view being updated. - * @param runnable the runnable which updates the model. - * @param preserveExpansion whether the expansion of the view should be preserver - * @param runInUIThread - */ - public void performUpdate(IWorkspaceRunnable runnable, boolean preserveExpansion, boolean runInUIThread) { - updateHandler.performUpdate(runnable, preserveExpansion, runInUIThread); - } + ISynchronizeModelElement element = getModelRoot(); + String name = getClass().getName(); + int index = name.lastIndexOf("."); //$NON-NLS-1$ + if (index != -1) { + name = name.substring(index + 1); + } + String name2 = element.getName(); + if (name2.length() == 0) { + name2 = "/"; //$NON-NLS-1$ + } + return name + ": " + name2; //$NON-NLS-1$ + } + + /** + * Execute a runnable which performs an update of the model being displayed + * by this provider. The runnable should be executed in a thread-safe manner + * which results in the view being updated. + * @param runnable the runnable which updates the model. + * @param preserveExpansion whether the expansion of the view should be preserver + * @param runInUIThread + */ + public void performUpdate(IWorkspaceRunnable runnable, boolean preserveExpansion, boolean runInUIThread) { + updateHandler.performUpdate(runnable, preserveExpansion, runInUIThread); + } } |