Java Code Examples for org.eclipse.jface.viewers.TableViewer#getTable()

The following examples show how to use org.eclipse.jface.viewers.TableViewer#getTable() . 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: UnDefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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 CmakeUnDefineTableContentProvider());
    viewer.setLabelProvider(new CmakeVariableLabelProvider());

//    // make the selection available to other views
//    getSite().setSelectionProvider(tableViewer);

    // 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;
  }
 
Example 2
Source File: DefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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;
  }
 
Example 3
Source File: FilterTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
public FilterTableControl(Composite parent) {
  super(parent, SWT.NONE);
  setLayout(Widgets.buildContainerLayout(1));

  filterViewer = 
      new TableViewer(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI );

  // Set up layout properties.
  Table filterTable = filterViewer.getTable();
  filterTable.setLayoutData(Widgets.buildGrabFillData());

  // Initialize the table.
  filterTable.setHeaderVisible(true);
  filterTable.setToolTipText("Node Filter Editor");
  EditColTableDef.setupTable(TABLE_DEF, filterTable);

  CellEditor[] cellEditors = new CellEditor[TABLE_DEF.length];
  cellEditors[INDEX_NAME] = new TextCellEditor(filterTable);
  cellEditors[INDEX_SUMMARY] = new NodeFilterCellEditor(filterTable);

  // Configure table properties.
  filterViewer.setCellEditors(cellEditors);
  filterViewer.setLabelProvider(LABEL_PROVIDER);
  filterViewer.setColumnProperties(EditColTableDef.getProperties(TABLE_DEF));
  filterViewer.setCellModifier(new ControlCellModifier());

  // Since the order is significant, no sorting capabilities.

  // Avoid setInput() invocations that come with
  // TableContentProvider.initViewer
  filterViewer.setContentProvider(ArrayContentProvider.getInstance());
}
 
Example 4
Source File: FilterConfigurationDialog.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
private SeverityEditingSupport(TableViewer viewer) {
    super(viewer);
    this.viewer = viewer;
    displayValues = ArrayUtils.toArray("Any", "Style", "Low", "Medium", "High", "Critical");
    severityValues = ArrayUtils.toArray(Severity.ANY, Severity.STYLE, Severity.LOW,
            Severity.MEDIUM, Severity.HIGH, Severity.CRITICAL);
    this.editor = new ComboBoxCellEditor(viewer.getTable(), displayValues, SWT.DROP_DOWN
            | SWT.READ_ONLY);
}
 
Example 5
Source File: Tables.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/** Add an event handler for double clicks on the given table viewer. */
public static void onDoubleClick(TableViewer viewer, Consumer<MouseEvent> handler) {
	if (viewer == null || viewer.getTable() == null || handler == null)
		return;
	viewer.getTable().addMouseListener(new MouseAdapter() {
		@Override
		public void mouseDoubleClick(MouseEvent e) {
			handler.accept(e);
		}
	});
}
 
Example 6
Source File: RemapTable.java    From depan with Apache License 2.0 5 votes vote down vote up
private Control setupControl(Composite parent) {
  Composite topLevel = new Composite(parent, SWT.NONE);
  GridLayout layout = new GridLayout();
  topLevel.setLayout(layout);

  tableViewer =
    new TableViewer(topLevel, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);

  Table tableData = tableViewer.getTable();
  tableData.setHeaderVisible(true);
  EditColTableDef.setupTable(TABLE_DEF, tableData);

  CellEditor[] cellEditors = new CellEditor[4];
  cellEditors[0] = null;
  cellEditors[1] = null;
  cellEditors[2] = new TextCellEditor(tableData);
  cellEditors[3] = new TextCellEditor(tableData);

  tableViewer.setCellEditors(cellEditors);
  tableViewer.setColumnProperties(EditColTableDef.getProperties(TABLE_DEF));

  RemapTableHelper cellHelper = new RemapTableHelper();
  tableViewer.setLabelProvider(cellHelper);

  tableData.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

  remapContent = new TableContentProvider<MigrationRule<?>>();
  remapContent.initViewer(tableViewer);

  return topLevel;
}
 
Example 7
Source File: NodeKindTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Create the ElementKindPicker, with all the usual sub-controls.
 *
 * @param parent containing controls
 * @param style standard style bits
 */
