JavaDoc


001    /**
002     * Copyright (c) 2003 Daffodil Software Ltd all rights reserved,
003     * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved.
004     * This program is free software; you can redistribute it and/or modify
005     * it under the terms of version 2 of the GNU General Public License as
006     * published by the Free Software Foundation.
007     * There are special exceptions to the terms and conditions of the GPL
008     * as it is applied to this software. See the GNU General Public License for more details.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018     */
019    
020    package org.dbreplicator.repconsole;
021    
022    import java.sql.*;
023    
024    import java.awt.*;
025    import java.awt.event.*;
026    import javax.swing.*;
027    import javax.swing.border.*;
028    import javax.swing.table.*;
029    import javax.swing.tree.*;
030    
031    import org.dbreplicator.replication.*;
032    
033    /**
034     * <p>Title: </p>
035     * <p>Description: </p>
036     * <p>Copyright: Copyright (c) 2003</p>
037     * <p>Company: </p>
038     * @author not attributable
039     * @version 1.0
040     */
041    
042    public class SetFilterClause extends JDialog
043    {
044        JPanel panel1 = new JPanel();
045        JButton jButtonBack = new JButton();
046        JButton jButtonNext = new JButton();
047        JButton jButtonFinish = new JButton();
048        JButton jButtonCancle = new JButton();
049        String[] tableNames;
050        _Publication pub;
051        JDialog selectTable;
052        TitledBorder titledBorder1;
053        TitledBorder titledBorder2;
054        JScrollPane jScrollPane1 = new JScrollPane();
055        RCellEditor editor = new RCellEditor(new JTextField());
056        String[] columnNames = new String[]
057            {
058            "TableNames",
059            "FilterClause"};
060        DefaultTableModel dtm = new DefaultTableModel(columnNames, 0);
061        JTable jTableFilter = new JTable(dtm);
062    
063        int noOFTables;
064        String[] tableNameString;
065        DefaultTreeModel defaultTreeModel;
066        DefaultMutableTreeNode pubRootNode;
067        String pubName;
068        _ReplicationServer repServer;
069        JLabel jLabel2 = new JLabel();
070        JEditorPane help = new JEditorPane();
071        String operationType=null;
072    
073        public SetFilterClause(Frame frame, String title, boolean modal)
074        {
075            super(frame, title, modal);
076            try
077            {
078                jbInit();
079                pack();
080            }
081            catch (Exception ex)
082            {
083                JOptionPane.showMessageDialog(this, ex, "Error Message",
084                                              JOptionPane.ERROR_MESSAGE);
085                return;
086            }
087        }
088    
089        public SetFilterClause(_ReplicationServer repServer,
090                               DefaultTreeModel defaultTreeModel,
091                               DefaultMutableTreeNode pubRootNode, String pubName,
092                               _Publication pub, String[] tableNames,
093                               JDialog selectTable,String operationType0)
094        {
095            this(StartRepServer.getMainFrame(), "Set Filter Clause", true);
096    
097            this.pub = pub;
098            this.tableNames = tableNames;
099            this.selectTable = selectTable;
100            this.defaultTreeModel = defaultTreeModel;
101            this.pubRootNode = pubRootNode;
102            this.pubName = pubName;
103            this.repServer = repServer;
104            operationType=operationType0;
105    //System.out.println("operationType in set filter"+operationType);
106            initFilterList();
107        }
108    
109        private void jbInit() throws Exception
110        {
111    
112            jTableFilter.setEditingColumn(1);
113            jTableFilter.setColumnSelectionAllowed(false);
114            titledBorder1 = new TitledBorder("");
115            titledBorder2 = new TitledBorder("");
116            panel1.setLayout(null);
117            jButtonBack.setBounds(new Rectangle(47, 235, 81, 26));
118            jButtonBack.setFont(new java.awt.Font("Dialog", 1, 12));
119            jButtonBack.setText("<Back");
120            jButtonBack.addActionListener(new SetFilterClause_jButtonBack_actionAdapter(this));
121            jButtonNext.setBounds(new Rectangle(136, 235, 81, 26));
122            jButtonNext.setEnabled(false);
123            jButtonNext.setFont(new java.awt.Font("Dialog", 1, 12));
124            jButtonNext.setText("Next>");
125            jButtonFinish.setBounds(new Rectangle(224, 235, 81, 26));
126            jButtonFinish.setFont(new java.awt.Font("Dialog", 1, 12));
127            jButtonFinish.setText("Finish");
128            jButtonFinish.addActionListener(new
129                                            SetFilterClause_jButtonFinish_actionAdapter(this));
130            jButtonCancle.setBounds(new Rectangle(312, 235, 81, 26));
131            jButtonCancle.setFont(new java.awt.Font("Dialog", 1, 12));
132            jButtonCancle.setText("Cancel");
133            jButtonCancle.addActionListener(new
134                                            SetFilterClause_jButtonCancle_actionAdapter(this));
135            jScrollPane1.setFont(new java.awt.Font("Dialog", 0, 12));
136            jScrollPane1.setBounds(new Rectangle(17, 45, 375, 143));
137            jLabel2.setFont(new java.awt.Font("Serif", 3, 25));
138            jLabel2.setForeground(SystemColor.infoText);
139            jLabel2.setPreferredSize(new Dimension(175, 33));
140            jLabel2.setToolTipText("");
141            jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
142            jLabel2.setText("Set Filter Clause");
143            jLabel2.setBounds(new Rectangle(85, 2, 232, 23));
144            help.setBackground(UIManager.getColor("Button.background"));
145            help.setEnabled(false);
146            help.setFont(new java.awt.Font("Dialog", 2, 12));
147            help.setDoubleBuffered(false);
148            help.setRequestFocusEnabled(false);
149            help.setToolTipText("");
150            help.setDisabledTextColor(Color.black);
151            help.setEditable(false);
152            help.setSelectionStart(106);
153            help.setText(
154                "Optional filter clause specified on the tables will determine the " +
155                "data made available  to a Subscriber.");
156            help.setBounds(new Rectangle(18, 187, 375, 42));
157            jTableFilter.setFont(new java.awt.Font("Dialog", 0, 12));
158    
159            jTableFilter.addFocusListener(new FocusListener()
160            {
161                public void focusGained(FocusEvent fe)
162                {
163                    help.setText("Optional filter clause specified on the tables will determine the data made available  to a Subscriber.");
164                }
165    
166                public void focusLost(FocusEvent fe)
167                {
168    
169                }
170            });
171    
172            jTableFilter.addKeyListener(new KeyAdapter()
173            {
174                public void keyReleased(KeyEvent ke)
175                {
176    
177                }
178    
179            });
180            panel1.add(jLabel2, null);
181            panel1.add(jButtonFinish, null);
182            panel1.add(jButtonNext, null);
183            panel1.add(jScrollPane1, null);
184            panel1.add(help, null);
185            panel1.add(jButtonCancle, null);
186            panel1.add(jButtonBack, null);
187            jScrollPane1.getViewport().add(jTableFilter, null);
188            this.getContentPane().add(panel1, BorderLayout.CENTER);
189        }
190    
191        void initFilterList()
192        {
193    
194            noOFTables = tableNames.length;
195            tableNameString = new String[noOFTables];
196            for (int i = 0; i < noOFTables; i++)
197            {
198                tableNameString[i] = (String) tableNames[i];
199                dtm.addRow(new Object[]
200                           {tableNames[i], ""});
201            }
202            TableColumnModel tcm = jTableFilter.getColumnModel();
203            tcm.getColumn(0).setCellEditor(editor);
204        }
205    
206        void jButtonCancle_actionPerformed(ActionEvent e)
207        {
208            hide();
209        }
210    
211        void jButtonBack_actionPerformed(ActionEvent e)
212        {
213            hide();
214            selectTable.show();
215        }
216    
217        void jButtonFinish_actionPerformed(ActionEvent e)
218        {
219          String[] filterClauseList=new String[noOFTables];
220          String[] tableList=new String[noOFTables];
221            try
222            {
223                if (jTableFilter.isEditing())
224                {
225                    jTableFilter.getCellEditor().stopCellEditing();
226                }
227                for (int i = 0; i < noOFTables; i++)
228                {
229                    String filterClause = (String) dtm.getValueAt(i, 1);
230    //System.out.println("filter "+ filterClause);
231    //System.out.println("noOFTables="+noOFTables);
232    
233                    if (!filterClause.trim().equalsIgnoreCase(""))
234                    {
235                     if(operationType.equalsIgnoreCase(RepConstants.create_Publication))
236                       pub.setFilter( (String) dtm.getValueAt(i, 0), filterClause);
237                     else if(operationType.equalsIgnoreCase(RepConstants.addTable_Publication)){
238    //System.out.println("entering filter "+filterClause+" for table "+(String) dtm.getValueAt(i, 0));
239                       filterClauseList[i] = filterClause;
240                       tableList[i] = (String) dtm.getValueAt(i, 0);
241                     }
242                   }else
243                     filterClauseList[i] =null ;
244                       tableList[i] = (String) dtm.getValueAt(i, 0);
245                }
246    
247                 if(operationType.equalsIgnoreCase(RepConstants.addTable_Publication)){
248                  pub.addTableToPublication(tableList,filterClauseList);
249                  JOptionPane.showMessageDialog(this, "Publication Updated Successfully", "Success",
250                                                JOptionPane.INFORMATION_MESSAGE);
251                  hide();
252                }else if(operationType.equalsIgnoreCase(RepConstants.create_Publication)){
253                pub.publish();
254                createPubNode();
255                JOptionPane.showMessageDialog(this, "Published Successfully", "Success",
256                                              JOptionPane.INFORMATION_MESSAGE);
257                hide();
258              }
259    
260            }
261            catch (RepException ex)
262            {
263                JOptionPane.showMessageDialog(this, ex, "Error Message",
264                                              JOptionPane.ERROR_MESSAGE);
265                return;
266            }
267            catch (Exception ex1)
268            {
269    //          ex1.printStackTrace();
270                JOptionPane.showMessageDialog(this, ex1, "Error Message",
271                                              JOptionPane.ERROR_MESSAGE);
272                return;
273            }
274        }
275    
276        private void createPubNode()
277        {
278            try
279            {
280                Connection conn = repServer.getDefaultConnection();
281                DefaultMutableTreeNode node = new DefaultMutableTreeNode(pubName);
282                node.setAllowsChildren(true);
283                DefaultMutableTreeNode tableRootNode;
284                DefaultMutableTreeNode tableNode;
285                DefaultMutableTreeNode columnNode;
286                tableRootNode = new DefaultMutableTreeNode("TABLES");
287                for (int i = 0; i < tableNames.length; i++)
288                {
289                    String tabName = tableNames[i];
290                    int lastIndex = tabName.lastIndexOf(".");
291                    String schemaName=null;
292                    if (lastIndex != -1)
293                    {
294                       tabName.substring(0,lastIndex);
295                        tabName = tabName.substring(lastIndex + 1);
296                    }
297                    tableNode = new DefaultMutableTreeNode(tabName);
298                    tableNode.setAllowsChildren(true);
299                    ResultSet rsColumns = conn.getMetaData().getColumns(null, schemaName,
300                        tabName, "%");
301                    columnNode = new DefaultMutableTreeNode("COLUMNS");
302                    while (rsColumns.next())
303                    {
304                        DefaultMutableTreeNode leafColumn = new DefaultMutableTreeNode(
305                            rsColumns.getString("COLUMN_NAME"));
306                        leafColumn.setAllowsChildren(false);
307                        columnNode.add(leafColumn);
308                    }
309                    tableNode.add(columnNode);
310                    tableRootNode.add(tableNode);
311                }
312                node.add(tableRootNode);
313                defaultTreeModel.insertNodeInto(node, pubRootNode,
314                                                pubRootNode.getChildCount());
315    
316            }
317            catch (SQLException ex)
318            {
319                JOptionPane.showMessageDialog(this, ex, "Error Message",
320                                              JOptionPane.ERROR_MESSAGE);
321                return;
322            }
323        }
324    }
325    
326    class SetFilterClause_jButtonCancle_actionAdapter implements java.awt.event.ActionListener
327    {
328        SetFilterClause adaptee;
329    
330        SetFilterClause_jButtonCancle_actionAdapter(SetFilterClause adaptee)
331        {
332            this.adaptee = adaptee;
333        }
334    
335        public void actionPerformed(ActionEvent e)
336        {
337            adaptee.jButtonCancle_actionPerformed(e);
338        }
339    }
340    
341    class SetFilterClause_jButtonBack_actionAdapter implements java.awt.event.ActionListener
342    {
343        SetFilterClause adaptee;
344    
345        SetFilterClause_jButtonBack_actionAdapter(SetFilterClause adaptee)
346        {
347            this.adaptee = adaptee;
348        }
349    
350        public void actionPerformed(ActionEvent e)
351        {
352            adaptee.jButtonBack_actionPerformed(e);
353        }
354    }
355    
356    class SetFilterClause_jButtonFinish_actionAdapter implements java.awt.event.ActionListener
357    {
358        SetFilterClause adaptee;
359    
360        SetFilterClause_jButtonFinish_actionAdapter(SetFilterClause adaptee)
361        {
362            this.adaptee = adaptee;
363        }
364    
365        public void actionPerformed(ActionEvent e)
366        {
367            adaptee.jButtonFinish_actionPerformed(e);
368        }
369    }





























































Powered by Drupal - Theme by Danger4k