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 234212
Collapse All | Expand All

(-)plugin.xml (+1 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
<plugin>
3
<plugin>
4
    <extension-point id="taskEditorExtensions" name="Task Editor Extension" schema="schema/taskEditorExtensions.exsd"/>
4
5
5
	<extension point="org.eclipse.ui.views">
6
	<extension point="org.eclipse.ui.views">
6
     	<category name="Mylyn Sandbox" id="org.eclipse.mylyn.sandbox"/>
7
     	<category name="Mylyn Sandbox" id="org.eclipse.mylyn.sandbox"/>
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 34-39 Link Here
34
 org.eclipse.mylyn.internal.sandbox.ui;x-internal:=true,
34
 org.eclipse.mylyn.internal.sandbox.ui;x-internal:=true,
35
 org.eclipse.mylyn.internal.sandbox.ui.actions;x-internal:=true,
35
 org.eclipse.mylyn.internal.sandbox.ui.actions;x-internal:=true,
36
 org.eclipse.mylyn.internal.sandbox.ui.commands;x-internal:=true,
36
 org.eclipse.mylyn.internal.sandbox.ui.commands;x-internal:=true,
37
 org.eclipse.mylyn.internal.sandbox.ui.editors;x-internal:=true,
37
 org.eclipse.mylyn.internal.sandbox.ui.highlighters;x-internal:=true,
38
 org.eclipse.mylyn.internal.sandbox.ui.highlighters;x-internal:=true,
38
 org.eclipse.mylyn.internal.sandbox.ui.planner;x-internal:=true,
39
 org.eclipse.mylyn.internal.sandbox.ui.planner;x-internal:=true,
39
 org.eclipse.mylyn.internal.sandbox.ui.views;x-internal:=true
40
 org.eclipse.mylyn.internal.sandbox.ui.views;x-internal:=true
(-)schema/taskEditorExtensions.exsd (+142 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.mylyn.sandbox.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.eclipse.mylyn.sandbox.ui" id="taskEditorExtensions" name="Task Editor Extensions"/>
7
      </appinfo>
8
      <documentation>
9
         An extension to the Mylyn task editor that can provide viewing and editing controls that are markup-aware.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element internal="true" />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="taskEditorExtension" minOccurs="0" maxOccurs="unbounded"/>
22
            <element ref="repositoryAssociation" minOccurs="0" maxOccurs="unbounded"/>
23
         </sequence>
24
         <attribute name="point" type="string" use="required">
25
            <annotation>
26
               <documentation>
27
                  
28
               </documentation>
29
            </annotation>
30
         </attribute>
31
         <attribute name="id" type="string">
32
            <annotation>
33
               <documentation>
34
                  
35
               </documentation>
36
            </annotation>
37
         </attribute>
38
         <attribute name="name" type="string">
39
            <annotation>
40
               <documentation>
41
                  
42
               </documentation>
43
               <appinfo>
44
                  <meta.attribute translatable="true"/>
45
               </appinfo>
46
            </annotation>
47
         </attribute>
48
      </complexType>
49
   </element>
50
51
   <element name="taskEditorExtension">
52
      <complexType>
53
         <attribute name="class" type="string" use="required">
54
            <annotation>
55
               <documentation>
56
                  the fully qualified class name of the class that extends org.eclipse.mylyn.tasks.ui.editors.TaskEditorExtension
57
               </documentation>
58
               <appinfo>
59
                  <meta.attribute kind="java" basedOn="org.eclipse.mylyn.tasks.ui.editors.TaskEditorExtension:"/>
60
               </appinfo>
61
            </annotation>
62
         </attribute>
63
         <attribute name="id" type="string" use="required">
64
            <annotation>
65
               <documentation>
66
                  a unique identifier identifying the extension
67
               </documentation>
68
               <appinfo>
69
                  <meta.attribute kind="identifier"/>
70
               </appinfo>
71
            </annotation>
72
         </attribute>
73
         <attribute name="name" type="string" use="required">
74
            <annotation>
75
               <documentation>
76
                  A human-readable name for the extension that is presented to the Eclipse user in the UI.    Should be translated.  Used in the UI to identify the type of extension, so the name should indicate what the extension is for, and it should be short so that it can be displayed on one line (for example as an option in a combo box.)  Example: &quot;TracWiki&quot;, or &quot;Textile&quot;.
77
               </documentation>
78
               <appinfo>
79
                  <meta.attribute translatable="true"/>
80
               </appinfo>
81
            </annotation>
82
         </attribute>
83
      </complexType>
84
   </element>
85
86
   <element name="repositoryAssociation">
87
      <complexType>
88
         <attribute name="repository" type="string" use="required">
89
            <annotation>
90
               <documentation>
91
                  
92
               </documentation>
93
            </annotation>
94
         </attribute>
95
         <attribute name="taskEditorExtension" type="string" use="required">
96
            <annotation>
97
               <documentation>
98
                  
99
               </documentation>
100
            </annotation>
101
         </attribute>
102
      </complexType>
103
   </element>
104
105
   <annotation>
106
      <appinfo>
107
         <meta.section type="since"/>
108
      </appinfo>
109
      <documentation>
110
         3.1
111
      </documentation>
112
   </annotation>
113
114
   <annotation>
115
      <appinfo>
116
         <meta.section type="examples"/>
117
      </appinfo>
118
      <documentation>
119
         [Enter extension point usage example here.]
120
      </documentation>
121
   </annotation>
122
123
   <annotation>
124
      <appinfo>
125
         <meta.section type="apiinfo"/>
126
      </appinfo>
127
      <documentation>
128
         [Enter API information here.]
129
      </documentation>
130
   </annotation>
131
132
   <annotation>
133
      <appinfo>
134
         <meta.section type="implementation"/>
135
      </appinfo>
136
      <documentation>
137
         [Enter information about supplied implementation of this extension point.]
138
      </documentation>
139
   </annotation>
140
141
142
</schema>
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/TaskEditorExtensionReader.java (+80 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.core.runtime.CoreException;
12
import org.eclipse.core.runtime.IConfigurationElement;
13
import org.eclipse.core.runtime.IExtension;
14
import org.eclipse.core.runtime.IExtensionPoint;
15
import org.eclipse.core.runtime.IExtensionRegistry;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.mylyn.commons.core.StatusHandler;
20
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
21
22
/**
23
 * @author David Green
24
 */
25
public class TaskEditorExtensionReader {
26
27
	public static final String ATTR_ID = "id";
28
29
	public static final String ATTR_NAME = "name";
30
31
	public static final String EXTENSION_TASK_EDITOR_EXTENSIONS = "org.eclipse.mylyn.tasks.ui.taskEditorExtensions";
32
33
	private static final String REPOSITORY_ASSOCIATION = "repositoryAssociation";
34
35
	private static final String TASK_EDITOR_EXTENSION = "taskEditorExtension";
36
37
	public static void initExtensions() {
38
		IExtensionRegistry registry = Platform.getExtensionRegistry();
39
40
		IExtensionPoint editorExtensionPoint = registry.getExtensionPoint(EXTENSION_TASK_EDITOR_EXTENSIONS);
41
		IExtension[] editorExtensions = editorExtensionPoint.getExtensions();
42
		for (IExtension extension : editorExtensions) {
43
			IConfigurationElement[] elements = extension.getConfigurationElements();
44
			for (IConfigurationElement element : elements) {
45
				if (element.getName().equals(TASK_EDITOR_EXTENSION)) {
46
					readEditorExtension(element);
47
				} else if (element.getName().equals(REPOSITORY_ASSOCIATION)) {
48
					readEditorExtensionAssociation(element);
49
				}
50
			}
51
		}
52
	}
53
54
	private static void readEditorExtension(IConfigurationElement element) {
55
		try {
56
			String id = element.getAttribute(ATTR_ID);
57
			String name = element.getAttribute(ATTR_NAME);
58
			AbstractTaskEditorExtension extension = (AbstractTaskEditorExtension) element.createExecutableExtension("class");
59
			TaskEditorExtensions.addTaskEditorExtension(id, name, extension);
60
		} catch (CoreException e) {
61
			StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load taskEditorExtension",
62
					e));
63
		} catch (Exception e) {
64
			StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load taskEditorExtension",
65
					e));
66
		}
67
	}
