From fc2175dcf16edceb38dfff55a4cd49496a2b6697 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 5 Nov 2010 13:03:45 +0000 Subject: [PATCH] Old equation view, not needed git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18582 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../AuxiliaryExpressionViewFactor.java | 140 ------ .../ui/equation/expressions/ColorManager.java | 43 -- .../ConstantExpressionViewFactor.java | 140 ------ .../DelayExpressionViewFactor.java | 64 --- .../EmptyExpressionViewFactor.java | 64 --- .../equation/expressions/ExpressionField.java | 165 ------- .../ExpressionFieldConfiguration.java | 180 ------- .../expressions/IExpressionViewFactor.java | 70 --- .../equation/expressions/LookupChartInfo.java | 74 --- .../expressions/LookupChartPanel.java | 163 ------- .../LookupExpressionViewFactor.java | 64 --- .../expressions/LookupInputOutputTable.java | 213 --------- .../ui/equation/expressions/LookupPopup.java | 446 ------------------ .../ParameterExpressionViewFactor.java | 142 ------ .../StockExpressionViewFactor.java | 208 -------- .../WithLookupExpressionViewFactor.java | 221 --------- 16 files changed, 2397 deletions(-) delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/AuxiliaryExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ColorManager.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ConstantExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/DelayExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionFieldConfiguration.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/IExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartInfo.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartPanel.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupInputOutputTable.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupPopup.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ParameterExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionViewFactor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/WithLookupExpressionViewFactor.java diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/AuxiliaryExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/AuxiliaryExpressionViewFactor.java deleted file mode 100644 index 49aa803e..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/AuxiliaryExpressionViewFactor.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; - -public class AuxiliaryExpressionViewFactor implements IExpressionViewFactor { - - private Label equationLabel; - private ExpressionField expression; - - @Override - public void createView(Composite parent, Map data) { - - final String equation = data.get("equation") != null ? (String)data.get("equation") : ""; - - GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(parent); - equationLabel = new Label(parent, SWT.NONE); - equationLabel.setFont(FONT); - equationLabel.setText("="); - GridDataFactory.fillDefaults().applyTo(equationLabel); - - - expression = new ExpressionField(parent, SWT.BORDER); - expression.setFont(FONT); - expression.setExpression(equation); - GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); - - } - - @Override - public void readData(final Resource variable, Map data) { - String equation = null; - if (variable != null && data.get("equation") == null) { - try { - equation = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource expression = graph.getPossibleObject(variable, sr.HasExpression); - if (expression != null && graph.isInstanceOf(expression, sr.NormalExpression)) { - return graph.getRelatedValue(expression, sr.HasEquation); - } else { - return ""; - } - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - data.put("equation", equation); - } - } - - @Override - public void writeData(final Resource variable, Map data) { - final String currentText = expression.getExpression(); - if(currentText != null) { - data.put("equation", currentText); - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph g) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(g); - Resource expression = g.getPossibleObject(variable, sr.HasExpression); - Layer0 l0 = Layer0.getInstance(g); - if(expression != null) { - g.deny(variable, sr.HasExpression); - } - expression = g.newResource(); - g.claim(expression, l0.InstanceOf, null, sr.NormalExpression); - g.claim(variable, sr.HasExpression, expression); - g.claimLiteral(expression, sr.HasEquation, currentText); - } - - }); - } - } - - @Override - public void focus() { - if(this.expression != null) this.expression.focus(); - } - - @Override - public void replaceSelection(String var) { - if(expression != null) { - IDocument doc = expression.getDocument(); - try { - Point selection = expression.getSelection(); - doc.replace(selection.x, selection.y, var); - expression.setSelection(selection.x + var.length()); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - } - - @Override - public void updateData(Map data) { - if(this.expression != null && this.expression.getExpression() != null) - data.put("equation", this.expression.getExpression()); - } - - @Override - public List getExpressionFields() { - return Arrays.asList(this.expression); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ColorManager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ColorManager.java deleted file mode 100644 index 4325a925..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ColorManager.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.HashMap; - -import org.eclipse.jface.text.source.ISharedTextColors; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -public class ColorManager implements ISharedTextColors { - - protected HashMap colorTable = new HashMap(); - - @Override - public void dispose() { - for(Color c : colorTable.values()) - c.dispose(); - colorTable.clear(); - } - - @Override - public Color getColor(RGB rgb) { - Color color = colorTable.get(rgb); - if (color == null) { - color = new Color(Display.getCurrent(), rgb); - colorTable.put(rgb, color); - } - return color; - - - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ConstantExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ConstantExpressionViewFactor.java deleted file mode 100644 index 3d7a65e4..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ConstantExpressionViewFactor.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; - -public class ConstantExpressionViewFactor implements IExpressionViewFactor { - - private Label equationLabel; - private ExpressionField expression; - - @Override - public void createView(Composite parent, Map data) { - - final String equation = data.get("equation") != null ? (String)data.get("equation") : ""; - - GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(parent); - equationLabel = new Label(parent, SWT.NONE); - equationLabel.setFont(FONT); - equationLabel.setText("="); - GridDataFactory.fillDefaults().applyTo(equationLabel); - - - expression = new ExpressionField(parent, SWT.BORDER); - expression.setFont(FONT); - expression.setExpression(equation); - GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); - } - - @Override - public void focus() { - if(this.expression != null) this.expression.focus(); - } - - @Override - public void readData(final Resource variable, Map data) { - String equation = null; - if (variable != null && data.get("equation") == null) { - try { - equation = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource expression = graph.getPossibleObject(variable, sr.HasExpression); - if (expression != null && graph.isInstanceOf(expression, sr.ConstantExpression)) { - return graph.getRelatedValue(expression, sr.HasEquation); - } else { - return ""; - } - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - data.put("equation", equation); - } - } - - @Override - public void replaceSelection(String var) { - if(expression != null) { - IDocument doc = expression.getDocument(); - try { - Point selection = expression.getSelection(); - doc.replace(selection.x, selection.y, var); - expression.setSelection(selection.x + var.length()); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - } - - @Override - public void writeData(final Resource variable, Map data) { - final String currentText = expression.getExpression(); - if(currentText != null) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph g) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(g); - Resource expression = g.getPossibleObject(variable, sr.HasExpression); - Layer0 l0 = Layer0.getInstance(g); - if(expression != null) { - g.deny(variable, sr.HasExpression); - } - expression = g.newResource(); - g.claim(expression, l0.InstanceOf, null, sr.ConstantExpression); - g.claim(variable, sr.HasExpression, expression); - g.claimLiteral(expression, sr.HasEquation, currentText); - } - - }); - } - } - - @Override - public void updateData(Map data) { - if(this.expression != null && this.expression.getExpression() != null) - data.put("equation", this.expression.getExpression()); - } - - @Override - public List getExpressionFields() { - return Arrays.asList(this.expression); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/DelayExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/DelayExpressionViewFactor.java deleted file mode 100644 index da9702ff..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/DelayExpressionViewFactor.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.widgets.Composite; -import org.simantics.db.Resource; - -public class DelayExpressionViewFactor implements IExpressionViewFactor { - - @Override - public void createView(Composite parent, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void focus() { - // TODO Auto-generated method stub - - } - - @Override - public void readData(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void replaceSelection(String var) { - // TODO Auto-generated method stub - - } - - @Override - public void writeData(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void updateData(Map data) { - // TODO Auto-generated method stub - - } - - @Override - public List getExpressionFields() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java deleted file mode 100644 index a3ea40d3..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.widgets.Composite; -import org.simantics.db.Resource; - -public class EmptyExpressionViewFactor implements IExpressionViewFactor { - - @Override - public void createView(Composite parent, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void focus() { - // TODO Auto-generated method stub - - } - - @Override - public List getExpressionFields() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void readData(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void replaceSelection(String var) { - // TODO Auto-generated method stub - - } - - @Override - public void updateData(Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void writeData(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java deleted file mode 100644 index dde64a0d..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.List; - -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.PaintManager; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.AnnotationModel; -import org.eclipse.jface.text.source.AnnotationPainter; -import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; -import org.eclipse.jface.text.source.IAnnotationAccess; -import org.eclipse.jface.text.source.MatchingCharacterPainter; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; -import org.eclipse.swt.graphics.Point; -import org.simantics.sysdyn.expressionParser.Token; - -public class ExpressionField extends Composite { - - protected SourceViewer _sourceViewer; - protected IDocument _document; - protected AnnotationModel _annotationModel; - - ColorManager cManager = new ColorManager(); - - IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess(); - - public ExpressionField(Composite parent, int style) { - super(parent, style); - - GridLayoutFactory.fillDefaults().applyTo(this); - - int styles = SWT.V_SCROLL - | SWT.MULTI - | SWT.FULL_SELECTION - | SWT.WRAP; - - _document = new Document(); - _document.set(""); - - _annotationModel = new AnnotationModel(); - _annotationModel.connect(_document); - - _sourceViewer = new SourceViewer(this, - - null, - null, - true, - styles); - _sourceViewer.configure(new ExpressionFieldConfiguration(cManager)); - - AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess); - _sourceViewer.addPainter(painter); - - painter.addAnnotationType("MissingLink"); - painter.setAnnotationTypeColor("MissingLink", new Color(this.getDisplay(), 255,0,0)); - painter.addAnnotationType("NoSuchVariable"); - painter.setAnnotationTypeColor("NoSuchVariable", new Color(this.getDisplay(), 255,0,0)); - - _sourceViewer.setDocument(_document, _annotationModel); - - _sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL, - SWT.FILL, - true, - true)); - - PaintManager paintManager = new PaintManager(_sourceViewer); - MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(_sourceViewer, - new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} )); - matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160))); - paintManager.addPainter(matchingCharacterPainter); - - - } - - public SourceViewer getSourceViewer() { - return this._sourceViewer; - } - - public void setMissingLinkAnnotations(List positions){ - for(Position p : positions) { - Annotation annotation = new Annotation(false); - annotation.setType("MissingLink"); - annotation.setText("No link to this variable"); - _annotationModel.addAnnotation(annotation, p); - } - } - - public void setNoSuchVariableAnnotations(List positions){ - for(Position p : positions) { - Annotation annotation = new Annotation(false); - annotation.setType("NoSuchVariable"); - annotation.setText("No such variable in model"); - _annotationModel.addAnnotation(annotation, p); - } - } - - public void setSyntaxError(Token token){ - int start = 0; - int offset = this._document.getLength(); - if(token.image != null && this._document.getLength() > 0) { - try { - start = this._document.getLineOffset(token.beginLine - 1) + token.beginColumn - 1; - offset = this._document.getLineOffset(token.endLine - 1) + token.endColumn - start; - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - - Annotation annotation = new Annotation(false); - annotation.setType("MissingLink"); - annotation.setText("Syntax error"); - Position p = new Position(start, offset); - _annotationModel.addAnnotation(annotation, p); - } - - public void resetAnnotations() { - _annotationModel.removeAllAnnotations(); - } - public void setExpression(String expression) { - _document.set(expression); - } - - public String getExpression() { - return this._document.get(); - } - - public Point getSelection() { - return _sourceViewer.getSelectedRange(); - } - - public void setSelection(int selection) { - this._sourceViewer.setSelectedRange(selection, 0); - } - - public IDocument getDocument() { - return _document; - } - - public void focus() { - this._sourceViewer.getTextWidget().forceFocus(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionFieldConfiguration.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionFieldConfiguration.java deleted file mode 100644 index c9b0022e..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionFieldConfiguration.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.jface.text.DefaultTextHover; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.PresentationReconciler; -import org.eclipse.jface.text.rules.DefaultDamagerRepairer; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.ITokenScanner; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.RuleBasedScanner; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.rules.WordRule; -import org.eclipse.jface.text.source.DefaultAnnotationHover; -import org.eclipse.jface.text.source.IAnnotationHover; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.RGB; - -public class ExpressionFieldConfiguration extends SourceViewerConfiguration { - - - ColorManager colorManager; - - public ExpressionFieldConfiguration(ColorManager colorManager) { - super(); - this.colorManager = colorManager; - } - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return new String[] { - IDocument.DEFAULT_CONTENT_TYPE - }; - } - - /* - @Override - public IAutoEditStrategy[] getAutoEditStrategies( - ISourceViewer sourceViewer, String contentType) { - return new IAutoEditStrategy[] { - new ReplaceTabsBySpaces(), - new IndentLineEditStrategy(), - new MatchingBracketsEditStrategy() - }; - } - */ - - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - PresentationReconciler reconciler = new PresentationReconciler(); - - DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner()); - - reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - - return reconciler; - } - - /* - * - */ - ITokenScanner getSclTokenScanner() { - RuleBasedScanner scanner = new RuleBasedScanner(); - - final Token reserved = new Token( - new TextAttribute( - colorManager.getColor(new RGB(127, 0, 85)), - null, - SWT.BOLD - )); - - - WordRule reservedWord = new WordRule(new IWordDetector() { - @Override - public boolean isWordStart(char c) { - return Character.isLetter(c); - } - - @Override - public boolean isWordPart(char c) { - return Character.isLetter(c); - } - }); - - for(String s : keywords) { - reservedWord.addWord(s, reserved); - } - - IRule[] rules = new IRule[] { - reservedWord - }; - scanner.setRules(rules); - - return scanner; - } - - @Override - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { - return new DefaultTextHover(sourceViewer); - } - - @Override - public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { - return new DefaultAnnotationHover(); - } - - static final Set keywords = new HashSet(); - - static { - keywords.add("within"); - keywords.add("final"); - keywords.add("public"); - keywords.add("protected"); - keywords.add("connect"); - keywords.add("when"); - keywords.add("then"); - keywords.add("elsewhen"); - keywords.add("if"); - keywords.add("end"); - keywords.add("elseif"); - keywords.add("else"); - keywords.add("for"); - keywords.add("while"); - keywords.add("loop"); - keywords.add("der"); - keywords.add("enumeration"); - keywords.add("extends"); - keywords.add("class"); - keywords.add("partial"); - keywords.add("encapsulated"); - keywords.add("model"); - keywords.add("record"); - keywords.add("block"); - keywords.add("expandable"); - keywords.add("connector"); - keywords.add("type"); - keywords.add("package"); - keywords.add("function"); - keywords.add("import"); - keywords.add("external"); - keywords.add("constrainedby"); - keywords.add("redeclare"); - keywords.add("replaceable"); - keywords.add("flow"); - keywords.add("discrete"); - keywords.add("parameter"); - keywords.add("constant"); - keywords.add("input"); - keywords.add("output"); - keywords.add("annotation"); - keywords.add("false"); - keywords.add("true"); - keywords.add("each"); - keywords.add("initial"); - keywords.add("algorithm"); - keywords.add("equation"); - keywords.add("or"); - keywords.add("and"); - keywords.add("not"); - keywords.add("break"); - keywords.add("return"); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/IExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/IExpressionViewFactor.java deleted file mode 100644 index 360776bd..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/IExpressionViewFactor.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Composite; -import org.simantics.db.Resource; - -public interface IExpressionViewFactor { - - static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL); - - /** - * Creates expression type specific user interface and initializes - * the components by the given data. The given map is linked - * to the ui components and updated. - * @param parent - * @param data - */ - void createView(Composite parent, Map data); - /** - * Reads expression type specific data from database. - * @param variable - * @return - */ - void readData(Resource variable, Map data); - - /** - * Writes expression type specific data to database. - * @param variable - * @return - */ - void writeData(Resource variable, Map data); - - /** - * Focuses to some part of the expression view. - */ - void focus(); - - /** - * Replaces the current selection with a variable name. - * @param var - */ - void replaceSelection(String var); - - /** - * Updates data from text inputs to the data map - * @param data - */ - void updateData(Map data); - - /** - * @return all individual expression fields for modelica validation - */ - List getExpressionFields(); - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartInfo.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartInfo.java deleted file mode 100644 index 96ec9b49..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartInfo.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.Map; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; - -public class LookupChartInfo { - - String lookupTable, expression; - Double minX, maxX, minY, maxY; - - private static Double MINX = 0.0; - private static Double MAXX = 10.0; - private static Double MINY = 0.0; - private static Double MAXY = 10.0; - - public LookupChartInfo(String expression, String lookupTable, final Resource variable, Map data) { - this.lookupTable = lookupTable != null ? lookupTable : ""; - this.expression = expression != null ? expression : ""; - this.minX = (Double)data.get("minX"); - this.maxX = (Double)data.get("maxX"); - this.minY = (Double)data.get("minY"); - this.maxY = (Double)data.get("maxY"); - if(variable != null && (minX == null || maxX == null || minY == null || maxY == null)) { - try { - SimanticsUI.getSession().syncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource expression = graph.getPossibleObject(variable, sr.HasExpression); - if(expression != null && graph.isInstanceOf(expression, sr.WithLookupExpression)) { - minX = graph.getPossibleRelatedValue(expression, sr.HasMinX); - if(minX == null) minX = MINX; - maxX = graph.getPossibleRelatedValue(expression, sr.HasMaxX); - if(maxX == null) maxX = MAXX; - minY = graph.getPossibleRelatedValue(expression, sr.HasMinY); - if(minY == null) minY = MINY; - maxY = graph.getPossibleRelatedValue(expression, sr.HasMaxY); - if(maxY == null) maxY = MAXY; - } else { - defaultValues(); - } - - } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - } - - private void defaultValues() { - minX = MINX; - maxX = MAXX; - minY = MINY; - maxY = MAXY; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartPanel.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartPanel.java deleted file mode 100644 index 8118d79b..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartPanel.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -import org.jfree.chart.ChartPanel; -import org.jfree.chart.ChartRenderingInfo; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.entity.ChartEntity; -import org.jfree.chart.entity.PlotEntity; -import org.jfree.chart.entity.XYItemEntity; -import org.jfree.chart.plot.XYPlot; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; - -@SuppressWarnings("serial") -public class LookupChartPanel extends ChartPanel { - - private XYItemEntity dragPrevEntity; - private boolean drawing; - private XYSeries series; - private JFreeChart chart; - private LookupInputOutputTable table; - - public LookupChartPanel(JFreeChart chart) { - super(chart); - this.chart = chart; - XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset(); - series = collection.getSeries(0); - } - - public void setTable(LookupInputOutputTable table) { - this.table = table; - } - - public void mouseDragged(MouseEvent e) - { - if(dragPrevEntity != null) { - - int item = dragPrevEntity.getItem(); - XYPlot plot = (XYPlot)chart.getPlot(); - ValueAxis rangeAxis = plot.getRangeAxis(); - ValueAxis domainAxis = plot.getDomainAxis(); - Point2D location = getLocationOnChart(getMouseLocation(e)); - Number prevX = item == 0 ? null : series.getX(item - 1); - Number nextX = item == series.getItemCount() - 1 ? null : series.getX(item + 1); - - - if(series.indexOf(location.getX()) >= 0 && series.indexOf(location.getX()) != item) - return; - else if (prevX != null && location.getX() < prevX.doubleValue()) - location.setLocation(series.getX(item).doubleValue(), location.getY()); - else if (nextX != null && location.getX() > nextX.doubleValue()) - location.setLocation(series.getX(item).doubleValue(), location.getY()); - else if (location.getX() > domainAxis.getUpperBound()) - location.setLocation(domainAxis.getUpperBound(), location.getY()); - else if (location.getX() < domainAxis.getLowerBound()) - location.setLocation(domainAxis.getLowerBound(), location.getY()); - - if (location.getY() > rangeAxis.getUpperBound()) - location.setLocation(location.getX(), rangeAxis.getUpperBound()); - else if (location.getY() < rangeAxis.getLowerBound()) - location.setLocation(location.getX(), rangeAxis.getLowerBound()); - - removeItemFromSeries(dragPrevEntity.getItem()); - addLocationToSeries(location); - } else { - ChartEntity currEntity = this.getEntityForPoint(e.getX(),e.getY()); - if(!drawing && currEntity instanceof XYItemEntity) { - dragPrevEntity = ((XYItemEntity)currEntity); - } else if (currEntity instanceof PlotEntity){ - drawing = true; - Point2D locationOnChart = getLocationOnChart(getMouseLocation(e)); - int item = series.indexOf(locationOnChart.getX()); - if (item >= 0) { - Point2D location = new Point2D.Double(series.getX(item).doubleValue(), series.getY(item).doubleValue()); - Point2D javaLocation = getLocationOnJava2D(location); - removeItemFromSeries(item); - addLocationToSeries(getLocationOnChart(new Point2D.Double(javaLocation.getX(), e.getY()))); - } - } - } - - } - - public void mouseReleased(MouseEvent e) { - - dragPrevEntity = null; - drawing = false; - } - - public void mouseClicked(MouseEvent e) - { - if(e.getButton() == MouseEvent.BUTTON1) { - addLocationToSeries(getLocationOnChart(getMouseLocation(e))); - } else if (e.getButton() == MouseEvent.BUTTON3) { - ChartEntity entity = this.getEntityForPoint(e.getX(),e.getY()); - if(entity instanceof XYItemEntity) { - XYItemEntity xyentity = ((XYItemEntity)entity); - removeItemFromSeries(xyentity.getItem()); - } - } - } - - private Point2D getLocationOnChart(Point2D coordinates) { - XYPlot plot = (XYPlot)chart.getPlot(); - ChartRenderingInfo info = getChartRenderingInfo(); - Rectangle2D dataArea = info.getPlotInfo().getDataArea(); - double chartX = plot.getDomainAxis().java2DToValue(coordinates.getX(), dataArea, - plot.getDomainAxisEdge()); - double chartY = plot.getRangeAxis().java2DToValue(coordinates.getY(), dataArea, - plot.getRangeAxisEdge()); - return new Point2D.Double(chartX, chartY); - } - - private Point2D getLocationOnJava2D(Point2D location) { - XYPlot plot = (XYPlot)chart.getPlot(); - ChartRenderingInfo info = getChartRenderingInfo(); - Rectangle2D dataArea = info.getPlotInfo().getDataArea(); - double javaX = plot.getDomainAxis().valueToJava2D(location.getX(), dataArea, - plot.getDomainAxisEdge()); - double javaY = plot.getRangeAxis().valueToJava2D(location.getY(), dataArea, - plot.getRangeAxisEdge()); - return new Point2D.Double(javaX, javaY); - } - - public void addLocationToSeries(Point2D location) { - if(series.indexOf(location.getX()) < 0) { - series.add(location.getX(), location.getY()); - table.addLocation(location); - } - } - - public void removeItemFromSeries(int item){ - Point2D location = new Point2D.Double(series.getX(item).doubleValue(),series.getY(item).doubleValue()); - series.remove(item); - table.removeLocation(location); - } - - private Point2D getMouseLocation(MouseEvent e) { - int mouseX = e.getX(); - int mouseY = e.getY(); - Point2D p = translateScreenToJava2D( - new Point(mouseX, mouseY)); - return p; - } - - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupExpressionViewFactor.java deleted file mode 100644 index 15ce9b20..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupExpressionViewFactor.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.widgets.Composite; -import org.simantics.db.Resource; - -public class LookupExpressionViewFactor implements IExpressionViewFactor { - - @Override - public void createView(Composite parent, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void focus() { - // TODO Auto-generated method stub - - } - - @Override - public void readData(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void replaceSelection(String var) { - // TODO Auto-generated method stub - - } - - @Override - public void writeData(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void updateData(Map data) { - // TODO Auto-generated method stub - - } - - @Override - public List getExpressionFields() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupInputOutputTable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupInputOutputTable.java deleted file mode 100644 index 1bfb8245..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupInputOutputTable.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; - -public class LookupInputOutputTable extends Composite { - - public static final String INPUT = "Input"; - public static final String OUTPUT = "Output"; - public static final String[] PROPS = { INPUT, OUTPUT }; - - Table table; - TableViewer tableViewer; - List tableRows; - - public LookupInputOutputTable(Composite parent, int style) { - super(parent, style); - - GridLayoutFactory.fillDefaults().applyTo(this); - GridDataFactory.fillDefaults().grab(true, true).applyTo(this); - table = new Table(this, SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION); - GridDataFactory.fillDefaults().grab(true, true).applyTo(table); - table.setHeaderVisible (true); - table.setLinesVisible(true); - table.getVerticalBar().setVisible(true); - TableColumn column1 = new TableColumn (table, SWT.LEFT); - column1.setText (INPUT); - column1.setWidth (85); - - TableColumn column2 = new TableColumn (table, SWT.LEFT); - column2.setText (OUTPUT); - column2.setWidth (85); - - // Create the viewer and connect it to the view - tableViewer = new TableViewer (table); - - tableViewer.setContentProvider (new ArrayContentProvider()); - tableViewer.setLabelProvider (new InputOutputLabelProvider()); - - tableRows = new ArrayList(); - tableViewer.setInput(tableRows); - - CellEditor[] editors = new CellEditor[2]; - editors[0] = new TextCellEditor(table); - editors[1] = new TextCellEditor(table); - tableViewer.setCellEditors(editors); - tableViewer.setColumnProperties(PROPS); - - } - - private class InputOutputLabelProvider extends LabelProvider implements ITableLabelProvider { - public Image getColumnImage (Object element, int columnIndex) { - return null; - } - public String getColumnText (Object element, int columnIndex) { - if(element instanceof InputOutput) { - InputOutput io = (InputOutput)element; - switch (columnIndex) { - case 0: return (String)io.getInput(String.class); - case 1: return (String)io.getOutput(String.class); - } - } - return ""; - } - } - - public void addLocation(Point2D location) { - tableRows.add(new InputOutput(location.getX(), location.getY())); - tableViewer.getTable().getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - refresh(); - } - }); - - } - - public void removeLocation(Point2D location) { - for(InputOutput io : tableRows) { - if((Double)io.getInput(Double.class) == location.getX()) { - tableRows.remove(io); - tableViewer.getTable().getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - refresh(); - } - }); - break; - } - } - - } - - - class InputOutput { - private double input, output; - - public InputOutput(double input, double output) { - this.input = input; - this.output = output; - } - - /** - * - * @param clazz String.class or Double.class - * @return input as string or double or null if asked for something else - */ - @SuppressWarnings("rawtypes") - public Object getInput(Class clazz) { - if(clazz == String.class) { - return "" + input; - } else if (clazz == Double.class) { - return input; - } - return null; - } - - public Double setInput(String input) { - try { - this.input = Double.parseDouble(input); - return this.input; - } catch (NumberFormatException e) { - return null; - } - } - - public void setInput(double input) { - this.input = input; - } - - /** - * - * @param clazz String.class or Double.class - * @return output as string or double or null if asked for something else - */ - @SuppressWarnings("rawtypes") - public Object getOutput(Class clazz) { - if(clazz == String.class) { - return "" + output; - } else if (clazz == Double.class) { - return output; - } - return null; - } - - public void setOutput(String output) { - try { - this.output = Double.parseDouble(output); - } catch (NumberFormatException e) { - - } - } - - public void setOutput(double output) { - this.output = output; - } - - } - - class InputOutputComparator extends ViewerComparator { - @Override - public int compare(Viewer viewer, Object e1, Object e2) { - if ((e1 instanceof InputOutput) && - (e2 instanceof InputOutput)) { - InputOutput io1 = (InputOutput)e1; - InputOutput io2 = (InputOutput)e2; - Double d1 = (Double)io1.getInput((Double.class)); - Double d2 = (Double)io2.getInput((Double.class)); - return d1.compareTo(d2); - } - return 0; - } - } - - public TableViewer getTableViewer() { - return this.tableViewer; - } - - public void refresh() { - tableViewer.setComparator(new InputOutputComparator()); - tableViewer.refresh(); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupPopup.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupPopup.java deleted file mode 100644 index b3700cfd..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupPopup.java +++ /dev/null @@ -1,446 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.GridLayout; -import java.awt.event.MouseEvent; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Point2D; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Iterator; -import javax.swing.JComponent; -import javax.swing.JPanel; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Widget; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.data.xy.XYDataItem; -import org.jfree.data.xy.XYDataset; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; -import org.simantics.sysdyn.tableParser.ParseException; -import org.simantics.sysdyn.tableParser.Token; -import org.simantics.sysdyn.tableParser.TableParser; -import org.simantics.sysdyn.ui.equation.expressions.LookupInputOutputTable.InputOutput; -import org.simantics.utils.ui.SWTAWTComponent; - -public class LookupPopup extends Dialog { - - JFreeChart chart; - LookupInputOutputTable table; - ArrayList dataPoints; - Text input, output; - Text minX, maxX, minY, maxY; - Label unit; - LookupChartInfo chartInfo; - - protected LookupPopup(Shell parentShell, LookupChartInfo chartInfo) { - super(parentShell); - this.chartInfo = chartInfo; - this.dataPoints = new ArrayList(); - TableParser parser = new TableParser(new StringReader("")); - parser.ReInit(new StringReader(chartInfo.lookupTable)); - try { - parser.table(); - ArrayList xTokens = parser.getXTokens(); - for(Token token : xTokens) { - dataPoints.add(new Point2D.Double( - Double.parseDouble(token.image), - Double.parseDouble(token.next.next.image))); - } - } catch (ParseException e1) { - } - - } - - @Override - protected Control createDialogArea(Composite parent) { - KeyListener enterListener = new KeyListener() { - - @Override - public void keyReleased(KeyEvent e) {} - - @Override - public void keyPressed(KeyEvent e) { - if(e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) - getButton(IDialogConstants.OK_ID).forceFocus(); - } - }; - - final LookupChartPanel chartPanel = new LookupChartPanel(createChart()); - chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); - chartPanel.setMouseZoomable(true, false); - chartPanel.setDomainZoomable(false); - chartPanel.setRangeZoomable(false); - - XYPlot plot = (XYPlot) chart.getPlot(); - ValueAxis rangeAxis = plot.getRangeAxis(); - ValueAxis domainAxis = plot.getDomainAxis(); - - Composite container = new Composite(parent, SWT.None); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(container); - - Composite yAxis = new Composite(container, SWT.NONE); - GridLayoutFactory.fillDefaults().applyTo(yAxis); - GridDataFactory.fillDefaults().grab(false, true).applyTo(yAxis); - maxY = new Text(yAxis, SWT.BORDER | SWT.RIGHT); - GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(maxY); - maxY.addKeyListener(enterListener); - maxY.addModifyListener(getAxisBoundModifyListener()); - maxY.setText("" + rangeAxis.getUpperBound()); - Composite fillY = new Composite(yAxis, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(false, true).applyTo(fillY); - GridLayoutFactory.fillDefaults().applyTo(fillY); - unit = new Label(fillY, SWT.RIGHT); - GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(unit); - unit.setText(""); //TODO: how to get and update units? - unit.addKeyListener(enterListener); - minY = new Text(yAxis, SWT.BORDER | SWT.RIGHT); - GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(minY); - minY.addKeyListener(enterListener); - minY.addModifyListener(getAxisBoundModifyListener()); - minY.setText("" + rangeAxis.getLowerBound()); - - SWTAWTComponent c = new SWTAWTComponent(container, SWT.BORDER) { - @Override - protected JComponent createSwingComponent() { - JPanel panel = new JPanel(); - panel.setLayout(new GridLayout(1, 1)); - panel.setPreferredSize(new java.awt.Dimension(500, 270)); - panel.add(chartPanel); - panel.doLayout(); - return panel; - } - }; - GridDataFactory.fillDefaults().hint(500, 300).applyTo(c); - c.populate(); - - - Composite valueTableComposite = new Composite(container, SWT.NONE); - GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(valueTableComposite); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(valueTableComposite); - - - table = new LookupInputOutputTable(valueTableComposite, SWT.NONE); - GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(table); - chartPanel.setTable(table); - table.getTableViewer().setCellModifier(new InputOutputCellModifier()); - table.getTableViewer().getTable().addMouseListener(new MouseListener() { - - @Override - public void mouseUp(org.eclipse.swt.events.MouseEvent e) { - if(e.button == MouseEvent.BUTTON3) { - Table table = (Table)e.widget; - TableItem item = (TableItem)table.getItem(new org.eclipse.swt.graphics.Point(e.x, e.y)); - chartPanel.removeItemFromSeries(table.indexOf(item)); - } - } - @Override - public void mouseDown(org.eclipse.swt.events.MouseEvent e) { } - @Override - public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e) { } - }); - for(Point2D location : this.dataPoints) { - chartPanel.addLocationToSeries(location); - } - - input = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT); - GridDataFactory.fillDefaults().hint(60, SWT.DEFAULT).applyTo(input); - input.setText(""); - output = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT); - GridDataFactory.fillDefaults().hint(60, SWT.DEFAULT).applyTo(output); - output.setText(""); - - Button add = new Button(valueTableComposite, SWT.None); - add.setText("Add"); - add.addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - try { - Double in = Double.parseDouble(input.getText()); - Double out = Double.parseDouble(output.getText()); - chartPanel.addLocationToSeries(new Point2D.Double(in, out)); - } catch (NumberFormatException e1) { - input.setText(""); - output.setText(""); - } - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) {} - }); - - FocusListener flistener = new FocusListener() { - @Override - public void focusGained(FocusEvent e) { - Text text = (Text)e.widget; - text.setSelection(0, text.getCharCount()); - } - @Override - public void focusLost(FocusEvent e) { } - }; - - - KeyListener listener = new KeyListener() { - - @Override - public void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { - try { - Double in = Double.parseDouble(input.getText()); - Double out = Double.parseDouble(output.getText()); - chartPanel.addLocationToSeries(new Point2D.Double(in, out)); - } catch (NumberFormatException e1) { - if(input.getText().isEmpty() && output.getText().isEmpty()) { - getButton(IDialogConstants.OK_ID).forceFocus(); - return; - } - } - input.setText(""); - output.setText(""); - input.setFocus(); - } - } - - @Override - public void keyReleased(KeyEvent e) { } - - }; - - input.addFocusListener(flistener); - input.addKeyListener(listener); - output.addFocusListener(flistener); - output.addKeyListener(listener); - - Label l = new Label(container, SWT.NONE); - l.setText(""); - - Composite xAxis = new Composite(container, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(xAxis); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(xAxis); - minX = new Text(xAxis, SWT.BORDER | SWT.RIGHT); - GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(minX); - minX.addKeyListener(enterListener); - minX.addModifyListener(getAxisBoundModifyListener()); - minX.setText("" + domainAxis.getLowerBound()); - Composite fillX = new Composite(xAxis, SWT.CENTER); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(fillX); - GridLayoutFactory.fillDefaults().applyTo(fillX); - l = new Label(fillX, SWT.NONE); - l.setText(chartInfo.expression); - maxX = new Text(xAxis, SWT.BORDER | SWT.RIGHT); - GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(maxX); - maxX.addKeyListener(enterListener); - maxX.addModifyListener(getAxisBoundModifyListener()); - maxX.setText("" + domainAxis.getUpperBound()); - - return null; - } - - protected void createButtonsForButtonBar(Composite parent) { - // create OK and Cancel buttons by default - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, - false); - createButton(parent, IDialogConstants.CANCEL_ID, - IDialogConstants.CANCEL_LABEL, false); - } - - public LookupChartInfo open(Boolean bool) { - Shell shell = this.getShell(); - if (shell == null || shell.isDisposed()) { - shell = null; - create(); - shell = this.getShell(); - } - constrainShellSize(); - shell.open(); - getButton(IDialogConstants.OK_ID).setFocus(); - Display display = getParentShell().getDisplay(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - return chartInfo; - } - - @Override - public void okPressed() { - chartInfo.lookupTable = graphToModelicaTable(); - chartInfo.minX = Double.parseDouble(minX.getText()); - chartInfo.maxX = Double.parseDouble(maxX.getText()); - chartInfo.minY = Double.parseDouble(minY.getText()); - chartInfo.maxY = Double.parseDouble(maxY.getText()); - super.okPressed(); - } - - private String graphToModelicaTable() { - StringBuilder b = new StringBuilder(); - b.append("{"); - XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset(); - XYSeries series = collection.getSeries(0); - if(series.isEmpty()) - return ""; - @SuppressWarnings("rawtypes") - Iterator iterator = series.getItems().iterator(); - while(iterator.hasNext()){ - XYDataItem item = (XYDataItem)iterator.next(); - b.append("{" + item.getX() + "," + item.getY() + "}"); - if(iterator.hasNext()) - b.append(","); - } - b.append("}"); - return b.toString(); - } - - private JFreeChart createChart() { - XYDataset dataset = createDataset(); - chart = ChartFactory.createXYLineChart(null, null, null, - dataset, PlotOrientation.VERTICAL, false, true, false); - XYPlot plot = (XYPlot) chart.getPlot(); - XYLineAndShapeRenderer renderer - = (XYLineAndShapeRenderer) plot.getRenderer(); - renderer.setBaseShapesVisible(true); - renderer.setDrawOutlines(true); - renderer.setUseFillPaint(true); - renderer.setBaseFillPaint(Color.white); - renderer.setSeriesStroke(0, new BasicStroke(3.0f)); - renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f)); - renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0)); - - ValueAxis rangeAxis = plot.getRangeAxis(); - rangeAxis.setAutoRange(false); - rangeAxis.setRange(chartInfo.minY, chartInfo.maxY); - ValueAxis domainAxis = plot.getDomainAxis(); - domainAxis.setAutoRange(false); - domainAxis.setRange(chartInfo.minX, chartInfo.maxX); - return chart; - } - - public XYDataset createDataset() { - XYSeries series = new XYSeries("Series"); - XYSeriesCollection dataset = new XYSeriesCollection(); - dataset.addSeries(series); - return dataset; - } - - private ModifyListener getAxisBoundModifyListener() { - return new ModifyListener() { - - @Override - public void modifyText(ModifyEvent e) { - Widget widget = e.widget; - if(widget instanceof Text) { - Text text = (Text)widget; - Double value; - try { - value = Double.parseDouble(text.getText()); - } catch (NumberFormatException e1 ) { - return; - } - XYPlot plot = (XYPlot) chart.getPlot(); - ValueAxis rangeAxis = plot.getRangeAxis(); - ValueAxis domainAxis = plot.getDomainAxis(); - if(text == minX) { - domainAxis.setLowerBound(value); - } else if (text == maxX) { - domainAxis.setUpperBound(value); - } else if (text == minY) { - rangeAxis.setLowerBound(value); - } else if (text == maxY) { - rangeAxis.setUpperBound(value); - } - } - } - }; - } - - private class InputOutputCellModifier implements ICellModifier { - - XYSeries series; - - public InputOutputCellModifier() { - XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset(); - series = collection.getSeries(0); - } - - public boolean canModify(Object element, String property) { - return true; - } - - public Object getValue(Object element, String property) { - InputOutput io = (InputOutput)element; - if (LookupInputOutputTable.INPUT.equals(property)) - return (String)io.getInput(String.class); - else if (LookupInputOutputTable.OUTPUT.equals(property)) - return (String)io.getOutput(String.class); - else - return null; - } - - public void modify(Object element, String property, Object value) { - if (element instanceof Item) element = ((Item) element).getData(); - - InputOutput io = (InputOutput)element; - Double x = (Double)io.getInput(Double.class); - int item = series.indexOf(x); - series.remove(item); - - if (LookupInputOutputTable.INPUT.equals(property)) { - Double newX = io.setInput((String)value); - // if has the same x-value, revert back - if(newX != null && series.indexOf(newX) >= 0) { - io.setInput(x); - } - } else if (LookupInputOutputTable.OUTPUT.equals(property)) { - io.setOutput((String)value); - } - - series.add((Double)io.getInput(Double.class), (Double)io.getOutput(Double.class)); - - table.refresh(); - } - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ParameterExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ParameterExpressionViewFactor.java deleted file mode 100644 index f03218e9..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ParameterExpressionViewFactor.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; - -public class ParameterExpressionViewFactor implements IExpressionViewFactor { - - private Label equationLabel; - private ExpressionField expression; - - @Override - public void createView(Composite parent, Map data) { - - final String equation = data.get("equation") != null ? (String)data.get("equation") : ""; - - - GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(parent); - equationLabel = new Label(parent, SWT.NONE); - equationLabel.setFont(FONT); - equationLabel.setText("="); - GridDataFactory.fillDefaults().applyTo(equationLabel); - - - expression = new ExpressionField(parent, SWT.BORDER); - expression.setFont(FONT); - expression.setExpression(equation); - GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); - } - - @Override - public void focus() { - if(this.expression != null) this.expression.focus(); - } - - @Override - public void readData(final Resource variable, Map data) { - String equation = null; - if (variable != null && data.get("equation") == null) { - try { - equation = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource expression = graph.getPossibleObject(variable, sr.HasExpression); - if (expression != null && graph.isInstanceOf(expression, sr.ParameterExpression)) { - return graph.getRelatedValue(expression, sr.HasEquation); - } else { - return ""; - } - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - data.put("equation", equation); - } - } - - @Override - public void replaceSelection(String var) { - if(expression != null) { - IDocument doc = expression.getDocument(); - try { - Point selection = expression.getSelection(); - doc.replace(selection.x, selection.y, var); - expression.setSelection(selection.x + var.length()); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - } - - @Override - public void writeData(final Resource variable, Map data) { - final String currentText = expression.getExpression(); - if(currentText != null) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph g) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(g); - Resource expression = g.getPossibleObject(variable, sr.HasExpression); - Layer0 l0 = Layer0.getInstance(g); - if(expression != null) { - g.deny(variable, sr.HasExpression); - } - expression = g.newResource(); - g.claim(expression, l0.InstanceOf, null, sr.ParameterExpression); - g.claim(variable, sr.HasExpression, expression); - g.claimLiteral(expression, sr.HasEquation, currentText); - } - - }); - } - } - - @Override - public void updateData(Map data) { - if(this.expression != null && this.expression.getExpression() != null) - data.put("equation", this.expression.getExpression()); - } - - @Override - public List getExpressionFields() { - return Arrays.asList(this.expression); - } - -} - diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionViewFactor.java deleted file mode 100644 index 16948ab3..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionViewFactor.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; - -public class StockExpressionViewFactor implements IExpressionViewFactor { - - private Label integralLabel; - private Text integral; - private Label equationLabel; - private ExpressionField expression; - - @Override - public void createView(Composite parent, Map data) { - - final String initialEquation = data.get("initialEquation") != null ? (String)data.get("initialEquation") : ""; - final String integralEquation = data.get("integral") != null ? (String)data.get("integral") : ""; - - GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(parent); - - integralLabel = new Label(parent, SWT.NONE); - integralLabel.setFont(FONT); - integralLabel.setText("Integral"); - GridDataFactory.fillDefaults().applyTo(integralLabel); - - integral = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); - integral.setEditable(false); - integral.setFont(FONT); - integral.setText(integralEquation); - GridDataFactory.fillDefaults().grab(true, true).applyTo(integral); - - equationLabel = new Label(parent, SWT.NONE); - equationLabel.setFont(FONT); - equationLabel.setText("Initial\nValue"); - GridDataFactory.fillDefaults().applyTo(equationLabel); - - - expression = new ExpressionField(parent, SWT.BORDER); - expression.setFont(FONT); - expression.setExpression(initialEquation); - GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); - - } - - @Override - public void readData(final Resource variable, Map data) { - String initialEquation = null; - - if (variable != null && data.get("initialEquation") == null) { - try { - initialEquation = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource expression = graph.getPossibleObject(variable, sr.HasExpression); - if (expression != null && graph.isInstanceOf(expression, sr.StockExpression)) { - return graph.getRelatedValue(expression, sr.HasInitialEquation); - } else { - return ""; - } - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - data.put("initialEquation", initialEquation); - } - - data.put("integral", getIntegral(variable)); - } - - @Override - public void writeData(final Resource variable, Map data) { - final String currentText = expression.getExpression(); - if(currentText != null) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph g) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(g); - Resource expression = g.getPossibleObject(variable, sr.HasExpression); - Layer0 l0 = Layer0.getInstance(g); - if(expression != null) { - g.deny(variable, sr.HasExpression); - } - expression = g.newResource(); - g.claim(expression, l0.InstanceOf, null, sr.StockExpression); - g.claim(variable, sr.HasExpression, expression); - g.claimLiteral(expression, sr.HasInitialEquation, currentText); - } - - }); - } - } - - private String getIntegral(final Resource variable) { - String integral = ""; - try { - integral = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Collection heads = graph.getObjects(variable, sr.IsHeadOf); - Collection tails = graph.getObjects(variable, sr.IsTailOf); - - StringBuilder builder = new StringBuilder(); - builder.append(""); - for (Resource r : heads) { - if(graph.isInstanceOf(r, sr.Flow)) { - Resource tail = graph.getPossibleObject(r, sr.HasTail); - if(tail != null) { - Object name = graph.getPossibleRelatedValue(tail, l0.HasName); - if (name != null) - builder.append(" + " + name); - } - } - } - for (Resource r : tails) { - if(graph.isInstanceOf(r, sr.Flow)) { - Resource head = graph.getPossibleObject(r, sr.HasHead); - if(head != null) { - Object name = graph.getPossibleRelatedValue(head, l0.HasName); - if (name != null) - builder.append(" - " + name); - } - } - } - if (builder.indexOf(" + ") == 0) - builder.delete(0, 3); - return builder.toString().trim(); - } - - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - return integral; - } - - @Override - public void focus() { - if(this.expression != null) this.expression.focus(); - } - - @Override - public void replaceSelection(String var) { - if(expression != null) { - IDocument doc = expression.getDocument(); - try { - Point selection = expression.getSelection(); - doc.replace(selection.x, selection.y, var); - expression.setSelection(selection.x + var.length()); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - } - - @Override - public void updateData(Map data) { - if(this.expression != null && this.expression.getExpression() != null) - data.put("initialEquation", this.expression.getExpression()); - if(this.integral != null && this.integral.getText() != null) - data.put("integral", this.integral.getText()); - } - - @Override - public List getExpressionFields() { - return Arrays.asList(this.expression); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/WithLookupExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/WithLookupExpressionViewFactor.java deleted file mode 100644 index 0edf625c..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/WithLookupExpressionViewFactor.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.equation.expressions; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; - -public class WithLookupExpressionViewFactor implements IExpressionViewFactor { - - - private Label expressionLabel; - private ExpressionField expression; - private Label lookupLabel; - private ExpressionField lookup; - private Button asGraph; - private ExpressionField lastSelectedText = expression; - private Resource variable; - private LookupChartInfo chartInfo; - - public WithLookupExpressionViewFactor(Resource variable) { - super(); - this.variable = variable; - } - - @Override - public void createView(Composite parent, final Map data) { - String equation = data.get("equation") != null ? (String)data.get("equation") : ""; - String lookupTable = data.get("lookup") != null ? (String)data.get("lookup") : ""; - - GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(parent); - - expressionLabel = new Label(parent, SWT.NONE); - expressionLabel.setFont(FONT); - expressionLabel.setText("With\nLookup"); - GridDataFactory.fillDefaults().applyTo(expressionLabel); - - expression = new ExpressionField(parent, SWT.BORDER); - expression.setFont(FONT); - expression.setExpression(equation); - GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); - - expression.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { - - @Override - public void focusLost(FocusEvent e) { - lastSelectedText = expression; - } - }); - - lookupLabel = new Label(parent, SWT.NONE); - lookupLabel.setFont(FONT); - lookupLabel.setText("Lookup\ntable"); - GridDataFactory.fillDefaults().applyTo(lookupLabel); - - lookup = new ExpressionField(parent, SWT.BORDER); - lookup.setFont(FONT); - lookup.setExpression(lookupTable); - GridDataFactory.fillDefaults().grab(true, true).applyTo(lookup); - - lookup.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { - - @Override - public void focusLost(FocusEvent e) { - lastSelectedText = lookup; - } - }); - - asGraph = new Button(parent, SWT.None); - asGraph.setText("As graph"); - asGraph.setFont(FONT); - asGraph.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if(e.widget == asGraph) { - if(chartInfo == null) chartInfo = new LookupChartInfo(expression.getExpression(), lookup.getExpression(), variable, data); - LookupPopup pud = new LookupPopup(asGraph.getParent().getShell(), chartInfo); - LookupChartInfo newInfo = pud.open(false); - if(pud.getReturnCode() == org.eclipse.jface.window.Window.OK) { - chartInfo = newInfo; - lookup.setExpression(chartInfo.lookupTable); - } - } - } - }); - - } - - @Override - public void readData(final Resource variable, Map data) { - String[] results = null; - if (variable != null && data.get("equation") == null) { - try { - results = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public String[] perform(ReadGraph graph) throws DatabaseException { - String[] results = new String[2]; - SysdynResource sr = SysdynResource.getInstance(graph); - Resource expression = graph.getPossibleObject(variable, sr.HasExpression); - if (expression != null && graph.isInstanceOf(expression, sr.WithLookupExpression)) { - results[0] = graph.getRelatedValue(expression, sr.HasEquation); - results[1] = graph.getRelatedValue(expression, sr.HasLookup); - } else { - results[0] = ""; - results[1] = ""; - } - return results; - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - data.put("equation", results[0]); - data.put("lookup", results[1]); - } - } - - @Override - public void writeData(final Resource variable, Map data) { - final String currentExpression = expression.getExpression(); - final String currentLookupTable = lookup.getExpression(); - - if(currentExpression != null && currentLookupTable != null) { - data.putAll(data); - data.put("equation", currentExpression); - data.put("lookup", currentLookupTable); - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph g) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(g); - Resource expression = g.getPossibleObject(variable, sr.HasExpression); - Layer0 l0 = Layer0.getInstance(g); - if(expression != null) { - g.deny(variable, sr.HasExpression); - } - expression = g.newResource(); - g.claim(expression, l0.InstanceOf, null, sr.WithLookupExpression); - g.claim(variable, sr.HasExpression, expression); - g.claimLiteral(expression, sr.HasEquation, currentExpression); - g.claimLiteral(expression, sr.HasLookup, currentLookupTable); - g.claimLiteral(expression, sr.HasMinX, chartInfo.minX); - g.claimLiteral(expression, sr.HasMaxX, chartInfo.maxX); - g.claimLiteral(expression, sr.HasMinY, chartInfo.minY); - g.claimLiteral(expression, sr.HasMaxY, chartInfo.maxY); - } - }); - } - } - - @Override - public void focus() { - if(this.lastSelectedText != null) this.lastSelectedText.focus(); - } - - @Override - public void replaceSelection(String var) { - if(lastSelectedText != null) { - IDocument doc = lastSelectedText.getDocument(); - try { - Point selection = lastSelectedText.getSelection(); - doc.replace(selection.x, selection.y, var); - lastSelectedText.setSelection(selection.x + var.length()); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - } - - @Override - public void updateData(Map data) { - if(this.expression != null && this.expression.getExpression() != null) - data.put("equation", this.expression.getExpression()); - if(this.lookup != null && this.lookup.getExpression() != null) - data.put("lookup", this.lookup.getExpression()); - if(this.chartInfo != null) { - data.put("minX", chartInfo.minX); - data.put("maxX", chartInfo.maxX); - data.put("minY", chartInfo.minY); - data.put("maxY", chartInfo.maxY); - } - } - - @Override - public List getExpressionFields() { - return Arrays.asList(this.expression, this.lookup); - } -} \ No newline at end of file -- 2.47.1