View | Details | Raw Unified | Return to bug 234044 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+3 lines)
Lines 4-10 Link Here
4
Bundle-SymbolicName: org.eclipse.mylyn.commons.ui;singleton:=true
4
Bundle-SymbolicName: org.eclipse.mylyn.commons.ui;singleton:=true
5
Bundle-Version: 3.1.0.qualifier
5
Bundle-Version: 3.1.0.qualifier
6
Require-Bundle: org.eclipse.core.runtime,
6
Require-Bundle: org.eclipse.core.runtime,
7
 org.eclipse.core.expressions,
8
 org.eclipse.jface.text,
7
 org.eclipse.ui,
9
 org.eclipse.ui,
10
 org.eclipse.ui.editors;resolution:=optional,
8
 org.eclipse.ui.forms;resolution:=optional
11
 org.eclipse.ui.forms;resolution:=optional
9
Bundle-ActivationPolicy: lazy
12
Bundle-ActivationPolicy: lazy
10
Bundle-RequiredExecutionEnvironment: J2SE-1.5
13
Bundle-RequiredExecutionEnvironment: J2SE-1.5
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/WorkbenchActionSupport.java (+253 lines)
Added 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
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.provisional.commons.ui;
13
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.Separator;
17
import org.eclipse.jface.text.TextSelection;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.ISelectionChangedListener;
20
import org.eclipse.jface.viewers.SelectionChangedEvent;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.ui.IActionBars;
24
import org.eclipse.ui.ISharedImages;
25
import org.eclipse.ui.IWorkbenchWindow;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.actions.ActionFactory;
28
import org.eclipse.ui.internal.WorkbenchImages;
29
import org.eclipse.ui.internal.WorkbenchMessages;
30
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
31
32
/**
33
 * @author Mik Kersten
34
 * @author Rob Elves
35
 * @author Steffen Pingel
36
 */
37
@SuppressWarnings("restriction")
38
public class WorkbenchActionSupport implements ISelectionChangedListener {
39
40
	private class GlobalAction extends Action {
41
42
		private final String actionId;
43
44
		public GlobalAction(String actionId) {
45
			this.actionId = actionId;
46
		}
47
48
		@Override
49
		public void run() {
50
			if (callback != null) {
51
				callback.doAction(actionId, callback.getFocusControl());
52
				updateActions(callback.getSelection());
53
			}
54
		}
55
56
		public void selectionChanged(ISelection selection) {
57
			if (callback != null) {
58
				setEnabled(callback.canPerformAction(actionId, callback.getFocusControl()));
59
			} else {
60
				setEnabled(false);
61
			}
62
		}
63
	}
64
65
	public static class WorkbenchActionCallback {
66
67
		public boolean canPerformAction(String actionId, Control control) {
68
			return CommonTextSupport.canPerformAction(actionId, control);
69
		}
70
71
		public void doAction(String actionId, Control control) {
72
			CommonTextSupport.doAction(actionId, control);
73
		}
74
75
		public Control getFocusControl() {
76
			return Display.getDefault().getFocusControl();
77
		}
78
79
		public ISelection getSelection() {
80
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
81
			if (window != null && window.getSelectionService() != null) {
82
				return window.getSelectionService().getSelection();
83
			}
84
			return null;
85
		}
86
87
	}
88
89
	private WorkbenchActionCallback callback;
90
91
	private final GlobalAction copyAction;
92
93
	private final GlobalAction cutAction;
94
95
	private final GlobalAction findAction;
96
97
	private final GlobalAction pasteAction;
98
99
	private final GlobalAction redoAction;
100
101
	private final GlobalAction selectAllAction;
102
103
	private final GlobalAction undoAction;
104
105
	public WorkbenchActionSupport() {
106
		cutAction = new GlobalAction(ActionFactory.CUT.getId());
107
		cutAction.setText(WorkbenchMessages.Workbench_cut);
108
		cutAction.setToolTipText(WorkbenchMessages.Workbench_cutToolTip);
109
		cutAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
110
		cutAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
111
		cutAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED));
112
		cutAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.CUT);
113
114
		pasteAction = new GlobalAction(ActionFactory.PASTE.getId());
115
		pasteAction.setText(WorkbenchMessages.Workbench_paste);
116
		pasteAction.setToolTipText(WorkbenchMessages.Workbench_pasteToolTip);
117
		pasteAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
118
		pasteAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
119
		pasteAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
120
		pasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
121
122
		copyAction = new GlobalAction(ActionFactory.COPY.getId());
123
		copyAction.setText(WorkbenchMessages.Workbench_copy);
124
		copyAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
125
		copyAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
126
		copyAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
127
		copyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY);
128
129
		undoAction = new GlobalAction(ActionFactory.UNDO.getId());
130
		undoAction.setText(WorkbenchMessages.Workbench_undo);
131
		undoAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
132
		undoAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
133
		undoAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
134
		undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
135
136
		redoAction = new GlobalAction(ActionFactory.REDO.getId());
137
		redoAction.setText(WorkbenchMessages.Workbench_redo);
138
		redoAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
139
		redoAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
140
		redoAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO_DISABLED));
141
		redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);
142
143
		selectAllAction = new GlobalAction(ActionFactory.SELECT_ALL.getId());
144
		selectAllAction.setText(WorkbenchMessages.Workbench_selectAll);
145
		selectAllAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.SELECT_ALL);
146
		selectAllAction.setEnabled(true);
147
148
		findAction = new GlobalAction(ActionFactory.FIND.getId());
149
		findAction.setText(WorkbenchMessages.Workbench_findReplace);
150
		findAction.setImageDescriptor(CommonImages.FIND);
151
		findAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE);
152
	}
153
154
	public void contributeActions(IMenuManager manager) {
155
		manager.add(undoAction);
156
		manager.add(redoAction);
157
		manager.add(new Separator());
158
		manager.add(cutAction);
159
		manager.add(copyAction);
160
		manager.add(pasteAction);
161
		manager.add(selectAllAction);
162
		manager.add(new Separator());
163
	}
164
165
	public void forceEditActionsEnabled() {
166
		cutAction.setEnabled(true);
167
		copyAction.setEnabled(true);
168
		pasteAction.setEnabled(true);
169
		selectAllAction.setEnabled(true);
170
		undoAction.setEnabled(false);
171
		redoAction.setEnabled(false);
172
	}
173
174
	public WorkbenchActionCallback getCallback() {
175
		return callback;
176
	}
177
178
	public Action getCopyAction() {
179
		return copyAction;
180
	}
181
182
	public Action getCutAction() {
183
		return cutAction;
184
	}
185
186
	public Action getFindAction() {
187
		return findAction;
188
	}
189
190
	public Action getPasteAction() {
191
		return pasteAction;
192
	}
193
194
	public Action getRedoAction() {
195
		return redoAction;
196
	}
197
198
	public Action getSelectAllAction() {
199
		return selectAllAction;
200
	}
201
202
	public Action getUndoAction() {
203
		return undoAction;
204
	}
205
206
	public void install(IActionBars bars) {
207
		bars.setGlobalActionHandler(ActionFactory.CUT.getId(), cutAction);
208
		bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), pasteAction);
209
		bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
210
		bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
211
		bars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
212
		bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAllAction);
213
		bars.setGlobalActionHandler(ActionFactory.FIND.getId(), findAction);
214
		bars.updateActionBars();
215
	}
216
217
	public void selectionChanged(SelectionChangedEvent event) {
218
		ISelection selection = event.getSelection();
219
		if (selection instanceof TextSelection) {
220
			// only update global actions
221
			updateActions(event.getSelection());
222
		} else if (selection.isEmpty()) {
223
			// XXX a styled text widget has lost focus, re-enable all edit actions
224
			forceEditActionsEnabled();
225
		}
226
	}
227
228
	public void setCallback(WorkbenchActionCallback callback) {
229
		this.callback = callback;
230
	}
231
232
	public void uninstall(IActionBars bars) {
233
		bars.setGlobalActionHandler(ActionFactory.CUT.getId(), null);
234
		bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), null);
