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