Announcement Announcement Module
Collapse
No announcement yet.
ShuttleList component and bindings Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ShuttleList component and bindings

    I know that RCP's mission is not to create components, but it all boils down to components at some point :wink:

    I've put together a ShuttleList component (standard 2 lists with shuttle buttons). I've created an RCP binder and binding for it as well.

    The implementation is a little unique in that it really behaves like a different UI implementation for a single list. (I didn't actually do that since I don't know much about creating alternate UI implementations). The ShuttleList presents a typical selection model that represents the "chosen" elements. It can be used identically to the BoundList implementation that is part of RCP.

    If anyone is interested, I'm happy to share the code.

    Also, if anyone knows of a similar component that I should have looked at, please post it since I'd like to compare implementations.

    Larry.

  • #2
    what is shuttle list?
    can you send me a jar with it? (alex at law dot columbia dot edu)
    Cool controls never hurt :-)

    Thanks,
    Alex

    Comment


    • #3
      Re: ShuttleList component and bindings

      Originally posted by lstreepy
      If anyone is interested, I'm happy to share the code.
      Hi larry,
      I am now working on a shufflelist of a project. I am very anxious of your shufflelist code, would you share it
      many thanks!

      Comment


      • #4
        Ok - I've created a place for user community components on the wiki and posted the code for this one.

        Here's the link:

        http://opensource2.atlassian.com/con...nt+Integration

        Comment


        • #5
          Can you post an example of how to use this?

          Can you post an example of how to use this?

          Comment


          • #6
            --------------------------------------------------------------------------------

            Hi
            I use the component ShuttleList Larry posted. It is a nice component. I follow the sample he posted in the following link:http://opensource2.atlassian.com/con.../Contributions.

            It is cool. But I got two problems:
            1. when I push the edit button, the two lists are shown in the dialog. But they are in the compact format. I mean the contents of two lists are not shown immediatly. You must drag the dialog to make the dialog larger and then the whole two lists with contents are shown. Is there any one else who met that similar problem before?

            2. I want to manipulate the selected values in the list. I know there is a method of getSelectedValues() in the ShuttleList. But for the shuttle list creation, I have only shuttlelistForm for right now. How to get the selected values for this condition? I need to get the selected values to be saved into database. How can I do that?

            Thanks.
            Jeff

            Comment


            • #7
              Jeff,

              2. I want to manipulate the selected values in the list. I know there is a method of getSelectedValues() in the ShuttleList. But for the shuttle list creation, I have only shuttlelistForm for right now. How to get the selected values for this condition? I need to get the selected values to be saved into database. How can I do that?
              If you are using the shuttle list as a component bound to a domain object property, then there's no need for you to access the component's selected values directly. They are automatically placed into the bound property whenever they selected list changes. Can you explain why you would need to handle the value commit yourself?

              In any case, if you need to access the shuttle list component, you can do it using the normal return value of the form builder's add method, like this:

              Code:
              ShuttleList shuttle = (ShuttleList) subformBuilder.add( bf.createBoundShuttleList( "fhmSpecialty",
                          MasterLists.FHM_SPECIALTY_DESCRIPTIONS ), "align=left" )[1];
              shuttle.setVisibleRowCount( 5 );
              Note that the "createBoundShuttleList" comes from an extended binding factory as explained in the wiki.

              HTH,
              Larry.

              Comment


              • #8
                Thanks, Larry
                Actually, I figure that out that It has no need to manually control the selected values. It is nice. Actually I integrate the springRCP and hibernate, there is a many-to-many relationship between project and equipment. I use the shuttlelist to assign existing equipment to a project. For that condition, I just code

                equipmentShuttleListForm.commit();
                projectManager.storeProject(project);(projectManag er is similar to clinic in the petclinic sample)

                in the onfinish() method. I am not sure whether I am correct or not. It throws an exception: ERROR BasicPropertyAccessor:115 - IllegalArgumentException in class: Equipment, getter method of property: id. It seems that The project don't know which equipments are assigned. Could you give me some hints? Thank you.

                Jeff

                Comment


                • #9
                  Hi Jeff,

                  I'm sorry, but I've never used Hibernate, so I don't know off hand what the specific error message means.

                  A couple of things come to mind:

                  1. If the onFinish method you mention is the ApplicationDialog.onFinish, then the commit of the form(s) associated with the dialog have already been committed. So, the call to equipmentShuttleListForm.commit() would seem redundant, unless you're doing something out of the ordinary.

                  2. I don't know where the reference to "project" is coming from and it was updated by the form(s) associated with the dialog. Further, from a quick search of the web, the error you post implies that there is a problem with the "id" accessor method on the Equipment class. Beyond that, I really don't have enough context to help out.

                  Larry.

                  Comment


                  • #10
                    Larry,
                    I posted the code of my shuttlelist form and Assign Command:
                    package sjgeophysics.fieldman.ui;


                    public class EquipmentShuttleListForm extends AbstractForm{
                    private Collection allEquipments;
                    private ArrayList equipmentNameList = new ArrayList();


                    public static final String EQUIPMENTSHUTTLELIST_FORM_PAGE = "equipmentShuttleListProperties";


                    public EquipmentShuttleListForm(FormModel formModel) {
                    super(formModel, EQUIPMENTSHUTTLELIST_FORM_PAGE);

                    }

                    protected JComponent createFormControl() {
                    PdbBindingFactory pdf = (PdbBindingFactory)getBindingFactory();
                    TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());
                    for (Iterator i = allEquipments.iterator(); i.hasNext() {
                    Equipment equipment = (Equipment) i.next();
                    equipmentNameList.add(equipment.getModel() + " " + equipment.getType());
                    }
                    formBuilder.add(pdf.createBoundShuttleList("equipm ents", equipmentNameList));
                    return formBuilder.getForm();

                    }

                    public void setAllEquipments(Collection equipments) {
                    this.allEquipments = equipments;
                    // TODO Auto-generated method stub

                    }

                    }

                    // Assign an Equipment to a project
                    private class AssignEquipmentAction extends ActionCommand {

                    public AssignEquipmentAction() {
                    super("assignEquipmentCommand");
                    }

                    protected void doExecuteCommand() {

                    final Project project = getSelectedProject();

                    Collection equipments = projectManager.getEquipments();
                    final HierarchicalFormModel formModel = FormModelHelper
                    .createCompoundFormModel(project,
                    "equipmentShuttleListModel");

                    final EquipmentShuttleListForm equipmentShuttleListForm = new EquipmentShuttleListForm(
                    formModel);

                    equipmentShuttleListForm.setAllEquipments(equipmen ts);

                    final FormBackedDialogPage dialogPage = new FormBackedDialogPage(
                    equipmentShuttleListForm);

                    TitledPageApplicationDialog dialog = new TitledPageApplicationDialog(
                    dialogPage, getWindowControl()) {
                    protected void onAboutToShow() {
                    setEnabled(dialogPage.isPageComplete());
                    }

                    protected boolean onFinish() {
                    // add assign code here
                    equipmentShuttleListForm.commit();
                    projectManager.storeProject(project);

                    return true;
                    }
                    };
                    dialog.showDialog();

                    }
                    }

                    Thanks.
                    Jeff

                    Comment


                    • #11
                      Hey Jeff,

                      I haven't digested your code fully, but it looks like the problem is in the way that you construct the shuttle list binding. You are calling

                      Code:
                      formBuilder.add(pdf.createBoundShuttleList("equipm ents", equipmentNameList));
                      and equpmentNameList is a list of composed strings (not Equipment objects). Thus, when the selection is placed into the project object, it is storing String objects, not Equipment objects and that's probably what makes Hibernate choke.

                      Instead of making your selectable items list be Strings, they should be whatever object type the bound property expects, my guess here is that is an Equipment object. I would suggest that you try specifying the allEquipments list as the selectable objects, and then specify a renderer, or if you can change it, make the toString method on Equipment show "model + type". If you have to specify a renderer, you'll probably need to change the binding factory's createBoundShuttleList method since it is expecting a property name to render, and you appear to want to compose two properties into the value to display.

                      Larry.

                      Comment


                      • #12
                        Larry,
                        Thanks a lot!
                        I changed my code like what you suggested. It has no exception(nice). But I still can't save the assign relationship into the database. Because I really don't know how to tell the database to do the operation. I posted the changed code as follows:
                        public class EquipmentShuttleListForm extends AbstractForm{
                        private Collection allEquipments;
                        public static final String EQUIPMENTSHUTTLELIST_FORM_PAGE = "equipmentShuttleListProperties";


                        public EquipmentShuttleListForm(FormModel formModel) {
                        super(formModel, EQUIPMENTSHUTTLELIST_FORM_PAGE);

                        }

                        protected JComponent createFormControl() {
                        PdbBindingFactory pdf = (PdbBindingFactory)getBindingFactory();
                        TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());
                        formBuilder.add(pdf.createBoundShuttleList("equipm ents", allEquipments));
                        return formBuilder.getForm();

                        }

                        public void setAllEquipments(Collection equipments) {
                        this.allEquipments = equipments;
                        }
                        }

                        // Assign an Equipment to a project
                        private class AssignEquipmentAction extends ActionCommand {

                        public AssignEquipmentAction() {
                        super("assignEquipmentCommand");
                        }

                        protected void doExecuteCommand() {

                        final Project project = getSelectedProject();
                        Collection equipments = projectManager.getEquipments();
                        final HierarchicalFormModel formModel = FormModelHelper
                        .createCompoundFormModel(project,
                        "equipmentShuttleListModel");

                        final EquipmentShuttleListForm equipmentShuttleListForm = new EquipmentShuttleListForm(
                        formModel);

                        equipmentShuttleListForm.setAllEquipments(equipmen ts);

                        final FormBackedDialogPage dialogPage = new FormBackedDialogPage(
                        equipmentShuttleListForm);

                        TitledPageApplicationDialog dialog = new TitledPageApplicationDialog(
                        dialogPage, getWindowControl()) {
                        protected void onAboutToShow() {
                        setEnabled(dialogPage.isPageComplete());
                        }

                        protected boolean onFinish() {
                        // add assign code here
                        equipmentShuttleListForm.commit();
                        projectManager.storeProject(project);
                        return true;
                        }
                        };
                        dialog.showDialog();

                        }
                        }

                        I think all the transaction code should be in the onFinish() method. I just followed the architecture in the petclinic sample. I know you never use hibernate. But could you show me a little detail how to save this assign to the database. You can just use whatever database you are familiar. I just want to have a clear idea how to manipulate this shuttlelist. The database schema should be like: a table for project, a table for equipment, a mapping table for equipment and project(many-to-many).

                        Thank you very much!
                        Jeff

                        Comment


                        • #13
                          Hi Jeff, you say:

                          I just want to have a clear idea how to manipulate this shuttlelist.
                          This is where I think the misunderstanding lies. Since you are using a "bound" shuttle list, after the call to commit there's nothing else to do with the shuttle list. Its current selected values have already been stored into the form object (in your case, the object referenced by "project").

                          So you need to do whatever Hibernate requires to store the project object. It has already been updated in memory, you just need to get the changes persisted.

                          Larry.

                          Comment


                          • #14
                            Originally posted by lstreepy
                            Jeff,



                            If you are using the shuttle list as a component bound to a domain object property, then there's no need for you to access the component's selected values directly. They are automatically placed into the bound property whenever they selected list changes. Can you explain why you would need to handle the value commit yourself?

                            In any case, if you need to access the shuttle list component, you can do it using the normal return value of the form builder's add method, like this:

                            Code:
                            ShuttleList shuttle = (ShuttleList) subformBuilder.add( bf.createBoundShuttleList( "fhmSpecialty",
                                        MasterLists.FHM_SPECIALTY_DESCRIPTIONS ), "align=left" )[1];
                            shuttle.setVisibleRowCount( 5 );
                            Note that the "createBoundShuttleList" comes from an extended binding factory as explained in the wiki.

                            HTH,
                            Larry.

                            Thanks, Larry
                            Why I want the selected values, because I implement the JTree structure. I want the selected values shown as a node in the JTree. I try to follow your above sample code. But I don't where is subformBuilder. It can't be solved. Could you tell me where it is? Thanks

                            Comment


                            • #15
                              Hi Jeff,

                              If you need to update a tree structure after the form is committed, then just get the value of the "equipments" property. The bound shuttle list will have updated the property during the form model commit.

                              As for the "subformBuilder", equate it to your formBuilder, it's the same thing.

                              Larry.

                              Comment

                              Working...
                              X