235
		bars.setGlobalActionHandler(ActionFactory.COPY.getId(), null);
236
		bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), null);
237
		bars.setGlobalActionHandler(ActionFactory.REDO.getId(), null);
238
		bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), null);
239
		bars.setGlobalActionHandler(ActionFactory.FIND.getId(), null);
240
		bars.updateActionBars();
241
	}
242
243
	public void updateActions(ISelection selection) {
244
		cutAction.selectionChanged(selection);
245
		copyAction.selectionChanged(selection);
246
		pasteAction.selectionChanged(selection);
247
		undoAction.selectionChanged(selection);
248
		redoAction.selectionChanged(selection);
249
		selectAllAction.selectionChanged(selection);
250
		findAction.selectionChanged(selection);
251
	}
252
253
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonTextSupport.java (+310 lines)
Added 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
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.provisional.commons.ui;
13
14
import java.util.Iterator;
15
16
import org.eclipse.core.commands.IHandler;
17
import org.eclipse.jface.action.Action;
18
import org.eclipse.jface.commands.ActionHandler;
19
import org.eclipse.jface.text.Document;
20
import org.eclipse.jface.text.ITextListener;
21
import org.eclipse.jface.text.ITextOperationTarget;
22
import org.eclipse.jface.text.TextEvent;
23
import org.eclipse.jface.text.TextViewer;
24
import org.eclipse.jface.text.source.AnnotationModel;
25
import org.eclipse.jface.text.source.IAnnotationAccess;
26
import org.eclipse.jface.text.source.ISourceViewer;
27
import org.eclipse.jface.viewers.ISelectionChangedListener;
28
import org.eclipse.jface.viewers.SelectionChangedEvent;
29
import org.eclipse.jface.viewers.StructuredSelection;
30
import org.eclipse.swt.custom.StyledText;
31
import org.eclipse.swt.events.DisposeEvent;
32
import org.eclipse.swt.events.DisposeListener;
33
import org.eclipse.swt.events.FocusEvent;
34
import org.eclipse.swt.events.FocusListener;
35
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Text;
37
import org.eclipse.swt.widgets.Widget;
38
import org.eclipse.ui.ActiveShellExpression;
39
import org.eclipse.ui.actions.ActionFactory;
40
import org.eclipse.ui.editors.text.EditorsUI;
41
import org.eclipse.ui.handlers.IHandlerActivation;
42
import org.eclipse.ui.handlers.IHandlerService;
43
import org.eclipse.ui.texteditor.AnnotationPreference;
44
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
45
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
46
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
47
48
/**
49
 * @author Steffen Pingel
50
 */
51
public class CommonTextSupport {
52
53
	private class TextViewerFocusListener implements FocusListener {
54
55
		private final boolean spellCheck;
56
57
		private final TextViewer viewer;
58
59
		public TextViewerFocusListener(TextViewer viewer, boolean spellCheck) {
60
			this.viewer = viewer;
61
			this.spellCheck = spellCheck;
62
		}
63
64
		public void focusGained(FocusEvent e) {
65
			if (selectionChangedListener != null) {
66
				selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer, viewer.getSelection()));
67
			}
68
			activateHandlers(viewer, spellCheck);
69
		}
70
71
		public void focusLost(FocusEvent e) {
72
			deactivateHandlers();
73
			if (selectionChangedListener != null) {
74
				// make sure selection no text is selected when control looses focus
75
				StyledText st = (StyledText) e.widget;
76
				st.setSelectionRange(st.getCaretOffset(), 0);
77
				// update action enablement
78
				selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer, StructuredSelection.EMPTY));
79
			}
80
		}
81
82
	}
83
84
	private static String CONTENT_ASSIST_PROPOSALS = "org.eclipse.ui.edit.text.contentAssist.proposals"; //$NON-NLS-1$
85
86
	private static final String KEY_TEXT_VIEWER = "textViewer"; //$NON-NLS-1$
87
88
	private static final String QUICK_ASSIST = "org.eclipse.jdt.ui.edit.text.java.correction.assist.proposals"; //$NON-NLS-1$
89
90
	private static boolean canDoGlobalAction(String actionId, TextViewer textViewer) {
91
		if (actionId.equals(ActionFactory.CUT.getId())) {
92
			return textViewer.canDoOperation(ITextOperationTarget.CUT);
93
		} else if (actionId.equals(ActionFactory.COPY.getId())) {
94
			return textViewer.canDoOperation(ITextOperationTarget.COPY);
95
		} else if (actionId.equals(ActionFactory.PASTE.getId())) {
96
			return textViewer.canDoOperation(ITextOperationTarget.PASTE);
97
		} else if (actionId.equals(ActionFactory.DELETE.getId())) {
98
			return textViewer.canDoOperation(ITextOperationTarget.DELETE);
99
		} else if (actionId.equals(ActionFactory.UNDO.getId())) {
100
			return textViewer.canDoOperation(ITextOperationTarget.UNDO);
101
		} else if (actionId.equals(ActionFactory.REDO.getId())) {
102
			return textViewer.canDoOperation(ITextOperationTarget.REDO);
103
		} else if (actionId.equals(ActionFactory.SELECT_ALL.getId())) {
104
			return textViewer.canDoOperation(ITextOperationTarget.SELECT_ALL);
105
		}
106
		return false;
107
	}
108
109
	public static boolean canPerformAction(String actionId, Control focusControl) {
110
		TextViewer viewer = getTextViewer(focusControl);
111
		if (viewer != null) {
112
			return canDoGlobalAction(actionId, viewer);
113
		}
114
		if (actionId.equals(ActionFactory.UNDO.getId()) || actionId.equals(ActionFactory.REDO.getId())) {
115
			return false;
116
		}
117
		return true;
118
	}
119
120
	private static boolean canPerformDirectly(String id, Control control) {
121
		if (control instanceof Text) {
122
			Text text = (Text) control;
123
			if (id.equals(ActionFactory.CUT.getId())) {
124
				text.cut();
125
				return true;
126
			}
127
			if (id.equals(ActionFactory.COPY.getId())) {
128
				text.copy();
129
				return true;
130
			}
131
			if (id.equals(ActionFactory.PASTE.getId())) {
132
				text.paste();
133
				return true;
134
			}
135
			if (id.equals(ActionFactory.SELECT_ALL.getId())) {
136
				text.selectAll();
137
				return true;
138
			}
139
			if (id.equals(ActionFactory.DELETE.getId())) {
140
				int count = text.getSelectionCount();
141
				if (count == 0) {
142
					int caretPos = text.getCaretPosition();
143
					text.setSelection(caretPos, caretPos + 1);
144
				}
145
				text.insert(""); //$NON-NLS-1$
146
				return true;
147
			}
148
		}
149
		return false;
150
	}
151
152
	public static void doAction(String actionId, Control focusControl) {
153
		if (canPerformDirectly(actionId, focusControl)) {
154
			return;
155
		}
156
		TextViewer viewer = getTextViewer(focusControl);
157
		if (viewer != null) {
158
			doGlobalAction(actionId, viewer);
159
		}
160
	}
161
162
	private static boolean doGlobalAction(String actionId, TextViewer textViewer) {
163
		if (actionId.equals(ActionFactory.CUT.getId())) {
164
			textViewer.doOperation(ITextOperationTarget.CUT);
165
			return true;
166
		} else if (actionId.equals(ActionFactory.COPY.getId())) {
167
			textViewer.doOperation(ITextOperationTarget.COPY);
168
			return true;
169
		} else if (actionId.equals(ActionFactory.PASTE.getId())) {
170
			textViewer.doOperation(ITextOperationTarget.PASTE);
171
			return true;
172
		} else if (actionId.equals(ActionFactory.DELETE.getId())) {
173
			textViewer.doOperation(ITextOperationTarget.DELETE);
174
			return true;
175
		} else if (actionId.equals(ActionFactory.UNDO.getId())) {
176
			textViewer.doOperation(ITextOperationTarget.UNDO);
177
			return true;
178
		} else if (actionId.equals(ActionFactory.REDO.getId())) {
179
			textViewer.doOperation(ITextOperationTarget.REDO);
180
			return true;
181
		} else if (actionId.equals(ActionFactory.SELECT_ALL.getId())) {
182
			textViewer.doOperation(ITextOperationTarget.SELECT_ALL);
183
			return true;
184
		}
185
		return false;
186
	}
