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 GetSnapshot extends JDialog implements FocusListener, KeyListener 039 { 040 JPanel panel1 = new JPanel(); 041 JLabel jLabel1 = new JLabel(); 042 JTextField jTextSubName = new JTextField(); 043 JButton jButtonGetSNapshot = 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 _Subscription sub = null; 054 String subName; 055 boolean able = true; 056 String snapShotType; 057 TitledBorder titledBorder1; 058 Border border1; 059 String snapShotAfterSubscribing="AfterSubscribing"; 060 String snapShotAfterUpdating="AfterUpdating"; 061 062 public GetSnapshot(Frame frame, String title, boolean modal) 063 { 064 super(frame, title, modal); 065 try 066 { 067 jbInit(); 068 pack(); 069 } 070 catch (Exception ex) 071 { 072 JOptionPane.showMessageDialog(this, ex, "Error Message", 073 JOptionPane.ERROR_MESSAGE); 074 return; 075 } 076 } 077 078 public GetSnapshot(Frame frame, String title, boolean modal, boolean able0) 079 { 080 super(frame, title, modal); 081 able = able0; 082 try 083 { 084 jbInit(); 085 pack(); 086 } 087 catch (Exception ex) 088 { 089 JOptionPane.showMessageDialog(this, ex, "Error Message", 090 JOptionPane.ERROR_MESSAGE); 091 return; 092 } 093 } 094 095 /* 096 public GetSnapshot(_ReplicationServer repServer0) { 097 this(null, "SnapShot", true); 098 repServer = repServer0; 099 } 100 101 public GetSnapshot(_ReplicationServer repServer0, String subName0) { 102 this(null, "SnapShot", true); 103 repServer = repServer0; 104 subName = subName0; 105 init(); 106 } 107 */ 108 public GetSnapshot(_ReplicationServer repServer0, boolean able0,String snapShotType0) 109 { 110 this(StartRepServer.getMainFrame(), "SnapShot", true, able0); 111 repServer = repServer0; 112 able = able0; 113 snapShotType=snapShotType0; 114 } 115 116 public GetSnapshot(_ReplicationServer repServer0, String subName0, 117 boolean able0,String snapShotType0) 118 { 119 this(null, "SnapShot", true, able0); 120 repServer = repServer0; 121 subName = subName0; 122 able = able0; 123 snapShotType=snapShotType0; 124 init(); 125 } 126 127 private void init() 128 { 129 try 130 { 131 sub = repServer.getSubscription(subName); 132 jTextSubName.setText(subName); 133 jTextSubName.setEnabled(able); 134 jTextRemoteRepPortNo.setText("" + sub.getRemoteServerPortNo()); 135 jTextRemoteServerName.setText(sub.getRemoteServerUrl()); 136 if (!jTextRemoteRepPortNo.getText().trim().equalsIgnoreCase("") && 137 !jTextRemoteServerName.getText().equalsIgnoreCase("")) 138 { 139 jButtonGetSNapshot.setEnabled(true); 140 } 141 } 142 catch (RepException ex) 143 { 144 JOptionPane.showMessageDialog(this, ex, "Error Message", 145 JOptionPane.ERROR_MESSAGE); 146 // ex.printStackTrace(); 147 return; 148 } 149 } 150 151 private void jbInit() throws Exception 152 { 153 titledBorder1 = new TitledBorder(""); 154 border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, 155 new Color(148, 145, 140)); 156 panel1.setLayout(null); 157 jLabel1.setFont(new java.awt.Font("Dialog", 1, 13)); 158 jLabel1.setPreferredSize(new Dimension(182, 16)); 159 jLabel1.setHorizontalAlignment(SwingConstants.LEFT); 160 jLabel1.setText("Subscription Name"); 161 jLabel1.setBounds(new Rectangle(23, 72, 157, 23)); 162 panel1.setAlignmentY( (float) 0.5); 163 panel1.setDebugGraphicsOptions(0); 164 jTextSubName.setFont(new java.awt.Font("Dialog", 0, 12)); 165 jTextSubName.setMinimumSize(new Dimension(6, 22)); 166 jTextSubName.setFocusAccelerator('0'); 167 jTextSubName.setText(""); 168 jTextSubName.setHorizontalAlignment(SwingConstants.LEFT); 169 jTextSubName.setBounds(new Rectangle(190, 73, 178, 21)); 170 jButtonGetSNapshot.setBounds(new Rectangle(106, 229, 131, 25)); 171 jButtonGetSNapshot.setEnabled(false); 172 jButtonGetSNapshot.setFont(new java.awt.Font("Dialog", 1, 12)); 173 jButtonGetSNapshot.setHorizontalAlignment(SwingConstants.CENTER); 174 jButtonGetSNapshot.setText("Get Snapshot"); 175 jButtonGetSNapshot.addActionListener(new 176 GetSnapshot_jButtonGetSNapshot_actionAdapter(this)); 177 jButtonCancle.setBounds(new Rectangle(249, 229, 131, 25)); 178 jButtonCancle.setFont(new java.awt.Font("Dialog", 1, 12)); 179 jButtonCancle.setHorizontalAlignment(SwingConstants.CENTER); 180 jButtonCancle.setText("Cancel"); 181 jButtonCancle.addActionListener(new GetSnapshot_jButtonCancle_actionAdapter(this)); 182 jLabel2.setEnabled(true); 183 jLabel2.setFont(new java.awt.Font("Serif", 3, 25)); 184 jLabel2.setText("Snapshot"); 185 jLabel2.setBounds(new Rectangle(135, 2, 118, 36)); 186 jLabel4.setFont(new java.awt.Font("Dialog", 1, 13)); 187 jLabel4.setRequestFocusEnabled(true); 188 jLabel4.setToolTipText(""); 189 jLabel4.setHorizontalAlignment(SwingConstants.LEFT); 190 jLabel4.setText("Publication Server Name"); 191 jLabel4.setBounds(new Rectangle(22, 102, 163, 23)); 192 jTextRemoteServerName.setFont(new java.awt.Font("Dialog", 0, 12)); 193 jTextRemoteServerName.setText(""); 194 jTextRemoteServerName.setHorizontalAlignment(SwingConstants.LEFT); 195 jTextRemoteServerName.setBounds(new Rectangle(190, 102, 178, 21)); 196 jTextRemoteRepPortNo.setFont(new java.awt.Font("Dialog", 0, 12)); 197 jTextRemoteRepPortNo.setText(""); 198 jTextRemoteRepPortNo.setHorizontalAlignment(SwingConstants.LEFT); 199 jTextRemoteRepPortNo.setBounds(new Rectangle(190, 130, 178, 21)); 200 jLabel3.setFont(new java.awt.Font("Dialog", 1, 13)); 201 jLabel3.setRequestFocusEnabled(true); 202 jLabel3.setHorizontalAlignment(SwingConstants.LEFT); 203 jLabel3.setText("Publication Port Number"); 204 jLabel3.setBounds(new Rectangle(22, 131, 157, 23)); 205 jLabel6.setBorder(border1); 206 jLabel6.setDebugGraphicsOptions(0); 207 jLabel6.setText(""); 208 jLabel6.setBounds(new Rectangle(12, 56, 369, 111)); 209 210 jTextRemoteRepPortNo.setDocument(new NumericDocument()); 211 212 jTextRemoteRepPortNo.addFocusListener(this); 213 jTextRemoteServerName.addFocusListener(this); 214 jTextSubName.addFocusListener(this); 215 jTextRemoteRepPortNo.addKeyListener(this); 216 jTextRemoteServerName.addKeyListener(this); 217 jTextSubName.addKeyListener(this); 218 219 jTextSubName.grabFocus(); 220 help.setBackground(UIManager.getColor("Button.background")); 221 help.setEnabled(false); 222 help.setFont(new java.awt.Font("Dialog", 2, 12)); 223 help.setRequestFocusEnabled(false); 224 help.setToolTipText(""); 225 help.setDisabledTextColor(Color.black); 226 help.setEditable(false); 227 help.setText( 228 "Will transfer a complete copy of the contents of a Publishers publication " + 229 "to a Subscribers subscription."); 230 help.setBounds(new Rectangle(10, 169, 363, 34)); 231 panel1.add(jLabel6, null); 232 panel1.add(jTextRemoteRepPortNo, null); 233 panel1.add(jTextSubName, null); 234 panel1.add(jTextRemoteServerName, null); 235 panel1.add(jLabel1, null); 236 panel1.add(jLabel3, null); 237 panel1.add(jLabel4, null); 238 panel1.add(help, null); 239 panel1.add(jButtonCancle, null); 240 panel1.add(jButtonGetSNapshot, null); 241 panel1.add(jLabel2, null); 242 this.getContentPane().add(panel1, BorderLayout.CENTER); 243 } 244 245 void jButtonCancle_actionPerformed(ActionEvent e) 246 { 247 hide(); 248 } 249 250 void jButtonGetSNapshot_actionPerformed(ActionEvent e) 251 { 252 try 253 { 254 String subName = jTextSubName.getText().trim(); 255 if (subName.equalsIgnoreCase("")) 256 { 257 throw new RepException("REP093", new Object[] 258 {null}); 259 } 260 String port = jTextRemoteRepPortNo.getText().trim(); 261 if (port.equalsIgnoreCase("")) 262 { 263 throw new RepException("REP094", new Object[] 264 {null}); 265 } 266 int remoteRepPortNo = Integer.valueOf(port).intValue(); 267 268 if (remoteRepPortNo < 0) 269 { 270 JOptionPane.showMessageDialog(this, 271 "Enter only positive number in Server Port No", 272 "Error Message", 273 JOptionPane.ERROR_MESSAGE); 274 return; 275 } 276 277 String remoteServerName = jTextRemoteServerName.getText().trim(); 278 if (remoteServerName.equalsIgnoreCase("")) 279 { 280 throw new RepException("REP095", new Object[] 281 {null}); 282 } 283 284 sub = repServer.getSubscription(subName); 285 if (sub == null) 286 { 287 throw new RepException("REP058", new Object[] 288 {subName}); 289 } 290 sub.setRemoteServerPortNo(remoteRepPortNo); 291 sub.setRemoteServerUrl(remoteServerName); 292 if (snapShotType.equalsIgnoreCase(snapShotAfterSubscribing)){ 293 sub.getSnapShot(); 294 } 295 if (snapShotType.equalsIgnoreCase(snapShotAfterUpdating)){ 296 sub.getSnapShotAfterUpdatingSubscriber(); 297 } 298 JOptionPane.showMessageDialog(this, "Snapshot Taken Successfully", 299 "Success", JOptionPane.INFORMATION_MESSAGE); 300 hide(); 301 } 302 catch (RepException ex) 303 { 304 JOptionPane.showMessageDialog(this, ex, "Error Message", 305 JOptionPane.ERROR_MESSAGE); 306 return; 307 } 308 catch (NumberFormatException ex2) 309 { 310 JOptionPane.showMessageDialog(this, 311 "Enter valid integer value in Server Port Number", 312 "Error Message", JOptionPane.ERROR_MESSAGE); 313 return; 314 } 315 catch (Exception ex1) 316 { 317 JOptionPane.showMessageDialog(this, ex1, "Error Message", 318 JOptionPane.ERROR_MESSAGE); 319 return; 320 } 321 } 322 323 public void keyTyped(KeyEvent keyEvent) 324 { 325 } 326 327 public void keyPressed(KeyEvent keyEvent) 328 { 329 } 330 331 public void keyReleased(KeyEvent keyEvent) 332 { 333 jButtonGetSNapshot.setEnabled(true); 334 if (jTextRemoteRepPortNo.getText().equals("") || 335 jTextRemoteServerName.getText().equals("") || 336 jTextSubName.getText().equals("") || jTextSubName.getText().equals("")) 337 { 338 jButtonGetSNapshot.setEnabled(false); 339 } 340 else 341 { 342 if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) 343 { 344 jButtonGetSNapshot_actionPerformed(null); 345 } 346 } 347 348 } 349 350 public void focusGained(FocusEvent fe) 351 { 352 if ( ( (JTextField) fe.getSource()).equals(jTextRemoteServerName)) 353 { 354 help.setText("Enter Remote Server Name in this Box"); 355 } 356 if ( ( (JTextField) fe.getSource()).equals(jTextSubName)) 357 { 358 help.setText("Enter Subscription Name in this Box"); 359 } 360 if ( ( (JTextField) fe.getSource()).equals(jTextRemoteRepPortNo)) 361 { 362 help.setText("Enter Port Number in this Box"); 363 } 364 365 if (! (jTextRemoteRepPortNo.getText().equals("") || 366 jTextRemoteServerName.getText().equals("") || 367 jTextSubName.getText().equals("") || 368 jTextSubName.getText().equals(""))) 369 { 370 jButtonGetSNapshot.setEnabled(true); 371 372 } 373 } 374 375 public void focusLost(FocusEvent focusEvent) 376 { 377 jButtonGetSNapshot.setEnabled(true); 378 if (jTextRemoteRepPortNo.getText().equals("") || 379 jTextRemoteServerName.getText().equals("") || 380 jTextSubName.getText().equals("") || jTextSubName.getText().equals("")) 381 { 382 jButtonGetSNapshot.setEnabled(false); 383 384 } 385 } 386 } 387 388 class GetSnapshot_jButtonCancle_actionAdapter implements java.awt.event.ActionListener 389 { 390 GetSnapshot adaptee; 391 392 GetSnapshot_jButtonCancle_actionAdapter(GetSnapshot adaptee) 393 { 394 this.adaptee = adaptee; 395 } 396 397 public void actionPerformed(ActionEvent e) 398 { 399 adaptee.jButtonCancle_actionPerformed(e); 400 } 401 } 402 403 class GetSnapshot_jButtonGetSNapshot_actionAdapter implements java.awt.event.ActionListener 404 { 405 GetSnapshot adaptee; 406 407 GetSnapshot_jButtonGetSNapshot_actionAdapter(GetSnapshot adaptee) 408 { 409 this.adaptee = adaptee; 410 } 411 412 public void actionPerformed(ActionEvent e) 413 { 414 adaptee.jButtonGetSNapshot_actionPerformed(e); 415 } 416 }

