*******************************************************************************/\r
package org.simantics.db.layer0.adapter.impl;\r
\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.Collections;\r
import org.simantics.db.layer0.adapter.Instances;\r
import org.simantics.db.layer0.genericrelation.IndexQueries;\r
import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.db.request.ReadExt;\r
+import org.simantics.db.request.RequestFlags;\r
import org.simantics.db.service.CollectionSupport;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.operation.Layer0X;\r
import org.simantics.scl.runtime.function.Function;\r
\r
+import gnu.trove.set.hash.THashSet;\r
+\r
/**\r
* @author Antti Villberg\r
* @author Tuukka Lehtonen\r
* A (cacheable) query to optimize single index queries for immutable\r
* indexes such as ontologies.\r
*/\r
- public static class QueryIndex extends TernaryRead<Resource, Resource, String, List<Resource>> {\r
+ public static class QueryIndex extends TernaryRead<Resource, Resource, String, List<Resource>> implements ReadExt {\r
\r
public QueryIndex(Resource index, Resource type, String filter) {\r
super(index, type, filter);\r
return "QueryIndex " + parameter + " " + parameter2 + " " + parameter3;\r
}\r
\r
+ @Override\r
+ public boolean isImmutable(ReadGraph graph) throws DatabaseException {\r
+ // TODO Auto-generated method stub\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public int getType() {\r
+ return RequestFlags.IMMEDIATE_UPDATE;\r
+ }\r
+\r
}\r
\r
private List<Resource> findRec(ReadGraph graph, Resource index, String filter, Set<Resource> visited) throws DatabaseException {\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.ResourceRead;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
\r
-public class OntologiesFromLibrary implements Read<List<Resource>> {\r
- \r
- Resource library;\r
+public class OntologiesFromLibrary extends ResourceRead<List<Resource>> {\r
\r
public OntologiesFromLibrary(Resource library) {\r
- this.library = library;\r
+ super(library);\r
}\r
\r
@Override\r
public List<Resource> perform(ReadGraph graph) throws DatabaseException {\r
Layer0 L0 = Layer0.getInstance(graph);\r
ArrayList<Resource> result = new ArrayList<Resource>();\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(library, L0.ConsistsOf, L0.Library))) {\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, L0.Library))) {\r
if(graph.isInstanceOf(r, L0.Ontology))\r
result.add(r);\r
else\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.IndexRoot;\r
import org.simantics.db.common.request.ResourceRead;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.simulation.ontology.SimulationResource;\r
@Override\r
public Resource perform(ReadGraph graph) throws DatabaseException {\r
\r
- Resource model = graph.syncRequest(new Model(resource));\r
+ Resource model = graph.syncRequest(new IndexRoot(resource));\r
return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014, 2016 Association for Decentralized \r
+ * Information Management in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the THTH Simantics \r
+ * Division Member Component License which accompanies this \r
+ * distribution, and is available at\r
+ * http://www.simantics.org/legal/sdmcl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.document.server.io;\r
+\r
+public class Content {\r
+ private byte[] data;\r
+ private String mimeType;\r
+ private long lastModified;\r
+ \r
+ public Content(byte[] data, String mimeType, long lastModified) {\r
+ this.data = data;\r
+ this.mimeType = mimeType;\r
+ this.lastModified = lastModified;\r
+ }\r
+\r
+ public byte[] getData() {\r
+ return data;\r
+ }\r
+\r
+ public void setData(byte[] data) {\r
+ this.data = data;\r
+ }\r
+\r
+ public String getMimeType() {\r
+ return mimeType;\r
+ }\r
+\r
+ public void setMimeType(String mimeType) {\r
+ this.mimeType = mimeType;\r
+ }\r
+\r
+ public long getLastModified() {\r
+ return lastModified;\r
+ }\r
+\r
+ public void setLastModified(long lastModified) {\r
+ this.lastModified = lastModified;\r
+ }\r
+}\r
String requestCSS(String documentURI);\r
int[] requestLoadingIndicatorDelay(String documentURI);\r
Double requestPollingInterval(String documentURI);\r
+ Content requestContent(String resourceURI);\r
public CommandResult execute(String id, CommandContext context);\r
public void subscribeDocument(String document, String sessionGUID, IDocumentListener documentListener);\r
public IJSONResult readChanges(String uri, String sessionGUID, int sequenceNumber);\r
--- /dev/null
+package org.simantics.document.ui.actions;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.ActionFactory;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class NewDocumentFolder implements ActionFactory {\r
+ Resource folderType;\r
+ Resource relation;\r
+ \r
+ public NewDocumentFolder(ReadGraph graph, String folderTypeUri, String relationUri) throws DatabaseException {\r
+ folderType = graph.getResource(folderTypeUri);\r
+ relation = graph.getResource(relationUri);\r
+ }\r
+ \r
+ @Override\r
+ public Runnable create(Object target) {\r
+\r
+ if(!(target instanceof Resource))\r
+ return null;\r
+\r
+ final Resource resource = (Resource)target;\r
+\r
+ return new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.markUndoPoint();\r
+ \r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+ String name = NameUtils.findFreshName(graph, "Folder", resource, relation);\r
+ Resource folder = graph.newResource();\r
+ graph.claim(folder, l0.InstanceOf, folderType);\r
+ graph.claimLiteral(folder, l0.HasName, name);\r
+ graph.claim(resource, relation, folder);\r
+ }\r
+ \r
+ });\r
+ }\r
+ };\r
+ }\r
+}\r
final public Optional<String> perform(Path file) throws Exception {\r
\r
Path dropins = Activator.getDropinsFolder();\r
- Path parts = dropins.relativize(file);\r
+ \r
+ Path parts;\r
+ if (file.toAbsolutePath().toString().startsWith(dropins.toAbsolutePath().toString())) {\r
+ parts = dropins.relativize(file);\r
+ } else {\r
+ parts = file.getFileName();\r
+ }\r
+ \r
Resource parent = resolveParent(null, parts);\r
if (parent == null)\r
return Optional.empty();\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.diagram.Logger;\r
+import org.simantics.diagram.flag.FlagUtil;\r
import org.simantics.diagram.stubs.DiagramResource;\r
import org.simantics.diagram.ui.DiagramModelHints;\r
import org.simantics.diagram.ui.WorkbenchSelectionProvider;\r
import org.simantics.g2d.element.ElementHints;\r
import org.simantics.g2d.element.ElementUtils;\r
import org.simantics.g2d.element.IElement;\r
+import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.selection.AnyResource;\r
//return Variables.getPossibleVariable(graph, resource2);\r
return var;\r
}\r
+ \r
+ if(graph.isInstanceOf(resource2, DIA.Flag)) {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Variable signal = FlagUtil.getPossibleFlagSignal(graph, var, resource2, L0.Entity);\r
+ if(signal != null)\r
+ return signal;\r
+ }\r
\r
return null;\r
+ \r
}\r
\r
return var.browsePossible(graph, config);\r
}\r
\r
protected boolean hitTest(MouseEvent event) {\r
- Rectangle2D bounds = super.getBoundsInLocal(false);\r
+ Rectangle2D bounds = super.getBoundsInLocal(true);\r
if (bounds == null)\r
return false;\r
Point2D localPos = NodeUtil.worldToLocal(this, event.controlPosition, new Point2D.Double());\r
package org.simantics.scl.compiler.internal.elaboration.constraints;
-import org.cojen.classfile.TypeDesc;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.constants.ClassConstant;
-import org.simantics.scl.compiler.constants.JavaConstructor;
-import org.simantics.scl.compiler.constants.JavaStaticField;
-import org.simantics.scl.compiler.constants.JavaStaticMethod;
import org.simantics.scl.compiler.constants.StringConstant;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
}
return result;
}
-
- private static final Type SERIALIZABLE_BOOLEAN = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN);
- private static final Type SERIALIZABLE_BYTE = Types.pred(Types.SERIALIZABLE, Types.BYTE);
- private static final Type SERIALIZABLE_SHORT = Types.pred(Types.SERIALIZABLE, Types.SHORT);
- private static final Type SERIALIZABLE_INTEGER = Types.pred(Types.SERIALIZABLE, Types.INTEGER);
- private static final Type SERIALIZABLE_LONG = Types.pred(Types.SERIALIZABLE, Types.LONG);
- private static final Type SERIALIZABLE_FLOAT = Types.pred(Types.SERIALIZABLE, Types.FLOAT);
- private static final Type SERIALIZABLE_DOUBLE = Types.pred(Types.SERIALIZABLE, Types.DOUBLE);
- private static final Type SERIALIZABLE_STRING = Types.pred(Types.SERIALIZABLE, Types.STRING);
-
- private static final Type SERIALIZABLE_BOOLEAN_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN_ARRAY);
- private static final Type SERIALIZABLE_BYTE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BYTE_ARRAY);
- private static final Type SERIALIZABLE_SHORT_ARRAY = Types.pred(Types.SERIALIZABLE, Types.SHORT_ARRAY);
- private static final Type SERIALIZABLE_INTEGER_ARRAY = Types.pred(Types.SERIALIZABLE, Types.INTEGER_ARRAY);
- private static final Type SERIALIZABLE_LONG_ARRAY = Types.pred(Types.SERIALIZABLE, Types.LONG_ARRAY);
- private static final Type SERIALIZABLE_FLOAT_ARRAY = Types.pred(Types.SERIALIZABLE, Types.FLOAT_ARRAY);
- private static final Type SERIALIZABLE_DOUBLE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.DOUBLE_ARRAY);
-
- private static final Type SERIALIZABLE_BOOLEAN_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BOOLEAN));
- private static final Type SERIALIZABLE_BYTE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BYTE));
- private static final Type SERIALIZABLE_SHORT_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.SHORT));
- private static final Type SERIALIZABLE_INTEGER_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.INTEGER));
- private static final Type SERIALIZABLE_LONG_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.LONG));
- private static final Type SERIALIZABLE_FLOAT_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.FLOAT));
- private static final Type SERIALIZABLE_DOUBLE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.DOUBLE));
-
- private static final Type SERIALIZABLE_TUPLE0 = Types.pred(Types.SERIALIZABLE, Types.tuple());
- private static final Type SERIALIZABLE_VARIANT = Types.pred(Types.SERIALIZABLE, Types.VARIANT);
-
+
public Reduction reduce(TPred constraint) {
// VecComp
if(constraint.typeClass == Types.VEC_COMP) {
Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
}
// Serializable
- if(constraint.typeClass == Types.SERIALIZABLE) {
- Type parameter = Types.canonical(constraint.parameters[0]);
- if(parameter instanceof TCon) {
- TCon con = (TCon)parameter;
- if(con == Types.DOUBLE)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/DoubleBinding"), SERIALIZABLE_DOUBLE, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.STRING)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "STRING", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/StringBinding"), SERIALIZABLE_STRING, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.INTEGER)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/IntegerBinding"), SERIALIZABLE_INTEGER, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.BOOLEAN)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/BooleanBinding"), SERIALIZABLE_BOOLEAN, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.BYTE)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BYTE", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ByteBinding"), SERIALIZABLE_BYTE, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.FLOAT)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/FloatBinding"), SERIALIZABLE_FLOAT, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.LONG)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "LONG", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/LongBinding"), SERIALIZABLE_LONG, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.tupleConstructor(0))
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "VOID", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/Binding"), SERIALIZABLE_TUPLE0, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.VARIANT)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "VARIANT", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/VariantBinding"), SERIALIZABLE_VARIANT, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.DOUBLE_ARRAY)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_DOUBLE_ARRAY, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.INTEGER_ARRAY)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_INTEGER_ARRAY, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.BOOLEAN_ARRAY)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BOOLEAN_ARRAY, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.BYTE_ARRAY)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BYTE_ARRAY, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.FLOAT_ARRAY)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_FLOAT_ARRAY, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(con == Types.LONG_ARRAY)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_LONG_ARRAY, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- }
- else if(parameter instanceof TApply) {
- TApply apply1 = (TApply)parameter;
- Type f1 = Types.canonical(apply1.function);
- Type p1 = Types.canonical(apply1.parameter);
- if(f1 instanceof TCon) {
- TCon con = (TCon)f1;
- if(con == Types.LIST)
- return new Reduction(
- new ELiteral(new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding", Types.NO_EFFECTS,
- Types.pred(Types.SERIALIZABLE, Types.list(p1)), Types.pred(Types.SERIALIZABLE, p1))),
- Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, p1) });
- else if(con == Types.MAYBE)
- return new Reduction(
- new ELiteral(new JavaConstructor("org/simantics/databoard/binding/impl/OptionalBindingDefault", Types.NO_EFFECTS,
- Types.pred(Types.SERIALIZABLE, Types.apply(Types.MAYBE, p1)), Types.pred(Types.SERIALIZABLE, p1))),
- Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, p1) });
- else if(con == Types.VECTOR) {
- if (p1 == Types.DOUBLE)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_DOUBLE_VECTOR, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(p1 == Types.INTEGER)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_INTEGER_VECTOR, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(p1 == Types.BOOLEAN)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BOOLEAN_VECTOR, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(p1 == Types.BYTE)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BYTE_VECTOR, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(p1 == Types.FLOAT)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_FLOAT_VECTOR, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else if(p1 == Types.LONG)
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_LONG_VECTOR, -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- else
- return new Reduction(
- new ELiteral(new JavaStaticMethod("org/simantics/databoard/Bindings", "getArrayBinding", Types.NO_EFFECTS,
- Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, p1)), Types.pred(Types.SERIALIZABLE, p1))),
- Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, p1) });
- }
- }
- else if(f1 instanceof TApply) {
- TApply apply2 = (TApply)parameter;
- Type f2 = Types.canonical(apply2.function);
- Type p2 = Types.canonical(apply2.parameter);
- if(f2 instanceof TCon) {
- TCon con = (TCon)f2;
- /*if(con == Types.tupleConstructor(2)) {
- return new Reduction(
- new EConstant(Builtins.TUPLE_CONSTRUCTORS[2]new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding", Types.NO_EFFECTS,
- Types.pred(Types.SERIALIZABLE, p1), Types.pred(Types.SERIALIZABLE, Types.list(p1)))),
- Type.EMPTY_ARRAY,
- new TPred[] { Types.pred(Types.SERIALIZABLE, p2), Types.pred(Types.SERIALIZABLE, p1) });
- }*/
- }
- }
- }
-
- // Default to a binding as an ObjectVariantBinding
- // This can be applied only if the type is ground type (i.e. does not contain type variables),
- // because otherwise the Serializable instance could be provided as a parameter to the function
- if(parameter.isGround())
- return new Reduction(
- new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "OBJECT", Types.NO_EFFECTS,
- TypeDesc.forClass("org/simantics/databoard/binding/VariantBinding"), Types.pred(Types.SERIALIZABLE, parameter), -1)),
- Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
- }
+ if(constraint.typeClass == Types.SERIALIZABLE)
+ return ReduceSerializable.reduceSerializable(constraint.parameters[0]);
// Typeable
else if(constraint.typeClass == Types.TYPEABLE) {
}\r
for(Constraint constraint : group) {\r
Reduction reduction = environment.reduce(constraint.constraint);\r
- if(reduction.parameters.length > 0)\r
+ if(reduction.demands.length > 0)\r
throw new InternalCompilerError();\r
constraint.setGenerator(Constraint.STATE_HAS_INSTANCE,\r
reduction.generator, reduction.parameters);\r
--- /dev/null
+package org.simantics.scl.compiler.internal.elaboration.constraints;\r
+\r
+import org.cojen.classfile.TypeDesc;\r
+import org.simantics.scl.compiler.constants.ClassConstant;\r
+import org.simantics.scl.compiler.constants.Constant;\r
+import org.simantics.scl.compiler.constants.JavaConstructor;\r
+import org.simantics.scl.compiler.constants.JavaStaticField;\r
+import org.simantics.scl.compiler.constants.JavaStaticMethod;\r
+import org.simantics.scl.compiler.elaboration.expressions.EApply;\r
+import org.simantics.scl.compiler.elaboration.expressions.EApplyType;\r
+import org.simantics.scl.compiler.elaboration.expressions.ELiteral;\r
+import org.simantics.scl.compiler.elaboration.expressions.Expression;\r
+import org.simantics.scl.compiler.elaboration.expressions.Expressions;\r
+import org.simantics.scl.compiler.types.TCon;\r
+import org.simantics.scl.compiler.types.TPred;\r
+import org.simantics.scl.compiler.types.TVar;\r
+import org.simantics.scl.compiler.types.Type;\r
+import org.simantics.scl.compiler.types.Types;\r
+import org.simantics.scl.compiler.types.kinds.Kinds;\r
+import org.simantics.scl.compiler.types.util.MultiApply;\r
+\r
+import gnu.trove.map.hash.THashMap;\r
+\r
+public class ReduceSerializable {\r
+ \r
+ private static final TVar A = Types.var(Kinds.STAR);\r
+ private static final TVar B = Types.var(Kinds.STAR);\r
+ \r
+ private static final Type SERIALIZABLE_BOOLEAN = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN);\r
+ private static final Type SERIALIZABLE_BYTE = Types.pred(Types.SERIALIZABLE, Types.BYTE);\r
+ private static final Type SERIALIZABLE_INTEGER = Types.pred(Types.SERIALIZABLE, Types.INTEGER);\r
+ private static final Type SERIALIZABLE_LONG = Types.pred(Types.SERIALIZABLE, Types.LONG);\r
+ private static final Type SERIALIZABLE_FLOAT = Types.pred(Types.SERIALIZABLE, Types.FLOAT);\r
+ private static final Type SERIALIZABLE_DOUBLE = Types.pred(Types.SERIALIZABLE, Types.DOUBLE);\r
+ private static final Type SERIALIZABLE_STRING = Types.pred(Types.SERIALIZABLE, Types.STRING);\r
+ \r
+ private static final Type SERIALIZABLE_BOOLEAN_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN_ARRAY);\r
+ private static final Type SERIALIZABLE_BYTE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BYTE_ARRAY);\r
+ private static final Type SERIALIZABLE_INTEGER_ARRAY = Types.pred(Types.SERIALIZABLE, Types.INTEGER_ARRAY);\r
+ private static final Type SERIALIZABLE_LONG_ARRAY = Types.pred(Types.SERIALIZABLE, Types.LONG_ARRAY);\r
+ private static final Type SERIALIZABLE_FLOAT_ARRAY = Types.pred(Types.SERIALIZABLE, Types.FLOAT_ARRAY);\r
+ private static final Type SERIALIZABLE_DOUBLE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.DOUBLE_ARRAY);\r
+ \r
+ private static final Type SERIALIZABLE_BOOLEAN_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BOOLEAN));\r
+ private static final Type SERIALIZABLE_BYTE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BYTE));\r
+ private static final Type SERIALIZABLE_INTEGER_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.INTEGER));\r
+ private static final Type SERIALIZABLE_LONG_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.LONG));\r
+ private static final Type SERIALIZABLE_FLOAT_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.FLOAT));\r
+ private static final Type SERIALIZABLE_DOUBLE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.DOUBLE));\r
+ \r
+ private static final Type SERIALIZABLE_TUPLE0 = Types.pred(Types.SERIALIZABLE, Types.tuple());\r
+ private static final Type SERIALIZABLE_VARIANT = Types.pred(Types.SERIALIZABLE, Types.VARIANT);\r
+ \r
+ private static final TCon MLIST = Types.con("MList", "T");\r
+ private static final TCon MAP = Types.con("Map", "T");\r
+ private static final TCon MMAP = Types.con("MMap", "T");\r
+ \r
+ private static Constant GET_BINDING =\r
+ new JavaStaticMethod("org/simantics/databoard/Bindings", "getBinding", Types.NO_EFFECTS,\r
+ Types.pred(Types.SERIALIZABLE, A), Types.pred(Types.VEC_COMP, A));\r
+\r
+ private static final THashMap<TCon,Constant> BINDING_CONSTANTS0 = new THashMap<TCon,Constant>();\r
+ static {\r
+ BINDING_CONSTANTS0.put(Types.DOUBLE, new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/DoubleBinding"), SERIALIZABLE_DOUBLE, -1));\r
+ BINDING_CONSTANTS0.put(Types.STRING, new JavaStaticField("org/simantics/databoard/Bindings", "STRING", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/StringBinding"), SERIALIZABLE_STRING, -1));\r
+ BINDING_CONSTANTS0.put(Types.INTEGER, new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/IntegerBinding"), SERIALIZABLE_INTEGER, -1));\r
+ BINDING_CONSTANTS0.put(Types.BOOLEAN, new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/BooleanBinding"), SERIALIZABLE_BOOLEAN, -1));\r
+ BINDING_CONSTANTS0.put(Types.BYTE, new JavaStaticField("org/simantics/databoard/Bindings", "BYTE", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ByteBinding"), SERIALIZABLE_BYTE, -1));\r
+ BINDING_CONSTANTS0.put(Types.FLOAT, new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/FloatBinding"), SERIALIZABLE_FLOAT, -1));\r
+ BINDING_CONSTANTS0.put(Types.LONG, new JavaStaticField("org/simantics/databoard/Bindings", "LONG", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/LongBinding"), SERIALIZABLE_LONG, -1));\r
+ BINDING_CONSTANTS0.put(Types.UNIT, new JavaStaticField("org/simantics/databoard/Bindings", "VOID", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/Binding"), SERIALIZABLE_TUPLE0, -1));\r
+ BINDING_CONSTANTS0.put(Types.VARIANT, new JavaStaticField("org/simantics/databoard/Bindings", "VARIANT", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/VariantBinding"), SERIALIZABLE_VARIANT, -1));\r
+ BINDING_CONSTANTS0.put(Types.DOUBLE_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_DOUBLE_ARRAY, -1));\r
+ BINDING_CONSTANTS0.put(Types.INTEGER_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_INTEGER_ARRAY, -1));\r
+ BINDING_CONSTANTS0.put(Types.BOOLEAN_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BOOLEAN_ARRAY, -1));\r
+ BINDING_CONSTANTS0.put(Types.BYTE_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BYTE_ARRAY, -1));\r
+ BINDING_CONSTANTS0.put(Types.FLOAT_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_FLOAT_ARRAY, -1));\r
+ BINDING_CONSTANTS0.put(Types.LONG_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_LONG_ARRAY, -1));\r
+ }\r
+ \r
+ private static final THashMap<TCon,Constant> BINDING_CONSTANTS1 = new THashMap<TCon,Constant>();\r
+ static {\r
+ BINDING_CONSTANTS1.put(Types.LIST, new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.list(A)), Types.pred(Types.SERIALIZABLE, A)));\r
+ BINDING_CONSTANTS1.put(Types.MAYBE, new JavaConstructor("org/simantics/databoard/binding/impl/OptionalBindingDefault", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(Types.MAYBE, A)), Types.pred(Types.SERIALIZABLE, A)));\r
+ BINDING_CONSTANTS1.put(Types.VECTOR, new JavaStaticMethod("org/simantics/databoard/Bindings", "getArrayBinding", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, A)), Types.pred(Types.SERIALIZABLE, A)));\r
+ BINDING_CONSTANTS1.put(MLIST, new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(MLIST, A)), Types.pred(Types.SERIALIZABLE, A)));\r
+ }\r
+ \r
+ private static final THashMap<TCon,Constant> VECTOR_BINDING_CONSTANTS = new THashMap<TCon,Constant>();\r
+ static {\r
+ VECTOR_BINDING_CONSTANTS.put(Types.DOUBLE, new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_DOUBLE_VECTOR, -1));\r
+ VECTOR_BINDING_CONSTANTS.put(Types.INTEGER, new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_INTEGER_VECTOR, -1));\r
+ VECTOR_BINDING_CONSTANTS.put(Types.BOOLEAN, new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BOOLEAN_VECTOR, -1));\r
+ VECTOR_BINDING_CONSTANTS.put(Types.BYTE, new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BYTE_VECTOR, -1));\r
+ VECTOR_BINDING_CONSTANTS.put(Types.FLOAT, new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_FLOAT_VECTOR, -1));\r
+ VECTOR_BINDING_CONSTANTS.put(Types.LONG, new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_LONG_VECTOR, -1));\r
+ }\r
+ \r
+ private static final THashMap<TCon,Constant> BINDING_CONSTANTS2 = new THashMap<TCon,Constant>();\r
+ static {\r
+ BINDING_CONSTANTS2.put(MAP, new JavaConstructor("org/simantics/databoard/binding/impl/HashMapBinding", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(MAP, A, B)), Types.pred(Types.SERIALIZABLE, A), Types.pred(Types.SERIALIZABLE, B)));\r
+ BINDING_CONSTANTS2.put(MMAP, new JavaConstructor("org/simantics/databoard/binding/impl/HashMapBinding", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(MMAP, A, B)), Types.pred(Types.SERIALIZABLE, A), Types.pred(Types.SERIALIZABLE, B)));\r
+ }\r
+ \r
+ public static Reduction reduceSerializable(Type parameter) {\r
+ MultiApply apply = Types.matchApply(parameter);\r
+ if(!(apply.constructor instanceof TCon))\r
+ return null;\r
+ \r
+ switch(apply.parameters.length) {\r
+ case 0: {\r
+ Constant constant = BINDING_CONSTANTS0.get(apply.constructor);\r
+ if(constant != null)\r
+ return new Reduction(new ELiteral(constant), Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);\r
+ } break;\r
+ case 1: {\r
+ Type parameter0 = apply.parameters[0];\r
+ if(apply.constructor == Types.VECTOR) {\r
+ Constant vecConstant = VECTOR_BINDING_CONSTANTS.get(parameter0);\r
+ if(vecConstant != null)\r
+ return new Reduction(new ELiteral(vecConstant), Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);\r
+ }\r
+ Constant constant = BINDING_CONSTANTS1.get(apply.constructor);\r
+ if(constant != null)\r
+ return new Reduction(new EApplyType(new ELiteral(constant), parameter0), Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, parameter0) });\r
+ } break;\r
+ case 2: {\r
+ Constant constant = BINDING_CONSTANTS2.get(apply.constructor);\r
+ if(constant != null)\r
+ return new Reduction(Expressions.applyTypes(new ELiteral(constant), apply.parameters),\r
+ Type.EMPTY_ARRAY,\r
+ new TPred[] { Types.pred(Types.SERIALIZABLE, apply.parameters[0]), Types.pred(Types.SERIALIZABLE, apply.parameters[1]) });\r
+ } break;\r
+ }\r
+ \r
+ // Default to a binding based on the class of the type.\r
+ // This can be applied only if the type is ground type (i.e. does not contain type variables),\r
+ // because otherwise the Serializable instance could be provided as a parameter to the function\r
+ if(parameter.isGround()) {\r
+ Expression bindingGenerator = new EApplyType(new ELiteral(GET_BINDING), parameter);\r
+ Expression bindingExpression = new EApply(bindingGenerator, new ELiteral(new ClassConstant(Types.pred(Types.VEC_COMP, parameter), parameter)));\r
+ return new Reduction(bindingExpression, Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);\r
+ }\r
+ \r
+ return null;\r
+ }\r
+}\r
parameters.add(Types.canonical(apply.parameter));
type = canonical(apply.function);
}
- return new MultiApply(type, parameters.toArray(new Type[parameters.size()]));
+ Type[] parametersArray;
+ if(parameters.isEmpty())
+ parametersArray = Type.EMPTY_ARRAY;
+ else {
+ parametersArray = new Type[parameters.size()];
+ for(int i=0,j=parametersArray.length-1;i<parametersArray.length;++i,--j)
+ parametersArray[i] = parameters.get(j);
+ }
+ return new MultiApply(type, parametersArray);
}
public static Type unifyApply(TCon func, Type type) throws MatchException {
if(rightVal==null) rightResult = rightTemp.toString();\r
else rightResult = rightVal;\r
}\r
- \r
- if ((leftResult instanceof String) || (rightResult instanceof String)) {\r
+ if ((leftResult instanceof String) && (rightResult instanceof String)) {\r
String leftString = (leftResult.toString()).toLowerCase();\r
String rightString = (rightResult.toString()).toLowerCase();\r
if("<".equals(astRelation.op.trim())) return leftString.compareTo(rightString) < 0;\r
else if(">".equals(astRelation.op.trim())) return leftString.compareTo(rightString) > 0;\r
- // empty string should equal zero (TODO: this is a hack, the proper fix should be somewhere earlier so other cases would work as well)\r
- else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0 || emptyAndZero(leftString, rightString) || emptyAndZero(rightString, leftString);\r
+ else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0;\r
else if("<>".equals(astRelation.op.trim())) return leftString.compareTo(rightString) != 0 ;\r
else if("<=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) <= 0 ;\r
else if(">=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) >= 0 ;\r
else throw new IllegalStateException();\r
} else {\r
- Number leftNumber = SpreadsheetGraphUtils.asNumber(leftResult);\r
- Number rightNumber = SpreadsheetGraphUtils.asNumber(rightResult);\r
+ Number leftNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftResult);\r
+ Number rightNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(rightResult);\r
+ if(leftNumber==null || rightNumber==null) return false;\r
if("<".equals(astRelation.op.trim())) return leftNumber.doubleValue() < rightNumber.doubleValue();\r
else if(">".equals(astRelation.op.trim())) return leftNumber.doubleValue() > rightNumber.doubleValue();\r
else if("=".equals(astRelation.op.trim())) return leftNumber.doubleValue() == rightNumber.doubleValue();\r
}\r
}\r
\r
- private static boolean emptyAndZero(String a, String b) {\r
- try {\r
- return a.isEmpty() && (Double.parseDouble(b) == 0);\r
- }\r
- catch (NumberFormatException e) {\r
- return false;\r
- }\r
- }\r
- \r
Object leftValueWithPrefix(Object result, AstValue value, String prefix, boolean forceNumber) {\r
if(result == null) {\r
Object obj = value.accept(this);\r
MBC
@VP.namedRelationChildRule TestsUI.Contributions.STSSuites L0.Entity L0.ConsistsOf TESTS.STSSuite
- @VP.namedConstantImageRule TestsUI.Contributions.ModuleImage TESTS.STSSuite TestsUI.testSuiteImage
+ @VP.namedConstantImageRule TestsUI.Contributions.SuiteImage TESTS.STSSuite TestsUI.testSuiteImage
@VP.namedRelationChildRule TestsUI.Contributions.STSTests L0.Entity L0.ConsistsOf TESTS.STSTest
- @VP.namedConstantImageRule TestsUI.Contributions.ModuleImage TESTS.STSTest TestsUI.testImage
+ @VP.namedConstantImageRule TestsUI.Contributions.TestImage TESTS.STSTest TestsUI.testImage
MAC = TestsUI.ModelingActionContext : VP.BrowseContext
VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext
\r
public final Resource BrowseContext;\r
public final Resource Contributions;\r
- public final Resource Contributions_ModuleImage;\r
public final Resource Contributions_NewSTSSuite;\r
public final Resource Contributions_NewSTSTest;\r
public final Resource Contributions_STSSuites;\r
public final Resource Contributions_STSTests;\r
+ public final Resource Contributions_SuiteImage;\r
+ public final Resource Contributions_TestImage;\r
public final Resource ModelingActionContext;\r
public final Resource ModelingActionContext_Actions;\r
public final Resource ModelingActionContext_Actions_NewSTSSuite;\r
public static class URIs {\r
public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext";\r
public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions";\r
- public static final String Contributions_ModuleImage = "http://www.simantics.org/TestsUI-1.0/Contributions/ModuleImage";\r
public static final String Contributions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSSuite";\r
public static final String Contributions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSTest";\r
public static final String Contributions_STSSuites = "http://www.simantics.org/TestsUI-1.0/Contributions/STSSuites";\r
public static final String Contributions_STSTests = "http://www.simantics.org/TestsUI-1.0/Contributions/STSTests";\r
+ public static final String Contributions_SuiteImage = "http://www.simantics.org/TestsUI-1.0/Contributions/SuiteImage";\r
+ public static final String Contributions_TestImage = "http://www.simantics.org/TestsUI-1.0/Contributions/TestImage";\r
public static final String ModelingActionContext = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext";\r
public static final String ModelingActionContext_Actions = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions";\r
public static final String ModelingActionContext_Actions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSSuite";\r
public TestsUIResource(ReadGraph graph) {\r
BrowseContext = getResourceOrNull(graph, URIs.BrowseContext);\r
Contributions = getResourceOrNull(graph, URIs.Contributions);\r
- Contributions_ModuleImage = getResourceOrNull(graph, URIs.Contributions_ModuleImage);\r
Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite);\r
Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest);\r
Contributions_STSSuites = getResourceOrNull(graph, URIs.Contributions_STSSuites);\r
Contributions_STSTests = getResourceOrNull(graph, URIs.Contributions_STSTests);\r
+ Contributions_SuiteImage = getResourceOrNull(graph, URIs.Contributions_SuiteImage);\r
+ Contributions_TestImage = getResourceOrNull(graph, URIs.Contributions_TestImage);\r
ModelingActionContext = getResourceOrNull(graph, URIs.ModelingActionContext);\r
ModelingActionContext_Actions = getResourceOrNull(graph, URIs.ModelingActionContext_Actions);\r
ModelingActionContext_Actions_NewSTSSuite = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSSuite);\r
\r
private int floatDigits;\r
private int doubleDigits;\r
+ private double lowLimit;\r
+ private double highLimit;\r
private DecimalFormatSymbols decimalFormatSymbols;\r
\r
private DecimalFormat flow;\r
public FormattingUtil(int floatDigits, int doubleDigits) {\r
this(floatDigits, doubleDigits, Locale.getDefault());\r
}\r
-\r
+ \r
public FormattingUtil(int floatDigits, int doubleDigits, Locale locale) {\r
- this.floatDigits = floatDigits;\r
+ this(floatDigits, doubleDigits, 0.01, 1e6, locale);\r
+ }\r
+\r
+ public FormattingUtil(int floatDigits, int doubleDigits, double lowLimit, double highLimit, Locale locale) {\r
+ this.floatDigits = floatDigits;\r
this.doubleDigits = doubleDigits;\r
- this.decimalFormatSymbols = DecimalFormatSymbols.getInstance(locale);\r
+ this.lowLimit = lowLimit;\r
+ this.highLimit = highLimit;\r
+ this.decimalFormatSymbols = DecimalFormatSymbols.getInstance(locale != null ? locale : Locale.getDefault());\r
initFormats();\r
}\r
\r
private void initFormats() {\r
this.flow = createLowFormat(floatDigits);\r
- this.fmiddles = createMiddleFormats(6, floatDigits);\r
+ double exp = Math.log10(highLimit);\r
+ int formatCount = Math.max(1, (int) Math.ceil(exp));\r
+ this.fmiddles = createMiddleFormats(formatCount, floatDigits);\r
this.fhigh = createHighFormat(floatDigits);\r
this.dlow = createLowFormat(doubleDigits);\r
- this.dmiddles = createMiddleFormats(6, doubleDigits);\r
+ this.dmiddles = createMiddleFormats(formatCount, doubleDigits);\r
this.dhigh = createHighFormat(doubleDigits);\r
}\r
\r
\r
private DecimalFormat createHighFormat(int digitCount) {\r
StringBuilder fmt = new StringBuilder();\r
- fmt.append("##0.");\r
+ fmt.append("##0");\r
+ if (digitCount > 3) fmt.append(".");\r
for (int i = 3; i < digitCount; ++i)\r
fmt.append('#');\r
fmt.append("E0");\r
return new DecimalFormat(fmt.toString(), decimalFormatSymbols);\r
}\r
\r
- private static DecimalFormat[] createMiddleFormats(int formatCount, int digitCount) {\r
- DecimalFormat[] middles = new DecimalFormat[6];\r
+ private DecimalFormat[] createMiddleFormats(int formatCount, int digitCount) {\r
+ DecimalFormat[] middles = new DecimalFormat[formatCount];\r
for (int exp10 = 0; exp10 < formatCount; ++exp10) {\r
StringBuilder fmt = new StringBuilder();\r
int digits = digitCount;\r
fmt.append('#');\r
fmt.append('0');\r
--digits;\r
- fmt.append('.');\r
+ if (digits > 0) fmt.append('.');\r
for (; digits > 0; --digits)\r
fmt.append('#');\r
//System.out.println(fmt.toString());\r
- middles[exp10] = new DecimalFormat(fmt.toString(), DecimalFormatSymbols.getInstance(Locale.US));\r
+ middles[exp10] = new DecimalFormat(fmt.toString(), decimalFormatSymbols);\r
}\r
return middles;\r
}\r
}\r
}\r
\r
- private String formatNumber(float v) {\r
+ public String formatNumber(float v) {\r
if (Float.isInfinite(v)) {\r
return (v == Float.POSITIVE_INFINITY) ? "\u221E" : "-\u221E";\r
} else if (Float.isNaN(v)) {\r
return "NaN";\r
} else {\r
float abs = Math.abs(v);\r
- if (abs < 1.0f && abs >= 0.01f) {\r
+ if (abs < 1.0f && abs >= (float)lowLimit) {\r
return flow.format(v);\r
- } else if (abs >= 1.0f && abs < 1e6f) {\r
+ } else if (abs >= 1.0f && abs < (float)highLimit) {\r
double exp = Math.log10(abs);\r
int expi = (int) Math.floor(exp);\r
// System.out.println("format(" + v + ")");\r
}\r
}\r
\r
- private String formatNumber(double v) {\r
+ public String formatNumber(double v) {\r
if (Double.isInfinite(v)) {\r
return (v == Double.POSITIVE_INFINITY) ? "\u221E" : "-\u221E";\r
} else if (Double.isNaN(v)) {\r
return "NaN";\r
} else {\r
double abs = Math.abs(v);\r
- if (abs < 1.0 && abs >= 0.01) {\r
+ if (abs < 1.0 && abs >= lowLimit) {\r
return dlow.format(v);\r
- } else if (abs >= 1.0 && abs < 1e6) {\r
+ } else if (abs >= 1.0 && abs < highLimit) {\r
double exp = Math.log10(abs);\r
int expi = (int) Math.floor(exp);\r
// System.out.println("format(" + v + ")");\r