blob: 807e077bd1e5d4cf3cfd1173d2f74aed55f308b5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* 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:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.frameworkgui.preferences;
import java.io.IOException;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.PathEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.viatra2.ViatraPlugin;
import org.eclipse.viatra2.framework.properties.IViatraPropertyProvider;
import org.eclipse.viatra2.framework.properties.VIATRAPreferences;
@SuppressWarnings("deprecation")
public class VIATRAPreferencePage extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
public VIATRAPreferencePage()
{
super(GRID);
// setPreferenceStore(ViatraPlugin.getDefault().getPreferenceStore());
setPreferenceStore(new TrickPreferenceStore());
setDescription("Changes will be applied for newly loaded VPML files.");
setMessage("VIATRA2 Framework");
//initPrefs();
}
/**
*
* @author istvan rath
*
*/
public class TrickPreferenceStore implements IPersistentPreferenceStore
{
Preferences ViatraPluginPrefs;
public TrickPreferenceStore() {
ViatraPluginPrefs = ViatraPlugin.getDefault().getPluginPreferences();
}
public void addPropertyChangeListener(IPropertyChangeListener listener) {
ViatraPluginPrefs.addPropertyChangeListener((Preferences.IPropertyChangeListener)listener);
}
public void removePropertyChangeListener(
IPropertyChangeListener listener) {
ViatraPluginPrefs.removePropertyChangeListener((Preferences.IPropertyChangeListener)listener);
}
public boolean contains(String name) {
return ViatraPluginPrefs.contains(name);
}
public void firePropertyChangeEvent(String name, Object oldValue,
Object newValue) {
}
public boolean getBoolean(String name) {
return ViatraPluginPrefs.getBoolean(name);
}
public boolean getDefaultBoolean(String name) {
return ViatraPluginPrefs.getDefaultBoolean(name);
}
public double getDefaultDouble(String name) {
return ViatraPluginPrefs.getDefaultDouble(name);
}
public float getDefaultFloat(String name) {
return ViatraPluginPrefs.getDefaultFloat(name);
}
public int getDefaultInt(String name) {
return ViatraPluginPrefs.getDefaultInt(name);
}
public long getDefaultLong(String name) {
return ViatraPluginPrefs.getDefaultLong(name);
}
public String getDefaultString(String name) {
return ViatraPluginPrefs.getDefaultString(name);
}
public double getDouble(String name) {
return ViatraPluginPrefs.getDouble(name);
}
public float getFloat(String name) {
return ViatraPluginPrefs.getFloat(name);
}
public int getInt(String name) {
return ViatraPluginPrefs.getInt(name);
}
public long getLong(String name) {
return ViatraPluginPrefs.getLong(name);
}
public String getString(String name) {
return ViatraPluginPrefs.getString(name);
}
public boolean isDefault(String name) {
return ViatraPluginPrefs.isDefault(name);
}
public boolean needsSaving() {
return ViatraPluginPrefs.needsSaving();
}
public void putValue(String name, String value) {
ViatraPluginPrefs.setValue(name, value);
}
public void setDefault(String name, double value) {
ViatraPluginPrefs.setDefault(name, value);
}
public void setDefault(String name, float value) {
ViatraPluginPrefs.setDefault(name, value);
}
public void setDefault(String name, int value) {
ViatraPluginPrefs.setDefault(name, value);
}
public void setDefault(String name, long value) {
ViatraPluginPrefs.setDefault(name, value);
}
public void setDefault(String name, String defaultObject) {
ViatraPluginPrefs.setDefault(name, defaultObject);
}
public void setDefault(String name, boolean value) {
ViatraPluginPrefs.setDefault(name, value);
}
public void setToDefault(String name) {
ViatraPluginPrefs.setToDefault(name);
}
public void setValue(String name, double value) {
ViatraPluginPrefs.setValue(name, value);
}
public void setValue(String name, float value) {
ViatraPluginPrefs.setValue(name, value);
}
public void setValue(String name, int value) {
ViatraPluginPrefs.setValue(name, value);
}
public void setValue(String name, long value) {
ViatraPluginPrefs.setValue(name, value);
}
public void setValue(String name, String value) {
ViatraPluginPrefs.setValue(name, value);
}
public void setValue(String name, boolean value) {
ViatraPluginPrefs.setValue(name, value);
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.IPersistentPreferenceStore#save()
*/
@Override
public void save() throws IOException {
ViatraPlugin.getDefault().savePluginPreferences();
}
}
@Override
protected void createFieldEditors() {
addField(
new BooleanFieldEditor(
VIATRAPreferences.DISABLE_VPML_OVERRIDE,
"&Disable override by custom preferences in VPML files",
getFieldEditorParent()
)
);
// add contributed field editors
for (IViatraPropertyProvider p : ViatraPlugin.getDefault().getPropertyProviders())
{
Label l = new Label(getFieldEditorParent(),SWT.BOLD);
l.setText(p.getProviderID());
l.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
//l.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
Label sep = new Label(getFieldEditorParent(), SWT.NONE);//SWT.HORIZONTAL|SWT.SEPARATOR);
sep.setText("");
sep.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
//sep.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
for (String prop_id : p.getAllPropertyIds())
{
switch (p.getPropertyKind(prop_id))
{
case STRING:
addField(
new StringFieldEditor(
p.getProviderID()+"::"+prop_id,
prop_id,
getFieldEditorParent()
)
);
break;
case INTEGER:
addField(
new IntegerFieldEditor(
p.getProviderID()+"::"+prop_id,
prop_id,
getFieldEditorParent()
)
);
break;
case BOOLEAN:
addField(
new BooleanFieldEditor(
p.getProviderID()+"::"+prop_id,
"&"+prop_id,
getFieldEditorParent()
)
);
break;
case PATH:
addField(
new PathEditor(
p.getProviderID()+"::"+prop_id,
prop_id,
"Choose path",
getFieldEditorParent()
)
);
break;
}
}
// just to ensure there is enough distance to the next category
Label placeHolder0 = new Label(getFieldEditorParent(),SWT.BOLD);
placeHolder0.setText("\n\n");
Label placeHolder1 = new Label(getFieldEditorParent(), SWT.NONE);//SWT.HORIZONTAL|SWT.SEPARATOR);
placeHolder1.setText("\n\n");
}
// just to ensure there is enough distance to the next category
Label placeHolder0 = new Label(getFieldEditorParent(),SWT.BOLD);
placeHolder0.setText("\n\n");
Label placeHolder1 = new Label(getFieldEditorParent(), SWT.NONE);//SWT.HORIZONTAL|SWT.SEPARATOR);
placeHolder1.setText("\n\n");
}
public void init(IWorkbench workbench)
{
}
}