Enable word wrapping with preference key editor.wrap.words (false by default)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / actions / category / CategoryDialog.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.wiki.actions.category;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.jface.window.Window;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.swt.widgets.Text;
24
25 /**
26  * A dialog for prompting for a category and fPassword
27  */
28 public class CategoryDialog extends Dialog {
29   // widgets
30   protected Text categoryField;
31
32   protected String category = null;
33
34   /**
35    * Creates a new CategoryDialog.
36    * 
37    * @param parentShell
38    *          the parent shell
39    * @param location
40    *          the location
41    * @param defaultName
42    *          the default fUser name
43    * @param message
44    *          a mesage to display to the fUser
45    */
46   public CategoryDialog(Shell parentShell) {
47     super(parentShell);
48   }
49
50   /**
51    * @see Window#configureShell
52    */
53   protected void configureShell(Shell newShell) {
54     super.configureShell(newShell);
55     newShell.setText(Messages.getString("CategoryDialog.required")); //$NON-NLS-1$
56     // set F1 help
57     //          WorkbenchHelp.setHelp(newShell, IHelpContextIds.USER_VALIDATION_DIALOG);
58   }
59
60   /**
61    * @see Window#create
62    */
63   public void create() {
64     super.create();
65     // add some default values
66     categoryField.setFocus();
67   }
68
69   /**
70    * @see Dialog#createDialogArea
71    */
72   protected Control createDialogArea(Composite parent) {
73     Composite top = new Composite(parent, SWT.NONE);
74     GridLayout layout = new GridLayout();
75     layout.numColumns = 2;
76
77     top.setLayout(layout);
78     top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
79
80     Composite imageComposite = new Composite(top, SWT.NONE);
81     layout = new GridLayout();
82     imageComposite.setLayout(layout);
83     imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
84
85     Composite main = new Composite(top, SWT.NONE);
86     layout = new GridLayout();
87     layout.numColumns = 3;
88     main.setLayout(layout);
89     main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
90
91     GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
92
93     createCategoryFields(main);
94
95     Dialog.applyDialogFont(parent);
96
97     return main;
98   }
99
100   /**
101    * Create a spacer.
102    */
103   //  protected void createSpacer(Composite top, int columnSpan, int vertSpan) {
104   //    Label l = new Label(top, SWT.NONE);
105   //    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
106   //    data.horizontalSpan = columnSpan;
107   //    data.verticalSpan = vertSpan;
108   //    l.setLayoutData(data);
109   //  }
110   /**
111    * Creates the three widgets that represent the fPassword entry area.
112    * 
113    * @param parent
114    *          the parent of the widgets
115    */
116   //  protected void createPasswordFields(Composite parent) {
117   //    new Label(parent, SWT.NONE).setText(Messages.getString("CategoryDialog.password")); //$NON-NLS-1$
118   //
119   //    passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD);
120   //    GridData data = new GridData(GridData.FILL_HORIZONTAL);
121   //    data.horizontalSpan = 2;
122   //    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
123   //    passwordField.setLayoutData(data);
124   //  }
125   /**
126    * Creates the three widgets that represent the fUser name entry area.
127    * 
128    * @param parent
129    *          the parent of the widgets
130    */
131   protected void createCategoryFields(Composite parent) {
132     new Label(parent, SWT.NONE).setText(Messages.getString("CategoryDialog.category")); //$NON-NLS-1$
133
134     categoryField = new Text(parent, SWT.BORDER);
135     GridData data = new GridData(GridData.FILL_HORIZONTAL);
136     data.horizontalSpan = 2;
137     data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
138     categoryField.setLayoutData(data);
139   }
140
141   /**
142    * Returns the category entered by the fUser, or null if the fUser canceled.
143    * 
144    * @return the entered category
145    */
146   public String getCategory() {
147     return category;
148   }
149
150   /**
151    * Notifies that the ok button of this dialog has been pressed.
152    * <p>
153    * The default implementation of this framework method sets this dialog's return code to <code>Window.OK</code> and closes the
154    * dialog. Subclasses may override.
155    * </p>
156    */
157   protected void okPressed() {
158     category = categoryField.getText();
159
160     super.okPressed();
161   }
162
163   /*
164    * (non-Javadoc)
165    * 
166    * @see org.eclipse.jface.dialogs.Dialog#close()
167    */
168   public boolean close() {
169     return super.close();
170   }
171 }