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;
import com.fasterxml.jackson.databind.node.ObjectNode;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
public class PushDialog extends Dialog {
private static final Logger _log = Logger.getLogger(PushDialog.class);
......@@ -212,6 +214,14 @@ public class PushDialog extends Dialog {
createContents();
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.setLayoutData(BorderLayout.SOUTH);
......@@ -297,6 +307,9 @@ public class PushDialog extends Dialog {
for (int i = futures.size() - 1; i >= 0; i--) {
Future<?> future = futures.get(i);
if (future == null) {
continue;
}
if (future.isDone() || future.isCancelled()) {
futures.remove(future);
} else {
......@@ -512,9 +525,12 @@ public class PushDialog extends Dialog {
long lastTime = 0;
do {
for (int i = futures.size() - 1; i >= 0; i--) {
Future<?> f = futures.get(i);
if (f.isDone()) {
futures.remove(f);
Future<?> future = futures.get(i);
if (future == null) {
continue;
}
if (future.isDone()) {
futures.remove(future);
}
}
......@@ -676,7 +692,7 @@ public class PushDialog extends Dialog {
// If filtering, check INSTCODE is listed
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;
}
......
......@@ -47,6 +47,17 @@ public class SwtLogAppender extends WriterAppender {
patternLayout.setConversionPattern(DEFAULT_LAYOUT_PATTERN);
setLayout(patternLayout);
}
public void clearBuffer() {
synchronized (logBuffer) {
display.asyncExec(() -> {
if (text != null) {
text.setText("");
}
});
logBuffer.delete(0, logBuffer.length());
}
}
public void setConversionPattern(String conversionPattern) {
PatternLayout patternLayout = (PatternLayout) getLayout();
......@@ -75,14 +86,16 @@ public class SwtLogAppender extends WriterAppender {
}
}
final String mes = layout.format(loggingEvent) + (throwableStr == null ? "" : sb.toString());
logBuffer.append(mes);
if (logBuffer.length() > maxBufferSize && text.getSelectionCount() == 0) {
// System.err.println("CLEARING POOL len=" + logBuffer.length() +
// " removing=" + (logBuffer.length() - maxBufferSize));
logBuffer.replace(0, logBuffer.length() - maxBufferSize, "");
int pos = logBuffer.indexOf("\n");
if (pos >= 0) {
logBuffer.replace(0, pos + 1, "");
synchronized (logBuffer) {
logBuffer.append(mes);
if (logBuffer.length() > maxBufferSize) {
// System.err.println("CLEARING POOL len=" + logBuffer.length() +
// " removing=" + (logBuffer.length() - maxBufferSize));
logBuffer.replace(0, logBuffer.length() - maxBufferSize, "");
int pos = logBuffer.indexOf("\n");
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