Search in sources :

Example 16 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.

the class AbstractFeatureTypesPage method createContent.

@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(1, false));
    // create filtered tree
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(page, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
            return new CheckboxTreeViewer(parent, style);
        }
    };
    // configure viewer
    viewer = (CheckboxTreeViewer) tree.getViewer();
    contentProvider = new FeatureTypeTreeContentProvider();
    viewer.setContentProvider(contentProvider);
    // viewer.setComparator(new DefinitionComparator());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object doubleClicked = selection.getFirstElement();
            if (doubleClicked instanceof String)
                viewer.setExpandedState(doubleClicked, !viewer.getExpandedState(doubleClicked));
            else {
                boolean newState = !checkStateProvider.isChecked(doubleClicked);
                viewer.setChecked(doubleClicked, newState);
                checkStateOfTypeChanged((QName) doubleClicked, newState);
            }
        }
    });
    viewer.setLabelProvider(new FeatureTypeTreeLabelProvider());
    // because elements filtered by FilteredTree lose their checked state:
    checkStateProvider = new ICheckStateProvider() {

        @Override
        public boolean isGrayed(Object element) {
            if (element instanceof String) {
                Object[] children = contentProvider.getChildren(element);
                boolean containsChecked = false;
                boolean containsUnchecked = false;
                for (Object child : children) {
                    if (isChecked(child))
                        containsChecked = true;
                    else
                        containsUnchecked = true;
                    if (containsChecked && containsUnchecked)
                        return true;
                }
            }
            return false;
        }

        @Override
        public boolean isChecked(Object element) {
            if (element instanceof String) {
                for (Object child : contentProvider.getChildren(element)) if (isChecked(child))
                    return true;
                return false;
            }
            return selected.contains(element);
        }
    };
    viewer.setCheckStateProvider(checkStateProvider);
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof String) {
                // update children
                viewer.setGrayed(event.getElement(), false);
                for (Object child : contentProvider.getChildren(event.getElement())) {
                    if (checkStateProvider.isChecked(child) != event.getChecked()) {
                        viewer.setChecked(child, event.getChecked());
                        checkStateOfTypeChanged((QName) child, event.getChecked());
                    }
                }
                viewer.setGrayed(event.getElement(), checkStateProvider.isGrayed(event.getElement()));
            // only two levels, no need to update any parents or
            // children's children
            } else {
                checkStateOfTypeChanged((QName) event.getElement(), event.getChecked());
            }
        }
    });
    setControl(page);
    // initial update
    updateState(selected);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) QName(javax.xml.namespace.QName) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 17 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.

the class TypeDefinitionDialog method createViewer.

