fix preference handling
This commit is contained in:
parent
24720340be
commit
7ad70411f3
@ -84,12 +84,5 @@
|
||||
category="com.minres.scviewer.e4.application.preferences.scviewer">
|
||||
</page>
|
||||
</extension>
|
||||
<extension
|
||||
point="com.opcoach.e4.preferences.e4PreferenceStoreProvider">
|
||||
<preferenceStoreProvider
|
||||
class="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.preferences.PreferencesStoreProvider"
|
||||
pluginId="com.minres.scviewer.e4.application">
|
||||
</preferenceStoreProvider>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
@ -4,45 +4,43 @@ package com.minres.scviewer.e4.application.handlers;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.ConfigurationScope;
|
||||
import org.eclipse.e4.core.contexts.Active;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.di.extensions.Preference;
|
||||
import org.eclipse.e4.ui.model.application.MApplication;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
|
||||
import com.opcoach.e4.preferences.ScopedPreferenceStore;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class EnableHover {
|
||||
static final String TAG_NAME = "EnableHover"; //$NON-NLS-1$
|
||||
|
||||
@Inject
|
||||
MApplication application;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize(EModelService modelService) {
|
||||
@Inject
|
||||
@Optional
|
||||
public void reactOnShowHoverChange(EModelService modelService, @Preference(value = PreferenceConstants.SHOW_HOVER) Boolean hover) {
|
||||
List<String> tags = new LinkedList<>();
|
||||
tags.add(TAG_NAME);
|
||||
List<MHandledItem> elements = modelService.findElements(application, null, MHandledItem.class, tags );
|
||||
// cover initialization stuff, sync it with code
|
||||
IPreferenceStore store = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
|
||||
boolean state = store.getBoolean(PreferenceConstants.SHOW_HOVER);
|
||||
for( MHandledItem hi : elements ){
|
||||
hi.setSelected(state);
|
||||
hi.setSelected(hover);
|
||||
}
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(@Active MPart part, @Active MWindow window, MHandledItem handledItem, EModelService modelService ) {
|
||||
IPreferenceStore store = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
|
||||
store.setValue(PreferenceConstants.SHOW_HOVER, handledItem.isSelected());
|
||||
public void execute(MHandledItem handledItem, @Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE) IEclipsePreferences prefs ) {
|
||||
try {
|
||||
prefs.putBoolean(PreferenceConstants.SHOW_HOVER, handledItem.isSelected());
|
||||
prefs.flush();
|
||||
} catch (BackingStoreException e) {}
|
||||
}
|
||||
|
||||
}
|
@ -31,17 +31,18 @@ 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.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.core.runtime.jobs.JobGroup;
|
||||
import org.eclipse.core.runtime.preferences.ConfigurationScope;
|
||||
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||
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.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.di.extensions.Preference;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.e4.ui.di.Focus;
|
||||
import org.eclipse.e4.ui.di.PersistState;
|
||||
@ -52,9 +53,7 @@ import org.eclipse.e4.ui.services.EMenuService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.resource.StringConverter;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
@ -80,7 +79,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 org.osgi.service.prefs.Preferences;
|
||||
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
@ -108,7 +107,6 @@ import com.minres.scviewer.e4.application.internal.util.FileMonitor;
|
||||
import com.minres.scviewer.e4.application.internal.util.IFileChangeListener;
|
||||
import com.minres.scviewer.e4.application.internal.util.IModificationChecker;
|
||||
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
|
||||
import com.opcoach.e4.preferences.ScopedPreferenceStore;
|
||||
|
||||
/**
|
||||
* The Class WaveformViewerPart.
|
||||
@ -190,7 +188,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
@Inject
|
||||
EPartService ePartService;
|
||||
|
||||
IPreferenceStore store = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
|
||||
IEclipsePreferences store = null;
|
||||
|
||||
@Inject @Optional DesignBrowser designBrowser;
|
||||
|
||||
@ -207,7 +205,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
private Composite myParent;
|
||||
|
||||
/** The files to load. */
|
||||
ArrayList<File> filesToLoad;
|
||||
ArrayList<File> filesToLoad = new ArrayList<>();
|
||||
|
||||
/** The persisted state. */
|
||||
Map<String, String> persistedState;
|
||||
@ -227,6 +225,8 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
/** The file checker. */
|
||||
IModificationChecker fileChecker;
|
||||
|
||||
private Boolean showHover;
|
||||
|
||||
/**
|
||||
* Creates the composite.
|
||||
*
|
||||
@ -235,11 +235,13 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
* @param dbFactory the db factory
|
||||
*/
|
||||
@PostConstruct
|
||||
public void createComposite(MPart part, Composite parent, IWaveformDbFactory dbFactory) {
|
||||
public void createComposite(MPart part, Composite parent, IWaveformDbFactory dbFactory, @Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE) IEclipsePreferences prefs, @Preference(value = PreferenceConstants.SHOW_HOVER) Boolean hover) {
|
||||
disposeListenerNumber += 1;
|
||||
|
||||
myPart = part;
|
||||
myParent = parent;
|
||||
store=prefs;
|
||||
showHover=hover;
|
||||
database = dbFactory.getDatabase();
|
||||
database.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
@Override
|
||||
@ -256,7 +258,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
});
|
||||
waveformPane = factory.createPanel(parent);
|
||||
waveformPane.setMaxTime(0);
|
||||
|
||||
setupColors();
|
||||
//set selection to empty selection when opening a new waveformPane
|
||||
selectionService.setSelection(new StructuredSelection());
|
||||
|
||||
@ -344,8 +346,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
});
|
||||
|
||||
zoomLevel = waveformPane.getZoomLevels();
|
||||
setupColors();
|
||||
checkForUpdates = store.getBoolean(PreferenceConstants.DATABASE_RELOAD);
|
||||
checkForUpdates = store.getBoolean(PreferenceConstants.DATABASE_RELOAD, true);
|
||||
filesToLoad = new ArrayList<File>();
|
||||
persistedState = part.getPersistedState();
|
||||
Integer files = persistedState.containsKey(DATABASE_FILE + "S") //$NON-NLS-1$
|
||||
@ -374,23 +375,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
}
|
||||
}
|
||||
});
|
||||
store.addPropertyChangeListener(new IPropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
|
||||
if (PreferenceConstants.DATABASE_RELOAD.equals(event.getProperty())) {
|
||||
checkForUpdates = (Boolean)event.getNewValue();
|
||||
fileChecker = null;
|
||||
if (checkForUpdates)
|
||||
fileChecker = fileMonitor.addFileChangeListener(WaveformViewer.this, filesToLoad,
|
||||
FILE_CHECK_INTERVAL);
|
||||
else
|
||||
fileMonitor.removeFileChangeListener(WaveformViewer.this);
|
||||
} else if (!PreferenceConstants.SHOW_HOVER.equals(event.getProperty())){
|
||||
setupColors();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
waveformPane.addDisposeListener(this);
|
||||
|
||||
waveformPane.getWaveformControl().setData(Constants.HELP_PROVIDER_TAG, new ToolTipHelpTextProvider() {
|
||||
@ -402,7 +386,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
waveformPane.getWaveformControl().setData(Constants.CONTENT_PROVIDER_TAG, new ToolTipContentProvider() {
|
||||
@Override
|
||||
public boolean createContent(Composite parent, Point pt) {
|
||||
if(!store.getBoolean(PreferenceConstants.SHOW_HOVER)) return false;
|
||||
if(!showHover) return false;
|
||||
List<Object> res = waveformPane.getElementsAt(pt);
|
||||
if(res.size()>0)
|
||||
if(res.get(0) instanceof ITx) {
|
||||
@ -472,8 +456,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
final Font font = new Font(Display.getCurrent(), "Terminal", 10, SWT.NORMAL);
|
||||
|
||||
final Label label = new Label(parent, SWT.NONE);
|
||||
//label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
|
||||
//label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
|
||||
label.setText(te.waveform.getFullName());
|
||||
label.setFont(font);
|
||||
GridData labelGridData = new GridData();
|
||||
@ -487,35 +469,49 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
});
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Optional
|
||||
public void reactOnPrefsChange(@Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE) IEclipsePreferences prefs) {
|
||||
prefs.addPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Optional
|
||||
public void reactOnShowHoverChange(@Preference(value = PreferenceConstants.SHOW_HOVER) Boolean hover) {
|
||||
showHover=hover;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Optional
|
||||
public void reactOnReloadDatabaseChange(@Preference(value = PreferenceConstants.DATABASE_RELOAD) Boolean checkForUpdates) {
|
||||
if (checkForUpdates) {
|
||||
fileChecker = fileMonitor.addFileChangeListener(WaveformViewer.this, filesToLoad, FILE_CHECK_INTERVAL);
|
||||
} else {
|
||||
fileMonitor.removeFileChangeListener(WaveformViewer.this);
|
||||
fileChecker = null;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
|
||||
*/
|
||||
@Override
|
||||
public void preferenceChange(PreferenceChangeEvent event) {
|
||||
InstancePreferences pref = (InstancePreferences)event.getSource();
|
||||
if (PreferenceConstants.DATABASE_RELOAD.equals(event.getKey())) {
|
||||
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 if (!PreferenceConstants.SHOW_HOVER.equals(event.getKey())){
|
||||
if (!PreferenceConstants.DATABASE_RELOAD.equals(event.getKey()) && !PreferenceConstants.SHOW_HOVER.equals(event.getKey())){
|
||||
setupColors();
|
||||
}
|
||||
try {
|
||||
pref.flush();
|
||||
} catch (BackingStoreException e) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup colors.
|
||||
*/
|
||||
protected void setupColors() {
|
||||
Preferences defaultPrefs= store.parent().parent().node("/"+DefaultScope.SCOPE+"/"+PreferenceConstants.PREFERENCES_SCOPE);
|
||||
HashMap<WaveformColors, RGB> colorPref = new HashMap<>();
|
||||
for (WaveformColors c : WaveformColors.values()) {
|
||||
String prefValue = store.getString(c.name() + "_COLOR"); //$NON-NLS-1$
|
||||
String key = c.name() + "_COLOR";
|
||||
String prefValue = store.get(key, defaultPrefs.get(key, "")); //$NON-NLS-1$
|
||||
RGB rgb = StringConverter.asRGB(prefValue);
|
||||
colorPref.put(c, rgb);
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ package com.minres.scviewer.e4.application.preferences;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
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 org.osgi.framework.FrameworkUtil;
|
||||
|
||||
import com.minres.scviewer.database.ui.WaveformColors;
|
||||
import com.opcoach.e4.preferences.ScopedPreferenceStore;
|
||||
|
||||
/**
|
||||
* The Class DefaultValuesInitializer.
|
||||
@ -27,7 +27,7 @@ import com.opcoach.e4.preferences.ScopedPreferenceStore;
|
||||
public class DefaultValuesInitializer extends AbstractPreferenceInitializer {
|
||||
|
||||
/** The default colors. */
|
||||
public final Color[] colors = new Color[WaveformColors.values().length];
|
||||
public static final Color[] colors = new Color[WaveformColors.values().length];
|
||||
|
||||
/**
|
||||
* Instantiates a new default values initializer.
|
||||
@ -64,21 +64,12 @@ public class DefaultValuesInitializer extends AbstractPreferenceInitializer {
|
||||
*/
|
||||
@Override
|
||||
public void initializeDefaultPreferences() {
|
||||
// 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(DefaultScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
|
||||
|
||||
store.setDefault(PreferenceConstants.DATABASE_RELOAD, true);
|
||||
store.setDefault(PreferenceConstants.SHOW_HOVER, true);
|
||||
IEclipsePreferences store = DefaultScope.INSTANCE.getNode(FrameworkUtil.getBundle(getClass()).getSymbolicName());
|
||||
|
||||
store.putBoolean(PreferenceConstants.DATABASE_RELOAD, true);
|
||||
store.putBoolean(PreferenceConstants.SHOW_HOVER, true);
|
||||
for (WaveformColors c : WaveformColors.values()) {
|
||||
store.setDefault(c.name()+"_COLOR", StringConverter.asString(colors[c.ordinal()].getRGB())); //$NON-NLS-1$
|
||||
store.put(c.name()+"_COLOR", StringConverter.asString(colors[c.ordinal()].getRGB())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user