Contenu connexe
Similaire à Griffon不定期便〜G*ワークショップ編〜
Similaire à Griffon不定期便〜G*ワークショップ編〜 (20)
Plus de Kiyotaka Oku (14)
Griffon不定期便〜G*ワークショップ編〜
- 3. create-command-alias
$ griffon create-command-alias hoge
> test-app unit: foo.BarTests
$ griffon hoge
Grails
Griffon
(ry
2011 9 23
- 5. Java
package sample; contentPane.add(button);
import java.awt.Container; setDefaultCloseOperation(EXIT_ON_CLOSE);
import java.awt.GridLayout; pack();
import java.awt.event.ActionEvent; setVisible(true);
import java.awt.event.ActionListener; }
import javax.swing.JButton; public static void main(String[] args) {
import javax.swing.JFrame; SwingUtilities.invokeLater(new Runnable() {
import javax.swing.JLabel; public void run() {
import javax.swing.JTextArea; new Hello();
import javax.swing.SwingUtilities; }
});
public class Hello extends JFrame { }
}
public Hello() {
super("Hello");
Container contentPane = getContentPane();
contentPane.setLayout(new GridLayout(3, 1));
JLabel label = new JLabel("Label");
contentPane.add(label);
JTextArea textArea = new JTextArea("Text Area");
textArea.setColumns(20);
textArea.setRows(2);
contentPane.add(textArea);
JButton button = new JButton("Button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
}
});
2011 9 23
- 6. Groovy
import groovy.swing.SwingBuilder
new SwingBuilder().edt {
frame(title:'Hello', show:true, pack:true) {
gridLayout(cols:1, rows:3)
label 'Label'
textArea('Text Area', rows:2, columns:20)
button('Button', actionPerformed:{ evt ->
...
})
}
}
2011 9 23
- 7. Java
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
...
}
});
SwingUtilities.invokeLater(new Runnable() {
public void run() {
...
}
});
2011 9 23
- 8. &
export GRIFFON_HOME=/path/to/griffon
export PATH=$GRIFFON_HOME/bin:$PATH
2011 9 23
- 9. griffon [ ]
griffon create-app myApp
griffon run-app
griffon test-app
griffon package
2011 9 23
- 13. View
SwingBuilder
2011 9 23
- 14. SwingBuilder
groovy.swing.SwingBuilder
Groovy
javax.swing.JXxx -> xxx()
JButton -> button()
JLabel -> label()
2011 9 23
- 15. View
application(title:'Sample', pack:true, ...) {
tableLayout {
tr {
td { label('User Name') }
td { textField(columns:20) }
}
tr {
td { label('Password') }
td { passwordField(columns:20) }
}
tr {
td(colspan:2, align:'right') { button('Submit') }
}
}
}
2011 9 23
- 16. View
// MyMenuBar.groovy
menuBar {
menu('File') {
menuItem('Open')
menuItem('Save')
}
}
// MyAppView.groovy
application(...) {
build(MyMenuBar)
}
2011 9 23
- 17. View Java
// MyPanel.java
class MyPanel extends JPanel {
...
}
// MyAppView.groovy
application(...) {
widget(new MyPanel())
}
2011 9 23
- 20. View
SwingPad
GroovyConsole
2011 9 23
- 24. Model
package sample
class SampleModel {
String username
String password
}
2011 9 23
- 25. View Model
Model View
2011 9 23
- 26. Model
package sample
import groovy.beans.Bindable
class SampleModel {
@Bindable String username
@Bindable String password
}
2011 9 23
- 27. Model
package sample
import groovy.beans.Bindable
@Bindable
class SampleModel {
String username
String password
}
2011 9 23
- 28. View -> Model
textField(text:bind(target:model, targetProperty:‘username’))
textField(text:bind(target:model, ‘username’))
2011 9 23
- 29. Model -> View
textField(text:bind(source:model, sourceProperty:‘username’))
textField(text:bind(source:model, ‘username’))
textField(text:bind { model.username })
2011 9 23
- 30. View -> View
buttonGroup(id:'group1')
radioButton(id:‘radio1’, ‘ ’, buttonGroup:group1)
radioButton(id:‘radio2’, ‘ ’, buttonGroup:group1)
textField(editable:bind(source:radio1,
sourceEvent:‘itemStateChanged’,
sourceValue:{radio1.selected}))
2011 9 23
- 31. // Model
class Model {
Date now = new Date()
}
// View
label(text:bind(‘now’, source:model,
converter:{it.format(‘yyyy-MM-dd’)}))
2011 9 23
- 32. // Model
class Model {
int num
}
// View
textField(text:bind(‘num’, target:model,
validator:{ it?.isInteger() }))
2011 9 23
- 33. constraints?
class MyModel {
@Bindable String requiredText
@Bindable String url
@Bindable String email
static constraints = {
requiredText(blank:false)
url(url:true)
email(email:true)
}
}
2011 9 23
- 34. Validation
Grails constraints Model
model.validate()
model.errors
net.sourceforge.gvalidation.swing.ErrorMessagePanel
2011 9 23
- 35. ErrorMessagePanel
// View
widget(new ErrorMessagePanel(messageSource),
errors: bind(source: model, 'errors'))
2011 9 23
- 37. Controller
class SampleController {
def model
def view
void mvcGroupInit(Map args) { ... }
void mvcGroupDestroy() { ... }
def fooAction = { evt -> ... }
def barAction = { evt -> ... }
}
2011 9 23
- 38. View
button(‘Click!’,
actionPerformed:controller.fooAction)
2011 9 23
- 41. @Threading
griffon.transform.Threading
2011 9 23
- 42. class MyController {
@Threading(Threading.Policy.INSIDE_UITHREAD_SYNC)
def myAction = {
}
}
2011 9 23
- 43. Threading.Policy
OUTSIDE_UITHREAD
( )
INSIDE_UITHREAD_SYNC
UI
INSIDE_UITHREAD_ASYNC
UI
SKIP
2011 9 23
- 45. exec
execSync
UI
execAsync
UI
execOutside
2011 9 23
- 46. Java/Groovy/Griffon
Java Groovy Griffon
new Thread() doOutside execOutside
invokeLater doLater execAsync
invokeAndWait edt execSync
2011 9 23
- 47. MVC
Model View Controller
MVC
griffon create-mvc myNewGroup
2011 9 23
- 48. create-mvc
-skip(View|Model|Controller)
View/Model/Controller MVC
-fileType=(groovy|java|etc)
Java
2011 9 23
- 49. createMvcGroup
MVC
createMvcGroup(groupType, groupName, args)
2011 9 23
- 50. MVC
SplitPane MVC
TabbedPane MVC
View MVC
2011 9 23
- 51. Group1
// View
button('Add tab', actionPerformed:controller.addTab)
tabbedPane id: 'tabGroup'
// Controller
def addTab = {
def name = new Date().format('yyyy-MM-dd HH:mm:ss')
createMVCGroup("tab", name
[tabGroup: view.tabGroup, tabName: name])
}
2011 9 23
- 52. Group2
// View
tabbedPane(tabGroup, selectedIndex:tabGroup.tabCount) {
panel(title: tabName) {
label(tabName)
}
}
2011 9 23
- 54. Spock + FEST
class CalcSpec extends FestSpec {
def 'my first FEST spec'() {
when:
window.textBox('arg1').enterText(arg1)
window.textBox('arg2').enterText(arg2)
window.button('calculate').click()
then:
window.label('result').requireText(result)
where:
arg1 | arg2 | result
'1' | '1' | '2'
'1' | '2' | '3'
}
}
2011 9 23
- 56. 0.9.3
Griffon
0.9.3
2011 9 23