68
69
	private static void readEditorExtensionAssociation(IConfigurationElement element) {
70
		try {
71
			String repository = element.getAttribute("repository");
72
			String taskEditorExtension = element.getAttribute("taskEditorExtension");
73
			TaskEditorExtensions.addRepositoryAssociation(repository, taskEditorExtension);
74
		} catch (Exception e) {
75
			StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load taskEditorExtension",
76
					e));
77
		}
78
	}
79
80
}
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/AbstractTaskEditorExtension.java (+54 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.source.SourceViewer;
12
import org.eclipse.mylyn.tasks.core.TaskRepository;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.ui.contexts.IContextService;
15
16
/**
17
 * An extension that provides task editor capabilities beyond the default, oriented towards providing markup-aware
18
 * editing and viewing
19
 * 
20
 * @author David Green
21
 */
22
public abstract class AbstractTaskEditorExtension {
23
24
	/**
25
	 * Create a source viewer that can be used to view content in the task editor. The source viewer should be
26
	 * configured with a source viewer configuration prior to returning.
27
	 * 
28
	 * @param taskRepository
29
	 *            the task repository for which the viewer is created
30
	 * @param parent
31
	 *            the control parent of the source viewer
32
	 * @param style
33
	 *            the styles to use
34
	 */
35
	public abstract SourceViewer createViewer(TaskRepository taskRepository, Composite parent, int style);
36
37
	/**
38
	 * Create a source viewer that can be used to edit content in the task editor. The source viewer should be
39
	 * configured with a source viewer configuration prior to returning.
40
	 * 
41
	 * @param taskRepository
42
	 *            the task repository for which the viewer is created
43
	 * @param parent
44
	 *            the control parent of the source viewer
45
	 * @param style
46
	 *            the styles to use
47
	 */
48
	public abstract SourceViewer createEditor(TaskRepository taskRepository, Composite parent, int style);
49
50
	/**
51
	 * Get the editor context id, to be passed to the {@link IContextService} when the editor is in focus.
52
	 */
53
	public abstract String getEditorContextId();
54
}
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/TaskEditorExtensions.java (+161 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 java.util.HashMap;
12
import java.util.Map;
13
import java.util.SortedSet;
14
import java.util.TreeSet;
15
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.mylyn.commons.core.StatusHandler;
20
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
21
import org.eclipse.mylyn.tasks.core.TaskRepository;
22
23
/**
24
 * @author David Green
25
 */
26
public class TaskEditorExtensions {
27
28
	public static final String REPOSITORY_PROPERTY_EDITOR_EXTENSION = "editorExtension";
29
30
	private static Map<String, RegisteredTaskEditorExtension> extensionsById = new HashMap<String, RegisteredTaskEditorExtension>();
31
32
	private static Map<String, String> associationByConnectorKind = new HashMap<String, String>();
33
34
	private static boolean initialized;
35
36
	public static SortedSet<RegisteredTaskEditorExtension> getTaskEditorExtensions() {
37
		return new TreeSet<RegisteredTaskEditorExtension>(extensionsById.values());
38
	}
39
40
	public static void addTaskEditorExtension(String id, String name, AbstractTaskEditorExtension extension) {
41
		Assert.isNotNull(id);
42
		RegisteredTaskEditorExtension previous = extensionsById.put(id, new RegisteredTaskEditorExtension(extension,
43
				id, name));
44
		if (previous != null) {
45
			StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Duplicate taskEditorExtension id="
46
					+ id, null));
47
		}
48
	}
49
50
	public static void addRepositoryAssociation(String connectorKind, String extensionId) {
51
		if (connectorKind == null || extensionId == null) {
52
			throw new IllegalArgumentException();
53
		}
54
		String previous = associationByConnectorKind.put(connectorKind, extensionId);
55
		if (previous != null) {
56
			StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, String.format(
57
					"Duplicate association for repository %s: %s replaces %s", connectorKind, extensionId, previous),
58
					null));
59
		}
60
	}
61
62
	/**
63
	 * get a task editor extension for a specific repository
64
	 * 
65
	 * @param taskRepository
66
	 * @return the extension, or null if there is none
67
	 * 
68
	 * @see #getDefaultTaskEditorExtension(TaskRepository)
69
	 */
70
	public static AbstractTaskEditorExtension getTaskEditorExtension(TaskRepository taskRepository) {
71
		init();
72
		String extensionId = getTaskEditorExtensionId(taskRepository);
73
		if (extensionId != null) {
74
			RegisteredTaskEditorExtension taskEditorExtension = extensionsById.get(extensionId);
75
			return taskEditorExtension == null ? null : taskEditorExtension.getExtension();
76
		}
77
		return null;
78
	}
79
80
	public static String getTaskEditorExtensionId(TaskRepository taskRepository) {
81
		init();
82
		String id = taskRepository.getProperty(REPOSITORY_PROPERTY_EDITOR_EXTENSION);
83
		if (id == null) {
84
			id = getDefaultTaskEditorExtensionId(taskRepository);
85
		}
86
		return id;
87
	}
88
89
	public static void setTaskEditorExtensionId(TaskRepository repository, String editorExtensionId) {
90
		repository.setProperty(REPOSITORY_PROPERTY_EDITOR_EXTENSION, editorExtensionId);
91
	}
