diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/AbstractMultiControlSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/AbstractMultiControlSection.java new file mode 100644 index 000000000..986feb880 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/AbstractMultiControlSection.java @@ -0,0 +1,66 @@ +/** + * 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.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + +import com.archimatetool.model.IArchimateModelObject; + + + +/** + * Abstract Property Section that contains two or more controls that update and layout according to the selection + * + * @author Phillip Beauvoir + */ +public abstract class AbstractMultiControlSection extends AbstractECorePropertySection { + + protected Composite parentComposite; + protected GridLayoutColumnHandler columnHandler; + + /** + * Create controls and set number of columns + * @param parent + * @param numColumns + */ + protected void init(Composite parent, int numColumns) { + parentComposite = parent; + ((GridLayout)parent.getLayout()).horizontalSpacing = 30; + columnHandler = GridLayoutColumnHandler.create(parentComposite, numColumns); + } + + /** + * @param featureName + * @return true if a control shouldbe shown according to its feature + */ + protected boolean shouldShowControl(String featureName) { + for(IArchimateModelObject object : getEObjects()) { + if(!getFilter().shouldExposeFeature(object, featureName)) { + return false; + } + } + return true; + } + + /** + * Layout controls + */ + protected void layout() { + if(columnHandler != null) { + columnHandler.updateColumns(); + } + + parentComposite.requestLayout(); + } + + @Override + public void dispose() { + super.dispose(); + columnHandler = null; + parentComposite = null; + } +} 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 578ac0858..5d5611530 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorSection.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/FillColorSection.java @@ -6,7 +6,6 @@ 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; @@ -20,7 +19,7 @@ * * @author Phillip Beauvoir */ -public class FillColorSection extends AbstractECorePropertySection { +public class FillColorSection extends AbstractMultiControlSection { private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ @@ -41,16 +40,12 @@ public Class getAdaptableType() { } } - private Composite parentComposite; private FillColorComposite fillColorComposite; private GradientComposite gradientComposite; - private GridLayoutColumnHandler columnHandler; @Override protected void createControls(Composite parent) { - parentComposite = parent; - - ((GridLayout)parent.getLayout()).horizontalSpacing = 30; + init(parent, 2); // Help ID PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); @@ -77,16 +72,10 @@ else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { protected void update() { updateColorControl(); updateGradientControl(); - - // 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()); + boolean show = shouldShowControl(IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__FILL_COLOR.getName()); if(show) { if(fillColorComposite == null) { @@ -109,7 +98,7 @@ else if(fillColorComposite != null) { } private void updateGradientControl() { - boolean show = getFilter().shouldExposeFeature(getFirstSelectedObject(), IDiagramModelObject.FEATURE_GRADIENT); + boolean show = shouldShowControl(IDiagramModelObject.FEATURE_GRADIENT); if(show) { if(gradientComposite == null) { @@ -125,14 +114,6 @@ else if(gradientComposite != null) { } } - private void layout() { - if(columnHandler != null) { - columnHandler.updateColumns(); - } - - parentComposite.requestLayout(); - } - @Override protected IObjectFilter getFilter() { return new Filter(); @@ -151,7 +132,5 @@ public void dispose() { gradientComposite.dispose(); gradientComposite = null; } - - columnHandler = 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 index b0af9266e..03de4f085 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineSection.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineSection.java @@ -6,7 +6,6 @@ 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; @@ -21,7 +20,7 @@ * * @author Phillip Beauvoir */ -public class LineSection extends AbstractECorePropertySection { +public class LineSection extends AbstractMultiControlSection { private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$ @@ -42,16 +41,12 @@ public Class getAdaptableType() { } } - 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; + init(parent, 2); // Help ID PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); @@ -78,16 +73,10 @@ else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { 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()); + boolean show = shouldShowControl(IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName()); if(show) { if(lineColorComposite == null) { @@ -109,7 +98,7 @@ else if(lineColorComposite != null) { } private void updateLineWidthControl() { - boolean show = getFilter().shouldExposeFeature(getFirstSelectedObject(), IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName()); + boolean show = shouldShowControl(IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName()); if(show) { if(lineWidthComposite == null) { @@ -125,14 +114,6 @@ else if(lineWidthComposite != null) { } } - private void layout() { - if(columnHandler != null) { - columnHandler.updateColumns(); - } - - parentComposite.requestLayout(); - } - @Override protected IObjectFilter getFilter() { return new Filter(); @@ -151,7 +132,5 @@ public void dispose() { lineWidthComposite.dispose(); lineWidthComposite = null; } - - columnHandler = null; } }