KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > mos > forms > JMOSPreferencesDlg


1 /*
2     =========================================================================
3     Package forms - Implements the user interface MOS module
4
5     This module is developed and maintained by PlanetaMessenger.org.
6     Specs, New and updated versions can be found in
7     http://www.planetamessenger.org
8     If you want contact the Team please send a email to Project Manager
9     Leidson Campos Alves Ferreira at leidson@planetamessenger.org
10
11     Copyright (C) since 2001 by PlanetaMessenger.org
12
13     This program is free software; you can redistribute it and/or modify
14     it under the terms of the GNU General Public License as published by
15     the Free Software Foundation; either version 2 of the License, or
16     (at your option) any later version.
17
18     This program is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21     GNU General Public License for more details.
22
23     You should have received a copy of the GNU General Public License
24     along with this program; if not, write to the Free Software
25     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27     =========================================================================
28 */

29 /**
30  *
31  * $Id: JMOSPreferencesDlg.java,v 1.44 2007/02/13 04:46:28 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.44 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.forms;
40
41 import javax.swing.*;
42 import javax.swing.tree.*;
43 import javax.swing.event.*;
44 import java.awt.Dimension JavaDoc;
45 import java.awt.event.*;
46 import java.util.*;
47 import java.sql.*;
48 import com.jgoodies.forms.builder.*;
49 import com.jgoodies.forms.layout.*;
50 import com.jgoodies.forms.debug.*;
51 import org.planetamessenger.plugin.*;
52 import org.planetamessenger.mos.engine.*;
53 import org.planetamessenger.mos.forms.preferences.*;
54
55
56 public class JMOSPreferencesDlg extends JDialog implements TreeSelectionListener {
57
58   private final int ITEM_EMPTY = 0;
59   private final int ITEM_ROOT = -1000;
60   private final int ITEM_PLUGINS = -1001;
61   private final int SUB_ITEM_AVAILABLE_PLUGINS = -1002;
62   private final int ITEM_PLUGIN_MANAGEMENT = -1003;
63   private final int SUB_ITEM_INSTALLED_PLUGINS = -1004;
64   private final int SUB_ITEM_PROXY_SETTINGS = -1005;
65   private final int ITEM_PROFILE_SETTINGS = -1006;
66   private final int SUB_ITEM_LANGUAGE_SETTINGS = -1007;
67   private final int SUB_ITEM_LAF_SETTINGS = -1008;
68   private final int SUB_ITEM_ADD_EXISTING_USER = -1009;
69   private final int SUB_ITEM_ADD_NEW_USER = -1010;
70   private final int SUB_ITEM_CHANGE_PASSWD = -1011;
71   private final int SUB_ITEM_UNREGISTER_USER = -1012;
72   private final int SUB_ITEM_REMOVE_PLUGIN = -1013;
73   private final int SUB_ITEM_PRIVACY_CONTROL = -1014;
74   
75   private JTree optionsTree = null;
76   private JScrollPane optionsScrollPane = null;
77   private JSplitPane splitPane = null;
78   private JButton okButton = null;
79   private JButton cancelButton = null;
80   private JButton applyButton = null;
81   private DefaultMutableTreeNode rootNode = null;
82   private DefaultMutableTreeNode installedPluginsNode = null;
83   private JAvailablePluginsPanel availablePluginsPanel = null;
84   private JPrivacyControlPanel privacyControlPanel = null;
85   private JProxySettingsPanel proxySettingsPanel = null;
86   private JRegisterUserPanel registerUserPanel = null;
87   private JLanguagesPanel languagesPanel = null;
88   private JYesNoPanel unregisterUserPanel = null;
89   private JYesNoPanel removePluginPanel = null;
90   private WindowAdapter windowAdapter = null;
91   private boolean bEnableApply = false;
92   private JUserInfo userInfo = null;
93   private JPlugin selectedPlugin = null;
94   private JMOSMessageDialog messageDlg = null;
95   private JUserRegistrationListener userRegistrationObject = null;
96   
97   
98   /**
99    * Constructor. Initializes all class data.
100    * @param parent The parent window;
101    * @param bModal The modal state for dialog;
102    */

