1
0
Fork 0
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:
Uwe Stieber 2007-02-12 12:48:05 +00:00
parent ab3919c38a
commit b1bc678b8a

View file

@ -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
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@ -12,18 +12,20 @@
*
* Contributors:
* 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;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.ui.ISystemIconConstants;
import org.eclipse.rse.ui.RSEUIPlugin;
@ -34,12 +36,13 @@ import org.eclipse.rse.ui.SystemResources;
*/
public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSENewConnectionWizard {
private HashMap map;
//private IRSESystemType systemType;
private IRSENewConnectionWizardDelegate delegate;
private final Map wizardDelegates = new HashMap();
private IRSENewConnectionWizardDelegate currentWizardDelegate;
private RSENewConnectionWizardMainPage mainPage;
private IRSESystemType[] restrictedSystemTypes;
private boolean onlySystemType;
private IRSENewConnectionWizardDelegate defaultDelegate;
private boolean defaultDelegateCreated;
@ -53,7 +56,7 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
setNeedsProgressMonitor(true);
}
/**
/* (non-Javadoc)
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#restrictToSystemType(org.eclipse.rse.core.IRSESystemType)
*/
public void restrictToSystemType(IRSESystemType systemType) {
@ -62,7 +65,7 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
restrictToSystemTypes(types);
}
/**
/* (non-Javadoc)
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#restrictToSystemTypes(org.eclipse.rse.core.IRSESystemType[])
*/
public void restrictToSystemTypes(IRSESystemType[] systemTypes) {
@ -70,52 +73,54 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
if (systemTypes.length == 1) {
this.onlySystemType = true;
}
else {
} else {
this.onlySystemType = false;
}
}
/**
/* (non-Javadoc)
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#setSelectedSystemType(org.eclipse.rse.core.IRSESystemType)
*/
public void setSelectedSystemType(IRSESystemType systemType) {
//this.systemType = systemType;
setDelegate(systemType);
}
/**
*
* Reads the newConnectionWizardDelegates extension point
*/
private void readWizardDelegateExtensions() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_POINT_ID);
assert wizardDelegates != null;
wizardDelegates.clear();
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_POINT_ID);
for (int i = 0; i < elements.length; i++) {
IConfigurationElement element = elements[i];
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;
try {
obj = element.createExecutableExtension(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_ATTRIBUTE_CLASS);
if (obj instanceof IRSENewConnectionWizardDelegate) {
String systemTypeId = element.getAttribute(NEW_CONNECTION_WIZARD_DELEGATE_EXTENSION_CONFIG_ATTRIBUTE_SYSTEMTYPE);
if (map == null) {
map = new HashMap();
}
if (!map.containsKey(systemTypeID)) {
map.put(systemTypeID, obj);
// if the systemTypeId is null or empty, ask the system types if they accept the newConnectionWizardDelegate
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 {
}
} else {
continue;
}
}
catch (CoreException e) {
} catch (CoreException e) {
SystemBasePlugin.logError("Class " + obj + " is not executable extension", e); //$NON-NLS-1$ //$NON-NLS-2$
continue;
}
@ -128,64 +133,57 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
* @param systemType the system type for which we need the delegate.
*/
private IRSENewConnectionWizardDelegate setDelegate(IRSESystemType systemType) {
currentWizardDelegate = (IRSENewConnectionWizardDelegate)(wizardDelegates.get(systemType.getId()));
if (map != null) {
delegate = (IRSENewConnectionWizardDelegate)(map.get(systemType.getId()));
}
if (delegate == null) {
// For system types where we don't have a registered wizard delegate, use the default
// wizard delegate implementation.
if (currentWizardDelegate == null) {
if (!defaultDelegateCreated) {
defaultDelegate = new RSEDefaultNewConnectionWizardDelegate();
defaultDelegateCreated = true;
}
delegate = defaultDelegate;
currentWizardDelegate = defaultDelegate;
}
// initialize with wizard and system type if not initialized before
if (!delegate.isInitialized()) {
delegate.init(this, systemType);
}
else {
delegate.systemTypeChanged(systemType);
if (!currentWizardDelegate.isInitialized()) {
currentWizardDelegate.init(this, systemType);
} else {
currentWizardDelegate.systemTypeChanged(systemType);
}
return delegate;
return currentWizardDelegate;
}
/**
/* (non-Javadoc)
* @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#getDelegate()
*/
public IRSENewConnectionWizardDelegate getDelegate() {
return delegate;
return currentWizardDelegate;
}
/**
* @see org.eclipse.jface.wizard.Wizard#addPages()
/* (non-Javadoc)
* @see org.eclipse.rse.ui.wizards.AbstractSystemWizard#addPages()
*/
public void addPages() {
if (!onlySystemType) {
mainPage = new RSENewConnectionWizardMainPage(this, "Select System Type", "Select a system type");
if (restrictedSystemTypes != null) {
mainPage.restrictToSystemTypes(restrictedSystemTypes);
}
addPage(mainPage);
}
else {
} else {
setDelegate(restrictedSystemTypes[0]);
addPage(delegate.getMainPage());
addPage(currentWizardDelegate.getMainPage());
}
}
/**
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#canFinish()
*/
public boolean canFinish() {
boolean result = true;
if (mainPage != null) {
@ -193,12 +191,10 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
}
if (result) {
if (delegate != null) {
result = delegate.canFinish();
}
if (currentWizardDelegate != null) {
result = currentWizardDelegate.canFinish();
} else {
// we do not allow wizard to complete if the delegate is not yet available
else {
result = false;
}
}
@ -206,54 +202,46 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
return result;
}
/**
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
*/
public IWizardPage getNextPage(IWizardPage page) {
if (mainPage != null && page == mainPage) {
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) {
return super.getNextPage(page);
}
else {
} else {
return nextPage;
}
}
else {
} else {
return super.getNextPage(page);
}
}
}
/**
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#getPreviousPage(org.eclipse.jface.wizard.IWizardPage)
*/
public IWizardPage getPreviousPage(IWizardPage page) {
if (mainPage != null && page == mainPage) {
return super.getPreviousPage(page);
}
else {
if (delegate != null) {
IWizardPage prevPage = delegate.getPreviousPage(page);
} else {
if (currentWizardDelegate != null) {
IWizardPage prevPage = currentWizardDelegate.getPreviousPage(page);
if (prevPage == null) {
return super.getPreviousPage(page);
}
else {
} else {
return prevPage;
}
}
else {
} else {
return super.getPreviousPage(page);
}
}
@ -271,9 +259,8 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE
}
if (result) {
if (delegate != null) {
result = delegate.performFinish();
if (currentWizardDelegate != null) {
result = currentWizardDelegate.performFinish();
}
}