### Eclipse Workspace Patch 1.0 #P org.eclipse.ide4edu.javalite.ui Index: src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassWizardPage.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.ide4edu/javalite/plugins/org.eclipse.ide4edu.javalite.ui/src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassWizardPage.java,v retrieving revision 1.1 diff -u -r1.1 NewLiteClassWizardPage.java --- src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassWizardPage.java 4 Sep 2009 19:57:23 -0000 1.1 +++ src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassWizardPage.java 9 Oct 2009 13:37:08 -0000 @@ -1,286 +1,296 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Eclipse Foundation - modified from org.eclipse.jdt.ui.wizards.NewClassWizardPage - *******************************************************************************/ -package org.eclipse.ide4edu.javalite.ui.view; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; -import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; -import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; -import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup; -import org.eclipse.jdt.ui.CodeGeneration; -import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.PlatformUI; - -/** - * Wizard page to create a new class. - *
- * Note: This class is not intended to be subclassed, but clients can instantiate.
- * To implement a different kind of a new class wizard page, extend NewTypeWizardPage
.
- *
NewClassWizardPage
- */
- public NewLiteClassWizardPage() {
- super(true, PAGE_NAME);
-
- setTitle("New Java Class");
- setDescription("Create a new Java class.");
-
- String[] buttonNames3= new String[] {
- NewWizardMessages.NewClassWizardPage_methods_main, NewWizardMessages.NewClassWizardPage_methods_constructors,
- NewWizardMessages.NewClassWizardPage_methods_inherited
- };
- fMethodStubsButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames3, 1);
- fMethodStubsButtons.setLabelText(NewWizardMessages.NewClassWizardPage_methods_label);
- }
-
- // -------- Initialization ---------
-
- /**
- * The wizard owning this page is responsible for calling this method with the
- * current selection. The selection is used to initialize the fields of the wizard
- * page.
- *
- * @param selection used to initialize the fields
- */
- public void init(IStructuredSelection selection) {
- IJavaElement jelem= getInitialJavaElement(selection);
- initContainerPage(jelem);
- initTypePage(jelem);
- doStatusUpdate();
-
- boolean createMain= true;
- boolean createConstructors= true;
- boolean createUnimplemented= true;
- IDialogSettings dialogSettings= getDialogSettings();
- if (dialogSettings != null) {
- IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
- if (section != null) {
- createMain= section.getBoolean(SETTINGS_CREATEMAIN);
- createConstructors= section.getBoolean(SETTINGS_CREATECONSTR);
- createUnimplemented= section.getBoolean(SETTINGS_CREATEUNIMPLEMENTED);
- }
- }
-
- setMethodStubSelection(createMain, createConstructors, createUnimplemented, true);
- }
-
- // ------ validation --------
- private void doStatusUpdate() {
- // status of all used components
- IStatus[] status= new IStatus[] {
- fContainerStatus,
- isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus,
- fTypeNameStatus,
- fModifierStatus,
- fSuperClassStatus,
- fSuperInterfacesStatus
- };
-
- // the mode severe status will be displayed and the OK button enabled/disabled.
- updateStatus(status);
- }
-
-
- /*
- * @see NewContainerWizardPage#handleFieldChanged
- */
- protected void handleFieldChanged(String fieldName) {
- super.handleFieldChanged(fieldName);
-
- doStatusUpdate();
- }
-
-
- // ------ UI --------
-
- /*
- * @see WizardPage#createControl
- */
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
-
- Composite composite= new Composite(parent, SWT.NONE);
- composite.setFont(parent.getFont());
-
- int nColumns= 4;
-
- GridLayout layout= new GridLayout();
- layout.numColumns= nColumns;
- composite.setLayout(layout);
-
- // pick & choose the wanted UI components
-
- //createContainerControls(composite, nColumns);
- //createPackageControls(composite, nColumns);
- //createEnclosingTypeControls(composite, nColumns);
-
- //createSeparator(composite, nColumns);
-
- createTypeNameControls(composite, nColumns);
- createModifierControls(composite, nColumns);
-
- createSuperClassControls(composite, nColumns);
- createSuperInterfacesControls(composite, nColumns);
-
- //createMethodStubSelectionControls(composite, nColumns);
-
- //createCommentControls(composite, nColumns);
- //enableCommentControl(true);
-
- setControl(composite);
-
- Dialog.applyDialogFont(composite);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.NEW_CLASS_WIZARD_PAGE);
- }
-
- /*
- * @see WizardPage#becomesVisible
- */
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible) {
- setFocus();
- } else {
- IDialogSettings dialogSettings= getDialogSettings();
- if (dialogSettings != null) {
- IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
- if (section == null) {
- section= dialogSettings.addNewSection(PAGE_NAME);
- }
- section.put(SETTINGS_CREATEMAIN, isCreateMain());
- section.put(SETTINGS_CREATECONSTR, isCreateConstructors());
- section.put(SETTINGS_CREATEUNIMPLEMENTED, isCreateInherited());
- }
- }
- }
-
- private void createMethodStubSelectionControls(Composite composite, int nColumns) {
- Control labelControl= fMethodStubsButtons.getLabelControl(composite);
- LayoutUtil.setHorizontalSpan(labelControl, nColumns);
-
- DialogField.createEmptySpace(composite);
-
- Control buttonGroup= fMethodStubsButtons.getSelectionButtonsGroup(composite);
- LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
- }
-
- /**
- * Returns the current selection state of the 'Create Main' checkbox.
- *
- * @return the selection state of the 'Create Main' checkbox
- */
- public boolean isCreateMain() {
- return fMethodStubsButtons.isSelected(0);
- }
-
- /**
- * Returns the current selection state of the 'Create Constructors' checkbox.
- *
- * @return the selection state of the 'Create Constructors' checkbox
- */
- public boolean isCreateConstructors() {
- return fMethodStubsButtons.isSelected(1);
- }
-
- /**
- * Returns the current selection state of the 'Create inherited abstract methods'
- * checkbox.
- *
- * @return the selection state of the 'Create inherited abstract methods' checkbox
- */
- public boolean isCreateInherited() {
- return fMethodStubsButtons.isSelected(2);
- }
-
- /**
- * Sets the selection state of the method stub checkboxes.
- *
- * @param createMain initial selection state of the 'Create Main' checkbox.
- * @param createConstructors initial selection state of the 'Create Constructors' checkbox.
- * @param createInherited initial selection state of the 'Create inherited abstract methods' checkbox.
- * @param canBeModified if true
the method stub checkboxes can be changed by
- * the user. If false
the buttons are "read-only"
- */
- public void setMethodStubSelection(boolean createMain, boolean createConstructors, boolean createInherited, boolean canBeModified) {
- fMethodStubsButtons.setSelection(0, createMain);
- fMethodStubsButtons.setSelection(1, createConstructors);
- fMethodStubsButtons.setSelection(2, createInherited);
-
- fMethodStubsButtons.setEnabled(canBeModified);
- }
-
- // ---- creation ----------------
-
- /*
- * @see NewTypeWizardPage#createTypeMembers
- */
- protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
- boolean doMain= isCreateMain();
- boolean doConstr= isCreateConstructors();
- boolean doInherited= isCreateInherited();
- createInheritedMethods(type, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1));
-
- if (doMain) {
- StringBuffer buf= new StringBuffer();
- final String lineDelim= "\n"; // OK, since content is formatted afterwards //$NON-NLS-1$
- String comment= CodeGeneration.getMethodComment(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", new String[] {"args"}, new String[0], Signature.createTypeSignature("void", true), null, lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if (comment != null) {
- buf.append(comment);
- buf.append(lineDelim);
- }
- buf.append("public static void main("); //$NON-NLS-1$
- buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$
- buf.append("[] args) {"); //$NON-NLS-1$
- buf.append(lineDelim);
- final String content= CodeGeneration.getMethodBodyContent(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", false, "", lineDelim); //$NON-NLS-1$ //$NON-NLS-2$
- if (content != null && content.length() != 0)
- buf.append(content);
- buf.append(lineDelim);
- buf.append("}"); //$NON-NLS-1$
- type.createMethod(buf.toString(), null, false, null);
- }
-
- if (monitor != null) {
- monitor.done();
- }
- }
-
-}
-
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Eclipse Foundation - modified from org.eclipse.jdt.ui.wizards.NewClassWizardPage
+ *******************************************************************************/
+package org.eclipse.ide4edu.javalite.ui.view;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
+import org.eclipse.jdt.ui.CodeGeneration;
+import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Wizard page to create a new class.
+ *
+ * Note: This class is not intended to be subclassed, but clients can instantiate.
+ * To implement a different kind of a new class wizard page, extend NewTypeWizardPage
.
+ *
NewClassWizardPage
+ *
+ * @param firstPage the first page of the wizard
+ */
+ public NewLiteClassWizardPage(NewLiteClassProjectChooser firstPage) {
+ super(true, PAGE_NAME);
+
+ setTitle("New Java Class");
+ setDescription("Create a new Java class.");
+
+ String[] buttonNames3= new String[] {
+ NewWizardMessages.NewClassWizardPage_methods_main,
+ NewWizardMessages.NewClassWizardPage_methods_constructors,
+ NewWizardMessages.NewClassWizardPage_methods_inherited
+ };
+ fMethodStubsButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames3, 1);
+ fMethodStubsButtons.setLabelText(NewWizardMessages.NewClassWizardPage_methods_label);
+ fFirstPage = firstPage;
+ }
+
+ // -------- Initialization ---------
+
+ /**
+ * The wizard owning this page is responsible for calling this method with the
+ * current selection. The selection is used to initialize the fields of the wizard
+ * page.
+ *
+ * @param selection used to initialize the fields
+ */
+ public void init(IStructuredSelection selection) {
+ IJavaElement jelem = null;
+ if (fFirstPage == null) {
+ jelem = getInitialJavaElement(selection);
+ } else {
+ jelem = fFirstPage.getSelectedProject();
+ }
+ initContainerPage(jelem);
+ initTypePage(jelem);
+ doStatusUpdate();
+
+ boolean createMain= true;
+ boolean createConstructors= true;
+ boolean createUnimplemented= true;
+ IDialogSettings dialogSettings= getDialogSettings();
+ if (dialogSettings != null) {
+ IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
+ if (section != null) {
+ createMain= section.getBoolean(SETTINGS_CREATEMAIN);
+ createConstructors= section.getBoolean(SETTINGS_CREATECONSTR);
+ createUnimplemented= section.getBoolean(SETTINGS_CREATEUNIMPLEMENTED);
+ }
+ }
+
+ setMethodStubSelection(createMain, createConstructors, createUnimplemented, true);
+ }
+
+ // ------ validation --------
+ private void doStatusUpdate() {
+ // status of all used components
+ IStatus[] status= new IStatus[] {
+ fContainerStatus,
+ isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus,
+ fTypeNameStatus,
+ fModifierStatus,
+ fSuperClassStatus,
+ fSuperInterfacesStatus
+ };
+
+ // the mode severe status will be displayed and the OK button enabled/disabled.
+ updateStatus(status);
+ }
+
+
+ /*
+ * @see NewContainerWizardPage#handleFieldChanged
+ */
+ protected void handleFieldChanged(String fieldName) {
+ super.handleFieldChanged(fieldName);
+
+ doStatusUpdate();
+ }
+
+
+ // ------ UI --------
+
+ /*
+ * @see WizardPage#createControl
+ */
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite= new Composite(parent, SWT.NONE);
+ composite.setFont(parent.getFont());
+
+ int nColumns= 4;
+
+ GridLayout layout= new GridLayout();
+ layout.numColumns= nColumns;
+ composite.setLayout(layout);
+
+ // pick & choose the wanted UI components
+
+ //createContainerControls(composite, nColumns);
+ //createPackageControls(composite, nColumns);
+ //createEnclosingTypeControls(composite, nColumns);
+
+ //createSeparator(composite, nColumns);
+
+ createTypeNameControls(composite, nColumns);
+ createModifierControls(composite, nColumns);
+
+ createSuperClassControls(composite, nColumns);
+ createSuperInterfacesControls(composite, nColumns);
+
+ //createMethodStubSelectionControls(composite, nColumns);
+
+ //createCommentControls(composite, nColumns);
+ //enableCommentControl(true);
+
+ setControl(composite);
+
+ Dialog.applyDialogFont(composite);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.NEW_CLASS_WIZARD_PAGE);
+ }
+
+ /*
+ * @see WizardPage#becomesVisible
+ */
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ setFocus();
+ } else {
+ IDialogSettings dialogSettings= getDialogSettings();
+ if (dialogSettings != null) {
+ IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
+ if (section == null) {
+ section= dialogSettings.addNewSection(PAGE_NAME);
+ }
+ section.put(SETTINGS_CREATEMAIN, isCreateMain());
+ section.put(SETTINGS_CREATECONSTR, isCreateConstructors());
+ section.put(SETTINGS_CREATEUNIMPLEMENTED, isCreateInherited());
+ }
+ }
+ }
+
+ private void createMethodStubSelectionControls(Composite composite, int nColumns) {
+ Control labelControl= fMethodStubsButtons.getLabelControl(composite);
+ LayoutUtil.setHorizontalSpan(labelControl, nColumns);
+
+ DialogField.createEmptySpace(composite);
+
+ Control buttonGroup= fMethodStubsButtons.getSelectionButtonsGroup(composite);
+ LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
+ }
+
+ /**
+ * Returns the current selection state of the 'Create Main' checkbox.
+ *
+ * @return the selection state of the 'Create Main' checkbox
+ */
+ public boolean isCreateMain() {
+ return fMethodStubsButtons.isSelected(0);
+ }
+
+ /**
+ * Returns the current selection state of the 'Create Constructors' checkbox.
+ *
+ * @return the selection state of the 'Create Constructors' checkbox
+ */
+ public boolean isCreateConstructors() {
+ return fMethodStubsButtons.isSelected(1);
+ }
+
+ /**
+ * Returns the current selection state of the 'Create inherited abstract methods'
+ * checkbox.
+ *
+ * @return the selection state of the 'Create inherited abstract methods' checkbox
+ */
+ public boolean isCreateInherited() {
+ return fMethodStubsButtons.isSelected(2);
+ }
+
+ /**
+ * Sets the selection state of the method stub checkboxes.
+ *
+ * @param createMain initial selection state of the 'Create Main' checkbox.
+ * @param createConstructors initial selection state of the 'Create Constructors' checkbox.
+ * @param createInherited initial selection state of the 'Create inherited abstract methods' checkbox.
+ * @param canBeModified if true
the method stub checkboxes can be changed by
+ * the user. If false
the buttons are "read-only"
+ */
+ public void setMethodStubSelection(boolean createMain, boolean createConstructors, boolean createInherited, boolean canBeModified) {
+ fMethodStubsButtons.setSelection(0, createMain);
+ fMethodStubsButtons.setSelection(1, createConstructors);
+ fMethodStubsButtons.setSelection(2, createInherited);
+
+ fMethodStubsButtons.setEnabled(canBeModified);
+ }
+
+ // ---- creation ----------------
+
+ /*
+ * @see NewTypeWizardPage#createTypeMembers
+ */
+ protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
+ boolean doMain= isCreateMain();
+ boolean doConstr= isCreateConstructors();
+ boolean doInherited= isCreateInherited();
+ createInheritedMethods(type, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1));
+
+ if (doMain) {
+ StringBuffer buf= new StringBuffer();
+ final String lineDelim= "\n"; // OK, since content is formatted afterwards //$NON-NLS-1$
+ String comment= CodeGeneration.getMethodComment(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", new String[] {"args"}, new String[0], Signature.createTypeSignature("void", true), null, lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (comment != null) {
+ buf.append(comment);
+ buf.append(lineDelim);
+ }
+ buf.append("public static void main("); //$NON-NLS-1$
+ buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$
+ buf.append("[] args) {"); //$NON-NLS-1$
+ buf.append(lineDelim);
+ final String content= CodeGeneration.getMethodBodyContent(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", false, "", lineDelim); //$NON-NLS-1$ //$NON-NLS-2$
+ if (content != null && content.length() != 0)
+ buf.append(content);
+ buf.append(lineDelim);
+ buf.append("}"); //$NON-NLS-1$
+ type.createMethod(buf.toString(), null, false, null);
+ }
+
+ if (monitor != null) {
+ monitor.done();
+ }
+ }
+
+}
+
Index: src/org/eclipse/ide4edu/javalite/ui/view/OpenNewLiteClassWizardAction.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.ide4edu/javalite/plugins/org.eclipse.ide4edu.javalite.ui/src/org/eclipse/ide4edu/javalite/ui/view/OpenNewLiteClassWizardAction.java,v
retrieving revision 1.1
diff -u -r1.1 OpenNewLiteClassWizardAction.java
--- src/org/eclipse/ide4edu/javalite/ui/view/OpenNewLiteClassWizardAction.java 4 Sep 2009 19:57:23 -0000 1.1
+++ src/org/eclipse/ide4edu/javalite/ui/view/OpenNewLiteClassWizardAction.java 9 Oct 2009 13:37:08 -0000
@@ -1,87 +1,94 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Eclipse Foundation - Modified from org.eclipse.jdt.ui.actions.OpenNewClassWizardAction
- *******************************************************************************/
-package org.eclipse.ide4edu.javalite.ui.view;
-
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.internal.ui.JavaPluginImages;
-import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
-import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.INewWizard;
-
-public class OpenNewLiteClassWizardAction extends AbstractOpenWizardAction {
-
- private NewLiteClassWizardPage fPage;
- private boolean fOpenEditorOnFinish;
-
- /**
- * Creates an instance of the OpenNewClassWizardAction
.
- */
- public OpenNewLiteClassWizardAction() {
- setText("New Java Class");
- setDescription("Create a new Java class.");
- setToolTipText("New Java Class");
- //setImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWCLASS);
- setImageDescriptor(JavaPluginImages.DESC_TOOL_NEWCLASS);
- //PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION);
-
- fPage= new NewLiteClassWizardPage();
- fOpenEditorOnFinish= true;
- }
-
- /**
- * Sets a page to be used by the wizard or null
to use a page initialized with values
- * from the current selection (see {@link #getSelection()} and {@link #setSelection(IStructuredSelection)}).
- * @param page the page to use or null
- */
- public void setConfiguredWizardPage(NewLiteClassWizardPage page) {
- fPage= page;
- }
-
- /**
- * Specifies if the wizard will open the created type with the default editor. The default behaviour is to open
- * an editor.
- *
- * @param openEditorOnFinish if set, the wizard will open the created type with the default editor
- *
- * @since 3.3
- */
- public void setOpenEditorOnFinish(boolean openEditorOnFinish) {
- fOpenEditorOnFinish= openEditorOnFinish;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.ui.actions.AbstractOpenWizardAction#createWizard()
- */
- protected final INewWizard createWizard() throws CoreException {
- return new NewLiteClassCreationWizard(fPage, fOpenEditorOnFinish);
- }
-
- protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) {
- IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
- if (workspaceRoot.getProjects().length == 0) {
- String title= NewWizardMessages.AbstractOpenWizardAction_noproject_title;
- String message= NewWizardMessages.AbstractOpenWizardAction_noproject_message;
- if (MessageDialog.openQuestion(shell, title, message)) {
- new OpenNewLiteJavaProjectWizardAction().run();
- return workspaceRoot.getProjects().length != 0;
- }
- return false;
- }
- return true;
- }
-}
-
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Eclipse Foundation - Modified from org.eclipse.jdt.ui.actions.OpenNewClassWizardAction
+ *******************************************************************************/
+package org.eclipse.ide4edu.javalite.ui.view;
+
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.INewWizard;
+
+public class OpenNewLiteClassWizardAction extends AbstractOpenWizardAction {
+
+ private NewLiteClassWizardPage fPage;
+ private boolean fOpenEditorOnFinish;
+
+ /**
+ * Creates an instance of the OpenNewClassWizardAction
.
+ */
+ public OpenNewLiteClassWizardAction() {
+ setText("New Java Class");
+ setDescription("Create a new Java class.");
+ setToolTipText("New Java Class");
+ //setImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWCLASS);
+ setImageDescriptor(JavaPluginImages.DESC_TOOL_NEWCLASS);
+ //PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION);
+
+ fPage= new NewLiteClassWizardPage(null);
+ fOpenEditorOnFinish= true;
+ }
+
+ /**
+ * Sets a page to be used by the wizard or null
to use a page initialized with values
+ * from the current selection (see {@link #getSelection()} and {@link #setSelection(IStructuredSelection)}).
+ * @param page the page to use or null
+ */
+ public void setConfiguredWizardPage(NewLiteClassWizardPage page) {
+ fPage= page;
+ }
+
+ /**
+ * Specifies if the wizard will open the created type with the default editor. The default behaviour is to open
+ * an editor.
+ *
+ * @param openEditorOnFinish if set, the wizard will open the created type with the default editor
+ *
+ * @since 3.3
+ */
+ public void setOpenEditorOnFinish(boolean openEditorOnFinish) {
+ fOpenEditorOnFinish= openEditorOnFinish;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.ui.actions.AbstractOpenWizardAction#createWizard()
+ */
+ protected final INewWizard createWizard() throws CoreException {
+ // If there is more then one project in the workspace and none is
+ // selected, show the project chooser.
+ boolean openProjectChooser = false;
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ if (workspaceRoot.getProjects().length >= 2 && getSelection().size() == 0) {
+ openProjectChooser = true;
+ }
+ return new NewLiteClassCreationWizard(fPage, openProjectChooser, fOpenEditorOnFinish);
+ }
+
+ protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) {
+ IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
+ if (workspaceRoot.getProjects().length == 0) {
+ String title= NewWizardMessages.AbstractOpenWizardAction_noproject_title;
+ String message= NewWizardMessages.AbstractOpenWizardAction_noproject_message;
+ if (MessageDialog.openQuestion(shell, title, message)) {
+ new OpenNewLiteJavaProjectWizardAction().run();
+ return workspaceRoot.getProjects().length != 0;
+ }
+ return false;
+ }
+ return true;
+ }
+}
+
Index: src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassCreationWizard.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.ide4edu/javalite/plugins/org.eclipse.ide4edu.javalite.ui/src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassCreationWizard.java,v
retrieving revision 1.1
diff -u -r1.1 NewLiteClassCreationWizard.java
--- src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassCreationWizard.java 4 Sep 2009 19:57:23 -0000 1.1
+++ src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassCreationWizard.java 9 Oct 2009 13:37:08 -0000
@@ -1,99 +1,105 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Eclipse Foundation - Modified from org.eclipse.jdt.internal.ui.wizards.NewClassCreationWizard
- *******************************************************************************/
-package org.eclipse.ide4edu.javalite.ui.view;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-
-import org.eclipse.jdt.core.IJavaElement;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jdt.ui.wizards.NewClassWizardPage;
-
-import org.eclipse.jdt.internal.ui.JavaPlugin;
-import org.eclipse.jdt.internal.ui.JavaPluginImages;
-import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
-import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
-
-public class NewLiteClassCreationWizard extends NewElementWizard {
-
- private NewLiteClassWizardPage fPage;
- private boolean fOpenEditorOnFinish;
-
- public NewLiteClassCreationWizard(NewLiteClassWizardPage page, boolean openEditorOnFinish) {
- setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWCLASS);
- setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
- setWindowTitle(NewWizardMessages.NewClassCreationWizard_title);
-
- fPage= new NewLiteClassWizardPage();
- fOpenEditorOnFinish= openEditorOnFinish;
- }
-
- public NewLiteClassCreationWizard() {
- this(null, true);
- }
-
- /*
- * @see Wizard#createPages
- */
- public void addPages() {
- super.addPages();
- if (fPage == null) {
- fPage= new NewLiteClassWizardPage();
- }
- fPage.init(getSelection());
- addPage(fPage);
- }
-
- /*(non-Javadoc)
- * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#canRunForked()
- */
- protected boolean canRunForked() {
- return !fPage.isEnclosingTypeSelected();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
- fPage.createType(monitor); // use the full progress monitor
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.wizard.IWizard#performFinish()
- */
- public boolean performFinish() {
- warnAboutTypeCommentDeprecation();
- boolean res= super.performFinish();
- if (res) {
- IResource resource= fPage.getModifiedResource();
- if (resource != null) {
- selectAndReveal(resource);
- if (fOpenEditorOnFinish) {
- openResource((IFile) resource);
- }
- }
- }
- return res;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
- */
- public IJavaElement getCreatedElement() {
- return fPage.getCreatedType();
- }
-
-}
-
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Eclipse Foundation - Modified from org.eclipse.jdt.internal.ui.wizards.NewClassCreationWizard
+ *******************************************************************************/
+package org.eclipse.ide4edu.javalite.ui.view;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.jface.wizard.IWizardPage;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class NewLiteClassCreationWizard extends NewElementWizard {
+
+ private NewLiteClassProjectChooser fProjectChooserPage;
+ private NewLiteClassWizardPage fNewLiteClassPage;
+ private boolean fOpenProjectChooser;
+ private boolean fOpenEditorOnFinish;
+
+ public NewLiteClassCreationWizard(NewLiteClassWizardPage page, boolean openProjectChooser, boolean openEditorOnFinish) {
+ setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWCLASS);
+ setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
+ setWindowTitle(NewWizardMessages.NewClassCreationWizard_title);
+
+ fOpenProjectChooser= openProjectChooser;
+ fOpenEditorOnFinish= openEditorOnFinish;
+ }
+
+ public NewLiteClassCreationWizard() {
+ this(null, false, true);
+ }
+
+ /*
+ * @see Wizard#createPages
+ */
+ public void addPages() {
+ super.addPages();
+ if (!fOpenProjectChooser) {
+ fProjectChooserPage = null;
+ fNewLiteClassPage = new NewLiteClassWizardPage(null);
+ fNewLiteClassPage.init(getSelection());
+ } else {
+ fProjectChooserPage = new NewLiteClassProjectChooser();
+ fNewLiteClassPage = new NewLiteClassWizardPage(fProjectChooserPage);
+ fProjectChooserPage.setSecondPage(fNewLiteClassPage);
+ addPage(fProjectChooserPage);
+ }
+ addPage(fNewLiteClassPage);
+ }
+
+ /*(non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#canRunForked()
+ */
+ protected boolean canRunForked() {
+ return !fNewLiteClassPage.isEnclosingTypeSelected();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
+ fNewLiteClassPage.createType(monitor); // use the full progress monitor
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.IWizard#performFinish()
+ */
+ public boolean performFinish() {
+ warnAboutTypeCommentDeprecation();
+ boolean res= super.performFinish();
+ if (res) {
+ IResource resource= fNewLiteClassPage.getModifiedResource();
+ if (resource != null) {
+ selectAndReveal(resource);
+ if (fOpenEditorOnFinish) {
+ openResource((IFile) resource);
+ }
+ }
+ }
+ return res;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
+ */
+ public IJavaElement getCreatedElement() {
+ return fNewLiteClassPage.getCreatedType();
+ }
+
+}
+
Index: src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassProjectChooser.java
===================================================================
RCS file: src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassProjectChooser.java
diff -N src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassProjectChooser.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ide4edu/javalite/ui/view/NewLiteClassProjectChooser.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,120 @@
+package org.eclipse.ide4edu.javalite.ui.view;
+
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.debug.internal.ui.sourcelookup.SourceElementLabelProvider;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.dialogs.FilteredList;
+
+/**
+ * Wizard page to create a new class. Visible only if there's no project selected in the project explorer.
+ *
+ *
+ * Note: This class is not intended to be subclassed, but clients can instantiate.
+ * To implement a different kind of a new class wizard page, extend NewTypeWizardPage
.
+ *
NewLiteClassProjectChooser
+ */
+ public NewLiteClassProjectChooser() {
+ super(PAGE_NAME);
+
+ setTitle("New Java Class");
+ setDescription("Choose the project to add the new class.");
+ }
+
+ /*
+ * @see WizardPage#createControl
+ */
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite= new Composite(parent, SWT.NONE);
+ composite.setFont(parent.getFont());
+
+ createFilteredList(composite);
+
+ setControl(composite);
+ Dialog.applyDialogFont(composite);
+ }
+
+ /**
+ * Creates a filtered list that shows the projects in the project explorer.
+ * @param parent the parent composite.
+ */
+ private void createFilteredList(Composite parent) {
+ int flags = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE;
+ SourceElementLabelProvider fRenderer = new SourceElementLabelProvider();
+ fFilteredList = new FilteredList(parent, flags, fRenderer, fIgnoreCase, fAllowDuplicates, fMatchEmptyString);
+ fFilteredList.setBounds(10, 10, 300, 300);
+
+ IJavaProject[] projects;
+ try {
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ projects= JavaCore.create(workspaceRoot).getJavaProjects();
+ } catch (JavaModelException e) {
+ JavaPlugin.log(e);
+ projects= new IJavaProject[0];
+ }
+
+ fFilteredList.setElements(projects);
+ fFilteredList.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ selectedProject = (IJavaProject) fFilteredList.getSelection()[0];
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ selectedProject = (IJavaProject) fFilteredList.getSelection()[0];
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
+ */
+ public IWizardPage getNextPage() {
+ if (fSecondPage != null) {
+ fSecondPage.init(null);
+ }
+ return super.getNextPage();
+ }
+
+ /**
+ * Set the second page
+ * @param secondPage The second page
+ */
+ public void setSecondPage(NewLiteClassWizardPage secondPage) {
+ fSecondPage = secondPage;
+ }
+
+ /**
+ * Return the current selected project.
+ *
+ * @return the current selected project.
+ */
+ public IJavaProject getSelectedProject() {
+ return selectedProject;
+ }
+}