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 annotation 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 annotation wizard page, extend <code>NewTypeWizardPage</code>.
033: * </p>
034: *
035: * @since 3.1
036: */
037: public class NewAnnotationWizardPage extends NewTypeWizardPage {
038:
039: private final static String PAGE_NAME = "NewAnnotationWizardPage"; //$NON-NLS-1$
040: private final static int TYPE = NewTypeWizardPage.ANNOTATION_TYPE;
041:
042: /**
043: * Create a new <code>NewAnnotationWizardPage</code>
044: */
045: public NewAnnotationWizardPage() {
046: super (TYPE, PAGE_NAME);
047:
048: setTitle(NewWizardMessages.NewAnnotationWizardPage_title);
049: setDescription(NewWizardMessages.NewAnnotationWizardPage_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: doStatusUpdate();
067: }
068:
069: // ------ validation --------
070:
071: private void doStatusUpdate() {
072: // all used component status
073: IStatus[] status = new IStatus[] {
074: fContainerStatus,
075: isEnclosingTypeSelected() ? fEnclosingTypeStatus
076: : fPackageStatus, fTypeNameStatus,
077: fModifierStatus, };
078:
079: // the mode severe status will be displayed and the OK button enabled/disabled.
080: updateStatus(status);
081: }
082:
083: /*
084: * @see NewContainerWizardPage#handleFieldChanged
085: */
086: protected void handleFieldChanged(String fieldName) {
087: super .handleFieldChanged(fieldName);
088:
089: doStatusUpdate();
090: }
091:
092: // ------ UI --------
093:
094: /*
095: * @see WizardPage#createControl
096: */
097: public void createControl(Composite parent) {
098: initializeDialogUnits(parent);
099:
100: Composite composite = new Composite(parent, SWT.NONE);
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: createCommentControls(composite, nColumns);
118: enableCommentControl(true);
119:
120: setControl(composite);
121:
122: Dialog.applyDialogFont(composite);
123: PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
124: IJavaHelpContextIds.NEW_ANNOTATION_WIZARD_PAGE);
125: }
126:
127: /*
128: * @see WizardPage#becomesVisible
129: */
130: public void setVisible(boolean visible) {
131: super.setVisible(visible);
132: if (visible) {
133: setFocus();
134: }
135: }
136: }
|