1/*******************************************************************************
2 * Copyright (c) 2011 Google, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *    Google, Inc. - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.wb.core.controls.flyout;
12
13import org.eclipse.jface.preference.IPreferenceStore;
14
15/**
16 * Implementation of {@link IFlyoutPreferences} for {@link IPreferenceStore}.
17 *
18 * @author scheglov_ke
19 * @coverage core.control
20 */
21public final class PluginFlyoutPreferences implements IFlyoutPreferences {
22  private final IPreferenceStore m_store;
23  private final String m_dockLocationKey;
24  private final String m_stateKey;
25  private final String m_widthKey;
26
27  ////////////////////////////////////////////////////////////////////////////
28  //
29  // Constructor
30  //
31  ////////////////////////////////////////////////////////////////////////////
32  public PluginFlyoutPreferences(IPreferenceStore store, String prefix) {
33    m_store = store;
34    m_dockLocationKey = prefix + ".flyout.dockLocation";
35    m_stateKey = prefix + ".flyout.state";
36    m_widthKey = prefix + ".flyout.width";
37  }
38
39  ////////////////////////////////////////////////////////////////////////////
40  //
41  // Access
42  //
43  ////////////////////////////////////////////////////////////////////////////
44  /**
45   * Initializes defaults using given values.
46   */
47  public void initializeDefaults(int location, int state, int width) {
48    m_store.setDefault(m_dockLocationKey, location);
49    m_store.setDefault(m_stateKey, state);
50    m_store.setDefault(m_widthKey, width);
51  }
52
53  ////////////////////////////////////////////////////////////////////////////
54  //
55  // IFlyoutPreferences
56  //
57  ////////////////////////////////////////////////////////////////////////////
58  public int getDockLocation() {
59    return m_store.getInt(m_dockLocationKey);
60  }
61
62  public int getState() {
63    return m_store.getInt(m_stateKey);
64  }
65
66  public int getWidth() {
67    return m_store.getInt(m_widthKey);
68  }
69
70  public void setDockLocation(int location) {
71    m_store.setValue(m_dockLocationKey, location);
72  }
73
74  public void setState(int state) {
75    m_store.setValue(m_stateKey, state);
76  }
77
78  public void setWidth(int width) {
79    m_store.setValue(m_widthKey, width);
80  }
81}
82