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

The following examples show how to use org.eclipse.swt.widgets.Table#addListener() . 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: TableCombo.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * creates the popup shell.
 *
 * @param selectionIndex
 */
void createPopup(final int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null) {
		table.setFont(font);
	}
	if (foreground != null) {
		table.setForeground(foreground);
	}
	if (background != null) {
		table.setBackground(background);
	}

	// Add popup listeners
	final int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (final int popupEvent : popupEvents) {
		popup.addListener(popupEvent, listener);
	}

	// add table listeners
	final int[] tableEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn,
			SWT.Dispose };
	for (final int tableEvent : tableEvents) {
		table.addListener(tableEvent, listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 2
Source File: StyleCombo.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
void createPopup( Object[] items, int selectionIndex )
{
	// create shell and list
	popup = new Shell( getShell( ), SWT.NO_TRIM | SWT.ON_TOP );

	table = new Table( popup, SWT.SINGLE
			| SWT.V_SCROLL
			| SWT.FULL_SELECTION );
	new TableColumn( table, SWT.LEFT );
	if ( font != null )
		table.setFont( font );
	if ( foreground != null )
		table.setForeground( foreground );
	if ( background != null )
		table.setBackground( background );

	label.setBackground( table.getBackground( ) );
	label.setForeground( table.getForeground( ) );
	label.setFont( table.getFont( ) );

	int[] popupEvents = {
			SWT.Close, SWT.Paint, SWT.Deactivate
	};
	for ( int i = 0; i < popupEvents.length; i++ )
		popup.addListener( popupEvents[i], listener );
	int[] tableEvents = {
			SWT.MouseUp,
			SWT.Selection,
			SWT.Traverse,
			SWT.KeyDown,
			SWT.KeyUp,
			SWT.FocusIn,
			SWT.FocusOut,
			SWT.Dispose
	};
	for ( int i = 0; i < tableEvents.length; i++ )
		table.addListener( tableEvents[i], listener );
}
 
Example 3
Source File: TableCombo.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
    // create shell and table
    popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

    // create table
    table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

    if (font != null)
        table.setFont(font);
    if (foreground != null)
        table.setForeground(foreground);
    if (background != null)
        table.setBackground(background);

    // Add popup listeners
    int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
    for (int i = 0; i < popupEvents.length; i++) {
        popup.addListener(popupEvents[i], listener);
    }

    // add table listeners
    int[] tableEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn,
            SWT.Dispose };
    for (int i = 0; i < tableEvents.length; i++) {
        table.addListener(tableEvents[i], listener);
    }

    // set the selection
    if (selectionIndex != -1) {
        table.setSelection(selectionIndex);
    }
}
 
Example 4
Source File: KeyAssistDialog.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a dialog area with a table of the partial matches for the current
 * key binding state. The table will be either the minimum width, or
 * <code>previousWidth</code> if it is not
 * <code>NO_REMEMBERED_WIDTH</code>.
 * 
 * @param parent
 *            The parent composite for the dialog area; must not be
 *            <code>null</code>.
 * @param partialMatches
 *            The lexicographically sorted map of partial matches for the
 *            current state; must not be <code>null</code> or empty.
 */
private final void createTableDialogArea(final Composite parent) {
    // Layout the table.
    completionsTable = new Table(parent, SWT.FULL_SELECTION | SWT.SINGLE);
    final GridData gridData = new GridData(GridData.FILL_BOTH);
    completionsTable.setLayoutData(gridData);
    completionsTable.setBackground(parent.getBackground());
    completionsTable.setLinesVisible(true);

    // Initialize the columns and rows.
    bindings.clear();
    final TableColumn columnCommandName = new TableColumn(completionsTable, SWT.LEFT, 0);
    final TableColumn columnKeySequence = new TableColumn(completionsTable, SWT.LEFT, 1);
    final Iterator itemsItr = keybindingToActionInfo.entrySet().iterator();
    while (itemsItr.hasNext()) {
        final Map.Entry entry = (Entry) itemsItr.next();
        final String sequence = (String) entry.getKey();
        final ActionInfo actionInfo = (ActionInfo) entry.getValue();
        final String[] text = { sequence, actionInfo.description };
        final TableItem item = new TableItem(completionsTable, SWT.NULL);
        item.setText(text);
        item.setData("ACTION_INFO", actionInfo);
        bindings.add(actionInfo);
    }

    Dialog.applyDialogFont(parent);
    columnKeySequence.pack();
    columnCommandName.pack();

    /*
     * If you double-click on the table, it should execute the selected
     * command.
     */
    completionsTable.addListener(SWT.DefaultSelection, new Listener() {
        @Override
        public final void handleEvent(final Event event) {
            executeKeyBinding(event);
        }
    });
}
 
