ab1b11c6edb3f1403194f63850f7d99a25755d3d
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / SwingView.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2011 - DIGITEO - Bruno JOFRET
4  * Copyright (C) 2011 - DIGITEO - Vincent COUVERT
5  *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  */
16 package org.scilab.modules.gui;
17
18 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
19 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES__;
20 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACKTYPE__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACK__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CONSOLE__;
24 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_FIGURE__;
25 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_IMMEDIATE_DRAWING__;
26 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
27 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_PARENT__;
28 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
29 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_PROGRESSIONBAR__;
30 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_SIZE__;
31 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_STYLE__;
32 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
33 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHECKEDMENU__;
34 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHILDMENU__;
35 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTEXTMENU__;
36 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
37 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIMENU__;
38 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIPARENTMENU__;
39 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BACKGROUNDCOLOR__;
40 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_CHECKBOX__;
41 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_CHECKED__;
42 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_EDIT__;
43 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SPINNER__;
44 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
45 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTANGLE__;
46 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTNAME__;
47 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTSIZE__;
48 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTUNITS__;
49 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTWEIGHT__;
50 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOREGROUNDCOLOR__;
51 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
52 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME__;
53 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_HORIZONTALALIGNMENT__;
54 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ICON__;
55 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_IMAGE__;
56 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LABEL__;
57 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LAYER__;
58 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LISTBOX__;
59 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MAX__;
60 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MIN__;
61 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_POPUPMENU__;
62 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_PUSHBUTTON__;
63 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_RADIOBUTTON__;
64 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_RELIEF__;
65 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SCROLLABLE__;
66 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SEPARATOR__;
67 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SLIDER__;
68 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
69 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TABLE__;
70 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TAB__;
71 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TEXT__;
72 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VERTICALALIGNMENT__;
73 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VALID__;
74 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
75 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_WAITBAR__;
76 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOCUS__;
77 import static org.scilab.modules.gui.utils.Debug.DEBUG;
78
79 import java.awt.Component;
80 import java.awt.Container;
81 import java.awt.GraphicsEnvironment;
82 import java.lang.reflect.InvocationTargetException;
83 import java.util.Arrays;
84 import java.util.Collections;
85 import java.util.HashMap;
86 import java.util.HashSet;
87 import java.util.Map;
88 import java.util.Set;
89 import java.util.UUID;
90
91 import javax.media.opengl.GL;
92 import javax.media.opengl.GLCapabilities;
93 import javax.media.opengl.GLProfile;
94 import javax.media.opengl.awt.GLCanvas;
95 import javax.swing.JComponent;
96 import javax.swing.JSeparator;
97 import javax.swing.SwingUtilities;
98
99 import org.flexdock.docking.Dockable;
100 import org.flexdock.docking.DockingManager;
101 import org.flexdock.docking.activation.ActiveDockableTracker;
102 import org.scilab.modules.graphic_export.Driver;
103 import org.scilab.modules.graphic_objects.DataLoader;
104 import org.scilab.modules.graphic_objects.console.Console;
105 import org.scilab.modules.graphic_objects.figure.Figure;
106 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
107 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
108 import org.scilab.modules.graphic_objects.graphicView.GraphicView;
109 import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
110 import org.scilab.modules.gui.bridge.checkboxmenuitem.SwingScilabCheckBoxMenuItem;
111 import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
112 import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
113 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
114 import org.scilab.modules.gui.bridge.editbox.SwingScilabSpinner;
115 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
116 import org.scilab.modules.gui.bridge.frame.SwingScilabLayer;
117 import org.scilab.modules.gui.bridge.frame.SwingScilabScrollableFrame;
118 import org.scilab.modules.gui.bridge.label.SwingScilabLabel;
119 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
120 import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
121 import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
122 import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
123 import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
124 import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
125 import org.scilab.modules.gui.bridge.slider.SwingScilabScroll;
126 import org.scilab.modules.gui.bridge.slider.SwingScilabSlider;
127 import org.scilab.modules.gui.bridge.tab.SwingScilabAxes;
128 import org.scilab.modules.gui.bridge.tab.SwingScilabDockablePanel;
129 import org.scilab.modules.gui.bridge.tab.SwingScilabPanel;
130 import org.scilab.modules.gui.bridge.tab.SwingScilabStaticPanel;
131 import org.scilab.modules.gui.bridge.tab.SwingScilabTabGroup;
132 import org.scilab.modules.gui.bridge.uiimage.SwingScilabUiImage;
133 import org.scilab.modules.gui.bridge.uitable.SwingScilabUiTable;
134 import org.scilab.modules.gui.bridge.waitbar.SwingScilabWaitBar;
135 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
136 import org.scilab.modules.gui.console.ScilabConsole;
137 import org.scilab.modules.gui.ged.Inspector;
138 import org.scilab.modules.gui.menubar.MenuBar;
139 import org.scilab.modules.gui.menubar.ScilabMenuBar;
140 import org.scilab.modules.gui.textbox.ScilabTextBox;
141 import org.scilab.modules.gui.textbox.TextBox;
142 import org.scilab.modules.gui.toolbar.ScilabToolBar;
143 import org.scilab.modules.gui.toolbar.ToolBar;
144 import org.scilab.modules.gui.utils.BorderConvertor;
145 import org.scilab.modules.gui.utils.ClosingOperationsManager;
146 import org.scilab.modules.gui.utils.Size;
147 import org.scilab.modules.gui.utils.WindowsConfigurationManager;
148 import org.scilab.modules.gui.widget.Widget;
149 import org.scilab.modules.renderer.utils.textRendering.FontManager;
150
151 /**
152  * @author Bruno JOFRET
153  * @author Vincent COUVERT
154  */
155 public final class SwingView implements GraphicView {
156
157     public static final String NULLUUID = new UUID(0L, 0L).toString();
158     private static SwingView me;
159     private static boolean headless;
160     private Map<Integer, TypedObject> allObjects;
161
162     static {
163         try {
164             System.loadLibrary("gluegen2-rt");
165         } catch (Exception e) {
166             System.err.println(e);
167         }
168     }
169
170     /**
171      * Constructor
172      */
173     private SwingView() {
174         GraphicController.getController().register(this);
175         allObjects = Collections.synchronizedMap(new HashMap<Integer, TypedObject>());
176
177         try {
178             GLCanvas tmpCanvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()));
179             tmpCanvas.getContext().makeCurrent();
180             GL gl = tmpCanvas.getGL();
181             DataLoader.setABGRExt(gl.isExtensionAvailable("GL_EXT_abgr") ? 1 : 0);
182             tmpCanvas.getContext().release();
183             tmpCanvas = null;
184
185             /*
186              * Forces font loading from the main thread. This is done because if
187              * getSciFontManager (thus, font loading) is concurrently accessed
188              * from 2 different threads (the AWT's and the main one), freezing
189              * may occur.
190              */
191             FontManager.getSciFontManager();
192         } catch (Exception e) {
193         }
194     }
195
196     public static void registerSwingView() {
197         DEBUG("SwingView", "calling registerSwingView()");
198         if (me == null) {
199             me = new SwingView();
200         }
201     }
202
203     public static void setHeadless(boolean headless) {
204         SwingView.headless = headless;
205     }
206
207     public static boolean isHeadless() {
208         return SwingView.headless;
209     }
210
211     public static SwingViewObject getFromId(Integer id) {
212         TypedObject typedObject = me.allObjects.get(id);
213
214         if (typedObject == null) {
215             return null;
216         }
217
218         return typedObject.getValue();
219     }
220
221     public static int getSize() {
222         return me.allObjects.size();
223     }
224
225     private enum UielementType {
226         Console, CheckBox, Edit, Spinner, Frame, Figure, Axes, Image, ListBox, PopupMenu, Progressbar, PushButton, RadioButton, Slider, Table, Text, Uimenu, UiParentMenu, UiChildMenu, UiCheckedMenu, UiContextMenu, Waitbar, Tab, Layer
227     }
228
229     private class TypedObject {
230         private UielementType _type;
231         private SwingViewObject _value;
232         private Set<Integer> _children;
233
234         public TypedObject(UielementType _type, SwingViewObject _value) {
235             this._type = _type;
236             this._value = _value;
237             this._children = Collections.synchronizedSet(new HashSet<Integer>());
238         }
239
240         public UielementType getType() {
241             return _type;
242         }
243
244         public SwingViewObject getValue() {
245             return _value;
246         }
247
248         public Set<Integer> getChildren() {
249             return _children;
250         }
251
252         public void addChild(Integer childUID) {
253             _children.add(childUID);
254         }
255
256         public void removeChild(Integer childUID) {
257             _children.remove(childUID);
258         }
259
260         public boolean hasChild(Integer childUID) {
261             return _children.contains(childUID);
262         }
263     };
264
265     private static final Set<Integer> managedTypes = new HashSet<Integer>(Arrays.asList(
266                 GraphicObjectProperties.__GO_FIGURE__,
267                 GraphicObjectProperties.__GO_AXES__,
268                 GraphicObjectProperties.__GO_UICONTEXTMENU__,
269                 GraphicObjectProperties.__GO_UIMENU__,
270                 GraphicObjectProperties.__GO_CONSOLE__,
271                 GraphicObjectProperties.__GO_PROGRESSIONBAR__,
272                 GraphicObjectProperties.__GO_WAITBAR__,
273                 GraphicObjectProperties.__GO_UICONTROL__
274             ));
275
276     @Override
277     public void createObject(Integer id) {
278
279         int objectType = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
280
281         if (managedTypes.contains(objectType) == false) {
282             return;
283         }
284         //System.err.println("[SwingWiew] Object Created : " + id + " with type : " + objectType);
285         boolean isValid = (Boolean) GraphicController.getController().getProperty(id, __GO_VALID__);
286         if (!isValid) {
287             return;
288         }
289
290         if (!headless && !GraphicsEnvironment.isHeadless()) {
291             DEBUG("SwingWiew", "Object Created : " + id + "with type : " + objectType);
292             if (objectType != __GO_UICONTROL__) {
293                 allObjects.put(id, CreateObjectFromType(objectType, id));
294                 return;
295             }
296
297             if (objectType == __GO_UICONTROL__) {
298                 int style = (Integer) GraphicController.getController().getProperty(id, __GO_STYLE__);
299                 DEBUG("SwingView", "__GO_STYLE__(" + style + ")");
300                 allObjects.put(id, CreateObjectFromType(style, id));
301             }
302         } else {
303             if (objectType == __GO_FIGURE__) {
304                 Driver.setDefaultVisitor(id);
305             }
306         }
307     }
308
309     private UielementType StyleToEnum(int style) {
310         DEBUG("SwingView", "StyleToEnum(" + style + ")");
311         switch (style) {
312             case __GO_FIGURE__:
313                 return UielementType.Figure;
314             case __GO_AXES__ :
315                 return UielementType.Axes;
316             case __GO_CONSOLE__:
317                 return UielementType.Console;
318             case __GO_UI_CHECKBOX__:
319                 return UielementType.CheckBox;
320             case __GO_UI_EDIT__:
321                 return UielementType.Edit;
322             case __GO_UI_SPINNER__:
323                 return UielementType.Spinner;
324             case __GO_UI_FRAME__:
325                 return UielementType.Frame;
326             case __GO_UI_IMAGE__:
327                 return UielementType.Image;
328             case __GO_UI_LISTBOX__:
329                 return UielementType.ListBox;
330             case __GO_UI_POPUPMENU__:
331                 return UielementType.PopupMenu;
332             case __GO_UI_PUSHBUTTON__:
333                 return UielementType.PushButton;
334             case __GO_UI_RADIOBUTTON__:
335                 return UielementType.RadioButton;
336             case __GO_UI_SLIDER__:
337                 return UielementType.Slider;
338             case __GO_UI_TABLE__:
339                 return UielementType.Table;
340             case __GO_UI_TEXT__:
341                 return UielementType.Text;
342             case __GO_UIMENU__:
343                 return UielementType.UiChildMenu;
344             case __GO_UIPARENTMENU__:
345                 return UielementType.UiParentMenu;
346             case __GO_UICHILDMENU__:
347                 return UielementType.UiChildMenu;
348             case __GO_UICHECKEDMENU__:
349                 return UielementType.UiCheckedMenu;
350             case __GO_PROGRESSIONBAR__:
351                 return UielementType.Progressbar;
352             case __GO_WAITBAR__:
353                 return UielementType.Waitbar;
354             case __GO_UICONTEXTMENU__:
355                 return UielementType.UiContextMenu;
356             case __GO_UI_TAB__:
357                 return UielementType.Tab;
358             case __GO_UI_LAYER__:
359                 return UielementType.Layer;
360         }
361         return null;
362     }
363
364     private TypedObject CreateObjectFromType(final int type, final Integer id) {
365         final UielementType enumType = StyleToEnum(type);
366         final SwingViewObject newSVObject[] = new SwingViewObject[1];
367         if (SwingUtilities.isEventDispatchThread()) {
368             newSVObject[0] = CreateObjectFromType(enumType, id);
369         } else {
370             try {
371                 SwingUtilities.invokeAndWait(new Runnable() {
372
373                     @Override
374                     public void run() {
375                         newSVObject[0] = CreateObjectFromType(enumType, id);
376                     }
377                 });
378             } catch (InterruptedException e) {
379                 // TODO Auto-generated catch block
380                 e.printStackTrace();
381             } catch (InvocationTargetException e) {
382                 // TODO Auto-generated catch block
383                 e.printStackTrace();
384             }
385         }
386         return new TypedObject(enumType, newSVObject[0]);
387     }
388
389     private SwingViewObject CreateObjectFromType(UielementType type, Integer id) {
390         switch (type) {
391             case CheckBox:
392                 SwingScilabCheckBox checkBox = new SwingScilabCheckBox();
393                 checkBox.setId(id);
394                 setDefaultProperties(checkBox, id);
395                 return checkBox;
396             case Console:
397                 Console console = (Console) GraphicController.getController().getObjectFromId(id);
398                 if (console.getScilabMode() == Console.ScilabMode.STD) {
399                     WindowsConfigurationManager.restoreUUID(NULLUUID);
400                     SwingScilabConsole sciConsole = ((SwingScilabConsole) ScilabConsole.getConsole().getAsSimpleConsole());
401                     SwingScilabDockablePanel consoleTab = (SwingScilabDockablePanel) sciConsole.getParent();
402                     consoleTab.setId(id);
403                     return consoleTab;
404                 }
405                 return null;
406             case Edit: {
407                 SwingScilabEditBox edit = new SwingScilabEditBox();
408                 edit.setId(id);
409                 setDefaultProperties(edit, id);
410                 return edit;
411             }
412             case Spinner : {
413                 SwingScilabSpinner spin = new SwingScilabSpinner();
414                 spin.setId(id);
415                 setDefaultProperties(spin, id);
416                 return spin;
417             }
418             case Figure: {
419                 Figure figure = (Figure) GraphicController.getController().getObjectFromId(id);
420                 String figureTitle = figure.getName();
421                 Integer figureId = figure.getId();
422                 if ((figureTitle != null) && (figureId != null)) {
423                     figureTitle = figureTitle.replaceFirst("%d", figureId.toString());
424                 }
425
426                 SwingScilabWindow window = SwingScilabWindow.createWindow(figure.getDockable());
427
428                 window.setTitle(figureTitle);
429                 Integer[] figureSize = figure.getSize();
430                 window.setDims(new Size(figureSize[0], figureSize[1]));
431
432                 SwingScilabPanel tab;
433                 if (figure.getDockable()) {
434                     tab = new SwingScilabDockablePanel(figureTitle, figureId, figure);
435                 } else {
436                     tab = new SwingScilabStaticPanel(figureTitle, figureId, figure);
437                 }
438                 tab.setId(id);
439
440                 /* MENUBAR */
441                 MenuBar menuBar = ScilabMenuBar.createMenuBar();
442                 menuBar.setVisible(false);
443                 tab.setMenuBar(menuBar);
444                 window.addMenuBar(menuBar);
445
446                 /* TOOLBAR */
447                 ToolBar toolbar = ScilabToolBar.createToolBar();
448                 toolbar.setVisible(false);
449                 tab.setToolBar(toolbar);
450                 window.addToolBar(toolbar);
451
452                 /* INFOBAR */
453                 TextBox infoBar = ScilabTextBox.createTextBox();
454                 infoBar.setVisible(false);
455                 tab.setInfoBar(infoBar);
456                 window.addInfoBar(infoBar);
457
458                 if (figure.getDockable()) {
459                     DockingManager.dock((SwingScilabDockablePanel) tab, window.getDockingPort());
460                     ActiveDockableTracker.requestDockableActivation((SwingScilabDockablePanel) tab);
461                 } else {
462                     window.addTab(tab);
463                 }
464
465                 tab.setWindowIcon("graphic-window");
466
467                 tab.setParentWindowId(window.getId());
468
469                 tab.setEventHandler(figure.getEventHandlerString());
470                 tab.setEventHandlerEnabled(figure.getEventHandlerEnable());
471                 tab.setVisible(true);
472                 tab.setName(figureTitle);
473
474                 String infoMessage = figure.getInfoMessage();
475                 if ((infoMessage == null) || (infoMessage.length() == 0)) {
476                     infoBar.setText("");
477                 } else {
478                     infoBar.setText(infoMessage);
479                 }
480
481                 tab.update(__GO_POSITION__, GraphicController.getController().getProperty(id, __GO_POSITION__));
482
483                 String icon = (String)GraphicController.getController().getProperty(id, __GO_UI_ICON__);
484                 if (icon != null && icon.equals("") == false) {
485                     tab.update(__GO_UI_ICON__, icon);
486                 }
487
488                 // TODO set other default properties
489                 window.pack();
490                 window.setVisible(figure.getVisible());
491                 return tab;
492             }
493             case Axes:
494                 SwingScilabAxes axes = new SwingScilabAxes();
495                 return axes;
496             case Frame: {
497                 Boolean scrollable = (Boolean) GraphicController.getController().getProperty(id, __GO_UI_SCROLLABLE__);
498                 if (scrollable) {
499                     SwingScilabScrollableFrame frame = new SwingScilabScrollableFrame();
500                     frame.setId(id);
501                     setDefaultProperties(frame, id);
502                     Integer borderId = (Integer) GraphicController.getController().getProperty(id, __GO_UI_FRAME_BORDER__);
503                     if (borderId != 0) {
504                         frame.setBorder(BorderConvertor.getBorder(borderId));
505                     }
506                     return frame;
507                 } else {
508                     SwingScilabFrame frame = new SwingScilabFrame();
509                     frame.setId(id);
510                     setDefaultProperties(frame, id);
511                     Integer borderId = (Integer) GraphicController.getController().getProperty(id, __GO_UI_FRAME_BORDER__);
512                     if (borderId != 0) {
513                         frame.setBorder(BorderConvertor.getBorder(borderId));
514                     }
515                     return frame;
516                 }
517             }
518             case Image:
519                 SwingScilabUiImage image = new SwingScilabUiImage();
520                 image.setId(id);
521                 setDefaultProperties(image, id);
522                 return image;
523             case ListBox:
524                 SwingScilabListBox listBox = new SwingScilabListBox();
525                 listBox.setId(id);
526                 setDefaultProperties(listBox, id);
527                 return listBox;
528             case PopupMenu:
529                 SwingScilabPopupMenu popupMenu = new SwingScilabPopupMenu();
530                 popupMenu.setId(id);
531                 setDefaultProperties(popupMenu, id);
532                 return popupMenu;
533             case Progressbar:
534                 SwingScilabWaitBar progressbar = new SwingScilabWaitBar();
535                 progressbar.setIndeterminateMode(true);
536                 progressbar.setId(id);
537                 return progressbar;
538             case PushButton: {
539                 SwingScilabPushButton pushButton = new SwingScilabPushButton();
540                 pushButton.setId(id);
541                 setDefaultProperties(pushButton, id);
542                 String icon = (String)GraphicController.getController().getProperty(id, __GO_UI_ICON__);
543                 if (icon != null && icon.equals("") == false) {
544                     pushButton.update(__GO_UI_ICON__, icon);
545                 }
546
547                 return pushButton;
548             }
549             case RadioButton:
550                 SwingScilabRadioButton radioButton = new SwingScilabRadioButton();
551                 radioButton.setId(id);
552                 setDefaultProperties(radioButton, id);
553                 return radioButton;
554             case Slider:
555                 if (Console.getConsole().getUseDeprecatedLF()) {
556                     SwingScilabScroll slider = new SwingScilabScroll();
557                     slider.setId(id);
558                     setDefaultProperties(slider, id);
559                     return slider;
560                 } else {
561                     SwingScilabSlider slider = new SwingScilabSlider();
562                     slider.setId(id);
563                     setDefaultProperties(slider, id);
564                     return slider;
565                 }
566             case Table:
567                 SwingScilabUiTable table = new SwingScilabUiTable();
568                 table.setId(id);
569                 setDefaultProperties(table, id);
570                 return table;
571             case Text: {
572                 SwingScilabLabel text = new SwingScilabLabel();
573                 text.setId(id);
574                 setDefaultProperties(text, id);
575                 String icon = (String)GraphicController.getController().getProperty(id, __GO_UI_ICON__);
576                 if (icon != null && icon.equals("") == false) {
577                     text.update(__GO_UI_ICON__, icon);
578                 }
579                 return text;
580             }
581             case Uimenu:
582                 throw new UnsupportedOperationException();
583             case UiParentMenu: /* SwingView internal type */
584                 SwingScilabMenu parentMenu = new SwingScilabMenu();
585                 parentMenu.setId(id);
586                 setMenuDefaultProperties(parentMenu, id);
587                 return parentMenu;
588             case UiChildMenu: /* SwingView internal type */
589                 SwingScilabMenuItem childMenu = new SwingScilabMenuItem();
590                 childMenu.setId(id);
591                 setMenuDefaultProperties(childMenu, id);
592                 return childMenu;
593             case UiCheckedMenu: /* SwingView internal type */
594                 SwingScilabCheckBoxMenuItem checkedMenu = new SwingScilabCheckBoxMenuItem(false);
595                 checkedMenu.setId(id);
596                 setMenuDefaultProperties(checkedMenu, id);
597                 return checkedMenu;
598             case UiContextMenu:
599                 SwingScilabContextMenu contextMenu = new SwingScilabContextMenu();
600                 contextMenu.setId(id);
601                 return contextMenu;
602             case Waitbar:
603                 SwingScilabWaitBar waitbar = new SwingScilabWaitBar();
604                 waitbar.setIndeterminateMode(false);
605                 waitbar.setId(id);
606                 return waitbar;
607             case Tab:
608                 SwingScilabTabGroup TabGroup = new SwingScilabTabGroup();
609                 TabGroup.setId(id);
610                 //setDefaultProperties(TabGroup, id);
611                 //TabGroup.update(property, value);
612                 return TabGroup;
613             case Layer:
614                 SwingScilabLayer layer = new SwingScilabLayer();
615                 layer.setId(id);
616                 return layer;
617             default:
618                 System.err.println("[SwingView] Unmanaged Creation type !!!");
619                 return null;
620         }
621     }
622
623     /**
624      * Initialize all poperties according to model
625      * @param uiMenuObject the uimenu
626      * @param id the uimenu id
627      */
628     private void setMenuDefaultProperties(Widget uiMenuObject, Integer id) {
629         SwingViewMenu.update(uiMenuObject, __GO_CHILDREN__, GraphicController.getController().getProperty(id, __GO_CHILDREN__));
630         SwingViewMenu.update(uiMenuObject, __GO_CALLBACK__, GraphicController.getController().getProperty(id, __GO_CALLBACK__));
631         SwingViewMenu.update(uiMenuObject, __GO_CALLBACKTYPE__, GraphicController.getController().getProperty(id, __GO_CALLBACKTYPE__));
632         SwingViewMenu.update(uiMenuObject, __GO_UI_CHECKED__, GraphicController.getController().getProperty(id, __GO_UI_CHECKED__));
633         SwingViewMenu.update(uiMenuObject, __GO_UI_ENABLE__, GraphicController.getController().getProperty(id, __GO_UI_ENABLE__));
634         SwingViewMenu.update(uiMenuObject, __GO_UI_FOREGROUNDCOLOR__, GraphicController.getController().getProperty(id, __GO_UI_FOREGROUNDCOLOR__));
635         SwingViewMenu.update(uiMenuObject, __GO_UI_LABEL__, GraphicController.getController().getProperty(id, __GO_UI_LABEL__));
636         SwingViewMenu.update(uiMenuObject, __GO_UI_ICON__, GraphicController.getController().getProperty(id, __GO_UI_ICON__));
637     }
638
639     /**
640      * Initialize all poperties according to model
641      * @param uiControlObject the uicontrol
642      * @param id the uicontrol id
643      */
644     private void setDefaultProperties(SwingViewObject uiControlObject, Integer id) {
645
646         /*
647          * Visible property is set first to avoid to see the object rendered
648          * before all its properties to be set (See bug #10346)
649          */
650         uiControlObject.update(__GO_VISIBLE__, GraphicController.getController().getProperty(id, __GO_VISIBLE__));
651         uiControlObject.update(__GO_UI_BACKGROUNDCOLOR__, GraphicController.getController().getProperty(id, __GO_UI_BACKGROUNDCOLOR__));
652         uiControlObject.update(__GO_UI_ENABLE__, GraphicController.getController().getProperty(id, __GO_UI_ENABLE__));
653         uiControlObject.update(__GO_UI_FONTANGLE__, GraphicController.getController().getProperty(id, __GO_UI_FONTANGLE__));
654         uiControlObject.update(__GO_UI_FONTNAME__, GraphicController.getController().getProperty(id, __GO_UI_FONTNAME__));
655         uiControlObject.update(__GO_UI_FONTUNITS__, GraphicController.getController().getProperty(id, __GO_UI_FONTUNITS__));
656         uiControlObject.update(__GO_UI_FONTSIZE__, GraphicController.getController().getProperty(id, __GO_UI_FONTSIZE__));
657         uiControlObject.update(__GO_UI_FONTWEIGHT__, GraphicController.getController().getProperty(id, __GO_UI_FONTWEIGHT__));
658         uiControlObject.update(__GO_UI_FOREGROUNDCOLOR__, GraphicController.getController().getProperty(id, __GO_UI_FOREGROUNDCOLOR__));
659         uiControlObject.update(__GO_UI_HORIZONTALALIGNMENT__, GraphicController.getController().getProperty(id, __GO_UI_HORIZONTALALIGNMENT__));
660         uiControlObject.update(__GO_UI_RELIEF__, GraphicController.getController().getProperty(id, __GO_UI_RELIEF__));
661         uiControlObject.update(__GO_UI_STRING__, GraphicController.getController().getProperty(id, __GO_UI_STRING__));
662         uiControlObject.update(__GO_UI_VERTICALALIGNMENT__, GraphicController.getController().getProperty(id, __GO_UI_VERTICALALIGNMENT__));
663         uiControlObject.update(__GO_POSITION__, GraphicController.getController().getProperty(id, __GO_POSITION__));
664         uiControlObject.update(__GO_LAYOUT__, GraphicController.getController().getProperty(id, __GO_LAYOUT__));
665         uiControlObject.update(__GO_UI_MIN__, GraphicController.getController().getProperty(id, __GO_UI_MIN__));
666         uiControlObject.update(__GO_UI_MAX__, GraphicController.getController().getProperty(id, __GO_UI_MAX__));
667     }
668
669     public void deleteObject(Integer id) {
670         final TypedObject requestedObject = allObjects.get(id);
671         if (requestedObject != null) {
672             switch (requestedObject.getType()) {
673                 case Figure:
674                     if (SwingUtilities.isEventDispatchThread()) {
675                         final SwingScilabPanel tab = (SwingScilabPanel) requestedObject.getValue();
676                         if (requestedObject.getValue() instanceof SwingScilabDockablePanel) {
677                             final SwingScilabDockablePanel dockableTab = (SwingScilabDockablePanel) tab;
678                             dockableTab.disablePaint();
679                             DockingManager.close(dockableTab);
680                             DockingManager.unregisterDockable((Dockable) dockableTab);
681                             ClosingOperationsManager.unregisterClosingOperation(dockableTab);
682                             ClosingOperationsManager.removeDependency(dockableTab);
683                             ClosingOperationsManager.checkTabForClosing(dockableTab);
684                             tab.close();
685                         } else {
686                             tab.close();
687                         }
688                     } else {
689                         try {
690                             SwingUtilities.invokeAndWait(new Runnable() {
691
692                                 @Override
693                                 public void run() {
694                                     final SwingScilabPanel tab = (SwingScilabPanel) requestedObject.getValue();
695                                     if (tab instanceof SwingScilabDockablePanel) {
696                                         final SwingScilabDockablePanel dockableTab = (SwingScilabDockablePanel) tab;
697                                         dockableTab.disablePaint();
698                                         DockingManager.close(dockableTab);
699                                         DockingManager.unregisterDockable((Dockable) dockableTab);
700                                         ClosingOperationsManager.unregisterClosingOperation(dockableTab);
701                                         ClosingOperationsManager.removeDependency(dockableTab);
702                                         ClosingOperationsManager.checkTabForClosing(dockableTab);
703                                         tab.close();
704                                     } else {
705                                         tab.close();
706                                     }
707                                 }
708
709                             });
710                         } catch (InterruptedException e) {
711                             // TODO Auto-generated catch block
712                             e.printStackTrace();
713                         } catch (InvocationTargetException e) {
714                             // TODO Auto-generated catch block
715                             e.printStackTrace();
716                         }
717                     }
718
719                     //try close the Property List (GED)
720                     try {
721                         Inspector.getInspector().close();
722                     } catch (NullPointerException e) {
723                     }
724                     break;
725                 case Progressbar:
726                 case Waitbar:
727                     SwingScilabWaitBar bar = (SwingScilabWaitBar) requestedObject.getValue();
728                     bar.close();
729                     break;
730                 case Frame:
731                     Boolean scrollable = (Boolean) GraphicController.getController().getProperty(id, __GO_UI_SCROLLABLE__);
732                     if (scrollable) {
733                         SwingScilabScrollableFrame frame = (SwingScilabScrollableFrame) requestedObject.getValue();
734                         frame.destroy();
735                     } else {
736                         SwingScilabFrame frame = (SwingScilabFrame) requestedObject.getValue();
737                         frame.destroy();
738                     }
739                     break;
740                 default:
741                     // Nothing to do
742                     // uicontrol case: the object is destroyed when its parent updates its children
743                     break;
744             }
745             allObjects.remove(id);
746         }
747     }
748
749     @Override
750     public void updateObject(final Integer id, final int property) {
751         final TypedObject registeredObject = allObjects.get(id);
752
753         if (property == __GO_SIZE__ && (headless || GraphicsEnvironment.isHeadless())) {
754             int objectType = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
755             if (objectType == __GO_FIGURE__) {
756                 Integer[] dims = (Integer[]) GraphicController.getController().getProperty(id, __GO_SIZE__);
757                 GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, dims);
758             }
759         }
760
761         if (registeredObject != null && property == __GO_VALID__ && ((Boolean) GraphicController.getController().getProperty(id, __GO_VALID__))) {
762             if (registeredObject.getValue() instanceof SwingScilabDockablePanel) {
763                 final Runnable r = new Runnable() {
764                     @Override
765                     public void run() {
766                         boolean figVis = (Boolean) GraphicController.getController().getProperty(id, __GO_VISIBLE__);
767                         ((SwingScilabDockablePanel) registeredObject.getValue()).getParentWindow().setVisible(figVis);
768                         ((SwingScilabDockablePanel) registeredObject.getValue()).setVisible(true);
769                         Integer[] figureSize = (Integer[]) GraphicController.getController().getProperty(id, __GO_SIZE__);
770                         ((SwingScilabDockablePanel) registeredObject.getValue()).getParentWindow().setDims(new Size(figureSize[0], figureSize[1]));
771                     }
772                 };
773
774                 if (SwingUtilities.isEventDispatchThread()) {
775                     r.run();
776                 } else {
777                     SwingUtilities.invokeLater(r);
778                 }
779             }
780         }
781
782         if (property == __GO_IMMEDIATE_DRAWING__) {
783             return;
784         }
785
786         if (registeredObject == null && property != __GO_STYLE__) {
787             return;
788         }
789
790         /* On uicontrol style is set after object creation */
791         if (registeredObject == null && property == __GO_STYLE__) {
792             int style = (Integer) GraphicController.getController().getProperty(id, __GO_STYLE__);
793             allObjects.put(id, CreateObjectFromType(style, id));
794             return;
795         }
796
797         if(property == __GO_UI_FOCUS__) {
798             requestFocus(registeredObject);
799             return;
800         }
801
802         /* Do not update axes on EDT to avoid dead locks between SwingView & DrawerVisitor */
803         /* Test which freezes without this condition: bug_1257.tst in graphics */
804         int type = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
805         if (type == __GO_AXES__) {
806             if (property == __GO_PARENT__) {
807                 Integer parentId = (Integer) GraphicController.getController().getProperty(id, __GO_PARENT__);
808                 TypedObject registeredParent = allObjects.get(parentId);
809                 if (registeredParent == null) {
810                     allObjects.remove(id);
811                 } else {
812                     ((SwingScilabAxes) allObjects.get(id).getValue()).update(property, parentId);
813                 }
814             }
815             return;
816         }
817
818         if (SwingUtilities.isEventDispatchThread()) {
819             updateObjectOnEDT(registeredObject, id, property);
820         } else {
821             try {
822                 SwingUtilities.invokeAndWait(new Runnable() {
823                     public void run() {
824                         updateObjectOnEDT(registeredObject, id, property);
825                     }
826                 });
827             } catch (InterruptedException e) {
828                 e.printStackTrace();
829             } catch (InvocationTargetException e) {
830                 e.printStackTrace();
831             }
832         }
833     }
834
835     public void updateObjectOnEDT(TypedObject registeredObject, final Integer id, final int property) {
836         /* Removes the swing object if its parent is not display */
837         if (registeredObject != null && property == __GO_PARENT__) {
838             Integer parentId = (Integer) GraphicController.getController().getProperty(id, __GO_PARENT__);
839             TypedObject registeredParent = allObjects.get(parentId);
840             if (registeredParent == null) {
841                 allObjects.remove(id);
842             }
843         }
844
845         int type = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
846         /* Children list update */
847         if (registeredObject != null && property == __GO_CHILDREN__) {
848             final Integer[] newChildren = (Integer[]) GraphicController.getController().getProperty(id, __GO_CHILDREN__);
849
850             switch (type) {
851                     /*
852                      * FIGURE CHILDREN UPDATE
853                      */
854                 case __GO_FIGURE__:
855                     updateFigureChildren(registeredObject, newChildren);
856                     break;
857                     /*
858                      * CONSOLE CHILDREN UPDATE
859                      */
860                 case __GO_CONSOLE__:
861                     updateConsoleChildren(registeredObject, newChildren);
862                     break;
863                     /*
864                      * MENU CHILDREN UPDATE
865                      */
866                 case __GO_UIMENU__:
867                     updateMenuChildren(registeredObject, id, newChildren);
868                     break;
869                     /*
870                      * CONTEXTMENU CHILDREN UPDATE
871                      */
872                 case __GO_UICONTEXTMENU__:
873                     updateContextMenuChildren(registeredObject, newChildren);
874                     break;
875                     /*
876                      * UICONTROL "FRAME" CHILDREN UPDATE
877                      */
878                 case __GO_UICONTROL__:
879
880                     int style = (Integer) GraphicController.getController().getProperty(id, __GO_STYLE__);
881                     switch (style) {
882                         case __GO_UI_LAYER__:
883                             updateLayerChildren(registeredObject, newChildren);
884                             break;
885                         case __GO_UI_FRAME__:
886                             if (registeredObject.getValue() instanceof SwingScilabFrame) {
887                                 updateFrameChildren(registeredObject, newChildren);
888                             } else if (registeredObject.getValue() instanceof SwingScilabScrollableFrame) {
889                                 updateScrollableFrameChildren(registeredObject, newChildren);
890                             }
891                             break;
892                         case __GO_UI_TAB__:
893                             updateTabGroupChildren(registeredObject, newChildren);
894                             break;
895                     }
896                     break;
897             }
898         }
899
900         /*
901          * When the CHECKED property is updated for a UIMENU, the object is
902          * converted to a SwingScilabCheckBoxMenuItem is not already of this
903          * type
904          */
905         if (registeredObject != null && property == __GO_UI_CHECKED__) {
906             if (type == __GO_UIMENU__) {
907                 switch (registeredObject.getType()) {
908                     case UiParentMenu: {
909                         SwingScilabMenu meAsAMenu = (SwingScilabMenu) registeredObject.getValue();
910                         Container parent = meAsAMenu.getParent();
911                         if (parent != null) {
912                             parent.remove(meAsAMenu);
913                         }
914
915                         registeredObject = CreateObjectFromType(__GO_UICHECKEDMENU__, id);
916                         allObjects.put(id, registeredObject);
917                         SwingScilabCheckBoxMenuItem meAsAMenuItem = (SwingScilabCheckBoxMenuItem) registeredObject.getValue();
918                         if (parent != null) {
919                             parent.add(meAsAMenuItem);
920                         }
921                         break;
922                     }
923                     case UiChildMenu: {
924                         SwingScilabMenuItem childMenu = (SwingScilabMenuItem) allObjects.get(id).getValue();
925                         JComponent parentMenu = (JComponent) childMenu.getParent();
926                         int index = 0;
927                         if (parentMenu != null) {
928                             index = parentMenu.getComponentZOrder(childMenu);
929                             parentMenu.remove(childMenu);
930                         }
931                         registeredObject = CreateObjectFromType(__GO_UICHECKEDMENU__, id);
932                         allObjects.put(id, registeredObject);
933                         registeredObject = allObjects.get(id);
934                         if (parentMenu != null) {
935                             parentMenu.add((SwingScilabCheckBoxMenuItem) registeredObject.getValue(), index);
936                         }
937                         return;
938                     }
939                     default:
940                         break;
941                 }
942             }
943         }
944
945         /*
946          * When the SEPARATOR property is updated for a UIMENU, When the
947          * property is set to TRUE: A separator is added if not already done
948          * When the property is set to FALSE: The previous separator is removed
949          * if it exists
950          */
951         if (registeredObject != null && property == __GO_UI_SEPARATOR__) {
952             if (type == __GO_UIMENU__) {
953                 Integer parentId = (Integer) GraphicController.getController().getProperty(id, __GO_PARENT__);
954                 int menuPosition = -1;
955                 Component currentComponent = (Component) registeredObject.getValue();
956                 Component[] allChildren = ((SwingScilabMenu) allObjects.get(parentId).getValue()).getMenuComponents();
957                 for (int kChild = 0; kChild < allChildren.length; kChild++) {
958                     if (allChildren[kChild] == currentComponent) {
959                         menuPosition = kChild;
960                         break;
961                     }
962                 }
963                 if (menuPosition < 0) {
964                     return;
965                 }
966                 boolean newSeparatorMode = (Boolean) GraphicController.getController().getProperty(id, __GO_UI_SEPARATOR__);
967                 if (newSeparatorMode) { // Add a separator above the menu
968                     ((SwingScilabMenu) allObjects.get(parentId).getValue()).insertSeparator(menuPosition);
969                 } else { // Remove the separator above the menu (if there is one)
970                     if (menuPosition == 0) { // There is no object above the menu
971                         return;
972                     }
973                     if (((SwingScilabMenu) allObjects.get(parentId).getValue()).getComponent(menuPosition - 1) instanceof JSeparator) {
974                         ((SwingScilabMenu) allObjects.get(parentId).getValue()).remove(menuPosition - 1);
975                     }
976                 }
977             }
978         }
979
980         if (registeredObject != null) {
981             final SwingViewObject swingObject = registeredObject.getValue();
982             if (swingObject != null) {
983                 swingObject.update(property, GraphicController.getController().getProperty(id, property));
984             }
985         }
986     }
987
988     /**
989      * Update the figure children (called by generic updateObject method)
990      * @param id the id of the figure
991      * @param newChildren the new children IDs list
992      */
993     private void updateFigureChildren(TypedObject updatedObject, Integer[] newChildren) {
994         Container updatedComponent = (Container) updatedObject.getValue();
995         boolean needRevalidate = false;
996         boolean needRevalidateMenubar = false;
997
998         // Add new children
999         for (Integer childId : newChildren) {
1000             if (!updatedObject.hasChild(childId)) {
1001
1002                 // Add the child
1003                 updatedObject.addChild(childId);
1004
1005                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1006
1007                 /* Add an Axes */
1008                 if (childType == __GO_AXES__) {
1009                     SwingViewObject canvas = allObjects.get(childId).getValue();
1010                     ((SwingScilabPanel) updatedComponent).addMember(canvas);
1011                 }
1012
1013                 /* Add an uicontrol */
1014                 if (childType == __GO_UICONTROL__) {
1015                     SwingViewObject uiContol = allObjects.get(childId).getValue();
1016                     ((SwingScilabPanel) updatedComponent).addMember(uiContol);
1017
1018                     // Force Position
1019                     uiContol.update(__GO_POSITION__, GraphicController.getController().getProperty(childId, __GO_POSITION__));
1020                     needRevalidate = true;
1021                 }
1022
1023                 /* Add an uimenu */
1024                 if (childType == __GO_UIMENU__) {
1025                     TypedObject childAsTypedObject = allObjects.get(childId);
1026                     switch (childAsTypedObject.getType()) {
1027                         case UiChildMenu:
1028                         case UiCheckedMenu:
1029                             allObjects.remove(childId);
1030                             allObjects.put(childId, CreateObjectFromType(__GO_UIPARENTMENU__, childId));
1031                             ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) allObjects.get(childId).getValue());
1032                             break;
1033                         default: /* UiParentMenu */
1034                             ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) allObjects.get(childId).getValue());
1035                             break;
1036                     }
1037                     needRevalidateMenubar = true;
1038                 }
1039             }
1040         }
1041
1042         // Remove children which have been deleted
1043         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1044         // Clone the children set to avoid concurrent accesses
1045         Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1046         for (Integer childId : oldChildrenSet) {
1047             if (!newChildrenSet.contains(childId)) {
1048
1049                 // Remove the child
1050                 updatedObject.removeChild(childId);
1051
1052                 final Object childTypeObject = GraphicController.getController().getProperty(childId, __GO_TYPE__);
1053                 if (childTypeObject == null) {
1054                     // the child has already been removed from the model
1055                     continue;
1056                 }
1057                 int childType = (Integer) childTypeObject;
1058
1059                 /* Remove an uicontrol */
1060                 if (childType == __GO_UICONTROL__) {
1061                     ((SwingScilabPanel) updatedComponent).removeMember(allObjects.get(childId).getValue());
1062                     needRevalidate = true;
1063                 }
1064
1065                 /* Remove an uimenu */
1066                 if (childType == __GO_UIMENU__) {
1067                     TypedObject childAsTypedObject = allObjects.get(childId);
1068                     switch (childAsTypedObject.getType()) {
1069                         case UiCheckedMenu:
1070                             ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).remove((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1071                             break;
1072                         default: /* UiParentMenu */
1073                             ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).remove((SwingScilabMenu) allObjects.get(childId).getValue());
1074                             break;
1075                     }
1076                     needRevalidateMenubar = true;
1077                 }
1078             }
1079         }
1080
1081         if (needRevalidateMenubar) {
1082             ((JComponent) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).revalidate();
1083             ((JComponent) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).repaint();
1084         }
1085
1086         if (needRevalidate && updatedComponent != null) {
1087             ((JComponent) updatedComponent).revalidate();
1088         }
1089     }
1090
1091     /**
1092      * Update the frame children (called by generic updateObject method)
1093      * @param id the id of the figure
1094      * @param newChildren the new children IDs list
1095      */
1096     private void updateFrameChildren(TypedObject updatedObject, Integer[] newChildren) {
1097         SwingScilabFrame updatedComponent = (SwingScilabFrame) updatedObject.getValue();
1098         boolean needRevalidate = false;
1099         boolean hasOpenGLAxes = false;
1100         int oldComponentCount = updatedComponent.getComponentCount();
1101
1102         // Add new children
1103         for (Integer childId : newChildren) {
1104             int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1105             if (!updatedObject.hasChild(childId)) {
1106
1107                 // Add the child
1108                 updatedObject.addChild(childId);
1109
1110                 /* Add an uicontrol */
1111                 if (childType == __GO_UICONTROL__ || childType == __GO_AXES__) {
1112                     updatedComponent.addMember(allObjects.get(childId).getValue());
1113                     needRevalidate = true;
1114                 }
1115             }
1116
1117             if (childType == __GO_AXES__) {
1118                 hasOpenGLAxes = true;
1119             }
1120
1121         }
1122
1123         // Remove children which have been deleted
1124         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1125         // Clone the children set to avoid concurrent accesses
1126         Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1127         for (Integer childId : oldChildrenSet) {
1128             if (!newChildrenSet.contains(childId)) {
1129
1130                 // Remove the child
1131                 updatedObject.removeChild(childId);
1132
1133                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1134
1135                 /* Remove an uicontrol */
1136                 if (childType == __GO_UICONTROL__) {
1137                     updatedComponent.remove((Component) allObjects.get(childId).getValue());
1138                     needRevalidate = true;
1139                 }
1140             }
1141         }
1142
1143         if (!hasOpenGLAxes) {
1144             updatedComponent.removeAxes();
1145             needRevalidate = true;
1146         }
1147
1148         if (needRevalidate && updatedComponent != null) {
1149             updatedComponent.revalidate();
1150         }
1151
1152         // Force repaint if we removed components
1153         if (oldComponentCount > updatedComponent.getComponentCount()) {
1154             updatedComponent.repaint();
1155         }
1156     }
1157
1158     private void updateScrollableFrameChildren(TypedObject updatedObject, Integer[] newChildren) {
1159         SwingScilabScrollableFrame updatedComponent = (SwingScilabScrollableFrame) updatedObject.getValue();
1160         boolean needRevalidate = false;
1161         int oldComponentCount = updatedComponent.getPanel().getComponentCount();
1162
1163         // Add new children
1164         for (Integer childId : newChildren) {
1165             if (!updatedObject.hasChild(childId)) {
1166
1167                 // Add the child
1168                 updatedObject.addChild(childId);
1169
1170                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1171
1172                 /* Add an uicontrol */
1173                 if (childType == __GO_UICONTROL__) {
1174                     updatedComponent.addMember(allObjects.get(childId).getValue());
1175                     needRevalidate = true;
1176                 }
1177             }
1178         }
1179
1180         // Remove children which have been deleted
1181         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1182         // Clone the children set to avoid concurrent accesses
1183         Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1184         for (Integer childId : oldChildrenSet) {
1185             if (!newChildrenSet.contains(childId)) {
1186
1187                 // Remove the child
1188                 updatedObject.removeChild(childId);
1189
1190                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1191
1192                 /* Remove an uicontrol */
1193                 if (childType == __GO_UICONTROL__) {
1194                     updatedComponent.getPanel().remove((Component) allObjects.get(childId).getValue());
1195                     needRevalidate = true;
1196                 }
1197             }
1198         }
1199         if (needRevalidate && updatedComponent != null) {
1200             updatedComponent.getPanel().revalidate();
1201         }
1202
1203         // Force repaint if we removed components
1204         if (oldComponentCount > updatedComponent.getPanel().getComponentCount()) {
1205             updatedComponent.repaint();
1206         }
1207
1208     }
1209
1210     /**
1211      * Update the frame children (called by generic updateObject method)
1212      * @param id the id of the figure
1213      * @param newChildren the new children IDs list
1214      */
1215     private void updateLayerChildren(TypedObject updatedObject, Integer[] newChildren) {
1216         SwingScilabLayer updatedComponent = (SwingScilabLayer) updatedObject.getValue();
1217
1218         // Add new children
1219         for (Integer childId : newChildren) {
1220             if (!updatedObject.hasChild(childId)) {
1221
1222                 // Add the child
1223                 updatedObject.addChild(childId);
1224
1225                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1226
1227                 /* Add an uicontrol */
1228                 if (childType == __GO_UICONTROL__) {
1229                     int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
1230                     if (childStyle == __GO_UI_FRAME__) {
1231                         SwingViewObject obj = allObjects.get(childId).getValue();
1232                         if (obj instanceof SwingScilabScrollableFrame) {
1233                             updatedComponent.addMember((SwingScilabScrollableFrame)obj);
1234                         } else {
1235                             updatedComponent.addMember((SwingScilabFrame)obj);
1236                         }
1237                     }
1238                 }
1239             }
1240         }
1241
1242         // Remove children which have been deleted
1243         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1244         // Clone the children set to avoid concurrent accesses
1245         Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1246         for (Integer childId : oldChildrenSet) {
1247             if (!newChildrenSet.contains(childId)) {
1248
1249                 // Remove the child
1250                 updatedObject.removeChild(childId);
1251
1252                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1253
1254                 /* Remove an uicontrol */
1255                 if (childType == __GO_UICONTROL__) {
1256                     int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
1257                     if (childStyle == __GO_UI_FRAME__) {
1258                         SwingViewObject obj = allObjects.get(childId).getValue();
1259                         if (obj instanceof SwingScilabScrollableFrame) {
1260                             updatedComponent.removeMember((SwingScilabScrollableFrame)obj);
1261                         } else {
1262                             updatedComponent.removeMember((SwingScilabFrame)obj);
1263                         }
1264                     }
1265                 }
1266             }
1267         }
1268     }
1269
1270     /**
1271      * Update the frame children (called by generic updateObject method)
1272      * @param id the id of the figure
1273      * @param newChildren the new children IDs list
1274      */
1275     private void updateTabGroupChildren(TypedObject updatedObject, Integer[] newChildren) {
1276         SwingScilabTabGroup updatedComponent = (SwingScilabTabGroup) updatedObject.getValue();
1277         boolean needRevalidate = false;
1278
1279         // Add new children
1280         for (Integer childId : newChildren) {
1281             if (!updatedObject.hasChild(childId)) {
1282
1283                 // Add the child
1284                 updatedObject.addChild(childId);
1285
1286                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1287
1288                 /* Add an uicontrol */
1289                 if (childType == __GO_UICONTROL__) {
1290                     String str = "Tab";
1291                     String[] text = (String[]) GraphicController.getController().getProperty(childId, __GO_UI_STRING__);
1292                     if (text != null && text.length != 0 && text[0] != null) {
1293                         str = text[0];
1294                     }
1295
1296                     updatedComponent.insertTab(str, null, (Component) allObjects.get(childId).getValue(), "", 0);
1297                     needRevalidate = true;
1298                 }
1299             }
1300         }
1301
1302         // Remove children which have been deleted
1303         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1304         // Clone the children set to avoid concurrent accesses
1305         Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1306         for (Integer childId : oldChildrenSet) {
1307             if (!newChildrenSet.contains(childId)) {
1308
1309                 // Remove the child
1310                 updatedObject.removeChild(childId);
1311
1312                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1313
1314                 /* Remove an uicontrol */
1315                 if (childType == __GO_UICONTROL__) {
1316                     updatedComponent.remove((Component) allObjects.get(childId).getValue());
1317                     needRevalidate = true;
1318                 }
1319             }
1320         }
1321         if (needRevalidate && updatedComponent != null) {
1322             updatedComponent.revalidate();
1323         }
1324     }
1325
1326     /**
1327      * Update the Console menus (called by generic updateObject method)
1328      * @param id the id of the console object
1329      * @param newChildren the new children IDs list
1330      */
1331     private void updateConsoleChildren(TypedObject updatedObject, Integer[] newChildren) {
1332         Container updatedComponent = (SwingScilabDockablePanel) updatedObject.getValue();
1333         boolean needRevalidate = false;
1334
1335         // Add new children
1336         for (Integer childId : newChildren) {
1337             if (!updatedObject.hasChild(childId)) {
1338
1339                 // Add the child
1340                 updatedObject.addChild(childId);
1341
1342                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1343
1344                 if (childType == __GO_UIMENU__) {
1345                     TypedObject childAsTypedObject = allObjects.get(childId);
1346                     switch (childAsTypedObject.getType()) {
1347                         case UiChildMenu:
1348                         case UiCheckedMenu:
1349                             TypedObject newUiParentMenu = CreateObjectFromType(__GO_UIPARENTMENU__, childId);
1350                             allObjects.put(childId, newUiParentMenu);
1351                             ((Container) ((SwingScilabDockablePanel) updatedObject.getValue()).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) newUiParentMenu.getValue());
1352                             break;
1353                         default: /* UiParentMenu */
1354                             ((Container) ((SwingScilabDockablePanel) updatedObject.getValue()).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) childAsTypedObject.getValue());
1355                             break;
1356                     }
1357                     needRevalidate = true;
1358                 }
1359             }
1360         }
1361
1362         // Remove children which have been deleted
1363         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1364         Object[] updatedObjectChildren = updatedObject.getChildren().toArray();
1365         for (int i = 0; i < updatedObjectChildren.length; ++i) {
1366             Integer childId = (Integer) updatedObjectChildren[i];
1367             if (!newChildrenSet.contains(childId)) {
1368
1369                 // Remove the child
1370                 updatedObject.removeChild(childId);
1371
1372                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1373
1374                 if (childType == __GO_UIMENU__) {
1375                     ((Container) ((SwingScilabDockablePanel) updatedObject.getValue()).getMenuBar().getAsSimpleMenuBar()).remove((SwingScilabMenu) allObjects.get(childId).getValue());
1376                     needRevalidate = true;
1377                 }
1378             }
1379         }
1380         if (needRevalidate && updatedComponent != null) {
1381             updatedComponent.validate();
1382         }
1383
1384     }
1385
1386     /**
1387      * Update the children of a menu menus (called by generic updateObject
1388      * method)
1389      * @param id the id of the menu object
1390      * @param newChildren the new children IDs list
1391      */
1392     private void updateMenuChildren(TypedObject updatedObject, Integer id, Integer[] newChildren) {
1393         Container updatedComponent = null;
1394         boolean needRevalidate = false;
1395         int updatedObjectPosition = 0;
1396         TypedObject newParent = null;
1397
1398         // Add new children
1399         for (Integer childId : newChildren) {
1400             int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1401             if (childType == __GO_UIMENU__) {
1402                 if (!updatedObject.hasChild(childId)) {
1403                     // Add the child
1404                     updatedObject.addChild(childId);
1405
1406                     TypedObject childAsTypedObject = allObjects.get(childId);
1407                     Object addedChild = allObjects.get(childId).getValue();
1408                     JComponent parent = null;
1409                     switch (updatedObject.getType()) {
1410                         case UiChildMenu:
1411                             updatedComponent = (SwingScilabMenuItem) updatedObject.getValue();
1412                             parent = (JComponent) updatedComponent.getParent();
1413                             switch (childAsTypedObject.getType()) {
1414                                 case UiChildMenu:
1415                                     /* Replace the item by a parent menu */
1416                                     if (parent != null) {
1417                                         updatedObjectPosition = parent.getComponentZOrder((SwingScilabMenuItem) updatedObject.getValue());
1418                                         parent.remove((SwingScilabMenuItem) updatedObject.getValue());
1419                                     }
1420                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1421                                     allObjects.put(id, newParent);
1422                                     newParent.addChild(childId);
1423                                     if (parent != null) {
1424                                         parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1425                                     }
1426                                     /* Update the created menu */
1427                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabMenuItem) addedChild);
1428                                     break;
1429                                 case UiCheckedMenu:
1430                                     /* Replace the item by a parent menu */
1431                                     if (parent != null) {
1432                                         updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1433                                         parent.remove((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1434                                     }
1435                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1436                                     allObjects.put(id, newParent);
1437                                     newParent.addChild(childId);
1438                                     if (parent != null) {
1439                                         parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1440                                     }
1441                                     /* Update the created menu */
1442                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabCheckBoxMenuItem) addedChild);
1443                                     break;
1444                                 default: /* UiParentMenu */
1445                                     ((SwingScilabMenu) updatedObject.getValue()).add((SwingScilabMenu) addedChild);
1446                                     break;
1447                             }
1448                             break;
1449                         case UiCheckedMenu:
1450                             updatedComponent = (SwingScilabCheckBoxMenuItem) updatedObject.getValue();
1451                             parent = (JComponent) updatedComponent.getParent();
1452                             switch (childAsTypedObject.getType()) {
1453                                 case UiChildMenu:
1454                                     /* Replace the item by a parent menu */
1455                                     if (parent != null) {
1456                                         updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1457                                         parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
1458                                     }
1459                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1460                                     allObjects.put(id, newParent);
1461                                     newParent.addChild(childId);
1462                                     if (parent != null) {
1463                                         parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1464                                     }
1465                                     /* Update the created menu */
1466                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabMenuItem) allObjects.get(childId).getValue());
1467                                     break;
1468                                 case UiCheckedMenu:
1469                                     /* Replace the item by a parent menu */
1470                                     if (parent != null) {
1471                                         updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1472                                         parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
1473                                     }
1474                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1475                                     allObjects.put(id, newParent);
1476                                     newParent.addChild(childId);
1477                                     if (parent != null) {
1478                                         parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1479                                     }
1480                                     /* Update the created menu */
1481                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1482                                     break;
1483                                 default: /* UiParentMenu */
1484                                     ((SwingScilabMenu) updatedObject.getValue()).add((SwingScilabMenu) allObjects.get(childId).getValue());
1485                                     break;
1486                             }
1487                             break;
1488                         default: /* UiParentMenu */
1489                             SwingScilabMenu updatedMenu = (SwingScilabMenu) updatedObject.getValue();
1490                             updatedComponent = updatedMenu;
1491                             switch (childAsTypedObject.getType()) {
1492                                 case UiChildMenu:
1493                                     updatedMenu.add((SwingScilabMenuItem) allObjects.get(childId).getValue());
1494                                     break;
1495                                 case UiCheckedMenu:
1496                                     updatedMenu.add((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1497                                     break;
1498                                 default: /* UiParentMenu */
1499                                     /* Java can not add a JMenu in a JMenu */
1500                                     /*
1501                                      * We need to convert the child into a
1502                                      * MenuItem
1503                                      */
1504                                     TypedObject newMenu = CreateObjectFromType(__GO_UIMENU__, childId);
1505                                     allObjects.put(childId, newMenu);
1506                                     updatedMenu.add((SwingScilabMenuItem) newMenu.getValue());
1507                                     break;
1508                             }
1509                             break;
1510                     }
1511                     needRevalidate = true;
1512                 }
1513             }
1514         }
1515         // Remove children which have been deleted
1516         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1517         Integer[] oldChildren = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1518         for (int childIndex = 0; childIndex < oldChildren.length; childIndex++) {
1519             Integer childId = oldChildren[childIndex];
1520             if (!newChildrenSet.contains(childId)) {
1521                 // Remove the child
1522                 updatedObject.removeChild(childId);
1523                 updatedComponent = (SwingScilabMenu) updatedObject.getValue();
1524
1525                 TypedObject childAsTypedObject = allObjects.get(childId);
1526                 Object removedMenu = childAsTypedObject.getValue();
1527
1528                 switch (childAsTypedObject.getType()) {
1529                     case UiChildMenu:
1530                         updatedComponent.remove((SwingScilabMenuItem) removedMenu);
1531                         break;
1532                     case UiCheckedMenu:
1533                         updatedComponent.remove((SwingScilabCheckBoxMenuItem) removedMenu);
1534                         break;
1535                     default:
1536                         updatedComponent.remove((SwingScilabMenu) removedMenu);
1537                         break;
1538                 }
1539                 needRevalidate = true;
1540             }
1541         }
1542         if (needRevalidate && updatedComponent != null) {
1543             updatedComponent.validate();
1544         }
1545     }
1546
1547     /**
1548      * Update the children of a contextmenu (called by generic updateObject
1549      * method)
1550      * @param id the id of the contextmenu object
1551      * @param newChildren the new children IDs list
1552      */
1553     private void updateContextMenuChildren(TypedObject updatedObject, Integer[] newChildren) {
1554         Container updatedComponent = null;
1555         boolean needRevalidate = false;
1556
1557         // Add new children
1558         for (Integer childId : newChildren) {
1559             int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1560             if (childType == __GO_UIMENU__) {
1561                 if (!updatedObject.hasChild(childId)) {
1562
1563                     // Add the child
1564                     updatedObject.addChild(childId);
1565
1566                     TypedObject childAsTypedObject = allObjects.get(childId);
1567                     SwingScilabContextMenu updatedMenu = (SwingScilabContextMenu) updatedObject.getValue();
1568                     updatedComponent = updatedMenu;
1569                     switch (childAsTypedObject.getType()) {
1570                         case UiChildMenu:
1571                             updatedMenu.add((SwingScilabMenuItem) allObjects.get(childId).getValue());
1572                             break;
1573                         case UiCheckedMenu:
1574                             updatedMenu.add((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1575                             break;
1576                         default: /* UiParentMenu */
1577                             updatedMenu.add((SwingScilabMenu) allObjects.get(childId).getValue());
1578                             break;
1579                     }
1580                     needRevalidate = true;
1581                 }
1582             }
1583         }
1584         // Remove children which have been deleted
1585         Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1586         for (Integer childId : updatedObject.getChildren()) {
1587             if (!newChildrenSet.contains(childId)) {
1588                 // Remove the child
1589                 updatedObject.removeChild(childId);
1590                 updatedComponent = (SwingScilabMenu) updatedObject.getValue();
1591
1592                 TypedObject childAsTypedObject = allObjects.get(childId);
1593                 SwingScilabContextMenu updatedMenu = (SwingScilabContextMenu) updatedObject.getValue();
1594                 Object removedMenu = allObjects.get(childId).getValue();
1595
1596                 switch (childAsTypedObject.getType()) {
1597                     case UiChildMenu:
1598                         updatedMenu.remove((SwingScilabMenuItem) removedMenu);
1599                         break;
1600                     case UiCheckedMenu:
1601                         updatedMenu.remove((SwingScilabCheckBoxMenuItem) removedMenu);
1602                         break;
1603                     default:
1604                         updatedMenu.remove((SwingScilabMenu) removedMenu);
1605                         break;
1606                 }
1607                 needRevalidate = true;
1608             }
1609         }
1610         if (needRevalidate && updatedComponent != null) {
1611             updatedComponent.validate();
1612         }
1613     }
1614
1615     private void requestFocus(TypedObject updatedObject) {
1616         SwingViewObject uicontrol = updatedObject.getValue();
1617         if (uicontrol instanceof SwingScilabScrollableFrame) {
1618             ((SwingScilabScrollableFrame) uicontrol).requestFocus();
1619         } else if (uicontrol instanceof SwingScilabFrame) {
1620             ((SwingScilabFrame) uicontrol).requestFocus();
1621         } else {
1622             ((Widget) uicontrol).requestFocus();
1623         }
1624     }
1625 }