org.eclipse.datatools.sqltools.common.ui.sqlstatementarea
Class SQLStatementArea

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by org.eclipse.datatools.sqltools.common.ui.sqlstatementarea.SQLStatementArea
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class SQLStatementArea
extends org.eclipse.swt.widgets.Composite

A customized SWT widget based on org.eclipse.swt.widgets.Composite is for displaying SQL Statement in other SWT Control. It looks like an embedded SQL Editor with Syntax high lighting, vertical ruler for line number, etc.

Following example code is a demo for using the SQLStatementArea in a dialog which displayes some pieces of SQL Statements with syntax high lighting and simple context menu:

     public class SQLDialog extends TitleAreaDialog
     {
         private SQLStatementArea sta;
           .......
         protected Control createDialogArea(Composite parent)
         {
           sta = new SQLStatementArea(composite, SWT.BORDER, new DMPSQLSourceViewerService(), true);
           sta.setInput(sqlCode,dbType);
           sta.setEditable(false);
           sta.setEnabled(false);
           sta.configureViewer(new SQLSourceViewerConfiguration(dbType));
           sta.setLayoutData(new GridData(GridData.FILL_BOTH));
           createContextMenu();
          }
          
         private void createContextMenu()
         {
             ...... 
           MenuManager menuMgr = new MenuManager();
           menuMgr.setRemoveAllWhenShown(true);
           menuMgr.addMenuListener(new IMenuListener()
           {
               public void menuAboutToShow(IMenuManager mgr)
               {
                   mgr.add(new Separator());
                   mgr.add(select_action);
               }
           }); 
           Menu menu = menuMgr.createContextMenu(sta.getViewer().getTextWidget());
           sta.getViewer().getTextWidget().setMenu(menu);
          }
     }
 

Author:
Shi-feng Yu

Field Summary
 
Fields inherited from class org.eclipse.swt.widgets.Composite
embeddedHandle
 
Fields inherited from class org.eclipse.swt.widgets.Widget
handle
 
Constructor Summary
SQLStatementArea(org.eclipse.swt.widgets.Composite parent, int style, ISQLSourceViewerService service, boolean lineNum)
          Instantiates a new SQLStatementArea.
 
Method Summary
 void configureViewer(org.eclipse.jface.text.source.SourceViewerConfiguration configuration)
          Configures the source viewer using the given configuration.
 java.lang.String getContentInString()
          Gets the SQL Statements String which is displayed in this SQLStatementArea.
 org.eclipse.jface.text.source.SourceViewer getViewer()
          Gets the Viewer which is an instance of SourceViewer.
 void setEditable(boolean editable)
          Sets the editable state
 void setInput(java.lang.String source, java.lang.String dbType)
          Sets the input for the SQLStatementArea.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, drawBackground, getBackgroundMode, getChildren, getClientArea, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getBorderWidth, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getRegion, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setRegion, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, reskin, setData, setData, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SQLStatementArea

public SQLStatementArea(org.eclipse.swt.widgets.Composite parent,
                        int style,
                        ISQLSourceViewerService service,
                        boolean lineNum)
Instantiates a new SQLStatementArea.

Parameters:
parent - a composite control which will be the parent of the new instance (cannot be null)
style - the style of control to construct
service - a helper class implemented by user
lineNum - whether to display line number in vertial ruler
Method Detail

setInput

public void setInput(java.lang.String source,
                     java.lang.String dbType)
Sets the input for the SQLStatementArea. There could be two kinds of input:
  • java.lang.String which contains the SQL Statements. If user passes in a String, we need to create a Document for it.
  • org.eclipse.jface.text.IDocument which contains the SQL Statements.

    Parameters:
    source - The SQL Statement in String.
    dbType - The Database type for the SQL Statement.

  • setEditable

    public void setEditable(boolean editable)
    Sets the editable state

    Parameters:
    editable -

    configureViewer

    public void configureViewer(org.eclipse.jface.text.source.SourceViewerConfiguration configuration)
    Configures the source viewer using the given configuration.

    Parameters:
    configuration - the source viewer configuration to be used

    getViewer

    public org.eclipse.jface.text.source.SourceViewer getViewer()
    Gets the Viewer which is an instance of SourceViewer.

    Returns:

    getContentInString

    public java.lang.String getContentInString()
    Gets the SQL Statements String which is displayed in this SQLStatementArea.

    Returns: