Example usage for org.eclipse.jface.viewers TableViewer add

List of usage examples for org.eclipse.jface.viewers TableViewer add

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer add.

Prototype

public void add(Object[] elements) 

Source Link

Document

Adds the given elements to this table viewer.

Usage

From source file:pspnetparty.client.swt.RoomWindow.java

License:Open Source License

private void replaceRoomPlayerList(final String[] playerInfoList) {
    try {/*www. ja  v a 2s  . c  o m*/
        if (SwtUtils.isNotUIThread()) {
            SwtUtils.DISPLAY.asyncExec(new Runnable() {
                @Override
                public void run() {
                    replaceRoomPlayerList(playerInfoList);
                }
            });
            return;
        }
        TableViewer viewer = widgets.roomPlayerListTable;

        viewer.getTable().clearAll();
        roomPlayerMap.clear();
        for (int i = 0; i < playerInfoList.length - 1; i++) {
            String name = playerInfoList[i];
            String ssid = playerInfoList[++i];

            if (Utility.isEmpty(name))
                continue;

            Player player = new Player(name);
            player.setSsid(name.equals(roomLoginName) ? widgets.ssidCurrentSsidText.getText() : ssid);

            roomPlayerMap.put(name, player);
            viewer.add(player);
        }
        viewer.refresh();
    } catch (SWTException e) {
    }
}

From source file:pspnetparty.client.swt.RoomWindow.java

License:Open Source License

private void addRoomPlayer(final String name) {
    try {/*  w  ww.  jav  a 2  s.c o m*/
        if (SwtUtils.isNotUIThread()) {
            SwtUtils.DISPLAY.asyncExec(new Runnable() {
                @Override
                public void run() {
                    addRoomPlayer(name);
                }
            });
            return;
        }
        TableViewer viewer = widgets.roomPlayerListTable;

        InfoLog log = new InfoLog(name + "  ");
        widgets.logViewer.appendMessage(log);

        if (!isActive && application.getSettings().isBallonNotifyRoom())
            application.balloonNotify(shell, log.getMessage());

        Player player = new Player(name);

        roomPlayerMap.put(name, player);
        viewer.add(player);
        viewer.refresh();

        sendMyRoomPlayerCountChange();
    } catch (SWTException e) {
    }
}

From source file:x10dt.ui.launch.cpp.launching.CommunicationInterfaceTab.java

License:Open Source License

