Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2010-09-28 20:48:56 +0000
committerpfullbright2010-09-28 20:48:56 +0000
commite49a4c74a203d297f3e8dbd92458549581085cf7 (patch)
treedd3430f5adcbb7616b9ef82f27ebc1435b8bd8e7 /jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java
parentd735ff30d68aa292fe7a2333da50bd7198327e9d (diff)
downloadwebtools.dali-e49a4c74a203d297f3e8dbd92458549581085cf7.tar.gz
webtools.dali-e49a4c74a203d297f3e8dbd92458549581085cf7.tar.xz
webtools.dali-e49a4c74a203d297f3e8dbd92458549581085cf7.zip
moved to jaxb component
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java')
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java145
1 files changed, 145 insertions, 0 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java
new file mode 100644
index 0000000000..aa53811e71
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+* 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.*;
+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.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;
+ }
+
+}

Back to the top