public NodeKindTableControl(Composite parent) {
  super(parent, SWT.NONE);
  setLayout(Widgets.buildContainerLayout(1));

  // Setup selection button bar
  Composite buttonBar = configButtonBar(this);
  buttonBar.setLayoutData(
      new GridData(SWT.LEFT, SWT.CENTER, false, false));

  // Configure the table viewer
  kindViewer = new TableViewer(
      this, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);

  // Set up layout properties.
  Table elementKindTable = kindViewer.getTable();
  elementKindTable.setLayoutData(Widgets.buildGrabFillData());

  // Initialize the table.
  elementKindTable.setHeaderVisible(true);
  elementKindTable.setToolTipText("Node Kind Selector");
  EditColTableDef.setupTable(TABLE_DEF, elementKindTable);

  // Configure the table viewer
  kindViewer.setLabelProvider(LABEL_PROVIDER);
  kindViewer.setColumnProperties(EditColTableDef.getProperties(TABLE_DEF));

  configSorters(elementKindTable);
  setSortColumn(elementKindTable.getColumn(0), 0, SWT.DOWN);

  kindViewer.setContentProvider(new ArrayContentProvider());
}
 
Example 8
Source File: JavaSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Object[] getRootElements(TableViewer viewer) {
	Table t= viewer.getTable();
	Item[] roots= t.getItems();
	Object[] elements= new Object[roots.length];
	for (int i = 0; i < elements.length; i++) {
		elements[i]= roots[i].getData();
	}
	return elements;
}
 
Example 9
Source File: PreTranslationResultDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: RelationDisplayTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
public RelationDisplayTableControl(Composite parent) {
  super(parent, SWT.NONE);
  setLayout(Widgets.buildContainerLayout(1));

  propViewer = new TableViewer(this,
      SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);

  // Layout embedded table
  Table propTable = propViewer.getTable();
  propTable.setLayoutData(Widgets.buildGrabFillData());

  // initialize the table
  propTable.setHeaderVisible(true);
  propTable.setToolTipText("Relations Display Properties");
  EditColTableDef.setupTable(TABLE_DEF, propTable);

  // Configure cell editing
  CellEditor[] cellEditors = new CellEditor[TABLE_DEF.length];
  cellEditors[INDEX_NAME] = null;
  cellEditors[INDEX_SOURCE] = null;
  cellEditors[INDEX_COLOR] = new ColorCellEditor(propTable);
  cellEditors[INDEX_STYLE] = new ComboBoxCellEditor(propTable,
      toString(EdgeDisplayProperty.LineStyle.values(), true));
  cellEditors[INDEX_ARROWHEAD] = new ComboBoxCellEditor(propTable,
      toString(EdgeDisplayProperty.ArrowheadStyle.values(), true));

  propViewer.setCellEditors(cellEditors);
  propViewer.setLabelProvider(new EdgeDisplayLabelProvider());
  propViewer.setColumnProperties(EditColTableDef.getProperties(TABLE_DEF));
  propViewer.setCellModifier(new EdgeDisplayCellModifier());

  // TODO: Add column sorters, filters?
  configSorters(propTable);

  // Configure content last: use updateTable() to render relations
  propViewer.setContentProvider(ArrayContentProvider.getInstance());
}
 
