use of org.eclipse.jface.viewers.TreeSelection in project knime-core by knime.
the class WorkflowGroupSelectionDialog method pathToTreeSelection.
/**
* @param path the path of a resource
* @return the selection to be passed to a tree in order to select the
* resource denoted by the given path
*/
public static IStructuredSelection pathToTreeSelection(final IPath path) {
if (path != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource r = root.findMember(path);
if (r != null && !r.equals(root)) {
IContainer c = r.getParent();
if (r instanceof IContainer) {
c = (IContainer) r;
}
String[] segments = c.getFullPath().segments();
Object[] treePathSegments = new Object[segments.length];
// find all parents in order to create the path segments
int i = 1;
while (c.getParent() != null) {
treePathSegments[treePathSegments.length - i] = c;
c = c.getParent();
i++;
}
TreePath treePath = new TreePath(treePathSegments);
return new TreeSelection(treePath);
}
}
// default: return empty selection
return new TreeSelection();
}
use of org.eclipse.jface.viewers.TreeSelection in project translationstudio8 by heartsome.
the class ColumnCategoriesDialog method getColumnIndexesFromTreeNodes.
/**
* @return selected columns index(s) from the tree viewer
*/
private List<Integer> getColumnIndexesFromTreeNodes() {
Object[] nodes = ((TreeSelection) treeViewer.getSelection()).toArray();
List<Integer> indexes = new ArrayList<Integer>();
for (Object object : nodes) {
Node node = (Node) object;
if (Type.COLUMN == node.getType()) {
indexes.add(Integer.parseInt(node.getData()));
}
}
return indexes;
}
use of org.eclipse.jface.viewers.TreeSelection in project cubrid-manager by CUBRID.
the class QueryEditorDNDController method fillInSelectedNode.
/**
*
* Fill in the selected node
*
* @param schemaNodeList all table nodes
* @param columnNodeMap all columns node
* @return boolean
*/
private boolean fillInSelectedNode(List<ISchemaNode> schemaNodeList, Map<String, List<ISchemaNode>> columnNodeMap) {
TreeViewer treeViewer = perspectiveTreeviewerMap.get(PerspectiveManager.getInstance().getCurrentPerspectiveId());
if (treeViewer == null) {
return false;
}
ISelection selection = treeViewer.getSelection();
if (!(selection instanceof TreeSelection)) {
return false;
}
TreeSelection ts = (TreeSelection) selection;
Object[] objs = ts.toArray();
String dbId = null;
for (Object obj : objs) {
if (obj instanceof ISchemaNode) {
ISchemaNode node = (ISchemaNode) obj;
CubridDatabase database = node.getDatabase();
if (dbId == null) {
dbId = database.getId();
}
if (!dbId.equals(database.getId())) {
return false;
}
String type = node.getType();
if (NodeType.SYSTEM_TABLE.equals(type) || NodeType.SYSTEM_VIEW.equals(type) || NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE.equals(type) || NodeType.USER_VIEW.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
schemaNodeList.add(node);
} else if (NodeType.TABLE_COLUMN.equals(type)) {
String name = node.getParent().getParent().getName();
List<ISchemaNode> columnNodeList = columnNodeMap.get(name);
if (columnNodeList == null) {
columnNodeList = new ArrayList<ISchemaNode>();
columnNodeMap.put(name, columnNodeList);
}
columnNodeList.add(node);
}
}
}
return true;
}
use of org.eclipse.jface.viewers.TreeSelection in project cubrid-manager by CUBRID.
the class UnifyHostConfigDialogDNDController method addHost.
/**
* add database
*/
public void addHost() {
synchronized (this) {
ISelection selection = navigatorTreeViewer.getSelection();
if (!(selection instanceof TreeSelection)) {
return;
}
TreeSelection ts = (TreeSelection) selection;
Object[] objs = ts.toArray();
dialog.addHost(objs);
}
}
use of org.eclipse.jface.viewers.TreeSelection in project cubrid-manager by CUBRID.
the class RunSQLFileDialogDNDController method addDatabase.
/**
* add database
*/
public void addDatabase() {
synchronized (this) {
TreeViewer treeViewer = perspectiveTreeviewerMap.get(PerspectiveManager.getInstance().getCurrentPerspectiveId());
if (treeViewer == null) {
return;
}
ISelection selection = treeViewer.getSelection();
if (!(selection instanceof TreeSelection)) {
return;
}
TreeSelection ts = (TreeSelection) selection;
Object[] objs = ts.toArray();
dialog.addDatabase(objs);
}
}
Aggregations