KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > administrator > Administrator


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.genimen.djeneric.tools.administrator;
32
33 import java.awt.AWTEvent JavaDoc;
34 import java.awt.BorderLayout JavaDoc;
35 import java.awt.Dimension JavaDoc;
36 import java.awt.Image JavaDoc;
37 import java.awt.Toolkit JavaDoc;
38 import java.awt.event.ActionEvent JavaDoc;
39 import java.awt.event.MouseEvent JavaDoc;
40 import java.awt.event.WindowEvent JavaDoc;
41 import java.net.URL JavaDoc;
42 import java.sql.Connection JavaDoc;
43 import java.sql.DriverManager JavaDoc;
44 import java.sql.SQLException JavaDoc;
45
46 import javax.swing.BorderFactory JavaDoc;
47 import javax.swing.DefaultComboBoxModel JavaDoc;
48 import javax.swing.ImageIcon JavaDoc;
49 import javax.swing.JButton JavaDoc;
50 import javax.swing.JLabel JavaDoc;
51 import javax.swing.JList JavaDoc;
52 import javax.swing.JMenu JavaDoc;
53 import javax.swing.JMenuBar JavaDoc;
54 import javax.swing.JMenuItem JavaDoc;
55 import javax.swing.JOptionPane JavaDoc;
56 import javax.swing.JPanel JavaDoc;
57 import javax.swing.JScrollPane JavaDoc;
58 import javax.swing.border.Border JavaDoc;
59
60 import com.genimen.djeneric.language.Messages;
61 import com.genimen.djeneric.repository.DjPersistenceManager;
62 import com.genimen.djeneric.repository.DjPersistenceManagerFactory;
63 import com.genimen.djeneric.repository.DjRepositoryDescriptor;
64 import com.genimen.djeneric.repository.exceptions.DjenericException;
65 import com.genimen.djeneric.repository.exceptions.LogonException;
66 import com.genimen.djeneric.tools.administrator.helpers.AdminPanel;
67 import com.genimen.djeneric.tools.administrator.helpers.DefineRepositoryDialog;
68 import com.genimen.djeneric.tools.administrator.helpers.DescriptorWizard;
69 import com.genimen.djeneric.tools.common.AboutDialog;
70 import com.genimen.djeneric.tools.common.DjenericTool;
71 import com.genimen.djeneric.tools.common.LoginDialog;
72 import com.genimen.djeneric.ui.DjTabbedPane;
73 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
74 import com.genimen.djeneric.util.DjEnvironment;
75 import com.genimen.djeneric.util.DjLogPrintStream;
76 import com.genimen.djeneric.util.DjLogger;
77 import com.genimen.djeneric.util.DjVersion;
78
79 public class Administrator extends DjenericTool
80 {
81   private static final long serialVersionUID = 1L;
82
83   private final String JavaDoc PROPERTIES_FILE_NAME = DjEnvironment.getAbsoluteFileName("administrator.properties");
84   private final static String JavaDoc LOG_FILE_NAME = DjEnvironment.getAbsoluteFileName("administrator.log");
85
86   public final static String JavaDoc OK_MSG = Messages.getString("global.Ok");
87   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
88   JPanel JavaDoc _pnlStatus = new JPanel JavaDoc();
89   JLabel JavaDoc _lblStatus = new JLabel JavaDoc();
90   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
91   Border JavaDoc border1;
92   DjTabbedPane _tabMain = new DjTabbedPane();
93   String JavaDoc _configFileName;
94   DefaultComboBoxModel JavaDoc _repositoryModel;
95   DjPersistenceManagerFactory _fact;
96   JMenuBar JavaDoc jMenuBar1 = new JMenuBar JavaDoc();
97   JMenu JavaDoc jMenu1 = new JMenu JavaDoc();
98   JMenuItem JavaDoc jMenuItem1 = new JMenuItem JavaDoc();
99   JMenu JavaDoc jMenu2 = new JMenu JavaDoc();
100   JMenuItem JavaDoc jMenuItem2 = new JMenuItem JavaDoc();
101   JMenu JavaDoc jMenu3 = new JMenu JavaDoc();
102   JMenuItem JavaDoc jMenuItem3 = new JMenuItem JavaDoc();
103   JMenu JavaDoc jMenu4 = new JMenu JavaDoc();
104   JMenuItem JavaDoc _mnuNextTab = new JMenuItem JavaDoc();
105   JMenuItem JavaDoc _mnuPrevTab = new JMenuItem JavaDoc();
106   JMenuItem JavaDoc _mnuCloseTab = new JMenuItem JavaDoc();
107   JPanel JavaDoc _pnlRepositories = new JPanel JavaDoc();
108   JButton JavaDoc _butCopyRepos = new JButton JavaDoc();
109   JButton JavaDoc _butAdmin = new JButton JavaDoc();
110   JScrollPane JavaDoc _scrRepositories = new JScrollPane JavaDoc();
111   JButton JavaDoc _butDeleteRepos = new JButton JavaDoc();
112   JButton JavaDoc _butEditRepos = new JButton JavaDoc();
113   BorderLayout JavaDoc borderLayout4 = new BorderLayout JavaDoc();
114   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
115   JList JavaDoc _lstRepositories = new JList JavaDoc();
116   JButton JavaDoc _butCreateRepos = new JButton JavaDoc();
117   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
118   JLabel JavaDoc jLabel1 = new JLabel JavaDoc();
119
120   public Administrator(String JavaDoc configFileName)
121   {
122     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
123     try
124     {
125       setStatusLabel(_lblStatus);
126       _configFileName = configFileName;
127
128       jbInit();
129       this.setIconImage(getImage("admin.gif"));
130       _fact = new DjPersistenceManagerFactory(this, configFileName);
131
132       _repositoryModel = new DefaultComboBoxModel JavaDoc(_fact.getRepositoryDescriptors());
133       _lstRepositories.setModel(_repositoryModel);
134       if (_repositoryModel.getSize() > 0)
135       {
136         _lstRepositories.setSelectedIndex(0);
137       }
138
139       _butEditRepos.setIcon(getImageIcon("edit.gif"));
140       _butCreateRepos.setIcon(getImageIcon("new.gif"));
141       _butDeleteRepos.setIcon(getImageIcon("delete.gif"));
142       _butAdmin.setIcon(getImageIcon("admin.gif"));
143       _butCopyRepos.setIcon(getImageIcon("copy.gif"));
144
145       loadProps(PROPERTIES_FILE_NAME);
146
147       int width = Integer.parseInt(getProperty("window.width", "400"));
148       int height = Integer.parseInt(getProperty("window.height", "400"));
149       setSize(new Dimension JavaDoc(width, height));
150
151     }
152     catch (Exception JavaDoc e)
153     {
154       handleException(e);
155       System.exit(-1);
156     }
157   }
158
159   public String JavaDoc getConfigFileName()
160   {
161     return _configFileName;
162   }
163
164   /**
165    * Component initialization
166    *
167    * @exception Exception
168    * Description of the Exception
169    */

170   private void jbInit() throws Exception JavaDoc
171   {
172     setTitle("Djeneric Administrator v" + DjVersion.getVersion());
173     border1 = BorderFactory.createEmptyBorder(0, 5, 0, 0);
174     this.getContentPane().setLayout(borderLayout1);
175     _lblStatus.setText(Messages.getString("global.Ok"));
176     _pnlStatus.setLayout(borderLayout2);
177     _pnlStatus.setBorder(border1);
178     jMenu1.setMnemonic('F');
179     jMenu1.setText(Messages.getString("global.File"));
180     jMenuItem1.setMnemonic('X');
181     jMenuItem1.setText(Messages.getString("global.Exit"));
182     jMenuItem1.addActionListener(new java.awt.event.ActionListener JavaDoc()
183     {
184       public void actionPerformed(ActionEvent JavaDoc e)
185       {
186         mnuExit(e);
187       }
188     });
189     jMenu2.setMnemonic('T');
190     jMenu2.setText(Messages.getString("global.Tools"));
191     jMenuItem2.setActionCommand(Messages.getString("Administrator.KillModelLock1"));
192     jMenuItem2.setMnemonic('K');
193     jMenuItem2.setText(Messages.getString("Administrator.KillModelLock"));
194     jMenuItem2.addActionListener(new java.awt.event.ActionListener JavaDoc()
195     {
196       public void actionPerformed(ActionEvent JavaDoc e)
197       {
198         mnuKillModelLock(e);
199       }
200     });
201     jMenu3.setMnemonic('H');
202     jMenu3.setText(Messages.getString("global.Help"));
203     jMenuItem3.setText(Messages.getString("global.About"));
204     jMenuItem3.addActionListener(new java.awt.event.ActionListener JavaDoc()
205     {
206       public void actionPerformed(ActionEvent JavaDoc e)
207       {
208         mnuAbout(e);
209       }
210     });
211     jMenu4.setMnemonic('A');
212     jMenu4.setText(Messages.getString("global.Tabs"));
213     _mnuNextTab.setText(Messages.getString("global.NextTab"));
214     _mnuNextTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(117, java.awt.event.KeyEvent.CTRL_MASK, false));
215     _mnuNextTab.addActionListener(new java.awt.event.ActionListener JavaDoc()
216     {
217       public void actionPerformed(ActionEvent JavaDoc e)
218       {
219         mnuNextTab(e);
220       }
221     });
222     _mnuPrevTab.setText(Messages.getString("global.PreviousTab"));
223     _mnuPrevTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(117, java.awt.event.KeyEvent.CTRL_MASK
224                                                                        | java.awt.event.KeyEvent.SHIFT_MASK, false));
225     _mnuPrevTab.addActionListener(new java.awt.event.ActionListener JavaDoc()
226     {
227       public void actionPerformed(ActionEvent JavaDoc e)
228       {
229         mnuPrevTab(e);
230       }
231     });
232     _mnuCloseTab.setText(Messages.getString("global.CloseTab"));
233     _mnuCloseTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, java.awt.event.KeyEvent.CTRL_MASK, false));
234     _mnuCloseTab.addActionListener(new java.awt.event.ActionListener JavaDoc()
235     {
236       public void actionPerformed(ActionEvent JavaDoc e)
237       {
238         mnuCloseTab(e);
239       }
240     });
241     _pnlRepositories.setLayout(borderLayout4);
242     _butCopyRepos.addActionListener(new java.awt.event.ActionListener JavaDoc()
243     {
244       public void actionPerformed(ActionEvent JavaDoc e)
245       {
246         _butCopyRepos_actionPerformed(e);
247       }
248     });
249     _butCopyRepos.setToolTipText(Messages.getString("Administrator.DuplicateRepositoryDescriptor"));
250     _butCopyRepos.setPreferredSize(new Dimension JavaDoc(24, 24));
251     _butAdmin.addActionListener(new java.awt.event.ActionListener JavaDoc()
252     {
253       public void actionPerformed(ActionEvent JavaDoc e)
254       {
255         _butAdmin_actionPerformed(e);
256       }
257     });
258     _butAdmin.setPreferredSize(new Dimension JavaDoc(24, 24));
259     _butAdmin.setToolTipText(Messages.getString("Administrator.AdministerRepository"));
260     _butDeleteRepos.setPreferredSize(new Dimension JavaDoc(24, 24));
261     _butDeleteRepos.setToolTipText(Messages.getString("global.DelDescriptorTitle"));
262     _butDeleteRepos.addActionListener(new java.awt.event.ActionListener JavaDoc()
263     {
264       public void actionPerformed(ActionEvent JavaDoc e)
265       {
266         _butDeleteRepos_actionPerformed(e);
267       }
268     });
269     _butEditRepos.setPreferredSize(new Dimension JavaDoc(24, 24));
270     _butEditRepos.setToolTipText(Messages.getString("Administrator.EditRepositoryDescriptor"));
271     _butEditRepos.addActionListener(new java.awt.event.ActionListener JavaDoc()
272     {
273       public void actionPerformed(ActionEvent JavaDoc e)
274       {
275         _butEditRepos_actionPerformed(e);
276       }
277     });
278     _lstRepositories.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
279     {
280       public void mouseClicked(MouseEvent JavaDoc e)
281       {
282         _lstRepositories_mouseClicked(e);
283       }
284     });
285     _butCreateRepos.setPreferredSize(new Dimension JavaDoc(24, 24));
286     _butCreateRepos.setToolTipText(Messages.getString("Administrator.CreateRepositoryDescriptor"));
287     _butCreateRepos.addActionListener(new java.awt.event.ActionListener JavaDoc()
288     {
289       public void actionPerformed(ActionEvent JavaDoc e)
290       {
291         _butCreateRepos_actionPerformed(e);
292       }
293     });
294     jPanel4.setLayout(verticalFlowLayout2);
295     _scrRepositories.setPreferredSize(new Dimension JavaDoc(200, 132));
296     _pnlRepositories.setPreferredSize(new Dimension JavaDoc(250, 150));
297     jLabel1.setPreferredSize(new Dimension JavaDoc(5, 5));
298     _pnlStatus.add(_lblStatus, BorderLayout.CENTER);
299     this.getContentPane().add(_pnlRepositories, BorderLayout.WEST);
300     _pnlRepositories.add(_scrRepositories, BorderLayout.CENTER);
301     _pnlRepositories.add(jPanel4, BorderLayout.WEST);
302     _scrRepositories.getViewport().add(_lstRepositories, null);
303     jPanel4.add(_butAdmin, null);
304     jPanel4.add(jLabel1, null);
305     jPanel4.add(_butEditRepos, null);
306     jPanel4.add(_butCopyRepos, null);
307     jPanel4.add(_butCreateRepos, null);
308     jPanel4.add(_butDeleteRepos, null);
309     this.getContentPane().add(_tabMain, BorderLayout.CENTER);
310     this.getContentPane().add(_pnlStatus, BorderLayout.SOUTH);
311     jMenuBar1.add(jMenu1);
312     jMenuBar1.add(jMenu2);
313     jMenuBar1.add(jMenu4);
314     jMenuBar1.add(jMenu3);
315     jMenu1.add(jMenuItem1);
316     jMenu2.add(jMenuItem2);
317     jMenu3.add(jMenuItem3);
318     jMenu4.add(_mnuNextTab);
319     jMenu4.add(_mnuPrevTab);
320     jMenu4.add(_mnuCloseTab);
321     setJMenuBar(jMenuBar1);
322   }
323
324   protected void processWindowEvent(WindowEvent JavaDoc e)
325   {
326     try
327     {
328       if (e.getID() == WindowEvent.WINDOW_CLOSING)
329       {
330         exitProgram();
331       }
332       else super.processWindowEvent(e);
333
334     }
335     catch (Exception JavaDoc x)
336     {
337       setStatusMessage(x);
338     }
339   }
340
341   protected void updateProperties()
342   {
343     setProperty("window.width", "" + getWidth());
344     setProperty("window.height", "" + getHeight());
345   }
346
347   public static ImageIcon JavaDoc getImageIcon(String JavaDoc fileName)
348   {
349     URL JavaDoc url = Administrator.class.getResource("images/" + fileName);
350     if (url != null) return new ImageIcon JavaDoc(url);
351     else return new ImageIcon JavaDoc("");
352     // Default to empty image
353
}
354
355   public static Image JavaDoc getImage(String JavaDoc fileName)
356   {
357     URL JavaDoc url = Administrator.class.getResource("images/" + fileName);
358     if (url != null) return Toolkit.getDefaultToolkit().getImage(url);
359
360     else return Toolkit.getDefaultToolkit().getImage("");
361   }
362
363   void _butEditRepos_actionPerformed(ActionEvent JavaDoc e)
364   {
365     try
366     {
367       if (_lstRepositories.getSelectedIndex() != -1)
368       {
369         DjRepositoryDescriptor rd = (DjRepositoryDescriptor) _lstRepositories.getSelectedValue();
370         DefineRepositoryDialog dlg = new DefineRepositoryDialog(this, Messages
371             .getString("Administrator.EditRepositoryDescriptor"), rd);
372         if (!dlg.wasCancelled())
373         {
374           _fact.saveRepositoryDescriptors(_configFileName);
375           setStatusMessage(Messages.getString("Administrator.DefsWrittenTo", _configFileName));
376         }
377         updateRepositoryList(rd);
378       }
379     }
380     catch (Exception JavaDoc x)
381     {
382       setStatusMessage(x);
383     }
384
385   }
386
387   void updateRepositoryList(DjRepositoryDescriptor selectThis)
388   {
389     _repositoryModel = new DefaultComboBoxModel JavaDoc(_fact.getRepositoryDescriptors());
390     _lstRepositories.setModel(_repositoryModel);
391     for (int i = 0; i < _repositoryModel.getSize(); i++)
392     {
393       if (_repositoryModel.getElementAt(i).equals(selectThis))
394       {
395         _lstRepositories.setSelectedIndex(i);
396         break;
397       }
398     }
399   }
400
401   void _butCreateRepos_actionPerformed(ActionEvent JavaDoc e)
402   {
403     try
404     {
405       DescriptorWizard dw = new DescriptorWizard(this);
406       if (!dw.wasCancelled())
407       {
408         DjRepositoryDescriptor rd = new DjRepositoryDescriptor(dw.getName(),
409             DjPersistenceManagerFactory.TYPE_POLYMORPH, dw.getDriver(), dw.getUrl());
410         rd.setSharedUser(dw.getUser());
411         rd.setSharedPassword(dw.getPassword());
412         rd.setSharedConnection(true);
413         DefineRepositoryDialog dlg = new DefineRepositoryDialog(this, Messages
414             .getString("Administrator.CreateRepositoryDescriptor"), rd);
415         if (!dlg.wasCancelled())
416         {
417           _fact.addRepositoryDescriptor(rd);
418           _fact.saveRepositoryDescriptors(_configFileName);
419
420           updateRepositoryList(rd);
421         }
422       }
423     }
424     catch (Exception JavaDoc x)
425     {
426       setStatusMessage(x);
427     }
428
429   }
430
431   void _butDeleteRepos_actionPerformed(ActionEvent JavaDoc e)
432   {
433     try
434     {
435       if (_lstRepositories.getSelectedIndex() != -1)
436       {
437         DjRepositoryDescriptor rd = (DjRepositoryDescriptor) _lstRepositories.getSelectedValue();
438         int result = JOptionPane.showOptionDialog(this,
439                                                   Messages.getString("Administrator.DelDescriptor", rd.getName()),
440                                                   Messages.getString("global.DelDescriptorTitle"),
441                                                   JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
442                                                   new String JavaDoc[]{Messages.getString("global.Cancel"),
443                                                       Messages.getString("global.Delete")}, null);
444         if (result != 1)
445         {
446           return;
447         }
448
449         _fact.removeRepositoryDescriptor(rd);
450         _fact.saveRepositoryDescriptors(_configFileName);
451
452         int idx = _lstRepositories.getSelectedIndex();
453         if (idx > 0) idx--;
454         _repositoryModel = new DefaultComboBoxModel JavaDoc(_fact.getRepositoryDescriptors());
455         _lstRepositories.setModel(_repositoryModel);
456         if (_repositoryModel.getSize() > 0) _lstRepositories.setSelectedIndex(idx);
457       }
458     }
459     catch (Exception JavaDoc x)
460     {
461       setStatusMessage(x);
462     }
463
464   }
465
466   void _lstRepositories_mouseClicked(MouseEvent JavaDoc e)
467   {
468     if (e.getClickCount() > 1) _butAdmin_actionPerformed(null);
469   }
470
471   void _butAdmin_actionPerformed(ActionEvent JavaDoc e)
472   {
473     try
474     {
475       if (_lstRepositories.getSelectedIndex() != -1)
476       {
477         DjRepositoryDescriptor rd = (DjRepositoryDescriptor) _lstRepositories.getSelectedValue();
478         setStatusMessageNow(Messages.getString("Administrator.Connecting", rd.toString()), true);
479         AdminPanel ap = new AdminPanel(this, rd);
480         _tabMain.addTab(rd.getName(), getImageIcon("schema.gif"), ap);
481         _tabMain.setSelectedComponent(ap);
482         setStatusMessage(OK_MSG);
483       }
484     }
485     catch (Exception JavaDoc de)
486     {
487       handleException(de);
488     }
489   }
490
491   void mnuExit(ActionEvent JavaDoc e)
492   {
493     try
494     {
495       exitProgram();
496     }
497     catch (Exception JavaDoc x)
498     {
499       setStatusMessage(x);
500     }
501   }
502
503   void mnuKillModelLock(ActionEvent JavaDoc e)
504   {
505     try
506     {
507       DjPersistenceManager mgr = _fact.createInstance();
508       String JavaDoc tag = mgr.getCurrentLockTag();
509       if (tag == null)
510       {
511         setStatusMessage(Messages.getString("Administrator.NoLockActive"));
512         return;
513       }
514
515       int result = JOptionPane.showOptionDialog(this, Messages.getString("Administrator.AboutToKillLock", tag),
516                                                 Messages.getString("Administrator.AboutToKillLockTitle"),
517                                                 JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
518                                                 new String JavaDoc[]{Messages.getString("global.Cancel"),
519                                                     Messages.getString("Administrator.KillLock")}, null);
520       if (result == 1) mgr.forceUnlockModel();
521       setStatusMessage(Messages.getString("Administrator.LockKilled"));
522       mgr.close();
523     }
524     catch (Exception JavaDoc x)
525     {
526       setStatusMessage(x);
527     }
528   }
529
530   void _butCopyRepos_actionPerformed(ActionEvent JavaDoc e)
531   {
532     try
533     {
534       if (_lstRepositories.getSelectedIndex() != -1)
535       {
536         DjRepositoryDescriptor rd = (DjRepositoryDescriptor) _lstRepositories.getSelectedValue();
537         DjRepositoryDescriptor nrd = (DjRepositoryDescriptor) rd.clone();
538         nrd.setName(Messages.getString("global.CopyOf", nrd.getName()));
539
540         _fact.addRepositoryDescriptor(nrd);
541         _fact.saveRepositoryDescriptors(_configFileName);
542
543         updateRepositoryList(nrd);
544       }
545     }
546     catch (Exception JavaDoc x)
547     {
548       setStatusMessage(x);
549     }
550   }
551
552   void mnuAbout(ActionEvent JavaDoc e)
553   {
554     new AboutDialog(this);
555   }
556
557   void mnuNextTab(ActionEvent JavaDoc e)
558   {
559     int idx = _tabMain.getSelectedIndex();
560     if (idx < _tabMain.getComponentCount() - 1) idx++;
561     else idx = 0;
562     _tabMain.setSelectedIndex(idx);
563   }
564
565   void mnuCloseTab(ActionEvent JavaDoc e)
566   {
567     if (_tabMain.getSelectedComponent() instanceof AdminPanel)
568     {
569       AdminPanel editor = (AdminPanel) _tabMain.getSelectedComponent();
570       if (editor != null)
571       {
572         editor.close();
573       }
574     }
575
576   }
577
578   public void removeTab(AdminPanel panel)
579   {
580     _tabMain.remove(panel);
581   }
582
583   void mnuPrevTab(ActionEvent JavaDoc e)
584   {
585     int idx = _tabMain.getSelectedIndex();
586     if (idx > 0) idx--;
587     else idx = _tabMain.getComponentCount() - 1;
588     _tabMain.setSelectedIndex(idx);
589   }
590
591   void _lstRepositories_mousePressed(MouseEvent JavaDoc e)
592   {
593
594   }
595
596   void _lstRepositories_mouseReleased(MouseEvent JavaDoc e)
597   {
598
599   }
600
601   void _lstRepositories_mouseEntered(MouseEvent JavaDoc e)
602   {
603
604   }
605
606   void _lstRepositories_mouseExited(MouseEvent JavaDoc e)
607   {
608
609   }
610
611   public Connection JavaDoc getConnection(DjRepositoryDescriptor repositoryDescriptor) throws LogonException,
612       DjenericException, ClassNotFoundException JavaDoc, SQLException JavaDoc
613   {
614     String JavaDoc username;
615     String JavaDoc password;
616
617     if (repositoryDescriptor.isSharedConnection())
618     {
619       username = repositoryDescriptor.getSharedUser();
620       password = repositoryDescriptor.getSharedPassword();
621     }
622     else
623     {
624       LoginDialog lid = new LoginDialog(this, repositoryDescriptor);
625       if (lid.isCancelled()) throw new DjenericException(Messages.getString("Administrator.CreationAborted"));
626       username = lid.getUserId();
627       password = lid.getPassword();
628     }
629
630     Class.forName(repositoryDescriptor.getDriver());
631     Connection JavaDoc conn = DriverManager.getConnection(repositoryDescriptor.getUrl(), username, password);
632
633     return conn;
634   }
635
636   public static void main(String JavaDoc[] args)
637   {
638     try
639     {
640       DjenericTool.setLookAndFeel();
641
642       if (args.length < 1)
643       {
644         System.out.println("Usage: java " + Administrator.class.getName() + " <repositories.xml>");
645         return;
646       }
647       String JavaDoc banner = Administrator.class.getName() + " version " + DjVersion.getVersion();
648       DjLogPrintStream.logAll(banner, LOG_FILE_NAME);
649
650       System.out.println(Messages.getString("global.Reading", args[0]));
651       new Administrator(args[0]).startApp();
652     }
653     catch (Exception JavaDoc e)
654     {
655       DjLogger.log(e);
656     }
657   }
658
659 }
Popular Tags