Code Generator for Eclipse Code
Brought to you by:
hotzst
<%@ jet imports="java.util.* ch.sahits.model.* ch.sahits.model.db.* ch.sahits.model.java.* ch.sahits.model.java.db.* ch.sahits.codegen.java.model.util.* ch.sahits.model.gui.* ch.sahits.model.java.gui.* ch.sahits.codegen.java.gui.util.*" package="ch.sahits.codegen.java.gui" class="SWTGuiGenerator" %> <% IJavaForm genClass = (IJavaForm) argument; %> <%=ConvenientCodegen.toPackageDefinition(genClass.getPackageName()) %><% if (!genClass.superclasses().get(0).equals("") && !ConvenientCodegen.isPrimitiveClass(genClass.superclasses().get(0))){ %>import <%=genClass.superclasses().get(0).getName() %>; <% } // End if import superclass if (!genClass.interfaces().isEmpty()){ for (Iterator i = genClass.interfaces().iterator(); i.hasNext(); ){ Class c = (Class)i.next(); %> import <%=c.getName() %>; <% } // End for loop } // End if for import interfaces %> import java.util.Iterator; import java.util.Vector; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; <% if (genClass.isPublic()){ %> public <% } else if (genClass.isProtected()){ %> protected <% } else if (genClass.isPrivate()){ %> private <% } %><% if (genClass.isAbstract()) { %>abstract <% } %><% if (genClass.isFinal()) { %>final <% } %>class <%=genClass.getClassName() %> <% if (!genClass.superclasses().get(0).getName().equals("") && !ConvenientCodegen.isPrimitiveClass(genClass.superclasses().get(0))){ %> extends <%=ConvenientCodegen.getSimpleClassName(genClass.superclasses().get(0)) %> <% } if (!genClass.interfaces().isEmpty()){ int counter=0; int maxInt = genClass.interfaces().size();%> implements <% for (Iterator i = genClass.interfaces().iterator(); i.hasNext(); ){ Class c=(Class)i.next(); %><%=ConvenientCodegen.getSimpleClassName(c) %><% counter++; if ( counter<maxInt){%>, <% } // End if for comma %><% } // End for loop over interfaces%><% } // End if interfaces %> { <% SWTGUIHelper guiHelper = new SWTGUIHelper(genClass); genClass= guiHelper.convertOneColumnLayout(); %> private Display display = new Display(); private Shell shell = new Shell(display); <% if (guiHelper.hasHiddenFields()){ List<IFormHidden> l = guiHelper.getHiddenFields(); for (Iterator<IFormHidden> iterator = l.iterator(); iterator.hasNext();) { IFormHidden elem = (IFormHidden) iterator.next(); %> private String <%=elem.getName() %>="<%=elem.getDefaultValue() %>"; <% } %> <% } %> <% List<IFormElement> variables = new Vector<IFormElement>(); List<IFormElement> addedGroups = new Vector<IFormElement>(); for (Iterator<IFormElement> iterator = guiHelper.inputFields().iterator(); iterator.hasNext();){ IFormElement elem = (IFormElement) iterator.next(); variables.add(elem); if (elem instanceof IFormFileUpload) { %>private Composite <%=guiHelper.toName(elem) %>Comp; private <%=guiHelper.getSWTClass(elem) %> <%=guiHelper.toName(elem) %>; private Button <%=guiHelper.getBrowseButtonName((IFormFileUpload)elem) %>; <% } else if (elem instanceof IFormRadioButton){ IFormGroup parentGroup = guiHelper.getParentGroup(elem); if (!addedGroups.contains(parentGroup)){ addedGroups.add(parentGroup); %>private Composite <%=guiHelper.toName(elem) %>Comp; <% } // end if (!addedGroups.contains(parentGroup) %>private <%=guiHelper.getSWTClass(elem) %> <%=guiHelper.toName(elem) %>; <% } else if (elem instanceof IFormCheckbox){ IFormGroup parentGroup = guiHelper.getParentGroup(elem); if (!addedGroups.contains(parentGroup)){ addedGroups.add(parentGroup); %>private Composite <%=guiHelper.toName(elem) %>Comp; <% } // end if (!addedGroups.contains(parentGroup) %>private <%=guiHelper.getSWTClass(elem) %> <%=guiHelper.toName(elem) %>; <% } else { %>private <%=guiHelper.getSWTClass(elem) %> <%=guiHelper.toName(elem) %>; <% } // end else } // end for %> /** * Default constructor initializes this GUI element */ public <%=genClass.getClassName() %>(){ createControl(getShell()); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); } /** * Create all the field instances * @param parent container */ private void init(Composite parent){ <% for (Iterator<IFormElement> iterator = variables.iterator(); iterator.hasNext();){ IFormElement elem = (IFormElement) iterator.next(); %><%=guiHelper.initializeString(elem) %> <% } %> } /** * Retrive the shell of this GUI element * @return shell */ private Shell getShell(){ return shell; } /** * Set the control up with the layout and the input fields */ private void createControl(Composite composite) { Composite container = shell;//new Composite(composite, SWT.NULL); init(container); container.setFont(composite.getFont()); GridLayout layout = new GridLayout(); container.setLayout(layout); int nColumns = <%=guiHelper.getNumberOfColums() %>; layout.numColumns = nColumns; layout.verticalSpacing = 9; // Create the different elements <% for (Iterator<IFormElement> iterator = genClass.elements().iterator(); iterator.hasNext();) { IFormElement elem = (IFormElement) iterator.next(); if (elem instanceof IFormGroup){ IFormGroup group = (IFormGroup)elem; if (guiHelper.isFormGroup(group)){ // process the different elements EGUIGroup g = guiHelper.getGroupType(group); switch (g){ case BUTTON: case SUBMIT_BUTTON:{ IFormButton btn = (IFormButton) group.elements().get(1); String name = guiHelper.toName(btn); %>createButton(container, <%=name %>, "<%=btn.getDefaultValue() %>", "<%=btn.getTooltip() %>", <%=btn.isVisible() %>, <%=btn.isEnabled() %>);<% break; } // end submit button case CHECK_BOX:{ IFormGroup grp = (IFormGroup)group.elements().get(1); IFormLabel lbl = (IFormLabel) group.elements().get(0); String name1 = guiHelper.toName(lbl); List<IFormElement> ch = grp.elements(); boolean[] selected = new boolean[ch.size()]; for (int i = 0; i < selected.length; i++) { selected[i]=((IFormCheckbox)ch.get(i)).isChecked(); } %> { Button[] btns = {<% for (int i = 0; i < ch.size(); i++) { %><%=guiHelper.toName(ch.get(i)) %><% if (i!=ch.size()-1) {%>, <% } } %>}; String[] text = {<% for (int i = 0; i < ch.size(); i++) { %><% if (((IFormCheckbox)ch.get(i)).getDefaultValue().trim().equals("")){ %>""<% } else {%>"<%=((IFormCheckbox)ch.get(i)).getDefaultValue() %>"<% } if (i!=ch.size()-1) {%>, <% } } %>}; String[] tooltip = {<% for (int i = 0; i < ch.size(); i++) { %><% if (ch.get(i).getTooltip().trim().equals("")){ %>""<% } else {%>"<%=ch.get(i).getTooltip() %>"<% } if (i!=ch.size()-1) {%>, <% } } %>}; boolean[] visible={<% for (int i = 0; i < ch.size(); i++) { %><%=((IFormCheckbox)ch.get(i)).isVisible() %><% if (i!=ch.size()-1) {%>, <% } } %>}; boolean[] editable={<% for (int i = 0; i < ch.size(); i++) { %><%=((IFormCheckbox)ch.get(i)).isEnabled() %><% if (i!=ch.size()-1) {%>, <% } } %>}; boolean[] selected ={<% for (int i = 0; i < ch.size(); i++) { %><%=((IFormCheckbox)ch.get(i)).isChecked() %><% if (i!=ch.size()-1) {%>, <% } } IFormGroup parentGroup = guiHelper.getParentGroup(elem); String contName = guiHelper.toName(ch.get(0))+"Comp"; %>}; createCheckBoxes(container,<%=contName %>, <%=name1 %>, btns, "<%=lbl.getText() %>",text, tooltip , visible, editable, selected); }<% break; } // end checkbox case COMBO:{ IFormLabel lbl = (IFormLabel) group.elements().get(0); IFormCombo combo =(IFormCombo)group.elements().get(1); String name1 = guiHelper.toName(lbl); String name2 = guiHelper.toName(combo); %>{ Vector<String> l = new Vector<String>();<% for (int i=0;i<combo.elements().size();i++){ String s = (String)combo.elements().get(i); %>l.add("<%=s %>");<% }%> createCombo(container, <%=name1 %>, <%=name2 %>, "<%=lbl.getText() %>", <%=lbl.isVisible() %>, <%=combo.isVisible() %>, <%=combo.isEnabled() %>, "<%=combo.getTooltip() %>", <%=combo.getSelectedIndex() %>, l); }<% break; } // end combo case FILE_BROWSE:{ IFormLabel lbl = (IFormLabel) group.elements().get(0); IFormFileUpload txt =(IFormFileUpload)group.elements().get(1); String name1 = guiHelper.toName(lbl); String name2 = guiHelper.toName(txt); String name3 = guiHelper.getBrowseButtonName(txt); %>Vector<String> l = new Vector<String>();<% for (int i=0;i<txt.acceptedTypes().size();i++){ String s = (String)txt.acceptedTypes().get(i); %>l.add("<%=s %>");<% }%> { String[] accType = {<% for (int i = 0; i < txt.acceptedTypes().size(); i++) { %><% if (txt.acceptedTypes().get(i).trim().equals("")){ continue; } else {%>"<%=txt.acceptedTypes().get(i) %>"<% } if (i!=txt.acceptedTypes().size()-1) {%>, <% } } %>}; createFileBrowse(container, <%=name2 %>Comp, <%=name1 %>, <%=name2 %>, <%=name3 %>, "<%=lbl.getText() %>", <%=lbl.isVisible() %>, <%=txt.isVisible() %>, <%=txt.isEnabled() %>, "<%=txt.getTooltip() %>", "<%=txt.getDefaultValue() %>", "<%=txt.getButtonText() %>", accType); }<% break; } // end file browse case IMAGE_BUTTON:{ IFormImageButton btn = (IFormImageButton) group.elements().get(1); String name = guiHelper.toName(btn); %>createImageButton(container, <%=name %>, "<%=btn.getImageSrc() %>", "<%=btn.getTooltip() %>", <%=btn.isVisible() %>, <%=btn.isEnabled() %>);<% break; } // end image button case INPUT:{ IFormLabel lbl = (IFormLabel) group.elements().get(0); IFormInput txt =(IFormInput)group.elements().get(1); String name1 = guiHelper.toName(lbl); String name2 = guiHelper.toName(txt); %>createInput(container, <%=name1 %>, <%=name2 %>, "<%=lbl.getText() %>", <%=lbl.isVisible() %>, <%=txt.isVisible() %>, <%=txt.isEnabled() %>, "<%=txt.getTooltip() %>", "<%=txt.getDefaultValue() %>");<% break; } // end imput case LIST:{ IFormLabel lbl = (IFormLabel) group.elements().get(0); IFormList list =(IFormList)group.elements().get(1); String name1 = guiHelper.toName(lbl); String name2 = guiHelper.toName(list); %> { Vector<String> l = new Vector<String>();<% for (int i=0;i<list.elements().size();i++){ String s = (String)list.elements().get(i); %>l.add("<%=s %>");<% }%> createList(container, <%=name1 %>, <%=name2 %>, "<%=lbl.getText() %>", <%=lbl.isVisible() %>, <%=list.isVisible() %>, <%=list.isEnabled() %>, "<%=list.getTooltip() %>", l, <%=list.isMultiselect() %>); }<% break; } // end list case PASSWORD:{ IFormLabel lbl = (IFormLabel) group.elements().get(0); IFormPasswordInput txt =(IFormPasswordInput)group.elements().get(1); String name1 = guiHelper.toName(lbl); String name2 = guiHelper.toName(txt); %>createPassword(container, <%=name1 %>, <%=name2 %>, "<%=lbl.getText() %>", <%=lbl.isVisible() %>, <%=txt.isVisible() %>, <%=txt.isEnabled() %>, "<%=txt.getTooltip() %>", "<%=txt.getDefaultValue()%>");<% break; } // end password case RADIO_BUTTON:{ IFormGroup grp = (IFormGroup)group.elements().get(1); IFormLabel lbl = (IFormLabel) group.elements().get(0); String name1 = guiHelper.toName(lbl); List<IFormElement> ch = grp.elements(); %> { Button[] btns = {<% for (int i = 0; i < ch.size(); i++) { %><%=guiHelper.toName(ch.get(i)) %><% if (i!=ch.size()-1) {%>, <% } } %>}; String[] text = {<% for (int i = 0; i < ch.size(); i++) { %><% if (((IFormRadioButton)ch.get(i)).getDefaultValue().trim().equals("")){ %>""<% } else {%>"<%=((IFormRadioButton)ch.get(i)).getDefaultValue() %>"<% } if (i!=ch.size()-1) {%>, <% } } %>}; String[] tooltip = {<% for (int i = 0; i < ch.size(); i++) { %><% if (ch.get(i).getTooltip().trim().equals("")){ %>""<% } else {%>"<%=ch.get(i).getTooltip() %>"<% } if (i!=ch.size()-1) {%>, <% } } %>}; boolean[] visible={<% for (int i = 0; i < ch.size(); i++) { %><%=((IFormRadioButton)ch.get(i)).isVisible() %><% if (i!=ch.size()-1) {%>, <% } } %>}; boolean[] editable={<% for (int i = 0; i < ch.size(); i++) { %><%=((IFormRadioButton)ch.get(i)).isEnabled() %><% if (i!=ch.size()-1) {%>, <% } } %>}; boolean[] selected ={<% for (int i = 0; i < ch.size(); i++) { %><%=((IFormRadioButton)ch.get(i)).isChecked() %><% if (i!=ch.size()-1) {%>, <% } } IFormGroup parentGroup = guiHelper.getParentGroup(elem); String contName = guiHelper.toName(ch.get(0))+"Comp"; %>}; createRadioButtons(container,<%=contName %>, <%=name1 %>, btns, "<%=lbl.getText() %>", text, tooltip, visible, editable,selected); }<% break; } // end radio button case RESET_BUTTON:{ IFormResetButton btn = (IFormResetButton) group.elements().get(1); String name = guiHelper.toName(btn); %>createResetButton(container, <%=name %>, "<%=btn.getDefaultValue() %>", "<%=btn.getTooltip() %>", <%=btn.isVisible() %>, <%=btn.isEnabled() %>);<% break; } // end reset button case TEXT:{ IFormLabel lbl = (IFormLabel) group.elements().get(0); IFormInput txt =(IFormInput)group.elements().get(1); String name1 = guiHelper.toName(lbl); String name2 = guiHelper.toName(txt); %>createTextArea(container, <%=name1 %>, <%=name2 %>, "<%=lbl.getText() %>", <%=lbl.isVisible() %>, <%=txt.isVisible() %>, <%=txt.isEnabled() %>, "<%=txt.getTooltip() %>", "<%=txt.getDefaultValue() %>");<% break; } // end text } // end switch } // Is not a form group %> <% } // the base element was not of type IFormGroup else if (elem instanceof IFormResetButton){ IFormResetButton btn = (IFormResetButton) elem; String name = guiHelper.toName(btn); %>createResetButton(container, <%=name %>, "<%=btn.getDefaultValue() %>", "<%=btn.getTooltip() %>", <%=btn.isVisible() %>, <%=btn.isEnabled() %>); <% } else if (elem instanceof IFormButton) { IFormButton btn = (IFormButton) elem; String name = guiHelper.toName(btn); %>createButton(container, <%=name %>, "<%=btn.getDefaultValue() %>", "<%=btn.getTooltip() %>", <%=btn.isVisible() %>, <%=btn.isEnabled() %>); <% } } // end for loop %> } <% if (guiHelper.hasButton()){ %> /** * Create a button * @param parent container * @param btn Button * @param btnText button text * @param tooltip button tooltip * @param visible is the button visible * @param editable is the button cklickable */ private void createButton(Composite parent,Button btn,String btnText,String tooltip,boolean visible,boolean editable) { btn.setText(btnText); btn.setToolTipText(tooltip); btn.setEnabled(editable); btn.setVisible(visible); btn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // set the default data } }); } <% } %><% if (guiHelper.hasCheckBox()){ %> /** * Create checkboxes * @param parent container * @param cont Container for the buttons * @param lbl Label field * @param btn Array of Button fields * @param lblText Label text * @param text Array of labels for the check boxes * @param tooltip Array of tooltips of the buttons * @param visible Array of the buttons visibility * @param editable Array of the buttons editability * @param selected Array of the buttons selectedness */ private void createCheckBoxes(Composite parent,Composite cont,Label lbl,Button[] btn,String lblText,String[] text, String[] tooltip, boolean[] visible, boolean[] editable,boolean[] selected) { FillLayout fl = new FillLayout(SWT.HORIZONTAL); cont.setLayout(fl); lbl.setText(lblText); lbl.setVisible(visible[0]); for (int i = 0; i < selected.length; i++) { createCheckbox(cont,btn[i],text[i],tooltip[i],visible[i],editable[i],selected[i]); btn[i].setParent(cont); } } /** * Create a checkbox * @param parent container * @param btn Button field * @param text of labels for the check box * @param tooltip of the button * @param visible is the button visible * @param editable is the button editable * @param selected is the button selected */ private void createCheckbox(Composite parent,Button btn,String text, String tooltip, boolean visible, boolean editable,boolean selected){ btn.setText(text); btn.setToolTipText(tooltip); btn.setVisible(visible); btn.setEnabled(editable); btn.setSelection(selected); btn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // TODO Implement SelectionEvent } }); } <% } %><% if (guiHelper.hasCombo()){ %> /** * Create a text input field with preceeding lable * @param parent container * @param lbl Label field * @param list Combo field * @param lableText text of the lable * @param lblVisibility is the lable visible * @param inputVisibility is the input field visible * @param inputEditable ist the input field enabled and editibla * @param tooltip tooltip of the input field may be null * @param defaultSelection index of the default selection * @param elements List of all elements */ private void createCombo(Composite parent,Label lbl, Combo combo,String lableText, boolean lblVisibility, boolean inputVisibility,boolean inputEditable,String tooltip, int defaultSelection,java.util.List<String> elements) { lbl.setText(lableText); lbl.setVisible(lblVisibility); combo.setVisible(inputVisibility); combo.setEnabled(inputEditable); combo.setToolTipText(tooltip); for (Iterator<String> iterator = elements.iterator(); iterator.hasNext();) { String type = (String) iterator.next(); combo.add(type); } combo.select(defaultSelection); combo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // TODO: implement SelectionEvent } }); } <% } %><% if (guiHelper.hasImageButton()){ %> /** * Create a button * @param parent container * @param btn Button * @param imageSrc button image * @param tooltip button tooltip * @param visible is the button visible * @param editable is the button cklickable */ private void createImageButton(Composite parent,Button btn,String imageSrc,String tooltip,boolean visible,boolean editable) { Image image = new Image(parent.getDisplay(),imageSrc); btn.setImage(image); btn.setToolTipText(tooltip); btn.setEnabled(editable); btn.setVisible(visible); btn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // TODO: implement the SelectionEvent } }); } <% } %><% if (guiHelper.hasInputField()){ %> /** * Create a text input field with preceeding lable * @param parent container * @param lbl Label field * @param txt Text input field * @param lableText text of the lable * @param lblVisibility is the lable visible * @param inputVisibility is the input field visible * @param inputEditable ist the input field enabled and editibla * @param inputTooltip tooltip of the input field may be null * @param inputText text of the input field may be null */ private void createInput(Composite parent,Label lbl, Text txt,String lableText, boolean lblVisibility, boolean inputVisibility,boolean inputEditable,String inputTooltip,String inputText){ lbl.setText(lableText); lbl.setVisible(lblVisibility); GridData gd = new GridData(GridData.FILL_HORIZONTAL); txt.setLayoutData(gd); if (inputTooltip!=null) txt.setToolTipText(inputTooltip); txt.setVisible(inputVisibility); txt.setEnabled(inputEditable); txt.setEditable(inputEditable); if (inputText!=null) txt.setText(inputText); } <% } %><% if (guiHelper.hasList()){ %> /** * Create a text input field with preceeding lable * @param parent container * @param lbl Label field * @param list List field * @param lableText text of the lable * @param lblVisibility is the lable visible * @param inputVisibility is the input field visible * @param inputEditable ist the input field enabled and editibla * @param tooltip tooltip of the input field may be null * @param elements List of all elements * @param multiselect selection of several elements allowed */ private void createList(Composite parent,Label lbl, org.eclipse.swt.widgets.List list,String lableText, boolean lblVisibility, boolean inputVisibility,boolean inputEditable,String tooltip,java.util.List<String> elements,boolean multiselect) { lbl.setText(lableText); lbl.setVisible(lblVisibility); list.setVisible(inputVisibility); list.setEnabled(inputEditable); list.setToolTipText(tooltip); for (Iterator<String> iterator = elements.iterator(); iterator.hasNext();) { String type = (String) iterator.next(); list.add(type); } list.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // TODO: implement SelectionEvent } }); } <% } %><% if (guiHelper.hasPasswordField()){ %> /** * Create a text input field with preceeding lable * @param parent container * @param lbl Label field * @param txt Text input field * @param lableText text of the lable * @param lblVisibility is the lable visible * @param inputVisibility is the input field visible * @param inputEditable ist the input field enabled and editibla * @param inputTooltip tooltip of the input field may be null * @param inputText text of the input field may be null */ private void createPassword(Composite parent,Label lbl, Text txt,String lableText, boolean lblVisibility, boolean inputVisibility,boolean inputEditable,String inputTooltip,String inputText){ lbl.setText(lableText); lbl.setVisible(lblVisibility); GridData gd = new GridData(GridData.FILL_HORIZONTAL); txt.setLayoutData(gd); if (inputTooltip!=null) txt.setToolTipText(inputTooltip); txt.setVisible(inputVisibility); txt.setEnabled(inputEditable); txt.setEditable(inputEditable); if (inputText!=null) txt.setText(inputText); } <% } %><% if (guiHelper.hasRadioButton()){ %> /** * Create radio Buttons * @param parent container * @param cont Container for the buttons * @param lbl Label field * @param btn Array of Button fields * @param lblText label text * @param text Array of texts of the buttons * @param tooltip Array of tooltips of the buttons * @param visible Array of the buttons visibility * @param editable Array of the buttons editability * @param selected Array of the buttons selectedness */ private void createRadioButtons(Composite parent,Composite cont,Label lbl, Button[] btn,String lblText,String[] text, String[] tooltip, boolean[] visible, boolean[] editable,boolean[] selected) { FillLayout fl = new FillLayout(SWT.HORIZONTAL); cont.setLayout(fl); lbl.setText(lblText); lbl.setVisible(visible[0]); for (int i = 0; i < selected.length; i++) { createRadioButton(cont,btn[i],text[i],tooltip[i],visible[i],editable[i],selected[i]); btn[i].setParent(cont); } } /** * Create a radio Button * @param parent container * @param btn Button field * @param text Text of the button * @param tooltip of the button * @param visible is the button visible * @param editable is the button editable * @param selected is the button selected */ private void createRadioButton(Composite parent,Button btn,String text, String tooltip, boolean visible, boolean editable,boolean selected){ btn.setText(text); btn.setToolTipText(tooltip); btn.setVisible(visible); btn.setEnabled(editable); btn.setSelection(selected); btn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // TODO Implement SelectionEvent } }); } <% } %><% if (guiHelper.hasResetButton()){ %> /** * Create a reset buttonbutton * @param parent container * @param btn Button * @param btnText button text * @param tooltip button tooltip * @param visible is the button visible * @param editable is the button cklickable */ private void createResetButton(Composite parent,Button btn,String btnText,String tooltip,boolean visible,boolean editable) { btn.setText(btnText); btn.setToolTipText(tooltip); btn.setEnabled(editable); btn.setVisible(visible); btn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // set the default data } }); } <% } %><% if (guiHelper.hasTextArea()){ %> /** * Create a text input field with preceeding lable * @param parent container * @param lbl Label field * @param txt Text input field * @param lableText text of the lable * @param lblVisibility is the lable visible * @param inputVisibility is the input field visible * @param inputEditable ist the input field enabled and editibla * @param inputTooltip tooltip of the input field may be null * @param inputText text of the input field may be null */ private void createTextArea(Composite parent,Label lbl, Text txt,String lableText, boolean lblVisibility, boolean inputVisibility,boolean inputEditable,String inputTooltip,String inputText){ lbl.setText(lableText); lbl.setVisible(lblVisibility); GridData gd = new GridData(GridData.FILL_HORIZONTAL); txt.setLayoutData(gd); if (inputTooltip!=null) txt.setToolTipText(inputTooltip); txt.setVisible(inputVisibility); txt.setEnabled(inputEditable); txt.setEditable(inputEditable); if (inputText!=null) txt.setText(inputText); } <% } %><% if (guiHelper.hasFileBrowse()){ %> /** * Create a text input field with preceeding lable * @param parent container * @param cont Container for the file upload * @param lbl Label field * @param list txt Input field * @param btn Browse button * @param lableText text of the lable * @param lblVisibility is the lable visible * @param inputVisibility is the input field visible * @param inputEditable ist the input field enabled and editibla * @param inputTooltip tooltip of the input field may be null * @param inputText text of the input field may be null */ private void createFileBrowse(Composite parent,Composite cont, Label lbl,final Text txt, Button btn,String lableText, boolean lblVisibility, boolean inputVisibility,boolean inputEditable,String inputTooltip,String inputText,String btnText,final String[] fileTypes){ lbl.setText(lableText); lbl.setVisible(lblVisibility); FillLayout fl = new FillLayout(SWT.HORIZONTAL); cont.setLayout(fl); txt.setParent(cont); if (inputTooltip!=null) txt.setToolTipText(inputTooltip); txt.setVisible(inputVisibility); txt.setEnabled(inputEditable); txt.setEditable(inputEditable); if (inputText!=null) txt.setText(inputText); btn.setText(btnText); btn.setParent(cont); btn.setToolTipText(inputTooltip); btn.setEnabled(inputEditable); btn.setVisible(inputVisibility); btn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String selection = handleBroseFileSystem(fileTypes); if (selection!=null){ txt.setText(selection); } } }); } /** * Browse for the jet file * @param filter Array of filters in the form of *.jpg * @return selected file or null */ private String handleBroseFileSystem(String[] filter){ FileDialog dialog = new FileDialog(getShell(),SWT.OPEN); dialog.setText("Browse file"); dialog.setFilterExtensions(filter); dialog.setFilterNames(filter); return dialog.open(); } <% } %> }