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 153539
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+1 lines)
Lines 7-12 Link Here
7
Bundle-Vendor: Eclipse.org
7
Bundle-Vendor: Eclipse.org
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Require-Bundle: org.eclipse.ui,
9
Require-Bundle: org.eclipse.ui,
10
 org.eclipse.ui.forms,
10
 org.eclipse.core.runtime,
11
 org.eclipse.core.runtime,
11
 org.eclipse.mylar.context.core,
12
 org.eclipse.mylar.context.core,
12
 org.eclipse.mylar.tasks.ui,
13
 org.eclipse.mylar.tasks.ui,
(-)src/org/eclipse/mylar/internal/trac/TracRepositoryConnector.java (-1 / +1 lines)
Lines 308-314 Link Here
308
308
309
	@Override
309
	@Override
310
	public boolean hasSearchPage() {
310
	public boolean hasSearchPage() {
311
		return false;
311
		return true;
312
	}
312
	}
313
313
314
}
314
}
(-)src/org/eclipse/mylar/internal/trac/ui/wizard/TracCustomQueryPage.java (-9 / +62 lines)
Lines 15-25 Link Here
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.Map;
16
import java.util.Map;
17
17
18
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.operation.IRunnableWithProgress;
21
import org.eclipse.jface.operation.IRunnableWithProgress;
21
import org.eclipse.mylar.context.core.MylarStatusHandler;
22
import org.eclipse.mylar.context.core.MylarStatusHandler;
22
import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositoryQueryPage;
23
import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositoryQueryPage;
24
import org.eclipse.mylar.internal.tasks.ui.search.RepositorySearchResult;
23
import org.eclipse.mylar.internal.trac.TracRepositoryConnector;
25
import org.eclipse.mylar.internal.trac.TracRepositoryConnector;
24
import org.eclipse.mylar.internal.trac.TracRepositoryQuery;
26
import org.eclipse.mylar.internal.trac.TracRepositoryQuery;
25
import org.eclipse.mylar.internal.trac.TracUiPlugin;
27
import org.eclipse.mylar.internal.trac.TracUiPlugin;
Lines 28-37 Link Here
28
import org.eclipse.mylar.internal.trac.model.TracSearch;
30
import org.eclipse.mylar.internal.trac.model.TracSearch;
29
import org.eclipse.mylar.internal.trac.model.TracSearchFilter;
31
import org.eclipse.mylar.internal.trac.model.TracSearchFilter;
30
import org.eclipse.mylar.internal.trac.model.TracSearchFilter.CompareOperator;
32
import org.eclipse.mylar.internal.trac.model.TracSearchFilter.CompareOperator;
33
import org.eclipse.mylar.internal.trac.ui.search.AbstractQueryHitCollector;
34
import org.eclipse.mylar.internal.trac.ui.search.IQueryHitCollector;
35
import org.eclipse.mylar.internal.trac.ui.search.RepositorySearchQuery;
36
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
31
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
37
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
32
import org.eclipse.mylar.tasks.core.TaskRepository;
38
import org.eclipse.mylar.tasks.core.TaskRepository;
33
import org.eclipse.mylar.tasks.ui.TaskRepositoryManager;
39
import org.eclipse.mylar.tasks.ui.TaskRepositoryManager;
34
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
40
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
41
import org.eclipse.search.ui.NewSearchUI;
42
import org.eclipse.search.ui.text.Match;
35
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.events.KeyEvent;
44
import org.eclipse.swt.events.KeyEvent;
37
import org.eclipse.swt.events.KeyListener;
45
import org.eclipse.swt.events.KeyListener;
Lines 120-126 Link Here
120
	}
128
	}
121
129
122
	public void createControl(Composite parent) {
130
	public void createControl(Composite parent) {
123
		
131
124
		Composite control = new Composite(parent, SWT.NONE);
132
		Composite control = new Composite(parent, SWT.NONE);
125
		GridData gd = new GridData(GridData.FILL_BOTH);
133
		GridData gd = new GridData(GridData.FILL_BOTH);
126
		control.setLayoutData(gd);
134
		control.setLayoutData(gd);
Lines 128-134 Link Here
128
		control.setLayout(layout);
136
		control.setLayout(layout);
129
137
130
		createTitleGroup(control);
138
		createTitleGroup(control);
131
		
139
132
		summaryField = new TextSearchField("summary");
140
		summaryField = new TextSearchField("summary");
133
		summaryField.createControls(control, "Summary");
141
		summaryField.createControls(control, "Summary");
134
142
Lines 169-179 Link Here
169
	}
177
	}
170
178
171
	private void createTitleGroup(Composite control) {
179
	private void createTitleGroup(Composite control) {
172
		// Group group = new Group(composite, SWT.NONE);
180
		if (inSearchContainer()) {
173
		// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
181
			return;
174
		// group.setText(TITLE_QUERY_TITLE);
182
		}
175
		// group.setLayout(new GridLayout(1, false));
183
176
		if(inSearchContainer()) return;
177
		Label titleLabel = new Label(control, SWT.NONE);
184
		Label titleLabel = new Label(control, SWT.NONE);
178
		titleLabel.setText(TITLE_QUERY_TITLE);
185
		titleLabel.setText(TITLE_QUERY_TITLE);
179
186
Lines 306-311 Link Here
306
		return group;
313
		return group;
307
	}
314
	}
