BZ 202587 Componentization
Improve handling of changes to model.
diff --git a/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/META-INF/MANIFEST.MF b/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/META-INF/MANIFEST.MF
index bcfaf47..0ac4757 100644
--- a/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/META-INF/MANIFEST.MF
+++ b/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: SQL Query Builder Examples Plug-in
Bundle-SymbolicName: org.eclipse.datatools.sqltools.sqlbuilder.examples;singleton:=true
-Bundle-Version: 1.0.0.200710181
+Bundle-Version: 1.0.0.200710191
Bundle-Activator: org.eclipse.datatools.sqltools.sqlbuilder.examples.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
diff --git a/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/src/org/eclipse/datatools/sqltools/sqlbuilder/examples/dialogs/SQLBuilderDialog.java b/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/src/org/eclipse/datatools/sqltools/sqlbuilder/examples/dialogs/SQLBuilderDialog.java
index 79f9fbf..f45bd9d 100644
--- a/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/src/org/eclipse/datatools/sqltools/sqlbuilder/examples/dialogs/SQLBuilderDialog.java
+++ b/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples/src/org/eclipse/datatools/sqltools/sqlbuilder/examples/dialogs/SQLBuilderDialog.java
@@ -13,6 +13,7 @@
import java.io.IOException;
import java.io.StringWriter;
+import org.eclipse.datatools.sqltools.sqlbuilder.IContentChangeListener;
import org.eclipse.datatools.sqltools.sqlbuilder.ISQLBuilderEditorInput;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderFileEditorInput;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderInputFactory;
@@ -46,7 +47,7 @@
*
* @author Jeremy Lindop
*/
-public class SQLBuilderDialog extends Dialog {
+public class SQLBuilderDialog extends Dialog implements IContentChangeListener {
public static final int I_SAVE_ID = IDialogConstants.CLIENT_ID;
public static final String I_SAVE_LABEL = "Save";
@@ -121,26 +122,10 @@
* It is important to make the next 3 calls in this order.
*/
_sqlBuilder = new SQLBuilder();
+ _sqlBuilder.addContentChangeListener(this);
_sqlBuilder.setInput(_editorInput);
_sqlBuilder.createClient(editComposite);
- /*
- * Add an INotifyChangedListener to the SQLBuilder's domain model.
- * This will notify the dialog when the underlying SQL Query Model is changed.
- */
- ((IChangeNotifier) _sqlBuilder.getDomainModel().getAdapterFactory())
- .addListener(new INotifyChangedListener() {
- public void notifyChanged(Notification msg) {
- if (Display.getCurrent() != null) {
- Display.getCurrent().asyncExec(new Runnable() {
- public void run() {
- updateDirtyStatus();
- }
- });
- }
- }
- });
-
} catch (PartInitException e) {
System.out.println(e.getLocalizedMessage());
e.printStackTrace();
@@ -196,18 +181,14 @@
.createWriteRoot(SQLBuilderInputFactory.ID_XML_MEMENTO_ROOT_ELEMENT);
// Create a SQLEditorStorage passing a name and the SQL Statement as parameters
SQLEditorStorage storage = new SQLEditorStorage(
- _editorInput.getName(), _sqlBuilder
- .getDomainModel().getSQLStatement()
- .getSQL());
+ _editorInput.getName(), _sqlBuilder.getSQL());
// Create a SQLBuilderStorageEditorInput based on the SQLEditorStorage just created
SQLBuilderStorageEditorInput storageEditorInput = new SQLBuilderStorageEditorInput(
storage);
// Set the SQLBuilderStorageEditorInput's connectionInfo
- storageEditorInput.setConnectionInfo(_sqlBuilder
- .getDomainModel().getConnectionInfo());
+ storageEditorInput.setConnectionInfo(_sqlBuilder.getConnectionInfo());
// Set the SQLBuilderStorageEditorInput's OmitSchemaInfo
- storageEditorInput.setOmitSchemaInfo(_sqlBuilder
- .getDomainModel().getOmitSchemaInfo());
+ storageEditorInput.setOmitSchemaInfo(_sqlBuilder.getOmitSchemaInfo());
// Save the state of the SQLBuilderStorageEditorInput to the XMLMemento
SQLBuilderInputFactory.saveState(memento,
@@ -226,6 +207,11 @@
mb.setText("SQL Query Builder XMLMemento");
mb.setMessage(writer.toString());
mb.open();
+
+ /*
+ * Set _sqlBuilder's dirty flag to false
+ */
+ _sqlBuilder.setDirty(false);
}
/*
@@ -315,13 +301,17 @@
}
/**
- * Tests whether the dialog is dirty by asking the SQLBuilder's domain model whether it
+ * Tests whether the dialog is dirty by asking the SQLBuilder's whether it
* is dirty
*
* @return boolean flag indicating the dirty state
*/
protected boolean isDirty() {
- return _sqlBuilder.getDomainModel().isDirty();
+ return _sqlBuilder.isDirty();
+ }
+
+ public void notifyContentChange() {
+ updateDirtyStatus();
}
}
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/META-INF/MANIFEST.MF b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/META-INF/MANIFEST.MF
index c249536..bc45971 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@
Bundle-Name: %_UI_PLUGIN_NAME
Bundle-SymbolicName: org.eclipse.datatools.sqltools.sqlbuilder; singleton:=true
Bundle-ClassPath: .
-Bundle-Version: 1.0.0.200710181
+Bundle-Version: 1.0.0.200710191
Bundle-Activator: org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderPlugin
Bundle-Vendor: %_UI_PLUGIN_PROVIDER
Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/IContentChangeListener.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/IContentChangeListener.java
new file mode 100644
index 0000000..87d6d6e
--- /dev/null
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/IContentChangeListener.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright © 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.sqltools.sqlbuilder;
+
+/**
+ * This interface is a listener interface for receiving notifications about changes
+ * made to the <code>SQLBuilder</code>'s content.
+ *
+ */
+public interface IContentChangeListener {
+
+ /**
+ * This should be called when the content changes.
+ */
+ public void notifyContentChange();
+}
+
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilder.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilder.java
index 44cfb44..6aa4120 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilder.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilder.java
@@ -17,6 +17,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.ListenerList;
import org.eclipse.datatools.modelbase.sql.query.QueryCombined;
import org.eclipse.datatools.modelbase.sql.query.QueryExpressionBody;
import org.eclipse.datatools.modelbase.sql.query.QueryExpressionRoot;
@@ -28,6 +29,7 @@
import org.eclipse.datatools.modelbase.sql.schema.Database;
import org.eclipse.datatools.sqltools.editor.core.connection.ISQLEditorConnectionInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.actions.SQLBuilderActionBarContributor;
+import org.eclipse.datatools.sqltools.sqlbuilder.model.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.model.SQLBuilderConstants;
import org.eclipse.datatools.sqltools.sqlbuilder.model.SQLDomainModel;
import org.eclipse.datatools.sqltools.sqlbuilder.model.SelectHelper;
@@ -38,14 +40,16 @@
import org.eclipse.datatools.sqltools.sqlbuilder.views.DesignViewer;
import org.eclipse.datatools.sqltools.sqlbuilder.views.SQLTreeViewer;
import org.eclipse.datatools.sqltools.sqlbuilder.views.graph.GraphControl;
-import org.eclipse.datatools.sqltools.sqlbuilder.views.source.QueryEventListener;
import org.eclipse.datatools.sqltools.sqlbuilder.views.source.SQLSourceViewer;
import org.eclipse.datatools.sqltools.sqleditor.SQLEditorStorageEditorInput;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.emf.edit.provider.IChangeNotifier;
+import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
@@ -75,7 +79,7 @@
*/
public class SQLBuilder implements IEditingDomainProvider, Observer,
- QueryEventListener, IMenuListener {
+ IContentChangeListener, IMenuListener {
protected SashForm _sashForm = null;
protected SQLTreeViewer _contentOutlinePage;
@@ -87,6 +91,7 @@
ISQLBuilderEditorInput _sqlBuilderEditorInput = null;
protected IFile _iFile;
+ protected ListenerList _contentChangeListeners = null;
/**
* If this is created from an IEditorPart, this is passed in as a parameter
* to the constructor.
@@ -133,8 +138,22 @@
.getAdapterFactory(), commandStack);
_sqlDomainModel.setEditingDomain(_editingDomain);
+
+ _contentChangeListeners = new ListenerList();
}
+ public void addContentChangeListener(IContentChangeListener listener){
+ if (_contentChangeListeners != null){
+ _contentChangeListeners.add(listener);
+ }
+ }
+
+ public void removeContentChangeListener(IContentChangeListener listener){
+ if (_contentChangeListeners != null){
+ _contentChangeListeners.remove(listener);
+ }
+ }
+
/**
* Creates the UI component for the <code>SQLBuilder</code>.
* This method should be called after <code>setInput(ISQLBuilderEditorInput)</code>.
@@ -182,23 +201,23 @@
}
// The client should make this call, not the SQLBuilder
-// ((IChangeNotifier) ui.getDomainModel().getAdapterFactory())
-// .addListener(new INotifyChangedListener() {
-//
-// // public void notifyChanged(Object object, int eventType,
-// // Object
-// // feature, Object oldValue, Object newValue, int index)
-// public void notifyChanged(Notification msg) {
-// if (Display.getCurrent() != null) {
-// Display.getCurrent().asyncExec(new Runnable() {
-//
-// public void run() {
-// updateDirtyStatus();
-// }
-// });
-// }
-// }
-// });
+ ((IChangeNotifier) getDomainModel().getAdapterFactory())
+ .addListener(new INotifyChangedListener() {
+
+ // public void notifyChanged(Object object, int eventType,
+ // Object
+ // feature, Object oldValue, Object newValue, int index)
+ public void notifyChanged(Notification msg) {
+ if (Display.getCurrent() != null) {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ notifyContentChange();
+ }
+ });
+ }
+ }
+ });
boolean isProper = _sqlDomainModel.isProper();
updateProperStatement(isProper);
@@ -313,7 +332,7 @@
*/
protected void createSourceViewer(Composite client) {
_sourceViewer = new SQLSourceViewer(_sqlDomainModel, client, _iFile, true);
- _sourceViewer.setQueryEventListener(this);
+ _sourceViewer.setContentChangeListener(this);
_sourceViewer.initDBContext();
_sourceViewer.setContentProvider(_sqlDomainModel.createContentProvider());
_sourceViewer.setSQLBuilder(this);
@@ -577,8 +596,10 @@
public void update(Observable ob, Object arg) {
if (ob instanceof OmitSchemaInfo) {
_sqlDomainModel.setCurrentSchema();
+ setDirty(true);
_sourceViewer.refreshSource(_sqlDomainModel.getSQLStatement()
.getSQL());
+ notifyContentChange();
}
}
@@ -670,7 +691,7 @@
.encode());
}
- _sqlDomainModel.setDirty(false);
+ setDirty(false);
if (_sourceViewer != null) {
_sourceViewer.setTextChanged(false);
}
@@ -688,8 +709,29 @@
// RATLC01136221 bgp 10Jan2007 - end
}
+ /**
+ * Returns whether the contents of this <code>SQLBuilder</code> have changed since
+ * the last save operation.
+ *
+ * @return <code>true</code> if the contents have been modified and need
+ * saving, and <code>false</code> if they have not changed since the last
+ * save
+ */
+ public boolean isDirty() {
+ return _sqlDomainModel.isDirty();
+ }
+
+ /**
+ * Marks this SQLBuilder's statement as "dirty" (has unsaved changes).
+ *
+ * @param dirty true when there are unsaved changes, otherwise false
+ */
+ public void setDirty(boolean dirty){
+ _sqlDomainModel.setDirty(dirty);
+ }
+
/*
- * @
+ *
*/
protected boolean validateBeforeSave() {
return SQLBuilderPlugin.getPlugin().getPreferenceStore().getBoolean(
@@ -697,12 +739,16 @@
}
/**
- * @see org.eclipse.datatools.sqltools.sqlbuilder.views.source.QueryEventListener#notifyContentChange()
+ * Called when content has changed. This can be a change to the SQL or the
+ * OmitSchemaInfo.
+ *
+ * @see org.eclipse.datatools.sqltools.sqlbuilder.IContentChangeListener#notifyContentChange()
*/
public void notifyContentChange() {
- if (_editor != null && _editor instanceof QueryEventListener){
- ((QueryEventListener)_editor).notifyContentChange();
- }
+ Object[] listeners = _contentChangeListeners.getListeners();
+ for (int i = 0; i < listeners.length; ++i) {
+ ((IContentChangeListener) listeners[i]).notifyContentChange();
+ }
}
/**
@@ -765,4 +811,26 @@
return contextMenu;
}
+ public String getSQL() {
+ return _sqlDomainModel.getSQLStatement().getSQL();
+ }
+
+ /**
+ * Gets the <code>ISQLEditorConnectionInfo</code> object associated with this
+ * SQLBuilder's statement.
+ *
+ * @return ISQLEditorConnectionInfo the SQLBuilder's SQLEditorConnectionInfo object.
+ */
+ public ISQLEditorConnectionInfo getConnectionInfo() {
+ return _sqlDomainModel.getConnectionInfo();
+ }
+
+ /**
+ * Gets the <code>OmitSchemaInfo</code> object associated with this statement
+ *
+ * @return OmitSchemaInfo the SQLBuilder's OmitSchemaInfo object.
+ */
+ public OmitSchemaInfo getOmitSchemaInfo() {
+ return _sqlDomainModel.getOmitSchemaInfo();
+ }
}
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilderEditor.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilderEditor.java
index 3014aa4..9ce5bea 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilderEditor.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/SQLBuilderEditor.java
@@ -19,11 +19,7 @@
import org.eclipse.datatools.sqltools.editor.core.connection.ISQLEditorConnectionInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.actions.SQLBuilderActionBarContributor;
import org.eclipse.datatools.sqltools.sqlbuilder.model.SQLDomainModel;
-import org.eclipse.datatools.sqltools.sqlbuilder.views.source.QueryEventListener;
import org.eclipse.datatools.sqltools.sqleditor.internal.SQLEditorResources;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.edit.provider.IChangeNotifier;
-import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -48,7 +44,7 @@
* SQL Query Builder content editor.
*/
public class SQLBuilderEditor extends EditorPart implements
- ISelectionProvider, QueryEventListener {
+ ISelectionProvider, IContentChangeListener {
/**
* The SQLBuilder for this editor.
@@ -85,6 +81,7 @@
super();
_sqlBuilder = new SQLBuilder(this);
+ _sqlBuilder.addContentChangeListener(this);
}
@@ -106,24 +103,6 @@
*/
_sqlBuilder.createClient(composite);
- /*
- * Add a listener for changes to the SQLBuilderEditor's domain model.
- */
- ((IChangeNotifier) _sqlBuilder.getDomainModel().getAdapterFactory())
- .addListener(new INotifyChangedListener() {
-
- public void notifyChanged(Notification msg) {
- if (Display.getCurrent() != null) {
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- updateDirtyStatus();
- }
- });
- }
- }
- });
-
}
/**
@@ -182,7 +161,7 @@
}
/**
- * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.views.source.QueryEventListener#notifyContentChange()}
+ * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.IContentChangeListener#notifyContentChange()}
*/
public void notifyContentChange() {
updateDirtyStatus();
@@ -193,7 +172,7 @@
}
public boolean isDirty() {
- return _sqlBuilder.getDomainModel().isDirty();
+ return _sqlBuilder.isDirty();
}
public void setResourceRemoved(boolean value) {
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/actions/OmitCurrentSchemaAction.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/actions/OmitCurrentSchemaAction.java
index 0e36c11..f81f3b5 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/actions/OmitCurrentSchemaAction.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/actions/OmitCurrentSchemaAction.java
@@ -11,8 +11,8 @@
package org.eclipse.datatools.sqltools.sqlbuilder.actions;
import org.eclipse.datatools.sqltools.sqlbuilder.Messages;
-import org.eclipse.datatools.sqltools.sqlbuilder.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.dialogs.OmitCurrentSchemaDialog;
+import org.eclipse.datatools.sqltools.sqlbuilder.model.OmitSchemaInfo;
import org.eclipse.jface.window.Window;
public class OmitCurrentSchemaAction extends SQLBuilderAction {
@@ -40,7 +40,14 @@
return;
}
else {
+ // Test if omitSchemaInfo has changed
+ boolean hasChanged = ! omitSchemaInfo.equals(tmpOmitSchemaInfo);
+ // Copy tmpOmitSchemaInfo back to omitSchemaInfo
omitSchemaInfo.copyOmitSchemaInfo(tmpOmitSchemaInfo);
+ // Notify observers
+ if (hasChanged){
+ omitSchemaInfo.omitSchemaInfoChanged();
+ }
}
}
}
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/dialogs/OmitCurrentSchemaDialog.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/dialogs/OmitCurrentSchemaDialog.java
index a064cd7..c0f7c63 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/dialogs/OmitCurrentSchemaDialog.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/dialogs/OmitCurrentSchemaDialog.java
@@ -11,8 +11,8 @@
package org.eclipse.datatools.sqltools.sqlbuilder.dialogs;
import org.eclipse.datatools.sqltools.sqlbuilder.Messages;
-import org.eclipse.datatools.sqltools.sqlbuilder.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderContextIds;
+import org.eclipse.datatools.sqltools.sqlbuilder.model.OmitSchemaInfo;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/IOmitSchemaInfo.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/IOmitSchemaInfo.java
new file mode 100644
index 0000000..da01629
--- /dev/null
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/IOmitSchemaInfo.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright © 2007 Sybase, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.sqltools.sqlbuilder.model;
+
+
+/**
+ * This interface defines the set of properties which determine whether the
+ * current schema name is omitted from SQL generated by the SQL Query Builder.
+ */
+public interface IOmitSchemaInfo {
+
+ /**
+ * Gets whether or not to omit the current schema name in SQL generated by
+ * the SQL Builder.
+ *
+ * @return true when the current schema should be omitted, otherwise false.
+ */
+ public boolean getOmitCurrentSchema();
+
+ /**
+ * Sets whether or not to omit the current schema name in SQL generated by
+ * the SQL Builder.
+ *
+ */
+ public void setOmitCurrentSchema(boolean omitCurrentSchema);
+
+ /**
+ * Gets whether or not to use the authorisation ID as the current schema name for the
+ * omit current schema setting.
+ *
+ * @return true when the authorisation ID should be used as the current schema.
+ */
+ public boolean getUseAUIDAsCurrentSchema();
+
+ /**
+ * Sets whether or not to use the authorisation ID as the current schema name for the
+ * omit current schema setting.
+ *
+ */
+ public void setUseAUIDAsCurrentSchema(boolean useAUIDAsCurrentSchema);
+
+ /**
+ * Gets the current schema as input by the user.
+ *
+ * @return the current schema as input by the user.
+ */
+ public String getCurrentSchema();
+
+ /**
+ * Sets the current schema as input by the user.
+ *
+ * @return the current schema as input by the user.
+ */
+ public void setCurrentSchema(String currentSchema);
+
+ /**
+ * Encodes the given <code>IOmitSchemaInfo</code> object for persistence.
+ * @see org.eclipse.datatools.sqltools.sqlbuilder.model.OmitSchemaInfo#decode(String)
+ * @return encoded String
+ */
+ public String encode();
+
+}
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/OmitSchemaInfo.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/OmitSchemaInfo.java
new file mode 100644
index 0000000..fe2fb09
--- /dev/null
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/OmitSchemaInfo.java
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * Copyright © 2000, 2007 Sybase, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.datatools.sqltools.sqlbuilder.model;
+
+import java.util.Observable;
+
+import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderPlugin;
+import org.eclipse.datatools.sqltools.sqlbuilder.preferences.SQLBuilderPreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * This class defines the set of properties which determine whether the
+ * current schema name is omitted from SQL generated by the SQL Query Builder.
+ */
+public class OmitSchemaInfo extends Observable implements IOmitSchemaInfo{
+
+ protected boolean _omitCurrentSchema = false;
+ protected boolean _useAUIDAsCurrentSchema = true;
+ protected String _currentSchema = "";
+
+ /**
+ * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.model.IOmitSchemaInfo#getOmitCurrentSchema()}
+ */
+ public boolean getOmitCurrentSchema() {
+ return _omitCurrentSchema;
+ }
+
+ /**
+ * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.model.IOmitSchemaInfo#setOmitCurrentSchema(boolean)}
+ */
+ public void setOmitCurrentSchema(boolean omitCurrentSchema)
+ {
+ if (omitCurrentSchema != _omitCurrentSchema){
+ _omitCurrentSchema = omitCurrentSchema;
+ omitSchemaInfoChanged();
+ }
+ }
+
+ /**
+ * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.model.IOmitSchemaInfo#getUseAUIDAsCurrentSchema()}
+ */
+ public boolean getUseAUIDAsCurrentSchema() {
+ return _useAUIDAsCurrentSchema;
+ }
+
+ /**
+ * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.model.IOmitSchemaInfo#setUseAUIDAsCurrentSchema(boolean)}
+ */
+ public void setUseAUIDAsCurrentSchema(boolean useAUIDAsCurrentSchema)
+ {
+ if (useAUIDAsCurrentSchema != _useAUIDAsCurrentSchema){
+ _useAUIDAsCurrentSchema = useAUIDAsCurrentSchema;
+ omitSchemaInfoChanged();
+ }
+ }
+
+ /**
+ * @see org.eclipse.datatools.sqltools.sqlbuilder.model.IOmitSchemaInfo#getCurrentSchema()
+ */
+ public String getCurrentSchema() {
+ return _currentSchema;
+ }
+
+ /**
+ * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.model.IOmitSchemaInfo#setCurrentSchema(String)}
+ */
+ public void setCurrentSchema(String currentSchema)
+ {
+ if (!_currentSchema.equals(currentSchema)){
+ _currentSchema = (currentSchema == null ? "" : currentSchema);
+ omitSchemaInfoChanged();
+ }
+ }
+
+ /**
+ * Implements {@link org.eclipse.datatools.sqltools.sqlbuilder.model.IOmitSchemaInfo#encode()}
+ * @see decode()
+ */
+ public String encode() {
+ StringBuffer code = new StringBuffer("");
+ code.append(Boolean.toString(_omitCurrentSchema)).append(":");
+ code.append(Boolean.toString(_useAUIDAsCurrentSchema)).append(":");
+ code.append(_currentSchema == null? "":_currentSchema);
+ return code.toString();
+ }
+
+ /**
+ * Decodes a <code>OmitSchemaInfo</code> from an encoded String.
+ * @see encode()
+ * @param code encoded <code>OmitSchemaInfo</code> object.
+ * @return <code>OmitSchemaInfo</code> object
+ */
+ public static OmitSchemaInfo decode(String code)
+ {
+ OmitSchemaInfo omitSchemaInfo = new OmitSchemaInfo();
+
+ if(SQLBuilderPlugin.getPlugin().getLogger().isTracing()){
+ SQLBuilderPlugin.getPlugin().getLogger().writeTraceEntry(
+ new Object[]{code});
+ }
+
+ if (code == null || !code.matches(".*:.*:.*"))
+ {
+ SQLBuilderPlugin.getPlugin().getLogger().writeTrace( "Cannot decode <" + code + ">");
+ omitSchemaInfo.initFromPreferences();
+ }
+ else {
+
+ }
+ int i = 0;
+ int j = code.indexOf(':');
+ String sOmitCurrentSchema = code.substring(i, j);
+ omitSchemaInfo._omitCurrentSchema =
+ Boolean.valueOf(sOmitCurrentSchema).booleanValue();
+
+ i = j + 1;
+ j = code.indexOf(':', i);
+ String sUseAUIDAsCurrentSchema = code.substring(i, j);
+ omitSchemaInfo._useAUIDAsCurrentSchema =
+ Boolean.valueOf(sUseAUIDAsCurrentSchema).booleanValue();
+
+ i = j + 1;
+ omitSchemaInfo._currentSchema = code.substring(i);
+
+ return (OmitSchemaInfo) SQLBuilderPlugin.getPlugin().getLogger().writeTraceExit(omitSchemaInfo);
+ }
+
+ /**
+ * Function to be called when this <code>OmitSchemaInfo</code> has changed.
+ */
+ public void omitSchemaInfoChanged(){
+ this.setChanged();
+ this.notifyObservers(null);
+ }
+
+ /**
+ * Returns true if the IOmitSchemaInfo passed has the same values as this OmitSchemaInfo
+ * @param iOmitSchemaInfo
+ */
+ public boolean equals(IOmitSchemaInfo iOmitSchemaInfo){
+ boolean equals = true;
+ if (iOmitSchemaInfo.getOmitCurrentSchema() != _omitCurrentSchema){
+ equals = false;
+ }
+ else if (iOmitSchemaInfo.getUseAUIDAsCurrentSchema() != _useAUIDAsCurrentSchema){
+ equals = false;
+ }
+ else if (_currentSchema == null){
+ if (iOmitSchemaInfo.getCurrentSchema() != null && iOmitSchemaInfo.getCurrentSchema().length() > 0){
+ equals = false;
+ }
+ }
+ else if (_currentSchema != null && !_currentSchema.equals(iOmitSchemaInfo.getCurrentSchema())){
+ equals = false;
+ }
+
+ return equals;
+ }
+
+ /**
+ * Copy the OmitSchemaInfo passed as a parameter to this OmitSchemaInfo.
+ *
+ * @param iOmitSchemaInfo <code>IOmitSchemaInfo</code> object to be copied.
+ */
+ public void copyOmitSchemaInfo(IOmitSchemaInfo iOmitSchemaInfo){
+
+ // Reset values of this
+ _omitCurrentSchema = iOmitSchemaInfo.getOmitCurrentSchema();
+ _useAUIDAsCurrentSchema = iOmitSchemaInfo.getUseAUIDAsCurrentSchema();
+ if (iOmitSchemaInfo.getCurrentSchema() == null){
+ _currentSchema = "";
+ }
+ else {
+ _currentSchema = iOmitSchemaInfo.getCurrentSchema();
+ }
+
+ }
+
+
+ /**
+ * Initialises the <code>OmitSchemaInfo</code> from Eclipse preference store.
+ */
+ public void initFromPreferences(){
+ IPreferenceStore store = getPreferenceStore();
+ _omitCurrentSchema = store.getBoolean(SQLBuilderPreferenceConstants.OMIT_CURRENT_SCHEMA_IN_SQL);
+ _useAUIDAsCurrentSchema = store.getBoolean(SQLBuilderPreferenceConstants.OMIT_CURRENT_SCHEMA_USE_AUID);
+ _currentSchema = store.getString(SQLBuilderPreferenceConstants.OMIT_CURRENT_SCHEMA_CURRENT_SCHEMA);
+ }
+
+ /*
+ * Returns preference store that belongs to the our plugin.
+ */
+ protected IPreferenceStore getPreferenceStore()
+ {
+ return SQLBuilderPlugin.getPlugin().getPreferenceStore();
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/SQLDomainModel.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/SQLDomainModel.java
index eab7309..417bfd4 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/SQLDomainModel.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/model/SQLDomainModel.java
@@ -52,7 +52,6 @@
import org.eclipse.datatools.sqltools.parsers.sql.query.postparse.DataTypeResolver;
import org.eclipse.datatools.sqltools.parsers.sql.query.postparse.TableReferenceResolver;
import org.eclipse.datatools.sqltools.sqlbuilder.Messages;
-import org.eclipse.datatools.sqltools.sqlbuilder.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderPlugin;
import org.eclipse.datatools.sqltools.sqlbuilder.util.RSCCoreUIUtil;
import org.eclipse.datatools.sqltools.sqlbuilder.util.SQLDBUtil;
@@ -591,7 +590,7 @@
/**
* Gets the <code>ISQLEditorConnectionInfo</code> object associated with this statement.
*
- * @return the current connection info object
+ * @return ISQLEditorConnectionInfo the model's connection info object
*/
public ISQLEditorConnectionInfo getConnectionInfo() {
return connectionInfo;
@@ -620,7 +619,7 @@
/**
* Gets the <code>OmitSchemaInfo</code> object associated with this statement
*
- * @param info the OmitSchemaInfo object to get
+ * @return OmitSchemaInfo the model's OmitSchemaInfo object
*/
public OmitSchemaInfo getOmitSchemaInfo() {
return _omitSchemaInfo;
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLBuilderEditorInputUtil.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLBuilderEditorInputUtil.java
index e52364d..4264e3a 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLBuilderEditorInputUtil.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLBuilderEditorInputUtil.java
@@ -17,10 +17,10 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.datatools.sqltools.editor.core.connection.ISQLEditorConnectionInfo;
-import org.eclipse.datatools.sqltools.sqlbuilder.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderFileEditorInput;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderInputFactory;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderStorageEditorInput;
+import org.eclipse.datatools.sqltools.sqlbuilder.model.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqleditor.SQLEditorStorage;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.XMLMemento;
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLFileUtil.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLFileUtil.java
index 6bd4203..51ea481 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLFileUtil.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/util/SQLFileUtil.java
@@ -15,8 +15,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.datatools.sqltools.editor.core.connection.ISQLEditorConnectionInfo;
-import org.eclipse.datatools.sqltools.sqlbuilder.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderPlugin;
+import org.eclipse.datatools.sqltools.sqlbuilder.model.OmitSchemaInfo;
import org.eclipse.datatools.sqltools.sqleditor.SQLEditorConnectionInfo;
/**
diff --git a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/views/source/SQLSourceViewer.java b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/views/source/SQLSourceViewer.java
index 779f48f..bf8bf54 100644
--- a/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/views/source/SQLSourceViewer.java
+++ b/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/views/source/SQLSourceViewer.java
@@ -27,6 +27,7 @@
import org.eclipse.datatools.sqltools.parsers.sql.SQLParserException;
import org.eclipse.datatools.sqltools.parsers.sql.SQLParserInternalException;
import org.eclipse.datatools.sqltools.parsers.sql.query.postparse.TableReferenceResolver;
+import org.eclipse.datatools.sqltools.sqlbuilder.IContentChangeListener;
import org.eclipse.datatools.sqltools.sqlbuilder.Messages;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderPlugin;
import org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilder;
@@ -95,7 +96,7 @@
SourceViewerAction contentTipAction;
protected boolean textChanged = false;
private boolean isParseRequired = false;
- protected QueryEventListener qListener = null;
+ protected IContentChangeListener qListener = null;
private ITextListener textChangeListener;
protected SQLBuilder sqlbuilder;
@@ -320,7 +321,7 @@
// pass in the editor using the source viewer
// detect changes in source
- public void setQueryEventListener(QueryEventListener qListener) {
+ public void setContentChangeListener(IContentChangeListener qListener) {
this.qListener = qListener;
}