187
188
	public static TextViewer getTextViewer(Widget widget) {
189
		if (widget instanceof StyledText) {
190
			Object data = widget.getData(KEY_TEXT_VIEWER);
191
			if (data instanceof TextViewer) {
192
				return (TextViewer) data;
193
			}
194
		}
195
		return null;
196
	}
197
198
	public static void setTextViewer(Widget widget, TextViewer textViewer) {
199
		widget.setData(KEY_TEXT_VIEWER, textViewer);
200
	}
201
202
	public IHandlerActivation contentAssistHandlerActivation;
203
204
	private final IHandlerService handlerService;
205
206
	private IHandlerActivation quickAssistHandlerActivation;
207
208
	private ISelectionChangedListener selectionChangedListener;
209
210
	public CommonTextSupport(IHandlerService handlerService) {
211
		this.handlerService = handlerService;
212
	}
213
214
	private IHandlerActivation activateHandler(TextViewer viewer, int operation, String actionDefinitionId) {
215
		IHandler handler = createActionHandler(viewer, operation, actionDefinitionId);
216
		return handlerService.activateHandler(actionDefinitionId, handler, //
217
				new ActiveShellExpression(viewer.getTextWidget().getShell()));
218
	}
219
220
	private void activateHandlers(TextViewer viewer, boolean spellCheck) {
221
		deactivateHandlers();
222
		if (spellCheck) {
223
			quickAssistHandlerActivation = activateHandler(viewer, ISourceViewer.QUICK_ASSIST, QUICK_ASSIST);
224
		}
225
		contentAssistHandlerActivation = activateHandler(viewer, ISourceViewer.CONTENTASSIST_PROPOSALS,
226
				CONTENT_ASSIST_PROPOSALS);
227
	}
228
229
	public void configure(final TextViewer viewer, Document document, boolean spellCheck) {
230
		if (spellCheck && viewer instanceof ISourceViewer) {
231
			configureAsEditor((ISourceViewer) viewer, document);
232
		} else {
233
			viewer.setDocument(document);
234
		}
235
		install(viewer, spellCheck);
236
	}
237
238
	/** Configures annotation model for spell checking. */
239
	private void configureAsEditor(ISourceViewer viewer, Document document) {
240
		IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
241
		final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(viewer, null, annotationAccess,
242
				EditorsUI.getSharedTextColors());
243
		Iterator<?> e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator();
244
		while (e.hasNext()) {
245
			support.setAnnotationPreference((AnnotationPreference) e.next());
246
		}
247
		support.install(EditorsUI.getPreferenceStore());
248
		viewer.getTextWidget().addDisposeListener(new DisposeListener() {
249
			public void widgetDisposed(DisposeEvent e) {
250
				support.uninstall();
251
			}
252
		});
253
		AnnotationModel annotationModel = new AnnotationModel();
254
		viewer.setDocument(document, annotationModel);
255
	}
256
257
	private IHandler createActionHandler(final ITextOperationTarget viewer, final int operation,
258
			String actionDefinitionId) {
259
		Action action = new Action() {
260
			@Override
261
			public void run() {
262
				if (viewer.canDoOperation(operation)) {
263
					viewer.doOperation(operation);
264
				}
265
			}
266
		};
267
		action.setActionDefinitionId(actionDefinitionId);
268
		return new ActionHandler(action);
269
	}
270
271
	private void deactivateHandlers() {
272
		if (quickAssistHandlerActivation != null) {
273
			handlerService.deactivateHandler(quickAssistHandlerActivation);
274
			quickAssistHandlerActivation = null;
275
		}
276
		if (contentAssistHandlerActivation != null) {
277
			handlerService.deactivateHandler(contentAssistHandlerActivation);
278
			contentAssistHandlerActivation = null;
279
		}
280
	}
281
282
	public void dispose() {
283
		deactivateHandlers();
284
	}
285
286
	public ISelectionChangedListener getSelectionChangedListener() {
287
		return selectionChangedListener;
288
	}
289
290
	public void install(final TextViewer viewer, boolean spellCheck) {
291
		viewer.getControl().addFocusListener(new TextViewerFocusListener(viewer, spellCheck));
292
		if (selectionChangedListener != null) {
293
			viewer.addSelectionChangedListener(selectionChangedListener);
294
			viewer.addTextListener(new ITextListener() {
295
				public void textChanged(TextEvent event) {
296
					if (selectionChangedListener != null) {
297
						selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer,
298
								viewer.getSelection()));
299
					}
300
				}
301
			});
302
		}
303
		setTextViewer(viewer.getControl(), viewer);
304
	}
305
306
	public void setSelectionChangedListener(ISelectionChangedListener selectionChangedListener) {
307
		this.selectionChangedListener = selectionChangedListener;
308
	}
309
310
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskPlanningEditor.java (-1 / +32 lines)
Lines 24-35 Link Here
24
import org.eclipse.jface.action.IToolBarManager;
24
import org.eclipse.jface.action.IToolBarManager;
25
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.dialogs.MessageDialog;
26
import org.eclipse.jface.layout.GridDataFactory;
26
import org.eclipse.jface.layout.GridDataFactory;
27
import org.eclipse.jface.text.Document;
27
import org.eclipse.jface.text.ITextListener;
28
import org.eclipse.jface.text.ITextListener;
28
import org.eclipse.jface.text.TextEvent;
29
import org.eclipse.jface.text.TextEvent;
29
import org.eclipse.jface.text.TextViewer;
30
import org.eclipse.jface.text.TextViewer;
31
import org.eclipse.jface.text.source.SourceViewer;
30
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.mylyn.commons.core.StatusHandler;
33
import org.eclipse.mylyn.commons.core.StatusHandler;
32
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
34
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
35
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonTextSupport;
33
import org.eclipse.mylyn.internal.provisional.commons.ui.DatePicker;
36
import org.eclipse.mylyn.internal.provisional.commons.ui.DatePicker;
34
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
37
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
35
import org.eclipse.mylyn.internal.tasks.core.DayDateRange;
38
import org.eclipse.mylyn.internal.tasks.core.DayDateRange;
Lines 77-85 Link Here
77
import org.eclipse.swt.widgets.Label;
80
import org.eclipse.swt.widgets.Label;
78
import org.eclipse.swt.widgets.Spinner;
81
import org.eclipse.swt.widgets.Spinner;
79
import org.eclipse.swt.widgets.Text;
82
import org.eclipse.swt.widgets.Text;
83
import org.eclipse.ui.IEditorInput;
84
import org.eclipse.ui.IEditorSite;
80
import org.eclipse.ui.PlatformUI;
85
import org.eclipse.ui.PlatformUI;
81
import org.eclipse.ui.forms.IFormColors;
86
import org.eclipse.ui.forms.IFormColors;
82
import org.eclipse.ui.forms.IManagedForm;
87
import org.eclipse.ui.forms.IManagedForm;
88
import org.eclipse.ui.forms.editor.FormPage;
83
import org.eclipse.ui.forms.events.ExpansionEvent;
89
import org.eclipse.ui.forms.events.ExpansionEvent;
84
import org.eclipse.ui.forms.events.HyperlinkAdapter;
90
import org.eclipse.ui.forms.events.HyperlinkAdapter;
85
import org.eclipse.ui.forms.events.HyperlinkEvent;
91
import org.eclipse.ui.forms.events.HyperlinkEvent;
Lines 90-101 Link Here
90
import org.eclipse.ui.forms.widgets.ImageHyperlink;
96
import org.eclipse.ui.forms.widgets.ImageHyperlink;
91
import org.eclipse.ui.forms.widgets.ScrolledForm;
97
import org.eclipse.ui.forms.widgets.ScrolledForm;
92
import org.eclipse.ui.forms.widgets.Section;
98
import org.eclipse.ui.forms.widgets.Section;
99
import org.eclipse.ui.handlers.IHandlerService;
93
100
94
/**
101
/**
95
 * @author Mik Kersten
102
 * @author Mik Kersten
96
 * @author Rob Elves
103
 * @author Rob Elves
97
 */
