001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.ui.wizards;
011:
012: import org.eclipse.core.runtime.IStatus;
013:
014: import org.eclipse.swt.SWT;
015: import org.eclipse.swt.layout.GridLayout;
016: import org.eclipse.swt.widgets.Composite;
017:
018: import org.eclipse.jface.dialogs.Dialog;
019: import org.eclipse.jface.viewers.IStructuredSelection;
020:
021: import org.eclipse.ui.PlatformUI;
022:
023: import org.eclipse.jdt.core.IJavaElement;
024:
025: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
026: import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
027:
028: /**
029: * Wizard page to create a new enum type.
030: * <p>
031: * Note: This class is not intended to be subclassed, but clients can instantiate.
032: * To implement a different kind of a new enum wizard page, extend <code>NewTypeWizardPage</code>.
033: * </p>
034: *
035: * @since 3.1
036: */
037: public class NewEnumWizardPage extends NewTypeWizardPage {
038:
039: private final static String PAGE_NAME = "NewEnumWizardPage"; //$NON-NLS-1$
040: private final static int TYPE = NewTypeWizardPage.ENUM_TYPE;
041:
042: /**
043: * Create a new <code>NewEnumWizardPage</code>
044: */
045: public NewEnumWizardPage() {
046: super (TYPE, PAGE_NAME);
047:
048: setTitle(NewWizardMessages.NewEnumWizardPage_title);
049: setDescription(NewWizardMessages.NewEnumWizardPage_description);
050: }
051:
052: // -------- Initialization ---------
053:
054: /**
055: * The wizard owning this page is responsible for calling this method with the
056: * current selection. The selection is used to initialize the fields of the wizard
057: * page.
058: *
059: * @param selection used to initialize the fields
060: */
061: public void init(IStructuredSelection selection) {
062: IJavaElement jelem = getInitialJavaElement(selection);
063:
064: initContainerPage(jelem);
065: initTypePage(jelem);
066:
067: doStatusUpdate();
068: }
069:
070: // ------ validation --------
071:
072: private void doStatusUpdate() {
073: // all used component status
074: IStatus[] status = new IStatus[] {
075: fContainerStatus,
076: isEnclosingTypeSelected() ? fEnclosingTypeStatus
077: : fPackageStatus, fTypeNameStatus,
078: fModifierStatus, fSuperInterfacesStatus };
079:
080: // the mode severe status will be displayed and the OK button enabled/disabled.
081: updateStatus(status);
082: }
083:
084: /*
085: * @see NewContainerWizardPage#handleFieldChanged
086: */
087: protected void handleFieldChanged(String fieldName) {
088: super .handleFieldChanged(fieldName);
089:
090: doStatusUpdate();
091: }
092:
093: // ------ UI --------
094:
095: /*
096: * @see WizardPage#createControl
097: */
098: public void createControl(Composite parent) {
099: initializeDialogUnits(parent);
100:
101: Composite composite = new Composite(parent, SWT.NONE);
102: composite.setFont(parent.getFont());
103:
104: int nColumns = 4;
105:
106: GridLayout layout = new GridLayout();
107: layout.numColumns = nColumns;
108: composite.setLayout(layout);
109:
110: createContainerControls(composite, nColumns);
111: createPackageControls(composite, nColumns);
112: createEnclosingTypeControls(composite, nColumns);
113:
114: createSeparator(composite, nColumns);
115:
116: createTypeNameControls(composite, nColumns);
117: createModifierControls(composite, nColumns);
118:
119: createSuperInterfacesControls(composite, nColumns);
120:
121: createCommentControls(composite, nColumns);
122: enableCommentControl(true);
123:
124: setControl(composite);
125:
126: Dialog.applyDialogFont(composite);
127: PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
128: IJavaHelpContextIds.NEW_ENUM_WIZARD_PAGE);
129: }
130:
131: /*
132: * @see WizardPage#becomesVisible
133: */
134: public void setVisible(boolean visible) {
135: super.setVisible(visible);
136: if (visible) {
137: setFocus();
138: }
139: }
140:
141: }
|