92
93
	public static String getDefaultTaskEditorExtensionId(TaskRepository taskRepository) {
94
		init();
95
		return associationByConnectorKind.get(taskRepository.getConnectorKind());
96
	}
97
98
	/**
99
	 * get a default task editor extension for a specific repository
100
	 * 
101
	 * @param taskRepository
102
	 * @return the extension, or null if there is none
103
	 * 
104
	 * @see #getTaskEditorExtension(TaskRepository)
105
	 */
106
	public static AbstractTaskEditorExtension getDefaultTaskEditorExtension(TaskRepository taskRepository) {
107
		init();
108
		String extensionId = getDefaultTaskEditorExtensionId(taskRepository);
109
		if (extensionId != null) {
110
			RegisteredTaskEditorExtension taskEditorExtension = extensionsById.get(extensionId);
111
			return taskEditorExtension == null ? null : taskEditorExtension.getExtension();
112
		}
113
		return null;
114
	}
115
116
	private static void init() {
117
		if (!initialized) {
118
			initialized = true;
119
			TaskEditorExtensionReader.initExtensions();
120
		}
121
	}
122
123
	public static class RegisteredTaskEditorExtension implements Comparable<RegisteredTaskEditorExtension> {
124
125
		private final String id;
126
127
		private final String name;
128
129
		private final AbstractTaskEditorExtension extension;
130
131
		private RegisteredTaskEditorExtension(AbstractTaskEditorExtension extension, String id, String name) {
132
			this.extension = extension;
133
			this.id = id;
134
			this.name = name;
135
		}
136
137
		public String getId() {
138
			return id;
139
		}
140
141
		public String getName() {
142
			return name;
143
		}
144
145
		public AbstractTaskEditorExtension getExtension() {
146
			return extension;
147
		}
148
149
		public int compareTo(RegisteredTaskEditorExtension o) {
150
			if (o == this) {
151
				return 0;
152
			}
153
			int i = name.compareTo(o.name);
154
			if (i == 0) {
155
				i = id.compareTo(o.id);
156
			}
157
			return i;
158
		}
159
	}
160
161
}

Return to bug 234212