From 85fd84d18ace66f4c675ea7c0e07db794ebf3c96 Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Mon, 11 Sep 2023 21:52:46 +0100 Subject: [PATCH] Fix binned output couple of fixes in binned output --- src/tethys/TethysControl.java | 11 +++--- .../detection/BinnedGranularityHandler.java | 3 +- src/tethys/pamdata/TethysParameterPacker.java | 35 ++++++++++--------- .../swing/DatablockDetectionsPanel.java | 25 +++++++++++-- .../swing/PAMGuardDeploymentsTable.java | 2 +- 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/tethys/TethysControl.java b/src/tethys/TethysControl.java index c5f26031..637f4bcb 100644 --- a/src/tethys/TethysControl.java +++ b/src/tethys/TethysControl.java @@ -596,17 +596,20 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet PamFileFilter fileFilter = new PamFileFilter("XML documents", ".xml"); // fileFilter - JFileChooser fileChooser = new PamFileChooser(); + JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(fileFilter); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); // make a default name based on the document id and the dataset directory. String defFolder = PamFolders.getDefaultProjectFolder(); + File defFile = null; if (defFolder != null) { - defFolder = String.format("%s%s%s.xml", defFolder,File.separator,documentId); - File defFile = new File(defFolder); - fileChooser.setSelectedFile(defFile); + defFolder = String.format("%s%s%s_%s.xml", defFolder,File.separator,collection,documentId); + defFile = new File(defFolder); fileChooser.setAcceptAllFileFilterUsed(true); + fileChooser.setSelectedFile(defFile); +// fileChooser.setSelectedFile(new File(String.format("%s.xml", documentId))); +// fileChooser.set } int state = fileChooser.showSaveDialog(getGuiFrame()); if (state != JFileChooser.APPROVE_OPTION) return; diff --git a/src/tethys/detection/BinnedGranularityHandler.java b/src/tethys/detection/BinnedGranularityHandler.java index b39f4550..056fc092 100644 --- a/src/tethys/detection/BinnedGranularityHandler.java +++ b/src/tethys/detection/BinnedGranularityHandler.java @@ -88,6 +88,7 @@ public class BinnedGranularityHandler extends GranularityHandler { Detection[] detections = null; if (dataUnit.getTimeMilliseconds() >= binEndMillis) { detections = closeBins(dataUnit.getTimeMilliseconds()); + prepare(dataUnit.getTimeMilliseconds()); } String speciesCode = speciesManager.getSpeciesCode(dataUnit); Detection det = currentDetections.get(speciesCode); @@ -140,8 +141,6 @@ public class BinnedGranularityHandler extends GranularityHandler { } - // finally, start new bins (not really needed on last call, but do anyway). - startBin(binEndMillis); /* * Clean up the end of the array and return detections that have enough calls. diff --git a/src/tethys/pamdata/TethysParameterPacker.java b/src/tethys/pamdata/TethysParameterPacker.java index b663db20..c4c7e6f7 100644 --- a/src/tethys/pamdata/TethysParameterPacker.java +++ b/src/tethys/pamdata/TethysParameterPacker.java @@ -132,26 +132,29 @@ public class TethysParameterPacker { * first do the data filter. I can't see any way of doing this * without creating a doc as was in the helper example. */ - QName qnamef = new QName(MarshalXML.schema, "datafilter", "ty"); - JAXBElement jaxelf = new JAXBElement( - qnamef, String.class, parameterSet.getParentObject().getClass().getCanonicalName()); - Document docf = null; - try { - docf = marshaller.marshalToDOM(jaxelf); - } catch (JAXBException | ParserConfigurationException e1) { - e1.printStackTrace(); - } - Element elf = docf.getDocumentElement(); - elList.add(elf);/** - * Is there a data filter ? If so, write it's - * XML parameters out here. - */ DataSelector dataSelector = pamDataBlock.getDataSelector(tethysControl.getDataSelectName(), false); if (dataSelector != null) { DataSelectParams filterParams = dataSelector.getParams(); if (filterParams != null) { - Element pEl = xmlWriter.writeObjectData(docf, elf, filterParams, null); -// if (pEl != null) { + int selected = filterParams.getCombinationFlag(); + if (selected != DataSelectParams.DATA_SELECT_DISABLE) { + QName qnamef = new QName(MarshalXML.schema, "datafilter", "ty"); + JAXBElement jaxelf = new JAXBElement( + qnamef, String.class, parameterSet.getParentObject().getClass().getCanonicalName()); + Document docf = null; + try { + docf = marshaller.marshalToDOM(jaxelf); + } catch (JAXBException | ParserConfigurationException e1) { + e1.printStackTrace(); + } + Element elf = docf.getDocumentElement(); + elList.add(elf);/** + * Is there a data filter ? If so, write it's + * XML parameters out here. + */ + Element pEl = xmlWriter.writeObjectData(docf, elf, filterParams, null); + } + // if (pEl != null) { //// filterEl.appendChild(pEl); // elf.appendChild(filterEl); // } diff --git a/src/tethys/swing/DatablockDetectionsPanel.java b/src/tethys/swing/DatablockDetectionsPanel.java index dfa0c2cc..1decb0fd 100644 --- a/src/tethys/swing/DatablockDetectionsPanel.java +++ b/src/tethys/swing/DatablockDetectionsPanel.java @@ -17,6 +17,8 @@ import javax.swing.JTable; import javax.swing.border.TitledBorder; import javax.swing.table.AbstractTableModel; +import PamView.PamGui; +import PamView.dialog.warn.WarnOnce; import PamView.tables.SwingTableColumnWidths; import PamguardMVC.PamDataBlock; import nilus.DetectionEffortKind; @@ -120,7 +122,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa JPopupMenu popMenu = new JPopupMenu(); - JMenuItem menuItem = new JMenuItem("Delete " + pDets.detections.getId()); + JMenuItem menuItem = new JMenuItem("Delete document " + pDets.detections.getId()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -129,7 +131,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa }); popMenu.add(menuItem); - menuItem = new JMenuItem("Display " + pDets.detections.getId()); + menuItem = new JMenuItem("Display document " + pDets.detections.getId()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -138,6 +140,15 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa }); popMenu.add(menuItem); + menuItem = new JMenuItem("Export document " + pDets.detections.getId()); + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + exportDocument(pDets); + } + }); + popMenu.add(menuItem); + popMenu.show(e.getComponent(), e.getX(), e.getY()); @@ -145,6 +156,11 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa } protected void deleteDocument(PDetections pDets) { + String msg = String.format("Are you sure you want to delete the Detections document %s ?", pDets.detections.getId()); + int ans = WarnOnce.showWarning(PamGui.findComponentWindow(mainPanel), "Delete Document", msg, WarnOnce.OK_CANCEL_OPTION); + if (ans != WarnOnce.OK_OPTION) { + return; + } try { getTethysControl().getDbxmlConnect().deleteDocument(pDets.detections); } catch (TethysException e) { @@ -159,6 +175,11 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa } + private void exportDocument(PDetections pDets) { + getTethysControl().exportDocument(TethysCollections.Detections.toString(), pDets.detections.getId()); + + } + private PDetections detectionsForRow(int iRow) { if (streamDetectionsSummary == null || streamDetectionsSummary.detectionsDocs == null) { return null; diff --git a/src/tethys/swing/PAMGuardDeploymentsTable.java b/src/tethys/swing/PAMGuardDeploymentsTable.java index d17a659d..688c949b 100644 --- a/src/tethys/swing/PAMGuardDeploymentsTable.java +++ b/src/tethys/swing/PAMGuardDeploymentsTable.java @@ -134,7 +134,7 @@ public class PAMGuardDeploymentsTable extends TethysGUIPanel { } if (matchedDeployments.size() == 1) { JPopupMenu popMenu = new JPopupMenu(); - JMenuItem menuItem = new JMenuItem("Remove deployment document " + matchedDeployments.get(0)); + JMenuItem menuItem = new JMenuItem("Delete deployment document " + matchedDeployments.get(0)); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {