mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-25 08:32:32 +00:00
Update Calibration export
Stop repeating hydrophones and add two addresses to Calibrations docs
This commit is contained in:
parent
9c86b41027
commit
860d1bec17
@ -45,6 +45,7 @@ import tethys.TethysTimeFuncs;
|
||||
import tethys.calibration.swing.CalibrationsExportWizard;
|
||||
import tethys.dbxml.DBXMLConnect;
|
||||
import tethys.dbxml.TethysException;
|
||||
import tethys.niluswraps.NilusSettingsWrapper;
|
||||
import tethys.niluswraps.NilusUnpacker;
|
||||
import tethys.pamdata.AutoTethysProvider;
|
||||
|
||||
@ -176,6 +177,9 @@ public class CalibrationHandler implements TethysStateObserver {
|
||||
return 0;
|
||||
}
|
||||
|
||||
NilusSettingsWrapper<Calibration> wrappedSample = new NilusSettingsWrapper<Calibration>();
|
||||
wrappedSample.setNilusObject(sampleCal);
|
||||
|
||||
PamArray array = ArrayManager.getArrayManager().getCurrentArray();
|
||||
int nPhone = array.getHydrophoneCount();
|
||||
DBXMLConnect dbxml = tethysControl.getDbxmlConnect();
|
||||
@ -184,6 +188,8 @@ public class CalibrationHandler implements TethysStateObserver {
|
||||
boolean exists;
|
||||
for (int i = 0; i < nPhone; i++) {
|
||||
// String docName = getHydrophoneId(i);
|
||||
NilusSettingsWrapper<Calibration> clonedWrap = wrappedSample.clone();
|
||||
sampleCal = clonedWrap.getNilusObject(Calibration.class);
|
||||
Calibration calDoc = createCalibrationDocument(i);
|
||||
if (sampleCal != null) {
|
||||
calDoc.setMetadataInfo(sampleCal.getMetadataInfo());
|
||||
|
@ -16,6 +16,7 @@ import javax.swing.JTextField;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import PamView.dialog.PamGridBagContraints;
|
||||
import PamView.panel.WestAlignedPanel;
|
||||
import PamView.wizard.PamWizard;
|
||||
import nilus.AlgorithmType;
|
||||
import nilus.AlgorithmType.Parameters;
|
||||
@ -43,8 +44,10 @@ public class CalibrationProcessCard extends CalibrationsCard {
|
||||
super(pamWizard, "Calibration Process");
|
||||
this.setLayout(new BorderLayout());
|
||||
processPanel = new JPanel(new GridBagLayout());
|
||||
processPanel.setBorder(new TitledBorder("Calibration Process"));
|
||||
this.add(BorderLayout.NORTH, processPanel);
|
||||
WestAlignedPanel wp;
|
||||
this.add(BorderLayout.NORTH, wp = new WestAlignedPanel(processPanel));
|
||||
wp.setBorder(new TitledBorder("Calibration Process"));
|
||||
|
||||
GridBagConstraints c = new PamGridBagContraints();
|
||||
|
||||
calMethod = new JComboBox<String>();
|
||||
|
@ -7,6 +7,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
@ -19,6 +20,7 @@ import org.jdesktop.swingx.JXDatePicker;
|
||||
|
||||
import PamView.dialog.PamDialog;
|
||||
import PamView.dialog.PamGridBagContraints;
|
||||
import PamView.panel.WestAlignedPanel;
|
||||
import PamView.wizard.PamWizard;
|
||||
import nilus.Calibration;
|
||||
import nilus.ContactInfo;
|
||||
@ -26,20 +28,25 @@ import nilus.MetadataInfo;
|
||||
import nilus.ResponsibleParty;
|
||||
import tethys.TethysTimeFuncs;
|
||||
import tethys.calibration.CalibrationHandler;
|
||||
import tethys.swing.export.ResponsiblePartyPanel;
|
||||
|
||||
public class CalibrationsContactCard extends CalibrationsCard {
|
||||
|
||||
private JXDatePicker datePicker;
|
||||
|
||||
private JTextField individual, organisation, position, email;
|
||||
private ResponsiblePartyPanel calibrator, dataManager;
|
||||
|
||||
private JComboBox<String> updateInterval;
|
||||
|
||||
private MetadataInfo metaData;
|
||||
|
||||
private JButton copyDown, copyUp;
|
||||
|
||||
public CalibrationsContactCard(PamWizard pamWizard) {
|
||||
super(pamWizard, "Contact Details");
|
||||
// TODO Auto-generated constructor stub
|
||||
// setBorder(new TitledBorder("Contact"));
|
||||
setLayout(new BorderLayout());
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
|
||||
updateInterval = new JComboBox<>();
|
||||
String[] vals = CalibrationHandler.updateOptions;
|
||||
@ -48,8 +55,8 @@ public class CalibrationsContactCard extends CalibrationsCard {
|
||||
}
|
||||
|
||||
JPanel datePanel = new JPanel(new GridBagLayout());
|
||||
datePanel.setBorder(new TitledBorder("Calibration date"));
|
||||
add(BorderLayout.NORTH, datePanel);
|
||||
JPanel lp = new WestAlignedPanel(datePanel);
|
||||
lp.setBorder(new TitledBorder("Calibration date"));
|
||||
GridBagConstraints c = new PamGridBagContraints();
|
||||
datePanel.add(new JLabel("Calibration date: ", JLabel.RIGHT), c);
|
||||
datePicker = new JXDatePicker();
|
||||
@ -61,67 +68,66 @@ public class CalibrationsContactCard extends CalibrationsCard {
|
||||
c.gridx++;
|
||||
datePanel.add(updateInterval, c);
|
||||
|
||||
calibrator = new ResponsiblePartyPanel("Technical Person");
|
||||
dataManager = new ResponsiblePartyPanel("Data Manager");
|
||||
|
||||
JPanel contactPanel = new JPanel(new GridBagLayout());
|
||||
contactPanel.setBorder(new TitledBorder("Contact"));
|
||||
this.add(BorderLayout.CENTER, contactPanel);
|
||||
JPanel copyPanel = new JPanel(new GridBagLayout());
|
||||
c = new PamGridBagContraints();
|
||||
contactPanel.add(new JLabel("Individual Name "), c);
|
||||
copyPanel.add(copyDown = new JButton("Copy down"),c);
|
||||
c.gridx++;
|
||||
contactPanel.add(individual = new JTextField(15), c);
|
||||
c.gridx = 0;
|
||||
c.gridy++;
|
||||
contactPanel.add(new JLabel("Organisation "), c);
|
||||
c.gridx++;
|
||||
contactPanel.add(organisation = new JTextField(15), c);
|
||||
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++;
|
||||
copyPanel.add(copyUp = new JButton("Copy up"), c);
|
||||
|
||||
add(lp);
|
||||
add(calibrator.getMainPanel());
|
||||
add(copyPanel);
|
||||
add(dataManager.getMainPanel());
|
||||
|
||||
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
|
||||
public boolean getParams(Calibration cardParams) {
|
||||
if (cardParams == null) {
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
}
|
||||
ResponsibleParty rp = checkRPChildren(cardParams.getResponsibleParty());
|
||||
cardParams.setResponsibleParty(rp);
|
||||
calibrator.getParams(rp);
|
||||
|
||||
// so far as I'm aware, the meta info contains the time we create this record
|
||||
// and the other timestamp is the data the calibration was donw.
|
||||
metaInf.setDate(TethysTimeFuncs.xmlGregCalFromMillis(System.currentTimeMillis()));
|
||||
metaInf.setUpdateFrequency((String) updateInterval.getSelectedItem());
|
||||
metaData = cardParams.getMetadataInfo();
|
||||
if (metaData == null) {
|
||||
metaData = new MetadataInfo();
|
||||
cardParams.setMetadataInfo(metaData);
|
||||
}
|
||||
metaData.setContact(checkRPChildren(metaData.getContact()));
|
||||
dataManager.getParams(metaData.getContact());
|
||||
|
||||
contact.setIndividualName(individual.getText());
|
||||
contact.setOrganizationName(organisation.getText());
|
||||
contact.setPositionName(position.getText());
|
||||
contactInfo.setContactInstructions(email.getText());
|
||||
|
||||
// and set this both as the RepsonsiblePArty and in the metadata.
|
||||
cardParams.setResponsibleParty(contact);
|
||||
metaData.setUpdateFrequency((String) updateInterval.getSelectedItem());
|
||||
metaData.setDate(TethysTimeFuncs.xmlGregCalFromMillis(System.currentTimeMillis()));
|
||||
|
||||
Date date = datePicker.getDate();
|
||||
if (date == null) {
|
||||
@ -133,6 +139,19 @@ public class CalibrationsContactCard extends CalibrationsCard {
|
||||
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) {
|
||||
if (cal == null) {
|
||||
return null;
|
||||
@ -151,19 +170,17 @@ public class CalibrationsContactCard extends CalibrationsCard {
|
||||
@Override
|
||||
public void setParams(Calibration cardParams) {
|
||||
// fill in as much as possible from the existing Calibration
|
||||
ResponsibleParty resp = findResponsibleParty(cardParams);
|
||||
ResponsibleParty resp = cardParams.getResponsibleParty();
|
||||
if (resp != null) {
|
||||
individual.setText(resp.getIndividualName());
|
||||
organisation.setText(resp.getOrganizationName());
|
||||
position.setText(resp.getPositionName());
|
||||
ContactInfo cInf = resp.getContactInfo();
|
||||
if (cInf != null) {
|
||||
email.setText(cInf.getContactInstructions());
|
||||
}
|
||||
calibrator.setParams(resp);
|
||||
}
|
||||
|
||||
MetadataInfo metaInf = cardParams.getMetadataInfo();
|
||||
if (metaInf != null) {
|
||||
resp = metaInf.getContact();
|
||||
if (resp != null) {
|
||||
dataManager.getParams(resp);
|
||||
}
|
||||
String uf = metaInf.getUpdateFrequency();
|
||||
if (uf != null) {
|
||||
updateInterval.setSelectedItem(uf);
|
||||
|
@ -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
|
||||
*/
|
||||
public boolean repackNilusObject() {
|
||||
@ -150,6 +151,25 @@ public class NilusSettingsWrapper<T extends Object> implements Serializable, Clo
|
||||
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 {
|
||||
// Method method = this.getClass().getMethod("getNilusObject", null);
|
||||
|
@ -9,6 +9,7 @@ import javax.swing.JTextField;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import PamView.dialog.PamGridBagContraints;
|
||||
import nilus.ContactInfo.Address;
|
||||
import nilus.ResponsibleParty;
|
||||
|
||||
/**
|
||||
@ -22,13 +23,17 @@ public class ResponsiblePartyPanel {
|
||||
|
||||
private JPanel mainPanel;
|
||||
|
||||
public ResponsiblePartyPanel() {
|
||||
this(null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ResponsiblePartyPanel() {
|
||||
public ResponsiblePartyPanel(String borderTitle) {
|
||||
super();
|
||||
mainPanel = new JPanel(new GridBagLayout());
|
||||
// mainPanel.setBorder(new TitledBorder("Responsible party"));
|
||||
if (borderTitle != null)
|
||||
mainPanel.setBorder(new TitledBorder(borderTitle));
|
||||
GridBagConstraints c = new PamGridBagContraints();
|
||||
mainPanel.add(new JLabel("Name ", JLabel.RIGHT), c);
|
||||
c.gridx++;
|
||||
@ -64,14 +69,26 @@ public class ResponsiblePartyPanel {
|
||||
name.setText(responsibleParty.getIndividualName());
|
||||
organisation.setText(responsibleParty.getOrganizationName());
|
||||
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) {
|
||||
responsibleParty.setIndividualName(name.getText());
|
||||
responsibleParty.setOrganizationName(organisation.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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user