blob: b9c6b6eb53dcae0901d78f776d5619750c09ae79 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2005, 2018 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.ide.ui.preferences;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.databinding.swt.WidgetProperties;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.statet.ecommons.databinding.jface.DataBindingSupport;
import org.eclipse.statet.ecommons.preferences.core.Preference;
import org.eclipse.statet.ecommons.preferences.core.Preference.BooleanPref;
import org.eclipse.statet.ecommons.preferences.ui.ConfigurationBlock;
import org.eclipse.statet.ecommons.preferences.ui.ConfigurationBlockPreferencePage;
import org.eclipse.statet.ecommons.preferences.ui.ManagedConfigurationBlock;
import org.eclipse.statet.ecommons.runtime.core.StatusChangeListener;
import org.eclipse.statet.ecommons.text.ui.settings.AssistPreferences;
import org.eclipse.statet.ecommons.ui.util.LayoutUtil;
import org.eclipse.statet.base.ui.IStatetUIPreferenceConstants;
public class EditorsPreferencePage extends ConfigurationBlockPreferencePage {
public EditorsPreferencePage() {
}
@Override
protected ConfigurationBlock createConfigurationBlock() {
return new EditorsConfigurationBlock(createStatusChangedListener());
}
}
class EditorsConfigurationBlock extends ManagedConfigurationBlock {
private Button fCodeAssistAutoSingleControl;
private BooleanPref fCodeAssistAutoSinglePref;
private Button fCodeAssistAutoCommonControl;
private BooleanPref fCodeAssistAutoCommonPref;
public EditorsConfigurationBlock(final StatusChangeListener statusListener) {
super(null, statusListener);
}
@Override
protected void createBlockArea(final Composite pageComposite) {
final Map<Preference<?>, String> prefs= new HashMap<>();
// Content Assist
final AssistPreferences assistPreferences = IStatetUIPreferenceConstants.EDITING_ASSIST_PREFERENCES;
this.fCodeAssistAutoSinglePref = assistPreferences.getAutoInsertSinglePref();
prefs.put(this.fCodeAssistAutoSinglePref, assistPreferences.getGroupId());
this.fCodeAssistAutoCommonPref = assistPreferences.getAutoInsertPrefixPref();
prefs.put(this.fCodeAssistAutoCommonPref, assistPreferences.getGroupId());
// Register preferences
setupPreferenceManager(prefs);
// Controls
addLinkHeader(pageComposite, Messages.Editors_link);
{ final Composite group= createCodeAssistSection(pageComposite);
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
// Binding
initBindings();
updateControls();
}
private Composite createCodeAssistSection(final Composite parent) {
final Group group = new Group(parent, SWT.NONE);
group.setText(Messages.Editors_CodeAssist);
group.setLayout(LayoutUtil.applyGroupDefaults(new GridLayout(), 2));
final Label label;
GridData gd;
this.fCodeAssistAutoSingleControl = new Button(group, SWT.CHECK);
this.fCodeAssistAutoSingleControl.setText(Messages.Editors_CodeAssist_AutoInsertSingle);
gd = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
this.fCodeAssistAutoSingleControl.setLayoutData(gd);
this.fCodeAssistAutoCommonControl = new Button(group, SWT.CHECK);
this.fCodeAssistAutoCommonControl.setText(Messages.Editors_CodeAssist_AutoInsertCommon);
gd = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
this.fCodeAssistAutoCommonControl.setLayoutData(gd);
return group;
}
@Override
protected void addBindings(final DataBindingSupport db) {
db.getContext().bindValue(
WidgetProperties.selection().observe(this.fCodeAssistAutoSingleControl),
createObservable(this.fCodeAssistAutoSinglePref) );
db.getContext().bindValue(
WidgetProperties.selection().observe(this.fCodeAssistAutoCommonControl),
createObservable(this.fCodeAssistAutoCommonPref) );
}
}