@Override public Object[] getElements(Object inputElement) { List<String[]> l = new ArrayList<String[]>(); IXArchADTTypeMetadata typeMetadata = xarch.getTypeMetadata((ObjRef) inputElement); for (IXArchADTFeature feature : typeMetadata.getFeatures().values()) { if (feature.getType().equals(IXArchADTFeature.FeatureType.ATTRIBUTE)) { Object value = xarch.get((ObjRef) inputElement, feature.getName()); l.add(new String[] {feature.getName(), value == null ? null : value.toString()}); } } return l.toArray(); }
private void set(String featureName, String stringValue) { IXArchADTTypeMetadata typeMetadata = xarch.getTypeMetadata(ref); IXArchADTFeature feature = typeMetadata.getFeatures().get(featureName); if (feature != null) { try { // If the feature is an enumeration type, then xarch.set will // automatically try to convert it to an enum and throw // IllegalArgumentException if it's not a valid value. XArchADTOperations.set("Set", xarch, ref, featureName, stringValue); } catch (IllegalArgumentException iae) { MessageBox messageBox = new MessageBox(parent.getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage("Invalid value for this field."); messageBox.setText("Error"); messageBox.open(); } } else { throw new RuntimeException("This shouldn't happen."); } }
@Override public void createEditorContents(Composite parent) { List<INodeInfo> selectedNodeInfos = null; if (outlinePage != null) { selectedNodeInfos = ((ArchEditOutlinePage) outlinePage).getSelectedNodeInfos(); } if (selectedNodeInfos == null || selectedNodeInfos.size() == 0) { Label lNothingSelected = new Label(parent, SWT.LEFT); lNothingSelected.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); lNothingSelected.setFont(resources.getPlatformFont(IResources.PLATFORM_DEFAULT_FONT_ID)); lNothingSelected.setText("Select one or more elements in the outline view."); } else { for (INodeInfo selectedNodeInfo : selectedNodeInfos) { Label lElement = new Label(parent, SWT.LEFT); lElement.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); lElement.setFont(resources.getPlatformFont(IResources.PLATFORM_HEADER_FONT_ID)); if (selectedNodeInfo instanceof IReferenceNodeInfo) { IReferenceNodeInfo referenceNodeInfo = (IReferenceNodeInfo) selectedNodeInfo; String headerLine = "Link: " + referenceNodeInfo.getFeatureName(); lElement.setText(headerLine.toString()); createDragSourceComposite(parent, referenceNodeInfo); } else if (selectedNodeInfo instanceof IElementNodeInfo) { ObjRef selectedRef = ((IElementNodeInfo) selectedNodeInfo).getRef(); IXArchADTTypeMetadata typeMetadata = xarch.getTypeMetadata(selectedRef); StringBuffer headerLine = new StringBuffer(); headerLine.append(XadlUtils.getDisplayName(xarch, selectedRef)); headerLine.append(": "); headerLine.append(typeMetadata.getTypeName()); lElement.setText(headerLine.toString()); boolean hasAttribute = false; for (IXArchADTFeature feature : typeMetadata.getFeatures().values()) { if (feature.getType().equals(IXArchADTFeature.FeatureType.ATTRIBUTE)) { hasAttribute = true; break; } } if (!hasAttribute) { // No attributes. Label lNoAttributes = new Label(parent, SWT.LEFT); lNoAttributes.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); lNoAttributes.setFont(resources.getPlatformFont(IResources.PLATFORM_DEFAULT_FONT_ID)); lNoAttributes.setText("This element has no attributes."); } else { TableViewer tv = new TableViewer(parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.NO_FOCUS); tv.setContentProvider(new ViewContentProvider()); tv.setLabelProvider(new ViewLabelProvider()); tv.setInput(selectedRef); Table table = tv.getTable(); TableColumn column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_NAMES[0]); TableColumn column2 = new TableColumn(table, SWT.LEFT); column2.setText(COLUMN_NAMES[1]); TableLayout tableLayout = new AutoResizeTableLayout(table); tableLayout.addColumnData(new ColumnWeightData(30, true)); tableLayout.addColumnData(new ColumnWeightData(70, true)); table.setLayout(tableLayout); table.setHeaderVisible(true); table.setLinesVisible(true); table.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); tv.setColumnProperties(COLUMN_NAMES); CellEditor tce = new TextCellEditor(table); tv.setCellEditors(new CellEditor[] {null, tce}); tv.setCellModifier(new ViewCellModifier(selectedRef)); tv.refresh(); } } } } }