[eclipsefinance-subversion] SF.net SVN: eclipsefinance: [17] trunk/net.sf.eclipsefinance.converter.
Status: Pre-Alpha
Brought to you by:
yukio7
|
From: <yu...@us...> - 2006-09-20 06:58:06
|
Revision: 17
http://svn.sourceforge.net/eclipsefinance/?rev=17&view=rev
Author: yukio7
Date: 2006-09-19 23:57:37 -0700 (Tue, 19 Sep 2006)
Log Message:
-----------
new project
Added Paths:
-----------
trunk/net.sf.eclipsefinance.converter.ubs/.classpath
trunk/net.sf.eclipsefinance.converter.ubs/.project
trunk/net.sf.eclipsefinance.converter.ubs/META-INF/
trunk/net.sf.eclipsefinance.converter.ubs/META-INF/MANIFEST.MF
trunk/net.sf.eclipsefinance.converter.ubs/build.properties
trunk/net.sf.eclipsefinance.converter.ubs/icons/
trunk/net.sf.eclipsefinance.converter.ubs/icons/sample.gif
trunk/net.sf.eclipsefinance.converter.ubs/plugin.xml
trunk/net.sf.eclipsefinance.converter.ubs/src/
trunk/net.sf.eclipsefinance.converter.ubs/src/net/
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/Activator.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/CSVEditor.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/ColorManager.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/IXMLColorConstants.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/NonRuleBasedDamagerRepairer.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/TagRule.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLConfiguration.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDocumentProvider.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDoubleClickStrategy.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLPartitionScanner.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLScanner.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLTagScanner.java
trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLWhitespaceDetector.java
Added: trunk/net.sf.eclipsefinance.converter.ubs/.classpath
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/.classpath (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/.classpath 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="classes"/>
+</classpath>
Added: trunk/net.sf.eclipsefinance.converter.ubs/.project
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/.project (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/.project 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>net.sf.eclipsefinance.converter.ubs</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>
Added: trunk/net.sf.eclipsefinance.converter.ubs/META-INF/MANIFEST.MF
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/META-INF/MANIFEST.MF (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/META-INF/MANIFEST.MF 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Ubs Plug-in
+Bundle-SymbolicName: net.sf.eclipsefinance.converter.ubs; singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: net.sf.eclipsefinance.converter.ubs.Activator
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.jface.text,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.workbench.texteditor
+Eclipse-LazyStart: true
Added: trunk/net.sf.eclipsefinance.converter.ubs/build.properties
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/build.properties (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/build.properties 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = classes/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/
Added: trunk/net.sf.eclipsefinance.converter.ubs/icons/sample.gif
===================================================================
(Binary files differ)
Property changes on: trunk/net.sf.eclipsefinance.converter.ubs/icons/sample.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/net.sf.eclipsefinance.converter.ubs/plugin.xml
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/plugin.xml (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/plugin.xml 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="UBS CSV Editor"
+ extensions="csv"
+ icon="icons/sample.gif"
+ contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
+ class="net.sf.eclipsefinance.converter.ubs.editors.CSV Editor"
+ id="net.sf.eclipsefinance.converter.ubs.editors.CSV Editor">
+ </editor>
+ </extension>
+
+</plugin>
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/Activator.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/Activator.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/Activator.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,61 @@
+package net.sf.eclipsefinance.converter.ubs;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "net.sf.eclipsefinance.converter.ubs";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/CSVEditor.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/CSVEditor.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/CSVEditor.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,20 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.ui.editors.text.TextEditor;
+
+public class CSVEditor extends TextEditor {
+
+ private ColorManager colorManager;
+
+ public CSVEditor() {
+ super();
+ colorManager = new ColorManager();
+ setSourceViewerConfiguration(new XMLConfiguration(colorManager));
+ setDocumentProvider(new XMLDocumentProvider());
+ }
+ public void dispose() {
+ colorManager.dispose();
+ super.dispose();
+ }
+
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/ColorManager.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/ColorManager.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/ColorManager.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,28 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+public class ColorManager {
+
+ protected Map fColorTable = new HashMap(10);
+
+ public void dispose() {
+ Iterator e = fColorTable.values().iterator();
+ while (e.hasNext())
+ ((Color) e.next()).dispose();
+ }
+ public Color getColor(RGB rgb) {
+ Color color = (Color) fColorTable.get(rgb);
+ if (color == null) {
+ color = new Color(Display.getCurrent(), rgb);
+ fColorTable.put(rgb, color);
+ }
+ return color;
+ }
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/IXMLColorConstants.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/IXMLColorConstants.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/IXMLColorConstants.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,11 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.swt.graphics.RGB;
+
+public interface IXMLColorConstants {
+ RGB XML_COMMENT = new RGB(128, 0, 0);
+ RGB PROC_INSTR = new RGB(128, 128, 128);
+ RGB STRING = new RGB(0, 128, 0);
+ RGB DEFAULT = new RGB(0, 0, 0);
+ RGB TAG = new RGB(0, 0, 128);
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/NonRuleBasedDamagerRepairer.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/NonRuleBasedDamagerRepairer.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/NonRuleBasedDamagerRepairer.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,138 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.presentation.IPresentationDamager;
+import org.eclipse.jface.text.presentation.IPresentationRepairer;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.swt.custom.StyleRange;
+
+public class NonRuleBasedDamagerRepairer
+ implements IPresentationDamager, IPresentationRepairer {
+
+ /** The document this object works on */
+ protected IDocument fDocument;
+ /** The default text attribute if non is returned as data by the current token */
+ protected TextAttribute fDefaultTextAttribute;
+
+ /**
+ * Constructor for NonRuleBasedDamagerRepairer.
+ */
+ public NonRuleBasedDamagerRepairer(TextAttribute defaultTextAttribute) {
+ Assert.isNotNull(defaultTextAttribute);
+
+ fDefaultTextAttribute = defaultTextAttribute;
+ }
+
+ /**
+ * @see IPresentationRepairer#setDocument(IDocument)
+ */
+ public void setDocument(IDocument document) {
+ fDocument = document;
+ }
+
+ /**
+ * Returns the end offset of the line that contains the specified offset or
+ * if the offset is inside a line delimiter, the end offset of the next line.
+ *
+ * @param offset the offset whose line end offset must be computed
+ * @return the line end offset for the given offset
+ * @exception BadLocationException if offset is invalid in the current document
+ */
+ protected int endOfLineOf(int offset) throws BadLocationException {
+
+ IRegion info = fDocument.getLineInformationOfOffset(offset);
+ if (offset <= info.getOffset() + info.getLength())
+ return info.getOffset() + info.getLength();
+
+ int line = fDocument.getLineOfOffset(offset);
+ try {
+ info = fDocument.getLineInformation(line + 1);
+ return info.getOffset() + info.getLength();
+ } catch (BadLocationException x) {
+ return fDocument.getLength();
+ }
+ }
+
+ /**
+ * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
+ */
+ public IRegion getDamageRegion(
+ ITypedRegion partition,
+ DocumentEvent event,
+ boolean documentPartitioningChanged) {
+ if (!documentPartitioningChanged) {
+ try {
+
+ IRegion info =
+ fDocument.getLineInformationOfOffset(event.getOffset());
+ int start = Math.max(partition.getOffset(), info.getOffset());
+
+ int end =
+ event.getOffset()
+ + (event.getText() == null
+ ? event.getLength()
+ : event.getText().length());
+
+ if (info.getOffset() <= end
+ && end <= info.getOffset() + info.getLength()) {
+ // optimize the case of the same line
+ end = info.getOffset() + info.getLength();
+ } else
+ end = endOfLineOf(end);
+
+ end =
+ Math.min(
+ partition.getOffset() + partition.getLength(),
+ end);
+ return new Region(start, end - start);
+
+ } catch (BadLocationException x) {
+ }
+ }
+
+ return partition;
+ }
+
+ /**
+ * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion)
+ */
+ public void createPresentation(
+ TextPresentation presentation,
+ ITypedRegion region) {
+ addRange(
+ presentation,
+ region.getOffset(),
+ region.getLength(),
+ fDefaultTextAttribute);
+ }
+
+ /**
+ * Adds style information to the given text presentation.
+ *
+ * @param presentation the text presentation to be extended
+ * @param offset the offset of the range to be styled
+ * @param length the length of the range to be styled
+ * @param attr the attribute describing the style of the range to be styled
+ */
+ protected void addRange(
+ TextPresentation presentation,
+ int offset,
+ int length,
+ TextAttribute attr) {
+ if (attr != null)
+ presentation.addStyleRange(
+ new StyleRange(
+ offset,
+ length,
+ attr.getForeground(),
+ attr.getBackground(),
+ attr.getStyle()));
+ }
+}
\ No newline at end of file
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/TagRule.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/TagRule.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/TagRule.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,31 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.rules.*;
+
+public class TagRule extends MultiLineRule {
+
+ public TagRule(IToken token) {
+ super("<", ">", token);
+ }
+ protected boolean sequenceDetected(
+ ICharacterScanner scanner,
+ char[] sequence,
+ boolean eofAllowed) {
+ int c = scanner.read();
+ if (sequence[0] == '<') {
+ if (c == '?') {
+ // processing instruction - abort
+ scanner.unread();
+ return false;
+ }
+ if (c == '!') {
+ scanner.unread();
+ // comment - abort
+ return false;
+ }
+ } else if (sequence[0] == '>') {
+ scanner.unread();
+ }
+ return super.sequenceDetected(scanner, sequence, eofAllowed);
+ }
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLConfiguration.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLConfiguration.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLConfiguration.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,79 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+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.Token;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+
+public class XMLConfiguration extends SourceViewerConfiguration {
+ private XMLDoubleClickStrategy doubleClickStrategy;
+ private XMLTagScanner tagScanner;
+ private XMLScanner scanner;
+ private ColorManager colorManager;
+
+ public XMLConfiguration(ColorManager colorManager) {
+ this.colorManager = colorManager;
+ }
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return new String[] {
+ IDocument.DEFAULT_CONTENT_TYPE,
+ XMLPartitionScanner.XML_COMMENT,
+ XMLPartitionScanner.XML_TAG };
+ }
+ public ITextDoubleClickStrategy getDoubleClickStrategy(
+ ISourceViewer sourceViewer,
+ String contentType) {
+ if (doubleClickStrategy == null)
+ doubleClickStrategy = new XMLDoubleClickStrategy();
+ return doubleClickStrategy;
+ }
+
+ protected XMLScanner getXMLScanner() {
+ if (scanner == null) {
+ scanner = new XMLScanner(colorManager);
+ scanner.setDefaultReturnToken(
+ new Token(
+ new TextAttribute(
+ colorManager.getColor(IXMLColorConstants.DEFAULT))));
+ }
+ return scanner;
+ }
+ protected XMLTagScanner getXMLTagScanner() {
+ if (tagScanner == null) {
+ tagScanner = new XMLTagScanner(colorManager);
+ tagScanner.setDefaultReturnToken(
+ new Token(
+ new TextAttribute(
+ colorManager.getColor(IXMLColorConstants.TAG))));
+ }
+ return tagScanner;
+ }
+
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+ PresentationReconciler reconciler = new PresentationReconciler();
+
+ DefaultDamagerRepairer dr =
+ new DefaultDamagerRepairer(getXMLTagScanner());
+ reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
+ reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
+
+ dr = new DefaultDamagerRepairer(getXMLScanner());
+ reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+
+ NonRuleBasedDamagerRepairer ndr =
+ new NonRuleBasedDamagerRepairer(
+ new TextAttribute(
+ colorManager.getColor(IXMLColorConstants.XML_COMMENT)));
+ reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
+ reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
+
+ return reconciler;
+ }
+
+}
\ No newline at end of file
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDocumentProvider.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDocumentProvider.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDocumentProvider.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,25 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.FastPartitioner;
+import org.eclipse.ui.editors.text.FileDocumentProvider;
+
+public class XMLDocumentProvider extends FileDocumentProvider {
+
+ protected IDocument createDocument(Object element) throws CoreException {
+ IDocument document = super.createDocument(element);
+ if (document != null) {
+ IDocumentPartitioner partitioner =
+ new FastPartitioner(
+ new XMLPartitionScanner(),
+ new String[] {
+ XMLPartitionScanner.XML_TAG,
+ XMLPartitionScanner.XML_COMMENT });
+ partitioner.connect(document);
+ document.setDocumentPartitioner(partitioner);
+ }
+ return document;
+ }
+}
\ No newline at end of file
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDoubleClickStrategy.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDoubleClickStrategy.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLDoubleClickStrategy.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,112 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.*;
+
+public class XMLDoubleClickStrategy implements ITextDoubleClickStrategy {
+ protected ITextViewer fText;
+
+ public void doubleClicked(ITextViewer part) {
+ int pos = part.getSelectedRange().x;
+
+ if (pos < 0)
+ return;
+
+ fText = part;
+
+ if (!selectComment(pos)) {
+ selectWord(pos);
+ }
+ }
+ protected boolean selectComment(int caretPos) {
+ IDocument doc = fText.getDocument();
+ int startPos, endPos;
+
+ try {
+ int pos = caretPos;
+ char c = ' ';
+
+ while (pos >= 0) {
+ c = doc.getChar(pos);
+ if (c == '\\') {
+ pos -= 2;
+ continue;
+ }
+ if (c == Character.LINE_SEPARATOR || c == '\"')
+ break;
+ --pos;
+ }
+
+ if (c != '\"')
+ return false;
+
+ startPos = pos;
+
+ pos = caretPos;
+ int length = doc.getLength();
+ c = ' ';
+
+ while (pos < length) {
+ c = doc.getChar(pos);
+ if (c == Character.LINE_SEPARATOR || c == '\"')
+ break;
+ ++pos;
+ }
+ if (c != '\"')
+ return false;
+
+ endPos = pos;
+
+ int offset = startPos + 1;
+ int len = endPos - offset;
+ fText.setSelectedRange(offset, len);
+ return true;
+ } catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+ protected boolean selectWord(int caretPos) {
+
+ IDocument doc = fText.getDocument();
+ int startPos, endPos;
+
+ try {
+
+ int pos = caretPos;
+ char c;
+
+ while (pos >= 0) {
+ c = doc.getChar(pos);
+ if (!Character.isJavaIdentifierPart(c))
+ break;
+ --pos;
+ }
+
+ startPos = pos;
+
+ pos = caretPos;
+ int length = doc.getLength();
+
+ while (pos < length) {
+ c = doc.getChar(pos);
+ if (!Character.isJavaIdentifierPart(c))
+ break;
+ ++pos;
+ }
+
+ endPos = pos;
+ selectRange(startPos, endPos);
+ return true;
+
+ } catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+
+ private void selectRange(int startPos, int stopPos) {
+ int offset = startPos + 1;
+ int length = stopPos - offset;
+ fText.setSelectedRange(offset, length);
+ }
+}
\ No newline at end of file
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLPartitionScanner.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLPartitionScanner.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLPartitionScanner.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,21 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.rules.*;
+
+public class XMLPartitionScanner extends RuleBasedPartitionScanner {
+ public final static String XML_COMMENT = "__xml_comment";
+ public final static String XML_TAG = "__xml_tag";
+
+ public XMLPartitionScanner() {
+
+ IToken xmlComment = new Token(XML_COMMENT);
+ IToken tag = new Token(XML_TAG);
+
+ IPredicateRule[] rules = new IPredicateRule[2];
+
+ rules[0] = new MultiLineRule("<!--", "-->", xmlComment);
+ rules[1] = new TagRule(tag);
+
+ setPredicateRules(rules);
+ }
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLScanner.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLScanner.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLScanner.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,22 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.rules.*;
+import org.eclipse.jface.text.*;
+
+public class XMLScanner extends RuleBasedScanner {
+
+ public XMLScanner(ColorManager manager) {
+ IToken procInstr =
+ new Token(
+ new TextAttribute(
+ manager.getColor(IXMLColorConstants.PROC_INSTR)));
+
+ IRule[] rules = new IRule[2];
+ //Add rule for processing instructions
+ rules[0] = new SingleLineRule("<?", "?>", procInstr);
+ // Add generic whitespace rule.
+ rules[1] = new WhitespaceRule(new XMLWhitespaceDetector());
+
+ setRules(rules);
+ }
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLTagScanner.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLTagScanner.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLTagScanner.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,24 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.rules.*;
+
+public class XMLTagScanner extends RuleBasedScanner {
+
+ public XMLTagScanner(ColorManager manager) {
+ IToken string =
+ new Token(
+ new TextAttribute(manager.getColor(IXMLColorConstants.STRING)));
+
+ IRule[] rules = new IRule[3];
+
+ // Add rule for double quotes
+ rules[0] = new SingleLineRule("\"", "\"", string, '\\');
+ // Add a rule for single quotes
+ rules[1] = new SingleLineRule("'", "'", string, '\\');
+ // Add generic whitespace rule.
+ rules[2] = new WhitespaceRule(new XMLWhitespaceDetector());
+
+ setRules(rules);
+ }
+}
Added: trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLWhitespaceDetector.java
===================================================================
--- trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLWhitespaceDetector.java (rev 0)
+++ trunk/net.sf.eclipsefinance.converter.ubs/src/net/sf/eclipsefinance/converter/ubs/editors/XMLWhitespaceDetector.java 2006-09-20 06:57:37 UTC (rev 17)
@@ -0,0 +1,10 @@
+package net.sf.eclipsefinance.converter.ubs.editors;
+
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+
+public class XMLWhitespaceDetector implements IWhitespaceDetector {
+
+ public boolean isWhitespace(char c) {
+ return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|