Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 77ac587fd65066b15a3753aab9a75d44e97e6b13 (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
/*******************************************************************************
 * Copyright (c) 2005, 2013 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.viewers.model;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.internal.core.commands.Request;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputRequestor;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputUpdate;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.ui.progress.WorkbenchJob;

/**
 * Internal implementation of the {@link IViewerInputUpdate} interface.  Allows
 * implementors to translate the active debug context into an appropriate viewer
 * input.
 *
 * @since 3.4
 * @see IViewerInputUpdate
 */
public class ViewerInputUpdate extends Request implements IViewerInputUpdate {

    /**
     * Presentation context
     */
    private IPresentationContext fContext;

    /**
     * New viewer input
     */
    private Object fSource;

    /**
     * Whether this update is done
     */
    private boolean fDone;

    /**
     * Viewer input to use
     */
    private Object fInputElement;

    /**
     * Viewer input at the time the request was made
     */
    private Object fViewerInput;

    /**
     * Client making request
     */
    private IViewerInputRequestor fRequestor;

    /**
     * When <code>done()</code> is called, the viewer must be informed that the update is complete in the UI thread.
     */
    protected WorkbenchJob fViewerInputUpdateJob = new WorkbenchJob("Asynchronous viewer input update") { //$NON-NLS-1$
        @Override
		public IStatus runInUIThread(IProgressMonitor monitor) {
        	if (ViewerInputUpdate.this.isCanceled()){
        		return Status.CANCEL_STATUS;
        	}
            fRequestor.viewerInputComplete(ViewerInputUpdate.this);
            return Status.OK_STATUS;
        }
    };

    /**
     * Constructs a viewer input update request.
     *
     * @param context presentation context
     * @param viewerInput viewer input at the time the request was made
     * @param requestor client making the request
     * @param source source from which to derive a viewer input
     */
    public ViewerInputUpdate(IPresentationContext context, Object viewerInput, IViewerInputRequestor requestor, Object source){
    	fContext = context;
    	fSource = source;
    	fRequestor = requestor;
    	fViewerInputUpdateJob.setSystem(true);
    	fViewerInput = viewerInput;
    }

	@Override
	public IPresentationContext getPresentationContext() {
		return fContext;
	}

    @Override
	public final void done() {
    	synchronized (this) {
    		if (isDone()) {
    			return;
    		}
    		fDone = true;
		}
        fViewerInputUpdateJob.schedule();
	}

    /**
     * Returns whether this request is done yet.
     *
     * @return whether this request is done yet
     */
    protected synchronized boolean isDone() {
    	return fDone;
    }

	@Override
	public Object getElement() {
		return fSource;
	}

	@Override
	public TreePath getElementPath() {
		return TreePath.EMPTY;
	}

	@Override
	public void setInputElement(Object element) {
		fInputElement = element;
	}

	@Override
	public Object getInputElement() {
		return fInputElement;
	}

	@Override
	public Object getViewerInput() {
		return fViewerInput;
	}



}

Back to the top