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