104
 */
98
public class TaskPlanningEditor extends TaskFormPage {
105
public class TaskPlanningEditor extends FormPage {
99
106
100
	private static final String RESET = Messages.TaskPlanningEditor_Reset;
107
	private static final String RESET = Messages.TaskPlanningEditor_Reset;
101
108
Lines 182-193 Link Here
182
189
183
	private ITaskActivityListener timingListener;
190
	private ITaskActivityListener timingListener;
184
191
192
	private boolean isDirty;
193
194
	private CommonTextSupport textSupport;
195
185
	public TaskPlanningEditor(TaskEditor editor) {
196
	public TaskPlanningEditor(TaskEditor editor) {
186
		super(editor, ITasksUiConstants.ID_PAGE_PLANNING, Messages.TaskPlanningEditor_Planning);
197
		super(editor, ITasksUiConstants.ID_PAGE_PLANNING, Messages.TaskPlanningEditor_Planning);
187
		this.parentEditor = editor;
198
		this.parentEditor = editor;
188
		TasksUiInternal.getTaskList().addChangeListener(TASK_LIST_LISTENER);
199
		TasksUiInternal.getTaskList().addChangeListener(TASK_LIST_LISTENER);
189
	}
200
	}
190
201
202
	@Override
203
	public void init(IEditorSite site, IEditorInput input) {
204
		super.init(site, input);
205
		this.textSupport = new CommonTextSupport((IHandlerService) getSite().getService(IHandlerService.class));
206
		this.textSupport.setSelectionChangedListener((TaskEditorActionContributor) getEditorSite().getActionBarContributor());
207
	}
208
191
	/**
209
	/**
192
	 * Override for customizing the tool bar.
210
	 * Override for customizing the tool bar.
193
	 */
211
	 */
Lines 564-569 Link Here
564
		toolkit.paintBordersFor(statusComposite);
582
		toolkit.paintBordersFor(statusComposite);
565
	}
583
	}
566
584
585
	private TextViewer addTextEditor(TaskRepository repository, Composite parent, String text, boolean spellCheck,
586
			int style) {
587
		SourceViewer viewer = new SourceViewer(parent, null, style);
588
		viewer.configure(new RepositoryTextViewerConfiguration(repository, spellCheck));
589
		textSupport.configure(viewer, new Document(text), spellCheck);
590
		return viewer;
591
	}
592
593
	private void markDirty(boolean dirty) {
594
		isDirty = dirty;
595
		getManagedForm().dirtyStateChanged();
596
	}
597
567
	/**
598
	/**
568
	 * Attempts to set the task pageTitle to the title from the specified url
599
	 * Attempts to set the task pageTitle to the title from the specified url
569
	 */
