KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > folder > FolderOptionsDialog


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.mail.gui.config.folder;
18
19 import java.awt.BorderLayout JavaDoc;
20 import java.awt.Color JavaDoc;
21 import java.awt.Dimension JavaDoc;
22 import java.awt.Font JavaDoc;
23 import java.awt.GridLayout JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26 import java.awt.event.KeyEvent JavaDoc;
27 import java.io.File JavaDoc;
28
29 import javax.swing.BorderFactory JavaDoc;
30 import javax.swing.DefaultListSelectionModel JavaDoc;
31 import javax.swing.JButton JavaDoc;
32 import javax.swing.JCheckBox JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JDialog JavaDoc;
35 import javax.swing.JFileChooser JavaDoc;
36 import javax.swing.JLabel JavaDoc;
37 import javax.swing.JPanel JavaDoc;
38 import javax.swing.JScrollPane JavaDoc;
39 import javax.swing.JTextField JavaDoc;
40 import javax.swing.KeyStroke JavaDoc;
41 import javax.swing.UIManager JavaDoc;
42 import javax.swing.event.ListSelectionEvent JavaDoc;
43 import javax.swing.event.ListSelectionListener JavaDoc;
44
45 import org.columba.core.command.CommandProcessor;
46 import org.columba.core.gui.base.ButtonWithMnemonic;
47 import org.columba.core.gui.base.CTabbedPane;
48 import org.columba.core.gui.base.LabelWithMnemonic;
49 import org.columba.core.gui.base.MultiLineLabel;
50 import org.columba.core.help.HelpManager;
51 import org.columba.core.xml.XmlElement;
52 import org.columba.mail.command.MailFolderCommandReference;
53 import org.columba.mail.config.IFolderItem;
54 import org.columba.mail.folder.AbstractLocalFolder;
55 import org.columba.mail.folder.IMailbox;
56 import org.columba.mail.folder.IMailboxInfo;
57 import org.columba.mail.folder.command.ExportFolderCommand;
58 import org.columba.mail.folder.command.RenameFolderCommand;
59 import org.columba.mail.folder.command.SyncSearchEngineCommand;
60 import org.columba.mail.folder.search.LuceneQueryEngine;
61 import org.columba.mail.folderoptions.FolderOptionsController;
62 import org.columba.mail.gui.frame.MailFrameMediator;
63 import org.columba.mail.gui.table.command.ViewHeaderListCommand;
64 import org.columba.mail.util.MailResourceLoader;
65 import org.frapuccino.checkablelist.CheckableItem;
66 import org.frapuccino.checkablelist.CheckableItemListTableModel;
67
68 import com.jgoodies.forms.builder.ButtonStackBuilder;
69 import com.jgoodies.forms.builder.PanelBuilder;
70 import com.jgoodies.forms.layout.CellConstraints;
71 import com.jgoodies.forms.layout.FormLayout;
72
73 /**
74  * Folder Options Dialog. Shows status information about selected folder.
75  * <p>
76  * Note, that this dialog is not modal. A background thread is used to calculate
77  * the total mailbox size.
78  *
79  * @author fdietz
80  */

