Java Code Examples for org.eclipse.swt.widgets.TableColumn

The following examples show how to use org.eclipse.swt.widgets.TableColumn. These examples are extracted from open source projects. 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
private void addUserNameColumn(final StructuredViewer viewer) {
    final TableViewerColumn column = new TableViewerColumn((TableViewer) viewer, SWT.FILL);
    final TableColumn usernameColumn = column.getColumn();
    column.getColumn().setText(Messages.userName);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            return ((User) element).getUserName();
        }
    });

    column.getColumn().setWidth(90);
    column.getColumn().setMoveable(false);
    column.getColumn().setResizable(true);

    final TableColumnSorter sorter = new TableColumnSorter((TableViewer) viewer);
    sorter.setColumn(usernameColumn);
}
 
Example 2
/**
 * 设置列属性 ;
 */
private void setColumnType() {
	if (cols < 2) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TBXMakerDialog.msgTitle"),
				Messages.getString("dialog.TBXMakerDialog.msg2"));
		return;
	}
	Vector<ColProperties> colTypes = new Vector<ColProperties>(cols);
	for (int i = 0; i < cols; i++) {
		colTypes.add((ColProperties) table.getColumn(i).getData());
	}

	ColumnTypeDialog selector = new ColumnTypeDialog(getShell(), colTypes, template, imagePath);
	if (selector.open() == IDialogConstants.OK_ID) {
		for (int i = 0; i < cols; i++) {
			TableColumn col = table.getColumn(i);
			ColProperties type = colTypes.get(i);
			if (!type.getColName().equals("") && !type.getLanguage().equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
				col.setText(type.getColName());
			}
		}
	}
}
 
Example 3
Source Project: tracecompass   Source File: TmfEventsTable.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Pack the columns.
 *
 * @return true if this is the first call to pack columns
 *
 * @since 2.0
 */
protected boolean packColumns() {
    boolean packDone = fPackDone;
    fTable.setRedraw(false);
    try {
        int horizontalPos = fTable.getHorizontalBar().getSelection();
        TableColumn tableColumns[] = fTable.getColumns();
        for (int i = 0; i < tableColumns.length; i++) {
            final TableColumn column = tableColumns[i];
            if (Objects.equals(column.getData(Key.WIDTH), SWT.DEFAULT)) {
                packSingleColumn(i, column);
            }
        }
        if (!IS_WIN32) {
            /* Bug 410369: Cannot programmatically scroll on Windows */
            fTable.getHorizontalBar().setSelection(horizontalPos);
        }
    } finally {
        // Make sure that redraw is always enabled.
        fTable.setRedraw(true);
    }
    fPackDone = true;
    return !packDone;
}
 
Example 4
public static TableViewerColumn createDosageColumn(TableViewer viewer,
	TableColumnLayout layout, int columnIndex){
	TableViewerColumn ret = new TableViewerColumn(viewer, SWT.NONE);
	ret.setLabelProvider(new MedicationCellLabelProvider() {
		
		@Override
		public String getText(Object element){
			MedicationTableViewerItem pres = (MedicationTableViewerItem) element;
			String dosis = pres.getDosis();
			return (dosis.equals(StringConstants.ZERO) ? Messages.MedicationComposite_stopped
					: dosis);
		}
	});
	TableColumn tblclmnDosage = ret.getColumn();
	tblclmnDosage.setToolTipText(Messages.TherapieplanComposite_tblclmnDosage_toolTipText);
	tblclmnDosage.addSelectionListener(getSelectionAdapter(viewer, tblclmnDosage, columnIndex));
	layout.setColumnData(tblclmnDosage, new ColumnPixelData(60, true, true));
	ret.getColumn().setText(Messages.TherapieplanComposite_tblclmnDosage_text);
	return ret;
}
 
