Search in sources :

Example 1 with SimpleTableModel

use of org.weasis.core.ui.util.SimpleTableModel in project Weasis by nroduit.

the class WorklistDialog method fillTable.

public void fillTable() {
    DicomState state = queryWorklist(calling, called);
    jtable.getSelectionModel().removeListSelectionListener(selectionListener);
    List<Attributes> items = state.getDicomRSP();
    if (items != null && !items.isEmpty()) {
        DicomParam[] cols = { CFind.PatientName, CFind.PatientID, CFind.PatientBirthDate, CFind.PatientSex, CFind.AccessionNumber, ModalityWorklist.ScheduledProcedureStepDescription, ModalityWorklist.Modality, ModalityWorklist.ScheduledStationName };
        TagW[] tags = TagD.getTagFromIDs(Arrays.stream(cols).mapToInt(DicomParam::getTag).toArray());
        Object[][] labels = new Object[items.size()][];
        for (int i = 0; i < labels.length; i++) {
            Attributes m = items.get(i);
            Object[] row = new Object[tags.length];
            for (int j = 0; j < tags.length; j++) {
                int[] pSeq = cols[j].getParentSeqTags();
                if (pSeq == null || pSeq.length == 0) {
                    row[j] = tags[j].getFormattedTagValue(tags[j].getValue(m), null);
                } else {
                    Attributes parent = m;
                    for (int value : pSeq) {
                        Attributes p = parent.getNestedDataset(value);
                        if (p == null) {
                            break;
                        }
                        parent = p;
                    }
                    row[j] = tags[j].getFormattedTagValue(tags[j].getValue(parent), null);
                }
            }
            labels[i] = row;
        }
        jtable.setModel(new SimpleTableModel(Arrays.stream(tags).map(TagW::getDisplayedName).toArray(String[]::new), labels));
        TableColumnAdjuster.pack(jtable);
        selectionListener = event -> {
            int row = jtable.getSelectedRow();
            if (row < 0) {
                selectedItem = null;
                selection.setText("");
            } else {
                selectedItem = items.get(row);
                TagW name = TagD.get(Tag.PatientName);
                StringBuilder buf = new StringBuilder(name.getFormattedTagValue(name.getValue(selectedItem), null));
                buf.append(" ");
                TagW date = TagD.get(Tag.PatientBirthDate);
                buf.append(date.getFormattedTagValue(date.getValue(selectedItem), null));
                selection.setText(buf.toString());
            }
        };
        jtable.getSelectionModel().addListSelectionListener(selectionListener);
    } else {
        if (state.getStatus() != Status.Success) {
            GuiExecutor.instance().execute(() -> JOptionPane.showMessageDialog(this, state.getMessage(), null, JOptionPane.ERROR_MESSAGE));
            dispose();
            throw new IllegalStateException(state.getMessage());
        }
        jtable.setModel(new SimpleTableModel(new String[] {}, new Object[][] {}));
        tableContainer.setPreferredSize(GuiUtils.getDimension(450, 50));
    }
    tableContainer.setViewportView(jtable);
}
Also used : DicomParam(org.weasis.dicom.param.DicomParam) Attributes(org.dcm4che3.data.Attributes) SimpleTableModel(org.weasis.core.ui.util.SimpleTableModel) DicomState(org.weasis.dicom.param.DicomState) TagW(org.weasis.core.api.media.data.TagW)

Aggregations

Attributes (org.dcm4che3.data.Attributes)1 TagW (org.weasis.core.api.media.data.TagW)1 SimpleTableModel (org.weasis.core.ui.util.SimpleTableModel)1 DicomParam (org.weasis.dicom.param.DicomParam)1 DicomState (org.weasis.dicom.param.DicomState)1