class="org.simantics.sysdyn.ui.browser.contributions.SharedFunctionLibraries"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.Book"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
<binding browseContext="http://www.simantics.org/Sysdyn-1.0/SysdynOperationBrowser">\r
<implementation class="org.simantics.sysdyn.ui.property.OperationProjectContributor" preference="1.0"/>\r
class="org.simantics.sysdyn.ui.browser.contributions.SharedFunctionsLabeler"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.BookLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SheetLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
<binding browseContext="http://www.simantics.org/Sysdyn-1.0/SysdynOperationBrowser">\r
<implementation class="org.simantics.sysdyn.ui.property.OperationModelLabels" preference="1.0"/>\r
org.eclipse.ui/SHOW_PROGRESS_ON_STARTUP = false\r
+org.eclipse.ui/DOCK_PERSPECTIVE_BAR=right
\ No newline at end of file
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder;\r
import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;\r
import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
+import org.simantics.sysdyn.ui.browser.nodes.SheetNode;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
\r
public class AbstractNodeImager extends ImagerContributor<AbstractNode<Resource>> {\r
image = "icons/chart_organisation.png";\r
else if (node instanceof VariableNode)\r
image = "icons/brick.png";\r
+ else if (node instanceof BookNode)\r
+ image = "icons/table_multiple.png";\r
+ else if (node instanceof SheetNode)\r
+ image = "icons/table.png";\r
\r
if (image != null)\r
return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image));\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\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.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SheetNode;\r
+\r
+public class Book extends ViewpointContributor<BookNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, BookNode book) throws DatabaseException {\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(book.data, l0.ConsistsOf, SpreadsheetResource.getInstance(graph).Spreadsheet))) {\r
+ result.add(new SheetNode(r));\r
+ }\r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
+\r
+public class BookLabeler extends LabelerContributor<BookNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, BookNode input) throws DatabaseException {\r
+ return "SpreadSheets";\r
+ }\r
+\r
+}\r
import java.util.ArrayList;\r
import java.util.Collection;\r
\r
-import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\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.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ui.modelBrowser2.model.SheetsNode;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode;\r
import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
\r
@Override\r
public Collection<?> getContribution(ReadGraph graph, ConfigurationNode<Resource> configuration) throws DatabaseException {\r
- ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ ArrayList<Object> result = new ArrayList<Object>();\r
Variable variable = configuration.getVariable();\r
\r
if (variable == null) {\r
Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
result.add(new EnumerationNode(v, represents));\r
}\r
+ \r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(\r
+ configuration.data,\r
+ Layer0.getInstance(graph).ConsistsOf, \r
+ SpreadsheetResource.getInstance(graph).Book))) {\r
+ result.add(new BookNode(r));\r
+ }\r
+ \r
return result;\r
}\r
\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.browser.nodes.SheetNode;\r
+\r
+public class SheetLabeler extends LabelerContributor<SheetNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SheetNode sheet) throws DatabaseException {\r
+ return graph.getPossibleRelatedValue(sheet.data, Layer0.getInstance(graph).HasName);\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.Resource;\r
+\r
+public class BookNode extends AbstractNode<Resource> {\r
+\r
+ public BookNode(Resource data) {\r
+ super(data);\r
+ }\r
+\r
+ @SuppressWarnings("rawtypes")\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if(clazz == adapter) // There is no resource for this node..\r
+ return null;\r
+ return super.getAdapter(adapter);\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.workbench.ResourceEditorInput2;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+public class SheetNode extends AbstractNode<Resource> implements IModifiableNode, IDoubleClickableNode {\r
+\r
+ public SheetNode(Resource data) {\r
+ super(data);\r
+ }\r
+ \r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ \r
+ Session session = SimanticsUI.getSession();\r
+ LabelModifier modifier = new LabelModifier(session, data, session.getService(Layer0.class).HasName) {\r
+ @Override\r
+ public String isValid(String label) {\r
+ if (label.isEmpty())\r
+ return "Empty label not allowed";\r
+ return null;\r
+ }\r
+ };\r
+ return modifier;\r
+ }\r
+\r
+ @Override\r
+ public boolean handleDoubleClick() {\r
+ \r
+ try {\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+\r
+ Variable variable = graph.adapt(data, Variable.class);\r
+ Resource model = Variables.getModel(graph, variable);\r
+ final String modelURI = graph.getURI(model);\r
+ final String RVI = Variables.getRVI(graph, variable);\r
+\r
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+ \r
+ private static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2";\r
+ \r
+ @Override\r
+ public void run() {\r
+ try {\r
+ System.out.println("Activating sheet: model=" + modelURI + " rvi=" + RVI);\r
+ WorkbenchUtils.openEditor(EDITOR_ID, new ResourceEditorInput2(EDITOR_ID, data, modelURI, RVI));\r
+ } catch (PartInitException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ });\r
+ }\r
+ });\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ return true;\r
+ }\r
+\r
+\r
+}\r
import java.io.File;\r
import java.io.IOException;\r
import java.util.HashSet;\r
+import java.util.UUID;\r
\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ObjectsWithType;\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.layer0.utils.direct.GraphUtils;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.Activator;\r
updateOldConfigurationToBaseRealization(graph, root);\r
addDefaultOntologyLinks(graph, root);\r
addURIsToDiagrams(graph, root);\r
+ addSpreadSheetBook(graph, root);\r
}\r
}\r
});\r
e.printStackTrace();\r
}\r
}\r
+ \r
+ \r
+ /**\r
+ * Add a missing spreadsheet book to the model\r
+ * \r
+ * @param graph\r
+ * @param model\r
+ */\r
+ private static void addSpreadSheetBook(WriteGraph graph, Resource model) {\r
+ try {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SpreadsheetResource ssr = SpreadsheetResource.getInstance(graph);\r
+ SimulationResource simu = SimulationResource.getInstance(graph);\r
+ Resource conf = graph.getPossibleObject(model, simu.HasConfiguration);\r
+ if(conf != null && graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, ssr.Book)).isEmpty()) {\r
+ Resource book = graph.newResource();\r
+ graph.claim(book, l0.InstanceOf, null, ssr.Book);\r
+ graph.addLiteral(book, l0.HasName, l0.NameOf, l0.String, "Book" + UUID.randomUUID().toString(), Bindings.STRING);\r
+ graph.claim(conf, l0.ConsistsOf, l0.PartOf, book);\r
+\r
+ createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 });\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Create a sheet (Copied from SysdynProject)\r
+ * \r
+ * @param graph\r
+ * @param book\r
+ * @param name\r
+ * @param colNames\r
+ * @param colWidths\r
+ * @return\r
+ * @throws DatabaseException\r
+ */\r
+ private static Resource createSheet(WriteGraph graph, Resource book, String name, String[] colNames, int[] colWidths) throws DatabaseException {\r
+\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);\r
+\r
+ Resource result = graph.newResource();\r
+ graph.claim(result, L0.InstanceOf, null, sr.Spreadsheet);\r
+\r
+ if(name == null) {\r
+ name = NameUtils.findFreshEscapedName(graph, "Sheet", book, sr.HasSheet);\r
+ }\r
+ graph.claimLiteral(result, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING);\r
+ graph.claim(book, L0.ConsistsOf, L0.PartOf, result);\r
+\r
+ {\r
+ Resource newCell = graph.newResource();\r
+ graph.claim(newCell, L0.InstanceOf, null, sr.Cell);\r
+ graph.claimLiteral(newCell, L0.HasName, L0.NameOf, L0.String, "Dimensions", Bindings.STRING);\r
+ graph.addLiteral(newCell, sr.FitColumns, sr.FitColumnsOf, L0.Boolean, false, Bindings.BOOLEAN);\r
+ graph.addLiteral(newCell, sr.FitRows, sr.FitRowsOf, L0.Boolean, false, Bindings.BOOLEAN);\r
+ graph.addLiteral(newCell, sr.ColumnCount, sr.ColumnCountOf, L0.Integer, 128, Bindings.INTEGER);\r
+ graph.addLiteral(newCell, sr.RowCount, sr.RowCountOf, L0.Integer, 256, Bindings.INTEGER);\r
+ graph.claim(result, L0.ConsistsOf, L0.PartOf, newCell);\r
+ }\r
+\r
+ {\r
+ Resource newCell = graph.newResource();\r
+ graph.claim(newCell, L0.InstanceOf, null, sr.Cell);\r
+ graph.claimLiteral(newCell, L0.HasName, L0.NameOf, L0.String, "Headers", Bindings.STRING);\r
+ graph.addLiteral(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, L0.StringArray, colNames, Bindings.STRING_ARRAY);\r
+ graph.addLiteral(newCell, sr.ColumnWidths, sr.ColumnWidthsOf, L0.IntegerArray, colWidths, Bindings.INT_ARRAY);\r
+ graph.claim(result, L0.ConsistsOf, L0.PartOf, newCell);\r
+ }\r
+\r
+ {\r
+ \r
+ double[] doubles = new double[10*2];\r
+ for(int i=0;i<10*2;i++) doubles[i] = i;\r
+ \r
+ Resource newCell = graph.newResource();\r
+ graph.claim(newCell, L0.InstanceOf, null, sr.DoubleArrayCell);\r
+ graph.addLiteral(newCell, sr.DoubleArrayCell_HasWidth, sr.DoubleArrayCell_HasWidth_Inverse, L0.Integer, 10, Bindings.INTEGER);\r
+ graph.addLiteral(newCell, sr.HasLocation, sr.HasLocation_Inverse, L0.String, "B2", Bindings.STRING);\r
+ graph.addLiteral(newCell, sr.DoubleArrayCell_HasDoubleArray, sr.DoubleArrayCell_HasDoubleArray_Inverse, L0.DoubleArray, doubles, Bindings.DOUBLE_ARRAY);\r
+ graph.claim(result, L0.HasChildVariables, L0.HasChildVariables_Inverse, newCell);\r
+ \r
+ }\r
+ \r
+ return result;\r
+\r
+ }\r
+\r
}\r
//IDENT [ array_subscripts ] [ "." component_reference ]\r
<IDENT> {\r
String name = token.image; \r
- // prevToken != null => this is the second part of an enumeration\r
+ // forIndex == true and prevToken != null => this is the second part of an enumeration in for-index\r
if(forIndex == true && prevToken != null) {\r
if(enumerationReferences.get(prevToken) == null) {\r enumerationReferences.put(prevToken, new ArrayList<Token>());\r
}\r
List<Token> list = enumerationReferences.get(prevToken);\r
list.add(token); \r
\r
- // forIndex == true, prevToken == null => this is the enumeration\r
+ // forIndex == true and prevToken == null => this is the enumeration in for-index\r
} else if(forIndex == true && prevToken == null) {\r
if(enumerationReferences.get(name) == null) {\r
enumerationReferences.put(name, new ArrayList<Token>());\r