Search in sources :

Example 61 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.

the class SourceBranchPage method createControl.

@Override
public void createControl(final Composite parent) {
    final Composite panel = new Composite(parent, SWT.NULL);
    final GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    panel.setLayout(layout);
    label = new Label(panel, SWT.NONE);
    label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    FilteredCheckboxTree fTree = new FilteredCheckboxTree(panel, null, SWT.NONE, new PatternFilter()) {

        /*
			 * Overridden to check page when refreshing is done.
			 */
        @Override
        protected WorkbenchJob doCreateRefreshJob() {
            WorkbenchJob refreshJob = super.doCreateRefreshJob();
            refreshJob.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (event.getResult().isOK()) {
                        getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                checkPage();
                            }
                        });
                    }
                }
            });
            return refreshJob;
        }
    };
    refsViewer = fTree.getCheckboxTreeViewer();
    ITreeContentProvider provider = new ITreeContentProvider() {

        @Override
        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
        // nothing
        }

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

        @Override
        public Object[] getElements(Object input) {
            return ((List) input).toArray();
        }

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

        @Override
        public Object getParent(Object element) {
            return null;
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            return null;
        }
    };
    refsViewer.setContentProvider(provider);
    refsViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (((Ref) element).getName().startsWith(Constants.R_HEADS))
                return ((Ref) element).getName().substring(Constants.R_HEADS.length());
            return ((Ref) element).getName();
        }

        @Override
        public Image getImage(Object element) {
            return RepositoryTreeNodeType.REF.getIcon();
        }
    });
    refsViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            checkPage();
        }
    });
    final Composite bPanel = new Composite(panel, SWT.NONE);
    bPanel.setLayout(new RowLayout());
    selectB = new Button(bPanel, SWT.PUSH);
    selectB.setText(UIText.SourceBranchPage_selectAll);
    selectB.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            refsViewer.setAllChecked(true);
            checkPage();
        }
    });
    unselectB = new Button(bPanel, SWT.PUSH);
    unselectB.setText(UIText.SourceBranchPage_selectNone);
    unselectB.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            refsViewer.setAllChecked(false);
            checkPage();
        }
    });
    bPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    Dialog.applyDialogFont(panel);
    setControl(panel);
    checkPage();
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) Label(org.eclipse.swt.widgets.Label) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) Composite(org.eclipse.swt.widgets.Composite) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Ref(org.eclipse.jgit.lib.Ref) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 62 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.

the class GitProjectsImportPage method createProjectsList.

/**
 * Create the checkbox list for the found projects.
 *
 * @param workArea
 */
private void createProjectsList(Composite workArea) {
    Label title = new Label(workArea, SWT.NONE);
    title.setText(UIText.WizardProjectsImportPage_ProjectsListTitle);
    Composite listComposite = new Composite(workArea, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.makeColumnsEqualWidth = false;
    listComposite.setLayout(layout);
    listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
    PatternFilter filter = new PatternFilter() {

        @Override
        public boolean isElementVisible(Viewer viewer, Object element) {
            if (getCheckedProjects().contains(element))
                return true;
            if (element instanceof ProjectRecord) {
                ProjectRecord p = (ProjectRecord) element;
                if (wordMatches(p.getProjectName()))
                    return true;
                String projectPath = p.getProjectSystemFile().getParent();
                if (projectPath.startsWith(lastPath)) {
                    String distinctPath = projectPath.substring(lastPath.length());
                    return wordMatches(distinctPath);
                } else {
                    return wordMatches(projectPath);
                }
            }
            return false;
        }
    };
    filter.setIncludeLeadingWildcard(true);
    FilteredCheckboxTree filteredTree = new FilteredCheckboxTree(listComposite, null, SWT.NONE, filter);
    filteredTree.setInitialText(UIText.WizardProjectsImportPage_filterText);
    projectsList = filteredTree.getCheckboxTreeViewer();
    GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    projectsList.getControl().setLayoutData(listData);
    projectsList.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            ProjectRecord element = (ProjectRecord) event.getElement();
            if (isProjectInWorkspace(element.getProjectName())) {
                projectsList.setChecked(element, false);
            }
            enableSelectAllButtons();
        }
    });
    // a bug in the CachedCheckboxTreeView requires us to not return null
    final Object[] children = new Object[0];
    projectsList.setContentProvider(new ITreeContentProvider() {

        @Override
        public Object[] getChildren(Object parentElement) {
            return children;
        }

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

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

        @Override
        public Object getParent(Object element) {
            return null;
        }

        @Override
        public void dispose() {
        // ignore
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // ignore
        }
    });
    projectsList.getTree().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPageComplete();
        }
    });
    projectsList.setLabelProvider(new ProjectLabelProvider());
    projectsList.setInput(this);
    projectsList.setComparator(new ViewerComparator());
    createSelectionButtons(listComposite);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 63 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.

