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 UnPublish extends JDialog implements KeyListener, FocusListener 042 { 043 JPanel panel1 = new JPanel(); 044 JLabel jLabel1 = new JLabel(); 045 JTextField jTextPubName = new JTextField(); 046 JButton jButtonUnpublish = new JButton(); 047 JButton jButtonCancle = new JButton(); 048 static _ReplicationServer repServer; 049 JLabel jLabel2 = new JLabel(); 050 static DefaultMutableTreeNode pubRootNode; 051 static DefaultTreeModel defaultTreeModel; 052 JLabel jLabel4 = new JLabel(); 053 JEditorPane help = new JEditorPane(); 054 String pubName; 055 Border border1; 056 057 public UnPublish(Frame frame, String title, boolean modal) 058 { 059 super(frame, title, modal); 060 061 try 062 { 063 jbInit(); 064 pack(); 065 } 066 catch (Exception ex) 067 { 068 JOptionPane.showMessageDialog(this, ex, "Error Message", 069 JOptionPane.ERROR_MESSAGE); 070 return; 071 } 072 } 073 074 public UnPublish(_ReplicationServer repServer0, 075 DefaultMutableTreeNode pubRootNode0, 076 DefaultTreeModel defaultTreeModel0) 077 { 078 this(StartRepServer.getMainFrame(), "UnPublish", true); 079 repServer = repServer0; 080 pubRootNode = pubRootNode0; 081 defaultTreeModel = defaultTreeModel0; 082 } 083 084 public UnPublish(_ReplicationServer repServer0, 085 DefaultMutableTreeNode pubRootNode0, 086 DefaultTreeModel defaultTreeModel0, String pubName0) 087 { 088 this(null, "UnPublish", true); 089 repServer = repServer0; 090 pubRootNode = pubRootNode0; 091 defaultTreeModel = defaultTreeModel0; 092 pubName = pubName0; 093 init(); 094 } 095 096 private void init() 097 { 098 try 099 { 100 _Publication sub = repServer.getPublication(pubName); 101 jTextPubName.setText(pubName); 102 jButtonUnpublish.enable(true); 103 } 104 catch (Exception ex) 105 { 106 JOptionPane.showMessageDialog(this, ex, "Error Message", 107 JOptionPane.ERROR_MESSAGE); 108 // ex.printStackTrace(); 109 return; 110 } 111 } 112 113 public static void dropPublication(String nameOfPublication, Component com, 114 _ReplicationServer server, 115 DefaultMutableTreeNode pubRootNode0, 116 DefaultTreeModel defaultTreeModel0) 117 { 118 _Publication pub = null; 119 try 120 { 121 pub = server.getPublication(nameOfPublication); 122 if (pub == null) 123 { 124 throw new RepException("REP043", new Object[] 125 {nameOfPublication}); 126 } 127 pub.unpublish(); 128 129 pubRootNode = pubRootNode0; 130 defaultTreeModel = defaultTreeModel0; 131 132 Enumeration iterator = pubRootNode.children(); 133 while (iterator.hasMoreElements()) 134 { 135 DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) iterator. 136 nextElement(); 137 if ( ( (String) treeNode.getUserObject()).equalsIgnoreCase( 138 nameOfPublication)) 139 { 140 defaultTreeModel.removeNodeFromParent(treeNode); 141 } 142 } 143 JOptionPane.showMessageDialog(com, "Unpublished Successfully", "Success", 144 JOptionPane.INFORMATION_MESSAGE); 145 } 146 catch (Exception ex) 147 { 148 JOptionPane.showMessageDialog(com, ex, "Error Message", 149 JOptionPane.ERROR_MESSAGE); 150 return; 151 } 152 153 } 154 155 private void jbInit() throws Exception 156 { 157 border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, 158 new Color(148, 145, 140)); 159 panel1.setLayout(null); 160 jLabel1.setFont(new java.awt.Font("Dialog", 1, 13)); 161 jLabel1.setText("Publication Name"); 162 jLabel1.setBounds(new Rectangle(22, 64, 119, 23)); 163 panel1.setAlignmentY( (float) 0.5); 164 panel1.setDebugGraphicsOptions(0); 165 jTextPubName.setFont(new java.awt.Font("Dialog", 0, 12)); 166 jTextPubName.setText(""); 167 jTextPubName.setBounds(new Rectangle(140, 64, 153, 21)); 168 jButtonUnpublish.setBounds(new Rectangle(90, 141, 98, 25)); 169 jButtonUnpublish.setEnabled(false); 170 jButtonUnpublish.setFont(new java.awt.Font("Dialog", 1, 12)); 171 jButtonUnpublish.setText("UnPublish"); 172 jButtonUnpublish.addActionListener(new 173 UnPublish_jButtonUnpublish_actionAdapter(this)); 174 jButtonCancle.setBounds(new Rectangle(202, 141, 98, 25)); 175 jButtonCancle.setFont(new java.awt.Font("Dialog", 1, 12)); 176 jButtonCancle.setText("Cancel"); 177 jButtonCancle.addActionListener(new UnPublish_jButtonCancle_actionAdapter(this)); 178 jLabel2.setEnabled(true); 179 jLabel2.setFont(new java.awt.Font("Serif", 3, 25)); 180 jLabel2.setForeground(SystemColor.infoText); 181 jLabel2.setText("Drop Publication"); 182 jLabel2.setBounds(new Rectangle(68, 2, 202, 36)); 183 jLabel4.setBorder(border1); 184 jLabel4.setOpaque(false); 185 jLabel4.setText(""); 186 jLabel4.setBounds(new Rectangle(13, 48, 289, 55)); 187 help.setBackground(UIManager.getColor("Button.background")); 188 help.setEnabled(false); 189 help.setFont(new java.awt.Font("Dialog", 2, 12)); 190 help.setRequestFocusEnabled(false); 191 help.setDisabledTextColor(Color.black); 192 help.setEditable(false); 193 help.setText("Deletes the specified publication"); 194 help.setBounds(new Rectangle(20, 105, 252, 24)); 195 getContentPane().add(panel1); 196 197 jTextPubName.addFocusListener(this); 198 jTextPubName.addKeyListener(this); 199 200 panel1.add(jLabel4, null); 201 panel1.add(jLabel1, null); 202 panel1.add(help, null); 203 panel1.add(jButtonCancle, null); 204 panel1.add(jButtonUnpublish, null); 205 panel1.add(jLabel2, null); 206 panel1.add(jTextPubName, null); 207 } 208 209 void jButtonCancle_actionPerformed(ActionEvent e) 210 { 211 hide(); 212 } 213 214 void jButtonUnpublish_actionPerformed(ActionEvent e) 215 { 216 String pubName = jTextPubName.getText().trim(); 217 _Publication pub = null; 218 try 219 { 220 if (pubName.equalsIgnoreCase("")) 221 { 222 throw new Exception("Publication Name not specified."); 223 } 224 pub = repServer.getPublication(pubName); 225 if (pub == null) 226 { 227 throw new RepException("REP043", new Object[] 228 {pubName}); 229 } 230 pub.unpublish(); 231 232 Enumeration iterator = pubRootNode.children(); 233 while (iterator.hasMoreElements()) 234 { 235 DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) iterator. 236 nextElement(); 237 if ( ( (String) treeNode.getUserObject()).equalsIgnoreCase(pubName)) 238 { 239 defaultTreeModel.removeNodeFromParent(treeNode); 240 241 } 242 } 243 244 JOptionPane.showMessageDialog(this, "Unpublished Successfully", "Success", 245 JOptionPane.OK_OPTION); 246 hide(); 247 } 248 catch (Exception ex) 249 { 250 JOptionPane.showMessageDialog(this, ex, "Error Message", 251 JOptionPane.ERROR_MESSAGE); 252 return; 253 } 254 } 255 256 public void keyTyped(KeyEvent keyEvent) 257 { 258 } 259 260 public void keyPressed(KeyEvent keyEvent) 261 { 262 } 263 264 public void keyReleased(KeyEvent keyEvent) 265 { 266 jButtonUnpublish.setEnabled(true); 267 if (jTextPubName.getText().trim().equals("")) 268 { 269 jButtonUnpublish.setEnabled(false); 270 } 271 else 272 { 273 if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) 274 { 275 jButtonUnpublish_actionPerformed(null); 276 } 277 } 278 279 } 280 281 public void focusGained(FocusEvent fe) 282 { 283 if ( ( (JTextField) fe.getSource()).equals(jTextPubName)) 284 { 285 help.setText("Enter Publication Name "); 286 } 287 if (!jTextPubName.getText().trim().equals("")) 288 { 289 jButtonUnpublish.setEnabled(true); 290 } 291 } 292 293 public void focusLost(FocusEvent fe) 294 { 295 jButtonUnpublish.setEnabled(true); 296 if (jTextPubName.getText().trim().equals("")) 297 { 298 jButtonUnpublish.setEnabled(false); 299 } 300 } 301 } 302 303 class UnPublish_jButtonCancle_actionAdapter implements java.awt.event.ActionListener 304 { 305 UnPublish adaptee; 306 307 UnPublish_jButtonCancle_actionAdapter(UnPublish adaptee) 308 { 309 this.adaptee = adaptee; 310 } 311 312 public void actionPerformed(ActionEvent e) 313 { 314 adaptee.jButtonCancle_actionPerformed(e); 315 } 316 } 317 318 class UnPublish_jButtonUnpublish_actionAdapter implements java.awt.event.ActionListener 319 { 320 UnPublish adaptee; 321 322 UnPublish_jButtonUnpublish_actionAdapter(UnPublish adaptee) 323 { 324 this.adaptee = adaptee; 325 } 326 327 public void actionPerformed(ActionEvent e) 328 { 329 adaptee.jButtonUnpublish_actionPerformed(e); 330 } 331 }

