Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7cc0b428ecf1115addfcc8f1cc2e69f17aeaa3bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
 * Copyright (c) 2004 - 2006 Mylar committers and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.mylyn.internal.trac.ui.editor;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.internal.trac.core.TracCorePlugin;
import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector;
import org.eclipse.mylyn.internal.trac.core.TracTask;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorFactory;
import org.eclipse.mylyn.tasks.ui.editors.RepositoryTaskEditorInput;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;

/**
 * @author Steffen Pingel
 */
public class TracTaskEditorFactory extends AbstractTaskEditorFactory {

	private static final String TITLE = "Browser";
	
	public boolean canCreateEditorFor(AbstractTask task) {
		return (task instanceof TracTask);
	}

	public boolean canCreateEditorFor(IEditorInput input) {
		if (input instanceof RepositoryTaskEditorInput) {
			RepositoryTaskEditorInput taskInput = (RepositoryTaskEditorInput) input;
			return taskInput.getTaskData() != null
					&& TracCorePlugin.REPOSITORY_KIND.equals(taskInput.getRepository().getKind());
		} else if (input instanceof TaskEditorInput) {
			TaskEditorInput taskInput = (TaskEditorInput) input;
			return taskInput.getTask() instanceof TracTask;
		} 
 
		return false;
	}

	public IEditorPart createEditor(TaskEditor parentEditor, IEditorInput editorInput) {
		if (editorInput instanceof RepositoryTaskEditorInput) {
			RepositoryTaskEditorInput taskInput = (RepositoryTaskEditorInput) editorInput;
			if (taskInput.getTaskData().isNew()) {
				return new NewTracTaskEditor(parentEditor);
			} else {
				return new TracTaskEditor(parentEditor);
			}
		} else if (editorInput instanceof TaskEditorInput) {
			TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(TracCorePlugin.REPOSITORY_KIND,
					((TaskEditorInput)editorInput).getTask().getRepositoryUrl());
			if (TracRepositoryConnector.hasRichEditor(repository)) {
				// the editor is actually initialized with a RepositoryTaskEditorInput, see bug 193430
				return new TracTaskEditor(parentEditor);
			} else {
				return new BrowserFormPage(parentEditor, TITLE);
			}
		}
		return null;
	}

	public IEditorInput createEditorInput(AbstractTask task) {
		TracTask tracTask = (TracTask) task;
		TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(TracCorePlugin.REPOSITORY_KIND,
				tracTask.getRepositoryUrl());
		if (TracRepositoryConnector.hasRichEditor(repository)) {
			return new RepositoryTaskEditorInput(repository, tracTask.getTaskId(), tracTask.getUrl());
		} else {
			return new TaskEditorInput(task, false) {
				@Override
				public ImageDescriptor getImageDescriptor() {
					return TasksUiImages.BROWSER_SMALL;
				}
			};
		}
	}

	public String getTitle() {
		return "Trac";
	}

	public boolean providesOutline() {
		return true;
	}
}

Back to the top