diff options
| author | kalyan prasad | 2017-08-09 09:02:57 +0000 |
|---|---|---|
| committer | kalyan prasad | 2017-08-23 11:02:45 +0000 |
| commit | 6e90489bb8bedb191fdd84efeb8a17859d7dcae4 (patch) | |
| tree | 77f5a79b11626bc88daa523ae7bf6957d59586a3 | |
| parent | df7958249c77c46710995fd91fd22f2dbb347975 (diff) | |
| download | eclipse.jdt.ui-6e90489bb8bedb191fdd84efeb8a17859d7dcae4.tar.gz eclipse.jdt.ui-6e90489bb8bedb191fdd84efeb8a17859d7dcae4.tar.xz eclipse.jdt.ui-6e90489bb8bedb191fdd84efeb8a17859d7dcae4.zip | |
creation
Change-Id: I59ab992009918109f0606d21a72c7415c98f9ade
Signed-off-by: kalyan prasad <kalyan_prasad@in.ibm.com>
8 files changed, 465 insertions, 95 deletions
diff --git a/org.eclipse.jdt.ui/icons/full/wizban/newmodule_wiz.png b/org.eclipse.jdt.ui/icons/full/wizban/newmodule_wiz.png Binary files differnew file mode 100644 index 0000000000..98e6bbc023 --- /dev/null +++ b/org.eclipse.jdt.ui/icons/full/wizban/newmodule_wiz.png diff --git a/org.eclipse.jdt.ui/icons/full/wizban/newmodule_wiz@2x.png b/org.eclipse.jdt.ui/icons/full/wizban/newmodule_wiz@2x.png Binary files differnew file mode 100644 index 0000000000..1fcefff896 --- /dev/null +++ b/org.eclipse.jdt.ui/icons/full/wizban/newmodule_wiz@2x.png diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java index 41c9a0435c..e11ecd9153 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java @@ -426,6 +426,7 @@ public class JavaPluginImages { public static final ImageDescriptor DESC_WIZBAN_NEWJPRJ= createUnManaged(T_WIZBAN, "newjprj_wiz.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_NEWSRCFOLDR= createUnManaged(T_WIZBAN, "newsrcfldr_wiz.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_NEWPACK= createUnManaged(T_WIZBAN, "newpack_wiz.png"); //$NON-NLS-1$ + public static final ImageDescriptor DESC_WIZBAN_NEWMODULE= createUnManaged(T_WIZBAN, "newmodule_wiz.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_NEWSCRAPPAGE= createUnManaged(T_WIZBAN, "newsbook_wiz.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_JAVA_LAUNCH= createUnManaged(T_WIZBAN, "java_app_wiz.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_JAVA_ATTACH= createUnManaged(T_WIZBAN, "java_attach_wiz.png"); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CreateModuleInfoAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CreateModuleInfoAction.java index cd84955083..9971a0cdb3 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CreateModuleInfoAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CreateModuleInfoAction.java @@ -21,10 +21,7 @@ import java.util.List; import org.eclipse.swt.widgets.Display; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -32,33 +29,28 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; +import org.eclipse.ui.IWorkbenchWizard; -import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IModuleDescription; -import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.internal.corext.util.InfoFilesUtil; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.wizards.NewModuleInfoWizard; public class CreateModuleInfoAction implements IObjectActionDelegate { private static final String MODULE_INFO_JAVA_FILENAME= JavaModelUtil.MODULE_INFO_JAVA; private ISelection fSelection; - + @Override public void selectionChanged(IAction action, ISelection selection) { fSelection= selection; @@ -119,95 +111,17 @@ public class CreateModuleInfoAction implements IObjectActionDelegate { } } - if (targetPkgFragmentRoot == null) { - targetPkgFragmentRoot= packageFragmentRoots[0]; - } - - createAndOpenFile(targetPkgFragmentRoot, packageFragmentRoots); - + IWorkbenchWizard moduleInfoWizard= new NewModuleInfoWizard(javaProject, packageFragmentRoots, targetPkgFragmentRoot); + WizardDialog dialog= new WizardDialog(getDisplay().getActiveShell(), moduleInfoWizard); + dialog.setHelpAvailable(false); + dialog.create(); + dialog.open(); } catch (CoreException e) { JavaPlugin.log(e); } } } - private void createAndOpenFile(IPackageFragmentRoot targetPkgFragmentRoot, IPackageFragmentRoot[] packageFragmentRoots) throws CoreException { - createModuleInfoJava(targetPkgFragmentRoot, packageFragmentRoots); - - IFile file= ((IFolder) targetPkgFragmentRoot.getCorrespondingResource()).getFile(MODULE_INFO_JAVA_FILENAME); - if (file.exists()) { - BasicNewResourceWizard.selectAndReveal(file, JavaPlugin.getActiveWorkbenchWindow()); - openFile(file); - } - } - - private void createModuleInfoJava(IPackageFragmentRoot targetPkgFragmentRoot, IPackageFragmentRoot[] packageFragmentRoots) throws CoreException { - String fileContent= getModuleInfoFileContent(packageFragmentRoots); - IPackageFragment defaultPkg= targetPkgFragmentRoot.getPackageFragment(""); //$NON-NLS-1$ - InfoFilesUtil.createInfoJavaFile(MODULE_INFO_JAVA_FILENAME, fileContent.toString(), defaultPkg, new NullProgressMonitor()); - } - - private String getModuleInfoFileContent(IPackageFragmentRoot[] packageFragmentRoots) throws CoreException { - List<String> exportedPackages= new ArrayList<>(); - for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { - for (IJavaElement child : packageFragmentRoot.getChildren()) { - if (child instanceof IPackageFragment) { - IPackageFragment pkgFragment= (IPackageFragment) child; - if (!pkgFragment.isDefaultPackage() && pkgFragment.getCompilationUnits().length != 0) { - exportedPackages.add(pkgFragment.getElementName()); - } - } - } - } - - IJavaProject javaProject= packageFragmentRoots[0].getJavaProject(); - - String[] requiredModules= JavaCore.getReferencedModules(javaProject); - - IModuleDescription moduleDescription= javaProject.getModuleDescription(); - String moduleName= moduleDescription != null ? moduleDescription.getElementName() : javaProject.getElementName(); - - StringBuilder fileContent= new StringBuilder(); - fileContent.append("module "); //$NON-NLS-1$ - fileContent.append(moduleName); - fileContent.append(" {"); //$NON-NLS-1$ - - for (String exportedPkg : exportedPackages) { - fileContent.append("exports "); //$NON-NLS-1$ - fileContent.append(exportedPkg); - fileContent.append(";"); //$NON-NLS-1$ - } - - for (String requiredModule : requiredModules) { - fileContent.append("requires "); //$NON-NLS-1$ - fileContent.append(requiredModule); - fileContent.append(';'); - } - - fileContent.append('}'); - - return fileContent.toString(); - } - - private void openFile(final IFile file) { - final IWorkbenchPage activePage= JavaPlugin.getActivePage(); - if (activePage != null) { - final Display display= getDisplay(); - if (display != null) { - display.asyncExec(new Runnable() { - @Override - public void run() { - try { - IDE.openEditor(activePage, file, true); - } catch (PartInitException e) { - JavaPlugin.log(e); - } - } - }); - } - } - } - private Display getDisplay() { Display display= Display.getCurrent(); if (display == null) diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewModuleInfoWizard.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewModuleInfoWizard.java new file mode 100644 index 0000000000..34097d3272 --- /dev/null +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewModuleInfoWizard.java @@ -0,0 +1,189 @@ +/*******************************************************************************
+ * Copyright (c) 2017 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
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.wizards;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+
+import org.eclipse.jdt.internal.corext.util.InfoFilesUtil;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+
+import org.eclipse.jdt.ui.wizards.NewModuleInfoWizardPage;
+
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+
+public class NewModuleInfoWizard extends Wizard implements INewWizard {
+
+ private NewModuleInfoWizardPage fPage;
+
+ private static final String MODULE_INFO_JAVA_FILENAME= JavaModelUtil.MODULE_INFO_JAVA;
+
+ private IPackageFragmentRoot fTargetPkgFragmentRoot;
+
+ private IPackageFragmentRoot[] fPackageFragmentRoots;
+
+ private IJavaProject fProject;
+
+ public NewModuleInfoWizard(IJavaProject project, IPackageFragmentRoot[] packageFragmentRoots, IPackageFragmentRoot targetPkgFragmentRoot) {
+ setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWMODULE);
+ setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
+ setWindowTitle(NewWizardMessages.NewModuleInfoWizard_title);
+ fProject= project;
+ fPackageFragmentRoots= packageFragmentRoots;
+ if (targetPkgFragmentRoot != null) {
+ fTargetPkgFragmentRoot= targetPkgFragmentRoot;
+ } else if (fPackageFragmentRoots != null && fPackageFragmentRoots.length > 0) {
+ fTargetPkgFragmentRoot= fPackageFragmentRoots[0];
+ }
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ if (fPage == null) {
+ fPage= new NewModuleInfoWizardPage();
+ fPage.setWizard(this);
+ fPage.init(fProject);
+ }
+ addPage(fPage);
+ }
+
+ @Override
+ public boolean performFinish() {
+ IStatus status= fPage.getModuleNameStatus();
+ int severity= status.getSeverity();
+ if (severity == IStatus.OK || severity == IStatus.WARNING || severity == IStatus.INFO) {
+ if (fProject != null && fTargetPkgFragmentRoot != null && fPackageFragmentRoots != null && fPackageFragmentRoots.length > 0) {
+ try {
+ createAndOpenFile(fTargetPkgFragmentRoot, fPackageFragmentRoots);
+ } catch (CoreException e) {
+ JavaPlugin.log(e);
+ }
+ }
+ }
+ return true;
+ }
+
+ private void createAndOpenFile(IPackageFragmentRoot targetPkgFragmentRoot, IPackageFragmentRoot[] packageFragmentRoots) throws CoreException {
+ createModuleInfoJava(targetPkgFragmentRoot, packageFragmentRoots);
+
+ IFile file= ((IFolder) targetPkgFragmentRoot.getCorrespondingResource()).getFile(MODULE_INFO_JAVA_FILENAME);
+ if (file.exists()) {
+ BasicNewResourceWizard.selectAndReveal(file, JavaPlugin.getActiveWorkbenchWindow());
+ openFile(file);
+ }
+ }
+
+ private void openFile(final IFile file) {
+ final IWorkbenchPage activePage= JavaPlugin.getActivePage();
+ if (activePage != null) {
+ final Display display= getDisplay();
+ if (display != null) {
+ display.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ IDE.openEditor(activePage, file, true);
+ } catch (PartInitException e) {
+ JavaPlugin.log(e);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ private Display getDisplay() {
+ Display display= Display.getCurrent();
+ if (display == null)
+ display= Display.getDefault();
+ return display;
+ }
+
+ private void createModuleInfoJava(IPackageFragmentRoot targetPkgFragmentRoot, IPackageFragmentRoot[] packageFragmentRoots) throws CoreException {
+ String fileContent= getModuleInfoFileContent(packageFragmentRoots);
+ IPackageFragment defaultPkg= targetPkgFragmentRoot.getPackageFragment(""); //$NON-NLS-1$
+ InfoFilesUtil.createInfoJavaFile(MODULE_INFO_JAVA_FILENAME, fileContent.toString(), defaultPkg, new NullProgressMonitor());
+ }
+
+ private String getModuleInfoFileContent(IPackageFragmentRoot[] packageFragmentRoots) throws CoreException {
+ List<String> exportedPackages= new ArrayList<>();
+ for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
+ for (IJavaElement child : packageFragmentRoot.getChildren()) {
+ if (child instanceof IPackageFragment) {
+ IPackageFragment pkgFragment= (IPackageFragment) child;
+ if (!pkgFragment.isDefaultPackage() && pkgFragment.getCompilationUnits().length != 0) {
+ exportedPackages.add(pkgFragment.getElementName());
+ }
+ }
+ }
+ }
+
+ String[] requiredModules= JavaCore.getReferencedModules(fProject);
+ String moduleName= fPage.getModuleNameText();
+ StringBuilder fileContent= new StringBuilder();
+ fileContent.append("module "); //$NON-NLS-1$
+ fileContent.append(moduleName);
+ fileContent.append(" {"); //$NON-NLS-1$
+
+ for (String exportedPkg : exportedPackages) {
+ fileContent.append("exports "); //$NON-NLS-1$
+ fileContent.append(exportedPkg);
+ fileContent.append(";"); //$NON-NLS-1$
+ }
+
+ for (String requiredModule : requiredModules) {
+ fileContent.append("requires "); //$NON-NLS-1$
+ fileContent.append(requiredModule);
+ fileContent.append(';');
+ }
+
+ fileContent.append('}');
+
+ return fileContent.toString();
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ //do nothing
+ }
+
+}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java index bfe5d68cc0..7aa095cc68 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java @@ -769,6 +769,14 @@ public final class NewWizardMessages extends NLS { public static String EditVariableEntryDialog_filename_empty; public static String CPListLabelProvider_external_annotations_location_label; + + public static String NewModuleInfoWizard_title; + public static String NewModuleInfoWizardPage_title; + public static String NewModuleInfoWizardPage_description; + public static String NewModuleInfoWizardPage_module_label; + public static String NewModuleInfoWizardPage_error_InvalidModuleName; + public static String NewModuleInfoWizardPage_warning_DiscouragedModuleName; + public static String NewModuleInfoWizardPage_error_EnterName; static { NLS.initializeMessages(BUNDLE_NAME, NewWizardMessages.class); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties index 1f968cc422..c4b1c21639 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties @@ -745,6 +745,18 @@ HintTextGroup_NoAction=<form>\ No actions available for this selection.<br>Reason:</br>{0}\ </form> +# ------- NewModuleFileWizardPage ------- + +NewModuleInfoWizardPage_title=module-info.java +NewModuleInfoWizardPage_description=Create a new module-info.java file. +NewModuleInfoWizardPage_module_label=&Module name: +NewModuleInfoWizardPage_error_InvalidModuleName=Invalid module name. {0} +NewModuleInfoWizardPage_error_EnterName=Enter a module name. +NewModuleInfoWizardPage_warning_DiscouragedModuleName=Discouraged module name. {0} + +NewModuleInfoWizard_title=New module-info.java + + # ------- NewSourceContainerWorkbookPage ------- NewSourceContainerWorkbookPage_HintTextGroup_title=Details NewSourceContainerWorkbookPage_ToolBar_ConfigureBP_tooltip=Configure Build Path diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewModuleInfoWizardPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewModuleInfoWizardPage.java new file mode 100644 index 0000000000..93dcf7e07b --- /dev/null +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewModuleInfoWizardPage.java @@ -0,0 +1,246 @@ +/*******************************************************************************
+ * Copyright (c) 2017 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
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.ui.wizards;
+
+import org.eclipse.equinox.bidi.StructuredTextTypeHandlerFactory;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.core.runtime.IStatus;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.util.BidiUtils;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IModuleDescription;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.internal.corext.util.Messages;
+
+import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
+import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
+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.IDialogFieldListener;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
+
+/**
+ * Wizard page to create a new module-info file.
+ *
+ * <p>
+ * Note: This class is not intended to be subclassed, but clients can instantiate.
+ * </p>
+ *
+ * @since 3.13 BETA_JAVA9
+ *
+ * @noextend This class is not intended to be subclassed by clients.
+ */
+public class NewModuleInfoWizardPage extends NewElementWizardPage {
+
+ private static final String PAGE_NAME= "NewModuleInfoWizardPage"; //$NON-NLS-1$
+
+ private IJavaProject fProject;
+
+ private static final String MODULE_INFO_JAVA_FILENAME= JavaModelUtil.MODULE_INFO_JAVA;
+
+ private StringDialogField fModuleNameDialogField;
+
+ /*
+ * Status of last validation of the module name field
+ */
+ private IStatus fModuleNameStatus;
+
+ public NewModuleInfoWizardPage() {
+ super(PAGE_NAME);
+ String title= Messages.format(NewWizardMessages.NewModuleInfoWizardPage_title, MODULE_INFO_JAVA_FILENAME);
+ setTitle(title);
+ String description= Messages.format(NewWizardMessages.NewModuleInfoWizardPage_description, MODULE_INFO_JAVA_FILENAME);
+ setDescription(description);
+
+ ModuleFieldAdapter adapter= new ModuleFieldAdapter();
+
+ fModuleNameDialogField= new StringDialogField();
+ fModuleNameDialogField.setDialogFieldListener(adapter);
+ fModuleNameDialogField.setLabelText(NewWizardMessages.NewModuleInfoWizardPage_module_label);
+
+ fModuleNameStatus= new StatusInfo();
+ }
+
+ // -------- Initialization ---------
+
+ /**
+ * The wizard owning this page is responsible for calling this method with the
+ * current selection's project. The project is used to initialize the fields of the wizard page.
+ *
+ * @param project used to initialize the fields
+ */
+ public void init(IJavaProject project) {
+
+ if (project != null) {
+ fProject= project;
+ } else {
+ return;
+ }
+
+ IModuleDescription moduleDescription= null;
+ try {
+ moduleDescription= fProject.getModuleDescription();
+ } catch (JavaModelException e) {
+ // Ignore
+ }
+ String moduleName= moduleDescription != null ? moduleDescription.getElementName() : fProject.getElementName();
+
+ IStatus status= getModuleStatus(moduleName);
+ if (status.getSeverity() == IStatus.OK || status.getSeverity() == IStatus.WARNING || status.getSeverity() == IStatus.INFO) {
+ setModuleText(moduleName, true);
+ } else {
+ setModuleText("", true); //$NON-NLS-1$
+ }
+
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite= new Composite(parent, SWT.NONE);
+ composite.setFont(parent.getFont());
+ int nColumns= 2;
+
+ GridLayout layout= new GridLayout();
+ layout.numColumns= 2;
+ composite.setLayout(layout);
+
+ createModuleInfoControls(composite, nColumns);
+
+ setControl(composite);
+ Dialog.applyDialogFont(composite);
+
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ setFocus();
+ }
+ }
+
+ /**
+ * Sets the focus to the module name field.
+ */
+ private void setFocus() {
+ fModuleNameDialogField.setFocus();
+ }
+
+ private void createModuleInfoControls(Composite composite, int nColumns) {
+ fModuleNameDialogField.doFillIntoGrid(composite, nColumns);
+ Text text= fModuleNameDialogField.getTextControl(null);
+ LayoutUtil.setWidthHint(text, getMaxFieldWidth());
+ LayoutUtil.setHorizontalGrabbing(text);
+ DialogField.createEmptySpace(composite);
+ TextFieldNavigationHandler.install(text);
+ BidiUtils.applyBidiProcessing(fModuleNameDialogField.getTextControl(null), StructuredTextTypeHandlerFactory.JAVA);
+ }
+
+ private class ModuleFieldAdapter implements IDialogFieldListener {
+
+ @Override
+ public void dialogFieldChanged(DialogField field) {
+ fModuleNameStatus= getModuleStatus(getModuleNameText());
+ // tell all others
+ handleFieldChanged();
+ }
+ }
+
+ /**
+ * Returns the recommended maximum width for text fields (in pixels). This method requires that
+ * createContent has been called before this method is call.
+ *
+ * @return the recommended maximum width for text fields.
+ */
+ private int getMaxFieldWidth() {
+ return convertWidthInCharsToPixels(25);
+ }
+
+ private void handleFieldChanged() {
+ updateStatus(fModuleNameStatus);
+ }
+
+ private IStatus validateModuleName(String name) {
+ String sourceLevel= fProject.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel= fProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ return JavaConventions.validateModuleName(name, sourceLevel, complianceLevel);
+ }
+
+ /**
+ * Validates the module name and returns the status of the validation.
+ *
+ * @param moduleName the module name
+ *
+ * @return the status of the validation
+ */
+ private IStatus getModuleStatus(String moduleName) {
+ StatusInfo status= new StatusInfo();
+ if (moduleName != null && moduleName.length() > 0) {
+ IStatus val= validateModuleName(moduleName);
+ if (val.getSeverity() == IStatus.ERROR) {
+ status.setError(Messages.format(NewWizardMessages.NewModuleInfoWizardPage_error_InvalidModuleName, val.getMessage()));
+ } else if (val.getSeverity() == IStatus.WARNING) {
+ status.setWarning(Messages.format(NewWizardMessages.NewModuleInfoWizardPage_warning_DiscouragedModuleName, val.getMessage()));
+ }
+ } else {
+ status.setError(NewWizardMessages.NewModuleInfoWizardPage_error_EnterName);
+ }
+ return status;
+ }
+
+ /**
+ * Returns the content of the module name field.
+ *
+ * @return the content of the module name field
+ */
+ public String getModuleNameText() {
+ return fModuleNameDialogField.getText();
+ }
+
+ public IJavaProject getProject() {
+ return fProject;
+ }
+
+ public IStatus getModuleNameStatus() {
+ return fModuleNameStatus;
+ }
+
+ /**
+ * Sets the content of the module name field to the given value.
+ *
+ * @param moduleName the new module name field text
+ * @param canBeModified if <code>true</code> the module input field can be modified; otherwise it is
+ * read-only.
+ */
+ private void setModuleText(String moduleName, boolean canBeModified) {
+ fModuleNameDialogField.setText(moduleName);
+ fModuleNameDialogField.setEnabled(canBeModified);
+ }
+
+}
|
