Skip to content

Commit ec619aa

Browse files
committed
Done milestone feature: customize column feature
1 parent 42741c1 commit ec619aa

File tree

8 files changed

+95
-114
lines changed

8 files changed

+95
-114
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.zzg</groupId>
55
<artifactId>mybatis-generator-gui</artifactId>
6-
<version>0.0.2</version>
6+
<version>0.3</version>
77

88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ public void generate() throws Exception {
8989
daoConfig.setConfigurationType("XMLMAPPER");
9090
daoConfig.setTargetPackage(generatorConfig.getDaoPackage());
9191
daoConfig.setTargetProject(generatorConfig.getProjectFolder() + "/" + generatorConfig.getDaoTargetFolder());
92-
// Comment
93-
CommentGeneratorConfiguration commentConfig = new CommentGeneratorConfiguration();
94-
commentConfig.addProperty("suppressAllComments", "true");
95-
commentConfig.addProperty("suppressDate", "true");
9692

9793
context.setId("myid");
9894
context.addTableConfiguration(tableConfig);
@@ -101,17 +97,24 @@ public void generate() throws Exception {
10197
context.setJavaModelGeneratorConfiguration(modelConfig);
10298
context.setSqlMapGeneratorConfiguration(mapperConfig);
10399
context.setJavaClientGeneratorConfiguration(daoConfig);
104-
context.setCommentGeneratorConfiguration(commentConfig);
100+
// Comment
101+
if (generatorConfig.isComment()) {
102+
CommentGeneratorConfiguration commentConfig = new CommentGeneratorConfiguration();
103+
commentConfig.addProperty("suppressAllComments", "true");
104+
commentConfig.addProperty("suppressDate", "true");
105+
context.setCommentGeneratorConfiguration(commentConfig);
106+
}
105107
// limit/offset插件
106-
PluginConfiguration pluginConfiguration = new PluginConfiguration();
107-
pluginConfiguration.addProperty("type", "com.zzg.mybatis.generator.plugins.MySQLLimitPlugin");
108-
pluginConfiguration.setConfigurationType("com.zzg.mybatis.generator.plugins.MySQLLimitPlugin");
109-
context.addPluginConfiguration(pluginConfiguration);
110-
108+
if (generatorConfig.isOffsetLimit()) {
109+
PluginConfiguration pluginConfiguration = new PluginConfiguration();
110+
pluginConfiguration.addProperty("type", "com.zzg.mybatis.generator.plugins.MySQLLimitPlugin");
111+
pluginConfiguration.setConfigurationType("com.zzg.mybatis.generator.plugins.MySQLLimitPlugin");
112+
context.addPluginConfiguration(pluginConfiguration);
113+
}
111114
context.setTargetRuntime("MyBatis3");
112115

113116
List<String> warnings = new ArrayList<>();
114-
Set<String> fullyqualifiedTables = new HashSet<String>();
117+
Set<String> fullyqualifiedTables = new HashSet<>();
115118
Set<String> contexts = new HashSet<>();
116119
ShellCallback shellCallback = new DefaultShellCallback(true); // override=true
117120
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);

src/main/java/com/zzg/mybatis/generator/controller/BaseFXController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public abstract class BaseFXController implements Initializable {
2727
private static Map<FXMLPage, SoftReference<? extends BaseFXController>> cacheNodeMap = new HashMap<>();
2828

2929
public BaseFXController loadFXMLPage(String title, FXMLPage fxmlPage) {
30-
// SoftReference<? extends BaseFXController> parentNodeRef = cacheNodeMap.get(fxmlPage);
31-
// if (parentNodeRef != null) {
32-
// return parentNodeRef.get();
33-
// }
30+
SoftReference<? extends BaseFXController> parentNodeRef = cacheNodeMap.get(fxmlPage);
31+
if (parentNodeRef != null) {
32+
return parentNodeRef.get();
33+
}
3434
URL skeletonResource = Thread.currentThread().getContextClassLoader().getResource(fxmlPage.getFxml());
3535
FXMLLoader loader = new FXMLLoader(skeletonResource);
3636
Parent loginNode;
@@ -47,8 +47,8 @@ public BaseFXController loadFXMLPage(String title, FXMLPage fxmlPage) {
4747
dialogStage.show();
4848
controller.setDialogStage(dialogStage);
4949
// put into cache map
50-
//SoftReference<BaseFXController> softReference = new SoftReference<>(controller);
51-
// cacheNodeMap.put(fxmlPage, softReference);
50+
SoftReference<BaseFXController> softReference = new SoftReference<>(controller);
51+
cacheNodeMap.put(fxmlPage, softReference);
5252

5353
return controller;
5454
} catch (IOException e) {

src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public class MainUIController extends BaseFXController {
7474
private TextField daoTargetProject;
7575
@FXML
7676
private TextField projectFolderField;
77+
@FXML
78+
private CheckBox offsetLimitCheckBox;
79+
@FXML
80+
private CheckBox commentCheckBox;
81+
7782
@FXML
7883
private TreeView<String> leftDBTree;
7984
@FXML
@@ -245,6 +250,8 @@ public GeneratorConfig getGeneratorConfigFromUI() {
245250
generatorConfig.setMappingXMLTargetFolder(mappingTargetProject.getText());
246251
generatorConfig.setTableName(tableNameField.getText());
247252
generatorConfig.setDomainObjectName(domainObjectNameField.getText());
253+
generatorConfig.setOffsetLimit(offsetLimitCheckBox.isSelected());
254+
generatorConfig.setComment(commentCheckBox.isSelected());
248255
return generatorConfig;
249256
}
250257

src/main/java/com/zzg/mybatis/generator/controller/SelectTableColumnController.java

Lines changed: 22 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import javafx.collections.ObservableList;
88
import javafx.fxml.FXML;
99
import javafx.scene.control.*;
10+
import javafx.scene.control.cell.CheckBoxTableCell;
11+
import javafx.scene.control.cell.PropertyValueFactory;
12+
import javafx.scene.control.cell.TextFieldTableCell;
1013
import org.mybatis.generator.config.ColumnOverride;
1114
import org.mybatis.generator.config.IgnoredColumn;
1215

@@ -41,87 +44,26 @@ public class SelectTableColumnController extends BaseFXController {
4144

4245
@Override
4346
public void initialize(URL location, ResourceBundle resources) {
44-
columnListView.setFocusTraversable(false);
45-
46-
checkedColumn.setCellValueFactory(cellData -> cellData.getValue().checkedProperty());
47-
columnNameColumn.setCellValueFactory(cellData -> cellData.getValue().columnNameProperty());
48-
jdbcTypeColumn.setCellValueFactory(cellData -> cellData.getValue().jdbcTypeProperty());
49-
propertyNameColumn.setCellValueFactory(cellData -> cellData.getValue().propertyNameProperty());
50-
typeHandlerColumn.setCellValueFactory(cellData -> cellData.getValue().typeHandleProperty());
51-
checkedColumn.setCellFactory(column -> {
52-
return new TableCell<UITableColumnVO, Boolean>() {
53-
54-
@Override
55-
protected void updateItem(Boolean item, boolean empty) {
56-
super.updateItem(item, empty);
57-
58-
if (item == null || empty) {
59-
setText(null);
60-
} else {
61-
CheckBox checkBox = new CheckBox();
62-
checkBox.setSelected(item);
63-
checkBox.setFocusTraversable(false);
64-
ObservableList<UITableColumnVO> items = this.getTableView().getItems();
65-
UITableColumnVO element = items.get(this.getIndex());
66-
checkBox.selectedProperty().bindBidirectional(element.checkedProperty());
67-
setGraphic(checkBox);
68-
}
69-
}
70-
};
47+
// cellvaluefactory
48+
checkedColumn.setCellValueFactory(new PropertyValueFactory<>("checked"));
49+
columnNameColumn.setCellValueFactory(new PropertyValueFactory<>("columnName"));
50+
jdbcTypeColumn.setCellValueFactory(new PropertyValueFactory<>("jdbcType"));
51+
propertyNameColumn.setCellValueFactory(new PropertyValueFactory<>("propertyName"));
52+
typeHandlerColumn.setCellValueFactory(new PropertyValueFactory<>("typeHandler"));
53+
// Cell Factory that customize how the cell should render
54+
checkedColumn.setCellFactory(CheckBoxTableCell.forTableColumn(checkedColumn));
55+
javaTypeColumn.setCellFactory(TextFieldTableCell.forTableColumn());
56+
// handle commit event to save the user input data
57+
javaTypeColumn.setOnEditCommit(event -> {
58+
event.getTableView().getItems().get(event.getTablePosition().getRow()).setJavaType(event.getNewValue());
7159
});
72-
javaTypeColumn.setCellFactory(column -> {
73-
return new TableCell<UITableColumnVO, String>() {
74-
@Override
75-
protected void updateItem(String item, boolean empty) {
76-
super.updateItem(item, empty);
77-
78-
if (empty) {
79-
setText(null);
80-
} else {
81-
TextField textField = new TextField();
82-
ObservableList<UITableColumnVO> items = this.getTableView().getItems();
83-
UITableColumnVO element = items.get(this.getIndex());
84-
textField.textProperty().bindBidirectional(element.javaTypeProperty());
85-
setGraphic(textField);
86-
}
87-
}
88-
};
60+
propertyNameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
61+
propertyNameColumn.setOnEditCommit(event -> {
62+
event.getTableView().getItems().get(event.getTablePosition().getRow()).setPropertyName(event.getNewValue());
8963
});
90-
propertyNameColumn.setCellFactory(column -> {
91-
return new TableCell<UITableColumnVO, String>() {
92-
@Override
93-
protected void updateItem(String item, boolean empty) {
94-
super.updateItem(item, empty);
95-
96-
if (empty) {
97-
setText(null);
98-
} else {
99-
TextField textField = new TextField();
100-
ObservableList<UITableColumnVO> items = this.getTableView().getItems();
101-
UITableColumnVO element = items.get(this.getIndex());
102-
textField.textProperty().bindBidirectional(element.propertyNameProperty());
103-
setGraphic(textField);
104-
}
105-
}
106-
};
107-
});
108-
typeHandlerColumn.setCellFactory(column -> {
109-
return new TableCell<UITableColumnVO, String>() {
110-
@Override
111-
protected void updateItem(String item, boolean empty) {
112-
super.updateItem(item, empty);
113-
114-
if (empty) {
115-
setText(null);
116-
} else {
117-
TextField textField = new TextField();
118-
ObservableList<UITableColumnVO> items = this.getTableView().getItems();
119-
UITableColumnVO element = items.get(this.getIndex());
120-
textField.textProperty().bindBidirectional(element.typeHandleProperty());
121-
setGraphic(textField);
122-
}
123-
}
124-
};
64+
typeHandlerColumn.setCellFactory(TextFieldTableCell.forTableColumn());
65+
typeHandlerColumn.setOnEditCommit(event -> {
66+
event.getTableView().getItems().get(event.getTablePosition().getRow()).setTypeHandle(event.getNewValue());
12567
});
12668
}
12769

@@ -135,7 +77,7 @@ public void ok() {
13577
if (!item.getChecked()) {
13678
IgnoredColumn ignoredColumn = new IgnoredColumn(item.getColumnName());
13779
ignoredColumns.add(ignoredColumn);
138-
} else if (item.getTypeHandle() != null) { // unchecked and have typeHandler value
80+
} else if (item.getTypeHandle() != null || item.getJavaType() != null || item.getPropertyName() != null) { // unchecked and have typeHandler value
13981
ColumnOverride columnOverride = new ColumnOverride(item.getColumnName());
14082
columnOverride.setTypeHandler(item.getTypeHandle());
14183
columnOverride.setJavaProperty(item.getPropertyName());

src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class GeneratorConfig {
2828

2929
private String domainObjectName;
3030

31+
private boolean offsetLimit;
32+
33+
private boolean comment;
34+
3135
public String getTableName() {
3236
return tableName;
3337
}
@@ -107,4 +111,20 @@ public String getMappingXMLTargetFolder() {
107111
public void setMappingXMLTargetFolder(String mappingXMLTargetFolder) {
108112
this.mappingXMLTargetFolder = mappingXMLTargetFolder;
109113
}
114+
115+
public boolean isOffsetLimit() {
116+
return offsetLimit;
117+
}
118+
119+
public void setOffsetLimit(boolean offsetLimit) {
120+
this.offsetLimit = offsetLimit;
121+
}
122+
123+
public boolean isComment() {
124+
return comment;
125+
}
126+
127+
public void setComment(boolean comment) {
128+
this.comment = comment;
129+
}
110130
}

src/main/resources/fxml/MainUI.fxml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<children>
5858
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
5959
<children>
60-
<GridPane layoutX="5.0" layoutY="29.0" prefHeight="387.0" prefWidth="736.0" vgap="5.0" AnchorPane.leftAnchor="-5.0" AnchorPane.rightAnchor="10.0">
60+
<GridPane layoutX="5.0" layoutY="29.0" prefHeight="404.0" prefWidth="732.0" vgap="5.0" AnchorPane.leftAnchor="-5.0" AnchorPane.rightAnchor="10.0">
6161
<columnConstraints>
6262
<ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" maxWidth="157.0" minWidth="156.0" prefWidth="156.0" />
6363
<ColumnConstraints hgrow="SOMETIMES" maxWidth="688.0" minWidth="10.0" prefWidth="226.0" />
@@ -72,6 +72,7 @@
7272
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
7373
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
7474
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
75+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
7576
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
7677
</rowConstraints>
7778
<children>
@@ -107,7 +108,7 @@
107108
<Label text="Model Package" GridPane.rowIndex="4" />
108109
<HBox alignment="CENTER_LEFT" prefHeight="27.0" prefWidth="261.0" spacing="10.0" GridPane.columnIndex="1" GridPane.rowIndex="4">
109110
<children>
110-
<TextField fx:id="modelTargetPackage" prefHeight="27.0" prefWidth="248.0">
111+
<TextField fx:id="modelTargetPackage" prefHeight="27.0" prefWidth="248.0" promptText="com.example.model">
111112
<HBox.margin>
112113
<Insets right="5.0" />
113114
</HBox.margin>
@@ -119,7 +120,7 @@
119120
<Label text="DAO Package" GridPane.rowIndex="5" />
120121
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" spacing="10.0" GridPane.columnIndex="1" GridPane.rowIndex="5">
121122
<children>
122-
<TextField fx:id="daoTargetPackage" prefHeight="27.0" prefWidth="248.0">
123+
<TextField fx:id="daoTargetPackage" prefHeight="27.0" prefWidth="248.0" promptText="com.example.mapper">
123124
<HBox.margin>
124125
<Insets right="5.0" />
125126
</HBox.margin>
@@ -131,7 +132,7 @@
131132
<Label text="Mapping XML Package" GridPane.rowIndex="6" />
132133
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" spacing="10.0" GridPane.columnIndex="1" GridPane.rowIndex="6">
133134
<children>
134-
<TextField fx:id="mapperTargetPackage" prefHeight="27.0" prefWidth="248.0">
135+
<TextField fx:id="mapperTargetPackage" prefHeight="27.0" prefWidth="248.0" promptText="com.example">
135136
<HBox.margin>
136137
<Insets right="5.0" />
137138
</HBox.margin>
@@ -140,7 +141,13 @@
140141
</HBox>
141142
<Label text="Target Folder" GridPane.columnIndex="2" GridPane.rowIndex="6" />
142143
<TextField fx:id="mappingTargetProject" promptText="src/main/resources" GridPane.columnIndex="3" GridPane.rowIndex="6" />
143-
<Button mnemonicParsing="false" onAction="#generateCode" text="Generate" GridPane.columnIndex="1" GridPane.rowIndex="7" />
144+
<HBox alignment="CENTER_LEFT" spacing="10.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="7">
145+
<children>
146+
<CheckBox fx:id="offsetLimitCheckBox" mnemonicParsing="false" selected="true" text="offset/limit" GridPane.columnIndex="1" GridPane.rowIndex="7" />
147+
<CheckBox fx:id="commentCheckBox" mnemonicParsing="false" text="suppressAllComments" />
148+
</children>
149+
</HBox>
150+
<Button mnemonicParsing="false" onAction="#generateCode" text="Generate" GridPane.columnIndex="1" GridPane.rowIndex="8" />
144151
<Button mnemonicParsing="false" onAction="#openTableColumnCustomizationPage" text="Customize" GridPane.columnIndex="2" GridPane.rowIndex="2" />
145152
</children>
146153
</GridPane>
@@ -149,7 +156,7 @@
149156
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
150157
</padding>
151158
</VBox>
152-
<TextArea fx:id="consoleTextArea" editable="false" focusTraversable="false" prefHeight="106.0" prefWidth="721.0" styleClass="consoleTextArea" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="396.0" />
159+
<TextArea fx:id="consoleTextArea" editable="false" focusTraversable="false" layoutY="429.0" prefHeight="77.0" prefWidth="722.0" styleClass="consoleTextArea" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="429.0" />
153160
</children>
154161
</AnchorPane>
155162
</items>

0 commit comments

Comments
 (0)