Retrieving a Project object from inside an actionPerformed()

What is the recommended way of retrieving a Project object from a actionPerformed method. In this case I have a Action implementation which is created from the createOptionsPanel() method of an inspection. Currently my code looks like this, but I wonder, is there is a better way?

public void actionPerformed(ActionEvent e) {
        final DataManager dataManager = DataManager.getInstance();
        final DataContext dataContext = dataManager.getDataContext();
        final Project project = DataKeys.PROJECT.getData(dataContext);
        final TreeClassChooserFactory chooserFactory =
                TreeClassChooserFactory.getInstance(project);
}


Any suggestions are welcome.

Bas

3 comments

Hello Bas,

e.getData(PlatformDataKeys.PROJECT) is all you need.

What is the recommended way of retrieving a Project object from a
actionPerformed method. In this case I have a Action implementation
which is created from the createOptionsPanel() method of an
inspection. Currently my code looks like this, but I wonder, is there
is a better way?

 actionPerformed(ActionEvent e) {
> final DataManager dataManager = DataManager.getInstance();
> final DataContext dataContext = dataManager.getDataContext();
> final Project project = DataKeys.PROJECT.getData(dataContext);
> final TreeClassChooserFactory chooserFactory =
> TreeClassChooserFactory.getInstance(project);
> }]]>

Any suggestions are welcome.

Bas


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Perhaps I was not clear, but this was a javax.swing.Action implementation. java.awt.event.ActionEvent does not have a getData() method, does it?

Bas

0

Hello Bas,

Perhaps I was not clear, but this was a javax.swing.Action
implementation. java.awt.event.ActionEvent does not have a getData()
method, does it?


Ah, sorry, wasn't paying attention. :) I think with Swing actions you do
have to use DataManager.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.