+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.modelica.data;\r
\r
import java.io.InputStream;\r
\r
@Override\r
public void read(InputStream stream) {\r
+ errors.clear();\r
\r
// First line contains the variable names in format "name" (including quotes);\r
String line = getLine(stream);\r
if(line == null)\r
return;\r
\r
- // FIXME: yks elementti liikaa alusta.\r
line = line.substring(1, line.lastIndexOf("\""));\r
String[] names = line.split("\",\"");\r
\r
try {\r
valueMap.get(names[i]).add(Double.parseDouble(values[i]));\r
} catch (NumberFormatException e) {\r
- e.printStackTrace();\r
- break;\r
+ ArrayList<TimeValuePair> list = errors.get(names[i]);\r
+ if(list == null) {\r
+ list = new ArrayList<TimeValuePair>();\r
+ errors.put(names[i], list);\r
+ }\r
+ list.add(new TimeValuePair(values[0], values[i]));\r
}\r
}\r
}\r
variables.add(ds);\r
}\r
}\r
- \r
}\r
\r
List<DataSet> variables = new ArrayList<DataSet>();\r
List<DataSet> initials = new ArrayList<DataSet>();\r
+ \r
+ class TimeValuePair {\r
+ public String time;\r
+ public String value;\r
+ \r
+ public TimeValuePair(String time, String value) {\r
+ this.time = time;\r
+ this.value = value;\r
+ }\r
+ }\r
+ \r
+ HashMap<String, ArrayList<TimeValuePair>> errors = new HashMap<String, ArrayList<TimeValuePair>>();\r
\r
static String getLine(InputStream stream) {\r
if(stream == null)\r
return set;\r
return null;\r
}\r
+ \r
+ \r
+ /**\r
+ * Return errors encountered during reading of the results.\r
+ * \r
+ * @return\r
+ */\r
+ public String getResultReadErrors() {\r
+ StringBuilder errorString = new StringBuilder();\r
+ if(!errors.isEmpty()) {\r
+ errorString.append("Number format errors (Time, Value):\n");\r
+ for(String key : errors.keySet()) {\r
+ errorString.append("\n" + key + ":\n");\r
+ for(TimeValuePair tv : errors.get(key)) {\r
+ errorString.append(" " + tv.time + ", " + tv.value + "\n");\r
+ }\r
+ }\r
+ }\r
+ return errorString.toString();\r
+ }\r
}\r
</visibleWhen>\r
</command>\r
<command\r
- commandId="org.simantics.sysdyn.ui.importModuleLibrary"\r
- label="Module library"\r
+ commandId="org.simantics.sysdyn.ui.importModule"\r
+ label="Module"\r
style="push">\r
<visibleWhen\r
checkEnabled="true">\r
</visibleWhen>\r
</command>\r
<command\r
- commandId="org.simantics.sysdyn.ui.exportModuleLibrary"\r
- label="Module library"\r
+ commandId="org.simantics.sysdyn.ui.exportModule"\r
+ label="Module"\r
style="push">\r
<visibleWhen\r
checkEnabled="true">\r
</menuContribution>\r
<menuContribution\r
locationURI="popup:#ExternalFunctionFileBrowser?after=wbStart">\r
- <command\r
- commandId="org.simantics.sysdyn.ui.importExternalFunctionFile"\r
- label="Import Files"\r
- style="push">\r
- </command>\r
- <command\r
- commandId="org.simantics.sysdyn.ui.exportExternalFunctionFile"\r
- label="Export Files"\r
- style="push">\r
- </command>\r
- <command\r
- commandId="org.simantics.sysdyn.ui.removeNode"\r
- icon="icons/cross.png"\r
- id="org.simantics.sysdyn.ui.browser.remove"\r
- label="Remove"\r
- style="push">\r
- <visibleWhen\r
- checkEnabled="true">\r
- </visibleWhen>\r
- </command>\r
</menuContribution>\r
</extension>\r
<extension\r
id="org.simantics.sysdyn.ui.exportFunctionLibrary"\r
name="Export Function Library">\r
</command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.importModule"\r
+ name="Import Module">\r
+ </command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.exportModule"\r
+ name="Export Module">\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
</with>\r
</activeWhen>\r
</handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.ImportModuleHandler"\r
+ commandId="org.simantics.sysdyn.ui.importModule">\r
+ <activeWhen>\r
+ <with\r
+ variable="selection">\r
+ <or>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModulesNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
+ </with>\r
+ </activeWhen>\r
+ </handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.ExportModuleHandler"\r
+ commandId="org.simantics.sysdyn.ui.exportModule">\r
+ <activeWhen>\r
+ <with\r
+ variable="selection">\r
+ <or>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
+ </with>\r
+ </activeWhen>\r
+ </handler>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
}\r
\r
// Find model function libraries\r
- for(Resource modelLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
- new FunctionLibraryNode<Resource>(modelLibrary);\r
+ for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
+ result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
} \r
\r
Resource sysdyn = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.0");\r
parent = ((ChildVariable)v).getParent(graph);\r
if(parent != null && !(parent instanceof RunVariable) && !(parent instanceof ConfigurationVariable)) {\r
String parentURI = parent.getURI(graph);\r
- moduleName = (String) graph.getPossibleRelatedValue(graph.getResource(parentURI), l0.HasName);\r
+ Resource p = graph.getPossibleResource(parentURI);\r
+ if(p != null)\r
+ moduleName = (String) graph.getPossibleRelatedValue(p, l0.HasName);\r
}\r
break;\r
}\r
if (resources.length < 1)\r
return null;\r
\r
+ return exportFiles(shell, resources);\r
+ }\r
+ \r
+ public static Object exportFiles(Shell shell, final Resource[] resources) {\r
DirectoryDialog dd = new DirectoryDialog(shell);\r
dd.setFilterPath(Platform.getLocation().toOSString());\r
dd.setText("Export files to...");\r
\r
}\r
});\r
-\r
return null;\r
}\r
\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.MessageBox;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\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.ObjectsWithType;\r
+import org.simantics.db.common.request.ReadRequest;\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.util.TransferableGraphRequest2;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public class ExportModuleHandler extends AbstractHandler {\r
+\r
+ /**\r
+ * Temporary exception. At this phase, the system will not support exporting modules\r
+ * that depend on other modules. \r
+ * \r
+ * @author TLTEEMU\r
+ *\r
+ */\r
+ class ContainsDependenciesException extends DatabaseException {\r
+ private static final long serialVersionUID = -1533706136673146020L;\r
+ \r
+ private Collection<String> dependencies;\r
+ \r
+ ContainsDependenciesException(Collection<String> dependencies) {\r
+ this.dependencies = dependencies;\r
+ }\r
+ \r
+ public Collection<String> getDependencies() {\r
+ return this.dependencies;\r
+ }\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ final Resource modulesymbol = ResourceAdaptionUtils.toSingleResource(sel);\r
+ if(modulesymbol == null) return null;\r
+ \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
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
+ if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf))\r
+ return null;\r
+ \r
+ Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
+ if (configuration == null)\r
+ return null;\r
+ \r
+ ArrayList<String> dependencies = null;\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) {\r
+ if(dependencies == null)\r
+ dependencies = new ArrayList<String>();\r
+ String name = NameUtils.getSafeName(graph, r);\r
+ String instanceOf = NameUtils.getSafeName(graph, graph.getSingleObject(r, l0.InstanceOf));\r
+ dependencies.add(name + " : " + instanceOf);\r
+ }\r
+ if(dependencies != null && !dependencies.isEmpty())\r
+ throw new ContainsDependenciesException(dependencies);\r
+ \r
+ String name = graph.getPossibleRelatedValue(component, l0.HasName, Bindings.STRING);\r
+ return name;\r
+ \r
+ }\r
+ \r
+ });\r
+ } catch (ContainsDependenciesException e1) {\r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ MessageBox mb = new MessageBox(shell, SWT.OK);\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("This version does not support exporting modules with other module instances.\n\n");\r
+ sb.append("Dependencies:\n");\r
+ for(String s : e1.getDependencies())\r
+ sb.append(" " + s + "\n");\r
+ mb.setMessage(sb.toString());\r
+ mb.setText("Module contains dependencies.");\r
+ mb.open();\r
+ return null;\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ if(name == null) return null;\r
+ \r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+ fd.setText("Export..");\r
+ fd.setFileName(name);\r
+ fd.setFilterPath(Platform.getLocation().toOSString());\r
+ String[] filterExt = {"*.tg"};\r
+ fd.setFilterExtensions(filterExt);\r
+ final String selected = fd.open();\r
+ if(selected == null) return null;\r
+ \r
+ \r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+\r
+ final Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
+ if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf))\r
+ return;\r
+ String name = graph.syncRequest(new PossibleRelatedValue<String>(component, l0.HasName, Bindings.STRING ));\r
+ final ArrayList<Pair<Resource, String>> roots = new ArrayList<Pair<Resource, String>>();\r
+ roots.add(Pair.make(component, name));\r
+\r
+ graph.asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+\r
+ Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
+ if (!graph.hasStatement(configuration, l0.PartOf, component)&& \r
+ !graph.hasStatement(modulesymbol, l0.PartOf, component)) {\r
+ // Make sure that configuration and symbol are included.\r
+ // In old versions, they were attached to model, not to module.\r
+ Resource previousPartof = graph.getSingleObject(configuration, l0.PartOf);\r
+\r
+ graph.deny(configuration, l0.PartOf);\r
+ graph.deny(modulesymbol, l0.PartOf);\r
+ graph.claim(configuration, l0.PartOf, l0.ConsistsOf, component);\r
+ graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, component);\r
+\r
+ export(graph, selected, roots, component);\r
+\r
+ graph.deny(configuration, l0.PartOf);\r
+ graph.deny(modulesymbol, l0.PartOf);\r
+ graph.claim(configuration, l0.PartOf, l0.ConsistsOf, previousPartof);\r
+ graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, previousPartof);\r
+ } else {\r
+ // Normal export\r
+ export(graph, selected, roots, component);\r
+ }\r
+ }\r
+ });\r
+\r
+ }\r
+ });\r
+\r
+ return null;\r
+ }\r
+ \r
+ /**\r
+ * Export module (without dependencies to other modules) and write it to file. \r
+ * Disable existing enumeration replacement for during export. \r
+ * \r
+ * @param graph WriteGraph\r
+ * @param path Path for the exported file\r
+ * @param roots\r
+ * @param component Module\r
+ */\r
+ private void export(WriteGraph graph, String path, ArrayList<Pair<Resource, String>> roots, Resource component) {\r
+ \r
+ // FIXME: Enumeration replacement handling like this is not suitable.\r
+ try {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+\r
+ Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
+ ArrayList<Pair<Resource, Resource>> replacements = new ArrayList<Pair<Resource, Resource>>();\r
+\r
+ for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
+ if(graph.hasStatement(enumeration, sr.ReplacedEnumeration_Inverse)) {\r
+ for(Resource replacement : graph.getObjects(enumeration, sr.ReplacedEnumeration_Inverse)) {\r
+ replacements.add(new Pair<Resource, Resource>(enumeration, replacement));\r
+ }\r
+ }\r
+ }\r
+ \r
+ for(Pair<Resource,Resource> replacement : replacements)\r
+ graph.deny(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second);\r
+ \r
+ TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component));\r
+ Files.createFile(new File(path), Bindings.getBindingUnchecked(TransferableGraph1.class), tg);\r
+ \r
+ for(Pair<Resource,Resource> replacement : replacements)\r
+ graph.claim(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second);\r
+\r
+ } catch (RuntimeBindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+}
\ No newline at end of file
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
public class ImportFunctionLibrary extends AbstractHandler {\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
- Resource project = SimanticsUI.getProject().get();\r
- if(project == null) return null;\r
-\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
- final Resource functionLibrary = ResourceAdaptionUtils.toSingleResource(sel);\r
- if(functionLibrary == null) return null;\r
+ Resource r = ResourceAdaptionUtils.toSingleResource(sel);\r
+ if(r == null) {\r
+ FunctionsFolder mn = AdaptionUtils.adaptToSingle(sel, FunctionsFolder.class);\r
+ r = mn.data;\r
+ }\r
+ if(r == null) return null;\r
+ \r
+ final Resource functionLibrary = r;\r
\r
Shell shell = HandlerUtil.getActiveShellChecked(event);\r
FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
+import org.simantics.graph.db.MissingDependencyException;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+public class ImportModuleHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+\r
+ final Resource model = node.data;\r
+ \r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
+ fd.setText("Import Module");\r
+ fd.setFilterPath(Platform.getLocation().toOSString());\r
+ String[] filterExt = {"*.tg"};\r
+ fd.setFilterExtensions(filterExt);\r
+ String selected = fd.open();\r
+ if(selected == null) return null;\r
+\r
+ TransferableGraph1 tg = null;\r
+ try {\r
+ tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
+ } catch (RuntimeBindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ if(tg == null) return null;\r
+\r
+ \r
+ DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model);\r
+ try {\r
+ DefaultPasteHandler.defaultExecute(tg, model, ia);\r
+ } catch (MissingDependencyException e) {\r
+ e.printStackTrace();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ return null;\r
+ }\r
+\r
+}\r
Resource configuration = GraphUtils.create2(g, \r
sr.Configuration,\r
l0.HasName, name + "Configuration",\r
- l0.PartOf, model);\r
+ l0.PartOf, moduleType);\r
\r
g.claim(moduleType, sr2.IsDefinedBy , configuration);\r
\r
\r
Resource moduleSymbol = g.newResource();\r
g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol");\r
- g.claimLiteral(moduleSymbol, l0.HasLabel, name);\r
+ g.claimLiteral(moduleSymbol, l0.HasLabel, name + " Symbol");\r
g.claim(moduleSymbol, l0.Inherits, sr.ModuleSymbol);\r
g.claim(moduleSymbol, mr.SymbolToComponentType, moduleType);\r
- g.claim(moduleSymbol, l0.PartOf, model);\r
+ g.claim(moduleSymbol, l0.PartOf, moduleType);\r
\r
Resource terminal = g.newResource();\r
g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal);\r
return null;\r
}\r
\r
- private void deleteItem(final Resource[] resources) {\r
+ public static void deleteItem(final Resource[] resources) {\r
try {\r
SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
@Override\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.properties;\r
\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Control;\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.swt.widgets.Tree;\r
import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
import org.simantics.browsing.ui.swt.widgets.Button;\r
import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.ui.handlers.ExportExternalFunctionFilesHandler;\r
import org.simantics.sysdyn.ui.handlers.ImportExternalFunctionFilesHandler;\r
+import org.simantics.sysdyn.ui.handlers.RemoveNodeHandler;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.ArrayMap;\r
import org.simantics.utils.datastructures.Pair;\r
public class ExternalFilesTab extends LabelPropertyTabContributor implements Widget {\r
\r
GraphExplorerComposite externalFilesExplorer;\r
- Button importButton; \r
+ Button importButton, exportButton, removeButton; \r
\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site,\r
if (c instanceof Tree)\r
((Tree) c).setLinesVisible(true);\r
\r
- importButton = new Button(composite, support, SWT.NONE);\r
+ \r
+ Composite buttonRow = new Composite(composite, SWT.NONE);\r
+ GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonRow);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonRow);\r
+ \r
+ importButton = new Button(buttonRow, support, SWT.NONE);\r
importButton.setText("Import");\r
importButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
final Pair<String, String[]> importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS);\r
\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- \r
+\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles);\r
});\r
}\r
});\r
- \r
- \r
+\r
+\r
+ }\r
+ });\r
+\r
+ exportButton = new Button(buttonRow, support, SWT.NONE);\r
+ exportButton.setText("Export");\r
+ exportButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, final Resource input)\r
+ throws DatabaseException {\r
+\r
+ exportButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ Shell shell = exportButton.getWidget().getShell();\r
+ List<Resource> resourceList = getSelectedResources(externalFilesExplorer);\r
+ Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+ if (resources.length > 0)\r
+ ExportExternalFunctionFilesHandler.exportFiles(shell, resources);\r
+ }\r
+ });\r
+\r
+\r
+ }\r
+ });\r
+\r
+ removeButton = new Button(buttonRow, support, SWT.NONE);\r
+ removeButton.setText("Remove");\r
+ removeButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, final Resource input)\r
+ throws DatabaseException {\r
+\r
+ removeButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ Shell shell = removeButton.getWidget().getShell();\r
+\r
+ List<Resource> resourceList = getSelectedResources(externalFilesExplorer);\r
+ Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+ if(resources.length > 0) {\r
+ MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0,\r
+ new String[] { "OK", "Cancel" }, 0);\r
+ dialog.create();\r
+ if (dialog.open() == 0) {\r
+ RemoveNodeHandler.deleteItem(resources);\r
+ }\r
+ }\r
+ }\r
+ });\r
+\r
+\r
}\r
});\r
- \r
}\r
\r
@Override\r
externalFilesExplorer.setInput(context, input);\r
}\r
\r
+ private List<Resource> getSelectedResources(GraphExplorerComposite explorer) {\r
+ List<Resource> result = new ArrayList<Resource>();\r
+ \r
+ ISelection selection = ((ISelectionProvider) explorer\r
+ .getAdapter(ISelectionProvider.class)).getSelection();\r
+ if (selection == null)\r
+ return result;\r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ @SuppressWarnings("unchecked")\r
+ List<AdaptableHintContext> selections = iss.toList();\r
+ for(AdaptableHintContext ahc : selections) {\r
+ Resource resource = (Resource) ahc.getAdapter(Resource.class);\r
+ result.add(resource);\r
+ }\r
+ return result;\r
+ }\r
\r
}\r
Frame frame;\r
ChartPanel panel;\r
SysdynDatasets sysdynDatasets = new SysdynDatasets();\r
-\r
+ SysdynDatasetSelectionListener sysdynDatasetSelectionListener;\r
\r
@SuppressWarnings("serial")\r
class SysdynDatasets extends AbstractXYDataset {\r
\r
});\r
\r
- getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new SysdynDatasetSelectionListener() {\r
+ sysdynDatasetSelectionListener = new SysdynDatasetSelectionListener() {\r
\r
@Override\r
protected void selectionChanged(final Collection<SysdynDataSet> activeDatasets) {\r
\r
});\r
}\r
- });\r
+ };\r
+ \r
+ getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(sysdynDatasetSelectionListener);\r
\r
}\r
+ \r
+ @Override\r
+ public void dispose() {\r
+ super.dispose();\r
+ getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(sysdynDatasetSelectionListener);\r
+ }\r
\r
@Override\r
public void setFocus() {\r
this.modelResource = modelResource;\r
}\r
\r
- public synchronized void simulate(IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException {\r
+ public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException {\r
canceled = false;\r
progressMonitor.subTask("Write modelica classes");\r
ModelicaWriter writer = new ModelicaWriter();\r
resultChanged();\r
\r
setExperimentStopped(experiment);\r
+ \r
+ String errorString = result.getResultReadErrors();\r
+ if(errorString != null && !errorString.isEmpty()) \r
+ monitor.message(errorString);\r
}\r
} catch (FileNotFoundException e) {\r
e.printStackTrace();\r
public void resultChanged() {\r
synchronized(resultListeners) {\r
for(Runnable listener : resultListeners) {\r
+ System.out.println("Run resultListener");\r
listener.run();\r
}\r
}\r
/**\r
* Returns the declaration of a module with possible redeclared enumerations\r
* \r
- * Module m(redeclare type E1 = enumeration(i1, i2, i3), redeclare type E2 = enumeration(i4, i5, i6));\r
+ * Module m(redeclared.size = enumeration.size, redeclared.elements = enumeration.elements);\r
* \r
* @return Declaration of a module instance\r
*/\r