|
Lines 6-13
Link Here
|
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Raphael Ackermann - initial API and implementation |
9 |
* Tasktop Technologies - initial API and implementation |
| 10 |
* Tasktop Technologies - improvements |
10 |
* Raphael Ackermann - spell checking support on bug 195514 |
|
|
11 |
* Jingwen Ou - extensibility improvements |
| 11 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
| 12 |
|
13 |
|
| 13 |
package org.eclipse.mylyn.internal.tasks.ui.editors; |
14 |
package org.eclipse.mylyn.internal.tasks.ui.editors; |
|
Lines 15-20
Link Here
|
| 15 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
| 16 |
|
17 |
|
| 17 |
import org.eclipse.core.runtime.Assert; |
18 |
import org.eclipse.core.runtime.Assert; |
|
|
19 |
import org.eclipse.jface.action.Action; |
| 20 |
import org.eclipse.jface.action.IAction; |
| 21 |
import org.eclipse.jface.resource.JFaceResources; |
| 18 |
import org.eclipse.jface.text.Document; |
22 |
import org.eclipse.jface.text.Document; |
| 19 |
import org.eclipse.jface.text.ITextListener; |
23 |
import org.eclipse.jface.text.ITextListener; |
| 20 |
import org.eclipse.jface.text.TextEvent; |
24 |
import org.eclipse.jface.text.TextEvent; |
|
Lines 22-44
Link Here
|
| 22 |
import org.eclipse.jface.text.source.IAnnotationAccess; |
26 |
import org.eclipse.jface.text.source.IAnnotationAccess; |
| 23 |
import org.eclipse.jface.text.source.SourceViewer; |
27 |
import org.eclipse.jface.text.source.SourceViewer; |
| 24 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes; |
28 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes; |
|
|
29 |
import org.eclipse.mylyn.internal.tasks.ui.commands.ViewSourceHandler; |
| 25 |
import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTextViewerConfiguration.Mode; |
30 |
import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTextViewerConfiguration.Mode; |
| 26 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; |
31 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; |
| 27 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
32 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
| 28 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
33 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
| 29 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModel; |
34 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModel; |
| 30 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; |
35 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; |
|
|
36 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorExtension; |
| 31 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint; |
37 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint; |
| 32 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan; |
38 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan; |
| 33 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan; |
39 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan; |
| 34 |
import org.eclipse.swt.SWT; |
40 |
import org.eclipse.swt.SWT; |
|
|
41 |
import org.eclipse.swt.custom.StackLayout; |
| 35 |
import org.eclipse.swt.events.DisposeEvent; |
42 |
import org.eclipse.swt.events.DisposeEvent; |
| 36 |
import org.eclipse.swt.events.DisposeListener; |
43 |
import org.eclipse.swt.events.DisposeListener; |
|
|
44 |
import org.eclipse.swt.events.FocusAdapter; |
| 45 |
import org.eclipse.swt.events.FocusEvent; |
| 46 |
import org.eclipse.swt.events.FocusListener; |
| 37 |
import org.eclipse.swt.graphics.Font; |
47 |
import org.eclipse.swt.graphics.Font; |
|
|
48 |
import org.eclipse.swt.graphics.Point; |
| 38 |
import org.eclipse.swt.widgets.Composite; |
49 |
import org.eclipse.swt.widgets.Composite; |
|
|
50 |
import org.eclipse.swt.widgets.Control; |
| 39 |
import org.eclipse.swt.widgets.Event; |
51 |
import org.eclipse.swt.widgets.Event; |
| 40 |
import org.eclipse.swt.widgets.Listener; |
52 |
import org.eclipse.swt.widgets.Listener; |
|
|
53 |
import org.eclipse.swt.widgets.Menu; |
| 41 |
import org.eclipse.ui.PlatformUI; |
54 |
import org.eclipse.ui.PlatformUI; |
|
|
55 |
import org.eclipse.ui.contexts.IContextActivation; |
| 56 |
import org.eclipse.ui.contexts.IContextService; |
| 42 |
import org.eclipse.ui.editors.text.EditorsUI; |
57 |
import org.eclipse.ui.editors.text.EditorsUI; |
| 43 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
58 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
| 44 |
import org.eclipse.ui.texteditor.AnnotationPreference; |
59 |
import org.eclipse.ui.texteditor.AnnotationPreference; |
|
Lines 48-74
Link Here
|
| 48 |
import org.eclipse.ui.themes.IThemeManager; |
63 |
import org.eclipse.ui.themes.IThemeManager; |
| 49 |
|
64 |
|
| 50 |
/** |
65 |
/** |
| 51 |
* FIXME comment is out dated |
66 |
* A text attribute editor that can switch between a editor, preview and source view. |
| 52 |
* |
67 |
* |
| 53 |
* Text viewer generally used for displaying non-editable text. No annotation model or spell checking support. Supports |
68 |
* @author Raphael Ackermann |
| 54 |
* cut/copy/paste/etc.. |
|
|
| 55 |
* |
| 56 |
* For viewing and editing text. Spell checking w/ annotations supported One or two max per editor, any more and the |
| 57 |
* spell checker will bring the editor to a grinding halt. |
| 58 |
* |
| 59 |
* @author Raphael Ackermann (bug 195514) |
| 60 |
* @author Steffen Pingel |
69 |
* @author Steffen Pingel |
|
|
70 |
* @author Jingwen Ou |
| 61 |
*/ |
71 |
*/ |
| 62 |
public class RichTextAttributeEditor extends AbstractAttributeEditor { |
72 |
public class RichTextAttributeEditor extends AbstractAttributeEditor { |
| 63 |
|
73 |
|
| 64 |
private RepositoryTextViewer viewer; |
74 |
private IContextActivation contextActivation; |
| 65 |
|
75 |
|
| 66 |
private boolean spellCheckingEnabled; |
76 |
private final IContextService contextService; |
| 67 |
|
77 |
|
| 68 |
private final int style; |
78 |
private SourceViewer defaultViewer; |
|
|
79 |
|
| 80 |
private Composite editorComposite; |
| 81 |
|
| 82 |
private StackLayout editorLayout; |
| 83 |
|
| 84 |
private final AbstractTaskEditorExtension extension; |
| 85 |
|
| 86 |
private SourceViewer editorViewer; |
| 87 |
|
| 88 |
private SourceViewer previewViewer; |
| 69 |
|
89 |
|
| 70 |
private final TaskRepository taskRepository; |
90 |
private final TaskRepository taskRepository; |
| 71 |
|
91 |
|
|
|
92 |
private FormToolkit toolkit; |
| 93 |
|
| 94 |
public class ViewSourceAction extends Action { |
| 95 |
|
| 96 |
public ViewSourceAction() { |
| 97 |
super("Viewer Source", SWT.TOGGLE); |
| 98 |
setChecked(false); |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
public void run() { |
| 103 |
if (isChecked()) { |
| 104 |
showDefault(); |
| 105 |
} else { |
| 106 |
showEditor(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
private final IAction viewSourceAction = new ViewSourceAction(); |
| 113 |
|
| 114 |
private boolean spellCheckingEnabled; |
| 115 |
|
| 116 |
private final int style; |
| 117 |
|
| 72 |
private Mode mode; |
118 |
private Mode mode; |
| 73 |
|
119 |
|
| 74 |
public RichTextAttributeEditor(TaskDataModel manager, TaskRepository taskRepository, TaskAttribute taskAttribute) { |
120 |
public RichTextAttributeEditor(TaskDataModel manager, TaskRepository taskRepository, TaskAttribute taskAttribute) { |
|
Lines 77-85
Link Here
|
| 77 |
|
123 |
|
| 78 |
public RichTextAttributeEditor(TaskDataModel manager, TaskRepository taskRepository, TaskAttribute taskAttribute, |
124 |
public RichTextAttributeEditor(TaskDataModel manager, TaskRepository taskRepository, TaskAttribute taskAttribute, |
| 79 |
int style) { |
125 |
int style) { |
|
|
126 |
this(manager, taskRepository, taskAttribute, style, null, null); |
| 127 |
} |
| 128 |
|
| 129 |
public RichTextAttributeEditor(TaskDataModel manager, TaskRepository taskRepository, TaskAttribute taskAttribute, |
| 130 |
int style, IContextService contextService, AbstractTaskEditorExtension extension) { |
| 80 |
super(manager, taskAttribute); |
131 |
super(manager, taskAttribute); |
| 81 |
this.taskRepository = taskRepository; |
132 |
this.taskRepository = taskRepository; |
| 82 |
this.style = style; |
133 |
this.style = style; |
|
|
134 |
this.contextService = contextService; |
| 135 |
this.extension = extension; |
| 83 |
if ((style & SWT.MULTI) != 0) { |
136 |
if ((style & SWT.MULTI) != 0) { |
| 84 |
setLayoutHint(new LayoutHint(RowSpan.MULTIPLE, ColumnSpan.MULTIPLE)); |
137 |
setLayoutHint(new LayoutHint(RowSpan.MULTIPLE, ColumnSpan.MULTIPLE)); |
| 85 |
} else { |
138 |
} else { |
|
Lines 97-111
Link Here
|
| 97 |
this.mode = mode; |
150 |
this.mode = mode; |
| 98 |
} |
151 |
} |
| 99 |
|
152 |
|
| 100 |
private void configureAsTextEditor(Document document) { |
153 |
private void installListeners(final SourceViewer viewer) { |
|
|
154 |
viewer.addTextListener(new ITextListener() { |
| 155 |
public void textChanged(TextEvent event) { |
| 156 |
// filter out events caused by text presentation changes, e.g. annotation drawing |
| 157 |
String value = viewer.getTextWidget().getText(); |
| 158 |
if (!getValue().equals(value)) { |
| 159 |
setValue(value); |
| 160 |
EditorUtil.ensureVisible(viewer.getTextWidget()); |
| 161 |
} |
| 162 |
} |
| 163 |
}); |
| 164 |
// ensure that tab traverses to next control instead of inserting a tab character unless editing multi-line text |
| 165 |
if ((style & SWT.MULTI) != 0 && mode != Mode.DEFAULT) { |
| 166 |
viewer.getTextWidget().addListener(SWT.Traverse, new Listener() { |
| 167 |
public void handleEvent(Event event) { |
| 168 |
switch (event.detail) { |
| 169 |
case SWT.TRAVERSE_TAB_NEXT: |
| 170 |
case SWT.TRAVERSE_TAB_PREVIOUS: |
| 171 |
event.doit = true; |
| 172 |
break; |
| 173 |
} |
| 174 |
} |
| 175 |
}); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
public String getValue() { |
| 180 |
return getAttributeMapper().getValue(getTaskAttribute()); |
| 181 |
} |
| 182 |
|
| 183 |
public boolean isSpellCheckingEnabled() { |
| 184 |
return spellCheckingEnabled; |
| 185 |
} |
| 186 |
|
| 187 |
public void setSpellCheckingEnabled(boolean spellCheckingEnabled) { |
| 188 |
this.spellCheckingEnabled = spellCheckingEnabled; |
| 189 |
} |
| 190 |
|
| 191 |
public void setValue(String value) { |
| 192 |
getAttributeMapper().setValue(getTaskAttribute(), value); |
| 193 |
attributeChanged(); |
| 194 |
} |
| 195 |
|
| 196 |
/** Configures annotation model for spell checking. */ |
| 197 |
private void configureAsEditor(SourceViewer viewer, Document document) { |
| 101 |
AnnotationModel annotationModel = new AnnotationModel(); |
198 |
AnnotationModel annotationModel = new AnnotationModel(); |
| 102 |
viewer.showAnnotations(false); |
199 |
viewer.showAnnotations(false); |
| 103 |
viewer.showAnnotationsOverview(false); |
200 |
viewer.showAnnotationsOverview(false); |
| 104 |
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess(); |
201 |
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess(); |
| 105 |
final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(viewer, null, annotationAccess, |
202 |
final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(viewer, null, annotationAccess, |
| 106 |
EditorsUI.getSharedTextColors()); |
203 |
EditorsUI.getSharedTextColors()); |
| 107 |
@SuppressWarnings("unchecked") |
204 |
Iterator<?> e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator(); |
| 108 |
Iterator e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator(); |
|
|
| 109 |
while (e.hasNext()) { |
205 |
while (e.hasNext()) { |
| 110 |
support.setAnnotationPreference((AnnotationPreference) e.next()); |
206 |
support.setAnnotationPreference((AnnotationPreference) e.next()); |
| 111 |
} |
207 |
} |
|
Lines 115-160
Link Here
|
| 115 |
support.uninstall(); |
211 |
support.uninstall(); |
| 116 |
} |
212 |
} |
| 117 |
}); |
213 |
}); |
| 118 |
viewer.getTextWidget().setIndent(2); |
214 |
//viewer.getTextWidget().setIndent(2); |
| 119 |
viewer.setDocument(document, annotationModel); |
215 |
viewer.setDocument(document, annotationModel); |
| 120 |
} |
216 |
} |
| 121 |
|
217 |
|
| 122 |
@Override |
218 |
private RepositoryTextViewerConfiguration installHyperlinkPresenter(SourceViewer viewer) { |
| 123 |
public void createControl(Composite parent, FormToolkit toolkit) { |
219 |
RepositoryTextViewerConfiguration configuration = new RepositoryTextViewerConfiguration(taskRepository, false); |
| 124 |
int style = this.style; |
|
|
| 125 |
if (!isReadOnly() && (style & TasksUiInternal.SWT_NO_SCROLL) == 0) { |
| 126 |
style |= SWT.V_SCROLL; |
| 127 |
} |
| 128 |
viewer = new RepositoryTextViewer(taskRepository, parent, SWT.FLAT | SWT.WRAP | style); |
| 129 |
|
| 130 |
// NOTE: configuration must be applied before the document is set in order for |
| 131 |
// hyper link coloring to work, the Presenter requires the document object up front |
| 132 |
configure(); |
| 133 |
|
| 134 |
Document document = new Document(getValue()); |
| 135 |
if (isReadOnly()) { |
| 136 |
viewer.setEditable(false); |
| 137 |
viewer.setDocument(document); |
| 138 |
} else { |
| 139 |
viewer.setEditable(true); |
| 140 |
configureAsTextEditor(document); |
| 141 |
installListeners(viewer); |
| 142 |
viewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); |
| 143 |
} |
| 144 |
|
| 145 |
IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager(); |
| 146 |
Font font = themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT); |
| 147 |
viewer.getTextWidget().setFont(font); |
| 148 |
toolkit.adapt(viewer.getTextWidget(), false, false); |
| 149 |
|
| 150 |
setControl(viewer.getTextWidget()); |
| 151 |
} |
| 152 |
|
| 153 |
private RepositoryTextViewerConfiguration configure() { |
| 154 |
RepositoryTextViewerConfiguration configuration = new RepositoryTextViewerConfiguration(taskRepository, |
| 155 |
spellCheckingEnabled); |
| 156 |
configuration.setMode(getMode()); |
220 |
configuration.setMode(getMode()); |
| 157 |
viewer.configure(configuration); |
221 |
|
|
|
222 |
// do not configure viewer, this has already been done in extension |
| 158 |
|
223 |
|
| 159 |
AbstractHyperlinkTextPresentationManager manager; |
224 |
AbstractHyperlinkTextPresentationManager manager; |
| 160 |
if (getMode() == Mode.DEFAULT) { |
225 |
if (getMode() == Mode.DEFAULT) { |
|
Lines 174-224
Link Here
|
| 174 |
return configuration; |
239 |
return configuration; |
| 175 |
} |
240 |
} |
| 176 |
|
241 |
|
| 177 |
private void installListeners(RepositoryTextViewer viewer2) { |
242 |
private SourceViewer configure(final SourceViewer viewer, boolean readOnly) { |
| 178 |
viewer.addTextListener(new ITextListener() { |
243 |
// do this before setting the document to not require invalidating the presentation |
| 179 |
public void textChanged(TextEvent event) { |
244 |
installHyperlinkPresenter(viewer); |
| 180 |
// filter out events caused by text presentation changes, e.g. annotation drawing |
245 |
|
| 181 |
String value = viewer.getTextWidget().getText(); |
246 |
Document document = new Document(getValue()); |
| 182 |
if (!getValue().equals(value)) { |
247 |
if (readOnly) { |
| 183 |
setValue(value); |
248 |
viewer.setDocument(document); |
| 184 |
EditorUtil.ensureVisible(viewer.getTextWidget()); |
249 |
if (extension != null) { |
| 185 |
} |
250 |
// setting view source action |
|
|
251 |
viewer.getControl().setData(ViewSourceHandler.VIEW_SOURCE_ACTION, viewSourceAction); |
| 252 |
viewer.getControl().addFocusListener(new FocusAdapter() { |
| 253 |
@Override |
| 254 |
public void focusGained(FocusEvent e) { |
| 255 |
ViewSourceHandler.setChecked(getViewer() == defaultViewer); |
| 256 |
} |
| 257 |
}); |
| 186 |
} |
258 |
} |
| 187 |
}); |
259 |
} else { |
| 188 |
// ensure that tab traverses to next control instead of inserting a tab character unless editing multi-line text |
260 |
configureAsEditor(viewer, document); |
| 189 |
if ((style & SWT.MULTI) != 0 && mode != Mode.DEFAULT) { |
261 |
installListeners(viewer); |
| 190 |
viewer.getTextWidget().addListener(SWT.Traverse, new Listener() { |
262 |
viewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); |
| 191 |
public void handleEvent(Event event) { |
263 |
} |
| 192 |
switch (event.detail) { |
264 |
|
| 193 |
case SWT.TRAVERSE_TAB_NEXT: |
265 |
// enable cut/copy/paste |
| 194 |
case SWT.TRAVERSE_TAB_PREVIOUS: |
266 |
EditorUtil.setTextViewer(viewer.getTextWidget(), viewer); |
| 195 |
event.doit = true; |
267 |
viewer.setEditable(!readOnly); |
| 196 |
break; |
268 |
viewer.getTextWidget().setFont(getFont()); |
|
|
269 |
toolkit.adapt(viewer.getControl(), false, false); |
| 270 |
|
| 271 |
return viewer; |
| 272 |
} |
| 273 |
|
| 274 |
@Override |
| 275 |
public void createControl(Composite parent, FormToolkit toolkit) { |
| 276 |
this.toolkit = toolkit; |
| 277 |
|
| 278 |
int style = this.style; |
| 279 |
if (!isReadOnly() && (style & TasksUiInternal.SWT_NO_SCROLL) == 0) { |
| 280 |
style |= SWT.V_SCROLL; |
| 281 |
} |
| 282 |
|
| 283 |
if (extension != null) { |
| 284 |
editorComposite = new Composite(parent, SWT.NULL); |
| 285 |
editorLayout = new StackLayout() { |
| 286 |
@Override |
| 287 |
protected Point computeSize(Composite composite, int hint, int hint2, boolean flushCache) { |
| 288 |
return topControl.computeSize(hint, hint2, flushCache); |
| 289 |
} |
| 290 |
}; |
| 291 |
editorComposite.setLayout(editorLayout); |
| 292 |
setControl(editorComposite); |
| 293 |
|
| 294 |
if (isReadOnly()) { |
| 295 |
editorViewer = extension.createViewer(taskRepository, editorComposite, style); |
| 296 |
} else { |
| 297 |
editorViewer = extension.createEditor(taskRepository, editorComposite, style); |
| 298 |
editorViewer.getTextWidget().addFocusListener(new FocusListener() { |
| 299 |
public void focusGained(FocusEvent e) { |
| 300 |
setContext(); |
| 197 |
} |
301 |
} |
|
|
302 |
|
| 303 |
public void focusLost(FocusEvent e) { |
| 304 |
unsetContext(); |
| 305 |
} |
| 306 |
}); |
| 307 |
editorViewer.getTextWidget().addDisposeListener(new DisposeListener() { |
| 308 |
public void widgetDisposed(DisposeEvent e) { |
| 309 |
unsetContext(); |
| 310 |
} |
| 311 |
}); |
| 312 |
} |
| 313 |
configure(editorViewer, isReadOnly()); |
| 314 |
show(editorViewer); |
| 315 |
} else { |
| 316 |
defaultViewer = createDefaultEditor(parent, style); |
| 317 |
configure(defaultViewer, isReadOnly()); |
| 318 |
setControl(defaultViewer.getControl()); |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
private SourceViewer createDefaultEditor(Composite parent, int styles) { |
| 323 |
SourceViewer defaultEditor = new RepositoryTextViewer(taskRepository, parent, styles | SWT.WRAP); |
| 324 |
|
| 325 |
RepositoryTextViewerConfiguration viewerConfig = new RepositoryTextViewerConfiguration(taskRepository, |
| 326 |
isSpellCheckingEnabled()); |
| 327 |
viewerConfig.setMode(getMode()); |
| 328 |
defaultEditor.configure(viewerConfig); |
| 329 |
|
| 330 |
return defaultEditor; |
| 331 |
} |
| 332 |
|
| 333 |
public SourceViewer getDefaultViewer() { |
| 334 |
if (defaultViewer == null) { |
| 335 |
defaultViewer = createDefaultEditor(editorComposite, style); |
| 336 |
configure(defaultViewer, isReadOnly()); |
| 337 |
|
| 338 |
// fixed font size |
| 339 |
defaultViewer.getTextWidget().setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT)); |
| 340 |
// adapt maximize action |
| 341 |
defaultViewer.getControl().setData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION, |
| 342 |
editorViewer.getControl().getData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION)); |
| 343 |
// adapt menu to the new viewer |
| 344 |
installMenu(defaultViewer.getControl(), editorViewer.getControl().getMenu()); |
| 345 |
} |
| 346 |
return defaultViewer; |
| 347 |
} |
| 348 |
|
| 349 |
private void installMenu(final Control control, Menu menu) { |
| 350 |
if (menu != null) { |
| 351 |
control.setMenu(menu); |
| 352 |
control.addDisposeListener(new DisposeListener() { |
| 353 |
public void widgetDisposed(DisposeEvent e) { |
| 354 |
control.setMenu(null); |
| 198 |
} |
355 |
} |
| 199 |
}); |
356 |
}); |
| 200 |
} |
357 |
} |
| 201 |
} |
358 |
} |
| 202 |
|
359 |
|
| 203 |
public String getValue() { |
360 |
private Font getFont() { |
| 204 |
return getAttributeMapper().getValue(getTaskAttribute()); |
361 |
IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager(); |
|
|
362 |
Font font = themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT); |
| 363 |
return font; |
| 364 |
} |
| 365 |
|
| 366 |
private SourceViewer getPreviewViewer() { |
| 367 |
if (extension == null) { |
| 368 |
return null; |
| 369 |
} |
| 370 |
|
| 371 |
// construct as needed |
| 372 |
if (previewViewer == null) { |
| 373 |
previewViewer = extension.createViewer(taskRepository, editorComposite, style); |
| 374 |
configure(previewViewer, true); |
| 375 |
// adapt maximize action |
| 376 |
previewViewer.getControl().setData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION, |
| 377 |
editorViewer.getControl().getData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION)); |
| 378 |
} |
| 379 |
Document document = new Document(editorViewer.getDocument().get()); |
| 380 |
previewViewer.setDocument(document); |
| 381 |
return previewViewer; |
| 382 |
} |
| 383 |
|
| 384 |
public SourceViewer getEditorViewer() { |
| 385 |
return editorViewer; |
| 205 |
} |
386 |
} |
| 206 |
|
387 |
|
| 207 |
public SourceViewer getViewer() { |
388 |
public SourceViewer getViewer() { |
| 208 |
return viewer; |
389 |
if (editorLayout == null) { |
|
|
390 |
return defaultViewer; |
| 391 |
} |
| 392 |
if (defaultViewer != null && editorLayout.topControl == defaultViewer.getControl()) { |
| 393 |
return defaultViewer; |
| 394 |
} else if (previewViewer != null && editorLayout.topControl == previewViewer.getControl()) { |
| 395 |
return previewViewer; |
| 396 |
} else { |
| 397 |
return editorViewer; |
| 398 |
} |
| 209 |
} |
399 |
} |
| 210 |
|
400 |
|
| 211 |
public boolean isSpellCheckingEnabled() { |
401 |
private void setContext() { |
| 212 |
return spellCheckingEnabled; |
402 |
if (contextService == null) { |
|
|
403 |
return; |
| 404 |
} |
| 405 |
if (contextActivation != null) { |
| 406 |
contextService.deactivateContext(contextActivation); |
| 407 |
contextActivation = null; |
| 408 |
} |
| 409 |
if (contextService != null && extension.getEditorContextId() != null) { |
| 410 |
contextActivation = contextService.activateContext(extension.getEditorContextId()); |
| 411 |
} |
| 213 |
} |
412 |
} |
| 214 |
|
413 |
|
| 215 |
public void setSpellCheckingEnabled(boolean spellCheckingEnabled) { |
414 |
/** |
| 216 |
this.spellCheckingEnabled = spellCheckingEnabled; |
415 |
* Brings <code>viewer</code> to top. |
|
|
416 |
*/ |
| 417 |
private void show(SourceViewer viewer) { |
| 418 |
// no extension is available |
| 419 |
if (editorComposite == null) { |
| 420 |
return; |
| 421 |
} |
| 422 |
|
| 423 |
editorLayout.topControl = viewer.getControl(); |
| 424 |
editorComposite.layout(); |
| 425 |
viewer.getControl().setFocus(); |
| 217 |
} |
426 |
} |
| 218 |
|
427 |
|
| 219 |
public void setValue(String value) { |
428 |
public void showDefault() { |
| 220 |
getAttributeMapper().setValue(getTaskAttribute(), value); |
429 |
show(getDefaultViewer()); |
| 221 |
attributeChanged(); |
430 |
} |
|
|
431 |
|
| 432 |
public void showPreview() { |
| 433 |
if (!isReadOnly()) { |
| 434 |
show(getPreviewViewer()); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
public void showEditor() { |
| 439 |
show(getEditorViewer()); |
| 440 |
} |
| 441 |
|
| 442 |
private void unsetContext() { |
| 443 |
if (contextService == null) { |
| 444 |
return; |
| 445 |
} |
| 446 |
if (contextActivation != null) { |
| 447 |
contextService.deactivateContext(contextActivation); |
| 448 |
contextActivation = null; |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
public boolean hasPreview() { |
| 453 |
return extension != null && !isReadOnly(); |
| 222 |
} |
454 |
} |
| 223 |
|
455 |
|
| 224 |
} |
456 |
} |