103   public JMOSPreferencesDlg( java.awt.Frame JavaDoc parent, boolean bModal ) {
104
105     super( parent, bModal );
106     initComponents();
107   }
108   
109   /**
110    * Add a new node to this options Tree component.
111    * @param parentNode The parent node for added node;
112    * @param item The item theat will be added to tree;
113    */

114   public DefaultMutableTreeNode addNode( DefaultMutableTreeNode parentNode, JDataField item ) {
115
116     DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( item );
117     
118     parentNode.add( newNode );
119
120     return newNode;
121   }
122
123   /**
124    * Enable/Disable the apply button.
125    * @param bEnabled The new button status;
126    */

127   public void EnableApply( boolean bEnabled ) {
128     
129     applyButton.setEnabled( bEnabled );
130   }
131   
132   /**
133    * Update all dialog labels depending on selected language
134    */

135   public void updateLanguage() {
136     
137     String JavaDoc strItem = JSharedObjects.getLanguageManager().getStringEx( "OPTIONS" );
138     JDataField item = new JDataField( strItem, strItem, new Integer JavaDoc( ITEM_ROOT ) );
139     
140     rootNode = new DefaultMutableTreeNode( item );
141     
142     DefaultTreeModel treeModel = new DefaultTreeModel( rootNode );
143     
144     optionsTree.removeAll();
145     optionsTree.setModel( treeModel );
146     applyButton.setText( JSharedObjects.getLanguageManager().getStringEx( "APPLY" ) );
147     okButton.setText( JSharedObjects.getLanguageManager().getStringEx( "OK" ) );
148     cancelButton.setText( JSharedObjects.getLanguageManager().getStringEx( "CANCEL" ) );
149     setTitle( JSharedObjects.getLanguageManager().getStringEx( "MY_MESSENGER" ) );
150     fillOptionsTree();
151     
152     // Update languages for all pages
153
JSharedObjects.getPluginPreferencesManager().fireOnLanguageChanged( "" );
154   }
155
156   /**
157    * Called when look-and-fell is changed by user.
158    * Update all setup pages, renew renderer for
159    * Tree components (important).
160    */

161   public void updateLAF() {
162
163     DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
164     
165     optionsTree.setCellRenderer( renderer );
166     renderer.setLeafIcon( null );
167     renderer.setOpenIcon( null );
168     renderer.setClosedIcon( null );
169
170     javax.swing.SwingUtilities.updateComponentTreeUI( this );
171     JSharedObjects.getPluginPreferencesManager().fireOnLookAndFeelChanged();
172   }
173
174   /**
175    * Override the parent setVisible method to update the
176    * options selected item.
177    */

178   public void setVisible( boolean bVisible ) {
179     
180     if( bVisible ) {
181       DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) optionsTree.getLastSelectedPathComponent();
182     
183       if( node != null ) {
184         JDataField item = ( JDataField ) node.getUserObject();
185         JSharedObjects.getPluginPreferencesManager().fireOnShow( ( ( Integer JavaDoc ) item.getObject() ).intValue(), item );
186       }
187     }
188
189     super.setVisible( bVisible );
190   }
191   
192   /**
193    * Set the Enabled status of options pane.
194    * @param bEnabled The new status;
195    */

196   public void EnableComponents( boolean bEnabled ) {
197
198     optionsTree.setEnabled( bEnabled );
199     
200     okButton.setEnabled( bEnabled );
201     cancelButton.setEnabled( bEnabled );
202     
203     if( !bEnabled ) {
204       bEnableApply = applyButton.isEnabled();
205       applyButton.setEnabled( false );
206       removeWindowListener( windowAdapter );
207     }
208     else {
209       applyButton.setEnabled( bEnableApply );
210       addWindowListener( windowAdapter );
211     }
212   }
213   
214   /**
215    * Set the parent item of current selection.
216    */

217   public void setParentOfCurrentSelection() {
218
219     optionsTree.setSelectionPath( optionsTree.getSelectionPath().getParentPath() );
220   }
221
222   /**
223    * Initializes all components of this
224    * window.
225    */

