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 159135 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/tasks/ui/properties/ProjectTaskRepositoryPage.java (-1 / +3 lines)
Lines 104-110 Link Here
104
		listViewer.setInput(project.getWorkspace());
104
		listViewer.setInput(project.getWorkspace());
105
105
106
		TaskRepository repository = TasksUiPlugin.getDefault().getRepositoryForResource(project, true);
106
		TaskRepository repository = TasksUiPlugin.getDefault().getRepositoryForResource(project, true);
107
108
		if (repository != null) {
107
		if (repository != null) {
109
			listViewer.setCheckedElements(new Object[] { repository });
108
			listViewer.setCheckedElements(new Object[] { repository });
110
		}
109
		}
Lines 118-123 Link Here
118
				modified = true;
117
				modified = true;
119
			}
118
			}
120
		});
119
		});
120
		listViewer.getControl().setEnabled(TasksUiPlugin.getDefault().canSetRepositoryForResource(project));
121
121
122
		final AddRepositoryAction action = new AddRepositoryAction();
122
		final AddRepositoryAction action = new AddRepositoryAction();
123
123
Lines 167-172 Link Here
167
		if (listViewer.getCheckedElements().length > 0) {
167
		if (listViewer.getCheckedElements().length > 0) {
168
			TaskRepository selectedRepository = (TaskRepository) listViewer.getCheckedElements()[0];
168
			TaskRepository selectedRepository = (TaskRepository) listViewer.getCheckedElements()[0];
169
			try {
169
			try {
170
				
171
				
170
				TasksUiPlugin.getDefault().setRepositoryForResource(project, selectedRepository);
172
				TasksUiPlugin.getDefault().setRepositoryForResource(project, selectedRepository);
171
			} catch (CoreException e) {
173
			} catch (CoreException e) {
172
				MylarStatusHandler.fail(e, "Unable to associate project with task repository", true);
174
				MylarStatusHandler.fail(e, "Unable to associate project with task repository", true);
(-)plugin.xml (+10 lines)
Lines 4-9 Link Here
4
    <extension-point id="actions" name="Tasklist Actions" schema="schema/actions.exsd"/>
4
    <extension-point id="actions" name="Tasklist Actions" schema="schema/actions.exsd"/>
5
    <extension-point id="repositories" name="Task Repositories" schema="schema/repositories.exsd"/>
5
    <extension-point id="repositories" name="Task Repositories" schema="schema/repositories.exsd"/>
6
    <extension-point id="editors" name="Task Editors" schema="schema/editors.exsd"/>
6
    <extension-point id="editors" name="Task Editors" schema="schema/editors.exsd"/>
7
    <extension-point id="repositoryLinkProviders" name="Task Repository Link Provider" schema="schema/repositoryLinkProviders.exsd"/>
7
8
8
	<!--
9
	<!--
9
    <extension
10
    <extension
Lines 711-716 Link Here
711
          </commandParameter>
712
          </commandParameter>
712
       </command>
713
       </command>
713
    </extension>
714
    </extension>
715
    <extension
716
          point="org.eclipse.mylar.tasks.ui.repositoryLinkProviders">
717
       <linkProvider
718
             class="org.eclipse.mylar.tasks.ui.DefaultTaskRepositoryLinkProvider"
719
             name="Default Repository Link"
720
             order="1000"
721
             id="org.eclipse.mylar.tasks.ui.defaultRepositoryLinkProvider">
722
       </linkProvider>
723
    </extension>
714
  
724
  
715
</plugin>
725
</plugin>
716
726
(-)src/org/eclipse/mylar/tasks/ui/TasksUiPlugin.java (-40 / +55 lines)
Lines 13-36 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collection;
15
import java.util.Collection;
16
import java.util.Comparator;
16
import java.util.Date;
17
import java.util.Date;
17
import java.util.HashMap;
18
import java.util.HashMap;
18
import java.util.HashSet;
19
import java.util.HashSet;
19
import java.util.List;
20
import java.util.List;
20
import java.util.Map;
21
import java.util.Map;
21
import java.util.Set;
22
import java.util.Set;
23
import java.util.TreeSet;
22
24
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.ProjectScope;
26
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.core.runtime.Platform;
30
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
30
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
31
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
31
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
32
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
33
import org.eclipse.core.runtime.preferences.IScopeContext;
34
import org.eclipse.jface.dialogs.MessageDialog;
32
import org.eclipse.jface.dialogs.MessageDialog;
35
import org.eclipse.jface.preference.IPreferenceStore;
33
import org.eclipse.jface.preference.IPreferenceStore;
36
import org.eclipse.jface.resource.ImageDescriptor;
34
import org.eclipse.jface.resource.ImageDescriptor;
Lines 84-90 Link Here
84
import org.eclipse.ui.plugin.AbstractUIPlugin;
82
import org.eclipse.ui.plugin.AbstractUIPlugin;
85
import org.osgi.framework.Bundle;
83
import org.osgi.framework.Bundle;
86
import org.osgi.framework.BundleContext;
84
import org.osgi.framework.BundleContext;
87
import org.osgi.service.prefs.BackingStoreException;
88
85
89
/**
86
/**
90
 * @author Mik Kersten
87
 * @author Mik Kersten
Lines 97-108 Link Here
97
94
98
	public static final String PLUGIN_ID = "org.eclipse.mylar.tasklist";
95
	public static final String PLUGIN_ID = "org.eclipse.mylar.tasklist";
99
	
96
	
100
	private static final String PROPERTY_PREFIX = "project.repository";
101
102
	private static final String PROJECT_REPOSITORY_KIND = PROPERTY_PREFIX + ".kind";
103
104
	private static final String PROJECT_REPOSITORY_URL = PROPERTY_PREFIX + ".url";
105
106
	private static final String NAME_DATA_DIR = ".mylar";
97
	private static final String NAME_DATA_DIR = ".mylar";
107
98
108
	private static final char DEFAULT_PATH_SEPARATOR = '/';
99
	private static final char DEFAULT_PATH_SEPARATOR = '/';
Lines 133-138 Link Here
133
124
134
	private ArrayList<IHyperlinkDetector> hyperlinkDetectors = new ArrayList<IHyperlinkDetector>();
125
	private ArrayList<IHyperlinkDetector> hyperlinkDetectors = new ArrayList<IHyperlinkDetector>();
135
126
127
	private TreeSet<AbstractTaskRepositoryLinkProvider> repositoryLinkProviders = new TreeSet<AbstractTaskRepositoryLinkProvider>(new OrderComparator());
128
	
136
	private TaskListWriter taskListWriter;
129
	private TaskListWriter taskListWriter;
137
130
138
	private ITaskHighlighter highlighter;
131
	private ITaskHighlighter highlighter;
Lines 147-152 Link Here
147
140
148
	private boolean eclipse_3_3_workbench = false;
141
	private boolean eclipse_3_3_workbench = false;
149
142
143
	private static final class OrderComparator implements Comparator<AbstractTaskRepositoryLinkProvider> {
144
		public int compare(AbstractTaskRepositoryLinkProvider p1, AbstractTaskRepositoryLinkProvider p2) {
145
			return p1.getOrder()-p2.getOrder(); 
146
		}
147
	}
148
150
	public enum TaskListSaveMode {
149
	public enum TaskListSaveMode {
151
		ONE_HOUR, THREE_HOURS, DAY;
150
		ONE_HOUR, THREE_HOURS, DAY;
152
		@Override
151
		@Override
Lines 671-676 Link Here
671
			this.hyperlinkDetectors.add(listener);
670
			this.hyperlinkDetectors.add(listener);
672
	}
671
	}
673
672
673
	public void addRepositoryLinkProvider(AbstractTaskRepositoryLinkProvider repositoryLinkProvider) {
674
		if (repositoryLinkProvider != null)
675
			this.repositoryLinkProviders.add(repositoryLinkProvider);
676
	}
677
	
674
	public TaskListBackupManager getBackupManager() {
678
	public TaskListBackupManager getBackupManager() {
675
		return taskListBackupManager;
679
		return taskListBackupManager;
676
	}
680
	}
Lines 736-741 Link Here
736
		return getDataDirectory() + File.separator + TaskRepositoryManager.DEFAULT_REPOSITORIES_FILE;
740
		return getDataDirectory() + File.separator + TaskRepositoryManager.DEFAULT_REPOSITORIES_FILE;
737
	}
741
	}
738
742
743
	public boolean canSetRepositoryForResource(IResource resource) {
744
		if (resource == null) {
745
			return false;
746
		}
747
748
		for (AbstractTaskRepositoryLinkProvider linkProvider : repositoryLinkProviders) {
749
			TaskRepository repository = linkProvider.getTaskRepository(resource, getRepositoryManager());
750
			if (repository != null) {
751
				return linkProvider.canSetTaskRepository(resource);
752
			}
753
		}
754
		return false;
755
	}
756
739
	/**
757
	/**
740
	 * Associate a Task Repository with a workbench project
758
	 * Associate a Task Repository with a workbench project
741
	 * 
759
	 * 
Lines 746-766 Link Here
746
	 * @throws CoreException
764
	 * @throws CoreException
747
	 */
765
	 */
748
	public void setRepositoryForResource(IResource resource, TaskRepository repository) throws CoreException {
766
	public void setRepositoryForResource(IResource resource, TaskRepository repository) throws CoreException {
749
		if (resource == null || repository == null || !resource.getProject().isOpen()) {
767
		if (resource == null || repository == null) {
750
			return;
768
			return;
751
		}
769
		}
752
		IProject project = resource.getProject();
770
753
		if (project == null)
771
		for (AbstractTaskRepositoryLinkProvider linkProvider : repositoryLinkProviders) {
754
			return;
772
			TaskRepository r = linkProvider.getTaskRepository(resource, getRepositoryManager());
755
		IScopeContext projectScope = new ProjectScope(project);
773
			boolean canSetRepository = linkProvider.canSetTaskRepository(resource);
756
		IEclipsePreferences projectNode = projectScope.getNode(PLUGIN_ID);
774
			if (r != null && !canSetRepository) {
757
		if (projectNode != null) {
775
				return;
758
			projectNode.put(PROJECT_REPOSITORY_KIND, repository.getKind());
776
			}
759
			projectNode.put(PROJECT_REPOSITORY_URL, repository.getUrl());
777
			if (canSetRepository) {
760
			try {
778
				linkProvider.setTaskRepository(resource, repository);
761
				projectNode.flush();
779
				return;
762
			} catch (BackingStoreException e) {
763
				MylarStatusHandler.fail(e, "Failed to save task repository to project association preference", false);
764
			}
780
			}
765
		}
781
		}
766
	}
782
	}
Lines 770-794 Link Here
770
	 * project (or resource belonging to a project)
786
	 * project (or resource belonging to a project)
771
	 */
787
	 */
772
	public TaskRepository getRepositoryForResource(IResource resource, boolean silent) {
788
	public TaskRepository getRepositoryForResource(IResource resource, boolean silent) {
773
		if (resource == null)
789
		if (resource == null) {
774
			return null;
790
			return null;
775
		IProject project = resource.getProject();
791
		}
776
		if (project == null)
792
777
			return null;
793
		for (AbstractTaskRepositoryLinkProvider linkProvider : repositoryLinkProviders) {
778
		TaskRepository taskRepository = null;
794
			TaskRepository repository = linkProvider.getTaskRepository(resource, getRepositoryManager());
779
		IScopeContext projectScope = new ProjectScope(project);
795
			if (repository != null) {
780
		IEclipsePreferences projectNode = projectScope.getNode(PLUGIN_ID);
796
				return repository;
781
		if (projectNode != null) {
782
			String kind = projectNode.get(PROJECT_REPOSITORY_KIND, "");
783
			String urlString = projectNode.get(PROJECT_REPOSITORY_URL, "");
784
			taskRepository = getRepositoryManager().getRepository(kind, urlString);
785
			if (taskRepository == null && !silent) {
786
				MessageDialog
787
						.openInformation(null, "No Repository Found",
788
								"No repository was found. Associate a Task Repository with this project via the project's property page.");
789
			}
797
			}
790
		}
798
		}
791
		return taskRepository;
799
800
		if (!silent) {
801
			MessageDialog
802
					.openInformation(null, "No Repository Found",
803
							"No repository was found. Associate a Task Repository with this project via the project's property page.");
804
		}
805
806
		return null;
792
	}
807
	}
793
808
794
	public boolean isEclipse_3_3_workbench() {
809
	public boolean isEclipse_3_3_workbench() {
(-)src/org/eclipse/mylar/internal/tasks/ui/util/TasksUiExtensionReader.java (+31 lines)
Lines 28-33 Link Here
28
import org.eclipse.mylar.tasks.core.ITaskListExternalizer;
28
import org.eclipse.mylar.tasks.core.ITaskListExternalizer;
29
import org.eclipse.mylar.tasks.core.RepositoryTemplate;
29
import org.eclipse.mylar.tasks.core.RepositoryTemplate;
30
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
30
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
31
import org.eclipse.mylar.tasks.ui.AbstractTaskRepositoryLinkProvider;
31
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
32
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
32
import org.eclipse.mylar.tasks.ui.editors.ITaskEditorFactory;
33
import org.eclipse.mylar.tasks.ui.editors.ITaskEditorFactory;
33
import org.eclipse.ui.plugin.AbstractUIPlugin;
34
import org.eclipse.ui.plugin.AbstractUIPlugin;
Lines 41-46 Link Here
41
42
42
	public static final String EXTENSION_REPOSITORIES = "org.eclipse.mylar.tasks.ui.repositories";
43
	public static final String EXTENSION_REPOSITORIES = "org.eclipse.mylar.tasks.ui.repositories";
43
44
45
	public static final String EXTENSION_REPOSITORY_LINKS_PROVIDERS = "org.eclipse.mylar.tasks.ui.repositoryLinkProviders";
46
44
	public static final String EXTENSION_TEMPLATES = "org.eclipse.mylar.tasks.core.templates";
47
	public static final String EXTENSION_TEMPLATES = "org.eclipse.mylar.tasks.core.templates";
45
48
46
	public static final String EXTENSION_TMPL_REPOSITORY = "repository";
49
	public static final String EXTENSION_TMPL_REPOSITORY = "repository";
Lines 69-74 Link Here
69
72
70
	public static final String ELMNT_REPOSITORY_CONNECTOR = "connectorCore";
73
	public static final String ELMNT_REPOSITORY_CONNECTOR = "connectorCore";
71
74
75
	public static final String ELMNT_REPOSITORY_LINK_PROVIDER = "linkProvider";
76
	
72
	public static final String ELMNT_REPOSITORY_UI= "connectorUi";
77
	public static final String ELMNT_REPOSITORY_UI= "connectorUi";
73
	
78
	
74
	public static final String ELMNT_EXTERNALIZER = "externalizer";
79
	public static final String ELMNT_EXTERNALIZER = "externalizer";
Lines 174-181 Link Here
174
				} 
179
				} 
175
			}
180
			}
176
		}
181
		}
