0

I am working with GWT 2.0.0 in a Java 6 project. The functionality I am working on permits the user to select items within a DualListField but is allowed only a certain number of items. So I require that the 'Add selected' and 'Add all' buttons in a DualListField button bar to be disabled once a certain limit is reached (ie only x number of items can be selected). Has anyone attempted this before? Is there a simpler way other than customizing the DualListField?

Thanks.

beebris
  • 55
  • 2
  • 9

2 Answers2

2

Create a new XY Class that extends from DualListField. In this XY Class define something like:

public clas XY <D extends ModelData> extends DualListField<D>{
    public static final int leftButton = 0x1;
    public static final int rightButton = 0x2;
    public static final int allLeftButton = 0x3;
    public static final int allRightButton = 0x4;
    public static final int upButton = 0x5;
    public static final int downButton = 0x6;

List<Integer> buttonsToRemoveList;

public CustomDualListField(List<Integer> buttonsToRemoveList){
    super();
    this.buttonsToRemoveList = buttonsToRemoveList;
}

    @Override
    protected void onRender(Element target, int index) {
        super.onRender(target, index);

        if(buttonsToRemoveList != null){
            for(Integer val:buttonsToRemoveList){
                switch(val.intValue()){
                    case leftButton:{
                        buttonBar.remove(left);
                        break;
                    }
                    case rightButton:{
                        buttonBar.remove(right);
                        break;
                    }
                    case allLeftButton:{
                        buttonBar.remove(allLeft);
                        break;
                    }
                    case allRightButton:{
                        buttonBar.remove(allRight);
                        break;
                    }
                    case upButton:{
                        buttonBar.remove(up);
                        break;
                    }
                    case downButton:{
                        buttonBar.remove(down);
                        break;
                    }
                }
            }
        }
    }
}

With this approach you can configure the buttons that will be displayed.

anahuacv
  • 21
  • 2
0

I was kindof able to achieve this, by customizing DualListField and setting:

super.buttonBar.getWidget(0).setVisible(false) 
beebris
  • 55
  • 2
  • 9