Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 141541 Details for
Bug 261873
[fiximprove]: Enhancements on the project creation wizard
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
New updated patch for the improvement.
bug261873.patch (text/plain), 150.60 KB, created by
Fernando Rocha
on 2009-07-14 12:06:17 EDT
(
hide
)
Description:
New updated patch for the improvement.
Filename:
MIME Type:
Creator:
Fernando Rocha
Created:
2009-07-14 12:06:17 EDT
Size:
150.60 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mtj.core >Index: src/org/eclipse/mtj/internal/core/project/midp/MidletSuiteFactory.java >=================================================================== >--- src/org/eclipse/mtj/internal/core/project/midp/MidletSuiteFactory.java (revision 1344) >+++ src/org/eclipse/mtj/internal/core/project/midp/MidletSuiteFactory.java (working copy) >@@ -34,6 +34,7 @@ > import java.util.ArrayList; > import java.util.Arrays; > import java.util.HashMap; >+import java.util.List; > import java.util.Map; > > import org.eclipse.core.resources.IFile; >@@ -40,6 +41,7 @@ > import org.eclipse.core.resources.IFolder; > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IProjectDescription; >+import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >@@ -47,7 +49,10 @@ > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Preferences; > import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.jdt.core.IClasspathEntry; > 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.mtj.core.MTJCore; > import org.eclipse.mtj.core.project.IMTJProject; >@@ -56,10 +61,11 @@ > import org.eclipse.mtj.core.project.runtime.MTJRuntimeList; > import org.eclipse.mtj.core.sdk.device.IDevice; > import org.eclipse.mtj.core.sdk.device.IDeviceRegistryListener; >-import org.eclipse.mtj.core.sdk.device.midp.IMIDPAPI; > import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice; > import org.eclipse.mtj.internal.core.IMTJCoreConstants; >+import org.eclipse.mtj.internal.core.l10n.L10nApi; > import org.eclipse.mtj.internal.core.util.ColonDelimitedProperties; >+import org.eclipse.mtj.internal.core.util.Utils; > import org.eclipse.mtj.internal.core.util.log.MTJLogger; > > /** >@@ -87,26 +93,6 @@ > */ > private static final String BIN_FOLDER_NAME = "bin"; //$NON-NLS-1$ > >- /** >- * >- */ >- private static final String CONFIGURATION_VERSION_1_0 = "CLDC-1.0"; //$NON-NLS-1$ >- >- /** >- * >- */ >- private static final String MIDLET_DEFAULT_NAME_END = " MIDlet Suite"; //$NON-NLS-1$ >- >- /** >- * >- */ >- private static final String MIDLET_DEFAULT_VENDOR = "MIDlet Suite Vendor"; //$NON-NLS-1$ >- >- /** >- * >- */ >- private static final String MIDLET_INITIAL_VERSION_1_0_0 = "1.0.0"; //$NON-NLS-1$ >- > private IMIDPDevice device; > > private String jadFileName; >@@ -117,6 +103,16 @@ > > private IProject project; > >+ private Map<String, String> properties; >+ >+ private boolean localizationEnable; >+ >+ private String propertiesFolderName; >+ >+ private String packageName; >+ >+ private boolean jmUnitSupportEnable; >+ > /** > * Construct a new runnable for MIDlet suite creation. > * >@@ -138,6 +134,20 @@ > } > > /** >+ * @return the localizationEnable >+ */ >+ public boolean isLocalizationEnable() { >+ return localizationEnable; >+ } >+ >+ /** >+ * @return the jmUnitSupportEnable >+ */ >+ public boolean isJMUnitSupportEnable() { >+ return jmUnitSupportEnable; >+ } >+ >+ /** > * Run the specified runnable using the specified progress monitor. > * > * @param monitor the monitor used to report progress >@@ -150,6 +160,9 @@ > // Configure the project > IMidletSuiteProject suite = getMidletSuiteProject(javaProject); > >+ // Create the localization data >+ createL10nData(suite, monitor); >+ > suite.setJadFileName(jadFileName); > addNatures(monitor); > >@@ -173,6 +186,53 @@ > } > } > >+ private void createL10nData(IMidletSuiteProject suite, >+ IProgressMonitor monitor) throws CoreException, IOException { >+ IProject project = suite.getProject(); >+ >+ if (this.localizationEnable) { >+ IFolder newSource = project.getFolder(propertiesFolderName); >+ if (!newSource.exists()) { >+ newSource.create(true, true, monitor); >+ } >+ project.refreshLocal(IResource.DEPTH_ONE, monitor); >+ >+ IClasspathEntry newEntry = JavaCore.newSourceEntry(newSource >+ .getFullPath()); >+ List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); >+ entries.addAll(Arrays.asList(javaProject.getRawClasspath())); >+ entries.add(newEntry); >+ >+ IClasspathEntry[] array = entries >+ .toArray(new IClasspathEntry[entries.size()]); >+ if (!javaProject.hasClasspathCycle(array)) { >+ javaProject.setRawClasspath(array, monitor); >+ } >+ >+ IResource[] sources = Utils.getSourceFolders(javaProject); >+ for (int i = 0; i < sources.length; i++) { >+ IPackageFragmentRoot source = javaProject >+ .getPackageFragmentRoot(sources[i]); >+ if (source.exists()) { >+ IPackageFragment packageFragment = source >+ .createPackageFragment(packageName, true, >+ monitor); >+ L10nApi.createLocalizationFile(project, newSource >+ .getProjectRelativePath(), packageFragment); >+ javaProject.getProject().refreshLocal( >+ IResource.DEPTH_INFINITE, >+ new NullProgressMonitor()); >+ L10nApi.createLocalizationApi(project, packageFragment, >+ newSource.getProjectRelativePath()); >+ javaProject.getProject().refreshLocal( >+ IResource.DEPTH_INFINITE, >+ new NullProgressMonitor()); >+ break; >+ } >+ } >+ } >+ } >+ > /** > * @param preprocessEnable the preprocessEnable to set > */ >@@ -181,6 +241,20 @@ > } > > /** >+ * @param localizationEnable the localizationEnable to set >+ */ >+ public void setLocalizationEnabled(boolean localizationEnable) { >+ this.localizationEnable = localizationEnable; >+ } >+ >+ /** >+ * @param jmUnitSupportEnable the jmUnitSupportEnable to set >+ */ >+ public void setJMUnitSupport(boolean jmUnitSupportEnable) { >+ this.jmUnitSupportEnable = jmUnitSupportEnable; >+ } >+ >+ /** > * Add the specified nature to the list of natures if it is not already > * in the list. > * >@@ -222,6 +296,18 @@ > IMTJCoreConstants.J2ME_PREPROCESSING_NATURE_ID); > } > >+ if (isLocalizationEnable()) { >+ updated = updated >+ | addNatureIfNecessary(natures, >+ IMTJCoreConstants.L10N_NATURE_ID); >+ } >+ >+ if (isJMUnitSupportEnable()) { >+ updated = updated >+ | addNatureIfNecessary(natures, >+ IMTJCoreConstants.JMUNIT_NATURE_ID); >+ } >+ > if (updated) { > IProgressMonitor submonitor = new SubProgressMonitor(monitor, 1); > desc.setNatureIds(natures.toArray(new String[natures.size()])); >@@ -283,17 +369,6 @@ > } > > /** >- * Return the version of the configuration from the device or >- * <code>null</code> if the version cannot be determined. >- * >- * @return >- */ >- private String getConfigurationVersion() { >- IMIDPAPI api = device.getCLDCAPI(); >- return (api == null) ? CONFIGURATION_VERSION_1_0 : api.toString(); >- } >- >- /** > * @see org.eclipse.mtj.core.project.midp.IMidletSuiteProject#getDefaultApplicationDescriptorProperties() > */ > private ColonDelimitedProperties getDefaultApplicationDescriptorProperties( >@@ -305,26 +380,19 @@ > .getJarFilename()); > > // Couple of names... >- descriptor.setProperty(IJADConstants.JAD_MIDLET_NAME, project >- .getName() >- + MIDLET_DEFAULT_NAME_END); >- descriptor.setProperty(IJADConstants.JAD_MIDLET_VENDOR, >- MIDLET_DEFAULT_VENDOR); >- descriptor.setProperty(IJADConstants.JAD_MIDLET_VERSION, >- MIDLET_INITIAL_VERSION_1_0_0); >+ descriptor.setProperty(IJADConstants.JAD_MIDLET_NAME, properties >+ .get(IJADConstants.JAD_MIDLET_NAME)); >+ descriptor.setProperty(IJADConstants.JAD_MIDLET_VENDOR, properties >+ .get(IJADConstants.JAD_MIDLET_VENDOR)); >+ descriptor.setProperty(IJADConstants.JAD_MIDLET_VERSION, properties >+ .get(IJADConstants.JAD_MIDLET_VERSION)); > > // Platform information >- String configVersion = getConfigurationVersion(); >- if (configVersion != null) { >- descriptor.setProperty(IJADConstants.JAD_MICROEDITION_CONFIG, >- configVersion); >- } >+ descriptor.setProperty(IJADConstants.JAD_MICROEDITION_CONFIG, >+ properties.get(IJADConstants.JAD_MICROEDITION_CONFIG)); > >- String profileVersion = getProfileVersion(); >- if (profileVersion != null) { >- descriptor.setProperty(IJADConstants.JAD_MICROEDITION_PROFILE, >- profileVersion); >- } >+ descriptor.setProperty(IJADConstants.JAD_MICROEDITION_PROFILE, >+ properties.get(IJADConstants.JAD_MICROEDITION_PROFILE)); > > return descriptor; > } >@@ -371,18 +439,6 @@ > } > > /** >- * Return the version of the profile from the device or >- * <code>null</code> if the version cannot be determined. >- * >- * @return >- */ >- private String getProfileVersion() { >- IMIDPAPI api = device.getMIDPAPI(); >- >- return (api == null) ? null : api.toString(); >- } >- >- /** > * Set the necessary java project options. > * > * @param monitor >@@ -409,6 +465,18 @@ > IMTJProject midletprj = getMidletSuiteProject(javaProject); > midletprj.saveMetaData(); > } >+ >+ public void setProperties(Map<String, String> properties) { >+ this.properties = properties; >+ } >+ >+ public void setPropertiesFolderName(String propertiesFolderName) { >+ this.propertiesFolderName = propertiesFolderName; >+ } >+ >+ public void setPackageName(String packageName) { >+ this.packageName = packageName; >+ } > } > > // Storage of the previously created MIDlet suite projects >Index: src/org/eclipse/mtj/internal/core/l10n/Messages.java >=================================================================== >--- src/org/eclipse/mtj/internal/core/l10n/Messages.java (revision 1344) >+++ src/org/eclipse/mtj/internal/core/l10n/Messages.java (working copy) >@@ -7,7 +7,8 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * David Marques (Motorola) - Initial version >+ * David Marques (Motorola) - Initial version >+ * Fernando Rocha (Motorola) - Add new message unableToCreateL10nFile [Bug 261873] > */ > package org.eclipse.mtj.internal.core.l10n; > >@@ -21,7 +22,8 @@ > */ > public class Messages extends NLS { > >- public static String L10nBuilder_BuildingLocalizationData; >+ public static String L10nApi_unableToCreateL10nFile; >+ public static String L10nBuilder_BuildingLocalizationData; > public static String L10nBuilder_clean_CleaningOldProperties; > public static String L10nBuilder_InvalidModel; > public static String L10nBuilder_ErrorParsingLocalizationData; >Index: src/org/eclipse/mtj/internal/core/l10n/messages.properties >=================================================================== >--- src/org/eclipse/mtj/internal/core/l10n/messages.properties (revision 1344) >+++ src/org/eclipse/mtj/internal/core/l10n/messages.properties (working copy) >@@ -1,3 +1,4 @@ >+L10nApi_unableToCreateL10nFile=Unable to resolve Localization Data location > L10nBuilder_BuildingLocalizationData=Building Localization Data > L10nBuilder_clean_CleaningOldProperties=Cleaning old properties > L10nBuilder_InvalidModel=Localization Model is not valid. >Index: src/org/eclipse/mtj/internal/core/l10n/L10nApi.java >=================================================================== >--- src/org/eclipse/mtj/internal/core/l10n/L10nApi.java (revision 1344) >+++ src/org/eclipse/mtj/internal/core/l10n/L10nApi.java (working copy) >@@ -7,15 +7,17 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * David Marques (Motorola) - Initial version >- * David Marques (Motorola) - Fixing propeties folder path >- * David Marques (Motorola) - Removing old classes from L10n API >- * upon API creation. >- * David Marques (Motorola) - Generating keys on upper case. >- * David Marques (Motorola) - Refactoring to support default locale. >+ * David Marques (Motorola) - Initial version >+ * David Marques (Motorola) - Fixing propeties folder path >+ * David Marques (Motorola) - Removing old classes from L10n API >+ * upon API creation. >+ * David Marques (Motorola) - Generating keys on upper case. >+ * David Marques (Motorola) - Refactoring to support default locale. >+ * Fernando Rocha (Motorola) - Method for create the localization file [Bug 261873]. > */ > package org.eclipse.mtj.internal.core.l10n; > >+import java.io.IOException; > import java.io.InputStream; > import java.util.ArrayList; > import java.util.HashMap; >@@ -32,9 +34,12 @@ > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Path; > import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jface.text.Document; > import org.eclipse.mtj.core.MTJCore; > import org.eclipse.mtj.internal.core.text.IDocumentElementNode; > import org.eclipse.mtj.internal.core.text.l10n.L10nEntry; >@@ -85,10 +90,10 @@ > public static String buildL10nConstantsClass(IProject project, > IPackageFragment _package) throws CoreException { > InputStream stream = MTJCore.getResourceAsStream(new Path( >- "templates/L10nConstants.java.template")); >+ "templates/L10nConstants.java.template")); //$NON-NLS-1$ > if (stream == null) { > MTJStatusHandler.throwCoreException(IStatus.ERROR, -999, >- "Unable to load templates/L10nResources.java.template."); >+ "Unable to load templates/L10nResources.java.template."); //$NON-NLS-1$ > } > > StringBuffer localesBuffer = new StringBuffer(); >@@ -123,12 +128,12 @@ > Map<String, String> map = new HashMap<String, String>(); > String packName = _package.getElementName(); > if (packName != null && packName.length() > 0x00) { >- map.put(PACKAGE, NLS.bind("package {0};", packName)); >+ map.put(PACKAGE, NLS.bind("package {0};", packName)); //$NON-NLS-1$ > } else { > map.put(PACKAGE, Utils.EMPTY_STRING); > } >- map.put("locales", localesBuffer.toString()); >- map.put("keys", constntBuffer.toString()); >+ map.put("locales", localesBuffer.toString()); //$NON-NLS-1$ >+ map.put("keys", constntBuffer.toString()); //$NON-NLS-1$ > > StringBuffer buffer = new StringBuffer(Utils.getStreamContent(stream)); > String code = ReplaceableParametersProcessor.processReplaceableValues( >@@ -148,10 +153,10 @@ > public static String buildL10nResourcesClass(IPackageFragment _package, > IPath _properties, String _defaultLocale) throws CoreException { > InputStream stream = MTJCore.getResourceAsStream(new Path( >- "templates/L10nResources.java.template")); >+ "templates/L10nResources.java.template")); //$NON-NLS-1$ > if (stream == null) { > MTJStatusHandler.throwCoreException(IStatus.ERROR, -999, >- "Unable to load templates/L10nResources.java.template."); >+ "Unable to load templates/L10nResources.java.template."); //$NON-NLS-1$ > } > > Map<String, String> map = new HashMap<String, String>(); >@@ -158,7 +163,7 @@ > map.put(DESTINATION, _properties.removeFirstSegments(1).toString()); > String packName = _package.getElementName(); > if (packName != null && packName.length() > 0x00) { >- map.put(PACKAGE, NLS.bind("package {0};", packName)); >+ map.put(PACKAGE, NLS.bind("package {0};", packName)); //$NON-NLS-1$ > } else { > map.put(PACKAGE, Utils.EMPTY_STRING); > } >@@ -205,6 +210,35 @@ > } > > /** >+ * Creates a Localization Data file into the specified destination. >+ * >+ * @param _project target project. >+ * @param _properties destination folder. >+ * @param _package Class package name. >+ * @return true upon success, false otherwise. >+ * @throws IOException If any error occurs during class creation. >+ * @throws JavaModelException If any java model error occurs. >+ */ >+ public static boolean createLocalizationFile(IProject _project, IPath _properties, >+ IJavaElement _package) throws JavaModelException, IOException { >+ >+ L10nModel model = new L10nModel(new Document(), false); >+ L10nLocales locales = model.getLocales(); >+ locales.setDestination(_properties.toString()); >+ locales.setPackage(_package.getElementName()); >+ >+ IPath path = _project.getLocation().append("Localization Data"); //$NON-NLS-1$ >+ IFile file = _project.getWorkspace().getRoot().getFileForLocation(path); >+ if (file == null) { >+ throw new IOException(Messages.L10nApi_unableToCreateL10nFile); >+ } >+ model.setUnderlyingResource(file); >+ model.save(); >+ >+ return file.exists(); >+ } >+ >+ /** > * Writes a constant declaration. > * > * @param name constant name. >@@ -213,8 +247,8 @@ > */ > private static String writeStringConstantDeclaration(String name, > String value) { >- return NLS.bind("\t\tpublic static final String {0} = \"{1}\";\n", >- new String[] { name.replace("-", "_"), value }); >+ return NLS.bind("\t\tpublic static final String {0} = \"{1}\";\n", //$NON-NLS-1$ >+ new String[] { name.replace("-", "_"), value }); //$NON-NLS-1$ //$NON-NLS-2$ > } > > /** >Index: src/org/eclipse/mtj/internal/core/sdk/device/DeviceRegistry.java >=================================================================== >--- src/org/eclipse/mtj/internal/core/sdk/device/DeviceRegistry.java (revision 1344) >+++ src/org/eclipse/mtj/internal/core/sdk/device/DeviceRegistry.java (working copy) >@@ -12,6 +12,7 @@ > * standards > * Hugo Raniere (Motorola) - Storing default preverifier > * David Aragao (Motorola) - Fixing device removal. >+ * Fernando Rocha(Motorola) - Loading the default devices [Bug 261873]. > */ > package org.eclipse.mtj.internal.core.sdk.device; > >@@ -91,6 +92,11 @@ > private DeviceRegistry() { > super(); > listenerList = new ArrayList<IDeviceRegistryListener>(); >+ try { >+ this.load(); >+ } catch (PersistenceException e) { >+ e.printStackTrace(); >+ } > } > > /* (non-Javadoc) >#P org.eclipse.mtj.core.library >Index: .project >=================================================================== >--- .project (revision 0) >+++ .project (revision 0) >@@ -0,0 +1,11 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<projectDescription> >+ <name>org.eclipse.mtj.core.library</name> >+ <comment></comment> >+ <projects> >+ </projects> >+ <buildSpec> >+ </buildSpec> >+ <natures> >+ </natures> >+</projectDescription> >#P org.eclipse.mtj.ui >Index: src/org/eclipse/mtj/internal/ui/MTJUIMessages.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/MTJUIMessages.java (revision 1344) >+++ src/org/eclipse/mtj/internal/ui/MTJUIMessages.java (working copy) >@@ -453,7 +453,6 @@ > public static String LocalizationPage_text; > public static String LocalizationPage_title; > >- public static String LocalizationWizard_failed_createLocalizationFile; > public static String LocalizationWizard_window_title; > public static String LogAndDisplaySafeRunnable_handleException_message; > public static String LogAndDisplaySafeRunnable_handleException_title; >@@ -932,6 +931,12 @@ > > private static final String BUNDLE_NAME = "org.eclipse.mtj.internal.ui.messages"; //$NON-NLS-1$ > >+ public static final String MidletDefaultNameEnd = " MIDlet Suite"; //$NON-NLS-1$ >+ public static final String MidletDefaultVendor = "MIDlet Suite Vendor"; //$NON-NLS-1$ >+ public static final String MidletInitialVersion_1_0_0 = "1.0.0"; //$NON-NLS-1$ >+ public static final String MeConfigurationVersion = "CLDC-1.0"; //$NON-NLS-1$ >+ public static final String MeProfileVersion = "MIDP-2.1"; //$NON-NLS-1$ >+ > public static String LibraryPropertyPage_description; > > public static String LibraryPropertyPage_unsavedchanges_button_discard; >@@ -990,23 +995,45 @@ > public static String NewMidletProjectWizardPageOne_locationGroup_externalLocationRadio; > public static String NewMidletProjectWizardPageOne_locationGroup_projectLocation; > public static String NewMidletProjectWizardPageOne_locationGroup_workspaceLocationRadio; >+ public static String NewMidletProjectWizardPageOne_locationGroup_workingSetsButton; >+ public static String NewMidletProjectWizardPageOne_workingSetGroup_contents; >+ public static String NewMidletProjectWizardPageOne_workingSetGroup_selection; >+ public static String NewMidletProjectWizardPageOne_workingSetGroup_select_button; > public static String NewMidletProjectWizardPageOne_title; >+ >+ public static String NewMidletProjectWizardPageTwo_description; >+ public static String NewMidletProjectWizardPageTwo_propertiesGroup_contents; >+ public static String NewMidletProjectWizardPageTwo_propertiesGroup_midletName; >+ public static String NewMidletProjectWizardPageTwo_propertiesGroup_midletVendor; >+ public static String NewMidletProjectWizardPageTwo_propertiesGroup_midletVersion; >+ public static String NewMidletProjectWizardPageTwo_propertiesGroup_meConfiguration; >+ public static String NewMidletProjectWizardPageTwo_propertiesGroup_meProfile; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_contents; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_enablePreprocessing; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_enableLocalization; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_propertiesFolder; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_package; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_packageEmpty; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_packageUpperCase; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_packageError; >+ public static String NewMidletProjectWizardPageTwo_optionsGroup_enableJMUnit; >+ public static String NewMidletProjectWizardPageTwo_title; > >- public static String NewMidletProjectWizardPageTwo_changeToNewProject_errordialog_message; >- public static String NewMidletProjectWizardPageTwo_changeToNewProject_errordialog_title; >- public static String NewMidletProjectWizardPageTwo_createBackup_error_1; >- public static String NewMidletProjectWizardPageTwo_createBackup_error_2; >- public static String NewMidletProjectWizardPageTwo_doRemoveProject_taskname; >- public static String NewMidletProjectWizardPageTwo_performFinish_monitor_taskname; >- public static String NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_message; >- public static String NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_title; >- public static String NewMidletProjectWizardPageTwo_restoreExistingFiles_problem_restoring_dotclasspath; >- public static String NewMidletProjectWizardPageTwo_restoreExistingFiles_problem_restoring_dotproject; >- public static String NewMidletProjectWizardPageTwo_updateProject_errordialog_message; >- public static String NewMidletProjectWizardPageTwo_updateProject_errordialog_title; >- public static String NewMidletProjectWizardPageTwo_updateProject_fail_read_metadata; >- public static String NewMidletProjectWizardPageTwo_updateProject_monitor_buildpath_name; >- public static String NewMidletProjectWizardPageTwo_updateProject_taskname; >+ public static String NewMidletProjectWizardPageThree_changeToNewProject_errordialog_message; >+ public static String NewMidletProjectWizardPageThree_changeToNewProject_errordialog_title; >+ public static String NewMidletProjectWizardPageThree_createBackup_error_1; >+ public static String NewMidletProjectWizardPageThree_createBackup_error_2; >+ public static String NewMidletProjectWizardPageThree_doRemoveProject_taskname; >+ public static String NewMidletProjectWizardPageThree_performFinish_monitor_taskname; >+ public static String NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_message; >+ public static String NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_title; >+ public static String NewMidletProjectWizardPageThree_restoreExistingFiles_problem_restoring_dotclasspath; >+ public static String NewMidletProjectWizardPageThree_restoreExistingFiles_problem_restoring_dotproject; >+ public static String NewMidletProjectWizardPageThree_updateProject_errordialog_message; >+ public static String NewMidletProjectWizardPageThree_updateProject_errordialog_title; >+ public static String NewMidletProjectWizardPageThree_updateProject_fail_read_metadata; >+ public static String NewMidletProjectWizardPageThree_updateProject_monitor_buildpath_name; >+ public static String NewMidletProjectWizardPageThree_updateProject_taskname; > > public static String NewMidletProjectWizardPageLibrary_title; > public static String NewMidletProjectWizardPageLibrary_description; >@@ -1021,6 +1048,7 @@ > public static String NewMidletProjectWizardPageLibrary_HintTextGroup_title; > > public static String ConfigurationSection_Description; >+ > > static { > // initialize resource bundle >Index: src/org/eclipse/mtj/internal/ui/wizards/l10n/LocalizationWizard.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/l10n/LocalizationWizard.java (revision 1344) >+++ src/org/eclipse/mtj/internal/ui/wizards/l10n/LocalizationWizard.java (working copy) >@@ -10,7 +10,8 @@ > * David Marques (Motorola) - Initial version > * David Marques (Motorola) - Adding canFinish method. > * David Marques (Motorola) - Refactoring Localization API. >- * David Marques (Motorola) - Refactoring to use L10nModel. >+ * David Marques (Motorola) - Refactoring to use L10nModel. >+ * Fernando Rocha(Motorola) - Refactoring Localization API. > */ > package org.eclipse.mtj.internal.ui.wizards.l10n; > >@@ -16,11 +17,8 @@ > > import java.io.IOException; > >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IResource; > import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaProject; >@@ -25,12 +23,8 @@ > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.IPackageFragment; >-import org.eclipse.jdt.core.JavaModelException; >-import org.eclipse.jface.text.Document; > import org.eclipse.jface.wizard.Wizard; > import org.eclipse.mtj.internal.core.l10n.L10nApi; >-import org.eclipse.mtj.internal.core.text.l10n.L10nLocales; >-import org.eclipse.mtj.internal.core.text.l10n.L10nModel; > import org.eclipse.mtj.internal.ui.MTJUIMessages; > > /** >@@ -87,7 +81,7 @@ > > if (targetPack instanceof IPackageFragment) { > try { >- result = createLocalizationFile(properties >+ result = L10nApi.createLocalizationFile(jProject.getProject(), properties > .getProjectRelativePath(), targetPack); > jProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, > new NullProgressMonitor()); >@@ -105,34 +99,4 @@ > } > return result; > } >- >- /** >- * Creates a Localization Data file into the specified destination. >- * >- * @param _properties destination folder. >- * @param _package Class package name. >- * @return true upon success, false otherwise. >- * @throws IOException If any error occurs during class creation. >- * @throws JavaModelException If any java model error occurs. >- */ >- private boolean createLocalizationFile(IPath _properties, >- IJavaElement _package) throws JavaModelException, IOException { >- >- L10nModel model = new L10nModel(new Document(), false); >- L10nLocales locales = model.getLocales(); >- locales.setDestination(_properties.toString()); >- locales.setPackage(_package.getElementName()); >- >- IProject project = jProject.getProject(); >- IPath path = project.getLocation().append("Localization Data"); //$NON-NLS-1$ >- IFile file = project.getWorkspace().getRoot().getFileForLocation(path); >- if (file == null) { >- throw new IOException( >- MTJUIMessages.LocalizationWizard_failed_createLocalizationFile); >- } >- model.setUnderlyingResource(file); >- model.save(); >- >- return file.exists(); >- } > } >Index: src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageTwo.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageTwo.java (revision 1344) >+++ src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageTwo.java (working copy) >@@ -1,878 +0,0 @@ >-/** >- * Copyright (c) 2008 Motorola. >- * >- * 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: >- * Diego Sandin (Motorola) - Initial version >- * Feng Wang (Sybase) - Add configurations into Metadata for Multi-Configs >- * support. >- * Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874] >- */ >-package org.eclipse.mtj.internal.ui.wizards.projects; >- >-import java.io.File; >-import java.io.FileInputStream; >-import java.io.FileOutputStream; >-import java.io.IOException; >-import java.io.InputStream; >-import java.io.OutputStream; >-import java.lang.reflect.InvocationTargetException; >-import java.net.URI; >-import java.net.URISyntaxException; >-import java.util.ArrayList; >-import java.util.HashSet; >-import java.util.List; >-import java.util.Map; >- >-import org.eclipse.core.filesystem.EFS; >-import org.eclipse.core.filesystem.IFileInfo; >-import org.eclipse.core.filesystem.IFileStore; >-import org.eclipse.core.resources.IFolder; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.resources.IResourceStatus; >-import org.eclipse.core.resources.IWorkspaceDescription; >-import org.eclipse.core.resources.IWorkspaceRoot; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.Assert; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.NullProgressMonitor; >-import org.eclipse.core.runtime.OperationCanceledException; >-import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.Preferences; >-import org.eclipse.core.runtime.Status; >-import org.eclipse.core.runtime.SubProgressMonitor; >-import org.eclipse.jdt.core.IClasspathEntry; >-import org.eclipse.jdt.core.IJavaProject; >-import org.eclipse.jdt.core.JavaCore; >-import org.eclipse.jdt.ui.PreferenceConstants; >-import org.eclipse.jdt.ui.wizards.JavaCapabilityConfigurationPage; >-import org.eclipse.jface.dialogs.ErrorDialog; >-import org.eclipse.jface.operation.IRunnableWithProgress; >-import org.eclipse.jface.preference.IPreferenceStore; >-import org.eclipse.mtj.core.MTJCore; >-import org.eclipse.mtj.core.project.IMetaData; >-import org.eclipse.mtj.core.project.ProjectType; >-import org.eclipse.mtj.core.project.runtime.MTJRuntimeList; >-import org.eclipse.mtj.core.sdk.device.IDevice; >-import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice; >-import org.eclipse.mtj.internal.core.IMTJCoreConstants; >-import org.eclipse.mtj.internal.core.build.preprocessor.PreprocessorBuilder; >-import org.eclipse.mtj.internal.core.project.midp.JavaMEClasspathContainer; >-import org.eclipse.mtj.internal.core.project.midp.MidletSuiteFactory; >-import org.eclipse.mtj.internal.ui.IMTJUIConstants; >-import org.eclipse.mtj.internal.ui.MTJUIMessages; >-import org.eclipse.mtj.internal.ui.util.ExceptionHandler; >-import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; >- >-/** >- * The New MIDlet Project Java Capability Wizard Page allows the user to >- * configure the build path and output location of the MIDlet Project. As >- * addition to the {@link JavaCapabilityConfigurationPage}, the wizard page does >- * an early project creation (so that linked folders can be defined). >- * >- * @author Diego Madruga Sandin >- * @since 0.9 >- */ >-public class NewMidletProjectWizardPageTwo extends >- JavaCapabilityConfigurationPage { >- >- private static final String FILENAME_CLASSPATH = ".classpath"; //$NON-NLS-1$ >- >- private static final String FILENAME_PROJECT = ".project"; //$NON-NLS-1$ >- >- /** >- * @param projectName >- * @param location >- * @return >- */ >- private static URI getRealLocation(String projectName, URI location) { >- if (location == null) { // inside workspace >- try { >- URI rootLocation = MTJCore.getWorkspace().getRoot() >- .getLocationURI(); >- >- location = new URI(rootLocation.getScheme(), null, Path >- .fromPortableString(rootLocation.getPath()).append( >- projectName).toString(), null); >- } catch (URISyntaxException e) { >- Assert.isTrue(false, "Can't happen"); //$NON-NLS-1$ >- } >- } >- return location; >- } >- >- public Boolean isAutobuild; >- private IProject currProject; >- private URI currProjectLocation; >- private File fDotClasspathBackup; >- private File fDotProjectBackup; >- private NewMidletProjectWizardPageOne firstPage; >- private HashSet<IFileStore> fOrginalFolders; >- >- private boolean keepContent; >- >- private NewMidletProjectWizardPageLibrary pageLibrary; >- >- /** >- * Creates a new New MIDlet Project Java Capability Wizard Page. >- * >- * @param workbench >- */ >- public NewMidletProjectWizardPageTwo(NewMidletProjectWizardPageOne page, >- NewMidletProjectWizardPageLibrary pageLibrary) { >- this.currProjectLocation = null; >- this.currProject = null; >- this.firstPage = page; >- this.pageLibrary = pageLibrary; >- isAutobuild = null; >- } >- >- /** >- * Called from the wizard on cancel. >- */ >- public void performCancel() { >- if (currProject != null) { >- removeProvisonalProject(); >- } >- } >- >- /** >- * Called from the wizard on finish. >- * >- * @param monitor the progress monitor >- * @throws CoreException thrown when the project creation or configuration >- * failed >- * @throws InterruptedException thrown when the user canceled the project >- * creation >- */ >- @SuppressWarnings("unchecked") >- public void performFinish(IProgressMonitor monitor) throws CoreException, >- InterruptedException { >- try { >- >- monitor >- .beginTask( >- MTJUIMessages.NewMidletProjectWizardPageTwo_performFinish_monitor_taskname, >- 3); >- if (currProject == null) { >- updateProject(new SubProgressMonitor(monitor, 1)); >- } >- >- configureJavaProject(new SubProgressMonitor(monitor, 2)); >- >- if (!keepContent) { >- IJavaProject project = JavaCore.create(currProject); >- Map options = project.getOptions(false); >- >- // complete compliance options >- project.setOptions(options); >- } >- >- } finally { >- monitor.done(); >- currProject = null; >- if (isAutobuild != null) { >- IWorkspaceDescription description = ResourcesPlugin >- .getWorkspace().getDescription(); >- description.setAutoBuilding(isAutobuild.booleanValue()); >- MTJCore.getWorkspace().setDescription(description); >- isAutobuild = null; >- } >- } >- } >- >- /* >- * (non-Javadoc) >- * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean) >- */ >- @Override >- public void setVisible(boolean visible) { >- boolean isShownFirstTime = visible && (currProject == null); >- if (visible) { >- if (isShownFirstTime) { >- // entering from the first page >- createProvisonalProject(); >- } >- } else { >- if ((getContainer().getCurrentPage() == firstPage) >- || (getContainer().getCurrentPage() == pageLibrary)) { >- // leaving back to previous pages >- removeProvisonalProject(); >- } >- } >- super.setVisible(visible); >- if (isShownFirstTime) { >- setFocus(); >- } >- } >- >- /** >- * Update the java configuration before making the page visible. >- */ >- public void updateConfiguration() { >- String projectName = firstPage.getProjectName(); >- >- currProject = MTJCore.getWorkspace().getRoot().getProject( >- projectName); >- >- IJavaProject javaProject = JavaCore.create(currProject); >- IPath projectPath = currProject.getFullPath(); >- >- // Initialize the classpath entries using the source directories >- // and classpath container >- ArrayList<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>(); >- entryList.add(getSrcPathEntry(projectPath)); >- addResourcesDirectoryIfRequested(entryList, currProject); >- IPath entryPath = new Path(JavaMEClasspathContainer.JAVAME_CONTAINER >- + "/" + firstPage.getSelectedDevice()); //$NON-NLS-1$ >- >- entryList.add(JavaCore.newContainerEntry(entryPath)); >- >- IClasspathEntry[] entries = entryList >- .toArray(new IClasspathEntry[entryList.size()]); >- >- init(javaProject, null, entries, false); >- } >- >- /** >- * Add a resources directory as a source path entry if the user preferences >- * requested. >- * >- * @param entryList >- * @param project >- */ >- private void addResourcesDirectoryIfRequested( >- List<IClasspathEntry> entryList, IProject project) { >- Preferences prefs = MTJCore.getMTJCore().getPluginPreferences(); >- >- if (useSourceAndBinaryFolders() >- && prefs.getBoolean(IMTJCoreConstants.PREF_USE_RESOURCES_DIR)) { >- // Create the resources directory if it doesn't already exist >- String resDirName = prefs >- .getString(IMTJCoreConstants.PREF_RESOURCES_DIR); >- IFolder resFolder = project.getFolder(resDirName); >- >- if (!resFolder.exists()) { >- try { >- resFolder.create(true, true, new NullProgressMonitor()); >- } catch (CoreException e) { >- e.printStackTrace(); >- } >- } >- >- // Add it as a source folder to the java project >- entryList.add(JavaCore.newSourceEntry(resFolder.getFullPath())); >- } >- } >- >- private IStatus changeToNewProject() { >- class UpdateRunnable implements IRunnableWithProgress { >- public IStatus infoStatus = Status.OK_STATUS; >- >- public void run(IProgressMonitor monitor) >- throws InvocationTargetException, InterruptedException { >- try { >- if (isAutobuild == null) { >- IWorkspaceDescription description = ResourcesPlugin >- .getWorkspace().getDescription(); >- isAutobuild = Boolean.valueOf(description >- .isAutoBuilding()); >- description.setAutoBuilding(false); >- MTJCore.getWorkspace().setDescription( >- description); >- } >- infoStatus = updateProject(monitor); >- } catch (CoreException e) { >- throw new InvocationTargetException(e); >- } catch (OperationCanceledException e) { >- throw new InterruptedException(); >- } finally { >- monitor.done(); >- } >- } >- } >- >- UpdateRunnable op = new UpdateRunnable(); >- try { >- getContainer().run(true, false, >- new WorkspaceModifyDelegatingOperation(op)); >- >- return op.infoStatus; >- } catch (InvocationTargetException e) { >- >- final String title = MTJUIMessages.NewMidletProjectWizardPageTwo_changeToNewProject_errordialog_title; >- final String message = MTJUIMessages.NewMidletProjectWizardPageTwo_changeToNewProject_errordialog_message; >- ExceptionHandler.handle(e, getShell(), title, message); >- >- } catch (InterruptedException e) { >- // cancel pressed >- } >- return null; >- } >- >- /** >- * @param source >- * @param target >- * @param monitor >- * @throws IOException >- * @throws CoreException >- */ >- private void copyFile(File source, IFileStore target, >- IProgressMonitor monitor) throws IOException, CoreException { >- FileInputStream is = new FileInputStream(source); >- OutputStream os = target.openOutputStream(EFS.NONE, monitor); >- copyFile(is, os); >- } >- >- /** >- * @param source >- * @param target >- * @throws IOException >- * @throws CoreException >- */ >- private void copyFile(IFileStore source, File target) throws IOException, >- CoreException { >- InputStream is = source.openInputStream(EFS.NONE, null); >- FileOutputStream os = new FileOutputStream(target); >- copyFile(is, os); >- } >- >- /** >- * @param is >- * @param os >- * @throws IOException >- */ >- private void copyFile(InputStream is, OutputStream os) throws IOException { >- try { >- byte[] buffer = new byte[8192]; >- while (true) { >- int bytesRead = is.read(buffer); >- if (bytesRead == -1) { >- break; >- } >- >- os.write(buffer, 0, bytesRead); >- } >- } finally { >- try { >- is.close(); >- } finally { >- os.close(); >- } >- } >- } >- >- /** >- * @param source >- * @param name >- * @return >- * @throws CoreException >- */ >- private File createBackup(IFileStore source, String name) >- throws CoreException { >- try { >- File bak = File.createTempFile("eclipse-" + name, ".bak"); //$NON-NLS-1$//$NON-NLS-2$ >- copyFile(source, bak); >- return bak; >- } catch (IOException e) { >- IStatus status = new Status( >- IStatus.ERROR, >- IMTJUIConstants.PLUGIN_ID, >- IStatus.ERROR, >- MTJUIMessages.NewMidletProjectWizardPageTwo_createBackup_error_1 >- + name >- + MTJUIMessages.NewMidletProjectWizardPageTwo_createBackup_error_2, >- e); >- throw new CoreException(status); >- } >- } >- >- private void deleteProjectFile(URI projectLocation) throws CoreException { >- IFileStore file = EFS.getStore(projectLocation); >- if (file.fetchInfo().exists()) { >- IFileStore projectFile = file.getChild(FILENAME_PROJECT); >- if (projectFile.fetchInfo().exists()) { >- projectFile.delete(EFS.NONE, null); >- } >- } >- } >- >- private final void doRemoveProject(IProgressMonitor monitor) >- throws InvocationTargetException { >- final boolean noProgressMonitor = (currProjectLocation == null); // inside >- // workspace >- if ((monitor == null) || noProgressMonitor) { >- monitor = new NullProgressMonitor(); >- } >- monitor >- .beginTask( >- MTJUIMessages.NewMidletProjectWizardPageTwo_doRemoveProject_taskname, >- 3); >- try { >- try { >- URI projLoc = currProject.getLocationURI(); >- >- boolean removeContent = !keepContent >- && currProject.isSynchronized(IResource.DEPTH_INFINITE); >- if ((!removeContent) >- && (currProject.getProject().getFullPath().toFile() >- .exists())) { >- restoreExistingFolders(projLoc); >- } >- currProject.delete(removeContent, false, >- new SubProgressMonitor(monitor, 2)); >- >- MidletSuiteFactory.removeMidletSuiteProject(getJavaProject()); >- >- restoreExistingFiles(projLoc, >- new SubProgressMonitor(monitor, 1)); >- } finally { >- IWorkspaceDescription description = ResourcesPlugin >- .getWorkspace().getDescription(); >- description.setAutoBuilding(isAutobuild.booleanValue()); >- MTJCore.getWorkspace().setDescription(description); >- // isAutobuild must be set >- isAutobuild = null; >- } >- } catch (CoreException e) { >- throw new InvocationTargetException(e); >- } finally { >- monitor.done(); >- currProject = null; >- keepContent = false; >- } >- } >- >- /** >- * Get the source path for the project taking into account the new project >- * preferences that the user has specified. >- * >- * @param projectPath >- * @return >- */ >- private IPath getSrcPath(IPath projectPath) { >- IPath srcPath = projectPath; >- >- if (useSourceAndBinaryFolders()) { >- IPreferenceStore store = PreferenceConstants.getPreferenceStore(); >- String srcPathName = store >- .getString(PreferenceConstants.SRCBIN_SRCNAME); >- srcPath = projectPath.append(srcPathName); >- } >- >- return srcPath; >- } >- >- /** >- * Return an IClasspathEntry for the source path. >- * >- * @param projectPath >- * @return >- */ >- private IClasspathEntry getSrcPathEntry(IPath projectPath) { >- IPath srcPath = getSrcPath(projectPath); >- >- // Set up exclusions for the verified and deployed directories >- // if the source and project directories are the same >- IPath[] exclusions = null; >- if (srcPath.equals(projectPath)) { >- exclusions = new IPath[3]; >- exclusions[0] = new Path(MTJCore.getDeploymentDirectoryName() + "/"); //$NON-NLS-1$ >- exclusions[1] = new Path(IMTJCoreConstants.TEMP_FOLDER_NAME + "/"); //$NON-NLS-1$ >- exclusions[2] = new Path(PreprocessorBuilder.PROCESSED_DIRECTORY >- + "/"); //$NON-NLS-1$ >- } else { >- exclusions = new IPath[0]; >- } >- >- return JavaCore.newSourceEntry(srcPath, exclusions); >- } >- >- /** >- * @param realLocation >- * @return >- * @throws CoreException >- */ >- private boolean hasExistingContent(URI realLocation) throws CoreException { >- IFileStore file = EFS.getStore(realLocation); >- return file.fetchInfo().exists(); >- } >- >- private void rememberExisitingFolders(URI projectLocation) { >- fOrginalFolders = new HashSet<IFileStore>(); >- >- try { >- IFileStore[] children = EFS.getStore(projectLocation).childStores( >- EFS.NONE, null); >- for (IFileStore child : children) { >- IFileInfo info = child.fetchInfo(); >- if (info.isDirectory() && info.exists() >- && !fOrginalFolders.contains(child.getName())) { >- fOrginalFolders.add(child); >- } >- } >- } catch (CoreException e) { >- final String title = MTJUIMessages.NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_title; >- final String message = MTJUIMessages.NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_message; >- ExceptionHandler.handle(e, getShell(), title, message); >- } >- } >- >- private void rememberExistingFiles(URI projectLocation) >- throws CoreException { >- fDotProjectBackup = null; >- fDotClasspathBackup = null; >- >- IFileStore file = EFS.getStore(projectLocation); >- if (file.fetchInfo().exists()) { >- IFileStore projectFile = file.getChild(FILENAME_PROJECT); >- if (projectFile.fetchInfo().exists()) { >- fDotProjectBackup = createBackup(projectFile, "project-desc"); //$NON-NLS-1$ >- } >- IFileStore classpathFile = file.getChild(FILENAME_CLASSPATH); >- if (classpathFile.fetchInfo().exists()) { >- fDotClasspathBackup = createBackup(classpathFile, >- "classpath-desc"); //$NON-NLS-1$ >- } >- } >- } >- >- private void restoreExistingFiles(URI projectLocation, >- IProgressMonitor monitor) throws CoreException { >- int ticks = ((fDotProjectBackup != null ? 1 : 0) + (fDotClasspathBackup != null ? 1 >- : 0)) * 2; >- monitor.beginTask("", ticks); //$NON-NLS-1$ >- try { >- IFileStore projectFile = EFS.getStore(projectLocation).getChild( >- FILENAME_PROJECT); >- projectFile.delete(EFS.NONE, new SubProgressMonitor(monitor, 1)); >- if (fDotProjectBackup != null) { >- copyFile(fDotProjectBackup, projectFile, >- new SubProgressMonitor(monitor, 1)); >- } >- } catch (IOException e) { >- IStatus status = new Status( >- IStatus.ERROR, >- IMTJUIConstants.PLUGIN_ID, >- IStatus.ERROR, >- MTJUIMessages.NewMidletProjectWizardPageTwo_restoreExistingFiles_problem_restoring_dotproject, >- e); >- throw new CoreException(status); >- } >- try { >- IFileStore classpathFile = EFS.getStore(projectLocation).getChild( >- FILENAME_CLASSPATH); >- classpathFile.delete(EFS.NONE, new SubProgressMonitor(monitor, 1)); >- if (fDotClasspathBackup != null) { >- copyFile(fDotClasspathBackup, classpathFile, >- new SubProgressMonitor(monitor, 1)); >- } >- } catch (IOException e) { >- IStatus status = new Status( >- IStatus.ERROR, >- IMTJUIConstants.PLUGIN_ID, >- IStatus.ERROR, >- MTJUIMessages.NewMidletProjectWizardPageTwo_restoreExistingFiles_problem_restoring_dotclasspath, >- e); >- throw new CoreException(status); >- } >- } >- >- private void restoreExistingFolders(URI projectLocation) { >- try { >- IFileStore[] children = EFS.getStore(projectLocation).childStores( >- EFS.NONE, null); >- for (IFileStore child : children) { >- IFileInfo info = child.fetchInfo(); >- if (info.isDirectory() && info.exists() >- && !fOrginalFolders.contains(child)) { >- child.delete(EFS.NONE, null); >- fOrginalFolders.remove(child); >- } >- } >- >- for (IFileStore fileStore : fOrginalFolders) { >- IFileStore deleted = fileStore; >- deleted.mkdir(EFS.NONE, null); >- } >- } catch (CoreException e) { >- final String title = MTJUIMessages.NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_title; >- final String message = MTJUIMessages.NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_message; >- ExceptionHandler.handle(e, getShell(), title, message); >- } >- } >- >- /** >- * @param monitor >- * @return >- * @throws CoreException >- * @throws InterruptedException >- */ >- private final IStatus updateProject(IProgressMonitor monitor) >- throws CoreException, InterruptedException { >- IStatus result = Status.OK_STATUS; >- if (monitor == null) { >- monitor = new NullProgressMonitor(); >- } >- try { >- monitor >- .beginTask( >- MTJUIMessages.NewMidletProjectWizardPageTwo_updateProject_taskname, >- 7); >- if (monitor.isCanceled()) { >- throw new OperationCanceledException(); >- } >- >- String projectName = firstPage.getProjectName(); >- >- currProject = MTJCore.getWorkspace().getRoot().getProject( >- projectName); >- currProjectLocation = firstPage.getProjectLocationURI(); >- >- URI realLocation = getRealLocation(projectName, currProjectLocation); >- keepContent = hasExistingContent(realLocation); >- >- if (monitor.isCanceled()) { >- throw new OperationCanceledException(); >- } >- >- if (keepContent) { >- rememberExistingFiles(realLocation); >- rememberExisitingFolders(realLocation); >- } >- >- if (monitor.isCanceled()) { >- throw new OperationCanceledException(); >- } >- >- try { >- >- JavaCapabilityConfigurationPage.createProject(currProject, >- firstPage.getProjectLocationURI(), >- new SubProgressMonitor(monitor, 1)); >- >- // Set the device into the project metadata to make >- // the java project creation happy. >- IDevice device = firstPage.getSelectedDevice(); >- MTJRuntimeList configurations = firstPage.getConfigurations(); >- // Make up Metadata and save it. >- IMetaData metadata = MTJCore.createMetaData(currProject, >- ProjectType.MIDLET_SUITE); >- metadata.setMTJRuntimeList(configurations); >- try { >- metadata.saveMetaData(); >- } catch (CoreException e) { >- throw new InvocationTargetException(e); >- } >- >- updateConfiguration(); >- >- // Get the java nature >- try { >- IRunnableWithProgress progress = super.getRunnable(); >- progress.run(monitor); >- } catch (Throwable e) { >- throw new CoreException(new Status( >- IResourceStatus.FAILED_READ_METADATA, "", e //$NON-NLS-1$ >- .getMessage())); >- } >- >- // Get the J2ME nature and metadata set up >- String jadFileName = firstPage.getJadFileName(); >- >- IJavaProject javaProject = super.getJavaProject(); >- >- MidletSuiteFactory.MidletSuiteCreationRunnable runnable = MidletSuiteFactory >- .getMidletSuiteCreationRunnable(currProject, >- javaProject, (IMIDPDevice) device, jadFileName); >- >- runnable.setPreprocessingEnable(firstPage >- .isPreprocessingEnabled()); >- >- runnable.run(monitor); >- >- } catch (CoreException e) { >- if (e.getStatus().getCode() == IResourceStatus.FAILED_READ_METADATA) { >- result = new Status( >- IStatus.INFO, >- IMTJUIConstants.PLUGIN_ID, >- MTJUIMessages.NewMidletProjectWizardPageTwo_updateProject_fail_read_metadata); >- >- deleteProjectFile(realLocation); >- if (currProject.exists()) { >- currProject.delete(true, null); >- } >- >- createProject(currProject, currProjectLocation, null); >- } else { >- throw e; >- } >- } catch (Throwable e) { >- throw new CoreException(Status.CANCEL_STATUS); >- } >- >- if (monitor.isCanceled()) { >- throw new OperationCanceledException(); >- } >- >- initializeBuildPath(JavaCore.create(currProject), >- new SubProgressMonitor(monitor, 2)); >- >- configureJavaProject(new SubProgressMonitor(monitor, 3)); >- // create the Java project to allow the use of the new source folder >- // page >- } catch (Exception e) { >- throw new CoreException(Status.CANCEL_STATUS); >- } finally { >- monitor.done(); >- } >- >- return result; >- } >- >- /** >- * Return a boolean indicating whether there will be separate source and >- * binary folders in the project. >- * >- * @return >- */ >- private boolean useSourceAndBinaryFolders() { >- IPreferenceStore store = PreferenceConstants.getPreferenceStore(); >- return store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ); >- } >- >- /** >- * Creates the provisional project on which the wizard is working on. The >- * provisional project is typically created when the page is entered the >- * first time. The early project creation is required to configure linked >- * folders. >- * >- * @return the provisional project >- */ >- protected IProject createProvisonalProject() { >- IStatus status = changeToNewProject(); >- if ((status != null) && !status.isOK()) { >- ErrorDialog.openError(getShell(), "createProvisonalProject", null, //$NON-NLS-1$ >- status); >- } >- return currProject; >- } >- >- /** >- * Evaluates the new build path and output folder according to the settings >- * on the first page. The resulting build path is set by calling >- * {@link #init(IJavaProject, IPath, IClasspathEntry[], boolean)}. Clients >- * can override this method. >- * >- * @param javaProject the new project which is already created when this >- * method is called. >- * @param monitor the progress monitor >- * @throws CoreException thrown when initializing the build path failed >- */ >- protected void initializeBuildPath(IJavaProject javaProject, >- IProgressMonitor monitor) throws CoreException { >- if (monitor == null) { >- monitor = new NullProgressMonitor(); >- } >- monitor >- .beginTask( >- MTJUIMessages.NewMidletProjectWizardPageTwo_updateProject_monitor_buildpath_name, >- 2); >- >- try { >- IClasspathEntry[] entries = null; >- IProject project = javaProject.getProject(); >- >- List<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>(); >- IWorkspaceRoot root = project.getWorkspace().getRoot(); >- >- IClasspathEntry sourceClasspathEntry = getSrcPathEntry(project >- .getFullPath()); >- >- if (sourceClasspathEntry.getPath() != project.getFullPath()) { >- >- IFolder folder = root.getFolder(sourceClasspathEntry.getPath()); >- >- if (!folder.exists()) { >- folder.create(true, true, >- new SubProgressMonitor(monitor, 1)); >- } >- } >- cpEntries.add(sourceClasspathEntry); >- addResourcesDirectoryIfRequested(cpEntries, project); >- >- IPath entryPath = new Path( >- JavaMEClasspathContainer.JAVAME_CONTAINER + "/" //$NON-NLS-1$ >- + firstPage.getSelectedDevice()); >- cpEntries.add(JavaCore.newContainerEntry(entryPath)); >- >- if (pageLibrary != null) { >- List<IPath> list = pageLibrary.getSelectedLibraries(); >- >- for (IPath path : list) { >- cpEntries.add(JavaCore.newContainerEntry(path, true)); >- } >- } >- >- entries = cpEntries.toArray(new IClasspathEntry[cpEntries.size()]); >- >- if (monitor.isCanceled()) { >- throw new OperationCanceledException(); >- } >- >- init(javaProject, getOutputLocation(), entries, true); >- } finally { >- monitor.done(); >- } >- } >- >- /** >- * Removes the provisional project. The provisional project is typically >- * removed when the user cancels the wizard or goes back to the first page. >- */ >- protected void removeProvisonalProject() { >- if (!currProject.exists()) { >- currProject = null; >- return; >- } >- >- IRunnableWithProgress op = new IRunnableWithProgress() { >- public void run(IProgressMonitor monitor) >- throws InvocationTargetException, InterruptedException { >- doRemoveProject(monitor); >- } >- }; >- >- try { >- getContainer().run(true, true, >- new WorkspaceModifyDelegatingOperation(op)); >- } catch (InvocationTargetException e) { >- >- final String title = MTJUIMessages.NewMidletProjectWizardPageTwo_updateProject_errordialog_title; >- final String message = MTJUIMessages.NewMidletProjectWizardPageTwo_updateProject_errordialog_message; >- ExceptionHandler.handle(e, getShell(), title, message); >- >- } catch (InterruptedException e) { >- // cancel pressed >- } >- } >- >- /* >- * (non-Javadoc) >- * @see >- * org.eclipse.jdt.ui.wizards.JavaCapabilityConfigurationPage#useNewSourcePage >- * () >- */ >- @Override >- protected final boolean useNewSourcePage() { >- return true; >- } >-} >Index: src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizard.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizard.java (revision 1344) >+++ src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizard.java (working copy) >@@ -11,6 +11,7 @@ > * Diego Sandin (Motorola) - Added library selection page > * Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874] > * David Marques (Motorola) - Refactoring build.properties >+ * Fernando Rocha (Motorola)- Add a page for project properties [Bug 261873] > */ > package org.eclipse.mtj.internal.ui.wizards.projects; > >@@ -54,8 +55,9 @@ > private IConfigurationElement configElement; > > private NewMidletProjectWizardPageOne firstPage; >+ private NewMidletProjectWizardPageProperties propertiesPage; > private NewMidletProjectWizardPageLibrary libraryPage; >- private NewMidletProjectWizardPageTwo secondPage; >+ private NewMidletProjectWizardPageJavaSettings javaSettingsPage; > > private IWorkbench workbench; > >@@ -63,7 +65,7 @@ > * Construct a new MIDLet project wizard. > */ > public NewMidletProjectWizard() { >- this(null, null, null); >+ this(null, null, null, null); > } > > /** >@@ -71,10 +73,12 @@ > * > * @param pageOne the first wizard page > * @param pageTwo the second wizard page >+ * @param pageThree the third wizard page > * @param libraryPage the library wizard page > */ > public NewMidletProjectWizard(NewMidletProjectWizardPageOne pageOne, >- NewMidletProjectWizardPageTwo pageTwo, >+ NewMidletProjectWizardPageProperties pageTwo, >+ NewMidletProjectWizardPageJavaSettings pageThree, > NewMidletProjectWizardPageLibrary libraryPage) { > > ImageDescriptor descriptor = MTJUIPluginImages.DESC_NEW_PROJECT; >@@ -82,7 +86,8 @@ > setWindowTitle(MTJUIMessages.NewMidletProjectWizard_wizard_title); > > this.firstPage = pageOne; >- this.secondPage = pageTwo; >+ this.propertiesPage = pageTwo; >+ this.javaSettingsPage = pageThree; > this.libraryPage = libraryPage; > } > >@@ -96,6 +101,11 @@ > firstPage = new NewMidletProjectWizardPageOne(); > } > addPage(firstPage); >+ >+ if(propertiesPage == null) { >+ propertiesPage = new NewMidletProjectWizardPageProperties(firstPage); >+ } >+ addPage(propertiesPage); > > if (libraryPage == null) { > libraryPage = new NewMidletProjectWizardPageLibrary(); >@@ -104,12 +114,12 @@ > if (libraryPage.isPageDisplayable()) { > addPage(libraryPage); > } >- >- if (secondPage == null) { >- secondPage = new NewMidletProjectWizardPageTwo(firstPage, >- libraryPage); >+ >+ if (javaSettingsPage == null) { >+ javaSettingsPage = new NewMidletProjectWizardPageJavaSettings(firstPage, >+ propertiesPage, libraryPage); > } >- addPage(secondPage); >+ addPage(javaSettingsPage); > > firstPage.init(getSelection(), getActivePart()); > } >@@ -130,7 +140,7 @@ > */ > @Override > public IJavaElement getCreatedElement() { >- return secondPage.getJavaProject(); >+ return javaSettingsPage.getJavaProject(); > } > > /* (non-Javadoc) >@@ -148,7 +158,7 @@ > */ > @Override > public boolean performCancel() { >- secondPage.performCancel(); >+ javaSettingsPage.performCancel(); > return super.performCancel(); > } > >@@ -166,7 +176,7 @@ > /* Open the Application Descriptor file */ > try { > IMidletSuiteProject midletSuiteProject = MidletSuiteFactory >- .getMidletSuiteProject(secondPage.getJavaProject()); >+ .getMidletSuiteProject(javaSettingsPage.getJavaProject()); > > IFile jadfile = midletSuiteProject > .getApplicationDescriptorFile(); >@@ -178,8 +188,8 @@ > } > > MTJBuildProperties buildProperties = MTJBuildProperties >- .getBuildProperties(midletSuiteProject); >- buildProperties.store(); >+ .getBuildProperties(midletSuiteProject); >+ buildProperties.store(); > } catch (Throwable e) { > MTJLogger > .log( >@@ -199,7 +209,6 @@ > String propertyName, Object data) { > configElement = cfig; > } >- > private IWorkbenchPart getActivePart() { > IWorkbenchWindow activeWindow = getWorkbench() > .getActiveWorkbenchWindow(); >@@ -221,7 +230,7 @@ > @Override > protected void finishPage(IProgressMonitor monitor) > throws InterruptedException, CoreException { >- secondPage.performFinish(monitor); // use the full progress monitor >+ javaSettingsPage.performFinish(monitor); // use the full progress monitor > } > > @Override >Index: src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageProperties.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageProperties.java (revision 0) >+++ src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageProperties.java (revision 0) >@@ -0,0 +1,412 @@ >+package org.eclipse.mtj.internal.ui.wizards.projects; >+ >+import java.util.HashMap; >+import java.util.Map; >+import java.util.Observable; >+import java.util.Observer; >+import java.util.regex.Matcher; >+import java.util.regex.Pattern; >+ >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.mtj.core.sdk.device.IAPI; >+import org.eclipse.mtj.internal.core.sdk.device.midp.Configuration; >+import org.eclipse.mtj.internal.core.sdk.device.midp.Profile; >+import org.eclipse.mtj.internal.ui.MTJUIMessages; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.ComboDialogField; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.DialogField; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.IDialogFieldListener; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.LayoutUtil; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.SelectionButtonDialogField; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.StringDialogField; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.ScrolledComposite; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Group; >+ >+public class NewMidletProjectWizardPageProperties extends WizardPage { >+ >+ private final class PropertiesGroup implements IDialogFieldListener, Observer { >+ >+ private StringDialogField midletName; >+ private StringDialogField midletVendor; >+ private StringDialogField midletVersion; >+ private ComboDialogField meConfiguration; >+ private ComboDialogField meProfile; >+ private Map<String, IAPI> configurations; >+ private Map<String, IAPI> profiles; >+ >+ >+ public PropertiesGroup() { >+ configurations = new HashMap<String, IAPI>(); >+ profiles = new HashMap<String, IAPI>(); >+ >+ midletName = new StringDialogField(); >+ midletName.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_propertiesGroup_midletName); >+ midletName.setDialogFieldListener(this); >+ >+ midletVendor = new StringDialogField(); >+ midletVendor.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_propertiesGroup_midletVendor); >+ midletVendor.setDialogFieldListener(this); >+ >+ midletVersion = new StringDialogField(); >+ midletVersion.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_propertiesGroup_midletVersion); >+ midletVersion.setDialogFieldListener(this); >+ >+ IAPI[] meConfigurations = Configuration.values(); >+ String[] configurationNames = new String[meConfigurations.length]; >+ String defaultConfiguration = ""; >+ for(int i = 0; i < meConfigurations.length; i++) { >+ configurationNames[i] = meConfigurations[i].getName(); >+ if(meConfigurations[i].toString().equals(MTJUIMessages.MeConfigurationVersion)) { >+ defaultConfiguration = meConfigurations[i].getName(); >+ } >+ configurations.put(configurationNames[i], meConfigurations[i]); >+ } >+ >+ meConfiguration = new ComboDialogField(SWT.READ_ONLY); >+ meConfiguration.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_propertiesGroup_meConfiguration); >+ meConfiguration.setDialogFieldListener(this); >+ meConfiguration.setItems(configurationNames); >+ meConfiguration.setTextWithoutUpdate(defaultConfiguration); >+ >+ IAPI[] meProfiles = Profile.values(); >+ String[] profileNames = new String[meProfiles.length]; >+ String defaultProfile = ""; >+ for(int i = 0; i < meProfiles.length; i++) { >+ profileNames[i] = meProfiles[i].getName(); >+ if(meProfiles[i].toString().equals(MTJUIMessages.MeProfileVersion)) { >+ defaultProfile = meProfiles[i].getName(); >+ } >+ >+ profiles.put(profileNames[i], meProfiles[i]); >+ } >+ >+ meProfile = new ComboDialogField(SWT.READ_ONLY); >+ meProfile.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_propertiesGroup_meProfile); >+ meProfile.setDialogFieldListener(this); >+ meProfile.setItems(profileNames); >+ meProfile.setTextWithoutUpdate(defaultProfile); >+ } >+ >+ public Control createControl(Composite parent) { >+ final int numColumns = 2; >+ >+ final Group group = new Group(parent, SWT.NONE); >+ group.setLayout(initGridLayout(new GridLayout(numColumns, false), >+ true)); >+ group.setText(MTJUIMessages.NewMidletProjectWizardPageTwo_propertiesGroup_contents); >+ >+ midletName.doFillIntoGrid(group, numColumns); >+ LayoutUtil.setHorizontalGrabbing(midletName.getTextControl(null)); >+ midletVendor.doFillIntoGrid(group, numColumns); >+ LayoutUtil.setHorizontalGrabbing(midletVendor.getTextControl(null)); >+ midletVersion.doFillIntoGrid(group, numColumns); >+ LayoutUtil.setHorizontalGrabbing(midletVersion.getTextControl(null)); >+ meConfiguration.doFillIntoGrid(group, numColumns); >+ LayoutUtil.setHorizontalGrabbing(meConfiguration.getComboControl(null)); >+ meProfile.doFillIntoGrid(group, numColumns); >+ LayoutUtil.setHorizontalGrabbing(meProfile.getComboControl(null)); >+ >+ initValues(); >+ >+ return group; >+ } >+ >+ private void initValues() { >+ midletName.setText(pageOne.getProjectName() + MTJUIMessages.MidletDefaultNameEnd); >+ midletVendor.setText(MTJUIMessages.MidletDefaultVendor); >+ midletVersion.setText(MTJUIMessages.MidletInitialVersion_1_0_0); >+ } >+ >+ @Override >+ public void dialogFieldChanged(DialogField field) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public String getMIDletName() { >+ return midletName.getText(); >+ } >+ >+ public String getMIDletVendor() { >+ return midletVendor.getText(); >+ } >+ >+ public String getMIDletVersion() { >+ return midletVersion.getText(); >+ } >+ >+ public String getMeConfiguration() { >+ return configurations.get(meConfiguration.getText()).toString(); >+ } >+ >+ public String getMeProfile() { >+ return profiles.get(meProfile.getText()).toString(); >+ } >+ >+ @Override >+ public void update(Observable o, Object arg) { >+ String midlet = midletName.getText(); >+ String projectName = pageOne.getProjectName(); >+ if (midlet.startsWith(projectName.substring(0, >+ projectName.length() - 1)) >+ || midlet.equals(MTJUIMessages.MidletDefaultNameEnd)) { >+ midletName.setText(projectName >+ + MTJUIMessages.MidletDefaultNameEnd); >+ } >+ } >+ >+ } >+ >+ private final class OptionsGroup extends Observable implements IDialogFieldListener { >+ >+ private SelectionButtonDialogField enablePreprocessing; >+ private SelectionButtonDialogField enableLocalization; >+ private StringDialogField propertiesFolder; >+ private StringDialogField packageField; >+ private SelectionButtonDialogField enableJMUnit; >+ >+ public OptionsGroup() { >+ enablePreprocessing = new SelectionButtonDialogField(SWT.CHECK); >+ enablePreprocessing.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_enablePreprocessing); >+ enablePreprocessing.setDialogFieldListener(this); >+ >+ enableLocalization = new SelectionButtonDialogField(SWT.CHECK); >+ enableLocalization.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_enableLocalization); >+ enableLocalization.setDialogFieldListener(this); >+ >+ propertiesFolder = new StringDialogField(); >+ propertiesFolder.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_propertiesFolder); >+ propertiesFolder.setDialogFieldListener(this); >+ >+ packageField = new StringDialogField(); >+ packageField.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_package); >+ packageField.setDialogFieldListener(this); >+ >+ enableJMUnit = new SelectionButtonDialogField(SWT.CHECK); >+ enableJMUnit.setLabelText(MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_enableJMUnit); >+ enableJMUnit.setDialogFieldListener(this); >+ >+ >+ enablePreprocessing.setSelection(false); >+ enableLocalization.setSelection(false); >+ enableLocalization.attachDialogField(propertiesFolder); >+ enableLocalization.attachDialogFields(new DialogField[]{packageField, propertiesFolder}); >+ } >+ >+ public Control createControl(Composite parent) { >+ final int numColumns = 2; >+ >+ final Group group = new Group(parent, SWT.NONE); >+ group.setLayout(initGridLayout(new GridLayout(numColumns, false), >+ true)); >+ group.setText(MTJUIMessages.NewMidletProjectWizardPageTwo_propertiesGroup_contents); >+ >+ >+ enablePreprocessing.doFillIntoGrid(group, numColumns); >+ enableLocalization.doFillIntoGrid(group, numColumns); >+ propertiesFolder.doFillIntoGrid(group, numColumns); >+ LayoutUtil.setHorizontalGrabbing(propertiesFolder.getTextControl(null)); >+ packageField.doFillIntoGrid(group, numColumns); >+ LayoutUtil.setHorizontalGrabbing(packageField.getTextControl(null)); >+ enableJMUnit.doFillIntoGrid(group, numColumns); >+ >+ return group; >+ } >+ >+ @Override >+ public void dialogFieldChanged(DialogField field) { >+ fireEvent(); >+ } >+ >+ protected void fireEvent() { >+ setChanged(); >+ notifyObservers(); >+ } >+ >+ public boolean isPreprocessingEnable() { >+ return enablePreprocessing.isSelected(); >+ } >+ >+ public boolean isLocalizationEnable() { >+ return enableLocalization.isSelected(); >+ } >+ >+ public String getPropertiesFolder() { >+ return propertiesFolder.getText(); >+ } >+ >+ public String getPackage () { >+ return packageField.getText(); >+ } >+ >+ public boolean isJMUnitEnable() { >+ return enableJMUnit.isSelected(); >+ } >+ >+ } >+ >+ private final class Validator implements Observer { >+ >+ private Pattern packagePattern = Pattern >+ .compile("[a-zA-Z]([\\w\\.]*\\w)*"); >+ private Pattern correctPattern = Pattern >+ .compile("[a-z]([\\w\\.]*\\w)*"); >+ >+ @Override >+ public void update(Observable o, Object arg) { >+ if(isLocalizationEnabled()) { >+ String packageName = getPackageName(); >+ if (packageName.equals("")) { >+ setErrorMessage(MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_packageEmpty); >+ setMessage(null); >+ setPageComplete(false); >+ return; >+ } >+ Matcher packageMatcher = packagePattern.matcher(packageName); >+ if (packageMatcher.matches()) { >+ Matcher correctMatcher = correctPattern.matcher(packageName); >+ // Correct package >+ if (correctMatcher.matches()) { >+ setErrorMessage(null); >+ setMessage(null); >+ setPageComplete(true); >+ } >+ // Upper case package >+ else { >+ setErrorMessage(null); >+ setMessage( >+ MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_packageUpperCase, >+ WizardPage.WARNING); >+ setPageComplete(true); >+ } >+ } >+ // Error package >+ else { >+ setMessage(null); >+ setErrorMessage(NLS >+ .bind( >+ MTJUIMessages.NewMidletProjectWizardPageTwo_optionsGroup_packageError, >+ packageName)); >+ setPageComplete(false); >+ } >+ } >+ } >+ } >+ >+ private static final String PAGE_NAME = "NewJavaProjectWizardPageTwo"; //$NON-NLS-1$ >+ private NewMidletProjectWizardPageOne pageOne; >+ private PropertiesGroup propertiesGroup; >+ private OptionsGroup optionsGroup; >+ private Validator validator; >+ >+ >+ public NewMidletProjectWizardPageProperties(NewMidletProjectWizardPageOne firstPage) { >+ super(PAGE_NAME); >+ >+ this.pageOne = firstPage; >+ this.validator = new Validator(); >+ >+ this.propertiesGroup = new PropertiesGroup(); >+ this.optionsGroup = new OptionsGroup(); >+ >+ this.pageOne.getProjectNameGroup().addObserver(propertiesGroup); >+ this.optionsGroup.addObserver(validator); >+ } >+ >+ @Override >+ public void createControl(Composite parent) { >+ initializeDialogUnits(parent); >+ >+ ScrolledComposite scrolledComposite = new ScrolledComposite(parent, >+ SWT.V_SCROLL | SWT.H_SCROLL); >+ scrolledComposite.setExpandHorizontal(true); >+ scrolledComposite.setExpandVertical(true); >+ scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, >+ true)); >+ >+ final Composite composite = new Composite(scrolledComposite, SWT.NONE); >+ composite.setFont(parent.getFont()); >+ composite.setLayout(initGridLayout(new GridLayout(), true)); >+ >+ // create UI elements >+ Control nameControl = createPropertiesControl(composite); >+ nameControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ >+ Control optionsControl = createOptionsControl(composite); >+ optionsControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ >+ scrolledComposite.setContent(composite); >+ scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, >+ SWT.DEFAULT)); >+ setControl(scrolledComposite); >+ } >+ >+ private Control createOptionsControl(Composite parent) { >+ return optionsGroup.createControl(parent); >+ } >+ >+ protected Control createPropertiesControl(Composite parent) { >+ return propertiesGroup.createControl(parent); >+ } >+ >+ public boolean isPreprocessingEnabled() { >+ return optionsGroup.isPreprocessingEnable(); >+ } >+ >+ public boolean isLocalizationEnabled() { >+ return optionsGroup.isLocalizationEnable(); >+ } >+ >+ public boolean isJMUnitEnabled() { >+ return optionsGroup.isJMUnitEnable(); >+ } >+ >+ public String getMIDletName() { >+ return propertiesGroup.getMIDletName(); >+ } >+ >+ public String getMIDletVendor() { >+ return propertiesGroup.getMIDletVendor(); >+ } >+ >+ public String getMIDletVersion() { >+ return propertiesGroup.getMIDletVersion(); >+ } >+ >+ public String getMeConfiguration() { >+ return propertiesGroup.getMeConfiguration(); >+ } >+ >+ public String getMeProfile() { >+ return propertiesGroup.getMeProfile(); >+ } >+ >+ public String getPropertiesFolderName() { >+ return optionsGroup.getPropertiesFolder(); >+ } >+ >+ public String getPackageName() { >+ return optionsGroup.getPackage(); >+ } >+ >+ >+ private GridLayout initGridLayout(GridLayout layout, boolean margins) { >+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); >+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); >+ if (margins) { >+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); >+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); >+ } else { >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ } >+ return layout; >+ } >+ >+} >Index: src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageOne.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageOne.java (revision 1344) >+++ src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageOne.java (working copy) >@@ -12,6 +12,7 @@ > * management section, for multi-configs support. > * Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874] > * Fernando Rocha (Motorola) - Add the scroll bar in the page [Bug 273646] >+ * Fernando Rocha (Motorola) - Add the WorkingSet preference [Bug 261873] > */ > package org.eclipse.mtj.internal.ui.wizards.projects; > >@@ -18,6 +19,9 @@ > import java.io.File; > import java.io.IOException; > import java.net.URI; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; > import java.util.Observable; > import java.util.Observer; > >@@ -37,6 +41,7 @@ > import org.eclipse.jface.dialogs.Dialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.window.Window; > import org.eclipse.jface.wizard.WizardPage; > import org.eclipse.mtj.core.MTJCore; > import org.eclipse.mtj.core.project.runtime.MTJRuntime; >@@ -52,7 +57,9 @@ > import org.eclipse.mtj.internal.ui.MTJUIMessages; > import org.eclipse.mtj.internal.ui.MTJUIPlugin; > import org.eclipse.mtj.internal.ui.configurations.ConfigManageComponent; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.ComboButtonDialogField; > import org.eclipse.mtj.internal.ui.wizards.dialogfields.DialogField; >+import org.eclipse.mtj.internal.ui.wizards.dialogfields.IComboButtonAdapter; > import org.eclipse.mtj.internal.ui.wizards.dialogfields.IDialogFieldListener; > import org.eclipse.mtj.internal.ui.wizards.dialogfields.IStringButtonAdapter; > import org.eclipse.mtj.internal.ui.wizards.dialogfields.LayoutUtil; >@@ -61,11 +68,8 @@ > import org.eclipse.mtj.internal.ui.wizards.dialogfields.StringDialogField; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.ScrolledComposite; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; >-import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.DirectoryDialog; >@@ -71,7 +75,12 @@ > import org.eclipse.swt.widgets.DirectoryDialog; > import org.eclipse.swt.widgets.Group; > import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; > import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.IWorkingSet; >+import org.eclipse.ui.IWorkingSetManager; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog; > > /** > * Main page for the wizard that creates the new MIDlet project. >@@ -97,6 +106,7 @@ > > public void activeMTJRuntimeSwitched( > SwitchActiveMTJRuntimeEvent event) { >+ fireEvent(); > } > > /** >@@ -141,7 +151,11 @@ > } > > public IDevice getSelectedDevice() { >- return configManager.getActiveConfiguration().getDevice(); >+ MTJRuntime activeConfiguration = configManager.getActiveConfiguration(); >+ if(activeConfiguration == null) { >+ return null; >+ } >+ return activeConfiguration.getDevice(); > } > > private void initConfigManager(Composite configComposite) { >@@ -485,6 +499,118 @@ > } > } > >+ private final class WorkingSetGroup extends Observable implements Observer, >+ IStringButtonAdapter, IComboButtonAdapter, IDialogFieldListener { >+ >+ private SelectionButtonDialogField addWorkingSetButton; >+ private ComboButtonDialogField workingSetsSelection; >+ private IWorkingSetManager workingSetManager; >+ >+ private IWorkingSet workingSet; >+ >+ public WorkingSetGroup() { >+ workingSetManager = PlatformUI.getWorkbench() >+ .getWorkingSetManager(); >+ >+ addWorkingSetButton = new SelectionButtonDialogField(SWT.CHECK); >+ addWorkingSetButton.setDialogFieldListener(this); >+ addWorkingSetButton >+ .setLabelText(MTJUIMessages.NewMidletProjectWizardPageOne_locationGroup_workingSetsButton); >+ >+ workingSetsSelection = new ComboButtonDialogField(this, >+ SWT.READ_ONLY); >+ workingSetsSelection >+ .setLabelText(MTJUIMessages.NewMidletProjectWizardPageOne_workingSetGroup_selection); >+ workingSetsSelection >+ .setButtonLabel(MTJUIMessages.NewMidletProjectWizardPageOne_workingSetGroup_select_button); >+ >+ IWorkingSet[] recentWorkingSets = workingSetManager >+ .getRecentWorkingSets(); >+ String[] items = new String[recentWorkingSets.length]; >+ int i = 0; >+ for (IWorkingSet workingSet : recentWorkingSets) { >+ items[i] = workingSet.getName(); >+ i++; >+ } >+ workingSetsSelection.setItems(items); >+ workingSetsSelection.setDialogFieldListener(this); >+ >+ addWorkingSetButton.setSelection(false); >+ addWorkingSetButton.attachDialogField(workingSetsSelection); >+ } >+ >+ @Override >+ public void dialogFieldChanged(DialogField field) { >+ if (field == workingSetsSelection) { >+ workingSet = workingSetManager >+ .getWorkingSet(workingSetsSelection.getText()); >+ } else if (field == addWorkingSetButton) { >+ if (workingSetsSelection.getText().equals("")) { >+ String[] items = workingSetsSelection.getItems(); >+ if (items.length > 0) { >+ workingSetsSelection.setText(items[0]); >+ } >+ } >+ } >+ fireEvent(); >+ } >+ >+ @Override >+ public void changeControlPressed(DialogField field) { >+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() >+ .getShell(); >+ IWorkingSetSelectionDialog workingSetWizard = workingSetManager >+ .createWorkingSetSelectionDialog(shell, false); >+ if (workingSetWizard != null) { >+ if (workingSetWizard.open() == Window.OK) { >+ workingSet = workingSetWizard.getSelection()[0]; >+ List<String> items = new ArrayList<String>(Arrays >+ .asList(workingSetsSelection.getItems())); >+ String workingSetName = workingSet.getName(); >+ items.add(workingSetName); >+ workingSetsSelection.setItems(items >+ .toArray(new String[items.size()])); >+ workingSetsSelection.setText(workingSetName); >+ } >+ } >+ fireEvent(); >+ } >+ >+ @Override >+ public void update(Observable o, Object arg) { >+ fireEvent(); >+ } >+ >+ public Control createControl(Composite composite) { >+ final int numColumns = 3; >+ >+ final Group group = new Group(composite, SWT.NONE); >+ group.setLayout(initGridLayout(new GridLayout(numColumns, false), >+ true)); >+ group >+ .setText(MTJUIMessages.NewMidletProjectWizardPageOne_workingSetGroup_contents); >+ >+ addWorkingSetButton.doFillIntoGrid(group, numColumns); >+ workingSetsSelection.doFillIntoGrid(group, numColumns); >+ >+ return group; >+ } >+ >+ public boolean isProjectAddedWorkingSet() { >+ return addWorkingSetButton.isSelected(); >+ } >+ >+ protected void fireEvent() { >+ setChanged(); >+ notifyObservers(); >+ } >+ >+ public IWorkingSet getWorkingSet() { >+ return workingSet; >+ } >+ >+ } >+ > /** > * Request a project name. Fires an event whenever the text field is > * changed, regardless of its content. >@@ -489,7 +615,7 @@ > * Request a project name. Fires an event whenever the text field is > * changed, regardless of its content. > */ >- private final class ProjectNameGroup extends Observable implements >+ public final class ProjectNameGroup extends Observable implements > IDialogFieldListener { > > protected final StringDialogField projNameField; >@@ -765,9 +891,6 @@ > > private final JadNameGroup jadNameGroup; > >- private Button preprocessedButton; >- >- private boolean preprocessingEnabled; > private final LocationGroup projectLocationGroup; > > private final ProjectNameGroup projectNameGroup; >@@ -774,6 +897,8 @@ > > private final Validator wizardPageValidator; > >+ private final WorkingSetGroup workingSetGroup; >+ > /** > * Creates a new NewMidletProjectWizardPageOne > */ >@@ -786,6 +911,7 @@ > projectNameGroup = new ProjectNameGroup(); > jadNameGroup = new JadNameGroup(); > projectLocationGroup = new LocationGroup(); >+ workingSetGroup = new WorkingSetGroup(); > configurationGroup = new ConfigurationGroup(); > > // establish connections >@@ -801,6 +927,7 @@ > configurationGroup.addObserver(wizardPageValidator); > projectLocationGroup.addObserver(wizardPageValidator); > jadNameGroup.addObserver(wizardPageValidator); >+ workingSetGroup.addObserver(wizardPageValidator); > > // initialize defaults > setProjectName(""); //$NON-NLS-1$ >@@ -817,7 +944,7 @@ > */ > public void createControl(final Composite parent) { > initializeDialogUnits(parent); >- >+ > ScrolledComposite scrolledComposite = new ScrolledComposite(parent, > SWT.V_SCROLL | SWT.H_SCROLL); > scrolledComposite.setExpandHorizontal(true); >@@ -822,12 +949,13 @@ > SWT.V_SCROLL | SWT.H_SCROLL); > scrolledComposite.setExpandHorizontal(true); > scrolledComposite.setExpandVertical(true); >- scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >- >+ scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, >+ true)); >+ > final Composite composite = new Composite(scrolledComposite, SWT.NONE); > composite.setFont(parent.getFont()); > composite.setLayout(initGridLayout(new GridLayout(1, false), true)); >- >+ > // create UI elements > Control nameControl = createNameControl(composite); > nameControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >@@ -841,12 +969,12 @@ > Control configControl = createConfigGroupControl(composite); > configControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); > >- Control preprocessorControl = createPreprocessorGroupSelectionControl(composite); >- preprocessorControl >- .setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ Control workingSets = createWorkingSets(composite); >+ workingSets.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); > > scrolledComposite.setContent(composite); >- scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); >+ scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, >+ SWT.DEFAULT)); > setControl(scrolledComposite); > } > >@@ -921,6 +1049,20 @@ > } > > /** >+ * @return the projectNameGroup >+ */ >+ public Observable getProjectNameGroup() { >+ return projectNameGroup; >+ } >+ >+ /** >+ * @return the configurationGroup >+ */ >+ public Observable getConfigurationGroup() { >+ return configurationGroup; >+ } >+ >+ /** > * Returns the compiler compliance to be used for the project, or > * <code>null</code> to use the workspace compiler compliance. > * >@@ -963,16 +1105,6 @@ > } > > /** >- * Return a boolean concerning whether preprocessing is enabled for the >- * newly created project. >- * >- * @return the preprocessingEnabled >- */ >- public boolean isPreprocessingEnabled() { >- return preprocessingEnabled; >- } >- >- /** > * Sets the project location of the new project or <code>null</code> if the > * project should be created in the workspace > * >@@ -1059,40 +1191,13 @@ > return projectNameGroup.createControl(composite); > } > >- /** >- * @param composite >- * @return >- */ >- protected Control createPreprocessorGroupSelectionControl( >- Composite composite) { >+ protected Control createWorkingSets(Composite composite) { > >- // Add an extra composite to get the layout to match up the >- // components vertically >- Group preprocessorGroup = new Group(composite, SWT.NONE); >- preprocessorGroup.setLayout(new GridLayout(1, true)); >- preprocessorGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); >- preprocessorGroup >- .setText(MTJUIMessages.NewMidletProjectWizardPageOne_preprocessorGroup); >- >- preprocessedButton = new Button(preprocessorGroup, SWT.CHECK); >- preprocessedButton >- .setText(MTJUIMessages.NewMidletProjectWizardPageOne_preprocessor); >- preprocessedButton >- .setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- preprocessedButton.addSelectionListener(new SelectionAdapter() { >+ return workingSetGroup.createControl(composite); >+ } > >- /* >- * (non-Javadoc) >- * @see >- * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse >- * .swt.events.SelectionEvent) >- */ >- @Override >- public void widgetSelected(SelectionEvent e) { >- preprocessingEnabled = preprocessedButton.getSelection(); >- } >- }); >- return preprocessorGroup; >+ public IWorkingSet getWorkingSet() { >+ return workingSetGroup.getWorkingSet(); > } > > /* >Index: src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageJavaSettings.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageJavaSettings.java (revision 0) >+++ src/org/eclipse/mtj/internal/ui/wizards/projects/NewMidletProjectWizardPageJavaSettings.java (revision 0) >@@ -0,0 +1,928 @@ >+/** >+ * Copyright (c) 2008 Motorola. >+ * >+ * 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: >+ * Diego Sandin (Motorola) - Initial version >+ * Feng Wang (Sybase) - Add configurations into Metadata for Multi-Configs >+ * support. >+ * Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874] >+ */ >+package org.eclipse.mtj.internal.ui.wizards.projects; >+ >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileOutputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.OutputStream; >+import java.lang.reflect.InvocationTargetException; >+import java.net.URI; >+import java.net.URISyntaxException; >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.List; >+import java.util.Map; >+import java.util.Vector; >+ >+import org.eclipse.core.filesystem.EFS; >+import org.eclipse.core.filesystem.IFileInfo; >+import org.eclipse.core.filesystem.IFileStore; >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IResourceStatus; >+import org.eclipse.core.resources.IWorkspaceDescription; >+import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IAdaptable; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.ui.PreferenceConstants; >+import org.eclipse.jdt.ui.wizards.JavaCapabilityConfigurationPage; >+import org.eclipse.jface.dialogs.ErrorDialog; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.mtj.core.MTJCore; >+import org.eclipse.mtj.core.project.IMetaData; >+import org.eclipse.mtj.core.project.ProjectType; >+import org.eclipse.mtj.core.project.runtime.MTJRuntimeList; >+import org.eclipse.mtj.core.sdk.device.IDevice; >+import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice; >+import org.eclipse.mtj.internal.core.IMTJCoreConstants; >+import org.eclipse.mtj.internal.core.build.preprocessor.PreprocessorBuilder; >+import org.eclipse.mtj.internal.core.project.midp.IJADConstants; >+import org.eclipse.mtj.internal.core.project.midp.JavaMEClasspathContainer; >+import org.eclipse.mtj.internal.core.project.midp.MidletSuiteFactory; >+import org.eclipse.mtj.internal.ui.IMTJUIConstants; >+import org.eclipse.mtj.internal.ui.MTJUIMessages; >+import org.eclipse.mtj.internal.ui.util.ExceptionHandler; >+import org.eclipse.ui.IWorkingSet; >+import org.eclipse.ui.IWorkingSetManager; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; >+ >+/** >+ * The New MIDlet Project Java Capability Wizard Page allows the user to >+ * configure the build path and output location of the MIDlet Project. As >+ * addition to the {@link JavaCapabilityConfigurationPage}, the wizard page does >+ * an early project creation (so that linked folders can be defined). >+ * >+ * @author Diego Madruga Sandin >+ * @since 0.9 >+ */ >+public class NewMidletProjectWizardPageJavaSettings extends >+ JavaCapabilityConfigurationPage { >+ >+ private static final String FILENAME_CLASSPATH = ".classpath"; //$NON-NLS-1$ >+ >+ private static final String FILENAME_PROJECT = ".project"; //$NON-NLS-1$ >+ >+ /** >+ * @param projectName >+ * @param location >+ * @return >+ */ >+ private static URI getRealLocation(String projectName, URI location) { >+ if (location == null) { // inside workspace >+ try { >+ URI rootLocation = MTJCore.getWorkspace().getRoot() >+ .getLocationURI(); >+ >+ location = new URI(rootLocation.getScheme(), null, Path >+ .fromPortableString(rootLocation.getPath()).append( >+ projectName).toString(), null); >+ } catch (URISyntaxException e) { >+ Assert.isTrue(false, "Can't happen"); //$NON-NLS-1$ >+ } >+ } >+ return location; >+ } >+ >+ public Boolean isAutobuild; >+ private IProject currProject; >+ private URI currProjectLocation; >+ private File fDotClasspathBackup; >+ private File fDotProjectBackup; >+ private NewMidletProjectWizardPageOne firstPage; >+ private NewMidletProjectWizardPageProperties propertiesPage; >+ private HashSet<IFileStore> fOrginalFolders; >+ >+ private boolean keepContent; >+ >+ private NewMidletProjectWizardPageLibrary pageLibrary; >+ >+ /** >+ * Creates a new New MIDlet Project Java Capability Wizard Page. >+ * >+ * @param workbench >+ */ >+ public NewMidletProjectWizardPageJavaSettings(NewMidletProjectWizardPageOne pageOne, >+ NewMidletProjectWizardPageProperties pageTwo, >+ NewMidletProjectWizardPageLibrary pageLibrary) { >+ this.currProjectLocation = null; >+ this.currProject = null; >+ this.firstPage = pageOne; >+ this.propertiesPage = pageTwo; >+ this.pageLibrary = pageLibrary; >+ isAutobuild = null; >+ } >+ >+ /** >+ * Called from the wizard on cancel. >+ */ >+ public void performCancel() { >+ if (currProject != null) { >+ removeProvisonalProject(); >+ } >+ } >+ >+ /** >+ * Called from the wizard on finish. >+ * >+ * @param monitor the progress monitor >+ * @throws CoreException thrown when the project creation or configuration >+ * failed >+ * @throws InterruptedException thrown when the user canceled the project >+ * creation >+ */ >+ @SuppressWarnings("unchecked") >+ public void performFinish(IProgressMonitor monitor) throws CoreException, >+ InterruptedException { >+ try { >+ >+ monitor >+ .beginTask( >+ MTJUIMessages.NewMidletProjectWizardPageThree_performFinish_monitor_taskname, >+ 3); >+ if (currProject == null) { >+ updateProject(new SubProgressMonitor(monitor, 1)); >+ } >+ >+ configureJavaProject(new SubProgressMonitor(monitor, 2)); >+ >+ if (!keepContent) { >+ IJavaProject project = JavaCore.create(currProject); >+ Map options = project.getOptions(false); >+ >+ // complete compliance options >+ project.setOptions(options); >+ } >+ >+ } finally { >+ monitor.done(); >+ currProject = null; >+ if (isAutobuild != null) { >+ IWorkspaceDescription description = ResourcesPlugin >+ .getWorkspace().getDescription(); >+ description.setAutoBuilding(isAutobuild.booleanValue()); >+ MTJCore.getWorkspace().setDescription(description); >+ isAutobuild = null; >+ } >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean) >+ */ >+ @Override >+ public void setVisible(boolean visible) { >+ boolean isShownFirstTime = visible && (currProject == null); >+ if (visible) { >+ if (isShownFirstTime) { >+ // entering from the first page >+ createProvisonalProject(); >+ } >+ } else { >+ if ((getContainer().getCurrentPage() == firstPage) >+ || (getContainer().getCurrentPage() == pageLibrary)) { >+ // leaving back to previous pages >+ removeProvisonalProject(); >+ } >+ } >+ super.setVisible(visible); >+ if (isShownFirstTime) { >+ setFocus(); >+ } >+ } >+ >+ /** >+ * Update the java configuration before making the page visible. >+ */ >+ public void updateConfiguration() { >+ String projectName = firstPage.getProjectName(); >+ >+ currProject = MTJCore.getWorkspace().getRoot().getProject( >+ projectName); >+ >+ IJavaProject javaProject = JavaCore.create(currProject); >+ IPath projectPath = currProject.getFullPath(); >+ >+ // Initialize the classpath entries using the source directories >+ // and classpath container >+ ArrayList<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>(); >+ entryList.add(getSrcPathEntry(projectPath)); >+ addResourcesDirectoryIfRequested(entryList, currProject); >+ IPath entryPath = new Path(JavaMEClasspathContainer.JAVAME_CONTAINER >+ + "/" + firstPage.getSelectedDevice()); //$NON-NLS-1$ >+ >+ entryList.add(JavaCore.newContainerEntry(entryPath)); >+ >+ IClasspathEntry[] entries = entryList >+ .toArray(new IClasspathEntry[entryList.size()]); >+ >+ init(javaProject, null, entries, false); >+ } >+ >+ /** >+ * Add a resources directory as a source path entry if the user preferences >+ * requested. >+ * >+ * @param entryList >+ * @param project >+ */ >+ private void addResourcesDirectoryIfRequested( >+ List<IClasspathEntry> entryList, IProject project) { >+ Preferences prefs = MTJCore.getMTJCore().getPluginPreferences(); >+ >+ if (useSourceAndBinaryFolders() >+ && prefs.getBoolean(IMTJCoreConstants.PREF_USE_RESOURCES_DIR)) { >+ // Create the resources directory if it doesn't already exist >+ String resDirName = prefs >+ .getString(IMTJCoreConstants.PREF_RESOURCES_DIR); >+ IFolder resFolder = project.getFolder(resDirName); >+ >+ if (!resFolder.exists()) { >+ try { >+ resFolder.create(true, true, new NullProgressMonitor()); >+ } catch (CoreException e) { >+ e.printStackTrace(); >+ } >+ } >+ >+ // Add it as a source folder to the java project >+ entryList.add(JavaCore.newSourceEntry(resFolder.getFullPath())); >+ } >+ } >+ >+ private IStatus changeToNewProject() { >+ class UpdateRunnable implements IRunnableWithProgress { >+ public IStatus infoStatus = Status.OK_STATUS; >+ >+ public void run(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ try { >+ if (isAutobuild == null) { >+ IWorkspaceDescription description = ResourcesPlugin >+ .getWorkspace().getDescription(); >+ isAutobuild = Boolean.valueOf(description >+ .isAutoBuilding()); >+ description.setAutoBuilding(false); >+ MTJCore.getWorkspace().setDescription( >+ description); >+ } >+ infoStatus = updateProject(monitor); >+ } catch (CoreException e) { >+ throw new InvocationTargetException(e); >+ } catch (OperationCanceledException e) { >+ throw new InterruptedException(); >+ } finally { >+ monitor.done(); >+ } >+ } >+ } >+ >+ UpdateRunnable op = new UpdateRunnable(); >+ try { >+ getContainer().run(true, false, >+ new WorkspaceModifyDelegatingOperation(op)); >+ >+ return op.infoStatus; >+ } catch (InvocationTargetException e) { >+ >+ final String title = MTJUIMessages.NewMidletProjectWizardPageThree_changeToNewProject_errordialog_title; >+ final String message = MTJUIMessages.NewMidletProjectWizardPageThree_changeToNewProject_errordialog_message; >+ ExceptionHandler.handle(e, getShell(), title, message); >+ >+ } catch (InterruptedException e) { >+ // cancel pressed >+ } >+ return null; >+ } >+ >+ /** >+ * @param source >+ * @param target >+ * @param monitor >+ * @throws IOException >+ * @throws CoreException >+ */ >+ private void copyFile(File source, IFileStore target, >+ IProgressMonitor monitor) throws IOException, CoreException { >+ FileInputStream is = new FileInputStream(source); >+ OutputStream os = target.openOutputStream(EFS.NONE, monitor); >+ copyFile(is, os); >+ } >+ >+ /** >+ * @param source >+ * @param target >+ * @throws IOException >+ * @throws CoreException >+ */ >+ private void copyFile(IFileStore source, File target) throws IOException, >+ CoreException { >+ InputStream is = source.openInputStream(EFS.NONE, null); >+ FileOutputStream os = new FileOutputStream(target); >+ copyFile(is, os); >+ } >+ >+ /** >+ * @param is >+ * @param os >+ * @throws IOException >+ */ >+ private void copyFile(InputStream is, OutputStream os) throws IOException { >+ try { >+ byte[] buffer = new byte[8192]; >+ while (true) { >+ int bytesRead = is.read(buffer); >+ if (bytesRead == -1) { >+ break; >+ } >+ >+ os.write(buffer, 0, bytesRead); >+ } >+ } finally { >+ try { >+ is.close(); >+ } finally { >+ os.close(); >+ } >+ } >+ } >+ >+ /** >+ * @param source >+ * @param name >+ * @return >+ * @throws CoreException >+ */ >+ private File createBackup(IFileStore source, String name) >+ throws CoreException { >+ try { >+ File bak = File.createTempFile("eclipse-" + name, ".bak"); //$NON-NLS-1$//$NON-NLS-2$ >+ copyFile(source, bak); >+ return bak; >+ } catch (IOException e) { >+ IStatus status = new Status( >+ IStatus.ERROR, >+ IMTJUIConstants.PLUGIN_ID, >+ IStatus.ERROR, >+ MTJUIMessages.NewMidletProjectWizardPageThree_createBackup_error_1 >+ + name >+ + MTJUIMessages.NewMidletProjectWizardPageThree_createBackup_error_2, >+ e); >+ throw new CoreException(status); >+ } >+ } >+ >+ private void deleteProjectFile(URI projectLocation) throws CoreException { >+ IFileStore file = EFS.getStore(projectLocation); >+ if (file.fetchInfo().exists()) { >+ IFileStore projectFile = file.getChild(FILENAME_PROJECT); >+ if (projectFile.fetchInfo().exists()) { >+ projectFile.delete(EFS.NONE, null); >+ } >+ } >+ } >+ >+ private final void doRemoveProject(IProgressMonitor monitor) >+ throws InvocationTargetException { >+ final boolean noProgressMonitor = (currProjectLocation == null); // inside >+ // workspace >+ if ((monitor == null) || noProgressMonitor) { >+ monitor = new NullProgressMonitor(); >+ } >+ monitor >+ .beginTask( >+ MTJUIMessages.NewMidletProjectWizardPageThree_doRemoveProject_taskname, >+ 3); >+ try { >+ try { >+ URI projLoc = currProject.getLocationURI(); >+ >+ boolean removeContent = !keepContent >+ && currProject.isSynchronized(IResource.DEPTH_INFINITE); >+ if ((!removeContent) >+ && (currProject.getProject().getFullPath().toFile() >+ .exists())) { >+ restoreExistingFolders(projLoc); >+ } >+ currProject.delete(removeContent, false, >+ new SubProgressMonitor(monitor, 2)); >+ >+ MidletSuiteFactory.removeMidletSuiteProject(getJavaProject()); >+ >+ restoreExistingFiles(projLoc, >+ new SubProgressMonitor(monitor, 1)); >+ } finally { >+ IWorkspaceDescription description = ResourcesPlugin >+ .getWorkspace().getDescription(); >+ description.setAutoBuilding(isAutobuild.booleanValue()); >+ MTJCore.getWorkspace().setDescription(description); >+ // isAutobuild must be set >+ isAutobuild = null; >+ } >+ } catch (CoreException e) { >+ throw new InvocationTargetException(e); >+ } finally { >+ monitor.done(); >+ currProject = null; >+ keepContent = false; >+ } >+ } >+ >+ /** >+ * Get the source path for the project taking into account the new project >+ * preferences that the user has specified. >+ * >+ * @param projectPath >+ * @return >+ */ >+ private IPath getSrcPath(IPath projectPath) { >+ IPath srcPath = projectPath; >+ >+ if (useSourceAndBinaryFolders()) { >+ IPreferenceStore store = PreferenceConstants.getPreferenceStore(); >+ String srcPathName = store >+ .getString(PreferenceConstants.SRCBIN_SRCNAME); >+ srcPath = projectPath.append(srcPathName); >+ } >+ >+ return srcPath; >+ } >+ >+ /** >+ * Return an IClasspathEntry for the source path. >+ * >+ * @param projectPath >+ * @return >+ */ >+ private IClasspathEntry getSrcPathEntry(IPath projectPath) { >+ IPath srcPath = getSrcPath(projectPath); >+ >+ // Set up exclusions for the verified and deployed directories >+ // if the source and project directories are the same >+ IPath[] exclusions = null; >+ if (srcPath.equals(projectPath)) { >+ exclusions = new IPath[3]; >+ exclusions[0] = new Path(MTJCore.getDeploymentDirectoryName() + "/"); //$NON-NLS-1$ >+ exclusions[1] = new Path(IMTJCoreConstants.TEMP_FOLDER_NAME + "/"); //$NON-NLS-1$ >+ exclusions[2] = new Path(PreprocessorBuilder.PROCESSED_DIRECTORY >+ + "/"); //$NON-NLS-1$ >+ } else { >+ exclusions = new IPath[0]; >+ } >+ >+ return JavaCore.newSourceEntry(srcPath, exclusions); >+ } >+ >+ /** >+ * @param realLocation >+ * @return >+ * @throws CoreException >+ */ >+ private boolean hasExistingContent(URI realLocation) throws CoreException { >+ IFileStore file = EFS.getStore(realLocation); >+ return file.fetchInfo().exists(); >+ } >+ >+ private void rememberExisitingFolders(URI projectLocation) { >+ fOrginalFolders = new HashSet<IFileStore>(); >+ >+ try { >+ IFileStore[] children = EFS.getStore(projectLocation).childStores( >+ EFS.NONE, null); >+ for (IFileStore child : children) { >+ IFileInfo info = child.fetchInfo(); >+ if (info.isDirectory() && info.exists() >+ && !fOrginalFolders.contains(child.getName())) { >+ fOrginalFolders.add(child); >+ } >+ } >+ } catch (CoreException e) { >+ final String title = MTJUIMessages.NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_title; >+ final String message = MTJUIMessages.NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_message; >+ ExceptionHandler.handle(e, getShell(), title, message); >+ } >+ } >+ >+ private void rememberExistingFiles(URI projectLocation) >+ throws CoreException { >+ fDotProjectBackup = null; >+ fDotClasspathBackup = null; >+ >+ IFileStore file = EFS.getStore(projectLocation); >+ if (file.fetchInfo().exists()) { >+ IFileStore projectFile = file.getChild(FILENAME_PROJECT); >+ if (projectFile.fetchInfo().exists()) { >+ fDotProjectBackup = createBackup(projectFile, "project-desc"); //$NON-NLS-1$ >+ } >+ IFileStore classpathFile = file.getChild(FILENAME_CLASSPATH); >+ if (classpathFile.fetchInfo().exists()) { >+ fDotClasspathBackup = createBackup(classpathFile, >+ "classpath-desc"); //$NON-NLS-1$ >+ } >+ } >+ } >+ >+ private void restoreExistingFiles(URI projectLocation, >+ IProgressMonitor monitor) throws CoreException { >+ int ticks = ((fDotProjectBackup != null ? 1 : 0) + (fDotClasspathBackup != null ? 1 >+ : 0)) * 2; >+ monitor.beginTask("", ticks); //$NON-NLS-1$ >+ try { >+ IFileStore projectFile = EFS.getStore(projectLocation).getChild( >+ FILENAME_PROJECT); >+ projectFile.delete(EFS.NONE, new SubProgressMonitor(monitor, 1)); >+ if (fDotProjectBackup != null) { >+ copyFile(fDotProjectBackup, projectFile, >+ new SubProgressMonitor(monitor, 1)); >+ } >+ } catch (IOException e) { >+ IStatus status = new Status( >+ IStatus.ERROR, >+ IMTJUIConstants.PLUGIN_ID, >+ IStatus.ERROR, >+ MTJUIMessages.NewMidletProjectWizardPageThree_restoreExistingFiles_problem_restoring_dotproject, >+ e); >+ throw new CoreException(status); >+ } >+ try { >+ IFileStore classpathFile = EFS.getStore(projectLocation).getChild( >+ FILENAME_CLASSPATH); >+ classpathFile.delete(EFS.NONE, new SubProgressMonitor(monitor, 1)); >+ if (fDotClasspathBackup != null) { >+ copyFile(fDotClasspathBackup, classpathFile, >+ new SubProgressMonitor(monitor, 1)); >+ } >+ } catch (IOException e) { >+ IStatus status = new Status( >+ IStatus.ERROR, >+ IMTJUIConstants.PLUGIN_ID, >+ IStatus.ERROR, >+ MTJUIMessages.NewMidletProjectWizardPageThree_restoreExistingFiles_problem_restoring_dotclasspath, >+ e); >+ throw new CoreException(status); >+ } >+ } >+ >+ private void restoreExistingFolders(URI projectLocation) { >+ try { >+ IFileStore[] children = EFS.getStore(projectLocation).childStores( >+ EFS.NONE, null); >+ for (IFileStore child : children) { >+ IFileInfo info = child.fetchInfo(); >+ if (info.isDirectory() && info.exists() >+ && !fOrginalFolders.contains(child)) { >+ child.delete(EFS.NONE, null); >+ fOrginalFolders.remove(child); >+ } >+ } >+ >+ for (IFileStore fileStore : fOrginalFolders) { >+ IFileStore deleted = fileStore; >+ deleted.mkdir(EFS.NONE, null); >+ } >+ } catch (CoreException e) { >+ final String title = MTJUIMessages.NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_title; >+ final String message = MTJUIMessages.NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_message; >+ ExceptionHandler.handle(e, getShell(), title, message); >+ } >+ } >+ >+ /** >+ * @param monitor >+ * @return >+ * @throws CoreException >+ * @throws InterruptedException >+ */ >+ private final IStatus updateProject(IProgressMonitor monitor) >+ throws CoreException, InterruptedException { >+ IStatus result = Status.OK_STATUS; >+ if (monitor == null) { >+ monitor = new NullProgressMonitor(); >+ } >+ try { >+ monitor >+ .beginTask( >+ MTJUIMessages.NewMidletProjectWizardPageThree_updateProject_taskname, >+ 7); >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ >+ String projectName = firstPage.getProjectName(); >+ >+ currProject = MTJCore.getWorkspace().getRoot().getProject( >+ projectName); >+ currProjectLocation = firstPage.getProjectLocationURI(); >+ >+ URI realLocation = getRealLocation(projectName, currProjectLocation); >+ keepContent = hasExistingContent(realLocation); >+ >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ >+ if (keepContent) { >+ rememberExistingFiles(realLocation); >+ rememberExisitingFolders(realLocation); >+ } >+ >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ >+ try { >+ >+ JavaCapabilityConfigurationPage.createProject(currProject, >+ firstPage.getProjectLocationURI(), >+ new SubProgressMonitor(monitor, 1)); >+ >+ // Set the device into the project metadata to make >+ // the java project creation happy. >+ IDevice device = firstPage.getSelectedDevice(); >+ MTJRuntimeList configurations = firstPage.getConfigurations(); >+ // Make up Metadata and save it. >+ IMetaData metadata = MTJCore.createMetaData(currProject, >+ ProjectType.MIDLET_SUITE); >+ metadata.setMTJRuntimeList(configurations); >+ try { >+ metadata.saveMetaData(); >+ } catch (CoreException e) { >+ throw new InvocationTargetException(e); >+ } >+ >+ updateConfiguration(); >+ >+ // Get the java nature >+ try { >+ IRunnableWithProgress progress = super.getRunnable(); >+ progress.run(monitor); >+ } catch (Throwable e) { >+ throw new CoreException(new Status( >+ IResourceStatus.FAILED_READ_METADATA, "", e //$NON-NLS-1$ >+ .getMessage())); >+ } >+ >+ // Get the J2ME nature and metadata set up >+ String jadFileName = firstPage.getJadFileName(); >+ >+ IJavaProject javaProject = super.getJavaProject(); >+ >+ MidletSuiteFactory.MidletSuiteCreationRunnable runnable = MidletSuiteFactory >+ .getMidletSuiteCreationRunnable(currProject, >+ javaProject, (IMIDPDevice) device, jadFileName); >+ >+ Map<String, String> properties = new HashMap<String, String>(); >+ properties.put(IJADConstants.JAD_MIDLET_NAME, propertiesPage.getMIDletName()); >+ properties.put(IJADConstants.JAD_MIDLET_VENDOR, propertiesPage.getMIDletVendor()); >+ properties.put(IJADConstants.JAD_MIDLET_VERSION, propertiesPage.getMIDletVersion()); >+ properties.put(IJADConstants.JAD_MICROEDITION_CONFIG, propertiesPage.getMeConfiguration()); >+ properties.put(IJADConstants.JAD_MICROEDITION_PROFILE, propertiesPage.getMeProfile()); >+ >+ runnable.setProperties(properties); >+ >+ >+ runnable.setPreprocessingEnable(propertiesPage >+ .isPreprocessingEnabled()); >+ >+ boolean localizationEnabled = propertiesPage >+ .isLocalizationEnabled(); >+ runnable.setLocalizationEnabled(localizationEnabled); >+ if (localizationEnabled) { >+ runnable.setPropertiesFolderName(propertiesPage >+ .getPropertiesFolderName()); >+ runnable.setPackageName(propertiesPage.getPackageName()); >+ } >+ runnable.setJMUnitSupport(propertiesPage.isJMUnitEnabled()); >+ >+ runnable.run(monitor); >+ >+ IAdaptable[] adaptableElements = new IAdaptable[] { currProject }; >+ IWorkingSet workingSet = firstPage.getWorkingSet(); >+ if (workingSet != null) { >+ List<IAdaptable> list = new Vector<IAdaptable>(); >+ >+ for (IAdaptable adaptable : workingSet.getElements()) { >+ list.add(adaptable); >+ } >+ for (IAdaptable adaptable : workingSet >+ .adaptElements(adaptableElements)) { >+ list.add(adaptable); >+ } >+ IAdaptable[] newElements = new IAdaptable[list.size()]; >+ workingSet.setElements(list.toArray(newElements)); >+ IWorkingSetManager workingSetManager = PlatformUI >+ .getWorkbench().getWorkingSetManager(); >+ workingSetManager.addRecentWorkingSet(workingSet); >+ } >+ >+ >+ } catch (CoreException e) { >+ if (e.getStatus().getCode() == IResourceStatus.FAILED_READ_METADATA) { >+ result = new Status( >+ IStatus.INFO, >+ IMTJUIConstants.PLUGIN_ID, >+ MTJUIMessages.NewMidletProjectWizardPageThree_updateProject_fail_read_metadata); >+ >+ deleteProjectFile(realLocation); >+ if (currProject.exists()) { >+ currProject.delete(true, null); >+ } >+ >+ createProject(currProject, currProjectLocation, null); >+ } else { >+ throw e; >+ } >+ } catch (Throwable e) { >+ throw new CoreException(Status.CANCEL_STATUS); >+ } >+ >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ >+ initializeBuildPath(JavaCore.create(currProject), >+ new SubProgressMonitor(monitor, 2)); >+ >+ configureJavaProject(new SubProgressMonitor(monitor, 3)); >+ // create the Java project to allow the use of the new source folder >+ // page >+ } catch (Exception e) { >+ throw new CoreException(Status.CANCEL_STATUS); >+ } finally { >+ monitor.done(); >+ } >+ >+ return result; >+ } >+ >+ /** >+ * Return a boolean indicating whether there will be separate source and >+ * binary folders in the project. >+ * >+ * @return >+ */ >+ private boolean useSourceAndBinaryFolders() { >+ IPreferenceStore store = PreferenceConstants.getPreferenceStore(); >+ return store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ); >+ } >+ >+ /** >+ * Creates the provisional project on which the wizard is working on. The >+ * provisional project is typically created when the page is entered the >+ * first time. The early project creation is required to configure linked >+ * folders. >+ * >+ * @return the provisional project >+ */ >+ protected IProject createProvisonalProject() { >+ IStatus status = changeToNewProject(); >+ if ((status != null) && !status.isOK()) { >+ ErrorDialog.openError(getShell(), "createProvisonalProject", null, //$NON-NLS-1$ >+ status); >+ } >+ return currProject; >+ } >+ >+ /** >+ * Evaluates the new build path and output folder according to the settings >+ * on the first page. The resulting build path is set by calling >+ * {@link #init(IJavaProject, IPath, IClasspathEntry[], boolean)}. Clients >+ * can override this method. >+ * >+ * @param javaProject the new project which is already created when this >+ * method is called. >+ * @param monitor the progress monitor >+ * @throws CoreException thrown when initializing the build path failed >+ */ >+ protected void initializeBuildPath(IJavaProject javaProject, >+ IProgressMonitor monitor) throws CoreException { >+ if (monitor == null) { >+ monitor = new NullProgressMonitor(); >+ } >+ monitor >+ .beginTask( >+ MTJUIMessages.NewMidletProjectWizardPageThree_updateProject_monitor_buildpath_name, >+ 2); >+ >+ try { >+ IClasspathEntry[] entries = null; >+ IProject project = javaProject.getProject(); >+ >+ List<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>(); >+ IWorkspaceRoot root = project.getWorkspace().getRoot(); >+ >+ IClasspathEntry sourceClasspathEntry = getSrcPathEntry(project >+ .getFullPath()); >+ >+ if (sourceClasspathEntry.getPath() != project.getFullPath()) { >+ >+ IFolder folder = root.getFolder(sourceClasspathEntry.getPath()); >+ >+ if (!folder.exists()) { >+ folder.create(true, true, >+ new SubProgressMonitor(monitor, 1)); >+ } >+ } >+ cpEntries.add(sourceClasspathEntry); >+ addResourcesDirectoryIfRequested(cpEntries, project); >+ >+ IPath entryPath = new Path( >+ JavaMEClasspathContainer.JAVAME_CONTAINER + "/" //$NON-NLS-1$ >+ + firstPage.getSelectedDevice()); >+ cpEntries.add(JavaCore.newContainerEntry(entryPath)); >+ >+ if (pageLibrary != null) { >+ List<IPath> list = pageLibrary.getSelectedLibraries(); >+ >+ for (IPath path : list) { >+ cpEntries.add(JavaCore.newContainerEntry(path, true)); >+ } >+ } >+ >+ entries = cpEntries.toArray(new IClasspathEntry[cpEntries.size()]); >+ >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ >+ init(javaProject, getOutputLocation(), entries, true); >+ } finally { >+ monitor.done(); >+ } >+ } >+ >+ /** >+ * Removes the provisional project. The provisional project is typically >+ * removed when the user cancels the wizard or goes back to the first page. >+ */ >+ protected void removeProvisonalProject() { >+ if (!currProject.exists()) { >+ currProject = null; >+ return; >+ } >+ >+ IRunnableWithProgress op = new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ doRemoveProject(monitor); >+ } >+ }; >+ >+ try { >+ getContainer().run(true, true, >+ new WorkspaceModifyDelegatingOperation(op)); >+ } catch (InvocationTargetException e) { >+ >+ final String title = MTJUIMessages.NewMidletProjectWizardPageThree_updateProject_errordialog_title; >+ final String message = MTJUIMessages.NewMidletProjectWizardPageThree_updateProject_errordialog_message; >+ ExceptionHandler.handle(e, getShell(), title, message); >+ >+ } catch (InterruptedException e) { >+ // cancel pressed >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * @see >+ * org.eclipse.jdt.ui.wizards.JavaCapabilityConfigurationPage#useNewSourcePage >+ * () >+ */ >+ @Override >+ protected final boolean useNewSourcePage() { >+ return true; >+ } >+} >Index: src/org/eclipse/mtj/internal/ui/wizards/dialogfields/ComboButtonDialogField.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/dialogfields/ComboButtonDialogField.java (revision 0) >+++ src/org/eclipse/mtj/internal/ui/wizards/dialogfields/ComboButtonDialogField.java (revision 0) >@@ -0,0 +1,140 @@ >+/** >+ * Copyright (c) 2009 Motorola. >+ * >+ * 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: >+ * Fernando Rocha (Motorola) - Initial implementation >+ */ >+package org.eclipse.mtj.internal.ui.wizards.dialogfields; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Label; >+ >+/** >+ * Dialog field containing a label, combo control and a button control. >+ * >+ * @author Fernando Rocha >+ * @since 1.0 >+ */ >+public class ComboButtonDialogField extends ComboDialogField { >+ >+ protected static GridData gridDataForButton(Button button, int span) { >+ GridData gd = new GridData(); >+ gd.horizontalAlignment = GridData.FILL; >+ gd.grabExcessHorizontalSpace = false; >+ gd.horizontalSpan = span; >+ return gd; >+ } >+ >+ private IComboButtonAdapter fComboButtonAdapter; >+ >+ private Button fSelectButton; >+ private String fSelectButtonLabel; >+ private boolean fButtonEnabled; >+ >+ public ComboButtonDialogField(IComboButtonAdapter adapter, int comboStyle) { >+ super(comboStyle); >+ fComboButtonAdapter = adapter; >+ fSelectButtonLabel = "!Select...!"; //$NON-NLS-1$ >+ fButtonEnabled = true; >+ } >+ >+ // ------ adapter communication >+ >+ /** >+ * Programmatical pressing of the button >+ */ >+ public void changeControlPressed() { >+ fComboButtonAdapter.changeControlPressed(this); >+ } >+ >+ // ------- layout helpers >+ >+ /* >+ * @see DialogField#doFillIntoGrid >+ */ >+ @Override >+ public Control[] doFillIntoGrid(Composite parent, int nColumns) { >+ assertEnoughColumns(nColumns); >+ >+ Label label = getLabelControl(parent); >+ label.setLayoutData(gridDataForLabel(1)); >+ Combo combo = getComboControl(parent); >+ combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // gridDataForCombo(nColumns >+ // - 2)); >+ Button button = getChangeControl(parent); >+ button.setLayoutData(gridDataForButton(button, 1)); >+ >+ return new Control[] { label, combo, button }; >+ } >+ >+ /** >+ * Sets the enable state of the button. >+ */ >+ public void enableButton(boolean enable) { >+ if (isOkToUse(fSelectButton)) { >+ fSelectButton.setEnabled(isEnabled() && enable); >+ } >+ fButtonEnabled = enable; >+ } >+ >+ /** >+ * Creates or returns the created button widget. >+ * >+ * @param parent The parent composite or <code>null</code> if the widget has >+ * already been created. >+ */ >+ public Button getChangeControl(Composite parent) { >+ if (fSelectButton == null) { >+ assertCompositeNotNull(parent); >+ >+ fSelectButton = new Button(parent, SWT.PUSH); >+ fSelectButton.setFont(parent.getFont()); >+ fSelectButton.setText(fSelectButtonLabel); >+ fSelectButton.setEnabled(isEnabled() && fButtonEnabled); >+ fSelectButton.addSelectionListener(new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ changeControlPressed(); >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ changeControlPressed(); >+ } >+ }); >+ >+ } >+ return fSelectButton; >+ } >+ >+ /** >+ * Sets the label of the button. >+ */ >+ public void setButtonLabel(String label) { >+ fSelectButtonLabel = label; >+ } >+ >+ @Override >+ public int getNumberOfControls() { >+ return 3; >+ } >+ >+ @Override >+ protected void updateEnableState() { >+ super.updateEnableState(); >+ if (isOkToUse(fSelectButton)) { >+ fSelectButton.setEnabled(isEnabled() && fButtonEnabled); >+ } >+ } >+ >+} >Index: src/org/eclipse/mtj/internal/ui/wizards/dialogfields/IComboButtonAdapter.java >=================================================================== >--- src/org/eclipse/mtj/internal/ui/wizards/dialogfields/IComboButtonAdapter.java (revision 0) >+++ src/org/eclipse/mtj/internal/ui/wizards/dialogfields/IComboButtonAdapter.java (revision 0) >@@ -0,0 +1,24 @@ >+/** >+ * Copyright (c) 2009 Motorola. >+ * >+ * 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: >+ * Fernando Rocha (Motorola) - Initial implementation >+ */ >+package org.eclipse.mtj.internal.ui.wizards.dialogfields; >+ >+/** >+ * Change listener used by <code>ComboButtonDialogField</code> >+ * >+ * @author Fernando Rocha >+ * @since 1.0 >+ */ >+public interface IComboButtonAdapter { >+ >+ void changeControlPressed(DialogField field); >+ >+} >Index: src/org/eclipse/mtj/internal/ui/messages.properties >=================================================================== >--- src/org/eclipse/mtj/internal/ui/messages.properties (revision 1344) >+++ src/org/eclipse/mtj/internal/ui/messages.properties (working copy) >@@ -302,7 +302,6 @@ > LocalizationPage_PageTitle=Add Localization Support. > LocalizationPage_text=Localization Data > LocalizationPage_title=Localization Data >-LocalizationWizard_failed_createLocalizationFile=Unable to resolve Localization Data location. > LocalizationWizard_window_title=Localization Wizard > LogAndDisplaySafeRunnable_handleException_message=An error occurred during {0} > LogAndDisplaySafeRunnable_handleException_title=Error Occurred >@@ -725,6 +724,10 @@ > NewMidletProjectWizardPageOne_locationGroup_externalLocationRadio=Create project from existing source > NewMidletProjectWizardPageOne_locationGroup_projectLocation=Directory: > NewMidletProjectWizardPageOne_locationGroup_workspaceLocationRadio=Create new project in workspace >+NewMidletProjectWizardPageOne_locationGroup_workingSetsButton=Add project to working sets >+NewMidletProjectWizardPageOne_workingSetGroup_contents=Working Sets >+NewMidletProjectWizardPageOne_workingSetGroup_selection=Working Sets: >+NewMidletProjectWizardPageOne_workingSetGroup_select_button=Select... > NewMidletProjectWizardPageOne_validate_devicecount_error=You must add at least one configuration. > NewMidletProjectWizardPageOne_validate_jadname_error_extension=Invalid jad name, missing the \".jad\" file extension. > NewMidletProjectWizardPageOne_validate_jadname_error_emptyname=Invalid jad name, missing the file name. >@@ -740,21 +743,39 @@ > NewMidletProjectWizardPageOne_projectNameGroup_update_error_workspace2=The selected existing source location in the workspace root does not exist > NewMidletProjectWizardPageOne_title=Create a MIDlet Project > >-NewMidletProjectWizardPageTwo_changeToNewProject_errordialog_message=An error occurred while creating project. Check log for details. >-NewMidletProjectWizardPageTwo_changeToNewProject_errordialog_title=New MIDlet Project >-NewMidletProjectWizardPageTwo_createBackup_error_1=Problem while creating backup for '' >-NewMidletProjectWizardPageTwo_createBackup_error_2='' >-NewMidletProjectWizardPageTwo_doRemoveProject_taskname=Removing project... >-NewMidletProjectWizardPageTwo_performFinish_monitor_taskname=Creating project... >-NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_message=An error occurred while creating project. Check log for details. >-NewMidletProjectWizardPageTwo_rememberExisitingFolders_errordialog_title=New MIDlet Project >-NewMidletProjectWizardPageTwo_restoreExistingFiles_problem_restoring_dotclasspath=Problem while restoring backup for .classpath >-NewMidletProjectWizardPageTwo_restoreExistingFiles_problem_restoring_dotproject=Problem while restoring backup for .project >-NewMidletProjectWizardPageTwo_updateProject_errordialog_message=An error occurred while creating project. Check log for details. >-NewMidletProjectWizardPageTwo_updateProject_errordialog_title=New MIDlet Project >-NewMidletProjectWizardPageTwo_updateProject_fail_read_metadata=Could not read project metadata >-NewMidletProjectWizardPageTwo_updateProject_monitor_buildpath_name=Initializing build path >-NewMidletProjectWizardPageTwo_updateProject_taskname=Initializing project... >+NewMidletProjectWizardPageTwo_description=Enter the data required to generate the MIDlet Project >+NewMidletProjectWizardPageTwo_propertiesGroup_contents=MIDlet Project Properties >+NewMidletProjectWizardPageTwo_propertiesGroup_midletName=MIDlet Name >+NewMidletProjectWizardPageTwo_propertiesGroup_midletVendor=MIDlet Vendor >+NewMidletProjectWizardPageTwo_propertiesGroup_midletVersion=MIDlet Version >+NewMidletProjectWizardPageTwo_propertiesGroup_meConfiguration=Microedition Configuration >+NewMidletProjectWizardPageTwo_propertiesGroup_meProfile=Microedition Profile >+NewMidletProjectWizardPageTwo_optionsGroup_contents=MIDlet Project Options >+NewMidletProjectWizardPageTwo_optionsGroup_enablePreprocessing=Enable Preprocessing Support >+NewMidletProjectWizardPageTwo_optionsGroup_enableLocalization=Enable Localization Support >+NewMidletProjectWizardPageTwo_optionsGroup_propertiesFolder=Properties Folder: >+NewMidletProjectWizardPageTwo_optionsGroup_package=Package: >+NewMidletProjectWizardPageTwo_optionsGroup_packageEmpty=Package: Names cannot be empty. >+NewMidletProjectWizardPageTwo_optionsGroup_packageUpperCase=Discouraged package name. By convention, package names usually start with a lowercase letter. >+NewMidletProjectWizardPageTwo_optionsGroup_packageError=Invalid package name. \"{0}\" is not a valid Java identifier >+NewMidletProjectWizardPageTwo_optionsGroup_enableJMUnit=Enable JMUnit Support >+NewMidletProjectWizardPageTwo_title=MIDlet Project Content >+ >+NewMidletProjectWizardPageThree_changeToNewProject_errordialog_message=An error occurred while creating project. Check log for details. >+NewMidletProjectWizardPageThree_changeToNewProject_errordialog_title=New MIDlet Project >+NewMidletProjectWizardPageThree_createBackup_error_1=Problem while creating backup for '' >+NewMidletProjectWizardPageThree_createBackup_error_2='' >+NewMidletProjectWizardPageThree_doRemoveProject_taskname=Removing project... >+NewMidletProjectWizardPageThree_performFinish_monitor_taskname=Creating project... >+NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_message=An error occurred while creating project. Check log for details. >+NewMidletProjectWizardPageThree_rememberExisitingFolders_errordialog_title=New MIDlet Project >+NewMidletProjectWizardPageThree_restoreExistingFiles_problem_restoring_dotclasspath=Problem while restoring backup for .classpath >+NewMidletProjectWizardPageThree_restoreExistingFiles_problem_restoring_dotproject=Problem while restoring backup for .project >+NewMidletProjectWizardPageThree_updateProject_errordialog_message=An error occurred while creating project. Check log for details. >+NewMidletProjectWizardPageThree_updateProject_errordialog_title=New MIDlet Project >+NewMidletProjectWizardPageThree_updateProject_fail_read_metadata=Could not read project metadata >+NewMidletProjectWizardPageThree_updateProject_monitor_buildpath_name=Initializing build path >+NewMidletProjectWizardPageThree_updateProject_taskname=Initializing project... > > NewMidletProjectWizardPageLibrary_title=Select a Library > NewMidletProjectWizardPageLibrary_description=Select the libraries to be included in your project classpath and exported in the deployable JAR file.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
wds057
:
review-
Actions:
View
|
Diff
Attachments on
bug 261873
:
123260
|
123261
|
138038
|
138568
|
139348
|
141541
|
141681
|
142991