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.event.ListSelectionEvent; 19 import javax.swing.event.ListSelectionListener; 20 import javax.swing.event.TreeSelectionEvent; 21 import javax.swing.event.TreeSelectionListener; 22 23 import org.xulux.api.core.PartRequest; 24 import org.xulux.api.gui.IWidget; 25 import org.xulux.gui.GuiUtils; 26 27 /** 28 * The ImmidiateTreeSelectionListeners fires of events when 29 * a new tree selection is selected. The execute method in the rules 30 * are being called. 31 * 32 * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a> 33 * @version $Id: ImmidiateTreeSelectionListener.java,v 1.1 2005/12/18 12:58:21 mvdb Exp $ 34 */ 35 public class ImmidiateTreeSelectionListener implements ListSelectionListener, TreeSelectionListener { 36 37 /** 38 * The widget 39 */ 40 protected IWidget widget; 41 42 /** 43 * @param widget the widget 44 */ 45 public ImmidiateTreeSelectionListener(IWidget widget) { 46 this.widget = widget; 47 } 48 49 /** 50 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) 51 */ 52 public void valueChanged(ListSelectionEvent e) { 53 if (e != null) { 54 selectionChanged(); 55 } 56 } 57 58 /** 59 * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent) 60 */ 61 public void valueChanged(TreeSelectionEvent e) { 62 if (e != null) { 63 if (e.isAddedPath()) { 64 selectionChanged(); 65 } 66 } 67 } 68 69 /** 70 * Refresh the value of all widgets that are pointing this widget. 71 */ 72 public void selectionChanged() { 73 if (widget != null) { 74 // first free up the event queue 75 // we process after any other events.. 76 GuiUtils.fireFieldExecuteRule(widget, widget, PartRequest.NO_ACTION); 77 // this was there for some reason, need to figure out why this was done. 78 // SwingUtilities.invokeLater(new Runnable() { 79 // public void run() { 80 // } 81 // }); 82 } 83 } 84 85 }