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

The following examples show how to use org.eclipse.swt.widgets.Table#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: ModulaContentAssistant.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void selectProposal(ICompletionProposal proposal) {
	try{
		Object fProposalPopup = ReflectionUtils.getField(this.getClass(), "fProposalPopup", this, true);
		Object fProposalTable = ReflectionUtils.getField(fProposalPopup.getClass(), "fProposalTable", fProposalPopup, true);
		if (fProposalTable instanceof Table) {
			Table table = (Table) fProposalTable;
			int i = 0; 
			for (;i < table.getItemCount(); i++) {
				TableItem item = table.getItem(i);
				if (Objects.equals(item.getData(), proposal)) {
					break;
				}
			}
			if (i < table.getItemCount()) {
				Method selectMethod = ReflectionUtils.findMethod(fProposalPopup.getClass(), "selectProposal", int.class, boolean.class);
				ReflectionUtils.invokeMethod(selectMethod, fProposalPopup, i, false);
			}
		}
	}
	catch(AssertionError e) {
	}
}
 
Example 2
Source File: OrderableFieldDialogImpl.java    From jenerate with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Move the current selection in the field list down.
 */
private void moveSelectionDown() {
    Table builderTable = fieldViewer.getTable();
    int indices[] = builderTable.getSelectionIndices();
    if (indices.length < 1) {
        return;
    }
    int newSelection[] = new int[indices.length];
    int max = builderTable.getItemCount() - 1;
    for (int i = indices.length - 1; i >= 0; i--) {
        int index = indices[i];
        if (index < max) {
            move(builderTable.getItem(index), index + 1);
            newSelection[i] = index + 1;
        }
    }
    builderTable.setSelection(newSelection);
}
 
Example 3
Source File: ExportToTsvUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Export content of a table to TSV file
 * @param table
 *              the table to export
 * @param stream
 *              the output stream
 */
public static void exportTableToTsv(Table table, @Nullable OutputStream stream) {
    if (table == null || stream == null) {
        return;
    }
    try (PrintWriter pw = new PrintWriter(stream)) {
        int size = table.getItemCount();
        List<String> columns = new ArrayList<>();
        for (int i = 0; i < table.getColumnCount(); i++) {
            TableColumn column = table.getColumn(i);
            if (column == null) {
                return;
            }
            String columnName = String.valueOf(column.getText());
            if (columnName.isEmpty() && i == table.getColumnCount() - 1) {
                // Linux GTK2 undocumented feature
                break;
            }
            columns.add(columnName);
        }
        pw.println(Joiner.on('\t').join(columns));
        for (int i = 0; i < size; i++) {
            TableItem item = table.getItem(i);
            if (item == null) {
                continue;
            }
            List<String> data = new ArrayList<>();
            for (int col = 0; col < columns.size(); col++) {
                data.add(String.valueOf(item.getText(col)));
            }
            pw.println(Joiner.on('\t').join(data));
        }
    }
}
 
Example 4
Source File: OrderableFieldDialogImpl.java    From jenerate with Eclipse Public License 1.0 5 votes vote down vote up
private void handleTableSelectionChanged() {
    Table fieldTable = fieldViewer.getTable();
    TableItem[] items = fieldTable.getSelection();
    boolean validSelection = items != null && items.length > 0;
    boolean enableUp = validSelection;
    boolean enableDown = validSelection;
    if (validSelection) {
        int indices[] = fieldTable.getSelectionIndices();
        int max = fieldTable.getItemCount();
        enableUp = indices[0] != 0;
        enableDown = indices[indices.length - 1] < max - 1;
    }
    upButton.setEnabled(enableUp);
    downButton.setEnabled(enableDown);
}
 
Example 5
Source File: JavaSearchTableContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getAddLimit() {
	int limit= getPage().getElementLimit().intValue();
	if (limit != -1) {
		Table table= (Table) getPage().getViewer().getControl();
		int itemCount= table.getItemCount();
		if (itemCount >= limit) {
			return 0;
		}
		return limit - itemCount;
	}
	return Integer.MAX_VALUE;
}
 
