Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9e80c07a0194d1550112240e8c109658cd52bb76 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*****************************************************************
 * Copyright (c) 2009, 2013 Texas Instruments 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:
 *     Patrick Chuong (Texas Instruments) - Initial API and implementation (Bug 238956)
 *     Wind River Systems - ongoing enhancements and bug fixing
 *     IBM Corporation - bug fixing
 *****************************************************************/
package org.eclipse.debug.internal.ui.viewers.update;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.internal.ui.elements.adapters.DefaultBreakpointsViewInput;
import org.eclipse.debug.internal.ui.model.elements.BreakpointManagerContentProvider;
import org.eclipse.debug.internal.ui.viewers.model.ViewerAdapterService;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.progress.WorkbenchJob;

/**
 * Breakpoint manager model proxy.
 *
 * @since 3.6
 */
public class BreakpointManagerProxy extends AbstractModelProxy {
	/**
	 * The breakpoint manager content provider for this model proxy
	 */
	final private BreakpointManagerContentProvider fProvider;

	/**
	 * The breakpoint manager input for this model proxy
	 */
	final private DefaultBreakpointsViewInput fInput;

	/**
	 * Job to fire posted deltas.
	 */
    private Job fFireModelChangedJob;

    /**
     * Object used for describing a posted delta.
     */
    private static class DeltaInfo {
        final boolean fSelect;
        final IModelDelta fDelta;

        DeltaInfo(boolean selectDelta, IModelDelta delta) {
            fSelect = selectDelta;
            fDelta = delta;
        }
    }

    /**
     * List of posted deltas ready to be fired.
     */
	private List<DeltaInfo> fPendingDeltas = new LinkedList<DeltaInfo>();


	/**
	 * Constructor.
	 *
	 * @param input the breakpoint manager input
	 * @param context the presentation context for this model proxy
	 */
	public BreakpointManagerProxy(Object input, IPresentationContext context) {
		super();

		DefaultBreakpointsViewInput bpmInput = null;
		BreakpointManagerContentProvider bpmProvider = null;
		if (input instanceof DefaultBreakpointsViewInput) {
			bpmInput = (DefaultBreakpointsViewInput) input;

			// cache the required data and pass to the provider when this model is installed
			IElementContentProvider provider = ViewerAdapterService.getContentProvider(input);
			if (provider instanceof BreakpointManagerContentProvider) {
				bpmProvider = (BreakpointManagerContentProvider) provider;
			}
		}
		fInput = bpmInput;
		fProvider = bpmProvider;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy#installed(org.eclipse.jface.viewers.Viewer)
	 */
	@Override
	public void installed(Viewer viewer) {
		super.installed(viewer);
		if (fProvider != null) {
			fProvider.registerModelProxy(fInput, this);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy#dispose()
	 */
	@Override
	public void dispose() {
	    fProvider.unregisterModelProxy(fInput, this);
	    synchronized(this) {
	        if (fFireModelChangedJob != null) {
                fFireModelChangedJob.cancel();
                fFireModelChangedJob = null;
	        }
            fPendingDeltas.clear();
	    }

		super.dispose();
	}

	/**
	 * Posts a given delta to be fired by the proxy.  Posting a delta places it
	 * in a queue which is later emptied by a job that fires the deltas.
	 * <p>
	 * If the delta is used only to select a breakpiont and does not change the
	 * viewer content, the caller should set the <code>select</code> parameter
	 * to <code>true</code>.  When a select delta is added to the delta queue,
	 * any previous select deltas are removed.
	 *
	 * @param delta Delta to be posted to the viewer.
	 * @param select Flag indicating that the delta is only to change the
	 * viewer selection.
	 */
	public synchronized void postModelChanged(IModelDelta delta, boolean select) {
        // Check for proxy being disposed.
        if (isDisposed()) {
            return;
        }
        // Check for viewer being disposed.
        Widget viewerControl = getViewer().getControl();
        if (viewerControl == null) {
            return;
        }

        // If we are processing a select delta, remove the previous select delta.
        if (select) {
			for (Iterator<DeltaInfo> itr = fPendingDeltas.iterator(); itr.hasNext();) {
                if ( itr.next().fSelect ) {
                    itr.remove();
                }
            }
        }
        fPendingDeltas.add(new DeltaInfo(select, delta));

        if (fFireModelChangedJob == null) {
	        fFireModelChangedJob = new WorkbenchJob(viewerControl.getDisplay(), "Select Breakpoint Job") { //$NON-NLS-1$
	            {
	                setSystem(true);
	            }

	            @Override
				public IStatus runInUIThread(IProgressMonitor monitor) {
                    Object[] deltas;
                    synchronized(BreakpointManagerProxy.this) {
                        deltas = fPendingDeltas.toArray();
                        fPendingDeltas.clear();
                        fFireModelChangedJob = null;
                    }
                    for (int i = 0; i < deltas.length; i++) {
                        fireModelChanged( ((DeltaInfo)deltas[i]).fDelta );
                    }
                    return Status.OK_STATUS;
                }
            };
            fFireModelChangedJob.schedule();
	    }
	}

}

Back to the top