fix preferences storage
This commit is contained in:
		@@ -11,8 +11,6 @@ import org.eclipse.swt.widgets.Event;
 | 
			
		||||
import org.eclipse.swt.widgets.Label;
 | 
			
		||||
import org.eclipse.swt.widgets.Listener;
 | 
			
		||||
import org.eclipse.swt.widgets.Shell;
 | 
			
		||||
import org.eclipse.swt.widgets.Table;
 | 
			
		||||
import org.eclipse.swt.widgets.TableColumn;
 | 
			
		||||
import org.eclipse.swt.widgets.Widget;
 | 
			
		||||
 | 
			
		||||
import com.minres.scviewer.database.swt.Constants;
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,7 @@ import javax.annotation.PostConstruct;
 | 
			
		||||
import javax.inject.Inject;
 | 
			
		||||
import javax.inject.Named;
 | 
			
		||||
 | 
			
		||||
import org.eclipse.core.internal.preferences.InstancePreferences;
 | 
			
		||||
import org.eclipse.core.runtime.IProgressMonitor;
 | 
			
		||||
import org.eclipse.core.runtime.IStatus;
 | 
			
		||||
import org.eclipse.core.runtime.MultiStatus;
 | 
			
		||||
@@ -41,9 +42,11 @@ import org.eclipse.core.runtime.jobs.IJobChangeEvent;
 | 
			
		||||
import org.eclipse.core.runtime.jobs.Job;
 | 
			
		||||
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
 | 
			
		||||
import org.eclipse.core.runtime.jobs.JobGroup;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.ConfigurationScope;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
 | 
			
		||||
import org.eclipse.e4.core.contexts.IEclipseContext;
 | 
			
		||||
import org.eclipse.e4.core.di.annotations.Optional;
 | 
			
		||||
import org.eclipse.e4.core.di.extensions.Preference;
 | 
			
		||||
import org.eclipse.e4.core.services.events.IEventBroker;
 | 
			
		||||
@@ -81,6 +84,7 @@ import org.eclipse.swt.widgets.Table;
 | 
			
		||||
import org.eclipse.swt.widgets.TableColumn;
 | 
			
		||||
import org.eclipse.swt.widgets.TableItem;
 | 
			
		||||
import org.eclipse.swt.widgets.Widget;
 | 
			
		||||
import org.osgi.service.prefs.BackingStoreException;
 | 
			
		||||
 | 
			
		||||
import com.minres.scviewer.database.DataType;
 | 
			
		||||
import com.minres.scviewer.database.ITx;
 | 
			
		||||
@@ -192,9 +196,9 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
 | 
			
		||||
 | 
			
		||||
	/** The prefs. */
 | 
			
		||||
	@Inject
 | 
			
		||||
	@Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE)
 | 
			
		||||
	IEclipsePreferences prefs;
 | 
			
		||||
	
 | 
			
		||||
	@Preference(value = ConfigurationScope.SCOPE, nodePath = PreferenceConstants.PREFERENCES_SCOPE)
 | 
			
		||||
	protected IEclipsePreferences prefs;
 | 
			
		||||
 | 
			
		||||
	@Inject @Optional DesignBrowser designBrowser;
 | 
			
		||||
 | 
			
		||||
	/** The database. */
 | 
			
		||||
