001: package net.sourceforge.squirrel_sql.plugins.syntax.netbeans;
002:
003: /*
004: * Copyright (C) 2004 Gerd Wagner
005: * colbell@users.sourceforge.net
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021: import java.util.HashMap;
022:
023: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
024: import net.sourceforge.squirrel_sql.client.session.ISession;
025: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
026: import net.sourceforge.squirrel_sql.plugins.syntax.IConstants;
027: import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxPreferences;
028: import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxPugin;
029:
030: import org.netbeans.editor.DialogSupport;
031: import org.netbeans.editor.ImplementationProvider;
032: import org.netbeans.modules.editor.NbImplementationProvider;
033:
034: /**
035: * Factory for creating Netbeans SQL entry area objects.
036: *
037: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
038: */
039: public class NetbeansSQLEntryAreaFactory {
040: private SyntaxPugin _plugin;
041: private SyntaxFactory _syntaxFactory;
042:
043: /**
044: * This stores the panels that have been allocated so that they can be
045: * told when sessions are ending. Internally they store references that need
046: * to be nulled to allow for garbage-collection.
047: */
048: private HashMap<IIdentifier, NetbeansSQLEntryPanel> _panels = new HashMap<IIdentifier, NetbeansSQLEntryPanel>();
049:
050: public NetbeansSQLEntryAreaFactory(SyntaxPugin plugin) {
051: if (plugin == null) {
052: throw new IllegalArgumentException(
053: "Null NetbeansPlugin passed");
054: }
055:
056: _plugin = plugin;
057: _syntaxFactory = new SyntaxFactory();
058:
059: //DialogSupport.setDialogFactory(new NbDialogSupport());
060: DialogSupport.setDialogFactory(new SquirrelNBDialogFactory(
061: _plugin));
062: ImplementationProvider
063: .registerDefault(new NbImplementationProvider());
064: }
065:
066: /**
067: * @see net.sourceforge.squirrel_sql.client.session.ISQLEntryPanelFactory#createSQLEntryPanel()
068: */
069: public ISQLEntryPanel createSQLEntryPanel(ISession session,
070: HashMap<String, Object> props)
071: throws IllegalArgumentException {
072: if (session == null) {
073: throw new IllegalArgumentException("Null ISession passed");
074: }
075:
076: SyntaxPreferences prefs = getPreferences(session);
077: NetbeansSQLEntryPanel panel = new NetbeansSQLEntryPanel(
078: session, prefs, _syntaxFactory, _plugin, props);
079: _panels.put(session.getIdentifier(), panel);
080: return panel;
081: }
082:
083: private SyntaxPreferences getPreferences(ISession session) {
084: return (SyntaxPreferences) session.getPluginObject(_plugin,
085: IConstants.ISessionKeys.PREFS);
086: }
087:
088: /**
089: * Removes the references to sessions when they are ending so that they can
090: * be garbage-collected.
091: *
092: * @param sess the session that is ending.
093: */
094: public void sessionEnding(final ISession sess) {
095: _syntaxFactory.sessionEnding(sess);
096: final IIdentifier id = sess.getIdentifier();
097: if (id != null && _panels.containsKey(id)) {
098: NetbeansSQLEntryPanel panel = _panels.get(id);
099: if (panel != null) {
100: panel.sessionEnding();
101: }
102: _panels.remove(id);
103: }
104: }
105: }
|