Skip to content
Snippets Groups Projects
Commit 66c3323c authored by nullsub's avatar nullsub
Browse files

Merge branch 'feature-editpolicy' of https://github.com/Eden-06/FRaMED-2.0 into feature-editpolicy

parents ae451d02 94358062
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<featureModel chosenLayoutAlgorithm="4">
<featureModel>
<properties/>
<struct>
<and abstract="true" mandatory="true" name="RML_Feature_Model">
<and abstract="true" mandatory="true" name="Role_Types">
<description>
</description>
<or abstract="true" name="Role_Structure">
<feature mandatory="true" name="Role_Properties"/>
<feature mandatory="true" name="Role_Behavior"/>
<feature mandatory="true" name="Role_Inheritance"/>
<feature name="Role_Properties"/>
<feature name="Role_Behavior"/>
<feature name="Role_Inheritance"/>
</or>
<and abstract="true" mandatory="true" name="Playable">
<and abstract="true" mandatory="true" name="Players">
......@@ -20,31 +18,31 @@
</and>
</and>
<or abstract="true" name="Dependent">
<feature mandatory="true" name="On_Compartments"/>
<feature mandatory="true" name="On_Relationships"/>
<feature name="On_Compartments"/>
<feature name="On_Relationships"/>
</or>
<or abstract="true" name="Role_Constraints">
<feature mandatory="true" name="Role_Implication"/>
<feature mandatory="true" name="Role_Prohibition"/>
<feature mandatory="true" name="Role_Equivalence"/>
<feature mandatory="true" name="Group_Constraints"/>
<feature mandatory="true" name="Occurrence_Constraints"/>
<feature name="Role_Implication"/>
<feature name="Role_Prohibition"/>
<feature name="Role_Equivalence"/>
<feature name="Group_Constraints"/>
<feature name="Occurrence_Constraints"/>
</or>
</and>
<and name="Relationships">
<or abstract="true" name="Relationship_Constraints">
<feature mandatory="true" name="Relationship_Cardinality"/>
<and mandatory="true" name="Intra_Relationship_Constraints">
<feature name="Relationship_Cardinality"/>
<and name="Intra_Relationship_Constraints">
<feature name="Parthood_Constraints"/>
</and>
<feature mandatory="true" name="Inter_Relationship_Constraints"/>
<feature name="Inter_Relationship_Constraints"/>
</or>
</and>
<and name="Compartment_Types">
<or abstract="true" name="Compartment_Structure">
<feature mandatory="true" name="Compartment_Properties"/>
<feature mandatory="true" name="Compartment_Behavior"/>
<feature mandatory="true" name="Compartment_Inheritance"/>
<feature name="Compartment_Properties"/>
<feature name="Compartment_Behavior"/>
<feature name="Compartment_Inheritance"/>
</or>
<and abstract="true" mandatory="true" name="Participants">
<feature name="Contains_Compartments"/>
......@@ -105,6 +103,12 @@
<var>Roles</var>
</eq>
</rule>
<rule>
<imp>
<var>Playable_by_Defining_Compartment</var>
<var>Compartments</var>
</imp>
</rule>
</constraints>
<calculations Auto="true" Constraints="true" Features="true" Redundant="true" Tautology="true"/>
<comments/>
......
......@@ -5,6 +5,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileAlreadyExistsException;
......@@ -83,7 +84,7 @@ public class TransformationExecutor extends EpsilonStandalone {
URL epsilonFolderURL = TransformationBundle.getEntry("epsilon");
File epsilonFolder = null;
try {
epsilonFolder = new File(FileLocator.resolve(epsilonFolderURL).toURI());
epsilonFolder = new File(resolveURL(FileLocator.resolve(epsilonFolderURL)));
} catch (URISyntaxException | IOException e1) { e1.printStackTrace(); };
if(epsilonFolder == null) {
System.err.println("No folder 'epsilon' found");
......@@ -104,7 +105,7 @@ public class TransformationExecutor extends EpsilonStandalone {
!packageETLFilesMarkedAsNotUsed(url.toString(), "modules/")) {
//(a)
try {
etlFile = new File(FileLocator.resolve(url).toURI());
etlFile = new File(resolveURL(FileLocator.resolve(url)));
} catch (URISyntaxException | IOException e) { e.printStackTrace(); }
try {
try {
......@@ -125,7 +126,7 @@ public class TransformationExecutor extends EpsilonStandalone {
!packageETLFilesMarkedAsNotUsed(url.toString(), "core/")) {
//(a)
try {
etlFile = new File(FileLocator.resolve(url).toURI());
etlFile = new File(resolveURL(FileLocator.resolve(url)));
} catch (URISyntaxException | IOException e) { e.printStackTrace(); }
try {
try {
......@@ -154,7 +155,7 @@ public class TransformationExecutor extends EpsilonStandalone {
public boolean packageMarkedAsNotUsed(String url, String sourceFolder) {
url = url.substring(url.indexOf(sourceFolder) + sourceFolder.length());
url = url.substring(0, url.indexOf("/"));
if(url.startsWith("_") && url.endsWith("_")) return true;
if(url.startsWith("_")) return true;
return false;
}
......@@ -167,7 +168,7 @@ public class TransformationExecutor extends EpsilonStandalone {
public boolean packageETLFilesMarkedAsNotUsed(String url, String sourceFolder) {
url = url.substring(url.indexOf(sourceFolder) + sourceFolder.length());
url = url.substring(url.indexOf("/")+1, url.indexOf(".etl"));
if(url.startsWith("_") && url.endsWith("_")) return true;
if(url.startsWith("_")) return true;
return false;
}
......@@ -194,7 +195,7 @@ public class TransformationExecutor extends EpsilonStandalone {
} else {
//Step 2
try {
File ORM2CROMUrl = new File(FileLocator.resolve(ORM2CROMUrls.get(0)).toURI());
File ORM2CROMUrl = new File(resolveURL(FileLocator.resolve(ORM2CROMUrls.get(0))));
BufferedReader buff = new BufferedReader(new FileReader(ORM2CROMUrl.getPath()));
String str = "";
while ((str = buff.readLine()) != null) {
......@@ -319,4 +320,16 @@ public class TransformationExecutor extends EpsilonStandalone {
return models;
}
/**
* Translator from URLs to URIs that creates correct URIs, in contrast to URL.toURI().
* (cf. https://stackoverflow.com/questions/14676966/escape-result-of-filelocator-resolveurl/14677157)
*
* @param url the given URL
* @return a new correctly initialized URI object
* @throws URISyntaxException
*/
private static URI resolveURL(URL url) throws URISyntaxException {
return new URI(url.getProtocol(), url.getPath(), null);
}
}
......@@ -2,6 +2,8 @@ package model;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
......@@ -154,7 +156,7 @@ public class ModelPattern extends FRaMEDShapePattern implements IPattern {
private void setStandartConfiguration(Model model) throws URISyntaxException, IOException {
ResourceSet resourceSet = new ResourceSetImpl();
Resource resourceStandartConfiguration =
resourceSet.createResource(URI.createURI(FileLocator.resolve(UILiterals.URL_TO_STANDARD_CONFIGURATION).toURI().toString()));
resourceSet.createResource(URI.createFileURI(FileLocator.resolve(UILiterals.URL_TO_STANDARD_CONFIGURATION).getFile()));
try {
resourceStandartConfiguration.load(null);
} catch (IOException e) {
......@@ -164,4 +166,5 @@ public class ModelPattern extends FRaMEDShapePattern implements IPattern {
Model standardConfigurationModel = (Model) resourceStandartConfiguration.getContents().get(0);
model.setFramedConfiguration(standardConfigurationModel.getFramedConfiguration());
}
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ import org.eclipse.graphiti.features.IMappingProvider;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.context.IReconnectionContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.context.impl.CreateContext;
import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.pictograms.Anchor;
......@@ -55,7 +56,14 @@ import org.framed.iorm.ui.exceptions.NoLinkedModelYet;
import org.framed.iorm.ui.exceptions.NoModelFoundException;
import org.framed.iorm.ui.multipage.MultipageEditor;
import org.framed.iorm.ui.providers.ToolBehaviorProvider;
import org.framed.iorm.ui.references.*;
import org.framed.iorm.ui.references.AbstractAttributeAndOperationReference;
import org.framed.iorm.ui.references.AbstractGroupingFeatureReference;
import org.framed.iorm.ui.references.AbstractIntraRelationshipConstraintReference;
import org.framed.iorm.ui.references.AbstractModelFeatureReference;
import org.framed.iorm.ui.references.AbstractRelationshipFeatureReference;
import org.framed.iorm.ui.references.AbstractStepInReference;
import org.framed.iorm.ui.references.MoreThanOneFeatureReferenceFoundException;
import org.framed.iorm.ui.references.NotExactlyOneFeatureReferenceFoundException;
import org.framed.iorm.ui.wizards.RoleModelWizard;
import org.osgi.framework.Bundle;
......@@ -693,8 +701,9 @@ public class UIUtil {
*/
public static boolean packageMarkedAsNotUsed(String classURL, String sourceFolder) {
classURL = classURL.substring(classURL.indexOf(sourceFolder) + sourceFolder.length());
if (classURL.indexOf("/")>-1)
classURL = classURL.substring(0, classURL.indexOf("/"));
if(classURL.startsWith("_") && classURL.endsWith("_")) return true;
if(classURL.startsWith("_")) return true;
return false;
}
......@@ -1152,4 +1161,5 @@ public class UIUtil {
public static String getGroupingFeaturesElementText(ModelElement modelElement) {
return modelElement.getType().toString() + " " + modelElement.getName();
}
}
package org.framed.iorm.ui.editPolicy;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
import org.eclipse.graphiti.features.context.impl.CreateContext;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.framed.iorm.model.ModelElement;
......@@ -24,16 +29,18 @@ import editpolicymodel.OrConstraintRule;
import editpolicymodel.SourceEqualsTarget;
import editpolicymodel.SourceEqualsTargetType;
import editpolicymodel.TrueConstraintRule;
import compartment.AddCompartmentTypeContext;
/**
* This class provides the rule-parse for the command-rules. Using VisitorPattern
* This class provides the rule-parse for the command-rules. Using
* VisitorPattern
*
* @author Christian Deussen
*
*/
public class ConstraintRuleVisitor {
public Map<Type, String> groupingFeatureCache = new HashMap<Type, String>();
/**
* command to check rules against
*/
......@@ -50,10 +57,10 @@ public class ConstraintRuleVisitor {
this.diagram = diagram;
}
public Diagram getDiagramWithName(String name, Diagram rootDiagram)
{
public Diagram getDiagramWithName(String name, Diagram rootDiagram) {
Diagram containerDiagram = UIUtil.getContainerDiagramForAnyDiagram(rootDiagram);
if(containerDiagram == null) throw new NoDiagramFoundException();
if (containerDiagram == null)
throw new NoDiagramFoundException();
for (Shape shape : containerDiagram.getChildren()) {
if (shape instanceof Diagram) {
if (((Diagram) shape).getName().equals(name))
......@@ -71,8 +78,7 @@ public class ConstraintRuleVisitor {
* @param rule
* @return Boolean
*/
public boolean checkRule(ConstraintRule rule)
{
public boolean checkRule(ConstraintRule rule) {
if (rule instanceof InCompartment) {
return isInCompartmentRuleVisitor((InCompartment) rule);
}
......@@ -119,39 +125,62 @@ public class ConstraintRuleVisitor {
}
private boolean isInCompartmentRuleVisitor(InCompartment rule) {
org.framed.iorm.model.Shape parent = null;
if(this.context instanceof AddCompartmentTypeContext) {
AddCompartmentTypeContext ctx = (AddCompartmentTypeContext) context;
parent = ctx.getModelToLink().getParent();
} else if(this.context instanceof AddContext) {
AddContext ctx = (AddContext) context;
Diagram contextDiagram = (Diagram)ctx.getTargetContainer();
if(contextDiagram.getName().startsWith("compartmentType"))
return true;
ContainerShape container = null;
if (this.context instanceof AddContext) {
container = ((AddContext) this.context).getTargetContainer();
} else if (this.context instanceof CreateContext) {
CreateContext ctx = (CreateContext) context;
if(ctx.getTargetContainer() instanceof Diagram) {
Diagram contextDiagram = (Diagram)ctx.getTargetContainer();
if(contextDiagram.getName().startsWith("compartmentType"))
return true;
}
container = ((CreateContext) this.context).getTargetContainer();
}
if(parent == null) {
//System.out.println("Parent null. Wrong context InCompartment(): " + this.context.getClass());
if (container == null)
return false;
// travers Containers to find the compartment type.
Diagram compartmentDiagram = findContainerDiagramOfType(container, Type.COMPARTMENT_TYPE);
return compartmentDiagram != null;
}
String parentDiagramName = null;
try {
parentDiagramName = parent.getContainer().getParent().getName();
} catch (Exception e) {}
Diagram myDiagram = this.getDiagramWithName(parentDiagramName, this.diagram);
if(myDiagram == null)
return false;
if(myDiagram.getName().startsWith("compartmentType"))
return true;
/**
* Returns the grouping reference (diagram kind) of the given container type, if
* it exists. Note: this method is cached for better performance.
*
* @param type
* the IORM::Type of the container element
* @return the string reference of the diagram kind of the given container type
*/
private String getGroupingReference(Type type) {
if (groupingFeatureCache.containsKey(type))
return groupingFeatureCache.get(type);
Optional<String> result = UIUtil.getGroupingFeatureReferences().stream().filter(a -> a.getModelType() == type) // rule.getType();
.map(a -> a.getDiagramKind()).findFirst();
if (!result.isPresent())
return null;
groupingFeatureCache.put(type, result.get());
return result.get();
}
return false;
/**
* This method checks if the given container shape is a Diagram of the Diagram
* Kind of the given type. Otherwise, the method traverses the containers to
* find a suitable candidate, if any exists.
*
* @param sourceShape
* the ContainerShape to investigate
* @param type
* the IORM::Type of the container to look for
* @return the diagram of the correct diagram kind or null if no corresponding
* diagram was not found.
*/
public Diagram findContainerDiagramOfType(ContainerShape sourceShape, Type type) {
String groupingReference = getGroupingReference(type);
while ((sourceShape != null) && !((sourceShape instanceof Diagram)
&& (UIUtil.isDiagram_KindValue((Diagram) sourceShape, groupingReference)))) {
sourceShape = sourceShape.getContainer();
}
if (sourceShape == null)
return null;
if (sourceShape instanceof Diagram)
return (Diagram) sourceShape;
throw new IllegalStateException(
"Invariant violated! findDiagramOfType found a sourceShape that was not a Diagram.");
}
private boolean andRuleVisitor(AndConstraintRule rule) {
......@@ -244,7 +273,8 @@ public class ConstraintRuleVisitor {
Anchor targetAnchor = this.getTargetAnchorFromContext(this.context);
ModelElement target = UIUtil.getModelElementForAnchor(targetAnchor);
System.out.println("sourceEqualsTargetTypeVisitor comparison: " + source.getType().getLiteral() + " == " + target.getType().getLiteral());
System.out.println("sourceEqualsTargetTypeVisitor comparison: " + source.getType().getLiteral() + " == "
+ target.getType().getLiteral());
return target.getType().getLiteral().equals(source.getType().getLiteral());
} catch (Exception e) {
......
......@@ -90,20 +90,6 @@ public class EditPolicyService {
}
}
/**
* checks if the package part of a file url starts and ends with an _
*
* @param url
* the string url to check against
* @param sourceFolder
* the source folder in which the class is located in
* @return if the package part of a class url starts and ends with an _
*/
private static boolean isPackageMarkedAsNotUsed(String url) {
url = url.substring(url.lastIndexOf('/')+1, url.length());
return url.startsWith("_") && url.endsWith("_");
}
private static void loadAllFiles() {
Bundle UIBundle = Platform.getBundle("org.framed.iorm.ui");
......@@ -117,14 +103,14 @@ public class EditPolicyService {
if (moduleFileURLs != null) {
for (URL url : moduleFileURLs) {
if (!isPackageMarkedAsNotUsed(url.toString())) {
if (!UIUtil.packageMarkedAsNotUsed(url.toString(), "modules/")) {
loadEditPolicyFile(url.toString());
}
}
}
if (coreFileURLs != null) {
for (URL url : coreFileURLs) {
if (!isPackageMarkedAsNotUsed(url.toString())) {
if (!UIUtil.packageMarkedAsNotUsed(url.toString(), "core/")) {
loadEditPolicyFile(url.toString());
}
}
......
......@@ -2,6 +2,7 @@ package org.framed.iorm.ui.subeditors;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
......@@ -160,7 +161,7 @@ public class FRaMEDFeatureEditor extends EditorPart {
private IFeatureModel readFeatureModel() {
File featureModelFile = null;
try {
featureModelFile = new File(FileLocator.resolve(URL_TO_FEATUREMODEL).toURI());
featureModelFile = new File(resolveURL(FileLocator.resolve(URL_TO_FEATUREMODEL)));
} catch (URISyntaxException | IOException e) { e.printStackTrace(); }
FeatureModelManager featureModelManager = FeatureModelManager.getInstance(featureModelFile.toPath());
if(featureModelManager.getLastProblems().containsError()) {
......@@ -185,6 +186,18 @@ public class FRaMEDFeatureEditor extends EditorPart {
}
}
/**
* Translator from URLs to URIs that creates correct URIs, in contrast to URL.toURI().
* (cf. https://stackoverflow.com/questions/14676966/escape-result-of-filelocator-resolveurl/14677157)
*
* @param url the given URL
* @return a new correctly initialized URI object
* @throws URISyntaxException
*/
private static URI resolveURL(URL url) throws URISyntaxException {
return new URI(url.getProtocol(), url.getPath(), null);
}
//tree related operation
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment