Announcement Announcement Module
Collapse
No announcement yet.
Building complex forms Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Building complex forms

    Awhile back I when I was first starting out into building rich GUIs.(Swing/SpringRCP,quite a bit to take on all at once) I posted this thread and mock up screen: http://forum.springframework.org/vie...607&highlight=

    I now wanted to follow up with this to show what I had to do and it aint' pretty! So I'll post the source to the form at end of this text but I want to make a point. The current form builders that allow you to create forms in this manner:

    Code:
    TableFormBuilder formBuilder = new TableFormBuilder(getFormModel());
            
            this.inmateId = formBuilder.add("inmateId")[1];
            formBuilder.row();
            formBuilder.add("lastName");
            formBuilder.row();        
            formBuilder.add("firstName");
            formBuilder.row();
            formBuilder.add("soundEx");
            formBuilder.add("includeAka");
                    
            return formBuilder.getForm();
    Are very slick but if you have to do anything remotely complex, it falls apart. ie my form! So I guess my question is does anyone have any advice or pointers after seeing my code as to how I could tighten it up cuz' I've got ~1200 of views/forms to do and if they all have to be done this way I'm going to end up no better off then I am now with my current code base and tools (Sybase PowerBuilder). I do have some Ideas of my own I'd like to share but I'd like to heare what others have to say first.

    Lastly here is the code

    Code:
    public class CreateOffenderFormPg1 extends AbstractForm
    {
        public static final String PAGE_ONE = "pageOne";    
        private IdentificationSupport identificationSupport;    
        private SimpleDateFormat simpleDateFormat;    
        private JFormattedTextField iincarcerationNumber;    
        private JTextField iinmateId;    
        private JTextField ifirstName;    
        private JTextField iminit;    
        private JTextField ilastName;    
        private JFormattedTextField idob;
        private JComboBox isexPvv;
        private JComboBox iclassCodePvv;
        private JComboBox iracePvv;
        private JComboBox isecurityIdPvv;
        private JComboBox istatusPvv;
        private JFormattedTextField issno;
        private JComboBox iadmissionTypePvv;
        private JComboBox ictechnicalViolation;
        private JTextField ihealthAlert;
        private JComboBox idetainers1Pvv;
        private JComboBox idetainers2Pvv;
        private JComboBox idetainers3Pvv;
        private JComboBox idetainers4Pvv;
        private JComboBox idetainers5Pvv;
        private JTextField isrg;
        private JTextField iarea;
        private JTextField isuffix;
        private JTextField icellId;
        private JTextField ipinNo;
        private JTextField ijobCode;
            
        private JFormattedTextField istatusDate;
           
        private JTextField ipcReason;
        private JCheckBox ipcIndicatorBool;
        private JComboBox inonstInmateTypePvv;
        private JTextField ibciNumber;
        private JFormattedTextField icommConfEligDate;
        private JTextField isosLocation;
        private JTextField ifpNbr;
        private JFormattedTextField ifpClass1;
        private JTextField ifpNbr2;
        private JFormattedTextField ifpClass2;
        private JTextField ifbi;
        private JComboBox isosCodePvv;
        private JComboBox isosStatePvv;
        
        /** Creates a new instance of CreateOffender */
        public CreateOffenderFormPg1(FormModel formModel)
        {
            super(formModel, PAGE_ONE);                
        }
        
        private void initComponents()
        {
            identificationSupport = (IdentificationSupport)this.getFormObject();        
            simpleDateFormat = new SimpleDateFormat(getMessage("simpleDateFormat"));                
            iincarcerationNumber = new JFormattedTextField(new DecimalFormat("#"));        
            //iinmateId = new JFormattedTextField(new DecimalFormat("0000000"));
            
            ifirstName = new JTextField();
            iminit = new JTextField();
            ilastName = new JTextField();
            idob = new JFormattedTextField();
            issno = new JFormattedTextField(new DecimalFormat("000000000"));
            ihealthAlert = new JTextField();
            isrg = new JTextField();
            iarea = new JTextField();
            isuffix = new JTextField();
            icellId = new JTextField();
            ipinNo = new JTextField();
            ijobCode = new JTextField();        
            
            istatusDate = new JFormattedTextField();
                
            ipcReason = new JTextField();
            ipcIndicatorBool = new JCheckBox();
            ibciNumber = new JTextField();
            icommConfEligDate = new JFormattedTextField(simpleDateFormat);
            isosLocation = new JTextField();
            ifpNbr = new JTextField();
            ifpClass1 = new JFormattedTextField(new DecimalFormat("#"));
            ifpNbr2 = new JTextField();
            ifpClass2 = new JFormattedTextField(new DecimalFormat("#"));
            ifbi = new JTextField();
        }
        
        /**
         * Adds fill components to empty cells in the first row and first column of 
         * the grid. This ensures that the grid spacing will be the same as shown in
         * the designer.
         * @param cols an array of column indices in the first row where fill 
         *  components should be added.
         * @param rows an array of row indices in the first column where fill 
         *  components should be added.
         */
        private void addFillComponents( Container panel, int[] cols, int[] rows )
        {
            Dimension filler = new Dimension(10,10);
            
            boolean filled_cell_11 = false;
            CellConstraints cc = new CellConstraints();
            if ( cols.length > 0 && rows.length > 0 )
            {
                if ( cols[0] == 1 && rows[0] == 1 )
                {
                    /** add a rigid area  */
                    panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
                    filled_cell_11 = true;
                }
            }
            
            for&#40; int index = 0; index < cols.length; index++ &#41;
            &#123;
                if &#40; cols&#91;index&#93; == 1 && filled_cell_11 &#41;
                &#123;
                    continue;
                &#125;
                panel.add&#40; Box.createRigidArea&#40; filler &#41;, cc.xy&#40;cols&#91;index&#93;,1&#41; &#41;;
            &#125;
            
            for&#40; int index = 0; index < rows.length; index++ &#41;
            &#123;
                if &#40; rows&#91;index&#93; == 1 && filled_cell_11 &#41;
                &#123;
                    continue;
                &#125;
                panel.add&#40; Box.createRigidArea&#40; filler &#41;, cc.xy&#40;1,rows&#91;index&#93;&#41; &#41;;
            &#125;
        &#125;
        
        public JComponent buildScreen&#40;&#41;
        &#123;
            initComponents&#40;&#41;;
            JPanel jpanel1 = new JPanel&#40;&#41;;
            JScrollPane detailScrollPane = new JScrollPane&#40;&#41;;
            CellConstraints cc = new CellConstraints&#40;&#41;;        
            
            ////////////////////////////////////////////////////////////////////////
            //
            // Create and set the layout
            //
            ////////////////////////////////////////////////////////////////////////
            FormLayout formlayout1 = new FormLayout&#40;
                
                    /* Column Def */        
                    "FILL&#58;4DLU&#58;NONE,FILL&#58;85PX&#58;NONE,FILL&#58;4DLU&#58;NONE,"+
                    "FILL&#58;70DLU&#58;NONE,FILL&#58;4DLU&#58;NONE,"+
                    "FILL&#58;73PX&#58;NONE,FILL&#58;4DLU&#58;NONE,"+
                    "FILL&#58;MIN&#40;130PX;DEFAULT&#41;&#58;GROW&#40;1.0&#41;,FILL&#58;4DLU&#58;NONE,"+
                    "FILL&#58;80PX&#58;NONE,FILL&#58;4DLU&#58;NONE,"+
                    "FILL&#58;75DLU&#58;NONE,FILL&#58;4DLU&#58;NONE,"+
                    "FILL&#58;73PX&#58;NONE,FILL&#58;4DLU&#58;NONE,"+
                    "FILL&#58;60DLU&#58;NONE,FILL&#58;4DLU&#58;NONE",
                
                    /* Row Def */
                    "CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,"+
                    "CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,"+
                    "CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,"+
                    "CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,CENTER&#58;15DLU&#58;NONE,"+
                    "CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,"+
                    "CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,"+
                    "CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,"+
                    "CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,"+
                    "CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,"+
                    "CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,"+
                    "CENTER&#58;2DLU&#58;NONE,CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;2DLU&#58;NONE,"+
                    "CENTER&#58;DEFAULT&#58;NONE,CENTER&#58;12DLU&#58;GROW&#40;1.0&#41;"
                
                &#41;;
            
            jpanel1.setLayout&#40;formlayout1&#41;;
            
            ////////////////////////////////////////////////////////////////////////
            //
            // Bind the fields
            //
            ////////////////////////////////////////////////////////////////////////
            getFormModel&#40;&#41;.bind&#40;iincarcerationNumber, "iincarcerationNumber"&#41;; 
            //getFormModel&#40;&#41;.bind&#40;iinmateId, "iinmateId"&#41;;        
            iinmateId = getFormModel&#40;&#41;.createBoundTextField&#40;"iinmateId"&#41;;
            
            getFormModel&#40;&#41;.bind&#40;ifirstName, "ifirstName"&#41;;
            getFormModel&#40;&#41;.bind&#40;iminit, "iminit"&#41;;
            getFormModel&#40;&#41;.bind&#40;ilastName, "ilastName"&#41;;
            getFormModel&#40;&#41;.bind&#40;idob, "idob"&#41;;
                    
            isexPvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"isexPvv", identificationSupport.getIsexList&#40;&#41;
                .toArray&#40;&#41;&#41;;
            
            isexPvv.setEditable&#40;false&#41;;
            
            iclassCodePvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"iclassCodePvv", 
                 identificationSupport.getIclassCodeList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            iclassCodePvv.setEditable&#40;false&#41;;
            
            iracePvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"iracePvv", 
                 identificationSupport.getIraceList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            iracePvv.setEditable&#40;false&#41;;
            
            isecurityIdPvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"isecurityIdPvv", 
                 identificationSupport.getIsecurityIdList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            isecurityIdPvv.setEditable&#40;false&#41;;
            
            istatusPvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"istatusPvv", 
                 identificationSupport.getIstatusList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            istatusPvv.setEditable&#40;false&#41;;
            
            getFormModel&#40;&#41;.bind&#40;issno, "issno"&#41;;
            iadmissionTypePvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"iadmissionTypePvv", 
                 identificationSupport.getIadmissionTypeList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            iadmissionTypePvv.setEditable&#40;false&#41;;
            
            ictechnicalViolation = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"ictechnicalViolation", 
                 identificationSupport.getIctechnicalViolationList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            ictechnicalViolation.setEditable&#40;false&#41;;
            
            getFormModel&#40;&#41;.bind&#40;ihealthAlert, "ihealthAlert"&#41;;
            
            idetainers1Pvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"idetainers1Pvv", 
                 identificationSupport.getIdetainersList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            idetainers1Pvv.setEditable&#40;false&#41;;
            
            idetainers2Pvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"idetainers2Pvv", 
                 identificationSupport.getIdetainersList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            idetainers2Pvv.setEditable&#40;false&#41;;
            
            idetainers3Pvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"idetainers3Pvv", 
                 identificationSupport.getIdetainersList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            idetainers3Pvv.setEditable&#40;false&#41;;
            
            idetainers4Pvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"idetainers4Pvv", 
                 identificationSupport.getIdetainersList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            idetainers4Pvv.setEditable&#40;false&#41;;
            
            idetainers5Pvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"idetainers5Pvv", 
                 identificationSupport.getIdetainersList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            idetainers5Pvv.setEditable&#40;false&#41;;
            
            getFormModel&#40;&#41;.bind&#40;isrg, "isrg"&#41;;
            getFormModel&#40;&#41;.bind&#40;iarea, "iarea"&#41;;
            getFormModel&#40;&#41;.bind&#40;isuffix, "isuffix"&#41;;
            getFormModel&#40;&#41;.bind&#40;icellId, "icellId"&#41;;
            getFormModel&#40;&#41;.bind&#40;ipinNo, "ipinNo"&#41;;
            getFormModel&#40;&#41;.bind&#40;ijobCode, "ijobCode"/*, 
                    ValueCommitPolicy.FOCUS_LOST*/&#41;;                
            
            getFormModel&#40;&#41;.bind&#40;istatusDate, "istatusDate"&#41;;
            
            getFormModel&#40;&#41;.bind&#40;ipcReason, "ipcReason"&#41;;
            getFormModel&#40;&#41;.bind&#40;ipcIndicatorBool, "ipcIndicatorBool"&#41;;
            inonstInmateTypePvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"inonstInmateTypePvv", 
                 identificationSupport.getInonstInmateTypeList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            inonstInmateTypePvv.setEditable&#40;false&#41;;            
                
            getFormModel&#40;&#41;.bind&#40;ibciNumber, "ibciNumber"&#41;;
            getFormModel&#40;&#41;.bind&#40;icommConfEligDate, "icommConfEligDate"&#41;;
            getFormModel&#40;&#41;.bind&#40;isosLocation, "isosLocation"&#41;;
            getFormModel&#40;&#41;.bind&#40;ifpNbr, "ifpNbr"&#41;;
            getFormModel&#40;&#41;.bind&#40;ifpClass1, "ifpClass1"&#41;;
            getFormModel&#40;&#41;.bind&#40;ifpNbr2,"ifpNbr2"&#41;;
            getFormModel&#40;&#41;.bind&#40;ifpClass2, "ifpClass2"&#41;;
            getFormModel&#40;&#41;.bind&#40;ifbi, "ifbi"&#41;;
            isosCodePvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"isosCodePvv", 
                 identificationSupport.getIsosCodeList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            isosCodePvv.setEditable&#40;false&#41;;
            
            isosStatePvv = getFormModel&#40;&#41;
                .createBoundComboBox&#40;"isosStatePvv", 
                 identificationSupport.getIsosStateList&#40;&#41;.toArray&#40;&#41;&#41;;
            
            isosStatePvv.setEditable&#40;false&#41;;
            
            ///////////////////////////////////////////////////////////////////////
            //
            // add the Fields to the layout.
            //
            ///////////////////////////////////////////////////////////////////////        
            addComponentToPanel&#40;cc.xy&#40;4,2&#41;, jpanel1, iincarcerationNumber, 
                    "iincarcerationNumber"&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;4,4&#41;, jpanel1, iinmateId, "iinmateId", true&#41;;
            addComponentToPanel&#40;cc.xy&#40;4,6&#41;, jpanel1, ifirstName, "ifirstName", 
                    true&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;8,6&#41;, jpanel1, iminit, "iminit", true&#41;;
            addComponentToPanel&#40;cc.xy&#40;12,6&#41;, jpanel1, ilastName, "ilastName", true&#41;; 
            
            addComponentToPanel&#40;cc.xy&#40;4,8&#41;, jpanel1, new SCTDateChooser&#40;idob, "idob"&#41;, 
                    "idob", true&#41;;        
            
            cc = new CellConstraints&#40;8,8,1,1, CellConstraints.DEFAULT, 
                    CellConstraints.CENTER&#41;;
            
            addComponentToPanel&#40;cc, jpanel1, isexPvv, "isexPvv", true&#41;;        
            cc = new CellConstraints&#40;12,8,5,1,CellConstraints.DEFAULT,
                    CellConstraints.CENTER&#41;;
            
            addComponentToPanel&#40;cc, jpanel1, iclassCodePvv, "iclassCodePvv", true&#41;;        
            addComponentToPanel&#40;cc.xy&#40;4,10&#41;, jpanel1, iracePvv, "iracePvv", true&#41;;
            addComponentToPanel&#40;cc.xywh&#40;12,10,5,1&#41;, jpanel1, isecurityIdPvv, 
                    "isecurityIdPvv", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,14,5,1&#41;, jpanel1, istatusPvv, 
                    "istatusPvv", true&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;8,10&#41;, jpanel1, issno, "issno", true&#41;;
            addComponentToPanel&#40;cc.xywh&#40;4,16,5,1&#41;, jpanel1, iadmissionTypePvv, 
                    "iadmissionTypePvv", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;12,16,5,1&#41;, jpanel1, 
                    ictechnicalViolation, "ictechnicalViolation", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;12,20,5,1&#41;, jpanel1, ihealthAlert, 
                    "ihealthAlert", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,22,5,1&#41;, jpanel1, idetainers1Pvv, 
                    "idetainers1Pvv", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,24,5,1&#41;, jpanel1, idetainers2Pvv, 
                    "idetainers2Pvv", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,26,5,1&#41;, jpanel1, idetainers3Pvv, 
                    "idetainers3Pvv", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,28,5,1&#41;, jpanel1, idetainers4Pvv, 
                    "idetainers4Pvv", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,30,5,1&#41;, jpanel1, idetainers5Pvv, 
                    "idetainers5Pvv", true&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;8,2&#41;, jpanel1, isrg, "isrg", true&#41;;
            addComponentToPanel&#40;cc.xy&#40;12,12&#41;, jpanel1, iarea, "iarea", true&#41;;
            addComponentToPanel&#40;cc.xy&#40;16,6&#41;, jpanel1, isuffix, "isuffix", true&#41;;
            addComponentToPanel&#40;cc.xywh&#40;14,12,3,1&#41;, jpanel1, icellId, "icellId", 
                    true&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;8,4&#41;, jpanel1, ipinNo, "ipinNo", true&#41;;
            addComponentToPanel&#40;cc.xy&#40;12,2&#41;, jpanel1, ijobCode, "ijobCode", true&#41;;
     
            
            addComponentToPanel&#40;cc.xy&#40;12,14&#41;, jpanel1, new SCTDateChooser&#40;
                istatusDate, "istatusDate"&#41;, "istatusDate", true&#41;;
       
    
            addComponentToPanel&#40;cc.xywh&#40;12,18,5,1&#41;, jpanel1, ipcReason, 
                    "ipcReason", true&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;10,18&#41;, jpanel1, ipcIndicatorBool, 
                    "ipcIndicatorBool", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,18,5,1&#41;, jpanel1, inonstInmateTypePvv, 
                    "inonstInmateTypePvv", true&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;12,4&#41;, jpanel1, ibciNumber, "ibciNumber", 
                    false&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;16,4&#41;, jpanel1, icommConfEligDate, 
                    "icommConfEligDate", false&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;10,32,3,1&#41;, jpanel1, isosLocation, 
                    "isosLocation", true&#41;;
    
            addComponentToPanel&#40;cc.xywh&#40;14,26,3,1&#41;, jpanel1, ifpNbr, "ifpNbr", 
                    true&#41;;
            
            addComponentToPanel&#40;cc.xy&#40;12,26&#41;, jpanel1, ifpClass1, "ifpClass1", 
                    true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;14,28,3,1&#41;, jpanel1, ifpNbr2, "ifpNbr2", 
                    true&#41;;        
            
            addComponentToPanel&#40;cc.xy&#40;12,28&#41;, jpanel1, ifpClass2, "ifpClass2", 
                    true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;12,24,5,1&#41;, jpanel1, ifbi, "ifbi", true&#41;;
            addComponentToPanel&#40;cc.xywh&#40;4,32,3,1&#41;, jpanel1, isosCodePvv, 
                    "isosCodePvv", true&#41;;
            
            addComponentToPanel&#40;cc.xywh&#40;4,34,3,1&#41;, jpanel1, isosStatePvv, 
                    "isosStatePvv", true&#41;;
            
            ipcIndicatorBool.setActionCommand&#40;"P.C."&#41;;
            ipcIndicatorBool.setBackground&#40;new Color&#40;212,208,200&#41;&#41;;
            ipcIndicatorBool.setOpaque&#40;false&#41;;
            ipcIndicatorBool.setText&#40;"P.C."&#41;;
            ipcIndicatorBool.setHorizontalAlignment&#40;JCheckBox.RIGHT&#41;;
            ipcIndicatorBool.setHorizontalTextPosition&#40;JCheckBox.LEFT&#41;;
            
            ////////////////////////////////////////////////////////////////////////
            //
            // Labels
            //
            ////////////////////////////////////////////////////////////////////////        
            addLabelToPanel&#40;cc.xy&#40;6,6&#41;, jpanel1, "odv.iminit"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,6&#41;, jpanel1, "odv.ilastName"&#41;;
            addLabelToPanel&#40;cc.xy&#40;6,8&#41;, jpanel1, "odv.isexPvv"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,8&#41;, jpanel1, "odv.iclassCodePvv"&#41;;
            addLabelToPanel&#40;cc.xy&#40;6,10&#41;, jpanel1, "odv.issno"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,10&#41;, jpanel1, "odv.isecurityId1"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,12&#41;, jpanel1, "odv.iAreaCell"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,2&#41;, jpanel1, "odv.iincarcerationNumber"&#41;;        
            addLabelToPanel&#40;cc.xy&#40;2,4&#41;, jpanel1, "odv.iinmateId"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,6&#41;, jpanel1, "odv.ifirstName"&#41;;        
            addLabelToPanel&#40;cc.xy&#40;2,8&#41;, jpanel1, "odv.idob"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,10&#41;, jpanel1, "odv.iracePvv"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,14&#41;, jpanel1, "odv.istatus1"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,16&#41;, jpanel1, "odv.iadmissionType"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,16&#41;, jpanel1, "odv.ictechnicalViolation"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,20&#41;, jpanel1, "odv.ihealthAlert"&#41;;        
            addLabelToPanel&#40;cc.xy&#40;14,6&#41;, jpanel1, "odv.isuffix"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,22&#41;, jpanel1, "odv.idetainers1"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,24&#41;, jpanel1, "odv.idetainers2"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,26&#41;, jpanel1, "odv.idetainers3"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,28&#41;, jpanel1, "odv.idetainers4"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,30&#41;, jpanel1, "odv.idetainers5"&#41;;
            addLabelToPanel&#40;cc.xy&#40;6,2&#41;, jpanel1, "odv.isrg"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,2&#41;, jpanel1, "odv.ijobCode"&#41;;
            addLabelToPanel&#40;cc.xy&#40;6,4&#41;, jpanel1, "odv.ipinNo"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,4&#41;, jpanel1, "odv.ibciNumber"&#41;;
            addLabelToPanel&#40;cc.xy&#40;14,4&#41;, jpanel1, "odv.icommConfEligDate"&#41;;        
            addLabelToPanel&#40;cc.xy&#40;2,18&#41;, jpanel1, "odv.inonstInmateType"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,14&#41;, jpanel1, "odv.istatusDate"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,32&#41;, jpanel1, "odv.isosCode"&#41;;
            addLabelToPanel&#40;cc.xy&#40;8,32&#41;, jpanel1, "odv.isosLocation"&#41;;
            addLabelToPanel&#40;cc.xy&#40;10,28&#41;, jpanel1, "odv.ifpClass1"&#41;;
            
            JLabel jlabel34 = new JLabel&#40;&#41;;
            jlabel34.setFont&#40;new Font&#40;"Dialog",Font.BOLD,12&#41;&#41;;
            jlabel34.setText&#40;"/"&#41;;
            jlabel34.setHorizontalAlignment&#40;JLabel.CENTER&#41;;
            jpanel1.add&#40;jlabel34,cc.xy&#40;13,28&#41;&#41;;
            
            addLabelToPanel&#40;cc.xy&#40;10,26&#41;, jpanel1, "odv.ifpNbr"&#41;;
                    
            JLabel jlabel36 = new JLabel&#40;&#41;;
            jlabel36.setFont&#40;new Font&#40;"Dialog",Font.BOLD,12&#41;&#41;;
            jlabel36.setText&#40;"/"&#41;;
            jlabel36.setHorizontalAlignment&#40;JLabel.CENTER&#41;;
            jpanel1.add&#40;jlabel36,cc.xy&#40;13,26&#41;&#41;;
            
            addLabelToPanel&#40;cc.xy&#40;10,24&#41;, jpanel1, "odv.ifbi"&#41;;
            addLabelToPanel&#40;cc.xy&#40;2,34&#41;, jpanel1, "odv.isosState"&#41;;        
            
            addFillComponents&#40;jpanel1,
                    new int&#91;&#93;&#123; 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 &#125;,
                    new int&#91;&#93;&#123; 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
                               21,22,23,24,25,26,27,28,29,30,31,32,33,34,35 &#125;&#41;;
            return jpanel1;
        &#125;
        
        protected JComponent createFormControl&#40;&#41;
        &#123;
            return buildScreen&#40;&#41;;
        &#125;
        
        public boolean requestFocusInWindow&#40;&#41; &#123;
             return iinmateId.requestFocusInWindow&#40;&#41;;        
        &#125;
        
        private void addComponentToPanel&#40;CellConstraints cc, JComponent 
                thePanel, JComponent theComponent, String theName&#41;
        &#123;
            addComponentToPanel&#40;cc, thePanel,theComponent, theName, false&#41;;
        &#125;
        
        private void addComponentToPanel&#40;CellConstraints cc, JComponent thePanel, 
                JComponent theComponent, String theName, boolean enabled&#41;
        &#123;
            theComponent.setEnabled&#40;enabled&#41;;
            theComponent.setName&#40;theName&#41;;
            thePanel.add&#40;theComponent, cc&#41;;
        &#125;
        
        private void addLabelToPanel&#40;CellConstraints cc, JPanel thePanel, 
                String theName&#41;
        &#123;
            addLabelToPanel&#40;cc, thePanel, theName, JLabel.TRAILING&#41;;
        &#125;
        
        private void addLabelToPanel&#40;CellConstraints cc, JPanel thePanel, 
                String theName, int HorizontalAlignment&#41;
        &#123;
            JLabel jlabel = new JLabel&#40;&#41;;
            jlabel.setText&#40;getMessage&#40;theName+".label"&#41;&#41;;
            jlabel.setHorizontalAlignment&#40;HorizontalAlignment&#41;;
            thePanel.add&#40;jlabel,cc&#41;;
        &#125;
    and the image

    http://<br /> <a href="http://www.t...h=64</a><br />

  • #2
    Once you've got the hang of TableFormBuilder and TableLayoutBuilder it's really not that hard at all. Off the top of my head you'd do something like the following:

    Code:
    protected JComponent createFormControl&#40;&#41; &#123;
    
    	TableFormBuilder formBuilder = new TableFormBuilder&#40;getFormModel&#40;&#41;&#41;; 
            
    	// row 1
    	formBuilder.add&#40;"iincarcerationNumber"&#41;; 
    	formBuilder.add&#40;"isrg"&#41;; 
    	formBuilder.add&#40;"ijobCode", "colspan=1"&#41;; 
    
    	// row 2
    	formBuilder.row&#40;&#41;; 
    	formBuilder.add&#40;"iinmateId"&#41;; 
    	formBuilder.add&#40;"ipinNo"&#41;; 
    	formBuilder.add&#40;"ibciNumber"&#41;; 
    	formBuilder.add&#40;"icommConfEligDate"&#41;; 
    
    	...
    
    	// row 6
    	formBuilder.row&#40;&#41;; 	
    	formBuilder.getLayoutBuilder&#40;&#41;.cell&#40;"colspan=4"&#41;;
    	formBuilder.add&#40;"iarea"&#41;; 	
    	formBuilder.getLayoutBuilder&#40;&#41;
    		.cell&#40;getFormModel&#40;&#41;.createBoundControl&#40;"icellId"&#41;&#41;;
    
    	...
    
    	// row 9
    	formBuilder.row&#40;&#41;; 
    	formBuilder.add&#40;"inonstInmateType", "colspan=3"&#41;; 
    	formBuilder.getLayoutBuilder&#40;&#41;
    		.cell&#40;getFormModel&#40;&#41;.createBoundControl&#40;"ipcIndicatorBool"&#41;&#41;;
    	formBuilder.getLayoutBuilder&#40;&#41;
    		.cell&#40;getFormModel&#40;&#41;.createBoundControl&#40;"ipcReason"&#41;&#41;;
    
    	...
    	return formBuilder.getForm&#40;&#41;;
    &#125;
    DISCLAIMER: I donít guaranty this will work as I've just typed this straight in ;-) but it should give you the idea.

    Also a few suggestions:

    * For the special date pickers use a custom PropertyEditor registered for the Date class. That way they get automatically inserted where needed.
    * Let the binding framework create all of your controls rather than doing it yourself. In your initComponents() method you are creating whole lot of components expect for the JFormattedTextFields there's not need. In fact you can even avoid explicitly creating the JFormattedTextFields by registering custom PropertyEditors for the fields that need the special JFormattedTextField formatting.

    HTH

    Ollie

    Comment


    • #3
      Thanks Ollie! Is there a way to control the space between the columns? Like the number of DLUs or PXs' and what if I want to disable a field ie. theComponent.setEnabled(false);

      thanks again for all your help.

      Originally posted by oliverhutchison
      Once you've got the hang of TableFormBuilder and TableLayoutBuilder it's really not that hard at all. Off the top of my head you'd do something like the following:

      Code:
      protected JComponent createFormControl&#40;&#41; &#123;
      
      	TableFormBuilder formBuilder = new TableFormBuilder&#40;getFormModel&#40;&#41;&#41;; 
              
      	// row 1
      	formBuilder.add&#40;"iincarcerationNumber"&#41;; 
      	formBuilder.add&#40;"isrg"&#41;; 
      	formBuilder.add&#40;"ijobCode", "colspan=1"&#41;; 
      
      	// row 2
      	formBuilder.row&#40;&#41;; 
      	formBuilder.add&#40;"iinmateId"&#41;; 
      	formBuilder.add&#40;"ipinNo"&#41;; 
      	formBuilder.add&#40;"ibciNumber"&#41;; 
      	formBuilder.add&#40;"icommConfEligDate"&#41;; 
      
      	...
      
      	// row 6
      	formBuilder.row&#40;&#41;; 	
      	formBuilder.getLayoutBuilder&#40;&#41;.cell&#40;"colspan=4"&#41;;
      	formBuilder.add&#40;"iarea"&#41;; 	
      	formBuilder.getLayoutBuilder&#40;&#41;
      		.cell&#40;getFormModel&#40;&#41;.createBoundControl&#40;"icellId"&#41;&#41;;
      
      	...
      
      	// row 9
      	formBuilder.row&#40;&#41;; 
      	formBuilder.add&#40;"inonstInmateType", "colspan=3"&#41;; 
      	formBuilder.getLayoutBuilder&#40;&#41;
      		.cell&#40;getFormModel&#40;&#41;.createBoundControl&#40;"ipcIndicatorBool"&#41;&#41;;
      	formBuilder.getLayoutBuilder&#40;&#41;
      		.cell&#40;getFormModel&#40;&#41;.createBoundControl&#40;"ipcReason"&#41;&#41;;
      
      	...
      	return formBuilder.getForm&#40;&#41;;
      &#125;
      DISCLAIMER: I donít guaranty this will work as I've just typed this straight in ;-) but it should give you the idea.

      Also a few suggestions:

      * For the special date pickers use a custom PropertyEditor registered for the Date class. That way they get automatically inserted where needed.
      * Let the binding framework create all of your controls rather than doing it yourself. In your initComponents() method you are creating whole lot of components expect for the JFormattedTextFields there's not need. In fact you can even avoid explicitly creating the JFormattedTextFields by registering custom PropertyEditors for the fields that need the special JFormattedTextField formatting.

      HTH

      Ollie

      Comment


      • #4
        special date pickers

        Originally posted by oliverhutchison
        <snip>
        * For the special date pickers use a custom PropertyEditor registered for the Date class. That way they get automatically inserted where needed.
        <snip>
        My custom date picker takes two parameters a JFormattedTextField (which is used in the binding ) and a string to name the control. So how would I pass thease two parameters to the PropertyEditor? Could I inject them as a bean?

        Comment


        • #5
          Thanks Ollie! Is there a way to control the space between the columns? Like the number of DLUs or PXs' and what if I want to disable a field ie. theComponent.setEnabled(false);
          You can specify the space of each cell, so the column sizes the greater cell it contains using the flag "colSpec=XXX" where XXX is the size in DLU's (you can also use pixels writing "colSpec=XXXpx") :
          Code:
             
             // row 1
             formBuilder.add&#40;"iincarcerationNumber", "colSpec=50"&#41;;
             formBuilder.add&#40;"isrg"&#41;;
             formBuilder.add&#40;"ijobCode", "colspan=1"&#41;;
          The space between columns is similar, but using the call .gapCol():
          Code:
             
             // row 1
             formBuilder.add&#40;"iincarcerationNumber"&#41;;
             formBuilder.getLayoutBuilder&#40;&#41;.gapCol&#40;"colSpec=10"&#41;;
             formBuilder.add&#40;"isrg"&#41;;
             formBuilder.getLayoutBuilder&#40;&#41;.gapCol&#40;"colSpec=10"&#41;;
             formBuilder.add&#40;"ijobCode", "colspan=1"&#41;;
          And you an also set the space between rows with .row()
          Code:
             
             // row 1
             formBuilder.add&#40;"iincarcerationNumber"&#41;;
             formBuilder.getLayoutBuilder&#40;&#41;.row&#40;"colSpec=10"&#41;;
             // row2
             formBuilder.add&#40;"isrg"&#41;;

          Comment


          • #6
            Thanks...

            ...this is a big help.

            Comment


            • #7
              Hi Scott,

              If you need mode control and visual edit of your forms, I suggest you to take a look in JFormDesigner, it's a WYSIWYG tool.
              I'm using it just to draw my interfaces and I'm very satisfied.

              Mauro.

              Comment


              • #8
                Already have it another very good one is Abeille forms Designer from Jetaware. They both do a great job with jgoodies layout. How are you making out with getting what is generated from the tool and integrating it into springRPC? What are the steps you are going through?

                TIA,

                Comment


                • #9
                  Hi Scott,

                  Unfortunately the steps are manual, there is no integration.
                  What I do is to copy the layout builded by tool and paste inside my code doing the tunning.
                  The code from JFormsDesigner that interests me is some like this:
                  Code:
                  	contentPane.setLayout&#40;new FormLayout&#40;
                  		new ColumnSpec&#91;&#93; &#123;
                  			FormFactory.DEFAULT_COLSPEC,
                  			FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                  			new ColumnSpec&#40;"max&#40;default;40dlu&#41;"&#41;,
                  			FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                  			new ColumnSpec&#40;"max&#40;default;90dlu&#41;"&#41;
                  		&#125;,
                  		new RowSpec&#91;&#93; &#123;
                  			FormFactory.DEFAULT_ROWSPEC,
                  			FormFactory.LINE_GAP_ROWSPEC,
                  			FormFactory.DEFAULT_ROWSPEC,
                  			FormFactory.LINE_GAP_ROWSPEC,
                  			FormFactory.DEFAULT_ROWSPEC
                  		&#125;&#41;&#41;;
                  	
                  	//---- label1 ----
                  	label1.setText&#40;"State&#58;"&#41;;
                  	contentPane.add&#40;label1, cc.xy&#40;1, 1&#41;&#41;;
                  	contentPane.add&#40;state, cc.xy&#40;3, 1&#41;&#41;;
                  	
                  	//---- label2 ----
                  	label2.setText&#40;"City&#58;"&#41;;
                  	contentPane.add&#40;label2, cc.xy&#40;1, 3&#41;&#41;;
                  	contentPane.add&#40;jcbCity, cc.xywh&#40;3, 3, 3, 1&#41;&#41;;
                  	
                  	//---- label3 ----
                  	label3.setText&#40;"Quarter&#58;"&#41;;
                  	contentPane.add&#40;label3, cc.xy&#40;1, 5&#41;&#41;;
                  	contentPane.add&#40;jcbQuarter, cc.xywh&#40;3, 5, 3, 1&#41;&#41;;
                  
                  	...
                  What I do is to 'convert it' to RCP 'style', so in my Form:
                  Code:
                      protected JComponent createFormControl&#40;&#41;
                      &#123;
                          getObjectConfigurer&#40;&#41;.configure&#40;this, QUARTER_FORM_PAGE&#41;;
                          CellConstraints cc = new CellConstraints&#40;&#41;;
                          FormLayout layout = new FormLayout&#40;
                              new ColumnSpec&#91;&#93; &#123;
                                  FormFactory.DEFAULT_COLSPEC,
                                  FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                  new ColumnSpec&#40;"max&#40;default;40dlu&#41;"&#41;, //$NON-NLS-1$
                                  FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                  new ColumnSpec&#40;"max&#40;default;90dlu&#41;"&#41; &#125;,
                              new RowSpec&#91;&#93; &#123; //$NON-NLS-1$
                                  FormFactory.DEFAULT_ROWSPEC,
                                  FormFactory.LINE_GAP_ROWSPEC,
                                  FormFactory.DEFAULT_ROWSPEC,
                                  FormFactory.LINE_GAP_ROWSPEC,
                                  FormFactory.DEFAULT_ROWSPEC &#125;&#41;;
                  
                          JGoodiesBeanFormBuilder formBuilder = new JGoodiesBeanFormBuilder&#40;
                              getBindingFactory&#40;&#41;, layout&#41;;
                          DefaultFormBuilder defaultFormBuilder = formBuilder.getDefaultFormBuilder&#40;&#41;;
                  
                          SwingBindingFactory factory = &#40;SwingBindingFactory&#41; getBindingFactory&#40;&#41;;
                  
                          //state
                          defaultFormBuilder.add&#40;getComponentFactory&#40;&#41;.createLabel&#40;"city.state"&#41;, //$NON-NLS-1$
                              cc.xy&#40;1, 1&#41;&#41;;
                          this.jcbState = defaultFormBuilder.add&#40;createStatesField&#40;&#41;, cc.xy&#40;3, 1&#41;&#41;;
                  
                          //city
                          defaultFormBuilder.add&#40;getComponentFactory&#40;&#41;.createLabel&#40;"city"&#41;, //$NON-NLS-1$
                              cc.xy&#40;1, 3&#41;&#41;;
                          this.jcbCity = defaultFormBuilder
                              .add&#40;createCitiesField&#40;&#41;, cc.xywh&#40;3, 3, 3, 1&#41;&#41;;
                  	...
                      &#125;
                  I hope in a near future the guys from FormDev will create an plugin for Eclipse. :roll:
                  If you know a better way, please post it.

                  Thanks,

                  Mauro.

                  Comment


                  • #10
                    Scott,
                    sorry, I (attempted to) posta really long answered to your problem with the FormBuilder last night but I must not have hit submit (I've had some very long days lately...).

                    Xtreme has covered similar ground to the post you never received (thanks Xtreme). Basically IMHO there's no grid based layout you can't do using TableFromLayout once you get the hang of it. When I coded TableFormBuilder I simply wanted to take the best from HTML forms and JGoodies forms. I believe I've done this though I've not really documented it as well as I should have.

                    Trust me. Once you get he hang of it you'll never look back!

                    Ollie

                    PS. I'll attempt to hit submit on any new posts I send on this subject. ;-)s

                    Comment


                    • #11
                      Thanks Ollie for all your efforts, I'm in the mist of trying out the FormBuilder based on the responses in this thread. And have posted other questions. In partictualr custom PropertyEditor. But first I think I need to update to the lastest sources from cvs before I continue. So once again thanks for all your work and help.

                      Comment

                      Working...
                      X