1 19 20 package org.netbeans.modules.xml.multiview; 21 22 import javax.swing.*; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 26 31 public abstract class ItemComboBoxHelper implements ActionListener , Refreshable { 32 private XmlMultiViewDataSynchronizer synchronizer; 33 private JComboBox comboBox; 34 35 41 public ItemComboBoxHelper(XmlMultiViewDataSynchronizer synchronizer, JComboBox comboBox) { 42 this.synchronizer = synchronizer; 43 this.comboBox = comboBox; 44 comboBox.addActionListener(this); 45 setValue(getItemValue()); 46 } 47 48 51 public final void actionPerformed(ActionEvent e) { 52 final String value = (String ) comboBox.getSelectedItem(); 53 if (value == null || !value.equals(getItemValue())) { 54 setItemValue(value); 55 synchronizer.requestUpdateData(); 56 } 57 } 58 59 64 public void setValue(String itemValue) { 65 comboBox.setSelectedItem(itemValue); 66 } 67 68 73 public JComboBox getComboBox() { 74 return comboBox; 75 } 76 77 82 public String getValue() { 83 return (String ) comboBox.getSelectedItem(); 84 } 85 86 91 public abstract String getItemValue(); 92 93 98 public abstract void setItemValue(String value); 99 100 public void refresh() { 101 setValue(getItemValue()); 102 } 103 } 104 | Popular Tags |