From b1bc678b8a885ab0f16b168589df53bfe53fff00 Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Mon, 12 Feb 2007 12:48:05 +0000 Subject: [PATCH] [api] Needs possibility to register newWizardConnectionDelegate with dynamically contributed system types --- .../ui/wizards/RSENewConnectionWizard.java | 191 ++++++++---------- 1 file changed, 89 insertions(+), 102 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/wizards/RSENewConnectionWizard.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/wizards/RSENewConnectionWizard.java index 425be0a9098..16f573171e1 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/wizards/RSENewConnectionWizard.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/wizards/RSENewConnectionWizard.java @@ -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; @@ -33,13 +35,14 @@ import org.eclipse.rse.ui.SystemResources; * The New Connection wizard. This wizard allows users to create new RSE connections. */ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSENewConnectionWizard { + + private final Map wizardDelegates = new HashMap(); + private IRSENewConnectionWizardDelegate currentWizardDelegate; - private HashMap map; - //private IRSESystemType systemType; - private IRSENewConnectionWizardDelegate delegate; private RSENewConnectionWizardMainPage mainPage; private IRSESystemType[] restrictedSystemTypes; private boolean onlySystemType; + private IRSENewConnectionWizardDelegate defaultDelegate; 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)); readWizardDelegateExtensions(); setForcePreviousAndNextButtons(true); - setNeedsProgressMonitor(true); + setNeedsProgressMonitor(true); } - /** + /* (non-Javadoc) * @see org.eclipse.rse.ui.wizards.IRSENewConnectionWizard#restrictToSystemType(org.eclipse.rse.core.IRSESystemType) */ public void restrictToSystemType(IRSESystemType systemType) { @@ -62,198 +65,183 @@ 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) { this.restrictedSystemTypes = systemTypes; - + 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 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); + } + } } - - if (!map.containsKey(systemTypeID)) { - map.put(systemTypeID, 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; } } } } - + /** * Get the new connection wizard delegate for the system type. * @param systemType the system type for which we need the delegate. */ private IRSENewConnectionWizardDelegate setDelegate(IRSESystemType systemType) { - - if (map != null) { - delegate = (IRSENewConnectionWizardDelegate)(map.get(systemType.getId())); - } - - if (delegate == null) { - + currentWizardDelegate = (IRSENewConnectionWizardDelegate)(wizardDelegates.get(systemType.getId())); + + // 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); + if (!currentWizardDelegate.isInitialized()) { + currentWizardDelegate.init(this, systemType); + } else { + currentWizardDelegate.systemTypeChanged(systemType); } - else { - delegate.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) { result = mainPage.isPageComplete(); } - + if (result) { - - if (delegate != null) { - result = delegate.canFinish(); - } - // we do not allow wizard to complete if the delegate is not yet available - else { + if (currentWizardDelegate != null) { + result = currentWizardDelegate.canFinish(); + } else { + // we do not allow wizard to complete if the delegate is not yet available result = false; } } - + 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 { - - if (delegate != null) { - - IWizardPage nextPage = delegate.getNextPage(page); - + } else { + + if (currentWizardDelegate != null) { + + 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); } } @@ -263,21 +251,20 @@ public class RSENewConnectionWizard extends AbstractSystemWizard implements IRSE * @see org.eclipse.jface.wizard.Wizard#performFinish() */ public boolean performFinish() { - + boolean result = true; - + if (mainPage != null) { result = mainPage.performFinish(); } - + if (result) { - - if (delegate != null) { - result = delegate.performFinish(); + if (currentWizardDelegate != null) { + result = currentWizardDelegate.performFinish(); } } - + return result; } - + } \ No newline at end of file