KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > cheatsheet > NewCategoryNameDialog


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.pde.internal.ui.wizards.cheatsheet;
13
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.jface.dialogs.TrayDialog;
16 import org.eclipse.pde.internal.ui.PDEUIMessages;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
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.Shell;
24 import org.eclipse.swt.widgets.Text;
25
26 /**
27  * NewCategoryNameDialog
28  *
29  */

30 public class NewCategoryNameDialog extends TrayDialog {
31
32     private Text fNameText;
33     
34     private String JavaDoc fNameTextValue;
35     
36     /**
37      * @param shell
38      */

39     public NewCategoryNameDialog(Shell shell) {
40         super(shell);
41         
42         fNameText = null;
43         fNameTextValue = null;
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
48      */

49     protected Control createDialogArea(Composite parent) {
50         
51         Composite composite = createUI(parent);
52         createListeners();
53         updateUI();
54
55         return composite;
56     }
57
58     /**
59      * @param parent
60      */

61     private Composite createUI(Composite parent) {
62         // Create the container
63
Composite container = createUIContainer(parent);
64         // Create the instructional label
65
createUIInstructionLabel(container);
66         // Create the name field
67
createUINameField(container);
68         // Apply the default font to the dialog
69
applyDialogFont(container);
70         
71         return container;
72     }
73     
74     /**
75      *
76      */

77     private void createListeners() {
78         // NO-OP
79
}
80     
81     /**
82      *
83      */

84     private void updateUI() {
85         // NO-OP
86
}
87     
88     /**
89      * @param parent
90      * @return
91      */

92     private Composite createUIContainer(Composite parent) {
93         Composite composite = new Composite(parent, SWT.NONE);
94         GridLayout layout = new GridLayout(2, false);
95         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
96         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
97         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
98         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
99         composite.setLayout(layout);
100         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
101
102         return composite;
103     }
104
105     /**
106      * @param container
107      */

108     private void createUIInstructionLabel(Composite container) {
109         Label label = new Label(container, SWT.WRAP);
110         label.setText(PDEUIMessages.NewCategoryNameDialog_instructionLabel);
111         GridData data = new GridData(GridData.FILL_HORIZONTAL);
112         data.horizontalSpan = 2;
113         data.widthHint = 200;
114         label.setLayoutData(data);
115     }
116     
117     /**
118      * @param parent
119      */

120     private void createUINameField(Composite parent) {
121         // Create the label
122
createUINameLabel(parent);
123         // Create the text widget
124
createUINameText(parent);
125     }
126
127     /**
128      * @param parent
129      */

130     private void createUINameLabel(Composite parent) {
131         Label label = new Label(parent, SWT.NONE);
132         label.setText(PDEUIMessages.NewCategoryNameDialog_name);
133     }
134
135     /**
136      * @param parent
137      */

138     private void createUINameText(Composite parent) {
139         int style = SWT.BORDER;
140         fNameText = new Text(parent, style);
141         fNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
142     }
143     
144     /* (non-Javadoc)
145      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
146      */

147     protected void okPressed() {
148         // This is needed because the widget is disposed before after okay is
149
// pressed before the value can be retrieved
150
fNameTextValue = fNameText.getText();
151         super.okPressed();
152     }
153     
154     /**
155      * @return
156      */

157     public String JavaDoc getNameText() {
158         return fNameTextValue;
159     }
160     
161 }
162
Popular Tags