1 11 package org.eclipse.jdt.internal.ui.wizards.dialogfields; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.events.SelectionEvent; 15 import org.eclipse.swt.events.SelectionListener; 16 import org.eclipse.swt.layout.GridData; 17 import org.eclipse.swt.widgets.Button; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Label; 21 import org.eclipse.swt.widgets.Text; 22 23 import org.eclipse.jdt.internal.ui.util.SWTUtil; 24 25 28 public class StringButtonDialogField extends StringDialogField { 29 30 private Button fBrowseButton; 31 private String fBrowseButtonLabel; 32 private IStringButtonAdapter fStringButtonAdapter; 33 34 private boolean fButtonEnabled; 35 36 public StringButtonDialogField(IStringButtonAdapter adapter) { 37 super(); 38 fStringButtonAdapter= adapter; 39 fBrowseButtonLabel= "!Browse...!"; fButtonEnabled= true; 41 } 42 43 46 public void setButtonLabel(String label) { 47 fBrowseButtonLabel= label; 48 } 49 50 52 55 public void changeControlPressed() { 56 fStringButtonAdapter.changeControlPressed(this); 57 } 58 59 61 64 public Control[] doFillIntoGrid(Composite parent, int nColumns) { 65 assertEnoughColumns(nColumns); 66 67 Label label= getLabelControl(parent); 68 label.setLayoutData(gridDataForLabel(1)); 69 Text text= getTextControl(parent); 70 text.setLayoutData(gridDataForText(nColumns - 2)); 71 Button button= getChangeControl(parent); 72 button.setLayoutData(gridDataForButton(button, 1)); 73 74 return new Control[] { label, text, button }; 75 } 76 77 80 public int getNumberOfControls() { 81 return 3; 82 } 83 84 protected static GridData gridDataForButton(Button button, int span) { 85 GridData gd= new GridData(); 86 gd.horizontalAlignment= GridData.FILL; 87 gd.grabExcessHorizontalSpace= false; 88 gd.horizontalSpan= span; 89 gd.widthHint = SWTUtil.getButtonWidthHint(button); 90 return gd; 91 } 92 93 95 100 public Button getChangeControl(Composite parent) { 101 if (fBrowseButton == null) { 102 assertCompositeNotNull(parent); 103 104 fBrowseButton= new Button(parent, SWT.PUSH); 105 fBrowseButton.setFont(parent.getFont()); 106 fBrowseButton.setText(fBrowseButtonLabel); 107 fBrowseButton.setEnabled(isEnabled() && fButtonEnabled); 108 fBrowseButton.addSelectionListener(new SelectionListener() { 109 public void widgetDefaultSelected(SelectionEvent e) { 110 changeControlPressed(); 111 } 112 public void widgetSelected(SelectionEvent e) { 113 changeControlPressed(); 114 } 115 }); 116 117 } 118 return fBrowseButton; 119 } 120 121 123 126 public void enableButton(boolean enable) { 127 if (isOkToUse(fBrowseButton)) { 128 fBrowseButton.setEnabled(isEnabled() && enable); 129 } 130 fButtonEnabled= enable; 131 } 132 133 136 protected void updateEnableState() { 137 super.updateEnableState(); 138 if (isOkToUse(fBrowseButton)) { 139 fBrowseButton.setEnabled(isEnabled() && fButtonEnabled); 140 } 141 } 142 } 143 | Popular Tags |