Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 90840

Summary: [JFace] Strange label/id resolution in MessageDialogWithToggle.
Product: [Eclipse Project] Platform Reporter: Michael Van Meekeren <michaelvanmeekeren>
Component: UIAssignee: Susan McCourt <susan>
Status: RESOLVED DUPLICATE QA Contact:
Severity: minor    
Priority: P4    
Version: 3.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Michael Van Meekeren CLA 2005-04-08 14:28:36 EDT
the following code will generate duplicate ids (for example) because it assigns
an id to the field id based on the iteration of the loop when a label is not found.

So if I pass an array with 

String [] {IDialogConstants.YES, IDialogConstants.NO , "FRED"};

I will get 

Yes, No, Yes


   /**
     * @see Dialog#createButtonBar(Composite)
     */
    protected void createButtonsForButtonBar(Composite parent) {
        final String[] buttonLabels = getButtonLabels();
        final Button[] buttons = new Button[buttonLabels.length];
        final int defaultButtonIndex = getDefaultButtonIndex();

        for (int i = 0; i < buttonLabels.length; i++) {
            int id = i;
            String label = buttonLabels[i];
            if (IDialogConstants.OK_LABEL.equals(label)) {
                id = IDialogConstants.OK_ID;
            } else if (IDialogConstants.YES_LABEL.equals(label)) {
                id = IDialogConstants.YES_ID;
            } else if (IDialogConstants.NO_LABEL.equals(label)) {
                id = IDialogConstants.NO_ID;
            } else if (IDialogConstants.CANCEL_LABEL.equals(label)) {
                id = IDialogConstants.CANCEL_ID;
            } else if (IDialogConstants.YES_TO_ALL_LABEL.equals(label)) {
                id = IDialogConstants.YES_TO_ALL_ID;
            } else if (IDialogConstants.SKIP_LABEL.equals(label)) {
                id = IDialogConstants.SKIP_ID;
            } else if (IDialogConstants.STOP_LABEL.equals(label)) {
                id = IDialogConstants.STOP_ID;
            } else if (IDialogConstants.ABORT_LABEL.equals(label)) {
                id = IDialogConstants.ABORT_ID;
            } else if (IDialogConstants.RETRY_LABEL.equals(label)) {
                id = IDialogConstants.RETRY_ID;
            } else if (IDialogConstants.IGNORE_LABEL.equals(label)) {
                id = IDialogConstants.IGNORE_ID;
            } else if (IDialogConstants.PROCEED_LABEL.equals(label)) {
                id = IDialogConstants.PROCEED_ID;
            } else if (IDialogConstants.OPEN_LABEL.equals(label)) {
                id = IDialogConstants.OPEN_ID;
            } else if (IDialogConstants.CLOSE_LABEL.equals(label)) {
                id = IDialogConstants.CLOSE_ID;
            } else if (IDialogConstants.BACK_LABEL.equals(label)) {
                id = IDialogConstants.BACK_ID;
            } else if (IDialogConstants.NEXT_LABEL.equals(label)) {
                id = IDialogConstants.NEXT_ID;
            } else if (IDialogConstants.FINISH_LABEL.equals(label)) {
                id = IDialogConstants.FINISH_ID;
            } else if (IDialogConstants.HELP_LABEL.equals(label)) {
                id = IDialogConstants.HELP_ID;
            } else if (IDialogConstants.NO_TO_ALL_LABEL.equals(label)) {
                id = IDialogConstants.NO_TO_ALL_ID;
            }

            //          No XXX_LABEL in IDialogConstants for these. Unlikely
            //            they would be used in a message dialog though.
            //        	public int DETAILS_ID = 13;
            //        	public int SELECT_ALL_ID = 18;
            //        	public int DESELECT_ALL_ID = 19;
            //        	public int SELECT_TYPES_ID = 20;

            Button button = createButton(parent, id, label,
                    defaultButtonIndex == i);
            buttons[i] = button;
        }

        setButtons(buttons);
    }
Comment 1 Michael Van Meekeren CLA 2005-04-08 14:29:28 EDT
Note, this is because the id for Yes is = 2.
Comment 2 Douglas Pollock CLA 2005-04-08 16:39:16 EDT
Nice catch.
Comment 3 Susan McCourt CLA 2007-06-29 14:08:40 EDT

*** This bug has been marked as a duplicate of bug 66526 ***