Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / ResourceWizardDialog.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 org.eclipse.jface.wizard.IWizard;
20 import org.eclipse.jface.wizard.IWizardPage;
21 import org.eclipse.jface.wizard.WizardDialog;
22 import org.eclipse.swt.widgets.Shell;
23
24 /**
25  * Dialog for handling wizards.
26  */
27 public class ResourceWizardDialog extends WizardDialog {
28
29     private IWizard wizard;
30
31     public ResourceWizardDialog(Shell parentShell, IWizard newWizard) {
32         super(parentShell, newWizard);
33         wizard = newWizard;
34     }
35
36     @Override
37     public boolean isHelpAvailable() {
38         return false;
39     }
40
41     @Override
42     public void finishPressed() {
43         super.finishPressed();
44     }
45
46     @Override
47     protected void backPressed() {
48         if (wizard.getClass() == CreateResourceWizard.class) {
49             CreateResourceWizard createWizard = (CreateResourceWizard) wizard;
50
51             MainPage mainPage = createWizard.getMainPage();
52             SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage = createWizard
53                     .getSimpleResourceBasicDetailsPage();
54             SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage = createWizard
55                     .getSimpleResourceOtherDetailsPage();
56             SimpleResourceAddAttributePage simpleResourceAddAttributesPage = createWizard
57                     .getSimpleResourceAddAttributePage();
58             LoadRamlPage loadRamlPage = createWizard.getLoadRamlPage();
59             UpdatePropertiesPage updatePropPage = createWizard
60                     .getUpdatePropPage();
61
62             IWizardPage curPage = wizard.getContainer().getCurrentPage();
63             IWizardPage prevPage = null;
64
65             if (curPage == loadRamlPage
66                     || curPage == simpleResourceBasicDetailsPage) {
67                 prevPage = mainPage;
68             } else if (curPage == updatePropPage) {
69                 loadRamlPage.setResource(null);
70                 prevPage = loadRamlPage;
71             } else if (curPage == simpleResourceAddAttributesPage) {
72                 prevPage = simpleResourceBasicDetailsPage;
73             } else if (curPage == simpleResourceOtherDetailsPage) {
74                 prevPage = simpleResourceAddAttributesPage;
75             }
76             if (null != prevPage)
77                 showPage(prevPage);
78         }
79     }
80 }