Java tutorial
/******************************************************************************* * Copyright (c) 2013, 2014 ETAS GmbH. * 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: * Dennis Eder (ETAS GmbH) - initial API and implementation and/or initial documentation *******************************************************************************/ package mbtarranger.preferences; import mbtarranger.Activator; import mbtarranger.preferences.QueryPreferences.PlatformChoice; import org.eclipse.jface.preference.DirectoryFieldEditor; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.RadioGroupFieldEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; public class MbtArrangerPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { public MbtArrangerPreferencePage() { super(); setPreferenceStore(Activator.getDefault().getPreferenceStore()); } Composite top; public class RadioGroupFieldEditorExt extends RadioGroupFieldEditor { public RadioGroupFieldEditorExt(String name, String labelText, int numColumns, String[][] labelAndValues, Composite parent, boolean useGroup) { super(name, labelText, numColumns, labelAndValues, parent, useGroup); } public RadioGroupFieldEditorExt(String name, String labelText, int numColumns, String[][] labelAndValues, Composite parent) { super(name, labelText, numColumns, labelAndValues, parent); } @Override protected void fireValueChanged(String property, Object oldValue, Object newValue) { super.fireValueChanged(property, oldValue, newValue); if (PreferenceConstants.const_Platform_WindowsMSSVS.equals(newValue)) { dirEdit_MSVC_COMMONTOOLS_DIR.setEnabled(true, top); } else { dirEdit_MSVC_COMMONTOOLS_DIR.setEnabled(false, top); } dirEdit_MSVC_COMMONTOOLS_DIR.notifyAll(); } } protected DirectoryFieldEditor dirEdit_SMV_DIR; protected DirectoryFieldEditor dirEdit_MSVC_COMMONTOOLS_DIR; protected DirectoryFieldEditor dirEdit_GRAPHVIZ_DIR; protected RadioGroupFieldEditorExt radEdit_PLATFORM_CHOICE; protected Control createContents(Composite parent) { top = new Composite(parent, SWT.LEFT); // Sets the layout data for the top composite's // place in its parent's layout. top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Sets the layout for the top composite's // children to populate. top.setLayout(new GridLayout()); dirEdit_SMV_DIR = new DirectoryFieldEditor(PreferenceConstants.P_SMV_DIR, "&NuSMV Directory: \n(nusmv.exe or nusmv.sh)", top); dirEdit_SMV_DIR.setPreferenceStore(getPreferenceStore()); dirEdit_SMV_DIR.load(); dirEdit_GRAPHVIZ_DIR = new DirectoryFieldEditor(PreferenceConstants.P_GRAPHVIZ_DIR, "&Graphviz Directory (dot.exe or dot.sh):", top); dirEdit_GRAPHVIZ_DIR.setPreferenceStore(getPreferenceStore()); dirEdit_GRAPHVIZ_DIR.load(); radEdit_PLATFORM_CHOICE = new RadioGroupFieldEditorExt(PreferenceConstants.P_PLATFORM_CHOICE, "Platform", 1, new String[][] { { "Windows &Visual Studio CL", PreferenceConstants.const_Platform_WindowsMSSVS }, { "Windows &MinGw", PreferenceConstants.const_Platform_WindowsMinGW }, { "Linu&x gcc (todo)", PreferenceConstants.const_Platform_LinuxGCC } }, top); radEdit_PLATFORM_CHOICE.setPreferenceStore(getPreferenceStore()); radEdit_PLATFORM_CHOICE.load(); dirEdit_MSVC_COMMONTOOLS_DIR = new DirectoryFieldEditor(PreferenceConstants.P_MSVC_COMMONTOOLS_DIR, "&Visual Studio TypeConverterCommons Tools Directory: \n" + "(includes e.g. vsvars32.bat and often directed to\n" + "by environment variable %VSxxxCOMNTOOLS%)", top); if (QueryPreferences.getPlatformChoice_asEnum() == PlatformChoice.windowsMSSVS) { dirEdit_MSVC_COMMONTOOLS_DIR.setEnabled(true, top); } else { dirEdit_MSVC_COMMONTOOLS_DIR.setEnabled(false, top); } dirEdit_MSVC_COMMONTOOLS_DIR.setPreferenceStore(getPreferenceStore()); dirEdit_MSVC_COMMONTOOLS_DIR.load(); return top; } protected void performDefaults() { dirEdit_SMV_DIR.loadDefault(); dirEdit_GRAPHVIZ_DIR.loadDefault(); radEdit_PLATFORM_CHOICE.loadDefault(); dirEdit_MSVC_COMMONTOOLS_DIR.loadDefault(); if (QueryPreferences.getPlatformChoice_asEnum() == PlatformChoice.windowsMSSVS) { dirEdit_MSVC_COMMONTOOLS_DIR.setEnabled(true, top); } else { dirEdit_MSVC_COMMONTOOLS_DIR.setEnabled(false, top); } dirEdit_MSVC_COMMONTOOLS_DIR.notifyAll(); super.performDefaults(); } public boolean performOk() { dirEdit_SMV_DIR.store(); dirEdit_GRAPHVIZ_DIR.store(); radEdit_PLATFORM_CHOICE.store(); dirEdit_MSVC_COMMONTOOLS_DIR.store(); return super.performOk(); } @Override public void init(IWorkbench workbench) { // TODO Auto-generated method stub } }