Skip to content

Commit

Permalink
Refactor and re-order some property sections
Browse files Browse the repository at this point in the history
- See #978
- Move some controls
- Refactor so that controls are re-usable
  • Loading branch information
Phillipus committed Oct 17, 2023
1 parent 6802f13 commit e45556e
Show file tree
Hide file tree
Showing 20 changed files with 1,000 additions and 783 deletions.
39 changes: 16 additions & 23 deletions com.archimatetool.editor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,30 +417,30 @@
</propertySection>
<propertySection
afterSection="fillColorSection"
class="com.archimatetool.editor.propertysections.LineColorSection"
filter="com.archimatetool.editor.propertysections.LineColorSection$Filter"
id="lineColorSection"
class="com.archimatetool.editor.propertysections.FillOpacitySection"
filter="com.archimatetool.editor.propertysections.FillOpacitySection$Filter"
id="fillOpacitySection"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineColorSection"
class="com.archimatetool.editor.propertysections.IconColorSection"
filter="com.archimatetool.editor.propertysections.IconColorSection$Filter"
id="iconColorSection"
afterSection="fillOpacitySection"
class="com.archimatetool.editor.propertysections.LineSection"
filter="com.archimatetool.editor.propertysections.LineSection$Filter"
id="lineSection"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineColorSection"
class="com.archimatetool.editor.propertysections.LineWidthSection"
filter="com.archimatetool.editor.propertysections.LineWidthSection$Filter"
id="lineWidthSection"
afterSection="lineSection"
class="com.archimatetool.editor.propertysections.LineOpacitySection"
filter="com.archimatetool.editor.propertysections.LineOpacitySection$Filter"
id="lineOpacitySection"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="iconColorSection"
class="com.archimatetool.editor.propertysections.GradientSection"
filter="com.archimatetool.editor.propertysections.GradientSection$Filter"
id="gradientSection"
afterSection="lineOpacitySection"
class="com.archimatetool.editor.propertysections.IconColorSection"
filter="com.archimatetool.editor.propertysections.IconColorSection$Filter"
id="iconColorSection"
tab="appearance.tab">
</propertySection>
<propertySection
Expand Down Expand Up @@ -477,7 +477,7 @@
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="fillColorSection"
afterSection="fillOpacitySection"
class="com.archimatetool.editor.propertysections.BorderColorSection"
filter="com.archimatetool.editor.propertysections.BorderColorSection$Filter"
id="borderColorSection"
Expand All @@ -490,13 +490,6 @@
id="fontSection"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="fontSection"
class="com.archimatetool.editor.propertysections.OpacitySection"
filter="com.archimatetool.editor.propertysections.OpacitySection$Filter"
id="opacitySection"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="gradientSection"
class="com.archimatetool.editor.propertysections.NoteBorderTypeSection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.ui.IWorkbenchPart;

