Search in sources :

Example 41 with ITreeContentProvider

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

the class AbstractTextSearchViewPage method internalRemoveSelected.

/**
 * Note: this is internal API and should not be called from clients outside
 * of the search plug-in.
 * <p>
 * Removes the currently selected match. Does nothing if no match is
 * selected.
 * </p>
 *
 * @noreference This method is not intended to be referenced by clients.
 */
public void internalRemoveSelected() {
    AbstractTextSearchResult result = getInput();
    if (result == null)
        return;
    StructuredViewer viewer = getViewer();
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    HashSet<Match> set = new HashSet<>();
    if (viewer instanceof TreeViewer) {
        ITreeContentProvider cp = (ITreeContentProvider) viewer.getContentProvider();
        collectAllMatchesBelow(result, set, cp, selection.toArray());
    } else {
        collectAllMatches(set, selection.toArray());
    }
    navigateNext(true);
    Match[] matches = new Match[set.size()];
    set.toArray(matches);
    result.removeMatches(matches);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashSet(java.util.HashSet)

Example 42 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project knime-core by knime.

the class WorkflowExportPage method createTreeViewer.

private void createTreeViewer(final Composite parent) {
    m_treeViewer = new CheckboxTreeViewer(parent);
    m_treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    m_treeViewer.setContentProvider(new ITreeContentProvider() {

        // assume to have IContainers as input
        @Override
        public Object[] getChildren(final Object parentElement) {
            if (parentElement instanceof IContainer) {
                IContainer container = (IContainer) parentElement;
                try {
                    // return only workflows and workflow groups
                    Collection<IContainer> children = new ArrayList<IContainer>();
                    for (IResource r : container.members(false)) {
                        if (KnimeResourceUtil.isWorkflow(r) || KnimeResourceUtil.isWorkflowGroup(r)) {
                            // if it is a workflow or workflow group
                            // it must be a container
                            children.add((IContainer) r);
                        }
                    }
                    return children.toArray();
                } catch (CoreException e) {
                    return new Object[0];
                }
            }
            return new Object[0];
        }

        @Override
        public Object getParent(final Object element) {
            if (element instanceof IResource) {
                return ((IResource) element).getParent();
            }
            return null;
        }

        @Override
        public boolean hasChildren(final Object element) {
            if (element instanceof IWorkspaceRoot) {
                return true;
            }
            if ((element instanceof IContainer) && KnimeResourceUtil.isWorkflowGroup((IContainer) element)) {
                return true;
            }
            return false;
        }

        @Override
        public Object[] getElements(final Object inputElement) {
            return getChildren(inputElement);
        }

        @Override
        public void dispose() {
        // nothing to do
        }

        @Override
        public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
        // nothing to do
        }
    });
    m_treeViewer.setLabelProvider(new KnimeResourceLabelProvider());
    m_treeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            Object o = event.getElement();
            boolean isChecked = event.getChecked();
            // first expand in order to be able to check children as well
            m_treeViewer.expandToLevel(o, AbstractTreeViewer.ALL_LEVELS);
            m_treeViewer.setSubtreeChecked(o, isChecked);
            if (o instanceof IResource) {
                IResource element = (IResource) o;
                setParentTreeChecked(m_treeViewer, element, isChecked);
            }
            dialogChanged();
            getWizard().getContainer().updateButtons();
        }
    });
    m_treeViewer.getTree().setVisible(false);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) KnimeResourceLabelProvider(org.knime.workbench.ui.navigator.KnimeResourceLabelProvider) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) IContainer(org.eclipse.core.resources.IContainer) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) IResource(org.eclipse.core.resources.IResource)

Example 43 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project knime-core by knime.

the class WorkflowImportSelectionPage method createWorkflowListComposite.

/**
 * @param parent parent composite
 * @return the lower part of the workflow selection page, the list with
 *  selected workflows to import
 */
