Search in sources :

Example 41 with ITreeSelection

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

the class PropertyEntityDialog method getObjectFromSelection.

/**
 * @see EntityDialog#getObjectFromSelection(ISelection)
 */
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof EntityDefinition) {
            return (EntityDefinition) element;
        }
    }
    if (!selection.isEmpty() && selection instanceof ITreeSelection) {
        // create property definition w/ default contexts
        TreePath path = ((ITreeSelection) selection).getPaths()[0];
        // get parent type
        TypeDefinition type = ((PropertyDefinition) path.getFirstSegment()).getParentType();
        // determine definition path
        List<ChildContext> defPath = new ArrayList<ChildContext>();
        for (int i = 0; i < path.getSegmentCount(); i++) {
            defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
        }
        // TODO check if property entity definition is applicable?
        return new PropertyEntityDefinition(type, defPath, ssid, parentType.getFilter());
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 42 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection 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 = Collections.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)

Example 43 with ITreeSelection

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

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

use of org.eclipse.jface.viewers.ITreeSelection in project meclipse by flaper87.

the class FilterWizard method addFilter.

public void addFilter(ISelection selection, Filter filter) {
    if (selection == null)
        throw new IllegalStateException(getCaption("filterWizard.error.nullSelection"));
    if (!(selection instanceof ITreeSelection))
        throw new IllegalStateException(selection.getClass().getSimpleName() + getCaption("filterWizard.error.noITreeSelection"));
    ITreeSelection treeSelection = (ITreeSelection) selection;
    Object obj = treeSelection.getFirstElement();
    if (!(obj instanceof Collection) && !(obj instanceof Filter))
        throw new IllegalStateException(obj.getClass().getSimpleName() + getCaption("filterWizard.error.noCollection"));
    TreeParent parent = (TreeParent) obj;
    filter.setParent(parent);
    MeclipsePlugin.getDefault().addFilter(new FilterPlacement(parent), filter);
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) Filter(org.mongodb.meclipse.views.objects.Filter) TreeParent(org.mongodb.meclipse.views.objects.TreeParent) FilterPlacement(org.mongodb.meclipse.views.FilterPlacement) Collection(org.mongodb.meclipse.views.objects.Collection)

Aggregations

ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)56 TreePath (org.eclipse.jface.viewers.TreePath)17 ISelection (org.eclipse.jface.viewers.ISelection)16 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 ArrayList (java.util.ArrayList)7 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)7 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)7 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)5 IProject (org.eclipse.core.resources.IProject)4 IStatus (org.eclipse.core.runtime.IStatus)4 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 Test (org.junit.Test)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)3 URL (java.net.URL)3 HashSet (java.util.HashSet)3