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

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/jira/JiraFilter.java (-141 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.jira;
13
14
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryQuery;
15
import org.tigris.jira.core.model.NamedFilter;
16
17
/**
18
 * A JiraFilter represents a query for issues from a Jira repository.
19
 * 
20
 * @author Mik Kersten
21
 * @author Wesley Coelho (initial integration patch)
22
 */
23
public class JiraFilter extends AbstractRepositoryQuery {
24
25
//	private static final String LABEL_REFRESH_JOB = "Refreshing Jira Filter(s)";
26
27
	private static final int MAX_HITS = 75;
28
29
	protected NamedFilter filter = null;
30
31
//	private boolean isRefreshing = false;
32
33
	public JiraFilter(String repositoryUrl, NamedFilter filter) {
34
		setMaxHits(MAX_HITS);
35
		this.filter = filter;
36
		super.repositoryUrl = repositoryUrl;
37
		setQueryUrl(repositoryUrl + MylarJiraPlugin.FILTER_URL_PREFIX + filter.getId());
38
39
		super.setDescription(filter.getName());
40
	}
41
42
	public NamedFilter getNamedFilter() {
43
		return filter;
44
	}
45
46
//	/**
47
//	 * TODO: refactor into common refresh mechanism.
48
//	 */
49
//	public void refreshHits() {
50
//		isRefreshing = true;
51
//		Job j = new Job(LABEL_REFRESH_JOB) {
52
//
53
//			@Override
54
//			protected IStatus run(final IProgressMonitor monitor) {
55
//				clearHits();
56
//				try {
57
//					TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(MylarJiraPlugin.JIRA_REPOSITORY_KIND, repositoryUrl);
58
//					JiraServerFacade.getDefault().getJiraServer(repository).executeNamedFilter(filter, new IssueCollector() {
59
//
60
//						public void done() {
61
//							isRefreshing = false;
62
//							Display.getDefault().asyncExec(new Runnable() {
63
//								public void run() {
64
//									if (TaskListView.getDefault() != null)
65
//										TaskListView.getDefault().refreshAndFocus();
66
//								}
67
//							});
68
//						}
69
//
70
//						public boolean isCancelled() {
71
//							return monitor.isCanceled();
72
//						}
73
//
74
//						public void collectIssue(Issue issue) {
75
//							int issueId = new Integer(issue.getId());
76
//							JiraFilterHit hit = new JiraFilterHit(issue, JiraFilter.this.getRepositoryUrl(), issueId);
77
//							addHit(hit);
78
//						}
79
//
80
//						public void start() {
81
//
82
//						}
83
//					});
84
//
85
//				} catch (Exception e) {
86
//					isRefreshing = false;
87
//					JiraServerFacade.handleConnectionException(e);
88
//					return Status.CANCEL_STATUS;
89
//				}
90
//
91
//				return Status.OK_STATUS;
92
//			}
93
//
94
//		};
95
//
96
//		j.schedule();
97
//
98
//	}
99
100
	public String getQueryUrl() {
101
		return super.getQueryUrl();
102
	}
103
104
	public String getPriority() {
105
		return "";
106
	}
107
108
	public String getDescription() {
109
		if (filter.getName() != null) {
110
			return filter.getName();
111
		} else {
112
			return super.getDescription();
113
		}
114
	}
115
116
	public void setDescription(String description) {
117
		filter.setDescription(description);
118
	}
119
120
	public boolean isLocal() {
121
		return false;
122
	}
123
124
//	/** True if the filter is currently downloading hits */
125
//	public boolean isRefreshing() {
126
//		return isRefreshing;
127
//	}
128
129
	public String getRepositoryKind() {
130
		return MylarJiraPlugin.JIRA_REPOSITORY_KIND;
131
	}
132
133
	public NamedFilter getFilter() {
134
		return filter;
135
	}
136
137
//	public void setRefreshing(boolean refreshing) {
138
//		this.isRefreshing = refreshing;
139
//	}
140
141
}
(-)src/org/eclipse/mylar/internal/jira/JiraRepositoryConnector.java (-47 / +100 lines)
Lines 22-27 Link Here
22
import org.eclipse.jface.wizard.IWizard;
22
import org.eclipse.jface.wizard.IWizard;
23
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
23
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
24
import org.eclipse.mylar.internal.jira.ui.wizards.AddExistingJiraTaskWizard;
24
import org.eclipse.mylar.internal.jira.ui.wizards.AddExistingJiraTaskWizard;
25
import org.eclipse.mylar.internal.jira.ui.wizards.IssueFilterWizard;
25
import org.eclipse.mylar.internal.jira.ui.wizards.JiraRepositorySettingsPage;
26
import org.eclipse.mylar.internal.jira.ui.wizards.JiraRepositorySettingsPage;
26
import org.eclipse.mylar.internal.jira.ui.wizards.NewJiraQueryWizard;
27
import org.eclipse.mylar.internal.jira.ui.wizards.NewJiraQueryWizard;
27
import org.eclipse.mylar.internal.tasklist.ui.TaskListUiUtil;
28
import org.eclipse.mylar.internal.tasklist.ui.TaskListUiUtil;
Lines 84-90 Link Here
84
	}
85
	}
85
86
86
	public IWizard getQueryWizard(TaskRepository repository) {
87
	public IWizard getQueryWizard(TaskRepository repository) {
87
		return new NewJiraQueryWizard(repository);
88
//		return new NewJiraQueryWizard(repository);
89
		return new IssueFilterWizard(repository);
88
	}
90
	}
