Coverage Report - org.xmlhammer.gui.util.UndoableComboBoxEdit
 
Classes in this File Line Coverage Branch Coverage Complexity
UndoableComboBoxEdit
51% 
33% 
2
 
 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 javax.swing.JComboBox;
 24  
 import javax.swing.undo.AbstractUndoableEdit;
 25  
 
 26  
 import org.xmlhammer.gui.Page;
 27  
 import org.xmlhammer.gui.history.HistoryComboBox;
 28  
 
 29  
 public class UndoableComboBoxEdit extends AbstractUndoableEdit {
 30  
     private static final long serialVersionUID = 8615885869967750791L;
 31  
 
 32  10604
     private Object current = null;
 33  10604
     private Object previous = null;
 34  10604
     private Page page = null;
 35  10604
     private JComboBox combo = null;
 36  
     
 37  
     public UndoableComboBoxEdit(Page page, JComboBox combo, Object current, Object previous) {
 38  10604
         super();
 39  
         
 40  10604
         this.page = page;
 41  10604
         this.combo = combo;
 42  10604
         this.current = current;
 43  10604
         this.previous = previous;
 44  10604
     }
 45  
 
 46  
     public void undo() {
 47  0
         super.undo();
 48  
 
 49  0
         page.getProjectView().getOverviewPanel().selectNode(page);
 50  0
         combo.requestFocusInWindow();
 51  0
         combo.setSelectedItem(previous);
 52  
 
 53  0
         if (combo.isEditable() && previous != null) {
 54  0
             combo.getEditor().setItem(previous);
 55  0
         } else if (previous == null && combo instanceof HistoryComboBox) {
 56  0
             combo.getEditor().setItem(((HistoryComboBox)combo).getEmptyValue());
 57  
         }
 58  0
     }
 59  
 
 60  
     public void redo() {
 61  0
         super.redo();
 62  
 
 63  0
         page.getProjectView().getOverviewPanel().selectNode(page);
 64  0
         combo.requestFocusInWindow();
 65  0
         combo.setSelectedItem(current);
 66  
 
 67  0
         if (combo.isEditable() && current != null) {
 68  0
             combo.getEditor().setItem(current);
 69  0
         } else if (current == null && combo instanceof HistoryComboBox) {
 70  0
             combo.getEditor().setItem(((HistoryComboBox)combo).getEmptyValue());
 71  
         }
 72  0
     }
 73  
     
 74  
     public String getUndoPresentationName() {
 75  0
         return "Set "+previous.toString();
 76  
     }
 77  
 
 78  
     public String getRedoPresentationName() {
 79  0
         return "Reset "+current.toString();
 80  
     }
 81  
     
 82  
     public String toString() {
 83  10604
         StringBuffer buffer = new StringBuffer("ComboBoxEdit Undo ");
 84  
 
 85  10604
         if ( previous != null) {
 86  5608
             buffer.append(previous.toString());
 87  5608
         } else {
 88  4996
             buffer.append("null");
 89  
         }
 90  
         
 91  10604
         buffer.append(" Redo ");
 92  
 
 93  10604
         if ( current != null) {
 94  6338
             buffer.append(current.toString());
 95  6338
         } else {
 96  4266
             buffer.append("null");
 97  
         }
 98  
 
 99  10604
         return buffer.toString();
 100  
     }
 101  
 }