Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 322567
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+1 lines)
Lines 28-33 Link Here
28
 org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)"
28
 org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)"
29
Dali-Comment: We friend 'utility' to all non-EclipseLink, non-test bundles
29
Dali-Comment: We friend 'utility' to all non-EclipseLink, non-test bundles
30
Export-Package: org.eclipse.jpt.common.core,
30
Export-Package: org.eclipse.jpt.common.core,
31
 org.eclipse.jpt.common.core.gen,
31
 org.eclipse.jpt.common.core.internal;
32
 org.eclipse.jpt.common.core.internal;
32
  x-friends:="org.eclipse.jpt.jpa.core,
33
  x-friends:="org.eclipse.jpt.jpa.core,
33
   org.eclipse.jpt.jaxb.core",
34
   org.eclipse.jpt.jaxb.core",
(-)src/org/eclipse/jpt/common/core/gen/JptGenerator.java (+22 lines)
Added Link Here
1
/*******************************************************************************
2
* Copyright (c) 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
6
* 
7
* Contributors:
8
*     Oracle - initial API and implementation
9
*******************************************************************************/
10
package org.eclipse.jpt.common.core.gen;
11
12
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
14
15
public interface JptGenerator
16
{
17
	JptGenerator generate(IProgressMonitor monitor);
18
19
	void addLaunchConfigListener(LaunchConfigListener listener);
20
21
	void removeLaunchConfigListener(LaunchConfigListener listener);
22
}
(-)src/org/eclipse/jpt/common/core/gen/LaunchConfigListener.java (+16 lines)
Added Link Here
1
/*******************************************************************************
2
* Copyright (c) 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
6
* 
7
* Contributors:
8
*     Oracle - initial API and implementation
9
*******************************************************************************/
10
package org.eclipse.jpt.common.core.gen;
11
12
public interface LaunchConfigListener
13
{
14
	void launchCompleted(boolean generationSuccessful);
15
16
}
(-)src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java (-14 / +73 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
* Copyright (c) 2008, 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 12-30 Link Here
12
import java.io.File;
12
import java.io.File;
13
import java.io.IOException;
13
import java.io.IOException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Iterator;
15
import java.util.List;
16
import java.util.List;
16
17
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.FileLocator;
20
import org.eclipse.core.runtime.FileLocator;
21
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.NullProgressMonitor;
24
import org.eclipse.core.runtime.OperationCanceledException;
23
import org.eclipse.core.runtime.OperationCanceledException;
25
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Path;
26
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.core.runtime.SubMonitor;
26
import org.eclipse.core.runtime.SubMonitor;
27
import org.eclipse.debug.core.DebugException;
28
import org.eclipse.debug.core.DebugPlugin;
28
import org.eclipse.debug.core.DebugPlugin;
29
import org.eclipse.debug.core.ILaunch;
29
import org.eclipse.debug.core.ILaunch;
30
import org.eclipse.debug.core.ILaunchConfiguration;
30
import org.eclipse.debug.core.ILaunchConfiguration;
Lines 32-48 Link Here
32
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
32
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
33
import org.eclipse.debug.core.ILaunchManager;
33
import org.eclipse.debug.core.ILaunchManager;
34
import org.eclipse.debug.core.ILaunchesListener2;
34
import org.eclipse.debug.core.ILaunchesListener2;
35
import org.eclipse.debug.core.model.IProcess;
35
import org.eclipse.jdt.core.IJavaProject;
36
import org.eclipse.jdt.core.IJavaProject;
36
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
37
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
37
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
38
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
38
import org.eclipse.jdt.launching.IVMInstall;
39
import org.eclipse.jdt.launching.IVMInstall;
39
import org.eclipse.jdt.launching.JavaRuntime;
40
import org.eclipse.jdt.launching.JavaRuntime;
40
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
41
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
42
import org.eclipse.jpt.common.core.gen.JptGenerator;
43
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
41
import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
44
import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
45
import org.eclipse.jpt.common.utility.internal.CollectionTools;
46
import org.eclipse.jpt.common.utility.internal.ListenerList;
42
import org.eclipse.osgi.service.datalocation.Location;
47
import org.eclipse.osgi.service.datalocation.Location;
43
import org.osgi.framework.Bundle;
48
import org.osgi.framework.Bundle;
44
49
45
public abstract class AbstractJptGenerator
50
public abstract class AbstractJptGenerator implements JptGenerator
46
{
51
{
47
	public static final String PLUGINS_DIR = "plugins/";	  //$NON-NLS-1$
52
	public static final String PLUGINS_DIR = "plugins/";	  //$NON-NLS-1$
48
53
Lines 52-57 Link Here
52
	
57
	
53
	protected final IJavaProject javaProject;
58
	protected final IJavaProject javaProject;
54
	protected final String projectLocation;
59
	protected final String projectLocation;
60
	protected final ListenerList<LaunchConfigListener> launchConfigListenerList;
55
61
56
	private boolean isDebug = false;
62
	private boolean isDebug = false;
57
63
Lines 61-66 Link Here
61
		super();
67
		super();
62
		this.javaProject = javaProject;
68
		this.javaProject = javaProject;
63
		this.projectLocation = javaProject.getProject().getLocation().toString();
69
		this.projectLocation = javaProject.getProject().getLocation().toString();
70
		this.launchConfigListenerList = this.buildLaunchConfigListenerList();
64
		this.initialize();
71
		this.initialize();
65
	}
72
	}
66
73
Lines 82-100 Link Here
82
	
89
	
83
	protected void initialize() {
90
	protected void initialize() {
84
		try {
91
		try {
92
			this.launchConfig = this.buildLaunchConfiguration();
85
			this.jre = this.getProjectJRE();
93
			this.jre = this.getProjectJRE();
86
			if (this.jre == null) {
94
			if (this.jre == null) {
87
				String message = "Could not identify the VM."; //$NON-NLS-1$
95
				String message = "Could not identify the VM."; //$NON-NLS-1$
88
				throw new RuntimeException(message);
96
				throw new RuntimeException(message);
89
			}
97
			}
90
			this.launchConfig = this.buildLaunchConfiguration();
91
		} 
98
		} 
92
		catch (CoreException e) {
99
		catch (CoreException e) {
93
			throw new RuntimeException(e);
100
			throw new RuntimeException(e);
94
		}
101
		}
95
	}
102
	}
96
103
97
	protected void generate(IProgressMonitor monitor) {
104
	public JptGenerator generate(IProgressMonitor monitor) {
98
		SubMonitor sm = SubMonitor.convert(monitor, 10);
105
		SubMonitor sm = SubMonitor.convert(monitor, 10);
99
		this.preGenerate(sm.newChild(2));
106
		this.preGenerate(sm.newChild(2));
100
		if (sm.isCanceled()) {
107
		if (sm.isCanceled()) {
Lines 114-121 Link Here
114
			throw new OperationCanceledException();
121
			throw new OperationCanceledException();
115
		}
122
		}
116
		this.launch = this.saveAndLaunchConfig(sm.newChild(6));
123
		this.launch = this.saveAndLaunchConfig(sm.newChild(6));
124
		return this;
117
	}
125
	}
118
	
126
119
	private void initializeLaunchConfiguration() {
127
	private void initializeLaunchConfiguration() {
120
		this.specifyJRE();
128
		this.specifyJRE();
121
		
129
		
Lines 133-154 Link Here
133
		this.getLaunchManager().addLaunchListener(this.buildLaunchListener());
141
		this.getLaunchManager().addLaunchListener(this.buildLaunchListener());
134
	}
142
	}
135
	
143
	
144
	private void removeLaunchListener(ILaunchesListener2 listener) {
145
146
		this.getLaunchManager().removeLaunchListener(listener);
147
	}
148
	
136
	protected abstract void preGenerate(IProgressMonitor monitor);
149
	protected abstract void preGenerate(IProgressMonitor monitor);
137
150
138
	protected void postGenerate() {
151
	protected void postGenerate(boolean generationSuccessful) {
139
		try {
152
		try {
140
			if( ! this.isDebug) {
153
			if( ! this.isDebug) {
141
				this.removeLaunchConfiguration();
154
				this.removeLaunchConfiguration();
142
			}
155
			}
143
			this.refreshProject();
156
			this.notifyLaunchConfigListeners(generationSuccessful);
144
		}
157
		}
145
		catch(CoreException e) {
158
		catch(CoreException e) {
146
			throw new RuntimeException(e);
159
			throw new RuntimeException(e);
147
		}
160
		}
148
	}
161
	}
149
162
150
	protected void refreshProject() throws CoreException {
163
	private void notifyLaunchConfigListeners(boolean generationSuccessful) {
151
			this.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
164
		for(LaunchConfigListener launchConfigListener : this.launchConfigListenerList.getListeners()) {
165
			launchConfigListener.launchCompleted(generationSuccessful);
166
		}	
167
	}
168
	
169
	private void generationSuccessful() {
170
		this.postGenerate(true);
171
	}
172
	
173
	private void generationFailed() {
174
		this.postGenerate(false);
152
	}
175
	}
153
176
154
	private ILaunchesListener2 buildLaunchListener() {
177
	private ILaunchesListener2 buildLaunchListener() {
Lines 159-174 Link Here
159
					ILaunch launch = launches[i];
182
					ILaunch launch = launches[i];
160
					if (launch.equals(AbstractJptGenerator.this.getLaunch())) {
183
					if (launch.equals(AbstractJptGenerator.this.getLaunch())) {
161
						try {
184
						try {
162
							AbstractJptGenerator.this.postGenerate();
185
							if(launch.isTerminated()) {
163
							AbstractJptGenerator.this.launch = null;
186
								if(this.generationIsSuccessful(launch)) {
187
									AbstractJptGenerator.this.generationSuccessful();
188
								}
189
								else {
190
									AbstractJptGenerator.this.generationFailed();
191
								}
192
								AbstractJptGenerator.this.launch = null;
193
							}
164
						}
194
						}
165
						finally {
195
						finally {
166
							AbstractJptGenerator.this.getLaunchManager().removeLaunchListener(this);
196
							AbstractJptGenerator.this.removeLaunchListener(this);
167
						}
197
						}
168
						return;
198
						return;
169
					}
199
					}
170
				}
200
				}
171
			}
201
			}
202
			
203
			private boolean generationIsSuccessful(ILaunch launch) {
204
				Iterator<IProcess> processes = CollectionTools.iterator(launch.getProcesses());
205
				int exitValue = 0xFFFF;
206
				while (processes.hasNext()) {
207
					IProcess process = (IProcess)processes.next();
208
					try {
209
						exitValue = process.getExitValue();
210
						break;
211
					}
212
					catch (DebugException e) {
213
						throw new RuntimeException(e);
214
					}
215
				}
216
				return (exitValue == 0);
217
			}
172
218
173
			public void launchesAdded(ILaunch[] launches) {
219
			public void launchesAdded(ILaunch[] launches) {
174
				// not interested to this event
220
				// not interested to this event
Lines 386-390 Link Here
386
	protected void setDebug(boolean isDebug) {
432
	protected void setDebug(boolean isDebug) {
387
		this.isDebug = isDebug;
433
		this.isDebug = isDebug;
388
	}
434
	}
435
436
	// ********** listener **********
389
	
437
	
438
	private ListenerList<LaunchConfigListener> buildLaunchConfigListenerList() {
439
		return new ListenerList<LaunchConfigListener>(LaunchConfigListener.class);
440
	}
441
442
	public void addLaunchConfigListener(LaunchConfigListener listener) {
443
		this.launchConfigListenerList.add(listener);
444
	}
445
446
	public void removeLaunchConfigListener(LaunchConfigListener listener) {
447
		this.launchConfigListenerList.remove(listener);
448
	}
390
}
449
}
(-)src/org/eclipse/jpt/dbws/eclipselink/core/internal/gen/DbwsGenerator.java (-3 / +4 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.core.IJavaProject;
19
import org.eclipse.jdt.core.IJavaProject;
20
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
21
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
21
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
22
import org.eclipse.jpt.common.core.gen.JptGenerator;
22
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
23
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
23
import org.eclipse.jpt.common.utility.internal.StringTools;
24
import org.eclipse.jpt.common.utility.internal.StringTools;
24
25
Lines 39-45 Link Here
39
40
40
	// ********** static methods **********
41
	// ********** static methods **********
41
	
42
	
42
	public static void generate(
43
	public static JptGenerator generate(
43
			IJavaProject javaProject, 
44
			IJavaProject javaProject, 
44
			String builderFileName, 
45
			String builderFileName, 
45
			String stageDirName, 
46
			String stageDirName, 
Lines 48-54 Link Here
48
		if (javaProject == null) {
49
		if (javaProject == null) {
49
			throw new NullPointerException();
50
			throw new NullPointerException();
50
		}
51
		}
51
		new DbwsGenerator(javaProject, 
52
		return new DbwsGenerator(javaProject, 
52
			builderFileName, 
53
			builderFileName, 
53
			stageDirName, 
54
			stageDirName, 
54
			driverJarList).generate(monitor);
55
			driverJarList).generate(monitor);
Lines 56-62 Link Here
56
57
57
	// ********** constructors **********
58
	// ********** constructors **********
58
59
59
	private DbwsGenerator(
60
	public DbwsGenerator(
60
			IJavaProject javaProject, 
61
			IJavaProject javaProject, 
61
			String builderFileName, 
62
			String builderFileName, 
62
			String stageDirName, 
63
			String stageDirName, 
(-)src/org/eclipse/jpt/dbws/eclipselink/ui/internal/DbwsGeneratorUi.java (-6 / +93 lines)
Lines 14-25 Link Here
14
14
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.WorkspaceJob;
18
import org.eclipse.core.resources.WorkspaceJob;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.runtime.Status;
24
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IJavaProject;
26
import org.eclipse.jdt.core.IJavaProject;
Lines 28-36 Link Here
28
import org.eclipse.jface.dialogs.MessageDialog;
29
import org.eclipse.jface.dialogs.MessageDialog;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.wizard.WizardDialog;
31
import org.eclipse.jface.wizard.WizardDialog;
32
import org.eclipse.jpt.common.core.gen.JptGenerator;
33
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
34
import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
35
import org.eclipse.jpt.common.utility.internal.StringTools;
36
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
31
import org.eclipse.jpt.dbws.eclipselink.core.internal.gen.DbwsGenerator;
37
import org.eclipse.jpt.dbws.eclipselink.core.internal.gen.DbwsGenerator;
38
import org.eclipse.jpt.dbws.eclipselink.ui.JptDbwsUiPlugin;
32
import org.eclipse.jpt.dbws.eclipselink.ui.internal.wizards.gen.DbwsGeneratorWizard;
39
import org.eclipse.jpt.dbws.eclipselink.ui.internal.wizards.gen.DbwsGeneratorWizard;
33
import org.eclipse.jpt.common.utility.internal.StringTools;
34
import org.eclipse.persistence.oxm.XMLContext;
40
import org.eclipse.persistence.oxm.XMLContext;
35
import org.eclipse.persistence.oxm.XMLUnmarshaller;
41
import org.eclipse.persistence.oxm.XMLUnmarshaller;
36
import org.eclipse.persistence.tools.dbws.DBWSBuilderModel;
42
import org.eclipse.persistence.tools.dbws.DBWSBuilderModel;
Lines 251-275 Link Here
251
	// ********** generate DBWS job **********
257
	// ********** generate DBWS job **********
252
258
253
	public static class GenerateDbwsJob extends WorkspaceJob {
259
	public static class GenerateDbwsJob extends WorkspaceJob {
254
		private final IJavaProject project;
260
		private final IJavaProject javaProject;
255
		final String builderFileName;
261
		final String builderFileName;
256
		final String stageDirName;
262
		final String stageDirName;
257
		final String driverJarList;
263
		final String driverJarList;
264
		private final SynchronizedBoolean generationCompleted;
265
		private boolean generationSuccessful;
258
266
259
		public GenerateDbwsJob(IJavaProject project, String builderFileName, String stageDirName, String driverJarList) {
267
		public GenerateDbwsJob(IJavaProject javaProject, String builderFileName, String stageDirName, String driverJarList) {
260
			super(JptDbwsUiMessages.DbwsGeneratorWizard_generatingDbws);
268
			super(JptDbwsUiMessages.DbwsGeneratorWizard_generatingDbws);
261
269
262
			this.project = project ;
270
			this.javaProject = javaProject ;
263
			this.builderFileName = builderFileName;
271
			this.builderFileName = builderFileName;
264
			this.stageDirName = stageDirName;
272
			this.stageDirName = stageDirName;
265
			this.driverJarList = driverJarList;
273
			this.driverJarList = driverJarList;
274
			this.generationCompleted = new SynchronizedBoolean(false);
275
			this.generationSuccessful = false;
266
		}
276
		}
267
277
268
		@Override
278
		@Override
269
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
279
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
270
			DbwsGenerator.generate(this.project, this.builderFileName, this.stageDirName, this.driverJarList, monitor);
280
			this.dbwsGeneratorGenerate(monitor);
271
			return Status.OK_STATUS;
281
			return Status.OK_STATUS;
272
		}
282
		}
283
284
		private void dbwsGeneratorGenerate(IProgressMonitor monitor) {
285
			JptGenerator dbwsGenerator = new DbwsGenerator(this.javaProject, this.builderFileName, this.stageDirName, this.driverJarList);
286
			LaunchConfigListener launchListener = this.buildLaunchListener();
287
			dbwsGenerator.addLaunchConfigListener(launchListener);
288
			dbwsGenerator.generate(monitor);
289
			try {
290
				this.generationCompleted.waitUntilTrue();
291
			}
292
			catch (InterruptedException e) {	
293
				this.logException(e);
294
			}
295
			finally {
296
				dbwsGenerator.removeLaunchConfigListener(launchListener);
297
			}
298
			
299
			this.postGenerate(this.generationSuccessful);
300
		}
301
		
302
		protected void postGenerate(boolean generationSuccessful) {
303
			if( ! generationSuccessful) {
304
				this.displayError("Generation Failed");	//TODO
305
				return;
306
			}
307
			else {
308
				this.refreshProject();
309
			}
310
		}
311
312
		private void refreshProject() {
313
			try {
314
				this.javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
315
			}
316
			catch (CoreException e) {	
317
				this.logException(e);
318
			}
319
		}
320
		
321
		private LaunchConfigListener buildLaunchListener() {
322
			return new LaunchConfigListener() {
323
				
324
				public void launchCompleted(boolean generationSuccessful) {
325
					GenerateDbwsJob.this.generationSuccessful = generationSuccessful;
326
					GenerateDbwsJob.this.generationCompleted.setTrue();
327
				}
328
			};
329
		}
330
331
		protected void logException(Exception exception) {
332
			String msg = exception.getMessage();
333
			String message = (msg == null) ? exception.toString() : msg;
334
			this.displayError(message);
335
			JptDbwsUiPlugin.log(exception);
336
		}
337
		
338
		private void displayError(final String message) {
339
			SWTUtil.syncExec(new Runnable() {
340
				public void run() {
341
					MessageDialog.openError(
342
						getShell(),
343
						"Error",	//TODO
344
						message
345
					);
346
				}
347
			});
348
		}
349
350
		protected Shell getShell() {
351
			Display display = Display.getCurrent();
352
			Shell shell = (display == null) ? null : display.getActiveShell();
353
			if (shell == null && display != null) {
354
				Shell[] shells = display.getShells();
355
				if (shells.length > 0)
356
					shell = shells[0];
357
			}
358
			return shell;
359
		}
273
		
360
		
274
	}
361
	}
275
}
362
}
(-)src/org/eclipse/jpt/dbws/eclipselink/ui/internal/wizards/gen/DbwsGeneratorWizard.java (-3 / +2 lines)
Lines 13-19 Link Here
13
import org.eclipse.core.resources.IProject;
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.WorkspaceJob;
15
import org.eclipse.core.resources.WorkspaceJob;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.core.IJavaProject;
Lines 127-133 Link Here
127
		this.jdbcDriversPage.finish();	// persist settings
126
		this.jdbcDriversPage.finish();	// persist settings
128
127
129
		if(DbwsGeneratorUi.displayOverridingWebContentWarning(this.getShell())) {
128
		if(DbwsGeneratorUi.displayOverridingWebContentWarning(this.getShell())) {
130
			this.generateDbws(driverJarList);
129
			this.scheduleGenerateDbwsJob(driverJarList);
131
		}
130
		}
132
		return true;
131
		return true;
133
	}
132
	}
Lines 179-185 Link Here
179
		return relativePath.toOSString();
178
		return relativePath.toOSString();
180
	}
179
	}
181
	
180
	
