How to use getNewTypes?

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

How to use getNewTypes?

by Klaus Martinschitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

I have written a FilterNode to filter a DataFolder object. In my
FitlerNode I write

 @Override
    public NewType[] getNewTypes() {
        return new NewType[]{
                    new NewType() {

                        @Override
                        public void create() throws IOException {
                            ...whatever...
                        }

                        @Override
                        public HelpCtx getHelpCtx() {
                            return super.getHelpCtx();
                        }

                        @Override
                        public String getName() {
                            return "My New Type";
                        }
                    }
                };
    }

But if I right click my node, nothing is displayed in the new section,
only disabled "Empty folder" and "Empty File" menu items. How do I have
to override my getActions method correctly?

Thanks.

Best regards,
Klaus

Re: How to use getNewTypes?

by Geertjan Wielenga :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Klaus Martinschitz wrote:

> Hi!
>
> I have written a FilterNode to filter a DataFolder object. In my
> FitlerNode I write
>
>  @Override
>     public NewType[] getNewTypes() {
>         return new NewType[]{
>                     new NewType() {
>
>                         @Override
>                         public void create() throws IOException {
>                             ...whatever...
>                         }
>
>                         @Override
>                         public HelpCtx getHelpCtx() {
>                             return super.getHelpCtx();
>                         }
>
>                         @Override
>                         public String getName() {
>                             return "My New Type";
>                         }
>                     }
>                 };
>     }
>
> But if I right click my node, nothing is displayed in the new section,
> only disabled "Empty folder" and "Empty File" menu items. How do I have
> to override my getActions method correctly?
>
> Thanks.
>
> Best regards,
> Klaus
>  
I think you need a NewAction in your getActions. The NewAction comes
from the Actions API.

Gj

Re: How to use getNewTypes?

by Klaus Martinschitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Geertjan Wielenga schrieb:

> Klaus Martinschitz wrote:
>> Hi!
>>
>> I have written a FilterNode to filter a DataFolder object. In my
>> FitlerNode I write
>>
>>  @Override
>>     public NewType[] getNewTypes() {
>>         return new NewType[]{
>>                     new NewType() {
>>
>>                         @Override
>>                         public void create() throws IOException {
>>                             ...whatever...
>>                         }
>>
>>                         @Override
>>                         public HelpCtx getHelpCtx() {
>>                             return super.getHelpCtx();
>>                         }
>>
>>                         @Override
>>                         public String getName() {
>>                             return "My New Type";
>>                         }
>>                     }
>>                 };
>>     }
>>
>> But if I right click my node, nothing is displayed in the new section,
>> only disabled "Empty folder" and "Empty File" menu items. How do I have
>> to override my getActions method correctly?
>>
>> Thanks.
>>
>> Best regards,
>> Klaus
>>  
> I think you need a NewAction in your getActions. The NewAction comes
> from the Actions API.
>
> Gj
>
Hi!

Thanks, I tried this

 @Override
    public Action[] getActions(boolean arg0) {
        return new Action[]{SystemAction.get(NewAction.class)};
    }

This does not work. There is only a disabled and "Add" labeled MenuItem
appearing in my popup menu.

Regards,
Klaus


Re: How to use getNewTypes?

by bruehlicke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here something from my code. (the "DeleteAction" is my own action -
all the others are out-of-the-box

Hope that gets you going.

    @Override
    public Action[] getActions(boolean popup) {
        List<Action> actions = new ArrayList<Action>();

        actions.add(SystemAction.get(NewAction.class));
        actions.add(SystemAction.get(RenameAction.class));
        actions.add(new DeleteAction());
        actions.add(null);
        actions.add(SystemAction.get(PropertiesAction.class));

        return actions.toArray(new Action[actions.size()]);
    }

Bernd



On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
<klausmartinschitz@...> wrote:

> Geertjan Wielenga schrieb:
>> Klaus Martinschitz wrote:
>>> Hi!
>>>
>>> I have written a FilterNode to filter a DataFolder object. In my
>>> FitlerNode I write
>>>
>>>  @Override
>>>     public NewType[] getNewTypes() {
>>>         return new NewType[]{
>>>                     new NewType() {
>>>
>>>                         @Override
>>>                         public void create() throws IOException {
>>>                             ...whatever...
>>>                         }
>>>
>>>                         @Override
>>>                         public HelpCtx getHelpCtx() {
>>>                             return super.getHelpCtx();
>>>                         }
>>>
>>>                         @Override
>>>                         public String getName() {
>>>                             return "My New Type";
>>>                         }
>>>                     }
>>>                 };
>>>     }
>>>
>>> But if I right click my node, nothing is displayed in the new section,
>>> only disabled "Empty folder" and "Empty File" menu items. How do I have
>>> to override my getActions method correctly?
>>>
>>> Thanks.
>>>
>>> Best regards,
>>> Klaus
>>>
>> I think you need a NewAction in your getActions. The NewAction comes
>> from the Actions API.
>>
>> Gj
>>
> Hi!
>
> Thanks, I tried this
>
>  @Override
>    public Action[] getActions(boolean arg0) {
>        return new Action[]{SystemAction.get(NewAction.class)};
>    }
>
> This does not work. There is only a disabled and "Add" labeled MenuItem
> appearing in my popup menu.
>
> Regards,
> Klaus
>
>

Re: How to use getNewTypes?

by bruehlicke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

.. opps sorry ... and in addition to get the NewAction to fill up you
need a method


    @Override
    public NewType[] getNewTypes() {
        return new NewType[]{new MyAction1(), new MyAction2()};
    }


B-)




