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

The following examples show how to use org.eclipse.swt.widgets.Table#getColumnCount() . 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: CausalFactorTable.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
public void render(Section section, FormToolkit toolkit) {
	Composite composite = UI.sectionClient(section, toolkit, 1);
	String[] columnTitles = getColumnTitles();
	viewer = Tables.createViewer(composite, columnTitles);
	viewer.setLabelProvider(new FactorLabel());
	Action copy = TableClipboard.onCopy(viewer);
	Actions.bind(viewer, copy);
	Tables.bindColumnWidths(viewer, 0.2, 0.1, 0.1, 0.1);
	createModifySupport();
	Table table = viewer.getTable();
	for (int i = 0; i < table.getColumnCount(); i++) {
		if (i < 4)
			continue;
		TableColumn column = table.getColumn(i);
		if (!editor.hasAnyComment("allocationFactors") || i % 2 == 0) {
			column.setWidth(80);
			column.setToolTipText(columnTitles[i]);
		} else {
			column.setWidth(24);
		}
	}
	for (int i = 3; i < table.getColumnCount(); i++) {
		viewer.getTable().getColumns()[i].setAlignment(SWT.RIGHT);
	}
}
 
Example 2
Source File: UiUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public static int getClickedItemColumnIndex(Table table, TableItem item, 
    Point point){
  int column = -1;
  if (item != null) {
    // Determine which column was selected
    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
      Rectangle rect = item.getBounds(i);
      if (rect.contains(point)) {
        // This is the selected column
        column = i;
        break;
      }
    }
  }
  return column;
}
 
Example 3
Source File: CloneDiffTooltip.java    From JDeodorant with MIT License 6 votes vote down vote up
protected void packAndFillLastColumn(Table table) {
    int columnsWidth = 0;
    for (int i = 0; i < table.getColumnCount() - 1; i++) {
        columnsWidth += table.getColumn(i).getWidth();
    }
    TableColumn lastColumn = table.getColumn(table.getColumnCount() - 1);
    lastColumn.pack();

    Rectangle area = table.getClientArea();

    Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int width = area.width - 2*table.getBorderWidth();

    if (preferredSize.y > area.height + table.getHeaderHeight()) {
        // Subtract the scrollbar width from the total column width
        // if a vertical scrollbar will be required
        Point vBarSize = table.getVerticalBar().getSize();
        width -= vBarSize.x;
    }

    // last column is packed, so that is the minimum. If more space is available, add it.
    if(lastColumn.getWidth() < width - columnsWidth) {
        lastColumn.setWidth(width - columnsWidth + 4);
    }
}
 
Example 4
Source File: SwtUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public static int getClickedItemColumnIndex(Table table, TableItem item,
		Point point) {
	int column = -1;
	if (item != null) {
		// Determine which column was selected
		for (int i = 0, n = table.getColumnCount(); i < n; i++) {
			Rectangle rect = item.getBounds(i);
			if (rect.contains(point)) {
				// This is the selected column
				column = i;
				break;
			}
		}
	}
	return column;
}
 
Example 5
Source File: AbstractSegmentStoreTableViewer.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Sets the segment provider, use only in test, only run in display thread
 *
 * @param segmentProvider
 *            the segment provider
 * @since 1.2
 */
@VisibleForTesting
public void setSegmentProvider(ISegmentStoreProvider segmentProvider) {
    fSegmentProvider = segmentProvider;
    // Sort order of the content provider is by start time by default
    getTableViewer().setContentProvider(new SegmentStoreContentProvider());

    Table table = getTableViewer().getTable();
    table.setRedraw(false);
    while (table.getColumnCount() > 0) {
        table.getColumn(0).dispose();
    }
    createColumns();
    createProviderColumns();
    getTableViewer().getTable().addSelectionListener(new TableSelectionListener());
    addPackListener();
    table.setRedraw(true);
}
 
Example 6
Source File: TableClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void copyHeaders(Table table, StringBuilder text) {
	int cols = table.getColumnCount();
	for (int col = 0; col < cols; col++) {
		TableColumn column = table.getColumn(col);
		String s = column.getText();
		text.append(s == null ? "" : s);
		if (col != (cols - 1))
			text.append('\t');
	}
	text.append('\n');
}
 
Example 7
Source File: SelectionDialog.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private ItemPkg getCell(MouseEvent event, Table table) {
	ItemPkg result = null;
	TableItem item = table.getItem(new Point(event.x,event.y));

	if (item != null) {
		for (int i = 0; i < table.getColumnCount(); i++) {
			if (item.getBounds(i).contains(event.x, event.y)) {
				result = new ItemPkg(item,i);
				break;
			}
		}
	}
	return result;
}
 
Example 8
Source File: SelectionDialog.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private ItemPkg getCell(Event event, Table table) {
	ItemPkg result = null;
	TableItem item = table.getItem(new Point(event.x,event.y));

	if (item != null) {
		for (int i = 0; i < table.getColumnCount(); i++) {
			if (item.getBounds(i).contains(event.x, event.y)) {
				result = new ItemPkg(item,i);
				break;
			}
		}
	}
	return result;
}
 
Example 9
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 10
Source File: TableClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void copyItems(Table table, Converter converter,
		StringBuilder buffer) {
	int cols = table.getColumnCount();
	for (TableItem item : table.getSelection()) {
		for (int col = 0; col < cols; col++) {
			String s = converter.asString(item, col);
			buffer.append(s);
			if (col != (cols - 1)) {
				buffer.append('\t');
			}
		}
		buffer.append('\n');
	}
}
 
