-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from eMoflon/rkluge-dev
Results of Hacker Day 2018-08
- Loading branch information
Showing
65 changed files
with
3,019 additions
and
918 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.settings/ | ||
/bin | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.moflon.core.ui.packageregistration</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
15 changes: 15 additions & 0 deletions
15
org.moflon.core.ui.packageregistration/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: org.moflon.core.ui.packageregistration | ||
Bundle-SymbolicName: org.moflon.core.ui.packageregistration;singleton:=true | ||
Bundle-Version: 1.0.0.qualifier | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
Require-Bundle: org.eclipse.emf.ecore;bundle-version="2.11.0", | ||
org.eclipse.core.resources, | ||
org.eclipse.equinox.registry, | ||
org.apache.log4j, | ||
org.eclipse.jface, | ||
org.eclipse.ui.workbench, | ||
org.eclipse.emf.ecore.xmi, | ||
org.moflon.core.ui | ||
Bundle-Vendor: eMoflon Developers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
plugin.xml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?eclipse version="3.0"?> | ||
<plugin> | ||
<extension point="org.eclipse.ui.commands"> | ||
<command | ||
defaultHandler="org.moflon.core.ui.packageregistration.RegisterMetamodelHandler" | ||
id="org.moflon.ide.ui.commands.emf.RegisterMetamodelCommand" | ||
name="Register the selected metamodel in the global EMF registry"/> | ||
</extension> | ||
<extension point="org.eclipse.ui.menus"> | ||
<menuContribution allPopups="false" locationURI="popup:org.moflon.ide.ui.moflon?after=moflonGroupResources"> | ||
<command | ||
commandId="org.moflon.ide.ui.commands.emf.RegisterMetamodelCommand" | ||
label="Register metamodel globally" | ||
style="push" | ||
tooltip="Register the selected metamodel in the global EMF registry" | ||
icon="icons/register.png"> | ||
<visibleWhen checkEnabled="false"> | ||
<iterate ifEmpty="false" operator="and"> | ||
<reference definitionId="org.moflon.ide.ui.definitions.isEcoreFile"/> | ||
<or> | ||
<reference definitionId="org.moflon.ide.ui.definitions.isInPackageExplorer"/> | ||
<reference definitionId="org.moflon.ide.ui.definitions.isInProjectExplorer"/> | ||
</or> | ||
</iterate> | ||
</visibleWhen> | ||
</command> | ||
</menuContribution> | ||
</extension> | ||
</plugin> |
166 changes: 166 additions & 0 deletions
166
...ui.packageregistration/src/org/moflon/core/ui/packageregistration/EmfRegistryManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008 The University of York. | ||
* 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: | ||
* Dimitrios Kolovos - initial API and implementation | ||
******************************************************************************/ | ||
package org.moflon.core.ui.packageregistration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.EDataType; | ||
import org.eclipse.emf.ecore.EEnum; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EPackage; | ||
import org.eclipse.emf.ecore.EcorePackage; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
|
||
/** | ||
* This class allows to register and manage EMF metamodels | ||
* | ||
* @author Roland Kluge - Initial implementation | ||
* | ||
*/ | ||
public class EmfRegistryManager { | ||
private static EmfRegistryManager instance = null; | ||
|
||
private HashMap<String, List<EPackage>> managedMetamodels = new HashMap<>(); | ||
|
||
public static EmfRegistryManager getInstance() { | ||
if (instance == null) { | ||
instance = new EmfRegistryManager(); | ||
} | ||
return instance; | ||
} | ||
|
||
public void registerMetamodel(String fileName) throws Exception { | ||
List<EPackage> ePackages = register(URI.createPlatformResourceURI(fileName, true), EPackage.Registry.INSTANCE); | ||
managedMetamodels.put(fileName, ePackages); | ||
} | ||
|
||
// The following methods are taken from org.eclipse.epsilon.emc.emf.EmfUtil | ||
|
||
public static List<EPackage> register(URI uri, EPackage.Registry registry) throws Exception { | ||
return register(uri, registry, true); | ||
} | ||
|
||
/** | ||
* Register all the packages in the metamodel specified by the uri in the | ||
* registry. | ||
* | ||
* @param uri | ||
* The URI of the metamodel | ||
* @param registry | ||
* The registry in which the metamodel's packages are registered | ||
* @param useUriForResource | ||
* If True, the URI of the resource created for the metamodel would | ||
* be overwritten with the URI of the last EPackage in the metamodel. | ||
* @return A list of the EPackages registered. | ||
* @throws Exception | ||
* If there is an error accessing the resources. | ||
*/ | ||
public static List<EPackage> register(URI uri, EPackage.Registry registry, boolean useUriForResource) | ||
throws Exception { | ||
|
||
List<EPackage> ePackages = new ArrayList<EPackage>(); | ||
|
||
initialiseResourceFactoryRegistry(); | ||
|
||
ResourceSet resourceSet = new ResourceSetImpl(); | ||
resourceSet.getPackageRegistry().put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE); | ||
|
||
Resource metamodel = resourceSet.createResource(uri); | ||
metamodel.load(Collections.EMPTY_MAP); | ||
|
||
setDataTypesInstanceClasses(metamodel); | ||
|
||
Iterator<EObject> it = metamodel.getAllContents(); | ||
while (it.hasNext()) { | ||
Object next = it.next(); | ||
if (next instanceof EPackage) { | ||
EPackage p = (EPackage) next; | ||
|
||
adjustNsAndPrefix(metamodel, p, useUriForResource); | ||
registry.put(p.getNsURI(), p); | ||
ePackages.add(p); | ||
} | ||
} | ||
|
||
return ePackages; | ||
|
||
} | ||
|
||
private static void initialiseResourceFactoryRegistry() { | ||
final Map<String, Object> etfm = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
|
||
if (!etfm.containsKey("*")) { | ||
etfm.put("*", new XMIResourceFactoryImpl()); | ||
} | ||
|
||
} | ||
|
||
private static void adjustNsAndPrefix(Resource metamodel, EPackage p, boolean useUriForResource) { | ||
if (p.getNsURI() == null || p.getNsURI().trim().length() == 0) { | ||
if (p.getESuperPackage() == null) { | ||
p.setNsURI(p.getName()); | ||
} else { | ||
p.setNsURI(p.getESuperPackage().getNsURI() + "/" + p.getName()); | ||
} | ||
} | ||
|
||
if (p.getNsPrefix() == null || p.getNsPrefix().trim().length() == 0) { | ||
if (p.getESuperPackage() != null) { | ||
if (p.getESuperPackage().getNsPrefix() != null) { | ||
p.setNsPrefix(p.getESuperPackage().getNsPrefix() + "." + p.getName()); | ||
} else { | ||
p.setNsPrefix(p.getName()); | ||
} | ||
} | ||
} | ||
|
||
if (p.getNsPrefix() == null) | ||
p.setNsPrefix(p.getName()); | ||
if (useUriForResource) | ||
metamodel.setURI(URI.createURI(p.getNsURI())); | ||
} | ||
|
||
protected static void setDataTypesInstanceClasses(Resource metamodel) { | ||
Iterator<EObject> it = metamodel.getAllContents(); | ||
while (it.hasNext()) { | ||
EObject eObject = (EObject) it.next(); | ||
if (eObject instanceof EEnum) { | ||
// ((EEnum) eObject).setInstanceClassName("java.lang.Integer"); | ||
} else if (eObject instanceof EDataType) { | ||
EDataType eDataType = (EDataType) eObject; | ||
String instanceClass = ""; | ||
if (eDataType.getName().equals("String")) { | ||
instanceClass = "java.lang.String"; | ||
} else if (eDataType.getName().equals("Boolean")) { | ||
instanceClass = "java.lang.Boolean"; | ||
} else if (eDataType.getName().equals("Integer")) { | ||
instanceClass = "java.lang.Integer"; | ||
} else if (eDataType.getName().equals("Float")) { | ||
instanceClass = "java.lang.Float"; | ||
} else if (eDataType.getName().equals("Double")) { | ||
instanceClass = "java.lang.Double"; | ||
} | ||
if (instanceClass.trim().length() > 0) { | ||
eDataType.setInstanceClassName(instanceClass); | ||
} | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...kageregistration/src/org/moflon/core/ui/packageregistration/RegisterMetamodelHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008 The University of York. | ||
* 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: | ||
* Dimitrios Kolovos - initial API and implementation | ||
******************************************************************************/ | ||
package org.moflon.core.ui.packageregistration; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.eclipse.core.commands.ExecutionEvent; | ||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.jface.viewers.IStructuredSelection; | ||
import org.eclipse.ui.handlers.HandlerUtil; | ||
import org.moflon.core.ui.AbstractCommandHandler; | ||
|
||
/** | ||
* This class provides the front-end capabilities for registering an EMF model. | ||
* | ||
* @author Roland Kluge - Initial implementation | ||
* | ||
*/ | ||
public class RegisterMetamodelHandler extends AbstractCommandHandler { | ||
|
||
@Override | ||
public Object execute(final ExecutionEvent event) throws ExecutionException { | ||
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); | ||
|
||
if (selection instanceof IStructuredSelection) { | ||
final IStructuredSelection structuredSelection = (IStructuredSelection) selection; | ||
final Iterator<?> it = structuredSelection.iterator(); | ||
while (it.hasNext()) { | ||
final IFile file = (IFile) it.next(); | ||
registerMetamodelInFile(file); | ||
} | ||
} | ||
|
||
return AbstractCommandHandler.DEFAULT_HANDLER_RESULT; | ||
} | ||
|
||
private void registerMetamodelInFile(final IFile file) { | ||
final String fileName = file.getFullPath().toOSString(); | ||
try { | ||
EmfRegistryManager.getInstance().registerMetamodel(fileName); | ||
logger.info("Metamodel " + fileName + " registered successfully"); | ||
} catch (final Exception ex) { | ||
logger.info("Metamodel " + fileName + " could not be registered", ex); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.