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;
}
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;
}
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();
}
}
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);
}
}
}
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);
}
}
}
Aggregations