mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-22 07:43:56 +02:00
[api] Needs possibility to register newWizardConnectionDelegate with dynamically contributed system types
This commit is contained in:
parent
ab3919c38a
commit
b1bc678b8a
1 changed files with 89 additions and 102 deletions
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (c) 2000, 2006 IBM Corporation and Symbian Software Ltd. All rights reserved.
|
* Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved.
|
||||||
* This program and the accompanying materials are made available under the terms
|
* 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
|
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
||||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
@ -12,18 +12,20 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Javier Montalvo Orús (Symbian) - Bug 158555 - newConnectionWizardDelegates can only be used once
|
* Javier Montalvo Orús (Symbian) - Bug 158555 - newConnectionWizardDelegates can only be used once
|
||||||
|
* Uwe Stieber (Wind River) - Support newConnectionWizardDelegates registration with dynamically registered system types
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.ui.wizards;
|
package org.eclipse.rse.ui.wizards;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtensionRegistry;
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.jface.wizard.IWizardPage;
|
import org.eclipse.jface.wizard.IWizardPage;
|
||||||
import org.eclipse.rse.core.IRSESystemType;
|
import org.eclipse.rse.core.IRSESystemType;
|
||||||
|
import org.eclipse.rse.core.RSECorePlugin;
|
||||||
import org.eclipse.rse.core.SystemBasePlugin;
|
import org.eclipse.rse.core.SystemBasePlugin;
|
||||||
import org.eclipse.rse.ui.ISystemIconConstants;
|
import org.eclipse.rse.ui.ISystemIconConstants;
|
||||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||||
|
@ -34,12 +36,13 @@ import org.eclipse.rse.ui.SystemResources;
|
||||||
*/
|
*/
|
||||||
public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSENewConnectionWizard {
|
public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSENewConnectionWizard {
|
||||||
|
|
||||||
private HashMap map;
|
private final Map wizardDelegates = new HashMap();
|
||||||
//private IRSESystemType systemType;
|
private IRSENewConnectionWizardDelegate currentWizardDelegate;
|
||||||
private IRSENewConnectionWizardDelegate delegate;
|
|
||||||
private RSENewConnectionWizardMainPage mainPage;
|
private RSENewConnectionWizardMainPage mainPage;
|
||||||
private IRSESystemType[] restrictedSystemTypes;
|
private IRSESystemType[] restrictedSystemTypes;
|
||||||
private boolean onlySystemType;
|
private boolean onlySystemType;
|
||||||
|
|
||||||
private IRSENewConnectionWizardDelegate defaultDelegate;
|
private IRSENewConnectionWizardDelegate defaultDelegate;
|
||||||
private boolean defaultDelegateCreated;
|
private boolean defaultDelegateCreated;
|
||||||
|
|
||||||
|
@ -50,10 +53,10 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
|
||||||
super(SystemResources.RESID_NEWCONN_TITLE, RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_NEWCONNECTIONWIZARD_ID));
|
super(SystemResources.RESID_NEWCONN_TITLE, RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_NEWCONNECTIONWIZARD_ID));
|
||||||
readWizardDelegateExtensions();
|
readWizardDelegateExtensions();
|
||||||
setForcePreviousAndNextButtons(true);
|
setForcePreviousAndNextButtons(true);
|
||||||
setNeedsProgressMonitor(true);
|
setNeedsProgressMonitor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#restrictToSystemType(org.eclipse.rse.core.IRSESystemType)
|
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#restrictToSystemType(org.eclipse.rse.core.IRSESystemType)
|
||||||
*/
|
*/
|
||||||
public void restrictToSystemType(IRSESystemType systemType) {
|
public void restrictToSystemType(IRSESystemType systemType) {
|
||||||
|
@ -62,7 +65,7 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
|
||||||
restrictToSystemTypes(types);
|
restrictToSystemTypes(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#restrictToSystemTypes(org.eclipse.rse.core.IRSESystemType[])
|
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#restrictToSystemTypes(org.eclipse.rse.core.IRSESystemType[])
|
||||||
*/
|
*/
|
||||||
public void restrictToSystemTypes(IRSESystemType[] systemTypes) {
|
public void restrictToSystemTypes(IRSESystemType[] systemTypes) {
|
||||||
|
@ -70,52 +73,54 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
|
||||||
|
|
||||||
if (systemTypes.length == 1) {
|
if (systemTypes.length == 1) {
|
||||||
this.onlySystemType = true;
|
this.onlySystemType = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.onlySystemType = false;
|
this.onlySystemType = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#setSelectedSystemType(org.eclipse.rse.core.IRSESystemType)
|
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#setSelectedSystemType(org.eclipse.rse.core.IRSESystemType)
|
||||||
*/
|
*/
|
||||||
public void setSelectedSystemType(IRSESystemType systemType) {
|
public void setSelectedSystemType(IRSESystemType systemType) {
|
||||||
//this.systemType = systemType;
|
|
||||||
setDelegate(systemType);
|
setDelegate(systemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Reads the newConnectionWizardDelegates extension point
|
||||||
*/
|
*/
|
||||||
private void readWizardDelegateExtensions() {
|
private void readWizardDelegateExtensions() {
|
||||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
assert wizardDelegates != null;
|
||||||
IConfigurationElement[] elements = registry.getConfigurationElementsFor(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_POINT_ID);
|
|
||||||
|
wizardDelegates.clear();
|
||||||
|
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_POINT_ID);
|
||||||
|
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
IConfigurationElement element = elements[i];
|
IConfigurationElement element = elements[i];
|
||||||
|
|
||||||
if (element.getName().equals(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_NAME)) {
|
if (element.getName().equals(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_NAME)) {
|
||||||
String systemTypeID = element.getAttribute(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_ATTRIBUTE_SYSTEMTYPE);
|
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
obj = element.createExecutableExtension(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_ATTRIBUTE_CLASS);
|
obj = element.createExecutableExtension(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_ATTRIBUTE_CLASS);
|
||||||
|
|
||||||
if (obj instanceof IRSENewConnectionWizardDelegate) {
|
if (obj instanceof IRSENewConnectionWizardDelegate) {
|
||||||
|
String systemTypeId = element.getAttribute(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_ATTRIBUTE_SYSTEMTYPE);
|
||||||
|
|
||||||
if (map == null) {
|
// if the systemTypeId is null or empty, ask the system types if they accept the newConnectionWizardDelegate
|
||||||
map = new HashMap();
|
if (systemTypeId != null && !"".equals(systemTypeId.trim())) { //$NON-NLS-1$
|
||||||
|
if (!wizardDelegates.containsKey(systemTypeId)) wizardDelegates.put(systemTypeId, obj);
|
||||||
|
} else {
|
||||||
|
IRSESystemType[] systemTypes = RSECorePlugin.getDefault().getRegistry().getSystemTypes();
|
||||||
|
for (int j = 0; j < systemTypes.length; j++) {
|
||||||
|
IRSESystemType systemType = systemTypes[j];
|
||||||
|
if (systemType.acceptNewConnectionWizardDelegate(element.getDeclaringExtension().getUniqueIdentifier())
|
||||||
|
&& !wizardDelegates.containsKey(systemType.getId())) {
|
||||||
|
wizardDelegates.put(systemType.getId(), obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (!map.containsKey(systemTypeID)) {
|
|
||||||
map.put(systemTypeID, obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
} catch (CoreException e) {
|
||||||
catch (CoreException e) {
|
|
||||||
SystemBasePlugin.logError("Class " + obj + " is not executable extension", e); //$NON-NLS-1$ //$NON-NLS-2$
|
SystemBasePlugin.logError("Class " + obj + " is not executable extension", e); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -128,64 +133,57 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
|
||||||
* @param systemType the system type for which we need the delegate.
|
* @param systemType the system type for which we need the delegate.
|
||||||
*/
|
*/
|
||||||
private IRSENewConnectionWizardDelegate setDelegate(IRSESystemType systemType) {
|
private IRSENewConnectionWizardDelegate setDelegate(IRSESystemType systemType) {
|
||||||
|
currentWizardDelegate = (IRSENewConnectionWizardDelegate)(wizardDelegates.get(systemType.getId()));
|
||||||
|
|
||||||
if (map != null) {
|
// For system types where we don't have a registered wizard delegate, use the default
|
||||||
delegate = (IRSENewConnectionWizardDelegate)(map.get(systemType.getId()));
|
// wizard delegate implementation.
|
||||||
}
|
if (currentWizardDelegate == null) {
|
||||||
|
|
||||||
if (delegate == null) {
|
|
||||||
|
|
||||||
if (!defaultDelegateCreated) {
|
if (!defaultDelegateCreated) {
|
||||||
defaultDelegate = new RSEDefaultNewConnectionWizardDelegate();
|
defaultDelegate = new RSEDefaultNewConnectionWizardDelegate();
|
||||||
defaultDelegateCreated = true;
|
defaultDelegateCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate = defaultDelegate;
|
currentWizardDelegate = defaultDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize with wizard and system type if not initialized before
|
// initialize with wizard and system type if not initialized before
|
||||||
if (!delegate.isInitialized()) {
|
if (!currentWizardDelegate.isInitialized()) {
|
||||||
delegate.init(this, systemType);
|
currentWizardDelegate.init(this, systemType);
|
||||||
}
|
} else {
|
||||||
else {
|
currentWizardDelegate.systemTypeChanged(systemType);
|
||||||
delegate.systemTypeChanged(systemType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return delegate;
|
return currentWizardDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#getDelegate()
|
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#getDelegate()
|
||||||
*/
|
*/
|
||||||
public IRSENewConnectionWizardDelegate getDelegate() {
|
public IRSENewConnectionWizardDelegate getDelegate() {
|
||||||
return delegate;
|
return currentWizardDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.jface.wizard.Wizard#addPages()
|
* @see org.eclipse.rse.ui.wizards.AbstractSystemWizard#addPages()
|
||||||
*/
|
*/
|
||||||
public void addPages() {
|
public void addPages() {
|
||||||
|
|
||||||
if (!onlySystemType) {
|
if (!onlySystemType) {
|
||||||
mainPage = new RSENewConnectionWizardMainPage(this, "Select System Type", "Select a system type");
|
mainPage = new RSENewConnectionWizardMainPage(this, "Select System Type", "Select a system type");
|
||||||
|
|
||||||
if (restrictedSystemTypes != null) {
|
if (restrictedSystemTypes != null) {
|
||||||
mainPage.restrictToSystemTypes(restrictedSystemTypes);
|
mainPage.restrictToSystemTypes(restrictedSystemTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
addPage(mainPage);
|
addPage(mainPage);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setDelegate(restrictedSystemTypes[0]);
|
setDelegate(restrictedSystemTypes[0]);
|
||||||
addPage(delegate.getMainPage());
|
addPage(currentWizardDelegate.getMainPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.jface.wizard.Wizard#canFinish()
|
* @see org.eclipse.jface.wizard.Wizard#canFinish()
|
||||||
*/
|
*/
|
||||||
public boolean canFinish() {
|
public boolean canFinish() {
|
||||||
|
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
if (mainPage != null) {
|
if (mainPage != null) {
|
||||||
|
@ -193,12 +191,10 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
if (currentWizardDelegate != null) {
|
||||||
if (delegate != null) {
|
result = currentWizardDelegate.canFinish();
|
||||||
result = delegate.canFinish();
|
} else {
|
||||||
}
|
// we do not allow wizard to complete if the delegate is not yet available
|
||||||
// we do not allow wizard to complete if the delegate is not yet available
|
|
||||||
else {
|
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,54 +202,46 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
|
* @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
|
||||||
*/
|
*/
|
||||||
public IWizardPage getNextPage(IWizardPage page) {
|
public IWizardPage getNextPage(IWizardPage page) {
|
||||||
|
|
||||||
if (mainPage != null && page == mainPage) {
|
if (mainPage != null && page == mainPage) {
|
||||||
return super.getNextPage(page);
|
return super.getNextPage(page);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
|
|
||||||
if (delegate != null) {
|
if (currentWizardDelegate != null) {
|
||||||
|
|
||||||
IWizardPage nextPage = delegate.getNextPage(page);
|
IWizardPage nextPage = currentWizardDelegate.getNextPage(page);
|
||||||
|
|
||||||
if (nextPage == null) {
|
if (nextPage == null) {
|
||||||
return super.getNextPage(page);
|
return super.getNextPage(page);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return nextPage;
|
return nextPage;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return super.getNextPage(page);
|
return super.getNextPage(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.jface.wizard.Wizard#getPreviousPage(org.eclipse.jface.wizard.IWizardPage)
|
* @see org.eclipse.jface.wizard.Wizard#getPreviousPage(org.eclipse.jface.wizard.IWizardPage)
|
||||||
*/
|
*/
|
||||||
public IWizardPage getPreviousPage(IWizardPage page) {
|
public IWizardPage getPreviousPage(IWizardPage page) {
|
||||||
|
|
||||||
if (mainPage != null && page == mainPage) {
|
if (mainPage != null && page == mainPage) {
|
||||||
return super.getPreviousPage(page);
|
return super.getPreviousPage(page);
|
||||||
}
|
} else {
|
||||||
else {
|
if (currentWizardDelegate != null) {
|
||||||
|
IWizardPage prevPage = currentWizardDelegate.getPreviousPage(page);
|
||||||
if (delegate != null) {
|
|
||||||
IWizardPage prevPage = delegate.getPreviousPage(page);
|
|
||||||
|
|
||||||
if (prevPage == null) {
|
if (prevPage == null) {
|
||||||
return super.getPreviousPage(page);
|
return super.getPreviousPage(page);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return prevPage;
|
return prevPage;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return super.getPreviousPage(page);
|
return super.getPreviousPage(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,9 +259,8 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
if (currentWizardDelegate != null) {
|
||||||
if (delegate != null) {
|
result = currentWizardDelegate.performFinish();
|
||||||
result = delegate.performFinish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue