Commit 706f7425 authored by Matija Obreza's avatar Matija Obreza

Merge branch '26-upload-pause-resume' into 'master'

Resolve "Upload pause-resume"

Closes #26

See merge request !19
parents 85ab4a9a bdfa81df
......@@ -15,16 +15,12 @@
*/
package org.genesys2.anno.gui;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.log4j.LogManager;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.WriterAppender;
import org.apache.log4j.spi.LoggingEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
......@@ -33,9 +29,8 @@ public class SwtLogAppender extends WriterAppender {
private static final String DEFAULT_LAYOUT_PATTERN = "%d{yyyy-MM-dd HH:mm:ss} %t %-5p %c{1}:%L - %m%n";
private Text text;
private Display display;
private int maxBufferSize = 100000;
private int maxBufferSize = 1000000;
private StringBuffer logBuffer = new StringBuffer();
private AtomicBoolean resetText = new AtomicBoolean(true);
public SwtLogAppender(Text text2) {
this.text = text2;
......@@ -45,15 +40,6 @@ public class SwtLogAppender extends WriterAppender {
close();
}
});
text.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (resetText.getAndSet(false)) {
text.setText(logBuffer.toString());
text.setSelection(logBuffer.length());
}
}
});
display = text.getDisplay();
LogManager.getRootLogger().addAppender(this);
PatternLayout patternLayout = new org.apache.log4j.PatternLayout();
......@@ -98,14 +84,15 @@ public class SwtLogAppender extends WriterAppender {
logBuffer.replace(0, pos + 1, "");
}
}
resetText.set(true);
// System.err.println(mes);
display.asyncExec(new Runnable() {
@Override
public void run() {
display.asyncExec(() -> {
if (text != null) {
text.redraw();
int scrollPos = text.getLineCount() - 1;
text.setText(logBuffer.toString());
int topIndex = text.getTopIndex();
if ((scrollPos <= 0 && topIndex == 0) || topIndex >= scrollPos - 3) {
text.setSelection(text.getText().length() * 2);
}
}
});
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -12,48 +12,71 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
*/
package org.genesys2.anno.gui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import swing2swt.layout.BorderLayout;
public class LogViewer extends Composite {
private Text txtLogtext;
/**
* Create the composite.
/**
* The Class TimedList.
*
* @param parent
* @param style
* @param <T> the generic type
*/
public LogViewer(Composite parent, int style) {
super(parent, style);
setLayout(new BorderLayout(0, 0));
public class TimedList<T> extends ArrayList<T> {
private static final long serialVersionUID = 2721716147790325499L;
private Date created = null;
ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(BorderLayout.NORTH);
public TimedList() {
}
ToolItem tltmClear = new ToolItem(toolBar, SWT.NONE);
tltmClear.setText("Clear");
@Override
public void clear() {
created = null;
super.clear();
}
ToolItem tltmSave = new ToolItem(toolBar, SWT.NONE);
tltmSave.setText("Save...");
@Override
public boolean add(T e) {
if (created == null) {
created = new Date();
}
return super.add(e);
}
txtLogtext = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.MULTI);
txtLogtext.setLayoutData(BorderLayout.CENTER);
@Override
public boolean addAll(Collection<? extends T> c) {
if (created == null) {
created = new Date();
}
return super.addAll(c);
}
@Override
public void add(int index, T element) {
if (created == null) {
created = new Date();
}
super.add(index, element);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
public boolean addAll(int index, Collection<? extends T> c) {
if (created == null) {
created = new Date();
}
return super.addAll(index, c);
}
public Date getCreated() {
return created;
}
public boolean isOlderThanSeconds(int seconds) {
if (created == null) {
return true;
}
return (new Date().getTime() - created.getTime()) / 1000 > seconds;
}
}
......@@ -54,21 +54,22 @@ public class MsAccessRowReader implements RowReader {
this.db = DatabaseBuilder.open(sourceFile);
_log.debug("CHARSET: " + db.getCharset());
this.table = db.getTable(sheetName);
this.cursor = table.getDefaultCursor();
this.cursor = table.newCursor().setIndexByColumnNames("INSTCODE").toCursor();
}
/// This is called in case data starts beyond 1st row
@Override
public void setSkipRows(int skipRows) {
_log.info("Skipping rows {}", skipRows);
// The -1 is because CSV and Excel include the header row in the count
_log.info("Skipping rows {}", skipRows - 1);
cursor.reset();
// try {
// cursor.moveNextRows(skipRows);
// } catch (IOException e) {
// _log.error("Could not skip rows", e);
// }
try {
cursor.moveNextRows(skipRows - 1);
} catch (IOException e) {
_log.error("Could not skip rows", e);
}
}
@Override
......
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