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 kind of
32 * 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$
42 private final static String SETTINGS_CREATECONSTR = "create_constructor"; //$NON-NLS-1$
43 private final static String SETTINGS_CREATEUNIMPLEMENTED = "create_unimplemented"; //$NON-NLS-1$
45 private SelectionButtonDialogFieldGroup fMethodStubsButtons;
48 * Creates a new <code>NewClassWizardPage</code>
50 public NewClassWizardPage() {
51 super(true, PAGE_NAME);
53 setTitle(NewWizardMessages.getString("NewClassWizardPage.title")); //$NON-NLS-1$
54 setDescription(NewWizardMessages.getString("NewClassWizardPage.description")); //$NON-NLS-1$
56 String[] buttonNames3 = new String[] { NewWizardMessages.getString("NewClassWizardPage.methods.main"), NewWizardMessages.getString("NewClassWizardPage.methods.constructors"), //$NON-NLS-1$ //$NON-NLS-2$
57 NewWizardMessages.getString("NewClassWizardPage.methods.inherited") //$NON-NLS-1$
59 fMethodStubsButtons = new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames3, 1);
60 fMethodStubsButtons.setLabelText(NewWizardMessages.getString("NewClassWizardPage.methods.label")); //$NON-NLS-1$
63 // -------- Initialization ---------
66 * The wizard owning this page is responsible for calling this method with the
67 * current selection. The selection is used to initialize the fields of the wizard
70 * @param selection used to initialize the fields
72 public void init(IStructuredSelection selection) {
73 IJavaElement jelem = getInitialJavaElement(selection);
74 initContainerPage(jelem);
78 boolean createMain = false;
79 boolean createConstructors = false;
80 boolean createUnimplemented = true;
81 IDialogSettings section = getDialogSettings().getSection(PAGE_NAME);
82 if (section != null) {
83 createMain = section.getBoolean(SETTINGS_CREATEMAIN);
84 createConstructors = section.getBoolean(SETTINGS_CREATECONSTR);
85 createUnimplemented = section.getBoolean(SETTINGS_CREATEUNIMPLEMENTED);
88 setMethodStubSelection(createMain, createConstructors, createUnimplemented, true);
91 // ------ validation --------
92 private void doStatusUpdate() {
93 // status of all used components
97 isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus,
100 // fSuperClassStatus,
101 // fSuperInterfacesStatus
104 // the mode severe status will be displayed and the ok button enabled/disabled.
105 updateStatus(status);
109 * @see NewContainerWizardPage#handleFieldChanged
111 protected void handleFieldChanged(String fieldName) {
112 super.handleFieldChanged(fieldName);
117 // ------ ui --------
120 * @see WizardPage#createControl
122 public void createControl(Composite parent) {
123 initializeDialogUnits(parent);
125 Composite composite = new Composite(parent, SWT.NONE);
129 GridLayout layout = new GridLayout();
130 layout.numColumns = nColumns;
131 composite.setLayout(layout);
133 // pick & choose the wanted UI components
135 createContainerControls(composite, nColumns);
136 createPackageControls(composite, nColumns);
137 createEnclosingTypeControls(composite, nColumns);
139 createSeparator(composite, nColumns);
141 createTypeNameControls(composite, nColumns);
142 createModifierControls(composite, nColumns);
144 createSuperClassControls(composite, nColumns);
145 createSuperInterfacesControls(composite, nColumns);
147 createMethodStubSelectionControls(composite, nColumns);
149 setControl(composite);
151 Dialog.applyDialogFont(composite);
152 // WorkbenchHelp.setHelp(composite, IJavaHelpContextIds.NEW_CLASS_WIZARD_PAGE);
156 * @see WizardPage#becomesVisible
158 public void setVisible(boolean visible) {
159 super.setVisible(visible);
165 private void createMethodStubSelectionControls(Composite composite, int nColumns) {
166 Control labelControl = fMethodStubsButtons.getLabelControl(composite);
167 LayoutUtil.setHorizontalSpan(labelControl, nColumns);
169 DialogField.createEmptySpace(composite);
171 Control buttonGroup = fMethodStubsButtons.getSelectionButtonsGroup(composite);
172 LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
176 * Returns the current selection state of the 'Create Main' checkbox.
178 * @return the selection state of the 'Create Main' checkbox
180 public boolean isCreateMain() {
181 return fMethodStubsButtons.isSelected(0);
185 * Returns the current selection state of the 'Create Constructors' checkbox.
187 * @return the selection state of the 'Create Constructors' checkbox
189 public boolean isCreateConstructors() {
190 return fMethodStubsButtons.isSelected(1);
194 * Returns the current selection state of the 'Create inherited abstract methods'
197 * @return the selection state of the 'Create inherited abstract methods' checkbox
199 public boolean isCreateInherited() {
200 return fMethodStubsButtons.isSelected(2);
204 * Sets the selection state of the method stub checkboxes.
206 * @param createMain initial selection state of the 'Create Main' checkbox.
207 * @param createConstructors initial selection state of the 'Create Constructors' checkbox.
208 * @param createInherited initial selection state of the 'Create inherited abstract methods' checkbox.
209 * @param canBeModified if <code>true</code> the method stub checkboxes can be changed by
210 * the user. If <code>false</code> the buttons are "read-only"
212 public void setMethodStubSelection(
214 boolean createConstructors,
215 boolean createInherited,
216 boolean canBeModified) {
217 fMethodStubsButtons.setSelection(0, createMain);
218 fMethodStubsButtons.setSelection(1, createConstructors);
219 fMethodStubsButtons.setSelection(2, createInherited);
221 fMethodStubsButtons.setEnabled(canBeModified);
224 // ---- creation ----------------
227 * @see NewTypeWizardPage#createTypeMembers
229 // protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
230 // boolean doMain= isCreateMain();
231 // boolean doConstr= isCreateConstructors();
232 // boolean doInherited= isCreateInherited();
233 // createInheritedMethods(type, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1));
236 // StringBuffer buf= new StringBuffer();
237 // buf.append("public static void main("); //$NON-NLS-1$
238 // buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$
239 // buf.append("[] args) {}"); //$NON-NLS-1$
240 // type.createMethod(buf.toString(), null, false, null);
243 // IDialogSettings section= getDialogSettings().getSection(PAGE_NAME);
244 // if (section == null) {
245 // section= getDialogSettings().addNewSection(PAGE_NAME);
247 // section.put(SETTINGS_CREATEMAIN, doMain);
248 // section.put(SETTINGS_CREATECONSTR, doConstr);
249 // section.put(SETTINGS_CREATEUNIMPLEMENTED, doInherited);
251 // if (monitor != null) {