mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-23 08:13:50 +02:00
[fix] [175027] Team profile is selected when creating a new connection
This commit is contained in:
parent
ee5fae7ae3
commit
6aab1d83d3
5 changed files with 109 additions and 62 deletions
|
@ -48,7 +48,7 @@ public class SystemNewConnectionAction extends SystemBaseWizardAction {
|
||||||
private boolean fromPopupMenu = true;
|
private boolean fromPopupMenu = true;
|
||||||
private ISelectionProvider sp;
|
private ISelectionProvider sp;
|
||||||
private String[] restrictSystemTypesTo;
|
private String[] restrictSystemTypesTo;
|
||||||
private String systemTypeFromSelectedContext;
|
private IHost selectedContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -105,7 +105,7 @@ public class SystemNewConnectionAction extends SystemBaseWizardAction {
|
||||||
*/
|
*/
|
||||||
protected IWizard createWizard() {
|
protected IWizard createWizard() {
|
||||||
RSEMainNewConnectionWizard newConnWizard = new RSEMainNewConnectionWizard();
|
RSEMainNewConnectionWizard newConnWizard = new RSEMainNewConnectionWizard();
|
||||||
if (!fromPopupMenu && (sp != null)) {
|
if (!fromPopupMenu && sp != null) {
|
||||||
setSelection(sp.getSelection());
|
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
|
// if there is a system type available from the current context, this system type
|
||||||
// is selected by default
|
// is selected by default
|
||||||
if (systemTypeFromSelectedContext != null && RSECorePlugin.getDefault().getRegistry().getSystemType(systemTypeFromSelectedContext) != null) {
|
if (selectedContext != null){
|
||||||
newConnWizard.setSelection(new StructuredSelection(RSECorePlugin.getDefault().getRegistry().getSystemType(systemTypeFromSelectedContext)));
|
// send a selection changed event to the wizard with the selected context.
|
||||||
|
newConnWizard.setSelection(new StructuredSelection(selectedContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
return newConnWizard;
|
return newConnWizard;
|
||||||
|
@ -202,7 +203,7 @@ public class SystemNewConnectionAction extends SystemBaseWizardAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
systemTypeFromSelectedContext = conn != null ? conn.getSystemType() : null;
|
selectedContext = conn;
|
||||||
}
|
}
|
||||||
return enable;
|
return enable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.eclipse.rse.ui.wizards.newconnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
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.IWizardPage;
|
||||||
import org.eclipse.jface.wizard.WizardPage;
|
import org.eclipse.jface.wizard.WizardPage;
|
||||||
import org.eclipse.rse.core.IRSESystemType;
|
import org.eclipse.rse.core.IRSESystemType;
|
||||||
import org.eclipse.rse.core.RSEPreferencesManager;
|
|
||||||
import org.eclipse.rse.core.SystemBasePlugin;
|
import org.eclipse.rse.core.SystemBasePlugin;
|
||||||
import org.eclipse.rse.core.model.IHost;
|
import org.eclipse.rse.core.model.IHost;
|
||||||
import org.eclipse.rse.core.model.ISystemNewConnectionWizardPage;
|
import org.eclipse.rse.core.model.ISystemNewConnectionWizardPage;
|
||||||
|
@ -61,14 +61,20 @@ public class RSEDefaultNewConnectionWizard extends RSEAbstractNewConnectionWizar
|
||||||
private String[] activeProfileNames = null;
|
private String[] activeProfileNames = null;
|
||||||
private int privateProfileIndex = -1;
|
private int privateProfileIndex = -1;
|
||||||
private ISystemProfile privateProfile = null;
|
private ISystemProfile privateProfile = null;
|
||||||
private IHost currentlySelectedConnection = null;
|
private IHost selectedContext = null;
|
||||||
private static String lastProfile = null;
|
private static String lastProfile = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public RSEDefaultNewConnectionWizard() {
|
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)
|
/* (non-Javadoc)
|
||||||
|
@ -86,7 +92,7 @@ public class RSEDefaultNewConnectionWizard extends RSEAbstractNewConnectionWizar
|
||||||
activeProfileNames = null;
|
activeProfileNames = null;
|
||||||
privateProfileIndex = -1;
|
privateProfileIndex = -1;
|
||||||
privateProfile = null;
|
privateProfile = null;
|
||||||
currentlySelectedConnection = null;
|
selectedContext = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -109,51 +115,15 @@ public class RSEDefaultNewConnectionWizard extends RSEAbstractNewConnectionWizar
|
||||||
try {
|
try {
|
||||||
mainPage = createMainPage(getSystemType());
|
mainPage = createMainPage(getSystemType());
|
||||||
mainPage.setConnectionNameValidators(SystemConnectionForm.getConnectionNameValidators());
|
mainPage.setConnectionNameValidators(SystemConnectionForm.getConnectionNameValidators());
|
||||||
mainPage.setCurrentlySelectedConnection(currentlySelectedConnection);
|
mainPage.setCurrentlySelectedConnection(selectedContext);
|
||||||
|
|
||||||
if (defaultUserId != null)
|
if (defaultUserId != null) mainPage.setUserId(defaultUserId);
|
||||||
mainPage.setUserId(defaultUserId);
|
if (defaultConnectionName != null) mainPage.setConnectionName(defaultConnectionName);
|
||||||
if (defaultConnectionName != null)
|
if (defaultHostName != null) mainPage.setHostName(defaultHostName);
|
||||||
mainPage.setConnectionName(defaultConnectionName);
|
|
||||||
if (defaultHostName != null)
|
|
||||||
mainPage.setHostName(defaultHostName);
|
|
||||||
|
|
||||||
if (mainPage != null && getSystemType() != null)
|
if (mainPage != null && getSystemType() != null) mainPage.setSystemType(getSystemType());
|
||||||
mainPage.setSystemType(getSystemType());
|
|
||||||
|
|
||||||
// If the team profile is available and active, then we default to the team profile.
|
updateDefaultSelectedProfile();
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
addPage(mainPage);
|
addPage(mainPage);
|
||||||
} catch (Exception exc) {
|
} 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) {
|
protected void updateDefaultSelectedProfile() {
|
||||||
this.currentlySelectedConnection = conn;
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.jface.wizard.IWizardPage;
|
||||||
import org.eclipse.jface.wizard.Wizard;
|
import org.eclipse.jface.wizard.Wizard;
|
||||||
import org.eclipse.rse.core.IRSESystemType;
|
import org.eclipse.rse.core.IRSESystemType;
|
||||||
import org.eclipse.rse.core.RSECorePlugin;
|
import org.eclipse.rse.core.RSECorePlugin;
|
||||||
|
import org.eclipse.rse.core.model.IHost;
|
||||||
import org.eclipse.rse.ui.ISystemIconConstants;
|
import org.eclipse.rse.ui.ISystemIconConstants;
|
||||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||||
import org.eclipse.rse.ui.SystemResources;
|
import org.eclipse.rse.ui.SystemResources;
|
||||||
|
@ -47,6 +48,8 @@ import org.eclipse.ui.IWorkbench;
|
||||||
public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, ISelectionProvider {
|
public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, ISelectionProvider {
|
||||||
protected static final String LAST_SELECTED_SYSTEM_TYPE_ID = "lastSelectedSystemTypeId"; //$NON-NLS-1$
|
protected static final String LAST_SELECTED_SYSTEM_TYPE_ID = "lastSelectedSystemTypeId"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
private IHost selectedContext;
|
||||||
|
|
||||||
private IWizard selectedWizard;
|
private IWizard selectedWizard;
|
||||||
private IRSESystemType selectedSystemType;
|
private IRSESystemType selectedSystemType;
|
||||||
private boolean selectedWizardCanFinishEarly;
|
private boolean selectedWizardCanFinishEarly;
|
||||||
|
@ -73,6 +76,7 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
|
||||||
if (settings.getSection(sectionName) == null) settings.addNewSection(sectionName);
|
if (settings.getSection(sectionName) == null) settings.addNewSection(sectionName);
|
||||||
setDialogSettings(settings.getSection(sectionName));
|
setDialogSettings(settings.getSection(sectionName));
|
||||||
|
|
||||||
|
selectedContext = null;
|
||||||
mainPage = new RSENewConnectionWizardSelectionPage();
|
mainPage = new RSENewConnectionWizardSelectionPage();
|
||||||
initializedWizards.clear();
|
initializedWizards.clear();
|
||||||
selectionChangedListener.clear();
|
selectionChangedListener.clear();
|
||||||
|
@ -87,6 +91,7 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
|
selectedContext = null;
|
||||||
selectedWizard = null;
|
selectedWizard = null;
|
||||||
selectedSystemType = null;
|
selectedSystemType = null;
|
||||||
selectedWizardCanFinishEarly = false;
|
selectedWizardCanFinishEarly = false;
|
||||||
|
@ -170,14 +175,25 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
|
||||||
* @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
|
* @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
|
||||||
*/
|
*/
|
||||||
public void setSelection(ISelection selection) {
|
public void setSelection(ISelection selection) {
|
||||||
if (selection instanceof IStructuredSelection
|
if (selection instanceof IStructuredSelection) {
|
||||||
&& ((IStructuredSelection)selection).getFirstElement() instanceof IRSESystemType) {
|
IStructuredSelection sel = (IStructuredSelection)selection;
|
||||||
|
if (sel.getFirstElement() instanceof IRSESystemType) {
|
||||||
selectedSystemType = (IRSESystemType)((IStructuredSelection)selection).getFirstElement();
|
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 {
|
} else {
|
||||||
selectedSystemType = null;
|
selectedSystemType = null;
|
||||||
}
|
}
|
||||||
onSelectedSystemTypeChanged();
|
onSelectedSystemTypeChanged();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
||||||
|
@ -214,6 +230,13 @@ public class RSEMainNewConnectionWizard extends Wizard implements INewWizard, IS
|
||||||
selectedWizardCanFinishEarly = false;
|
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
|
// register the newly selected wizard as selection changed listener
|
||||||
if (selectedWizard instanceof ISelectionChangedListener) {
|
if (selectedWizard instanceof ISelectionChangedListener) {
|
||||||
addSelectionChangedListener((ISelectionChangedListener)selectedWizard);
|
addSelectionChangedListener((ISelectionChangedListener)selectedWizard);
|
||||||
|
|
|
@ -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 = new FilteredTree(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, filteredTreeFilter);
|
||||||
filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
|
filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
|
||||||
GridData layoutData = new GridData(GridData.FILL_BOTH);
|
GridData layoutData = new GridData(GridData.FILL_BOTH);
|
||||||
layoutData.heightHint = 275; layoutData.widthHint = 450;
|
layoutData.heightHint = 325; layoutData.widthHint = 450;
|
||||||
filteredTree.setLayoutData(layoutData);
|
filteredTree.setLayoutData(layoutData);
|
||||||
|
|
||||||
final TreeViewer treeViewer = filteredTree.getViewer();
|
final TreeViewer treeViewer = filteredTree.getViewer();
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class RSEWizardDescriptor extends RSEWizardRegistryElement implements IRS
|
||||||
wizard = (IWizard)element.createExecutableExtension("class"); //$NON-NLS-1$
|
wizard = (IWizard)element.createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
String message = "RSE new connection wizard failed creation (plugin: {0}, id: {1})."; //$NON-NLS-1$
|
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);
|
RSECorePlugin.getDefault().getLogger().logError(message, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue