List of usage examples for org.eclipse.jface.viewers CellLabelProvider CellLabelProvider
public CellLabelProvider()
From source file:Snippet015CustomTooltipsForTree.java
License:Open Source License
/** * @param args/*from w w w .ja v a 2 s. c om*/ */ public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); TreeViewer v = new TreeViewer(shell, SWT.FULL_SELECTION); v.getTree().setLinesVisible(true); v.getTree().setHeaderVisible(true); ColumnViewerToolTipSupport.enableFor(v); v.setContentProvider(new MyContentProvider()); CellLabelProvider labelProvider = new CellLabelProvider() { /* (non-Javadoc) * @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipText(java.lang.Object) */ public String getToolTipText(Object element) { return "Tooltip (" + element + ")"; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipShift(java.lang.Object) */ public Point getToolTipShift(Object object) { return new Point(5, 5); } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipDisplayDelayTime(java.lang.Object) */ public int getToolTipDisplayDelayTime(Object object) { return 1000; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipTimeDisplayed(java.lang.Object) */ public int getToolTipTimeDisplayed(Object object) { return 50000; } public void update(ViewerCell cell) { cell.setText(cell.getElement().toString()); } }; v.setLabelProvider(labelProvider); v.setInput(""); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:au.gov.ga.earthsci.bookmark.part.editor.LayersPropertyEditor.java
License:Apache License
@Override public Control createControl(Composite parent) { container = new Composite(parent, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); container.setLayout(new GridLayout(1, false)); Label l = new Label(container, SWT.TITLE); l.setText(Messages.LayersPropertyEditor_LayerStateLabel); Table table = new Table(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.CHECK); layerTable = new CheckboxTableViewer(table); layerTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); layerTable.setContentProvider(ArrayContentProvider.getInstance()); layerTable.getTable().setHeaderVisible(true); layerTable.getTable().setLinesVisible(true); TableViewerColumn col = new TableViewerColumn(layerTable, SWT.NONE); col.getColumn().setWidth(200);/* w w w . j a v a2 s . c o m*/ col.getColumn().setText(Messages.LayersPropertyEditor_LayerStateLabelColumnLabel); col.getColumn().setResizable(true); col.getColumn().setMoveable(false); col = new TableViewerColumn(layerTable, SWT.NONE); col.getColumn().setWidth(100); col.getColumn().setText(Messages.LayersPropertyEditor_LayerStateOpacityColumnLabel); col.getColumn().setResizable(true); col.getColumn().setMoveable(false); col.setEditingSupport(new EditingSupport(col.getViewer()) { @Override protected CellEditor getCellEditor(Object element) { TextCellEditor textCellEditor = new TextCellEditor(layerTable.getTable()); textCellEditor.setValidator(new ICellEditorValidator() { @Override public String isValid(Object value) { try { Double.parseDouble((String) value); return null; } catch (Exception e) { return Messages.LayersPropertyEditor_InvalidOpacityMessage; } } }); return textCellEditor; } @Override protected boolean canEdit(Object element) { return true; } @SuppressWarnings("unchecked") @Override protected Object getValue(Object element) { return Double.toString(((Entry<URI, Double>) element).getValue()); } @SuppressWarnings("unchecked") @Override protected void setValue(Object element, Object value) { ((Entry<URI, Double>) element).setValue(Util.clamp(Double.parseDouble((String) value), 0, 1)); layerTable.refresh(element, true); } }); layerTable.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { @SuppressWarnings("unchecked") Entry<URI, Double> entry = (Entry<URI, Double>) cell.getElement(); if (cell.getColumnIndex() == 0) { cell.setText(entry.getKey().toString()); } else { cell.setText(Double.toString(entry.getValue())); } } }); fillFieldsFromProperty(getProperty()); return container; }
From source file:au.gov.ga.earthsci.bookmark.ui.editor.LayersPropertyEditor.java
License:Apache License
@Override public Control createControl(Composite parent) { container = new Composite(parent, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); container.setLayout(new GridLayout(1, false)); Label l = new Label(container, SWT.TITLE); l.setText(Messages.LayersPropertyEditor_LayerStateLabel); Table table = new Table(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.CHECK); tableColumns = new ArrayList<TableViewerColumn>(); colToName = new ConcurrentHashMap<Integer, String>(); colToName.put(0, "id"); colToName.put(1, "opacity"); layerTable = new CheckboxTableViewer(table); layerTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); layerTable.setContentProvider(new IStructuredContentProvider() { @Override/*w ww . j a v a2 s. com*/ public void inputChanged(Viewer arg0, Object oldItem, Object newItem) { for (TableViewerColumn col : tableColumns) { col.getColumn().dispose(); } tableColumns.clear(); colToName.clear(); if (newItem != null) { Collection<String> cols = null; if (newItem instanceof Map) { cols = getColumnsNeeded((Map) newItem); } for (String s : cols) { if (!s.equals("id")) { createTableColumn(s, s.equals(LayersPropertyPersister.OPACITY_ATTRIBUTE_NAME)); } } createTableColumn("id", false); } } @Override public void dispose() { } @Override public Object[] getElements(Object element) { List items = new ArrayList(); Map<String, Map<String, String>> stateinfo = (Map<String, Map<String, String>>) element; for (Entry<String, Map<String, String>> entry : stateinfo.entrySet()) { items.add(entry); } return items.toArray(new Object[0]); } }); layerTable.getTable().setHeaderVisible(true); layerTable.getTable().setLinesVisible(true); labelProv = new CellLabelProvider() { @Override public void update(ViewerCell cell) { @SuppressWarnings("unchecked") Entry<String, Map<String, String>> entry = (Entry<String, Map<String, String>>) cell.getElement(); int index = cell.getColumnIndex(); String colName = colToName.get(index); cell.setText(colName.equals("id") ? entry.getKey() : entry.getValue().get(colName)); } }; fillFieldsFromProperty(getProperty()); return container; }
From source file:ch.elexis.core.ui.contacts.preferences.BezugsKontaktSettings.java
License:Open Source License
@Override protected Control createContents(Composite parent) { updateExistingEntriesIds.clear();//from ww w . ja va2 s .c o m Composite container = new Composite(parent, SWT.NULL); container.setLayout(new GridLayout(1, false)); Group group = new Group(container, SWT.NONE); group.setLayout(new GridLayout(1, false)); group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); group.setText(Messages.Bezugskontakt_Definition); Composite composite = new Composite(group, SWT.NONE); GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); gd_composite.heightHint = 300; composite.setLayoutData(gd_composite); TableColumnLayout tcl_composite = new TableColumnLayout(); composite.setLayout(tcl_composite); tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); tableBezugsKontaktRelations = tableViewer.getTable(); tableBezugsKontaktRelations.setHeaderVisible(true); tableBezugsKontaktRelations.setLinesVisible(true); if (allowEditing) { Menu menu = new Menu(tableBezugsKontaktRelations); tableBezugsKontaktRelations.setMenu(menu); MenuItem mntmAddBezugsKontaktRelation = new MenuItem(menu, SWT.NONE); mntmAddBezugsKontaktRelation.setText(Messages.Bezugskontakt_Add); mntmAddBezugsKontaktRelation.setImage(Images.IMG_NEW.getImage()); mntmAddBezugsKontaktRelation.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { BezugsKontaktRelation bezugsKontaktRelation = new BezugsKontaktRelation("", RelationshipType.AGENERIC, RelationshipType.AGENERIC); tableViewer.add(bezugsKontaktRelation); tableViewer.setSelection(new StructuredSelection(bezugsKontaktRelation)); } }); MenuItem mntmRemoveBezugsKontaktRelation = new MenuItem(menu, SWT.NONE); mntmRemoveBezugsKontaktRelation.setText(Messages.Bezugskontakt_Delete); mntmRemoveBezugsKontaktRelation.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int selectionsIdx = tableViewer.getTable().getSelectionIndex(); if (selectionsIdx != -1) { boolean ret = MessageDialog.openQuestion(UiDesk.getTopShell(), Messages.Bezugskontakt_ConfirmDelete, Messages.Bezugskontakt_ConfirmDeleteText); if (ret) { tableViewer.getTable().remove(selectionsIdx); } } } }); } TableViewerColumn viewCol = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn col = viewCol.getColumn(); tcl_composite.setColumnData(col, new ColumnWeightData(1, 140)); col.setText(Messages.BezugsKonktat_Reference); col.setToolTipText(Messages.Bezugskontakt_ReferenceTooltip); viewCol.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { BezugsKontaktRelation s = (BezugsKontaktRelation) cell.getElement(); if (s == null) return; cell.setText(s.getName()); } }); viewCol.setEditingSupport(new EditingSupport(tableViewer) { @Override protected void setValue(Object element, Object value) { if (element instanceof BezugsKontaktRelation) { String newName = String.valueOf(value); BezugsKontaktRelation tableData = null; for (TableItem tableItem : tableViewer.getTable().getItems()) { tableData = (BezugsKontaktRelation) tableItem.getData(); if (tableData != null && !tableData.equals(element) && !tableData.getName().isEmpty() && newName.equalsIgnoreCase(tableData.getName())) { MessageDialog.openError(UiDesk.getTopShell(), "", Messages.Bezugskontakt_NameMustBeUnique); return; } } BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element; if (!bezugsKontaktRelation.getName().equals(newName)) { bezugsKontaktRelation.setName(newName); getViewer().update(bezugsKontaktRelation, null); openConfirmUpdateExistingData(bezugsKontaktRelation); } } } @Override protected Object getValue(Object element) { if (element instanceof BezugsKontaktRelation) { return ((BezugsKontaktRelation) element).getName(); } return null; } @Override protected CellEditor getCellEditor(Object element) { return new TextCellEditor(tableViewer.getTable()); } @Override protected boolean canEdit(Object element) { return allowEditing; } }); viewCol = new TableViewerColumn(tableViewer, SWT.NONE); col = viewCol.getColumn(); tcl_composite.setColumnData(col, new ColumnWeightData(0, 140)); col.setText(Messages.Bezugskontakt_RelationFrom); viewCol.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { BezugsKontaktRelation s = (BezugsKontaktRelation) cell.getElement(); if (s == null) return; cell.setText(LocalizeUtil.getLocaleText(s.getDestRelationType())); } }); viewCol.setEditingSupport(new EditingSupport(tableViewer) { @Override protected void setValue(Object element, Object value) { if (element instanceof BezugsKontaktRelation && value instanceof Integer) { BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element; RelationshipType[] allRelationshipTypes = RelationshipType.values(); if ((int) value != -1 && !bezugsKontaktRelation.getDestRelationType() .equals(allRelationshipTypes[(int) value])) { bezugsKontaktRelation.setDestRelationType(allRelationshipTypes[(int) value]); getViewer().update(bezugsKontaktRelation, null); openConfirmUpdateExistingData(bezugsKontaktRelation); } } } @Override protected Object getValue(Object element) { if (element instanceof BezugsKontaktRelation) { BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element; RelationshipType relationshipType = bezugsKontaktRelation.getDestRelationType(); if (relationshipType != null) { return relationshipType.getValue(); } } return 0; } @Override protected CellEditor getCellEditor(Object element) { return new ComboBoxCellEditor(tableViewer.getTable(), BezugsKontaktAuswahl.getBezugKontaktTypes(), SWT.NONE); } @Override protected boolean canEdit(Object element) { return allowEditing; } }); viewCol = new TableViewerColumn(tableViewer, SWT.NONE); col = viewCol.getColumn(); tcl_composite.setColumnData(col, new ColumnWeightData(0, 140)); col.setText(Messages.Bezugskontakt_RelationTo); viewCol.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { BezugsKontaktRelation s = (BezugsKontaktRelation) cell.getElement(); if (s == null) return; cell.setText(LocalizeUtil.getLocaleText(s.getSrcRelationType())); } }); viewCol.setEditingSupport(new EditingSupport(tableViewer) { @Override protected void setValue(Object element, Object value) { if (element instanceof BezugsKontaktRelation && value instanceof Integer) { BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element; RelationshipType[] allRelationshipTypes = RelationshipType.values(); if ((int) value != -1 && !bezugsKontaktRelation.getSrcRelationType() .equals(allRelationshipTypes[(int) value])) { bezugsKontaktRelation.setSrcRelationType(allRelationshipTypes[(int) value]); getViewer().update(bezugsKontaktRelation, null); openConfirmUpdateExistingData(bezugsKontaktRelation); } } } @Override protected Object getValue(Object element) { if (element instanceof BezugsKontaktRelation) { BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element; RelationshipType relationshipType = bezugsKontaktRelation.getSrcRelationType(); if (relationshipType != null) { return relationshipType.getValue(); } } return 0; } @Override protected CellEditor getCellEditor(Object element) { return new ComboBoxCellEditor(tableViewer.getTable(), BezugsKontaktAuswahl.getBezugKontaktTypes(), SWT.NONE); } @Override protected boolean canEdit(Object element) { return allowEditing; } }); ; tableViewer .setInput(loadBezugKonkaktTypes(CoreHub.globalCfg.get(Patientenblatt2.CFG_BEZUGSKONTAKTTYPEN, ""))); return container; }
From source file:com.android.ide.eclipse.adt.internal.wizards.newxmlfile.AddTranslationDialog.java
License:Open Source License
/** Populates the table with keys and default strings */ private void fillStrings() { ResourceManager manager = ResourceManager.getInstance(); ProjectResources resources = manager.getProjectResources(mProject); mExistingLanguages = resources.getLanguages(); Collection<ResourceItem> items = resources.getResourceItemsOfType(ResourceType.STRING); ResourceItem[] array = items.toArray(new ResourceItem[items.size()]); Arrays.sort(array);/*from w ww . jav a2s. c o m*/ // TODO: Read in the actual XML files providing the default keys here // (they can be obtained via ResourceItem.getSourceFileList()) // such that we can read all the attributes associated with each // item, and if it defines translatable=false, or the filename is // donottranslate.xml, we can ignore it, and in other cases just // duplicate all the attributes (such as "formatted=true", or other // local conventions such as "product=tablet", or "msgid="123123123", // etc.) mTranslations = Maps.newHashMapWithExpectedSize(items.size()); IBaseLabelProvider labelProvider = new CellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); int index = cell.getColumnIndex(); ResourceItem item = (ResourceItem) element; switch (index) { case KEY_COLUMN: { // Key cell.setText(item.getName()); return; } case DEFAULT_TRANSLATION_COLUMN: { // Default translation ResourceValue value = item.getResourceValue(ResourceType.STRING, mConfiguration, false); if (value != null) { cell.setText(value.getValue()); return; } break; } case NEW_TRANSLATION_COLUMN: { // New translation String translation = mTranslations.get(item.getName()); if (translation != null) { cell.setText(translation); return; } break; } default: assert false : index; } cell.setText(""); } }; mTableViewer.setLabelProvider(labelProvider); mTableViewer.setContentProvider(new ArrayContentProvider()); mTableViewer.setInput(array); }
From source file:com.android.sdkuilib.internal.widgets.AvdCreationDialog.java
License:Apache License
/** * Creates the UI for the hardware properties table. * This creates the {@link Table}, and several viewers ({@link TableViewer}, * {@link TableViewerColumn}) and adds edit support for the 2nd column *///w w w . j a v a2 s .c o m private void createHardwareTable(Composite parent) { final Table hardwareTable = new Table(parent, SWT.SINGLE | SWT.FULL_SELECTION); GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gd.widthHint = 200; gd.heightHint = 100; hardwareTable.setLayoutData(gd); hardwareTable.setHeaderVisible(true); hardwareTable.setLinesVisible(true); // -- Table viewer mHardwareViewer = new TableViewer(hardwareTable); mHardwareViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // it's a single selection mode, we can just access the selection index // from the table directly. mDeleteHardwareProp.setEnabled(hardwareTable.getSelectionIndex() != -1); } }); // only a content provider. Use viewers per column below (for editing support) mHardwareViewer.setContentProvider(new IStructuredContentProvider() { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // we can just ignore this. we just use mProperties directly. } public Object[] getElements(Object arg0) { return mProperties.keySet().toArray(); } public void dispose() { // pass } }); // -- column 1: prop abstract name TableColumn col1 = new TableColumn(hardwareTable, SWT.LEFT); col1.setText("Property"); col1.setWidth(150); TableViewerColumn tvc1 = new TableViewerColumn(mHardwareViewer, col1); tvc1.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { String name = cell.getElement().toString(); HardwareProperty prop = mHardwareMap.get(name); if (prop != null) { cell.setText(prop.getAbstract()); } else { cell.setText(String.format("%1$s (Unknown)", name)); } } }); // -- column 2: prop value TableColumn col2 = new TableColumn(hardwareTable, SWT.LEFT); col2.setText("Value"); col2.setWidth(50); TableViewerColumn tvc2 = new TableViewerColumn(mHardwareViewer, col2); tvc2.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { String value = mProperties.get(cell.getElement()); cell.setText(value != null ? value : ""); } }); // add editing support to the 2nd column tvc2.setEditingSupport(new EditingSupport(mHardwareViewer) { @Override protected void setValue(Object element, Object value) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); switch (property.getType()) { case INTEGER: mProperties.put((String) element, (String) value); break; case DISKSIZE: if (HardwareProperties.DISKSIZE_PATTERN.matcher((String) value).matches()) { mProperties.put((String) element, (String) value); } break; case BOOLEAN: int index = (Integer) value; mProperties.put((String) element, HardwareProperties.BOOLEAN_VALUES[index]); break; } mHardwareViewer.refresh(element); } @Override protected Object getValue(Object element) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); String value = mProperties.get(hardwareName); switch (property.getType()) { case INTEGER: // intended fall-through. case DISKSIZE: return value; case BOOLEAN: return HardwareProperties.getBooleanValueIndex(value); } return null; } @Override protected CellEditor getCellEditor(Object element) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); switch (property.getType()) { // TODO: custom TextCellEditor that restrict input. case INTEGER: // intended fall-through. case DISKSIZE: return new TextCellEditor(hardwareTable); case BOOLEAN: return new ComboBoxCellEditor(hardwareTable, HardwareProperties.BOOLEAN_VALUES, SWT.READ_ONLY | SWT.DROP_DOWN); } return null; } @Override protected boolean canEdit(Object element) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); return property != null; } }); mHardwareViewer.setInput(mProperties); }
From source file:com.android.sdkuilib.internal.widgets.LegacyAvdEditDialog.java
License:Apache License
/** * Creates the UI for the hardware properties table. * This creates the {@link Table}, and several viewers ({@link TableViewer}, * {@link TableViewerColumn}) and adds edit support for the 2nd column *///w w w . j a va 2 s . c om private void createHardwareTable(Composite parent) { final Table hardwareTable = new Table(parent, SWT.SINGLE | SWT.FULL_SELECTION); GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gd.widthHint = 200; gd.heightHint = 100; hardwareTable.setLayoutData(gd); hardwareTable.setHeaderVisible(true); hardwareTable.setLinesVisible(true); // -- Table viewer mHardwareViewer = new TableViewer(hardwareTable); mHardwareViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // it's a single selection mode, we can just access the selection index // from the table directly. mDeleteHardwareProp.setEnabled(hardwareTable.getSelectionIndex() != -1); } }); // only a content provider. Use viewers per column below (for editing support) mHardwareViewer.setContentProvider(new IStructuredContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // we can just ignore this. we just use mProperties directly. } @Override public Object[] getElements(Object arg0) { return mProperties.keySet().toArray(); } @Override public void dispose() { // pass } }); // -- column 1: prop abstract name TableColumn col1 = new TableColumn(hardwareTable, SWT.LEFT); col1.setText("Property"); col1.setWidth(150); TableViewerColumn tvc1 = new TableViewerColumn(mHardwareViewer, col1); tvc1.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { String name = cell.getElement().toString(); HardwareProperty prop = mHardwareMap.get(name); if (prop != null) { cell.setText(prop.getAbstract()); } else { cell.setText(String.format("%1$s (Unknown)", name)); } } }); // -- column 2: prop value TableColumn col2 = new TableColumn(hardwareTable, SWT.LEFT); col2.setText("Value"); col2.setWidth(50); TableViewerColumn tvc2 = new TableViewerColumn(mHardwareViewer, col2); tvc2.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { String value = mProperties.get(cell.getElement()); cell.setText(value != null ? value : ""); } }); // add editing support to the 2nd column tvc2.setEditingSupport(new EditingSupport(mHardwareViewer) { @Override protected void setValue(Object element, Object value) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); int index; switch (property.getType()) { case INTEGER: mProperties.put((String) element, (String) value); break; case DISKSIZE: if (HardwareProperties.DISKSIZE_PATTERN.matcher((String) value).matches()) { mProperties.put((String) element, (String) value); } break; case BOOLEAN: index = (Integer) value; mProperties.put((String) element, HardwareProperties.getBooleanValue(index)); break; case STRING_ENUM: case INTEGER_ENUM: // For a combo, value is the index of the enum to use. index = (Integer) value; String[] values = property.getEnum(); if (values != null && values.length > index) { mProperties.put((String) element, values[index]); } break; } mHardwareViewer.refresh(element); } @Override protected Object getValue(Object element) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); String value = mProperties.get(hardwareName); switch (property.getType()) { case INTEGER: // intended fall-through. case DISKSIZE: return value; case BOOLEAN: return HardwareProperties.getBooleanValueIndex(value); case STRING_ENUM: case INTEGER_ENUM: // For a combo, we need to return the index of the value in the enum String[] values = property.getEnum(); if (values != null) { for (int i = 0; i < values.length; i++) { if (values[i].equals(value)) { return i; } } } } return null; } @Override protected CellEditor getCellEditor(Object element) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); switch (property.getType()) { // TODO: custom TextCellEditor that restrict input. case INTEGER: // intended fall-through. case DISKSIZE: return new TextCellEditor(hardwareTable); case BOOLEAN: return new ComboBoxCellEditor(hardwareTable, new String[] { HardwareProperties.getBooleanValue(0), HardwareProperties.getBooleanValue(1), }, SWT.READ_ONLY | SWT.DROP_DOWN); case STRING_ENUM: case INTEGER_ENUM: String[] values = property.getEnum(); if (values != null && values.length > 0) { return new ComboBoxCellEditor(hardwareTable, values, SWT.READ_ONLY | SWT.DROP_DOWN); } } return null; } @Override protected boolean canEdit(Object element) { String hardwareName = (String) element; HardwareProperty property = mHardwareMap.get(hardwareName); return property != null; } }); mHardwareViewer.setInput(mProperties); }
From source file:com.archimatetool.editor.ui.dialog.RelationshipsMatrixDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { // Help//from www . jav a2 s . co m PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); setTitle(Messages.RelationshipsMatrixDialog_0); setMessage(Messages.RelationshipsMatrixDialog_1); Composite composite = (Composite) super.createDialogArea(parent); Composite client = new Composite(composite, SWT.NULL); GridLayout layout = new GridLayout(2, false); client.setLayout(layout); client.setLayoutData(new GridData(GridData.FILL_BOTH)); GridData gd; GridTableViewer viewer = new GridTableViewer(client); gd = new GridData(GridData.FILL_BOTH); gd.widthHint = 800; gd.heightHint = 500; viewer.getControl().setLayoutData(gd); viewer.getGrid().setHeaderVisible(true); viewer.getGrid().setRowHeaderVisible(true); viewer.getGrid().setRowsResizeable(true); viewer.getGrid().setCellSelectionEnabled(true); //viewer.setColumnProperties(new String[] {"1", "2", "3"}); viewer.setRowHeaderLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { cell.setText(ArchimateLabelProvider.INSTANCE.getDefaultName((EClass) cell.getElement())); cell.setImage(ArchimateLabelProvider.INSTANCE.getImage(cell.getElement())); } }); for (EClass eClass : getData()) { GridColumn column = new GridColumn(viewer.getGrid(), SWT.NONE); column.setWidth(70); column.setImage(ArchimateLabelProvider.INSTANCE.getImage(eClass)); column.setHeaderTooltip(ArchimateLabelProvider.INSTANCE.getDefaultName(eClass)); } viewer.setContentProvider(new IStructuredContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @Override public void dispose() { } @Override public Object[] getElements(Object inputElement) { return getData().toArray(); } }); viewer.setLabelProvider(new MyLabelProvider()); //hookContextMenu(viewer); viewer.setInput(getData()); String text = ""; //$NON-NLS-1$ for (Entry<EClass, Character> entry : RelationshipsMatrix.INSTANCE.getRelationshipsValueMap().entrySet()) { text += entry.getValue() + ": " + ArchimateLabelProvider.INSTANCE.getDefaultShortName(entry.getKey()) //$NON-NLS-1$ + "\n"; //$NON-NLS-1$ } Label label = new Label(client, SWT.NULL); label.setText(text); label.setLayoutData(new GridData(SWT.TOP, SWT.TOP, false, true)); return composite; }
From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java
License:Apache License
/** * Create the license text editor component * /*from ww w . ja v a2 s. c o m*/ * @param parent * @return * @throws InvalidSPDXAnalysisException */ private Group createLicenseTextEditor(Composite parent) throws InvalidSPDXAnalysisException { Group licenseTextEditorGroup = new Group(parent, SWT.SHADOW_ETCHED_IN); licenseTextEditorGroup.setText("Licenses referenced in SPDX file"); GridLayout licenseTextEditorGroupLayout = new GridLayout(); licenseTextEditorGroupLayout.numColumns = 2; licenseTextEditorGroup.setLayout(licenseTextEditorGroupLayout); // Add table viewer final TableViewer tableViewer = new TableViewer(licenseTextEditorGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); // The list of available extracted license texts final Table table = tableViewer.getTable(); table.setToolTipText("Right click to add/remove licenses."); // Build a drop down menu to add/remove licenses Menu licenseTableMenu = new Menu(parent.getShell(), SWT.POP_UP); MenuItem addNewLicenseText = new MenuItem(licenseTableMenu, SWT.PUSH); addNewLicenseText.setText("Add license text"); addNewLicenseText.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Retrieve the corresponding Services IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class); // Retrieve the command Command generateCmd = commandService.getCommand("SPDXEditor.addNewLicenseText"); // Create an ExecutionEvent ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event()); // Launch the command try { generateCmd.executeWithChecks(executionEvent); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { MessageDialog.openError(getSite().getShell(), "Execution failed", e1.getMessage()); } } }); // Listen for changes on model this.getInput().addChangeListener(new IResourceChangeListener() { @Override public void resourceChanged(IResourceChangeEvent event) { try { SPDXNonStandardLicense[] nonStandardLicenses = getInput().getAssociatedSPDXFile() .getExtractedLicenseInfos(); tableViewer.setInput(nonStandardLicenses); tableViewer.refresh(); loadLicenseDataFromSPDXFile(); setLicenseComboBoxValue(concludedLicenseChoice, getInput().getAssociatedSPDXFile().getSpdxPackage().getConcludedLicenses()); // populateLicenseSelectorWithAvailableLicenses(declaredLicenseChoice); setLicenseComboBoxValue(declaredLicenseChoice, getInput().getAssociatedSPDXFile().getSpdxPackage().getDeclaredLicense()); setDirtyFlag(true); } catch (InvalidSPDXAnalysisException e) { e.printStackTrace(); } } }); final MenuItem deleteSelectedLicenseTexts = new MenuItem(licenseTableMenu, SWT.PUSH); deleteSelectedLicenseTexts.setText("Delete licenses"); deleteSelectedLicenseTexts.setEnabled(false); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // Never enable, not yet implemented // deleteSelectedLicenseTexts.setEnabled(table.getSelectionCount() // != 0); } }); table.setMenu(licenseTableMenu); // Make headers and borders visible table.setHeaderVisible(true); table.setLinesVisible(true); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); // Create TableViewerColumn for each column TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("License ID"); viewerNameColumn.getColumn().setWidth(100); // Set LabelProvider for each column viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXNonStandardLicense licenseInCell = (SPDXNonStandardLicense) cell.getElement(); cell.setText(licenseInCell.getId()); } }); viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("License text"); viewerNameColumn.getColumn().setWidth(100); viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXNonStandardLicense iteratorLicense = (SPDXNonStandardLicense) cell.getElement(); cell.setText(iteratorLicense.getText()); } }); /* * All ExtractedLicensingInfo is contained in the SPDX file assigned to * the input. */ tableViewer.setInput(getInput().getAssociatedSPDXFile().getExtractedLicenseInfos()); GridData spdxDetailsPanelGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); spdxDetailsPanelGridData.horizontalSpan = 1; spdxDetailsPanelGridData.heightHint = 150; licenseTextEditorGroup.setLayoutData(spdxDetailsPanelGridData); GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; gridData.horizontalSpan = 1; gridData.heightHint = 100; gridData.minimumWidth = 70; tableViewer.getControl().setLayoutData(gridData); /* * Text editor field for editing license texts. */ final Text licenseEditorText = new Text(licenseTextEditorGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); licenseEditorText.setText(""); licenseEditorText.setEditable(true); GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gd.minimumHeight = 70; gd.minimumWidth = 200; gd.heightHint = 100; gd.horizontalSpan = 1; licenseEditorText.setLayoutData(gd); licenseEditorText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { try { SPDXNonStandardLicense[] nonStandardLicenses; nonStandardLicenses = getInput().getAssociatedSPDXFile().getExtractedLicenseInfos(); nonStandardLicenses[table.getSelectionIndex()].setText(licenseEditorText.getText()); setDirtyFlag(true); } catch (InvalidSPDXAnalysisException e1) { MessageDialog.openError(getSite().getShell(), "SPDX Analysis error", e1.getMessage()); } } }); /* * Listener for updating text editor selection based on selected table * entry. */ table.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { SPDXNonStandardLicense[] nonStandardLicenses; try { nonStandardLicenses = getInput().getAssociatedSPDXFile().getExtractedLicenseInfos(); licenseEditorText.setText(nonStandardLicenses[table.getSelectionIndex()].getText()); } catch (InvalidSPDXAnalysisException e1) { MessageDialog.openError(getSite().getShell(), "SPDX Analysis invalid", e1.getMessage()); } } }); // Style group panel GridData licenseTextEditorGroupGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); licenseTextEditorGroupGridData.horizontalSpan = 2; licenseTextEditorGroup.setLayoutData(licenseTextEditorGroupGridData); return licenseTextEditorGroup; }
From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java
License:Apache License
/** * Create the linked files group panel/*from ww w . j av a 2 s . co m*/ * * @param parent * @return * @throws InvalidSPDXAnalysisException */ private Composite createLinkedFilesDetailsPanel(Composite parent) throws InvalidSPDXAnalysisException { Group linkedFilesDetailsGroup = new Group(parent, SWT.SHADOW_ETCHED_IN); linkedFilesDetailsGroup.setText("Referenced files"); GridLayout linkedFilesDetailsGroupLayout = new GridLayout(); linkedFilesDetailsGroup.setLayout(linkedFilesDetailsGroupLayout); // Add table viewer final TableViewer tableViewer = new TableViewer(linkedFilesDetailsGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.horizontalAlignment = GridData.FILL; gridData.heightHint = 80; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; tableViewer.getControl().setLayoutData(gridData); // SWT Table final Table table = tableViewer.getTable(); table.setToolTipText("Right-click to add or remove files"); // Make header and columns visible table.setHeaderVisible(true); table.setLinesVisible(true); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); // Add context menu to TableViewer Menu linkesFileTableMenu = new Menu(parent.getShell(), SWT.POP_UP); MenuItem addNewLicenseText = new MenuItem(linkesFileTableMenu, SWT.PUSH); addNewLicenseText.setText("Add source code archive"); addNewLicenseText.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Retrieve the corresponding Services IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class); // Retrieve the command Command generateCmd = commandService.getCommand("SPDXEditor.addLinkedSourceCodeFile"); // Create an ExecutionEvent ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event()); // Launch the command try { generateCmd.executeWithChecks(executionEvent); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage()); } } }); final MenuItem deleteSelectedLicenseTexts = new MenuItem(linkesFileTableMenu, SWT.PUSH); deleteSelectedLicenseTexts.setText("Delete selected source code archive"); deleteSelectedLicenseTexts.setEnabled(false); deleteSelectedLicenseTexts.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Retrieve the corresponding Services IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class); // Retrieve the command Command generateCmd = commandService.getCommand("SPDXEditor.removedLinkedSourceCodeFile"); // Create an ExecutionEvent ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event()); // Launch the command try { generateCmd.executeWithChecks(executionEvent); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage()); } } }); table.setMenu(linkesFileTableMenu); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { deleteSelectedLicenseTexts.setEnabled(table.getSelectionCount() != 0); } }); // Create TableViewer for each column TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("File name"); viewerNameColumn.getColumn().setWidth(160); viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); cell.setText(currentFile.getName()); } }); viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("Type"); viewerNameColumn.getColumn().setWidth(120); viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); cell.setText(currentFile.getType()); } }); // License choice for file viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("Concluded License"); viewerNameColumn.getColumn().setWidth(120); // // LabelProvider fr jede Spalte setzen viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); SPDXLicenseInfo spdxConcludedLicenseInfo = currentFile.getConcludedLicenses(); cell.setText(getLicenseIdentifierTextForLicenseInfo(spdxConcludedLicenseInfo)); } }); viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("SHA1 hash"); viewerNameColumn.getColumn().setWidth(120); // LabelProvider fr jede Spalte setzen viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); cell.setText(currentFile.getSha1()); } }); SPDXFile[] referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles(); tableViewer.setInput(referencedFiles); getSite().setSelectionProvider(tableViewer); this.getInput().addChangeListener(new IResourceChangeListener() { @Override public void resourceChanged(IResourceChangeEvent event) { SPDXFile[] referencedFiles; try { referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles(); tableViewer.setInput(referencedFiles); tableViewer.refresh(); setDirtyFlag(true); } catch (InvalidSPDXAnalysisException e) { MessageDialog.openError(getSite().getShell(), "SPDX Analysis invalid", e.getMessage()); } } }); GridData spdxDetailsPanelGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, true); spdxDetailsPanelGridData.horizontalSpan = 1; spdxDetailsPanelGridData.grabExcessVerticalSpace = true; spdxDetailsPanelGridData.grabExcessHorizontalSpace = true; spdxDetailsPanelGridData.minimumHeight = 90; linkedFilesDetailsGroup.setLayoutData(spdxDetailsPanelGridData); return linkedFilesDetailsGroup; }