-// $Id$\r
-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-\r
-package eu.etaxonomy.taxeditor.annotatedlineeditor;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.eclipse.jface.text.BadLocationException;\r
-import org.eclipse.jface.text.Document;\r
-import org.eclipse.jface.text.DocumentEvent;\r
-import org.eclipse.jface.text.IDocument;\r
-import org.eclipse.jface.text.IRegion;\r
-import org.eclipse.jface.text.ITypedRegion;\r
-import org.eclipse.jface.text.Region;\r
-import org.eclipse.jface.text.TypedRegion;\r
-import org.eclipse.jface.text.rules.FastPartitioner;\r
-import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;\r
-\r
-/**\r
- * Separates each line into partitions for the main text - usually the\r
- * object's title cache - and supplemental text. The supplemental text\r
- * partition can then be given a different color and / or font style by \r
- * the editor's presentation reconciler. \r
- * \r
- * @author p.ciardelli\r
- * @created 28.10.2009\r
- * @version 1.0\r
- * @deprecated\r
- */\r
-public class AnnotatedLineEditorPartitioner extends FastPartitioner {\r
- private static final Logger logger = Logger\r
- .getLogger(AnnotatedLineEditorPartitioner.class);\r
- \r
- private Document document;\r
- private LineAnnotationModel model;\r
- private ILineDisplayStrategy lineDisplayStrategy;\r
- \r
- /**\r
- * @param scanner\r
- * @param legalContentTypes\r
- */\r
- public AnnotatedLineEditorPartitioner(Document document, LineAnnotationModel model, ILineDisplayStrategy lineDisplayStrategy) {\r
- super(new RuleBasedPartitionScanner(), \r
- new String[] {ILineDisplayStrategy.SUPPLEMENTAL_TEXT});\r
- \r
- this.document = document;\r
- this.model = model;\r
- this.lineDisplayStrategy = lineDisplayStrategy;\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.text.rules.FastPartitioner#computePartitioning(int, int, boolean)\r
- */\r
- @Override\r
- public ITypedRegion[] computePartitioning(int offset,\r
- int length, boolean includeZeroLengthPartitions) {\r
- List<ITypedRegion> regions = new ArrayList<ITypedRegion>(); \r
- try {\r
- int lines = document.getNumberOfLines(offset, length);\r
- int startLine = document.getLineOfOffset(offset);\r
- \r
- // Iterate through all affected lines, separating into regions of DEFAULT_CONTENT_TYPE and SUPPLEMENTAL_TEXT\r
- for (int i = startLine; i < startLine + lines; i++) {\r
- LineAnnotation annotation = (LineAnnotation) ((LineAnnotationModel) model).getAnnotationAtLine(i, document);\r
- if (annotation != null) {\r
- IRegion lineInfo = document.getLineInformation(i);\r
- String lineText = document.get(lineInfo.getOffset(), lineInfo.getLength());\r
- \r
- String supplementalText = lineDisplayStrategy.getSupplementalText(annotation.getEntity());\r
- if (supplementalText == null || supplementalText.equals("")) {\r
- continue;\r
- }\r
- if (lineText.contains(supplementalText)) {\r
- int startSupplementalText = lineText.indexOf(supplementalText) + lineInfo.getOffset();\r
- \r
- if (startSupplementalText > lineInfo.getOffset()) {\r
- regions.add(new TypedRegion(lineInfo.getOffset(), startSupplementalText - lineInfo.getOffset(), \r
- IDocument.DEFAULT_CONTENT_TYPE));\r
- logger.warn("Non supp at " + lineInfo.getOffset() + ", length " + (startSupplementalText - lineInfo.getOffset()));\r
- } \r
- regions.add(new TypedRegion(startSupplementalText, supplementalText.length(), \r
- ILineDisplayStrategy.SUPPLEMENTAL_TEXT));\r
- logger.warn("Supp at " + startSupplementalText + ", length " + supplementalText.length());\r
- if (startSupplementalText + supplementalText.length() < lineInfo.getOffset() + lineInfo.getLength()) {\r
- regions.add(new TypedRegion(startSupplementalText + supplementalText.length(), \r
- lineInfo.getLength() - startSupplementalText - supplementalText.length(), \r
- IDocument.DEFAULT_CONTENT_TYPE));\r
- } \r
- }\r
- \r
- }\r
- }\r
- } catch (BadLocationException e) {\r
- return super.computePartitioning(offset, length, includeZeroLengthPartitions);\r
- }\r
- return (ITypedRegion[]) regions.toArray(new ITypedRegion[regions.size()]);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.text.rules.FastPartitioner#documentChanged2(org.eclipse.jface.text.DocumentEvent)\r
- */\r
- @Override\r
- public IRegion documentChanged2(DocumentEvent e) {\r
- computePartitioning(e.getOffset(), e.getLength());\r
- return new Region(e.getOffset(), e.getLength());\r
-// return super.documentChanged2(e);\r
- }\r
-}\r
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.annotatedlineeditor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+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.TypedRegion;
+import org.eclipse.jface.text.rules.FastPartitioner;
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
+
+/**
+ * Separates each line into partitions for the main text - usually the
+ * object's title cache - and supplemental text. The supplemental text
+ * partition can then be given a different color and / or font style by
+ * the editor's presentation reconciler.
+ *
+ * @author p.ciardelli
+ * @created 28.10.2009
+ * @version 1.0
+ */
+public class AnnotatedLineEditorPartitioner extends FastPartitioner {
+ private static final Logger logger = Logger
+ .getLogger(AnnotatedLineEditorPartitioner.class);
+
+ private Document document;
+ private LineAnnotationModel model;
+ private ILineDisplayStrategy lineDisplayStrategy;
+
+ /**
+ * <p>Constructor for AnnotatedLineEditorPartitioner.</p>
+ *
+ * @param document a {@link org.eclipse.jface.text.Document} object.
+ * @param model a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel} object.
+ * @param lineDisplayStrategy a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy} object.
+ */
+ public AnnotatedLineEditorPartitioner(Document document, LineAnnotationModel model, ILineDisplayStrategy lineDisplayStrategy) {
+ super(new RuleBasedPartitionScanner(),
+ new String[] {ILineDisplayStrategy.SUPPLEMENTAL_TEXT});
+
+ this.document = document;
+ this.model = model;
+ this.lineDisplayStrategy = lineDisplayStrategy;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.rules.FastPartitioner#computePartitioning(int, int, boolean)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public ITypedRegion[] computePartitioning(int offset,
+ int length, boolean includeZeroLengthPartitions) {
+ List<ITypedRegion> regions = new ArrayList<ITypedRegion>();
+ try {
+ int lines = document.getNumberOfLines(offset, length);
+ int startLine = document.getLineOfOffset(offset);
+
+ // Iterate through all affected lines, separating into regions of DEFAULT_CONTENT_TYPE and SUPPLEMENTAL_TEXT
+ for (int i = startLine; i < startLine + lines; i++) {
+ LineAnnotation annotation = (LineAnnotation) ((LineAnnotationModel) model).getAnnotationAtLine(i, document);
+ if (annotation != null) {
+ IRegion lineInfo = document.getLineInformation(i);
+ String lineText = document.get(lineInfo.getOffset(), lineInfo.getLength());
+
+ String supplementalText = lineDisplayStrategy.getSupplementalText(annotation.getEntity());
+ if (supplementalText == null || supplementalText.equals("")) {
+ continue;
+ }
+ if (lineText.contains(supplementalText)) {
+ int startSupplementalText = lineText.indexOf(supplementalText) + lineInfo.getOffset();
+
+ if (startSupplementalText > lineInfo.getOffset()) {
+ regions.add(new TypedRegion(lineInfo.getOffset(), startSupplementalText - lineInfo.getOffset(),
+ IDocument.DEFAULT_CONTENT_TYPE));
+ logger.warn("Non supp at " + lineInfo.getOffset() + ", length " + (startSupplementalText - lineInfo.getOffset()));
+ }
+ regions.add(new TypedRegion(startSupplementalText, supplementalText.length(),
+ ILineDisplayStrategy.SUPPLEMENTAL_TEXT));
+ logger.warn("Supp at " + startSupplementalText + ", length " + supplementalText.length());
+ if (startSupplementalText + supplementalText.length() < lineInfo.getOffset() + lineInfo.getLength()) {
+ regions.add(new TypedRegion(startSupplementalText + supplementalText.length(),
+ lineInfo.getLength() - startSupplementalText - supplementalText.length(),
+ IDocument.DEFAULT_CONTENT_TYPE));
+ }
+ }
+
+ }
+ }
+ } catch (BadLocationException e) {
+ return super.computePartitioning(offset, length, includeZeroLengthPartitions);
+ }
+ return (ITypedRegion[]) regions.toArray(new ITypedRegion[regions.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.rules.FastPartitioner#documentChanged2(org.eclipse.jface.text.DocumentEvent)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public IRegion documentChanged2(DocumentEvent e) {
+ computePartitioning(e.getOffset(), e.getLength());
+ return new Region(e.getOffset(), e.getLength());
+// return super.documentChanged2(e);
+ }
+}