Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
#278: handle UserDocListLoad- & HtrListLoad- apart from DocListLoadEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlep committed Apr 15, 2019
1 parent 8c80c1c commit 9cff6df
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public void widgetDisposed(DisposeEvent e) {

void addListener() {
storageListener = new IStorageListener() {
@Override public void handleDocListLoadEvent(DocListLoadEvent e) {
if (!e.isDocsByUser)
return;

@Override public void handleUserDocListLoadEvent(UserDocListLoadEvent e) {
Display.getDefault().asyncExec(() -> {
if (SWTUtil.isDisposed(MyDocsTableWidgetPagination.this))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class ServerWidgetListener extends SelectionAdapter implements Listener,
Storage storage = Storage.getInstance();
DocumentManager ac;

/**
* Counts all DocListLoadEvents until the collection is changed.
*/
private int docListLoadEventCounter = 0;

public ServerWidgetListener(ServerWidget sw) {
this.sw = sw;
this.dtv = sw.getTableViewer();
Expand Down Expand Up @@ -164,6 +169,19 @@ public void detach() {
TrpMainWidget.getInstance().loadMostRecentDoc();
}
}

@Override public void handleDocListLoadEvent(DocListLoadEvent e) {
if(e.isCollectionChange) {
logger.debug("Collection changed to ID = " + e.collId);
docListLoadEventCounter = 0;
}
logger.debug("Handling DocListLoadEvent #" + ++docListLoadEventCounter + " in collection " + e.collId + " sent by " + e.getSource());
sw.refreshDocListFromStorage();
}

@Override public void handleHtrListLoadEvent(HtrListLoadEvent e) {
sw.updateGroundTruthTreeViewer();
}

@Override public void doubleClick(DoubleClickEvent event) {
TrpMainWidget mw = TrpMainWidget.getInstance();
Expand Down Expand Up @@ -327,14 +345,7 @@ public void handleEvent(Event event) {
//need to empty document list filter when loading of new collection happened
sw.docTableWidget.clearFilter();

/*
* otherwise loading a new collection gets stuck with the old collection due to this check:
* DocTableWidgetPagination, line 228: forceReload || collectionId != store.getCollId()
* but changing this may has effects on some other parts
*/

sw.refreshDocListFromStorage();

//switch collections and load documents from the server, which sends out DocListLoadEvent triggering UI updates in IStorageListener impls
Future<List<TrpDocMetadata>> docs = TrpMainWidget.getInstance().reloadDocList(sw.getSelectedCollectionId());

//unload currently loaded remote document (if any) on collection change
Expand All @@ -347,9 +358,7 @@ public void handleEvent(Event event) {
if (ac != null && !ac.getShell().isDisposed() && ac.getShell().isVisible()){
ac.totalReload(sw.getSelectedCollectionId());
}




//last and least: the role of a user in this collection must be taken into account for visibility of buttons, tabs, tools,...
TrpMainWidget.getInstance().getUi().updateVisibility();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,26 @@ void detach() {
@Override public void handleCollectionsLoadEvent(CollectionsLoadEvent cle) {
}

@Override public void handleUserDocListLoadEvent(UserDocListLoadEvent e) {
if (SWTUtil.isOpen(mw.strayDocsDialog)){
mw.strayDocsDialog.refreshDocList();
}
}

@Override public void handleDocListLoadEvent(DocListLoadEvent e) {
if(e.isCollectionChange) {
logger.debug("Collection changed to ID = " + e.collId);
docListLoadEventCounter = 0;
}
logger.debug("Handling DocListLoadEvent #" + ++docListLoadEventCounter + " in collection " + e.collId + ": " + e);

if (e.isDocsByUser){
if (SWTUtil.isOpen(mw.strayDocsDialog)){
mw.strayDocsDialog.refreshDocList();
}
logger.debug("Handling DocListLoadEvent #" + ++docListLoadEventCounter + " in collection " + e.collId + " sent by " + e.getSource());
if (mw.recycleBinDiag != null){
mw.recycleBinDiag.getDocTableWidget().refreshList(mw.getSelectedCollectionId());
}
else{
ui.getServerWidget().refreshDocListFromStorage();
if (mw.recycleBinDiag != null){
mw.recycleBinDiag.getDocTableWidget().refreshList(mw.getSelectedCollectionId());
}
if(e.isCollectionChange) {
//force a reload of the HTR model list only if collection has changed
storage.reloadHtrs();
} else {
logger.debug("Omitting reload of HTR list as collection has not changed.");
}
mw.getUi().getServerWidget().updateGroundTruthTreeViewer();
if(e.isCollectionChange) {
//force a reload of the HTR model list only if collection has changed
storage.reloadHtrs();
} else {
logger.debug("Omitting reload of HTR list as collection has not changed.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import eu.transkribus.core.model.beans.TrpCollection;
import eu.transkribus.core.model.beans.TrpDoc;
import eu.transkribus.core.model.beans.TrpDocMetadata;
import eu.transkribus.core.model.beans.TrpHtr;
import eu.transkribus.core.model.beans.TrpPage;
import eu.transkribus.core.model.beans.TrpTranscriptMetadata;
import eu.transkribus.core.model.beans.auth.TrpUserLogin;
Expand Down Expand Up @@ -42,6 +43,10 @@ default void handleDocMetadataUpdateEvent(DocMetadataUpdateEvent e) {}

default void handleDocListLoadEvent(DocListLoadEvent e) {}

default void handleUserDocListLoadEvent(UserDocListLoadEvent e) {}

default void handleHtrListLoadEvent(HtrListLoadEvent e) {}

default void handlTagSpecsChangedEvent(TagSpecsChangedEvent e) {}

default void handlStructTagSpecsChangedEvent(StructTagSpecsChangedEvent e) {}
Expand Down Expand Up @@ -83,6 +88,12 @@ else if (event instanceof MainImageLoadEvent) {
else if (event instanceof DocListLoadEvent) {
handleDocListLoadEvent((DocListLoadEvent) event);
}
else if (event instanceof UserDocListLoadEvent) {
handleUserDocListLoadEvent((UserDocListLoadEvent) event);
}
else if (event instanceof HtrListLoadEvent) {
handleHtrListLoadEvent((HtrListLoadEvent) event);
}
else if (event instanceof TagSpecsChangedEvent) {
handlTagSpecsChangedEvent((TagSpecsChangedEvent) event);
}
Expand Down Expand Up @@ -160,23 +171,41 @@ public GroundTruthLoadEvent(Object source, TrpDoc doc) {
public static class DocListLoadEvent extends Event {
public final int collId;
public final List<TrpDocMetadata> docs;
// public final int collId;
// public final TrpUserLogin user;
public final boolean isDocsByUser;
/**
* true if this DocListLoadEvent was sent during a collection change
*/
public final boolean isCollectionChange;

public DocListLoadEvent(Object source, int collId, List<TrpDocMetadata> docs, boolean isDocsByUser, boolean isCollectionChange) {
public DocListLoadEvent(Object source, int collId, List<TrpDocMetadata> docs, boolean isCollectionChange) {
super(source, docs.size()+" documents loaded from collection "+collId);
this.collId = collId;
this.docs = docs;
this.isDocsByUser = isDocsByUser;
this.isCollectionChange = isCollectionChange;
}
}

@SuppressWarnings("serial")
public static class UserDocListLoadEvent extends Event {
public final List<TrpDocMetadata> docs;

public UserDocListLoadEvent(Object source, List<TrpDocMetadata> docs) {
super(source, docs.size()+" user documents loaded from collection");
this.docs = docs;
}
}

@SuppressWarnings("serial")
public static class HtrListLoadEvent extends Event {
public final int collId;
public final List<TrpHtr> htrs;

public HtrListLoadEvent(Object source, int collId, List<TrpHtr> htrs) {
super(source, htrs.size() + " HTRs loaded for collection " + collId);
this.collId = collId;
this.htrs = htrs;
}
}

@SuppressWarnings("serial")
public static class MainImageLoadEvent extends Event {
public final CanvasImage image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.DocLoadEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.DocMetadataUpdateEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.GroundTruthLoadEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.HtrListLoadEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.JobUpdateEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.LoginOrLogoutEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.MainImageLoadEvent;
Expand All @@ -147,6 +148,7 @@
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.TranscriptListLoadEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.TranscriptLoadEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.TranscriptSaveEvent;
import eu.transkribus.swt_gui.mainwidget.storage.IStorageListener.UserDocListLoadEvent;
import eu.transkribus.swt_gui.metadata.CustomTagSpec;
import eu.transkribus.swt_gui.metadata.CustomTagSpecDBUtil;
import eu.transkribus.swt_gui.metadata.CustomTagSpecUtil;
Expand Down Expand Up @@ -870,14 +872,14 @@ public void reloadUserDocs() {
userDocList.clear();
userDocList.addAll(response);

sendEvent(new DocListLoadEvent(this, 0, userDocList, true, false));
sendEvent(new UserDocListLoadEvent(this, userDocList));
}
}
});
} else {
synchronized (this) {
userDocList.clear();
sendEvent(new DocListLoadEvent(this, 0, userDocList, true, false));
sendEvent(new UserDocListLoadEvent(this, userDocList));
}
}
}
Expand Down Expand Up @@ -921,7 +923,7 @@ public void completed(List<TrpDocMetadata> docs) {
logger.debug("async loaded "+docList.size()+" nr of docs of collection "+collId+" thread: "+Thread.currentThread().getName());
SebisStopWatch.SW.stop(true, "load time: ", logger);

sendEvent(new DocListLoadEvent(this, colId, docList, false, isCollectionChange));
sendEvent(new DocListLoadEvent(this, colId, docList, isCollectionChange));
}

@Override public void failed(Throwable throwable) {
Expand Down Expand Up @@ -2463,6 +2465,7 @@ public void reloadHtrs() {
logger.error("Error loading HTR models: " + e.getMessage(), e);
htrList.clear();
}
sendEvent(new HtrListLoadEvent(this, this.getCollId(), htrList));
}

public List<TrpHtr> getHtrs(String provider) {
Expand Down

0 comments on commit 9cff6df

Please sign in to comment.