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.util.*; 023 024 import java.awt.*; 025 import java.awt.event.*; 026 import javax.swing.*; 027 import javax.swing.border.*; 028 import javax.swing.tree.*; 029 030 import org.dbreplicator.replication.*; 031 032 /** 033 * <p>Title: </p> 034 * <p>Description: </p> 035 * <p>Copyright: Copyright (c) 2003</p> 036 * <p>Company: </p> 037 * @author not attributable 038 * @version 1.0 039 */ 040 041 public class UnSubscribe extends JDialog implements FocusListener, KeyListener 042 { 043 JPanel panel1 = new JPanel(); 044 JLabel jLabel1 = new JLabel(); 045 JTextField jTextSubName = new JTextField(); 046 JButton jButtonUnsubscribe = new JButton(); 047 JButton jButtonCancle = new JButton(); 048 _ReplicationServer repServer; 049 JLabel jLabel2 = new JLabel(); 050 DefaultMutableTreeNode subRootNode; 051 DefaultTreeModel defaultTreeModel; 052 JLabel jLabel3 = new JLabel(); 053 JLabel jLabel4 = new JLabel(); 054 JTextField jTextRemoteServerName = new JTextField(); 055 JLabel jLabel6 = new JLabel(); 056 JEditorPane help = new JEditorPane(); 057 String subName; 058 boolean able = true; 059 JTextField jTextRemoteRepPortNo = new JTextField(); 060 Border border1; 061 062 public UnSubscribe(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 UnSubscribe(_ReplicationServer repServer0, 079 // DefaultMutableTreeNode subRootNode0, 080 // DefaultTreeModel defaultTreeModel0) { 081 // this(null, "Unsubscribe", true); 082 // repServer = repServer0; 083 // subRootNode = subRootNode0; 084 // defaultTreeModel = defaultTreeModel0; 085 // } 086 // 087 // public UnSubscribe(_ReplicationServer repServer0, 088 // DefaultMutableTreeNode subRootNode0, 089 // DefaultTreeModel defaultTreeModel0, String subName0) { 090 // this(null, "Unsubscribe", true); 091 // repServer = repServer0; 092 // subRootNode = subRootNode0; 093 // defaultTreeModel = defaultTreeModel0; 094 // subName = subName0; 095 // init(); 096 // } 097 098 public UnSubscribe(_ReplicationServer repServer0, 099 DefaultMutableTreeNode subRootNode0, 100 DefaultTreeModel defaultTreeModel0, boolean able0) 101 { 102 this(StartRepServer.getMainFrame(), "Unsubscribe", true); 103 repServer = repServer0; 104 subRootNode = subRootNode0; 105 defaultTreeModel = defaultTreeModel0; 106 able = able0; 107 } 108 109 public UnSubscribe(_ReplicationServer repServer0, 110 DefaultMutableTreeNode subRootNode0, 111 DefaultTreeModel defaultTreeModel0, String subName0, 112 boolean able0) 113 { 114 this(null, "Unsubscribe", true); 115 repServer = repServer0; 116 subRootNode = subRootNode0; 117 defaultTreeModel = defaultTreeModel0; 118 subName = subName0; 119 able = able0; 120 init(); 121 } 122 123 private void init() 124 { 125 try 126 { 127 _Subscription sub = repServer.getSubscription(subName); 128 jTextSubName.setText(subName); 129 jTextSubName.setEnabled(able); 130 jTextRemoteRepPortNo.setText("" + sub.getRemoteServerPortNo()); 131 jTextRemoteServerName.setText(sub.getRemoteServerUrl()); 132 if (!jTextRemoteRepPortNo.getText().trim().equalsIgnoreCase("") && 133 !jTextRemoteServerName.getText().equalsIgnoreCase("")) 134 { 135 jButtonUnsubscribe.setEnabled(true); 136 } 137 } 138 catch (RepException ex) 139 { 140 JOptionPane.showMessageDialog(this, ex, "Error Message", 141 JOptionPane.ERROR_MESSAGE); 142 return; 143 } 144 } 145 146 private void jbInit() throws Exception 147 { 148 border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, 149 new Color(148, 145, 140)); 150 panel1.setLayout(null); 151 jLabel1.setFont(new java.awt.Font("Dialog", 1, 13)); 152 jLabel1.setMaximumSize(new Dimension(136, 16)); 153 jLabel1.setMinimumSize(new Dimension(136, 16)); 154 jLabel1.setPreferredSize(new Dimension(136, 16)); 155 jLabel1.setHorizontalAlignment(SwingConstants.LEFT); 156 jLabel1.setHorizontalTextPosition(SwingConstants.LEFT); 157 jLabel1.setText("Subscription Name"); 158 jLabel1.setBounds(new Rectangle(19, 84, 174, 23)); 159 panel1.setAlignmentY( (float) 0.5); 160 panel1.setDebugGraphicsOptions(0); 161 jTextSubName.setFont(new java.awt.Font("Dialog", 0, 12)); 162 jTextSubName.setNextFocusableComponent(jTextRemoteServerName); 163 jTextSubName.setPreferredSize(new Dimension(6, 22)); 164 jTextSubName.setRequestFocusEnabled(true); 165 jTextSubName.setFocusAccelerator('1'); 166 jTextSubName.setText(""); 167 jTextSubName.setBounds(new Rectangle(188, 82, 158, 23)); 168 jButtonUnsubscribe.setBounds(new Rectangle(113, 216, 117, 25)); 169 jButtonUnsubscribe.setEnabled(false); 170 jButtonUnsubscribe.setFont(new java.awt.Font("Dialog", 1, 12)); 171 jButtonUnsubscribe.setText("UnSubscribe"); 172 jButtonUnsubscribe.addActionListener(new 173 UnSubscribe_jButtonUnsubscribe_actionAdapter(this)); 174 jButtonCancle.setBounds(new Rectangle(240, 216, 117, 25)); 175 jButtonCancle.setFont(new java.awt.Font("Dialog", 1, 12)); 176 jButtonCancle.setToolTipText(""); 177 jButtonCancle.setText("Cancel"); 178 jButtonCancle.addActionListener(new UnSubscribe_jButtonCancle_actionAdapter(this)); 179 jLabel2.setEnabled(true); 180 jLabel2.setFont(new java.awt.Font("Serif", 3, 25)); 181 jLabel2.setForeground(SystemColor.infoText); 182 jLabel2.setText("Drop Subscription"); 183 jLabel2.setBounds(new Rectangle(92, 5, 193, 35)); 184 jLabel3.setFont(new java.awt.Font("Dialog", 1, 13)); 185 jLabel3.setHorizontalAlignment(SwingConstants.LEFT); 186 jLabel3.setHorizontalTextPosition(SwingConstants.LEFT); 187 jLabel3.setText("Publication Port Number"); 188 jLabel3.setBounds(new Rectangle(19, 142, 174, 15)); 189 jLabel4.setFont(new java.awt.Font("Dialog", 1, 13)); 190 jLabel4.setMinimumSize(new Dimension(136, 16)); 191 jLabel4.setRequestFocusEnabled(true); 192 jLabel4.setHorizontalAlignment(SwingConstants.LEFT); 193 jLabel4.setHorizontalTextPosition(SwingConstants.LEFT); 194 jLabel4.setText("Publication Server Name"); 195 jLabel4.setBounds(new Rectangle(19, 115, 174, 15)); 196 jTextRemoteServerName.setFont(new java.awt.Font("Dialog", 0, 12)); 197 jTextRemoteServerName.setDoubleBuffered(false); 198 jTextRemoteServerName.setText(""); 199 jTextRemoteServerName.setBounds(new Rectangle(188, 110, 158, 23)); 200 jLabel6.setBorder(border1); 201 jLabel6.setText(""); 202 jLabel6.setBounds(new Rectangle(9, 66, 350, 105)); 203 help.setBackground(UIManager.getColor("Button.background")); 204 help.setEnabled(false); 205 help.setFont(new java.awt.Font("Dialog", 2, 12)); 206 help.setRequestFocusEnabled(false); 207 help.setToolTipText(""); 208 help.setDisabledTextColor(Color.black); 209 help.setEditable(false); 210 help.setText("Deletes specified subscription"); 211 help.setBounds(new Rectangle(12, 176, 341, 23)); 212 jTextRemoteRepPortNo.setMinimumSize(new Dimension(6, 21)); 213 jTextRemoteRepPortNo.setText(""); 214 jTextRemoteRepPortNo.setBounds(new Rectangle(188, 138, 158, 23)); 215 getContentPane().add(panel1); 216 217 jTextRemoteRepPortNo.setDocument(new NumericDocument()); 218 219 jTextRemoteServerName.addKeyListener(this); 220 jTextSubName.addKeyListener(this); 221 jTextRemoteRepPortNo.addKeyListener(this); 222 jTextRemoteRepPortNo.addFocusListener(this); 223 jTextRemoteServerName.addFocusListener(this); 224 jTextSubName.addFocusListener(this); 225 226 jTextSubName.grabFocus(); 227 panel1.add(help, null); 228 panel1.add(jTextSubName, null); 229 panel1.add(jLabel4, null); 230 panel1.add(jLabel3, null); 231 panel1.add(jLabel1, null); 232 panel1.add(jButtonCancle, null); 233 panel1.add(jButtonUnsubscribe, null); 234 panel1.add(jTextRemoteServerName, null); 235 panel1.add(jTextRemoteRepPortNo, null); 236 panel1.add(jLabel6, null); 237 panel1.add(jLabel2, null); 238 } 239 240 void jButtonCancle_actionPerformed(ActionEvent e) 241 { 242 hide(); 243 } 244 245 void jButtonUnsubscribe_actionPerformed(ActionEvent e) 246 { 247 try 248 { 249 String subName = jTextSubName.getText().trim(); 250 if (subName.equalsIgnoreCase("")) 251 { 252 throw new Exception("Subscription name is not specified."); 253 } 254 String port = jTextRemoteRepPortNo.getText().trim(); 255 if (port.equalsIgnoreCase("")) 256 { 257 throw new Exception("Port number is not specified."); 258 } 259 int remoteRepPortNo = Integer.valueOf(port).intValue(); 260 if (remoteRepPortNo < 0) 261 { 262 JOptionPane.showMessageDialog(this, 263 "Enter only positive number in Server Port No", 264 "Error Message", 265 JOptionPane.ERROR_MESSAGE); 266 return; 267 } 268 269 String remoteServerName = jTextRemoteServerName.getText().trim(); 270 if (remoteServerName.equalsIgnoreCase("")) 271 { 272 throw new Exception("Remote Replication Server Name can not be blank."); 273 } 274 _Subscription sub = repServer.getSubscription(subName); 275 if (sub == null) 276 { 277 throw new RepException("REP044", new Object[] 278 {subName}); 279 } 280 sub.setRemoteServerPortNo(remoteRepPortNo); 281 sub.setRemoteServerUrl(remoteServerName); 282 sub.unsubscribe(); 283 Enumeration iterator = subRootNode.children(); 284 while (iterator.hasMoreElements()) 285 { 286 DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) iterator. 287 nextElement(); 288 if ( ( (String) treeNode.getUserObject()).equalsIgnoreCase(subName)) 289 { 290 defaultTreeModel.removeNodeFromParent(treeNode); 291 } 292 } 293 JOptionPane.showMessageDialog(this, "Unsubscribed Successfully", 294 "Success", JOptionPane.INFORMATION_MESSAGE); 295 hide(); 296 } 297 catch (RepException ex) 298 { 299 JOptionPane.showMessageDialog(this, ex, "Error Message", 300 JOptionPane.ERROR_MESSAGE); 301 return; 302 } 303 catch (NumberFormatException ex2) 304 { 305 // ex2.printStackTrace(); 306 JOptionPane.showMessageDialog(this, 307 "Enter valid integer value in Port Number", 308 "Error Message", 309 JOptionPane.ERROR_MESSAGE); 310 return; 311 } 312 catch (Exception ex1) 313 { 314 JOptionPane.showMessageDialog(this, ex1, "Error Message", 315 JOptionPane.ERROR_MESSAGE); 316 return; 317 } 318 } 319 320 public void keyTyped(KeyEvent keyEvent) 321 { 322 } 323 324 public void keyPressed(KeyEvent keyEvent) 325 { 326 } 327 328 public void keyReleased(KeyEvent keyEvent) 329 { 330 jButtonUnsubscribe.setEnabled(true); 331 if (jTextRemoteServerName.getText().trim().equalsIgnoreCase("") || 332 jTextRemoteRepPortNo.getText().trim().equalsIgnoreCase("") || 333 jTextSubName.getText().trim().equalsIgnoreCase("")) 334 { 335 jButtonUnsubscribe.setEnabled(false); 336 } 337 else 338 { 339 if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) 340 { 341 jButtonUnsubscribe_actionPerformed(null); 342 } 343 } 344 345 } 346 347 public void focusGained(FocusEvent fe) 348 { 349 if ( ( (JTextField) fe.getSource()).equals(jTextRemoteRepPortNo)) 350 { 351 help.setText("Enter Port number in this box"); 352 } 353 else if ( ( (JTextField) fe.getSource()).equals(jTextSubName)) 354 { 355 help.setText("Enter Subscription Name in this box"); 356 } 357 else if ( ( (JTextField) fe.getSource()).equals(jTextRemoteServerName)) 358 { 359 help.setText("Enter Server Name in this box"); 360 361 } 362 if ( (jTextRemoteServerName.getText().trim().equalsIgnoreCase("") || 363 jTextRemoteRepPortNo.getText().trim().equalsIgnoreCase("") || 364 jTextSubName.getText().trim().equalsIgnoreCase(""))) 365 { 366 jButtonUnsubscribe.setEnabled(false); 367 368 } 369 } 370 371 public void focusLost(FocusEvent fe) 372 { 373 jButtonUnsubscribe.setEnabled(true); 374 if ( (jTextRemoteServerName.getText().trim().equalsIgnoreCase("") || 375 jTextRemoteRepPortNo.getText().trim().equalsIgnoreCase("") || 376 jTextSubName.getText().trim().equalsIgnoreCase(""))) 377 { 378 jButtonUnsubscribe.setEnabled(false); 379 } 380 } 381 } 382 383 class UnSubscribe_jButtonCancle_actionAdapter implements java.awt.event.ActionListener 384 { 385 UnSubscribe adaptee; 386 387 UnSubscribe_jButtonCancle_actionAdapter(UnSubscribe adaptee) 388 { 389 this.adaptee = adaptee; 390 } 391 392 public void actionPerformed(ActionEvent e) 393 { 394 adaptee.jButtonCancle_actionPerformed(e); 395 } 396 } 397 398 class UnSubscribe_jButtonUnsubscribe_actionAdapter implements java.awt.event.ActionListener 399 { 400 UnSubscribe adaptee; 401 402 UnSubscribe_jButtonUnsubscribe_actionAdapter(UnSubscribe adaptee) 403 { 404 this.adaptee = adaptee; 405 } 406 407 public void actionPerformed(ActionEvent e) 408 { 409 adaptee.jButtonUnsubscribe_actionPerformed(e); 410 } 411 }

