List of usage examples for org.eclipse.jface.viewers TableViewer getElementAt
public Object getElementAt(int index)
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 ww . j a v a2s. co m 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(); }