Lines 22-27
Link Here
|
22 |
import java.lang.reflect.InvocationTargetException; |
22 |
import java.lang.reflect.InvocationTargetException; |
23 |
import java.lang.reflect.Method; |
23 |
import java.lang.reflect.Method; |
24 |
import java.util.HashMap; |
24 |
import java.util.HashMap; |
|
|
25 |
import java.util.Map; |
25 |
import org.openide.ErrorManager; |
26 |
import org.openide.ErrorManager; |
26 |
import org.openide.util.HelpCtx; |
27 |
import org.openide.util.HelpCtx; |
27 |
import org.openide.util.NbBundle; |
28 |
import org.openide.util.NbBundle; |
Lines 50-61
Link Here
|
50 |
private static final Object PROP_LOADING = new Object (); |
51 |
private static final Object PROP_LOADING = new Object (); |
51 |
/** property to indicate that the option is currently loading its data */ |
52 |
/** property to indicate that the option is currently loading its data */ |
52 |
private static final Object PROP_STORING = new Object (); |
53 |
private static final Object PROP_STORING = new Object (); |
|
|
54 |
/** property that holds a Map<String,Object> that stores old values */ |
55 |
private static final Object PROP_ORIGINAL_VALUES = new Object (); |
53 |
|
56 |
|
54 |
/** Default constructor. */ |
57 |
/** Default constructor. */ |
55 |
public SystemOption() { |
58 |
public SystemOption() { |
56 |
// SystemOption must declare this property in order to be correctly deserialized |
|
|
57 |
// by SharedClassObject.findObject function |
58 |
putProperty ("netbeans.systemoption.hack", null); // NOI18N |
59 |
} |
59 |
} |
60 |
|
60 |
|
61 |
/** Fire a property change event to all listeners. Delays |
61 |
/** Fire a property change event to all listeners. Delays |
Lines 68-73
Link Here
|
68 |
protected void firePropertyChange ( |
68 |
protected void firePropertyChange ( |
69 |
String name, Object oldValue, Object newValue |
69 |
String name, Object oldValue, Object newValue |
70 |
) { |
70 |
) { |
|
|
71 |
if (name != null && oldValue != null) { |
72 |
Map originalValues = (Map)getProperty (PROP_ORIGINAL_VALUES); |
73 |
if (originalValues == null) { |
74 |
originalValues = new HashMap (); |
75 |
putProperty (PROP_ORIGINAL_VALUES, originalValues); |
76 |
} |
77 |
if (originalValues.get (name) == null) { |
78 |
if (getProperty (name) == null) { |
79 |
// this is supposed to be setter |
80 |
originalValues.put (name, new Box (oldValue)); |
81 |
} else { |
82 |
// regular usage of putProperty (....); |
83 |
originalValues.put (name, oldValue); |
84 |
} |
85 |
} |
86 |
} |
87 |
|
71 |
if (getProperty (PROP_LOADING) != null) { |
88 |
if (getProperty (PROP_LOADING) != null) { |
72 |
// somebody is loading, assign any object different than |
89 |
// somebody is loading, assign any object different than |
73 |
// this to indicate that firing should occure |
90 |
// this to indicate that firing should occure |
Lines 78-83
Link Here
|
78 |
super.firePropertyChange (name, oldValue, newValue); |
95 |
super.firePropertyChange (name, oldValue, newValue); |
79 |
} |
96 |
} |
80 |
|
97 |
|
|
|
98 |
/** Implements the reset by setting back all properties that were |
99 |
* modified. A <em>modified property</em> has fired a |
100 |
* <code>PropertyChangeEvent</code> with |
101 |
* non-null name and non-null old value. The name and value are |
102 |
* remembered and this method sets them back to original value. |
103 |
* <p> |
104 |
* Subclasses are free to override this method and reimplement the |
105 |
* reset by themselves. |
106 |
* |
107 |
* @since 4.46 |
108 |
*/ |
109 |
protected void reset () { |
110 |
synchronized (getLock ()) { |
111 |
Map m = (Map)getProperty (PROP_ORIGINAL_VALUES); |
112 |
if (m == null || m.isEmpty ()) return; |
113 |
|
114 |
java.util.Iterator it = m.entrySet ().iterator (); |
115 |
WHILE: while (it.hasNext ()) { |
116 |
Map.Entry e = (Map.Entry)it.next (); |
117 |
if (e.getValue () instanceof Box) { |
118 |
Object value = ((Box)e.getValue ()).value; |
119 |
try { |
120 |
// gets info about all properties that were added by subclass |
121 |
BeanInfo info = org.openide.util.Utilities.getBeanInfo (getClass (), SystemOption.class); |
122 |
PropertyDescriptor[] desc = info.getPropertyDescriptors (); |
123 |
|
124 |
for (int i = 0; i < desc.length; i++) { |
125 |
if (e.getKey ().equals (desc[i].getName ())) { |
126 |
// our property |
127 |
Method write = desc[i].getWriteMethod (); |
128 |
if (write != null) { |
129 |
write.invoke (this, new Object[] { value }); |
130 |
} |
131 |
continue WHILE; |
132 |
} |
133 |
} |
134 |
} catch (InvocationTargetException ex) { |
135 |
// exception thrown |
136 |
ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ex); |
137 |
} catch (IllegalAccessException ex) { |
138 |
ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ex); |
139 |
} catch (IntrospectionException ex) { |
140 |
ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ex); |
141 |
} |
142 |
} else { |
143 |
putProperty (e.getKey (), e.getValue ()); |
144 |
} |
145 |
} |
146 |
// reset all remembered values |
147 |
putProperty (PROP_ORIGINAL_VALUES, null); |
148 |
} |
149 |
super.firePropertyChange (null, null, null); |
150 |
} |
151 |
|
81 |
/** Write all properties of this object (or subclasses) to an object output. |
152 |
/** Write all properties of this object (or subclasses) to an object output. |
82 |
* @param out the output stream |
153 |
* @param out the output stream |
83 |
* @exception IOException on error |
154 |
* @exception IOException on error |
Lines 328-331
Link Here
|
328 |
protected final boolean isWriteExternal () { |
399 |
protected final boolean isWriteExternal () { |
329 |
return getProperty (PROP_STORING) != null; |
400 |
return getProperty (PROP_STORING) != null; |
330 |
} |
401 |
} |
|
|
402 |
|
403 |
/** A wrapper object to indicate that a setter should be called |
404 |
* when reseting to default. |
405 |
*/ |
406 |
private static final class Box extends Object { |
407 |
public Object value; |
408 |
public Box (Object v) { |
409 |
this.value = v; |
410 |
} |
411 |
} // end of Box |
331 |
} |
412 |
} |