Example 5
private void createComparisonTable(Composite composite) {
	GridData tableGridData = new GridData();
	tableGridData.horizontalSpan = 2;
	tableGridData.heightHint = 100;
	tableGridData.horizontalAlignment = GridData.FILL;
	tableGridData.grabExcessHorizontalSpace = true;

	this.comparisonTable = new Table(composite, SWT.SINGLE | SWT.BORDER
			| SWT.FULL_SELECTION);
	this.comparisonTable.setLayoutData(tableGridData);
	this.comparisonTable.setHeaderVisible(true);
	this.comparisonTable.setLinesVisible(true);

	TableColumn referencedColumn = new TableColumn(this.comparisonTable,
			SWT.NONE);
	referencedColumn.setWidth(COLUMN_WIDTH);
	referencedColumn.setText(ResourceString
			.getResourceString("label.reference.column"));

	TableColumn foreignKeyColumn = new TableColumn(this.comparisonTable,
			SWT.NONE);
	foreignKeyColumn.setWidth(COLUMN_WIDTH);
	foreignKeyColumn.setText(ResourceString
			.getResourceString("label.foreign.key"));
}
 
Example 6
public static TableViewerColumn createStopColumn(TableViewer viewer, TableColumnLayout layout,
	int columnIndex){
	TableViewerColumn ret = new TableViewerColumn(viewer, SWT.CENTER);
	TableColumn tblclmnStop = ret.getColumn();
	ColumnPixelData stopColumnPixelData = new ColumnPixelData(60, true, true);
	layout.setColumnData(tblclmnStop, stopColumnPixelData);
	tblclmnStop.setImage(Images.resize(Images.IMG_ARROWSTOP_WO_SHADOW.getImage(),
		ImageSize._12x12_TableColumnIconSize));
	tblclmnStop.setToolTipText(Messages.MedicationComposite_column_sortBy + " "
		+ Messages.MedicationComposite_column_endDate);
	tblclmnStop.addSelectionListener(getSelectionAdapter(viewer, tblclmnStop, columnIndex));
	ret.setLabelProvider(new MedicationCellLabelProvider() {
		@Override
		public String getText(Object element){
			MedicationTableViewerItem pres = (MedicationTableViewerItem) element;
			if (pres.getEntryType() != EntryType.RECIPE
				&& pres.getEntryType() != EntryType.SELF_DISPENSED) {
				return pres.getEndDate();
			}
			return "";
		}
	});
	return ret;
}
 
Example 7
Source Project: tracecompass   Source File: TmfEventsTable.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns true if the column is expanded to take extra available space.
 * This is the last non-zero-width visible column in the column order on
 * Linux. This column's width should not be persisted.
 *
 * @param column
 *            the column
 * @return true if the column is expanded.
 */
private static boolean isExpanded(TableColumn column) {
    if (IS_LINUX) {
        Table table = column.getParent();
        int[] order = table.getColumnOrder();
        for (int i = order.length - 1; i >= 0; i--) {
            TableColumn col = table.getColumn(order[i]);
            if (col == column) {
                return true;
            }
            if (col.getWidth() > 0) {
                return false;
            }
        }
    }
    return false;
}
 
Example 8
/**
 * Saves the sorting state to the dialog settings.
 */
private void saveState() {

  IDialogSettings settings = mSettingsProvider != null ? mSettingsProvider.getTableSettings()
          : null;

  if (settings == null) {
    return;
  }

  settings.put(TAG_COLUMN_INDEX, mSortedColumnIndex);
  settings.put(TAG_SORT_DIRECTION, mSortDirection);

  // store the column widths
  TableColumn[] columns = this.getTable().getColumns();
  for (int i = 0, size = columns.length; i < size; i++) {
    int width = columns[i].getWidth();
    if (width > 0) {
      settings.put(TAG_COLUMN_WIDTH + i, width);
    }
  }

  // store the selection
  settings.put(TAG_CURRENT_SELECTION, this.getTable().getSelectionIndex());
}
 
Example 9
/**
 * Defines what columns the drop down table will have.
 * @param columnHeaders
 * @param columnBounds
 */
private void defineColumnsInternal(String[] columnHeaders, int[] columnBounds, int totalColumnsToBeCreated) {

	checkWidget();

	int totalColumnHeaders = columnHeaders == null ? 0 : columnHeaders.length;
	int totalColBounds = columnBounds == null ? 0 : columnBounds.length;

	if (totalColumnsToBeCreated > 0) {

		for (int index = 0; index < totalColumnsToBeCreated; index++) {
			TableColumn column = new TableColumn(table, SWT.NONE);

			if (index < totalColumnHeaders) {
				column.setText(columnHeaders[index]);
			}

			if (index < totalColBounds) {
				column.setWidth(columnBounds[index]);
			}

			column.setResizable(true);
			column.setMoveable(true);
		}
	}
}
 
