Search in sources :

Example 1 with SQLTextViewer

use of net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer in project tdq-studio-se by Talend.

the class SQLPreferencePage method createPreviewer.

/**
 * Creates the synatx highlighting previewer
 *
 * @param parent
 * @return
 */
private Control createPreviewer(Composite parent) {
    final String separator = System.getProperty("line.separator");
    final String content = Messages.getString("select_*_from_MyTable_--_single_line_comment_12") + separator + Messages.getString("/*_multi_line_comment_13") + // $NON-NLS-2$
    separator + Messages.getString("select_*_14") + separator + Messages.getString("end_multi_line_comment*/_15") + separator + // $NON-NLS-2$
    Messages.getString("where_A___1___16");
    // Get a text viewer and load our sample into it
    final SQLTextViewer fPreviewViewer = new SQLTextViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, getPreferenceStore(), null);
    fPreviewViewer.setEditable(false);
    IDocument document = new Document(content);
    fPreviewViewer.setDocument(document);
    getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            fPreviewViewer.invalidateTextPresentation();
            // MOD by zshen for bug 12046,save the font size.
            FontData fd = PreferenceConverter.getFontData(fontFieldEditor.getPreferenceStore(), IConstants.FONT);
            getPreferenceStore().setValue(IConstants.FONT, fd.toString());
        // ~12046
        }
    });
    return fPreviewViewer.getControl();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) FontData(org.eclipse.swt.graphics.FontData) SQLTextViewer(net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with SQLTextViewer

use of net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer 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 SQLTextViewer

use of net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer 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

SQLTextViewer (net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer)3 Dictionary (net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary)2 Document (org.eclipse.jface.text.Document)2 IDocument (org.eclipse.jface.text.IDocument)2 ArrayList (java.util.ArrayList)1 INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)1 TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)1 ExecSQLAction (net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IRegion (org.eclipse.jface.text.IRegion)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)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 FontData (org.eclipse.swt.graphics.FontData)1 Point (org.eclipse.swt.graphics.Point)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1