diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java')
-rw-r--r-- | jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java index 1068d7fd75..3c070571f3 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java @@ -1,57 +1,53 @@ /******************************************************************************* - * Copyright (c) 2008 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 - *******************************************************************************/ + * Copyright (c) 2008, 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.commands; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jpt.common.core.internal.utility.PlatformTools; import org.eclipse.jpt.jpa.core.context.orm.EntityMappings; import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; import org.eclipse.jpt.jpa.ui.internal.dialogs.AddPersistentClassDialog; -import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection; -import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory; +import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; -public class AddPersistentClassHandler extends AbstractHandler +/** + * Add an <code>orm.xml</code> type to the selected entity mappings. + * This handler is only active if <em>one</em> entity mappings is selected. + * <p> + * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>. + */ +public class AddPersistentClassHandler + extends AbstractHandler { - public Object execute(ExecutionEvent executionEvent) throws ExecutionException { - final IWorkbenchWindow window = - HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent); - - IStructuredSelection selection - = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent); - - // only applies for a singly selected EntityMappings object in a tree - EntityMappings entityMappings = - (EntityMappings) selection.getFirstElement(); - - AddPersistentClassDialog dialog = - new AddPersistentClassDialog(window.getShell(), entityMappings); + public Object execute(ExecutionEvent event) throws ExecutionException { + this.execute_(event); + return null; + } + + private void execute_(ExecutionEvent event) throws ExecutionException { + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); + EntityMappings entityMappings = (EntityMappings) selection.getFirstElement(); + + AddPersistentClassDialog dialog = new AddPersistentClassDialog(window.getShell(), entityMappings); dialog.create(); dialog.setBlockOnOpen(true); - final OrmPersistentType type = dialog.openAndReturnType(); - + OrmPersistentType type = dialog.openAndReturnType(); + if (type != null) { - window.getShell().getDisplay().asyncExec( - new Runnable() { - public void run() { - JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window); - selectionManager.select(new DefaultJpaSelection(type), null); - } - }); + JpaSelectionManager selectionManager = PlatformTools.getAdapter(window, JpaSelectionManager.class); + selectionManager.setSelection(type); } - - return null; } } |