+ /**
+ * Method for initialising cache items for a given cache key and populating
+ * the in-memory cache with persisted cache items
+ *
+ * @param cacheKey
+ */
+ private void initCache(String cacheKey)
+ {
+ // obtain persisted cache items from properties file as a delimited string
+ String delimitedCacheStr = Cache.getProperty(cacheKey);
+ if (delimitedCacheStr == null || delimitedCacheStr.isEmpty())
+ {
+ return;
+ }
+ // convert delimited cache items to a list of strings
+ List<String> persistedCacheItems = Arrays
+ .asList(delimitedCacheStr.split(AppCache.CACHE_DELIMITER));
+
+ LinkedHashSet<String> foundCacheItems = appCache
+ .getAllCachedItemsFor(cacheKey);
+ if (foundCacheItems == null)
+ {
+ foundCacheItems = new LinkedHashSet<String>();
+ }
+ // populate memory cache
+ for (String cacheItem : persistedCacheItems)
+ {
+ foundCacheItems.add(cacheItem);
+ }
+ appCache.putCache(cacheKey, foundCacheItems);
+ }
+
+ /**
+ * Initialise this cache's pop-up menu
+ */
+ private void initCachePopupMenu()
+ {
+ pnlDefaultCache.setBackground(Color.WHITE);
+ // pad panel so as to align with other menu items
+ pnlDefaultCache.setBorder(
+ BorderFactory.createEmptyBorder(0, LEFT_BOARDER_WIDTH, 0, 0));
+ txtDefaultCacheSize.setPreferredSize(new Dimension(45, 20));
+ txtDefaultCacheSize.setFont(new java.awt.Font("Verdana", 0, 12));
+ lblDefaultCacheSize
+ .setText(MessageManager.getString("label.default_cache_size"));
+ lblDefaultCacheSize.setFont(new java.awt.Font("Verdana", 0, 12));
+ // Force input to accept only Integer entries up to length - INPUT_LIMIT
+ txtDefaultCacheSize.setDocument(new PlainDocument()
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void insertString(int offs, String str, AttributeSet a)
+ throws BadLocationException
+ {
+ if (getLength() + str.length() <= INPUT_LIMIT && isInteger(str))
+ {
+ super.insertString(offs, str, a);
+ }
+ }
+ });
+ txtDefaultCacheSize.addKeyListener(new java.awt.event.KeyAdapter()
+ {
+ @Override
+ public void keyPressed(KeyEvent e)
+ {
+ if (e.getKeyCode() == KeyEvent.VK_ENTER)
+ {
+ e.consume();
+ updateCache();
+ closePopup();
+ }
+ }
+ });
+
+ txtDefaultCacheSize.setText(appCache.getCacheLimit(cacheKey));
+ pnlDefaultCache.add(lblDefaultCacheSize);
+ menuItemClearCache.setFont(new java.awt.Font("Verdana", 0, 12));
+ pnlDefaultCache.add(txtDefaultCacheSize);
+ menuItemClearCache
+ .setText(MessageManager.getString("action.clear_cached_items"));
+ menuItemClearCache.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ // System.out.println(">>>>> Clear cache items");
+ setSelectedItem("");
+ appCache.deleteCacheItems(cacheKey);
+ updateCache();
+ }
+ });
+
+ popup.insert(pnlDefaultCache, 0);
+ popup.add(menuItemClearCache);
+ setComponentPopupMenu(popup);
+ add(popup);
+ }
+
+ private void closePopup()
+ {
+ popup.setVisible(false);
+ popup.transferFocus();
+ }