private static void createColumns(final TableViewer viewer) { // First column is the widget name TableViewerColumn col = createTableViewerColumn(viewer, "Widget", 150); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { NebulaWidget w = (NebulaWidget) element; return w.getName(); } }); col.getColumn().addSelectionListener(new SortTableColumnSelectionListener("name")); // Second column is the committer col = createTableViewerColumn(viewer, "Commiter", 150); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { NebulaWidget w = (NebulaWidget) element; Person p = w.getCommitter(); return p.getFirstName() + " " + p.getLastName(); } }); col.getColumn() .addSelectionListener(new SortTableColumnSelectionListener("committer.firstName")); }
private TableViewer createPropertiesSection(Composite parent) { TableViewer viewer = new TableViewer( parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); Table table = viewer.getTable(); setLayout(table); table.setHeaderVisible(true); table.setLinesVisible(true); table.setFont(parent.getFont()); TableViewerColumn nameColumn = new TableViewerColumn(viewer, SWT.NONE); nameColumn.setLabelProvider(new NameLabelProvider()); nameColumn.getColumn().setText("Name"); nameColumn.getColumn().setResizable(true); nameColumn.getColumn().setMoveable(true); TableViewerColumn valueColumn = new TableViewerColumn(viewer, SWT.NONE); valueColumn.setLabelProvider(new ValueLabelProvider()); valueColumn.getColumn().setText("Value"); valueColumn.getColumn().setResizable(true); valueColumn.getColumn().setMoveable(true); valueColumn.setEditingSupport(new RedDeerEditingSupport(viewer)); viewer.setContentProvider(new ArrayContentProvider()); return viewer; }
private void createPatientColumns(TableViewer viewer) { // clear columns Table table = viewer.getTable(); table.setRedraw(false); while (table.getColumnCount() > 0) { table.getColumns()[0].dispose(); } TableViewerColumn nameColumn = new TableViewerColumn(viewer, SWT.NONE); nameColumn.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { return ((IPatient) element).getName(); } }); nameColumn.getColumn().setText("Name"); nameColumn.getColumn().setWidth(150); TableViewerColumn idColumn = new TableViewerColumn(viewer, SWT.NONE); idColumn.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { return ((IPatient) element).getId(); } }); idColumn.getColumn().setWidth(150); idColumn.getColumn().setText("Id"); table.setRedraw(true); }
// This will create the columns for the table private void createColumnsResults(final Composite parent, final TableViewer viewer) { String[] titles = {"Analysis type", "Result"}; int[] bounds = {100, 100}; // First column is for the first name TableViewerColumn col = createTableViewerColumn(viewer, titles[0], bounds[0], 0); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { String res = "unknown"; if (element instanceof ResultAnalysis) { res = ((ResultAnalysis) element).getName(); } return res; } }); // Second column is for the last name col = createTableViewerColumn(viewer, titles[1], bounds[1], 1); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { String res = "unknown"; if (element instanceof ResultAnalysis) { Object verdict = ((ResultAnalysis) element).getResult(); if (verdict != null) { res = verdict.toString(); } } return res; } }); }
/** * Creates the table layout * * @param viewer */ public void createColumns(final TableViewer viewer) { TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setWidth(300); column .getColumn() .setText(Messages.getString("PatientIdDialog.column_header.type")); // $NON-NLS-1$ column.getColumn().setMoveable(true); column.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { PatientIdentifier content = (PatientIdentifier) element; return content.getType().getName(); } }); TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE); column1.getColumn().setWidth(200); column1 .getColumn() .setText(Messages.getString("PatientIdDialog.column_header.number")); // $NON-NLS-1$ column1.getColumn().setMoveable(true); column1.setEditingSupport(new PatientIdentifierEditingSupport(viewer)); column1.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { PatientIdentifier content = (PatientIdentifier) element; return content.getValueEdit(); } }); }
/** * Adds columns to the provided <code>TableViewer</code>. * * @param tableViewer */ protected void addTableViewerColumns(TableViewer tableViewer) { if (tableViewer != null) { TableColumn column; ICellContentProvider contentProvider; // ---- Create the name column. ---- // nameColumn = new TableViewerColumn(tableViewer, SWT.LEFT); column = nameColumn.getColumn(); column.setText("Name"); column.setToolTipText("The name of the property"); column.setResizable(true); // Create an ICellContentProvider, then use it to generate the // column labels and provide editing support for the name column. contentProvider = new NameCellContentProvider() { @Override public boolean setValue(Object element, Object value) { boolean changed = super.setValue(element, value); // If the value changed, mark the associated ICEFormEditor // as dirty. if (changed && editor != null) { editor.setDirty(true); } return changed; } }; nameColumn.setLabelProvider(new CellColumnLabelProvider(contentProvider)); nameColumn.setEditingSupport(new TextCellEditingSupport(tableViewer, contentProvider)); // --------------------------------- // // ---- Create the value column. ---- // valueColumn = new TableViewerColumn(tableViewer, SWT.LEFT); column = valueColumn.getColumn(); column.setText("Value"); column.setToolTipText("The value of the property"); column.setResizable(true); // Create an ICellContentProvider, then use it to generate the // column labels and provide editing support for the value column. contentProvider = new ValueCellContentProvider() { @Override public boolean setValue(Object element, Object value) { boolean changed = super.setValue(element, value); // If the value changed, mark the associated ICEFormEditor // as dirty. if (changed && editor != null) { editor.setDirty(true); } return changed; } }; valueColumn.setLabelProvider(new CellColumnLabelProvider(contentProvider)); valueColumn.setEditingSupport( new ComboCellEditingSupport(tableViewer, (IComboCellContentProvider) contentProvider)); // ---------------------------------- // } return; }
private void createColumns(final Composite parent, final TableViewer viewer) { String[] titles = {"Id", "Name", "Status", "Due date", "Info"}; int[] bounds = {50, 200, 100, 100, 200}; TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { Task t = (Task) element; return t.getId().toString(); } }); col = createTableViewerColumn(titles[1], bounds[1], 1); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { Task t = (Task) element; return t.getName(); } }); col = createTableViewerColumn(titles[2], bounds[2], 2); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { Task t = (Task) element; return t.getStatus(); } }); col = createTableViewerColumn(titles[3], bounds[3], 3); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { Task t = (Task) element; return t.getDate(); } }); col = createTableViewerColumn(titles[4], bounds[4], 4); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { Task t = (Task) element; return t.getInfo(); } }); }
@Override protected void setColumnsWidth(String[] columnProperties) { for (int i = 0; i < columnProperties.length; i++) { String fieldName = getColumnFieldNames()[i]; TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE); tvc.setLabelProvider(new TableLabelProviderEditable(getColumnFieldNames()[i])); TableColumn tableColumn = tvc.getColumn(); tableColumn.setText(columnProperties[i]); tableColumn.setAlignment(SWT.LEFT); if (fieldName.equals("b.pd_code")) { tableColumn.setWidth(0); } else if (fieldName.equals("b.dp_code")) { tableColumn.setWidth(0); } else if (fieldName.equals("c.name")) { tableColumn.setWidth(250); } else if (fieldName.equals("b.dp_name")) { tableColumn.setWidth(250); } else if (fieldName.equals("a.write_date")) { tableColumn.setWidth(80); } else if (fieldName.equals("a.content")) { tableColumn.setWidth(450); } else if (fieldName.equals("a.deal_date")) { tableColumn.setWidth(80); } else if (fieldName.equals("a.deal_status")) { tableColumn.setWidth(80); // tvc.setEditingSupport(new EditorSupportIntenal(viewer, // columnFieldNames[i], this.getColumnStyleMap())); } else if (fieldName.equals("a.mark")) { tableColumn.setWidth(300); } else { tableColumn.setWidth(30); } } }
private void createHeaderTableColumns(TableViewer viewer, TableColumnLayout layout) { final String[] titles = { "Name", "Value", }; final ColumnLayoutData[] layoutData = { new ColumnPixelData(120, true, true), new ColumnWeightData(100, 100, true), }; final EditingSupport editorList[] = { new HeaderNameEditingSupport(viewer), new HeaderValueEditingSupport(viewer), }; final ColumnLabelProvider providerList[] = { new ColumnLabelProvider() { @Override public String getText(Object element) { return ((IHttpHeaderBuilder) element).getName(); } }, new ColumnLabelProvider() { @Override public String getText(Object element) { return ((IHttpHeaderBuilder) element).getValue(); } }, }; for (int i = 0; i < titles.length; i++) { final TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); final TableColumn c = column.getColumn(); layout.setColumnData(c, layoutData[i]); c.setText(titles[i]); c.setMoveable(true); column.setEditingSupport(editorList[i]); column.setLabelProvider(providerList[i]); } }
private void createColumns() { List<Column> modelColumns = project.getTextTable().getColumns(); for (int i = 0; i < modelColumns.size(); i++) { final int columnIndex = i; TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE); col.getColumn().setWidth(50); col.getColumn().setText(project.getTextTable().getColumns().get(i).getName()); col.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { Line line = (Line) element; return line.getFragmentAt(columnIndex).getText(); } }); col.getColumn().setMoveable(true); col.getColumn() .addListener( SWT.Move, new Listener() { public void handleEvent(Event event) { int[] columnsOrder = table.getColumnOrder(); boolean moved = previewsColumnOrder.move(columnsOrder); if (moved) { moveDataColumn( previewsColumnOrder.getMovedFrom(), previewsColumnOrder.getMovedTo()); } } }); } }
private void setLabelAndTooltipProviders( final IColumnLabelProvider<E> labelProvider, final CellLabelProvider cellLabelProvider, final ICellToolTipProvider<E> tooltipProvider, TableViewerColumn column) { Assert.isLegal( (cellLabelProvider != null && tooltipProvider == null) || cellLabelProvider == null, "cannot use ITooltipProvider with CellLabelProvider"); if (labelProvider != null) { column.setLabelProvider( new CellLabelProvider() { @SuppressWarnings("unchecked") @Override public void update(ViewerCell cell) { if (labelProvider != null) { String cellValue = labelProvider.getValue((E) cell.getElement()); cell.setText(cellValue); boolean italic = labelProvider.isModified((E) cell.getElement()); applyFont(cell, italic); } } @SuppressWarnings("unchecked") @Override public String getToolTipText(Object object) { if (tooltipProvider != null) { return tooltipProvider.getToolTipText((E) object); } else { return super.getToolTipText(object); } }; @SuppressWarnings("unchecked") @Override public int getToolTipDisplayDelayTime(Object element) { if (tooltipProvider != null) { return tooltipProvider.getToolTipDisplayDelayTime((E) element); } else { return super.getToolTipDisplayDelayTime(element); } } }); } else if (cellLabelProvider != null) { column.setLabelProvider(cellLabelProvider); } }
private void configureColumn( TableViewerColumn viewerColumn, int columnIndex, String headerText, boolean resizable) { viewerColumn.setLabelProvider(new MedLabelProvider(columnIndex)); TableColumn column = viewerColumn.getColumn(); column.setText(headerText); column.setMoveable(false); column.setResizable(resizable); }
private void createTableColumn( TableViewer target, String title, int size, ActivityCellLabelProvider provider) { TableViewerColumn viewerNameColumn = new TableViewerColumn(target, SWT.NONE); viewerNameColumn.getColumn().setText(title); viewerNameColumn.getColumn().setWidth(size); viewerNameColumn.getColumn().setResizable(true); viewerNameColumn.getColumn().setMoveable(true); viewerNameColumn.setLabelProvider(provider); }
private void createColumns(final TableViewer viewer) { ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE); TableViewerColumn var = new TableViewerColumn(viewer, SWT.LEFT, 0); var.getColumn().setText("Name"); var.getColumn().setWidth(80); var.setLabelProvider(new VariableLabelProvider(0)); }
public DirectoryPathsEditor(Composite parent, IProject project, PluginImageHelper imageHelper) { super(parent, SWT.NONE); this.project = project; // generated by WindowBuilder setLayout(new GridLayout(2, false)); tblVwrDirectoryPaths = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); tblVwrDirectoryPaths.setLabelProvider(new RichLabelProvider(imageHelper)); tblVwrDirectoryPaths.setContentProvider(ArrayContentProvider.getInstance()); tblDirectoryPaths = tblVwrDirectoryPaths.getTable(); tblDirectoryPaths.setHeaderVisible(true); tblDirectoryPaths.setLinesVisible(true); tblDirectoryPaths.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); TableViewerColumn tblclmnVwrPath = new TableViewerColumn(tblVwrDirectoryPaths, SWT.NONE); TableColumn tblclmnPath = tblclmnVwrPath.getColumn(); tblclmnPath.setWidth(290); tblclmnPath.setResizable(true); tblclmnPath.setText(directories); tblclmnVwrPath.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { return element.toString(); } }); Composite composite = new Composite(this, SWT.NONE); composite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1)); composite.setLayout(new GridLayout(1, false)); btnAdd = new Button(composite, SWT.NONE); btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnAdd.setText(add); btnRemove = new Button(composite, SWT.NONE); btnRemove.setEnabled(false); btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnRemove.setText(remove); new Label(composite, SWT.NONE); btnUp = new Button(composite, SWT.NONE); btnUp.setEnabled(false); btnUp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnUp.setText(up); btnDown = new Button(composite, SWT.NONE); btnDown.setEnabled(false); btnDown.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnDown.setText(down); addEventListeners(); }
protected void createMainColumn() { TableViewerColumn c = createTableViewerColumn("Service", 200, SWT.LEFT, false); ColumnLabelProvider labelProvider = new ColumnLabelProvider() { public String getText(Object element) { if (element instanceof ServiceSummary) { return TextProxy.service.getText(((ServiceSummary) element).hash); } return null; } }; c.setLabelProvider(labelProvider); }
@PostConstruct public void postConstruct(Composite parent) { devicesGroupsView = partService.findPart("dec-rcp.part.devices.groups"); devicesView = partService.findPart("dec-rcp.part.devices.list"); sensorsView = partService.findPart("dec-rcp.part.devices.sensors"); FilterMatcher matcher = new FilterMatcher(); FilteredTable table = new FilteredTable( parent, SWT.SINGLE | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION, matcher, true); viewer = table.getViewer(); viewer.setContentProvider(ArrayContentProvider.getInstance()); viewer .getTable() .addSelectionListener( new SensorsViewerSelectionListener( viewer, devicesGroupsView, devicesView, sensorsView, partService, selectionService, context)); TableViewerColumn idColumnViewer = new TableViewerColumn(viewer, SWT.NONE); idColumnViewer.getColumn().setWidth(50); idColumnViewer.getColumn().setText("#"); idColumnViewer.setLabelProvider(new IDColumnLabelProvider(viewer)); TableViewerColumn deviceGroupsNameColumnViewer = new TableViewerColumn(viewer, SWT.NONE); deviceGroupsNameColumnViewer.getColumn().setWidth(800); deviceGroupsNameColumnViewer.getColumn().setText("Sensor Name"); deviceGroupsNameColumnViewer.setLabelProvider(new NameColumnLabelProvider(viewer)); viewer.getTable().setHeaderVisible(true); }
private void addColumnsExceptionTable(TableViewer viewer, TableColumnLayout layout) { TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText(Messages.ColumnErrorMessages); column.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { Exception e = (Exception) element; String text = e.getMessage(); return text == null || text.isEmpty() ? e.getClass().getName() : text; } }); layout.setColumnData(column.getColumn(), new ColumnWeightData(100, true)); }
private void createTableColumn( String name, int weight, int alignment, CellLabelProvider cellLabelProvider, TableViewer viewer, TableColumnLayout layout) { TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT); column.getColumn().setText(name); column.getColumn().setAlignment(alignment); if (cellLabelProvider != null) { column.setLabelProvider(cellLabelProvider); } layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true)); }
private void createFilesAddedView(FormToolkit toolkit, Composite parent) { Section section = toolkit.createSection(parent, Section.TITLE_BAR | Section.DESCRIPTION); section.setText("Files selected"); section.setDescription("Double click to remove from current project"); Composite client = toolkit.createComposite(section, SWT.WRAP); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginWidth = 2; layout.marginHeight = 2; client.setLayout(layout); Table t = toolkit.createTable(client, SWT.NULL); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 20; gd.widthHint = 200; t.setLayoutData(gd); toolkit.paintBordersFor(client); section.setClient(client); table = new TableViewer(t); ArrayContentProvider tmp = new ArrayContentProvider(); table.setContentProvider(tmp); TableViewerColumn viewerColumn = new TableViewerColumn(table, SWT.LEFT); viewerColumn.getColumn().setWidth(300); viewerColumn.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { return element.toString(); }; public Image getImage(Object element) { return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE); }; }); hookContextMenu2(); hookDoubleClickAction2(); }
/** * Create a column for the table * * @param name the name of the column (must be unique) * @param provider the provider of the column * @param viewerComparator the comparator associated with clicking on the column, if it is null, a * string comparator will be used */ protected final void createColumn( String name, ColumnLabelProvider provider, ViewerCompoundComparator viewerComparator) { if (fComparators.containsKey(name)) { throw new IllegalArgumentException( "Cannot have two columns with the same name"); //$NON-NLS-1$ } TableViewerColumn col = new TableViewerColumn(fTableViewer, SWT.NONE); col.setLabelProvider(provider); final TableColumn column = col.getColumn(); column.setWidth(DEFAULT_COL_WIDTH); column.setText(name); column.setResizable(true); column.setMoveable(true); column.addSelectionListener(new ColumnSorter(column)); final ViewerCompoundComparator comparator = (viewerComparator == null) ? ViewerCompoundComparator.STRING_COMPARATOR : viewerComparator; fComparators.put(name, comparator); }
private void createColumns(TableViewer viewer) { for (int i = 0; i < fColumnLabels.length; i++) { TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); viewerColumn.setLabelProvider(new CSearchListLabelProvider(this, i)); TableColumn tableColumn = viewerColumn.getColumn(); tableColumn.setText(fColumnLabels[i]); tableColumn.setWidth(fColumnWidths[i]); tableColumn.setResizable(true); tableColumn.setMoveable(false); if (i == DEFINITION_COLUMN_INDEX && !fShowEnclosingDefinitions) { tableColumn.setWidth(0); tableColumn.setResizable(false); } } Table table = viewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); }
private void createDependencyViewer(Composite parent) { dependencyViewer = new TableViewer( parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 80; dependencyViewer.getTable().setLayoutData(gd); // viewer.setLabelProvider(new TableLabelProvider()); dependencyViewer.setContentProvider(new TableContentProvider()); Table table = dependencyViewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); table.setFont(parent.getFont()); String[] columnHeaders = { Messages.MavenUserLibraryProviderInstallPanel_GroupId, Messages.MavenUserLibraryProviderInstallPanel_ArtifactId, Messages.MavenUserLibraryProviderInstallPanel_Version, Messages.MavenUserLibraryProviderInstallPanel_Scope, Messages.MavenUserLibraryProviderInstallPanel_Type }; for (int i = 0; i < columnHeaders.length; i++) { TableViewerColumn column = new TableViewerColumn(dependencyViewer, SWT.NONE); column.setLabelProvider(new DependencyColumnLabelProvider(i)); column.getColumn().setText(columnHeaders[i]); column.getColumn().setResizable(true); column.getColumn().setMoveable(true); column.setEditingSupport(new DependencyEditingSupport(dependencyViewer, i)); } TableLayout layout = new AutoResizeTableLayout(table); for (int i = 0; i < dependencyTableColumnLayouts.length; i++) { layout.addColumnData(dependencyTableColumnLayouts[i]); } dependencyViewer.getTable().setLayout(layout); dependencyViewer.setInput(dependencies); createDependencyButtons(parent); }
public Snippet034CellEditorPerRowNewAPI(Shell shell) { final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); final TableViewer v = new TableViewer(table); v.getTable().setLinesVisible(true); TableViewerColumn column = new TableViewerColumn(v, SWT.NONE); column.getColumn().setWidth(200); column.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { return element.toString(); } }); column.setEditingSupport(new MyEditingSupport(v)); v.setContentProvider(new MyContentProvider()); MyModel[] model = createModel(); v.setInput(model); }
private TableViewerColumn createTableViewerColumn( TableViewer viewer, final ICellModifier modifier, final String property, String title, String tooltip) { final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.FILL); viewerColumn.setLabelProvider( new CellLabelProvider() { @Override public void update(ViewerCell cell) { Object value = modifier.getValue(cell.getElement(), property); cell.setText(Strings.getOrElse(value)); } }); final TableColumn column = viewerColumn.getColumn(); column.setText(title); column.setWidth(100); column.setResizable(true); column.setMoveable(false); column.setToolTipText(tooltip); return viewerColumn; }
@Override public TabItem doCreateForm( TabFolder folder, EditingDomain domain, DataBindingContext dbc, IObservableValue master) { TabItem item = new TabItem(folder, SWT.NONE); IValueProperty textProp = WidgetProperties.text(); dbc.bindValue( textProp.observe(item), EMFEditObservables.observeDetailValue( Realm.getDefault(), domain, master, EXTLibraryPackage.Literals.LIBRARY__WRITERS), new UpdateValueStrategy(), new UpdateValueStrategy().setConverter(new LengthConverter())); Composite comp = new Composite(folder, SWT.NONE); TableColumnLayout layout = new TableColumnLayout(); comp.setLayout(layout); TableViewer writerViewer = new TableViewer( comp, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); writerViewer.getTable().setHeaderVisible(true); writerViewer.getTable().setLinesVisible(true); ObservableListContentProvider cp = new ObservableListContentProvider(); writerViewer.setContentProvider(cp); CondiditionalTemplate[] tpl = new CondiditionalTemplate[3]; tpl[0] = new CondiditionalTemplate("${0}") { @Override public boolean isTemplate(EObject element) { return element instanceof Writer && ((Writer) element).getFirstName() != null; } }; tpl[1] = new CondiditionalTemplate("${0}") { @Override public boolean isTemplate(EObject element) { return element instanceof Writer && ((Writer) element).getLastName() != null; } }; tpl[2] = new CondiditionalTemplate("-") { @Override public boolean isTemplate(EObject element) { return true; } }; EStructuralFeature[] features = new EStructuralFeature[3]; features[0] = EXTLibraryPackage.Literals.PERSON__FIRST_NAME; features[1] = EXTLibraryPackage.Literals.PERSON__LAST_NAME; IObservableMap[] map = EMFEditObservables.observeMaps(domain, cp.getKnownElements(), features); TableViewerColumn c = new TableViewerColumn(writerViewer, SWT.NONE); c.getColumn().setText("Firstname"); layout.setColumnData(c.getColumn(), new ColumnWeightData(1, 120)); c.setLabelProvider( new ObservableColumnLabelProvider( new IObservableMap[] {map[0]}, Arrays.asList(tpl[0], tpl[2]))); c = new TableViewerColumn(writerViewer, SWT.NONE); c.getColumn().setText("Lastname"); layout.setColumnData(c.getColumn(), new ColumnWeightData(1, 120)); c.setLabelProvider( new ObservableColumnLabelProvider( new IObservableMap[] {map[1]}, Arrays.asList(tpl[1], tpl[2]))); MenuManager mgr = new MenuManager(); writerViewer.getControl().setMenu(mgr.createContextMenu(writerViewer.getControl())); getSite() .registerContextMenu( "org.eclipse.emf.examples.library.databinding.writer", mgr, writerViewer); writerViewer.setInput( EMFEditObservables.observeDetailList( Realm.getDefault(), domain, master, EXTLibraryPackage.Literals.LIBRARY__WRITERS)); item.setControl(comp); return item; }
private void createTable(Composite parent) { final int gdHeightSubtrahend = 100; final int iconRowSize = 10; int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; style = style | SWT.SINGLE | SWT.FULL_SELECTION; viewer = new TableViewer(parent, style); viewer.setContentProvider(new ArrayContentProvider()); TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer)); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) { @Override protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { boolean retVal = event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION; retVal = retVal || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR); return retVal || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; } }; TableViewerEditor.create( viewer, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); Table table = viewer.getTable(); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = SIZE_X - gdHeightSubtrahend; table.setLayoutData(gd); table.addListener( SWT.MeasureItem, new Listener() { @Override public void handleEvent(Event event) { // height cannot be per row so simply set event.height = getThumbnailSize() + ICON_SPACING; } }); table.addMouseListener( new MouseListener() { @Override public void mouseUp(MouseEvent e) {} @Override public void mouseDown(MouseEvent e) { ViewerCell cell = viewer.getCell(new Point(e.x, e.y)); if (cell != null) { selectedPath = getRelativePath( ((IconDescriptor[]) cell.getElement())[cell.getColumnIndex()].getPath()); if (LOG.isDebugEnabled()) { LOG.debug("Icon: " + selectedPath); // $NON-NLS-1$ } } } @Override public void mouseDoubleClick(MouseEvent e) {} }); for (int i = 0; i < iconRowSize; i++) { TableViewerColumn imageColumn = new TableViewerColumn(viewer, SWT.LEFT); imageColumn.setLabelProvider(new IconCellProvider(i)); imageColumn.getColumn().setWidth(getThumbnailSize() + ICON_SPACING); } if (!dirComboModel.isEmpty()) { dirComboModel.setSelectedIndex(2); dirCombo.select(2); directory = dirComboModel.getSelectedObject(); loadIcons(directory.getPath()); } else { loadIcons(ICON_DIRECTORY + "silk"); // $NON-NLS-1$ } }
/** * Reads in preview data * * <p>This goes through up to {@link ImportWizardModel#PREVIEW_MAX_LINES} lines within the * appropriate file and reads them in. It uses {@link ImportAdapter} in combination with {@link * ImportConfigurationCSV} to actually read in the data. * * @throws IOException Signals that an I/O exception has occurred. */ private void readPreview() throws IOException { /* Reset preview data */ previewData.clear(); /* Parameters from the user interface */ final String location = comboLocation.getText(); final char delimiter = delimiters[selectedDelimiter]; final char[] linebreak = CSVSyntax.getLinebreakForLabel(CSVSyntax.getAvailableLinebreaks()[selectedLinebreak]); final char quote = quotes[selectedQuote]; final char escape = escapes[selectedEscape]; final boolean containsHeader = btnContainsHeader.getSelection(); final Charset charset = Charsets.getCharsetForName(Charsets.getNamesOfAvailableCharsets()[selectedCharset]); /* Variables needed for processing */ final CSVDataInput in = new CSVDataInput(location, charset, delimiter, quote, escape, linebreak); final Iterator<String[]> it = in.iterator(); final String[] firstLine; wizardColumns = new ArrayList<ImportWizardModelColumn>(); ImportConfigurationCSV config = new ImportConfigurationCSV( location, charset, delimiter, quote, escape, linebreak, containsHeader); /* Check whether there is at least one line in file and retrieve it */ if (it.hasNext()) { firstLine = it.next(); } else { in.close(); throw new IOException(Resources.getMessage("ImportWizardPageCSV.17")); // $NON-NLS-1$ } /* Iterate over columns and add it to {@link #allColumns} */ for (int i = 0; i < firstLine.length; i++) { ImportColumn column = new ImportColumnCSV(i, DataType.STRING); ImportWizardModelColumn wizardColumn = new ImportWizardModelColumn(column); wizardColumns.add(wizardColumn); config.addColumn(column); } /* Create adapter to import data with given configuration */ ImportAdapter importAdapter = ImportAdapter.create(config); /* Get up to {ImportData#previewDataMaxLines} lines for previewing */ int count = 0; while (importAdapter.hasNext() && (count <= ImportWizardModel.PREVIEW_MAX_LINES)) { previewData.add(importAdapter.next()); count++; } in.close(); /* Remove first entry as it always contains name of columns */ previewData.remove(0); /* Check whether there is actual any data */ if (previewData.size() == 0) { throw new IOException(Resources.getMessage("ImportWizardPageCSV.18")); // $NON-NLS-1$ } /* * Show preview in appropriate table */ /* Disable redrawing once redesign is finished */ tablePreview.setRedraw(false); /* Remove all of the old columns */ while (tablePreview.getColumnCount() > 0) { tablePreview.getColumns()[0].dispose(); } /* Add new columns */ for (ImportWizardModelColumn column : wizardColumns) { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewerPreview, SWT.NONE); tableViewerColumn.setLabelProvider( new CSVColumnLabelProvider(((ImportColumnCSV) column.getColumn()).getIndex())); TableColumn tableColumn = tableViewerColumn.getColumn(); tableColumn.setWidth(100); if (btnContainsHeader.getSelection()) { tableColumn.setText(column.getColumn().getAliasName()); tableColumn.setToolTipText( Resources.getMessage("ImportWizardPageCSV.19") + ((ImportColumnCSV) column.getColumn()).getIndex()); // $NON-NLS-1$ } ColumnViewerToolTipSupport.enableFor(tableViewerPreview, ToolTip.NO_RECREATE); } /* Setup preview table */ tableViewerPreview.setInput(previewData); tablePreview.setHeaderVisible(btnContainsHeader.getSelection()); tablePreview.setVisible(true); tablePreview.layout(); tablePreview.setRedraw(true); }
/** {@inheritDoc} */ @Override protected void doCreatePartControl(final Composite parent) { final GridLayout layout = new GridLayout(3, false); parent.setLayout(layout); // Item: pvs [Refresh] Label l = new Label(parent, 0); l.setText(Messages.SampleView_Item); l.setLayoutData(new GridData()); items = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); items.setLayoutData(new GridData(SWT.FILL, 0, true, false)); items.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(final SelectionEvent e) { widgetDefaultSelected(e); } @Override public void widgetDefaultSelected( final SelectionEvent e) { // Configure table to display samples of the selected model item if (items.getSelectionIndex() == 0) { sample_table.setInput(null); return; } final int selected = items.getSelectionIndex() - 1; // / Skip initial "Select item" entry int index = 0; for (ModelItem item : model.getItems()) { if (index == selected) { sample_table.setInput(item); return; } ++index; } Activator.getLogger().log(Level.WARNING, "Invalid item index " + selected); } }); final Button refresh = new Button(parent, SWT.PUSH); refresh.setText(Messages.SampleView_Refresh); refresh.setToolTipText(Messages.SampleView_RefreshTT); refresh.setLayoutData(new GridData()); refresh.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { // Trigger GUI update update(false); } }); // Sample Table // TableColumnLayout requires this to be in its own container final Composite table_parent = new Composite(parent, 0); table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1)); final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10); table_parent.setLayout(table_layout); sample_table = new TableViewer( table_parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL); sample_table.setContentProvider(new SampleTableContentProvider()); final Table table = sample_table.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); // Time column TableViewerColumn col = TableHelper.createColumn(table_layout, sample_table, Messages.TimeColumn, 90, 100); col.setLabelProvider( new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); cell.setText(TimestampHelper.format(TimeHelper.toTimestamp(sample.getPosition()))); } }); // Value column col = TableHelper.createColumn(table_layout, sample_table, Messages.ValueColumn, 50, 100); col.setLabelProvider( new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); cell.setText(format.format(sample.getVType())); } @Override public String getToolTipText(Object element) { final PlotSample sample = (PlotSample) element; final VType value = sample.getVType(); // Show numbers in their 'natural' format which may differ from the Display settings if (value instanceof VStatistics) { final VStatistics mmd = (VStatistics) value; return NLS.bind( Messages.SampleView_MinMaxValueTT, new String[] { Double.toString(mmd.getAverage()), Double.toString(mmd.getMin()), Double.toString(mmd.getMax()) }); } else if (value instanceof VNumber) { final VNumber dbl = (VNumber) value; return Double.toString(dbl.getValue().doubleValue()); } else return VTypeHelper.toString(value); } }); // Severity column col = TableHelper.createColumn(table_layout, sample_table, Messages.SeverityColumn, 90, 50); col.setLabelProvider( new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); final VType value = sample.getVType(); final AlarmSeverity severity = VTypeHelper.getSeverity(value); cell.setText(severity.toString()); if (severity == AlarmSeverity.NONE) { cell.setBackground(null); return; } final Display display = cell.getControl().getDisplay(); if (severity == AlarmSeverity.MAJOR) cell.setBackground(display.getSystemColor(SWT.COLOR_RED)); else if (severity == AlarmSeverity.MINOR) cell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); else cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY)); } }); // Status column col = TableHelper.createColumn(table_layout, sample_table, Messages.StatusColumn, 90, 50); col.setLabelProvider( new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); final VType value = sample.getVType(); cell.setText(VTypeHelper.getMessage(value)); } }); // Sample Source column col = TableHelper.createColumn(table_layout, sample_table, Messages.SampleView_Source, 90, 10); col.setLabelProvider( new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); cell.setText(sample.getSource()); } }); ColumnViewerToolTipSupport.enableFor(sample_table); // Be ignorant of any change of the current model after this view // is disposed. parent.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { if (model != null) model.removeListener(model_listener); } }); }
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); setControl(container); GridLayoutFactory.fillDefaults().numColumns(3).applyTo(container); Label lblAcc = new Label(container, SWT.NULL); lblAcc.setText(Messages.ColumnAccount); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblAcc); final Text accountName = new Text(container, SWT.BORDER | SWT.SINGLE); GridDataFactory.fillDefaults() .grab(true, false) .align(SWT.FILL, SWT.CENTER) .applyTo(accountName); Button button = new Button(container, SWT.PUSH); button.setText(Messages.NewFileWizardButtonAdd); GridDataFactory.fillDefaults().applyTo(button); Composite tableContainer = new Composite(container, SWT.NONE); GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(tableContainer); TableColumnLayout layout = new TableColumnLayout(); tableContainer.setLayout(layout); tViewer = new TableViewer(tableContainer); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String acnName = accountName.getText(); if (acnName.length() > 0) { Account currentAccount = new Account(); currentAccount.setName(acnName); client.addAccount(currentAccount); tViewer.refresh(); accountName.setText(""); // $NON-NLS-1$ accountName.setFocus(); } } }); Table table = tViewer.getTable(); table.setHeaderVisible(true); table.setEnabled(false); tViewer.setContentProvider(ArrayContentProvider.getInstance()); tViewer.setInput(client.getAccounts()); TableViewerColumn aCol = new TableViewerColumn(tViewer, SWT.NONE); layout.setColumnData(aCol.getColumn(), new ColumnWeightData(50)); aCol.getColumn().setText(Messages.ColumnAccount); aCol.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { return ((Account) element).getName(); } @Override public Image getImage(Object element) { return PortfolioPlugin.image(PortfolioPlugin.IMG_ACCOUNT); } }); container.pack(); setPageComplete(true); }