001: /*
002: ** $Id: SchemaListController.java,v 1.7 2000/10/26 08:34:16 mrw Exp $
003: **
004: ** Controller for the schema list view.
005: **
006: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
007: **
008: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
009: **
010: ** This program is free software; you can redistribute it and/or modify
011: ** it under the terms of the GNU General Public License as published by
012: ** the Free Software Foundation; either version 2 of the License, or
013: ** (at your option) any later version.
014: **
015: ** This program is distributed in the hope that it will be useful,
016: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
017: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: ** GNU General Public License for more details.
019: **
020: ** You should have received a copy of the GNU Library General
021: ** Public License along with this library; if not, write to the
022: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: ** Boston, MA 02111-1307 USA.
024: */
025:
026: package uk.co.whisperingwind.vienna;
027:
028: import java.sql.Connection;
029: import uk.co.whisperingwind.framework.Controller;
030: import uk.co.whisperingwind.framework.ModelEvent;
031: import uk.co.whisperingwind.framework.ViewEvent;
032:
033: class SchemaListController extends Controller {
034: private static SchemaListController instance = null;
035:
036: private SchemaListView schemaListView = null;
037: private SchemaListModel schemaListModel = null;
038: private Connection connection = null;
039: private ConfigModel configModel = null;
040:
041: public static SchemaListController singleton(
042: Connection theConnection, ConfigModel theConfigModel) {
043: SchemaListController result = null;
044:
045: if (instance == null) {
046: instance = new SchemaListController(theConnection,
047: theConfigModel);
048: result = instance;
049: }
050:
051: instance.schemaListView.setVisible(true);
052:
053: return result;
054: }
055:
056: public SchemaListController(Connection theConnection,
057: ConfigModel theConfigModel) {
058: connection = theConnection;
059: configModel = theConfigModel;
060:
061: schemaListModel = new SchemaListModel(connection);
062: schemaListModel.addObserver(this );
063:
064: schemaListView = new SchemaListView(null, schemaListModel,
065: false);
066: schemaListView.addObserver(this );
067:
068: schemaListModel.load();
069: }
070:
071: public void modelEvent(ModelEvent event) {
072: String field = event.getField();
073: String value = (String) event.getValue();
074:
075: if (field.equals("schema")) {
076: if (value.equals("begin"))
077: schemaListView.busyCursor(true);
078: else if (value.equals("end"))
079: schemaListView.busyCursor(false);
080: }
081: }
082:
083: public void viewEvent(ViewEvent event) {
084: String action = event.getArg1();
085:
086: /*
087: ** Setting "instance" to null means a new instance of
088: ** SchemaListController is created each time. That in turn
089: ** means a new SchemaListModel which can take a while. Speed
090: ** this up by removing the deleteObserver () and instance =
091: ** null. SchemaListModel is then reused each time the dialog
092: ** pops up.
093: */
094:
095: if (action.equals("ok")) {
096: schemaListView.closeDialog();
097: schemaListModel.deleteObserver(this );
098: schemaListView.deleteObserver(this );
099: SchemaController controller = new SchemaController(
100: configModel, connection, schemaListView
101: .getSelection());
102: instance = null;
103: } else if (action.equals("cancel")) {
104: schemaListView.closeDialog();
105: schemaListModel.deleteObserver(this);
106: schemaListView.deleteObserver(this);
107: instance = null;
108: }
109: }
110: }
|