/***************************************************************************
* 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/ShowInForm.java,v 1.1.2.10 2008/06/02 20:04:33 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.10 $
- $Date: 2008/06/02 20:04:33 $
- $Log: ShowInForm.java,v $
- Revision 1.1.2.10 2008/06/02 20:04:33 fab
- Eliminate System.out
-
- Revision 1.1.2.9 2008/05/25 07:30:42 fab
- Fix nelle voci di menu delle relazioni - mancavano le relazioni 1:1
-
- Revision 1.1.2.8 2008/05/19 09:32:29 fab
- *** empty log message ***
-
- Revision 1.1.2.7 2008/05/19 08:39:11 fab
- *** empty log message ***
-
- 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
-
- Revision 1.1.2.1 2008/03/28 18:44:26 fab
- Refactoring delle azioni
- Internazionalizzazione di tutte le voci di menu
-
- Revision 1.6.2.4 2007/10/01 15:16:05 fab
- Aggiornata dialog per la creazione del bean
- Riletta l'annotazione @ShowInForm
-
- Revision 1.6.2.3 2007/09/29 20:13:10 fab
- Fix del bug 0122/B
-
- Revision 1.6.2.2 2006/09/10 05:43:21 dev
- *** empty log message ***
-
- Revision 1.6.2.1 2006/08/28 08:48:49 dev
- Modifiche principli per il supporto di seam
-
- Revision 1.6 2006/06/05 12:00:54 dev
- Inserita gestione dello help
-
- Revision 1.5 2006/06/05 11:50:42 dev
- Inserita gestione dello help
-
- Revision 1.4 2006/05/24 15:33:34 dev
- Fix import AttributeImplementationType
-
- Revision 1.3 2006/05/23 14:33:07 dev
- Fix per import delle annotazioni
-
- Revision 1.2 2006/05/21 13:41:18 dev
- Corretta annotazione cvs
-
**/
package boco.ejb3PlugIn.popup.actions.attribute;
import java.util.Map;
import java.util.StringTokenizer;
import javax.swing.text.BadLocationException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.internal.core.SourceField;
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.ShowInFormDialog;
import boco.ejb3PlugIn.utils.Utils;
public class ShowInForm implements IObjectActionDelegate
{
private IField field;
private IField nextField;
public ShowInForm()
{
super();
}
public void setActivePart(IAction action, IWorkbenchPart targetPart)
{
}
public void run(IAction action)
{
Shell shell = new Shell();
String annotationCode = "";
if (!field.getParent().getParent().getParent().getElementName().endsWith("entity"))
{
MessageDialog.openInformation(shell, "EJB_PlugIn Plug-in", "Operazione valida solo per un bean");
return;
}
ICompilationUnit compilationUnit = field.getCompilationUnit();
try
{
String newFieldSourceCode = "";
String oldFieldSourceCode = "";
// Dal codice esistente rimuove l'annotazione se presente
StringTokenizer st = new StringTokenizer(field.getSource(), "\n\r\f");
while (st.hasMoreTokens())
{
String token = st.nextToken();
//System.out.println(".." + token);
if (!token.contains("@ShowInForm"))
{
oldFieldSourceCode += token + "\r\n";
}
else
{
annotationCode = token;
}
}
// Richiama la dialog per l'acquisizione delle informazioni
ShowInFormDialog showInFormDialog = new ShowInFormDialog(null, Utils.getIntegerValue(annotationCode, "order").toString(), getImplementationType(annotationCode), Utils.getBooleanValue(annotationCode, "required"), Utils.getBooleanValue(annotationCode, "help"));
showInFormDialog.pack();
showInFormDialog.setLocationRelativeTo(null);
showInFormDialog.setVisible(true);
String order = showInFormDialog.getOrder();
String implementationType = showInFormDialog.getType();
if (order == null)
return;
IType type = compilationUnit.getTypes()[0];
//Rimuove il campo esistente
type.getField(field.getElementName()).delete(true, null);
if (implementationType.contains("TEXTAREA"))
{
newFieldSourceCode += "\r\n\r\n@ShowInForm(order=" + order + ",type=" + implementationType + ", rows=" + showInFormDialog.getRows() + ", columns=" + showInFormDialog.getColumns();
}
else
{
newFieldSourceCode += "\r\n\r\n@ShowInForm(order=" + order + ",type=" + implementationType;
}
if (showInFormDialog.getRequired())
{
newFieldSourceCode += ", required=true";
}
if (showInFormDialog.getHelp())
{
newFieldSourceCode += ", help=true";
}
newFieldSourceCode += ")\r\n";
newFieldSourceCode += oldFieldSourceCode;
newFieldSourceCode += "\r\n \r\n \r\n ";
type.createField("\r\n"+newFieldSourceCode, nextField, true, null);
if (!compilationUnit.getSource().contains("import org.boco.seamwebappgen.annotations.ShowInForm"))
compilationUnit.createImport("org.boco.seamwebappgen.annotations.ShowInForm", null, null);
if (!compilationUnit.getSource().contains("import org.boco.seamwebappgen.annotations.AttributeImplementationType"))
compilationUnit.createImport("org.boco.seamwebappgen.annotations.AttributeImplementationType", null, null);
compilationUnit.save(null, true);
}
catch (JavaModelException e)
{
e.printStackTrace();
}
}
public void selectionChanged(IAction action, ISelection selection)
{
StructuredSelection structSelection = (StructuredSelection) selection;
nextField = null;
//System.out.println("Class " + structSelection.getFirstElement().getClass());
if (structSelection.getFirstElement().getClass().equals(org.eclipse.jdt.internal.core.SourceField.class))
{
field = (SourceField) structSelection.getFirstElement();
}
IType Clazz = (IType) field.getParent();
try
{
IField fields[] = Clazz.getFields();
for(int i=0; i<fields.length; i++)
{
IField item = fields[i];
if (item.equals(field))
{
nextField = (IField)fields[i+1];
// System.out.println("Next Field"+nextField);
}
}
}
catch (JavaModelException e)
{
e.printStackTrace();
}
}
private ShowInFormDialog.ImplementationType getImplementationType(String annotationCode)
{
String type = Utils.getTypeValue(annotationCode, "type");
if (type == null)
return null;
if (type.equals("AttributeImplementationType.TEXT"))
return ShowInFormDialog.ImplementationType.TEXT;
if (type.equals("AttributeImplementationType.TEXTAREA"))
return ShowInFormDialog.ImplementationType.TEXTAREA;
if (type.equals("AttributeImplementationType.LISTBOX"))
return ShowInFormDialog.ImplementationType.LISTBOX;
return null;
}
}