fix settings handling

for this a common workspace is being created. To allow for multiple
instances the work space is being unlocked as soon as the application is
initialized
This commit is contained in:
Eyck Jentzsch 2020-03-25 23:01:28 +01:00
parent 220eaea73c
commit 0e8a757d6e
6 changed files with 90 additions and 54 deletions

View File

@ -73,7 +73,7 @@ class ToolTipHandler {
Point pt = new Point (event.x, event.y);
tipPosition = control.toDisplay(pt);
if (tip != null && !tip.isDisposed ()) tip.dispose ();
tip = new Shell (parentShell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
tip = new Shell (parentShell, SWT.NO_FOCUS | SWT.TOOL);
tip.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
GridLayout layout = new GridLayout(1, true);
layout.verticalSpacing=0;

View File

@ -11,10 +11,12 @@
package com.minres.scviewer.e4.application;
import java.io.File;
import java.io.IOException;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
@ -30,6 +32,7 @@ import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
@ -91,6 +94,20 @@ public class E4LifeCycle {
}
}
});
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() {
@Override
public void handleEvent(Event event) {
Location instanceLocation = Platform.getInstanceLocation();
try {
boolean isLocked = instanceLocation.isLocked();
if(isLocked)
instanceLocation.release();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
/**

View File

@ -7,26 +7,23 @@ import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.e4.core.contexts.Active;
import org.eclipse.e4.core.di.annotations.Execute;
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 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
@Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE)
IEclipsePreferences prefs;
@Inject
MApplication application;
@ -36,14 +33,17 @@ public class EnableHover {
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(prefs.getBoolean(PreferenceConstants.SHOW_HOVER, true));
hi.setSelected(state);
}
}
@Execute
public void execute(@Active MPart part, @Active MWindow window, MHandledItem handledItem, EModelService modelService ) {
prefs.putBoolean(PreferenceConstants.SHOW_HOVER, handledItem.isSelected());
IPreferenceStore store = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
store.setValue(PreferenceConstants.SHOW_HOVER, handledItem.isSelected());
}
}

View File

@ -43,12 +43,9 @@ 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;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.PersistState;
@ -59,7 +56,9 @@ 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;
@ -112,8 +111,8 @@ import com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl;
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.DefaultValuesInitializer;
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
import com.opcoach.e4.preferences.ScopedPreferenceStore;
/**
* The Class WaveformViewerPart.
@ -195,10 +194,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
@Inject
EPartService ePartService;
/** The prefs. */
@Inject
@Preference(value = ConfigurationScope.SCOPE, nodePath = PreferenceConstants.PREFERENCES_SCOPE)
protected IEclipsePreferences prefs;
IPreferenceStore store = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, PreferenceConstants.PREFERENCES_SCOPE);
@Inject @Optional DesignBrowser designBrowser;
@ -353,7 +349,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
zoomLevel = waveformPane.getZoomLevels();
setupColors();
checkForUpdates = prefs.getBoolean(PreferenceConstants.DATABASE_RELOAD, true);
checkForUpdates = store.getBoolean(PreferenceConstants.DATABASE_RELOAD);
filesToLoad = new ArrayList<File>();
persistedState = part.getPersistedState();
Integer files = persistedState.containsKey(DATABASE_FILE + "S") //$NON-NLS-1$
@ -382,7 +378,22 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
}
}
});
prefs.addPreferenceChangeListener(this);
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);
@ -395,7 +406,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(!prefs.getBoolean(PreferenceConstants.SHOW_HOVER, true)) return false;
if(!store.getBoolean(PreferenceConstants.SHOW_HOVER)) return false;
List<Object> res = waveformPane.getElementsAt(pt);
if(res.size()>0)
if(res.get(0) instanceof ITx) {
@ -403,9 +414,9 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
final Display display = parent.getDisplay();
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));
final Label label = new Label(parent, SWT.SHADOW_IN);
label.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
label.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
label.setText(tx.toString());
label.setFont(font);
GridData labelGridData = new GridData();
@ -414,12 +425,11 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
label.setLayoutData(labelGridData);
final Table table = new Table(parent, SWT.NONE);
table.setHeaderVisible(true);
table.setHeaderVisible(false);
table.setLinesVisible(true);
table.setFont(font);
// table.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
// table.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
table.setRedraw(false);
label.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
label.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
GridData tableGridData = new GridData();
tableGridData.horizontalAlignment = GridData.FILL;
tableGridData.grabExcessHorizontalSpace = true;
@ -441,14 +451,15 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
item.setText(0, iTxAttribute.getName());
item.setText(1, value);
}
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0, "");
item.setText(1, "");
if(table.getHeaderVisible()) {
// add dummy row to get make last row visible
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0, "");
item.setText(1, "");
}
nameCol.pack();
valueCol.pack();
table.pack();
table.setRedraw(true);
table.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT));
parent.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
@ -462,7 +473,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
return true;
} else if(res.get(0) instanceof TrackEntry) {
TrackEntry te = (TrackEntry)res.get(0);
final Display display = parent.getDisplay();
final Font font = new Font(Display.getCurrent(), "Terminal", 10, SWT.NORMAL);
final Label label = new Label(parent, SWT.NONE);
@ -507,11 +517,9 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
* Setup colors.
*/
protected void setupColors() {
DefaultValuesInitializer initializer = new DefaultValuesInitializer();
HashMap<WaveformColors, RGB> colorPref = new HashMap<>();
for (WaveformColors c : WaveformColors.values()) {
String prefValue = prefs.get(c.name() + "_COLOR", //$NON-NLS-1$
StringConverter.asString(initializer.colors[c.ordinal()].getRGB()));
String prefValue = store.getString(c.name() + "_COLOR"); //$NON-NLS-1$
RGB rgb = StringConverter.asRGB(prefValue);
colorPref.put(c, rgb);
}

View File

@ -12,13 +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.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.preference.IPreferenceStore;
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.
@ -63,22 +64,22 @@ 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(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(DefaultScope.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$
}
}
}

View File

@ -11,6 +11,8 @@
<programArgs>-clearPersistedState
</programArgs>
<vmArgs>-Xmx2G
-Dosgi.instance.area=@user.home/.scviewer
-Dosgi.instance.area.default=@user.home/.scviewer
</vmArgs>
<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
</vmArgsMac>
@ -18,6 +20,7 @@
<windowImages/>
<launcher name="scviewer">
<linux icon="icons/SCViewer_512x512.xpm"/>
<macosx icon="icons/SCViewer.icns"/>
@ -142,4 +145,11 @@
<plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="2" />
</configurations>
<preferencesInfo>
<targetfile overwrite="false"/>
</preferencesInfo>
<cssInfo>
</cssInfo>
</product>