3a0403a8e3b8fc84bbebbe7fcf7f0fc5626fd490
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / AttributeView.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;
18
19 import java.util.Map;
20
21 import oic.simulator.clientcontroller.Activator;
22 import oic.simulator.clientcontroller.listener.IConfigurationUpload;
23 import oic.simulator.clientcontroller.listener.IGetUIListener;
24 import oic.simulator.clientcontroller.listener.IObserveUIListener;
25 import oic.simulator.clientcontroller.listener.IPostUIListener;
26 import oic.simulator.clientcontroller.listener.IPutUIListener;
27 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
28 import oic.simulator.clientcontroller.listener.IVerificationUIListener;
29 import oic.simulator.clientcontroller.manager.ResourceManager;
30 import oic.simulator.clientcontroller.manager.UiListenerHandler;
31 import oic.simulator.clientcontroller.remoteresource.AttributeElement;
32 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
33 import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
34 import oic.simulator.clientcontroller.utils.Constants;
35 import oic.simulator.clientcontroller.utils.Utility;
36 import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
37 import oic.simulator.clientcontroller.view.dialogs.PutRequestDialog;
38 import oic.simulator.clientcontroller.view.dialogs.VerificationDialog;
39
40 import org.eclipse.jface.dialogs.MessageDialog;
41 import org.eclipse.jface.viewers.ILabelProviderListener;
42 import org.eclipse.jface.viewers.ITableLabelProvider;
43 import org.eclipse.jface.viewers.ITreeContentProvider;
44 import org.eclipse.jface.viewers.TreeViewer;
45 import org.eclipse.jface.viewers.Viewer;
46 import org.eclipse.jface.window.Window;
47 import org.eclipse.swt.SWT;
48 import org.eclipse.swt.events.SelectionAdapter;
49 import org.eclipse.swt.events.SelectionEvent;
50 import org.eclipse.swt.graphics.Color;
51 import org.eclipse.swt.graphics.Image;
52 import org.eclipse.swt.layout.GridData;
53 import org.eclipse.swt.layout.GridLayout;
54 import org.eclipse.swt.widgets.Button;
55 import org.eclipse.swt.widgets.Composite;
56 import org.eclipse.swt.widgets.Display;
57 import org.eclipse.swt.widgets.Group;
58 import org.eclipse.swt.widgets.Tree;
59 import org.eclipse.swt.widgets.TreeColumn;
60 import org.eclipse.ui.PlatformUI;
61 import org.eclipse.ui.part.ViewPart;
62 import org.oic.simulator.AttributeValue.ValueType;
63 import org.oic.simulator.SimulatorResourceAttribute;
64 import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
65
66 /**
67  * This class manages and shows the attribute view in the perspective.
68  */
69 public class AttributeView extends ViewPart {
70
71     public static final String                  VIEW_ID        = "oic.simulator.clientcontroller.view.attribute";
72
73     private TreeViewer                          attViewer;
74
75     private Button                              getButton;
76     private Button                              putButton;
77     private Button                              postButton;
78     private Button                              automateButton;
79     private Button                              observeResButton;
80
81     private final String[]                      attTblHeaders  = {
82             "Attribute Name", "Attribute Value"               };
83     private final Integer[]                     attTblColWidth = { 200, 200 };
84
85     private ResourceManager                     resourceManager;
86
87     private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
88     private IGetUIListener                      getUIListener;
89     private IPutUIListener                      putUIListener;
90     private IPostUIListener                     postUIListener;
91     private IObserveUIListener                  observeUIListener;
92     private IVerificationUIListener             verificationUIListener;
93     private IConfigurationUpload                configUploadUIListener;
94
95     private RemoteResource                      resourceInSelection;
96
97     public AttributeView() {
98         resourceManager = Activator.getDefault().getResourceManager();
99
100         resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
101
102             @Override
103             public void onResourceSelectionChange(final RemoteResource resource) {
104                 Display.getDefault().asyncExec(new Runnable() {
105
106                     @Override
107                     public void run() {
108                         resourceInSelection = resource;
109
110                         // Set visibility of manual and automation controls
111                         setVisibility((resource == null) ? false : true);
112
113                         // Update the attribute table
114                         if (null != attViewer
115                                 && !attViewer.getControl().isDisposed()) {
116                             updateViewer(resource);
117                         }
118
119                         // Update the observe status
120                         updateObserve(resource);
121                     }
122                 });
123             }
124         };
125
126         getUIListener = new IGetUIListener() {
127
128             @Override
129             public void onGetCompleted(final RemoteResource resource) {
130                 Display.getDefault().asyncExec(new Runnable() {
131
132                     @Override
133                     public void run() {
134                         if (null == resource) {
135                             return;
136                         }
137                         // Update the attribute table
138                         if (resourceInSelection != resource) {
139                             return;
140                         }
141                         updateViewer(resource);
142
143                         // Update the observe status
144                         updateObserve(resource);
145                     }
146                 });
147             }
148         };
149
150         putUIListener = new IPutUIListener() {
151
152             @Override
153             public void onPutCompleted(final RemoteResource resource) {
154                 Display.getDefault().asyncExec(new Runnable() {
155
156                     @Override
157                     public void run() {
158                         if (null == resource) {
159                             return;
160                         }
161                         // Update the attribute table
162                         if (resourceInSelection != resource) {
163                             return;
164                         }
165                         updateViewer(resource);
166
167                         // Update the observe status
168                         updateObserve(resource);
169                     }
170                 });
171             }
172         };
173
174         postUIListener = new IPostUIListener() {
175
176             @Override
177             public void onPostCompleted(final RemoteResource resource) {
178                 Display.getDefault().asyncExec(new Runnable() {
179
180                     @Override
181                     public void run() {
182                         if (null == resource) {
183                             return;
184                         }
185                         // Update the attribute table
186                         if (resourceInSelection != resource) {
187                             return;
188                         }
189                         updateViewer(resource);
190
191                         // Update the observe status
192                         updateObserve(resource);
193                     }
194                 });
195             }
196         };
197
198         observeUIListener = new IObserveUIListener() {
199
200             @Override
201             public void onObserveCompleted(final RemoteResource resource) {
202                 Display.getDefault().asyncExec(new Runnable() {
203
204                     @Override
205                     public void run() {
206                         if (null == resource) {
207                             return;
208                         }
209                         // Update the attribute table
210                         if (resourceInSelection != resource) {
211                             return;
212                         }
213                         updateViewer(resource);
214
215                         // Update the observe status
216                         updateObserve(resource);
217                     }
218                 });
219             }
220         };
221
222         verificationUIListener = new IVerificationUIListener() {
223
224             @Override
225             public void onVerificationStarted(final RemoteResource resource,
226                     final int autoType) {
227                 Display.getDefault().asyncExec(new Runnable() {
228
229                     @Override
230                     public void run() {
231                         // changeReqBtnVisibility(autoType, false);
232                     }
233                 });
234             }
235
236             @Override
237             public void onVerificationCompleted(final RemoteResource resource,
238                     final int autoType) {
239                 Display.getDefault().asyncExec(new Runnable() {
240
241                     @Override
242                     public void run() {
243                         // changeReqBtnVisibility(autoType, true);
244                     }
245                 });
246             }
247
248             @Override
249             public void onVerificationAborted(final RemoteResource resource,
250                     final int autoType) {
251                 Display.getDefault().asyncExec(new Runnable() {
252
253                     @Override
254                     public void run() {
255                         // changeReqBtnVisibility(autoType, true);
256                     }
257                 });
258             }
259         };
260
261         configUploadUIListener = new IConfigurationUpload() {
262
263             @Override
264             public void onConfigurationUploaded(final RemoteResource resource) {
265                 Display.getDefault().asyncExec(new Runnable() {
266
267                     @Override
268                     public void run() {
269                         if (null == resource) {
270                             return;
271                         }
272                         if (resourceInSelection != resource) {
273                             return;
274                         }
275                         if (!automateButton.isDisposed()) {
276                             automateButton.setEnabled(true);
277                         }
278                     }
279                 });
280             }
281         };
282     }
283
284     private void changeReqBtnVisibility(int reqType, boolean visibility) {
285         if (reqType == Constants.GET_AUTOMATION_INDEX) {
286             if (!getButton.isDisposed()) {
287                 getButton.setEnabled(visibility);
288             }
289         } else if (reqType == Constants.PUT_AUTOMATION_INDEX) {
290             if (!putButton.isDisposed()) {
291                 putButton.setEnabled(visibility);
292             }
293         } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
294             if (!postButton.isDisposed()) {
295                 postButton.setEnabled(visibility);
296             }
297         }
298     }
299
300     private void updateViewer(RemoteResource resource) {
301         if (null == attViewer) {
302             return;
303         }
304         Tree tree = attViewer.getTree();
305         if (null != resource) {
306             attViewer.setInput(resource.getResourceRepresentation());
307             attViewer.expandAll();
308             if (!tree.isDisposed()) {
309                 tree.setLinesVisible(true);
310             }
311         } else {
312             if (!tree.isDisposed()) {
313                 tree.removeAll();
314                 tree.setLinesVisible(false);
315             }
316         }
317     }
318
319     private void updateObserve(RemoteResource resource) {
320         if (null == resource || observeResButton.isDisposed()) {
321             return;
322         }
323         boolean observed = resource.isObserved();
324         if (observed) {
325             observeResButton.setText(Constants.STOP_OBSERVE);
326         } else {
327             observeResButton.setText(Constants.OBSERVE);
328         }
329     }
330
331     @Override
332     public void createPartControl(Composite parent) {
333         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
334
335         parent.setLayout(new GridLayout());
336         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
337         parent.setLayoutData(gd);
338
339         Group attGroup = new Group(parent, SWT.NONE);
340         attGroup.setLayout(new GridLayout());
341         gd = new GridData();
342         gd.grabExcessHorizontalSpace = true;
343         gd.horizontalAlignment = SWT.FILL;
344         gd.grabExcessVerticalSpace = true;
345         gd.verticalAlignment = SWT.FILL;
346         gd.horizontalSpan = 2;
347         // gd.heightHint = 175;
348         attGroup.setLayoutData(gd);
349         attGroup.setText("Attributes");
350         attGroup.setBackground(color);
351
352         setupAttributeTable(attGroup);
353
354         setupRequestControls(parent);
355
356         setUIListeners();
357
358         addManagerListeners();
359
360         setVisibility(false);
361
362         // Updating the data in the UI as per the resource in selection.
363         if (null != attViewer && !attViewer.getControl().isDisposed()) {
364             updateViewer(resourceManager.getCurrentResourceInSelection());
365         }
366     }
367
368     private void setupRequestControls(Composite parent) {
369         GridData gd;
370         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
371         Composite opsComp = new Composite(parent, SWT.NONE);
372         gd = new GridData();
373         gd.grabExcessHorizontalSpace = true;
374         gd.horizontalAlignment = SWT.FILL;
375         opsComp.setLayoutData(gd);
376         GridLayout grid = new GridLayout(5, false);
377         opsComp.setLayout(grid);
378         opsComp.setBackground(color);
379
380         getButton = new Button(opsComp, SWT.PUSH);
381         getButton.setText("GET");
382         gd = new GridData();
383         gd.grabExcessHorizontalSpace = true;
384         gd.horizontalAlignment = SWT.FILL;
385         gd.widthHint = 50;
386         getButton.setLayoutData(gd);
387
388         putButton = new Button(opsComp, SWT.PUSH);
389         putButton.setText("PUT");
390         gd = new GridData();
391         gd.grabExcessHorizontalSpace = true;
392         gd.horizontalAlignment = SWT.FILL;
393         gd.widthHint = 50;
394         putButton.setLayoutData(gd);
395
396         postButton = new Button(opsComp, SWT.PUSH);
397         postButton.setText("POST");
398         gd = new GridData();
399         gd.grabExcessHorizontalSpace = true;
400         gd.horizontalAlignment = SWT.FILL;
401         gd.widthHint = 50;
402         postButton.setLayoutData(gd);
403
404         observeResButton = new Button(opsComp, SWT.PUSH);
405         observeResButton.setText(Constants.OBSERVE);
406         gd = new GridData();
407         gd.grabExcessHorizontalSpace = true;
408         gd.horizontalAlignment = SWT.FILL;
409         observeResButton.setLayoutData(gd);
410
411         automateButton = new Button(opsComp, SWT.PUSH);
412         automateButton.setText("Automation");
413         gd = new GridData();
414         gd.grabExcessHorizontalSpace = true;
415         gd.horizontalAlignment = SWT.FILL;
416         automateButton.setLayoutData(gd);
417     }
418
419     private void setupAttributeTable(Group attGroup) {
420         Tree addressTree = new Tree(attGroup, SWT.SINGLE | SWT.BORDER
421                 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
422         addressTree.setHeaderVisible(true);
423
424         attViewer = new TreeViewer(addressTree);
425
426         createAttributeColumns(attViewer);
427
428         // make lines and header visible
429         Tree tree = attViewer.getTree();
430         tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
431         tree.setHeaderVisible(true);
432         tree.setLinesVisible(true);
433
434         attViewer.setContentProvider(new AttributeContentProvider());
435         attViewer.setLabelProvider(new AttributeLabelProvider());
436     }
437
438     public void createAttributeColumns(TreeViewer viewer) {
439         Tree tree = viewer.getTree();
440
441         TreeColumn attName = new TreeColumn(tree, SWT.NONE);
442         attName.setWidth(attTblColWidth[0]);
443         attName.setText(attTblHeaders[0]);
444
445         TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
446         attValue.setWidth(attTblColWidth[1]);
447         attValue.setText(attTblHeaders[1]);
448     }
449
450     private void setUIListeners() {
451
452         getButton.addSelectionListener(new SelectionAdapter() {
453             @Override
454             public void widgetSelected(SelectionEvent e) {
455                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
456                     @Override
457                     public void run() {
458                         resourceManager.sendGetRequest(resourceInSelection);
459                     }
460                 });
461             }
462         });
463
464         putButton.addSelectionListener(new SelectionAdapter() {
465             @Override
466             public void widgetSelected(SelectionEvent e) {
467                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
468                     @Override
469                     public void run() {
470                         boolean attributesExist = false;
471                         ResourceRepresentation rep = resourceInSelection
472                                 .getResourceRepresentation();
473                         if (null != rep) {
474                             Map<String, AttributeElement> attributes = rep
475                                     .getAttributes();
476                             if (null != attributes && !attributes.isEmpty()) {
477                                 attributesExist = true;
478                             }
479                         }
480                         if (!attributesExist) {
481                             MessageDialog
482                                     .openInformation(Display.getDefault()
483                                             .getActiveShell(), "PUT Request",
484                                             "No attributes exist in the resource model.");
485                             return;
486                         }
487                         PutRequestDialog putDialog = new PutRequestDialog(
488                                 Display.getDefault().getActiveShell());
489                         if (putDialog.open() == Window.OK) {
490                             resourceManager.sendPutRequest(resourceInSelection,
491                                     putDialog.getUpdatedRepresentation()
492                                             .getModel());
493                         }
494                     }
495                 });
496             }
497         });
498
499         postButton.addSelectionListener(new SelectionAdapter() {
500             @Override
501             public void widgetSelected(SelectionEvent e) {
502                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
503                     @Override
504                     public void run() {
505                         boolean attributesExist = false;
506                         ResourceRepresentation rep = resourceInSelection
507                                 .getResourceRepresentation();
508                         if (null != rep) {
509                             Map<String, AttributeElement> attributes = rep
510                                     .getAttributes();
511                             if (null != attributes && !attributes.isEmpty()) {
512                                 attributesExist = true;
513                             }
514                         }
515                         if (!attributesExist) {
516                             MessageDialog
517                                     .openInformation(Display.getDefault()
518                                             .getActiveShell(), "POST Request",
519                                             "No attributes exist in the resource model.");
520                             return;
521                         }
522
523                         PostRequestDialog postDialog = new PostRequestDialog(
524                                 Display.getDefault().getActiveShell());
525                         if (postDialog.open() == Window.OK) {
526                             ResourceRepresentation representation = postDialog
527                                     .getUpdatedRepresentation();
528                             resourceManager.sendPostRequest(
529                                     resourceInSelection,
530                                     representation.getSelectedModel());
531                         }
532                     }
533                 });
534             }
535         });
536
537         observeResButton.addSelectionListener(new SelectionAdapter() {
538             @Override
539             public void widgetSelected(SelectionEvent e) {
540                 boolean result;
541                 if (observeResButton.getText().equals(Constants.OBSERVE)) {
542                     result = resourceManager
543                             .sendObserveRequest(resourceInSelection);
544                     if (result) {
545                         observeResButton.setText(Constants.STOP_OBSERVE);
546                     } else {
547                         MessageDialog.openError(Display.getDefault()
548                                 .getActiveShell(), "Observe failed",
549                                 "Failed to observe the resource. Try again.");
550                     }
551                 } else {
552                     result = resourceManager.sendCancelObserveRequest(
553                             resourceInSelection, true);
554                     if (result) {
555                         observeResButton.setText(Constants.OBSERVE);
556                     } else {
557                         MessageDialog
558                                 .openError(Display.getDefault()
559                                         .getActiveShell(),
560                                         "Cancel Observe failed",
561                                         "Failed to stop observing the resource. Try again.");
562                     }
563                 }
564             }
565         });
566
567         automateButton.addSelectionListener(new SelectionAdapter() {
568             @Override
569             public void widgetSelected(SelectionEvent e) {
570                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
571                     @Override
572                     public void run() {
573                         RemoteResource resource = resourceManager
574                                 .getCurrentResourceInSelection();
575                         if (null == resource) {
576                             return;
577                         }
578                         Map<String, Boolean> autoStatus = resourceManager
579                                 .getAutomationStatus(resource);
580                         if (null == autoStatus) {
581                             return;
582                         }
583
584                         int startCount = 0;
585                         int stopCount = 0;
586                         boolean startGet, startPut, startPost;
587                         boolean stopGet, stopPut, stopPost;
588                         startGet = startPut = startPost = false;
589                         stopGet = stopPut = stopPost = false;
590                         String status = null;
591                         String startMsg = "Verification will be started for: ";
592                         String stopMsg = "Verification will be stopped for: ";
593                         VerificationDialog ad = new VerificationDialog(Display
594                                 .getDefault().getActiveShell(), autoStatus);
595                         if (ad.open() == Window.OK) {
596                             Map<String, Boolean> oldStatus = resourceManager
597                                     .getAutomationStatus(resource);
598                             if (null == oldStatus || oldStatus.size() < 1) {
599                                 status = "Failed to perform the requested operation.";
600                             } else {
601                                 // GET
602                                 if (oldStatus.get(Constants.GET) != autoStatus
603                                         .get(Constants.GET)) {
604                                     if (autoStatus.get(Constants.GET)) {
605                                         startMsg += Constants.GET;
606                                         startCount++;
607                                         startGet = true;
608                                     } else {
609                                         stopMsg += Constants.GET;
610                                         stopCount++;
611                                         stopGet = true;
612                                     }
613                                 }
614                                 // PUT
615                                 if (oldStatus.get(Constants.PUT) != autoStatus
616                                         .get(Constants.PUT)) {
617                                     if (autoStatus.get(Constants.PUT)) {
618                                         if (startCount == 1) {
619                                             startMsg += ", ";
620                                         }
621                                         startMsg += Constants.PUT;
622                                         startCount++;
623                                         startPut = true;
624                                     } else {
625                                         if (stopCount == 1) {
626                                             stopMsg += ", ";
627                                         }
628                                         stopMsg += Constants.PUT;
629                                         stopCount++;
630                                         stopPut = true;
631                                     }
632
633                                 }
634                                 // POST
635                                 if (oldStatus.get(Constants.POST) != autoStatus
636                                         .get(Constants.POST)) {
637                                     if (autoStatus.get(Constants.POST)) {
638                                         if (startCount > 0) {
639                                             startMsg += ", ";
640                                         }
641                                         startMsg += Constants.POST;
642                                         startCount++;
643                                         startPost = true;
644                                     } else {
645                                         if (stopCount > 0) {
646                                             stopMsg += ", ";
647                                         }
648                                         stopMsg += Constants.POST;
649                                         stopCount++;
650                                         stopPost = true;
651                                     }
652                                 }
653                                 if (startCount > 0) {
654                                     status = startMsg + ".";
655                                 }
656                                 if (stopCount > 0) {
657                                     if (startCount <= 0) {
658                                         status = stopMsg;
659                                     } else {
660                                         status += "\n" + stopMsg + ".";
661                                     }
662                                 }
663                             }
664                             if (startCount == 0 && stopCount == 0) {
665                                 MessageDialog.openInformation(Display
666                                         .getDefault().getActiveShell(),
667                                         "Verification", "No New Changes.");
668                             } else {
669                                 boolean answer = MessageDialog.openQuestion(
670                                         Display.getDefault().getActiveShell(),
671                                         "Verification", status
672                                                 + "\nDo you want to proceed?");
673                                 if (answer) {
674                                     if (startGet || stopGet)
675                                         automate(VerificationType.GET,
676                                                 autoStatus.get(Constants.GET));
677                                     if (startPut || stopPut)
678                                         automate(VerificationType.PUT,
679                                                 autoStatus.get(Constants.PUT));
680                                     if (startPost || stopPost)
681                                         automate(VerificationType.POST,
682                                                 autoStatus.get(Constants.POST));
683                                 }
684                             }
685                         }
686                     }
687                 });
688             }
689         });
690     }
691
692     private void automate(VerificationType type, boolean start) {
693         if (start) {
694             resourceManager.startAutomationRequest(type, resourceInSelection);
695         } else {
696             resourceManager.stopAutomationRequest(type, resourceInSelection);
697         }
698     }
699
700     private void addManagerListeners() {
701         UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
702                 resourceSelectionChangedListener);
703         UiListenerHandler.getInstance().addGetUIListener(getUIListener);
704         UiListenerHandler.getInstance().addPutUIListener(putUIListener);
705         UiListenerHandler.getInstance().addPostUIListener(postUIListener);
706         UiListenerHandler.getInstance().addObserveUIListener(observeUIListener);
707         UiListenerHandler.getInstance().addVerificationUIListener(
708                 verificationUIListener);
709         UiListenerHandler.getInstance().addConfigUploadUIListener(
710                 configUploadUIListener);
711     }
712
713     private void setVisibility(boolean visibility) {
714         if (!getButton.isDisposed())
715             getButton.setEnabled(visibility);
716         if (!putButton.isDisposed())
717             putButton.setEnabled(visibility);
718         if (!postButton.isDisposed())
719             postButton.setEnabled(visibility);
720         if (!automateButton.isDisposed()) {
721             if (visibility && null != resourceInSelection
722                     && resourceInSelection.isConfigUploaded()) {
723                 automateButton.setEnabled(true);
724             } else {
725                 automateButton.setEnabled(false);
726             }
727         }
728         if (!observeResButton.isDisposed())
729             observeResButton.setEnabled(visibility);
730     }
731
732     class AttributeContentProvider implements ITreeContentProvider {
733
734         @Override
735         public void dispose() {
736         }
737
738         @Override
739         public void inputChanged(Viewer viewer, Object oldAttribute,
740                 Object newAttribute) {
741         }
742
743         @Override
744         public Object[] getChildren(Object attribute) {
745             if (attribute instanceof AttributeElement) {
746                 return ((AttributeElement) attribute).getChildren().values()
747                         .toArray();
748             }
749
750             return new Object[0];
751         }
752
753         @Override
754         public Object getParent(Object attribute) {
755             if (attribute instanceof AttributeElement)
756                 return ((AttributeElement) attribute).getParent();
757             return null;
758         }
759
760         @Override
761         public boolean hasChildren(Object attribute) {
762             if (attribute instanceof AttributeElement)
763                 return ((AttributeElement) attribute).hasChildren();
764             return false;
765         }
766
767         @Override
768         public Object[] getElements(Object resourceModel) {
769             if (resourceModel instanceof ResourceRepresentation) {
770                 return ((ResourceRepresentation) resourceModel).getAttributes()
771                         .values().toArray();
772             }
773
774             return new Object[0];
775         }
776     }
777
778     class AttributeLabelProvider implements ITableLabelProvider {
779
780         @Override
781         public void addListener(ILabelProviderListener arg0) {
782         }
783
784         @Override
785         public void dispose() {
786         }
787
788         @Override
789         public boolean isLabelProperty(Object arg0, String arg1) {
790             return false;
791         }
792
793         @Override
794         public void removeListener(ILabelProviderListener arg0) {
795
796         }
797
798         @Override
799         public Image getColumnImage(Object element, int col) {
800             return null;
801         }
802
803         @Override
804         public String getColumnText(Object element, int column) {
805             if (element instanceof AttributeElement) {
806                 AttributeElement attrElement = (AttributeElement) element;
807                 switch (column) {
808                     case 0: // Attribute name column
809                     {
810                         SimulatorResourceAttribute attribute = attrElement
811                                 .getSimulatorResourceAttribute();
812                         return attribute.name();
813                     }
814
815                     case 1: // Attribute value column
816                     {
817                         SimulatorResourceAttribute attribute = attrElement
818                                 .getSimulatorResourceAttribute();
819
820                         if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
821                             return Utility.getAttributeValueAsString(attribute
822                                     .value());
823                         return null;
824                     }
825                 }
826             }
827             return null;
828         }
829     }
830
831     @Override
832     public void dispose() {
833         // Unregister the selection listener
834         if (null != resourceSelectionChangedListener) {
835             UiListenerHandler.getInstance()
836                     .removeResourceSelectionChangedUIListener(
837                             resourceSelectionChangedListener);
838         }
839
840         // Unregister the GET listener
841         if (null != getUIListener) {
842             UiListenerHandler.getInstance().removeGetUIListener(getUIListener);
843         }
844
845         super.dispose();
846     }
847
848     @Override
849     public void setFocus() {
850     }
851
852 }