Package boco.ejb3PlugIn.popup.actions.bean

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

/***************************************************************************
* 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/NewEJB.java,v 1.1.2.9 2008/05/05 12:12:06 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.9 $
- $Date: 2008/05/05 12:12:06 $
- $Log: NewEJB.java,v $
- Revision 1.1.2.9  2008/05/05 12:12:06  fab
- *** empty log message ***
-
- Revision 1.1.2.8  2008/05/05 11:57:49  fab
- Indirizzo di posta errato
- Errata formattazione dei nuovi bean creati
-
- Revision 1.1.2.7  2008/04/22 17:09:22  fab
- *** empty log message ***
-
- Revision 1.1.2.6  2008/04/22 06:17:38  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.5  2008/04/19 11:21:02  fab
- Modifiche a seguito del refactoring del generatore
-
- Revision 1.1.2.4  2008/04/19 10:28:43  fab
- *** empty log message ***
-
- Revision 1.1.2.3  2008/04/19 10:26:49  fab
- Aggiornamento riferimenti licenza
-
- Revision 1.1.2.2  2008/03/30 15:37:11  fab
-  Fix 0671/B
-
- Revision 1.1.2.1  2008/03/28 18:44:26  fab
- Refactoring delle azioni
- Internazionalizzazione di tutte le voci di menu
-
- Revision 1.5.2.21  2008/03/26 12:03:27  fab
- *** empty log message ***
-
- Revision 1.5.2.20  2008/02/22 07:16:14  fab
- *** empty log message ***
-
- Revision 1.5.2.19  2007/11/07 10:19:28  fab
- Fix vari
- Gestione errori
-
- Revision 1.5.2.18  2007/11/04 20:56:14  fab
- Review Interfaccia
-
- Revision 1.5.2.17  2007/10/01 15:16:05  fab
- Aggiornata dialog per la creazione del bean
- Riletta l'annotazione @ShowInForm
-
- Revision 1.5.2.16  2007/09/29 20:13:10  fab
- Fix del bug 0122/B
-
- Revision 1.5.2.15  2007/03/27 06:25:53  dev
- Completata gestione dei ruoli sulle azioni del bean
-
- Revision 1.5.2.14  2007/03/26 07:50:59  dev
- Acquisizione dati per liste multiple
-
- Revision 1.5.2.13  2007/03/25 21:33:11  dev
- Modifica interfaccia per supportare le liste multiple e la security dei bean
-
- Revision 1.5.2.12  2007/03/25 14:40:20  dev
- Acquisita la lista principale dell'applicazione
-
- Revision 1.5.2.11  2007/02/13 09:59:12  dev
- Modifica alla equals del bean
-
- Revision 1.5.2.10  2007/02/13 09:57:54  dev
- Modifica alla equals del bean
-
- Revision 1.5.2.9  2007/01/07 14:38:20  dev
- Modifiche Dicembre 2006
-
- Revision 1.5.2.8  2007/01/03 12:51:13  dev
- Fix per i tag CVS
-
- Revision 1.5.2.7  2007/01/03 12:50:24  dev
- Fix per i tag CVS
-
- Revision 1.5.2.6  2007/01/03 11:36:05  dev
- Inseriti disclaymer e tag cvs
-
- Revision 1.5.2.5  2007/01/03 10:39:10  dev
- I Bean sono creati nella CONVERSATION
-
- Revision 1.5.2.4  2006/12/25 11:10:18  dev
- Introdotta gestione degli errori
- Fix per le relazioni N:M che avevano l'ownership invertita
-
- Revision 1.5.2.3  2006/12/24 16:15:57  dev
- Acquisito il nome della relazione per le relazioni N:M
-
- Revision 1.5.2.2  2006/12/17 16:15:35  dev
- Riorganizzata la classe Utils che era divisia in due !?
-
- Revision 1.5.2.1  2006/08/28 08:48:49  dev
- Modifiche principli per il supporto di seam
-
- Revision 1.5  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 NewEJB implements IObjectActionDelegate
{

  private IJavaProject      javaProject;
  private IPackageFragment  packageFragment;

  public NewEJB()
  {
    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);

      if (!beanDialog.isCancelled())
      {
        String beanName = Utils.makeFirstLetterUpperCase(beanDialog.getBeanName());

        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 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 += "import org.boco.seamwebappgen.annotations.Security;\r\n";
        sourceCode += "import org.boco.seamwebappgen.annotations.ShowList;\r\n";
        sourceCode += "import org.boco.seamwebappgen.annotations.IgnoreBean;\r\n";
        sourceCode += "import org.boco.seamwebappgen.annotations.IgnoreBeanManager;\r\n";
        sourceCode += "import org.boco.seamwebappgen.annotations.IgnorePrintListForm;\r\n";
        sourceCode += "import org.boco.seamwebappgen.annotations.IgnorePrintForm;\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 += Utils.makeShowListAnnotation(beanDialog).replace(" = ", "=").replace(", ", ",");
        sourceCode += Utils.makeSecurityAnnotation(beanDialog).replace(" = ", "=").replace(", ", ",");

        if (beanDialog.ignoreBean())
        {
          sourceCode += "@IgnoreBean()\r\n";
        }
        if (beanDialog.ignoreBeanManager())
        {
          sourceCode += "@IgnoreBeanManager()\r\n";
        }
        if (beanDialog.ignoreBeanLists())
        {
          sourceCode += "@IgnoreBeanLists()\r\n";
        }
        if (beanDialog.ignoreBeanLists())
        {
          sourceCode += "@IgnoreBeanLists()\r\n";
        }
        if (beanDialog.ignorePrintForm())
        {
          sourceCode += "@IgnorePrintForm()\r\n";
        }
        if (beanDialog.ignorePrintList())
        {
          sourceCode += "@IgnorePrintListForm()\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);

      //e.printStackTrace();
    }
  }

  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();
    }
  }

  public static Object getGUIBuilderInstance()
  {
    return new NewEJB(Boolean.FALSE);
  }

 
  public NewEJB(Boolean initGUI)
  {
    super();
  }

}
TOP

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

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.