Example 10
Source Project: depan   Source File: NodeKindTableControl.java    License: Apache License 2.0 6 votes vote down vote up
private void setSortColumn(
    TableColumn column, int colIndex, int direction) {

  ITableLabelProvider labelProvider =
      (ITableLabelProvider) kindViewer.getLabelProvider();
  ViewerComparator sorter = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, colIndex));
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Table tableControl = (Table) kindViewer.getControl();
  kindViewer.setComparator(sorter);
  tableControl.setSortColumn(column);
  tableControl.setSortDirection(direction);
}
 
Example 11
Source Project: tuxguitar   Source File: SWTTable.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void adjustColumnWidth(TableColumn column) {
	int minimumWidth = 0;
	
	String headerText = column.getText();
	if( headerText != null && headerText.length() > 0 ) {
		GC gc = new GC(this.getControl());
		minimumWidth = (gc.stringExtent(headerText).x + (TABLE_COLUMN_MARGIN * 2));
		gc.dispose();
	}
	
	column.pack();
	if( column.getWidth() < minimumWidth ) {
		column.setWidth(minimumWidth);
	}
	
}
 
Example 12
Source Project: ermasterr   Source File: IndexTabWrapper.java    License: Apache License 2.0 6 votes vote down vote up
private void initTable(final Composite parent) {
    final GridData gridData = new GridData();
    gridData.horizontalSpan = 3;
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.heightHint = 200;

    indexTable = new Table(parent, SWT.BORDER | SWT.HIDE_SELECTION);

    indexTable.setHeaderVisible(true);
    indexTable.setLayoutData(gridData);
    indexTable.setLinesVisible(true);

    CompositeFactory.createTableColumn(indexTable, "label.column.name", -1);
    final TableColumn separatorColumn = CompositeFactory.createTableColumn(indexTable, "", 3);
    separatorColumn.setResizable(false);
}
 
Example 13
private void addPackListener() {
    getControl().addListener(SWT.SetData, new Listener() {
        @Override
        public void handleEvent(@Nullable Event event) {
            // Remove the listener before the pack
            getControl().removeListener(SWT.SetData, this);

            // Pack the column the first time data is set
            TableViewer tableViewer = getTableViewer();
            if (tableViewer != null) {
                for (TableColumn col : tableViewer.getTable().getColumns()) {
                    col.pack();
                }
            }
        }
    });
}
 
Example 14
Source Project: arx   Source File: ComponentFilterTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Clears the table.
 */
public void clear() {
    this.selectedKey = null;
    this.keys = null;
    this.selectedProperty = null;
    this.keyProperties = null;
    this.properties = null;
    this.permitted = null;
    this.pageableTable.setRedraw(false);
    for (TableColumn c : this.pageableTable.getViewer().getTable().getColumns()) {
    	c.dispose();
    }
    this.pageableTable.setRedraw(true);
}
 
Example 15
Source Project: pentaho-kettle   Source File: DataGridDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void cellFocusLost( int rowIndex ) {
  List<Integer> nonEmptyIndexesBeforeChanges = wFields.getNonEmptyIndexes();
  wFields.nrNonEmpty();
  List<Integer> nonEmptyIndexesAfterChanges = wFields.getNonEmptyIndexes();
  if ( CollectionUtils.isEqualCollection( nonEmptyIndexesBeforeChanges, nonEmptyIndexesAfterChanges ) ) {
    //count of fields rows didn't change
    return;
  }
  Collection<Integer>
    disjunction = CollectionUtils.disjunction( nonEmptyIndexesBeforeChanges, nonEmptyIndexesAfterChanges );
  Integer disjunctionIdx = (Integer) disjunction.toArray()[0];
  if ( nonEmptyIndexesAfterChanges.contains( disjunctionIdx ) ) {
    // new Field was added
    Integer idxByValue = getIdxByValue( nonEmptyIndexesAfterChanges, disjunctionIdx );
    if ( idxByValue == null ) {
      return; //can not happen (preventing warnings)
    }

    idxByValue++; //data table have one technical column
    TableColumn column = new TableColumn( wData.table, SWT.NONE, idxByValue );
    column.pack();
  } else {
    // Field was deleted
    Integer removeColumn = getIdxByValue( nonEmptyIndexesBeforeChanges, disjunctionIdx );
    if ( removeColumn == null ) {
      return; //can not happen (preventing warnings)
    }
    removeColumn++;  //data table have one technical column
    wData.table.getColumn( removeColumn ).dispose();
    wFields.nrNonEmpty();
  }
}
 
