package org.wso2.developerstudio.eclipse.gmf.esb.presentation;

import java.awt.GridLayout;

import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class EEFPropertyViewUtil {

    Composite view;

    public EEFPropertyViewUtil(Composite view) {
        this.view = view;
    }

    public void clearElements(Composite[] propertiesGroups) {
        for (Composite propertiesGroup : propertiesGroups) {
        	hideEntry(propertiesGroup.getChildren(), false);
        }
    }
    
    public void clearElement(Control control) {
    	 if (control.getLayoutData() != null && control.getLayoutData() instanceof GridData) {
             ((GridData) control.getLayoutData()).exclude = true;
             control.setVisible(false);
         }
    }

    public void hideEntry(Control controls[], boolean layout) {
        // view.getChildren();
        for (Control control : controls) {
            // null check and type check
            control.setLayoutData( new GridData(GridData.FILL_HORIZONTAL));
            control.setEnabled(true);
            if (control.getLayoutData() != null && control.getLayoutData() instanceof GridData) {
                ((GridData) control.getLayoutData()).exclude = true;
                control.setVisible(false);
            } else if (control.getLayoutData() != null && control.getLayoutData() instanceof FormData) {
               // ((FormData) control.getLayoutData()). = true;
                control.setVisible(false);
            } else {
                control.setVisible(false);
            }
        }
        if (layout) {
            view.layout(true, true);
        }
    }

    public void showEntry(Control controls[], boolean layout) {
        for (Control control : controls) {
            // null check and type check
            control.setLayoutData( new GridData(GridData.FILL_HORIZONTAL));
            control.setEnabled(true);
            if (control.getLayoutData() != null && control.getLayoutData() instanceof GridData) {
               ((GridData) control.getLayoutData()).exclude = false;
                control.setVisible(true);
            } else if (control.getLayoutData() != null && control.getLayoutData() instanceof FormData) {
                control.setVisible(true);
            } else {
                control.setVisible(true);
            }
        }
        if (layout) {
            view.layout(true, true);
        }
    }
    
    public static Control[] getTableElements(Control[] previousControls, Control[] newControls) {
        Control [] tableElements = new Control[newControls.length - previousControls.length];
        for (int i = previousControls.length; i < newControls.length; i++) {
            tableElements[i - previousControls.length] = newControls[i];
        }
        return tableElements;
    }
}

@@ -519,17 +519,20 @@
         
-%09
+    
 hideEntr
@@ -580,36 +580,32 @@
         %7D%0A    %7D%0A
-    
 %0A    public void
@@ -645,9 +645,11 @@
     
-%09
+   
  if 
@@ -735,33 +735,32 @@
 ) %7B%0A            
- 
 ((GridData) cont
@@ -800,33 +800,32 @@
 ue;%0A            
- 
 control.setVisib
@@ -827,33 +827,32 @@
 Visible(false);%0A
- 
         %7D%0A    %7D%0A
@@ -1034,32 +1034,35 @@
 heck%0A           
+ //
  control.setLayo
@@ -1478,16 +1478,17 @@
         
+ 
 // ((For
@@ -1584,32 +1584,180 @@
        %7D else %7B%0A
+                control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));%0A                ((GridData) control.getLayoutData()).exclude = true;%0A
                 
@@ -2034,32 +2034,35 @@
 heck%0A           
+ //
  control.setLayo
@@ -2253,32 +2253,33 @@
 %0A               
+ 
 ((GridData) cont
@@ -2518,32 +2518,181 @@
        %7D else %7B%0A
+                control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));%0A                ((GridData) control.getLayoutData()).exclude = false;%0A
                 
@@ -2816,20 +2816,16 @@
 %7D%0A    %7D%0A
-    
 %0A    pub
@@ -2930,17 +2930,16 @@
  Control
- 
 %5B%5D table

Refactor layout fix