Search in sources :

Example 66 with TreePath

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

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

the class UnpopulatedPropertiesFilter method select.

/**
 * @see ViewerFilter#select(Viewer, Object, Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (ps != null) {
        if (element instanceof TreePath) {
            element = ((TreePath) element).getLastSegment();
        }
        if (element instanceof EntityDefinition) {
            EntityDefinition entityDef = (EntityDefinition) element;
            if (filterOnlyPopulatedTypes) {
                TypeEntityDefinition type = AlignmentUtil.getTypeEntity(entityDef);
                int typeCount = ps.getPopulation(type).getOverallCount();
                if (typeCount == 0 || typeCount == Population.UNKNOWN) {
                    // all
                    return true;
                }
            }
            if (!entityDef.getPropertyPath().isEmpty() && // only filter properties
            ps.hasPopulation(entityDef.getSchemaSpace())) {
                // only filter if there is a population
                Population pop = ps.getPopulation(entityDef);
                return pop != null && pop.getOverallCount() != 0;
            }
        }
    }
    return true;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath) Population(eu.esdihumboldt.hale.ui.common.service.population.Population)

Example 68 with TreePath

use of org.eclipse.jface.viewers.TreePath in project linuxtools by eclipse.

the class NewProjectCreationPage method getSelectedWorkingSet.

/**
 * Try our best to set the working sets field to something sensible based on the
 * current selection.
 */
private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
    if (!(selection instanceof ITreeSelection)) {
        return EMPTY_WORKING_SET_ARRAY;
    }
    ITreeSelection treeSelection = (ITreeSelection) selection;
    if (treeSelection.isEmpty()) {
        return EMPTY_WORKING_SET_ARRAY;
    }
    List<?> elements = treeSelection.toList();
    if (elements.size() == 1) {
        Object element = elements.get(0);
        TreePath[] paths = treeSelection.getPathsFor(element);
        if (paths.length != 1 || paths[0].getSegmentCount() == 0) {
            return EMPTY_WORKING_SET_ARRAY;
        }
        Object candidate = paths[0].getSegment(0);
        if (!(candidate instanceof IWorkingSet)) {
            return EMPTY_WORKING_SET_ARRAY;
        }
        IWorkingSet workingSetCandidate = (IWorkingSet) candidate;
        if (!workingSetCandidate.isAggregateWorkingSet()) {
            return new IWorkingSet[] { workingSetCandidate };
        }
        return EMPTY_WORKING_SET_ARRAY;
    }
    ArrayList<IWorkingSet> result = new ArrayList<>();
    for (Object element : elements) {
        if (element instanceof IWorkingSet && !((IWorkingSet) element).isAggregateWorkingSet()) {
            result.add((IWorkingSet) element);
        }
    }
    if (!result.isEmpty()) {
        return result.toArray(new IWorkingSet[result.size()]);
    } else {
        return EMPTY_WORKING_SET_ARRAY;
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 69 with TreePath

use of org.eclipse.jface.viewers.TreePath in project linuxtools by eclipse.

the class CModelLabelsTest method checkLabelProvider.

private static void checkLabelProvider(CachegrindFile file) {
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    TreeViewer viewer = view.getViewer();
    TreePath path = new TreePath(new Object[] { view.getOutputs()[0], file });
    checkLabelProvider(viewer, path, file);
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)

Example 70 with TreePath

use of org.eclipse.jface.viewers.TreePath in project linuxtools by eclipse.

the class DoubleClickTest method testDoubleClickFunction.

@Test
public void testDoubleClickFunction() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testDoubleClickFunction");
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    CachegrindOutput output = view.getOutputs()[0];
    // $NON-NLS-1$
    CachegrindFile file = getFileByName(output, "cpptest.cpp");
    // $NON-NLS-1$
    CachegrindFunction func = getFunctionByName(file, "main");
    TreePath path = new TreePath(new Object[] { output, file, func });
    doDoubleClick(path);
    // check file in editor
    IEditorPart editor = checkFile(file);
    // check line number
    ITextEditor textEditor = (ITextEditor) editor;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    TextSelection textSelection = (TextSelection) selection;
    // zero-indexed
    int line = textSelection.getStartLine() + 1;
    int expectedLine = ((IFunction) func.getModel()).getSourceRange().getStartLine();
    assertEquals(expectedLine, line);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TreePath(org.eclipse.jface.viewers.TreePath) CachegrindOutput(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput) CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) IEditorPart(org.eclipse.ui.IEditorPart) Test(org.junit.Test)

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