Example 16
private void createColumns() {
    TableLayout layout = new TableLayout();
    getTable().setLayout(layout);
    getTable().setHeaderVisible(true);
    for (int i = 0; i < columnHeaders.length; i++) {
        layout.addColumnData(columnLayouts[i]);
        TableColumn tc = new TableColumn(getTable(), SWT.NONE,i);
        tc.setResizable(columnLayouts[i].resizable);
        tc.setText(columnHeaders[i]);
    }
}
 
Example 17
Source Project: nebula   Source File: AbstractNativeHeader.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void initializeColumns() {
    this.tableColumns = new ArrayList();
    for (int i = 0; i < columnLabelStrings.length; i++) {
        TableColumn column = new TableColumn(headerTable, columnAlignments[i]);
        column.setMoveable(movable);
        column.setResizable(resizable);
        column.setText(columnLabelStrings[i]);
        this.tableColumns.add(column);
        column.addControlListener(columnControlListener);
        column.addSelectionListener(columnSelectionListener);
    }
}
 
Example 18
Source Project: gama   Source File: PopulationInspectView.java    License: GNU General Public License v3.0 5 votes vote down vote up
private TableViewerColumn createTableViewerColumn(final String title, final int bound, final int colNumber) {
	final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
	final TableColumn column = viewerColumn.getColumn();
	column.setText(title);
	column.setWidth(bound);
	column.setResizable(true);
	column.setMoveable(true);
	column.addSelectionListener(getSelectionAdapter(column, title));
	viewerColumn.setLabelProvider(getColumnLabelProvider(title));
	return viewerColumn;
}
 
Example 19
Source Project: cppcheclipse   Source File: TableEditor.java    License: Apache License 2.0 5 votes vote down vote up
public void addColumn(ExtendedTableColumn column) {
	TableColumn tc = new TableColumn(tableViewer.getTable(),
			column.getStyle());
	tc.setText(column.getLabel());
	tc.setWidth(column.getWidth());
	tc.setMoveable(true);
	
	new TableColumnSorter(tableViewer, tc, columnIndex++);
}
 
Example 20
Source Project: logbook   Source File: ResourceChartDialogEx.java    License: MIT License 5 votes vote down vote up
/**
 * テーブルヘッダーをセットする
 */
private void setTableHeader() {
    for (int i = 0; i < this.header.length; i++) {
        TableColumn col = new TableColumn(this.table, SWT.LEFT);
        col.setText(this.header[i]);
    }
    this.packTableHeader();
}
 
Example 21
Source Project: elexis-3-core   Source File: DiagnosenDisplay.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private TableViewerColumn createTableViewerColumn(String title, int weight, int colNumber,
	int style){
	final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, style);
	final TableColumn column = viewerColumn.getColumn();
	column.setText(title);
	column.setResizable(true);
	column.setMoveable(false);
	tableLayout.setColumnData(column, new ColumnWeightData(weight));
	return viewerColumn;
}
 
Example 22
Source Project: JDeodorant   Source File: FeatureEnvy.java    License: 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 23
Source Project: nebula   Source File: PaginationExampleTab.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private static TableViewerColumn createTableViewerColumn(
		TableViewer viewer, String title, int bound) {
	final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
			SWT.NONE);
	final TableColumn column = viewerColumn.getColumn();
	column.setText(title);
	column.setWidth(bound);
	column.setResizable(true);
	column.setMoveable(true);
	return viewerColumn;
}
 
