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

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/tasks/web/WebRepositorySettingsPage.java (-2 / +104 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.mylar.internal.tasks.web;
12
package org.eclipse.mylar.internal.tasks.web;
13
13
14
import java.util.ArrayList;
14
import java.util.LinkedHashMap;
15
import java.util.LinkedHashMap;
15
import java.util.Map;
16
import java.util.Map;
16
17
Lines 18-23 Link Here
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage;
21
import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage;
22
import org.eclipse.mylar.internal.tasks.web.restui.EMethodType;
23
import org.eclipse.mylar.internal.tasks.web.restui.NameValuePair;
24
import org.eclipse.mylar.internal.tasks.web.restui.RESTRequestEditor;
21
import org.eclipse.mylar.tasks.core.RepositoryTemplate;
25
import org.eclipse.mylar.tasks.core.RepositoryTemplate;
22
import org.eclipse.mylar.tasks.core.TaskRepository;
26
import org.eclipse.mylar.tasks.core.TaskRepository;
23
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
27
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
Lines 56-63 Link Here
56
60
57
	private Text queryPatternText;
61
	private Text queryPatternText;
58
62
63
	private Text loginFormUrlText;
64
65
	private Text loginTokenPatternText;
66
59
	private ParametersEditor parametersEditor;
67
	private ParametersEditor parametersEditor;
60
68
69
	private RESTRequestEditor loginRequestEditor;
70
61
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
71
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
62
72
63
	private Map<String, String> oldProperties;
73
	private Map<String, String> oldProperties;
Lines 84-99 Link Here
84
					newTaskText.setText(template.newTaskUrl);
94
					newTaskText.setText(template.newTaskUrl);
85
					queryUrlText.setText(template.taskQueryUrl);
95
					queryUrlText.setText(template.taskQueryUrl);
86
					queryPatternText.setText(template.getAttribute(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
96
					queryPatternText.setText(template.getAttribute(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
97
					loginFormUrlText.setText(template.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL));
98
					loginTokenPatternText.setText(template
99
							.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP));
100
					try {
101
						loginRequestEditor.setMethod(EMethodType.valueOf(template
102
								.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD)));
103
					} catch (IllegalArgumentException e1) {
104
						// ignore
105
					}
106
					loginRequestEditor.setUrl(template.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL));
87
107
88
					parametersEditor.removeAll();
108
					parametersEditor.removeAll();
89
109
110
					ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
90
					for (Map.Entry<String, String> entry : template.getAttributes().entrySet()) {
111
					for (Map.Entry<String, String> entry : template.getAttributes().entrySet()) {
91
						String key = entry.getKey();
112
						String key = entry.getKey();
92
						if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)) {
113
						if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)) {
93
							parametersEditor.add(key.substring(WebRepositoryConnector.PARAM_PREFIX.length()), entry
114
							parametersEditor.add(key.substring(WebRepositoryConnector.PARAM_PREFIX.length()), entry
94
									.getValue());
115
									.getValue());
95
						}
116
						}
117
						if (key.startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
118
							pairs.add(new NameValuePair(key.substring(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX
119
									.length()), entry.getValue()));
120
						}
96
					}
121
					}
122
					loginRequestEditor.setParameters(pairs.toArray(new NameValuePair[pairs.size()]));
97
123
98
					getContainer().updateButtons();
124
					getContainer().updateButtons();
99
					return;
125
					return;
Lines 114-122 Link Here
114
			newTaskText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL));
140
			newTaskText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL));
115
			queryUrlText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_URL));
141
			queryUrlText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_URL));
116
			queryPatternText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
142
			queryPatternText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
143
			loginFormUrlText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL));
144
			loginTokenPatternText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP));
145
			try {
146
				loginRequestEditor.setMethod(EMethodType
147
						.valueOf(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD)));
148
			} catch (IllegalArgumentException e) {
149
				// ignore
150
			}
151
			loginRequestEditor.setUrl(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL));
117
152
118
			oldProperties = repository.getProperties();
153
			oldProperties = repository.getProperties();
119
			parametersEditor.addParams(oldProperties, new LinkedHashMap<String, String>());
154
			parametersEditor.addParams(oldProperties, new LinkedHashMap<String, String>());
155
			ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
156
			for (Map.Entry<String, String> entry : oldProperties.entrySet()) {
157
				if (entry.getKey().startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
158
					pairs.add(new NameValuePair(entry.getKey().substring(
159
							WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX.length()), entry.getValue()));
160
				}
161
			}
162
			loginRequestEditor.setParameters(pairs.toArray(new NameValuePair[pairs.size()]));
120
		}
163
		}
121
	}
164
	}
122
165
Lines 153-158 Link Here
153
		gridData_1.minimumHeight = 80;
196
		gridData_1.minimumHeight = 80;
154
		parametersEditor.setLayoutData(gridData_1);
197
		parametersEditor.setLayoutData(gridData_1);
155
198
199
		createAdvancedComposite(parent, composite);
200
		createLoginComposite(parent, composite);
201
202
		return composite;
203
	}
204
205
	private void createAdvancedComposite(Composite parent, final Composite composite) {
156
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
206
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
157
				| Section.TWISTIE | Section.TITLE_BAR);
207
				| Section.TWISTIE | Section.TITLE_BAR);
158
		expComposite.clientVerticalSpacing = 0;
208
		expComposite.clientVerticalSpacing = 0;
Lines 201-208 Link Here
201
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
251
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
202
		gridData.heightHint = 40;
252
		gridData.heightHint = 40;
203
		queryPatternText.setLayoutData(gridData);
253
		queryPatternText.setLayoutData(gridData);
254
	}
255
256
	private void createLoginComposite(final Composite parent, final Composite composite) {
257
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
258
				| Section.TWISTIE | Section.TITLE_BAR);
259
		expComposite.clientVerticalSpacing = 0;
260
		GridData gridData_2 = new GridData(SWT.FILL, SWT.FILL, true, false);
261
		gridData_2.horizontalIndent = -5;
262
		expComposite.setLayoutData(gridData_2);
263
		expComposite.setFont(parent.getFont());
264
		expComposite.setBackground(parent.getBackground());
265
		expComposite.setText("&Login Configuration (Expert)");
266
		expComposite.addExpansionListener(new ExpansionAdapter() {
267
			public void expansionStateChanged(ExpansionEvent e) {
268
				composite.layout();
269
			}
270
		});
