Working with action?

View: New views
4 Messages — Rating Filter:   Alert me  

Working with action?

by Sergio Lopes-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm having some doubts about how to use actions, or what are  the
correct action to use.

Much of my action are to exist in the menu bar, toolbar and popup
menus for the nodes. They are exactly the same actions, they should no
be different instances. And most of them should be context aware.
If I use the wizard to create an action it will create a callable
action or  a cookie action. I don't have use for cookies so I never
created cookie actions, I always created callable actions.
To make the actions context aware I was overriding the isEnabled
method, for every action. That is just what a cookie action must do
and I don't want to control what is selected and what is not.

Now I started porting some Dialogs to TopComponents, and ended up with
another type of action, an AbstractAction, that is visible in the
window menu.

So, what do I want? I need to make all this actions, that are
different instances and that are in different menus, the same object,
the same type of action, I also need them to be selection aware and I
need them to be in all three places, menu bar, toolbar and popup
menus. I also need the icons to behave accordingly, e.g. be a 16x16
icon when in the menu and a 22x22 icon when in the toolbar.

What type of action should I use and how can I make the same action
show in different places. I've read about .shadow files but I have
some trouble understanding the structure of the layer file, and what
represents what. Sorry but the tutorials are just too easy to follow,
so easy that they end up explaining nothing, I need to know how things
work in order to properly understand them, and the tutorials just tell
you where to click and what to copy, not what you are doing.

--
Best regards,

Sérgio Lopes

Re: Working with action?

by Jesse Glick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sergio Lopes wrote:
> I need to make all this actions, that are different instances and
> that are in different menus, the same object, the same type of
> action, I also need them to be selection aware and I need them to be
> in all three places, menu bar, toolbar and popup menus.

Define the action instance in Actions/*/*.instance. For declarative
registration, link to it:

<fo n=Menu>
   <fo n=Tools>
     <file name="my-action.shadow">
       <attr name="originalFile"
stringvalue="Actions/whatever/whatever.instance"/>

For popus menus etc., use
Repository.default.defaultFileSystem.findResource to find the .instance
file, then use DataObject.find and InstanceCookie to retrieve the actual
instance. Yes it is ugly, sorry.

The global action is a singleton so has one enablement state and action.
For use in context menus you will want to implement ContextAwareAction.

> I also need the icons to behave accordingly, e.g. be a 16x16 icon
> when in the menu and a 22x22 icon when in the toolbar.

Use

putValue("iconBase", "org/whatever/basicIcon.png");

and create

org/whatever/basicIcon.png
org/whatever/basicIcon24.png

The 24x24 will automatically be used in the toolbar (when large icons
are enabled).


Re: Re: Working with action?

by Sergio Lopes-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Thanks for the answer, I've been very busy trying to complete some
other tasks and I'm now returning to this task.
I tried to write something in the lines of what you told me but I'm
not getting this thing to produce the expected results.

My layer file has the following code:
 <folder name="Toolbars">
        <folder name="JFindMyFiles">
            <file name="NewDisk.shadow">
                    <attr name="originalFile"
stringvalue="Action/Edit/de-berlios-jfindmyfiles-jfindmyfilesgui-actions-ActionAddNewDisk.instance"/>
            </file>
            <file name="NewDiskGroup.shadow">
                    <attr name="originalFile"
stringvalue="Action/Edit/de-berlios-jfindmyfiles-jfindmyfilesgui-actions-ActionAddNewDiskGroup.instance"/>
            </file>
(...)

And in the actions I wrote the code for the icon:
putValue("iconBase",
"de/berlios/jfindmyfiles/jfindmyfilesgui/resources/icons/actions/new-disk.png");

Theres a new-disk.png and a new-disk24.png in that folder, but know
nothing shows, there is no icons, either in the menus or the toolbars.
Where can I find some docs about using the icons in actions?

--
Sem mais e com os melhores cumprimentos,

Sérgio Lopes

Re: Re: Working with action?

by Sergio Lopes-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I tried creation an action through the wizard, and it works, no
putValue used, only the iconResource method returns the name of the
16x16 icon version, the toolbar behaves has it should, when the "Small
Toolbar Icons" option is selected, I see the 16x16 ones and when it's
not I see the 24x24 ones.
Now, why don't my actions work?

Do I need to specify the positioning in the layer.xml file? Is the
declaration I shown before no enough?

--
Sem mais e com os melhores cumprimentos,

Sérgio Lopes
LightInTheBox - Buy quality products at wholesale price