Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8e46c02fa41be6798b0931a7c3192cd9273105b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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);
	}
}

Back to the top