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

import java.awt.GridLayout;
import java.util.ArrayList;

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.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                ((GridData) control.getLayoutData()).exclude = true;
                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.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                ((GridData) control.getLayoutData()).exclude = false;
                control.setVisible(true);
            }
        }
        if (layout) {
            view.layout(true, true);
        }
    }
    
    public void showEntry(ArrayList<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.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                ((GridData) control.getLayoutData()).exclude = false;
                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;
    }
    
    public static void addTableElementsAsList(ArrayList<Control> arrayList, Control[] previousControls, Control[] newControls) {
/*        Control [] controlArray = getTableElements(previousControls, newControls);
        for(Control control : controlArray) {
            arrayList.add(control);
        }*/
        
        //Control[] tableElements = new Control[newControls.length - previousControls.length];
        for (int i = previousControls.length; i < newControls.length; i++) {
            //tableElements[i - previousControls.length] = newControls[i];
            arrayList.add(newControls[i]);
        }
    }
}

@@ -114,16 +114,84 @@
 yList;%0A%0A
+import org.eclipse.swt.SWT;%0Aimport org.eclipse.swt.events.KeyEvent;%0A
 import o
@@ -4875,10 +4875,969 @@
 %7D%0A    %7D%0A
+    %0A    /**%0A     * This method will check if a specific key combination matches a defined%0A     * set of key combinations.%0A     * %0A     * @param e KeyEvent instance.%0A     * @return 'True' if matches, 'False' otherwise.%0A     */%0A    public static boolean isReservedKeyCombination(KeyEvent e) %7B%0A        boolean isReserved = false;%0A        %0A        if (e.keyCode == SWT.CR) %7B%0A            isReserved = true;%0A        %7D else if (e.keyCode == SWT.COMMAND) %7B%0A            isReserved = true;%0A        %7D else if (e.keyCode == SWT.CTRL) %7B%0A            isReserved = true;%0A        %7D else if (e.keyCode == SWT.ALT) %7B%0A            isReserved = true;%0A        %7D else if (e.keyCode == SWT.SHIFT) %7B%0A            isReserved = true;%0A        %7D else if (e.stateMask == SWT.COMMAND && e.character == 's') %7B%0A            isReserved = true;%0A        %7D else if (e.stateMask == SWT.CTRL && e.character == 's') %7B%0A            isReserved = true;%0A        %7D%0A        %0A        return isReserved;%0A    %7D%0A
 %7D%0A

Add method to check for reserved key combinations