Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
claudenirmf committed Dec 14, 2021
2 parents 85a6efb + 86ac53d commit 9fc02b8
Show file tree
Hide file tree
Showing 38 changed files with 1,862 additions and 1,152 deletions.
52 changes: 3 additions & 49 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>it.unibz.inf.ontouml</groupId>
<artifactId>ontouml-vp-plugin</artifactId>
<version>0.5.2</version>
<version>0.5.3</version>

<name>OntoUML 2 Plugin for Visual Paradigm</name>

Expand Down Expand Up @@ -173,36 +173,7 @@
</dependencies>

<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<versionRange>[2.5.2,)</versionRange>
<goals>
<goal>install-file</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -292,24 +263,7 @@
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>com.coveo</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.10</version>
<configuration>
<verbose>true</verbose>
<skip>false</skip>
<style>google</style>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class OntoUMLPlugin implements VPPlugin {

public static final String PLUGIN_VERSION_RELEASE = "0.5.2";
public static final String PLUGIN_VERSION_RELEASE = "0.5.3";
public static final String PLUGIN_ID = "it.unibz.inf.ontouml.vp";
public static final String PLUGIN_NAME = "OntoUML Plugin";
public static final String PLUGIN_REPO = "https://github.com/OntoUML/ontouml-vp-plugin/";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package it.unibz.inf.ontouml.vp.controllers;

import it.unibz.inf.ontouml.vp.utils.Stereotype;
import java.util.Arrays;
import java.util.HashMap;

public enum ApplyAssociationStereotypeId {
INSTANTIATION(
"it.unibz.inf.ontouml.vp.addInstantiationStereotype",
Stereotype.INSTANTIATION,
"Instantiation"),
TERMINATION(
"it.unibz.inf.ontouml.vp.addTerminationStereotype", Stereotype.TERMINATION, "Termination"),
PARTICIPATIONAL(
"it.unibz.inf.ontouml.vp.addParticipationalStereotype",
Stereotype.PARTICIPATIONAL,
"Participational"),
PARTICIPATION(
"it.unibz.inf.ontouml.vp.addParticipationStereotype",
Stereotype.PARTICIPATION,
"Participation"),
HISTORICAL_DEPENDENCE(
"it.unibz.inf.ontouml.vp.addHistoricalDependenceStereotype",
Stereotype.HISTORICAL_DEPENDENCE,
"HistoricalDependence"),
CREATION("it.unibz.inf.ontouml.vp.addCreationStereotype", Stereotype.CREATION, "Creation"),
MANIFESTATION(
"it.unibz.inf.ontouml.vp.addManifestationStereotype",
Stereotype.MANIFESTATION,
"Manifestation"),
BRINGS_ABOUT(
"it.unibz.inf.ontouml.vp.addBringsAboutStereotype", Stereotype.BRINGS_ABOUT, "BringsAbout"),
TRIGGERS("it.unibz.inf.ontouml.vp.addTriggersStereotype", Stereotype.TRIGGERS, "Triggers"),
SUB_QUANTITY_OF(
"it.unibz.inf.ontouml.vp.addSubQuantityStereotype",
Stereotype.SUB_QUANTITY_OF,
"SubQuantityOf"),
SUB_COLLECTION_OF(
"it.unibz.inf.ontouml.vp.addSubCollectionStereotype",
Stereotype.SUB_COLLECTION_OF,
"SubCollectionOf"),
MEMBER_OF("it.unibz.inf.ontouml.vp.addMemberOfStereotype", Stereotype.MEMBER_OF, "MemberOf"),
MEDIATION("it.unibz.inf.ontouml.vp.addMediationStereotype", Stereotype.MEDIATION, "Mediation"),
MATERIAL("it.unibz.inf.ontouml.vp.addMaterialStereotype", Stereotype.MATERIAL, "Material"),
EXTERNAL_DEPENDENCE(
"it.unibz.inf.ontouml.vp.addExternalDependenceStereotype",
Stereotype.EXTERNAL_DEPENDENCE,
"ExternalDependence"),
COMPONENT_OF(
"it.unibz.inf.ontouml.vp.addComponentOfStereotype", Stereotype.COMPONENT_OF, "ComponentOf"),
COMPARATIVE(
"it.unibz.inf.ontouml.vp.addComparativeStereotype", Stereotype.COMPARATIVE, "Comparative"),
CHARACTERIZATION(
"it.unibz.inf.ontouml.vp.addCharacterizationStereotype",
Stereotype.CHARACTERIZATION,
"Characterization"),

INSTANTIATION_FIXED(
"it.unibz.inf.ontouml.vp.addInstantiationStereotype.fixedMenu",
Stereotype.INSTANTIATION,
"Instantiation"),
TERMINATION_FIXED(
"it.unibz.inf.ontouml.vp.addTerminationStereotype.fixedMenu",
Stereotype.TERMINATION,
"Termination"),
PARTICIPATIONAL_FIXED(
"it.unibz.inf.ontouml.vp.addParticipationalStereotype.fixedMenu",
Stereotype.PARTICIPATIONAL,
"Participational"),
PARTICIPATION_FIXED(
"it.unibz.inf.ontouml.vp.addParticipationStereotype.fixedMenu",
Stereotype.PARTICIPATION,
"Participation"),
HISTORICAL_DEPENDENCE_FIXED(
"it.unibz.inf.ontouml.vp.addHistoricalDependenceStereotype.fixedMenu",
Stereotype.HISTORICAL_DEPENDENCE,
"HistoricalDependence"),
CREATION_FIXED(
"it.unibz.inf.ontouml.vp.addCreationStereotype.fixedMenu", Stereotype.CREATION, "Creation"),
MANIFESTATION_FIXED(
"it.unibz.inf.ontouml.vp.addManifestationStereotype.fixedMenu",
Stereotype.MANIFESTATION,
"Manifestation"),
BRINGS_ABOUT_FIXED(
"it.unibz.inf.ontouml.vp.addBringsAboutStereotype.fixedMenu",
Stereotype.BRINGS_ABOUT,
"BringsAbout"),
TRIGGERS_FIXED(
"it.unibz.inf.ontouml.vp.addTriggersStereotype.fixedMenu", Stereotype.TRIGGERS, "Triggers"),
SUB_QUANTITY_OF_FIXED(
"it.unibz.inf.ontouml.vp.addSubQuantityStereotype.fixedMenu",
Stereotype.SUB_QUANTITY_OF,
"SubQuantityOf"),
SUB_COLLECTION_OF_FIXED(
"it.unibz.inf.ontouml.vp.addSubCollectionStereotype.fixedMenu",
Stereotype.SUB_COLLECTION_OF,
"SubCollectionOf"),
MEMBER_OF_FIXED(
"it.unibz.inf.ontouml.vp.addMemberOfStereotype.fixedMenu", Stereotype.MEMBER_OF, "MemberOf"),
MEDIATION_FIXED(
"it.unibz.inf.ontouml.vp.addMediationStereotype.fixedMenu",
Stereotype.MEDIATION,
"Mediation"),
MATERIAL_FIXED(
"it.unibz.inf.ontouml.vp.addMaterialStereotype.fixedMenu", Stereotype.MATERIAL, "Material"),
EXTERNAL_DEPENDENCE_FIXED(
"it.unibz.inf.ontouml.vp.addExternalDependenceStereotype.fixedMenu",
Stereotype.EXTERNAL_DEPENDENCE,
"ExternalDependence"),
COMPONENT_OF_FIXED(
"it.unibz.inf.ontouml.vp.addComponentOfStereotype.fixedMenu",
Stereotype.COMPONENT_OF,
"ComponentOf"),
COMPARATIVE_FIXED(
"it.unibz.inf.ontouml.vp.addComparativeStereotype.fixedMenu",
Stereotype.COMPARATIVE,
"Comparative"),
CHARACTERIZATION_FIXED(
"it.unibz.inf.ontouml.vp.addCharacterizationStereotype.fixedMenu",
Stereotype.CHARACTERIZATION,
"Characterization");

private final String actionId;
private final String stereotype;
private final String defaultLabel;

private static HashMap<String, ApplyAssociationStereotypeId> actionIdMap;

private ApplyAssociationStereotypeId(String actionId, String stereotype, String defaultLabel) {
this.actionId = actionId;
this.stereotype = stereotype;
this.defaultLabel = defaultLabel;
}

public String getActionId() {
return actionId;
}

public String getDefaultLabel() {
return defaultLabel;
}

public String getStereotype() {
return stereotype;
}

public boolean isFixed() {
return getActionId().contains(".fixedMenu");
}

public static ApplyAssociationStereotypeId getFromActionId(String actionId) {
if (actionIdMap == null || actionIdMap.isEmpty()) {
actionIdMap = new HashMap<String, ApplyAssociationStereotypeId>();
Arrays.stream(ApplyAssociationStereotypeId.values())
.forEach(
applyAssociationStereotypeId ->
actionIdMap.put(
applyAssociationStereotypeId.getActionId(), applyAssociationStereotypeId));
}

return actionIdMap.get(actionId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package it.unibz.inf.ontouml.vp.controllers;

import com.vp.plugin.action.VPAction;
import com.vp.plugin.action.VPContext;
import com.vp.plugin.model.IAssociation;
import com.vp.plugin.model.IModelElement;
import it.unibz.inf.ontouml.vp.model.uml.Association;
import it.unibz.inf.ontouml.vp.utils.OntoUMLConstraintsManager;
import it.unibz.inf.ontouml.vp.utils.StereotypesManager;
import it.unibz.inf.ontouml.vp.utils.VPContextUtils;
import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
import java.util.Set;
import java.util.stream.Collectors;

public class ApplyAssociationStereotypeMenuManager extends ApplyStereotypeMenuManager {

private final ApplyAssociationStereotypeId associationStereotypeId;
private final Set<IModelElement> elements;
private final Set<IModelElement> elementsWhereStereotypeIsAllowed;
private final Set<IModelElement> elementsWhereStereotypeIsAllowedOnlyIfInverted;
private final boolean hasSomeElementThatRequiresInversion;
private final boolean allElementsCanReceiveTheStereotype;

ApplyAssociationStereotypeMenuManager(VPAction action, VPContext context) {
this.action = action;
this.context = context;
this.associationStereotypeId =
ApplyAssociationStereotypeId.getFromActionId(action.getActionId());

this.elements = VPContextUtils.getModelElements(context);
this.elementsWhereStereotypeIsAllowed = getElementsWhereStereotypeIsAllowed(elements);
this.elementsWhereStereotypeIsAllowedOnlyIfInverted =
getElementsWhereStereotypeIsAllowedIfInverted(elements);

this.allElementsCanReceiveTheStereotype =
elements.stream()
.allMatch(
element ->
elementsWhereStereotypeIsAllowed.contains(element)
|| elementsWhereStereotypeIsAllowedOnlyIfInverted.contains(element));

this.hasSomeElementThatRequiresInversion =
elementsWhereStereotypeIsAllowedOnlyIfInverted.stream()
.anyMatch(element -> !elementsWhereStereotypeIsAllowed.contains(element));
}

@Override
public void performAction() {
boolean shouldProceed = true;

if (shouldWarnAboutInvertingAssociations())
shouldProceed = ViewManagerUtils.associationInvertionWarningDialog();

if (!shouldProceed) return;

elements.stream()
.map(e -> (IAssociation) e)
.filter(Association::holdsBetweenClasses)
.forEach(
association -> {
if (doesRequireInverting(association))
Association.invertAssociation(association, true);

StereotypesManager.applyStereotype(
association, associationStereotypeId.getStereotype());
});
}

@Override
public void update() {
updateMenuLabel();
updateMenuEnable();
}

private void updateMenuLabel() {
String label =
hasSomeElementThatRequiresInversion
? associationStereotypeId.getDefaultLabel() + " (inverted)"
: associationStereotypeId.getDefaultLabel();

if (associationStereotypeId.isFixed()) action.setLabel(label);
else if (allElementsCanReceiveTheStereotype) action.setLabel(label);
else action.setLabel(associationStereotypeId.getDefaultLabel());
}

private void updateMenuEnable() {
if (associationStereotypeId.isFixed()) {
boolean holdsBetweenClasses =
Association.holdsBetweenClasses((IAssociation) context.getModelElement());
action.setEnabled(holdsBetweenClasses);
} else {
action.setEnabled(allElementsCanReceiveTheStereotype);
}
}

private Set<IModelElement> getElementsWhereStereotypeIsAllowed(Set<IModelElement> elements) {
String stereotype = associationStereotypeId.getStereotype();

return elements.stream()
.map(e -> (IAssociation) e)
.filter(Association::holdsBetweenClasses)
.filter(a -> OntoUMLConstraintsManager.isStereotypeAllowed(a, stereotype))
.collect(Collectors.toSet());
}

private Set<IModelElement> getElementsWhereStereotypeIsAllowedIfInverted(
Set<IModelElement> elements) {
String stereotype = associationStereotypeId.getStereotype();

return elements.stream()
.map(e -> (IAssociation) e)
.filter(Association::holdsBetweenClasses)
.filter(a -> OntoUMLConstraintsManager.isStereotypeAllowedIfInverted(a, stereotype))
.collect(Collectors.toSet());
}

private boolean shouldWarnAboutInvertingAssociations() {
return elements.stream().anyMatch(element -> doesRequireInverting((IAssociation) element));
}

private boolean doesRequireInverting(IAssociation association) {
return elementsWhereStereotypeIsAllowedOnlyIfInverted.contains(association)
&& !elementsWhereStereotypeIsAllowed.contains(association);
}
}
Loading

0 comments on commit 9fc02b8

Please sign in to comment.