Skip to content

Commit

Permalink
Enable "Default" on color chooser based on multi-selection
Browse files Browse the repository at this point in the history
- Before this change the "Default" button was enabled or disabled based on the first selected object. This meant that when selecting many objects you could not select "Default" if the first selected object was in disabled state.

- Now we base the enabled state on all selected objects.
  • Loading branch information
Phillipus committed Feb 6, 2025
1 parent 9723c62 commit b216386
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 35 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.IArchimateModelObject;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelObject;

Expand Down Expand Up @@ -112,23 +113,33 @@ private void createColorControl(Composite parent) {
}

void updateControl() {
IDiagramModelObject lastSelected = (IDiagramModelObject)section.getFirstSelectedObject();
IDiagramModelObject firstSelected = (IDiagramModelObject)section.getFirstSelectedObject();

String colorValue = lastSelected.getFillColor();
RGB rgb = ColorFactory.convertStringToRGB(colorValue);
RGB rgb = ColorFactory.convertStringToRGB(firstSelected.getFillColor());
if(rgb == null) {
rgb = ColorFactory.getDefaultFillColor(lastSelected).getRGB();
rgb = ColorFactory.getDefaultFillColor(firstSelected).getRGB();
}

fColorChooser.setColorValue(rgb);
fColorChooser.setEnabled(!section.isLocked(firstSelected));

fColorChooser.setEnabled(!section.isLocked(lastSelected));

// Set default enabled based on all selected objects.
// Note that the default button might not show the correct enabled state depending on what's selected at the time of the action.
boolean isDefaultColor = true;
// If user pref is to save the color then it's a different meaning of default
boolean isDefaultColor = (colorValue == null);
if(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) {
isDefaultColor = (colorValue != null) && rgb.equals(ColorFactory.getDefaultFillColor(lastSelected).getRGB());
boolean saveUserDefaultColor = ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR);

for(IArchimateModelObject object : section.getEObjects()) {
if(object instanceof IDiagramModelObject dmo) {
if(saveUserDefaultColor) {
isDefaultColor &= (dmo.getFillColor() != null && rgb.equals(ColorFactory.getDefaultFillColor(dmo).getRGB()));
}
else {
isDefaultColor &= dmo.getFillColor() == null;
}
}
}

fColorChooser.setIsDefaultColor(isDefaultColor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.editor.ui.components.ColorChooser;
import com.archimatetool.editor.ui.components.FontChooser;
import com.archimatetool.model.IArchimateModelObject;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelComponent;
import com.archimatetool.model.IFontAttribute;
Expand Down Expand Up @@ -203,9 +204,9 @@ private void updateFontControl() {
}

private void updateColorControl() {
String colorValue = ((IFontAttribute)getFirstSelectedObject()).getFontColor();
RGB rgb = ColorFactory.convertStringToRGB(colorValue);
IFontAttribute firstSelected = (IFontAttribute)getFirstSelectedObject();

RGB rgb = ColorFactory.convertStringToRGB(firstSelected.getFontColor());
if(rgb != null) {
fColorChooser.setColorValue(rgb);
}
Expand All @@ -214,8 +215,18 @@ private void updateColorControl() {
fColorChooser.setColorValue(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND).getRGB());
}

fColorChooser.setEnabled(!isLocked(getFirstSelectedObject()));
fColorChooser.setIsDefaultColor(colorValue == null);
fColorChooser.setEnabled(!isLocked(firstSelected));

// Set default enabled based on all selected objects.
// Note that the default button might not show the correct enabled state depending on what's selected at the time of the action.
boolean isDefaultColor = true;
for(IArchimateModelObject object : getEObjects()) {
if(object instanceof IFontAttribute fontObject) {
isDefaultColor &= fontObject.getFontColor() == null;
}
}

fColorChooser.setIsDefaultColor(isDefaultColor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.archimatetool.editor.model.commands.FeatureCommand;
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.editor.ui.components.ColorChooser;
import com.archimatetool.model.IArchimateModelObject;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelArchimateObject;
import com.archimatetool.model.IDiagramModelObject;
Expand Down Expand Up @@ -104,17 +105,26 @@ protected void notifyChanged(Notification msg) {

@Override
protected void update() {
IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject();
IDiagramModelObject firstSelected = (IDiagramModelObject)getFirstSelectedObject();

String colorValue = lastSelected.getIconColor();
RGB rgb = ColorFactory.convertStringToRGB(colorValue);
RGB rgb = ColorFactory.convertStringToRGB(firstSelected.getIconColor());
if(rgb == null) {
rgb = new RGB(0, 0, 0);
}

fColorChooser.setColorValue(rgb);
fColorChooser.setIsDefaultColor(IDiagramModelObject.FEATURE_ICON_COLOR_DEFAULT.equals(colorValue));
fColorChooser.setEnabled(!isLocked(lastSelected));
fColorChooser.setEnabled(!isLocked(firstSelected));

// Set default enabled based on all selected objects.
// Note that the default button might not show the correct enabled state depending on what's selected at the time of the action.
boolean isDefaultColor = true;
for(IArchimateModelObject object : getEObjects()) {
if(object instanceof IDiagramModelObject dmo) {
isDefaultColor &= IDiagramModelObject.FEATURE_ICON_COLOR_DEFAULT.equals(dmo.getIconColor());
}
}

fColorChooser.setIsDefaultColor(isDefaultColor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.editor.ui.components.ColorChooser;
import com.archimatetool.model.IArchimateModelObject;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelObject;
import com.archimatetool.model.IFeatures;
Expand Down Expand Up @@ -132,42 +133,47 @@ public void run() {
}

void updateControl() {
ILineObject lineObject = (ILineObject)section.getFirstSelectedObject();
ILineObject firstSelected = (ILineObject)section.getFirstSelectedObject();

String colorValue = lineObject.getLineColor();
RGB rgb = ColorFactory.convertStringToRGB(colorValue);
RGB rgb = ColorFactory.convertStringToRGB(firstSelected.getLineColor());
if(rgb == null) {
rgb = ColorFactory.getDefaultLineColor(lineObject).getRGB();
rgb = ColorFactory.getDefaultLineColor(firstSelected).getRGB();
}

fColorChooser.setColorValue(rgb);

// Locked
boolean enabled = !section.isLocked(lineObject);
fColorChooser.setEnabled(!section.isLocked(firstSelected));

fColorChooser.setEnabled(enabled);
// Set default enabled based on all selected objects.
// Note that the default button might not show the correct enabled state depending on what's selected at the time of the action.
boolean isDefaultColor = true;
// If user pref is to save the color then it's a different meaning of default
boolean saveUserDefaultColor = ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR);

if(!enabled) {
return;
for(IArchimateModelObject object : section.getEObjects()) {
if(object instanceof ILineObject lo) {
if(saveUserDefaultColor) {
isDefaultColor &= (lo.getLineColor() != null && rgb.equals(ColorFactory.getDefaultLineColor(lo).getRGB()));
}
else {
isDefaultColor &= lo.getLineColor() == null;
}
}
}

// If the user pref is to save the color in the file, then it's a different meaning of default
boolean isDefaultColor = (colorValue == null);
if(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) {
isDefaultColor = (colorValue != null) && rgb.equals(ColorFactory.getDefaultLineColor(lineObject).getRGB());
}
fColorChooser.setIsDefaultColor(isDefaultColor);

// If this is an element line enable or disable some things
if(lineObject instanceof IDiagramModelObject dmo) {
// If this is an object line enable or disable some things
if(firstSelected instanceof IDiagramModelObject dmo) {
boolean deriveElementLineColor = dmo.getDeriveElementLineColor();

fColorChooser.setDoShowColorImage(!deriveElementLineColor);
fColorChooser.getColorButton().setEnabled(!deriveElementLineColor);
fColorChooser.setDoShowDefaultMenuItem(!deriveElementLineColor);

fColorChooser.addMenuAction(fDeriveLineColorAction);
fDeriveLineColorAction.setChecked(deriveElementLineColor);
}
// Connection line
else {
fColorChooser.setDoShowColorImage(true);
fColorChooser.getColorButton().setEnabled(true);
Expand Down

0 comments on commit b216386

Please sign in to comment.