>-- SYSDYN.SysdynModel.variableFilter --> L0.String <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.SysdynModel.fmuFile --> L0.ByteArray <R L0.HasProperty
>-- SYSDYN.SysdynModel.timeUnit --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+ >-- SYSDYN.SysdynModel.lastExportFileName --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+ >-- SYSDYN.SysdynModel.lastExportFilePath --> L0.String <R L0.HasProperty : L0.FunctionalRelation
// >-- SYSDYN.SysdynModel.exeFile --> L0.ByteArray <R L0.HasProperty
@L0.assert SYSDYN.SysdynModel.startTime 0.0
@L0.assert SYSDYN.SysdynModel.stopTime 10.0
public final Resource SysdynModel;\r
public final Resource SysdynModel_fmuFile;\r
public final Resource SysdynModel_fmuFile_Inverse;\r
+ public final Resource SysdynModel_lastExportFileName;\r
+ public final Resource SysdynModel_lastExportFileName_Inverse;\r
+ public final Resource SysdynModel_lastExportFilePath;\r
+ public final Resource SysdynModel_lastExportFilePath_Inverse;\r
public final Resource SysdynModel_outputInterval;\r
public final Resource SysdynModel_outputInterval_Inverse;\r
public final Resource SysdynModel_simulationStepLength;\r
public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.1/SysdynModel";\r
public static final String SysdynModel_fmuFile = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/fmuFile";\r
public static final String SysdynModel_fmuFile_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/fmuFile/Inverse";\r
+ public static final String SysdynModel_lastExportFileName = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/lastExportFileName";\r
+ public static final String SysdynModel_lastExportFileName_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/lastExportFileName/Inverse";\r
+ public static final String SysdynModel_lastExportFilePath = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/lastExportFilePath";\r
+ public static final String SysdynModel_lastExportFilePath_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/lastExportFilePath/Inverse";\r
public static final String SysdynModel_outputInterval = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/outputInterval";\r
public static final String SysdynModel_outputInterval_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/outputInterval/Inverse";\r
public static final String SysdynModel_simulationStepLength = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/simulationStepLength";\r
SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
SysdynModel_fmuFile = getResourceOrNull(graph, URIs.SysdynModel_fmuFile);\r
SysdynModel_fmuFile_Inverse = getResourceOrNull(graph, URIs.SysdynModel_fmuFile_Inverse);\r
+ SysdynModel_lastExportFileName = getResourceOrNull(graph, URIs.SysdynModel_lastExportFileName);\r
+ SysdynModel_lastExportFileName_Inverse = getResourceOrNull(graph, URIs.SysdynModel_lastExportFileName_Inverse);\r
+ SysdynModel_lastExportFilePath = getResourceOrNull(graph, URIs.SysdynModel_lastExportFilePath);\r
+ SysdynModel_lastExportFilePath_Inverse = getResourceOrNull(graph, URIs.SysdynModel_lastExportFilePath_Inverse);\r
SysdynModel_outputInterval = getResourceOrNull(graph, URIs.SysdynModel_outputInterval);\r
SysdynModel_outputInterval_Inverse = getResourceOrNull(graph, URIs.SysdynModel_outputInterval_Inverse);\r
SysdynModel_simulationStepLength = getResourceOrNull(graph, URIs.SysdynModel_simulationStepLength);\r
icon="platform:/plugin/com.famfamfam.silk/icons/plugin.png"\r
id="org.simantics.sysdyn.ui.diagramViewer"\r
matchingStrategy="org.simantics.ui.workbench.editor.input.ResourceEditorInputMatchingStrategy"\r
- name="System dynamic diagram viewer">\r
+ name="System Dynamic Diagram Viewer">\r
</editor>\r
<editor\r
class="org.simantics.sysdyn.ui.modelica.SysdynModelicaEditor"\r
default="false"\r
icon="platform:/plugin/com.famfamfam.silk/icons/page_white_text.png"\r
id="org.simantics.sysdyn.ui.modelicaEditor"\r
- name="Modelica code viewer">\r
+ name="Modelica Code Viewer">\r
</editor>\r
<editor\r
class="org.simantics.sysdyn.ui.trend.TrendEditor"\r
class="org.simantics.sysdyn.ui.project.SysdynPerspectiveFactory"\r
icon="platform:/plugin/com.famfamfam.silk/icons/chart_curve.png"\r
id="org.simantics.sysdyn.ui.perspective"\r
- name="System dynamics">\r
+ name="System Dynamics">\r
</perspective>\r
</extension>\r
<extension\r
</context>\r
<context\r
id="org.simantics.sysdyn.ui.playbackExperiment"\r
- name="Playback experiment">\r
+ name="Playback Experiment">\r
</context>\r
<context\r
id="org.simantics.sysdyn.ui.gameExperiment"\r
- name="Game experiment">\r
+ name="Game Experiment">\r
</context>\r
<context\r
id="org.simantics.sysdyn.ui.sensitivityAnalysisExperiment"\r
- name="Sensitivity analysis experiment">\r
+ name="Sensitivity Analysis Experiment">\r
</context>\r
</extension>\r
<extension\r
point="org.eclipse.ui.menus">\r
<menuContribution\r
locationURI="toolbar:org.eclipse.ui.main.toolbar">\r
+ <toolbar\r
+ id="org.simantics.sysdyn.ui.modelToolbar">\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.exportModelButton"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/disk.png"\r
+ id="org.simantics.sysdyn.ui.export.button">\r
+ </command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.exportModelAsButton"\r
+ icon="icons/save_as.png"\r
+ id="org.simantics.sysdyn.ui.exportAs.button">\r
+ </command>\r
+ </toolbar>\r
<toolbar\r
id="org.simantics.sysdyn.ui.experimentControlToolbar">\r
<command\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.saveResults"\r
- icon="platform:/plugin/com.famfamfam.silk/icons/disk.png"\r
- id="org.simantics.sysdyn.ui.save.button">\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/table_save.png"\r
+ id="org.simantics.sysdyn.ui.save.button"\r
+ label="Save Results">\r
<visibleWhen>\r
<with\r
variable="activeContexts">\r
hoverIcon="platform:/plugin/com.famfamfam.silk/icons/control_play_blue.png"\r
icon="platform:/plugin/com.famfamfam.silk/icons/control_play.png"\r
id="org.simantics.sysdyn.ui.playback.button"\r
- label="Start playback"\r
+ label="Start Playback"\r
style="pulldown"\r
tooltip="Start playback">\r
<visibleWhen>\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.saveSensitivityAnalysisResults"\r
- icon="platform:/plugin/com.famfamfam.silk/icons/disk.png"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/table_save.png"\r
id="org.simantics.sysdyn.ui.saveSensitivityAnalysis.button">\r
<visibleWhen>\r
<with\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.trend.view.png"\r
- name="Export to PNG">\r
+ name="Export To PNG">\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.trend.view.svg"\r
- name="Export to SVG">\r
+ name="Export To SVG">\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.showModule"\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.pasteSpecial"\r
- name="Paste special">\r
+ name="Paste Special">\r
</command> \r
<command\r
id="org.simantics.sysdyn.ui.removeNode"\r
<command\r
defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultActivation"\r
id="org.simantics.sysdyn.ui.activateResult"\r
- name="Show in charts">\r
+ name="Show In Charts">\r
</command>\r
<command\r
defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultSetActivation"\r
id="org.simantics.sysdyn.ui.activateResultSet"\r
- name="Show in charts">\r
+ name="Show In Charts">\r
</command>\r
<command\r
defaultHandler="org.simantics.sysdyn.ui.handlers.newComponents.NewExperimentNodeHandler"\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.exportModel"\r
- name="Export model">\r
+ name="Export Model">\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.importModel"\r
- name="Import model">\r
+ name="Import Model">\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.newEnumeration"\r
id="org.simantics.sysdyn.ui.saveSensitivityAnalysisResults"\r
name="Save Results">\r
</command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.exportModelButton"\r
+ name="Export Model">\r
+ </command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.exportModelAsButton"\r
+ name="Export Model As...">\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
<handler\r
class="org.simantics.sysdyn.ui.handlers.imports.ImportModelHandler"\r
commandId="org.simantics.sysdyn.ui.importModel">\r
+ <activeWhen></activeWhen>\r
</handler>\r
<handler\r
class="org.simantics.sysdyn.ui.handlers.exports.ExportModelHandler"\r
<activeWhen>\r
<with\r
variable="selection">\r
- <test\r
- args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
- property="org.simantics.sysdyn.ui.nodeClass">\r
- </test>\r
+ <or>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
</with>\r
</activeWhen>\r
</handler>\r
class="org.simantics.sysdyn.ui.handlers.FindReplaceHandler"\r
commandId="org.eclipse.ui.edit.findReplace">\r
</handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.exports.ExportModelAsButtonHandler"\r
+ commandId="org.simantics.sysdyn.ui.exportModelAsButton">\r
+ <activeWhen>\r
+ <or>\r
+ <with\r
+ variable="activePartId">\r
+ <equals value="org.simantics.browsing.ui.graph.propertyView"/>\r
+ </with>\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.VariableNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass2">\r
+ </test>\r
+ </with>\r
+ </or>\r
+ </activeWhen>\r
+ </handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.exports.ExportModelButtonHandler"\r
+ commandId="org.simantics.sysdyn.ui.exportModelButton">\r
+ <activeWhen>\r
+ <or>\r
+ <with\r
+ variable="activePartId">\r
+ <equals\r
+ value="org.simantics.browsing.ui.graph.propertyView">\r
+ </equals>\r
+ </with>\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.VariableNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass2">\r
+ </test>\r
+ </with>\r
+ </or>\r
+ </activeWhen>\r
+ </handler>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
properties="nodeClass"\r
type="org.eclipse.jface.viewers.IStructuredSelection">\r
</propertyTester>\r
+ <propertyTester\r
+ class="org.simantics.sysdyn.ui.browser.nodes.ExportTester"\r
+ id="org.simantics.sysdyn.ui.selectionPropertyTester"\r
+ namespace="org.simantics.sysdyn.ui"\r
+ properties="nodeClass2"\r
+ type="org.eclipse.jface.viewers.IStructuredSelection">\r
+ </propertyTester>\r
</extension>\r
<extension\r
point="org.simantics.ui.doubleClick">\r
</doubleClickAction>\r
<doubleClickAction\r
class="org.simantics.sysdyn.ui.browser.actions.ActivateResultDatasetAction"\r
- name="Activate result in charts"\r
+ name="Activate Result In Charts"\r
priority="250.0">\r
</doubleClickAction> \r
<doubleClickAction\r
class="org.simantics.sysdyn.ui.browser.actions.ActivateResultSetDatasetAction"\r
- name="Activate result in charts"\r
+ name="Activate Result In Charts"\r
priority="240.0">\r
</doubleClickAction> \r
<doubleClickAction\r
</doubleClickAction>-->\r
<doubleClickAction\r
class="org.simantics.sysdyn.ui.actions.ShowInstantiatedModuleAction"\r
- name="Show instantiated module"\r
+ name="Show Instantiated Module"\r
priority="100.0">\r
</doubleClickAction>\r
</extension>\r
<feature\r
class="org.simantics.project.features.DependencyValidationFeature:http://www.simantics.org/Sysdyn-0.0/ImportedOntologies"\r
id="org.simantics.sysdyn.dependencies"\r
- label="System Dynamics ontology dependencies">\r
+ label="System Dynamics Ontology Dependencies">\r
</feature>\r
</extension>\r
<extension\r
class="org.simantics.sysdyn.ui.wizards.mdl.ImportWizardMdl"\r
icon="platform:/plugin/com.famfamfam.silk/icons/chart_organisation.png"\r
id="org.simantics.sysdyn.ui.wizards.mdlImport"\r
- name="Import Vensim model (.mdl)">\r
+ name="Import Vensim Model (.mdl)">\r
</wizard>\r
</extension>\r
<extension\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+\r
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import java.util.Collection;\r
+\r
+import org.eclipse.core.expressions.PropertyTester;\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.IWorkbenchPage;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.DatabaseJob;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
+\r
+/**\r
+ * This class tests whether the export functionality is active\r
+ * \r
+ * @author Tuomas Miettinen\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ExportTester extends PropertyTester {\r
+\r
+ @Override\r
+ public boolean test(Object receiver, final String property, final Object[] args, final Object expectedValue) {\r
+ // Find the resource from the receiver.\r
+ Resource inputResource = ResourceAdaptionUtils.toSingleResource(receiver);\r
+ if (inputResource == null) {\r
+ @SuppressWarnings("rawtypes")\r
+ Collection<AbstractNode> a = AdaptionUtils.adaptToCollection(receiver, AbstractNode.class);\r
+ if (a.size() > 1) // Multiple selections.\r
+ return false;\r
+ if (a.size() == 1)\r
+ inputResource = (Resource)a.iterator().next().data;\r
+ }\r
+ if (inputResource == null) {\r
+ DiagramEditor editor = null;\r
+ IWorkbench workbench = PlatformUI.getWorkbench();\r
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();\r
+ // To ask for the active window doesn't work, so browse through all\r
+ // windows and when an active editor is found, use that\r
+ for (IWorkbenchWindow window : windows) {\r
+ IWorkbenchPage page = window.getActivePage();\r
+ if (page != null) {\r
+ try {\r
+ editor = (DiagramEditor)page.getActiveEditor();\r
+ if (editor != null)\r
+ // Found one\r
+ break;\r
+ } catch (ClassCastException e) {\r
+ continue;\r
+ }\r
+ }\r
+ }\r
+ if (editor != null) {\r
+ if (editor instanceof DiagramEditor) {\r
+ inputResource = editor.getInputResource();\r
+ }\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+ final Resource resource = inputResource;\r
+\r
+ Session session = SimanticsUI.peekSession();\r
+ if (session == null)\r
+ return false;\r
+\r
+ if (DatabaseJob.inProgress())\r
+ return false;\r
+\r
+ // Check if we can get the model of the resource.\r
+ try {\r
+ return session.syncRequest(new Read<Boolean>() {\r
+ @Override\r
+ public Boolean perform(ReadGraph g) throws DatabaseException {\r
+ if (g.sync(new PossibleModel(resource)) != null) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ // Purposefully not logging these exceptions, there might be way too\r
+ // many even under normal circumstances.\r
+ // TODO: add debug tracing options controlling the printing of these exceptions\r
+ return false;\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers.exports;\r
+\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.simantics.db.Resource;\r
+\r
+/**\r
+ * Exports a selected model asking the location.\r
+ * Model determination is based on any resource of the model.\r
+ * \r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class ExportModelAsButtonHandler extends ExportModelButtonHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ \r
+ final Resource model = determineModel(event);\r
+ if (model == null)\r
+ return null;\r
+ \r
+ String selected = getAbsolutePath(model, event, true);\r
+ \r
+ if (selected != null)\r
+ createFile(model, selected);\r
+ \r
+ return null;\r
+ }\r
+\r
+}\r
+\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers.exports;\r
+\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.IWorkbenchPage;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.platform.PropertyPageView;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
+\r
+/**\r
+ * Exports a selected model without asking the location.\r
+ * Model determination is based on any resource of the model.\r
+ * \r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class ExportModelButtonHandler extends ExportModelHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ \r
+ final Resource model = determineModel(event);\r
+ if (model == null)\r
+ return null;\r
+\r
+ String selected = getAbsolutePath(model, event, false);\r
+ \r
+ if (selected != null)\r
+ createFile(model, selected);\r
+ \r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected Resource determineModel(ExecutionEvent event) {\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ if (sel == null) {\r
+ // No selection, this is true e.g. in PropertyPageView\r
+ IWorkbenchPart activePart = HandlerUtil.getActivePart(event);\r
+ // In such a case get the selection the PropertyPageView point to.\r
+ if (activePart instanceof PropertyPageView)\r
+ sel = ((PropertyPageView)activePart).getLastSelection();\r
+ }\r
+ \r
+ // Get the Resource of the selection\r
+ Resource inputResource = ResourceAdaptionUtils.toSingleResource(sel);\r
+ if (inputResource == null) {\r
+ // Coner case for when export is called when some folder in model browser is selected.\r
+ if (sel instanceof IStructuredSelection) {\r
+ IStructuredSelection iss = (IStructuredSelection) sel;\r
+ if (iss.size() == 1) {\r
+ Object element = iss.getFirstElement();\r
+ AbstractNode<?> a = AdaptionUtils.adaptToSingle(element, AbstractNode.class);\r
+ if (a != null)\r
+ inputResource = (Resource)a.data;\r
+ }\r
+ }\r
+ }\r
+ \r
+ // When the selection doesn't have a resource, use the currently active diagram.\r
+ if (inputResource == null) {\r
+ DiagramEditor editor = null;\r
+ IWorkbench workbench = PlatformUI.getWorkbench();\r
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();\r
+ // To ask for the active window doesn't work, so browse through all\r
+ // windows and when an active editor is found, use that\r
+ for (IWorkbenchWindow window : windows) {\r
+ IWorkbenchPage page = window.getActivePage();\r
+ if (page != null) {\r
+ try {\r
+ editor = (DiagramEditor)page.getActiveEditor();\r
+ if (editor != null)\r
+ // Found one\r
+ break;\r
+ } catch (ClassCastException e) {\r
+ continue;\r
+ }\r
+ }\r
+ }\r
+ if (editor != null && editor instanceof DiagramEditor) {\r
+ inputResource = editor.getInputResource();\r
+ } else {\r
+ return null; \r
+ }\r
+ }\r
+ \r
+ // Now that we finally have determined which Resource is selected, we just need\r
+ // to get the model of that Resource.\r
+ Resource model;\r
+ final Resource resource = inputResource;\r
+ try {\r
+ model = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph) throws DatabaseException {\r
+ return graph.sync(new PossibleModel(resource));\r
+ }\r
+ \r
+ });\r
+ if(model == null) return null;\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ return null;\r
+ }\r
+ return model;\r
+ }\r
+ \r
+}\r
+\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;\r
import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;\r
import org.simantics.graph.db.TransferableGraphSource;\r
import org.simantics.graph.db.TransferableGraphs;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.Activator;\r
import org.simantics.sysdyn.ui.utils.imports.ImportUtilsUI;\r
import org.simantics.ui.SimanticsUI;\r
\r
/**\r
* Exports a selected model\r
+ * Model determination is based on the very Resource of the model.\r
* \r
* @author Teemu Lempinen\r
* @author Tuomas Miettinen\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
- ISelection sel = HandlerUtil.getCurrentSelection(event);\r
- final Resource model = ResourceAdaptionUtils.toSingleResource(sel);\r
- if(model == null) return null;\r
- \r
- // FIXME: Model browser doesn't change its selection even if the selected object is removed,\r
- // so you can try to export a removed model \r
- String name = null;\r
- try {\r
- name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
\r
- @Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- if (!graph.hasStatement(model, Layer0.getInstance(graph).PartOf))\r
- return null;\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- String name = graph.syncRequest(new PossibleRelatedValue<String>(model, l0.HasName, Bindings.STRING ));\r
- return name;\r
- \r
- }\r
- \r
- });\r
- } catch (DatabaseException e1) {\r
- e1.printStackTrace();\r
- }\r
- // Do not export if the resource has no name\r
- if(name == null) return null;\r
- \r
- // Find a location (and name) for the exported library using FileDialog\r
- Shell shell = HandlerUtil.getActiveShellChecked(event);\r
- FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
- fd.setText("Export Model");\r
- fd.setFileName(name);\r
- String path = Activator.getDefault().getPreferenceStore().getString(ImportUtilsUI.IMPORTMODELTPATH);\r
- if(path.isEmpty() || !(new File(path).exists()))\r
- path = Platform.getLocation().toOSString();\r
- fd.setFilterPath(path);\r
- String[] filterExt = {"*.tg"};\r
- fd.setFilterExtensions(filterExt);\r
- fd.setOverwrite(true);\r
- final String selected = fd.open();\r
- if(selected == null) return null;\r
+ final Resource model = determineModel(event);\r
+ if (model == null)\r
+ return null;\r
+ \r
+ String selected = getAbsolutePath(model, event, true);\r
+ \r
+ if (selected != null)\r
+ createFile(model, selected);\r
\r
- // Save location to preference store\r
- Activator.getDefault().getPreferenceStore().setValue(ImportUtilsUI.IMPORTMODELTPATH, (new File(selected)).getParent());\r
+ return null;\r
+ }\r
\r
+ /**\r
+ * Create the export file.\r
+ * @param model Model which is exported.\r
+ * @param fileName Full name of the file.\r
+ */\r
+ protected void createFile(final Resource model, final String fileName) {\r
+ \r
// Asynchronously create the file using transferable graph\r
SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
\r
\r
TransferableGraphSource s = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));\r
try {\r
- TransferableGraphs.writeTransferableGraph(graph, "sysdynModel", 1, s,new File(selected));\r
+ TransferableGraphs.writeTransferableGraph(graph, "sysdynModel", 1, s,new File(fileName));\r
} catch (Exception e) {\r
e.printStackTrace();\r
}\r
}\r
});\r
-\r
- return null;\r
}\r
+ \r
+ /**\r
+ * Get the model Resource based on the event.\r
+ * @param event\r
+ * @return model Resource which the event refers to.\r
+ */\r
+ protected Resource determineModel(ExecutionEvent event) {\r
+ // Just get the selected model.\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ final Resource model = ResourceAdaptionUtils.toSingleResource(sel);\r
+ return model;\r
+ }\r
+ \r
+ /**\r
+ * Get the absolute save path for the export file and save it to the database.\r
+ * @param model Model Resource which is exported.\r
+ * @param event\r
+ * @param saveAs true if save as... functionality is used; otherwise save \r
+ * functionality is used. \r
+ * @return The full path name of the exported model.\r
+ * @throws ExecutionException\r
+ */\r
+ protected String getAbsolutePath(final Resource model, ExecutionEvent event, boolean saveAs) throws ExecutionException {\r
+\r
+ // Determine the default path.\r
+ String path = null;\r
+ try {\r
+ //If the model has been exported earlier, use that path.\r
+ path = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ if (!graph.hasStatement(model, Layer0.getInstance(graph).PartOf))\r
+ return null;\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ String path = graph.syncRequest(new PossibleRelatedValue<String>(model, SR.SysdynModel_lastExportFilePath, Bindings.STRING ));\r
+ return path;\r
+ \r
+ }\r
+ \r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ // If this is the initial save:\r
+ if (path == null) {\r
+ if (saveAs == false) {\r
+ // Save == Save as... when there has been no earlier save. \r
+ return getAbsolutePath(model, event, true);\r
+ }\r
+ // Use import default path.\r
+ path = Activator.getDefault().getPreferenceStore().getString(ImportUtilsUI.IMPORTMODELTPATH);\r
+ }\r
+ if(path.isEmpty() || !(new File(path).exists()))\r
+ path = Platform.getLocation().toOSString();\r
+ \r
+ // Determine the default name\r
+ // FIXME: Model browser doesn't change its selection even if the selected object is removed,\r
+ // so you can try to export a removed model \r
+ String name = null;\r
+ try {\r
+ name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ if (!graph.hasStatement(model, Layer0.getInstance(graph).PartOf))\r
+ return null;\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ // If the model has been exported earlier, use that name.\r
+ // When mere Save has progressed here, there is always be the name in the database. \r
+ String name = graph.syncRequest(new PossibleRelatedValue<String>(model, SR.SysdynModel_lastExportFileName, Bindings.STRING ));\r
+ if (name == null) {\r
+ // If not, use the model name.\r
+ name = graph.syncRequest(new PossibleRelatedValue<String>(model, l0.HasName, Bindings.STRING ));\r
+ }\r
+ return name;\r
+ \r
+ }\r
+ \r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ // Do not export if the resource has no name\r
+ if(name == null) return null;\r
+ \r
+ final String selected;\r
+ String fullPath = null;\r
+ if (saveAs == true) {\r
+ // Find a location (and name) for the exported library using FileDialog\r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+ fd.setText("Export Model");\r
+ fd.setFileName(name);\r
+ \r
+ fd.setFilterPath(path);\r
+ String[] filterExt = {"*.tg"};\r
+ fd.setFilterExtensions(filterExt);\r
+ fd.setOverwrite(true);\r
+ fullPath = fd.open();\r
+ }\r
+ else {\r
+ // Save to the earlier location. \r
+ fullPath = path;\r
+ if (path.charAt(path.length() - 1) != '\\')\r
+ fullPath += "\\"; // Saving to C:\ would otherwise add excess backslashes.\r
+ fullPath += name;\r
+ }\r
+ selected = fullPath;\r
+ \r
+ if(selected == null) return null;\r
+\r
+ // Save location to preference store\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ graph.deny(model, SR.SysdynModel_lastExportFilePath);\r
+ graph.deny(model, SR.SysdynModel_lastExportFileName);\r
+ graph.addLiteral(model, SR.SysdynModel_lastExportFilePath, SR.SysdynModel_lastExportFilePath_Inverse, l0.String, new File(selected).getParent(), Bindings.STRING);\r
+ graph.addLiteral(model, SR.SysdynModel_lastExportFileName, SR.SysdynModel_lastExportFilePath_Inverse, l0.String, new File(selected).getName(), Bindings.STRING); \r
+ }\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ \r
+ return selected;\r
+\r
+ }\r
}\r
Resource model = null;\r
for(Object o : (ArrayList<?>)selection) {\r
Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
+ if (r == null)\r
+ continue;\r
Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
if (component != null) {\r
r = component;\r