List of usage examples for org.eclipse.jface.viewers TableViewer getTable
public Table getTable()
From source file:era.foss.ui.contrib.TableViewerExtensions.java
License:Open Source License
/** * Requires a TableViewer. Will translate a MouseClick into the active column. Primary use-case: reset column value * to its default value.//w w w . ja v a 2s.co m * * @param tableViewer the table viewer */ public static void addActiveColumnDetection(final TableViewer tableViewer) { tableViewer.getTable().addMouseListener(new MouseAdapter() { public void mouseDown(MouseEvent e) { int x = 0; for (int i = 0; i < tableViewer.getTable().getColumnCount(); i++) { x += tableViewer.getTable().getColumn(i).getWidth(); if (e.x <= x) { ((IActiveColumn) tableViewer).setActiveColumn(i); break; } } } }); }
From source file:eu.geclipse.batch.ui.internal.adapters.QueueAdapter.java
License:Open Source License
/** * Add's a new Allowed Virtual Organization to a {@link TableViewer} that holds the VO's * for the {@link QueueType}. /*from w w w .j a va2s. c o m*/ * * @param tableViewer The {@link TableViewer} that contains all allowed VO's for the Queue. * @param value The VO name. */ @SuppressWarnings("unchecked") public void addAllowedVO(final TableViewer tableViewer, final Object value) { if (value == null) { return; } Collection<String> collection = new ArrayList<String>(); EList<String> newInputList = (EList<String>) tableViewer.getInput(); if (newInputList == null) { newInputList = new BasicEList<String>(); } newInputList.add((String) value); tableViewer.setInput(newInputList); for (int i = 0; i < tableViewer.getTable().getItemCount(); i++) { collection.add((String) tableViewer.getElementAt(i)); } this.allowedVOs.getVOName().clear(); this.allowedVOs.getVOName().addAll(collection); if (this.queue.getAllowedVirtualOrganizations() == null) { this.queue.setAllowedVirtualOrganizations(this.allowedVOs); } this.contentChanged(); collection = null; }
From source file:eu.geclipse.jsdl.ui.adapters.jsdl.ResourcesTypeAdapter.java
License:Open Source License
/** * //from w w w. ja v a 2 s .c o m * Method that adds a list of Candidate Hosts . * * @param tableViewer The {@link TableViewer} that will hold the Candidate Hosts. * @param value The list of Candidate Hosts. */ @SuppressWarnings("unchecked") public void addCandidateHosts(final TableViewer tableViewer, final Object[] value) { if (value == null) { return; } Collection<String> collection = new ArrayList<String>(); EList<String> newInputList = (EList<String>) tableViewer.getInput(); if (newInputList == null) { newInputList = new BasicEList<String>(); } for (int i = 0; i < value.length; i++) { newInputList.add((String) value[i]); } tableViewer.setInput(newInputList); for (int i = 0; i < tableViewer.getTable().getItemCount(); i++) { collection.add((String) tableViewer.getElementAt(i)); } checkCandidateHostsElement(); this.candidateHosts.getHostName().clear(); this.candidateHosts.getHostName().addAll(collection); this.contentChanged(); collection = null; }
From source file:eu.geclipse.jsdl.ui.adapters.jsdl.ResourcesTypeAdapter.java
License:Open Source License
/** * /* w ww . ja v a 2s.c om*/ * Method that adds a list of File Systems. * * @param tableViewer The {@link TableViewer} that will hold the File Systems. * @param value The list of File Systems. */ @SuppressWarnings("unchecked") public void addFileSystem(final TableViewer tableViewer, final Object[] value) { if (value == null) { return; } Collection<FileSystemType> collection = new ArrayList<FileSystemType>(); EList<FileSystemType> newInputList = (EList<FileSystemType>) tableViewer.getInput(); if (newInputList == null) { newInputList = new BasicEList<FileSystemType>(); } for (int i = 0; i < value.length; i++) { newInputList.add((FileSystemType) value[i]); } tableViewer.setInput(newInputList); for (int i = 0; i < tableViewer.getTable().getItemCount(); i++) { collection.add((FileSystemType) tableViewer.getElementAt(i)); } checkFileSystemElement(); this.resourcesType.getFileSystem().clear(); this.resourcesType.getFileSystem().addAll(collection); this.contentChanged(); collection = null; }
From source file:eu.hydrologis.jgrass.database.view.DatabaseView.java
License:Open Source License
private TableViewer createTableViewer(Composite connectionsListComposite) { final TableViewer connectionsViewer = new TableViewer(connectionsListComposite); Table table = connectionsViewer.getTable(); GridData tableGD = new GridData(SWT.FILL, SWT.FILL, true, true); tableGD.horizontalSpan = 2;/*w w w . j a v a 2 s . c om*/ table.setLayoutData(tableGD); connectionsViewer.setContentProvider(new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { DatabaseConnectionProperties[] array = (DatabaseConnectionProperties[]) availableDatabaseConnectionProperties .toArray(new DatabaseConnectionProperties[availableDatabaseConnectionProperties.size()]); return array; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); connectionsViewer.setLabelProvider(new LabelProvider() { public Image getImage(Object element) { if (element instanceof DatabaseConnectionProperties) { DatabaseConnectionProperties connProp = (DatabaseConnectionProperties) element; Image image = null; if (ConnectionManager.isLocal(connProp)) { if (connProp.isActive()) { image = ImageCache.getInstance().getImage(ImageCache.LOCAL_DB_ACTIVE); return image; } else { image = ImageCache.getInstance().getImage(ImageCache.LOCAL_DB); return image; } } else { if (connProp.isActive()) { image = ImageCache.getInstance().getImage(ImageCache.REMOTE_DB_ACTIVE); return image; } else { image = ImageCache.getInstance().getImage(ImageCache.REMOTE_DB); return image; } } } return null; } public String getText(Object element) { if (element instanceof DatabaseConnectionProperties) { DatabaseConnectionProperties connProp = (DatabaseConnectionProperties) element; return connProp.getTitle(); } return ""; //$NON-NLS-1$ } }); connectionsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!(event.getSelection() instanceof IStructuredSelection)) { return; } IStructuredSelection sel = (IStructuredSelection) event.getSelection(); Object selectedItem = sel.getFirstElement(); if (selectedItem == null) { // unselected, show empty panel return; } if (selectedItem instanceof DatabaseConnectionProperties) { currentSelectedConnectionProperties = (DatabaseConnectionProperties) selectedItem; DatabaseConnectionPropertiesWidget widget = widgetMap.get(currentSelectedConnectionProperties); if (widget == null) { widget = new DatabaseConnectionPropertiesWidget(DatabaseView.this); widgetMap.put(currentSelectedConnectionProperties, widget); } Control propControl = widget.getComposite(currentSelectedConnectionProperties, propertiesComposite); propertiesStackLayout.topControl = propControl; propertiesComposite.layout(true); widget.checkActivationButton(); currentSelectedConnectionPropertiesList.clear(); Object[] array = sel.toArray(); for (Object conn : array) { if (conn instanceof DatabaseConnectionProperties) { currentSelectedConnectionPropertiesList.add((DatabaseConnectionProperties) conn); } } } else { putUnselected(); } } }); return connectionsViewer; }
From source file:eu.hydrologis.jgrass.utilitylinkables.OutputTableFileWriter.java
License:Open Source License
public IValueSet safeGetValues(ITime time, String linkID) { /*/*w w w.j av a 2s . co m*/ * trigger the linked model */ IValueSet valueSet = inputLink.getSourceComponent().getValues(time, inputLink.getID()); if (valueSet instanceof ValueSet) { ValueSet values = (ValueSet) valueSet; Object numObject = values.get(0); if (numObject instanceof Number) { Number number = (Number) numObject; columns = number.intValue(); } else { columns = (int) Double.parseDouble((String) numObject); } int l = 1; final Object[][] dataToWrite = new Object[(values.getCount() - 1) / columns][columns]; for (int i = 0; i < dataToWrite.length; i++) { for (int j = 0; j < dataToWrite[0].length; j++) { dataToWrite[i][j] = values.get(l); l++; } } try { if (doConsole) { for (int i = 0; i < columns; i++) { out.print(headerSplits[i] + " \t "); //$NON-NLS-1$ } out.println(); for (int i = 0; i < dataToWrite.length; i++) { for (int j = 0; j < dataToWrite[0].length; j++) { out.print(String.valueOf(dataToWrite[i][j]) + "\t"); //$NON-NLS-1$ } out.println(); } } else if (doUiTable) { Display.getDefault().asyncExec(new Runnable() { public void run() { Shell shell2 = new Shell(Display.getDefault(), SWT.DIALOG_TRIM | SWT.RESIZE); shell2.setSize(800, 600); shell2.setLayout(new GridLayout(1, false)); final TableViewer v = new TableViewer(shell2); v.setLabelProvider(new TableLabelProvider()); v.setContentProvider(new ArrayContentProvider()); Table table = v.getTable(); table.setLayoutData(new GridData(GridData.FILL_BOTH)); table.setHeaderVisible(true); table.setLinesVisible(true); TableLayout layout = new TableLayout(); for (int i = 0; i < columns; i++) { layout.addColumnData(new ColumnWeightData(100 / columns, true)); TableColumn tmpHead = new TableColumn(table, SWT.LEFT); tmpHead.setWidth(shell2.getSize().x / columns); tmpHead.setText(headerSplits[i + 1]); } table.setLayout(layout); v.setInput(dataToWrite); v.getTable().setLinesVisible(true); shell2.open(); } }); } else { File f = new File(filePath); if (f.getParentFile() == null || !f.getParentFile().exists()) { throw new RuntimeException("The path to the output file doesn't exist: " + f.getParent()); } BufferedWriter bW = new BufferedWriter(new FileWriter(filePath)); for (int i = 0; i < columns; i++) { bW.write(headerSplits[i + 1] + " \t "); //$NON-NLS-1$ } bW.write("\n"); //$NON-NLS-1$ for (int i = 0; i < dataToWrite.length; i++) { for (int j = 0; j < dataToWrite[0].length; j++) { bW.write(String.valueOf(dataToWrite[i][j]) + "\t"); //$NON-NLS-1$ } bW.write("\n"); //$NON-NLS-1$ } bW.close(); } } catch (IOException e) { throw new RuntimeException("An error occurred in writing the output data."); } } return null; }
From source file:eu.modelwriter.marker.ui.internal.preferences.MarkerTypePreferencePage.java
License:Open Source License
@Override protected Control createContents(final Composite parent) { final Composite container = new Composite(parent, SWT.NULL); final TreeViewer treeViewer = new TreeViewer(container, SWT.BORDER); final Tree tree = treeViewer.getTree(); tree.setBounds(10, 32, 232, 280);/*from w w w . ja v a 2 s . co m*/ final MarkerTreeViewContentProvider treeViewerContentProvider = new MarkerTreeViewContentProvider(); treeViewer.setLabelProvider(new MarkerTreeViewLabelProvider()); treeViewer.setContentProvider(treeViewerContentProvider); final TableViewer tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION); this.table = tableViewer.getTable(); this.table.setBounds(254, 32, 365, 280); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); new RefColumn().addColumnTo(tableViewer); final Button btnParseAlloy = new Button(container, SWT.NONE); btnParseAlloy.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { final MessageDialog warningdialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null, "If new alloy file will be parsed , your all marker type will be lost !", MessageDialog.WARNING, new String[] { "OK", "Cancel" }, 0); if (warningdialog.open() == 1) { return; } final FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN); dialog.setFilterExtensions(new String[] { "*.mw", "*.als" }); final String result = dialog.open(); if (result == null) { return; } for (final IResource iResource : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { boolean isClosed = false; try { if (!((IProject) iResource).isOpen()) { isClosed = true; ((IProject) iResource).open(new NullProgressMonitor()); } for (final IMarker iMarker : MarkerFactory.findMarkersAsArrayList(iResource)) { if (MarkUtilities.getType(iMarker) != null) { MarkUtilities.setType(iMarker, null); } } if (isClosed == true) { ((IProject) iResource).close(new NullProgressMonitor()); } } catch (final CoreException e1) { e1.printStackTrace(); } } MarkerPage.settings.put("alloyFile", result); final AlloyParser parser = new AlloyParser(result); final ArrayList<MarkerTypeElement> roots = parser.getTypes(); final ArrayList<String> rels = parser.getRels(); final MarkerTypeElement systemRoot = new MarkerTypeElement("universe"); for (final MarkerTypeElement root : roots) { systemRoot.getChildren().add(root); } try { MarkerPage.settings.put("universe", Serialization.getInstance().toString(systemRoot)); final Object[] array = new Object[1]; array[0] = systemRoot; treeViewer.setInput(array); treeViewer.expandAll(); MarkerPage.settings.put("rels", Serialization.getInstance().toString(rels)); tableViewer.setInput(rels); // auto size columns final TableColumn[] columns = tableViewer.getTable().getColumns(); for (int i = 0; i < columns.length; i++) { columns[i].pack(); } MarkerTypePreferencePage.this.lblNewLabel.setText(result); MarkerTypePreferencePage.this.lblNewLabel.setToolTipText(result); } catch (final IOException e1) { e1.printStackTrace(); } } }); btnParseAlloy.setBounds(10, 320, 75, 25); btnParseAlloy.setText("Specification"); final Label lblMarkerTypes = new Label(container, SWT.NONE); lblMarkerTypes.setBounds(10, 10, 75, 15); lblMarkerTypes.setText("Sets"); final Label lblRelations = new Label(container, SWT.NONE); lblRelations.setBounds(254, 10, 55, 15); lblRelations.setText("Relations"); this.lblNewLabel = new Label(container, SWT.WRAP); this.lblNewLabel.setBounds(91, 325, 498, 72); if (MarkerPage.settings.get("alloyFile") != null) { this.lblNewLabel.setText(MarkerPage.settings.get("alloyFile")); } this.lblNewLabel.setToolTipText(MarkerPage.settings.get("alloyFile")); try { final String savedTree = MarkerPage.settings.get("universe"); if (savedTree != null) { final Object[] array = new Object[1]; array[0] = Serialization.getInstance().fromString(savedTree); treeViewer.setInput(array); treeViewer.expandAll(); } final String rels = MarkerPage.settings.get("rels"); if (rels != null) { tableViewer.setInput(Serialization.getInstance().fromString(rels)); // auto size columns final TableColumn[] columns = tableViewer.getTable().getColumns(); for (int i = 0; i < columns.length; i++) { columns[i].pack(); } } } catch (final IOException e1) { e1.printStackTrace(); } catch (final ClassNotFoundException e) { e.printStackTrace(); } return container; }
From source file:eu.modelwriter.marker.ui.internal.wizards.selectionwizard.SelectionWizardPage.java
License:Open Source License
/** * Create contents of the wizard./*from w w w .ja va 2 s . c o m*/ * * @param parent */ public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); setControl(container); container.setLayout(new GridLayout(1, false)); TableViewer tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION); table = tableViewer.getTable(); table.setLinesVisible(true); table.setHeaderVisible(true); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); tableViewer.setInput(candidateList); tableViewer.setLabelProvider(new MarkerColumn()); // auto size columns TableColumn[] columns = tableViewer.getTable().getColumns(); for (int i = 0; i < columns.length; i++) { columns[i].pack(); } }
From source file:eu.numberfour.n4js.ui.viewer.TableViewerBuilder.java
License:Open Source License
@Override protected TableViewer createViewer(final Composite parent, final AbstractColumnLayout columnLayout, final int style) { final TableViewer viewer = new TableViewer(parent, style); final Table table = viewer.getTable(); table.setLinesVisible(linesVisible); table.setHeaderVisible(headerVisible); int columnIndex = 0; for (final String columnLabel : columnLabels) { final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, NONE); final TableColumn column = viewerColumn.getColumn(); columnLayout.setColumnData(column, createColumnLayoutData(columnIndex)); column.setText(columnLabel);//from w w w . jav a 2 s.c o m column.setMoveable(moveable); columnIndex++; } return viewer; }
From source file:fr.irisa.triskell.kermeta.tools.wizards.Kermeta2EcoreResolveWizardPage.java
/** * /*from ww w . jav a 2 s .c om*/ * Creates the controls for the superclass name field. Expects a <code>GridLayout</code> with * at least 3 columns. * Copied from jdt plugin sources and adapted. * @param composite the parent composite * @param nColumns number of columns to span * */ protected void createRequiredEcoreFileList(Composite composite, int nColumns) { final String INTERFACE = "interface"; //$NON-NLS-1$ // Create the field table where ecore file list will be put. createEcoreFileField(); requiredEcoreFileDialogField.doFillIntoGrid(composite, nColumns); final TableViewer tableViewer = requiredEcoreFileDialogField.getTableViewer(); tableViewer.setColumnProperties(new String[] { INTERFACE }); TableTextCellEditor cellEditor = new TableTextCellEditor(tableViewer, 0) { protected void doSetFocus() { if (text != null) { text.setFocus(); text.setSelection(text.getText().length()); checkSelection(); checkDeleteable(); checkSelectable(); } } }; tableViewer.setCellEditors(new CellEditor[] { cellEditor }); tableViewer.setCellModifier(new ICellModifier() { public void modify(Object element, String property, Object value) { if (element instanceof Item) element = ((Item) element).getData(); requiredEcoreFileDialogField.elementChanged(element); } public Object getValue(Object element, String property) { return element.toString(); } public boolean canModify(Object element, String property) { return true; } }); tableViewer.getTable().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent event) { if (event.keyCode == SWT.F2 && event.stateMask == 0) { ISelection selection = tableViewer.getSelection(); if (!(selection instanceof IStructuredSelection)) return; IStructuredSelection structuredSelection = (IStructuredSelection) selection; tableViewer.editElement(structuredSelection.getFirstElement(), 0); } } }); GridData gd = (GridData) requiredEcoreFileDialogField.getListControl(null).getLayoutData(); gd.grabExcessVerticalSpace = false; //gd.widthHint= GridData.FILL_HORIZONTAL; }