Now, we configured up our environment and have newly created plugin project, we can try to write some code.
Plugin.xml
In this file I write simple info about my plugin - id, name, vendor etc. It's enough for this point. About components, actions and extensions we'll talk a little bit later. So my plugin.xml looks like attached below.
Well, now we can create our first Action. So let's do it!
Create new package, for example "com.test.plugin" and then go to New -> Action. I believe you already know about this class and I don't give deep explanations in here. Just fill the fields and choose WindowMenu(Window) item in Groups area.
Now we have new action and it registered in our plugin.xml (just check it).
As well we should to create the application component (New -> Application Component).
And the last step we should do - it's create the form. Choose New -> GUI Form. Put elements on the main Panel and write to them human friendly names (like shown below).
Now we should to bind our form fields. Write mouse button klick on panel area and select "Data Binding Wizzard..." item. Choose path to our application component class and set the variables to bind.
After finishing this process we'll have the implemented code in our application component class (just check it). Now we have to do some changes in code to run our plugin. So lets do it.
Also you ned to implement the methods from ApplicationComponent, Configurable and JDOMExternalizable interfaces (how to do this you can find in The Basics of Plugin Development.pdf ).
Now we able to run our plugin and see what we've got.
Open the Edit Configurations window, add the Idea Plugin item from the menu and press OK button.
Well done. Now let's run our plugin in debug mode and look what we've got.
Plugin.xml
In this file I write simple info about my plugin - id, name, vendor etc. It's enough for this point. About components, actions and extensions we'll talk a little bit later. So my plugin.xml looks like attached below.
Well, now we can create our first Action. So let's do it!
Create new package, for example "com.test.plugin" and then go to New -> Action. I believe you already know about this class and I don't give deep explanations in here. Just fill the fields and choose WindowMenu(Window) item in Groups area.
As well we should to create the application component (New -> Application Component).
And the last step we should do - it's create the form. Choose New -> GUI Form. Put elements on the main Panel and write to them human friendly names (like shown below).
After finishing this process we'll have the implemented code in our application component class (just check it). Now we have to do some changes in code to run our plugin. So lets do it.
//Method to show entered credentials in 'Messages Dialog'.
public void showCredentials() {
Messages.showMessageDialog(
Constants.USER_LOGIN + loginField + "\n" + Constants.USER_PASSWORD + passwordField,
Constants.USER_CREDENTIALS,
Messages.getInformationIcon()
);
}
Also you ned to implement the methods from ApplicationComponent, Configurable and JDOMExternalizable interfaces (how to do this you can find in The Basics of Plugin Development.pdf ).
Now we able to run our plugin and see what we've got.
Open the Edit Configurations window, add the Idea Plugin item from the menu and press OK button.
Well, now run our project in Debug mode. You should get the new instance of Intellij Idea. Create new project or choose existing. After Idea is loaded go to Idea Preferences and find our plugin by name using search. You should see item shown below. Fill the data into fields and apply changes.
Now we can check this information on dialog. Open Window menu and select our plugin item.
Thats it. You can change info and I believe it will how the changes to you every time.
Another thing I want to talk about ToolTipWindow.
Let's get back to our plugin and create another one Application Component and new one GUI Form. Put three textFields and one button (look on screen below).
Bind it to our Component (set the values as we done in previous steps). An go back to our Form class. In here we need to set the button logic. I've write simple string concat.
//Gets values from 1 and 2 fields and sets the result into 3 field.
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField3.setText(textField1.getText() + " - " + textField2.getText());
}
});
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent(rootPanel, "ONE_TEST", false);
toolWindow.getContentManager().addContent(content);
}
And the last one step we need to do - register this form in plugin.xml file.
Well done. Now let's run our plugin in debug mode and look what we've got.









No comments:
Post a Comment