Java Code Examples for org.eclipse.swt.widgets.Tree#getItem()

The following examples show how to use org.eclipse.swt.widgets.Tree#getItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestResultsView.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean shouldCreateToolTip(final Event e) {
	this.lastDescriptor = null;
	if (e.widget instanceof Tree && actionShowTestHover != null && actionShowTestHover.isChecked()) {

		final Tree tree = (Tree) e.widget;
		final TreeItem item = tree.getItem(new Point(e.x, e.y));

		if (null != item && item.getData() instanceof ResultNode) {
			final ResultNode node = (ResultNode) item.getData();
			if (node.getElement() instanceof TestCase) {
				final URI uri = ((TestCase) node.getElement()).getURI();
				if (null != uri) {
					final StyledTextDescriptor descriptor = getDescriptor(uri);
					if (null != descriptor) {
						this.lastDescriptor = descriptor;
					}
				}
			}
		}
	}

	return null != this.lastDescriptor;
}
 
Example 2
Source File: ExportToTsvUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Export content of a tree to TSV file
 * @param tree
 *              the tree to export
 * @param stream
 *              the output stream
 */
public static void exportTreeToTsv(@Nullable Tree tree, @Nullable OutputStream stream) {
    if (tree == null || stream == null) {
        return;
    }
    try (PrintWriter pw = new PrintWriter(stream)) {
        int size = tree.getItemCount();
        List<String> columns = new ArrayList<>();
        for (int i = 0; i < tree.getColumnCount(); i++) {
            String valueOf = String.valueOf(tree.getColumn(i).getText());
            if (valueOf.isEmpty() && i == tree.getColumnCount() - 1) {
                // Linux "feature", an invisible column is added at the end
                // with gtk2
                break;
            }
            columns.add(valueOf);
        }
        String join = Joiner.on('\t').skipNulls().join(columns);
        pw.println(join);
        for (int i = 0; i < size; i++) {
            TreeItem item = tree.getItem(i);
            printItem(pw, columns, item);
        }
    }
}
 
Example 3
Source File: AbstractInformationControl.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Handles mouse up action for the tree viewer
 * 
 * @param tree
 *            current tree
 * @param e
 *            mouse event
 */
private void handleTreeViewerMouseUp(final Tree tree, MouseEvent e) {
	// Ensure a selection was made, the first mouse button was
	// used and the event happened in the tree
	if ((tree.getSelectionCount() < 1) || (e.button != 1) || !tree.equals(e.getSource())) {
		return;
	}
	// Selection is made in the selection changed listener
	Object object = tree.getItem(new Point(e.x, e.y));
	TreeItem selection = tree.getSelection()[0];
	if (selection.equals(object)) {
		gotoSelectedElement();
	}
}
 
Example 4
Source File: TmfTreeViewerToolTipHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fill(Control control, MouseEvent event, Point pt) {
    Tree tree = (Tree) control;
    TreeItem item = tree.getItem(pt);
    if (item == null) {
        return;
    }
    Object data = item.getData();
    if (data instanceof TmfTreeViewerEntry) {
        fillValues((TmfTreeViewerEntry) data);
    }
}
 
Example 5
Source File: LongMethod.java    From JDeodorant with MIT License 5 votes vote down vote up
private void saveResults() {
	FileDialog fd = new FileDialog(getSite().getWorkbenchWindow().getShell(), SWT.SAVE);
	fd.setText("Save Results");
       String[] filterExt = { "*.txt" };
       fd.setFilterExtensions(filterExt);
       String selected = fd.open();
       if(selected != null) {
       	try {
       		BufferedWriter out = new BufferedWriter(new FileWriter(selected));
       		Tree tree = treeViewer.getTree();
       		/*TreeColumn[] columns = tree.getColumns();
       		for(int i=0; i<columns.length; i++) {
       			if(i == columns.length-1)
       				out.write(columns[i].getText());
       			else
       				out.write(columns[i].getText() + "\t");
       		}
       		out.newLine();*/
       		for(int i=0; i<tree.getItemCount(); i++) {
				TreeItem treeItem = tree.getItem(i);
				ASTSliceGroup group = (ASTSliceGroup)treeItem.getData();
				for(ASTSlice candidate : group.getCandidates()) {
					out.write(candidate.toString());
					out.newLine();
				}
			}
       		out.close();
       	} catch (IOException e) {
       		e.printStackTrace();
       	}
       }
}
 