182
	private void generateDbws(String driverJarList) {
181
	private void scheduleGenerateDbwsJob(String driverJarList) {
183
182
184
		String stageDirName = this.getJavaProject().getProject().getLocation().toOSString();
183
		String stageDirName = this.getJavaProject().getProject().getLocation().toOSString();
185
184
(-)src/org/eclipse/jpt/jaxb/core/internal/gen/ClassesGenerator.java (-4 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2010, 2011 Oracle. All rights reserved.
2
* Copyright (c) 2010, 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 12-17 Link Here
12
import java.io.File;
12
import java.io.File;
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.List;
14
import java.util.List;
15
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.Path;
18
import org.eclipse.core.runtime.Path;
Lines 25-30 Link Here
25
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
26
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
26
import org.eclipse.jdt.launching.IVMInstall;
27
import org.eclipse.jdt.launching.IVMInstall;
27
import org.eclipse.jdt.launching.JavaRuntime;
28
import org.eclipse.jdt.launching.JavaRuntime;
29
import org.eclipse.jpt.common.core.gen.JptGenerator;
28
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
30
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
29
import org.eclipse.jpt.common.utility.internal.StringTools;
31
import org.eclipse.jpt.common.utility.internal.StringTools;
30
32
Lines 50-56 Link Here
50
52
51
	// ********** static methods **********
53
	// ********** static methods **********
52
	
54
	
53
	public static void generate(
55
	public static JptGenerator generate(
54
			IJavaProject javaProject, 
56
			IJavaProject javaProject, 
55
			String schemaPathOrUri, 
57
			String schemaPathOrUri, 
56
			String outputDir, 
58
			String outputDir, 
Lines 65-71 Link Here
65
		if (javaProject == null) {
67
		if (javaProject == null) {
66
			throw new NullPointerException();
68
			throw new NullPointerException();
67
		}
69
		}
68
		new ClassesGenerator(javaProject, 
70
		return new ClassesGenerator(javaProject, 
69
			schemaPathOrUri, 
71
			schemaPathOrUri, 
70
			outputDir, 
72
			outputDir, 
71
			targetPackage, 
73
			targetPackage, 
Lines 136-142 Link Here
136
138
137
	// ********** constructors **********
139
	// ********** constructors **********
138
	
140
	
139
	protected ClassesGenerator(
141
	public ClassesGenerator(
140
			IJavaProject javaProject, 
142
			IJavaProject javaProject, 
141
			String schemaPathOrUri, 
143
			String schemaPathOrUri, 
142
			String outputDir, 
144
			String outputDir, 
(-)src/org/eclipse/jpt/jaxb/core/internal/gen/GenerateJaxbClassesJob.java (-33 / +70 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2010 Oracle. All rights reserved.
2
* Copyright (c) 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-24 Link Here
9
*******************************************************************************/
9
*******************************************************************************/
10
package org.eclipse.jpt.jaxb.core.internal.gen;
10
package org.eclipse.jpt.jaxb.core.internal.gen;
11
11
12
import org.eclipse.core.resources.IResource;
12
import org.eclipse.core.resources.ResourcesPlugin;
13
import org.eclipse.core.resources.ResourcesPlugin;
13
import org.eclipse.core.resources.WorkspaceJob;
14
import org.eclipse.core.resources.WorkspaceJob;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.NullProgressMonitor;
17
import org.eclipse.core.runtime.OperationCanceledException;
19
import org.eclipse.core.runtime.OperationCanceledException;
18
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.SubMonitor;
21
import org.eclipse.core.runtime.SubMonitor;
20
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jpt.common.core.gen.JptGenerator;
24
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
21
import org.eclipse.jpt.common.utility.internal.StringTools;
25
import org.eclipse.jpt.common.utility.internal.StringTools;
26
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
27
import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
22
import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages;
28
import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages;
23
29
24
/**
30
/**
Lines 34-39 Link Here
34
	private final String[] bindingsFileNames;
40
	private final String[] bindingsFileNames;
35
	private final ClassesGeneratorOptions generatorOptions;
41
	private final ClassesGeneratorOptions generatorOptions;
36
	private final ClassesGeneratorExtensionOptions generatorExtensionOptions;
42
	private final ClassesGeneratorExtensionOptions generatorExtensionOptions;
43
	private final SynchronizedBoolean generationCompleted;
44
	private boolean generationSuccessful;
37
45
38
	// ********** constructors **********
46
	// ********** constructors **********
39
	
47
	
Lines 68-121 Link Here
68
		this.generatorOptions = generatorOptions;
76
		this.generatorOptions = generatorOptions;
69
		this.generatorExtensionOptions = generatorExtensionOptions;
77
		this.generatorExtensionOptions = generatorExtensionOptions;
70
		this.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(this.javaProject.getProject()));
78
		this.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(this.javaProject.getProject()));
79
		this.generationCompleted = new SynchronizedBoolean(false);
80
		this.generationSuccessful = false;
71
	}
81
	}
72
82
73
	@Override
83
	@Override
74
	public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
84
	public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
75
		SubMonitor sm = SubMonitor.convert(monitor, JptJaxbCoreMessages.ClassesGenerator_generatingClassesTask, 1);
85
		SubMonitor sm = SubMonitor.convert(monitor, JptJaxbCoreMessages.ClassesGenerator_generatingClassesTask, 1);
76
		try {
86
		try {
77
			this.classesGeneratorGenerate(this.javaProject, 
87
			this.classesGeneratorGenerate(sm.newChild(1));
78
				this.absoluteLocalXsdUri, 
79
				this.outputDir, 
80
				this.targetPackage, 
81
				this.catalog, 
82
				this.usesMoxyGenerator,
83
				this.bindingsFileNames,
84
				this.generatorOptions,
85
				this.generatorExtensionOptions, 
86
				sm.newChild(1));
87
		} 
88
		} 
88
		catch (OperationCanceledException e) {
89
		catch (OperationCanceledException e) {
89
			return Status.CANCEL_STATUS;
90
			return Status.CANCEL_STATUS;
90
			// fall through and tell monitor we are done
91
			// fall through and tell monitor we are done
91
		}
92
		}
92
		catch (RuntimeException re) {
93
		catch (RuntimeException re) {
93
			throw new RuntimeException(re);
94
			this.logException(re);
94
		}
95
		}
95
		return Status.OK_STATUS;
96
		return Status.OK_STATUS;
96
}
97
}
97
98
98
	private void classesGeneratorGenerate(IJavaProject javaProject, 
99
	private void classesGeneratorGenerate(IProgressMonitor monitor) {
99
		String absoluteLocalXsdUri, 
100
100
		String outputDir, 
101
		JptGenerator classesGenerator = new ClassesGenerator(this.javaProject, 
101
		String targetPackage, 
102
			this.absoluteLocalXsdUri, 
102
		String catalog, 
103
			this.outputDir, 
103
		boolean usesMoxyGenerator,
104
			this.targetPackage, 
104
		String[] bindingsFileNames, 
105
			this.catalog, 
105
		ClassesGeneratorOptions generatorOptions,
106
			this.usesMoxyGenerator,
106
		ClassesGeneratorExtensionOptions generatorExtensionOptions,
107
			this.bindingsFileNames,
107
		IProgressMonitor monitor) {
108
			this.generatorOptions,
109
			this.generatorExtensionOptions);
110
		
111
		LaunchConfigListener launchListener = this.buildLaunchListener();
112
		classesGenerator.addLaunchConfigListener(launchListener);
113
		classesGenerator.generate(monitor);
114
		try {
115
			this.generationCompleted.waitUntilTrue();
116
		}
117
		catch (InterruptedException e) {
118
			this.logException(e);
119
		}
120
		finally {
121
			classesGenerator.removeLaunchConfigListener(launchListener);
122
		}
123
		this.postGenerate(this.generationSuccessful);
124
	}
108
125
109
		ClassesGenerator.generate(javaProject, 
126
	
110
			absoluteLocalXsdUri, 
127
	protected void postGenerate(boolean generationSuccessful) {
111
			outputDir, 
128
		if( ! generationSuccessful) {
112
			targetPackage, 
129
			JptJaxbCorePlugin.log("ClassesGenerator: Generation Failed"); //TODO
113
			catalog, 
130
			return;
114
			usesMoxyGenerator, 
131
		}
115
			bindingsFileNames, 
132
		else {
116
			generatorOptions, 
133
			this.refreshProject();
117
			generatorExtensionOptions,
134
		}
118
			monitor);
135
	}
119
		return;
136
137
	private void refreshProject() {
138
		try {
139
			this.javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
140
		}
141
		catch (CoreException e) {	
142
			this.logException(e);
143
		}
144
	}
145
	
146
	private LaunchConfigListener buildLaunchListener() {
147
		return new LaunchConfigListener() {
148
			
149
			public void launchCompleted(boolean generationSuccessful) {
150
				GenerateJaxbClassesJob.this.generationSuccessful = generationSuccessful;
151
				GenerateJaxbClassesJob.this.generationCompleted.setTrue();
152
			}
153
		};
154
	}
155
	protected void logException(Exception exception) {
156
		JptJaxbCorePlugin.log(exception);
120
	}
157
	}
121
}
158
}
(-)src/org/eclipse/jpt/jaxb/core/internal/gen/SchemaGenerator.java (-3 / +5 lines)
Lines 18-23 Link Here
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Iterator;
19
import java.util.Iterator;
20
import java.util.List;
20
import java.util.List;
21
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IFolder;
23
import org.eclipse.core.resources.IFolder;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IResource;
Lines 30-35 Link Here
30
import org.eclipse.jdt.core.IPackageFragmentRoot;
31
import org.eclipse.jdt.core.IPackageFragmentRoot;
31
import org.eclipse.jdt.core.JavaModelException;
32
import org.eclipse.jdt.core.JavaModelException;
32
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
33
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
34
import org.eclipse.jpt.common.core.gen.JptGenerator;
33
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
35
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
34
import org.eclipse.jpt.common.core.internal.utility.JDTTools;
36
import org.eclipse.jpt.common.core.internal.utility.JDTTools;
35
import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages;
37
import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages;
Lines 62-68 Link Here
62
64
63
	// ********** static methods **********
65
	// ********** static methods **********
64
	
66
	
65
	public static void generate(
67
	public static JptGenerator generate(
66
			IJavaProject javaProject, 
68
			IJavaProject javaProject, 
67
			String targetSchemaName, 
69
			String targetSchemaName, 
68
			String[] sourceClassNames,
70
			String[] sourceClassNames,
Lines 71-77 Link Here
71
		if (javaProject == null) {
73
		if (javaProject == null) {
72
			throw new NullPointerException();
74
			throw new NullPointerException();
73
		}
75
		}
74
		new SchemaGenerator(javaProject, 
76
		return new SchemaGenerator(javaProject, 
75
			targetSchemaName, 
77
			targetSchemaName, 
76
			sourceClassNames,
78
			sourceClassNames,
77
			useMoxy).generate(monitor);
79
			useMoxy).generate(monitor);
Lines 79-85 Link Here
79
81
80
	// ********** constructors **********
82
	// ********** constructors **********
81
	
83
	
82
	protected SchemaGenerator(
84
	public SchemaGenerator(
83
			IJavaProject javaProject, 
85
			IJavaProject javaProject, 
84
			String targetSchemaName, 
86
			String targetSchemaName, 
85
			String[] sourceClassNames,
87
			String[] sourceClassNames,
(-)src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java (-7 / +7 lines)
Lines 11-23 Link Here
11
11
12
import java.util.List;
12
import java.util.List;
13
import java.util.Vector;
13
import java.util.Vector;
14
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.WorkspaceJob;
19
import org.eclipse.core.resources.WorkspaceJob;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.emf.common.util.URI;
21
import org.eclipse.emf.common.util.URI;
22
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IJavaProject;
Lines 160-168 Link Here
160
		}
160
		}
161
161
162
		if (this.performsGeneration) {
162
		if (this.performsGeneration) {
163
			if (displayOverwritingClassesWarning(this.generatorOptions)) {
163
			if (this.displayOverwritingClassesWarning(this.generatorOptions)) {
164
				generateJaxbClasses();
164
				this.scheduleGenerateJaxbClassesJob();
165
				addSchemaToLibrary();
165
				this.addSchemaToLibrary();
166
			}
166
			}
167
		}
167
		}
168
168
Lines 348-356 Link Here
348
		}
348
		}
349
	}
349
	}
350
	
350
	
351
	private void generateJaxbClasses() {
351
	private void scheduleGenerateJaxbClassesJob() {
352
		try {
352
		try {
353
			WorkspaceJob job = 
353
			WorkspaceJob generateJaxbClassesJob = 
354
					new GenerateJaxbClassesJob(
354
					new GenerateJaxbClassesJob(
355
						this.getJavaProject(),
355
						this.getJavaProject(),
356
						this.getLocalSchemaUri().toString(),
356
						this.getLocalSchemaUri().toString(),
Lines 361-367 Link Here
361
						this.bindingsFileNames,
361
						this.bindingsFileNames,
362
						this.generatorOptions,
362
						this.generatorOptions,
363
						this.generatorExtensionOptions);
363
						this.generatorExtensionOptions);
364
			job.schedule();
364
			generateJaxbClassesJob.schedule();
365
		}
365
		}
366
		catch(RuntimeException re) {
366
		catch(RuntimeException re) {
367
			JptJaxbUiPlugin.log(re);
367
			JptJaxbUiPlugin.log(re);
(-)src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java (-43 / +111 lines)
Lines 10-22 Link Here
10
package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen;
10
package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen;
11
11
12
import java.io.File;
12
import java.io.File;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.List;
14
import java.util.List;
16
15
17
import org.eclipse.core.resources.IContainer;
16
import org.eclipse.core.resources.IContainer;
18
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IResourceRuleFactory;
20
import org.eclipse.core.resources.IResourceRuleFactory;
21
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.resources.WorkspaceJob;
22
import org.eclipse.core.resources.WorkspaceJob;
Lines 25-30 Link Here
25
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.NullProgressMonitor;
28
import org.eclipse.core.runtime.OperationCanceledException;
29
import org.eclipse.core.runtime.OperationCanceledException;
29
import org.eclipse.core.runtime.Path;
30
import org.eclipse.core.runtime.Path;
30
import org.eclipse.core.runtime.Status;
31
import org.eclipse.core.runtime.Status;
Lines 33-51 Link Here
33
import org.eclipse.jdt.core.IJavaProject;
34
import org.eclipse.jdt.core.IJavaProject;
34
import org.eclipse.jdt.core.IPackageFragment;
35
import org.eclipse.jdt.core.IPackageFragment;
35
import org.eclipse.jdt.core.JavaCore;
36
import org.eclipse.jdt.core.JavaCore;
37
import org.eclipse.jface.dialogs.MessageDialog;
36
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.viewers.StructuredSelection;
39
import org.eclipse.jface.viewers.StructuredSelection;
38
import org.eclipse.jface.wizard.Wizard;
40
import org.eclipse.jface.wizard.Wizard;
41
import org.eclipse.jpt.common.core.gen.JptGenerator;
42
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
39
import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
43
import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
40
import org.eclipse.jpt.common.utility.internal.ArrayTools;
44
import org.eclipse.jpt.common.utility.internal.ArrayTools;
41
import org.eclipse.jpt.common.utility.internal.FileTools;
45
import org.eclipse.jpt.common.utility.internal.FileTools;
42
import org.eclipse.jpt.common.utility.internal.StringTools;
46
import org.eclipse.jpt.common.utility.internal.StringTools;
47
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
43
import org.eclipse.jpt.jaxb.core.internal.gen.SchemaGenerator;
48
import org.eclipse.jpt.jaxb.core.internal.gen.SchemaGenerator;
44
import org.eclipse.jpt.jaxb.core.internal.operations.SchemaFileCreationDataModelProvider;
49
import org.eclipse.jpt.jaxb.core.internal.operations.SchemaFileCreationDataModelProvider;
45
import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
50
import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
46
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
51
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
47
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
52
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
48
import org.eclipse.osgi.util.NLS;
53
import org.eclipse.osgi.util.NLS;
54
import org.eclipse.swt.widgets.Display;
55
import org.eclipse.swt.widgets.Shell;
49
import org.eclipse.ui.INewWizard;
56
import org.eclipse.ui.INewWizard;
50
import org.eclipse.ui.IWorkbench;
57
import org.eclipse.ui.IWorkbench;
51
import org.eclipse.ui.IWorkbenchPage;
58
import org.eclipse.ui.IWorkbenchPage;
Lines 115-138 Link Here
115
	}
122
	}
116
123
117
	protected void scheduleGenerateSchemaJob(String[] sourceClassNames) {
124
	protected void scheduleGenerateSchemaJob(String[] sourceClassNames) {
118
			
125
126
		IPath schemaPath = this.newSchemaFileWizardPage.getContainerFullPath(); 
127
		String schemaName = this.newSchemaFileWizardPage.getFileName();
128
119
		WorkspaceJob genSchemaJob = new GenerateSchemaJob( 
129
		WorkspaceJob genSchemaJob = new GenerateSchemaJob( 
120
									this.targetProject, 
130
									this.targetProject, 
121
									sourceClassNames, 
131
									sourceClassNames, 
122
									this.getTargetSchema(), 
132
									this.getTargetSchema(), 
123
									this.usesMoxy());
133
									this.usesMoxy(),
134
									schemaPath,
135
									schemaName);
124
		genSchemaJob.schedule();
136
		genSchemaJob.schedule();
125
		
137
		
126
		IPath schemaPath = this.newSchemaFileWizardPage.getContainerFullPath(); 
127
		String schemaName = this.newSchemaFileWizardPage.getFileName();
128
		
129
		IContainer container = (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(schemaPath);
130
		IFile schemaFile = container.getFile(new Path(schemaName)); 
131
132
		OpenSchemaFileJob openSchemaFileJob = new OpenSchemaFileJob(
133
									this.targetProject, 
134
									schemaFile);
135
		openSchemaFileJob.schedule();
136
	}
138
	}
137
139
138
	// ********** intra-wizard methods **********
140
	// ********** intra-wizard methods **********
Lines 264-326 Link Here
264
		private final String[] sourceClassNames;
266
		private final String[] sourceClassNames;
265
		private final String targetSchema;
267
		private final String targetSchema;
266
		private final boolean useMoxy;
268
		private final boolean useMoxy;
269
		private final IPath schemaPath;
270
		private final String schemaName;
271
		private final SynchronizedBoolean generationCompleted;
272
		private boolean generationSuccessful;
267
		
273
		
268
		GenerateSchemaJob(IJavaProject project, String[] sourceClassNames, String targetSchema, boolean useMoxy) {
274
		GenerateSchemaJob(IJavaProject project, String[] sourceClassNames, String targetSchema, 
275
										boolean useMoxy, IPath schemaPath, String schemaName) {
276
			
269
			super(JptJaxbUiMessages.SchemaGeneratorWizard_generatingSchema);
277
			super(JptJaxbUiMessages.SchemaGeneratorWizard_generatingSchema);
270
			
278
			
271
			this.javaProject = project ;
279
			this.javaProject = project ;
272
			this.sourceClassNames = sourceClassNames;
280
			this.sourceClassNames = sourceClassNames;
273
			this.targetSchema = targetSchema;
281
			this.targetSchema = targetSchema;
274
			this.useMoxy = useMoxy;
282
			this.useMoxy = useMoxy;
283
			this.schemaPath = schemaPath;
284
			this.schemaName = schemaName;
285
			this.generationCompleted = new SynchronizedBoolean(false);
286
			this.generationSuccessful = false;
275
287
276
			this.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(this.javaProject.getProject()));
288
			IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
289
			this.setRule(ruleFactory.modifyRule(this.javaProject.getProject()));
277
		}
290
		}
278
291
279
		@Override
292
		@Override
280
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
293
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
281
			SubMonitor sm = SubMonitor.convert(monitor, NLS.bind(JptJaxbUiMessages.SchemaGeneratorWizard_generateSchemaTask, this.targetSchema), 1);
294
			SubMonitor sm = SubMonitor.convert(monitor, NLS.bind(JptJaxbUiMessages.SchemaGeneratorWizard_generateSchemaTask, this.targetSchema), 1);
282
			try {
295
			try {
283
				SchemaGenerator.generate(this.javaProject, this.targetSchema, this.sourceClassNames, this.useMoxy, sm.newChild(1));
296
				this.schemaGeneratorGenerate(sm.newChild(1));
284
			}
297
			} 
285
			catch (OperationCanceledException e) {
298
			catch (OperationCanceledException e) {
286
				return Status.CANCEL_STATUS;
299
				return Status.CANCEL_STATUS;
287
			}
300
			}
301
			catch (RuntimeException re) {
302
				this.logException(re);
303
			}
288
			return Status.OK_STATUS;
304
			return Status.OK_STATUS;
289
		}
305
		}
290
	}
291
	
292
	// ********** open schema file job **********
293
306
294
	public static class OpenSchemaFileJob extends WorkspaceJob {
307
		private void schemaGeneratorGenerate(IProgressMonitor monitor) {
295
		private final IJavaProject javaProject;
308
			JptGenerator schemaGenerator = new SchemaGenerator(this.javaProject, this.targetSchema, this.sourceClassNames, this.useMoxy);
296
		private final IFile schemaFile;
297
298
		public OpenSchemaFileJob(IJavaProject javaProject, IFile schemaFile) {
299
			super(JptJaxbUiMessages.SchemaGeneratorWizard_openSchemaFileJobName);
300
			this.javaProject = javaProject;
301
			this.schemaFile = schemaFile;
302
			IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
303
			this.setRule(ruleFactory.modifyRule(this.javaProject.getProject()));
304
		}
305
309
306
		@Override
310
			LaunchConfigListener launchListener = this.buildLaunchListener();
307
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
311
			schemaGenerator.addLaunchConfigListener(launchListener);
312
			schemaGenerator.generate(monitor);
308
			try {
313
			try {
309
				this.postGeneration(this.schemaFile);
314
				this.generationCompleted.waitUntilTrue();
310
			} 
311
			catch (InvocationTargetException e) {
312
				throw new CoreException(new Status(IStatus.ERROR, JptJaxbUiPlugin.PLUGIN_ID, "error", e));	   //$NON-NLS-1$
313
			}
315
			}
314
			return Status.OK_STATUS;
316
			catch (InterruptedException e) {	
317
				this.logException(e);
318
			}
319
			finally {
320
				schemaGenerator.removeLaunchConfigListener(launchListener);
321
			}
322
			
323
			this.postGenerate(this.generationSuccessful);
315
		}
324
		}
316
		
325
		
317
		private void postGeneration(IFile schemaFile) throws InvocationTargetException {
326
		protected void postGenerate(boolean generationSuccessful) {
327
			if( ! generationSuccessful) {
328
				this.displayError("Generation Failed");	//TODO
329
				return;
330
			}
331
			else {
332
				this.refreshProject();
333
				this.openGeneratedSchemaFile();
334
			}
335
		}
336
337
		private void refreshProject() {
318
			try {
338
			try {
319
				this.openEditor(schemaFile);
339
				this.javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
320
			}
340
			}
321
			catch (Exception cantOpen) {
341
			catch (CoreException e) {	
322
				throw new InvocationTargetException(cantOpen);
342
				this.logException(e);
323
			} 
343
			}
344
		}
345
		
346
		private LaunchConfigListener buildLaunchListener() {
347
			return new LaunchConfigListener() {
348
				
349
				public void launchCompleted(boolean generationSuccessful) {
350
					GenerateSchemaJob.this.generationSuccessful = generationSuccessful;
351
					GenerateSchemaJob.this.generationCompleted.setTrue();
352
				}
353
			};
354
		}
355
356
		private void openGeneratedSchemaFile() {
357
358
			IContainer container = (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(this.schemaPath);
359
			IFile schemaFile = container.getFile(new Path(this.schemaName)); 
360
361
			this.openEditor(schemaFile);
324
		}
362
		}
325
		
363
		
326
		private void openEditor(final IFile file) {
364
		private void openEditor(final IFile file) {
Lines 338-342 Link Here
338
				});
376
				});
339
			}
377
			}
340
		}
378
		}
379
380
		protected void logException(Exception exception) {
381
			String msg = exception.getMessage();
382
			String message = (msg == null) ? exception.toString() : msg;
383
			this.displayError(message);
384
			JptJaxbUiPlugin.log(exception);
385
		}
386
		
387
		private void displayError(final String message) {
388
			SWTUtil.syncExec(new Runnable() {
389
				public void run() {
390
					MessageDialog.openError(
391
						getShell(),
392
						"Error",	//TODO
393
						message
394
					);
395
				}
396
			});
397
		}
398
399
		protected Shell getShell() {
400
			Display display = Display.getCurrent();
401
			Shell shell = (display == null) ? null : display.getActiveShell();
402
			if (shell == null && display != null) {
403
				Shell[] shells = display.getShells();
404
				if (shells.length > 0)
405
					shell = shells[0];
406
			}
407
			return shell;
408
		}
341
	}
409
	}
342
}
410
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/builder/EclipseLinkStaticWeavingBuilder.java (-13 / +62 lines)
Lines 12-21 Link Here
12
import java.util.Map;
12
import java.util.Map;
13
13
14
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IncrementalProjectBuilder;
16
import org.eclipse.core.resources.IncrementalProjectBuilder;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.core.JavaCore;
21
import org.eclipse.jdt.core.JavaCore;
22
import org.eclipse.jpt.common.core.gen.JptGenerator;
23
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
24
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
19
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
25
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
20
import org.eclipse.jpt.jpa.eclipselink.core.internal.weave.StaticWeave;
26
import org.eclipse.jpt.jpa.eclipselink.core.internal.weave.StaticWeave;
21
27
Lines 24-29 Link Here
24
    public static final String BUILDER_ID = JptJpaEclipseLinkCorePlugin.PLUGIN_ID + ".builder"; //$NON-NLS-1$
30
    public static final String BUILDER_ID = JptJpaEclipseLinkCorePlugin.PLUGIN_ID + ".builder"; //$NON-NLS-1$
25
31
26
	private EclipseLinkStaticWeavingBuilderConfigurator configurator;
32
	private EclipseLinkStaticWeavingBuilderConfigurator configurator;
33
34
	private final SynchronizedBoolean generationCompleted = new SynchronizedBoolean(false);
35
	private boolean generationSuccessful;
27
	
36
	
28
	// ********** overrides **********
37
	// ********** overrides **********
29
	
38
	
Lines 33-58 Link Here
33
	@Override
42
	@Override
34
	protected IProject[] build(int kind, Map<String, String> parameters, IProgressMonitor monitor) throws CoreException
43
	protected IProject[] build(int kind, Map<String, String> parameters, IProgressMonitor monitor) throws CoreException
35
	{
44
	{
36
		StaticWeave.weave(
45
		this.staticWeaveGeneratorGenerate(monitor);
37
			JavaCore.create(this.getProject()), 
38
			this.configurator.getSourceLocationPreference(),
39
			this.configurator.getTargetLocationPreference(),
40
			this.configurator.getLogLevelPreference(),
41
			this.configurator.getPersistenceInfoPreference(),
42
			monitor);
43
46
44
		return new IProject[0];
47
		return new IProject[0];
45
	}
48
	}
46
49
50
	private void staticWeaveGeneratorGenerate(IProgressMonitor monitor) throws CoreException {
51
		this.generationSuccessful = false;
52
		
53
		JptGenerator staticWeaveGenerator = new StaticWeave(
54
								this.getJavaProject(),
55
								this.configurator.getSourceLocationPreference(),
56
								this.configurator.getTargetLocationPreference(),
57
								this.configurator.getLogLevelPreference(),
58
								this.configurator.getPersistenceInfoPreference());
59
60
		LaunchConfigListener launchListener = this.buildLaunchListener();
61
		staticWeaveGenerator.addLaunchConfigListener(launchListener);
62
		staticWeaveGenerator.generate(monitor);
63
		try {
64
			this.generationCompleted.waitUntilTrue();
65
		}
66
		catch (InterruptedException e) {
67
			throw new RuntimeException(e);
68
		}
69
		finally {
70
			staticWeaveGenerator.removeLaunchConfigListener(launchListener);
71
		}
72
		this.postGenerate(this.generationSuccessful);
73
	}
74
	
75
	protected void postGenerate(boolean generationSuccessful) throws CoreException {
76
		if( ! generationSuccessful) {
77
			throw new RuntimeException("Weaving Failed"); //TODO
78
		}
79
		else {
80
			this.refreshProject();
81
		}
82
	}
83
84
	private void refreshProject() throws CoreException {
85
		this.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
86
	}
87
	
88
	private LaunchConfigListener buildLaunchListener() {
89
		return new LaunchConfigListener() {
90
			
91
			public void launchCompleted(boolean generationSuccessful) {
92
				EclipseLinkStaticWeavingBuilder.this.generationSuccessful = generationSuccessful;
93
				EclipseLinkStaticWeavingBuilder.this.generationCompleted.setTrue();
94
			}
95
		};
96
	}
97
98
	private IJavaProject getJavaProject() {
99
		return JavaCore.create(this.getProject());
100
	}
101
47
	@Override
102
	@Override
48
	protected void startupOnInitialize() {
103
	protected void startupOnInitialize() {
49
		super.startupOnInitialize();
104
		super.startupOnInitialize();
50
		this.configurator = new EclipseLinkStaticWeavingBuilderConfigurator(this.getProject());
105
		this.configurator = new EclipseLinkStaticWeavingBuilderConfigurator(this.getProject());
51
	}
106
	}
52
	
53
	@Override
54
	protected void clean(IProgressMonitor monitor) throws CoreException {
55
		super.clean(monitor);
56
		
57
	}
58
}
107
}
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/AbstractEclipseLinkDDLGenerator.java (-37 / +3 lines)
Lines 20-36 Link Here
20
import java.util.List;
20
import java.util.List;
21
import java.util.Properties;
21
import java.util.Properties;
22
22
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.FileLocator;
24
import org.eclipse.core.runtime.FileLocator;
26
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.Path;
27
import org.eclipse.core.runtime.Path;
30
import org.eclipse.core.runtime.Platform;
28
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Status;
32
import org.eclipse.core.runtime.SubMonitor;
29
import org.eclipse.core.runtime.SubMonitor;
33
import org.eclipse.core.runtime.jobs.Job;
34
import org.eclipse.jdt.core.JavaCore;
30
import org.eclipse.jdt.core.JavaCore;
35
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
31
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
36
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
32
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
Lines 38-44 Link Here
38
import org.eclipse.jpt.jpa.core.JpaPlatform;
34
import org.eclipse.jpt.jpa.core.JpaPlatform;
39
import org.eclipse.jpt.jpa.core.JpaProject;
35
import org.eclipse.jpt.jpa.core.JpaProject;
40
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXmlEnumValue;
36
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXmlEnumValue;
41
import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
42
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
37
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
43
import org.eclipse.jpt.jpa.db.ConnectionProfile;
38
import org.eclipse.jpt.jpa.db.ConnectionProfile;
44
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
39
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
Lines 50-56 Link Here
50
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.OutputMode;
45
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.OutputMode;
51
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.SchemaGeneration;
46
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.SchemaGeneration;
52
import org.eclipse.osgi.util.ManifestElement;
47
import org.eclipse.osgi.util.ManifestElement;
53
import org.eclipse.wst.validation.ValidationFramework;
54
import org.osgi.framework.Bundle;
48
import org.osgi.framework.Bundle;
55
import org.osgi.framework.BundleException;
49
import org.osgi.framework.BundleException;
56
50
Lines 112-121 Link Here
112
	}
106
	}
113
	
107
	
114
	@Override
108
	@Override
115
	protected void postGenerate() {
109
	protected void postGenerate(boolean generationSuccessful) {
116
		super.postGenerate();
110
		super.postGenerate(generationSuccessful);
111
		
117
		this.reconnect();
112
		this.reconnect();
118
		this.validateProject();
119
	}
113
	}
120
114
121
	// ********** Setting Launch Configuration **********
115
	// ********** Setting Launch Configuration **********
Lines 184-193 Link Here
184
		}
178
		}
185
	}
179
	}
186
180
187
	protected void validateProject() {
188
		new ValidateJob(this.jpaProject.getProject()).schedule();
189
	}
190
191
	// ********** ClasspathEntry **********
181
	// ********** ClasspathEntry **********
192
182
193
	private IRuntimeClasspathEntry getJdbcJarClasspathEntry() {
183
	private IRuntimeClasspathEntry getJdbcJarClasspathEntry() {
Lines 340-369 Link Here
340
		JpaXmlResource persistenceXmlResource = this.jpaProject.getPersistenceXmlResource();
330
		JpaXmlResource persistenceXmlResource = this.jpaProject.getPersistenceXmlResource();
341
		return ! this.jpaProject.getJavaProject().isOnClasspath(persistenceXmlResource.getFile());
331
		return ! this.jpaProject.getJavaProject().isOnClasspath(persistenceXmlResource.getFile());
342
	}
332
	}
343
344
	/**
345
	 * Performs validation after tables have been generated
346
	 */
347
	/* CU private */ class ValidateJob
348
		extends Job 
349
	{	
350
		private final IProject[] projects;
351
		
352
		ValidateJob(IProject project) {
353
			super(JptCoreMessages.VALIDATE_JOB);
354
			this.projects = new IProject[] {project};
355
		}
356
		
357
		@Override
358
		protected IStatus run(IProgressMonitor monitor) {
359
			try {
360
				ValidationFramework.getDefault().validate(this.projects, true, false, monitor);
361
			} catch (CoreException ex) {
362
				throw new RuntimeException(ex);
363
			}
364
			return Status.OK_STATUS;
365
		}
366
	}
367
	
333
	
368
	private IPath buildJdbcJarPath() {
334
	private IPath buildJdbcJarPath() {
369
		return new Path(this.getJpaProjectConnectionDriverJarList());
335
		return new Path(this.getJpaProjectConnectionDriverJarList());
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/EclipseLink2_0DDLGenerator.java (-7 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
* Copyright (c) 2009, 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 10-16 Link Here
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen;
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen;
11
11
12
import java.util.Properties;
12
import java.util.Properties;
13
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.jpt.common.core.gen.JptGenerator;
14
import org.eclipse.jpt.jpa.core.JpaProject;
16
import org.eclipse.jpt.jpa.core.JpaProject;
15
import org.eclipse.jpt.jpa.core.jpa2.context.persistence.connection.JpaConnection2_0;
17
import org.eclipse.jpt.jpa.core.jpa2.context.persistence.connection.JpaConnection2_0;
16
import org.eclipse.jpt.jpa.db.ConnectionProfile;
18
import org.eclipse.jpt.jpa.db.ConnectionProfile;
Lines 30-46 Link Here
30
public class EclipseLink2_0DDLGenerator extends AbstractEclipseLinkDDLGenerator
32
public class EclipseLink2_0DDLGenerator extends AbstractEclipseLinkDDLGenerator
31
{
33
{
32
	static final String VALIDATION_MODE_PROPERTY = "javax.persistence.validation.mode"; 	  //$NON-NLS-1$
34
	static final String VALIDATION_MODE_PROPERTY = "javax.persistence.validation.mode"; 	  //$NON-NLS-1$
33
	
35
34
	// ********** constructors **********
36
	public static JptGenerator generate(String puName, JpaProject project, OutputMode outputMode, IProgressMonitor monitor) {
35
	
36
	public static void generate(String puName, JpaProject project, OutputMode outputMode, IProgressMonitor monitor) {
37
		if (puName == null || puName.length() == 0 || project == null) {
37
		if (puName == null || puName.length() == 0 || project == null) {
38
			throw new NullPointerException();
38
			throw new NullPointerException();
39
		}
39
		}
40
		new EclipseLink2_0DDLGenerator(puName, project, outputMode).generate(monitor);
40
		return new EclipseLink2_0DDLGenerator(puName, project, outputMode).generate(monitor);
41
	}
41
	}
42
42
43
	private EclipseLink2_0DDLGenerator(String puName, JpaProject jpaProject, OutputMode outputMode) {
43
	// ********** constructors **********
44
45
	public EclipseLink2_0DDLGenerator(String puName, JpaProject jpaProject, OutputMode outputMode) {
44
		super(puName, jpaProject, outputMode);
46
		super(puName, jpaProject, outputMode);
45
	}
47
	}
46
48
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/EclipseLinkDDLGenerator.java (-5 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2008, 2011 Oracle. All rights reserved.
2
* Copyright (c) 2008, 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 10-16 Link Here
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen;
10
package org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen;
11
11
12
import java.util.Properties;
12
import java.util.Properties;
13
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.jpt.common.core.gen.JptGenerator;
14
import org.eclipse.jpt.jpa.core.JpaProject;
16
import org.eclipse.jpt.jpa.core.JpaProject;
15
import org.eclipse.jpt.jpa.db.ConnectionProfile;
17
import org.eclipse.jpt.jpa.db.ConnectionProfile;
16
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.Connection;
18
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.Connection;
Lines 29-44 Link Here
29
public class EclipseLinkDDLGenerator extends AbstractEclipseLinkDDLGenerator
31
public class EclipseLinkDDLGenerator extends AbstractEclipseLinkDDLGenerator
30
{
32
{
31
33
32
	// ********** constructors **********
33
	
34
	
34
	public static void generate(String puName, JpaProject project, OutputMode outputMode, IProgressMonitor monitor) {
35
	public static JptGenerator generate(String puName, JpaProject project, OutputMode outputMode, IProgressMonitor monitor) {
35
		if (puName == null || puName.length() == 0 || project == null) {
36
		if (puName == null || puName.length() == 0 || project == null) {
36
			throw new NullPointerException();
37
			throw new NullPointerException();
37
		}
38
		}
38
		new EclipseLinkDDLGenerator(puName, project, outputMode).generate(monitor);
39
		return new EclipseLinkDDLGenerator(puName, project, outputMode).generate(monitor);
39
	}
40
	}
41
	
42
	// ********** constructors **********
40
43
41
	private EclipseLinkDDLGenerator(String puName, JpaProject jpaProject, OutputMode outputMode) {
44
	public EclipseLinkDDLGenerator(String puName, JpaProject jpaProject, OutputMode outputMode) {
42
		super(puName, jpaProject, outputMode);
45
		super(puName, jpaProject, outputMode);
43
	}
46
	}
44
47
(-)src/org/eclipse/jpt/jpa/eclipselink/core/internal/weave/StaticWeave.java (-11 / +4 lines)
Lines 21-26 Link Here
21
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
21
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
22
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
22
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
23
import org.eclipse.jdt.launching.JavaRuntime;
23
import org.eclipse.jdt.launching.JavaRuntime;
24
import org.eclipse.jpt.common.core.gen.JptGenerator;
24
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
25
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
25
import org.eclipse.jpt.common.utility.internal.StringTools;
26
import org.eclipse.jpt.common.utility.internal.StringTools;
26
27
Lines 42-48 Link Here
42
	
43
	
43
	// ********** static methods **********
44
	// ********** static methods **********
44
45
45
	public static void weave(
46
	public static JptGenerator weave(
46
			IJavaProject javaProject, 
47
			IJavaProject javaProject, 
47
			String source, 
48
			String source, 
48
			String target, 
49
			String target, 
Lines 54-60 Link Here
54
			throw new NullPointerException("javaProject is null");   //$NON-NLS-1$
55
			throw new NullPointerException("javaProject is null");   //$NON-NLS-1$
55
		}
56
		}
56
		
57
		
57
		new StaticWeave(javaProject,
58
		return new StaticWeave(javaProject,
58
			source, 
59
			source, 
59
			target,
60
			target,
60
			loglevel, 
61
			loglevel, 
Lines 63-69 Link Here
63
64
64
	// ********** constructors **********
65
	// ********** constructors **********
65
	
66
	
66
	protected StaticWeave(
67
	public StaticWeave(
67
			IJavaProject javaProject, 
68
			IJavaProject javaProject, 
68
			String source, 
69
			String source, 
69
			String target, 
70
			String target, 
Lines 77-84 Link Here
77
		this.persistenceinfo = persistenceinfo;
78
		this.persistenceinfo = persistenceinfo;
78
79
79
		this.mainType = WEAVING_CLASS;
80
		this.mainType = WEAVING_CLASS;
80
81
		this.setDebug(false);
82
	}
81
	}
83
82
84
	// ********** overrides **********
83
	// ********** overrides **********
Lines 98-109 Link Here
98
		// do nothing
97
		// do nothing
99
	}
98
	}
100
99
101
	@Override
102
	protected void refreshProject() throws CoreException {
103
		// do nothing
104
		// 370895 - Static weaving results in infinite builder loop when enabled
105
	}
106
107
	// ********** behavior **********
100
	// ********** behavior **********
108
101
109
	@Override
102
	@Override
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 34-40 Link Here
34
 org.eclipse.ui.views;bundle-version="[3.6.100,4.0.0)",
34
 org.eclipse.ui.views;bundle-version="[3.6.100,4.0.0)",
35
 org.eclipse.wst.common.emf;bundle-version="[1.2.100,2.0.0)",
35
 org.eclipse.wst.common.emf;bundle-version="[1.2.100,2.0.0)",
36
 org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
36
 org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
37
 org.eclipse.wst.common.frameworks.ui;bundle-version="[1.1.200,2.0.0)"
37
 org.eclipse.wst.common.frameworks.ui;bundle-version="[1.1.200,2.0.0)",
38
 org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)"
38
Export-Package: org.eclipse.jpt.jpa.eclipselink.ui,
39
Export-Package: org.eclipse.jpt.jpa.eclipselink.ui,
39
 org.eclipse.jpt.jpa.eclipselink.ui.internal;x-internal:=true,
40
 org.eclipse.jpt.jpa.eclipselink.ui.internal;x-internal:=true,
40
 org.eclipse.jpt.jpa.eclipselink.ui.internal.commands;x-internal:=true,
41
 org.eclipse.jpt.jpa.eclipselink.ui.internal.commands;x-internal:=true,
(-)src/org/eclipse/jpt/jpa/eclipselink/ui/internal/ddlgen/EclipseLinkDDLGeneratorUi.java (-132 / +8 lines)
Lines 9-40 Link Here
9
*******************************************************************************/
9
*******************************************************************************/
10
package org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen;
10
package org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen;
11
11
12
import org.eclipse.core.resources.WorkspaceJob;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.OperationCanceledException;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.SubMonitor;
19
import org.eclipse.jface.dialogs.IDialogConstants;
20
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.window.Window;
22
import org.eclipse.jface.wizard.WizardDialog;
12
import org.eclipse.jface.wizard.WizardDialog;
23
import org.eclipse.jpt.common.ui.internal.dialogs.OptionalMessageDialog;
24
import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
25
import org.eclipse.jpt.common.utility.internal.StringTools;
26
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
13
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
27
import org.eclipse.jpt.jpa.core.JpaPlatform;
14
import org.eclipse.jpt.jpa.core.JpaPlatform;
28
import org.eclipse.jpt.jpa.core.JpaProject;
15
import org.eclipse.jpt.jpa.core.JpaProject;
29
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
16
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
30
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
17
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
31
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.OutputMode;
32
import org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen.EclipseLinkDDLGenerator;
33
import org.eclipse.jpt.jpa.eclipselink.ui.JptJpaEclipseLinkUiPlugin;
34
import org.eclipse.jpt.jpa.eclipselink.ui.internal.EclipseLinkUiMessages;
35
import org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards.GenerateDDLWizard;
18
import org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards.GenerateDDLWizard;
36
import org.eclipse.osgi.util.NLS;
37
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Display;
39
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.swt.widgets.Shell;
40
21
Lines 45-58 Link Here
45
public class EclipseLinkDDLGeneratorUi
26
public class EclipseLinkDDLGeneratorUi
46
{
27
{
47
	private final JpaProject project;
28
	private final JpaProject project;
48
	private static final String CR = StringTools.CR;
49
29
50
	// ********** constructors **********
30
	// ********** static method **********
51
	
31
	
52
	public static void generate(JpaProject project) {
32
	public static void generate(JpaProject project) {
53
		new EclipseLinkDDLGeneratorUi(project).generate();
33
		new EclipseLinkDDLGeneratorUi(project).generate();
54
	}
34
	}
55
35
36
	// ********** constructors **********
37
	
56
	protected EclipseLinkDDLGeneratorUi(JpaProject project) {
38
	protected EclipseLinkDDLGeneratorUi(JpaProject project) {
57
		super();
39
		super();
58
		if (project == null) {
40
		if (project == null) {
Lines 68-108 Link Here
68
		PersistenceUnit persistenceUnit = this.getPersistenceUnits().iterator().next(); // Take the first persistenceUnit
50
		PersistenceUnit persistenceUnit = this.getPersistenceUnits().iterator().next(); // Take the first persistenceUnit
69
		String puName = persistenceUnit.getName();
51
		String puName = persistenceUnit.getName();
70
52
71
		GenerateDDLWizard wizard = new GenerateDDLWizard(this.project);
53
		GenerateDDLWizard wizard = this.buildGenerateDDLWizard(this.project, puName);
72
		WizardDialog wizardDialog = new WizardDialog(this.getCurrentShell(), wizard);
54
		WizardDialog wizardDialog = new WizardDialog(this.getCurrentShell(), wizard);
73
		wizardDialog.create();
55
		wizardDialog.create();
74
		if(wizard.getPageCount() > 0) {
56
		if(wizard.getPageCount() > 0) {
75
			int returnCode = wizardDialog.open();
57
			wizardDialog.open();
76
			if (returnCode == Window.CANCEL) {
77
				return;
78
			}
79
		}
80
		OutputMode outputMode = wizard.getOutputMode();
81
82
		if((outputMode != OutputMode.sql_script) && ( ! this.displayGeneratingDDLWarning())) {
83
			return;
84
		}
58
		}
85
		WorkspaceJob job = this.buildGenerateDDLJob(puName, this.project, outputMode);
86
		job.schedule();
87
	}
59
	}
88
	
60
	
89
	protected WorkspaceJob buildGenerateDDLJob(String puName, JpaProject project, OutputMode outputMode) {
61
	protected GenerateDDLWizard buildGenerateDDLWizard(JpaProject project, String puName) {
90
		return new GenerateDDLJob(puName, project, outputMode);
62
		return new GenerateDDLWizard(project, puName);
91
	}
63
	}
92
	
64
93
	private Shell getCurrentShell() {
65
	private Shell getCurrentShell() {
94
	    return Display.getCurrent().getActiveShell();
66
	    return Display.getCurrent().getActiveShell();
95
	}
67
	}
96
68
97
	private boolean displayGeneratingDDLWarning() {
98
		if (!OptionalMessageDialog.isDialogEnabled(OverwriteConfirmerDialog.ID)) {
99
			return true;
100
		} else {
101
			OverwriteConfirmerDialog dialog = new OverwriteConfirmerDialog(this.getCurrentShell());
102
			return dialog.open() == IDialogConstants.YES_ID;
103
		}
104
	}
105
106
	// ********** Persistence Unit **********
69
	// ********** Persistence Unit **********
107
70
108
	protected JpaPlatform getPlatform() {
71
	protected JpaPlatform getPlatform() {
Lines 116-206 Link Here
116
	protected Persistence getPersistence() {
79
	protected Persistence getPersistence() {
117
		return this.project.getRootContextNode().getPersistenceXml().getPersistence();
80
		return this.project.getRootContextNode().getPersistenceXml().getPersistence();
118
	}
81
	}
119
120
	// ********** runnable **********
121
122
	protected static class GenerateDDLJob extends WorkspaceJob {
123
		private final String puName;
124
		private final JpaProject project;
125
		private final OutputMode outputMode;
126
127
		public GenerateDDLJob(String puName, JpaProject project, OutputMode outputMode) {
128
			super(EclipseLinkUiMessages.ECLIPSELINK_GENERATE_TABLES_JOB);
129
			this.puName = puName;
130
			this.project = project;
131
			this.outputMode = outputMode;
132
		}
133
134
		@Override
135
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
136
			SubMonitor sm = SubMonitor.convert(monitor, EclipseLinkUiMessages.ECLIPSELINK_GENERATE_TABLES_TASK, 1);
137
			try {
138
				this.ddlGeneratorGenerate(this.puName, this.project, this.outputMode, sm.newChild(1));
139
			} 
140
			catch (OperationCanceledException e) {
141
				return Status.CANCEL_STATUS;
142
			}
143
			catch (RuntimeException re) {				
144
				this.logException(re);
145
			}
146
			return Status.OK_STATUS;
147
		}
148
149
		protected void ddlGeneratorGenerate(String puName, JpaProject project, OutputMode outputMode, IProgressMonitor monitor) {
150
			EclipseLinkDDLGenerator.generate(puName, project, outputMode, monitor);
151
		}
152
153
		protected void logException(RuntimeException re) {
154
			String msg = re.getMessage();
155
			String message = (msg == null) ? re.toString() : msg;
156
			this.displayError(message);
157
			JptJpaEclipseLinkUiPlugin.log(re);
158
		}
159
		
160
		private void displayError(final String message) {
161
			SWTUtil.syncExec(new Runnable() {
162
				public void run() {
163
					MessageDialog.openError(
164
						getShell(),
165
						EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_error,
166
						message
167
					);
168
				}
169
			});
170
		}
171
172
		protected Shell getShell() {
173
			Display display = Display.getCurrent();
174
			Shell shell = (display == null) ? null : display.getActiveShell();
175
			if (shell == null && display != null) {
176
				Shell[] shells = display.getShells();
177
				if (shells.length > 0)
178
					shell = shells[0];
179
			}
180
			return shell;
181
		}
182
	}
183
184
	// ********** overwrite dialog **********
185
186
	static class OverwriteConfirmerDialog extends OptionalMessageDialog {
187
188
		private static final String ID= "dontShowOverwriteExistingTablesFromClasses.warning"; //$NON-NLS-1$
189
190
		OverwriteConfirmerDialog(Shell parent) {
191
			super(ID, parent,
192
					EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_generatingDDLWarningTitle,
193
					NLS.bind(EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_generatingDDLWarningMessage, CR,  CR + CR),
194
					MessageDialog.WARNING,
195
					new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL},
196
					1);
197
		}
198
		
199
		@Override
200
		protected void createButtonsForButtonBar(Composite parent) {
201
			this.createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false);
202
			this.createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true);
203
		}
204
205
	}
206
}
82
}
(-)src/org/eclipse/jpt/jpa/eclipselink/ui/internal/ddlgen/wizards/EclipseLink2_0DDLGeneratorUi.java (-20 / +2 lines)
Lines 9-19 Link Here
9
*******************************************************************************/
9
*******************************************************************************/
10
package org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards;
10
package org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards;
11
11
12
import org.eclipse.core.resources.WorkspaceJob;
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.jpt.jpa.core.JpaProject;
12
import org.eclipse.jpt.jpa.core.JpaProject;
15
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.OutputMode;
16
import org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen.EclipseLink2_0DDLGenerator;
17
import org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.EclipseLinkDDLGeneratorUi;
13
import org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.EclipseLinkDDLGeneratorUi;
18
14
19
/**
15
/**
Lines 37-58 Link Here
37
	// ********** behavior **********
33
	// ********** behavior **********
38
34
39
	@Override
35
	@Override
40
	protected WorkspaceJob buildGenerateDDLJob(String puName, JpaProject project, OutputMode outputMode) {
36
	protected GenerateDDLWizard buildGenerateDDLWizard(JpaProject project, String puName) {
41
		return new Generate2_0DDLJob(puName, project, outputMode);
37
		return new EclipseLink2_0GenerateDDLWizard(project, puName);
42
	}
43
44
	// ********** runnable **********
45
46
	protected static class Generate2_0DDLJob extends EclipseLinkDDLGeneratorUi.GenerateDDLJob {
47
48
		public Generate2_0DDLJob(String puName, JpaProject project, OutputMode outputMode) {
49
			super(puName, project, outputMode);
50
		}
51
52
		@Override
53
		protected void ddlGeneratorGenerate(String puName, JpaProject project, OutputMode outputMode, IProgressMonitor monitor) {
54
			EclipseLink2_0DDLGenerator.generate(puName, project, outputMode, monitor);
55
		}
56
	}
38
	}
57
}
39
}
58
40
(-)src/org/eclipse/jpt/jpa/eclipselink/ui/internal/ddlgen/wizards/EclipseLink2_0GenerateDDLWizard.java (+72 lines)
Added Link Here
1
/*******************************************************************************
2
* Copyright (c) 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
6
* 
7
* Contributors:
8
*     Oracle - initial API and implementation
9
*******************************************************************************/
10
package org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards;
11
12
import org.eclipse.core.resources.IProject;
13
import org.eclipse.core.resources.WorkspaceJob;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.jpt.common.core.gen.JptGenerator;
17
import org.eclipse.jpt.jpa.core.JpaProject;
18
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.OutputMode;
19
import org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen.EclipseLink2_0DDLGenerator;
20
import org.eclipse.wst.validation.ValidationFramework;
21
22
/**
23
 *  EclipseLink2_0GenerateDDLWizard
24
 */
25
public class EclipseLink2_0GenerateDDLWizard extends GenerateDDLWizard {
26
27
	public EclipseLink2_0GenerateDDLWizard(JpaProject jpaProject, String puName) {
28
		super(jpaProject, puName);
29
	}
30
31
	@Override
32
	protected WorkspaceJob buildGenerateDDLJob(String puName, JpaProject project, OutputMode outputMode) {
33
		return new Generate2_0DDLJob(puName, project, outputMode);
34
	}
35
36
	// ********** generate ddl job **********
37
38
	protected static class Generate2_0DDLJob extends GenerateDDLWizard.GenerateDDLJob {
39
40
		public Generate2_0DDLJob(String puName, JpaProject jpaProject, OutputMode outputMode) {
41
			super(puName, jpaProject, outputMode);
42
		}
43
44
		@Override
45
		protected JptGenerator buildDDLGenerator(String puName, JpaProject project, OutputMode outputMode) {
46
			return new EclipseLink2_0DDLGenerator(puName, project, outputMode);
47
		}
48
		
49
		@Override
50
		protected void postGenerate(boolean generationSuccessful) {
51
			super.postGenerate(generationSuccessful);
52
			
53
			if((outputMode != OutputMode.database) && generationSuccessful) {
54
				this.validateProject();
55
			}
56
		}
57
58
		/**
59
		 * Performs validation after tables have been generated
60
		 */
61
		protected void validateProject() {
62
			IProject[] projects = new IProject[] {this.jpaProject.getProject()};
63
			try {
64
				ValidationFramework.getDefault().validate(projects, true, false, new NullProgressMonitor());
65
			}
66
			catch (CoreException e) {
67
				this.logException(e);
68
			}
69
		}
70
	}
71
	
72
}
(-)src/org/eclipse/jpt/jpa/eclipselink/ui/internal/ddlgen/wizards/GenerateDDLWizard.java (-5 / +253 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
* Copyright (c) 2007, 2012 Oracle. All rights reserved.
3
* This program and the accompanying materials are made available under the
3
* This program and the accompanying materials are made available under the
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
4
* terms of the Eclipse Public License v1.0, which accompanies this distribution
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
5
* and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-36 Link Here
9
*******************************************************************************/
9
*******************************************************************************/
10
package org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards;
10
package org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards;
11
11
12
import org.eclipse.core.resources.IContainer;
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResourceRuleFactory;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.resources.WorkspaceJob;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.OperationCanceledException;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.core.runtime.SubMonitor;
27
import org.eclipse.jdt.core.IJavaProject;
28
import org.eclipse.jface.dialogs.IDialogConstants;
29
import org.eclipse.jface.dialogs.MessageDialog;
12
import org.eclipse.jface.wizard.Wizard;
30
import org.eclipse.jface.wizard.Wizard;
31
import org.eclipse.jpt.common.core.gen.JptGenerator;
32
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
33
import org.eclipse.jpt.common.ui.internal.dialogs.OptionalMessageDialog;
34
import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
35
import org.eclipse.jpt.common.utility.internal.StringTools;
36
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
13
import org.eclipse.jpt.jpa.core.JpaProject;
37
import org.eclipse.jpt.jpa.core.JpaProject;
14
import org.eclipse.jpt.jpa.db.ConnectionProfile;
38
import org.eclipse.jpt.jpa.db.ConnectionProfile;
15
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.OutputMode;
39
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.OutputMode;
40
import org.eclipse.jpt.jpa.eclipselink.core.internal.ddlgen.EclipseLinkDDLGenerator;
41
import org.eclipse.jpt.jpa.eclipselink.ui.JptJpaEclipseLinkUiPlugin;
42
import org.eclipse.jpt.jpa.eclipselink.ui.internal.EclipseLinkUiMessages;
43
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
16
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
44
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
17
import org.eclipse.jpt.jpa.ui.internal.wizards.DatabaseSchemaWizardPage;
45
import org.eclipse.jpt.jpa.ui.internal.wizards.DatabaseSchemaWizardPage;
46
import org.eclipse.osgi.util.NLS;
47
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Display;
49
import org.eclipse.swt.widgets.Shell;
50
import org.eclipse.ui.IWorkbenchPage;
51
import org.eclipse.ui.PartInitException;
52
import org.eclipse.ui.PlatformUI;
53
import org.eclipse.ui.ide.IDE;
18
54
19
/**
55
/**
20
 *  GenerateDDLWizard
56
 *  GenerateDDLWizard
21
 */
57
 */
22
public class GenerateDDLWizard extends Wizard {	
58
public class GenerateDDLWizard extends Wizard {	
23
59
60
	private static final String CR = StringTools.CR;
61
	
24
	private JpaProject jpaProject;
62
	private JpaProject jpaProject;
25
63
	private String puName;
64
	private JptGenerator ddlGenerator;
65
	
26
	private DatabaseSchemaWizardPage dbSettingsPage;
66
	private DatabaseSchemaWizardPage dbSettingsPage;
27
	private GenerationOutputModeWizardPage generationOutputModePage;
67
	private GenerationOutputModeWizardPage generationOutputModePage;
28
68
29
	// ********** constructor **********
69
	// ********** constructor **********
30
70
31
	public GenerateDDLWizard(JpaProject jpaProject) {
71
	public GenerateDDLWizard(JpaProject jpaProject, String puName) {
32
		super();
72
		super();
33
		this.jpaProject = jpaProject;
73
		this.jpaProject = jpaProject;
74
		this.puName = puName;
34
		this.setWindowTitle(JptUiMessages.GenerateDDLWizard_title); 
75
		this.setWindowTitle(JptUiMessages.GenerateDDLWizard_title); 
35
	}
76
	}
36
77
Lines 49-62 Link Here
49
	
90
	
50
	@Override
91
	@Override
51
	public boolean performFinish() {
92
	public boolean performFinish() {
52
		return (this.getJpaProjectConnectionProfile() != null);
93
		OutputMode outputMode = this.getOutputMode();
94
95
		if((outputMode != OutputMode.sql_script) && ( ! this.displayGeneratingDDLWarning())) {
96
			return false;
97
		}
98
		
99
		this.scheduleGenerateDDLJob(outputMode);
100
		return true;
53
	}
101
	}
54
102
55
    @Override
103
    @Override
56
	public boolean canFinish() {
104
	public boolean canFinish() {
57
    	return this.dbSettingsPageCanFinish() && this.generationOutputModePageCanFinish();
105
    	return this.dbSettingsPageCanFinish() && this.generationOutputModePageCanFinish();
58
    }
106
    }
59
    
107
108
	protected void scheduleGenerateDDLJob(OutputMode outputMode) {
109
			
110
		WorkspaceJob generateDDLJob = this.buildGenerateDDLJob(this.puName, this.jpaProject, outputMode);
111
		generateDDLJob.schedule();
112
	}
113
	
114
	protected WorkspaceJob buildGenerateDDLJob(String puName, JpaProject project, OutputMode outputMode) {
115
		return new GenerateDDLJob(puName, project, outputMode);
116
	}
117
60
	// ********** intra-wizard methods **********
118
	// ********** intra-wizard methods **********
61
    
119
    
62
    public OutputMode getOutputMode() {
120
    public OutputMode getOutputMode() {
Lines 76-79 Link Here
76
	private ConnectionProfile getJpaProjectConnectionProfile() {
134
	private ConnectionProfile getJpaProjectConnectionProfile() {
77
		return this.jpaProject.getConnectionProfile();
135
		return this.jpaProject.getConnectionProfile();
78
	}
136
	}
137
138
	private boolean displayGeneratingDDLWarning() {
139
		if (!OptionalMessageDialog.isDialogEnabled(OverwriteConfirmerDialog.ID)) {
140
			return true;
141
		} else {
142
			OverwriteConfirmerDialog dialog = new OverwriteConfirmerDialog(this.getCurrentShell());
143
			return dialog.open() == IDialogConstants.YES_ID;
144
		}
145
	}
146
147
	private Shell getCurrentShell() {
148
	    return Display.getCurrent().getActiveShell();
149
	}
150
	
151
	private JptGenerator getDDLGenerator() {
152
		return ddlGenerator;
153
	}
154
155
	protected void setDDLGenerator(JptGenerator ddlGenerator) {
156
		this.ddlGenerator = ddlGenerator;
157
	}
158
159
	// ********** overwrite dialog **********
160
161
	static class OverwriteConfirmerDialog extends OptionalMessageDialog {
162
163
		private static final String ID= "dontShowOverwriteExistingTablesFromClasses.warning"; //$NON-NLS-1$
164
165
		OverwriteConfirmerDialog(Shell parent) {
166
			super(ID, parent,
167
					EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_generatingDDLWarningTitle,
168
					NLS.bind(EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_generatingDDLWarningMessage, CR,  CR + CR),
169
					MessageDialog.WARNING,
170
					new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL},
171
					1);
172
		}
173
		
174
		@Override
175
		protected void createButtonsForButtonBar(Composite parent) {
176
			this.createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false);
177
			this.createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true);
178
		}
179
180
	}
181
182
	// ********** generate ddl job **********
183
184
	protected static class GenerateDDLJob extends WorkspaceJob {
185
		protected final String puName;
186
		protected final JpaProject jpaProject;
187
		protected final OutputMode outputMode;
188
		private final SynchronizedBoolean generationCompleted;
189
		private boolean generationSuccessful;
190
191
		public GenerateDDLJob(String puName, JpaProject jpaProject, OutputMode outputMode) {
192
			super(EclipseLinkUiMessages.ECLIPSELINK_GENERATE_TABLES_JOB);
193
			this.puName = puName;
194
			this.jpaProject = jpaProject;
195
			this.outputMode = outputMode;
196
			this.generationCompleted = new SynchronizedBoolean(false);
197
			this.generationSuccessful = false;
198
			
199
			IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
200
			this.setRule(ruleFactory.modifyRule(this.jpaProject.getProject()));
201
		}
202
203
		@Override
204
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
205
			SubMonitor sm = SubMonitor.convert(monitor, EclipseLinkUiMessages.ECLIPSELINK_GENERATE_TABLES_TASK, 1);
206
			try {
207
				this.ddlGeneratorGenerate(sm.newChild(1));
208
			} 
209
			catch (OperationCanceledException e) {
210
				return Status.CANCEL_STATUS;
211
			}
212
			catch (RuntimeException re) {
213
				this.logException(re);
214
			}
215
			return Status.OK_STATUS;
216
		}
217
218
		protected void ddlGeneratorGenerate(IProgressMonitor monitor) {
219
			JptGenerator ddlGenerator = this.buildDDLGenerator(this.puName, this.jpaProject, this.outputMode);
220
221
			LaunchConfigListener launchListener = this.buildLaunchListener();
222
			ddlGenerator.addLaunchConfigListener(launchListener);
223
			ddlGenerator.generate(monitor);
224
			try {
225
				this.generationCompleted.waitUntilTrue();
226
			}
227
			catch (InterruptedException e) {	
228
				this.logException(e);
229
			}
230
			finally {
231
				ddlGenerator.removeLaunchConfigListener(launchListener);
232
			}
233
			
234
			this.postGenerate(this.generationSuccessful);
235
		}
236
		
237
		protected void postGenerate(boolean generationSuccessful) {
238
			if( ! generationSuccessful) {
239
				this.displayError("Generation Failed");	//TODO
240
				return;
241
			}
242
			if((this.outputMode != OutputMode.database) && generationSuccessful) {
243
				this.refreshProject();
244
				this.openGeneratedSqlFile();
245
			}
246
		}
247
248
		private void refreshProject() {
249
			try {
250
				this.jpaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
251
			}
252
			catch (CoreException e) {	
253
				this.logException(e);
254
			}
255
		}
256
		
257
		private LaunchConfigListener buildLaunchListener() {
258
			return new LaunchConfigListener() {
259
				
260
				public void launchCompleted(boolean generationSuccessful) {
261
					GenerateDDLJob.this.generationSuccessful = generationSuccessful;
262
					GenerateDDLJob.this.generationCompleted.setTrue();
263
				}
264
			};
265
		}
266
		
267
		protected JptGenerator buildDDLGenerator(String puName, JpaProject project, OutputMode outputMode) {
268
			return new EclipseLinkDDLGenerator(puName, project, outputMode);
269
		}
270
271
		private void openGeneratedSqlFile() {
272
273
			IJavaProject javaProject = this.jpaProject.getJavaProject();
274
			IPath projecName = new Path(javaProject.getProject().getName());
275
			IContainer container = (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(projecName);
276
			IFile sqlFile = container.getFile(new Path("createDDL.sql")); //TODO
277
278
			this.openEditor(sqlFile);
279
		}
280
		
281
		private void openEditor(final IFile file) {
282
			if(file != null) {
283
				SWTUtil.asyncExec(new Runnable() {
284
					public void run() {
285
						try {
286
							IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
287
							IDE.openEditor(page, file, true);
288
						}
289
						catch (PartInitException e) {
290
							JptJpaUiPlugin.log(e);
291
						}
292
					}
293
				});
294
			}
295
		}
296
297
		protected void logException(Exception exception) {
298
			String msg = exception.getMessage();
299
			String message = (msg == null) ? exception.toString() : msg;
300
			this.displayError(message);
301
			JptJpaEclipseLinkUiPlugin.log(exception);
302
		}
303
		
304
		private void displayError(final String message) {
305
			SWTUtil.syncExec(new Runnable() {
306
				public void run() {
307
					MessageDialog.openError(
308
						getShell(),
309
						EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_error,
310
						message
311
					);
312
				}
313
			});
314
		}
315
316
		protected Shell getShell() {
317
			Display display = Display.getCurrent();
318
			Shell shell = (display == null) ? null : display.getActiveShell();
319
			if (shell == null && display != null) {
320
				Shell[] shells = display.getShells();
321
				if (shells.length > 0)
322
					shell = shells[0];
323
			}
324
			return shell;
325
		}
326
	}
79
}
327
}

Return to bug 322567