import ch.psi.pshell.console.App;
import ch.psi.pshell.framework.Context;
import ch.psi.pshell.framework.Setup;
import ch.psi.pshell.framework.Panel;
import ch.psi.pshell.notification.NotificationManager.NotificationLevel;
import ch.psi.pshell.utils.State;
import ch.psi.pshell.swing.SwingUtils;
import ch.psi.pshell.swing.SwingUtils.OptionResult;
import ch.psi.pshell.swing.SwingUtils.OptionType;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
/**
*
*/
public class Settings extends Panel {
//static String DEFAULT_PATH = "{data}/{year}_{month}/{date}_{seq}%03d";
static String DEFAULT_PATH = "{data}/{year}_{month}/{date}/{date}_{seq}%04d_{name}";
public Settings() {
initComponents();
updateRsync();
SwingUtils.setEnumCombo(comboNotification, NotificationLevel.class);
}
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
SwingUtilities.invokeLater(() -> {
undo();
});
textNamePattern.setText(App.getInstance().getConfig().dataPath);
}
@Override
public void onStateChange(State state, State former) {
updateControls();
updateNotify();
}
@Override
public void onExecutedFile(String fileName, Object result) {
}
//Callback to perform update - in event thread
@Override
protected void doUpdate() {
}
void undo() {
try {
textDataPath.setText(Setup.expandPath(App.getInstance().getConfig().dataPath));
textPGroup.setText(Context.getSetting("pgroup") == null ? "" : Context.getSetting("pgroup"));
textProposal.setText(Context.getSetting("proposal") == null ? "" : Context.getSetting("proposal"));
textProposer.setText(Context.getSetting("proposer") == null ? "" : Context.getSetting("proposer"));
textSamples.setText(Context.getSetting("sample") == null ? "" : Context.getSetting("sample"));
textAuthors.setText(Context.getSetting("authors") == null ? "" : Context.getSetting("authors").replace("|", "\n"));
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
}
}
void apply() {
try {
String proposal = textProposal.getText().trim();
String pgroup = textPGroup.getText().trim();
String proposer = textProposer.getText().trim();
String samples = textSamples.getText().trim();
String authors = textAuthors.getText().trim().replace("\n", "|");
Context.setSetting("pgroup", pgroup);
Context.setSetting("proposal", proposal);
Context.setSetting("proposer", proposer);
Context.setSetting("sample", samples);
Context.setSetting("authors", authors);
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
}
undo();
}
void reset() {
try {
textProposal.setText("");
textPGroup.setText("");
textProposer.setText("");
textSamples.setText("");
textAuthors.setText("");
apply();
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
}
undo();
}
boolean updatingControls;
void updateRsync() {
try {
updatingControls = true;
String user = null;
String host = null;
String path = null;
String remove = null;
try {
user = getSetting("RSYNC_USER");
host = getSetting("RSYNC_HOST");
path = getSetting("RSYNC_PATH");
remove = getSetting("RSYNC_DEL");
} catch (IOException ex) {
}
boolean enabled = ((user != null) && (!user.trim().isEmpty()));
textRsyncUser.setText(enabled ? user : "");
textRsyncHost.setText(enabled ? host : "");
textRsyncPath.setText((enabled && (path != null)) ? path : "");
checkRsyncRemove.setSelected((remove==null) ? false : remove.toLowerCase().equals("true"));
checkRsyncEnable.setSelected(enabled);
textRsyncUser.setEnabled(!enabled);
textRsyncHost.setEnabled(!enabled);
//textRsyncPath.setEnabled(!enabled);
buttonUndoFolder.setEnabled(false);
buttonSetFolder.setEnabled(false);
} finally {
updatingControls = false;
}
}
void updateNotify() {
try {
updatingControls = true;
comboNotification.setSelectedItem(App.getInstance().getConfig().notificationLevel);
textRecipients.setText(Context.getNotificationManager().getConfig().to);
} finally {
updatingControls = false;
}
}
void updateControls() {
boolean editable = getState().isInitialized() && !getState().isProcessing();
textNamePattern.setEnabled(editable);
spinnerSeq.setEnabled(editable);
buttonDefaultPath.setEnabled(editable && !textNamePattern.getText().equals(DEFAULT_PATH));
buttonSetPath.setEnabled(editable && !textNamePattern.getText().equals(App.getInstance().getConfig().dataPath));
buttonUndoPath.setEnabled(editable && !textNamePattern.getText().equals(App.getInstance().getConfig().dataPath));
buttonSetSeq.setEnabled(editable && !spinnerSeq.getValue().equals(Context.getFileSequentialNumber()));
buttonUndoSeq.setEnabled(editable && !spinnerSeq.getValue().equals(Context.getFileSequentialNumber()));
buttonApply.setEnabled(editable);
spinnerSeq.setValue(Context.getFileSequentialNumber());
textDataPath.setText(Setup.expandPath(App.getInstance().getConfig().dataPath));
}
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
textProposer = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
textProposal = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
textPGroup = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
textSamples = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
textAuthors = new javax.swing.JTextArea();
buttonApply = new javax.swing.JButton();
buttonUndo = new javax.swing.JButton();
buttonClear = new javax.swing.JButton();
panelDataFile = new javax.swing.JPanel();
buttonSetSeq = new javax.swing.JButton();
buttonUndoSeq = new javax.swing.JButton();
buttonDefaultPath = new javax.swing.JButton();
buttonSetPath = new javax.swing.JButton();
buttonUndoPath = new javax.swing.JButton();
jLabel9 = new javax.swing.JLabel();
spinnerSeq = new javax.swing.JSpinner();
textNamePattern = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
textDataPath = new javax.swing.JTextField();
jPanel6 = new javax.swing.JPanel();
jLabel11 = new javax.swing.JLabel();
textRsyncUser = new javax.swing.JTextField();
jLabel18 = new javax.swing.JLabel();
textRsyncPath = new javax.swing.JTextField();
checkRsyncEnable = new javax.swing.JCheckBox();
buttonSetFolder = new javax.swing.JButton();
jLabel12 = new javax.swing.JLabel();
textRsyncHost = new javax.swing.JTextField();
checkRsyncRemove = new javax.swing.JCheckBox();
buttonUndoFolder = new javax.swing.JButton();
jPanel7 = new javax.swing.JPanel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
textRecipients = new javax.swing.JTextField();
comboNotification = new javax.swing.JComboBox<>();
buttonNotificationApply = new javax.swing.JButton();
buttonNotificationUndo = new javax.swing.JButton();
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Metadata"));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel3.setText("Proposer:");
textProposer.setDisabledTextColor(javax.swing.UIManager.getDefaults().getColor("TextField.foreground"));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel4.setText("Proposal:");
textProposal.setDisabledTextColor(javax.swing.UIManager.getDefaults().getColor("TextField.foreground"));
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel5.setText("P-group:");
jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel6.setText("Sample:");
jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel7.setText("Authors:");
textAuthors.setColumns(20);
textAuthors.setRows(4);
jScrollPane1.setViewportView(textAuthors);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(textPGroup, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
.addComponent(textProposal)
.addComponent(textProposer))
.addGap(40, 40, 40)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(textSamples, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4, jLabel5, jLabel6, jLabel7});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textProposer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textSamples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textProposal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textPGroup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1)
.addGap(5, 5, 5)))
.addContainerGap())
);
buttonApply.setText("Apply");
buttonApply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonApplyActionPerformed(evt);
}
});
buttonUndo.setText("Undo");
buttonUndo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonUndoActionPerformed(evt);
}
});
buttonClear.setText("Reset");
buttonClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonClearActionPerformed(evt);
}
});
panelDataFile.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Location"));
buttonSetSeq.setText("Save");
buttonSetSeq.setEnabled(false);
buttonSetSeq.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSetSeqActionPerformed(evt);
}
});
buttonUndoSeq.setText("Undo");
buttonUndoSeq.setEnabled(false);
buttonUndoSeq.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonUndoSeqActionPerformed(evt);
}
});
buttonDefaultPath.setText("Default");
buttonDefaultPath.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonDefaultPathActionPerformed(evt);
}
});
buttonSetPath.setText("Save");
buttonSetPath.setEnabled(false);
buttonSetPath.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSetPathActionPerformed(evt);
}
});
buttonUndoPath.setText("Undo");
buttonUndoPath.setEnabled(false);
buttonUndoPath.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonUndoPathActionPerformed(evt);
}
});
jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel9.setText("Sequential:");
spinnerSeq.setModel(new javax.swing.SpinnerNumberModel(0, 0, 99999, 1));
spinnerSeq.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spinnerSeqStateChanged(evt);
}
});
textNamePattern.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
textNamePatternKeyTyped(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
textNamePatternKeyReleased(evt);
}
});
jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel10.setText("Name Pattern:");
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel2.setText("Path:");
textDataPath.setDisabledTextColor(javax.swing.UIManager.getDefaults().getColor("TextField.foreground"));
textDataPath.setEnabled(false);
javax.swing.GroupLayout panelDataFileLayout = new javax.swing.GroupLayout(panelDataFile);
panelDataFile.setLayout(panelDataFileLayout);
panelDataFileLayout.setHorizontalGroup(
panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelDataFileLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelDataFileLayout.createSequentialGroup()
.addGroup(panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel10)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelDataFileLayout.createSequentialGroup()
.addComponent(spinnerSeq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonSetSeq)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonUndoSeq)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(textNamePattern))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(panelDataFileLayout.createSequentialGroup()
.addComponent(buttonSetPath)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonUndoPath))
.addComponent(buttonDefaultPath)))
.addGroup(panelDataFileLayout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textDataPath)))
.addContainerGap())
);
panelDataFileLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonDefaultPath, buttonSetPath, buttonUndoPath});
panelDataFileLayout.setVerticalGroup(
panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelDataFileLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(textNamePattern, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonSetPath)
.addComponent(buttonUndoPath))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(spinnerSeq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonSetSeq)
.addComponent(buttonUndoSeq)
.addComponent(buttonDefaultPath))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(panelDataFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textDataPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Transfer"));
jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel11.setText("User:");
jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel18.setText("Destination Folder:");
textRsyncPath.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
textRsyncPathKeyReleased(evt);
}
});
checkRsyncEnable.setText("Enable");
checkRsyncEnable.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkRsyncEnableActionPerformed(evt);
}
});
buttonSetFolder.setText("Set");
buttonSetFolder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSetFolderActionPerformed(evt);
}
});
jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel12.setText("Host:");
checkRsyncRemove.setText("Remove local files after transfer");
checkRsyncRemove.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkRsyncRemoveActionPerformed(evt);
}
});
buttonUndoFolder.setText("Undo");
buttonUndoFolder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonUndoFolderActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(checkRsyncRemove)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(textRsyncPath)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonSetFolder)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonUndoFolder))))
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(checkRsyncEnable)
.addGap(83, 83, 83)
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textRsyncUser)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textRsyncHost)))
.addContainerGap())
);
jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonSetFolder, buttonUndoFolder});
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(textRsyncUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(checkRsyncEnable)
.addComponent(jLabel12)
.addComponent(textRsyncHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(textRsyncPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonSetFolder)
.addComponent(buttonUndoFolder))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(checkRsyncRemove))
.addGroup(jPanel6Layout.createSequentialGroup()
.addGap(42, 42, 42)
.addComponent(jLabel18)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Notification"));
jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel13.setText("Mode:");
jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel14.setText("Recipients:");
comboNotification.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
buttonNotificationApply.setText("Set");
buttonNotificationApply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonNotificationApplyActionPerformed(evt);
}
});
buttonNotificationUndo.setText("Undo");
buttonNotificationUndo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonNotificationUndoActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboNotification, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel14)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textRecipients)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(buttonNotificationApply)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonNotificationUndo)
.addContainerGap())
);
jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonNotificationApply, buttonNotificationUndo});
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel13)
.addComponent(jLabel14)
.addComponent(textRecipients, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonNotificationApply)
.addComponent(buttonNotificationUndo)
.addComponent(comboNotification, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonClear)
.addGap(18, 18, 18)
.addComponent(buttonUndo)
.addGap(18, 18, 18)
.addComponent(buttonApply)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(panelDataFile, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonApply, buttonClear, buttonUndo});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(panelDataFile, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonApply)
.addComponent(buttonUndo)
.addComponent(buttonClear))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {buttonApply, buttonClear, buttonUndo});
}// //GEN-END:initComponents
private void buttonUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUndoActionPerformed
try {
undo();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonUndoActionPerformed
private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
try {
apply();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonApplyActionPerformed
private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearActionPerformed
try {
reset();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonClearActionPerformed
private void buttonSetSeqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetSeqActionPerformed
try {
Context.setFileSequentialNumber(((Number) spinnerSeq.getValue()).intValue());
updateControls();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonSetSeqActionPerformed
private void buttonUndoSeqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUndoSeqActionPerformed
try {
spinnerSeq.setValue(Context.getFileSequentialNumber());
updateControls();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonUndoSeqActionPerformed
private void buttonDefaultPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDefaultPathActionPerformed
textNamePattern.setText(DEFAULT_PATH);
updateControls();
}//GEN-LAST:event_buttonDefaultPathActionPerformed
private void buttonSetPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetPathActionPerformed
try {
App.getInstance().getConfig().dataPath = textNamePattern.getText();
App.getInstance().getConfig().save();
updateControls();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonSetPathActionPerformed
private void buttonUndoPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUndoPathActionPerformed
try {
textNamePattern.setText(App.getInstance().getConfig().dataPath);
updateControls();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonUndoPathActionPerformed
private void spinnerSeqStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerSeqStateChanged
updateControls();
}//GEN-LAST:event_spinnerSeqStateChanged
private void textNamePatternKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textNamePatternKeyTyped
}//GEN-LAST:event_textNamePatternKeyTyped
private void textNamePatternKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textNamePatternKeyReleased
updateControls();
}//GEN-LAST:event_textNamePatternKeyReleased
private void checkRsyncEnableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkRsyncEnableActionPerformed
if (!updatingControls) {
if (!checkRsyncEnable.isSelected()) {
if (SwingUtils.showOption(getTopLevel(), "Disable Data Transfer", "Do you want to disable data transfer and remove the user authentication?", OptionType.YesNo) != OptionResult.Yes) {
updateRsync();
return;
}
}
try {
setSetting("RSYNC_USER", "");
//setSetting("RSYNC_PATH", "");
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
}
if (checkRsyncEnable.isSelected()) {
String user = textRsyncUser.getText().trim();
String host = textRsyncHost.getText().trim();
String path = textRsyncPath.getText().trim();
boolean del = checkRsyncRemove.isEnabled();
if (!user.isEmpty()) {
try {
//this.eval("authorize_user('" + user +"', aux_file = '/scratch/.rsync.tmp')");
this.eval("authorize_user('" + user + "')");
setSetting("RSYNC_USER", user);
setSetting("RSYNC_HOST", host);
setSetting("RSYNC_PATH", path);
setSetting("RSYNC_DEL", del);
} catch (Exception ex) {
try {
this.evalAsync("remove_user_key()");
} catch (Exception e) {
getLogger().log(Level.SEVERE, null, e);
}
showException(ex);
}
} else {
showMessage("Error", "Enter a valid user name to enable data transfer");
}
} else {
try {
this.evalAsync("remove_user_key()");
} catch (Exception e) {
getLogger().log(Level.SEVERE, null, e);
}
}
updateRsync();
}
}//GEN-LAST:event_checkRsyncEnableActionPerformed
private void buttonSetFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetFolderActionPerformed
try {
String path = textRsyncPath.getText().trim();
setSetting("RSYNC_PATH", path);
/*
String ret = SwingUtils.getString(this, "Enter destination path:", String.valueOf(getSetting("RSYNC_PATH")));
if ((ret != null) && (!ret.trim().isEmpty())) {
setSetting("RSYNC_PATH", ret.trim());
}
*/
updateRsync();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonSetFolderActionPerformed
private void checkRsyncRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkRsyncRemoveActionPerformed
if (!updatingControls) {
try {
setSetting("RSYNC_DEL", checkRsyncRemove.isSelected());
} catch (Exception ex) {
showException(ex);
}
}
}//GEN-LAST:event_checkRsyncRemoveActionPerformed
private void buttonUndoFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUndoFolderActionPerformed
try {
updateRsync();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonUndoFolderActionPerformed
private void textRsyncPathKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textRsyncPathKeyReleased
buttonUndoFolder.setEnabled(checkRsyncEnable.isSelected());
buttonSetFolder.setEnabled(checkRsyncEnable.isSelected());
}//GEN-LAST:event_textRsyncPathKeyReleased
private void buttonNotificationUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNotificationUndoActionPerformed
try {
updateNotify();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonNotificationUndoActionPerformed
private void buttonNotificationApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNotificationApplyActionPerformed
try {
NotificationLevel level = (NotificationLevel) comboNotification.getSelectedItem();
String to = textRecipients.getText().trim();
if (level!=NotificationLevel.Off){
if (to.isEmpty()){
throw new Exception("To enable notifications please set the recepient list.");
}
}
App.getInstance().getConfig().notificationLevel =level;
Context.getNotificationManager().setRecipients(to.split(";"));
Context.getNotificationManager().initialize(); //Remove this when fix setRecipients
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonNotificationApplyActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonApply;
private javax.swing.JButton buttonClear;
private javax.swing.JButton buttonDefaultPath;
private javax.swing.JButton buttonNotificationApply;
private javax.swing.JButton buttonNotificationUndo;
private javax.swing.JButton buttonSetFolder;
private javax.swing.JButton buttonSetPath;
private javax.swing.JButton buttonSetSeq;
private javax.swing.JButton buttonUndo;
private javax.swing.JButton buttonUndoFolder;
private javax.swing.JButton buttonUndoPath;
private javax.swing.JButton buttonUndoSeq;
private javax.swing.JCheckBox checkRsyncEnable;
private javax.swing.JCheckBox checkRsyncRemove;
private javax.swing.JComboBox comboNotification;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JPanel panelDataFile;
private javax.swing.JSpinner spinnerSeq;
private javax.swing.JTextArea textAuthors;
private javax.swing.JTextField textDataPath;
private javax.swing.JTextField textNamePattern;
private javax.swing.JTextField textPGroup;
private javax.swing.JTextField textProposal;
private javax.swing.JTextField textProposer;
private javax.swing.JTextField textRecipients;
private javax.swing.JTextField textRsyncHost;
private javax.swing.JTextField textRsyncPath;
private javax.swing.JTextField textRsyncUser;
private javax.swing.JTextField textSamples;
// End of variables declaration//GEN-END:variables
}