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

The following examples show how to use org.eclipse.swt.widgets.Table#addMouseListener() . 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: ModelPropertiesDialog.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
/**
 * This method initializes composite1
 */
private void createTableComposite(final Composite parent) {
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;

    final GridData gridData = new GridData();
    gridData.heightHint = 320;

    final GridData tableGridData = new GridData();
    tableGridData.horizontalSpan = 3;
    tableGridData.heightHint = 185;

    final Composite composite = new Composite(parent, SWT.BORDER);
    composite.setLayout(gridLayout);
    composite.setLayoutData(gridData);

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

    final TableColumn tableColumn0 = new TableColumn(table, SWT.NONE);
    tableColumn0.setWidth(200);
    tableColumn0.setText(ResourceString.getResourceString("label.property.name"));
    final TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
    tableColumn1.setWidth(200);
    tableColumn1.setText(ResourceString.getResourceString("label.property.value"));

    tableEditor = new TableEditor(table);
    tableEditor.grabHorizontal = true;

    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent event) {
            final int index = table.getSelectionIndex();
            if (index == -1) {
                return;
            }

            final TableItem item = table.getItem(index);
            final Point selectedPoint = new Point(event.x, event.y);

            targetColumn = -1;

            for (int i = 0; i < table.getColumnCount(); i++) {
                final Rectangle rect = item.getBounds(i);
                if (rect.contains(selectedPoint)) {
                    targetColumn = i;
                    break;
                }
            }

            if (targetColumn == -1) {
                return;
            }

            edit(item, tableEditor);
        }

    });
}
 
Example 2
Source File: ModelPropertiesDialog.java    From erflute with Apache License 2.0 4 votes vote down vote up
/**
 * This method initializes composite1
 */
private void createTableComposite(Composite parent) {
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;

    final GridData gridData = new GridData();
    gridData.heightHint = 320;

    final GridData tableGridData = new GridData();
    tableGridData.horizontalSpan = 3;
    tableGridData.heightHint = 185;

    final Composite composite = new Composite(parent, SWT.BORDER);
    composite.setLayout(gridLayout);
    composite.setLayoutData(gridData);

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

    final TableColumn tableColumn0 = new TableColumn(table, SWT.NONE);
    tableColumn0.setWidth(200);
    tableColumn0.setText(DisplayMessages.getMessage("label.property.name"));
    final TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
    tableColumn1.setWidth(200);
    tableColumn1.setText(DisplayMessages.getMessage("label.property.value"));

    tableEditor = new TableEditor(table);
    tableEditor.grabHorizontal = true;

    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent event) {
            final int index = table.getSelectionIndex();
            if (index == -1) {
                return;
            }

            final TableItem item = table.getItem(index);
            final Point selectedPoint = new Point(event.x, event.y);

            targetColumn = -1;

            for (int i = 0; i < table.getColumnCount(); i++) {
                final Rectangle rect = item.getBounds(i);
                if (rect.contains(selectedPoint)) {
                    targetColumn = i;
                    break;
                }
            }

            if (targetColumn == -1) {
                return;
            }

            edit(item, tableEditor);
        }
    });
}
 
Example 3
Source File: ResultSetPreviewPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Control createPageControl( Composite parent )
{
	Composite resultSetComposite = new Composite( parent, SWT.NONE );
	GridLayout layout = new GridLayout( );
	layout.verticalSpacing = 15;
	resultSetComposite.setLayout( layout );
	resultSetComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	resultSetTable = new Table( resultSetComposite, SWT.FULL_SELECTION | SWT.MULTI | SWT.VIRTUAL | SWT.BORDER );
	resultSetTable.setHeaderVisible( true );
	resultSetTable.setLinesVisible( true );
	resultSetTable.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	( (DataSetHandle) getContainer( ).getModel( ) ).addListener( this );

	resultSetTable.addMouseListener( new MouseAdapter( ) {

		public void mouseUp( MouseEvent e )
		{
			// if not mouse left button
			if ( e.button != 1 )
			{
				MenuManager menuManager = new MenuManager( );

				ResultSetTableAction copyAction = ResultSetTableActionFactory.createResultSetTableAction( resultSetTable,
						ResultSetTableActionFactory.COPY_ACTION );
				ResultSetTableAction selectAllAction = ResultSetTableActionFactory.createResultSetTableAction( resultSetTable,
						ResultSetTableActionFactory.SELECTALL_ACTION );
				menuManager.add( copyAction );
				menuManager.add( selectAllAction );

				menuManager.update( );

				copyAction.update( );
				selectAllAction.update( );

				Menu contextMenu = menuManager.createContextMenu( resultSetTable );

				contextMenu.setEnabled( true );
				contextMenu.setVisible( true );
			}
		}
	} );

	createResultSetTableViewer( );
	promptLabel = new CLabel( resultSetComposite, SWT.WRAP );
	GridData labelData = new GridData( GridData.FILL_HORIZONTAL );
	promptLabel.setLayoutData( labelData );
	
	return resultSetComposite;
}
 
Example 4
Source File: OutputParameterPreviewPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Control createPageControl( Composite parent )
{
	outputParameterTable = new Table( parent, SWT.FULL_SELECTION
			| SWT.MULTI );
	outputParameterTable.setHeaderVisible( true );
	outputParameterTable.setLinesVisible( true );
	( (DataSetHandle) getContainer( ).getModel( ) ).addListener( this );

	outputParameterTable.addMouseListener( new MouseAdapter( ) {

		/*
		 *  (non-Javadoc)
		 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
		 */
		public void mouseUp( MouseEvent e )
		{
			// if not mouse left button
			if ( e.button != 1 )
			{
				MenuManager menuManager = new MenuManager( );

				ResultSetTableAction copyAction = ResultSetTableActionFactory.createResultSetTableAction( outputParameterTable,
						ResultSetTableActionFactory.COPY_ACTION );
				ResultSetTableAction selectAllAction = ResultSetTableActionFactory.createResultSetTableAction( outputParameterTable,
						ResultSetTableActionFactory.SELECTALL_ACTION );
				menuManager.add( copyAction );
				menuManager.add( selectAllAction );

				menuManager.update( );

				copyAction.update( );
				selectAllAction.update( );

				Menu contextMenu = menuManager.createContextMenu( outputParameterTable );

				contextMenu.setEnabled( true );
				contextMenu.setVisible( true );
			}
		}
	} );

	return outputParameterTable;
}