Skip to main content
summaryrefslogtreecommitdiffstats
blob: f6da665c124c75176d1e0b836b40e6e2947ead52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.internal.bugzilla.ui;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaContentProvider;
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaSearchResult;
import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchResultView;
import org.eclipse.search.internal.ui.SearchPreferencePage;

/**
 * This implementation of <code>BugzillaContentProvider</code> is used for the
 * table view of a Bugzilla search result.
 */
public class BugzillaTableContentProvider extends BugzillaContentProvider implements IStructuredContentProvider {

	/** The page the Bugzilla search results are displayed in */
	private BugzillaSearchResultView bugPage;

	/**
	 * Constructor
	 * 
	 * @param page
	 *            The page the Bugzilla search results are displayed in
	 */
	public BugzillaTableContentProvider(BugzillaSearchResultView page) {
		bugPage = page;
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		if (newInput instanceof BugzillaSearchResult) {
			bugResult = (BugzillaSearchResult) newInput;
		}
	}

	@Override
	public void elementsChanged(Object[] updatedElements) {
		TableViewer viewer = getViewer();
		boolean tableLimited = SearchPreferencePage.isTableLimited();
		for (int i = 0; i < updatedElements.length; i++) {
			if (bugResult.getMatchCount(updatedElements[i]) > 0) {
				if (viewer.testFindItem(updatedElements[i]) != null)
					viewer.update(updatedElements[i], null);
				else {
					if (!tableLimited || viewer.getTable().getItemCount() < SearchPreferencePage.getTableLimit())
						viewer.add(updatedElements[i]);
				}
			} else
				viewer.remove(updatedElements[i]);
		}
	}

	/**
	 * Returns the viewer the bug results are displayed in.
	 */
	private TableViewer getViewer() {
		return (TableViewer) bugPage.getViewer();
	}

	@Override
	public void clear() {
		getViewer().refresh();
	}

	/**
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 */
	public Object[] getElements(Object inputElement) {
		if (inputElement instanceof BugzillaSearchResult) {
			Object[] elements = ((BugzillaSearchResult) inputElement).getElements();
			int tableLimit = SearchPreferencePage.getTableLimit();
			if (SearchPreferencePage.isTableLimited() && elements.length > tableLimit) {
				Object[] shownElements = new Object[tableLimit];
				System.arraycopy(elements, 0, shownElements, 0, tableLimit);
				return shownElements;
			}
			return elements;
		}
		return EMPTY_ARR;
	}

}

Back to the top