From: villberg Date: Thu, 7 Jul 2011 12:55:42 +0000 (+0000) Subject: Adding a workbook for configuration. X-Git-Tag: simantics-1.5~77 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f18790993f90716789425c2472f791e5d80ec3c2;p=simantics%2Fsysdyn.git Adding a workbook for configuration. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@21424 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 6c7f8493..b633d258 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph index 015bb200..18248d92 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph @@ -81,11 +81,19 @@ ACTIONS.NewEnumeration : ACT.Action ACTIONS.NewFunction : ACT.Action ACTIONS.NewFunctionLibrary : ACT.Action ACTIONS.NewSharedFunctionLibrary : ACT.Action +ACTIONS.OpenWorkbook : ACT.Action -MAC +MAC @VP.actionContribution "Module" SBC.ModulesFolder MBC.Images.Composite VP.NewActionCategory ACTIONS.NewModuleType + VP.BrowseContext.HasActionContribution _ : VP.ActionContribution + L0.HasLabel "Open Workbook" + VP.ActionContribution.HasImage MBC.Images.Component + VP.ActionContribution.HasNodeType MBC.Configuration + VP.ActionContribution.HasAction ACTIONS.OpenWorkbook + @VP.actionContribution "Enumeration" MBC.Configuration MBC.Images.Component VP.NewActionCategory ACTIONS.NewEnumeration + //@VP.actionContribution "Open Workbook" MBC.Configuration MBC.Images.Component VP.NewActionCategory ACTIONS.OpenWorkbook @VP.actionContribution "Enumeration" SBC.ModuleSymbol MBC.Images.Component VP.NewActionCategory ACTIONS.NewEnumeration @VP.actionContribution "Function" SBC.FunctionsFolder MBC.Images.Component VP.NewActionCategory ACTIONS.NewFunction @VP.actionContribution "Function" SYSDYN.SysdynModelicaFunctionLibrary MBC.Images.Component VP.NewActionCategory ACTIONS.NewFunction diff --git a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java index 74c7015d..5308d589 100644 --- a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java @@ -145,6 +145,7 @@ public class SysdynResource { public final Resource ProjectActionContext_Actions_NewFunctionLibrary; public final Resource ProjectActionContext_Actions_NewModuleType; public final Resource ProjectActionContext_Actions_NewSharedFunctionLibrary; + public final Resource ProjectActionContext_Actions_OpenWorkbook; public final Resource ProjectBrowseContext; public final Resource ProjectBrowseContext_BuiltinFunctions; public final Resource ProjectBrowseContext_FunctionsFolder; @@ -324,6 +325,7 @@ public class SysdynResource { public static final String ProjectActionContext_Actions_NewFunctionLibrary = "http://www.simantics.org/Sysdyn-1.0/ProjectActionContext/Actions/NewFunctionLibrary"; public static final String ProjectActionContext_Actions_NewModuleType = "http://www.simantics.org/Sysdyn-1.0/ProjectActionContext/Actions/NewModuleType"; public static final String ProjectActionContext_Actions_NewSharedFunctionLibrary = "http://www.simantics.org/Sysdyn-1.0/ProjectActionContext/Actions/NewSharedFunctionLibrary"; + public static final String ProjectActionContext_Actions_OpenWorkbook = "http://www.simantics.org/Sysdyn-1.0/ProjectActionContext/Actions/OpenWorkbook"; public static final String ProjectBrowseContext = "http://www.simantics.org/Sysdyn-1.0/ProjectBrowseContext"; public static final String ProjectBrowseContext_BuiltinFunctions = "http://www.simantics.org/Sysdyn-1.0/ProjectBrowseContext/BuiltinFunctions"; public static final String ProjectBrowseContext_FunctionsFolder = "http://www.simantics.org/Sysdyn-1.0/ProjectBrowseContext/FunctionsFolder"; @@ -513,6 +515,7 @@ public class SysdynResource { ProjectActionContext_Actions_NewFunctionLibrary = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewFunctionLibrary); ProjectActionContext_Actions_NewModuleType = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewModuleType); ProjectActionContext_Actions_NewSharedFunctionLibrary = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewSharedFunctionLibrary); + ProjectActionContext_Actions_OpenWorkbook = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_OpenWorkbook); ProjectBrowseContext = getResourceOrNull(graph, URIs.ProjectBrowseContext); ProjectBrowseContext_BuiltinFunctions = getResourceOrNull(graph, URIs.ProjectBrowseContext_BuiltinFunctions); ProjectBrowseContext_FunctionsFolder = getResourceOrNull(graph, URIs.ProjectBrowseContext_FunctionsFolder); diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index ed95e058..54792ffe 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -40,7 +40,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2", org.simantics.graph;bundle-version="1.0.2", org.simantics.graph.db;bundle-version="1.0.0", org.simantics.structural.ui;bundle-version="1.1.1", - org.simantics.browsing.ui.model;bundle-version="1.0.0" + org.simantics.browsing.ui.model;bundle-version="1.0.0", + org.simantics.spreadsheet.ui;bundle-version="1.1.0" Bundle-Activator: org.simantics.sysdyn.ui.Activator Bundle-ActivationPolicy: lazy Export-Package: org.simantics.sysdyn.ui.browser.nodes diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml index bb6ba6dd..f15dc9e0 100644 --- a/org.simantics.sysdyn.ui/adapters.xml +++ b/org.simantics.sysdyn.ui/adapters.xml @@ -10,5 +10,5 @@ VTT Technical Research Centre of Finland - initial API and implementation --> - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java new file mode 100644 index 00000000..f233f3a4 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java @@ -0,0 +1,82 @@ +package org.simantics.sysdyn.ui.browser.actions; + +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ui.diagramEditor.OpenSheetAdapter; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class OpenWorkbookAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + + if(!(target instanceof Resource)) + return null; + + final Resource resource = (Resource)target; + + return new Runnable() { + + @Override + public void run() { + + try { + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + + Resource book = graph.syncRequest(new PossibleObjectWithType(resource, L0.ConsistsOf, sr.Book)); + final Resource sheet = graph.syncRequest(new PossibleObjectWithType(book, L0.ConsistsOf, sr.Spreadsheet)); + + SimulationResource SIMU = SimulationResource.getInstance(graph); + Variable variable = graph.adapt(sheet, Variable.class); + Resource model = Variables.getModel(graph, variable); + final String modelURI = graph.getURI(model); + final String RVI = Variables.getRVI(graph, variable); + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + private static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2"; + + @Override + public void run() { + try { + System.out.println("Activating sheet: model=" + modelURI + " rvi=" + RVI); + WorkbenchUtils.openEditor(EDITOR_ID, new ResourceEditorInput2(EDITOR_ID, sheet, modelURI, RVI)); + } catch (PartInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + }; + + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index 0147a2f2..366e0038 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.project; import java.io.File; import java.util.HashMap; +import java.util.UUID; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.IEclipsePreferences; @@ -54,6 +55,7 @@ import org.simantics.project.ontology.ProjectResource; import org.simantics.simulation.experiment.IExperiment; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.simulation.project.IExperimentManager; +import org.simantics.spreadsheet.resource.SpreadsheetResource; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService; @@ -104,11 +106,63 @@ public class SysdynProject extends AbstractProjectFeature { } private final WriteRunnable CREATE_MODEL = new WriteRunnable() { + + Resource createSheet(WriteGraph graph, Resource book, String name, String[] colNames, int[] colWidths) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + + Resource result = graph.newResource(); + graph.claim(result, L0.InstanceOf, null, sr.Spreadsheet); + + if(name == null) { + name = NameUtils.findFreshEscapedName(graph, "Sheet", book, sr.HasSheet); + } + graph.claimLiteral(result, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); + graph.claim(book, L0.ConsistsOf, L0.PartOf, result); + + { + Resource newCell = graph.newResource(); + graph.claim(newCell, L0.InstanceOf, null, sr.DimensionsCell); + graph.claimLiteral(newCell, L0.HasName, L0.NameOf, L0.String, "Dimensions", Bindings.STRING); + graph.addLiteral(newCell, sr.FitColumns, sr.FitColumnsOf, L0.Boolean, true, Bindings.BOOLEAN); + graph.addLiteral(newCell, sr.FitRows, sr.FitRowsOf, L0.Boolean, true, Bindings.BOOLEAN); + graph.claim(result, L0.ConsistsOf, L0.PartOf, newCell); + } + + { + Resource newCell = graph.newResource(); + graph.claimLiteral(newCell, L0.HasName, L0.NameOf, L0.String, "Headers", Bindings.STRING); + graph.claim(newCell, L0.InstanceOf, null, sr.HeadersCell); + graph.addLiteral(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, L0.StringArray, colNames, Bindings.getBindingUnchecked(String[].class)); + graph.addLiteral(newCell, sr.ColumnWidths, sr.ColumnWidthsOf, L0.IntegerArray, colWidths, Bindings.INT_ARRAY); + graph.claim(result, L0.ConsistsOf, L0.PartOf, newCell); + } + + { + + double[] doubles = new double[10*10]; + for(int i=0;i<10*10;i++) doubles[i] = i; + + Resource newCell = graph.newResource(); + graph.claim(newCell, L0.InstanceOf, null, sr.DoubleArrayCell); + graph.addLiteral(newCell, sr.DoubleArrayCell_HasWidth, sr.DoubleArrayCell_HasWidth_Inverse, L0.Integer, 10, Bindings.INTEGER); + graph.addLiteral(newCell, sr.HasLocation, sr.HasLocation_Inverse, L0.String, "A1", Bindings.STRING); + graph.addLiteral(newCell, sr.DoubleArrayCell_HasDoubleArray, sr.DoubleArrayCell_HasDoubleArray_Inverse, L0.DoubleArray, doubles, Bindings.DOUBLE_ARRAY); + graph.claim(result, L0.HasChildVariables, L0.HasChildVariables_Inverse, newCell); + + } + + return result; + + } + @Override public void run(WriteGraph g, Resource library, Callback callback, Callback errorCallback) { try { Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); + SpreadsheetResource SHEET = SpreadsheetResource.getInstance(g); ModelingUtils mu = new ModelingUtils(g); String modelName = NameUtils.findFreshName(g, "Model", SimanticsUI.getProject().get(), l0.ConsistsOf, "%s%d"); @@ -135,6 +189,15 @@ public class SysdynProject extends AbstractProjectFeature { g.claim(model, mu.SIMU.HasConfiguration, conf); + Resource book = g.newResource(); + g.claim(book, l0.InstanceOf, null, SHEET.Book); + g.addLiteral(book, l0.HasName, l0.NameOf, l0.String, "Book" + UUID.randomUUID().toString(), Bindings.STRING); + g.claim(conf, l0.ConsistsOf, l0.PartOf, book); + + createSheet(g, book, "Sheet1", new String[] { "ARG" }, new int[] { 50 }); + + + ModelingResources mr = ModelingResources.getInstance(g); // Remove default mapping and add sysdyn mapping for(Resource trigger : g.getObjects(diagram, l0.HasTrigger)) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java index 1402f225..859e5d7f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java @@ -29,15 +29,15 @@ public class ConfigurationVariable extends StandardGraphChildVariable { super(resource); } - @Override - public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { - Map children = graph.syncRequest(new UnescapedChildMapOfResource(resource)); - Resource child = children.get(name); - if(child == null) { - return getPossibleSpecialChild(graph, name); - } - else return graph.adaptContextual(child, this, Variable.class, Variable.class); - } +// @Override +// public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { +// Map children = graph.syncRequest(new UnescapedChildMapOfResource(resource)); +// Resource child = children.get(name); +// if(child == null) { +// return getPossibleSpecialChild(graph, name); +// } +// else return graph.adaptContextual(child, this, Variable.class, Variable.class); +// } @Override