Search in sources :

Example 31 with ITreeSelection

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

the class EnableConnectionCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof CommonNavigator) {
        final CommonViewer viewer = ((CommonNavigator) activePart).getCommonViewer();
        final ITreeSelection selection = (ITreeSelection) viewer.getSelection();
        for (TreePath treePath : selection.getPaths()) {
            final IDockerConnection conn = (IDockerConnection) treePath.getLastSegment();
            if (!conn.isOpen()) {
                final Job openConnectionJob = new Job(CommandMessages.getFormattedString(// $NON-NLS-1$
                "command.enableconnection", conn.getUri())) {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        try {
                            conn.open(true);
                            Display.getDefault().asyncExec(() -> viewer.refresh(conn));
                        } catch (DockerException e) {
                            Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
                            "command.enableconnection.failure"), e);
                            return Status.CANCEL_STATUS;
                        }
                        return Status.OK_STATUS;
                    }
                };
                openConnectionJob.schedule();
            }
        }
    }
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) CommonViewer(org.eclipse.ui.navigator.CommonViewer) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 32 with ITreeSelection

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

the class RefreshCommandHandler method getRefreshJobs.

private List<Job> getRefreshJobs(final IWorkbenchPart activePart) {
    final IDockerConnection connection = getCurrentConnection(activePart);
    final ArrayList<Job> jobs = new ArrayList<>();
    if (activePart instanceof DockerImagesView) {
        jobs.add(getRefreshImagesJob(connection));
    } else if (activePart instanceof DockerContainersView) {
        jobs.add(getRefreshContainersJob(connection));
    } else if (activePart instanceof DockerExplorerView) {
        DockerExplorerView dockerExplorerView = (DockerExplorerView) activePart;
        final ITreeSelection selection = dockerExplorerView.getCommonViewer().getStructuredSelection();
        if (selection.getFirstElement() instanceof DockerContainersCategory) {
            jobs.add(getRefreshContainersJob(connection));
        } else if (selection.getFirstElement() instanceof DockerImagesCategory) {
            jobs.add(getRefreshImagesJob(connection));
        } else {
            final IDockerConnection[] connections = DockerConnectionManager.getInstance().getConnections();
            for (IDockerConnection selectedConnection : connections) {
                if (!selectedConnection.isOpen()) {
                    try {
                        selectedConnection.open(true);
                    } catch (DockerException e) {
                    // do nothing
                    }
                }
                if (selectedConnection.isOpen()) {
                    jobs.add(getRefreshContainersJob(selectedConnection));
                    jobs.add(getRefreshImagesJob(selectedConnection));
                }
            }
        }
    }
    return jobs;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerExplorerView(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ArrayList(java.util.ArrayList) DockerImagesView(org.eclipse.linuxtools.internal.docker.ui.views.DockerImagesView) DockerContainersView(org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView) Job(org.eclipse.core.runtime.jobs.Job) DockerContainersCategory(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainersCategory) DockerImagesCategory(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerImagesCategory)

Example 33 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project knime-core by knime.

the class SearchQueryContributionItem method keyPressed.

/**
 * {@inheritDoc}
 */
@Override
public void keyPressed(final KeyEvent e) {
    if (e.keyCode == KEY_UP || e.keyCode == KEY_DOWN) {
        if (m_treeItems == null) {
            m_treeItems = m_viewer.getTree().getItems();
            if (m_treeItems[0].getItemCount() != 0) {
                // tree is an actual tree and we have to retrieve all leaves by traversing the tree
                List<TreeItem> tmp = new ArrayList<TreeItem>();
                getLeavesRecursively(m_treeItems, tmp);
                m_treeItems = tmp.toArray(new TreeItem[tmp.size()]);
            }
        }
        ITreeSelection hu = m_viewer.getStructuredSelection();
        int i = -1;
        if (!hu.isEmpty()) {
            // checks whether there is an element already selected
            Object selected = hu.getFirstElement();
            for (i = 0; i < m_treeItems.length; i++) {
                if (m_treeItems[i].getData() == selected) {
                    break;
                }
            }
        }
        // if there wasn't any element selected already, select the first one,
        // otherwise the one above/below
        int index = (i == -1 ? 0 : (e.keyCode == KEY_UP ? i - 1 : i + 1));
        if (index >= 0 && index < m_treeItems.length) {
            m_viewer.setSelection(new StructuredSelection(m_treeItems[index].getData()), true);
        }
    } else if (e.character == SWT.CR) {
        // enter was pressed, insert the selected node, if there is one selected
        // and select the whole search string (such that the user can just further type text in
        createNode(((IStructuredSelection) m_viewer.getSelection()).getFirstElement());
        Display.getDefault().asyncExec(() -> {
            m_text.setFocus();
        });
        m_text.selectAll();
    } else if (e.character == SWT.ESC) {
        // give focus to the workflow editor
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().setFocus();
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 34 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project cubrid-manager by CUBRID.

the class UnExpandTreeItemAction method run.

/**
	 * Filter
	 */
@SuppressWarnings("rawtypes")
public void run() {
    if (tv != null) {
        ITreeSelection sel = (ITreeSelection) tv.getSelection();
        Iterator it = sel.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            if (!(obj instanceof ICubridNode)) {
                continue;
            }
            tv.collapseToLevel(obj, 1);
        }
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) Iterator(java.util.Iterator) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 35 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project cubrid-manager by CUBRID.

the class ExpandTreeItemAction method run.

@SuppressWarnings("rawtypes")
public void run() {
    if (treeViewer != null) {
        ITreeSelection selectedNodes = (ITreeSelection) treeViewer.getSelection();
        Iterator iter = selectedNodes.iterator();
        while (iter.hasNext()) {
            Object node = iter.next();
            if (!(node instanceof ICubridNode)) {
                continue;
            }
            treeViewer.expandToLevel(node, 1);
        }
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) Iterator(java.util.Iterator) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

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