From 90af08dc524f9ce2565bb726b9b0f6b20781b1dd Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 20 Jan 2010 16:12:22 +0000 Subject: [PATCH] Multiple dependency arrows show only one dependency in the table git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13571 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/equation/EquationView.java | 69 +++++++++++-------- .../sysdyn/ui/equation/ShortcutTabs.java | 16 ++--- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java index 742ae5a3..b39f0044 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java @@ -48,10 +48,10 @@ public class EquationView extends ViewPart implements ISelectionListener { //Resources Resource variable; Resource configuration; - + boolean disposed = false; org.eclipse.ui.IPartListener2 focusLostListener; - + ShortcutTabs shortcutTabs; ExpressionTypeSelector expressionController; Composite unitComposite; @@ -62,7 +62,7 @@ public class EquationView extends ViewPart implements ISelectionListener { Text nameText; Composite unitsAndRange; Composite emptyComposite; - + @Override public void createPartControl(Composite parent) { // Listeners @@ -81,7 +81,7 @@ public class EquationView extends ViewPart implements ISelectionListener { expressionComposite.save(); } - + // Save unit if(unitSelector != null) { unitSelector.save(); @@ -104,18 +104,18 @@ public class EquationView extends ViewPart implements ISelectionListener { nameText.setFont(FONT); GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText); - + // Upper part of the view: Expression type expressionController = new ExpressionTypeSelector(parent, SWT.NONE); GridDataFactory.fillDefaults().applyTo(expressionController); addVariableTypeSelectionListener(); - + // Upper part of the view: Unit input/selection unitComposite = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().applyTo(unitComposite); GridLayoutFactory.fillDefaults().applyTo(unitComposite); unitSelector = new UnitSelector(unitComposite, SWT.NONE); - + // Center of the view: variables and possible functions shortcutTabs = new ShortcutTabs(parent, SWT.NONE); GridDataFactory.fillDefaults().span(1, 4).applyTo(shortcutTabs); @@ -129,7 +129,7 @@ public class EquationView extends ViewPart implements ISelectionListener { // Below variable name: Equation expressionComposite = new ExpressionComposite(parent, SWT.NONE); GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(expressionComposite); - + // Lower part of the view: Units and Range unitsAndRange = new Composite(parent, SWT.NONE); @@ -199,7 +199,7 @@ public class EquationView extends ViewPart implements ISelectionListener { @Override public void run(){ - + if(configuration == null || !configuration.equals(result.configuration)) { configuration = result.configuration; if(unitSelector!= null) { @@ -209,15 +209,15 @@ public class EquationView extends ViewPart implements ISelectionListener { } else { unitSelector.updateUnits(variable); } - + if(shortcutTabs != null) shortcutTabs.updateTables(variable); - + String expressionType = expressionComposite.resetExpressionView(variable); addExpressionFieldListeners(); validateExpressionFields(); expressionController.setExpressionTypes(expressionComposite.getExpressionTypes()); expressionController.select(expressionType); - + nameText.setText(result.name); } }); @@ -238,17 +238,17 @@ public class EquationView extends ViewPart implements ISelectionListener { @Override public void setFocus() { if(expressionComposite != null) - expressionComposite.focus(); + expressionComposite.focus(); } - + @Override public void dispose() { disposed = true; getViewSite().getPage().removePartListener(focusLostListener); super.dispose(); } - - + + private void addVariableTypeSelectionListener() { expressionController.getTypeCombo().addSelectionListener(new SelectionListener() { @@ -264,7 +264,7 @@ public class EquationView extends ViewPart implements ISelectionListener { } }); } - + private void addVariableTableListeners() { final Table variableTable = this.shortcutTabs.getVariableTable(); variableTable.addMouseListener(new MouseListener(){ @@ -309,24 +309,24 @@ public class EquationView extends ViewPart implements ISelectionListener { }); } - + private void addExpressionFieldListeners() { - if(expressionComposite.getExpressionViewFactor() != null) - for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields()) { - text.addModifyListener(new ModifyListener() { + if(expressionComposite.getExpressionViewFactor() != null) + for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields()) { + text.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - validateExpressionFields(); - } - }); - } + @Override + public void modifyText(ModifyEvent e) { + validateExpressionFields(); + } + }); + } } - + private void validateExpressionFields() { ExpressionParser parser = new ExpressionParser(new StringReader("")); Set variables = new HashSet(); - + if(expressionComposite.getExpressionViewFactor() != null) for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields()) { String textString = text.getText(); @@ -340,7 +340,7 @@ public class EquationView extends ViewPart implements ISelectionListener { return; } } - + for(TableItem ti : this.shortcutTabs.getVariableTable().getItems()) { if(!variables.contains(ti.getText())) { for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields()) @@ -348,7 +348,16 @@ public class EquationView extends ViewPart implements ISelectionListener { ti.setBackground(new Color(ti.getDisplay(), 255, 230, 230)); } else { ti.setBackground(new Color(ti.getDisplay(), 255, 255, 255)); + variables.remove(ti.getText()); + } + } + + if(!variables.isEmpty()) { + String no_connections = "No connections for: "; + for(String s : variables) { + no_connections = no_connections + s + " "; } + System.out.println(no_connections); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ShortcutTabs.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ShortcutTabs.java index 533b6312..0835eb68 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ShortcutTabs.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ShortcutTabs.java @@ -1,7 +1,7 @@ package org.simantics.sysdyn.ui.equation; -import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -55,8 +55,8 @@ public class ShortcutTabs extends Composite { this.layout(); } - public ArrayList updateTables(Resource variable) { - ArrayList dependencies = getDependencies(variable); + public HashSet updateTables(Resource variable) { + HashSet dependencies = getDependencies(variable); variableTable.removeAll(); TableItem item; for(String d : dependencies) { @@ -67,15 +67,15 @@ public class ShortcutTabs extends Composite { } // Returns the names of the related variables (dependencies) - private ArrayList getDependencies(final Resource r){ - ArrayList variables = null; + private HashSet getDependencies(final Resource r){ + HashSet variables = null; try { - variables = SimanticsUI.getSession().syncRequest(new Read>() { + variables = SimanticsUI.getSession().syncRequest(new Read>() { @Override - public ArrayList perform(ReadGraph graph) + public HashSet perform(ReadGraph graph) throws DatabaseException { - ArrayList variables = new ArrayList(); + HashSet variables = new HashSet(); SysdynResource sr = SysdynResource.getInstance(graph); Builtins b = graph.getBuiltins(); -- 2.47.1