Update Calibration export

Stop repeating hydrophones and add two addresses to Calibrations docs
This commit is contained in:
Douglas Gillespie 2023-12-07 20:08:17 +00:00
parent 9c86b41027
commit 860d1bec17
5 changed files with 134 additions and 71 deletions

View File

@ -45,6 +45,7 @@ import tethys.TethysTimeFuncs;
import tethys.calibration.swing.CalibrationsExportWizard; import tethys.calibration.swing.CalibrationsExportWizard;
import tethys.dbxml.DBXMLConnect; import tethys.dbxml.DBXMLConnect;
import tethys.dbxml.TethysException; import tethys.dbxml.TethysException;
import tethys.niluswraps.NilusSettingsWrapper;
import tethys.niluswraps.NilusUnpacker; import tethys.niluswraps.NilusUnpacker;
import tethys.pamdata.AutoTethysProvider; import tethys.pamdata.AutoTethysProvider;
@ -176,6 +177,9 @@ public class CalibrationHandler implements TethysStateObserver {
return 0; return 0;
} }
NilusSettingsWrapper<Calibration> wrappedSample = new NilusSettingsWrapper<Calibration>();
wrappedSample.setNilusObject(sampleCal);
PamArray array = ArrayManager.getArrayManager().getCurrentArray(); PamArray array = ArrayManager.getArrayManager().getCurrentArray();
int nPhone = array.getHydrophoneCount(); int nPhone = array.getHydrophoneCount();
DBXMLConnect dbxml = tethysControl.getDbxmlConnect(); DBXMLConnect dbxml = tethysControl.getDbxmlConnect();
@ -184,6 +188,8 @@ public class CalibrationHandler implements TethysStateObserver {
boolean exists; boolean exists;
for (int i = 0; i < nPhone; i++) { for (int i = 0; i < nPhone; i++) {
// String docName = getHydrophoneId(i); // String docName = getHydrophoneId(i);
NilusSettingsWrapper<Calibration> clonedWrap = wrappedSample.clone();
sampleCal = clonedWrap.getNilusObject(Calibration.class);
Calibration calDoc = createCalibrationDocument(i); Calibration calDoc = createCalibrationDocument(i);
if (sampleCal != null) { if (sampleCal != null) {
calDoc.setMetadataInfo(sampleCal.getMetadataInfo()); calDoc.setMetadataInfo(sampleCal.getMetadataInfo());

View File

@ -16,6 +16,7 @@ import javax.swing.JTextField;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import PamView.dialog.PamGridBagContraints; import PamView.dialog.PamGridBagContraints;
import PamView.panel.WestAlignedPanel;
import PamView.wizard.PamWizard; import PamView.wizard.PamWizard;
import nilus.AlgorithmType; import nilus.AlgorithmType;
import nilus.AlgorithmType.Parameters; import nilus.AlgorithmType.Parameters;
@ -43,8 +44,10 @@ public class CalibrationProcessCard extends CalibrationsCard {
super(pamWizard, "Calibration Process"); super(pamWizard, "Calibration Process");
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
processPanel = new JPanel(new GridBagLayout()); processPanel = new JPanel(new GridBagLayout());
processPanel.setBorder(new TitledBorder("Calibration Process")); WestAlignedPanel wp;
this.add(BorderLayout.NORTH, processPanel); this.add(BorderLayout.NORTH, wp = new WestAlignedPanel(processPanel));
wp.setBorder(new TitledBorder("Calibration Process"));
GridBagConstraints c = new PamGridBagContraints(); GridBagConstraints c = new PamGridBagContraints();
calMethod = new JComboBox<String>(); calMethod = new JComboBox<String>();

View File

@ -7,6 +7,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Date; import java.util.Date;
import javax.swing.BoxLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JLabel; import javax.swing.JLabel;
@ -19,6 +20,7 @@ import org.jdesktop.swingx.JXDatePicker;
import PamView.dialog.PamDialog; import PamView.dialog.PamDialog;
import PamView.dialog.PamGridBagContraints; import PamView.dialog.PamGridBagContraints;
import PamView.panel.WestAlignedPanel;
import PamView.wizard.PamWizard; import PamView.wizard.PamWizard;
import nilus.Calibration; import nilus.Calibration;
import nilus.ContactInfo; import nilus.ContactInfo;
@ -26,20 +28,25 @@ import nilus.MetadataInfo;
import nilus.ResponsibleParty; import nilus.ResponsibleParty;
import tethys.TethysTimeFuncs; import tethys.TethysTimeFuncs;
import tethys.calibration.CalibrationHandler; import tethys.calibration.CalibrationHandler;
import tethys.swing.export.ResponsiblePartyPanel;
public class CalibrationsContactCard extends CalibrationsCard { public class CalibrationsContactCard extends CalibrationsCard {
private JXDatePicker datePicker; private JXDatePicker datePicker;
private JTextField individual, organisation, position, email; private ResponsiblePartyPanel calibrator, dataManager;
private JComboBox<String> updateInterval; private JComboBox<String> updateInterval;
private MetadataInfo metaData;
private JButton copyDown, copyUp;
public CalibrationsContactCard(PamWizard pamWizard) { public CalibrationsContactCard(PamWizard pamWizard) {
super(pamWizard, "Contact Details"); super(pamWizard, "Contact Details");
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
// setBorder(new TitledBorder("Contact")); // setBorder(new TitledBorder("Contact"));
setLayout(new BorderLayout()); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
updateInterval = new JComboBox<>(); updateInterval = new JComboBox<>();
String[] vals = CalibrationHandler.updateOptions; String[] vals = CalibrationHandler.updateOptions;
@ -48,8 +55,8 @@ public class CalibrationsContactCard extends CalibrationsCard {
} }
JPanel datePanel = new JPanel(new GridBagLayout()); JPanel datePanel = new JPanel(new GridBagLayout());
datePanel.setBorder(new TitledBorder("Calibration date")); JPanel lp = new WestAlignedPanel(datePanel);
add(BorderLayout.NORTH, datePanel); lp.setBorder(new TitledBorder("Calibration date"));
GridBagConstraints c = new PamGridBagContraints(); GridBagConstraints c = new PamGridBagContraints();
datePanel.add(new JLabel("Calibration date: ", JLabel.RIGHT), c); datePanel.add(new JLabel("Calibration date: ", JLabel.RIGHT), c);
datePicker = new JXDatePicker(); datePicker = new JXDatePicker();
@ -61,67 +68,66 @@ public class CalibrationsContactCard extends CalibrationsCard {
c.gridx++; c.gridx++;
datePanel.add(updateInterval, c); datePanel.add(updateInterval, c);
calibrator = new ResponsiblePartyPanel("Technical Person");
dataManager = new ResponsiblePartyPanel("Data Manager");
JPanel contactPanel = new JPanel(new GridBagLayout()); JPanel copyPanel = new JPanel(new GridBagLayout());
contactPanel.setBorder(new TitledBorder("Contact"));
this.add(BorderLayout.CENTER, contactPanel);
c = new PamGridBagContraints(); c = new PamGridBagContraints();
contactPanel.add(new JLabel("Individual Name "), c); copyPanel.add(copyDown = new JButton("Copy down"),c);
c.gridx++; c.gridx++;
contactPanel.add(individual = new JTextField(15), c); copyPanel.add(copyUp = new JButton("Copy up"), c);
c.gridx = 0;
c.gridy++; add(lp);
contactPanel.add(new JLabel("Organisation "), c); add(calibrator.getMainPanel());
c.gridx++; add(copyPanel);
contactPanel.add(organisation = new JTextField(15), c); add(dataManager.getMainPanel());
c.gridx = 0;
c.gridy++;
contactPanel.add(new JLabel("Position "), c);
c.gridx++;
contactPanel.add(position = new JTextField(15), c);
c.gridx = 0;
c.gridy++;
contactPanel.add(new JLabel("Email "), c);
c.gridx++;
contactPanel.add(email = new JTextField(15), c);
c.gridx = 0;
c.gridy++;
copyDown.setToolTipText("Copy technical person to data manager");
copyUp.setToolTipText("Copy data manager to technical person");
copyDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
copyRPDown();
}
});
copyUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
copyRPUp();
}
});
}
protected void copyRPDown() {
copyRPData(calibrator, dataManager);
}
private void copyRPUp() {
copyRPData(dataManager, calibrator);
}
private void copyRPData(ResponsiblePartyPanel rFrom, ResponsiblePartyPanel rTo) {
ResponsibleParty rp = checkRPChildren(null);
rFrom.getParams(rp);
rTo.setParams(rp);
} }
@Override @Override
public boolean getParams(Calibration cardParams) { public boolean getParams(Calibration cardParams) {
if (cardParams == null) { ResponsibleParty rp = checkRPChildren(cardParams.getResponsibleParty());
return false; cardParams.setResponsibleParty(rp);
} calibrator.getParams(rp);
MetadataInfo metaInf = cardParams.getMetadataInfo();
if (metaInf == null) {
metaInf = new MetadataInfo();
cardParams.setMetadataInfo(metaInf);
}
ResponsibleParty contact = metaInf.getContact();
if (contact == null) {
contact = new ResponsibleParty();
metaInf.setContact(contact);
}
ContactInfo contactInfo = contact.getContactInfo();
if (contactInfo == null) {
contactInfo = new ContactInfo();
contact.setContactInfo(contactInfo);
}
// so far as I'm aware, the meta info contains the time we create this record metaData = cardParams.getMetadataInfo();
// and the other timestamp is the data the calibration was donw. if (metaData == null) {
metaInf.setDate(TethysTimeFuncs.xmlGregCalFromMillis(System.currentTimeMillis())); metaData = new MetadataInfo();
metaInf.setUpdateFrequency((String) updateInterval.getSelectedItem()); cardParams.setMetadataInfo(metaData);
}
metaData.setContact(checkRPChildren(metaData.getContact()));
dataManager.getParams(metaData.getContact());
contact.setIndividualName(individual.getText()); metaData.setUpdateFrequency((String) updateInterval.getSelectedItem());
contact.setOrganizationName(organisation.getText()); metaData.setDate(TethysTimeFuncs.xmlGregCalFromMillis(System.currentTimeMillis()));
contact.setPositionName(position.getText());
contactInfo.setContactInstructions(email.getText());
// and set this both as the RepsonsiblePArty and in the metadata.
cardParams.setResponsibleParty(contact);
Date date = datePicker.getDate(); Date date = datePicker.getDate();
if (date == null) { if (date == null) {
@ -133,6 +139,19 @@ public class CalibrationsContactCard extends CalibrationsCard {
return true; return true;
} }
private ResponsibleParty checkRPChildren(ResponsibleParty rp) {
if (rp == null) {
rp = new ResponsibleParty();
}
if (rp.getContactInfo() == null) {
rp.setContactInfo(new ContactInfo());
}
if (rp.getContactInfo().getAddress() == null) {
// rp.getContactInfo().setAddress(new Address());
}
return rp;
}
private ResponsibleParty findResponsibleParty(Calibration cal) { private ResponsibleParty findResponsibleParty(Calibration cal) {
if (cal == null) { if (cal == null) {
return null; return null;
@ -151,19 +170,17 @@ public class CalibrationsContactCard extends CalibrationsCard {
@Override @Override
public void setParams(Calibration cardParams) { public void setParams(Calibration cardParams) {
// fill in as much as possible from the existing Calibration // fill in as much as possible from the existing Calibration
ResponsibleParty resp = findResponsibleParty(cardParams); ResponsibleParty resp = cardParams.getResponsibleParty();
if (resp != null) { if (resp != null) {
individual.setText(resp.getIndividualName()); calibrator.setParams(resp);
organisation.setText(resp.getOrganizationName());
position.setText(resp.getPositionName());
ContactInfo cInf = resp.getContactInfo();
if (cInf != null) {
email.setText(cInf.getContactInstructions());
}
} }
MetadataInfo metaInf = cardParams.getMetadataInfo(); MetadataInfo metaInf = cardParams.getMetadataInfo();
if (metaInf != null) { if (metaInf != null) {
resp = metaInf.getContact();
if (resp != null) {
dataManager.getParams(resp);
}
String uf = metaInf.getUpdateFrequency(); String uf = metaInf.getUpdateFrequency();
if (uf != null) { if (uf != null) {
updateInterval.setSelectedItem(uf); updateInterval.setSelectedItem(uf);

View File

@ -102,7 +102,8 @@ public class NilusSettingsWrapper<T extends Object> implements Serializable, Clo
} }
/** /**
* Repack the object. May want to do this before serializing. * Repack the object.i.e. write the xml text string.
* May want to do this before serializing or cloning.
* @return * @return
*/ */
public boolean repackNilusObject() { public boolean repackNilusObject() {
@ -149,6 +150,25 @@ public class NilusSettingsWrapper<T extends Object> implements Serializable, Clo
public void reSerialise() { public void reSerialise() {
packNilusObject(nilusObject); packNilusObject(nilusObject);
} }
@Override
public NilusSettingsWrapper<T> clone() {
/**
* Clone the underlying data, then force it to re-read the string into a new object.
*/
this.repackNilusObject();
NilusSettingsWrapper<T> clone = null;
try {
clone = (NilusSettingsWrapper<T>) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
return null;
}
if (nilusObject != null) {
clone.nilusObject = clone.unpackNilusObject(nilusObject.getClass());
}
return clone;
}
// private Class<?> getNilusClass() throws NoSuchMethodException, SecurityException { // private Class<?> getNilusClass() throws NoSuchMethodException, SecurityException {

View File

@ -9,6 +9,7 @@ import javax.swing.JTextField;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import PamView.dialog.PamGridBagContraints; import PamView.dialog.PamGridBagContraints;
import nilus.ContactInfo.Address;
import nilus.ResponsibleParty; import nilus.ResponsibleParty;
/** /**
@ -21,14 +22,18 @@ public class ResponsiblePartyPanel {
private JTextField name, organisation, position, email; private JTextField name, organisation, position, email;
private JPanel mainPanel; private JPanel mainPanel;
public ResponsiblePartyPanel() {
this(null);
}
/** /**
* *
*/ */
public ResponsiblePartyPanel() { public ResponsiblePartyPanel(String borderTitle) {
super(); super();
mainPanel = new JPanel(new GridBagLayout()); mainPanel = new JPanel(new GridBagLayout());
// mainPanel.setBorder(new TitledBorder("Responsible party")); if (borderTitle != null)
mainPanel.setBorder(new TitledBorder(borderTitle));
GridBagConstraints c = new PamGridBagContraints(); GridBagConstraints c = new PamGridBagContraints();
mainPanel.add(new JLabel("Name ", JLabel.RIGHT), c); mainPanel.add(new JLabel("Name ", JLabel.RIGHT), c);
c.gridx++; c.gridx++;
@ -64,14 +69,26 @@ public class ResponsiblePartyPanel {
name.setText(responsibleParty.getIndividualName()); name.setText(responsibleParty.getIndividualName());
organisation.setText(responsibleParty.getOrganizationName()); organisation.setText(responsibleParty.getOrganizationName());
position.setText(responsibleParty.getPositionName()); position.setText(responsibleParty.getPositionName());
email.setText(responsibleParty.getContactInfo().getContactInstructions());
Address addr = responsibleParty.getContactInfo().getAddress();
if (addr != null) {
email.setText(addr.getElectronicMailAddress());
}
} }
public boolean getParams(ResponsibleParty responsibleParty) { public boolean getParams(ResponsibleParty responsibleParty) {
responsibleParty.setIndividualName(name.getText()); responsibleParty.setIndividualName(name.getText());
responsibleParty.setOrganizationName(organisation.getText()); responsibleParty.setOrganizationName(organisation.getText());
responsibleParty.setPositionName(position.getText()); responsibleParty.setPositionName(position.getText());
responsibleParty.getContactInfo().setContactInstructions(email.getText());
Address addr = responsibleParty.getContactInfo().getAddress();
if (addr == null) {
addr = new Address();
responsibleParty.getContactInfo().setAddress(addr);
}
addr.setElectronicMailAddress(email.getText());
return true; return true;
} }
} }