import com.archimatetool.editor.diagram.commands.LineWidthCommand;
import com.archimatetool.editor.propertysections.LineWidthSection;
import com.archimatetool.editor.ui.factory.IObjectUIProvider;
import com.archimatetool.editor.ui.factory.ObjectUIFactory;
import com.archimatetool.model.IArchimatePackage;
Expand Down Expand Up @@ -118,6 +117,12 @@ private boolean shouldEnable(Object model) {
private static class LineWidthDialog extends Dialog {
private Combo fCombo;
private int fLineWidth;

private static final String[] comboLineWidthItems = {
Messages.LineWidthAction_2,
Messages.LineWidthAction_3,
Messages.LineWidthAction_4
};

protected LineWidthDialog(Shell parent, int lineWidth) {
super(parent);
Expand All @@ -135,7 +140,7 @@ protected Control createDialogArea(Composite parent) {
Composite composite = (Composite)super.createDialogArea(parent);

fCombo = new Combo(composite, SWT.READ_ONLY);
fCombo.setItems(LineWidthSection.comboLineWidthItems);
fCombo.setItems(comboLineWidthItems);
fCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fCombo.select(fLineWidth - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public class Messages extends NLS {

public static String LineWidthAction_1;

public static String LineWidthAction_2;

public static String LineWidthAction_3;

public static String LineWidthAction_4;

public static String LockObjectAction_0;

public static String LockObjectAction_1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ LineColorAction_0=Line colour...
LineColorAction_1=Change line colour
LineWidthAction_0=Line width...
LineWidthAction_1=Line width
LineWidthAction_2=Normal
LineWidthAction_3=Medium
LineWidthAction_4=Heavy
LockObjectAction_0=Lock
LockObjectAction_1=Lock the component
LockObjectAction_2=Unlock
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* This program and the accompanying materials
* are made available under the terms of the License
* which accompanies this distribution in the file LICENSE.txt
*/
package com.archimatetool.editor.propertysections;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;

import com.archimatetool.editor.ArchiPlugin;
import com.archimatetool.editor.diagram.commands.FillColorCommand;
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.editor.ui.components.ColorChooser;
import com.archimatetool.model.IDiagramModelObject;



/**
* Fill Color Composite
*
* @author Phillip Beauvoir
*/
class FillColorComposite {

private ColorChooser fColorChooser;
private AbstractECorePropertySection section;

FillColorComposite(AbstractECorePropertySection section, Composite parent) {
this.section = section;
createColorControl(section.createComposite(parent, 2, false));
addListeners();
}

/**
* Color listener
*/
private IPropertyChangeListener colorListener = event -> {
CompoundCommand result = new CompoundCommand();

if(event.getProperty() == ColorChooser.PROP_COLORCHANGE) {
RGB rgb = fColorChooser.getColorValue();
String newColor = ColorFactory.convertRGBToString(rgb);

for(EObject dmo : section.getEObjects()) {
if(section.isAlive(dmo) && !section.isLocked(dmo)) {
Command cmd = new FillColorCommand((IDiagramModelObject)dmo, newColor);
if(cmd.canExecute()) {
result.add(cmd);
}
}
}
}
else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) {
for(EObject dmo : section.getEObjects()) {
if(section.isAlive(dmo) && !section.isLocked(dmo)) {
// If user pref to save color is set then save the value, otherwise save as null
String rgbValue = null;

if(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) {
Color color = ColorFactory.getDefaultFillColor(dmo);
rgbValue = ColorFactory.convertColorToString(color);
}

Command cmd = new FillColorCommand((IDiagramModelObject)dmo, rgbValue);
if(cmd.canExecute()) {
result.add(cmd);
}
}
}
}

section.executeCommand(result.unwrap());
};

/**
* Listen to default fill colour changes in Prefs
*/
private IPropertyChangeListener prefsListener = event -> {
if(event.getProperty().startsWith(IPreferenceConstants.DEFAULT_FILL_COLOR_PREFIX) ||
event.getProperty().equals(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) { // This will affect the "Default" menu in color chooser
updateControl();
}
};


private void createColorControl(Composite parent) {
section.createLabel(parent, Messages.FillColorSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
fColorChooser = new ColorChooser(parent, section.getWidgetFactory());
}

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

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

fColorChooser.setColorValue(rgb);

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

// 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());
}
fColorChooser.setIsDefaultColor(isDefaultColor);
}

void dispose() {
removeListeners();
section = null;
fColorChooser = null;
}

private void addListeners() {
if(fColorChooser != null) {
fColorChooser.addListener(colorListener);
}

ArchiPlugin.PREFERENCES.addPropertyChangeListener(prefsListener);
}

private void removeListeners() {
if(fColorChooser != null) {
fColorChooser.removeListener(colorListener);
}

ArchiPlugin.PREFERENCES.removePropertyChangeListener(prefsListener);
}
}
Loading

0 comments on commit e45556e

Please sign in to comment.