Search in sources :

Example 1 with StructuredViewer

use of org.eclipse.jface.viewers.StructuredViewer 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 2 with StructuredViewer

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

the class WorkingSetSorter method compare.

public int compare(Viewer viewer, Object e1, Object e2) {
    if (viewer instanceof StructuredViewer) {
        ILabelProvider labelProvider = (ILabelProvider) ((StructuredViewer) viewer).getLabelProvider();
        String text1 = labelProvider.getText(e1);
        String text2 = labelProvider.getText(e2);
        if (text1 != null) {
            return text1.compareTo(text2);
        }
    }
    return -1;
}
Also used : StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 3 with StructuredViewer

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

the class ResourceMgmtActionProvider method makeActions.

protected void makeActions() {
    IShellProvider sp = new IShellProvider() {

        public Shell getShell() {
            return shell;
        }
    };
    openProjectAction = new OpenResourceAction(sp);
    openProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_openProjectAction);
    closeProjectAction = new CloseResourceAction(sp);
    closeProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_closeProjectAction);
    //
    // closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(sp);
    // closeUnrelatedProjectsAction.setText("关闭无关的项目");
    refreshAction = new RefreshAction(sp) {

        public void run() {
            final IStatus[] errorStatus = new IStatus[1];
            errorStatus[0] = Status.OK_STATUS;
            final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
            WorkspaceJob job = new //$NON-NLS-1$
            WorkspaceJob(//$NON-NLS-1$
            "refresh") {

                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    try {
                        op.run(monitor);
                        if (shell != null && !shell.isDisposed()) {
                            shell.getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    StructuredViewer viewer = getActionSite().getStructuredViewer();
                                    if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
                                        viewer.refresh();
                                    }
                                }
                            });
                        }
                    } catch (InvocationTargetException e) {
                        String msg = NLS.bind(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_logTitle, getClass().getName(), e.getTargetException());
                        throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR, msg, e.getTargetException()));
                    } catch (InterruptedException e) {
                        return Status.CANCEL_STATUS;
                    }
                    return errorStatus[0];
                }
            };
            ISchedulingRule rule = op.getRule();
            if (rule != null) {
                job.setRule(rule);
            }
            job.setUser(true);
            job.schedule();
        }
    };
    refreshAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_refreshAction);
    //$NON-NLS-1$
    refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));
    //$NON-NLS-1$
    refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));
    refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
    if (getContext() == null) {
        refreshAction.setEnabled(false);
    } else {
        IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
        refreshAction.selectionChanged(selection);
        refreshAction.setEnabled(!selection.isEmpty());
    }
// buildAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
// buildAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
}
Also used : IShellProvider(org.eclipse.jface.window.IShellProvider) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CloseResourceAction(org.eclipse.ui.actions.CloseResourceAction) IStatus(org.eclipse.core.runtime.IStatus) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) OpenResourceAction(org.eclipse.ui.actions.OpenResourceAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RefreshAction(org.eclipse.ui.actions.RefreshAction) CoreException(org.eclipse.core.runtime.CoreException) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

Example 4 with StructuredViewer

use of org.eclipse.jface.viewers.StructuredViewer in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringWizardPage method createSelectAllCheckbox.

private void createSelectAllCheckbox(Composite parent) {
    selectAllVisibleCheckbox = new Button(parent, SWT.CHECK);
    selectAllVisibleCheckbox.setText("Toggle all the visible refactorings");
    selectAllVisibleCheckbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final Object[] visibleElements = filter(tableViewer, tableViewer.getInput());
            for (Object element : visibleElements) {
                setChecked(element, selectAllVisibleCheckbox.getSelection());
            }
        }

        private Object[] filter(StructuredViewer viewer, Object input) {
            try {
                final Class<StructuredViewer> clazz = StructuredViewer.class;
                Method m = clazz.getDeclaredMethod("filter", Object[].class);
                m.setAccessible(true);
                return (Object[]) m.invoke(viewer, (Object) ((List<?>) input).toArray());
            } catch (Exception e) {
                throw new UnhandledException(null, e);
            }
        }
    });
}
Also used : UnhandledException(org.autorefactor.util.UnhandledException) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Method(java.lang.reflect.Method) UnhandledException(org.autorefactor.util.UnhandledException)

Example 5 with StructuredViewer

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

the class CreateDiagramAction method setRepositoryNode.

private void setRepositoryNode(Properties params) {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (null == workbenchWindow) {
        return;
    }
    IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
    if (null == workbenchPage) {
        return;
    }
    IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
    if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
        // show di perspective
        try {
            workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
            workbenchPage = workbenchWindow.getActivePage();
        } catch (WorkbenchException e) {
            ExceptionHandler.process(e);
            return;
        }
    }
    // bug 16594
    IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
    if (view != null) {
        Object type = params.get("type");
        if (ERepositoryObjectType.BUSINESS_PROCESS != null && ERepositoryObjectType.BUSINESS_PROCESS.name().equals(type)) {
            RepositoryNode processNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(ERepositoryObjectType.BUSINESS_PROCESS);
            final StructuredViewer viewer = view.getViewer();
            if (viewer instanceof TreeViewer) {
                ((TreeViewer) viewer).expandToLevel(processNode, 1);
            }
            this.repositoryNode = processNode;
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) WorkbenchException(org.eclipse.ui.WorkbenchException) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Aggregations

StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 Control (org.eclipse.swt.widgets.Control)3 IPerspectiveDescriptor (org.eclipse.ui.IPerspectiveDescriptor)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 WorkbenchException (org.eclipse.ui.WorkbenchException)3 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)3 IRepositoryView (org.talend.repository.ui.views.IRepositoryView)3 IResource (org.eclipse.core.resources.IResource)2 IResourceDelta (org.eclipse.core.resources.IResourceDelta)2 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)2 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UnhandledException (org.autorefactor.util.UnhandledException)1