the class LinkRequirementsCheckStateListener method updateAllChildrenAndGrayWhenAppropriate.

/**
 * Checks all the children of {@code element} in {@code checkboxTreeViewer}.
 * Grays those that may have children. Then apply this behavior on its
 * grandchildren.
 *
 * @param checkboxTreeViewer
 * @param element
 */
private static void updateAllChildrenAndGrayWhenAppropriate(CheckboxTreeViewer checkboxTreeViewer, Object element, boolean newValue) {
    ITreeContentProvider contentProvider = getTreeContentProvider(checkboxTreeViewer);
    for (Object child : Arrays.asList(contentProvider.getChildren(element))) {
        checkboxTreeViewer.setChecked(child, newValue);
        if (isOfContainerType(child)) {
            checkboxTreeViewer.setGrayed(child, newValue);
            updateAllChildrenAndGrayWhenAppropriate(checkboxTreeViewer, child, newValue);
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider)

Example 64 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.

the class LinkRequirementsDialog method expandTreeViewerUpToCheckedElements.

/**
 * Expands a {@link TreeViewer} up to all the given elements.
 *
 * @param treeViewer
 * @param checkedElements
 */
private static void expandTreeViewerUpToCheckedElements(TreeViewer treeViewer, List<Requirement> checkedElements) {
    ITreeContentProvider contentProvider = (ITreeContentProvider) treeViewer.getContentProvider();
    // We need the unicity because there may be common ancestors in the tree
    // of several checked elements. We also need the insertion order because
    // we need to expand the higher nodes first.
    LinkedHashSet<Object> treeOfElements = new LinkedHashSet<Object>();
    for (Requirement checkedElement : checkedElements) {
        Object element = checkedElement;
        while (contentProvider.getParent(element) != null) {
            treeOfElements.add(element);
            element = contentProvider.getParent(element);
        }
    }
    // Reverse the order to start with the root element (the EMF Resource).
    List<Object> elementsToExpand = new ArrayList<Object>(treeOfElements);
    Collections.reverse(elementsToExpand);
    treeViewer.setExpandedElements(elementsToExpand.toArray());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Requirement(org.obeonetwork.dsl.requirement.Requirement) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject)

Example 65 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.

the class TreeMapper method resolveTreeViewerItem.

/**
 * @param treeViewer
 * @param treeItem
 * @return
 */
private Object resolveTreeViewerItem(TreeViewer treeViewer, TreeItem treeItem) {
    // return treeItem.getData();
    ITreeContentProvider contentProvider = (ITreeContentProvider) treeViewer.getContentProvider();
    List<Integer> locations = new ArrayList<Integer>();
    TreeItem parentTreeItem = treeItem.getParentItem();
    while (parentTreeItem != null) {
        int index = Arrays.asList(parentTreeItem.getItems()).indexOf(treeItem);
        locations.add(index);
        treeItem = parentTreeItem;
        parentTreeItem = treeItem.getParentItem();
    }
    // root
    if (treeItem != null) {
        int rootIndex = Arrays.asList(treeViewer.getTree().getItems()).indexOf(treeItem);
        locations.add(rootIndex);
    }
    Collections.reverse(locations);
    Object current = contentProvider.getElements(treeViewer.getInput())[locations.get(0)];
    locations.remove(0);
    for (int index : locations) {
        current = contentProvider.getChildren(current)[index];
    }
    return current;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList)

Aggregations

ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)67 Viewer (org.eclipse.jface.viewers.Viewer)31 LabelProvider (org.eclipse.jface.viewers.LabelProvider)18 GridData (org.eclipse.swt.layout.GridData)18 Composite (org.eclipse.swt.widgets.Composite)16 TreeViewer (org.eclipse.jface.viewers.TreeViewer)15 GridLayout (org.eclipse.swt.layout.GridLayout)14 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)12 Label (org.eclipse.swt.widgets.Label)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