Skip to content

Commit

Permalink
eclipse-capella#2913 Merge two commands to avoid refresh between them
Browse files Browse the repository at this point in the history
This commit merge two command for navigability state of association in
CDB to avoid diagram refresh (and unwanted behavior) between them.

Signed-off-by: Séraphin Costa <[email protected]>
  • Loading branch information
scosta-obeo committed Nov 6, 2024
1 parent d968e2e commit fe9801f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import org.polarsys.capella.common.data.modellingcore.ModellingcorePackage;
import org.polarsys.capella.common.ef.command.AbstractCompoundCommand;
import org.polarsys.capella.common.ef.command.ICommand;
import org.polarsys.capella.common.helpers.EObjectExt;
import org.polarsys.capella.core.data.capellacore.CapellacorePackage;
import org.polarsys.capella.core.data.capellacore.Classifier;
Expand Down Expand Up @@ -82,8 +84,10 @@ public void widgetSelected(SelectionEvent event) {
if (oppositeMember != null) {
EObject oppositeTypeElement = (EObject) oppositeMember.eGet(ModellingcorePackage.Literals.ABSTRACT_TYPED_ELEMENT__ABSTRACT_TYPE);
if (oppositeTypeElement != null) {
moveDataValue(semanticElement, oppositeTypeElement, CapellacorePackage.Literals.CLASSIFIER__OWNED_FEATURES);
addDataValue(ownerElement, InformationPackage.Literals.ASSOCIATION__NAVIGABLE_MEMBERS, semanticElement);
AbstractCompoundCommand command = new AbstractCompoundCommand() {};
command.append(createMoveDataValueCommand(semanticElement, oppositeTypeElement, CapellacorePackage.Literals.CLASSIFIER__OWNED_FEATURES));
command.append(createAddDataValueCommand(ownerElement, InformationPackage.Literals.ASSOCIATION__NAVIGABLE_MEMBERS, semanticElement));
executeCommand(command);
}
}
}
Expand All @@ -96,8 +100,10 @@ public void widgetSelected(SelectionEvent event) {
}

if ((typeElement instanceof Classifier) && (referencerElement instanceof Association)) {
moveDataValue(semanticElement, referencerElement, InformationPackage.Literals.ASSOCIATION__OWNED_MEMBERS);
removeDataValue(referencerElement, InformationPackage.Literals.ASSOCIATION__NAVIGABLE_MEMBERS, semanticElement);
AbstractCompoundCommand command = new AbstractCompoundCommand() {};
command.append(createMoveDataValueCommand(semanticElement, referencerElement, InformationPackage.Literals.ASSOCIATION__OWNED_MEMBERS));
command.append(createRemoveDataValueCommand(referencerElement, InformationPackage.Literals.ASSOCIATION__NAVIGABLE_MEMBERS, semanticElement));
executeCommand(command);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,17 @@ public void run() {
* @param feature
* @param value
*/
protected void addDataValue(final EObject object, final EStructuralFeature feature, final Object value) {
protected AbstractReadWriteCommand createAddDataValueCommand(final EObject object, final EStructuralFeature feature, final Object value) {
if (NotificationHelper.isNotificationRequired(object, feature, value)) {
AbstractReadWriteCommand command = new AbstractReadWriteCommand() {
return new AbstractReadWriteCommand() {
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void run() {
((List) object.eGet(feature)).add(value);
}
};
executeCommand(command);
} else {
return null;
}
}

Expand All @@ -451,8 +452,8 @@ public void run() {
* @param feature
*/
@SuppressWarnings("unchecked")
protected void moveDataValue(final EObject object, final EObject owner, final EStructuralFeature feature) {
AbstractReadWriteCommand command = new AbstractReadWriteCommand() {
protected AbstractReadWriteCommand createMoveDataValueCommand(final EObject object, final EObject owner, final EStructuralFeature feature) {
return new AbstractReadWriteCommand() {
@Override
public void run() {
if (feature.isMany()) {
Expand All @@ -462,7 +463,6 @@ public void run() {
}
}
};
executeCommand(command);
}

/**
Expand All @@ -472,9 +472,9 @@ public void run() {
* @param feature
* @param value
*/
protected void removeDataValue(final EObject object, final EStructuralFeature feature, final Object value) {
protected AbstractReadWriteCommand createRemoveDataValueCommand(final EObject object, final EStructuralFeature feature, final Object value) {
if (NotificationHelper.isNotificationRequired(object, feature, value)) {
AbstractReadWriteCommand command = new AbstractReadWriteCommand() {
return new AbstractReadWriteCommand() {
@Override
public void run() {
if ((feature instanceof EReference) && ((EReference) feature).isContainment()) {
Expand All @@ -484,7 +484,8 @@ public void run() {
}
}
};
executeCommand(command);
} else {
return null;
}
}

Expand Down

0 comments on commit fe9801f

Please sign in to comment.