[Editor] Add support for api classes selection in SelectJavaClassView
This commit is contained in:
@@ -15,7 +15,11 @@ class APIProvider {
|
|||||||
|
|
||||||
val apiNode: FileNode by lazy { loadNode() }
|
val apiNode: FileNode by lazy { loadNode() }
|
||||||
|
|
||||||
private fun loadNode() = ResourceFileNode.root("api").apply {
|
private fun loadNode() = ResourceFileNode.root(API_DIR).apply {
|
||||||
apiIndex.inputStream.bufferedReader().use(BufferedReader::readLines).forEach(this::createNode)
|
apiIndex.inputStream.bufferedReader().use(BufferedReader::readLines).forEach(this::createNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val API_DIR = "api"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,24 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.view.select
|
package com.bartlomiejpluta.base.editor.code.view.select
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.file.model.FileSystemNode
|
import com.bartlomiejpluta.base.editor.code.api.APIProvider
|
||||||
import com.bartlomiejpluta.base.editor.file.model.FileType
|
import com.bartlomiejpluta.base.editor.file.model.*
|
||||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
import javafx.beans.binding.Bindings.createBooleanBinding
|
import javafx.beans.binding.Bindings.createBooleanBinding
|
||||||
import javafx.beans.property.SimpleObjectProperty
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
import java.io.File
|
import java.nio.file.Path
|
||||||
|
|
||||||
class SelectJavaClassFragment : Fragment("Select Java Class") {
|
class SelectJavaClassFragment : Fragment("Select Java Class") {
|
||||||
private val projectContext: ProjectContext by di()
|
private val projectContext: ProjectContext by di()
|
||||||
private val rootNode = projectContext.project!!.codeFSNode
|
private val apiProvider: APIProvider by di()
|
||||||
private val selection = SimpleObjectProperty<FileSystemNode>()
|
|
||||||
|
private val codeFSNode = projectContext.project!!.codeFSNode
|
||||||
|
private val rootNode = PseudoFileNode.emptyRoot().apply {
|
||||||
|
children += apiProvider.apiNode
|
||||||
|
children += codeFSNode
|
||||||
|
}
|
||||||
|
|
||||||
|
private val selection = SimpleObjectProperty<FileNode>()
|
||||||
|
|
||||||
private val selectJavaClassView = find<SelectJavaClassView>(
|
private val selectJavaClassView = find<SelectJavaClassView>(
|
||||||
SelectJavaClassView::rootNode to rootNode,
|
SelectJavaClassView::rootNode to rootNode,
|
||||||
@@ -35,7 +42,7 @@ class SelectJavaClassFragment : Fragment("Select Java Class") {
|
|||||||
action {
|
action {
|
||||||
selection.value?.let { node ->
|
selection.value?.let { node ->
|
||||||
onCompleteConsumer?.let { consumer ->
|
onCompleteConsumer?.let { consumer ->
|
||||||
consumer(formatClassName(node.file))
|
consumer(formatClassName(node))
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,10 +57,9 @@ class SelectJavaClassFragment : Fragment("Select Java Class") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatClassName(file: File) = file
|
private fun formatClassName(node: FileNode) = when (node) {
|
||||||
.relativeTo(rootNode.file)
|
is FileSystemNode -> node.file.relativeTo(codeFSNode.file).toPath()
|
||||||
.toPath()
|
is ResourceFileNode -> Path.of(node.absolutePath.substringAfter("/${APIProvider.API_DIR}"))
|
||||||
.normalize()
|
else -> throw IllegalStateException("Unsupported file node type")
|
||||||
.joinToString(".")
|
}.normalize().joinToString(".").substringBeforeLast(".")
|
||||||
.substringBeforeLast(".")
|
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,29 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.view.select
|
package com.bartlomiejpluta.base.editor.code.view.select
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.file.model.FileSystemNode
|
import com.bartlomiejpluta.base.editor.file.model.FileNode
|
||||||
|
import com.bartlomiejpluta.base.editor.file.model.FileType
|
||||||
import javafx.beans.property.Property
|
import javafx.beans.property.Property
|
||||||
import javafx.scene.control.TreeItem
|
import javafx.scene.control.TreeItem
|
||||||
import org.kordamp.ikonli.javafx.FontIcon
|
import org.kordamp.ikonli.javafx.FontIcon
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
class SelectJavaClassView : View() {
|
class SelectJavaClassView : View() {
|
||||||
val rootNode: FileSystemNode by param()
|
val rootNode: FileNode by param()
|
||||||
val selection: Property<FileSystemNode> by param()
|
val selection: Property<FileNode> by param()
|
||||||
|
|
||||||
private val treeView = treeview<FileSystemNode> {
|
private val treeView = treeview<FileNode> {
|
||||||
root = TreeItem(rootNode)
|
root = TreeItem(rootNode)
|
||||||
|
isShowRoot = false
|
||||||
|
|
||||||
populate {
|
populate {
|
||||||
it.value?.children
|
it.value?.children
|
||||||
}
|
}
|
||||||
|
|
||||||
cellFormat {
|
cellFormat {
|
||||||
text = it.file.nameWithoutExtension
|
text = it.name
|
||||||
graphic = when {
|
graphic = when (it.type) {
|
||||||
it.file.isFile -> FontIcon("fa-cube")
|
FileType.FILE -> FontIcon("fa-cube")
|
||||||
else -> FontIcon("fa-folder")
|
FileType.DIRECTORY -> FontIcon("fa-folder")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ interface FileNode {
|
|||||||
val lastModifiedProperty: ObservableLongValue
|
val lastModifiedProperty: ObservableLongValue
|
||||||
val lastModified: Long
|
val lastModified: Long
|
||||||
|
|
||||||
fun delete()
|
fun delete(): Unit = throw UnsupportedOperationException()
|
||||||
fun rename(name: String)
|
fun rename(name: String): Unit = throw UnsupportedOperationException()
|
||||||
fun refresh()
|
fun refresh(): Unit = throw UnsupportedOperationException()
|
||||||
fun createNode(path: String): FileNode
|
fun createNode(path: String): FileNode = throw UnsupportedOperationException()
|
||||||
|
|
||||||
fun inputStream(): InputStream
|
fun inputStream(): InputStream = throw UnsupportedOperationException()
|
||||||
fun outputStream(): OutputStream
|
fun outputStream(): OutputStream = throw UnsupportedOperationException()
|
||||||
|
|
||||||
fun readText(charset: Charset = Charsets.UTF_8) = inputStream().reader(charset).readText()
|
fun readText(charset: Charset = Charsets.UTF_8) = inputStream().reader(charset).readText()
|
||||||
fun writeText(text: String, charset: Charset = Charsets.UTF_8) = writeBytes(text.toByteArray(charset))
|
fun writeText(text: String, charset: Charset = Charsets.UTF_8) = writeBytes(text.toByteArray(charset))
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.file.model
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleLongProperty
|
||||||
|
import tornadofx.getValue
|
||||||
|
import tornadofx.observableListOf
|
||||||
|
import tornadofx.toProperty
|
||||||
|
|
||||||
|
class PseudoFileNode(name: String, absolutePath: String, override val type: FileType) : FileNode {
|
||||||
|
|
||||||
|
override val nameProperty = name.toProperty()
|
||||||
|
override val name by nameProperty
|
||||||
|
|
||||||
|
override val extensionProperty = "".toProperty()
|
||||||
|
override val extension by extensionProperty
|
||||||
|
|
||||||
|
override val absolutePathProperty = absolutePath.toProperty()
|
||||||
|
override val absolutePath by absolutePathProperty
|
||||||
|
|
||||||
|
override val lastModifiedProperty = SimpleLongProperty(0L)
|
||||||
|
override val lastModified by lastModifiedProperty
|
||||||
|
|
||||||
|
override val parent = null
|
||||||
|
|
||||||
|
override val children = observableListOf<FileNode>()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun emptyRoot() = PseudoFileNode("", "", FileType.DIRECTORY)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,11 +48,6 @@ class ResourceFileNode private constructor(
|
|||||||
?.inputStream
|
?.inputStream
|
||||||
?: throw IllegalStateException("Attempt to open input stream of resource directory")
|
?: throw IllegalStateException("Attempt to open input stream of resource directory")
|
||||||
|
|
||||||
override fun delete() = throw UnsupportedOperationException()
|
|
||||||
override fun rename(name: String) = throw UnsupportedOperationException()
|
|
||||||
override fun refresh() = throw UnsupportedOperationException()
|
|
||||||
override fun outputStream() = throw UnsupportedOperationException()
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun resource(resource: Resource, parent: ResourceFileNode) = ResourceFileNode(resource, parent)
|
fun resource(resource: Resource, parent: ResourceFileNode) = ResourceFileNode(resource, parent)
|
||||||
fun directory(name: String, parent: ResourceFileNode) = ResourceFileNode(null, parent, FileType.DIRECTORY, name)
|
fun directory(name: String, parent: ResourceFileNode) = ResourceFileNode(null, parent, FileType.DIRECTORY, name)
|
||||||
|
|||||||
Reference in New Issue
Block a user