Skip to content

Commit

Permalink
dbeaver#7072 Entity post-save actions: double-compile fix
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Feb 8, 2020
1 parent 2277c1d commit 0327a44
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@

package org.jkiss.dbeaver.ui.editors;

import java.util.Map;

/**
* IDatabasePostSaveProcessor
*/
public interface IDatabasePostSaveProcessor {

void runPostSaveCommands();
/**
* Execute post-save commands.
* May run database object compile or other complex stuff.
* @param context can be used to save object state. Cleared on each save.
*/
void runPostSaveCommands(Map<String, Object> context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package org.jkiss.dbeaver.ui.controls;

import org.eclipse.jface.action.*;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.events.MouseAdapter;
Expand Down Expand Up @@ -87,14 +89,11 @@ public void clearLog()

public void layoutLog()
{
UIUtils.syncExec(new Runnable() {
@Override
public void run() {
if (!infoTable.isDisposed()) {
infoTable.getColumn(0).setWidth(infoTable.getBounds().width - 110);
infoTable.getColumn(1).setWidth(50);
infoTable.getColumn(2).setWidth(50);
}
UIUtils.asyncExec(() -> {
if (!infoTable.isDisposed()) {
infoTable.getColumn(0).setWidth(infoTable.getBounds().width - 110);
infoTable.getColumn(1).setWidth(50);
infoTable.getColumn(2).setWidth(50);
}
});
}
Expand All @@ -103,65 +102,62 @@ public void run() {
protected void log(final int type, final Object message, final Throwable t)
{
super.log(type, message, t);
UIUtils.syncExec(new Runnable() {
@Override
public void run() {
if (infoTable == null || infoTable.isDisposed()) {
return;
}
int color = -1;
switch (type) {
case LOG_LEVEL_TRACE:
color = SWT.COLOR_DARK_BLUE;
break;
case LOG_LEVEL_DEBUG:
case LOG_LEVEL_INFO:
break;
case LOG_LEVEL_WARN:
color = SWT.COLOR_DARK_YELLOW;
break;
case LOG_LEVEL_ERROR:
case LOG_LEVEL_FATAL:
color = SWT.COLOR_DARK_RED;
break;
default:
break;
}
String messageStr;
DBCCompileError error = null;
if (message instanceof DBCCompileError) {
error = (DBCCompileError) message;
messageStr = error.getMessage();
} else {
messageStr = CommonUtils.toString(message);
UIUtils.syncExec(() -> {
if (infoTable == null || infoTable.isDisposed()) {
return;
}
int color = -1;
switch (type) {
case LOG_LEVEL_TRACE:
color = SWT.COLOR_DARK_BLUE;
break;
case LOG_LEVEL_DEBUG:
case LOG_LEVEL_INFO:
break;
case LOG_LEVEL_WARN:
color = SWT.COLOR_DARK_YELLOW;
break;
case LOG_LEVEL_ERROR:
case LOG_LEVEL_FATAL:
color = SWT.COLOR_DARK_RED;
break;
default:
break;
}
String messageStr;
DBCCompileError error = null;
if (message instanceof DBCCompileError) {
error = (DBCCompileError) message;
messageStr = error.getMessage();
} else {
messageStr = CommonUtils.toString(message);
}
StringTokenizer st = new StringTokenizer(messageStr, "\n"); //$NON-NLS-1$
while (st.hasMoreTokens()) {
final TableItem item = new TableItem(infoTable, SWT.NONE);
item.setText(0, st.nextToken());
if (error != null && error.getLine() > 0) {
item.setText(1, String.valueOf(((DBCCompileError) message).getLine()));
item.setText(2, String.valueOf(((DBCCompileError) message).getPosition()));
}
StringTokenizer st = new StringTokenizer(messageStr, "\n"); //$NON-NLS-1$
while (st.hasMoreTokens()) {
final TableItem item = new TableItem(infoTable, SWT.NONE);
item.setText(0, st.nextToken());
if (error != null && error.getLine() > 0) {
item.setText(1, String.valueOf(((DBCCompileError) message).getLine()));
item.setText(2, String.valueOf(((DBCCompileError) message).getPosition()));
}
if (color != -1) {
item.setForeground(infoTable.getDisplay().getSystemColor(color));
}
item.setData(message);
infoTable.showItem(item);
if (color != -1) {
item.setForeground(infoTable.getDisplay().getSystemColor(color));
}
if (t != null) {
String prevMessage = null;
for (Throwable ex = t; error != null; ex = ex.getCause()) {
final String errorMessage = ex.getMessage();
if (errorMessage == null || errorMessage.equals(prevMessage)) {
continue;
}
prevMessage = errorMessage;
TableItem stackItem = new TableItem(infoTable, SWT.NONE);
stackItem.setText(errorMessage);
stackItem.setForeground(infoTable.getDisplay().getSystemColor(SWT.COLOR_RED));
infoTable.showItem(stackItem);
item.setData(message);
infoTable.showItem(item);
}
if (t != null) {
String prevMessage = null;
for (Throwable ex = t; error != null; ex = ex.getCause()) {
final String errorMessage = ex.getMessage();
if (errorMessage == null || errorMessage.equals(prevMessage)) {
continue;
}
prevMessage = errorMessage;
TableItem stackItem = new TableItem(infoTable, SWT.NONE);
stackItem.setText(errorMessage);
stackItem.setForeground(infoTable.getDisplay().getSystemColor(SWT.COLOR_RED));
infoTable.showItem(stackItem);
}
}
});
Expand Down Expand Up @@ -210,7 +206,7 @@ public void run()
infoTable.addDisposeListener(e -> menuMgr.dispose());
}

public void copySelectionToClipboard()
private void copySelectionToClipboard()
{
final TableItem[] selection = infoTable.getSelection();
if (ArrayUtils.isEmpty(selection)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
import org.jkiss.dbeaver.ui.editors.text.DatabaseMarkerAnnotationModel;
import org.jkiss.dbeaver.utils.RuntimeUtils;

import java.util.Map;

/**
* SQLEditorNested
*/
Expand All @@ -75,6 +77,8 @@ public abstract class SQLEditorNested<T extends DBSObject>
implements IActiveWorkbenchPart, IRefreshablePart, DBCSourceHost, IDatabasePostSaveProcessor
{

private static final String SAVE_CONTEXT_COMPILE_PARAM = "object.compiled";

private EditorPageControl pageControl;
private ObjectCompilerLogViewer compileLog;
private Control editorControl;
Expand Down Expand Up @@ -167,11 +171,15 @@ public void doSave(final IProgressMonitor progressMonitor) {
}

@Override
public void runPostSaveCommands() {
public void runPostSaveCommands(Map<String, Object> context) {
String compileCommandId = getCompileCommandId();
if (compileCommandId != null) {
if (compileCommandId != null && context.get(SAVE_CONTEXT_COMPILE_PARAM) == null) {
// Compile after save
ActionUtils.runCommand(compileCommandId, getSite().getWorkbenchWindow());
try {
ActionUtils.runCommand(compileCommandId, getSite().getWorkbenchWindow());
} finally {
context.put(SAVE_CONTEXT_COMPILE_PARAM, true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ public void doSave(IProgressMonitor monitor)
}

// Run post-save commands (e.g. compile)
Map<String, Object> context = new LinkedHashMap<>();
for (IEditorPart editor : editorMap.values()) {
if (editor instanceof IDatabasePostSaveProcessor) {
((IDatabasePostSaveProcessor) editor).runPostSaveCommands();
((IDatabasePostSaveProcessor) editor).runPostSaveCommands(context);
}
if (monitor.isCanceled()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,12 @@ public boolean isRelationalObject(DBSObject object) {
}

@Override
public void runPostSaveCommands() {
public void runPostSaveCommands(Map<String, Object> context) {
for (ISaveablePart sp : nestedSaveable) {
if (sp instanceof TabbedFolderPageEditor) {
IEditorPart editor = ((TabbedFolderPageEditor) sp).getEditor();
if (editor instanceof IDatabasePostSaveProcessor) {
((IDatabasePostSaveProcessor) editor).runPostSaveCommands();
((IDatabasePostSaveProcessor) editor).runPostSaveCommands(context);
}
}
}
Expand Down

0 comments on commit 0327a44

Please sign in to comment.