Switched from groovy script config to java.util.Properties based config.
This commit is contained in:
parent
501bb04b89
commit
790d2c2a77
@ -1,5 +1,6 @@
|
|||||||
package com.jdbernard.pit.swing
|
package com.jdbernard.pit.swing
|
||||||
|
|
||||||
|
import com.jdbernard.pit.Category
|
||||||
import com.jdbernard.pit.FileProject
|
import com.jdbernard.pit.FileProject
|
||||||
import javax.swing.JFileChooser
|
import javax.swing.JFileChooser
|
||||||
import javax.swing.SwingUtilities
|
import javax.swing.SwingUtilities
|
||||||
@ -15,55 +16,82 @@ class PITController {
|
|||||||
SwingUtilities.invokeAndWait {
|
SwingUtilities.invokeAndWait {
|
||||||
model.issueListRenderer = new IssueTableCellRenderer()
|
model.issueListRenderer = new IssueTableCellRenderer()
|
||||||
|
|
||||||
def config = new File(System.getProperty('user.home'), '.pit')
|
File pitHome, pitrcFile, pitswingrcFile
|
||||||
config = new File(config, 'pit_swing.groovy')
|
Properties config = new Properties()
|
||||||
|
|
||||||
// read and process configuration
|
// look for config directory
|
||||||
if (config.exists() && config.isFile()) {
|
pitHome = new File(System.getProperty('user.home'), '.pit')
|
||||||
// load script
|
println "$pitHome is ${pitHome.exists() ? '' : 'not '} present."
|
||||||
def loader = new GroovyClassLoader(PITController.classLoader)
|
|
||||||
|
|
||||||
// create binding for variables in the script
|
// look for general config options
|
||||||
def configBinding = new Binding()
|
pitrcFile = new File(pitHome, 'pitrc')
|
||||||
|
println "$pitrcFile is ${pitrcFile.exists() ? '' : 'not '} present."
|
||||||
|
|
||||||
// add default values for all configurable values
|
// load general config (if present)
|
||||||
configBinding.templates = model.templates
|
if (pitrcFile.exists()) {
|
||||||
configBinding.issueListRenderer = model.issueListRenderer
|
pitrcFile.withInputStream() { config.load(it) }
|
||||||
configBinding.initialRepositories = []
|
println "Loaded pitrc"
|
||||||
configBinding.issueCSS = model.issueCSS
|
}
|
||||||
configBinding.PIT_HOME = config.parentFile
|
|
||||||
|
|
||||||
def configScript = loader.parseClass(config)
|
// look for swing specific config
|
||||||
.newInstance(configBinding)
|
pitswingrcFile = new File(pitHome, 'pitswingrc')
|
||||||
|
println "$pitswingrcFile is " (pitswingrcFile.exists() ?
|
||||||
|
'' : 'not ') + "present."
|
||||||
|
|
||||||
configScript.invokeMethod("run", null)
|
// load swing specific config (if present)
|
||||||
|
if (pitswingrcFile.exists()) {
|
||||||
|
pitswingrcFile.withInputStream() { config.load(it) }
|
||||||
|
println "Loaded pitswingrc"
|
||||||
|
}
|
||||||
|
|
||||||
// act on the results of the configuration script
|
// Process Configurable Options
|
||||||
|
// ----------------------------
|
||||||
|
|
||||||
// use custom templates, if given
|
config.keySet().each { println it }
|
||||||
model.templates = configBinding.templates ?: [:]
|
|
||||||
|
|
||||||
// check for customer issur list rendered
|
// add custom category templates
|
||||||
if (configBinding.issueListRenderer &&
|
Category.values().each { category ->
|
||||||
configBinding.issueListRenderer != model.issueListRenderer)
|
def expectedKey = "issue." + category.name().toLowerCase() +
|
||||||
model.issueListRenderer = configBinding.issueListRenderer
|
".template"
|
||||||
|
println "Looking for key: $expectedKey"
|
||||||
// open any initial repositories configured
|
config.keySet().each { currentKey ->
|
||||||
if (configBinding.initialRepositories) {
|
if (currentKey == expectedKey)
|
||||||
configBinding.initialRepositories.each { repo ->
|
model.templates[(category)] =
|
||||||
// try to create a file object if this is not one
|
config.getProperty(expectedKey, "")
|
||||||
if (!(repo instanceof File)) repo = new File(repo)
|
println "Template for category $category: '" +
|
||||||
|
model.templates[(category)] + "'"
|
||||||
loadProject(repo)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// open any custom CSS for issue dsiplay
|
// load custom issueListRenderer
|
||||||
if (configBinding.issueCSS instanceof File)
|
// TODO: not yet supported (maybe no need)
|
||||||
model.issueCSS = configBinding.issueCSS.text
|
|
||||||
else
|
// load initial repositories
|
||||||
model.issueCSS = configBinding.issueCSS
|
if (config.containsKey('initial-repositories')) {
|
||||||
|
def initRepos = config.getProperty('initial-repositories', '')
|
||||||
|
initRepos = initRepos.split(/[;:,]/)
|
||||||
|
initRepos.each { repoPath -> loadProject(new File(repoPath)) }
|
||||||
|
println "Init repos: '$initRepos'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load custom issue CSS
|
||||||
|
if (config.containsKey('issue.display.css')) {
|
||||||
|
def issueCSS = config.getProperty('issue.display.css', "")
|
||||||
|
|
||||||
|
// look for a file relative to the pit home directory
|
||||||
|
def cssFile
|
||||||
|
|
||||||
|
// use short-circuit logic to test several possible locations
|
||||||
|
// for a css file
|
||||||
|
if ((cssFile = new File(pitHome, issueCSS)).exists() ||
|
||||||
|
(cssFile = new File(pitHome.parentFile(), issueCSS)).exists() ||
|
||||||
|
(cssFile = new File(issueCSS).exists()))
|
||||||
|
issueCSS = cssFile.text
|
||||||
|
|
||||||
|
println "CS for issue display: $issueCSS"
|
||||||
|
model.issueCSS = issueCSS
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -173,7 +173,7 @@ class ProjectPanelController {
|
|||||||
view.issueTable.model.issues.remove(issue)
|
view.issueTable.model.issues.remove(issue)
|
||||||
|
|
||||||
issue.delete()
|
issue.delete()
|
||||||
view.issueTable.invlidate()
|
view.issueTable.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
def getSelectedIssue() {
|
def getSelectedIssue() {
|
||||||
@ -215,7 +215,6 @@ class ProjectPanelController {
|
|||||||
// add in the CSS information to the head
|
// add in the CSS information to the head
|
||||||
if (line =~/<head>/) result.append(model.issueCSS)
|
if (line =~/<head>/) result.append(model.issueCSS)
|
||||||
}
|
}
|
||||||
println result.toString()
|
|
||||||
|
|
||||||
return result.toString()
|
return result.toString()
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,7 @@ panel = splitPane(orientation: JSplitPane.HORIZONTAL_SPLIT,
|
|||||||
issueTextDisplay = editorPane(contentType: "text/html",
|
issueTextDisplay = editorPane(contentType: "text/html",
|
||||||
constraints: "display",
|
constraints: "display",
|
||||||
editable: false,
|
editable: false,
|
||||||
preferredSize: [200, 200],
|
preferredSize: [10, 10],
|
||||||
mouseClicked: { evt ->
|
mouseClicked: { evt ->
|
||||||
if (evt.clickCount > 1)
|
if (evt.clickCount > 1)
|
||||||
issueTextPanelLayout.show(issueTextPanel, "editor")
|
issueTextPanelLayout.show(issueTextPanel, "editor")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user