Author: dgeraskov
Date: 2008-06-18 08:56:04 -0400 (Wed, 18 Jun 2008)
New Revision: 8825
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-2344
http://jira.jboss.com/jira/browse/JBIDE-2345
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF 2008-06-18
12:06:37 UTC (rev 8824)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF 2008-06-18
12:56:04 UTC (rev 8825)
@@ -7,7 +7,16 @@
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jpt.ui,
- org.eclipse.jpt.core;bundle-version="2.0.0"
+ org.eclipse.jpt.core;bundle-version="2.0.0",
+ org.eclipse.jpt;bundle-version="2.0.0",
+ org.eclipse.jpt.eclipselink.core;bundle-version="1.0.0",
+ org.eclipse.jpt.eclipselink.ui;bundle-version="1.0.0",
+ org.eclipse.jpt.gen;bundle-version="1.1.0",
+ org.eclipse.jpt.utility;bundle-version="1.2.0",
+ org.hibernate.eclipse.console;bundle-version="3.2.0",
+ org.hibernate.eclipse;bundle-version="3.2.0",
+ org.eclipse.core.resources;bundle-version="3.4.0",
+ org.eclipse.debug.core;bundle-version="3.4.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: Hibernate Team
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java 2008-06-18
12:06:37 UTC (rev 8824)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java 2008-06-18
12:56:04 UTC (rev 8825)
@@ -1,32 +1,113 @@
/*******************************************************************************
- * Copyright (c) 2007-2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.hibernate.jpt.ui.internal.platform;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.ui.internal.platform.base.EntitiesGenerator;
import org.eclipse.jpt.ui.internal.platform.generic.GenericPlatformUi;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
/**
* @author Dmitry Geraskov
- *
+ *
*/
public class HibernatePlatformUI extends GenericPlatformUi {
-
- /**
- * Change method realization to provide other entities generation.
- */
+
+ public static final String LaunchConfigurationType_ID =
"org.hibernate.eclipse.launch.CodeGenerationLaunchConfigurationType";
+
+ private static String exporter_id = "hbmexporter";
+ private static String full_exporter_id = HibernateLaunchConstants.ATTR_EXPORTERS +
'.' + "hbmexporter";
+
@Override
public void generateEntities(JpaProject project, IStructuredSelection selection) {
- EntitiesGenerator.generate(project, selection);
+ ILaunchConfigurationWorkingCopy wc = createDefaultLaunchConfig(project.getName());
+ if (wc != null) {
+ // Main
+ // SHOULD PRESENT THE CONFIGURATION!!!
+ wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
project.getName());
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR, project.getName() +
"\\src"); //$NON-NLS-1$
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,
"package_name");
+ 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_ENABLE_JDK5, true);
+ wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + '.' + exporter_id +
".extension_id",
+ HibernateLaunchConstants.ATTR_PREFIX + "hbm2java"); //$NON-NLS-1$
//$NON-NLS-2$
+ runLaunchConfiguration(wc);
+ }
}
+ @Override
+ public void generateDDL(JpaProject project, IStructuredSelection selection) {
+ ILaunchConfigurationWorkingCopy wc = createDefaultLaunchConfig(project.getName());
+ if (wc != null) {
+ // Main
+ // SHOULD PRESENT THE CONFIGURATION!!!
+ wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
project.getName());
+ wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR, project.getName() +
"\\src"); //$NON-NLS-1$
+
+ Map<String, String> prop = new HashMap<String, String>();
+ prop.put("outputFileName", "schema.ddl");
+ prop.put("outputdir", project.getName() + "\\src");
+ prop.put("format", "true");
+ prop.put("scriptToConsole", "false");
+
+ wc.setAttribute(full_exporter_id + ".properties", prop);
+ wc.setAttribute(full_exporter_id + ".extension_id",
HibernateLaunchConstants.ATTR_PREFIX + "hbm2ddl"); //$NON-NLS-1$ //$NON-NLS-2$
+ runLaunchConfiguration(wc);
+ }
+ }
+
+ private ILaunchConfigurationWorkingCopy createDefaultLaunchConfig(String projectName) {
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType launchConfigurationType = launchManager
+ .getLaunchConfigurationType(LaunchConfigurationType_ID); //$NON-NLS-1$
+
+ ILaunchConfigurationWorkingCopy wc = null;
+ try {
+ wc = launchConfigurationType.newInstance(null, projectName +
"-hibernate-generate");
+ wc.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, true);
+ // Create exporters
+ List<String> exporters = new ArrayList<String>();
+ exporters.add(exporter_id); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, exporters);
+ wc.setAttribute(full_exporter_id, true);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+
+ return wc;
+ }
+
+ private void runLaunchConfiguration(ILaunchConfiguration configuration) {
+ try {
+ DebugPlugin.getDefault().getLaunchManager().addLaunch(configuration.launch(ILaunchManager.RUN_MODE,
null));
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
}