From 9cff6dfe20760aa61909f4fc2cf88089945f21c8 Mon Sep 17 00:00:00 2001 From: kahlep Date: Mon, 15 Apr 2019 17:16:42 +0200 Subject: [PATCH] #278: handle UserDocListLoad- & HtrListLoad- apart from DocListLoadEvent --- .../MyDocsTableWidgetPagination.java | 5 +-- .../doc_overview/ServerWidgetListener.java | 31 +++++++++------ .../TrpMainWidgetStorageListener.java | 32 +++++++-------- .../mainwidget/storage/IStorageListener.java | 39 ++++++++++++++++--- .../swt_gui/mainwidget/storage/Storage.java | 9 +++-- 5 files changed, 75 insertions(+), 41 deletions(-) diff --git a/src/main/java/eu/transkribus/swt_gui/doc_overview/MyDocsTableWidgetPagination.java b/src/main/java/eu/transkribus/swt_gui/doc_overview/MyDocsTableWidgetPagination.java index 83152897f..53d3f8c89 100644 --- a/src/main/java/eu/transkribus/swt_gui/doc_overview/MyDocsTableWidgetPagination.java +++ b/src/main/java/eu/transkribus/swt_gui/doc_overview/MyDocsTableWidgetPagination.java @@ -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; diff --git a/src/main/java/eu/transkribus/swt_gui/doc_overview/ServerWidgetListener.java b/src/main/java/eu/transkribus/swt_gui/doc_overview/ServerWidgetListener.java index e19d123a3..1aa536a70 100644 --- a/src/main/java/eu/transkribus/swt_gui/doc_overview/ServerWidgetListener.java +++ b/src/main/java/eu/transkribus/swt_gui/doc_overview/ServerWidgetListener.java @@ -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(); @@ -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(); @@ -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> docs = TrpMainWidget.getInstance().reloadDocList(sw.getSelectedCollectionId()); //unload currently loaded remote document (if any) on collection change @@ -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(); } diff --git a/src/main/java/eu/transkribus/swt_gui/mainwidget/TrpMainWidgetStorageListener.java b/src/main/java/eu/transkribus/swt_gui/mainwidget/TrpMainWidgetStorageListener.java index 7efc1e3e3..ee2b1c734 100644 --- a/src/main/java/eu/transkribus/swt_gui/mainwidget/TrpMainWidgetStorageListener.java +++ b/src/main/java/eu/transkribus/swt_gui/mainwidget/TrpMainWidgetStorageListener.java @@ -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."); } } diff --git a/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/IStorageListener.java b/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/IStorageListener.java index 62cd6ab28..306e7624d 100644 --- a/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/IStorageListener.java +++ b/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/IStorageListener.java @@ -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; @@ -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) {} @@ -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); } @@ -160,23 +171,41 @@ public GroundTruthLoadEvent(Object source, TrpDoc doc) { public static class DocListLoadEvent extends Event { public final int collId; public final List 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 docs, boolean isDocsByUser, boolean isCollectionChange) { + public DocListLoadEvent(Object source, int collId, List 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 docs; + + public UserDocListLoadEvent(Object source, List 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 htrs; + + public HtrListLoadEvent(Object source, int collId, List 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; diff --git a/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/Storage.java b/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/Storage.java index 4892baf03..3852a2997 100644 --- a/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/Storage.java +++ b/src/main/java/eu/transkribus/swt_gui/mainwidget/storage/Storage.java @@ -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; @@ -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; @@ -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)); } } } @@ -921,7 +923,7 @@ public void completed(List 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) { @@ -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 getHtrs(String provider) {