Search in sources :

Example 51 with TreePath

use of org.eclipse.jface.viewers.TreePath in project polymap4-core by Polymap4.

the class NavigatorSaveablesService method getActiveSaveablesFromTreePathProvider.

/**
 * @param selection
 * @param provider
 * @return the active saveables
 */
private Saveable[] getActiveSaveablesFromTreePathProvider(IStructuredSelection selection, ITreePathContentProvider provider) {
    Set result = new HashSet();
    for (Iterator it = selection.iterator(); it.hasNext(); ) {
        Object element = it.next();
        Saveable saveable = getSaveable(element);
        if (saveable != null) {
            result.add(saveable);
        } else {
            TreePath[] paths = provider.getParents(element);
            saveable = findSaveable(paths);
            if (saveable != null) {
                result.add(saveable);
            }
        }
    }
    return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
Also used : Saveable(org.eclipse.ui.Saveable) HashSet(java.util.HashSet) Set(java.util.Set) TreePath(org.eclipse.jface.viewers.TreePath) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 52 with TreePath

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

the class ObjectBrowser method restoreSelection.

/**
 * Restore selection in the tree
 */
private void restoreSelection() {
    if (// $NON-NLS-1$
    (initialObjectSelection == null) || initialObjectSelection.isEmpty() || !initialObjectSelection.startsWith("/"))
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    // $NON-NLS-1$
    final String[] parts = initialObjectSelection.split("/");
    final Object[] elements = new Object[parts.length - 1];
    for (int i = 1; i < parts.length; i++) {
        long id;
        try {
            id = Long.parseLong(parts[i]);
        } catch (NumberFormatException e) {
            return;
        }
        elements[i - 1] = session.findObjectById(id);
        if (elements[i - 1] == null)
            // path element is missing
            return;
    }
    objectTree.getTreeViewer().setSelection(new TreeSelection(new TreePath(elements)), true);
    final Display display = getSite().getShell().getDisplay();
    display.asyncExec(new Runnable() {

        @Override
        public void run() {
            // wait for events to finish before continue
            while (display.readAndDispatch()) ;
            // $NON-NLS-1$
            CommandBridge.getInstance().execute("TabbedObjectView/changeObject", ((AbstractObject) elements[elements.length - 1]).getObjectId());
        }
    });
}
Also used : NXCSession(org.netxms.client.NXCSession) TreePath(org.eclipse.jface.viewers.TreePath) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractObject(org.netxms.client.objects.AbstractObject) Display(org.eclipse.swt.widgets.Display)

Example 53 with TreePath

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

the class ObjectBrowser method saveSelection.

/**
 * Save tree viewer selection
 *
 * @param memento
 */
private void saveSelection(IMemento memento) {
    ITreeSelection selection = (ITreeSelection) objectTree.getTreeViewer().getSelection();
    if (selection.size() == 1) {
        TreePath path = selection.getPaths()[0];
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < path.getSegmentCount(); i++) {
            sb.append('/');
            sb.append(((AbstractObject) path.getSegment(i)).getObjectId());
        }
        // $NON-NLS-1$
        memento.putString("ObjectBrowser.selectedObject", sb.toString());
    } else {
        // $NON-NLS-1$ //$NON-NLS-2$
        memento.putString("ObjectBrowser.selectedObject", "");
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath)

Example 54 with TreePath

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

the class RepositoriesViewRefresher method refreshRepositories.

public void refreshRepositories(final RepositoryPlugin target) {
    synchronized (this) {
        if (busy) {
            redo = true;
            return;
        }
        busy = true;
        redo = false;
    }
    // 
    // Since this can delay, we move this to the background
    // 
    new WorkspaceJob("Updating repositories content") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                if (monitor == null)
                    monitor = new NullProgressMonitor();
                Set<RepositoryPlugin> repos = new HashSet<>();
                if (target != null)
                    repos.add(target);
                else {
                    for (RefreshModel m : viewers.values()) {
                        repos.addAll(m.getRepositories());
                    }
                }
                ensureLoaded(monitor, repos);
                // get repositories first, then do UI thread work
                final Map<Entry<TreeViewer, RefreshModel>, List<RepositoryPlugin>> entryRepos = new HashMap<>();
                for (Map.Entry<TreeViewer, RefreshModel> entry : viewers.entrySet()) {
                    entryRepos.put(entry, entry.getValue().getRepositories());
                }
                // 
                // And now back to the UI thread
                // 
                getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        synchronized (RepositoriesViewRefresher.this) {
                            redo = false;
                        }
                        for (Map.Entry<TreeViewer, RefreshModel> entry : viewers.entrySet()) {
                            TreePath[] expandedTreePaths = entry.getKey().getExpandedTreePaths();
                            entry.getKey().setInput(entryRepos.get(entry));
                            if (expandedTreePaths != null && expandedTreePaths.length > 0)
                                entry.getKey().setExpandedTreePaths(expandedTreePaths);
                        }
                        synchronized (RepositoriesViewRefresher.this) {
                            busy = false;
                            if (redo) {
                                refreshRepositories(null);
                            }
                        }
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
            return Status.OK_STATUS;
        }
    }.schedule(1000);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) HashSet(java.util.HashSet) Set(java.util.Set) TreeViewer(org.eclipse.jface.viewers.TreeViewer) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) TimeoutException(java.util.concurrent.TimeoutException) CoreException(org.eclipse.core.runtime.CoreException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Entry(java.util.Map.Entry) CoreException(org.eclipse.core.runtime.CoreException) TreePath(org.eclipse.jface.viewers.TreePath) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 55 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tdi-studio-se by Talend.

the class MoveUpTreeNodeButton method updateStatus.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.fileoutputJSON.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
     */
@Override
protected void updateStatus(TreeSelection selection) {
    if (selection.isEmpty()) {
        getButton().setEnabled(false);
        return;
    }
    final TreePath[] paths = selection.getPaths();
    boolean sameSegment = true;
    for (int i = 0; i < paths.length - 1; i++) {
        if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
            sameSegment = false;
        }
    }
    if (sameSegment) {
        getButton().setEnabled(true);
    } else {
        getButton().setEnabled(false);
        return;
    }
    // if same segment ,they have the same parent and parent must be an element
    FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
    if (foxNode.getParent() instanceof Element) {
        final Element parent = (Element) foxNode.getParent();
        if (parent == null) {
            getButton().setEnabled(false);
            return;
        }
        final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
        final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
        final List<FOXTreeNode> elementChildren = parent.getElementChildren();
        final Iterator iterator = selection.iterator();
        while (iterator.hasNext()) {
            final Object next = iterator.next();
            if (next instanceof Attribute) {
                if (attrChildren.contains(next) && attrChildren.indexOf(next) == 0) {
                    getButton().setEnabled(false);
                    return;
                }
            } else if (next instanceof NameSpaceNode) {
                if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == 0) {
                    getButton().setEnabled(false);
                    return;
                }
            } else if (next instanceof Element) {
                if (elementChildren.contains(next) && elementChildren.indexOf(next) == 0) {
                    getButton().setEnabled(false);
                    return;
                }
            }
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreePath(org.eclipse.jface.viewers.TreePath) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) Iterator(java.util.Iterator)

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