01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.ui.tests.search;
11:
12: import java.util.Random;
13: import org.eclipse.core.runtime.CoreException;
14: import org.eclipse.core.runtime.IProgressMonitor;
15: import org.eclipse.jdt.internal.ui.JavaPluginImages;
16: import org.eclipse.jdt.ui.ISharedImages;
17: import org.eclipse.jdt.ui.search.IQueryParticipant;
18: import org.eclipse.jdt.ui.search.ISearchRequestor;
19: import org.eclipse.jdt.ui.search.IMatchPresentation;
20: import org.eclipse.jdt.ui.search.QuerySpecification;
21: import org.eclipse.jface.dialogs.MessageDialog;
22: import org.eclipse.jface.viewers.ILabelProvider;
23: import org.eclipse.jface.viewers.LabelProvider;
24: import org.eclipse.search.ui.text.Match;
25: import org.eclipse.swt.graphics.Image;
26: import org.eclipse.ui.PartInitException;
27:
28: /**
29: */
30: public class TestParticipant implements IQueryParticipant {
31: private static final Random fgRandom = new Random();
32: private IMatchPresentation fUIParticipant;
33:
34: public TestParticipant() {
35: fUIParticipant = new TestUIParticipant();
36: }
37:
38: public void search(ISearchRequestor requestor,
39: QuerySpecification data, IProgressMonitor monitor)
40: throws CoreException {
41: for (int i = 0; i < 20; i++) {
42: requestor.reportMatch(new Match(new Integer(fgRandom
43: .nextInt()), -1, -1));
44: }
45: }
46:
47: public int estimateTicks(QuerySpecification data) {
48: return 100;
49: }
50:
51: public IMatchPresentation getUIParticipant() {
52: return fUIParticipant;
53: }
54:
55: }
56:
57: class TestLabelProvider extends LabelProvider {
58: public Image getImage(Object element) {
59: return JavaPluginImages.get(ISharedImages.IMG_OBJS_PROTECTED);
60: }
61:
62: public String getText(Object element) {
63: return "Int: value= " + ((Integer) element).toString();
64: }
65: }
66:
67: class TestUIParticipant implements IMatchPresentation {
68:
69: public void showMatch(Match match, int currentOffset,
70: int currentLength, boolean activate)
71: throws PartInitException {
72: MessageDialog.openInformation(null, "Showing element",
73: "Showning an integer of value: "
74: + ((Integer) match.getElement()).intValue());
75:
76: }
77:
78: public ILabelProvider createLabelProvider() {
79: return new TestLabelProvider();
80: }
81:
82: }
|