Former-commit-id: 8fdc4e53677081e73bb55d785a321c6366fb4177
master
wangbingit@outlook.com 5 years ago
parent 19b94f30bd
commit ec575773cf

@ -117,7 +117,7 @@ public class JavaFxApplication extends Application {
mainController.setMain(this); mainController.setMain(this);
mTree = mainController.getDbtree(); mTree = mainController.getDbtree();
mDetail = mainController.getDetail(); mDetail = mainController.getDetail();
mFields = mainController.getFeilds(); mFields = mainController.getFields();
mFields.setEditable(true); mFields.setEditable(true);
mFields.setSortPolicy(new Callback<TableView, Boolean>() { mFields.setSortPolicy(new Callback<TableView, Boolean>() {
@Override @Override
@ -145,7 +145,7 @@ public class JavaFxApplication extends Application {
@Override @Override
public void handle(MouseEvent event) { public void handle(MouseEvent event) {
int selectedIndex = mFields.getSelectionModel().getSelectedIndex(); int selectedIndex = mFields.getSelectionModel().getSelectedIndex();
if (currentTable== null){ if (currentTable== null || selectedIndex == -1){
return; return;
} }
Field field = currentTable.getFields().get(selectedIndex); Field field = currentTable.getFields().get(selectedIndex);
@ -202,7 +202,7 @@ public class JavaFxApplication extends Application {
Dialog.showDictEdit(field); Dialog.showDictEdit(field);
break; break;
} }
loadTable(); //refreshTable();
JavaFxApplication.this.mFields.getSelectionModel().clearSelection(); JavaFxApplication.this.mFields.getSelectionModel().clearSelection();
} }
} }
@ -422,7 +422,7 @@ public class JavaFxApplication extends Application {
if (currentMD != null) { if (currentMD != null) {
currentTable = projectManager.findTableByTableName(currentMD, (String) targetItem.getValue()); currentTable = projectManager.findTableByTableName(currentMD, (String) targetItem.getValue());
} }
loadTable(); initTable();
break; break;
} }
default: default:
@ -577,7 +577,7 @@ public class JavaFxApplication extends Application {
@Override @Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
currentTable.setSys(newValue); currentTable.setSys(newValue);
loadTable(); //refreshTable();
} }
}); });
} }
@ -593,7 +593,7 @@ public class JavaFxApplication extends Application {
String fieldName = projectManager.getNewFieldName(fields); String fieldName = projectManager.getNewFieldName(fields);
System.out.println("新增字段-" + fieldName + "成功!"); System.out.println("新增字段-" + fieldName + "成功!");
this.mFields.getSelectionModel().select(fields.size() - 1); this.mFields.getSelectionModel().select(fields.size() - 1);
loadTable(); //refreshTable();
} }
} }
@ -603,7 +603,7 @@ public class JavaFxApplication extends Application {
if (selectedIndex > -1 && !currentTable.getFields().get(selectedIndex).getIsSystem()) { if (selectedIndex > -1 && !currentTable.getFields().get(selectedIndex).getIsSystem()) {
currentTable.getFields().remove(selectedIndex); currentTable.getFields().remove(selectedIndex);
mFields.getSelectionModel().clearSelection(); mFields.getSelectionModel().clearSelection();
loadTable(); //refreshTable();
} }
} }
@ -692,7 +692,7 @@ public class JavaFxApplication extends Application {
/** /**
* *
*/ */
private void loadTable() { private void initTable() {
GridPane gridPane = mTableLoader.getRoot(); GridPane gridPane = mTableLoader.getRoot();
if (currentTable != null) { if (currentTable != null) {
detailTableController.getTablename().setText(currentTable.getTableName()); detailTableController.getTablename().setText(currentTable.getTableName());
@ -738,7 +738,7 @@ public class JavaFxApplication extends Application {
if (newValue.toUpperCase().endsWith("_TYPE")) { if (newValue.toUpperCase().endsWith("_TYPE")) {
field.setFieldType(FieldType.Dict); field.setFieldType(FieldType.Dict);
} }
loadTable(); //refreshTable();
} }
}); });
@ -839,7 +839,7 @@ public class JavaFxApplication extends Application {
currentTable.getFields().add(i2, t1); currentTable.getFields().add(i2, t1);
currentTable.getFields().remove(i2 + 1); currentTable.getFields().remove(i2 + 1);
} }
loadTable(); //refreshTable();
} }
event.setDropCompleted(true); event.setDropCompleted(true);
event.consume(); event.consume();
@ -1046,8 +1046,46 @@ public class JavaFxApplication extends Application {
return checkBoxTableCell; return checkBoxTableCell;
} }
}); });
columns.get(6).setCellValueFactory(new PropertyValueFactory("isQuery")); columns.get(6).setCellValueFactory(new PropertyValueFactory("isUnique"));
columns.get(6).setCellFactory(new Callback<TableColumn, TableCell>() { columns.get(6).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
final DBCheckBoxTableCell checkBoxTableCell = new DBCheckBoxTableCell();
DBCheckBoxTableCell.sCallback sCallback = checkBoxTableCell.new sCallback() {
@Override
public ObservableValue<Boolean> call(Integer param) {
super.call(param);
List<Field> fields = currentTable.getFields();
if (fields.get(param).getIsSystem()) {
checkBoxTableCell.setInvalid(true);
} else {
checkBoxTableCell.setInvalid(false);
}
if (fields.get(param).getIsUnique()) {
return new SimpleBooleanProperty(true);
} else {
return new SimpleBooleanProperty(false);
}
}
};
checkBoxTableCell.setSelectedStateCallback(sCallback);
checkBoxTableCell.setOnChangeListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
int param1 = checkBoxTableCell.getParam();
Field field = currentTable.getFields().get(param1);
field.setIsUnique(newValue);
if (newValue) {//
field.setIsQuery(true);
}
}
});
return checkBoxTableCell;
}
});
columns.get(7).setCellValueFactory(new PropertyValueFactory("isQuery"));
columns.get(7).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override @Override
public TableCell call(TableColumn param) { public TableCell call(TableColumn param) {
final DBCheckBoxTableCell checkBoxTableCell = new DBCheckBoxTableCell(); final DBCheckBoxTableCell checkBoxTableCell = new DBCheckBoxTableCell();
@ -1080,8 +1118,8 @@ public class JavaFxApplication extends Application {
return checkBoxTableCell; return checkBoxTableCell;
} }
}); });
columns.get(7).setCellValueFactory(new PropertyValueFactory("isSearch")); columns.get(8).setCellValueFactory(new PropertyValueFactory("isSearch"));
columns.get(7).setCellFactory(new Callback<TableColumn, TableCell>() { columns.get(8).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override @Override
public TableCell call(TableColumn param) { public TableCell call(TableColumn param) {
final DBCheckBoxTableCell checkBoxTableCell = new DBCheckBoxTableCell(); final DBCheckBoxTableCell checkBoxTableCell = new DBCheckBoxTableCell();
@ -1114,8 +1152,8 @@ public class JavaFxApplication extends Application {
return checkBoxTableCell; return checkBoxTableCell;
} }
}); });
columns.get(8).setCellValueFactory(new PropertyValueFactory("fieldComment")); columns.get(9).setCellValueFactory(new PropertyValueFactory("fieldComment"));
columns.get(8).setCellFactory(new Callback<TableColumn, TableCell>() { columns.get(9).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override @Override
public TableCell call(TableColumn param) { public TableCell call(TableColumn param) {
@ -1149,14 +1187,11 @@ public class JavaFxApplication extends Application {
} }
}); });
ObservableList<Field> data = null;
if (currentTable != null) { if (currentTable != null) {
List<Field> fields = currentTable.getFields(); ObservableList<Field> fields = currentTable.getFields();
data = FXCollections.observableArrayList(); mFields.setItems(fields);
data.addAll(fields);
} }
mFields.setItems(data);
} }
void ignoreField(TableCell tableCell) { void ignoreField(TableCell tableCell) {
@ -1198,7 +1233,7 @@ public class JavaFxApplication extends Application {
Table table = projectManager.findTableByTableName(md, (String) event.getOldValue()); Table table = projectManager.findTableByTableName(md, (String) event.getOldValue());
if (table != null) { if (table != null) {
table.setTableName((String) event.getNewValue()); table.setTableName((String) event.getNewValue());
loadTable(); initTable();
} }
break; break;
} }

@ -27,7 +27,7 @@ public class MainController {
@FXML @FXML
private Pane detail; private Pane detail;
@FXML @FXML
private TableView feilds; private TableView fields;
@FXML @FXML
private Button add; private Button add;
@FXML @FXML
@ -69,12 +69,12 @@ public class MainController {
this.sub = sub; this.sub = sub;
} }
public TableView getFeilds() { public TableView getFields() {
return feilds; return fields;
} }
public void setFeilds(TableView feilds) { public void setFields(TableView fields) {
this.feilds = feilds; this.fields = fields;
} }
public TreeView getDbtree() { public TreeView getDbtree() {

@ -117,8 +117,9 @@ public class XmlManager {
field.setFieldComment(fieldElement.getAttribute("fieldComment")); field.setFieldComment(fieldElement.getAttribute("fieldComment"));
field.setDefaultValue(fieldElement.getAttribute("defaultValue")); field.setDefaultValue(fieldElement.getAttribute("defaultValue"));
field.setIsSystem(getBoolean(fieldElement.getAttribute("IsSystem"))); field.setIsSystem(getBoolean(fieldElement.getAttribute("IsSystem")));
field.setIsMust(getBoolean(fieldElement.getAttribute("isMust")));
field.setIsPrimaryKey(getBoolean(fieldElement.getAttribute("isPrimaryKey"))); field.setIsPrimaryKey(getBoolean(fieldElement.getAttribute("isPrimaryKey")));
field.setIsMust(getBoolean(fieldElement.getAttribute("isMust")));
field.setIsUnique(getBoolean(fieldElement.getAttribute("isUnique")));
field.setIsQuery(getBoolean(fieldElement.getAttribute("isQuery"))); field.setIsQuery(getBoolean(fieldElement.getAttribute("isQuery")));
field.setIsSearch(getBoolean(fieldElement.getAttribute("isSearch"))); field.setIsSearch(getBoolean(fieldElement.getAttribute("isSearch")));
table.putField(field); table.putField(field);
@ -236,31 +237,21 @@ public class XmlManager {
table.setAttribute("sys", Boolean.toString(t.getSys())); table.setAttribute("sys", Boolean.toString(t.getSys()));
Element fields = doc.createElement("fields"); Element fields = doc.createElement("fields");
table.appendChild(fields); table.appendChild(fields);
for (Field f : t.getFields()) { for (Field f : t.getFields()) {
Element field = doc.createElement("field"); Element field = doc.createElement("field");
field.setAttribute("fieldName", f.getFieldName()); field.setAttribute("fieldName", f.getFieldName());
if (f.getFieldType() != null) { field.setAttribute("fieldType", f.getFieldType().name());
field.setAttribute("fieldType", f.getFieldType().name()); field.setAttribute("fieldLength", f.getFieldLength().toString());
}
if (f.getFieldLength() != null) {
field.setAttribute("fieldLength", f.getFieldLength().toString());
}
field.setAttribute("fieldComment", f.getFieldComment()); field.setAttribute("fieldComment", f.getFieldComment());
field.setAttribute("defaultValue", f.getDefaultValue()); field.setAttribute("defaultValue", f.getDefaultValue());
if (f.getIsMust() != null) { field.setAttribute("isPrimaryKey", String.valueOf(f.getIsPrimaryKey()));
field.setAttribute("isMust", f.getIsMust().toString()); field.setAttribute("isMust", String.valueOf(f.getIsMust()));
} field.setAttribute("isUnique", String.valueOf(f.getIsUnique()));
field.setAttribute("isQuery", f.getIsQuery().toString()); field.setAttribute("isQuery", String.valueOf(f.getIsQuery()));
field.setAttribute("isSearch", f.getIsSearch().toString()); field.setAttribute("isSearch", String.valueOf(f.getIsSearch()));
if (f.getIsPrimaryKey() != null) { field.setAttribute("IsSystem", String.valueOf(f.getIsSystem()));
field.setAttribute("isPrimaryKey", f.getIsPrimaryKey().toString());
}
if (f.getIsSystem() != null) {
field.setAttribute("IsSystem", f.getIsSystem().toString());
}
if (f.getDictItems().size() > 0) { if (f.getDictItems().size() > 0) {
for (DictItem dictItem : f.getDictItems()) { for (DictItem dictItem : f.getDictItems()) {
Element dict = doc.createElement("dictItem"); Element dict = doc.createElement("dictItem");

@ -1,5 +1,7 @@
package xyz.wbsite.dbtool.javafx.po; package xyz.wbsite.dbtool.javafx.po;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import xyz.wbsite.dbtool.javafx.tool.Tool; import xyz.wbsite.dbtool.javafx.tool.Tool;
@ -34,7 +36,7 @@ public class Field extends Table {
/** /**
* *
*/ */
private String fieldComment = null; private String fieldComment = "";
/** /**
* *
@ -44,20 +46,25 @@ public class Field extends Table {
/** /**
* NULL * NULL
*/ */
private Boolean isMust = false; private boolean isMust = false;
/**
*
*/
// private boolean isUnique = false;
/** /**
* *
*/ */
private Boolean isPrimaryKey = false; private boolean isPrimaryKey = false;
/** /**
* *
*/ */
private Boolean isQuery = false; // private boolean isQuery = false;
private Boolean isSearch = false; private boolean isSearch = false;
private Boolean isSystem = false; private boolean isSystem = false;
private List<DictItem> dictItems = new ArrayList<>(); private List<DictItem> dictItems = new ArrayList<>();
@ -150,19 +157,19 @@ public class Field extends Table {
return value; return value;
} }
public Boolean getIsSearch() { public boolean getIsSearch() {
return isSearch; return isSearch;
} }
public void setIsSearch(Boolean isSearch) { public void setIsSearch(boolean isSearch) {
this.isSearch = isSearch; this.isSearch = isSearch;
} }
public Boolean getIsSystem() { public boolean getIsSystem() {
return isSystem; return isSystem;
} }
public void setIsSystem(Boolean isSystem) { public void setIsSystem(boolean isSystem) {
this.isSystem = isSystem; this.isSystem = isSystem;
} }
@ -174,12 +181,34 @@ public class Field extends Table {
return "set" + Tool.ABB2Abb(this.fieldName); return "set" + Tool.ABB2Abb(this.fieldName);
} }
public Boolean getIsQuery() { // isUnique
private final BooleanProperty isUnique = new SimpleBooleanProperty();
public BooleanProperty isUniqueProperty() {
return isUnique;
}
public boolean getIsUnique() {
return isUnique.get();
}
public void setIsUnique(boolean isUnique) {
this.isUnique.set(isUnique);
}
// isQuery
private final BooleanProperty isQuery = new SimpleBooleanProperty();
public BooleanProperty isQueryProperty() {
return isQuery; return isQuery;
} }
public void setIsQuery(Boolean isQuery) { public boolean getIsQuery() {
this.isQuery = isQuery; return isQuery.get();
}
public void setIsQuery(boolean isQuery) {
this.isQuery.set(isQuery);
} }
public String getFieldName() { public String getFieldName() {
@ -222,19 +251,19 @@ public class Field extends Table {
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
} }
public Boolean getIsMust() { public boolean getIsMust() {
return isMust; return isMust;
} }
public void setIsMust(Boolean isMust) { public void setIsMust(boolean isMust) {
this.isMust = isMust; this.isMust = isMust;
} }
public Boolean getIsPrimaryKey() { public boolean getIsPrimaryKey() {
return isPrimaryKey; return isPrimaryKey;
} }
public void setIsPrimaryKey(Boolean isPrimaryKey) { public void setIsPrimaryKey(boolean isPrimaryKey) {
this.isPrimaryKey = isPrimaryKey; this.isPrimaryKey = isPrimaryKey;
} }

@ -1,5 +1,7 @@
package xyz.wbsite.dbtool.javafx.po; package xyz.wbsite.dbtool.javafx.po;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TreeItem; import javafx.scene.control.TreeItem;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.manger.ProjectManager; import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
@ -49,7 +51,7 @@ public class Table extends TreeItem {
/** /**
* *
*/ */
private List<Field> fields = new ArrayList(); private ObservableList<Field> fields = FXCollections.observableArrayList();
public boolean has(String type) { public boolean has(String type) {
for (Field field : fields) { for (Field field : fields) {
@ -73,17 +75,11 @@ public class Table extends TreeItem {
} }
public boolean putField(Field field) { public boolean putField(Field field) {
if (fields == null) {
fields = new ArrayList<Field>();
}
fields.add(field); fields.add(field);
return true; return true;
} }
public boolean putFirstField(Field field) { public boolean putFirstField(Field field) {
if (fields == null) {
fields = new ArrayList<Field>();
}
fields.add(0, field); fields.add(0, field);
return true; return true;
} }
@ -117,14 +113,10 @@ public class Table extends TreeItem {
this.tableComment = tableComment != null ? tableComment : ""; this.tableComment = tableComment != null ? tableComment : "";
} }
public List<Field> getFields() { public ObservableList<Field> getFields() {
return fields; return fields;
} }
public void setFields(List<Field> fields) {
this.fields = fields;
}
public Module getdBhandle() { public Module getdBhandle() {
return dBhandle; return dBhandle;
} }

@ -57,7 +57,7 @@
<Pane fx:id="detail" prefHeight="200.0" prefWidth="200.0"/> <Pane fx:id="detail" prefHeight="200.0" prefWidth="200.0"/>
<BorderPane> <BorderPane>
<center> <center>
<TableView fx:id="feilds" prefHeight="200.0" prefWidth="200.0"> <TableView fx:id="fields" prefHeight="200.0" prefWidth="200.0">
<columns> <columns>
<TableColumn prefWidth="100" text="字段名"/> <TableColumn prefWidth="100" text="字段名"/>
<TableColumn prefWidth="90" text="类型"/> <TableColumn prefWidth="90" text="类型"/>
@ -65,6 +65,7 @@
<TableColumn prefWidth="40" text="默认值"/> <TableColumn prefWidth="40" text="默认值"/>
<TableColumn prefWidth="35" text="主键"/> <TableColumn prefWidth="35" text="主键"/>
<TableColumn prefWidth="35" text="必填"/> <TableColumn prefWidth="35" text="必填"/>
<TableColumn prefWidth="35" text="唯一"/>
<TableColumn prefWidth="35" text="查询"/> <TableColumn prefWidth="35" text="查询"/>
<TableColumn prefWidth="35" text="模糊"/> <TableColumn prefWidth="35" text="模糊"/>
<TableColumn prefWidth="90" text="注释"/> <TableColumn prefWidth="90" text="注释"/>

@ -108,10 +108,10 @@ public class DataInit {
<#list module.tables as table> <#list module.tables as table>
<#list table.fields as field> <#list table.fields as field>
<#if field.fieldType == 'Dict'> <#if field.fieldType == 'Dict'>
{// ${field.fieldComment} {// ${field.fieldComment?default('')}
createDict("${field.fieldName}", "${field.fieldComment}", new String[][]{ createDict("${field.fieldName?default('')}", "${field.fieldComment?default('')}", new String[][]{
<#list field.dictItems as dictItem> <#list field.dictItems as dictItem>
{"${dictItem.key}", "${dictItem.value}"}, {"${dictItem.key?default('')}", "${dictItem.value?default('')}"},
</#list> </#list>
}); });
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.