Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a preference and an project preference page
The preference is initialized with framework defaults (play.api.templates._, play.api.templates.PlayMagic._). It can be overriden at the project level, in the project properties. Changes are not applied directly, as we are currently lacking a real builder. Fix #35.
- Loading branch information
Luc Bourlier
committed
Apr 3, 2013
1 parent
5c7dd65
commit c97147b
Showing
9 changed files
with
241 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
org.scala-ide.play2/src/org/scalaide/play2/properties/PreferenceInitializer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.scalaide.play2.properties | ||
|
||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer | ||
import org.scalaide.play2.PlayPlugin | ||
|
||
class PreferenceInitializer extends AbstractPreferenceInitializer { | ||
|
||
override def initializeDefaultPreferences() { | ||
PlayPlugin.prefStore.setDefault(PlayPreferences.TemplateImports, "import play.api.templates._\nimport play.api.templates.PlayMagic._\n") | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
org.scala-ide.play2/src/org/scalaide/play2/properties/ProjectPropertyPage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.scalaide.play2.properties | ||
|
||
import org.eclipse.core.resources.IProject | ||
import org.eclipse.core.runtime.IAdaptable | ||
import org.eclipse.jdt.core.IJavaProject | ||
import org.eclipse.jface.dialogs.IInputValidator | ||
import org.eclipse.jface.dialogs.InputDialog | ||
import org.eclipse.jface.preference.FieldEditorPreferencePage | ||
import org.eclipse.jface.preference.IPreferenceStore | ||
import org.eclipse.jface.preference.ListEditor | ||
import org.eclipse.jface.window.Window | ||
import org.eclipse.swt.widgets.Composite | ||
import org.eclipse.swt.widgets.Display | ||
import org.eclipse.ui.IWorkbenchPropertyPage | ||
import org.scalaide.play2.PlayPlugin | ||
|
||
/** Preference page displayed in the property dialog of (play) projects. | ||
* Used from the UI thread. | ||
*/ | ||
class ProjectPropertyPage extends FieldEditorPreferencePage(FieldEditorPreferencePage.GRID) with IWorkbenchPropertyPage { | ||
|
||
/** Preference field to display the list of extra imports. | ||
*/ | ||
private class ImportsFieldEditor(name: String, labelText: String, parent: Composite) extends ListEditor(name, labelText, parent) { | ||
|
||
override protected def createList(entries: Array[String]): String = | ||
PlayPreferences.serializeImports(entries) | ||
|
||
override protected def parseString(s: String): Array[String] = | ||
PlayPreferences.deserializeImports(s) | ||
|
||
override protected def getNewInputObject(): String = { | ||
|
||
val dlg = new InputDialog( | ||
Display.getCurrent().getActiveShell(), | ||
"Play template import", | ||
"Enter an import value:", | ||
"com.example._", | ||
new IInputValidator { | ||
def isValid(text: String) = null | ||
}); | ||
|
||
if (dlg.open() == Window.OK) { | ||
dlg.getValue() | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
} | ||
|
||
// The preference store being edited. | ||
// The data require to get the store is provided by the workbench during the page lifecycle. | ||
private var prefStore: IPreferenceStore = _ | ||
|
||
// Members declared in org.eclipse.jface.preference.FieldEditorPreferencePage | ||
|
||
override def createFieldEditors() { | ||
addField(new ImportsFieldEditor(PlayPreferences.TemplateImports, "Template default imports", getFieldEditorParent())) | ||
} | ||
|
||
// Members declared in org.eclipse.ui.IWorkbenchPropertyPage | ||
|
||
// doesn't seem to be a real function for this method. | ||
// It looks like it leaked from the implementation of PropertyPage. | ||
override def getElement(): IAdaptable = null | ||
|
||
override def setElement(element: IAdaptable) { | ||
prefStore = element match { | ||
case project: IProject => | ||
PlayPlugin.plugin.asPlayProject(project).get.generateScopedPreferenceStore | ||
case project: IJavaProject => | ||
PlayPlugin.plugin.asPlayProject(project.getProject()).get.generateScopedPreferenceStore | ||
} | ||
} | ||
|
||
// ---- | ||
|
||
override def doGetPreferenceStore(): IPreferenceStore = { | ||
prefStore | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
org.scala-ide.play2/src/org/scalaide/play2/util/Play2PropertyTester.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.scalaide.play2.util | ||
|
||
import org.eclipse.core.expressions.PropertyTester | ||
import org.eclipse.core.resources.IProject | ||
import org.scalaide.play2.PlayPlugin | ||
import org.eclipse.jdt.core.IJavaProject | ||
|
||
object Play2PropertyTester { | ||
final val IsPlayProject = "isPlay2Project" | ||
} | ||
|
||
/** Eclipse property tester. Can check if a project is a play2 project. | ||
*/ | ||
class Play2PropertyTester() extends PropertyTester { | ||
|
||
// from IPropertyTester | ||
|
||
override def test(receiver: Any, property: String, args: Array[Object], expectedValue: Any): Boolean = { | ||
import Play2PropertyTester._ | ||
|
||
property match { | ||
case IsPlayProject => | ||
receiver match { | ||
case project: IProject => | ||
PlayPlugin.plugin.asPlayProject(project).isDefined | ||
case project: IJavaProject => | ||
PlayPlugin.plugin.asPlayProject(project.getProject()).isDefined | ||
case _ => | ||
false | ||
} | ||
case _ => | ||
false | ||
} | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
org.scala-ide.play2/src/org/scalaide/play2/util/SyncedScopedPreferenceStore.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.scalaide.play2.util | ||
|
||
import org.eclipse.core.resources.IProject | ||
import org.eclipse.core.resources.ProjectScope | ||
import org.eclipse.ui.preferences.ScopedPreferenceStore | ||
|
||
class SyncedScopedPreferenceStore(project: IProject, pluginId: String) { | ||
|
||
private val preferenceStore = new ScopedPreferenceStore(new ProjectScope(project), pluginId) | ||
|
||
def getString(name: String): String = { | ||
preferenceStore.synchronized { | ||
preferenceStore.getString(name) | ||
} | ||
} | ||
} |