89
91
90
	public IWizard getAddExistingTaskWizard(TaskRepository repository) {
92
	public IWizard getAddExistingTaskWizard(TaskRepository repository) {
Lines 118-126 Link Here
118
120
119
	@Override
121
	@Override
120
	public void openEditQueryDialog(AbstractRepositoryQuery query) {
122
	public void openEditQueryDialog(AbstractRepositoryQuery query) {
121
		JiraFilter filter = (JiraFilter) query;
123
		if (query instanceof JiraNamedFilter) {
122
		String title = "Filter: " + filter.getDescription();
124
			JiraNamedFilter filter = (JiraNamedFilter) query;
123
		TaskListUiUtil.openUrl(title, title, filter.getQueryUrl());
125
			String title = "Filter: " + filter.getDescription();
126
			TaskListUiUtil.openUrl(title, title, filter.getQueryUrl());
127
		}
128
		// TODO support custom filters
124
	}
129
	}
125
130
126
//	public void refreshFilters() {
131
//	public void refreshFilters() {
Lines 162-212 Link Here
162
167
163
	@Override
168
	@Override
164
	protected List<AbstractQueryHit> performQuery(AbstractRepositoryQuery repositoryQuery, final IProgressMonitor monitor, MultiStatus queryStatus) {
169
	protected List<AbstractQueryHit> performQuery(AbstractRepositoryQuery repositoryQuery, final IProgressMonitor monitor, MultiStatus queryStatus) {
165
		if (!(repositoryQuery instanceof JiraFilter)) {
170
//		if (!(repositoryQuery instanceof JiraNamedFilter)) {
166
			return Collections.emptyList();
171
//			return Collections.emptyList();
167
		}
172
//		}
168
		final JiraFilter jiraFilter = (JiraFilter)repositoryQuery;
169
		final List<AbstractQueryHit> hits = new ArrayList<AbstractQueryHit>();
173
		final List<AbstractQueryHit> hits = new ArrayList<AbstractQueryHit>();
170
//		jiraFilter.setRefreshing(true);
174
		
171
		try {
175
		if (repositoryQuery instanceof JiraNamedFilter) {
172
			TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(MylarJiraPlugin.JIRA_REPOSITORY_KIND, repositoryQuery.getRepositoryUrl());
173
			JiraServerFacade.getDefault().getJiraServer(repository).executeNamedFilter(jiraFilter.getNamedFilter(), new IssueCollector() {
174
175
				public void done() {
176
//					jiraFilter.setRefreshing(false);
177
//					Display.getDefault().asyncExec(new Runnable() {
178
//						public void run() {
179
//							if (TaskListView.getDefault() != null)
180
//								TaskListView.getDefault().refreshAndFocus();
181
//						}
182
//					});
183
				}
184
185
				public boolean isCancelled() {
186
					return monitor.isCanceled();
187
				}
188
189
				public void collectIssue(Issue issue) {
190
					int issueId = new Integer(issue.getId());
191
					JiraFilterHit hit = new JiraFilterHit(issue, jiraFilter.getRepositoryUrl(), issueId);
192
					hits.add(hit);
193
//					addHit(hit);
194
				}
195
196
				public void start() {
197
198
				}
199
			});
200
201
		} catch (Exception e) {
202
//			isRefreshing = false;
203
//			jiraFilter.setRefreshing(false);
204
//			JiraServerFacade.handleConnectionException(e);
205
			queryStatus.add(new Status(IStatus.OK, MylarTaskListPlugin.PLUGIN_ID, IStatus.OK, 
206
					"Could not log in to server: " + repositoryQuery.getRepositoryUrl()
207
					+ "\n\nCheck network connection.", e));
208
//			queryStatus.add(Status.CANCEL_STATUS);
209
			
176
			
177
			final JiraNamedFilter jiraNamedFilter = (JiraNamedFilter)repositoryQuery;
178
	//		jiraFilter.setRefreshing(true);
179
			try {
180
				TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(MylarJiraPlugin.JIRA_REPOSITORY_KIND, repositoryQuery.getRepositoryUrl());
181
				JiraServerFacade.getDefault().getJiraServer(repository).executeNamedFilter(jiraNamedFilter.getNamedFilter(), new IssueCollector() {
182
	
183
					public void done() {
184
	//					jiraFilter.setRefreshing(false);
185
	//					Display.getDefault().asyncExec(new Runnable() {
186
	//						public void run() {
187
	//							if (TaskListView.getDefault() != null)
188
	//								TaskListView.getDefault().refreshAndFocus();
189
	//						}
190
	//					});
191
					}
192
	
193
					public boolean isCancelled() {
194
						return monitor.isCanceled();
195
					}
196
	
197
					public void collectIssue(Issue issue) {
198
						int issueId = new Integer(issue.getId());
199
						JiraFilterHit hit = new JiraFilterHit(issue, jiraNamedFilter.getRepositoryUrl(), issueId);
200
						hits.add(hit);
201
	//					addHit(hit);
202
					}
203
	
204
					public void start() {
205
	
206
					}
207
				});
208
	
209
			} catch (Exception e) {
210
	//			isRefreshing = false;
211
	//			jiraFilter.setRefreshing(false);
212
	//			JiraServerFacade.handleConnectionException(e);
213
				queryStatus.add(new Status(IStatus.OK, MylarTaskListPlugin.PLUGIN_ID, IStatus.OK, 
214
						"Could not log in to server: " + repositoryQuery.getRepositoryUrl()
215
						+ "\n\nCheck network connection.", e));
216
	//			queryStatus.add(Status.CANCEL_STATUS);
217
				
218
			}
219
		} else if (repositoryQuery instanceof JiraCustomFilter) {
220
			final JiraCustomFilter jiraCustomFilter = (JiraCustomFilter)repositoryQuery;
221
222
	//		jiraFilter.setRefreshing(true);
223
			try {
224
				TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(MylarJiraPlugin.JIRA_REPOSITORY_KIND, repositoryQuery.getRepositoryUrl());
225
				JiraServerFacade.getDefault().getJiraServer(repository).findIssues(jiraCustomFilter.getFilter(), new IssueCollector() {
226
	
227
					public void done() {
228
	//					jiraFilter.setRefreshing(false);
229
	//					Display.getDefault().asyncExec(new Runnable() {
230
	//						public void run() {
231
	//							if (TaskListView.getDefault() != null)
232
	//								TaskListView.getDefault().refreshAndFocus();
233
	//						}
234
	//					});
235
					}
236
	
237
					public boolean isCancelled() {
238
						return monitor.isCanceled();
239
					}
240
	
241
					public void collectIssue(Issue issue) {
242
						int issueId = new Integer(issue.getId());
243
						JiraFilterHit hit = new JiraFilterHit(issue, jiraCustomFilter.getRepositoryUrl(), issueId);
244
						hits.add(hit);
245
	//					addHit(hit);
246
					}
247
	
248
					public void start() {
249
	
250
					}
251
				});
252
	
253
			} catch (Exception e) {
254
	//			isRefreshing = false;
255
	//			jiraFilter.setRefreshing(false);
256
	//			JiraServerFacade.handleConnectionException(e);
257
				queryStatus.add(new Status(IStatus.OK, MylarTaskListPlugin.PLUGIN_ID, IStatus.OK, 
258
						"Could not log in to server: " + repositoryQuery.getRepositoryUrl()
259
						+ "\n\nCheck network connection.", e));
260
	//			queryStatus.add(Status.CANCEL_STATUS);
261
				
262
			}
210
		}
263
		}
211
		queryStatus.add(Status.OK_STATUS);
264
		queryStatus.add(Status.OK_STATUS);
212
		return hits;
265
		return hits;
(-)src/org/eclipse/mylar/internal/jira/JiraTaskExternalizer.java (-42 / +55 lines)
Lines 51-125 Link Here
51
	private static final String KEY_FILTER_ID = "FilterID";
51
	private static final String KEY_FILTER_ID = "FilterID";
52
52
53
	private static final String KEY_FILTER_DESCRIPTION = "FilterDesc";
53
	private static final String KEY_FILTER_DESCRIPTION = "FilterDesc";
54
	
55
	private static final String KEY_QUERY_TYPE = "QueryType";
54
56
55
	public boolean canReadQuery(Node node) {
57
	public boolean canReadQuery(Node node) {
56
		return node.getNodeName().equals(KEY_JIRA_QUERY);
58
		return node.getNodeName().equals(KEY_JIRA_QUERY);
57
	}
59
	}
58
60
59
	public boolean canCreateElementFor(AbstractRepositoryQuery category) {
61
	public boolean canCreateElementFor(AbstractRepositoryQuery category) {
60
		return category instanceof JiraFilter;
62
		return category instanceof JiraNamedFilter || category instanceof JiraCustomFilter;
61
	}
63
	}
62
64
63
	public boolean canCreateElementFor(ITask task) {
65
	public boolean canCreateElementFor(ITask task) {
64
		return task instanceof JiraTask;
66
		return task instanceof JiraTask;
65
	}
67
	}
66
68
69
	@Override
67
	public AbstractRepositoryQuery readQuery(Node node, TaskList taskList) throws TaskExternalizationException {
70
	public AbstractRepositoryQuery readQuery(Node node, TaskList taskList) throws TaskExternalizationException {
68
		boolean hasCaughtException = false;
71
		boolean hasCaughtException = false;
69
		Element element = (Element) node;
72
		Element element = (Element) node;
70
73
71
		NamedFilter namedFilter = new NamedFilter();
74
		String queryType = element.getAttribute(KEY_QUERY_TYPE);
72
		namedFilter.setId(element.getAttribute(KEY_FILTER_ID));
75
		if ("Custom".equals(queryType)) {
73
		namedFilter.setName(element.getAttribute(KEY_FILTER_NAME));
76
			return null;
74
//		namedFilter.setDescription(element.getAttribute(KEY_FILTER_DESCRIPTION));
77
		} else {
75
78
			NamedFilter namedFilter = new NamedFilter();
76
		AbstractRepositoryQuery query = new JiraFilter(element.getAttribute(KEY_REPOSITORY_URL), namedFilter);
79
			namedFilter.setId(element.getAttribute(KEY_FILTER_ID));
80
			namedFilter.setName(element.getAttribute(KEY_FILTER_NAME));
81
	//		namedFilter.setDescription(element.getAttribute(KEY_FILTER_DESCRIPTION));
82
	
83
			AbstractRepositoryQuery query = new JiraNamedFilter(element.getAttribute(KEY_REPOSITORY_URL), namedFilter);
77
		
84
		
78
		NodeList list = node.getChildNodes();
85
			NodeList list = node.getChildNodes();
79
		for (int i = 0; i < list.getLength(); i++) {
86
			for (int i = 0; i < list.getLength(); i++) {
80
			Node child = list.item(i);
87
				Node child = list.item(i);
81
			try {
88
				try {
82
				readQueryHit(child, taskList, query);
89
					readQueryHit(child, taskList, query);
83
			} catch (TaskExternalizationException e) {
90
				} catch (TaskExternalizationException e) {
84
				hasCaughtException = true;
91
					hasCaughtException = true;
92
				}
93
			}
94
			if (hasCaughtException) {
95
				throw new TaskExternalizationException("Failed to load all hits");
96
			} else {
97
				return query;
85
			}
98
			}
86
		}
99
		}
87
		if (hasCaughtException) {
100
		
88
			throw new TaskExternalizationException("Failed to load all hits");
89
		} else {
90
			return query;
91
		}
92
	}
101
	}
93
102
94
	public Element createQueryElement(AbstractRepositoryQuery query, Document doc, Element parent) {
103
	public Element createQueryElement(AbstractRepositoryQuery query, Document doc, Element parent) {
95
		String queryTagName = getQueryTagNameForElement(query);
104
		String queryTagName = getQueryTagNameForElement(query);
96
		Element node = doc.createElement(queryTagName);
105
		Element node = doc.createElement(queryTagName);
97
106
98
		NamedFilter filter = ((JiraFilter) query).getNamedFilter();
107
		if (query instanceof JiraNamedFilter) {
99
		node.setAttribute(KEY_NAME, query.getDescription());
108
			NamedFilter filter = ((JiraNamedFilter) query).getNamedFilter();
100
		node.setAttribute(KEY_QUERY_MAX_HITS, query.getMaxHits() + "");
109
			node.setAttribute(KEY_NAME, query.getDescription());
101
		node.setAttribute(KEY_QUERY_STRING, query.getQueryUrl());
110
			node.setAttribute(KEY_QUERY_MAX_HITS, query.getMaxHits() + "");
102
		node.setAttribute(KEY_REPOSITORY_URL, query.getRepositoryUrl());
111
			node.setAttribute(KEY_QUERY_STRING, query.getQueryUrl());
103
112
			node.setAttribute(KEY_REPOSITORY_URL, query.getRepositoryUrl());
104
		node.setAttribute(KEY_FILTER_ID, filter.getId());
113
	
105
		node.setAttribute(KEY_FILTER_NAME, filter.getName());
114
			node.setAttribute(KEY_FILTER_ID, filter.getId());
106
		node.setAttribute(KEY_FILTER_DESCRIPTION, filter.getDescription());
115
			node.setAttribute(KEY_FILTER_NAME, filter.getName());
107
116
			node.setAttribute(KEY_FILTER_DESCRIPTION, filter.getDescription());
108
		for (AbstractQueryHit hit : query.getHits()) {
117
	
109
			try {
118
			for (AbstractQueryHit hit : query.getHits()) {
110
				Element element = null;
119
				try {
111
				for (ITaskListExternalizer externalizer : super.getDelegateExternalizers()) {
120
					Element element = null;
112
					if (externalizer.canCreateElementFor(hit))
121
					for (ITaskListExternalizer externalizer : super.getDelegateExternalizers()) {
113
						element = externalizer.createQueryHitElement(hit, doc, node);
122
						if (externalizer.canCreateElementFor(hit))
123
							element = externalizer.createQueryHitElement(hit, doc, node);
124
					}
125
					if (element == null)
126
						createQueryHitElement(hit, doc, node);
127
				} catch (Exception e) {
128
					MylarStatusHandler.log(e, e.getMessage());
114
				}
129
				}
115
				if (element == null)
116
					createQueryHitElement(hit, doc, node);
117
			} catch (Exception e) {
118
				MylarStatusHandler.log(e, e.getMessage());
119
			}
130
			}
131
			parent.appendChild(node);
132
			return node;
133
		} else {
134
			return node;
120
		}
135
		}
121
		parent.appendChild(node);
122
		return node;
123
	}
136
	}
124
		
137
		
125
	@Override
138
	@Override
Lines 222-228 Link Here
222
	}
235
	}
223
236
224
	public String getQueryTagNameForElement(AbstractRepositoryQuery query) {
237
	public String getQueryTagNameForElement(AbstractRepositoryQuery query) {
225
		if (query instanceof JiraFilter) {
238
		if (query instanceof JiraNamedFilter || query instanceof JiraCustomFilter) {
226
			return KEY_JIRA_QUERY;
239
			return KEY_JIRA_QUERY;
227
		}
240
		}
228
		return "";
241
		return "";
(-).settings/org.eclipse.jdt.ui.prefs (-2 / +2 lines)
Lines 1-5 Link Here
1
#Thu Feb 09 16:45:35 PST 2006
1
#Sat Feb 18 09:21:28 EST 2006
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
formatter_profile=_Mylar based on Eclipse [built-in]
3
formatter_profile=_Mylar based on Eclipse [built-in]
4
formatter_settings_version=9
4
formatter_settings_version=10
5
internal.default.compliance=default
5
internal.default.compliance=default
(-)src/org/eclipse/mylar/internal/jira/ui/wizards/NewJiraQueryWizard.java (-2 / +2 lines)
Lines 12-18 Link Here
12
package org.eclipse.mylar.internal.jira.ui.wizards;
12
package org.eclipse.mylar.internal.jira.ui.wizards;
13
13
14
import org.eclipse.jface.wizard.Wizard;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.mylar.internal.jira.JiraFilter;
15
import org.eclipse.mylar.internal.jira.JiraNamedFilter;
16
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
16
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
17
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
17
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
18
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
18
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
Lines 48-54 Link Here
48
		NamedFilter namedFilter = queryPage.getSelectedFilter();
48
		NamedFilter namedFilter = queryPage.getSelectedFilter();
49
49
50
		if (namedFilter != null) {
50
		if (namedFilter != null) {
51
			JiraFilter filter = new JiraFilter(repository.getUrl().toExternalForm(), namedFilter);
51
			JiraNamedFilter filter = new JiraNamedFilter(repository.getUrl().toExternalForm(), namedFilter);
52
			MylarTaskListPlugin.getTaskListManager().addQuery(filter);
52
			MylarTaskListPlugin.getTaskListManager().addQuery(filter);
53
			AbstractRepositoryConnector connector = MylarTaskListPlugin.getRepositoryManager().getRepositoryConnector(repository.getKind());
53
			AbstractRepositoryConnector connector = MylarTaskListPlugin.getRepositoryManager().getRepositoryConnector(repository.getKind());
54
			if (connector != null) {
54
			if (connector != null) {
(-)src/org/eclipse/mylar/internal/jira/JiraCustomFilter.java (+138 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.jira;
13
14
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryQuery;
15
import org.tigris.jira.core.model.NamedFilter;
16
import org.tigris.jira.core.model.filter.FilterDefinition;
17
18
/**
19
 * A JiraFilter represents a query for issues from a Jira repository.
20
 * 
21
 * @author Mik Kersten
22
 * @author Wesley Coelho (initial integration patch)
23
 */
24
public class JiraCustomFilter extends AbstractRepositoryQuery {
25
26
//	private static final String LABEL_REFRESH_JOB = "Refreshing Jira Filter(s)";
27
28
	private static final int MAX_HITS = 75;
29
30
	protected FilterDefinition filter = null;
31
32
//	private boolean isRefreshing = false;
33
34
	public JiraCustomFilter(String repositoryUrl, FilterDefinition filter) {
35
		setMaxHits(MAX_HITS);
36
		this.filter = filter;
37
		super.repositoryUrl = repositoryUrl;
38
		setQueryUrl(repositoryUrl + MylarJiraPlugin.FILTER_URL_PREFIX + filter.getName());
39
40
		super.setDescription(filter.getName());
41
	}
42
43
	public FilterDefinition getFilter() {
44
		return filter;
45
	}
46
47
//	/**
48
//	 * TODO: refactor into common refresh mechanism.
49
//	 */
50
//	public void refreshHits() {
51
//		isRefreshing = true;
52
//		Job j = new Job(LABEL_REFRESH_JOB) {
53
//
54
//			@Override
55
//			protected IStatus run(final IProgressMonitor monitor) {
56
//				clearHits();
57
//				try {
58
//					TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(MylarJiraPlugin.JIRA_REPOSITORY_KIND, repositoryUrl);
59
//					JiraServerFacade.getDefault().getJiraServer(repository).executeNamedFilter(filter, new IssueCollector() {
60
//
61
//						public void done() {
62
//							isRefreshing = false;
63
//							Display.getDefault().asyncExec(new Runnable() {
64
//								public void run() {
65
//									if (TaskListView.getDefault() != null)
66
//										TaskListView.getDefault().refreshAndFocus();
67
//								}
68
//							});
69
//						}
70
//
71
//						public boolean isCancelled() {
72
//							return monitor.isCanceled();
73
//						}
74
//
75
//						public void collectIssue(Issue issue) {
76
//							int issueId = new Integer(issue.getId());
77
//							JiraFilterHit hit = new JiraFilterHit(issue, JiraFilter.this.getRepositoryUrl(), issueId);
78
//							addHit(hit);
79
//						}
80
//
81
//						public void start() {
82
//
83
//						}
84
//					});
85
//
86
//				} catch (Exception e) {
87
//					isRefreshing = false;
88
//					JiraServerFacade.handleConnectionException(e);
89
//					return Status.CANCEL_STATUS;
90
//				}
91
//
92
//				return Status.OK_STATUS;
93
//			}
94
//
95
//		};
96
//
97
//		j.schedule();
98
//
99
//	}
100
101
	public String getQueryUrl() {
102
		return super.getQueryUrl();
103
	}
104
105
	public String getPriority() {
106
		return "";
107
	}
108
109
	public String getDescription() {
110
		if (filter.getName() != null) {
111
			return filter.getName();
112
		} else {
113
			return super.getDescription();
114
		}
115
	}
116
117
	public void setDescription(String description) {
118
		filter.setDescription(description);
119
	}
120
121
	public boolean isLocal() {
122
		return false;
123
	}
124
125
//	/** True if the filter is currently downloading hits */
126
//	public boolean isRefreshing() {
127
//		return isRefreshing;
128
//	}
129
130
	public String getRepositoryKind() {
131
		return MylarJiraPlugin.JIRA_REPOSITORY_KIND;
132
	}
133
134
//	public void setRefreshing(boolean refreshing) {
135
//		this.isRefreshing = refreshing;
136
//	}
137
138
}
(-)src/org/eclipse/mylar/internal/jira/ui/wizards/IssueFilterWizard.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 Jira Dashboard project.
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
 *    Brock Janiczak - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.jira.ui.wizards;
12
13
import org.eclipse.jface.wizard.Wizard;
14
import org.eclipse.mylar.internal.jira.JiraCustomFilter;
15
import org.eclipse.mylar.internal.jira.JiraNamedFilter;
16
import org.eclipse.mylar.internal.jira.JiraServerFacade;
17
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
18
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
19
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
20
import org.tigris.jira.core.model.filter.FilterDefinition;
21
import org.tigris.jira.core.service.JiraServer;
22
23
24
// TODO this should be two different wizards (create and update)
25
public class IssueFilterWizard extends Wizard {
26
27
	private FilterSummaryPage filterSummaryPage;
28
	private final JiraServer server;
29
	private FilterDefinition workingCopy;
30
	private final boolean isAdd;
31
	private FilterDefinition filter;
32
	private IssueAttributesPage issueAttributesPage;
33
	private final TaskRepository repository;
34
	
35
	public IssueFilterWizard(TaskRepository repository) {
36
		this.repository = repository;
37
		// TODO this is most likely not a cool thing to be doing
38
		this.server = JiraServerFacade.getDefault().getJiraServer(repository);
39
		workingCopy = new FilterDefinition();
40
		this.setWindowTitle("Create Issue Filter");
41
		isAdd = true;
42
	}
43
	
44
	public IssueFilterWizard(TaskRepository repository, FilterDefinition filter) {
45
		this.repository = repository;
46
		// TODO this is most likely not a cool thing to be doing
47
		this.server = JiraServerFacade.getDefault().getJiraServer(repository);
48
		this.filter = filter;
49
		workingCopy = new FilterDefinition(filter);
50
		this.setWindowTitle("Create Issue Filter");
51
		isAdd = false;
52
	}
53
	
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
56
	 */
57
	public void addPages() {
58
		filterSummaryPage = new FilterSummaryPage("summaryPage", "Filter Summary", null, server, workingCopy, isAdd);
59
		issueAttributesPage = new IssueAttributesPage("issueAttributes", "Issue Attributes", null, server, workingCopy, isAdd);
60
		
61
		addPage(filterSummaryPage);
62
		addPage(issueAttributesPage);
63
		
64
	}
65
	
66
	public boolean performFinish() {
67
		if (isAdd) {
68
			filterSummaryPage.applyChanges();
69
			issueAttributesPage.applyChanges();
70
			server.addLocalFilter(workingCopy);
71
			
72
			JiraCustomFilter customFilter = new JiraCustomFilter(repository.getUrl().toExternalForm(), workingCopy);
73
			MylarTaskListPlugin.getTaskListManager().addQuery(customFilter);
74
			AbstractRepositoryConnector connector = MylarTaskListPlugin.getRepositoryManager().getRepositoryConnector(repository.getKind());
75
			if (connector != null) {
76
				connector.synchronize(customFilter, null);
77
			}
78
//				filter.refreshHits();
79
		} else {
80
			filterSummaryPage.applyChanges();
81
			issueAttributesPage.applyChanges();
82
			filter.copyAttributes(workingCopy);
83
			
84
			JiraCustomFilter customFilter = new JiraCustomFilter(repository.getUrl().toExternalForm(), workingCopy);
85
			MylarTaskListPlugin.getTaskListManager().addQuery(customFilter);
86
			AbstractRepositoryConnector connector = MylarTaskListPlugin.getRepositoryManager().getRepositoryConnector(repository.getKind());
87
			if (connector != null) {
88
				connector.synchronize(customFilter, null);
89
			}
90
//				filter.refreshHits();
91
		}
92
		return true;
93
	}
94
95
}
(-)src/org/eclipse/mylar/internal/jira/ui/wizards/FilterSummaryPage.java (+723 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 Jira Dashboard project.
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
 *    Brock Janiczak - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.jira.ui.wizards;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.viewers.ComboViewer;
19
import org.eclipse.jface.viewers.IColorProvider;
20
import org.eclipse.jface.viewers.ILabelProvider;
21
import org.eclipse.jface.viewers.ILabelProviderListener;
22
import org.eclipse.jface.viewers.ISelectionChangedListener;
23
import org.eclipse.jface.viewers.IStructuredContentProvider;
24
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.jface.viewers.LabelProvider;
26
import org.eclipse.jface.viewers.ListViewer;
27
import org.eclipse.jface.viewers.SelectionChangedEvent;
28
import org.eclipse.jface.viewers.StructuredSelection;
29
import org.eclipse.jface.viewers.Viewer;
30
import org.eclipse.jface.wizard.WizardPage;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.events.FocusAdapter;
33
import org.eclipse.swt.events.FocusEvent;
34
import org.eclipse.swt.events.SelectionAdapter;
35
import org.eclipse.swt.events.SelectionEvent;
36
import org.eclipse.swt.graphics.Color;
37
import org.eclipse.swt.graphics.Image;
38
import org.eclipse.swt.layout.GridData;
39
import org.eclipse.swt.layout.GridLayout;
40
import org.eclipse.swt.widgets.Button;
41
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Text;
45
import org.tigris.jira.core.model.Component;
46
import org.tigris.jira.core.model.Project;
47
import org.tigris.jira.core.model.Version;
48
import org.tigris.jira.core.model.filter.ComponentFilter;
49
import org.tigris.jira.core.model.filter.ContentFilter;
50
import org.tigris.jira.core.model.filter.FilterDefinition;
51
import org.tigris.jira.core.model.filter.ProjectFilter;
52
import org.tigris.jira.core.model.filter.VersionFilter;
53
import org.tigris.jira.core.service.JiraServer;
54
55
public class FilterSummaryPage extends WizardPage {
56
	private final Placeholder ANY_FIX_VERSION = new Placeholder("Any");
57
	private final Placeholder NO_FIX_VERSION = new Placeholder("No Fix Version");
58
	
59
	private final Placeholder ANY_REPORTED_VERSION = new Placeholder("Any");
60
	private final Placeholder NO_REPORTED_VERSION = new Placeholder("No Version");
61
	private final Placeholder UNRELEASED_VERSION = new Placeholder("Unreleased Versions");
62
	private final Placeholder RELEASED_VERSION = new Placeholder("Released Versions");
63
	
64
	private final Placeholder ANY_COMPONENT = new Placeholder("Any");
65
	private final Placeholder NO_COMPONENT = new Placeholder("No Component");
66
	
67
	private final JiraServer server;
68
	private ListViewer reportedIn;
69
	private ListViewer components;
70
	private ListViewer fixFor;
71
	
72
	private final FilterDefinition workingCopy;
73
	private Text name;
74
	private Text description;
75
	private ComboViewer project;
76
	private Text queryString;
77
	private Button searchSummary;
78
	private Button searchDescription;
79
	private Button searchComments;
80
	private Button searchEnvironment;
81
	private final boolean isNew;
82
	
83
	/**
84
	 * @param pageName
85
	 * @param title
86
	 * @param titleImage
87
	 */
88
	protected FilterSummaryPage(String pageName, String title, ImageDescriptor titleImage, JiraServer server, FilterDefinition workingCopy, boolean isNew) {
89
		super(pageName, title, titleImage);
90
		this.server = server;
91
		this.workingCopy = workingCopy;
92
		this.isNew = isNew;
93
	}
94
95
	public void createControl(Composite parent) {
96
		GridData gd;
97
		Composite c = new Composite(parent, SWT.NONE);
98
		c.setLayout(new GridLayout(3, false));
99
		
100
		Label lblName = new Label(c, SWT.NONE);
101
		lblName.setText("Name:");
102
		
103
		name = new Text(c, SWT.BORDER);
104
		name.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
105
		name.addFocusListener(new FocusAdapter() {
106
			
107
			public void focusLost(FocusEvent e) {
108
				validatePage();
109
			}
110
		
111
		});
112
		
113
		if (!isNew) {
114
			name.setEnabled(false);
115
		}
116
		
117
		Label lblDescription = new Label(c, SWT.NONE);
118
		lblDescription.setText("Description:");
119
		lblDescription.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
120
		
121
		description = new Text(c, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
122
		gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
123
		gd.heightHint = 40;
124
		description.setLayoutData(gd);
125
		description.addFocusListener(new FocusAdapter() {
126
			
127
			public void focusLost(FocusEvent e) {
128
				validatePage();
129
			}
130
		
131
		});
132
		
133
		Label lblProject = new Label(c, SWT.NONE);
134
		lblProject.setText("Project:");
135
		
136
		project = new ComboViewer(c, SWT.READ_ONLY);
137
		project.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
138
		project.setContentProvider(new IStructuredContentProvider() {
139
		
140
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
141
			}
142
		
143
			public void dispose() {
144
			}
145
		
146
			public Object[] getElements(Object inputElement) {
147
				JiraServer server = (JiraServer) inputElement;
148
				Object[] elements = new Object[server.getProjects().length + 1];
149
				elements[0] = new Placeholder("All Projects");
150
				System.arraycopy(server.getProjects(), 0, elements, 1, server.getProjects().length);
151
				
152
				return elements;
153
			}
154
		
155
		});
156
		
157
		project.setLabelProvider(new LabelProvider() {
158
		
159
			public String getText(Object element) {
160
				if (element instanceof Placeholder) {
161
					return ((Placeholder)element).getText();
162
				}
163
				
164
				return ((Project)element).getName();
165
			}
166
		
167
		});
168
		
169
		project.setInput(server);
170
		project.addSelectionChangedListener(new ISelectionChangedListener() {
171
		
172
			public void selectionChanged(SelectionChangedEvent event) {
173
				IStructuredSelection selection = ((IStructuredSelection)event.getSelection());
174
				Project selectedProject = null;
175
				if (!selection.isEmpty() && !(selection.getFirstElement() instanceof Placeholder)) {
176
					selectedProject = (Project)selection.getFirstElement();
177
				}
178
				
179
				updateCurrentProject(selectedProject);
180
				validatePage();
181
			}
182
		
183
		});
184
		
185
		Label lblFixFor = new Label(c, SWT.NONE);
186
		lblFixFor.setText("Fix For:");
187
		lblFixFor.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
188
		
189
		fixFor = new ListViewer(c, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
190
		gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
191
		gd.heightHint = 40;
192
		fixFor.getControl().setLayoutData(gd);
193
		
194
		fixFor.setContentProvider(new IStructuredContentProvider() {
195
			private Project project;
196
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
197
				project = (Project)newInput;
198
			}
199
		
200
			public void dispose() {
201
			}
202
		
203
			public Object[] getElements(Object inputElement) {
204
				if (project != null) {
205
					Version[] versions = project.getVersions();
206
					Version[] releasedVersions = project.getReleasedVersions();
207
					Version[] unreleasedVersions = project.getUnreleasedVersions();
208
					
209
					Object[] elements = new Object[versions.length + 4];
210
					elements[0] = ANY_FIX_VERSION;
211
					elements[1] = NO_FIX_VERSION;
212
					elements[2] = RELEASED_VERSION;
213
					System.arraycopy(releasedVersions, 0, elements, 3, releasedVersions.length);
214
					
215
					elements[releasedVersions.length + 3] = UNRELEASED_VERSION;
216
					
217
					System.arraycopy(unreleasedVersions, 0, elements, releasedVersions.length + 4, unreleasedVersions.length);
218
					return elements;
219
				} else {
220
					return new Object[] {ANY_REPORTED_VERSION};
221
				}
222
			}
223
		
224
		});
225
		fixFor.setLabelProvider(new VersionLabelProvider());
226
		fixFor.setInput(null);
227
228
		Label lblComponent = new Label(c, SWT.NONE);
229
		lblComponent.setText("In Components:");
230
		lblComponent.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
231
232
		components = new ListViewer(c, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
233
		gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
234
		gd.heightHint = 40;
235
		components.getControl().setLayoutData(gd);
236
		
237
		components.setContentProvider(new IStructuredContentProvider() {
238
			private Project project;
239
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
240
				project = (Project)newInput;
241
			}
242
		
243
			public void dispose() {
244
			}
245
		
246
			public Object[] getElements(Object inputElement) {
247
				if (project != null) {
248
					Component[] components = project.getComponents();
249
					
250
					Object[] elements = new Object[components.length + 2];
251
					elements[0] = ANY_COMPONENT;
252
					elements[1] = NO_COMPONENT;
253
					System.arraycopy(components, 0, elements, 2, components.length);
254
					return elements;
255
				} else {
256
					return new Object[] {ANY_COMPONENT};
257
				}
258
				
259
			}
260
		
261
		});
262
		components.setLabelProvider(new ComponentLabelProvider());
263
		components.setInput(null);
264
		
265
		Label lblReportedIn = new Label(c, SWT.NONE);
266
		lblReportedIn.setText("Reported In:");
267
		lblReportedIn.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
268
		
269
		reportedIn = new ListViewer(c, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
270
		gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
271
		gd.heightHint = 40;
272
		reportedIn.getControl().setLayoutData(gd);
273
		
274
		reportedIn.setContentProvider(new IStructuredContentProvider() {
275
			private Project project;
276
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
277
				project = (Project)newInput;
278
			}
279
		
280
			public void dispose() {
281
			}
282
		
283
			public Object[] getElements(Object inputElement) {
284
				if (project != null) {
285
					Version[] versions = project.getVersions();
286
					Version[] releasedVersions = project.getReleasedVersions();
287
					Version[] unreleasedVersions = project.getUnreleasedVersions();
288
					
289
					Object[] elements = new Object[versions.length + 4];
290
					elements[0] = ANY_REPORTED_VERSION;
291
					elements[1] = NO_REPORTED_VERSION;
292
					elements[2] = RELEASED_VERSION;
293
					System.arraycopy(releasedVersions, 0, elements, 3, releasedVersions.length);
294
					
295
					elements[releasedVersions.length + 3] = UNRELEASED_VERSION;
296
					
297
					System.arraycopy(unreleasedVersions, 0, elements, releasedVersions.length + 4, unreleasedVersions.length);
298
					return elements;
299
				} else {
300
					return new Object[] {ANY_REPORTED_VERSION};
301
				}
302
				
303
			}
304
		
305
		});
306
		reportedIn.setLabelProvider(new VersionLabelProvider());
307
		reportedIn.setInput(null);
308
		
309
		Label lblQuery = new Label(c, SWT.NONE);
310
		lblQuery.setText("Query:");
311
		queryString = new Text(c, SWT.BORDER);
312
		queryString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
313
		// TODO put content assist here and a label describing what is available
314
		
315
		queryString.addFocusListener(new FocusAdapter() {
316
			
317
			public void focusLost(FocusEvent e) {
318
				validatePage();
319
			}
320
		
321
		});
322
		
323
		Label lblFields = new Label(c, SWT.NONE);
324
		lblFields.setText("Fields:");
325
		lblFields.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 2));
326
		
327
		searchSummary = new Button(c, SWT.CHECK);
328
		searchSummary.setText("Summary");
329
		searchSummary.addSelectionListener(new SelectionAdapter() {
330
		
331
			public void widgetSelected(SelectionEvent e) {
332
				validatePage();
333
			}
334
		
335
		});
336
		
337
		searchDescription = new Button(c, SWT.CHECK);
338
		searchDescription.setText("Description");
339
		searchDescription.addSelectionListener(new SelectionAdapter() {
340
		
341
			public void widgetSelected(SelectionEvent e) {
342
				validatePage();
343
			}
344
		
345
		});
346
	
347
		searchComments = new Button(c, SWT.CHECK);
348
		searchComments.setText("Comments");
349
		searchComments.addSelectionListener(new SelectionAdapter() {
350
		
351
			public void widgetSelected(SelectionEvent e) {
352
				validatePage();
353
			}
354
		
355
		});
356
		
357
		searchEnvironment = new Button(c, SWT.CHECK);
358
		searchEnvironment.setText("Environment");
359
		searchEnvironment.addSelectionListener(new SelectionAdapter() {
360
		
361
			public void widgetSelected(SelectionEvent e) {
362
				validatePage();
363
			}
364
		
365
		});
366
367
		// Need to turn off validation here
368
		if (isNew) {
369
			loadFromDefaults();
370
		} else {
371
			loadFromWorkingCopy();
372
		}
373
		
374
		setControl(c);
375
	}
376
	
377
	private void updateCurrentProject(Project project) {
378
		this.fixFor.setInput(project);
379
		this.components.setInput(project);
380
		this.reportedIn.setInput(project);
381
		
382
	}
383
	
384
	private void validatePage() {
385
		if (name.getText().length() == 0) {
386
			setErrorMessage("Name is mandatory");
387
			setPageComplete(false);
388
			return;
389
		}
390
		
391
		setErrorMessage(null);
392
		setPageComplete(true);
393
	}
394
	
395
	private void loadFromDefaults() {
396
		project.setSelection(new StructuredSelection(new Placeholder("All Projects")));
397
		searchSummary.setSelection(true);
398
		searchDescription.setSelection(true);
399
	}
400
	
401
	private void loadFromWorkingCopy() {
402
		if (workingCopy.getName() != null) {
403
			name.setText(workingCopy.getName());
404
		}
405
		
406
		if (workingCopy.getDescription() != null) {
407
			description.setText(workingCopy.getDescription());
408
		}
409
		
410
		if (workingCopy.getProjectFilter() != null) {
411
			project.setSelection(new StructuredSelection(workingCopy.getProjectFilter().getProject()));
412
		} else {
413
			project.setSelection(new StructuredSelection(new Placeholder("All Projects")));
414
		}
415
		
416
		if (workingCopy.getFixForVersionFilter() != null) {
417
			if (workingCopy.getFixForVersionFilter().hasNoVersion()) {
418
				fixFor.setSelection(new StructuredSelection(new Object[] {NO_FIX_VERSION}));
419
			} else if (workingCopy.getFixForVersionFilter().isReleasedVersions() && workingCopy.getFixForVersionFilter().isUnreleasedVersions()) {
420
				fixFor.setSelection(new StructuredSelection(new Object[] {RELEASED_VERSION, UNRELEASED_VERSION}));
421
			} else if (workingCopy.getFixForVersionFilter().isReleasedVersions()) {
422
				fixFor.setSelection(new StructuredSelection(RELEASED_VERSION));
423
			} else if (workingCopy.getFixForVersionFilter().isUnreleasedVersions()) {
424
				fixFor.setSelection(new StructuredSelection(UNRELEASED_VERSION));
425
			} else {
426
				fixFor.setSelection(new StructuredSelection(workingCopy.getFixForVersionFilter().getVersions()));
427
			}
428
		} else {
429
			fixFor.setSelection(new StructuredSelection(ANY_FIX_VERSION));
430
		}
431
		
432
		if (workingCopy.getReportedInVersionFilter() != null) {
433
			if (workingCopy.getReportedInVersionFilter().hasNoVersion()) {
434
				reportedIn.setSelection(new StructuredSelection(new Object[] {NO_REPORTED_VERSION}));
435
			} else if (workingCopy.getReportedInVersionFilter().isReleasedVersions() && workingCopy.getReportedInVersionFilter().isUnreleasedVersions()) {
436
				reportedIn.setSelection(new StructuredSelection(new Object[] {RELEASED_VERSION, UNRELEASED_VERSION}));
437
			} else if (workingCopy.getReportedInVersionFilter().isReleasedVersions()) {
438
				reportedIn.setSelection(new StructuredSelection(RELEASED_VERSION));
439
			} else if (workingCopy.getReportedInVersionFilter().isUnreleasedVersions()) {
440
				reportedIn.setSelection(new StructuredSelection(UNRELEASED_VERSION));
441
			} else {
442
				reportedIn.setSelection(new StructuredSelection(workingCopy.getReportedInVersionFilter().getVersions()));
443
			}
444
		} else {
445
			reportedIn.setSelection(new StructuredSelection(ANY_REPORTED_VERSION));
446
		}
447
		
448
		if (workingCopy.getContentFilter() != null) {
449
			this.queryString.setText(workingCopy.getContentFilter().getQueryString());
450
			this.searchComments.setSelection(workingCopy.getContentFilter().isSearchingComments());
451
			this.searchDescription.setSelection(workingCopy.getContentFilter().isSearchingDescription());
452
			this.searchEnvironment.setSelection(workingCopy.getContentFilter().isSearchingEnvironment());
453
			this.searchSummary.setSelection(workingCopy.getContentFilter().isSearchingSummary());
454
		}
455
		
456
		if (workingCopy.getComponentFilter() != null) {
457
			if (workingCopy.getComponentFilter().hasNoComponent()) {
458
				components.setSelection(new StructuredSelection(NO_COMPONENT));
459
			} else {
460
				components.setSelection(new StructuredSelection(workingCopy.getComponentFilter().getComponents()));
461
			}
462
		} else {
463
			components.setSelection(new StructuredSelection(ANY_COMPONENT));
464
		}
465
	}
466
	
467
	/* default */ void applyChanges() {
468
		workingCopy.setName(this.name.getText());
469
		workingCopy.setDescription(this.description.getText());
470
		if (this.queryString.getText().length() > 0 || this.searchSummary.getSelection() || this.searchDescription.getSelection() || this.searchEnvironment.getSelection() || this.searchComments.getSelection()) { 
471
			workingCopy.setContentFilter(new ContentFilter(this.queryString.getText(), this.searchSummary.getSelection(), this.searchDescription.getSelection(), this.searchEnvironment.getSelection(), this.searchComments.getSelection()));
472
		} else {
473
			workingCopy.setContentFilter(null);
474
		}
475
		
476
		IStructuredSelection projectSelection = (IStructuredSelection)this.project.getSelection();
477
		if (!projectSelection.isEmpty() && projectSelection.getFirstElement() instanceof Project) {
478
			workingCopy.setProjectFilter(new ProjectFilter((Project) projectSelection.getFirstElement()));
479
		} else {
480
			workingCopy.setProjectFilter(null);
481
		}
482
		
483
		IStructuredSelection reportedInSelection = (IStructuredSelection)reportedIn.getSelection();
484
		if (reportedInSelection.isEmpty()) {
485
			workingCopy.setReportedInVersionFilter(null);
486
		} else {
487
			boolean selectionContainsReleased = false;
488
			boolean selectionContainsUnreleased = false;
489
			boolean selectionContainsAll = false;
490
			boolean selectionContainsNone = false;
491
			
492
			List selectedVersions = new ArrayList();
493
			
494
			for (Iterator i = reportedInSelection.iterator(); i.hasNext(); ) {
495
				Object selection = i.next();
496
				if (ANY_REPORTED_VERSION.equals(selection)) {
497
					selectionContainsAll = true;
498
				} else if (NO_REPORTED_VERSION.equals(selection)) {
499
					selectionContainsNone = true;
500
				} else if (RELEASED_VERSION.equals(selection)) {
501
					selectionContainsReleased = true;
502
				} else if (UNRELEASED_VERSION.equals(selection)) {
503
					selectionContainsUnreleased = true;
504
				} else if (selection instanceof Version) {
505
					selectedVersions.add(selection);
506
				}
507
			}
508
			
509
			if (selectionContainsAll) {
510
				workingCopy.setReportedInVersionFilter(null);
511
			} else if (selectionContainsNone) {
512
				workingCopy.setReportedInVersionFilter(new VersionFilter(new Version[0]));
513
			} else if (selectionContainsReleased || selectionContainsUnreleased) {
514
				workingCopy.setReportedInVersionFilter(new VersionFilter(selectionContainsReleased, selectionContainsUnreleased));
515
			} else if (selectedVersions.size() > 0) {
516
				workingCopy.setReportedInVersionFilter(new VersionFilter((Version[]) selectedVersions.toArray(new Version[selectedVersions.size()])));
517
			} else {
518
				workingCopy.setReportedInVersionFilter(null);
519
			}
520
		}
521
		
522
		IStructuredSelection fixForSelection = (IStructuredSelection)fixFor.getSelection();
523
		if (fixForSelection.isEmpty()) {
524
			workingCopy.setFixForVersionFilter(null);
525
		} else {
526
			boolean selectionContainsReleased = false;
527
			boolean selectionContainsUnreleased = false;
528
			boolean selectionContainsAll = false;
529
			boolean selectionContainsNone = false;
530
			
531
			List selectedVersions = new ArrayList();
532
			
533
			for (Iterator i = fixForSelection.iterator(); i.hasNext(); ) {
534
				Object selection = i.next();
535
				if (ANY_FIX_VERSION.equals(selection)) {
536
					selectionContainsAll = true;
537
				} else if (NO_FIX_VERSION.equals(selection)) {
538
					selectionContainsNone = true;
539
				} else if (RELEASED_VERSION.equals(selection)) {
540
					selectionContainsReleased = true;
541
				} else if (UNRELEASED_VERSION.equals(selection)) {
542
					selectionContainsUnreleased = true;
543
				} else if (selection instanceof Version) {
544
					selectedVersions.add(selection);
545
				}
546
			}
547
			
548
			if (selectionContainsAll) {
549
				workingCopy.setFixForVersionFilter(null);
550
			} else if (selectionContainsNone) {
551
				workingCopy.setFixForVersionFilter(new VersionFilter(new Version[0]));
552
			} else if (selectionContainsReleased || selectionContainsUnreleased) {
553
				workingCopy.setFixForVersionFilter(new VersionFilter(selectionContainsReleased, selectionContainsUnreleased));
554
			} else if (selectedVersions.size() > 0) {
555
				workingCopy.setFixForVersionFilter(new VersionFilter((Version[]) selectedVersions.toArray(new Version[selectedVersions.size()])));
556
			} else {
557
				workingCopy.setFixForVersionFilter(null);
558
			}
559
		}
560
		
561
		IStructuredSelection componentsSelection = (IStructuredSelection)components.getSelection();
562
		if (componentsSelection.isEmpty()) {
563
			workingCopy.setComponentFilter(null);
564
		} else {
565
		
566
			boolean selectionContainsAll = false;
567
			boolean selectionContainsNone = false;
568
			List selectedComponents = new ArrayList();
569
			
570
			for (Iterator i = componentsSelection.iterator(); i.hasNext(); ) {
571
				Object selection = i.next();
572
				if (ANY_COMPONENT.equals(selection)) {
573
					selectionContainsAll = true;
574
				} else if (NO_COMPONENT.equals(selection)) {
575
					selectionContainsNone = true;
576
				} else if (selection instanceof Component){
577
					selectedComponents.add(selection);
578
				}
579
			}
580
			
581
			if (selectionContainsAll) {
582
				workingCopy.setComponentFilter(null);
583
			} else if (selectedComponents.size() > 0) {
584
				workingCopy.setComponentFilter(new ComponentFilter((Component[]) selectedComponents.toArray(new Component[selectedComponents.size()])));
585
			} else if (selectionContainsNone){
586
				workingCopy.setComponentFilter(new ComponentFilter(new Component[0]));
587
			} else {
588
				workingCopy.setComponentFilter(null);
589
			}
590
		}
591
	}
592
593
	private final class ComponentLabelProvider implements ILabelProvider {
594
595
		/* (non-Javadoc)
596
		 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
597
		 */
598
		public Image getImage(Object element) {
599
			return null;
600
		}
601
602
		/* (non-Javadoc)
603
		 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
604
		 */
605
		public String getText(Object element) {
606
			if (element instanceof Placeholder) {
607
				return ((Placeholder)element).getText();
608
			}
609
			return ((Component)element).getName();
610
		}
611
612
		/* (non-Javadoc)
613
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
614
		 */
615
		public void addListener(ILabelProviderListener listener) {
616
		}
617
618
		/* (non-Javadoc)
619
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
620
		 */
621
		public void dispose() {
622
		}
623
624
		/* (non-Javadoc)
625
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
626
		 */
627
		public boolean isLabelProperty(Object element, String property) {
628
			return false;
629
		}
630
631
		/* (non-Javadoc)
632
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
633
		 */
634
		public void removeListener(ILabelProviderListener listener) {
635
		}
636
		
637
	}
638
	
639
	private final class VersionLabelProvider implements ILabelProvider, IColorProvider {
640
641
		/* (non-Javadoc)
642
		 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
643
		 */
644
		public Image getImage(Object element) {
645
			return null;
646
		}
647
648
		/* (non-Javadoc)
649
		 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
650
		 */
651
		public String getText(Object element) {
652
			if (element instanceof Placeholder) {
653
				return ((Placeholder)element).getText();
654
			}
655
			return ((Version)element).getName();
656
		}
657
658
		/* (non-Javadoc)
659
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
660
		 */
661
		public void addListener(ILabelProviderListener listener) {
662
			
663
		}
664
665
		/* (non-Javadoc)
666
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
667
		 */
668
		public void dispose() {
669
		}
670
671
		/* (non-Javadoc)
672
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
673
		 */
674
		public boolean isLabelProperty(Object element, String property) {
675
			return false;
676
		}
677
678
		/* (non-Javadoc)
679
		 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
680
		 */
681
		public void removeListener(ILabelProviderListener listener) {
682
		}
683
684
		/* (non-Javadoc)
685
		 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
686
		 */
687
		public Color getForeground(Object element) {
688
			return null;
689
		}
690
691
		/* (non-Javadoc)
692
		 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
693
		 */
694
		public Color getBackground(Object element) {
695
			if (element instanceof Placeholder) {
696
				return Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
697
			}
698
			return null;
699
		}
700
		
701
	}
702
	
703
	private final class Placeholder {
704
		private final String text;
705
		
706
		public Placeholder(String text) {
707
			this.text = text;
708
		}
709
		/* (non-Javadoc)
710
		 * @see java.lang.Object#equals(java.lang.Object)
711
		 */
712
		public boolean equals(Object obj) {
713
			if (obj == null) return false;
714
			if (!(obj instanceof Placeholder)) return false;
715
			
716
			Placeholder that = (Placeholder) obj;
717
			return this.text.equals(that.text);
718
		}
719
		public String getText() {
720
			return this.text;
721
		}
722
	}
723
}
(-)src/org/eclipse/mylar/internal/jira/JiraNamedFilter.java (+141 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.jira;
13
14
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryQuery;
15
import org.tigris.jira.core.model.NamedFilter;
16
17
/**
18
 * A JiraFilter represents a query for issues from a Jira repository.
19
 * 
20
 * @author Mik Kersten
21
 * @author Wesley Coelho (initial integration patch)
22
 */
23
public class JiraNamedFilter extends AbstractRepositoryQuery {
24
25
//	private static final String LABEL_REFRESH_JOB = "Refreshing Jira Filter(s)";
26
27
	private static final int MAX_HITS = 75;
28
29
	protected NamedFilter filter = null;
30
31
//	private boolean isRefreshing = false;
32
33
	public JiraNamedFilter(String repositoryUrl, NamedFilter filter) {
34
		setMaxHits(MAX_HITS);
35
		this.filter = filter;
36
		super.repositoryUrl = repositoryUrl;
37
		setQueryUrl(repositoryUrl + MylarJiraPlugin.FILTER_URL_PREFIX + filter.getId());
38
39
		super.setDescription(filter.getName());
40
	}
41
42
	public NamedFilter getNamedFilter() {
43
		return filter;
44
	}
45
46
//	/**
47
//	 * TODO: refactor into common refresh mechanism.
48
//	 */
49
//	public void refreshHits() {
50
//		isRefreshing = true;
51
//		Job j = new Job(LABEL_REFRESH_JOB) {
52
//
53
//			@Override
54
//			protected IStatus run(final IProgressMonitor monitor) {
55
//				clearHits();
56
//				try {
57
//					TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(MylarJiraPlugin.JIRA_REPOSITORY_KIND, repositoryUrl);
58
//					JiraServerFacade.getDefault().getJiraServer(repository).executeNamedFilter(filter, new IssueCollector() {
59
//
60
//						public void done() {
61
//							isRefreshing = false;
62
//							Display.getDefault().asyncExec(new Runnable() {
63
//								public void run() {
64
//									if (TaskListView.getDefault() != null)
65
//										TaskListView.getDefault().refreshAndFocus();
66
//								}
67
//							});
68
//						}
69
//
70
//						public boolean isCancelled() {
71
//							return monitor.isCanceled();
72
//						}
73
//
74
//						public void collectIssue(Issue issue) {
75
//							int issueId = new Integer(issue.getId());
76
//							JiraFilterHit hit = new JiraFilterHit(issue, JiraFilter.this.getRepositoryUrl(), issueId);
77
//							addHit(hit);
78
//						}
79
//
80
//						public void start() {
81
//
82
//						}
83
//					});
84
//
85
//				} catch (Exception e) {
86
//					isRefreshing = false;
87
//					JiraServerFacade.handleConnectionException(e);
88
//					return Status.CANCEL_STATUS;
89
//				}
90
//
91
//				return Status.OK_STATUS;
92
//			}
93
//
94
//		};
95
//
96
//		j.schedule();
97
//
98
//	}
99
100
	public String getQueryUrl() {
101
		return super.getQueryUrl();
102
	}
103
104
	public String getPriority() {
105
		return "";
106
	}
107
108
	public String getDescription() {
109
		if (filter.getName() != null) {
110
			return filter.getName();
111
		} else {
112
			return super.getDescription();
113
		}
114
	}
115
116
	public void setDescription(String description) {
117
		filter.setDescription(description);
118
	}
119
120
	public boolean isLocal() {
121
		return false;
122
	}
123
124
//	/** True if the filter is currently downloading hits */
125
//	public boolean isRefreshing() {
126
//		return isRefreshing;
127
//	}
128
129
	public String getRepositoryKind() {
130
		return MylarJiraPlugin.JIRA_REPOSITORY_KIND;
131
	}
132
133
	public NamedFilter getFilter() {
134
		return filter;
135
	}
136
137
//	public void setRefreshing(boolean refreshing) {
138
//		this.isRefreshing = refreshing;
139
//	}
140
141
}
(-)src/org/eclipse/mylar/internal/jira/ui/wizards/IssueAttributesPage.java (+652 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 Jira Dashboard project.
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
 *    Brock Janiczak - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.jira.ui.wizards;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.viewers.ComboViewer;
19
import org.eclipse.jface.viewers.ISelectionChangedListener;
20
import org.eclipse.jface.viewers.IStructuredContentProvider;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.viewers.LabelProvider;
23
import org.eclipse.jface.viewers.ListViewer;
24
import org.eclipse.jface.viewers.SelectionChangedEvent;
25
import org.eclipse.jface.viewers.StructuredSelection;
26
import org.eclipse.jface.viewers.Viewer;
27
import org.eclipse.jface.wizard.WizardPage;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.events.ModifyEvent;
30
import org.eclipse.swt.events.ModifyListener;
31
import org.eclipse.swt.layout.GridData;
32
import org.eclipse.swt.layout.GridLayout;
33
import org.eclipse.swt.widgets.Composite;
34
import org.eclipse.swt.widgets.Label;
35
import org.eclipse.swt.widgets.Text;
36
import org.tigris.jira.core.model.IssueType;
37
import org.tigris.jira.core.model.Priority;
38
import org.tigris.jira.core.model.Resolution;
39
import org.tigris.jira.core.model.Status;
40
import org.tigris.jira.core.model.filter.CurrentUserFilter;
41
import org.tigris.jira.core.model.filter.FilterDefinition;
42
import org.tigris.jira.core.model.filter.IssueTypeFilter;
43
import org.tigris.jira.core.model.filter.NobodyFilter;
44
import org.tigris.jira.core.model.filter.PriorityFilter;
45
import org.tigris.jira.core.model.filter.ResolutionFilter;
46
import org.tigris.jira.core.model.filter.SpecificUserFilter;
47
import org.tigris.jira.core.model.filter.StatusFilter;
48
import org.tigris.jira.core.model.filter.UserFilter;
49
import org.tigris.jira.core.model.filter.UserInGroupFilter;
50
import org.tigris.jira.core.service.JiraServer;
51
52
public class IssueAttributesPage extends WizardPage {
53
	private final Placeholder ANY_ISSUE_TYPE = new Placeholder("Any");
54
	private final Placeholder ANY_RESOLUTION = new Placeholder("Any");
55
	private final Placeholder UNRESOLVED = new Placeholder("Unresolved");
56
	private final Placeholder UNASSIGNED = new Placeholder("Unassigned");
57
	
58
	private final Placeholder ANY_REPORTER = new Placeholder("Any");
59
	private final Placeholder NO_REPORTER = new Placeholder("No Reporter");
60
	private final Placeholder CURRENT_USER_REPORTER = new Placeholder("Current User");
61
	private final Placeholder SPECIFIC_USER_REPORTER = new Placeholder("Specified User");
62
	private final Placeholder SPECIFIC_GROUP_REPORTER = new Placeholder("Specified Group");
63
64
	private final Placeholder ANY_ASSIGNEE = new Placeholder("Any");
65
	private final Placeholder CURRENT_USER_ASSIGNEE = new Placeholder("Current User");
66
	private final Placeholder SPECIFIC_USER_ASSIGNEE = new Placeholder("Specified User");
67
	private final Placeholder SPECIFIC_GROUP_ASSIGNEE = new Placeholder("Specified Group");
68
	
69
	private final Placeholder ANY_STATUS = new Placeholder("Any");
70
	private final Placeholder ANY_PRIORITY = new Placeholder("Any");
71
	
72
	private final JiraServer jiraServer;
73
	private final FilterDefinition workingCopy;
74
	private final boolean isNew;
75
	private ListViewer issueType;
76
	private ComboViewer reporterType;
77
	private ComboViewer assigneeType;
78
	private ListViewer status;
79
	private ListViewer resolution;
80
	private ListViewer priority;
81
	private Text assignee;
82
	private Text reporter;
83
	
84
	/**
85
	 * @param pageName
86
	 * @param title
87
	 * @param titleImage
88
	 */
89
	protected IssueAttributesPage(String pageName, String title, ImageDescriptor titleImage, JiraServer jiraServer, FilterDefinition workingCopy, boolean isNew) {
90
		super(pageName, title, titleImage);
91
		this.jiraServer = jiraServer;
92
		this.workingCopy = workingCopy;
93
		this.isNew = isNew;
94
	}
95
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
98
	 */
99
	public void createControl(Composite parent) {
100
		GridData gd;
101
		Composite c = new Composite(parent, SWT.NONE);
102
		c.setLayout(new GridLayout(2, false));
103
		
104
		Label lblIssueType = new Label(c, SWT.NONE);
105
		lblIssueType.setText("Type:");
106
		lblIssueType.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
107
		issueType = new ListViewer(c, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
108
		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
109
		gd.heightHint = 40;
110
		issueType.getControl().setLayoutData(gd);
111
		
112
		issueType.setContentProvider(new IStructuredContentProvider() {
113
			
114
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
115
			}
116
		
117
			public void dispose() {
118
			}
119
		
120
			public Object[] getElements(Object inputElement) {
121
				JiraServer server = (JiraServer) inputElement;
122
				Object[] elements = new Object[server.getIssueTypes().length + 1];
123
				elements[0] = ANY_ISSUE_TYPE;
124
				System.arraycopy(server.getIssueTypes(), 0, elements, 1, server.getIssueTypes().length);
125
				
126
				return elements;
127
			}
128
		});
129
		
130
		issueType.setLabelProvider(new LabelProvider() {
131
		
132
			public String getText(Object element) {
133
				if (element instanceof Placeholder) {
134
					return ((Placeholder)element).getText();
135
				}
136
				
137
				return ((IssueType)element).getName();
138
			}
139
		
140
		});
141
		
142
		issueType.addSelectionChangedListener(new ISelectionChangedListener() {
143
			
144
			public void selectionChanged(SelectionChangedEvent event) {
145
				validatePage();
146
			}
147
		
148
		});
149
		issueType.setInput(jiraServer);
150
		
151
		Label lblReportedBy = new Label(c, SWT.NONE);
152
		lblReportedBy.setText("Reported By:");
153
		lblReportedBy.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 2));
154
		
155
		reporterType = new ComboViewer(c, SWT.BORDER | SWT.READ_ONLY);
156
		reporterType.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
157
		
158
		reporterType.setContentProvider(new IStructuredContentProvider() {
159
			
160
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
161
			}
162
		
163
			public void dispose() {
164
			}
165
		
166
			public Object[] getElements(Object inputElement) {
167
				return new Object[] {ANY_REPORTER, NO_REPORTER, CURRENT_USER_REPORTER, SPECIFIC_USER_REPORTER, SPECIFIC_GROUP_REPORTER};
168
			}
169
		
170
		});	
171
172
		reporterType.setLabelProvider(new LabelProvider() {
173
		
174
			public String getText(Object element) {
175
				return ((Placeholder)element).getText();
176
			}
177
		
178
		});
179
		
180
		reporterType.setInput(jiraServer);
181
		
182
		reporter = new Text(c, SWT.BORDER);
183
		reporter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
184
		reporter.setEnabled(false);
185
186
		reporter.addModifyListener(new ModifyListener() {
187
			
188
			public void modifyText(ModifyEvent e) {
189
				validatePage();
190
			}
191
		
192
		});
193
		
194
		reporterType.addSelectionChangedListener(new ISelectionChangedListener() {
195
			
196
			public void selectionChanged(SelectionChangedEvent event) {
197
				Object selection = ((IStructuredSelection)event.getSelection()).getFirstElement();
198
				if (SPECIFIC_USER_REPORTER.equals(selection) ||
199
					SPECIFIC_GROUP_REPORTER.equals(selection)) {
200
					reporter.setEnabled(true);
201
				} else {
202
					reporter.setEnabled(false);
203
				}
204
			}
205
		
206
		});
207
		
208
		Label lblAssignedTo = new Label(c, SWT.NONE);
209
		lblAssignedTo.setText("Assigned To:");
210
		lblAssignedTo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 2));
211
		
212
		assigneeType = new ComboViewer(c, SWT.BORDER | SWT.READ_ONLY);
213
		assigneeType.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
214
		
215
		
216
		assigneeType.setContentProvider(new IStructuredContentProvider() {
217
		
218
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
219
			}
220
		
221
			public void dispose() {
222
			}
223
		
224
			public Object[] getElements(Object inputElement) {
225
				return new Object[] {ANY_ASSIGNEE, UNASSIGNED, CURRENT_USER_ASSIGNEE, SPECIFIC_USER_ASSIGNEE, SPECIFIC_GROUP_ASSIGNEE};
226
			}
227
		
228
		});	
229
230
		assigneeType.setLabelProvider(new LabelProvider() {
231
		
232
			public String getText(Object element) {
233
				return ((Placeholder)element).getText();
234
			}
235
		
236
		});
237
		
238
		assigneeType.setInput(jiraServer);
239
		
240
		assignee = new Text(c, SWT.BORDER);
241
		assignee.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
242
		assignee.setEnabled(false);
243
244
		assignee.addModifyListener(new ModifyListener() {
245
		
246
			public void modifyText(ModifyEvent e) {
247
				validatePage();
248
			}
249
		
250
		});
251
		assigneeType.addSelectionChangedListener(new ISelectionChangedListener() {
252
			
253
			public void selectionChanged(SelectionChangedEvent event) {
254
				Object selection = ((IStructuredSelection)event.getSelection()).getFirstElement();
255
				if (SPECIFIC_USER_ASSIGNEE.equals(selection) ||
256
					SPECIFIC_GROUP_ASSIGNEE.equals(selection)) {
257
					assignee.setEnabled(true);
258
				} else {
259
					assignee.setEnabled(false);
260
					assignee.setText(""); //$NON-NLS-1$
261
				}
262
				validatePage();
263
			}
264
		
265
		});
266
		
267
		Label lblStatus = new Label(c, SWT.NONE);
268
		lblStatus.setText("Status:");
269
		lblStatus.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
270
		
271
		status = new ListViewer(c, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
272
		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
273
		gd.heightHint = 40;
274
		status.getControl().setLayoutData(gd);
275
276
		status.setContentProvider(new IStructuredContentProvider() {
277
			
278
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
279
			}
280
		
281
			public void dispose() {
282
			}
283
		
284
			public Object[] getElements(Object inputElement) {
285
				JiraServer server = (JiraServer) inputElement;
286
				Object[] elements = new Object[server.getStatuses().length + 1];
287
				elements[0] = ANY_STATUS;
288
				System.arraycopy(server.getStatuses(), 0, elements, 1, server.getStatuses().length);
289
				
290
				return elements;
291
			}
292
		});
293
		
294
		status.setLabelProvider(new LabelProvider() {
295
		
296
			public String getText(Object element) {
297
				if (element instanceof Placeholder) {
298
					return ((Placeholder)element).getText();
299
				}
300
				
301
				return ((Status)element).getName();
302
			}
303
		
304
		});
305
		
306
		status.addSelectionChangedListener(new ISelectionChangedListener() {
307
			
308
			public void selectionChanged(SelectionChangedEvent event) {
309
				validatePage();
310
			}
311
		
312
		});
313
		status.setInput(jiraServer);
314
		
315
		Label lblResolution = new Label(c, SWT.NONE);
316
		lblResolution.setText("Resolution:");
317
		lblResolution.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
318
		
319
		resolution = new ListViewer(c, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
320
		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
321
		gd.heightHint = 40;
322
		resolution.getControl().setLayoutData(gd);
323
		resolution.setContentProvider(new IStructuredContentProvider() {
324
		
325
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
326
			}
327
		
328
			public void dispose() {
329
			}
330
		
331
			public Object[] getElements(Object inputElement) {
332
				JiraServer server = (JiraServer) inputElement;
333
				Object[] elements = new Object[server.getResolutions().length + 2];
334
				elements[0] = ANY_RESOLUTION;
335
				elements[1] = UNRESOLVED;
336
				System.arraycopy(server.getResolutions(), 0, elements, 2, server.getResolutions().length);
337
				
338
				return elements;
339
			}
340
		});
341
		
342
		resolution.setLabelProvider(new LabelProvider() {
343
		
344
			public String getText(Object element) {
345
				if (element instanceof Placeholder) {
346
					return ((Placeholder)element).getText();
347
				}
348
				
349
				return ((Resolution)element).getName();
350
			}
351
		
352
		});
353
		
354
		resolution.addSelectionChangedListener(new ISelectionChangedListener() {
355
			
356
			public void selectionChanged(SelectionChangedEvent event) {
357
				validatePage();
358
			}
359
		
360
		});
361
		resolution.setInput(jiraServer);
362
		
363
		Label lblPriority = new Label(c, SWT.NONE);
364
		lblPriority.setText("Priority:");
365
		lblPriority.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
366
		
367
		priority = new ListViewer(c, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
368
		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
369
		gd.heightHint = 40;
370
		priority.getControl().setLayoutData(gd);
371
		
372
		priority.setContentProvider(new IStructuredContentProvider() {
373
			
374
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
375
			}
376
		
377
			public void dispose() {
378
			}
379
		
380
			public Object[] getElements(Object inputElement) {
381
				JiraServer server = (JiraServer) inputElement;
382
				Object[] elements = new Object[server.getPriorities().length + 1];
383
				elements[0] = ANY_PRIORITY;
384
				System.arraycopy(server.getPriorities(), 0, elements, 1, server.getPriorities().length);
385
				
386
				return elements;
387
			}
388
		});
389
		
390
		priority.setLabelProvider(new LabelProvider() {
391
		
392
			public String getText(Object element) {
393
				if (element instanceof Placeholder) {
394
					return ((Placeholder)element).getText();
395
				}
396
				
397
				return ((Priority)element).getName();
398
			}
399
		
400
		});
401
		priority.addSelectionChangedListener(new ISelectionChangedListener() {
402
		
403
			public void selectionChanged(SelectionChangedEvent event) {
404
				validatePage();
405
			}
406
		
407
		});
408
		priority.setInput(jiraServer);
409
		
410
		if (isNew) {
411
			loadFromDefaults();
412
		} else {
413
			loadFromWorkingCopy();
414
		}
415
		
416
		setControl(c);
417
	}
418
	
419
	private void validatePage() {
420
		
421
	}
422
423
	/* default */ void applyChanges() {
424
		
425
		// TODO support standard and subtask issue types
426
		IStructuredSelection issueTypeSelection = (IStructuredSelection) issueType.getSelection();
427
		if (issueTypeSelection.isEmpty()) {
428
			workingCopy.setIssueTypeFilter(null);
429
		} else {
430
			boolean isAnyIssueTypeSelected = false;
431
			
432
			List selectedIssueTypes = new ArrayList();
433
			
434
			for (Iterator i = issueTypeSelection.iterator(); i.hasNext(); ) {
435
				Object selection = i.next();
436
				if (ANY_ISSUE_TYPE.equals(selection)) {
437
					isAnyIssueTypeSelected = true;
438
				} else if (selection instanceof IssueType) {
439
					selectedIssueTypes.add(selection);
440
				}
441
			}
442
			
443
			if (isAnyIssueTypeSelected) {
444
				workingCopy.setIssueTypeFilter(null);
445
			} else {
446
				workingCopy.setIssueTypeFilter(new IssueTypeFilter((IssueType[]) selectedIssueTypes.toArray(new IssueType[selectedIssueTypes.size()])));
447
			}
448
		}
449
		
450
		IStructuredSelection reporterSelection = (IStructuredSelection) reporterType.getSelection();
451
		if (reporterSelection.isEmpty()) {
452
			workingCopy.setReportedByFilter(null);
453
		} else {
454
			if (ANY_REPORTER.equals(reporterSelection.getFirstElement())) {
455
				workingCopy.setReportedByFilter(null);
456
			} else if (NO_REPORTER.equals(reporterSelection.getFirstElement())) {
457
				workingCopy.setReportedByFilter(new NobodyFilter());
458
			} else if (CURRENT_USER_REPORTER.equals(reporterSelection.getFirstElement())) {
459
				workingCopy.setReportedByFilter(new CurrentUserFilter());
460
			} else if (SPECIFIC_GROUP_REPORTER.equals(reporterSelection.getFirstElement())) {
461
				workingCopy.setReportedByFilter(new UserInGroupFilter(reporter.getText()));
462
			} else if (SPECIFIC_USER_REPORTER.equals(reporterSelection.getFirstElement())) {
463
				workingCopy.setReportedByFilter(new SpecificUserFilter(reporter.getText()));
464
			} else {
465
				workingCopy.setReportedByFilter(null);
466
			}
467
		}
468
		
469
		IStructuredSelection assigneeSelection = (IStructuredSelection) assigneeType.getSelection();
470
		if (assigneeSelection.isEmpty()) {
471
			workingCopy.setAssignedToFilter(null);
472
		} else {
473
			if (ANY_REPORTER.equals(assigneeSelection.getFirstElement())) {
474
				workingCopy.setAssignedToFilter(null);
475
			} else if (UNASSIGNED.equals(assigneeSelection.getFirstElement())) {
476
				workingCopy.setAssignedToFilter(new NobodyFilter());
477
			} else if (CURRENT_USER_REPORTER.equals(assigneeSelection.getFirstElement())) {
478
				workingCopy.setAssignedToFilter(new CurrentUserFilter());
479
			} else if (SPECIFIC_GROUP_REPORTER.equals(assigneeSelection.getFirstElement())) {
480
				workingCopy.setAssignedToFilter(new UserInGroupFilter(assignee.getText()));
481
			} else if (SPECIFIC_USER_REPORTER.equals(assigneeSelection.getFirstElement())) {
482
				workingCopy.setAssignedToFilter(new SpecificUserFilter(assignee.getText()));
483
			} else {
484
				workingCopy.setAssignedToFilter(null);
485
			}
486
		}
487
		
488
		
489
		IStructuredSelection statusSelection = (IStructuredSelection) status.getSelection();
490
		if (statusSelection.isEmpty()) {
491
			workingCopy.setStatusFilter(null);
492
		} else {
493
			boolean isAnyStatusSelected = false;
494
			
495
			List selectedStatuses = new ArrayList();
496
			
497
			for (Iterator i = statusSelection.iterator(); i.hasNext(); ) {
498
				Object selection = i.next();
499
				if (ANY_STATUS.equals(selection)) {
500
					isAnyStatusSelected = true;
501
				} else if (selection instanceof Status) {
502
					selectedStatuses.add(selection);
503
				}
504
			}
505
			
506
			if (isAnyStatusSelected) {
507
				workingCopy.setStatusFilter(null);
508
			} else {
509
				workingCopy.setStatusFilter(new StatusFilter((Status[]) selectedStatuses.toArray(new Status[selectedStatuses.size()])));
510
			}
511
		}
512
		
513
		IStructuredSelection resolutionSelection = (IStructuredSelection) resolution.getSelection();
514
		if (resolutionSelection.isEmpty()) {
515
			workingCopy.setResolutionFilter(null);
516
		} else {
517
			boolean isAnyResolutionSelected = false;
518
			
519
			List selectedResolutions = new ArrayList();
520
			
521
			for (Iterator i = resolutionSelection.iterator(); i.hasNext(); ) {
522
				Object selection = i.next();
523
				if (ANY_RESOLUTION.equals(selection)) {
524
					isAnyResolutionSelected = true;
525
				} else if (selection instanceof Resolution) {
526
					selectedResolutions.add(selection);
527
				}
528
			}
529
			
530
			if (isAnyResolutionSelected) {
531
				workingCopy.setResolutionFilter(null);
532
			} else {
533
				workingCopy.setResolutionFilter(new ResolutionFilter((Resolution[]) selectedResolutions.toArray(new Resolution[selectedResolutions.size()])));
534
			}
535
		}
536
		
537
		
538
		IStructuredSelection prioritySelection = (IStructuredSelection) priority.getSelection();
539
		if (prioritySelection.isEmpty()) {
540
			workingCopy.setPriorityFilter(null);
541
		} else {
542
			boolean isAnyPrioritiesSelected = false;
543
			
544
			List selectedPriorities = new ArrayList();
545
			
546
			for (Iterator i = prioritySelection.iterator(); i.hasNext(); ) {
547
				Object selection = i.next();
548
				if (ANY_PRIORITY.equals(selection)) {
549
					isAnyPrioritiesSelected = true;
550
				} else if (selection instanceof Priority) {
551
					selectedPriorities.add(selection);
552
				}
553
			}
554
			
555
			if (isAnyPrioritiesSelected) {
556
				workingCopy.setPriorityFilter(null);
557
			} else {
558
				workingCopy.setPriorityFilter(new PriorityFilter((Priority[]) selectedPriorities.toArray(new Priority[selectedPriorities.size()])));
559
			}
560
		}
561
	}
562
	
563
	private void loadFromDefaults() {
564
		issueType.setSelection(new StructuredSelection(ANY_ISSUE_TYPE));
565
		reporterType.setSelection(new StructuredSelection(ANY_REPORTER));
566
		assigneeType.setSelection(new StructuredSelection(ANY_ASSIGNEE));
567
		status.setSelection(new StructuredSelection(ANY_STATUS));
568
		resolution.setSelection(new StructuredSelection(ANY_RESOLUTION));
569
		priority.setSelection(new StructuredSelection(ANY_PRIORITY));
570
	}
571
	
572
	private void loadFromWorkingCopy() {
573
		if (workingCopy.getIssueTypeFilter() != null) {
574
			issueType.setSelection(new StructuredSelection(workingCopy.getIssueTypeFilter().getIsueTypes()));
575
		} else {
576
			issueType.setSelection(new StructuredSelection(ANY_ISSUE_TYPE));
577
		}
578
		
579
		if (workingCopy.getReportedByFilter() != null) {
580
			UserFilter reportedByFilter = workingCopy.getReportedByFilter();
581
			if (reportedByFilter instanceof NobodyFilter) {
582
				reporterType.setSelection(new StructuredSelection(NO_REPORTER));
583
			} else if (reportedByFilter instanceof CurrentUserFilter) {
584
				reporterType.setSelection(new StructuredSelection(CURRENT_USER_REPORTER));
585
			} else if (reportedByFilter instanceof SpecificUserFilter) {
586
				reporterType.setSelection(new StructuredSelection(SPECIFIC_USER_REPORTER));
587
				reporter.setText(((SpecificUserFilter)reportedByFilter).getUser());
588
			} else if (reportedByFilter instanceof UserInGroupFilter) {
589
				reporterType.setSelection(new StructuredSelection(SPECIFIC_GROUP_REPORTER));
590
				reporter.setText(((UserInGroupFilter)reportedByFilter).getGroup());
591
			}
592
		} else {
593
			reporterType.setSelection(new StructuredSelection(ANY_REPORTER));
594
		}
595
		
596
		if (workingCopy.getAssignedToFilter() != null) {
597
			UserFilter assignedToFilter = workingCopy.getAssignedToFilter();
598
			if (assignedToFilter instanceof NobodyFilter) {
599
				assigneeType.setSelection(new StructuredSelection(UNASSIGNED));
600
			} else if (assignedToFilter instanceof CurrentUserFilter) {
601
				assigneeType.setSelection(new StructuredSelection(CURRENT_USER_ASSIGNEE));
602
			} else if (assignedToFilter instanceof SpecificUserFilter) {
603
				assigneeType.setSelection(new StructuredSelection(SPECIFIC_USER_ASSIGNEE));
604
				assignee.setText(((SpecificUserFilter)assignedToFilter).getUser());
605
			} else if (assignedToFilter instanceof UserInGroupFilter) {
606
				assigneeType.setSelection(new StructuredSelection(SPECIFIC_GROUP_ASSIGNEE));
607
				assignee.setText(((UserInGroupFilter)assignedToFilter).getGroup());
608
			}
609
		} else {
610
			assigneeType.setSelection(new StructuredSelection(ANY_ASSIGNEE));
611
		}
612
		
613
		if (workingCopy.getStatusFilter() != null) {
614
			status.setSelection(new StructuredSelection(workingCopy.getStatusFilter().getStatuses()));
615
		} else {
616
			status.setSelection(new StructuredSelection(ANY_STATUS));
617
		}
618
		
619
		if (workingCopy.getResolutionFilter() != null) {
620
			resolution.setSelection(new StructuredSelection(workingCopy.getResolutionFilter().getResolutions()));
621
		} else {
622
			resolution.setSelection(new StructuredSelection(ANY_RESOLUTION));
623
		}
624
		
625
		if (workingCopy.getPriorityFilter() != null) {
626
			priority.setSelection(new StructuredSelection(workingCopy.getPriorityFilter().getPriorities()));
627
		} else {
628
			priority.setSelection(new StructuredSelection(ANY_PRIORITY));
629
		}
630
	}
631
	
632
	private final class Placeholder {
633
		private final String text;
634
		
635
		public Placeholder(String text) {
636
			this.text = text;
637
		}
638
		/* (non-Javadoc)
639
		 * @see java.lang.Object#equals(java.lang.Object)
640
		 */
641
		public boolean equals(Object obj) {
642
			if (obj == null) return false;
643
			if (!(obj instanceof Placeholder)) return false;
644
			
645
			Placeholder that = (Placeholder) obj;
646
			return this.text.equals(that.text);
647
		}
648
		public String getText() {
649
			return this.text;
650
		}
651
	}
652
}

Return to bug 129086