List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:com.diversityarrays.kdxplore.trials.TrialOverviewPanel.java
public TrialOverviewPanel(String title, OfflineData offdata, TrialExplorerManager manager, FileListTransferHandler flth, MessagePrinter mp, final Closure<List<Trial>> onTrialSelected) { super(new BorderLayout()); offlineData = offdata;/* w w w. j ava 2 s. c o m*/ KdxploreDatabase kdxdb = offlineData.getKdxploreDatabase(); if (kdxdb != null) { kdxdb.addEntityChangeListener(trialChangeListener); kdxdb.addEntityChangeListener(traitChangeListener); } this.messagePrinter = mp; TableTransferHandler tth = TableTransferHandler.initialiseForCopySelectAll(trialsTable, true); trialsTable.setTransferHandler(new ChainingTransferHandler(flth, tth)); trialsTable.setAutoCreateRowSorter(true); trialsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { List<Trial> selectedTrials = getSelectedTrials(); if (selectedTrials.size() == 1) { trialTraitsTableModel.setSelectedTrial(selectedTrials.get(0)); } else { trialTraitsTableModel.setSelectedTrial(null); } onTrialSelected.execute(selectedTrials); } } }); trialsTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) { fireEditCommand(e); } } }); GuiUtil.setVisibleRowCount(trialsTable, MAX_INITIAL_VISIBLE_TRIAL_ROWS); offlineData.addOfflineDataChangeListener(offlineDataChangeListener); trialTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateRefreshAction(); } }); trialTraitsTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateAddTraitAction(); updateRemoveTraitAction(); updateScoringOrderAction(); } }); trialTraitsTable.addMouseListener(new MouseAdapter() { List<Trait> selectedTraits; JPopupMenu popupMenu; Action showTraitsAction = new AbstractAction("Select in Trait Explorer") { @Override public void actionPerformed(ActionEvent e) { manager.showTraitsInTraitExplorer(selectedTraits); } }; @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && 2 == e.getClickCount()) { // Start editing the Trait e.consume(); int vrow = trialTraitsTable.rowAtPoint(e.getPoint()); if (vrow >= 0) { int mrow = trialTraitsTable.convertRowIndexToModel(vrow); if (mrow >= 0) { Trait trait = trialTraitsTableModel.getTraitAt(mrow); if (trait != null) { traitExplorer.startEditing(trait); ; } } } } else if (SwingUtilities.isRightMouseButton(e) && 1 == e.getClickCount()) { // Select the traits in the traitExplorer e.consume(); List<Integer> modelRows = GuiUtil.getSelectedModelRows(trialTraitsTable); if (!modelRows.isEmpty()) { selectedTraits = modelRows.stream().map(trialTraitsTableModel::getTraitAt) .collect(Collectors.toList()); if (popupMenu == null) { popupMenu = new JPopupMenu(); popupMenu.add(showTraitsAction); } Point pt = e.getPoint(); popupMenu.show(trialTraitsTable, pt.x, pt.y); } } } }); trialTraitsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateRemoveTraitAction(); } } }); updateAddTraitAction(); updateRemoveTraitAction(); updateScoringOrderAction(); updateRefreshAction(); KDClientUtils.initAction(ImageId.REFRESH_24, refreshTrialTraitsAction, "Refresh"); KDClientUtils.initAction(ImageId.MINUS_GOLD_24, removeTraitAction, "Remove selected Traits"); KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addTraitAction, "Add Traits to Trial"); KDClientUtils.initAction(ImageId.TRAIT_ORDER_24, setScoringOrderAction, "Define Trait Scoring Order"); Box buttons = Box.createHorizontalBox(); buttons.add(new JButton(setScoringOrderAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(addTraitAction)); buttons.add(new JButton(removeTraitAction)); buttons.add(Box.createHorizontalStrut(10)); buttons.add(refreshTrialTraitsButton); JPanel traitsPanel = new JPanel(new BorderLayout()); traitsPanel.add(GuiUtil.createLabelSeparator("Uses Traits", buttons), BorderLayout.NORTH); traitsPanel.add(new PromptScrollPane(trialTraitsTable, "If the (single) selected Trial has Traits they will appear here"), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(trialsTable), traitsPanel); splitPane.setResizeWeight(0.5); add(splitPane, BorderLayout.CENTER); }
From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateImportDialog.java
private void initComponents() { setBackground(UIConstants.BACKGROUND_COLOR); getContentPane().setBackground(getBackground()); topPanel = new JPanel(); topPanel.setBackground(getBackground()); linkPanel = new JPanel(); linkPanel.setBackground(topPanel.getBackground()); linkLeftPanel = new JPanel(); linkLeftPanel.setBackground(linkPanel.getBackground()); linkLeftSelectAllLabel = new JLabel("<html><u>All</u></html>"); linkLeftSelectAllLabel.setForeground(Color.BLUE); linkLeftSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkLeftSelectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { importTreeTable.getModel().setValueAt(true, row, IMPORT_SELECTED_COLUMN); }//from w w w .j a va 2s. c o m } }); linkLeftDeselectAllLabel = new JLabel("<html><u>None</u></html>"); linkLeftDeselectAllLabel.setForeground(Color.BLUE); linkLeftDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkLeftDeselectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { importTreeTable.getModel().setValueAt(false, row, IMPORT_SELECTED_COLUMN); } } }); linkRightPanel = new JPanel(); linkRightPanel.setBackground(linkPanel.getBackground()); linkRightOverwriteAllLabel = new JLabel("<html><u>All</u></html>"); linkRightOverwriteAllLabel.setForeground(Color.BLUE); linkRightOverwriteAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkRightOverwriteAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { TreePath path = importTreeTable.getPathForRow(row); if (path != null) { ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent(); if (node instanceof ImportLibraryTreeTableNode) { ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node; if (libraryNode.getConflicts().getMatchingLibrary() != null) { importTreeTable.getModel().setValueAt(true, row, IMPORT_OVERWRITE_COLUMN); } } else if (node instanceof ImportCodeTemplateTreeTableNode) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node; if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null) { importTreeTable.getModel().setValueAt(true, row, IMPORT_OVERWRITE_COLUMN); } } } } } }); linkRightOverwriteNoneLabel = new JLabel("<html><u>None</u></html>"); linkRightOverwriteNoneLabel.setForeground(Color.BLUE); linkRightOverwriteNoneLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkRightOverwriteNoneLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { TreePath path = importTreeTable.getPathForRow(row); if (path != null) { ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent(); if (node instanceof ImportLibraryTreeTableNode) { ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node; if (libraryNode.getConflicts().getMatchingLibrary() != null) { importTreeTable.getModel().setValueAt(false, row, IMPORT_OVERWRITE_COLUMN); } } else if (node instanceof ImportCodeTemplateTreeTableNode) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node; if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null) { importTreeTable.getModel().setValueAt(false, row, IMPORT_OVERWRITE_COLUMN); } } } } } }); final TableCellEditor templateCellEditor = new NameCellEditor(); importTreeTable = new JXTreeTable() { @Override public boolean isCellEditable(int row, int column) { return (column == IMPORT_OVERWRITE_COLUMN || column == IMPORT_SELECTED_COLUMN || column == IMPORT_NAME_COLUMN); } @Override public TableCellEditor getCellEditor(int row, int column) { if (isHierarchical(column)) { return templateCellEditor; } else { return super.getCellEditor(row, column); } } }; importTreeTable.setLargeModel(true); DefaultTreeTableModel model = new ImportTreeTableModel(); model.setColumnIdentifiers(Arrays.asList(new String[] { "", "Name", "Overwrite", "Conflicts", "Id" })); DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(); model.setRoot(rootNode); importTreeTable.setTreeTableModel(model); Set<String> addedCodeTemplateIds = new HashSet<String>(); if (unassignedCodeTemplates) { ImportTreeTableNode libraryNode = new ImportUnassignedLibraryTreeTableNode("Select a library", ""); CodeTemplateLibrary library = importLibraries.get(0); for (CodeTemplate codeTemplate : library.getCodeTemplates()) { if (!addedCodeTemplateIds.contains(codeTemplate.getId())) { libraryNode .add(new ImportCodeTemplateTreeTableNode(codeTemplate.getName(), codeTemplate.getId())); addedCodeTemplateIds.add(codeTemplate.getId()); importCodeTemplateMap.put(codeTemplate.getId(), codeTemplate); } } rootNode.add(libraryNode); } else { Set<String> addedLibraryIds = new HashSet<String>(); for (CodeTemplateLibrary library : importLibraries) { if (!addedLibraryIds.contains(library.getId())) { ImportTreeTableNode libraryNode = new ImportLibraryTreeTableNode(library.getName(), library.getId()); importLibraryMap.put(library.getId(), library); for (CodeTemplate codeTemplate : library.getCodeTemplates()) { if (!addedCodeTemplateIds.contains(codeTemplate.getId())) { libraryNode.add(new ImportCodeTemplateTreeTableNode(codeTemplate.getName(), codeTemplate.getId())); addedCodeTemplateIds.add(codeTemplate.getId()); importCodeTemplateMap.put(codeTemplate.getId(), codeTemplate); } } rootNode.add(libraryNode); addedLibraryIds.add(library.getId()); } } } importTreeTable.setOpenIcon(null); importTreeTable.setClosedIcon(null); importTreeTable.setLeafIcon(null); importTreeTable.setRootVisible(false); importTreeTable.setDoubleBuffered(true); importTreeTable.setDragEnabled(false); importTreeTable.setRowSelectionAllowed(true); importTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); importTreeTable.setRowHeight(UIConstants.ROW_HEIGHT); importTreeTable.setFocusable(true); importTreeTable.setOpaque(true); importTreeTable.getTableHeader().setReorderingAllowed(false); importTreeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); importTreeTable.setEditable(true); importTreeTable.setSortable(false); importTreeTable.setAutoCreateColumnsFromModel(false); importTreeTable.setShowGrid(true, true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { importTreeTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } importTreeTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { checkSelection(evt); } @Override public void mouseReleased(MouseEvent evt) { checkSelection(evt); } private void checkSelection(MouseEvent evt) { int row = importTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row < 0) { importTreeTable.clearSelection(); } } }); importTreeTable.addTreeWillExpandListener(new TreeWillExpandListener() { @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { } @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { throw new ExpandVetoException(event); } }); importTreeTable.setTreeCellRenderer(new NameCellRenderer()); importTreeTable.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent evt) { if (evt.getColumn() != IMPORT_CONFLICTS_COLUMN) { for (int row = evt.getFirstRow(); row <= evt.getLastRow() && row < importTreeTable.getRowCount(); row++) { TreePath path = importTreeTable.getPathForRow(row); if (path != null) { ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent(); if (path.getPathCount() == 2) { if (node instanceof ImportUnassignedLibraryTreeTableNode) { String libraryName = (String) node.getValueAt(IMPORT_NAME_COLUMN); String libraryId = null; for (CodeTemplateLibrary library : PlatformUI.MIRTH_FRAME.codeTemplatePanel .getCachedCodeTemplateLibraries().values()) { if (library.getName().equals(libraryName)) { libraryId = library.getId(); break; } } node.setValueAt(libraryId, IMPORT_ID_COLUMN); } else if (node instanceof ImportLibraryTreeTableNode) { ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node; libraryNode.setConflicts(getLibraryConflicts(node)); } for (Enumeration<? extends TreeTableNode> codeTemplateNodes = node .children(); codeTemplateNodes.hasMoreElements();) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) codeTemplateNodes .nextElement(); codeTemplateNode.setConflicts(getCodeTemplateConflicts(codeTemplateNode)); } importTreeTable.updateUI(); } else if (path.getPathCount() == 3) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node; codeTemplateNode.setConflicts(getCodeTemplateConflicts(node)); } } } } updateImportButton(); updateErrorsAndWarnings(); } }); importTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { updateImportButton(); updateErrorsAndWarnings(); } } }); importTreeTable.expandAll(); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN).setMinWidth(20); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN).setMaxWidth(20); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN) .setCellRenderer(new ImportSelectedCellRenderer()); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN) .setCellEditor(new ImportSelectedCellEditor()); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN).setMinWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN).setMaxWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN) .setCellRenderer(new OverwriteCellRenderer()); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN) .setCellEditor(new OverwriteCellEditor()); importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setMinWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setMaxWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setCellRenderer(new IconCellRenderer()); importTreeTable.getColumnModel().removeColumn(importTreeTable.getColumnModel().getColumn(IMPORT_ID_COLUMN)); importTreeTableScrollPane = new JScrollPane(importTreeTable); importTreeTableScrollPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(0x6E6E6E))); warningsPanel = new JPanel(); warningsPanel.setBackground(getBackground()); warningsPanel.setVisible(false); warningsLabel = new JLabel(UIConstants.ICON_WARNING); warningsTextArea = new JTextArea(); warningsTextArea.setLineWrap(true); warningsTextArea.setWrapStyleWord(true); errorsPanel = new JPanel(); errorsPanel.setBackground(getBackground()); errorsPanel.setVisible(false); errorsLabel = new JLabel(UIConstants.ICON_ERROR); errorsTextArea = new JTextArea(); errorsTextArea.setLineWrap(true); errorsTextArea.setWrapStyleWord(true); separator = new JSeparator(); buttonPanel = new JPanel(); buttonPanel.setBackground(getBackground()); importButton = new JButton("Import"); importButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { boolean warnings = false; for (Enumeration<? extends TreeTableNode> libraryNodes = ((TreeTableNode) importTreeTable .getTreeTableModel().getRoot()).children(); libraryNodes.hasMoreElements();) { for (Enumeration<? extends TreeTableNode> codeTemplateNodes = libraryNodes.nextElement() .children(); codeTemplateNodes.hasMoreElements();) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) codeTemplateNodes .nextElement(); if ((boolean) codeTemplateNode.getValueAt(IMPORT_SELECTED_COLUMN)) { CodeTemplateConflicts conflicts = codeTemplateNode.getConflicts(); if (conflicts.getMatchingCodeTemplate() != null) { warnings = true; break; } } } if (warnings) { break; } } if (!warnings || PlatformUI.MIRTH_FRAME.alertOption(CodeTemplateImportDialog.this, "Some selected rows have warnings. Are you sure you wish to continue?")) { save(); dispose(); } } catch (Exception e) { PlatformUI.MIRTH_FRAME.alertThrowable(CodeTemplateImportDialog.this, e, "Unable to import: " + e.getMessage()); } } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (confirmClose()) { dispose(); } } }); updateImportButton(); }
From source file:com.mirth.connect.connectors.ws.WebServiceSender.java
private void setAttachments(List<List<String>> attachments) { List<String> attachmentIds = attachments.get(0); List<String> attachmentContents = attachments.get(1); List<String> attachmentTypes = attachments.get(2); Object[][] tableData = new Object[attachmentIds.size()][3]; attachmentsTable = new MirthTable(); for (int i = 0; i < attachmentIds.size(); i++) { tableData[i][ID_COLUMN_NUMBER] = attachmentIds.get(i); tableData[i][CONTENT_COLUMN_NUMBER] = attachmentContents.get(i); tableData[i][MIME_TYPE_COLUMN_NUMBER] = attachmentTypes.get(i); }/* w w w.java 2s. co m*/ attachmentsTable.setModel(new javax.swing.table.DefaultTableModel(tableData, new String[] { ID_COLUMN_NAME, CONTENT_COLUMN_NAME, MIME_TYPE_COLUMN_NAME }) { boolean[] canEdit = new boolean[] { true, true, true }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); attachmentsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (attachmentsTable.getSelectedModelIndex() != -1) { deleteButton.setEnabled(true); } else { deleteButton.setEnabled(false); } } }); class AttachmentsTableCellEditor extends TextFieldCellEditor { boolean checkUnique; public AttachmentsTableCellEditor(boolean checkUnique) { super(); this.checkUnique = checkUnique; } public boolean checkUnique(String value) { boolean exists = false; for (int i = 0; i < attachmentsTable.getModel().getRowCount(); i++) { if (((String) attachmentsTable.getModel().getValueAt(i, ID_COLUMN_NUMBER)) .equalsIgnoreCase(value)) { exists = true; } } return exists; } @Override public boolean isCellEditable(EventObject evt) { boolean editable = super.isCellEditable(evt); if (editable) { deleteButton.setEnabled(false); } return editable; } @Override protected boolean valueChanged(String value) { deleteButton.setEnabled(true); if (checkUnique && (value.length() == 0 || checkUnique(value))) { return false; } parent.setSaveEnabled(true); return true; } } attachmentsTable.getColumnModel().getColumn(attachmentsTable.getColumnModelIndex(ID_COLUMN_NAME)) .setCellEditor(new AttachmentsTableCellEditor(true)); attachmentsTable.getColumnModel().getColumn(attachmentsTable.getColumnModelIndex(CONTENT_COLUMN_NAME)) .setCellEditor(new AttachmentsTableCellEditor(false)); attachmentsTable.getColumnModel().getColumn(attachmentsTable.getColumnModelIndex(MIME_TYPE_COLUMN_NAME)) .setCellEditor(new AttachmentsTableCellEditor(false)); attachmentsTable.setCustomEditorControls(true); attachmentsTable.setSelectionMode(0); attachmentsTable.setRowSelectionAllowed(true); attachmentsTable.setRowHeight(UIConstants.ROW_HEIGHT); attachmentsTable.setDragEnabled(true); attachmentsTable.setTransferHandler(new TransferHandler() { protected Transferable createTransferable(JComponent c) { try { MirthTable table = ((MirthTable) (c)); if (table == null) { return null; } int currRow = table.convertRowIndexToModel(table.getSelectedRow()); String text = ""; if (currRow >= 0 && currRow < table.getModel().getRowCount()) { text = (String) table.getModel().getValueAt(currRow, ID_COLUMN_NUMBER); } text = "<inc:Include href=\"cid:" + text + "\" xmlns:inc=\"http://www.w3.org/2004/08/xop/include\"/>"; return new StringSelection(text); } catch (ClassCastException cce) { return null; } } public int getSourceActions(JComponent c) { return COPY; } public boolean canImport(JComponent c, DataFlavor[] df) { return false; } }); attachmentsTable.setOpaque(true); attachmentsTable.setSortable(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); attachmentsTable.setHighlighters(highlighter); } attachmentsPane.setViewportView(attachmentsTable); deleteButton.setEnabled(false); }
From source file:jboost.visualization.HistogramFrame.java
private JScrollPane getJScrollPane1() { if (jScrollPane1 == null) { jScrollPane1 = new JScrollPane(); jList1 = new JList(infoParser.iterNoList); jList1.setLayout(new FlowLayout()); jList1.setFocusable(false);// ww w . j a va2 s .co m jList1.setIgnoreRepaint(false); jList1.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { JList list = (JList) evt.getSource(); iter = list.getSelectedIndex(); loadIteration(iter); } } }); jScrollPane1.getViewport().add(jList1); } return jScrollPane1; }
From source file:com.diversityarrays.kdxplore.importdata.ImportSourceChoiceDialog.java
public ImportSourceChoiceDialog(SourceChoice sc, Window owner, KdxploreDatabase kdxdb, MessagePrinter mp, Closure<List<Trial>> onTrialsLoaded, BackgroundRunner backgroundRunner) throws IOException, KdxploreConfigException { super(owner, "Load Trial Data", ModalityType.APPLICATION_MODAL); this.sourceChoice = sc; this.kdxDatabase = kdxdb; this.databaseDeviceIdentifier = kdxDatabase.getDatabaseDeviceIdentifier(); this.database = kdxDatabase.getKDXploreKSmartDatabase(); this.backgroundRunner = backgroundRunner; this.messagePrinter = new CompoundMessagePrinter(mp, messagePanel); this.onTrialsLoaded = onTrialsLoaded; DevicesAndOperators devsAndOps = new DevicesAndOperators(System.getProperty("user.name")); //$NON-NLS-1$ devAndOpPanel = new DeviceAndOperatorPanel(kdxdb, devsAndOps, true); devAndOpPanel.addChangeListener(devAndOpChangeListener); // Note: devAndOpPanel.initialise() is done in WindowListener.windowOpened() below StringBuilder sb = new StringBuilder("Drag/Drop "); ImportType[] tmp = null;// www. ja va 2 s.c o m switch (sourceChoice) { case CSV: predicate = new Predicate<DeviceIdentifier>() { @Override public boolean evaluate(DeviceIdentifier devid) { return devid != null && DeviceIdentifier.PLEASE_SELECT_DEVICE_TYPE != devid.getDeviceType(); } }; sb.append("CSV"); tmp = new ImportType[] { ImportType.CSV }; break; case KDX: predicate = new Predicate<DeviceIdentifier>() { @Override public boolean evaluate(DeviceIdentifier devid) { if (devid == null || DeviceIdentifier.PLEASE_SELECT_DEVICE_TYPE == devid.getDeviceType()) { return false; } return DeviceType.KDSMART.equals(devid.getDeviceType()); } }; sb.append(".KDX"); tmp = new ImportType[] { ImportType.KDX }; break; case XLS: devAndOpPanel.disableAddDevice(); predicate = new Predicate<DeviceIdentifier>() { @Override public boolean evaluate(DeviceIdentifier devid) { if (devid == null || DeviceIdentifier.PLEASE_SELECT_DEVICE_TYPE == devid.getDeviceType()) { return false; } return DeviceType.DATABASE.equals(devid.getDeviceType()); } }; sb.append("Excel"); tmp = new ImportType[] { ImportType.KDXPLORE_EXCEL, ImportType.BMS_EXCEL }; break; case DATABASE: default: throw new IllegalStateException("sourceChoice=" + sourceChoice.name()); } importTypes = tmp; if (importTypes == null) { throw new IllegalArgumentException(sourceChoice.name()); } sb.append(" files here"); String prompt = sb.toString(); setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); Container cp = getContentPane(); PromptScrollPane pscrollPane = new PromptScrollPane(fileImportTable, prompt); pscrollPane.setTransferHandler(flth); fileImportTable.setTransferHandler(flth); fileImportTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // fileImportTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); fileImportTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateImportAction(); } } }); final JSplitPane vSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pscrollPane, messagePanel); updateImportAction(); Box buttons = Box.createHorizontalBox(); buttons.add(Box.createHorizontalStrut(4)); buttons.add(new JButton(importAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(errorMessage); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(browseAction)); buttons.add(Box.createHorizontalStrut(4)); errorMessage.setForeground(Color.RED); JPanel top = new JPanel(); GBH gbh = new GBH(top, 2, 2, 2, 2); int y = 0; gbh.add(0, y, 1, 1, GBH.BOTH, 1, 1, GBH.CENTER, devAndOpPanel); ++y; if (RunMode.getRunMode().isDeveloper()) { // Only Developer gets to see the Excel options panel (for now). gbh.add(0, y, 3, 1, GBH.BOTH, 2, 2, GBH.CENTER, bmsOptionsPanel); ++y; } gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, buttons); ++y; cp.add(top, BorderLayout.NORTH); cp.add(vSplit, BorderLayout.CENTER); pack(); GuiUtil.centreOnOwner(ImportSourceChoiceDialog.this); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { vSplit.setDividerLocation(0.5); // NO_BMS bmsOptionsPanel.setVisible(false /* SourceChoice.XLS == sourceChoice */); List<Pair<String, Exception>> errors = devAndOpPanel.initialise(predicate); if (errors.isEmpty()) { List<String> kdxFileNamesWithoutSuffix = new ArrayList<>(); for (int rowIndex = fileImportTableModel.getRowCount(); --rowIndex >= 0;) { File file = fileImportTableModel.getFileAt(rowIndex); String fname = file.getName(); int dotpos = fname.lastIndexOf('.'); if (dotpos > 0) { String sfx = fname.substring(dotpos); if (ExportFor.KDX_SUFFIX.equalsIgnoreCase(sfx)) { kdxFileNamesWithoutSuffix.add(fname.substring(0, dotpos)); } } } if (!kdxFileNamesWithoutSuffix.isEmpty()) { devAndOpPanel.selectInitialDeviceIdentifier(kdxFileNamesWithoutSuffix); } } else { for (Pair<String, Exception> pair : errors) { messagePrinter.println(pair.first + ":"); messagePrinter.println(pair.second.getMessage()); } } } @Override public void windowClosing(WindowEvent e) { if (busy) { GuiUtil.beep(); } else { dispose(); } } }); }
From source file:ca.uhn.hl7v2.testpanel.ui.TestPanelWindow.java
/** * Initialize the contents of the frame. *//*from w w w .j ava 2 s . c o m*/ private void initialize() { myframe = new JFrame(); myframe.setVisible(false); List<Image> l = new ArrayList<Image>(); l.add(Toolkit.getDefaultToolkit() .getImage(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/hapi_16.png"))); l.add(Toolkit.getDefaultToolkit() .getImage(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/hapi_64.png"))); myframe.setIconImages(l); myframe.setTitle("HAPI TestPanel"); myframe.setBounds(100, 100, 796, 603); myframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); myframe.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent theE) { myController.close(); } }); JMenuBar menuBar = new JMenuBar(); myframe.setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('f'); menuBar.add(mnFile); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { myController.close(); } }); JMenuItem mntmNewMessage = new JMenuItem("New Message..."); mntmNewMessage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addMessage(); } }); mntmNewMessage.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/message_hl7.png"))); mnFile.add(mntmNewMessage); mySaveMenuItem = new JMenuItem("Save"); mySaveMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mySaveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doSaveMessages(); } }); mnFile.add(mySaveMenuItem); mySaveAsMenuItem = new JMenuItem("Save As..."); mySaveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doSaveMessagesAs(); } }); mnFile.add(mySaveAsMenuItem); mymenuItem_3 = new JMenuItem("Open"); mymenuItem_3.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mymenuItem_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.openMessages(); } }); myRevertToSavedMenuItem = new JMenuItem("Revert to Saved"); myRevertToSavedMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.revertMessage((Hl7V2MessageCollection) myController.getLeftSelectedItem()); } }); mnFile.add(myRevertToSavedMenuItem); mnFile.add(mymenuItem_3); myRecentFilesMenu = new JMenu("Open Recent"); mnFile.add(myRecentFilesMenu); JSeparator separator = new JSeparator(); mnFile.add(separator); mnFile.add(mntmExit); JMenu mnNewMenu = new JMenu("View"); mnNewMenu.setMnemonic('v'); menuBar.add(mnNewMenu); myShowLogConsoleMenuItem = new JMenuItem("Show Log Console"); myShowLogConsoleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Prefs.getInstance().setShowLogConsole(!Prefs.getInstance().getShowLogConsole()); updateLogScrollPaneVisibility(); myframe.validate(); } }); mnNewMenu.add(myShowLogConsoleMenuItem); mymenu_1 = new JMenu("Test"); menuBar.add(mymenu_1); mymenuItem_1 = new JMenuItem("Populate TestPanel with Sample Message and Connections..."); mymenuItem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.populateWithSampleMessageAndConnections(); } }); mymenu_1.add(mymenuItem_1); mymenu_3 = new JMenu("Tools"); menuBar.add(mymenu_3); mnHl7V2FileDiff = new JMenuItem("HL7 v2 File Diff..."); mnHl7V2FileDiff.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myHl7V2FileDiff == null) { myHl7V2FileDiff = new Hl7V2FileDiffController(myController); } myHl7V2FileDiff.show(); } }); mymenu_3.add(mnHl7V2FileDiff); mymenuItem_5 = new JMenuItem("HL7 v2 File Sort..."); mymenuItem_5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myHl7V2FileSort == null) { myHl7V2FileSort = new Hl7V2FileSortController(myController); } myHl7V2FileSort.show(); } }); mymenu_3.add(mymenuItem_5); mymenu_2 = new JMenu("Conformance"); menuBar.add(mymenu_2); mymenuItem_2 = new JMenuItem("Profiles and Tables..."); mymenuItem_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.showProfilesAndTablesEditor(); } }); mymenu_2.add(mymenuItem_2); mymenu = new JMenu("Help"); mymenu.setMnemonic('H'); menuBar.add(mymenu); mymenuItem = new JMenuItem("About HAPI TestPanel..."); mymenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showAboutDialog(); } }); mymenuItem.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/hapi_16.png"))); mymenu.add(mymenuItem); mymenuItem_4 = new JMenuItem("Licenses..."); mymenuItem_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new LicensesDialog().setVisible(true); } }); mymenu.add(mymenuItem_4); myframe.getContentPane().setLayout(new BorderLayout(0, 0)); JSplitPane outerSplitPane = new JSplitPane(); outerSplitPane.setBorder(null); myframe.getContentPane().add(outerSplitPane); JSplitPane leftSplitPane = new JSplitPane(); leftSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); outerSplitPane.setLeftComponent(leftSplitPane); JPanel messagesPanel = new JPanel(); leftSplitPane.setLeftComponent(messagesPanel); GridBagLayout gbl_messagesPanel = new GridBagLayout(); gbl_messagesPanel.columnWidths = new int[] { 110, 0 }; gbl_messagesPanel.rowHeights = new int[] { 20, 30, 118, 0, 0 }; gbl_messagesPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_messagesPanel.rowWeights = new double[] { 0.0, 0.0, 100.0, 1.0, Double.MIN_VALUE }; messagesPanel.setLayout(gbl_messagesPanel); JLabel lblMessages = new JLabel("Messages"); GridBagConstraints gbc_lblMessages = new GridBagConstraints(); gbc_lblMessages.insets = new Insets(0, 0, 5, 0); gbc_lblMessages.gridx = 0; gbc_lblMessages.gridy = 0; messagesPanel.add(lblMessages, gbc_lblMessages); JToolBar messagesToolBar = new JToolBar(); messagesToolBar.setFloatable(false); messagesToolBar.setRollover(true); messagesToolBar.setAlignmentX(Component.LEFT_ALIGNMENT); GridBagConstraints gbc_messagesToolBar = new GridBagConstraints(); gbc_messagesToolBar.insets = new Insets(0, 0, 5, 0); gbc_messagesToolBar.weightx = 1.0; gbc_messagesToolBar.anchor = GridBagConstraints.NORTHWEST; gbc_messagesToolBar.gridx = 0; gbc_messagesToolBar.gridy = 1; messagesPanel.add(messagesToolBar, gbc_messagesToolBar); JButton msgOpenButton = new JButton(""); msgOpenButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.openMessages(); } }); myAddMessageButton = new JButton(""); myAddMessageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addMessage(); } }); myAddMessageButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/add.png"))); myAddMessageButton.setToolTipText("New Message"); myAddMessageButton.setBorderPainted(false); myAddMessageButton.addMouseListener(new HoverButtonMouseAdapter(myAddMessageButton)); messagesToolBar.add(myAddMessageButton); myDeleteMessageButton = new JButton(""); myDeleteMessageButton.setToolTipText("Close Selected Message"); myDeleteMessageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.closeMessage((Hl7V2MessageCollection) myController.getLeftSelectedItem()); } }); myDeleteMessageButton.setBorderPainted(false); myDeleteMessageButton.addMouseListener(new HoverButtonMouseAdapter(myDeleteMessageButton)); myDeleteMessageButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/close.png"))); messagesToolBar.add(myDeleteMessageButton); msgOpenButton.setBorderPainted(false); msgOpenButton.setToolTipText("Open Messages from File"); msgOpenButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/open.png"))); msgOpenButton.addMouseListener(new HoverButtonMouseAdapter(msgOpenButton)); messagesToolBar.add(msgOpenButton); myMsgSaveButton = new JButton(""); myMsgSaveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doSaveMessages(); } }); myMsgSaveButton.setBorderPainted(false); myMsgSaveButton.setToolTipText("Save Selected Messages to File"); myMsgSaveButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/save.png"))); myMsgSaveButton.addMouseListener(new HoverButtonMouseAdapter(myMsgSaveButton)); messagesToolBar.add(myMsgSaveButton); myMessagesList = new JList(); myMessagesList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (myMessagesList.getSelectedIndex() >= 0) { ourLog.debug("New messages selection " + myMessagesList.getSelectedIndex()); myController.setLeftSelectedItem(myMessagesList.getSelectedValue()); myOutboundConnectionsList.clearSelection(); myOutboundConnectionsList.repaint(); myInboundConnectionsList.clearSelection(); myInboundConnectionsList.repaint(); } updateLeftToolbarButtons(); } }); GridBagConstraints gbc_MessagesList = new GridBagConstraints(); gbc_MessagesList.gridheight = 2; gbc_MessagesList.weightx = 1.0; gbc_MessagesList.weighty = 1.0; gbc_MessagesList.fill = GridBagConstraints.BOTH; gbc_MessagesList.gridx = 0; gbc_MessagesList.gridy = 2; messagesPanel.add(myMessagesList, gbc_MessagesList); JPanel connectionsPanel = new JPanel(); leftSplitPane.setRightComponent(connectionsPanel); GridBagLayout gbl_connectionsPanel = new GridBagLayout(); gbl_connectionsPanel.columnWidths = new int[] { 194, 0 }; gbl_connectionsPanel.rowHeights = new int[] { 0, 30, 0, 0, 0, 0, 0 }; gbl_connectionsPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_connectionsPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; connectionsPanel.setLayout(gbl_connectionsPanel); JLabel lblConnections = new JLabel("Sending Connections"); lblConnections.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_lblConnections = new GridBagConstraints(); gbc_lblConnections.insets = new Insets(0, 0, 5, 0); gbc_lblConnections.anchor = GridBagConstraints.NORTH; gbc_lblConnections.fill = GridBagConstraints.HORIZONTAL; gbc_lblConnections.gridx = 0; gbc_lblConnections.gridy = 0; connectionsPanel.add(lblConnections, gbc_lblConnections); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); GridBagConstraints gbc_toolBar = new GridBagConstraints(); gbc_toolBar.insets = new Insets(0, 0, 5, 0); gbc_toolBar.anchor = GridBagConstraints.NORTH; gbc_toolBar.fill = GridBagConstraints.HORIZONTAL; gbc_toolBar.gridx = 0; gbc_toolBar.gridy = 1; connectionsPanel.add(toolBar, gbc_toolBar); myAddConnectionButton = new JButton(""); myAddConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addOutboundConnection(); } }); myAddConnectionButton.setBorderPainted(false); myAddConnectionButton.addMouseListener(new HoverButtonMouseAdapter(myAddConnectionButton)); myAddConnectionButton.setBorder(null); myAddConnectionButton.setToolTipText("New Connection"); myAddConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/add.png"))); toolBar.add(myAddConnectionButton); myDeleteOutboundConnectionButton = new JButton(""); myDeleteOutboundConnectionButton.setToolTipText("Delete Selected Connection"); myDeleteOutboundConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof OutboundConnection) { myController.removeOutboundConnection((OutboundConnection) myController.getLeftSelectedItem()); } } }); myDeleteOutboundConnectionButton.setBorderPainted(false); myDeleteOutboundConnectionButton .addMouseListener(new HoverButtonMouseAdapter(myDeleteOutboundConnectionButton)); myDeleteOutboundConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/delete.png"))); toolBar.add(myDeleteOutboundConnectionButton); myStartOneOutboundButton = new JButton(""); myStartOneOutboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof OutboundConnection) { myController.startOutboundConnection((OutboundConnection) myController.getLeftSelectedItem()); } } }); myStartOneOutboundButton.setBorderPainted(false); myStartOneOutboundButton.setToolTipText("Start selected connection"); myStartOneOutboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_one.png"))); myStartOneOutboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartOneOutboundButton)); toolBar.add(myStartOneOutboundButton); myStartAllOutboundButton = new JButton(""); myStartAllOutboundButton.setBorderPainted(false); myStartAllOutboundButton.setToolTipText("Start all sending connections"); myStartAllOutboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_all.png"))); myStartAllOutboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartAllOutboundButton)); myStartAllOutboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { myController.startAllOutboundConnections(); } }); toolBar.add(myStartAllOutboundButton); myStopAllOutboundButton = new JButton(""); myStopAllOutboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.stopAllOutboundConnections(); } }); myStopAllOutboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/stop_all.png"))); myStopAllOutboundButton.setToolTipText("Stop all sending connections"); myStopAllOutboundButton.setBorderPainted(false); myStopAllOutboundButton.addMouseListener(new HoverButtonMouseAdapter(myStopAllOutboundButton)); toolBar.add(myStopAllOutboundButton); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(null); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.fill = GridBagConstraints.BOTH; gbc_scrollPane.insets = new Insets(0, 0, 5, 0); gbc_scrollPane.gridx = 0; gbc_scrollPane.gridy = 2; connectionsPanel.add(scrollPane, gbc_scrollPane); myOutboundConnectionsList = new JList(); myOutboundConnectionsList.setBorder(null); myOutboundConnectionsList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (myOutboundConnectionsList.getSelectedIndex() >= 0) { ourLog.debug( "New outbound connection selection " + myOutboundConnectionsList.getSelectedIndex()); myController.setLeftSelectedItem(myOutboundConnectionsList.getSelectedValue()); myMessagesList.clearSelection(); myMessagesList.repaint(); myInboundConnectionsList.clearSelection(); myInboundConnectionsList.repaint(); } updateLeftToolbarButtons(); } }); scrollPane.setViewportView(myOutboundConnectionsList); JLabel lblReceivingConnections = new JLabel("Receiving Connections"); lblReceivingConnections.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_lblReceivingConnections = new GridBagConstraints(); gbc_lblReceivingConnections.insets = new Insets(0, 0, 5, 0); gbc_lblReceivingConnections.gridx = 0; gbc_lblReceivingConnections.gridy = 3; connectionsPanel.add(lblReceivingConnections, gbc_lblReceivingConnections); JToolBar toolBar_1 = new JToolBar(); toolBar_1.setFloatable(false); GridBagConstraints gbc_toolBar_1 = new GridBagConstraints(); gbc_toolBar_1.anchor = GridBagConstraints.WEST; gbc_toolBar_1.insets = new Insets(0, 0, 5, 0); gbc_toolBar_1.gridx = 0; gbc_toolBar_1.gridy = 4; connectionsPanel.add(toolBar_1, gbc_toolBar_1); myAddInboundConnectionButton = new JButton(""); myAddInboundConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addInboundConnection(); } }); myAddInboundConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/add.png"))); myAddInboundConnectionButton.setToolTipText("New Connection"); myAddInboundConnectionButton.setBorderPainted(false); myAddInboundConnectionButton.addMouseListener(new HoverButtonMouseAdapter(myAddInboundConnectionButton)); toolBar_1.add(myAddInboundConnectionButton); myDeleteInboundConnectionButton = new JButton(""); myDeleteInboundConnectionButton.setToolTipText("Delete Selected Connection"); myDeleteInboundConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof InboundConnection) { myController.removeInboundConnection((InboundConnection) myController.getLeftSelectedItem()); } } }); myDeleteInboundConnectionButton.setBorderPainted(false); myDeleteInboundConnectionButton .addMouseListener(new HoverButtonMouseAdapter(myDeleteInboundConnectionButton)); myDeleteInboundConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/delete.png"))); toolBar_1.add(myDeleteInboundConnectionButton); myStartOneInboundButton = new JButton(""); myStartOneInboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof InboundConnection) { myController.startInboundConnection((InboundConnection) myController.getLeftSelectedItem()); } } }); myStartOneInboundButton.setBorderPainted(false); myStartOneInboundButton.setToolTipText("Start selected connection"); myStartOneInboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_one.png"))); myStartOneInboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartOneInboundButton)); toolBar_1.add(myStartOneInboundButton); myStartAllInboundButton = new JButton(""); myStartAllInboundButton.setBorderPainted(false); myStartAllInboundButton.setToolTipText("Start all receiving connections"); myStartAllInboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_all.png"))); myStartAllInboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartAllInboundButton)); myStartAllInboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { myController.startAllInboundConnections(); } }); toolBar_1.add(myStartAllInboundButton); myStopAllInboundButton = new JButton(""); myStopAllInboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.stopAllInboundConnections(); } }); myStopAllInboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/stop_all.png"))); myStopAllInboundButton.setToolTipText("Stop all receiving connections"); myStopAllInboundButton.setBorderPainted(false); myStopAllInboundButton.addMouseListener(new HoverButtonMouseAdapter(myStopAllInboundButton)); toolBar_1.add(myStopAllInboundButton); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBorder(null); GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints(); gbc_scrollPane_1.fill = GridBagConstraints.BOTH; gbc_scrollPane_1.gridx = 0; gbc_scrollPane_1.gridy = 5; connectionsPanel.add(scrollPane_1, gbc_scrollPane_1); myInboundConnectionsList = new JList(); myInboundConnectionsList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (myInboundConnectionsList.getSelectedIndex() >= 0) { ourLog.debug("New inbound connection selection " + myInboundConnectionsList.getSelectedIndex()); myController.setLeftSelectedItem(myInboundConnectionsList.getSelectedValue()); myMessagesList.clearSelection(); myMessagesList.repaint(); myOutboundConnectionsList.clearSelection(); myOutboundConnectionsList.repaint(); myInboundConnectionsList.repaint(); } updateLeftToolbarButtons(); } }); scrollPane_1.setViewportView(myInboundConnectionsList); leftSplitPane.setDividerLocation(200); myWorkspacePanel = new JPanel(); myWorkspacePanel.setBorder(null); outerSplitPane.setRightComponent(myWorkspacePanel); myWorkspacePanel.setLayout(new BorderLayout(0, 0)); outerSplitPane.setDividerLocation(200); myLogScrollPane = new LogTable(); myLogScrollPane.setPreferredSize(new Dimension(454, 120)); myLogScrollPane.setMaximumSize(new Dimension(32767, 120)); myframe.getContentPane().add(myLogScrollPane, BorderLayout.SOUTH); updateLogScrollPaneVisibility(); updateLeftToolbarButtons(); }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * /*from w w w . j ava2 s. c o m*/ */ private void createUI() { IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$ System.setProperty("edu.ku.brc.ui.db.PickListDBAdapterFactory", //$NON-NLS-1$ "edu.ku.brc.specify.tools.StrLocPickListFactory"); // Needed By the Auto Cosmplete UI //$NON-NLS-1$ CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "p,4px,f:p:g,4px,p"), this); pb.addSeparator("Localize", cc.xyw(1, 1, 3)); termList = new JList(new ItemModel(srcFile)); newTermList = new JList(newKeyList); srcLbl = UIHelper.createTextArea(3, 40); srcLbl.setBorder(new LineBorder(srcLbl.getForeground())); textField = UIHelper.createTextField(40); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { hasChanged = true; } }); statusBar = new JStatusBar(); statusBar.setSectionText(1, " "); //$NON-NLS-1$ //$NON-NLS-2$ UIRegistry.setStatusBar(statusBar); srcLbl.setEditable(false); rsController = new ResultSetController(null, false, false, false, "", 1, true); //transBtn = UIHelper.createButton(getResourceString("StrLocalizerApp.Translate")); PanelBuilder pbr = new PanelBuilder( new FormLayout("r:p,2px,f:p:g", "p, 4px, c:p,4px,p,4px,p,4px,p,4px,p,10px,p,2px,f:p:g")); pbr.add(UIHelper.createLabel(getResourceString("StrLocalizerApp.FileLbl")), cc.xy(1, 1)); fileLbl = UIHelper.createLabel(" "); pbr.add(fileLbl, cc.xy(3, 1)); pbr.add(UIHelper.createLabel("English:"), cc.xy(1, 3)); pbr.add(srcLbl, cc.xy(3, 3)); destLbl = UIHelper.createFormLabel(destLanguage.getEnglishName()); pbr.add(destLbl, cc.xy(1, 5)); pbr.add(textField, cc.xy(3, 5)); pbr.add(rsController.getPanel(), cc.xyw(1, 7, 3)); //pbr.add(transBtn, cc.xy(1, 9)); pbr.addSeparator("Searching", cc.xyw(1, 11, 3)); searchBtn = createButton(getResourceString("SEARCH")); searchBtn.setToolTipText(getResourceString("ExpressSearchTT")); searchText = new JAutoCompTextField(15, PickListDBAdapterFactory.getInstance().create("ExpressSearch", true)); searchText.setAskBeforeSave(false); searchBox = new SearchBox(searchText, null, true); searchText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { fndKeyHash.clear(); results.clear(); String txt = searchText.getText(); if (!txt.isEmpty()) { doSearch(txt, "key"); doSearch(txt, "src"); doSearch(txt, "dst"); } model.fireChanges(); } } }); pbr.add(searchBox, cc.xyw(1, 13, 3)); model = new SearchResultsModel(); searchResultsTbl = new JTable(model); pbr.add(UIHelper.createScrollPane(searchResultsTbl), cc.xyw(1, 15, 3)); searchResultsTbl.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { //tableRowSelected(); if (results != null && results.size() > 0 && searchResultsTbl.getSelectedRow() > -1) { StrLocaleEntry entry = (StrLocaleEntry) results.get(searchResultsTbl.getSelectedRow()); if (entry != null) { int listIndex = srcFile.getInxForKey(entry.getKey()); termList.setSelectedIndex(listIndex); termList.ensureIndexIsVisible(listIndex); } } } }); PanelBuilder pbl = new PanelBuilder(new FormLayout("f:p:g", "f:p:g,10px,p,4px,f:p:g")); JScrollPane sp = UIHelper.createScrollPane(termList); JScrollPane nsp = UIHelper.createScrollPane(newTermList); pbl.add(sp, cc.xy(1, 1)); pbl.addSeparator("New Items", cc.xy(1, 3)); pbl.add(nsp, cc.xy(1, 5)); pb.add(pbl.getPanel(), cc.xy(1, 3)); pb.add(pbr.getPanel(), cc.xy(3, 3)); pb.add(statusBar, cc.xyw(1, 5, 3)); ResultSetController.setBackStopRS(rsController); pb.setDefaultDialogBorder(); mainPane = pb.getPanel(); termList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { listSelected(); } }); newTermList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { newListSelected(); } }); transBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String txt = srcLbl.getText(); String newText = translate(txt); if (StringUtils.isNotEmpty(newText)) { newText = newText.replace("'", "'"); textField.setText(newText); StrLocaleEntry entry = srcFile.getKey(termList.getSelectedIndex()); entry.setDstStr(textField.getText()); } } }); rscListener = new ResultSetControllerListener() { @Override public void newRecordAdded() { } @Override public void indexChanged(int newIndex) { termList.setSelectedIndex(newIndex); } @Override public boolean indexAboutToChange(int oldIndex, int newIndex) { return true; } }; rsController.addListener(rscListener); frame.pack(); }
From source file:com.diversityarrays.kdxplore.trials.TrialViewPanel.java
public TrialViewPanel(WindowOpener<JFrame> windowOpener, OfflineData od, Transformer<Trial, Boolean> checkIfEditorActive, Consumer<Trial> onTraitInstancesRemoved, MessagePrinter mp) {/*from w w w .ja v a 2s . c om*/ super(new BorderLayout()); this.windowOpener = windowOpener; this.checkIfEditorActive = checkIfEditorActive; this.onTraitInstancesRemoved = onTraitInstancesRemoved; this.messagePrinter = mp; this.offlineData = od; this.offlineData.addOfflineDataChangeListener(offlineDataChangeListener); KdxploreDatabase db = offlineData.getKdxploreDatabase(); if (db != null) { db.addEntityChangeListener(trialChangeListener); } trialDataTable.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(trialDataTable, true)); trialPropertiesTable .setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(trialPropertiesTable, true)); // Note: Can't use renderers because the TM always returns String.class // for getColumnClass() // trialPropertiesTable.setDefaultRenderer(TrialLayout.class, new // TrialLayoutRenderer(trialPropertiesTableModel)); // trialPropertiesTable.setDefaultRenderer(PlotIdentOption.class, new // PlotIdentOptionRenderer(trialPropertiesTableModel)); trialPropertiesTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (trialPropertiesTableModel.getRowCount() > 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GuiUtil.initialiseTableColumnWidths(trialPropertiesTable); } }); trialPropertiesTableModel.removeTableModelListener(this); } } }); // int tnsColumnIndex = -1; // for (int col = trialPropertiesTableModel.getColumnCount(); --col >= 0; ) { // if (TraitNameStyle.class == trialPropertiesTableModel.getColumnClass(col)) { // tnsColumnIndex = col; // break; // } // } editAction.setEnabled(false); trialPropertiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int vrow = trialPropertiesTable.getSelectedRow(); editAction.setEnabled(vrow >= 0 && trialPropertiesTableModel.isCellEditable(vrow, 1)); } } }); errorMessage.setForeground(Color.RED); Box top = Box.createHorizontalBox(); top.add(errorMessage); top.add(Box.createHorizontalGlue()); top.add(new JButton(editAction)); JPanel main = new JPanel(new BorderLayout()); main.add(new JScrollPane(trialPropertiesTable), BorderLayout.CENTER); main.add(legendPanel, BorderLayout.SOUTH); JScrollPane trialDataTableScrollPane = new JScrollPane(trialDataTable); // The preferred height of the viewport is determined // by whether or not we need to use hh:mm:ss in the name of any of // the scoring data sets. JViewport viewPort = new JViewport() { @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.height = 32; TableModel model = trialDataTable.getModel(); if (model instanceof TrialData) { if (((TrialData) model).isUsingHMSformat()) { d.height = 48; } } return d; } }; trialDataTableScrollPane.setColumnHeader(viewPort); JTableHeader th = trialDataTable.getTableHeader(); th.setDefaultRenderer(trialDataTableHeaderRenderer); th.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int column = th.columnAtPoint(e.getPoint()); trialDataTableHeaderRenderer.columnSelected = column; boolean shifted = 0 != (MouseEvent.SHIFT_MASK & e.getModifiers()); boolean right = SwingUtilities.isRightMouseButton(e); updateDeleteSamplesAction(shifted, right); e.consume(); } }); trialDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { removeTraitInstancesAction.setEnabled(trialDataTable.getSelectedRowCount() > 0); } } }); removeTraitInstancesAction.setEnabled(false); KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addSampleGroupAction, Msg.TOOLTIP_ADD_SAMPLES_FOR_SCORING()); KDClientUtils.initAction(ImageId.TRASH_24, deleteSamplesAction, Msg.TOOLTIP_DELETE_COLLECTED_SAMPLES()); KDClientUtils.initAction(ImageId.EXPORT_24, exportSamplesAction, Msg.TOOLTIP_EXPORT_SAMPLES_OR_TRAITS()); KDClientUtils.initAction(ImageId.MINUS_GOLD_24, removeTraitInstancesAction, Msg.TOOLTIP_REMOVE_TRAIT_INSTANCES_WITH_NO_DATA()); JPanel trialDataPanel = new JPanel(new BorderLayout()); Box buttons = Box.createHorizontalBox(); buttons.add(new JButton(removeTraitInstancesAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(exportSamplesAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(addSampleGroupAction)); buttons.add(Box.createHorizontalStrut(8)); buttons.add(new JButton(deleteSamplesAction)); trialDataPanel.add(GuiUtil.createLabelSeparator("Measurements by Source", buttons), BorderLayout.NORTH); trialDataPanel.add(trialDataTableScrollPane, BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, main, trialDataPanel); splitPane.setResizeWeight(0.5); add(top, BorderLayout.NORTH); add(splitPane, BorderLayout.CENTER); trialDataTable.setDefaultRenderer(Object.class, new TrialDataCellRenderer()); trialDataTable.addPropertyChangeListener("model", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { trialDataTableHeaderRenderer.columnSelected = -1; updateDeleteSamplesAction(false, false); } }); }
From source file:de.codesourcery.eve.skills.ui.components.impl.planning.ShoppingListComponent.java
@Override protected JPanel createPanel() { table.setFillsViewportHeight(true);// w w w. j a v a 2 s.co m table.setRowSorter(tableModel.getRowSorter()); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { final int[] selectedViewRows = table.getSelectedRows(); final int[] selectedModelRows = new int[selectedViewRows.length]; int i = 0; for (int viewRow : selectedViewRows) { selectedModelRows[i++] = viewRow; } List<TableRow> selection = new ArrayList<TableRow>(); for (int modelRow : selectedModelRows) { selection.add(tableModel.getRow(modelRow)); } totalValue.setItems(selection); totalVolume.setItems(selection); } }); FixedBooleanTableCellRenderer.attach(table); final JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); final JPanel controlsPanel = new JPanel(); controlsPanel.setLayout(new GridBagLayout()); controlsPanel.add(this.tableViewModePanel, constraints(0, 0).useRemainingWidth().end()); final JPanel totalsPanel = new JPanel(); totalsPanel.setLayout(new GridBagLayout()); totalsPanel.add(totalValue.getPanel(), constraints(0, 0).weightX(0.2).width(1).weightY(0).anchorWest().end()); totalsPanel.add(totalVolume.getPanel(), constraints(1, 0).weightX(0.2).width(1).weightY(0).anchorWest().end()); final JPanel rest = new JPanel(); rest.setLayout(new GridBagLayout()); rest.add(componentPanel, constraints(0, 0).weightX(0.2).width(1).weightY(0.3).anchorWest().end()); rest.add(totalsPanel, constraints(0, 1).weightX(0.2).width(1).weightY(0).resizeHorizontally().anchorWest().end()); rest.add(controlsPanel, constraints(0, 2).weightX(0.2).width(1).weightY(0).resizeHorizontally().anchorWest().end()); rest.add(new JScrollPane(table), constraints(0, 3).weightX(0.2).width(1).weightY(0.7).resizeBoth().anchorWest().end()); // new GridLayoutBuilder().add( // new VerticalGroup( new Cell( componentPanel ), // new FixedCell( controlsPanel ), // new FixedCell( totalsPanel ), // new Cell( new JScrollPane( table ) ) ) ).addTo( rest ); final ImprovedSplitPane splitPane = new ImprovedSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tree), rest); panel.add(splitPane, constraints(0, 0).resizeBoth().end()); tree.setRootVisible(false); tree.setCellRenderer(cellRenderer); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { final TreePath selection = e.getPath(); selectedNodeChanged((ITreeNode) (selection != null ? selection.getLastPathComponent() : null)); } }); final PopupMenuBuilder menuBuilder = new PopupMenuBuilder(); menuBuilder.addItem("New shopping list...", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final ShoppingListEditorComponent comp = new ShoppingListEditorComponent("New list", "", new ArrayList<ItemWithQuantity>()); comp.setModal(true); ComponentWrapper.wrapComponent("Create new shopping list", comp).setVisible(true); if (!comp.wasCancelled()) { manager.addShoppingList(comp.getShoppingList()); } } }); menuBuilder.addItem("Edit list...", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final ITreeNode node = getSelectedTreeNode(); if (node == null) { return; } final ShoppingList list = (ShoppingList) node.getValue(); final ShoppingListEditorComponent comp = new ShoppingListEditorComponent(list); comp.setModal(true); ComponentWrapper.wrapComponent(list.getTitle(), comp).setVisible(true); if (!comp.wasCancelled() && comp.isExistingEntryEdited()) { manager.shoppingListChanged(comp.getShoppingList()); } } @Override public boolean isEnabled() { final ITreeNode node = getSelectedTreeNode(); return node != null && node.getValue() instanceof ShoppingList; } }); menuBuilder.addItem("Delete item", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final ITreeNode node = getSelectedTreeNode(); if (node != null && node.getValue() instanceof ShoppingListEntry) { final ShoppingListEntry entry = (ShoppingListEntry) node.getValue(); final ShoppingList list = entry.getShoppingList(); manager.removeEntry(list, entry); selectedNodeChanged(null); } } @Override public boolean isEnabled() { final ITreeNode node = getSelectedTreeNode(); return node != null && node.getValue() instanceof ShoppingListEntry; } }); menuBuilder.addItem("Delete list", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final ShoppingList list = getSelectedShoppingList(); if (list != null) { manager.removeShoppingList(list); selectedNodeChanged(null); } } @Override public boolean isEnabled() { final ITreeNode node = getSelectedTreeNode(); return node.getValue() instanceof ShoppingList; } }); menuBuilder.addItem("Copy this list to clipboard (text)", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { putSelectedShoppingListOnClipboard(); } @Override public boolean isEnabled() { return getSelectedShoppingList() != null; } }); menuBuilder.attach(tree); return panel; }
From source file:com.mirth.connect.client.ui.ChannelSetup.java
/** * Makes the destination table with a parameter that is true if a new destination should be * added as well./* w ww . j a va 2 s.c o m*/ */ public void makeDestinationTable(boolean addNew) { List<Connector> destinationConnectors; Object[][] tableData; int tableSize; destinationConnectors = currentChannel.getDestinationConnectors(); tableSize = destinationConnectors.size(); if (addNew) { tableSize++; } int chain = 1; tableData = new Object[tableSize][5]; for (int i = 0; i < tableSize; i++) { if (tableSize - 1 == i && addNew) { Connector connector = makeNewConnector(true); // Set the default inbound and outbound dataType and properties String dataType = currentChannel.getSourceConnector().getTransformer().getOutboundDataType(); // Use a different properties object for the inbound and outbound DataTypeProperties defaultInboundProperties = LoadedExtensions.getInstance().getDataTypePlugins() .get(dataType).getDefaultProperties(); DataTypeProperties defaultOutboundProperties = LoadedExtensions.getInstance().getDataTypePlugins() .get(dataType).getDefaultProperties(); DataTypeProperties defaultResponseInboundProperties = LoadedExtensions.getInstance() .getDataTypePlugins().get(dataType).getDefaultProperties(); DataTypeProperties defaultResponseOutboundProperties = LoadedExtensions.getInstance() .getDataTypePlugins().get(dataType).getDefaultProperties(); connector.getTransformer().setInboundDataType(dataType); connector.getTransformer().setInboundProperties(defaultInboundProperties); connector.getTransformer().setOutboundDataType(dataType); connector.getTransformer().setOutboundProperties(defaultOutboundProperties); connector.getResponseTransformer().setInboundDataType(dataType); connector.getResponseTransformer().setInboundProperties(defaultResponseInboundProperties); connector.getResponseTransformer().setOutboundDataType(dataType); connector.getResponseTransformer().setOutboundProperties(defaultResponseOutboundProperties); connector.setName(getNewDestinationName(tableSize)); connector.setTransportName(DESTINATION_DEFAULT); // We need to add the destination first so that the metadata ID is initialized. currentChannel.addDestination(connector); if (connector.isEnabled()) { tableData[i][0] = new CellData( new ImageIcon( com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_blue.png")), UIConstants.ENABLED_STATUS); } else { tableData[i][0] = new CellData( new ImageIcon( com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_black.png")), UIConstants.DISABLED_STATUS); } tableData[i][1] = connector.getName(); tableData[i][2] = connector.getMetaDataId(); tableData[i][3] = new ConnectorTypeData(destinationConnectors.get(i).getTransportName()); if (i > 0 && !connector.isWaitForPrevious()) { chain++; } tableData[i][4] = chain; } else { if (destinationConnectors.get(i).isEnabled()) { tableData[i][0] = new CellData( new ImageIcon( com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_blue.png")), UIConstants.ENABLED_STATUS); } else { tableData[i][0] = new CellData( new ImageIcon( com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_black.png")), UIConstants.DISABLED_STATUS); } tableData[i][1] = destinationConnectors.get(i).getName(); tableData[i][2] = destinationConnectors.get(i).getMetaDataId(); tableData[i][3] = new ConnectorTypeData(destinationConnectors.get(i).getTransportName()); if (i > 0 && !destinationConnectors.get(i).isWaitForPrevious()) { chain++; } tableData[i][4] = chain; } } destinationTable = new MirthTable(); destinationTable.setModel(new javax.swing.table.DefaultTableModel(tableData, new String[] { STATUS_COLUMN_NAME, DESTINATION_COLUMN_NAME, METADATA_COLUMN_NAME, CONNECTOR_TYPE_COLUMN_NAME, DESTINATION_CHAIN_COLUMN_NAME }) { boolean[] canEdit = new boolean[] { false, true, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); destinationTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // Set the custom cell editor for the Destination Name column. destinationTable.getColumnModel() .getColumn(destinationTable.getColumnModel().getColumnIndex(DESTINATION_COLUMN_NAME)) .setCellEditor(new DestinationTableCellEditor()); destinationTable.setCustomEditorControls(true); // Must set the maximum width on columns that should be packed. destinationTable.getColumnExt(STATUS_COLUMN_NAME).setMaxWidth(UIConstants.MAX_WIDTH); destinationTable.getColumnExt(STATUS_COLUMN_NAME).setMinWidth(UIConstants.MIN_WIDTH); // Set the cell renderer for the status column. destinationTable.getColumnExt(STATUS_COLUMN_NAME).setCellRenderer(new ImageCellRenderer()); // Set the maximum width and cell renderer for the metadata ID column destinationTable.getColumnExt(METADATA_COLUMN_NAME).setMaxWidth(UIConstants.METADATA_ID_COLUMN_WIDTH); destinationTable.getColumnExt(METADATA_COLUMN_NAME).setMinWidth(UIConstants.METADATA_ID_COLUMN_WIDTH); destinationTable.getColumnExt(METADATA_COLUMN_NAME) .setCellRenderer(new NumberCellRenderer(SwingConstants.CENTER, false)); // Set the cell renderer for the destination connector type destinationTable.getColumnExt(CONNECTOR_TYPE_COLUMN_NAME).setCellRenderer(new ConnectorTypeCellRenderer()); // Set the cell renderer and the max width for the destination chain column destinationTable.getColumnExt(DESTINATION_CHAIN_COLUMN_NAME) .setCellRenderer(new NumberCellRenderer(SwingConstants.CENTER, false)); destinationTable.getColumnExt(DESTINATION_CHAIN_COLUMN_NAME).setMaxWidth(50); destinationTable.setSelectionMode(0); destinationTable.setRowSelectionAllowed(true); destinationTable.setRowHeight(UIConstants.ROW_HEIGHT); destinationTable.setFocusable(true); destinationTable.setSortable(false); destinationTable.getTableHeader().setReorderingAllowed(false); destinationTable.setOpaque(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); destinationTable.setHighlighters(highlighter); } // This action is called when a new selection is made on the destination // table. destinationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { if (lastModelIndex != -1 && lastModelIndex != destinationTable.getRowCount() && !isDeleting) { Connector destinationConnector = currentChannel.getDestinationConnectors() .get(lastModelIndex); ConnectorProperties props = destinationConnectorPanel.getProperties(); ((DestinationConnectorPropertiesInterface) props).getDestinationConnectorProperties() .setResourceIds(resourceIds.get(destinationConnector.getMetaDataId())); destinationConnector.setProperties(props); } if (!loadConnector()) { if (lastModelIndex == destinationTable.getRowCount()) { destinationTable.setRowSelectionInterval(lastModelIndex - 1, lastModelIndex - 1); } else { destinationTable.setRowSelectionInterval(lastModelIndex, lastModelIndex); } } else { lastModelIndex = destinationTable.getSelectedModelIndex(); } /* * Loading the connector may have updated the current destination with incorrect * properties, so after updating lastModelIndex we need to update the * destination panel again. */ saveDestinationPanel(); checkVisibleDestinationTasks(); } } }); destinationTable.requestFocus(); // Mouse listener for trigger-button popup on the table. destinationTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { checkSelectionAndPopupMenu(evt); } public void mouseReleased(java.awt.event.MouseEvent evt) { checkSelectionAndPopupMenu(evt); } }); // Checks to see what to set the new row selection to based on // last index and if a new destination was added. int last = lastModelIndex; // Select each destination in turn so that the connector types can be decorated for (int row = 0; row < destinationTable.getRowCount(); row++) { destinationTable.setRowSelectionInterval(row, row); destinationConnectorPanel.decorateConnectorType(); } if (addNew) { destinationTable.setRowSelectionInterval(destinationTable.getRowCount() - 1, destinationTable.getRowCount() - 1); } else if (last == -1) { destinationTable.setRowSelectionInterval(0, 0); // Makes sure the } // event is called // when the table is // created. else if (last == destinationTable.getRowCount()) { destinationTable.setRowSelectionInterval(last - 1, last - 1); } else { destinationTable.setRowSelectionInterval(last, last); } destinationTablePane.setViewportView(destinationTable); destinationTablePane.setWheelScrollingEnabled(true); // Key Listener trigger for DEL destinationTable.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { parent.doDeleteDestination(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); destinationTable.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { destinationTablePane.getMouseWheelListeners()[0].mouseWheelMoved(e); } }); }