111 lines
3.4 KiB
Groovy
111 lines
3.4 KiB
Groovy
package com.jdbernard.timestamper
|
|
|
|
import com.jdbernard.timestamper.core.TimelineMarker
|
|
import com.jdbernard.timestamper.core.TimelineProperties
|
|
|
|
class TimeStamperMainController {
|
|
// these will be injected by Griffon
|
|
def model
|
|
def view
|
|
|
|
def syncTimers = [:]
|
|
|
|
void mvcGroupInit(Map args) {
|
|
|
|
def configFile
|
|
|
|
logger.traceIfEnabled("Initializing TimeStamperMain MVC...")
|
|
|
|
def thisMVC = ['model': model, 'view': view, 'controller': this]
|
|
|
|
model.notesDialogMVC = buildMVCGroup('NotesDialog', 'notesDialog',
|
|
'mainMVC': thisMVC)
|
|
|
|
model.punchcardDialogMVC = buildMVCGroup('PunchcardDialog',
|
|
'punchcardDialog', 'mainMVC': thisMVC)
|
|
|
|
// load application properties
|
|
Properties prop = new Properties()
|
|
String userHomeDir = System.getProperty('user.home')
|
|
configFile = new File(userHomeDir, ".timestamperrc")
|
|
if (!configFile.exists()) configFile.createNewFile()
|
|
|
|
logger.traceIfEnabled("Reading configuration from "
|
|
+ "'${configFile.name}'")
|
|
|
|
try { configFile.withInputStream { prop.load(it) } }
|
|
catch (IOException ioe) {
|
|
logger.error('Unable to load configuration', ioe)
|
|
}
|
|
|
|
model.config = prop
|
|
|
|
// load the last used timeline file
|
|
String lastUsed = model.config.getProperty('lastUsed', null)
|
|
if (lastUsed == null) {
|
|
lastUsed = 'timeline.default.properties'
|
|
model.config.setProperty('lastUsed', lastUsed)
|
|
}
|
|
|
|
logger.traceIfEnabled("Reading Timeline properties from '${lastUsed}'")
|
|
|
|
model.timelinePropertiesFile = new File(lastUsed)
|
|
if (!model.timelinePropertiesFile.exists())
|
|
model.timelinePropertiesFile.createNewFile()
|
|
|
|
load(propertyFile)
|
|
}
|
|
|
|
def load = { File propertiesFile ->
|
|
try {
|
|
model.config.setProperty('lastUsed', propertiesFile.canonicalPath)
|
|
} catch (IOException ioe) { logger.error(ioe) }
|
|
|
|
// load the properties file
|
|
model.timelineProperties = new TimelineProperties(propertiesFile)
|
|
|
|
// load the main timeline
|
|
model.timeline = model.timelineProperties.timeline
|
|
|
|
// load the last marker
|
|
model.currentMarker = model.timeline.getLastMarker(new Date())
|
|
}
|
|
|
|
def saveas = {
|
|
|
|
}
|
|
|
|
def exitGracefully = { evt = null ->
|
|
|
|
logger.traceIfEnabled("Exiting gracefully.")
|
|
|
|
// save config
|
|
logger.debugIfEnabled("Config: ${model.config}")
|
|
logger.debugIfEnabled("Storing config to file: ${model.configFile.path}")
|
|
try { model.configFile.withOutputStream { out ->
|
|
model.config.store(out, null) } }
|
|
catch (IOException ioe) {
|
|
logger.error("Unable to save the configuration file", ioe)
|
|
}
|
|
|
|
// save timeline and properties
|
|
model.timelineProperties.save()
|
|
|
|
logger.traceIfEnabled("Completed graceful shutdown.")
|
|
|
|
app.shutdown()
|
|
}
|
|
|
|
def newTask = { mark, notes = "No comments.", timestamp = new Date() ->
|
|
TimelineMarker tm = new TimelineMarker(timestamp, mark, notes)
|
|
model.timeline.addMarker(tm)
|
|
model.currentMarker = model.timeline.getLastMarker(new Date())
|
|
}
|
|
|
|
def deleteTask = { marker ->
|
|
model.timeline.removeMarker(marker)
|
|
model.currentMarker = model.timeline.getLastMarker(new Date())
|
|
}
|
|
|
|
}
|