01: package net.sourceforge.squirrel_sql.plugins.hibernate;
02:
03: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
04: import net.sourceforge.squirrel_sql.client.session.ISession;
05: import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcherFactory;
06: import net.sourceforge.squirrel_sql.client.session.action.UndoAction;
07: import net.sourceforge.squirrel_sql.client.session.action.RedoAction;
08: import net.sourceforge.squirrel_sql.client.session.mainpanel.SquirrelDefaultUndoManager;
09: import net.sourceforge.squirrel_sql.client.session.parser.IParserEventsProcessorFactory;
10: import net.sourceforge.squirrel_sql.client.IApplication;
11: import net.sourceforge.squirrel_sql.client.gui.session.ToolsPopupAccessor;
12: import net.sourceforge.squirrel_sql.fw.util.Resources;
13:
14: import javax.swing.*;
15: import java.util.HashMap;
16:
17: public class EntryPanelManagerBase {
18: private ISession _session;
19: private ISQLEntryPanel _entry;
20: private JComponent _component;
21:
22: public EntryPanelManagerBase(ISession session) {
23: _session = session;
24: }
25:
26: public void init(
27: ISyntaxHighlightTokenMatcherFactory syntaxHighlightTokenMatcherFactory,
28: ToolsPopupAccessor tpa) {
29: HashMap props = new HashMap();
30: props.put(IParserEventsProcessorFactory.class.getName(), null);
31:
32: if (null != syntaxHighlightTokenMatcherFactory) {
33: props.put(ISyntaxHighlightTokenMatcherFactory.class
34: .getName(), syntaxHighlightTokenMatcherFactory);
35: }
36:
37: if (null != tpa) {
38: props.put(ToolsPopupAccessor.class.getName(), tpa);
39: }
40:
41: _entry = _session.getApplication().getSQLEntryPanelFactory()
42: .createSQLEntryPanel(_session, props);
43:
44: _component = _entry.getTextComponent();
45: if (false == _entry.getDoesTextComponentHaveScroller()) {
46: _component = new JScrollPane(_entry.getTextComponent());
47: _component.setBorder(BorderFactory.createEmptyBorder());
48: }
49:
50: if (!_entry.hasOwnUndoableManager()) {
51: SquirrelDefaultUndoManager undoManager = new SquirrelDefaultUndoManager();
52: IApplication app = _session.getApplication();
53: Resources res = app.getResources();
54: UndoAction undoAction = new UndoAction(app, undoManager);
55: RedoAction redoAction = new RedoAction(app, undoManager);
56:
57: JComponent comp = _entry.getTextComponent();
58: comp.registerKeyboardAction(undoAction, res
59: .getKeyStroke(undoAction),
60: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
61: comp.registerKeyboardAction(redoAction, res
62: .getKeyStroke(redoAction),
63: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
64: _entry.setUndoActions(undoAction, redoAction);
65:
66: _entry.setUndoManager(undoManager);
67: }
68: }
69:
70: public JComponent getComponent() {
71: checkInit();
72: return _component;
73: }
74:
75: private void checkInit() {
76: if (null == _component) {
77: throw new IllegalStateException(
78: "Call init() before using this object");
79: }
80: }
81:
82: public ISQLEntryPanel getEntryPanel() {
83: checkInit();
84: return _entry;
85: }
86:
87: public void requestFocus() {
88: checkInit();
89: _entry.requestFocus();
90: }
91:
92: protected ISession getSession() {
93: return _session;
94: }
95:
96: }
|