Example 11
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 12
Source File: SwtUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void resizeColumnsByCaption(Table table) {
	GC gc = new GC(table);
	try {
		for (int i = 0; i < table.getColumnCount(); i++) {
			int maxTextExtent = getColumnTextWidth(table, gc, i);
			table.getColumn(i).setWidth(maxTextExtent);
		}
	} finally {
		gc.dispose();
	}
}
 
Example 13
Source File: UiUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void resizeColumnsByCaption(Table table){
   GC gc = new GC(table);
   try {
   	for (int i = 0; i < table.getColumnCount(); i++) {
   		int maxTextExtent = getColumnTextWidth(table, gc, i);
   		table.getColumn(i).setWidth(maxTextExtent);
   	}
} finally {
	gc.dispose();
}
 }
 
Example 14
Source File: HeaderLayout.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void storeLastWidths(Table table) {
    if (lastWidths == null) {
        lastWidths = new int[table.getColumnCount()];
    }
    TableColumn[] columns = table.getColumns();
    for (int col = 0; col < columns.length; col++) {
        lastWidths[col] = columns[col].getWidth();
    }
}
 
Example 15
Source File: SwtUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void resizeColumsByContent(Table table) {
	for (int i = 0; i < table.getColumnCount(); i++) {
		table.getColumn(i).pack();
	}
}
 
Example 16
Source File: TableSetter.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void saveColumnWeights(Table table, String qualifier) {
    for (int i = 0; i < table.getColumnCount(); i++) {
        settings.put(qualifier + ".columnWeight" + i, getColumnWeight(table, i)); //$NON-NLS-1$
    }        
}
 
Example 17
Source File: UiUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void resizeColumsByContent(Table table){
  for (int i = 0; i < table.getColumnCount(); i++) {
    table.getColumn(i).pack();
  }
}
 
Example 18
Source File: HeaderLayout.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private boolean resizedColumnIsNotTheLastColumn(int resizedColumnNumber, Table table) {
    return resizedColumnNumber < table.getColumnCount()-1;
}
 
Example 19
Source File: LaborblattView.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public boolean createLaborblatt(final Patient pat, final String[] header, final TableItem[] rows){
	Brief br =
		text.createFromTemplateName(text.getAktuelleKons(), TT_LABPAPER,
			Brief.LABOR,
			pat, null);
	if (br == null) {
		return false;
	}
	Table table = rows[0].getParent();
	int cols = table.getColumnCount();
	int[] colsizes = new int[cols];
	float first = 25;
	float second = 10;
	if (cols > 2) {
		int rest = Math.round((100f - first - second) / (cols - 2f));
		for (int i = 2; i < cols; i++) {
			colsizes[i] = rest;
		}
	}
	colsizes[0] = Math.round(first);
	colsizes[1] = Math.round(second);
	
	LinkedList<String[]> usedRows = new LinkedList<String[]>();
	usedRows.add(header);
	for (int i = 0; i < rows.length; i++) {
		boolean used = false;
		String[] row = new String[cols];
		for (int j = 0; j < cols; j++) {
			row[j] = rows[i].getText(j);
			if ((j > 1) && (row[j].length() > 0)) {
				used = true;
				// break;
			}
		}
		if (used == true) {
			usedRows.add(row);
		}
	}
	String[][] fld = usedRows.toArray(new String[0][]);
	boolean ret = text.getPlugin().insertTable("[Laborwerte]", //$NON-NLS-1$
		ITextPlugin.FIRST_ROW_IS_HEADER, fld, colsizes);
	text.saveBrief(br, Brief.LABOR);
	return ret;
}
 
Example 20
Source File: NewCodewindProjectPage.java    From codewind-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public static void sortTable(Table table, TableColumn column) {
	TableItem[] items = table.getItems();
	int rows = items.length;
	int dir = table.getSortDirection() == SWT.DOWN ? 1 : -1;
	TableColumn currentColumn = table.getSortColumn();
	int columnNum = 0;
	for (int j = 0; j < table.getColumnCount(); j++) {
		if (table.getColumn(j).equals(column)) {
			columnNum = j;
			break;
		}
	}
	if (column.equals(currentColumn))
		dir = -dir;
	else
		dir = 1;

	// sort an index map, then move the actual rows
	int[] map = new int[rows];
	for (int i = 0; i < rows; i++)
		map[i] = i;

	for (int i = 0; i < rows - 1; i++) {
		for (int j = i + 1; j < rows; j++) {
			TableItem a = items[map[i]];
			TableItem b = items[map[j]];
			if ((a.getText(columnNum).toLowerCase().compareTo(b.getText(columnNum).toLowerCase()) * dir > 0)) {
				int t = map[i];
				map[i] = map[j];
				map[j] = t;
			}
		}
	}

	// can't move existing items or delete first, so append new items to the end and then delete existing rows
	for (int i = 0; i < rows; i++) {
		int n = map[i];
		TableItem item = new TableItem(table, SWT.NONE);
		for (int j = 0; j < table.getColumnCount(); j++) {
			item.setText(j, items[n].getText(j));
		}
		item.setData(items[n].getData());
		items[n].dispose();
	}

	table.setSortDirection(dir == 1 ? SWT.DOWN : SWT.UP);
	table.setSortColumn(column);
}