下面列出了org.eclipse.jface.viewers.ArrayContentProvider#org.eclipse.swt.widgets.Table 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Copy information from the meta-data input to the dialog fields.
*/
public void getData() {
Table table = wFields.table;
if ( input.getTransformName().length > 0 ) {
table.removeAll();
}
for ( int i = 0; i < input.getTransformName().length; i++ ) {
TableItem ti = new TableItem( table, SWT.NONE );
ti.setText( 0, "" + ( i + 1 ) );
if ( input.getTransformName()[ i ] != null ) {
ti.setText( 1, input.getTransformName()[ i ] );
}
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth( true );
wTransformName.selectAll();
wTransformName.setFocus();
}
public static Table createTable(final Composite composite, final int height, final int span, final boolean multi) {
final GridData gridData = new GridData();
gridData.horizontalSpan = span;
gridData.heightHint = height;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
int style = SWT.SINGLE;
if (multi) {
style = SWT.MULTI;
}
final Table table = new Table(composite, style | SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(gridData);
table.setHeaderVisible(true);
table.setLinesVisible(true);
return table;
}
private void createTable(Composite parent) {
GridData gridData = new GridData();
gridData.heightHint = 150;
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
this.dictionaryTable = new Table(parent, SWT.FULL_SELECTION
| SWT.BORDER | SWT.MULTI);
this.dictionaryTable.setHeaderVisible(true);
this.dictionaryTable.setLinesVisible(true);
this.dictionaryTable.setLayoutData(gridData);
TableColumn tableColumn = new TableColumn(this.dictionaryTable,
SWT.LEFT);
tableColumn.setWidth(250);
tableColumn.setText(ResourceString
.getResourceString("label.physical.name"));
TableColumn tableColumn1 = new TableColumn(this.dictionaryTable,
SWT.LEFT);
tableColumn1.setWidth(250);
tableColumn1.setText(ResourceString
.getResourceString("label.logical.name"));
}
/**
* 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;
}
public static TableEditor createCheckBoxTableEditor(TableItem tableItem,
boolean selection, int column) {
Table table = tableItem.getParent();
final Button checkBox = new Button(table, SWT.CHECK);
checkBox.pack();
TableEditor editor = new TableEditor(table);
editor.minimumWidth = checkBox.getSize().x;
editor.horizontalAlignment = SWT.CENTER;
editor.setEditor(checkBox, tableItem, column);
checkBox.setSelection(selection);
return editor;
}
public static ResultSetTableAction createResultSetTableAction(
Table resultSetTable, int operationID )
{
assert resultSetTable != null;
ResultSetTableAction rsTableAction = null;
if ( operationID == COPY_ACTION )
{
rsTableAction = new CopyAction( resultSetTable );
}
else if ( operationID == SELECTALL_ACTION )
{
rsTableAction = new SelectAllAction( resultSetTable );
}
return rsTableAction;
}
public BuyOrderTableViewer(Composite parent, UISynchronize sync) {
super(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
| SWT.BORDER);
this.contentProvider = new BuyOrderContentProvider(sync);
this.comparator = new BuyOrderComparator();
setUseHashlookup(false);
setContentProvider(contentProvider);
setComparator(comparator);
createColumns();
/* Pack the columns */
for (TableColumn column : getTable().getColumns())
column.pack();
Table table = getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
}
@Override
public void widgetSelected ( final SelectionEvent e )
{
final Table table = this.tableViewer.getTable ();
final TableColumn newColumn = (TableColumn)e.widget;
final TableColumn currentColumn = table.getSortColumn ();
final EventTableColumn column = (EventTableColumn)newColumn.getData ( COLUMN_KEY );
if ( column == EventTableColumn.reservedColumnSourceTimestamp || column == EventTableColumn.reservedColumnEntryTimestamp )
{
final int currentDir = table.getSortDirection ();
int newDir = SWT.UP;
if ( newColumn == currentColumn )
{
newDir = currentDir == SWT.UP ? SWT.DOWN : SWT.UP;
}
else
{
table.setSortColumn ( newColumn );
}
table.setSortDirection ( newDir );
this.tableViewer.setSorter ( new EventTableSorter ( column, newDir ) );
}
}
private void createForeignKeyColumnMapper(Composite composite) {
final GridData tableGridData = new GridData();
tableGridData.horizontalSpan = 2;
tableGridData.heightHint = 100;
tableGridData.horizontalAlignment = GridData.FILL;
tableGridData.grabExcessHorizontalSpace = true;
foreignKeyColumnMapper = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
foreignKeyColumnMapper.setLayoutData(tableGridData);
foreignKeyColumnMapper.setHeaderVisible(true);
foreignKeyColumnMapper.setLinesVisible(true);
final TableColumn referredColumn = new TableColumn(foreignKeyColumnMapper, SWT.NONE);
referredColumn.setWidth(COLUMN_WIDTH);
referredColumn.setText("Referred Column");
final TableColumn foreignKeyColumn = new TableColumn(foreignKeyColumnMapper, SWT.NONE);
foreignKeyColumn.setWidth(COLUMN_WIDTH);
foreignKeyColumn.setText("ForeignKey Column");
}
private void initializeIndexColumnList(Composite parent) {
final GridData gridData = new GridData();
gridData.heightHint = 150;
gridData.verticalSpan = 2;
indexColumnList = new Table(parent, SWT.FULL_SELECTION | SWT.BORDER);
indexColumnList.setHeaderVisible(true);
indexColumnList.setLayoutData(gridData);
indexColumnList.setLinesVisible(false);
final TableColumn tableColumn = new TableColumn(indexColumnList, SWT.CENTER);
tableColumn.setWidth(150);
tableColumn.setText(DisplayMessages.getMessage("label.column.name"));
if (DBManagerFactory.getDBManager(table.getDiagram()).isSupported(DBManager.SUPPORT_DESC_INDEX)) {
final TableColumn tableColumn1 = new TableColumn(indexColumnList, SWT.CENTER);
tableColumn1.setWidth(50);
tableColumn1.setText(DisplayMessages.getMessage("label.order.desc"));
}
}
/** Expects one row selected in the table and returns value of second row. */
private String getTableItem(Table table) {
String result = "";
if (table == null)
return result;
TableItem[] items = table.getSelection();
if (items.length >= 2) {
String text = Strings.nullToEmpty(table.getToolTipText());
if (!text.isEmpty())
text = " :: " + text;
throw new RuntimeException("Multiple selections are not supported" + text);
}
if (items.length == 1 && items[0] != null)
// first is the display name, second is data
result = Strings.nullToEmpty(items[0].getText(1));
return result;
}
private CellEditor[] getCellEditors( Table table )
{
CellEditor[] editors = new CellEditor[COLUMNS.length];
editors[0] = new TextCellEditor( table ) {
@Override
protected void keyReleaseOccured( KeyEvent keyEvent )
{
super.keyReleaseOccured( keyEvent );
if ( keyEvent.character == '\r' )
{
fTableViewer.editElement( fTableViewer.getElementAt( fTable.getSelectionIndex( ) ),
1 );
}
}
};
editors[1] = new TextCellEditor( table );
return editors;
}
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);
}
}
private TableViewer createViewer(Composite parent) {
TableViewer viewer = new TableViewer(parent, SWT.BORDER | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
createColumns(parent, viewer);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new CmakeDefineTableContentProvider());
viewer.setLabelProvider(new CmakeVariableLabelProvider());
// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
// gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
return viewer;
}
/**
* @param parent a widget which will be the parent of the new instance (cannot
* be null)
* @param style the style of widget to construct
*/
public GitRepositoryPreferencePageView(Composite parent, int style) {
super(parent, style);
final TableColumnLayout tableColumnLayout = new TableColumnLayout();
setLayout(tableColumnLayout);
tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
final Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
columnRepository = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn colRepository = columnRepository.getColumn();
tableColumnLayout.setColumnData(colRepository, new ColumnWeightData(1));
colRepository.setText("Repository");
columnLocalPath = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn colLocalPath = columnLocalPath.getColumn();
tableColumnLayout.setColumnData(colLocalPath, new ColumnWeightData(1));
colLocalPath.setText("Local Path");
columnMemory = new TableViewerColumn(tableViewer, SWT.RIGHT);
TableColumn colMemory = columnMemory.getColumn();
tableColumnLayout.setColumnData(colMemory, new ColumnPixelData(80, true, true));
colMemory.setText("Memory");
final Menu menu = new Menu(tableViewer.getTable());
menuItemGoToRepository = new MenuItem(menu, SWT.NONE);
menuItemGoToRepository.setText("Go to Repository");
tableViewer.getTable().setMenu(menu);
}
/**
* Get the bounds of a cell (SWT.Rectangle) for the specified row and column
* index in a table
*
* @param table
* the table
* @param row
* the row of the table to look up
* @param col
* the column of the table to look up
* @return the bounds in display relative coordinates
*/
public static Rectangle getCellBounds(final Table table, final int row, final int col) {
return UIThreadRunnable.syncExec(new Result<Rectangle>() {
@Override
public Rectangle run() {
TableItem item = table.getItem(row);
Rectangle bounds = item.getBounds(col);
Point p = table.toDisplay(bounds.x, bounds.y);
Rectangle rect = new Rectangle(p.x, p.y, bounds.width, bounds.height);
return rect;
}
});
}
public CellEditor[] getEditors( final Table table )
{
if ( editors == null )
{
editors = new CellEditor[columnKeys.length];
editors[0] = new TextCellEditor( table );
editors[1] = new TextCellEditor( table );
editors[2] = new TextCellEditor( table );
editors[3] = new TextCellEditor( table );
}
return editors;
}
void showTip(String txt, ItemPkg tp, Table table) {
tip = new Shell((Shell) null, SWT.ON_TOP | SWT.TOOL);
tip.setLayout(new FillLayout());
tip.setBackground(table.getBackground());
createBufferTip(tip, (IEditorReference)getSelectables().get(txt));
Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Rectangle rect = tp.getBounds();
Point pt = table.toDisplay(rect.x + getSizeAdjustment(), rect.y
- size.y);
tip.setBounds(pt.x, pt.y, size.x, size.y);
tip.setVisible(true);
}
/**
* Create a new viewer.
*/
public SearchResultViewer(Table table) {
super(table);
createColumns(); // must be done before label provider is set
setLabelProvider(new SearchResultLabel());
setContentProvider(new ArrayContentProvider());
}
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(1, false));
Composite composite = new Composite(container, SWT.NONE);
GridLayout gl_composite = new GridLayout(1, false);
gl_composite.verticalSpacing = 0;
gl_composite.marginWidth = 0;
gl_composite.marginHeight = 0;
composite.setLayout(gl_composite);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
Table table = tableViewer.getTable();
GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
tableGd.heightHint = 220;
table.setLayoutData(tableGd);
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] clmnTitles = new String[] { Messages.getString("dialog.PreTranslationResultDialog.clmnTitles1"),
Messages.getString("dialog.PreTranslationResultDialog.clmnTitles2"),
Messages.getString("dialog.PreTranslationResultDialog.clmnTitles3"),
Messages.getString("dialog.PreTranslationResultDialog.clmnTitles4"),
Messages.getString("dialog.PreTranslationResultDialog.clmnTitles5"),
Messages.getString("dialog.PreTranslationResultDialog.clmnTitles6") };
int[] clmnBounds = { 60, 200, 100, 110, 110, 110 };
for (int i = 0; i < clmnTitles.length; i++) {
createTableViewerColumn(tableViewer, clmnTitles[i], clmnBounds[i], i);
}
tableViewer.setLabelProvider(new TableViewerLabelProvider());
tableViewer.setContentProvider(new ArrayContentProvider());
tableViewer.setInput(this.getTableViewerInput());
return container;
}
/**
* Gets the index.
*
* @param item the item
* @return the index
*/
public static int getIndex(TableItem item) {
Table parent = item.getParent();
TableItem[] items = parent.getItems();
for (int i = items.length - 1; i >= 0; i--) {
if (items[i] == item)
return i;
}
throw new InternalErrorCDE("invalid state"); //$NON-NLS-1$
}
@Override
protected Control createDialogArea(Composite parent) {
Composite tparent = (Composite) super.createDialogArea(parent);
GridLayoutFactory.swtDefaults().spacing(0, 0).numColumns(1).applyTo(tparent);
GridDataFactory.fillDefaults().hint(750, 500).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tparent);
createMenu();
createToolBar(tparent);
table = new Table(tparent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite cmpStatus = new Composite(tparent, SWT.BORDER);
cmpStatus.setLayout(new GridLayout(2, true));
cmpStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
lblRowCount = new Label(cmpStatus, SWT.None);
lblRowCount.setText(MessageFormat.format(Messages.getString("dialog.CSV2TMXConverterDialog.lblRowCount"), 0));
lblRowCount.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
lblColCount = new Label(cmpStatus, SWT.None);
lblColCount.setText(MessageFormat.format(Messages.getString("dialog.CSV2TMXConverterDialog.lblColCount"), 0));
lblColCount.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
tparent.layout();
getShell().layout();
return tparent;
}
public void updateVariant(ProjectVariant variant) {
int idx = getIndex(variant);
if (idx == -1)
return;
Column column = columns[idx];
Table table = viewer.getTable();
String title = column.getTitle() == null ? "" : column.getTitle();
table.getColumn(idx + LABEL_COLS).setText(title);
viewer.refresh();
}
private void configSorters(Table table) {
int index = 0;
for (TableColumn column : table.getColumns()) {
final int colIndex = index++;
column.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
updateSortColumn((TableColumn) event.widget, colIndex);
}
});
}
}
public CellEditor[] getEditors( Table table )
{
if ( editors == null )
{
editors = new TextCellEditor[columnKeys.length];
editors[0] = new TextCellEditor( table );
editors[1] = new TextCellEditor( table );
}
return null;
}
private void get() {
wFields.removeAll();
Table table = wFields.table;
for ( int i = 0; i < previousTransforms.length; i++ ) {
TableItem ti = new TableItem( table, SWT.NONE );
ti.setText( 0, "" + ( i + 1 ) );
ti.setText( 1, previousTransforms[ i ] );
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth( true );
}
private void tableColumnClicked(TableColumn column){
Table table = column.getParent();
if (column.equals(table.getSortColumn())) {
table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP);
} else {
table.setSortColumn(column);
table.setSortDirection(SWT.UP);
}
tableViewer.refresh();
}
private String getCellText(Event event, Table table) {
String result = null;
ItemPkg item = getCell(event,table);
if (item != null){
result = item.getText();
}
return result;
}
/**
* load a list of rows with a single column
* @return
*/
private static List<TableItem> loadSingleDataset(Table table) {
List<TableItem> rowList = new ArrayList<TableItem>();
int total = (modelList == null ? 0 : modelList.size());
for (int index=0; index < total; index++) {
TableItem ti = new TableItem(table, SWT.NONE);
Model model = (Model)modelList.get(index);
ti.setText(model.getDescription());
rowList.add(ti);
}
return rowList;
}
private void setSortColumn(
TableColumn column, int colIndex, int direction) {
ViewerComparator sorter = buildColumnSorter(colIndex);
if (SWT.UP == direction) {
sorter = new InverseSorter(sorter);
}
Table tableControl = (Table) propViewer.getControl();
propViewer.setComparator(sorter);
tableControl.setSortColumn(column);
tableControl.setSortDirection(direction);
}