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