/***************************************************************************
* Copyright (c) 2004 - 2008 Fabrizio Boco fabboco@users.sourceforge.net *
* *
* *
* This is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License (version 2.1) as published by the Free Software Foundation *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
/**
- $Header: /usr/local/cvslocalrepository/EJB3PlugIn/src/boco/ejb3PlugIn/popup/actions/bean/Attic/NewEJBSon.java,v 1.1.2.6 2008/06/02 20:04:33 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.6 $
- $Date: 2008/06/02 20:04:33 $
- $Log: NewEJBSon.java,v $
- Revision 1.1.2.6 2008/06/02 20:04:33 fab
- Eliminate System.out
-
- Revision 1.1.2.5 2008/05/05 12:12:06 fab
- *** empty log message ***
-
- Revision 1.1.2.4 2008/05/05 11:57:49 fab
- Indirizzo di posta errato
- Errata formattazione dei nuovi bean creati
-
- Revision 1.1.2.3 2008/04/22 06:17:38 fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.2 2008/04/19 10:26:49 fab
- Aggiornamento riferimenti licenza
-
- Revision 1.1.2.1 2008/03/28 18:44:26 fab
- Refactoring delle azioni
- Internazionalizzazione di tutte le voci di menu
-
- Revision 1.3.2.12 2008/03/26 12:03:27 fab
- *** empty log message ***
-
- Revision 1.3.2.11 2007/11/04 20:56:14 fab
- Review Interfaccia
-
- Revision 1.3.2.10 2007/04/30 16:10:47 dev
- *** empty log message ***
-
- Revision 1.3.2.9 2007/03/25 21:33:11 dev
- Modifica interfaccia per supportare le liste multiple e la security dei bean
-
- Revision 1.3.2.8 2007/02/13 09:59:12 dev
- Modifica alla equals del bean
-
- Revision 1.3.2.7 2007/01/07 14:38:20 dev
- Modifiche Dicembre 2006
-
- Revision 1.3.2.6 2006/12/25 11:10:18 dev
- Introdotta gestione degli errori
- Fix per le relazioni N:M che avevano l'ownership invertita
-
- Revision 1.3.2.5 2006/12/24 16:15:57 dev
- Acquisito il nome della relazione per le relazioni N:M
-
- Revision 1.3.2.4 2006/12/17 16:15:35 dev
- Riorganizzata la classe Utils che era divisia in due !?
-
- Revision 1.3.2.3 2006/12/03 19:06:26 dev
- Modifica per supportare bean ereditati in modo corretto anche su seam
-
- Revision 1.3.2.2 2006/12/03 10:30:28 dev
- Modifica per supportare bean ereditati in modo corretto anche su seam
-
- Revision 1.3.2.1 2006/08/28 08:48:49 dev
- Modifiche principli per il supporto di seam
-
- Revision 1.3 2006/05/21 13:41:18 dev
- Corretta annotazione cvs
-
**/
package boco.ejb3PlugIn.popup.actions.bean;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import boco.ejb3PlugIn.gui.ErrorMessageDialog;
import boco.ejb3PlugIn.gui.BeanDialog;
import boco.ejb3PlugIn.utils.Utils;
public class NewEJBSon implements IObjectActionDelegate
{
private IJavaProject javaProject;
private ICompilationUnit iCompilationUnit;
public NewEJBSon()
{
super();
}
public void setActivePart(IAction action, IWorkbenchPart targetPart)
{
}
public void run(IAction action)
{
Shell shell = new Shell();
try
{
/*
ASTParser parser = ASTParser.newParser(AST.JLS3); // handles JDK 1.0, 1.1, 1.2, 1.3, 1.4, 1.5
parser.setSource(iCompilationUnit.getSource().toCharArray());
CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
*/
if (!iCompilationUnit.getSource().contains("@Inheritance"))
{
MessageDialog.openInformation(shell, "EJB_PlugIn Plug-in", "Una BEAN figlio può essere creato solo a partire da un bean PADRE");
return;
}
IPackageFragment entityPackage = (IPackageFragment) iCompilationUnit.getParent();
BeanDialog beanDialog = new BeanDialog(javaProject.getProject().getLocation().toOSString());
beanDialog.pack();
beanDialog.setLocationRelativeTo(null);
beanDialog.setVisible(true);
String beanName = Utils.makeFirstLetterUpperCase(beanDialog.getBeanName());
if ((beanName != null) && (!beanName.equals("")))
{
String sourceCode = "/*****************************************************************************\r\n";
sourceCode += "* Copyright (c) 2006 - 2008 Fabrizio Boco <fabboco@users.sourceforge.net> *\r\n";
sourceCode += "* *\r\n";
sourceCode += "* This file is generated with SeamWebAppGen. *\r\n";
sourceCode += "* *\r\n";
sourceCode += "* This library is free software; you can redistribute it and/or *\r\n";
sourceCode += "* modify it under the terms of the GNU Library General Public *\r\n";
sourceCode += "* License as published by the Free Software Foundation; either *\r\n";
sourceCode += "* version 2 of the License, or (at your option) any later version. *\r\n";
sourceCode += "* *\r\n";
sourceCode += "* This library is distributed in the hope that it will be useful, *\r\n";
sourceCode += "* but WITHOUT ANY WARRANTY; without even the implied warranty of *\r\n";
sourceCode += "* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *\r\n";
sourceCode += "* GNU Library General Public License for more details. *\r\n";
sourceCode += "* *\r\n";
sourceCode += "* You should have received a copy of the GNU Library General Public *\r\n";
sourceCode += "* License along with this library; see the file COPYING.LIB. If not, *\r\n";
sourceCode += "* write to the Free Software Foundation, Inc., 59 Temple Place, *\r\n";
sourceCode += "* Suite 330, Boston, MA 02111-1307, USA *\r\n";
sourceCode += "* *\r\n";
sourceCode += "******************************************************************************/\r\n";
sourceCode += "\r\n\r\n";
sourceCode += "/**\r\n";
sourceCode += "- $"+"Header: $\r\n";
sourceCode += "- $"+"Author: $\r\n";
sourceCode += "- $"+"Revision: $\r\n";
sourceCode += "- $"+"Date: $\r\n";
sourceCode += "\r\n\r\n";
sourceCode += "- $"+"Log: $\r\n";
sourceCode += "**/\r\n";
sourceCode += "\r\n\r\n";
sourceCode += "package " + entityPackage.getElementName() + ";\r\n";
sourceCode += "\r\n";
sourceCode += "\r\n";
sourceCode += "import javax.persistence.Entity;\r\n";
sourceCode += "import javax.persistence.DiscriminatorValue;\r\n";
sourceCode += "import javax.persistence.Transient;\r\n";
sourceCode += "import org.boco.seamwebappgen.annotations.Security;\r\n";
sourceCode += "import org.boco.seamwebappgen.annotations.ShowList;\r\n";
sourceCode += "import org.jboss.seam.annotations.Name;\r\n";
sourceCode += "import org.jboss.seam.annotations.Scope;\r\n";
sourceCode += "import static org.jboss.seam.ScopeType.CONVERSATION;\r\n";
// System.out.println(iCompilationUnit.getElementName());
sourceCode += "@Entity\r\n";
sourceCode += "@Name(\""+Utils.makeFirstLetterLowerCase(beanName)+"\")\r\n";
sourceCode += "@Scope(CONVERSATION)\r\n";
sourceCode += "@DiscriminatorValue(\"" + beanName + "\")\r\n";
sourceCode += Utils.makeShowListAnnotation(beanDialog).replace(" = ", "=").replace(", ", ",").replace("\r", "").replace("\n", "")+"\r\n";
sourceCode += Utils.makeSecurityAnnotation(beanDialog).replace(" = ", "=").replace(", ", ",").replace("\r", "").replace("\n", "")+"\r\n";
// sourceCode += "@ShowList(names = {"+beanDialog.getViewNames()+"}, filters={"+beanDialog.getFilters()+"}, enabledRoles={"+beanDialog.getEnableRoles()+"}, mains={"+beanDialog.getMain()+"}, newMenuOptionConditions={"+beanDialog.getNewMenuOptionConditions()+"}, printMenuOptionConditionsInList={"+beanDialog.getprintMenuOptionConditionsInList()+"})\r\n";
// sourceCode += "@Security(";
//
// if (!beanDialog.getCreateEnabledRoles().equals(""))
// {
// sourceCode += "rolesEnabledToCreate={"+beanDialog.getCreateEnabledRoles()+"}, ";
// }
// else
// {
// sourceCode += "createCondition=\"#{"+beanDialog.getCreateCondition()+"}\", ";
// }
//
// if (!beanDialog.getEditEnabledRoles().equals(""))
// {
// sourceCode += "rolesEnabledToEdit={"+beanDialog.getEditEnabledRoles()+"}, ";
// }
// else
// {
// sourceCode += "editCondition=\"#{"+beanDialog.getEditCondition()+"}\", ";
// }
//
// if (!beanDialog.getDeleteEnabledRoles().equals(""))
// {
// sourceCode += "rolesEnabledToDelete={"+beanDialog.getDeleteEnabledRoles()+"} ";
// }
// else
// {
// sourceCode += "deleteCondition=\"#{"+beanDialog.getDeleteCondition()+"}\" ";
// }
//
// sourceCode += ")\r\n";
sourceCode += "public class " + beanName + " extends " + iCompilationUnit.getElementName().substring(0, iCompilationUnit.getElementName().length() - 5) + "\r\n";
sourceCode += "{\r\n";
sourceCode += "}\r\n";
ICompilationUnit icu = entityPackage.createCompilationUnit(beanName + ".java", sourceCode, false, null);
IType type = icu.getType(beanName);
type.createField("private static final long serialVersionUID = 0;", null, true, null);
String getSerialVersionUID = "\r\n";
getSerialVersionUID = "@Transient\r\n";
getSerialVersionUID += "public static long getSerialVersionUID()\r\n";
getSerialVersionUID += "{\r\n";
getSerialVersionUID += "\treturn serialVersionUID;\r\n";
getSerialVersionUID += "}\r\n";
type.createMethod(getSerialVersionUID, null, true, null);
String equals = "";
equals += "\r\n\r\npublic boolean equals(Object obj)\r\n";
equals += "{\r\n";
equals += "\tif (obj==null)\r\n";
equals += "\t\treturn false;\r\n\r\n";
equals += "\tif (!(obj instanceof " + beanName + "))\r\n";
equals += "\t\treturn false;\r\n\r\n";
equals += "\t" + beanName + " tmp = (" + beanName + ") obj;\r\n";
equals += "\t\r\n";
equals += "\tif (this.getId() != null && tmp.getId() != null && this.getId().longValue() == tmp.getId().longValue())\r\n";
equals += "\t\treturn true;\r\n";
equals += "\t\r\n";
equals += "\treturn false;\r\n";
equals += "}\r\n";
type.createMethod(equals, null, true, null);
icu.save(null, true);
}
}
catch (Exception e)
{
ErrorMessageDialog errorMessageDialog = new ErrorMessageDialog(e.getMessage());
errorMessageDialog.pack();
errorMessageDialog.setLocationRelativeTo(null);
errorMessageDialog.setVisible(true);
}
}
public void selectionChanged(IAction action, ISelection selection)
{
StructuredSelection structSelection = (StructuredSelection) selection;
// System.out.println("Class " + structSelection.getFirstElement().getClass());
if (structSelection.getFirstElement().getClass().equals(org.eclipse.jdt.internal.core.CompilationUnit.class))
{
iCompilationUnit = (ICompilationUnit) structSelection.getFirstElement();
javaProject = iCompilationUnit.getJavaProject();
}
}
}