Package boco.ejb3PlugIn.popup.actions.attribute

Source Code of boco.ejb3PlugIn.popup.actions.attribute.ShowRelationshipAttributesInForm

/***************************************************************************
* 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/attribute/Attic/ShowRelationshipAttributesInForm.java,v 1.1.2.7 2008/06/02 20:04:33 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.7 $
- $Date: 2008/06/02 20:04:33 $


- $Log: ShowRelationshipAttributesInForm.java,v $
- Revision 1.1.2.7  2008/06/02 20:04:33  fab
- Eliminate System.out
-
- Revision 1.1.2.6  2008/05/05 12:40:11  fab
- Fix nella generazione dei packages
-
- Revision 1.1.2.5  2008/04/22 17:09:21  fab
- *** empty log message ***
-
- Revision 1.1.2.4  2008/04/22 06:17:38  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.3  2008/04/19 11:21:01  fab
- Modifiche a seguito del refactoring del generatore
-
- Revision 1.1.2.2  2008/04/19 10:26:49  fab
- Aggiornamento riferimenti licenza
-
-
**/

package boco.ejb3PlugIn.popup.actions.attribute;

import java.util.StringTokenizer;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
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.AttributesSelectionDialog;
import boco.ejb3PlugIn.utils.Utils;


public class ShowRelationshipAttributesInForm implements IObjectActionDelegate
{
  private IMethod  method;
 
  public ShowRelationshipAttributesInForm()
  {
    super();
  }

  public void setActivePart(IAction action, IWorkbenchPart targetPart)
  {
  }
 
  public void run(IAction action)
  {
    Shell shell = new Shell();
   
    if (!method.getParent().getParent().getParent().getElementName().endsWith("entity"))
    {
      MessageDialog.openInformation(shell, "EJB_PlugIn Plug-in", "Operazione valida solo per un bean");
      return;
    }

    ICompilationUnit compilationUnit = method.getCompilationUnit();
       
    try
    {
      String newMethodSourceCode = "";
      String oldMethodAnnotations = "";
      String oldMethodSourceCode = "";
     
      String targetBean = Utils.getTargetBean(compilationUnit,method.getElementName());
           
      AttributesSelectionDialog attributesSelectionDialog = new AttributesSelectionDialog(Utils.getCompilationUnit(compilationUnit,targetBean),true,false);
      attributesSelectionDialog.pack();
      attributesSelectionDialog.setLocationRelativeTo(null);
      attributesSelectionDialog.setVisible(true);     
     
      if(!attributesSelectionDialog.selectedAttributes())
        return;
     
     
      // Dal codice esistente rimuove l'annotazione se presente
      StringTokenizer st = new StringTokenizer(method.getSource(),"\t\n\r\f");
      while (st.hasMoreTokens())
      {
        String token = st.nextToken();
       
        if(!token.contains("@ShowRelationshipAttributesInForm"))
        {
          if (token.startsWith("@"))
            oldMethodAnnotations += token + "\r\n";
          else
            oldMethodSourceCode += token + "\r\n";
        }
      }     
     
      IType type = compilationUnit.getTypes()[0];

      //Rimuove il metodo esistente
      type.getMethod(method.getElementName(),null).delete(true, null);
           
      newMethodSourceCode += "\r\n@ShowRelationshipAttributesInForm(names="+attributesSelectionDialog.getSelectedAttributes()+", orders="+attributesSelectionDialog.getSelectedAttributesOrders()+")\r\n";
           
      newMethodSourceCode = oldMethodAnnotations + newMethodSourceCode + oldMethodSourceCode + "\r\n";
     
      type.createMethod(newMethodSourceCode, null, true, null);
     
      if(!compilationUnit.getSource().contains("import org.boco.seamwebappgen.annotations.ShowRelationshipAttributesInForm"))
        compilationUnit.createImport("org.boco.seamwebappgen.annotations.ShowRelationshipAttributesInForm", null, null);
     
      compilationUnit.save(null, true);
    }
    catch (JavaModelException e)
    {
      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.SourceMethod.class))
    {
      method = (IMethod) structSelection.getFirstElement();
    }
  }
 
}
TOP

Related Classes of boco.ejb3PlugIn.popup.actions.attribute.ShowRelationshipAttributesInForm

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.