Resource resource = new SingleResource();
resource.setSimulatorResource(jSimulatorResource);
- // Fetch and locally store the resource name and uri.
+ // Fetch and locally store the resource name, type and uri.
String uri = jSimulatorResource.getURI();
if (null == uri || uri.trim().isEmpty()) {
+ // URI is mandatory to be present in RAML. If it is not there, then
+ // resource can't be created.
return null;
}
resource.setResourceURI(uri.trim());
- String name = jSimulatorResource.getName();
- if (null == name || name.trim().isEmpty()) {
- return null;
+ String type = jSimulatorResource.getResourceType();
+ if (null != type) {
+ type = type.trim();
}
+ resource.setResourceType(type);
- resource.setResourceName(name.trim());
+ String name = jSimulatorResource.getName();
+ if (null != name) {
+ name = name.trim();
+ }
+ resource.setResourceName(name);
return resource;
}
* notifies the UI listeners.
*/
public boolean completeSingleResourceCreationByRAML(Resource resource,
- String uri, String name, boolean multiInstance)
+ String uri, String name, String type, boolean multiInstance)
throws SimulatorException {
if (null == resource || !(resource instanceof SingleResource)) {
return false;
}
// Update resource URI and Name if they are changed.
- String newUri = uri.trim();
- String newName = name.trim();
-
- if (multiInstance) {
+ String newUri = "";
+ String newName = "";
+ String newType = "";
+
+ if (null != uri)
+ newUri = uri.trim();
+ if (null != name)
+ newName = name.trim();
+ if (null != type)
+ newType = type.trim();
+
+ if (!multiInstance && !singleRes.getResourceURI().equals(newUri)) {
+ jSimulatorSingleResource.setURI(newUri);
singleRes.setResourceURI(newUri);
+ }
+ String currentName = singleRes.getResourceName();
+ if (null == currentName || !currentName.equals(newName)) {
+ jSimulatorSingleResource.setName(newName);
singleRes.setResourceName(newName);
- } else {
- if (!singleRes.getResourceURI().equals(newUri)) {
- jSimulatorSingleResource.setURI(newUri);
- singleRes.setResourceURI(newUri);
- }
- if (!singleRes.getResourceName().equals(newName)) {
- jSimulatorSingleResource.setName(newName);
- singleRes.setResourceName(newName);
- }
+ }
+ String currentType = singleRes.getResourceType();
+ if (null == currentType || !currentType.equals(newType)) {
+ jSimulatorSingleResource.setResourceType(newType);
+ singleRes.setResourceType(newType);
}
// Set the model change listener.
singleRes.setResourceModel(jResModel);
// Fetch the basic details of the resource.
- singleRes.setResourceType(jSimulatorSingleResource
- .getResourceType());
singleRes
.setResourceInterfaces(Utility
.convertVectorToSet(jSimulatorSingleResource
}
SimulatorSingleResource jResource;
SingleResource resource;
- boolean result;
for (SimulatorResource jSimulatorResource : jSimulatorResources) {
// If the resource creation progress is canceled, then stop the
// creation and stop/delete
resource = new SingleResource();
resource.setSimulatorResource(jResource);
try {
- result = completeSingleResourceCreationByRAML(resource,
- jResource.getURI(), jResource.getName(), true);
- if (result) {
- resultSet.add(resource);
+ String uri = jSimulatorResource.getURI();
+ if (null == uri || uri.trim().isEmpty()) {
+ // URI is mandatory to be present in RAML. If it is not
+ // there, then resource will be ignored.
+ continue;
+ }
+ resource.setResourceURI(uri.trim());
+
+ String type = jSimulatorResource.getResourceType();
+ if (null != type) {
+ type = type.trim();
}
+ resource.setResourceType(type);
+
+ String name = jSimulatorResource.getName();
+ if (null != name) {
+ name = name.trim();
+ }
+ resource.setResourceName(name);
+
+ resultSet.add(resource);
} catch (SimulatorException eInner) {
Activator
.getDefault()
.getDefault()
.getLogManager()
.log(Level.ERROR.ordinal(), new Date(),
- "There is an error while creating the wizard.\n");
+ "There is an error while reading information from the UI wizard.\n");
return;
}
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
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 LoadRamlPage loadRamlPage;
- private UpdatePropertiesPage updatePropPage;
+ private MainPage mainPage;
+ private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage;
+ private SimpleResourceAddAttributePage simpleResourceAddAttributePage;
+ private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage;
+ private LoadRamlPage loadRamlPage;
+ private UpdatePropertiesPage updatePropPage;
+ private UpdateMultiInstanceCreationPropertiesPage updateMultiInstanceCreationPropPage;
- private String status;
+ private String status;
- private WizardDialog wizDialog;
- private boolean dlgForceClosed;
+ private WizardDialog wizDialog;
+ private boolean dlgForceClosed;
- private Resource createdResource;
-
- private IProgressMonitor progressMonitor;
+ private Resource createdResource;
+ private Set<SingleResource> multiInstanceResourceSet;
public CreateResourceWizard() {
setWindowTitle("Create resources");
simpleResourceOtherDetailsPage = new SimpleResourceOtherDetailsPage();
loadRamlPage = new LoadRamlPage();
updatePropPage = new UpdatePropertiesPage();
+ updateMultiInstanceCreationPropPage = new UpdateMultiInstanceCreationPropertiesPage();
addPage(mainPage);
addPage(simpleResourceBasicDetailsPage);
addPage(simpleResourceOtherDetailsPage);
addPage(loadRamlPage);
addPage(updatePropPage);
+ addPage(updateMultiInstanceCreationPropPage);
}
public void setWizardDialog(WizardDialog dlg) {
return createdResource;
}
+ public Set<SingleResource> getCreatedMultiInstanceResourceSet() {
+ return multiInstanceResourceSet;
+ }
+
@Override
public boolean canFinish() {
IWizardPage curPage = this.getContainer().getCurrentPage();
- if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
- .getDefault().getResourceManager().isAnyResourceExist()))
- || curPage == simpleResourceAddAttributePage
- || (curPage == loadRamlPage && loadRamlPage.isSelectionDone() && loadRamlPage
- .isMultiResourceCreation())) {
+ if ((curPage == updateMultiInstanceCreationPropPage || curPage == updatePropPage
+ && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
+ .getDefault().getResourceManager().isAnyResourceExist()))
+ || curPage == simpleResourceAddAttributePage) {
return true;
}
return false;
.log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
}
- } else if (curPage == loadRamlPage) {
- // Validate the file path.
- FileInputStream fileStream = null;
- try {
- fileStream = new FileInputStream(
- loadRamlPage.getConfigFilePath());
- } catch (FileNotFoundException e) {
- MessageDialog
- .openError(getShell(), "Invalid File",
- "File doesn't exist. Either the file path or file name is invalid.");
- return false;
- } finally {
- if (null != fileStream) {
- try {
- fileStream.close();
- } catch (IOException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- "There is an error while closing the file stream.\n");
- }
- }
- }
-
- // 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",
- Constants.RESOURCE_LIMIT_EXCEEDED_MSG);
- return false;
- }
-
- final int[] resCreatedCount = new int[1];
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(final IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- progressMonitor = monitor;
- try {
- monitor.beginTask(
- "Single Resource Creation(multi-instance) With RAML",
- loadRamlPage.getResourceCount());
- resCreatedCount[0] = createMultiInstanceSingleResourceWithoutRAML();
-
- } 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();
- }
- boolean canceled = false;
- if (null != progressMonitor && progressMonitor.isCanceled()
- && 0 == resCreatedCount[0]) {
- canceled = true;
- }
- progressMonitor = null;
- if (canceled) {
- return false;
+ } else if (curPage == updatePropPage
+ || curPage == updateMultiInstanceCreationPropPage) {
+ multiInstanceResourceSet = loadRamlPage
+ .getMultiInstanceResourceSet();
+ createdResource = loadRamlPage.getResource();
+
+ String resName;
+ String resURI;
+ String resType;
+ boolean multiInstanceCreation = loadRamlPage
+ .isMultiResourceCreation();
+
+ if (curPage == updatePropPage) {
+ resName = updatePropPage.getResName();
+ resURI = updatePropPage.getResURI();
+ resType = updatePropPage.getResType();
} else {
- if (resCreatedCount[0] > 0) {
- UiListenerHandler.getInstance()
- .resourceCreatedUINotification(ResourceType.SINGLE);
- }
+ resName = updateMultiInstanceCreationPropPage.getResName();
+ resURI = "";
+ resType = updateMultiInstanceCreationPropPage.getResType();
}
- } 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)) {
+
+ if (!multiInstanceCreation && !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())) {
+ if (!multiInstanceCreation
+ && Activator.getDefault().getResourceManager()
+ .isResourceExist(resURI)) {
MessageDialog
.openError(getShell(), "Resource URI in use",
"Entered resource URI is in use. Please try a different one.");
return false;
}
+ if (!Utility.isResourceTypeValid(resType)) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource Type.",
+ Constants.INVALID_RESOURCE_TYPE_MESSAGE);
+ return false;
+ }
+
try {
getContainer().run(true, false, new IRunnableWithProgress() {
try {
monitor.beginTask("Completing Resource Creation", 2);
monitor.worked(1);
- completeResourceCreationWithRAML();
+ if (loadRamlPage.isMultiResourceCreation()) {
+ completeMultiInstanceResourceCreationWithRAML();
+ } else {
+ completeSingleInstanceResourceCreationWithRAML();
+ }
monitor.worked(1);
} finally {
monitor.done();
return updatePropPage;
}
+ public UpdateMultiInstanceCreationPropertiesPage getUpdateMultiInstanceCreationPropPage() {
+ return updateMultiInstanceCreationPropPage;
+ }
+
+ public void setUpdateMultiInstanceCreationPropPage(
+ UpdateMultiInstanceCreationPropertiesPage updateMultiInstanceCreationPropPage) {
+ this.updateMultiInstanceCreationPropPage = updateMultiInstanceCreationPropPage;
+ }
+
public void setStatus(String status) {
this.status = status;
}
}
}
- private void completeResourceCreationWithRAML() {
+ private void completeSingleInstanceResourceCreationWithRAML() {
+ String resName = updatePropPage.getResName();
+ String resURI = updatePropPage.getResURI();
+ String resType = updatePropPage.getResType();
+
try {
boolean result = false;
- Resource res = loadRamlPage.getResource();
- if (res instanceof SingleResource) {
+ if (createdResource instanceof SingleResource) {
result = Activator
.getDefault()
.getResourceManager()
- .completeSingleResourceCreationByRAML(res,
- updatePropPage.getResURI(),
- updatePropPage.getResName(), false);
+ .completeSingleResourceCreationByRAML(createdResource,
+ resURI, resName, resType, false);
}
if (result) {
status = "Resource created.";
- createdResource = res;
} else {
status = "Failed to create resource.";
createdResource = null;
}
}
- private int createMultiInstanceSingleResourceWithoutRAML() {
- int toCreateCount = loadRamlPage.getResourceCount();
- int resCreatedCount = 0;
- Set<SingleResource> resources;
- try {
- resources = Activator
- .getDefault()
- .getResourceManager()
- .createSingleResourceMultiInstances(
- loadRamlPage.getConfigFilePath(), toCreateCount,
- progressMonitor);
- if (null != progressMonitor && progressMonitor.isCanceled()) {
- try {
- Activator.getDefault().getResourceManager()
- .removeSingleResources(resources);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "There is an error while updating the resource model.\n"
- + Utility.getSimulatorErrorString(
- e, null));
+ private void completeMultiInstanceResourceCreationWithRAML() {
+ String resName = updateMultiInstanceCreationPropPage.getResName();
+ String resType = updateMultiInstanceCreationPropPage.getResType();
+
+ if (null == multiInstanceResourceSet)
+ return;
+
+ boolean result = false;
+ int count = loadRamlPage.getResourceCount();
+ int successCount = 0;
+ SingleResource resource;
+ Iterator<SingleResource> itr = multiInstanceResourceSet.iterator();
+ while (itr.hasNext()) {
+ resource = itr.next();
+ try {
+ result = Activator
+ .getDefault()
+ .getResourceManager()
+ .completeSingleResourceCreationByRAML(resource, null,
+ resName, resType, true);
+ if (result) {
+ successCount++;
}
- return 0;
- }
- if (null != resources)
- resCreatedCount = resources.size();
- if (resCreatedCount > 0) {
- status = "[" + resCreatedCount + " out of " + toCreateCount
- + "]";
- status += ((resCreatedCount == 1) ? "resource" : "resources")
- + " created successfully.";
- } else {
- status = "Failed to create resources.";
+
+ } catch (SimulatorException e) {
+ // Do Nothing.
}
- } catch (SimulatorException e) {
- status = "Failed to create resource.\n"
- + Utility.getSimulatorErrorString(e, null);
}
- return resCreatedCount;
+ if (successCount > 0) {
+ UiListenerHandler.getInstance().resourceCreatedUINotification(
+ ResourceType.SINGLE);
+
+ status = "[" + successCount + " out of " + count + "]";
+ status += ((successCount == 1) ? "resource" : "resources")
+ + " created successfully.";
+ } else {
+ status = "Failed to create resources.";
+ }
}
}
\ No newline at end of file
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
+import java.util.Set;
import org.oic.simulator.ILogger.Level;
import org.oic.simulator.SimulatorException;
private int resourceCount;
private Resource resource;
+ private Set<SingleResource> multiInstanceResourceSet;
private SimulatorResource.Type typeOfResource;
+ private IProgressMonitor progressMonitor;
+
protected LoadRamlPage() {
super("Create Resource");
resourceCount = -1;
resourceCount = -1;
}
if (null != configFilePath && configFilePath.trim().length() > 0) {
- if (resourceCount == 1) {
+ if (resourceCount >= 1) {
done = true;
}
}
return null;
}
+ IWizardPage nextPage;
+ String resName;
+ String resURI;
+ String resType;
final CreateResourceWizard wizard = ((CreateResourceWizard) getWizard());
+ if (isMultiResourceCreation()) {
+ final int[] resCreatedCount = new int[1];
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+
+ @Override
+ public void run(final IProgressMonitor monitor)
+ throws InvocationTargetException,
+ InterruptedException {
+ progressMonitor = monitor;
+ try {
+ monitor.beginTask(
+ "Single Resource Creation(multi-instance) With RAML",
+ wizard.getLoadRamlPage().getResourceCount());
+ resCreatedCount[0] = createMultiInstanceSingleResourceWithRAML();
+
+ } 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();
+ }
- try {
- getContainer().run(true, false, new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- try {
- monitor.beginTask("Resource Creation With RAML", 2);
- monitor.worked(1);
- resource = Activator.getDefault().getResourceManager()
- .createResourceByRAML(configFilePath);
- monitor.worked(1);
- } catch (SimulatorException e) {
- wizard.setStatus("Failed to create resource.\n"
- + Utility.getSimulatorErrorString(e, null));
- } finally {
- monitor.done();
+ if (0 == resCreatedCount[0]) {
+ wizard.setStatus("Failed to create Resources.");
+ wizard.getWizardDialog().close();
+ return null;
+ }
+
+ boolean canceled = false;
+ if (null != progressMonitor && progressMonitor.isCanceled()) {
+ canceled = true;
+ }
+ progressMonitor = null;
+ if (canceled) {
+ return null;
+ }
+
+ // It is guaranteed that will be at least one resource at this
+ // point.
+ SingleResource resourceInstance = (SingleResource) multiInstanceResourceSet
+ .toArray()[0];
+ resName = resourceInstance.getResourceName();
+ resType = resourceInstance.getResourceType();
+ resURI = resourceInstance.getResourceURI();
+ UpdateMultiInstanceCreationPropertiesPage updatePageRef = wizard
+ .getUpdateMultiInstanceCreationPropPage();
+ updatePageRef.setResName(resName);
+ updatePageRef.setResType(resType);
+ nextPage = updatePageRef;
+ } else {
+ try {
+ getContainer().run(true, false, new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException,
+ InterruptedException {
+ try {
+ monitor.beginTask("Resource Creation With RAML", 2);
+ monitor.worked(1);
+ resource = Activator.getDefault()
+ .getResourceManager()
+ .createResourceByRAML(configFilePath);
+ monitor.worked(1);
+ } catch (SimulatorException e) {
+ wizard.setStatus("Failed to create resource.\n"
+ + Utility.getSimulatorErrorString(e, null));
+ } 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();
+ }
+ if (null == resource) {
+ wizard.setStatus("Failed to create Resource.");
+ wizard.getWizardDialog().close();
+ return null;
+ } else {
+ // Checking whether the resource is of type single.
+ Option intendedResource = wizard.getMainPage().getOption();
+ if ((intendedResource == Option.SIMPLE_FROM_RAML && !(resource instanceof SingleResource))) {
+ MessageDialog
+ .openError(
+ getShell(),
+ "Invalid RAML",
+ "Uploaded RAML is not of simple type. "
+ + "Please upload the proper RAML of simple type.");
+ return null;
}
- });
- } 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();
+ }
+ resName = resource.getResourceName();
+ resURI = resource.getResourceURI();
+ resType = resource.getResourceType();
+ UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
+ updatePageRef.setResName(resName);
+ updatePageRef.setResURI(resURI);
+ updatePageRef.setResType(resType);
+ nextPage = updatePageRef;
}
- if (null == resource) {
- wizard.setStatus("Failed to create Resource.");
- wizard.getWizardDialog().close();
- return null;
- } else {
- // Checking whether the resource is of type single.
- Option intendedResource = wizard.getMainPage().getOption();
- if ((intendedResource == Option.SIMPLE_FROM_RAML && !(resource instanceof SingleResource))) {
- MessageDialog
- .openError(
- getShell(),
- "Invalid RAML",
- "Uploaded RAML is not of simple type. "
- + "Please upload the proper RAML of simple type.");
- return null;
+ return nextPage;
+ }
+
+ public int createMultiInstanceSingleResourceWithRAML() {
+ int resCreatedCount = 0;
+ try {
+ multiInstanceResourceSet = Activator
+ .getDefault()
+ .getResourceManager()
+ .createSingleResourceMultiInstances(configFilePath,
+ resourceCount, progressMonitor);
+ if (null != progressMonitor && progressMonitor.isCanceled()) {
+ try {
+ Activator.getDefault().getResourceManager()
+ .removeSingleResources(multiInstanceResourceSet);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while handling the cancellation request.\n"
+ + Utility.getSimulatorErrorString(
+ e, null));
+ }
+ return 0;
}
+ if (null != multiInstanceResourceSet)
+ resCreatedCount = multiInstanceResourceSet.size();
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "Failed to create resource(s).\n"
+ + Utility.getSimulatorErrorString(e, null));
}
- UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
- updatePageRef.setResName(resource.getResourceName());
- updatePageRef.setResURI(resource.getResourceURI());
- return updatePageRef;
+ return resCreatedCount;
}
public String getConfigFilePath() {
public void setResource(Resource resource) {
this.resource = resource;
}
+
+ public Set<SingleResource> getMultiInstanceResourceSet() {
+ return multiInstanceResourceSet;
+ }
+
+ public void setMultiInstanceResourceSet(Set<SingleResource> resource) {
+ multiInstanceResourceSet = resource;
+ }
}
\ No newline at end of file
LoadRamlPage loadRamlPage = createWizard.getLoadRamlPage();
UpdatePropertiesPage updatePropPage = createWizard
.getUpdatePropPage();
+ UpdateMultiInstanceCreationPropertiesPage updateMultiInstanceCreationPropPage = createWizard
+ .getUpdateMultiInstanceCreationPropPage();
IWizardPage curPage = wizard.getContainer().getCurrentPage();
IWizardPage prevPage = null;
if (curPage == loadRamlPage
|| curPage == simpleResourceBasicDetailsPage) {
prevPage = mainPage;
- } else if (curPage == updatePropPage) {
+ } else if (curPage == updatePropPage
+ || curPage == updateMultiInstanceCreationPropPage) {
loadRamlPage.setResource(null);
+ loadRamlPage.setMultiInstanceResourceSet(null);
prevPage = loadRamlPage;
} else if (curPage == simpleResourceAddAttributesPage) {
prevPage = simpleResourceBasicDetailsPage;
--- /dev/null
+/*
+ * Copyright 2016 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 org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+public class UpdateMultiInstanceCreationPropertiesPage extends WizardPage {
+
+ private Text resNameTxt;
+ private Text resTypeTxt;
+
+ private String resName;
+ private String resType;
+
+ protected UpdateMultiInstanceCreationPropertiesPage() {
+ super("Update Properties");
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ setPageComplete(true);
+ setTitle(Constants.UPDATE_PROP_PAGE_TITLE);
+ setMessage(Constants.UPDATE_PROP_PAGE_MESSAGE);
+
+ Composite comp = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ comp.setLayout(gridLayout);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ comp.setLayoutData(gd);
+
+ Group grp = new Group(comp, SWT.NONE);
+ gridLayout = new GridLayout(2, false);
+ grp.setLayout(gridLayout);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ grp.setLayoutData(gd);
+
+ Label resNameLbl = new Label(grp, SWT.NULL);
+ resNameLbl.setText("Resource Name");
+ gd = new GridData();
+ gd.verticalIndent = 20;
+ resNameLbl.setLayoutData(gd);
+
+ resNameTxt = new Text(grp, SWT.BORDER);
+ resNameTxt.setFocus();
+ gd = new GridData();
+ gd.widthHint = 300;
+ gd.verticalIndent = 20;
+ resNameTxt.setLayoutData(gd);
+
+ Label resTypeLbl = new Label(grp, SWT.NULL);
+ resTypeLbl.setText("Resource Type");
+ gd = new GridData();
+ gd.verticalIndent = 10;
+ resTypeLbl.setLayoutData(gd);
+
+ resTypeTxt = new Text(grp, SWT.BORDER);
+ gd = new GridData();
+ gd.widthHint = 300;
+ gd.verticalIndent = 10;
+ resTypeTxt.setLayoutData(gd);
+
+ Label descLbl = new Label(comp, SWT.NONE);
+ descLbl.setText("Description:");
+ gd = new GridData();
+ descLbl.setLayoutData(gd);
+
+ final Text text = new Text(comp, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER
+ | SWT.WRAP | SWT.V_SCROLL);
+ text.setText("All resource instances will be configured with the same resource name and type.\n"
+ + "These properties can be changed later from properties view.");
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ text.setLayoutData(gd);
+
+ addUIListeners();
+
+ // Initialize data
+ if (resNameTxt.getText().length() < 1 && null != resName) {
+ resNameTxt.setText(resName);
+ }
+ if (resTypeTxt.getText().length() < 1 && null != resType) {
+ resTypeTxt.setText(resType);
+ }
+
+ setControl(comp);
+ }
+
+ private void addUIListeners() {
+ resNameTxt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ resName = resNameTxt.getText();
+ setPageComplete(isSelectionDone());
+ }
+ });
+
+ resTypeTxt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ resType = resTypeTxt.getText();
+ if (null == resType) {
+ return;
+ }
+
+ setPageComplete(isSelectionDone());
+ }
+ });
+ }
+
+ @Override
+ public boolean canFlipToNextPage() {
+ return false;
+ }
+
+ public boolean isSelectionDone() {
+ boolean done = false;
+ if (null != resName && resName.trim().length() > 0 && null != resType
+ && resType.trim().length() > 0) {
+ done = true;
+ }
+ return done;
+ }
+
+ @Override
+ public IWizardPage getNextPage() {
+ return null;
+ }
+
+ public void setResName(String resName) {
+ if (null == resName) {
+ resName = "";
+ }
+
+ this.resName = resName;
+ if (null != resName && !resNameTxt.isDisposed())
+ resNameTxt.setText(resName);
+ }
+
+ public void setResType(String resType) {
+ if (null == resType) {
+ resType = "";
+ }
+
+ this.resType = resType;
+ if (null != resType && !resTypeTxt.isDisposed())
+ resTypeTxt.setText(resType);
+ }
+
+ public String getResName() {
+ return resName;
+ }
+
+ public String getResType() {
+ return resType;
+ }
+}
private Text resNameTxt;
private Text resUriTxt;
+ private Text resTypeTxt;
private String resName;
private String resURI;
+ private String resType;
protected UpdatePropertiesPage() {
super("Update Properties");
gd.verticalIndent = 10;
resUriTxt.setLayoutData(gd);
+ Label resTypeLbl = new Label(grp, SWT.NULL);
+ resTypeLbl.setText("Resource Type");
+ gd = new GridData();
+ gd.verticalIndent = 10;
+ resTypeLbl.setLayoutData(gd);
+
+ resTypeTxt = new Text(grp, SWT.BORDER);
+ gd = new GridData();
+ gd.widthHint = 300;
+ gd.verticalIndent = 10;
+ resTypeTxt.setLayoutData(gd);
+
Label descLbl = new Label(comp, SWT.NONE);
descLbl.setText("Description:");
gd = new GridData();
if (resNameTxt.getText().length() < 1 && null != resName) {
resNameTxt.setText(resName);
}
+ if (resTypeTxt.getText().length() < 1 && null != resType) {
+ resTypeTxt.setText(resType);
+ }
setControl(comp);
}
setPageComplete(isSelectionDone());
}
});
+
+ resTypeTxt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ resType = resTypeTxt.getText();
+ if (null == resType) {
+ return;
+ }
+
+ setPageComplete(isSelectionDone());
+ }
+ });
}
@Override
public boolean isSelectionDone() {
boolean done = false;
if (null != resName && resName.trim().length() > 0 && null != resURI
- && resURI.trim().length() > 0) {
+ && resURI.trim().length() > 0 && null != resType
+ && resType.trim().length() > 0) {
done = true;
}
return done;
}
public void setResName(String resName) {
+ if (null == resName) {
+ resName = "";
+ }
+
this.resName = resName;
- if (!resNameTxt.isDisposed())
+ if (null != resName && !resNameTxt.isDisposed())
resNameTxt.setText(resName);
}
public void setResURI(String resURI) {
+ if (null == resURI) {
+ resURI = "";
+ }
+
this.resURI = resURI;
- if (!resUriTxt.isDisposed())
+ if (null != resUriTxt && !resUriTxt.isDisposed())
resUriTxt.setText(resURI);
}
+ public void setResType(String resType) {
+ if (null == resType) {
+ resType = "";
+ }
+
+ this.resType = resType;
+ if (null != resType && !resTypeTxt.isDisposed())
+ resTypeTxt.setText(resType);
+ }
+
public String getResName() {
return resName;
}
public String getResURI() {
return resURI;
}
+
+ public String getResType() {
+ return resType;
+ }
}
resourceModel.remove("resourceType");\r
}\r
\r
- // Construct resource type from uri\r
- if(resourceType.empty())\r
- {\r
- std::ostringstream rtString;\r
- rtString << "oic.r.";\r
-\r
- size_t pos = resourceURI.rfind("/");\r
- if (pos == std::string::npos)\r
- pos = -1;\r
-\r
- std::string rtName = resourceURI.substr(pos+1);\r
- std::transform(rtName.begin(), rtName.end(), rtName.begin(), ::tolower);\r
- rtString << rtName;\r
- resourceType = rtString.str();\r
- }\r
-\r
// Extracting interface type.\r
std::vector<std::string> interfaceTypes;\r
if (resourceModel.contains("if"))\r
new SimulatorCollectionResourceImpl());\r
\r
collectionRes->setName(resourceName);\r
- collectionRes->setResourceType(resourceType);\r
+ if(!resourceType.empty())\r
+ collectionRes->setResourceType(resourceType);\r
if (interfaceTypes.size() > 0)\r
collectionRes->setInterface(interfaceTypes);\r
collectionRes->setURI(ResourceURIFactory::getInstance()->makeUniqueURI(resourceURI));\r
new SimulatorSingleResourceImpl());\r
\r
singleRes->setName(resourceName);\r
- singleRes->setResourceType(resourceType);\r
+ if(!resourceType.empty())\r
+ singleRes->setResourceType(resourceType);\r
if (interfaceTypes.size() > 0)\r
singleRes->setInterface(interfaceTypes);\r
singleRes->setURI(ResourceURIFactory::getInstance()->makeUniqueURI(resourceURI));\r