81
82 public class FolderOptionsDialog extends JDialog JavaDoc implements ActionListener JavaDoc,
83         ListSelectionListener JavaDoc {
84     public final static String JavaDoc[] tooltips = { "columns", "sorting", "filter",
85             "threadedview", "selection" };
86
87     private IMailbox folder;
88
89     private JLabel JavaDoc nameLabel;
90
91     private JTextField JavaDoc nameTextField;
92
93     private JLabel JavaDoc totalLabel;
94
95     private JLabel JavaDoc totalLabel2;
96
97     private JLabel JavaDoc unreadLabel;
98
99     private JLabel JavaDoc unreadLabel2;
100
101     private JLabel JavaDoc recentLabel;
102
103     private JLabel JavaDoc recentLabel2;
104
105     private JLabel JavaDoc locationLabel;
106
107     private JLabel JavaDoc locationLabel2;
108
109     private JLabel JavaDoc sizeLabel;
110
111     private JLabel JavaDoc sizeLabel2;
112
113     private JButton JavaDoc exportButton;
114
115     private MultiLineLabel enableLabel;
116
117     //private JLabel enableTextIndexingLabel;
118

119     private JCheckBox JavaDoc enableTextIndexingCheckBox;
120
121     private boolean renameFolder;
122
123     private String JavaDoc oldFolderName = null;
124
125     private MultiLineLabel overwriteLabel;
126
127     private JButton JavaDoc resetButton;
128
129     private JButton JavaDoc enableButton;
130
131     private JButton JavaDoc disableButton;
132
133     // JCheckBox overwriteOptionsCheckBox;
134
private CheckableTooltipList checkableList;
135
136     private MailFrameMediator mediator;
137
138     /**
139      * Constructor
140      *
141      * @param folder
142      * selected folder
143      * @param renameFolder
144      * this is a "rename folder" operation
145      */

146     public FolderOptionsDialog(IMailbox folder, boolean renameFolder,
147             MailFrameMediator mediator) {
148         super(mediator.getView().getFrame(), MailResourceLoader.getString(
149                 "dialog", "folderoptions", "dialog_title"), false);
150
151         this.folder = folder;
152         this.renameFolder = renameFolder;
153         this.mediator = mediator;
154
155         oldFolderName = folder.getName();
156
157         initComponents();
158         updateComponents(true);
159         pack();
160         setLocationRelativeTo(null);
161
162         // focus name textfield
163
if (renameFolder) {
164             nameTextField.selectAll();
165             nameTextField.requestFocus();
166         }
167
168         setVisible(true);
169     }
170
171     /**
172      * Default constructor
173      *
174      * @param folder
175      * selected folder
176      */

177     public FolderOptionsDialog(IMailbox folder, MailFrameMediator mediator) {
178         super(mediator.getView().getFrame(), MailResourceLoader.getString(
179                 "dialog", "folderoptions", "dialog_title"), true);
180
181         this.folder = folder;
182         this.mediator = mediator;
183
184         initComponents();
185         updateComponents(true);
186         pack();
187         setLocationRelativeTo(null);
188
189         nameTextField.selectAll();
190         nameTextField.requestFocus();
191
192         setVisible(true);
193     }
194
195     protected JPanel JavaDoc createGeneralPanel() {
196         // Create a FormLayout instance.
197
FormLayout layout = new FormLayout(
198                 "6dlu, right:max(25dlu;default), 3dlu, fill:default:grow, fill:0dlu:grow", //$NON-NLS-1$
199

200                 // 3 columns
201
"pref, 3dlu, pref, 6dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 6dlu, pref, 24dlu, pref, 3dlu, pref, 6dlu, default, 0dlu"); //$NON-NLS-1$
202

203         // create a form builder
204
PanelBuilder builder = new PanelBuilder(layout);
205         CellConstraints cc = new CellConstraints();
206
207         // create EmptyBorder between components and dialog-frame
208
builder.setDefaultDialogBorder();
209
210         // Add components to the panel:
211
builder.addSeparator(MailResourceLoader.getString("dialog",
212                 "folderoptions", "general_info"), cc.xywh(1, 1, 5, 1)); //$NON-NLS-1$
213

214         builder.add(nameLabel, cc.xy(2, 3));
215         builder.add(nameTextField, cc.xywh(4, 3, 2, 1));
216
217         builder.add(totalLabel, cc.xy(2, 5));
218         builder.add(totalLabel2, cc.xy(4, 5));
219
220         builder.add(unreadLabel, cc.xy(2, 7));
221         builder.add(unreadLabel2, cc.xy(4, 7));
222
223         builder.add(recentLabel, cc.xy(2, 9));
224         builder.add(unreadLabel2, cc.xy(4, 9));
225
226         builder.add(sizeLabel, cc.xy(2, 11));
227         builder.add(sizeLabel2, cc.xy(4, 11));
228
229         // @author tstich: Added Lucene gui element here
230
//builder.add(enableTextIndexingLabel, cc.xy(2, 13));
231
builder.add(enableTextIndexingCheckBox, cc.xywh(2, 13, 4, 1));
232
233         builder.appendGlueRow();
234
235         builder.addSeparator(MailResourceLoader.getString("dialog",
236                 "folderoptions", "archiving_messages"), cc.xywh(1, 15, 5, 1)); //$NON-NLS-1$
237

238         builder.add(locationLabel, cc.xy(2, 17));
239         builder.add(locationLabel2, cc.xy(4, 17));
240
241         JPanel JavaDoc panel = new JPanel JavaDoc();
242         panel.setLayout(new BorderLayout JavaDoc());
243
244         panel.add(exportButton, BorderLayout.EAST);
245         builder.add(panel, cc.xywh(4, 19, 2, 1));
246
247         return builder.getPanel();
248     }
249
250     /**
251      * Create advanced panel.
252      * <p>
253      *
254      * @return panel
255      */

256     protected JPanel JavaDoc createAdvancedPanel() {
257         // Create a FormLayout instance.
258
FormLayout layout = new FormLayout("fill:default:grow, 6px, default", //$NON-NLS-1$
259

260                 // 3 columns
261
"pref, 6px, fill:pref:grow"); //$NON-NLS-1$
262

263         // create a form builder
264
PanelBuilder builder = new PanelBuilder(layout);
265         CellConstraints cc = new CellConstraints();
266
267         // create EmptyBorder between components and dialog-frame
268
builder.setDefaultDialogBorder();
269
270         builder.add(overwriteLabel, cc.xywh(1, 1, 3, 1));
271
272         JScrollPane JavaDoc sp = new JScrollPane JavaDoc(checkableList);
273         sp.setPreferredSize(new Dimension JavaDoc(200, 200));
274         sp.getViewport().setBackground(Color.white);
275         builder.add(sp, cc.xy(1, 3));
276
277         ButtonStackBuilder b = new ButtonStackBuilder();
278         b.addGridded(enableButton);
279         b.addRelatedGap();
280         b.addGridded(disableButton);
281         b.addUnrelatedGap();
282         b.addGlue();
283         b.addFixed(resetButton);
284
285         JPanel JavaDoc buttonPanel = b.getPanel();
286         builder.add(buttonPanel, cc.xy(3, 3));
287
288         /*
289          * JPanel panel= new JPanel(); panel.setLayout(new BorderLayout());
290          * panel.add(resetButton, BorderLayout.EAST); builder.add(panel,
291          * cc.xywh(5, 7, 1, 1));
292          */

293         /*
294          * builder.addSeparator("Full-text indexing");
295          *
296          * builder.add(enableLabel, cc.xywh(1, 7, 5, 1));
297          * builder.add(enableTextIndexingCheckBox, cc.xywh(2, 9, 4, 1));
298          */

299         return builder.getPanel();
300     }
301
302     protected void initComponents() {
303         Font JavaDoc boldFont = (Font JavaDoc) UIManager.get("Label.font"); //$NON-NLS-1$
304
boldFont = boldFont.deriveFont(Font.BOLD);
305
306         nameLabel = new LabelWithMnemonic(MailResourceLoader.getString(
307                 "dialog", "folderoptions", "name")); //$NON-NLS-1$
308
//nameLabel.setFont(boldFont);
309
nameTextField = new JTextField JavaDoc();
310
311         totalLabel = new JLabel JavaDoc(MailResourceLoader.getString("dialog",
312                 "folderoptions", "total")); //$NON-NLS-1$
313
//totalLabel.setFont(boldFont);
314
totalLabel2 = new JLabel JavaDoc("0"); //$NON-NLS-1$
315

316         unreadLabel = new JLabel JavaDoc(MailResourceLoader.getString("dialog",
317                 "folderoptions", "unread")); //$NON-NLS-1$
318
//unreadLabel.setFont(boldFont);
319
unreadLabel2 = new JLabel JavaDoc("0"); //$NON-NLS-1$
320

321         recentLabel = new JLabel JavaDoc(MailResourceLoader.getString("dialog",
322                 "folderoptions", "recent")); //$NON-NLS-1$
323
//recentLabel.setFont(boldFont);
324
recentLabel2 = new JLabel JavaDoc("0"); //$NON-NLS-1$
325

326         sizeLabel = new JLabel JavaDoc(MailResourceLoader.getString("dialog",
327                 "folderoptions", "mailbox_size")); //$NON-NLS-1$
328
//sizeLabel.setFont(boldFont);
329
sizeLabel2 = new JLabel JavaDoc(); //$NON-NLS-1$
330

331         locationLabel = new JLabel JavaDoc(MailResourceLoader.getString("dialog",
332                 "folderoptions", "location")); //$NON-NLS-1$
333
//locationLabel.setFont(boldFont);
334
locationLabel2 = new JLabel JavaDoc(""); //$NON-NLS-1$
335

336         exportButton = new ButtonWithMnemonic(MailResourceLoader.getString(
337                 "dialog", "folderoptions", "export")); //$NON-NLS-1$
338
exportButton.setActionCommand("EXPORT"); //$NON-NLS-1$
339
exportButton.addActionListener(this);
340
341     
342         enableTextIndexingCheckBox = new JCheckBox JavaDoc(MailResourceLoader.getString(
343                 "dialog", "folderoptions", "enable_full-text_indexing")); //$NON-NLS-1$
344
enableTextIndexingCheckBox.setToolTipText(MailResourceLoader.getString(
345                 "dialog", "folderoptions", "enable_full-text_indexing_tooltip"));
346         
347         enableLabel = new MultiLineLabel(MailResourceLoader.getString(
348                 "dialog", "folderoptions", "this_is_an_experimental_feature")); //$NON-NLS-1$
349
//enableLabel.setFont(boldFont);
350

351         overwriteLabel = new MultiLineLabel(MailResourceLoader.getString(
352                 "dialog", "folderoptions", "select_individual_options"));
353
354         resetButton = new ButtonWithMnemonic(MailResourceLoader.getString(
355                 "dialog", "folderoptions", "reset")); //$NON-NLS-1$
356
resetButton.setActionCommand("RESET"); //$NON-NLS-1$
357
resetButton.addActionListener(this);
358
359         enableButton = new ButtonWithMnemonic(MailResourceLoader.getString(
360                 "dialog", "folderoptions", "overwrite")); //$NON-NLS-1$
361
enableButton.setActionCommand("ENABLED"); //$NON-NLS-1$
362
enableButton.addActionListener(this);
363         disableButton = new ButtonWithMnemonic(MailResourceLoader.getString(
364                 "dialog", "folderoptions", "use_default")); //$NON-NLS-1$
365
disableButton.setActionCommand("DISABLED"); //$NON-NLS-1$
366
disableButton.addActionListener(this);
367         enableButton.setEnabled(false);
368         disableButton.setEnabled(false);
369
370         /*
371          * overwriteOptionsCheckBox = new JCheckBox("Overwrite global
372          * settings"); overwriteOptionsCheckBox.addActionListener(this);
373          * overwriteOptionsCheckBox.setActionCommand("OVERWRITE");
374          */

375         checkableList = new CheckableTooltipList();
376         checkableList.setOptionsCellRenderer(new OptionsRenderer());
377         checkableList.getSelectionModel().addListSelectionListener(this);
378
379         CTabbedPane tp = new CTabbedPane();
380         tp.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 6));
381
382         tp.add(MailResourceLoader.getString("dialog", "folderoptions",
383                 "general_options"), createGeneralPanel()); //$NON-NLS-1$
384
tp.add(MailResourceLoader.getString("dialog", "folderoptions",
385                 "advanced"), createAdvancedPanel()); //$NON-NLS-1$
386