226   private void initComponents() {
227
228     Box btnsPanel = Box.createHorizontalBox();
229     FormLayout layout = new FormLayout( "fill:100dlu:grow",
230                                                            "fill:75dlu:grow, fill:3dlu, fill:pref" );
231     PanelBuilder builder = new PanelBuilder( layout );
232     //DefaultFormBuilder builder = new DefaultFormBuilder( layout, new FormDebugPanel() );
233
CellConstraints cellConst = new CellConstraints();
234     DefaultTreeCellRenderer renderer = null;
235
236
237     setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
238     windowAdapter = new java.awt.event.WindowAdapter JavaDoc() {
239                           public void windowClosing( java.awt.event.WindowEvent JavaDoc evt ) {
240                             closeDialog( evt );
241                           }
242                         };
243
244     addWindowListener( windowAdapter );
245     builder.setDefaultDialogBorder();
246     
247     // Components initialization
248
okButton = new JButton();
249     cancelButton = new JButton();
250     applyButton = new JButton();
251     optionsTree = new JTree();
252     optionsScrollPane = new JScrollPane( optionsTree );
253     splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, optionsScrollPane, JSharedObjects.getPluginPreferencesManager().getPreferencesScrollPane() );
254     availablePluginsPanel = new JAvailablePluginsPanel( this );
255     registerUserPanel = new JRegisterUserPanel( this );
256     unregisterUserPanel = new JYesNoPanel( "USER_UNREGISTRATION_QUESTION" );
257     removePluginPanel = new JYesNoPanel( "REMOVE_PLUGIN_QUESTION" );
258     privacyControlPanel = new JPrivacyControlPanel();
259     proxySettingsPanel = new JProxySettingsPanel();
260     languagesPanel = new JLanguagesPanel();
261     renderer = ( DefaultTreeCellRenderer ) optionsTree.getCellRenderer();
262
263     renderer.setLeafIcon( null );
264     renderer.setOpenIcon( null );
265     renderer.setClosedIcon( null );
266
267     optionsTree.putClientProperty( "JTree.lineStyle", "Angled" );
268     optionsTree.addTreeSelectionListener( this );
269     optionsTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
270     optionsScrollPane.setPreferredSize( new Dimension JavaDoc( optionsScrollPane.getPreferredSize().width + 150, optionsScrollPane.getPreferredSize().height ) );
271     builder.add( splitPane, cellConst.xy( 1, 1 ) );
272     
273     // Apply Button initialization
274
applyButton.setFont( JSystemFonts.FONT );
275     applyButton.setIcon( JSharedObjects.getResources().getIcon( JResources.APPLY_BUTTON_ICON ) );
276     applyButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
277     applyButton.setMinimumSize( applyButton.getPreferredSize() );
278     applyButton.setEnabled( false );
279     
280     // Ok Button initialization
281
okButton.setFont( JSystemFonts.FONT );
282     okButton.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) );
283     okButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
284     okButton.setMinimumSize( okButton.getPreferredSize() );
285
286     // Cancel Button initialization
287
cancelButton.setFont( JSystemFonts.FONT );
288     cancelButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) );
289     cancelButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
290     cancelButton.setMinimumSize( cancelButton.getPreferredSize() );
291     
292     // Ok button action event
293
applyButton.addActionListener( new ActionListener() {
294                                          
295                                       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
296                                         applyButtonActionPerformed( evt );
297                                       }
298                                     }
299                                  );
300     
301     // Ok button action event
302
okButton.addActionListener( new ActionListener() {
303
304                                       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
305                                         okButtonActionPerformed( evt );
306                                       }
307                                     }
308                                  );
309                                  
310     // Cancel button action event
311
cancelButton.addActionListener( new ActionListener() {
312
313                                           public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
314                                             cancelButtonActionPerformed( evt );
315                                           }
316                                         }
317                                   );
318
319     // Unregister user action event handler
320
unregisterUserPanel.addEventListener( new ActionListener() {
321                                                 
322                                                 public void actionPerformed( ActionEvent evt ) {
323                                                   unregisterUserPanelActionPerformed( evt );
324                                                 }
325                                           }
326                                         );
327
328     // Remove plugin action event handler
329
removePluginPanel.addEventListener( new ActionListener() {
330
331                                               public void actionPerformed( ActionEvent evt ) {
332                                                 removePluginPanelActionPerformed( evt );
333                                               }
334                                         }
335                                       );
336
337     // Unregister user event listener
338
userRegistrationObject = new JUserRegistrationAdapter() {
339       
340                                public void onUnregisterUserSucessfull() {
341
342                                  TreePath path = optionsTree.getSelectionPath();
343
344                                  selectedPlugin.removeRegistrationEngineListener( this );
345                                  JSharedObjects.getProfileManager().userDel( selectedPlugin.getPluginProperties().getPluginId(), userInfo );
346                                  JOptionPane.showMessageDialog( messageDlg, JSharedObjects.getLanguageManager().getStringEx( "SUCCESSFULL_UNREGISTRATION_USER_WARNING" ), JSharedObjects.getLanguageManager().getStringEx( "INFORMATION" ), JOptionPane.INFORMATION_MESSAGE );
347                                  messageDlg.setEnabled( false );
348                                  messageDlg.setVisible( false );
349                                  optionsTree.setSelectionPath( path.getParentPath().getParentPath() );
350                                  fillInstalledPluginsOptionsTree();
351                                }
352                              };
353
354     btnsPanel.add( javax.swing.Box.createHorizontalGlue() );
355     btnsPanel.add( cancelButton );
356     btnsPanel.add( javax.swing.Box.createHorizontalStrut( 2 ) );
357     btnsPanel.add( okButton );
358     btnsPanel.add( javax.swing.Box.createHorizontalStrut( 20 ) );
359     btnsPanel.add( applyButton );
360     builder.add( btnsPanel, cellConst.xy( 1, 3 ) );
361
362     updateLanguage();
363     getContentPane().add( builder.getPanel() );
364         
365     // Sets the initial dialog position and miscelaneous options
366
splitPane.setOneTouchExpandable( true );
367     splitPane.setDividerLocation( JSharedObjects.getConfiguration().getPreferencesSplitPosition() );
368     setSize( JSharedObjects.getConfiguration().getPreferencesWindowSize() );
369     setLocation( JSharedObjects.getConfiguration().getPreferencesWindowLocation() );
370     setResizable( true );
371   }
372   
373   /**
374    * Fill the options tree component with all options.
375    */