600
	 */
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorActionContributor.java (-186 / +103 lines)
Lines 29-35 Link Here
29
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.SelectionChangedEvent;
30
import org.eclipse.jface.viewers.SelectionChangedEvent;
31
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
32
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchActionSupport;
33
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchActionSupport.WorkbenchActionCallback;
33
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
34
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
34
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
35
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
35
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
36
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
Lines 51-70 Link Here
51
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
52
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
52
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
53
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
53
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
54
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
55
import org.eclipse.swt.widgets.Control;
54
import org.eclipse.ui.IActionBars;
56
import org.eclipse.ui.IActionBars;
55
import org.eclipse.ui.IEditorInput;
57
import org.eclipse.ui.IEditorInput;
56
import org.eclipse.ui.IEditorPart;
58
import org.eclipse.ui.IEditorPart;
57
import org.eclipse.ui.ISharedImages;
58
import org.eclipse.ui.IWorkbenchActionConstants;
59
import org.eclipse.ui.IWorkbenchActionConstants;
59
import org.eclipse.ui.IWorkbenchPage;
60
import org.eclipse.ui.IWorkbenchPage;
60
import org.eclipse.ui.PlatformUI;
61
import org.eclipse.ui.PlatformUI;
61
import org.eclipse.ui.actions.ActionFactory;
62
import org.eclipse.ui.forms.editor.IFormPage;
62
import org.eclipse.ui.forms.editor.IFormPage;
63
import org.eclipse.ui.internal.WorkbenchImages;
64
import org.eclipse.ui.internal.WorkbenchMessages;
65
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
63
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
66
import org.eclipse.ui.progress.IProgressService;
64
import org.eclipse.ui.progress.IProgressService;
67
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
68
65
69
/**
66
/**
70
 * @author Mik Kersten
67
 * @author Mik Kersten
Lines 74-163 Link Here
74
public class TaskEditorActionContributor extends MultiPageEditorActionBarContributor implements
71
public class TaskEditorActionContributor extends MultiPageEditorActionBarContributor implements
75
		ISelectionChangedListener {
72
		ISelectionChangedListener {
76
73
77
	private TaskEditor editor;
74
	private class EditorPageCallback extends WorkbenchActionCallback {
78
75
79
	private final OpenWithBrowserAction openWithBrowserAction = new OpenWithBrowserAction();
76
		@Override
77
		public boolean canPerformAction(String actionId, Control control) {
78
			IFormPage activePage = getActivePage();
79
			if (activePage instanceof AbstractTaskEditorPage) {
80
				AbstractTaskEditorPage page = (AbstractTaskEditorPage) activePage;
81
				return page.canPerformAction(actionId);
82
			} else {
83
				WorkbenchActionCallback textSupport = (WorkbenchActionCallback) activePage.getAdapter(WorkbenchActionCallback.class);
84
				if (textSupport != null) {
85
					return textSupport.canPerformAction(actionId, control);
86
				} else {
87
					return super.canPerformAction(actionId, control);
88
				}
89
			}
90
		}
80
91
81
	private final CopyTaskDetailsAction copyTaskDetailsAction = new CopyTaskDetailsAction();
92
		@Override
93
		public void doAction(String actionId, Control control) {
94
			IFormPage activePage = getActivePage();
95
			if (activePage instanceof AbstractTaskEditorPage) {
96
				AbstractTaskEditorPage page = (AbstractTaskEditorPage) activePage;
97
				page.doAction(actionId);
98
			} else {
99
				WorkbenchActionCallback textSupport = (WorkbenchActionCallback) activePage.getAdapter(WorkbenchActionCallback.class);
100
				if (textSupport != null) {
101
					textSupport.doAction(actionId, control);
102
				} else {
103
					super.doAction(actionId, control);
104
				}
105
			}
106
		}
82
107
83
	private final SynchronizeEditorAction synchronizeEditorAction = new SynchronizeEditorAction();
108
		@Override
109
		public Control getFocusControl() {
110
			IFormPage page = getActivePage();
111
			return EditorUtil.getFocusControl(page);
112
		}
84
113
85
	private final ShowInTaskListAction showInTaskListAction = new ShowInTaskListAction();
114
		@Override
115
		public ISelection getSelection() {
116
			return TaskEditorActionContributor.this.getSelection();
117
		}
86
118
87
	private final NewTaskFromSelectionAction newTaskFromSelectionAction = new NewTaskFromSelectionAction();
119
	}
88
120
89
	private final GlobalAction cutAction;
121
	private TaskEditor editor;
90
122
91
	private final GlobalAction undoAction;
123
	private final OpenWithBrowserAction openWithBrowserAction = new OpenWithBrowserAction();
92
124
93
	private final GlobalAction redoAction;
125
	private final CopyTaskDetailsAction copyTaskDetailsAction = new CopyTaskDetailsAction();
94
126
95
	private final GlobalAction copyAction;
127
	private final SynchronizeEditorAction synchronizeEditorAction = new SynchronizeEditorAction();
96
128
97
	private final GlobalAction pasteAction;
129
	private final ShowInTaskListAction showInTaskListAction = new ShowInTaskListAction();
98
130
99
	private final GlobalAction selectAllAction;
131
	private final NewTaskFromSelectionAction newTaskFromSelectionAction = new NewTaskFromSelectionAction();
100
132
101
	private final GlobalAction findAction;
133
	private final WorkbenchActionSupport actionSupport;
102
134
103
	public TaskEditorActionContributor() {
135
	public TaskEditorActionContributor() {
104
		cutAction = new GlobalAction(ActionFactory.CUT.getId());
136
		actionSupport = new WorkbenchActionSupport();
105
		cutAction.setText(WorkbenchMessages.Workbench_cut);
137
		actionSupport.setCallback(new EditorPageCallback());
106
		cutAction.setToolTipText(WorkbenchMessages.Workbench_cutToolTip);
107
		cutAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
108
		cutAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
109
		cutAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED));
110
		cutAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.CUT);
111
112
		pasteAction = new GlobalAction(ActionFactory.PASTE.getId());
113
		pasteAction.setText(WorkbenchMessages.Workbench_paste);
114
		pasteAction.setToolTipText(WorkbenchMessages.Workbench_pasteToolTip);
115
		pasteAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
116
		pasteAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
117
		pasteAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
118
		pasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
119
120
		copyAction = new GlobalAction(ActionFactory.COPY.getId());
121
		copyAction.setText(WorkbenchMessages.Workbench_copy);
122
		copyAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
123
		copyAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
124
		copyAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
125
		copyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY);
126
127
		undoAction = new GlobalAction(ActionFactory.UNDO.getId());
128
		undoAction.setText(WorkbenchMessages.Workbench_undo);
129
		undoAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
130
		undoAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
131
		undoAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
132
		undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);
133
134
		redoAction = new GlobalAction(ActionFactory.REDO.getId());
135
		redoAction.setText(WorkbenchMessages.Workbench_redo);
136
		redoAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
137
		redoAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
138
		redoAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO_DISABLED));
139
		redoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.REDO);
140
141
		selectAllAction = new GlobalAction(ActionFactory.SELECT_ALL.getId());
142
		selectAllAction.setText(WorkbenchMessages.Workbench_selectAll);
143
		selectAllAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.SELECT_ALL);
144
		selectAllAction.setEnabled(true);
145
146
		findAction = new GlobalAction(ActionFactory.FIND.getId());
147
		findAction.setText(Messages.TaskEditorActionContributor_Find);
148
		findAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE);
149
		findAction.setImageDescriptor(CommonImages.FIND);
150
	}
138
	}
151
139
152
	public void addClipboardActions(IMenuManager manager) {
140
	public void addClipboardActions(IMenuManager manager) {
153
		manager.add(undoAction);
141
		manager.add(actionSupport.getUndoAction());
154
		manager.add(redoAction);
142
		manager.add(actionSupport.getRedoAction());
155
		manager.add(new Separator());
143
		manager.add(new Separator());
156
		manager.add(cutAction);
144
		manager.add(actionSupport.getCutAction());
157
		manager.add(copyAction);
145
		manager.add(actionSupport.getCopyAction());
158
		manager.add(copyTaskDetailsAction);
146
		manager.add(copyTaskDetailsAction);
159
		manager.add(pasteAction);
147
		manager.add(actionSupport.getPasteAction());
160
		manager.add(selectAllAction);
148
		manager.add(actionSupport.getSelectAllAction());
161
		manager.add(newTaskFromSelectionAction);
149
		manager.add(newTaskFromSelectionAction);
162
		manager.add(new Separator());
150
		manager.add(new Separator());
163
	}
151
	}
Lines 257-289 Link Here
257
		manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
245
		manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
258
	}
246
	}
259
247
260
	private void moveToCategory(AbstractTaskCategory category) {
248
	@Override
261
		IEditorInput input = getEditor().getEditorInput();
249
	public void contributeToCoolBar(ICoolBarManager cbm) {
262
		if (input instanceof TaskEditorInput) {
263
			TaskEditorInput repositoryTaskEditorInput = (TaskEditorInput) input;
264
			final IProgressService svc = PlatformUI.getWorkbench().getProgressService();
265
			final AddExistingTaskJob job = new AddExistingTaskJob(repositoryTaskEditorInput.getTaskRepository(),
266
					repositoryTaskEditorInput.getTask().getTaskId(), category);
267
			job.schedule();
268
			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
269
				public void run() {
270
					svc.showInDialog(getEditor().getSite().getShell(), job);
271
				}
272
			});
273
		}
274
	}
275
276
	public void updateSelectableActions(ISelection selection) {
277
		if (editor != null) {
278
			cutAction.selectionChanged(selection);
279
			copyAction.selectionChanged(selection);
280
			pasteAction.selectionChanged(selection);
281
			undoAction.selectionChanged(selection);
282
			redoAction.selectionChanged(selection);
283
			selectAllAction.selectionChanged(selection);
284
			newTaskFromSelectionAction.selectionChanged(selection);
285
			findAction.selectionChanged(selection);
286
		}
287
	}
250
	}
288
251
289
	@Override
252
	@Override
Lines 298-415 Link Here
298
	public void contributeToToolBar(IToolBarManager tbm) {
261
	public void contributeToToolBar(IToolBarManager tbm) {
299
	}
262
	}
300
263
301
	@Override
264
	public void forceActionsEnabled() {
302
	public void contributeToCoolBar(ICoolBarManager cbm) {
265
		actionSupport.forceEditActionsEnabled();
303
	}
266
	}
304
267
305
	@Override
268
	private IFormPage getActivePage() {
306
	public void init(IActionBars bars, IWorkbenchPage page) {
269
		return (editor != null) ? editor.getActivePageInstance() : null;
307
		super.init(bars, page);
308
		registerGlobalHandlers(bars);
309
		findAction.selectionChanged(StructuredSelection.EMPTY);
310
	}
270
	}
311
271
312
	public TaskEditor getEditor() {
272
	public TaskEditor getEditor() {
313
		return editor;
273
		return editor;
314
	}
274
	}
315
275
316
	@Override
276
	public ISelection getSelection() {
317
	public void setActiveEditor(IEditorPart activeEditor) {
277
		if (editor != null && editor.getSite().getSelectionProvider() != null) {
318
		if (activeEditor instanceof TaskEditor) {
278
			return editor.getSite().getSelectionProvider().getSelection();
319
			this.editor = (TaskEditor) activeEditor;
320
			updateSelectableActions(getSelection());
321
		} else {
279
		} else {
322
			this.editor = null;
280
			return StructuredSelection.EMPTY;
323
		}
281
		}
324
	}
282
	}
325
283
326
	@Override
284
	@Override
327
	public void setActivePage(IEditorPart activePage) {
285
	public void init(IActionBars bars, IWorkbenchPage page) {
328
		updateSelectableActions(getSelection());
286
		super.init(bars, page);
329
	}
287
		actionSupport.install(bars);
330
331
	public void selectionChanged(SelectionChangedEvent event) {
332
		updateSelectableActions(event.getSelection());
333
	}
288
	}
334
289
335
	private class GlobalAction extends Action {
290
	private void moveToCategory(AbstractTaskCategory category) {
336
291
		IEditorInput input = getEditor().getEditorInput();
337
		private final String actionId;
292
		if (input instanceof TaskEditorInput) {
338
293
			TaskEditorInput repositoryTaskEditorInput = (TaskEditorInput) input;
339
		public GlobalAction(String actionId) {
294
			final IProgressService svc = PlatformUI.getWorkbench().getProgressService();
340
			this.actionId = actionId;
295
			final AddExistingTaskJob job = new AddExistingTaskJob(repositoryTaskEditorInput.getTaskRepository(),
341
		}
296
					repositoryTaskEditorInput.getTask().getTaskId(), category);
342
297
			job.schedule();
343
		@Override
298
			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
344
		public void run() {
299
				public void run() {
345
			IFormPage page = getActivePage();
300
					svc.showInDialog(getEditor().getSite().getShell(), job);
346
			if (page instanceof TaskFormPage) {
301
				}
347
				TaskFormPage editor = (TaskFormPage) page;
302
			});
348
				editor.doAction(actionId);
349
			} else if (page instanceof AbstractTaskEditorPage) {
350
				AbstractTaskEditorPage editor = (AbstractTaskEditorPage) page;
351
				editor.doAction(actionId);
352
			} else {
353
				EditorUtil.doAction(actionId, EditorUtil.getFocusControl(getActivePage()));
354
			}
355
			updateSelectableActions(getSelection());
356
		}
357
358
		public void selectionChanged(ISelection selection) {
359
			IFormPage page = getActivePage();
360
			if (page instanceof TaskFormPage) {
361
				TaskFormPage editor = (TaskFormPage) page;
362
				setEnabled(editor.canPerformAction(actionId));
363
			} else if (page instanceof AbstractTaskEditorPage) {
364
				AbstractTaskEditorPage editor = (AbstractTaskEditorPage) page;
365
				setEnabled(editor.canPerformAction(actionId));
366
			} else {
367
				setEnabled(EditorUtil.canPerformAction(actionId, EditorUtil.getFocusControl(getActivePage())));
368
			}
369
		}
303
		}
370
	}
304
	}
371
305
372
	private void registerGlobalHandlers(IActionBars bars) {
306
	public void selectionChanged(SelectionChangedEvent event) {
373
		bars.setGlobalActionHandler(ActionFactory.CUT.getId(), cutAction);
307
		actionSupport.selectionChanged(event);
374
		bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), pasteAction);
308
		newTaskFromSelectionAction.selectionChanged(event.getSelection());
375
		bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
376
		bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
377
		bars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
378
		bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAllAction);
379
		bars.setGlobalActionHandler(ActionFactory.FIND.getId(), findAction);
380
		bars.updateActionBars();
381
	}
382
383
	@SuppressWarnings("unused")
384
	private void unregisterGlobalHandlers(IActionBars bars) {
385
		bars.setGlobalActionHandler(ActionFactory.CUT.getId(), null);
386
		bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), null);
387
		bars.setGlobalActionHandler(ActionFactory.COPY.getId(), null);
388
		bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), null);
389
		bars.setGlobalActionHandler(ActionFactory.REDO.getId(), null);
390
		bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), null);
391
		bars.setGlobalActionHandler(ActionFactory.FIND.getId(), null);
392
		bars.updateActionBars();
393
	}
309
	}
394
310
395
	public void forceActionsEnabled() {
311
	@Override
396
		cutAction.setEnabled(true);
312
	public void setActiveEditor(IEditorPart activeEditor) {
397
		copyAction.setEnabled(true);
313
		if (activeEditor instanceof TaskEditor) {
398
		pasteAction.setEnabled(true);
314
			this.editor = (TaskEditor) activeEditor;
399
		selectAllAction.setEnabled(true);
315
			updateSelectableActions(getSelection());
400
		undoAction.setEnabled(false);
316
		} else {
401
		redoAction.setEnabled(false);
317
			this.editor = null;
318
		}
402
	}
319
	}
403
320
404
	private IFormPage getActivePage() {
321
	@Override
405
		return (editor != null) ? editor.getActivePageInstance() : null;
322
	public void setActivePage(IEditorPart activePage) {
323
		updateSelectableActions(getSelection());
406
	}
324
	}
407
325
408
	private ISelection getSelection() {
326
	public void updateSelectableActions(ISelection selection) {
409
		if (editor != null && editor.getSite().getSelectionProvider() != null) {
327
		if (editor != null) {
410
			return editor.getSite().getSelectionProvider().getSelection();
328
			actionSupport.updateActions(selection);
411
		} else {
329
			newTaskFromSelectionAction.selectionChanged(selection);
412
			return StructuredSelection.EMPTY;
413
		}
330
		}
414
	}
331
	}
415
332
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskFormPage.java (-747 lines)
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
}
(-)src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java (-3 / +13 lines)
Lines 52-57 Link Here
52
import org.eclipse.mylyn.context.core.ContextCore;
52
import org.eclipse.mylyn.context.core.ContextCore;
53
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
53
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
54
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
54
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
55
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonTextSupport;
55
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
56
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
56
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
57
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
57
import org.eclipse.mylyn.internal.tasks.core.DateRange;
58
import org.eclipse.mylyn.internal.tasks.core.DateRange;
Lines 449-454 Link Here
449
450
450
	private TaskAttachmentDropListener defaultDropListener;
451
	private TaskAttachmentDropListener defaultDropListener;
451
452
453
	private CommonTextSupport textSupport;
454
452
	// TODO 3.1 define constructor for setting id and label
455
	// TODO 3.1 define constructor for setting id and label
453
	public AbstractTaskEditorPage(TaskEditor editor, String connectorKind) {
456
	public AbstractTaskEditorPage(TaskEditor editor, String connectorKind) {
454
		super(editor, "id", "label"); //$NON-NLS-1$ //$NON-NLS-2$
457
		super(editor, "id", "label"); //$NON-NLS-1$ //$NON-NLS-2$
Lines 520-527 Link Here
520
	}
523
	}
521
524
522
	AttributeEditorToolkit createAttributeEditorToolkit() {
525
	AttributeEditorToolkit createAttributeEditorToolkit() {
523
		IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
526
		return new AttributeEditorToolkit(textSupport);
524
		return new AttributeEditorToolkit(handlerService);
525
	}
527
	}
526
528
527
	@Override
529
	@Override
Lines 620-626 Link Here
620
		attributeEditorToolkit = createAttributeEditorToolkit();
622
		attributeEditorToolkit = createAttributeEditorToolkit();
621
		Assert.isNotNull(attributeEditorToolkit);
623
		Assert.isNotNull(attributeEditorToolkit);
622
		attributeEditorToolkit.setMenu(editorComposite.getMenu());
624
		attributeEditorToolkit.setMenu(editorComposite.getMenu());
623
		attributeEditorToolkit.setSelectionChangedListener(this);
624
		attributeEditorFactory.setEditorToolkit(attributeEditorToolkit);
625
		attributeEditorFactory.setEditorToolkit(attributeEditorToolkit);
625
626
626
		createParts();
627
		createParts();
Lines 1113-1118 Link Here
1113
		this.task = taskEditorInput.getTask();
1114
		this.task = taskEditorInput.getTask();
1114
		this.defaultSelection = new StructuredSelection(task);
1115
		this.defaultSelection = new StructuredSelection(task);
1115
		this.lastSelection = defaultSelection;
1116
		this.lastSelection = defaultSelection;
1117
		IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
1118
		this.textSupport = new CommonTextSupport(handlerService);
1116
1119
1117
		initModel(taskEditorInput);
1120
		initModel(taskEditorInput);
1118
1121
Lines 1424-1427 Link Here
1424
		}
1427
		}
1425
	}
1428
	}
1426
1429
1430
	/**
1431
	 * @since 3.1
1432
	 */
