001: /*
002: ** $Id: SchemaController.java,v 1.18 2000/10/26 08:34:16 mrw Exp $
003: **
004: ** Mike Wilson, September 2000, mrw@whisperingwind.co.uk
005: **
006: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
007: **
008: ** This program is free software; you can redistribute it and/or modify
009: ** it under the terms of the GNU General Public License as published by
010: ** the Free Software Foundation; either version 2 of the License, or
011: ** (at your option) any later version.
012: **
013: ** This program is distributed in the hope that it will be useful,
014: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
015: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: ** GNU General Public License for more details.
017: **
018: ** You should have received a copy of the GNU Library General
019: ** Public License along with this library; if not, write to the
020: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
021: ** Boston, MA 02111-1307 USA.
022: */
023:
024: package uk.co.whisperingwind.vienna;
025:
026: import java.sql.Connection;
027: import uk.co.whisperingwind.framework.Controller;
028: import uk.co.whisperingwind.framework.ModelEvent;
029: import uk.co.whisperingwind.framework.ViewEvent;
030:
031: /**
032: ** Controller for the schema view.
033: */
034:
035: class SchemaController extends Controller {
036: private ConfigModel configModel = null;
037: private Connection connection = null;
038: private String schemaName = null;
039: private SchemaView schemaView = null;
040: private SchemaTableModel tableModel = null;
041: private SchemaColumnModel columnModel = null;
042: private SchemaPrimaryModel primaryModel = null;
043: private SchemaForeignModel foreignModel = null;
044:
045: public SchemaController(ConfigModel theConfigModel,
046: Connection theConnection, String theSchemaName) {
047: configModel = theConfigModel;
048: connection = theConnection;
049: schemaName = theSchemaName;
050:
051: tableModel = new SchemaTableModel(connection, schemaName);
052: columnModel = new SchemaColumnModel(connection, schemaName);
053: primaryModel = new SchemaPrimaryModel(connection, schemaName);
054: foreignModel = new SchemaForeignModel(connection, schemaName);
055: schemaView = new SchemaView(connection, tableModel
056: .getTableModel(), columnModel.getTableModel(),
057: primaryModel.getTableModel(), foreignModel
058: .getTableModel(), schemaName);
059: schemaView.addObserver(this );
060:
061: tableModel.addObserver(this );
062: columnModel.addObserver(this );
063: primaryModel.addObserver(this );
064: foreignModel.addObserver(this );
065: }
066:
067: public void modelEvent(ModelEvent event) {
068: String field = event.getField();
069: String value = (String) event.getValue();
070:
071: if (field.equals("table")) {
072: if (value.equals("updated")) {
073: schemaView.setTableModel(tableModel.getTableModel());
074: schemaView.busyCursor(false);
075: schemaView.setStatus("");
076: }
077: } else if (field.equals("columns")) {
078: if (value.equals("updated")) {
079: schemaView.setColumnModel(columnModel.getTableModel());
080: schemaView.busyCursor(false);
081: schemaView.setStatus("");
082: }
083: } else if (field.equals("primary")) {
084: if (value.equals("updated")) {
085: schemaView
086: .setPrimaryModel(primaryModel.getTableModel());
087: schemaView.busyCursor(false);
088: schemaView.setStatus("");
089: }
090: } else if (field.equals("foreign")) {
091: if (value.equals("updated")) {
092: schemaView
093: .setForeignModel(foreignModel.getTableModel());
094: schemaView.busyCursor(false);
095: schemaView.setStatus("");
096: }
097: }
098: }
099:
100: public void viewEvent(ViewEvent event) {
101: String action = event.getArg1();
102: String tableName = schemaView.getSelectedName();
103: String tableType = schemaView.getSelectedType();
104:
105: if (action.equals("table"))
106: loadTabData(tableName, tableType);
107: else if (action.equals("new"))
108: new SchemaController(configModel, connection, schemaName);
109: else if (action.equals("close"))
110: schemaView.closeDialog();
111: else if (action.equals("viewtable"))
112: reloadTableModel();
113: else if (action.equals("viewview"))
114: reloadTableModel();
115: else if (action.equals("viewsynonym"))
116: reloadTableModel();
117: else if (action.equals("viewsequence"))
118: reloadTableModel();
119: else if (action.equals("changeTab"))
120: loadTabData(tableName, tableType);
121: }
122:
123: private void reloadTableModel() {
124: schemaView.busyCursor(true);
125: schemaView.clearColumnSelection();
126: schemaView.clearTableSelection();
127:
128: columnModel.clear();
129: primaryModel.clear();
130: foreignModel.clear();
131:
132: schemaView.setStatus("Loading schema");
133: boolean showTables = schemaView.getShowTables();
134: boolean showViews = schemaView.getShowViews();
135: boolean showSynonyms = schemaView.getShowSynonyms();
136: boolean showSequences = schemaView.getShowSequences();
137: tableModel.load(showTables, showViews, showSynonyms,
138: showSequences);
139: }
140:
141: /**
142: ** Load column details, primary keys or foreign keys depending on
143: ** which tab is currently selected.
144: */
145:
146: private void loadTabData(String tableName, String tableType) {
147: schemaView.clearColumnSelection();
148:
149: switch (schemaView.getSelectedTab()) {
150: case 0:
151: if (columnModel.load(tableName, tableType)) {
152: schemaView.busyCursor(true);
153: schemaView.setStatus("Loading columns");
154: }
155:
156: break;
157:
158: case 1:
159: if (primaryModel.load(tableName)) {
160: schemaView.busyCursor(true);
161: schemaView.setStatus("Loading primary keys");
162: }
163:
164: break;
165:
166: case 2:
167: if (foreignModel.load(tableName)) {
168: schemaView.busyCursor(true);
169: schemaView.setStatus("Loading foreign keys");
170: }
171:
172: break;
173:
174: default:
175: break;
176: }
177: }
178: }
|