Search in sources :

Example 1 with Dictionary

use of net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary in project tdq-studio-se by Talend.

the class MetaDataSession method initialise.

/**
 * Initialises the metadata, but only if the meta data has not already been collected
 */
private void initialise() throws SQLException {
    if (getConnection() != null)
        return;
    _assistanceEnabled = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.SQL_ASSIST);
    if (_assistanceEnabled) {
        // schedule job to load dictionary for this session
        dictionary = new Dictionary();
        DictionaryLoader dictionaryLoader = new DictionaryLoader(this);
        dictionaryLoader.schedule(500);
    }
    SQLConnection connection = null;
    try {
        connection = grabConnection();
        metaData = connection.getSQLMetaData();
        // MOD gdbu 2011-4-12 bug : 20578
        databaseProductName = metaData.getDatabaseProductName();
        dbModel = new DatabaseModel(this);
        if (metaData.supportsCatalogs())
            catalogs = metaData.getCatalogs();
    } catch (SQLException sqlerror) {
        SQLExplorerPlugin.error(sqlerror);
    // ~20578
    } finally {
        if (connection != null)
            releaseConnection(connection);
    }
}
Also used : Dictionary(net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary) DatabaseModel(net.sourceforge.sqlexplorer.dbstructure.DatabaseModel) SQLException(java.sql.SQLException) DictionaryLoader(net.sourceforge.sqlexplorer.sessiontree.model.utility.DictionaryLoader)

Example 2 with Dictionary

use of net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary in project tdq-studio-se by Talend.

the class SQLTextEditor method createSourceViewer.

@Override
protected ISourceViewer createSourceViewer(final Composite parent, IVerticalRuler ruler, int style) {
    parent.setLayout(new FillLayout());
    final Composite myParent = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0;
    myParent.setLayout(layout);
    // create divider line
    Composite div1 = new Composite(myParent, SWT.NONE);
    GridData lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL;
    lgid.heightHint = 1;
    lgid.verticalIndent = 1;
    div1.setLayoutData(lgid);
    div1.setBackground(editor.getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
    // create text viewer
    GridData gid = new GridData();
    gid.grabExcessHorizontalSpace = gid.grabExcessVerticalSpace = true;
    gid.horizontalAlignment = gid.verticalAlignment = GridData.FILL;
    Dictionary dictionary = null;
    if (editor.getSession() != null && _enableContentAssist) {
        dictionary = editor.getSession().getUser().getMetaDataSession().getDictionary();
    }
    sqlTextViewer = new SQLTextViewer(myParent, style, store, dictionary, ruler);
    sqlTextViewer.getControl().setLayoutData(gid);
    // create bottom divider line
    Composite div2 = new Composite(myParent, SWT.NONE);
    lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL;
    lgid.heightHint = 1;
    lgid.verticalIndent = 0;
    div2.setLayoutData(lgid);
    div2.setBackground(editor.getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
    final SQLEditor thisEditor = editor;
    sqlTextViewer.getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {

        private ExecSQLAction _execSQLAction = new ExecSQLAction(thisEditor);

        @Override
        public void verifyKey(VerifyEvent event) {
            if (event.stateMask == SWT.CTRL && event.keyCode == 13) {
                event.doit = false;
                _execSQLAction.run();
            }
        }
    });
    sqlTextViewer.getTextWidget().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            SQLTextEditor.this.editor.getEditorSite().getPage().activate(SQLTextEditor.this.editor.getEditorSite().getPart());
        }
    });
    myParent.layout();
    IDocument dc = new Document();
    sqlTextViewer.setDocument(dc);
    mcl.install(sqlTextViewer);
    return sqlTextViewer;
}
Also used : Dictionary(net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary) Composite(org.eclipse.swt.widgets.Composite) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) ExecSQLAction(net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction) KeyAdapter(org.eclipse.swt.events.KeyAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) SQLTextViewer(net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) VerifyEvent(org.eclipse.swt.events.VerifyEvent) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with Dictionary

use of net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary in project tdq-studio-se by Talend.

the class MouseClickListener method getCurrentTextRegion.

private IRegion getCurrentTextRegion(ISourceViewer viewer) {
    if (viewer == null)
        return null;
    Dictionary dictionary = ((SQLTextViewer) viewer).dictionary;
    if (dictionary == null)
        return null;
    int offset = getCurrentTextOffset(viewer);
    if (offset == -1)
        return null;
    try {
        IRegion reg = selectWord(viewer.getDocument(), offset);
        if (reg == null)
            return null;
        String selection = viewer.getDocument().get(reg.getOffset(), reg.getLength());
        if (selection == null)
            return null;
        Object obj = dictionary.getByTableName(selection.toLowerCase());
        if (obj == null)
            return null;
        else {
            if (!(obj instanceof ArrayList))
                return null;
            ArrayList ls = (ArrayList) obj;
            if (ls.isEmpty())
                return null;
            Object node = ((ArrayList) obj).get(0);
            if (node instanceof TableNode)
                activeTableNode = (INode) node;
            else
                return null;
        }
        return reg;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Dictionary(net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary) INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) ArrayList(java.util.ArrayList) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) SQLTextViewer(net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

Dictionary (net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary)3 SQLTextViewer (net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DatabaseModel (net.sourceforge.sqlexplorer.dbstructure.DatabaseModel)1 INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)1 TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)1 DictionaryLoader (net.sourceforge.sqlexplorer.sessiontree.model.utility.DictionaryLoader)1 ExecSQLAction (net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 VerifyEvent (org.eclipse.swt.events.VerifyEvent)1 Point (org.eclipse.swt.graphics.Point)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1