2016-09-06 16:49:11 +02:00
package org.hwo.pulscounter.ui ;
import java.awt.BorderLayout ;
import java.awt.EventQueue ;
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import javax.swing.border.EmptyBorder ;
import javax.swing.event.ListSelectionEvent ;
import javax.swing.event.ListSelectionListener ;
2017-03-10 15:11:01 +01:00
import org.hwo.i18n.Messages ;
2016-09-06 16:49:11 +02:00
import org.hwo.interactiveobjects.ObjectEditorUI ;
import org.hwo.interactiveobjects.ObjectEditorUIHelper ;
import org.hwo.models.TableMapper.TableMapper ;
import org.hwo.pulscounter.ExportSetting ;
2016-09-08 18:47:31 +02:00
import org.hwo.pulscounter.PulsCounterApplication ;
2016-09-06 16:49:11 +02:00
import java.awt.GridBagLayout ;
import javax.swing.JButton ;
2016-11-17 16:37:45 +01:00
import javax.swing.JDialog ;
2016-09-06 16:49:11 +02:00
import java.awt.GridBagConstraints ;
import javax.swing.JScrollPane ;
import java.awt.Insets ;
import javax.swing.JTable ;
import java.awt.event.ActionListener ;
import java.awt.event.ActionEvent ;
import javax.swing.JToolBar ;
import javax.swing.ListSelectionModel ;
import javax.swing.JSeparator ;
2016-11-17 16:37:45 +01:00
import java.awt.Dialog.ModalExclusionType ;
import java.awt.Dialog.ModalityType ;
2016-09-06 16:49:11 +02:00
2016-11-17 16:37:45 +01:00
public class ExportFilesFrame extends JDialog {
2016-09-06 16:49:11 +02:00
private JPanel contentPane ;
private JTable tExportSettings ;
private TableMapper tmExportSettings ;
private JButton bRemove ;
private JButton bEdit ;
private JButton bAdd ;
private ExportSetting selectedExportSetting ;
private JSeparator separator ;
private JButton btnExec ;
2016-10-06 10:57:31 +02:00
private JButton btnBatch ;
2016-09-06 16:49:11 +02:00
/ * *
* Create the frame .
* /
public ExportFilesFrame ( ) {
2016-11-17 16:37:45 +01:00
setModalityType ( ModalityType . APPLICATION_MODAL ) ;
2017-03-10 15:11:01 +01:00
setTitle ( Messages . getString ( "Export Einstellungen..." ) ) ;
2016-09-06 16:49:11 +02:00
setDefaultCloseOperation ( JFrame . DISPOSE_ON_CLOSE ) ;
setBounds ( 100 , 100 , 825 , 433 ) ;
contentPane = new JPanel ( ) ;
contentPane . setBorder ( new EmptyBorder ( 5 , 5 , 5 , 5 ) ) ;
setContentPane ( contentPane ) ;
GridBagLayout gbl_contentPane = new GridBagLayout ( ) ;
gbl_contentPane . columnWidths = new int [ ] { 0 , 0 , 0 , 0 } ;
gbl_contentPane . rowHeights = new int [ ] { 0 , 0 , 0 , 0 } ;
gbl_contentPane . columnWeights = new double [ ] { 1.0 , 0.0 , 0.0 , Double . MIN_VALUE } ;
gbl_contentPane . rowWeights = new double [ ] { 0.0 , 1.0 , 0.0 , Double . MIN_VALUE } ;
contentPane . setLayout ( gbl_contentPane ) ;
JToolBar toolBar = new JToolBar ( ) ;
toolBar . setFloatable ( false ) ;
GridBagConstraints gbc_toolBar = new GridBagConstraints ( ) ;
gbc_toolBar . fill = GridBagConstraints . BOTH ;
gbc_toolBar . gridwidth = 3 ;
gbc_toolBar . insets = new Insets ( 0 , 0 , 5 , 5 ) ;
gbc_toolBar . gridx = 0 ;
gbc_toolBar . gridy = 0 ;
contentPane . add ( toolBar , gbc_toolBar ) ;
2017-03-10 15:11:01 +01:00
bAdd = new JButton ( Messages . getString ( "Export hinzufügen" ) ) ;
bAdd . setToolTipText ( Messages . getString ( "tooltip.export.add" ) ) ; //"<html>\n<b>Neue Exportkonfiguration hinzufügen</b><br/>\n</html>");
2016-09-06 16:49:11 +02:00
bAdd . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
ExportSetting es = new ExportSetting ( ) ;
tmExportSettings . addRow ( es ) ;
}
} ) ;
toolBar . add ( bAdd ) ;
2017-03-10 15:11:01 +01:00
bEdit = new JButton ( Messages . getString ( "Einstellungen" ) ) ;
bEdit . setToolTipText ( Messages . getString ( "tooltip.export.configuration" ) ) ; // "<html>\n<b>Ausgewählte Exportkonfiguration bearbeiten</b>\n</html>");
2016-09-06 16:49:11 +02:00
bEdit . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
ExportSetting es = ( ExportSetting ) tmExportSettings . getSelectedRow ( ) ;
if ( es ! = null ) {
if ( ObjectEditorUIHelper . edit ( es ) ) {
tmExportSettings . fireTableDataChanged ( ) ;
}
}
}
} ) ;
bEdit . setEnabled ( false ) ;
toolBar . add ( bEdit ) ;
2017-03-10 15:11:01 +01:00
bRemove = new JButton ( Messages . getString ( Messages . getString ( "Export löschen" ) ) ) ;
bRemove . setToolTipText ( Messages . getString ( "tooltip.export.remove" ) ) ; // "<html>\n<b>Ausgewählte Exportkonfiguration entfernen</b>\n</html>");
2016-09-06 16:49:11 +02:00
bRemove . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
if ( selectedExportSetting ! = null ) {
ExportSetting es = selectedExportSetting ;
tmExportSettings . removeRow ( es ) ;
}
}
} ) ;
bRemove . setEnabled ( false ) ;
toolBar . add ( bRemove ) ;
separator = new JSeparator ( ) ;
toolBar . add ( separator ) ;
2017-03-10 15:11:01 +01:00
btnExec = new JButton ( Messages . getString ( "Export ausführen" ) ) ;
btnExec . setToolTipText ( Messages . getString ( "tooltip.export.run" ) ) ; //"<html>\n<b>Ausgewählte Exportkonfiguration jetzt ausführen</b><br/>\n</html>");
2016-09-06 16:49:11 +02:00
btnExec . setEnabled ( false ) ;
btnExec . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
doExport ( ) ;
}
} ) ;
2016-10-26 19:21:57 +02:00
toolBar . add ( btnExec ) ;
2016-10-06 10:57:31 +02:00
2017-03-10 15:11:01 +01:00
btnBatch = new JButton ( Messages . getString ( "Automatiklauf" ) ) ;
2016-10-06 10:57:31 +02:00
btnBatch . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
doBatchExport ( ) ;
}
} ) ;
toolBar . add ( btnBatch ) ;
2016-09-06 16:49:11 +02:00
JScrollPane scrollPane = new JScrollPane ( ) ;
2017-03-10 15:11:01 +01:00
scrollPane . setToolTipText ( Messages . getString ( "tooltip.export.list" ) ) ; // "<html>\n<b>Exportkonfigurationen</b><br/>\nZeigt eine Übersicht über die aktuell vorhandenen Exportkonfigurationen\n</html>");
2016-09-06 16:49:11 +02:00
GridBagConstraints gbc_scrollPane = new GridBagConstraints ( ) ;
gbc_scrollPane . gridwidth = 3 ;
gbc_scrollPane . insets = new Insets ( 0 , 0 , 5 , 0 ) ;
gbc_scrollPane . fill = GridBagConstraints . BOTH ;
gbc_scrollPane . gridx = 0 ;
gbc_scrollPane . gridy = 1 ;
contentPane . add ( scrollPane , gbc_scrollPane ) ;
tExportSettings = new JTable ( ) ;
tExportSettings . setSelectionMode ( ListSelectionModel . SINGLE_SELECTION ) ;
tmExportSettings = new TableMapper ( ExportSetting . class , tExportSettings ) ;
tmExportSettings . addListSelectionListener ( new ListSelectionListener ( ) {
@Override
public void valueChanged ( ListSelectionEvent e ) {
ExportSetting es = ( ExportSetting ) tmExportSettings . getSelectedRow ( ) ;
setSelectedExportSetting ( es ) ;
}
} ) ;
2016-09-08 18:47:31 +02:00
tmExportSettings . setRows ( PulsCounterApplication . getApplication ( ) . getExportSettings ( ) ) ;
2016-09-06 16:49:11 +02:00
scrollPane . setViewportView ( tExportSettings ) ;
2017-03-10 15:11:01 +01:00
JButton btnSchliessen = new JButton ( Messages . getString ( "schliessen" ) ) ;
2016-09-06 16:49:11 +02:00
btnSchliessen . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
setVisible ( false ) ;
}
} ) ;
GridBagConstraints gbc_btnSchliessen = new GridBagConstraints ( ) ;
gbc_btnSchliessen . gridx = 2 ;
gbc_btnSchliessen . gridy = 2 ;
contentPane . add ( btnSchliessen , gbc_btnSchliessen ) ;
}
public ExportSetting getSelectedExportSetting ( ) {
return selectedExportSetting ;
}
public void setSelectedExportSetting ( ExportSetting selectedExportSetting ) {
this . selectedExportSetting = selectedExportSetting ;
if ( this . selectedExportSetting ! = null ) {
bEdit . setEnabled ( true ) ;
bRemove . setEnabled ( true ) ;
btnExec . setEnabled ( true ) ;
} else {
bEdit . setEnabled ( false ) ;
bRemove . setEnabled ( false ) ;
btnExec . setEnabled ( false ) ;
}
}
public void doExport ( ) {
( ( ExportSetting ) tmExportSettings . getSelectedRow ( ) ) . export ( ) ;
}
2016-10-06 10:57:31 +02:00
public void doBatchExport ( ) {
for ( ExportSetting es : PulsCounterApplication . getApplication ( ) . getExportSettings ( ) ) {
if ( es . getAutostart ( ) ) {
es . export ( ) ;
}
}
}
2016-09-06 16:49:11 +02:00
}