Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / PostRequestDialog.java
index 26c11b4..8d694bb 100644 (file)
 
 package oic.simulator.clientcontroller.view.dialogs;
 
-import java.util.List;
-
-import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
-import oic.simulator.clientcontroller.utils.Constants;
-
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MenuAdapter;
+import org.eclipse.swt.events.MenuEvent;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.oic.simulator.ArrayProperty;
+import org.oic.simulator.AttributeProperty;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.ModelProperty;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
+
+import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
+import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.AttributeEditingSupport;
 
 /**
  * This dialog is used for generating a POST request.
  */
 public class PostRequestDialog extends TitleAreaDialog {
 
-    private TableViewer                 attTblViewer;
+    private TreeViewer              attViewer;
+    private Combo                   ifTypesCmb;
+
+    private String                  ifType;
+
+    private Map<String, String>     ifTypes;
+
+    private AttributeEditingSupport attributeEditor;
+
+    private ResourceRepresentation  updatedRepresentation;
 
-    private final String[]              attTblHeaders  = { "Name", "Value",
-            "Select"                                  };
-    private final Integer[]             attTblColWidth = { 200, 200, 50 };
+    private final String[]          attTblHeaders  = { "Name", "Value",
+            "Select"                              };
+    private final Integer[]         attTblColWidth = { 200, 200, 50 };
 
-    private List<PutPostAttributeModel> modelList      = null;
-    
-    public PostRequestDialog(Shell parentShell,
-            List<PutPostAttributeModel> modelList) {
+    public PostRequestDialog(Shell parentShell) {
         super(parentShell);
-        this.modelList = modelList;
     }
 
     @Override
@@ -78,220 +114,699 @@ public class PostRequestDialog extends TitleAreaDialog {
     @Override
     protected Control createDialogArea(Composite parent) {
         Composite compLayout = (Composite) super.createDialogArea(parent);
-        Composite container = new Composite(compLayout, SWT.NONE);
+
+        Composite rootContainer = new Composite(compLayout, SWT.NONE);
+        GridLayout layout = new GridLayout();
+        rootContainer.setLayout(layout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        rootContainer.setLayoutData(gd);
+
+        Group paramsGrp = new Group(rootContainer, SWT.NONE);
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.minimumHeight = 50;
+        paramsGrp.setLayoutData(gd);
+        layout = new GridLayout(2, false);
+        layout.verticalSpacing = 10;
+        layout.marginTop = 10;
+        paramsGrp.setLayout(layout);
+
+        Label ifTypeLbl = new Label(paramsGrp, SWT.NONE);
+        ifTypeLbl.setText("Interface Type");
+
+        ifTypesCmb = new Combo(paramsGrp, SWT.NULL);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        ifTypesCmb.setLayoutData(gd);
+        ifTypesCmb.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e) {
+                ifType = ifTypesCmb.getText();
+            }
+        });
+
+        RemoteResource resource = Activator.getDefault().getResourceManager()
+                .getCurrentResourceInSelection();
+
+        // Set the interface types in combo box.
+        Map<String, String> ifTypes = Utility.getResourceInterfaces();
+        this.ifTypes = new HashMap<String, String>();
+        String key;
+        for (Map.Entry<String, String> entry : ifTypes.entrySet()) {
+            key = entry.getValue() + " (" + entry.getKey() + ")";
+            this.ifTypes.put(key, entry.getKey());
+            ifTypesCmb.add(key);
+        }
+
+        // Select the default value to be shown in the interface types combo.
+        Vector<String> ifTypesSupportedByResource = resource
+                .getRemoteResourceRef().getResourceInterfaces();
+        if (null != ifTypesSupportedByResource) {
+            int index = -1;
+            if (ifTypesSupportedByResource
+                    .contains(Constants.BASELINE_INTERFACE)
+                    && ifTypes.containsKey(Constants.BASELINE_INTERFACE)) {
+                // Baseline interface is given preference to be shown in the if
+                // types combo.
+                String value = ifTypes.get(Constants.BASELINE_INTERFACE);
+                index = ifTypesCmb.indexOf(value + " ("
+                        + Constants.BASELINE_INTERFACE + ")");
+                if (index != -1)
+                    ifTypesCmb.select(index);
+            }
+            if (index == -1) {
+                // Baseline interface is not selected so selecting some other
+                // interface supported by the resource.
+                Iterator<String> itr = ifTypesSupportedByResource.iterator();
+                while (itr.hasNext() && index == -1) {
+                    key = itr.next();
+                    if (ifTypes.containsKey(key)) {
+                        String value = ifTypes.get(key);
+                        index = ifTypesCmb.indexOf(value + " (" + key + ")");
+                        if (index != -1) {
+                            ifTypesCmb.select(index);
+                            break;
+                        }
+                    }
+                }
+                if (index == -1 && !ifTypesSupportedByResource.isEmpty()) {
+                    // Resource has custom interfaces.
+                    ifTypesCmb.setText(ifTypesSupportedByResource.get(0));
+                }
+            }
+        }
+
+        Composite container = new Composite(rootContainer, SWT.NONE);
         container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        GridLayout layout = new GridLayout(1, false);
+        layout = new GridLayout(1, false);
         layout.verticalSpacing = 10;
         layout.marginTop = 10;
         container.setLayout(layout);
 
-        createTableViewer(container);
+        createTreeViewer(container);
+
+        // Clone the resource model for maintaining a local copy of attributes
+        // for POST requests.
+        SimulatorResourceModel resourceModel = null;
+        try {
+            AttributeValue attValue = Utility
+                    .cloneAttributeValue(new AttributeValue(resource
+                            .getResourceModelRef()));
+            if (null != attValue)
+                resourceModel = (SimulatorResourceModel) attValue.get();
+        } catch (Exception e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while forming an instance of the attribute value.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+        }
+
+        if (null == resourceModel) {
+            // Failed to clone. So taking the base copy and continuing the
+            // operation.
+            resourceModel = resource.getResourceModelRef();
+        }
+
+        updatedRepresentation = new ResourceRepresentation(resourceModel);
+
+        if (resource.isConfigUploaded()) {
+            try {
+                // Request Type needs to be changed to PUT.
+                updatedRepresentation.updateAttributeProperties(resource
+                        .getRequestModels().get(RequestType.POST),
+                        resourceModel);
+            } catch (Exception e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(),
+                                new Date(),
+                                "There is an error while forming an instance of the attribute value.\n"
+                                        + Utility.getSimulatorErrorString(e,
+                                                null));
+            }
+        }
+
+        attViewer.setInput(updatedRepresentation);
 
-        attTblViewer.setInput(modelList.toArray());
+        attViewer.expandAll();
 
         return compLayout;
     }
 
