Skip to content

Commit 60764a2

Browse files
authored
Merge pull request #14 from xcomart/devel
Devel
2 parents 01cc890 + b198028 commit 60764a2

File tree

12 files changed

+129
-42
lines changed

12 files changed

+129
-42
lines changed

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Generating text files using table information and templates.
149149
|Templates|Select template to be generated, click `Select` table header to select/deselect all template|
150150
|Output Directory|Output location of generated text/source files|
151151
|Author Name|Author text(`${author}` in template) which used in template.<br/>(ex. John Doe &lt;john.doe@abc.com&gt;)|
152+
|Abbreviation|Check if you want apply abbreviation replace to all items which has `.abbr` or not|
152153
|Custom Variables|User defined `item type` variables which used in templates.|
153154
|Dark UI|Change UI theme to dark/light.|
154155
|Generate|Start generate process, [Progress Window](#progress-window) will be shown.|
@@ -161,6 +162,8 @@ Generating text files using table information and templates.
161162
Manage abbreviation mapping rules.
162163
This abbreviation mapping will be applied in [`.abbr` decorator of `item` statement](#item-statement).
163164

165+
If you check total name it will check and replace name itself not each words.
166+
164167

165168
### Progress Window
166169

docs/images/abbreviation.png

1.52 KB
Loading

docs/images/generator_main.png

-3.04 KB
Loading

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>jdbgen</artifactId>
66
<name>jdbgen</name>
77
<packaging>jar</packaging>
8-
<version>0.2.2</version>
8+
<version>0.2.3</version>
99
<build>
1010
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
1111
<outputDirectory>${basedir}/target/classes</outputDirectory>
@@ -138,6 +138,7 @@
138138
<configuration>
139139
<source>11</source>
140140
<target>11</target>
141+
<release>11</release>
141142
<encoding>UTF-8</encoding>
142143
</configuration>
143144
</plugin>

src/main/java/comart/tools/jdbgen/template/TemplateManager.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.List;
3737
import java.util.Map;
3838
import java.util.Set;
39+
import java.util.StringTokenizer;
3940
import java.util.logging.Level;
4041
import java.util.logging.Logger;
4142
import java.util.regex.Matcher;
@@ -463,25 +464,29 @@ private static String procReplace(String item, List<Object> params) {
463464

464465
@SuppressWarnings("unused")
465466
private static String procAbbr(String item, List<Object> params) {
466-
// add last underbar for convenience
467-
item = item + "_";
468-
StringBuilder res = new StringBuilder();
469-
StringBuilder buf = new StringBuilder();
470-
for (char c: item.toCharArray()) {
471-
if (c == '_' || c == '-') {
472-
String word = buf.toString();
473-
if (JDBAbbr.abbrMap.containsKey(word))
474-
word = JDBAbbr.abbrMap.get(word);
475-
res.append(word);
476-
res.append(c);
477-
buf = new StringBuilder();
478-
} else {
479-
buf.append(c);
467+
if (JDBAbbr.abbrNameMap.containsKey(item.toLowerCase())) {
468+
return JDBAbbr.abbrNameMap.get(item.toLowerCase());
469+
} else {
470+
// add last underbar for convenience
471+
item = item + "_";
472+
StringBuilder res = new StringBuilder();
473+
StringBuilder buf = new StringBuilder();
474+
for (char c: item.toCharArray()) {
475+
if (c == '_' || c == '-') {
476+
String word = buf.toString();
477+
if (JDBAbbr.abbrMap.containsKey(word))
478+
word = JDBAbbr.abbrMap.get(word);
479+
res.append(word);
480+
res.append(c);
481+
buf = new StringBuilder();
482+
} else {
483+
buf.append(c);
484+
}
480485
}
486+
// remove last underbar
487+
res.deleteCharAt(res.length()-1);
488+
return res.toString();
481489
}
482-
// remove last underbar
483-
res.deleteCharAt(res.length()-1);
484-
return res.toString();
485490
}
486491

487492
private static final Map<String, TemplateHandler> handlers = new HashMap<>();
@@ -718,7 +723,7 @@ private static boolean condContains(String key, String condVal, Object mapper, M
718723
}
719724
}
720725
} else {
721-
throw new RuntimeException("contains/notcontains in if statement item must be a collection object or contain/notcontain value must be a ',' separated string.");
726+
throw new RuntimeException("contains/notcontains in if statement item must be a collection object or a ',' separated string.");
722727
}
723728
return contains;
724729
}

src/main/java/comart/tools/jdbgen/types/JDBAbbr.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838
@AllArgsConstructor
3939
public class JDBAbbr {
4040
Boolean check;
41+
Boolean totalName;
4142
String abbr;
4243
String replaceTo;
4344

4445
public Object[] getRowArray() {
45-
return new Object[]{ check, abbr, replaceTo };
46+
return new Object[]{ check, totalName, abbr, replaceTo };
4647
}
4748

4849
@Override
@@ -51,11 +52,19 @@ public String toString() {
5152
}
5253

5354
public static Map<String, String> abbrMap = null;
55+
public static Map<String, String> abbrNameMap = null;
5456
public static void buildMap() {
5557
abbrMap = new HashMap<>();
58+
abbrNameMap = new HashMap<>();
5659
JDBGenConfig.getInstance().getAbbrs().forEach(a -> {
57-
if (a.check)
58-
abbrMap.put(a.abbr, a.replaceTo);
60+
if (a.check) {
61+
if (a.totalName == null) a.totalName = false;
62+
if (a.totalName) {
63+
abbrNameMap.put(a.abbr.toLowerCase(), a.replaceTo);
64+
} else {
65+
abbrMap.put(a.abbr.toLowerCase(), a.replaceTo);
66+
}
67+
}
5968
});
6069
}
6170
}

src/main/java/comart/tools/jdbgen/types/JDBGenConfig.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public static synchronized JDBGenConfig getInstance(boolean useDefault) {
7575
Gson gson = new Gson();
7676
if (!useDefault) {
7777
for (int cnt=0; cnt < 3; cnt++) {
78-
String master = UIUtils.password("Enter master password", !(f.exists() && f.isFile()));
78+
boolean isNew = !(f.exists() && f.isFile());
79+
String message = isNew ? "Enter new master password": "Enter master password";
80+
String master = UIUtils.password(message, isNew);
7981
if (master == null)
8082
System.exit(1);
8183
StrUtils.setMaster(master);
@@ -94,6 +96,10 @@ public static synchronized JDBGenConfig getInstance(boolean useDefault) {
9496
if (!isOk) {
9597
System.exit(1);
9698
}
99+
master = UIUtils.password("Enter new master password", true);
100+
if (master == null)
101+
System.exit(1);
102+
StrUtils.setMaster(master);
97103
}
98104
}
99105
} else {

src/main/java/comart/tools/jdbgen/ui/JDBAbbreviationMapper.form

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,18 @@
7979
<Component class="javax.swing.JTable" name="tblMapping">
8080
<Properties>
8181
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
82-
<Table columnCount="3" rowCount="1">
82+
<Table columnCount="4" rowCount="1">
8383
<Column editable="true" title="Apply" type="java.lang.Boolean"/>
84+
<Column editable="true" title="Total Name" type="java.lang.Boolean"/>
8485
<Column editable="true" title="Abbreviation" type="java.lang.String"/>
8586
<Column editable="true" title="Replace To" type="java.lang.String"/>
8687
</Table>
8788
</Property>
8889
<Property name="toolTipText" type="java.lang.String" value="Abbreviation Mapping Rules applied to object(table, column) name."/>
8990
</Properties>
91+
<Events>
92+
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="tblMappingMouseClicked"/>
93+
</Events>
9094
</Component>
9195
</SubComponents>
9296
</Container>

src/main/java/comart/tools/jdbgen/ui/JDBAbbreviationMapper.java

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@
2525

2626
import comart.tools.jdbgen.types.JDBAbbr;
2727
import comart.tools.jdbgen.types.JDBGenConfig;
28+
import comart.tools.jdbgen.types.db.DBTable;
2829
import comart.utils.StrUtils;
2930
import comart.utils.UIUtils;
3031
import java.awt.Frame;
32+
import java.awt.Point;
33+
import java.awt.event.MouseEvent;
3134
import java.util.ArrayList;
3235
import java.util.HashMap;
3336
import java.util.List;
3437
import java.util.logging.Logger;
38+
import javax.swing.JMenuItem;
39+
import javax.swing.JPopupMenu;
3540
import javax.swing.SwingUtilities;
3641
import javax.swing.UIManager;
3742
import javax.swing.table.DefaultTableModel;
@@ -76,8 +81,9 @@ public JDBAbbreviationMapper(java.awt.Frame parent, boolean modal) {
7681

7782
TableColumnModel colModel = tblMapping.getColumnModel();
7883
colModel.getColumn(0).setPreferredWidth(50);
79-
colModel.getColumn(1).setPreferredWidth(130);
80-
colModel.getColumn(2).setPreferredWidth(130);
84+
colModel.getColumn(1).setPreferredWidth(50);
85+
colModel.getColumn(2).setPreferredWidth(110);
86+
colModel.getColumn(3).setPreferredWidth(110);
8187

8288
applyIcons();
8389

@@ -90,12 +96,12 @@ public JDBAbbreviationMapper(java.awt.Frame parent, boolean modal) {
9096
mdl.setRowCount(0);
9197

9298
conf.getAbbrs().forEach(a -> mdl.addRow(a.getRowArray()));
93-
mdl.addRow(new Object[]{Boolean.FALSE, "", ""});
99+
mdl.addRow(new Object[]{Boolean.FALSE, Boolean.FALSE, "", ""});
94100

95101
tblMapping.getModel().addTableModelListener((evt) -> {
96102
if (checkDuplication(mdl)) {
97103
conf.setAbbrs(applyTableToList(mdl));
98-
UIUtils.tableSetLastEmpty(tblMapping.getModel(), 1);
104+
UIUtils.tableSetLastEmpty(tblMapping.getModel(), 2);
99105
}
100106
});
101107
UIUtils.setCommitOnLostFocus(tblMapping);
@@ -106,8 +112,8 @@ private boolean checkDuplication(DefaultTableModel model) {
106112
HashMap<String,String> map = new HashMap<>();
107113
for (int i=0; i<model.getRowCount(); i++) {
108114
Boolean check = (Boolean)model.getValueAt(i, 0);
109-
String k = (String)model.getValueAt(i, 1);
110-
String v = (String)model.getValueAt(i, 2);
115+
String k = (String)model.getValueAt(i, 2);
116+
String v = (String)model.getValueAt(i, 3);
111117
if (check && !StrUtils.isEmpty(k) && !StrUtils.isEmpty(v)) {
112118
if (map.containsKey(k)) {
113119
UIUtils.error(this, "'"+k+"' duplicated.");
@@ -129,10 +135,11 @@ public static List<JDBAbbr> applyTableToList(TableModel model) {
129135
List<JDBAbbr> abbrs = new ArrayList<>();
130136
for (int i=0; i<model.getRowCount(); i++) {
131137
Boolean check = (Boolean)model.getValueAt(i, 0);
132-
String k = (String)model.getValueAt(i, 1);
133-
String v = (String)model.getValueAt(i, 2);
138+
Boolean tname = (Boolean)model.getValueAt(i, 1);
139+
String k = (String)model.getValueAt(i, 2);
140+
String v = (String)model.getValueAt(i, 3);
134141
if (!StrUtils.isEmpty(k) && !StrUtils.isEmpty(v))
135-
abbrs.add(new JDBAbbr(check, k, v));
142+
abbrs.add(new JDBAbbr(check, tname, k, v));
136143
}
137144
return abbrs;
138145
}
@@ -159,21 +166,26 @@ private void initComponents() {
159166

160167
tblMapping.setModel(new javax.swing.table.DefaultTableModel(
161168
new Object [][] {
162-
{null, null, null}
169+
{null, null, null, null}
163170
},
164171
new String [] {
165-
"Apply", "Abbreviation", "Replace To"
172+
"Apply", "Total Name", "Abbreviation", "Replace To"
166173
}
167174
) {
168175
Class[] types = new Class [] {
169-
java.lang.Boolean.class, java.lang.String.class, java.lang.String.class
176+
java.lang.Boolean.class, java.lang.Boolean.class, java.lang.String.class, java.lang.String.class
170177
};
171178

172179
public Class getColumnClass(int columnIndex) {
173180
return types [columnIndex];
174181
}
175182
});
176183
tblMapping.setToolTipText("Abbreviation Mapping Rules applied to object(table, column) name.");
184+
tblMapping.addMouseListener(new java.awt.event.MouseAdapter() {
185+
public void mouseClicked(java.awt.event.MouseEvent evt) {
186+
tblMappingMouseClicked(evt);
187+
}
188+
});
177189
jScrollPane1.setViewportView(tblMapping);
178190

179191
btnOk.setText("Ok");
@@ -242,6 +254,29 @@ private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
242254
}
243255
}//GEN-LAST:event_btnDelActionPerformed
244256

257+
private void showPopupTrigger(java.awt.event.MouseEvent evt) {
258+
if (evt.getButton() == MouseEvent.BUTTON3) {
259+
Point p = evt.getPoint();
260+
int row = tblMapping.rowAtPoint(p);
261+
int col = tblMapping.columnAtPoint(p);
262+
Boolean tmap = (Boolean)mdl.getValueAt(row, 1);
263+
if (col == 2 && tmap != null && tmap) {
264+
JPopupMenu menu = new JPopupMenu();
265+
List<DBTable> tables = JDBGeneratorMain.INSTANCE.getTables();
266+
for (DBTable t: tables) {
267+
JMenuItem item = new JMenuItem(t.getName());
268+
item.addActionListener(e -> mdl.setValueAt(t.getName(), row, col));
269+
menu.add(item);
270+
}
271+
menu.show(evt.getComponent(), evt.getX(), evt.getY());
272+
}
273+
}
274+
}
275+
276+
private void tblMappingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblMappingMouseClicked
277+
showPopupTrigger(evt);
278+
}//GEN-LAST:event_tblMappingMouseClicked
279+
245280
/**
246281
* @param args the command line arguments
247282
*/

src/main/java/comart/tools/jdbgen/ui/JDBGeneratorMain.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public class JDBGeneratorMain extends javax.swing.JFrame {
7979
private List<DBTable> tables;
8080
private boolean autoReset = true;
8181

82+
public static JDBGeneratorMain INSTANCE = null;
83+
84+
public List<DBTable> getTables() {
85+
return tables;
86+
}
87+
8288
/**
8389
* Creates new form JDBGeneratorMain
8490
*/
@@ -112,6 +118,7 @@ public JDBGeneratorMain() {
112118
PlatformUtils.registerHandlers(e -> showAbout(), null, null, null);
113119

114120
this.pack();
121+
INSTANCE = this;
115122
}
116123

117124
private void showAbout() {

0 commit comments

Comments
 (0)