Search in sources :

Example 11 with PatternFilter

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

the class EditMappableTypesPage method createControl.

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControl(Composite parent) {
    parent.setLayout(new GridLayout());
    // create filtered tree
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, 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 NSTypeTreeContentProvider();
    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((TypeDefinition) doubleClicked, newState);
            }
        }
    });
    viewer.setLabelProvider(definitionLabels);
    // 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 ((TypeDefinition) element).getConstraint(MappingRelevantFlag.class).isEnabled() != changedTypes.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 (mappedTypeFilter.select(viewer, event.getElement(), child)) {
                    if (checkStateProvider.isChecked(child) != event.getChecked()) {
                        viewer.setChecked(child, event.getChecked());
                        checkStateOfTypeChanged((TypeDefinition) 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 {
                // if (mappedTypeFilter.select(viewer, null, event.getElement()))
                checkStateOfTypeChanged((TypeDefinition) event.getElement(), event.getChecked());
            // else if (!event.getChecked())
            // viewer.setChecked(event.getElement(), true);
            }
        }
    });
    // // filter types which are used in the current alignment
    // viewer.addFilter(mappedTypeFilter);
    // set input to all types in the given index
    viewer.setInput(typeIndex.getTypes());
    // expand all except XMLSchema
    viewer.expandAll();
    viewer.setExpandedState("http://www.w3.org/2001/XMLSchema", false);
    // set control
    setControl(viewer.getControl());
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) NSTypeTreeContentProvider(eu.esdihumboldt.hale.ui.service.schema.util.NSTypeTreeContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) MappingRelevantFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)

Example 12 with PatternFilter

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

the class CodeListSelectionDialog method createViewer.

/**
 * @see AbstractViewerSelectionDialog#createViewer(Composite)
 */
@Override
protected TreeViewer createViewer(Composite parent) {
    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 CodeListComparator());
    // set filter to only accept code list selection (must be set after
    // pattern filter is created)
    setFilters(new ViewerFilter[] { new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof CodeListRef;
        }
    } });
    return tree.getViewer();
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) CodeListRef(eu.esdihumboldt.hale.common.inspire.codelists.CodeListRef)

Example 13 with PatternFilter

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

the class NewRelationPage method createViewer.

/**
 * @see ViewerWizardSelectionPage#createViewer(Composite)
 */
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
    PatternFilter filter = new PatternFilter();
    filter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    viewer = tree.getViewer();
    viewer.setContentProvider(new FunctionWizardNodeContentProvider(getContainer(), initialSelection, selectionMatcher));
    viewer.setLabelProvider(new FunctionWizardNodeLabelProvider());
    // no input needed, but we have to set something
    viewer.setInput(Boolean.TRUE);
    // set focus on viewer control to prevent odd behavior
    viewer.getControl().setFocus();
    // expand selection
    viewer.expandAll();
    // selection context
    contextProvider = new HALEContextProvider(viewer, null);
    // help update on page shown
    if (getContainer() instanceof IPageChangeProvider) {
        ((IPageChangeProvider) getContainer()).addPageChangedListener(changeListener = new IPageChangedListener() {

            @Override
            public void pageChanged(PageChangedEvent event) {
                if (event.getSelectedPage() == NewRelationPage.this) {
                    // update the help button
                    if (getContainer() instanceof HaleWizardDialog) {
                        ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(getHelpContext() != null);
                    }
                }
            }
        });
    }
    // help update on selection change
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IContext context = getHelpContext();
            // update the help button
            if (getContainer() instanceof HaleWizardDialog) {
                ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(context != null);
            }
            // update the help
            if (context != null) {
                TrayDialog trayDialog = (TrayDialog) getContainer();
                if (trayDialog.getTray() != null) {
                    // if the tray is already open, update the help
                    performHelp();
                }
            }
        }
    });
    // load page configuration
    // XXX would be better if called from outside
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    restore(ps.getConfigurationService());
    return new Pair<StructuredViewer, Control>(viewer, tree);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) IContext(org.eclipse.help.IContext) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TrayDialog(org.eclipse.jface.dialogs.TrayDialog) HALEContextProvider(eu.esdihumboldt.hale.ui.HALEContextProvider) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) Pair(eu.esdihumboldt.util.Pair)

Example 14 with PatternFilter

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

