001: package net.sourceforge.squirrel_sql.plugins.hibernate;
002:
003: import net.sourceforge.squirrel_sql.client.session.ISession;
004: import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcherFactory;
005: import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcher;
006: import net.sourceforge.squirrel_sql.client.gui.session.ToolsPopupController;
007: import net.sourceforge.squirrel_sql.fw.util.StringManager;
008: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
009: import net.sourceforge.squirrel_sql.plugins.hibernate.completion.HQLCompleteCodeAction;
010:
011: import javax.swing.*;
012: import java.awt.event.ActionEvent;
013:
014: public class HQLEntryPanelManager extends EntryPanelManagerBase {
015:
016: private static final StringManager s_stringMgr = StringManagerFactory
017: .getStringManager(HQLEntryPanelManager.class);
018:
019: private HqlSyntaxHighlightTokenMatcherProxy _hqlSyntaxHighlightTokenMatcherProxy = new HqlSyntaxHighlightTokenMatcherProxy();
020: private HibernatePluginResources _resources;
021: private IHibernateConnectionProvider _connectionProvider;
022: private ToolsPopupController _toolsPopupController;
023:
024: public HQLEntryPanelManager(ISession session,
025: HibernatePluginResources resources,
026: IHibernateConnectionProvider connectionProvider) {
027: super (session);
028: _connectionProvider = connectionProvider;
029:
030: ToolsPopupAccessorProxy tpap = new ToolsPopupAccessorProxy();
031:
032: init(createSyntaxHighlightTokenMatcherFactory(), tpap);
033:
034: _resources = resources;
035:
036: initToolsPopUp();
037: tpap.apply(this );
038: initCodeCompletion();
039: initBookmarks();
040:
041: // i18n[HQLEntryPanelManager.quoteHQL=Quote HQL]
042: String strQuote = s_stringMgr
043: .getString("HQLEntryPanelManager.quoteHQL");
044: AbstractAction quoteHql = new AbstractAction(strQuote) {
045: public void actionPerformed(ActionEvent e) {
046: onQuoteHQL();
047: }
048: };
049: quoteHql.putValue(Action.SHORT_DESCRIPTION, strQuote);
050: addToSQLEntryAreaMenu(quoteHql, "quote");
051:
052: // i18n[HQLEntryPanelManager.quoteHQLsb=Quote HQL as StingBuffer]
053: String strQuoteSb = s_stringMgr
054: .getString("HQLEntryPanelManager.quoteHQLsb");
055: AbstractAction quoteSbHql = new AbstractAction(strQuoteSb) {
056: public void actionPerformed(ActionEvent e) {
057: onQuoteHQLSb();
058: }
059: };
060: quoteSbHql.putValue(Action.SHORT_DESCRIPTION, strQuoteSb);
061: addToSQLEntryAreaMenu(quoteSbHql, "quotesb");
062:
063: // i18n[HQLEntryPanelManager.unquoteHQL=Unquote HQL]
064: String strUnquote = s_stringMgr
065: .getString("HQLEntryPanelManager.unquoteHQL");
066: AbstractAction unquoteHql = new AbstractAction(strUnquote) {
067: public void actionPerformed(ActionEvent e) {
068: onUnquoteHQL();
069: }
070: };
071: unquoteHql.putValue(Action.SHORT_DESCRIPTION, strUnquote);
072: addToSQLEntryAreaMenu(unquoteHql, "unquote");
073: }
074:
075: private void initBookmarks() {
076: HQLBookmarksAction hba = new HQLBookmarksAction(getSession()
077: .getApplication(), _resources, getEntryPanel());
078: JMenuItem item = addToSQLEntryAreaMenu(hba, "bookmarkselect");
079: _resources.configureMenuItem(hba, item);
080: registerKeyboardAction(hba, _resources.getKeyStroke(hba));
081: }
082:
083: private void initToolsPopUp() {
084: _toolsPopupController = new ToolsPopupController(getSession(),
085: getEntryPanel());
086: HQLToolsPopUpAction htp = new HQLToolsPopUpAction(_resources,
087: _toolsPopupController, getSession().getApplication());
088: JMenuItem item = addToSQLEntryAreaMenu(htp, null);
089: _resources.configureMenuItem(htp, item);
090: registerKeyboardAction(htp, _resources.getKeyStroke(htp));
091: }
092:
093: private void initCodeCompletion() {
094: HQLCompleteCodeAction hcca = new HQLCompleteCodeAction(
095: getSession().getApplication(), _resources, this ,
096: _connectionProvider,
097: _hqlSyntaxHighlightTokenMatcherProxy);
098: JMenuItem item = addToSQLEntryAreaMenu(hcca, "complete");
099: _resources.configureMenuItem(hcca, item);
100: registerKeyboardAction(hcca, _resources.getKeyStroke(hcca));
101: }
102:
103: private ISyntaxHighlightTokenMatcherFactory createSyntaxHighlightTokenMatcherFactory() {
104: return new ISyntaxHighlightTokenMatcherFactory() {
105: public ISyntaxHighlightTokenMatcher getSyntaxHighlightTokenMatcher(
106: ISession sess, JEditorPane editorPane) {
107: _hqlSyntaxHighlightTokenMatcherProxy
108: .setEditorPane(editorPane);
109: return _hqlSyntaxHighlightTokenMatcherProxy;
110: }
111: };
112:
113: }
114:
115: private void onUnquoteHQL() {
116: EditExtrasAccessor.unquoteHQL(getEntryPanel(), getSession());
117: }
118:
119: private void onQuoteHQLSb() {
120: EditExtrasAccessor.quoteHQLSb(getEntryPanel(), getSession());
121: }
122:
123: private void onQuoteHQL() {
124: EditExtrasAccessor.quoteHQL(getEntryPanel(), getSession());
125: }
126:
127: public JMenuItem addToSQLEntryAreaMenu(Action action,
128: String toolsPopupSelectionString) {
129: if (null != toolsPopupSelectionString) {
130: _toolsPopupController.addAction(toolsPopupSelectionString,
131: action);
132: }
133:
134: return getEntryPanel().addToSQLEntryAreaMenu(action);
135: }
136:
137: public void registerKeyboardAction(Action action,
138: KeyStroke keyStroke) {
139: JComponent comp = getEntryPanel().getTextComponent();
140: comp.registerKeyboardAction(action, keyStroke,
141: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
142: }
143: }
|