public void createControl(final Composite parent) {
    this.fTransport = getTransport();
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setFont(parent.getFont());
    mainComposite.setLayout(new GridLayout(1, false));
    mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Composite placesCompo = new Composite(mainComposite, SWT.NONE);
    placesCompo.setFont(mainComposite.getFont());
    placesCompo.setLayout(new GridLayout(2, false));
    placesCompo.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, true, false));

    new Label(placesCompo, SWT.NONE).setText(Messages.SRMLCDT_PlacesNumber);
    this.fNumPlacesSpinner = new Spinner(placesCompo, SWT.BORDER);
    this.fNumPlacesSpinner.setSelection(DEFAULT_NUM_PLACES);
    this.fNumPlacesSpinner.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            updateLaunchConfigurationDialog();
        }/*  w  w w  .j av  a2  s  .com*/

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Group hostsGroup = new Group(mainComposite, SWT.NONE);
    hostsGroup.setFont(mainComposite.getFont());
    hostsGroup.setLayout(new GridLayout(2, false));
    hostsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    hostsGroup.setText(Messages.SRMLCDT_HostsGroupName);

    this.fHostFileBt = new Button(hostsGroup, SWT.RADIO);
    this.fHostFileBt.setText(Messages.SRMLCDT_HostFileBt);
    this.fHostFileBt.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false, 2, 1));
    this.fHostFileBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            updateSelectionState(HOST_FILE, CommunicationInterfaceTab.this.fTransport);
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Text hostFileText = new Text(hostsGroup, SWT.BORDER);
    this.fHostFileText = hostFileText;
    final GridData hostFileGData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    hostFileGData.horizontalIndent = 30;
    this.fHostFileText.setLayoutData(hostFileGData);
    this.fHostFileText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent event) {
            updateLaunchConfigurationDialog();
        }

    });

    this.fHostFileBrowseBt = new Button(hostsGroup, SWT.PUSH);
    this.fHostFileBrowseBt.setText(Messages.SRMLCDT_BrowseBt);
    this.fHostFileBrowseBt.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    this.fHostFileBrowseBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            try {
                final String path;
                ILaunchConfiguration compilationConf = ConfUtils
                        .getConfiguration(CommunicationInterfaceTab.this.fProjectName);
                if (ConfUtils.isLocalConnection(compilationConf)) {
                    final FileDialog dialog = new FileDialog(parent.getShell());
                    dialog.setText(Messages.SRMLCDT_SelectHostFileDialogTitle);
                    path = dialog.open();
                } else {
                    final IRemoteServices remoteServices = RemoteServices
                            .getRemoteServices(REMOTE_CONN_SERVICE_ID);
                    final IRemoteConnection connection = remoteServices.getConnectionManager()
                            .getConnection(ConfUtils.getConnectionName(compilationConf));
                    path = remoteBrowse(parent.getShell(), connection,
                            Messages.SRMLCDT_SelectHostFileDialogTitle, Constants.EMPTY_STR);
                }
                if (path != null) {
                    hostFileText.setText(path);
                }
            } catch (CoreException e) {
                CppLaunchCore.getInstance().getLog().log(e.getStatus());
            }
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    this.fHostListBt = new Button(hostsGroup, SWT.RADIO);
    this.fHostListBt.setText(Messages.SRMLCDT_HostListBt);
    this.fHostListBt.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false, 2, 1));
    this.fHostListBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            updateSelectionState(HOST_LIST, CommunicationInterfaceTab.this.fTransport);
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Composite tableComposite = new Composite(hostsGroup, SWT.NONE);
    tableComposite.setFont(hostsGroup.getFont());
    final GridData tableGData = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableGData.verticalSpan = 2;
    tableGData.horizontalIndent = 30;
    tableComposite.setLayoutData(tableGData);

    final TableViewer viewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    this.fHostListViewer = viewer;
    this.fHostListViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final TableViewerColumn column = new TableViewerColumn(this.fHostListViewer, SWT.NONE);
    column.setLabelProvider(new ColumnLabelProvider() {

        public String getText(final Object element) {
            return (String) element;
        }

    });
    final TextCellEditor editor = new TextCellEditor(viewer.getTable());
    ;
    column.setEditingSupport(new EditingSupport(this.fHostListViewer) {

        protected CellEditor getCellEditor(final Object element) {
            return editor;
        }

        @SuppressWarnings("unqualified-field-access")
        protected boolean canEdit(final Object element) {
            return viewer.getTable().getSelectionIndex() < fHosts.size();
        }

        protected Object getValue(final Object element) {
            return element;
        }

        @SuppressWarnings("unqualified-field-access")
        protected void setValue(final Object element, final Object value) {
            final int index = fHosts.indexOf(element);
            fHosts.remove(element);
            fHosts.add(index, (String) value);
            viewer.refresh();

            updateLaunchConfigurationDialog();
        }

    });

    final TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableColumnLayout.setColumnData(column.getColumn(), new ColumnWeightData(100));
    tableComposite.setLayout(tableColumnLayout);

    this.fHostListViewer.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(final Viewer curViewer, final Object oldInput, final Object newInput) {
        }

        public void dispose() {
        }

        @SuppressWarnings("unqualified-field-access")
        public Object[] getElements(final Object inputElement) {
            return fHosts.toArray(new String[fHosts.size()]);
        }

    });

    this.fHostListViewer.setInput(this.fHosts);
    this.fHostListViewer.getTable().setLinesVisible(true);

    final Button addButton = new Button(hostsGroup, SWT.PUSH);
    this.fAddButton = addButton;
    addButton.setText(Messages.SRMLCDT_AddBt);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.addSelectionListener(new SelectionListener() {

        @SuppressWarnings("unqualified-field-access")
        public void widgetSelected(final SelectionEvent event) {
            fHosts.add(Constants.EMPTY_STR);
            viewer.getTable().select(viewer.getTable().getItemCount() - 1);
            viewer.add(Constants.EMPTY_STR);
            viewer.editElement(Constants.EMPTY_STR, 0);
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Button removeButton = new Button(hostsGroup, SWT.PUSH);
    this.fRemoveButton = removeButton;
    removeButton.setText(Messages.SRMLCDT_RemoveBt);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    removeButton.addSelectionListener(new SelectionListener() {

        @SuppressWarnings("unqualified-field-access")
        public void widgetSelected(final SelectionEvent event) {
            final Object hostName = viewer.getElementAt(viewer.getTable().getSelectionIndex());
            if (hostName != null) {
                fHosts.remove(hostName);
                viewer.remove(hostName);

                updateLaunchConfigurationDialog();
            }
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    this.fLoadLevelerBt = new Button(hostsGroup, SWT.RADIO);
    this.fLoadLevelerBt.setText(Messages.SRMLCDT_LLBt);
    this.fLoadLevelerBt.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false, 2, 1));
    this.fLoadLevelerBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            updateSelectionState(LOAD_LEVELER, CommunicationInterfaceTab.this.fTransport);
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    this.fLoadLevelerText = new Text(hostsGroup, SWT.BORDER);
    this.fLoadLevelerText.setText(Constants.EMPTY_STR);
    final GridData loadLevelerGData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    loadLevelerGData.horizontalIndent = 30;
    this.fLoadLevelerText.setLayoutData(loadLevelerGData);
    this.fLoadLevelerText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent event) {
            updateLaunchConfigurationDialog();
        }

    });

    this.fLoadLevelerBrowseBt = new Button(hostsGroup, SWT.PUSH);
    this.fLoadLevelerBrowseBt.setText(Messages.SRMLCDT_BrowseBt);
    this.fLoadLevelerBrowseBt.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    this.fLoadLevelerBrowseBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            try {
                final String path;
                ILaunchConfiguration compilationConf = ConfUtils
                        .getConfiguration(CommunicationInterfaceTab.this.fProjectName);
                if (ConfUtils.isLocalConnection(compilationConf)) {
                    final FileDialog dialog = new FileDialog(parent.getShell());
                    dialog.setText(Messages.SRMLCDT_SelectHostFileDialogTitle);
                    path = dialog.open();
                } else {
                    final IRemoteServices remoteServices = RemoteServices
                            .getRemoteServices(REMOTE_CONN_SERVICE_ID);
                    final IRemoteConnection connection = remoteServices.getConnectionManager()
                            .getConnection(ConfUtils.getConnectionName(compilationConf));
                    path = remoteBrowse(parent.getShell(), connection,
                            Messages.SRMLCDT_SelectHostFileDialogTitle, Constants.EMPTY_STR);
                }
                if (path != null) {
                    hostFileText.setText(path);
                }
            } catch (CoreException e) {
                CppLaunchCore.getInstance().getLog().log(e.getStatus());
            }
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    setControl(mainComposite);

    updateSelectionState(HOST_FILE, this.fTransport);
}