387         getContentPane().add(tp, BorderLayout.CENTER);
388
389         getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
390         getRootPane().registerKeyboardAction(this, "CANCEL", //$NON-NLS-1$
391
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
392                 JComponent.WHEN_IN_FOCUSED_WINDOW);
393     }
394
395     protected JPanel JavaDoc createButtonPanel() {
396         JPanel JavaDoc bottom = new JPanel JavaDoc();
397         bottom.setLayout(new BorderLayout JavaDoc());
398
399         // bottom.setBorder(new SingleSideEtchedBorder(SwingConstants.TOP));
400
// bottom.setLayout( new BoxLayout( bottom, BoxLayout.X_AXIS ) );
401
// bottom.add( Box.createHorizontalStrut());
402
ButtonWithMnemonic cancelButton = new ButtonWithMnemonic(
403                 MailResourceLoader.getString("global", "cancel")); //$NON-NLS-1$ //$NON-NLS-2$
404

405         //$NON-NLS-1$ //$NON-NLS-2$
406
cancelButton.addActionListener(this);
407         cancelButton.setActionCommand("CANCEL"); //$NON-NLS-1$
408

409         ButtonWithMnemonic okButton = new ButtonWithMnemonic(MailResourceLoader
410                 .getString("global", "ok")); //$NON-NLS-1$ //$NON-NLS-2$
411

412         //$NON-NLS-1$ //$NON-NLS-2$
413
okButton.addActionListener(this);
414         okButton.setActionCommand("OK"); //$NON-NLS-1$
415
okButton.setDefaultCapable(true);
416         getRootPane().setDefaultButton(okButton);
417
418         ButtonWithMnemonic helpButton = new ButtonWithMnemonic(
419                 MailResourceLoader.getString("global", "help")); //$NON-NLS-1$ //$NON-NLS-2$
420

421         // associate with JavaHelp
422
HelpManager.getInstance().enableHelpOnButton(helpButton,
423                 "folder_options");
424         HelpManager.getInstance()
425                 .enableHelpKey(getRootPane(), "folder_options");
426
427         JPanel JavaDoc buttonPanel = new JPanel JavaDoc();
428         buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
429         buttonPanel.setLayout(new GridLayout JavaDoc(1, 3, 6, 0));
430         buttonPanel.add(okButton);
431         buttonPanel.add(cancelButton);
432         buttonPanel.add(helpButton);
433
434         // bottom.add( Box.createHorizontalGlue() );
435
bottom.add(buttonPanel, BorderLayout.EAST);
436
437         return bottom;
438     }
439
440     public void updateComponents(boolean b) {
441         if (b) {
442             IMailboxInfo info = folder.getMessageFolderInfo();
443
444             nameTextField.setText(folder.getName());
445
446             totalLabel2.setText(Integer.toString(info.getExists()));
447             unreadLabel2.setText(Integer.toString(info.getUnseen()));
448             recentLabel2.setText(Integer.toString(info.getRecent()));
449
450             locationLabel2.setText(folder.getDirectoryFile().getPath());
451
452             IFolderItem item = folder.getConfiguration();
453             XmlElement property = item.getElement("property"); //$NON-NLS-1$
454

455             CheckableItemListTableModel model = new CheckableItemListTableModel();
456
457             for (int i = 0; i < property.count(); i++) {
458                 OptionsItem optionsItem = new OptionsItem((XmlElement) property
459                         .getElement(i).clone());
460
461                 model.addElement(optionsItem);
462             }
463
464             checkableList.setModel(model);
465
466             /*
467              * if (property.getAttribute("overwrite_default_settings", "false")
468              * .equals("true")) { overwriteOptionsCheckBox.setSelected(true); }
469              * else { overwriteOptionsCheckBox.setSelected(false); }
470              */

471
472             // only local folders have an full-text indexing capability
473
if (folder instanceof AbstractLocalFolder) {
474                 item = folder.getConfiguration();
475                 // enable lucene search index by default
476
boolean bool = item.getBooleanWithDefault("property", "enable_lucene", true); //$NON-NLS-1$ //$NON-NLS-2$
477

478                 enableTextIndexingCheckBox.setSelected(bool);
479             } else {
480                 //enableTextIndexingLabel.setEnabled(false);
481
enableTextIndexingCheckBox.setEnabled(false);
482             }
483         } else {
484             if (renameFolder) {
485                 if (!oldFolderName.equals(nameTextField.getText())) {
486                     // user changed folder name
487
MailFolderCommandReference r = new MailFolderCommandReference(
488                             folder);
489                     r.setFolderName(nameTextField.getText());
490                     CommandProcessor.getInstance().addOp(
491                             new RenameFolderCommand(r));
492                 }
493             }
494
495             IFolderItem item = folder.getConfiguration();
496             XmlElement property = item.getElement("property"); //$NON-NLS-1$
497

498             // remove all old elements
499
property.removeAllElements();
500
501             CheckableItemListTableModel model = (CheckableItemListTableModel) checkableList
502                     .getModel();
503
504             for (int i = 0; i < model.count(); i++) {
505                 OptionsItem optionsItem = (OptionsItem) model.getElement(i);
506
507                 // add new element
508
property.addElement(optionsItem.getElement());
509             }
510
511             // only local folders have an full-text indexing capability
512
if (folder instanceof AbstractLocalFolder) {
513                 item = folder.getConfiguration();
514
515                 boolean bool = enableTextIndexingCheckBox.isSelected();
516                 item.setBoolean("property", "enable_lucene", bool); //$NON-NLS-1$ //$NON-NLS-2$
517

518                 // cast to Local AbstractMessageFolder is safe here
519
AbstractLocalFolder localFolder = (AbstractLocalFolder) folder;
520
521                 if (bool) {
522                     localFolder.getSearchEngine().setNonDefaultEngine(
523                             new LuceneQueryEngine(localFolder));
524
525                     // execute resyncing command
526
MailFolderCommandReference r = new MailFolderCommandReference(
527                             folder);
528                     CommandProcessor.getInstance().addOp(
529                             new SyncSearchEngineCommand(r));
530                 } else {
531                     localFolder.setSearchEngine(null);
532                 }
533             }
534
535             // restore settings
536
getMediator().getFolderOptionsController().load(
537                     FolderOptionsController.STATE_BEFORE);
538
539             // re-select folder to make changes visible to the user
540
MailFolderCommandReference r = new MailFolderCommandReference(
541                     folder);
542             CommandProcessor.getInstance().addOp(
543                     new ViewHeaderListCommand(getMediator(), r));
544         }
545     }
546
547     public void actionPerformed(ActionEvent JavaDoc arg0) {
548         String JavaDoc action = arg0.getActionCommand();
549
550         if (action.equals("CANCEL")) { //$NON-NLS-1$
551
setVisible(false);
552         } else if (action.equals("OK")) { //$NON-NLS-1$
553
setVisible(false);
554             updateComponents(false);
555         } else if (action.equals("EXPORT")) { //$NON-NLS-1$
556

557             File JavaDoc destFile = null;
558
559             // ask the user about the destination file
560
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
561             chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
562             chooser.setMultiSelectionEnabled(false);
563
564             int result = chooser.showSaveDialog(this);
565
566             if (result == JFileChooser.APPROVE_OPTION) {
567                 File JavaDoc file = chooser.getSelectedFile();
568
569                 destFile = file;
570             } else {
571                 return;
572             }
573
574             setVisible(false);
575
576             MailFolderCommandReference r = new MailFolderCommandReference(
577                     folder);
578             r.setDestFile(destFile);
579             CommandProcessor.getInstance().addOp(new ExportFolderCommand(r));
580         } else if (action.equals("RESET")) { //$NON-NLS-1$
581

582             IFolderItem item = folder.getConfiguration();
583             XmlElement property = item.getElement("property"); //$NON-NLS-1$
584

585             // remove all options
586
property.removeAllElements();
587
588             // create new default options
589
getMediator().getFolderOptionsController().createDefaultSettings(
590                     folder);
591
592             /*
593              * for (int i= 0; i < property.count(); i++) { XmlElement child=
594              * property.getElement(i);
595              *
596              * child.addAttribute("overwrite", "false"); //$NON-NLS-1$
597              * //$NON-NLS-2$ }
598              */

599
600             // update list view
601
CheckableItemListTableModel model = new CheckableItemListTableModel();
602
603             for (int i = 0; i < property.count(); i++) {
604                 OptionsItem optionsItem = new OptionsItem((XmlElement) property
605                         .getElement(i).clone());
606
607                 model.addElement(optionsItem);
608             }
609
610             checkableList.setModel(model);
611         } else if (action.equals("ENABLED")) { //$NON-NLS-1$
612

613             CheckableItem item = (CheckableItem) checkableList.getSelected();
614             item.setSelected(!item.isSelected());
615             ((CheckableItemListTableModel) checkableList.getModel())
616                     .updateRow(item);
617             updateButtonState(item.isSelected());
618         } else if (action.equals("DISABLED")) { //$NON-NLS-1$
619

620             CheckableItem item = (CheckableItem) checkableList.getSelected();
621             item.setSelected(!item.isSelected());
622             ((CheckableItemListTableModel) checkableList.getModel())
623                     .updateRow(item);
624             updateButtonState(item.isSelected());
625         }
626     }
627
628     private void updateButtonState(boolean selected) {
629         if (selected) {
630             enableButton.setEnabled(false);
631             disableButton.setEnabled(true);
632         } else {
633             enableButton.setEnabled(true);
634             disableButton.setEnabled(false);
635         }
636     }
637
638     public void valueChanged(ListSelectionEvent JavaDoc e) {
639         if (e.getValueIsAdjusting()) {
640             return;
641         }
642
643         DefaultListSelectionModel JavaDoc theList = (DefaultListSelectionModel JavaDoc) e
644                 .getSource();
645
646         if (!theList.isSelectionEmpty()) {
647             
648             CheckableItem item = (CheckableItem) checkableList.getSelected();
649             updateButtonState(item.isSelected());
650         }
651     }
652
653     /**
654      * Set size of mailbox.
655      *
656      * @param size
657      * size of mailbox
658      */

659     public void setMailboxSize(int sizeInKB) {
660         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
661
662         // if size > than 1000 KB, transform to MB
663
if (sizeInKB > 1000)
664             buf.append(new Integer JavaDoc(sizeInKB / 1000).toString() + " MB");
665         else
666             buf.append(new Integer JavaDoc(sizeInKB).toString() + " KB");
667
668         sizeLabel2.setText(buf.toString());
669     }
670
671     /**
672      * @return
673      */

674     public MailFrameMediator getMediator() {
675         return mediator;
676     }
677 }
Popular Tags