KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > launchConfigurations > VariableInputDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.launchConfigurations;
12
13 import org.eclipse.ant.internal.ui.AntUIPlugin;
14 import org.eclipse.debug.ui.StringVariableSelectionDialog;
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.dialogs.IDialogSettings;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.swt.widgets.Text;
29
30
31 public class VariableInputDialog extends Dialog {
32     
33     private static String JavaDoc DIALOG_SETTINGS_SECTION = "RuntimeClasspathAction.VariableInputDialog"; //$NON-NLS-1$
34
private Text fText;
35     private String JavaDoc fVariableString;
36     
37     public VariableInputDialog(Shell shell) {
38         super(shell);
39         setShellStyle(SWT.RESIZE | getShellStyle());
40     }
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
44      */

45     protected Control createDialogArea(Composite parent) {
46         Composite inner= (Composite) super.createDialogArea(parent);
47         ((GridLayout)inner.getLayout()).numColumns= 2;
48         
49         Label label = new Label(inner, SWT.NONE);
50         label.setText(AntLaunchConfigurationMessages.AddVariableStringAction_2);
51         GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
52         gd.horizontalSpan= 2;
53         label.setLayoutData(gd);
54         
55         fText = new Text(inner, SWT.SINGLE | SWT.BORDER);
56         gd = new GridData(GridData.FILL_HORIZONTAL);
57         gd.grabExcessHorizontalSpace = true;
58         gd.widthHint = 200;
59         fText.setLayoutData(gd);
60         
61         Button button = new Button(inner, SWT.PUSH);
62         button.setText(AntLaunchConfigurationMessages.AddVariableStringAction_3);
63         button.addSelectionListener(new SelectionAdapter() {
64             public void widgetSelected(SelectionEvent se) {
65                 getVariable();
66             }
67         });
68         
69         applyDialogFont(parent);
70         return inner;
71     }
72     
73     protected void createButtonsForButtonBar(Composite parent) {
74         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
75         createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
76     }
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
80      */

81     protected void configureShell(Shell newShell) {
82         super.configureShell(newShell);
83         newShell.setText(AntLaunchConfigurationMessages.AddVariableStringAction_4);
84     }
85     
86     private void getVariable() {
87         StringVariableSelectionDialog variableDialog = new StringVariableSelectionDialog(getShell());
88         int returnCode = variableDialog.open();
89         if (returnCode == IDialogConstants.OK_ID) {
90             String JavaDoc variable = variableDialog.getVariableExpression();
91             if (variable != null) {
92                 fText.insert(variable);
93             }
94         }
95     }
96     
97     /* (non-Javadoc)
98      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
99      */

100     protected void okPressed() {
101         String JavaDoc variableString = fText.getText();
102         if (variableString != null && variableString.trim().length() > 0) {
103             fVariableString= variableString;
104         } else {
105             fVariableString= null;
106         }
107         super.okPressed();
108     }
109     
110     public String JavaDoc getVariableString() {
111         return fVariableString;
112     }
113
114      /* (non-Javadoc)
115      * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
116      */

117     protected IDialogSettings getDialogBoundsSettings() {
118          IDialogSettings settings = AntUIPlugin.getDefault().getDialogSettings();
119          IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION);
120          if (section == null) {
121              section = settings.addNewSection(DIALOG_SETTINGS_SECTION);
122          }
123          return section;
124     }
125 }
126
Popular Tags