Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7b27aea2316752dddaf928ca8e591a6d2a277003 (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
/*******************************************************************************
 * Copyright (c) 2013, 2014 THALES GLOBAL SERVICES.
 * 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:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.ui.tools.internal.actions.session;

import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.ui.tools.internal.editor.NavigateToCommand;
import org.eclipse.sirius.viewpoint.DRepresentation;

public final class OpenRepresentationAction extends Action {

    private final DRepresentation representation;

    private final Session session;

    private TransactionalEditingDomain editingDomain;

    /**
     * Constructor.
     * 
     * @param text
     *            the action's text, or <code>null</code> if there is no text
     * @param image
     *            the action's image, or <code>null</code> if there is no image
     * @param representation
     *            the representation to open. Caller has to check this is not a
     *            dangling representation, see {@link
     *            org.eclipse.sirius.business.api.query.DRepresentationQuery.
     *            isDanglingRepresentation()}.
     * @param session
     *            the session in which to open it.
     */
    public OpenRepresentationAction(String text, ImageDescriptor image, DRepresentation representation, Session session) {
        super(text, image);
        this.representation = representation;
        this.session = session;
        this.editingDomain = session.getTransactionalEditingDomain();
    }

    /**
     * Constructor.
     * 
     * @param representation
     *            the representation to open.
     * @param session
     *            the session in which to open it.
     */
    public OpenRepresentationAction(DRepresentation representation, Session session) {
        super();
        this.representation = representation;
        this.session = session;
        this.editingDomain = session.getTransactionalEditingDomain();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void run() {
        super.run();
        editingDomain.getCommandStack().execute(new NavigateToCommand(session, representation));
    }
}

Back to the top