Example 11
Source File: PreMachineTranslationResultDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: PreTranslationResultDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: ReflectiveEditingSupport.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public ReflectiveEditingSupport(TableViewer columnViewer, String field,
	ICellEditorValidator validator, boolean markValidationFailed){
	super(columnViewer);
	this.field = field;
	this.editor = new TextCellEditor(columnViewer.getTable());
	if (validator != null)
	{
		editor.setValidator(validator);
		
		if (markValidationFailed)
		{
			editor.addListener(new ICellEditorListener() {
				@Override
				public void editorValueChanged(boolean oldValidState, boolean newValidState){
					if (newValidState) {
						editor.getControl().setBackground(
							Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
					} else {
						editor.getControl().setBackground(
							Display.getCurrent().getSystemColor(SWT.COLOR_RED));
					}
				}
				
				@Override
				public void cancelEditor(){
					editor.getControl().setBackground(
						Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
				}
				
				@Override
				public void applyEditorValue(){
					editor.getControl().setBackground(
						Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
				}
			});
		}
	}
}
 
Example 14
Source File: GitRepositoryPreferencePageView.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example 15
Source File: UpdateNoteDialog.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	Composite tparent = (Composite) super.createDialogArea(parent);
	GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).extendedMargins(5, 5, 5, 5).applyTo(tparent);
	GridDataFactory.fillDefaults().hint(620, 250).grab(true, true).applyTo(tparent);

	Group noteGroup = new Group(tparent, SWT.None);
	noteGroup.setText(Messages.getString("dialog.UpdateNoteDialog.noteGroup"));
	GridDataFactory.fillDefaults().grab(true, true).applyTo(noteGroup);
	noteGroup.setLayout(new GridLayout());

	tableViewer = new TableViewer(noteGroup, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL
			| SWT.V_SCROLL);
	Table table = tableViewer.getTable();
	table.setLayoutData(new GridData(GridData.FILL_BOTH));
	table.setHeaderVisible(true);
	table.setLinesVisible(true);

	String[] arrColName = new String[] { Messages.getString("dialog.UpdateNoteDialog.tableColumn1"),
			Messages.getString("dialog.UpdateNoteDialog.tableColumn2"),
			Messages.getString("dialog.UpdateNoteDialog.tableColumn3"),
			Messages.getString("dialog.UpdateNoteDialog.tableColumn4"),
			Messages.getString("dialog.UpdateNoteDialog.tableColumn5") };
	int[] arrColWidth = new int[] { 40, 100, 100, 150, 120 };
	for (int i = 0; i < arrColName.length; i++) {
		TableColumn column = new TableColumn(table, SWT.LEFT);
		column.setWidth(arrColWidth[i]);
		column.setText(arrColName[i]);
	}
	tableViewer.setLabelProvider(new TableViewerLabelProvider());
	tableViewer.setContentProvider(new ArrayContentProvider());

	Composite cmpBtn = new Composite(tparent, SWT.None);
	// cmpBtn.setLayout(new GridLayout());
	GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(0, 0, 35, 5).applyTo(cmpBtn);
	cmpBtn.setLayoutData(new GridData(GridData.FILL_VERTICAL));
	btnAdd = new Button(cmpBtn, SWT.NONE);
	btnAdd.setText(Messages.getString("dialog.UpdateNoteDialog.btnAdd"));
	btnAdd.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	btnEdit = new Button(cmpBtn, SWT.NONE);
	btnEdit.setText(Messages.getString("dialog.UpdateNoteDialog.btnEdit"));
	btnEdit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	btnDelete = new Button(cmpBtn, SWT.NONE);
	btnDelete.setText(Messages.getString("dialog.UpdateNoteDialog.btnDelete"));
	btnDelete.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	initTable();
	initListener();

	return tparent;
}
 
Example 16
Source File: CommentEditor.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
CommentEditor(TableViewer viewer, ProcessEditor editor) {
	super(viewer.getTable());
	this.editor = editor;
}
 
Example 17
Source File: SellOrderEditingSupport.java    From offspring with MIT License 4 votes vote down vote up
public SellOrderEditingSupport(TableViewer viewer, int columnId) {
  super(viewer);
  this.editor = new TextCellEditor(viewer.getTable());
  this.provider = new SellOrderLabelProvider();
  this.columnId = columnId;
}
 
Example 18
Source File: XBookmarksDialog.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
 protected Control createDialogArea(Composite parent) {
     Composite composite = (Composite) super.createDialogArea(parent);
     GridLayoutFactory.fillDefaults().extendedMargins(Util.isWindows() ? 0 : 3, 3, 2, 2).applyTo(composite);

     Composite tableComposite = new Composite(composite, SWT.NONE);
     tableComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
     tableComposite.setLayout(new GridLayout(1, false));
     
     tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
             | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
     
     table = tableViewer.getTable();
     table.setLayoutData(new GridData(GridData.FILL_BOTH));
     tableViewer.setContentProvider(new MenuTableContentProvider());
     tableViewer.setLabelProvider(new MenuTableLabelProvider());

     { // Columns:
         GC gc= new GC(table);
         try {
         	int maxW = gc.stringExtent("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW").x; //$NON-NLS-1$
         	int gap  = gc.stringExtent("WW").x; //$NON-NLS-1$
         	int widths[] = new int[model.columns];
         	for (int i=0; i<model.columns; ++i) {
         		widths[i] = 0;
         	}
         	for (Model.Row r : model.getRows()) {
         		for (int i=0; i<model.columns; ++i) {
         			if (!r.getField(i).isEmpty()) {
         				int w     = Math.min(gc.stringExtent(r.getField(i)).x + gap, maxW);
         				widths[i] = Math.max(widths[i], w);
         			}
         		}
         	}
         	
         	for (int i=0; i<model.columns; ++i) {
         		TableColumn tc = new TableColumn(table, SWT.LEFT);
         		tc.setWidth(widths[i]);
         	}
         	table.setHeaderVisible(false);
         	table.setLinesVisible(false);
} finally {
	gc.dispose();
}
     }
     
     Listener eventListener = new Listener() {
         @Override
         public void handleEvent(Event event) {
             if (event.type == SWT.MouseDoubleClick || 
                (event.type == SWT.KeyDown && event.character == SWT.CR)) 
             {
                 doSelect();
             }
         }
         
     };
     
     addListener (SWT.KeyDown, eventListener);
     addListener (SWT.MouseDoubleClick, eventListener);
         
     tableViewer.setInput(model);
     table.select(0);

     return composite;
 }
 
Example 19
Source File: CrosstabFilterConditionBuilder.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void createMemberValuesGroup( Composite content )
{
	group = new Group( content, SWT.NONE );
	group.setText( Messages.getString( "CrosstabFilterConditionBuilder.Label.SelColumnMemberValue" ) ); //$NON-NLS-1$
	group.setLayout( new GridLayout( ) );

	memberValueTable = new Table( group, SWT.SINGLE
			| SWT.BORDER
			| SWT.H_SCROLL
			| SWT.V_SCROLL
			| SWT.FULL_SELECTION );
	memberValueTable.setLinesVisible( true );
	memberValueTable.setHeaderVisible( true );
	memberValueTable.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	GridData gd = new GridData( GridData.FILL_BOTH );
	gd.heightHint = 150;
	gd.horizontalSpan = 3;
	group.setLayoutData( gd );

	dynamicViewer = new TableViewer( memberValueTable );

	TableColumn column = new TableColumn( memberValueTable, SWT.LEFT );
	column.setText( columns[0] );
	column.setWidth( 15 );

	TableColumn column1 = new TableColumn( memberValueTable, SWT.LEFT );
	column1.setResizable( columns[1] != null );
	if ( columns[1] != null )
	{
		column1.setText( columns[1] );
	}
	column1.setWidth( 200 );

	TableColumn column2 = new TableColumn( memberValueTable, SWT.LEFT );
	column2.setResizable( columns[2] != null );
	if ( columns[2] != null )
	{
		column2.setText( columns[2] );
	}
	column2.setWidth( 200 );

	dynamicViewer.setColumnProperties( columns );
	editor = new ExpressionValueCellEditor( dynamicViewer.getTable( ),
			SWT.READ_ONLY );
	TextCellEditor textEditor = new TextCellEditor( dynamicViewer.getTable( ),
			SWT.READ_ONLY );
	TextCellEditor textEditor2 = new TextCellEditor( dynamicViewer.getTable( ),
			SWT.READ_ONLY );
	CellEditor[] cellEditors = new CellEditor[]{
			textEditor, textEditor2, editor
	};
	if ( designHandle != null )
	{
		editor.setExpressionProvider( getCrosstabExpressionProvider( ) );
		editor.setReportElement( (ExtendedItemHandle) designHandle );
	}

	dynamicViewer.setCellEditors( cellEditors );

	dynamicViewer.setContentProvider( contentProvider );
	dynamicViewer.setLabelProvider( labelProvider );
	dynamicViewer.setCellModifier( cellModifier );
	dynamicViewer.addSelectionChangedListener( selectionChangeListener );
}
 
Example 20
Source File: ExpressionBuilder.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void initTable( TableViewer tableViewer, boolean leafOnly )
{
	final Table table = tableViewer.getTable( );

	GridData gd = new GridData( GridData.FILL_BOTH );
	gd.heightHint = 150;
	table.setLayoutData( gd );
	table.setToolTipText( null );

	final TableColumn column = new TableColumn( table, SWT.NONE );
	column.setWidth( 200 );
	table.getShell( ).addControlListener( new ControlAdapter( ) {

		public void controlResized( ControlEvent e )
		{
			Display.getCurrent( ).asyncExec( new Runnable( ) {

				public void run( )
				{
					if ( column != null && !column.isDisposed( ) )
					{
						column.setWidth( table.getSize( ).x > 204 ? table.getSize( ).x - 4
								: 200 );
					}
				}
			} );

		}

	} );

	table.addMouseTrackListener( new MouseTrackAdapter( ) {

		public void mouseHover( MouseEvent event )
		{
			Widget widget = event.widget;
			if ( widget == table )
			{
				Point pt = new Point( event.x, event.y );
				TableItem item = table.getItem( pt );
				if ( item == null )
				{

					table.setToolTipText( null );
				}
				else
				{
					table.setToolTipText( provider.getTooltipText( item.getData( ) ) );
				}
			}
		}
	} );

	tableViewer.setLabelProvider( new ExpressionLabelProvider( ) );
	tableViewer.setContentProvider( new TableContentProvider( tableViewer, leafOnly ) );
	tableViewer.addSelectionChangedListener( selectionListener );
	tableViewer.addDoubleClickListener( doubleClickListener );
}