Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1fb02a6ef04a793f2f16225fed08cdd24b45deb0 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
 * Copyright (c) 2007, 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.ui.internal.platform.base;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.ui.internal.wizards.gen.GenerateEntitiesFromSchemaWizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 *  EntitiesGenerator
 */
public class EntitiesGenerator {
	private JpaProject project;
	private IStructuredSelection selection;

	public static void generate(JpaProject project, IStructuredSelection selection) {
		new EntitiesGenerator(project, selection).generate();
	}
	
	private EntitiesGenerator(JpaProject project, IStructuredSelection selection) {
		super();
		if (project == null) {
			throw new NullPointerException();
		}
		this.project = project;
		this.selection = selection;
	}


	// ********** generate **********

	/**
	 * prompt the user with a wizard;
	 * schedule a job to generate the entities;
	 * optionally schedule a job to synchronize persistence.xml to
	 * run afterwards
	 */
	protected void generate() {
		GenerateEntitiesFromSchemaWizard wizard = new GenerateEntitiesFromSchemaWizard(this.project, this.selection);
		WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard);
		dialog.create();
		int returnCode = dialog.open();
		if (returnCode != Window.OK) {
			return;
		}
		//Entities generation happens in the GenerateEntitiesFromSchemaWizard.performFinish()
		//method
	}
	
	private Shell getCurrentShell() {
	    return Display.getCurrent().getActiveShell();
	}


}

Back to the top