1433
	public CommonTextSupport getTextSupport() {
1434
		return textSupport;
1435
	}
1436
1427
}
1437
}
(-)src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java (-128 / +10 lines)
Lines 11-19 Link Here
11
11
12
package org.eclipse.mylyn.tasks.ui.editors;
12
package org.eclipse.mylyn.tasks.ui.editors;
13
13
14
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.commands.ActionHandler;
17
import org.eclipse.jface.fieldassist.ComboContentAdapter;
14
import org.eclipse.jface.fieldassist.ComboContentAdapter;
18
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
15
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
19
import org.eclipse.jface.fieldassist.ControlDecoration;
16
import org.eclipse.jface.fieldassist.ControlDecoration;
Lines 22-36 Link Here
22
import org.eclipse.jface.fieldassist.IContentProposalProvider;
19
import org.eclipse.jface.fieldassist.IContentProposalProvider;
23
import org.eclipse.jface.fieldassist.IControlContentAdapter;
20
import org.eclipse.jface.fieldassist.IControlContentAdapter;
24
import org.eclipse.jface.fieldassist.TextContentAdapter;
21
import org.eclipse.jface.fieldassist.TextContentAdapter;
25
import org.eclipse.jface.text.ITextListener;
26
import org.eclipse.jface.text.TextEvent;
27
import org.eclipse.jface.text.TextViewer;
22
import org.eclipse.jface.text.TextViewer;
28
import org.eclipse.jface.text.source.ISourceViewer;
29
import org.eclipse.jface.text.source.SourceViewer;
23
import org.eclipse.jface.text.source.SourceViewer;
30
import org.eclipse.jface.viewers.ILabelProvider;
24
import org.eclipse.jface.viewers.ILabelProvider;
31
import org.eclipse.jface.viewers.ISelectionChangedListener;
25
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonTextSupport;
32
import org.eclipse.jface.viewers.SelectionChangedEvent;
33
import org.eclipse.jface.viewers.StructuredSelection;
34
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes;
26
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes;
35
import org.eclipse.mylyn.internal.tasks.ui.PersonProposalLabelProvider;
27
import org.eclipse.mylyn.internal.tasks.ui.PersonProposalLabelProvider;
36
import org.eclipse.mylyn.internal.tasks.ui.PersonProposalProvider;
28
import org.eclipse.mylyn.internal.tasks.ui.PersonProposalProvider;
Lines 42-62 Link Here
42
import org.eclipse.osgi.util.NLS;
34
import org.eclipse.osgi.util.NLS;
43
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.SWT;
44
import org.eclipse.swt.custom.CCombo;
36
import org.eclipse.swt.custom.CCombo;
45
import org.eclipse.swt.custom.StyledText;
46
import org.eclipse.swt.events.DisposeEvent;
37
import org.eclipse.swt.events.DisposeEvent;
47
import org.eclipse.swt.events.DisposeListener;
38
import org.eclipse.swt.events.DisposeListener;
48
import org.eclipse.swt.events.FocusEvent;
49
import org.eclipse.swt.events.FocusListener;
50
import org.eclipse.swt.graphics.Color;
39
import org.eclipse.swt.graphics.Color;
51
import org.eclipse.swt.widgets.Combo;
40
import org.eclipse.swt.widgets.Combo;
52
import org.eclipse.swt.widgets.Control;
41
import org.eclipse.swt.widgets.Control;
53
import org.eclipse.swt.widgets.Menu;
42
import org.eclipse.swt.widgets.Menu;
54
import org.eclipse.swt.widgets.Text;
43
import org.eclipse.swt.widgets.Text;
55
import org.eclipse.ui.ActiveShellExpression;
56
import org.eclipse.ui.PlatformUI;
44
import org.eclipse.ui.PlatformUI;
57
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
45
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
58
import org.eclipse.ui.handlers.IHandlerActivation;
46
import org.eclipse.ui.handlers.IHandlerActivation;
59
import org.eclipse.ui.handlers.IHandlerService;
60
import org.eclipse.ui.keys.IBindingService;
47
import org.eclipse.ui.keys.IBindingService;
61
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
48
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
62
import org.eclipse.ui.themes.IThemeManager;
49
import org.eclipse.ui.themes.IThemeManager;
Lines 68-141 Link Here
68
// TODO EDITOR rename to AttributeUiToolkit?
55
// TODO EDITOR rename to AttributeUiToolkit?
69
public class AttributeEditorToolkit {
56
public class AttributeEditorToolkit {
70
57
71
	private class StyledTextFocusListener implements FocusListener {
72
73
		private final boolean spellCheck;
74
75
		private final SourceViewer viewer;
76
77
		public StyledTextFocusListener(SourceViewer viewer, boolean spellCheck) {
78
			this.viewer = viewer;
79
			this.spellCheck = spellCheck;
80
		}
81
82
		public void focusGained(FocusEvent e) {
83
			if (selectionChangedListener != null) {
84
				selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer, viewer.getSelection()));
85
			}
86
			activateHandlers(viewer, spellCheck);
87
		}
88
89
		public void focusLost(FocusEvent e) {
90
			deactivateHandlers();
91
			if (selectionChangedListener != null) {
92
				// make sure selection no text is selected when control looses focus
93
				StyledText st = (StyledText) e.widget;
94
				st.setSelectionRange(st.getCaretOffset(), 0);
95
				// update action enablement
96
				selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer, StructuredSelection.EMPTY));
97
			}