@@ -240,7 +244,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
 | 
			
		||||
	@PostConstruct
 | 
			
		||||
	public void createComposite(MPart part, Composite parent, IWaveformDbFactory dbFactory) {
 | 
			
		||||
		disposeListenerNumber += 1;
 | 
			
		||||
				
 | 
			
		||||
		
 | 
			
		||||
		myPart = part;
 | 
			
		||||
		myParent = parent;
 | 
			
		||||
		database = dbFactory.getDatabase();
 | 
			
		||||
@@ -465,17 +469,21 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
 | 
			
		||||
	 */
 | 
			
		||||
	@Override
 | 
			
		||||
	public void preferenceChange(PreferenceChangeEvent event) {
 | 
			
		||||
		InstancePreferences pref = (InstancePreferences)event.getSource();
 | 
			
		||||
		if (PreferenceConstants.DATABASE_RELOAD.equals(event.getKey())) {
 | 
			
		||||
			checkForUpdates = (Boolean) event.getNewValue();
 | 
			
		||||
			checkForUpdates = pref.getBoolean(PreferenceConstants.DATABASE_RELOAD, true);
 | 
			
		||||
			fileChecker = null;
 | 
			
		||||
			if (checkForUpdates)
 | 
			
		||||
				fileChecker = fileMonitor.addFileChangeListener(WaveformViewer.this, filesToLoad,
 | 
			
		||||
						FILE_CHECK_INTERVAL);
 | 
			
		||||
			else
 | 
			
		||||
				fileMonitor.removeFileChangeListener(this);
 | 
			
		||||
		} else {
 | 
			
		||||
		} else if (!PreferenceConstants.SHOW_HOVER.equals(event.getKey())){
 | 
			
		||||
			setupColors();
 | 
			
		||||
		}
 | 
			
		||||
		try {
 | 
			
		||||
			pref.flush();
 | 
			
		||||
		} catch (BackingStoreException e) { }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
 
 | 
			
		||||
@@ -11,15 +11,14 @@
 | 
			
		||||
package com.minres.scviewer.e4.application.preferences;
 | 
			
		||||
 | 
			
		||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.InstanceScope;
 | 
			
		||||
import org.eclipse.jface.preference.IPreferenceStore;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.DefaultScope;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 | 
			
		||||
import org.eclipse.jface.resource.StringConverter;
 | 
			
		||||
import org.eclipse.swt.SWT;
 | 
			
		||||
import org.eclipse.swt.graphics.Color;
 | 
			
		||||
import org.eclipse.wb.swt.SWTResourceManager;
 | 
			
		||||
 | 
			
		||||
import com.minres.scviewer.database.ui.WaveformColors;
 | 
			
		||||
import com.opcoach.e4.preferences.ScopedPreferenceStore;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The Class DefaultValuesInitializer.
 | 
			
		||||
@@ -64,13 +63,22 @@ public class DefaultValuesInitializer extends AbstractPreferenceInitializer {
 | 
			
		||||
	 */
 | 
			
		||||
	@Override
 | 
			
		||||
	public void initializeDefaultPreferences() {
 | 
			
		||||
		IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
 | 
			
		||||
 | 
			
		||||
		store.setDefault(PreferenceConstants.DATABASE_RELOAD, true);
 | 
			
		||||
		store.setDefault(PreferenceConstants.SHOW_HOVER, true);
 | 
			
		||||
        for (WaveformColors c : WaveformColors.values()) {
 | 
			
		||||
        	 store.setDefault(c.name()+"_COLOR", StringConverter.asString(colors[c.ordinal()].getRGB())); //$NON-NLS-1$
 | 
			
		||||
        }
 | 
			
		||||
		IEclipsePreferences node = DefaultScope.INSTANCE.getNode(PreferenceConstants.PREFERENCES_SCOPE);
 | 
			
		||||
		if (node != null)
 | 
			
		||||
		{
 | 
			
		||||
			node.putBoolean(PreferenceConstants.DATABASE_RELOAD, true);
 | 
			
		||||
			node.putBoolean(PreferenceConstants.SHOW_HOVER, true);
 | 
			
		||||
	        for (WaveformColors c : WaveformColors.values()) {
 | 
			
		||||
	        	node.put(c.name()+"_COLOR", StringConverter.asString(colors[c.ordinal()].getRGB())); //$NON-NLS-1$
 | 
			
		||||
	        }
 | 
			
		||||
		}		
 | 
			
		||||
//		IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
 | 
			
		||||
//
 | 
			
		||||
//		store.setDefault(PreferenceConstants.DATABASE_RELOAD, true);
 | 
			
		||||
//		store.setDefault(PreferenceConstants.SHOW_HOVER, true);
 | 
			
		||||
//        for (WaveformColors c : WaveformColors.values()) {
 | 
			
		||||
//        	 store.setDefault(c.name()+"_COLOR", StringConverter.asString(colors[c.ordinal()].getRGB())); //$NON-NLS-1$
 | 
			
		||||
//        }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
package com.minres.scviewer.e4.application.preferences;
 | 
			
		||||
import org.eclipse.core.runtime.preferences.ConfigurationScope;
 | 
			
		||||
import org.eclipse.jface.preference.IPreferenceStore;
 | 
			
		||||
 | 
			
		||||
import com.opcoach.e4.preferences.IPreferenceStoreProvider;
 | 
			
		||||
import com.opcoach.e4.preferences.ScopedPreferenceStore;
 | 
			
		||||
 | 
			
		||||
public class PreferencesStoreProvider implements IPreferenceStoreProvider{
 | 
			
		||||
 | 
			
		||||
	public PreferencesStoreProvider(){
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public IPreferenceStore getPreferenceStore() {
 | 
			
		||||
		return new ScopedPreferenceStore(ConfigurationScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
   </configIni>
 | 
			
		||||
 | 
			
		||||
   <launcherArgs>
 | 
			
		||||
      <programArgs>-clearPersistedState -data @none
 | 
			
		||||
      <programArgs>-clearPersistedState
 | 
			
		||||
      </programArgs>
 | 
			
		||||
      <vmArgs>-Xmx2G
 | 
			
		||||
      </vmArgs>
 | 
			
		||||
 
 | 
			
		||||
@@ -46,6 +46,7 @@ public class E4PreferenceRegistry
 | 
			
		||||
 | 
			
		||||
	public static final String PREFS_PAGE_XP = "com.opcoach.e4.preferences.e4PreferencePages"; // $NON-NLS-1$
 | 
			
		||||
	public static final String PREF_STORE_PROVIDER = "com.opcoach.e4.preferences.e4PreferenceStoreProvider"; // $NON-NLS-1$
 | 
			
		||||
	public static final String KEY_PREF_STORE_PROVIDERS = "com.opcoach.e4.preferences.e4PreferenceStoreProviders"; // $NON-NLS-1$
 | 
			
		||||
	protected static final String ELMT_PAGE = "page"; // $NON-NLS-1$
 | 
			
		||||
	protected static final String ATTR_ID = "id"; // $NON-NLS-1$
 | 
			
		||||
	protected static final String ATTR_CATEGORY = "category"; // $NON-NLS-1$
 | 
			
		||||
@@ -235,6 +236,7 @@ public class E4PreferenceRegistry
 | 
			
		||||
			IContributionFactory factory = context.get(IContributionFactory.class);
 | 
			
		||||
 | 
			
		||||
			psProviders = new HashMap<String, Object>();
 | 
			
		||||
			IExtensionRegistry registry = context.get(IExtensionRegistry.class);
 | 
			
		||||
 | 
			
		||||
			// Read extensions and fill the map...
 | 
			
		||||
			for (IConfigurationElement elmt : registry.getConfigurationElementsFor(PREF_STORE_PROVIDER))
 | 
			
		||||
@@ -261,7 +263,7 @@ public class E4PreferenceRegistry
 | 
			
		||||
				Object data = objectId;
 | 
			
		||||
				if (classname != null)
 | 
			
		||||
				{
 | 
			
		||||
					data = factory.create(classname, context);
 | 
			
		||||
					data = factory.create("bundleclass://"+declaringBundle+"/"+classname, context);
 | 
			
		||||
					if (!(data instanceof IPreferenceStoreProvider))
 | 
			
		||||
					{
 | 
			
		||||
						logger.warn("In extension " + PREF_STORE_PROVIDER + " the class must implements IPreferenceStoreProvider. Check the plugin " + declaringBundle);
 | 
			
		||||
@@ -272,6 +274,8 @@ public class E4PreferenceRegistry
 | 
			
		||||
				psProviders.put(pluginId, data);
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			context.set(KEY_PREF_STORE_PROVIDERS, psProviders);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user