From c45e1ddec8efe605301da09a73545928866adee1 Mon Sep 17 00:00:00 2001 From: miettinen Date: Fri, 15 Nov 2013 11:32:16 +0000 Subject: [PATCH] EquationTab changes layout when the available area changes. (refs #4550) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28307 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 4 +- .../sysdyn/ui/properties/EquationTab.java | 245 ++++++++---------- .../properties/widgets/ShortcutTabWidget.java | 2 +- 3 files changed, 116 insertions(+), 135 deletions(-) diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index f2c00902..d0ecb92e 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -198,8 +198,8 @@ () { - - @Override - public Resource perform(ReadGraph graph) - throws DatabaseException { - return var.getRepresents(graph); - } - }); - input = new StructuredSelection(r); - } catch (DatabaseException e) { - e.printStackTrace(); - } - - } - - super.fireInput(context, input); - } - }; + // Get size of the available area. + spp = body; + do { + spp = spp.getParent(); + } while (!(spp instanceof StandardProperties)); - this.site = site; + // Add listener to change the layout when the composite resizes. + spp.addControlListener(controlListener = new ControlListener(){ - // Composite for the whole tab - Composite composite = new Composite(body, SWT.NONE); + @Override + public void controlMoved(ControlEvent e) {} + + @Override + public void controlResized(ControlEvent e) { + createLayout(); + } + }); + + // Create the controls and their initial layout. + createAndAddControls(body, site, context, _support); + createLayout(); + } + + /** + * Create layout for controls. + */ + private void createLayout() { + Point size = spp.getSize(); + if (size.x > size.y) { + createControlLayoutHorizontal((size.x > 1100)); + } else { + createControlLayoutVertical(); + } + } + + private void createControlLayoutHorizontal(boolean wideScreen) { GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); - // Composite holding name controls and controls for adding and removing expressions - Composite nameComposite = new Composite(composite, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(wideScreen ? 4 : 3).applyTo(nameComposite); + GridDataFactory.fillDefaults().grab(true, true).applyTo(nameComposite); + + GridDataFactory.fillDefaults().grab(true, false).hint(280, SWT.DEFAULT).applyTo(arrayEquationCombo.getWidget()); + GridDataFactory.fillDefaults().applyTo(deleteExpression.getWidget()); + GridDataFactory.fillDefaults().applyTo(newExpression.getWidget()); + + GridDataFactory.fillDefaults().span(1, wideScreen ? 2 : 3).grab(false, true).hint(250, SWT.DEFAULT).applyTo(shortcutTabWidget.getWidget()); + + GridDataFactory.fillDefaults().span(wideScreen ? 1 : 3, 1).grab(true, false).applyTo(TypeAndUnit); + GridLayoutFactory.fillDefaults().numColumns(5).applyTo(TypeAndUnit); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(typeLabel); + GridDataFactory.fillDefaults().applyTo(expressionTypeCombo.getWidget()); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(unitLabel); + GridDataFactory.fillDefaults().grab(true, false).hint(160, SWT.DEFAULT).applyTo(unitCombo.getWidget()); + GridDataFactory.fillDefaults().applyTo(isOutput.getWidget()); + + GridDataFactory.fillDefaults().span(wideScreen ? 4 : 3, 1).grab(true, true).applyTo(expressionComposite); + } + + private void createControlLayoutVertical() { + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(nameComposite); - GridDataFactory.fillDefaults().grab(true, false).applyTo(nameComposite); + GridDataFactory.fillDefaults().grab(true, true).applyTo(nameComposite); - arrayEquationCombo = new ArrayExpressionCombo(nameComposite, support, SWT.DROP_DOWN | SWT.BORDER); - arrayEquationCombo.setInputValidator(new VariableNameInputValidator(support)); GridDataFactory.fillDefaults().grab(true, false).applyTo(arrayEquationCombo.getWidget()); + GridDataFactory.fillDefaults().applyTo(deleteExpression.getWidget()); + GridDataFactory.fillDefaults().applyTo(newExpression.getWidget()); + + GridDataFactory.fillDefaults().span(3, 1).applyTo(TypeAndUnit); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(TypeAndUnit); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(typeLabel); + GridDataFactory.fillDefaults().applyTo(expressionTypeCombo.getWidget()); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(unitLabel); + GridDataFactory.fillDefaults().grab(true, false).hint(160, SWT.DEFAULT).applyTo(unitCombo.getWidget()); + GridDataFactory.fillDefaults().span(3, 1).align(SWT.END, SWT.CENTER).applyTo(isOutput.getWidget()); + + GridDataFactory.fillDefaults().span(3, 1).grab(true, true).hint(SWT.DEFAULT, 250).applyTo(expressionComposite); + GridDataFactory.fillDefaults().span(3, 1).grab(true, true).hint(SWT.DEFAULT, 300).applyTo(shortcutTabWidget.getWidget()); + } + + private void createAndAddControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) { + // Composite for the whole tab + Composite composite = new Composite(body, SWT.NONE); + this.composite = composite; + + // Composite holding name controls and controls for adding and removing expressions + nameComposite = new Composite(composite, SWT.NONE); + arrayEquationCombo = new ArrayExpressionCombo(nameComposite, support, SWT.DROP_DOWN | SWT.BORDER); + arrayEquationCombo.setInputValidator(new VariableNameInputValidator(support)); + arrayEquationCombo.addModifyListener(new NameAndArrayRangeModifyListener(support, expressionWidget, (ArrayExpressionCombo)arrayEquationCombo)); deleteExpression = new Button(nameComposite, support, SWT.NONE); deleteExpression.setText("Delete"); - GridDataFactory.fillDefaults().applyTo(deleteExpression.getWidget()); - newExpression = new Button(nameComposite, support, SWT.NONE); newExpression.setText("New"); - GridDataFactory.fillDefaults().applyTo(newExpression.getWidget()); - + // Shortcut widget. Tabular widget containing tabs for functions and connected variables shortcutTabWidget = new ShortcutTabWidget(composite, support, SWT.NONE); - GridDataFactory.fillDefaults().span(1, 3).grab(false, true).applyTo(shortcutTabWidget.getWidget()); - - // Type and unit selection composite - Composite TypeAndUnit = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(TypeAndUnit); - GridLayoutFactory.fillDefaults().numColumns(5).applyTo(TypeAndUnit); - - Label label = new Label(TypeAndUnit, SWT.SINGLE ); - label.setText("Type:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - + + TypeAndUnit = new Composite(nameComposite, SWT.NONE); + typeLabel = new Label(TypeAndUnit, SWT.SINGLE ); + typeLabel.setText("Type:"); expressionTypeCombo = new TrackedCombo(TypeAndUnit, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); - GridDataFactory.fillDefaults().applyTo(expressionTypeCombo.getWidget()); - - label = new Label(TypeAndUnit, SWT.SINGLE ); - label.setText("Unit:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - + unitLabel = new Label(TypeAndUnit, SWT.SINGLE ); + unitLabel.setText("Unit:"); unitCombo = new TrackedCombo(TypeAndUnit, support, SWT.DROP_DOWN | SWT.BORDER); - GridDataFactory.fillDefaults().applyTo(unitCombo.getWidget()); - - IsOutputWidget isOutput = new IsOutputWidget(TypeAndUnit, support, SWT.NULL); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.FILL).applyTo(isOutput.getWidget()); - + isOutput = new IsOutputWidget(TypeAndUnit, support, SWT.NULL); + // The actual expression - expressionComposite = new ExpressionComposite(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(expressionComposite); + expressionComposite = new ExpressionComposite(nameComposite, SWT.NONE); expressionWidget = new ExpressionWidget(expressionComposite, expressionSupport, SWT.NONE); expressionWidget.setVariableTable(shortcutTabWidget.getVariableTable()); - arrayEquationCombo.addModifyListener(new NameAndArrayRangeModifyListener(support, expressionWidget, (ArrayExpressionCombo)arrayEquationCombo)); - addListeners(context); } - - private void createControlsCompressed(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) { - _support.register(this); - - support = new WidgetSupportImpl() { - + + private void setSupport() { + support = new WidgetSupportImpl() { + @Override public void fireInput(ISessionContext context, Object input) { final Variable var = AdaptionUtils.adaptToSingle(input, Variable.class); @@ -225,62 +260,6 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { super.fireInput(context, input); } }; - - this.site = site; - - // Composite for the whole tab - Composite composite = new Composite(body, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); - - // Composite holding name controls and controls for adding and removing expressions - Composite nameComposite = new Composite(composite, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(8).applyTo(nameComposite); - GridDataFactory.fillDefaults().grab(true, false).applyTo(nameComposite); - - arrayEquationCombo = new ArrayExpressionCombo(nameComposite, support, SWT.DROP_DOWN | SWT.BORDER); - arrayEquationCombo.setInputValidator(new VariableNameInputValidator(support)); - GridDataFactory.fillDefaults().grab(true, false).applyTo(arrayEquationCombo.getWidget()); - - deleteExpression = new Button(nameComposite, support, SWT.NONE); - deleteExpression.setText("Delete"); - GridDataFactory.fillDefaults().applyTo(deleteExpression.getWidget()); - - newExpression = new Button(nameComposite, support, SWT.NONE); - newExpression.setText("New"); - GridDataFactory.fillDefaults().applyTo(newExpression.getWidget()); - - // Shortcut widget. Tabular widget containing tabs for functions and connected variables - shortcutTabWidget = new ShortcutTabWidget(composite, support, SWT.NONE); - GridDataFactory.fillDefaults().span(1, 2).grab(false, true).applyTo(shortcutTabWidget.getWidget()); - - Label label = new Label(nameComposite, SWT.SINGLE ); - label.setText("Type:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - expressionTypeCombo = new TrackedCombo(nameComposite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); - GridDataFactory.fillDefaults().applyTo(expressionTypeCombo.getWidget()); - - label = new Label(nameComposite, SWT.SINGLE ); - label.setText("Unit:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - - unitCombo = new TrackedCombo(nameComposite, support, SWT.DROP_DOWN | SWT.BORDER); - GridDataFactory.fillDefaults().applyTo(unitCombo.getWidget()); - - IsOutputWidget isOutput = new IsOutputWidget(nameComposite, support, SWT.NULL); - GridDataFactory.fillDefaults().applyTo(isOutput.getWidget()); - - // The actual expression - expressionComposite = new ExpressionComposite(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(expressionComposite); - expressionWidget = new ExpressionWidget(expressionComposite, expressionSupport, SWT.NONE); - expressionWidget.setVariableTable(shortcutTabWidget.getVariableTable()); - - arrayEquationCombo.addModifyListener(new NameAndArrayRangeModifyListener(support, expressionWidget, (ArrayExpressionCombo)arrayEquationCombo)); - - addListeners(context); } @Override @@ -787,6 +766,8 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { } if(focusLostListener != null && site != null) site.getPage().removePartListener(focusLostListener); + if(controlListener != null && spp != null) + spp.removeControlListener(controlListener); super.dispose(); if(expressionComposite != null && !expressionComposite.isDisposed()) expressionComposite.dispose(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java index 41f0871f..ab5b0d07 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java @@ -71,7 +71,7 @@ public class ShortcutTabWidget implements Widget { GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite); tabFolder = new TabFolder (composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).applyTo(tabFolder); + GridDataFactory.fillDefaults().grab(true, true).applyTo(tabFolder); GridLayoutFactory.fillDefaults().applyTo(tabFolder); variables = new TabItem(tabFolder, SWT.NULL); variables.setText("Variables"); -- 2.47.1