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

The following examples show how to use org.eclipse.swt.widgets.Tree#getItemCount() . 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: 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 2
Source File: ColumnChooserDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isLastLeafSelected(Tree tree) {
	TreeItem[] selectedLeaves = tree.getSelection();
	for (int i = 0; i < selectedLeaves.length; i++) {
		if (tree.indexOf(selectedLeaves[i])+1 == tree.getItemCount()) {
			return true;
		}
	}
	return false;
}
 
Example 3
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 4
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 5
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 6
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 7
Source File: ColumnChooserDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isLastLeafSelected(Tree tree) {
	TreeItem[] selectedLeaves = tree.getSelection();
	for (int i = 0; i < selectedLeaves.length; i++) {
		if (tree.indexOf(selectedLeaves[i])+1 == tree.getItemCount()) {
			return true;
		}
	}
	return false;
}
 
Example 8
Source File: PyUnitView2TestTestWorkbench.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private ICallback<Boolean, Object> getPyUnitViewOkCallback(final int historySize, final int methodsAppearingInTree) {
    return new ICallback<Boolean, Object>() {

        @Override
        public Boolean call(Object arg) {
            PyUnitView view = PyUnitView.getView();
            PyUnitTestRun currentTestRun = view.getCurrentTestRun();
            if (currentTestRun == null) {
                if (arg == THROW_ERROR) {
                    throw new AssertionError("currentTestRun == null");
                }
                return false;
            }
            if (!currentTestRun.getFinished()) {
                if (arg == THROW_ERROR) {
                    throw new AssertionError("!currentTestRun.getFinished()");
                }
                return false;
            }
            Tree tree = view.getTree();
            if (tree.getItemCount() != methodsAppearingInTree) {
                if (arg == THROW_ERROR) {
                    throw new AssertionError("tree.getItemCount() " + tree.getItemCount() +
                            "!= methodsRun "
                            + methodsAppearingInTree);
                }
                return false;
            }
            CounterPanel counterPanel = view.getCounterPanel();
            if (!counterPanel.fNumberOfErrors.getText().equals("1")) {
                if (arg == THROW_ERROR) {
                    throw new AssertionError("!counterPanel.fNumberOfErrors.getText().equals(\"1\")");
                }
                return false;
            }
            if (!counterPanel.fNumberOfFailures.getText().equals("1")) {
                if (arg == THROW_ERROR) {
                    throw new AssertionError("!counterPanel.fNumberOfFailures.getText().equals(\"1\")");
                }
                return false;
            }
            HistoryAction historyAction = (HistoryAction) getPyUnitViewAction(view, HistoryAction.class);
            HistoryAction.HistoryMenuCreator menuCreator = (HistoryMenuCreator) historyAction.getMenuCreator();
            final List<SetCurrentRunAction> actions = new ArrayList<SetCurrentRunAction>();
            final List<ClearTerminatedAction> terminatedActions = new ArrayList<ClearTerminatedAction>();
            IActionsMenu actionsMenu = new IActionsMenu() {

                @Override
                public void add(IAction action) {
                    if (action instanceof SetCurrentRunAction) {
                        actions.add((SetCurrentRunAction) action);
                    } else if (action instanceof ClearTerminatedAction) {
                        terminatedActions.add((ClearTerminatedAction) action);
                    }
                }
            };
            menuCreator.fillMenuManager(actionsMenu);
            if (historySize + 1 != actions.size()) { //+1 to count for the current!
                if (arg == THROW_ERROR) {
                    throw new AssertionError("historySize + 1 != actions.size()");
                }
                return false;
            }

            return true;
        }
    };
}