View Javadoc

1   /*
2    * $Id$
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  package org.xmlhammer.gui.util;
22  
23  import org.xmlhammer.gui.Page;
24  import org.xmlhammer.gui.history.HistoryComboBox;
25  
26  public class UndoableHistoryComboBoxItemListener extends UndoableComboBoxItemListener {
27      private HistoryComboBox combo = null;
28  
29      public UndoableHistoryComboBoxItemListener(Page page, HistoryComboBox combo) {
30          super(page, combo);
31  
32          this.combo = combo;
33      }
34  
35      protected boolean equals(Object item1, Object item2) {
36          if (item1 != item2) {
37              if (item1 == null && (item2 != null && item2.toString().length() == 0)) {
38                  return true;
39              }
40              
41              if (item2 == null && (item1 != null && item1.toString().length() == 0)) {
42                  return true;
43              }
44  
45              if ((item1 != null && item1.equals(combo.getEmptyValue())) && (item2 == null || item2.toString().length() == 0)) {
46                  return true;
47              } else if ((item2 != null && item2.equals(combo.getEmptyValue())) && (item1 == null || item1.toString().length() == 0)) {
48                  return true;
49              }
50              
51              if (item1 == null || item2 == null) {
52                  return false;
53              }
54              
55              return item1.toString().equals(item2.toString());
56          }
57  
58          return true;
59      }
60  }