Skip to content

Commit

Permalink
[Property Sections] Composite controls should check for valid object …
Browse files Browse the repository at this point in the history
…selection

- Because these composites appear share a Section we need to filter for valid objects when there is a multi-selection
  • Loading branch information
Phillipus committed Oct 7, 2024
1 parent 839d90c commit b051cf9
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,11 @@ int getValue() {
IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject();
return lastSelected.getAlpha();
}

@Override
boolean isValidObject(EObject eObject) {
return getFilter().isRequiredType(eObject);
}
};

// Help ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,11 @@ int getValue() {
IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject();
return lastSelected.getLineAlpha();
}

@Override
boolean isValidObject(EObject eObject) {
return getFilter().isRequiredType(eObject);
}
};

// Help ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit b051cf9

Please sign in to comment.