Resolved issues and concerns found during overall functionality testing.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / PostRequestDialog.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.clientcontroller.view.dialogs;
18
19 import org.eclipse.jface.dialogs.IDialogConstants;
20 import org.eclipse.jface.dialogs.MessageDialog;
21 import org.eclipse.jface.dialogs.TitleAreaDialog;
22 import org.eclipse.jface.viewers.ILabelProviderListener;
23 import org.eclipse.jface.viewers.IStructuredSelection;
24 import org.eclipse.jface.viewers.ITableLabelProvider;
25 import org.eclipse.jface.viewers.ITreeContentProvider;
26 import org.eclipse.jface.viewers.TreeViewer;
27 import org.eclipse.jface.viewers.TreeViewerColumn;
28 import org.eclipse.jface.viewers.Viewer;
29 import org.eclipse.jface.window.Window;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.events.MenuAdapter;
32 import org.eclipse.swt.events.MenuEvent;
33 import org.eclipse.swt.events.ModifyEvent;
34 import org.eclipse.swt.events.ModifyListener;
35 import org.eclipse.swt.events.SelectionAdapter;
36 import org.eclipse.swt.events.SelectionEvent;
37 import org.eclipse.swt.graphics.Image;
38 import org.eclipse.swt.layout.GridData;
39 import org.eclipse.swt.layout.GridLayout;
40 import org.eclipse.swt.widgets.Button;
41 import org.eclipse.swt.widgets.Combo;
42 import org.eclipse.swt.widgets.Composite;
43 import org.eclipse.swt.widgets.Control;
44 import org.eclipse.swt.widgets.Display;
45 import org.eclipse.swt.widgets.Group;
46 import org.eclipse.swt.widgets.Label;
47 import org.eclipse.swt.widgets.Menu;
48 import org.eclipse.swt.widgets.MenuItem;
49 import org.eclipse.swt.widgets.MessageBox;
50 import org.eclipse.swt.widgets.Shell;
51 import org.eclipse.swt.widgets.Tree;
52 import org.eclipse.swt.widgets.TreeColumn;
53 import org.eclipse.swt.widgets.TreeItem;
54
55 import java.util.ArrayList;
56 import java.util.Collections;
57 import java.util.HashMap;
58 import java.util.Iterator;
59 import java.util.List;
60 import java.util.Map;
61 import java.util.Vector;
62
63 import org.oic.simulator.ArrayProperty;
64 import org.oic.simulator.AttributeProperty;
65 import org.oic.simulator.AttributeValue;
66 import org.oic.simulator.AttributeValue.TypeInfo;
67 import org.oic.simulator.AttributeValue.ValueType;
68 import org.oic.simulator.ModelProperty;
69 import org.oic.simulator.SimulatorResourceAttribute;
70 import org.oic.simulator.SimulatorResourceModel;
71 import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
72
73 import oic.simulator.clientcontroller.Activator;
74 import oic.simulator.clientcontroller.remoteresource.AttributeElement;
75 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
76 import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
77 import oic.simulator.clientcontroller.utils.Constants;
78 import oic.simulator.clientcontroller.utils.Utility;
79 import oic.simulator.clientcontroller.view.AttributeEditingSupport;
80
81 /**
82  * This dialog is used for generating a POST request.
83  */
84 public class PostRequestDialog extends TitleAreaDialog {
85
86     private TreeViewer              attViewer;
87     private Combo                   ifTypesCmb;
88
89     private String                  ifType;
90
91     private Map<String, String>     ifTypes;
92
93     private AttributeEditingSupport attributeEditor;
94
95     private ResourceRepresentation  updatedRepresentation;
96
97     private final String[]          attTblHeaders  = { "Name", "Value",
98             "Select"                              };
99     private final Integer[]         attTblColWidth = { 200, 200, 50 };
100
101     public PostRequestDialog(Shell parentShell) {
102         super(parentShell);
103     }
104
105     @Override
106     public void create() {
107         super.create();
108         setTitle("Generate POST Request");
109         setMessage("Dialog which takes input and generates a post request.");
110     }
111
112     @Override
113     protected Control createDialogArea(Composite parent) {
114         Composite compLayout = (Composite) super.createDialogArea(parent);
115
116         Composite rootContainer = new Composite(compLayout, SWT.NONE);
117         GridLayout layout = new GridLayout();
118         rootContainer.setLayout(layout);
119         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
120         rootContainer.setLayoutData(gd);
121
122         Group paramsGrp = new Group(rootContainer, SWT.NONE);
123         gd = new GridData();
124         gd.horizontalAlignment = SWT.FILL;
125         gd.grabExcessHorizontalSpace = true;
126         gd.minimumHeight = 50;
127         paramsGrp.setLayoutData(gd);
128         layout = new GridLayout(2, false);
129         layout.verticalSpacing = 10;
130         layout.marginTop = 10;
131         paramsGrp.setLayout(layout);
132
133         Label ifTypeLbl = new Label(paramsGrp, SWT.NONE);
134         ifTypeLbl.setText("Interface Type");
135
136         ifTypesCmb = new Combo(paramsGrp, SWT.NULL);
137         gd = new GridData();
138         gd.grabExcessHorizontalSpace = true;
139         gd.horizontalAlignment = SWT.FILL;
140         ifTypesCmb.setLayoutData(gd);
141         ifTypesCmb.addModifyListener(new ModifyListener() {
142             @Override
143             public void modifyText(ModifyEvent e) {
144                 ifType = ifTypesCmb.getText();
145             }
146         });
147
148         RemoteResource resource = Activator.getDefault().getResourceManager()
149                 .getCurrentResourceInSelection();
150
151         // Set the interface types in combo box.
152         Map<String, String> ifTypes = Utility.getResourceInterfaces();
153         this.ifTypes = new HashMap<String, String>();
154         String key;
155         for (Map.Entry<String, String> entry : ifTypes.entrySet()) {
156             key = entry.getValue() + " (" + entry.getKey() + ")";
157             this.ifTypes.put(key, entry.getKey());
158             ifTypesCmb.add(key);
159         }
160
161         // Select the default value to be shown in the interface types combo.
162         Vector<String> ifTypesSupportedByResource = resource
163                 .getRemoteResourceRef().getResourceInterfaces();
164         if (null != ifTypesSupportedByResource) {
165             int index = -1;
166             if (ifTypesSupportedByResource
167                     .contains(Constants.BASELINE_INTERFACE)
168                     && ifTypes.containsKey(Constants.BASELINE_INTERFACE)) {
169                 // Baseline interface is given preference to be shown in the if
170                 // types combo.
171                 String value = ifTypes.get(Constants.BASELINE_INTERFACE);
172                 index = ifTypesCmb.indexOf(value + " ("
173                         + Constants.BASELINE_INTERFACE + ")");
174                 if (index != -1)
175                     ifTypesCmb.select(index);
176             }
177             if (index == -1) {
178                 // Baseline interface is not selected so selecting some other
179                 // interface supported by the resource.
180                 Iterator<String> itr = ifTypesSupportedByResource.iterator();
181                 while (itr.hasNext() && index == -1) {
182                     key = itr.next();
183                     if (ifTypes.containsKey(key)) {
184                         String value = ifTypes.get(key);
185                         index = ifTypesCmb.indexOf(value + " (" + key + ")");
186                         if (index != -1) {
187                             ifTypesCmb.select(index);
188                             break;
189                         }
190                     }
191                 }
192                 if (index == -1 && !ifTypesSupportedByResource.isEmpty()) {
193                     // Resource has custom interfaces.
194                     ifTypesCmb.setText(ifTypesSupportedByResource.get(0));
195                 }
196             }
197         }
198
199         Composite container = new Composite(rootContainer, SWT.NONE);
200         container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
201         layout = new GridLayout(1, false);
202         layout.verticalSpacing = 10;
203         layout.marginTop = 10;
204         container.setLayout(layout);
205
206         createTreeViewer(container);
207
208         // Clone the resource model for maintaining a local copy of attributes
209         // for PUT requests.
210         SimulatorResourceModel resourceModel = null;
211         try {
212             resourceModel = (SimulatorResourceModel) Utility
213                     .cloneAttributeValue(
214                             new AttributeValue(resource.getResourceModelRef()))
215                     .get();
216         } catch (Exception e2) {
217         }
218
219         if (null == resourceModel) {
220             // Failed to clone. So taking the base copy and continuing the
221             // operation.
222             resourceModel = resource.getResourceModelRef();
223         }
224
225         updatedRepresentation = new ResourceRepresentation(resourceModel);
226
227         if (resource.isConfigUploaded()) {
228             try {
229                 // Request Type needs to be changed to PUT.
230                 updatedRepresentation.updateAttributeProperties(resource
231                         .getRequestModels().get(RequestType.POST),
232                         resourceModel);
233             } catch (Exception e1) {
234             }
235         }
236
237         attViewer.setInput(updatedRepresentation);
238
239         attViewer.expandAll();
240
241         return compLayout;
242     }
243
244     private void createTreeViewer(Composite parent) {
245         Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER
246                 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
247         addressTree.setHeaderVisible(true);
248
249         attViewer = new TreeViewer(addressTree);
250
251         createAttributeColumns(attViewer);
252
253         // make lines and header visible
254         Tree tree = attViewer.getTree();
255         tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
256         tree.setHeaderVisible(true);
257         tree.setLinesVisible(true);
258
259         attViewer.setContentProvider(new AttributeContentProvider());
260         attViewer.setLabelProvider(new AttributeLabelProvider());
261     }
262
263     public void createAttributeColumns(TreeViewer viewer) {
264         Tree tree = viewer.getTree();
265
266         attributeEditor = new AttributeEditingSupport();
267
268         TreeColumn attName = new TreeColumn(tree, SWT.NONE);
269         attName.setWidth(attTblColWidth[0]);
270         attName.setText(attTblHeaders[0]);
271
272         TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
273         attValue.setWidth(attTblColWidth[1]);
274         attValue.setText(attTblHeaders[1]);
275         TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
276                 attValue);
277         attValueVwrCol.setEditingSupport(attributeEditor
278                 .createAttributeValueEditor(attViewer, this));
279
280         TreeColumn updateColumn = new TreeColumn(tree, SWT.NONE);
281         updateColumn.setWidth(attTblColWidth[2]);
282         updateColumn.setText(attTblHeaders[2]);
283         TreeViewerColumn updateVwrCol = new TreeViewerColumn(attViewer,
284                 updateColumn);
285         updateVwrCol.setEditingSupport(attributeEditor
286                 .createPostSelectionEditor(attViewer));
287
288         addMenuItems();
289     }
290
291     private void addMenuItems() {
292         if (null != attViewer) {
293             final Tree resourceTreeHead = attViewer.getTree();
294             if (null != resourceTreeHead) {
295                 // Below code creates menu entries and shows them on right
296                 // clicking a resource
297                 final Menu menu = new Menu(resourceTreeHead);
298                 resourceTreeHead.setMenu(menu);
299                 menu.addMenuListener(new MenuAdapter() {
300                     @Override
301                     public void menuShown(MenuEvent e) {
302                         // Clear existing menu items
303                         MenuItem[] items = menu.getItems();
304                         for (int index = 0; index < items.length; index++) {
305                             items[index].dispose();
306                         }
307
308                         IStructuredSelection selection = ((IStructuredSelection) attViewer
309                                 .getSelection());
310                         final AttributeElement attElement = (AttributeElement) selection
311                                 .getFirstElement();
312                         if (null == attElement) {
313                             return;
314                         }
315
316                         // Check the type of attribute.
317                         SimulatorResourceAttribute attribute = attElement
318                                 .getSimulatorResourceAttribute();
319                         if (null == attribute) {
320                             return;
321                         }
322
323                         AttributeValue value = attribute.value();
324                         if (null == value || null == value.get()) {
325                             return;
326                         }
327
328                         TypeInfo type = value.typeInfo();
329
330                         final Object parent = attElement.getParent();
331
332                         if ((type.mType == ValueType.ARRAY
333                                 && type.mBaseType == ValueType.RESOURCEMODEL && type.mDepth == 1)
334                                 && (null == parent || parent instanceof ResourceRepresentation)) {
335                             addMenuToOneDimensionalTopLevelModelAttributes(menu);
336                             return;
337                         }
338
339                         if (null != parent
340                                 && !(parent instanceof ResourceRepresentation)) {
341                             Object grandParent = ((AttributeElement) parent)
342                                     .getParent();
343                             if (null == grandParent
344                                     || grandParent instanceof ResourceRepresentation) {
345                                 AttributeElement parentElement = (AttributeElement) parent;
346
347                                 // Check the type of attribute.
348                                 SimulatorResourceAttribute parentAttribute = parentElement
349                                         .getSimulatorResourceAttribute();
350                                 if (null != parentAttribute
351                                         && null != parentAttribute.value()
352                                         && null != parentAttribute.value()
353                                                 .get()) {
354                                     AttributeValue parentValue = parentAttribute
355                                             .value();
356
357                                     TypeInfo parentType = parentValue
358                                             .typeInfo();
359                                     if (parentType.mType == ValueType.ARRAY
360                                             && parentType.mBaseType == ValueType.RESOURCEMODEL
361                                             && parentType.mDepth == 1) {
362                                         addDeleteMenuToArrayItemsOfOneDimensionalModelAttribute(
363                                                 menu, attElement, parentElement);
364                                         return;
365                                     }
366                                 }
367                             }
368                         }
369                     }
370                 });
371             }
372         }
373     }
374
375     private void addMenuToOneDimensionalTopLevelModelAttributes(Menu menu) {
376         // Menu to add items to the array.
377         MenuItem addItems = new MenuItem(menu, SWT.NONE);
378         addItems.setText("Add Items");
379         addItems.addSelectionListener(new SelectionAdapter() {
380             @Override
381             public void widgetSelected(SelectionEvent e) {
382                 // Get the attributes.
383                 ResourceRepresentation representation;
384                 representation = getRepresentationForOneDimensionTopLevelAttribute();
385                 if (null == representation) {
386                     MessageDialog
387                             .openError(Display.getDefault().getActiveShell(),
388                                     "Unable to perform the operation.",
389                                     "Failed to obtain the required data. Operation cannot be performed.");
390                 } else {
391                     ModelArrayAddItemDialog dialog = new ModelArrayAddItemDialog(
392                             Display.getDefault().getActiveShell(),
393                             PostRequestDialog.this, representation);
394                     if (Window.OK == dialog.open()) {
395                         // Add the new item to the local resource
396                         // representation.
397                         AttributeElement newElement = (AttributeElement) representation
398                                 .getAttributes().values().toArray()[0];
399                         SimulatorResourceAttribute newAttribute = newElement
400                                 .getSimulatorResourceAttribute();
401                         SimulatorResourceModel newModel = (SimulatorResourceModel) newAttribute
402                                 .value().get();
403
404                         AttributeElement attElement = getSelectedElement();
405                         SimulatorResourceAttribute attribute = attElement
406                                 .getSimulatorResourceAttribute();
407                         SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) attribute
408                                 .value().get();
409                         SimulatorResourceModel[] newModelArray = new SimulatorResourceModel[modelArray.length + 1];
410
411                         int i;
412                         for (i = 0; i < modelArray.length; i++) {
413                             newModelArray[i] = modelArray[i];
414                         }
415                         newModelArray[i] = newModel;
416
417                         AttributeValue newValue = new AttributeValue(
418                                 newModelArray);
419
420                         newAttribute.setValue(newValue);
421
422                         newAttribute.setProperty(attribute.property());
423
424                         attribute.setValue(newValue);
425
426                         attElement.update(newAttribute);
427
428                         attElement.setPostState(true);
429
430                         attViewer.refresh(attElement);
431
432                         attViewer.expandAll();
433                     }
434                 }
435             }
436         });
437     }
438
439     private void addDeleteMenuToArrayItemsOfOneDimensionalModelAttribute(
440             final Menu menu, final AttributeElement elementToDelete,
441             final AttributeElement parentElement) {
442         // Menu to add items to the array.
443         MenuItem addItems = new MenuItem(menu, SWT.NONE);
444         addItems.setText("Delete Item");
445         addItems.addSelectionListener(new SelectionAdapter() {
446             @Override
447             public void widgetSelected(SelectionEvent e) {
448                 MessageBox dialog = new MessageBox(menu.getShell(),
449                         SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
450                 dialog.setText("Confirm action");
451                 dialog.setMessage("Do you want to delete this item from the array?");
452                 int retval = dialog.open();
453                 if (retval != SWT.OK) {
454                     return;
455                 }
456
457                 // Removing the element from the attribute value.
458                 SimulatorResourceAttribute parentSRA = parentElement
459                         .getSimulatorResourceAttribute();
460                 AttributeValue value = parentSRA.value();
461                 SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) value
462                         .get();
463
464                 String elementIndexName = elementToDelete
465                         .getSimulatorResourceAttribute().name();
466                 int elementIndex = Integer.parseInt(elementIndexName.substring(
467                         elementIndexName.indexOf('[') + 1,
468                         elementIndexName.indexOf(']')));
469
470                 SimulatorResourceModel[] newModelArray = new SimulatorResourceModel[modelArray.length - 1];
471                 int sIndex = 0, dIndex = 0;
472                 for (SimulatorResourceModel model : modelArray) {
473                     if (sIndex != elementIndex)
474                         newModelArray[dIndex++] = model;
475                     sIndex++;
476                 }
477
478                 // Setting the new model array in the attribute.
479                 AttributeValue newValue = new AttributeValue(newModelArray);
480                 parentSRA.setValue(newValue);
481
482                 // Removing the element from the child map.
483                 Map<String, AttributeElement> elements = parentElement
484                         .getChildren();
485                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
486                 attElementList.addAll(elements.values());
487                 Collections.sort(attElementList, Utility.attributeComparator);
488
489                 // Renaming the index of the elements.
490                 AttributeElement[] attElementArray = attElementList
491                         .toArray(new AttributeElement[0]);
492                 boolean deleted = false;
493                 int index, newIndex;
494                 for (index = 0, newIndex = 0; index < attElementArray.length; index++) {
495                     if (index == elementIndex) {
496                         elements.remove(elementIndexName);
497                         deleted = true;
498                     } else {
499                         if (deleted) {
500                             AttributeElement element = attElementArray[index];
501                             String curIndexStr = "[" + index + "]";
502                             String newIndexStr = "[" + newIndex + "]";
503
504                             element.getSimulatorResourceAttribute().setName(
505                                     newIndexStr);
506
507                             elements.remove(curIndexStr);
508                             elements.put(newIndexStr, element);
509                         }
510                         newIndex++;
511                     }
512                 }
513
514                 parentElement.setPostState(true);
515
516                 attViewer.refresh(parentElement);
517             }
518         });
519     }
520
521     private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
522         ResourceRepresentation representation = null;
523
524         AttributeValue value = null;
525         ModelProperty property = null;
526
527         AttributeElement element = getSelectedElement();
528         if (null == element)
529             return null;
530
531         SimulatorResourceAttribute modelArrayAtt = element
532                 .getSimulatorResourceAttribute();
533         if (null == modelArrayAtt) {
534             return null;
535         }
536
537         AttributeValue attValue = modelArrayAtt.value();
538         if (null == attValue) {
539             return null;
540         }
541
542         TypeInfo type = attValue.typeInfo();
543
544         if (!(type.mType == ValueType.ARRAY
545                 && type.mBaseType == ValueType.RESOURCEMODEL && type.mDepth == 1)) {
546             return null;
547         }
548
549         SimulatorResourceModel[] modelValue = (SimulatorResourceModel[]) attValue
550                 .get();
551         if (null == modelValue || modelValue.length < 0) {
552             return null;
553         }
554
555         // Clone an instance of model value.
556         try {
557             value = Utility.cloneAttributeValue(new AttributeValue(
558                     modelValue[0]));
559         } catch (Exception e) {
560             return null;
561         }
562
563         if (null == value) {
564             return null;
565         }
566
567         // Get the model property of the model value instance.
568         AttributeProperty attProperty = modelArrayAtt.property();
569         if (null != attProperty && attProperty instanceof ArrayProperty) {
570             ArrayProperty prop = attProperty.asArray();
571             if (null != prop) {
572                 AttributeProperty elementProperty = prop.getElementProperty();
573                 if (null != elementProperty && elementProperty.isModel()) {
574                     property = elementProperty.asModel();
575                 }
576             }
577         }
578
579         SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
580                 modelArrayAtt.name(), value, property);
581         Map<String, SimulatorResourceAttribute> attributes = new HashMap<String, SimulatorResourceAttribute>();
582         attributes.put(modelArrayAtt.name(), attribute);
583         representation = new ResourceRepresentation(attributes, false);
584
585         return representation;
586     }
587
588     private AttributeElement getSelectedElement() {
589         IStructuredSelection selection = (IStructuredSelection) attViewer
590                 .getSelection();
591         if (null == selection) {
592             return null;
593         }
594
595         Object obj = selection.getFirstElement();
596         if (null == obj) {
597             return null;
598         }
599
600         Tree t = attViewer.getTree();
601         TreeItem item = t.getSelection()[0];
602         if (null == item) {
603             return null;
604         }
605
606         if (!(item.getData() instanceof AttributeElement)) {
607             return null;
608         }
609
610         return (AttributeElement) item.getData();
611     }
612
613     class AttributeContentProvider implements ITreeContentProvider {
614
615         @Override
616         public void dispose() {
617         }
618
619         @Override
620         public void inputChanged(Viewer viewer, Object oldAttribute,
621                 Object newAttribute) {
622         }
623
624         @Override
625         public Object[] getChildren(Object attribute) {
626             if (attribute instanceof AttributeElement) {
627                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
628                 attElementList.addAll(((AttributeElement) attribute)
629                         .getChildren().values());
630                 Collections.sort(attElementList, Utility.attributeComparator);
631                 return attElementList.toArray();
632             }
633
634             return new Object[0];
635         }
636
637         @Override
638         public Object getParent(Object attribute) {
639             if (attribute instanceof AttributeElement)
640                 return ((AttributeElement) attribute).getParent();
641             return null;
642         }
643
644         @Override
645         public boolean hasChildren(Object attribute) {
646             if (attribute instanceof AttributeElement)
647                 return ((AttributeElement) attribute).hasChildren();
648             return false;
649         }
650
651         @Override
652         public Object[] getElements(Object resourceModel) {
653             if (resourceModel instanceof ResourceRepresentation) {
654                 return ((ResourceRepresentation) resourceModel).getAttributes()
655                         .values().toArray();
656             }
657
658             return new Object[0];
659         }
660     }
661
662     class AttributeLabelProvider implements ITableLabelProvider {
663
664         @Override
665         public void addListener(ILabelProviderListener arg0) {
666         }
667
668         @Override
669         public void dispose() {
670         }
671
672         @Override
673         public boolean isLabelProperty(Object arg0, String arg1) {
674             return false;
675         }
676
677         @Override
678         public void removeListener(ILabelProviderListener arg0) {
679
680         }
681
682         @Override
683         public Image getColumnImage(Object element, int col) {
684             if (col == 2) {
685                 if (element instanceof AttributeElement) {
686
687                     AttributeElement attrElement = (AttributeElement) element;
688                     Object parent = attrElement.getParent();
689                     if (null == parent
690                             || parent instanceof ResourceRepresentation) {
691                         if (attrElement.getPostState()) {
692                             return Activator.getDefault().getImageRegistry()
693                                     .get(Constants.CHECKED);
694                         } else {
695                             return Activator.getDefault().getImageRegistry()
696                                     .get(Constants.UNCHECKED);
697                         }
698                     }
699                 }
700             }
701
702             return null;
703         }
704
705         @Override
706         public String getColumnText(Object element, int column) {
707             if (element instanceof AttributeElement) {
708                 AttributeElement attrElement = (AttributeElement) element;
709                 switch (column) {
710                     case 0: // Attribute name column
711                     {
712                         SimulatorResourceAttribute attribute = attrElement
713                                 .getSimulatorResourceAttribute();
714                         return attribute.name();
715                     }
716
717                     case 1: // Attribute value column
718                     {
719                         SimulatorResourceAttribute attribute = attrElement
720                                 .getSimulatorResourceAttribute();
721
722                         if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) {
723                             String value = Utility
724                                     .getAttributeValueAsString(attribute
725                                             .value());
726                             if (null == value) {
727                                 value = "";
728                             }
729                             return value;
730                         }
731                         return null;
732                     }
733
734                     case 2: {
735                         return "";
736                     }
737                 }
738             }
739             return null;
740         }
741     }
742
743     @Override
744     protected boolean isResizable() {
745         return true;
746     }
747
748     @Override
749     public boolean isHelpAvailable() {
750         return false;
751     }
752
753     @Override
754     protected Button createButton(Composite parent, int id, String label,
755             boolean defaultButton) {
756         if (id == IDialogConstants.OK_ID) {
757             label = "POST";
758         }
759         return super.createButton(parent, id, label, defaultButton);
760     }
761
762     public ResourceRepresentation getUpdatedRepresentation() {
763         return updatedRepresentation;
764     }
765
766     public String getIfType() {
767         if (ifTypes.containsKey(ifType)) {
768             return ifTypes.get(ifType);
769         }
770         return ifType;
771     }
772 }