Example 6
Source File: FeatureEnvy.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));
			Table table = tableViewer.getTable();
			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<table.getItemCount(); i++) {
				TableItem tableItem = table.getItem(i);
				for(int j=0; j<table.getColumnCount(); j++) {
					if(j == table.getColumnCount()-1)
						out.write(tableItem.getText(j));
					else
						out.write(tableItem.getText(j) + "\t");
				}
				out.newLine();
			}
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
Example 7
Source File: FeatureEnvy.java    From JDeodorant with MIT License 5 votes vote down vote up
public void setSelectedLine(final CandidateRefactoring candidateRefactoring) {
	Table table = tableViewer.getTable();
	for(int i=0; i<table.getItemCount(); i++) {
		Object tableElement = tableViewer.getElementAt(i);
		CandidateRefactoring candidate = (CandidateRefactoring)tableElement;
		if(candidate.equals(candidateRefactoring)) {
			table.setSelection(i);
			break;
		}
	}
}
 
Example 8
Source File: ViewAttributeList.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Update
 * @param attribute
 */
private void updateSelectedAttribute(String attribute) {
    if (model != null && model.getInputConfig() != null && model.getInputConfig().getInput() != null) {
        Table table = this.table.getViewer().getTable();
        for (int i=0; i < table.getItemCount(); i++) {
            TableItem item = table.getItem(i);
            if (item.getData().equals(attribute)) {
                table.select(i);
                break;
            }
        }
    }
}
 
Example 9
Source File: UiUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void setEnabled(Table table, boolean isEnabled){
  for (int i = 0; i < table.getItemCount(); i++) {
    table.getItem(i).setGrayed(!isEnabled);
  }
}
 
Example 10
Source File: UiUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void setDataColumnBackground(Table table, int columnIdx, Color color){
  for (int i = 0; i < table.getItemCount(); i++) {
    table.getItem(i).setBackground(columnIdx, color);
  }
}
 
Example 11
Source File: SwtUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void setEnabled(Table table, boolean isEnabled) {
	for (int i = 0; i < table.getItemCount(); i++) {
		table.getItem(i).setGrayed(!isEnabled);
	}
}
 
Example 12
Source File: SwtUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void setDataColumnBackground(Table table, int columnIdx,
		Color color) {
	for (int i = 0; i < table.getItemCount(); i++) {
		table.getItem(i).setBackground(columnIdx, color);
	}
}
 
Example 13
Source File: ProjectBuildPathPropertyPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handle table selection. In case it's a single selection, enable/disable the 'Up' and 'Down' buttons according to
 * the selection. We only allow up and down for checked items.
 */
private void handleTableSelection()
{
	ISelection selection = tableViewer.getSelection();
	if (selection instanceof StructuredSelection)
	{
		StructuredSelection structuredSelection = (StructuredSelection) selection;
		Table table = tableViewer.getTable();
		if (structuredSelection.size() == 1 && table.getItemCount() > 1)
		{
			int selectionIndex = table.getSelectionIndex();
			TableItem item = table.getItem(selectionIndex);
			IBuildPathEntry data = (IBuildPathEntry) item.getData();
			if (item.getChecked())
			{
				upButton.setEnabled(selectionIndex != 0);
				downButton.setEnabled(selectionIndex < table.getItemCount() - 1
						&& selectionIndex < tableViewer.getCheckedElements().length - 1);
				if (!selectedEntries.contains(data))
				{
					selectedEntries.add(data);
					tableViewer.refresh();
				}
			}
			else
			{
				if (selectedEntries.contains(data))
				{
					selectedEntries.remove(data);
					tableViewer.refresh();
				}
				upButton.setEnabled(false);
				downButton.setEnabled(false);
			}
		}
		else
		{
			upButton.setEnabled(false);
			downButton.setEnabled(false);
		}
	}
}