Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 235222 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/TaskEditorExtensions.java (+1 lines)
Lines 34-39 Link Here
34
	private static boolean initialized;
34
	private static boolean initialized;
35
35
36
	public static SortedSet<RegisteredTaskEditorExtension> getTaskEditorExtensions() {
36
	public static SortedSet<RegisteredTaskEditorExtension> getTaskEditorExtensions() {
37
		init();
37
		return new TreeSet<RegisteredTaskEditorExtension>(extensionsById.values());
38
		return new TreeSet<RegisteredTaskEditorExtension>(extensionsById.values());
38
	}
39
	}
39
40
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/TaskEditorExtensionReader.java (-1 / +1 lines)
Lines 28-34 Link Here
28
28
29
	public static final String ATTR_NAME = "name";
29
	public static final String ATTR_NAME = "name";
30
30
31
	public static final String EXTENSION_TASK_EDITOR_EXTENSIONS = "org.eclipse.mylyn.tasks.ui.taskEditorExtensions";
31
	public static final String EXTENSION_TASK_EDITOR_EXTENSIONS = "org.eclipse.mylyn.sandbox.ui.taskEditorExtensions";
32
32
33
	private static final String REPOSITORY_ASSOCIATION = "repositoryAssociation";
33
	private static final String REPOSITORY_ASSOCIATION = "repositoryAssociation";
34
34
(-)plugin.xml (+8 lines)
Lines 357-362 Link Here
357
             state="true">
357
             state="true">
358
       </decorator>
358
       </decorator>
359
    </extension>
359
    </extension>
360
   <extension
361
         point="org.eclipse.mylyn.tasks.ui.editors">
362
      <pageFactory
363
            class="org.eclipse.mylyn.internal.sandbox.ui.editors.ExtensibleBugzillaTaskEditorPageFactory"
364
            id="org.eclipse.mylyn.sandbox..pageFactories.extensibleBugzillaTaskEditor">
365
      </pageFactory>     
366
      </extension>
360
   
367
   
361
   
368
   
362
   
369
   
Lines 389-394 Link Here
389
            contentProvider="org.eclipse.mylyn.internal.sandbox.ui.GroupedTaskListContentProvider:Sheduled"/>
396
            contentProvider="org.eclipse.mylyn.internal.sandbox.ui.GroupedTaskListContentProvider:Sheduled"/>
390
   </extension>
397
   </extension>
391
   -->
398
   -->
399
  
392
   
400
   
