Package boco.ejb3PlugIn.popup.actions.bean

Source Code of boco.ejb3PlugIn.popup.actions.bean.NewEJBFather

/***************************************************************************
* 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/NewEJBFather.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: NewEJBFather.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.15  2008/03/26 12:03:27  fab
- *** empty log message ***
-
- Revision 1.3.2.14  2007/11/05 13:32:32  fab
- *** empty log message ***
-
- Revision 1.3.2.13  2007/11/05 13:31:16  fab
- Modifica delle annotazioni relative ai bean
- @ShowLists
- @Security
-
- Revision 1.3.2.12  2007/11/04 20:57:33  fab
- *** empty log message ***
-
- Revision 1.3.2.11  2007/11/04 20:56:14  fab
- Review Interfaccia
-
- Revision 1.3.2.10  2007/03/25 21:33:11  dev
- Modifica interfaccia per supportare le liste multiple e la security dei bean
-
- Revision 1.3.2.9  2007/02/13 09:59:12  dev
- Modifica alla equals del bean
-
- Revision 1.3.2.8  2007/01/07 14:38:20  dev
- Modifiche Dicembre 2006
-
- Revision 1.3.2.7  2007/01/03 11:36:05  dev
- Inseriti disclaymer e tag cvs
-
- Revision 1.3.2.6  2007/01/03 10:39:10  dev
- I Bean sono creati nella CONVERSATION
-
- Revision 1.3.2.5  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.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.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 NewEJBFather implements IObjectActionDelegate
{

  private IJavaProject      javaProject;
  private IPackageFragment  packageFragment;

  public NewEJBFather()
  {
    super();
  }

  public void setActivePart(IAction action, IWorkbenchPart targetPart)
  {
  }

  public void run(IAction action)
  {
    Shell shell = new Shell();

    try
    {
      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("")))
      {
        // System.out.println("Creazione del bean  " + beanName + " nel package " + packageFragment.getElementName() + " del progetto " + javaProject.getElementName());

        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 " + packageFragment.getElementName() + ";\r\n";
        sourceCode += "\r\n";
        sourceCode += "\r\n";

        sourceCode += "import javax.persistence.Entity;\r\n";
        sourceCode += "import javax.persistence.Table;\r\n";
        sourceCode += "import javax.persistence.Transient;\r\n";
        sourceCode += "import javax.persistence.Id;\r\n";
        sourceCode += "import javax.persistence.GeneratedValue;\r\n";
        sourceCode += "import javax.persistence.GenerationType;\r\n";
        sourceCode += "import java.io.Serializable;\r\n";
        sourceCode += "import javax.persistence.Inheritance;\r\n";
        sourceCode += "import javax.persistence.InheritanceType;\r\n";
        sourceCode += "import javax.persistence.DiscriminatorColumn;\r\n";
        sourceCode += "import javax.persistence.DiscriminatorType;\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";
       

        sourceCode += "\r\n";
        sourceCode += "\r\n";
        sourceCode += "@Entity\r\n";
        sourceCode += "@Name(\""+Utils.makeFirstLetterLowerCase(beanName)+"\")\r\n";
        sourceCode += "@Scope(CONVERSATION)\r\n";       
        sourceCode += "@Table(name = \"" + beanName + "\")\r\n";
        sourceCode += "@Inheritance(strategy=InheritanceType.SINGLE_TABLE)\r\n";
        sourceCode += "@DiscriminatorColumn(name=\"type\", discriminatorType=DiscriminatorType.STRING)\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 + " implements Serializable\r\n";
        sourceCode += "{\r\n";
        sourceCode += "}\r\n";

        ICompilationUnit icu = packageFragment.createCompilationUnit(beanName + ".java", sourceCode, false, null);

        IType type = icu.getType(beanName);

        type.createField("private static final long     serialVersionUID = 0;", null, true, null);
        type.createField("private Long                  id;", 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 getId = "";
        getId += "\r\n\r\n@Id\r\n";
        getId += "@GeneratedValue(strategy=GenerationType.AUTO)\r\n";
        getId += "public Long getId()\r\n";
        getId += "{\r\n";
        getId += "\treturn id;\r\n";
        getId += "}\r\n";
        type.createMethod(getId, null, true, null);

        String setId = "";
        setId += "\r\n\r\npublic void setId(Long id)\r\n";
        setId += "{\r\n";
        setId += "\tthis.id=id;\r\n";
        setId += "}\r\n";
        type.createMethod(setId, 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 (id != null && tmp.getId() != null && id.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.PackageFragment.class))
    {
      packageFragment = (IPackageFragment) structSelection.getFirstElement();
      javaProject = packageFragment.getJavaProject();
    }
  }
}
TOP

Related Classes of boco.ejb3PlugIn.popup.actions.bean.NewEJBFather

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.