Example 5
Source File: NetworkPreferencePage.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private Group createUpnpGroup(Composite parent) {

    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.NetworkPreferencePage_upnp_devices);

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;

    group.setLayout(gridLayout);
    group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));

    gatewayInfo = new Label(group, SWT.CENTER);
    gatewayInfo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    upnpDevicesTable = new Table(group, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);

    upnpDevicesTable.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    upnpDevicesTable.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (event.detail == SWT.CHECK) handleGatewaySelection(event);
          }
        });

    gatewayInfo.setVisible(false);
    upnpDevicesTable.setVisible(false);

    return group;
  }
 
Example 6
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * New table.
 *
 * @param parent the parent
 * @param style the style
 * @param minHeight the min height
 * @param flags the flags
 * @return the table
 */
protected Table newTable(Composite parent, int style, int minHeight, int flags) {
  Table table = toolkit.createTable(parent, style);
  GridData gd = new GridData(GridData.FILL_BOTH);
  if (minHeight != NO_MIN_HEIGHT)
    gd.heightHint = minHeight;
  table.setLayoutData(gd);

  table.setLinesVisible(0 != (flags & LINES_VISIBLE));
  table.setHeaderVisible(0 != (flags & HEADER_VISIBLE));
  table.addListener(SWT.Selection, this);
  table.addListener(SWT.KeyUp, this); // delete key
  return table;
}
 
Example 7
Source File: AbstractDialog.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Styles = SWT.SINGLE / MULTI / CHECK / FULL_SELECTION / HIDE_SELECTION
 *
 * @param parent the parent
 * @param style the style
 * @return the new table widget
 */
protected Table newTable(Composite parent, int style) {
  Table table = new Table(parent, style | SWT.BORDER);
  GridData gd = new GridData(GridData.FILL_BOTH);
  table.setLayoutData(gd);
  table.addListener(SWT.Selection, this);
  table.addListener(SWT.KeyUp, this); // delete key
  return table;
}
 
Example 8
Source File: TableClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static Action onCopy(Table table, Converter converter) {
	table.addListener(SWT.KeyUp, e -> {
		if (((e.stateMask & SWT.CTRL) == SWT.CTRL)
				&& (e.keyCode == 'c' || e.keyCode == 'C')) {
			copy(table, converter);
		}
	});
	ImageDescriptor image = Icon.COPY.descriptor();
	return Actions.create(M.Copy, image, () -> copy(table, converter));
}
 
Example 9
Source File: TableClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static Action onPaste(Table table, Consumer<String> fn) {
	table.addListener(SWT.KeyUp, e -> {
		if (((e.stateMask & SWT.CTRL) == SWT.CTRL)
				&& (e.keyCode == 'v' || e.keyCode == 'V')) {
			paste(table, fn);
		}
	});
	ImageDescriptor image = Icon.PASTE.descriptor();
	return Actions.create(M.Paste, image, () -> paste(table, fn));
}
 
