Commit 7654c623 authored by Matija Obreza's avatar Matija Obreza

Fixed SWT thread access and added Ctrl+K shortcut to clear log window

parent ff9d0ea4
...@@ -87,6 +87,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -87,6 +87,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import swing2swt.layout.BorderLayout; import swing2swt.layout.BorderLayout;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
public class PushDialog extends Dialog { public class PushDialog extends Dialog {
private static final Logger _log = Logger.getLogger(PushDialog.class); private static final Logger _log = Logger.getLogger(PushDialog.class);
...@@ -212,6 +214,14 @@ public class PushDialog extends Dialog { ...@@ -212,6 +214,14 @@ public class PushDialog extends Dialog {
createContents(); createContents();
logAppender = new SwtLogAppender(this.txtJson); logAppender = new SwtLogAppender(this.txtJson);
txtJson.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.character == 'k' && (e.stateMask == SWT.COMMAND || e.stateMask == SWT.CTRL)) {
logAppender.clearBuffer();
}
}
});
Composite composite = new Composite(shell, SWT.NO_FOCUS); Composite composite = new Composite(shell, SWT.NO_FOCUS);
composite.setLayoutData(BorderLayout.SOUTH); composite.setLayoutData(BorderLayout.SOUTH);
...@@ -297,6 +307,9 @@ public class PushDialog extends Dialog { ...@@ -297,6 +307,9 @@ public class PushDialog extends Dialog {
for (int i = futures.size() - 1; i >= 0; i--) { for (int i = futures.size() - 1; i >= 0; i--) {
Future<?> future = futures.get(i); Future<?> future = futures.get(i);
if (future == null) {
continue;
}
if (future.isDone() || future.isCancelled()) { if (future.isDone() || future.isCancelled()) {
futures.remove(future); futures.remove(future);
} else { } else {
...@@ -512,9 +525,12 @@ public class PushDialog extends Dialog { ...@@ -512,9 +525,12 @@ public class PushDialog extends Dialog {
long lastTime = 0; long lastTime = 0;
do { do {
for (int i = futures.size() - 1; i >= 0; i--) { for (int i = futures.size() - 1; i >= 0; i--) {
Future<?> f = futures.get(i); Future<?> future = futures.get(i);
if (f.isDone()) { if (future == null) {
futures.remove(f); continue;
}
if (future.isDone()) {
futures.remove(future);
} }
} }
...@@ -676,7 +692,7 @@ public class PushDialog extends Dialog { ...@@ -676,7 +692,7 @@ public class PushDialog extends Dialog {
// If filtering, check INSTCODE is listed // If filtering, check INSTCODE is listed
if (instCodesFilter.size() > 0 && !(isBlackList ^ instCodesFilter.contains(accessionInstCode))) { if (instCodesFilter.size() > 0 && !(isBlackList ^ instCodesFilter.contains(accessionInstCode))) {
_log.info("Ignoring accessions with inst code : " + accessionInstCode); _log.debug("Ignoring accessions with inst code : " + accessionInstCode);
continue; continue;
} }
......
...@@ -47,6 +47,17 @@ public class SwtLogAppender extends WriterAppender { ...@@ -47,6 +47,17 @@ public class SwtLogAppender extends WriterAppender {
patternLayout.setConversionPattern(DEFAULT_LAYOUT_PATTERN); patternLayout.setConversionPattern(DEFAULT_LAYOUT_PATTERN);
setLayout(patternLayout); setLayout(patternLayout);
} }
public void clearBuffer() {
synchronized (logBuffer) {
display.asyncExec(() -> {
if (text != null) {
text.setText("");
}
});
logBuffer.delete(0, logBuffer.length());
}
}
public void setConversionPattern(String conversionPattern) { public void setConversionPattern(String conversionPattern) {
PatternLayout patternLayout = (PatternLayout) getLayout(); PatternLayout patternLayout = (PatternLayout) getLayout();
...@@ -75,14 +86,16 @@ public class SwtLogAppender extends WriterAppender { ...@@ -75,14 +86,16 @@ public class SwtLogAppender extends WriterAppender {
} }
} }
final String mes = layout.format(loggingEvent) + (throwableStr == null ? "" : sb.toString()); final String mes = layout.format(loggingEvent) + (throwableStr == null ? "" : sb.toString());
logBuffer.append(mes); synchronized (logBuffer) {
if (logBuffer.length() > maxBufferSize && text.getSelectionCount() == 0) { logBuffer.append(mes);
// System.err.println("CLEARING POOL len=" + logBuffer.length() + if (logBuffer.length() > maxBufferSize) {
// " removing=" + (logBuffer.length() - maxBufferSize)); // System.err.println("CLEARING POOL len=" + logBuffer.length() +
logBuffer.replace(0, logBuffer.length() - maxBufferSize, ""); // " removing=" + (logBuffer.length() - maxBufferSize));
int pos = logBuffer.indexOf("\n"); logBuffer.replace(0, logBuffer.length() - maxBufferSize, "");
if (pos >= 0) { int pos = logBuffer.indexOf("\n");
logBuffer.replace(0, pos + 1, ""); if (pos >= 0) {
logBuffer.replace(0, pos + 1, "");
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment