01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 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.ui.internal.progress;
11:
12: import org.eclipse.jface.viewers.IStructuredContentProvider;
13: import org.eclipse.jface.viewers.Viewer;
14:
15: /**
16: * The ProgressContentProvider is the content provider used for classes that
17: * listen to the progress changes.
18: */
19: public abstract class ProgressContentProvider implements
20: IProgressUpdateCollector, IStructuredContentProvider {
21:
22: /**
23: * Return whether or not we check the preferences or overide.
24: */
25: private boolean canShowDebug = false;
26:
27: /**
28: * Create a new instance of the receiver with all of the
29: * default values.
30: */
31: public ProgressContentProvider() {
32: ProgressViewUpdater.getSingleton().addCollector(this );
33: }
34:
35: /**
36: * Create a new instance of the receiver with a flag to
37: * indicate if there will be debug info shown or not.
38: * @param debug If true debug information will be shown
39: * if the debug flag in the ProgressManager is true.
40: */
41: public ProgressContentProvider(boolean debug) {
42: this ();
43: canShowDebug = debug;
44: }
45:
46: /*
47: * (non-Javadoc)
48: *
49: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
50: */
51: public Object[] getElements(Object inputElement) {
52:
53: return ProgressManager.getInstance().getRootElements(debug());
54: }
55:
56: /*
57: * (non-Javadoc)
58: *
59: * @see org.eclipse.jface.viewers.IContentProvider#dispose()
60: */
61: public void dispose() {
62: ProgressViewUpdater.getSingleton().removeCollector(this );
63: }
64:
65: /*
66: * (non-Javadoc)
67: *
68: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
69: * java.lang.Object, java.lang.Object)
70: */
71: public void inputChanged(Viewer viewer, Object oldInput,
72: Object newInput) {
73: //No change when input changes
74: }
75:
76: /**
77: * Return whether or not we are debugging. Check the
78: * system settings unless we are overiding them.
79: * @return boolean <code>true</code> if debug
80: * (system) jobs are being shown.
81: */
82: public boolean debug() {
83: if (!canShowDebug) {
84: return false;
85: }
86: return ProgressViewUpdater.getSingleton().debug;
87:
88: }
89:
90: }
|