protected Composite createWorkflowListComposite(final Composite parent) {
    Group overall = new Group(parent, SWT.FILL);
    overall.setText("Workflows:");
    overall.setLayoutData(FILL_BOTH);
    overall.setLayout(new GridLayout(2, false));
    // list with checkboxes....
    m_workflowListUI = new CheckboxTreeViewer(overall);
    m_workflowListUI.getTree().setLayoutData(FILL_BOTH);
    m_workflowListUI.setContentProvider(new ITreeContentProvider() {

        @Override
        public Object[] getChildren(final Object parentElement) {
            if (parentElement instanceof IWorkflowImportElement) {
                return ((IWorkflowImportElement) parentElement).getChildren().toArray();
            }
            return new Object[0];
        }

        @Override
        public Object getParent(final Object element) {
            if (element instanceof IWorkflowImportElement) {
                return ((IWorkflowImportElement) element).getParent();
            }
            return null;
        }

        @Override
        public boolean hasChildren(final Object element) {
            if (element instanceof IWorkflowImportElement) {
                return ((IWorkflowImportElement) element).getChildren().size() > 0;
            }
            return false;
        }

        @Override
        public Object[] getElements(final Object inputElement) {
            return getChildren(inputElement);
        }

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
        // should never happen
        }
    });
    m_workflowListUI.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IWorkflowImportElement) {
                IWorkflowImportElement wf = (IWorkflowImportElement) element;
                return wf.getName();
            }
            return element.toString();
        }

        @Override
        public Image getImage(final Object element) {
            if (element instanceof IWorkflowImportElement) {
                IWorkflowImportElement wf = (IWorkflowImportElement) element;
                // display invalid ones differently
                if (wf.isInvalid()) {
                    return IMG_WARN;
                } else if (wf.isWorkflow()) {
                    return KnimeResourceLabelProvider.CLOSED_WORKFLOW;
                } else if (wf.isWorkflowGroup()) {
                    return KnimeResourceLabelProvider.WORKFLOW_GROUP;
                }
            }
            return super.getImage(element);
        }
    });
    m_workflowListUI.setInput(m_importRoot);
    m_workflowListUI.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            Object o = event.getElement();
            boolean isChecked = event.getChecked();
            // first expand in order to be able to check children as well
            m_workflowListUI.expandToLevel(o, AbstractTreeViewer.ALL_LEVELS);
            m_workflowListUI.setSubtreeChecked(o, isChecked);
            if (o instanceof IWorkflowImportElement) {
                IWorkflowImportElement element = (IWorkflowImportElement) o;
                setParentTreeChecked(m_workflowListUI, element, isChecked);
            }
            validateWorkflows();
        }
    });
    // and 3 buttons -> panel in second column
    GridData rightAlign = new GridData();
    rightAlign.horizontalAlignment = SWT.RIGHT;
    rightAlign.verticalAlignment = SWT.BEGINNING;
    Composite buttonPanel = new Composite(overall, SWT.NONE);
    buttonPanel.setLayout(new GridLayout(1, false));
    buttonPanel.setLayoutData(rightAlign);
    // select all
    Button selectAllBtn = new Button(buttonPanel, SWT.PUSH);
    selectAllBtn.setText("Select All");
    selectAllBtn.setLayoutData(m_btnData);
    selectAllBtn.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (m_importRoot != null) {
                m_workflowListUI.expandAll();
                m_workflowListUI.setAllChecked(true);
                validateWorkflows();
            }
        }
    });
    // deselect all
    Button deselectAllBtn = new Button(buttonPanel, SWT.PUSH);
    deselectAllBtn.setText("Deselect All");
    deselectAllBtn.setLayoutData(m_btnData);
    deselectAllBtn.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (m_importRoot != null) {
                m_workflowListUI.expandAll();
                m_workflowListUI.setAllChecked(false);
                validateWorkflows();
            }
        }
    });
    // below a check box -> copy projects
    m_copyProjectsUI = new Button(overall, SWT.CHECK);
    m_copyProjectsUI.setText("Copy projects into workspace");
    m_copyProjectsUI.setSelection(true);
    m_copyProjectsUI.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            validateWorkflows();
        }
    });
    // if from zip this checkbox must be disabled
    m_copyProjectsUI.setEnabled(initialFromDir);
    return parent;
}
Also used : Group(org.eclipse.swt.widgets.Group) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Composite(org.eclipse.swt.widgets.Composite) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Image(org.eclipse.swt.graphics.Image) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) KnimeResourceLabelProvider(org.knime.workbench.ui.navigator.KnimeResourceLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 44 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project tmdm-studio-se by Talend.

the class DataModelMainPage method activeMarkerItem.

private void activeMarkerItem(TreeViewer v, Element dom) {
    ITreeContentProvider provider = (ITreeContentProvider) v.getContentProvider();
    for (Object data : provider.getElements(xsdSchema)) {
        Object[] foundData = findMarkerData(provider, data, dom, new Object[0]);
        if (foundData != null) {
            TreePath treePath = new TreePath(foundData);
            v.setSelection(new TreeSelection(treePath));
            return;
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) TreeObject(com.amalto.workbench.models.TreeObject)

Example 45 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project webtools.sourceediting by eclipse.

the class XMLSyntaxColoringPage method createStylesViewer.

/**
 * Creates the List viewer where we see the various syntax element display
 * names--would it ever be a Tree like JDT's?
 *
 * @param parent
 * @return
 */
private StructuredViewer createStylesViewer(Composite parent) {
    StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    stylesViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    stylesViewer.setLabelProvider(new LabelProvider() {

        public String getText(Object element) {
            Object description = fStyleToDescriptionMap.get(element);
            if (description != null)
                return description.toString();
            return super.getText(element);
        }
    });
    stylesViewer.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return getStylePreferenceKeys().toArray();
        }

        public Object[] getElements(Object inputElement) {
            return getChildren(inputElement);
        }

        public Object getParent(Object element) {
            return getStylePreferenceKeys();
        }

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    return stylesViewer;
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)68 Viewer (org.eclipse.jface.viewers.Viewer)32 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 GridData (org.eclipse.swt.layout.GridData)19 Composite (org.eclipse.swt.widgets.Composite)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 GridLayout (org.eclipse.swt.layout.GridLayout)15 Label (org.eclipse.swt.widgets.Label)13 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)12 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)11 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)11 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)11 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)11 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)11 ArrayList (java.util.ArrayList)10 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)9 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)9 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)8 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7