Removed
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2004, 2008 Tasktop Technologies and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* Tasktop Technologies - initial API and implementation |
10 |
* Eugene Kuleshov - spelling correction |
11 |
*******************************************************************************/ |
12 |
|
13 |
package org.eclipse.mylyn.internal.tasks.ui.editors; |
14 |
|
15 |
import java.util.ArrayList; |
16 |
import java.util.Iterator; |
17 |
import java.util.List; |
18 |
|
19 |
import org.eclipse.core.commands.IHandler; |
20 |
import org.eclipse.core.resources.IMarker; |
21 |
import org.eclipse.jface.action.Action; |
22 |
import org.eclipse.jface.action.MenuManager; |
23 |
import org.eclipse.jface.commands.ActionHandler; |
24 |
import org.eclipse.jface.text.DefaultInformationControl; |
25 |
import org.eclipse.jface.text.Document; |
26 |
import org.eclipse.jface.text.IInformationControl; |
27 |
import org.eclipse.jface.text.IInformationControlCreator; |
28 |
import org.eclipse.jface.text.IRegion; |
29 |
import org.eclipse.jface.text.ITextHover; |
30 |
import org.eclipse.jface.text.ITextListener; |
31 |
import org.eclipse.jface.text.ITextOperationTarget; |
32 |
import org.eclipse.jface.text.ITextViewer; |
33 |
import org.eclipse.jface.text.Position; |
34 |
import org.eclipse.jface.text.TextEvent; |
35 |
import org.eclipse.jface.text.TextViewer; |
36 |
import org.eclipse.jface.text.source.Annotation; |
37 |
import org.eclipse.jface.text.source.AnnotationModel; |
38 |
import org.eclipse.jface.text.source.IAnnotationAccess; |
39 |
import org.eclipse.jface.text.source.IAnnotationAccessExtension; |
40 |
import org.eclipse.jface.text.source.IAnnotationHover; |
41 |
import org.eclipse.jface.text.source.ISharedTextColors; |
42 |
import org.eclipse.jface.text.source.ISourceViewer; |
43 |
import org.eclipse.jface.text.source.ImageUtilities; |
44 |
import org.eclipse.jface.text.source.SourceViewer; |
45 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonColors; |
46 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes; |
47 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
48 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; |
49 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
50 |
import org.eclipse.swt.SWT; |
51 |
import org.eclipse.swt.custom.StyledText; |
52 |
import org.eclipse.swt.events.DisposeEvent; |
53 |
import org.eclipse.swt.events.DisposeListener; |
54 |
import org.eclipse.swt.events.FocusEvent; |
55 |
import org.eclipse.swt.events.FocusListener; |
56 |
import org.eclipse.swt.graphics.Color; |
57 |
import org.eclipse.swt.graphics.GC; |
58 |
import org.eclipse.swt.graphics.Image; |
59 |
import org.eclipse.swt.graphics.RGB; |
60 |
import org.eclipse.swt.graphics.Rectangle; |
61 |
import org.eclipse.swt.widgets.Canvas; |
62 |
import org.eclipse.swt.widgets.Composite; |
63 |
import org.eclipse.swt.widgets.Control; |
64 |
import org.eclipse.swt.widgets.Display; |
65 |
import org.eclipse.swt.widgets.Shell; |
66 |
import org.eclipse.swt.widgets.Text; |
67 |
import org.eclipse.ui.ActiveShellExpression; |
68 |
import org.eclipse.ui.PlatformUI; |
69 |
import org.eclipse.ui.actions.ActionFactory; |
70 |
import org.eclipse.ui.editors.text.EditorsUI; |
71 |
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; |
72 |
import org.eclipse.ui.forms.IManagedForm; |
73 |
import org.eclipse.ui.forms.editor.FormEditor; |
74 |
import org.eclipse.ui.forms.editor.FormPage; |
75 |
import org.eclipse.ui.handlers.IHandlerActivation; |
76 |
import org.eclipse.ui.handlers.IHandlerService; |
77 |
import org.eclipse.ui.texteditor.AnnotationPreference; |
78 |
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; |
79 |
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
80 |
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; |
81 |
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; |
82 |
import org.eclipse.ui.themes.IThemeManager; |
83 |
|
84 |
/** |
85 |
* Used by the task editor. Not recommended to extend. |
86 |
* |
87 |
* @author Rob Elves |
88 |
* |
89 |
* ref: PDEFormPage.class ref: ref: http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg19676.html |
90 |
* @deprecated use {@link AbstractTaskEditorPage} instead |
91 |
*/ |
92 |
@Deprecated |
93 |
public class TaskFormPage extends FormPage { |
94 |
|
95 |
protected boolean isDirty; |
96 |
|
97 |
private TaskEditor taskEditor = null; |
98 |
|
99 |
private TaskEditorActionContributor actionContributor; |
100 |
|
101 |
protected List<TextViewer> textViewers = new ArrayList<TextViewer>(); |
102 |
|
103 |
private IHandlerActivation handlerActivation; |
104 |
|
105 |
private IHandlerActivation handlerCompletion; |
106 |
|
107 |
private void addTextViewer(TextViewer viewer) { |
108 |
textViewers.add(viewer); |
109 |
} |
110 |
|
111 |
public TaskFormPage(FormEditor editor, String id, String title) { |
112 |
super(editor, id, title); |
113 |
taskEditor = (TaskEditor) editor; |
114 |
} |
115 |
|
116 |
public boolean canPerformAction(String actionId) { |
117 |
Control focusControl = getFocusControl(); |
118 |
if (focusControl instanceof StyledText) { |
119 |
StyledText text = (StyledText) focusControl; |
120 |
for (TextViewer viewer : textViewers) { |
121 |
if (viewer.getTextWidget() == text) { |
122 |
return canDoGlobalAction(actionId, viewer); |
123 |
} |
124 |
} |
125 |
} else { |
126 |
if (actionId.equals(ActionFactory.UNDO.getId()) || actionId.equals(ActionFactory.REDO.getId())) { |
127 |
return false; |
128 |
} else { |
129 |
return true; |
130 |
} |
131 |
} |
132 |
// else if (focusControl instanceof Text) { |
133 |
// |
134 |
// Text textControl = (Text) focusControl; |
135 |
// if (actionId.equals(ActionFactory.CUT.getId())) { |
136 |
// return textControl.getSelectionText().length() > 0; |
137 |
// } |
138 |
// if (actionId.equals(ActionFactory.COPY.getId())) { |
139 |
// return textControl.getSelectionText().length() > 0; |
140 |
// } |
141 |
// if (actionId.equals(ActionFactory.PASTE.getId())) { |
142 |
// return true; |
143 |
// } |
144 |
// if (actionId.equals(ActionFactory.SELECT_ALL.getId())) { |
145 |
// return textControl.getText().length() > 0; |
146 |
// } |
147 |
// if (actionId.equals(ActionFactory.DELETE.getId())) { |
148 |
// return textControl.getSelectionText().length() > 0; |
149 |
// } |
150 |
// } |
151 |
return false; |
152 |
} |
153 |
|
154 |
public void doAction(String actionId) { |
155 |
Control focusControl = getFocusControl(); |
156 |
if (focusControl == null) { |
157 |
return; |
158 |
} |
159 |
if (canPerformDirectly(actionId, focusControl)) { |
160 |
return; |
161 |
} |
162 |
if (focusControl instanceof StyledText) { |
163 |
StyledText text = (StyledText) focusControl; |
164 |
for (TextViewer viewer : textViewers) { |
165 |
if (viewer.getTextWidget() == text) { |
166 |
doGlobalAction(actionId, viewer); |
167 |
return; |
168 |
} |
169 |
} |
170 |
} |
171 |
} |
172 |
|
173 |
protected boolean canPerformDirectly(String id, Control control) { |
174 |
if (control instanceof Text) { |
175 |
Text text = (Text) control; |
176 |
if (id.equals(ActionFactory.CUT.getId())) { |
177 |
text.cut(); |
178 |
return true; |
179 |
} |
180 |
if (id.equals(ActionFactory.COPY.getId())) { |
181 |
text.copy(); |
182 |
return true; |
183 |
} |
184 |
if (id.equals(ActionFactory.PASTE.getId())) { |
185 |
text.paste(); |
186 |
return true; |
187 |
} |
188 |
if (id.equals(ActionFactory.SELECT_ALL.getId())) { |
189 |
text.selectAll(); |
190 |
return true; |
191 |
} |
192 |
if (id.equals(ActionFactory.DELETE.getId())) { |
193 |
int count = text.getSelectionCount(); |
194 |
if (count == 0) { |
195 |
int caretPos = text.getCaretPosition(); |
196 |
text.setSelection(caretPos, caretPos + 1); |
197 |
} |
198 |
text.insert(""); //$NON-NLS-1$ |
199 |
return true; |
200 |
} |
201 |
} |
202 |
return false; |
203 |
} |
204 |
|
205 |
protected Control getFocusControl() { |
206 |
IManagedForm form = getManagedForm(); |
207 |
if (form == null) { |
208 |
return null; |
209 |
} |
210 |
Control control = form.getForm(); |
211 |
if (control == null || control.isDisposed()) { |
212 |
return null; |
213 |
} |
214 |
Display display = control.getDisplay(); |
215 |
Control focusControl = display.getFocusControl(); |
216 |
if (focusControl == null || focusControl.isDisposed()) { |
217 |
return null; |
218 |
} |
219 |
return focusControl; |
220 |
} |
221 |
|
222 |
private boolean doGlobalAction(String actionId, TextViewer textViewer) { |
223 |
if (actionId.equals(ActionFactory.CUT.getId())) { |
224 |
textViewer.doOperation(ITextOperationTarget.CUT); |
225 |
return true; |
226 |
} else if (actionId.equals(ActionFactory.COPY.getId())) { |
227 |
textViewer.doOperation(ITextOperationTarget.COPY); |
228 |
return true; |
229 |
} else if (actionId.equals(ActionFactory.PASTE.getId())) { |
230 |
textViewer.doOperation(ITextOperationTarget.PASTE); |
231 |
return true; |
232 |
} else if (actionId.equals(ActionFactory.DELETE.getId())) { |
233 |
textViewer.doOperation(ITextOperationTarget.DELETE); |
234 |
return true; |
235 |
} else if (actionId.equals(ActionFactory.UNDO.getId())) { |
236 |
textViewer.doOperation(ITextOperationTarget.UNDO); |
237 |
return true; |
238 |
} else if (actionId.equals(ActionFactory.REDO.getId())) { |
239 |
textViewer.doOperation(ITextOperationTarget.REDO); |
240 |
return true; |
241 |
} else if (actionId.equals(ActionFactory.SELECT_ALL.getId())) { |
242 |
textViewer.doOperation(ITextOperationTarget.SELECT_ALL); |
243 |
return true; |
244 |
} |
245 |
return false; |
246 |
} |
247 |
|
248 |
private boolean canDoGlobalAction(String actionId, TextViewer textViewer) { |
249 |
if (actionId.equals(ActionFactory.CUT.getId())) { |
250 |
return textViewer.canDoOperation(ITextOperationTarget.CUT); |
251 |
} else if (actionId.equals(ActionFactory.COPY.getId())) { |
252 |
return textViewer.canDoOperation(ITextOperationTarget.COPY); |
253 |
} else if (actionId.equals(ActionFactory.PASTE.getId())) { |
254 |
return textViewer.canDoOperation(ITextOperationTarget.PASTE); |
255 |
} else if (actionId.equals(ActionFactory.DELETE.getId())) { |
256 |
return textViewer.canDoOperation(ITextOperationTarget.DELETE); |
257 |
} else if (actionId.equals(ActionFactory.UNDO.getId())) { |
258 |
return textViewer.canDoOperation(ITextOperationTarget.UNDO); |
259 |
} else if (actionId.equals(ActionFactory.REDO.getId())) { |
260 |
return textViewer.canDoOperation(ITextOperationTarget.REDO); |
261 |
} else if (actionId.equals(ActionFactory.SELECT_ALL.getId())) { |
262 |
return textViewer.canDoOperation(ITextOperationTarget.SELECT_ALL); |
263 |
} |
264 |
return false; |
265 |
} |
266 |
|
267 |
/** |
268 |
* Text viewer generally used for displaying non-editable text. No annotation model or spell checking support. |
269 |
* Supports cut/copy/paste/etc.. |
270 |
*/ |
271 |
protected TextViewer addTextViewer(TaskRepository repository, Composite composite, String text, int style) { |
272 |
|
273 |
if (actionContributor == null) { |
274 |
actionContributor = (TaskEditorActionContributor) getEditorSite().getActionBarContributor(); |
275 |
} |
276 |
|
277 |
final RepositoryTextViewer commentViewer = new RepositoryTextViewer(repository, composite, style); |
278 |
|
279 |
// NOTE: Configuration must be applied before the document is set in |
280 |
// order for |
281 |
// Hyperlink colouring to work. (Presenter needs document object up |
282 |
// front) |
283 |
RepositoryTextViewerConfiguration repositoryViewerConfig = new RepositoryTextViewerConfiguration(repository, |
284 |
false); |
285 |
commentViewer.configure(repositoryViewerConfig); |
286 |
|
287 |
IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); |
288 |
|
289 |
commentViewer.getTextWidget().setFont( |
290 |
themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT)); |
291 |
|
292 |
commentViewer.addSelectionChangedListener(actionContributor); |
293 |
|
294 |
commentViewer.getTextWidget().addFocusListener(new FocusListener() { |
295 |
|
296 |
public void focusGained(FocusEvent e) { |
297 |
|
298 |
actionContributor.updateSelectableActions(commentViewer.getSelection()); |
299 |
|
300 |
} |
301 |
|
302 |
public void focusLost(FocusEvent e) { |
303 |
StyledText st = (StyledText) e.widget; |
304 |
st.setSelectionRange(st.getCaretOffset(), 0); |
305 |
actionContributor.forceActionsEnabled(); |
306 |
} |
307 |
}); |
308 |
|
309 |
commentViewer.addTextListener(new ITextListener() { |
310 |
public void textChanged(TextEvent event) { |
311 |
actionContributor.updateSelectableActions(commentViewer.getSelection()); |
312 |
} |
313 |
}); |
314 |
|
315 |
commentViewer.setEditable(false); |
316 |
MenuManager manager = commentViewer.getMenuManager(); |
317 |
taskEditor.configureContextMenuManager(manager); |
318 |
commentViewer.setMenu(manager.createContextMenu(commentViewer.getTextWidget())); |
319 |
Document document = new Document(text); |
320 |
commentViewer.setDocument(document); |
321 |
|
322 |
addTextViewer(commentViewer); |
323 |
return commentViewer; |
324 |
} |
325 |
|
326 |
/** |
327 |
* For viewing and editing text. Spell checking w/ annotations supported One or two max per editor, any more and the |
328 |
* spell checker will bring the editor to a grinding halt. |
329 |
*/ |
330 |
protected TextViewer addTextEditor(TaskRepository repository, Composite composite, String text, boolean spellCheck, |
331 |
int style) { |
332 |
|
333 |
if (actionContributor == null) { |
334 |
actionContributor = (TaskEditorActionContributor) getEditorSite().getActionBarContributor(); |
335 |
} |
336 |
|
337 |
AnnotationModel annotationModel = new AnnotationModel(); |
338 |
final RepositoryTextViewer commentViewer = new RepositoryTextViewer(null, null, repository, composite, style); |
339 |
commentViewer.showAnnotations(false); |
340 |
commentViewer.showAnnotationsOverview(false); |
341 |
|
342 |
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess(); |
343 |
|
344 |
final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(commentViewer, null, |
345 |
annotationAccess, EditorsUI.getSharedTextColors()); |
346 |
|
347 |
@SuppressWarnings("unchecked") |
348 |
Iterator e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator(); |
349 |
while (e.hasNext()) { |
350 |
support.setAnnotationPreference((AnnotationPreference) e.next()); |
351 |
} |
352 |
|
353 |
support.install(EditorsUI.getPreferenceStore()); |
354 |
|
355 |
commentViewer.getTextWidget().setIndent(2); |
356 |
commentViewer.getTextWidget().addDisposeListener(new DisposeListener() { |
357 |
public void widgetDisposed(DisposeEvent e) { |
358 |
support.uninstall(); |
359 |
} |
360 |
}); |
361 |
|
362 |
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService( |
363 |
IHandlerService.class); |
364 |
|
365 |
IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); |
366 |
|
367 |
commentViewer.getTextWidget().setFont( |
368 |
themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT)); |
369 |
|
370 |
commentViewer.addSelectionChangedListener(actionContributor); |
371 |
|
372 |
commentViewer.getTextWidget().addFocusListener(new FocusListener() { |
373 |
|
374 |
public void focusGained(FocusEvent e) { |
375 |
actionContributor.updateSelectableActions(commentViewer.getSelection()); |
376 |
activate(); |
377 |
} |
378 |
|
379 |
public void focusLost(FocusEvent e) { |
380 |
StyledText st = (StyledText) e.widget; |
381 |
st.setSelectionRange(st.getCaretOffset(), 0); |
382 |
actionContributor.forceActionsEnabled(); |
383 |
|
384 |
deactivate(); |
385 |
} |
386 |
|
387 |
private void activate() { |
388 |
deactivate(); |
389 |
if (handlerActivation == null) { |
390 |
handlerActivation = handlerService.activateHandler( // |
391 |
ITextEditorActionDefinitionIds.QUICK_ASSIST, // |
392 |
createQuickFixActionHandler(commentViewer), // |
393 |
new ActiveShellExpression(commentViewer.getTextWidget().getShell())); |
394 |
} |
395 |
if (handlerCompletion == null) { |
396 |
handlerCompletion = handlerService.activateHandler( // |
397 |
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, // |
398 |
createContentAssistActionHandler(commentViewer), // |
399 |
new ActiveShellExpression(commentViewer.getTextWidget().getShell())); |
400 |
} |
401 |
} |
402 |
|
403 |
private void deactivate() { |
404 |
if (handlerCompletion != null) { |
405 |
handlerService.deactivateHandler(handlerCompletion); |
406 |
handlerCompletion = null; |
407 |
} |
408 |
if (handlerActivation != null) { |
409 |
handlerService.deactivateHandler(handlerActivation); |
410 |
handlerActivation = null; |
411 |
} |
412 |
} |
413 |
}); |
414 |
|
415 |
commentViewer.addTextListener(new ITextListener() { |
416 |
public void textChanged(TextEvent event) { |
417 |
actionContributor.updateSelectableActions(commentViewer.getSelection()); |
418 |
} |
419 |
}); |
420 |
|
421 |
commentViewer.setEditable(false); |
422 |
MenuManager manager = commentViewer.getMenuManager(); |
423 |
taskEditor.configureContextMenuManager(manager); |
424 |
commentViewer.setMenu(manager.createContextMenu(commentViewer.getTextWidget())); |
425 |
Document document = new Document(text); |
426 |
|
427 |
// NOTE: Configuration must be applied before the document is set in order for |
428 |
// Hyperlink coloring to work. (Presenter needs document object up front) |
429 |
TextSourceViewerConfiguration viewerConfig = new RepositoryTextViewerConfiguration(repository, spellCheck); |
430 |
commentViewer.configure(viewerConfig); |
431 |
|
432 |
commentViewer.setDocument(document, annotationModel); |
433 |
|
434 |
// !Do Not Delete! hover manager that shows text when we hover |
435 |
// AnnotationBarHoverManager fAnnotationHoverManager = new AnnotationBarHoverManager(fCompositeRuler, |
436 |
// commentViewer, new AnnotationHover(fAnnotationModel), new AnnotationConfiguration()); |
437 |
// fAnnotationHoverManager.install(annotationRuler.getControl()); |
438 |
|
439 |
// !Do Not Delete! Sample debugging code |
440 |
// document.set("Here's some texst so that we have somewhere to show an error"); |
441 |
// |
442 |
// // // add an annotation |
443 |
// ErrorAnnotation errorAnnotation = new ErrorAnnotation(1, ""); |
444 |
// // lets underline the word "texst" |
445 |
// fAnnotationModel.addAnnotation(errorAnnotation, new Position(12, 5)); |
446 |
|
447 |
// CoreSpellingProblem iProblem = new CoreSpellingProblem(12, 5, 1, |
448 |
// "problem message", "theword", false, false, document, "task editor"); |
449 |
// editorInput.getName() |
450 |
// |
451 |
// fAnnotationModel.addAnnotation(new ProblemAnnotation(iProblem, null), new Position(12, 5)); |
452 |
|
453 |
addTextViewer(commentViewer); |
454 |
return commentViewer; |
455 |
} |
456 |
|
457 |
private IHandler createQuickFixActionHandler(final SourceViewer viewer) { |
458 |
Action quickFixAction = new Action() { |
459 |
@Override |
460 |
public void run() { |
461 |
if (viewer.canDoOperation(ISourceViewer.QUICK_ASSIST)) { |
462 |
viewer.doOperation(ISourceViewer.QUICK_ASSIST); |
463 |
} |
464 |
} |
465 |
}; |
466 |
quickFixAction.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICK_ASSIST); |
467 |
return new ActionHandler(quickFixAction); |
468 |
} |
469 |
|
470 |
private IHandler createContentAssistActionHandler(final SourceViewer viewer) { |
471 |
Action quickFixAction = new Action() { |
472 |
@Override |
473 |
public void run() { |
474 |
if (viewer.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)) { |
475 |
viewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); |
476 |
} |
477 |
} |
478 |
}; |
479 |
quickFixAction.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); |
480 |
return new ActionHandler(quickFixAction); |
481 |
} |
482 |
|
483 |
@Override |
484 |
public boolean isDirty() { |
485 |
return isDirty; |
486 |
} |
487 |
|
488 |
public void markDirty(boolean dirty) { |
489 |
isDirty = dirty; |
490 |
getManagedForm().dirtyStateChanged(); |
491 |
return; |
492 |
} |
493 |
|
494 |
static class AnnotationMarkerAccess implements IAnnotationAccess, IAnnotationAccessExtension { |
495 |
public Object getType(Annotation annotation) { |
496 |
return annotation.getType(); |
497 |
} |
498 |
|
499 |
public boolean isMultiLine(Annotation annotation) { |
500 |
return true; |
501 |
} |
502 |
|
503 |
public boolean isTemporary(Annotation annotation) { |
504 |
return !annotation.isPersistent(); |
505 |
} |
506 |
|
507 |
public String getTypeLabel(Annotation annotation) { |
508 |
if (annotation instanceof ErrorAnnotation) { |
509 |
return Messages.TaskFormPage_Errors; |
510 |
} |
511 |
|
512 |
return null; |
513 |
} |
514 |
|
515 |
public int getLayer(Annotation annotation) { |
516 |
if (annotation instanceof ErrorAnnotation) { |
517 |
return ((ErrorAnnotation) annotation).getLayer(); |
518 |
} |
519 |
|
520 |
return 0; |
521 |
} |
522 |
|
523 |
public void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) { |
524 |
ImageUtilities.drawImage(((ErrorAnnotation) annotation).getImage(), gc, canvas, bounds, SWT.CENTER, SWT.TOP); |
525 |
} |
526 |
|
527 |
public boolean isPaintable(Annotation annotation) { |
528 |
if (annotation instanceof ErrorAnnotation) { |
529 |
return ((ErrorAnnotation) annotation).getImage() != null; |
530 |
} |
531 |
|
532 |
return false; |
533 |
} |
534 |
|
535 |
public boolean isSubtype(Object annotationType, Object potentialSupertype) { |
536 |
if (annotationType.equals(potentialSupertype)) { |
537 |
return true; |
538 |
} |
539 |
|
540 |
return false; |
541 |
|
542 |
} |
543 |
|
544 |
public Object[] getSupertypes(Object annotationType) { |
545 |
return new Object[0]; |
546 |
} |
547 |
} |
548 |
|
549 |
static class AnnotationHover implements IAnnotationHover, ITextHover { |
550 |
|
551 |
AnnotationModel fAnnotationModel = null; |
552 |
|
553 |
public AnnotationHover(AnnotationModel model) { |
554 |
this.fAnnotationModel = model; |
555 |
} |
556 |
|
557 |
@SuppressWarnings("unchecked") |
558 |
public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) { |
559 |
Iterator ite = fAnnotationModel.getAnnotationIterator(); |
560 |
|
561 |
ArrayList<String> all = new ArrayList<String>(); |
562 |
|
563 |
while (ite.hasNext()) { |
564 |
Annotation a = (Annotation) ite.next(); |
565 |
if (a instanceof ErrorAnnotation) { |
566 |
all.add(((ErrorAnnotation) a).getText()); |
567 |
} |
568 |
} |
569 |
|
570 |
StringBuffer total = new StringBuffer(); |
571 |
for (int x = 0; x < all.size(); x++) { |
572 |
String str = all.get(x); |
573 |
total.append(" " + str + (x == (all.size() - 1) ? "" : "\n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
574 |
} |
575 |
|
576 |
return total.toString(); |
577 |
} |
578 |
|
579 |
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { |
580 |
return null; |
581 |
} |
582 |
|
583 |
public IRegion getHoverRegion(ITextViewer textViewer, int offset) { |
584 |
return null; |
585 |
} |
586 |
} |
587 |
|
588 |
public static class ErrorAnnotation extends Annotation { |
589 |
|
590 |
public static String ERROR_TYPE = "spelling.error"; //$NON-NLS-1$ |
591 |
|
592 |
// ProblemAnnotation.SPELLING_ANNOTATION_TYPE; |
593 |
|
594 |
private final IMarker marker; |
595 |
|
596 |
private String text; |
597 |
|
598 |
private int line; |
599 |
|
600 |
private Position position; |
601 |
|
602 |
public ErrorAnnotation(IMarker marker) { |
603 |
this.marker = marker; |
604 |
} |
605 |
|
606 |
public ErrorAnnotation(int line, String text) { |
607 |
super(ERROR_TYPE, true, null); |
608 |
this.marker = null; |
609 |
this.line = line; |
610 |
this.text = text; |
611 |
} |
612 |
|
613 |
public IMarker getMarker() { |
614 |
return marker; |
615 |
} |
616 |
|
617 |
public int getLine() { |
618 |
return line; |
619 |
} |
620 |
|
621 |
@Override |
622 |
public String getText() { |
623 |
return text; |
624 |
} |
625 |
|
626 |
public Image getImage() { |
627 |
return null;// ERROR_IMAGE; |
628 |
} |
629 |
|
630 |
public int getLayer() { |
631 |
return 3; |
632 |
} |
633 |
|
634 |
@Override |
635 |
public String getType() { |
636 |
return ERROR_TYPE; |
637 |
} |
638 |
|
639 |
public Position getPosition() { |
640 |
return position; |
641 |
} |
642 |
|
643 |
public void setPosition(Position position) { |
644 |
this.position = position; |
645 |
} |
646 |
} |
647 |
|
648 |
// NOTE: See commented code below for example implementation |
649 |
static class SharedTextColors implements ISharedTextColors { |
650 |
|
651 |
/** Creates an returns a shared color manager. */ |
652 |
public SharedTextColors() { |
653 |
super(); |
654 |
} |
655 |
|
656 |
public Color getColor(RGB rgb) { |
657 |
return CommonColors.TEXT_SPELLING_ERROR; |
658 |
} |
659 |
|
660 |
public void dispose() { |
661 |
return; |
662 |
} |
663 |
} |
664 |
|
665 |
// DND relves |
666 |
//// From org.eclipse.ui.internal.editors.text.SharedTextColors |
667 |
// static class SharedTextColors implements ISharedTextColors { |
668 |
// /** The display table. */ |
669 |
// @SuppressWarnings("unchecked") |
670 |
// private Map fDisplayTable; |
671 |
// |
672 |
// /** Creates an returns a shared color manager. */ |
673 |
// public SharedTextColors() { |
674 |
// super(); |
675 |
// } |
676 |
// |
677 |
// /* |
678 |
// * @see ISharedTextColors#getColor(RGB) |
679 |
// */ |
680 |
// @SuppressWarnings("unchecked") |
681 |
// public Color getColor(RGB rgb) { |
682 |
// if (rgb == null) |
683 |
// return null; |
684 |
// |
685 |
// if (fDisplayTable == null) |
686 |
// fDisplayTable = new HashMap(2); |
687 |
// |
688 |
// Display display = Display.getCurrent(); |
689 |
// |
690 |
// Map colorTable = (Map) fDisplayTable.get(display); |
691 |
// if (colorTable == null) { |
692 |
// colorTable = new HashMap(10); |
693 |
// fDisplayTable.put(display, colorTable); |
694 |
// } |
695 |
// |
696 |
// Color color = (Color) colorTable.get(rgb); |
697 |
// if (color == null) { |
698 |
// color = new Clr(display, rgb); |
699 |
// colorTable.put(rgb, color); |
700 |
// } |
701 |
// |
702 |
// return color; |
703 |
// } |
704 |
// |
705 |
// /* |
706 |
// * @see ISharedTextColors#dispose() |
707 |
// */ |
708 |
// @SuppressWarnings("unchecked") |
709 |
// public void dispose() { |
710 |
// if (fDisplayTable != null) { |
711 |
// Iterator j = fDisplayTable.values().iterator(); |
712 |
// while (j.hasNext()) { |
713 |
// Iterator i = ((Map) j.next()).values().iterator(); |
714 |
// while (i.hasNext()) |
715 |
// ((Color) i.next()).dispose(); |
716 |
// } |
717 |
// } |
718 |
// } |
719 |
// } |
720 |
|
721 |
static class AnnotationConfiguration implements IInformationControlCreator { |
722 |
public IInformationControl createInformationControl(Shell shell) { |
723 |
return new DefaultInformationControl(shell); |
724 |
} |
725 |
} |
726 |
|
727 |
/** |
728 |
* @since 2.2 |
729 |
*/ |
730 |
// TODO 3.1 remove method |
731 |
public String getSelectionText() { |
732 |
Control focusControl = getFocusControl(); |
733 |
if (focusControl == null) { |
734 |
return null; |
735 |
} |
736 |
if (focusControl instanceof StyledText) { |
737 |
StyledText text = (StyledText) focusControl; |
738 |
for (TextViewer viewer : textViewers) { |
739 |
if (viewer.getTextWidget() == text) { |
740 |
return text.getSelectionText(); |
741 |
} |
742 |
} |
743 |
} |
744 |
return null; |
745 |
} |
746 |
|
747 |
} |