Author: dgeraskov
Date: 2009-08-04 04:43:28 -0400 (Tue, 04 Aug 2009)
New Revision: 16956
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesWizard.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesWizardPage.java
Removed:
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
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesTablesWizardPage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4702
SeamGenerateEnitiesWizard name misprint fixed.
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2009-08-04 08:17:02 UTC (rev
16955)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2009-08-04 08:43:28 UTC (rev
16956)
@@ -85,7 +85,7 @@
</wizard>
<wizard
category="org.jboss.tools.seam.ui"
- class="org.jboss.tools.seam.ui.wizard.SeamGenerateEnitiesWizard"
+ class="org.jboss.tools.seam.ui.wizard.SeamGenerateEntitiesWizard"
icon="icons/seam16.png"
id="org.jboss.tools.seam.ui.wizard.SeamGenerateEnitiesWizard"
name="Seam Generate Entities">
Deleted:
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 2009-08-04
08:17:02 UTC (rev 16955)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizard.java 2009-08-04
08:43:28 UTC (rev 16956)
@@ -1,388 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.ui.wizard;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-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.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.Status;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-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.jface.resource.ImageDescriptor;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.PlatformUI;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.KnownConfigurations;
-import org.hibernate.eclipse.launch.HibernateLaunchConstants;
-import org.jboss.tools.jst.web.WebUtils;
-import org.jboss.tools.seam.core.ISeamProject;
-import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.core.SeamProjectsSet;
-import org.jboss.tools.seam.core.project.facet.SeamRuntime;
-import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
-import org.jboss.tools.seam.core.project.facet.SeamVersion;
-import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
-import org.jboss.tools.seam.ui.ISeamHelpContextIds;
-import org.jboss.tools.seam.ui.SeamUIMessages;
-import org.jboss.tools.seam.ui.widget.editor.INamedElement;
-
-/**
- * Seam Generate Entities Wizard.
- * @author Alexey Kazakov
- */
-public class SeamGenerateEnitiesWizard extends SeamBaseWizard implements INewWizard {
-
- SeamGenerateEnitiesWizardPage page1 = new SeamGenerateEnitiesWizardPage();
- IWizardPage page2 = new SeamGenerateEntitiesTablesWizardPage();
-
- public void createPageControls(Composite pageContainer) {
- super.createPageControls(pageContainer);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(pageContainer,
ISeamHelpContextIds.GENERATE_SEAM_ENTITIES);
- }
-
- public SeamGenerateEnitiesWizard() {
- super(GENERATE_SEAM_ENTITIES);
- setWindowTitle(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_TITLE);
- setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(SeamGenerateEnitiesWizard.class,
"SeamWebProjectWizBan.png"));
- addPage(page1);
- addPage(page2);
- }
-
- @Override
- public boolean canFinish() {
- return page1.isPageComplete();
- }
-
- public static final IUndoableOperation GENERATE_SEAM_ENTITIES = new
SeamBaseOperation(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_ACTION_CREATING_OPERATION)
{
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.tools.seam.ui.wizard.SeamBaseOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws
ExecutionException {
- Map<String, INamedElement> params = (Map)info.getAdapter(Map.class);
- IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(params.get(IParameter.SEAM_PROJECT_NAME).getValueAsString());
-
- try {
-
- ISeamProject seamProject = (ISeamProject)project.getNature(ISeamProject.NATURE_ID);
- boolean seam2 = seamProject.getRuntime().getVersion().compareTo(SeamVersion.SEAM_2_0)
>= 0;
-
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfigurationType launchConfigurationType =
- launchManager.getLaunchConfigurationType("org.hibernate.eclipse.launch.CodeGenerationLaunchConfigurationType");
//$NON-NLS-1$
- // we put null in location to avoid it being inside the project by default since the
launch config currenlty will be machine independent with respect to the paths.
- launchConfigurationType.getAttribute("");
- ILaunchConfigurationWorkingCopy wc =
- launchConfigurationType.newInstance(null, project.getName() +
"-generate-entities"); //$NON-NLS-1$
-
- //Main
- wc.setAttribute(
- HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
- params.get(IParameter.HIBERNATE_CONFIGURATION_NAME).getValueAsString());
-
- SeamProjectsSet seamProjectsSet = SeamProjectsSet.create(project);
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
- seamProjectsSet.getModelFolder()==null?
- "":seamProjectsSet.getModelFolder().getFullPath().toString());
//$NON-NLS-1$
-
- boolean isReverseEngineer =
"true".equals(params.get(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER).getValueAsString());
//$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, isReverseEngineer);
-
- if(isReverseEngineer) {
- wc.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,
seamProjectsSet.getEntityPackage());
- 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);
-
- boolean seam21 =
seamProject.getRuntime().getVersion().compareTo(SeamVersion.SEAM_2_1) >= 0 ||
- seamProject.getRuntime().getVersion().compareTo(SeamVersion.SEAM_2_2) >= 0;
- // Only Seam 2.1 does not break when generating from one-to-one
- wc.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_ONE_TO_ONE, seam21);
- }
-
- SeamRuntime seamRt = getRuntime(project);
- if(seamRt==null) {
- seamRt = getRuntime(project);
- }
- if(seamRt == null) {
- throw new CoreException(new Status(IStatus.ERROR, SeamCorePlugin.PLUGIN_ID,
- NLS.bind(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_CAN_NOT_FIND_SEAM_RUNTIME,
project.getName())));
- }
- String seamTemplatesRoot = seamRt.getTemplatesDir();
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR, seamTemplatesRoot);
- wc.setAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES, true);
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5, true);
- wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
-
- // Create exporters
- // TODO Add others exporters
- List<String> exporters = new ArrayList<String>();
-
- if(isReverseEngineer) {
- exporters.add("hbmtemplate0"); //$NON-NLS-1$
- }
- exporters.add("hbmtemplate1"); //$NON-NLS-1$
- exporters.add("hbmtemplate2"); //$NON-NLS-1$
- exporters.add("hbmtemplate3"); //$NON-NLS-1$
- exporters.add("hbmtemplate4"); //$NON-NLS-1$
- exporters.add("hbmtemplate5"); //$NON-NLS-1$
- exporters.add("hbmtemplate6"); //$NON-NLS-1$
- exporters.add("hbmtemplate7"); //$NON-NLS-1$
- exporters.add("hbmtemplate8"); //$NON-NLS-1$
- exporters.add("hbmtemplate9"); //$NON-NLS-1$
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, exporters);
-
- if(isReverseEngineer) {
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate0",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate0.extension_id", "org.hibernate.tools.hbm2java");
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate1",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate1.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate2",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate2.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate3",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate3.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate4",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate4.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate5",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate5.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate6",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate6.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate7",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate7.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate8",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate8.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate9",
true); //$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate9.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
-
- Map<String, String> hbmtemplateAttributes = new HashMap<String,
String>();
-
-// <hbmtemplate filepattern="{class-name}List.xhtml"
-// template="view/list.xhtml.ftl"
-// destdir="${project.home}/view"
-// foreach="entity"/>
-
- hbmtemplateAttributes.put("file_pattern",
"{class-name}List.xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("template_name",
"view/list.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",
seamProjectsSet.getViewsFolder().getFullPath().toString()); //$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity");
//$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass",SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_54);
//$NON-NLS-1$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate1.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="{class-name}.xhtml"
-// template="view/view.xhtml.ftl"
-// destdir="${project.home}/view"
-// foreach="entity"/>
-
- hbmtemplateAttributes = new HashMap<String, String>();
- hbmtemplateAttributes.put("file_pattern", "{class-name}.xhtml");
//$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("template_name",
"view/view.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate2.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="{class-name}.page.xml"
-// template="view/view.page.xml.ftl"
-// destdir="${project.home}/view"
-// foreach="entity"/>
-
- hbmtemplateAttributes = new HashMap<String, String>();
- hbmtemplateAttributes.put("file_pattern",
"{class-name}.page.xml"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("template_name",
"view/view.page.xml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate3.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="{class-name}Edit.xhtml"
-// template="view/edit.xhtml.ftl"
-// destdir="${project.home}/view"
-// foreach="entity"/>
-
- hbmtemplateAttributes = new HashMap<String, String>();
- hbmtemplateAttributes.put("file_pattern",
"{class-name}Edit.xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("template_name",
"view/edit.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate4.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="{class-name}Edit.page.xml"
-// template="view/edit.page.xml.ftl"
-// destdir="${project.home}/view"
-// foreach="entity"/>
-
- hbmtemplateAttributes = new HashMap<String, String>();
- hbmtemplateAttributes.put("file_pattern",
"{class-name}Edit.page.xml"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("template_name",
"view/edit.page.xml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate5.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="{package-name}/{class-name}List.java"
-// template="src/EntityList.java.ftl"
-// destdir="${project.home}/src"
-// foreach="entity"/>
-
- IEclipsePreferences seamFacetPrefs = SeamCorePlugin.getSeamPreferences(project);
- final String actionpackage =
seamFacetPrefs.get(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME,
"");
- final String actionDir = actionpackage.replace('.','/');
-
- hbmtemplateAttributes = new HashMap<String, String>();
-
- if(seam2) {
- //Seam2: <property key="actionPackage"
value="${action.package}" />
- hbmtemplateAttributes.put("actionPackage",actionpackage); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("file_pattern", actionDir +
"/{class-name}List.java"); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- hbmtemplateAttributes.put("file_pattern",
"{package-name}/{class-name}List.java"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- hbmtemplateAttributes.put("template_name",
"src/EntityList.java.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getActionFolder().getFullPath().toString());
//$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate6.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="{class-name}List.page.xml"
-// template="view/list.page.xml.ftl"
-// destdir="${project.home}/view"
-// foreach="entity"/>
-
- hbmtemplateAttributes = new HashMap<String, String>();
- hbmtemplateAttributes.put("file_pattern",
"{class-name}List.page.xml"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("template_name",
"view/list.page.xml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate7.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="{package-name}/{class-name}Home.java"
-// template="src/EntityHome.java.ftl"
-// destdir="${project.home}/src"
-// foreach="entity"/>
-
- hbmtemplateAttributes = new HashMap<String, String>();
- if(seam2) {
- //Seam2: <property key="actionPackage"
value="${action.package}" />
- hbmtemplateAttributes.put("actionPackage",actionpackage); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("file_pattern", actionDir +
"/{class-name}Home.java"); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- hbmtemplateAttributes.put("file_pattern",
"{package-name}/{class-name}Home.java"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- hbmtemplateAttributes.put("template_name",
"src/EntityHome.java.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getActionFolder().getFullPath().toString());
//$NON-NLS-1$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate8.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
-// <hbmtemplate filepattern="menu.xhtml"
-// template="view/layout/menu.xhtml.ftl"
-// destdir="${project.home}/view/layout"
-// foreach="entity"/>
-
- hbmtemplateAttributes = new HashMap<String, String>();
- hbmtemplateAttributes.put("file_pattern", "menu.xhtml");
//$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("template_name",
"view/layout/menu.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString()+"/layout");
//$NON-NLS-1$ //$NON-NLS-2$
- hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
- hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate9.properties", hbmtemplateAttributes); //$NON-NLS-1$
-
- //save before adding additional attribute
- wc.doSave();
-
- if (params.containsKey(HibernateLaunchConstants.ATTR_REVENG_TABLES)){
- //create reveng.xml file
- IPath revengPath =
project.getLocation().append(".settings").append("gen-entities.hibernate.reveng.xml");
//$NON-NLS-1$ //$NON-NLS-2$
- File location = revengPath.toFile();
- org.jboss.tools.common.util.FileUtil.writeFile(location,
params.get(HibernateLaunchConstants.ATTR_REVENG_TABLES).getValueAsString());
- wc.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
revengPath.toString());
- }
-
- launchManager.addLaunch(wc.launch(ILaunchManager.RUN_MODE, monitor));
-
- WebUtils.changeTimeStamp(project);
- } catch (CoreException e) {
- SeamCorePlugin.getDefault().showError(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_CAN_NOT_GENERATE_SEAM_ENTITIES,
e);
- }
- return Status.OK_STATUS;
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.tools.seam.ui.wizard.SeamBaseOperation#getFileMappings(java.util.Map)
- */
- @Override
- public List<FileMapping> getFileMappings(Map<String, Object> vars) {
-// throw new
UnsupportedOperationException(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_THIS_METHOD_IS_NOT_RELEVANT_IN_GENERATING_SEAM_ENTITIES);
- // Return empty list;
- return new ArrayList<FileMapping>();
- }
- };
-
- static SeamRuntime getRuntime(IProject project) {
- if(project==null) {
- return null;
- }
- SeamRuntime seamRt = SeamRuntimeManager.getInstance().getRuntimeForProject(project);
-
- String runtimeName = SeamCorePlugin.getSeamPreferences(project)
- .get(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME,""); //$NON-NLS-1$
-
- if(!"".equals(runtimeName)) { //$NON-NLS-1$
- seamRt = SeamRuntimeManager.getInstance().findRuntimeByName(runtimeName);
- }
- return seamRt;
- }
-
- @Override
- public boolean performFinish() {
- boolean result = super.performFinish();
- if (result){
- String ccName = page1.getConsoleCongigurationName();
- ConsoleConfiguration config = KnownConfigurations.getInstance().find(ccName);
- //fix for JBIDE-3599
- if (config != null) config.reset();
- }
- return result;
- }
-
-
-}
\ No newline at end of file
Deleted:
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 2009-08-04
08:17:02 UTC (rev 16955)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEnitiesWizardPage.java 2009-08-04
08:43:28 UTC (rev 16956)
@@ -1,319 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.ui.wizard;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jface.wizard.IWizardPage;
-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.console.ConsoleConfiguration;
-import org.hibernate.console.KnownConfigurations;
-import org.hibernate.eclipse.console.utils.ProjectUtils;
-import org.hibernate.eclipse.launch.HibernateLaunchConstants;
-import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.core.SeamProjectsSet;
-import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
-import org.jboss.tools.seam.internal.core.validation.SeamProjectPropertyValidator;
-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;
-import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
-import org.jboss.tools.seam.ui.widget.editor.INamedElement;
-import org.jboss.tools.seam.ui.widget.field.RadioField;
-
-/**
- * @author Alexey Kazakov
- */
-public class SeamGenerateEnitiesWizardPage extends WizardPage implements
PropertyChangeListener, IAdaptable {
-
- private IFieldEditor projectEditor;
- private IFieldEditor configEditor;
- private RadioField radios;
- IProject rootSeamProject;
-
- public SeamGenerateEnitiesWizardPage() {
- super("seam.generate.entities.page",
SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_TITLE, null); //$NON-NLS-1$
- setMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_PAGE_MESSAGE);
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
- public void createControl(Composite parent) {
- rootSeamProject = SeamWizardUtils.getCurrentSelectedRootSeamProject();
- String projectName = rootSeamProject==null?"":rootSeamProject.getName();
- projectEditor = SeamWizardFactory.createSeamProjectSelectionFieldEditor(projectName);
- projectEditor.addPropertyChangeListener(this);
- if(projectName!=null && projectName.length()>0) {
- Map<String, IStatus> errors =
ValidatorFactory.SEAM_PROJECT_NAME_VALIDATOR.validate(projectEditor.getValue(), null);
- if(!errors.isEmpty()) {
- IStatus message = errors.get(IValidator.DEFAULT_ERROR);
- if(message.getSeverity()==IStatus.ERROR) {
- setErrorMessage(message.getMessage());
- setPageComplete(false);
- } else {
- setMessage(message.getMessage());
- }
- } else {
- setMessage(null);
- }
- } else {
- setMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_PAGE_MESSAGE);
- setPageComplete(false);
- }
-
- Composite top = new GridLayoutComposite(parent);
- Composite projectComposite = new GridLayoutComposite(top, SWT.NONE, 4);
-
- projectEditor.doFillIntoGrid(projectComposite);
-
- configEditor =
SeamWizardFactory.createHibernateConsoleConfigurationSelectionFieldEditor(getConsoleConfigurationName(projectName));
- configEditor.addPropertyChangeListener(this);
- configEditor.doFillIntoGrid(projectComposite);
- configEditor.setEditable(false);
- configEditor.addPropertyChangeListener(this);
-
- String config = (String)configEditor.getValue();
- if(config==null || config.length()==0) {
- setMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_HIBERNATE_CONFIGURATION_MESSAGE);
- setPageComplete(false);
- }
-
- Composite groupComposite = new GridLayoutComposite(top);
- Group group = new Group(groupComposite, SWT.NONE);
- group.setText(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_GROUP_LABEL);
- group.setLayout(new GridLayout(1, false));
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- Composite radioComposite = new GridLayoutComposite(group, SWT.NONE, 2);
- ArrayList<Object> values = new ArrayList<Object>();
- values.add("reverse"); //$NON-NLS-1$
- values.add("existing"); //$NON-NLS-1$
- ArrayList<String> labels = new ArrayList<String>();
- labels.add(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_REVERSE_ENGINEER_LABEL);
- labels.add(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_EXISTING_ENTITIES_LABEL);
- radios = new RadioField(radioComposite, labels, values, null, true);
- radios.addPropertyChangeListener(this);
-
- setControl(top);
- validate();
- }
-
- private static String getConsoleConfigurationName(String seamWebProjectName) {
- if(seamWebProjectName==null || seamWebProjectName.trim().length()==0) {
- return null;
- }
- String seamProjectName = seamWebProjectName;
- IProject webProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(seamWebProjectName);
- if(webProject==null) {
- return null;
- }
- SeamProjectsSet projectSet = SeamProjectsSet.create(webProject);
- if(!projectSet.isWarConfiguration()) {
- IProject ejbProject = projectSet.getEjbProject();
- if(ejbProject==null) {
- return null;
- }
- seamProjectName = ejbProject.getName();
- }
- ConsoleConfiguration[] configs =
KnownConfigurations.getInstance().getConfigurations();
- for (int i = 0; i < configs.length; i++) {
- IJavaProject javaProject = ProjectUtils.findJavaProject(configs[i]);
- if(javaProject!=null &&
javaProject.getProject().getName().equals(seamProjectName)) {
- return configs[i].getName();
- }
- }
- return null;
- }
-
- public static class GridLayoutComposite extends Composite {
-
- public GridLayoutComposite(Composite parent, int style, int columnNumber) {
- super(parent, style);
- GridLayout gl = new GridLayout(columnNumber, false);
- setLayout(gl);
- setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- }
-
- public GridLayoutComposite(Composite parent) {
- this(parent, SWT.NONE, 1);
- }
- }
-
- /* (non-Javadoc)
- * @see
java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- if(IParameter.SEAM_PROJECT_NAME.equals(event.getPropertyName()) &&
- event.getNewValue()!=null &&
- !event.getNewValue().equals(event.getOldValue())) {
- String consoleConfigName =
getConsoleConfigurationName(event.getNewValue().toString());
- if(consoleConfigName!=null) {
- configEditor.setValue(consoleConfigName);
- }
- }
- validate();
- }
-
- protected boolean isProjectSettingsOk() {
- if(rootSeamProject!=null) {
- if(!isValidRuntimeConfigured(rootSeamProject)) {
- return false;
- }
- IEclipsePreferences prefs = SeamCorePlugin.getSeamPreferences(rootSeamProject);
- return
SeamProjectPropertyValidator.isFolderPathValid(prefs.get(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER,
""), false) &&
- SeamProjectPropertyValidator.isFolderPathValid(prefs.get(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER,
""), false) &&
- SeamProjectPropertyValidator.isFolderPathValid(prefs.get(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER,
""), false) &&
- (ISeamFacetDataModelProperties.DEPLOY_AS_WAR.equals(prefs.get(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,
ISeamFacetDataModelProperties.DEPLOY_AS_WAR).trim()) ||
SeamProjectPropertyValidator.isProjectNameValid(prefs.get(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT,
""), false));
- }
- return true;
- }
-
- /**
- * @param project
- */
- protected boolean isValidRuntimeConfigured(IProject project) {
- Map<String, IStatus> errors;
- String seamRt =
SeamCorePlugin.getSeamPreferences(project).get(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME,"");
//$NON-NLS-1$
- errors = ValidatorFactory.SEAM_RUNTIME_VALIDATOR.validate(seamRt, null);
- if(!errors.isEmpty()) {
- setErrorMessage(errors.get(IValidator.DEFAULT_ERROR).getMessage());
- setPageComplete(false);
- return false;
- }
- return true;
- }
-
- private void validate() {
- String projectName = projectEditor.getValue().toString();
- Map<String, IStatus> errors =
ValidatorFactory.SEAM_PROJECT_NAME_VALIDATOR.validate(projectName, null);
-
- if(!errors.isEmpty() || !isProjectSettingsOk()) {
- IStatus errorMessage = errors.get(IValidator.DEFAULT_ERROR);
- if(errorMessage==null) {
- setErrorMessage(SeamUIMessages.VALIDATOR_INVALID_SETTINGS);
- setPageComplete(false);
- } else {
- if(errorMessage.getSeverity()==IStatus.ERROR) {
- setErrorMessage(errorMessage.getMessage());
- setPageComplete(false);
- } else {
- setMessage(errorMessage.getMessage());
- }
- }
- return;
- }
- String config = (String)configEditor.getValue();
- if(config==null || config.length()==0) {
- setErrorMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_HIBERNATE_CONFIGURATION_ERROR);
- setPageComplete(false);
- return;
- }
-
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- SeamProjectsSet seamProjectsSet = SeamProjectsSet.create(project);
- IContainer viewsFolder = seamProjectsSet.getViewsFolder();
- if (viewsFolder != null){
- if (!viewsFolder.getFolder(new Path("layout")).exists()){//$NON-NLS-1$
- setErrorMessage(SeamUIMessages.bind(SeamUIMessages.VALIDATOR_FACTORY_FOLDER_DOES_NOT_EXIST,
- viewsFolder.getName() + "/layout"));//$NON-NLS-1$
- setPageComplete(false);
- return;
- }
- }
-
- setErrorMessage(null);
- setMessage(null);
- setPageComplete(true);
- }
-
- @SuppressWarnings("unchecked")
- public Object getAdapter(Class adapter) {
- if(adapter == Map.class) {
- Map<String, INamedElement> values = new HashMap<String, INamedElement>();
- values.put(projectEditor.getName(), new NamedElementImpl(projectEditor.getName(),
projectEditor.getValueAsString()));
- values.put(configEditor.getName(), new NamedElementImpl(configEditor.getName(),
configEditor.getValueAsString()));
- String mode = radios.getValue().toString();
- String value = "reverse".equals(mode) ? "true" :
"false"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- values.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, new
NamedElementImpl("reverse", value)); //$NON-NLS-1$
- IWizardPage page2 =
getWizard().getPage(SeamGenerateEntitiesTablesWizardPage.pageName);
- if (page2 instanceof SeamGenerateEntitiesTablesWizardPage){
- SeamGenerateEntitiesTablesWizardPage page =
(SeamGenerateEntitiesTablesWizardPage)page2;
- String filters = page.getFilters();
- if (filters.length() > 0) values.put(HibernateLaunchConstants.ATTR_REVENG_TABLES,
new NamedElementImpl("filters", filters)); //$NON-NLS-1$
- }
- return values;
- }
- return null;
- }
-
- class NamedElementImpl implements INamedElement {
-
- private String name;
- private Object value;
-
- public NamedElementImpl(String name, Object value) {
- this.name = name;
- this.value = value;
- }
-
- public String getName() {
- return name;
- }
-
- public Object getValue() {
- return value;
- }
-
- public String getValueAsString() {
- return value.toString();
- }
-
- public void setValue(Object newValue) {
- this.value = newValue;
- }
-
- public void setValueAsString(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return getValueAsString();
- }
- }
-
- @Override
- public boolean canFlipToNextPage() {
- return "reverse".equals(radios.getValue()) && (getErrorMessage() ==
null); //$NON-NLS-1$
- }
-
- public String getConsoleCongigurationName(){
- return configEditor.getValueAsString();
- }
-}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesTablesWizardPage.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesTablesWizardPage.java 2009-08-04
08:17:02 UTC (rev 16955)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesTablesWizardPage.java 2009-08-04
08:43:28 UTC (rev 16956)
@@ -63,7 +63,7 @@
//set console configuration as treeViewer input
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == SeamGenerateEntitiesTablesWizardPage.this){
- SeamGenerateEnitiesWizardPage page1 =
(SeamGenerateEnitiesWizardPage)getWizard().getPreviousPage(SeamGenerateEntitiesTablesWizardPage.this);
+ SeamGenerateEntitiesWizardPage page1 =
(SeamGenerateEntitiesWizardPage)getWizard().getPreviousPage(SeamGenerateEntitiesTablesWizardPage.this);
cfgName = page1.getConsoleCongigurationName();
}
}});
Copied:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesWizard.java
(from rev 16753,
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/SeamGenerateEntitiesWizard.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesWizard.java 2009-08-04
08:43:28 UTC (rev 16956)
@@ -0,0 +1,389 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.wizard;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+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.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.Status;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+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.jface.resource.ImageDescriptor;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.PlatformUI;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.jboss.tools.jst.web.WebUtils;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.SeamProjectsSet;
+import org.jboss.tools.seam.core.project.facet.SeamRuntime;
+import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
+import org.jboss.tools.seam.core.project.facet.SeamVersion;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+import org.jboss.tools.seam.ui.ISeamHelpContextIds;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.widget.editor.INamedElement;
+
+/**
+ * Seam Generate Entities Wizard.
+ * @author Alexey Kazakov
+ */
+public class SeamGenerateEntitiesWizard extends SeamBaseWizard implements INewWizard {
+
+ SeamGenerateEntitiesWizardPage page1 = new SeamGenerateEntitiesWizardPage();
+ IWizardPage page2 = new SeamGenerateEntitiesTablesWizardPage();
+
+ public void createPageControls(Composite pageContainer) {
+ super.createPageControls(pageContainer);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(pageContainer,
ISeamHelpContextIds.GENERATE_SEAM_ENTITIES);
+ }
+
+ public SeamGenerateEntitiesWizard() {
+ super(GENERATE_SEAM_ENTITIES);
+ setWindowTitle(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_TITLE);
+ setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(SeamGenerateEntitiesWizard.class,
"SeamWebProjectWizBan.png"));
+ addPage(page1);
+ addPage(page2);
+ }
+
+ @Override
+ public boolean canFinish() {
+ return page1.isPageComplete();
+ }
+
+ public static final IUndoableOperation GENERATE_SEAM_ENTITIES = new
SeamBaseOperation(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_ACTION_CREATING_OPERATION)
{
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.wizard.SeamBaseOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.core.runtime.IAdaptable)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws
ExecutionException {
+ Map<String, INamedElement> params = (Map<String,
INamedElement>)info.getAdapter(Map.class);
+ IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(params.get(IParameter.SEAM_PROJECT_NAME).getValueAsString());
+
+ try {
+
+ ISeamProject seamProject = (ISeamProject)project.getNature(ISeamProject.NATURE_ID);
+ boolean seam2 = seamProject.getRuntime().getVersion().compareTo(SeamVersion.SEAM_2_0)
>= 0;
+
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType launchConfigurationType =
+ launchManager.getLaunchConfigurationType("org.hibernate.eclipse.launch.CodeGenerationLaunchConfigurationType");
//$NON-NLS-1$
+ // we put null in location to avoid it being inside the project by default since the
launch config currenlty will be machine independent with respect to the paths.
+ launchConfigurationType.getAttribute("");
+ ILaunchConfigurationWorkingCopy wc =
+ launchConfigurationType.newInstance(null, project.getName() +
"-generate-entities"); //$NON-NLS-1$
+
+ //Main
+ wc.setAttribute(
+ HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
+ params.get(IParameter.HIBERNATE_CONFIGURATION_NAME).getValueAsString());
+
+ SeamProjectsSet seamProjectsSet = SeamProjectsSet.create(project);
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
+ seamProjectsSet.getModelFolder()==null?
+ "":seamProjectsSet.getModelFolder().getFullPath().toString());
//$NON-NLS-1$
+
+ boolean isReverseEngineer =
"true".equals(params.get(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER).getValueAsString());
//$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, isReverseEngineer);
+
+ if(isReverseEngineer) {
+ wc.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,
seamProjectsSet.getEntityPackage());
+ 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);
+
+ boolean seam21 =
seamProject.getRuntime().getVersion().compareTo(SeamVersion.SEAM_2_1) >= 0 ||
+ seamProject.getRuntime().getVersion().compareTo(SeamVersion.SEAM_2_2) >= 0;
+ // Only Seam 2.1 does not break when generating from one-to-one
+ wc.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_ONE_TO_ONE, seam21);
+ }
+
+ SeamRuntime seamRt = getRuntime(project);
+ if(seamRt==null) {
+ seamRt = getRuntime(project);
+ }
+ if(seamRt == null) {
+ throw new CoreException(new Status(IStatus.ERROR, SeamCorePlugin.PLUGIN_ID,
+ NLS.bind(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_CAN_NOT_FIND_SEAM_RUNTIME,
project.getName())));
+ }
+ String seamTemplatesRoot = seamRt.getTemplatesDir();
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR, seamTemplatesRoot);
+ wc.setAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES, true);
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5, true);
+ wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
+
+ // Create exporters
+ // TODO Add others exporters
+ List<String> exporters = new ArrayList<String>();
+
+ if(isReverseEngineer) {
+ exporters.add("hbmtemplate0"); //$NON-NLS-1$
+ }
+ exporters.add("hbmtemplate1"); //$NON-NLS-1$
+ exporters.add("hbmtemplate2"); //$NON-NLS-1$
+ exporters.add("hbmtemplate3"); //$NON-NLS-1$
+ exporters.add("hbmtemplate4"); //$NON-NLS-1$
+ exporters.add("hbmtemplate5"); //$NON-NLS-1$
+ exporters.add("hbmtemplate6"); //$NON-NLS-1$
+ exporters.add("hbmtemplate7"); //$NON-NLS-1$
+ exporters.add("hbmtemplate8"); //$NON-NLS-1$
+ exporters.add("hbmtemplate9"); //$NON-NLS-1$
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, exporters);
+
+ if(isReverseEngineer) {
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate0",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate0.extension_id", "org.hibernate.tools.hbm2java");
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate1",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate1.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate2",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate2.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate3",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate3.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate4",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate4.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate5",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate5.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate6",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate6.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate7",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate7.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate8",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate8.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + ".hbmtemplate9",
true); //$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate9.extension_id", "org.hibernate.tools.hbmtemplate");
//$NON-NLS-1$ //$NON-NLS-2$
+
+ Map<String, String> hbmtemplateAttributes = new HashMap<String,
String>();
+
+// <hbmtemplate filepattern="{class-name}List.xhtml"
+// template="view/list.xhtml.ftl"
+// destdir="${project.home}/view"
+// foreach="entity"/>
+
+ hbmtemplateAttributes.put("file_pattern",
"{class-name}List.xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("template_name",
"view/list.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",
seamProjectsSet.getViewsFolder().getFullPath().toString()); //$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity");
//$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass",SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_54);
//$NON-NLS-1$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate1.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="{class-name}.xhtml"
+// template="view/view.xhtml.ftl"
+// destdir="${project.home}/view"
+// foreach="entity"/>
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+ hbmtemplateAttributes.put("file_pattern", "{class-name}.xhtml");
//$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("template_name",
"view/view.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate2.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="{class-name}.page.xml"
+// template="view/view.page.xml.ftl"
+// destdir="${project.home}/view"
+// foreach="entity"/>
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+ hbmtemplateAttributes.put("file_pattern",
"{class-name}.page.xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("template_name",
"view/view.page.xml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate3.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="{class-name}Edit.xhtml"
+// template="view/edit.xhtml.ftl"
+// destdir="${project.home}/view"
+// foreach="entity"/>
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+ hbmtemplateAttributes.put("file_pattern",
"{class-name}Edit.xhtml"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("template_name",
"view/edit.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate4.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="{class-name}Edit.page.xml"
+// template="view/edit.page.xml.ftl"
+// destdir="${project.home}/view"
+// foreach="entity"/>
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+ hbmtemplateAttributes.put("file_pattern",
"{class-name}Edit.page.xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("template_name",
"view/edit.page.xml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate5.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="{package-name}/{class-name}List.java"
+// template="src/EntityList.java.ftl"
+// destdir="${project.home}/src"
+// foreach="entity"/>
+
+ IEclipsePreferences seamFacetPrefs = SeamCorePlugin.getSeamPreferences(project);
+ final String actionpackage =
seamFacetPrefs.get(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME,
"");
+ final String actionDir = actionpackage.replace('.','/');
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+
+ if(seam2) {
+ //Seam2: <property key="actionPackage"
value="${action.package}" />
+ hbmtemplateAttributes.put("actionPackage",actionpackage); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("file_pattern", actionDir +
"/{class-name}List.java"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ hbmtemplateAttributes.put("file_pattern",
"{package-name}/{class-name}List.java"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ hbmtemplateAttributes.put("template_name",
"src/EntityList.java.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getActionFolder().getFullPath().toString());
//$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate6.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="{class-name}List.page.xml"
+// template="view/list.page.xml.ftl"
+// destdir="${project.home}/view"
+// foreach="entity"/>
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+ hbmtemplateAttributes.put("file_pattern",
"{class-name}List.page.xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("template_name",
"view/list.page.xml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString());
//$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate7.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="{package-name}/{class-name}Home.java"
+// template="src/EntityHome.java.ftl"
+// destdir="${project.home}/src"
+// foreach="entity"/>
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+ if(seam2) {
+ //Seam2: <property key="actionPackage"
value="${action.package}" />
+ hbmtemplateAttributes.put("actionPackage",actionpackage); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("file_pattern", actionDir +
"/{class-name}Home.java"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ hbmtemplateAttributes.put("file_pattern",
"{package-name}/{class-name}Home.java"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ hbmtemplateAttributes.put("template_name",
"src/EntityHome.java.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getActionFolder().getFullPath().toString());
//$NON-NLS-1$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate8.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+// <hbmtemplate filepattern="menu.xhtml"
+// template="view/layout/menu.xhtml.ftl"
+// destdir="${project.home}/view/layout"
+// foreach="entity"/>
+
+ hbmtemplateAttributes = new HashMap<String, String>();
+ hbmtemplateAttributes.put("file_pattern", "menu.xhtml");
//$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("template_name",
"view/layout/menu.xhtml.ftl"); //$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("outputdir",seamProjectsSet.getViewsFolder().getFullPath().toString()+"/layout");
//$NON-NLS-1$ //$NON-NLS-2$
+ hbmtemplateAttributes.put("for_each", "entity"); //$NON-NLS-1$
//$NON-NLS-2$
+ hbmtemplateAttributes.put("hibernatetool.util.toolclass","org.hibernate.eclipse.launch.SeamUtil");
//$NON-NLS-1$ //$NON-NLS-2$
+ wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS +
".hbmtemplate9.properties", hbmtemplateAttributes); //$NON-NLS-1$
+
+ //save before adding additional attribute
+ wc.doSave();
+
+ if (params.containsKey(HibernateLaunchConstants.ATTR_REVENG_TABLES)){
+ //create reveng.xml file
+ IPath revengPath =
project.getLocation().append(".settings").append("gen-entities.hibernate.reveng.xml");
//$NON-NLS-1$ //$NON-NLS-2$
+ File location = revengPath.toFile();
+ org.jboss.tools.common.util.FileUtil.writeFile(location,
params.get(HibernateLaunchConstants.ATTR_REVENG_TABLES).getValueAsString());
+ wc.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
revengPath.toString());
+ }
+
+ launchManager.addLaunch(wc.launch(ILaunchManager.RUN_MODE, monitor));
+
+ WebUtils.changeTimeStamp(project);
+ } catch (CoreException e) {
+ SeamCorePlugin.getDefault().showError(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_CAN_NOT_GENERATE_SEAM_ENTITIES,
e);
+ }
+ return Status.OK_STATUS;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.ui.wizard.SeamBaseOperation#getFileMappings(java.util.Map)
+ */
+ @Override
+ public List<FileMapping> getFileMappings(Map<String, Object> vars) {
+// throw new
UnsupportedOperationException(SeamUIMessages.SEAM_GENERATE_ENTITIES_WIZARD_THIS_METHOD_IS_NOT_RELEVANT_IN_GENERATING_SEAM_ENTITIES);
+ // Return empty list;
+ return new ArrayList<FileMapping>();
+ }
+ };
+
+ static SeamRuntime getRuntime(IProject project) {
+ if(project==null) {
+ return null;
+ }
+ SeamRuntime seamRt = SeamRuntimeManager.getInstance().getRuntimeForProject(project);
+
+ String runtimeName = SeamCorePlugin.getSeamPreferences(project)
+ .get(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME,""); //$NON-NLS-1$
+
+ if(!"".equals(runtimeName)) { //$NON-NLS-1$
+ seamRt = SeamRuntimeManager.getInstance().findRuntimeByName(runtimeName);
+ }
+ return seamRt;
+ }
+
+ @Override
+ public boolean performFinish() {
+ boolean result = super.performFinish();
+ if (result){
+ String ccName = page1.getConsoleCongigurationName();
+ ConsoleConfiguration config = KnownConfigurations.getInstance().find(ccName);
+ //fix for JBIDE-3599
+ if (config != null) config.reset();
+ }
+ return result;
+ }
+
+
+}
\ No newline at end of file
Copied:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesWizardPage.java
(from rev 16955,
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/SeamGenerateEntitiesWizardPage.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamGenerateEntitiesWizardPage.java 2009-08-04
08:43:28 UTC (rev 16956)
@@ -0,0 +1,319 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.wizard;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jface.wizard.IWizardPage;
+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.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.SeamProjectsSet;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+import org.jboss.tools.seam.internal.core.validation.SeamProjectPropertyValidator;
+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;
+import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
+import org.jboss.tools.seam.ui.widget.editor.INamedElement;
+import org.jboss.tools.seam.ui.widget.field.RadioField;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamGenerateEntitiesWizardPage extends WizardPage implements
PropertyChangeListener, IAdaptable {
+
+ private IFieldEditor projectEditor;
+ private IFieldEditor configEditor;
+ private RadioField radios;
+ IProject rootSeamProject;
+
+ public SeamGenerateEntitiesWizardPage() {
+ super("seam.generate.entities.page",
SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_TITLE, null); //$NON-NLS-1$
+ setMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_PAGE_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ rootSeamProject = SeamWizardUtils.getCurrentSelectedRootSeamProject();
+ String projectName = rootSeamProject==null?"":rootSeamProject.getName();
+ projectEditor = SeamWizardFactory.createSeamProjectSelectionFieldEditor(projectName);
+ projectEditor.addPropertyChangeListener(this);
+ if(projectName!=null && projectName.length()>0) {
+ Map<String, IStatus> errors =
ValidatorFactory.SEAM_PROJECT_NAME_VALIDATOR.validate(projectEditor.getValue(), null);
+ if(!errors.isEmpty()) {
+ IStatus message = errors.get(IValidator.DEFAULT_ERROR);
+ if(message.getSeverity()==IStatus.ERROR) {
+ setErrorMessage(message.getMessage());
+ setPageComplete(false);
+ } else {
+ setMessage(message.getMessage());
+ }
+ } else {
+ setMessage(null);
+ }
+ } else {
+ setMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_PAGE_MESSAGE);
+ setPageComplete(false);
+ }
+
+ Composite top = new GridLayoutComposite(parent);
+ Composite projectComposite = new GridLayoutComposite(top, SWT.NONE, 4);
+
+ projectEditor.doFillIntoGrid(projectComposite);
+
+ configEditor =
SeamWizardFactory.createHibernateConsoleConfigurationSelectionFieldEditor(getConsoleConfigurationName(projectName));
+ configEditor.addPropertyChangeListener(this);
+ configEditor.doFillIntoGrid(projectComposite);
+ configEditor.setEditable(false);
+ configEditor.addPropertyChangeListener(this);
+
+ String config = (String)configEditor.getValue();
+ if(config==null || config.length()==0) {
+ setMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_HIBERNATE_CONFIGURATION_MESSAGE);
+ setPageComplete(false);
+ }
+
+ Composite groupComposite = new GridLayoutComposite(top);
+ Group group = new Group(groupComposite, SWT.NONE);
+ group.setText(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_GROUP_LABEL);
+ group.setLayout(new GridLayout(1, false));
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Composite radioComposite = new GridLayoutComposite(group, SWT.NONE, 2);
+ ArrayList<Object> values = new ArrayList<Object>();
+ values.add("reverse"); //$NON-NLS-1$
+ values.add("existing"); //$NON-NLS-1$
+ ArrayList<String> labels = new ArrayList<String>();
+ labels.add(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_REVERSE_ENGINEER_LABEL);
+ labels.add(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_EXISTING_ENTITIES_LABEL);
+ radios = new RadioField(radioComposite, labels, values, null, true);
+ radios.addPropertyChangeListener(this);
+
+ setControl(top);
+ validate();
+ }
+
+ private static String getConsoleConfigurationName(String seamWebProjectName) {
+ if(seamWebProjectName==null || seamWebProjectName.trim().length()==0) {
+ return null;
+ }
+ String seamProjectName = seamWebProjectName;
+ IProject webProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(seamWebProjectName);
+ if(webProject==null) {
+ return null;
+ }
+ SeamProjectsSet projectSet = SeamProjectsSet.create(webProject);
+ if(!projectSet.isWarConfiguration()) {
+ IProject ejbProject = projectSet.getEjbProject();
+ if(ejbProject==null) {
+ return null;
+ }
+ seamProjectName = ejbProject.getName();
+ }
+ ConsoleConfiguration[] configs =
KnownConfigurations.getInstance().getConfigurations();
+ for (int i = 0; i < configs.length; i++) {
+ IJavaProject javaProject = ProjectUtils.findJavaProject(configs[i]);
+ if(javaProject!=null &&
javaProject.getProject().getName().equals(seamProjectName)) {
+ return configs[i].getName();
+ }
+ }
+ return null;
+ }
+
+ public static class GridLayoutComposite extends Composite {
+
+ public GridLayoutComposite(Composite parent, int style, int columnNumber) {
+ super(parent, style);
+ GridLayout gl = new GridLayout(columnNumber, false);
+ setLayout(gl);
+ setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ }
+
+ public GridLayoutComposite(Composite parent) {
+ this(parent, SWT.NONE, 1);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if(IParameter.SEAM_PROJECT_NAME.equals(event.getPropertyName()) &&
+ event.getNewValue()!=null &&
+ !event.getNewValue().equals(event.getOldValue())) {
+ String consoleConfigName =
getConsoleConfigurationName(event.getNewValue().toString());
+ if(consoleConfigName!=null) {
+ configEditor.setValue(consoleConfigName);
+ }
+ }
+ validate();
+ }
+
+ protected boolean isProjectSettingsOk() {
+ if(rootSeamProject!=null) {
+ if(!isValidRuntimeConfigured(rootSeamProject)) {
+ return false;
+ }
+ IEclipsePreferences prefs = SeamCorePlugin.getSeamPreferences(rootSeamProject);
+ return
SeamProjectPropertyValidator.isFolderPathValid(prefs.get(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER,
""), false) &&
+ SeamProjectPropertyValidator.isFolderPathValid(prefs.get(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER,
""), false) &&
+ SeamProjectPropertyValidator.isFolderPathValid(prefs.get(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER,
""), false) &&
+ (ISeamFacetDataModelProperties.DEPLOY_AS_WAR.equals(prefs.get(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,
ISeamFacetDataModelProperties.DEPLOY_AS_WAR).trim()) ||
SeamProjectPropertyValidator.isProjectNameValid(prefs.get(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT,
""), false));
+ }
+ return true;
+ }
+
+ /**
+ * @param project
+ */
+ protected boolean isValidRuntimeConfigured(IProject project) {
+ Map<String, IStatus> errors;
+ String seamRt =
SeamCorePlugin.getSeamPreferences(project).get(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME,"");
//$NON-NLS-1$
+ errors = ValidatorFactory.SEAM_RUNTIME_VALIDATOR.validate(seamRt, null);
+ if(!errors.isEmpty()) {
+ setErrorMessage(errors.get(IValidator.DEFAULT_ERROR).getMessage());
+ setPageComplete(false);
+ return false;
+ }
+ return true;
+ }
+
+ private void validate() {
+ String projectName = projectEditor.getValue().toString();
+ Map<String, IStatus> errors =
ValidatorFactory.SEAM_PROJECT_NAME_VALIDATOR.validate(projectName, null);
+
+ if(!errors.isEmpty() || !isProjectSettingsOk()) {
+ IStatus errorMessage = errors.get(IValidator.DEFAULT_ERROR);
+ if(errorMessage==null) {
+ setErrorMessage(SeamUIMessages.VALIDATOR_INVALID_SETTINGS);
+ setPageComplete(false);
+ } else {
+ if(errorMessage.getSeverity()==IStatus.ERROR) {
+ setErrorMessage(errorMessage.getMessage());
+ setPageComplete(false);
+ } else {
+ setMessage(errorMessage.getMessage());
+ }
+ }
+ return;
+ }
+ String config = (String)configEditor.getValue();
+ if(config==null || config.length()==0) {
+ setErrorMessage(SeamUIMessages.GENERATE_SEAM_ENTITIES_WIZARD_HIBERNATE_CONFIGURATION_ERROR);
+ setPageComplete(false);
+ return;
+ }
+
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ SeamProjectsSet seamProjectsSet = SeamProjectsSet.create(project);
+ IContainer viewsFolder = seamProjectsSet.getViewsFolder();
+ if (viewsFolder != null){
+ if (!viewsFolder.getFolder(new Path("layout")).exists()){//$NON-NLS-1$
+ setErrorMessage(SeamUIMessages.bind(SeamUIMessages.VALIDATOR_FACTORY_FOLDER_DOES_NOT_EXIST,
+ viewsFolder.getName() + "/layout"));//$NON-NLS-1$
+ setPageComplete(false);
+ return;
+ }
+ }
+
+ setErrorMessage(null);
+ setMessage(null);
+ setPageComplete(true);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter) {
+ if(adapter == Map.class) {
+ Map<String, INamedElement> values = new HashMap<String, INamedElement>();
+ values.put(projectEditor.getName(), new NamedElementImpl(projectEditor.getName(),
projectEditor.getValueAsString()));
+ values.put(configEditor.getName(), new NamedElementImpl(configEditor.getName(),
configEditor.getValueAsString()));
+ String mode = radios.getValue().toString();
+ String value = "reverse".equals(mode) ? "true" :
"false"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ values.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, new
NamedElementImpl("reverse", value)); //$NON-NLS-1$
+ IWizardPage page2 =
getWizard().getPage(SeamGenerateEntitiesTablesWizardPage.pageName);
+ if (page2 instanceof SeamGenerateEntitiesTablesWizardPage){
+ SeamGenerateEntitiesTablesWizardPage page =
(SeamGenerateEntitiesTablesWizardPage)page2;
+ String filters = page.getFilters();
+ if (filters.length() > 0) values.put(HibernateLaunchConstants.ATTR_REVENG_TABLES,
new NamedElementImpl("filters", filters)); //$NON-NLS-1$
+ }
+ return values;
+ }
+ return null;
+ }
+
+ class NamedElementImpl implements INamedElement {
+
+ private String name;
+ private Object value;
+
+ public NamedElementImpl(String name, Object value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public String getValueAsString() {
+ return value.toString();
+ }
+
+ public void setValue(Object newValue) {
+ this.value = newValue;
+ }
+
+ public void setValueAsString(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return getValueAsString();
+ }
+ }
+
+ @Override
+ public boolean canFlipToNextPage() {
+ return "reverse".equals(radios.getValue()) && (getErrorMessage() ==
null); //$NON-NLS-1$
+ }
+
+ public String getConsoleCongigurationName(){
+ return configEditor.getValueAsString();
+ }
+}
\ No newline at end of file