001: package net.sourceforge.squirrel_sql.plugins.syntax;
002:
003: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
004: import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
005: import net.sourceforge.squirrel_sql.client.gui.session.ToolsPopupAccessor;
006: import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
007: import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
008: import net.sourceforge.squirrel_sql.client.IApplication;
009: import net.sourceforge.squirrel_sql.client.action.ActionCollection;
010: import net.sourceforge.squirrel_sql.plugins.syntax.netbeans.*;
011: import net.sourceforge.squirrel_sql.fw.util.Resources;
012:
013: import javax.swing.*;
014: import java.util.HashMap;
015:
016: import org.netbeans.editor.BaseKit;
017:
018: public class ToolsPopupHandler {
019: private SyntaxPugin _syntaxPugin;
020:
021: ToolsPopupHandler(SyntaxPugin syntaxPugin) {
022: _syntaxPugin = syntaxPugin;
023: }
024:
025: void initToolsPopup(HashMap<String, Object> props,
026: ISQLEntryPanel isqlEntryPanel) {
027: // Note: SessionInternalFrame and SQLinternalFrame should never provide
028: // a ToolsPopupAccessor. Their Tools Popup ist configured in the SyntaxPlugin class
029: // with standard Actions from ActionCollection.
030: ToolsPopupAccessor tpa = (ToolsPopupAccessor) props
031: .get((ToolsPopupAccessor.class.getName()));
032:
033: if (null == tpa) {
034: return;
035: }
036:
037: SyntaxPluginResources rsrc = _syntaxPugin.getResources();
038: IApplication app = _syntaxPugin.getApplication();
039:
040: tpa.addToToolsPopup(SyntaxPugin.i18n.FIND, new FindAction(app,
041: rsrc, isqlEntryPanel));
042: tpa.addToToolsPopup(SyntaxPugin.i18n.REPLACE,
043: new ReplaceAction(app, rsrc, isqlEntryPanel));
044: tpa
045: .addToToolsPopup(SyntaxPugin.i18n.AUTO_CORR,
046: new ConfigureAutoCorrectAction(app, rsrc,
047: _syntaxPugin));
048: tpa.addToToolsPopup(SyntaxPugin.i18n.DUP_LINE,
049: new DuplicateLineAction(app, rsrc, isqlEntryPanel));
050: tpa.addToToolsPopup(SyntaxPugin.i18n.COMMENT,
051: new CommentAction(app, rsrc, isqlEntryPanel));
052: tpa.addToToolsPopup(SyntaxPugin.i18n.UNCOMMENT,
053: new UncommentAction(app, rsrc, isqlEntryPanel));
054:
055: if (isqlEntryPanel.getTextComponent() instanceof NetbeansSQLEditorPane) {
056: NetbeansSQLEditorPane nbEdit = (NetbeansSQLEditorPane) isqlEntryPanel
057: .getTextComponent();
058: Action toUpperAction = ((SQLKit) nbEdit.getEditorKit())
059: .getActionByName(BaseKit.toUpperCaseAction);
060: toUpperAction
061: .putValue(
062: Resources.ACCELERATOR_STRING,
063: SQLSettingsInitializer.ACCELERATOR_STRING_TO_UPPER_CASE);
064: tpa.addToToolsPopup(SyntaxPugin.i18n.TO_UPPER_CASE,
065: toUpperAction);
066:
067: Action toLowerAction = ((SQLKit) nbEdit.getEditorKit())
068: .getActionByName(BaseKit.toLowerCaseAction);
069: toLowerAction
070: .putValue(
071: Resources.ACCELERATOR_STRING,
072: SQLSettingsInitializer.ACCELERATOR_STRING_TO_LOWER_CASE);
073: tpa.addToToolsPopup(SyntaxPugin.i18n.TO_LOWER_CASE,
074: toLowerAction);
075: }
076:
077: }
078:
079: void initToolsPopup(SessionInternalFrame sif, ActionCollection coll) {
080: ISQLEntryPanel sep = sif.getSQLPanelAPI().getSQLEntryPanel();
081: JComponent septc = sep.getTextComponent();
082:
083: sif.addToToolsPopUp(SyntaxPugin.i18n.FIND, coll
084: .get(FindAction.class));
085: sif.addToToolsPopUp(SyntaxPugin.i18n.REPLACE, coll
086: .get(ReplaceAction.class));
087: sif.addToToolsPopUp(SyntaxPugin.i18n.AUTO_CORR, coll
088: .get(ConfigureAutoCorrectAction.class));
089: sif.addToToolsPopUp(SyntaxPugin.i18n.DUP_LINE, coll
090: .get(DuplicateLineAction.class));
091: sif.addToToolsPopUp(SyntaxPugin.i18n.COMMENT, coll
092: .get(CommentAction.class));
093: sif.addToToolsPopUp(SyntaxPugin.i18n.UNCOMMENT, coll
094: .get(UncommentAction.class));
095:
096: if (sep.getTextComponent() instanceof NetbeansSQLEditorPane) {
097: NetbeansSQLEditorPane nbEdit = (NetbeansSQLEditorPane) septc;
098: SQLKit kit = (SQLKit) nbEdit.getEditorKit();
099:
100: Action toUpperAction = kit
101: .getActionByName(BaseKit.toUpperCaseAction);
102: toUpperAction
103: .putValue(
104: Resources.ACCELERATOR_STRING,
105: SQLSettingsInitializer.ACCELERATOR_STRING_TO_UPPER_CASE);
106: sif.addToToolsPopUp(SyntaxPugin.i18n.TO_UPPER_CASE,
107: toUpperAction);
108:
109: Action toLowerAction = kit
110: .getActionByName(BaseKit.toLowerCaseAction);
111: toLowerAction
112: .putValue(
113: Resources.ACCELERATOR_STRING,
114: SQLSettingsInitializer.ACCELERATOR_STRING_TO_LOWER_CASE);
115: sif.addToToolsPopUp(SyntaxPugin.i18n.TO_LOWER_CASE,
116: toLowerAction);
117: }
118:
119: }
120:
121: void initToolsPopup(SQLInternalFrame sqlInternalFrame,
122: ActionCollection coll) {
123: sqlInternalFrame.addToToolsPopUp(SyntaxPugin.i18n.FIND, coll
124: .get(FindAction.class));
125: sqlInternalFrame.addToToolsPopUp(SyntaxPugin.i18n.REPLACE, coll
126: .get(ReplaceAction.class));
127: sqlInternalFrame.addToToolsPopUp(SyntaxPugin.i18n.AUTO_CORR,
128: coll.get(ConfigureAutoCorrectAction.class));
129: sqlInternalFrame.addToToolsPopUp(SyntaxPugin.i18n.DUP_LINE,
130: coll.get(DuplicateLineAction.class));
131: sqlInternalFrame.addToToolsPopUp(SyntaxPugin.i18n.COMMENT, coll
132: .get(CommentAction.class));
133: sqlInternalFrame.addToToolsPopUp(SyntaxPugin.i18n.UNCOMMENT,
134: coll.get(UncommentAction.class));
135:
136: ISQLPanelAPI sqlPanelAPI = sqlInternalFrame.getSQLPanelAPI();
137:
138: if (sqlPanelAPI.getSQLEntryPanel().getTextComponent() instanceof NetbeansSQLEditorPane) {
139: NetbeansSQLEditorPane nbEdit = (NetbeansSQLEditorPane) sqlPanelAPI
140: .getSQLEntryPanel().getTextComponent();
141: Action toUpperAction = ((SQLKit) nbEdit.getEditorKit())
142: .getActionByName(BaseKit.toUpperCaseAction);
143: toUpperAction
144: .putValue(
145: Resources.ACCELERATOR_STRING,
146: SQLSettingsInitializer.ACCELERATOR_STRING_TO_UPPER_CASE);
147: sqlInternalFrame.addToToolsPopUp(
148: SyntaxPugin.i18n.TO_UPPER_CASE, toUpperAction);
149:
150: Action toLowerAction = ((SQLKit) nbEdit.getEditorKit())
151: .getActionByName(BaseKit.toLowerCaseAction);
152: toLowerAction
153: .putValue(
154: Resources.ACCELERATOR_STRING,
155: SQLSettingsInitializer.ACCELERATOR_STRING_TO_LOWER_CASE);
156: sqlInternalFrame.addToToolsPopUp(
157: SyntaxPugin.i18n.TO_LOWER_CASE, toLowerAction);
158: }
159: }
160:
161: }
|