add frame_borders as hidden children to allow recursive deletion
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / bridge / window / SwingScilabStaticWindow.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2014 - Scilab Enterprises - Bruno JOFRET
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10  *
11  */
12
13 package org.scilab.modules.gui.bridge.window;
14
15 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CLOSEREQUESTFCN__;
16
17 import java.awt.BorderLayout;
18 import java.awt.Component;
19 import java.awt.event.WindowAdapter;
20 import java.awt.event.WindowEvent;
21
22 import org.flexdock.docking.DockingPort;
23 import org.scilab.modules.action_binding.InterpreterManagement;
24 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
25 import org.scilab.modules.gui.bridge.tab.SwingScilabPanel;
26 import org.scilab.modules.gui.bridge.tab.SwingScilabStaticPanel;
27
28 public class SwingScilabStaticWindow extends SwingScilabWindow {
29
30     private SwingScilabStaticPanel panel;
31
32     public SwingScilabStaticWindow() {
33         super();
34         setLayout(new BorderLayout());
35         addWindowListener(new WindowAdapter() {
36             public void windowClosing(WindowEvent e) {
37                 String closeRequestFcn = (String) GraphicController.getController().getProperty(panel.getId(), __GO_CLOSEREQUESTFCN__);
38                 if (!closeRequestFcn.equals("")) {
39                     String closeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;" + "gcbo = getcallbackobject(" + panel.getId() + ");" + closeRequestFcn
40                                           + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
41                     InterpreterManagement.putCommandInScilabQueue(closeCommand);
42                 } else {
43                     //GraphicController.getController().deleteObject(panel.getId());
44                     GraphicController.getController().removeRelationShipAndDelete(panel.getId());
45                 }
46             }
47         });
48     }
49
50     /**
51      * @return number of objects (tabs) docked in this window
52      */
53     @Override
54     public int getNbDockedObjects() {
55         return 1;
56     }
57
58     /**
59      * Close the window
60      * @see org.scilab.modules.gui.window.SimpleWindow#close()
61      */
62     @Override
63     public void close() {
64         try {
65             setVisible(false);
66             dispose();
67         } catch (IllegalStateException e) {
68             enableInputMethods(false);
69         }
70         allScilabWindows.remove(windowUID);
71     }
72
73     public DockingPort getDockingPort() {
74         return null;
75     }
76
77     public void addTab(SwingScilabPanel tab) {
78         add((Component) tab, BorderLayout.CENTER);
79         this.panel = (SwingScilabStaticPanel) tab;
80     }
81
82     public void removeTabs(SwingScilabPanel[] tabs) {
83         removeAll();
84     }
85 }