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();
}
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;
}
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;
}
}
Aggregations