DataKey - howto ?
I was looking at writing an IntelliJ plugin. Downloaded the devkit, watched the flash tutorial, keyed it into 7.0M2, and it showed DataConstants as deprecated.
Editor editor = (Editor)event.getDataContext().getData( DataConstants.EDITOR );
The OpenAPI JavaDoc says to use DataKey instead. I would assume I need to make a series of calls like:
DataKey myDataKey = ???;
Editor editor = myDataKey.getData( event.getDataContext() );
Now DataKey has a static method that returns a DataKey, but it needs a String name parameter, and what is that supposed to be?
String editorDataKeyName = ???;
DataKey my DataKey = DataKey]]>.create( editorDataKeyName );
Is it supposed to be the FQN? Editor.class.getName() or "com.intellij.openapi.editor.Editor". If that were the case, then why not have the create method take the class object:, ie Editor.class, as a parameter?
A small code example in the JavaDoc would be extremely helpful. Thank you.
Please sign in to leave a comment.
DataKeys.EDITOR.getData(e.getDataContext())
Frederick N. Brier wrote:
--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"
Hello Frederick,
e.getData(DataKeys.EDITOR);
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Thank you both for the replies. Both solutions work, and that is wonderful. However, if I might ask, why, if DataKeys.Editor is an object of DataKeys, does DataKeys]]>.getData( context ) return type Object instead of type Editor? I am assuming that is why you chose to switch to templates. Thank you.
Fred
Hello Frederick,
Well, it does return Editor.
public class DataKey]]> {
public T getData() { ... }
}
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Perhaps the reason for the IntelliJ error message is something else. If I have the line:
Editor editor = DataKeys.EDITOR.getData( event.getDataContext() );
The line is marked in error and the popup says: "Incompatible types:" "Required: com.intellij.openapi.editor.Editor" "Found: java.lang.Object". There is an import statement:
import com.intellij.openapi.editor.Editor;
If I click on the little light bulb helper and accept the cast, the statement is changed to:
Editor editor = (Editor)DataKeys.EDITOR.getData( event.getDataContext() );
Normally (Editor) would be shown in a light gray with a warning that it was an unncessary cast, but the Intellij (7.0M2) is perfectly happy. That is why I was confused. Any thoughts? When I am typing DataKeys.Editor and then type a period (.) the popup list of methods has getData() returning Object. Does that help? Thank you.
Please check your language level. I'm pretty sure it is on 1.3 or 1.4. After changing it to 5.0 everything should be ok.
Oh, that's embarrassing. I could have sworn I had it set correctly ]]>. Thank you.