[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[tm-cvs-commit] moberhuber org.eclipse.tm.core/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/preferences PreferenceModifyListener.java TerminalPreferencePage.java ITerminalConstants.java TerminalPreferenceInitializer.java

Update of /cvsroot/tools/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/preferences
In directory dev2:/tmp/cvs-serv28265/src/org/eclipse/tm/internal/terminal/preferences

Added Files:
	PreferenceModifyListener.java TerminalPreferencePage.java 
	ITerminalConstants.java TerminalPreferenceInitializer.java 
Log Message:
Bug 378691 - [terminal][api] Terminal Preferences should be maintained in the Widget (for font, invert, and buffer)

--- NEW FILE: PreferenceModifyListener.java ---
/*******************************************************************************
 * Copyright (c) 2007, 2012 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 API and implementation
 * Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget
 *******************************************************************************/
package org.eclipse.tm.internal.terminal.preferences;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;
import org.osgi.service.prefs.Preferences;

public class PreferenceModifyListener extends
		org.eclipse.core.runtime.preferences.PreferenceModifyListener {

	public PreferenceModifyListener() {
		// Nothing to do
	}

	/**
	 * Intercept programmatic access to old Terminal Preferences such as "invert"
	 */
	public IEclipsePreferences preApply(IEclipsePreferences node) {
		migrateTerminalPreferences(node.node("instance")); //$NON-NLS-1$
		return super.preApply(node);
	}

	public static void migrateTerminalPreferences(Preferences node) {
		Preferences terminalPrefs = node.node(TerminalPlugin.PLUGIN_ID);
		Preferences oldPrefs = node.node("org.eclipse.tm.terminal.view"); //$NON-NLS-1$
		String oldInvert = oldPrefs.get(ITerminalConstants.PREF_INVERT_COLORS, null);
		String oldBuflines = oldPrefs.get(ITerminalConstants.PREF_BUFFERLINES, null);
		if (oldInvert != null) {
			terminalPrefs.put(ITerminalConstants.PREF_INVERT_COLORS, oldInvert);
			oldPrefs.remove(ITerminalConstants.PREF_INVERT_COLORS);
		}
		if (oldBuflines != null) {
			terminalPrefs.put(ITerminalConstants.PREF_BUFFERLINES, oldBuflines);
			oldPrefs.remove(ITerminalConstants.PREF_BUFFERLINES);
		}
	}

}

--- NEW FILE: ITerminalConstants.java ---
/*******************************************************************************
 * Copyright (c) 2006, 2012 Wind River Systems, Inc. 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:
 * Michael Scharf (Wind River) - initial API and implementation
 * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
 * Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget
 *******************************************************************************/
package org.eclipse.tm.internal.terminal.preferences;

public interface ITerminalConstants {

	public static final String  PREF_HAS_MIGRATED      = "TerminalPref.migrated"; //$NON-NLS-1$

	public static final String  PREF_BUFFERLINES       = "TerminalPrefBufferLines"; //$NON-NLS-1$
	public static final String  PREF_INVERT_COLORS     = "TerminalPrefInvertColors"; //$NON-NLS-1$
	public static final int     DEFAULT_BUFFERLINES    = 1000;
	public static final boolean DEFAULT_INVERT_COLORS  = false;

	public static final String  FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$

}

--- NEW FILE: TerminalPreferencePage.java ---
/*******************************************************************************
 * Copyright (c) 2003, 2012 Wind River Systems, Inc. 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
 *
 * Initial Contributors:
 * The following Wind River employees contributed to the Terminal component
 * that contains this file: Chris Thew, Fran Litterio, Stephen Lamb,
 * Helmut Haigermoser and Ted Williams.
 *
 * Contributors:
 * Michael Scharf (Wind River) - split into core, view and connector plugins
 * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
 * Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget
 *******************************************************************************/
package org.eclipse.tm.internal.terminal.preferences;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.tm.internal.terminal.control.impl.TerminalMessages;
import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class TerminalPreferencePage extends FieldEditorPreferencePage implements
		IWorkbenchPreferencePage {
    protected BooleanFieldEditor fInvertColors;

	protected IntegerFieldEditor fEditorBufferSize;

	public TerminalPreferencePage() {
		super(GRID);
	}
	protected void createFieldEditors() {
		setupPage();
	}
	public void init(IWorkbench workbench) {
		// do nothing
	}
	protected void setupPage() {
		setupData();
		setupEditors();
	}
	protected void setupData() {
		TerminalPlugin plugin;
		IPreferenceStore preferenceStore;

		plugin = TerminalPlugin.getDefault();
		preferenceStore = plugin.getPreferenceStore();
		setPreferenceStore(preferenceStore);
	}
	protected void setupEditors() {
		fInvertColors = new BooleanFieldEditor(
				ITerminalConstants.PREF_INVERT_COLORS, TerminalMessages.INVERT_COLORS,
				getFieldEditorParent());
		fEditorBufferSize = new IntegerFieldEditor(ITerminalConstants.PREF_BUFFERLINES,
				TerminalMessages.BUFFERLINES, getFieldEditorParent());

		fEditorBufferSize.setValidRange(0, Integer.MAX_VALUE);

		addField(fInvertColors);
		addField(fEditorBufferSize);
	}
}

--- NEW FILE: TerminalPreferenceInitializer.java ---
/*******************************************************************************
 * Copyright (c) 2006, 2012 Wind River Systems, Inc. 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:
 * Michael Scharf (Wind River) - initial API and implementation
 * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
 * Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget
 *******************************************************************************/
package org.eclipse.tm.internal.terminal.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.core.runtime.preferences.InstanceScope;
import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;

public class TerminalPreferenceInitializer extends AbstractPreferenceInitializer {

	public TerminalPreferenceInitializer() {
	}

	public void initializeDefaultPreferences() {
		IEclipsePreferences defaultPrefs = DefaultScope.INSTANCE.getNode(TerminalPlugin.PLUGIN_ID);
		defaultPrefs.putBoolean(ITerminalConstants.PREF_INVERT_COLORS, ITerminalConstants.DEFAULT_INVERT_COLORS);
		defaultPrefs.putInt(ITerminalConstants.PREF_BUFFERLINES, ITerminalConstants.DEFAULT_BUFFERLINES);
        migrateTerminalPreferences();
	}

	/**
	 * Migrate settings from the older org.eclipse.tm.terminal.view bundle into the o.e.tm.terminal bundle 
	 */
	public static void migrateTerminalPreferences() {
		IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TerminalPlugin.PLUGIN_ID);
		if (!prefs.getBoolean(ITerminalConstants.PREF_HAS_MIGRATED, false)) {
			prefs.putBoolean(ITerminalConstants.PREF_HAS_MIGRATED, true);
			PreferenceModifyListener.migrateTerminalPreferences(InstanceScope.INSTANCE.getNode("")); //$NON-NLS-1$
		}
	}

}