diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Bundle.properties b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Bundle.properties
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Bundle.properties
@@ -0,0 +1,43 @@
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+#
+# The contents of this file are subject to the terms of either the GNU
+# General Public License Version 2 only ("GPL") or the Common
+# Development and Distribution License("CDDL") (collectively, the
+# "License"). You may not use this file except in compliance with the
+# License. You can obtain a copy of the License at
+# http://www.netbeans.org/cddl-gplv2.html
+# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+# specific language governing permissions and limitations under the
+# License. When distributing the software, include this License Header
+# Notice in each file and include the License file at
+# nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Sun in the GPL Version 2 section of the License file that
+# accompanied this code. If applicable, add the following below the
+# License Header, with the fields enclosed by brackets [] replaced by
+# your own identifying information:
+# "Portions Copyrighted [year] [name of copyright owner]"
+#
+# If you wish your version of this file to be governed by only the CDDL
+# or only the GPL Version 2, indicate your decision by adding
+# "[Contributor] elects to include this software in this distribution
+# under the [CDDL or GPL Version 2] license." If you do not indicate a
+# single choice of license, a recipient has the option to distribute
+# your version of this file under either the CDDL, the GPL Version 2 or
+# to extend the choice of license to its licensees as provided above.
+# However, if you add GPL Version 2 code and therefore, elected the GPL
+# Version 2 license, then the option applies only if the new code is
+# made subject to such option by the copyright holder.
+#
+# Contributor(s):
+#
+# Portions Copyrighted 2009 Sun Microsystems, Inc.
+
+ERR_REG_EXP_SYNTAX=regular expression syntax error
+ERR_IS_NOT_ID=is not identifier
+ERR_DUP_ID=duplicate identifier
+NC_WARNING_TITLE=Name convertion warning
+NC_WAS_ERRORS=There were errors while name converting.
+NC_DETAILS_TITLE=Name convertion details
\ No newline at end of file
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/DbSchemaEjbGenerator.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/DbSchemaEjbGenerator.java
--- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/DbSchemaEjbGenerator.java
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/DbSchemaEjbGenerator.java
@@ -49,6 +49,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.swing.JOptionPane;
import org.netbeans.modules.dbschema.ColumnElement;
import org.netbeans.modules.dbschema.ColumnPairElement;
import org.netbeans.modules.dbschema.DBIdentifier;
@@ -57,6 +58,9 @@
import org.netbeans.modules.dbschema.TableElement;
import org.netbeans.modules.dbschema.UniqueKeyElement;
import org.netbeans.modules.j2ee.persistence.entitygenerator.CMPMappingModel.ColumnData;
+import org.netbeans.modules.j2ee.persistence.wizard.fromdb.NameConvertionDetailsPanel;
+import org.netbeans.modules.j2ee.persistence.wizard.fromdb.NameConvertionProperties;
+import org.openide.util.NbBundle;
/**
* This class provides an algorithm to produce a set of cmp beans and relations
@@ -71,6 +75,7 @@
private List relations = new ArrayList();
private SchemaElement schemaElement;
private Set tablesReferecedByOtherTables;
+ private NameConvertionProperties nameConvertionProperties;
/**
* Creates a generator for a set of beans.
@@ -78,9 +83,11 @@
* @param genTables contains the tables to generate and their respective locations.
* @param schemaElement the dbschema containing the tables to generate beans for.
*/
- public DbSchemaEjbGenerator(GeneratedTables genTables, SchemaElement schemaElement) {
+ public DbSchemaEjbGenerator(GeneratedTables genTables, SchemaElement schemaElement,
+ NameConvertionProperties namesConvertionProperties) {
this.schemaElement = schemaElement;
this.genTables = genTables;
+ this.nameConvertionProperties = namesConvertionProperties;
tablesReferecedByOtherTables = getTablesReferecedByOtherTables(schemaElement);
buildCMPSet();
@@ -502,6 +509,175 @@
helperData.setIsForTable(table.isTable());
}
makeRelationsUnique();
+
+ if ( nameConvertionProperties.isActive() ){
+ HashMap> namesMap = getNameMap();
+
+ boolean wasConvertionErrors = false;
+ String errorMessage = "";
+ if ( nameConvertionProperties.isUseRegExpPK() ||
+ nameConvertionProperties.isUseRegExpFKA() ||
+ nameConvertionProperties.isUseRegExpFKB()){
+ for( String key : namesMap.keySet() ){
+ for ( NameTableRow tr : namesMap.get(key) ){
+ String s = null;
+
+
+ if ( tr.getType().equals("PK") && nameConvertionProperties.isUseRegExpPK() )
+ try{
+ s = tr.getClassFieldName().replaceAll(
+ nameConvertionProperties.getSrcExprPK(), nameConvertionProperties.getDestExprPK() );
+ } catch ( Exception ex ) {
+ wasConvertionErrors = true;
+ errorMessage += NbBundle.getMessage(DbSchemaEjbGenerator.class, "ERR_REG_EXP_SYNTAX") + "\n";
+ nameConvertionProperties.setSrcExprPK(" ");
+ continue;
+ }
+ else if ( tr.getType().equals("FK") && nameConvertionProperties.isUseRegExpFKA() )
+ try{
+ s = tr.getClassFieldName().replaceAll(
+ nameConvertionProperties.getSrcExprFKA(), nameConvertionProperties.getDestExprFKA() );
+ } catch ( Exception ex ) {
+ wasConvertionErrors = true;
+ errorMessage += NbBundle.getMessage(DbSchemaEjbGenerator.class, "ERR_REG_EXP_SYNTAX") + "\n";
+ nameConvertionProperties.setSrcExprFKA(" ");
+ continue;
+ }
+ else if ( tr.getType().equals("FK(ref)") && nameConvertionProperties.isUseRegExpFKB() )
+ try{
+ s = tr.getClassFieldName().replaceAll(
+ nameConvertionProperties.getSrcExprFKB(), nameConvertionProperties.getDestExprFKB() );
+ } catch ( Exception ex ) {
+ wasConvertionErrors = true;
+ errorMessage += NbBundle.getMessage(DbSchemaEjbGenerator.class, "ERR_REG_EXP_SYNTAX") + "\n";
+ nameConvertionProperties.setSrcExprFKB(" ");
+ continue;
+ }
+
+ // if was replacing
+ if ( s != null )
+ {
+ // replacing %KEYWORD% expressions
+ s = s.replaceAll("%([><])ENTITY%", "$1" + key);
+ if ( tr.getType().equals("FK") )
+ s = s.replaceAll("%([><])REFENTITY%", "$1" + ((RelationshipRole)tr.getParentObject()).getParent().getRoleB().getEntityName() );
+ else if ( tr.getType().equals("FK(ref)") )
+ s = s.replaceAll("%([><])REFENTITY%", "$1" + ((RelationshipRole)tr.getParentObject()).getParent().getRoleA().getEntityName() );
+
+ for( int i = 0 ; i < s.length() ; ++i )
+ if ( s.charAt(i) == '>' )
+ s = s.substring(0, i) + s.substring(i+1, i+2).toUpperCase()
+ + s.substring(i+2);
+ else if ( s.charAt(i) == '<')
+ s = s.substring(0, i) + s.substring(i+1, i+2).toLowerCase()
+ + s.substring(i+2);
+
+ // if not id
+ if ( !s.matches("[a-zA-Z_][a-zA-Z_0-9]*") ){
+ wasConvertionErrors = true;
+ errorMessage += s+" "+NbBundle.getMessage(DbSchemaEjbGenerator.class, "ERR_IS_NOT_ID") + "\n";
+ continue;
+ }
+
+ // searching for duplicate fields
+ for ( NameTableRow tr1 : namesMap.get(key) )
+ if ( tr1.getParentObject() != tr.getParentObject()
+ && s.equals( tr1.getClassFieldName() ) ){
+ wasConvertionErrors = true;
+ errorMessage += s+" "+NbBundle.getMessage(DbSchemaEjbGenerator.class, "ERR_DUP_ID")+"\n";
+ break;
+ }
+
+ if ( wasConvertionErrors )
+ continue;
+
+ tr.setClassFieldName( s );
+ }
+ }
+ }
+ }
+
+ if ( wasConvertionErrors )
+ JOptionPane.showMessageDialog(null, NbBundle.getMessage(DbSchemaEjbGenerator.class, "NC_WAS_ERRORS")+"\n\n" + errorMessage,
+ NbBundle.getMessage(DbSchemaEjbGenerator.class, "NC_WARNING_TITLE"), JOptionPane.WARNING_MESSAGE);
+
+ boolean applyMap = true;
+ if ( nameConvertionProperties.isUseManual() || wasConvertionErrors ){
+ org.netbeans.modules.j2ee.persistence.wizard.fromdb.NameConvertionDetailsPanel panel;
+ panel = new NameConvertionDetailsPanel( namesMap );
+ org.openide.DialogDescriptor namesConvDD = new org.openide.DialogDescriptor( panel ,
+ NbBundle.getMessage(DbSchemaEjbGenerator.class, "NC_DETAILS_TITLE") );
+ namesConvDD.setModal( true );
+ panel.setDialogDescriptor(namesConvDD);
+
+ // showing dialog
+ org.openide.DialogDisplayer.getDefault().notify( namesConvDD );
+
+ // getting result
+ if ( namesConvDD.getValue() != org.openide.NotifyDescriptor.OK_OPTION )
+ applyMap = false;
+
+ panel.setDialogDescriptor( null );
+ }
+
+ if ( applyMap )
+ applyNameMap( namesMap );
+ }
+ }
+
+ /**
+ * applies names map on entity classes
+ * @param namesMap new names map
+ */
+ private void applyNameMap(HashMap> namesMap){
+ EntityMember em = null;
+ RelationshipRole rr = null;
+ String type = null;
+ for( String key : namesMap.keySet() ){
+ for ( NameTableRow tr : namesMap.get(key) ){
+ type = tr.getType();
+
+ if ( type.startsWith( "FK" ) ){
+ rr = (RelationshipRole)tr.getParentObject();
+ Map map = tr.getEntityClass().getCMPMapping().getCmrFieldMapping();
+ ColumnData cd[] = map.get( rr.getFieldName() );
+ rr.setFieldName( tr.getClassFieldName() );
+ map.put(tr.getClassFieldName(), cd);
+ }
+ else{
+ em = (EntityMember)tr.getParentObject();
+ em.setMemberName( tr.getClassFieldName() );
+ }
+ }
+ }
+ }
+
+ /**
+ * prepares names map for name convertion
+ * @return
+ */
+ private HashMap> getNameMap(){
+ HashMap> result =
+ new HashMap>();
+ ArrayList newRow = null;
+ for( String key : ((HashMap)beans).keySet() ){
+ newRow = new ArrayList();
+
+ EntityClass ec = ((HashMap)beans).get(key);
+ // fields
+ for( EntityMember em : ec.getFields() )
+ newRow.add(new NameTableRow((em.isPrimaryKey()) ? "PK" : "",
+ em.getColumnName(), em.getMemberName(), em, ec));
+
+ // roles
+ for( RelationshipRole rr : ec.getRoles() )
+ newRow.add(new NameTableRow((rr.getParent().getRoleA() == rr)?"FK":"FK(ref)",
+ "", rr.getFieldName(), rr, ec));
+
+ result.put(key, newRow);
+ }
+
+ return result;
}
private List getFieldNames(EntityClass bean) {
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/NameTableRow.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/NameTableRow.java
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/NameTableRow.java
@@ -0,0 +1,107 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.j2ee.persistence.entitygenerator;
+
+/**
+ * Stores information about single row of names convertion table
+ * @author Tomilov Mikhail
+ */
+public class NameTableRow
+{
+ private String type; // PK, FK or empty
+ private String tableColumnName; // name in DB table
+ private String classFieldName; // name in class
+ private Object parentObject;
+ private EntityClass entityClass;
+
+ public NameTableRow(String type, String tableColumnName, String classFieldName,
+ Object parentObject, EntityClass entityClass )
+ {
+ this.type = type;
+ this.tableColumnName = tableColumnName;
+ this.classFieldName = classFieldName;
+ this.parentObject = parentObject;
+ this.entityClass = entityClass;
+ }
+
+ public EntityClass getEntityClass() {
+ return entityClass;
+ }
+
+ public String getClassFieldName()
+ {
+ return classFieldName;
+ }
+
+ public void setClassFieldName(String classFieldName)
+ {
+ this.classFieldName = classFieldName;
+ }
+
+ public Object getParentObject()
+ {
+ return parentObject;
+ }
+
+ public void setParentObject(Object parentObject)
+ {
+ this.parentObject = parentObject;
+ }
+
+ public String getTableColumnName()
+ {
+ return tableColumnName;
+ }
+
+ public void setTableColumnName(String tableColumnName)
+ {
+ this.tableColumnName = tableColumnName;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+};
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties
--- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties
@@ -217,3 +217,41 @@
TXT_SelectedTables=Selected Tables
TXT_AvailableTables=Available Tables
LBL_Progress_Adding_Classpath=Adding J2EE apis to project classpath.
+
+#NameConvertionPanel
+TXT_NC_AddButton=Add
+TXT_NC_RemoveButton=Remove
+NamesConvertionDialog.okButton.text=OK
+NamesConvertionDialog.cancelButton.text=Cancel
+LBL_NC_FieldType=Field type
+LBL_NC_PredefinedPatterns=Predefined patterns
+LBL_NC_Source=Source
+LBL_NC_Target=Target
+TXT_NC_UseNC=Use name convertion
+TXT_NC_UseRE=use regular expressions
+TXT_NC_Manual=Manual convertion
+TXT_NameConvertion=Name convertion...
+ERR_IncorrectRegExp=Incorrect convertion
+TXT_NC_BorderText=Regular expressions
+TXT_PrimaryKey=Primary key
+TXT_ForeignKeyRoleA=Foreign key
+TXT_ForeignKeyRoleB=Foreign key(ref)
+TXT_TableSourceHeader=Source exp
+TXT_TableTargetHeader=Target exp
+LBL_NCD_TableLabel=Table
+ERR_IncorrectId=Incorrect identifier
+ERR_Duplicates=There are duplicate field names
+TXT_NCD_TableFieldTypeHeader=Type
+TXT_NCD_TableColumnHeader=Table column
+TXT_NCD_ClassFieldHeader=Class field
+TXT_NCD_MODIFY_BUTTON=Modify...
+TXT_NCD_SRC_LABEL=Source
+TXT_NCD_TARGET_LABEL=Target
+TXT_NCD_PK_LABEL=Primary key
+TXT_NCD_FKA_LABEL=Foreign key
+TXT_NCD_FKB_LABEL=Foreign key referenced
+TXT_NCP_SRC_LABEL=Source
+TXT_NCP_TAR_LABEL=Target
+TXT_NCP_ADD_BUTTON=Add
+TXT_NCP_REMOVE_BUTTON=Remove
+NameConvertionPatternsPanel.errorLabel.text=
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.form b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.form
--- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.form
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.form
@@ -8,6 +8,8 @@
+
+
@@ -38,7 +40,11 @@
-
+
+
+
+
+
@@ -75,7 +81,10 @@
-
+
+
+
+
@@ -216,5 +225,13 @@
+
+
+
+
+
+
+
+
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.java
--- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.java
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/EntityClassesPanel.java
@@ -101,6 +101,9 @@
private PersistenceUnit persistenceUnit;
+ /** names convertion properties */
+ private NameConvertionProperties nameConvertionProperties;
+
public EntityClassesPanel() {
initComponents();
@@ -124,6 +127,14 @@
}
});
}
+
+ public NameConvertionProperties getNameConvertionProperties() {
+ return nameConvertionProperties;
+ }
+
+ public void setNameConvertionProperties(NameConvertionProperties namesConvertionProperties) {
+ this.nameConvertionProperties = namesConvertionProperties;
+ }
public void addChangeListener(ChangeListener listener) {
changeSupport.addChangeListener(listener);
@@ -309,6 +320,7 @@
cmpFieldsInInterfaceCheckBox = new javax.swing.JCheckBox();
spacerPanel = new javax.swing.JPanel();
createPUWarningLabel = new ShyLabel();
+ nameConvertionButton = new javax.swing.JButton();
setName(org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_EntityClasses")); // NOI18N
@@ -364,6 +376,13 @@
org.openide.awt.Mnemonics.setLocalizedText(createPUWarningLabel, " ");
+ org.openide.awt.Mnemonics.setLocalizedText(nameConvertionButton, "Name convertion...");
+ nameConvertionButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ nameConvertionButtonActionPerformed(evt);
+ }
+ });
+
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@@ -384,7 +403,10 @@
.add(classNamesScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)))
.add(cmpFieldsInInterfaceCheckBox)
.add(generateFinderMethodsCheckBox)
- .add(createPUButton)
+ .add(layout.createSequentialGroup()
+ .add(createPUButton)
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 143, Short.MAX_VALUE)
+ .add(nameConvertionButton))
.add(createPUWarningLabel)
);
layout.setVerticalGroup(
@@ -416,7 +438,9 @@
.add(21, 21, 21)
.add(createPUWarningLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(createPUButton))
+ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
+ .add(createPUButton)
+ .add(nameConvertionButton)))
);
}// //GEN-END:initComponents
@@ -432,6 +456,20 @@
}
}//GEN-LAST:event_createPUButtonActionPerformed
+ private void nameConvertionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameConvertionButtonActionPerformed
+ // prepearing dialog
+ NameConvertionPanel panel = new NameConvertionPanel( new NameConvertionProperties(nameConvertionProperties) );
+ org.openide.DialogDescriptor nameConvDD = new org.openide.DialogDescriptor( panel , "Name convertion" );
+ nameConvDD.setHelpCtx(new HelpCtx("persist_nameconvertion"));
+ nameConvDD.setModal( true );
+ // showing dialog
+ org.openide.DialogDisplayer.getDefault().notify( nameConvDD );
+
+ // getting result
+ if ( nameConvDD.getValue() == org.openide.NotifyDescriptor.OK_OPTION )
+ nameConvertionProperties = panel.getNamesConvertionProperties();
+ }//GEN-LAST:event_nameConvertionButtonActionPerformed
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel classNamesLabel;
@@ -443,6 +481,7 @@
private javax.swing.JCheckBox generateFinderMethodsCheckBox;
private javax.swing.JComboBox locationComboBox;
private javax.swing.JLabel locationLabel;
+ private javax.swing.JButton nameConvertionButton;
private javax.swing.JComboBox packageComboBox;
private javax.swing.JLabel packageLabel;
private javax.swing.JLabel projectLabel;
@@ -518,6 +557,7 @@
}
getComponent().update(helper.getTableClosure(), tableSourceName);
+ getComponent().setNameConvertionProperties(helper.getNameConvertionProperties());
}
public boolean isValid() {
@@ -596,6 +636,7 @@
helper.setCmpFieldsInInterface(getComponent().getCmpFieldsInInterface());
helper.setGenerateFinderMethods(getComponent().getGenerateFinderMethods());
helper.setPersistenceUnit(getComponent().getPersistenceUnit());
+ helper.setNameConvertionProperties(getComponent().getNameConvertionProperties());
}
public void stateChanged(ChangeEvent event) {
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionDetailsPanel.form b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionDetailsPanel.form
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionDetailsPanel.form
@@ -0,0 +1,87 @@
+
+
+
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionDetailsPanel.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionDetailsPanel.java
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionDetailsPanel.java
@@ -0,0 +1,305 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+
+/*
+ * NameConvertionDetailsPanel.java
+ *
+ * Created on 25.03.2009, 16:28:39
+ */
+
+package org.netbeans.modules.j2ee.persistence.wizard.fromdb;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import javax.swing.Icon;
+import javax.swing.table.AbstractTableModel;
+import org.netbeans.modules.j2ee.persistence.entitygenerator.NameTableRow;
+import org.openide.util.ImageUtilities;
+import org.openide.DialogDescriptor;
+import org.openide.util.NbBundle;
+
+
+/**
+ * Class provides edit ability for name convertion map
+ * @author Tomilov Mikhail
+ */
+public class NameConvertionDetailsPanel extends javax.swing.JPanel {
+
+ HashMap> namesMap = null;
+ DialogDescriptor dialogDescriptor = null;
+
+ public NameConvertionDetailsPanel(HashMap> namesMap) {
+ initComponents();
+ this.namesMap = namesMap;
+
+ fieldsTable.setModel( new NamesMapTableModel() );
+ for( String key : namesMap.keySet() )
+ tableComboBox.addItem( key );
+ }
+
+ public void setDialogDescriptor(DialogDescriptor dialogDescriptor) {
+ this.dialogDescriptor = dialogDescriptor;
+ }
+
+ /**
+ * Loads names map to JTable
+ * @param tableName table for map to load
+ */
+ private void loadMap( String tableName )
+ {
+ NamesMapTableModel tabModel = (NamesMapTableModel)fieldsTable.getModel();
+ tabModel.setRows( namesMap.get(tableName) );
+ }
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ tableComboBox = new javax.swing.JComboBox();
+ jLabel1 = new javax.swing.JLabel();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ fieldsTable = new javax.swing.JTable();
+ errorLabel = new javax.swing.JLabel();
+
+ tableComboBox.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ tableComboBoxActionPerformed(evt);
+ }
+ });
+
+ jLabel1.setText(org.openide.util.NbBundle.getMessage(NameConvertionDetailsPanel.class, "LBL_NCD_TableLabel")); // NOI18N
+
+ fieldsTable.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null}
+ },
+ new String [] {
+ "", "Table column", "Class field"
+ }
+ ) {
+ Class[] types = new Class [] {
+ java.lang.String.class, java.lang.String.class, java.lang.String.class
+ };
+ boolean[] canEdit = new boolean [] {
+ false, false, true
+ };
+
+ public Class getColumnClass(int columnIndex) {
+ return types [columnIndex];
+ }
+
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return canEdit [columnIndex];
+ }
+ });
+ jScrollPane1.setViewportView(fieldsTable);
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel1)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(tableComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(errorLabel))
+ .addContainerGap())
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel1)
+ .addComponent(tableComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(errorLabel)
+ .addContainerGap())
+ );
+ }// //GEN-END:initComponents
+
+ private void tableComboBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_tableComboBoxActionPerformed
+ {//GEN-HEADEREND:event_tableComboBoxActionPerformed
+ loadMap( (String)tableComboBox.getSelectedItem() );
+ }//GEN-LAST:event_tableComboBoxActionPerformed
+
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JLabel errorLabel;
+ private javax.swing.JTable fieldsTable;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JComboBox tableComboBox;
+ // End of variables declaration//GEN-END:variables
+
+ class NamesMapTableModel extends AbstractTableModel
+ {
+ private ArrayList rows = null;
+
+ public void clear()
+ {
+ rows.clear();
+ fireTableDataChanged();
+ }
+
+ public void setRows( ArrayList rows )
+ {
+ this.rows = rows;
+ fireTableDataChanged();
+ }
+
+ @Override
+ public String getColumnName(int col)
+ {
+ switch ( col )
+ {
+ case 0 : return NbBundle.getMessage(NameConvertionDetailsPanel.class, "TXT_NCD_TableFieldTypeHeader");
+ case 1 : return NbBundle.getMessage(NameConvertionDetailsPanel.class, "TXT_NCD_TableColumnHeader");
+ case 2 : return NbBundle.getMessage(NameConvertionDetailsPanel.class, "TXT_NCD_ClassFieldHeader");
+ default : throw new java.lang.IndexOutOfBoundsException();
+ }
+ }
+
+ public int getRowCount()
+ {
+ return rows.size();
+ }
+
+ public int getColumnCount()
+ {
+ return 3;
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex)
+ {
+ if ( rowIndex >= rows.size() || rowIndex < 0 )
+ throw new java.lang.IndexOutOfBoundsException();
+
+ switch( columnIndex ) {
+ case 0 : return rows.get(rowIndex).getType();
+ case 1 : return rows.get(rowIndex).getTableColumnName();
+ case 2 : return rows.get(rowIndex).getClassFieldName();
+ case 3 : return rows.get(rowIndex).getParentObject();
+ default : throw new java.lang.IndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public void setValueAt(Object value, int row, int col)
+ {
+ if ( row >= rows.size() || row < 0 )
+ throw new java.lang.IndexOutOfBoundsException();
+
+ switch( col )
+ {
+ case 0 : rows.get(row).setType( (String)value ); break;
+ case 1 : rows.get(row).setTableColumnName( (String)value ); break;
+ case 2 : rows.get(row).setClassFieldName( (String)value ); break;
+ case 3 : rows.get(row).setParentObject( value ); break;
+ default : throw new java.lang.IndexOutOfBoundsException();
+ }
+
+ if ( col == 2 )
+ {
+ // is new value valid
+ if ( !((String)value).matches("[_a-zA-Z][_a-zA-Z0-9]*") )
+ {
+ tableComboBox.setEnabled(false);
+ Icon icon = ImageUtilities.loadImageIcon("org/netbeans/modules/j2ee/persistence/ui/resources/warning.gif", false);
+ errorLabel.setIcon(icon);
+ errorLabel.setText(NbBundle.getMessage(NameConvertionDetailsPanel.class, "ERR_IncorrectId"));
+ if ( dialogDescriptor != null )
+ dialogDescriptor.setValid(false);
+ }
+ else
+ {
+ // searching for duplicates
+ boolean duplicates = false;
+ for( int i = 0 ; i < rows.size() ; ++i ){
+ for( int j = i + 1 ; j < rows.size() ; ++j )
+ if ( rows.get(i).getClassFieldName().equals(rows.get(j).getClassFieldName()) ){
+ duplicates = true;
+ break;
+ }
+ if ( duplicates )
+ break;
+ }
+
+ if ( duplicates ){
+ tableComboBox.setEnabled(false);
+ errorLabel.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/j2ee/persistence/ui/resources/warning.gif", false));
+ errorLabel.setText(NbBundle.getMessage(NameConvertionDetailsPanel.class, "ERR_Duplicates"));
+ if ( dialogDescriptor != null )
+ dialogDescriptor.setValid(false);
+ }
+ else{
+ tableComboBox.setEnabled(true);
+ errorLabel.setIcon(null);
+ errorLabel.setText(null);
+ if ( dialogDescriptor != null )
+ dialogDescriptor.setValid(true);
+ }
+ }
+ }
+
+ fireTableCellUpdated(row, col);
+ }
+
+ @Override
+ public boolean isCellEditable(int row, int col)
+ {
+ return col == 2; // just third column is editable
+ }
+
+ };
+}
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPanel.form b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPanel.form
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPanel.form
@@ -0,0 +1,309 @@
+
+
+
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPanel.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPanel.java
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPanel.java
@@ -0,0 +1,463 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+
+/*
+ * NameConvertionPanel.java
+ *
+ * Created on 25.03.2009, 2:04:53
+ */
+package org.netbeans.modules.j2ee.persistence.wizard.fromdb;
+
+/**
+ * Name convertion base parameters panel
+ * @author Tomilov Mikhail
+ */
+public class NameConvertionPanel extends javax.swing.JPanel {
+ NameConvertionProperties ncprops = null;
+
+ /** index of last selected item of field type combo */
+ int lastFieldTypeIndex = -1;
+
+ /**
+ * Creates new form NameConvertionPanel
+ * @param convType current names convertion type
+ * @param patterns useful regular expressions from preferences
+ */
+ public NameConvertionPanel(NameConvertionProperties ncprops ) {
+ initComponents();
+
+ this.ncprops = ncprops;
+
+ pkSrcTextField.setText(ncprops.getSrcExprPK());
+ pkDestTextField.setText(ncprops.getDestExprPK());
+ fkaSrcTextField.setText(ncprops.getSrcExprFKA());
+ fkaDestTextField.setText(ncprops.getDestExprFKA());
+ fkbSrcTextField.setText(ncprops.getSrcExprFKB());
+ fkbDestTextField.setText(ncprops.getDestExprFKB());
+
+ nameConvertionCheckBox.setSelected(ncprops.isActive());
+ pkCheckBox.setSelected(ncprops.isUseRegExpPK());
+ fkaCheckBox.setSelected(ncprops.isUseRegExpFKA());
+ fkbCheckBox.setSelected(ncprops.isUseRegExpFKB());
+ useNCCheckBoxChanged();
+ manualCheckBox.setSelected(ncprops.isUseManual());
+ }
+
+ public NameConvertionProperties getNamesConvertionProperties(){
+ ncprops.setActive(nameConvertionCheckBox.isSelected());
+ ncprops.setUseManual(manualCheckBox.isSelected());
+ ncprops.setUseRegExpPK(pkCheckBox.isSelected());
+ ncprops.setUseRegExpFKA(fkaCheckBox.isSelected());
+ ncprops.setUseRegExpFKB(fkbCheckBox.isSelected());
+
+ if ( pkCheckBox.isSelected() ){
+ ncprops.setSrcExprPK(pkSrcTextField.getText());
+ ncprops.setDestExprPK(pkDestTextField.getText());
+ }
+
+ if ( fkaCheckBox.isSelected() ){
+ ncprops.setSrcExprFKA(fkaSrcTextField.getText());
+ ncprops.setDestExprFKA(fkaDestTextField.getText());
+ }
+
+ if ( fkbCheckBox.isSelected() ){
+ ncprops.setSrcExprFKB(fkbSrcTextField.getText());
+ ncprops.setDestExprFKB(fkbDestTextField.getText());
+ }
+
+ return ncprops;
+ }
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ buttonGroup1 = new javax.swing.ButtonGroup();
+ nameConvertionCheckBox = new javax.swing.JCheckBox();
+ paramPanel = new javax.swing.JPanel();
+ pkCheckBox = new javax.swing.JCheckBox();
+ pkSrcLabel = new javax.swing.JLabel();
+ pkSrcTextField = new javax.swing.JTextField();
+ pkDestLabel = new javax.swing.JLabel();
+ pkDestTextField = new javax.swing.JTextField();
+ fkaCheckBox = new javax.swing.JCheckBox();
+ fkaSrcLabel = new javax.swing.JLabel();
+ fkaSrcTextField = new javax.swing.JTextField();
+ fkaDestLabel = new javax.swing.JLabel();
+ fkaDestTextField = new javax.swing.JTextField();
+ pkModifyButton = new javax.swing.JButton();
+ fkaModifyButton = new javax.swing.JButton();
+ fkbCheckBox = new javax.swing.JCheckBox();
+ fkbSrcLabel = new javax.swing.JLabel();
+ fkbSrcTextField = new javax.swing.JTextField();
+ fkbDestLabel = new javax.swing.JLabel();
+ fkbDestTextField = new javax.swing.JTextField();
+ fkbModifyButton = new javax.swing.JButton();
+ manualCheckBox = new javax.swing.JCheckBox();
+ errorLabel = new javax.swing.JLabel();
+
+ nameConvertionCheckBox.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NC_UseNC")); // NOI18N
+ nameConvertionCheckBox.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ nameConvertionCheckBoxActionPerformed(evt);
+ }
+ });
+
+ paramPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NC_BorderText"))); // NOI18N
+
+ pkCheckBox.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_PK_LABEL")); // NOI18N
+ pkCheckBox.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ pkCheckBoxActionPerformed(evt);
+ }
+ });
+
+ pkSrcLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_SRC_LABEL")); // NOI18N
+
+ pkSrcTextField.setEditable(false);
+
+ pkDestLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_TARGET_LABEL")); // NOI18N
+
+ pkDestTextField.setEditable(false);
+
+ fkaCheckBox.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_FKA_LABEL")); // NOI18N
+ fkaCheckBox.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ fkaCheckBoxActionPerformed(evt);
+ }
+ });
+
+ fkaSrcLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_SRC_LABEL")); // NOI18N
+
+ fkaSrcTextField.setEditable(false);
+
+ fkaDestLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_TARGET_LABEL")); // NOI18N
+
+ fkaDestTextField.setEditable(false);
+
+ pkModifyButton.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_MODIFY_BUTTON")); // NOI18N
+ pkModifyButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ pkModifyButtonActionPerformed(evt);
+ }
+ });
+
+ fkaModifyButton.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_MODIFY_BUTTON")); // NOI18N
+ fkaModifyButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ fkaModifyButtonActionPerformed(evt);
+ }
+ });
+
+ fkbCheckBox.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_FKB_LABEL")); // NOI18N
+ fkbCheckBox.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ fkbCheckBoxActionPerformed(evt);
+ }
+ });
+
+ fkbSrcLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_SRC_LABEL")); // NOI18N
+
+ fkbSrcTextField.setEditable(false);
+
+ fkbDestLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_TARGET_LABEL")); // NOI18N
+
+ fkbDestTextField.setEditable(false);
+
+ fkbModifyButton.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NCD_MODIFY_BUTTON")); // NOI18N
+ fkbModifyButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ fkbModifyButtonActionPerformed(evt);
+ }
+ });
+
+ javax.swing.GroupLayout paramPanelLayout = new javax.swing.GroupLayout(paramPanel);
+ paramPanel.setLayout(paramPanelLayout);
+ paramPanelLayout.setHorizontalGroup(
+ paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(paramPanelLayout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(pkCheckBox)
+ .addComponent(fkbCheckBox)
+ .addGroup(paramPanelLayout.createSequentialGroup()
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
+ .addGroup(javax.swing.GroupLayout.Alignment.LEADING, paramPanelLayout.createSequentialGroup()
+ .addComponent(fkbSrcLabel)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(fkbSrcTextField))
+ .addComponent(fkaCheckBox, javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.LEADING, paramPanelLayout.createSequentialGroup()
+ .addComponent(fkaSrcLabel)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(fkaSrcTextField))
+ .addGroup(javax.swing.GroupLayout.Alignment.LEADING, paramPanelLayout.createSequentialGroup()
+ .addComponent(pkSrcLabel)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(pkSrcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)))
+ .addGap(18, 18, 18)
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(pkDestLabel)
+ .addComponent(fkaDestLabel)
+ .addComponent(fkbDestLabel))
+ .addGap(6, 6, 6)
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(pkDestTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
+ .addComponent(fkaDestTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, paramPanelLayout.createSequentialGroup()
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(fkbDestTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(fkbModifyButton)
+ .addComponent(fkaModifyButton)
+ .addComponent(pkModifyButton))))
+ .addContainerGap())
+ );
+ paramPanelLayout.setVerticalGroup(
+ paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(paramPanelLayout.createSequentialGroup()
+ .addComponent(pkCheckBox)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(pkSrcLabel)
+ .addComponent(pkModifyButton)
+ .addComponent(pkDestTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(pkSrcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(pkDestLabel))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(fkaCheckBox)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(fkaSrcLabel)
+ .addComponent(fkaDestTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(fkaModifyButton)
+ .addComponent(fkaSrcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(fkaDestLabel))
+ .addGap(7, 7, 7)
+ .addComponent(fkbCheckBox)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(paramPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(fkbSrcLabel)
+ .addComponent(fkbSrcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(fkbDestTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(fkbModifyButton)
+ .addComponent(fkbDestLabel))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+
+ manualCheckBox.setText(org.openide.util.NbBundle.getMessage(NameConvertionPanel.class, "TXT_NC_Manual")); // NOI18N
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(paramPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(manualCheckBox)
+ .addComponent(nameConvertionCheckBox)
+ .addComponent(errorLabel))
+ .addContainerGap())
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(nameConvertionCheckBox)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(paramPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(manualCheckBox)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(errorLabel)
+ .addContainerGap())
+ );
+ }// //GEN-END:initComponents
+
+ private void nameConvertionCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameConvertionCheckBoxActionPerformed
+ useNCCheckBoxChanged();
+}//GEN-LAST:event_nameConvertionCheckBoxActionPerformed
+
+ private void pkModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pkModifyButtonActionPerformed
+ showPatternsDialog( 0 );
+ }//GEN-LAST:event_pkModifyButtonActionPerformed
+
+ private void fkaModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fkaModifyButtonActionPerformed
+ showPatternsDialog( 1 );
+ }//GEN-LAST:event_fkaModifyButtonActionPerformed
+
+ private void fkbModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fkbModifyButtonActionPerformed
+ showPatternsDialog( 2 );
+ }//GEN-LAST:event_fkbModifyButtonActionPerformed
+
+ private void pkCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pkCheckBoxActionPerformed
+ fieldCheckBoxChanged(0);
+ }//GEN-LAST:event_pkCheckBoxActionPerformed
+
+ private void fkbCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fkbCheckBoxActionPerformed
+ fieldCheckBoxChanged(2);
+ }//GEN-LAST:event_fkbCheckBoxActionPerformed
+
+ private void fkaCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fkaCheckBoxActionPerformed
+ fieldCheckBoxChanged(1);
+ }//GEN-LAST:event_fkaCheckBoxActionPerformed
+
+ /** enables or disables parameters panel */
+ private void useNCCheckBoxChanged() {
+ boolean active = nameConvertionCheckBox.isSelected();
+ pkCheckBox.setEnabled(active);
+ fkaCheckBox.setEnabled(active);
+ fkbCheckBox.setEnabled(active);
+ manualCheckBox.setEnabled(active);
+
+ for( int i = 0 ; i < 3 ; ++i )
+ fieldCheckBoxChanged( i );
+ }
+
+ private void showPatternsDialog( int fieldType ) {
+ // prepearing dialog
+ NameConvertionPatternsPanel panel = null;
+
+ switch (fieldType) {
+ case 0:
+ panel = new NameConvertionPatternsPanel( fieldType, pkSrcTextField.getText(), pkDestTextField.getText() );
+ break;
+ case 1:
+ panel = new NameConvertionPatternsPanel( fieldType, fkaSrcTextField.getText(), fkaDestTextField.getText() );
+ break;
+ case 2:
+ panel = new NameConvertionPatternsPanel( fieldType, fkbSrcTextField.getText(), fkbDestTextField.getText() );
+ break;
+ default:
+ throw new IndexOutOfBoundsException();
+ }
+ org.openide.DialogDescriptor nameConvDD = new org.openide.DialogDescriptor( panel , "Name convertion patterns" );
+ panel.setDialogDescriptor(nameConvDD);
+ nameConvDD.setModal( true );
+ // showing dialog
+ org.openide.DialogDisplayer.getDefault().notify( nameConvDD );
+
+ // getting result
+ if ( nameConvDD.getValue() == org.openide.NotifyDescriptor.OK_OPTION ) {
+ panel.setDialogDescriptor(null);
+ switch ( fieldType ) {
+ case 0:
+ pkSrcTextField.setText( panel.getSrcExpression() );
+ pkDestTextField.setText( panel.getDestExpression() );
+ break;
+
+ case 1:
+ fkaSrcTextField.setText( panel.getSrcExpression() );
+ fkaDestTextField.setText( panel.getDestExpression() );
+ break;
+
+ case 2:
+ fkbSrcTextField.setText( panel.getSrcExpression() );
+ fkbDestTextField.setText( panel.getDestExpression() );
+ break;
+ }
+ panel.savePatterns();
+ }
+ }
+
+ private void fieldCheckBoxChanged( int fieldType ) {
+ boolean active = nameConvertionCheckBox.isSelected();
+
+ switch ( fieldType ) {
+ case 0:
+ active &= pkCheckBox.isSelected();
+ pkSrcLabel.setEnabled(active);
+ pkSrcTextField.setEnabled(active);
+ pkDestLabel.setEnabled(active);
+ pkDestTextField.setEnabled(active);
+ pkModifyButton.setEnabled(active);
+ break;
+ case 1:
+ active &= fkaCheckBox.isSelected();
+ fkaSrcLabel.setEnabled(active);
+ fkaSrcTextField.setEnabled(active);
+ fkaDestLabel.setEnabled(active);
+ fkaDestTextField.setEnabled(active);
+ fkaModifyButton.setEnabled(active);
+ break;
+ case 2:
+ active &= fkbCheckBox.isSelected();
+ fkbSrcLabel.setEnabled(active);
+ fkbSrcTextField.setEnabled(active);
+ fkbDestLabel.setEnabled(active);
+ fkbDestTextField.setEnabled(active);
+ fkbModifyButton.setEnabled(active);
+ break;
+ }
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.ButtonGroup buttonGroup1;
+ private javax.swing.JLabel errorLabel;
+ private javax.swing.JCheckBox fkaCheckBox;
+ private javax.swing.JLabel fkaDestLabel;
+ private javax.swing.JTextField fkaDestTextField;
+ private javax.swing.JButton fkaModifyButton;
+ private javax.swing.JLabel fkaSrcLabel;
+ private javax.swing.JTextField fkaSrcTextField;
+ private javax.swing.JCheckBox fkbCheckBox;
+ private javax.swing.JLabel fkbDestLabel;
+ private javax.swing.JTextField fkbDestTextField;
+ private javax.swing.JButton fkbModifyButton;
+ private javax.swing.JLabel fkbSrcLabel;
+ private javax.swing.JTextField fkbSrcTextField;
+ private javax.swing.JCheckBox manualCheckBox;
+ private javax.swing.JCheckBox nameConvertionCheckBox;
+ private javax.swing.JPanel paramPanel;
+ private javax.swing.JCheckBox pkCheckBox;
+ private javax.swing.JLabel pkDestLabel;
+ private javax.swing.JTextField pkDestTextField;
+ private javax.swing.JButton pkModifyButton;
+ private javax.swing.JLabel pkSrcLabel;
+ private javax.swing.JTextField pkSrcTextField;
+ // End of variables declaration//GEN-END:variables
+}
+
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPatternsPanel.form b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPatternsPanel.form
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPatternsPanel.form
@@ -0,0 +1,138 @@
+
+
+
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPatternsPanel.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPatternsPanel.java
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionPatternsPanel.java
@@ -0,0 +1,445 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+
+/*
+ * NameConvertionPatternsPanel.java
+ *
+ * Created on 01.05.2009, 17:59:48
+ */
+
+package org.netbeans.modules.j2ee.persistence.wizard.fromdb;
+
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.DefaultTableModel;
+import org.openide.util.NbBundle;
+import org.openide.DialogDescriptor;
+import org.openide.util.ImageUtilities;
+import org.openide.util.NbPreferences;
+
+/**
+ * Class provides panel which allows to store regular expression convertions
+ * @author Tomilov Mikhail
+ */
+public class NameConvertionPatternsPanel extends javax.swing.JPanel {
+
+ private int fieldType;
+ private DialogDescriptor dialogDescriptor = null;
+
+ /** Creates new form NameConvertionPatternsPanel */
+ public NameConvertionPatternsPanel( int fieldType, String src, String dest ) {
+ initComponents();
+
+ this.fieldType = fieldType;
+
+ // patterns loading
+ String patterns = null;
+ switch ( fieldType ) {
+ case 0 :
+ patterns = NbPreferences.forModule( NameConvertionProperties.class ).get("pk", "");
+ break;
+ case 1:
+ patterns = NbPreferences.forModule( NameConvertionProperties.class ).get("fka", "");
+ break;
+ case 2:
+ patterns = NbPreferences.forModule( NameConvertionProperties.class ).get("fkb", "");
+ break;
+ }
+
+ DefaultTableModel model = (DefaultTableModel) patternTable.getModel();
+ String newRow[] = null;
+ int currentRow = 0;
+ String ex[] = patterns.split(";");
+ model.setRowCount( 0 );
+ newRow = new String[ 2 ];
+ newRow[ 0 ] = "User input";
+ newRow[ 1 ] = "";
+ model.addRow(newRow);
+ for( int j = 0 ; j + 1 < ex.length ; j += 2 ) {
+ newRow = new String[ 2 ];
+
+ if ( src.equals( ex[ j ] ) && dest.equals( ex[ j + 1 ] ) )
+ currentRow = 1 + (int) (j / 2);
+
+ newRow[ 0 ] = ex[ j ];
+ newRow[ 1 ] = ex[ j + 1 ];
+ model.addRow(newRow);
+ }
+
+ patternTable.getSelectionModel().setSelectionInterval(currentRow, currentRow);
+ tableSelectionChange();
+ if ( currentRow == 0 ) {
+ srcTextField.setText(src);
+ destTextField.setText(dest);
+ }
+
+ patternTable.getColumnModel().getColumn(0).setHeaderValue(
+ NbBundle.getMessage(NameConvertionPanel.class, "TXT_TableSourceHeader"));
+ patternTable.getColumnModel().getColumn(1).setHeaderValue(
+ NbBundle.getMessage(NameConvertionPanel.class, "TXT_TableTargetHeader"));
+
+ SelectionListener sl = new SelectionListener();
+ patternTable.getSelectionModel().addListSelectionListener(sl);
+ patternTable.getColumnModel().getSelectionModel().addListSelectionListener(sl);
+ }
+
+ /**
+ * prepares regular expression for names convertion. preparation need cause
+ * names convertion must have ability to change character's register
+ * @param regexp raw regular expression
+ * @return prepared expression
+ */
+ private String prepareRegExp( String regexp )
+ {
+ for( int i = 0 ; i < regexp.length() ; ++i )
+ if ( regexp.charAt(i) == '$' )
+ {
+ // if $-char is escaped
+ if ( i > 0 && regexp.charAt(i - 1) == '\\' )
+ continue;
+
+ // if no number after $
+ if ( i + 2 >= regexp.length() )
+ continue;
+
+ if ( regexp.charAt(i+1) != '>' && regexp.charAt(i+1) != '<' )
+ continue;
+
+ int endPos = i + 2;
+ while ( endPos < regexp.length() && regexp.charAt(endPos) >= '0'
+ && regexp.charAt(endPos) <= '9' )
+ ++endPos;
+
+ // no number
+ if ( endPos == i+2 )
+ continue;
+
+ // replacing
+ regexp = regexp.substring(0, i) + regexp.charAt(i+1) + regexp.charAt(i)
+ + regexp.substring(i+2, endPos) + regexp.substring(endPos) ;
+
+ ++i;
+ }
+
+ return regexp;
+ }
+
+ public void setDialogDescriptor(DialogDescriptor dialogDescriptor) {
+ this.dialogDescriptor = dialogDescriptor;
+ }
+
+ public String getSrcExpression() {
+ return srcTextField.getText();
+ }
+
+ public String getDestExpression() {
+ return prepareRegExp( destTextField.getText() );
+ }
+
+ /** saves regular expression patterns */
+ public void savePatterns() {
+ String val = "";
+
+ DefaultTableModel model = (DefaultTableModel) patternTable.getModel();
+ for( int j = 1 ; j < model.getRowCount() ; ++j )
+ val += model.getValueAt(j, 0) + ";" + model.getValueAt(j, 1) + ";";
+
+ switch ( fieldType )
+ {
+ case 0: NbPreferences.forModule( NameConvertionPatternsPanel.class ).put("pk", val);break;
+ case 1: NbPreferences.forModule( NameConvertionPatternsPanel.class ).put("fka", val);break;
+ case 2: NbPreferences.forModule( NameConvertionPatternsPanel.class ).put("fkb", val);break;
+ }
+ }
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ jScrollPane1 = new javax.swing.JScrollPane();
+ patternTable = new javax.swing.JTable();
+ srcLabel = new javax.swing.JLabel();
+ srcTextField = new javax.swing.JTextField();
+ destLabel = new javax.swing.JLabel();
+ destTextField = new javax.swing.JTextField();
+ addButton = new javax.swing.JButton();
+ removeButton = new javax.swing.JButton();
+ errorLabel = new javax.swing.JLabel();
+
+ patternTable.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+ {null, null},
+ {null, null},
+ {null, null},
+ {null, null}
+ },
+ new String [] {
+ "Title 1", "Title 2"
+ }
+ ) {
+ Class[] types = new Class [] {
+ java.lang.String.class, java.lang.String.class
+ };
+ boolean[] canEdit = new boolean [] {
+ false, false
+ };
+
+ public Class getColumnClass(int columnIndex) {
+ return types [columnIndex];
+ }
+
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return canEdit [columnIndex];
+ }
+ });
+ patternTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+ jScrollPane1.setViewportView(patternTable);
+
+ srcLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPatternsPanel.class, "TXT_NCP_SRC_LABEL")); // NOI18N
+
+ srcTextField.addKeyListener(new java.awt.event.KeyAdapter() {
+ public void keyReleased(java.awt.event.KeyEvent evt) {
+ srcTextFieldKeyReleased(evt);
+ }
+ });
+
+ destLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPatternsPanel.class, "TXT_NCP_TAR_LABEL")); // NOI18N
+
+ destTextField.addKeyListener(new java.awt.event.KeyAdapter() {
+ public void keyReleased(java.awt.event.KeyEvent evt) {
+ destTextFieldKeyReleased(evt);
+ }
+ });
+
+ addButton.setText(org.openide.util.NbBundle.getMessage(NameConvertionPatternsPanel.class, "TXT_NCP_ADD_BUTTON")); // NOI18N
+ addButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ addButtonActionPerformed(evt);
+ }
+ });
+
+ removeButton.setText(org.openide.util.NbBundle.getMessage(NameConvertionPatternsPanel.class, "TXT_NCP_REMOVE_BUTTON")); // NOI18N
+ removeButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ removeButtonActionPerformed(evt);
+ }
+ });
+
+ errorLabel.setText(org.openide.util.NbBundle.getMessage(NameConvertionPatternsPanel.class, "NameConvertionPatternsPanel.errorLabel.text")); // NOI18N
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(srcLabel)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(srcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(18, 18, 18)
+ .addComponent(destLabel)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(destTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(addButton)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(removeButton))
+ .addComponent(errorLabel))
+ .addContainerGap())
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(srcLabel)
+ .addComponent(destLabel)
+ .addComponent(destTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(addButton)
+ .addComponent(removeButton)
+ .addComponent(srcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(errorLabel)
+ .addContainerGap())
+ );
+ }// //GEN-END:initComponents
+
+ private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
+ DefaultTableModel model = (DefaultTableModel) patternTable.getModel();
+ Object firstRow[] = new Object[ 2 ];
+ firstRow[ 0 ] = srcTextField.getText();
+ firstRow[ 1 ] = destTextField.getText();
+ model.addRow( firstRow );
+
+ int row = patternTable.getRowCount() - 1;
+ patternTable.getSelectionModel().setSelectionInterval(row, row);
+ }//GEN-LAST:event_addButtonActionPerformed
+
+ private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
+ int row = patternTable.getSelectedRow();
+
+ if ( row < 1 )
+ return;
+
+ patternTable.getSelectionModel().setSelectionInterval(0, 0);
+ DefaultTableModel model = (DefaultTableModel) patternTable.getModel();
+ model.removeRow(row);
+
+ if ( row == patternTable.getRowCount() ) // last row
+ --row;
+
+ patternTable.getSelectionModel().setSelectionInterval(row, row);
+ }//GEN-LAST:event_removeButtonActionPerformed
+
+ private void destTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_destTextFieldKeyReleased
+ checkRegExpConversion();
+ }//GEN-LAST:event_destTextFieldKeyReleased
+
+ private void srcTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_srcTextFieldKeyReleased
+ checkRegExpConversion();
+ }//GEN-LAST:event_srcTextFieldKeyReleased
+
+ private void tableSelectionChange()
+ {
+ int row = patternTable.getSelectedRow();
+
+ /// javax.swing.JOptionPane.showMessageDialog(null, "tableSelectionChange " + row);
+ if ( row == -1 || row >= patternTable.getRowCount() )
+ {
+ return;
+ //row = ncprops.getSelectedIndexAt( lastFieldTypeIndex );
+ //patternTable.getSelectionModel().setSelectionInterval( row, row );
+ }
+
+ if ( row == 0 ){
+ // user input row
+ srcLabel.setEnabled(true);
+ destLabel.setEnabled(true);
+ srcTextField.setEnabled(true);
+ destTextField.setEnabled(true);
+ removeButton.setEnabled(false);
+ addButton.setEnabled(true);
+ srcTextField.setText( "" );
+ destTextField.setText( "" );
+ }
+ else{
+ srcTextField.setEnabled(false);
+ destTextField.setEnabled(false);
+ removeButton.setEnabled(true);
+ addButton.setEnabled(false);
+
+ DefaultTableModel model = (DefaultTableModel)patternTable.getModel();
+ srcTextField.setText((String) model.getValueAt(row, 0));
+ destTextField.setText((String) model.getValueAt(row, 1));
+ }
+ }
+
+ /** checks regular expression replacion. also it sets error message label */
+ void checkRegExpConversion(){
+ String src = srcTextField.getText();
+ String dest = destTextField.getText();
+ boolean correct = true;
+
+ try{
+ Pattern.compile(src);
+ } catch ( PatternSyntaxException ex ){
+ correct = false;
+ }
+
+ if ( src.matches(".*[;!@#%&].*") )
+ correct = false;
+
+ String exp;
+ if ( fieldType == 0 )
+ exp = "([a-zA-Z0-9_]*(\\$[<>][0-9])*(%[<>]ENTITY%)?)+";
+ else
+ exp = "([a-zA-Z0-9_]*(\\$[<>][0-9])*(%[<>]REFENTITY%)?(%[<>]ENTITY%)?)+";
+
+ if ( !dest.matches(exp) )
+ correct = false;
+
+ if ( correct ){
+ if ( dialogDescriptor != null )
+ dialogDescriptor.setValid(true);
+
+ addButton.setEnabled(true);
+ errorLabel.setIcon( null );
+ errorLabel.setText( null );
+ }
+ else {
+ errorLabel.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/j2ee/persistence/ui/resources/warning.gif", false));
+ errorLabel.setText(NbBundle.getMessage(NameConvertionPatternsPanel.class, "ERR_IncorrectRegExp"));
+ addButton.setEnabled(false);
+
+ if ( dialogDescriptor != null )
+ dialogDescriptor.setValid(false);
+ }
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton addButton;
+ private javax.swing.JLabel destLabel;
+ private javax.swing.JTextField destTextField;
+ private javax.swing.JLabel errorLabel;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTable patternTable;
+ private javax.swing.JButton removeButton;
+ private javax.swing.JLabel srcLabel;
+ private javax.swing.JTextField srcTextField;
+ // End of variables declaration//GEN-END:variables
+
+ /** patterns table selection change listener */
+ class SelectionListener implements ListSelectionListener {
+ public void valueChanged(ListSelectionEvent e) {
+ NameConvertionPatternsPanel.this.tableSelectionChange();
+ }
+ }
+}
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionProperties.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionProperties.java
new file mode 100644
--- /dev/null
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/NameConvertionProperties.java
@@ -0,0 +1,167 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.j2ee.persistence.wizard.fromdb;
+
+/**
+ * Class just stores names convertion properties
+ * @author Tomilov Mikhail
+ */
+public class NameConvertionProperties {
+ /** is names convertion activated */
+ private boolean active = false;
+ /** is using regular expressions selected */
+ private boolean[] useRegExp = new boolean[ 3 ];
+ /** is uing manual convertion selected */
+ private boolean useManual = false;
+ /** source regular expressions */
+ private String[] srcExpr = new String[ 3 ];
+ /** destination regular expressions */
+ private String[] destExpr = new String[ 3 ];
+ /** saved regular expression offers */
+
+ /** default constructor sets defaults */
+ public NameConvertionProperties() {
+ for( int i = 0 ; i < 3 ; ++i ) {
+ useRegExp[ i ] = false;
+ srcExpr[ i ] = null;
+ destExpr[ i ] = null;
+ }
+ }
+
+ /** constructs copy for parameters dialog */
+ public NameConvertionProperties( NameConvertionProperties ncp ) {
+ active = ncp.active;
+ useManual = ncp.useManual;
+
+ for( int i = 0 ; i < 3 ; ++i ) {
+ useRegExp[ i ] = ncp.useRegExp[ i ];
+ srcExpr[ i ] = ncp.srcExpr[ i ];
+ destExpr[ i ] = ncp.destExpr[ i ];
+ }
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public String getDestExprPK() {
+ return destExpr[ 0 ];
+ }
+
+ public String getDestExprFKA() {
+ return destExpr[ 1 ];
+ }
+
+ public String getDestExprFKB() {
+ return destExpr[ 2 ];
+ }
+
+ public void setDestExprPK(String destExpr) {
+ this.destExpr[ 0 ] = destExpr;
+ }
+
+ public void setDestExprFKA(String destExpr) {
+ this.destExpr[ 1 ] = destExpr;
+ }
+
+ public void setDestExprFKB(String destExpr) {
+ this.destExpr[ 2 ] = destExpr;
+ }
+
+ public String getSrcExprPK() {
+ return srcExpr[ 0 ];
+ }
+
+ public String getSrcExprFKA() {
+ return srcExpr[ 1 ];
+ }
+
+ public String getSrcExprFKB() {
+ return srcExpr[ 2 ];
+ }
+
+ public void setSrcExprPK(String srcExpr) {
+ this.srcExpr[ 0 ] = srcExpr;
+ }
+
+ public void setSrcExprFKA(String srcExpr) {
+ this.srcExpr[ 1 ] = srcExpr;
+ }
+
+ public void setSrcExprFKB(String srcExpr) {
+ this.srcExpr[ 2 ] = srcExpr;
+ }
+
+ public boolean isUseManual() {
+ return useManual;
+ }
+
+ public void setUseManual(boolean useManual) {
+ this.useManual = useManual;
+ }
+
+ public boolean isUseRegExpPK() {
+ return useRegExp[ 0 ];
+ }
+
+ public boolean isUseRegExpFKA() {
+ return useRegExp[ 1 ];
+ }
+
+ public boolean isUseRegExpFKB() {
+ return useRegExp[ 2 ];
+ }
+
+ public void setUseRegExpPK(boolean useRegExp) {
+ this.useRegExp[ 0 ] = useRegExp;
+ }
+
+ public void setUseRegExpFKA(boolean useRegExp) {
+ this.useRegExp[ 1 ] = useRegExp;
+ }
+
+ public void setUseRegExpFKB(boolean useRegExp) {
+ this.useRegExp[ 2 ] = useRegExp;
+ }
+}
diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/RelatedCMPHelper.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/RelatedCMPHelper.java
--- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/RelatedCMPHelper.java
+++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/RelatedCMPHelper.java
@@ -95,15 +95,27 @@
private FetchType fetchType = FetchType.DEFAULT;
private boolean regenTablesAttrs = false;
private CollectionType collectionType = CollectionType.COLLECTION;
+
+ /** name convertion properties */
+ private NameConvertionProperties nameConvertionProperties;
public RelatedCMPHelper(Project project, FileObject configFilesFolder, PersistenceGenerator persistenceGen) {
this.project = project;
this.configFilesFolder = configFilesFolder;
this.persistenceGen = persistenceGen;
+ this.nameConvertionProperties = new NameConvertionProperties();
tableSource = TableSource.get(project);
dbschemaFileList = new DBSchemaFileList(project, configFilesFolder);
}
+
+ public NameConvertionProperties getNameConvertionProperties() {
+ return nameConvertionProperties;
+ }
+
+ public void setNameConvertionProperties(NameConvertionProperties namesConvertionProperties) {
+ this.nameConvertionProperties = namesConvertionProperties;
+ }
public Project getProject() {
return project;
@@ -307,7 +319,7 @@
}
}
- generator = new DbSchemaEjbGenerator(genTables, schemaElement);
+ generator = new DbSchemaEjbGenerator(genTables, schemaElement, nameConvertionProperties);
}
public EntityClass[] getBeans() {
diff --git a/java.helpset/javahelp/org/netbeans/modules/java/helpset/docs/javadev-map.jhm b/java.helpset/javahelp/org/netbeans/modules/java/helpset/docs/javadev-map.jhm
--- a/java.helpset/javahelp/org/netbeans/modules/java/helpset/docs/javadev-map.jhm
+++ b/java.helpset/javahelp/org/netbeans/modules/java/helpset/docs/javadev-map.jhm
@@ -271,6 +271,7 @@
+
diff --git a/java.helpset/javahelp/org/netbeans/modules/java/helpset/docs/persistence/general/persistence_nameconvertion.html b/java.helpset/javahelp/org/netbeans/modules/java/helpset/docs/persistence/general/persistence_nameconvertion.html
new file mode 100644
--- /dev/null
+++ b/java.helpset/javahelp/org/netbeans/modules/java/helpset/docs/persistence/general/persistence_nameconvertion.html
@@ -0,0 +1,38 @@
+
+
+
+
+
+ Name convertion
+
+
+
+
+
+ Name convertion options
+ See Also
+ Name convertion allows you to change default java classes field names
+
+
+ You may use regular expressions for converting and/or manual convertion (to adjust automatic name convertion for example). Regular expressions are applied separately for different field types. You may store your regular expression patterns using Add button (optional).
+
+ You may use the following keywords in target expressions:
+
+ %>ENTITY% or %<ENTITY% is a name of a class which corresponding current field. If second charater is '>' then replacement begins with capital letter, if it is '<', then replacement begins with lower-case letter.
+ %>REFENTITY% or %<REFENTITY% can be used for foreign key and field corresponding to foreign key only. The replacement for this keyword is the referenced entity name.
+
+
+ Also, you can use Java regular expression groups capturing mechanism. But with a little difference. You must use '>' or '<' symbol to indicate whether the first letter should be upper-case or lower-case. For example, $<1 is a first group but with decapitalized first letter.
+
+
+ Legal Notices
+
+
+
+