Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 5852c908373cc873f09e2904abccc94ae39d011e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.command.internal.env.context;

import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.wst.command.internal.env.core.context.Context;

/**
 * This class is used as the base class for types that what to persist preference
 * data in the plugin preferences area.
 *
 *
 */
public abstract class PersistentContext implements Context
{
 protected Preferences preferences_;
 protected Plugin plugin_;

 public PersistentContext ( Plugin plugin)
 	{
 		plugin_ = plugin;
 	  	preferences_ = plugin.getPluginPreferences();
 	}

 /**
  * Sets the default for a boolean preference.
  * @param name the preference name.
  * @param value the preference value.
  */
 public void setDefault (String name, boolean value) {
 	preferences_.setDefault(name, value);
 	}
 
 /**
  * Sets the default for a string preference.
  * @param name the preference name.
  * @param value the preference value.
  */
 public void setDefault (String name, String value) {
 	preferences_.setDefault(name,value);
 	}
 
 /**
  * Sets the default for a int preference.
  * @param name the preference name.
  * @param value the preference value.
  */
 public void setDefault (String name, int value) {
 	preferences_.setDefault(name,value);
 	}
 
 /**
  * Sets the value for a string preference.
  * @param name the preference name.
  * @param value the preference value.
  */
 public void setValue (String name, String value) {
 	preferences_.setValue(name,value);
 	plugin_.savePluginPreferences();
 	}
 
 /**
  * Sets the value for a boolean preference.
  * @param name the preference name.
  * @param value the preference value.
  */
 public void setValue (String name, boolean value) {
 	preferences_.setValue(name, value);
 	plugin_.savePluginPreferences();
 	}
 
 /**
  * Sets the value for a int preference.
  * @param name the preference name.
  * @param value the preference value.
  */
 public void setValue (String name, int value) {
 	preferences_.setValue(name, value);
 	plugin_.savePluginPreferences();
	}

 /**
  * Gets the value for a string preference.
  * @param name the preference name.
  * @return the preference value.
  */
 public String getValueAsString ( String name) {
 	return preferences_.getString(name);
 	}
 
 /**
  * Gets the value for a boolean preference.
  * @param name the preference name.
  * @return the preference value.
  */
  public boolean getValueAsBoolean ( String name) {
 	return preferences_.getBoolean(name);
 	}
  
  /**
   * Gets the value for a int preference.
   * @param name the preference name.
   * @return the preference value.
   */
 public int getValueAsInt( String name) {
 		return preferences_.getInt(name);
 	}
 
 /**
  * Gets the default value for a string preference.
  * @param name the preference name.
  * @return the default preference value.
  */
 public String getDefaultString(String name)
 {
 	return preferences_.getDefaultString(name);
 }
 
 /**
  * Gets the default value for a boolean preference.
  * @param name the preference name.
  * @return the default preference value.
  */
 public boolean getDefaultBoolean(String name)
 {
 	return preferences_.getDefaultBoolean(name);
 }
 
 /**
  * Gets the default value for a int preference.
  * @param name the preference name.
  * @return the default preference value.
  */
 public int getDefaultInt(String name)
 {
 	return preferences_.getDefaultInt(name);
 }
 
 /**
  * Sets the default value for a string preference if a default value has
  * not already been set.
  * @param name the preference name.
  * @param value the default preference value
  */
 public void setDefaultStringIfNoDefault( String key, String value )
 {
   // If the key already has a default value we don't want to override it.
   if( preferences_.getDefaultString( key ).equals("") ) 
   {
     preferences_.setDefault( key, value );
   }
 }
 
 /**
  * Sets the default value for a boolean preference if a default value has
  * not already been set.
  * @param name the preference name.
  * @param value the default preference value
  */
 public void setDefaultBooleanIfNoDefault( String key, boolean value )
 {
   // If the key already has a default value we don't want to override it.
   if( preferences_.getDefaultString( key ).equals("") ) 
   {
     preferences_.setDefault( key, value );
   }
 }
 
 /**
  * Sets the default value for a int preference if a default value has
  * not already been set.
  * @param name the preference name.
  * @param value the default preference value
  */
 public void setDefaultIntIfNoDefault( String key, int value )
 {
   // If the key already has a default value we don't want to override it.
   if( preferences_.getDefaultString( key ).equals("") ) 
   {
     preferences_.setDefault( key, value );
   }
 }
}

Back to the top