271
		toolkit.paintBordersFor(expComposite);
272
273
		Composite composite2 = toolkit.createComposite(expComposite, SWT.BORDER);
274
		GridLayout gridLayout2 = new GridLayout();
275
		gridLayout2.numColumns = 2;
276
		gridLayout2.verticalSpacing = 0;
277
		composite2.setLayout(gridLayout2);
278
		expComposite.setClient(composite2);
279
280
		Label queryUrlLabel = toolkit.createLabel(composite2, "Login &Page URL:", SWT.NONE);
281
		queryUrlLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
282
283
		loginFormUrlText = new Text(composite2, SWT.BORDER);
284
		loginFormUrlText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
285
286
		Label queryPatternLabel = toolkit.createLabel(composite2, "Login &Token Pattern:", SWT.NONE);
287
		queryPatternLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, true));
288
289
		loginTokenPatternText = new Text(composite2, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.WRAP);
290
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
291
		gridData.heightHint = 40;
292
		loginTokenPatternText.setLayoutData(gridData);
293
294
		loginRequestEditor = new RESTRequestEditor(composite2, SWT.NONE);
295
		GridDataFactory.generate(loginRequestEditor, 2, 1);
296
		toolkit.adapt(loginRequestEditor);
297
		toolkit.paintBordersFor(loginRequestEditor);
204
298
205
		return composite;
206
	}
299
	}
207
300
208
	public void propertyChange(PropertyChangeEvent event) {
301
	public void propertyChange(PropertyChangeEvent event) {
Lines 218-228 Link Here
218
		repository.setProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL, newTaskText.getText());
311
		repository.setProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL, newTaskText.getText());
219
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_URL, queryUrlText.getText());
312
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_URL, queryUrlText.getText());
220
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP, queryPatternText.getText());
313
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP, queryPatternText.getText());
314
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL, loginFormUrlText.getText());
315
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP, loginTokenPatternText.getText());
316
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD, loginRequestEditor.getMethod()
317
				.name());
318
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL, loginRequestEditor.getUrl());
221
319
222
		if (oldProperties != null) {
320
		if (oldProperties != null) {
223
			for (Map.Entry<String, String> e : oldProperties.entrySet()) {
321
			for (Map.Entry<String, String> e : oldProperties.entrySet()) {
224
				String key = e.getKey();
322
				String key = e.getKey();
225
				if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)) {
323
				if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)
324
						|| key.startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
226
					repository.removeProperty(key);
325
					repository.removeProperty(key);
227
				}
326
				}
228
			}
327
			}
Lines 231-236 Link Here
231
		for (Map.Entry<String, String> e : parametersEditor.getParameters().entrySet()) {
330
		for (Map.Entry<String, String> e : parametersEditor.getParameters().entrySet()) {
232
			repository.setProperty(e.getKey(), e.getValue());
331
			repository.setProperty(e.getKey(), e.getValue());
233
		}
332
		}
333
		for (NameValuePair pair : loginRequestEditor.getParameters()) {
334
			repository.setProperty(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX + pair.getName(), pair.getValue());
335
		}
234
	}
336
	}
235
337
236
}
338
}
(-)src/org/eclipse/mylar/internal/tasks/web/WebRepositoryConnector.java (-8 / +119 lines)
Lines 17-22 Link Here
17
import java.net.URLDecoder;
17
import java.net.URLDecoder;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.HashMap;
20
import java.util.List;
21
import java.util.List;
21
import java.util.Map;
22
import java.util.Map;
22
import java.util.Set;
23
import java.util.Set;
Lines 25-31 Link Here
25
26
26
import org.apache.commons.httpclient.Header;
27
import org.apache.commons.httpclient.Header;
27
import org.apache.commons.httpclient.HttpClient;
28
import org.apache.commons.httpclient.HttpClient;
29
import org.apache.commons.httpclient.HttpMethod;
30
import org.apache.commons.httpclient.NameValuePair;
28
import org.apache.commons.httpclient.methods.GetMethod;
31
import org.apache.commons.httpclient.methods.GetMethod;
32
import org.apache.commons.httpclient.methods.PostMethod;
29
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IProgressMonitor;
31
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.IStatus;
Lines 34-39 Link Here
34
import org.eclipse.mylar.internal.tasks.core.WebQueryHit;
38
import org.eclipse.mylar.internal.tasks.core.WebQueryHit;
35
import org.eclipse.mylar.internal.tasks.core.WebTask;
39
import org.eclipse.mylar.internal.tasks.core.WebTask;
36
import org.eclipse.mylar.internal.tasks.ui.RetrieveTitleFromUrlJob;
40
import org.eclipse.mylar.internal.tasks.ui.RetrieveTitleFromUrlJob;
41
import org.eclipse.mylar.internal.tasks.web.restui.EMethodType;
37
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
42
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
38
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
43
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
39
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
44
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
Lines 60-65 Link Here
60
65
61
	public static final String PROPERTY_QUERY_REGEXP = "queryPattern";
66
	public static final String PROPERTY_QUERY_REGEXP = "queryPattern";
62
67
68
	public static final String PROPERTY_LOGIN_FORM_URL = "loginFormUrl";
69
70
	public static final String PROPERTY_LOGIN_TOKEN_REGEXP = "loginTokenPattern";
71
72
	public static final String PROPERTY_LOGIN_REQUEST_METHOD = "loginRequestMethod";
73
74
	public static final String PROPERTY_LOGIN_REQUEST_URL = "loginRequestUrl";
75
76
	public static final String LOGIN_REQUEST_PARAM_PREFIX = "loginRequestParam_";
77
63
	public static final String PARAM_PREFIX = "param_";
78
	public static final String PARAM_PREFIX = "param_";
64
79
65
	public static final String PARAM_SERVER_URL = "serverUrl";
80
	public static final String PARAM_SERVER_URL = "serverUrl";
Lines 68-73 Link Here
68
83
69
	public static final String PARAM_PASSWORD = "password";
84
	public static final String PARAM_PASSWORD = "password";
70
85
86
	public static final String PARAM_LOGIN_TOKEN = "loginToken";
87
71
	public String getRepositoryType() {
88
	public String getRepositoryType() {
72
		return WebTask.REPOSITORY_TYPE;
89
		return WebTask.REPOSITORY_TYPE;
73
	}
90
	}
