JavaDoc


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    import javax.swing.tree.*;
027    
028    import org.dbreplicator.replication.*;
029    
030    /**
031     * <p>Title: </p>
032     * <p>Description: </p>
033     * <p>Copyright: Copyright (c) 2003</p>
034     * <p>Company: </p>
035     * @author not attributable
036     * @version 1.0
037     */
038    
039    public class CreateSubscription extends JDialog implements FocusListener, KeyListener
040    {
041        JPanel panel1 = new JPanel();
042        JLabel jLabel1 = new JLabel();
043        JLabel jLabel2 = new JLabel();
044        JTextField jTextSubName = new JTextField();
045        _ReplicationServer repServer;
046        JLabel jLabel4 = new JLabel();
047        JTextField jTextPubName = new JTextField();
048        JButton jButtonPublish = new JButton();
049        JButton jButton2 = new JButton();
050        JTextField jTextRemotePORT = new JTextField();
051        JTextField jTextRemoteSystemName = new JTextField();
052        JLabel jLabel3 = new JLabel();
053        JLabel jLabel5 = new JLabel();
054        String subName;
055        DefaultMutableTreeNode node, subRootNode;
056        DefaultTreeModel defaultTreeModel;
057        JLabel jLabel7 = new JLabel();
058        JEditorPane help = new JEditorPane();
059        Border border1;
060    
061        public CreateSubscription(Frame frame, String title, boolean modal)
062        {
063            super(frame, title, modal);
064            try
065            {
066                jbInit();
067                pack();
068            }
069            catch (Exception ex)
070            {
071                JOptionPane.showMessageDialog(this, ex, "Error Message",
072                                              JOptionPane.ERROR_MESSAGE);
073                return;
074            }
075        }
076    
077        public CreateSubscription(_ReplicationServer repServer0,
078                                  DefaultMutableTreeNode subRootNode,
079                                  DefaultTreeModel defaultTreeModel0)
080        {
081            this(StartRepServer.getMainFrame(), "Create Subscription", true);
082            repServer = repServer0;
083            this.subRootNode = subRootNode;
084            defaultTreeModel = defaultTreeModel0;
085        }
086    
087        private void jbInit() throws Exception
088        {
089            border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white,
090                                       new Color(148, 145, 140));
091            panel1.setLayout(null);
092            panel1.setDebugGraphicsOptions(0);
093            jLabel1.setFont(new java.awt.Font("Serif", 3, 25));
094            jLabel1.setForeground(SystemColor.infoText);
095            jLabel1.setBorder(null);
096            jLabel1.setText("Create Subscription");
097            jLabel1.setBounds(new Rectangle(89, 9, 223, 32));
098            jLabel2.setFont(new java.awt.Font("Dialog", 1, 13));
099            jLabel2.setHorizontalAlignment(SwingConstants.LEFT);
100            jLabel2.setText("Subscription Name");
101            jLabel2.setBounds(new Rectangle(14, 83, 164, 15));
102            jTextSubName.setFont(new java.awt.Font("Dialog", 0, 12));
103            jTextSubName.setNextFocusableComponent(jTextPubName);
104            jTextSubName.setFocusAccelerator('1');
105            jTextSubName.setSelectionEnd(4);
106            jTextSubName.setSelectionStart(0);
107            jTextSubName.setText("");
108            jTextSubName.setScrollOffset(1);
109            jTextSubName.setBounds(new Rectangle(181, 77, 195, 21));
110            jLabel4.setFont(new java.awt.Font("Dialog", 1, 13));
111            jLabel4.setRequestFocusEnabled(true);
112            jLabel4.setHorizontalAlignment(SwingConstants.LEFT);
113            jLabel4.setText("Publication Name");
114            jLabel4.setBounds(new Rectangle(14, 109, 164, 15));
115            jTextPubName.setFont(new java.awt.Font("Dialog", 0, 12));
116            jTextPubName.setSelectedTextColor(Color.white);
117            jTextPubName.setText("");
118            jTextPubName.setBounds(new Rectangle(181, 102, 195, 21));
119            jButtonPublish.setBounds(new Rectangle(173, 229, 99, 25));
120            jButtonPublish.setEnabled(false);
121            jButtonPublish.setFont(new java.awt.Font("Dialog", 1, 12));
122            jButtonPublish.setText("Subscribe");
123            jButtonPublish.addActionListener(new
124                                             CreateSubscription_jButtonPublish_actionAdapter(this));
125            jButton2.setBounds(new Rectangle(284, 229, 99, 25));
126            jButton2.setFont(new java.awt.Font("Dialog", 1, 12));
127            jButton2.setText("Cancel");
128            jButton2.addActionListener(new CreateSubscription_jButton2_actionAdapter(this));
129            jTextRemotePORT.setFont(new java.awt.Font("Dialog", 0, 12));
130            jTextRemotePORT.setText("");
131            jTextRemotePORT.setBounds(new Rectangle(181, 155, 195, 21));
132            jTextRemotePORT.setDocument(new NumericDocument());
133            jTextRemoteSystemName.setFont(new java.awt.Font("Dialog", 0, 12));
134            jTextRemoteSystemName.setText("");
135            jTextRemoteSystemName.setBounds(new Rectangle(181, 129, 195, 21));
136            jLabel3.setFont(new java.awt.Font("Dialog", 1, 13));
137            jLabel3.setMinimumSize(new Dimension(270, 16));
138            jLabel3.setPreferredSize(new Dimension(105, 16));
139            jLabel3.setHorizontalAlignment(SwingConstants.LEFT);
140            jLabel3.setText("Publication Port Number");
141            jLabel3.setBounds(new Rectangle(14, 160, 164, 15));
142            jLabel5.setFont(new java.awt.Font("Dialog", 1, 13));
143            jLabel5.setHorizontalAlignment(SwingConstants.LEFT);
144            jLabel5.setText("Publication System Name");
145            jLabel5.setBounds(new Rectangle(14, 134, 164, 15));
146            jLabel7.setBorder(border1);
147            jLabel7.setBounds(new Rectangle(7, 66, 380, 124));
148            help.setBackground(UIManager.getColor("Button.background"));
149            help.setEnabled(false);
150            help.setFont(new java.awt.Font("Dialog", 2, 12));
151            help.setDoubleBuffered(false);
152            help.setPreferredSize(new Dimension(373, 21));
153            help.setRequestFocusEnabled(false);
154            help.setCaretColor(Color.black);
155            help.setDisabledTextColor(Color.black);
156            help.setEditable(false);
157            help.setMargin(new Insets(3, 3, 3, 3));
158            help.setSelectedTextColor(Color.white);
159            help.setText("Creates subscription corresponding to a publication ");
160            help.setBounds(new Rectangle(5, 190, 382, 29));
161            getContentPane().add(panel1, BorderLayout.CENTER);
162            this.setForeground(Color.darkGray);
163    
164            jTextPubName.addFocusListener(this);
165            jTextRemotePORT.addFocusListener(this);
166            jTextSubName.addFocusListener(this);
167            jTextRemoteSystemName.addFocusListener(this);
168            jTextRemoteSystemName.addKeyListener(this);
169            jTextPubName.addKeyListener(this);
170            jTextRemotePORT.addKeyListener(this);
171            jTextSubName.addKeyListener(this);
172    
173            jTextPubName.grabFocus();
174            panel1.add(help, null);
175            panel1.add(jLabel4, null);
176            panel1.add(jLabel5, null);
177            panel1.add(jLabel3, null);
178            panel1.add(jLabel2, null);
179            panel1.add(jLabel7, null);
180            panel1.add(jButton2, null);
181            panel1.add(jButtonPublish, null);
182            panel1.add(jTextRemotePORT, null);
183            panel1.add(jTextRemoteSystemName, null);
184            panel1.add(jTextSubName, null);
185            panel1.add(jTextPubName, null);
186            panel1.add(jLabel1, null);
187        }
188    
189        void jButton2_actionPerformed(ActionEvent e)
190        {
191            hide();
192        }
193    
194        void createSubscription()
195        {
196            try
197            {
198                String subName = jTextSubName.getText().trim();
199                if (subName == null || subName.equalsIgnoreCase("") ||
200                    subName.startsWith("\"") || subName.startsWith("\\") ||
201                    subName.startsWith("/") || subName.startsWith(":") ||
202                    subName.startsWith("<") || subName.startsWith(">") ||
203                    subName.startsWith("|") || subName.startsWith("?"))
204                {
205                    throw new RepException("REP093", new Object[]
206                                           {null});
207                }
208                String pubName = jTextPubName.getText().trim();
209                if (pubName == null || subName.equalsIgnoreCase("") ||
210                    pubName.startsWith("\"") || pubName.startsWith("\\") ||
211                    pubName.startsWith("/") || pubName.startsWith(":") ||
212                    pubName.startsWith("<") || pubName.startsWith(">") ||
213                    pubName.startsWith("|") || pubName.startsWith("?"))
214                {
215                    throw new RepException("REP092", new Object[]
216                                           {null});
217                }
218                _Subscription sub = repServer.createSubscription(subName, pubName);
219                String port = jTextRemotePORT.getText().trim();
220                if (port == null || port.equalsIgnoreCase(""))
221                {
222                    throw new RepException("REP094", new Object[]
223                                           {null});
224                }
225                int remotePORTno = Integer.valueOf(port).intValue();
226                if (remotePORTno <= 0)
227                {
228                    throw new NumberFormatException();
229                }
230                String remoteSystemName = jTextRemoteSystemName.getText();
231                sub.setRemoteServerPortNo(remotePORTno);
232                sub.setRemoteServerUrl(remoteSystemName);
233                sub.subscribe();
234                JOptionPane.showMessageDialog(this, "Subscription Created Successfully",
235                                              "Success", JOptionPane.INFORMATION_MESSAGE);
236                setSubName(subName);
237                createSubNode(pubName);
238                hide();
239            }
240            catch (RepException ex1)
241            {
242                JOptionPane.showMessageDialog(this, ex1, "Error Message",
243                                              JOptionPane.ERROR_MESSAGE);
244                return;
245            }
246            catch (NumberFormatException ex2)
247            {
248                JOptionPane.showMessageDialog(this,
249                                              "Enter only positive integer value in Server Port No",
250                                              "Error Message", JOptionPane.ERROR_MESSAGE);
251                return;
252            }
253            catch (Exception ex)
254            {
255                JOptionPane.showMessageDialog(this, ex, "Error Message",
256                                              JOptionPane.ERROR_MESSAGE);
257                return;
258            }
259        }
260    
261        void jButtonPublish_actionPerformed(ActionEvent e)
262        {
263            createSubscription();
264        }
265    
266        public void setSubName(String subName0)
267        {
268            subName = subName0;
269        }
270    
271        public String getSubName()
272        {
273            return subName;
274        }
275    
276        public void createSubNode(String pubName)
277        {
278            node = new DefaultMutableTreeNode(subName);
279            DefaultMutableTreeNode pubNode = new DefaultMutableTreeNode("PUBLICATION");
280            DefaultMutableTreeNode leafPubNode = new DefaultMutableTreeNode(pubName);
281            leafPubNode.setAllowsChildren(false);
282            pubNode.add(leafPubNode);
283            node.add(pubNode);
284    //    adding node to subRootNode
285            defaultTreeModel.insertNodeInto(node, subRootNode,
286                                            subRootNode.getChildCount());
287        }
288    
289        public void focusGained(FocusEvent fe)
290        {
291            if ( ( (JTextField) fe.getSource()).equals(jTextRemoteSystemName))
292            {
293                help.setText("Enter Remote System Name in this Box");
294            }
295            if ( ( (JTextField) fe.getSource()).equals(jTextPubName))
296            {
297                help.setText("Enter Publication Name in this Box");
298            }
299            if ( ( (JTextField) fe.getSource()).equals(jTextSubName))
300            {
301                help.setText("Enter Subscription Name in this Box");
302            }
303            if ( ( (JTextField) fe.getSource()).equals(jTextRemotePORT))
304            {
305                help.setText("Enter Port Number in this Box");
306            }
307        }
308    
309        public void focusLost(FocusEvent focusEvent)
310        {
311            jButtonPublish.setEnabled(true);
312            if (jTextPubName.getText().equals("") ||
313                jTextRemotePORT.getText().equals("") ||
314                jTextSubName.getText().equals("") ||
315                jTextRemoteSystemName.getText().equals(""))
316            {
317                jButtonPublish.setEnabled(false);
318            }
319        }
320    
321        public void keyTyped(KeyEvent keyEvent)
322        {
323        }
324    
325        public void keyPressed(KeyEvent keyEvent)
326        {
327        }
328    
329        public void keyReleased(KeyEvent keyEvent)
330        {
331            jButtonPublish.setEnabled(true);
332            if (jTextPubName.getText().equals("") ||
333                jTextRemotePORT.getText().equals("") ||
334                jTextSubName.getText().equals("") ||
335                jTextRemoteSystemName.getText().equals(""))
336            {
337                jButtonPublish.setEnabled(false);
338            }
339            else
340            {
341                if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER)
342                {
343                    jButtonPublish_actionPerformed(null);
344                }
345            }
346        }
347    }
348    
349    class CreateSubscription_jButton2_actionAdapter implements java.awt.event.ActionListener
350    {
351        CreateSubscription adaptee;
352    
353        CreateSubscription_jButton2_actionAdapter(CreateSubscription adaptee)
354        {
355            this.adaptee = adaptee;
356        }
357    
358        public void actionPerformed(ActionEvent e)
359        {
360            adaptee.jButton2_actionPerformed(e);
361        }
362    }
363    
364    class CreateSubscription_jButtonPublish_actionAdapter implements java.awt.event.ActionListener
365    {
366        CreateSubscription adaptee;
367    
368        CreateSubscription_jButtonPublish_actionAdapter(CreateSubscription adaptee)
369        {
370            this.adaptee = adaptee;
371        }
372    
373        public void actionPerformed(ActionEvent e)
374        {
375            adaptee.jButtonPublish_actionPerformed(e);
376        }
377    }





























































Powered by Drupal - Theme by Danger4k