Imported Upstream version 1.1.0
[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                             PutRequestDialog putDialog = new PutRequestDialog(
514                                     Display.getDefault().getActiveShell());
515                             if (putDialog.open() == Window.OK) {
516                                 // Call the native PUT method
517                                 String ifType = putDialog.getIfType();
518                                 ResourceRepresentation updatedRepresentation = putDialog
519                                         .getUpdatedRepresentation();
520                                 if (null != updatedRepresentation) {
521                                     resourceManager.sendPutRequest(ifType,
522                                             resourceInSelection,
523                                             updatedRepresentation.getModel());
524                                     return;
525                                 }
526
527                                 MessageDialog
528                                         .openInformation(Display.getDefault()
529                                                 .getActiveShell(),
530                                                 "PUT Request",
531                                                 "No attributes exist in the resource model.");
532                             }
533                         }
534                     }
535                 });
536             }
537         });
538
539         postButton.addSelectionListener(new SelectionAdapter() {
540             @Override
541             public void widgetSelected(SelectionEvent e) {
542                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
543                     @Override
544                     public void run() {
545                         boolean attributesExist = false;
546                         ResourceRepresentation rep = resourceInSelection
547                                 .getResourceRepresentation();
548                         if (null != rep) {
549                             Map<String, AttributeElement> attributes = rep
550                                     .getAttributes();
551                             if (null != attributes && !attributes.isEmpty()) {
552                                 attributesExist = true;
553                             }
554                         }
555                         if (attributesExist) {
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 updatedRepresentation = postDialog
562                                         .getUpdatedRepresentation();
563                                 if (null != updatedRepresentation) {
564                                     resourceManager.sendPostRequest(ifType,
565                                             resourceInSelection,
566                                             updatedRepresentation
567                                                     .getSelectedModel());
568                                     return;
569                                 }
570
571                                 MessageDialog
572                                         .openInformation(Display.getDefault()
573                                                 .getActiveShell(),
574                                                 "POST Request",
575                                                 "No attributes exist in the resource model.");
576                             }
577                         }
578                     }
579                 });
580             }
581         });
582
583         observeResButton.addSelectionListener(new SelectionAdapter() {
584             @Override
585             public void widgetSelected(SelectionEvent e) {
586                 boolean result;
587                 if (observeResButton.getText().equals(Constants.OBSERVE)) {
588                     result = resourceManager
589                             .sendObserveRequest(resourceInSelection);
590                     if (result) {
591                         observeResButton.setText(Constants.STOP_OBSERVE);
592                     } else {
593                         MessageDialog.openError(Display.getDefault()
594                                 .getActiveShell(), "Observe failed",
595                                 "Failed to observe the resource. Try again.");
596                     }
597                 } else {
598                     result = resourceManager.sendCancelObserveRequest(
599                             resourceInSelection, true);
600                     if (result) {
601                         observeResButton.setText(Constants.OBSERVE);
602                     } else {
603                         MessageDialog
604                                 .openError(Display.getDefault()
605                                         .getActiveShell(),
606                                         "Cancel Observe failed",
607                                         "Failed to stop observing the resource. Try again.");
608                     }
609                 }
610             }
611         });
612
613         automateButton.addSelectionListener(new SelectionAdapter() {
614             @Override
615             public void widgetSelected(SelectionEvent e) {
616                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
617                     @Override
618                     public void run() {
619                         RemoteResource resource = resourceManager
620                                 .getCurrentResourceInSelection();
621                         if (null == resource) {
622                             return;
623                         }
624                         Map<String, Boolean> autoStatus = resourceManager
625                                 .getAutomationStatus(resource);
626                         if (null == autoStatus) {
627                             return;
628                         }
629
630                         int startCount = 0;
631                         int stopCount = 0;
632                         boolean startGet, startPut, startPost;
633                         boolean stopGet, stopPut, stopPost;
634                         startGet = startPut = startPost = false;
635                         stopGet = stopPut = stopPost = false;
636                         String status = null;
637                         String startMsg = "Verification will be started for: ";
638                         String stopMsg = "Verification will be stopped for: ";
639                         VerificationDialog ad = new VerificationDialog(Display
640                                 .getDefault().getActiveShell(), autoStatus);
641                         if (ad.open() == Window.OK) {
642                             Map<String, Boolean> oldStatus = resourceManager
643                                     .getAutomationStatus(resource);
644                             if (null == oldStatus || oldStatus.size() < 1) {
645                                 status = "Failed to perform the requested operation.";
646                             } else {
647                                 // GET
648                                 if (!oldStatus.get(Constants.GET).equals(
649                                         autoStatus.get(Constants.GET))) {
650                                     if (autoStatus.get(Constants.GET)) {
651                                         startMsg += Constants.GET;
652                                         startCount++;
653                                         startGet = true;
654                                     } else {
655                                         stopMsg += Constants.GET;
656                                         stopCount++;
657                                         stopGet = true;
658                                     }
659                                 }
660                                 // PUT
661                                 if (!oldStatus.get(Constants.PUT).equals(
662                                         autoStatus.get(Constants.PUT))) {
663                                     if (autoStatus.get(Constants.PUT)) {
664                                         if (startCount == 1) {
665                                             startMsg += ", ";
666                                         }
667                                         startMsg += Constants.PUT;
668                                         startCount++;
669                                         startPut = true;
670                                     } else {
671                                         if (stopCount == 1) {
672                                             stopMsg += ", ";
673                                         }
674                                         stopMsg += Constants.PUT;
675                                         stopCount++;
676                                         stopPut = true;
677                                     }
678
679                                 }
680                                 // POST
681                                 if (!oldStatus.get(Constants.POST).equals(
682                                         autoStatus.get(Constants.POST))) {
683                                     if (autoStatus.get(Constants.POST)) {
684                                         if (startCount > 0) {
685                                             startMsg += ", ";
686                                         }
687                                         startMsg += Constants.POST;
688                                         startCount++;
689                                         startPost = true;
690                                     } else {
691                                         if (stopCount > 0) {
692                                             stopMsg += ", ";
693                                         }
694                                         stopMsg += Constants.POST;
695                                         stopCount++;
696                                         stopPost = true;
697                                     }
698                                 }
699                                 if (startCount > 0) {
700                                     status = startMsg + ".";
701                                 }
702                                 if (stopCount > 0) {
703                                     if (startCount <= 0) {
704                                         status = stopMsg;
705                                     } else {
706                                         status += "\n" + stopMsg + ".";
707                                     }
708                                 }
709                             }
710                             if (!(startCount == 0 && stopCount == 0)) {
711                                 boolean answer = MessageDialog.openQuestion(
712                                         Display.getDefault().getActiveShell(),
713                                         "Verification", status
714                                                 + "\nDo you want to proceed?");
715                                 if (answer) {
716                                     if (startGet || stopGet)
717                                         automate(RequestType.GET,
718                                                 autoStatus.get(Constants.GET));
719                                     if (startPut || stopPut)
720                                         automate(RequestType.PUT,
721                                                 autoStatus.get(Constants.PUT));
722                                     if (startPost || stopPost)
723                                         automate(RequestType.POST,
724                                                 autoStatus.get(Constants.POST));
725                                 }
726                             }
727                         }
728                     }
729                 });
730             }
731         });
732     }
733
734     private void automate(RequestType type, boolean start) {
735         if (start) {
736             resourceManager.startAutomationRequest(type, resourceInSelection);
737         } else {
738             resourceManager.stopAutomationRequest(type, resourceInSelection);
739         }
740     }
741
742     private void addManagerListeners() {
743         UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
744                 resourceSelectionChangedListener);
745         UiListenerHandler.getInstance().addGetUIListener(getUIListener);
746         UiListenerHandler.getInstance().addPutUIListener(putUIListener);
747         UiListenerHandler.getInstance().addPostUIListener(postUIListener);
748         UiListenerHandler.getInstance().addObserveUIListener(observeUIListener);
749         UiListenerHandler.getInstance().addVerificationUIListener(
750                 verificationUIListener);
751         UiListenerHandler.getInstance().addConfigUploadUIListener(
752                 configUploadUIListener);
753     }
754
755     private void setVisibility(boolean visibility) {
756         if (!getButton.isDisposed())
757             getButton.setEnabled(visibility);
758         if (!putButton.isDisposed())
759             putButton.setEnabled(visibility);
760         if (!postButton.isDisposed())
761             postButton.setEnabled(visibility);
762         if (!automateButton.isDisposed()) {
763             if (visibility && null != resourceInSelection
764                     && resourceInSelection.isConfigUploaded()) {
765                 automateButton.setEnabled(true);
766             } else {
767                 automateButton.setEnabled(false);
768             }
769         }
770         if (!observeResButton.isDisposed())
771             observeResButton.setEnabled(visibility);
772     }
773
774     private static class AttributeContentProvider implements
775             ITreeContentProvider {
776
777         @Override
778         public void dispose() {
779         }
780
781         @Override
782         public void inputChanged(Viewer viewer, Object oldAttribute,
783                 Object newAttribute) {
784         }
785
786         @Override
787         public Object[] getChildren(Object attribute) {
788             if (attribute instanceof AttributeElement) {
789                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
790                 Map<String, AttributeElement> children = ((AttributeElement) attribute)
791                         .getChildren();
792                 if (null != children) {
793                     attElementList.addAll(children.values());
794                     Collections.sort(attElementList,
795                             Utility.attributeComparator);
796                     return attElementList.toArray();
797                 }
798             }
799
800             return new Object[0];
801         }
802
803         @Override
804         public Object getParent(Object attribute) {
805             if (attribute instanceof AttributeElement)
806                 return ((AttributeElement) attribute).getParent();
807             return null;
808         }
809
810         @Override
811         public boolean hasChildren(Object attribute) {
812             if (attribute instanceof AttributeElement)
813                 return ((AttributeElement) attribute).hasChildren();
814             return false;
815         }
816
817         @Override
818         public Object[] getElements(Object resourceModel) {
819             if (resourceModel instanceof ResourceRepresentation) {
820                 return ((ResourceRepresentation) resourceModel).getAttributes()
821                         .values().toArray();
822             }
823
824             return new Object[0];
825         }
826     }
827
828     private static class AttributeLabelProvider implements ITableLabelProvider {
829
830         @Override
831         public void addListener(ILabelProviderListener arg0) {
832         }
833
834         @Override
835         public void dispose() {
836         }
837
838         @Override
839         public boolean isLabelProperty(Object arg0, String arg1) {
840             return false;
841         }
842
843         @Override
844         public void removeListener(ILabelProviderListener arg0) {
845
846         }
847
848         @Override
849         public Image getColumnImage(Object element, int col) {
850             return null;
851         }
852
853         @Override
854         public String getColumnText(Object element, int column) {
855             if (element instanceof AttributeElement) {
856                 AttributeElement attrElement = (AttributeElement) element;
857                 switch (column) {
858                     case 0: // Attribute name column
859                     {
860                         SimulatorResourceAttribute attribute = attrElement
861                                 .getSimulatorResourceAttribute();
862                         return attribute.name();
863                     }
864
865                     case 1: // Attribute value column
866                     {
867                         SimulatorResourceAttribute attribute = attrElement
868                                 .getSimulatorResourceAttribute();
869
870                         if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) {
871                             String value = Utility
872                                     .getAttributeValueAsString(attribute
873                                             .value());
874                             if (null == value) {
875                                 value = "";
876                             }
877                             return value;
878                         }
879                         return null;
880                     }
881                 }
882             }
883             return null;
884         }
885     }
886
887     @Override
888     public void dispose() {
889         // Unregister the selection listener
890         if (null != resourceSelectionChangedListener) {
891             UiListenerHandler.getInstance()
892                     .removeResourceSelectionChangedUIListener(
893                             resourceSelectionChangedListener);
894         }
895
896         // Unregister the GET listener
897         if (null != getUIListener) {
898             UiListenerHandler.getInstance().removeGetUIListener(getUIListener);
899         }
900
901         super.dispose();
902     }
903
904     @Override
905     public void setFocus() {
906     }
907
908 }