Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jaxb
diff options
context:
space:
mode:
authorpfullbright2012-04-12 19:36:53 +0000
committerpfullbright2012-04-12 19:36:53 +0000
commitb7298b42a3bf04841b204cfa9309f8a41a1820c0 (patch)
tree8e7b3426d682042576f17f580cfe049b2ab24b77 /jaxb
parent40b2be4b87da52fe70eb43d664c2305a1ed4216a (diff)
downloadwebtools.dali-b7298b42a3bf04841b204cfa9309f8a41a1820c0.tar.gz
webtools.dali-b7298b42a3bf04841b204cfa9309f8a41a1820c0.tar.xz
webtools.dali-b7298b42a3bf04841b204cfa9309f8a41a1820c0.zip
bugs 331362 and 376656 - added actions for adding package-info.java/jaxb.properties
Diffstat (limited to 'jaxb')
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml16
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageAdapterFactory.java50
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageTester.java36
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java10
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF3
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml13
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/JaxbPackageTester.java47
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/META-INF/MANIFEST.MF5
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.properties2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.xml62
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/commands/AddEclipseLinkJaxbPropertyCommandHandler.java222
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.properties4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml84
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/commands/CreatePackageInfoCommandHandler.java80
14 files changed, 629 insertions, 5 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml
index 50ef08a052..6be37f5087 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml
@@ -36,6 +36,13 @@
adaptableType="org.eclipse.jdt.core.IJavaElement">
<adapter type="org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription"/>
</factory>
+
+ <!-- IPackageFragment -> JaxbPackage -->
+ <factory
+ class="org.eclipse.jpt.jaxb.core.internal.context.JaxbPackageAdapterFactory"
+ adaptableType="org.eclipse.jdt.core.IPackageFragment">
+ <adapter type="org.eclipse.jpt.jaxb.core.context.JaxbPackage"/>
+ </factory>
<factory
class="org.eclipse.jpt.jaxb.core.internal.libprov.JaxbLibraryProviderInstallOperationConfigAdapterFactory"
@@ -83,7 +90,14 @@
namespace="org.eclipse.jpt.jaxb.core"
properties="jaxbPlatform, jaxbPlatformGroup"
class="org.eclipse.jpt.jaxb.core.internal.platform.JaxbPlatformTester"/>
-
+
+ <propertyTester
+ id="org.eclipse.jpt.jaxb.core.propertyTester.jaxbPackage"
+ type="org.eclipse.jpt.jaxb.core.context.JaxbPackage"
+ namespace="org.eclipse.jpt.jaxb.core"
+ properties="hasPackageInfo"
+ class="org.eclipse.jpt.jaxb.core.internal.context.JaxbPackageTester"/>
+
</extension>
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageAdapterFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageAdapterFactory.java
new file mode 100644
index 0000000000..c918a9e0ad
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageAdapterFactory.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.context;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jpt.jaxb.core.JaxbProject;
+import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
+
+
+public class JaxbPackageAdapterFactory
+ implements IAdapterFactory {
+
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { JaxbPackage.class };
+
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IPackageFragment) {
+ return getAdapter((IPackageFragment) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IPackageFragment packageFragment, Class<?> adapterType) {
+ if (adapterType == JaxbPackage.class) {
+ return getJaxbPackage(packageFragment);
+ }
+ return null;
+ }
+
+ private JaxbPackage getJaxbPackage(IPackageFragment packageFragment) {
+ JaxbProject jaxbProject = JptJaxbCorePlugin.getJaxbProject(packageFragment.getJavaProject().getProject());
+ if (jaxbProject == null) {
+ return null;
+ }
+ return jaxbProject.getContextRoot().getPackage(packageFragment.getElementName());
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageTester.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageTester.java
new file mode 100644
index 0000000000..348517bbb1
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/JaxbPackageTester.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.context;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
+
+
+public class JaxbPackageTester
+ extends PropertyTester {
+
+ public static final String HAS_PACKAGE_INFO = "hasPackageInfo"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof JaxbPackage) {
+ return test((JaxbPackage) receiver, property, expectedValue);
+ }
+ return false;
+ }
+
+ private boolean test(JaxbPackage jaxbPackage, String property, Object expectedValue) {
+ if (property.equals(HAS_PACKAGE_INFO)) {
+ boolean hasPackageInfo = jaxbPackage.getJaxbProject().getJavaResourcePackage(jaxbPackage.getName()) != null;
+ return Tools.valuesAreEqual(hasPackageInfo, expectedValue);
+ }
+ return false;
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java
index f9873364c4..8df576788f 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java
@@ -14,6 +14,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
@@ -80,9 +81,14 @@ public abstract class AbstractJaxbFileResourceModel<S>
if (stream != null) {
this.load(new BufferedInputStream(stream));
}
- } catch (Exception ex) {
+ }
+ catch (CoreException ce) {
+ // workspace out of sync - no underlying file - simply don't load
+ }
+ catch (Exception ex) {
JptJaxbCorePlugin.log(ex);
- } finally {
+ }
+ finally {
this.closeStream(stream);
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF
index 456b30df45..07c7256bee 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF
@@ -9,7 +9,8 @@ Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Require-Bundle: org.eclipse.core.resources;bundle-version="[3.7.100,4.0.0)",
+Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.300,4.0.0)",
+ org.eclipse.core.resources;bundle-version="[3.7.100,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)",
org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)",
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml
index febcbf61d0..28efc2f92f 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml
@@ -12,6 +12,19 @@
<plugin>
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+
+ <propertyTester
+ id="org.eclipse.jpt.jaxb.eclipselink.core.propertyTester.jaxbPackage"
+ type="org.eclipse.jpt.jaxb.core.context.JaxbPackage"
+ namespace="org.eclipse.jpt.jaxb.eclipselink.core"
+ properties="hasEclipseLinkJaxbProperty"
+ class="org.eclipse.jpt.jaxb.eclipselink.core.internal.context.JaxbPackageTester"/>
+
+ </extension>
+
+
<extension
point="org.eclipse.jpt.jaxb.core.jaxbPlatforms">
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/JaxbPackageTester.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/JaxbPackageTester.java
new file mode 100644
index 0000000000..efc10690d3
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/JaxbPackageTester.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.eclipselink.core.internal.context;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
+import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource;
+
+
+public class JaxbPackageTester
+ extends PropertyTester {
+
+ public static final String HAS_ECLIPSELINK_JAXB_PROPERTY = "hasEclipseLinkJaxbProperty"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof JaxbPackage) {
+ return test((JaxbPackage) receiver, property, expectedValue);
+ }
+ return false;
+ }
+
+ private boolean test(JaxbPackage jaxbPackage, String property, Object expectedValue) {
+ if (property.equals(HAS_ECLIPSELINK_JAXB_PROPERTY)) {
+ JaxbPropertiesResource jpr =
+ jaxbPackage.getJaxbProject().getJaxbPropertiesResource(jaxbPackage.getName());
+
+ boolean value = jpr != null;
+
+ if (value) {
+ String factoryProp = "javax.xml.bind.context.factory";
+ String factoryPropValue = "org.eclipse.persistence.jaxb.JAXBContextFactory";
+ value = Tools.valuesAreEqual(jpr.getProperty(factoryProp), factoryPropValue);
+ }
+
+ return Tools.valuesAreEqual(value, expectedValue);
+ }
+ return false;
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/META-INF/MANIFEST.MF b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/META-INF/MANIFEST.MF
index ed5997bccc..8e669444a7 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/META-INF/MANIFEST.MF
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/META-INF/MANIFEST.MF
@@ -9,7 +9,9 @@ Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)",
+Require-Bundle: org.eclipse.core.resources;bundle-version="[3.5.2,4.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.jdt.core;bundle-version="[3.8.1,4.0.0)",
org.eclipse.jface;bundle-version="[3.7.0,4.0.0)",
org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)",
org.eclipse.jpt.common.ui;bundle-version="[1.0.0,2.0.0)",
@@ -18,6 +20,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)",
org.eclipse.jpt.jaxb.eclipselink.core;bundle-version="[1.0.0,2.0.0)",
org.eclipse.jpt.jaxb.ui;bundle-version="[1.1.0,2.0.0)",
org.eclipse.swt;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.ui.ide;bundle-version="[3.8.0,4.0.0)",
org.eclipse.ui.workbench;bundle-version="[3.7.0,4.0.0)"
Export-Package: org.eclipse.jpt.jaxb.eclipselink.ui,
org.eclipse.jpt.jaxb.eclipselink.ui.internal;x-internal:=true,
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.properties
index 0720b7bd33..affebbc075 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.properties
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.properties
@@ -21,3 +21,5 @@
# ====================================================================
pluginName= Dali Java Persistence Tools - EclipseLink MOXy Support - UI
providerName=Eclipse Web Tools Platform
+
+addEclipseLinkJaxbPropertyCommand=Add EclipseLink JAXB property
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.xml
index 012d4a44db..938f8a981b 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.xml
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/plugin.xml
@@ -37,4 +37,66 @@
</extension>
+
+ <extension
+ point="org.eclipse.ui.commands">
+
+ <command
+ id="org.eclipse.jpt.jaxb.eclipselink.ui.command.addEclipseLinkJaxbProperty"
+ name="%addEclipseLinkJaxbPropertyCommand"/>
+
+ </extension>
+
+
+ <extension
+ point="org.eclipse.ui.handlers">
+
+ <handler
+ commandId="org.eclipse.jpt.jaxb.eclipselink.ui.command.addEclipseLinkJaxbProperty"
+ class="org.eclipse.jpt.jaxb.eclipselink.ui.internal.commands.AddEclipseLinkJaxbPropertyCommandHandler">
+ <enabledWhen>
+ <iterate ifEmpty="false">
+ <adapt type="org.eclipse.jpt.jaxb.core.context.JaxbPackage">
+ <test
+ property="org.eclipse.jpt.jaxb.eclipselink.core.hasEclipseLinkJaxbProperty"
+ value="false"/>
+ </adapt>
+ </iterate>
+ </enabledWhen>
+ </handler>
+
+ </extension>
+
+
+ <extension
+ point="org.eclipse.ui.menus">
+
+ <!-- contributions to the JAXB menu -->
+ <menuContribution
+ locationURI="popup:org.eclipse.jpt.jaxb.ui.menu.jaxb">
+
+ <!--
+ "Add EclipseLink JAXB property" menu item for any JaxbPackage
+ that does not already have one
+ -->
+ <command
+ commandId="org.eclipse.jpt.jaxb.eclipselink.ui.command.addEclipseLinkJaxbProperty">
+ <visibleWhen>
+ <with
+ variable="selection">
+ <iterate ifEmpty="false">
+ <adapt type="org.eclipse.jpt.jaxb.core.context.JaxbPackage">
+ <test
+ property="org.eclipse.jpt.jaxb.eclipselink.core.hasEclipseLinkJaxbProperty"
+ value="false"/>
+ </adapt>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+
+ </menuContribution>
+
+ </extension>
+
</plugin>
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/commands/AddEclipseLinkJaxbPropertyCommandHandler.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/commands/AddEclipseLinkJaxbPropertyCommandHandler.java
new file mode 100644
index 0000000000..21bd600dfb
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/commands/AddEclipseLinkJaxbPropertyCommandHandler.java
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.eclipselink.ui.internal.commands;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.Properties;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
+import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource;
+import org.eclipse.jpt.jaxb.eclipselink.ui.JptJaxbEclipseLinkUiPlugin;
+import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.progress.UIJob;
+import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
+
+
+public class AddEclipseLinkJaxbPropertyCommandHandler
+ extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection =
+ (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ IWorkbenchWindow activeWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+
+ for (Iterator stream = selection.iterator(); stream.hasNext(); ) {
+ addEclipseLinkJaxbProperty(stream.next(), activeWindow);
+ }
+
+ return null;
+ }
+
+ protected void addEclipseLinkJaxbProperty(Object selectedObject, IWorkbenchWindow activeWindow) {
+ JaxbPackage jaxbPackage =
+ (JaxbPackage) Platform.getAdapterManager().getAdapter(selectedObject, JaxbPackage.class);
+
+ JaxbPropertiesResource jaxbProperties = jaxbPackage.getJaxbProject().getJaxbPropertiesResource(jaxbPackage.getName());
+
+ if (jaxbProperties == null) {
+ createJaxbPropertiesWithProperty(jaxbPackage, activeWindow);
+ }
+ else {
+ addPropertyToExistingProperties(jaxbPackage, activeWindow);
+ }
+ }
+
+ protected void createJaxbPropertiesWithProperty(
+ final JaxbPackage jaxbPackage, final IWorkbenchWindow activeWindow) {
+ final IFolder folder;
+ try {
+ folder = getFolder(jaxbPackage);
+ }
+ catch (JavaModelException jme) {
+ JptJaxbEclipseLinkUiPlugin.log(jme);
+ return;
+ }
+ Job job = new Job("Creating jaxb.properties") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ IFile file = folder.getFile("jaxb.properties");
+ InputStream stream = createInputStream(createNewProperties());
+ try {
+ file.create(stream, true, null);
+ }
+ catch (CoreException ce) {
+ JptJaxbEclipseLinkUiPlugin.log(ce);
+ return new Status(Status.ERROR, JptJaxbEclipseLinkUiPlugin.PLUGIN_ID, "Could not create jaxb.properties.");
+ }
+ AddEclipseLinkJaxbPropertyCommandHandler.this.revealAndOpenFile(file, activeWindow);
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(folder);
+ job.schedule();
+ }
+
+ protected void addPropertyToExistingProperties(
+ final JaxbPackage jaxbPackage, final IWorkbenchWindow activeWindow) {
+ final IFolder folder;
+ try {
+ folder = getFolder(jaxbPackage);
+ }
+ catch (JavaModelException jme) {
+ JptJaxbEclipseLinkUiPlugin.log(jme);
+ return;
+ }
+ Job job = new Job("Adding property to jaxb.properties.") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ IFile file = folder.getFile("jaxb.properties");
+ Properties properties = loadProperties(file);
+ if (properties == null) {
+ return new Status(Status.ERROR, JptJaxbEclipseLinkUiPlugin.PLUGIN_ID, "Could not load jaxb.properties.");
+ }
+ adjustProperties(properties);
+ InputStream stream = createInputStream(properties);
+ try {
+ file.setContents(stream, true, true, null);
+ }
+ catch (CoreException ce) {
+ JptJaxbEclipseLinkUiPlugin.log(ce);
+ return new Status(Status.ERROR, JptJaxbEclipseLinkUiPlugin.PLUGIN_ID, "Could not write to jaxb.properties.");
+ }
+ AddEclipseLinkJaxbPropertyCommandHandler.this.revealAndOpenFile(file, activeWindow);
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(folder);
+ job.schedule();
+ }
+
+ protected IFolder getFolder(JaxbPackage jaxbPackage) throws JavaModelException {
+ IPackageFragment jdtPackage =
+ (IPackageFragment) CollectionTools.get(
+ jaxbPackage.getContextRoot().getTypes(jaxbPackage), 0).
+ getJavaResourceType().getJavaResourceCompilationUnit().getCompilationUnit().getParent();
+ return (IFolder) jdtPackage.getUnderlyingResource();
+ }
+
+ protected Properties createNewProperties() {
+ Properties properties = new Properties();
+ adjustProperties(properties);
+ return properties;
+ }
+
+ protected Properties loadProperties(IFile file) {
+ Properties properties = new Properties();
+ InputStream stream = null;
+ try {
+ properties.load(file.getContents());
+ }
+ catch (Exception ex) {
+ JptJaxbEclipseLinkUiPlugin.log(ex);
+ return null;
+ }
+ finally {
+ closeStream(stream);
+ }
+ return properties;
+ }
+
+ protected void adjustProperties(Properties properties) {
+ String factoryProp = "javax.xml.bind.context.factory";
+ String factoryPropValue = "org.eclipse.persistence.jaxb.JAXBContextFactory";
+ properties.setProperty(factoryProp, factoryPropValue);
+ }
+
+ protected InputStream createInputStream(Properties properties) {
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ try {
+ properties.store(outStream, null);
+ }
+ catch (Exception e) {
+ JptJaxbCorePlugin.log(e);
+ return new ByteArrayInputStream(new byte[0]);
+ }
+ finally {
+ closeStream(outStream);
+ }
+
+ return new ByteArrayInputStream(outStream.toByteArray());
+ }
+
+ protected void closeStream(Closeable stream) {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException ex) {
+ JptJaxbEclipseLinkUiPlugin.log(ex);
+ }
+ }
+
+ protected void revealAndOpenFile(
+ final IFile file, final IWorkbenchWindow activeWindow) {
+ Job job = new UIJob("Opening jaxb.properties.") {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ BasicNewResourceWizard.selectAndReveal(file, activeWindow);
+ try {
+ IDE.openEditor(activeWindow.getActivePage(), file, true);
+ }
+ catch (PartInitException pie) {
+ JptJaxbUiPlugin.log(pie);
+ return new Status(Status.ERROR, JptJaxbEclipseLinkUiPlugin.PLUGIN_ID, "Could not open jaxb.properties in editor.");
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(file.getParent());
+ job.schedule();
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.properties
index 704b484070..8a4a68b8e4 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.properties
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.properties
@@ -38,6 +38,10 @@ newJaxbProjectWizardDesc = Create a JAXB project
jaxbCompletionProposals = JAXB Proposals
jaxbCompletionProposalComputer = JAXB Proposal Computer
+createPackageInfoCommand = Create package-info.java
+
+jaxbMenu = JAXB
+
jaxbNavigatorContent=JAXB Content
generateJaxbClasses = JAXB Classes...
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
index 9e7faddbb9..4a915d4b66 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
@@ -123,6 +123,90 @@
<extension
+ point="org.eclipse.ui.commands">
+
+ <command
+ id="org.eclipse.jpt.jaxb.ui.command.createPackageInfo"
+ name="%createPackageInfoCommand"/>
+
+ </extension>
+
+
+ <extension
+ point="org.eclipse.ui.handlers">
+
+ <handler
+ commandId="org.eclipse.jpt.jaxb.ui.command.createPackageInfo"
+ class="org.eclipse.jpt.jaxb.ui.internal.commands.CreatePackageInfoCommandHandler">
+ <enabledWhen>
+ <iterate ifEmpty="false">
+ <adapt type="org.eclipse.jpt.jaxb.core.context.JaxbPackage">
+ <test
+ property="org.eclipse.jpt.jaxb.core.hasPackageInfo"
+ value="false"/>
+ </adapt>
+ </iterate>
+ </enabledWhen>
+ </handler>
+
+ </extension>
+
+
+ <extension
+ point="org.eclipse.ui.menus">
+
+ <!-- contributions for any popup -->
+ <menuContribution
+ locationURI="popup:org.eclipse.ui.popup.any">
+
+ <!--
+ "JAXB" submenu for any JaxbPackage
+ -->
+ <menu
+ id="org.eclipse.jpt.jaxb.ui.menu.jaxb"
+ label="%jaxbMenu">
+ <visibleWhen>
+ <with
+ variable="selection">
+ <iterate ifEmpty="false">
+ <adapt type="org.eclipse.jpt.jaxb.core.context.JaxbPackage"/>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </menu>
+
+ </menuContribution>
+
+ <!-- contributions to the JAXB menu -->
+ <menuContribution
+ locationURI="popup:org.eclipse.jpt.jaxb.ui.menu.jaxb">
+
+ <!--
+ "Create package-info.java" menu item for any JaxbPackage
+ that does not already have one
+ -->
+ <command
+ commandId="org.eclipse.jpt.jaxb.ui.command.createPackageInfo">
+ <visibleWhen>
+ <with
+ variable="selection">
+ <iterate ifEmpty="false">
+ <adapt type="org.eclipse.jpt.jaxb.core.context.JaxbPackage">
+ <test
+ property="org.eclipse.jpt.jaxb.core.hasPackageInfo"
+ value="false"/>
+ </adapt>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+
+ </menuContribution>
+
+ </extension>
+
+
+ <extension
point="org.eclipse.ui.navigator.navigatorContent">
<navigatorContent
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/commands/CreatePackageInfoCommandHandler.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/commands/CreatePackageInfoCommandHandler.java
new file mode 100644
index 0000000000..ec18089158
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/commands/CreatePackageInfoCommandHandler.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.commands;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
+import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
+
+
+public class CreatePackageInfoCommandHandler
+ extends AbstractHandler {
+
+ private List<IFile> createdFiles = new Vector<IFile>();
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection =
+ (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+
+ for (Iterator stream = selection.iterator(); stream.hasNext(); ) {
+ createPackageInfo(stream.next());
+ }
+
+ for (IFile file : this.createdFiles) {
+ IWorkbenchWindow activeWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+ BasicNewResourceWizard.selectAndReveal(file, activeWindow);
+ try {
+ IDE.openEditor(activeWindow.getActivePage(), file, true);
+ }
+ catch (PartInitException pie) {
+ JptJaxbUiPlugin.log(pie);
+ }
+ }
+
+ return null;
+ }
+
+ private void createPackageInfo(Object selectedObject) {
+ JaxbPackage jaxbPackage =
+ (JaxbPackage) Platform.getAdapterManager().getAdapter(selectedObject, JaxbPackage.class);
+
+ IPackageFragment jdtPackage = getJdtPackage(jaxbPackage);
+ try {
+ ICompilationUnit cu = jdtPackage.createCompilationUnit("package-info.java", "package " + jdtPackage.getElementName() + ";", true, null);
+ this.createdFiles.add((IFile) cu.getCorrespondingResource());
+ }
+ catch (JavaModelException jme) {
+ JptJaxbUiPlugin.log(jme);
+ }
+ }
+
+ private IPackageFragment getJdtPackage(JaxbPackage jaxbPackage) {
+ return (IPackageFragment) CollectionTools.get(
+ jaxbPackage.getContextRoot().getTypes(jaxbPackage), 0).
+ getJavaResourceType().getJavaResourceCompilationUnit().getCompilationUnit().getParent();
+ }
+}

Back to the top