mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
20.36.2016 2a3158aad80fc910b83336485b3e545dea50066c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008-2010 Sun Microsystems, Inc.
 * Portions Copyright 2014-2016 ForgeRock AS.
 */
package org.opends.guitools.controlpanel.ui;
 
import static org.opends.messages.AdminToolMessages.*;
 
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.TreePath;
 
import org.forgerock.i18n.LocalizableMessage;
import org.opends.guitools.controlpanel.browser.BasicNodeError;
import org.opends.guitools.controlpanel.browser.BrowserController;
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
import org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
import org.opends.guitools.controlpanel.event.EntryReadErrorEvent;
import org.opends.guitools.controlpanel.event.EntryReadEvent;
import org.opends.guitools.controlpanel.event.EntryReadListener;
import org.opends.guitools.controlpanel.event.LDAPEntryChangedEvent;
import org.opends.guitools.controlpanel.event.LDAPEntryChangedListener;
import org.opends.guitools.controlpanel.task.DeleteEntryTask;
import org.opends.guitools.controlpanel.task.ModifyEntryTask;
import org.opends.guitools.controlpanel.task.Task;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.config.ConfigConstants;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.ServerConstants;
 
/** This is the panel that contains all the different views to display an entry. */
public class LDAPEntryPanel extends StatusGenericPanel
implements EntryReadListener
{
  private static final long serialVersionUID = -6608246173472437830L;
  private JButton saveChanges;
  private JButton delete;
  private JPanel mainPanel;
  private CardLayout cardLayout;
 
  private ErrorSearchingEntryPanel errorSearchingPanel;
  private LDIFViewEntryPanel ldifEntryPanel;
  private TableViewEntryPanel tableEntryPanel;
  private SimplifiedViewEntryPanel simplifiedEntryPanel;
 
  private ViewEntryPanel displayedEntryPanel;
 
  private CustomSearchResult searchResult;
  private BrowserController controller;
  private TreePath treePath;
 
  private ModifyEntryTask newTask;
 
  private final String NOTHING_SELECTED = "Nothing Selected";
  private final String MULTIPLE_SELECTED = "Multiple Selected";
  private final String LDIF_VIEW = "LDIF View";
  private final String ATTRIBUTE_VIEW = "Attribute View";
  private final String SIMPLIFIED_VIEW = "Simplified View";
  private final String ERROR_SEARCHING = "Error Searching";
 
  private View view = View.SIMPLIFIED_VIEW;
 
  /** The different views that we have to display an LDAP entry. */
  public enum View
  {
    /** Simplified view. */
    SIMPLIFIED_VIEW,
    /** Attribute view (contained in a table). */
    ATTRIBUTE_VIEW,
    /** LDIF view (text based). */
    LDIF_VIEW
  }
 
  /** Default constructor. */
  public LDAPEntryPanel()
  {
    super();
    createLayout();
  }
 
  /** Creates the layout of the panel (but the contents are not populated here). */
  private void createLayout()
  {
    GridBagConstraints gbc = new GridBagConstraints();
    cardLayout = new CardLayout();
    mainPanel = new JPanel(cardLayout);
    mainPanel.setOpaque(false);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    add(mainPanel, gbc);
    gbc.gridwidth = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 0.0;
    gbc.gridy ++;
    gbc.fill = GridBagConstraints.NONE;
    delete = Utilities.createButton(INFO_CTRL_PANEL_DELETE_ENTRY_BUTTON.get());
    delete.setOpaque(false);
    add(delete, gbc);
    delete.addActionListener(new ActionListener()
    {
      @Override
      public void actionPerformed(ActionEvent ev)
      {
        deleteEntry();
      }
    });
 
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridx ++;
    saveChanges =
      Utilities.createButton(INFO_CTRL_PANEL_SAVE_CHANGES_LABEL.get());
    saveChanges.setOpaque(false);
    add(saveChanges, gbc);
    saveChanges.addActionListener(new ActionListener()
    {
      @Override
      public void actionPerformed(ActionEvent ev)
      {
        saveChanges(true);
      }
    });
 
    Border border = new EmptyBorder(10, 10, 10, 10);
 
    NoItemSelectedPanel noEntryPanel = new NoItemSelectedPanel();
    noEntryPanel.setMessage(INFO_CTRL_PANEL_NO_ENTRY_SELECTED_LABEL.get());
    Utilities.setBorder(noEntryPanel, border);
    mainPanel.add(noEntryPanel, NOTHING_SELECTED);
 
    NoItemSelectedPanel multipleEntryPanel = new NoItemSelectedPanel();
    multipleEntryPanel.setMessage(
        INFO_CTRL_PANEL_MULTIPLE_ENTRIES_SELECTED_LABEL.get());
    Utilities.setBorder(multipleEntryPanel, border);
    mainPanel.add(multipleEntryPanel, MULTIPLE_SELECTED);
 
    errorSearchingPanel = new ErrorSearchingEntryPanel();
    if (errorSearchingPanel.requiresBorder())
    {
      Utilities.setBorder(multipleEntryPanel, border);
    }
    mainPanel.add(errorSearchingPanel, ERROR_SEARCHING);
 
    LDAPEntryChangedListener listener = new LDAPEntryChangedListener()
    {
      @Override
      public void entryChanged(LDAPEntryChangedEvent ev)
      {
        boolean enable = saveChanges.isVisible() &&
            !authenticationRequired(getInfo().getServerDescriptor());
        if (enable)
        {
          if (ev.getEntry() == null)
          {
            // Something changed that is wrong: assume the entry has been
            // modified, when the user tries to save we will inform of the
            // problem
            enable = true;
          }
          else
          {
            boolean modified =
              !Utilities.areDnsEqual(ev.getEntry().getName().toString(),
                  searchResult.getDN()) ||
                  !ModifyEntryTask.getModifications(ev.getEntry(), searchResult,
                      getInfo()).isEmpty();
            enable = modified;
          }
        }
        saveChanges.setEnabled(enable);
      }
    };
 
    ldifEntryPanel = new LDIFViewEntryPanel();
    ldifEntryPanel.addLDAPEntryChangedListener(listener);
    if (ldifEntryPanel.requiresBorder())
    {
      Utilities.setBorder(ldifEntryPanel, border);
    }
    mainPanel.add(ldifEntryPanel, LDIF_VIEW);
 
    tableEntryPanel = new TableViewEntryPanel();
    tableEntryPanel.addLDAPEntryChangedListener(listener);
    if (tableEntryPanel.requiresBorder())
    {
      Utilities.setBorder(tableEntryPanel, border);
    }
    mainPanel.add(tableEntryPanel, ATTRIBUTE_VIEW);
 
    simplifiedEntryPanel = new SimplifiedViewEntryPanel();
    simplifiedEntryPanel.addLDAPEntryChangedListener(listener);
    if (simplifiedEntryPanel.requiresBorder())
    {
      Utilities.setBorder(simplifiedEntryPanel, border);
    }
    mainPanel.add(simplifiedEntryPanel, SIMPLIFIED_VIEW);
 
    cardLayout.show(mainPanel, NOTHING_SELECTED);
  }
 
  @Override
  public void okClicked()
  {
    // No ok button
  }
 
  @Override
  public void entryRead(EntryReadEvent ev)
  {
    searchResult = ev.getSearchResult();
 
    updateEntryView(searchResult, treePath);
  }
 
  /**
   * Updates the panel with the provided search result.
   * @param searchResult the search result corresponding to the selected node.
   * @param treePath the tree path of the selected node.
   */
  private void updateEntryView(CustomSearchResult searchResult,
      TreePath treePath)
  {
    boolean isReadOnly = isReadOnly(searchResult.getDN());
    boolean canDelete = canDelete(searchResult.getDN());
 
    delete.setVisible(canDelete);
    saveChanges.setVisible(!isReadOnly);
    String cardKey;
    switch (view)
    {
    case LDIF_VIEW:
      displayedEntryPanel = ldifEntryPanel;
      cardKey = LDIF_VIEW;
      break;
    case ATTRIBUTE_VIEW:
      displayedEntryPanel = tableEntryPanel;
      cardKey = ATTRIBUTE_VIEW;
      break;
    default:
      displayedEntryPanel = simplifiedEntryPanel;
      cardKey = SIMPLIFIED_VIEW;
    }
    displayedEntryPanel.update(searchResult, isReadOnly, treePath);
    saveChanges.setEnabled(false);
    cardLayout.show(mainPanel, cardKey);
  }
 
  /**
   * Sets the view to be displayed by this panel.
   * @param view the view.
   */
  public void setView(View view)
  {
    if (view != this.view)
    {
      this.view = view;
      if (searchResult != null)
      {
        updateEntryView(searchResult, treePath);
      }
    }
  }
 
  /**
   * Displays a message informing that an error occurred reading the entry.
   * @param ev the entry read error event.
   */
  @Override
  public void entryReadError(EntryReadErrorEvent ev)
  {
    searchResult = null;
 
    errorSearchingPanel.setError(ev.getDN(), ev.getError());
 
    delete.setVisible(false);
    saveChanges.setVisible(false);
 
    cardLayout.show(mainPanel, ERROR_SEARCHING);
 
    displayedEntryPanel = null;
  }
 
  /**
   * Displays a message informing that an error occurred resolving a referral.
   * @param dn the DN of the local entry.
   * @param referrals the list of referrals defined in the entry.
   * @param error the error that occurred resolving the referral.
   */
  public void referralSolveError(String dn, String[] referrals,
      BasicNodeError error)
  {
    searchResult = null;
 
    errorSearchingPanel.setReferralError(dn, referrals, error);
 
    delete.setVisible(false);
    saveChanges.setVisible(false);
 
    cardLayout.show(mainPanel, ERROR_SEARCHING);
 
    displayedEntryPanel = null;
  }
 
  /** Displays a panel informing that nothing is selected. */
  public void noEntrySelected()
  {
    searchResult = null;
 
    delete.setVisible(false);
    saveChanges.setVisible(false);
 
    cardLayout.show(mainPanel, NOTHING_SELECTED);
 
    displayedEntryPanel = null;
  }
 
  /** Displays a panel informing that multiple entries are selected. */
  public void multipleEntriesSelected()
  {
    searchResult = null;
 
    delete.setVisible(false);
    saveChanges.setVisible(false);
 
    cardLayout.show(mainPanel, MULTIPLE_SELECTED);
 
    displayedEntryPanel = null;
  }
 
  @Override
  public GenericDialog.ButtonType getButtonType()
  {
    return GenericDialog.ButtonType.NO_BUTTON;
  }
 
  @Override
  public LocalizableMessage getTitle()
  {
    return INFO_CTRL_PANEL_EDIT_LDAP_ENTRY_TITLE.get();
  }
 
  @Override
  public Component getPreferredFocusComponent()
  {
    return saveChanges;
  }
 
  @Override
  public void configurationChanged(ConfigurationChangeEvent ev)
  {
    final ServerDescriptor desc = ev.getNewDescriptor();
    SwingUtilities.invokeLater(new Runnable()
    {
      @Override
      public void run()
      {
        boolean isReadOnly = true;
        boolean canDelete = false;
        if (searchResult != null && desc.isAuthenticated())
        {
          isReadOnly = isReadOnly(searchResult.getDN());
          canDelete = canDelete(searchResult.getDN());
        }
 
        delete.setVisible(canDelete);
        saveChanges.setVisible(!isReadOnly);
      }
    });
  }
 
  @Override
  public void setInfo(ControlPanelInfo info)
  {
    super.setInfo(info);
    simplifiedEntryPanel.setInfo(info);
    ldifEntryPanel.setInfo(info);
    tableEntryPanel.setInfo(info);
    errorSearchingPanel.setInfo(info);
  }
 
  private List<DN> parentReadOnly;
  private List<DN> nonDeletable;
  {
    try
    {
      parentReadOnly = Arrays.asList(
        DN.valueOf(ConfigConstants.DN_TASK_ROOT),
        DN.valueOf(ConfigConstants.DN_MONITOR_ROOT),
        DN.valueOf(ConfigConstants.DN_BACKUP_ROOT),
        DN.valueOf(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT)
      );
      nonDeletable = Arrays.asList(
          DN.valueOf(ConfigConstants.DN_CONFIG_ROOT),
          DN.valueOf(ConfigConstants.DN_DEFAULT_SCHEMA_ROOT),
          DN.valueOf(ConfigConstants.DN_TRUST_STORE_ROOT)
      );
    }
    catch (Throwable t)
    {
      throw new RuntimeException("Error decoding DNs: "+t, t);
    }
  }
 
  /**
   * Returns <CODE>true</CODE> if the provided DN corresponds to a read-only
   * entry and <CODE>false</CODE> otherwise.
   * @param sDn the DN of the entry.
   * @return <CODE>true</CODE> if the provided DN corresponds to a read-only
   * entry and <CODE>false</CODE> otherwise.
   */
  public boolean isReadOnly(String sDn)
  {
    boolean isReadOnly = false;
    try
    {
      DN dn = DN.valueOf(sDn);
      for (DN parentDN : parentReadOnly)
      {
        if (dn.isSubordinateOrEqualTo(parentDN))
        {
          isReadOnly = true;
          break;
        }
      }
      if (!isReadOnly)
      {
        isReadOnly = dn.equals(DN.rootDN());
      }
    }
    catch (Throwable t)
    {
      throw new RuntimeException("Error decoding DNs: "+t, t);
    }
    return isReadOnly;
  }
 
  /**
   * Returns <CODE>true</CODE> if the provided DN corresponds to an entry that
   * can be deleted and <CODE>false</CODE> otherwise.
   * @param sDn the DN of the entry.
   * @return <CODE>true</CODE> if the provided DN corresponds to an entry that
   * can be deleted and <CODE>false</CODE> otherwise.
   */
  public boolean canDelete(String sDn)
  {
    try
    {
      DN dn = DN.valueOf(sDn);
      return !dn.equals(DN.rootDN())
          && !nonDeletable.contains(dn)
          && isDescendantOfAny(dn, parentReadOnly);
    }
    catch (Throwable t)
    {
      throw new RuntimeException("Error decoding DNs: "+t, t);
    }
  }
 
  private boolean isDescendantOfAny(DN dn, List<DN> parentDNs)
  {
    for (DN parentDN : parentDNs)
    {
      if (dn.isSubordinateOrEqualTo(parentDN))
      {
        return false;
      }
    }
    return true;
  }
 
  /**
   * Saves the changes done to the entry.
   * @param modal whether the progress dialog for the task must be modal or
   * not.
   */
  private void saveChanges(boolean modal)
  {
    newTask = null;
    final ArrayList<LocalizableMessage> errors = new ArrayList<>();
    // Check that the entry is correct.
    try
    {
      ProgressDialog dlg = new ProgressDialog(
          Utilities.getFrame(this),
          Utilities.getFrame(this),
          INFO_CTRL_PANEL_MODIFYING_ENTRY_CHANGES_TITLE.get(), getInfo());
      dlg.setModal(modal);
      Entry entry = displayedEntryPanel.getEntry();
      newTask = new ModifyEntryTask(getInfo(), dlg, entry,
            searchResult, controller, treePath);
      for (Task task : getInfo().getTasks())
      {
        task.canLaunch(newTask, errors);
      }
 
      if (errors.isEmpty())
      {
        if (newTask.hasModifications()) {
          String dn = entry.getName().toString();
          launchOperation(newTask,
              INFO_CTRL_PANEL_MODIFYING_ENTRY_SUMMARY.get(dn),
              INFO_CTRL_PANEL_MODIFYING_ENTRY_COMPLETE.get(),
              INFO_CTRL_PANEL_MODIFYING_ENTRY_SUCCESSFUL.get(dn),
              ERR_CTRL_PANEL_MODIFYING_ENTRY_ERROR_SUMMARY.get(),
              ERR_CTRL_PANEL_MODIFYING_ENTRY_ERROR_DETAILS.get(dn),
              null,
              dlg);
          saveChanges.setEnabled(false);
          dlg.setVisible(true);
        }
        else
        {
          // Mark the panel as it has no changes.  This can happen because every
          // time the user types something the saveChanges button is enabled
          // (for performance reasons with huge entries).
          saveChanges.setEnabled(false);
        }
      }
    }
    catch (OpenDsException ode)
    {
      errors.add(ERR_CTRL_PANEL_INVALID_ENTRY.get(ode.getMessageObject()));
    }
    if (!errors.isEmpty())
    {
      displayErrorDialog(errors);
    }
  }
 
  private void deleteEntry()
  {
    final ArrayList<LocalizableMessage> errors = new ArrayList<>();
    // Check that the entry is correct.
    // Rely in numsubordinates and hassubordinates
    boolean isLeaf = !BrowserController.getHasSubOrdinates(searchResult);
 
    if (treePath != null)
    {
      LocalizableMessage title = isLeaf ? INFO_CTRL_PANEL_DELETING_ENTRY_TITLE.get() :
        INFO_CTRL_PANEL_DELETING_SUBTREE_TITLE.get();
      ProgressDialog dlg = new ProgressDialog(
          Utilities.createFrame(),
          Utilities.getParentDialog(this), title, getInfo());
      DeleteEntryTask newTask = new DeleteEntryTask(getInfo(), dlg,
          new TreePath[]{treePath}, controller);
      for (Task task : getInfo().getTasks())
      {
        task.canLaunch(newTask, errors);
      }
      if (errors.isEmpty())
      {
        LocalizableMessage confirmationMessage =
          isLeaf ? INFO_CTRL_PANEL_DELETE_ENTRY_CONFIRMATION_DETAILS.get(
              searchResult.getDN()) :
                INFO_CTRL_PANEL_DELETE_SUBTREE_CONFIRMATION_DETAILS.get(
                    searchResult.getDN());
          if (displayConfirmationDialog(
              INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(),
              confirmationMessage))
          {
            String dn = searchResult.getDN();
            if (isLeaf)
            {
              launchOperation(newTask,
                  INFO_CTRL_PANEL_DELETING_ENTRY_SUMMARY.get(dn),
                  INFO_CTRL_PANEL_DELETING_ENTRY_COMPLETE.get(),
                  INFO_CTRL_PANEL_DELETING_ENTRY_SUCCESSFUL.get(dn),
                  ERR_CTRL_PANEL_DELETING_ENTRY_ERROR_SUMMARY.get(),
                  ERR_CTRL_PANEL_DELETING_ENTRY_ERROR_DETAILS.get(dn),
                  null,
                  dlg);
            }
            else
            {
              launchOperation(newTask,
                  INFO_CTRL_PANEL_DELETING_SUBTREE_SUMMARY.get(dn),
                  INFO_CTRL_PANEL_DELETING_SUBTREE_COMPLETE.get(),
                  INFO_CTRL_PANEL_DELETING_SUBTREE_SUCCESSFUL.get(dn),
                  ERR_CTRL_PANEL_DELETING_SUBTREE_ERROR_SUMMARY.get(),
                  ERR_CTRL_PANEL_DELETING_SUBTREE_ERROR_DETAILS.get(dn),
                  null,
                  dlg);
            }
            dlg.setVisible(true);
          }
      }
    }
    if (!errors.isEmpty())
    {
      displayErrorDialog(errors);
    }
  }
 
  /**
   * Returns the browser controller in charge of the tree.
   * @return the browser controller in charge of the tree.
   */
  public BrowserController getController()
  {
    return controller;
  }
 
  /**
   * Sets the browser controller in charge of the tree.
   * @param controller the browser controller in charge of the tree.
   */
  public void setController(BrowserController controller)
  {
    this.controller = controller;
  }
 
  /**
   * Returns the tree path associated with the node that is being displayed.
   * @return the tree path associated with the node that is being displayed.
   */
  public TreePath getTreePath()
  {
    return treePath;
  }
 
  /**
   * Sets the tree path associated with the node that is being displayed.
   * @param treePath the tree path associated with the node that is being
   * displayed.
   */
  public void setTreePath(TreePath treePath)
  {
    this.treePath = treePath;
  }
 
  /**
   * Method used to know if there are unsaved changes or not.  It is used by
   * the entry selection listener when the user changes the selection.
   * @return <CODE>true</CODE> if there are unsaved changes (and so the
   * selection of the entry should be cancelled) and <CODE>false</CODE>
   * otherwise.
   */
  public boolean mustCheckUnsavedChanges()
  {
    return displayedEntryPanel != null &&
        saveChanges.isVisible() && saveChanges.isEnabled();
  }
 
  /**
   * Tells whether the user chose to save the changes in the panel, to not save
   * them or simply canceled the selection change in the tree.
   * @return the value telling whether the user chose to save the changes in the
   * panel, to not save them or simply canceled the selection in the tree.
   */
  public UnsavedChangesDialog.Result checkUnsavedChanges()
  {
    UnsavedChangesDialog.Result result;
    UnsavedChangesDialog unsavedChangesDlg = new UnsavedChangesDialog(
          Utilities.getParentDialog(this), getInfo());
    unsavedChangesDlg.setMessage(INFO_CTRL_PANEL_UNSAVED_CHANGES_SUMMARY.get(),
       INFO_CTRL_PANEL_UNSAVED_ENTRY_CHANGES_DETAILS.get(searchResult.getDN()));
    Utilities.centerGoldenMean(unsavedChangesDlg,
          Utilities.getParentDialog(this));
    unsavedChangesDlg.setVisible(true);
    result = unsavedChangesDlg.getResult();
    if (result == UnsavedChangesDialog.Result.SAVE)
    {
      saveChanges(false);
      if (newTask == null || // The user data is not valid
          newTask.getState() != Task.State.FINISHED_SUCCESSFULLY)
      {
        result = UnsavedChangesDialog.Result.CANCEL;
      }
    }
 
    return result;
  }
}