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

Return to bug 129086