diff options
author | Tran Le | 2012-12-26 16:21:40 +0000 |
---|---|---|
committer | Tran Le | 2012-12-26 16:21:40 +0000 |
commit | 8ac751a8b8531fb642ccd9f85746afe7ed2da36c (patch) | |
tree | 8d5295a5c82d1c451ff782d9fc62a9e636a752c6 | |
parent | cc909737f7584a6b16a9733660d4da2eedb26b0b (diff) | |
download | webtools.dali-8ac751a8b8531fb642ccd9f85746afe7ed2da36c.tar.gz webtools.dali-8ac751a8b8531fb642ccd9f85746afe7ed2da36c.tar.xz webtools.dali-8ac751a8b8531fb642ccd9f85746afe7ed2da36c.zip |
393448 - convert our plugin.xml popupMenus and actionsSets to thev201212262036
command extension point
10 files changed, 808 insertions, 0 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/handlers/GenerateDbwsHandler.java b/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/handlers/GenerateDbwsHandler.java new file mode 100644 index 0000000000..a802c6902e --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/handlers/GenerateDbwsHandler.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.dbws.eclipselink.ui.internal.handlers; + +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.jface.viewers.IStructuredSelection; +import org.eclipse.jpt.dbws.eclipselink.ui.internal.DbwsGeneratorUi; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * GenerateDbwsHandler + */ +public class GenerateDbwsHandler extends AbstractHandler +{ + public Object execute(ExecutionEvent event) throws ExecutionException { + // There is always only one element in the actual selection. + IStructuredSelection selection = (IStructuredSelection)HandlerUtil.getCurrentSelectionChecked(event); + + IFile xmlFile = this.buildXmlFile(selection.getFirstElement()); + if(xmlFile != null) { + DbwsGeneratorUi.generate(xmlFile); + } + return null; + } + + private IFile buildXmlFile(Object selection) { + if (selection instanceof IFile) { + return (IFile) selection; + } + return null; + } + +}
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/handlers/GenerateClassesHandler.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/handlers/GenerateClassesHandler.java new file mode 100644 index 0000000000..47ba447b9d --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/handlers/GenerateClassesHandler.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.handlers; + +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.jface.viewers.IStructuredSelection; +import org.eclipse.jpt.jaxb.ui.internal.ClassesGeneratorUi; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * GenerateClassesHandler + */ +public class GenerateClassesHandler extends AbstractHandler +{ + public Object execute(ExecutionEvent event) throws ExecutionException { + // There is always only one element in the actual selection. + IStructuredSelection selection = (IStructuredSelection)HandlerUtil.getCurrentSelectionChecked(event); + + IFile xsdFile = this.buildXsdFile(selection.getFirstElement()); + if(xsdFile != null) { + ClassesGeneratorUi.generate(xsdFile); + } + return null; + } + + private IFile buildXsdFile(Object selection) { + if (selection instanceof IFile) { + return (IFile) selection; + } + return null; + } + +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/handlers/NewDynamicEntityHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/handlers/NewDynamicEntityHandler.java new file mode 100644 index 0000000000..ee642c8855 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/handlers/NewDynamicEntityHandler.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.jpa.eclipselink.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.EclipseLinkDynamicEntityWizard; +import org.eclipse.jpt.jpa.ui.internal.handlers.NewEntityHandler.OpenJptWizardAction; +import org.eclipse.ui.INewWizard; + +/** + * NewDynamicEntityHandler + */ +public class NewDynamicEntityHandler extends AbstractHandler +{ + + public Object execute(ExecutionEvent event) throws ExecutionException { + + Command command = event.getCommand(); + + OpenJptWizardAction openJptWizardAction = new OpenDynamicEntityWizardAction(command); + openJptWizardAction.run(); + + return null; + } + + // ********** OpenDynamicEntityWizardAction ********** + + public static class OpenDynamicEntityWizardAction extends OpenJptWizardAction { + + public OpenDynamicEntityWizardAction(Command command) { + super(command); + } + + @Override + protected INewWizard createWizard() throws CoreException { + return new EclipseLinkDynamicEntityWizard(null); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/handlers/NewEclipseLinkMappingFileHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/handlers/NewEclipseLinkMappingFileHandler.java new file mode 100644 index 0000000000..defc468dc5 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/handlers/NewEclipseLinkMappingFileHandler.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.jpa.eclipselink.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.EclipseLinkMappingFileWizard; +import org.eclipse.jpt.jpa.ui.internal.handlers.NewEntityHandler.OpenJptWizardAction; +import org.eclipse.ui.INewWizard; + +/** + * NewEclipseLinkMappingFileHandler + */ +public class NewEclipseLinkMappingFileHandler extends AbstractHandler +{ + + public Object execute(ExecutionEvent event) throws ExecutionException { + + Command command = event.getCommand(); + + OpenJptWizardAction openJptWizardAction = new OpenEclipseLinkMappingFileWizardAction(command); + openJptWizardAction.run(); + + return null; + } + + // ********** OpenEclipseLinkMappingFileWizardAction ********** + + public static class OpenEclipseLinkMappingFileWizardAction extends OpenJptWizardAction { + + public OpenEclipseLinkMappingFileWizardAction(Command command) { + super(command); + } + + @Override + protected INewWizard createWizard() throws CoreException { + return new EclipseLinkMappingFileWizard(null); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateDDLHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateDDLHandler.java new file mode 100644 index 0000000000..b1ddda213c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateDDLHandler.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.jpa.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jpt.common.core.internal.utility.PlatformTools; +import org.eclipse.jpt.jpa.core.JpaProject; +import org.eclipse.jpt.jpa.ui.JpaPlatformUi; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * See org.eclipse.jpt.jpa.ui/plugin.xml + */ +public class GenerateDDLHandler extends AbstractHandler +{ + public Object execute(ExecutionEvent event) throws ExecutionException { + JpaProject jpaProject = null; + ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); + + if(selection instanceof IStructuredSelection) { + Object selectedObject = ((IStructuredSelection) selection).getFirstElement(); + jpaProject = this.adaptSelection(selectedObject); + } + if(jpaProject != null) { + this.generateDDL(jpaProject, (IStructuredSelection)selection); + } + return null; + } + + protected void generateDDL(JpaProject project, IStructuredSelection selection) { + this.getJpaPlatformUi(project).generateDDL(project, selection); + } + + private JpaProject adaptSelection(Object selectedObject) { + return PlatformTools.getAdapter(selectedObject, JpaProject.class); + } + + private JpaPlatformUi getJpaPlatformUi(JpaProject project) { + return (JpaPlatformUi) project.getJpaPlatform().getAdapter(JpaPlatformUi.class); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java new file mode 100644 index 0000000000..8e46c02fa4 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.jpa.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jpt.common.core.internal.utility.PlatformTools; +import org.eclipse.jpt.jpa.core.JpaProject; +import org.eclipse.jpt.jpa.ui.JpaPlatformUi; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * See org.eclipse.jpt.jpa.ui/plugin.xml + */ +public class GenerateEntitiesHandler extends AbstractHandler +{ + public Object execute(ExecutionEvent event) throws ExecutionException { + JpaProject jpaProject = null; + ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); + + if (selection instanceof IStructuredSelection) { + Object selectedObject = ((IStructuredSelection) selection).getFirstElement(); + jpaProject = this.adaptSelection(selectedObject); + } + if (jpaProject != null) { + this.generateEntities(jpaProject, (IStructuredSelection)selection); + } + return null; + } + + protected void generateEntities(JpaProject project, IStructuredSelection selection) { + this.getJpaPlatformUi(project).generateEntities(project, selection); + } + + private JpaProject adaptSelection(Object selectedObject) { + return PlatformTools.getAdapter(selectedObject, JpaProject.class); + } + + private JpaPlatformUi getJpaPlatformUi(JpaProject project) { + return (JpaPlatformUi) project.getJpaPlatform().getAdapter(JpaPlatformUi.class); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java new file mode 100644 index 0000000000..5a8fd56fc4 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * 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.jpa.ui.internal.handlers; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IProject; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.jpt.jpa.core.JpaProject; +import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin; +import org.eclipse.jpt.jpa.ui.internal.wizards.JpaMakePersistentWizard; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * MakePersistentHandler + */ +public class MakePersistentHandler extends AbstractHandler +{ + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); + + for (Map.Entry<IProject, Set<IType>> entry : this.buildSelectedTypes(selection).entrySet()) { + IProject project = entry.getKey(); + Set<IType> types = entry.getValue(); + JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class); + if (jpaProject != null) { + //open the wizard once for each selected project + JpaMakePersistentWizard wizard = new JpaMakePersistentWizard(jpaProject, types); + WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard); + dialog.create(); + dialog.open(); + } + } + return null; + } + + /** + * Return a map containing lists of types, keyed by project. + * <p> + * The action is contributed for:<ul> + * <li>{@link IType} + * <li>{@link ICompilationUnit} + * <li>{@link IPackageFragment} + * <li>{@link IPackageFragmentRoot} that is a source folder + * </ul> + */ + private Map<IProject, Set<IType>> buildSelectedTypes(ISelection currentSelection) { + if ( ! (currentSelection instanceof StructuredSelection)) { + return Collections.emptyMap(); + } + HashMap<IProject, Set<IType>> types = new HashMap<IProject, Set<IType>>(); + for (Object sel : ((StructuredSelection) currentSelection).toList()) { + switch (((IJavaElement) sel).getElementType()) { + case IJavaElement.PACKAGE_FRAGMENT_ROOT : + this.addSelectedTypes((IPackageFragmentRoot) sel, types); + break; + case IJavaElement.PACKAGE_FRAGMENT : + this.addSelectedTypes((IPackageFragment) sel, types); + break; + case IJavaElement.COMPILATION_UNIT : + this.addSelectedTypes((ICompilationUnit) sel, types); + break; + case IJavaElement.TYPE : + this.addSelectedType((IType) sel, types); + break; + default : + break; + } + } + return types; + } + + private void addSelectedTypes(IPackageFragmentRoot packageFragmentRoot, Map<IProject, Set<IType>> types) { + for (IJavaElement pkgFragment : this.getPackageFragments(packageFragmentRoot)) { + this.addSelectedTypes((IPackageFragment) pkgFragment, types); + } + } + + private void addSelectedTypes(IPackageFragment packageFragment, Map<IProject, Set<IType>> types) { + for (ICompilationUnit compUnit : this.getCompilationUnits(packageFragment)) { + this.addSelectedTypes(compUnit, types); + } + } + + private void addSelectedTypes(ICompilationUnit compilationUnit, Map<IProject, Set<IType>> types) { + IType primaryType = compilationUnit.findPrimaryType(); + if (primaryType != null) { + this.addSelectedType(primaryType, types); + } + } + + private void addSelectedType(IType primaryType, Map<IProject, Set<IType>> typesMap) { + IProject project = primaryType.getJavaProject().getProject(); + Set<IType> types = typesMap.get(project); + if (types == null) { + types = new HashSet<IType>(); + typesMap.put(project, types); + } + types.add(primaryType); + } + + private ICompilationUnit[] getCompilationUnits(IPackageFragment packageFragment) { + try { + return packageFragment.getCompilationUnits(); + } + catch (JavaModelException e) { + JptJpaUiPlugin.instance().logError(e); + } + return new ICompilationUnit[0]; + } + + private IJavaElement[] getPackageFragments(IPackageFragmentRoot packageFragmentRoot) { + try { + return packageFragmentRoot.getChildren(); + } + catch (JavaModelException e) { + JptJpaUiPlugin.instance().logError(e); + } + return new IJavaElement[0]; + } + + private Shell getCurrentShell() { + return Display.getCurrent().getActiveShell(); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/NewEntityHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/NewEntityHandler.java new file mode 100644 index 0000000000..5e5b03070b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/NewEntityHandler.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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.jpa.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.common.NotDefinedException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin; +import org.eclipse.jpt.jpa.ui.internal.wizards.entity.EntityWizard; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.PlatformUI; + +/** + * NewEntityHandler + */ +public class NewEntityHandler extends AbstractHandler +{ + + public Object execute(ExecutionEvent event) throws ExecutionException { + + Command command = event.getCommand(); + + OpenJptWizardAction openJptWizardAction = new OpenJptWizardAction(command); + openJptWizardAction.run(); + + return null; + } + + // ********** OpenJptWizardAction ********** + + public static class OpenJptWizardAction extends AbstractOpenWizardAction { + + private final Command command; + + public OpenJptWizardAction(Command command) { + this.command = command; + + String commandName = null; + try { + commandName = this.command.getName(); + } + catch (NotDefinedException e1) { + commandName = ""; + } + this.setText(commandName); + this.setDescription(commandName); + this.setToolTipText(commandName); + } + + @Override + public void run() { + Shell shell = this.getShell(); + try { + INewWizard wizard = createWizard(); + wizard.init(PlatformUI.getWorkbench(), this.getSelection()); + + WizardDialog dialog = new WizardDialog(shell, wizard); + PixelConverter converter = new PixelConverter(JFaceResources.getDialogFont()); + dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20)); + dialog.create(); + int res = dialog.open(); + + this.notifyResult(res == Window.OK); + } + catch (CoreException e) { + JptJpaUiPlugin.instance().logError(e); + } + } + + @Override + protected INewWizard createWizard() throws CoreException { + return new EntityWizard(null); + } + } + +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/NewMappingFileHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/NewMappingFileHandler.java new file mode 100644 index 0000000000..b751f09940 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/NewMappingFileHandler.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.jpa.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jpt.jpa.ui.internal.handlers.NewEntityHandler.OpenJptWizardAction; +import org.eclipse.jpt.jpa.ui.internal.wizards.orm.MappingFileWizard; +import org.eclipse.ui.INewWizard; + +/** + * NewMappingFileHandler + */ +public class NewMappingFileHandler extends AbstractHandler +{ + public Object execute(ExecutionEvent event) throws ExecutionException { + + Command command = event.getCommand(); + + OpenJptWizardAction openJptWizardAction = new OpenJpaMappingFileWizardAction(command); + openJptWizardAction.run(); + + return null; + } + + // ********** OpenJpaMappingFileWizardAction ********** + + public static class OpenJpaMappingFileWizardAction extends OpenJptWizardAction { + + public OpenJpaMappingFileWizardAction(Command command) { + super(command); + } + + @Override + protected INewWizard createWizard() throws CoreException { + return new MappingFileWizard(null); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/SynchronizeClassesHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/SynchronizeClassesHandler.java new file mode 100644 index 0000000000..87118f04bf --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/SynchronizeClassesHandler.java @@ -0,0 +1,228 @@ +/******************************************************************************* + * 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.jpa.ui.internal.handlers; + +import java.lang.reflect.InvocationTargetException; +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.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jpt.common.core.resource.xml.JptXmlResource; +import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor; +import org.eclipse.jpt.common.utility.command.Command; +import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.jpa.core.JpaProject; +import org.eclipse.jpt.jpa.core.JpaProjectManager; +import org.eclipse.jpt.jpa.core.context.persistence.Persistence; +import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml; +import org.eclipse.jpt.jpa.ui.internal.JptUiMessages; +import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * SynchronizeClassesHandler + */ +public class SynchronizeClassesHandler extends AbstractHandler +{ + private IFile persistenceXmlFile; + + public Object execute(ExecutionEvent event) throws ExecutionException { + // There is always only one element in the actual selection. + IStructuredSelection selection = (IStructuredSelection)HandlerUtil.getCurrentSelectionChecked(event); + this.persistenceXmlFile = this.buildPersistenceXmlFile(selection.getFirstElement()); + + try { + IRunnableWithProgress runnable = new SyncRunnable(this.persistenceXmlFile); + this.buildProgressMonitorDialog().run(true, true, runnable); // true => fork; true => cancellable + } catch (InvocationTargetException ex) { + JptJpaUiPlugin.instance().logError(ex); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + JptJpaUiPlugin.instance().logError(ex); + } + return null; + } + + private IFile buildPersistenceXmlFile(Object selection) { + if (selection instanceof IFile) { + return (IFile) selection; + } + if (selection instanceof PersistenceXml) { + return (IFile) ((PersistenceXml) selection).getResource(); + } + return null; + } + + private ProgressMonitorDialog buildProgressMonitorDialog() { + return new ProgressMonitorDialog(null); + } + + + // ********** sync runnable ********** + + /** + * This is dispatched to the progress monitor dialog. + */ + /* CU private */ static class SyncRunnable + implements IRunnableWithProgress + { + private IFile persistenceXmlFile; + + SyncRunnable(IFile persistenceXmlFile) { + super(); + this.persistenceXmlFile = persistenceXmlFile; + } + + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + this.run_(monitor); + } catch (CoreException ex) { + throw new InvocationTargetException(ex); + } + } + + private void run_(IProgressMonitor monitor) throws CoreException { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + // lock the entire project, since we might modify the metamodel classes + ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this.persistenceXmlFile.getProject()); + workspace.run( + new SyncWorkspaceRunnable(this.persistenceXmlFile), + rule, + IWorkspace.AVOID_UPDATE, + monitor + ); + } + } + + + // ********** sync workspace runnable ********** + + /** + * This is dispatched to the Eclipse workspace. + */ + /* CU private */ static class SyncWorkspaceRunnable + implements IWorkspaceRunnable + { + private IFile persistenceXmlFile; + + SyncWorkspaceRunnable(IFile persistenceXmlFile) { + super(); + this.persistenceXmlFile = persistenceXmlFile; + } + + public void run(IProgressMonitor monitor) throws CoreException { + if (monitor.isCanceled()) { + return; + } + SubMonitor sm = SubMonitor.convert(monitor, JptUiMessages.SynchronizingClasses_TaskName, 20); + + JpaProject jpaProject = this.getJpaProject(); + if (jpaProject == null) { + return; + } + + JptXmlResource resource = jpaProject.getPersistenceXmlResource(); + if (resource == null) { + // the resource can be null if the persistence.xml file has an invalid content type + return; + } + + if (sm.isCanceled()) { + return; + } + sm.worked(1); + + PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml(); + if (persistenceXml == null) { + return; // unlikely... + } + + Persistence persistence = persistenceXml.getRoot(); + if (persistence == null) { + return; // unlikely... + } + + PersistenceUnit persistenceUnit = (persistence.getPersistenceUnitsSize() == 0) ? + persistence.addPersistenceUnit() : + persistence.getPersistenceUnit(0); + if (sm.isCanceled()) { + return; + } + sm.worked(1); + + Command syncCommand = new SyncCommand(persistenceUnit, sm.newChild(17)); + try { + this.getJpaProjectManager().execute(syncCommand, SynchronousUiCommandExecutor.instance()); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); // skip save? + throw new RuntimeException(ex); + } + + resource.save(); + sm.worked(1); + } + + private JpaProjectManager getJpaProjectManager() { + return (JpaProjectManager) this.getWorkspace().getAdapter(JpaProjectManager.class); + } + + private IProject getProject() { + return this.persistenceXmlFile.getProject(); + } + + private JpaProject getJpaProject() { + return (JpaProject) this.getProject().getAdapter(JpaProject.class); + } + + private IWorkspace getWorkspace() { + return this.persistenceXmlFile.getWorkspace(); + } + } + + + // ********** sync command ********** + + /** + * This is dispatched to the JPA project manager. + */ + /* CU private */ static class SyncCommand + implements Command + { + private final PersistenceUnit persistenceUnit; + private final IProgressMonitor monitor; + + SyncCommand(PersistenceUnit persistenceUnit, IProgressMonitor monitor) { + super(); + this.persistenceUnit = persistenceUnit; + this.monitor = monitor; + } + + public void execute() { + this.persistenceUnit.synchronizeClasses(this.monitor); + } + + @Override + public String toString() { + return ObjectTools.toString(this, this.persistenceUnit); + } + } +}
\ No newline at end of file |