Example 10
Source File: PTWidgetTable.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.propertytable.AbstractPTWidget#buildWidget(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void buildWidget(final Composite parent) {
	table = new Table(parent, SWT.FULL_SELECTION);
	table.setLinesVisible(true);
	table.setHeaderVisible(true);
	table.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 3, 1));

	final TableColumn propertyColumn = new TableColumn(table, SWT.NONE);
	propertyColumn.setText(ResourceManager.getLabel(ResourceManager.PROPERTY));

	final TableColumn valueColumn = new TableColumn(table, SWT.NONE);
	valueColumn.setText(ResourceManager.getLabel(ResourceManager.VALUE));

	fillData();

	table.addControlListener(new ControlAdapter() {

		/**
		 * @see org.eclipse.swt.events.ControlAdapter#controlResized(org.eclipse.swt.events.ControlEvent)
		 */
		@Override
		public void controlResized(final ControlEvent e) {
			final Rectangle area = table.getParent().getClientArea();
			final Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
			final ScrollBar vBar = table.getVerticalBar();
			int width = area.width - table.computeTrim(0, 0, 0, 0).width - vBar.getSize().x;
			if (size.y > area.height + table.getHeaderHeight()) {
				// Subtract the scrollbar width from the total column width
				// if a vertical scrollbar will be required
				final Point vBarSize = vBar.getSize();
				width -= vBarSize.x;
			}
			propertyColumn.pack();
			valueColumn.setWidth(width - propertyColumn.getWidth());
			table.removeControlListener(this);
		}

	});

	table.addListener(SWT.Selection, event -> {
		if (table.getSelectionCount() == 0 || table.getSelection()[0] == null) {
			return;
		}
		updateDescriptionPanel(table.getSelection()[0].getData());
	});

}
 
Example 11
Source File: CenteredContentCellPaint.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
public CenteredContentCellPaint(final Table tbl, final int colIndex) {
    this.colIndex = colIndex;
    tbl.addListener(SWT.EraseItem, this);
    tbl.addListener(SWT.PaintItem, this);
}
 
Example 12
Source File: CenteredContentCellPaint.java    From erflute with Apache License 2.0 4 votes vote down vote up
public CenteredContentCellPaint(Table tbl, int colIndex) {
    this.colIndex = colIndex;
    tbl.addListener(SWT.EraseItem, this);
    tbl.addListener(SWT.PaintItem, this);
}
 
Example 13
Source File: TableCombo.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 14
Source File: TableCombo.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 15
Source File: ReportItemParametersDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void buildUI( Composite parent )
{
	// sets the layout
	GridLayout layout = new GridLayout( );
	layout.horizontalSpacing = 10;
	layout.verticalSpacing = 10;
	parent.setLayout( layout );

	// create table and tableViewer
	table = new Table( parent, SWT.SINGLE
			| SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION );
	table.setLinesVisible( true );
	table.setHeaderVisible( true );
	GridData gridData = new GridData( GridData.FILL_BOTH );
	gridData.heightHint = 100;
	table.setLayoutData( gridData );
	for ( int i = 0; i < columnNames.length; i++ )
	{
		TableColumn column = new TableColumn( table, SWT.LEFT );
		column.setText( columnNames[i] );
		if ( i == 1 )
		{
			column.setWidth( 80 );
		}
		else
		{
			column.setWidth( 160 );
		}
	}
	
	table.addListener( SWT.KeyDown, new Listener( ) {

		public void handleEvent( Event event )
		{
			// Use space key to open expression builder to edit
			if ( event.keyCode == ' ' )
			{
				int selectionIndex = table.getSelectionIndex( );
				if ( selectionIndex < 0 )
				{
					return;
				}
				TableItem item = table.getItem( selectionIndex );
				Object[] pair = (Object[]) item.getData( );
				DataSetParameterHandle dataHandle = (DataSetParameterHandle) pair[0];
				ParamBindingHandle bindingHandle = (ParamBindingHandle) pair[1];
				String oldValue = bindingHandle == null ? null
						: bindingHandle.getExpression( );
				if ( oldValue == null )
				{
					oldValue = dataHandle.getDefaultValue( );
				}
				Object value = expressionCellEditor.openDialogBox( table,
						oldValue );
				setValue( bindingHandle, value, item );
			}

		}
	} );

	createTableViewer( );

}
 
Example 16
Source File: CenteredContentCellPaint.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public CenteredContentCellPaint(Table tbl, int colIndex) {
	this.colIndex = colIndex;
	tbl.addListener(SWT.EraseItem, this);
	tbl.addListener(SWT.PaintItem, this);
}