diff --git a/com.archimatetool.editor/plugin.xml b/com.archimatetool.editor/plugin.xml index 50854fe2f..b6a8a4996 100644 --- a/com.archimatetool.editor/plugin.xml +++ b/com.archimatetool.editor/plugin.xml @@ -417,30 +417,30 @@ - - { + 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); + } +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorSection.java index dbfb5a7bd..99f84a3db 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorSection.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorSection.java @@ -6,30 +6,17 @@ package com.archimatetool.editor.propertysections; import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EAttribute; -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.jface.util.PropertyChangeEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; -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.IArchimatePackage; import com.archimatetool.model.IDiagramModelObject; /** - * Property Section for a Fill Color + * Property Section for a Fill Color and Gradient * * @author Phillip Beauvoir */ @@ -37,15 +24,15 @@ public class FillColorSection extends AbstractECorePropertySection { private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ - private static EAttribute FEATURE = IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__FILL_COLOR; - /** * Filter to show or reject this section depending on input value */ public static class Filter extends ObjectFilter { @Override public boolean isRequiredType(Object object) { - return (object instanceof IDiagramModelObject) && shouldExposeFeature((EObject)object, FEATURE.getName()); + return object instanceof IDiagramModelObject dmo && + (shouldExposeFeature(dmo, IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__FILL_COLOR.getName()) + || shouldExposeFeature(dmo, IDiagramModelObject.FEATURE_GRADIENT)); } @Override @@ -54,92 +41,35 @@ public Class getAdaptableType() { } } - /** - * Color listener - */ - private IPropertyChangeListener colorListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - if(event.getProperty() == ColorChooser.PROP_COLORCHANGE) { - CompoundCommand result = new CompoundCommand(); - - RGB rgb = fColorChooser.getColorValue(); - String newColor = ColorFactory.convertRGBToString(rgb); - - for(EObject dmo : getEObjects()) { - if(isAlive(dmo) && !isLocked(dmo)) { - Command cmd = new FillColorCommand((IDiagramModelObject)dmo, newColor); - if(cmd.canExecute()) { - result.add(cmd); - } - } - } - - executeCommand(result.unwrap()); - } - else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) { - CompoundCommand result = new CompoundCommand(); - - for(EObject dmo : getEObjects()) { - if(isAlive(dmo) && !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); - } - } - } - - executeCommand(result.unwrap()); - } - } - }; - - /** - * Listen to default fill colour change in Prefs - */ - private IPropertyChangeListener prefsListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent 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 - update(); - } - } - }; - - private ColorChooser fColorChooser; + private Composite parentComposite; + private FillColorComposite fillColorComposite; + private GradientComposite gradientComposite; + private GridLayoutColumnHandler columnHandler; @Override protected void createControls(Composite parent) { - createColorControl(parent); + parentComposite = parent; - ArchiPlugin.PREFERENCES.addPropertyChangeListener(prefsListener); + ((GridLayout)parent.getLayout()).horizontalSpacing = 30; // Help ID PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); } - private void createColorControl(Composite parent) { - createLabel(parent, Messages.FillColorSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); - - fColorChooser = new ColorChooser(parent, getWidgetFactory()); - fColorChooser.addListener(colorListener); - } - @Override protected void notifyChanged(Notification msg) { if(msg.getNotifier() == getFirstSelectedObject()) { Object feature = msg.getFeature(); - if(feature == FEATURE || feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { + if(feature == IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__FILL_COLOR) { + updateColorControl(); // update also when executing command in case "default" is chosen + } + else if(isFeatureNotification(msg, IDiagramModelObject.FEATURE_GRADIENT)) { + if(!fIsExecutingCommand) { + updateGradientControl(); + } + } + else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { update(); } } @@ -147,24 +77,46 @@ protected void notifyChanged(Notification msg) { @Override protected void update() { - IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject(); + updateColorControl(); + updateGradientControl(); - String colorValue = lastSelected.getFillColor(); - RGB rgb = ColorFactory.convertStringToRGB(colorValue); - if(rgb == null) { - rgb = ColorFactory.getDefaultFillColor(lastSelected).getRGB(); + // Allow setting 1 or 2 columns + if(columnHandler == null) { + columnHandler = GridLayoutColumnHandler.create(parentComposite, 2); + columnHandler.updateColumns(); } + } + + private void updateColorControl() { + boolean show = getFilter().shouldExposeFeature(getFirstSelectedObject(), IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__FILL_COLOR.getName()); - fColorChooser.setColorValue(rgb); - - fColorChooser.setEnabled(!isLocked(lastSelected)); + if(show) { + if(fillColorComposite == null) { + fillColorComposite = new FillColorComposite(this, parentComposite); + } + fillColorComposite.updateControl(); + } + else if(fillColorComposite != null) { + fillColorComposite.dispose(); + fillColorComposite = null; + return; + } + } + + private void updateGradientControl() { + boolean show = getFilter().shouldExposeFeature(getFirstSelectedObject(), IDiagramModelObject.FEATURE_GRADIENT); - // 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()); + if(show) { + if(gradientComposite == null) { + gradientComposite = new GradientComposite(this, parentComposite); + } + gradientComposite.updateControl(); + } + else if(gradientComposite != null) { + gradientComposite.dispose(); + gradientComposite = null; + return; } - fColorChooser.setIsDefaultColor(isDefaultColor); } @Override @@ -176,10 +128,16 @@ protected IObjectFilter getFilter() { public void dispose() { super.dispose(); - if(fColorChooser != null) { - fColorChooser.removeListener(colorListener); + if(fillColorComposite != null) { + fillColorComposite.dispose(); + fillColorComposite = null; + } + + if(gradientComposite != null) { + gradientComposite.dispose(); + gradientComposite = null; } - ArchiPlugin.PREFERENCES.removePropertyChangeListener(prefsListener); + columnHandler = null; } } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillOpacitySection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillOpacitySection.java new file mode 100644 index 000000000..51eebab59 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillOpacitySection.java @@ -0,0 +1,100 @@ +/** + * 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.common.notify.Notification; +import org.eclipse.gef.commands.Command; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; + +import com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand; +import com.archimatetool.model.IArchimatePackage; +import com.archimatetool.model.IDiagramModelObject; + + + +/** + * Property Section for Fill Opacity + * + * @author Phillip Beauvoir + */ +public class FillOpacitySection extends AbstractECorePropertySection { + + private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ + + /** + * Filter to show or reject this section depending on input value + */ + public static class Filter extends ObjectFilter { + @Override + public boolean isRequiredType(Object object) { + return object instanceof IDiagramModelObject dmo && shouldExposeFeature(dmo, IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__ALPHA.getName()); + } + + @Override + public Class getAdaptableType() { + return IDiagramModelObject.class; + } + } + + private OpacityComposite fOpacityComposite; + + @Override + protected void createControls(Composite parent) { + fOpacityComposite = new OpacityComposite(this, parent, Messages.FillOpacitySection_0) { + @Override + Command getCommand(IDiagramModelObject dmo, int newValue) { + return new DiagramModelObjectAlphaCommand(dmo, newValue); + } + + @Override + int getValue() { + IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject(); + return lastSelected.getAlpha(); + } + }; + + // Help ID + PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); + } + + @Override + protected void notifyChanged(Notification msg) { + if(msg.getNotifier() == getFirstSelectedObject()) { + Object feature = msg.getFeature(); + + if(feature == IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__ALPHA) { + if(!fIsExecutingCommand) { + update(); + } + } + else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { + update(); + } + } + } + + @Override + protected void update() { + fOpacityComposite.updateControl(); + } + + @Override + protected IObjectFilter getFilter() { + return new Filter(); + } + + @Override + public void dispose() { + super.dispose(); + + if(fOpacityComposite != null) { + fOpacityComposite.dispose(); + fOpacityComposite = null; + } + } + +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientComposite.java new file mode 100644 index 000000000..145b76b29 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientComposite.java @@ -0,0 +1,82 @@ +/** + * 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.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + +import com.archimatetool.editor.model.commands.FeatureCommand; +import com.archimatetool.model.IDiagramModelObject; +import com.archimatetool.model.IFeatures; + + +/** + * Gradient Composite + * + * @author Phillip Beauvoir + */ +class GradientComposite { + + private static String[] GRADIENT_STYLES = { + Messages.GradientSection_2, + Messages.GradientSection_3, + Messages.GradientSection_4, + Messages.GradientSection_5, + Messages.GradientSection_6, + }; + + private Combo fGradientCombo; + private AbstractECorePropertySection section; + + GradientComposite(AbstractECorePropertySection section, Composite parent) { + this.section = section; + createGradientControl(section.createComposite(parent, 2, false)); + } + + private void createGradientControl(Composite parent) { + section.createLabel(parent, Messages.GradientSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); + + fGradientCombo = new Combo(parent, SWT.READ_ONLY); + section.getWidgetFactory().adapt(fGradientCombo, true, true); + fGradientCombo.setItems(GRADIENT_STYLES); + + fGradientCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + CompoundCommand result = new CompoundCommand(); + + for(EObject object : section.getEObjects()) { + if(section.isAlive(object)) { + Command cmd = new FeatureCommand(Messages.GradientSection_1, (IFeatures)object, + IDiagramModelObject.FEATURE_GRADIENT, fGradientCombo.getSelectionIndex() - 1, IDiagramModelObject.FEATURE_GRADIENT_DEFAULT); + if(cmd.canExecute()) { + result.add(cmd); + } + } + } + + section.executeCommand(result.unwrap()); + } + }); + } + + void updateControl() { + IDiagramModelObject lastSelected = (IDiagramModelObject)section.getFirstSelectedObject(); + fGradientCombo.select(lastSelected.getGradient() + 1); + fGradientCombo.setEnabled(!section.isLocked(lastSelected)); + } + + void dispose() { + section = null; + fGradientCombo = null; + } +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientSection.java deleted file mode 100644 index 198d783d0..000000000 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GradientSection.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * 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.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; - -import com.archimatetool.editor.model.commands.FeatureCommand; -import com.archimatetool.model.IArchimatePackage; -import com.archimatetool.model.IDiagramModelObject; -import com.archimatetool.model.IFeatures; - - - -/** - * Gradient Section - * - * @author Phillip Beauvoir - */ -public class GradientSection extends AbstractECorePropertySection { - - private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ - - /** - * Filter to show or reject this section depending on input value - */ - public static class Filter extends ObjectFilter { - @Override - public boolean isRequiredType(Object object) { - return (object instanceof IDiagramModelObject) && shouldExposeFeature((EObject)object, IDiagramModelObject.FEATURE_GRADIENT); - } - - @Override - public Class getAdaptableType() { - return IDiagramModelObject.class; - } - } - - private Combo fGradientCombo; - - private String[] GRADIENT_STYLES = { - Messages.GradientSection_2, - Messages.GradientSection_3, - Messages.GradientSection_4, - Messages.GradientSection_5, - Messages.GradientSection_6, - }; - @Override - protected void createControls(Composite parent) { - createGradientControl(parent); - - // Help ID - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); - } - - private void createGradientControl(Composite parent) { - createLabel(parent, Messages.GradientSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); - - fGradientCombo = new Combo(parent, SWT.READ_ONLY); - getWidgetFactory().adapt(fGradientCombo, true, true); - fGradientCombo.setItems(GRADIENT_STYLES); - - fGradientCombo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - CompoundCommand result = new CompoundCommand(); - - for(EObject object : getEObjects()) { - if(isAlive(object)) { - Command cmd = new FeatureCommand(Messages.GradientSection_1, (IFeatures)object, - IDiagramModelObject.FEATURE_GRADIENT, fGradientCombo.getSelectionIndex() - 1, IDiagramModelObject.FEATURE_GRADIENT_DEFAULT); - if(cmd.canExecute()) { - result.add(cmd); - } - } - } - - executeCommand(result.unwrap()); - } - }); - } - - @Override - protected void notifyChanged(Notification msg) { - if(msg.getNotifier() == getFirstSelectedObject()) { - Object feature = msg.getFeature(); - if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { - update(); - } - } - - // Notifier is the Feature - if(isFeatureNotification(msg, IDiagramModelObject.FEATURE_GRADIENT)) { - refreshGradientButton(); - } - } - - @Override - protected void update() { - refreshGradientButton(); - } - - protected void refreshGradientButton() { - if(fIsExecutingCommand) { - return; - } - - IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject(); - fGradientCombo.select(lastSelected.getGradient() + 1); - - fGradientCombo.setEnabled(!isLocked(lastSelected)); - } - - @Override - protected IObjectFilter getFilter() { - return new Filter(); - } -} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GridLayoutColumnHandler.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GridLayoutColumnHandler.java index ec02bb126..0363c905b 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GridLayoutColumnHandler.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/GridLayoutColumnHandler.java @@ -6,7 +6,6 @@ package com.archimatetool.editor.propertysections; import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -29,13 +28,10 @@ public static GridLayoutColumnHandler create(Composite parent, int maxColumns) { private int maxColumns; private Composite parent; - IPropertyChangeListener listener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - if(IPreferenceConstants.PROPERTIES_SINGLE_COLUMN.equals(event.getProperty())) { - updateColumns(); - parent.requestLayout(); - } + IPropertyChangeListener listener = event -> { + if(IPreferenceConstants.PROPERTIES_SINGLE_COLUMN.equals(event.getProperty())) { + updateColumns(); + parent.requestLayout(); } }; @@ -45,6 +41,7 @@ private GridLayoutColumnHandler(Composite parent, int maxColumns) { parent.addDisposeListener((e) -> { ArchiPlugin.PREFERENCES.removePropertyChangeListener(listener); + this.parent = null; }); ArchiPlugin.PREFERENCES.addPropertyChangeListener(listener); diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/IconColorSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/IconColorSection.java index 183a10f16..eea419529 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/IconColorSection.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/IconColorSection.java @@ -54,7 +54,7 @@ public Class getAdaptableType() { /** * Color listener */ - private IPropertyChangeListener colorListener = (event) -> { + private IPropertyChangeListener colorListener = event -> { String newColor = IDiagramModelObject.FEATURE_ICON_COLOR_DEFAULT; // User changed color @@ -97,15 +97,11 @@ private void createColorControl(Composite parent) { protected void notifyChanged(Notification msg) { if(msg.getNotifier() == getFirstSelectedObject()) { Object feature = msg.getFeature(); - if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { - update(); + + if(isFeatureNotification(msg, IDiagramModelObject.FEATURE_ICON_COLOR) || feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { + update(); // Update in all cases } } - - // Notifier is the Feature - if(isFeatureNotification(msg, IDiagramModelObject.FEATURE_ICON_COLOR)) { - update(); - } } @Override diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorComposite.java new file mode 100644 index 000000000..7251f2ff0 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorComposite.java @@ -0,0 +1,191 @@ +/** + * 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.action.Action; +import org.eclipse.jface.action.IAction; +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.LineColorCommand; +import com.archimatetool.editor.model.commands.FeatureCommand; +import com.archimatetool.editor.preferences.IPreferenceConstants; +import com.archimatetool.editor.ui.ColorFactory; +import com.archimatetool.editor.ui.components.ColorChooser; +import com.archimatetool.model.IDiagramModelObject; +import com.archimatetool.model.ILineObject; + + + +/** + * Line Color Composite + * + * @author Phillip Beauvoir + */ +class LineColorComposite { + + private ColorChooser fColorChooser; + private Action fDeriveLineColorAction; + private AbstractECorePropertySection section; + + LineColorComposite(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 lineObject : section.getEObjects()) { + if(section.isAlive(lineObject)) { + Command cmd = new LineColorCommand((ILineObject)lineObject, newColor); + if(cmd.canExecute()) { + result.add(cmd); + } + } + } + } + else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) { + for(EObject lineObject : section.getEObjects()) { + if(section.isAlive(lineObject)) { + // 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.getDefaultLineColor(lineObject); + rgbValue = ColorFactory.convertColorToString(color); + } + + Command cmd = new LineColorCommand((ILineObject)lineObject, rgbValue); + if(cmd.canExecute()) { + result.add(cmd); + } + } + } + } + + section.executeCommand(result.unwrap()); + }; + + /** + * Listen to default line colour changes in Prefs + */ + private IPropertyChangeListener prefsListener = event -> { + if(event.getProperty().equals(IPreferenceConstants.DEFAULT_ELEMENT_LINE_COLOR) || + event.getProperty().equals(IPreferenceConstants.DEFAULT_CONNECTION_LINE_COLOR) || + 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.LineColorSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); + + fColorChooser = new ColorChooser(parent, section.getWidgetFactory()); + + // Derive line color from fill color action + fDeriveLineColorAction = new Action(Messages.LineColorSection_3, IAction.AS_CHECK_BOX) { + @Override + 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, + fDeriveLineColorAction.isChecked(), IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT); + if(cmd.canExecute()) { + result.add(cmd); + } + } + } + + section.executeCommand(result.unwrap()); + } + }; + } + + void updateControl() { + ILineObject lineObject = (ILineObject)section.getFirstSelectedObject(); + + String colorValue = lineObject.getLineColor(); + RGB rgb = ColorFactory.convertStringToRGB(colorValue); + if(rgb == null) { + rgb = ColorFactory.getDefaultLineColor(lineObject).getRGB(); + } + + fColorChooser.setColorValue(rgb); + + // Locked + boolean enabled = !section.isLocked(lineObject); + + fColorChooser.setEnabled(enabled); + + if(!enabled) { + return; + } + + // 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) { + boolean deriveElementLineColor = dmo.getDeriveElementLineColor(); + fColorChooser.setDoShowColorImage(!deriveElementLineColor); + fColorChooser.getColorButton().setEnabled(!deriveElementLineColor); + fColorChooser.setDoShowDefaultMenuItem(!deriveElementLineColor); + + fColorChooser.addMenuAction(fDeriveLineColorAction); + fDeriveLineColorAction.setChecked(deriveElementLineColor); + } + else { + fColorChooser.setDoShowColorImage(true); + fColorChooser.getColorButton().setEnabled(true); + fColorChooser.setDoShowDefaultMenuItem(true); + } + } + + 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); + } +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorSection.java deleted file mode 100644 index d36190a73..000000000 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorSection.java +++ /dev/null @@ -1,232 +0,0 @@ -/** - * 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.common.notify.Notification; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; - -import com.archimatetool.editor.ArchiPlugin; -import com.archimatetool.editor.diagram.commands.LineColorCommand; -import com.archimatetool.editor.model.commands.FeatureCommand; -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.ILineObject; - - - -/** - * Property Section for a Line Color - * - * @author Phillip Beauvoir - */ -public class LineColorSection extends AbstractECorePropertySection { - - private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ - - private static EAttribute FEATURE = IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR; - - /** - * Filter to show or reject this section depending on input value - */ - public static class Filter extends ObjectFilter { - @Override - public boolean isRequiredType(Object object) { - return (object instanceof ILineObject) && shouldExposeFeature((EObject)object, FEATURE.getName()); - } - - @Override - public Class getAdaptableType() { - return ILineObject.class; - } - } - - /** - * Color listener - */ - private IPropertyChangeListener colorListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - CompoundCommand result = new CompoundCommand(); - - if(event.getProperty() == ColorChooser.PROP_COLORCHANGE) { - RGB rgb = fColorChooser.getColorValue(); - String newColor = ColorFactory.convertRGBToString(rgb); - - for(EObject lineObject : getEObjects()) { - if(isAlive(lineObject)) { - Command cmd = new LineColorCommand((ILineObject)lineObject, newColor); - if(cmd.canExecute()) { - result.add(cmd); - } - } - } - } - else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) { - for(EObject lineObject : getEObjects()) { - if(isAlive(lineObject)) { - // 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.getDefaultLineColor(lineObject); - rgbValue = ColorFactory.convertColorToString(color); - } - - Command cmd = new LineColorCommand((ILineObject)lineObject, rgbValue); - if(cmd.canExecute()) { - result.add(cmd); - } - } - } - } - - executeCommand(result.unwrap()); - } - }; - - /** - * Listen to default element line colour change in Prefs - */ - private IPropertyChangeListener prefsListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - if(event.getProperty().equals(IPreferenceConstants.DEFAULT_ELEMENT_LINE_COLOR) || - event.getProperty().equals(IPreferenceConstants.DEFAULT_CONNECTION_LINE_COLOR) || - event.getProperty().equals(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) { // This will affect the "Default" menu in color chooser - update(); - } - } - }; - - private ColorChooser fColorChooser; - private Action fDeriveLineColorAction; - - - @Override - protected void createControls(Composite parent) { - createColorControl(parent); - - ArchiPlugin.PREFERENCES.addPropertyChangeListener(prefsListener); - - // Help ID - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); - } - - private void createColorControl(Composite parent) { - createLabel(parent, Messages.LineColorSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); - - fColorChooser = new ColorChooser(parent, getWidgetFactory()); - fColorChooser.addListener(colorListener); - - // Derive line color from fill color action - fDeriveLineColorAction = new Action(Messages.LineColorSection_3, IAction.AS_CHECK_BOX) { - @Override - public void run() { - CompoundCommand result = new CompoundCommand(); - - for(EObject object : getEObjects()) { - if(isAlive(object) && object instanceof IDiagramModelObject dmo) { - Command cmd = new FeatureCommand(Messages.LineColorSection_4, dmo, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR, - fDeriveLineColorAction.isChecked(), IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT); - if(cmd.canExecute()) { - result.add(cmd); - } - } - } - - executeCommand(result.unwrap()); - } - }; - } - - @Override - protected void notifyChanged(Notification msg) { - if(msg.getNotifier() == getFirstSelectedObject()) { - Object feature = msg.getFeature(); - - if(feature == FEATURE || feature == IArchimatePackage.Literals.LOCKABLE__LOCKED || - isFeatureNotification(msg, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR)) { - update(); - } - } - } - - @Override - protected void update() { - ILineObject lineObject = (ILineObject)getFirstSelectedObject(); - - String colorValue = lineObject.getLineColor(); - RGB rgb = ColorFactory.convertStringToRGB(colorValue); - if(rgb == null) { - rgb = ColorFactory.getDefaultLineColor(lineObject).getRGB(); - } - - fColorChooser.setColorValue(rgb); - - // Locked - boolean enabled = !isLocked(lineObject); - - fColorChooser.setEnabled(enabled); - - if(!enabled) { - return; - } - - // 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) { - boolean deriveElementLineColor = dmo.getDeriveElementLineColor(); - fColorChooser.setDoShowColorImage(!deriveElementLineColor); - fColorChooser.getColorButton().setEnabled(!deriveElementLineColor); - fColorChooser.setDoShowDefaultMenuItem(!deriveElementLineColor); - - fColorChooser.addMenuAction(fDeriveLineColorAction); - fDeriveLineColorAction.setChecked(deriveElementLineColor); - } - else { - fColorChooser.setDoShowColorImage(true); - fColorChooser.getColorButton().setEnabled(true); - fColorChooser.setDoShowDefaultMenuItem(true); - } - } - - @Override - protected IObjectFilter getFilter() { - return new Filter(); - } - - @Override - public void dispose() { - super.dispose(); - - if(fColorChooser != null) { - fColorChooser.removeListener(colorListener); - } - - ArchiPlugin.PREFERENCES.removePropertyChangeListener(prefsListener); - } -} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineOpacitySection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineOpacitySection.java new file mode 100644 index 000000000..d0f8e0d11 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineOpacitySection.java @@ -0,0 +1,99 @@ +/** + * 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.common.notify.Notification; +import org.eclipse.gef.commands.Command; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; + +import com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand; +import com.archimatetool.model.IArchimatePackage; +import com.archimatetool.model.IDiagramModelObject; + + + +/** + * Property Section for Line Opacity + * + * @author Phillip Beauvoir + */ +public class LineOpacitySection extends AbstractECorePropertySection { + + private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ + + /** + * Filter to show or reject this section depending on input value + */ + public static class Filter extends ObjectFilter { + @Override + public boolean isRequiredType(Object object) { + return object instanceof IDiagramModelObject dmo && shouldExposeFeature(dmo, IDiagramModelObject.FEATURE_LINE_ALPHA); + } + + @Override + public Class getAdaptableType() { + return IDiagramModelObject.class; + } + } + + private OpacityComposite fOpacityComposite; + + @Override + protected void createControls(Composite parent) { + fOpacityComposite = new OpacityComposite(this, parent, Messages.LineOpacitySection_0) { + @Override + Command getCommand(IDiagramModelObject dmo, int newValue) { + return new DiagramModelObjectOutlineAlphaCommand(dmo, newValue); + } + + @Override + int getValue() { + IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject(); + return lastSelected.getLineAlpha(); + } + }; + + // Help ID + PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); + } + + @Override + protected void notifyChanged(Notification msg) { + if(msg.getNotifier() == getFirstSelectedObject()) { + Object feature = msg.getFeature(); + + if(isFeatureNotification(msg, IDiagramModelObject.FEATURE_LINE_ALPHA)) { + if(!fIsExecutingCommand) { + update(); + } + } + else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { + update(); + } + } + } + + @Override + protected void update() { + fOpacityComposite.updateControl(); + } + + @Override + protected IObjectFilter getFilter() { + return new Filter(); + } + + @Override + public void dispose() { + super.dispose(); + + if(fOpacityComposite != null) { + fOpacityComposite.dispose(); + fOpacityComposite = null; + } + } +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineSection.java new file mode 100644 index 000000000..ff3915ac8 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineSection.java @@ -0,0 +1,144 @@ +/** + * 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.common.notify.Notification; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; + +import com.archimatetool.model.IArchimatePackage; +import com.archimatetool.model.IDiagramModelObject; +import com.archimatetool.model.ILineObject; + + + +/** + * Property Section for a Line + * + * @author Phillip Beauvoir + */ +public class LineSection extends AbstractECorePropertySection { + + private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ + + /** + * Filter to show or reject this section depending on input value + */ + public static class Filter extends ObjectFilter { + @Override + public boolean isRequiredType(Object object) { + return object instanceof ILineObject lo && + (shouldExposeFeature(lo, IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName()) + || shouldExposeFeature(lo, IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName())); + } + + @Override + public Class getAdaptableType() { + return ILineObject.class; + } + } + + private Composite parentComposite; + private LineColorComposite lineColorComposite; + private LineWidthComposite lineWidthComposite; + private GridLayoutColumnHandler columnHandler; + + @Override + protected void createControls(Composite parent) { + parentComposite = parent; + + ((GridLayout)parent.getLayout()).horizontalSpacing = 30; + + // Help ID + PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); + } + + @Override + protected void notifyChanged(Notification msg) { + if(msg.getNotifier() == getFirstSelectedObject()) { + Object feature = msg.getFeature(); + + if(feature == IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR || isFeatureNotification(msg, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR)) { + updateColorControl(); // update also when executing command in case "default" or "derive from fill color" is chosen + } + else if(feature == IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH) { + if(!fIsExecutingCommand) { + updateLineWidthControl(); + } + } + else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { + update(); + } + } + } + + @Override + protected void update() { + updateColorControl(); + updateLineWidthControl(); + + // Allow setting 1 or 2 columns + if(columnHandler == null) { + columnHandler = GridLayoutColumnHandler.create(parentComposite, 2); + columnHandler.updateColumns(); + } + } + + private void updateColorControl() { + boolean show = getFilter().shouldExposeFeature(getFirstSelectedObject(), IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName()); + + if(show) { + if(lineColorComposite == null) { + lineColorComposite = new LineColorComposite(this, parentComposite); + } + lineColorComposite.updateControl(); + } + else if(lineColorComposite != null) { + lineColorComposite.dispose(); + lineColorComposite = null; + return; + } + } + + private void updateLineWidthControl() { + boolean show = getFilter().shouldExposeFeature(getFirstSelectedObject(), IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName()); + + if(show) { + if(lineWidthComposite == null) { + lineWidthComposite = new LineWidthComposite(this, parentComposite); + } + lineWidthComposite.updateControl(); + } + else if(lineWidthComposite != null) { + lineWidthComposite.dispose(); + lineWidthComposite = null; + return; + } + } + + @Override + protected IObjectFilter getFilter() { + return new Filter(); + } + + @Override + public void dispose() { + super.dispose(); + + if(lineColorComposite != null) { + lineColorComposite.dispose(); + lineColorComposite = null; + } + + if(lineWidthComposite != null) { + lineWidthComposite.dispose(); + lineWidthComposite = null; + } + + columnHandler = null; + } +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthComposite.java new file mode 100644 index 000000000..a41c4b75b --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthComposite.java @@ -0,0 +1,79 @@ +/** + * 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.swt.SWT; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + +import com.archimatetool.editor.diagram.commands.LineWidthCommand; +import com.archimatetool.model.ILineObject; + + +/** + * Line Width Composite + * + * @author Phillip Beauvoir + */ +class LineWidthComposite { + + private static final String[] comboLineWidthItems = { + Messages.LineWidthSection_1, + Messages.LineWidthSection_2, + Messages.LineWidthSection_3 + }; + + private Combo fComboLineWidth; + private AbstractECorePropertySection section; + + LineWidthComposite(AbstractECorePropertySection section, Composite parent) { + this.section = section; + createLineWidthControl(section.createComposite(parent, 2, false)); + } + + private void createLineWidthControl(Composite parent) { + section.createLabel(parent, Messages.LineWidthSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); + + fComboLineWidth = new Combo(parent, SWT.READ_ONLY); + section.getWidgetFactory().adapt(fComboLineWidth, true, true); + fComboLineWidth.setItems(comboLineWidthItems); + + fComboLineWidth.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { + CompoundCommand result = new CompoundCommand(); + + for(EObject obj : section.getEObjects()) { + if(section.isAlive(obj)) { + Command cmd = new LineWidthCommand((ILineObject)obj, fComboLineWidth.getSelectionIndex() + 1); + if(cmd.canExecute()) { + result.add(cmd); + } + } + } + + section.executeCommand(result.unwrap()); + })); + } + + void updateControl() { + ILineObject lineObject = (ILineObject)section.getFirstSelectedObject(); + + int lineWidth = lineObject.getLineWidth(); + lineWidth = lineWidth < 1 ? 1 : lineWidth > 3 ? 3 : lineWidth; + + fComboLineWidth.select(lineWidth - 1); + + fComboLineWidth.setEnabled(!section.isLocked(lineObject)); + } + + void dispose() { + section = null; + fComboLineWidth = null; + } +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthSection.java deleted file mode 100644 index 51d58a2d6..000000000 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineWidthSection.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * 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.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; - -import com.archimatetool.editor.diagram.commands.LineWidthCommand; -import com.archimatetool.model.IArchimatePackage; -import com.archimatetool.model.ILineObject; - - - -/** - * Line Width Section - * - * @author Phillip Beauvoir - */ -public final class LineWidthSection extends AbstractECorePropertySection { - - private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ - - /** - * Filter to show or reject this section depending on input value - */ - public static class Filter extends ObjectFilter { - @Override - public boolean isRequiredType(Object object) { - return object instanceof ILineObject lo && shouldExposeFeature(lo, IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName()); - } - - @Override - public Class getAdaptableType() { - return ILineObject.class; - } - } - - private Combo fComboLineWidth; - - public static final String[] comboLineWidthItems = { - Messages.LineWidthSection_1, - Messages.LineWidthSection_2, - Messages.LineWidthSection_3 - }; - - @Override - protected void createControls(Composite parent) { - createLineWidthComboControl(parent); - - // Help ID - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); - } - - private void createLineWidthComboControl(Composite parent) { - createLabel(parent, Messages.LineWidthSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); - - fComboLineWidth = new Combo(parent, SWT.READ_ONLY); - getWidgetFactory().adapt(fComboLineWidth, true, true); - fComboLineWidth.setItems(comboLineWidthItems); - - fComboLineWidth.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { - CompoundCommand result = new CompoundCommand(); - - for(EObject obj : getEObjects()) { - if(isAlive(obj)) { - Command cmd = new LineWidthCommand((ILineObject)obj, fComboLineWidth.getSelectionIndex() + 1); - if(cmd.canExecute()) { - result.add(cmd); - } - } - } - - executeCommand(result.unwrap()); - })); - } - - @Override - protected void notifyChanged(Notification msg) { - if(msg.getNotifier() == getFirstSelectedObject()) { - Object feature = msg.getFeature(); - - if(feature == IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH) { - refreshLineWidthCombo(); - } - else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { - update(); - } - } - } - - @Override - protected void update() { - refreshLineWidthCombo(); - } - - private void refreshLineWidthCombo() { - if(fIsExecutingCommand) { - return; - } - - ILineObject firstSelected = (ILineObject)getFirstSelectedObject(); - - int lineWidth = firstSelected.getLineWidth(); - lineWidth = lineWidth < 1 ? 1 : lineWidth > 3 ? 3 : lineWidth; - - fComboLineWidth.select(lineWidth - 1); - - fComboLineWidth.setEnabled(!isLocked(firstSelected)); - } - - @Override - protected IObjectFilter getFilter() { - return new Filter(); - } -} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java index 03281495d..f98f4b69c 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java @@ -125,6 +125,8 @@ public class Messages extends NLS { public static String FillColorSection_1; + public static String FillOpacitySection_0; + public static String FontColorSection_0; public static String FontColorSection_1; @@ -243,6 +245,8 @@ public class Messages extends NLS { public static String LineColorSection_4; + public static String LineOpacitySection_0; + public static String LineWidthSection_0; public static String LineWidthSection_1; @@ -261,10 +265,6 @@ public class Messages extends NLS { public static String NoteBorderTypeSection_2; - public static String OpacitySection_0; - - public static String OutlineOpacitySection_0; - public static String PropertiesLabelProvider_0; public static String SketchElementSection_0; diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacityComposite.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacityComposite.java new file mode 100644 index 000000000..6bf351427 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacityComposite.java @@ -0,0 +1,90 @@ +/** + * 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.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Spinner; + +import com.archimatetool.model.IDiagramModelObject; + + + +/** + * Opacity Composite + * + * @author Phillip Beauvoir + */ +abstract class OpacityComposite { + + private Spinner fSpinner; + private AbstractECorePropertySection section; + + OpacityComposite(AbstractECorePropertySection section, Composite parent, String label) { + this.section = section; + createSpinnerControl(section.createComposite(parent, 2, false), label); + } + + private void createSpinnerControl(Composite parent, String label) { + section.createLabel(parent, label, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); + + fSpinner = new Spinner(parent, SWT.BORDER); + + fSpinner.setMinimum(0); + fSpinner.setMaximum(255); + fSpinner.setIncrement(5); + + section.getWidgetFactory().adapt(fSpinner, true, true); + + Listener listener = event -> { + int newValue = fSpinner.getSelection(); + + CompoundCommand result = new CompoundCommand(); + + for(EObject dmo : section.getEObjects()) { + if(section.isAlive(dmo)) { + Command cmd = getCommand((IDiagramModelObject)dmo, newValue); + if(cmd.canExecute()) { + result.add(cmd); + } + } + } + + section.executeCommand(result.unwrap()); + }; + + fSpinner.addListener(SWT.MouseUp, listener); + fSpinner.addListener(SWT.FocusOut, listener); + fSpinner.addListener(SWT.DefaultSelection, listener); + + fSpinner.addDisposeListener(event -> { + if(fSpinner != null && !fSpinner.isDisposed()) { + fSpinner.removeListener(SWT.MouseUp, listener); + fSpinner.removeListener(SWT.FocusOut, listener); + fSpinner.removeListener(SWT.DefaultSelection, listener); + } + }); + } + + abstract Command getCommand(IDiagramModelObject dmo, int newValue); + + abstract int getValue(); + + void updateControl() { + IDiagramModelObject lastSelected = (IDiagramModelObject)section.getFirstSelectedObject(); + fSpinner.setSelection(getValue()); + fSpinner.setEnabled(!section.isLocked(lastSelected)); + } + + void dispose() { + fSpinner = null; + section = null; + } +} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacitySection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacitySection.java deleted file mode 100644 index 2822a9f31..000000000 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/OpacitySection.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * 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.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.ui.PlatformUI; - -import com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand; -import com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand; -import com.archimatetool.model.IArchimatePackage; -import com.archimatetool.model.IDiagramModelObject; - - - -/** - * Property Section for Opacity - * - * @author Phillip Beauvoir - */ -public class OpacitySection extends AbstractECorePropertySection { - - private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ - - /** - * Filter to show or reject this section depending on input value - */ - public static class Filter extends ObjectFilter { - @Override - public boolean isRequiredType(Object object) { - return (object instanceof IDiagramModelObject) && (shouldExposeFeature((EObject)object, IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__ALPHA.getName()) - || shouldExposeFeature((EObject)object, IDiagramModelObject.FEATURE_LINE_ALPHA)); - } - - @Override - public Class getAdaptableType() { - return IDiagramModelObject.class; - } - } - - private Spinner fFillSpinner; - private Spinner fOutlineSpinner; - - @Override - protected void createControls(Composite parent) { - ((GridLayout)parent.getLayout()).horizontalSpacing = 30; - - Composite group1 = createComposite(parent, 2, false); - fFillSpinner = createSpinnerControl(group1, Messages.OpacitySection_0, 0); - - Composite group2 = createComposite(parent, 2, false); - fOutlineSpinner = createSpinnerControl(group2, Messages.OutlineOpacitySection_0, 1); - - // Allow setting 1 or 2 columns - GridLayoutColumnHandler.create(parent, 2).updateColumns(); - - // Help ID - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); - } - - private Spinner createSpinnerControl(Composite parent, String label, int type) { - createLabel(parent, label, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); - - final Spinner spinner = new Spinner(parent, SWT.BORDER); - - spinner.setMinimum(0); - spinner.setMaximum(255); - spinner.setIncrement(5); - - getWidgetFactory().adapt(spinner, true, true); - - Listener listener = (e) -> { - int newValue = spinner.getSelection(); - - CompoundCommand result = new CompoundCommand(); - - for(EObject dmo : getEObjects()) { - if(isAlive(dmo)) { - Command cmd; - if(type == 0) { - cmd = new DiagramModelObjectAlphaCommand((IDiagramModelObject)dmo, newValue); - } - else { - cmd = new DiagramModelObjectOutlineAlphaCommand((IDiagramModelObject)dmo, newValue); - } - if(cmd.canExecute()) { - result.add(cmd); - } - } - } - - executeCommand(result.unwrap()); - }; - - spinner.addListener(SWT.MouseUp, listener); - spinner.addListener(SWT.FocusOut, listener); - spinner.addListener(SWT.DefaultSelection, listener); - - spinner.addDisposeListener((e) -> { - if(spinner != null && !spinner.isDisposed()) { - spinner.removeListener(SWT.MouseUp, listener); - spinner.removeListener(SWT.FocusOut, listener); - spinner.removeListener(SWT.DefaultSelection, listener); - } - }); - - return spinner; - } - - @Override - protected void notifyChanged(Notification msg) { - if(msg.getNotifier() == getFirstSelectedObject()) { - Object feature = msg.getFeature(); - - if(feature == IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__ALPHA - || isFeatureNotification(msg, IDiagramModelObject.FEATURE_LINE_ALPHA) - || feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { - update(); - } - } - } - - @Override - protected void update() { - if(fIsExecutingCommand) { - return; - } - - IDiagramModelObject lastSelected = (IDiagramModelObject)getFirstSelectedObject(); - - fFillSpinner.setSelection(lastSelected.getAlpha()); - fOutlineSpinner.setSelection(lastSelected.getLineAlpha()); - - fFillSpinner.setEnabled(!isLocked(lastSelected) && getFilter().shouldExposeFeature(lastSelected, IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__ALPHA.getName())); - fOutlineSpinner.setEnabled(!isLocked(lastSelected) && getFilter().shouldExposeFeature(lastSelected, IDiagramModelObject.FEATURE_LINE_ALPHA)); - } - - @Override - protected IObjectFilter getFilter() { - return new Filter(); - } -} diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties index 9931209a1..741230651 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties @@ -64,6 +64,7 @@ DiagramModelReferenceSection_0=Add a name for this view here FillColorSection_0=Fill Colour: FillColorSection_1=Default +FillOpacitySection_0=Fill Opacity: FontColorSection_0=Font Colour: FontColorSection_1=Default @@ -127,6 +128,7 @@ LineColorSection_1=Default LineColorSection_2=Enable in Preferences LineColorSection_3=Derive from fill colour LineColorSection_4=Derive line colour +LineOpacitySection_0=Line Opacity: LineWidthSection_0=Line Width: LineWidthSection_1=Normal LineWidthSection_2=Medium @@ -139,8 +141,6 @@ NoteBorderTypeSection_0=Dog Ear NoteBorderTypeSection_1=Rectangle NoteBorderTypeSection_2=None -OpacitySection_0=Fill Opacity: -OutlineOpacitySection_0=Outline Opacity: PropertiesLabelProvider_0=(Multiple Selection) SketchElementSection_0=Add a name for this element here