1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 15:45:25 +02:00

[fix] [175027] Team profile is selected when creating a new connection

This commit is contained in:
Uwe Stieber 2007-02-22 12:50:12 +00:00
parent ee5fae7ae3
commit 6aab1d83d3
5 changed files with 109 additions and 62 deletions

View file

@ -48,7 +48,7 @@ public class SystemNewConnectionAction extends SystemBaseWizardAction {
private boolean fromPopupMenu = true;
private ISelectionProvider sp;
private String[] restrictSystemTypesTo;
private String systemTypeFromSelectedContext;
private IHost selectedContext;
/**
* Constructor.
@ -105,7 +105,7 @@ public class SystemNewConnectionAction extends SystemBaseWizardAction {
*/
protected IWizard createWizard() {
RSEMainNewConnectionWizard newConnWizard = new RSEMainNewConnectionWizard();
if (!fromPopupMenu && (sp != null)) {
if (!fromPopupMenu && sp != null) {
setSelection(sp.getSelection());
}
@ -121,8 +121,9 @@ public class SystemNewConnectionAction extends SystemBaseWizardAction {
// if there is a system type available from the current context, this system type
// is selected by default
if (systemTypeFromSelectedContext != null && RSECorePlugin.getDefault().getRegistry().getSystemType(systemTypeFromSelectedContext) != null) {
newConnWizard.setSelection(new StructuredSelection(RSECorePlugin.getDefault().getRegistry().getSystemType(systemTypeFromSelectedContext)));
if (selectedContext != null){
// send a selection changed event to the wizard with the selected context.
newConnWizard.setSelection(new StructuredSelection(selectedContext));
}
return newConnWizard;
@ -202,7 +203,7 @@ public class SystemNewConnectionAction extends SystemBaseWizardAction {
}
}
systemTypeFromSelectedContext = conn != null ? conn.getSystemType() : null;
selectedContext = conn;
}
return enable;
}

View file

@ -19,6 +19,7 @@ package org.eclipse.rse.ui.wizards.newconnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;
@ -27,7 +28,6 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSEPreferencesManager;
import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemNewConnectionWizardPage;
@ -61,14 +61,20 @@ public class RSEDefaultNewConnectionWizard extends RSEAbstractNewConnectionWizar
private String[] activeProfileNames = null;
private int privateProfileIndex = -1;
private ISystemProfile privateProfile = null;
private IHost currentlySelectedConnection = null;
private IHost selectedContext = null;
private static String lastProfile = null;
/**
* Constructor.
*/
public RSEDefaultNewConnectionWizard() {
activeProfileNames = SystemStartHere.getSystemProfileManager().getActiveSystemProfileNames();
String[] profiles = SystemStartHere.getSystemProfileManager().getActiveSystemProfileNames();
// normalize the profiles by sorting our null or empty profile names
List normalized = new LinkedList();
for (int i = 0; i < profiles.length; i++) {
if (profiles[i] != null && !"".equals(profiles[i].trim())) normalized.add(profiles[i]); //$NON-NLS-1$
}
activeProfileNames = (String[])normalized.toArray(new String[normalized.size()]);
}
/* (non-Javadoc)
@ -86,7 +92,7 @@ public class RSEDefaultNewConnectionWizard extends RSEAbstractNewConnectionWizar
activeProfileNames = null;
privateProfileIndex = -1;
privateProfile = null;
currentlySelectedConnection = null;
selectedContext = null;
}
/* (non-Javadoc)
@ -109,51 +115,15 @@ public class RSEDefaultNewConnectionWizard extends RSEAbstractNewConnectionWizar
try {
mainPage = createMainPage(getSystemType());
mainPage.setConnectionNameValidators(SystemConnectionForm.getConnectionNameValidators());
mainPage.setCurrentlySelectedConnection(currentlySelectedConnection);
mainPage.setCurrentlySelectedConnection(selectedContext);
if (defaultUserId != null)
mainPage.setUserId(defaultUserId);
if (defaultConnectionName != null)
mainPage.setConnectionName(defaultConnectionName);
if (defaultHostName != null)
mainPage.setHostName(defaultHostName);
if (defaultUserId != null) mainPage.setUserId(defaultUserId);
if (defaultConnectionName != null) mainPage.setConnectionName(defaultConnectionName);
if (defaultHostName != null) mainPage.setHostName(defaultHostName);
if (mainPage != null && getSystemType() != null)
mainPage.setSystemType(getSystemType());
if (mainPage != null && getSystemType() != null) mainPage.setSystemType(getSystemType());
// If the team profile is available and active, then we default to the team profile.
// If the team profile is not available or inactive, the default private system profile
// is used (if available).
List profileNames = activeProfileNames != null ? Arrays.asList(activeProfileNames) : new ArrayList();
String defaultProfileName = RSEPreferencesManager.getDefaultTeamProfileName();
if (!profileNames.contains(defaultProfileName)) {
ISystemProfile defaultPrivateProfile = RSEUIPlugin.getDefault().getSystemRegistry().getSystemProfileManager().getDefaultPrivateSystemProfile();
if (defaultPrivateProfile != null) defaultProfileName = defaultPrivateProfile.getName();
}
mainPage.setProfileNames(activeProfileNames);
// if there is no connection currently selected, default the profile to
// place the new connection into to be the first of:
// 1. the profile the last connection was created in, in this session
// 3. the default profile.
if (currentlySelectedConnection == null) {
if (lastProfile != null && "".equals(lastProfile)) lastProfile = null; //$NON-NLS-1$
if (lastProfile == null && activeProfileNames != null) {
if (defaultProfileName != null && profileNames.contains(defaultProfileName))
lastProfile = defaultProfileName;
// find the first non empty profile if any.
for (int i = 0; i < activeProfileNames.length && lastProfile == null; i++) {
if (!"".equals(activeProfileNames[i])) { //$NON-NLS-1$
lastProfile = activeProfileNames[i];
}
}
}
if (lastProfile != null)
mainPage.setProfileNamePreSelection(lastProfile);
}
updateDefaultSelectedProfile();
addPage(mainPage);
} catch (Exception exc) {
@ -190,10 +160,63 @@ public class RSEDefaultNewConnectionWizard extends RSEAbstractNewConnectionWizar
}
/**
* Set the currently selected connection. Used to better default entry fields.
* Calculates the default profile name to propose on the default new
* connection wizard main page.
*
* Expected order of default profile selection:
* 1. If a connection is selected, the default profile is the one from the connection.
* 2. If the wizard is invoked the 1st time, the default private system profile is the
* default profile.
* 3. If the wizard is invoked the 2nd time and a last profile is remembered, the last
* profile is the default profile.
* 4. The first non-empty profile from the list of active profiles is the default profile.
*
* In case a profile name is not in the list of currently active profiles, the logic will
* fall trough to the next lower level.
*/
public void setCurrentlySelectedConnection(IHost conn) {
this.currentlySelectedConnection = conn;
protected void updateDefaultSelectedProfile() {
if (mainPage == null) return;
List profileNames = activeProfileNames != null ? Arrays.asList(activeProfileNames) : new ArrayList();
mainPage.setProfileNames(activeProfileNames);
// 1. If a connection is selected, the default profile is the one from the connection.
String defaultProfileName = selectedContext != null ? selectedContext.getSystemProfileName() : null;
if (defaultProfileName == null || !profileNames.contains(defaultProfileName)) {
// 3. If the wizard is invoked the 2nd time and a last profile is remembered, the last
// profile is the default profile.
if (lastProfile != null && "".equals(lastProfile)) lastProfile = null; //$NON-NLS-1$
defaultProfileName = lastProfile;
if (defaultProfileName == null || !profileNames.contains(defaultProfileName)) {
// 2. If the wizard is invoked the 1st time, the default private system profile is the
// default profile.
ISystemProfile defaultPrivateProfile = RSEUIPlugin.getDefault().getSystemRegistry().getSystemProfileManager().getDefaultPrivateSystemProfile();
if (defaultPrivateProfile != null) defaultProfileName = defaultPrivateProfile.getName();
if (defaultProfileName == null || !profileNames.contains(defaultProfileName)) {
// 4. The first non-empty profile from the list of active profiles is the default profile.
// Note: The profile names get normalized within the constructor.
if (activeProfileNames.length > 0) defaultProfileName = activeProfileNames[0];
}
}
}
// set the default profile to the page and remember it.
if (defaultProfileName != null) {
mainPage.setProfileNamePreSelection(defaultProfileName);
// do not update the last selected profile marker if the default profile
// name came for the selected context.
if (selectedContext == null || !defaultProfileName.equals(selectedContext.getSystemProfileName()))
lastProfile = defaultProfileName;
}
}
/**
* Set the currently selected context. Used to better default entry fields.
*/
public void setSelectedContext(IHost selectedContext) {
this.selectedContext = selectedContext;
updateDefaultSelectedProfile();
}
/**

View file

@ -34,6 +34,7 @@ import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.ui.ISystemIconConstants;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemResources;
@ -47,6 +48,8 @@ import org.eclipse.ui.IWorkbench;
public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, ISelectionProvider {
protected static final String LAST_SELECTED_SYSTEM_TYPE_ID = "lastSelectedSystemTypeId"; //$NON-NLS-1$
private IHost selectedContext;
private IWizard selectedWizard;
private IRSESystemType selectedSystemType;
private boolean selectedWizardCanFinishEarly;
@ -73,6 +76,7 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
if (settings.getSection(sectionName) == null) settings.addNewSection(sectionName);
setDialogSettings(settings.getSection(sectionName));
selectedContext = null;
mainPage = new RSENewConnectionWizardSelectionPage();
initializedWizards.clear();
selectionChangedListener.clear();
@ -87,6 +91,7 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
public void dispose() {
super.dispose();
selectedContext = null;
selectedWizard = null;
selectedSystemType = null;
selectedWizardCanFinishEarly = false;
@ -170,13 +175,24 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
* @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
*/
public void setSelection(ISelection selection) {
if (selection instanceof IStructuredSelection
&& ((IStructuredSelection)selection).getFirstElement() instanceof IRSESystemType) {
selectedSystemType = (IRSESystemType)((IStructuredSelection)selection).getFirstElement();
} else {
selectedSystemType = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection)selection;
if (sel.getFirstElement() instanceof IRSESystemType) {
selectedSystemType = (IRSESystemType)((IStructuredSelection)selection).getFirstElement();
} else if (sel.getFirstElement() instanceof IHost) {
selectedContext = (IHost)sel.getFirstElement();
if (selectedContext.getSystemType() != null) {
String systemTypeName = selectedContext.getSystemType();
IRSESystemType systemType = RSECorePlugin.getDefault().getRegistry().getSystemType(systemTypeName);
if (systemType != null) {
selectedSystemType = systemType;
}
}
} else {
selectedSystemType = null;
}
onSelectedSystemTypeChanged();
}
onSelectedSystemTypeChanged();
}
/* (non-Javadoc)
@ -214,6 +230,13 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
selectedWizardCanFinishEarly = false;
}
// if the newly selected wizard is the default RSE new connection wizard
// and the selected context is non-null, set the selected context to the
// default RSE new connection wizard.
if (selectedWizard instanceof RSEDefaultNewConnectionWizard) {
((RSEDefaultNewConnectionWizard)selectedWizard).setSelectedContext(selectedContext);
}
// register the newly selected wizard as selection changed listener
if (selectedWizard instanceof ISelectionChangedListener) {
addSelectionChangedListener((ISelectionChangedListener)selectedWizard);

View file

@ -176,7 +176,7 @@ public class RSENewConnectionWizardSelectionPage extends WizardPage {
filteredTree = new FilteredTree(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, filteredTreeFilter);
filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
GridData layoutData = new GridData(GridData.FILL_BOTH);
layoutData.heightHint = 275; layoutData.widthHint = 450;
layoutData.heightHint = 325; layoutData.widthHint = 450;
filteredTree.setLayoutData(layoutData);
final TreeViewer treeViewer = filteredTree.getViewer();

View file

@ -53,7 +53,7 @@ public class RSEWizardDescriptor extends RSEWizardRegistryElement implements IRS
wizard = (IWizard)element.createExecutableExtension("class"); //$NON-NLS-1$
} catch (CoreException e) {
String message = "RSE new connection wizard failed creation (plugin: {0}, id: {1})."; //$NON-NLS-1$
message = MessageFormat.format(message, new Object[] { element.getContributor().getName(), element.getDeclaringExtension().getSimpleIdentifier()});
message = MessageFormat.format(message, new Object[] { element.getContributor().getName(), element.getAttribute("id")}); //$NON-NLS-1$
RSECorePlugin.getDefault().getLogger().logError(message, e);
}
}