Lines 159-169 Link Here
159
			String queryUrl = evaluateParams(query.getUrl(), queryParameters, repository);
176
			String queryUrl = evaluateParams(query.getUrl(), queryParameters, repository);
160
			String queryPattern = evaluateParams(webQuery.getQueryPattern(), queryParameters, repository);
177
			String queryPattern = evaluateParams(webQuery.getQueryPattern(), queryParameters, repository);
161
			String taskPrefix = evaluateParams(webQuery.getTaskPrefix(), queryParameters, repository);
178
			String taskPrefix = evaluateParams(webQuery.getTaskPrefix(), queryParameters, repository);
162
179
			Map<String, String> loginParams = new HashMap<String, String>();
180
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL, evaluateParams(repository
181
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL), queryParameters, repository));
182
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP, evaluateParams(repository
183
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP), queryParameters, repository));
184
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD, evaluateParams(repository
185
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD), queryParameters, repository));
186
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL, evaluateParams(repository
187
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL), queryParameters, repository));
188
			for (Map.Entry<String, String> entry : repository.getProperties().entrySet()) {
189
				if (entry.getKey().startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
190
					loginParams.put(entry.getKey(), entry.getValue());
191
				}
192
			}
193
			
163
			try {
194
			try {
164
				// if (regexp != null && regexp.trim().length() > 0) {
195
				// if (regexp != null && regexp.trim().length() > 0) {
165
				return performQuery(fetchResource(queryUrl, repositoryUser, repositoryPassword), queryPattern,
196
				return performQuery(fetchResource(queryUrl, repositoryUser, repositoryPassword, loginParams,
166
						taskPrefix, monitor, resultCollector, repository);
197
						queryParameters, repository), queryPattern, taskPrefix, monitor, resultCollector, repository);
167
				// } else {
198
				// } else {
168
				// return performRssQuery(queryUrl, taskPrefix, repositoryUrl,
199
				// return performRssQuery(queryUrl, taskPrefix, repositoryUrl,
169
				// repositoryUser, repositoryPassword,
200
				// repositoryUser, repositoryPassword,
Lines 270-286 Link Here
270
	 * try { collector.accept(new WebQueryHit(id, id+": "+entry.getTitle(),
301
	 * try { collector.accept(new WebQueryHit(id, id+": "+entry.getTitle(),
271
	 * taskPrefix, repositoryUrl)); } catch (CoreException e) { return new
302
	 * taskPrefix, repositoryUrl)); } catch (CoreException e) { return new
272
	 * Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR, "Unable
303
	 * Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR, "Unable
273
	 * collect results.", e); } } } return Status.OK_STATUS;
304
	 * collect results.", e); } } } return Status.OK_STATUS; } catch (Exception
274
	 *  } catch (Exception ex) { return new Status(IStatus.OK,
305
	 * ex) { return new Status(IStatus.OK, TasksUiPlugin.PLUGIN_ID, IStatus.OK,
275
	 * TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Could not fetch resource: " +
306
	 * "Could not fetch resource: " + queryUrl, ex); } }
276
	 * queryUrl, ex); } }
277
	 */
307
	 */
