1

I see in the tree representing my applications in the Scout Explorer view that I have two subfolders under the template node :

  • Forms
  • Form Fields

I know how to add form fields and its pretty simple, but I don't know how to create a form template and I can't find it on internet.

Marko

EDIT :

Now I figure out how to add form to From template folder. You just need to add abstract tag and then you can create new form from this template.

Now I need to change default main box class from : AbstractGroupBox to AbstractMyGroupBox. To be understand, what I need is to set somehow inside AbstractMyForm, that all form that come from AbstractMyForm template have instead :

public class TestFromForm extends AbstractMyForm

...

@Order(10.0)
@ClassId("e23ebc80-d948-4e23-aff6-ae49d3278331")
public class MainBox extends AbstractGroupBox {
    @Order(10.0)
    @ClassId("571bc88f-67ee-454d-b6ce-9616bc43bf74")
    public class OkButton extends AbstractOkButton {
    }
    @Order(20.0)
    @ClassId("66969857-002f-4689-981e-20ab60bbaf0e")
    public class CancelButton extends AbstractCancelButton {
    }
}

have this :

@Order(10.0)
@ClassId("e23ebc80-d948-4e23-aff6-ae49d3278331")
public class MainBox extends AbstractMyGroupBox {

}
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97

1 Answers1

1

You are right; there isn't any support in the Scout Perspective to create a form template. You need to use the Java tooling from the IDE.


Form template

A form template is nothing more than an Abstract class extending org.eclipse.scout.rt.client.ui.form.AbstractForm. Your template can be located where you want (where it makes sense, depending on your code organization). Possible package: <your_app>.client.ui.template.form.

This is a minimal example:

import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.form.AbstractForm;

public abstract class AbstractMyForm extends AbstractForm {

  /**
   * @throws ProcessingException
   */
  public AbstractMyForm() throws ProcessingException {
    super();
  }
}

Form and Mainbox

Be aware that a Form (used with a template or not) has only one MainBox (a root group box containing a tree of child fields). It is loaded during Form initialization. (see extended answer based on an example).

From the implementation of the private method AbstractForm.getConfiguredMainBox() I can deduce that only the first inner class implementing IGroupBox is selected.

Therefore Form Templates are suitable to mutualize logic on at form level. Sometime also some form handlers or tool buttons.

If the idea is to mutualize common fields between multiple forms, a possibility is to use a field template for the main box itself:

@Order(10.0)
public class MainBox extends AbstractMyTemplateGroupBox {
    //…
}

Without knowing more on the use case, it is hard to tell what you should do.

Community
  • 1
  • 1
Jmini
  • 9,189
  • 2
  • 55
  • 77
  • Thank you for your answer, but I have some sub question. I extend AbstractForm and have my MainBox with some tableField and it works. But when I want to use this template and I extend AbstractMyClassForm I rename MainBox in new form to newMainBox and give it a @Order(20.0) but table from template is still not showing. Do you have any clue why? – Marko Zadravec Sep 22 '14 at 05:48
  • Thanks, I think for this my self, but problem is that I have form with table and whole logic of download data with handlers. Then I want to have identical table with some additional fields below table, but loading logic is the same. – Marko Zadravec Sep 22 '14 at 09:26
  • Well without exactly knowing what you want to achieve, it is hard to tell how you could optimize your code organization. In a lot of project I have seen, combining AbstractGroupBox (a.k.a field template) with appropriate hooks, a form template and some code in static methods (Utility-like classes) is a way to go. I agree with you: it is a good principle to write similar logic only once. – Jmini Sep 23 '14 at 07:01
  • Please, can I ask You to check my new question. Thank you. http://stackoverflow.com/questions/25994014/extends-from-data-in-scout-eclipse – Marko Zadravec Sep 23 '14 at 11:36