001: /*******************************************************************************
002: * Copyright (c) 2000, 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 interface.
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 interface wizard page, extend <code>NewTypeWizardPage</code>.
033: * </p>
034: *
035: * @since 2.0
036: */
037: public class NewInterfaceWizardPage extends NewTypeWizardPage {
038:
039: private final static String PAGE_NAME = "NewInterfaceWizardPage"; //$NON-NLS-1$
040:
041: /**
042: * Create a new <code>NewInterfaceWizardPage</code>
043: */
044: public NewInterfaceWizardPage() {
045: super (false, PAGE_NAME);
046:
047: setTitle(NewWizardMessages.NewInterfaceWizardPage_title);
048: setDescription(NewWizardMessages.NewInterfaceWizardPage_description);
049: }
050:
051: // -------- Initialization ---------
052:
053: /**
054: * The wizard owning this page is responsible for calling this method with the
055: * current selection. The selection is used to initialize the fields of the wizard
056: * page.
057: *
058: * @param selection used to initialize the fields
059: */
060: public void init(IStructuredSelection selection) {
061: IJavaElement jelem = getInitialJavaElement(selection);
062:
063: initContainerPage(jelem);
064: initTypePage(jelem);
065: doStatusUpdate();
066: }
067:
068: // ------ validation --------
069:
070: private void doStatusUpdate() {
071: // all used component status
072: IStatus[] status = new IStatus[] {
073: fContainerStatus,
074: isEnclosingTypeSelected() ? fEnclosingTypeStatus
075: : fPackageStatus, fTypeNameStatus,
076: fModifierStatus, fSuperInterfacesStatus };
077:
078: // the mode severe status will be displayed and the OK button enabled/disabled.
079: updateStatus(status);
080: }
081:
082: /*
083: * @see NewContainerWizardPage#handleFieldChanged
084: */
085: protected void handleFieldChanged(String fieldName) {
086: super .handleFieldChanged(fieldName);
087:
088: doStatusUpdate();
089: }
090:
091: // ------ UI --------
092:
093: /*
094: * @see WizardPage#createControl
095: */
096: public void createControl(Composite parent) {
097: initializeDialogUnits(parent);
098:
099: Composite composite = new Composite(parent, SWT.NONE);
100: composite.setFont(parent.getFont());
101:
102: int nColumns = 4;
103:
104: GridLayout layout = new GridLayout();
105: layout.numColumns = nColumns;
106: composite.setLayout(layout);
107:
108: createContainerControls(composite, nColumns);
109: createPackageControls(composite, nColumns);
110: createEnclosingTypeControls(composite, nColumns);
111:
112: createSeparator(composite, nColumns);
113:
114: createTypeNameControls(composite, nColumns);
115: createModifierControls(composite, nColumns);
116:
117: createSuperInterfacesControls(composite, nColumns);
118:
119: createCommentControls(composite, nColumns);
120: enableCommentControl(true);
121:
122: setControl(composite);
123:
124: Dialog.applyDialogFont(composite);
125: PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
126: IJavaHelpContextIds.NEW_INTERFACE_WIZARD_PAGE);
127: }
128:
129: /*
130: * @see WizardPage#becomesVisible
131: */
132: public void setVisible(boolean visible) {
133: super.setVisible(visible);
134: if (visible) {
135: setFocus();
136: }
137: }
138:
139: }
|