278
308
279
	public static String fetchResource(String url, String user, String password) throws IOException {
309
	public static String fetchResource(String url, String user, String password, Map<String, String> loginParams,
310
			Map<String, String> params, TaskRepository repository) throws IOException {
280
		HttpClient client = new HttpClient();
311
		HttpClient client = new HttpClient();
281
		Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
312
		Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
282
		WebClientUtil.setupHttpClient(client, proxySettings, url, user, password);
313
		WebClientUtil.setupHttpClient(client, proxySettings, url, user, password);
283
314
315
		if (loginParams != null) {
316
			String loginFormUrl = loginParams.get(PROPERTY_LOGIN_FORM_URL);
317
			if (loginFormUrl != null && !"".equals(loginFormUrl)) {
318
				GetMethod get = new GetMethod(loginFormUrl);
319
				String loginFormPage = null;
320
				try {
321
					client.executeMethod(get);
322
					Header locationHeader = get.getResponseHeader("Location");
323
					if (locationHeader != null) {
324
						get = new GetMethod(locationHeader.getValue());
325
						client.executeMethod(get);
326
					}
327
					Header refreshHeader = get.getResponseHeader("Refresh");
328
					if (refreshHeader != null) {
329
						String value = refreshHeader.getValue();
330
						int n = value.indexOf(";url=");
331
						if (n != -1) {
332
							value = value.substring(n + 5);
333
							int requestPath;
334
							if (value.charAt(0) == '/') {
335
								int colonSlashSlash = url.indexOf("://");
336
								requestPath = url.indexOf('/', colonSlashSlash + 3);
337
							} else {
338
								requestPath = url.lastIndexOf('/');
339
							}
340
341
							String refreshUrl;
342
							if (requestPath == -1) {
343
								refreshUrl = url + "/" + value;
344
							} else {
345
								refreshUrl = url.substring(0, requestPath + 1) + value;
346
							}
347
348
							get = new GetMethod(refreshUrl);
349
							client.executeMethod(get);
350
						}
351
					}
352
					loginFormPage = get.getResponseBodyAsString();
353
				} catch (Exception e) {
354
					// ignore
355
					e.printStackTrace();
356
				} finally {
357
					get.releaseConnection();
358
				}
359
				if (loginFormPage != null) {
360
					Pattern p = Pattern.compile(loginParams.get(PROPERTY_LOGIN_TOKEN_REGEXP));
361
					Matcher m = p.matcher(loginFormPage);
362
					if (m.find()) {
363
						// TODO is it ok to modify the params map?
364
						params.put(PARAM_PREFIX + PARAM_LOGIN_TOKEN, m.group(1));
365
					}
366
				}
367
			}
368
			HttpMethod method = null;
369
			try {
370
				switch (EMethodType.valueOf(loginParams.get(PROPERTY_LOGIN_REQUEST_METHOD))) {
371
				case GET:
372
					method = new GetMethod(loginParams.get(PROPERTY_LOGIN_REQUEST_URL));
373
					break;
374
				case POST:
375
					method = new PostMethod(loginParams.get(PROPERTY_LOGIN_REQUEST_URL));
376
					for (Map.Entry<String, String> entry : loginParams.entrySet()) {
377
						if (entry.getKey().startsWith(LOGIN_REQUEST_PARAM_PREFIX)) {
378
							String value = evaluateParams(entry.getValue(), params, repository);
379
							((PostMethod) method).addParameter(new NameValuePair(entry.getKey().substring(
380
									LOGIN_REQUEST_PARAM_PREFIX.length()), value));
381
						}
382
					}
383
					break;
384
				}
385
				client.executeMethod(method);
386
			} catch (Exception e) {
387
				// ignore
388
			} finally {
389
				if (method != null) {
390
					method.releaseConnection();
391
				}
392
			}
393
		}
394
284
		GetMethod get = new GetMethod(url);
395
		GetMethod get = new GetMethod(url);
285
		try {
396
		try {
286
			client.executeMethod(get);
397
			client.executeMethod(get);
(-)src/org/eclipse/mylar/internal/tasks/web/WebQueryWizardPage.java (-54 / +90 lines)
Lines 10-15 Link Here
10
10
11
import java.io.IOException;
11
import java.io.IOException;
12
import java.util.ArrayList;
12
import java.util.ArrayList;
13
import java.util.HashMap;
13
import java.util.LinkedHashMap;
14
import java.util.LinkedHashMap;
14
import java.util.List;
15
import java.util.List;
15
import java.util.Map;
16
import java.util.Map;
Lines 49-79 Link Here
49
50
50
/**
51
/**
51
 * Wizard page for configuring and preview web query
52
 * Wizard page for configuring and preview web query
52
 *
53
 * 
53
 * @author Eugene Kuleshov
54
 * @author Eugene Kuleshov
54
 */
55
 */
55
public class WebQueryWizardPage extends AbstractRepositoryQueryPage {
56
public class WebQueryWizardPage extends AbstractRepositoryQueryPage {
56
	private Text queryUrlText;
57
	private Text queryUrlText;
58
57
	private Text queryPatternText;
59
	private Text queryPatternText;
60
58
	private Table previewTable;
61
	private Table previewTable;
59
62
60
	private String webPage;
63
	private String webPage;
61
64
62
	private TaskRepository repository;
65
	private TaskRepository repository;
66
63
	private WebQuery query;
67
	private WebQuery query;
68
64
	private UpdatePreviewJob updatePreviewJob;
69
	private UpdatePreviewJob updatePreviewJob;
65
70
66
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
71
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
72
67
	private ParametersEditor parametersEditor;
73
	private ParametersEditor parametersEditor;
68
	private Map<String, String> oldProperties;
69
74
75
	private Map<String, String> oldProperties;
70
76
71
	public WebQueryWizardPage(TaskRepository repository) {
77
	public WebQueryWizardPage(TaskRepository repository) {
72
		this(repository, null);
78
		this(repository, null);
73
	}
79
	}
74
80
75
	public WebQueryWizardPage(TaskRepository repository, WebQuery query) {
81
	public WebQueryWizardPage(TaskRepository repository, WebQuery query) {
76
		super("New web query", query==null ? getDefaultQueryTitle(repository) : query.getDescription());
82
		super("New web query", query == null ? getDefaultQueryTitle(repository) : query.getDescription());
77
		this.repository = repository;
83
		this.repository = repository;
78
		this.query = query;
84
		this.query = query;
79
		setTitle("Create web query");
85
		setTitle("Create web query");
Lines 83-97 Link Here
83
	private static String getDefaultQueryTitle(TaskRepository repository) {
89
	private static String getDefaultQueryTitle(TaskRepository repository) {
84
		String label = repository.getRepositoryLabel();
90
		String label = repository.getRepositoryLabel();
85
		String title = label;
91
		String title = label;
86
		Set<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager().getTaskList().getRepositoryQueries(repository.getUrl());
92
		Set<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager().getTaskList().getRepositoryQueries(
87
	    for(int n = 1; true; n++) {
93
				repository.getUrl());
94
		for (int n = 1; true; n++) {
88
			for (AbstractRepositoryQuery query : queries) {
95
			for (AbstractRepositoryQuery query : queries) {
89
				if(query.getDescription().equals(title)) {
96
				if (query.getDescription().equals(title)) {
90
					title = label + " " + n;
97
					title = label + " " + n;
91
				}
98
				}
92
			}
99
			}
93
			return title;
100
			return title;
94
	    }
101
		}
95
	}
102
	}
96
103
97
	public void createControl(Composite parent) {
104
	public void createControl(Composite parent) {
Lines 105-121 Link Here
105
112
106
		super.createControl(composite);
113
		super.createControl(composite);
107
114
108
//		Label descriptionLabel = new Label(composite, SWT.NONE);
115
		// Label descriptionLabel = new Label(composite, SWT.NONE);
109
//		descriptionLabel.setLayoutData(new GridData());
116
		// descriptionLabel.setLayoutData(new GridData());
110
//		descriptionLabel.setText("Query Title:");
117
		// descriptionLabel.setText("Query Title:");
111
118
112
//		queryTitleText = new Text(composite, SWT.BORDER);
119
		// queryTitleText = new Text(composite, SWT.BORDER);
113
//		queryTitleText.addModifyListener(new ModifyListener() {
120
		// queryTitleText.addModifyListener(new ModifyListener() {
114
//			public void modifyText(ModifyEvent e) {
121
		// public void modifyText(ModifyEvent e) {
115
//				setPageComplete(isPageComplete());
122
		// setPageComplete(isPageComplete());
116
//			}
123
		// }
117
//		});
124
		// });
118
//		queryTitleText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
125
		// queryTitleText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
126
		// false));
119
127
120
		parametersEditor = new ParametersEditor(composite, SWT.NONE);
128
		parametersEditor = new ParametersEditor(composite, SWT.NONE);
121
		GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
129
		GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
Lines 123-129 Link Here
123
		gridData1.minimumHeight = 80;
131
		gridData1.minimumHeight = 80;
124
		parametersEditor.setLayoutData(gridData1);
132
		parametersEditor.setLayoutData(gridData1);
125
133
126
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT | Section.TWISTIE);
134
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
135
				| Section.TWISTIE);
127
		expComposite.setFont(parent.getFont());
136
		expComposite.setFont(parent.getFont());
128
		GridData gridData_1 = new GridData(SWT.FILL, SWT.FILL, true, false);
137
		GridData gridData_1 = new GridData(SWT.FILL, SWT.FILL, true, false);
129
		gridData_1.heightHint = 150;
138
		gridData_1.heightHint = 150;
Lines 161-173 Link Here
161
		gridData.heightHint = 45;
170
		gridData.heightHint = 45;
162
		queryPatternText.setLayoutData(gridData);
171
		queryPatternText.setLayoutData(gridData);
163
172
164
//		regexpText.addModifyListener(new ModifyListener() {
173
		// regexpText.addModifyListener(new ModifyListener() {
165
//				public void modifyText(final ModifyEvent e) {
174
		// public void modifyText(final ModifyEvent e) {
166
//					if(webPage!=null) {
175
		// if(webPage!=null) {
167
//						updatePreview();
176
		// updatePreview();
168
//					}
177
		// }
169
//				}
178
		// }
170
//			});
179
		// });
171
180
172
		Button preview = new Button(composite1, SWT.NONE);
181
		Button preview = new Button(composite1, SWT.NONE);
173
		preview.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
182
		preview.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
Lines 198-213 Link Here
198
207
199
		LinkedHashMap<String, String> vars = new LinkedHashMap<String, String>();
208
		LinkedHashMap<String, String> vars = new LinkedHashMap<String, String>();
200
		Map<String, String> params = new LinkedHashMap<String, String>();
209
		Map<String, String> params = new LinkedHashMap<String, String>();
201
		if(repository!=null) {
210
		if (repository != null) {
202
203
211
204
			queryUrlText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_URL)));
212
			queryUrlText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_URL)));
205
			queryPatternText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP)));
213
			queryPatternText
214
					.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP)));
