Skip to content

Commit

Permalink
[Property Sections] Refactor multi-composite sections
Browse files Browse the repository at this point in the history
- Refactor into AbstractMultiControlSection
- Don't show a control if the multi-selection contains an object that is not valid
- This is how it works for Sections with one control
  • Loading branch information
Phillipus committed Oct 7, 2024
1 parent 0bd818b commit 474deb9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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$

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -151,7 +132,5 @@ public void dispose() {
gradientComposite.dispose();
gradientComposite = null;
}

columnHandler = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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$

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -151,7 +132,5 @@ public void dispose() {
lineWidthComposite.dispose();
lineWidthComposite = null;
}

columnHandler = null;
}
}

0 comments on commit 474deb9

Please sign in to comment.