com.atlassian.jira.plugin.keyboardshortcut
Class CachingKeyboardShortcutManager

java.lang.Object
  extended by com.atlassian.jira.plugin.keyboardshortcut.CachingKeyboardShortcutManager
All Implemented Interfaces:
Startable, KeyboardShortcutManager

public class CachingKeyboardShortcutManager
extends Object
implements KeyboardShortcutManager, Startable


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.jira.plugin.keyboardshortcut.KeyboardShortcutManager
KeyboardShortcutManager.Context, KeyboardShortcutManager.Operation
 
Constructor Summary
CachingKeyboardShortcutManager(BuildUtilsInfo buildUtilsInfo, com.atlassian.event.api.EventPublisher eventPublisher, com.atlassian.plugin.PluginAccessor pluginAccessor, com.atlassian.plugin.webresource.WebResourceIntegration webResourceIntegration, JiraAuthenticationContext authenticationContext, UserPreferencesManager userPreferencesManager)
           
 
Method Summary
 List<KeyboardShortcut> getAllShortcuts()
          Returns an ordered list of all KeyboardShortcuts available using the plugin descriptor's 'order' attribute for sorting.
 String includeShortcuts()
          Returns a URL to be used to include the currently registered keyboard shortcuts in a page.
 boolean isKeyboardShortcutsEnabled()
          Returns if the user has keyboard shortcuts enabled.
 void onClearCache(ClearCacheEvent event)
           
 void registerShortcut(String pluginModuleKey, KeyboardShortcut shortcut)
          Given a complete plugin module key, this method registers a keyboard shortcut with the manager, which will make it available in the UI to end-users.
 void requireShortcutsForContext(KeyboardShortcutManager.Context context)
          Register that the keyboard shortcuts for the context should be included by KeyboardShortcutManager.includeShortcuts() (in addition to the global shortcuts, which are always included).
 void start()
          This method wil be called after the plugin system is fully initialised and all components added to the dependency injection framework.
 void unregisterShortcut(String pluginModuleKey)
          Removes a keyboard shortcut by its complete plugin module key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingKeyboardShortcutManager

public CachingKeyboardShortcutManager(BuildUtilsInfo buildUtilsInfo,
                                      com.atlassian.event.api.EventPublisher eventPublisher,
                                      com.atlassian.plugin.PluginAccessor pluginAccessor,
                                      com.atlassian.plugin.webresource.WebResourceIntegration webResourceIntegration,
                                      JiraAuthenticationContext authenticationContext,
                                      UserPreferencesManager userPreferencesManager)
Method Detail

start

public void start()
           throws Exception
Description copied from interface: Startable
This method wil be called after the plugin system is fully initialised and all components added to the dependency injection framework.

Specified by:
start in interface Startable
Throws:
Exception - Allows implementations to throw an Exception.

onClearCache

@EventListener
public void onClearCache(ClearCacheEvent event)

registerShortcut

public void registerShortcut(String pluginModuleKey,
                             KeyboardShortcut shortcut)
Description copied from interface: KeyboardShortcutManager
Given a complete plugin module key, this method registers a keyboard shortcut with the manager, which will make it available in the UI to end-users.

Specified by:
registerShortcut in interface KeyboardShortcutManager
Parameters:
pluginModuleKey - the complete plugin module key for this keyboard shortcut
shortcut - the shortcut to register

unregisterShortcut

public void unregisterShortcut(String pluginModuleKey)
Description copied from interface: KeyboardShortcutManager
Removes a keyboard shortcut by its complete plugin module key.

Specified by:
unregisterShortcut in interface KeyboardShortcutManager
Parameters:
pluginModuleKey - the key to remove

getAllShortcuts

public List<KeyboardShortcut> getAllShortcuts()
Description copied from interface: KeyboardShortcutManager
Returns an ordered list of all KeyboardShortcuts available using the plugin descriptor's 'order' attribute for sorting. Implementations should take care to implement this method as quickly as possible since it will be called very often.

Specified by:
getAllShortcuts in interface KeyboardShortcutManager
Returns:
ordered list of all registered keyboard shortcuts

requireShortcutsForContext

public void requireShortcutsForContext(KeyboardShortcutManager.Context context)
Description copied from interface: KeyboardShortcutManager
Register that the keyboard shortcuts for the context should be included by KeyboardShortcutManager.includeShortcuts() (in addition to the global shortcuts, which are always included).

Specified by:
requireShortcutsForContext in interface KeyboardShortcutManager
Parameters:
context - the context whose keyboard shorcuts should be included (in addition to global).

includeShortcuts

public String includeShortcuts()
Description copied from interface: KeyboardShortcutManager
Returns a URL to be used to include the currently registered keyboard shortcuts in a page. The URL should point to the Keyboard Shortcut REST resource. Generally this URL will look something like: /rest/api/1.0/shortcuts/500/f1e3b05a6e6db41e5b77fb8afd7ddde9/shortcuts.js

It has been suggested that webresources (with say the systemcounter) would be a good fit for this, however the problem is that the systemcounter would have to be updated everytime a plugin is enabled/disabled (so everytime JIRA is started up), which would have some adverse side effects:

That's why this uses a md5 checksum of the shortcuts in the URL instead of the web-resources approach.

It does not contain the applications context path. Also, the hash included at the end of the URL should be a hash of all keyboard shortcuts currently available such that the resource can be cached indefinitely. If a new shortcut is registered (or an old shortcut unregistered), then the hash should obviously change.

Specified by:
includeShortcuts in interface KeyboardShortcutManager
Returns:
URL pointing to a REST resource to included keyboard shortcuts. The URL will be correctly URL-escaped, but it is not HTML escaped.
See Also:
KeyboardShortcutManager.requireShortcutsForContext(com.atlassian.jira.plugin.keyboardshortcut.KeyboardShortcutManager.Context)

isKeyboardShortcutsEnabled

public boolean isKeyboardShortcutsEnabled()
Description copied from interface: KeyboardShortcutManager
Returns if the user has keyboard shortcuts enabled. If the user is not logged in this will default to true

Specified by:
isKeyboardShortcutsEnabled in interface KeyboardShortcutManager
Returns:
boolean indicating if the user has keyboard shortcuts enabled. Defaults to true if the user is not logged in.


Copyright © 2002-2012 Atlassian. All Rights Reserved.