/com.mkalugin.pikachu.core/src/com/mkalugin/pikachu/core/preference/IPreferenceStore.java

https://github.com/andreyvit/yoursway-taskus · Java · 571 lines · 44 code · 41 blank · 486 comment · 0 complexity · 97627903b2882948120c311c5ed4b14f MD5 · raw file

  1. package com.mkalugin.pikachu.core.preference;
  2. /**
  3. * The <code>IPreferenceStore</code> interface represents a table mapping
  4. * named preferences to values. If there is no value for a given name,
  5. * then that preferences's default value is returned; and if there is no
  6. * default value for that preference, then a default-default value is returned.
  7. * The default-default values for the primitive types are as follows:
  8. * <ul>
  9. * <li><code>boolean</code> = <code>false</code></li>
  10. * <li><code>double</code> = <code>0.0</code></li>
  11. * <li><code>float</code> = <code>0.0f</code></li>
  12. * <li><code>int</code> = <code>0</code></li>
  13. * <li><code>long</code> = <code>0</code></li>
  14. * <li><code>String</code> = <code>""</code> (the empty string)</li>
  15. * </ul>
  16. * <p>
  17. * Thus a preference store maintains two values for each of a set of
  18. * names: a current value and a default value.
  19. * The typical usage is to establish the defaults for all known preferences
  20. * and then restore previously stored values for preferences whose values
  21. * were different from their defaults. After the current values of
  22. * the preferences have been modified, it is a simple matter to write
  23. * out only those preferences whose values are different from their defaults.
  24. * This two-tiered approach to saving and restoring preference setting
  25. * minimized the number of preferences that need to be persisted; indeed,
  26. * the normal starting state does not require storing any preferences
  27. * at all.
  28. * </p>
  29. * <p>
  30. * A property change event is reported whenever a preferences current
  31. * value actually changes (whether through <code>setValue</code>,
  32. * <code>setToDefault</code>, or other unspecified means). Note, however,
  33. * that manipulating default values (with <code>setDefault</code>)
  34. * does not cause such events to be reported.
  35. * </p>
  36. * <p>
  37. * Clients who need a preference store may implement this interface or
  38. * instantiate the standard implementation <code>PreferenceStore</code>.
  39. * </p>
  40. *
  41. * @see PreferenceStore
  42. */
  43. public interface IPreferenceStore {
  44. /**
  45. * The default-default value for boolean preferences (<code>false</code>).
  46. */
  47. public static final boolean BOOLEAN_DEFAULT_DEFAULT = false;
  48. /**
  49. * The default-default value for double preferences (<code>0.0</code>).
  50. */
  51. public static final double DOUBLE_DEFAULT_DEFAULT = 0.0;
  52. /**
  53. * The default-default value for float preferences (<code>0.0f</code>).
  54. */
  55. public static final float FLOAT_DEFAULT_DEFAULT = 0.0f;
  56. /**
  57. * The default-default value for int preferences (<code>0</code>).
  58. */
  59. public static final int INT_DEFAULT_DEFAULT = 0;
  60. /**
  61. * The default-default value for long preferences (<code>0L</code>).
  62. */
  63. public static final long LONG_DEFAULT_DEFAULT = 0L;
  64. /**
  65. * The default-default value for String preferences (<code>""</code>).
  66. */
  67. public static final String STRING_DEFAULT_DEFAULT = ""; //$NON-NLS-1$
  68. /**
  69. * The string representation used for <code>true</code> (<code>"true"</code>).
  70. */
  71. public static final String TRUE = "true"; //$NON-NLS-1$
  72. /**
  73. * The string representation used for <code>false</code> (<code>"false"</code>).
  74. */
  75. public static final String FALSE = "false"; //$NON-NLS-1$
  76. /**
  77. * <p>
  78. * Adds a property change listener to this preference store.
  79. * </p>
  80. * <p>
  81. * <b>Note</b> The types of the oldValue and newValue of the
  82. * generated PropertyChangeEvent are determined by whether
  83. * or not the typed API in IPreferenceStore was called.
  84. * If values are changed via setValue(name,type) the
  85. * values in the PropertyChangedEvent will be of that type.
  86. * If they are set using a non typed API (i.e. #setToDefault
  87. * or using the OSGI Preferences) the values will be unconverted
  88. * Strings.
  89. * </p>
  90. * <p>
  91. * A listener will be called in the same Thread
  92. * that it is invoked in. Any Thread dependant listeners (such as
  93. * those who update an SWT widget) will need to update in the
  94. * correct Thread. In the case of an SWT update you can update
  95. * using Display#syncExec(Runnable) or Display#asyncExec(Runnable).
  96. * </p>
  97. * <p>
  98. * Likewise any application that updates an IPreferenceStore
  99. * from a Thread other than the UI Thread should be aware of
  100. * any listeners that require an update in the UI Thread.
  101. * </p>
  102. *
  103. * @param listener a property change listener
  104. * @see org.eclipse.jface.util.PropertyChangeEvent
  105. * @see #setToDefault(String)
  106. * @see #setValue(String, boolean)
  107. * @see #setValue(String, double)
  108. * @see #setValue(String, float)
  109. * @see #setValue(String, int)
  110. * @see #setValue(String, long)
  111. * @see #setValue(String, String)
  112. */
  113. public void addPropertyChangeListener(IPropertyChangeListener listener);
  114. /**
  115. * Returns whether the named preference is known to this preference
  116. * store.
  117. *
  118. * @param name the name of the preference
  119. * @return <code>true</code> if either a current value or a default
  120. * value is known for the named preference, and <code>false</code> otherwise
  121. */
  122. public boolean contains(String name);
  123. /**
  124. * Fires a property change event corresponding to a change to the
  125. * current value of the preference with the given name.
  126. * <p>
  127. * This method is provided on this interface to simplify the implementation
  128. * of decorators. There is normally no need to call this method since
  129. * <code>setValue</code> and <code>setToDefault</code> report such
  130. * events in due course. Implementations should funnel all preference
  131. * changes through this method.
  132. * </p>
  133. *
  134. * @param name the name of the preference, to be used as the property
  135. * in the event object
  136. * @param oldValue the old value
  137. * @param newValue the new value
  138. */
  139. public void firePropertyChangeEvent(String name, Object oldValue,
  140. Object newValue);
  141. /**
  142. * Returns the current value of the boolean-valued preference with the
  143. * given name.
  144. * Returns the default-default value (<code>false</code>) if there
  145. * is no preference with the given name, or if the current value
  146. * cannot be treated as a boolean.
  147. *
  148. * @param name the name of the preference
  149. * @return the boolean-valued preference
  150. */
  151. public boolean getBoolean(String name);
  152. /**
  153. * Returns the default value for the boolean-valued preference
  154. * with the given name.
  155. * Returns the default-default value (<code>false</code>) if there
  156. * is no default preference with the given name, or if the default
  157. * value cannot be treated as a boolean.
  158. *
  159. * @param name the name of the preference
  160. * @return the default value of the named preference
  161. */
  162. public boolean getDefaultBoolean(String name);
  163. /**
  164. * Returns the default value for the double-valued preference
  165. * with the given name.
  166. * Returns the default-default value (<code>0.0</code>) if there
  167. * is no default preference with the given name, or if the default
  168. * value cannot be treated as a double.
  169. *
  170. * @param name the name of the preference
  171. * @return the default value of the named preference
  172. */
  173. public double getDefaultDouble(String name);
  174. /**
  175. * Returns the default value for the float-valued preference
  176. * with the given name.
  177. * Returns the default-default value (<code>0.0f</code>) if there
  178. * is no default preference with the given name, or if the default
  179. * value cannot be treated as a float.
  180. *
  181. * @param name the name of the preference
  182. * @return the default value of the named preference
  183. */
  184. public float getDefaultFloat(String name);
  185. /**
  186. * Returns the default value for the integer-valued preference
  187. * with the given name.
  188. * Returns the default-default value (<code>0</code>) if there
  189. * is no default preference with the given name, or if the default
  190. * value cannot be treated as an integer.
  191. *
  192. * @param name the name of the preference
  193. * @return the default value of the named preference
  194. */
  195. public int getDefaultInt(String name);
  196. /**
  197. * Returns the default value for the long-valued preference
  198. * with the given name.
  199. * Returns the default-default value (<code>0L</code>) if there
  200. * is no default preference with the given name, or if the default
  201. * value cannot be treated as a long.
  202. *
  203. * @param name the name of the preference
  204. * @return the default value of the named preference
  205. */
  206. public long getDefaultLong(String name);
  207. /**
  208. * Returns the default value for the string-valued preference
  209. * with the given name.
  210. * Returns the default-default value (the empty string <code>""</code>)
  211. * is no default preference with the given name, or if the default
  212. * value cannot be treated as a string.
  213. *
  214. * @param name the name of the preference
  215. * @return the default value of the named preference
  216. */
  217. public String getDefaultString(String name);
  218. /**
  219. * Returns the current value of the double-valued preference with the
  220. * given name.
  221. * Returns the default-default value (<code>0.0</code>) if there
  222. * is no preference with the given name, or if the current value
  223. * cannot be treated as a double.
  224. *
  225. * @param name the name of the preference
  226. * @return the double-valued preference
  227. */
  228. public double getDouble(String name);
  229. /**
  230. * Returns the current value of the float-valued preference with the
  231. * given name.
  232. * Returns the default-default value (<code>0.0f</code>) if there
  233. * is no preference with the given name, or if the current value
  234. * cannot be treated as a float.
  235. *
  236. * @param name the name of the preference
  237. * @return the float-valued preference
  238. */
  239. public float getFloat(String name);
  240. /**
  241. * Returns the current value of the integer-valued preference with the
  242. * given name.
  243. * Returns the default-default value (<code>0</code>) if there
  244. * is no preference with the given name, or if the current value
  245. * cannot be treated as an integter.
  246. *
  247. * @param name the name of the preference
  248. * @return the int-valued preference
  249. */
  250. public int getInt(String name);
  251. /**
  252. * Returns the current value of the long-valued preference with the
  253. * given name.
  254. * Returns the default-default value (<code>0L</code>) if there
  255. * is no preference with the given name, or if the current value
  256. * cannot be treated as a long.
  257. *
  258. * @param name the name of the preference
  259. * @return the long-valued preference
  260. */
  261. public long getLong(String name);
  262. /**
  263. * Returns the current value of the string-valued preference with the
  264. * given name.
  265. * Returns the default-default value (the empty string <code>""</code>)
  266. * if there is no preference with the given name, or if the current value
  267. * cannot be treated as a string.
  268. *
  269. * @param name the name of the preference
  270. * @return the string-valued preference
  271. */
  272. public String getString(String name);
  273. /**
  274. * Returns whether the current value of the preference with the given name
  275. * has the default value.
  276. *
  277. * @param name the name of the preference
  278. * @return <code>true</code> if the preference has a known default value
  279. * and its current value is the same, and <code>false</code> otherwise
  280. * (including the case where the preference is unknown to this store)
  281. */
  282. public boolean isDefault(String name);
  283. /**
  284. * Returns whether the current values in this property store
  285. * require saving.
  286. *
  287. * @return <code>true</code> if at least one of values of
  288. * the preferences known to this store has changed and
  289. * requires saving, and <code>false</code> otherwise.
  290. */
  291. public boolean needsSaving();
  292. /**
  293. * Sets the current value of the preference with the given name to
  294. * the given string value without sending a property change.
  295. * <p>
  296. * This method does not fire a property change event and
  297. * should only be used for setting internal preferences
  298. * that are not meant to be processed by listeners.
  299. * Normal clients should instead call #setValue.
  300. * </p>
  301. *
  302. * @param name the name of the preference
  303. * @param value the new current value of the preference
  304. */
  305. public void putValue(String name, String value);
  306. /**
  307. * Removes the given listener from this preference store.
  308. * Has no affect if the listener is not registered.
  309. *
  310. * @param listener a property change listener
  311. */
  312. public void removePropertyChangeListener(IPropertyChangeListener listener);
  313. /**
  314. * Sets the default value for the double-valued preference with the
  315. * given name.
  316. * <p>
  317. * Note that the current value of the preference is affected if
  318. * the preference's current value was its old default value, in which
  319. * case it changes to the new default value. If the preference's current
  320. * is different from its old default value, its current value is
  321. * unaffected. No property change events are reported by changing default
  322. * values.
  323. * </p>
  324. *
  325. * @param name the name of the preference
  326. * @param value the new default value for the preference
  327. */
  328. public void setDefault(String name, double value);
  329. /**
  330. * Sets the default value for the float-valued preference with the
  331. * given name.
  332. * <p>
  333. * Note that the current value of the preference is affected if
  334. * the preference's current value was its old default value, in which
  335. * case it changes to the new default value. If the preference's current
  336. * is different from its old default value, its current value is
  337. * unaffected. No property change events are reported by changing default
  338. * values.
  339. * </p>
  340. *
  341. * @param name the name of the preference
  342. * @param value the new default value for the preference
  343. */
  344. public void setDefault(String name, float value);
  345. /**
  346. * Sets the default value for the integer-valued preference with the
  347. * given name.
  348. * <p>
  349. * Note that the current value of the preference is affected if
  350. * the preference's current value was its old default value, in which
  351. * case it changes to the new default value. If the preference's current
  352. * is different from its old default value, its current value is
  353. * unaffected. No property change events are reported by changing default
  354. * values.
  355. * </p>
  356. *
  357. * @param name the name of the preference
  358. * @param value the new default value for the preference
  359. */
  360. public void setDefault(String name, int value);
  361. /**
  362. * Sets the default value for the long-valued preference with the
  363. * given name.
  364. * <p>
  365. * Note that the current value of the preference is affected if
  366. * the preference's current value was its old default value, in which
  367. * case it changes to the new default value. If the preference's current
  368. * is different from its old default value, its current value is
  369. * unaffected. No property change events are reported by changing default
  370. * values.
  371. * </p>
  372. *
  373. * @param name the name of the preference
  374. * @param value the new default value for the preference
  375. */
  376. public void setDefault(String name, long value);
  377. /**
  378. * Sets the default value for the string-valued preference with the
  379. * given name.
  380. * <p>
  381. * Note that the current value of the preference is affected if
  382. * the preference's current value was its old default value, in which
  383. * case it changes to the new default value. If the preference's current
  384. * is different from its old default value, its current value is
  385. * unaffected. No property change events are reported by changing default
  386. * values.
  387. * </p>
  388. *
  389. * @param name the name of the preference
  390. * @param defaultObject the new default value for the preference
  391. */
  392. public void setDefault(String name, String defaultObject);
  393. /**
  394. * Sets the default value for the boolean-valued preference with the
  395. * given name.
  396. * <p>
  397. * Note that the current value of the preference is affected if
  398. * the preference's current value was its old default value, in which
  399. * case it changes to the new default value. If the preference's current
  400. * is different from its old default value, its current value is
  401. * unaffected. No property change events are reported by changing default
  402. * values.
  403. * </p>
  404. *
  405. * @param name the name of the preference
  406. * @param value the new default value for the preference
  407. */
  408. public void setDefault(String name, boolean value);
  409. /**
  410. * Sets the current value of the preference with the given name back
  411. * to its default value.
  412. * <p>
  413. * Note that the preferred way of re-initializing a preference to the
  414. * appropriate default value is to call <code>setToDefault</code>.
  415. * This is implemented by removing the named value from the store,
  416. * thereby exposing the default value.
  417. * </p>
  418. *
  419. * @param name the name of the preference
  420. */
  421. public void setToDefault(String name);
  422. /**
  423. * Sets the current value of the double-valued preference with the
  424. * given name.
  425. * <p>
  426. * A property change event is reported if the current value of the
  427. * preference actually changes from its previous value. In the event
  428. * object, the property name is the name of the preference, and the
  429. * old and new values are wrapped as objects.
  430. * </p>
  431. * <p>
  432. * Note that the preferred way of re-initializing a preference to its
  433. * default value is to call <code>setToDefault</code>.
  434. * </p>
  435. *
  436. * @param name the name of the preference
  437. * @param value the new current value of the preference
  438. */
  439. public void setValue(String name, double value);
  440. /**
  441. * Sets the current value of the float-valued preference with the
  442. * given name.
  443. * <p>
  444. * A property change event is reported if the current value of the
  445. * preference actually changes from its previous value. In the event
  446. * object, the property name is the name of the preference, and the
  447. * old and new values are wrapped as objects.
  448. * </p>
  449. * <p>
  450. * Note that the preferred way of re-initializing a preference to its
  451. * default value is to call <code>setToDefault</code>.
  452. * </p>
  453. *
  454. * @param name the name of the preference
  455. * @param value the new current value of the preference
  456. */
  457. public void setValue(String name, float value);
  458. /**
  459. * Sets the current value of the integer-valued preference with the
  460. * given name.
  461. * <p>
  462. * A property change event is reported if the current value of the
  463. * preference actually changes from its previous value. In the event
  464. * object, the property name is the name of the preference, and the
  465. * old and new values are wrapped as objects.
  466. * </p>
  467. * <p>
  468. * Note that the preferred way of re-initializing a preference to its
  469. * default value is to call <code>setToDefault</code>.
  470. * </p>
  471. *
  472. * @param name the name of the preference
  473. * @param value the new current value of the preference
  474. */
  475. public void setValue(String name, int value);
  476. /**
  477. * Sets the current value of the long-valued preference with the
  478. * given name.
  479. * <p>
  480. * A property change event is reported if the current value of the
  481. * preference actually changes from its previous value. In the event
  482. * object, the property name is the name of the preference, and the
  483. * old and new values are wrapped as objects.
  484. * </p>
  485. * <p>
  486. * Note that the preferred way of re-initializing a preference to its
  487. * default value is to call <code>setToDefault</code>.
  488. * </p>
  489. *
  490. * @param name the name of the preference
  491. * @param value the new current value of the preference
  492. */
  493. public void setValue(String name, long value);
  494. /**
  495. * Sets the current value of the string-valued preference with the
  496. * given name.
  497. * <p>
  498. * A property change event is reported if the current value of the
  499. * preference actually changes from its previous value. In the event
  500. * object, the property name is the name of the preference, and the
  501. * old and new values are wrapped as objects.
  502. * </p>
  503. * <p>
  504. * Note that the preferred way of re-initializing a preference to its
  505. * default value is to call <code>setToDefault</code>.
  506. * </p>
  507. *
  508. * @param name the name of the preference
  509. * @param value the new current value of the preference
  510. */
  511. public void setValue(String name, String value);
  512. /**
  513. * Sets the current value of the boolean-valued preference with the
  514. * given name.
  515. * <p>
  516. * A property change event is reported if the current value of the
  517. * preference actually changes from its previous value. In the event
  518. * object, the property name is the name of the preference, and the
  519. * old and new values are wrapped as objects.
  520. * </p>
  521. * <p>
  522. * Note that the preferred way of re-initializing a preference to its
  523. * default value is to call <code>setToDefault</code>.
  524. * </p>
  525. *
  526. * @param name the name of the preference
  527. * @param value the new current value of the preference
  528. */
  529. public void setValue(String name, boolean value);
  530. }