376   private void fillOptionsTree() {
377     
378     String JavaDoc strItem = JSharedObjects.getLanguageManager().getStringEx( "PLUGIN_MANAGEMENT" );
379     JDataField item = new JDataField( strItem, strItem, new Integer JavaDoc( ITEM_PLUGIN_MANAGEMENT ) );
380     DefaultMutableTreeNode node = addNode( rootNode, item );
381     
382     // Available plugins
383
strItem = "AVAILABLE_PLUGINS";
384     item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_AVAILABLE_PLUGINS ) );
385     addNode( node, item );
386
387     strItem = "INSTALLED_PLUGINS";
388     item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_INSTALLED_PLUGINS ) );
389     installedPluginsNode = addNode( node, item );
390
391     strItem = "PROFILE_SETTINGS";
392     item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( ITEM_PROFILE_SETTINGS ) );
393     node = addNode( rootNode, item );
394     
395     strItem = "PROXY_SETTINGS";
396     item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_PROXY_SETTINGS ) );
397     addNode( node, item );
398     
399     strItem = "LANGUAGE_SETTINGS";
400     item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_LANGUAGE_SETTINGS ) );
401     addNode( node, item );
402     
403     strItem = "LAF_SETTINGS";
404     item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_LAF_SETTINGS ) );
405     addNode( node, item );
406
407     // Add all panels to preferences Manager
408
JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_AVAILABLE_PLUGINS, availablePluginsPanel );
409     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_PROXY_SETTINGS, proxySettingsPanel );
410     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_LANGUAGE_SETTINGS, languagesPanel );
411     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_ADD_EXISTING_USER, registerUserPanel );
412     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_ADD_NEW_USER, registerUserPanel );
413     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_CHANGE_PASSWD, registerUserPanel );
414     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_UNREGISTER_USER, unregisterUserPanel );
415     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_REMOVE_PLUGIN, removePluginPanel );
416     JSharedObjects.getPluginPreferencesManager().add( SUB_ITEM_PRIVACY_CONTROL, privacyControlPanel );
417
418     fillInstalledPluginsOptionsTree();
419     optionsTree.expandPath( optionsTree.getPathForRow( 0 ) );
420   }
421   
422   /**
423    * Implements the ok action button event.
424    * @param evt The button event object;
425    */

