From 060eb997d57cd6a37c99f6f593ace5b669ee3db5 Mon Sep 17 00:00:00 2001 From: Luca Cristoforetti <cristofo@fbk.eu> Date: Tue, 21 Aug 2018 18:19:13 +0200 Subject: [PATCH] Moved a command to a different plugin, small edits. --- .../commands/FMEAXSapHandler.java | 16 ++++--- .../commands/FTAXSapHandler.java | 15 ++++--- .../META-INF/MANIFEST.MF | 5 +-- .../plugin.xml | 15 ------- .../META-INF/MANIFEST.MF | 4 +- .../org.polarsys.chess.smvExporter/plugin.xml | 32 ++++++++++++++ .../ExportModelToMonolithicSMVCommand.java | 44 ++++++++++++++++--- 7 files changed, 92 insertions(+), 39 deletions(-) rename plugins/{contracts/org.polarsys.chess.contracts.verificationService/src/org/polarsys/chess/verificationService => org.polarsys.chess.smvExporter/src/org/polarsys/chess/smvExporter}/ui/commands/ExportModelToMonolithicSMVCommand.java (77%) diff --git a/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FMEAXSapHandler.java b/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FMEAXSapHandler.java index f13ab563c..3baba67d9 100644 --- a/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FMEAXSapHandler.java +++ b/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FMEAXSapHandler.java @@ -48,15 +48,15 @@ public class FMEAXSapHandler extends AbstractHandler { * @param smvFileName the name of the generated file * @return false if errors occurred, true otherwise */ - private Boolean createMonolithicSMVFile(String smvFileName) { - final String monolithicSmvCommand = "org.polarsys.chess.verificationService.commands.ExportModelToSMVCommand"; + private Boolean createMonolithicSmvFile(String smvFileName) { + final String monolithicSmvCommand = "org.polarsys.chess.smvExport.commands.ExportModelToSMVCommand"; final String fileNameParam = "file_name"; - final CommandBuilder modelCheckingCommand; + final CommandBuilder monolithicSmv; try { - modelCheckingCommand = CommandBuilder.build(monolithicSmvCommand); - modelCheckingCommand.setParameter(fileNameParam, smvFileName); - modelCheckingCommand.execute(); + monolithicSmv = CommandBuilder.build(monolithicSmvCommand); + monolithicSmv.setParameter(fileNameParam, smvFileName); + monolithicSmv.execute(); } catch (ExecutionException e) { return false; } catch (Exception e) { @@ -114,7 +114,7 @@ public class FMEAXSapHandler extends AbstractHandler { final String fmeaFileName = fileNamesService.computeFmeaFileName(editor, modelName); // Generate a monolithic SMV file - if (!createMonolithicSMVFile(smvFileName)){ + if (!createMonolithicSmvFile(smvFileName)){ return null; }; @@ -129,6 +129,8 @@ public class FMEAXSapHandler extends AbstractHandler { FMEAGenerationDialogUtil fmeaGenerationDialogUtil = FMEAGenerationDialogUtil.getInstance(); + //TODO: il risultato va visualizzato in una tabella! + fmeaGenerationDialogUtil.showMessage_FmeaGenerationDone(fmeaFileName); return null; } diff --git a/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FTAXSapHandler.java b/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FTAXSapHandler.java index b3091054f..8f3344cc1 100644 --- a/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FTAXSapHandler.java +++ b/plugins/contracts/org.polarsys.chess.contracts.transformations/src/org/polarsys/chess/contracts/transformations/commands/FTAXSapHandler.java @@ -42,20 +42,21 @@ public class FTAXSapHandler extends AbstractHandler { private String systemQN; private String ftaCond; + //TODO: spostare questo comando in un service, dentro SVMExporter? /** * Creates a monolithic SMV file for the active package. * @param smvFileName the name of the generated file * @return false if errors occurred, true otherwise */ - private Boolean createMonolithicSMVFile(String smvFileName) { - final String monolithicSmvCommand = "org.polarsys.chess.verificationService.commands.ExportModelToSMVCommand"; + private Boolean createMonolithicSmvFile(String smvFileName) { + final String monolithicSmvCommand = "org.polarsys.chess.smvExport.commands.ExportModelToSMVCommand"; final String fileNameParam = "file_name"; - final CommandBuilder modelCheckingCommand; + final CommandBuilder monolithicSmv; try { - modelCheckingCommand = CommandBuilder.build(monolithicSmvCommand); - modelCheckingCommand.setParameter(fileNameParam, smvFileName); - modelCheckingCommand.execute(); + monolithicSmv = CommandBuilder.build(monolithicSmvCommand); + monolithicSmv.setParameter(fileNameParam, smvFileName); + monolithicSmv.execute(); } catch (ExecutionException e) { return false; } catch (Exception e) { @@ -113,7 +114,7 @@ public class FTAXSapHandler extends AbstractHandler { final String ftFileName = fileNamesService.computeFtFileName(editor, modelName); // Generate a monolithic SMV file - if (!createMonolithicSMVFile(smvFileName)){ + if (!createMonolithicSmvFile(smvFileName)){ return null; }; diff --git a/plugins/contracts/org.polarsys.chess.contracts.verificationService/META-INF/MANIFEST.MF b/plugins/contracts/org.polarsys.chess.contracts.verificationService/META-INF/MANIFEST.MF index a96c5d324..c84d8a117 100644 --- a/plugins/contracts/org.polarsys.chess.contracts.verificationService/META-INF/MANIFEST.MF +++ b/plugins/contracts/org.polarsys.chess.contracts.verificationService/META-INF/MANIFEST.MF @@ -20,10 +20,7 @@ Require-Bundle: org.eclipse.core.resources, org.polarsys.chess.core, org.polarsys.chess.smvExporter, org.polarsys.chess.service, - eu.fbk.eclipse.standardtools.xtextService, - org.eclipse.uml2.uml, - org.polarsys.chess.contracts.transformations, - org.eclipse.papyrus.editor + eu.fbk.eclipse.standardtools.xtextService Import-Package: eu.fbk.eclipse.standardtools.nuXmvService.ui.dialogs, eu.fbk.eclipse.standardtools.nuXmvService.ui.services, eu.fbk.eclipse.standardtools.nuXmvService.ui.utils, diff --git a/plugins/contracts/org.polarsys.chess.contracts.verificationService/plugin.xml b/plugins/contracts/org.polarsys.chess.contracts.verificationService/plugin.xml index 413abc4c6..4a254fd8c 100644 --- a/plugins/contracts/org.polarsys.chess.contracts.verificationService/plugin.xml +++ b/plugins/contracts/org.polarsys.chess.contracts.verificationService/plugin.xml @@ -119,11 +119,6 @@ commandId="org.polarsys.chess.verificationService.commands.ExportModelToFileCommand" style="push"> </command> - <command - commandId="org.polarsys.chess.verificationService.commands.ExportModelToSMVCommand" - label="Export model to a monolithic SMV file" - style="push"> - </command> </menu> <menu id="org.eclipse.ui.main.menu.CHESS.validation" @@ -324,15 +319,5 @@ id="org.polarsys.chess.verificationService.ui.commands.CheckValidationAssertionPropertyCommand" name="Check Validation on Properties on selected component"> </command> - <command - defaultHandler="org.polarsys.chess.verificationService.ui.commands.ExportModelToMonolithicSMVCommand" - id="org.polarsys.chess.verificationService.commands.ExportModelToSMVCommand" - name="Export model as monolithic SMV file"> - <commandParameter - id="file_name" - name="FileName" - optional="true"> - </commandParameter> - </command> </extension> </plugin> diff --git a/plugins/org.polarsys.chess.smvExporter/META-INF/MANIFEST.MF b/plugins/org.polarsys.chess.smvExporter/META-INF/MANIFEST.MF index ddef2cffb..1713a0726 100644 --- a/plugins/org.polarsys.chess.smvExporter/META-INF/MANIFEST.MF +++ b/plugins/org.polarsys.chess.smvExporter/META-INF/MANIFEST.MF @@ -14,6 +14,8 @@ Require-Bundle: org.eclipse.papyrus.infra.gmfdiag.common, org.eclipse.papyrus.uml.tools, org.eclipse.core.resources, org.polarsys.chess.core, - org.eclipse.papyrus.cdo.core + org.eclipse.papyrus.cdo.core, + eu.fbk.eclipse.standardtools.nuXmvService, + eu.fbk.eclipse.standardtools.ExecOcraCommands Import-Package: org.apache.log4j Export-Package: org.polarsys.chess.smvExporter.ui.services diff --git a/plugins/org.polarsys.chess.smvExporter/plugin.xml b/plugins/org.polarsys.chess.smvExporter/plugin.xml index 5bfe6b885..d99171ef5 100644 --- a/plugins/org.polarsys.chess.smvExporter/plugin.xml +++ b/plugins/org.polarsys.chess.smvExporter/plugin.xml @@ -13,12 +13,27 @@ id="org.polarsys.chess.smvExport.commands.ExportSelectedNominalSMsToSmvFilesCommand" name="Export state machines of selected component or its sub-components as .smv files"> </command> + <command + defaultHandler="org.polarsys.chess.smvExporter.ui.commands.ExportModelToMonolithicSMVCommand" + id="org.polarsys.chess.smvExport.commands.ExportModelToSMVCommand" + name="Export model as monolithic SMV file"> + <commandParameter + id="file_name" + name="FileName" + optional="true"> + </commandParameter> + </command> </extension> <extension point="org.eclipse.ui.menus"> <menuContribution allPopups="false" locationURI="menu:org.eclipse.ui.main.menu.CHESS.basicOperation"> + <command + commandId="org.polarsys.chess.smvExport.commands.ExportModelToSMVCommand" + label="Export model to a monolithic SMV file" + style="push"> + </command> <command commandId="org.polarsys.chess.smvExport.commands.ExportNominalSMsToSmvFilesCommand" style="push"> @@ -34,6 +49,23 @@ commandId="org.polarsys.chess.smvExport.commands.ExportSelectedNominalSMsToSmvFilesCommand" style="push"> </command> + <command + commandId="org.polarsys.chess.smvExport.commands.ExportModelToSMVCommand" + style="push"> + <visibleWhen + checkEnabled="false"> + <iterate + ifEmpty="false" + operator="and"> + <adapt + type="org.eclipse.emf.ecore.EObject"> + <instanceof + value="org.eclipse.uml2.uml.Package"> + </instanceof> + </adapt> + </iterate> + </visibleWhen> + </command> </menu> </menuContribution> </extension> diff --git a/plugins/contracts/org.polarsys.chess.contracts.verificationService/src/org/polarsys/chess/verificationService/ui/commands/ExportModelToMonolithicSMVCommand.java b/plugins/org.polarsys.chess.smvExporter/src/org/polarsys/chess/smvExporter/ui/commands/ExportModelToMonolithicSMVCommand.java similarity index 77% rename from plugins/contracts/org.polarsys.chess.contracts.verificationService/src/org/polarsys/chess/verificationService/ui/commands/ExportModelToMonolithicSMVCommand.java rename to plugins/org.polarsys.chess.smvExporter/src/org/polarsys/chess/smvExporter/ui/commands/ExportModelToMonolithicSMVCommand.java index b93d65724..8230cba70 100644 --- a/plugins/contracts/org.polarsys.chess.contracts.verificationService/src/org/polarsys/chess/verificationService/ui/commands/ExportModelToMonolithicSMVCommand.java +++ b/plugins/org.polarsys.chess.smvExporter/src/org/polarsys/chess/smvExporter/ui/commands/ExportModelToMonolithicSMVCommand.java @@ -8,7 +8,7 @@ * Contributors: * Luca Cristoforetti - initial API and implementation ******************************************************************************/ -package org.polarsys.chess.verificationService.ui.commands; +package org.polarsys.chess.smvExporter.ui.commands; import java.util.HashMap; import org.apache.log4j.Logger; @@ -17,6 +17,8 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Package; @@ -48,6 +50,7 @@ public class ExportModelToMonolithicSMVCommand extends AbstractJobCommand { private OCRAExecService ocraExecService = OCRAExecService.getInstance(ChessSystemModel.getInstance()); private boolean isProgrExec; private Class umlSelectedComponent; + private Package pkg; private boolean showPopups; private boolean usexTextValidation; private String smvFileDirectory; @@ -61,17 +64,46 @@ public class ExportModelToMonolithicSMVCommand extends AbstractJobCommand { super("Monolithic SMV file generation"); } + /** + * Returns the selected package, if any. + * @param event the event + * @return the selected package + * @throws NoComponentException + */ + private Package getPackageFromSelectedObject(ExecutionEvent event) throws NoComponentException { + + ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection(); + + logger.debug("current selection: " + selection); + + Object selectedUmlElement = selectionUtil.getUmlSelectedObject(selection); + + logger.debug("selectedUmlElement: "+selectedUmlElement); + + if (selectedUmlElement instanceof Package) { + return (Package) selectedUmlElement; + } + + throw new NoComponentException(); + } + @Override public void execPreJobOperations(ExecutionEvent event, IProgressMonitor monitor) throws Exception { try { umlSelectedComponent = selectionUtil.getUmlComponentFromSelectedObject(event); } catch (NoComponentException e) { - DialogUtil.getInstance().showMessage_ExceptionError(e); - throw new ExecutionException(e.getMessage()); + try { + pkg = getPackageFromSelectedObject(event); + } catch (NoComponentException ex) { + DialogUtil.getInstance().showMessage_ExceptionError(ex); + throw new ExecutionException(ex.getMessage()); + } } - final Package pkg = umlSelectedComponent.getNearestPackage(); + if (pkg == null) { + pkg = umlSelectedComponent.getNearestPackage(); + } umlSelectedComponent = null; @@ -117,7 +149,9 @@ public class ExportModelToMonolithicSMVCommand extends AbstractJobCommand { ocraExecService.createMonolithicSMV(umlSelectedComponent, umlSelectedResource, smvPathComponentNameMap, isDiscreteTime, usexTextValidation, showPopups, ossFilePath, smvMapFilepath, monolithicSMVFilePath, isProgrExec, monitor); - logger.debug("createMonolithicSMV done"); + logger.debug("createMonolithicSMV done"); + + //TODO: aggiungere un messaggio opzionale di export finito } @Override -- GitLab