182
183
		IExtensionPoint linkProvidersExtensionPoint = registry.getExtensionPoint(EXTENSION_REPOSITORY_LINKS_PROVIDERS);
184
		IExtension[] linkProvidersExtensions = linkProvidersExtensionPoint.getExtensions();
185
		for (int i = 0; i < linkProvidersExtensions.length; i++) {
186
			IConfigurationElement[] elements = linkProvidersExtensions[i].getConfigurationElements();
187
			for (int j = 0; j < elements.length; j++) {
188
				if (elements[j].getName().equals(ELMNT_REPOSITORY_LINK_PROVIDER)) {
189
					readLinkProvider(elements[j]);
190
				} 
191
			}
192
		}
193
	
177
	}
194
	}
178
	
195
	
196
	private static void readLinkProvider(IConfigurationElement element) {
197
		try {
198
			Object repositoryLinkProvider = element.createExecutableExtension(ATTR_CLASS);
199
			if (repositoryLinkProvider instanceof AbstractTaskRepositoryLinkProvider) {
200
				TasksUiPlugin.getDefault().addRepositoryLinkProvider((AbstractTaskRepositoryLinkProvider) repositoryLinkProvider);
201
			} else {
202
				MylarStatusHandler.log("Could not load repository link provider: " + repositoryLinkProvider.getClass().getCanonicalName(),
203
						null);
204
			}
205
		} catch (CoreException e) {
206
			MylarStatusHandler.log(e, "Could not load repository link provider extension");
207
		}
208
	}
