Pretty easy. If you have the FileObject (that cna be acquired by the
DataObject if needed), Then get use the:
http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-projectapi/org/netbeans/api/project/FileOwnerQuery.html#getOwner-org.openide.filesystems.FileObject-
On 11/28/20 3:13 PM, Orlyanskiy Vladimir wrote:
Do you mean replace DataObject to Project as I have done in new
example? In this case my action is disabled in context menu. I have
added picture with example.
I need to know DataObject/File and Project in one time.
If I will know Project how can I find what DataObject/File has been
selected for action?
packageorg*.*vorlyanskiy*.*netbeans*.*groovy*;*
*import*java*.*awt*.*event*.*ActionEvent*;*
*import*java*.*awt*.*event*.*ActionListener*;*
*import*java*.*util*.*Collection*;*
*import*org*.*netbeans*.*api*.*project*.*Project*;*
*import*org*.*openide*.*awt*.*ActionID*;*
*import*org*.*openide*.*awt*.*ActionReference*;*
*import*org*.*openide*.*awt*.*ActionReferences*;*
*import*org*.*openide*.*awt*.*ActionRegistration*;*
*import*org*.*openide*.*loaders*.*DataObject*;*
*import*org*.*openide*.*util*.*Lookup*;*
*import*org*.*openide*.*util*.*NbBundle*.*Messages*;*
*import*org*.*openide*.*util*.*Utilities*;*
@ActionID*(*
category *=*"Build"*,*
id *=*"org.vorlyanskiy.netbeans.groovy.SomeAction"
*)*
@ActionRegistration*(*
displayName *=*"#CTL_SomeAction"
*)*
@ActionReferences*({*
@ActionReference*(*path
*=*"Loaders/text/x-groovy/Actions"*,*position *=*566*),*
*})*
@Messages*(*"CTL_SomeAction=My Action"*)*
publicfinalclassSomeAction *implements*ActionListener *{*
privatefinalProject context*;*
publicSomeAction*(*Project context*)**{*
*this**.*context *=*context*;*
*}*
@Override
publicvoidactionPerformed*(*ActionEvent ev*)**{*
Project project
*=*Utilities*.*actionsGlobalContext*().*lookup*(*Project*.*class*);*
Project project2
*=*context*.*getLookup*().*lookup*(*Project*.*class*);*
*}*
*}*
*From:* Geertjan Wielenga <geertjan.wiele...@googlemail.com.INVALID>
*Sent:* Sunday, November 29, 2020 1:41 AM
*To:* Orlyanskiy Vladimir <en...@mail.ru.invalid>
*Cc:* users@netbeans.apache.org
*Subject:* Re: How to get Project from custom action ?
Replace DataObject with Project.
Gj
On Sat, 28 Nov 2020 at 23:38, Orlyanskiy Vladimir
<en...@mail.ru.invalid <mailto:en...@mail.ru.invalid>> wrote:
Hello.
I try to create module with new action for existing file type.
I have created action with code that I have put below.
I have problem with loading Project in method actionPerformed.
Project is null in both cases.
How to load current Project from action ?
@ActionID*(*
category *=*"Build"*,*
id *=*"org.xxx.netbeans.groovy.SomeAction"
*)*
@ActionRegistration*(*
displayName *=*"#CTL_SomeAction"
*)*
@ActionReferences*({*
@ActionReference*(*path
*=*"Loaders/text/x-groovy/Actions"*,*position *=*566*),*
*})*
@Messages*(*"CTL_SomeAction=My Action"*)*
publicfinalclassSomeAction *implements*ActionListener *{*
privatefinalDataObject context*;*
publicSomeAction*(*DataObject context*)**{*
*this**.*context *=*context*;*
*}*
@Override
publicvoidactionPerformed*(*ActionEvent ev*)**{*
Project project
*=*Utilities*.*actionsGlobalContext*().*lookup*(*Project*.*class*);*
Project project2
*=*context*.*getLookup*().*lookup*(*Project*.*class*);*
*}*
*}*