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

Return to bug 129086