001: package net.sourceforge.squirrel_sql.plugins.syntax;
002:
003: import java.util.HashMap;
004:
005: import javax.swing.SwingUtilities;
006:
007: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
008: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanelFactory;
009: import net.sourceforge.squirrel_sql.client.session.ISession;
010: import net.sourceforge.squirrel_sql.client.gui.session.ToolsPopupAccessor;
011: import net.sourceforge.squirrel_sql.client.IApplication;
012: import net.sourceforge.squirrel_sql.fw.util.StringManager;
013: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
014: import net.sourceforge.squirrel_sql.plugins.syntax.netbeans.NetbeansSQLEntryAreaFactory;
015: import net.sourceforge.squirrel_sql.plugins.syntax.netbeans.FindAction;
016: import net.sourceforge.squirrel_sql.plugins.syntax.netbeans.ReplaceAction;
017: import net.sourceforge.squirrel_sql.plugins.syntax.oster.OsterSQLEntryAreaFactory;
018:
019: public class SQLEntryPanelFactoryProxy implements ISQLEntryPanelFactory {
020: private static final StringManager s_stringMgr = StringManagerFactory
021: .getStringManager(SQLEntryPanelFactoryProxy.class);
022:
023: private NetbeansSQLEntryAreaFactory _netbeansFactory;
024: private OsterSQLEntryAreaFactory _osterFactory;
025: private SyntaxPugin _syntaxPugin;
026:
027: /** The original Squirrel SQL CLient factory for creating SQL entry panels. */
028: private ISQLEntryPanelFactory _originalFactory;
029:
030: SQLEntryPanelFactoryProxy(SyntaxPugin syntaxPugin,
031: ISQLEntryPanelFactory originalFactory) {
032: _originalFactory = originalFactory;
033: _netbeansFactory = new NetbeansSQLEntryAreaFactory(syntaxPugin);
034: _osterFactory = new OsterSQLEntryAreaFactory(syntaxPugin);
035: _syntaxPugin = syntaxPugin;
036: }
037:
038: public void sessionEnding(ISession session) {
039: _netbeansFactory.sessionEnding(session);
040: }
041:
042: public ISQLEntryPanel createSQLEntryPanel(final ISession session,
043: HashMap<String, Object> props) {
044: if (session == null) {
045: throw new IllegalArgumentException("Null ISession passed");
046: }
047:
048: SyntaxPreferences prefs = getPreferences(session);
049: ISQLEntryPanel pnl = getPanel(session);
050:
051: ISQLEntryPanel newPnl;
052:
053: if (prefs.getUseNetbeansTextControl()) {
054: newPnl = _netbeansFactory.createSQLEntryPanel(session,
055: props);
056: } else if (prefs.getUseOsterTextControl()) {
057: SwingUtilities.invokeLater(new Runnable() {
058: public void run() {
059: session.showMessage(
060: // i18n[syntax.osterWarning=You are using the Oster editor. Please consider using the Netbeans editor. See menu File --> New Session Properties --> Syntax]
061: s_stringMgr
062: .getString("syntax.osterWarning"));
063: }
064: });
065:
066: newPnl = _osterFactory.createSQLEntryPanel(session);
067: } else {
068: newPnl = _originalFactory.createSQLEntryPanel(session,
069: props);
070: }
071:
072: new ToolsPopupHandler(_syntaxPugin).initToolsPopup(props,
073: newPnl);
074:
075: new AutoCorrector(newPnl.getTextComponent(), _syntaxPugin);
076:
077: if (null == pnl
078: || false == newPnl.getClass().equals(pnl.getClass())) {
079: removePanel(session);
080: savePanel(session, newPnl);
081: }
082:
083: return newPnl;
084: }
085:
086: private SyntaxPreferences getPreferences(ISession session) {
087: return (SyntaxPreferences) session.getPluginObject(
088: _syntaxPugin, IConstants.ISessionKeys.PREFS);
089: }
090:
091: private void removePanel(ISession session) {
092: session.removePluginObject(_syntaxPugin,
093: IConstants.ISessionKeys.SQL_ENTRY_CONTROL);
094: }
095:
096: private ISQLEntryPanel getPanel(ISession session) {
097: return (ISQLEntryPanel) session.getPluginObject(_syntaxPugin,
098: IConstants.ISessionKeys.SQL_ENTRY_CONTROL);
099: }
100:
101: private void savePanel(ISession session, ISQLEntryPanel pnl) {
102: session.putPluginObject(_syntaxPugin,
103: IConstants.ISessionKeys.SQL_ENTRY_CONTROL, pnl);
104: }
105:
106: }
|