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.awt.*; 023 import java.awt.event.*; 024 import javax.swing.*; 025 import javax.swing.border.*; 026 import javax.swing.tree.*; 027 028 import org.dbreplicator.replication.*; 029 import org.dbreplicator.replication.DBHandler.AbstractDataBaseHandler; 030 import java.sql.Connection; 031 import java.sql.Statement; 032 import java.sql.ResultSet; 033 import java.sql.*; 034 035 /** 036 * <p>Title: </p> 037 * <p>Description: </p> 038 * <p>Copyright: Copyright (c) 2003</p> 039 * <p>Company: </p> 040 * @author not attributable 041 * @version 1.0 042 */ 043 044 public class RemoveSchedule 045 extends JDialog 046 implements FocusListener, KeyListener { 047 JPanel panel1 = new JPanel(); 048 JEditorPane help = new JEditorPane(); 049 050 JLabel jLabelRemoveSchedule = new JLabel(); 051 JLabel jLabelScheduleName = new JLabel(); 052 JLabel jLabelSubName = new JLabel(); 053 054 JTextField jTextSubName = new JTextField(); 055 JComboBox jComboScheduleName = new JComboBox(); 056 057 JButton jButtonGetSchedule = new JButton(); 058 JButton jButtonRemoveSchedule = new JButton(); 059 JButton jButtonCancel = new JButton(); 060 061 _ReplicationServer repServer; 062 _Subscription sub = null; 063 AbstractDataBaseHandler dbHandler; 064 065 String subName; 066 boolean able = true; 067 068 Border border1; 069 070 public RemoveSchedule(Frame frame, String title, boolean modal) { 071 super(frame, title, modal); 072 try { 073 jbInit(); 074 pack(); 075 } 076 catch (Exception ex) { 077 JOptionPane.showMessageDialog(this, ex, "Error Message", 078 JOptionPane.ERROR_MESSAGE); 079 return; 080 } 081 } 082 083 public RemoveSchedule(_ReplicationServer repServer0, 084 DefaultMutableTreeNode subRootNode0, 085 DefaultTreeModel defaultTreeModel0, boolean able0) { 086 this(StartRepServer.getMainFrame(), "Remove Schedule", true); 087 repServer = repServer0; 088 able = able0; 089 } 090 091 public RemoveSchedule(_ReplicationServer repServer0, 092 DefaultMutableTreeNode subRootNode0, 093 DefaultTreeModel defaultTreeModel0, String subName0, 094 boolean able0) { 095 this(null, "Remove Schedule", true); 096 repServer = repServer0; 097 subName = subName0; 098 able = able0; 099 init(); 100 } 101 102 private void init() { 103 try { 104 _Subscription sub = repServer.getSubscription(subName); 105 jTextSubName.setText(subName); 106 jTextSubName.setEnabled(able); 107 } 108 catch (RepException ex) { 109 JOptionPane.showMessageDialog(this, ex, "Error Message", 110 JOptionPane.ERROR_MESSAGE); 111 return; 112 } 113 } 114 115 private void jbInit() throws Exception { 116 border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, 117 new Color(148, 145, 140)); 118 panel1.setLayout(null); 119 panel1.setAlignmentY( (float) 0.5); 120 panel1.setDebugGraphicsOptions(0); 121 122 jLabelRemoveSchedule.setEnabled(true); 123 jLabelRemoveSchedule.setFont(new java.awt.Font("Serif", 3, 25)); 124 jLabelRemoveSchedule.setForeground(SystemColor.infoText); 125 jLabelRemoveSchedule.setText("Remove Schedule"); 126 int center=jLabelRemoveSchedule.CENTER; 127 jLabelRemoveSchedule.setHorizontalAlignment(center); 128 jLabelRemoveSchedule.setBounds(new Rectangle(92, 5, 193, 35)); 129 130 jLabelSubName.setFont(new java.awt.Font("Dialog", 1, 13)); 131 jLabelSubName.setHorizontalAlignment(SwingConstants.LEFT); 132 jLabelSubName.setHorizontalTextPosition(SwingConstants.LEFT); 133 jLabelSubName.setText("Subscriber's Name"); 134 jLabelSubName.setBounds(new Rectangle(19, 84, 174, 23)); 135 136 jLabelScheduleName.setFont(new java.awt.Font("Dialog", 1, 13)); 137 jLabelScheduleName.setMaximumSize(new Dimension(136, 16)); 138 jLabelScheduleName.setMinimumSize(new Dimension(136, 16)); 139 jLabelScheduleName.setPreferredSize(new Dimension(136, 16)); 140 jLabelScheduleName.setHorizontalAlignment(SwingConstants.LEFT); 141 jLabelScheduleName.setHorizontalTextPosition(SwingConstants.LEFT); 142 jLabelScheduleName.setText("Schedule Name"); 143 jLabelScheduleName.setBounds(new Rectangle(19, 115, 174, 15)); 144 145 jTextSubName.setFont(new java.awt.Font("Dialog", 0, 12)); 146 jTextSubName.setPreferredSize(new Dimension(6, 22)); 147 jTextSubName.setText(""); 148 jTextSubName.setBounds(new Rectangle(188, 82, 168, 23)); 149 jTextSubName.setEnabled(true); 150 jTextSubName.addFocusListener(this); 151 152 jComboScheduleName.setBounds(new Rectangle(188, 115, 90, 23)); 153 154 jButtonGetSchedule.setBounds(new Rectangle(286, 115, 70, 23)); 155 jButtonGetSchedule.setEnabled(true); 156 jButtonGetSchedule.setFont(new java.awt.Font("Dialog", 1, 12)); 157 jButtonGetSchedule.setText("Load"); 158 jButtonGetSchedule.addActionListener(new 159 RemoveSchedule_jButtonGetSchedule_actionAdapter(this)); 160 161 help.setBackground(UIManager.getColor("Button.background")); 162 help.setEnabled(false); 163 help.setFont(new java.awt.Font("Dialog", 2, 12)); 164 help.setRequestFocusEnabled(false); 165 help.setToolTipText(""); 166 help.setDisabledTextColor(Color.black); 167 help.setEditable(false); 168 help.setText("Remove the selected schedule"); 169 help.setBounds(new Rectangle(12, 155, 341, 23)); 170 171 jButtonRemoveSchedule.setBounds(new Rectangle(113, 186, 117, 25)); 172 jButtonRemoveSchedule.setEnabled(false); 173 jButtonRemoveSchedule.setFont(new java.awt.Font("Dialog", 1, 12)); 174 jButtonRemoveSchedule.setText("Remove"); 175 jButtonRemoveSchedule.addActionListener(new 176 RemoveSchedule_jButtonRemoveSchedule_actionAdapter(this)); 177 178 jButtonCancel.setBounds(new Rectangle(240, 186, 117, 25)); 179 jButtonCancel.setFont(new java.awt.Font("Dialog", 1, 12)); 180 jButtonCancel.setToolTipText(""); 181 jButtonCancel.setText("Cancel"); 182 jButtonCancel.addActionListener(new 183 RemoveSchedule_jButtonCancle_actionAdapter(this)); 184 185 jTextSubName.requestFocus(); 186 jTextSubName.grabFocus(); 187 jTextSubName.addKeyListener(this); 188 jTextSubName.addFocusListener(this); 189 190 panel1.add(help); 191 panel1.add(jLabelRemoveSchedule); 192 panel1.add(jLabelScheduleName); 193 panel1.add(jLabelSubName); 194 panel1.add(jButtonGetSchedule, null); 195 panel1.add(jComboScheduleName); 196 panel1.add(jTextSubName); 197 198 panel1.add(jTextSubName); 199 200 panel1.add(jButtonRemoveSchedule, null); 201 panel1.add(jButtonCancel, null); 202 203 //For border purpose. 204 JLabel p1 = new JLabel(); 205 p1.setText(""); 206 p1.setBounds(new Rectangle(9, 66, 352, 90)); 207 p1.setBorder(border1); 208 209 panel1.add(p1); 210 getContentPane().add(panel1); 211 } 212 213 void jButtonCancle_actionPerformed(ActionEvent e) { 214 dispose(); 215 hide(); 216 } 217 218 void jButtonRemoveSchedule_actionPerformed(ActionEvent e) { 219 try { 220 String subName = jTextSubName.getText().trim(); 221 if (subName.equalsIgnoreCase("")) { 222 throw new RepException("REP093", new Object[] {null}); 223 } 224 sub = repServer.getSubscription(subName); 225 if (sub == null) { 226 throw new RepException("REP037", new Object[] {subName}); 227 } 228 if (jComboScheduleName.getSelectedItem() == null) { 229 throw new RepException("REP207", new Object[] {null}); 230 } 231 sub.removeSchedule(jComboScheduleName.getSelectedItem().toString(),subName); 232 JOptionPane.showMessageDialog(this, "Schedule dropped Successfully", 233 "Success", JOptionPane.INFORMATION_MESSAGE); 234 hide(); 235 } 236 catch (RepException ex) { 237 JOptionPane.showMessageDialog(this, ex, "Error Message", 238 JOptionPane.ERROR_MESSAGE); 239 return; 240 } 241 } 242 243 public void keyTyped(KeyEvent keyEvent) { 244 } 245 246 public void keyPressed(KeyEvent keyEvent) { 247 } 248 249 public void keyReleased(KeyEvent keyEvent) { 250 jButtonRemoveSchedule.setEnabled(true); 251 if (jTextSubName.getText().equals("") ){ 252 jButtonRemoveSchedule.setEnabled(false); 253 } 254 else { 255 if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) { 256 jButtonRemoveSchedule_actionPerformed(null); 257 } 258 } 259 } 260 261 public void jButtonGetSchedule_actionPerformed(ActionEvent e) { 262 ResultSet rs =null; 263 Statement st=null; 264 try { 265 if(jComboScheduleName.getItemCount()!=0){ 266 jComboScheduleName.removeAllItems(); 267 } 268 String subName = jTextSubName.getText().trim(); 269 if (subName.equalsIgnoreCase("")) { 270 throw new RepException("REP093", new Object[] {null}); 271 } 272 sub = repServer.getSubscription(subName); 273 if (sub == null) { 274 throw new RepException("REP037", new Object[] {subName}); 275 } 276 dbHandler = Utility.getDatabaseHandler(((Subscription)sub).getConnectionPool(), subName); 277 Connection con = repServer.getDefaultConnection(); 278 st = con.createStatement(); 279 StringBuffer query=new StringBuffer(); 280 query=query.append("select * from ").append(dbHandler.getScheduleTableName()) 281 .append(" where ") 282 .append(RepConstants.subscription_subName1) 283 .append(" = '") .append(subName ).append("'"); 284 285 rs = st.executeQuery(query.toString()); 286 if (rs.next()) { 287 jComboScheduleName.addItem(rs.getString(RepConstants.schedule_Name)); 288 jButtonRemoveSchedule.setEnabled(true); 289 } 290 else { 291 throw new RepException("REP210", new Object[] {subName}); 292 } 293 294 } 295 catch (RepException ex) { 296 JOptionPane.showMessageDialog(this, ex, "Error Message", 297 JOptionPane.ERROR_MESSAGE); 298 return; 299 } 300 catch (Exception ex) { 301 RepConstants.writeERROR_FILE(ex); 302 // ex.printStackTrace(); 303 } finally { 304 try { 305 if (rs != null) { 306 rs.close(); 307 } 308 if (st != null) { 309 st.close(); 310 } 311 } 312 catch (SQLException ex1) { 313 } 314 } 315 } 316 317 public void focusGained(FocusEvent fe) { 318 if ( ( (JTextField) fe.getSource()).equals(jTextSubName)) { 319 help.setText("Enter Subscription Name in this box"); 320 } 321 if (! (jTextSubName.getText().equals(""))) { 322 jButtonRemoveSchedule.setEnabled(true); 323 } 324 } 325 326 public void focusLost(FocusEvent fe) { 327 jButtonRemoveSchedule.setEnabled(true); 328 if (jTextSubName.getText().equals("")) { 329 jButtonRemoveSchedule.setEnabled(false); 330 331 } 332 } 333 } 334 335 class RemoveSchedule_jButtonCancle_actionAdapter 336 implements java.awt.event.ActionListener { 337 RemoveSchedule adaptee; 338 339 RemoveSchedule_jButtonCancle_actionAdapter(RemoveSchedule adaptee) { 340 this.adaptee = adaptee; 341 } 342 343 public void actionPerformed(ActionEvent e) { 344 adaptee.jButtonCancle_actionPerformed(e); 345 } 346 } 347 348 class RemoveSchedule_jButtonRemoveSchedule_actionAdapter 349 implements java.awt.event.ActionListener { 350 RemoveSchedule adaptee; 351 352 RemoveSchedule_jButtonRemoveSchedule_actionAdapter(RemoveSchedule adaptee) { 353 this.adaptee = adaptee; 354 } 355 356 public void actionPerformed(ActionEvent e) { 357 adaptee.jButtonRemoveSchedule_actionPerformed(e); 358 } 359 } 360 361 class RemoveSchedule_jButtonGetSchedule_actionAdapter 362 implements java.awt.event.ActionListener { 363 RemoveSchedule adaptee; 364 365 RemoveSchedule_jButtonGetSchedule_actionAdapter(RemoveSchedule adaptee) { 366 this.adaptee = adaptee; 367 } 368 369 public void actionPerformed(ActionEvent e) { 370 adaptee.jButtonGetSchedule_actionPerformed(e); 371 } 372 }