Example 24
Source Project: olca-app   Source File: CausalFactorTable.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private void addColumn(Exchange product) {
	Column newColumn = new Column(product);
	Table table = viewer.getTable();
	TableColumn tableColumn = new TableColumn(table, SWT.VIRTUAL);
	tableColumn.setText(newColumn.getTitle());
	tableColumn.setToolTipText(newColumn.getTitle());
	tableColumn.setWidth(80);
	Column[] newColumns = new Column[columns.length + 1];
	System.arraycopy(columns, 0, newColumns, 0, columns.length);
	newColumns[columns.length] = newColumn;
	columns = newColumns;
	if (editor.hasAnyComment("allocationFactors")) {
		new TableColumn(table, SWT.VIRTUAL).setWidth(24);
	}
}
 
Example 25
Source Project: elexis-3-core   Source File: InvoiceListView.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e){
	TableColumn sortColumn = tableViewerInvoiceList.getTable().getSortColumn();
	TableColumn selectedColumn = (TableColumn) e.widget;
	int sortDirection = tableViewerInvoiceList.getTable().getSortDirection();
	if (sortColumn == selectedColumn) {
		sortDirection = sortDirection == SWT.UP ? SWT.DOWN : SWT.UP;
	} else {
		tableViewerInvoiceList.getTable().setSortColumn(selectedColumn);
		sortDirection = SWT.UP;
	}
	
	setSortOrder(selectedColumn, sortDirection);
}
 
Example 26
/**
 * Constructs a new instance of this object.
 * 
 * @param w the widget.
 * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 * @since 2.0
 */
public SWTBotTableComboColumn(final TableColumn w) throws WidgetNotFoundException {
	this(w, UIThreadRunnable.syncExec(new WidgetResult<Table>() {
		public Table run() {
			return w.getParent();
		}
	}));
}
 
Example 27
Source Project: tuxguitar   Source File: SWTTable.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setColumnName(int column, String name) {
	if( column >= 0 && column < this.getColumns() ) {
		this.getControl().setHeaderVisible(true);
		
		TableColumn tableColumn = this.getControl().getColumn(column);
		tableColumn.setText(name);
		
		if( this.isVisible() ) {
			this.updateManager.setUpdateRequired();
		}
	}
}
 
Example 28
private static TableViewerColumn createTableViewerColumn(
		TableViewer viewer, String title, int bound) {
	final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
			SWT.NONE);
	final TableColumn column = viewerColumn.getColumn();
	column.setText(title);
	column.setWidth(bound);
	column.setResizable(true);
	column.setMoveable(true);
	return viewerColumn;
}
 
Example 29
private Control createTable(Composite parent) {
	Composite c= new Composite(parent, SWT.NONE);
	GridLayout gl= new GridLayout();
	gl.numColumns= 2;
	gl.marginWidth= 0;
	gl.marginHeight= 0;
	c.setLayout(gl);


	fTable= new Table(c, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.BORDER);
	fTable.setFont(parent.getFont());

	GridData tableGD= new GridData(GridData.FILL_BOTH);
	tableGD.heightHint= SWTUtil.getTableHeightHint(fTable, ROW_COUNT);
	//tableGD.widthHint= 40;
	fTable.setLayoutData(tableGD);

	fTable.setLinesVisible(true);

	TableLayout layout= new TableLayout();
	fTable.setLayout(layout);
	fTable.setHeaderVisible(true);

	ColumnLayoutData[] columnLayoutData= new ColumnLayoutData[SIZE];
	columnLayoutData[STATE_PROP]= new ColumnPixelData(18, false, true);
	columnLayoutData[KEY_PROP]= new ColumnWeightData(40, true);
	columnLayoutData[VAL_PROP]= new ColumnWeightData(40, true);

	for (int i= 0; i < fgTitles.length; i++) {
		TableColumn tc= new TableColumn(fTable, SWT.NONE, i);
		tc.setText(fgTitles[i]);
		layout.addColumnData(columnLayoutData[i]);
		tc.setResizable(columnLayoutData[i].resizable);
	}

	createButtonComposite(c);
	return c;
}
 
Example 30
@Override
protected Table getParent(SelectionEvent e) {
	// 1) Get table column which fire this selection event
	TableColumn tableColumn = (TableColumn) e.getSource();
	// 2) Get the owner table
	return tableColumn.getParent();
}