[Editor] Improve database columns description
This commit is contained in:
@@ -8,7 +8,7 @@ import javafx.scene.control.cell.TextFieldTreeCell
|
|||||||
import tornadofx.action
|
import tornadofx.action
|
||||||
import tornadofx.item
|
import tornadofx.item
|
||||||
|
|
||||||
class SQLElementCell(
|
class SchemaElementCell(
|
||||||
renameElement: (element: Schema, name: String) -> Schema,
|
renameElement: (element: Schema, name: String) -> Schema,
|
||||||
deleteElement: (element: Schema) -> Unit
|
deleteElement: (element: Schema) -> Unit
|
||||||
) : TextFieldTreeCell<Schema>() {
|
) : TextFieldTreeCell<Schema>() {
|
||||||
@@ -45,7 +45,7 @@ class SQLElementCell(
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
converter = SQLElementStringConverter(this, renameElement)
|
converter = SchemaElementStringConverter(this, renameElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateItem(item: Schema?, empty: Boolean) {
|
override fun updateItem(item: Schema?, empty: Boolean) {
|
||||||
@@ -58,7 +58,7 @@ class SQLElementCell(
|
|||||||
}
|
}
|
||||||
|
|
||||||
text = when (item) {
|
text = when (item) {
|
||||||
is SchemaColumn -> "${item.name}${if (item.nullable) "?" else ""}"
|
is SchemaColumn -> "${item.name}: ${item.rawType}${if (item.nullable) "?" else ""}"
|
||||||
else -> item.name
|
else -> item.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ import com.bartlomiejpluta.base.editor.database.model.schema.Schema
|
|||||||
import javafx.scene.control.TreeCell
|
import javafx.scene.control.TreeCell
|
||||||
import javafx.util.StringConverter
|
import javafx.util.StringConverter
|
||||||
|
|
||||||
class SQLElementStringConverter(
|
class SchemaElementStringConverter(
|
||||||
private val cell: TreeCell<Schema>,
|
private val cell: TreeCell<Schema>,
|
||||||
private val rename: (item: Schema, newName: String) -> Schema
|
private val rename: (item: Schema, newName: String) -> Schema
|
||||||
) : StringConverter<Schema>() {
|
) : StringConverter<Schema>() {
|
||||||
@@ -6,10 +6,12 @@ import java.sql.Connection
|
|||||||
class SchemaColumn(
|
class SchemaColumn(
|
||||||
val table: SchemaTable,
|
val table: SchemaTable,
|
||||||
name: String,
|
name: String,
|
||||||
val type: ColumnType,
|
val rawType: String,
|
||||||
val nullable: Boolean,
|
val nullable: Boolean,
|
||||||
val primary: Boolean
|
val primary: Boolean
|
||||||
) : Schema {
|
) : Schema {
|
||||||
|
val type = ColumnType.valueOf(rawType.replace(" ", "_").substringBefore("("))
|
||||||
|
|
||||||
override var name: String = name
|
override var name: String = name
|
||||||
private set(value) {
|
private set(value) {
|
||||||
field = value.toUpperCase()
|
field = value.toUpperCase()
|
||||||
@@ -25,7 +27,7 @@ class SchemaColumn(
|
|||||||
table.columns.remove(this)
|
table.columns.remove(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val icon = when (type) {
|
override val icon = if (primary) FontIcon("fa-key") else when (type) {
|
||||||
ColumnType.INTEGER -> FontIcon("fa-hashtag")
|
ColumnType.INTEGER -> FontIcon("fa-hashtag")
|
||||||
ColumnType.BOOLEAN -> FontIcon("fa-toggle-on")
|
ColumnType.BOOLEAN -> FontIcon("fa-toggle-on")
|
||||||
ColumnType.TINYINT -> FontIcon("fa-hashtag")
|
ColumnType.TINYINT -> FontIcon("fa-hashtag")
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SchemaTable(val database: SchemaDatabase, name: String) : Schema {
|
|||||||
|
|
||||||
val columns = observableListOf<SchemaColumn>()
|
val columns = observableListOf<SchemaColumn>()
|
||||||
|
|
||||||
fun addColumn(name: String, type: ColumnType, nullable: Boolean, primary: Boolean) {
|
fun addColumn(name: String, type: String, nullable: Boolean, primary: Boolean) {
|
||||||
val column = SchemaColumn(this, name, type, nullable, primary)
|
val column = SchemaColumn(this, name, type, nullable, primary)
|
||||||
columns += column
|
columns += column
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.bartlomiejpluta.base.editor.database.service
|
|||||||
import com.bartlomiejpluta.base.editor.database.model.data.DataField
|
import com.bartlomiejpluta.base.editor.database.model.data.DataField
|
||||||
import com.bartlomiejpluta.base.editor.database.model.data.DataRecord
|
import com.bartlomiejpluta.base.editor.database.model.data.DataRecord
|
||||||
import com.bartlomiejpluta.base.editor.database.model.data.Query
|
import com.bartlomiejpluta.base.editor.database.model.data.Query
|
||||||
import com.bartlomiejpluta.base.editor.database.model.schema.ColumnType
|
|
||||||
import com.bartlomiejpluta.base.editor.database.model.schema.SchemaDatabase
|
import com.bartlomiejpluta.base.editor.database.model.schema.SchemaDatabase
|
||||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
@@ -31,7 +30,7 @@ class H2DatabaseService : DatabaseService {
|
|||||||
while (results.next()) {
|
while (results.next()) {
|
||||||
table.addColumn(
|
table.addColumn(
|
||||||
results.getString("FIELD"),
|
results.getString("FIELD"),
|
||||||
parseType(results.getString("TYPE")),
|
results.getString("TYPE"),
|
||||||
results.getBoolean("NULL"),
|
results.getBoolean("NULL"),
|
||||||
results.getString("KEY") == "PRI"
|
results.getString("KEY") == "PRI"
|
||||||
)
|
)
|
||||||
@@ -49,8 +48,6 @@ class H2DatabaseService : DatabaseService {
|
|||||||
return projectContext.project?.database?.connection?.use(op)
|
return projectContext.project?.database?.connection?.use(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseType(type: String) = ColumnType.valueOf(type.replace(" ", "_").substringBefore("("))
|
|
||||||
|
|
||||||
override fun execute(statement: String, name: String): Query? = run {
|
override fun execute(statement: String, name: String): Query? = run {
|
||||||
val stmt = prepareStatement(statement).apply { execute() }
|
val stmt = prepareStatement(statement).apply { execute() }
|
||||||
val results = stmt.resultSet
|
val results = stmt.resultSet
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.bartlomiejpluta.base.editor.database.view.list
|
package com.bartlomiejpluta.base.editor.database.view.list
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.database.component.SQLElementCell
|
import com.bartlomiejpluta.base.editor.database.component.SchemaElementCell
|
||||||
import com.bartlomiejpluta.base.editor.database.controller.DatabaseController
|
import com.bartlomiejpluta.base.editor.database.controller.DatabaseController
|
||||||
import com.bartlomiejpluta.base.editor.database.model.*
|
import com.bartlomiejpluta.base.editor.database.model.*
|
||||||
import com.bartlomiejpluta.base.editor.database.model.schema.Schema
|
import com.bartlomiejpluta.base.editor.database.model.schema.Schema
|
||||||
@@ -28,7 +28,7 @@ class TablesListView : View() {
|
|||||||
isShowRoot = false
|
isShowRoot = false
|
||||||
|
|
||||||
setCellFactory {
|
setCellFactory {
|
||||||
SQLElementCell(this@TablesListView::renameElement, this@TablesListView::deleteElement)
|
SchemaElementCell(this@TablesListView::renameElement, this@TablesListView::deleteElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
setOnMouseClicked { event ->
|
setOnMouseClicked { event ->
|
||||||
|
|||||||
Reference in New Issue
Block a user