Configure action's properties

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Configure action's properties

markoong
Hello list,

I'm going through the initial chapters of the "Grina" book and while trying to translate the book's code examples to version 2.x of the framework I've hit an obstacle trying to set-up controllers' actions as described in the book's 1.2.1 paragraph.
To show some of the code, this is the Controller:
package org.grina

import griffon.core.artifact.GriffonController
import griffon.core.controller.ControllerAction
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.annotation.Nonnull
import javax.swing.JFileChooser

@ArtifactProviderFor(GriffonController)
class GroovyEditController {
    @MVCMember @Nonnull
    FactoryBuilderSupport builder

    @ControllerAction
    void openFileAction() {
        def openResult = builder.fileChooserWindow.showOpenDialog()
        if(JFileChooser.APPROVE_OPTION == openResult) {}
    }

    @ControllerAction
    void quitAction() {
        application.shutdown()
    }
}
and here is the relative view:
package org.grina

import griffon.core.artifact.GriffonView
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.swing.SwingConstants
import javax.annotation.Nonnull

@ArtifactProviderFor(GriffonView)
class GroovyEditView {
    @MVCMember @Nonnull
    FactoryBuilderSupport builder
    @MVCMember @Nonnull
    GroovyEditModel model

    @SuppressWarnings(["GroovyAssignabilityCheck"])
    void initUI() {
        builder.with {
            fileChooser(id: 'fileChooserWindow')
            application(size: [640, 320], id: 'mainWindow',
                title: application.configuration['application.title'],
                iconImage:   imageIcon('/griffon-icon-48x48.png').image,
                iconImages: [imageIcon('/griffon-icon-48x48.png').image,
                             imageIcon('/griffon-icon-32x32.png').image,
                             imageIcon('/griffon-icon-16x16.png').image]) {

                menuBar {
                    menu('File') {
                        menuItem openFileAction
                        separator()
                        menuItem quitAction
                    }
                }
                borderLayout()
                tabbedPane(id: 'tabGroup', constraints: CENTER)
            }
        }
    }
}
Now according to the manual (version 2.15.1) I should set up some properties to set up actions' name, accelerators, etc.., and this is what I've in my GroovyEdit/griffon-app/i18n/messages.properties:
org.grina.GroovyEditController.action.openFile.name=Opensss
org.grina.GroovyEditController.action.openFile.mnemonic=O
org.grina.GroovyEditController.action.openFile.accelerator=O
org.grina.GroovyEditController.action.openFile.enabled=false

org.grina.GroovyEditController.action.quit.name=Quitsss
org.grina.GroovyEditController.action.quit.mnemonic=Q
org.grina.GroovyEditController.action.quit.accelerator=Q
Unfortunately I can't see the Menu's entries modified accordingly, no matter what values I enter there and strangely enough I see the menu entry names set-up as "Open file" and "Quit" which I don't know where they come from (I guess some sort of default) :-| .

Also the Gradle task output does not contain any relevant errors:
> Task :run
[main] INFO org.codehaus.griffon.runtime.core.AbstractApplicationBootstrapper - Griffon 2.15.1
[main] INFO org.codehaus.griffon.runtime.core.AbstractApplicationBootstrapper - Build: 2018-11-06T14:02:08.126+0100
[main] INFO org.codehaus.griffon.runtime.core.AbstractApplicationBootstrapper - Revision: d5445b6e60e92ba6fe635ce9fe695c4b498f5ae7
[main] INFO org.codehaus.griffon.runtime.core.AbstractApplicationBootstrapper - JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)
[main] INFO org.codehaus.griffon.runtime.core.AbstractApplicationBootstrapper - OS: Linux 3.12.67-64-desktop amd64
[main] INFO griffon.util.AnnotationUtils - resource bundle loader class with instance org.codehaus.griffon.runtime.util.ClassResourceBundleLoader@723e88f9 evicted by org.codehaus.griffon.runtime.groovy.util.GroovyScriptResourceBundleLoader@5f0fd5a0
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 32: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 40: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 48: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 56: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 64: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 72: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 32: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 40: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 48: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 56: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 64: invalid attribute 'name'
Fontconfig error: "/home/marco/.config/fontconfig/fonts.conf", line 72: invalid attribute 'name'
[main] INFO griffon.swing.SwingGriffonApplication - Initializing all startup groups: [groovyEdit]
[griffon-pool-1-thread-1] INFO griffon.swing.SwingGriffonApplication - Shutdown is in process

BUILD SUCCESSFUL in 19s
3 actionable tasks: 1 executed, 2 up-to-date
3:46:22 PM: Task execution finished 'run'.
Any hints/suggestions/examples are really appreciated.

Thanks.
-- 
Marco Vittorini Orgeas
Reply | Threaded
Open this post in threaded view
|

Re: Configure action's properties

aalmiray
Administrator
Hi Marco,

Action key names should use the capatalized version of the action as shown at http://griffon-framework.org/guide/2.15.1/index.html#_controllers_actionmanager, that is

    org.grina.GroovyEditController.action.OpenFile.name

If no configuration is found then action properties follow certain defaults, that's why you see "Open File" in the menu as a result.

Cheers,
Andres