Link samples table to GUI events

This commit is contained in:
2018-09-10 16:57:44 +02:00
parent e2cbce5812
commit 014116ba6f
2 changed files with 79 additions and 41 deletions

View File

@@ -81,6 +81,27 @@ public class MainPanel extends Panel {
}
}
});
tableSamples.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
try {
String add = String.valueOf(tableSamples.getModel().getValueAt(tableSamples.getSelectedRow(), 3));
if (!add.trim().isEmpty()) {
String cur = Controller.getInstance().getCurrentSelection();
if (cur != null) {
cur = cur.substring(0, 2);
}
if (!add.equals(cur)) {
Puck puck = Controller.getInstance().getPuck(add);
Controller.getInstance().selectPuck(puck);
}
}
} catch (Exception ex) {
showException(ex);
}
}
});
}
@Override
@@ -159,11 +180,8 @@ public class MainPanel extends Panel {
}
setPuckDatamatrix(null);
setSampleDatamatrix(null);
Controller.getInstance().updatePuckTypes();
startTimer(3000, 1000);
updateCameraView();
refreshSamplesTable();
}
@Override
@@ -425,44 +443,14 @@ public class MainPanel extends Panel {
return panelDetail.getSize();
}
String[] HEADER = new String[]{
"User Name", "Dewar Name",
"Puck Name", "Puck Address", "Puck Barcode", "Puck Type",
"Sample Name", "Sample Position", "Sample Status", "Mount Count"
};
void refreshSamplesTable() {
try {
String json = (String) Context.getInstance().evalLineBackground("get_samples_info()");
//SamplesInfo sampleInfo = (SamplesInfo) JsonSerializer.decode(json, SampleInfo.class);
SampleInfo[] samples = (SampleInfo[]) JsonSerializer.decode(json, SampleInfo[].class);
Object[][] sampleData = new Object[samples.length][];
for (int i = 0; i < samples.length; i++) {
sampleData[i] = samples[i].getData();
}
tableSamples.setModel(new DefaultTableModel(
sampleData,
HEADER
) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
);
} catch (Exception ex) {
clearSamplesTable();
getLogger().log(Level.SEVERE, null, ex);
}
}
void clearSamplesTable() {
void setSamplesTable(Object[][] sampleData) {
tableSamples.setModel(new DefaultTableModel(
new Object[][]{},
HEADER
sampleData,
new String[]{
"User Name", "Dewar Name",
"Puck Name", "Puck Address", "Puck Barcode", "Puck Type",
"Sample Name", "Sample Position", "Sample Status", "Mount Count"
}
) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
@@ -475,7 +463,7 @@ public class MainPanel extends Panel {
if (segment != null) {
String add = segment + String.valueOf(puck);
for (int i = 0; i < tablePucks.getModel().getRowCount(); i++) {
if (tablePucks.getModel().getValueAt(i, 0).equals(add)) {
if (add.equals(tablePucks.getModel().getValueAt(i, 0))) {
if (tablePucks.getSelectedRow() != i) {
tablePucks.setRowSelectionInterval(i, i);
SwingUtils.scrollToVisible(tablePucks, i, 0);
@@ -483,6 +471,16 @@ public class MainPanel extends Panel {
break;
}
}
for (int i = 0; i < tableSamples.getModel().getRowCount(); i++) {
if (add.equals(tableSamples.getModel().getValueAt(i, 3))) {
if (tableSamples.getSelectedRow() != i) {
tableSamples.setRowSelectionInterval(i, i);
SwingUtils.scrollToVisible(tableSamples, i, 0);
}
break;
}
}
}
}