/
PlayProject.scala
56 lines (48 loc) · 2.21 KB
/
PlayProject.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.scalaide.play2
import scala.collection.mutable
import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.ProjectScope
import org.eclipse.jface.preference.IPreferenceStore
import org.eclipse.ui.preferences.ScopedPreferenceStore
import org.scalaide.core.IScalaProject
import org.scalaide.play2.properties.PlayPreferences
import org.scalaide.play2.templateeditor.TemplateCompilationUnit
import org.scalaide.play2.util.SyncedScopedPreferenceStore
class PlayProject private (val scalaProject: IScalaProject) {
val cachedPreferenceStore = new SyncedScopedPreferenceStore(scalaProject.underlying, PlayPlugin.PluginId)
/**
* Return additional imports that are automatically added to template files.
*
* @return The additional imports, or the empty string if none defined.
*/
def templateImports(extension: String): String = {
import org.scalaide.play2.properties.PlayPreferences._
(defaultImports + cachedPreferenceStore.getString(TemplateImports)).replace("%format%", extension)
}
/** Return a new project-scoped preference store for this project. */
def generateScopedPreferenceStore: IPreferenceStore = new ScopedPreferenceStore(new ProjectScope(scalaProject.underlying), PlayPlugin.PluginId)
/**
* Tries to load the scala template files
*/
def initialize() {
val templateCompilationUnits = for (
r <- scalaProject.underlying.members() if r.isInstanceOf[IFile] && r.getFullPath().toString().endsWith("." + PlayPlugin.TemplateExtension)
) yield TemplateCompilationUnit(r.asInstanceOf[IFile], false)
templateCompilationUnits foreach (_.initialReconcile())
// TODO: Why was there a second round of ask reload here?
// templateCompilationUnits.reverse foreach (_.askReload())
}
/**
* FIXME: This method should probably not exist.
* Template files can be anywhere
*
* @return the absolute location of the project directory
*/
lazy val sourceDir = scalaProject.underlying.getLocation().toFile()
}
object PlayProject {
private val projects = (new mutable.HashMap) withDefault { (scalaProject: IScalaProject) => new PlayProject(scalaProject) }
def apply(scalaProject: IScalaProject): PlayProject = {
projects(scalaProject)
}
}