Author: scabanovich
Date: 2007-08-31 10:30:10 -0400 (Fri, 31 Aug 2007)
New Revision: 3412
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizard.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizardPage.java
Log:
JBIDE-769
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF 2007-08-31 01:25:33
UTC (rev 3411)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF 2007-08-31 14:30:10
UTC (rev 3412)
@@ -41,6 +41,7 @@
org.eclipse.jst.j2ee.ui,
org.eclipse.jst.j2ee.web,
org.eclipse.wst.xml.ui,
+ org.eclipse.debug.core,
org.apache.ant,
org.jboss.ide.eclipse.jdt.core,
org.eclipse.datatools.connectivity,
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizard.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizard.java 2007-08-31
01:25:33 UTC (rev 3411)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizard.java 2007-08-31
14:30:10 UTC (rev 3412)
@@ -10,31 +10,122 @@
******************************************************************************/
package org.jboss.tools.seam.ui.wizard;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
+import org.hibernate.eclipse.console.ExtensionManager;
+import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.project.facet.SeamFacetPreference;
import org.jboss.tools.seam.ui.SeamUIMessages;
/**
* Seam Generate Entities Wizard.
* @author Alexey Kazakov
*/
-public class SeamGenerateEnitiesWizard extends Wizard implements INewWizard {
+public class SeamGenerateEnitiesWizard extends SeamBaseWizard implements INewWizard {
- /* (non-Javadoc)
- * @see org.eclipse.jface.wizard.Wizard#performFinish()
- */
- @Override
- public boolean performFinish() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
org.eclipse.jface.viewers.IStructuredSelection)
- */
- public void init(IWorkbench workbench, IStructuredSelection selection) {
+ public SeamGenerateEnitiesWizard() {
+ super(GENERATE_SEAM_ENTITIES);
setWindowTitle(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_TITLE);
addPage(new SeamGenerateEnitiesWizardPage());
}
-}
\ No newline at end of file
+
+ public static final IUndoableOperation GENERATE_SEAM_ENTITIES = new
SeamBaseOperation("Action creating operation") {
+
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws
ExecutionException {
+ Map<String, String> params = (Map)info.getAdapter(Map.class);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ params.get(IParameter.SEAM_PROJECT_NAME));
+
+ try {
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType launchConfigurationType =
launchManager.getLaunchConfigurationType("org.hibernate.eclipse.launch.CodeGenerationLaunchConfigurationType");
+ ILaunchConfigurationWorkingCopy wc = launchConfigurationType.newInstance(null,
"GenerateEntities");
+
+ //Main
+ wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
params.get(IParameter.HIBERNATE_CONFIGURATION_NAME));
+
+ IPath src = getSourceFolder(project);
+ if(src == null) {
+ throw new CoreException(new Status(IStatus.ERROR, SeamCorePlugin.PLUGIN_ID,
"Source folder not found in project " + project.getName()));
+ }
+ wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR, src.toString());
+
+ boolean isReverseEngineer =
"true".equals(params.get(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER));
+ wc.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, isReverseEngineer);
+
+ if(isReverseEngineer) {
+ wc.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME, "seamtest");
+ wc.setAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS, true);
+ wc.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY, true);
+ wc.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING, true);
+ }
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES, true);
+ String template = "" +
SeamFacetPreference.getStringPreference(SeamFacetPreference.SEAM_HOME_FOLDER) +
"/seam-gen/view";
+// wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_TEMPLATE_DIR, true);
+ wc.setAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR, template);
+
+ //Exporters
+ wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5, true);
+ wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
+
+ ExporterDefinition[] ds = ExtensionManager.findExporterDefinitions();
+ if(ds != null) for (int i = 0; i < ds.length; i++) {
+ wc.setAttribute(ds[i].getId(), true);
+ }
+
+ wc.launch("run", new NullProgressMonitor());
+ } catch (CoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public List<String[]> getFileMappings(Map<String, Object> vars) {
+ throw new UnsupportedOperationException("This method is not relevant in
generating seam entities.");
+ }
+
+ };
+
+ static IPath getSourceFolder(IProject project) throws CoreException {
+ if(!project.hasNature(JavaCore.NATURE_ID)) return null;
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] es = javaProject.getRawClasspath();
+ for (int i = 0; i < es.length; i++) {
+ if(es[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) continue;
+ IPath p = es[i].getPath();
+ if(p == null) continue;
+ IFolder f = ResourcesPlugin.getWorkspace().getRoot().getFolder(p);
+ if(f != null && f.exists()) {
+ return p;
+ }
+ }
+ return null;
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizardPage.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizardPage.java 2007-08-31
01:25:33 UTC (rev 3411)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizardPage.java 2007-08-31
14:30:10 UTC (rev 3412)
@@ -13,14 +13,17 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
import org.jboss.tools.seam.ui.SeamUIMessages;
import org.jboss.tools.seam.ui.internal.project.facet.IValidator;
import org.jboss.tools.seam.ui.internal.project.facet.ValidatorFactory;
@@ -30,7 +33,7 @@
/**
* @author Alexey Kazakov
*/
-public class SeamGenerateEnitiesWizardPage extends WizardPage implements
PropertyChangeListener {
+public class SeamGenerateEnitiesWizardPage extends WizardPage implements
PropertyChangeListener, IAdaptable {
private IFieldEditor projectEditor;
private IFieldEditor configEditor;
@@ -130,4 +133,17 @@
setMessage(null);
setPageComplete(true);
}
-}
\ No newline at end of file
+
+ public Object getAdapter(Class adapter) {
+ if(adapter == Map.class) {
+ Map<String,String> values = new HashMap<String, String>();
+ values.put(projectEditor.getName(), projectEditor.getValueAsString());
+ values.put(configEditor.getName(), configEditor.getValueAsString());
+ String mode = radios.getValue().toString();
+ values.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER,
("reverse".equals(mode) ? "true" : "false"));
+ return values;
+ }
+ return null;
+ }
+
+}