List of usage examples for org.eclipse.jface.viewers AbstractTreeViewer remove
public void remove(Object elementsOrTreePaths)
From source file:org.eclipse.imp.lpg.search.LPGSearchTreeContentProvider.java
License:Open Source License
public void elementsChanged(Object[] updatedElements) { AbstractTreeViewer viewer = (AbstractTreeViewer) getPage().getViewer(); if (fResult == null) return;/*from www .j a v a 2s. c om*/ Set toRemove = new HashSet(); Set toUpdate = new HashSet(); Map toAdd = new HashMap(); for (int i = 0; i < updatedElements.length; i++) { if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0) insert(toAdd, toUpdate, updatedElements[i]); else remove(toRemove, toUpdate, updatedElements[i]); } viewer.remove(toRemove.toArray()); for (Iterator iter = toAdd.keySet().iterator(); iter.hasNext();) { Object parent = iter.next(); HashSet children = (HashSet) toAdd.get(parent); viewer.add(parent, children.toArray()); } for (Iterator elementsToUpdate = toUpdate.iterator(); elementsToUpdate.hasNext();) { viewer.refresh(elementsToUpdate.next()); } }
From source file:org.eclipse.team.internal.ui.synchronize.AbstractSynchronizeModelProvider.java
License:Open Source License
/** * Remove the element from the viewer//from w w w.ja v a 2s . co m * @param elements the elements to be removed */ 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$ } } }
From source file:org.eclipse.ui.internal.navigator.resources.workbench.ResourceExtensionContentProvider.java
License:Open Source License
/** * Process a resource delta. Add any runnables */// w w w .j a va 2 s . co m private void processDelta(IResourceDelta delta, Collection runnables) { //he widget may have been destroyed // by the time this is run. Check for this and do nothing if so. Control ctrl = viewer.getControl(); if (ctrl == null || ctrl.isDisposed()) { return; } // Get the affected resource final IResource resource = delta.getResource(); // If any children have changed type, just do a full refresh of this // parent, // since a simple update on such children won't work, // and trying to map the change to a remove and add is too dicey. // The case is: folder A renamed to existing file B, answering yes to // overwrite B. IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED); for (int i = 0; i < affectedChildren.length; i++) { if ((affectedChildren[i].getFlags() & IResourceDelta.TYPE) != 0) { runnables.add(getRefreshRunnable(resource)); return; } } // Check the flags for changes the Navigator cares about. // See ResourceLabelProvider for the aspects it cares about. // Notice we don't care about F_CONTENT or F_MARKERS currently. int changeFlags = delta.getFlags(); if ((changeFlags & (IResourceDelta.OPEN | IResourceDelta.SYNC | IResourceDelta.TYPE | IResourceDelta.DESCRIPTION)) != 0) { // Runnable updateRunnable = new Runnable(){ // public void run() { // ((StructuredViewer) viewer).update(resource, null); // } // }; // runnables.add(updateRunnable); /* support the Closed Projects filter; * when a project is closed, it may need to be removed from the view. */ runnables.add(getRefreshRunnable(resource.getParent())); } // Replacing a resource may affect its label and its children if ((changeFlags & IResourceDelta.REPLACED) != 0) { runnables.add(getRefreshRunnable(resource)); return; } // Handle changed children . for (int i = 0; i < affectedChildren.length; i++) { processDelta(affectedChildren[i], runnables); } // @issue several problems here: // - should process removals before additions, to avoid multiple equal // elements in viewer // - Kim: processing removals before additions was the indirect cause of // 44081 and its varients // - Nick: no delta should have an add and a remove on the same element, // so processing adds first is probably OK // - using setRedraw will cause extra flashiness // - setRedraw is used even for simple changes // - to avoid seeing a rename in two stages, should turn redraw on/off // around combined removal and addition // - Kim: done, and only in the case of a rename (both remove and add // changes in one delta). IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED); IResourceDelta[] removedChildren = delta.getAffectedChildren(IResourceDelta.REMOVED); if (addedChildren.length == 0 && removedChildren.length == 0) { return; } final Object[] addedObjects; final Object[] removedObjects; // Process additions before removals as to not cause selection // preservation prior to new objects being added // Handle added children. Issue one update for all insertions. int numMovedFrom = 0; int numMovedTo = 0; if (addedChildren.length > 0) { addedObjects = new Object[addedChildren.length]; for (int i = 0; i < addedChildren.length; i++) { addedObjects[i] = addedChildren[i].getResource(); if ((addedChildren[i].getFlags() & IResourceDelta.MOVED_FROM) != 0) { ++numMovedFrom; } } } else { addedObjects = new Object[0]; } // Handle removed children. Issue one update for all removals. if (removedChildren.length > 0) { removedObjects = new Object[removedChildren.length]; for (int i = 0; i < removedChildren.length; i++) { removedObjects[i] = removedChildren[i].getResource(); if ((removedChildren[i].getFlags() & IResourceDelta.MOVED_TO) != 0) { ++numMovedTo; } } } else { removedObjects = new Object[0]; } // heuristic test for items moving within same folder (i.e. renames) final boolean hasRename = numMovedFrom > 0 && numMovedTo > 0; Runnable addAndRemove = new Runnable() { public void run() { if (viewer instanceof AbstractTreeViewer) { AbstractTreeViewer treeViewer = (AbstractTreeViewer) viewer; // Disable redraw until the operation is finished so we don't // get a flash of both the new and old item (in the case of // rename) // Only do this if we're both adding and removing files (the // rename case) if (hasRename) { treeViewer.getControl().setRedraw(false); } try { if (addedObjects.length > 0) { treeViewer.add(resource, addedObjects); } if (removedObjects.length > 0) { treeViewer.remove(removedObjects); } } finally { if (hasRename) { treeViewer.getControl().setRedraw(true); } } } else { ((StructuredViewer) viewer).refresh(resource); } } }; runnables.add(addAndRemove); }
From source file:org.eclipse.ui.model.WorkbenchContentProvider.java
License:Open Source License
/** * Process a resource delta. Add any runnables *///w w w. j a v a 2 s . c o m private void processDelta(IResourceDelta delta, Collection runnables) { //he widget may have been destroyed // by the time this is run. Check for this and do nothing if so. Control ctrl = viewer.getControl(); if (ctrl == null || ctrl.isDisposed()) { return; } // Get the affected resource final IResource resource = delta.getResource(); // If any children have changed type, just do a full refresh of this // parent, // since a simple update on such children won't work, // and trying to map the change to a remove and add is too dicey. // The case is: folder A renamed to existing file B, answering yes to // overwrite B. IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED); for (int i = 0; i < affectedChildren.length; i++) { if ((affectedChildren[i].getFlags() & IResourceDelta.TYPE) != 0) { runnables.add(getRefreshRunnable(resource)); return; } } // Opening a project just affects icon, but we need to refresh when // a project is closed because if child items have not yet been created // in the tree we still need to update the item's children int changeFlags = delta.getFlags(); if ((changeFlags & IResourceDelta.OPEN) != 0) { if (resource.isAccessible()) { runnables.add(getUpdateRunnable(resource)); } else { runnables.add(getRefreshRunnable(resource)); return; } } // Check the flags for changes the Navigator cares about. // See ResourceLabelProvider for the aspects it cares about. // Notice we don't care about F_CONTENT or F_MARKERS currently. if ((changeFlags & (IResourceDelta.SYNC | IResourceDelta.TYPE | IResourceDelta.DESCRIPTION)) != 0) { runnables.add(getUpdateRunnable(resource)); } // Replacing a resource may affect its label and its children if ((changeFlags & IResourceDelta.REPLACED) != 0) { runnables.add(getRefreshRunnable(resource)); return; } // Handle changed children . for (int i = 0; i < affectedChildren.length; i++) { processDelta(affectedChildren[i], runnables); } // @issue several problems here: // - should process removals before additions, to avoid multiple equal // elements in viewer // - Kim: processing removals before additions was the indirect cause of // 44081 and its varients // - Nick: no delta should have an add and a remove on the same element, // so processing adds first is probably OK // - using setRedraw will cause extra flashiness // - setRedraw is used even for simple changes // - to avoid seeing a rename in two stages, should turn redraw on/off // around combined removal and addition // - Kim: done, and only in the case of a rename (both remove and add // changes in one delta). IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED); IResourceDelta[] removedChildren = delta.getAffectedChildren(IResourceDelta.REMOVED); if (addedChildren.length == 0 && removedChildren.length == 0) { return; } final Object[] addedObjects; final Object[] removedObjects; // Process additions before removals as to not cause selection // preservation prior to new objects being added // Handle added children. Issue one update for all insertions. int numMovedFrom = 0; int numMovedTo = 0; if (addedChildren.length > 0) { addedObjects = new Object[addedChildren.length]; for (int i = 0; i < addedChildren.length; i++) { addedObjects[i] = addedChildren[i].getResource(); if ((addedChildren[i].getFlags() & IResourceDelta.MOVED_FROM) != 0) { ++numMovedFrom; } } } else { addedObjects = new Object[0]; } // Handle removed children. Issue one update for all removals. if (removedChildren.length > 0) { removedObjects = new Object[removedChildren.length]; for (int i = 0; i < removedChildren.length; i++) { removedObjects[i] = removedChildren[i].getResource(); if ((removedChildren[i].getFlags() & IResourceDelta.MOVED_TO) != 0) { ++numMovedTo; } } } else { removedObjects = new Object[0]; } // heuristic test for items moving within same folder (i.e. renames) final boolean hasRename = numMovedFrom > 0 && numMovedTo > 0; Runnable addAndRemove = new Runnable() { public void run() { if (viewer instanceof AbstractTreeViewer) { AbstractTreeViewer treeViewer = (AbstractTreeViewer) viewer; // Disable redraw until the operation is finished so we don't // get a flash of both the new and old item (in the case of // rename) // Only do this if we're both adding and removing files (the // rename case) if (hasRename) { treeViewer.getControl().setRedraw(false); } try { if (addedObjects.length > 0) { treeViewer.add(resource, addedObjects); } if (removedObjects.length > 0) { treeViewer.remove(removedObjects); } } finally { if (hasRename) { treeViewer.getControl().setRedraw(true); } } } else { ((StructuredViewer) viewer).refresh(resource); } } }; runnables.add(addAndRemove); }
From source file:org.eclipse.wst.dtd.ui.views.contentoutline.DTDTreeContentProvider.java
License:Open Source License
public void nodesRemoved(NodesEvent event) { if (fViewer instanceof AbstractTreeViewer) { AbstractTreeViewer abstractTreeViewer = (AbstractTreeViewer) fViewer; for (Iterator iter = event.getNodes().iterator(); iter.hasNext();) { abstractTreeViewer.remove(iter.next()); }/*from w w w . ja va 2 s . c o m*/ } //update the tree refreshTree(event); }
From source file:org.eclipse.wst.jsdt.internal.ui.search.LevelTreeContentProvider.java
License:Open Source License
public synchronized void elementsChanged(Object[] updatedElements) { if (getSearchResult() == null) return;/* www . ja v a 2 s . c om*/ AbstractTreeViewer viewer = (AbstractTreeViewer) getPage().getViewer(); Set toRemove = new HashSet(); Set toUpdate = new HashSet(); Map toAdd = new HashMap(); for (int i = 0; i < updatedElements.length; i++) { if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0) insert(toAdd, toUpdate, updatedElements[i]); else remove(toRemove, toUpdate, updatedElements[i]); } viewer.remove(toRemove.toArray()); for (Iterator iter = toAdd.keySet().iterator(); iter.hasNext();) { Object parent = iter.next(); HashSet children = (HashSet) toAdd.get(parent); viewer.add(parent, children.toArray()); } for (Iterator elementsToUpdate = toUpdate.iterator(); elementsToUpdate.hasNext();) { viewer.refresh(elementsToUpdate.next()); } }
From source file:org.python.pydev.navigator.PythonBaseModelProvider.java
License:Open Source License
/** * Process a resource delta. Add any runnables */// w w w. j av a 2 s . co m private void processDelta(final IResourceDelta delta, final Collection<Runnable> runnables) { // he widget may have been destroyed // by the time this is run. Check for this and do nothing if so. Control ctrl = viewer.getControl(); if (ctrl == null || ctrl.isDisposed()) { return; } // Get the affected resource final IResource resource = delta.getResource(); // If any children have changed type, just do a full refresh of this // parent, // since a simple update on such children won't work, // and trying to map the change to a remove and add is too dicey. // The case is: folder A renamed to existing file B, answering yes to // overwrite B. IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED); for (int i = 0; i < affectedChildren.length; i++) { if ((affectedChildren[i].getFlags() & IResourceDelta.TYPE) != 0) { runnables.add(getRefreshRunnable(resource)); return; } } // Opening a project just affects icon, but we need to refresh when // a project is closed because if child items have not yet been created // in the tree we still need to update the item's children int changeFlags = delta.getFlags(); if ((changeFlags & IResourceDelta.OPEN) != 0) { if (resource.isAccessible()) { runnables.add(getUpdateRunnable(resource)); } else { runnables.add(getRefreshRunnable(resource)); return; } } // Check the flags for changes the Navigator cares about. // See ResourceLabelProvider for the aspects it cares about. // Notice we don't care about F_CONTENT or F_MARKERS currently. if ((changeFlags & (IResourceDelta.SYNC | IResourceDelta.TYPE | IResourceDelta.DESCRIPTION)) != 0) { runnables.add(getUpdateRunnable(resource)); } // Replacing a resource may affect its label and its children if ((changeFlags & IResourceDelta.REPLACED) != 0) { runnables.add(getRefreshRunnable(resource)); return; } // Replacing a resource may affect its label and its children if ((changeFlags & (IResourceDelta.CHANGED | IResourceDelta.CONTENT)) != 0) { if (resource instanceof IFile) { IFile file = (IFile) resource; if (PythonPathHelper.isValidSourceFile(file)) { runnables.add(getRefreshRunnable(resource)); } } return; } // Handle changed children . for (int i = 0; i < affectedChildren.length; i++) { processDelta(affectedChildren[i], runnables); } // @issue several problems here: // - should process removals before additions, to avoid multiple equal // elements in viewer // - Kim: processing removals before additions was the indirect cause of // 44081 and its varients // - Nick: no delta should have an add and a remove on the same element, // so processing adds first is probably OK // - using setRedraw will cause extra flashiness // - setRedraw is used even for simple changes // - to avoid seeing a rename in two stages, should turn redraw on/off // around combined removal and addition // - Kim: done, and only in the case of a rename (both remove and add // changes in one delta). IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED); IResourceDelta[] removedChildren = delta.getAffectedChildren(IResourceDelta.REMOVED); if (addedChildren.length == 0 && removedChildren.length == 0) { return; } final IResource[] addedObjects; final IResource[] removedObjects; // Process additions before removals as to not cause selection // preservation prior to new objects being added // Handle added children. Issue one update for all insertions. int numMovedFrom = 0; int numMovedTo = 0; if (addedChildren.length > 0) { addedObjects = new IResource[addedChildren.length]; for (int i = 0; i < addedChildren.length; i++) { final IResourceDelta addedChild = addedChildren[i]; addedObjects[i] = addedChild.getResource(); if (checkInit(addedObjects[i], runnables)) { return; // If true, it means a refresh for the parent was issued! } if ((addedChild.getFlags() & IResourceDelta.MOVED_FROM) != 0) { ++numMovedFrom; } } } else { addedObjects = EMPTY_RESOURCE_ARRAY; } // Handle removed children. Issue one update for all removals. if (removedChildren.length > 0) { removedObjects = new IResource[removedChildren.length]; for (int i = 0; i < removedChildren.length; i++) { final IResourceDelta removedChild = removedChildren[i]; removedObjects[i] = removedChild.getResource(); if (checkInit(removedObjects[i], runnables)) { return; // If true, it means a refresh for the parent was issued! } if ((removedChild.getFlags() & IResourceDelta.MOVED_TO) != 0) { ++numMovedTo; } } } else { removedObjects = EMPTY_RESOURCE_ARRAY; } // heuristic test for items moving within same folder (i.e. renames) final boolean hasRename = numMovedFrom > 0 && numMovedTo > 0; Runnable addAndRemove = new Runnable() { public void run() { if (viewer instanceof AbstractTreeViewer) { AbstractTreeViewer treeViewer = viewer; // Disable redraw until the operation is finished so we don't // get a flash of both the new and old item (in the case of // rename) // Only do this if we're both adding and removing files (the // rename case) if (hasRename) { treeViewer.getControl().setRedraw(false); } try { Set<IProject> notifyRebuilt = new HashSet<IProject>(); //now, we have to make a bridge among the tree and //the python model (so, if some element is removed, //we have to create an actual representation for it) if (addedObjects.length > 0) { treeViewer.add(resource, addedObjects); for (Object object : addedObjects) { if (object instanceof IResource) { IResource rem = (IResource) object; Object remInPythonModel = getResourceInPythonModel(rem, true); if (remInPythonModel instanceof PythonSourceFolder) { notifyRebuilt.add(rem.getProject()); } } } } if (removedObjects.length > 0) { treeViewer.remove(removedObjects); for (Object object : removedObjects) { if (object instanceof IResource) { IResource rem = (IResource) object; Object remInPythonModel = getResourceInPythonModel(rem, true); if (remInPythonModel instanceof PythonSourceFolder) { notifyRebuilt.add(rem.getProject()); } } } } for (IProject project : notifyRebuilt) { PythonNature nature = PythonNature.getPythonNature(project); if (nature != null) { notifyPythonPathRebuilt(project, nature); } } } finally { if (hasRename) { treeViewer.getControl().setRedraw(true); } } } else { ((StructuredViewer) viewer).refresh(resource); } } }; runnables.add(addAndRemove); }
From source file:org.talend.componentdesigner.resources.ResourceExtensionContentProvider.java
License:Open Source License
/** * Process a resource delta. Add any runnables *//*from w ww .j a v a 2 s. co m*/ private void processDelta(IResourceDelta delta, Collection runnables) { // he widget may have been destroyed // by the time this is run. Check for this and do nothing if so. Control ctrl = viewer.getControl(); if (ctrl == null || ctrl.isDisposed()) { return; } // Get the affected resource final IResource resource = delta.getResource(); // If any children have changed type, just do a full refresh of this // parent, // since a simple update on such children won't work, // and trying to map the change to a remove and add is too dicey. // The case is: folder A renamed to existing file B, answering yes to // overwrite B. IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED); for (int i = 0; i < affectedChildren.length; i++) { if ((affectedChildren[i].getFlags() & IResourceDelta.TYPE) != 0) { runnables.add(getRefreshRunnable(resource)); return; } } // Check the flags for changes the Navigator cares about. // See ResourceLabelProvider for the aspects it cares about. // Notice we don't care about F_CONTENT or F_MARKERS currently. int changeFlags = delta.getFlags(); if ((changeFlags & (IResourceDelta.OPEN | IResourceDelta.SYNC | IResourceDelta.TYPE | IResourceDelta.DESCRIPTION)) != 0) { // Runnable updateRunnable = new Runnable(){ // public void run() { // ((StructuredViewer) viewer).update(resource, null); // } // }; // runnables.add(updateRunnable); /* * support the Closed Projects filter; when a project is closed, it may need to be removed from the view. */ runnables.add(getRefreshRunnable(resource.getParent())); } // Replacing a resource may affect its label and its children if ((changeFlags & IResourceDelta.REPLACED) != 0) { runnables.add(getRefreshRunnable(resource)); return; } // Handle changed children . for (int i = 0; i < affectedChildren.length; i++) { processDelta(affectedChildren[i], runnables); } // @issue several problems here: // - should process removals before additions, to avoid multiple equal // elements in viewer // - Kim: processing removals before additions was the indirect cause of // 44081 and its varients // - Nick: no delta should have an add and a remove on the same element, // so processing adds first is probably OK // - using setRedraw will cause extra flashiness // - setRedraw is used even for simple changes // - to avoid seeing a rename in two stages, should turn redraw on/off // around combined removal and addition // - Kim: done, and only in the case of a rename (both remove and add // changes in one delta). IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED); IResourceDelta[] removedChildren = delta.getAffectedChildren(IResourceDelta.REMOVED); if (addedChildren.length == 0 && removedChildren.length == 0) { return; } final Object[] addedObjects; final Object[] removedObjects; // Process additions before removals as to not cause selection // preservation prior to new objects being added // Handle added children. Issue one update for all insertions. int numMovedFrom = 0; int numMovedTo = 0; if (addedChildren.length > 0) { addedObjects = new Object[addedChildren.length]; for (int i = 0; i < addedChildren.length; i++) { addedObjects[i] = addedChildren[i].getResource(); if ((addedChildren[i].getFlags() & IResourceDelta.MOVED_FROM) != 0) { ++numMovedFrom; } } } else { addedObjects = new Object[0]; } // Handle removed children. Issue one update for all removals. if (removedChildren.length > 0) { removedObjects = new Object[removedChildren.length]; for (int i = 0; i < removedChildren.length; i++) { removedObjects[i] = removedChildren[i].getResource(); if ((removedChildren[i].getFlags() & IResourceDelta.MOVED_TO) != 0) { ++numMovedTo; } } } else { removedObjects = new Object[0]; } // heuristic test for items moving within same folder (i.e. renames) final boolean hasRename = numMovedFrom > 0 && numMovedTo > 0; Runnable addAndRemove = new Runnable() { public void run() { if (viewer instanceof AbstractTreeViewer) { AbstractTreeViewer treeViewer = (AbstractTreeViewer) viewer; // Disable redraw until the operation is finished so we don't // get a flash of both the new and old item (in the case of // rename) // Only do this if we're both adding and removing files (the // rename case) if (hasRename) { treeViewer.getControl().setRedraw(false); } try { if (addedObjects.length > 0) { treeViewer.add(resource, addedObjects); } if (removedObjects.length > 0) { treeViewer.remove(removedObjects); } } finally { if (hasRename) { treeViewer.getControl().setRedraw(true); } } } else { ((StructuredViewer) viewer).refresh(resource); } } }; runnables.add(addAndRemove); }
From source file:org.zamia.plugin.views.navigator.ZamiaContentProvider.java
License:Open Source License
/** * Process a resource delta. Add any runnables *//*from w w w. java 2s .c o m*/ @SuppressWarnings({ "unchecked", "rawtypes" }) private void processDelta(IResourceDelta delta, Collection runnables) { // he widget may have been destroyed // by the time this is run. Check for this and do nothing if so. Control ctrl = viewer.getControl(); if (ctrl == null || ctrl.isDisposed()) { return; } // Get the affected resource final IResource resource = delta.getResource(); // If any children have changed type, just do a full refresh of this // parent, // since a simple update on such children won't work, // and trying to map the change to a remove and add is too dicey. // The case is: folder A renamed to existing file B, answering yes to // overwrite B. IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED); for (int i = 0; i < affectedChildren.length; i++) { if ((affectedChildren[i].getFlags() & IResourceDelta.TYPE) != 0) { runnables.add(getRefreshRunnable(resource)); return; } } // Opening a project just affects icon, but we need to refresh when // a project is closed because if child items have not yet been created // in the tree we still need to update the item's children int changeFlags = delta.getFlags(); if ((changeFlags & IResourceDelta.OPEN) != 0) { if (resource.isAccessible()) { runnables.add(getUpdateRunnable(resource)); } else { runnables.add(getRefreshRunnable(resource)); return; } } // Check the flags for changes the Navigator cares about. // See ResourceLabelProvider for the aspects it cares about. // Notice we don't care about F_CONTENT or F_MARKERS currently. if ((changeFlags & (IResourceDelta.SYNC | IResourceDelta.TYPE | IResourceDelta.DESCRIPTION)) != 0) { runnables.add(getUpdateRunnable(resource)); } // Replacing a resource may affect its label and its children if ((changeFlags & IResourceDelta.REPLACED) != 0) { runnables.add(getRefreshRunnable(resource)); return; } /* * re-parse file if source file was changed */ if ((changeFlags & (IResourceDelta.CHANGED | IResourceDelta.CONTENT)) != 0) { if (resource instanceof IFile) { // IFile file = (IFile) resource; // if(PythonPathHelper.isValidSourceFile(file)){ runnables.add(getRefreshRunnable(resource)); // } } return; } // Handle changed children . for (int i = 0; i < affectedChildren.length; i++) { processDelta(affectedChildren[i], runnables); } // @issue several problems here: // - should process removals before additions, to avoid multiple equal // elements in viewer // - Kim: processing removals before additions was the indirect cause of // 44081 and its varients // - Nick: no delta should have an add and a remove on the same element, // so processing adds first is probably OK // - using setRedraw will cause extra flashiness // - setRedraw is used even for simple changes // - to avoid seeing a rename in two stages, should turn redraw on/off // around combined removal and addition // - Kim: done, and only in the case of a rename (both remove and add // changes in one delta). IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED); IResourceDelta[] removedChildren = delta.getAffectedChildren(IResourceDelta.REMOVED); if (addedChildren.length == 0 && removedChildren.length == 0) { return; } final Object[] addedObjects; final Object[] removedObjects; // Process additions before removals as to not cause selection // preservation prior to new objects being added // Handle added children. Issue one update for all insertions. int numMovedFrom = 0; int numMovedTo = 0; if (addedChildren.length > 0) { addedObjects = new Object[addedChildren.length]; for (int i = 0; i < addedChildren.length; i++) { addedObjects[i] = addedChildren[i].getResource(); if ((addedChildren[i].getFlags() & IResourceDelta.MOVED_FROM) != 0) { ++numMovedFrom; } } } else { addedObjects = new Object[0]; } // Handle removed children. Issue one update for all removals. if (removedChildren.length > 0) { removedObjects = new Object[removedChildren.length]; for (int i = 0; i < removedChildren.length; i++) { removedObjects[i] = removedChildren[i].getResource(); if ((removedChildren[i].getFlags() & IResourceDelta.MOVED_TO) != 0) { ++numMovedTo; } } } else { removedObjects = new Object[0]; } // heuristic test for items moving within same folder (i.e. renames) final boolean hasRename = numMovedFrom > 0 && numMovedTo > 0; Runnable addAndRemove = new Runnable() { public void run() { if (viewer instanceof AbstractTreeViewer) { AbstractTreeViewer treeViewer = (AbstractTreeViewer) viewer; // Disable redraw until the operation is finished so we // don't // get a flash of both the new and old item (in the case of // rename) // Only do this if we're both adding and removing files (the // rename case) if (hasRename) { treeViewer.getControl().setRedraw(false); } try { if (addedObjects.length > 0) { treeViewer.add(resource, addedObjects); } if (removedObjects.length > 0) { treeViewer.remove(removedObjects); } } finally { if (hasRename) { treeViewer.getControl().setRedraw(true); } } } else { ((StructuredViewer) viewer).refresh(resource); } } }; runnables.add(addAndRemove); }