the class TypeStructureTray method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);
    // retrieve the types
    final Collection<? extends TypeDefinition> types = this.types.getTypes();
    // heading
    Label caption = new Label(page, SWT.NONE);
    switch(schemaSpace) {
        case SOURCE:
            caption.setText("Source structure");
            break;
        case TARGET:
            caption.setText("Target structure");
            break;
    }
    caption.setFont(JFaceResources.getHeaderFont());
    // create tree viewer
    PatternFilter patternFilter = new SchemaPatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    final FilteredTree filteredTree = new TreePathFilteredTree(page, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    TreeViewer tree = filteredTree.getViewer();
    tree.setUseHashlookup(true);
    StyledDefinitionLabelProvider labelProvider = new StyledDefinitionLabelProvider(tree);
    tree.setLabelProvider(labelProvider);
    IContentProvider contentProvider = createContentProvider(tree);
    tree.setContentProvider(contentProvider);
    GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
    tree.setComparator(new DefinitionComparator());
    // set input
    if (types.size() == 1) {
        tree.setInput(types.iterator().next());
    } else {
        tree.setInput(types);
    }
    /*
		 * Groovy specific part
		 */
    // caption
    Label example = new Label(page, SWT.NONE);
    switch(schemaSpace) {
        case SOURCE:
            example.setText("Examples: Access variables");
            break;
        case TARGET:
            example.setText("Example: Build instance");
            break;
        default:
            example.setText("Example");
    }
    // source viewer
    final SourceViewer viewer = new SourceViewer(page, null, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    final IColorManager colorManager = new GroovyColorManager();
    SourceViewerConfiguration configuration = new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_TARGET, BINDING_BUILDER, BINDING_INDEX, BINDING_SOURCE, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT), null);
    viewer.configure(configuration);
    GridDataFactory.fillDefaults().grab(true, false).hint(200, 130).applyTo(viewer.getControl());
    // make sure the color manager is disposed
    viewer.getControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            colorManager.dispose();
        }
    });
    // react to tree selection changes
    tree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IDocument doc = new Document();
            GroovySourceViewerUtil.setupDocument(doc);
            String example = null;
            if (!event.getSelection().isEmpty()) {
                switch(schemaSpace) {
                    case SOURCE:
                        example = createSourceSample(event.getSelection(), types);
                        break;
                    case TARGET:
                        example = createTargetSample(event.getSelection(), types);
                        break;
                }
            }
            if (example == null || example.isEmpty()) {
                switch(schemaSpace) {
                    case SOURCE:
                        doc.set("// Please select schema elements to access");
                        break;
                    case TARGET:
                        doc.set("// Please select which schema elements\n// to include in the instance to build");
                        break;
                    default:
                        doc.set("// Please select one or more schema elements");
                }
            } else {
                doc.set(example);
            }
            viewer.setDocument(doc);
        }
    });
    tree.setSelection(StructuredSelection.EMPTY);
    return page;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) IContentProvider(org.eclipse.jface.viewers.IContentProvider) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) GroovyColorManager(eu.esdihumboldt.hale.ui.util.groovy.GroovyColorManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) IColorManager(eu.esdihumboldt.hale.ui.util.IColorManager) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) IDocument(org.eclipse.jface.text.IDocument)

Example 15 with PatternFilter

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

the class InstanceValidationReportDetailsPage 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 TreePathPatternFilter();
    filter.setIncludeLeadingWildcard(true);
    // create FilteredTree
    FilteredTree filteredTree = new TreePathFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    treeViewer = filteredTree.getViewer();
    // set content provider
    contentProvider = new InstanceValidationReportDetailsContentProvider();
    treeViewer.setContentProvider(contentProvider);
    // set label provider
    treeViewer.setLabelProvider(new InstanceValidationReportDetailsLabelProvider(contentProvider));
    // set comparator
    treeViewer.setComparator(new ViewerComparator() {

        /**
         * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
         */
        @Override
        public int category(Object element) {
            if (element instanceof QName || element instanceof Definition<?>)
                // Path
                return 0;
            else if (element instanceof String)
                // Category
                return 1;
            else
                // InstanceValidationMessage
                return 2;
        }
    });
    // 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 (getValidSelection() == null)
                return;
            // selection is valid, offer link to transformed data view
            manager.add(new ShowExampleAction());
        }
    });
    // remove previous menus
    menuMgr.setRemoveAllWhenShown(true);
    // add menu to tree
    treeViewer.getTree().setMenu(menu);
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            showSelectionInDataView();
        }
    });
    Image noReportBaseImage = InstanceValidationUIPlugin.getDefault().getImageRegistry().get(InstanceValidationUIPlugin.IMG_INSTANCE_VALIDATION);
    reportImage = new DecorationOverlayIcon(noReportBaseImage, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), IDecoration.BOTTOM_LEFT).createImage();
    return filteredTree;
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) QName(javax.xml.namespace.QName) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) Image(org.eclipse.swt.graphics.Image) IMenuListener(org.eclipse.jface.action.IMenuListener) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) 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)

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