+ TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+ attName.setWidth(attTblColWidth[0]);
+ attName.setText(attTblHeaders[0]);
+
+ TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+ attValue.setWidth(attTblColWidth[1]);
+ attValue.setText(attTblHeaders[1]);
+ TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
+ attValue);
+ attValueVwrCol.setEditingSupport(attributeEditor
+ .createAttributeValueEditor(attViewer, this));
+
+ TreeColumn updateColumn = new TreeColumn(tree, SWT.NONE);
+ updateColumn.setWidth(attTblColWidth[2]);
+ updateColumn.setText(attTblHeaders[2]);
+ TreeViewerColumn updateVwrCol = new TreeViewerColumn(attViewer,
+ updateColumn);
+ updateVwrCol.setEditingSupport(attributeEditor
+ .createPostSelectionEditor(attViewer));
+
+ addMenuItems();
+ }
+
+ private void addMenuItems() {
+ if (null != attViewer) {
+ final Tree resourceTreeHead = attViewer.getTree();
+ if (null != resourceTreeHead) {
+ // Below code creates menu entries and shows them on right
+ // clicking a resource
+ final Menu menu = new Menu(resourceTreeHead);
+ resourceTreeHead.setMenu(menu);
+ menu.addMenuListener(new MenuAdapter() {
+ @Override
+ public void menuShown(MenuEvent e) {
+ // Clear existing menu items
+ MenuItem[] items = menu.getItems();
+ for (int index = 0; index < items.length; index++) {
+ items[index].dispose();
+ }
+
+ IStructuredSelection selection = ((IStructuredSelection) attViewer
+ .getSelection());
+ final AttributeElement attElement = (AttributeElement) selection
+ .getFirstElement();
+ if (null == attElement) {
+ return;
+ }
+
+ // Check the type of attribute.
+ SimulatorResourceAttribute attribute = attElement
+ .getSimulatorResourceAttribute();
+ if (null == attribute) {
+ return;
+ }
+
+ AttributeValue value = attribute.value();
+ if (null == value || null == value.get()) {
+ return;
+ }
+
+ TypeInfo type = value.typeInfo();
+
+ final Object parent = attElement.getParent();
+
+ if ((type.mType == ValueType.ARRAY
+ && type.mBaseType == ValueType.RESOURCEMODEL && type.mDepth == 1)
+ && (null == parent || parent instanceof ResourceRepresentation)) {
+ addMenuToOneDimensionalTopLevelModelAttributes(menu);
+ return;
+ }
+
+ if (null != parent
+ && parent instanceof AttributeElement) {
+ Object grandParent = ((AttributeElement) parent)
+ .getParent();
+ if (null == grandParent
+ || grandParent instanceof ResourceRepresentation) {
+ AttributeElement parentElement = (AttributeElement) parent;
+
+ // Check the type of attribute.
+ SimulatorResourceAttribute parentAttribute = parentElement
+ .getSimulatorResourceAttribute();
+ if (null != parentAttribute
+ && null != parentAttribute.value()
+ && null != parentAttribute.value()
+ .get()) {
+ AttributeValue parentValue = parentAttribute
+ .value();
+
+ TypeInfo parentType = parentValue
+ .typeInfo();
+ if (parentType.mType == ValueType.ARRAY
+ && parentType.mBaseType == ValueType.RESOURCEMODEL
+ && parentType.mDepth == 1) {
+ addDeleteMenuToArrayItemsOfOneDimensionalModelAttribute(
+ menu, attElement, parentElement);
+ return;
+ }
+ }
+ }
+ }
+ }
+ });