Results 1 to 5 of 5

Thread: Spring RCP and Abeille

  1. #1
    Join Date
    Jun 2005
    Posts
    16

    Default Spring RCP and Abeille

    Hi,

    I'm new to Spring RCP but browsing the code and samples I could figure out quite many things. I find it very promising.

    But I still have some doubts and hope you can help. I'm working with Abeille, I found it great to have the forms in a separate file etc. (if you know a better tool with its characteristics I would appreciate your opinion), anyways, what I want is to know the better way to show a dialog with Spring RCP (which class to extend and how to show it). I have already configured the main app., and a menu item which triggers a NewClientCommand. Now I want the newClientDialog to appear. It is not a Wizard, just a dialog with an Abellie form inside. Also I would like to know the best way to attach validation constraints and associate a command to the OK button in the dialog.

    Thanks in advance.

    Walbar

  2. #2
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    The following works:

    First you need to create a Form, this is necessary to get the validation stuff working:
    Code:
    public class NewClientForm extends AbstractForm {
        public NewClientForm(FormModel formModel) {
            super(formModel, "newClientForm");
        }
    
        /**
         * @see org.springframework.richclient.forms.AbstractForm#createFormControl()
         */
        protected JComponent createFormControl() {
            FormPanel formPanel = new FormPanel("foo/bar/Client.jfrm");
    
            FormAccessor accessor = formPanel.getFormAccessor();
    
            // bind the form components to the form model
            getBindingFactory().bind(accessor.getComboBox("title"), "title");
            getBindingFactory().bind(accessor.getTextField("firstName"), "firstName");
            getBindingFactory().bind(accessor.getTextField("lastName"), "lastName");
    
            return formPanel;
        }
    }
    For the validation, you need to create a RulesSource and define it in your spring context file. See the sample app for that.

    For the dialog:

    This creates a dialog with the form, and the onFinish method is called when the user presses the ok button.

    Code:
            Client newClient = new Client();
            final FormModel formModel = FormModelHelper.createFormModel(newClient);
    
            new TitledPageApplicationDialog(new NewClientForm(formModel), getWindowControl()) {
    
                protected boolean onFinish() {
                    formModel.commit();
                    Client newClient = formModel.getFormObject();
    
                    // do whatever you want to do
    
                    return true;
                }
    
            }.showDialog();
    Hope this helps

  3. #3
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    After giving this some thought: perhaps it would be possible to create a generic "integration" class that handles the binding transparantly.


    just of the top of my head, so there might be some errors in the following code :twisted:
    Code:
    public class AbeilleForm extends AbstractForm {
        private String[] properties;
        private FormPanel formPanel;
    
        public AbeilleForm(FormModel formModel, String id, FormPanel formPanel, String[] properties) {
            super(formModel, id);
            this.formPanel = formPanel;
            this.properties = properties;
        }
    
        /**
         * @see org.springframework.richclient.forms.AbstractForm#createFormControl()
         */
        protected JComponent createFormControl() {
            FormAccessor accessor = formPanel.getFormAccessor();
    
            for &#40;int i = 0; i < properties.length; i++&#41; &#123;
                getBindingFactory&#40;&#41;.bind&#40;&#40;JComponent&#41; accessor.getComponentByName&#40;properties&#91;i&#93;&#41;, properties&#91;i&#93;&#41;;
            &#125;
            return formPanel;
        &#125;
    &#125;

  4. #4
    Join Date
    Jun 2005
    Posts
    16

    Default

    Thanks a lot, this will help me much. I'll try your AbeilleForm approach and give some feedback.

    Walbar

  5. #5
    Join Date
    Jun 2005
    Posts
    16

    Default

    Hi,

    Following the above I coded a minimalistic example, but I get this exception when I try to display the form. Any clue?

    Code:
    &#91;ERROR,ApplicationLifecycleAdvisor,AWT-EventQueue-0&#93; component must be showing on the screen to determine its location
    java.awt.IllegalComponentStateException&#58; component must be showing on the screen to determine its location
    	at java.awt.Component.getLocationOnScreen_NoTreeLock&#40;Unknown Source&#41;
    	at java.awt.Component.getLocationOnScreen&#40;Unknown Source&#41;
    ...
    Here is my code:

    Create the form from Abeille:

    Code:
    protected JComponent createFormControl&#40;&#41; &#123;
    		FormPanel formPanel = new FormPanel&#40;"main/main.jfrm"&#41;;
    
    
    		FormAccessor accessor = formPanel.getFormAccessor&#40;&#41;;
    
    		// bind the form components to the form model
    		getBindingFactory&#40;&#41;.bindControl&#40;accessor.getTextField&#40;"nombre.field"&#41;, "nombre"&#41;;
    
    		return formPanel;
    	&#125;
    Pojo Class:
    Code:
    public class Usuario &#123;
    	
    	String nombre;
    	
    	
    	public void setNombre&#40;String value&#41;&#123;
    		
    		this.nombre = value;
    	&#125;
    	
    	public String getNombre&#40;&#41;&#123;
    	
    		return nombre;
    	&#125;
    &#125;
    And rules:

    Code:
    	private Rules createUsuarioRules&#40;&#41; &#123;
    		return new Rules&#40;Usuario.class&#41; &#123;
    			protected void initRules&#40;&#41; &#123;
    				add&#40;"nombre", required&#40;&#41;&#41;;
    			&#125;
    		&#125;;
    	&#125;
    It's weird because the exception is raised if I add the "nombre" required rule or if I bind the "nombre.field" component to the "nombre" property. If one of those lines is commented out, no exception is thrown and the form is displayed normally.

    Thanks,

    Walbar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •