From ac6a654fd8461808777b52b126f7f60d6544996d Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 8 Nov 2011 12:51:09 +0000 Subject: [PATCH] Refactoring handlers package. The package contained too many handlers. Added comments to all refactored files. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23229 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 36 ++--- .../ui/handlers/ImportModuleHandler.java | 135 ---------------- .../ExportExternalFunctionFilesHandler.java | 21 ++- .../{ => exports}/ExportFunctionLibrary.java | 13 +- .../{ => exports}/ExportModelHandler.java | 13 +- .../{ => exports}/ExportModuleHandler.java | 19 ++- .../ImportExternalFunctionFilesHandler.java | 27 +++- .../{ => imports}/ImportFunctionLibrary.java | 37 ++++- .../{ => imports}/ImportMdlHandler.java | 10 +- .../{ => imports}/ImportModelHandler.java | 20 ++- .../handlers/imports/ImportModuleHandler.java | 145 ++++++++++++++++++ .../NewEnumerationNodeHandler.java | 21 ++- .../NewExperimentNodeHandler.java | 23 ++- .../NewFunctionHandler.java | 12 +- .../NewFunctionLibraryHandler.java | 8 +- .../{ => newComponents}/NewModelHandler.java | 20 ++- .../NewModuleNodeHandler.java | 12 +- .../NewPlaybackExperimentNodeHandler.java | 9 +- .../NewSharedFunctionLibraryHandler.java | 8 +- .../NewSpreadSheetHandler.java | 21 ++- .../ui/properties/ExternalFilesTab.java | 19 ++- .../models/WizardModelsImportPage.java | 2 +- 22 files changed, 444 insertions(+), 187 deletions(-) delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => exports}/ExportExternalFunctionFilesHandler.java (82%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => exports}/ExportFunctionLibrary.java (89%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => exports}/ExportModelHandler.java (88%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => exports}/ExportModuleHandler.java (91%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => imports}/ImportExternalFunctionFilesHandler.java (82%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => imports}/ImportFunctionLibrary.java (83%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => imports}/ImportMdlHandler.java (88%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => imports}/ImportModelHandler.java (91%) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewEnumerationNodeHandler.java (72%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewExperimentNodeHandler.java (81%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewFunctionHandler.java (87%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewFunctionLibraryHandler.java (93%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewModelHandler.java (63%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewModuleNodeHandler.java (94%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewPlaybackExperimentNodeHandler.java (92%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewSharedFunctionLibraryHandler.java (88%) rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/{ => newComponents}/NewSpreadSheetHandler.java (58%) diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 2fa55a78..33696445 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -787,7 +787,7 @@ @@ -816,7 +816,7 @@ name="Show in charts"> @@ -837,7 +837,7 @@ name="Import .mdl"> @@ -1043,11 +1043,11 @@ diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java deleted file mode 100644 index acbfc95a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.MessageBox; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.browsing.ui.common.node.AbstractNode; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; -import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; -import org.simantics.graph.db.MissingDependencyException; -import org.simantics.graph.representation.TransferableGraph1; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.Activator; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; - -public class ImportModuleHandler extends AbstractHandler { - - public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH"; - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - ISelection sel = HandlerUtil.getCurrentSelection(event); - - @SuppressWarnings("unchecked") - AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); - if (node == null) - return null; - - final Resource model = node.data; - - final Shell shell = HandlerUtil.getActiveShellChecked(event); - FileDialog fd = new FileDialog(shell, SWT.OPEN); - fd.setText("Import Module"); - - String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODULETPATH); - if(path.isEmpty() || !(new File(path).exists())) - path = Platform.getLocation().toOSString(); - fd.setFilterPath(path); - String[] filterExt = {"*.tg"}; - fd.setFilterExtensions(filterExt); - String selected = fd.open(); - if(selected == null) return null; - - Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(selected)).getParent()); - - TransferableGraph1 tg = null; - try { - tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); - } catch (RuntimeBindingConstructionException e) { - e.printStackTrace(); - } catch (IOException e) { - MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); - mb.setText("Error"); - mb.setMessage("The imported file is not of type: Module Type"); - mb.open(); - return null; - } - if(tg == null) return null; - - - DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model); - try { - DefaultPasteHandler.defaultExecute(tg, model, ia); - } catch (MissingDependencyException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - - final Resource root = ia.getRoot(); - - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) { - Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); - String type = "..."; - if(instanceOf != null) - type = NameUtils.getSafeName(graph, instanceOf); - else { - Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); - if(inheritedFrom != null) - type = NameUtils.getSafeName(graph, inheritedFrom); - } - final String ft = type; - graph.deny(root, Layer0.getInstance(graph).PartOf); - - shell.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); - mb.setText("Error"); - mb.setMessage("The imported file is not of type: System Dynamics Module (" + ft +")"); - mb.open(); - } - }); - } - } - }); - return null; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportExternalFunctionFilesHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportExternalFunctionFilesHandler.java similarity index 82% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportExternalFunctionFilesHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportExternalFunctionFilesHandler.java index 727bb8be..53b012c5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportExternalFunctionFilesHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportExternalFunctionFilesHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.exports; import java.io.FileOutputStream; import java.io.IOException; @@ -32,12 +32,17 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; +/** + * Exports external function files from SysdynModelicaFunctions + * + * @author Teemu Lempinen + * + */ public class ExportExternalFunctionFilesHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - - + // Find shell and resources to be exported Shell shell = HandlerUtil.getActiveShellChecked(event); ISelection sel = HandlerUtil.getCurrentSelection(event); final Resource[] resources = ResourceAdaptionUtils.toResources(sel); @@ -47,7 +52,16 @@ public class ExportExternalFunctionFilesHandler extends AbstractHandler { return exportFiles(shell, resources); } + /** + * Exports selected file resources to files on disk. Assumes all resources are external files. + * + * @param shell SWT Shell + * @param resources External file resources + * @return null + */ public static Object exportFiles(Shell shell, final Resource[] resources) { + + // Select a path where to export the files DirectoryDialog dd = new DirectoryDialog(shell); dd.setFilterPath(Platform.getLocation().toOSString()); dd.setText("Export files to..."); @@ -62,6 +76,7 @@ public class ExportExternalFunctionFilesHandler extends AbstractHandler { @Override public void run(ReadGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); + // Get byte arrays from each resource and write them to disk for(Resource r : resources) { try { String name = NameUtils.getSafeName(graph, r); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java similarity index 89% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java index 38054f78..0b65cfd8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportFunctionLibrary.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.exports; import java.io.File; import java.io.IOException; @@ -37,10 +37,17 @@ import org.simantics.db.request.Read; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.handlers.imports.ImportFunctionLibrary; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.utils.datastructures.Pair; +/** + * Exports a function library + * + * @author Teemu Lempinen + * + */ public class ExportFunctionLibrary extends AbstractHandler { @Override @@ -68,8 +75,10 @@ public class ExportFunctionLibrary extends AbstractHandler { } catch (DatabaseException e1) { e1.printStackTrace(); } + // Do not export if the resource has no name if(name == null) return null; + // Find a location (and name) for the exported library using FileDialog Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.SAVE); fd.setText("Export Function Library"); @@ -83,8 +92,10 @@ public class ExportFunctionLibrary extends AbstractHandler { final String selected = fd.open(); if(selected == null) return null; + // Save location to preference store Activator.getDefault().getPreferenceStore().setValue(ImportFunctionLibrary.IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent()); + // Asynchronously create the file using transferable graph SimanticsUI.getSession().asyncRequest(new ReadRequest() { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java similarity index 88% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java index f4e007df..2c58e90c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.exports; import java.io.File; import java.io.IOException; @@ -37,10 +37,17 @@ import org.simantics.db.request.Read; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.handlers.imports.ImportModelHandler; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.utils.datastructures.Pair; +/** + * Exports a selected model + * + * @author Teemu Lempinen + * + */ public class ExportModelHandler extends AbstractHandler { @Override @@ -69,8 +76,10 @@ public class ExportModelHandler extends AbstractHandler { } catch (DatabaseException e1) { e1.printStackTrace(); } + // Do not export if the resource has no name if(name == null) return null; + // Find a location (and name) for the exported library using FileDialog Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.SAVE); fd.setText("Export Model"); @@ -84,8 +93,10 @@ public class ExportModelHandler extends AbstractHandler { final String selected = fd.open(); if(selected == null) return null; + // Save location to preference store Activator.getDefault().getPreferenceStore().setValue(ImportModelHandler.IMPORTMODELTPATH, (new File(selected)).getParent()); + // Asynchronously create the file using transferable graph SimanticsUI.getSession().asyncRequest(new ReadRequest() { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java similarity index 91% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java index 88bb8d8f..ab804371 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.exports; import java.io.File; import java.io.IOException; @@ -46,17 +46,23 @@ import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.handlers.imports.ImportModuleHandler; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.utils.datastructures.Pair; -public class ExportModuleHandler extends AbstractHandler { +/** + * Exports a selected module + * @author Teemu Lempinen + * + */ +public class ExportModuleHandler extends AbstractHandler { /** * Temporary exception. At this phase, the system will not support exporting modules * that depend on other modules. * - * @author TLTEEMU + * @author Teemu Lempinen * */ class ContainsDependenciesException extends DatabaseException { @@ -92,6 +98,7 @@ public class ExportModuleHandler extends AbstractHandler { SysdynResource sr = SysdynResource.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); + // Start checking for module dependencies Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType); if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf)) return null; @@ -110,6 +117,7 @@ public class ExportModuleHandler extends AbstractHandler { } if(dependencies != null && !dependencies.isEmpty()) throw new ContainsDependenciesException(dependencies); + // End checking for module dependencies. If dependencies were found, an exception was thrown String name = graph.getPossibleRelatedValue(component, l0.HasName, Bindings.STRING); return name; @@ -132,8 +140,11 @@ public class ExportModuleHandler extends AbstractHandler { } catch (DatabaseException e1) { e1.printStackTrace(); } + + // Do not export if the resource has no name if(name == null) return null; + // Find a location (and name) for the exported library using FileDialog Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.SAVE); fd.setText("Export Module"); @@ -147,8 +158,10 @@ public class ExportModuleHandler extends AbstractHandler { final String selected = fd.open(); if(selected == null) return null; + // Save location to preference store Activator.getDefault().getPreferenceStore().setValue(ImportModuleHandler.IMPORTMODULETPATH, (new File(selected)).getParent()); + // Asynchronously create the file using transferable graph SimanticsUI.getSession().asyncRequest(new ReadRequest() { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportExternalFunctionFilesHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportExternalFunctionFilesHandler.java similarity index 82% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportExternalFunctionFilesHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportExternalFunctionFilesHandler.java index 21158257..f0052c6d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportExternalFunctionFilesHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportExternalFunctionFilesHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.imports; import java.io.File; import java.io.FileInputStream; @@ -35,6 +35,12 @@ import org.simantics.sysdyn.manager.FunctionUtils; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Pair; +/** + * Imports external functions to SysdynModelicaFunctions using FileDialog. + * + * @author Teemu Lempinen + * + */ public class ImportExternalFunctionFilesHandler extends AbstractHandler { public static final String[] C_EXTENSIONS = {"*.c","*.h","*.a","*.o"}; @@ -56,10 +62,12 @@ public class ImportExternalFunctionFilesHandler extends AbstractHandler { } /** - * Import - * - * @param shell - * @return + * Opens a {@link FileDialog} to select the imported files. + * + * @param shell SWT Shell + * @param text Header text for the FileDialog + * @param filter Filters for the FileDialog + * @return File names and paths for the files to be imported */ public static Pair importFiles(Shell shell, String text, String[] filter) { FileDialog fd = new FileDialog(shell, SWT.OPEN); @@ -70,6 +78,15 @@ public class ImportExternalFunctionFilesHandler extends AbstractHandler { return new Pair(fd.getFilterPath(), fd.getFileNames()); } + + /** + * Saves the given files as byte arrays to a function + * + * @param graph WriteGraph + * @param function Function where the files are to be added + * @param files Files to be added + * @throws DatabaseException + */ public static void addFilesToFunction(WriteGraph graph, Resource function, Pair files) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java similarity index 83% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java index 4730432c..b20206c4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.imports; import java.io.File; import java.io.IOException; @@ -50,10 +50,18 @@ import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; import org.simantics.ui.utils.ResourceAdaptionUtils; +/** + * Imports an exported function library (or shared function library) transferable graph. + * @author Teemu Lempinen + * + */ public class ImportFunctionLibrary extends AbstractHandler { public static String IMPORTFUNCTIONLIBRARYPATH = "IMPORT_FUNCTION_LIBRARY_PATH"; + /** + * Called from a functions folder node + */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection sel = HandlerUtil.getCurrentSelection(event); @@ -66,6 +74,8 @@ public class ImportFunctionLibrary extends AbstractHandler { final Resource functionLibrary = r; + + // Get a transferable graph file final Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Import Function Library"); @@ -81,6 +91,7 @@ public class ImportFunctionLibrary extends AbstractHandler { Activator.getDefault().getPreferenceStore().setValue(IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent()); + // Load the transferable graph TransferableGraph1 tg = null; try { tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); @@ -96,7 +107,7 @@ public class ImportFunctionLibrary extends AbstractHandler { } if(tg == null) return null; - + // Make sure the "http://SharedOntologies resource exists try { Boolean hasSharedOntologies; hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read() { @@ -131,6 +142,7 @@ public class ImportFunctionLibrary extends AbstractHandler { } + // Import a function library from the transferable graph SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(functionLibrary); try { DefaultPasteHandler.defaultExecute(tg, functionLibrary, ia); @@ -138,19 +150,26 @@ public class ImportFunctionLibrary extends AbstractHandler { e.printStackTrace(); } - final Resource root = ia.getRoot(); + final Resource root = ia.getRoot(); // Root of the library + // Link the imported library to the selected resource (functionLibrary) SimanticsUI.getSession().asyncRequest(new WriteRequest() { + /** + * Link the imported library to the selected resource (functionLibrary) + * The imported library can be either SysdynModelicaFunctionLibrary or SysdynFunctionOntology + */ @Override public void perform(WriteGraph graph) throws DatabaseException { Layer0 l0 = Layer0.getInstance(graph); + // Case: SharedFunctionOntology. Link to SharedOntologies if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) { Resource library = graph.getResource("http://SharedOntologies"); if(!graph.hasStatement(library, l0.ConsistsOf, root)) { graph.claim(library, l0.ConsistsOf, root); } + // Link model to the shared library SysdynResource sr = SysdynResource.getInstance(graph); Resource model = functionLibrary; while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology)) @@ -159,6 +178,7 @@ public class ImportFunctionLibrary extends AbstractHandler { graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root); } + // Case: not SharedFunctionOntology or SysdynModelicaFunctionLibrary. } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) { Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf); String type = "..."; @@ -170,8 +190,11 @@ public class ImportFunctionLibrary extends AbstractHandler { type = NameUtils.getSafeName(graph, inheritedFrom); } final String ft = type; + + // Remove the functionLibrary ConsistsOf root relation graph.deny(root, l0.PartOf); + // Display error message shell.getDisplay().asyncExec(new Runnable() { @Override @@ -183,6 +206,7 @@ public class ImportFunctionLibrary extends AbstractHandler { } }); } else { + // imported library is already in the right place. Update function library files. FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary); } @@ -191,6 +215,12 @@ public class ImportFunctionLibrary extends AbstractHandler { return null; } + /** + * Import advisor for importing function libraries to SysDyn + * + * @author Teemu Lempinen + * + */ private class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor { public SysdynFunctionLibraryImportAdvisor(Resource library) { @@ -199,6 +229,7 @@ public class ImportFunctionLibrary extends AbstractHandler { @Override public void analyzeType(ReadGraph graph, Root root) throws DatabaseException { + // Change the library to http://SharedOntologies, if the imported library is of type SharedFunctionOntology if(root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) { try { library = graph.getResource("http://SharedOntologies"); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java similarity index 88% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java index 156ab7bc..2ce39ec6 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportMdlHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.imports; import java.io.File; @@ -30,6 +30,12 @@ import org.simantics.sysdyn.mdlImport.mdlElements.Model; import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; +/** + * Class for importing Vensim models (.mdl) to Simantics SysDyn using MdlParser + * + * @author Teemu Lempinen + * + */ public class ImportMdlHandler extends AbstractHandler { public static String IMPORTMDLTPATH = "IMPORT_MDL_PATH"; @@ -40,6 +46,7 @@ public class ImportMdlHandler extends AbstractHandler { final Resource project = SimanticsUI.getProject().get(); if(project == null) return null; + // Get the .mdl file Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Import .mdl"); @@ -57,6 +64,7 @@ public class ImportMdlHandler extends AbstractHandler { Activator.getDefault().getPreferenceStore().setValue(IMPORTMDLTPATH, (new File(selected)).getParent()); + // Convert Vensim model to Simantics SysDyn format using MdlParser final Model model = MdlParser.parse(file); SimanticsUI.getSession().asyncRequest(new WriteRequest() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java similarity index 91% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java index 0bf887a3..ccecf5bb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.imports; import java.io.File; import java.io.IOException; @@ -50,6 +50,12 @@ import org.simantics.sysdyn.ui.utils.OldTransferableGraph1; import org.simantics.sysdyn.ui.utils.SheetUtils; import org.simantics.ui.SimanticsUI; +/** + * Imports models from exported transferable graph files. + * + * @author Teemu Lempinen + * + */ public class ImportModelHandler extends AbstractHandler { public static String IMPORTMODELTPATH = "IMPORT_MODEL_PATH"; @@ -60,6 +66,7 @@ public class ImportModelHandler extends AbstractHandler { Resource project = SimanticsUI.getProject().get(); if(project == null) return null; + // Get imported transferable graph file using FileDialog final Shell shell = HandlerUtil.getActiveShellChecked(event); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Import Model"); @@ -75,7 +82,7 @@ public class ImportModelHandler extends AbstractHandler { Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(selected)).getParent()); - + // Get the transferable graph from file TransferableGraph1 tg = null; try { tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); @@ -83,6 +90,7 @@ public class ImportModelHandler extends AbstractHandler { e.printStackTrace(); } catch (IOException e) { try { + // "Version migration". Use OldTransferableGraph1 if the file was imported using old methods OldTransferableGraph1 otg = (OldTransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(OldTransferableGraph1.class)); tg = new TransferableGraph1(otg.resourceCount, otg.identities, otg.statements, otg.values); } catch (RuntimeBindingConstructionException e1) { @@ -112,6 +120,7 @@ public class ImportModelHandler extends AbstractHandler { public void perform(WriteGraph graph) throws DatabaseException { if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModel)) { + // Imported model was not a SysdynModel, display error message. Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); String type = "..."; if(instanceOf != null) @@ -140,6 +149,7 @@ public class ImportModelHandler extends AbstractHandler { Resource project = SimanticsUI.getProject().get(); graph.claim(root, Layer0X.getInstance(graph).IsActivatedBy, project); + // Do all modifications that are necessary updateOldConfigurationToBaseRealization(graph, root); addDefaultOntologyLinks(graph, root); addURIsToDiagrams(graph, root); @@ -197,6 +207,12 @@ public class ImportModelHandler extends AbstractHandler { } + /** + * Add a container for providing URIs to diagrams. + * + * @param graph WriteGraph + * @param model Imported model + */ private static void addURIsToDiagrams(WriteGraph graph, Resource model) { Layer0 l0 = Layer0.getInstance(graph); SimulationResource simu = SimulationResource.getInstance(graph); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java new file mode 100644 index 00000000..9a0cfceb --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.imports; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.graph.db.MissingDependencyException; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Imports modules from exported transferable graph files. + * + * @author Teemu Lempinen + * + */ +public class ImportModuleHandler extends AbstractHandler { + + public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + + @SuppressWarnings("unchecked") + AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); + if (node == null) + return null; + + final Resource model = node.data; + + // Get imported transferable graph file using FileDialog + final Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText("Import Module"); + + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODULETPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.tg"}; + fd.setFilterExtensions(filterExt); + String selected = fd.open(); + if(selected == null) return null; + + Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(selected)).getParent()); + + // Get the transferable graph from file + TransferableGraph1 tg = null; + try { + tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Module Type"); + mb.open(); + return null; + } + if(tg == null) return null; + + + // Import the module to model + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model); + try { + DefaultPasteHandler.defaultExecute(tg, model, ia); + } catch (MissingDependencyException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + final Resource root = ia.getRoot(); + + // Check that the imported file actually was a module. Display error message otherwise. + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) { + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(root, Layer0.getInstance(graph).PartOf); + + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: System Dynamics Module (" + ft +")"); + mb.open(); + } + }); + } + } + }); + return null; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java similarity index 72% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java index 49b3f023..fbd774ff 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java @@ -1,4 +1,15 @@ -package org.simantics.sysdyn.ui.handlers; +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -19,6 +30,12 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; +/** + * Creates a new Enumeration node to a configuration or module + * + * @author Teemu Lempinen + * + */ public class NewEnumerationNodeHandler extends AbstractHandler { @Override @@ -35,6 +52,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler { SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); + // Find the actual configuration. Possible cases for resource are sr.Configuration, sr.ModuleSymbol or sr.Module. Resource configuration = null; if(g.isInstanceOf(resource, sr.Configuration)) { configuration = resource; @@ -50,6 +68,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler { } } + // Create the enumeartion Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes); String name = NameUtils.findFreshName(g, "Enum", configuration, l0.ConsistsOf, "%s%d"); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewExperimentNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java similarity index 81% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewExperimentNodeHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java index 0d854f02..f8e1f331 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewExperimentNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -30,8 +30,17 @@ import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; +/** + * Creates a new normal SysDyn experiment + * + * @author Teemu Lempinen + * + */ public class NewExperimentNodeHandler extends AbstractHandler { + /** + * Assumes that it is called from a node that has a SysDyn model as its resource. + */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection sel = HandlerUtil.getCurrentSelection(event); @@ -71,10 +80,22 @@ public class NewExperimentNodeHandler extends AbstractHandler { } + /** + * Get the type of this experiment. + * + * @param g ReadGraph + * @return The type resource of this experiment + */ protected Resource getExperimentType(ReadGraph g) { return SysdynResource.getInstance(g).BasicExperiment; } + /** + * Returns the suggested name for this experiment. + * If the name has already been taken, appropriate prefix needs to be added. + * + * @return Suggested name for this experiment. + */ protected String getNameSuggestion() { return "Experiment"; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewFunctionHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java similarity index 87% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewFunctionHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java index 881281f0..a9a970db 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewFunctionHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -29,8 +29,17 @@ import org.simantics.sysdyn.manager.FunctionUtils; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; +/** + * Creates a new function to a SysdynModel or Library. + * + * @author Teemu Lempinen + * + */ public class NewFunctionHandler extends AbstractHandler { + /** + * Assumes to be called from a node with SysdynModel, Library or SysdynModelicaFunction as its resource + */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { @@ -50,6 +59,7 @@ public class NewFunctionHandler extends AbstractHandler { Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); + // Library can be either SysdynModel or L0.Library. Resource library = null; if(g.isInstanceOf(data, sr.SysdynModel) || g.isInstanceOf(data, l0.Library)) library = data; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewFunctionLibraryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java similarity index 93% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewFunctionLibraryHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java index 3465aa12..98f40231 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewFunctionLibraryHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -30,6 +30,12 @@ import org.simantics.sysdyn.manager.FunctionUtils; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; +/** + * Creates a new function library to a model or other library. + * + * @author Teemu Lempinen + * + */ public class NewFunctionLibraryHandler extends AbstractHandler { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java similarity index 63% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java index 90778d94..393d5ae8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java @@ -1,4 +1,15 @@ -package org.simantics.sysdyn.ui.handlers; +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -14,6 +25,12 @@ import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.utils.ModelUtils; import org.simantics.ui.SimanticsUI; +/** + * Creates a new SysDyn model. + * + * @author Teemu Lempinen + * + */ public class NewModelHandler extends AbstractHandler { @Override @@ -27,6 +44,7 @@ public class NewModelHandler extends AbstractHandler { SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { + // Use ModelUtils to keep all model creations up-to-date ModelUtils.createModel(graph); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java similarity index 94% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java index 4478bae7..441bef3c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -35,8 +35,17 @@ import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; import org.simantics.utils.datastructures.ArrayMap; +/** + * Creates a new module node for a model. + * + * @author Teemu Lempinen + * + */ public class NewModuleNodeHandler extends AbstractHandler { + /** + * Assumes to be called from a node that has a SysDyn model as its resource. + */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { @@ -52,7 +61,6 @@ public class NewModuleNodeHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { - // Same as in SysdynProject.java. Should use the same code, not copy. SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); Layer0X L0X = Layer0X.getInstance(g); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewPlaybackExperimentNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPlaybackExperimentNodeHandler.java similarity index 92% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewPlaybackExperimentNodeHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPlaybackExperimentNodeHandler.java index 9eb53798..a54ce36f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewPlaybackExperimentNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPlaybackExperimentNodeHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.newComponents; import java.awt.Color; @@ -21,7 +21,12 @@ import org.simantics.diagram.stubs.G2DResource; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; - +/** + * Creates a new playback experiment. + * + * @author Teemu Lempinen + * + */ public class NewPlaybackExperimentNodeHandler extends NewExperimentNodeHandler { protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSharedFunctionLibraryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSharedFunctionLibraryHandler.java similarity index 88% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSharedFunctionLibraryHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSharedFunctionLibraryHandler.java index 83ab3442..5eba69cd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSharedFunctionLibraryHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSharedFunctionLibraryHandler.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -19,6 +19,12 @@ import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.db.Resource; import org.simantics.ui.utils.AdaptionUtils; +/** + * Creates a new shared function library. + * + * @author Teemu Lempinen + * + */ public class NewSharedFunctionLibraryHandler extends NewFunctionLibraryHandler { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSpreadSheetHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java similarity index 58% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSpreadSheetHandler.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java index 3f467ea5..16c6a3da 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSpreadSheetHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java @@ -1,4 +1,15 @@ -package org.simantics.sysdyn.ui.handlers; +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -13,8 +24,16 @@ import org.simantics.sysdyn.ui.utils.SheetUtils; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; +/** + * Creates a new spreadsheet sheet to a book. + * @author Teemu Lempinen + * + */ public class NewSpreadSheetHandler extends AbstractHandler { + /** + * Called from a node that has a book as its resource. + */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection sel = HandlerUtil.getCurrentSelection(event); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java index 88c72a6f..47ba4e84 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java @@ -39,13 +39,19 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.handlers.ExportExternalFunctionFilesHandler; -import org.simantics.sysdyn.ui.handlers.ImportExternalFunctionFilesHandler; import org.simantics.sysdyn.ui.handlers.RemoveNodeHandler; +import org.simantics.sysdyn.ui.handlers.exports.ExportExternalFunctionFilesHandler; +import org.simantics.sysdyn.ui.handlers.imports.ImportExternalFunctionFilesHandler; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; import org.simantics.utils.datastructures.Pair; +/** + * Tab for properties of a SysdynModelicaFunction containing all external files added to that function + * + * @author Teemu Lempinen + * + */ public class ExternalFilesTab extends LabelPropertyTabContributor implements Widget { GraphExplorerComposite externalFilesExplorer; @@ -59,7 +65,8 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid Composite composite = new Composite(body, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); - + + // Create the graph explorer displaying external files externalFilesExplorer = new GraphExplorerComposite(ArrayMap.keys( "displaySelectors", "displayFilter").values(false, false), site, composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI); @@ -79,6 +86,7 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid ((Tree) c).setLinesVisible(true); + // Create controls for importing, exporting and removing external files Composite buttonRow = new Composite(composite, SWT.NONE); GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonRow); GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonRow); @@ -174,6 +182,11 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid externalFilesExplorer.setInput(context, input); } + /** + * Method for retreiving selected resources from a GraphExplorerComposite + * @param explorer + * @return + */ private List getSelectedResources(GraphExplorerComposite explorer) { List result = new ArrayList(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java index e778d60c..39a6487f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java @@ -43,7 +43,7 @@ import org.simantics.spreadsheet.resource.SpreadsheetResource; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; -import org.simantics.sysdyn.ui.handlers.ImportModelHandler; +import org.simantics.sysdyn.ui.handlers.imports.ImportModelHandler; import org.simantics.sysdyn.ui.utils.OldTransferableGraph1; import org.simantics.ui.SimanticsUI; -- 2.47.1