/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * 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.
*/
* @version 1.0
*/
public class NameViewer extends SourceViewer {
-
+
/** Constant <code>RULER_WIDTH=16</code> */
public static final int RULER_WIDTH = 16;
-
+
private final IVerticalRuler ruler;
private final AnnotationModel annotationModel;
*/
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.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
+
+ // 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); //$NON-NLS-1$
-
+
createAnnotationPainter();
- this.configure(new ViewerConfiguration());
-
+ 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));
+ 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);
+ getTextWidget().getParent().setBackground(color);
}
-
+
/**
* <p>getRulerControl</p>
*
throw new IllegalStateException("Viewer's IVerticalRuler is not an instance of RulerWithIcon."); //$NON-NLS-1$
}
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.text.source.SourceViewer#createLayout()
*/
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(EditorAnnotationType.ERROR.name(), LineWrapSquigglesStrategy.ID);
- annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image,
+ annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image,
new Color(Display.getDefault(), EditorAnnotationType.ERROR.color));
// Add ability to paint yellow squigglies
annotationPainter.addAnnotationType(EditorAnnotationType.WARNING.name(), LineWrapSquigglesStrategy.ID);
- annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image,
+ annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image,
new Color(Display.getDefault(), EditorAnnotationType.WARNING.color));
-
+
this.addPainter(annotationPainter);
}
public void clearAnnotations() {
Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();
while (annotations.hasNext()) {
- Annotation annotation = annotations.next();
+ Annotation annotation = annotations.next();
this.getAnnotationModel().removeAnnotation(annotation);
}
}
-
+
/**
* If <code>name.hasProblem()</code> is <code>true</code>, underlines section
* of text bounded by <code>name.getProblemStarts()</code> and
* @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;
// continue;
// }
// this.getAnnotationModel().addAnnotation(
-// new EditorAnnotation(type, 0, problem.getMessage()),
+// new EditorAnnotation(type, 0, problem.getMessage()),
// new Position(start, length));
// }
-//
+//
// }
// }
-
+
public void addAnnotation(EditorAnnotation annotation){
addAnnotation(annotation, null);
}
-
+
public void addAnnotation(EditorAnnotation annotation, Position position){
if(position == null){
position = new Position(0, 0);
}
-
+
this.getAnnotationModel().addAnnotation(annotation, position);
}
-
+
/**
* <p>setText</p>
*
throw e;
}
}
-
+
/**
* <p>setMenu</p>
*
*/
public void setCursorToEOL() {
getTextWidget().setCaretOffset(getTextWidget().getText().length());
- getTextWidget().setFocus();
}
-
+
/**
* <p>getCursorPosition</p>
*
public int getCursorPosition(){
return getTextWidget().getCaretOffset();
}
-
+
/**
* <p>setCursorPosition</p>
*
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);
// 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>
*
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);
if (actionBars != null) {
actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.UNDO, undoAction);
actionBars.setGlobalActionHandler(IWorkbenchActionDefinitionIds.REDO, redoAction);
-
+
}
}
}