426   private void okButtonActionPerformed( ActionEvent evt ) {
427     
428     applyButtonActionPerformed( null );
429     closeDialog( null );
430   }
431   
432   /**
433    * Implements the apply action button event.
434    * Apply changes for all property pages;
435    * @param evt The button event object;
436    */

437   private void applyButtonActionPerformed( ActionEvent evt ) {
438
439     if( JSharedObjects.getPluginPreferencesManager().fireOnApply() )
440       applyButton.setEnabled( false );
441   }
442   
443   /**
444    * Implements the cancel action button event.
445    * @param evt The button event object;
446    */

447   private void cancelButtonActionPerformed( ActionEvent evt ) {
448
449     JSharedObjects.getPluginPreferencesManager().fireOnCancel();
450     closeDialog( null );
451   }
452   
453   /**
454    * Implements the unregister user panel event.
455    * @param evt The button pressed on JYesNoPanel;
456    */

457   private void unregisterUserPanelActionPerformed( ActionEvent evt ) {
458     
459     TreePath path = optionsTree.getSelectionPath();
460     DefaultMutableTreeNode parentNode = ( DefaultMutableTreeNode ) path.getParentPath().getLastPathComponent();
461
462
463     if( evt.getID() == JYesNoPanel.YES_BUTTON ) {
464
465       // Is a installed plugin ???
466
if( parentNode != null ) {
467
468         JDataField parentItem = ( JDataField ) parentNode.getUserObject();
469         int nPluginId = ( ( Integer JavaDoc ) parentItem.getObject() ).intValue();
470
471         if( nPluginId >= 0 ) {
472           selectedPlugin = JSharedObjects.getPluginEngine().get( nPluginId );
473           
474           if( selectedPlugin.isConnected() ) {
475             userInfo = JSharedObjects.getProfileManager().getUserInfo( nPluginId );
476             messageDlg = null;
477             messageDlg = new JMOSMessageDialog( this, JSharedObjects.getLanguageManager().getStringEx( "CONFIRM_UNREGISTRATION" ),
478                                                 JSharedObjects.getLanguageManager().getStringEx( "USER_UNREGISTRATION_QUESTION" ) + " " + userInfo.getUserId() + " " + JSharedObjects.getLanguageManager().getStringEx( "QUESTION_SYMBOL" ), true );
479
480             messageDlg.setVisible( true );
481
482             // The user selected unregister plugin user ??
483
if( messageDlg.getButtonResult() == JMOSMessageDialog.YES_BUTTON ) {
484               selectedPlugin.addRegistrationEngineListener( userRegistrationObject );
485               messageDlg.setEnabled( false );
486               selectedPlugin.fireOnUnregisterUser();
487             }
488           }
489           else
490             javax.swing.JOptionPane.showMessageDialog( this,
491                                                        JSharedObjects.getLanguageManager().getStringEx( "DISCONNECTED_PLUGIN_WARNING" ),
492                                                        JSharedObjects.getLanguageManager().getStringEx( "INFORMATION" ), javax.swing.JOptionPane.INFORMATION_MESSAGE );
493         }
494       }
495     }
496     else
497       optionsTree.setSelectionPath( path.getParentPath() );
498   }
499   
500   /**
501    * Implements the remove plugin panel event.
502    * @param evt The button pressed on JYesNoPanel;
503    */

