-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,862 additions
and
1,152 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
163 changes: 163 additions & 0 deletions
163
src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyAssociationStereotypeId.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,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); | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyAssociationStereotypeMenuManager.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,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); | ||
} | ||
} |
Oops, something went wrong.