package oic.simulator.serviceprovider.view.dialogs;
++import java.io.FileInputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Date;
*/
public class CreateResourceWizard extends Wizard {
- private MainPage mainPage;
- private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage;
- private SimpleResourceAddAttributePage simpleResourceAddAttributePage;
- private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage;
- private CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage;
- private AddResourcesToCollectionPage addResourcesToCollectionPage;
- private LoadRamlPage loadRamlPage;
- private UpdatePropertiesPage updatePropPage;
- private DevicePage devicePage;
- private StartStopResourcePage startStopPage;
+ private MainPage mainPage;
+ private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage;
+ private SimpleResourceAddAttributePage simpleResourceAddAttributePage;
+ private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage;
+ private LoadRamlPage loadRamlPage;
+ private UpdatePropertiesPage updatePropPage;
- private StartStopResourcePage startStopPage;
- // private SingleResource simResource;
- private String status;
+ private String status;
- private WizardDialog wizDialog;
- private boolean dlgForceClosed;
+ private WizardDialog wizDialog;
+ private boolean dlgForceClosed;
+
+ private Resource createdResource;
public CreateResourceWizard() {
setWindowTitle("Create resources");
simpleResourceBasicDetailsPage = new SimpleResourceBasicDetailsPage();
simpleResourceAddAttributePage = new SimpleResourceAddAttributePage();
simpleResourceOtherDetailsPage = new SimpleResourceOtherDetailsPage();
- collectionResourceBasicDetailsPage = new CollectionResourceBasicDetailsPage();
- addResourcesToCollectionPage = new AddResourcesToCollectionPage();
loadRamlPage = new LoadRamlPage();
updatePropPage = new UpdatePropertiesPage();
- devicePage = new DevicePage();
-- startStopPage = new StartStopResourcePage();
addPage(mainPage);
addPage(simpleResourceBasicDetailsPage);
addPage(simpleResourceAddAttributePage);
addPage(simpleResourceOtherDetailsPage);
- addPage(collectionResourceBasicDetailsPage);
- if (Activator.getDefault().getResourceManager().isAnyResourceExist())
- addPage(addResourcesToCollectionPage);
addPage(loadRamlPage);
addPage(updatePropPage);
- addPage(devicePage);
-- addPage(startStopPage);
}
public void setWizardDialog(WizardDialog dlg) {
return loadRamlPage.getResourceCount();
}
+ public Resource getCreatedResource() {
+ return createdResource;
+ }
+
@Override
public boolean canFinish() {
- System.out.println("canFinish()");
IWizardPage curPage = this.getContainer().getCurrentPage();
- System.out.println(curPage.getName());
- if ((curPage == updatePropPage && ((mainPage.getResourceOption() == ResourceOption.SIMPLE_FROM_RAML) || !Activator
+ if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
.getDefault().getResourceManager().isAnyResourceExist()))
- || (curPage == collectionResourceBasicDetailsPage
- && !Activator.getDefault().getResourceManager()
- .isAnyResourceExist() && collectionResourceBasicDetailsPage
- .isSelectionDone())
- || curPage == addResourcesToCollectionPage
|| curPage == simpleResourceAddAttributePage
|| (curPage == loadRamlPage && loadRamlPage.isSelectionDone() && loadRamlPage
- .isMultiResourceCreation())) {
- .isMultiResourceCreation()) || curPage == devicePage) {
++ .isMultiResourceCreation())) {
return true;
}
return false;
});
} catch (InvocationTargetException e) {
Activator.getDefault().getLogManager()
-- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
Activator.getDefault().getLogManager()
-- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
}
- } else if (curPage == loadRamlPage) { // Handling multi-instance
- // creation of simple resource
- // with RAML
+ } else if (curPage == loadRamlPage) {
++ // Validate the file path.
+ try {
- getContainer().run(true, true, new IRunnableWithProgress() {
++ new FileInputStream(loadRamlPage.getConfigFilePath());
++ } catch (Exception e) {
++ MessageDialog
++ .openError(getShell(), "Invalid File",
++ "File doesn't exist. Either the file path or file name is invalid.");
++ // TODO: Instead of MessageDialog, errors may be shown on wizard
++ // itself.
++ return false;
++ }
++
+ // Handling multiple instance creation of simple resource with RAML
+ if ((loadRamlPage.getResourceCount() + Activator.getDefault()
+ .getResourceManager().getResourceCount()) > Constants.MAX_RESOURCE_COUNT) {
+ MessageDialog
- .openInformation(Display.getDefault().getActiveShell(),
- "Resource limit exceeded",
- "Exceeded the limit of resources that can exist in the server.");
++ .openInformation(Display.getDefault().getActiveShell(),
++ "Resource limit exceeded",
++ "Exceeded the limit of resources that can exist in the server.");
+ return false;
+ }
+
+ try {
+ getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
});
} catch (InvocationTargetException e) {
Activator.getDefault().getLogManager()
-- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
Activator.getDefault().getLogManager()
-- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
}
- } else if (curPage == updatePropPage) { // Handling the single instance
- // creation of simple resource
- // with RAML
- // String resURI = updatePropPage.getResURI();
- // Checking whether the uri is used by any other resource.
+ } else if (curPage == updatePropPage) {
+ // Handling the single instance
+ String resName = updatePropPage.getResName();
+ String resURI = updatePropPage.getResURI();
+ if (null == resName || resName.trim().length() < 1) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource Name.", "Resource name is invalid");
+ return false;
+ }
+ if (!Utility.isUriValid(resURI)) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+ return false;
+ }
+ // Creation of simple resource with RAML
+ // Checking whether the URI is used by any other resource.
if (Activator.getDefault().getResourceManager()
.isResourceExist(updatePropPage.getResURI())) {
MessageDialog
-- .openError(getShell(), "Resource URI in use",
-- "Entered resource URI is in use. Please try a different one.");
++ .openError(getShell(), "Resource URI in use",
++ "Entered resource URI is in use. Please try a different one.");
// TODO: Instead of MessageDialog, errors may be shown on wizard
// itself.
return false;
});
} catch (InvocationTargetException e) {
Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- } catch (InterruptedException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- }
- } else if (curPage == collectionResourceBasicDetailsPage
- || curPage == addResourcesToCollectionPage) { // Handling
- // Collection
- // Resource
- // Creation
- // without RAML
- if (mainPage.getResourceOption() == ResourceOption.COLLECTION_FROM_RAML) {
- Resource res = loadRamlPage.getResource();
- if (null != res && res instanceof CollectionResource) {
- Set<Resource> selectedResources = addResourcesToCollectionPage
- .getSelectedResourceList();
- if (!selectedResources.isEmpty()) {
- int addedCount = Activator
- .getDefault()
- .getResourceManager()
- .addResourceToCollection(
- (CollectionResource) res,
- selectedResources);
- if (addedCount > 0) {
-
- status = "[" + addedCount + "/"
- + selectedResources.size()
- + "] resources added to the collection";
-
- UiListenerHandler.getInstance()
- .resourceListUpdateUINotification(
- ResourceType.COLLECTION);
- } else {
- status = "Failed to add resources to the collection";
- }
- }
- }
- } else {
- // Checking whether the uri is used by any other resource.
- if (Activator
- .getDefault()
- .getResourceManager()
- .isResourceExist(
- collectionResourceBasicDetailsPage.getResURI())) {
- MessageDialog
- .openError(getShell(), "Resource URI in use",
- "Entered resource URI is in use. Please try a different one.");
- // TODO: Instead of MessageDialog, errors may be shown on
- // wizard
- // itself.
- return false;
- }
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- monitor.beginTask(
- "Collection Resource Creation Without RAML",
- 3);
- monitor.worked(1);
- createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
- : false);
- monitor.worked(1);
- if (curPage == addResourcesToCollectionPage) {
- UiListenerHandler.getInstance()
- .resourceListUpdateUINotification(
- ResourceType.COLLECTION);
- }
- monitor.worked(1);
- } finally {
- monitor.done();
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- e.getMessage());
- e.printStackTrace();
- } catch (InterruptedException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- e.getMessage());
- e.printStackTrace();
- }
- }
- } else if (curPage == devicePage) {
- final String devName = devicePage.getDeviceName();
- final Set<Resource> resourceList = devicePage
- .getSelectedResourceList();
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- monitor.beginTask("Device Creation", 3);
- monitor.worked(1);
- createDevice(devName, resourceList);
- monitor.worked(1);
- UiListenerHandler.getInstance()
- .resourceListUpdateUINotification(
- ResourceType.DEVICE);
- status = "Device Created.";
- monitor.worked(1);
- } finally {
- monitor.done();
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator.getDefault().getLogManager()
-- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
Activator.getDefault().getLogManager()
-- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
}
}
return updatePropPage;
}
- public DevicePage getDevicePage() {
- return devicePage;
- }
-
-- public StartStopResourcePage getStartStopPage() {
-- return startStopPage;
-- }
-
- /*
- * public SingleResource getSimResource() { return simResource; }
- *
- * public void setSimResource(SingleResource simResource) { this.simResource
- * = simResource; }
- */
--
public void setStatus(String status) {
this.status = status;
}
+++ /dev/null
- /*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
--package oic.simulator.serviceprovider.view.dialogs;
--
--import oic.simulator.serviceprovider.utils.Constants;
--
--import org.eclipse.jface.wizard.IWizardPage;
--import org.eclipse.jface.wizard.WizardPage;
--import org.eclipse.swt.SWT;
--import org.eclipse.swt.events.SelectionAdapter;
--import org.eclipse.swt.events.SelectionEvent;
--import org.eclipse.swt.layout.GridData;
--import org.eclipse.swt.layout.GridLayout;
--import org.eclipse.swt.widgets.Button;
--import org.eclipse.swt.widgets.Composite;
--import org.eclipse.swt.widgets.Label;
--import org.eclipse.swt.widgets.Text;
--
--public class StartStopResourcePage extends WizardPage {
--
-- private Button startButton;
--
-- private boolean start;
--
-- protected StartStopResourcePage() {
-- super("Start/Stop Resource");
-- setStart(true);
-- }
--
-- @Override
-- public void createControl(Composite parent) {
-- setPageComplete(false);
-- setTitle(Constants.START_STOP_PAGE_TITLE);
-- setMessage(Constants.START_STOP_PAGE_MESSAGE);
-- Composite compContent = new Composite(parent, SWT.NONE);
-- GridLayout gridLayout = new GridLayout();
-- compContent.setLayout(gridLayout);
-- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-- compContent.setLayoutData(gd);
--
-- startButton = new Button(compContent, SWT.CHECK);
-- startButton.setText("Start Resource(s)");
-- startButton.setSelection(true);
-- gd = new GridData();
-- gd.verticalIndent = 10;
-- startButton.setLayoutData(gd);
--
-- Label descLbl = new Label(compContent, SWT.NONE);
-- descLbl.setText("Description:");
-- gd = new GridData();
-- gd.verticalIndent = 50;
-- descLbl.setLayoutData(gd);
--
-- final Text text = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
-- | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
-- text.setText("Starting the resource will register it with the platform and makes it visible on the network.\n"
-- + "Resources can be started or stopped later from 'Resource Manager' view.");
-- gd = new GridData();
-- gd.horizontalAlignment = SWT.FILL;
-- gd.grabExcessHorizontalSpace = true;
-- gd.heightHint = 100;
-- gd.verticalAlignment = SWT.BOTTOM;
-- text.setLayoutData(gd);
--
-- addUIListeners();
--
-- setControl(compContent);
-- }
--
-- private void addUIListeners() {
-- startButton.addSelectionListener(new SelectionAdapter() {
-- @Override
-- public void widgetSelected(SelectionEvent e) {
-- setStart(startButton.getSelection());
-- }
-- });
-- }
--
-- public boolean isStart() {
-- return start;
-- }
--
-- public void setStart(boolean start) {
-- this.start = start;
-- }
--
-- @Override
-- public IWizardPage getNextPage() {
- System.out.println(this.getClass().getName() + ": getNextPage");
-- return null;
-- }
--}