Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 121057 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/preference/PreferencePage.java (-49 / +75 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 73-84 Link Here
73
    private Control body;
73
    private Control body;
74
74
75
    /**
75
    /**
76
     * Whether this page has the standard Apply and Defaults buttons; 
76
	 * Whether this page has the standard Apply button; <code>true</code> by
77
     * <code>true</code> by default.
77
	 * default.
78
     *
78
	 *
79
     * @see #noDefaultAndApplyButton
79
	 * @see #noDefaultAndApplyButton
80
     */
80
	 */
81
    private boolean createDefaultAndApplyButton = true;
81
	private boolean createApplyButton = true;
82
83
	/**
84
	 * Whether this page has the standard Default button; <code>true</code> by
85
	 * default.
86
	 *
87
	 * @see #noDefaultButton
88
	 */
89
	private boolean createDefaultButton = true;
82
90
83
    /**
91
    /**
84
     * Standard Defaults button, or <code>null</code> if none.
92
     * Standard Defaults button, or <code>null</code> if none.
Lines 250-292 Link Here
250
258
251
        contributeButtons(buttonBar);
259
        contributeButtons(buttonBar);
252
        
260
        
253
        if (createDefaultAndApplyButton) {
261
		if (createApplyButton || createDefaultButton) {
254
            layout.numColumns = layout.numColumns + 2;
262
			layout.numColumns = 1 + (createApplyButton && createDefaultButton ? 1 : 0);
255
			String[] labels = JFaceResources.getStrings(new String[] {
256
					"defaults", "apply" }); //$NON-NLS-2$//$NON-NLS-1$
257
			int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
263
			int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
258
			defaultsButton = new Button(buttonBar, SWT.PUSH);
259
			defaultsButton.setText(labels[0]);
260
			Dialog.applyDialogFont(defaultsButton);
261
			GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
262
			Point minButtonSize = defaultsButton.computeSize(SWT.DEFAULT,
263
					SWT.DEFAULT, true);
264
			data.widthHint = Math.max(widthHint, minButtonSize.x);
265
			defaultsButton.setLayoutData(data);
266
			defaultsButton.addSelectionListener(new SelectionAdapter() {
267
				@Override
268
				public void widgetSelected(SelectionEvent e) {
269
					performDefaults();
270
				}
271
			});
272
264
273
            applyButton = new Button(buttonBar, SWT.PUSH);
265
			if (createDefaultButton) {
274
			applyButton.setText(labels[1]);
266
				String label = JFaceResources.getString("defaults"); //$NON-NLS-1$
275
			Dialog.applyDialogFont(applyButton);
267
				defaultsButton = new Button(buttonBar, SWT.PUSH);
276
			data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
268
				defaultsButton.setText(label);
277
			minButtonSize = applyButton.computeSize(SWT.DEFAULT, SWT.DEFAULT,
269
				Dialog.applyDialogFont(defaultsButton);
278
					true);
270
				Point minButtonSize = defaultsButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
279
			data.widthHint = Math.max(widthHint, minButtonSize.x);
271
				GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
280
			applyButton.setLayoutData(data);
272
				data.widthHint = Math.max(widthHint, minButtonSize.x);
281
			applyButton.addSelectionListener(new SelectionAdapter() {
273
				defaultsButton.setLayoutData(data);
282
				@Override
274
				defaultsButton.addSelectionListener(new SelectionAdapter() {
283
				public void widgetSelected(SelectionEvent e) {
275
					@Override
284
					performApply();
276
					public void widgetSelected(SelectionEvent e) {
285
				}
277
						performDefaults();
286
			});
278
					}
287
            applyButton.setEnabled(isValid());
279
				});
288
            applyDialogFont(buttonBar);
280
			}
289
        } else {
281
			if (createApplyButton) {
282
				String label = JFaceResources.getString("apply"); //$NON-NLS-1$
283
284
				applyButton = new Button(buttonBar, SWT.PUSH);
285
				applyButton.setText(label);
286
				Dialog.applyDialogFont(applyButton);
287
				Point minButtonSize = applyButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
288
				GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
289
				data.widthHint = Math.max(widthHint, minButtonSize.x);
290
				applyButton.setLayoutData(data);
291
				applyButton.addSelectionListener(new SelectionAdapter() {
292
					@Override
293
					public void widgetSelected(SelectionEvent e) {
294
						performApply();
295
					}
296
				});
297
				applyButton.setEnabled(isValid());
298
			}
299
			applyDialogFont(buttonBar);
300
		} else {
290
            /* Check if there are any other buttons on the button bar.
301
            /* Check if there are any other buttons on the button bar.
291
             * If not, throw away the button bar composite.  Otherwise
302
             * If not, throw away the button bar composite.  Otherwise
292
             * there is an unusually large button bar.
303
             * there is an unusually large button bar.
Lines 297-303 Link Here
297
        }
308
        }
298
    }
309
    }
299
310
300
	
311
301
312
302
	/**
313
	/**
303
     * Apply the dialog font to the composite and it's children
314
     * Apply the dialog font to the composite and it's children
Lines 408-422 Link Here
408
     * </p>
419
     * </p>
409
     */
420
     */
410
    protected void noDefaultAndApplyButton() {
421
    protected void noDefaultAndApplyButton() {
411
        createDefaultAndApplyButton = false;
422
		createApplyButton = false;
423
		createDefaultButton = false;
412
    }
424
    }
413
425
414
    /**
426
    /**
415
     * The <code>PreferencePage</code> implementation of this 
427
	 * Suppress creation of the standard Default button for this page.
416
     * <code>IPreferencePage</code> method returns <code>true</code>
428
	 * <p>
417
     * if the page is valid.
429
	 * Subclasses wishing a preference page with this button should call this
418
     * @see IPreferencePage#okToLeave()
430
	 * framework method before the page's control has been created.
419
     */
431
	 * </p>
432
	 * 
433
	 * @since 3.11
434
	 */
435
	protected void noDefaultButton() {
436
		createDefaultButton = false;
437
	}
438
439
	/**
440
	 * The <code>PreferencePage</code> implementation of this
441
	 * <code>IPreferencePage</code> method returns <code>true</code> if the page
442
	 * is valid.
443
	 * 
444
	 * @see IPreferencePage#okToLeave()
445
	 */
420
    @Override
446
    @Override
421
	public boolean okToLeave() {
447
	public boolean okToLeave() {
422
        return isValid();
448
        return isValid();

Return to bug 121057