1 11 package org.eclipse.jdt.internal.debug.ui.launcher; 12 13 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.jface.dialogs.IDialogConstants; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.events.ModifyEvent; 18 import org.eclipse.swt.events.ModifyListener; 19 import org.eclipse.swt.graphics.Font; 20 import org.eclipse.swt.layout.GridData; 21 import org.eclipse.swt.layout.GridLayout; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Control; 24 import org.eclipse.swt.widgets.Label; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.swt.widgets.Text; 27 28 public class NameValuePairDialog extends Dialog { 29 30 private String fName; 31 private String fValue; 32 33 private String fTitle; 34 private String [] fFieldLabels; 35 private String [] fInitialValues; 36 37 private Label fNameLabel; 38 private Text fNameText; 39 private Label fValueLabel; 40 private Text fValueText; 41 42 public NameValuePairDialog(Shell shell, String title, String [] fieldLabels, String [] initialValues) { 43 super(shell); 44 fTitle = title; 45 fFieldLabels = fieldLabels; 46 fInitialValues = initialValues; 47 } 48 49 52 protected Control createDialogArea(Composite parent) { 53 Font font = parent.getFont(); 54 55 Composite comp = new Composite(parent, SWT.NULL); 56 GridLayout topLayout = new GridLayout(); 57 topLayout.numColumns = 2; 58 topLayout.marginHeight = 59 convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 60 topLayout.marginWidth = 61 convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 62 topLayout.verticalSpacing = 63 convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 64 topLayout.horizontalSpacing = 65 convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 66 comp.setLayout(topLayout); 67 comp.setFont(font); 68 GridData gd; 69 70 fNameLabel = new Label(comp, SWT.NONE); 71 fNameLabel.setText(fFieldLabels[0]); 72 fNameLabel.setFont(font); 73 74 ModifyListener listener= new ModifyListener() { 75 public void modifyText(ModifyEvent e) { 76 updateButtons(); 77 } 78 }; 79 80 fNameText = new Text(comp, SWT.BORDER | SWT.SINGLE); 81 fNameText.setText(fInitialValues[0]); 82 gd = new GridData(GridData.FILL_HORIZONTAL); 83 gd.widthHint = 300; 84 fNameText.setLayoutData(gd); 85 fNameText.setFont(font); 86 fNameText.addModifyListener(listener); 87 88 fValueLabel = new Label(comp, SWT.NONE); 89 fValueLabel.setText(fFieldLabels[1]); 90 fValueLabel.setFont(font); 91 92 fValueText = new Text(comp, SWT.BORDER | SWT.SINGLE); 93 fValueText.setText(fInitialValues[1]); 94 gd = new GridData(GridData.FILL_HORIZONTAL); 95 gd.widthHint = 300; 96 fValueText.setLayoutData(gd); 97 fValueText.setFont(font); 98 fValueText.addModifyListener(listener); 99 100 applyDialogFont(comp); 101 return comp; 102 } 103 104 108 public String [] getNameValuePair() { 109 return new String [] {fName, fValue}; 110 } 111 112 115 protected void buttonPressed(int buttonId) { 116 if (buttonId == IDialogConstants.OK_ID) { 117 fName= fNameText.getText(); 118 fValue = fValueText.getText(); 119 } else { 120 fName = null; 121 fValue = null; 122 } 123 super.buttonPressed(buttonId); 124 } 125 126 129 protected void configureShell(Shell shell) { 130 super.configureShell(shell); 131 if (fTitle != null) { 132 shell.setText(fTitle); 133 } 134 } 135 136 139 protected void updateButtons() { 140 String name = fNameText.getText().trim(); 141 String value = fValueText.getText().trim(); 142 getButton(IDialogConstants.OK_ID).setEnabled((name.length() > 0) &&(value.length() > 0)); 143 } 144 145 148 public void create() { 149 super.create(); 150 updateButtons(); 151 } 152 } 153 | Popular Tags |