-    private void createTableViewer(Composite parent) {
-        attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
-                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+    private void createTreeViewer(Composite parent) {
+        Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+        addressTree.setHeaderVisible(true);
+
+        attViewer = new TreeViewer(addressTree);
 
-        createAttributeColumns(attTblViewer);
+        createAttributeColumns(attViewer);
 
         // make lines and header visible
-        Table table = attTblViewer.getTable();
-        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        table.setHeaderVisible(true);
-        table.setLinesVisible(true);
+        Tree tree = attViewer.getTree();
+        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        tree.setHeaderVisible(true);
+        tree.setLinesVisible(true);
 
-        attTblViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setLabelProvider(new AttributeLabelProvider());
     }
 
-    public void createAttributeColumns(TableViewer tableViewer) {
+    public void createAttributeColumns(TreeViewer viewer) {
+        Tree tree = viewer.getTree();
 
-        // attributeEditor = new AttributeEditingSupport();
+        attributeEditor = new AttributeEditingSupport();
 
-        TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
-        attName.getColumn().setWidth(attTblColWidth[0]);
-        attName.getColumn().setText(attTblHeaders[0]);
-        attName.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof PutPostAttributeModel) {
-                    PutPostAttributeModel entry = (PutPostAttributeModel) element;
-                    cell.setText(entry.getAttName());
-                }
+        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;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                });
             }
