Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SQL Query Builder Component API"

Line 21: Line 21:
 
The main component class is
 
The main component class is
 
:org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilder
 
:org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilder
This class is a graphical editing component to which a SQL statement is passed for editing. It can be hosted in an editor, a dialog or a wizard.
+
This class is a graphical editing component to which a SQL statement is passed for editing. It can be hosted in an editor, a dialog or a wizard. Examples of the SQLBuilder class hosted in a dialog and an editor are described below. These examples demonstrate all the API functions described below.
 +
 
 
The sequence of function calls required to host the SQLBuilder is as follows:
 
The sequence of function calls required to host the SQLBuilder is as follows:
 
::_sqlBuilder = new SQLBuilder();
 
::_sqlBuilder = new SQLBuilder();
Line 28: Line 29:
 
::_sqlBuilder.createClient(editComposite);
 
::_sqlBuilder.createClient(editComposite);
 
where ''_sqlBuilder'' is a variable of type SQLBuilder, ''this'' is the containing class, ''_editorInput'' is the input and ''editComposite'' is the composite which will contain the SQLBuilder.
 
where ''_sqlBuilder'' is a variable of type SQLBuilder, ''this'' is the containing class, ''_editorInput'' is the input and ''editComposite'' is the composite which will contain the SQLBuilder.
 +
 +
Depending on the consumer, these function calls may not all be called in a single sequence, but may be split into groups called from other functions. For example if the consumer is an EditorPart, ''setInput'' should be called during the editor's ''init(IEditorSite, IEditorInput)'' method and ''createClient'' should be called during ''createPartControl(Composite)'' (see '' Example SQLBuilder editor'' below).
  
 
'''Constructor'''
 
'''Constructor'''
Line 39: Line 42:
 
'''setInput(ISQLBuilderEditorInput)'''
 
'''setInput(ISQLBuilderEditorInput)'''
  
'''createClient'''
+
Passes an EditorInput to the SQLBuilder. See '''Input Types''' below.
  
Depending on the consumer, these function calls may not all be called in a single sequence, but may be split into groups called from other functions. For example if the consumer is an EditorPart, ''setInput'' should be called during the editor's ''init(IEditorSite, IEditorInput)'' method and ''createClient'' should be called during ''createPartControl(Composite)''. For more details, please see the examples described below.
+
'''createClient(Composite)'''
 +
Constructs the SQLBuilder UI inside the ''Composite'' passed as a parameter.
  
 
A further two functions are useful for editors. These are:
 
A further two functions are useful for editors. These are:
Line 51: Line 55:
  
 
== Input Types ==
 
== Input Types ==
 +
SQLBuilder.setInput takes an org.eclipse.datatools.sqltools.sqlbuilder.ISQLBuilderEditorInput parameter, for which two implementations are provided:
 +
:org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderFileEditorInput
 +
:org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderStorageEditorInput
  
 
'''File inputs'''
 
'''File inputs'''
 +
SQLBuilderFileEditorInput
  
 
'''Non file-based inputs'''
 
'''Non file-based inputs'''

Revision as of 09:26, 22 October 2007

Back to SQL Development Tools page

Introduction

The SQL Query Builder is a component for visually editing SQL DML statements. It can be consumed by other UI components such as editors, dialogs and wizards. As input, it can accept .sql files created by the DTP SQL File Editor or it can accept SQL statements passed by consumers in the form of strings.

The API described here is currently provisional and may be changed as a result of feedback from early adopters.

CVS Location

The SQL Query Builder is located in the datatools part of the Eclipse CVS repository:

Host: dev.eclipse.org
Repository path: /cvsroot/datatools

The SQL Query Builder plugin is in

org.eclipse.datatools.sqltools/plugins/org.eclipse.datatools.sqltools.sqlbuilder

There is also an examples plugin in

org.eclipse.datatools.sqltools/examples/org.eclipse.datatools.sqltools.sqlbuilder.examples

SQLBuilder Component and Example Consumers

SQLBuilder component

The main component class is

org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilder

This class is a graphical editing component to which a SQL statement is passed for editing. It can be hosted in an editor, a dialog or a wizard. Examples of the SQLBuilder class hosted in a dialog and an editor are described below. These examples demonstrate all the API functions described below.

The sequence of function calls required to host the SQLBuilder is as follows:

_sqlBuilder = new SQLBuilder();
_sqlBuilder.addContentChangeListener(this);
_sqlBuilder.setInput(_editorInput);
_sqlBuilder.createClient(editComposite);

where _sqlBuilder is a variable of type SQLBuilder, this is the containing class, _editorInput is the input and editComposite is the composite which will contain the SQLBuilder.

Depending on the consumer, these function calls may not all be called in a single sequence, but may be split into groups called from other functions. For example if the consumer is an EditorPart, setInput should be called during the editor's init(IEditorSite, IEditorInput) method and createClient should be called during createPartControl(Composite) (see Example SQLBuilder editor below).

Constructor

The constructor takes no parameters.

addContentChangeListener(IContentChangeListener)

addContentChangeListener should be passed an object which implements the interface org.eclipse.datatools.sqltools.sqlbuilder.IContentChangeListener. This interface has a single method notifyContentChange which is invoked when the content model being edited by the SQLBuilder changes. This allows the client to be notified of changes so that it can update its own dirty status and handle user requests to save the statement being edited.

setInput(ISQLBuilderEditorInput)

Passes an EditorInput to the SQLBuilder. See Input Types below.

createClient(Composite) Constructs the SQLBuilder UI inside the Composite passed as a parameter.

A further two functions are useful for editors. These are:

setLoadOnConnection(boolean);
connectIfNeeded(IWorkbenchPart)

The problem these functions are designed to solve is that of the workbench opening when its saved state includes an instance the editor which hosts the SQLBuilder. When the Workbench opens it will try to open the editor and the SQLBuilder will need to make a connection to a database. setLoadOnConnection tells the SQLBuilder to delay loading the input until a database connection has been obtained. connectIfNeeded should be invoked as soon as possible after the editor has initialized inside the Workbench.

setLoadOnConnection should be called before calling setInput and connectIfNeeded should be called after the editor has been initialized in the Workbench. In the example editor (see below), setLoadOnConnection is called during setFocus.

Input Types

SQLBuilder.setInput takes an org.eclipse.datatools.sqltools.sqlbuilder.ISQLBuilderEditorInput parameter, for which two implementations are provided:

org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderFileEditorInput
org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderStorageEditorInput

File inputs SQLBuilderFileEditorInput

Non file-based inputs

Example SQLBuilder editor

The SQLBuilderEditor hosts the SQLBuilder component in an Eclipse editor:

org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderEditor

Example SQLBuilder dialog

In the org.eclipse.datatools.sqltools.sqlbuilder.examples plugin, there is an example of a dialog which hosts the SQLBuilder component:

org.eclipse.datatools.sqltools.sqlbuilder.examples.dialogs.SQLBuilderDialog

The SQLBuilderEditor opens .sql files which have previously been created in the DTP SQL File Editor. It relies on the connection profile information being persisted as persistent properties associated with the .sql resource (this is done by the SQL File Editor).

Back to the top