use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class DataExporterHTML method writeImageCell.
private void writeImageCell(File file) throws DBException {
out.write("<td>");
if (file == null || !file.exists()) {
out.write(" ");
} else {
Image image = null;
try {
image = ImageIO.read(file);
} catch (IOException e) {
throw new DBException("Can't read an exported image " + image, e);
}
if (image != null) {
String imagePath = file.getAbsolutePath();
imagePath = "files/" + imagePath.substring(imagePath.lastIndexOf(File.separator));
int width = ((BufferedImage) image).getWidth();
int height = ((BufferedImage) image).getHeight();
int rwidth = width;
int rheight = height;
if (width > IMAGE_FRAME_SIZE || height > IMAGE_FRAME_SIZE) {
float scale = 1;
if (width > height) {
scale = IMAGE_FRAME_SIZE / (float) width;
} else {
scale = IMAGE_FRAME_SIZE / (float) height;
}
rwidth = (int) (rwidth * scale);
rheight = (int) (rheight * scale);
}
out.write("<a href=\"" + imagePath + "\">");
out.write("<img src=\"" + imagePath + "\" width=\"" + rwidth + "\" height=\"" + rheight + "\" />");
out.write("</a>");
} else {
out.write(" ");
}
}
out.write("</td>");
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class DataExporterSQL method exportHeader.
@Override
public void exportHeader(DBCSession session) throws DBException, IOException {
columns = getSite().getAttributes();
DBPNamedObject source = getSite().getSource();
if (source instanceof DBSObject) {
tableName = omitSchema ? DBUtils.getQuotedIdentifier((DBSObject) source) : DBUtils.getObjectFullName(source, DBPEvaluationContext.UI);
} else {
throw new DBException("SQL export may be done only from table object");
}
rowCount = 0;
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class DataExporterXML method writeImageCell.
private void writeImageCell(File file) throws DBException {
if (file != null && file.exists()) {
Image image = null;
try {
image = ImageIO.read(file);
} catch (IOException e) {
throw new DBException("Can't read an exported image " + image, e);
}
if (image != null) {
String imagePath = file.getAbsolutePath();
imagePath = "files/" + imagePath.substring(imagePath.lastIndexOf(File.separator));
out.write(imagePath);
}
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class SQLEditor method processQueries.
private void processQueries(@NotNull final List<SQLQuery> queries, final boolean newTab, final boolean export, final boolean checkSession) {
if (queries.isEmpty()) {
// Nothing to process
return;
}
final DBPDataSourceContainer container = getDataSourceContainer();
if (checkSession) {
try {
DBRProgressListener connectListener = new DBRProgressListener() {
@Override
public void onTaskFinished(IStatus status) {
if (!status.isOK() || container == null || !container.isConnected()) {
UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, null, status);
return;
}
// Make a small pause to let all UI connection listeners to finish
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// it's ok
}
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
processQueries(queries, newTab, export, false);
}
});
}
};
if (!checkSession(connectListener)) {
return;
}
} catch (DBException ex) {
ResultSetViewer viewer = getActiveResultSetViewer();
if (viewer != null) {
viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
}
UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
return;
}
}
if (sashForm.getMaximizedControl() != null) {
sashForm.setMaximizedControl(null);
}
// Save editor
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
doSave(new NullProgressMonitor());
}
final boolean isSingleQuery = (queries.size() == 1);
if (!newTab || !isSingleQuery) {
// We don't need new tab or we are executing a script - so close all extra tabs
closeExtraResultTabs(null);
}
if (newTab) {
// Execute each query in a new tab
for (int i = 0; i < queries.size(); i++) {
SQLQuery query = queries.get(i);
QueryProcessor queryProcessor = (i == 0 && !isSingleQuery ? curQueryProcessor : createQueryProcessor(queries.size() == 1));
queryProcessor.processQueries(Collections.singletonList(query), true, export);
}
} else {
// Use current tab.
// If current tab was pinned then use first tab
final QueryResultsContainer firstResults = curQueryProcessor.getFirstResults();
if (firstResults.isPinned()) {
curQueryProcessor = queryProcessors.get(0);
}
closeExtraResultTabs(curQueryProcessor);
if (firstResults.tabItem != null) {
resultTabs.setSelection(firstResults.tabItem);
}
curQueryProcessor.processQueries(queries, false, export);
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class NavigatorHandlerObjectOpen method refreshDatabaseNode.
private static void refreshDatabaseNode(@NotNull DBNDatabaseNode selectedNode) throws InvocationTargetException, InterruptedException {
final DBNDatabaseNode nodeToRefresh = selectedNode;
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
nodeToRefresh.refreshNode(monitor, nodeToRefresh);
} catch (DBException e) {
log.error("Error refreshing database object", e);
}
}
});
}
Aggregations