From 14539f0379b4be510fbd56f8f2174824c8e947f0 Mon Sep 17 00:00:00 2001 From: niemisto Date: Thu, 19 Nov 2009 10:41:15 +0000 Subject: [PATCH] text in valve element git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13147 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 4 +- org.simantics.sysdyn.ui/plugin.xml | 21 ++- .../simantics/sysdyn/ui/actions/Connect.java | 4 +- .../sysdyn/ui/elements/ValveElement.java | 9 +- .../sysdyn/ui/elements/ValveElementOld.java | 73 +++++++++ .../ModelicaSourceViewerConfiguration.java | 143 ++++++++++++++++++ .../sysdyn/ui/modelica/ModelicaView.java | 30 ---- .../ui/modelica/SysdynModelicaEditor.java | 85 +++++++++++ .../TextEditorActionBarContributor.java | 11 ++ .../representation/LoadRepresentation.java | 27 ++++ .../sysdyn/representation/SysdynSchema.java | 31 ++++ 11 files changed, 394 insertions(+), 44 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaSourceViewerConfiguration.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaView.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/TextEditorActionBarContributor.java create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index 6bd0fbf5..e1cedbe8 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -16,6 +16,8 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0", org.simantics.objmap;bundle-version="0.1.0", org.simantics.sysdyn;bundle-version="1.0.0", org.simantics.project;bundle-version="1.0.0", - org.apache.log4j;bundle-version="1.2.15" + org.apache.log4j;bundle-version="1.2.15", + org.eclipse.jface.text;bundle-version="3.5.0", + org.eclipse.ui.editors;bundle-version="3.5.0" Bundle-Activator: org.simantics.sysdyn.ui.Activator Bundle-ActivationPolicy: lazy diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 6092710c..1c9024bd 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -7,7 +7,14 @@ class="org.simantics.sysdyn.ui.editor.SysdynDiagramEditor" default="false" id="org.simantics.sysdyn.ui.diagramEditor" - name="Sysdyn diagram editor"> + name="System dynamic diagram editor"> + + + + @@ -24,13 +36,6 @@ id="org.simantics.sysdyn.ui.category" name="System Dynamics"> - - = 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9') || c == '_'; + } + + 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"); + } + + static IToken modelicaKeywordToken = null; + public IToken getModelicaKeywordToken() { + if(modelicaKeywordToken == null) { + modelicaKeywordToken = + new Token( + new TextAttribute( + new Color(null, 127, 0, 85), + new Color(null, 255, 255, 255), + SWT.BOLD + )); + } + return modelicaKeywordToken; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaView.java deleted file mode 100644 index fb884168..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaView.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.simantics.sysdyn.ui.modelica; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.part.ViewPart; - -public class ModelicaView extends ViewPart implements ISelectionListener { - - @Override - public void createPartControl(Composite parent) { - getSite().getPage().addPostSelectionListener(this); - new Label(parent, SWT.NONE).setText("Hello World!"); - } - - @Override - public void setFocus() { - // TODO Auto-generated method stub - - } - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - System.out.println("selection changed"); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java new file mode 100644 index 00000000..200a4806 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java @@ -0,0 +1,85 @@ +package org.simantics.sysdyn.ui.modelica; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.PaintManager; +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.IAnnotationModel; +import org.eclipse.jface.text.source.MatchingCharacterPainter; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.texteditor.AbstractDocumentProvider; + + +public class SysdynModelicaEditor extends TextEditor { + + AnnotationModel annotationModel = new AnnotationModel(); + AnnotationPainter apainter; + + public SysdynModelicaEditor() { + super(); + showOverviewRuler(); + setDocumentProvider(new AbstractDocumentProvider() { + + @Override + protected IAnnotationModel createAnnotationModel(Object element) + throws CoreException { + return annotationModel; + } + + @Override + protected IDocument createDocument(Object element) + throws CoreException { + return new Document((String)getEditorInput().getAdapter(String.class)); + } + + @Override + protected void doSaveDocument(IProgressMonitor monitor, + Object element, IDocument document, boolean overwrite) + throws CoreException { + } + + @Override + protected IRunnableContext getOperationRunner( + IProgressMonitor monitor) { + return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + } + + @Override + public boolean isModifiable(Object element) { + return false; + } + + @Override + public boolean isReadOnly(Object element) { + return true; + } + + }); + + setSourceViewerConfiguration(new ModelicaSourceViewerConfiguration()); + + } + + @Override + protected void createActions() { + super.createActions(); + + PaintManager paintManager = new PaintManager(getSourceViewer()); + MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(getSourceViewer(), + new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} )); + matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160))); + paintManager.addPainter(matchingCharacterPainter); + } + + +} + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/TextEditorActionBarContributor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/TextEditorActionBarContributor.java new file mode 100644 index 00000000..f03ab627 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/TextEditorActionBarContributor.java @@ -0,0 +1,11 @@ +package org.simantics.sysdyn.ui.modelica; + +import org.eclipse.ui.part.EditorActionBarContributor; + +public class TextEditorActionBarContributor extends EditorActionBarContributor { + + public TextEditorActionBarContributor() { + // TODO Auto-generated constructor stub + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java new file mode 100644 index 00000000..c02ac45a --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java @@ -0,0 +1,27 @@ +package org.simantics.sysdyn.representation; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.objmap.IMapping; +import org.simantics.objmap.Mappings; + +public class LoadRepresentation { + + public static Configuration load(Session session, final Resource configuration) throws DatabaseException { + return session.syncRequest(new Read() { + + @Override + public Configuration perform(ReadGraph graph) + throws DatabaseException { + SysdynSchema schema = new SysdynSchema(graph); + IMapping mapping = Mappings.createWithoutListening(schema); + return (Configuration)mapping.map(graph, configuration); + } + + }); + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java new file mode 100644 index 00000000..eccb7c9d --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java @@ -0,0 +1,31 @@ +package org.simantics.sysdyn.representation; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.schema.MappingSchemas; +import org.simantics.objmap.schema.SimpleSchema; + +public class SysdynSchema extends SimpleSchema { + + public SysdynSchema(ReadGraph g) { + try { + addLinkType(MappingSchemas.fromAnnotations(g, Auxiliary.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Cloud.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Configuration.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Dependency.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Flow.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Stock.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Valve.class)); + } catch (DatabaseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} -- 2.47.1