From 881011e9a82645113b90dfd7b4527ec12b55e7aa Mon Sep 17 00:00:00 2001
From: Phillipus
Date: Mon, 7 Oct 2024 18:22:58 +0100
Subject: [PATCH] [Property Sections] Composite controls should check for valid
object selection
- Because these composites share a Section we need to filter for valid objects when there is a multi-selection
---
.../propertysections/FillColorComposite.java | 13 +++++++--
.../propertysections/FillOpacitySection.java | 6 +++++
.../propertysections/GradientComposite.java | 10 ++++++-
.../propertysections/LineColorComposite.java | 27 ++++++++++++++++---
.../propertysections/LineOpacitySection.java | 6 +++++
.../propertysections/LineWidthComposite.java | 11 +++++++-
.../propertysections/OpacityComposite.java | 7 ++++-
7 files changed, 71 insertions(+), 9 deletions(-)
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorComposite.java
index 45ad3ebd0..c816e014b 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorComposite.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorComposite.java
@@ -19,6 +19,7 @@
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.editor.ui.components.ColorChooser;
+import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelObject;
@@ -56,7 +57,7 @@ Composite getComposite() {
String newColor = ColorFactory.convertRGBToString(rgb);
for(EObject dmo : section.getEObjects()) {
- if(section.isAlive(dmo) && !section.isLocked(dmo)) {
+ if(isValidObject(dmo)) {
Command cmd = new FillColorCommand((IDiagramModelObject)dmo, newColor);
if(cmd.canExecute()) {
result.add(cmd);
@@ -66,7 +67,7 @@ Composite getComposite() {
}
else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) {
for(EObject dmo : section.getEObjects()) {
- if(section.isAlive(dmo) && !section.isLocked(dmo)) {
+ if(isValidObject(dmo)) {
// If user pref to save color is set then save the value, otherwise save as null
String rgbValue = null;
@@ -86,6 +87,14 @@ else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) {
section.executeCommand(result.unwrap());
};
+ /**
+ * In case of multi-selection we should check this
+ */
+ private boolean isValidObject(EObject eObject) {
+ return section.isAlive(eObject) && !section.isLocked(eObject) &&
+ section.getFilter().shouldExposeFeature(eObject, IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__FILL_COLOR.getName());
+ }
+
/**
* Listen to default fill colour changes in Prefs
*/
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillOpacitySection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillOpacitySection.java
index bb6e3adb2..501adf625 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillOpacitySection.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillOpacitySection.java
@@ -6,6 +6,7 @@
package com.archimatetool.editor.propertysections;
import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
@@ -55,6 +56,11 @@ int getValue() {
IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject();
return lastSelected.getAlpha();
}
+
+ @Override
+ boolean isValidObject(EObject eObject) {
+ return getFilter().isRequiredType(eObject);
+ }
};
// Help ID
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientComposite.java
index b8de200d1..a3ad36d31 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientComposite.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientComposite.java
@@ -61,7 +61,7 @@ public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for(EObject object : section.getEObjects()) {
- if(section.isAlive(object)) {
+ if(isValidObject(object)) {
Command cmd = new FeatureCommand(Messages.GradientSection_1, (IFeatures)object,
IDiagramModelObject.FEATURE_GRADIENT, fGradientCombo.getSelectionIndex() - 1, IDiagramModelObject.FEATURE_GRADIENT_DEFAULT);
if(cmd.canExecute()) {
@@ -75,6 +75,14 @@ public void widgetSelected(SelectionEvent e) {
});
}
+ /**
+ * In case of multi-selection we should check this
+ */
+ private boolean isValidObject(EObject eObject) {
+ return section.isAlive(eObject) &&
+ section.getFilter().shouldExposeFeature(eObject, IDiagramModelObject.FEATURE_GRADIENT);
+ }
+
void updateControl() {
IDiagramModelObject lastSelected = (IDiagramModelObject)section.getFirstSelectedObject();
fGradientCombo.select(lastSelected.getGradient() + 1);
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorComposite.java
index 80430bf9c..9d8f10099 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorComposite.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorComposite.java
@@ -22,7 +22,9 @@
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.editor.ui.components.ColorChooser;
+import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelObject;
+import com.archimatetool.model.IFeatures;
import com.archimatetool.model.ILineObject;
@@ -61,7 +63,7 @@ Composite getComposite() {
String newColor = ColorFactory.convertRGBToString(rgb);
for(EObject lineObject : section.getEObjects()) {
- if(section.isAlive(lineObject)) {
+ if(isValidLineColorObject(lineObject)) {
Command cmd = new LineColorCommand((ILineObject)lineObject, newColor);
if(cmd.canExecute()) {
result.add(cmd);
@@ -71,7 +73,7 @@ Composite getComposite() {
}
else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) {
for(EObject lineObject : section.getEObjects()) {
- if(section.isAlive(lineObject)) {
+ if(isValidLineColorObject(lineObject)) {
// If user pref to save color is set then save the value, otherwise save as null
String rgbValue = null;
@@ -115,8 +117,8 @@ public void run() {
CompoundCommand result = new CompoundCommand();
for(EObject object : section.getEObjects()) {
- if(section.isAlive(object) && object instanceof IDiagramModelObject dmo) {
- Command cmd = new FeatureCommand(Messages.LineColorSection_4, dmo, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR,
+ if(isValidDerivedLineColorObject(object)) {
+ Command cmd = new FeatureCommand(Messages.LineColorSection_4, (IFeatures)object, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR,
fDeriveLineColorAction.isChecked(), IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT);
if(cmd.canExecute()) {
result.add(cmd);
@@ -173,6 +175,23 @@ void updateControl() {
}
}
+ /**
+ * In case of multi-selection we should check this
+ */
+ private boolean isValidLineColorObject(EObject eObject) {
+ return section.isAlive(eObject) &&
+ section.getFilter().shouldExposeFeature(eObject, IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName());
+ }
+
+ /**
+ * In case of multi-selection we should check this
+ */
+ private boolean isValidDerivedLineColorObject(EObject eObject) {
+ return isValidLineColorObject(eObject) &&
+ eObject instanceof IDiagramModelObject &&
+ section.getFilter().shouldExposeFeature(eObject, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR);
+ }
+
void dispose() {
removeListeners();
composite.dispose();
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineOpacitySection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineOpacitySection.java
index 209cec0c6..ac8fa424c 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineOpacitySection.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineOpacitySection.java
@@ -6,6 +6,7 @@
package com.archimatetool.editor.propertysections;
import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
@@ -55,6 +56,11 @@ int getValue() {
IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject();
return lastSelected.getLineAlpha();
}
+
+ @Override
+ boolean isValidObject(EObject eObject) {
+ return getFilter().isRequiredType(eObject);
+ }
};
// Help ID
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthComposite.java
index b1b12d3a3..0d01dba42 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthComposite.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthComposite.java
@@ -14,6 +14,7 @@
import org.eclipse.swt.widgets.Composite;
import com.archimatetool.editor.diagram.commands.LineWidthCommand;
+import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.ILineObject;
@@ -55,7 +56,7 @@ private void createLineWidthControl(Composite parent) {
CompoundCommand result = new CompoundCommand();
for(EObject obj : section.getEObjects()) {
- if(section.isAlive(obj)) {
+ if(isValidObject(obj)) {
Command cmd = new LineWidthCommand((ILineObject)obj, fComboLineWidth.getSelectionIndex() + 1);
if(cmd.canExecute()) {
result.add(cmd);
@@ -77,6 +78,14 @@ void updateControl() {
fComboLineWidth.setEnabled(!section.isLocked(lineObject));
}
+
+ /**
+ * In case of multi-selection we should check this
+ */
+ private boolean isValidObject(EObject eObject) {
+ return section.isAlive(eObject) &&
+ section.getFilter().shouldExposeFeature(eObject, IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName());
+ }
void dispose() {
composite.dispose();
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacityComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacityComposite.java
index 33c04f9d3..8030958bb 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacityComposite.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacityComposite.java
@@ -55,7 +55,7 @@ private void createSpinnerControl(Composite parent, String label) {
CompoundCommand result = new CompoundCommand();
for(EObject dmo : section.getEObjects()) {
- if(section.isAlive(dmo)) {
+ if(section.isAlive(dmo) && isValidObject(dmo)) {
Command cmd = getCommand((IDiagramModelObject)dmo, newValue);
if(cmd.canExecute()) {
result.add(cmd);
@@ -83,6 +83,11 @@ private void createSpinnerControl(Composite parent, String label) {
abstract int getValue();
+ /**
+ * In case of multi-selection we should check this
+ */
+ abstract boolean isValidObject(EObject eObject);
+
void updateControl() {
IDiagramModelObject lastSelected = (IDiagramModelObject)section.getFirstSelectedObject();
fSpinner.setSelection(getValue());