Search in sources :

Example 1 with AbstractTreeViewer

use of org.eclipse.jface.viewers.AbstractTreeViewer in project tdi-studio-se by Talend.

the class ResourceExtensionContentProvider method processDelta.

/**
     * Process a resource delta. Add any runnables
     */
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;
                // 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);
}
Also used : Control(org.eclipse.swt.widgets.Control) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 2 with AbstractTreeViewer

use of org.eclipse.jface.viewers.AbstractTreeViewer in project translationstudio8 by heartsome.

the class ResourceExtensionContentProvider method processDelta.

/**
	 * Process a resource delta. Add any runnables
	 */
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;
                // 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);
}
Also used : Control(org.eclipse.swt.widgets.Control) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 3 with AbstractTreeViewer

use of org.eclipse.jface.viewers.AbstractTreeViewer in project xtext-eclipse by eclipse.

the class HierarchyTreeContentProvider method inputChanged.

@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
    if ((viewer instanceof AbstractTreeViewer)) {
        IWorkbenchPartSite _site = this.viewPart.getSite();
        DeferredTreeContentManager _deferredTreeContentManager = new DeferredTreeContentManager(((AbstractTreeViewer) viewer), _site);
        this.deferredTreeContentManager = _deferredTreeContentManager;
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DeferredTreeContentManager(org.eclipse.ui.progress.DeferredTreeContentManager) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer)

Example 4 with AbstractTreeViewer

use of org.eclipse.jface.viewers.AbstractTreeViewer in project eclipse.platform.text by eclipse.

the class SearchResultPageTest method checkViewerDisplay.

private void checkViewerDisplay(FileSearchPage page) {
    StructuredViewer viewer = page.getViewer();
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    // make sure all elements have items.
    if (viewer instanceof AbstractTreeViewer)
        ((AbstractTreeViewer) viewer).expandAll();
    Object[] elements = result.getElements();
    for (int i = 0; i < elements.length; i++) {
        // make sure all elements in the test result are present in the viewer and have the proper count displayed
        checkElementDisplay(viewer, result, elements[i]);
    }
}
Also used : AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult)

Example 5 with AbstractTreeViewer

use of org.eclipse.jface.viewers.AbstractTreeViewer in project erlide_eclipse by erlang.

the class OpenErlangAction method run.

@Override
public void run() {
    if (isEnabled()) {
        try {
            if (selectedElement != null) {
                if (selectedElement instanceof IErlExternal) {
                    final StructuredViewer structuredViewer = site.getStructuredViewer();
                    if (structuredViewer instanceof AbstractTreeViewer) {
                        final AbstractTreeViewer treeViewer = (AbstractTreeViewer) structuredViewer;
                        final boolean expanded = treeViewer.getExpandedState(selectedElement);
                        treeViewer.setExpandedState(selectedElement, !expanded);
                    }
                } else {
                    final IEditorPart part = EditorUtility.openInEditor(selectedElement, true);
                    EditorUtility.revealInEditor(part, selectedElement);
                }
            } else if (!selectedClosedProjects.isEmpty()) {
                openResourceAction.selectionChanged((IStructuredSelection) provider.getSelection());
                openResourceAction.run();
            }
        } catch (final PartInitException e) {
            ErlLogger.warn(e);
        }
    }
}
Also used : IErlExternal(org.erlide.engine.model.root.IErlExternal) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)12 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)5 NodeList (org.eclipse.wst.dtd.core.internal.NodeList)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IResource (org.eclipse.core.resources.IResource)2 IResourceDelta (org.eclipse.core.resources.IResourceDelta)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)2 Control (org.eclipse.swt.widgets.Control)2 AttributeList (org.eclipse.wst.dtd.core.internal.AttributeList)2 DTDFile (org.eclipse.wst.dtd.core.internal.DTDFile)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 Action (org.eclipse.jface.action.Action)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ITreePathContentProvider (org.eclipse.jface.viewers.ITreePathContentProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1