209
179
	private static void readHyperlinkDetector(IConfigurationElement element) {
210
	private static void readHyperlinkDetector(IConfigurationElement element) {
180
		try {
211
		try {
181
			Object hyperlinkDetector = element.createExecutableExtension(ATTR_CLASS);
212
			Object hyperlinkDetector = element.createExecutableExtension(ATTR_CLASS);
(-)schema/repositoryLinkProviders.exsd (+126 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.mylar.tasks.ui">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.mylar.tasks.ui" id="repositoryLinkProviders" name="Task Repository Link Provider"/>
7
      </appInfo>
8
      <documentation>
9
         Providers responsible for linking Workspace resources/projects to the Task Repositories.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence>
16
            <element ref="linkProvider"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="linkProvider">
46
      <complexType>
47
         <attribute name="id" type="string">
48
            <annotation>
49
               <documentation>
50
                  
51
               </documentation>
52
            </annotation>
53
         </attribute>
54
         <attribute name="name" type="string" use="required">
55
            <annotation>
56
               <documentation>
57
                  
58
               </documentation>
59
            </annotation>
60
         </attribute>
61
         <attribute name="class" type="string" use="required">
62
            <annotation>
63
               <documentation>
64
                  
65
               </documentation>
66
               <appInfo>
67
                  <meta.attribute kind="java" basedOn="org.eclipse.mylar.tasks.ui.AbstractTaskRepositoryLinkProvider"/>
68
               </appInfo>
69
            </annotation>
70
         </attribute>
71
         <attribute name="order" type="string" use="required">
72
            <annotation>
73
               <documentation>
74
                  
75
               </documentation>
76
            </annotation>
77
         </attribute>
78
      </complexType>
79
   </element>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="since"/>
84
      </appInfo>
85
      <documentation>
86
         [Enter the first release in which this extension point appears.]
87
      </documentation>
88
   </annotation>
89
90
   <annotation>
91
      <appInfo>
92
         <meta.section type="examples"/>
93
      </appInfo>
94
      <documentation>
95
         [Enter extension point usage example here.]
96
      </documentation>
97
   </annotation>
98
99
   <annotation>
100
      <appInfo>
101
         <meta.section type="apiInfo"/>
102
      </appInfo>
103
      <documentation>
104
         See org.eclipse.mylar.tasks.ui.TasksUiPlugin.getRepositoryForResource(IResource resource, boolean silent)
105
      </documentation>
106
   </annotation>
107
108
   <annotation>
109
      <appInfo>
110
         <meta.section type="implementation"/>
111
      </appInfo>
112
      <documentation>
113
         [Enter information about supplied implementation of this extension point.]
114
      </documentation>
115
   </annotation>
116
117
   <annotation>
118
      <appInfo>
119
         <meta.section type="copyright"/>
120
      </appInfo>
121
      <documentation>
122
         
123
      </documentation>
124
   </annotation>
125
126
</schema>
(-)src/org/eclipse/mylar/tasks/ui/AbstractTaskRepositoryLinkProvider.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 Mylar 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.mylar.tasks.ui;
10
11
import org.eclipse.core.resources.IResource;
12
import org.eclipse.core.runtime.IConfigurationElement;
13
import org.eclipse.core.runtime.IExecutableExtension;
14
import org.eclipse.mylar.tasks.core.TaskRepository;
15
import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
16
17
/**
18
 * Abstract Task Repository link provider
19
 * 
20
 * @author Eugene Kuleshov
21
 */
22
public abstract class AbstractTaskRepositoryLinkProvider implements IExecutableExtension {
23
24
	private static final int DEFAULT_ORDER = 1000;
25
	
26
	private String id;
27
	private String name;
28
	private int order;
29
30
	public void setInitializationData(IConfigurationElement config, String propertyName, Object data) {
31
		id = config.getAttribute("id");
32
		name = config.getAttribute("name");
33
		try {
34
			order = Integer.parseInt(config.getAttribute("order"));
35
		} catch(NumberFormatException ex) {
36
			order = DEFAULT_ORDER;
37
		}
38
	}
39
	
40
	public abstract TaskRepository getTaskRepository(IResource resource, TaskRepositoryManager repositoryManager);
41
	
42
	public boolean canSetTaskRepository(IResource resource) {
43
		return false;
44
	}
45
46
	public boolean setTaskRepository(IResource resource, TaskRepository repository) {
47
		return false;
48
	}
49
50
	public String getId() {
51
		return id;
52
	}
53
54
	public String getName() {
55
		return name;
56
	}
57
58
	public int getOrder() {
59
		return order;
60
	}
61
	
62
}
(-)src/org/eclipse/mylar/tasks/ui/DefaultTaskRepositoryLinkProvider.java (+76 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 Mylar 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.mylar.tasks.ui;
10
11
import org.eclipse.core.resources.IProject;
12
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.ProjectScope;
14
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
15
import org.eclipse.core.runtime.preferences.IScopeContext;
16
import org.eclipse.mylar.core.MylarStatusHandler;
17
import org.eclipse.mylar.tasks.core.TaskRepository;
18
import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
19
import org.osgi.service.prefs.BackingStoreException;
20
21
/**
22
 * Default Task Repository link provider
23
 * 
24
 * @author Eugene Kuleshov
25
 */
26
public class DefaultTaskRepositoryLinkProvider extends AbstractTaskRepositoryLinkProvider {
27
28
	private static final String PROPERTY_PREFIX = "project.repository";
29
30
	private static final String PROJECT_REPOSITORY_KIND = PROPERTY_PREFIX + ".kind";
31
32
	private static final String PROJECT_REPOSITORY_URL = PROPERTY_PREFIX + ".url";
33
34
	public TaskRepository getTaskRepository(IResource resource, TaskRepositoryManager repositoryManager) {
35
		IProject project = resource.getProject();
36
		if (project == null || !project.isAccessible()) {
37
			return null;
38
		}
39
40
		IScopeContext projectScope = new ProjectScope(project);
41
		IEclipsePreferences projectNode = projectScope.getNode(TasksUiPlugin.PLUGIN_ID);
42
		if (projectNode != null) {
43
			String kind = projectNode.get(PROJECT_REPOSITORY_KIND, "");
44
			String urlString = projectNode.get(PROJECT_REPOSITORY_URL, "");
45
			return repositoryManager.getRepository(kind, urlString);
46
		}
47
		return null;
48
	}
49
50
	public boolean canSetTaskRepository(IResource resource, TaskRepository repository) {
51
		IProject project = resource.getProject();
52
		return project != null && project.isAccessible();
53
	}
54
55
	public boolean setTaskRepository(IResource resource, TaskRepository repository) {
56
		IProject project = resource.getProject();
57
		if (project == null || !project.isAccessible()) {
58
			return false;
59
		}
60
		
61
		IScopeContext projectScope = new ProjectScope(project);
62
		IEclipsePreferences projectNode = projectScope.getNode(TasksUiPlugin.PLUGIN_ID);
63
		if (projectNode != null) {
64
			projectNode.put(PROJECT_REPOSITORY_KIND, repository.getKind());
65
			projectNode.put(PROJECT_REPOSITORY_URL, repository.getUrl());
66
			try {
67
				projectNode.flush();
68
				return true;
69
			} catch (BackingStoreException e) {
70
				MylarStatusHandler.fail(e, "Failed to save task repository to project association preference", false);
71
			}
72
		}
73
		return false;
74
	}
75
76
}

Return to bug 159135