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 027 import org.dbreplicator.replication.*; 028 029 /** 030 * <p>Title: </p> 031 * <p>Description: </p> 032 * <p>Copyright: Copyright (c) 2003</p> 033 * <p>Company: </p> 034 * @author not attributable 035 * @version 1.0 036 */ 037 038 public class Synchronize extends JDialog implements FocusListener, KeyListener 039 { 040 JPanel panel1 = new JPanel(); 041 JLabel jLabel1 = new JLabel(); 042 JTextField jTextSubName = new JTextField(); 043 JButton jButtonSynchronize = new JButton(); 044 JButton jButtonCancle = new JButton(); 045 _ReplicationServer repServer; 046 JLabel jLabel2 = new JLabel(); 047 JLabel jLabel4 = new JLabel(); 048 JTextField jTextRemoteServerName = new JTextField(); 049 JTextField jTextRemoteRepPortNo = new JTextField(); 050 JLabel jLabel3 = new JLabel(); 051 JLabel jLabel6 = new JLabel(); 052 JEditorPane help = new JEditorPane(); 053 String subName; 054 boolean able = true; 055 _Subscription sub = null; 056 Border border1; 057 058 public Synchronize(Frame frame, String title, boolean modal, boolean able0) 059 { 060 super(frame, title, modal); 061 able = able0; 062 try 063 { 064 jbInit(); 065 pack(); 066 } 067 catch (Exception ex) 068 { 069 JOptionPane.showMessageDialog(this, ex, "Error Message", 070 JOptionPane.ERROR_MESSAGE); 071 return; 072 } 073 } 074 075 // public Synchronize(_ReplicationServer repServer0) { 076 // this(null, "Synchronize", true); 077 // repServer = repServer0; 078 // } 079 // 080 // public Synchronize(_ReplicationServer repServer0,String subName0) { 081 // this(null, "Synchronize", true); 082 // repServer = repServer0; 083 // subName = subName0; 084 // init(); 085 // } 086 087 public Synchronize(_ReplicationServer repServer0, boolean able0) 088 { 089 this(StartRepServer.getMainFrame(), "Synchronize", true, able0); 090 repServer = repServer0; 091 able = able0; 092 } 093 094 public Synchronize(_ReplicationServer repServer0, String subName0, 095 boolean able0) 096 { 097 this(null, "Synchronize", true, able0); 098 repServer = repServer0; 099 subName = subName0; 100 able = able0; 101 init(); 102 } 103 104 private void init() 105 { 106 try 107 { 108 sub = repServer.getSubscription(subName); 109 jTextSubName.setText(subName); 110 jTextSubName.setEnabled(able); 111 jTextRemoteRepPortNo.setText("" + sub.getRemoteServerPortNo()); 112 jTextRemoteServerName.setText(sub.getRemoteServerUrl()); 113 if (!jTextRemoteRepPortNo.getText().trim().equalsIgnoreCase("") && 114 !jTextRemoteServerName.getText().trim().equalsIgnoreCase("")) 115 { 116 jButtonSynchronize.setEnabled(true); 117 } 118 } 119 catch (RepException ex) 120 { 121 JOptionPane.showMessageDialog(this, ex, "Error Message", 122 JOptionPane.ERROR_MESSAGE); 123 // ex.printStackTrace(); 124 return; 125 } 126 } 127 128 private void jbInit() throws Exception 129 { 130 border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, 131 new Color(148, 145, 140)); 132 panel1.setLayout(null); 133 jLabel1.setFont(new java.awt.Font("Dialog", 1, 13)); 134 jLabel1.setToolTipText(""); 135 jLabel1.setHorizontalAlignment(SwingConstants.LEFT); 136 jLabel1.setText("Subscription Name"); 137 jLabel1.setBounds(new Rectangle(20, 65, 141, 23)); 138 panel1.setAlignmentY( (float) 0.5); 139 panel1.setDebugGraphicsOptions(0); 140 jTextSubName.setFont(new java.awt.Font("Dialog", 0, 12)); 141 jTextSubName.setText(""); 142 jTextSubName.setBounds(new Rectangle(186, 63, 147, 23)); 143 jButtonSynchronize.setBounds(new Rectangle(111, 211, 116, 25)); 144 jButtonSynchronize.setEnabled(false); 145 jButtonSynchronize.setFont(new java.awt.Font("Dialog", 1, 12)); 146 jButtonSynchronize.setText("Synchronize"); 147 jButtonSynchronize.addActionListener(new 148 Synchronize_jButtonSynchronize_actionAdapter(this)); 149 jButtonCancle.setBounds(new Rectangle(236, 211, 116, 25)); 150 jButtonCancle.setFont(new java.awt.Font("Dialog", 1, 12)); 151 jButtonCancle.setText("Cancel"); 152 jButtonCancle.addActionListener(new Synchronize_jButtonCancle_actionAdapter(this)); 153 jLabel2.setFont(new java.awt.Font("Serif", 3, 25)); 154 jLabel2.setForeground(SystemColor.infoText); 155 jLabel2.setVerifyInputWhenFocusTarget(true); 156 jLabel2.setText("Synchronize"); 157 jLabel2.setBounds(new Rectangle(113, 12, 167, 27)); 158 jLabel4.setFont(new java.awt.Font("Dialog", 1, 13)); 159 jLabel4.setRequestFocusEnabled(true); 160 jLabel4.setHorizontalAlignment(SwingConstants.LEFT); 161 jLabel4.setText("Publication Server Name"); 162 jLabel4.setBounds(new Rectangle(20, 91, 165, 23)); 163 jTextRemoteServerName.setFont(new java.awt.Font("Dialog", 0, 12)); 164 jTextRemoteServerName.setText(""); 165 jTextRemoteServerName.setBounds(new Rectangle(186, 90, 147, 23)); 166 jTextRemoteRepPortNo.setFont(new java.awt.Font("Dialog", 0, 12)); 167 jTextRemoteRepPortNo.setText(""); 168 jTextRemoteRepPortNo.setBounds(new Rectangle(186, 117, 147, 23)); 169 jLabel3.setFont(new java.awt.Font("Dialog", 1, 13)); 170 jLabel3.setRequestFocusEnabled(true); 171 jLabel3.setHorizontalAlignment(SwingConstants.LEFT); 172 jLabel3.setText("Publication Port Number"); 173 jLabel3.setBounds(new Rectangle(20, 119, 161, 23)); 174 jLabel6.setBorder(border1); 175 jLabel6.setPreferredSize(new Dimension(2, 2)); 176 jLabel6.setToolTipText(""); 177 jLabel6.setText(""); 178 jLabel6.setVerticalAlignment(SwingConstants.CENTER); 179 jLabel6.setBounds(new Rectangle(12, 51, 340, 104)); 180 181 jTextRemoteRepPortNo.setDocument(new NumericDocument()); 182 183 jTextRemoteRepPortNo.addKeyListener(this); 184 jTextRemoteServerName.addKeyListener(this); 185 jTextSubName.addKeyListener(this); 186 jTextRemoteRepPortNo.addFocusListener(this); 187 jTextRemoteServerName.addFocusListener(this); 188 jTextSubName.addFocusListener(this); 189 190 jTextSubName.grabFocus(); 191 help.setBackground(UIManager.getColor("Button.background")); 192 help.setEnabled(false); 193 help.setFont(new java.awt.Font("Dialog", 2, 12)); 194 help.setAlignmentY( (float) 0.5); 195 help.setMinimumSize(new Dimension(352, 21)); 196 help.setDisabledTextColor(Color.black); 197 help.setText( 198 " The changes made to the data by both Publisher and Subscriber " + 199 "will be merged"); 200 help.setBounds(new Rectangle(12, 159, 339, 35)); 201 panel1.add(help, null); 202 panel1.add(jTextRemoteServerName, null); 203 panel1.add(jTextRemoteRepPortNo, null); 204 panel1.add(jTextSubName, null); 205 panel1.add(jLabel4, null); 206 panel1.add(jLabel1, null); 207 panel1.add(jLabel3, null); 208 panel1.add(jLabel6, null); 209 panel1.add(jButtonCancle, null); 210 panel1.add(jButtonSynchronize, null); 211 panel1.add(jLabel2, null); 212 this.getContentPane().add(panel1, BorderLayout.CENTER); 213 } 214 215 void jButtonCancle_actionPerformed(ActionEvent e) 216 { 217 hide(); 218 } 219 220 void jButtonSynchronize_actionPerformed(ActionEvent e) 221 { 222 try 223 { 224 String subName = jTextSubName.getText().trim(); 225 if (subName.equalsIgnoreCase("")) 226 { 227 throw new RepException("REP093", new Object[] 228 {null}); 229 } 230 String port = jTextRemoteRepPortNo.getText().trim(); 231 if (port.equalsIgnoreCase("")) 232 { 233 throw new RepException("REP094", new Object[] 234 {null}); 235 } 236 int remoteRepPortNo = Integer.valueOf(port).intValue(); 237 if (remoteRepPortNo <= 0) 238 { 239 throw new NumberFormatException(); 240 } 241 242 String remoteServerName = jTextRemoteServerName.getText().trim(); 243 if (remoteServerName.equalsIgnoreCase("")) 244 { 245 throw new RepException("REP095", new Object[] 246 {null}); 247 } 248 249 sub = repServer.getSubscription(subName); 250 if (sub == null) 251 { 252 throw new RepException("REP059", new Object[] 253 {subName}); 254 } 255 sub.setRemoteServerPortNo(remoteRepPortNo); 256 sub.setRemoteServerUrl(remoteServerName); 257 sub.synchronize(); 258 JOptionPane.showMessageDialog(this, "Synchronized Successfully", 259 "Success", JOptionPane.INFORMATION_MESSAGE); 260 hide(); 261 } 262 catch (RepException ex) 263 { 264 JOptionPane.showMessageDialog(this, ex, "Error Message", 265 JOptionPane.ERROR_MESSAGE); 266 return; 267 } 268 catch (NumberFormatException ex2) 269 { 270 JOptionPane.showMessageDialog(this, 271 "Enter only Positive Integer in Server Port No", 272 "Error Message", 273 JOptionPane.ERROR_MESSAGE); 274 return; 275 } 276 catch (Exception ex1) 277 { 278 JOptionPane.showMessageDialog(this, ex1, "Error Message", 279 JOptionPane.ERROR_MESSAGE); 280 return; 281 } 282 } 283 284 public void focusGained(FocusEvent fe) 285 { 286 if ( ( (JTextField) fe.getSource()).equals(jTextRemoteRepPortNo)) 287 { 288 help.setText("Enter Port number in this box"); 289 } 290 else if ( ( (JTextField) fe.getSource()).equals(jTextSubName)) 291 { 292 help.setText("Enter Subscription Name in this box"); 293 } 294 else if ( ( (JTextField) fe.getSource()).equals(jTextRemoteServerName)) 295 { 296 help.setText("Enter Server Name in this box"); 297 298 } 299 if (! (jTextRemoteRepPortNo.getText().equals("") || 300 jTextRemoteServerName.getText().equals("") || 301 jTextSubName.getText().equals(""))) 302 { 303 jButtonSynchronize.setEnabled(true); 304 } 305 } 306 307 public void focusLost(FocusEvent fe) 308 { 309 jButtonSynchronize.setEnabled(true); 310 if (jTextRemoteRepPortNo.getText().equals("") || 311 jTextRemoteServerName.getText().equals("") || 312 jTextSubName.getText().equals("")) 313 { 314 jButtonSynchronize.setEnabled(false); 315 316 } 317 } 318 319 public void keyTyped(KeyEvent keyEvent) 320 { 321 } 322 323 public void keyPressed(KeyEvent keyEvent) 324 { 325 } 326 327 public void keyReleased(KeyEvent keyEvent) 328 { 329 jButtonSynchronize.setEnabled(true); 330 if (jTextRemoteRepPortNo.getText().equals("") || 331 jTextRemoteServerName.getText().equals("") || 332 jTextSubName.getText().equals("")) 333 { 334 jButtonSynchronize.setEnabled(false); 335 } 336 else 337 { 338 if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) 339 { 340 jButtonSynchronize_actionPerformed(null); 341 } 342 } 343 344 } 345 } 346 347 class Synchronize_jButtonCancle_actionAdapter implements java.awt.event.ActionListener 348 { 349 Synchronize adaptee; 350 351 Synchronize_jButtonCancle_actionAdapter(Synchronize adaptee) 352 { 353 this.adaptee = adaptee; 354 } 355 356 public void actionPerformed(ActionEvent e) 357 { 358 adaptee.jButtonCancle_actionPerformed(e); 359 } 360 } 361 362 class Synchronize_jButtonSynchronize_actionAdapter implements java.awt.event.ActionListener 363 { 364 Synchronize adaptee; 365 366 Synchronize_jButtonSynchronize_actionAdapter(Synchronize adaptee) 367 { 368 this.adaptee = adaptee; 369 } 370 371 public void actionPerformed(ActionEvent e) 372 { 373 adaptee.jButtonSynchronize_actionPerformed(e); 374 } 375 }

