Java SDK and Eclipse plugin for simulator.
[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         // Check the existence of the resource if the user has entered the uri
58         if (page.getDeleteCategory() == DeleteCategory.BY_URI) {
59             // Check whether the uri is in full form or short form
60             // If it is in short form, expand it to its full form.
61             String uri = page.getDeleteCandidate();
62             boolean uriComplete = Utility.isUriComplete(uri);
63             if (!uriComplete) {
64                 uri = Utility.displayNameToUri(uri);
65             }
66             boolean exist = Activator.getDefault().getResourceManager()
67                     .isResourceExist(uri);
68             if (!exist) {
69                 Shell activeShell = PlatformUI.getWorkbench().getDisplay()
70                         .getActiveShell();
71                 MessageDialog dialog = new MessageDialog(activeShell,
72                         "Resource Not Found", null,
73                         "No resource exist with the given URI.",
74                         MessageDialog.INFORMATION, new String[] { "OK" }, 0);
75                 dialog.open();
76                 page.setFocusToTextBox();
77                 return false;
78             }
79         }
80         return true;
81     }
82
83     public DeleteCategory getDeleteCategory() {
84         return page.getDeleteCategory();
85     }
86
87     public String getDeleteCandidate() {
88         return page.getDeleteCandidate();
89     }
90 }