1   package com.atlassian.plugins.codegen.modules.common.keyboard;
2   
3   import com.atlassian.plugins.codegen.modules.BasicNameModuleProperties;
4   import com.google.common.collect.ImmutableList;
5   import com.google.common.collect.Iterables;
6   import com.google.common.collect.Lists;
7   
8   import java.util.Collections;
9   import java.util.List;
10  
11  /**
12   * @since 3.6
13   */
14  public abstract class AbstractKeyboardShortcutProperties extends BasicNameModuleProperties
15  {
16  
17      public static final String HIDDEN = "HIDDEN";
18      public static final String ORDER = "ORDER";
19      public static final String SHORTCUT = "SHORTCUT";
20      public static final String OPERATION_TYPE = "OPERATION_TYPE";
21      public static final String OPERATION_VALUE = "OPERATION_VALUE";
22      public static final String CONTEXT = "CONTEXT";
23  
24      public static final List<String> OPERATIONS = Lists.newArrayList("click", "evaluate", "execute", "followLink",
25              "goTo", "moveToAndClick", "moveToAndFocus", "moveToNextItem", "moveToPrevItem");
26  
27      private static final List<String> XPRODUCT_CONTEXTS = Lists.newArrayList("global");
28  
29      private final List<String> allowedContexts;
30  
31      public AbstractKeyboardShortcutProperties()
32      {
33          this("My Keyboard Shortcut");
34      }
35  
36      public AbstractKeyboardShortcutProperties(String moduleName)
37      {
38          super(moduleName);
39          setHidden(false);
40          setOrder(10);
41          setContext("global");
42          allowedContexts = ImmutableList.copyOf(Iterables.concat(XPRODUCT_CONTEXTS, getAdditionalContexts()));
43      }
44  
45      public List<String> getAllowedContexts()
46      {
47          return allowedContexts;
48      }
49  
50      public void setHidden(boolean hidden)
51      {
52          setProperty(HIDDEN, Boolean.toString(hidden));
53      }
54  
55      public boolean isHidden()
56      {
57          return Boolean.valueOf(getProperty(HIDDEN));
58      }
59  
60      public void setOrder(int order)
61      {
62          setProperty(ORDER, Integer.toString(order));
63      }
64  
65      public String getOrder()
66      {
67          return getProperty(ORDER);
68      }
69  
70      public int getOrderAsInt()
71      {
72          return Integer.parseInt(getProperty(ORDER));
73      }
74  
75      public void setShortcut(String s)
76      {
77          setProperty(SHORTCUT, s);
78      }
79  
80      public String getShortcut()
81      {
82          return getProperty(SHORTCUT);
83      }
84  
85      public void setContext(String s)
86      {
87          setProperty(CONTEXT, s);
88      }
89  
90      public String getContext()
91      {
92          return getProperty(CONTEXT);
93      }
94  
95      public void setOperationType(String s)
96      {
97          setProperty(OPERATION_TYPE, s);
98      }
99  
100     public String getOperationType()
101     {
102         return getProperty(OPERATION_TYPE);
103     }
104 
105     public void setOperationValue(String s)
106     {
107         setProperty(OPERATION_VALUE, s);
108     }
109 
110     public String getOperationValue()
111     {
112         return getProperty(OPERATION_VALUE);
113     }
114 
115     /**
116      * @return additional contexts allowed by the specific product the plugin is targeting
117      */
118     protected List<String> getAdditionalContexts()
119     {
120         return Collections.emptyList();
121     }
122 }