Search in sources :

Example 56 with TreePath

use of org.eclipse.jface.viewers.TreePath 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 57 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class TypeStructureTray method createTargetSample.

/**
 * Create sample code for populating the target property.
 *
 * @param selection the selection in the tree viewer
 * @param types the types serving as input
 * @return the sample code
 */
protected String createTargetSample(ISelection selection, Collection<? extends TypeDefinition> types) {
    ITreeSelection treeSel = (ITreeSelection) selection;
    TreePath[] paths = treeSel.getPaths();
    if (paths != null && paths.length > 0) {
        // XXX for now only use the first path
        TreePath path = paths[0];
        DefinitionGroup parent;
        int startIndex = 0;
        List<PathTree> properties;
        // determine parent type
        if (path.getFirstSegment() instanceof TypeDefinition) {
            // XXX not supported yet
            return null;
        } else {
            // types are not in the tree, single type must be root
            parent = types.iterator().next();
            // build PathTrees from tree paths
            properties = PathTree.createPathTrees(Arrays.asList(paths), startIndex);
        }
        StringBuilder example = new StringBuilder();
        example.append(GroovyConstants.BINDING_TARGET);
        example.append(" {\n");
        int indentCount = 1;
        for (PathTree tree : properties) {
            InstanceBuilderCode.appendBuildProperties(example, indentCount, tree, parent, BUILDER_USE_BRACKETS);
        }
        example.append("}");
        return example.toString();
    }
    return GroovyConstants.BINDING_TARGET + " = {}";
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) DefinitionGroup(eu.esdihumboldt.hale.common.schema.model.DefinitionGroup) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 58 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class TypeStructureTray method createSourceSample.

/**
 * Create sample code for accessing a source property.
 *
 * @param selection the selection in the tree viewer
 * @param types the types serving as input
 * @return the sample code or <code>null</code>
 */
protected String createSourceSample(ISelection selection, Collection<? extends TypeDefinition> types) {
    ITreeSelection treeSel = (ITreeSelection) selection;
    TreePath[] paths = treeSel.getPaths();
    if (paths != null && paths.length > 0) {
        StringBuilder result = null;
        for (TreePath path : paths) {
            String examples = createSourceSample(path, types);
            if (examples != null) {
                if (result == null) {
                    result = new StringBuilder();
                }
                result.append(examples);
            }
        }
        if (result != null) {
            return result.toString();
        }
        return null;
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath)

Example 59 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class InstanceValidationReportDetailsContentProvider method inputChanged.

/**
 * @see ITreePathContentProvider#inputChanged(Viewer, Object, Object)
 */
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    childCache.clear();
    messages.clear();
    limitedPaths.clear();
    if (newInput instanceof Collection<?>) {
        SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
        TreePath emptyPath = new TreePath(new Object[0]);
        for (Object o : (Collection<?>) newInput) {
            if (o instanceof InstanceValidationMessage) {
                InstanceValidationMessage message = ((InstanceValidationMessage) o);
                Set<Object> baseTypes = childCache.get(emptyPath);
                if (baseTypes == null) {
                    baseTypes = new HashSet<Object>();
                    childCache.put(emptyPath, baseTypes);
                }
                // XXX maybe expand messages with SSID?
                TypeDefinition typeDef = null;
                if (message.getType() != null) {
                    typeDef = ss.getSchemas(SchemaSpaceID.TARGET).getType(message.getType());
                }
                // use typeDef if available, QName otherwise
                Object use = typeDef == null ? message.getType() : typeDef;
                if (use == null) {
                    // fall-back to generic category
                    use = "General";
                }
                baseTypes.add(use);
                messages.put(new TreePath(new Object[] { use }), message);
            }
        }
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) Collection(java.util.Collection) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 60 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class InstanceValidationReportDetailsPage method getValidSelection.

/**
 * Returns a valid instance selection for the current selection of the tree
 * viewer. Returns <code>null</code> if there is none.
 *
 * @return a valid instance selection for the current selection of the tree
 *         viewer or <code>null</code>
 */
private InstanceSelection getValidSelection() {
    ISelection viewerSelection = treeViewer.getSelection();
    if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty())
        return null;
    ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
    // XXX use all paths
    TreePath firstPath = treeSelection.getPaths()[0];
    // instead of first
    // only?
    InstanceValidationMessage firstMessage;
    Iterator<InstanceValidationMessage> restIter;
    if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
        firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
        restIter = Iterators.emptyIterator();
    } else {
        Collection<InstanceValidationMessage> messages = contentProvider.getMessages(treeSelection.getPaths()[0]);
        if (messages.isEmpty())
            // shouldn't happen, but doesn't really matter
            return null;
        restIter = messages.iterator();
        firstMessage = restIter.next();
    }
    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    // check first message for valid instance reference
    if (firstMessage.getInstanceReference() == null || is.getInstance(firstMessage.getInstanceReference()) == null)
        return null;
    Set<InstanceReference> references = new HashSet<InstanceReference>();
    references.add(firstMessage.getInstanceReference());
    while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());
    return new DefaultInstanceSelection(references.toArray());
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) HashSet(java.util.HashSet) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5