206
215
207
			oldProperties = repository.getProperties();
216
			oldProperties = repository.getProperties();
208
			params.putAll(oldProperties);
217
			params.putAll(oldProperties);
209
		}
218
		}
210
		if(query!=null) {
219
		if (query != null) {
211
			setTitle(query.getDescription());
220
			setTitle(query.getDescription());
212
			queryUrlText.setText(addVars(vars, query.getUrl()));
221
			queryUrlText.setText(addVars(vars, query.getUrl()));
213
			queryPatternText.setText(addVars(vars, query.getQueryPattern()));
222
			queryPatternText.setText(addVars(vars, query.getQueryPattern()));
Lines 217-226 Link Here
217
	}
226
	}
218
227
219
	private static String addVars(LinkedHashMap<String, String> vars, String property) {
228
	private static String addVars(LinkedHashMap<String, String> vars, String property) {
220
		if(property==null) {
229
		if (property == null) {
221
			return "";
230
			return "";
222
		}
231
		}
223
		for(String var : WebRepositoryConnector.getTemplateVariables(property)) {
232
		for (String var : WebRepositoryConnector.getTemplateVariables(property)) {
224
			vars.put(var, "");
233
			vars.put(var, "");
225
		}
234
		}
226
		return property;
235
		return property;
Lines 232-279 Link Here
232
		String queryPattern = queryPatternText.getText();
241
		String queryPattern = queryPatternText.getText();
233
		Map<String, String> params = parametersEditor.getParameters();
242
		Map<String, String> params = parametersEditor.getParameters();
234
		return new WebQuery(TasksUiPlugin.getTaskListManager().getTaskList(), description, queryUrl, queryPattern,
243
		return new WebQuery(TasksUiPlugin.getTaskListManager().getTaskList(), description, queryUrl, queryPattern,
235
				repository.getProperty(WebRepositoryConnector.PROPERTY_TASK_URL),
244
				repository.getProperty(WebRepositoryConnector.PROPERTY_TASK_URL), repository.getUrl(), params);
236
				repository.getUrl(), params);
237
	}
245
	}
238
246
239
	synchronized void updatePreview() {
247
	synchronized void updatePreview() {
240
		if(updatePreviewJob==null) {
248
		if (updatePreviewJob == null) {
241
			updatePreviewJob = new UpdatePreviewJob("Updating preview");
249
			updatePreviewJob = new UpdatePreviewJob("Updating preview");
242
			updatePreviewJob.setPriority(Job.DECORATE);
250
			updatePreviewJob.setPriority(Job.DECORATE);
243
		}
251
		}
244
		updatePreviewJob.setParams(queryUrlText.getText(), queryPatternText.getText(), parametersEditor.getParameters());
252
		updatePreviewJob
245
		if(!updatePreviewJob.isActive()) {
253
				.setParams(queryUrlText.getText(), queryPatternText.getText(), parametersEditor.getParameters());
254
		if (!updatePreviewJob.isActive()) {
246
			updatePreviewJob.schedule();
255
			updatePreviewJob.schedule();
247
		}
256
		}
248
	}
257
	}
249
258
250
	public boolean isPageComplete() {
259
	public boolean isPageComplete() {
251
		if(getErrorMessage()!=null) {
260
		if (getErrorMessage() != null) {
252
			return false;
261
			return false;
253
		}
262
		}
254
		return super.isPageComplete();
263
		return super.isPageComplete();
255
	}
264
	}
