001: /*
002: * EJBQLConnectionEditor.java
003: *
004: * Created on March 27, 2007, 1:18 PM
005: */
006:
007: package it.businesslogic.ireport.connection.gui;
008:
009: import it.businesslogic.ireport.IReportConnection;
010: import it.businesslogic.ireport.connection.EJBQLConnection;
011: import it.businesslogic.ireport.IReportConnectionEditor;
012: import it.businesslogic.ireport.util.I18n;
013:
014: /**
015: *
016: * @author gtoffoli
017: */
018: public class EJBQLConnectionEditor extends javax.swing.JPanel implements
019: IReportConnectionEditor {
020:
021: private IReportConnection iReportConnection = null;
022: private boolean init = false;
023:
024: /** Creates new form EJBQLConnectionEditor */
025: public EJBQLConnectionEditor() {
026: initComponents();
027: applyI18n();
028: }
029:
030: /** This method is called from within the constructor to
031: * initialize the form.
032: * WARNING: Do NOT modify this code. The content of this method is
033: * always regenerated by the Form Editor.
034: */
035: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
036: private void initComponents() {
037: java.awt.GridBagConstraints gridBagConstraints;
038:
039: jPanelEJBQL = new javax.swing.JPanel();
040: jLabel18 = new javax.swing.JLabel();
041: jTextFieldPersistanceUnit = new javax.swing.JTextField();
042: jLabel1 = new javax.swing.JLabel();
043:
044: setLayout(new java.awt.BorderLayout());
045:
046: jPanelEJBQL.setLayout(new java.awt.GridBagLayout());
047:
048: jLabel18.setText("Persistance Unit Name");
049: gridBagConstraints = new java.awt.GridBagConstraints();
050: gridBagConstraints.gridx = 0;
051: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
052: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
053: gridBagConstraints.weightx = 1.0;
054: gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 4);
055: jPanelEJBQL.add(jLabel18, gridBagConstraints);
056:
057: jTextFieldPersistanceUnit.setMargin(new java.awt.Insets(0, 5,
058: 2, 4));
059: gridBagConstraints = new java.awt.GridBagConstraints();
060: gridBagConstraints.gridx = 0;
061: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
062: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
063: gridBagConstraints.weightx = 1.0;
064: gridBagConstraints.insets = new java.awt.Insets(0, 4, 3, 4);
065: jPanelEJBQL.add(jTextFieldPersistanceUnit, gridBagConstraints);
066:
067: jLabel1.setText("jLabel1");
068: gridBagConstraints = new java.awt.GridBagConstraints();
069: gridBagConstraints.gridx = 0;
070: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
071: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
072: gridBagConstraints.weightx = 1.0;
073: gridBagConstraints.weighty = 1.0;
074: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
075: jPanelEJBQL.add(jLabel1, gridBagConstraints);
076:
077: add(jPanelEJBQL, java.awt.BorderLayout.CENTER);
078:
079: }// </editor-fold>//GEN-END:initComponents
080:
081: // Variables declaration - do not modify//GEN-BEGIN:variables
082: private javax.swing.JLabel jLabel1;
083: private javax.swing.JLabel jLabel18;
084: private javax.swing.JPanel jPanelEJBQL;
085: private javax.swing.JTextField jTextFieldPersistanceUnit;
086:
087: // End of variables declaration//GEN-END:variables
088:
089: public void setIReportConnection(IReportConnection c) {
090:
091: this .iReportConnection = c;
092: if (iReportConnection instanceof EJBQLConnection) {
093: EJBQLConnection con = (EJBQLConnection) iReportConnection;
094: this .jTextFieldPersistanceUnit
095: .setText(it.businesslogic.ireport.util.Misc
096: .nvl(con.getProperties().get(
097: "PersistenceUnit"), ""));
098: }
099: }
100:
101: public IReportConnection getIReportConnection() {
102:
103: IReportConnection irConn = new EJBQLConnection();
104:
105: if (jTextFieldPersistanceUnit.getText().trim().length() != 0) {
106: irConn.getProperties().put("PersistenceUnit",
107: jTextFieldPersistanceUnit.getText().trim());
108: } else {
109: javax.swing.JOptionPane
110: .showMessageDialog(
111: this ,
112: I18n
113: .getString(
114: "messages.connectionDialog.ejbql.invalidPersistenceUnit",
115: "Please specify a valid PersistenceUnit"),
116: I18n
117: .getString(
118: "messages.connectionDialog.invalidPersistenceUnitCaption",
119: "Invalid PersistenceUnit!"),
120: javax.swing.JOptionPane.WARNING_MESSAGE);
121: return null;
122: }
123:
124: iReportConnection = irConn;
125: return iReportConnection;
126: }
127:
128: public void applyI18n() {
129: // Start autogenerated code ----------------------
130: jLabel18.setText(I18n.getString("connectionDialog.label18",
131: "Persistance Unit Name"));
132: jLabel1
133: .setText("<html>"
134: + I18n
135: .getString(
136: "connectionDialog.textPane2",
137: "iReport will search for persistence.xml files within the META-INF directory of any CLASSPATH element"));
138: }
139:
140: }
|