Search in sources :

Example 1 with TreePathFilteredTree

use of eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree in project hale by halestudio.

the class PropertyDefinitionDialog method createViewer.

/**
 * @see AbstractViewerSelectionDialog#createViewer(Composite)
 */
@Override
protected TreeViewer createViewer(Composite parent) {
    // create viewer
    SchemaPatternFilter patternFilter = new SchemaPatternFilter() {

        @Override
        protected boolean matches(Viewer viewer, Object element) {
            boolean superMatches = super.matches(viewer, element);
            if (!superMatches)
                return false;
            return acceptObject(viewer, getFilters(), ((TreePath) element).getLastSegment());
        }
    };
    patternFilter.setUseEarlyReturnIfMatcherIsNull(false);
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new TreePathFilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    tree.getViewer().setComparator(new DefinitionComparator());
    return tree.getViewer();
}
Also used : SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree)

Example 2 with TreePathFilteredTree

use of eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree 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 3 with TreePathFilteredTree

use of eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree 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)

Example 4 with TreePathFilteredTree

use of eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree in project hale by halestudio.

the class PageFunctions method createContents.

/**
 * @see org.eclipse.jface.dialogs.DialogTray#createContents(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createContents(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(comp);
    Label label = new Label(comp, SWT.NONE);
    label.setText("Functions Overview");
    label.setFont(JFaceResources.getHeaderFont());
    // tree viwever
    PatternFilter patternFilter = new TreePathPatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    final FilteredTree filteredTree = new TreePathFilteredTree(comp, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    TreeViewer tree = filteredTree.getViewer();
    tree.setUseHashlookup(true);
    HelperFunctionLabelProvider labelProvider = new HelperFunctionLabelProvider();
    tree.setLabelProvider(labelProvider);
    IContentProvider contentProvider;
    HelperFunctionsService functions = HaleUI.getServiceProvider().getService(HelperFunctionsService.class);
    contentProvider = new TreePathProviderAdapter(new HelperFunctionContentProvider(functions));
    tree.setContentProvider(contentProvider);
    GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
    tree.setComparator(new HelperFunctionComparator());
    tree.setInput(Category.ROOT);
    // Examples
    Label example = new Label(comp, SWT.NONE);
    example.setText("Function documentation");
    try {
        browser = new Browser(comp, SWT.WRAP | SWT.BORDER);
        browser.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 250).create());
    } catch (Throwable e) {
        if (BROWSER_ERROR_REPORTED.compareAndSet(false, true)) {
            log.error("Could not create embedded browser, using text field as fall-back", e);
        }
        textField = new Text(comp, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        textField.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 250).create());
    }
    tree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String eg = null;
            HelperFunctionSpecification hfs = null;
            if (!event.getSelection().isEmpty()) {
                TreeSelection treesel = (TreeSelection) event.getSelection();
                TreePath[] paths = treesel.getPaths();
                if (paths != null) {
                    TreePath path = paths[0];
                    for (int i = 0; i < path.getSegmentCount(); i++) {
                        if (path.getSegment(i) instanceof Category) {
                            eg = "Select a function to see its documentation.";
                            if (browser != null) {
                                browser.setText(eg);
                            } else if (textField != null) {
                                textField.setText(eg);
                            }
                        } else if (path.getSegment(i) instanceof HelperFunctionOrCategory) {
                            HelperFunctionOrCategory hfoc = ((HelperFunctionOrCategory) path.getSegment(i));
                            try {
                                hfs = (HelperFunctionSpecification) hfoc.asFunction().getSpec(hfoc.getName());
                            } catch (Exception e) {
                                log.error("There is a problem in retrieving the specification for a helper function.", e);
                            }
                            // displaying the specification
                            if (browser != null) {
                                eg = getFunctionSpecHTML(hfs);
                                browser.setText(eg);
                            } else if (textField != null) {
                                eg = getFunctionSpecText(hfs);
                                textField.setText(eg);
                            }
                        }
                    }
                }
            }
        }
    });
    return comp;
}
Also used : HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) HelperFunctionsService(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService) Category(eu.esdihumboldt.cst.functions.groovy.helper.Category) HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) IContentProvider(org.eclipse.jface.viewers.IContentProvider) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) TreeViewer(org.eclipse.jface.viewers.TreeViewer) 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) StyledString(org.eclipse.jface.viewers.StyledString) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) TreePathProviderAdapter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter) TreePath(org.eclipse.jface.viewers.TreePath) HelperFunctionSpecification(eu.esdihumboldt.cst.functions.groovy.helper.spec.impl.HelperFunctionSpecification) Browser(org.eclipse.swt.browser.Browser)

Example 5 with TreePathFilteredTree

use of eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree in project hale by halestudio.

the class EntityDialog method createViewer.

/**
 * @see AbstractViewerSelectionDialog#createViewer(Composite)
 */
@Override
protected TreeViewer createViewer(Composite parent) {
    // create viewer
    SchemaPatternFilter patternFilter = new SchemaPatternFilter() {

        @Override
        protected boolean matches(Viewer viewer, Object element) {
            boolean superMatches = super.matches(viewer, element);
            if (!superMatches)
                return false;
            return acceptObject(viewer, getFilters(), ((TreePath) element).getLastSegment());
        }
    };
    patternFilter.setUseEarlyReturnIfMatcherIsNull(false);
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new TreePathFilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    tree.getViewer().setComparator(new DefinitionComparator());
    // create context menu
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(this);
    Menu targetMenu = menuManager.createContextMenu(tree.getViewer().getControl());
    tree.getViewer().getControl().setMenu(targetMenu);
    if (SchemaSpaceID.SOURCE.equals(ssid)) {
        // condition contexts only supported for source schema
        // ensure viewer is updated on context changes
        final EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
        eds.addListener(entityDefinitionListener = new EntityDefinitionServiceListener() {

            @Override
            public void contextsAdded(Iterable<EntityDefinition> contextEntities) {
                refreshInDisplayThread();
            }

            @Override
            public void contextRemoved(EntityDefinition contextEntity) {
                refreshInDisplayThread();
            }

            @Override
            public void contextAdded(EntityDefinition contextEntity) {
                refreshInDisplayThread();
            }
        });
        // remove listener from entity def service
        tree.getViewer().getControl().addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (entityDefinitionListener != null) {
                    eds.removeListener(entityDefinitionListener);
                }
            }
        });
    }
    return tree.getViewer();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) EntityDefinitionServiceListener(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionServiceListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

TreePathFilteredTree (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree)5 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 DefinitionComparator (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator)3 SchemaPatternFilter (eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter)3 PatternFilter (org.eclipse.ui.dialogs.PatternFilter)3 TreePathPatternFilter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 MenuManager (org.eclipse.jface.action.MenuManager)2 IContentProvider (org.eclipse.jface.viewers.IContentProvider)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 Viewer (org.eclipse.jface.viewers.Viewer)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 Menu (org.eclipse.swt.widgets.Menu)2 Category (eu.esdihumboldt.cst.functions.groovy.helper.Category)1 HelperFunctionOrCategory (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory)1