KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > search > SearchEditorPane


1 package net.suberic.pooka.gui.search;
2 import net.suberic.util.VariableBundle;
3 import net.suberic.util.gui.propedit.*;
4 import javax.swing.*;
5 import java.util.*;
6
7 /**
8  * This is a class which lets you choose SearchTerms as properties.
9  */

10 public class SearchEditorPane extends LabelValuePropertyEditor {
11
12   Properties originalProperties;
13
14   SearchEntryPanel searchEntryPanel;
15
16   /**
17    * @param propertyName The property to be edited.
18    * @param template The property that will define the layout of the
19    * editor.
20    * @param manager The PropertyEditorManager that will manage the
21    * changes.
22    */

23   public void configureEditor(String JavaDoc propertyName, String JavaDoc template, String JavaDoc propertyBaseName, PropertyEditorManager newManager) {
24     configureBasic(propertyName, template, propertyBaseName, newManager);
25
26     searchEntryPanel = new SearchEntryPanel(net.suberic.pooka.Pooka.getSearchManager(), property, manager.getFactory().getSourceBundle());
27     originalProperties = searchEntryPanel.generateSearchTermProperties(property);
28
29     //this.add(searchEntryPanel);
30
labelComponent = new JLabel(manager.getProperty("title.search.where", "Where"));
31     valueComponent = searchEntryPanel;
32
33     updateEditorEnabled();
34   }
35
36   /**
37    * Sets the value for this PropertyEditor.
38    */

39   public void setValue() throws PropertyValueVetoException {
40     // we need to go through all of the new properties any only set
41
// the ones that have changed. we also need to remove any that
42
// no longer exist.
43
Properties newValues = searchEntryPanel.generateSearchTermProperties(property);
44     Enumeration newKeys = newValues.keys();
45
46     Set originalKeys = originalProperties.keySet();
47
48     while (newKeys.hasMoreElements()) {
49       Object JavaDoc currentKey = newKeys.nextElement();
50       if (originalKeys.contains(currentKey)) {
51         originalKeys.remove(currentKey);
52         String JavaDoc originalValue = originalProperties.getProperty((String JavaDoc) currentKey);
53         String JavaDoc newValue = newValues.getProperty((String JavaDoc) currentKey);
54         if (originalValue == null || ! originalValue.equals(newValue))
55           manager.setProperty((String JavaDoc) currentKey, newValue);
56       } else {
57         manager.setProperty((String JavaDoc) currentKey, newValues.getProperty((String JavaDoc) currentKey));
58       }
59     }
60
61     Iterator iter = originalKeys.iterator();
62     while (iter.hasNext()) {
63       manager.removeProperty((String JavaDoc) iter.next());
64     }
65   }
66
67   public void validateProperty() throws PropertyValueVetoException {
68
69   }
70
71   /**
72    * Returns the values that would be set by this SearchEditorPane.
73    */

74   public Properties getValue() {
75     return searchEntryPanel.generateSearchTermProperties(property);
76   }
77
78   /**
79    * Resets the current Editor to its original value.
80    */

81   public void resetDefaultValue() {
82     searchEntryPanel.setSearchTerm(property, manager.getFactory().getSourceBundle());
83   }
84
85   /**
86    * Run when the PropertyEditor may have changed enabled states.
87    */

88   protected void updateEditorEnabled() {
89     searchEntryPanel.setEnabled(isEditorEnabled());
90   }
91 }
92
Popular Tags