List of usage examples for org.eclipse.jface.viewers TableViewer getElementAt
public Object getElementAt(int index)
From source file:org.emftrace.quarc.ui.views.PropertiesView.java
License:Open Source License
/** * @param tableViewer a TableViewer// w w w .jav a 2 s .co m * @return the selected Element of the TableViewer */ protected Element getSelectedElement(TableViewer tableViewer) { Element result = null; if (tableViewer.getTable().getSelectionIndex() != -1) result = (Element) tableViewer.getElementAt(tableViewer.getTable().getSelectionIndex()); return result; }
From source file:org.emftrace.quarc.ui.views.PropertiesView.java
License:Open Source License
/** * @param tableViewer a TableViewer//w w w. j a va 2 s . co m * @return a List with all checked Elements of the TableViewer */ protected List<Element> getCheckedElements(TableViewer tableViewer) { List<Element> result = new ArrayList<Element>(); for (int index = 0; index < tableViewer.getTable().getItems().length; index++) { TableItem item = tableViewer.getTable().getItem(index); if (item.getChecked()) { result.add((Element) tableViewer.getElementAt(index)); } } return result; }
From source file:org.fusesource.ide.zk.zookeeper.editors.znodetable.ZnodeModelTableEditor.java
License:Apache License
@Override protected void configureTable(Table table) { table.setLinesVisible(true);/*from w ww . j av a 2 s .co m*/ ZnodeModelElementType znodeModelElementType = (ZnodeModelElementType) getModelElementType(); int dataColumnIndex = znodeModelElementType.getColumnIndex(ZnodeModelElementType.COLUMN_TITLE_DATA); CommitEditRunnable commitEditRunnable = new CommitEditRunnable() { @Override public void run() { TableViewer tableViewer = getTableViewer(); TableItem row = getRow(); String newValue = getNewValue(); Table table = tableViewer.getTable(); int rowIndex = table.indexOf(row); final ZnodeModel znodeModel = (ZnodeModel) tableViewer.getElementAt(rowIndex); Znode znode = znodeModel.getData(); byte[] data = null; if (newValue != null && !newValue.isEmpty()) { // TODO: Need to support other Charsets? data = newValue.getBytes(); } znode.setData(data); znodeModel.setDirtyData(true); try { znodeModel.updateData(); } catch (Exception e) { setError(e); } } }; new TableEdit(table, commitEditRunnable, dataColumnIndex); }
From source file:org.fusesource.tools.messaging.ui.SimpleMessageEditorExtension.java
License:Open Source License
/** * /*from w ww . ja v a2 s. c o m*/ * @param tableViewer * @param buttonComposite */ protected void propertyOperations(final TableViewer tableViewer, Composite buttonComposite) { GridData data; final Button addProperty = new Button(buttonComposite, SWT.PUSH); addProperty.setText(" Add "); data = new GridData(); data.horizontalSpan = 1; data.verticalAlignment = SWT.TOP; addProperty.setLayoutData(data); final Button deleteProperty = new Button(buttonComposite, SWT.PUSH); deleteProperty.setText("Delete"); data = new GridData(); data.verticalAlignment = SWT.TOP; data.horizontalSpan = 1; deleteProperty.setLayoutData(data); addProperty.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (event.widget == addProperty) { createNewDefaultHeader(getMessageModel().getProperties()); tableViewer.refresh(); propertiesTableViewer.refresh(); } } }); deleteProperty.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (event.widget == deleteProperty) { int selectionIndex = tableViewer.getTable().getSelectionIndex(); Object elementAt = tableViewer.getElementAt(selectionIndex); if (elementAt instanceof Property) { Property property = (Property) elementAt; deleteProperty(property); tableViewer.refresh(); } } } }); }
From source file:org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsKeysListPage.java
License:Open Source License
private void markAllDuplicatedKeys(TableViewer tv) { for (int i = 0; i < tv.getTable().getItemCount(); i++) { KeyValueElement k = (KeyValueElement) tv.getElementAt(i); if (isDuplicatedBundleKey(k.key)) { k.duplicated = true;/*from ww w . j av a 2 s .c o m*/ } } }
From source file:org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsKeysListPage.java
License:Open Source License
private void highlightAllDuplicateKeys(TableViewer tv) { for (int i = 0; i < tv.getTable().getItemCount(); i++) { highlightDuplicateKey(tv.getTable().getItem(i), ((KeyValueElement) tv.getElementAt(i)).duplicated); }// w w w .j a v a 2 s . c o m }
From source file:org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsKeysListPage.java
License:Open Source License
private void attachCellEditors(final TableViewer viewer, Composite parent) { viewer.setCellModifier(new ICellModifier() { public boolean canModify(Object element, String property) { return true; }// ww w . ja v a2 s .c o m public Object getValue(Object element, String property) { if (KEY_PROPERTY.equals(property)) { return ((KeyValueElement) element).key; } else { return ((KeyValueElement) element).value; } } public void modify(Object element, String property, Object value) { TableItem tableItem = (TableItem) element; KeyValueElement kve = (KeyValueElement) tableItem.getData(); if (KEY_PROPERTY.equals(property)) { kve.key = value.toString(); } else { kve.value = value.toString(); } viewer.refresh(kve); /* * Mark/unmark all duplicated keys with red/white. * Change the dialog status. */ for (KeyValueElement k : initKeys) { if (isDuplicatedBundleKey(k.key) || isDuplicatedStringKey(k, k.key)) { k.duplicated = true; } else { k.duplicated = false; } } highlightAllDuplicateKeys(viewer); updateStatus(); } }); TextCellEditor keyEditor = new TextCellEditor(parent); /* * TODO: cell validator should be added after bug * https://bugs.eclipse.org/bugs/show_bug.cgi?id=130854 * is fixed. */ // keyEditor.setValidator(new ICellEditorValidator() { // @Override // public String isValid(Object value) { // return null; // } // }); ((Text) keyEditor.getControl()).addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { Text t = (Text) e.getSource(); String key = t.getText(); Table table = (Table) t.getParent(); int ind = table.getSelectionIndex(); KeyValueElement element = (KeyValueElement) viewer.getElementAt(ind); /* * Check duplicate key, set bkg color to red * Setting new key value is called after this modyfy listener, * thus pass new key value manually. */ if (isDuplicatedBundleKey(key) || isDuplicatedStringKey(element, key)) { element.duplicated = true; t.setBackground(red); } else { element.duplicated = false; t.setBackground(white); } } }); ((Text) keyEditor.getControl()).addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent e) { for (int i = 0; i < ExternalizeStringsUtils.REPLACED_CHARACTERS.length; i++) { /* * Entering of the forbidden characters will be prevented. */ if (e.character == ExternalizeStringsUtils.REPLACED_CHARACTERS[i]) { e.doit = false; break; } } } }); viewer.setCellEditors(new CellEditor[] { keyEditor, null }); viewer.setColumnProperties(new String[] { KEY_PROPERTY, VALUE_PROPERTY }); }
From source file:org.modelio.mda.infra.catalog.update.ModuleUpdateBrowserDialog.java
License:Open Source License
@objid("67e6c5f5-995f-4cb8-9b21-0337980af059") @Override//from www . j ava2s. c o m public Control createContentArea(Composite parent) { Composite compo = new Composite(parent, SWT.NONE); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); layoutData.minimumHeight = 150; compo.setLayoutData(layoutData); compo.setLayout(new GridLayout(2, false)); Composite leftComposite = new Composite(compo, SWT.NONE); leftComposite.setLayout(new GridLayout(1, false)); leftComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true)); // Define the TableViewer final TableViewer moduleTableViewer = new TableViewer(leftComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); final Table moduleTable = moduleTableViewer.getTable(); moduleTable.setHeaderVisible(true); moduleTable.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true)); // Create the columns createColumns(moduleTableViewer); // Set the ContentProvider moduleTableViewer.setContentProvider(ArrayContentProvider.getInstance()); moduleTableViewer.setInput(this.modulesToUpdate); for (int i = 0; i < moduleTable.getColumnCount(); i++) { TableColumn col = moduleTable.getColumn(i); col.pack(); // The column with an icon isn't resized well after pack, we need to add the image width if (i == 4) { final int width = col.getWidth(); col.setWidth(width + 50); } } moduleTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1) { Object obj = structuredSelection.getFirstElement(); if (obj instanceof ModuleUpdateDescriptor) { String url = ((ModuleUpdateDescriptor) obj).getLink(); ModuleUpdateBrowserDialog.this.browser.setUrl(url); } } } } }); Composite buttonComposite = new Composite(leftComposite, SWT.NONE); buttonComposite.setLayoutData(new GridData(SWT.END, SWT.END, false, false)); buttonComposite.setLayout(new GridLayout(2, false)); // Select all button Button selectAllButton = new Button(buttonComposite, SWT.PUSH); selectAllButton.setText(MdaInfra.I18N.getString("ModuleUpdateBrowserDialog.SelectAll")); selectAllButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { for (ModuleUpdateDescriptor moduleDescriptor : ModuleUpdateBrowserDialog.this.modulesToUpdate) { moduleDescriptor.setToUpdate(true); } moduleTableViewer.setInput(ModuleUpdateBrowserDialog.this.modulesToUpdate); } @Override public void widgetDefaultSelected(SelectionEvent e) { // } }); selectAllButton.setLayoutData(new GridData()); // Unselect all button Button unselectAllButton = new Button(buttonComposite, SWT.PUSH); unselectAllButton.setText(MdaInfra.I18N.getString("ModuleUpdateBrowserDialog.UnselectAll")); unselectAllButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { for (ModuleUpdateDescriptor moduleDescriptor : ModuleUpdateBrowserDialog.this.modulesToUpdate) { moduleDescriptor.setToUpdate(false); } moduleTableViewer.setInput(ModuleUpdateBrowserDialog.this.modulesToUpdate); } @Override public void widgetDefaultSelected(SelectionEvent e) { // } }); unselectAllButton.setLayoutData(new GridData()); this.browser = new Browser(compo, SWT.NONE); this.browser.setText(""); final GridData browserLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true); browserLayoutData.widthHint = 300; this.browser.setLayoutData(browserLayoutData); moduleTableViewer.setSelection(new StructuredSelection(moduleTableViewer.getElementAt(0))); return null; }
From source file:org.nuxeo.ide.sdk.userlibs.UserLibPreferencePage.java
License:Open Source License
protected void removeLib(UserLib lib) { TableViewer tv = getTable().getTableViewer(); prefs.removeUserLib(lib);/* ww w . j a va 2 s . c o m*/ int i = tv.getTable().getSelectionIndex(); tv.remove(lib); UserLib slib = null; if (i == 0) { slib = (UserLib) tv.getElementAt(0); } else if (i > 0) { slib = (UserLib) tv.getElementAt(i - 1); } if (slib != null) { tv.setSelection(new StructuredSelection(slib)); } }
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 a v a 2 s .c o 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(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); }