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="PAGAGE_NAME" class="CLASS_NAME" %> <% 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 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); %> private Display display = new Display(); private Shell shell = new Shell(display); <% if (guiHelper.hasHiddenFields()){ List<IFormHidden> l = guiHelper.getHiddenFields(); for (Iterator<IFormHidden> iterator = form.elements().iterator(); iterator.hasNext();) { IFormHidden elem = (IFormHidden) iterator.next(); %> private <%=elem.getName() %>="<%=elem.getDefaultValue() %>"; <% } %> <% } %> <% for (Iterator<IFormElement> iterator = guiHelper.inputFields().iterator(); iterator.hasNext();){ IFormElement elem = (IFormElement) iterator.next(); %> %>private <%=guiHelper.getSWTClass(elem) %> <%=guiHelper.toName(elem) %>; <% } %> /** * Default constructor initializes this GUI element */ public <%=genClass.getClassName() %>(){ createControl(getShell()); } /** * 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 = new Composite(composite, SWT.NULL); 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 = form.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 } // Is not a form group %> <% } // the base element was not of type IFormGroup } // end for loop %> } <% if (guiHelper.hasButton(){ %> <% } %><% if (guiHelper.hasCheckBox(){ %> /** * Create checkboxes * @param parent container * @param lbl Lable field * @param btn Array of Button fields * @param lblText Label text * @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,Label lbl,Button[] btn,String lblText String[] tooltip, boolean[] visible, boolean[] editable,boolean[] selected) { Composite cont = new Composite(parent,SWT.NULL); FillLayout fl = new FillLayout(SWT.HORIZONTAL); cont.setLayout(fl); lbl = new Label(parent,SWT.NULL); lbl.setText(lblText); lbl.setVisible(visible[0]); for (int i = 0; i < selected.length; i++) { createCheckbox(cont,btn[i],tooltip[i],visible[i],editable[i],selected[i]); } } /** * Create a checkbox * @param parent container * @param btn Button field * @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 tooltip, boolean visible, boolean editable,boolean selected){ btn = new Button(parent,SWT.CHECK); 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 Lable 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,List<String> elements) { lbl = new Label(parent,SWT.NULL); lbl.setText(lableText); lbl.setVisible(lblVisibility); combo = new Combo(parent,SWT.DROP_DOWN); 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) { btn = new Button(parent,SWT.PUSH); 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 Lable 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 = new Label(parent,SWT.NULL); lbl.setText(lableText); lbl.setVisible(lblVisibility); txt = new Text(parent,SWT.BORDER | SWT.SINGLE); 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 Lable 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,List<String> elements,boolean multiselect) { lbl = new Label(parent,SWT.NULL); lbl.setText(lableText); lbl.setVisible(lblVisibility); if (multiselect){ list = new org.eclipse.swt.widgets.List(parent,SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); } else { list = new org.eclipse.swt.widgets.List(parent,SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); } 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 Lable 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 = new Label(parent,SWT.NULL); lbl.setText(lableText); lbl.setVisible(lblVisibility); txt = new Text(parent,SWT.BORDER | SWT.PASSWORD); 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 lbl Lable 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,Label lbl, Button[] btn,String lblText,String[] text, String[] tooltip, boolean[] visible, boolean[] editable,boolean[] selected) { Composite cont = new Composite(parent,SWT.NULL); FillLayout fl = new FillLayout(SWT.HORIZONTAL); cont.setLayout(fl); lbl = new Label(parent,SWT.NULL); 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]); } } /** * 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 = new Button(parent,SWT.RADIO); 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 = new Button(parent,SWT.PUSH); 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 Lable 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 = new Label(parent,SWT.NULL); lbl.setText(lableText); lbl.setVisible(lblVisibility); txt = new Text(parent,SWT.BORDER | SWT.WRAP| SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 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 lbl Lable 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,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 = new Label(parent,SWT.NULL); lbl.setText(lableText); lbl.setVisible(lblVisibility); Composite cont = new Composite(parent,SWT.NULL); FillLayout fl = new FillLayout(SWT.HORIZONTAL); cont.setLayout(fl); txt.setParent(cont); 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); btn = new Button(cont,SWT.PUSH); btn.setText(btnText); 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(); } <% } %> // construct container // create for the different fields }