393
</plugin>
401
</plugin>
394
402
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/ExtensibleBugzillaTaskEditorPage.java (+50 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers 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
9
package org.eclipse.mylyn.internal.sandbox.ui.editors;
10
11
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
12
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
13
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
14
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
15
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.ui.contexts.IContextService;
18
19
/**
20
 * A bugzilla task editor page that has wiki facilities.
21
 * 
22
 * @author Jingwen Ou
23
 */
24
public class ExtensibleBugzillaTaskEditorPage extends BugzillaTaskEditorPage {
25
26
	public ExtensibleBugzillaTaskEditorPage(TaskEditor editor) {
27
		super(editor);
28
	}
29
30
	@Override
31
	protected AttributeEditorFactory createAttributeEditorFactory() {
32
		final AttributeEditorFactory bugzillaFactory = super.createAttributeEditorFactory();
33
		AttributeEditorFactory factory = new AttributeEditorFactory(getModel(), getTaskRepository()) {
34
			@Override
35
			public AbstractAttributeEditor createEditor(String type, TaskAttribute taskAttribute) {
36
				// replace description part and the comment part
37
				AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(getTaskRepository());
38
				if (extension != null) {
39
					if (TaskAttribute.TYPE_LONG_RICH_TEXT.equals(type)) {
40
						return new ExtensibleRichTextAttributeEditor((IContextService) getEditor().getEditorSite().getService(
41
								IContextService.class), getModel(), getTaskRepository(), extension, taskAttribute,
42
								SWT.MULTI);
43
					}
44
				}
45
				return bugzillaFactory.createEditor(type, taskAttribute);
46
			}
47
		};
48
		return factory;
49
	}
50
}
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/ExtensibleRichTextAttributeEditor.java (+176 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers 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
9
package org.eclipse.mylyn.internal.sandbox.ui.editors;
10
11
import org.eclipse.jface.text.Document;
12
import org.eclipse.jface.text.ITextListener;
13
import org.eclipse.jface.text.TextEvent;
14
import org.eclipse.jface.text.source.SourceViewer;
15
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes;
17
import org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor;
18
import org.eclipse.mylyn.tasks.core.TaskRepository;
19
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
20
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.custom.CTabFolder;
23
import org.eclipse.swt.custom.CTabItem;
24
import org.eclipse.swt.events.DisposeEvent;
25
import org.eclipse.swt.events.DisposeListener;
26
import org.eclipse.swt.events.FocusEvent;
27
import org.eclipse.swt.events.FocusListener;
28
import org.eclipse.swt.events.SelectionEvent;
29
import org.eclipse.swt.events.SelectionListener;
30
import org.eclipse.swt.graphics.Font;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.contexts.IContextActivation;
34
import org.eclipse.ui.contexts.IContextService;
35
import org.eclipse.ui.forms.widgets.FormToolkit;
36
import org.eclipse.ui.themes.IThemeManager;
37
38
/**
39
 * A multitab source viewer that can edit and preview Textile wikitext markup.
40
 * 
41
 * TODO generalize RichTextAttributeEditor: add a protected method to create the SourceViewer then subclasses can then
42
 * create its own SourceViewer without overriding createControl and copying the code in it
43
 * 
44
 * @author Jingwen Ou
45
 */
46
public class ExtensibleRichTextAttributeEditor extends RichTextAttributeEditor {
47
48
	private SourceViewer source;
49
50
	private final TaskRepository taskRepository;
51
52
	private final int styles;
53
54
	private final IContextService contextService;
55
56
	private IContextActivation contextActivation;
57
58
	private final AbstractTaskEditorExtension extension;
59
60
	public ExtensibleRichTextAttributeEditor(IContextService contextService, TaskDataModel manager,
61
			TaskRepository taskRepository, AbstractTaskEditorExtension extension, TaskAttribute taskAttribute,
62
			int styles) {
63
		super(manager, taskRepository, taskAttribute, styles);
64
		this.contextService = contextService;
65
		this.taskRepository = taskRepository;
66
		this.extension = extension;
67
		this.styles = styles;
68
	}
69
70
	@Override
71
	public SourceViewer getViewer() {
72
		return source;
73
	}
74
75
	@Override
76
	public void createControl(Composite parent, FormToolkit toolkit) {
77
		if (isReadOnly()) {
78
			source = extension.createViewer(taskRepository, parent, styles);
79
			source.setDocument(new Document(getValue()));
80
81
			setControl(source instanceof Viewer ? ((Viewer) source).getControl() : source.getTextWidget());
82
		} else {
83
			CTabFolder folder = new CTabFolder(parent, SWT.FLAT | SWT.BOTTOM);
84
85
			/** wikitext markup editor **/
86
87
			CTabItem viewerItem = new CTabItem(folder, SWT.NONE);
88
			viewerItem.setText("Source");
89
			viewerItem.setToolTipText("Edit Source");
90
91
			source = extension.createEditor(taskRepository, folder, styles | SWT.V_SCROLL);
92
			if (source.getDocument() == null) {
93
				source.setDocument(new Document(getValue()));
94
			}
95
			source.addTextListener(new ITextListener() {
96
				public void textChanged(TextEvent event) {
97
					// filter out events caused by text presentation changes, e.g. annotation drawing
98
					String value = source.getTextWidget().getText();
99
					if (!getValue().equals(value)) {
100
						setValue(value);
101
					}
102
				}
103
			});
104
			source.getControl().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
105
106
			//setting up focus stuff, copied from Daivd's solution
107
			FocusListener focusListener = new FocusListener() {
108
109
				public void focusGained(FocusEvent e) {
110
					setContext();
111
				}
112
113
				public void focusLost(FocusEvent e) {
114
					unsetContext();
115
				}
116
			};
117
			source.getTextWidget().addFocusListener(focusListener);
118
			DisposeListener disposeListener = new DisposeListener() {
119
				public void widgetDisposed(DisposeEvent e) {
120
					unsetContext();
121
				}
122
			};
123
			source.getTextWidget().addDisposeListener(disposeListener);
124
125
			viewerItem.setControl(source instanceof Viewer ? ((Viewer) source).getControl() : source.getTextWidget());
126
			folder.setSelection(viewerItem);
127
128
			/** wikitext markup viewer **/
129
130
			CTabItem previewItem = new CTabItem(folder, SWT.NONE);
131
			previewItem.setText("Preview");
132
			previewItem.setToolTipText("Preview Source");
133
134
			final SourceViewer preview = extension.createViewer(taskRepository, folder, styles);
135
136
			previewItem.setControl(preview instanceof Viewer ? ((Viewer) preview).getControl()
137
					: preview.getTextWidget());
138
139
			folder.addSelectionListener(new SelectionListener() {
140
				public void widgetDefaultSelected(SelectionEvent selectionevent) {
141
					widgetSelected(selectionevent);
142
				}
143
144
				public void widgetSelected(SelectionEvent selectionevent) {
145
					Document document = new Document(source.getDocument().get());
146
					preview.setDocument(document);
147
				}
148
			});
149
150
			setControl(folder);
151
		}
152
153
		IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
154
		Font font = themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT);
155
		source.getTextWidget().setFont(font);
156
		toolkit.adapt(source.getControl(), true, false);
157
158
	}
159
160
	protected void unsetContext() {
161
		if (contextActivation != null) {
162
			contextService.deactivateContext(contextActivation);
163
			contextActivation = null;
164
		}
165
	}
166
167
	protected void setContext() {
168
		if (contextActivation != null) {
169
			contextService.deactivateContext(contextActivation);
170
			contextActivation = null;
171
		}
172
		if (contextService != null && extension.getEditorContextId() != null) {
173
			contextActivation = contextService.activateContext(extension.getEditorContextId());
174
		}
175
	}
176
}
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/ExtensibleBugzillaTaskEditorPageFactory.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers 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
9
package org.eclipse.mylyn.internal.sandbox.ui.editors;
10
11
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPageFactory;
12
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
13
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
14
import org.eclipse.ui.forms.editor.FormPage;
15
16
/**
17
 * A bugzilla task editor page factory that invokes a task editor page that has wiki facilities
18
 * 
19
 * @author Jingwen Ou
20
 * @author Steffen Pingel
21
 */
22
public class ExtensibleBugzillaTaskEditorPageFactory extends BugzillaTaskEditorPageFactory {
23
24
	@Override
25
	public boolean canCreatePageFor(TaskEditorInput input) {
26
		return super.canCreatePageFor(input)
27
				&& TaskEditorExtensions.getTaskEditorExtension(input.getTaskRepository()) != null;
28
	}
29
30
	@Override
31
	public FormPage createPage(TaskEditor parentEditor) {
32
		return new ExtensibleBugzillaTaskEditorPage(parentEditor);
33
	}
34
35
	@Override
36
	public String[] getConflictingIds(TaskEditorInput input) {
37
		return new String[] { "org.eclipse.mylyn.bugzilla.ui.pageFactory" };
38
	}
39
40
}

Return to bug 235222