001: package net.suberic.pooka.gui.filter;
002:
003: import net.suberic.pooka.gui.search.*;
004: import net.suberic.pooka.*;
005: import net.suberic.util.gui.propedit.*;
006: import net.suberic.util.VariableBundle;
007: import javax.swing.*;
008: import java.util.Vector;
009:
010: /**
011: * This is a class that lets you choose your filter actions.
012: */
013: public class FilterEditorPane extends SwingPropertyEditor implements
014: java.awt.event.ItemListener {
015:
016: JLabel label;
017: JComboBox typeCombo;
018: JPanel filterConfigPanel;
019: java.awt.CardLayout layout;
020:
021: java.util.HashMap editorTable;
022:
023: /**
024: * Configures the FilterEditorPane.
025: */
026: public void configureEditor(String propertyName, String template,
027: PropertyEditorManager newManager, boolean isEnabled) {
028: property = propertyName;
029: manager = newManager;
030: editorTemplate = template;
031: originalValue = manager.getProperty(property, "");
032:
033: if (debug) {
034: System.out.println("property is " + property
035: + "; editorTemplate is " + editorTemplate);
036: }
037:
038: editorTable = new java.util.HashMap();
039:
040: // create the label
041: label = new JLabel(manager.getProperty(editorTemplate
042: + ".label", "Action"));
043:
044: // find out if we're a display filter or a backend filter
045: String filterType = manager.getProperty(editorTemplate
046: + ".filterType", "display");
047:
048: // create the combo
049: Vector filterLabels = null;
050: if (filterType.equalsIgnoreCase("display"))
051: filterLabels = Pooka.getSearchManager()
052: .getDisplayFilterLabels();
053: else
054: filterLabels = Pooka.getSearchManager()
055: .getBackendFilterLabels();
056:
057: typeCombo = new JComboBox(filterLabels);
058: typeCombo.addItemListener(this );
059:
060: // create the filterConfigPanel.
061:
062: String currentClassValue = manager.getProperty(property
063: + ".class", "");
064: String selectedLabel = null;
065:
066: filterConfigPanel = new JPanel();
067: layout = new java.awt.CardLayout();
068: filterConfigPanel.setLayout(layout);
069: for (int i = 0; i < filterLabels.size(); i++) {
070: String label = (String) filterLabels.elementAt(i);
071: FilterEditor currentEditor = Pooka.getSearchManager()
072: .getEditorForFilterLabel(label);
073: currentEditor.configureEditor(manager, property);
074:
075: filterConfigPanel.add(label, currentEditor);
076: editorTable.put(label, currentEditor);
077:
078: if (selectedLabel == null
079: && currentClassValue != null
080: && currentClassValue.equalsIgnoreCase(currentEditor
081: .getFilterClassValue()))
082: selectedLabel = label;
083: }
084:
085: if (selectedLabel != null)
086: typeCombo.setSelectedItem(selectedLabel);
087:
088: JPanel valuePanel = new JPanel();
089:
090: valuePanel.add(typeCombo);
091: valuePanel.add(filterConfigPanel);
092:
093: this .add(label);
094: this .add(valuePanel);
095:
096: labelComponent = label;
097: valueComponent = valuePanel;
098:
099: resetDefaultValue();
100: }
101:
102: /**
103: * Sets the value for this PropertyEditor.
104: */
105: public void setValue() {
106: getFilterEditor().setValue();
107: }
108:
109: /**
110: * Returns the currently selected FilterEditor.
111: */
112: public FilterEditor getFilterEditor() {
113: return (FilterEditor) editorTable.get(typeCombo
114: .getSelectedItem());
115: }
116:
117: /**
118: * Gets the value that would be set by this PropertyEditor.
119: */
120: public java.util.Properties getValue() {
121: return getFilterEditor().getValue();
122: }
123:
124: /**
125: * Resets the current Editor to its original value.
126: */
127: public void resetDefaultValue() {
128: // get the current value, if any
129: String currentLabel = Pooka.getSearchManager()
130: .getLabelForFilterClass(
131: manager.getProperty(property + ".class", ""));
132: if (currentLabel != null) {
133: typeCombo.setSelectedItem(currentLabel);
134: } else {
135: typeCombo.setSelectedIndex(0);
136: }
137:
138: FilterEditor currentEditor = getFilterEditor();
139:
140: }
141:
142: /**
143: * Enables or disables this editor.
144: */
145: public void setEnabled(boolean newValue) {
146: typeCombo.setEnabled(newValue);
147: }
148:
149: /**
150: * This handles the switch of the filterConfigPanel when the typeCombo
151: * value changes.
152: */
153: public void itemStateChanged(java.awt.event.ItemEvent e) {
154: String selectedString = (String) typeCombo.getSelectedItem();
155:
156: layout.show(filterConfigPanel, selectedString);
157: }
158:
159: }
|