308
315
316
	@Override
317
	public void setVisible(boolean visible) {
318
		super.setVisible(visible);
319
		
320
		if (scontainer != null) {
321
			scontainer.setPerformActionEnabled(true);
322
		}
323
	}
324
	
309
	private void updateAttributesFromRepository(boolean connect) {
325
	private void updateAttributesFromRepository(boolean connect) {
310
		TracRepositoryConnector connector = (TracRepositoryConnector) TasksUiPlugin.getRepositoryManager()
326
		TracRepositoryConnector connector = (TracRepositoryConnector) TasksUiPlugin.getRepositoryManager()
311
				.getRepositoryConnector(TracUiPlugin.REPOSITORY_KIND);
327
				.getRepositoryConnector(TracUiPlugin.REPOSITORY_KIND);
Lines 386-395 Link Here
386
	}
402
	}
387
403
388
	public TracRepositoryQuery getQuery() {
404
	public TracRepositoryQuery getQuery() {
389
		return new TracRepositoryQuery(repository.getUrl(), getQueryUrl(repository.getUrl()), titleText.getText(),
405
		return new TracRepositoryQuery(repository.getUrl(), getQueryUrl(repository.getUrl()), getTitleText(),
390
				TasksUiPlugin.getTaskListManager().getTaskList());
406
				TasksUiPlugin.getTaskListManager().getTaskList());
391
	}
407
	}
392
408
409
	private String getTitleText() {
410
		return (titleText != null) ? titleText.getText() : "<search>";
411
	}
412
413
	public boolean performAction() {
414
		if (repository == null) {
415
			MessageDialog.openInformation(Display.getCurrent().getActiveShell(), TracUiPlugin.TITLE_MESSAGE_DIALOG,
416
					TaskRepositoryManager.MESSAGE_NO_REPOSITORY);
417
			return false;
418
		}
419
420
		final RepositorySearchQuery searchQuery = new RepositorySearchQuery(repository, getQuery());
421
		IQueryHitCollector collector = new AbstractQueryHitCollector() {
422
			
423
			private RepositorySearchResult searchResult;
424
425
			@Override
426
			public void aboutToStart(int startMatchCount) throws CoreException {
427
				super.aboutToStart(startMatchCount);
428
429
				NewSearchUI.activateSearchResultView();
430
				searchResult = (RepositorySearchResult) searchQuery.getSearchResult();
431
				searchResult.removeAll();
432
			}
433
434
			@Override
435
			public void addMatch(AbstractQueryHit hit) {
436
				searchResult.addMatch(new Match(hit, 0, 0));
437
			}
438
439
		};
440
		searchQuery.setCollector(collector);
441
		NewSearchUI.runQueryInBackground(searchQuery);
442
443
		return true;
444
	}
445
393
	private abstract class SearchField {
446
	private abstract class SearchField {
394
447
395
		protected String fieldName;
448
		protected String fieldName;
Lines 553-556 Link Here
553
606
554
	}
607
	}
555
608
556
}
609
}
(-)src/org/eclipse/mylar/internal/trac/ui/search/IQueryHitCollector.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia 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
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.trac.ui.search;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
17
18
/**
19
 * Interface for the Mylar search result collector.
20
 * 
21
 * @author Shawn Minto
22
 */
