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