use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.
the class OpenInEditorAction method run.
public void run() {
try {
TableItem[] ti = _table.getSelection();
if (ti == null || ti.length == 0) {
return;
}
String queryDelimiter = SQLExplorerPlugin.getDefault().getPluginPreferences().getString(IConstants.SQL_QRY_DELIMITER);
StringBuffer copiedText = new StringBuffer();
for (int i = 0; i < ti.length; i++) {
SQLHistoryElement el = (SQLHistoryElement) ti[i].getData();
copiedText.append(el.getRawSQLString());
if (ti.length > 0) {
copiedText.append(queryDelimiter);
copiedText.append("\n");
}
}
SQLHistoryElement sqlHistoryElement = (SQLHistoryElement) ti[0].getData();
User user = sqlHistoryElement.getUser();
Alias alias;
if (user != null)
alias = user.getAlias();
else {
alias = sqlHistoryElement.getAlias();
if (alias != null)
user = alias.getDefaultUser();
if (user == null) {
ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
if (view != null)
user = view.getDefaultUser();
}
}
if (user != null && !user.hasAuthenticated()) {
boolean okToOpen = MessageDialog.openConfirm(_table.getShell(), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Title"), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Prefix") + " " + user.getDescription() + Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Postfix"));
if (okToOpen) {
OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, user, false);
openDlgAction.run();
}
}
SQLEditorInput input = new SQLEditorInput("SQL Editor (" + SQLExplorerPlugin.getDefault().getEditorSerialNo() + ").sql");
input.setUser(user);
IWorkbenchPage page = SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (page == null)
return;
SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
editorPart.setText(copiedText.toString());
} catch (Throwable e) {
SQLExplorerPlugin.error("Error creating sql editor", e);
}
}
use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.
the class SQLExplorerPlugin method startDefaultConnections.
/**
* Open all connections that have the 'open on startup property'. This method should be called from within the UI
* thread!
*/
public void startDefaultConnections(ConnectionsView connectionsView) {
this.connectionsView = connectionsView;
if (_defaultConnectionsStarted) {
return;
}
String fontDesc = getPluginPreferences().getString(IConstants.FONT);
FontData fontData = null;
try {
try {
fontData = new FontData(fontDesc);
} catch (IllegalArgumentException e) {
fontData = new FontData("1|Courier New|10|0|WINDOWS|1|-13|0|0|0|400|0|0|0|0|3|2|1|49|Courier New");
}
PreferenceConverter.setValue(getPreferenceStore(), IConstants.FONT, fontData);
} catch (IllegalArgumentException e) {
error("Error setting font", e);
}
boolean openEditor = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.AUTO_OPEN_EDITOR);
// Get the database structure view - NOTE: we don't use SQLExplorerPlugin.getDatabaseView()
// because it may not have an active page yet
DatabaseStructureView dbView = null;
IWorkbenchSite site = connectionsView.getSite();
if (site.getPage() != null) {
dbView = (DatabaseStructureView) site.getPage().findView(DatabaseStructureView.class.getName());
}
for (Alias alias : aliasManager.getAliases()) {
if (alias.isConnectAtStartup() && alias.isAutoLogon() && alias.getDefaultUser() != null) {
if (dbView != null) {
try {
dbView.addUser(alias.getDefaultUser());
} catch (SQLCannotConnectException e) {
// Ignore it; the problem is already in the log, we do not want to delay startup, and the
// problem will
// be apparent as soon as the user tries to use the connection
}
}
if (openEditor) {
SQLEditorInput input = new SQLEditorInput(SQL_EDITOR + SQLExplorerPlugin.getDefault().getEditorSerialNo() + SQL);
input.setUser(alias.getDefaultUser());
try {
site.getPage().openEditor(input, SQLEditor.class.getName());
} catch (PartInitException e) {
SQLExplorerPlugin.error("Cannot open SQL editor", e);
}
}
}
}
_defaultConnectionsStarted = true;
}
Aggregations