Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 350f1a998cc97596747915ec85bf93f097cc56c6 (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
/*******************************************************************************
 * Copyright (c) 2010, 2010 THALES GLOBAL SERVICES.
 * 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:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.policies;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.requests.ChangeBoundsRequest;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

/**
 * Records all requests that are sent to the given edit part and all its
 * children.
 * 
 * @author ymortier
 */
public class ChangeBoundRequestRecorder {

    /** All recorded requests. */
    private Multimap<EditPart, ChangeBoundsRequest> allRequests = HashMultimap.create();

    /** <code>true</code> if the recorder is recording. */
    private boolean recording;

    /**
     * Creates a new Request recorder. All requests sent to <code>root</code>
     * and its children will be registered.
     * 
     */
    public ChangeBoundRequestRecorder() {
    }

    /**
     * Start to record the ChangeBoundRequests.
     */
    public void startRecording() {
        recording = true;
        allRequests = HashMultimap.create();
    }

    /**
     * Stops the recorder.
     */
    public void stopRecording() {
        recording = false;
    }

    /**
     * Returns <code>true</code> if the recorder is recording.
     * 
     * @return <code>true</code> if the recorder is recording.
     */
    public boolean isRecording() {
        return recording;
    }

    /**
     * Returns all recorded requests.
     * 
     * @return all recorded requests.
     */
    public Multimap<EditPart, ChangeBoundsRequest> getAllRequests() {
        return this.allRequests;
    }

    /**
     * Tell the recorder to process the request. If active it will record it,
     * otherwise it will just ignore it.
     * 
     * @param request
     *            request to process.
     * @param host
     *            the editpart which has received the request.
     */
    public void processRequest(Request request, EditPart host) {
        if (isRecording() && request instanceof ChangeBoundsRequest) {
            allRequests.put(host, (ChangeBoundsRequest) request);
        }

    }

    /**
     * Disposes the recorder.
     */
    public void dispose() {
        if (isRecording()) {
            this.stopRecording();
        }
        if (this.allRequests != null) {
            this.allRequests.clear();
        }
        this.allRequests = null;
    }

}

Back to the top