256
265
257
	void updatePreviewTable(List<AbstractQueryHit> hits, MultiStatus queryStatus) {
266
	void updatePreviewTable(List<AbstractQueryHit> hits, MultiStatus queryStatus) {
258
		if(previewTable.isDisposed()) {
267
		if (previewTable.isDisposed()) {
259
			return;
268
			return;
260
		}
269
		}
261
270
262
		previewTable.removeAll();
271
		previewTable.removeAll();
263
272
264
		if(hits!=null) {
273
		if (hits != null) {
265
			for (AbstractQueryHit hit : hits) {
274
			for (AbstractQueryHit hit : hits) {
266
				TableItem item = new TableItem(previewTable, SWT.NONE);
275
				TableItem item = new TableItem(previewTable, SWT.NONE);
267
				if(hit.getId()!=null) {
276
				if (hit.getId() != null) {
268
					item.setText(0, hit.getId());
277
					item.setText(0, hit.getId());
269
					if(hit.getDescription()!=null) {
278
					if (hit.getDescription() != null) {
270
						item.setText(1, hit.getDescription());
279
						item.setText(1, hit.getDescription());
271
					}
280
					}
272
				}
281
				}
273
			}
282
			}
274
		}
283
		}
275
284
276
		if(queryStatus.isOK()) {
285
		if (queryStatus.isOK()) {
277
			setErrorMessage(null);
286
			setErrorMessage(null);
278
			setPageComplete(true);
287
			setPageComplete(true);
279
		} else {
288
		} else {
Lines 288-295 Link Here
288
297
289
	private final class UpdatePreviewJob extends Job {
298
	private final class UpdatePreviewJob extends Job {
290
		private volatile String url;
299
		private volatile String url;
300
291
		private volatile String regexp;
301
		private volatile String regexp;
302
292
		private volatile Map<String, String> params;
303
		private volatile Map<String, String> params;
304
293
		private volatile boolean active = false;
305
		private volatile boolean active = false;
294
306
295
		private UpdatePreviewJob(String name) {
307
		private UpdatePreviewJob(String name) {
Lines 312-342 Link Here
312
			String evaluatedUrl = WebRepositoryConnector.evaluateParams(url, params, repository);
324
			String evaluatedUrl = WebRepositoryConnector.evaluateParams(url, params, repository);
313
			active = true;
325
			active = true;
314
			do {
326
			do {
315
				final MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
327
				final MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result",
328
						null);
316
				final List<AbstractQueryHit> queryHits = new ArrayList<AbstractQueryHit>();
329
				final List<AbstractQueryHit> queryHits = new ArrayList<AbstractQueryHit>();
317
				try {
330
				try {
318
					if(webPage==null) {
331
					if (webPage == null) {
319
						webPage = WebRepositoryConnector.fetchResource(evaluatedUrl, repository.getUserName(), repository.getPassword());
332
						HashMap<String, String> loginParams = new HashMap<String, String>();
333
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL, WebRepositoryConnector
334
								.evaluateParams(repository.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL),
335
										params, repository));
336
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP, WebRepositoryConnector
337
								.evaluateParams(repository
338
										.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP), params,
339
										repository));
340
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD, WebRepositoryConnector
341
								.evaluateParams(repository
342
										.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD), params,
343
										repository));
344
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL, WebRepositoryConnector
345
								.evaluateParams(repository
346
										.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL), params,
347
										repository));
348
						for (Map.Entry<String, String> entry : repository.getProperties().entrySet()) {
349
							if (entry.getKey().startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
350
								loginParams.put(entry.getKey(), entry.getValue());
351
							}
352
						}
353
						webPage = WebRepositoryConnector.fetchResource(evaluatedUrl, repository.getUserName(),
354
								repository.getPassword(), loginParams, params, repository);
320
					}
355
					}
321
356
322
					QueryHitCollector collector = new QueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) {
357
					QueryHitCollector collector = new QueryHitCollector(TasksUiPlugin.getTaskListManager()
358
							.getTaskList()) {
323
						@Override
359
						@Override
324
						public void addMatch(AbstractQueryHit hit) {
360
						public void addMatch(AbstractQueryHit hit) {
325
							queryHits.add(hit);
361
							queryHits.add(hit);
326
						}
362
						}
327
					};
363
					};
328
364
329
					IStatus status = WebRepositoryConnector.performQuery(webPage, evaluatedRegexp, null, monitor, collector, repository);
365
					IStatus status = WebRepositoryConnector.performQuery(webPage, evaluatedRegexp, null, monitor,
330
					if(!status.isOK()) {
366
							collector, repository);
367
					if (!status.isOK()) {
331
						queryStatus.add(status);
368
						queryStatus.add(status);
332
					}
369
					}
333
370
334
				} catch (final IOException ex) {
371
				} catch (final IOException ex) {
335
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
372
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
336
							"Unable to fetch resource: "+ex.getMessage(), null));
373
							"Unable to fetch resource: " + ex.getMessage(), null));
337
				} catch (final Exception ex) {
374
				} catch (final Exception ex) {
338
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
375
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR, "Parsing error: "
339
							"Parsing error: "+ex.getMessage(), null));
376
							+ ex.getMessage(), null));
340
				}
377
				}
341
378
342
				Display.getDefault().asyncExec(new Runnable() {
379
				Display.getDefault().asyncExec(new Runnable() {
Lines 344-354 Link Here
344
						updatePreviewTable(queryHits, queryStatus);
381
						updatePreviewTable(queryHits, queryStatus);
345
					}
382
					}
346
				});
383
				});
347
			} while(!currentRegexp.equals(currentRegexp) && !monitor.isCanceled());
384
			} while (!currentRegexp.equals(currentRegexp) && !monitor.isCanceled());
348
			active = false;
385
			active = false;
349
			return Status.OK_STATUS;
386
			return Status.OK_STATUS;
350
		}
387
		}
351
	}
388
	}
352
389
353
}
390
}
354
(-)plugin.xml (+45 lines)
Lines 141-146 Link Here
141
        <attribute name="queryPattern"
141
        <attribute name="queryPattern"
142
                   value="&lt;tr .+?&lt;a href=&quot;view.php\?id=(.+?)&quot;&gt;.+?&lt;td class=&quot;left&quot;&gt;(.+?)&lt;/td&gt;&lt;/tr&gt;"/>
142
                   value="&lt;tr .+?&lt;a href=&quot;view.php\?id=(.+?)&quot;&gt;.+?&lt;td class=&quot;left&quot;&gt;(.+?)&lt;/td&gt;&lt;/tr&gt;"/>
143
     </repository>
143
     </repository>
144
     <repository
145
           anonymous="false"
146
           label="ChangeLogic"
147
           repositoryKind="web"
148
           urlNewTask="${serverUrl}/index.php?event=Add_task&amp;project_id=${projectId}"
149
           urlRepository="http://cvs.rm.sise/arendusweb"
150
           urlTask="${serverUrl}/index.php?event=Show_task&amp;task_id="
151
           urlTaskQuery="${serverUrl}/index.php?event=Show_task_list&amp;project_id=${projectId}">
152
        <attribute
153
              name="loginFormUrl"
154
              value="${serverUrl}">
155
        </attribute>
156
        <attribute
157
              name="loginTokenPattern"
158
              value="&lt;form name=&quot;Login_form&quot; method=&quot;POST&quot; action=&quot;index.php\?event\=Login&amp;amp;project_id\=0&amp;amp;link_uid\=(\p{Alnum}+?)\&quot;(?:.*?)&gt;">
159
        </attribute>
160
        <attribute
161
              name="loginRequestMethod"
