diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui')
15 files changed, 1196 insertions, 317 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JptJaxbUiPlugin.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JptJaxbUiPlugin.java index 09ff02efec..480d529875 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JptJaxbUiPlugin.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JptJaxbUiPlugin.java @@ -15,6 +15,8 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.wst.xml.core.internal.XMLCorePlugin; +import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; /** * The activator class controls the plug-in life cycle @@ -29,10 +31,12 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; @SuppressWarnings("nls") public class JptJaxbUiPlugin extends AbstractUIPlugin { - // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.jpt.jaxb.ui"; + public static final String USER_CATALOG_ID = XMLCorePlugin.USER_CATALOG_ID; //$NON-NLS-1$ + public static final String DEFAULT_CATALOG_ID = XMLCorePlugin.DEFAULT_CATALOG_ID; //$NON-NLS-1$ + public static final String SYSTEM_CATALOG_ID = XMLCorePlugin.SYSTEM_CATALOG_ID; //$NON-NLS-1$ // ********** singleton ********** private static JptJaxbUiPlugin INSTANCE; @@ -87,7 +91,11 @@ public class JptJaxbUiPlugin extends AbstractUIPlugin return image; } - + // ********** XMLCorePlugin API ********** + + public ICatalog getDefaultXMLCatalog() { + return XMLCorePlugin.getDefault().getDefaultXMLCatalog(); + } // ********** constructors ********** public JptJaxbUiPlugin() { diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ClassesGeneratorUi.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ClassesGeneratorUi.java index fb515919b4..a6835fc1a0 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ClassesGeneratorUi.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ClassesGeneratorUi.java @@ -10,23 +10,17 @@ package org.eclipse.jpt.jaxb.ui.internal; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.WorkspaceJob; -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.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jpt.jaxb.core.internal.ClassesGenerator; import org.eclipse.jpt.jaxb.core.internal.ClassesGeneratorExtensionOptions; import org.eclipse.jpt.jaxb.core.internal.ClassesGeneratorOptions; +import org.eclipse.jpt.jaxb.core.internal.GenerateJaxbClassesJob; +import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin; import org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen.ClassesGeneratorWizard; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.swt.widgets.Display; @@ -37,7 +31,7 @@ import org.eclipse.swt.widgets.Shell; */ public class ClassesGeneratorUi { private final IJavaProject javaProject; - private final String xmlSchemaName; + private final String schemaPathOrUri; // ********** static methods ********** @@ -52,13 +46,13 @@ public class ClassesGeneratorUi { } // ********** constructors ********** - private ClassesGeneratorUi(IJavaProject javaProject, String xmlSchemaName) { + private ClassesGeneratorUi(IJavaProject javaProject, String schemaPathOrUri) { super(); - if(javaProject == null || StringTools.stringIsEmpty(xmlSchemaName)) { + if(javaProject == null || StringTools.stringIsEmpty(schemaPathOrUri)) { throw new NullPointerException(); } this.javaProject = javaProject; - this.xmlSchemaName = xmlSchemaName; + this.schemaPathOrUri = schemaPathOrUri; } // ********** generate ********** @@ -66,7 +60,7 @@ public class ClassesGeneratorUi { * prompt the user with a wizard */ protected void generate() { - ClassesGeneratorWizard wizard = new ClassesGeneratorWizard(this.javaProject, this.xmlSchemaName); + ClassesGeneratorWizard wizard = new ClassesGeneratorWizard(this.javaProject, this.schemaPathOrUri); WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard); dialog.create(); int returnCode = dialog.open(); @@ -81,14 +75,14 @@ public class ClassesGeneratorUi { ClassesGeneratorOptions generatorOptions = wizard.getGeneratorOptions(); ClassesGeneratorExtensionOptions generatorExtensionOptions = wizard.getGeneratorExtensionOptions(); - if(this.displayGeneratingClassesWarning()) { - this.run(outputDir, targetPackage, catalog, usesMoxy, bindingsFileNames, generatorOptions, generatorExtensionOptions); + if(this.displayOverridingClassesWarning(generatorOptions)) { + this.generateJaxbClasses(outputDir, targetPackage, catalog, usesMoxy, bindingsFileNames, generatorOptions, generatorExtensionOptions); } } // ********** internal methods ********** - private void run( + private void generateJaxbClasses( String outputDir, String targetPackage, String catalog, @@ -97,144 +91,73 @@ public class ClassesGeneratorUi { ClassesGeneratorOptions generatorOptions, ClassesGeneratorExtensionOptions generatorExtensionOptions) { - WorkspaceJob job = new GenerateEntitiesJob( - this.javaProject, - this.xmlSchemaName, - outputDir, - targetPackage, - catalog, - usesMoxyGenerator, - bindingsFileNames, - generatorOptions, - generatorExtensionOptions); - job.schedule(); - } - - private boolean displayGeneratingClassesWarning() { + try { + WorkspaceJob job = new GenerateJaxbClassesJob( + this.javaProject, + this.schemaPathOrUri, + outputDir, + targetPackage, + catalog, + usesMoxyGenerator, + bindingsFileNames, + generatorOptions, + generatorExtensionOptions); + job.schedule(); + } + catch(RuntimeException re) { + JptJaxbUiPlugin.log(re); - return MessageDialog.openQuestion( - this.getCurrentShell(), - JptJaxbUiMessages.ClassesGeneratorUi_generatingClassesWarningTitle, - JptJaxbUiMessages.ClassesGeneratorUi_generatingClassesWarningMessage); + String msg = re.getMessage(); + String message = (msg == null) ? re.toString() : msg; + this.logError(message); + } } - private Shell getCurrentShell() { - return Display.getCurrent().getActiveShell(); + private void logError(String message) { + this.displayError(message); } - // ********** Runnable Class ********** - - private static class GenerateEntitiesJob extends WorkspaceJob { - private final IJavaProject javaProject; - private final String xmlSchemaName; - private final String outputDir; - private final String targetPackage; - private final String catalog; - private final boolean usesMoxyGenerator; - private final String[] bindingsFileNames; - private final ClassesGeneratorOptions generatorOptions; - private final ClassesGeneratorExtensionOptions generatorExtensionOptions; - - // ********** constructors ********** - - public GenerateEntitiesJob( - IJavaProject javaProject, - String xmlSchemaName, - String outputDir, - String targetPackage, - String catalog, - boolean usesMoxyGenerator, - String[] bindingsFileNames, - ClassesGeneratorOptions generatorOptions, - ClassesGeneratorExtensionOptions generatorExtensionOptions) { - - super(JptJaxbUiMessages.ClassesGeneratorUi_generatingEntities); - this.javaProject = javaProject; - this.xmlSchemaName = xmlSchemaName; - this.outputDir = outputDir; - this.targetPackage = targetPackage; - this.catalog = catalog; - this.usesMoxyGenerator = usesMoxyGenerator; - this.bindingsFileNames = bindingsFileNames; - this.generatorOptions = generatorOptions; - this.generatorExtensionOptions = generatorExtensionOptions; - this.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(this.javaProject.getProject())); - } - - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - SubMonitor sm = SubMonitor.convert(monitor, JptJaxbUiMessages.ClassesGeneratorUi_generatingEntitiesTask, 1); - try { - this.entitiesGeneratorGenerate(this.javaProject, - this.xmlSchemaName, - this.outputDir, - this.targetPackage, - this.catalog, - this.usesMoxyGenerator, - this.bindingsFileNames, - this.generatorOptions, - this.generatorExtensionOptions, - sm.newChild(1)); - } - catch (OperationCanceledException e) { - return Status.CANCEL_STATUS; - // fall through and tell monitor we are done - } - catch (RuntimeException re) { - String msg = re.getMessage(); - String message = (msg == null) ? re.toString() : msg; - - this.logError(message); - throw new RuntimeException(re); - } - return Status.OK_STATUS; + private void displayError(String message) { + MessageDialog.openError( + this.getShell(), + JptJaxbUiMessages.ClassesGeneratorWizard_errorDialogTitle, + message + ); } - private void entitiesGeneratorGenerate(IJavaProject javaProject, - String xmlSchemaName, - String outputDir, - String targetPackage, - String catalog, - boolean usesMoxyGenerator, - String[] bindingsFileNames, - ClassesGeneratorOptions generatorOptions, - ClassesGeneratorExtensionOptions generatorExtensionOptions, - IProgressMonitor monitor) { - - ClassesGenerator.generate(javaProject, - xmlSchemaName, - outputDir, - targetPackage, - catalog, - usesMoxyGenerator, - bindingsFileNames, - generatorOptions, - generatorExtensionOptions, - monitor); - return; + private Shell getShell() { + Display display = Display.getCurrent(); + Shell shell = (display == null) ? null : display.getActiveShell(); + if(shell == null && display != null) { + Shell[] shells = display.getShells(); + if(shells.length > 0) + shell = shells[0]; } + return shell; + } - private void logError(String message) { - this.displayError(message); + private boolean isOverridingClasses(ClassesGeneratorOptions generatorOptions) { + if(generatorOptions == null) { + throw new NullPointerException(); } - - private void displayError(String message) { - MessageDialog.openError( - this.getShell(), - JptJaxbUiMessages.ClassesGeneratorWizard_errorDialogTitle, - message - ); + if(generatorOptions.showsVersion() || generatorOptions.showsHelp()) { + return false; } + return true; + } - private Shell getShell() { - Display display = Display.getCurrent(); - Shell shell = (display == null) ? null : display.getActiveShell(); - if (shell == null && display != null) { - Shell[] shells = display.getShells(); - if (shells.length > 0) - shell = shells[0]; - } - return shell; + private boolean displayOverridingClassesWarning(ClassesGeneratorOptions generatorOptions) { + + if( ! this.isOverridingClasses(generatorOptions)) { + return true; } + return MessageDialog.openQuestion( + this.getCurrentShell(), + JptJaxbUiMessages.ClassesGeneratorUi_generatingClassesWarningTitle, + JptJaxbUiMessages.ClassesGeneratorUi_generatingClassesWarningMessage); + } + + private Shell getCurrentShell() { + return Display.getCurrent().getActiveShell(); } } 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 6abf2ec125..4130e9daab 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 @@ -23,6 +23,19 @@ public class JptJaxbUiMessages { public static String ClassesGeneratorWizard_errorDialogTitle; public static String ClassesGeneratorWizard_couldNotCreate; + public static String ClassesGeneratorProjectWizardPage_title; + + + public static String SchemaWizardPage_title; + public static String SchemaWizardPage_desc; + + public static String SchemaWizardPage_xmlCatalogTableTitle; + public static String SchemaWizardPage_xmlCatalogKeyColumn; + public static String SchemaWizardPage_xmlCatalogUriColumn; + + public static String SchemaWizardPage_errorUriCannotBeLocated; + + public static String ClassesGeneratorWizardPage_title; public static String ClassesGeneratorWizardPage_desc; @@ -36,6 +49,12 @@ public class JptJaxbUiMessages { public static String ClassesGeneratorWizardPage_chooseABindingsFile; public static String ClassesGeneratorWizardPage_chooseACatalog; + public static String ClassesGeneratorWizardPage_sourceFolderSelectionDialog_title; + public static String ClassesGeneratorWizardPage_chooseSourceFolderDialog_desc; + + public static String ClassesGeneratorWizardPage_jaxbLibrariesNotAvailable; + public static String ClassesGeneratorWizardPage_moxyLibrariesNotAvailable; + public static String ClassesGeneratorOptionsWizardPage_title; public static String ClassesGeneratorOptionsWizardPage_desc; @@ -68,10 +87,6 @@ public class JptJaxbUiMessages { public static String ClassesGeneratorExtensionOptionsWizardPage_classpath; public static String ClassesGeneratorExtensionOptionsWizardPage_additionalArguments; - public static String ClassesGeneratorWizardPage_jaxbLibrariesNotAvailable; - - public static String ClassesGeneratorWizardPage_moxyLibrariesNotAvailable; - public static String ClassesGeneratorUi_generatingEntities; public static String ClassesGeneratorUi_generatingEntitiesTask; @@ -85,6 +100,8 @@ public class JptJaxbUiMessages { public static String ProjectWizardPage_desc; public static String ProjectWizardPage_project; + public static String SchemaGeneratorProjectWizardPage_title; + public static String SchemaGeneratorWizardPage_title; public static String SchemaGeneratorWizardPage_desc; diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/ProjectWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java index 164072fecb..9e62a9eddf 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/ProjectWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java @@ -7,17 +7,20 @@ * Contributors: * Oracle - initial API and implementation *******************************************************************************/ -package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen; +package org.eclipse.jpt.jaxb.ui.internal.wizards; -import java.util.Comparator; import java.util.Iterator; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; import org.eclipse.jpt.utility.internal.ArrayTools; @@ -37,8 +40,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; -import com.ibm.icu.text.Collator; - /** * ProjectWizardPage */ @@ -47,18 +48,59 @@ public class ProjectWizardPage extends WizardPage private IJavaProject javaProject; private ProjectGroup projectGroup; + // ********** static methods ********** + + public static IJavaProject getJavaProjectFromSelection(IStructuredSelection selection) { + if(selection == null) { + return null; + } + Object firstElement = selection.getFirstElement(); + if(firstElement instanceof IJavaProject) { + return (IJavaProject)firstElement; + } + else if(firstElement instanceof IResource) { + IProject project = ((IResource) firstElement).getProject(); + return getJavaProjectFrom(project); + } + else if(firstElement instanceof IJavaElement) { + return ((IJavaElement)firstElement).getJavaProject(); + } + return null; + } + + public static IJavaProject getJavaProjectFrom(IProject project) { + return (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class)); + } + + // ********** constructor ********** + public ProjectWizardPage() { super("Java Project"); //$NON-NLS-1$ - - this.setTitle(JptJaxbUiMessages.SchemaGeneratorWizardPage_title); + this.setDescription(JptJaxbUiMessages.ProjectWizardPage_desc); } + + public ProjectWizardPage(IJavaProject javaProject) { + this(); + + this.javaProject = javaProject; + } + + // ********** IDialogPage implementation ********** public void createControl(Composite parent) { this.setPageComplete(false); this.setControl(this.buildTopLevelControl(parent)); } + // ********** intra-wizard methods ********** + + public IJavaProject getJavaProject() { + return this.javaProject; + } + + // ********** internal methods ********** + private Control buildTopLevelControl(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new FillLayout()); @@ -67,17 +109,8 @@ public class ProjectWizardPage extends WizardPage // PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, HELP_CONTEXT_ID); return composite; } - - // ********** intra-wizard methods ********** - - protected IJavaProject getProject() { - return this.javaProject; - } - - // ********** internal methods ********** - - private void setProject(IJavaProject project) { + private void setJavaProject(IJavaProject project) { this.javaProject = project; } @@ -87,8 +120,8 @@ public class ProjectWizardPage extends WizardPage if( ! StringTools.stringIsEmpty(projectName)) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - this.setProject(JavaCore.create(project)); - setPageComplete(true); + this.setJavaProject(JavaCore.create(project)); + this.setPageComplete(true); } } @@ -110,8 +143,8 @@ public class ProjectWizardPage extends WizardPage this.buildLabel(composite, JptJaxbUiMessages.ProjectWizardPage_project); this.projectCombo = this.buildProjectCombo(composite, this.buildProjectComboSelectionListener()); this.updateProjectCombo(); - - setPageComplete(false); + + setPageComplete( ! StringTools.stringIsEmpty(this.getProjectName())); } // ********** listeners ********** @@ -149,7 +182,8 @@ public class ProjectWizardPage extends WizardPage protected void updateProjectCombo() { this.projectCombo.removeAll(); - for (String name : this.getJavaProjectsNames()) { + + for (String name : this.getSortedJavaProjectsNames()) { this.projectCombo.add(name); } if(javaProject != null) { @@ -157,13 +191,19 @@ public class ProjectWizardPage extends WizardPage } } - private Iterable<String> getJavaProjectsNames() { - return new TransformationIterable<IProject, String>(this.getJavaProjects()) { - @Override - protected String transform(IProject project) { - return project.getName(); - } - }; + private String[] getSortedJavaProjectsNames() { + return ArrayTools.sort(getJavaProjectsNames()); + } + + private String[] getJavaProjectsNames() { + return ArrayTools.array( + new TransformationIterable<IProject, String>(this.getJavaProjects()) { + @Override + protected String transform(IProject project) { + return project.getName(); + } + }, + new String[0]); } private Iterable<IProject> getJavaProjects() { @@ -181,22 +221,9 @@ public class ProjectWizardPage extends WizardPage } private Iterator<IProject> getProjects() { - return new ArrayIterator<IProject>(this.sortedProjects()); - } - - private IProject[] sortedProjects() { - - return ArrayTools.sort(ResourcesPlugin.getWorkspace().getRoot().getProjects(), this.projectNameComparator()); + return new ArrayIterator<IProject>(ResourcesPlugin.getWorkspace().getRoot().getProjects()); } - private Comparator<IProject> projectNameComparator() { - return new Comparator<IProject>() { - public int compare(IProject project1, IProject project2) { - return Collator.getInstance().compare(project1.getName(), project2.getName()); - } - }; - } - // ********** UI components ********** private Label buildLabel(Composite parent, String text) { diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorExtensionOptionsWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorExtensionOptionsWizardPage.java index 1e867a57d9..c0300c5825 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorExtensionOptionsWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorExtensionOptionsWizardPage.java @@ -95,7 +95,7 @@ public class ClassesGeneratorExtensionOptionsWizardPage extends WizardPage layout.marginWidth = 0; composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(this.group, JpaHelpContextIds.XXX); + // TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(this.group, HELP_CONTEXT_ID); this.allowsExtensionsCheckBox = this.buildAllowsExtensionsCheckBox(composite, this.buildAllowsExtensionsSelectionListener()); diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorOptionsWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorOptionsWizardPage.java index e8f486e773..b040e0e316 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorOptionsWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorOptionsWizardPage.java @@ -9,9 +9,10 @@ *******************************************************************************/ package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jface.wizard.IWizard; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; import org.eclipse.jpt.utility.internal.StringTools; @@ -36,17 +37,11 @@ public class ClassesGeneratorOptionsWizardPage extends WizardPage private ProxyOptionsComposite proxyOptionsComposite; private Options1Composite options1Composite; private Options2Composite options2Composite; - - private final IJavaProject javaProject; // ********** constructor ********** - protected ClassesGeneratorOptionsWizardPage(IJavaProject javaProject) { + protected ClassesGeneratorOptionsWizardPage() { super("Classes Generator Options"); //$NON-NLS-1$ - if (javaProject == null) { - throw new NullPointerException(); - } - this.javaProject = javaProject; this.initialize(); } @@ -189,10 +184,13 @@ public class ClassesGeneratorOptionsWizardPage extends WizardPage private String makeRelativeToProjectPath(String filePath) { Path path = new Path(filePath); - IPath relativePath = path.makeRelativeTo(this.javaProject.getProject().getLocation()); + IPath relativePath = path.makeRelativeTo(this.getProject().getLocation()); return relativePath.toOSString(); } + private IProject getProject() { + return ((ClassesGeneratorWizard)this.getWizard()).getJavaProject().getProject(); + } // ********** ProxyOptionsComposite ********** @@ -307,7 +305,8 @@ public class ClassesGeneratorOptionsWizardPage extends WizardPage * prompt the user to select a file and return it. */ private String promptProxyFile() { - String projectPath = ClassesGeneratorOptionsWizardPage.this.javaProject.getProject().getLocation().toString(); + IWizard wizard = ClassesGeneratorOptionsWizardPage.this.getWizard(); + String projectPath = ((ClassesGeneratorWizard)wizard).getJavaProject().getProject().getLocation().toString(); FileDialog dialog = new FileDialog(getShell()); dialog.setText(JptJaxbUiMessages.ClassesGeneratorOptionsWizardPage_chooseAProxyFile); diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java index b5900d43c4..137727c192 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java @@ -9,26 +9,36 @@ *******************************************************************************/ package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jpt.jaxb.core.internal.ClassesGeneratorExtensionOptions; import org.eclipse.jpt.jaxb.core.internal.ClassesGeneratorOptions; +import org.eclipse.jpt.jaxb.core.internal.GenerateJaxbClassesJob; import org.eclipse.jpt.jaxb.ui.JptJaxbUiIcons; import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin; import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; +import org.eclipse.jpt.jaxb.ui.internal.wizards.ProjectWizardPage; import org.eclipse.osgi.util.NLS; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWizard; /** * ClassesGeneratorWizard */ -public class ClassesGeneratorWizard extends Wizard { - - private final IJavaProject javaProject; - private final String xmlSchemaName; +public class ClassesGeneratorWizard extends Wizard implements IWorkbenchWizard { + private IJavaProject javaProject; + private String schemaPathOrUri; + protected IStructuredSelection selection; + private String destinationFolder; private String targetPackage; private String catalog; @@ -37,28 +47,62 @@ public class ClassesGeneratorWizard extends Wizard { private ClassesGeneratorOptions generatorOptions; private ClassesGeneratorExtensionOptions generatorExtensionOptions; + private ProjectWizardPage javaProjectWizardPage; + private SchemaWizardPage schemaWizardPage; + private ClassesGeneratorWizardPage settingsPage; private ClassesGeneratorOptionsWizardPage optionsPage; private ClassesGeneratorExtensionOptionsWizardPage extensionOptionsPage; + private boolean performsGeneration; // ********** constructor ********** - public ClassesGeneratorWizard(IJavaProject javaProject, String xmlSchemaName) { + public ClassesGeneratorWizard() { + super(); + this.performsGeneration = true; + } + + public ClassesGeneratorWizard(IJavaProject javaProject, String xsdSchemaPath) { super(); this.javaProject = javaProject; - this.xmlSchemaName = xmlSchemaName; + this.schemaPathOrUri = xsdSchemaPath; + + this.performsGeneration = false; + } + + // ********** IWorkbenchWizard implementation ********** + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.selection = selection; + this.setWindowTitle(JptJaxbUiMessages.ClassesGeneratorWizard_title); this.setDefaultPageImageDescriptor(JptJaxbUiPlugin.getImageDescriptor(JptJaxbUiIcons.CLASSES_GEN_WIZ_BANNER)); this.setNeedsProgressMonitor(true); } - // ********** overrides ********** + // ********** IWizard implementation ********** @Override public void addPages() { super.addPages(); - + + if(this.selection != null) { + this.javaProject = ProjectWizardPage.getJavaProjectFromSelection(this.selection); + + this.javaProjectWizardPage = new ProjectWizardPage(this.javaProject); + this.javaProjectWizardPage.setTitle(JptJaxbUiMessages.ClassesGeneratorProjectWizardPage_title); + this.addPage(this.javaProjectWizardPage); + + // SchemaWizardPage + IFile schemaSelected = SchemaWizardPage.getSourceSchemaFromSelection(this.selection); + if(schemaSelected == null) { + this.schemaWizardPage = new SchemaWizardPage(this.selection); + this.addPage(this.schemaWizardPage); + } + else { + this.schemaPathOrUri = this.makeRelativeToProjectPath(schemaSelected.getFullPath()); + } + } this.settingsPage = this.buildClassesGeneratorPage(); this.optionsPage = this.buildClassesGeneratorOptionsPage(); this.extensionOptionsPage = this.buildExtensionOptionsPage(); @@ -70,19 +114,140 @@ public class ClassesGeneratorWizard extends Wizard { @Override public boolean performFinish() { + + WizardPage currentPage = (WizardPage)getContainer().getCurrentPage(); + if(currentPage != null) { + if( ! currentPage.isPageComplete()) { + return false; + } + this.retrieveGeneratorSettings(); + this.retrieveGeneratorOptions(); + this.retrieveGeneratorExtensionOptions(); + + IFolder folder = this.getJavaProject().getProject().getFolder(this.destinationFolder); + this.createFolderIfNotExist(folder); + } + + if(this.performsGeneration) { + if(this.displayOverridingClassesWarning(this.generatorOptions)) { + this.generateJaxbClasses(); + } + } + + return true; + } + + @Override + public boolean canFinish() { + return (this.settingsPage.isPageComplete() && + this.optionsPage.isPageComplete() && + this.extensionOptionsPage.isPageComplete()); + } + + // ********** intra-wizard methods ********** + + public IJavaProject getJavaProject() { + if(this.javaProjectWizardPage != null) { + return this.javaProjectWizardPage.getJavaProject(); + } + return this.javaProject; + } + + public String getSchemaPathOrUri() { + if(this.schemaWizardPage != null) { + IFile schemaFile = this.schemaWizardPage.getSourceSchema(); + if(schemaFile != null) { + return this.makeRelativeToProjectPath(schemaFile.getFullPath()); + } + else { + return this.schemaWizardPage.getSourceURI(); + } + } + return this.schemaPathOrUri; + } - this.initializeGeneratorSettings(); + private String makeRelativeToProjectPath(IPath path) { + IPath relativePath = path.makeRelativeTo(this.getJavaProject().getProject().getFullPath()); + return relativePath.toOSString(); + } + + // ********** public methods ********** + + public String getDestinationFolder() { + return this.destinationFolder; + } + + public String getTargetPackage() { + return this.targetPackage; + } + + public String getCatalog() { + return this.catalog; + } + + public boolean usesMoxy() { + return this.usesMoxy; + } - this.initializeGeneratorOptions(); + public String[] getBindingsFileNames() { + return this.bindingsFileNames; + } + + public ClassesGeneratorOptions getGeneratorOptions() { + return this.generatorOptions; + } + + public ClassesGeneratorExtensionOptions getGeneratorExtensionOptions() { + return this.generatorExtensionOptions; + } + + // ********** internal methods ********** + + private boolean displayOverridingClassesWarning(ClassesGeneratorOptions generatorOptions) { - this.initializeGeneratorExtensionOptions(); + if( ! this.isOverridingClasses(generatorOptions)) { + return true; + } + return MessageDialog.openQuestion( + this.getShell(), + JptJaxbUiMessages.ClassesGeneratorUi_generatingClassesWarningTitle, + JptJaxbUiMessages.ClassesGeneratorUi_generatingClassesWarningMessage); + } - IFolder folder = this.javaProject.getProject().getFolder(this.destinationFolder); - this.createFolderIfNotExist(folder); + private boolean isOverridingClasses(ClassesGeneratorOptions generatorOptions) { + if(generatorOptions == null) { + throw new NullPointerException(); + } + if(generatorOptions.showsVersion() || generatorOptions.showsHelp()) { + return false; + } return true; } + + private void generateJaxbClasses() { + try { + WorkspaceJob job = new GenerateJaxbClassesJob( + this.getJavaProject(), + this.getSchemaPathOrUri(), + this.destinationFolder, + this.targetPackage, + this.catalog, + this.usesMoxy, + this.bindingsFileNames, + this.generatorOptions, + this.generatorExtensionOptions); + job.schedule(); + } + catch(RuntimeException re) { + JptJaxbUiPlugin.log(re); + + String msg = re.getMessage(); + String message = (msg == null) ? re.toString() : msg; + this.logError(message); + } + } - private void initializeGeneratorSettings() { + private void retrieveGeneratorSettings() { this.destinationFolder = this.settingsPage.getTargetFolder(); this.targetPackage = this.settingsPage.getTargetPackage(); this.catalog = this.settingsPage.getCatalog(); @@ -90,7 +255,7 @@ public class ClassesGeneratorWizard extends Wizard { this.bindingsFileNames = this.settingsPage.getBindingsFileNames(); } - private void initializeGeneratorOptions() { + private void retrieveGeneratorOptions() { this.generatorOptions = new ClassesGeneratorOptions(); this.generatorOptions.setProxy(this.optionsPage.getProxy()); @@ -113,7 +278,7 @@ public class ClassesGeneratorWizard extends Wizard { this.generatorOptions.setShowsHelp(this.optionsPage.showsHelp()); } - private void initializeGeneratorExtensionOptions() { + private void retrieveGeneratorExtensionOptions() { this.generatorExtensionOptions = new ClassesGeneratorExtensionOptions(); @@ -122,49 +287,13 @@ public class ClassesGeneratorWizard extends Wizard { this.generatorExtensionOptions.setAdditionalArgs(this.extensionOptionsPage.getAdditionalArgs()); } - @Override - public boolean canFinish() { - return this.settingsPage.isPageComplete(); - } - - // ********** public methods ********** - - public String getDestinationFolder() { - return this.destinationFolder; - } - - public String getTargetPackage() { - return this.targetPackage; - } - - public String getCatalog() { - return this.catalog; - } - - public boolean usesMoxy() { - return this.usesMoxy; - } - - public String[] getBindingsFileNames() { - return this.bindingsFileNames; - } - - public ClassesGeneratorOptions getGeneratorOptions() { - return this.generatorOptions; - } - - public ClassesGeneratorExtensionOptions getGeneratorExtensionOptions() { - return this.generatorExtensionOptions; - } - - // ********** internal methods ********** - private ClassesGeneratorWizardPage buildClassesGeneratorPage() { - return new ClassesGeneratorWizardPage(this.javaProject, this.xmlSchemaName); + + return new ClassesGeneratorWizardPage(); } private ClassesGeneratorOptionsWizardPage buildClassesGeneratorOptionsPage() { - return new ClassesGeneratorOptionsWizardPage(this.javaProject); + return new ClassesGeneratorOptionsWizardPage(); } private ClassesGeneratorExtensionOptionsWizardPage buildExtensionOptionsPage() { @@ -179,6 +308,8 @@ public class ClassesGeneratorWizard extends Wizard { folder.create(true, true, null); } catch (CoreException e) { + JptJaxbUiPlugin.log(e); + this.logError(NLS.bind( JptJaxbUiMessages.ClassesGeneratorWizard_couldNotCreate, folder.getProjectRelativePath().toOSString())); diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizardPage.java index 73762697c4..19b1d4bec6 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizardPage.java @@ -24,7 +24,6 @@ import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; import org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator; import org.eclipse.jdt.internal.ui.wizards.TypedViewerFilter; import org.eclipse.jdt.ui.JavaElementComparator; @@ -81,8 +80,6 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { public static final String HELP_CONTEXT_ID = JptUiPlugin.PLUGIN_ID + ".configure_jaxb_class_generation_dialog"; //$NON-NLS-1$ - private final IJavaProject javaProject; - private SettingsGroup settingsGroup; private String targetFolder; @@ -93,16 +90,9 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { // ********** constructor ********** - public ClassesGeneratorWizardPage(IJavaProject javaProject, String xmlSchemaName) { + public ClassesGeneratorWizardPage() { super(true, "Classes Generator"); //$NON-NLS-1$ - if (javaProject == null) { - throw new NullPointerException(); - } - this.javaProject = javaProject; - // default usesMoxy to true only when JPT EclipseLink bundle exists and MOXy is on the classpath - this.usesMoxy = (this.jptEclipseLinkBundleExists() && this.moxyIsOnClasspath()); - - this.setTitle(NLS.bind(JptJaxbUiMessages.ClassesGeneratorWizardPage_title, xmlSchemaName)); + this.setDescription(JptJaxbUiMessages.ClassesGeneratorWizardPage_desc); } @@ -111,10 +101,36 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { public void createControl(Composite parent) { this.setPageComplete(false); this.setControl(this.buildTopLevelControl(parent)); - - initContainerPage(this.javaProject); } + // ********** intra-wizard methods ********** + + protected String getTargetFolder() { + return this.targetFolder; + } + + protected String getTargetPackage() { + return this.targetPackage; + } + + protected String getCatalog() { + return this.settingsGroup.getCatalog(); + } + + protected String[] getBindingsFileNames() { + return this.settingsGroup.getBindingsFileNames(); + } + + protected boolean usesMoxy() { + return this.usesMoxy; + } + + protected void setUsesMoxy(boolean usesMoxy){ + this.usesMoxy = usesMoxy; + } + + // ********** internal methods ********** + private Control buildTopLevelControl(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new GridLayout()); @@ -123,11 +139,7 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { this.settingsGroup = new SettingsGroup(composite); - // add checkbox only if jpt.eclipselink.ui plugin is available - // and EclipseLink MOXy is not on the classpath - if(this.jptEclipseLinkBundleExists() && ! this.moxyIsOnClasspath()) { - this.usesMoxyCheckBox = this.buildUsesMoxyCheckBox(composite); - } + this.usesMoxyCheckBox = this.buildUsesMoxyCheckBox(composite); Dialog.applyDialogFont(parent); return composite; @@ -158,34 +170,6 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { } }; } - - // ********** intra-wizard methods ********** - - protected String getTargetFolder() { - return this.targetFolder; - } - - protected String getTargetPackage() { - return this.targetPackage; - } - - protected String getCatalog() { - return this.settingsGroup.getCatalog(); - } - - protected String[] getBindingsFileNames() { - return this.settingsGroup.getBindingsFileNames(); - } - - protected boolean usesMoxy() { - return this.usesMoxy; - } - - protected void setUsesMoxy(boolean usesMoxy){ - this.usesMoxy = usesMoxy; - } - - // ********** internal methods ********** private boolean jptEclipseLinkBundleExists() { return (this.getJptEclipseLinkBundle() != null); @@ -228,7 +212,7 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { private boolean genericJaxbIsOnClasspath() { try { String className = ClassesGenerator.JAXB_GENERIC_GEN_CLASS; - IType genClass = this.javaProject.findType(className); + IType genClass = this.getJavaProject().findType(className); return (genClass != null); } catch (JavaModelException e) { @@ -242,7 +226,7 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { private boolean moxyIsOnClasspath() { try { String className = ClassesGenerator.JAXB_ECLIPSELINK_GEN_CLASS; - IType genClass = this.javaProject.findType(className); + IType genClass = this.getJavaProject().findType(className); return (genClass != null); } catch (JavaModelException e) { @@ -292,7 +276,20 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { @Override public void setVisible(boolean visible) { super.setVisible(visible); - validateProjectClasspath(); + if(visible) { + this.initContainerPage(((ClassesGeneratorWizard)this.getWizard()).getJavaProject()); + + // default usesMoxy to true only when JPT EclipseLink bundle exists and MOXy is on the classpath + this.usesMoxy = (this.jptEclipseLinkBundleExists() && this.moxyIsOnClasspath()); + + // checkbox is visible only if jpt.eclipselink.ui plugin is available + // and EclipseLink MOXy is not on the classpath + this.usesMoxyCheckBox.setVisible(this.jptEclipseLinkBundleExists() && ! this.moxyIsOnClasspath()); + this.validateProjectClasspath(); + + String schemaPathOrUri = ((ClassesGeneratorWizard)this.getWizard()).getSchemaPathOrUri(); + this.setTitle(NLS.bind(JptJaxbUiMessages.ClassesGeneratorWizardPage_title, schemaPathOrUri)); + } } /** @@ -343,12 +340,12 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), labelProvider, provider); dialog.setValidator(validator); dialog.setComparator(new JavaElementComparator()); - dialog.setTitle(NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_title); - dialog.setMessage(NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_description); + dialog.setTitle(JptJaxbUiMessages.ClassesGeneratorWizardPage_sourceFolderSelectionDialog_title); + dialog.setMessage(JptJaxbUiMessages.ClassesGeneratorWizardPage_chooseSourceFolderDialog_desc); dialog.addFilter(filter); //set the java project as the input instead of the workspace like the NewContainerWizardPage was doing //******************************************************// - dialog.setInput(this.javaProject); // + dialog.setInput(this.getJavaProject()); // //******************************************************// dialog.setInitialSelection(getPackageFragmentRoot()); dialog.setHelpAvailable(false); @@ -384,7 +381,7 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { layout.marginWidth = 0; composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(this.group, JpaHelpContextIds.XXX); + // TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(this.group, HELP_CONTEXT_ID); // Source folder createContainerControls(composite, 4); @@ -557,7 +554,7 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { private String makeRelativeToProjectPath(String filePath) { Path path = new Path(filePath); - IPath relativePath = path.makeRelativeTo(javaProject.getProject().getLocation()); + IPath relativePath = path.makeRelativeTo(getJavaProject().getProject().getLocation()); return relativePath.toOSString(); } @@ -585,7 +582,7 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { * prompt the user to select a file and return it. */ private String promptXmlFile() { - String projectPath= javaProject.getProject().getLocation().toString(); + String projectPath= getJavaProject().getProject().getLocation().toString(); FileDialog dialog = new FileDialog(getShell()); dialog.setText(JptJaxbUiMessages.ClassesGeneratorWizardPage_chooseACatalog); @@ -596,7 +593,7 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { } private ArrayList<String> promptBindingsFiles() { - String projectPath= javaProject.getProject().getLocation().toString(); + String projectPath= getJavaProject().getProject().getLocation().toString(); FileDialog dialog = new FileDialog(getShell(), SWT.MULTI); dialog.setText(JptJaxbUiMessages.ClassesGeneratorWizardPage_chooseABindingsFile); @@ -645,5 +642,4 @@ public class ClassesGeneratorWizardPage extends NewTypeWizardPage { return ((Collection<?>) inputElement).toArray(); } } - }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SchemaWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SchemaWizardPage.java new file mode 100644 index 0000000000..8e94a00130 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SchemaWizardPage.java @@ -0,0 +1,190 @@ +/******************************************************************************* +* Copyright (c) 2010 Oracle. 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: +* Oracle - initial API and implementation +*******************************************************************************/ +package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; +import org.eclipse.jpt.jaxb.ui.internal.wizards.ProjectWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; + +/** + * SchemaWizardPage + */ +public class SchemaWizardPage extends WizardPage { + + private final IStructuredSelection initialSelection; + private IProject targetProject; + + protected SelectFileOrXMLCatalogIdPanel selectSourcePanel; + + protected static final String[] browseXSDFilterExtensions = {".xsd"}; //$NON-NLS-1$ + + // ********** static method ********** + + public static IFile getSourceSchemaFromSelection(IStructuredSelection selection) { + Object firstElement = selection.getFirstElement(); + if(firstElement instanceof IFile) { + String elementExtension = ((IFile)firstElement).getFileExtension(); + if(elementExtension != null) { + if(browseXSDFilterExtensions[0].endsWith(elementExtension)) { + return ((IFile)firstElement); + } + } + } + return null; + } + + // ********** constructor ********** + + SchemaWizardPage(IStructuredSelection selection) { + super("SchemaWizardPage"); //$NON-NLS-1$ + + this.initialSelection = selection; + } + + // ********** IDialogPage implementation ********** + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); +// PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, HELP_CONTEXT_ID); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + this.setControl(composite); + + this.selectSourcePanel = new SelectFileOrXMLCatalogIdPanel(composite, this.initialSelection); + this.selectSourcePanel.setLayoutData(new GridData(GridData.FILL_BOTH)); + + SelectFileOrXMLCatalogIdPanel.PanelListener listener = new SelectFileOrXMLCatalogIdPanel.PanelListener() { + public void completionStateChanged() { + selectFileOrXMLCatalogIdPanelChanged(); + } + }; + this.selectSourcePanel.setListener(listener); + Dialog.applyDialogFont(parent); + } + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + if(visible) { + + if(this.getSourceSchema() != null) { + this.selectSourcePanel.setSingleFileViewDefaultSelection(new StructuredSelection(this.getSourceSchema())); + } + else { + this.updateTargetProject(); + IFile schema = getSourceSchemaFromSelection(this.initialSelection); + if(schema != null) { + this.selectSourcePanel.setSingleFileViewDefaultSelection(new StructuredSelection(schema)); + } + else { + this.selectSourcePanel.setSingleFileViewDefaultSelection(new StructuredSelection(this.targetProject)); + } + } + this.selectSourcePanel.update(); + + this.setTitle(JptJaxbUiMessages.SchemaWizardPage_title); + this.setDescription(JptJaxbUiMessages.SchemaWizardPage_desc); + this.selectSourcePanel.setFilterExtensions(browseXSDFilterExtensions); + } + this.selectSourcePanel.setVisibleHelper(visible); + } + + // ********** IWizardPage implementation ********** + + @Override + public boolean isPageComplete() { + + return this.schemaOrUriSelected() && (this.getErrorMessage() == null); + } + + // ********** intra-wizard methods ********** + + public IFile getSourceSchema() { + return this.selectSourcePanel.getFile(); + } + + public String getSourceURI() { + String uri = this.selectSourcePanel.getXMLCatalogURI(); + if(uri == null) { + IFile file = this.selectSourcePanel.getFile(); + if(file != null) { + uri = URIHelper.getPlatformURI(file); + } + } + return uri; + } + + public String getXMLCatalogId() { + return this.selectSourcePanel.getXMLCatalogId(); + } + + // ********** internal methods ********** + + private void updateTargetProject() { + IWizardPage previousPage = this.getPreviousPage(); + + if(previousPage instanceof ProjectWizardPage) { + // get project from previousPage + this.targetProject = (((ProjectWizardPage)previousPage).getJavaProject()).getProject(); + } + else if(initialSelection != null && ! this.initialSelection.isEmpty()) { + // no previousPage - get project from initialSelection + this.targetProject = this.getProjectFromInitialSelection(); + } + } + + private IProject getProjectFromInitialSelection() { + Object firstElement = initialSelection.getFirstElement(); + if(firstElement instanceof IProject) { + return (IProject)firstElement; + } + else if(firstElement instanceof IResource) { + return ((IResource) firstElement).getProject(); + } + else if(firstElement instanceof IJavaElement) { + return ((IJavaElement)firstElement).getJavaProject().getProject(); + } + return null; + } + + private boolean schemaOrUriSelected() { + return ((this.getSourceSchema() != null) || (this.getSourceURI() != null)); + } + + private String computeErrorMessage() { + String errorMessage = null; + String uri = this.getSourceURI(); + if(uri != null) { + if( ! URIHelper.isReadableURI(uri, false)) { + errorMessage = JptJaxbUiMessages.SchemaWizardPage_errorUriCannotBeLocated; + } + } + return errorMessage; + } + + private void selectFileOrXMLCatalogIdPanelChanged() { + String errorMessage = this.computeErrorMessage(); + this.setErrorMessage(errorMessage); + this.setPageComplete(this.isPageComplete()); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectFileOrXMLCatalogIdPanel.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectFileOrXMLCatalogIdPanel.java new file mode 100644 index 0000000000..c7a6db1116 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectFileOrXMLCatalogIdPanel.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (c) 2001, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Code originate from org.eclipse.wst.xml.ui.internal.dialogs + *******************************************************************************/ +package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin; +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.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.part.PageBook; +import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; +import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; + + +public class SelectFileOrXMLCatalogIdPanel extends Composite implements SelectionListener { + + public interface PanelListener { + void completionStateChanged(); + } + + protected PanelListener listener; + protected PageBook pageBook; + + protected Button[] radioButton; + protected SelectFilePanel selectFilePanel; + protected SelectXMLCatalogIdPanel selectXMLCatalogIdPanel; + + // ********** constructor ********** + + public SelectFileOrXMLCatalogIdPanel(Composite parent, IStructuredSelection selection) { + super(parent, SWT.NONE); + + // container group + setLayout(new GridLayout()); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 400; + gd.widthHint = 400; + setLayoutData(gd); + + radioButton = new Button[2]; + radioButton[0] = new Button(this, SWT.RADIO); + radioButton[0].setText("Select file from Workspace"); + radioButton[0].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + radioButton[0].setSelection(true); + radioButton[0].addSelectionListener(this); + + radioButton[1] = new Button(this, SWT.RADIO); + radioButton[1].setText("Select XML Catalog entry"); + radioButton[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + radioButton[1].addSelectionListener(this); + + pageBook = new PageBook(this, SWT.NONE); + pageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); + + selectFilePanel = new SelectFilePanel(pageBook, selection); + this.setSingleFileViewDefaultSelection(selection); + + // Catalog + ICatalog xmlCatalog = JptJaxbUiPlugin.instance().getDefaultXMLCatalog(); + selectXMLCatalogIdPanel = new SelectXMLCatalogIdPanel(pageBook, xmlCatalog); + selectXMLCatalogIdPanel.getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateCompletionStateChange(); + } + }); + Dialog.applyDialogFont(parent); + pageBook.showPage(selectFilePanel.getControl()); + } + + public void setSingleFileViewDefaultSelection(ISelection selection) { + this.selectFilePanel.setDefaultSelection(selection); + } + + public IFile getFile() { + IFile result = null; + if (radioButton[0].getSelection()) { + result = selectFilePanel.getFile(); + } + return result; + } + + public ICatalogEntry getXMLCatalogEntry() { + ICatalogEntry result = null; + if (radioButton[1].getSelection()) { + result = selectXMLCatalogIdPanel.getXMLCatalogEntry(); + } + return result; + } + + public String getXMLCatalogId() { + String result = null; + if (radioButton[1].getSelection()) { + result = selectXMLCatalogIdPanel.getId(); + } + return result; + } + + public String getXMLCatalogURI() { + String result = null; + if (radioButton[1].getSelection()) { + result = selectXMLCatalogIdPanel.getURI(); + } + return result; + } + + public void setCatalogEntryType(int catalogEntryType) { + selectXMLCatalogIdPanel.setCatalogEntryType(catalogEntryType); + } + + public void setFilterExtensions(String[] filterExtensions) { + selectFilePanel.resetFilters(); + selectFilePanel.addFilterExtensions(filterExtensions); + + selectXMLCatalogIdPanel.getTableViewer().setFilterExtensions(filterExtensions); + } + + public void setListener(PanelListener listener) { + this.listener = listener; + } + + public void setVisibleHelper(boolean isVisible) { + selectFilePanel.setVisibleHelper(isVisible); + } + + public void updateCompletionStateChange() { + if (listener != null) { + listener.completionStateChanged(); + } + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + + public void widgetSelected(SelectionEvent e) { + if (e.widget == radioButton[0]) { + pageBook.showPage(selectFilePanel.getControl()); + } + else { + pageBook.showPage(selectXMLCatalogIdPanel); + } + updateCompletionStateChange(); + } + + // ********** inner class ********** + + protected class SelectFilePanel extends SelectSingleFileViewFacade implements SelectSingleFileViewFacade.Listener { + protected Control control; + + public SelectFilePanel(Composite parent, IStructuredSelection selection) { + super(selection, true); + // String[] ext = {".dtd"}; + // addFilterExtensions(ext); + control = createControl(parent); + control.setLayoutData(new GridData(GridData.FILL_BOTH)); + SelectFilePanel.this.setListener(this); + } + + public Control getControl() { + return control; + } + + public void setControlComplete(boolean isComplete) { + updateCompletionStateChange(); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectSingleFileViewFacade.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectSingleFileViewFacade.java new file mode 100644 index 0000000000..f626b8f7b0 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectSingleFileViewFacade.java @@ -0,0 +1,59 @@ +/******************************************************************************* +* Copyright (c) 2010 Oracle. 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: +* Oracle - initial API and implementation +*******************************************************************************/ +package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Composite; + +/** + * SelectSingleFileView + * + * Façade class to change accessibility of SelectSingleFileView. + */ +@SuppressWarnings("restriction") +public class SelectSingleFileViewFacade extends org.eclipse.wst.common.ui.internal.viewers.SelectSingleFileView { + + public static interface Listener extends org.eclipse.wst.common.ui.internal.viewers.SelectSingleFileView.Listener + {} + + public SelectSingleFileViewFacade(IStructuredSelection selection, boolean isFileMandatory) { + super(selection, isFileMandatory); + } + + public void addFilterExtensions(String[] filterExtensions) { + super.addFilterExtensions(filterExtensions); + } + + public Composite createControl(Composite parent) { + return super.createControl(parent); + } + + public IFile getFile() { + return super.getFile(); + } + + public void resetFilters() { + super.resetFilters(); + } + + public void setVisibleHelper(boolean isVisible) { + super.setVisibleHelper(isVisible); + } + + public void setDefaultSelection(ISelection selection) { + super.setDefaultSelection(selection); + } + + public void setListener(Listener listener) { + super.setListener(listener); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectXMLCatalogIdPanel.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectXMLCatalogIdPanel.java new file mode 100644 index 0000000000..2745d0ab04 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SelectXMLCatalogIdPanel.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2001, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Code originate from org.eclipse.wst.xml.ui.internal.dialogs + *******************************************************************************/ +package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen; + +import java.util.Collection; +import java.util.List; +import java.util.Vector; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin; +import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; +import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; +import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; + + +public class SelectXMLCatalogIdPanel extends Composite { + protected int catalogEntryType; + protected boolean doTableSizeHack = false; + + protected XMLCatalogTableViewer tableViewer; + protected ICatalog fXmlCatalog; + + public SelectXMLCatalogIdPanel(Composite parent, ICatalog xmlCatalog) { + super(parent, SWT.NONE); + this.fXmlCatalog = xmlCatalog; + + GridLayout gridLayout = new GridLayout(); + this.setLayout(gridLayout); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 200; + gd.widthHint = 700; + this.setLayoutData(gd); + + Label label = new Label(this, SWT.NONE); + label.setText(JptJaxbUiMessages.SchemaWizardPage_xmlCatalogTableTitle); + + tableViewer = createTableViewer(this); + tableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); + tableViewer.setInput("dummy"); //$NON-NLS-1$ + } + + protected XMLCatalogTableViewer createTableViewer(Composite parent) { + String headings[] = new String[2]; + headings[0] = JptJaxbUiMessages.SchemaWizardPage_xmlCatalogKeyColumn; + headings[1] = JptJaxbUiMessages.SchemaWizardPage_xmlCatalogUriColumn; + + XMLCatalogTableViewer theTableViewer = new XMLCatalogTableViewer(parent, headings) { + + protected void addXMLCatalogEntries(List list, ICatalogEntry[] entries) { + for (int i = 0; i < entries.length; i++) { + ICatalogEntry entry = entries[i]; + if (catalogEntryType == 0) { + list.add(entry); + } + else if (catalogEntryType == entry.getEntryType()) { + list.add(entry); + } + } + } + + public Collection getXMLCatalogEntries() { + List result = null; + + if ((fXmlCatalog == null) || doTableSizeHack) { + // this lets us create a table with an initial height of + // 10 rows + // otherwise we get stuck with 0 row heigh table... that's + // too small + doTableSizeHack = false; + result = new Vector(); + for (int i = 0; i < 6; i++) { + result.add(""); //$NON-NLS-1$ + } + } + else { + result = new Vector(); + INextCatalog[] nextCatalogs = fXmlCatalog.getNextCatalogs(); + for (int i = 0; i < nextCatalogs.length; i++) { + INextCatalog catalog = nextCatalogs[i]; + ICatalog referencedCatalog = catalog.getReferencedCatalog(); + if (referencedCatalog != null) { + if (JptJaxbUiPlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) { + ICatalog systemCatalog = referencedCatalog; + addXMLCatalogEntries(result, systemCatalog.getCatalogEntries()); + + } + else if (JptJaxbUiPlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { + ICatalog userCatalog = referencedCatalog; + addXMLCatalogEntries(result, userCatalog.getCatalogEntries()); + + } + } + } + } + return result; + } + }; + return theTableViewer; + } + + + public String getId() { + ICatalogEntry entry = getXMLCatalogEntry(); + return entry != null ? entry.getKey() : null; + } + + public XMLCatalogTableViewer getTableViewer() { + return tableViewer; + } + + public String getURI() { + ICatalogEntry entry = getXMLCatalogEntry(); + return entry != null ? entry.getURI() : null; + } + + public ICatalogEntry getXMLCatalogEntry() { + ICatalogEntry result = null; + ISelection selection = tableViewer.getSelection(); + Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; + if (selectedObject instanceof ICatalogEntry) { + result = (ICatalogEntry) selectedObject; + } + return result; + } + + public void setCatalogEntryType(int catalogEntryType) { + this.catalogEntryType = catalogEntryType; + tableViewer.refresh(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/XMLCatalogTableViewer.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/XMLCatalogTableViewer.java new file mode 100644 index 0000000000..4a24f1c36b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/XMLCatalogTableViewer.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2001, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Code originate from org.eclipse.wst.xml.ui.internal.dialogs + *******************************************************************************/ +package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; +import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; + +import com.ibm.icu.text.Collator; + +public class XMLCatalogTableViewer extends TableViewer { + + protected static String ERROR_STATE_KEY = "errorstatekey"; //$NON-NLS-1$ + + protected static Image dtdFileImage = JptJaxbUiPlugin.getImage("icons/full/obj16/dtdfile.gif"); //$NON-NLS-1$ + protected static Image unknownFileImage = JptJaxbUiPlugin.getImage("icons/full/obj16/text.gif"); //$NON-NLS-1$ + protected static Image xsdFileImage = JptJaxbUiPlugin.getImage("icons/full/obj16/XSDFile.gif"); //$NON-NLS-1$ + protected static Image errorImage = JptJaxbUiPlugin.getImage("icons/full/ovr16/error_ovr.gif"); //$NON-NLS-1$ + + // ********** constructor ********** + + public XMLCatalogTableViewer(Composite parent, String[] columnProperties) { + super(parent, SWT.FULL_SELECTION); + + Table table = getTable(); + table.setLinesVisible(true); + table.setHeaderVisible(true); + table.setLinesVisible(true); + + TableLayout layout = new TableLayout(); + for (int i = 0; i < columnProperties.length; i++) { + TableColumn column = new TableColumn(table, i); + column.setText(columnProperties[i]); + column.setAlignment(SWT.LEFT); + layout.addColumnData(new ColumnWeightData(50, true)); + } + table.setLayout(layout); + table.setLinesVisible(false); + + setColumnProperties(columnProperties); + + setContentProvider(new CatalogEntryContentProvider()); + setLabelProvider(new CatalogEntryLabelProvider()); + } + + public Collection getXMLCatalogEntries() { + return null; + } + + public void menuAboutToShow(IMenuManager menuManager) { + Action action = new Action("hello") { //$NON-NLS-1$ + public void run() { + System.out.println("run!"); //$NON-NLS-1$ + } + }; + menuManager.add(action); + } + + public void setFilterExtensions(String[] extensions) { + resetFilters(); + addFilter(new XMLCatalogTableViewerFilter(extensions)); + } + + // ********** inner class ********** + + public class CatalogEntryContentProvider implements IStructuredContentProvider { + + public void dispose() { + } + + public Object[] getElements(Object element) { + Object[] array = getXMLCatalogEntries().toArray(); + Comparator comparator = new Comparator() { + public int compare(Object o1, Object o2) { + int result = 0; + if ((o1 instanceof ICatalogEntry) && (o2 instanceof ICatalogEntry)) { + ICatalogEntry mappingInfo1 = (ICatalogEntry) o1; + ICatalogEntry mappingInfo2 = (ICatalogEntry) o2; + result = Collator.getInstance().compare(mappingInfo1.getKey(), mappingInfo2.getKey()); + } + return result; + } + }; + Arrays.sort(array, comparator); + return array; + } + + public void inputChanged(Viewer viewer, Object old, Object newobj) { + } + + public boolean isDeleted(Object object) { + return false; + } + } + + public class CatalogEntryLabelProvider extends LabelProvider implements ITableLabelProvider { + + public Image getColumnImage(Object object, int columnIndex) { + Image result = null; + if (columnIndex == 0) { + Image base = null; + if (object instanceof ICatalogEntry) { + ICatalogEntry catalogEntry = (ICatalogEntry) object; + String uri = catalogEntry.getURI(); + if (uri.endsWith("dtd")) { //$NON-NLS-1$ + base = dtdFileImage; + } + else if (uri.endsWith("xsd")) { //$NON-NLS-1$ + base = xsdFileImage; + } + else { + base = unknownFileImage; + } + + if (base != null) { + if (URIHelper.isReadableURI(uri, false)) { + result = base; + } + else { + // TODO... SSE port + result = base;// imageFactory.createCompositeImage(base, + // errorImage, + // ImageFactory.BOTTOM_LEFT); + } + } + } + } + return result; + } + + public String getColumnText(Object object, int columnIndex) { + String result = null; + if (object instanceof ICatalogEntry) { + ICatalogEntry catalogEntry = (ICatalogEntry) object; + result = columnIndex == 0 ? catalogEntry.getKey() : catalogEntry.getURI(); + result = URIHelper.removePlatformResourceProtocol(result); + } + return result != null ? result : ""; //$NON-NLS-1$ + } + } + + class XMLCatalogTableViewerFilter extends ViewerFilter { + protected String[] extensions; + + public XMLCatalogTableViewerFilter(String[] extensions) { + this.extensions = extensions; + } + + public boolean isFilterProperty(Object element, Object property) { + return false; + } + + public boolean select(Viewer viewer, Object parent, Object element) { + boolean result = false; + if (element instanceof ICatalogEntry) { + ICatalogEntry catalogEntry = (ICatalogEntry) element; + for (int i = 0; i < extensions.length; i++) { + if (catalogEntry.getURI().endsWith(extensions[i])) { + result = true; + break; + } + } + } + return result; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java index cdcfcbf1fd..d864ad8df1 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java @@ -35,6 +35,7 @@ import org.eclipse.jpt.jaxb.core.internal.SchemaGenerator; import org.eclipse.jpt.jaxb.ui.JptJaxbUiIcons; import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin; import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; +import org.eclipse.jpt.jaxb.ui.internal.wizards.ProjectWizardPage; import org.eclipse.jpt.utility.internal.ArrayTools; import org.eclipse.jpt.utility.internal.FileTools; import org.eclipse.osgi.util.NLS; @@ -75,6 +76,7 @@ public class SchemaGeneratorWizard extends Wizard implements IExportWizard { super.addPages(); if(this.selection.isEmpty()) { this.javaProjectWizardPage = new ProjectWizardPage(); + this.javaProjectWizardPage.setTitle(JptJaxbUiMessages.SchemaGeneratorProjectWizardPage_title); this.addPage(this.javaProjectWizardPage); } @@ -89,12 +91,12 @@ public class SchemaGeneratorWizard extends Wizard implements IExportWizard { String[] sourceClassNames = this.buildSourceClassNames(this.getAllCheckedItems()); - WorkspaceJob genEntitiesJob = new GenerateSchemaJob( + WorkspaceJob genSchemaJob = new GenerateSchemaJob( javaProject, sourceClassNames, this.getTargetSchema(), this.usesMoxy()); - genEntitiesJob.schedule(); + genSchemaJob.schedule(); return true; } diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java index b2922033ae..9a2b065104 100644 --- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java @@ -44,6 +44,7 @@ import org.eclipse.jpt.jaxb.ui.internal.filters.EmptyInnerPackageFilter; import org.eclipse.jpt.jaxb.ui.internal.filters.NonArchiveOrExternalElementFilter; import org.eclipse.jpt.jaxb.ui.internal.filters.NonContainerFilter; import org.eclipse.jpt.jaxb.ui.internal.filters.NonJavaElementFilter; +import org.eclipse.jpt.jaxb.ui.internal.wizards.ProjectWizardPage; import org.eclipse.jpt.ui.JptUiPlugin; import org.eclipse.jpt.utility.internal.ArrayTools; import org.eclipse.jpt.utility.internal.StringTools; @@ -260,7 +261,7 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage if(previousPage instanceof ProjectWizardPage) { // get project from previousPage - this.targetProject = ((ProjectWizardPage)previousPage).getProject(); + this.targetProject = ((ProjectWizardPage)previousPage).getJavaProject(); } else if(initialSelection != null && ! this.initialSelection.isEmpty()) { // no previousPage - get project from initialSelection |