[Exmmt-commit] SF.net SVN: exmmt: [2] net.sourceforge.exmmt
Status: Inactive
Brought to you by:
lgrammel
From: <lgr...@us...> - 2006-05-15 12:48:57
|
Revision: 2 Author: lgrammel Date: 2006-05-15 05:48:08 -0700 (Mon, 15 May 2006) ViewCVS: http://svn.sourceforge.net/exmmt/?rev=2&view=rev Log Message: ----------- #1488473 migrate model editor from nomad pim to exmmt Added Paths: ----------- net.sourceforge.exmmt/.classpath net.sourceforge.exmmt/.project net.sourceforge.exmmt/META-INF/ net.sourceforge.exmmt/META-INF/MANIFEST.MF net.sourceforge.exmmt/build.properties net.sourceforge.exmmt/plugin.xml net.sourceforge.exmmt/resources/ net.sourceforge.exmmt/resources/icons/ net.sourceforge.exmmt/resources/icons/editor.gif net.sourceforge.exmmt/src/ net.sourceforge.exmmt/src/java/ net.sourceforge.exmmt/src/java/net/ net.sourceforge.exmmt/src/java/net/sourceforge/ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPoint.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactoryFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactoryFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Area.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactoryFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/DisplayVisitor.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteral.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactoryFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayElementFactoryFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayMapping.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElement.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElementVisitor.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IFocusChecker.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Line.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactoryFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Literal.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelEditor.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelText.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/NavigationElementSearcher.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/VariableFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/VariableFactoryFactory.java net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/VariableLiteral.java net.sourceforge.exmmt/src/mappings/ net.sourceforge.exmmt/src/mappings/JavaModelFiles.mapping.xml net.sourceforge.exmmt/src/mappings/Mapping.mapping.xml net.sourceforge.exmmt/src/mappings/mapping.xml Property Changed: ---------------- net.sourceforge.exmmt/ Property changes on: net.sourceforge.exmmt ___________________________________________________________________ Name: svn:ignore + bin Added: net.sourceforge.exmmt/.classpath =================================================================== --- net.sourceforge.exmmt/.classpath (rev 0) +++ net.sourceforge.exmmt/.classpath 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src/java"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> Property changes on: net.sourceforge.exmmt/.classpath ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/.project =================================================================== --- net.sourceforge.exmmt/.project (rev 0) +++ net.sourceforge.exmmt/.project 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>net.sourceforge.exmmt</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Property changes on: net.sourceforge.exmmt/.project ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/META-INF/MANIFEST.MF =================================================================== --- net.sourceforge.exmmt/META-INF/MANIFEST.MF (rev 0) +++ net.sourceforge.exmmt/META-INF/MANIFEST.MF 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Eclipse XML Meta-Modeling Tools +Bundle-SymbolicName: net.sourceforge.exmmt;singleton:=true +Bundle-Version: 0.0.1 +Bundle-Vendor: exmmt.sourceforge.net project +Bundle-Localization: plugin +Bundle-ClassPath: org.nomadpim.ide.jar +Eclipse-LazyStart: false +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.ui.views, + org.eclipse.ui.editors, + org.eclipse.ui.ide, + org.eclipse.core.resources, + org.jdom +Export-Package: net.sourceforge.exmmt Property changes on: net.sourceforge.exmmt/META-INF/MANIFEST.MF ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/build.properties =================================================================== --- net.sourceforge.exmmt/build.properties (rev 0) +++ net.sourceforge.exmmt/build.properties 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,10 @@ +bin.includes = META-INF/,\ + org.nomadpim.ide.jar,\ + plugin.xml,\ + resources/ +jars.compile.order = org.nomadpim.ide.jar +source.org.nomadpim.ide.jar = src/java/ +output.org.nomadpim.ide.jar = bin/ +src.includes = plugin.xml,\ + src/,\ + resources/ Property changes on: net.sourceforge.exmmt/build.properties ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/plugin.xml =================================================================== --- net.sourceforge.exmmt/plugin.xml (rev 0) +++ net.sourceforge.exmmt/plugin.xml 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin> + + <extension point="org.eclipse.ui.editors"> + <editor + class="net.sourceforge.exmmt.ModelEditor" + extensions="xml" + icon="resources/icons/editor.gif" + id="net.sourceforge.exmmt.ModelEditor" + name="Model Editor"/> + </extension> + +</plugin> Property changes on: net.sourceforge.exmmt/plugin.xml ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/resources/icons/editor.gif =================================================================== (Binary files differ) Property changes on: net.sourceforge.exmmt/resources/icons/editor.gif ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPoint.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPoint.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPoint.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,67 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.List; +import java.util.Map; + +import org.jdom.Element; + +public class AdditionPoint implements IDisplayModelElement { + + private Element parent; + + private Map<String, IDisplayMapping> mappingMap; + + private Area parentArea; + + private String childElementName; + + private Map<String, String> defaultValueMap; + + public AdditionPoint(Element parent, + Map<String, IDisplayMapping> mappingMap, Area parentArea, + Map<String, String> defaultValueMap, String childElementName) { + + assert parent != null; + + this.defaultValueMap = defaultValueMap; + this.childElementName = childElementName; + this.mappingMap = mappingMap; + this.parent = parent; + this.parentArea = parentArea; + } + + public void accept(IDisplayModelElementVisitor visitor) { + visitor.visit(this); + } + + public void execute() { + System.out.println("execute"); + + Element element2 = new Element(childElementName); + for (Map.Entry<String,String> entry : defaultValueMap.entrySet()) { + element2.setAttribute(entry.getKey(), entry.getValue()); + } + + List<Element> attributes = parent.getChildren(childElementName); + Element last = attributes.get(attributes.size() - 1); + int index = parent.indexOf(last); + + parent.addContent(index + 1, element2); + + parentArea.insertBefore(this, mappingMap.get(childElementName).create( + element2, parentArea)); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPoint.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,40 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.Map; + +import org.jdom.Element; + +public class AdditionPointFactory implements IDisplayMapping { + + private Map<String, IDisplayMapping> mappingMap; + + private String childElementName; + + private Map<String, String> defaultValueMap; + + public AdditionPointFactory(Map<String, IDisplayMapping> mappingMap, + Map<String, String> defaultValueMap, String childElementName) { + + this.defaultValueMap = defaultValueMap; + this.childElementName = childElementName; + this.mappingMap = mappingMap; + } + + public AdditionPoint create(Element element, IDisplayModelElement parent) { + return new AdditionPoint(element, mappingMap, (Area) parent, + defaultValueMap, childElementName); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactoryFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactoryFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactoryFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,41 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jdom.Element; + +public class AdditionPointFactoryFactory implements + IDisplayElementFactoryFactory { + + public AdditionPointFactory create(Element configuration, + Map<String, IDisplayElementFactoryFactory> factoryMap, + Map<String, IDisplayMapping> mappings) { + + Map<String, String> defaultValueMap = new HashMap<String, String>(); + + List<Element> defaultValueElements = configuration + .getChildren("default-value"); + for (Element defaultValue : defaultValueElements) { + defaultValueMap.put(defaultValue.getAttributeValue("attribute"), + defaultValue.getAttributeValue("value")); + } + + return new AdditionPointFactory(mappings, defaultValueMap, + configuration.getAttributeValue("element")); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AdditionPointFactoryFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,57 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.List; +import java.util.Map; + +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.xpath.XPath; + +public class ApplyMappingsFactory implements IDisplayMapping { + + private final Map<String, IDisplayMapping> mappingMap; + + private final String selection; + + public ApplyMappingsFactory(String selection, + Map<String, IDisplayMapping> mappingMap) { + this.selection = selection; + this.mappingMap = mappingMap; + } + + public Area create(Element element, IDisplayModelElement parent) { + Area area = new Area(0); + + // use xpath + try { + List childElements = XPath.selectNodes(element, selection); + + // List<Element> childElements = element.getChildren(selection); + for (Object child : childElements) { + if (child instanceof Element) { + Element childElement = (Element) child; + area.add(mappingMap.get(childElement.getName()).create( + childElement, area)); + } + } + } catch (JDOMException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return area; + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactoryFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactoryFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactoryFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,30 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.Map; + +import org.jdom.Element; + +public class ApplyMappingsFactoryFactory implements + IDisplayElementFactoryFactory { + + public ApplyMappingsFactory create(Element configuration, + Map<String, IDisplayElementFactoryFactory> factoryMap, + Map<String, IDisplayMapping> mappings) { + + return new ApplyMappingsFactory( + configuration.getAttributeValue("select"), mappings); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ApplyMappingsFactoryFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Area.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Area.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Area.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,56 @@ +/* $RCSfile$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.ArrayList; +import java.util.List; + +public class Area implements IDisplayModelElement { + + private List<IDisplayModelElement> children = new ArrayList<IDisplayModelElement>(); + + private final int indent; + + public Area(int indent, IDisplayModelElement... children) { + assert indent >= 0; + + this.indent = indent; + + for (IDisplayModelElement element : children) { + add(element); + } + } + + public void add(IDisplayModelElement element) { + this.children.add(element); + } + + public void accept(IDisplayModelElementVisitor visitor) { + visitor.areaStart(this); + + for (IDisplayModelElement child : children) { + child.accept(visitor); + } + + visitor.areaEnd(this); + } + + public void insertBefore(AdditionPoint point, IDisplayModelElement element) { + children.add(children.indexOf(point), element); + } + + public int getIndent() { + return indent; + } + +} Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Area.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,44 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.ArrayList; +import java.util.List; + +import org.jdom.Element; + +public class AreaFactory implements IDisplayMapping { + + private final List<IDisplayMapping> childFactories = new ArrayList<IDisplayMapping>(); + + private int indent; + + public AreaFactory(int indent) { + this.indent = indent; + } + + public void addChildFactory(IDisplayMapping mapping) { + childFactories.add(mapping); + } + + public Area create(Element element, IDisplayModelElement parent) { + Area result = new Area(indent); + + for (IDisplayMapping mapping : childFactories) { + result.add(mapping.create(element, result)); + } + + return result; + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactoryFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactoryFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactoryFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,38 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.List; +import java.util.Map; + +import org.jdom.Element; + +public class AreaFactoryFactory implements IDisplayElementFactoryFactory { + + public AreaFactory create(Element configuration, + Map<String, IDisplayElementFactoryFactory> factoryMap, + Map<String, IDisplayMapping> mappings) { + + AreaFactory areaFactory = new AreaFactory(Integer + .parseInt(configuration.getAttributeValue("indent"))); + + List<Element> children = configuration.getChildren(); + for (Element child : children) { + areaFactory.addChildFactory(factoryMap.get(child.getName()).create( + child, factoryMap, mappings)); + } + + return areaFactory; + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/AreaFactoryFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/DisplayVisitor.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/DisplayVisitor.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/DisplayVisitor.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,149 @@ +/* $RCSfile$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.TextLayout; +import org.eclipse.swt.widgets.Caret; + +public final class DisplayVisitor implements IDisplayModelElementVisitor { + + private final TextLayout layout; + + private final GC gc; + + private int xPosition = 0; + + private int yPosition = 0; + + private Color color; + + private Color color2; + + private Color color3; + + private IFocusChecker focusChecker; + + private Caret caret; + + private List<Area> areaStack = new ArrayList<Area>(); + + public DisplayVisitor(GC gc, Color color, Color color2, Color color3, + IFocusChecker focusChecker, Caret caret) { + assert gc != null; + + this.caret = caret; + this.focusChecker = focusChecker; + this.color = color; + this.color2 = color2; + this.color3 = color3; + this.gc = gc; + this.layout = new TextLayout(gc.getDevice()); + + layout.setFont(gc.getFont()); + } + + public void areaEnd(Area area) { + areaStack.remove(0); + } + + public void areaStart(Area area) { + areaStack.add(0, area); + } + + public void dispose() { + layout.dispose(); + } + + public void lineEnd(Line line) { + yPosition += layout.getBounds().height; + } + + public void lineStart(Line line) { + int sum = 0; + for (Area area : areaStack) { + sum += area.getIndent(); + } + + xPosition = sum; + } + + public void visit(AdditionPoint point) { + boolean hasFocus = focusChecker.hasFocus(point); + if (hasFocus) { + gc.setBackground(color3); + } else { + gc.setBackground(color2); + } + + gc.drawText("+", xPosition, yPosition); + layout.setText("+"); + Rectangle bounds = layout.getBounds(); + + xPosition = 0; + yPosition += layout.getBounds().height; + + if (hasFocus) { + caret.setVisible(false); + } + + gc.setBackground(color); + } + + public void visit(FixedLiteral literal) { + visit((Literal) literal); + } + + public void visit(Literal literal) { + gc.drawText(literal.getValue(), xPosition, yPosition); + layout.setText(literal.getValue()); + Rectangle bounds = layout.getBounds(); + + bounds.x = xPosition; + bounds.y = yPosition; + + literal.setBounds(bounds); + + xPosition += bounds.width; + } + + public void visit(VariableLiteral literal) { + boolean hasFocus = focusChecker.hasFocus(literal); + if (hasFocus) { + gc.setBackground(color3); + } else { + gc.setBackground(color2); + } + + visit((Literal) literal); + + if (hasFocus) { + caret.setSize(2, literal.getBounds().height); + caret.setVisible(true); + + String part = literal.getValue().substring(0, literal.getCaretPosition()); + layout.setText(part); + Rectangle bounds = layout.getBounds(); + + caret.setLocation(literal.getBounds().x + bounds.width, literal.getBounds().y); + } + + gc.setBackground(color); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/DisplayVisitor.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteral.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteral.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteral.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,33 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +public class FixedLiteral extends Literal { + + private final String value; + + public FixedLiteral(String value) { + assert value != null; + + this.value = value; + } + + public void accept(IDisplayModelElementVisitor visitor) { + visitor.visit(this); + } + + public final String getValue() { + return value; + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteral.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,31 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import org.jdom.Element; + +public class FixedLiteralFactory implements IDisplayMapping { + + private final String literal; + + public FixedLiteralFactory(String literal) { + assert literal != null; + + this.literal = literal; + } + + public IDisplayModelElement create(Element element, IDisplayModelElement parent) { + return new FixedLiteral(literal); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactoryFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactoryFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactoryFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,28 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.Map; + +import org.jdom.Element; + +public class FixedLiteralFactoryFactory implements IDisplayElementFactoryFactory { + + public FixedLiteralFactory create(Element configuration, + Map<String, IDisplayElementFactoryFactory> factoryMap, + Map<String, IDisplayMapping> mappings) { + + return new FixedLiteralFactory(configuration.getText()); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/FixedLiteralFactoryFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayElementFactoryFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayElementFactoryFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayElementFactoryFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,25 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.Map; + +import org.jdom.Element; + +public interface IDisplayElementFactoryFactory { + + IDisplayMapping create(Element configuration, + Map<String, IDisplayElementFactoryFactory> factoryMap, + Map<String, IDisplayMapping> mappings); + +} Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayElementFactoryFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayMapping.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayMapping.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayMapping.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,21 @@ +/* $RCSfile$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import org.jdom.Element; + +public interface IDisplayMapping { + + IDisplayModelElement create(Element element, IDisplayModelElement parent); + +} Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayMapping.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElement.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElement.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElement.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,19 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +public interface IDisplayModelElement { + + void accept(IDisplayModelElementVisitor visitor); + +} Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElement.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElementVisitor.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElementVisitor.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElementVisitor.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,31 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +public interface IDisplayModelElementVisitor { + + void visit(FixedLiteral literal); + + void visit(VariableLiteral literal); + + void lineStart(Line line); + + void lineEnd(Line line); + + void areaStart(Area area); + + void areaEnd(Area area); + + void visit(AdditionPoint point); + +} Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IDisplayModelElementVisitor.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IFocusChecker.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IFocusChecker.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IFocusChecker.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,19 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +public interface IFocusChecker { + + boolean hasFocus(IDisplayModelElement point); + +} Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/IFocusChecker.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Line.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Line.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Line.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,44 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.ArrayList; +import java.util.List; + +public class Line implements IDisplayModelElement { + + private List<IDisplayModelElement> children = new ArrayList<IDisplayModelElement>(); + + public Line(IDisplayModelElement... children) { + assert children != null; + + for (IDisplayModelElement element : children) { + add(element); + } + } + + public void add(IDisplayModelElement element) { + this.children.add(element); + } + + public void accept(IDisplayModelElementVisitor visitor) { + visitor.lineStart(this); + + for (IDisplayModelElement child : children) { + child.accept(visitor); + } + + visitor.lineEnd(this); + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Line.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,38 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.ArrayList; +import java.util.List; + +import org.jdom.Element; + +public class LineFactory implements IDisplayMapping { + + private final List<IDisplayMapping> childFactories = new ArrayList<IDisplayMapping>(); + + public void addChildFactory(IDisplayMapping mapping) { + childFactories.add(mapping); + } + + public Line create(Element element, IDisplayModelElement parent) { + Line line = new Line(); + + for (IDisplayMapping mapping : childFactories) { + line.add(mapping.create(element, line)); + } + + return line; + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactoryFactory.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactoryFactory.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactoryFactory.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,36 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.util.List; +import java.util.Map; + +import org.jdom.Element; + +public class LineFactoryFactory implements IDisplayElementFactoryFactory { + + public LineFactory create(Element configuration, + Map<String, IDisplayElementFactoryFactory> factoryMap, + Map<String, IDisplayMapping> mappings) { + + LineFactory lineFactory = new LineFactory(); + + List<Element> children = configuration.getChildren(); + for (Element child : children) { + lineFactory.addChildFactory(factoryMap.get(child.getName()).create(child, factoryMap, mappings)); + } + + return lineFactory; + } + +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/LineFactoryFactory.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Literal.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Literal.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Literal.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,30 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import org.eclipse.swt.graphics.Rectangle; + +public abstract class Literal implements IDisplayModelElement { + + public abstract String getValue(); + + private Rectangle bounds; + + public Rectangle getBounds() { + return bounds; + } + + public void setBounds(Rectangle r) { + this.bounds = r; + } +} \ No newline at end of file Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Literal.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelEditor.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelEditor.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelEditor.java 2006-05-15 12:48:08 UTC (rev 2) @@ -0,0 +1,331 @@ +/* $HeadURL$ + * ----------------------------------------------------------------------------- + * + * Copyright (C) Lars Grammel and others. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at + * + * http://www.eclipse.org/legal/cpl-v10.html + * + */ +package net.sourceforge.exmmt; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.EditorPart; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +public class ModelEditor extends EditorPart { + + final static boolean IS_CARBON, IS_GTK, IS_MOTIF; + + private static final String SPACE = " "; + + // TODO move / change + static { + String platform = SWT.getPlatform(); + IS_CARBON = "carbon".equals(platform); + IS_GTK = "gtk".equals(platform); + IS_MOTIF = "motif".equals(platform); + } + + IDisplayModelElement selectedLiteral; + + IDisplayModelElement rootArea; + + private Canvas control; + + private Document document; + + private boolean dirty = false; + + private IFile file; + + private Map<String, IDisplayMapping> mappingMap; + + @Override + public void createPartControl(Composite parent) { + control = new ModelText(this, parent, SWT.NONE); + } + + @Override + public void dispose() { + if (control != null) { + control.dispose(); + } + + super.dispose(); + } + + @Override + public void doSave(IProgressMonitor monitor) { + try { + // write the document back + XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + outputter.output(document, out); + + out.flush(); + out.close(); + + ByteArrayInputStream in = new ByteArrayInputStream(out + .toByteArray()); + + file.setContents(in, true, true, null); + + dirty = false; + firePropertyChange(PROP_DIRTY); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public void doSaveAs() { + } + + public Document getMappingFile() throws JDOMException, IOException { + String mappingFile = document.getRootElement().getAttributeValue( + "file", document.getRootElement().getNamespace("mapping")); + + System.out.println(mappingFile); + + IPath projectLocation = file.getProject().getLocation(); + IPath path2 = projectLocation.append(file.getProjectRelativePath() + .removeLastSegments(1)); + IPath path = path2.append(mappingFile); + + SAXBuilder builder = new SAXBuilder(); + return builder.build(path.toFile()); + } + + @Override + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + setSite(site); + setInput(input); + + file = (IFile) input.getAdapter(IFile.class); + try { + document = new SAXBuilder().build(file.getContents()); + System.out.println(document); + } catch (JDOMException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + createMappings(); + rootArea = mappingMap.get(document.getRootElement().getName()).create( + document.getRootElement(), null); + selectedLiteral = getVariableLiterals().get(0); + } + + @Override + public boolean isDirty() { + return dirty; + } + + @Override + public boolean isSaveAsAllowed() { + return false; + } + + @Override + public void setFocus() { + } + + void handleKeyDown(Event event) { + System.out.println(event); + + // TODO refactor + if (((event.keyCode == SWT.TAB) && ((event.stateMask & SWT.SHIFT) == SWT.SHIFT)) + || event.keyCode == SWT.ARROW_UP) { + int index = getVariableLiterals().indexOf(selectedLiteral) - 1; + if (index < 0) { + index = getVariableLiterals().size() - 1; + } + selectedLiteral = getVariableLiterals().get(index); + control.redraw(); + } else if (((event.keyCode == SWT.TAB) && !((event.stateMask & SWT.SHIFT) == SWT.SHIFT)) + || event.keyCode == SWT.ARROW_DOWN) { + int index = getVariableLiterals().indexOf(selectedLiteral) + 1; + if (index >= getVariableLiterals().size()) { + index = 0; + } + selectedLiteral = getVariableLiterals().get(index); + control.redraw(); + } else if (event.keyCode == SWT.ARROW_RIGHT + && selectedLiteral instanceof VariableLiteral) { + + VariableLiteral literal = (VariableLiteral) selectedLiteral; + + literal.setCaretPosition(literal.getCaretPosition() + 1); + control.redraw(); + } else if (event.keyCode == SWT.ARROW_LEFT + && selectedLiteral instanceof VariableLiteral) { + VariableLiteral literal = (VariableLiteral) selectedLiteral; + literal.setCaretPosition(literal.getCaretPosition() - 1); + control.redraw(); + } else if (event.keyCode == SWT.CR + && selectedLiteral instanceof AdditionPoint) { + AdditionPoint literal = (AdditionPoint) selectedLiteral; + literal.execute(); + control.redraw(); + } else if (event.keyCode == SWT.DEL + && selectedLiteral instanceof VariableLiteral) { + VariableLiteral literal = (VariableLiteral) selectedLiteral; + if (literal.getCaretPosition() < literal.getValue().length()) { + StringBuffer value = new StringBuffer(literal.getValue()); + value.deleteCharAt(literal.getCaretPosition()); + literal.setValue(value.toString()); + changed(); + control.redraw(); + } + } else if (event.keyCode == SWT.BS + && selectedLiteral instanceof VariableLiteral) { + VariableLiteral literal = (VariableLiteral) selectedLiteral; + if (literal.getCaretPosition() > 0) { + StringBuffer value = new StringBuffer(literal.getValue()); + value.deleteCharAt(literal.getCaretPosition() - 1); + literal.setValue(value.toString()); + literal.setCaretPosition(literal.getCaretPosition() - 1); + changed(); + control.redraw(); + } + } else if (isValidCharacter(event.stateMask, event.character) + && selectedLiteral instanceof VariableLiteral) { + VariableLiteral literal = (VariableLiteral) selectedLiteral; + StringBuffer value = new StringBuffer(literal.getValue()); + value.insert(literal.getCaretPosition(), event.character); + literal.setValue(value.toString()); + literal.setCaretPosition(literal.getCaretPosition() + 1); + changed(); + control.redraw(); + } + } + + private void changed() { + dirty = true; + firePropertyChange(PROP_DIRTY); + } + + private void createMappings() { + mappingMap = new HashMap<String, IDisplayMapping>(); + Map<String, IDisplayElementFactoryFactory> metaMappingMap = createMetaMappingMap(); + + try { + Document mappingFile = getMappingFile(); + + Element rootElement = mappingFile.getRootElement(); + List<Element> mappings = rootElement.getChildren("mapping"); + + for (Element mappingElement : mappings) { + Element configuration = (Element) mappingElement.getChildren() + .get(0); + + IDisplayMapping mappingX = metaMappingMap.get( + configuration.getName()).create(configuration, + metaMappingMap, mappingMap); + + mappingMap.put(mappingElement.getAttributeValue("select"), + mappingX); + } + + } catch (JDOMException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private Map<String, IDisplayElementFactoryFactory> createMetaMappingMap() { + Map<String, IDisplayElementFactoryFactory> metaMappingMap = new HashMap<String, IDisplayElementFactoryFactory>(); + + metaMappingMap.put("area", new AreaFactoryFactory()); + metaMappingMap.put("line", new LineFactoryFactory()); + metaMappingMap.put("edit", new VariableFactoryFactory()); + metaMappingMap.put("literal", new FixedLiteralFactoryFactory()); + metaMappingMap.put("apply-mappings", new ApplyMappingsFactoryFactory()); + metaMappingMap.put("addition-point", new AdditionPointFactoryFactory()); + + return metaMappingMap; + } + + private List<IDisplayModelElement> getVariableLiterals() { + NavigationElementSearcher visitor = new NavigationElementSearcher(); + + rootArea.accept(visitor); + + return visitor.getNavigationElements(); + } + + private boolean isValidCharacter(int stateMask, char character) { + boolean ignore = false; + + if (IS_CARBON) { + // Ignore accelerator key combinations (we do not want to + // insert a character in the text in this instance). Do not + // ignore COMMAND+ALT combinations since that key sequence + // produces characters on the mac. + ignore = (stateMask ^ SWT.COMMAND) == 0 + || (stateMask ^ (SWT.COMMAND | SWT.SHIFT)) == 0; + } else if (IS_MOTIF) { + // Ignore accelerator key combinations (we do not want to + // insert a character in the text in this instance). Do not + // ignore ALT combinations since this key sequence + // produces characters on motif. + ignore = (stateMask ^ SWT.CTRL) == 0 + || (stateMask ^ (SWT.CTRL | SWT.SHIFT)) == 0; + } else { + // Ignore accelerator key combinations (we do not want to + // insert a character in the text in this instance). Don't + // ignore CTRL+ALT combinations since that is the Alt Gr + // key on some keyboards. See bug 20953. + ignore = (stateMask ^ SWT.ALT) == 0 || (stateMask ^ SWT.CTRL) == 0 + || (stateMask ^ (SWT.ALT | SWT.SHIFT)) == 0 + || (stateMask ^ (SWT.CTRL | SWT.SHIFT)) == 0; + } + boolean isCharacter = !ignore && character > 31 && character != SWT.DEL; + // -ignore anything below SPACE except for line delimiter keys and tab. + // -ignore DEL + return isCharacter; + } +} Property changes on: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelEditor.java ___________________________________________________________________ Name: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelText.java =================================================================== --- net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/ModelText.java (rev 0) +++ net.sourceforge.exmmt/src/java/net/sourceforge/exmmt/Mode... [truncated message content] |