-/**\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.editor.name;\r
-\r
-import java.util.Iterator;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.eclipse.core.commands.operations.IUndoContext;\r
-import org.eclipse.core.runtime.Assert;\r
-import org.eclipse.jface.text.Document;\r
-import org.eclipse.jface.text.IUndoManager;\r
-import org.eclipse.jface.text.IUndoManagerExtension;\r
-import org.eclipse.jface.text.Position;\r
-import org.eclipse.jface.text.TextViewerUndoManager;\r
-import org.eclipse.jface.text.source.Annotation;\r
-import org.eclipse.jface.text.source.AnnotationModel;\r
-import org.eclipse.jface.text.source.AnnotationPainter;\r
-import org.eclipse.jface.text.source.IAnnotationAccess;\r
-import org.eclipse.jface.text.source.IVerticalRuler;\r
-import org.eclipse.jface.text.source.SourceViewer;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.widgets.Canvas;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Layout;\r
-import org.eclipse.swt.widgets.Menu;\r
-import org.eclipse.ui.IActionBars;\r
-import org.eclipse.ui.IEditorSite;\r
-import org.eclipse.ui.actions.ActionFactory;\r
-import org.eclipse.ui.forms.widgets.TableWrapData;\r
-import org.eclipse.ui.forms.widgets.TableWrapLayout;\r
-import org.eclipse.ui.operations.OperationHistoryActionHandler;\r
-import org.eclipse.ui.operations.RedoActionHandler;\r
-import org.eclipse.ui.operations.UndoActionHandler;\r
-import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;\r
-import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;\r
-\r
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.cdm.strategy.parser.ParserProblem;\r
-import eu.etaxonomy.taxeditor.editor.EditorUtil;\r
-import eu.etaxonomy.taxeditor.editor.ViewerConfiguration;\r
-import eu.etaxonomy.taxeditor.preference.Resources;\r
-\r
-/**\r
- * SourceViewer implementation called by NameComposite.\r
- * \r
- * @author p.ciardelli\r
- * @created 27.05.2008\r
- * @version 1.0\r
- */\r
-public class NameViewer extends SourceViewer {\r
- private static final Logger logger = Logger\r
- .getLogger(NameViewer.class);\r
- \r
- public static final int RULER_WIDTH = 16;\r
- \r
- private IVerticalRuler ruler;\r
- private AnnotationModel annotationModel;\r
-\r
- public NameViewer(Composite parent) {\r
- super(parent, new RulerWithIcon(RULER_WIDTH), SWT.WRAP | SWT.MULTI | SWT.RESIZE);\r
- \r
- this.ruler = getVerticalRuler();\r
- \r
- setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));\r
- \r
- Canvas canvas = (Canvas) getControl();\r
- TableWrapLayout layout = (TableWrapLayout) canvas.getLayout();\r
- layout.topMargin = 0;\r
- layout.rightMargin = 0;\r
- layout.bottomMargin = 0;\r
- layout.leftMargin = 0;\r
- layout.verticalSpacing = 10;\r
- layout.horizontalSpacing = 0;\r
- \r
- canvas.setLayout(layout);\r
- \r
- // Lay out the viewer's widgets\r
- TableWrapData twdata = new TableWrapData(TableWrapData.FILL_GRAB);\r
- getControl().setLayoutData(twdata);\r
- \r
- twdata = new TableWrapData(TableWrapData.FILL_GRAB);\r
- getTextWidget().setLayoutData(twdata);\r
- getTextWidget().setLineSpacing(5);\r
- \r
- // Default implementation adds ruler after the text widget, then \r
- // uses a custom layout to display it before the text widget\r
- ruler.getControl().moveAbove(getTextWidget());\r
-\r
- annotationModel = new AnnotationModel();\r
- this.setDocument(new Document(""), annotationModel);\r
- \r
- createAnnotationPainter();\r
-\r
- this.configure(new ViewerConfiguration()); \r
- \r
-// setDecorationSupport();\r
-// DocumentUndoManagerRegistry.connect(this.getDocument());\r
-// IDocumentUndoManager docUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(this.getDocument());\r
- \r
- /**\r
- getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.UNDO.getId(), new UndoActionHandler(getSite(), undoContext));\r
- getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext)); \r
- **/\r
- }\r
- \r
- public void setBackground(Color color) {\r
- \r
- // Set background color of ruler\r
- ruler.getControl().setBackground(color);\r
-\r
- // Set background color of text widget\r
- getTextWidget().setBackground(color);\r
- \r
- // Set background color of strip between ruler and textWidget\r
- getTextWidget().getParent().setBackground(color); \r
- }\r
- \r
- public Control getRulerControl() {\r
- return ruler.getControl();\r
- }\r
-\r
- public void setIcon(Image icon) {\r
- if (ruler instanceof RulerWithIcon) {\r
- ((RulerWithIcon) ruler).setIcon(icon);\r
- } else {\r
- logger.warn("Viewer's IVerticalRuler is not an instance of RulerWithIcon.");\r
- }\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.text.source.SourceViewer#createLayout()\r
- */\r
- protected Layout createLayout() {\r
- TableWrapLayout layout = new TableWrapLayout();\r
- layout.numColumns = 2;\r
- layout.verticalSpacing = 0;\r
- return layout;\r
- }\r
- \r
- private void createAnnotationPainter(){\r
- // Annotations section\r
- IAnnotationAccess fAnnotationAccess = new DefaultMarkerAnnotationAccess();\r
- \r
- // To paint the annotations\r
- AnnotationPainter annotationPainter = new AnnotationPainter(this, fAnnotationAccess);\r
-\r
- // Default SquigglesStrategy doesn't recognize line wraps\r
- annotationPainter.addDrawingStrategy(LineWrapSquigglesStrategy.ID, new LineWrapSquigglesStrategy());\r
- \r
- // Add ability to paint red squigglies\r
- annotationPainter.addAnnotationType(EditorAnnotation.ERROR_TYPE, LineWrapSquigglesStrategy.ID);\r
- annotationPainter.setAnnotationTypeColor(EditorAnnotation.ERROR_TYPE, \r
- new Color(Display.getDefault(), EditorAnnotation.ERROR_RGB));\r
-\r
- // Add ability to paint yellow squigglies\r
- annotationPainter.addAnnotationType(EditorAnnotation.WARNING_TYPE, LineWrapSquigglesStrategy.ID);\r
- annotationPainter.setAnnotationTypeColor(EditorAnnotation.WARNING_TYPE, \r
- new Color(Display.getDefault(), EditorAnnotation.WARNING_RGB));\r
- \r
- this.addPainter(annotationPainter);\r
- }\r
-\r
-\r
- public void clearErrors() {\r
- Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();\r
- while (annotations.hasNext()) {\r
- Annotation annotation = annotations.next(); \r
- if (annotation.getType().equals(EditorAnnotation.ERROR_TYPE) || annotation.getType().equals(EditorAnnotation.WARNING_TYPE)) {\r
- this.getAnnotationModel().removeAnnotation(annotation);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * If <code>name.hasProblem()</code> is <code>true</code>, underlines section\r
- * of text bounded by <code>name.getProblemStarts()</code> and \r
- * <code>name.getProblemEnds()</code>.\r
- * \r
- * @param name\r
- */\r
- public void setShowParsingErrors(TaxonNameBase<?, ?> name) {\r
- \r
- String text = this.getTextWidget().getText();\r
- \r
- if (name.hasProblem() && text.length() > 0) {\r
- int start = name.getProblemStarts();\r
- int length = name.getProblemEnds() - start;\r
- \r
- if (start == -1 || name.getProblemEnds() == -1) {\r
- return;\r
- }\r
- \r
- // Don't let squigglies try to draw beyond the end of the text\r
- if (text.length() < start + length) {\r
- length = text.length() - start;\r
- }\r
- \r
- for (ParserProblem problem : name.getParsingProblems()) {\r
- \r
- String type = null;\r
- if (problem.isWarning()) {\r
- type = EditorAnnotation.WARNING_TYPE;\r
- }\r
- if (problem.isError()) {\r
- type = EditorAnnotation.ERROR_TYPE;\r
- }\r
- if (type == null) {\r
- continue;\r
- }\r
- this.getAnnotationModel().addAnnotation(\r
- new EditorAnnotation(type, 0, problem.getMessage()), \r
- new Position(start, length));\r
- }\r
- }\r
- }\r
- \r
- \r
- public void setShowSecError(Taxon taxon) {\r
- \r
- // If taxon has no sec, show an annotation\r
- if (taxon.getSec() == null) {\r
- \r
- String text = "This taxon requires a sec. reference.";\r
- \r
- this.getAnnotationModel().addAnnotation(\r
- new EditorAnnotation(0, text),\r
- new Position(0, 0));\r
- }\r
- }\r
-\r
- \r
- public void setText(String text) {\r
- if (text == null) {\r
- text = "";\r
- }\r
- try {\r
- Assert.isNotNull(text);\r
- // TODO figure out why getTextWidget() returns null!\r
- if (this.getTextWidget() == null) {\r
- return;\r
- }\r
- Assert.isNotNull(this.getTextWidget());\r
- this.getTextWidget().setText(text);\r
- } catch (RuntimeException e) {\r
- logger.error("Could not set the text for a name viewer");\r
- throw e;\r
- }\r
- }\r
- \r
- public void setMenu(Menu menu) {\r
- getRulerControl().setMenu(menu);\r
- getTextWidget().setMenu(menu);\r
- }\r
-\r
- public void setCursorToEOL() {\r
- getTextWidget().setCaretOffset(getTextWidget().getText().length());\r
- getTextWidget().setFocus();\r
- }\r
-\r
- \r
- public int getCursorPosition(){\r
- return getTextWidget().getCaretOffset();\r
- }\r
- \r
- public void setCursorPosition(int offset){\r
- try{\r
- getTextWidget().setCaretOffset(offset);\r
- }catch(IllegalArgumentException e){\r
- // do nothing\r
- }\r
- }\r
-\r
- public void createUndoSupport(IEditorSite editorSite) {\r
-\r
- IUndoManager undoManager = new TextViewerUndoManager(25);\r
- this.setUndoManager(undoManager);\r
- undoManager.connect(this);\r
- \r
-// IUndoContext workbenchUndoContext = UiUtil.getWorkbenchUndoContext();\r
- \r
- IUndoContext workbenchUndoContext = ((IUndoManagerExtension)undoManager).getUndoContext();\r
- \r
- OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, workbenchUndoContext);\r
-// undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);\r
- undoAction.setActionDefinitionId(ActionFactory.UNDO.getId());\r
- \r
- // Create the redo action.\r
- OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, workbenchUndoContext);\r
-// redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);\r
- undoAction.setActionDefinitionId(ActionFactory.REDO.getId());\r
-\r
- IActionBars actionBars = editorSite.getActionBars();\r
- if (actionBars != null) {\r
-// actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.UNDO, undoAction);\r
-// actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);\r
- actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);\r
- actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);\r
- \r
- } \r
- \r
-// actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);\r
-// actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);\r
- }\r
- \r
- public void createUndoSupport_(IEditorSite editorSite) {\r
- IUndoManager undoManager = new TextViewerUndoManager(25);\r
- this.setUndoManager(undoManager);\r
- undoManager.connect(this);\r
- IUndoContext undoContext;\r
- if (undoManager instanceof IUndoManagerExtension) {\r
- undoContext = ((IUndoManagerExtension)undoManager).getUndoContext();\r
- \r
- OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, undoContext);\r
-// PlatformUI.getWorkbench().getHelpSystem().setHelp(undoAction, IAbstractTextEditorHelpContextIds.UNDO_ACTION);\r
- undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);\r
- \r
- // Create the redo action.\r
- OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, undoContext);\r
-// PlatformUI.getWorkbench().getHelpSystem().setHelp(redoAction, IAbstractTextEditorHelpContextIds.REDO_ACTION);\r
- redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);\r
-\r
-\r
- IActionBars actionBars = editorSite.getActionBars();\r
- if (actionBars != null) {\r
- actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.UNDO, undoAction);\r
- actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);\r
- \r
- }\r
- }\r
- }\r
-}\r
-\r
+/**
+ * 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.editor.name;
+
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IUndoManager;
+import org.eclipse.jface.text.IUndoManagerExtension;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TextViewerUndoManager;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationModel;
+import org.eclipse.jface.text.source.AnnotationPainter;
+import org.eclipse.jface.text.source.IAnnotationAccess;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+import org.eclipse.ui.operations.OperationHistoryActionHandler;
+import org.eclipse.ui.operations.RedoActionHandler;
+import org.eclipse.ui.operations.UndoActionHandler;
+import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.ViewerConfiguration;
+import eu.etaxonomy.taxeditor.preference.Resources;
+
+/**
+ * SourceViewer implementation called by NameComposite.
+ *
+ * @author p.ciardelli
+ * @created 27.05.2008
+ * @version 1.0
+ */
+public class NameViewer extends SourceViewer {
+ private static final Logger logger = Logger
+ .getLogger(NameViewer.class);
+
+ /** Constant <code>RULER_WIDTH=16</code> */
+ public static final int RULER_WIDTH = 16;
+
+ private IVerticalRuler ruler;
+ private AnnotationModel annotationModel;
+
+ /**
+ * <p>Constructor for NameViewer.</p>
+ *
+ * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
+ */
+ public NameViewer(Composite parent) {
+ super(parent, new RulerWithIcon(RULER_WIDTH), SWT.WRAP | SWT.MULTI | SWT.RESIZE);
+
+ this.ruler = getVerticalRuler();
+
+ setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
+
+ Canvas canvas = (Canvas) getControl();
+ TableWrapLayout layout = (TableWrapLayout) canvas.getLayout();
+ layout.topMargin = 0;
+ layout.rightMargin = 0;
+ layout.bottomMargin = 0;
+ layout.leftMargin = 0;
+ layout.verticalSpacing = 10;
+ layout.horizontalSpacing = 0;
+
+ canvas.setLayout(layout);
+
+ // Lay out the viewer's widgets
+ TableWrapData twdata = new TableWrapData(TableWrapData.FILL_GRAB);
+ getControl().setLayoutData(twdata);
+
+ twdata = new TableWrapData(TableWrapData.FILL_GRAB);
+ getTextWidget().setLayoutData(twdata);
+ getTextWidget().setLineSpacing(5);
+
+ // Default implementation adds ruler after the text widget, then
+ // uses a custom layout to display it before the text widget
+ ruler.getControl().moveAbove(getTextWidget());
+
+ annotationModel = new AnnotationModel();
+ this.setDocument(new Document(""), annotationModel);
+
+ createAnnotationPainter();
+
+ this.configure(new ViewerConfiguration());
+
+// setDecorationSupport();
+// DocumentUndoManagerRegistry.connect(this.getDocument());
+// IDocumentUndoManager docUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(this.getDocument());
+
+ /**
+ getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.UNDO.getId(), new UndoActionHandler(getSite(), undoContext));
+ getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext));
+ **/
+ }
+
+ /**
+ * <p>setBackground</p>
+ *
+ * @param color a {@link org.eclipse.swt.graphics.Color} object.
+ */
+ public void setBackground(Color color) {
+
+ // Set background color of ruler
+ ruler.getControl().setBackground(color);
+
+ // Set background color of text widget
+ getTextWidget().setBackground(color);
+
+ // Set background color of strip between ruler and textWidget
+ getTextWidget().getParent().setBackground(color);
+ }
+
+ /**
+ * <p>getRulerControl</p>
+ *
+ * @return a {@link org.eclipse.swt.widgets.Control} object.
+ */
+ public Control getRulerControl() {
+ return ruler.getControl();
+ }
+
+ /**
+ * <p>setIcon</p>
+ *
+ * @param icon a {@link org.eclipse.swt.graphics.Image} object.
+ */
+ public void setIcon(Image icon) {
+ if (ruler instanceof RulerWithIcon) {
+ ((RulerWithIcon) ruler).setIcon(icon);
+ } else {
+ logger.warn("Viewer's IVerticalRuler is not an instance of RulerWithIcon.");
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.source.SourceViewer#createLayout()
+ */
+ /**
+ * <p>createLayout</p>
+ *
+ * @return a {@link org.eclipse.swt.widgets.Layout} object.
+ */
+ protected Layout createLayout() {
+ TableWrapLayout layout = new TableWrapLayout();
+ layout.numColumns = 2;
+ layout.verticalSpacing = 0;
+ return layout;
+ }
+
+ private void createAnnotationPainter(){
+ // Annotations section
+ IAnnotationAccess fAnnotationAccess = new DefaultMarkerAnnotationAccess();
+
+ // To paint the annotations
+ AnnotationPainter annotationPainter = new AnnotationPainter(this, fAnnotationAccess);
+
+ // Default SquigglesStrategy doesn't recognize line wraps
+ annotationPainter.addDrawingStrategy(LineWrapSquigglesStrategy.ID, new LineWrapSquigglesStrategy());
+
+ // Add ability to paint red squigglies
+ annotationPainter.addAnnotationType(EditorAnnotation.ERROR_TYPE, LineWrapSquigglesStrategy.ID);
+ annotationPainter.setAnnotationTypeColor(EditorAnnotation.ERROR_TYPE,
+ new Color(Display.getDefault(), EditorAnnotation.ERROR_RGB));
+
+ // Add ability to paint yellow squigglies
+ annotationPainter.addAnnotationType(EditorAnnotation.WARNING_TYPE, LineWrapSquigglesStrategy.ID);
+ annotationPainter.setAnnotationTypeColor(EditorAnnotation.WARNING_TYPE,
+ new Color(Display.getDefault(), EditorAnnotation.WARNING_RGB));
+
+ this.addPainter(annotationPainter);
+ }
+
+
+ /**
+ * <p>clearErrors</p>
+ */
+ public void clearErrors() {
+ Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();
+ while (annotations.hasNext()) {
+ Annotation annotation = annotations.next();
+ if (annotation.getType().equals(EditorAnnotation.ERROR_TYPE) || annotation.getType().equals(EditorAnnotation.WARNING_TYPE)) {
+ this.getAnnotationModel().removeAnnotation(annotation);
+ }
+ }
+ }
+
+ /**
+ * If <code>name.hasProblem()</code> is <code>true</code>, underlines section
+ * of text bounded by <code>name.getProblemStarts()</code> and
+ * <code>name.getProblemEnds()</code>.
+ *
+ * @param name a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
+ */
+ public void setShowParsingErrors(TaxonNameBase<?, ?> name) {
+
+ String text = this.getTextWidget().getText();
+
+ if (name.hasProblem() && text.length() > 0) {
+ int start = name.getProblemStarts();
+ int length = name.getProblemEnds() - start;
+
+ if (start == -1 || name.getProblemEnds() == -1) {
+ return;
+ }
+
+ // Don't let squigglies try to draw beyond the end of the text
+ if (text.length() < start + length) {
+ length = text.length() - start;
+ }
+
+ for (ParserProblem problem : name.getParsingProblems()) {
+
+ String type = null;
+ if (problem.isWarning()) {
+ type = EditorAnnotation.WARNING_TYPE;
+ }
+ if (problem.isError()) {
+ type = EditorAnnotation.ERROR_TYPE;
+ }
+ if (type == null) {
+ continue;
+ }
+ this.getAnnotationModel().addAnnotation(
+ new EditorAnnotation(type, 0, problem.getMessage()),
+ new Position(start, length));
+ }
+ }
+ }
+
+
+ /**
+ * <p>setShowSecError</p>
+ *
+ * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
+ */
+ public void setShowSecError(Taxon taxon) {
+
+ // If taxon has no sec, show an annotation
+ if (taxon.getSec() == null) {
+
+ String text = "This taxon requires a sec. reference.";
+
+ this.getAnnotationModel().addAnnotation(
+ new EditorAnnotation(0, text),
+ new Position(0, 0));
+ }
+ }
+
+
+ /**
+ * <p>setText</p>
+ *
+ * @param text a {@link java.lang.String} object.
+ */
+ public void setText(String text) {
+ if (text == null) {
+ text = "";
+ }
+ try {
+ Assert.isNotNull(text);
+ // TODO figure out why getTextWidget() returns null!
+ if (this.getTextWidget() == null) {
+ return;
+ }
+ Assert.isNotNull(this.getTextWidget());
+ this.getTextWidget().setText(text);
+ } catch (RuntimeException e) {
+ logger.error("Could not set the text for a name viewer");
+ throw e;
+ }
+ }
+
+ /**
+ * <p>setMenu</p>
+ *
+ * @param menu a {@link org.eclipse.swt.widgets.Menu} object.
+ */
+ public void setMenu(Menu menu) {
+ getRulerControl().setMenu(menu);
+ getTextWidget().setMenu(menu);
+ }
+
+ /**
+ * <p>setCursorToEOL</p>
+ */
+ public void setCursorToEOL() {
+ getTextWidget().setCaretOffset(getTextWidget().getText().length());
+ getTextWidget().setFocus();
+ }
+
+
+ /**
+ * <p>getCursorPosition</p>
+ *
+ * @return a int.
+ */
+ public int getCursorPosition(){
+ return getTextWidget().getCaretOffset();
+ }
+
+ /**
+ * <p>setCursorPosition</p>
+ *
+ * @param offset a int.
+ */
+ public void setCursorPosition(int offset){
+ try{
+ getTextWidget().setCaretOffset(offset);
+ }catch(IllegalArgumentException e){
+ // do nothing
+ }
+ }
+
+ /**
+ * <p>createUndoSupport</p>
+ *
+ * @param editorSite a {@link org.eclipse.ui.IEditorSite} object.
+ */
+ public void createUndoSupport(IEditorSite editorSite) {
+
+ IUndoManager undoManager = new TextViewerUndoManager(25);
+ this.setUndoManager(undoManager);
+ undoManager.connect(this);
+
+// IUndoContext workbenchUndoContext = UiUtil.getWorkbenchUndoContext();
+
+ IUndoContext workbenchUndoContext = ((IUndoManagerExtension)undoManager).getUndoContext();
+
+ OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, workbenchUndoContext);
+// undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
+ undoAction.setActionDefinitionId(ActionFactory.UNDO.getId());
+
+ // Create the redo action.
+ OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, workbenchUndoContext);
+// redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);
+ undoAction.setActionDefinitionId(ActionFactory.REDO.getId());
+
+ IActionBars actionBars = editorSite.getActionBars();
+ if (actionBars != null) {
+// actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.UNDO, undoAction);
+// actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);
+ actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
+ actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
+
+ }
+
+// actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
+// actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
+ }
+
+ /**
+ * <p>createUndoSupport_</p>
+ *
+ * @param editorSite a {@link org.eclipse.ui.IEditorSite} object.
+ */
+ public void createUndoSupport_(IEditorSite editorSite) {
+ IUndoManager undoManager = new TextViewerUndoManager(25);
+ this.setUndoManager(undoManager);
+ undoManager.connect(this);
+ IUndoContext undoContext;
+ if (undoManager instanceof IUndoManagerExtension) {
+ undoContext = ((IUndoManagerExtension)undoManager).getUndoContext();
+
+ OperationHistoryActionHandler undoAction = new UndoActionHandler(editorSite, undoContext);
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(undoAction, IAbstractTextEditorHelpContextIds.UNDO_ACTION);
+ undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
+
+ // Create the redo action.
+ OperationHistoryActionHandler redoAction = new RedoActionHandler(editorSite, undoContext);
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(redoAction, IAbstractTextEditorHelpContextIds.REDO_ACTION);
+ redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);
+
+
+ IActionBars actionBars = editorSite.getActionBars();
+ if (actionBars != null) {
+ actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.UNDO, undoAction);
+ actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);
+
+ }
+ }
+ }
+}
+