From e053864219dffb99e054cd0f3a6c89d9713d15bf Mon Sep 17 00:00:00 2001 From: Erlend Stav <erlend.stav@sintef.no> Date: Fri, 11 May 2012 14:00:05 +0000 Subject: [PATCH] Corrected generation of package name for factory and updated println statements to provide more helpful information --- .../META-INF/MANIFEST.MF | 2 +- .../plugin.xml | 4 +++ .../handlers/TransformationHandler.java | 21 +++++++++--- .../transformations/ontUML2JavaV2.m2t | 32 +++++++++++-------- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/transformations/org.universaal.tools.transformationcommand/META-INF/MANIFEST.MF b/transformations/org.universaal.tools.transformationcommand/META-INF/MANIFEST.MF index 0d4ad84d6..df4b563d3 100644 --- a/transformations/org.universaal.tools.transformationcommand/META-INF/MANIFEST.MF +++ b/transformations/org.universaal.tools.transformationcommand/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Transformation Command Bundle-SymbolicName: org.universaal.tools.transformationcommand;singleton:=true -Bundle-Version: 0.6.5 +Bundle-Version: 0.7.0 Bundle-Vendor: universAAL Require-Bundle: org.eclipse.ui, org.eclipse.core.resources;bundle-version="3.0.0", diff --git a/transformations/org.universaal.tools.transformationcommand/plugin.xml b/transformations/org.universaal.tools.transformationcommand/plugin.xml index 74f6c85cc..7f03e318e 100644 --- a/transformations/org.universaal.tools.transformationcommand/plugin.xml +++ b/transformations/org.universaal.tools.transformationcommand/plugin.xml @@ -47,6 +47,10 @@ <handler commandId="org.universaal.tools.transformationcommand.commands.ontUML2Java" class="org.universaal.tools.transformationcommand.handlers.TransformOntUML2Java"> + </handler> + <handler + class="org.universaal.tools.transformationcommand.handlers.TransformOntUML2Java" + commandId="org.universaal.tools.transformationcommand.commands.ontUML2Java"> <activeWhen> <with variable="selection"> diff --git a/transformations/org.universaal.tools.transformationcommand/src/org/universaal/tools/transformationcommand/handlers/TransformationHandler.java b/transformations/org.universaal.tools.transformationcommand/src/org/universaal/tools/transformationcommand/handlers/TransformationHandler.java index 4dfefe486..a33f49ce7 100644 --- a/transformations/org.universaal.tools.transformationcommand/src/org/universaal/tools/transformationcommand/handlers/TransformationHandler.java +++ b/transformations/org.universaal.tools.transformationcommand/src/org/universaal/tools/transformationcommand/handlers/TransformationHandler.java @@ -75,6 +75,7 @@ public abstract class TransformationHandler extends AbstractHandler implements E private MessageConsole myConsole; private MessageConsoleStream stream; + private static final String SOURCE_FILE_SUFFIX = ".uml"; /** * Finally, I am subversive @@ -92,22 +93,34 @@ public abstract class TransformationHandler extends AbstractHandler implements E * from the application context. */ public Object execute(ExecutionEvent event) throws ExecutionException { - +//org.eclipse.ui.internal.handlers.WizardHandler // First, retrieve the current selection and check whether it is a file IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); - ISelection selection = window.getSelectionService().getSelection(); +// ISelection selection = window.getSelectionService().getSelection(); + ISelection selection = HandlerUtil.getCurrentSelection(event); + if (selection == null) + selection = window.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer"); + if (selection == null) + selection = window.getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer"); + + if ((selection != null) && (selection instanceof StructuredSelection)) { Object selectedFile = ((StructuredSelection)selection).getFirstElement(); - if (selectedFile instanceof IFile) { + if ((selectedFile instanceof IFile) && ((IFile)selectedFile).getName().endsWith(SOURCE_FILE_SUFFIX)){ // If the selection is a file, start the transformation doTransform((IFile)selectedFile, event); + } else { + MessageDialog.openInformation( + window.getShell(), + "Transformation Command", + "Please fist select a " + SOURCE_FILE_SUFFIX + " file in the package or project explorer." ); } } else { MessageDialog.openInformation( window.getShell(), "Transformation Command", - "The selection is not a valid source for transformation" ); + "Please fist select a " + SOURCE_FILE_SUFFIX + " file in the package or project explorer." ); } return null; diff --git a/transformations/org.universaal.tools.transformationcommand/transformations/ontUML2JavaV2.m2t b/transformations/org.universaal.tools.transformationcommand/transformations/ontUML2JavaV2.m2t index 23c5d0095..a9e83c4ba 100644 --- a/transformations/org.universaal.tools.transformationcommand/transformations/ontUML2JavaV2.m2t +++ b/transformations/org.universaal.tools.transformationcommand/transformations/ontUML2JavaV2.m2t @@ -53,6 +53,7 @@ texttransformation OntologyUML2JavaV2 (in uml:"http://www.eclipse.org/uml2/3.0.0 StdOut.println("WARNING!!! The owlOntology stereotype should NOW be applied to the root package(s).") StdOut.println("Remember to set all required values (defaultnamespace and name) for each package!") StdOut.println("Continuing with transformation...") + StdOut.println(""); defaultOntologyName = self.name defaultOntologyNamespace = self.getStereotypeValue("owlOntology", "defaultNamespace") @@ -71,20 +72,27 @@ texttransformation OntologyUML2JavaV2 (in uml:"http://www.eclipse.org/uml2/3.0.0 subPackageList = null if (!p.hasStereotype("owlOntology")) { - StdOut.println("WARNING!!! The model must be stereotyped with owlOntology and default namespace must be set!") - StdOut.println("To perform the transformation, add this information to the model") + StdOut.println("WARNING!!! The package " + p.name + " is not stereotyped with owlOntology!") if(defaultOntologyName==null) { - StdOut.println("It is required to set the owlOntology stereotype to ALL root package") + StdOut.println("It is required to set the owlOntology stereotype on ALL root package.") + StdOut.println("To perform the transformation, add this information to the model.") StdOut.println("Skipping package " + p.name.trim()) - break + StdOut.println(""); + break + } + else { + StdOut.println("Continuing transformation of package with information from the owlOntology sterotype of the model root.") } } //TODO: HANDLE unset packages ontologyName = p.name.substring(p.name.lastIndexOf(".")+1, p.name.size()) //get the last segment of the packagename - StdOut.println("Generating Java classes for ontology: " + ontologyName) + StdOut.println("Generating Java classes for package: " + ontologyName) ontologyNamespace = p.getStereotypeValue("owlOntology", "defaultNamespace") + if (ontologyNamespace.equals("")) { + ontologyNamespace = defaultOntologyNamespace + } StdOut.println("Namespace: "+ontologyNamespace) ontologyNamespaceReference = ontologyName + 'Ontology.NAMESPACE' @@ -92,7 +100,6 @@ texttransformation OntologyUML2JavaV2 (in uml:"http://www.eclipse.org/uml2/3.0.0 //recursively create the ontology classes and enumerations p.processOntologyPackage() subPackageList.remove(p.getFullPackageName().trim()) //remove own reference - StdOut.println("RETURNED from process main with C/E sizes:" + ontologyClassList.size() + "/" + ontologyEnumerationList.size()) //then the main ontology class and the factories for each package. StdOut.println("Handling main ontology class for :" + p.name) @@ -145,7 +152,6 @@ texttransformation OntologyUML2JavaV2 (in uml:"http://www.eclipse.org/uml2/3.0.0 self.ownedMember->forEach(subPack : uml.Package) { subPack.processOntologyPackage() } - Stdout.println("\nRETURNING from ProcessPackage with class/enums:" + ontologyClassList.size() + ", " + ontologyEnumerationList.size()) } uml.Package::generateActivator(ontNameList:Hashtable) { @@ -213,7 +219,7 @@ public class Activator implements BundleActivator { uml.Package::generateMainOntologyClass(ontologyClassList:Hashtable, ontologyEnumerationList:Hashtable) { file( javaBasePath + "/" + self.name.replace("\\.", "/") + '/' + ontologyName.firstToUpper() + "Ontology.java" ) - Stdout.println("MAIN: creating main ontology class. Should contain " + ontologyClassList.size() + " classes and " + ontologyEnumerationList.size() + " enumerations" ) + //Stdout.println("MAIN: creating main ontology class. Should contain " + ontologyClassList.size() + " classes and " + ontologyEnumerationList.size() + " enumerations" ) var importName:String importName= self.getFullPackageName() @@ -262,7 +268,7 @@ var factoryImportList: Hashtable ' //import the factory for this ontology -import ' importName.substring(0, importName.lastIndexOf(".")).replace("\\.", "/") '.' ontologyName.firstToUpper() 'Factory; +import ' importName.substring(0, importName.lastIndexOf(".")) '.' ontologyName.firstToUpper() 'Factory; /** @@ -467,7 +473,7 @@ public final class ' ontologyName.firstToUpper() 'Ontology extends Ontology { file( javaBasePath + "/" + pName.substring(0, pName.lastIndexOf(".")).replace("\\.", "/") + '/' + ontologyName.firstToUpper() + "Factory.java" ) ' -package ' pName.substring(0, pName.lastIndexOf(".")).replace("\\.", "/") '; +package ' pName.substring(0, pName.lastIndexOf(".")) '; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -581,7 +587,7 @@ public class ' ontologyName.firstToUpper() 'Factory extends ResourceFactoryImpl return self.getValue(mySType, tag) } else { - StdOut.println("The class "+self.name+" do not have the expected stereotype : " + stereotypeName) + //StdOut.println(self.name+" do not have the expected stereotype : " + stereotypeName) return "" } } @@ -1257,9 +1263,9 @@ public class ' ontologyName.firstToUpper() 'Factory extends ResourceFactoryImpl uml.Model::getImportList() { //get the imported packages self.packageImport->forEach(c : uml.PackageImport) { - stdout.println("Found imported elements: " + c.importedPackage.name + " - " + c.importedPackage.getAppliedStereotypes()) + //stdout.println("Found imported elements: " + c.importedPackage.name + " - " + c.importedPackage.getAppliedStereotypes()) if (c.importedPackage.hasStereotype("owlOntology")) { - stdout.println("Found owlOntology import. Adding import to list") + //stdout.println("Found owlOntology import. Adding import to list") //get the import name, default namespace and version to local hashtable var modelImport:Hashtable -- GitLab