Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2010-09-22 21:18:35 -0400
committertle2010-09-22 21:18:35 -0400
commit4573a4f21462e057bc4f20dfc7d76dc99411ab44 (patch)
tree96d16bfaf8618410137c5c9b4e3cc5dc2b62208b
parent4535c1470612b569ca5026216a7ddec4bdcff814 (diff)
downloadwebtools.dali-4573a4f21462e057bc4f20dfc7d76dc99411ab44.tar.gz
webtools.dali-4573a4f21462e057bc4f20dfc7d76dc99411ab44.tar.xz
webtools.dali-4573a4f21462e057bc4f20dfc7d76dc99411ab44.zip
322565 - JAXB schema from classes, can't select a different project
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/property_files/jpt_jaxb_ui.properties33
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/operations/SchemaFileCreationDataModelProvider.java42
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JptJaxbUiMessages.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/JavaProjectWizardPage.java252
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java45
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/SchemaWizardPage.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java149
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java185
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java265
14 files changed, 667 insertions, 354 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF
index 7252ca8c65..48d02f78da 100644
--- a/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF
@@ -64,7 +64,8 @@ Export-Package: org.eclipse.jpt.core,
org.eclipse.jpt.core.internal.jpa2.resource.java;x-internal:=true,
org.eclipse.jpt.core.internal.jpa2.resource.java.binary;x-internal:=true,
org.eclipse.jpt.core.internal.jpa2.resource.java.source;x-internal:=true,
- org.eclipse.jpt.core.internal.operations;x-internal:=true,
+ org.eclipse.jpt.core.internal.operations;
+ x-friends:="org.eclipse.jpt.jaxb.ui",
org.eclipse.jpt.core.internal.platform,
org.eclipse.jpt.core.internal.prefs;x-internal:=true,
org.eclipse.jpt.core.internal.refactoring;x-internal:=true,
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF
index 75f587f1ff..8e8d066cc9 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF
@@ -23,6 +23,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.help;bundle-version="[3.5.0,4.0.0)",
org.eclipse.wst.xml.core;bundle-version="[1.1.500,2.0.0)",
org.eclipse.wst.common.ui;bundle-version="[1.1.500,2.0.0)",
+ org.eclipse.wst.common.frameworks;bundle-version="[1.2.0,2.0.0)",
org.eclipse.wst.common.uriresolver;bundle-version="[1.1.401,2.0.0)"
Export-Package: org.eclipse.jpt.jaxb.core.internal;x-internal:=true,
org.eclipse.jpt.jaxb.ui;x-internal:=true,
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
index 006e0d8ed3..70458524c5 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
@@ -4,11 +4,11 @@
<extension
point="org.eclipse.ui.newWizards">
-
+
<category
id="org.eclipse.jpt.jaxb"
name="%jpaWizardCategoryName"/>
-
+
<wizard
id="org.eclipse.jpt.jaxb.ui.wizard.generateSchemaFromClasses"
name="%generateSchemaFromClassesName"
@@ -27,7 +27,7 @@
icon="icons/full/etool16/newclass_wiz.gif">
<description>%generateClassesFromSchemaDesc</description>
</wizard>
-
+
</extension>
<extension
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/property_files/jpt_jaxb_ui.properties b/jpa/plugins/org.eclipse.jpt.jaxb.ui/property_files/jpt_jaxb_ui.properties
index d358ac5221..787e2c03e7 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/property_files/jpt_jaxb_ui.properties
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/property_files/jpt_jaxb_ui.properties
@@ -8,18 +8,21 @@
# Oracle - initial API and implementation
################################################################################
+JavaProjectWizardPage_project = Project:
+JavaProjectWizardPage_destinationProject = Select destination project:
+
# ClassesGenerator
-ClassesGeneratorWizard_title = JAXB Class Generation
+ClassesGeneratorProjectWizardPage_title = Java Project
+ClassesGeneratorProjectWizardPage_desc = Specify project for the new classes.
+
+ClassesGeneratorWizard_title = New JAXB Classes from schema
ClassesGeneratorWizard_errorDialogTitle = Generate Classes Failed
ClassesGeneratorWizard_couldNotCreate = Could not create {0}
-ClassesGeneratorProjectWizardPage_title = Java Project Selection
-
-
SchemaWizardPage_title = Select Schema
-SchemaWizardPage_desc = Select the schema to generate the classes from
-
+SchemaWizardPage_desc = Specify schema to generate the classes from
+
SchemaWizardPage_xmlCatalogTableTitle = XML Catalog
SchemaWizardPage_xmlCatalogKeyColumn = Key
SchemaWizardPage_xmlCatalogUriColumn = URI
@@ -91,21 +94,19 @@ ClassesGeneratorUi_generatingClassesWarningMessage = \
\n\nAre you sure you want to continue?
# SchemaGenerator
-SchemaGeneratorWizard_title = JAXB Schema Generation
+SchemaGeneratorWizard_title = New JAXB Schema File
SchemaGeneratorWizard_generatingSchema = Generating JAXB Schema
-ProjectWizardPage_desc = Select a Java project.
-ProjectWizardPage_project = Project:
-
-SchemaGeneratorProjectWizardPage_title = Java Project Selection
+SchemaGeneratorProjectWizardPage_title = JAXB schema file
+SchemaGeneratorProjectWizardPage_desc = Specify schema file name and location
SchemaGeneratorWizardPage_title = Generate Schema from Classes
-SchemaGeneratorWizardPage_desc = Select schema location and included classes.
+SchemaGeneratorWizardPage_desc = Select classes to include.
SchemaGeneratorWizardPage_shemaLocation = Schema file:
SchemaGeneratorWizardPage_shema = Schema name:
-SchemaGeneratorWizardPage_packages = Select the classes to include in the schema:
+SchemaGeneratorWizardPage_packages = Select classes to include in schema:
SchemaGeneratorWizardPage_browse = Browse...
SchemaGeneratorWizardPage_chooseSchemaDialogTitle = Select Schema File
@@ -121,4 +122,8 @@ SchemaGeneratorWizardPage_moxyLibrariesNotAvailable = \
The classpath for this project does not appear to contain the necessary libraries to proceed with schema generation.\
\nPlease insure that EclipseLink MOXy is available on the classpath.
-SchemaGeneratorWizard_generateSchemaTask=Generating schema {0}
+SchemaGeneratorWizard_generateSchemaTask = Generating schema {0}
+
+#NewSchemaFileWizardPage
+
+NewSchemaFileWizardPage_errorNotJavaProject = Not a Java project
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/operations/SchemaFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/operations/SchemaFileCreationDataModelProvider.java
new file mode 100644
index 0000000000..4c02e173d8
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/operations/SchemaFileCreationDataModelProvider.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+* 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.core.internal.operations;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jpt.core.internal.operations.PersistenceFileCreationDataModelProvider;
+
+/**
+ * SchemaFileCreationDataModelProvider
+ */
+public class SchemaFileCreationDataModelProvider extends PersistenceFileCreationDataModelProvider
+{
+
+ @Override
+ protected String getDefaultFileName() {
+ if(this.getProject() == null) {
+ return null;
+ }
+ return this.getProject().getName();
+ }
+
+ /**
+ * Return a best guess source location for the for the specified project
+ */
+ @Override
+ protected IContainer getDefaultContainer() {
+ IContainer defaultContainer = super.getDefaultContainer();
+ if(defaultContainer != null) {
+ IProject project = (IProject) this.model.getProperty(PROJECT);
+ return defaultContainer.getFolder(project.getLocation());
+ }
+ return null;
+ }
+}
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 4130e9daab..84d58cfb98 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
@@ -17,13 +17,17 @@ import org.eclipse.osgi.util.NLS;
* @version 2.3
*/
public class JptJaxbUiMessages {
+
+ public static String JavaProjectWizardPage_project;
+ public static String JavaProjectWizardPage_destinationProject;
// ClassesGenerator
+ public static String ClassesGeneratorProjectWizardPage_title;
+ public static String ClassesGeneratorProjectWizardPage_desc;
+
public static String ClassesGeneratorWizard_title;
public static String ClassesGeneratorWizard_errorDialogTitle;
public static String ClassesGeneratorWizard_couldNotCreate;
-
- public static String ClassesGeneratorProjectWizardPage_title;
public static String SchemaWizardPage_title;
@@ -97,10 +101,8 @@ public class JptJaxbUiMessages {
public static String SchemaGeneratorWizard_title;
public static String SchemaGeneratorWizard_generatingSchema;
- public static String ProjectWizardPage_desc;
- public static String ProjectWizardPage_project;
-
public static String SchemaGeneratorProjectWizardPage_title;
+ public static String SchemaGeneratorProjectWizardPage_desc;
public static String SchemaGeneratorWizardPage_title;
public static String SchemaGeneratorWizardPage_desc;
@@ -121,6 +123,10 @@ public class JptJaxbUiMessages {
public static String SchemaGeneratorWizard_generateSchemaTask;
+
+ public static String NewSchemaFileWizardPage_errorNotJavaProject;
+
+
private static final String BUNDLE_NAME = "jpt_jaxb_ui"; //$NON-NLS-1$
private static final Class<?> BUNDLE_CLASS = JptJaxbUiMessages.class;
static {
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/JavaProjectWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/JavaProjectWizardPage.java
new file mode 100644
index 0000000000..70f25961f7
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/JavaProjectWizardPage.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+* 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;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
+import org.eclipse.jpt.utility.internal.ArrayTools;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.FilteringIterable;
+import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+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.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * JavaProjectWizardPage
+ */
+public class JavaProjectWizardPage extends WizardPage {
+
+ private IJavaProject javaProject;
+ private Table projectTable;
+ private TableViewer projectTableViewer;
+
+ private static String SELECT_PROJECT_PAGE_NAME = "SelectJavaProject"; //$NON-NLS-1$
+ private static int PROJECT_NAME_COLUMN_INDEX = 0;
+
+ // ********** constructor **********
+
+ public JavaProjectWizardPage(IJavaProject javaProject) {
+ super(SELECT_PROJECT_PAGE_NAME);
+
+ this.javaProject = javaProject;
+ }
+
+ // ********** IDialogPage implementation **********
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ composite.setLayout(layout);
+
+ this.buildLabel(composite, JptJaxbUiMessages.JavaProjectWizardPage_destinationProject);
+
+ this.projectTable = this.buildProjectTable(composite, this.buildProjectTableSelectionListener());
+
+ this.projectTableViewer = this.buildProjectTableViewer(
+ this.projectTable,
+ this.buildProjectTableLabelProvider(),
+ this.buildProjectTableContentProvider());
+ this.fillProjectList();
+ this.setControl(composite);
+ this.setTableSelection(this.javaProject);
+ this.validate();
+ }
+
+ // ********** listeners **********
+
+ private SelectionListener buildProjectTableSelectionListener() {
+ return new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ selectedProjectChanged();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ @Override
+ public String toString() {
+ return "PromptProjectWizardPage project table selection listener"; //$NON-NLS-1$
+ }
+ };
+ }
+
+ // ********** listener callbacks **********
+
+ protected void selectedProjectChanged() {
+ if(this.projectTable.getSelectionIndex() != -1) {
+ TableItem item = this.projectTable.getItem(this.projectTable.getSelectionIndex());
+ String projectName = item.getText(0);
+ if( ! StringTools.stringIsEmpty(projectName)) {
+
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ this.setJavaProject(JavaCore.create(project));
+ this.validate();
+ }
+ }
+ }
+
+ // ********** intra-wizard methods **********
+
+ public IJavaProject getJavaProject() {
+ return this.javaProject;
+ }
+
+ // ********** protected methods **********
+
+ protected void setTableSelection(IJavaProject javaProject) {
+ if(javaProject != null) {
+ String projectName = javaProject.getProject().getName();
+ for(TableItem item: this.projectTable.getItems()) {
+ if(item.getText(0).equals(projectName)) {
+ this.projectTable.setSelection(item);
+ }
+ }
+ }
+ }
+
+ protected void fillProjectList() {
+ this.projectTableViewer.setInput(this.getSortedJavaProjectsNames());
+ }
+
+ // ********** internal methods **********
+
+ private void validate() {
+ this.setPageComplete(this.projectTable.getSelectionIndex() != -1);
+ }
+
+ private void setJavaProject(IJavaProject project) {
+ this.javaProject = project;
+ }
+
+ private String[] getSortedJavaProjectsNames() {
+ return ArrayTools.sort(this.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() {
+ return new FilteringIterable<IProject>(CollectionTools.collection(this.getProjects())) {
+ @Override
+ protected boolean accept(IProject next) {
+ try {
+ return next.hasNature(JavaCore.NATURE_ID);
+ }
+ catch (CoreException e) {
+ return false;
+ }
+ }
+ };
+ }
+
+ private Iterator<IProject> getProjects() {
+ return new ArrayIterator<IProject>(ResourcesPlugin.getWorkspace().getRoot().getProjects());
+ }
+
+ // ********** inner classes **********
+
+ private final class ProjectTableLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if(columnIndex == PROJECT_NAME_COLUMN_INDEX)
+ return PlatformUI.getWorkbench().getSharedImages().getImage(org.eclipse.ui.ide.IDE.SharedImages.IMG_OBJ_PROJECT);
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ assert element instanceof String;
+ String projectName = (String)element;
+ if(columnIndex == PROJECT_NAME_COLUMN_INDEX)
+ return projectName;
+ return null;
+ }
+ }
+
+ private final class ProjectTableContentProvider implements IStructuredContentProvider {
+
+ public Object[] getElements(Object inputElement) {
+ return ((String[])inputElement);
+ }
+
+ public void dispose() {}
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ }
+
+ // ********** UI components **********
+
+ private ITableLabelProvider buildProjectTableLabelProvider() {
+ return new ProjectTableLabelProvider();
+ }
+
+ private IStructuredContentProvider buildProjectTableContentProvider() {
+ return new ProjectTableContentProvider();
+ }
+
+ private Label buildLabel(Composite parent, String text) {
+ Label label = new Label( parent, SWT.NONE );
+ label.setText(text);
+ return label;
+ }
+
+ private Table buildProjectTable(Composite parent, SelectionListener listener) {
+ TableViewer tableViewer = new TableViewer(parent,
+ SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
+
+ Table table = tableViewer.getTable();
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ table.addSelectionListener(listener);
+ return table;
+ }
+
+ private TableViewer buildProjectTableViewer(Table parent, ITableLabelProvider labelProvider, IStructuredContentProvider contentProvider) {
+
+ TableViewer tableViewer = new TableViewer(parent);
+ tableViewer.setLabelProvider(labelProvider);
+ tableViewer.setContentProvider(contentProvider);
+ return tableViewer;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java
index 9e62a9eddf..c2605b09d4 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java
@@ -77,7 +77,7 @@ public class ProjectWizardPage extends WizardPage
public ProjectWizardPage() {
super("Java Project"); //$NON-NLS-1$
- this.setDescription(JptJaxbUiMessages.ProjectWizardPage_desc);
+ this.setDescription(JptJaxbUiMessages.ClassesGeneratorProjectWizardPage_desc);
}
public ProjectWizardPage(IJavaProject javaProject) {
@@ -140,7 +140,7 @@ public class ProjectWizardPage extends WizardPage
composite.setLayout(new GridLayout(2, false));
// Project
- this.buildLabel(composite, JptJaxbUiMessages.ProjectWizardPage_project);
+ this.buildLabel(composite, JptJaxbUiMessages.JavaProjectWizardPage_project);
this.projectCombo = this.buildProjectCombo(composite, this.buildProjectComboSelectionListener());
this.updateProjectCombo();
@@ -192,7 +192,7 @@ public class ProjectWizardPage extends WizardPage
}
private String[] getSortedJavaProjectsNames() {
- return ArrayTools.sort(getJavaProjectsNames());
+ return ArrayTools.sort(this.getJavaProjectsNames());
}
private String[] getJavaProjectsNames() {
@@ -232,7 +232,7 @@ public class ProjectWizardPage extends WizardPage
label.setText(text);
return label;
}
-
+
private Combo buildProjectCombo(Composite parent, SelectionListener listener) {
Combo projectCombo = new Combo(parent, SWT.READ_ONLY);
GridData gridData = new GridData();
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 137727c192..4e7005a71d 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
@@ -11,9 +11,13 @@ 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.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -25,7 +29,7 @@ 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.jpt.jaxb.ui.internal.wizards.JavaProjectWizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
@@ -47,7 +51,7 @@ public class ClassesGeneratorWizard extends Wizard implements IWorkbenchWizard {
private ClassesGeneratorOptions generatorOptions;
private ClassesGeneratorExtensionOptions generatorExtensionOptions;
- private ProjectWizardPage javaProjectWizardPage;
+ private JavaProjectWizardPage projectWizardPage;
private SchemaWizardPage schemaWizardPage;
private ClassesGeneratorWizardPage settingsPage;
@@ -87,11 +91,12 @@ public class ClassesGeneratorWizard extends Wizard implements IWorkbenchWizard {
super.addPages();
if(this.selection != null) {
- this.javaProject = ProjectWizardPage.getJavaProjectFromSelection(this.selection);
+ this.javaProject = this.getJavaProjectFromSelection(this.selection);
- this.javaProjectWizardPage = new ProjectWizardPage(this.javaProject);
- this.javaProjectWizardPage.setTitle(JptJaxbUiMessages.ClassesGeneratorProjectWizardPage_title);
- this.addPage(this.javaProjectWizardPage);
+ this.projectWizardPage = new JavaProjectWizardPage(this.javaProject);
+ this.projectWizardPage.setTitle(JptJaxbUiMessages.ClassesGeneratorProjectWizardPage_title);
+ this.projectWizardPage.setDescription(JptJaxbUiMessages.ClassesGeneratorProjectWizardPage_desc);
+ this.addPage(this.projectWizardPage);
// SchemaWizardPage
IFile schemaSelected = SchemaWizardPage.getSourceSchemaFromSelection(this.selection);
@@ -147,8 +152,8 @@ public class ClassesGeneratorWizard extends Wizard implements IWorkbenchWizard {
// ********** intra-wizard methods **********
public IJavaProject getJavaProject() {
- if(this.javaProjectWizardPage != null) {
- return this.javaProjectWizardPage.getJavaProject();
+ if(this.projectWizardPage != null) {
+ this.javaProject = this.projectWizardPage.getJavaProject();
}
return this.javaProject;
}
@@ -202,7 +207,29 @@ public class ClassesGeneratorWizard extends Wizard implements IWorkbenchWizard {
}
// ********** internal methods **********
-
+
+ public 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 IJavaProject getJavaProjectFrom(IProject project) {
+ return (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class));
+ }
+
private boolean displayOverridingClassesWarning(ClassesGeneratorOptions generatorOptions) {
if( ! this.isOverridingClasses(generatorOptions)) {
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
index 8e94a00130..0f9371cfbc 100644
--- 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
@@ -19,7 +19,7 @@ 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.jpt.jaxb.ui.internal.wizards.JavaProjectWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -143,9 +143,9 @@ public class SchemaWizardPage extends WizardPage {
private void updateTargetProject() {
IWizardPage previousPage = this.getPreviousPage();
- if(previousPage instanceof ProjectWizardPage) {
+ if(previousPage instanceof JavaProjectWizardPage) {
// get project from previousPage
- this.targetProject = (((ProjectWizardPage)previousPage).getJavaProject()).getProject();
+ this.targetProject = (((JavaProjectWizardPage)previousPage).getJavaProject()).getProject();
}
else if(initialSelection != null && ! this.initialSelection.isEmpty()) {
// no previousPage - get project from initialSelection
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java
index 1b3f5be012..e551a5e32f 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java
@@ -52,7 +52,7 @@ public class CheckboxTreeAndListGroup implements ICheckStateListener, ISelection
private Object fRoot;
private Object fCurrentTreeSelection;
private List fExpandedTreeNodes= new ArrayList();
- private Map fCheckedStateStore= new HashMap(9);
+ private Map fCheckedStateStore= this.buildCheckedStateStore();
private List fWhiteCheckedTreeItems= new ArrayList();
private List fListeners= new ArrayList();
@@ -339,7 +339,7 @@ public class CheckboxTreeAndListGroup implements ICheckStateListener, ISelection
*/
public Iterator getAllCheckedListItems() {
Set result= new HashSet();
- Iterator listCollectionsEnum= fCheckedStateStore.values().iterator();
+ Iterator listCollectionsEnum= this.fCheckedStateStore.values().iterator();
while (listCollectionsEnum.hasNext())
result.addAll((List)listCollectionsEnum.next());
return result.iterator();
@@ -507,7 +507,7 @@ public class CheckboxTreeAndListGroup implements ICheckStateListener, ISelection
*
*@param treeElement java.lang.Object
*/
- protected void populateListViewer(final Object treeElement) {
+ public void populateListViewer(final Object treeElement) {
if (treeElement == fCurrentTreeSelection)
return;
fCurrentTreeSelection= treeElement;
@@ -792,6 +792,10 @@ public class CheckboxTreeAndListGroup implements ICheckStateListener, ISelection
return new HashSet(fWhiteCheckedTreeItems);
}
+ private HashMap buildCheckedStateStore() {
+ return new HashMap(9);
+ }
+
private void handleUpdateSelection(Map items) {
Iterator keyIterator= items.keySet().iterator();
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java
new file mode 100644
index 0000000000..431705840f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+* 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.schemagen;
+
+import static org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties.CONTAINER_PATH;
+import static org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties.FILE_NAME;
+import static org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties.PROJECT;
+
+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.IPath;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
+import org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen.old.SchemaGeneratorWizard;
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+
+/**
+ * NewSchemaFileWizardPage
+ */
+public class NewSchemaFileWizardPage extends WizardNewFileCreationPage {
+
+ protected IDataModel dataModel;
+
+ private IStructuredSelection initialSelection;
+
+ static public String DEFAULT_SCHEMA_NAME = "NewXMLSchema" + SchemaGeneratorWizard.XSD_EXTENSION; //$NON-NLS-1$
+
+ // ********** constructor **********
+
+ public NewSchemaFileWizardPage(String pageName, IStructuredSelection selection, IDataModel dataModel,
+ String title, String description) {
+
+ super(pageName, selection);
+ this.initialSelection = selection;
+
+ this.init(dataModel);
+ this.setTitle(title);
+ this.setDescription(description);
+ }
+
+ protected void init(IDataModel dataModel) {
+ this.dataModel = dataModel;
+
+ IProject project = this.getProjectFromInitialSelection();
+ this.dataModel.setProperty(PROJECT, project);
+
+ IPath containerPath = (IPath) this.dataModel.getProperty(CONTAINER_PATH);
+ if (containerPath != null) {
+ this.setContainerFullPath(containerPath);
+ }
+ }
+
+ // ********** IDialogPage implementation **********
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+
+ this.setFileName(DEFAULT_SCHEMA_NAME);
+ }
+
+ // ********** intra-wizard methods **********
+
+ public IProject getProject() {
+ return (IProject) this.dataModel.getProperty(PROJECT);
+ }
+
+ public IPath getFilePath() {
+ return this.getContainerFullPath();
+ }
+
+ // ********** validation **********
+
+ @Override
+ protected boolean validatePage() {
+ this.dataModel.setProperty(PROJECT, this.getProjectNamed(this.getContainerName()));
+ this.dataModel.setProperty(CONTAINER_PATH, this.getContainerFullPath());
+ this.dataModel.setProperty(FILE_NAME, this.getFileName());
+
+ boolean valid = super.validatePage();
+ if( ! valid) {
+ return valid;
+ }
+
+ valid = this.projectIsJavaProject(this.getProject());
+ if( ! valid) {
+ this.setErrorMessage(JptJaxbUiMessages.NewSchemaFileWizardPage_errorNotJavaProject);
+ return valid;
+ }
+ this.setErrorMessage(null);
+
+ return valid;
+ }
+
+ // ********** internal methods **********
+
+ private boolean projectIsJavaProject(IProject project) {
+ try {
+ return (project != null) && (project.hasNature(JavaCore.NATURE_ID));
+ }
+ catch (CoreException e) {
+ return false;
+ }
+ }
+
+ 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 IProject getProjectNamed(String projectName) {
+ if(StringTools.stringIsEmpty(projectName)) {
+ return null;
+ }
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ }
+
+ private String getContainerName() {
+ IPath containerPath = this.getContainerFullPath();
+ if(containerPath == null) {
+ return null;
+ }
+ String containerName = containerPath.segment(0);
+ return containerName;
+ }
+
+}
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 d864ad8df1..e9570f8010 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
@@ -9,8 +9,8 @@
*******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen;
+import java.io.File;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IProject;
@@ -18,55 +18,66 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
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.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jpt.jaxb.core.internal.SchemaGenerator;
+import org.eclipse.jpt.jaxb.core.internal.operations.SchemaFileCreationDataModelProvider;
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;
-import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
-public class SchemaGeneratorWizard extends Wizard implements IExportWizard {
-
- protected IStructuredSelection selection;
+/**
+ * SchemaGeneratorWizard
+ */
+public class SchemaGeneratorWizard extends Wizard implements INewWizard
+{
+ protected IStructuredSelection initialSelection;
+ private IJavaProject targetProject;
+
+ protected IDataModel dataModel;
+
+ private NewSchemaFileWizardPage newSchemaFileWizardPage;
- private ProjectWizardPage javaProjectWizardPage;
- protected SchemaGeneratorWizardPage schemaGenWizardPage;
+ private SchemaGeneratorWizardPage schemaGenWizardPage;
public static final String XSD_EXTENSION = ".xsd"; //$NON-NLS-1$
-
+
// ********** constructor **********
public SchemaGeneratorWizard() {
super();
+ setWindowTitle(JptJaxbUiMessages.SchemaGeneratorWizard_title);
+ setDefaultPageImageDescriptor(JptJaxbUiPlugin.getImageDescriptor(JptJaxbUiIcons.SCHEMA_GEN_WIZ_BANNER));
}
-
- // ********** IWorkbenchWizard implementation **********
public void init(IWorkbench workbench, IStructuredSelection selection) {
-
- this.selection = this.getValidSelection();
+ this.initialSelection = selection;
- this.setWindowTitle(JptJaxbUiMessages.SchemaGeneratorWizard_title);
- this.setDefaultPageImageDescriptor(JptJaxbUiPlugin.getImageDescriptor(JptJaxbUiIcons.SCHEMA_GEN_WIZ_BANNER));
- this.setNeedsProgressMonitor(true);
+ if (selection == null || selection.isEmpty()) {
+ return;
+ }
+ this.targetProject = this.getProjectFromInitialSelection();
+ this.dataModel = null;
}
// ********** IWizard implementation **********
@@ -74,25 +85,23 @@ public class SchemaGeneratorWizard extends Wizard implements IExportWizard {
@Override
public void addPages() {
super.addPages();
- if(this.selection.isEmpty()) {
- this.javaProjectWizardPage = new ProjectWizardPage();
- this.javaProjectWizardPage.setTitle(JptJaxbUiMessages.SchemaGeneratorProjectWizardPage_title);
- this.addPage(this.javaProjectWizardPage);
- }
+
+ this.newSchemaFileWizardPage = this.buildNewSchemaFileWizardPage(this.initialSelection);
+ this.addPage(this.newSchemaFileWizardPage);
- this.schemaGenWizardPage = new SchemaGeneratorWizardPage(this.selection);
+ this.schemaGenWizardPage = this.buildSchemaGeneratorWizardPage(this.buildSelection(this.getProject()));
this.addPage(this.schemaGenWizardPage);
}
@Override
public boolean performFinish() {
- IJavaProject javaProject = this.getJavaProject();
+ this.targetProject = this.getJavaProject();
String[] sourceClassNames = this.buildSourceClassNames(this.getAllCheckedItems());
WorkspaceJob genSchemaJob = new GenerateSchemaJob(
- javaProject,
+ this.targetProject,
sourceClassNames,
this.getTargetSchema(),
this.usesMoxy());
@@ -101,22 +110,59 @@ public class SchemaGeneratorWizard extends Wizard implements IExportWizard {
return true;
}
+ // ********** intra-wizard methods **********
+
+ public IJavaProject getJavaProject() {
+ return this.getJavaProjectFrom(this.getProject());
+ }
+
// ********** internal methods **********
+
+ private IProject getProject() {
+ return this.newSchemaFileWizardPage.getProject();
+ }
+
+ private IJavaProject getProjectFromInitialSelection() {
+ IJavaProject project = null;
+
+ Object firstElement = this.initialSelection.getFirstElement();
+ if(firstElement instanceof IJavaElement) {
+ IJavaElement javaElement = (IJavaElement)firstElement;
+ int type = javaElement.getElementType();
+ if(type == IJavaElement.JAVA_PROJECT) {
+ project = (IJavaProject)javaElement;
+ }
+ else if(type == IJavaElement.PACKAGE_FRAGMENT) {
+ project = ((IPackageFragment)javaElement).getJavaProject();
+ }
+ }
+ return project;
+ }
+
+ private IJavaProject getJavaProjectFrom(IProject project) {
+ IJavaProject javaProject = (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class));
+ if(javaProject == null) {
+ throw new RuntimeException("Not a Java Project"); //$NON-NLS-1$
+ }
+ return javaProject;
+ }
private String getTargetSchema() {
- String targetSchema = this.schemaGenWizardPage.getSchemaPath();
+
+ IPath filePath = this.newSchemaFileWizardPage.getFilePath();
+ String fileName = this.newSchemaFileWizardPage.getFileName();
+ String targetSchema = filePath.toOSString() + File.separator + fileName;
if ( ! FileTools.extension(targetSchema).equalsIgnoreCase(XSD_EXTENSION)) {
targetSchema += XSD_EXTENSION;
}
- return targetSchema;
- }
-
- private IJavaProject getJavaProject() {
- return this.schemaGenWizardPage.getJavaProject();
+
+ return this.makeRelativeToProjectPath(targetSchema);
}
- private boolean usesMoxy() {
- return this.schemaGenWizardPage.usesMoxy();
+ private String makeRelativeToProjectPath(String filePath) {
+ Path path = new Path(filePath);
+ IPath relativePath = path.makeRelativeTo(this.targetProject.getProject().getLocation());
+ return relativePath.removeFirstSegments(1).toOSString();
}
private Object[] getAllCheckedItems() {
@@ -138,46 +184,31 @@ public class SchemaGeneratorWizard extends Wizard implements IExportWizard {
return ArrayTools.array(classNames, new String[0]);
}
- /**
- * Gets the current workspace page selection and converts it to a valid
- * selection for this wizard.
- * Valid selections:
- * - Java projects
- * - Source package fragments
- * all other input elements are ignored
- *
- * @return a valid structured selection based on the current selection
- */
- private IStructuredSelection getValidSelection() {
- ISelection currentSelection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
- if(currentSelection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
- List<IAdaptable> selectedElements = new ArrayList<IAdaptable>(structuredSelection.size());
- Iterator<?> i = structuredSelection.iterator();
- while(i.hasNext()) {
- Object selectedElement = i.next();
- if(selectedElement instanceof IProject) {
- this.addProject(selectedElements, (IProject)selectedElement);
- }
- else if(selectedElement instanceof IJavaElement) {
- this.addJavaElement(selectedElements, (IJavaElement)selectedElement);
- }
- }
- return new StructuredSelection(selectedElements);
- }
- return StructuredSelection.EMPTY;
+ private boolean usesMoxy() {
+ return this.schemaGenWizardPage.usesMoxy();
}
-
- private void addJavaElement(List<IAdaptable> selectedElements, IJavaElement javaElement) {
- if(javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
- if( ! isInArchiveOrExternal(javaElement))
- selectedElements.add(javaElement);
- }
+
+ protected NewSchemaFileWizardPage buildNewSchemaFileWizardPage(IStructuredSelection selection) {
+ return new NewSchemaFileWizardPage(
+ "Page_1", selection, this.getDataModel(), //$NON-NLS-1$
+ JptJaxbUiMessages.SchemaGeneratorProjectWizardPage_title,
+ JptJaxbUiMessages.SchemaGeneratorProjectWizardPage_desc);
}
+
+ protected SchemaGeneratorWizardPage buildSchemaGeneratorWizardPage(IStructuredSelection selection) {
+ return new SchemaGeneratorWizardPage(selection);
+ }
+
+ private IStructuredSelection buildSelection(IProject project) {
- private void addProject(List<IAdaptable> selectedElements, IProject project) {
+ List<IAdaptable> selectedElements = new ArrayList<IAdaptable>(1);
+ this.addProjectTo(selectedElements, project);
+ return new StructuredSelection(selectedElements);
+ }
+
+ private void addProjectTo(List<IAdaptable> selectedElements, IProject project) {
try {
- if(project.hasNature(JavaCore.NATURE_ID))
+ if(project != null && project.hasNature(JavaCore.NATURE_ID))
selectedElements.add(JavaCore.create(project));
}
catch(CoreException ex) {
@@ -185,9 +216,15 @@ public class SchemaGeneratorWizard extends Wizard implements IExportWizard {
}
}
- private static boolean isInArchiveOrExternal(IJavaElement element) {
- IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
- return root != null && (root.isArchive() || root.isExternal());
+ protected IDataModel getDataModel() {
+ if (this.dataModel == null) {
+ this.dataModel = DataModelFactory.createDataModel(getDefaultProvider());
+ }
+ return this.dataModel;
+ }
+
+ protected IDataModelProvider getDefaultProvider() {
+ return new SchemaFileCreationDataModelProvider();
}
// ********** generate schema job **********
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 9a2b065104..6ac87ac400 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
@@ -11,16 +11,8 @@ package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen;
import java.util.Iterator;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.jdt.core.IClassFile;
-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.IType;
@@ -44,14 +36,9 @@ 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;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
-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.layout.GridData;
@@ -59,16 +46,14 @@ 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.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.Bundle;
+/**
+ * SchemaGeneratorWizardPage
+ */
public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage {
- private IStructuredSelection initialSelection;
private IJavaProject targetProject;
// widgets
@@ -90,8 +75,7 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
public SchemaGeneratorWizardPage(IStructuredSelection selection) {
super("JAXB Schema Generator", selection, null); //$NON-NLS-1$
-
- this.initialSelection = selection;
+
this.setUsesMoxy(false);
this.setTitle(JptJaxbUiMessages.SchemaGeneratorWizardPage_title);
this.setDescription(JptJaxbUiMessages.SchemaGeneratorWizardPage_desc);
@@ -108,39 +92,29 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
public void setVisible(boolean visible) {
super.setVisible(visible);
- this.updateTargetProject();
- this.setDefaultSchemaFile();
- this.updateInputGroupTreeFilter();
-
- // default usesMoxy to true only when JPT EclipseLink bundle exists and MOXy is on the classpath
- this.updateUsesMoxy(this.jptEclipseLinkBundleExists() && this.moxyIsOnClasspath());
-
- // checkbox 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();
- this.giveFocusToDestination();
+ if(visible) {
+ this.updateTargetProject();
+ this.updateInputGroupTreeFilter();
+
+ // default usesMoxy to true only when JPT EclipseLink bundle exists and MOXy is on the classpath
+ this.updateUsesMoxy(this.jptEclipseLinkBundleExists() && this.moxyIsOnClasspath());
+
+ // checkbox 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();
+ }
}
- // default the schema name to the project name
- protected void setDefaultSchemaFile() {
- String defaultSchemaName = this.targetProject.getProject().getName() + SchemaGeneratorWizard.XSD_EXTENSION;
- this.settingsGroup.schemaFileText.setText(defaultSchemaName);
- this.settingsGroup.schemaFileText.setSelection(0, defaultSchemaName.length());
- }
-
// ********** IWizardPage implementation **********
@Override
public boolean isPageComplete() {
- boolean complete = this.validateDestinationGroup();
- if(complete) {
- complete = this.validateSourceGroup();
+ boolean complete = this.validateSourceGroup();
if(complete) {
this.validateProjectClasspath();
}
- }
return complete;
}
@@ -153,17 +127,6 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
// ********** intra-wizard methods **********
- protected IJavaProject getJavaProject() {
- return this.targetProject;
- }
-
- /**
- * @return The schema relative path to the project.
- */
- protected String getSchemaPath() {
- return this.settingsGroup.getSchemaPath();
- }
-
protected Object[] getAllCheckedItems() {
return ArrayTools.array(this.getInputGroup().getAllCheckedListItems());
}
@@ -173,7 +136,7 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
}
// ********** validation **********
-
+
@Override
@SuppressWarnings("restriction")
protected void updatePageCompletion() {
@@ -182,12 +145,7 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
@Override
protected boolean validateDestinationGroup() {
- boolean complete = this.targetSchemaIsEmpty();
- if( ! complete) {
- this.setErrorMessage(JptJaxbUiMessages.SchemaGeneratorWizardPage_errorNoSchema);
- return false;
- }
- this.setErrorMessage(null);
+ // do nothing
return true;
}
@@ -204,6 +162,9 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
}
private void validateProjectClasspath() {
+ if(this.targetProject == null) { // project selected available yet
+ return;
+ }
//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);
@@ -257,19 +218,13 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
}
private void updateTargetProject() {
- IWizardPage previousPage = this.getPreviousPage();
- if(previousPage instanceof ProjectWizardPage) {
- // get project from previousPage
- this.targetProject = ((ProjectWizardPage)previousPage).getJavaProject();
- }
- else if(initialSelection != null && ! this.initialSelection.isEmpty()) {
- // no previousPage - get project from initialSelection
- this.targetProject = this.getProjectFromInitialSelection();
- }
+ this.targetProject = ((SchemaGeneratorWizard)this.getWizard()).getJavaProject();
}
private void updateInputGroupTreeFilter() {
+ this.getInputGroup().setAllSelections(false);
+
if(this.projectFilter != null) {
this.getInputGroup().removeTreeFilter(this.projectFilter);
}
@@ -277,27 +232,6 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
this.getInputGroup().addTreeFilter(this.projectFilter);
}
- private IJavaProject getProjectFromInitialSelection() {
- IJavaProject project = null;
-
- Object firstElement = initialSelection.getFirstElement();
- if(firstElement instanceof IJavaElement) {
- IJavaElement javaElement = (IJavaElement)firstElement;
- int type = javaElement.getElementType();
- if(type == IJavaElement.JAVA_PROJECT) {
- project = (IJavaProject)javaElement;
- }
- else if(type == IJavaElement.PACKAGE_FRAGMENT) {
- project = ((IPackageFragment)javaElement).getJavaProject();
- }
- }
- return project;
- }
-
- private boolean targetSchemaIsEmpty() {
- return ! StringTools.stringIsEmpty(this.getSchemaPath());
- }
-
private boolean jptEclipseLinkBundleExists() {
return (this.getJptEclipseLinkBundle() != null);
}
@@ -316,7 +250,6 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
this.validateProjectClasspath();
}
-
/**
* Test if the EclipseLink Jaxb compiler is on the classpath.
*/
@@ -380,7 +313,7 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
@Override
protected void giveFocusToDestination() {
- this.settingsGroup.giveFocusToDestination();
+ // do nothing
}
// ********** UI components **********
@@ -416,7 +349,6 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
private class SettingsGroup {
private CheckboxTreeAndListGroup inputGroup;
- private Text schemaFileText;
// ********** constructor **********
@@ -433,17 +365,10 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
buildSchemaComposite(composite);
-
// Input Tree
createPlainLabel(composite, JptJaxbUiMessages.SchemaGeneratorWizardPage_packages);
this.inputGroup = this.createInputGroup(composite);
- if(initialSelection != null)
- BusyIndicator.showWhile(parent.getDisplay(), new Runnable() {
- public void run() {
- setupBasedOnInitialSelections();
- }
- });
}
protected void buildSchemaComposite(Composite parent) {
@@ -455,84 +380,10 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- // Schema Location
- this.buildLabel(composite, JptJaxbUiMessages.SchemaGeneratorWizardPage_shemaLocation);
- this.schemaFileText = this.buildSchemaText(composite);
- this.buildBrowseButton(composite, 1);
-
- }
- // ********** intra-wizard methods **********
-
- /**
- * @return The schema relative path to the project.
- */
- protected String getSchemaPath() {
- return this.schemaFileText.getText();
- }
-
- protected void giveFocusToDestination() {
- this.schemaFileText.setFocus();
}
// ********** UI components **********
- private Label buildLabel(Composite parent, String text) {
- Label label = new Label(parent, SWT.LEFT);
- label.setText(text);
- label.setLayoutData(new GridData());
- return label;
- }
-
- private Text buildSchemaText(Composite parent) {
-
- Text text = new Text(parent, SWT.BORDER);
- GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.grabExcessHorizontalSpace = true;
- text.setLayoutData(gridData);
- text.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- updatePageCompletion();
- }
- });
- return text;
- }
-
- private Button buildBrowseButton(Composite parent, int horizontalSpan) {
-
- Button browseButton = new Button(parent, SWT.PUSH);
- browseButton.setText(JptJaxbUiMessages.SchemaGeneratorWizardPage_browse);
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.horizontalSpan = horizontalSpan;
- browseButton.setLayoutData(gridData);
- browseButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {}
-
- public void widgetSelected(SelectionEvent e) {
-
- String fileName = promptFile();
- if( ! StringTools.stringIsEmpty(fileName)) {
- schemaFileText.setText(makeRelativeToProjectPath(fileName));
- }
- }
- });
- return browseButton;
- }
-
- /**
- * The browse button was clicked, its action invokes this action which should
- * prompt the user to select a file and return it.
- */
- private String promptFile() {
- FileDialog dialog = new FileDialog(getShell());
- dialog.setText(JptJaxbUiMessages.SchemaGeneratorWizardPage_chooseSchemaDialogTitle);
- dialog.setFilterPath(this.getFilterPath());
- dialog.setFilterExtensions(new String[] {"*.xsd"}); //$NON-NLS-1$
- String filePath = dialog.open();
-
- return (filePath != null) ? filePath : null;
- }
-
/**
* Creates the checkbox tree and list for selecting resources.
*
@@ -585,67 +436,5 @@ public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage
checkboxTreeGroup.addCheckStateListener(listener);
return checkboxTreeGroup;
}
-
- // ********** internal methods **********
-
- private String makeRelativeToProjectPath(String filePath) {
- Path path = new Path(filePath);
- IPath relativePath = path.makeRelativeTo(targetProject.getProject().getLocation());
- return relativePath.toOSString();
- }
-
- /**
- * Returns the path that the dialog will use to filter the directories it shows to
- * the argument, which may be null.
- * If the string is null, then the operating system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent. For convenience, either
- * '/' or '\' can be used as a path separator.
- * </p>
- *
- * @return The filter path
- */
- private String getFilterPath() {
- return targetProject.getProject().getLocation().toOSString();
- }
-
- private void setupBasedOnInitialSelections() {
-
- Iterator<?> iterator = initialSelection.iterator();
- while(iterator.hasNext()) {
- Object selectedElement = iterator.next();
-
- if(selectedElement instanceof IResource && !((IResource)selectedElement).isAccessible())
- continue;
-
- if(selectedElement instanceof IJavaElement && !((IJavaElement)selectedElement).exists())
- continue;
-
- if(selectedElement instanceof ICompilationUnit || selectedElement instanceof IClassFile || selectedElement instanceof IFile)
- this.inputGroup.initialCheckListItem(selectedElement);
- else {
- if(selectedElement instanceof IFolder) {
- // Convert resource to Java element if possible
- IJavaElement je = JavaCore.create((IResource)selectedElement);
- if(je != null && je.exists() && je.getJavaProject().isOnClasspath((IResource)selectedElement)) {
-
- selectedElement = je;
- je.toString();
- }
- }
- this.inputGroup.initialCheckTreeItem(selectedElement);
- }
- }
-
- TreeItem[] items = this.inputGroup.getTree().getItems();
- int i = 0;
- while(i < items.length && ! items[i].getChecked())
- i++;
- if(i < items.length) {
- this.inputGroup.getTree().setSelection(new TreeItem[] {items[i]});
- this.inputGroup.getTree().showSelection();
- this.inputGroup.populateListViewer(items[i].getData());
- }
- }
}
}

Back to the top