2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Vincent COUVERT
4 * Copyright (C) 2010 - DIGITEO - Clement DAVID
5 * Copyright (C) 2011-2015 - Scilab Enterprises - Clement DAVID
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
18 package org.scilab.modules.xcos.block.actions;
20 import java.awt.Toolkit;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.KeyEvent;
24 import org.scilab.modules.graph.ScilabGraph;
25 import org.scilab.modules.graph.actions.base.DefaultAction;
26 import org.scilab.modules.gui.menuitem.MenuItem;
27 import org.scilab.modules.xcos.JavaController;
28 import org.scilab.modules.xcos.Kind;
29 import org.scilab.modules.xcos.ObjectProperties;
30 import org.scilab.modules.xcos.Xcos;
31 import org.scilab.modules.xcos.XcosTab;
32 import org.scilab.modules.xcos.XcosView;
33 import org.scilab.modules.xcos.graph.XcosDiagram;
34 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
35 import org.scilab.modules.xcos.graph.model.XcosCell;
36 import org.scilab.modules.xcos.graph.model.XcosCellFactory;
37 import org.scilab.modules.xcos.utils.XcosMessages;
40 * Show the parent graph (only installed on a {@link SuperBlockDiagram})
42 @SuppressWarnings(value = { "serial" })
43 public class ShowParentAction extends DefaultAction {
44 /** Name of the action */
45 public static final String NAME = XcosMessages.SHOW_PARENT;
46 /** Icon name of the action */
47 public static final String SMALL_ICON = "";
48 /** Mnemonic key of the action */
49 public static final int MNEMONIC_KEY = KeyEvent.VK_HOME;
50 /** Accelerator key for the action */
51 public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
59 public ShowParentAction(ScilabGraph scilabGraph) {
64 * Menu added to the menubar
70 public static MenuItem createMenu(ScilabGraph scilabGraph) {
71 return createMenu(scilabGraph, ShowParentAction.class);
77 * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
80 public void actionPerformed(ActionEvent e) {
81 final XcosDiagram graph = (XcosDiagram) getGraph(e);
83 if (graph.getKind() == Kind.BLOCK) {
84 JavaController controller = new JavaController();
86 XcosCell defaultParent = (XcosCell) graph.getDefaultParent();
87 XcosDiagram parentGraph = Xcos.findParent(controller, defaultParent.getUID(), defaultParent.getKind());
89 // the parent graph is not visible yet, load it into the UI
90 if (parentGraph == null) {
92 Kind parentKind = Kind.BLOCK;
94 // use parent / children model property
95 controller.getObjectProperty(defaultParent.getUID(), defaultParent.getKind(), ObjectProperties.PARENT_BLOCK, parent);
97 parentKind = Kind.DIAGRAM;
98 controller.getObjectProperty(defaultParent.getUID(), defaultParent.getKind(), ObjectProperties.PARENT_DIAGRAM, parent);
101 parentGraph = new XcosDiagram(controller, parent[0], parentKind, "");
102 XcosCellFactory.insertChildren(controller, parentGraph);
103 parentGraph.installListeners();
105 Xcos.getInstance().addDiagram(Xcos.findRoot(controller, graph), parentGraph);
108 // restore the parent graph tab
109 final XcosTab tab = XcosTab.get(parentGraph);
111 XcosTab.restore(parentGraph);