@Override
protected TreeViewer createViewer(Composite parent) {
    // create viewer
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    tree.getViewer().setComparator(new DefinitionComparator());
    return tree.getViewer();
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Example 18 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.

the class WebTemplatesDialog method createViewer.

@Override
protected TreeViewer createViewer(Composite parent) {
    layout = new TreeColumnLayout();
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true) {

        @Override
        protected Control createTreeControl(Composite parent, int style) {
            Control c = super.createTreeControl(parent, style);
            c.setLayoutData(null);
            c.getParent().setLayout(layout);
            return c;
        }
    };
    return tree.getViewer();
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Example 19 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.

the class DefaultReportDetailsPage method createControls.

/**
 * @see CustomReportDetailsPage#createControls(Composite)
 */
@Override
public Control createControls(Composite parent) {
    // filtered tree sets itself GridData, so set layout to gridlayout
    parent.setLayout(GridLayoutFactory.fillDefaults().create());
    // create pattern filter for FilteredTree
    PatternFilter filter = new PatternFilter();
    // create FilteredTree
    FilteredTree filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    treeViewer = filteredTree.getViewer();
    // set content provider
    treeViewer.setContentProvider(new ReportTreeContentProvider());
    // set label provider
    treeViewer.setLabelProvider(new ReportTreeLabelProvider() {

        @Override
        public MessageType getMessageType(Message message) {
            // the current message type
            return messageType;
        }
    });
    // add menu on right-click
    MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            if (treeViewer.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
                Object o = selection.getFirstElement();
                if (o instanceof Message) {
                    Message m = (Message) o;
                    // check if a stacktrace exists
                    if (m.getStackTrace() != null && !m.getStackTrace().equals("")) {
                        // add Action to the menu
                        manager.add(new ShowStackTraceAction("Show Stack Trace", null, m));
                    }
                }
            }
        }
    });
    // remove previous menus
    menuMgr.setRemoveAllWhenShown(true);
    // add menu to viewer
    treeViewer.getTree().setMenu(menu);
    // open stacktrace on double click
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TreeSelection o = (TreeSelection) event.getSelection();
            if (o.getFirstElement() instanceof Message) {
                Message m = (Message) o.getFirstElement();
                DefaultReportDetailsPage.this.onDoubleClick(m);
            }
        }
    });
    return filteredTree;
}
Also used : ReportTreeLabelProvider(eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeLabelProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Message(eu.esdihumboldt.hale.common.core.report.Message) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ReportTreeContentProvider(eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeContentProvider) IMenuListener(org.eclipse.jface.action.IMenuListener) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 20 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project arduino-eclipse-plugin by Sloeber.

the class LibrarySelectionPage method createTree.

public void createTree(Composite parent) {
    // filtering applied to all columns
    PatternFilter filter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
            int numberOfColumns = ((TreeViewer) viewer1).getTree().getColumnCount();
            boolean isMatch = false;
            for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
                String labelText = LibraryLabelProvider.getColumnText(element, columnIndex);
                isMatch |= wordMatches(labelText);
            }
            return isMatch;
        }
    };
    this.tree = new FilteredTree(parent, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
            CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
            viewer1.setCheckStateProvider(new LibraryCheckProvider());
            viewer1.setLabelProvider(new LibraryLabelProvider());
            viewer1.setContentProvider(new LibraryContentProvider());
            return viewer1;
        }
    };
    this.viewer = this.tree.getViewer();
    this.viewer.setInput(this.libs);
    TreeColumn name = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
    name.setWidth(400);
    TreeColumn version = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
    version.setWidth(100);
    // create the editor and set its attributes
    this.editor = new TreeEditor(this.viewer.getTree());
    this.editor.horizontalAlignment = SWT.LEFT;
    this.editor.grabHorizontal = true;
    this.editor.setColumn(1);
    // this ensures the tree labels are displayed correctly
    this.viewer.refresh(true);
    // enable tooltips
    ColumnViewerToolTipSupport.enableFor(this.viewer);
    // tree interactions listener
    this.viewer.getTree().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (LibrarySelectionPage.this.editor.getEditor() != null) {
                LibrarySelectionPage.this.editor.getEditor().dispose();
            }
            final TreeItem item = event.item instanceof TreeItem ? (TreeItem) event.item : null;
            if (item != null && event.detail == SWT.CHECK) {
                if (item.getData() instanceof LibraryTree.Category) {
                    Category category = ((LibraryTree.Category) item.getData());
                    item.setGrayed(false);
                    for (LibraryTree.Library child : category.getLibraries()) {
                        if (item.getChecked()) {
                            child.setVersion(child.getLatest());
                        } else {
                            child.setVersion((ArduinoLibraryVersion) null);
                        }
                    }
                    for (TreeItem child : item.getItems()) {
                        child.setChecked(item.getChecked());
                        child.setText(1, ((LibraryTree.Library) child.getData()).getVersionString());
                    }
                } else {
                    if (item.getData() instanceof LibraryTree.Library) {
                        Library lib = ((LibraryTree.Library) item.getData());
                        if (item.getChecked()) {
                            lib.setVersion(lib.getLatest());
                        } else {
                            lib.setVersion((ArduinoLibraryVersion) null);
                        }
                        item.setText(0, lib.getName());
                        item.setText(1, lib.getVersionString());
                        verifySubtreeCheckStatus(item.getParentItem());
                    }
                }
            }
            if (item != null && item.getItemCount() == 0 && item.getChecked()) {
                // Create the dropdown and add data to it
                final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY);
                Library selectedLib = ((LibraryTree.Library) item.getData());
                for (ArduinoLibraryVersion version1 : selectedLib.getVersions()) {
                    combo.add(version1.getVersion().toString());
                }
                ArduinoLibraryVersion displayVersion = selectedLib.getVersion();
                if (displayVersion == null) {
                    displayVersion = selectedLib.getLatest();
                    selectedLib.setVersion(displayVersion);
                    item.setText(0, selectedLib.getName());
                }
                combo.select(combo.indexOf(displayVersion.getVersion().toString()));
                // Compute the width for the editor
                // Also, compute the column width, so that the dropdown fits
                // Set the focus on the dropdown and set into the editor
                combo.setFocus();
                LibrarySelectionPage.this.editor.setEditor(combo, item, 1);
                // Add a listener to set the selected item back into the
                // cell
                combo.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event1) {
                        LibraryTree.Library lib = (LibraryTree.Library) item.getData();
                        lib.setVersion(new VersionNumber(combo.getText()));
                        item.setText(1, lib.getVersionString());
                        item.setText(0, lib.getName());
                        // Item selected: end the editing session
                        combo.dispose();
                    }
                });
            }
        }
    });
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Category(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category) TreeItem(org.eclipse.swt.widgets.TreeItem) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Category(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category) Composite(org.eclipse.swt.widgets.Composite) TreeEditor(org.eclipse.swt.custom.TreeEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Library(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Library) Point(org.eclipse.swt.graphics.Point) VersionNumber(io.sloeber.core.api.VersionNumber) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ArduinoLibraryVersion(io.sloeber.core.api.Json.ArduinoLibraryVersion) CCombo(org.eclipse.swt.custom.CCombo) ArduinoLibrary(io.sloeber.core.api.Json.ArduinoLibrary) Library(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Library)

Aggregations

PatternFilter (org.eclipse.ui.dialogs.PatternFilter)31 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)23 Composite (org.eclipse.swt.widgets.Composite)20 GridLayout (org.eclipse.swt.layout.GridLayout)12 TreeViewer (org.eclipse.jface.viewers.TreeViewer)11 Viewer (org.eclipse.jface.viewers.Viewer)11 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)9 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)9 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)8 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)8 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)7 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 GridData (org.eclipse.swt.layout.GridData)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 Label (org.eclipse.swt.widgets.Label)6 Tree (org.eclipse.swt.widgets.Tree)6 CachedCheckboxTreeViewer (org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer)5 FilteredCheckboxTree (org.eclipse.egit.ui.internal.components.FilteredCheckboxTree)5