enable/disable a tab children frame, enable/disable tab title to show its state 25/13825/3
Antoine ELIAS [Tue, 25 Feb 2014 11:37:39 +0000 (12:37 +0100)]
Change-Id: Ie3b13595aa4d8620e12ec9c4259f89dda3789d7a

scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabFrame.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabScrollableFrame.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabTabGroup.java

index a9995ae..eb4b960 100644 (file)
@@ -847,7 +847,7 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
             }
             case __GO_VISIBLE__: {
                 boolean needUpdate = true;
-                Component parent = ((SwingScilabFrame)this).getParent();
+                Component parent = getParent();
                 if (parent instanceof SwingScilabLayer) {
                     //no no no don't touch visible on layer children !
                     Boolean visible = (Boolean) value;
@@ -877,7 +877,7 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
                 break;
             }
             case __GO_TAG__ : {
-                Component parent = ((SwingScilabFrame)this).getParent();
+                Component parent = getParent();
                 if (parent instanceof SwingScilabLayer) {
                     SwingScilabLayer layer = (SwingScilabLayer)parent;
                     layer.updateModelProperties(null, layer.getActiveLayer());
@@ -915,6 +915,16 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
                 components[compIndex].setEnabled(false);
             }
         }
+
+        //if parent is a tab enable/disable children tab
+        Component parent = getParent();
+        if (parent instanceof SwingScilabTabGroup) {
+            SwingScilabTabGroup tab = (SwingScilabTabGroup)parent;
+            Integer index = tab.getIndex(this);
+            if (index != -1) {
+                tab.setEnabledAt(index, status);
+            }
+        }
     }
 
     public void resetBackground() {
index e8e4cf0..d32503f 100644 (file)
@@ -18,13 +18,9 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_GRID__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_PADDING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_PARENT__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_STYLE__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TAG__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LAYER__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
 
@@ -429,12 +425,9 @@ public class SwingScilabScrollableFrame extends JScrollPane implements SwingView
                 Container parent = getParent();
                 if (parent instanceof SwingScilabTabGroup) {
                     SwingScilabTabGroup tab = (SwingScilabTabGroup) parent;
-                    Component[] components = tab.getComponents();
-                    for (int i = 0; i < components.length; ++i) {
-                        if (components[i] instanceof SwingScilabScrollableFrame && this.getId() == ((SwingScilabScrollableFrame) components[i]).getId()) {
-                            tab.setTitleAt(i, ((String[]) value)[0]);
-                            break;
-                        }
+                    int index = tab.indexOfComponent(this);
+                    if (index != -1) {
+                        tab.setTitleAt(index, ((String[]) value)[0]);
                     }
                 }
                 break;
@@ -475,23 +468,27 @@ public class SwingScilabScrollableFrame extends JScrollPane implements SwingView
             }
             case __GO_VISIBLE__ : {
                 boolean needUpdate = true;
-                Integer parent = (Integer) controller.getProperty(uid, __GO_PARENT__);
-                if (parent != 0) {
-                    Integer type = (Integer) controller.getProperty(parent, __GO_TYPE__);
-                    if (type == __GO_UICONTROL__) {
-                        Integer style = (Integer) controller.getProperty(parent, __GO_STYLE__);
-                        if (style == __GO_UI_LAYER__) {
-                            //no no no don't touch visible on layer children !
-                            Boolean visible = (Boolean)value;
-                            SwingScilabLayer layer = (SwingScilabLayer) SwingView.getFromId(parent);
-                            Boolean isActive = layer.isLayerActive(this);
-                            if (isActive != visible ) {
-                                controller.setProperty(uid, __GO_VISIBLE__, isActive);
-                            }
-
-                            needUpdate = false;
-                        }
+                Component parent = getParent();
+                if (parent instanceof SwingScilabLayer) {
+                    //no no no don't touch visible on layer children !
+                    Boolean visible = (Boolean) value;
+                    SwingScilabLayer layer = (SwingScilabLayer) parent;
+                    Boolean isActive = layer.isLayerActive(this);
+                    if (isActive != visible) {
+                        controller.setProperty(uid, __GO_VISIBLE__, isActive);
+                    }
+
+                    needUpdate = false;
+                } else if (parent instanceof SwingScilabTabGroup) {
+                    //no no no don't touch visible on layer children !
+                    Boolean visible = (Boolean) value;
+                    SwingScilabTabGroup layer = (SwingScilabTabGroup) parent;
+                    Boolean isActive = layer.isTabActive(this);
+                    if (isActive != visible) {
+                        controller.setProperty(uid, __GO_VISIBLE__, isActive);
                     }
+
+                    needUpdate = false;
                 }
 
                 if (needUpdate) {
@@ -500,6 +497,16 @@ public class SwingScilabScrollableFrame extends JScrollPane implements SwingView
 
                 break;
             }
+            case __GO_TAG__ : {
+                Component parent = getParent();
+                if (parent instanceof SwingScilabLayer) {
+                    SwingScilabLayer layer = (SwingScilabLayer)parent;
+                    layer.updateModelProperties(null, layer.getActiveLayer());
+                } else if (parent instanceof SwingScilabTabGroup) {
+                    ((SwingScilabTabGroup)parent).updateModelProperties();
+                }
+                break;
+            }
             default:
                 SwingViewWidget.update(this, property, value);
                 break;
@@ -529,6 +536,16 @@ public class SwingScilabScrollableFrame extends JScrollPane implements SwingView
                 components[compIndex].setEnabled(false);
             }
         }
+
+        //if parent is a tab enable/disable children tab
+        Component parent = getParent();
+        if (parent instanceof SwingScilabTabGroup) {
+            SwingScilabTabGroup tab = (SwingScilabTabGroup)parent;
+            Integer index = tab.getIndex(this);
+            if (index != -1) {
+                tab.setEnabledAt(index, status);
+            }
+        }
     }
 
     public void setLayout(LayoutManager layout) {
index 80df1a9..0445e99 100644 (file)
@@ -252,5 +252,20 @@ public class SwingScilabTabGroup extends JTabbedPane implements SwingViewObject
         return false;
     }
 
+    public Integer getIndex(Component component) {
+        for (int i = 0 ; i < getTabCount() ; i++) {
+            if (getComponentAt(i) == component) {
+                return i;
+            }
+        }
 
+        return -1;
+    }
+
+    @Override
+    public void setEnabledAt(int index, boolean enabled) {
+        super.setEnabledAt(index, enabled);
+        //update tab label to show enabled state
+        getTabComponentAt(index).setEnabled(enabled);
+    }
 }