1 package net.suberic.pooka.gui.filter; 2 import net.suberic.pooka.gui.search.*; 3 import net.suberic.pooka.*; 4 import net.suberic.util.gui.propedit.*; 5 import net.suberic.util.VariableBundle; 6 import javax.swing.*; 7 import java.util.Vector ; 8 9 12 public class FilterEditorPane extends LabelValuePropertyEditor implements java.awt.event.ItemListener { 13 14 JLabel label; 15 JComboBox typeCombo; 16 JPanel filterConfigPanel; 17 java.awt.CardLayout layout; 18 19 java.util.HashMap editorTable; 20 21 24 public void configureEditor(String propertyName, String template, String propertyBaseName, PropertyEditorManager newManager) { 25 configureBasic(propertyName, template, propertyBaseName, newManager); 26 27 getLogger().fine("property is " + property + "; editorTemplate is " + editorTemplate); 28 29 editorTable = new java.util.HashMap (); 30 31 label = new JLabel(manager.getProperty(editorTemplate + ".label", "Action")); 33 34 String filterType = manager.getProperty(editorTemplate + ".filterType", "display"); 36 37 Vector filterLabels = null; 39 if (filterType.equalsIgnoreCase("display")) 40 filterLabels = Pooka.getSearchManager().getDisplayFilterLabels(); 41 else 42 filterLabels = Pooka.getSearchManager().getBackendFilterLabels(); 43 44 typeCombo = new JComboBox(filterLabels); 45 typeCombo.addItemListener(this); 46 47 48 50 String currentClassValue = manager.getProperty(property + ".class", ""); 51 String selectedLabel = null; 52 53 filterConfigPanel = new JPanel(); 54 layout = new java.awt.CardLayout (); 55 filterConfigPanel.setLayout(layout); 56 for (int i = 0; i < filterLabels.size(); i++) { 57 String label = (String ) filterLabels.elementAt(i); 58 FilterEditor currentEditor = Pooka.getSearchManager().getEditorForFilterLabel(label); 59 currentEditor.configureEditor(manager, property); 60 61 filterConfigPanel.add(label, currentEditor); 62 editorTable.put(label, currentEditor); 63 64 if (selectedLabel == null && currentClassValue != null && currentClassValue.equalsIgnoreCase(currentEditor.getFilterClassValue())) 65 selectedLabel = label; 66 } 67 68 if (selectedLabel != null) 69 typeCombo.setSelectedItem(selectedLabel); 70 71 JPanel tmpPanel = new JPanel(); 72 SpringLayout layout = new SpringLayout(); 73 tmpPanel.setLayout(layout); 74 75 tmpPanel.add(typeCombo); 76 tmpPanel.add(filterConfigPanel); 77 78 layout.putConstraint(SpringLayout.NORTH, typeCombo, 0, SpringLayout.NORTH, tmpPanel); 79 layout.putConstraint(SpringLayout.WEST, typeCombo, 0, SpringLayout.WEST, tmpPanel); 80 layout.putConstraint(SpringLayout.SOUTH, tmpPanel, 0, SpringLayout.SOUTH, typeCombo); 81 layout.putConstraint(SpringLayout.WEST, filterConfigPanel, 5, SpringLayout.EAST, typeCombo); 82 layout.putConstraint(SpringLayout.EAST, tmpPanel, 5, SpringLayout.EAST, filterConfigPanel); 83 84 tmpPanel.setPreferredSize(new java.awt.Dimension (tmpPanel.getPreferredSize().width, typeCombo.getMinimumSize().height)); 85 tmpPanel.setMaximumSize(new java.awt.Dimension (Integer.MAX_VALUE, typeCombo.getMinimumSize().height)); 86 87 this.add(label); 88 this.add(tmpPanel); 89 90 labelComponent = label; 91 valueComponent = tmpPanel; 92 93 resetDefaultValue(); 94 } 95 96 99 public void setValue() throws PropertyValueVetoException { 100 validateProperty(); 101 getFilterEditor().setValue(); 102 } 103 104 107 public void validateProperty() throws PropertyValueVetoException { 108 getFilterEditor().validate(); 109 } 110 111 114 public FilterEditor getFilterEditor() { 115 return (FilterEditor) editorTable.get(typeCombo.getSelectedItem()); 116 } 117 118 121 public java.util.Properties getValue() { 122 return getFilterEditor().getValue(); 123 } 124 125 128 public void resetDefaultValue() { 129 String currentLabel = Pooka.getSearchManager().getLabelForFilterClass(manager.getProperty(property + ".class", "")); 131 if (currentLabel != null) { 132 typeCombo.setSelectedItem(currentLabel); 133 } else { 134 typeCombo.setSelectedIndex(0); 135 } 136 137 FilterEditor currentEditor = getFilterEditor(); 138 139 } 140 141 145 public void itemStateChanged(java.awt.event.ItemEvent e) { 146 String selectedString = (String ) typeCombo.getSelectedItem(); 147 148 layout.show(filterConfigPanel, selectedString); 149 } 150 151 154 protected void updateEditorEnabled() { 155 typeCombo.setEnabled(isEditorEnabled()); 156 } 157 158 } 159 | Popular Tags |