Updated URI parsing code in server and added code to keep observed resources list...
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / DeleteResourceWizard.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.serviceprovider.view.dialogs;
18
19 import java.net.URL;
20
21 import oic.simulator.serviceprovider.Activator;
22 import oic.simulator.serviceprovider.resource.DeleteCategory;
23 import oic.simulator.serviceprovider.utils.Utility;
24
25 import org.eclipse.core.runtime.FileLocator;
26 import org.eclipse.core.runtime.IPath;
27 import org.eclipse.core.runtime.Path;
28 import org.eclipse.jface.dialogs.MessageDialog;
29 import org.eclipse.jface.resource.ImageDescriptor;
30 import org.eclipse.jface.wizard.Wizard;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.ui.PlatformUI;
33
34 /**
35  * This class creates a UI wizard for delete resource operation.
36  */
37 public class DeleteResourceWizard extends Wizard {
38
39     private DeleteResourcePage page;
40
41     public DeleteResourceWizard() {
42         setWindowTitle("Delete resources");
43         IPath path = new Path("/icons/oic_logo_64x64.png");
44         URL find = FileLocator.find(Activator.getDefault().getBundle(), path,
45                 null);
46         setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(find));
47     }
48
49     @Override
50     public void addPages() {
51         page = new DeleteResourcePage();
52         addPage(page);
53     }
54
55     @Override
56     public boolean performFinish() {
57         if (null == page) {
58             return false;
59         }
60         // Check the existence of the resource if the user has entered the uri
61         if (page.getDeleteCategory() == DeleteCategory.BY_URI) {
62             // Check whether the uri is in full form or short form
63             // If it is in short form, expand it to its full form.
64             String uri = page.getDeleteCandidate();
65             boolean uriComplete = Utility.isUriComplete(uri);
66             if (!uriComplete) {
67                 uri = Utility.displayNameToUri(uri);
68             }
69             boolean exist = Activator.getDefault().getResourceManager()
70                     .isResourceExist(uri);
71             if (!exist) {
72                 Shell activeShell = PlatformUI.getWorkbench().getDisplay()
73                         .getActiveShell();
74                 MessageDialog dialog = new MessageDialog(activeShell,
75                         "Resource Not Found", null,
76                         "No resource exist with the given URI.",
77                         MessageDialog.INFORMATION, new String[] { "OK" }, 0);
78                 dialog.open();
79                 page.setFocusToTextBox();
80                 return false;
81             }
82         }
83         return true;
84     }
85
86     public DeleteCategory getDeleteCategory() {
87         if (null == page) {
88             return DeleteCategory.NONE;
89         }
90         return page.getDeleteCategory();
91     }
92
93     public String getDeleteCandidate() {
94         if (null == page) {
95             return null;
96         }
97         return page.getDeleteCandidate();
98     }
99 }