import org.eclipse.jface.text.Position;\r
import org.eclipse.jface.text.TypedRegion;\r
import org.eclipse.jface.text.rules.FastPartitioner;\r
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;\r
+import org.eclipse.jface.text.rules.IToken;\r
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;\r
+import org.eclipse.jface.text.rules.Token;\r
import org.eclipse.jface.text.source.Annotation;\r
import org.eclipse.jface.text.source.IAnnotationModel;\r
import org.eclipse.swt.SWT;\r
\r
private Map<IEditorInput, ILineDisplayStrategy> lineDisplayStrategies = \r
new HashMap<IEditorInput, ILineDisplayStrategy>();\r
-\r
-// private ITextViewer viewer;\r
-// \r
-// public AnnotatedLineEditorDocumentProvider(ITextViewer viewer) {\r
-// this.viewer = viewer;\r
-// }\r
\r
@Override\r
public IAnnotationModel getAnnotationModel(Object element) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
- }\r
- \r
- // Create partitioner to put supplemental, non-cache text in different colors\r
- IDocumentPartitioner partitioner = \r
- new AnnotatedLineEditorPartitioner(document, (LineAnnotationModel) model, lineDisplayStrategies.get(element));\r
- partitioner.connect(document);\r
- document.setDocumentPartitioner(partitioner); \r
+ } \r
\r
return document;\r
}\r
--- /dev/null
+// $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.HashMap;\r
+import java.util.Iterator;\r
+import java.util.Map;\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.IDocument;\r
+import org.eclipse.jface.text.TextAttribute;\r
+import org.eclipse.jface.text.rules.IPredicateRule;\r
+import org.eclipse.jface.text.rules.IToken;\r
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;\r
+import org.eclipse.jface.text.rules.SingleLineRule;\r
+import org.eclipse.jface.text.rules.Token;\r
+import org.eclipse.jface.text.source.ISourceViewer;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Display;\r
+\r
+/**\r
+ * @author p.ciardelli\r
+ * @created 28.10.2009\r
+ * @version 1.0\r
+ */\r
+public class SupplementalTextScanner extends RuleBasedPartitionScanner {\r
+ private static final Logger logger = Logger\r
+ .getLogger(SupplementalTextScanner.class);\r
+ \r
+ private ILineDisplayStrategy lineDisplayStrategy;\r
+ private Document document;\r
+ private ISourceViewer sourceViewer;\r
+\r
+ private Map<Integer, String> supplementalTexts;\r
+ private SupplementalTextRule rule;\r
+ private int lastLine;\r
+ \r
+ /**\r
+ * @param sourceViewer\r
+ * @param lineDisplayStrategy\r
+ */\r
+ public SupplementalTextScanner(ISourceViewer sourceViewer, ILineDisplayStrategy lineDisplayStrategy) {\r
+ this.sourceViewer = sourceViewer;\r
+ this.lineDisplayStrategy = lineDisplayStrategy;\r
+ \r
+ TextAttribute textAttribute = new TextAttribute(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY), null, SWT.ITALIC);\r
+ IToken supplementalTextToken = new Token(textAttribute);\r
+ \r
+ rule = new SupplementalTextRule(supplementalTextToken);\r
+ setPredicateRules(new IPredicateRule[] {rule});\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.jface.text.rules.RuleBasedPartitionScanner#setPartialRange(org.eclipse.jface.text.IDocument, int, int, java.lang.String, int)\r
+ */\r
+ @Override\r
+ public void setPartialRange(IDocument document, int offset, int length,\r
+ String contentType, int partitionOffset) {\r
+ \r
+ // Get all supplemental texts in the partial range\r
+ supplementalTexts = new HashMap<Integer, String>();\r
+ LineAnnotationModel model = (LineAnnotationModel) sourceViewer.getAnnotationModel();\r
+ Iterator iter = model.getAnnotationIterator(offset, length, true, true);\r
+ while (iter.hasNext()) {\r
+ Object next = iter.next();\r
+ if (next instanceof LineAnnotation) {\r
+ Object entity = ((LineAnnotation) next).getEntity();\r
+ String supplementalText = lineDisplayStrategy.getSupplementalText(entity);\r
+ if (supplementalText != null && supplementalText.length() > 0) {\r
+ try {\r
+ int line = document.getLineOfOffset(model.getPosition((LineAnnotation) next).getOffset());\r
+ supplementalTexts.put(line, supplementalText);\r
+ } catch (BadLocationException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ }\r
+ }\r
+ }\r
+ this.document = (Document) document; \r
+ super.setPartialRange(document, offset, length, contentType, partitionOffset);\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.jface.text.rules.RuleBasedPartitionScanner#nextToken()\r
+ */\r
+ @Override\r
+ public IToken nextToken() {\r
+ try {\r
+ int line = document.getLineOfOffset(getTokenOffset());\r
+ if (line != lastLine) {\r
+ rule.setStartSequence(supplementalTexts.get(line));\r
+ }\r
+ lastLine = line;\r
+ } catch (BadLocationException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ return super.nextToken();\r
+ }\r
+ \r
+ class SupplementalTextRule extends SingleLineRule {\r
+\r
+ static final String DUMMY_SEQUENCE = "_dummy_sequence";\r
+ \r
+ /**\r
+ * @param startSequence\r
+ * @param endSequence\r
+ * @param token\r
+ * @param escapeCharacter\r
+ * @param breaksOnEOL\r
+ */\r
+ public SupplementalTextRule(IToken token) {\r
+ super(DUMMY_SEQUENCE, null, token, '\\', true);\r
+ }\r
+ \r
+ protected void setStartSequence(String sequence) {\r
+ if (sequence != null && sequence.length() > 0) {\r
+ fStartSequence = sequence.toCharArray();\r
+ }\r
+ }\r
+ \r
+ }\r
+}\r
public static final String ID = "bulkeditor.editor";\r
\r
private boolean isInitialFocus = true;\r
+\r
+ private IPropertyChangeListener markerPreferenceListener;\r
\r
/**\r
* \r
\r
setLineDisplayStrategy(new BulkEditorLineDisplay(this));\r
\r
- setSourceViewerConfiguration(new BulkEditorViewerConfiguration());\r
+ setSourceViewerConfiguration(new BulkEditorViewerConfiguration(lineDisplayStrategy));\r
}\r
\r
/* (non-Javadoc)\r
private void createMarkerEditing(Composite parent) {\r
final BulkEditorMarkerPreferenceComposite markerPreferenceBar = \r
new BulkEditorMarkerPreferenceComposite((BulkEditorInput) getEditorInput(), parent, SWT.NONE);\r
- PreferencesUtil.getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {\r
+ markerPreferenceListener = new IPropertyChangeListener() {\r
public void propertyChange(\r
org.eclipse.jface.util.PropertyChangeEvent event) {\r
if (event.getProperty().contains(PreferencesUtil.EDIT_MARKER_TYPE_PREFIX)) {\r
refreshLineDisplay();\r
}\r
}\r
- });\r
+ };\r
+ PreferencesUtil.getPreferenceStore().addPropertyChangeListener(markerPreferenceListener);\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.ui.editors.text.TextEditor#dispose()\r
+ */\r
+ @Override\r
+ public void dispose() {\r
+ if (markerPreferenceListener != null ) {\r
+ PreferencesUtil.getPreferenceStore().removePropertyChangeListener(markerPreferenceListener);\r
+ }\r
+ super.dispose();\r
}\r
\r
/**\r
\r
import org.apache.log4j.Logger;\r
import org.eclipse.jface.text.IDocument;\r
-import org.eclipse.jface.text.ITypedRegion;\r
-import org.eclipse.jface.text.TextPresentation;\r
import org.eclipse.jface.text.presentation.IPresentationReconciler;\r
import org.eclipse.jface.text.presentation.PresentationReconciler;\r
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;\r
-import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;\r
import org.eclipse.jface.text.source.ISourceViewer;\r
import org.eclipse.jface.text.source.SourceViewerConfiguration;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.StyleRange;\r
\r
+import eu.etaxonomy.taxeditor.annotatedlineeditor.SupplementalTextScanner;\r
import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;\r
\r
\r
public class BulkEditorViewerConfiguration extends SourceViewerConfiguration {\r
private static final Logger logger = Logger\r
.getLogger(BulkEditorViewerConfiguration.class);\r
+ \r
+ private ILineDisplayStrategy lineDisplayStrategy;\r
\r
+ public BulkEditorViewerConfiguration(ILineDisplayStrategy lineDisplayStrategy) {\r
+ this.lineDisplayStrategy = lineDisplayStrategy;\r
+ }\r
+ \r
+ \r
/* (non-Javadoc)\r
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)\r
*/\r
\r
PresentationReconciler reconciler = new PresentationReconciler();\r
\r
- DefaultDamagerRepairer damageRepairer = new DefaultDamagerRepairer(new RuleBasedPartitionScanner()) {\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.text.rules.DefaultDamagerRepairer#createPresentation(org.eclipse.jface.text.TextPresentation, org.eclipse.jface.text.ITypedRegion)\r
- */\r
- @Override\r
- public void createPresentation(TextPresentation presentation,\r
- ITypedRegion region) {\r
- presentation.addStyleRange(new StyleRange(region.getOffset(), region.getLength(),\r
- sourceViewer.getTextWidget().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY), null, SWT.ITALIC));\r
- }\r
- };\r
- reconciler.setDamager(damageRepairer, ILineDisplayStrategy.SUPPLEMENTAL_TEXT);\r
- reconciler.setRepairer(damageRepairer, ILineDisplayStrategy.SUPPLEMENTAL_TEXT);\r
+ DefaultDamagerRepairer damageRepairer = new DefaultDamagerRepairer(new SupplementalTextScanner(sourceViewer, lineDisplayStrategy));\r
+ reconciler.setDamager(damageRepairer, IDocument.DEFAULT_CONTENT_TYPE);\r
+ reconciler.setRepairer(damageRepairer, IDocument.DEFAULT_CONTENT_TYPE);\r
\r
return reconciler;\r
}\r