162
              value="POST">
163
        </attribute>
164
        <attribute
165
              name="loginRequestUrl"
166
              value="${serverUrl}/index.php?event=Login">
167
        </attribute>
168
        <attribute
169
              name="queryPattern"
170
              value="&lt;a href=&quot;index.php\?event\=Show_task&amp;amp;task_id\=.+?&amp;amp;project_id\=${projectId}&amp;amp;recent_list_id=.+?&quot;&gt;(.+?)&lt;/a&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;(.+?)&lt;/td&gt;">
171
        </attribute>
172
        <attribute
173
              name="loginRequestParam_link_uid"
174
              value="${loginToken}">
175
        </attribute>
176
        <attribute
177
              name="loginRequestParam_username"
178
              value="${userId}">
179
        </attribute>
180
        <attribute
181
              name="loginRequestParam_password"
182
              value="${password}">
183
        </attribute>
184
        <attribute
185
              name="param_projectId"
186
              value="10">
187
        </attribute>
188
     </repository>
144
   </extension>
189
   </extension>
145
190
146
</plugin>
191
</plugin>
(-)src/org/eclipse/mylar/internal/tasks/web/restui/MethodTypeContentProvider.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere 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
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.IStructuredContentProvider;
14
import org.eclipse.jface.viewers.Viewer;
15
16
public class MethodTypeContentProvider implements IStructuredContentProvider {
17
18
	public Object[] getElements(Object inputElement) {
19
		return EMethodType.values();
20
	}
21
22
	public void dispose() {
23
	}
24
25
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
26
	}