On Mon, Oct 26, 2009 at 2:23 PM, bruehlicke <bruehlicke@...> wrote:

> Here something from my code. (the "DeleteAction" is my own action -
> all the others are out-of-the-box
>
> Hope that gets you going.
>
>    @Override
>    public Action[] getActions(boolean popup) {
>        List<Action> actions = new ArrayList<Action>();
>
>        actions.add(SystemAction.get(NewAction.class));
>        actions.add(SystemAction.get(RenameAction.class));
>        actions.add(new DeleteAction());
>        actions.add(null);
>        actions.add(SystemAction.get(PropertiesAction.class));
>
>        return actions.toArray(new Action[actions.size()]);
>    }
>
> Bernd
>
>
>
> On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
> <klausmartinschitz@...> wrote:
>> Geertjan Wielenga schrieb:
>>> Klaus Martinschitz wrote:
>>>> Hi!
>>>>
>>>> I have written a FilterNode to filter a DataFolder object. In my
>>>> FitlerNode I write
>>>>
>>>>  @Override
>>>>     public NewType[] getNewTypes() {
>>>>         return new NewType[]{
>>>>                     new NewType() {
>>>>
>>>>                         @Override
>>>>                         public void create() throws IOException {
>>>>                             ...whatever...
>>>>                         }
>>>>
>>>>                         @Override
>>>>                         public HelpCtx getHelpCtx() {
>>>>                             return super.getHelpCtx();
>>>>                         }
>>>>
>>>>                         @Override
>>>>                         public String getName() {
>>>>                             return "My New Type";
>>>>                         }
>>>>                     }
>>>>                 };
>>>>     }
>>>>
>>>> But if I right click my node, nothing is displayed in the new section,
>>>> only disabled "Empty folder" and "Empty File" menu items. How do I have
>>>> to override my getActions method correctly?
>>>>
>>>> Thanks.
>>>>
>>>> Best regards,
>>>> Klaus
>>>>
>>> I think you need a NewAction in your getActions. The NewAction comes
>>> from the Actions API.
>>>
>>> Gj
>>>
>> Hi!
>>
>> Thanks, I tried this
>>
>>  @Override
>>    public Action[] getActions(boolean arg0) {
>>        return new Action[]{SystemAction.get(NewAction.class)};
>>    }
>>
>> This does not work. There is only a disabled and "Add" labeled MenuItem
>> appearing in my popup menu.
>>
>> Regards,
>> Klaus
>>
>>
>

Re: How to use getNewTypes?

by bruehlicke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

.. and ... theose new Types are implemented like for example


    private class MyAction1 extends NewType {

        @Override
        public String getName() {
            return "MyAction1";
        }

        @Override
        public void create() throws IOException {

        // Write code here what has to happen if selected (typically
calling a real Action or so ...

}




On Mon, Oct 26, 2009 at 2:25 PM, bruehlicke <bruehlicke@...> wrote:

> .. opps sorry ... and in addition to get the NewAction to fill up you
> need a method
>
>
>    @Override
>    public NewType[] getNewTypes() {
>        return new NewType[]{new MyAction1(), new MyAction2()};
>    }
>
>
> B-)
>
>
>
>
> On Mon, Oct 26, 2009 at 2:23 PM, bruehlicke <bruehlicke@...> wrote:
>> Here something from my code. (the "DeleteAction" is my own action -
>> all the others are out-of-the-box
>>
>> Hope that gets you going.
>>
>>    @Override
>>    public Action[] getActions(boolean popup) {
>>        List<Action> actions = new ArrayList<Action>();
>>
>>        actions.add(SystemAction.get(NewAction.class));
>>        actions.add(SystemAction.get(RenameAction.class));
>>        actions.add(new DeleteAction());
>>        actions.add(null);
>>        actions.add(SystemAction.get(PropertiesAction.class));
>>
>>        return actions.toArray(new Action[actions.size()]);
>>    }
>>
>> Bernd
>>
>>
>>
>> On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
>> <klausmartinschitz@...> wrote:
>>> Geertjan Wielenga schrieb:
>>>> Klaus Martinschitz wrote:
>>>>> Hi!
>>>>>
>>>>> I have written a FilterNode to filter a DataFolder object. In my
>>>>> FitlerNode I write
>>>>>
>>>>>  @Override
>>>>>     public NewType[] getNewTypes() {
>>>>>         return new NewType[]{
>>>>>                     new NewType() {
>>>>>
>>>>>                         @Override
>>>>>                         public void create() throws IOException {
>>>>>                             ...whatever...
>>>>>                         }
>>>>>
>>>>>                         @Override
>>>>>                         public HelpCtx getHelpCtx() {
>>>>>                             return super.getHelpCtx();
>>>>>                         }
>>>>>
>>>>>                         @Override
>>>>>                         public String getName() {
>>>>>                             return "My New Type";
>>>>>                         }
>>>>>                     }
>>>>>                 };
>>>>>     }
>>>>>
>>>>> But if I right click my node, nothing is displayed in the new section,
>>>>> only disabled "Empty folder" and "Empty File" menu items. How do I have
>>>>> to override my getActions method correctly?
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Best regards,
>>>>> Klaus
>>>>>
>>>> I think you need a NewAction in your getActions. The NewAction comes
>>>> from the Actions API.
>>>>
>>>> Gj
>>>>
>>> Hi!
>>>
>>> Thanks, I tried this
>>>
>>>  @Override
>>>    public Action[] getActions(boolean arg0) {
>>>        return new Action[]{SystemAction.get(NewAction.class)};
>>>    }
>>>
>>> This does not work. There is only a disabled and "Add" labeled MenuItem
>>> appearing in my popup menu.
>>>
>>> Regards,
>>> Klaus
>>>
>>>
>>
>

Re: How to use getNewTypes?

by Fabrizio Giudici :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

bruehlicke wrote:
> Here something from my code. (the "DeleteAction" is my own action -
> all the others are out-of-the-box
>
> Hope that gets you going.
>
> @Override public Action[] getActions(boolean popup) { List<Action>
> actions = new ArrayList<Action>();
>
> actions.add(SystemAction.get(NewAction.class));
> actions.add(SystemAction.get(RenameAction.class)); actions.add(new
> DeleteAction()); actions.add(null);
> actions.add(SystemAction.get(PropertiesAction.class));
>
> return actions.toArray(new Action[actions.size()]); }

As as side note, I suggest that even Actions for nodes are injected by using Lookups.forPath(), in a similar way as we today were discussing how to put actions in a Toolbar. In this way, actions are defined in layer.xml and your code is extendable at will.



--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/people
Fabrizio.Giudici@...


Re: How to use getNewTypes?

by Geertjan Wielenga :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>
> As as side note, I suggest that even Actions for nodes are injected by
> using Lookups.forPath(), in a similar way as we today were discussing
> how to put actions in a Toolbar. In this way, actions are defined in
> layer.xml and your code is extendable at will.
>
Take note of what Jesse added in the comments in my blog today:

http://blogs.sun.com/geertjan/entry/calling_an_action_in_the

Gj

Re: How to use getNewTypes?

by Klaus Martinschitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

bruehlicke schrieb:

> .. and ... theose new Types are implemented like for example
>
>
>     private class MyAction1 extends NewType {
>
>         @Override
>         public String getName() {
>             return "MyAction1";
>         }
>
>         @Override
>         public void create() throws IOException {
>
>         // Write code here what has to happen if selected (typically
> calling a real Action or so ...
>
> }
>
>
>
>
> On Mon, Oct 26, 2009 at 2:25 PM, bruehlicke <bruehlicke@...> wrote:
>  
>> .. opps sorry ... and in addition to get the NewAction to fill up you
>> need a method
>>
>>
>>    @Override
>>    public NewType[] getNewTypes() {
>>        return new NewType[]{new MyAction1(), new MyAction2()};
>>    }
>>
>>
>> B-)
>>
>>
>>
>>
>> On Mon, Oct 26, 2009 at 2:23 PM, bruehlicke <bruehlicke@...> wrote:
>>    
>>> Here something from my code. (the "DeleteAction" is my own action -
>>> all the others are out-of-the-box
>>>
>>> Hope that gets you going.
>>>
>>>    @Override
>>>    public Action[] getActions(boolean popup) {
>>>        List<Action> actions = new ArrayList<Action>();
>>>
>>>        actions.add(SystemAction.get(NewAction.class));
>>>        actions.add(SystemAction.get(RenameAction.class));
>>>        actions.add(new DeleteAction());
>>>        actions.add(null);
>>>        actions.add(SystemAction.get(PropertiesAction.class));
>>>
>>>        return actions.toArray(new Action[actions.size()]);
>>>    }
>>>
>>> Bernd
>>>
>>>
>>>
>>> On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
>>> <klausmartinschitz@...> wrote:
>>>      
>>>> Geertjan Wielenga schrieb:
>>>>        
>>>>> Klaus Martinschitz wrote:
>>>>>          
>>>>>> Hi!
>>>>>>
>>>>>> I have written a FilterNode to filter a DataFolder object. In my
>>>>>> FitlerNode I write
>>>>>>
>>>>>>  @Override
>>>>>>     public NewType[] getNewTypes() {
>>>>>>         return new NewType[]{
>>>>>>                     new NewType() {
>>>>>>
>>>>>>                         @Override
>>>>>>                         public void create() throws IOException {
>>>>>>                             ...whatever...
>>>>>>                         }
>>>>>>
>>>>>>                         @Override
>>>>>>                         public HelpCtx getHelpCtx() {
>>>>>>                             return super.getHelpCtx();
>>>>>>                         }
>>>>>>
>>>>>>                         @Override
>>>>>>                         public String getName() {
>>>>>>                             return "My New Type";
>>>>>>                         }
>>>>>>                     }
>>>>>>                 };
>>>>>>     }
>>>>>>
>>>>>> But if I right click my node, nothing is displayed in the new section,
>>>>>> only disabled "Empty folder" and "Empty File" menu items. How do I have
>>>>>> to override my getActions method correctly?
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> Best regards,
>>>>>> Klaus
>>>>>>
>>>>>>            
>>>>> I think you need a NewAction in your getActions. The NewAction comes
>>>>> from the Actions API.
>>>>>
>>>>> Gj
>>>>>
>>>>>          
>>>> Hi!
>>>>
>>>> Thanks, I tried this
>>>>
>>>>  @Override
>>>>    public Action[] getActions(boolean arg0) {
>>>>        return new Action[]{SystemAction.get(NewAction.class)};
>>>>    }
>>>>
>>>> This does not work. There is only a disabled and "Add" labeled MenuItem
>>>> appearing in my popup menu.
>>>>
>>>> Regards,
>>>> Klaus
>>>>
>>>>
>>>>        
>
>  
Hi!

Thanks for help. I don't know why, but it does not work in my case. If I
debuff my code, the getActions method is called properly. I also have an
additional "Add" MenuItem in my popup menu (which is disabled). But my
added (extended) NewType "Action" (Don't know why this is called action)
neither is part of the submenu "new" nor anything else. I don't see any
menuitem with my label defined in the getName method of NewType. Hmmmm.
Which NetBeans Platform Version do you use?
Thanks.

Bye,
Klaus

Re: How to use getNewTypes?

by bruehlicke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I run Nb 6.5

Can you add some code showing the NewType extending private class, the
getNewTypes method and the getActions method.

B-)

On Tue, Oct 27, 2009 at 11:38 AM, Klaus Martinschitz
<klausmartinschitz@...> wrote:

> bruehlicke schrieb:
>> .. and ... theose new Types are implemented like for example
>>
>>
>>     private class MyAction1 extends NewType {
>>
>>         @Override
>>         public String getName() {
>>             return "MyAction1";
>>         }
>>
>>         @Override
>>         public void create() throws IOException {
>>
>>         // Write code here what has to happen if selected (typically
>> calling a real Action or so ...
>>
>> }
>>
>>
>>
>>
>> On Mon, Oct 26, 2009 at 2:25 PM, bruehlicke <bruehlicke@...> wrote:
>>
>>> .. opps sorry ... and in addition to get the NewAction to fill up you
>>> need a method
>>>
>>>
>>>    @Override
>>>    public NewType[] getNewTypes() {
>>>        return new NewType[]{new MyAction1(), new MyAction2()};
>>>    }
>>>
>>>
>>> B-)
>>>
>>>
>>>
>>>
>>> On Mon, Oct 26, 2009 at 2:23 PM, bruehlicke <bruehlicke@...> wrote:
>>>
>>>> Here something from my code. (the "DeleteAction" is my own action -
>>>> all the others are out-of-the-box
>>>>
>>>> Hope that gets you going.
>>>>
>>>>    @Override
>>>>    public Action[] getActions(boolean popup) {
>>>>        List<Action> actions = new ArrayList<Action>();
>>>>
>>>>        actions.add(SystemAction.get(NewAction.class));
>>>>        actions.add(SystemAction.get(RenameAction.class));
>>>>        actions.add(new DeleteAction());
>>>>        actions.add(null);
>>>>        actions.add(SystemAction.get(PropertiesAction.class));
>>>>
>>>>        return actions.toArray(new Action[actions.size()]);
>>>>    }
>>>>
>>>> Bernd
>>>>
>>>>
>>>>
>>>> On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
>>>> <klausmartinschitz@...> wrote:
>>>>
>>>>> Geertjan Wielenga schrieb:
>>>>>
>>>>>> Klaus Martinschitz wrote:
>>>>>>
>>>>>>> Hi!
>>>>>>>
>>>>>>> I have written a FilterNode to filter a DataFolder object. In my
>>>>>>> FitlerNode I write
>>>>>>>
>>>>>>>  @Override
>>>>>>>     public NewType[] getNewTypes() {
>>>>>>>         return new NewType[]{
>>>>>>>                     new NewType() {
>>>>>>>
>>>>>>>                         @Override
>>>>>>>                         public void create() throws IOException {
>>>>>>>                             ...whatever...
>>>>>>>                         }
>>>>>>>
>>>>>>>                         @Override
>>>>>>>                         public HelpCtx getHelpCtx() {
>>>>>>>                             return super.getHelpCtx();
>>>>>>>                         }
>>>>>>>
>>>>>>>                         @Override
>>>>>>>                         public String getName() {
>>>>>>>                             return "My New Type";
>>>>>>>                         }
>>>>>>>                     }
>>>>>>>                 };
>>>>>>>     }
>>>>>>>
>>>>>>> But if I right click my node, nothing is displayed in the new section,
>>>>>>> only disabled "Empty folder" and "Empty File" menu items. How do I have
>>>>>>> to override my getActions method correctly?
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>> Best regards,
>>>>>>> Klaus
>>>>>>>
>>>>>>>
>>>>>> I think you need a NewAction in your getActions. The NewAction comes
>>>>>> from the Actions API.
>>>>>>
>>>>>> Gj
>>>>>>
>>>>>>
>>>>> Hi!
>>>>>
>>>>> Thanks, I tried this
>>>>>
>>>>>  @Override
>>>>>    public Action[] getActions(boolean arg0) {
>>>>>        return new Action[]{SystemAction.get(NewAction.class)};
>>>>>    }
>>>>>
>>>>> This does not work. There is only a disabled and "Add" labeled MenuItem
>>>>> appearing in my popup menu.
>>>>>
>>>>> Regards,
>>>>> Klaus
>>>>>
>>>>>
>>>>>
>>
>>
> Hi!
>
> Thanks for help. I don't know why, but it does not work in my case. If I
> debuff my code, the getActions method is called properly. I also have an
> additional "Add" MenuItem in my popup menu (which is disabled). But my
> added (extended) NewType "Action" (Don't know why this is called action)
> neither is part of the submenu "new" nor anything else. I don't see any
> menuitem with my label defined in the getName method of NewType. Hmmmm.
> Which NetBeans Platform Version do you use?
> Thanks.
>
> Bye,
> Klaus
>

Re: How to use getNewTypes?

by Geertjan Wielenga :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

bruehlicke wrote:
> I run Nb 6.5
>
> Can you add some code showing the NewType extending private class, the
> getNewTypes method and the getActions method.
>
>  

I'm confused too:

http://blogs.sun.com/geertjan/entry/how_to_use_getnewtypes

Gj

> B-)
>
> On Tue, Oct 27, 2009 at 11:38 AM, Klaus Martinschitz
> <klausmartinschitz@...> wrote:
>  
>> bruehlicke schrieb:
>>    
>>> .. and ... theose new Types are implemented like for example
>>>
>>>
>>>     private class MyAction1 extends NewType {
>>>
>>>         @Override
>>>         public String getName() {
>>>             return "MyAction1";
>>>         }
>>>
>>>         @Override
>>>         public void create() throws IOException {
>>>
>>>         // Write code here what has to happen if selected (typically
>>> calling a real Action or so ...
>>>
>>> }
>>>
>>>
>>>
>>>
>>> On Mon, Oct 26, 2009 at 2:25 PM, bruehlicke <bruehlicke@...> wrote:
>>>
>>>      
>>>> .. opps sorry ... and in addition to get the NewAction to fill up you
>>>> need a method
>>>>
>>>>
>>>>    @Override
>>>>    public NewType[] getNewTypes() {
>>>>        return new NewType[]{new MyAction1(), new MyAction2()};
>>>>    }
>>>>
>>>>
>>>> B-)
>>>>
>>>>
>>>>
>>>>
>>>> On Mon, Oct 26, 2009 at 2:23 PM, bruehlicke <bruehlicke@...> wrote:
>>>>
>>>>        
>>>>> Here something from my code. (the "DeleteAction" is my own action -
>>>>> all the others are out-of-the-box
>>>>>
>>>>> Hope that gets you going.
>>>>>
>>>>>    @Override
>>>>>    public Action[] getActions(boolean popup) {
>>>>>        List<Action> actions = new ArrayList<Action>();
>>>>>
>>>>>        actions.add(SystemAction.get(NewAction.class));
>>>>>        actions.add(SystemAction.get(RenameAction.class));
>>>>>        actions.add(new DeleteAction());
>>>>>        actions.add(null);
>>>>>        actions.add(SystemAction.get(PropertiesAction.class));
>>>>>
>>>>>        return actions.toArray(new Action[actions.size()]);
>>>>>    }
>>>>>
>>>>> Bernd
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
>>>>> <klausmartinschitz@...> wrote:
>>>>>
>>>>>          
>>>>>> Geertjan Wielenga schrieb:
>>>>>>
>>>>>>            
>>>>>>> Klaus Martinschitz wrote:
>>>>>>>
>>>>>>>              
>>>>>>>> Hi!
>>>>>>>>
>>>>>>>> I have written a FilterNode to filter a DataFolder object. In my
>>>>>>>> FitlerNode I write
>>>>>>>>
>>>>>>>>  @Override
>>>>>>>>     public NewType[] getNewTypes() {
>>>>>>>>         return new NewType[]{
>>>>>>>>                     new NewType() {
>>>>>>>>
>>>>>>>>                         @Override
>>>>>>>>                         public void create() throws IOException {
>>>>>>>>                             ...whatever...
>>>>>>>>                         }
>>>>>>>>
>>>>>>>>                         @Override
>>>>>>>>                         public HelpCtx getHelpCtx() {
>>>>>>>>                             return super.getHelpCtx();
>>>>>>>>                         }
>>>>>>>>
>>>>>>>>                         @Override
>>>>>>>>                         public String getName() {
>>>>>>>>                             return "My New Type";
>>>>>>>>                         }
>>>>>>>>                     }
>>>>>>>>                 };
>>>>>>>>     }
>>>>>>>>
>>>>>>>> But if I right click my node, nothing is displayed in the new section,
>>>>>>>> only disabled "Empty folder" and "Empty File" menu items. How do I have
>>>>>>>> to override my getActions method correctly?
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>>
>>>>>>>> Best regards,
>>>>>>>> Klaus
>>>>>>>>
>>>>>>>>
>>>>>>>>                
>>>>>>> I think you need a NewAction in your getActions. The NewAction comes
>>>>>>> from the Actions API.
>>>>>>>
>>>>>>> Gj
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>> Hi!
>>>>>>
>>>>>> Thanks, I tried this
>>>>>>
>>>>>>  @Override
>>>>>>    public Action[] getActions(boolean arg0) {
>>>>>>        return new Action[]{SystemAction.get(NewAction.class)};
>>>>>>    }
>>>>>>
>>>>>> This does not work. There is only a disabled and "Add" labeled MenuItem
>>>>>> appearing in my popup menu.
>>>>>>
>>>>>> Regards,
>>>>>> Klaus
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>      
>> Hi!
>>
>> Thanks for help. I don't know why, but it does not work in my case. If I
>> debuff my code, the getActions method is called properly. I also have an
>> additional "Add" MenuItem in my popup menu (which is disabled). But my
>> added (extended) NewType "Action" (Don't know why this is called action)
>> neither is part of the submenu "new" nor anything else. I don't see any
>> menuitem with my label defined in the getName method of NewType. Hmmmm.
>> Which NetBeans Platform Version do you use?
>> Thanks.
>>
>> Bye,
>> Klaus
>>
>>    


Re: How to use getNewTypes?

by Geertjan Wielenga :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Fixed it!

        Lookup lkp = ExplorerUtils.createLookup(em, getActionMap());
        associateLookup(lkp);


That was missing in the constructor of my own TopComponent. Then the
action displayed and worked as expected.

I bet that also fixes the problems of others in this thread with this
problem.

Gj



Geertjan Wielenga wrote:

> bruehlicke wrote:
>> I run Nb 6.5
>>
>> Can you add some code showing the NewType extending private class, the
>> getNewTypes method and the getActions method.
>>
>>  
>
> I'm confused too:
>
> http://blogs.sun.com/geertjan/entry/how_to_use_getnewtypes
>
> Gj
>
>> B-)
>>
>> On Tue, Oct 27, 2009 at 11:38 AM, Klaus Martinschitz
>> <klausmartinschitz@...> wrote:
>>  
>>> bruehlicke schrieb:
>>>    
>>>> .. and ... theose new Types are implemented like for example
>>>>
>>>>
>>>>     private class MyAction1 extends NewType {
>>>>
>>>>         @Override
>>>>         public String getName() {
>>>>             return "MyAction1";
>>>>         }
>>>>
>>>>         @Override
>>>>         public void create() throws IOException {
>>>>
>>>>         // Write code here what has to happen if selected (typically
>>>> calling a real Action or so ...
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>>
>>>> On Mon, Oct 26, 2009 at 2:25 PM, bruehlicke <bruehlicke@...>
>>>> wrote:
>>>>
>>>>      
>>>>> .. opps sorry ... and in addition to get the NewAction to fill up you
>>>>> need a method
>>>>>
>>>>>
>>>>>    @Override
>>>>>    public NewType[] getNewTypes() {
>>>>>        return new NewType[]{new MyAction1(), new MyAction2()};
>>>>>    }
>>>>>
>>>>>
>>>>> B-)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Oct 26, 2009 at 2:23 PM, bruehlicke <bruehlicke@...>
>>>>> wrote:
>>>>>
>>>>>        
>>>>>> Here something from my code. (the "DeleteAction" is my own action -
>>>>>> all the others are out-of-the-box
>>>>>>
>>>>>> Hope that gets you going.
>>>>>>
>>>>>>    @Override
>>>>>>    public Action[] getActions(boolean popup) {
>>>>>>        List<Action> actions = new ArrayList<Action>();
>>>>>>
>>>>>>        actions.add(SystemAction.get(NewAction.class));
>>>>>>        actions.add(SystemAction.get(RenameAction.class));
>>>>>>        actions.add(new DeleteAction());
>>>>>>        actions.add(null);
>>>>>>        actions.add(SystemAction.get(PropertiesAction.class));
>>>>>>
>>>>>>        return actions.toArray(new Action[actions.size()]);
>>>>>>    }
>>>>>>
>>>>>> Bernd
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
>>>>>> <klausmartinschitz@...> wrote:
>>>>>>
>>>>>>          
>>>>>>> Geertjan Wielenga schrieb:
>>>>>>>
>>>>>>>            
>>>>>>>> Klaus Martinschitz wrote:
>>>>>>>>
>>>>>>>>              
>>>>>>>>> Hi!
>>>>>>>>>
>>>>>>>>> I have written a FilterNode to filter a DataFolder object. In my
>>>>>>>>> FitlerNode I write
>>>>>>>>>
>>>>>>>>>  @Override
>>>>>>>>>     public NewType[] getNewTypes() {
>>>>>>>>>         return new NewType[]{
>>>>>>>>>                     new NewType() {
>>>>>>>>>
>>>>>>>>>                         @Override
>>>>>>>>>                         public void create() throws IOException {
>>>>>>>>>                             ...whatever...
>>>>>>>>>                         }
>>>>>>>>>
>>>>>>>>>                         @Override
>>>>>>>>>                         public HelpCtx getHelpCtx() {
>>>>>>>>>                             return super.getHelpCtx();
>>>>>>>>>                         }
>>>>>>>>>
>>>>>>>>>                         @Override
>>>>>>>>>                         public String getName() {
>>>>>>>>>                             return "My New Type";
>>>>>>>>>                         }
>>>>>>>>>                     }
>>>>>>>>>                 };
>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>> But if I right click my node, nothing is displayed in the new
>>>>>>>>> section,
>>>>>>>>> only disabled "Empty folder" and "Empty File" menu items. How
>>>>>>>>> do I have
>>>>>>>>> to override my getActions method correctly?
>>>>>>>>>
>>>>>>>>> Thanks.
>>>>>>>>>
>>>>>>>>> Best regards,
>>>>>>>>> Klaus
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>                
>>>>>>>> I think you need a NewAction in your getActions. The NewAction
>>>>>>>> comes
>>>>>>>> from the Actions API.
>>>>>>>>
>>>>>>>> Gj
>>>>>>>>
>>>>>>>>
>>>>>>>>              
>>>>>>> Hi!
>>>>>>>
>>>>>>> Thanks, I tried this
>>>>>>>
>>>>>>>  @Override
>>>>>>>    public Action[] getActions(boolean arg0) {
>>>>>>>        return new Action[]{SystemAction.get(NewAction.class)};
>>>>>>>    }
>>>>>>>
>>>>>>> This does not work. There is only a disabled and "Add" labeled
>>>>>>> MenuItem
>>>>>>> appearing in my popup menu.
>>>>>>>
>>>>>>> Regards,
>>>>>>> Klaus
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>            
>>>>      
>>> Hi!
>>>
>>> Thanks for help. I don't know why, but it does not work in my case.
>>> If I
>>> debuff my code, the getActions method is called properly. I also
>>> have an
>>> additional "Add" MenuItem in my popup menu (which is disabled). But my
>>> added (extended) NewType "Action" (Don't know why this is called
>>> action)
>>> neither is part of the submenu "new" nor anything else. I don't see any
>>> menuitem with my label defined in the getName method of NewType. Hmmmm.
>>> Which NetBeans Platform Version do you use?
>>> Thanks.
>>>
>>> Bye,
>>> Klaus
>>>
>>>    
>


Re: How to use getNewTypes?

by Klaus Martinschitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Geertjan Wielenga schrieb:

>
> Fixed it!
>
>        Lookup lkp = ExplorerUtils.createLookup(em, getActionMap());
>        associateLookup(lkp);
>
>
> That was missing in the constructor of my own TopComponent. Then the
> action displayed and worked as expected.
>
> I bet that also fixes the problems of others in this thread with this
> problem.
>
> Gj
>
>
>
> Geertjan Wielenga wrote:
>> bruehlicke wrote:
>>> I run Nb 6.5
>>>
>>> Can you add some code showing the NewType extending private class, the
>>> getNewTypes method and the getActions method.
>>>
>>>  
>>
>> I'm confused too:
>>
>> http://blogs.sun.com/geertjan/entry/how_to_use_getnewtypes
>>
>> Gj
>>
>>> B-)
>>>
>>> On Tue, Oct 27, 2009 at 11:38 AM, Klaus Martinschitz
>>> <klausmartinschitz@...> wrote:
>>>  
>>>> bruehlicke schrieb:
>>>>  
>>>>> .. and ... theose new Types are implemented like for example
>>>>>
>>>>>
>>>>>     private class MyAction1 extends NewType {
>>>>>
>>>>>         @Override
>>>>>         public String getName() {
>>>>>             return "MyAction1";
>>>>>         }
>>>>>
>>>>>         @Override
>>>>>         public void create() throws IOException {
>>>>>
>>>>>         // Write code here what has to happen if selected (typically
>>>>> calling a real Action or so ...
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Oct 26, 2009 at 2:25 PM, bruehlicke <bruehlicke@...>
>>>>> wrote:
>>>>>
>>>>>    
>>>>>> .. opps sorry ... and in addition to get the NewAction to fill up
>>>>>> you
>>>>>> need a method
>>>>>>
>>>>>>
>>>>>>    @Override
>>>>>>    public NewType[] getNewTypes() {
>>>>>>        return new NewType[]{new MyAction1(), new MyAction2()};
>>>>>>    }
>>>>>>
>>>>>>
>>>>>> B-)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Mon, Oct 26, 2009 at 2:23 PM, bruehlicke
>>>>>> <bruehlicke@...> wrote:
>>>>>>
>>>>>>      
>>>>>>> Here something from my code. (the "DeleteAction" is my own action -
>>>>>>> all the others are out-of-the-box
>>>>>>>
>>>>>>> Hope that gets you going.
>>>>>>>
>>>>>>>    @Override
>>>>>>>    public Action[] getActions(boolean popup) {
>>>>>>>        List<Action> actions = new ArrayList<Action>();
>>>>>>>
>>>>>>>        actions.add(SystemAction.get(NewAction.class));
>>>>>>>        actions.add(SystemAction.get(RenameAction.class));
>>>>>>>        actions.add(new DeleteAction());
>>>>>>>        actions.add(null);
>>>>>>>        actions.add(SystemAction.get(PropertiesAction.class));
>>>>>>>
>>>>>>>        return actions.toArray(new Action[actions.size()]);
>>>>>>>    }
>>>>>>>
>>>>>>> Bernd
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Oct 26, 2009 at 12:03 PM, Klaus Martinschitz
>>>>>>> <klausmartinschitz@...> wrote:
>>>>>>>
>>>>>>>        
>>>>>>>> Geertjan Wielenga schrieb:
>>>>>>>>
>>>>>>>>          
>>>>>>>>> Klaus Martinschitz wrote:
>>>>>>>>>
>>>>>>>>>            
>>>>>>>>>> Hi!
>>>>>>>>>>
>>>>>>>>>> I have written a FilterNode to filter a DataFolder object. In my
>>>>>>>>>> FitlerNode I write
>>>>>>>>>>
>>>>>>>>>>  @Override
>>>>>>>>>>     public NewType[] getNewTypes() {
>>>>>>>>>>         return new NewType[]{
>>>>>>>>>>                     new NewType() {
>>>>>>>>>>
>>>>>>>>>>                         @Override
>>>>>>>>>>                         public void create() throws
>>>>>>>>>> IOException {
>>>>>>>>>>                             ...whatever...
>>>>>>>>>>                         }
>>>>>>>>>>
>>>>>>>>>>                         @Override
>>>>>>>>>>                         public HelpCtx getHelpCtx() {
>>>>>>>>>>                             return super.getHelpCtx();
>>>>>>>>>>                         }
>>>>>>>>>>
>>>>>>>>>>                         @Override
>>>>>>>>>>                         public String getName() {
>>>>>>>>>>                             return "My New Type";
>>>>>>>>>>                         }
>>>>>>>>>>                     }
>>>>>>>>>>                 };
>>>>>>>>>>     }
>>>>>>>>>>
>>>>>>>>>> But if I right click my node, nothing is displayed in the new
>>>>>>>>>> section,
>>>>>>>>>> only disabled "Empty folder" and "Empty File" menu items. How
>>>>>>>>>> do I have
>>>>>>>>>> to override my getActions method correctly?
>>>>>>>>>>
>>>>>>>>>> Thanks.
>>>>>>>>>>
>>>>>>>>>> Best regards,
>>>>>>>>>> Klaus
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>                
>>>>>>>>> I think you need a NewAction in your getActions. The NewAction
>>>>>>>>> comes
>>>>>>>>> from the Actions API.
>>>>>>>>>
>>>>>>>>> Gj
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>              
>>>>>>>> Hi!
>>>>>>>>
>>>>>>>> Thanks, I tried this
>>>>>>>>
>>>>>>>>  @Override
>>>>>>>>    public Action[] getActions(boolean arg0) {
>>>>>>>>        return new Action[]{SystemAction.get(NewAction.class)};
>>>>>>>>    }
>>>>>>>>
>>>>>>>> This does not work. There is only a disabled and "Add" labeled
>>>>>>>> MenuItem
>>>>>>>> appearing in my popup menu.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Klaus
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>            
>>>>>      
>>>> Hi!
>>>>
>>>> Thanks for help. I don't know why, but it does not work in my case.
>>>> If I
>>>> debuff my code, the getActions method is called properly. I also
>>>> have an
>>>> additional "Add" MenuItem in my popup menu (which is disabled). But my
>>>> added (extended) NewType "Action" (Don't know why this is called
>>>> action)
>>>> neither is part of the submenu "new" nor anything else. I don't see
>>>> any
>>>> menuitem with my label defined in the getName method of NewType.
>>>> Hmmmm.
>>>> Which NetBeans Platform Version do you use?
>>>> Thanks.
>>>>
>>>> Bye,
>>>> Klaus
>>>>
>>>>    
>>
>
Hi!

Yes, of course. I am an idiot. This was exactly the problem. I already
solved it yesterday in the evening. I was going to post it here after
work. Thanks a lot. Now everything works as expected.

Regards,
Klaus

--
DI Dr. Klaus J. Martinschitz
Badhöring Nr. 41/2
4782 St. Florian
Austria
Tel.: 0043 650 2117866
Email.: klausmartinschitz@...