Java SDK and Eclipse plugin for simulator.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / AttributeView.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.clientcontroller.view;
18
19 import java.util.List;
20 import java.util.Map;
21
22 import oic.simulator.clientcontroller.Activator;
23 import oic.simulator.clientcontroller.listener.IConfigurationUpload;
24 import oic.simulator.clientcontroller.listener.IGetUIListener;
25 import oic.simulator.clientcontroller.listener.IObserveUIListener;
26 import oic.simulator.clientcontroller.listener.IPostUIListener;
27 import oic.simulator.clientcontroller.listener.IPutUIListener;
28 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
29 import oic.simulator.clientcontroller.listener.IVerificationUIListener;
30 import oic.simulator.clientcontroller.manager.ResourceManager;
31 import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
32 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
33 import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
34 import oic.simulator.clientcontroller.utils.Constants;
35 import oic.simulator.clientcontroller.view.dialogs.VerificationDialog;
36 import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
37 import oic.simulator.clientcontroller.view.dialogs.PutRequestDialog;
38
39 import org.eclipse.jface.dialogs.MessageDialog;
40 import org.eclipse.jface.viewers.IStructuredContentProvider;
41 import org.eclipse.jface.viewers.StyledCellLabelProvider;
42 import org.eclipse.jface.viewers.TableViewer;
43 import org.eclipse.jface.viewers.TableViewerColumn;
44 import org.eclipse.jface.viewers.Viewer;
45 import org.eclipse.jface.viewers.ViewerCell;
46 import org.eclipse.jface.window.Window;
47 import org.eclipse.swt.SWT;
48 import org.eclipse.swt.custom.CTabFolder;
49 import org.eclipse.swt.custom.CTabFolder2Adapter;
50 import org.eclipse.swt.custom.CTabFolderEvent;
51 import org.eclipse.swt.custom.CTabItem;
52 import org.eclipse.swt.events.SelectionAdapter;
53 import org.eclipse.swt.events.SelectionEvent;
54 import org.eclipse.swt.graphics.Color;
55 import org.eclipse.swt.layout.GridData;
56 import org.eclipse.swt.layout.GridLayout;
57 import org.eclipse.swt.widgets.Button;
58 import org.eclipse.swt.widgets.Composite;
59 import org.eclipse.swt.widgets.Display;
60 import org.eclipse.swt.widgets.Group;
61 import org.eclipse.swt.widgets.Table;
62 import org.eclipse.swt.widgets.Text;
63 import org.eclipse.ui.PlatformUI;
64 import org.eclipse.ui.part.ViewPart;
65
66 /**
67  * This class manages and shows the attribute view in the perspective.
68  */
69 public class AttributeView extends ViewPart {
70
71     public static final String                  VIEW_ID        = "oic.simulator.clientcontroller.view.attribute";
72
73     private TableViewer                         attTblViewer;
74
75     private Button                              getButton;
76     private Button                              putButton;
77     private Button                              postButton;
78     private Button                              automateButton;
79     private Button                              observeResButton;
80
81     private CTabFolder                          payloadFolder;
82     private CTabItem                            requestPayloadTab;
83     private CTabItem                            responsePayloadTab;
84     private Text                                requestPayloadTxt;
85     private Text                                responsePayloadTxt;
86
87     private final String[]                      attTblHeaders  = {
88             "Attribute Name", "Attribute Value"               };
89     private final Integer[]                     attTblColWidth = { 200, 200 };
90
91     private ResourceManager                     resourceManager;
92
93     private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
94     private IGetUIListener                      getUIListener;
95     private IPutUIListener                      putUIListener;
96     private IPostUIListener                     postUIListener;
97     private IObserveUIListener                  observeUIListener;
98     private IVerificationUIListener             verificationUIListener;
99     private IConfigurationUpload                configUploadUIListener;
100
101     private RemoteResource                      resourceInSelection;
102
103     public AttributeView() {
104         resourceManager = Activator.getDefault().getResourceManager();
105
106         resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
107
108             @Override
109             public void onResourceSelectionChange(final RemoteResource resource) {
110                 Display.getDefault().asyncExec(new Runnable() {
111
112                     @Override
113                     public void run() {
114                         System.out
115                                 .println("AttributeView: onResourceSelectionChange");
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 != attTblViewer
123                                 && !attTblViewer.getControl().isDisposed()) {
124                             System.out.println("viewer is alive");
125                             updateViewer(getData(resource));
126                         }
127
128                         // Update the observe status
129                         updateObserve(resource);
130
131                         // Update the pay-load details if any
132                     }
133                 });
134             }
135         };
136
137         getUIListener = new IGetUIListener() {
138
139             @Override
140             public void onGetCompleted(final RemoteResource resource) {
141                 Display.getDefault().asyncExec(new Runnable() {
142
143                     @Override
144                     public void run() {
145
146                         System.out.println("AttributeView: onGetCompleted");
147                         if (null == resource) {
148                             return;
149                         }
150                         // Update the attribute table
151                         if (resourceInSelection != resource) {
152                             System.out
153                                     .println("AttributeView: get response arrived for a different resource");
154                             return;
155                         }
156                         updateViewer(getData(resource));
157
158                         // Update the observe status
159                         updateObserve(resource);
160
161                         // Update the pay-load details if any
162                     }
163                 });
164             }
165
166             @Override
167             public void onGetFailed(RemoteResource resource) {
168             }
169         };
170
171         putUIListener = new IPutUIListener() {
172
173             @Override
174             public void onPutCompleted(final RemoteResource resource) {
175                 Display.getDefault().asyncExec(new Runnable() {
176
177                     @Override
178                     public void run() {
179
180                         System.out.println("AttributeView: onPutCompleted");
181                         if (null == resource) {
182                             return;
183                         }
184                         // Update the attribute table
185                         if (resourceInSelection != resource) {
186                             System.out
187                                     .println("AttributeView: put response arrived for a different resource");
188                             return;
189                         }
190                         updateViewer(getData(resource));
191
192                         // Update the observe status
193                         updateObserve(resource);
194
195                         // Update the pay-load details if any
196                     }
197                 });
198             }
199
200             @Override
201             public void onPutFailed(RemoteResource resource) {
202             }
203         };
204
205         postUIListener = new IPostUIListener() {
206
207             @Override
208             public void onPostCompleted(final RemoteResource resource) {
209                 Display.getDefault().asyncExec(new Runnable() {
210
211                     @Override
212                     public void run() {
213
214                         System.out.println("AttributeView: onPostCompleted");
215                         if (null == resource) {
216                             return;
217                         }
218                         // Update the attribute table
219                         if (resourceInSelection != resource) {
220                             System.out
221                                     .println("AttributeView: post response arrived for a different resource");
222                             return;
223                         }
224                         updateViewer(getData(resource));
225
226                         // Update the observe status
227                         updateObserve(resource);
228
229                         // Update the pay-load details if any
230                     }
231                 });
232             }
233
234             @Override
235             public void onPostFailed(RemoteResource resource) {
236             }
237         };
238
239         observeUIListener = new IObserveUIListener() {
240
241             @Override
242             public void onObserveCompleted(final RemoteResource resource) {
243                 Display.getDefault().asyncExec(new Runnable() {
244
245                     @Override
246                     public void run() {
247
248                         System.out.println("AttributeView: onObserveCompleted");
249                         if (null == resource) {
250                             return;
251                         }
252                         // Update the attribute table
253                         if (resourceInSelection != resource) {
254                             System.out
255                                     .println("AttributeView: observe response arrived for a different resource");
256                             return;
257                         }
258                         updateViewer(getData(resource));
259
260                         // Update the observe status
261                         updateObserve(resource);
262
263                         // Update the pay-load details if any
264                     }
265                 });
266             }
267
268             @Override
269             public void onObserveFailed(RemoteResource resource) {
270             }
271         };
272
273         verificationUIListener = new IVerificationUIListener() {
274
275             @Override
276             public void onVerificationStarted(final RemoteResource resource,
277                     final int autoType) {
278                 Display.getDefault().asyncExec(new Runnable() {
279
280                     @Override
281                     public void run() {
282                         changeReqBtnVisibility(autoType, false);
283                     }
284                 });
285             }
286
287             @Override
288             public void onVerificationCompleted(final RemoteResource resource,
289                     final int autoType) {
290                 Display.getDefault().asyncExec(new Runnable() {
291
292                     @Override
293                     public void run() {
294                         changeReqBtnVisibility(autoType, true);
295                     }
296                 });
297             }
298
299             @Override
300             public void onVerificationAborted(final RemoteResource resource,
301                     final int autoType) {
302                 Display.getDefault().asyncExec(new Runnable() {
303
304                     @Override
305                     public void run() {
306                         changeReqBtnVisibility(autoType, true);
307                     }
308                 });
309             }
310         };
311
312         configUploadUIListener = new IConfigurationUpload() {
313
314             @Override
315             public void onConfigurationUploaded(final RemoteResource resource) {
316                 Display.getDefault().asyncExec(new Runnable() {
317
318                     @Override
319                     public void run() {
320
321                         System.out
322                                 .println("AttributeView: onConfigurationUploaded");
323                         if (null == resource) {
324                             return;
325                         }
326                         if (resourceInSelection != resource) {
327                             System.out
328                                     .println("AttributeView: config upload response arrived for a different resource");
329                             return;
330                         }
331                         if (!automateButton.isDisposed()) {
332                             automateButton.setEnabled(true);
333                         }
334                     }
335                 });
336             }
337         };
338     }
339
340     private void changeReqBtnVisibility(int reqType, boolean visibility) {
341         if (reqType == Constants.GET_AUTOMATION_INDEX) {
342             if (!getButton.isDisposed()) {
343                 getButton.setEnabled(visibility);
344             }
345         } else if (reqType == Constants.PUT_AUTOMATION_INDEX) {
346             if (!putButton.isDisposed()) {
347                 putButton.setEnabled(visibility);
348             }
349         } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
350             if (!postButton.isDisposed()) {
351                 postButton.setEnabled(visibility);
352             }
353         }
354     }
355
356     private Map<String, RemoteResourceAttribute> getData(RemoteResource resource) {
357         if (null == resource) {
358             return null;
359         }
360         Map<String, RemoteResourceAttribute> attMap = resource
361                 .getResourceAttributesMap();
362         System.out.println("AttributeView: \n" + attMap);
363         return attMap;
364     }
365
366     private void updateViewer(Map<String, RemoteResourceAttribute> attMap) {
367         if (null != attTblViewer) {
368             Table tbl = attTblViewer.getTable();
369             if (null != attMap) {
370                 attTblViewer.setInput(attMap.entrySet().toArray());
371                 if (!tbl.isDisposed()) {
372                     tbl.setLinesVisible(true);
373                 }
374             } else {
375                 if (!tbl.isDisposed()) {
376                     tbl.removeAll();
377                     tbl.setLinesVisible(false);
378                 }
379             }
380         }
381     }
382
383     private void updateObserve(RemoteResource resource) {
384         if (null == resource) {
385             return;
386         }
387         boolean observed = resource.isObserved();
388         if (!observeResButton.isDisposed()) {
389             observeResButton.setSelection(observed);
390         }
391     }
392
393     @Override
394     public void createPartControl(Composite parent) {
395         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
396
397         parent.setLayout(new GridLayout(2, false));
398         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
399         parent.setLayoutData(gd);
400
401         Group attGroup = new Group(parent, SWT.NONE);
402         attGroup.setLayout(new GridLayout());
403         gd = new GridData();
404         gd.grabExcessHorizontalSpace = true;
405         gd.horizontalAlignment = SWT.FILL;
406         gd.horizontalSpan = 2;
407         gd.heightHint = 175;
408         attGroup.setLayoutData(gd);
409         attGroup.setText("Attributes");
410         attGroup.setBackground(color);
411
412         setupAttributeTable(attGroup);
413
414         setupMessageArea(parent);
415
416         setupResourceLevelOpsArea(parent);
417
418         setupTabArea(parent);
419
420         setUIListeners();
421
422         addManagerListeners();
423
424         setVisibility(false);
425
426         // Updating the data in the UI as per the resource in selection.
427         if (null != attTblViewer && !attTblViewer.getControl().isDisposed()) {
428             updateViewer(getData(resourceManager
429                     .getCurrentResourceInSelection()));
430         }
431     }
432
433     private void setupMessageArea(Composite parent) {
434         GridData gd;
435         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
436         Group msgTypesGrp = new Group(parent, SWT.NONE);
437         gd = new GridData();
438         gd.grabExcessHorizontalSpace = true;
439         gd.horizontalAlignment = SWT.FILL;
440         msgTypesGrp.setLayoutData(gd);
441         GridLayout grid = new GridLayout(3, false);
442         msgTypesGrp.setLayout(grid);
443         msgTypesGrp.setText("Request Types");
444         msgTypesGrp.setBackground(color);
445
446         getButton = new Button(msgTypesGrp, SWT.PUSH);
447         getButton.setText("GET");
448         gd = new GridData();
449         gd.grabExcessHorizontalSpace = true;
450         gd.horizontalAlignment = SWT.FILL;
451         gd.widthHint = 50;
452         getButton.setLayoutData(gd);
453
454         putButton = new Button(msgTypesGrp, SWT.PUSH);
455         putButton.setText("PUT");
456         gd = new GridData();
457         gd.grabExcessHorizontalSpace = true;
458         gd.horizontalAlignment = SWT.FILL;
459         gd.widthHint = 50;
460         putButton.setLayoutData(gd);
461
462         postButton = new Button(msgTypesGrp, SWT.PUSH);
463         postButton.setText("POST");
464         gd = new GridData();
465         gd.grabExcessHorizontalSpace = true;
466         gd.horizontalAlignment = SWT.FILL;
467         gd.widthHint = 50;
468         postButton.setLayoutData(gd);
469     }
470
471     private void setupResourceLevelOpsArea(Composite parent) {
472         GridData gd;
473         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
474         Group resOpsGrp = new Group(parent, SWT.NONE);
475         gd = new GridData();
476         gd.grabExcessHorizontalSpace = true;
477         gd.horizontalAlignment = SWT.FILL;
478         resOpsGrp.setLayoutData(gd);
479         GridLayout grid = new GridLayout(2, false);
480         resOpsGrp.setLayout(grid);
481         resOpsGrp.setText("Resource-Level Operations");
482         resOpsGrp.setBackground(color);
483
484         automateButton = new Button(resOpsGrp, SWT.PUSH);
485         automateButton.setText("Automation");
486         gd = new GridData();
487         gd.grabExcessHorizontalSpace = true;
488         gd.horizontalAlignment = SWT.FILL;
489         automateButton.setLayoutData(gd);
490
491         observeResButton = new Button(resOpsGrp, SWT.CHECK);
492         observeResButton.setText("Observe");
493         gd = new GridData();
494         gd.grabExcessHorizontalSpace = true;
495         gd.horizontalAlignment = SWT.FILL;
496         observeResButton.setLayoutData(gd);
497     }
498
499     private void setupTabArea(final Composite parent) {
500         GridData gd;
501         payloadFolder = new CTabFolder(parent, SWT.BORDER);
502         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
503         gd.horizontalSpan = 2;
504         payloadFolder.setLayoutData(gd);
505         payloadFolder.setSimple(false);
506         payloadFolder.setUnselectedCloseVisible(false);
507         payloadFolder.setUnselectedImageVisible(false);
508         // payloadFolder.setMaximizeVisible(true);
509         // payloadFolder.setMinimizeVisible(true);
510
511         requestPayloadTab = new CTabItem(payloadFolder, SWT.NULL);
512         requestPayloadTab.setText("Request Payload");
513
514         requestPayloadTxt = new Text(payloadFolder, SWT.MULTI | SWT.V_SCROLL
515                 | SWT.H_SCROLL | SWT.READ_ONLY | SWT.WRAP);
516         requestPayloadTab.setControl(requestPayloadTxt);
517
518         responsePayloadTab = new CTabItem(payloadFolder, SWT.NULL);
519         responsePayloadTab.setText("Response Payload");
520
521         responsePayloadTxt = new Text(payloadFolder, SWT.MULTI | SWT.V_SCROLL
522                 | SWT.H_SCROLL | SWT.READ_ONLY | SWT.WRAP);
523         responsePayloadTab.setControl(responsePayloadTxt);
524
525         // Add Listeners
526
527         payloadFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
528             @Override
529             public void minimize(CTabFolderEvent event) {
530                 payloadFolder.setMinimized(true);
531                 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
532                 gd.horizontalSpan = 2;
533                 payloadFolder.setLayoutData(gd);
534                 parent.layout(true);
535             }
536
537             @Override
538             public void maximize(CTabFolderEvent event) {
539                 payloadFolder.setMaximized(true);
540                 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
541                 gd.horizontalSpan = 2;
542                 payloadFolder.setLayoutData(gd);
543                 parent.layout(true);
544             }
545
546             @Override
547             public void restore(CTabFolderEvent event) {
548                 payloadFolder.setMaximized(false);
549                 payloadFolder.setMinimized(false);
550                 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
551                 gd.horizontalSpan = 2;
552                 payloadFolder.setLayoutData(gd);
553                 parent.layout(true);
554             }
555         });
556     }
557
558     private void setupAttributeTable(Group attGroup) {
559         attTblViewer = new TableViewer(attGroup, SWT.SINGLE | SWT.H_SCROLL
560                 | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
561
562         createAttributeColumns(attTblViewer);
563
564         // make lines and header visible
565         Table table = attTblViewer.getTable();
566         table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
567         table.setHeaderVisible(true);
568         table.setLinesVisible(true);
569
570         attTblViewer.setContentProvider(new AttributeContentProvider());
571     }
572
573     public void createAttributeColumns(TableViewer tableViewer) {
574
575         TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
576         attName.getColumn().setWidth(attTblColWidth[0]);
577         attName.getColumn().setText(attTblHeaders[0]);
578         attName.setLabelProvider(new StyledCellLabelProvider() {
579             @Override
580             public void update(ViewerCell cell) {
581                 Object element = cell.getElement();
582                 if (element instanceof Map.Entry) {
583                     @SuppressWarnings("unchecked")
584                     Map.Entry<String, RemoteResourceAttribute> entry = (Map.Entry<String, RemoteResourceAttribute>) element;
585                     cell.setText(entry.getKey());
586                 }
587             }
588         });
589
590         TableViewerColumn attValue = new TableViewerColumn(tableViewer,
591                 SWT.NONE);
592         attValue.getColumn().setWidth(attTblColWidth[1]);
593         attValue.getColumn().setText(attTblHeaders[1]);
594         attValue.setLabelProvider(new StyledCellLabelProvider() {
595             @Override
596             public void update(ViewerCell cell) {
597                 Object element = cell.getElement();
598                 if (element instanceof Map.Entry) {
599                     @SuppressWarnings("unchecked")
600                     Map.Entry<String, RemoteResourceAttribute> entry = (Map.Entry<String, RemoteResourceAttribute>) element;
601                     Object value = entry.getValue().getAttributeValue();
602                     if (null == value) {
603                         cell.setText("");
604                     } else {
605                         cell.setText(String.valueOf(value));
606                     }
607                 }
608             }
609         });
610     }
611
612     private void setUIListeners() {
613
614         getButton.addSelectionListener(new SelectionAdapter() {
615             @Override
616             public void widgetSelected(SelectionEvent e) {
617                 if (resourceInSelection.isGetAutomtnInProgress()) {
618                     MessageDialog
619                             .openInformation(Display.getDefault()
620                                     .getActiveShell(), "GET Request",
621                                     "GET Automation is in progress. Please wait or stop the automation.");
622                 } else {
623                     resourceManager.sendGetRequest(resourceInSelection);
624                 }
625             }
626         });
627
628         putButton.addSelectionListener(new SelectionAdapter() {
629             @Override
630             public void widgetSelected(SelectionEvent e) {
631                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
632                     @Override
633                     public void run() {
634                         if (resourceInSelection.isPutAutomtnInProgress()) {
635                             MessageDialog
636                                     .openInformation(Display.getDefault()
637                                             .getActiveShell(), "PUT Request",
638                                             "PUT Automation is in progress. Please wait or stop the automation.");
639                             return;
640                         }
641                         List<PutPostAttributeModel> putPostModelList;
642                         putPostModelList = resourceInSelection
643                                 .getPutPostModel();
644                         if (null == putPostModelList) {
645                             MessageDialog
646                                     .openInformation(Display.getDefault()
647                                             .getActiveShell(), "PUT Request",
648                                             "No attributes exist in the resource model.");
649                             return;
650                         }
651                         PutRequestDialog putDialog = new PutRequestDialog(
652                                 Display.getDefault().getActiveShell(),
653                                 putPostModelList);
654                         if (putDialog.open() == Window.OK) {
655                             // Call the native PUT method
656                             resourceManager.sendPutRequest(resourceInSelection,
657                                     putPostModelList);
658                         }
659                     }
660                 });
661             }
662         });
663
664         postButton.addSelectionListener(new SelectionAdapter() {
665             @Override
666             public void widgetSelected(SelectionEvent e) {
667                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
668                     @Override
669                     public void run() {
670                         if (resourceInSelection.isPostAutomtnInProgress()) {
671                             MessageDialog
672                                     .openInformation(Display.getDefault()
673                                             .getActiveShell(), "POST Request",
674                                             "POST Automation is in progress. Please wait or stop the automation.");
675                             return;
676                         }
677                         List<PutPostAttributeModel> putPostModelList;
678                         putPostModelList = resourceInSelection
679                                 .getPutPostModel();
680                         if (null == putPostModelList) {
681                             MessageDialog
682                                     .openInformation(Display.getDefault()
683                                             .getActiveShell(), "PUT Request",
684                                             "No attributes exist in the resource model.");
685                             return;
686                         }
687
688                         PostRequestDialog postDialog = new PostRequestDialog(
689                                 Display.getDefault().getActiveShell(),
690                                 putPostModelList);
691                         if (postDialog.open() == Window.OK) {
692                             // Call the native POST method
693                             resourceManager.sendPostRequest(
694                                     resourceInSelection, putPostModelList);
695                         }
696                     }
697                 });
698             }
699         });
700
701         observeResButton.addSelectionListener(new SelectionAdapter() {
702             @Override
703             public void widgetSelected(SelectionEvent e) {
704                 boolean checked = observeResButton.getSelection();
705                 if (checked) {
706                     resourceManager.sendObserveRequest(resourceInSelection);
707                 } else {
708                     resourceManager
709                             .sendCancelObserveRequest(resourceInSelection);
710                 }
711             }
712         });
713
714         automateButton.addSelectionListener(new SelectionAdapter() {
715             @Override
716             public void widgetSelected(SelectionEvent e) {
717                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
718                     @Override
719                     public void run() {
720                         RemoteResource resource = resourceManager
721                                 .getCurrentResourceInSelection();
722                         if (null == resource) {
723                             return;
724                         }
725                         Map<String, Boolean> autoStatus = resourceManager
726                                 .getAutomationStatus(resource);
727                         if (null == autoStatus) {
728                             return;
729                         }
730                         VerificationDialog ad = new VerificationDialog(Display
731                                 .getDefault().getActiveShell(), autoStatus);
732                         if (ad.open() == Window.OK) {
733
734                         }
735                     }
736                 });
737             }
738         });
739     }
740
741     private void addManagerListeners() {
742         resourceManager
743                 .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
744         resourceManager.addGetUIListener(getUIListener);
745         resourceManager.addPutUIListener(putUIListener);
746         resourceManager.addPostUIListener(postUIListener);
747         resourceManager.addObserveUIListener(observeUIListener);
748         resourceManager.addVerificationUIListener(verificationUIListener);
749         resourceManager.addConfigUploadUIListener(configUploadUIListener);
750     }
751
752     private void setVisibility(boolean visibility) {
753         if (!getButton.isDisposed())
754             getButton.setEnabled(visibility);
755         if (!putButton.isDisposed())
756             putButton.setEnabled(visibility);
757         if (!postButton.isDisposed())
758             postButton.setEnabled(visibility);
759         if (!automateButton.isDisposed()) {
760             if (visibility && null != resourceInSelection
761                     && resourceInSelection.isConfigUploaded()) {
762                 automateButton.setEnabled(true);
763             } else {
764                 automateButton.setEnabled(false);
765             }
766         }
767         if (!observeResButton.isDisposed())
768             observeResButton.setEnabled(visibility);
769     }
770
771     class AttributeContentProvider implements IStructuredContentProvider {
772
773         @Override
774         public void dispose() {
775         }
776
777         @Override
778         public void inputChanged(Viewer viewer, Object arg1, Object arg2) {
779         }
780
781         @Override
782         public Object[] getElements(Object element) {
783             return (Object[]) element;
784         }
785
786     }
787
788     @Override
789     public void dispose() {
790         // Unregister the selection listener
791         if (null != resourceSelectionChangedListener) {
792             resourceManager
793                     .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
794         }
795
796         // Unregister the GET listener
797         if (null != getUIListener) {
798             resourceManager.removeGetUIListener(getUIListener);
799         }
800
801         super.dispose();
802     }
803
804     @Override
805     public void setFocus() {
806     }
807
808 }