01: package org.dbbrowser.ui.panel.dbbrowserwindow;
02:
03: import org.dbbrowser.ui.UIControllerForQueries;
04: import org.dbbrowser.ui.widget.ProgressDialog;
05:
06: import javax.swing.*;
07: import javax.swing.event.ChangeListener;
08: import java.awt.event.ActionListener;
09: import java.util.Map;
10: import java.util.HashMap;
11:
12: /**
13: * Singleton class which manages building of code help. It is a singleton, so code help is built only once for a database
14: */
15: public class CodeHelpManager {
16: private static CodeHelpManager codeHelpManager = new CodeHelpManager();
17: private Map mapOfDatabaseNameToJPopupMenu = new HashMap();
18: private CodeHelpBuilder builder = null;
19:
20: private CodeHelpManager() {
21: }
22:
23: /**
24: * Returns the singleton CodeHelpManager
25: * @return
26: */
27: public static CodeHelpManager getInstance() {
28: return codeHelpManager;
29: }
30:
31: public Boolean hasPopupMenuBeenbuild(String schemaName) {
32: Object cachedPopupMenu = mapOfDatabaseNameToJPopupMenu
33: .get(schemaName);
34: boolean hasPopupMenuBeenBuild = false;
35:
36: if (cachedPopupMenu != null) {
37: hasPopupMenuBeenBuild = true;
38: }
39: return new Boolean(hasPopupMenuBeenBuild);
40: }
41:
42: /**
43: * Returns the popup menu for a database. Caches the pop up menu so it is built only once
44: * @param popup menu
45: * @return
46: */
47: public JPopupMenu getPopupMenu(UIControllerForQueries uicontroller,
48: ActionListener l, ProgressDialog progressDialog,
49: ChangeListener al) {
50: //if the popup menu has already been built, return the cached version
51: JPopupMenu pm = null;
52: Object cachedPopupMenuObject = mapOfDatabaseNameToJPopupMenu
53: .get(uicontroller.getConnectionInfo().getName());
54: if (cachedPopupMenuObject == null) {
55: //build the menu
56: //Start the code help builder
57: builder = new CodeHelpBuilder(uicontroller, l,
58: progressDialog, al);
59: builder.start();
60:
61: pm = builder.getJPopupMenu();
62: mapOfDatabaseNameToJPopupMenu.put(uicontroller
63: .getConnectionInfo().getName(), pm);
64: } else {
65: //return the cached popup menu
66: pm = (JPopupMenu) cachedPopupMenuObject;
67: }
68:
69: return pm;
70: }
71:
72: /**
73: * Returns the cached popup menu
74: * @param schemaName
75: * @return
76: */
77: public JPopupMenu getPopupMenu(String schemaName) {
78: JPopupMenu popupMenu = builder.getJPopupMenu();
79: mapOfDatabaseNameToJPopupMenu.put(schemaName, popupMenu);
80:
81: return popupMenu;
82: }
83: }
|