From: niemisto Date: Tue, 17 Nov 2009 14:38:03 +0000 (+0000) Subject: equation editor X-Git-Tag: simantics-1.0~135 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4039e0b3f077dd413986edb054b0971f20d5b778;p=simantics%2Fsysdyn.git equation editor git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13107 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index ab6b800d..4274ee39 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -13,4 +13,5 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0", org.simantics.ui;bundle-version="1.0.0", org.eclipse.ui;bundle-version="3.5.0", org.eclipse.core.runtime;bundle-version="3.5.0", - org.simantics.objmap;bundle-version="0.1.0" + org.simantics.objmap;bundle-version="0.1.0", + org.simantics.sysdyn;bundle-version="1.0.0" diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index bd010c48..19dc2d0c 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -31,6 +31,13 @@ name="Modelica View" restorable="true"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java deleted file mode 100644 index 426b3220..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007- VTT Technical Research Centre of Finland. - * 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; - - -import org.simantics.db.Resource; -import org.simantics.db.ReadGraph; -import org.simantics.db.Session; -import org.simantics.db.exception.DatabaseException; - -public class SysdynResource { - - public final Resource HasX; - public final Resource HasY; - public final Resource SysdynModel; - public final Resource SysdynModelManager; - public final Resource SysdynModellingDomain; - public final Resource TestDiagram; - public final Resource Variable; - public final Resource VariableElement; - - public static class URIs { - public static final String HasX = "http://www.simantics.org/Sysdyn#HasX"; - public static final String HasY = "http://www.simantics.org/Sysdyn#HasY"; - public static final String SysdynModel = "http://www.simantics.org/Sysdyn#SysdynModel"; - public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn#SysdynModelManager"; - public static final String SysdynModellingDomain = "http://www.simantics.org/Sysdyn#SysdynModellingDomain"; - public static final String TestDiagram = "http://www.simantics.org/Sysdyn#TestDiagram"; - public static final String Variable = "http://www.simantics.org/Sysdyn#Variable"; - public static final String VariableElement = "http://www.simantics.org/Sysdyn#VariableElement"; - } - - public static Resource getResourceOrNull(ReadGraph graph, String uri) { - try { - return graph.getResourceByURI(uri); - } catch(DatabaseException e) { - System.err.println(e.getMessage()); - return null; - } - } - - public SysdynResource(ReadGraph graph) { - HasX = getResourceOrNull(graph, URIs.HasX); - HasY = getResourceOrNull(graph, URIs.HasY); - SysdynModel = getResourceOrNull(graph, URIs.SysdynModel); - SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager); - SysdynModellingDomain = getResourceOrNull(graph, URIs.SysdynModellingDomain); - TestDiagram = getResourceOrNull(graph, URIs.TestDiagram); - Variable = getResourceOrNull(graph, URIs.Variable); - VariableElement = getResourceOrNull(graph, URIs.VariableElement); - } - - public static SysdynResource getInstance(ReadGraph graph) { - Session session = graph.getSession(); - SysdynResource ret = session.getService(SysdynResource.class); - if(ret == null) { - ret = new SysdynResource(graph); - session.registerService(SysdynResource.class, ret); - } - return ret; - } - -} - diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java index afefa916..0a2d62f7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java @@ -154,10 +154,17 @@ public class SysdynDiagramEditor extends ResourceEditorPart { @Override public void selectionChanged(ISelection selection) { - ArrayList resources = new ArrayList(selection.size()); + final ArrayList resources = new ArrayList(selection.size()); for(IElement element : selection) resources.add(mapping.inverseGet(element)); - selectionProvider.setSelection(new StructuredSelection(resources)); + composite.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + selectionProvider.setSelection(new StructuredSelection(resources)); + } + + }); } }); 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 new file mode 100644 index 00000000..ed3d8812 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java @@ -0,0 +1,123 @@ +package org.simantics.sysdyn.ui.equation; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.ViewPart; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class EquationView extends ViewPart implements ISelectionListener { + + static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL); + + Text text; + Resource auxiliary; + String originalText; + + @Override + public void createPartControl(Composite parent) { + getSite().getPage().addPostSelectionListener(this); + text = new Text(parent, SWT.MULTI); + text.setFont(FONT); + text.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + final String currentText = text.getText(); + if(originalText != null && !originalText.equals(currentText)) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + g.claimValue(auxiliary, sr.HasValue, currentText); + } + + }); + } + } + + }); + text.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + if(e.keyCode == SWT.ESC) { + text.setText(originalText); + } + } + + }); + } + + class UpdateViewRequest extends ReadRequest { + + Resource resource; + + public UpdateViewRequest(Resource resource) { + this.resource = resource; + } + + @Override + public void run(ReadGraph g) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Builtins b = g.getBuiltins(); + if(g.isInstanceOf(resource, sr.Auxiliary)) { + auxiliary = resource; + final String name = g.getRelatedValue(resource, b.HasName); + final String value = g.getPossibleRelatedValue(resource, sr.HasValue); + text.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(value == null) + originalText = ""; + else + originalText = value; + text.setText(originalText); + setPartName(name + " equation"); + } + + }); + } + } + + } + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if(selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = + (IStructuredSelection)selection; + if(structuredSelection.size() == 1) { + Object element = structuredSelection.getFirstElement(); + if(element instanceof Resource) + SimanticsUI.getSession().asyncRequest(new UpdateViewRequest((Resource)element)); + } + } + } + + @Override + public void setFocus() { + text.setFocus(); + } + +} diff --git a/org.simantics.sysdyn/META-INF/MANIFEST.MF b/org.simantics.sysdyn/META-INF/MANIFEST.MF index dcebe58c..6e6d17f2 100644 --- a/org.simantics.sysdyn/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -4,4 +4,9 @@ Bundle-Name: Sysdyn Bundle-SymbolicName: org.simantics.sysdyn Bundle-Version: 1.0.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.simantics.objmap;bundle-version="0.1.0" +Require-Bundle: org.simantics.objmap;bundle-version="0.1.0", + org.simantics.db;bundle-version="0.6.2" +Export-Package: org.simantics.sysdyn, + org.simantics.sysdyn.modelica, + org.simantics.sysdyn.representation, + org.simantics.sysdyn.representation.visitors diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java similarity index 94% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/SysdynResource.java rename to org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java index 07dfa85a..5281df8f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java @@ -26,6 +26,7 @@ public class SysdynResource { public final Resource HasAngle; public final Resource HasHead; public final Resource HasTail; + public final Resource HasValue; public final Resource HasX; public final Resource HasY; public final Resource IndependentVariable; @@ -45,6 +46,7 @@ public class SysdynResource { public static final String HasAngle = "http://www.simantics.org/Sysdyn#HasAngle"; public static final String HasHead = "http://www.simantics.org/Sysdyn#HasHead"; public static final String HasTail = "http://www.simantics.org/Sysdyn#HasTail"; + public static final String HasValue = "http://www.simantics.org/Sysdyn#HasValue"; public static final String HasX = "http://www.simantics.org/Sysdyn#HasX"; public static final String HasY = "http://www.simantics.org/Sysdyn#HasY"; public static final String IndependentVariable = "http://www.simantics.org/Sysdyn#IndependentVariable"; @@ -74,6 +76,7 @@ public class SysdynResource { HasAngle = getResourceOrNull(graph, URIs.HasAngle); HasHead = getResourceOrNull(graph, URIs.HasHead); HasTail = getResourceOrNull(graph, URIs.HasTail); + HasValue = getResourceOrNull(graph, URIs.HasValue); HasX = getResourceOrNull(graph, URIs.HasX); HasY = getResourceOrNull(graph, URIs.HasY); IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable); diff --git a/sysdyn_ontologies/sysdyn.graph b/sysdyn_ontologies/sysdyn.graph index a4dddeb8..eadd105a 100644 --- a/sysdyn_ontologies/sysdyn.graph +++ b/sysdyn_ontologies/sysdyn.graph @@ -34,10 +34,12 @@ Configuration