001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * ToolbarConnectionPanel.java
028: *
029: * Created on 7 mei 2005, 13:27
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: //import it.businesslogic.ireport.gui.event.*;
036: //import it.businesslogic.ireport.undo.*;
037: //import it.businesslogic.ireport.util.*;
038: import javax.swing.JToolBar;
039:
040: /**
041: *
042: * @Author: Robert Lamping
043: */
044: public class ToolbarConnectionPanel extends javax.swing.JPanel {
045:
046: private boolean updating = false;
047: private MainFrame mf = null; // MainFrame.getMainInstance();;
048: private StringBuffer outputBuffer;
049:
050: /** Creates new form ToolbarFormatPanel */
051: // Pass the workspace to this toolbar
052: public ToolbarConnectionPanel(MainFrame mf) {
053: this .mf = mf;
054: initComponents();
055: }
056:
057: public JToolBar getToolBar() {
058: // Make toolbar available to e.g. MainFrame
059: return jToolBarConnections;
060: }
061:
062: /** This method is called from within the constructor to
063: * initialize the form.
064: * WARNING: Do NOT modify this code. The content of this method is
065: * always regenerated by the Form Editor.
066: */
067: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
068: private void initComponents() {
069: jToolBarConnections = new javax.swing.JToolBar();
070: jComboBoxConnections = new javax.swing.JComboBox();
071: jButtonDatasources = new javax.swing.JButton();
072:
073: setLayout(new java.awt.BorderLayout());
074:
075: setName("ToolbarConnectionPanel");
076: getAccessibleContext().setAccessibleName(
077: "ToolbarConnectionPanel");
078: jComboBoxConnections.setMaximumSize(new java.awt.Dimension(250,
079: 32767));
080: jComboBoxConnections
081: .addActionListener(new java.awt.event.ActionListener() {
082: public void actionPerformed(
083: java.awt.event.ActionEvent evt) {
084: jComboBoxConnectionsActionPerformed(evt);
085: }
086: });
087:
088: jToolBarConnections.add(jComboBoxConnections);
089: jComboBoxConnections.getAccessibleContext().setAccessibleName(
090: "ToolbarConnections");
091:
092: jButtonDatasources
093: .setIcon(new javax.swing.ImageIcon(
094: getClass()
095: .getResource(
096: "/it/businesslogic/ireport/icons/toolbars/datasources.png")));
097: jButtonDatasources.setToolTipText("Datasources");
098: jButtonDatasources.setBorder(null);
099: jButtonDatasources.setBorderPainted(false);
100: jButtonDatasources.setFocusPainted(false);
101: jButtonDatasources.setMargin(new java.awt.Insets(0, 0, 0, 0));
102: jButtonDatasources
103: .setMaximumSize(new java.awt.Dimension(24, 23));
104: jButtonDatasources
105: .setMinimumSize(new java.awt.Dimension(22, 22));
106: jButtonDatasources.setPreferredSize(new java.awt.Dimension(22,
107: 22));
108: jButtonDatasources
109: .addActionListener(new java.awt.event.ActionListener() {
110: public void actionPerformed(
111: java.awt.event.ActionEvent evt) {
112: jButtonDatasourcesActionPerformed(evt);
113: }
114: });
115:
116: jToolBarConnections.add(jButtonDatasources);
117:
118: add(jToolBarConnections, java.awt.BorderLayout.NORTH);
119: jToolBarConnections.getAccessibleContext().setAccessibleName(
120: "ToolbarConnections");
121:
122: }// </editor-fold>//GEN-END:initComponents
123:
124: private void jButtonDatasourcesActionPerformed(
125: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDatasourcesActionPerformed
126: try {
127: ConnectionsDialog cd = new ConnectionsDialog(this
128: .getMainFrame(), true);
129: cd.setVisible(true);
130: this .updateConnections();
131: } catch (Exception ex) {
132: ex.printStackTrace();
133: }
134: }//GEN-LAST:event_jButtonDatasourcesActionPerformed
135:
136: private void jComboBoxConnectionsActionPerformed(
137: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxConnectionsActionPerformed
138:
139: if (!updating && jComboBoxConnections.getSelectedItem() != null) {
140: this .getMainFrame().getProperties().put(
141: "DefaultConnection",
142: jComboBoxConnections.getSelectedItem());
143: this .getMainFrame().saveiReportConfiguration();
144: }
145: }//GEN-LAST:event_jComboBoxConnectionsActionPerformed
146:
147: // Variables declaration - do not modify//GEN-BEGIN:variables
148: private javax.swing.JButton jButtonDatasources;
149: private javax.swing.JComboBox jComboBoxConnections;
150: private javax.swing.JToolBar jToolBarConnections;
151:
152: // End of variables declaration//GEN-END:variables
153:
154: public javax.swing.JComboBox getJComboBoxConnextions() {
155: return jComboBoxConnections;
156: }
157:
158: public synchronized void updateConnections() {
159: this .updating = true;
160:
161: try {
162: it.businesslogic.ireport.util.Misc.updateComboBox(
163: jComboBoxConnections, getMainFrame()
164: .getConnections());
165: if (getMainFrame().getProperties().get("DefaultConnection") != null)
166: jComboBoxConnections.setSelectedItem(getMainFrame()
167: .getProperties().get("DefaultConnection"));
168: } catch (Exception ex) {
169: ex.printStackTrace();
170: }
171: this .updating = false;
172: }
173:
174: private MainFrame getMainFrame() {
175: return mf;
176: }
177:
178: }
|