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
Please sign in to leave a comment.
Hello Bas,
e.getData(PlatformDataKeys.PROJECT) is all you need.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
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
Hello Bas,
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!"