-        });
+        }
+    }
 
-        TableViewerColumn attValue = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        attValue.getColumn().setWidth(attTblColWidth[1]);
-        attValue.getColumn().setText(attTblHeaders[1]);
-        attValue.setLabelProvider(new StyledCellLabelProvider() {
+    private void addMenuToOneDimensionalTopLevelModelAttributes(Menu menu) {
+        // Menu to add items to the array.
+        MenuItem addItems = new MenuItem(menu, SWT.NONE);
+        addItems.setText("Add Items");
+        addItems.addSelectionListener(new SelectionAdapter() {
             @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof PutPostAttributeModel) {
-                    PutPostAttributeModel entry = (PutPostAttributeModel) element;
-                    cell.setText(entry.getAttValue());
+            public void widgetSelected(SelectionEvent e) {
+                // Get the attributes.
+                ResourceRepresentation representation;
+                representation = getRepresentationForOneDimensionTopLevelAttribute();
+                if (null == representation) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "Unable to perform the operation.",
+                                    "Failed to obtain the required data. Operation cannot be performed.");
+                } else {
+                    ModelArrayAddItemDialog dialog = new ModelArrayAddItemDialog(
+                            Display.getDefault().getActiveShell(),
+                            PostRequestDialog.this, representation);
+                    if (Window.OK == dialog.open()) {
+                        // Add the new item to the local resource
+                        // representation.
+                        AttributeElement newElement = (AttributeElement) representation
+                                .getAttributes().values().toArray()[0];
+                        SimulatorResourceAttribute newAttribute = newElement
+                                .getSimulatorResourceAttribute();
+                        SimulatorResourceModel newModel = (SimulatorResourceModel) newAttribute
+                                .value().get();
+
+                        AttributeElement attElement = getSelectedElement();
+                        if (null == attElement) {
+                            MessageDialog
+                                    .openError(Display.getDefault()
+                                            .getActiveShell(),
+                                            "Unable to perform the operation.",
+                                            "Failed to obtain the required data. Operation cannot be performed.");
+                            return;
+                        }
+
+                        SimulatorResourceAttribute attribute = attElement
+                                .getSimulatorResourceAttribute();
+                        SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) attribute
+                                .value().get();
+                        SimulatorResourceModel[] newModelArray = new SimulatorResourceModel[modelArray.length + 1];
+
+                        int i;
+                        for (i = 0; i < modelArray.length; i++) {
+                            newModelArray[i] = modelArray[i];
+                        }
+                        newModelArray[i] = newModel;
+
+                        AttributeValue newValue = new AttributeValue(
+                                newModelArray);
+
+                        newAttribute.setValue(newValue);
+
+                        newAttribute.setProperty(attribute.property());
+
+                        attribute.setValue(newValue);
+
+                        attElement.update(newAttribute);
+
+                        attElement.setPostState(true);
+
+                        attViewer.refresh(attElement);
+
+                        attViewer.expandAll();
+                    }
                 }
             }
         });
-        attValue.setEditingSupport(new AttributeValueEditor(attTblViewer));
+    }
 