504   private void removePluginPanelActionPerformed( ActionEvent evt ) {
505     
506     TreePath path = optionsTree.getSelectionPath();
507     DefaultMutableTreeNode parentNode = ( DefaultMutableTreeNode ) path.getParentPath().getLastPathComponent();
508
509
510     if( evt.getID() == JYesNoPanel.YES_BUTTON ) {
511
512       // Is a installed plugin ???
513
if( parentNode != null ) {
514
515         JDataField parentItem = ( JDataField ) parentNode.getUserObject();
516         int nPluginId = ( ( Integer JavaDoc ) parentItem.getObject() ).intValue();
517
518         if( nPluginId >= 0 ) {
519           selectedPlugin = JSharedObjects.getPluginEngine().get( nPluginId );
520           messageDlg = null;
521           messageDlg = new JMOSMessageDialog( this, JSharedObjects.getLanguageManager().getStringEx( "REMOVE_PLUGIN" ),
522                                                   JSharedObjects.getLanguageManager().getStringEx( "REMOVE_PLUGIN_QUESTION" ) + " " + selectedPlugin.toString() + " " + JSharedObjects.getLanguageManager().getStringEx( "QUESTION_SYMBOL" ), true );
523
524           messageDlg.setVisible( true );
525
526           // The user selected unregister plugin user ??
527
if( messageDlg.getButtonResult() == JMOSMessageDialog.YES_BUTTON ) {
528
529             userInfo = JSharedObjects.getProfileManager().getUserInfo( nPluginId );
530             JSharedObjects.getProfileManager().userDel( nPluginId, userInfo );
531             JSharedObjects.getProfileManager().removePlugin( nPluginId, JSharedObjects.getProfileManager().getProfileId() );
532             JSharedObjects.getPluginEngine().remove( selectedPlugin );
533
534             optionsTree.setSelectionPath( path.getParentPath().getParentPath() );
535             fillInstalledPluginsOptionsTree();
536           }
537         }
538       }
539     }
540     else
541       optionsTree.setSelectionPath( path.getParentPath() );
542   }
543
544   /**
545    * Implements the closeDialog event
546    * handler.
547    * @param evt The close window event object;
548    */

549   private void closeDialog( WindowEvent evt ) {
550
551     JSharedObjects.getConfiguration().setPreferencesSplitPosition( splitPane.getDividerLocation() );
552     JSharedObjects.getConfiguration().setPreferencesWindowProperties( this.getLocation(), this.getSize() );
553     JSharedObjects.getPluginPreferencesManager().clearScrollPane();
554     applyButton.setEnabled( false );
555     setVisible( false );
556   }
557   
558   /**
559    * Update a tree node and it's childs.
560    * @param node The node to reload;
561    */

562   private void reload( TreeNode node ) {
563
564     ( ( DefaultTreeModel )optionsTree.getModel() ).reload( node );
565   }
566   
567   /**
568    * Fill the installed plugins child tree;
569    */