27
28
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/EMethodType.java (+20 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere 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
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
/**
14
 * Represents a subset of HTTP methods: GET, POST (and multipart POST)
15
 * 
16
 * @author Erkki
17
 */
18
public enum EMethodType {
19
	GET, POST, POST_MULTIPART
20
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/NameValuePairLabelProvider.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere 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
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.ITableLabelProvider;
14
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.swt.graphics.Image;
16
17
public class NameValuePairLabelProvider extends LabelProvider implements
18
		ITableLabelProvider {
19
20
	public Image getColumnImage(Object element, int columnIndex) {
21
		return getImage(element);
22
	}
23
24
	public String getColumnText(Object element, int columnIndex) {
25
		if (element instanceof NameValuePair) {
26
			NameValuePair pair = (NameValuePair) element;
27
			switch (columnIndex) {
28
			case 0:
29
				return pair.getName();
30
			case 1:
31
				return pair.getValue();
32
			}
33
		}
34
		return getText(element);
35
	}
36
37
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/RESTRequestEditor.java (+251 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere 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
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.CellEditor;
14
import org.eclipse.jface.viewers.ComboViewer;
15
import org.eclipse.jface.viewers.ICellModifier;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.jface.viewers.TableViewer;
19
import org.eclipse.jface.viewers.TextCellEditor;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Group;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Table;
30
import org.eclipse.swt.widgets.TableColumn;
31
import org.eclipse.swt.widgets.TableItem;
32
import org.eclipse.swt.widgets.Text;
33
34
public class RESTRequestEditor extends Composite {
35
36
	private Label urlLabel = null;
37
	private Label methodLabel = null;
38
	private Text urlText = null;
39
	private Combo methodCombo = null;
40
	private Group parametersGroup = null;
41
	private Table parametersTable = null;
42
	private TableViewer parametersViewer = null;
43
	private Composite buttonsComposite = null;
44
	private Button addButton = null;
45
	private Button removeButton = null;
46
	private ComboViewer comboViewer = null;
47
48
	public RESTRequestEditor(Composite parent, int style) {
49
		super(parent, style);
50
		initialize();
51
	}
52
53
	private void initialize() {
54
		GridData gridData = new GridData();
55
		gridData.grabExcessHorizontalSpace = true;
56
		gridData.verticalAlignment = GridData.CENTER;
57
		gridData.horizontalAlignment = GridData.FILL;
58
		GridLayout gridLayout = new GridLayout();
59
		gridLayout.numColumns = 2;
60
		methodLabel = new Label(this, SWT.NONE);
61
		methodLabel.setText("Method:");
62
		createMethodCombo();
63
		urlLabel = new Label(this, SWT.NONE);
64
		urlLabel.setText("URL:");
65
		urlText = new Text(this, SWT.BORDER);
66
		urlText.setLayoutData(gridData);
67
		this.setLayout(gridLayout);
68
		createParametersGroup();
69
		setSize(new Point(300, 200));
70
	}
71
72
	/**
73
	 * This method initializes methodCombo
74
	 * 
75
	 */
76
	private void createMethodCombo() {
77
		methodCombo = new Combo(this, SWT.NONE);
78
		comboViewer = new ComboViewer(methodCombo);
79
		comboViewer.setContentProvider(new MethodTypeContentProvider());
80
		comboViewer.setInput(new Object());
81
		comboViewer.setLabelProvider(new MethodTypeLabelProvider());
82
	}
83
84
	/**
85
	 * This method initializes parametersGroup
86
	 * 
87
	 */
88
	private void createParametersGroup() {
89
		GridLayout gridLayout1 = new GridLayout();
90
		gridLayout1.numColumns = 2;
91
		GridData gridData2 = new GridData();
92
		gridData2.grabExcessHorizontalSpace = true;
93
		gridData2.horizontalAlignment = GridData.FILL;
94
		gridData2.verticalAlignment = GridData.FILL;
95
		gridData2.grabExcessVerticalSpace = true;
96
		GridData gridData1 = new GridData();
97
		gridData1.horizontalSpan = 2;
98
		gridData1.verticalAlignment = GridData.FILL;
99
		gridData1.grabExcessVerticalSpace = true;
100
		gridData1.horizontalAlignment = GridData.FILL;
101
		parametersGroup = new Group(this, SWT.NONE);
102
		parametersGroup.setText("Parameters");
103
		parametersGroup.setLayout(gridLayout1);
104
		parametersGroup.setLayoutData(gridData1);
105
		parametersTable = new Table(parametersGroup, SWT.BORDER
106
				| SWT.FULL_SELECTION | SWT.MULTI);
107
		parametersTable.setHeaderVisible(true);
108
		parametersTable.setLayoutData(gridData2);
109
		parametersTable.setLinesVisible(true);
110
		createButtonsComposite();
111
		TableColumn tableColumn = new TableColumn(parametersTable, SWT.NONE);
112
		tableColumn.setWidth(60);
113
		tableColumn.setText("Name");
114
		TableColumn tableColumn1 = new TableColumn(parametersTable, SWT.NONE);
115
		tableColumn1.setWidth(120);
116
		tableColumn1.setText("Value");
117
		parametersViewer = new TableViewer(parametersTable);
118
		parametersViewer.setLabelProvider(new NameValuePairLabelProvider());
119
		parametersViewer.setCellEditors(new CellEditor[] {
120
				new TextCellEditor(parametersTable),
121
				new TextCellEditor(parametersTable) });
122
		parametersViewer.setColumnProperties(new String[] { "name", "value" });
123
		parametersViewer.setCellModifier(new ICellModifier() {
124
125
			public boolean canModify(Object element, String property) {
126
				return true;
127
			}
128
129
			public Object getValue(Object element, String property) {
130
				if (element instanceof NameValuePair) {
131
					NameValuePair pair = (NameValuePair) element;
132
					if ("name".equals(property)) {
133
						return pair.getName();
134
					}
135
					if ("value".equals(property)) {
136
						return pair.getValue();
137
					}
138
				}
139
				return null;
140
			}
141
142
			public void modify(Object element, String property, Object value) {
143
				if (element instanceof TableItem) {
144
					TableItem item = (TableItem) element;
145
					element = item.getData();
146
				}
147
				if (element instanceof NameValuePair) {
148
					NameValuePair pair = (NameValuePair) element;
149
					if ("name".equals(property)) {
150
						pair.setName((String) value);
151
					}
152
					if ("value".equals(property)) {
153
						pair.setValue((String) value);
154
					}
155
					parametersViewer.refresh(element);
156
				}
157
			}
158
159
		});
160
	}
161
162
	/**
163
	 * This method initializes buttonsComposite
164
	 * 
165
	 */
166
	private void createButtonsComposite() {
167
		GridData gridData5 = new GridData();
168
		gridData5.horizontalAlignment = GridData.FILL;
169
		gridData5.verticalAlignment = GridData.CENTER;
170
		GridData gridData4 = new GridData();
171
		gridData4.horizontalAlignment = GridData.FILL;
172
		gridData4.verticalAlignment = GridData.CENTER;
173
		GridData gridData3 = new GridData();
174
		gridData3.horizontalAlignment = GridData.FILL;
175
		gridData3.verticalAlignment = GridData.FILL;
176
		buttonsComposite = new Composite(parametersGroup, SWT.NONE);
177
		buttonsComposite.setLayout(new GridLayout());
178
		buttonsComposite.setLayoutData(gridData3);
179
		addButton = new Button(buttonsComposite, SWT.NONE);
180
		addButton.setText("Add");
181
		addButton.setLayoutData(gridData4);
182
		addButton
183
				.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
184
					public void widgetSelected(
185
							org.eclipse.swt.events.SelectionEvent e) {
186
						IStructuredSelection selection = (IStructuredSelection) parametersViewer
187
								.getSelection();
188
						Object newObject = new NameValuePair("<name>",
189
						"<value>");
190
						if (! selection.isEmpty()) {
191
							int minIndex = -1;
192
							for (int i : parametersTable.getSelectionIndices()) {
193
								if (minIndex == -1 || i < minIndex) {
194
									minIndex = i;
195
								}
196
							}
197
							parametersViewer.insert(newObject, minIndex);
198
						} else {
199
							parametersViewer.add(newObject);
200
						}
201
					}
202
				});
203
		removeButton = new Button(buttonsComposite, SWT.NONE);
204
		removeButton.setText("Remove");
205
		removeButton.setLayoutData(gridData5);
206
		removeButton
207
				.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
208
					public void widgetSelected(
209
							org.eclipse.swt.events.SelectionEvent e) {
210
						IStructuredSelection selection = (IStructuredSelection) parametersViewer
211
								.getSelection();
212
						for (Object selected : selection.toArray()) {
213
							parametersViewer.remove(selected);
214
						}
215
					}
216
				});
217
	}
218
	
219
	public NameValuePair[] getParameters() {
220
		TableItem[] items = parametersTable.getItems(); 
221
		NameValuePair[] pairs = new NameValuePair[items.length];
222
		int i = 0;
223
		for (TableItem item : items) {
224
			pairs[i++] = (NameValuePair) item.getData();
225
		}
226
		return pairs;
227
	}
228
229
	public void setParameters(NameValuePair[] pairs) {
230
		parametersTable.removeAll();
231
		for (NameValuePair pair : pairs) {
232
			parametersViewer.add(pair);
233
		}
234
	}
235
	
236
	public String getUrl() {
237
		return urlText.getText();
238
	}
239
240
	public void setUrl(String url) {
241
		urlText.setText(url);
242
	}
243
	
244
	public EMethodType getMethod() {
245
		return (EMethodType) ((IStructuredSelection) comboViewer.getSelection()).getFirstElement();
246
	}
247
	
248
	public void setMethod(EMethodType method) {
249
		comboViewer.setSelection(new StructuredSelection(method));
250
	}
251
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/NameValuePair.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere 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
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import java.io.Serializable;
14
15
public class NameValuePair implements Serializable {
16
	private static final long serialVersionUID = 987600743855633022L;
17
	private String name;
18
	private String value;
19
20
	public NameValuePair(String name, String value) {
21
		super();
22
		this.name = name;
23
		this.value = value;
24
	}
25
26
	public String getName() {
27
		return name;
28
	}
29
30
	public void setName(String name) {
31
		this.name = name;
32
	}
33
34
	public String getValue() {
35
		return value;
36
	}
37
38
	public void setValue(String value) {
39
		this.value = value;
40
	}
41
42
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/MethodTypeLabelProvider.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere 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
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.LabelProvider;
14
15
public class MethodTypeLabelProvider extends LabelProvider {
16
17
	@Override
18
	public String getText(Object element) {
19
		if (element instanceof EMethodType) {
20
			EMethodType type = (EMethodType) element;
21
			switch (type) {
22
			case POST_MULTIPART:
23
				return "POST (Multipart)";
24
			default:
25
				return type.name();
26
			}
27
		}
28
		return super.getText(element);
29
	}
30
31
}

Return to bug 151602