View Javadoc

1   /*
2      Copyright 2002-2006 Martin van den Bemt
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15  */
16  package org.xulux.guilayer.swing.listeners;
17  
18  import javax.swing.JTable;
19  
20  import org.xulux.api.gui.IWidget;
21  import org.xulux.api.gui.XuluxEvent;
22  import org.xulux.gui.XuluxListener;
23  import org.xulux.gui.events.XuluxValueChangedEvent;
24  import org.xulux.gui.utils.XuluxEventQueue;
25  import org.xulux.guilayer.swing.widgets.Table;
26  
27  /**
28   *
29   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
30   * @version $Id: ValueChangedListener.java,v 1.1 2005/12/18 12:58:21 mvdb Exp $
31   */
32  public class ValueChangedListener extends XuluxListener {
33  
34      /**
35       * Is the changelistener processing ?
36       */
37      private boolean isProcessing = false;
38      /**
39       *
40       */
41      public ValueChangedListener() {
42          super();
43      }
44  
45      /**
46       * @param widget the widget
47       */
48      public ValueChangedListener(IWidget widget) {
49          super(widget);
50      }
51  
52      /**
53       * @see org.xulux.nyx.gui.XuluxListener#processEvent(org.xulux.nyx.gui.XuluxEvent)
54       */
55      public void processEvent(XuluxEvent event) {
56          if (isProcessing) {
57              isProcessing = false;
58              return;
59          }
60          isProcessing = true;
61          if (event instanceof XuluxValueChangedEvent) {
62              // free the event queue..
63              XuluxEventQueue.getInstance().holdEvents(false);
64              Object value = ((XuluxValueChangedEvent) event).getValue();
65              JTable table = (JTable) ((Table) widget).getJTable();
66              if (table.isEditing()) {
67                  //                System.out.println("setting value in changelistener: "+value.getClass());
68                  table.getModel().setValueAt(value, table.getEditingRow(), table.getEditingColumn());
69              }
70              //widget.refresh();
71          }
72          isProcessing = false;
73      }
74  
75  }