98
		}
99
100
	}
101
102
	private final Color colorIncoming;
58
	private final Color colorIncoming;
103
59
104
	public IHandlerActivation contentAssistHandlerActivation;
105
106
	private final IHandlerService handlerService;
107
108
	private Menu menu;
60
	private Menu menu;
109
61
110
	private IHandlerActivation quickAssistHandlerActivation;
62
	private AbstractRenderingEngine renderingEngine;
111
63
112
	private ISelectionChangedListener selectionChangedListener;
64
	private final CommonTextSupport textSupport;
113
65
114
	private AbstractRenderingEngine renderingEngine;
66
	@Deprecated
67
	public IHandlerActivation contentAssistHandlerActivation;
115
68
116
	AttributeEditorToolkit(IHandlerService handlerService) {
69
	AttributeEditorToolkit(CommonTextSupport textSupport) {
117
		this.handlerService = handlerService;
70
		this.textSupport = textSupport;
118
		IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
71
		IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
119
		colorIncoming = themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_INCOMING_BACKGROUND);
72
		colorIncoming = themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_INCOMING_BACKGROUND);
120
	}
73
	}
121
74
122
	private IHandlerActivation activateHandler(SourceViewer viewer, int operation, String actionDefinitionId) {
123
		IHandler handler = createActionHandler(viewer, operation, actionDefinitionId);
124
		return handlerService.activateHandler(actionDefinitionId, handler, //
125
				new ActiveShellExpression(viewer.getTextWidget().getShell()));
126
	}
127
128
	private void activateHandlers(SourceViewer viewer, boolean spellCheck) {
129
		deactivateHandlers();
130
		if (spellCheck) {
131
			quickAssistHandlerActivation = activateHandler(viewer, ISourceViewer.QUICK_ASSIST,
132
					ITextEditorActionDefinitionIds.QUICK_ASSIST);
133
		}
134
		contentAssistHandlerActivation = activateHandler(viewer, ISourceViewer.CONTENTASSIST_PROPOSALS,
135
				ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
136
137
	}
138
139
	public void adapt(AbstractAttributeEditor editor) {
75
	public void adapt(AbstractAttributeEditor editor) {
140
		if (editor.getControl() instanceof Text || editor.getControl() instanceof CCombo) {
76
		if (editor.getControl() instanceof Text || editor.getControl() instanceof CCombo) {
141
			Control control = editor.getControl();
77
			Control control = editor.getControl();
Lines 154-190 Link Here
154
			RichTextAttributeEditor richTextEditor = (RichTextAttributeEditor) editor;
90
			RichTextAttributeEditor richTextEditor = (RichTextAttributeEditor) editor;
155
			boolean spellCheck = hasSpellChecking(editor.getTaskAttribute());
91
			boolean spellCheck = hasSpellChecking(editor.getTaskAttribute());
156
			final SourceViewer viewer = richTextEditor.getViewer();
92
			final SourceViewer viewer = richTextEditor.getViewer();
157
			viewer.getControl().addFocusListener(new StyledTextFocusListener(viewer, spellCheck));
93
			textSupport.install(viewer, spellCheck);
158
			if (selectionChangedListener != null) {
159
				viewer.addSelectionChangedListener(selectionChangedListener);
160
				viewer.addTextListener(new ITextListener() {
161
					public void textChanged(TextEvent event) {
162
						if (selectionChangedListener != null) {
163
							selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer,
164
									viewer.getSelection()));
165
						}
166
					}
167
				});
168
			}
169
			if (!editor.isReadOnly() && richTextEditor.getMode() == Mode.TASK_RELATION) {
94
			if (!editor.isReadOnly() && richTextEditor.getMode() == Mode.TASK_RELATION) {
170
				installContentAssistControlDecoration(viewer.getControl());
95
				installContentAssistControlDecoration(viewer.getControl());
171
			}
96
			}
172
			installMenu(viewer.getControl());
97
			installMenu(viewer.getControl());
173
			EditorUtil.setTextViewer(editor.getControl(), viewer);
174
		} else {
98
		} else {
175
			final TextViewer viewer = EditorUtil.getTextViewer(editor.getControl());
99
			final TextViewer viewer = EditorUtil.getTextViewer(editor.getControl());
176
			if (viewer != null) {
100
			if (viewer != null) {
177
				if (selectionChangedListener != null) {
101
				textSupport.install(viewer, false);
178
					viewer.addSelectionChangedListener(selectionChangedListener);
179
					viewer.addTextListener(new ITextListener() {
180
						public void textChanged(TextEvent event) {
181
							if (selectionChangedListener != null) {
182
								selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer,
183
										viewer.getSelection()));
184
							}
185
						}
186
					});
187
				}
188
				installMenu(viewer.getControl());
102
				installMenu(viewer.getControl());
189
			}
103
			}
190
		}
