1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.ui.wizards;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.internal.ui.wizards.NewWizardMessages;
15 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.DialogField;
16 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.LayoutUtil;
17 import net.sourceforge.phpdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.jface.dialogs.IDialogSettings;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
29 * Wizard page to create a new class.
31 * Note: This class is not intended to be subclassed. To implement a different
32 * kind of a new class wizard page, extend <code>NewTypeWizardPage</code>.
37 public class NewClassWizardPage extends NewTypeWizardPage {
39 private final static String PAGE_NAME = "NewClassWizardPage"; //$NON-NLS-1$
41 private final static String SETTINGS_CREATEMAIN = "create_main"; //$NON-NLS-1$
43 private final static String SETTINGS_CREATECONSTR = "create_constructor"; //$NON-NLS-1$
45 private final static String SETTINGS_CREATEUNIMPLEMENTED = "create_unimplemented"; //$NON-NLS-1$
47 private SelectionButtonDialogFieldGroup fMethodStubsButtons;
50 * Creates a new <code>NewClassWizardPage</code>
52 public NewClassWizardPage() {
53 super(true, PAGE_NAME);
55 setTitle(NewWizardMessages.getString("NewClassWizardPage.title")); //$NON-NLS-1$
56 setDescription(NewWizardMessages
57 .getString("NewClassWizardPage.description")); //$NON-NLS-1$
59 String[] buttonNames3 = new String[] {
60 NewWizardMessages.getString("NewClassWizardPage.methods.main"), NewWizardMessages.getString("NewClassWizardPage.methods.constructors"), //$NON-NLS-1$ //$NON-NLS-2$
62 .getString("NewClassWizardPage.methods.inherited") //$NON-NLS-1$
64 fMethodStubsButtons = new SelectionButtonDialogFieldGroup(SWT.CHECK,
66 fMethodStubsButtons.setLabelText(NewWizardMessages
67 .getString("NewClassWizardPage.methods.label")); //$NON-NLS-1$
70 // -------- Initialization ---------
73 * The wizard owning this page is responsible for calling this method with
74 * the current selection. The selection is used to initialize the fields of
78 * used to initialize the fields
80 public void init(IStructuredSelection selection) {
81 IJavaElement jelem = getInitialJavaElement(selection);
82 //initContainerPage(jelem);
86 boolean createMain = false;
87 boolean createConstructors = false;
88 boolean createUnimplemented = true;
89 IDialogSettings section = getDialogSettings().getSection(PAGE_NAME);
90 if (section != null) {
91 createMain = section.getBoolean(SETTINGS_CREATEMAIN);
92 createConstructors = section.getBoolean(SETTINGS_CREATECONSTR);
93 createUnimplemented = section
94 .getBoolean(SETTINGS_CREATEUNIMPLEMENTED);
97 setMethodStubSelection(createMain, createConstructors,
98 createUnimplemented, true);
101 // ------ validation --------
102 private void doStatusUpdate() {
103 // status of all used components
104 IStatus[] status = new IStatus[] {
106 isEnclosingTypeSelected() ? fEnclosingTypeStatus
107 : fPackageStatus, fTypeNameStatus, fModifierStatus,
108 // fSuperClassStatus,
109 // fSuperInterfacesStatus
112 // the mode severe status will be displayed and the ok button
114 updateStatus(status);
118 * @see NewContainerWizardPage#handleFieldChanged
120 protected void handleFieldChanged(String fieldName) {
121 super.handleFieldChanged(fieldName);
126 // ------ ui --------
129 * @see WizardPage#createControl
131 public void createControl(Composite parent) {
132 initializeDialogUnits(parent);
134 Composite composite = new Composite(parent, SWT.NONE);
138 GridLayout layout = new GridLayout();
139 layout.numColumns = nColumns;
140 composite.setLayout(layout);
142 // pick & choose the wanted UI components
144 createContainerControls(composite, nColumns);
145 createPackageControls(composite, nColumns);
146 createEnclosingTypeControls(composite, nColumns);
148 createSeparator(composite, nColumns);
150 createTypeNameControls(composite, nColumns);
151 createModifierControls(composite, nColumns);
153 createSuperClassControls(composite, nColumns);
154 createSuperInterfacesControls(composite, nColumns);
156 createMethodStubSelectionControls(composite, nColumns);
158 setControl(composite);
160 Dialog.applyDialogFont(composite);
161 // WorkbenchHelp.setHelp(composite,
162 // IJavaHelpContextIds.NEW_CLASS_WIZARD_PAGE);
166 * @see WizardPage#becomesVisible
168 public void setVisible(boolean visible) {
169 super.setVisible(visible);
175 private void createMethodStubSelectionControls(Composite composite,
177 Control labelControl = fMethodStubsButtons.getLabelControl(composite);
178 LayoutUtil.setHorizontalSpan(labelControl, nColumns);
180 DialogField.createEmptySpace(composite);
182 Control buttonGroup = fMethodStubsButtons
183 .getSelectionButtonsGroup(composite);
184 LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
188 * Returns the current selection state of the 'Create Main' checkbox.
190 * @return the selection state of the 'Create Main' checkbox
192 // public boolean isCreateMain() {
193 // return fMethodStubsButtons.isSelected(0);
197 * Returns the current selection state of the 'Create Constructors'
200 * @return the selection state of the 'Create Constructors' checkbox
202 // public boolean isCreateConstructors() {
203 // return fMethodStubsButtons.isSelected(1);
207 * Returns the current selection state of the 'Create inherited abstract
210 * @return the selection state of the 'Create inherited abstract methods'
213 // public boolean isCreateInherited() {
214 // return fMethodStubsButtons.isSelected(2);
218 * Sets the selection state of the method stub checkboxes.
221 * initial selection state of the 'Create Main' checkbox.
222 * @param createConstructors
223 * initial selection state of the 'Create Constructors' checkbox.
224 * @param createInherited
225 * initial selection state of the 'Create inherited abstract
227 * @param canBeModified
228 * if <code>true</code> the method stub checkboxes can be
229 * changed by the user. If <code>false</code> the buttons are
232 public void setMethodStubSelection(boolean createMain,
233 boolean createConstructors, boolean createInherited,
234 boolean canBeModified) {
235 fMethodStubsButtons.setSelection(0, createMain);
236 fMethodStubsButtons.setSelection(1, createConstructors);
237 fMethodStubsButtons.setSelection(2, createInherited);
239 fMethodStubsButtons.setEnabled(canBeModified);
242 // ---- creation ----------------
245 * @see NewTypeWizardPage#createTypeMembers
247 // protected void createTypeMembers(IType type, ImportsManager imports,
248 // IProgressMonitor monitor) throws CoreException {
249 // boolean doMain= isCreateMain();
250 // boolean doConstr= isCreateConstructors();
251 // boolean doInherited= isCreateInherited();
252 // createInheritedMethods(type, doConstr, doInherited, imports, new
253 // SubProgressMonitor(monitor, 1));
256 // StringBuffer buf= new StringBuffer();
257 // buf.append("public static void main("); //$NON-NLS-1$
258 // buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$
259 // buf.append("[] args) {}"); //$NON-NLS-1$
260 // type.createMethod(buf.toString(), null, false, null);
263 // IDialogSettings section= getDialogSettings().getSection(PAGE_NAME);
264 // if (section == null) {
265 // section= getDialogSettings().addNewSection(PAGE_NAME);
267 // section.put(SETTINGS_CREATEMAIN, doMain);
268 // section.put(SETTINGS_CREATECONSTR, doConstr);
269 // section.put(SETTINGS_CREATEUNIMPLEMENTED, doInherited);
271 // if (monitor != null) {