From source file:x10dt.ui.launch.java.launching.CommunicationInterfaceTab.java

License:Open Source License

public void createControl(final Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setFont(parent.getFont());
    mainComposite.setLayout(new GridLayout(1, false));
    mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Composite placesCompo = new Composite(mainComposite, SWT.NONE);
    placesCompo.setFont(mainComposite.getFont());
    placesCompo.setLayout(new GridLayout(2, false));
    placesCompo.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, true, false));

    new Label(placesCompo, SWT.NONE).setText(Messages.SRMLCDT_PlacesNumber);
    this.fNumPlacesSpinner = new Spinner(placesCompo, SWT.BORDER);
    this.fNumPlacesSpinner.setSelection(DEFAULT_NUM_PLACES);
    this.fNumPlacesSpinner.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            updateLaunchConfigurationDialog();
        }//from w  w  w.j  av a 2s. c  om

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Group hostsGroup = new Group(mainComposite, SWT.NONE);
    hostsGroup.setFont(mainComposite.getFont());
    hostsGroup.setLayout(new GridLayout(2, false));
    hostsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    hostsGroup.setText(Messages.SRMLCDT_HostsGroupName);

    this.fHostFileBt = new Button(hostsGroup, SWT.RADIO);
    this.fHostFileBt.setText(Messages.SRMLCDT_HostFileBt);
    this.fHostFileBt.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false, 2, 1));
    this.fHostFileBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            updateSelectionState(true);
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Text hostFileText = new Text(hostsGroup, SWT.BORDER);
    this.fHostFileText = hostFileText;
    final GridData hostFileGData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    hostFileGData.horizontalIndent = 30;
    this.fHostFileText.setLayoutData(hostFileGData);
    this.fHostFileText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent event) {
            updateLaunchConfigurationDialog();
        }

    });

    this.fHostFileBrowseBt = new Button(hostsGroup, SWT.PUSH);
    this.fHostFileBrowseBt.setText(Messages.SRMLCDT_BrowseBt);
    this.fHostFileBrowseBt.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    this.fHostFileBrowseBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {

            final String path;
            if (CommunicationInterfaceTab.this.fIsLocal) {
                final FileDialog dialog = new FileDialog(parent.getShell());
                dialog.setText(Messages.SRMLCDT_SelectHostFileDialogTitle);
                path = dialog.open();
            } else {
                final IRemoteServices remoteServices = RemoteServices.getRemoteServices(REMOTE_CONN_SERVICE_ID);
                final IRemoteConnection connection = remoteServices.getConnectionManager().getConnection(
                        ConfUtils.getConnectionName(CommunicationInterfaceTab.this.fConfiguration));
                path = remoteBrowse(parent.getShell(), connection, Messages.SRMLCDT_SelectHostFileDialogTitle,
                        Constants.EMPTY_STR);
            }
            if (path != null) {
                hostFileText.setText(path);
            }

        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    this.fHostListBt = new Button(hostsGroup, SWT.RADIO);
    this.fHostListBt.setText(Messages.SRMLCDT_HostListBt);
    this.fHostListBt.setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false, 2, 1));
    this.fHostListBt.addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent event) {
            updateLaunchConfigurationDialog();
            updateSelectionState(false);
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Composite tableComposite = new Composite(hostsGroup, SWT.NONE);
    tableComposite.setFont(hostsGroup.getFont());
    final GridData tableGData = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableGData.verticalSpan = 2;
    tableGData.horizontalIndent = 30;
    tableComposite.setLayoutData(tableGData);

    final TableViewer viewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    this.fHostListViewer = viewer;
    this.fHostListViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final TableViewerColumn column = new TableViewerColumn(this.fHostListViewer, SWT.NONE);
    column.setLabelProvider(new ColumnLabelProvider() {

        public String getText(final Object element) {
            return (String) element;
        }

    });
    final TextCellEditor editor = new TextCellEditor(viewer.getTable());
    ;
    column.setEditingSupport(new EditingSupport(this.fHostListViewer) {

        protected CellEditor getCellEditor(final Object element) {
            return editor;
        }

        @SuppressWarnings("unqualified-field-access")
        protected boolean canEdit(final Object element) {
            return viewer.getTable().getSelectionIndex() < fHosts.size();
        }

        protected Object getValue(final Object element) {
            return element;
        }

        @SuppressWarnings("unqualified-field-access")
        protected void setValue(final Object element, final Object value) {
            final int index = fHosts.indexOf(element);
            fHosts.remove(element);
            fHosts.add(index, (String) value);
            viewer.refresh();

            updateLaunchConfigurationDialog();
        }

    });

    final TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableColumnLayout.setColumnData(column.getColumn(), new ColumnWeightData(100));
    tableComposite.setLayout(tableColumnLayout);

    this.fHostListViewer.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(final Viewer curViewer, final Object oldInput, final Object newInput) {
        }

        public void dispose() {
        }

        @SuppressWarnings("unqualified-field-access")
        public Object[] getElements(final Object inputElement) {
            return fHosts.toArray(new String[fHosts.size()]);
        }

    });

    this.fHostListViewer.setInput(this.fHosts);
    this.fHostListViewer.getTable().setLinesVisible(true);

    final Button addButton = new Button(hostsGroup, SWT.PUSH);
    this.fAddButton = addButton;
    addButton.setText(Messages.SRMLCDT_AddBt);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.addSelectionListener(new SelectionListener() {

        @SuppressWarnings("unqualified-field-access")
        public void widgetSelected(final SelectionEvent event) {
            fHosts.add(Constants.EMPTY_STR);
            viewer.getTable().select(viewer.getTable().getItemCount() - 1);
            viewer.add(Constants.EMPTY_STR);
            viewer.editElement(Constants.EMPTY_STR, 0);
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    final Button removeButton = new Button(hostsGroup, SWT.PUSH);
    this.fRemoveButton = removeButton;
    removeButton.setText(Messages.SRMLCDT_RemoveBt);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    removeButton.addSelectionListener(new SelectionListener() {

        @SuppressWarnings("unqualified-field-access")
        public void widgetSelected(final SelectionEvent event) {
            final Object hostName = viewer.getElementAt(viewer.getTable().getSelectionIndex());
            if (hostName != null) {
                fHosts.remove(hostName);
                viewer.remove(hostName);

                updateLaunchConfigurationDialog();
            }
        }

        public void widgetDefaultSelected(final SelectionEvent event) {
            widgetSelected(event);
        }

    });

    setControl(mainComposite);

    initState();
}