use of net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction in project tdq-studio-se by Talend.
the class SqlexplorerService method runInDQViewer.
/**
* open the sql editor and run it.
*
* @param alias
* @param databaseConnection
* @param lEditorName
* @param query
*/
private void runInDQViewer(Alias alias, DatabaseConnection databaseConnection, String lEditorName, String query) {
String url = JavaSqlFactory.getURL(databaseConnection);
String username = JavaSqlFactory.getUsername(databaseConnection);
String password = JavaSqlFactory.getPassword(databaseConnection);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
SQLEditorInput input = new SQLEditorInput("SQL Editor (" + alias.getName() + "." + lEditorName + ").sql");
User user = alias.getUser(username);
if (PluginConstant.EMPTY_STRING.equals(username)) {
// get the user both the dbtype and username are the same.
if (!alias.getUrl().equals(url)) {
user = new net.sourceforge.sqlexplorer.dbproduct.User(username, password);
user.setAlias(alias);
alias.addUser(user);
}
} else {
if (user == null) {
user = alias.getDefaultUser();
}
}
alias.setDefaultUser(user);
// create the hive connection
if (databaseConnection != null) {
user.setDatabaseConnection(databaseConnection);
// if ManagedDriver class is not Loaded,check if it lack jars then update the realted jar.
updateDriverIfClassNotLoad(databaseConnection);
}
input.setUser(user);
// TDQ-9533 append a "limit X" in sql query for vertica database.
if (EDatabaseTypeName.VERTICA.getProduct().equals(databaseConnection.getProductId())) {
String maxPref = SQLExplorerPlugin.getDefault().getPreferenceStore().getString(IConstants.MAX_SQL_ROWS);
int maxNum = maxPref == null ? 100 : Integer.parseInt(maxPref);
query = query + " limit " + maxNum;
}
IWorkbenchPage page = SQLExplorerPlugin.getDefault().getActivePage();
try {
SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
editorPart.setText(query);
new ExecSQLAction(editorPart).run();
} catch (PartInitException e) {
log.error(e, e);
}
}
use of net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction 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;
}
Aggregations