Search in sources :

Example 66 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project whole by wholeplatform.

the class BrowseListChooser method addControls.

private void addControls() {
    Label title = new Label(this, SWT.NONE);
    title.setText("&Classes");
    Composite container = new Composite(this, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.makeColumnsEqualWidth = false;
    container.setLayout(layout);
    container.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
    listChooser = new CheckboxTreeViewer(container, SWT.BORDER);
    GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    listChooser.getControl().setLayoutData(listData);
    listChooser.setContentProvider(new ITreeContentProvider() {

        public Object[] getChildren(Object parentElement) {
            return null;
        }

        public Object[] getElements(Object inputElement) {
            return classList.toArray();
        }

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

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

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    listChooser.setLabelProvider(new LabelProvider() {

        public String getText(Object element) {
            return (((Class<?>) element).getSimpleName());
        }
    });
    listChooser.setInput(this);
    listChooser.setSorter(new ViewerSorter());
    createSelectionButtons(container);
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 67 with ITreeContentProvider

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

the class WizardBndFileSelector method createControl.

@Override
public void createControl(Composite composite) {
    checkboxTreeViewer = new CheckboxTreeViewer(composite);
    checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            ITreeContentProvider contentProvider = (ITreeContentProvider) checkboxTreeViewer.getContentProvider();
            alterChildren(element, contentProvider, event.getChecked());
            alterParents(element, contentProvider);
        }

        private void alterChildren(Object element, ITreeContentProvider contentProvider, boolean checked) {
            Queue<Object> toRecurse = new LinkedList<Object>();
            toRecurse.offer(element);
            while (!toRecurse.isEmpty()) {
                Object o = toRecurse.poll();
                for (Object child : contentProvider.getChildren(o)) {
                    if (contentProvider.hasChildren(child))
                        toRecurse.offer(child);
                    checkboxTreeViewer.setChecked(child, checked);
                    checkboxTreeViewer.setGrayed(child, false);
                }
            }
        }

        private void alterParents(Object element, ITreeContentProvider contentProvider) {
            Object parent = contentProvider.getParent(element);
            while (parent != null) {
                boolean allChecked = true;
                boolean noneChecked = true;
                for (Object child : contentProvider.getChildren(parent)) {
                    boolean checked = checkboxTreeViewer.getChecked(child);
                    boolean grayed = checkboxTreeViewer.getGrayed(child);
                    allChecked &= checked & !grayed;
                    noneChecked &= !checked;
                }
                if (allChecked) {
                    checkboxTreeViewer.setChecked(parent, true);
                    checkboxTreeViewer.setGrayed(parent, false);
                } else if (noneChecked) {
                    checkboxTreeViewer.setGrayChecked(parent, false);
                } else {
                    checkboxTreeViewer.setGrayChecked(parent, true);
                }
                parent = contentProvider.getParent(parent);
            }
        }
    });
    setControl(checkboxTreeViewer.getControl());
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Queue(java.util.Queue)

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