Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornhauge2010-03-09 23:19:57 +0000
committernhauge2010-03-09 23:19:57 +0000
commitbb09b803fff325c82ac4108244e10dfa251de4f0 (patch)
tree8097c0484142f699d39fa337a52fb5eb7d835684 /jpa/plugins/org.eclipse.jpt.jaxb.ui/src
parent3167724be874e7f5149e3cc6553ed2ec2fa01079 (diff)
downloadwebtools.dali-bb09b803fff325c82ac4108244e10dfa251de4f0.tar.gz
webtools.dali-bb09b803fff325c82ac4108244e10dfa251de4f0.tar.xz
webtools.dali-bb09b803fff325c82ac4108244e10dfa251de4f0.zip
296502 - updates to the class gen wizard that adds standard Eclipse controls for source folder and package selection. Also changed Generic vs Moxy logic.
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jaxb.ui/src')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JptJaxbUiMessages.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ClassesGeneratorWizardPage.java183
2 files changed, 94 insertions, 93 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JptJaxbUiMessages.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JptJaxbUiMessages.java
index 882186ad5d..3ede138705 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JptJaxbUiMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JptJaxbUiMessages.java
@@ -28,16 +28,12 @@ public class JptJaxbUiMessages {
public static String ClassesGeneratorWizardPage_usesMoxyImplementation;
public static String ClassesGeneratorWizardPage_settingsGroupTitle;
- public static String ClassesGeneratorWizardPage_targetFolder;
- public static String ClassesGeneratorWizardPage_targetPackage;
public static String ClassesGeneratorWizardPage_catalog;
public static String ClassesGeneratorWizardPage_bindingsFiles;
public static String ClassesGeneratorWizardPage_addButton;
public static String ClassesGeneratorWizardPage_removeButton;
public static String ClassesGeneratorWizardPage_chooseABindingsFile;
- public static String ClassesGeneratorWizardPage_targetFolderCannotBeEmpty;
-
public static String ClassesGeneratorWizardPage_jaxbLibrariesNotAvailable;
public static String ClassesGeneratorWizardPage_moxyLibrariesNotAvailable;
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ClassesGeneratorWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ClassesGeneratorWizardPage.java
index 9336d43bd8..80e3ff3da4 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ClassesGeneratorWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ClassesGeneratorWizardPage.java
@@ -12,14 +12,15 @@ package org.eclipse.jpt.jaxb.ui.internal.wizards;
import java.util.ArrayList;
import java.util.Collection;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IBaseLabelProvider;
@@ -30,7 +31,6 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.jaxb.core.internal.ClassesGenerator;
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
@@ -40,8 +40,6 @@ import org.eclipse.jpt.utility.internal.ArrayTools;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
@@ -61,24 +59,30 @@ import org.osgi.framework.Bundle;
/**
* ClassesGeneratorWizardPage
*/
-public class ClassesGeneratorWizardPage extends WizardPage {
+public class ClassesGeneratorWizardPage extends NewTypeWizardPage {
static public String JPT_JAXB_ECLIPSELINK_UI_PLUGIN_ID = "org.eclipse.jpt.eclipselink.jaxb.ui"; //$NON-NLS-1$
private final JpaProject jpaProject;
private SettingsGroup settingsGroup;
+ private String targetFolder;
+ private String targetPackage;
+
private Button usesMoxyCheckBox;
- private boolean usesMoxy = true; // always use Moxy when jaxb.eclipselink plugin is present
+ private boolean usesMoxy;
// ********** constructor **********
public ClassesGeneratorWizardPage(JpaProject jpaProject, String xmlSchemaName) {
- super("Classes Generator"); //$NON-NLS-1$
+ super(true, "Classes Generator"); //$NON-NLS-1$
if (jpaProject == null) {
throw new NullPointerException();
}
this.jpaProject = jpaProject;
+ // default usesMoxy to true only when JPT EclipseLink bundle exists and MOXy is on the classpath
+ this.usesMoxy = (jptEclipseLinkJaxbBundleExists() && moxyIsOnClasspath());
+
this.setTitle(NLS.bind(JptJaxbUiMessages.ClassesGeneratorWizardPage_title, xmlSchemaName));
this.setDescription(JptJaxbUiMessages.ClassesGeneratorWizardPage_desc);
}
@@ -88,6 +92,8 @@ public class ClassesGeneratorWizardPage extends WizardPage {
public void createControl(Composite parent) {
this.setPageComplete(false);
this.setControl(this.buildTopLevelControl(parent));
+
+ initContainerPage(this.jpaProject.getJavaProject());
}
private Control buildTopLevelControl(Composite parent) {
@@ -96,13 +102,12 @@ public class ClassesGeneratorWizardPage extends WizardPage {
this.settingsGroup = new SettingsGroup(composite);
- // add checkbox only if jaxb.eclipselink plugin not present
- if( ! jptEclipseLinkJaxbBundleExists()) {
+ // add checkbox only if jpt.eclipselink.jaxb plugin is available
+ // and EclipseLink MOXy is not on the classpath
+ if(jptEclipseLinkJaxbBundleExists() && ! moxyIsOnClasspath()) {
this.usesMoxyCheckBox = this.buildUsesMoxyCheckBox(composite);
}
- this.validateProjectClasspath();
-
Dialog.applyDialogFont(parent);
return composite;
}
@@ -111,7 +116,6 @@ public class ClassesGeneratorWizardPage extends WizardPage {
Button checkBox = new Button(parent, SWT.CHECK);
checkBox.setText(JptJaxbUiMessages.ClassesGeneratorWizardPage_usesMoxyImplementation);
- this.setUsesMoxy(false);
checkBox.setSelection(this.usesMoxy());
checkBox.addSelectionListener(this.buildUsesMoxySelectionListener());
@@ -134,11 +138,11 @@ public class ClassesGeneratorWizardPage extends WizardPage {
// ********** intra-wizard methods **********
protected String getTargetFolder() {
- return this.settingsGroup.getTargetFolder();
+ return this.targetFolder;
}
protected String getTargetPackage() {
- return this.settingsGroup.getTargetPackage();
+ return this.targetPackage;
}
protected String getCatalog() {
@@ -168,33 +172,31 @@ public class ClassesGeneratorWizardPage extends WizardPage {
}
private void validateProjectClasspath() {
- this.setMessage(null);
- if(this.usesMoxy()) {
- if(this.projectJreIs15OrLess()) {
- if( ! this.genericJaxbIsOnClasspath() || ! this.moxyIsOnClasspath()) {
- this.displayWarning(JptJaxbUiMessages.ClassesGeneratorWizardPage_moxyLibrariesNotAvailable);
- }
- }
- else {
- if( ! this.moxyIsOnClasspath()) {
- this.displayWarning(JptJaxbUiMessages.ClassesGeneratorWizardPage_moxyLibrariesNotAvailable);
- }
- }
+ //this line will suppress the "default package" warning (which doesn't really apply here
+ //as the JAXB gen uses an org.example.schemaName package by default) and will clear the classpath warnings when necessary
+ setMessage(null);
+
+ if ( ! this.genericJaxbIsOnClasspath()) {
+ this.displayWarning(JptJaxbUiMessages.ClassesGeneratorWizardPage_jaxbLibrariesNotAvailable);
}
- else {
- if(this.projectJreIs15OrLess() && ! this.genericJaxbIsOnClasspath()) {
- this.displayWarning(JptJaxbUiMessages.ClassesGeneratorWizardPage_jaxbLibrariesNotAvailable);
- }
+ else if (this.usesMoxy() && ! this.moxyIsOnClasspath()) {
+ //this message is being truncated by the wizard width in some cases
+ this.displayWarning(JptJaxbUiMessages.ClassesGeneratorWizardPage_moxyLibrariesNotAvailable);
}
+
+ //this code will intelligently remove our classpath warnings when they are present but no longer apply (as an alternative
+ //to setting the message to null continuously as is currently done)
+// else if( this.getMessage() != null){
+// if (this.getMessage().equals(JptJaxbUiMessages.ClassesGeneratorWizardPage_jaxbLibrariesNotAvailable) ||
+// this.getMessage().equals(JptJaxbUiMessages.ClassesGeneratorWizardPage_moxyLibrariesNotAvailable)) {
+// setMessage(null);
+// }
+// }
}
private void displayWarning(String message) {
this.setMessage(message, WARNING);
}
-
- private void displayError(String message) {
- this.setMessage(message, ERROR);
- }
/**
* Test if the Jaxb compiler is on the classpath.
@@ -223,27 +225,62 @@ public class ClassesGeneratorWizardPage extends WizardPage {
}
}
- /**
- * Test if the project's JDK version is 1.5 or less..
- */
- private boolean projectJreIs15OrLess() {
- IVMInstall vm;
- try {
- vm = JavaRuntime.getVMInstall(this.jpaProject.getJavaProject());
+ // ********** overrides **********
+
+
+
+ @Override
+ protected IStatus packageChanged() {
+ IStatus status = super.packageChanged();
+ IPackageFragment packageFragment = getPackageFragment();
+ if (!status.matches(IStatus.ERROR)) {
+ this.targetPackage = packageFragment.getElementName();
}
- catch (CoreException e) {
- throw new RuntimeException(e);
+ return status;
+ }
+
+ @Override
+ protected IStatus containerChanged() {
+ IStatus status = super.containerChanged();
+ String srcFolder = getPackageFragmentRootText();
+ if( !status.matches(IStatus.ERROR) ){
+ this.targetFolder = srcFolder.substring(srcFolder.indexOf("/") + 1);
+ }
+ return status;
+ }
+
+ @Override
+ protected void handleFieldChanged(String fieldName) {
+ super.handleFieldChanged(fieldName);
+ if (this.fContainerStatus.matches(IStatus.ERROR)) {
+ updateStatus(fContainerStatus);
+ }else if( ! this.fPackageStatus.matches(IStatus.OK) ) {
+ updateStatus(fPackageStatus);
+ } else {
+ updateStatus(Status.OK_STATUS);
}
- String vmName = vm.getName(); // format: jdk1.5.0_18
- return (vmName.startsWith("jdk1.4") || vmName.startsWith("jdk1.5")); //$NON-NLS-1$
+ validateProjectClasspath();
+ }
+
+ /**
+ * Override setVisible to insure that our more important warning
+ * message about classpath problems is displayed to the user first.
+ */
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ validateProjectClasspath();
}
+ @Override
+ public final void performHelp() {
+ //TODO We need a help ID for JAXB Generation
+ }
+
// ********** SettingsGroup class **********
private class SettingsGroup {
- private final Text targetFolderText;
- private final Text targetPackageText;
private final Text catalogText;
private final ArrayList<String> bindingsFileNames;
@@ -253,17 +290,17 @@ public class ClassesGeneratorWizardPage extends WizardPage {
private SettingsGroup(Composite composite) {
super();
Group group = new Group(composite, SWT.NONE);
- group.setLayout(new GridLayout(3, false)); // false = do not make columns equal width
+ group.setLayout(new GridLayout(4, false)); // false = do not make columns equal width
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
group.setText(JptJaxbUiMessages.ClassesGeneratorWizardPage_settingsGroupTitle);
// TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(this.group, JpaHelpContextIds.XXX);
- // Destination folder
- this.buildLabel(group, 1, JptJaxbUiMessages.ClassesGeneratorWizardPage_targetFolder);
- this.targetFolderText = this.buildTargetFolderText(group);
- // Target package
- this.buildLabel(group, 1, JptJaxbUiMessages.ClassesGeneratorWizardPage_targetPackage);
- this.targetPackageText = this.buildText(group);
+ // Source folder
+ createContainerControls(group, 4);
+
+ // Package
+ createPackageControls(group, 4);
+
// Catalog
this.buildLabel(group, 1, JptJaxbUiMessages.ClassesGeneratorWizardPage_catalog);
this.catalogText = this.buildText(group);
@@ -276,14 +313,6 @@ public class ClassesGeneratorWizardPage extends WizardPage {
// ********** intra-wizard methods **********
- protected String getTargetFolder() {
- return this.targetFolderText.getText();
- }
-
- protected String getTargetPackage() {
- return this.targetPackageText.getText();
- }
-
protected String getCatalog() {
return this.catalogText.getText();
}
@@ -307,28 +336,8 @@ public class ClassesGeneratorWizardPage extends WizardPage {
Text text = new Text(parent, SWT.BORDER);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- //Filler column
+ //Filler columns
new Label(parent, SWT.NONE);
- return text;
- }
-
- private Text buildTargetFolderText(Composite parent) {
-
- Text text = new Text(parent, SWT.BORDER);
- text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- text.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- if(validateTargetFolderText()) {
- validateProjectClasspath();
- setPageComplete(true);
- }
- else {
- displayError(JptJaxbUiMessages.ClassesGeneratorWizardPage_targetFolderCannotBeEmpty);
- setPageComplete(false);
- }
- }
- });
- //Filler column
new Label(parent, SWT.NONE);
return text;
}
@@ -467,10 +476,6 @@ public class ClassesGeneratorWizardPage extends WizardPage {
layout.addColumnData(new ColumnWeightData(50, true));
}
- private boolean validateTargetFolderText() {
-
- return ! StringTools.stringIsEmpty(getTargetFolder());
- }
}
// ********** inner class **********

Back to the top