570   public void fillInstalledPluginsOptionsTree() {
571
572     int nPluginId;
573     long nProfileId = JSharedObjects.getProfileManager().getProfileId();
574     boolean bNoAvail = true;
575     ResultSet rs = JSharedObjects.getProfileManager().getAllPlugins().getResultSet();
576     
577     
578     JSharedObjects.getPluginEngine().loadAllPlugins( nProfileId, false );
579
580     /*
581      * Search for all installed plugins
582      * for this profile and put it on the Tree
583      * list.
584      */

585     JPlugin plugins[] = JSharedObjects.getPluginEngine().toArray();
586
587
588     installedPluginsNode.removeAllChildren();
589
590     if( plugins != null ) {
591
592       for( int nCount = 0; nCount < plugins.length; nCount++ ) {
593
594         JPlugin plugin = plugins[nCount];
595
596
597         nPluginId = plugin.getPluginProperties().getPluginId();
598
599         if( JSharedObjects.getProfileManager().checkPluginInstall( nPluginId, nProfileId ) ) {
600           JPluginProperties properties = plugin.getPluginProperties();
601           JDataField item = new JDataField( properties.getName(), properties.getName(), new Integer JavaDoc( nPluginId ) );
602           DefaultMutableTreeNode node = addNode( installedPluginsNode, item );
603
604           // There a user registered for plugin ???
605
if( !JSharedObjects.getProfileManager().checkForPluginUser( nPluginId ) ) {
606
607             String JavaDoc strItem = "REGISTER_EXISTING_USER";
608
609             item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_ADD_EXISTING_USER ) );
610             addNode( node, item );
611
612             if( plugin.getPluginCapabilities().getBool( JPluginCapabilities.CAPABILITY_REGISTER_NEW_USER ) ) {
613               strItem = "REGISTER_NEW_USER";
614               item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_ADD_NEW_USER ) );
615               addNode( node, item );
616             }
617
618             strItem = "REMOVE_PLUGIN";
619             item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_REMOVE_PLUGIN ) );
620             addNode( node, item );
621           }
622           else {
623             String JavaDoc strItem = "CHANGE_PASSWORD";
624
625             item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_CHANGE_PASSWD ) );
626             addNode( node, item );
627
628             strItem = "UNREGISTER_USER";
629             item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_UNREGISTER_USER ) );
630             addNode( node, item );
631
632             strItem = "REMOVE_PLUGIN";
633             item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_REMOVE_PLUGIN ) );
634             addNode( node, item );
635
636             // Plugin has Privacy control capability
637
if( plugin.getPluginCapabilities().getBool( JPluginCapabilities.CAPABILITY_PRIVACY_CONTROL_ENABLED ) ) {
638               strItem = "PRIVACY_CONTROL";
639               item = new JDataField( strItem, JSharedObjects.getLanguageManager().getStringEx( strItem ), new Integer JavaDoc( SUB_ITEM_PRIVACY_CONTROL ) );
640               addNode( node, item );
641             }
642
643             // TODO: Registered options !!
644
}
645           bNoAvail = false;
646         }
647       }
648
649       if( bNoAvail ) {
650         String JavaDoc strItem = JSharedObjects.getLanguageManager().getStringEx( "NO_INSTALLED_PLUGINS" );
651         JDataField item = new JDataField( strItem, strItem, new Integer JavaDoc( ITEM_EMPTY ) );
652
653         addNode( installedPluginsNode, item );
654       }
655     }
656
657     reload( installedPluginsNode );
658   }
659   
660   /**
661    * Implements the valueChanged of TreeSelectionListener
662    * interface.<br>
663    * Update the right panel depending on selection;
664    * item selected;<br>
665    * @param See Jdk docs;
666    */

667   public void valueChanged( javax.swing.event.TreeSelectionEvent JavaDoc treeSelectionEvent ) {
668
669     TreePath path = treeSelectionEvent.getPath();
670     DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) path.getLastPathComponent();
671     DefaultMutableTreeNode parentNode = ( DefaultMutableTreeNode ) path.getParentPath().getLastPathComponent();
672     JDataField item = ( JDataField ) node.getUserObject();
673     JDataField parentItem = null;
674
675     // Is a installed plugin ???
676
if( parentNode != null ) {
677
678       int nPluginId = -1;
679       int nMode = JRegisterUserPanel.MODE_NONE;
680       
681       
682       switch( ( ( Integer JavaDoc ) item.getObject() ).intValue() ) {
683         
684         case SUB_ITEM_ADD_NEW_USER : nMode = JRegisterUserPanel.MODE_REGISTER_NEW_USER; break;
685         
686         case SUB_ITEM_ADD_EXISTING_USER : nMode = JRegisterUserPanel.MODE_REGISTER_USER; break;
687         
688         case SUB_ITEM_CHANGE_PASSWD : nMode = JRegisterUserPanel.MODE_CHANGE_PASSWD; break;
689       }
690       
691       parentItem = ( JDataField ) parentNode.getUserObject();
692       nPluginId = ( ( Integer JavaDoc ) parentItem.getObject() ).intValue();
693       privacyControlPanel.setPluginId( nPluginId );
694       registerUserPanel.setPluginId( nPluginId );
695       registerUserPanel.setMode( nMode );
696     }
697
698     JSharedObjects.getPluginPreferencesManager().fireOnShow( ( ( Integer JavaDoc ) item.getObject() ).intValue(), item );
699   }
700 }
701 // JMOSPreferencesDlg class
702
Popular Tags