001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.sql.framework.ui.model.impl;
043:
044: import java.util.Iterator;
045:
046: import org.netbeans.modules.sql.framework.model.SQLCanvasObject;
047: import org.netbeans.modules.sql.framework.model.SQLDefinition;
048: import org.netbeans.modules.sql.framework.model.SQLJoinView;
049: import org.netbeans.modules.sql.framework.model.SQLModelObjectFactory;
050: import org.netbeans.modules.sql.framework.model.SQLObject;
051: import org.netbeans.modules.sql.framework.model.SQLObjectFactory;
052: import org.netbeans.modules.sql.framework.ui.event.SQLDataEvent;
053: import org.netbeans.modules.sql.framework.ui.event.SQLDataListener;
054: import org.netbeans.modules.sql.framework.ui.model.JoinBuilderSQLUIModel;
055:
056: import com.sun.sql.framework.exception.BaseException;
057:
058: /**
059: * @author Ritesh Adval
060: */
061: public class JoinBuilderSQLUIModelImpl extends AbstractSQLModel
062: implements JoinBuilderSQLUIModel {
063:
064: private SQLJoinView joinView;
065:
066: /** Creates a new instance of JoinBuilderSQLUIModelImpl */
067: public JoinBuilderSQLUIModelImpl(SQLDefinition def) {
068: joinView = SQLModelObjectFactory.getInstance()
069: .createSQLJoinView();
070: if (def != null) {
071: joinView.setParent(def);
072: }
073:
074: joinView.setDisplayName("JoinView");
075: }
076:
077: public JoinBuilderSQLUIModelImpl(SQLJoinView jView) {
078: this .joinView = jView;
079: }
080:
081: public void addObject(SQLObject sqlObject) throws BaseException {
082: super .addObject(sqlObject);
083: addObjectIgnoreUndo(sqlObject);
084: }
085:
086: public void addObjectIgnoreUndo(SQLObject sqlObject)
087: throws BaseException {
088: addSQLObject(sqlObject);
089:
090: // first time when an source table is added we want to handle auto join
091: addObjectInGraph(sqlObject, true);
092: }
093:
094: public void addSQLObject(SQLObject sqlObject) throws BaseException {
095: joinView.addObject(sqlObject);
096: this .setDirty(true);
097: }
098:
099: public SQLCanvasObject createObject(String className)
100: throws BaseException {
101: SQLObject sqlObj = SQLObjectFactory.createSQLObject(className);
102: return (SQLCanvasObject) sqlObj;
103: }
104:
105: // hack need to override this and remove the runnable part
106: // otherwise a duplicate join was always created for 3 table join
107: public synchronized void fireSQLDataCreationEvent(
108: final SQLDataEvent evt) throws BaseException {
109: Iterator it = listeners.iterator();
110: while (it.hasNext()) {
111: final SQLDataListener l = (SQLDataListener) it.next();
112: l.objectCreated(evt);
113: }
114: }
115:
116: public SQLJoinView getSQLJoinView() {
117: return this .joinView;
118: }
119:
120: public void removeAll() {
121: joinView.removeAllObjects();
122: }
123:
124: public void removeObject(SQLObject sqlObject) throws BaseException {
125: super .removeObject(sqlObject);
126: removeObjectIgnoreUndo(sqlObject);
127: }
128:
129: public void removeObjectIgnoreUndo(SQLObject sqlObject)
130: throws BaseException {
131: joinView.removeObject(sqlObject);
132: }
133:
134: public void restoreLinks() {
135: // now link other objects
136: super .restoreLinks(joinView.getAllObjects());
137: }
138:
139: /**
140: * Rebuilds view model based on object pool and SQLDefinition hierarchy.
141: */
142: public synchronized void restoreUIState() throws BaseException {
143: restoreObjects();
144: restoreLinks();
145: }
146:
147: public void setSQLJoinView(SQLJoinView jView) {
148: this .joinView = jView;
149: }
150:
151: /**
152: * set it to true if a java operator is used in the model
153: *
154: * @param javaOp true if there is a java operator
155: */
156: void setContainsJavaOperators(boolean javaOp) {
157: // Does not implement this, since no operators are used in join preview
158: }
159:
160: protected void addObjectInGraph(SQLObject sqlObject,
161: boolean handleAutojoin) throws BaseException {
162: if (sqlObject instanceof SQLCanvasObject) {
163: SQLDataEvent evt = new SQLDataEvent(this ,
164: (SQLCanvasObject) sqlObject);
165: fireSQLDataCreationEvent(evt);
166: isDirty = true;
167: }
168: }
169:
170: private void restoreObjects() throws BaseException {
171: super.restoreObjects(joinView.getAllObjects());
172: }
173:
174: }
|