package oic.simulator.serviceprovider.manager;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.widgets.Display;
+
+import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
import java.util.Vector;
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.MetaProperty;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.ResourceType;
-import oic.simulator.serviceprovider.model.SingleResource;
-import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.swt.widgets.Display;
import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeProperty.Type;
import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener;
import org.oic.simulator.server.SimulatorSingleResource;
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.AttributeElement;
+import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+
/**
* This class acts as an interface between the simulator java SDK and the
* various UI modules. It maintains all the details of resources and provides
return true;
}
+ public boolean changeResourceType(Resource resource, String newResourceType)
+ throws SimulatorException {
+ if (null == resource || null == newResourceType) {
+ return false;
+ }
+
+ if (!stopResource(resource)) {
+ return false;
+ }
+
+ String curResourceType = resource.getResourceType();
+ setResourceType(resource, newResourceType);
+
+ try {
+ if (!startResource(resource)) {
+ return false;
+ }
+ } catch (SimulatorException e) {
+ setResourceType(resource, curResourceType);
+ }
+
+ return true;
+ }
+
public void setResourceURI(Resource resource, String newURI)
throws SimulatorException {
String curURI = resource.getResourceURI();
}
}
+ public void setResourceType(Resource resource, String newResourceType)
+ throws SimulatorException {
+ SimulatorResource server = resource.getSimulatorResource();
+ try {
+ server.setResourceType(newResourceType);
+ resource.setResourceType(newResourceType);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while changing the resource Type.\n"
+ + Utility.getSimulatorErrorString(e, null));
+ throw e;
+ }
+ }
+
public boolean updateResourceProperties(Resource resource,
List<MetaProperty> properties, boolean uriChanged,
- boolean nameChanged) throws SimulatorException {
+ boolean nameChanged, boolean resTypeChanged)
+ throws SimulatorException {
if (null == resource || null == properties) {
return false;
}
String propValue;
String resName = null;
String resURI = null;
+ String resType = null;
while (itr.hasNext()) {
property = itr.next();
if (null == property) {
resName = propValue;
} else if (propName.equals(Constants.RESOURCE_URI)) {
resURI = propValue;
+ } else if (propName.equals(Constants.RESOURCE_TYPE)) {
+ resType = propValue;
}
}
}
}
+ if (resTypeChanged) {
+ if (!changeResourceType(resource, resType)) {
+ return false;
+ }
+ }
+
return true;
}
if (!Utility.isUriValid(value)) {
invalid = true;
}
+ } else if (propName.equals(Constants.RESOURCE_TYPE)) {
+ if (!Utility.isResourceTypeValid(value)) {
+ invalid = true;
+ }
} else {
if (null == value || value.trim().isEmpty()) {
invalid = true;
public List<String> getAllValues(DoubleProperty dblProperty,
AttributeProperty.Type type) {
+ NumberFormat formatter = NumberFormat.getInstance();
List<String> values = new ArrayList<String>();
if (dblProperty.hasRange()) {
double min = (double) dblProperty.min();
double max = (double) dblProperty.max();
- for (double iVal = min; iVal <= max; iVal = iVal + 1) {
- values.add(String.valueOf(iVal));
+ for (double val = min; val <= max; val += 0.1) {
+ formatter.setMaximumFractionDigits(1);
+ formatter.setMinimumFractionDigits(1);
+ values.add(formatter.format(val));
}
} else if (dblProperty.hasValues()) {
for (Double val : dblProperty.getValues()) {