Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6bbcfb24f9d3ba3f8a3d130ec23df279b55ebbe1 (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
/*******************************************************************************
 * Copyright (c) 2006, 2018 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.debug.internal.ui.viewers.model.ViewerStateTracker.IElementMementoCollector;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoRequest;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ITreeModelViewer;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IMemento;

/**
 * Request for element memento.
 *
 * @since 3.3
 */
class ElementMementoRequest extends MementoUpdate implements IElementMementoRequest {

	private IElementMementoCollector fManager;
	private ModelDelta fDelta;

	/**
     * @param provider the content provider to use for the update
     * @param viewerInput the current input
     * @param collector Collector to report the result to
     * @param element the element to update
     * @param elementPath the path of the element to update
	 * @param memento Memento to encode result into
	 * @param delta Delta to write the result comparison into.
	 */
	public ElementMementoRequest(TreeModelContentProvider provider, Object viewerInput, IElementMementoCollector collector, Object element, TreePath elementPath, IMemento memento, ModelDelta delta) {
		super(provider, viewerInput, provider.getPresentationContext(), element, elementPath, memento);
		fManager = collector;
		fDelta = delta;
	}

	@Override
	public void done() {
		ITreeModelViewer viewer = getContentProvider().getViewer();
		if (viewer == null) {
			return; // disposed
		}
		Display display = viewer.getDisplay();
		if (display != null) {
			if (display.getThread() == Thread.currentThread()) {
				doComplete();
			} else {
				display.asyncExec(this::doComplete);
			}
		}
	}

	private void doComplete() {
        if (getContentProvider().isDisposed()) {
			return;
		}

        if (!isCanceled() && (getStatus() == null || getStatus().isOK())) {
            // replace the element with a memento
            fDelta.setElement(getMemento());
        }
        fManager.requestComplete(ElementMementoRequest.this);
	}

	@Override
	public String toString() {
        StringBuffer buf = new StringBuffer();
        buf.append("IElementMementoRequest: "); //$NON-NLS-1$
        buf.append(getElement());
        return buf.toString();
	}
}

Back to the top