Example 6
Source File: GodClass.java    From JDeodorant with MIT License 5 votes vote down vote up
private void saveResults() {
	FileDialog fd = new FileDialog(getSite().getWorkbenchWindow().getShell(), SWT.SAVE);
	fd.setText("Save Results");
	String[] filterExt = { "*.txt" };
	fd.setFilterExtensions(filterExt);
	String selected = fd.open();
	if(selected != null) {
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(selected));
			Tree tree = treeViewer.getTree();
			/*TreeColumn[] columns = tree.getColumns();
			for(int i=0; i<columns.length; i++) {
				if(i == columns.length-1)
					out.write(columns[i].getText());
				else
					out.write(columns[i].getText() + "\t");
			}
			out.newLine();*/
			for(int i=0; i<tree.getItemCount(); i++) {
				TreeItem treeItem = tree.getItem(i);
				ExtractClassCandidateGroup group = (ExtractClassCandidateGroup)treeItem.getData();
				for(CandidateRefactoring candidate : group.getCandidates()) {
					out.write(candidate.toString());
					out.newLine();
				}
			}
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
Example 7
Source File: GodClass.java    From JDeodorant with MIT License 5 votes vote down vote up
public void setSelectedLine(CandidateRefactoring candidateRefactoring) {
	Tree tree = treeViewer.getTree();
	for(int i=0; i< tree.getItemCount(); i++){
		TreeItem treeItem = tree.getItem(i);
		ExtractClassCandidateGroup group = (ExtractClassCandidateGroup)treeItem.getData();
		if(group.getCandidates().contains(candidateRefactoring)) {
			treeItem.setExpanded(true);
			treeViewer.refresh();
			setSelectedLineWithinCandidateGroup(tree, treeItem, candidateRefactoring);
			break;
		}
	}
}
 
Example 8
Source File: TypeChecking.java    From JDeodorant with MIT License 5 votes vote down vote up
private void saveResults() {
	FileDialog fd = new FileDialog(getSite().getWorkbenchWindow().getShell(), SWT.SAVE);
	fd.setText("Save Results");
       String[] filterExt = { "*.txt" };
       fd.setFilterExtensions(filterExt);
       String selected = fd.open();
       if(selected != null) {
       	try {
       		BufferedWriter out = new BufferedWriter(new FileWriter(selected));
       		Tree tree = treeViewer.getTree();
       		/*TableColumn[] columns = table.getColumns();
       		for(int i=0; i<columns.length; i++) {
       			if(i == columns.length-1)
       				out.write(columns[i].getText());
       			else
       				out.write(columns[i].getText() + "\t");
       		}
       		out.newLine();*/
       		for(int i=0; i<tree.getItemCount(); i++) {
       			TreeItem treeItem = tree.getItem(i);
       			TypeCheckEliminationGroup group = (TypeCheckEliminationGroup)treeItem.getData();
       			for(TypeCheckElimination candidate : group.getCandidates()) {
       				out.write(candidate.toString());
       				out.newLine();
       			}
       		}
       		out.close();
       	} catch (IOException e) {
       		e.printStackTrace();
       	}
       }
}
 
Example 9
Source File: Trees.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Get the tree item where the given event occurred. Returns null if the
 * event occurred in the empty tree area.
 */
public static TreeItem getItem(TreeViewer viewer, MouseEvent event) {
	if (viewer == null || event == null)
		return null;
	Tree tree = viewer.getTree();
	if (tree == null)
		return null;
	return tree.getItem(new Point(event.x, event.y));
}