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