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 org.dbreplicator.replication.DBHandler.AbstractDataBaseHandler; 027 import org.dbreplicator.replication.*; 028 import java.sql.Connection; 029 import java.sql.Statement; 030 import java.sql.ResultSet; 031 import java.sql.*; 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 EditSchedule 043 extends JDialog 044 implements FocusListener, KeyListener { 045 JPanel panel1 = new JPanel(); 046 JLabel jLabel1 = new JLabel(); 047 JComboBox jComboScheduleName = new JComboBox(); 048 JTextField jTextSubName = new JTextField(); 049 JButton jButtonGetSchedule = new JButton(); 050 JButton jButtonStartSchedule = new JButton(); 051 JButton jButtonCancle = new JButton(); 052 _ReplicationServer repServer; 053 JLabel jLabel2 = new JLabel(); 054 JLabel jLabelOldRemoteServerName = new JLabel(); 055 JLabel jLabelOldRemoteRepPortNo = new JLabel(); 056 JLabel jLabelNewRemoteServerName = new JLabel(); 057 JLabel jLabelNewRemoteRepPortNo = new JLabel(); 058 JLabel jLabelScheduleName = new JLabel(); 059 JTextField jTextOldRemoteServerName = new JTextField(); 060 JTextField jTextOldRemoteRepPortNo = new JTextField(); 061 JTextField jTextNewRemoteServerName = new JTextField(); 062 JTextField jTextNewRemoteRepPortNo = new JTextField(); 063 064 JLabel jLabel6 = new JLabel(); 065 JEditorPane help = new JEditorPane(); 066 String subName; 067 boolean able = true; 068 _Subscription sub = null; 069 AbstractDataBaseHandler dbHandler = null; 070 Border border1; 071 072 public EditSchedule(Frame frame, String title, boolean modal, boolean able0) { 073 super(frame, title, modal); 074 able = able0; 075 try { 076 jbInit(); 077 pack(); 078 } 079 catch (Exception ex) { 080 JOptionPane.showMessageDialog(this, ex, "Error Message", 081 JOptionPane.ERROR_MESSAGE); 082 return; 083 } 084 } 085 086 public EditSchedule(_ReplicationServer repServer0, boolean able0) { 087 this(StartRepServer.getMainFrame(), "Edit Schedule", true, able0); 088 repServer = repServer0; 089 able = able0; 090 } 091 092 public EditSchedule(_ReplicationServer repServer0, String subName0, 093 boolean able0) { 094 this(null, "Edit Schedule", true, able0); 095 repServer = repServer0; 096 subName = subName0; 097 able = able0; 098 init(); 099 } 100 101 private void init() { 102 try { 103 sub = repServer.getSubscription(subName); 104 jTextSubName.setText(subName); 105 jTextSubName.setEnabled(able); 106 if (!jTextNewRemoteRepPortNo.getText().trim().equalsIgnoreCase("") && 107 !jTextNewRemoteServerName.getText().trim().equalsIgnoreCase("")) { 108 jButtonStartSchedule.setEnabled(true); 109 } 110 } 111 catch (RepException ex) { 112 JOptionPane.showMessageDialog(this, ex, "Error Message", 113 JOptionPane.ERROR_MESSAGE); 114 return; 115 } 116 } 117 118 private void jbInit() throws Exception { 119 border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, 120 new Color(148, 145, 140)); 121 panel1.setLayout(null); 122 panel1.setAlignmentY( (float) 0.5); 123 panel1.setDebugGraphicsOptions(0); 124 125 jLabel1.setFont(new java.awt.Font("Dialog", 1, 13)); 126 jLabel1.setToolTipText(""); 127 jLabel1.setHorizontalAlignment(SwingConstants.LEFT); 128 jLabel1.setText("Subscription Name"); 129 jLabel1.setBounds(new Rectangle(20, 65, 141, 23)); 130 131 jLabel2.setFont(new java.awt.Font("Serif", 3, 25)); 132 jLabel2.setForeground(SystemColor.infoText); 133 jLabel2.setVerifyInputWhenFocusTarget(true); 134 jLabel2.setText("Edit Schedule"); 135 int center = jLabel2.CENTER; 136 jLabel2.setHorizontalAlignment(center); 137 jLabel2.setBounds(new Rectangle(130, 12, 167, 27)); 138 139 jLabelScheduleName.setFont(new java.awt.Font("Dialog", 1, 13)); 140 jLabelScheduleName.setToolTipText(""); 141 jLabelScheduleName.setHorizontalAlignment(SwingConstants.LEFT); 142 jLabelScheduleName.setText("Schedule Name"); 143 jLabelScheduleName.setBounds(new Rectangle(20, 91, 161, 23)); 144 145 jLabelOldRemoteServerName.setFont(new java.awt.Font("Dialog", 1, 13)); 146 jLabelOldRemoteServerName.setRequestFocusEnabled(true); 147 jLabelOldRemoteServerName.setHorizontalAlignment(SwingConstants.LEFT); 148 jLabelOldRemoteServerName.setText("Old Publication Server Name"); 149 jLabelOldRemoteServerName.setBounds(new Rectangle(20, 119, 200, 23)); 150 151 jLabelOldRemoteRepPortNo.setFont(new java.awt.Font("Dialog", 1, 13)); 152 jLabelOldRemoteRepPortNo.setRequestFocusEnabled(true); 153 jLabelOldRemoteRepPortNo.setHorizontalAlignment(SwingConstants.LEFT); 154 jLabelOldRemoteRepPortNo.setText("Old Publication Port No."); 155 jLabelOldRemoteRepPortNo.setBounds(new Rectangle(20, 148, 161, 23)); 156 157 jLabelNewRemoteServerName.setFont(new java.awt.Font("Dialog", 1, 13)); 158 jLabelNewRemoteServerName.setRequestFocusEnabled(true); 159 jLabelNewRemoteServerName.setHorizontalAlignment(SwingConstants.LEFT); 160 jLabelNewRemoteServerName.setText("New Publication Server Name"); 161 jLabelNewRemoteServerName.setBounds(new Rectangle(20, 177, 210, 23)); 162 163 jLabelNewRemoteRepPortNo.setFont(new java.awt.Font("Dialog", 1, 13)); 164 jLabelNewRemoteRepPortNo.setRequestFocusEnabled(true); 165 jLabelNewRemoteRepPortNo.setHorizontalAlignment(SwingConstants.LEFT); 166 jLabelNewRemoteRepPortNo.setText("New Publication Port No."); 167 jLabelNewRemoteRepPortNo.setBounds(new Rectangle(20, 206, 161, 23)); 168 169 jTextSubName.setFont(new java.awt.Font("Dialog", 0, 12)); 170 jTextSubName.setText(""); 171 jTextSubName.setBounds(new Rectangle(230, 63, 167, 23)); 172 jTextSubName.requestFocus(); 173 jTextSubName.grabFocus(); 174 175 jComboScheduleName.setBounds(new Rectangle(230, 90, 90, 23)); 176 177 jButtonGetSchedule.setBounds(new Rectangle(330, 90, 68, 23)); 178 jButtonGetSchedule.setEnabled(true); 179 jButtonGetSchedule.setFont(new java.awt.Font("Dialog", 1, 12)); 180 jButtonGetSchedule.setText("Load"); 181 jButtonGetSchedule.addActionListener(new 182 EditSchedule_jButtonGetSchedule_actionAdapter(this)); 183 184 jTextOldRemoteServerName.setFont(new java.awt.Font("Dialog", 0, 12)); 185 jTextOldRemoteServerName.setText(""); 186 jTextOldRemoteServerName.setEditable(false); 187 jTextOldRemoteServerName.setBounds(new Rectangle(230, 117, 167, 23)); 188 189 jTextOldRemoteRepPortNo.setFont(new java.awt.Font("Dialog", 0, 12)); 190 jTextOldRemoteRepPortNo.setText(""); 191 jTextOldRemoteRepPortNo.setEditable(false); 192 jTextOldRemoteRepPortNo.setBounds(new Rectangle(230, 146, 167, 23)); 193 194 jTextNewRemoteServerName.setFont(new java.awt.Font("Dialog", 0, 12)); 195 jTextNewRemoteServerName.setText(""); 196 jTextNewRemoteServerName.setBounds(new Rectangle(230, 177, 167, 23)); 197 198 jTextNewRemoteRepPortNo.setFont(new java.awt.Font("Dialog", 0, 12)); 199 jTextNewRemoteRepPortNo.setText(""); 200 jTextNewRemoteRepPortNo.setBounds(new Rectangle(230, 206, 167, 23)); 201 202 jButtonStartSchedule.setBounds(new Rectangle(161, 291, 116, 25)); 203 jButtonStartSchedule.setEnabled(false); 204 jButtonStartSchedule.setFont(new java.awt.Font("Dialog", 1, 12)); 205 jButtonStartSchedule.setText("Edit"); 206 jButtonStartSchedule.addActionListener(new 207 EditSchedule_jButtonStartSchedule_actionAdapter(this)); 208 209 jButtonCancle.setBounds(new Rectangle(286, 291, 116, 25)); 210 jButtonCancle.setFont(new java.awt.Font("Dialog", 1, 12)); 211 jButtonCancle.setText("Cancel"); 212 jButtonCancle.addActionListener(new 213 EditSchedule_jButtonCancle_actionAdapter(this)); 214 215 jLabel6.setBorder(border1); 216 jLabel6.setPreferredSize(new Dimension(2, 2)); 217 jLabel6.setToolTipText(""); 218 jLabel6.setText(""); 219 jLabel6.setVerticalAlignment(SwingConstants.CENTER); 220 jLabel6.setBounds(new Rectangle(12, 51, 400, 190)); 221 222 jTextNewRemoteRepPortNo.setDocument(new NumericDocument()); 223 224 jTextNewRemoteRepPortNo.addKeyListener(this); 225 jTextNewRemoteServerName.addKeyListener(this); 226 jTextSubName.addKeyListener(this); 227 jTextNewRemoteRepPortNo.addFocusListener(this); 228 jTextNewRemoteServerName.addFocusListener(this); 229 jTextSubName.addFocusListener(this); 230 231 help.setBackground(UIManager.getColor("Button.background")); 232 help.setEnabled(false); 233 help.setFont(new java.awt.Font("Dialog", 2, 12)); 234 help.setAlignmentY( (float) 0.5); 235 help.setMinimumSize(new Dimension(352, 21)); 236 help.setDisabledTextColor(Color.black); 237 help.setText( 238 "Edit schedule "); 239 help.setBounds(new Rectangle(12, 250, 339, 30)); 240 panel1.add(help, null); 241 panel1.add(jComboScheduleName, null); 242 panel1.add(jTextOldRemoteServerName, null); 243 panel1.add(jTextOldRemoteRepPortNo, null); 244 panel1.add(jTextNewRemoteServerName, null); 245 panel1.add(jTextNewRemoteRepPortNo, null); 246 panel1.add(jTextSubName, null); 247 panel1.add(jLabelScheduleName); 248 panel1.add(jLabel1, null); 249 panel1.add(jLabel2, null); 250 panel1.add(jLabelOldRemoteRepPortNo, null); 251 panel1.add(jLabelOldRemoteServerName, null); 252 panel1.add(jLabelNewRemoteRepPortNo, null); 253 panel1.add(jLabelNewRemoteServerName, null); 254 panel1.add(jButtonGetSchedule, null); 255 panel1.add(jButtonCancle, null); 256 panel1.add(jButtonStartSchedule, null); 257 panel1.add(jLabel6, null); 258 this.getContentPane().add(panel1, BorderLayout.CENTER); 259 } 260 261 void jButtonCancle_actionPerformed(ActionEvent e) { 262 dispose(); 263 hide(); 264 } 265 266 void jButtonStartSchedule_actionPerformed(ActionEvent e) { 267 try { 268 String subName = jTextSubName.getText().trim(); 269 if (subName.equalsIgnoreCase("")) { 270 throw new RepException("REP093", new Object[] {null}); 271 } 272 String port = jTextNewRemoteRepPortNo.getText().trim(); 273 if (port.equalsIgnoreCase("")) { 274 throw new RepException("REP094", new Object[] {null}); 275 } 276 int remoteRepPortNo = Integer.valueOf(port).intValue(); 277 if (remoteRepPortNo <= 0) { 278 throw new RepException("REP220", new Object[] {null}); 279 } 280 String remoteServerName = jTextNewRemoteServerName.getText().trim(); 281 if (remoteServerName.equalsIgnoreCase("")) { 282 throw new RepException("REP095", new Object[] {null}); 283 } 284 sub = repServer.getSubscription(subName); 285 if (sub == null) { 286 throw new RepException("REP037", new Object[] {subName}); 287 } 288 sub.setRemoteServerPortNo(remoteRepPortNo); 289 sub.setRemoteServerUrl(remoteServerName); 290 291 if (jComboScheduleName.getSelectedItem() == null) { 292 throw new RepException("REP207", new Object[] {null}); 293 } 294 String scheduleName = jComboScheduleName.getSelectedItem().toString(); 295 String newPubServerName = jTextNewRemoteServerName.getText().toString(); 296 String newPubPortNo = jTextNewRemoteRepPortNo.getText().toString(); 297 sub.editSchedule(scheduleName, subName, 298 newPubServerName, newPubPortNo); 299 JOptionPane.showMessageDialog(this, "Schedule edited Successfully", 300 "Success", JOptionPane.INFORMATION_MESSAGE); 301 hide(); 302 } 303 catch (RepException ex) { 304 RepConstants.writeERROR_FILE(ex); 305 JOptionPane.showMessageDialog(this, ex, "Error Message", 306 JOptionPane.ERROR_MESSAGE); 307 return; 308 } 309 catch (Exception ex1) { 310 RepConstants.writeERROR_FILE(ex1); 311 return; 312 } 313 } 314 315 public void jButtonGetSchedule_actionPerformed(ActionEvent e) { 316 Statement st =null; 317 ResultSet rs =null; 318 try { 319 if(jComboScheduleName.getItemCount()!=0){ 320 jComboScheduleName.removeAllItems(); 321 } 322 323 String subName = jTextSubName.getText().trim(); 324 if (subName.equalsIgnoreCase("")) { 325 throw new RepException("REP093", new Object[] {null}); 326 } 327 sub = repServer.getSubscription(subName); 328 if (sub == null) { 329 throw new RepException("REP037", new Object[] {subName}); 330 } 331 dbHandler = Utility.getDatabaseHandler(((Subscription)sub).getConnectionPool(), subName); 332 Connection con = repServer.getDefaultConnection(); 333 st = con.createStatement(); 334 rs = st.executeQuery("select * from " + 335 dbHandler.getScheduleTableName() + 336 " where " + 337 RepConstants.subscription_subName1 + 338 " = '" + subName + "'"); 339 340 if (rs.next()) { 341 jComboScheduleName.addItem(rs.getString(RepConstants.schedule_Name)); 342 jTextOldRemoteServerName.setText(rs.getString(4)); 343 jTextOldRemoteRepPortNo.setText(rs.getString(5)); 344 } 345 else { 346 throw new RepException("REP210", new Object[] {subName}); 347 } 348 } 349 catch (RepException ex) { 350 JOptionPane.showMessageDialog(this, ex, "Error Message", 351 JOptionPane.ERROR_MESSAGE); 352 return; 353 } 354 catch (Exception ex) { 355 } finally { 356 try { 357 if (rs != null) { 358 rs.close(); 359 } 360 if (st != null) { 361 st.close(); 362 } 363 } 364 catch (SQLException ex1) { 365 } 366 } 367 } 368 369 public void focusGained(FocusEvent fe) { 370 if ( ( (JTextField) fe.getSource()).equals(jTextNewRemoteRepPortNo)) { 371 help.setText("Enter New Port number in this box"); 372 } 373 else if ( ( (JTextField) fe.getSource()).equals(jTextSubName)) { 374 help.setText("Enter Subscription Name in this box"); 375 } 376 else if ( ( (JTextField) fe.getSource()).equals(jTextNewRemoteServerName)) { 377 help.setText("Enter New Server Name in this box"); 378 } 379 380 if ( (jTextNewRemoteRepPortNo.getText().equals("") || 381 jTextNewRemoteServerName.getText().equals(""))) { 382 jButtonStartSchedule.setEnabled(false); 383 } 384 } 385 386 public void focusLost(FocusEvent fe) { 387 jButtonStartSchedule.setEnabled(true); 388 if (jTextNewRemoteRepPortNo.getText().equals("") || 389 jTextNewRemoteServerName.getText().equals("") || 390 jTextSubName.getText().equals("")) { 391 jButtonStartSchedule.setEnabled(false); 392 393 } 394 } 395 396 public void keyTyped(KeyEvent keyEvent) { 397 } 398 399 public void keyPressed(KeyEvent keyEvent) { 400 } 401 402 public void keyReleased(KeyEvent keyEvent) { 403 jButtonStartSchedule.setEnabled(true); 404 if (jTextNewRemoteRepPortNo.getText().equals("") || 405 jTextNewRemoteServerName.getText().equals("") || 406 jTextSubName.getText().equals("")) { 407 jButtonStartSchedule.setEnabled(false); 408 } 409 else { 410 if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) { 411 jButtonStartSchedule_actionPerformed(null); 412 } 413 } 414 415 } 416 } 417 418 class EditSchedule_jButtonCancle_actionAdapter 419 implements java.awt.event.ActionListener { 420 EditSchedule adaptee; 421 422 EditSchedule_jButtonCancle_actionAdapter(EditSchedule adaptee) { 423 this.adaptee = adaptee; 424 } 425 426 public void actionPerformed(ActionEvent e) { 427 adaptee.jButtonCancle_actionPerformed(e); 428 } 429 } 430 431 class EditSchedule_jButtonStartSchedule_actionAdapter 432 implements java.awt.event.ActionListener { 433 EditSchedule adaptee; 434 435 EditSchedule_jButtonStartSchedule_actionAdapter(EditSchedule adaptee) { 436 this.adaptee = adaptee; 437 } 438 439 public void actionPerformed(ActionEvent e) { 440 adaptee.jButtonStartSchedule_actionPerformed(e); 441 } 442 443 } 444 445 class EditSchedule_jButtonGetSchedule_actionAdapter 446 implements java.awt.event.ActionListener { 447 EditSchedule adaptee; 448 449 EditSchedule_jButtonGetSchedule_actionAdapter(EditSchedule adaptee) { 450 this.adaptee = adaptee; 451 } 452 453 public void actionPerformed(ActionEvent e) { 454 adaptee.jButtonGetSchedule_actionPerformed(e); 455 } 456 }

