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
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2011 Google, Inc. * Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Google, Inc. - initial API and implementation * Google, Inc. - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.wb.swt; package org.eclipse.wb.swt;
import java.io.FileInputStream; import java.io.FileInputStream;
......
...@@ -15,16 +15,12 @@ ...@@ -15,16 +15,12 @@
*/ */
package org.genesys2.anno.gui; package org.genesys2.anno.gui;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
import org.apache.log4j.PatternLayout; import org.apache.log4j.PatternLayout;
import org.apache.log4j.WriterAppender; import org.apache.log4j.WriterAppender;
import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.LoggingEvent;
import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener; 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.Display;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
...@@ -33,9 +29,8 @@ public class SwtLogAppender extends WriterAppender { ...@@ -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 static final String DEFAULT_LAYOUT_PATTERN = "%d{yyyy-MM-dd HH:mm:ss} %t %-5p %c{1}:%L - %m%n";
private Text text; private Text text;
private Display display; private Display display;
private int maxBufferSize = 100000; private int maxBufferSize = 1000000;
private StringBuffer logBuffer = new StringBuffer(); private StringBuffer logBuffer = new StringBuffer();
private AtomicBoolean resetText = new AtomicBoolean(true);
public SwtLogAppender(Text text2) { public SwtLogAppender(Text text2) {
this.text = text2; this.text = text2;
...@@ -45,15 +40,6 @@ public class SwtLogAppender extends WriterAppender { ...@@ -45,15 +40,6 @@ public class SwtLogAppender extends WriterAppender {
close(); 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(); display = text.getDisplay();
LogManager.getRootLogger().addAppender(this); LogManager.getRootLogger().addAppender(this);
PatternLayout patternLayout = new org.apache.log4j.PatternLayout(); PatternLayout patternLayout = new org.apache.log4j.PatternLayout();
...@@ -98,14 +84,15 @@ public class SwtLogAppender extends WriterAppender { ...@@ -98,14 +84,15 @@ public class SwtLogAppender extends WriterAppender {
logBuffer.replace(0, pos + 1, ""); logBuffer.replace(0, pos + 1, "");
} }
} }
resetText.set(true);
// System.err.println(mes); // System.err.println(mes);
display.asyncExec(new Runnable() { display.asyncExec(() -> {
@Override if (text != null) {
public void run() { int scrollPos = text.getLineCount() - 1;
if (text != null) { text.setText(logBuffer.toString());
text.redraw(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.anno.gui; package org.genesys2.anno.gui;
import org.eclipse.swt.SWT; import java.util.ArrayList;
import org.eclipse.swt.widgets.Composite; import java.util.Collection;
import org.eclipse.swt.widgets.Text; import java.util.Date;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import swing2swt.layout.BorderLayout;
public class LogViewer extends Composite {
private Text txtLogtext;
/**
* Create the composite.
*
* @param parent
* @param style
*/
public LogViewer(Composite parent, int style) {
super(parent, style);
setLayout(new BorderLayout(0, 0));
ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT); /**
toolBar.setLayoutData(BorderLayout.NORTH); * The Class TimedList.
*
* @param <T> the generic type
*/
public class TimedList<T> extends ArrayList<T> {
private static final long serialVersionUID = 2721716147790325499L;
private Date created = null;
ToolItem tltmClear = new ToolItem(toolBar, SWT.NONE); public TimedList() {
tltmClear.setText("Clear"); }
@Override
public void clear() {
created = null;
super.clear();
}
ToolItem tltmSave = new ToolItem(toolBar, SWT.NONE); @Override
tltmSave.setText("Save..."); 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); @Override
txtLogtext.setLayoutData(BorderLayout.CENTER); 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 @Override
protected void checkSubclass() { public boolean addAll(int index, Collection<? extends T> c) {
// Disable the check that prevents subclassing of SWT components 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 { ...@@ -54,21 +54,22 @@ public class MsAccessRowReader implements RowReader {
this.db = DatabaseBuilder.open(sourceFile); this.db = DatabaseBuilder.open(sourceFile);
_log.debug("CHARSET: " + db.getCharset()); _log.debug("CHARSET: " + db.getCharset());
this.table = db.getTable(sheetName); 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 /// This is called in case data starts beyond 1st row
@Override @Override
public void setSkipRows(int skipRows) { 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(); cursor.reset();
// try { try {
// cursor.moveNextRows(skipRows); cursor.moveNextRows(skipRows - 1);
// } catch (IOException e) { } catch (IOException e) {
// _log.error("Could not skip rows", e); _log.error("Could not skip rows", e);
// } }
} }
@Override @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