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

import java.util.Map;

import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor;
import org.eclipse.sirius.diagram.ui.tools.internal.actions.SynchronizedDiagramAction;
import org.eclipse.sirius.ui.tools.internal.commands.AbstractActionWrapperHandler;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

/**
 * Toggle between synchronized and unsynchronized diagram modes.
 *
 * @author smonnier
 */
public class SynchronizedDiagramCommand extends AbstractActionWrapperHandler implements IElementUpdater {

    /**
     * Construct a new instance.
     */
    public SynchronizedDiagramCommand() {
        super(new SynchronizedDiagramAction());
    }

    /**
     * Update the synchronization contribution menu. {@inheritDoc}
     *
     * @see org.eclipse.ui.commands.IElementUpdater#updateElement(org.eclipse.ui.menus.UIElement,
     *      java.util.Map)
     */
    @Override
    public void updateElement(final UIElement element, final Map parameters) {
        final IWorkbenchWindow window = element.getServiceLocator().getService(IWorkbenchWindow.class);
        if (window == null) {
            return;
        }

        final IWorkbenchPage activePage = window.getActivePage();
        final IEditorPart activeEditor = activePage.getActiveEditor();
        if (activeEditor instanceof DDiagramEditor) {
            final DDiagramEditor ddiagramEditor = (DDiagramEditor) activeEditor;
            if (ddiagramEditor.getRepresentation() instanceof DDiagram) {
                final DDiagram diagram = (DDiagram) ddiagramEditor.getRepresentation();
                element.setChecked(!diagram.isSynchronized());
                element.setText(Messages.SynchronizedDiagramCommand_unsynchronizedLabel);
            }
        }
    }
}

Back to the top