1 19 package org.netbeans.modules.xml.catalog; 20 21 import java.beans.*; 22 import java.net.*; 23 import java.util.*; 24 25 import javax.swing.*; 26 import javax.swing.event.*; 27 28 import org.openide.util.Utilities; 29 30 import org.netbeans.modules.xml.catalog.spi.*; 31 32 40 final class CatalogMounterModel extends Object { 41 42 private Object catalog = null; 44 private ComboBoxModel cxModel = null; 46 private List changeListeners = new ArrayList(2); 47 48 49 50 public CatalogMounterModel(Iterator providers) { 51 52 Vector providersList = new Vector(); 53 while (providers.hasNext()) { 54 providersList.add(new Entry((Class )providers.next())); 55 } 56 57 cxModel = new DefaultComboBoxModel(providersList); 58 cxModel.addListDataListener(new Lis()); 59 initCatalog(); 60 } 61 62 66 public Object getCatalog() { 67 return catalog; 68 } 69 70 75 public Customizer getCatalogCustomizer() { 76 if (catalog == null) return null; 77 return org.netbeans.modules.xml.catalog.lib.Util.getProviderCustomizer(catalog.getClass()); 78 } 79 80 84 public ComboBoxModel getCatalogComboBoxModel() { 85 return cxModel; 86 } 87 88 91 public void addChangeListener(ChangeListener l) { 92 changeListeners.add(l); 93 } 94 95 96 public void removeChangeListener(ChangeListener l) { 97 changeListeners.remove(l); 98 } 99 100 102 private Entry getSelectedEntry() { 103 return (Entry) cxModel.getSelectedItem(); 104 } 105 106 107 private void initCatalog() { 108 109 Entry entry = getSelectedEntry(); 110 if (entry == null) { 111 catalog = null; 112 } else { 113 catalog = org.netbeans.modules.xml.catalog.lib.Util.createProvider(entry.src); 114 } 115 116 fireStateChanged(); 117 } 118 119 private void fireStateChanged() { 120 121 for (Iterator it = changeListeners.iterator(); it.hasNext();) { 122 ChangeListener next = (ChangeListener) it.next(); 123 next.stateChanged(new ChangeEvent(this)); 124 } 125 } 126 127 130 private class Entry { 131 132 String name = null; 133 Class src; 134 135 public Entry(Class src) { 136 this.src = src; 137 try { 138 name = Utilities.getBeanInfo(src).getBeanDescriptor().getDisplayName(); 139 } catch (IntrospectionException ex) { 140 name = src.toString(); 141 } 142 } 143 144 public String toString() { 145 return name; 146 } 147 } 148 149 150 155 private class Lis implements ListDataListener { 156 157 public void contentsChanged(ListDataEvent e) { 158 initCatalog(); 159 } 160 161 public void intervalAdded(ListDataEvent e) { 162 initCatalog(); 163 } 164 165 public void intervalRemoved(ListDataEvent e) { 166 initCatalog(); 167 } 168 } 169 } 170 | Popular Tags |