-        TableViewerColumn updateColumn = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        updateColumn.getColumn().setWidth(attTblColWidth[2]);
-        updateColumn.getColumn().setText(attTblHeaders[2]);
-        updateColumn.setLabelProvider(new ColumnLabelProvider() {
+    private void addDeleteMenuToArrayItemsOfOneDimensionalModelAttribute(
+            final Menu menu, final AttributeElement elementToDelete,
+            final AttributeElement parentElement) {
+        // Menu to add items to the array.
+        MenuItem addItems = new MenuItem(menu, SWT.NONE);
+        addItems.setText("Delete Item");
+        addItems.addSelectionListener(new SelectionAdapter() {
             @Override
-            public String getText(Object element) {
-                return "";
-            }
+            public void widgetSelected(SelectionEvent e) {
+                MessageBox dialog = new MessageBox(menu.getShell(),
+                        SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
+                dialog.setText("Confirm action");
+                dialog.setMessage("Do you want to delete this item from the array?");
+                int retval = dialog.open();
+                if (retval != SWT.OK) {
+                    return;
+                }
 
-            @Override
-            public Image getImage(Object element) {
-                PutPostAttributeModel model = (PutPostAttributeModel) element;
-                if (model.isModified()) {
-                    return Activator.getDefault().getImageRegistry()
-                            .get(Constants.CHECKED);
+                // Removing the element from the attribute value.
+                SimulatorResourceAttribute parentSRA = parentElement
+                        .getSimulatorResourceAttribute();
+                AttributeValue value = parentSRA.value();
+                SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) value
+                        .get();
+
+                String elementIndexName = elementToDelete
+                        .getSimulatorResourceAttribute().name();
+                int elementIndex = Integer.parseInt(elementIndexName.substring(
+                        elementIndexName.indexOf('[') + 1,
+                        elementIndexName.indexOf(']')));
+
+                SimulatorResourceModel[] newModelArray = new SimulatorResourceModel[modelArray.length - 1];
+                int sIndex = 0, dIndex = 0;
+                for (SimulatorResourceModel model : modelArray) {
+                    if (sIndex != elementIndex)
+                        newModelArray[dIndex++] = model;
+                    sIndex++;
+                }
+
+                // Setting the new model array in the attribute.
+                AttributeValue newValue = new AttributeValue(newModelArray);
+                parentSRA.setValue(newValue);
+
+                // Removing the element from the child map.
+                Map<String, AttributeElement> elements = parentElement
+                        .getChildren();
+                if (null == elements) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "Operation failed.",
+                                    "There is an error while removing the array items.");
+                    return;
+                }
+
+                List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
+                attElementList.addAll(elements.values());
+                Collections.sort(attElementList, Utility.attributeComparator);
+
+                // Renaming the index of the elements.
+                AttributeElement[] attElementArray = attElementList
+                        .toArray(new AttributeElement[0]);
+                boolean deleted = false;
+                int index, newIndex;
+                for (index = 0, newIndex = 0; index < attElementArray.length; index++) {
+                    if (index == elementIndex) {
+                        elements.remove(elementIndexName);
+                        deleted = true;
+                    } else {
+                        if (deleted) {
+                            AttributeElement element = attElementArray[index];
+                            String curIndexStr = "[" + index + "]";
+                            String newIndexStr = "[" + newIndex + "]";
+
+                            element.getSimulatorResourceAttribute().setName(
+                                    newIndexStr);
+
+                            elements.remove(curIndexStr);
+                            elements.put(newIndexStr, element);
+                        }
+                        newIndex++;
+                    }
                 }
-                return Activator.getDefault().getImageRegistry()
-                        .get(Constants.UNCHECKED);
+
+                parentElement.setPostState(true);
+
+                attViewer.refresh(parentElement);
             }
         });
-        updateColumn.setEditingSupport(new UpdateEditor(attTblViewer));
     }
 
-    @Override
-    protected boolean isResizable() {
-        return true;
-    }
+    private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
+        ResourceRepresentation representation;
 
-    @Override
-    public boolean isHelpAvailable() {
-        return false;
-    }
+        AttributeValue value;
+        ModelProperty property = null;
 
-    @Override
-    protected Button createButton(Composite parent, int id, String label,
-            boolean defaultButton) {
-        if (id == IDialogConstants.OK_ID) {
-            label = "POST";
+        AttributeElement element = getSelectedElement();
+        if (null == element)
+            return null;
+
+        SimulatorResourceAttribute modelArrayAtt = element
+                .getSimulatorResourceAttribute();
+        if (null == modelArrayAtt) {
+            return null;
         }
-        return super.createButton(parent, id, label, defaultButton);
+
+        AttributeValue attValue = modelArrayAtt.value();
+        if (null == attValue) {
+            return null;
+        }
+
+        TypeInfo type = attValue.typeInfo();
+
+        if (!(type.mType == ValueType.ARRAY
+                && type.mBaseType == ValueType.RESOURCEMODEL && type.mDepth == 1)) {
+            return null;
+        }
+
+        SimulatorResourceModel[] modelValue = (SimulatorResourceModel[]) attValue
+                .get();
+        if (null == modelValue || modelValue.length < 0) {
+            return null;
+        }
+
+        // Clone an instance of model value.
+        try {
+            value = Utility.cloneAttributeValue(new AttributeValue(
+                    modelValue[0]));
+        } catch (Exception e) {
+            return null;
+        }
+
+        if (null == value) {
+            return null;
+        }
+
+        // Get the model property of the model value instance.
+        AttributeProperty attProperty = modelArrayAtt.property();
+        if (null != attProperty && attProperty instanceof ArrayProperty) {
+            ArrayProperty prop = attProperty.asArray();
+            if (null != prop) {
+                AttributeProperty elementProperty = prop.getElementProperty();
+                if (null != elementProperty && elementProperty.isModel()) {
+                    property = elementProperty.asModel();
+                }
+            }
+        }
+
+        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
+                modelArrayAtt.name(), value, property);
+        Map<String, SimulatorResourceAttribute> attributes = new HashMap<String, SimulatorResourceAttribute>();
+        attributes.put(modelArrayAtt.name(), attribute);
+        representation = new ResourceRepresentation(attributes, false);
+
+        return representation;
     }
 
-    class AttributeContentProvider implements IStructuredContentProvider {
+    private AttributeElement getSelectedElement() {
+        IStructuredSelection selection = (IStructuredSelection) attViewer
+                .getSelection();
+        if (null == selection) {
+            return null;
+        }
 
-        @Override
-        public void dispose() {
+        Object obj = selection.getFirstElement();
+        if (null == obj) {
+            return null;
         }
 
-        @Override
-        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        Tree t = attViewer.getTree();
+        TreeItem item = t.getSelection()[0];
+        if (null == item) {
+            return null;
         }
 
-        @Override
-        public Object[] getElements(Object element) {
-            return (Object[]) element;
+        if (!(item.getData() instanceof AttributeElement)) {
+            return null;
         }
 
+        return (AttributeElement) item.getData();
     }
 
-    class AttributeValueEditor extends EditingSupport {
-        private final TableViewer viewer;
-        private final CellEditor  editor;
-        private final Text txt;
-        public AttributeValueEditor(TableViewer viewer) {
-            super(viewer);
-            this.viewer = viewer;
-            editor = new TextCellEditor(viewer.getTable());
-            txt = (Text)editor.getControl();
-            if(null != txt) {
-                txt.addModifyListener(new ModifyListener() {
-                    @Override
-                    public void modifyText(ModifyEvent e) {                 
-                        IStructuredSelection selection = (IStructuredSelection)AttributeValueEditor.this.viewer.getSelection();
-                        PutPostAttributeModel att = (PutPostAttributeModel)selection.getFirstElement();             
-                        if(null == att) {
-                            return;
-                        }
-                        String newValue = txt.getText();
-                        if(null != newValue && !newValue.isEmpty()) {
-                            att.setModified(true);
-                        }
-                        else {
-                            att.setModified(false);
-                        }
-                        AttributeValueEditor.this.viewer.update(att, null);
-                    }
-                });
-              
-            }
+    private static class AttributeContentProvider implements
+            ITreeContentProvider {
+
+        @Override
+        public void dispose() {
         }
 
         @Override
-        protected boolean canEdit(Object arg0) {
-            return true;
+        public void inputChanged(Viewer viewer, Object oldAttribute,
+                Object newAttribute) {
         }
 
         @Override
-        protected CellEditor getCellEditor(Object element) {
-            return editor;
+        public Object[] getChildren(Object attribute) {
+            if (attribute instanceof AttributeElement) {
+                List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
+                Map<String, AttributeElement> children = ((AttributeElement) attribute)
+                        .getChildren();
+                if (null != children) {
+                    attElementList.addAll(children.values());
+                    Collections.sort(attElementList,
+                            Utility.attributeComparator);
+                    return attElementList.toArray();
+                }
+            }
+
+            return new Object[0];
+        }
+
+        @Override
+        public Object getParent(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).getParent();
+            return null;
         }
 
         @Override
-        protected Object getValue(Object element) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            return model.getAttValue();
+        public boolean hasChildren(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).hasChildren();
+            return false;
         }
 
         @Override
-        protected void setValue(Object element, Object value) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            // Compare the actual value and the new value
-            // If there is a change, then its corresponding check box should be
-            // checked.
-            String newValue = String.valueOf(value);
-            model.setAttValue(newValue);
-            viewer.update(element, null);
+        public Object[] getElements(Object resourceModel) {
+            if (resourceModel instanceof ResourceRepresentation) {
+                return ((ResourceRepresentation) resourceModel).getAttributes()
+                        .values().toArray();
+            }
+
+            return new Object[0];
         }
     }
 
-    class UpdateEditor extends EditingSupport {
+    private static class AttributeLabelProvider implements ITableLabelProvider {
 
-        private final TableViewer viewer;
+        @Override
+        public void addListener(ILabelProviderListener arg0) {
+        }
 
-        public UpdateEditor(TableViewer viewer) {
-            super(viewer);
-            this.viewer = viewer;
+        @Override
+        public void dispose() {
         }
 
         @Override
-        protected boolean canEdit(Object arg0) {
-            return true;
+        public boolean isLabelProperty(Object arg0, String arg1) {
+            return false;
         }
 
         @Override
-        protected CellEditor getCellEditor(Object element) {
-            return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+        public void removeListener(ILabelProviderListener arg0) {
+
         }
 
         @Override
-        protected Object getValue(Object element) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            return model.isModified();
+        public Image getColumnImage(Object element, int col) {
+            if (col == 2) {
+                if (element instanceof AttributeElement) {
+
+                    AttributeElement attrElement = (AttributeElement) element;
+                    Object parent = attrElement.getParent();
+                    if (null == parent
+                            || parent instanceof ResourceRepresentation) {
+                        if (attrElement.getPostState()) {
+                            return Activator.getDefault().getImageRegistry()
+                                    .get(Constants.CHECKED);
+                        } else {
+                            return Activator.getDefault().getImageRegistry()
+                                    .get(Constants.UNCHECKED);
+                        }
+                    }
+                }
+            }
+
+            return null;
         }
 
         @Override
-        protected void setValue(Object element, Object value) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            boolean status = (boolean) value;
-            model.setModified(status);
-            viewer.update(element, null);
+        public String getColumnText(Object element, int column) {
+            if (element instanceof AttributeElement) {
+                AttributeElement attrElement = (AttributeElement) element;
+                switch (column) {
+                    case 0: // Attribute name column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+                        return attribute.name();
+                    }
+
+                    case 1: // Attribute value column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+
+                        if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) {
+                            String value = Utility
+                                    .getAttributeValueAsString(attribute
+                                            .value());
+                            if (null == value) {
+                                value = "";
+                            }
+                            return value;
+                        }
+                        return null;
+                    }
+
+                    case 2: {
+                        return "";
+                    }
+                }
+            }
+            return null;
+        }
+    }
+
+    @Override
+    protected boolean isResizable() {
+        return true;
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+
+    @Override
+    protected Button createButton(Composite parent, int id, String label,
+            boolean defaultButton) {
+        if (id == IDialogConstants.OK_ID) {
+            label = "POST";
+        }
+        return super.createButton(parent, id, label, defaultButton);
+    }
+
+    public ResourceRepresentation getUpdatedRepresentation() {
+        return updatedRepresentation;
+    }
+
+    public String getIfType() {
+        if (ifTypes.containsKey(ifType)) {
+            return ifTypes.get(ifType);
         }
+        return ifType;
     }
 }