plugin.xml
and other basic things - like the links to the relevant documentation - are already described in the above articles, we will not repeat; and I’ll just describe some of the issues I’ve come up with when developing solutions.com.intellij.util.net.HttpConfigurable
class. Its public fields contain all the necessary information: the USE_HTTP_PROXY
flag, for example, says whether we use a proxy at all or not; and there is also information about the host, port and user.prepareURL
method prepareURL
to call it for each connection: /** * Call this function before every HTTP connection. * If system configured to use HTTP proxy, this function * checks all required parameters and ask password if * required. * @param url URL for HTTP connection * @throws IOException */ public void prepareURL (String url) throws IOException {
url
it might look like this: // Ensure that proxy (if any) is set up for this request. final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); httpConfigurable.prepareURL(url.toExternalForm());
ApplicationComponent
will help. The types of components and their creation are remarkably described in the documentation, in the article Plugin Structure .plugin.xml
: <application-components> <component> <implementation-class>com.abelsky.idea.geekandpoke.ComicsPlugin</implementation-class> <interface-class>com.abelsky.idea.geekandpoke.ComicsPlugin</interface-class> </component> </application-components>
initComponent
method: public class ComicsPlugin implements ApplicationComponent { private static final int UPDATE_PERIOD = 15 * 60 * 60 * 1000; // ; // ProjectComponent - . @Override public void initComponent() { startUpdateTimer(); } private void startUpdateTimer() { final Timer timer = new Timer("Geek and Poke updater"); timer.schedule(new TimerTask() { @Override public void run() { // - 15 ... } }, 0, ComicsPlugin.UPDATE_PERIOD); }
package com.abelsky.idea.geekandpoke.messages; // ... public class MessageBundle { private static Reference<ResourceBundle> bundleRef; // com/abelsky/idea/geekandpoke/messages/MessageBundle.properties // - key-value .properties-. @NonNls private static final String BUNDLE = "com.abelsky.idea.geekandpoke.messages.MessageBundle"; private MessageBundle() { } public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Object... params) { return CommonBundle.message(getBundle(), key, params); } private static ResourceBundle getBundle() { ResourceBundle bundle = null; if (MessageBundle.bundleRef != null) { bundle = MessageBundle.bundleRef.get(); } if (bundle == null) { bundle = ResourceBundle.getBundle(BUNDLE); MessageBundle.bundleRef = new SoftReference<ResourceBundle>(bundle); } return bundle; } }
ResourceBundle
in the SoftReference . This is a fairly common practice in the IDEA source code - keep as many objects as possible in non-hard links.com.intellij.reference.SoftReference
class - it is the developers themselves who use it instead of the java.lang.ref
implementation. The difference is that if you suspect a memory leak com.intellij.reference.SoftReference
can be quickly converted into a hard-link, and this will help when profiling.org.jetbrains.annotations.PropertyKey
. It indicates that the annotated method argument can only be a string from the bundle specified in the resourceBundle
parameter. Its use adds confidence that the keys in the .properties file and in the code are not synchronized (and the IDEA refactoring in the IDEA also learns a lot, as the link between the key and the bandl appears).org.jetbrains.annotations.NonNls
/ org.jetbrains.annotations.Nls
, marking lines that should not (or, conversely, should) be translated. Use JetBrains documentation here .com.intellij.notification.Notifications
class. For example: private void notifyNewEntry() { final Notification newEntryNotification = new Notification( /* */ MessageBundle.message("notification.new.strip.group"), /* */ MessageBundle.message("notification.new.strip.title"), /* */ MessageBundle.message("notification.new.strip.content"), NotificationType.INFORMATION); // UI- - invokeLater. Notifications.Bus.notify(newEntryNotification); }
plugin.xml
: <extensions defaultExtensionNs="com.intellij"> <!-- ... --> <applicationConfigurable instance="com.abelsky.idea.geekandpoke.ui.SettingsPanel"/> </extensions>
com.intellij.openapi.options.Configurable
. Of these, the most important - createComponent
- should return the component on which our settings are displayed.%TMP%
. You can, for example, write them somewhere in %USERPROFILE%
, or you can make it more interesting by using the directory in which the plug-in itself is installed.%USERPROFILE%/.IdeaIC11/config/plugins/PLUGIN_NAME
; This way, however, can be changed by setting the variable idea.plugins.path
in idea.properties
. // PLUGIN_ID - id plugin.xml. final PluginId id = PluginId.getId(PLUGIN_ID); final IdeaPluginDescriptor plugin = PluginManager.getPlugin(id); // . File path = plugin.getPath();
Source: https://habr.com/ru/post/150829/
All Articles