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