23
public interface IQueryHitCollector {
24
25
	/**
26
	 * Called before the actual search starts.
27
	 * 
28
	 * @param startCount -
29
	 *            The starting count for the number of matches
30
	 * @throws CoreException
31
	 */
32
	public void aboutToStart(int startCount) throws CoreException;
33
34
	/**
35
	 * Accept a search hit and add it as a match and set the markers.
36
	 * 
37
	 * @param hit
38
	 *            The search hit that was a match
39
	 * @throws CoreException
40
	 */
41
	public void accept(AbstractQueryHit hit) throws CoreException;
42
43
	/**
44
	 * Called when the search has ended.
45
	 */
46
	public void done();
47
48
	/**
49
	 * Get the progress monitor for the search.
50
	 * 
51
	 * @return The progress monitor
52
	 */
53
	public IProgressMonitor getProgressMonitor();
54
55
	/**
56
	 * Set the progress monitor.
57
	 * 
58
	 * @param monitor
59
	 *            The progress monitor the search should use
60
	 */
61
	public void setProgressMonitor(IProgressMonitor monitor);
62
63
}
(-)src/org/eclipse/mylar/internal/trac/ui/search/AbstractQueryHitCollector.java (+102 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia 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
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.trac.ui.search;
12
13
import java.text.MessageFormat;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
18
19
/**
20
 * Collects results of a search.
21
 */
22
public abstract class AbstractQueryHitCollector implements IQueryHitCollector {
23
24
	/** The progress monitor for the search operation */
25
	private IProgressMonitor monitor;
26
27
	/** The number of matches found */
28
	private int matchCount;
29
30
	/** The string to display to the user while querying */
31
	private static final String STARTING = "querying the server";
32
33
	/** The string to display to the user when we have 1 match */
34
	private static final String MATCH = "1 match";
35
36
	/** The string to display to the user when we have multiple or no matches */
37
	private static final String MATCHES = "{0} matches";
38
39
	/** The string to display to the user when the query is done */
40
	private static final String DONE = "done";
41
42
	public void aboutToStart(int startMatchCount) throws CoreException {
43
		matchCount = startMatchCount;
44
45
		// set the progress monitor to say that we are querying the server
46
		monitor.setTaskName(STARTING);
47
	}
48
49
	public void accept(AbstractQueryHit hit) throws CoreException {
50
		addMatch(hit);
51
		
52
		// increment the match count
53
		matchCount++;
54
55
		if (!getProgressMonitor().isCanceled()) {
56
			// if the operation is cancelled finish with whatever data was
57
			// already found
58
			getProgressMonitor().subTask(getFormattedMatchesString(matchCount));
59
			getProgressMonitor().worked(1);
60
		}
61
	}
62
63
	public abstract void addMatch(AbstractQueryHit hit);
64
65
	public void done() {
66
		if (!monitor.isCanceled()) {
67
			// if the operation is cancelled, finish with the data that we
68
			// already have
69
			String matchesString = getFormattedMatchesString(matchCount);
70
			monitor.setTaskName(MessageFormat.format(DONE, new Object[] { matchesString }));
71
		}
72
73
		// Cut no longer used references because the collector might be re-used
74
		monitor = null;
75
	}
76
77
	/**
78
	 * Get the string specifying the number of matches found
79
	 * 
80
	 * @param count
81
	 *            The number of matches found
82
	 * @return The <code>String</code> specifying the number of matches found
83
	 */
84
	protected String getFormattedMatchesString(int count) {
85
		// if only 1 match, return the singular match string
86
		if (count == 1)
87
			return MATCH;
88
89
		// format the matches string and return it
90
		Object[] messageFormatArgs = { new Integer(count) };
91
		return MessageFormat.format(MATCHES, messageFormatArgs);
92
	}
93
94
	public IProgressMonitor getProgressMonitor() {
95
		return monitor;
96
	}
97
98
	public void setProgressMonitor(IProgressMonitor monitor) {
99
		this.monitor = monitor;
100
	}
101
102
}
(-)src/org/eclipse/mylar/internal/trac/ui/search/RepositorySearchQuery.java (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia 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
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.trac.ui.search;
13
14
import java.util.List;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.MultiStatus;
20
import org.eclipse.core.runtime.OperationCanceledException;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jface.dialogs.ErrorDialog;
23
import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery;
24
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
25
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
26
import org.eclipse.mylar.tasks.core.TaskRepository;
27
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector;
28
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
29
import org.eclipse.ui.PlatformUI;
30
31
/**
32
 * This class performs a search query.
33
 * 
34
 * @author Steffen Pingel
35
 */
36
public class RepositorySearchQuery extends AbstractRepositorySearchQuery {
37
38
	private IQueryHitCollector collector;
39
40
	private TaskRepository repository;
41
42
	private AbstractRepositoryQuery query;
43
44
	public RepositorySearchQuery(TaskRepository repository, AbstractRepositoryQuery query) {
45
		this.repository = repository;
46
		this.query = query;
47
	}
48
49
	public IQueryHitCollector getCollector() {
50
		return collector;
51
	}
52
53
	public void setCollector(IQueryHitCollector collector) {
54
		this.collector = collector;
55
	}
56
57
	public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
58
		MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
59
		try {
60
			collector.setProgressMonitor(monitor);
61
			collector.aboutToStart(0);
62
63
			AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
64
					repository.getKind());
65
66
			// TODO pass collector to performQuery() so results show up right away
67
			List<AbstractQueryHit> result = connector.performQuery(query, monitor, queryStatus);
68
			for (AbstractQueryHit hit : result) {
69
				collector.accept(hit);
70
			}
71
			collector.done();
72
		} catch (final CoreException e) {
73
			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
74
				public void run() {
75
					ErrorDialog.openError(null, "Repository Search Error", null, e.getStatus());
76
				}
77
			});
78
			return Status.OK_STATUS;
79
		}
80
81
		final IStatus status = queryStatus.getChildren()[0];
82
		if (status.getCode() == IStatus.CANCEL) {
83
			return Status.OK_STATUS;
84
		} else if (!status.isOK()) {
85
			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
86
				public void run() {
87
					ErrorDialog.openError(null, "Repository Search Error", null, status);
88
				}
89
			});
90
			return Status.OK_STATUS;
91
		}
92
		return status;
93
	}
94
}

Return to bug 153539