1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 20:15:22 +02:00

bug 196454: [terminal] Initial connection settings dialog should not be blank

improvements
This commit is contained in:
Michael Scharf 2008-07-09 01:19:22 +00:00
parent a441c7269f
commit 4e399ae9df
3 changed files with 171 additions and 20 deletions

View file

@ -21,6 +21,7 @@
* Martin Oberhuber (Wind River) - [168186] Add Terminal User Docs
* Michael Scharf (Wind River) - [172483] switch between connections
* Michael Scharf (Wind River) - [240023] Get rid of the terminal's "Pin" button
* Michael Scharf (Wind River) - [196454] Initial connection settings dialog should not be blank
*******************************************************************************/
package org.eclipse.tm.internal.terminal.view;
@ -64,7 +65,9 @@ import org.eclipse.tm.internal.terminal.control.actions.TerminalActionPaste;
import org.eclipse.tm.internal.terminal.control.actions.TerminalActionSelectAll;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
import org.eclipse.tm.internal.terminal.provisional.api.LayeredSettingsStore;
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
import org.eclipse.tm.internal.terminal.provisional.api.PreferenceSettingStore;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
import org.eclipse.tm.internal.terminal.view.ITerminalViewConnectionManager.ITerminalViewConnectionFactory;
@ -79,7 +82,9 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
public class TerminalView extends ViewPart implements ITerminalView, ITerminalViewConnectionListener {
private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$
private static final String PREF_CONNECTORS = "Connectors."; //$NON-NLS-1$
private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$
private static final String STORE_SETTING_SUMMARY = "SettingSummary"; //$NON-NLS-1$
@ -334,7 +339,13 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalVi
ITerminalConnector[] connectors = fCtlTerminal.getConnectors();
if(fCtlTerminal.getState()!=TerminalState.CLOSED)
connectors=new ITerminalConnector[0];
TerminalSettingsDlg dlgTerminalSettings = new TerminalSettingsDlg(getViewSite().getShell(),connectors,fCtlTerminal.getTerminalConnector());
// load the state from the settings
// first load from fStore and then from the preferences.
ITerminalConnector c = loadSettings(new LayeredSettingsStore(fStore,getPreferenceSettingsStore()), connectors);
// if we have no connector show the one from the settings
if(fCtlTerminal.getTerminalConnector()!=null)
c=fCtlTerminal.getTerminalConnector();
TerminalSettingsDlg dlgTerminalSettings = new TerminalSettingsDlg(getViewSite().getShell(),connectors,c);
dlgTerminalSettings.setTerminalTitle(getActiveConnection().getPartName());
if(title!=null)
dlgTerminalSettings.setTitle(title);
@ -348,8 +359,11 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalVi
Logger.log("Settings dialog OK'ed."); //$NON-NLS-1$
// When the settings dialog is closed, we persist the Terminal settings.
saveSettings(fStore,dlgTerminalSettings.getConnector());
// we also save it in the preferences. This will keep the last change
// made to this connector as default...
saveSettings(getPreferenceSettingsStore(), dlgTerminalSettings.getConnector());
saveSettings(dlgTerminalSettings.getConnector());
setViewTitle(dlgTerminalSettings.getTerminalTitle());
return dlgTerminalSettings.getConnector();
}
@ -466,18 +480,32 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalVi
ITerminalViewConnection conn = new TerminalViewConnection(fCtlTerminal);
listener.setConnection(conn);
conn.setPartName(getPartName());
String connectionType=fStore.get(STORE_CONNECTION_TYPE);
for (int i = 0; i < connectors.length; i++) {
connectors[i].load(getStore(connectors[i]));
if(connectors[i].getId().equals(connectionType))
ctrl.setConnector(connectors[i]);
}
// load from settings
ITerminalConnector connector = loadSettings(fStore,connectors);
// set the connector....
ctrl.setConnector(connector);
updatePreferences();
TerminalViewPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPreferenceListener);
return conn;
}
/**
* @param store contains the data
* @param connectors loads the data from store
* @return null or the currently selected connector
*/
private ITerminalConnector loadSettings(ISettingsStore store, ITerminalConnector[] connectors) {
ITerminalConnector connector=null;
String connectionType=store.get(STORE_CONNECTION_TYPE);
for (int i = 0; i < connectors.length; i++) {
connectors[i].load(getStore(store,connectors[i]));
if(connectors[i].getId().equals(connectionType))
connector=connectors[i];
}
return connector;
}
/**
* @return a list of connectors this view can use
*/
@ -486,16 +514,27 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalVi
return connectors;
}
private void saveSettings(ITerminalConnector connector) {
ITerminalConnector[] connectors=fCtlTerminal.getConnectors();
for (int i = 0; i < connectors.length; i++) {
connectors[i].save(getStore(connectors[i]));
}
if(connector!=null) {
fStore.put(STORE_CONNECTION_TYPE,connector.getId());
}
/**
* The preference setting store is used to save the settings that are
* shared between all views.
* @return the settings store for the connection based on the preferences.
*
*/
private PreferenceSettingStore getPreferenceSettingsStore() {
return new PreferenceSettingStore(TerminalViewPlugin.getDefault().getPluginPreferences(),PREF_CONNECTORS);
}
/**
* @param store the settings will be saved in this store
* @param connector the connector that will be saved. Can be null.
*/
private void saveSettings(ISettingsStore store, ITerminalConnector connector) {
if(connector!=null) {
connector.save(getStore(store, connector));
// the last saved connector becomes the default
store.put(STORE_CONNECTION_TYPE,connector.getId());
}
}
public void init(IViewSite site, IMemento memento) throws PartInitException {
super.init(site, memento);
fStore=new SettingsStore(memento);
@ -506,8 +545,8 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalVi
fMultiConnectionManager.saveState(new SettingStorePrefixDecorator(fStore,"connectionManager")); //$NON-NLS-1$
fStore.saveState(memento);
}
private ISettingsStore getStore(ITerminalConnector connector) {
return new SettingStorePrefixDecorator(fStore,connector.getId()+"."); //$NON-NLS-1$
private ISettingsStore getStore(ISettingsStore store, ITerminalConnector connector) {
return new SettingStorePrefixDecorator(store,connector.getId()+"."); //$NON-NLS-1$
}
protected void setupActions() {

View file

@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2008 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
*******************************************************************************/
package org.eclipse.tm.internal.terminal.provisional.api;
/**
* Uses an array of {@link ISettingsStore} to find a value.
*
*/
public class LayeredSettingsStore implements ISettingsStore {
private final ISettingsStore[] fStores;
/**
* @param stores the stores used to search the values.
* {@link #put(String, String)} will put the value in the
* first store in the list.
*/
public LayeredSettingsStore(ISettingsStore[] stores) {
fStores=stores;
}
/**
* Convince constructor for two stores
* @param s1 first store
* @param s2 second store
*/
public LayeredSettingsStore(ISettingsStore s1, ISettingsStore s2) {
this(new ISettingsStore[]{s1,s2});
}
public String get(String key) {
for (int i = 0; i < fStores.length; i++) {
String value=fStores[i].get(key);
if(value!=null)
return value;
}
return null;
}
public String get(String key, String defaultValue) {
String value=get(key);
if ((value == null) || (value.equals(""))) //$NON-NLS-1$
return defaultValue;
return value;
}
public void put(String key, String value) {
fStores[0].put(key,value);
}
}

View file

@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2008 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
*******************************************************************************/
package org.eclipse.tm.internal.terminal.provisional.api;
import org.eclipse.core.runtime.Preferences;
/**
* A preference based settings store.
*
*/
public class PreferenceSettingStore implements ISettingsStore {
private final String fPrefix;
private final Preferences fPreferences;
/**
* Creates a ISettingStore that uses the preferences as backend.
*
* @param preferences the backed.
* @param prefix a string that is prepended to the key
*/
public PreferenceSettingStore(Preferences preferences, String prefix) {
fPreferences=preferences;
fPrefix=prefix;
}
public String get(String key) {
return fPreferences.getString(makeKey(key));
}
public String get(String key, String defaultValue) {
String value=get(key);
if ((value == null) || (value.equals(""))) //$NON-NLS-1$
return defaultValue;
return value;
}
public void put(String key, String value) {
fPreferences.setValue(makeKey(key), value);
}
/**
* @param key
* @return the full path in the preferences
*/
private String makeKey(String key) {
return fPrefix+key;
}
}