Base layout of eclipse plugin for service provider.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / DeleteResourceWizard.java
1 package oic.simulator.serviceprovider.view.dialogs;
2
3 import oic.simulator.serviceprovider.Activator;
4 import oic.simulator.serviceprovider.utils.Convertion;
5
6 import org.eclipse.jface.dialogs.MessageDialog;
7 import org.eclipse.jface.wizard.Wizard;
8 import org.eclipse.swt.widgets.Shell;
9 import org.eclipse.ui.PlatformUI;
10
11 public class DeleteResourceWizard extends Wizard {
12
13     private DeleteResourcePage page;
14
15     public DeleteResourceWizard() {
16         setWindowTitle("Delete resources");
17     }
18
19     @Override
20     public void addPages() {
21         page = new DeleteResourcePage();
22         addPage(page);
23     }
24
25     @Override
26     public boolean performFinish() {
27         // Check the existence of the resource if the user has entered the uri
28         if (page.getDeleteCategory() == DeleteCategory.BY_URI) {
29             // Check whether the uri is in full form or short form
30             // If it is in short form, expand it to its full form.
31             String uri = page.getDeleteCandidate();
32             boolean uriComplete = Convertion.isUriComplete(uri);
33             if (!uriComplete) {
34                 uri = Convertion.displayNameToUri(uri);
35             }
36             boolean exist = Activator.getManager().isResourceExist(uri);
37             if (!exist) {
38                 Shell activeShell = PlatformUI.getWorkbench().getDisplay()
39                         .getActiveShell();
40                 MessageDialog dialog = new MessageDialog(activeShell,
41                         "Resource Not Found", null,
42                         "No resource exist with the given URI.",
43                         MessageDialog.INFORMATION, new String[] { "OK" }, 0);
44                 dialog.open();
45                 page.setFocusToTextBox();
46                 return false;
47             }
48         }
49         return true;
50     }
51
52     public DeleteCategory getDeleteCategory() {
53         return page.getDeleteCategory();
54     }
55
56     public String getDeleteCandidate() {
57         return page.getDeleteCandidate();
58     }
59 }