1 /*******************************************************************************
2 * Copyright (c) 2003 Berthold Daum.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
10 *******************************************************************************/
12 package net.sourceforge.phpeclipse.ui.overlaypages;
14 import java.io.IOException;
15 import java.io.OutputStream;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.QualifiedName;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.preference.PreferenceStore;
24 * @author Berthold Daum
27 public class PropertyStore extends PreferenceStore {
29 private IResource resource;
31 private IPreferenceStore workbenchStore;
33 private String pageId;
35 private boolean inserting = false;
37 public PropertyStore(IResource resource, IPreferenceStore workbenchStore,
39 this.resource = resource;
40 this.workbenchStore = workbenchStore;
44 /** * Write modified values back to properties ** */
49 * @see org.eclipse.jface.preference.IPersistentPreferenceStore#save()
51 public void save() throws IOException {
58 * @see org.eclipse.jface.preference.PreferenceStore#save(java.io.OutputStream,
61 public void save(OutputStream out, String header) throws IOException {
66 * Writes modified preferences into resource properties.
68 private void writeProperties() throws IOException {
69 String[] preferences = super.preferenceNames();
70 for (int i = 0; i < preferences.length; i++) {
71 String name = preferences[i];
73 setProperty(name, getString(name));
74 } catch (CoreException e) {
75 throw new IOException(
77 .getString("PropertyStore.Cannot_write_resource_property") + name); //$NON-NLS-1$
83 * Convenience method to set a property
88 * the property value or null to delete the property
89 * @throws CoreException
91 private void setProperty(String name, String value) throws CoreException {
92 resource.setPersistentProperty(new QualifiedName(pageId, name), value);
95 /** * Get default values (Delegate to workbench store) ** */
100 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultBoolean(java.lang.String)
102 public boolean getDefaultBoolean(String name) {
103 return workbenchStore.getDefaultBoolean(name);
109 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultDouble(java.lang.String)
111 public double getDefaultDouble(String name) {
112 return workbenchStore.getDefaultDouble(name);
118 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultFloat(java.lang.String)
120 public float getDefaultFloat(String name) {
121 return workbenchStore.getDefaultFloat(name);
127 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultInt(java.lang.String)
129 public int getDefaultInt(String name) {
130 return workbenchStore.getDefaultInt(name);
136 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultLong(java.lang.String)
138 public long getDefaultLong(String name) {
139 return workbenchStore.getDefaultLong(name);
145 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultString(java.lang.String)
147 public String getDefaultString(String name) {
148 return workbenchStore.getDefaultString(name);
151 /** * Get property values ** */
156 * @see org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String)
158 public boolean getBoolean(String name) {
160 return super.getBoolean(name);
166 * @see org.eclipse.jface.preference.IPreferenceStore#getDouble(java.lang.String)
168 public double getDouble(String name) {
170 return super.getDouble(name);
176 * @see org.eclipse.jface.preference.IPreferenceStore#getFloat(java.lang.String)
178 public float getFloat(String name) {
180 return super.getFloat(name);
186 * @see org.eclipse.jface.preference.IPreferenceStore#getInt(java.lang.String)
188 public int getInt(String name) {
190 return super.getInt(name);
196 * @see org.eclipse.jface.preference.IPreferenceStore#getLong(java.lang.String)
198 public long getLong(String name) {
200 return super.getLong(name);
206 * @see org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String)
208 public String getString(String name) {
210 return super.getString(name);
216 private synchronized void insertValue(String name) {
219 if (super.contains(name))
224 prop = getProperty(name);
225 } catch (CoreException e) {
228 prop = workbenchStore.getString(name);
230 setValue(name, prop);
235 * Convenience method to fetch a property
238 * the preference name
239 * @return - the property value
240 * @throws CoreException
242 private String getProperty(String name) throws CoreException {
243 return resource.getPersistentProperty(new QualifiedName(pageId, name));
251 * @see org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String)
253 public boolean contains(String name) {
254 return workbenchStore.contains(name);
260 * @see org.eclipse.jface.preference.IPreferenceStore#setToDefault(java.lang.String)
262 public void setToDefault(String name) {
263 setValue(name, getDefaultString(name));
269 * @see org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String)
271 public boolean isDefault(String name) {
272 String defaultValue = getDefaultString(name);
273 if (defaultValue == null)
275 return defaultValue.equals(getString(name));