1 /*******************************************************************************
 
   2  * Copyright (c) 2000, 2003 IBM Corporation and others.
 
   3  * All rights reserved. This program and the accompanying materials 
 
   4  * are made available under the terms of the Common Public License v1.0
 
   5  * which accompanies this distribution, and is available at
 
   6  * http://www.eclipse.org/legal/cpl-v10.html
 
   9  *     IBM Corporation - initial API and implementation
 
  10  *******************************************************************************/
 
  11 package net.sourceforge.phpdt.internal.ui.wizards.dialogfields;
 
  13 import net.sourceforge.phpdt.internal.ui.util.SWTUtil;
 
  15 import org.eclipse.swt.SWT;
 
  16 import org.eclipse.swt.events.SelectionEvent;
 
  17 import org.eclipse.swt.events.SelectionListener;
 
  18 import org.eclipse.swt.layout.GridData;
 
  19 import org.eclipse.swt.widgets.Button;
 
  20 import org.eclipse.swt.widgets.Composite;
 
  21 import org.eclipse.swt.widgets.Control;
 
  22 import org.eclipse.swt.widgets.Label;
 
  23 import org.eclipse.swt.widgets.Text;
 
  26  * Dialog field containing a label, text control and a button control.
 
  28 public class StringButtonDialogField extends StringDialogField {
 
  30         private Button fBrowseButton;
 
  32         private String fBrowseButtonLabel;
 
  34         //private IStringButtonAdapter fStringButtonAdapter;
 
  36         private boolean fButtonEnabled;
 
  38         public StringButtonDialogField(IStringButtonAdapter adapter) {
 
  40                 //fStringButtonAdapter = adapter;
 
  41                 fBrowseButtonLabel = "!Browse...!"; //$NON-NLS-1$
 
  42                 fButtonEnabled = true;
 
  46          * Sets the label of the button.
 
  48         public void setButtonLabel(String label) {
 
  49                 fBrowseButtonLabel = label;
 
  52         // ------ adapter communication
 
  55          * Programmatical pressing of the button
 
  57         public void changeControlPressed() {
 
  58                 //fStringButtonAdapter.changeControlPressed(this);
 
  61         // ------- layout helpers
 
  64          * @see DialogField#doFillIntoGrid
 
  66         public Control[] doFillIntoGrid(Composite parent, int nColumns) {
 
  67                 assertEnoughColumns(nColumns);
 
  69                 Label label = getLabelControl(parent);
 
  70                 label.setLayoutData(gridDataForLabel(1));
 
  71                 Text text = getTextControl(parent);
 
  72                 text.setLayoutData(gridDataForText(nColumns - 2));
 
  73                 Button button = getChangeControl(parent);
 
  74                 button.setLayoutData(gridDataForButton(button, 1));
 
  76                 return new Control[] { label, text, button };
 
  80          * @see DialogField#getNumberOfControls
 
  82         public int getNumberOfControls() {
 
  86         protected static GridData gridDataForButton(Button button, int span) {
 
  87                 GridData gd = new GridData();
 
  88                 gd.horizontalAlignment = GridData.FILL;
 
  89                 gd.grabExcessHorizontalSpace = false;
 
  90                 gd.horizontalSpan = span;
 
  91                 gd.heightHint = SWTUtil.getButtonHeightHint(button);
 
  92                 gd.widthHint = SWTUtil.getButtonWidthHint(button);
 
  96         // ------- ui creation
 
  99          * Creates or returns the created buttom widget.
 
 102          *            The parent composite or <code>null</code> if the widget has
 
 103          *            already been created.
 
 105         public Button getChangeControl(Composite parent) {
 
 106                 if (fBrowseButton == null) {
 
 107                         assertCompositeNotNull(parent);
 
 109                         fBrowseButton = new Button(parent, SWT.PUSH);
 
 110                         fBrowseButton.setText(fBrowseButtonLabel);
 
 111                         fBrowseButton.setEnabled(isEnabled() && fButtonEnabled);
 
 112                         fBrowseButton.addSelectionListener(new SelectionListener() {
 
 113                                 public void widgetDefaultSelected(SelectionEvent e) {
 
 114                                         changeControlPressed();
 
 117                                 public void widgetSelected(SelectionEvent e) {
 
 118                                         changeControlPressed();
 
 123                 return fBrowseButton;
 
 126         // ------ enable / disable management
 
 129          * Sets the enable state of the button.
 
 131         public void enableButton(boolean enable) {
 
 132                 if (isOkToUse(fBrowseButton)) {
 
 133                         fBrowseButton.setEnabled(isEnabled() && enable);
 
 135                 fButtonEnabled = enable;
 
 139          * @see DialogField#updateEnableState
 
 141         protected void updateEnableState() {
 
 142                 super.updateEnableState();
 
 143                 if (isOkToUse(fBrowseButton)) {
 
 144                         fBrowseButton.setEnabled(isEnabled() && fButtonEnabled);