|
22 | 22 | import java.nio.file.Paths; |
23 | 23 | import java.util.ArrayList; |
24 | 24 | import java.util.Collection; |
| 25 | +import java.util.Collections; |
25 | 26 | import java.util.HashSet; |
26 | 27 | import java.util.LinkedList; |
27 | 28 | import java.util.List; |
@@ -419,16 +420,14 @@ private void init() { |
419 | 420 | structurePanel.getSeveralAssignments().addAll(severalAssignments); |
420 | 421 |
|
421 | 422 | structurePanel.show(); |
422 | | - structurePanel.getSelectedLogicalNode().setSelected(true); |
423 | | - structurePanel.getSelectedPhysicalNode().setSelected(true); |
424 | 423 | metadataPanel.showLogical(getSelectedStructure()); |
425 | 424 | metadataPanel.showPhysical(getSelectedPhysicalDivision()); |
426 | 425 | galleryPanel.setGalleryViewMode(GalleryViewMode.getByName(user.getDefaultGalleryViewMode()).name()); |
427 | 426 | galleryPanel.show(); |
428 | 427 | paginationPanel.show(); |
429 | | - |
430 | 428 | editPagesDialog.prepare(); |
431 | 429 | updateNumberOfScans(); |
| 430 | + updateToDefaultSelection(); |
432 | 431 |
|
433 | 432 | if (logger.isTraceEnabled()) { |
434 | 433 | logger.trace("Initializing editor beans took {} ms", |
@@ -633,7 +632,7 @@ public void deleteStructure() { |
633 | 632 | * clicked on the context menu entry to delete the physical division. |
634 | 633 | */ |
635 | 634 | public void deletePhysicalDivision() { |
636 | | - structurePanel.deleteSelectedPhysicalDivision(); |
| 635 | + structurePanel.deleteSelectedPhysicalDivisions(); |
637 | 636 | updateNumberOfScans(); |
638 | 637 | } |
639 | 638 |
|
@@ -876,94 +875,80 @@ public boolean isSelected(PhysicalDivision physicalDivision, LogicalDivision log |
876 | 875 | return false; |
877 | 876 | } |
878 | 877 |
|
879 | | - void switchStructure(Object treeNodeData, boolean updateGalleryAndPhysicalTree) throws NoSuchMetadataFieldException { |
| 878 | + /** |
| 879 | + * Select first logical division when opening data editor. |
| 880 | + */ |
| 881 | + public void updateToDefaultSelection() { |
| 882 | + TreeNode firstSelectedLogicalNode = getStructurePanel().getLogicalTree().getChildren().get( |
| 883 | + getStructurePanel().getLogicalTree().getChildCount() - 1 |
| 884 | + ); |
880 | 885 | try { |
881 | | - metadataPanel.preserveLogical(); |
882 | | - } catch (InvalidMetadataValueException e) { |
883 | | - logger.info(e.getLocalizedMessage(), e); |
884 | | - } |
885 | | - |
886 | | - Optional<LogicalDivision> selectedStructure = structurePanel.getSelectedStructure(); |
887 | | - |
888 | | - metadataPanel.showLogical(selectedStructure); |
889 | | - if (treeNodeData instanceof StructureTreeNode) { |
890 | | - StructureTreeNode structureTreeNode = (StructureTreeNode) treeNodeData; |
891 | | - if (Objects.nonNull(structureTreeNode.getDataObject())) { |
892 | | - if (structureTreeNode.getDataObject() instanceof LogicalDivision |
893 | | - && selectedStructure.isPresent()) { |
894 | | - // Logical structure element selected |
895 | | - if (structurePanel.isSeparateMedia()) { |
896 | | - LogicalDivision structuralElement = selectedStructure.get(); |
897 | | - if (!structuralElement.getViews().isEmpty()) { |
898 | | - ArrayList<View> views = new ArrayList<>(structuralElement.getViews()); |
899 | | - if (Objects.nonNull(views.get(0)) && updateGalleryAndPhysicalTree) { |
900 | | - updatePhysicalStructureTree(views.get(0)); |
901 | | - updateGallery(views.get(0)); |
902 | | - } |
903 | | - } else { |
904 | | - updatePhysicalStructureTree(null); |
905 | | - } |
906 | | - } else { |
907 | | - getSelectedMedia().clear(); |
908 | | - } |
909 | | - } else if (structureTreeNode.getDataObject() instanceof View) { |
910 | | - View view = (View) structureTreeNode.getDataObject(); |
911 | | - if (view.getPhysicalDivision().hasMediaPartial()) { |
912 | | - View mediaView = DataEditorService.getViewOfBaseMediaByMediaFiles(structurePanel.getLogicalTree().getChildren(), |
913 | | - view.getPhysicalDivision().getMediaFiles()); |
914 | | - if (Objects.nonNull(mediaView)) { |
915 | | - view = mediaView; |
916 | | - } |
917 | | - } |
918 | | - |
919 | | - metadataPanel.showPageInLogical(view.getPhysicalDivision()); |
920 | | - if (updateGalleryAndPhysicalTree) { |
921 | | - updateGallery(view); |
922 | | - } |
923 | | - // no need to update physical tree because pages can only be clicked in logical tree if physical tree is hidden! |
924 | | - } |
925 | | - } |
| 886 | + updateSelection( |
| 887 | + Collections.emptyList(), |
| 888 | + Collections.singletonList(StructureTreeOperations.getLogicalDivisionFromTreeNode(firstSelectedLogicalNode)) |
| 889 | + ); |
| 890 | + } catch (NoSuchMetadataFieldException e) { |
| 891 | + logger.error("exception updating to default selection", e); |
926 | 892 | } |
927 | | - paginationPanel.preparePaginationSelectionSelectedItems(); |
928 | 893 | } |
929 | 894 |
|
930 | | - |
931 | | - |
932 | | - void switchPhysicalDivision() throws NoSuchMetadataFieldException { |
| 895 | + /** |
| 896 | + * Update the current selection in the metadata editor by dispatching update events to structure trees, |
| 897 | + * gallery and pagination panel. |
| 898 | + * |
| 899 | + * @param selectedPhysicalDivisions the list of selected physical divisions (and their parent logical divisions) |
| 900 | + * @param selectedLogicalDivisions the list of selected logical divisions |
| 901 | + * @throws NoSuchMetadataFieldException exception in case metadata can not be saved correctly |
| 902 | + */ |
| 903 | + public void updateSelection( |
| 904 | + List<Pair<PhysicalDivision, LogicalDivision>> selectedPhysicalDivisions, |
| 905 | + List<LogicalDivision> selectedLogicalDivisions |
| 906 | + ) throws NoSuchMetadataFieldException { |
933 | 907 | try { |
934 | | - metadataPanel.preservePhysical(); |
| 908 | + // save previously edited meta data |
| 909 | + getMetadataPanel().preserveLogical(); |
935 | 910 | } catch (InvalidMetadataValueException e) { |
936 | 911 | logger.info(e.getLocalizedMessage(), e); |
937 | 912 | } |
938 | 913 |
|
939 | | - Optional<PhysicalDivision> selectedPhysicalDivision = structurePanel.getSelectedPhysicalDivision(); |
940 | | - |
941 | | - metadataPanel.showPhysical(selectedPhysicalDivision); |
942 | | - if (selectedPhysicalDivision.isPresent()) { |
943 | | - // update gallery |
944 | | - galleryPanel.updateSelection(selectedPhysicalDivision.get(), null); |
945 | | - // update logical tree |
946 | | - for (GalleryMediaContent galleryMediaContent : galleryPanel.getMedias()) { |
947 | | - if (Objects.nonNull(galleryMediaContent.getView()) |
948 | | - && Objects.equals(selectedPhysicalDivision.get(), galleryMediaContent.getView().getPhysicalDivision())) { |
949 | | - structurePanel.updateLogicalNodeSelection(galleryMediaContent, null); |
950 | | - break; |
951 | | - } |
| 914 | + // update data editor selection (used e.g. in gallery) |
| 915 | + getSelectedMedia().clear(); |
| 916 | + getSelectedMedia().addAll(selectedPhysicalDivisions); |
| 917 | + |
| 918 | + // update logical metadata panel |
| 919 | + if (!getStructurePanel().isSeparateMedia() && selectedPhysicalDivisions.size() == 1 |
| 920 | + && selectedLogicalDivisions.isEmpty()) { |
| 921 | + // show physical division in logical metadata panel in combined meta data mode |
| 922 | + getMetadataPanel().showPageInLogical(selectedPhysicalDivisions.get(0).getLeft()); |
| 923 | + } else if (selectedLogicalDivisions.size() == 1 && selectedPhysicalDivisions.isEmpty()) { |
| 924 | + // show logical division in logical metadata panel |
| 925 | + getMetadataPanel().showLogical(Optional.of(selectedLogicalDivisions.get(0))); |
| 926 | + } else { |
| 927 | + // show nothing in logical metadata panel |
| 928 | + getMetadataPanel().showPageInLogical(null); |
| 929 | + } |
| 930 | + |
| 931 | + // update physical metadata panel |
| 932 | + if (getStructurePanel().isSeparateMedia()) { |
| 933 | + if (selectedPhysicalDivisions.size() == 1) { |
| 934 | + // show physical division in physical metadata panel |
| 935 | + getMetadataPanel().showPhysical(Optional.of(selectedPhysicalDivisions.get(0).getLeft())); |
| 936 | + } else { |
| 937 | + // show nothing in physical metadata panel |
| 938 | + getMetadataPanel().showPhysical(Optional.empty()); |
952 | 939 | } |
953 | 940 | } |
954 | | - } |
955 | 941 |
|
956 | | - private void updatePhysicalStructureTree(View view) { |
957 | | - GalleryMediaContent galleryMediaContent = this.galleryPanel.getGalleryMediaContent(view); |
958 | | - structurePanel.updatePhysicalNodeSelection(galleryMediaContent); |
| 942 | + // update structure trees |
| 943 | + getStructurePanel().updateNodeSelection( |
| 944 | + selectedPhysicalDivisions, |
| 945 | + selectedLogicalDivisions |
| 946 | + ); |
| 947 | + |
| 948 | + // update pagination panel |
| 949 | + getPaginationPanel().preparePaginationSelectionSelectedItems(); |
959 | 950 | } |
960 | 951 |
|
961 | | - private void updateGallery(View view) { |
962 | | - PhysicalDivision physicalDivision = view.getPhysicalDivision(); |
963 | | - if (Objects.nonNull(physicalDivision)) { |
964 | | - galleryPanel.updateSelection(physicalDivision, structurePanel.getPageStructure(view, workpiece.getLogicalStructure())); |
965 | | - } |
966 | | - } |
967 | 952 |
|
968 | 953 | void assignView(LogicalDivision logicalDivision, View view, Integer index) { |
969 | 954 | if (Objects.nonNull(index) && index >= 0 && index < logicalDivision.getViews().size()) { |
@@ -1317,7 +1302,7 @@ public String getMetadataFileLoadingError() { |
1317 | 1302 | */ |
1318 | 1303 | public boolean canUpdateMetadata() { |
1319 | 1304 | try { |
1320 | | - return DataEditorService.canUpdateCatalogMetadata(process, workpiece, structurePanel.getSelectedLogicalNode()); |
| 1305 | + return DataEditorService.canUpdateCatalogMetadata(process, workpiece, structurePanel.getSelectedLogicalNodeIfSingle()); |
1321 | 1306 | } catch (IOException e) { |
1322 | 1307 | Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); |
1323 | 1308 | return false; |
|
0 commit comments