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