blob: 0ec4d754e1c479ffb25317d9e12916ed277b40dd [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 IBM Corporation and others.
// 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:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.authoring.ui.preferences;
import org.eclipse.epf.authoring.ui.AuthoringUIResources;
import org.eclipse.epf.library.LibraryPlugin;
import org.eclipse.epf.library.configuration.ElementRealizer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
/**
* Preference page for modeling options
*
* @author Shilpa Toraskar
* @since 1.2
*
*/
public class ModelingOptionsPrefPage extends CommonPrefPage implements
IWorkbenchPreferencePage {
int NUM_COLUMN = 1;
private Composite composite_tab;
private Button extendSemanticsCheck;
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
protected Control createContents(Composite parent) {
// composite_tab << parent
composite_tab = createComposite(parent, NUM_COLUMN);
createLabel(composite_tab, " ", NUM_COLUMN); //$NON-NLS-1$
extendSemanticsCheck = new Button(composite_tab, SWT.CHECK);
extendSemanticsCheck.setText(AuthoringUIResources.extend_semantics_button_text);
Label label = new Label(composite_tab, SWT.LEFT| SWT.WRAP);
label.setText(AuthoringUIResources.extend_semantics_text);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
label.setLayoutData(data);
createLabel(composite_tab, " ", NUM_COLUMN); //$NON-NLS-1$
createLine(composite_tab, NUM_COLUMN);
initializeValues();
return composite_tab;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
public void init(IWorkbench workbench) {
// this.workbench = workbench;
}
/*
* (non-Javadoc) Method declared on PreferencePage
*/
protected void performDefaults() {
super.performDefaults();
initializeDefaults();
}
/*
* (non-Javadoc) Method declared on PreferencePage
*/
public boolean performOk() {
storeValues();
LibraryPlugin.getDefault().savePluginPreferences();
return true;
}
/*
* (non-Javadoc)
* @see org.eclipse.epf.authoring.ui.preferences.CommonPrefPage#doGetPreferenceStore()
*/
protected IPreferenceStore doGetPreferenceStore() {
return LibraryPlugin.getDefault().getPreferenceStore();
}
/**
* Stores the values of the controls back to the preference store.
*/
private void storeValues() {
IPreferenceStore store = getPreferenceStore();
boolean value = extendSemanticsCheck.getSelection();
store.setValue(LibraryPreferenceConstants.PREF_EXTEND_SEMANTICS_CHECK,
value);
// set this as well
ElementRealizer.setIgnoreBaseToManyAssociations(value);
}
/**
* Initializes states of the controls using default values in the preference
* store.
*/
private void initializeDefaults() {
IPreferenceStore store = getPreferenceStore();
extendSemanticsCheck
.setSelection(store
.getDefaultBoolean(LibraryPreferenceConstants.PREF_EXTEND_SEMANTICS_CHECK));
}
/**
* Initializes states of the controls from the preference store.
*/
private void initializeValues() {
IPreferenceStore store = getPreferenceStore();
extendSemanticsCheck
.setSelection(store
.getBoolean(LibraryPreferenceConstants.PREF_EXTEND_SEMANTICS_CHECK));
}
private Composite createComposite(Composite parent, int numColumns) {
Composite composite = new Composite(parent, SWT.NULL);
// GridLayout
GridLayout layout = new GridLayout();
layout.numColumns = numColumns;
layout.marginHeight = layout.marginWidth = 0;
composite.setLayout(layout);
// GridData
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.horizontalAlignment = GridData.FILL;
composite.setLayoutData(data);
return composite;
}
}