2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package oic.simulator.serviceprovider.view;
19 import java.util.ArrayList;
20 import java.util.List;
23 import oic.simulator.serviceprovider.Activator;
24 import oic.simulator.serviceprovider.listener.IPropertiesChangedListener;
25 import oic.simulator.serviceprovider.listener.IResourceListChangedListener;
26 import oic.simulator.serviceprovider.manager.ResourceManager;
27 import oic.simulator.serviceprovider.manager.UiListenerHandler;
28 import oic.simulator.serviceprovider.model.AutomationSettingHelper;
29 import oic.simulator.serviceprovider.model.CollectionResource;
30 import oic.simulator.serviceprovider.model.Device;
31 import oic.simulator.serviceprovider.model.Resource;
32 import oic.simulator.serviceprovider.model.ResourceType;
33 import oic.simulator.serviceprovider.model.SingleResource;
34 import oic.simulator.serviceprovider.utils.Constants;
35 import oic.simulator.serviceprovider.utils.Utility;
36 import oic.simulator.serviceprovider.view.dialogs.AddResourceToCollections;
37 import oic.simulator.serviceprovider.view.dialogs.AddResourceToDevices;
38 import oic.simulator.serviceprovider.view.dialogs.AddResources;
39 import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
40 import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard;
41 import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard;
42 import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
43 import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromCollections;
44 import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromDevices;
45 import oic.simulator.serviceprovider.view.dialogs.RemoveResources;
46 import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog;
48 import org.eclipse.jface.dialogs.MessageDialog;
49 import org.eclipse.jface.viewers.ISelectionChangedListener;
50 import org.eclipse.jface.viewers.IStructuredSelection;
51 import org.eclipse.jface.viewers.ITreeContentProvider;
52 import org.eclipse.jface.viewers.LabelProvider;
53 import org.eclipse.jface.viewers.SelectionChangedEvent;
54 import org.eclipse.jface.viewers.StructuredSelection;
55 import org.eclipse.jface.viewers.TreeViewer;
56 import org.eclipse.jface.viewers.Viewer;
57 import org.eclipse.jface.window.Window;
58 import org.eclipse.jface.wizard.WizardDialog;
59 import org.eclipse.swt.SWT;
60 import org.eclipse.swt.custom.CTabFolder;
61 import org.eclipse.swt.custom.CTabItem;
62 import org.eclipse.swt.events.MenuAdapter;
63 import org.eclipse.swt.events.MenuEvent;
64 import org.eclipse.swt.events.SelectionAdapter;
65 import org.eclipse.swt.events.SelectionEvent;
66 import org.eclipse.swt.graphics.Color;
67 import org.eclipse.swt.graphics.Image;
68 import org.eclipse.swt.layout.GridData;
69 import org.eclipse.swt.layout.GridLayout;
70 import org.eclipse.swt.widgets.Button;
71 import org.eclipse.swt.widgets.Composite;
72 import org.eclipse.swt.widgets.Display;
73 import org.eclipse.swt.widgets.Group;
74 import org.eclipse.swt.widgets.Menu;
75 import org.eclipse.swt.widgets.MenuItem;
76 import org.eclipse.swt.widgets.Tree;
77 import org.eclipse.swt.widgets.TreeItem;
78 import org.eclipse.ui.PlatformUI;
79 import org.eclipse.ui.dialogs.FilteredTree;
80 import org.eclipse.ui.dialogs.PatternFilter;
81 import org.eclipse.ui.part.ViewPart;
82 import org.oic.simulator.SimulatorException;
83 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
86 * This class manages and shows the resource manager view in the perspective.
88 public class ResourceManagerView extends ViewPart {
90 public static final String VIEW_ID = "oic.simulator.serviceprovider.view.resourcemanager";
92 private Button createButton;
93 private Button deleteButton;
95 private TreeViewer singleResTreeViewer;
96 private TreeViewer collectionResTreeViewer;
97 private TreeViewer deviceTreeViewer;
99 private CTabFolder folder;
100 private CTabItem singleResTab;
101 private CTabItem collectionResTab;
102 private CTabItem deviceTab;
104 private IResourceListChangedListener resourceListChangedListener;
106 private IPropertiesChangedListener resourcePropertiesChangedListener;
108 private ResourceManager resourceManager;
110 public ResourceManagerView() {
112 resourceManager = Activator.getDefault().getResourceManager();
114 resourceListChangedListener = new IResourceListChangedListener() {
117 public void onResourceCreation(final ResourceType type) {
118 Display.getDefault().asyncExec(new Runnable() {
122 if (type == ResourceType.SINGLE) {
123 if (null != singleResTreeViewer) {
124 singleResTreeViewer.refresh();
126 } else if (type == ResourceType.COLLECTION) {
127 if (null != collectionResTreeViewer) {
128 collectionResTreeViewer.refresh();
131 if (null != deviceTreeViewer) {
132 deviceTreeViewer.refresh();
136 // Trigger the visibility of delete button
137 changeDeleteVisibility();
143 public void onResourceDeletion(final ResourceType type) {
144 Display.getDefault().asyncExec(new Runnable() {
148 if (null != singleResTreeViewer
149 && null != collectionResTreeViewer
150 && null != deviceTreeViewer) {
153 singleResTreeViewer.refresh();
155 collectionResTreeViewer.refresh();
157 deviceTreeViewer.refresh();
160 // Trigger the visibility of delete button
161 changeDeleteVisibility();
167 public void onResourceListUpdate(final ResourceType type) {
168 Display.getDefault().asyncExec(new Runnable() {
172 if (null != singleResTreeViewer
173 && null != collectionResTreeViewer
174 && null != deviceTreeViewer) {
177 singleResTreeViewer.refresh();
179 collectionResTreeViewer.refresh();
181 deviceTreeViewer.refresh();
189 resourcePropertiesChangedListener = new IPropertiesChangedListener() {
192 public void onResourcePropertyChange() {
193 Display.getDefault().asyncExec(new Runnable() {
196 if (null != singleResTreeViewer
197 && null != collectionResTreeViewer
198 && null != deviceTreeViewer) {
199 singleResTreeViewer.refresh();
200 collectionResTreeViewer.refresh();
201 deviceTreeViewer.refresh();
208 public void onDevicePropertyChange() {
209 Display.getDefault().asyncExec(new Runnable() {
212 if (null != deviceTreeViewer) {
213 deviceTreeViewer.refresh();
221 public void changeDeleteVisibility() {
222 boolean visibility = resourceManager.isAnyResourceExist();
223 if (null != deleteButton && !deleteButton.isDisposed()) {
224 deleteButton.setEnabled(visibility);
229 public void createPartControl(Composite parent) {
230 Composite compContent = new Composite(parent, SWT.NONE);
231 GridLayout baseLayout = new GridLayout(1, false);
232 compContent.setLayout(baseLayout);
234 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
235 compContent.setLayoutData(gd);
237 Composite buttonComp = new Composite(compContent, SWT.NONE);
238 buttonComp.setLayout(new GridLayout(2, false));
241 gd.horizontalAlignment = SWT.FILL;
242 gd.grabExcessHorizontalSpace = true;
244 buttonComp.setLayoutData(gd);
246 createButton = new Button(buttonComp, SWT.PUSH);
247 createButton.setText("Create");
248 createButton.setToolTipText("Create Simulator Resource(s)");
252 createButton.setLayoutData(gd);
254 deleteButton = new Button(buttonComp, SWT.PUSH);
255 deleteButton.setText("Delete");
256 deleteButton.setToolTipText("Delete Simulator Resource(s)");
260 deleteButton.setLayoutData(gd);
262 // Create a Tab Folder.
263 folder = new CTabFolder(compContent, SWT.BORDER);
264 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
265 folder.setLayoutData(gd);
266 folder.setSimple(false);
267 folder.setUnselectedCloseVisible(false);
268 folder.setUnselectedImageVisible(false);
269 folder.addSelectionListener(new SelectionAdapter() {
271 public void widgetSelected(SelectionEvent e) {
273 singleResTreeViewer.setSelection(null);
274 collectionResTreeViewer.setSelection(null);
275 deviceTreeViewer.setSelection(null);
276 resourceManager.resourceSelectionChanged(null);
280 createSimpleResourcesArea();
282 createCollectionResourcesArea();
286 folder.setSelection(singleResTab);
290 addManagerListeners();
292 // If there is at least one resource exist, then enable the delete
294 changeDeleteVisibility();
297 private void createSimpleResourcesArea() {
298 singleResTab = new CTabItem(folder, SWT.NULL);
299 singleResTab.setText("Simple Resources");
301 // Create a group to show all the discovered resources.
302 // Adding the group to the folder.
303 Group resourceGroup = new Group(folder, SWT.NONE);
304 // resourceGroup.setText("Discovered Resources");
306 Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
307 resourceGroup.setBackground(color);
309 resourceGroup.setLayout(new GridLayout(1, false));
310 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
311 resourceGroup.setLayoutData(gd);
313 PatternFilter filter = new PatternFilter();
314 FilteredTree filteredTree = new FilteredTree(resourceGroup,
315 SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
316 singleResTreeViewer = filteredTree.getViewer();
317 singleResTreeViewer.getTree().setLayoutData(
318 new GridData(SWT.FILL, SWT.FILL, true, true));
320 .setContentProvider(new SingleResourceContentProvider());
321 singleResTreeViewer.setLabelProvider(new TreeLabelProvider());
322 singleResTreeViewer.setInput(new Object());
325 .addSelectionChangedListener(new ISelectionChangedListener() {
327 public void selectionChanged(SelectionChangedEvent e) {
328 IStructuredSelection selection = (IStructuredSelection) e
330 if (null == selection) {
335 int size = selection.size();
337 res = (Resource) selection.getFirstElement();
339 resourceManager.resourceSelectionChanged(res);
343 // TODO: Add menu items
344 addMenuToSimpleResources();
346 singleResTab.setControl(resourceGroup);
349 private void addMenuToSimpleResources() {
350 if (null != singleResTreeViewer) {
351 final Tree resourceTreeHead = singleResTreeViewer.getTree();
352 if (null != resourceTreeHead) {
353 // Below code creates menu entries and shows them on right
354 // clicking a resource
355 final Menu menu = new Menu(resourceTreeHead);
356 resourceTreeHead.setMenu(menu);
357 menu.addMenuListener(new MenuAdapter() {
359 public void menuShown(MenuEvent e) {
360 // Clear existing menu items
361 MenuItem[] items = menu.getItems();
362 for (int index = 0; index < items.length; index++) {
363 items[index].dispose();
366 IStructuredSelection selection = ((IStructuredSelection) singleResTreeViewer
368 final SingleResource resource = (SingleResource) selection
370 if (null == resource) {
374 addAutomationMenu(menu, resource);
376 // Menu to add resource to one or more collections.
377 MenuItem addToCollection = new MenuItem(menu, SWT.NONE);
378 addToCollection.setText("Add to Collection");
380 .addSelectionListener(new SelectionAdapter() {
382 public void widgetSelected(SelectionEvent e) {
383 List<CollectionResource> possibleCollections;
384 possibleCollections = resourceManager
385 .getCollectionsForAddingToSingleResource(resource);
386 if (null == possibleCollections
387 || possibleCollections
393 "No possible candidates",
394 "There are no possible collections to which the resource can be added.");
398 AddResourceToCollections addToCollectionsDlg = new AddResourceToCollections(
401 possibleCollections);
402 if (addToCollectionsDlg.open() != Window.OK) {
406 Set<CollectionResource> resultSet = addToCollectionsDlg
407 .getSelectedResourceList();
409 int addedCount = resourceManager
410 .addResourceToCollection(
411 resultSet, resource);
412 if (addedCount <= 0) {
414 .openInformation(Display
418 "Failed to add resources to the collection.");
422 collectionResTreeViewer.refresh();
424 deviceTreeViewer.refresh();
426 MessageDialog.openInformation(
434 + "] added to selected collections");
438 // Menu to remove resource from one or more collections
439 // to which it is a member.
440 MenuItem removeFromCollection = new MenuItem(menu,
442 removeFromCollection.setText("Remove from Collection");
444 .addSelectionListener(new SelectionAdapter() {
446 public void widgetSelected(SelectionEvent e) {
447 List<CollectionResource> possibleCollectionstoRemoveFrom;
448 possibleCollectionstoRemoveFrom = resourceManager
449 .getResourceReferences(resource);
450 if (null == possibleCollectionstoRemoveFrom
451 || possibleCollectionstoRemoveFrom
457 "No possible candidates",
458 "Resource has not been added to any collections.");
462 RemoveResourceFromCollections removeFromCollectionsDlg = new RemoveResourceFromCollections(
465 possibleCollectionstoRemoveFrom);
466 if (removeFromCollectionsDlg.open() != Window.OK) {
470 Set<CollectionResource> resultSet = removeFromCollectionsDlg
471 .getSelectedResourceList();
473 int removeCount = resourceManager
474 .removeResourceFromCollection(
475 resultSet, resource);
476 if (removeCount <= 0) {
478 .openInformation(Display
482 "Failed to remove resources from the collection.");
486 collectionResTreeViewer.refresh();
488 deviceTreeViewer.refresh();
490 MessageDialog.openInformation(
498 + "] resource removed from selected collections");
502 // Menu to add resource to one or more devices.
503 MenuItem addToDevice = new MenuItem(menu, SWT.NONE);
504 addToDevice.setText("Add to Device");
506 .addSelectionListener(new SelectionAdapter() {
508 public void widgetSelected(SelectionEvent e) {
509 List<Device> possibleDevices;
510 possibleDevices = resourceManager
511 .getDevicesForAddingToResource(resource);
512 if (null == possibleDevices
513 || possibleDevices.isEmpty()) {
518 "No possible candidates",
519 "There are no possible devices to which the resource can be added.");
523 AddResourceToDevices addToDevicesDlg = new AddResourceToDevices(
527 if (addToDevicesDlg.open() != Window.OK) {
531 Set<Device> resultSet = addToDevicesDlg
532 .getSelectedDeviceList();
534 resourceManager.addResourceToDevice(
535 resultSet, resource);
537 deviceTreeViewer.refresh();
540 .openInformation(Display
544 "Resource added to selected devices.");
548 // Menu to remove resource from one or more device to
549 // which it is a member.
550 MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE);
551 removeFromDevice.setText("Remove from Device");
553 .addSelectionListener(new SelectionAdapter() {
555 public void widgetSelected(SelectionEvent e) {
556 List<Device> possibleDevices;
557 possibleDevices = resourceManager
558 .getDeviceReferences(resource);
559 if (null == possibleDevices
560 || possibleDevices.isEmpty()) {
565 "No possible candidates",
566 "Resource has not been added to any devices.");
570 RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices(
574 if (removeFromDevicesDlg.open() != Window.OK) {
578 Set<Device> resultSet = removeFromDevicesDlg
579 .getSelectedDeviceList();
582 .removeResourceFromDevice(
583 resultSet, resource);
585 deviceTreeViewer.refresh();
588 .openInformation(Display
592 "Resource removed from selected devices");
596 // Menu to remove resource from one or more device to
597 // which it is a member.
598 MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
599 deleteResource.setText("Delete");
601 .addSelectionListener(new SelectionAdapter() {
603 public void widgetSelected(SelectionEvent e) {
606 .removeResource(resource);
607 singleResTreeViewer.refresh();
608 // if(refreshCollectionTree)
609 collectionResTreeViewer.refresh();
610 // if(refreshDeviceTree)
611 deviceTreeViewer.refresh();
614 .resourceSelectionChanged(null);
616 MessageDialog.openInformation(
620 "Resource deleted.");
621 } catch (SimulatorException e1) {
623 .openInformation(Display
627 "Failed to delete the resource.");
629 changeDeleteVisibility();
638 private void createCollectionResourcesArea() {
639 collectionResTab = new CTabItem(folder, SWT.NULL);
640 collectionResTab.setText("Collection Resources");
642 // Create a group to show all the discovered resources.
643 // Adding the group to the folder.
644 Group resourceGroup = new Group(folder, SWT.NONE);
645 // resourceGroup.setText("Discovered Resources");
647 Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
648 resourceGroup.setBackground(color);
650 resourceGroup.setLayout(new GridLayout(1, false));
651 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
652 resourceGroup.setLayoutData(gd);
654 PatternFilter filter = new PatternFilter();
655 FilteredTree filteredTree = new FilteredTree(resourceGroup,
656 SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
657 collectionResTreeViewer = filteredTree.getViewer();
658 collectionResTreeViewer.getTree().setLayoutData(
659 new GridData(SWT.FILL, SWT.FILL, true, true));
660 collectionResTreeViewer
661 .setContentProvider(new CollectionResourceContentProvider());
662 collectionResTreeViewer.setLabelProvider(new TreeLabelProvider());
663 collectionResTreeViewer.setInput(new Object());
665 collectionResTreeViewer
666 .addSelectionChangedListener(new ISelectionChangedListener() {
668 public void selectionChanged(SelectionChangedEvent e) {
669 IStructuredSelection selection = (IStructuredSelection) e
671 if (null == selection) {
676 int size = selection.size();
678 res = (Resource) selection.getFirstElement();
680 resourceManager.resourceSelectionChanged(res);
684 // TODO: Add menu items
685 addMenuToCollectionResources();
687 collectionResTab.setControl(resourceGroup);
690 private void addMenuToCollectionResources() {
691 if (null != collectionResTreeViewer) {
692 final Tree resourceTreeHead = collectionResTreeViewer.getTree();
693 if (null != resourceTreeHead) {
694 // Below code creates menu entries and shows them on right
695 // clicking a resource
696 final Menu menu = new Menu(resourceTreeHead);
697 resourceTreeHead.setMenu(menu);
698 menu.addMenuListener(new MenuAdapter() {
700 public void menuShown(MenuEvent e) {
701 // Clear existing menu items
702 MenuItem[] items = menu.getItems();
703 for (int index = 0; index < items.length; index++) {
704 items[index].dispose();
707 IStructuredSelection selection = ((IStructuredSelection) collectionResTreeViewer
709 final Resource resource = (Resource) selection
711 TreeItem[] treeItems = resourceTreeHead.getSelection();
712 if (null == resource || null == treeItems) {
716 final TreeItem parent = treeItems[0].getParentItem();
717 if (null == parent) {
718 System.out.println("No parent exist");
719 // Selected item is a top-level collection
720 addMenuToTopLevelCollectionResources(menu,
721 (CollectionResource) resource);
723 if (resource instanceof SingleResource)
724 addAutomationMenu(menu,
725 (SingleResource) resource);
727 MenuItem remFromParent = new MenuItem(menu,
729 remFromParent.setText("Remove from Parent");
731 .addSelectionListener(new SelectionAdapter() {
733 public void widgetSelected(
735 CollectionResource parentCollection = (CollectionResource) parent
740 .removeResourceFromCollection(
743 collectionResTreeViewer
745 deviceTreeViewer.refresh();
748 .resourceSelectionChanged(null);
750 status = "Resource removed from its parent";
751 } catch (SimulatorException e1) {
752 status = "Failed to remove the resource from its parent";
754 MessageDialog.openInformation(
761 if (resource instanceof SingleResource) {
762 // Menu Items for single resource will be added
772 private void addMenuToTopLevelCollectionResources(final Menu menu,
773 final CollectionResource colRes) {
774 // Menu to add one or more resources to the collection.
775 MenuItem addResources = new MenuItem(menu, SWT.CASCADE);
776 addResources.setText("Add Resources");
778 Menu addSubMenu = new Menu(menu);
779 addResources.setMenu(addSubMenu);
781 MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE);
782 simpleResources.setText("Simple");
783 simpleResources.addSelectionListener(new SelectionAdapter() {
785 public void widgetSelected(SelectionEvent e) {
786 List<SingleResource> possibleResources;
787 possibleResources = resourceManager
788 .getSingleTypeResourcesForAddingToCollectionResource(colRes);
789 if (null == possibleResources || possibleResources.isEmpty()) {
791 .openError(Display.getDefault().getActiveShell(),
792 "No possible candidates",
793 "There are no possible simple resources that can be added.");
797 List<Resource> resources = Utility
798 .convertSingleTypeResourceListToBaseType(possibleResources);
800 AddResources addToCollectionsDlg = new AddResources(Display
801 .getDefault().getActiveShell(), resources);
802 if (addToCollectionsDlg.open() != Window.OK) {
806 Set<Resource> resultSet = addToCollectionsDlg
807 .getSelectedResourceList();
809 int addedCount = resourceManager.addResourceToCollection(
811 if (addedCount <= 0) {
812 MessageDialog.openInformation(Display.getDefault()
813 .getActiveShell(), "Operation failed",
814 "Failed to add resources to the collection.");
818 collectionResTreeViewer.refresh();
820 deviceTreeViewer.refresh();
822 MessageDialog.openInformation(Display.getDefault()
823 .getActiveShell(), "Added", "[" + addedCount + "/"
825 + "] resources added to the collection");
829 MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE);
830 collectionResources.setText("Collection");
831 collectionResources.addSelectionListener(new SelectionAdapter() {
833 public void widgetSelected(SelectionEvent e) {
834 List<CollectionResource> possibleResources;
835 possibleResources = resourceManager
836 .getCollectionTypeResourcesForAddingToCollectionResource(colRes);
837 if (null == possibleResources || possibleResources.isEmpty()) {
839 .openError(Display.getDefault().getActiveShell(),
840 "No possible candidates",
841 "There are no possible collections that can be added.");
845 List<Resource> resources = Utility
846 .convertCollectionTypeResourceListToBaseType(possibleResources);
848 AddResources addToCollectionsDlg = new AddResources(Display
849 .getDefault().getActiveShell(), resources);
850 if (addToCollectionsDlg.open() != Window.OK) {
854 Set<Resource> resultSet = addToCollectionsDlg
855 .getSelectedResourceList();
857 int addedCount = resourceManager.addResourceToCollection(
859 if (addedCount <= 0) {
860 MessageDialog.openInformation(Display.getDefault()
861 .getActiveShell(), "Operation failed",
862 "Failed to add resources to the collection.");
866 collectionResTreeViewer.refresh();
868 deviceTreeViewer.refresh();
870 MessageDialog.openInformation(Display.getDefault()
871 .getActiveShell(), "Added", "[" + addedCount + "/"
873 + "] resources added to the collection");
877 // Menu to remove one or more resources from the collection.
878 MenuItem removeResources = new MenuItem(menu, SWT.CASCADE);
879 removeResources.setText("Remove Resources");
881 Menu removeSubMenu = new Menu(menu);
882 removeResources.setMenu(removeSubMenu);
884 simpleResources = new MenuItem(removeSubMenu, SWT.NONE);
885 simpleResources.setText("Simple");
886 simpleResources.addSelectionListener(new SelectionAdapter() {
888 public void widgetSelected(SelectionEvent e) {
889 List<SingleResource> possibleResources;
890 possibleResources = resourceManager.getSingleTypeChilds(colRes);
891 if (null == possibleResources || possibleResources.isEmpty()) {
893 .openError(Display.getDefault().getActiveShell(),
894 "No possible candidates",
895 "There are no possible simple resources which can be removed.");
899 List<Resource> resources = Utility
900 .convertSingleTypeResourceListToBaseType(possibleResources);
902 RemoveResources removeFromCollectionsDlg = new RemoveResources(
903 Display.getDefault().getActiveShell(), resources);
904 if (removeFromCollectionsDlg.open() != Window.OK) {
908 Set<Resource> resultSet = removeFromCollectionsDlg
909 .getSelectedResourceList();
911 int removeCount = resourceManager
912 .removeResourcesFromCollection(colRes, resultSet);
913 if (removeCount <= 0) {
914 MessageDialog.openInformation(Display.getDefault()
915 .getActiveShell(), "Operation failed",
916 "Failed to remove resources from the collection.");
920 collectionResTreeViewer.refresh();
922 deviceTreeViewer.refresh();
924 MessageDialog.openInformation(Display.getDefault()
925 .getActiveShell(), "Removed", "[" + removeCount + "/"
927 + "] resources removed from the collection");
931 collectionResources = new MenuItem(removeSubMenu, SWT.NONE);
932 collectionResources.setText("Collection");
933 collectionResources.addSelectionListener(new SelectionAdapter() {
935 public void widgetSelected(SelectionEvent e) {
936 List<CollectionResource> possibleResources;
937 possibleResources = resourceManager
938 .getCollectionTypeChilds(colRes);
939 if (null == possibleResources || possibleResources.isEmpty()) {
941 .openError(Display.getDefault().getActiveShell(),
942 "No possible candidates",
943 "There are no possible collections which can be removed.");
947 List<Resource> resources = Utility
948 .convertCollectionTypeResourceListToBaseType(possibleResources);
950 RemoveResources removeFromCollectionsDlg = new RemoveResources(
951 Display.getDefault().getActiveShell(), resources);
952 if (removeFromCollectionsDlg.open() != Window.OK) {
956 Set<Resource> resultSet = removeFromCollectionsDlg
957 .getSelectedResourceList();
959 int removeCount = resourceManager
960 .removeResourcesFromCollection(colRes, resultSet);
961 if (removeCount <= 0) {
962 MessageDialog.openInformation(Display.getDefault()
963 .getActiveShell(), "Operation failed",
964 "Failed to remove resources from the collection.");
968 collectionResTreeViewer.refresh();
970 deviceTreeViewer.refresh();
972 MessageDialog.openInformation(Display.getDefault()
973 .getActiveShell(), "Removed", "[" + removeCount + "/"
975 + "] resources removed from the collection");
979 // Menu to add resource to one or more devices.
980 MenuItem addToDevice = new MenuItem(menu, SWT.NONE);
981 addToDevice.setText("Add to Device");
982 addToDevice.addSelectionListener(new SelectionAdapter() {
984 public void widgetSelected(SelectionEvent e) {
985 List<Device> possibleDevices;
986 possibleDevices = resourceManager
987 .getDevicesForAddingToResource(colRes);
988 if (null == possibleDevices || possibleDevices.isEmpty()) {
990 .openError(Display.getDefault().getActiveShell(),
991 "No possible candidates",
992 "There are no possible devices to which the resource can be added.");
996 AddResourceToDevices addToDevicesDlg = new AddResourceToDevices(
997 Display.getDefault().getActiveShell(), possibleDevices);
998 if (addToDevicesDlg.open() != Window.OK) {
1002 Set<Device> resultSet = addToDevicesDlg.getSelectedDeviceList();
1004 resourceManager.addResourceToDevice(resultSet, colRes);
1006 deviceTreeViewer.refresh();
1008 MessageDialog.openInformation(Display.getDefault()
1009 .getActiveShell(), "Added",
1010 "Resource added to selected devices.");
1014 // Menu to remove resource from one or more device to which it is a
1016 MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE);
1017 removeFromDevice.setText("Remove from Device");
1018 removeFromDevice.addSelectionListener(new SelectionAdapter() {
1020 public void widgetSelected(SelectionEvent e) {
1021 List<Device> possibleDevices;
1022 possibleDevices = resourceManager.getDeviceReferences(colRes);
1023 if (null == possibleDevices || possibleDevices.isEmpty()) {
1024 MessageDialog.openError(Display.getDefault()
1025 .getActiveShell(), "No possible candidates",
1026 "Resource has not been added to any devices.");
1030 RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices(
1031 Display.getDefault().getActiveShell(), possibleDevices);
1032 if (removeFromDevicesDlg.open() != Window.OK) {
1036 Set<Device> resultSet = removeFromDevicesDlg
1037 .getSelectedDeviceList();
1039 resourceManager.removeResourceFromDevice(resultSet, colRes);
1041 deviceTreeViewer.refresh();
1043 MessageDialog.openInformation(Display.getDefault()
1044 .getActiveShell(), "Removed",
1045 "Resource removed from selected devices");
1049 // Menu to remove resource from one or more device to which it is a
1051 MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
1052 deleteResource.setText("Delete");
1053 deleteResource.addSelectionListener(new SelectionAdapter() {
1055 public void widgetSelected(SelectionEvent e) {
1057 * boolean refreshCollectionTree = false; boolean
1058 * refreshDeviceTree = false;
1059 * if(resource.isMemberOfAnyCollection()) {
1060 * refreshCollectionTree = true; }
1061 * if(resource.isMemberOfAnyDevice()) { refreshDeviceTree =
1065 resourceManager.removeResource(colRes);
1066 // if(refreshCollectionTree)
1067 collectionResTreeViewer.refresh();
1068 // if(refreshDeviceTree)
1069 deviceTreeViewer.refresh();
1071 resourceManager.resourceSelectionChanged(null);
1073 MessageDialog.openInformation(Display.getDefault()
1074 .getActiveShell(), "Deleted", "Resource deleted.");
1075 } catch (SimulatorException e1) {
1076 MessageDialog.openInformation(Display.getDefault()
1077 .getActiveShell(), "Deletion Failed",
1078 "Failed to delete the resource.");
1081 changeDeleteVisibility();
1087 private void createDeviceArea() {
1088 deviceTab = new CTabItem(folder, SWT.NULL);
1089 deviceTab.setText("Devices");
1091 // Create a group to show all the discovered resources.
1092 // Adding the group to the folder.
1093 Group resourceGroup = new Group(folder, SWT.NONE);
1094 // resourceGroup.setText("Discovered Resources");
1096 Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
1097 resourceGroup.setBackground(color);
1099 resourceGroup.setLayout(new GridLayout(1, false));
1100 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
1101 resourceGroup.setLayoutData(gd);
1103 PatternFilter filter = new PatternFilter();
1104 FilteredTree filteredTree = new FilteredTree(resourceGroup,
1105 SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
1106 deviceTreeViewer = filteredTree.getViewer();
1107 deviceTreeViewer.getTree().setLayoutData(
1108 new GridData(SWT.FILL, SWT.FILL, true, true));
1109 deviceTreeViewer.setContentProvider(new DeviceContentProvider());
1110 deviceTreeViewer.setLabelProvider(new TreeLabelProvider());
1111 deviceTreeViewer.setInput(new Object());
1114 .addSelectionChangedListener(new ISelectionChangedListener() {
1116 public void selectionChanged(SelectionChangedEvent e) {
1117 IStructuredSelection selection = (IStructuredSelection) e
1119 if (null == selection) {
1123 int size = selection.size();
1125 Object obj = selection.getFirstElement();
1126 if (obj instanceof Device) {
1128 .deviceSelectionChanged((Device) obj);
1131 .resourceSelectionChanged((Resource) obj);
1134 resourceManager.deviceSelectionChanged(null);
1139 // TODO: Add menu items
1142 deviceTab.setControl(resourceGroup);
1145 private void addMenuToDevices() {
1146 if (null != deviceTreeViewer) {
1147 final Tree resourceTreeHead = deviceTreeViewer.getTree();
1148 if (null != resourceTreeHead) {
1149 // Below code creates menu entries and shows them on right
1150 // clicking a resource
1151 final Menu menu = new Menu(resourceTreeHead);
1152 resourceTreeHead.setMenu(menu);
1153 menu.addMenuListener(new MenuAdapter() {
1155 public void menuShown(MenuEvent e) {
1156 // Clear existing menu items
1157 MenuItem[] items = menu.getItems();
1158 for (int index = 0; index < items.length; index++) {
1159 items[index].dispose();
1162 IStructuredSelection selection = ((IStructuredSelection) deviceTreeViewer
1164 final Object element = selection.getFirstElement();
1165 if (element instanceof Device) {
1166 addMenuToDevices(menu, (Device) element);
1168 final Resource resource = (Resource) element;
1169 TreeItem[] treeItems = resourceTreeHead
1171 if (null == resource || null == treeItems) {
1175 if (resource instanceof SingleResource)
1176 addAutomationMenu(menu,
1177 (SingleResource) resource);
1179 final TreeItem parent = treeItems[0]
1181 MenuItem remFromParent = new MenuItem(menu,
1183 remFromParent.setText("Remove from Parent");
1185 .addSelectionListener(new SelectionAdapter() {
1187 public void widgetSelected(
1189 String status = "Resource removed from its parent.";
1190 Object obj = parent.getData();
1191 if (obj instanceof Device) {
1193 .removeResourceFromDevice(
1199 .removeResourceFromCollection(
1200 (CollectionResource) obj,
1202 collectionResTreeViewer
1204 status = "Resource removed from its parent";
1205 } catch (SimulatorException e1) {
1206 status = "Failed to remove the resource from its parent";
1210 deviceTreeViewer.refresh();
1212 MessageDialog.openInformation(
1213 Display.getDefault()
1219 if (resource instanceof SingleResource) {
1220 // Menu Items for single resource will be added
1230 private void addMenuToDevices(Menu menu, final Device dev) {
1231 // Menu to add one or more resources to the collection.
1232 MenuItem addResources = new MenuItem(menu, SWT.CASCADE);
1233 addResources.setText("Add Resources");
1235 Menu addSubMenu = new Menu(menu);
1236 addResources.setMenu(addSubMenu);
1238 MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE);
1239 simpleResources.setText("Simple");
1240 simpleResources.addSelectionListener(new SelectionAdapter() {
1242 public void widgetSelected(SelectionEvent e) {
1243 List<SingleResource> possibleResources;
1244 possibleResources = resourceManager
1245 .getSingleTypeResourcesForAddingToDevice(dev);
1246 if (null == possibleResources || possibleResources.isEmpty()) {
1248 .openError(Display.getDefault().getActiveShell(),
1249 "No possible candidates",
1250 "There are no possible simple resources that can be added.");
1254 List<Resource> resources = Utility
1255 .convertSingleTypeResourceListToBaseType(possibleResources);
1257 AddResources addDlg = new AddResources(Display.getDefault()
1258 .getActiveShell(), resources);
1259 if (addDlg.open() != Window.OK) {
1263 Set<Resource> resultSet = addDlg.getSelectedResourceList();
1265 resourceManager.addResourceToDevice(dev, resultSet);
1267 deviceTreeViewer.refresh();
1269 MessageDialog.openInformation(Display.getDefault()
1270 .getActiveShell(), "Added",
1271 "Single Resources added to the device");
1275 MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE);
1276 collectionResources.setText("Collection");
1277 collectionResources.addSelectionListener(new SelectionAdapter() {
1279 public void widgetSelected(SelectionEvent e) {
1280 List<CollectionResource> possibleResources;
1281 possibleResources = resourceManager
1282 .getCollectionTypeResourcesForAddingToDevice(dev);
1283 if (null == possibleResources || possibleResources.isEmpty()) {
1285 .openError(Display.getDefault().getActiveShell(),
1286 "No possible candidates",
1287 "There are no possible collections that can be added.");
1291 List<Resource> resources = Utility
1292 .convertCollectionTypeResourceListToBaseType(possibleResources);
1294 AddResources addDlg = new AddResources(Display.getDefault()
1295 .getActiveShell(), resources);
1296 if (addDlg.open() != Window.OK) {
1300 Set<Resource> resultSet = addDlg.getSelectedResourceList();
1302 resourceManager.addResourceToDevice(dev, resultSet);
1304 deviceTreeViewer.refresh();
1306 MessageDialog.openInformation(Display.getDefault()
1307 .getActiveShell(), "Added",
1308 "Collection Resources added to the device");
1312 // Menu to remove one or more resources from the collection.
1313 MenuItem removeResources = new MenuItem(menu, SWT.CASCADE);
1314 removeResources.setText("Remove Resources");
1316 Menu removeSubMenu = new Menu(menu);
1317 removeResources.setMenu(removeSubMenu);
1319 simpleResources = new MenuItem(removeSubMenu, SWT.NONE);
1320 simpleResources.setText("Simple");
1321 simpleResources.addSelectionListener(new SelectionAdapter() {
1323 public void widgetSelected(SelectionEvent e) {
1324 List<SingleResource> possibleResources;
1325 possibleResources = resourceManager.getSingleTypeChilds(dev);
1326 if (null == possibleResources || possibleResources.isEmpty()) {
1328 .openError(Display.getDefault().getActiveShell(),
1329 "No possible candidates",
1330 "There are no possible simple resources which can be removed.");
1334 List<Resource> resources = Utility
1335 .convertSingleTypeResourceListToBaseType(possibleResources);
1337 RemoveResources removeDlg = new RemoveResources(Display
1338 .getDefault().getActiveShell(), resources);
1339 if (removeDlg.open() != Window.OK) {
1343 Set<Resource> resultSet = removeDlg.getSelectedResourceList();
1345 resourceManager.removeResourcesFromDevice(dev, resultSet);
1347 collectionResTreeViewer.refresh();
1349 deviceTreeViewer.refresh();
1351 MessageDialog.openInformation(Display.getDefault()
1352 .getActiveShell(), "Removed",
1353 "Single Resources removed from the device");
1357 collectionResources = new MenuItem(removeSubMenu, SWT.NONE);
1358 collectionResources.setText("Collection");
1359 collectionResources.addSelectionListener(new SelectionAdapter() {
1361 public void widgetSelected(SelectionEvent e) {
1362 List<CollectionResource> possibleResources;
1363 possibleResources = resourceManager
1364 .getCollectionTypeChilds(dev);
1365 if (null == possibleResources || possibleResources.isEmpty()) {
1367 .openError(Display.getDefault().getActiveShell(),
1368 "No possible candidates",
1369 "There are no possible collections which can be removed.");
1373 List<Resource> resources = Utility
1374 .convertCollectionTypeResourceListToBaseType(possibleResources);
1376 RemoveResources removeDlg = new RemoveResources(Display
1377 .getDefault().getActiveShell(), resources);
1378 if (removeDlg.open() != Window.OK) {
1382 Set<Resource> resultSet = removeDlg.getSelectedResourceList();
1384 resourceManager.removeResourcesFromDevice(dev, resultSet);
1386 collectionResTreeViewer.refresh();
1388 deviceTreeViewer.refresh();
1390 MessageDialog.openInformation(Display.getDefault()
1391 .getActiveShell(), "Removed",
1392 "Collection Resources removed from the device");
1396 // Menu to remove the device.
1397 MenuItem deleteDevice = new MenuItem(menu, SWT.NONE);
1398 deleteDevice.setText("Delete");
1399 deleteDevice.addSelectionListener(new SelectionAdapter() {
1401 public void widgetSelected(SelectionEvent e) {
1402 resourceManager.removeDevice(dev);
1403 deviceTreeViewer.refresh();
1408 private void addAutomationMenu(final Menu menu,
1409 final SingleResource selectedResource) {
1410 MenuItem startItem = new MenuItem(menu, SWT.NONE);
1411 startItem.setText(Constants.START_RESOURCE_AUTOMATION);
1412 startItem.addSelectionListener(new SelectionAdapter() {
1414 public void widgetSelected(SelectionEvent e) {
1415 // Block starting resource level
1416 // automation if any attribute level
1417 // automation is in progress for the
1418 // selected resource
1419 boolean started = resourceManager
1420 .isAttributeAutomationStarted(selectedResource);
1424 Display.getDefault().getActiveShell(),
1425 "Attribute automation is in progress",
1426 "Attribute level automation for this resource is already in progress!!!\nPlease stop all "
1427 + "running attribute level automations to start resource level automation.");
1430 // Start the automation
1431 // Fetch the settings data
1432 List<AutomationSettingHelper> automationSettings;
1433 automationSettings = AutomationSettingHelper
1434 .getAutomationSettings(null);
1436 // Open the settings dialog
1437 AutomationSettingDialog dialog = new AutomationSettingDialog(
1438 Activator.getDefault().getWorkbench()
1439 .getActiveWorkbenchWindow().getShell(),
1440 automationSettings);
1442 if (dialog.open() == Window.OK) {
1443 String automationType = dialog.getAutomationType();
1444 String updateFreq = dialog.getUpdateFrequency();
1446 AutoUpdateType autoType = AutoUpdateType
1447 .valueOf(automationType);
1448 int updFreq = Utility
1449 .getUpdateIntervalFromString(updateFreq);
1450 boolean status = resourceManager
1451 .startResourceAutomationUIRequest(autoType,
1452 updFreq, selectedResource);
1453 String statusMsg = status ? "Automation started successfully!!!"
1454 : "Automation request failed!!!";
1455 MessageDialog.openInformation(Display.getDefault()
1456 .getActiveShell(), "Automation Status",
1463 MenuItem stopItem = new MenuItem(menu, SWT.NONE);
1464 stopItem.setText(Constants.STOP_RESOURCE_AUTOMATION);
1465 stopItem.addSelectionListener(new SelectionAdapter() {
1467 public void widgetSelected(SelectionEvent e) {
1468 boolean status = resourceManager
1469 .stopResourceAutomationUIRequest(selectedResource);
1470 String statusMsg = status ? "Automation stopped!!!"
1471 : "Automation stop failed.";
1472 MessageDialog.openInformation(Display.getDefault()
1473 .getActiveShell(), "Automation Status", statusMsg);
1477 // Set the initial visibility of menu items
1478 boolean status = resourceManager
1479 .isResourceAutomationStarted(selectedResource);
1480 startItem.setEnabled(!status);
1481 stopItem.setEnabled(status);
1484 private void addUIListeners() {
1486 createButton.addSelectionListener(new SelectionAdapter() {
1488 public void widgetSelected(SelectionEvent e) {
1489 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
1493 CreateResourceWizard createWizard = new CreateResourceWizard();
1494 ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
1495 PlatformUI.getWorkbench().getDisplay()
1496 .getActiveShell(), createWizard);
1497 createWizard.setWizardDialog(wizardDialog);
1498 int open = wizardDialog.open();
1499 if (open == WizardDialog.OK
1500 || createWizard.isDlgForceClosed()) {
1502 Option option = createWizard.getMainPage()
1504 if (option == Option.DEVICE) {
1505 Device dev = createWizard.getCreatedDevice();
1507 folder.setSelection(deviceTab);
1508 deviceTreeViewer.setSelection(
1509 new StructuredSelection(dev), true);
1510 resourceManager.deviceSelectionChanged(dev);
1511 deviceTreeViewer.expandToLevel(dev,
1512 Constants.TREE_EXPANSION_LEVEL);
1514 } else if (option == Option.SIMPLE_FROM_RAML
1515 || option == Option.SIMPLE) {
1516 SingleResource res = (SingleResource) createWizard
1517 .getCreatedResource();
1519 folder.setSelection(singleResTab);
1520 boolean canSelect = true;
1521 if (option == Option.SIMPLE_FROM_RAML
1522 && createWizard.getResourceCount() > 1) {
1526 singleResTreeViewer.setSelection(
1527 new StructuredSelection(res),
1530 .resourceSelectionChanged(res);
1533 } else if (option == Option.COLLECTION_FROM_RAML
1534 || option == Option.COLLECTION) {
1535 CollectionResource res = (CollectionResource) createWizard
1536 .getCreatedResource();
1538 folder.setSelection(collectionResTab);
1539 collectionResTreeViewer.setSelection(
1540 new StructuredSelection(res), true);
1542 .resourceSelectionChanged(res);
1543 collectionResTreeViewer.expandToLevel(res,
1544 Constants.TREE_EXPANSION_LEVEL);
1548 MessageDialog.openInformation(Display.getDefault()
1550 "Resource Creation Status", createWizard
1558 deleteButton.addSelectionListener(new SelectionAdapter() {
1560 public void widgetSelected(SelectionEvent e) {
1561 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
1565 boolean exist = resourceManager.isAnyResourceExist();
1569 DeleteResourceWizard deleteWizard = new DeleteResourceWizard();
1570 ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
1571 PlatformUI.getWorkbench().getDisplay()
1572 .getActiveShell(), deleteWizard);
1573 int open = wizardDialog.open();
1574 if (open == Window.OK) {
1575 singleResTreeViewer.refresh();
1576 collectionResTreeViewer.refresh();
1577 deviceTreeViewer.refresh();
1578 MessageDialog.openInformation(Display.getDefault()
1580 "Resource Deletion Status", deleteWizard
1583 changeDeleteVisibility();
1591 public void addManagerListeners() {
1592 UiListenerHandler.getInstance().addResourceListChangedUIListener(
1593 resourceListChangedListener);
1594 UiListenerHandler.getInstance().addResourcePropertiesChangedUIListener(
1595 resourcePropertiesChangedListener);
1599 public void setFocus() {
1603 public void dispose() {
1604 // Unregister the listener
1605 if (null != resourceListChangedListener) {
1606 UiListenerHandler.getInstance()
1607 .removeResourceListChangedUIListener(
1608 resourceListChangedListener);
1609 resourceManager.resourceSelectionChanged(null);
1611 if (null != resourcePropertiesChangedListener) {
1612 UiListenerHandler.getInstance()
1613 .removeResourcePropertiesChangedUIListener(
1614 resourcePropertiesChangedListener);
1620 class SingleResourceContentProvider implements ITreeContentProvider {
1623 public void dispose() {
1627 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
1631 public Object[] getChildren(Object parent) {
1636 public Object[] getElements(Object parent) {
1637 List<SingleResource> resList;
1638 resList = Activator.getDefault().getResourceManager()
1639 .getSingleResourceList();
1640 if (null == resList) {
1641 resList = new ArrayList<SingleResource>();
1643 return resList.toArray();
1647 public Object getParent(Object child) {
1652 public boolean hasChildren(Object parent) {
1657 class CollectionResourceContentProvider implements ITreeContentProvider {
1660 public void dispose() {
1664 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
1668 public Object[] getChildren(Object parent) {
1669 if (parent instanceof CollectionResource) {
1670 CollectionResource cRes = (CollectionResource) parent;
1671 Set<Resource> childs = cRes.getChildResources();
1672 if (null == childs) {
1675 return childs.toArray();
1681 public Object[] getElements(Object parent) {
1682 List<CollectionResource> resList;
1683 resList = Activator.getDefault().getResourceManager()
1684 .getCollectionResourceList();
1685 if (null == resList) {
1686 resList = new ArrayList<CollectionResource>();
1688 return resList.toArray();
1692 public Object getParent(Object child) {
1697 public boolean hasChildren(Object parent) {
1698 if (parent instanceof CollectionResource) {
1699 CollectionResource cRes = (CollectionResource) parent;
1700 Set<Resource> children = cRes.getChildResources();
1701 if (null != children && children.size() > 0) {
1709 class DeviceContentProvider implements ITreeContentProvider {
1712 public void dispose() {
1716 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
1720 public Object[] getChildren(Object parent) {
1721 if (parent instanceof Device) {
1722 Device dev = (Device) parent;
1723 Set<Resource> children = dev.getChildResources();
1724 if (null != children && children.size() > 0) {
1725 return children.toArray();
1727 } else if (parent instanceof CollectionResource) {
1728 CollectionResource res = (CollectionResource) parent;
1729 Set<Resource> children = res.getChildResources();
1730 if (null != children && children.size() > 0) {
1731 return children.toArray();
1738 public Object[] getElements(Object parent) {
1739 List<Device> deviceList;
1740 deviceList = Activator.getDefault().getResourceManager()
1742 if (null == deviceList) {
1743 deviceList = new ArrayList<Device>();
1745 return deviceList.toArray();
1749 public Object getParent(Object child) {
1754 public boolean hasChildren(Object parent) {
1755 if (parent instanceof Device) {
1756 Device dev = (Device) parent;
1757 Set<Resource> children = dev.getChildResources();
1758 if (null != children && children.size() > 0) {
1761 } else if (parent instanceof CollectionResource) {
1762 CollectionResource res = (CollectionResource) parent;
1763 Set<Resource> children = res.getChildResources();
1764 if (null != children && children.size() > 0) {
1772 class TreeLabelProvider extends LabelProvider {
1774 public String getText(Object element) {
1775 if (element instanceof Resource) {
1776 Resource res = (Resource) element;
1777 return res.getResourceName();
1779 Device dev = (Device) element;
1780 return dev.getDeviceName();
1785 public Image getImage(Object element) {
1786 if (element instanceof SingleResource) {
1787 return Activator.getDefault().getImageRegistry()
1788 .get(Constants.SINGLE_RESOURCE);
1789 } else if (element instanceof CollectionResource) {
1790 return Activator.getDefault().getImageRegistry()
1791 .get(Constants.COLLECTION_RESOURCE);
1793 return Activator.getDefault().getImageRegistry()
1794 .get(Constants.DEVICE);