104
		}
Lines 236-254 Link Here
236
		return controlDecoration;
150
		return controlDecoration;
237
	}
151
	}
238
152
239
	private IHandler createActionHandler(final SourceViewer viewer, final int operation, String actionDefinitionId) {
240
		Action quickFixAction = new Action() {
241
			@Override
242
			public void run() {
243
				if (viewer.canDoOperation(operation)) {
244
					viewer.doOperation(operation);
245
				}
246
			}
247
		};
248
		quickFixAction.setActionDefinitionId(actionDefinitionId);
249
		return new ActionHandler(quickFixAction);
250
	}
251
252
	/**
153
	/**
253
	 * Creates an IContentProposalProvider to provide content assist proposals for the given attribute.
154
	 * Creates an IContentProposalProvider to provide content assist proposals for the given attribute.
254
	 * 
155
	 * 
Lines 264-282 Link Here
264
		return new PersonProposalLabelProvider();
165
		return new PersonProposalLabelProvider();
265
	}
166
	}
266
167
267
	private void deactivateHandlers() {
268
		if (quickAssistHandlerActivation != null) {
269
			handlerService.deactivateHandler(quickAssistHandlerActivation);
270
			quickAssistHandlerActivation = null;
271
		}
272
		if (contentAssistHandlerActivation != null) {
273
			handlerService.deactivateHandler(contentAssistHandlerActivation);
274
			contentAssistHandlerActivation = null;
275
		}
276
	}
277
278
	void dispose() {
168
	void dispose() {
279
		deactivateHandlers();
169
		// FIXME textSupport.deactivateHandlers();
280
	}
170
	}
281
171
282
	public Color getColorIncoming() {
172
	public Color getColorIncoming() {
Lines 298-307 Link Here
298
		return renderingEngine;
188
		return renderingEngine;
299
	}
189
	}
300
190
301
	ISelectionChangedListener getSelectionChangedListener() {
302
		return selectionChangedListener;
303
	}
304
305
	/**
191
	/**
306
	 * Called to check if there's content assist available for the given attribute.
192
	 * Called to check if there's content assist available for the given attribute.
307
	 * 
193
	 * 
Lines 331-340 Link Here
331
		this.menu = menu;
217
		this.menu = menu;
332
	}
218
	}
333
219
334
	void setSelectionChangedListener(ISelectionChangedListener selectionListener) {
335
		this.selectionChangedListener = selectionListener;
336
	}
337
338
	public void setRenderingEngine(AbstractRenderingEngine renderingEngine) {
220
	public void setRenderingEngine(AbstractRenderingEngine renderingEngine) {
339
		this.renderingEngine = renderingEngine;
221
		this.renderingEngine = renderingEngine;
340
	}
222
	}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorNotesPart.java (+130 lines)
Added 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
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui.editors;
13
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.jface.text.Document;
16
import org.eclipse.jface.text.ITextListener;
17
import org.eclipse.jface.text.TextEvent;
18
import org.eclipse.jface.text.source.SourceViewer;
19
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
20
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
21
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.ui.forms.widgets.FormToolkit;
27
import org.eclipse.ui.forms.widgets.Section;
28
import org.eclipse.ui.internal.EditorAreaHelper;
29
import org.eclipse.ui.internal.WorkbenchPage;
30
31
/**
32
 * @author Steffen Pingel
33
 */
34
public class TaskEditorNotesPart extends AbstractTaskEditorPart {
35
36
	private String value;
37
38
	private AbstractTask task;
39
40
	private SourceViewer noteEditor;
41
42
	public TaskEditorNotesPart() {
43
		setPartName(Messages.TaskPlanningEditor_Notes);
44
	}
45
46
	@Override
47
	public void initialize(AbstractTaskEditorPage taskEditorPage) {
48
		super.initialize(taskEditorPage);
49
		task = (AbstractTask) taskEditorPage.getTask();
50
	}
51
52
	private boolean notesEqual() {
53
		if (task.getNotes() == null && value == null) {
54
			return true;
55
		}
56
57
		if (task.getNotes() != null && value != null) {
58
			return task.getNotes().equals(value);
59
		}
60
		return false;
61
	}
62
63
	@Override
64
	public void commit(boolean onSave) {
65
		Assert.isNotNull(task);
66
67
		if (!notesEqual()) {
68
			task.setNotes(value);
69
			// XXX REFRESH THE TASLKIST
70
		}
71
72
		super.commit(onSave);
73
	}
74
75
	@Override
76
	public void createControl(Composite parent, FormToolkit toolkit) {
77
		this.value = task.getNotes();
78
		if (this.value == null) {
79
			this.value = "";
80
		}
81
82
		Section section = createSection(parent, toolkit, this.value != null && this.value.length() > 0);
83
84
		Composite composite = toolkit.createComposite(section);
85
		GridLayout layout = new GridLayout();
86
		layout.numColumns = 1;
87
		composite.setLayout(layout);
88
89
		noteEditor = new SourceViewer(parent, null, SWT.FLAT | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
90
		noteEditor.configure(new RepositoryTextViewerConfiguration(getModel().getTaskRepository(), true));
91
		getTaskEditorPage().getTextSupport().configure(noteEditor, new Document(this.value), true);
92
		noteEditor.addTextListener(new ITextListener() {
93
			public void textChanged(TextEvent event) {
94
				TaskEditorNotesPart.this.value = noteEditor.getTextWidget().getText();
95
				markDirty();
96
			}
97
		});
98
99
		final GridData gd = new GridData(GridData.FILL_BOTH);
100
		int widthHint = 0;
101
102
		if (getManagedForm() != null && getManagedForm().getForm() != null) {
103
			widthHint = getManagedForm().getForm().getClientArea().width - 90;
104
		}
105
		if (widthHint <= 0 && getTaskEditorPage().getEditor().getEditorSite() != null
106
				&& getTaskEditorPage().getEditor().getEditorSite().getPage() != null) {
107
			EditorAreaHelper editorManager = ((WorkbenchPage) getTaskEditorPage().getEditor().getEditorSite().getPage()).getEditorPresentation();
108
			if (editorManager != null && editorManager.getLayoutPart() != null) {
109
				widthHint = editorManager.getLayoutPart().getControl().getBounds().width - 90;
110
			}
111
		}
112
113
		if (widthHint <= 0) {
114
			widthHint = 100;
115
		}
116
117
		gd.widthHint = widthHint;
118
		gd.minimumHeight = 100;
119
		gd.grabExcessHorizontalSpace = true;
120
121
		noteEditor.getControl().setLayoutData(gd);
122
		noteEditor.getControl().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
123
		noteEditor.setEditable(true);
124
125
		toolkit.paintBordersFor(composite);
126
		section.setClient(composite);
127
		setSection(toolkit, section);
128
	}
129
130
}

Return to bug 234044