001: package net.suberic.pooka.gui.search;
002:
003: import net.suberic.util.VariableBundle;
004: import net.suberic.util.gui.propedit.*;
005: import javax.swing.*;
006: import java.util.*;
007:
008: /**
009: * This is a class which lets you choose SearchTerms as properties.
010: */
011: public class SearchEditorPane extends SwingPropertyEditor {
012:
013: Properties originalProperties;
014:
015: SearchEntryPanel searchEntryPanel;
016:
017: /**
018: * @param propertyName The property to be edited.
019: * @param template The property that will define the layout of the
020: * editor.
021: * @param manager The PropertyEditorManager that will manage the
022: * changes.
023: * @param isEnabled Whether or not this editor is enabled by default.
024: */
025: public void configureEditor(String propertyName, String template,
026: PropertyEditorManager newManager, boolean isEnabled) {
027: property = propertyName;
028: manager = newManager;
029: editorTemplate = template;
030: originalValue = manager.getProperty(property, "");
031:
032: searchEntryPanel = new SearchEntryPanel(net.suberic.pooka.Pooka
033: .getSearchManager(), property, manager.getFactory()
034: .getSourceBundle());
035: originalProperties = searchEntryPanel
036: .generateSearchTermProperties(property);
037:
038: //this.add(searchEntryPanel);
039: labelComponent = new JLabel(manager.getProperty(
040: "title.search.where", "Where"));
041: valueComponent = searchEntryPanel;
042:
043: this .setEnabled(isEnabled);
044: }
045:
046: /**
047: * Sets the value for this PropertyEditor.
048: */
049: public void setValue() {
050: // we need to go through all of the new properties any only set
051: // the ones that have changed. we also need to remove any that
052: // no longer exist.
053: Properties newValues = searchEntryPanel
054: .generateSearchTermProperties(property);
055: Enumeration newKeys = newValues.keys();
056:
057: Set originalKeys = originalProperties.keySet();
058:
059: while (newKeys.hasMoreElements()) {
060: Object currentKey = newKeys.nextElement();
061: if (originalKeys.contains(currentKey)) {
062: originalKeys.remove(currentKey);
063: String originalValue = originalProperties
064: .getProperty((String) currentKey);
065: String newValue = newValues
066: .getProperty((String) currentKey);
067: if (originalValue == null
068: || !originalValue.equals(newValue))
069: manager.setProperty((String) currentKey, newValue);
070: } else {
071: manager.setProperty((String) currentKey, newValues
072: .getProperty((String) currentKey));
073: }
074: }
075:
076: Iterator iter = originalKeys.iterator();
077: while (iter.hasNext()) {
078: manager.removeProperty((String) iter.next());
079: }
080: }
081:
082: /**
083: * Returns the values that would be set by this SearchEditorPane.
084: */
085: public Properties getValue() {
086: return searchEntryPanel.generateSearchTermProperties(property);
087: }
088:
089: /**
090: * Resets the current Editor to its original value.
091: */
092: public void resetDefaultValue() {
093: searchEntryPanel.setSearchTerm(property, manager.getFactory()
094: .getSourceBundle());
095: }
096:
097: /**
098: * Enables or disables this editor.
099: */
100: public void setEnabled(boolean newValue) {
101: searchEntryPanel.setEnabled(newValue);
102: }
103: }
|