diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfiguration.java index bf794f86845..6ef99e96dec 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfiguration.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2006, 2007 IBM Corporation. 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 @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 168870: move core function from UI to core ********************************************************************************/ package org.eclipse.rse.core.subsystems; @@ -36,6 +36,13 @@ public interface ISubSystemConfiguration extends ISystemFilterPoolManagerProvide * Reset for a full refresh from disk, such as after a team synch. */ public void reset(); + + /** + * Retrieves all the filter pool managers for all the profiles, active or not. + * This allows cross references from + * one subsystem in one profile to filter pools in any other profile. + */ + public ISystemFilterPoolManager[] getAllSystemFilterPoolManagers(); // --------------------------------- // CRITICAL METHODS... diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfigurationProxy.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfigurationProxy.java index b613af8727d..27fb83d79b7 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfigurationProxy.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ISubSystemConfigurationProxy.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2002, 2007 IBM Corporation. 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 @@ -11,11 +11,13 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ + * David Dykstal (IBM) - 168870: move core function from UI to core +********************************************************************************/ package org.eclipse.rse.core.subsystems; +import java.net.URL; + import org.osgi.framework.Bundle; /** @@ -120,4 +122,15 @@ public interface ISubSystemConfigurationProxy { * After a reset, restore from disk */ public void restore(); + + /** + * @return the URL of the image associated with this subsystem in its non-connected state. + */ + public URL getImageLocation(); + + /** + * @return the URL of the image associated with this subsystem in its connected state. + */ + public URL getLiveImageLocation(); + } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java index 428f0118413..d8125e2979e 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java @@ -13,6 +13,7 @@ * Contributors: * David Dykstal (IBM) - moved methods to SystemPreferencesManager. * Uwe Stieber (Wind River) - bugfixing. + * David Dykstal (IBM) - 168870: move core function from UI to core ********************************************************************************/ package org.eclipse.rse.ui; @@ -51,6 +52,7 @@ import org.eclipse.rse.internal.ui.RSESystemTypeAdapterFactory; import org.eclipse.rse.internal.ui.SystemResources; import org.eclipse.rse.internal.ui.actions.SystemDynamicPopupMenuExtensionManager; import org.eclipse.rse.internal.ui.actions.SystemShowPreferencesPageAction; +import org.eclipse.rse.internal.ui.subsystems.SubSystemConfigurationProxyAdapterFactory; import org.eclipse.rse.internal.ui.view.SubSystemConfigurationAdapterFactory; import org.eclipse.rse.internal.ui.view.SystemViewAdapterFactory; import org.eclipse.rse.internal.ui.view.team.SystemTeamViewResourceAdapterFactory; @@ -500,6 +502,8 @@ public class RSEUIPlugin extends SystemBasePlugin implements ISystemMessageProvi RSESystemTypeAdapterFactory rseSysTypeFactory = new RSESystemTypeAdapterFactory(); manager.registerAdapters(rseSysTypeFactory, IRSESystemType.class); + manager.registerAdapters(new SubSystemConfigurationProxyAdapterFactory(), ISubSystemConfigurationProxy.class); + svaf = new SystemViewAdapterFactory(); svaf.registerWithManager(manager); @@ -520,8 +524,7 @@ public class RSEUIPlugin extends SystemBasePlugin implements ISystemMessageProvi { return svaf; } - - + /** * Restart the whole thing after a team synchronization */ diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/internal/subsystems/SubSystemConfigurationProxy.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/internal/subsystems/SubSystemConfigurationProxy.java index 4ddcd1a8a9d..19184ec6267 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/internal/subsystems/SubSystemConfigurationProxy.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/internal/subsystems/SubSystemConfigurationProxy.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2002, 2007 IBM Corporation. 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 @@ -13,6 +13,7 @@ * Contributors: * Uwe Stieber (Wind River) - systemTypeIds attribute extension and dynamic association * of system types. + * David Dykstal (IBM) - 168870: move core function from UI to core ********************************************************************************/ package org.eclipse.rse.core.internal.subsystems; @@ -25,16 +26,12 @@ import java.util.List; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.rse.core.IRSESystemType; import org.eclipse.rse.core.RSECorePlugin; -import org.eclipse.rse.core.SystemBasePlugin; import org.eclipse.rse.core.SystemTypeMatcher; import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy; -import org.eclipse.rse.core.subsystems.SubSystemConfiguration; -import org.eclipse.rse.ui.ISystemIconConstants; -import org.eclipse.rse.ui.RSEUIPlugin; +import org.eclipse.rse.logging.Logger; import org.osgi.framework.Bundle; /** @@ -62,10 +59,6 @@ public class SubSystemConfigurationProxy implements ISubSystemConfigurationProxy private String category; // The subsystem configuration priority private int priority; - // The subsystem configuration image - private ImageDescriptor image; - // The subsystem configuration live image - private ImageDescriptor liveImage; // The subsystem configuration implementation class private ISubSystemConfiguration configuration = null; @@ -96,18 +89,13 @@ public class SubSystemConfigurationProxy implements ISubSystemConfigurationProxy try { if (priorityStr != null) priority = Integer.parseInt(priorityStr); } catch (NumberFormatException e) { - SystemBasePlugin.logError("Exception reading priority for subsystem configuration " + name + " defined in plugin " + element.getDeclaringExtension().getNamespaceIdentifier(), e); //$NON-NLS-1$ //$NON-NLS-2$ + Logger logger = RSECorePlugin.getDefault().getLogger(); + logger.logError("Exception reading priority for subsystem configuration " + name + " defined in plugin " + element.getDeclaringExtension().getNamespaceIdentifier(), e); //$NON-NLS-1$ //$NON-NLS-2$ } if (vendor == null) vendor = "Unknown"; //$NON-NLS-1$ if (category == null) category = "Unknown"; //$NON-NLS-1$ - this.image = getPluginImage(element, element.getAttribute("icon")); //$NON-NLS-1$ - if (this.image == null) this.image = RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CONNECTION_ID); - - this.liveImage = getPluginImage(element, element.getAttribute("iconlive")); //$NON-NLS-1$ - if (this.liveImage == null) this.liveImage = RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CONNECTIONLIVE_ID); - systemTypeMatcher = new SystemTypeMatcher(getDeclaredSystemTypeIds()); } @@ -212,19 +200,6 @@ public class SubSystemConfigurationProxy implements ISubSystemConfigurationProxy return category; } - public ImageDescriptor getImage() { - return image; - } - - /** - * Returns the live image to use when this susystem is connection. - * Comes from iconLive attribute in extension point xml. - */ - public ImageDescriptor getLiveImage() { - if (liveImage != null) return liveImage; - return getImage(); - } - /* (non-Javadoc) * @see org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy#getPriority() */ @@ -241,21 +216,6 @@ public class SubSystemConfigurationProxy implements ISubSystemConfigurationProxy return Arrays.asList(getSystemTypes()).contains(type); } - /** - * Retrieve image in given plugin's directory tree, given its file name. - * The file name should be relatively qualified with the subdir containing it. - */ - protected ImageDescriptor getPluginImage(IConfigurationElement element, String fileName) { - URL path = getDeclaringBundle().getEntry("/"); //$NON-NLS-1$ - URL fullPathString = null; - try { - fullPathString = new URL(path, fileName); - return ImageDescriptor.createFromURL(fullPathString); - } catch (MalformedURLException e) { - } - return null; - } - /** * Return true if this subsystem factory has been instantiated yet. * Use this when you want to avoid the side effect of starting the subsystem factory object. @@ -278,13 +238,8 @@ public class SubSystemConfigurationProxy implements ISubSystemConfigurationProxy configuration.setSubSystemConfigurationProxy(this); // side effect: restores filter pools } } catch (Exception exc) { - exc.printStackTrace(); - SystemBasePlugin.logError("Unable to start subsystem factory " + id, exc); //$NON-NLS-1$ - org.eclipse.swt.widgets.MessageBox mb = new org.eclipse.swt.widgets.MessageBox(SystemBasePlugin.getActiveWorkbenchShell()); - mb.setText("Unexpected Error"); //$NON-NLS-1$ - String errmsg = "Unable to start subsystem factory " + getName() + ". See log file for details"; //$NON-NLS-1$ //$NON-NLS-2$ - mb.setMessage(errmsg); - mb.open(); + Logger logger = RSECorePlugin.getDefault().getLogger(); + logger.logError("Unable to start subsystem factory " + id, exc); //$NON-NLS-1$ } // Attempt to restore the subsystem configuration completely. @@ -307,14 +262,10 @@ public class SubSystemConfigurationProxy implements ISubSystemConfigurationProxy * After a reset, restore from disk */ public void restore() { - // If the subsystem configuration implementation is based on our default - // implementation, we can initiate the filter pool manager restore from here. - if (configuration instanceof SubSystemConfiguration) { - try { - ((SubSystemConfiguration)configuration).restoreAllFilterPoolManagersForAllProfiles(); - } catch (Exception exc) { - SystemBasePlugin.logError("Error restoring subsystem for factory " + getName(), exc); //$NON-NLS-1$ - } + try { + configuration.getAllSystemFilterPoolManagers(); + } catch (Exception exc) { + RSECorePlugin.getDefault().getLogger().logError("Error restoring subsystem for configuration " + getName(), exc); //$NON-NLS-1$ } } @@ -343,5 +294,27 @@ public class SubSystemConfigurationProxy implements ISubSystemConfigurationProxy public String toString() { return id + "." + name; //$NON-NLS-1$ } - + + private URL getLocation(String fileName) { + URL result = null; + if (fileName != null) { + URL path = getDeclaringBundle().getEntry("/"); //$NON-NLS-1$ + try { + result = new URL(path, fileName); + } catch (MalformedURLException e) { + } + } + return result; + } + + public URL getImageLocation() { + URL result = getLocation(element.getAttribute("icon")); //$NON-NLS-1$ + return result; + } + + public URL getLiveImageLocation() { + URL result = getLocation(element.getAttribute("iconlive")); //$NON-NLS-1$ + return result; + } + } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java index 4b4cb41d25d..6f28a15ba47 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java @@ -13,6 +13,7 @@ * Contributors: * David Dykstal (IBM) - 168870: moved SystemPreferencesManager to a new package * David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies + * David Dykstal (IBM) - 168870: made use of adapters on the SubSystemConfigurationProxy ********************************************************************************/ package org.eclipse.rse.core.subsystems; @@ -42,7 +43,6 @@ import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManager; import org.eclipse.rse.core.filters.ISystemFilterSavePolicies; import org.eclipse.rse.core.filters.ISystemFilterString; import org.eclipse.rse.core.filters.SystemFilterPoolManager; -import org.eclipse.rse.core.internal.subsystems.SubSystemConfigurationProxy; import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.ISystemModelChangeEvents; import org.eclipse.rse.core.model.ISystemNewConnectionWizardPage; @@ -55,6 +55,7 @@ import org.eclipse.rse.internal.core.filters.SystemFilterStartHere; import org.eclipse.rse.internal.model.SystemProfileManager; import org.eclipse.rse.internal.ui.SystemPropertyResources; import org.eclipse.rse.internal.ui.SystemResources; +import org.eclipse.rse.internal.ui.subsystems.SubSystemConfigurationProxyAdapter; import org.eclipse.rse.model.ISystemResourceChangeEvents; import org.eclipse.rse.model.SystemResourceChangeEvent; import org.eclipse.rse.model.SystemStartHere; @@ -668,8 +669,26 @@ public abstract class SubSystemConfiguration implements ISubSystemConfiguration */ public ImageDescriptor getImage() { - return ((SubSystemConfigurationProxy)proxy).getImage(); + Object adapterCandidate = Platform.getAdapterManager().getAdapter(proxy, SubSystemConfigurationProxyAdapter.class); + SubSystemConfigurationProxyAdapter adapter = (SubSystemConfigurationProxyAdapter) adapterCandidate; + ImageDescriptor result = adapter.getImageDescriptor(); + return result; } + + /** + * Return image to use when this susystem is connection. + * This comes from the xml "iconlive" attribute of the extension point. + */ + public ImageDescriptor getLiveImage() + { + Object adapterCandidate = Platform.getAdapterManager().getAdapter(proxy, SubSystemConfigurationProxyAdapter.class); + SubSystemConfigurationProxyAdapter adapter = (SubSystemConfigurationProxyAdapter) adapterCandidate; + ImageDescriptor result = adapter.getLiveImageDescriptor(); + return result; + } + + + /** * Return actual graphics Image of this factory. * This is the same as calling getImage().createImage() but the resulting @@ -695,15 +714,6 @@ public abstract class SubSystemConfiguration implements ISubSystemConfiguration return null; } - /** - * Return image to use when this susystem is connection. - * This comes from the xml "iconlive" attribute of the extension point. - */ - public ImageDescriptor getLiveImage() - { - return ((SubSystemConfigurationProxy)proxy).getLiveImage(); - } - /** * Return actual graphics LiveImage of this factory. * This is the same as calling getLiveImage().createImage() but the resulting @@ -2871,10 +2881,10 @@ public abstract class SubSystemConfiguration implements ISubSystemConfiguration /** * Get all the filter pool managers for all the profiles, active or not. - * Why do this? Because we need to in order to allow cross references from + * This allows cross references from * one subsystem in one profile to filter pools in any other profile. */ - public ISystemFilterPoolManager[] restoreAllFilterPoolManagersForAllProfiles() + public ISystemFilterPoolManager[] getAllSystemFilterPoolManagers() { ISystemProfile[] profiles = SystemStartHere.getSystemProfileManager().getSystemProfiles(); ISystemFilterPoolManager[] allMgrs = new ISystemFilterPoolManager[profiles.length]; diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/internal/ui/subsystems/SubSystemConfigurationProxyAdapter.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/internal/ui/subsystems/SubSystemConfigurationProxyAdapter.java new file mode 100644 index 00000000000..dc611440c5e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/internal/ui/subsystems/SubSystemConfigurationProxyAdapter.java @@ -0,0 +1,68 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. 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 + * + * Contributors: + * David Dykstal (IBM) - 168870: created adapter for ui portions of SubSystemConfigurationProxy + ********************************************************************************/ +package org.eclipse.rse.internal.ui.subsystems; + +import java.net.URL; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.RSEUIPlugin; + +public class SubSystemConfigurationProxyAdapter { + + private static final ImageDescriptor defaultNormalDescriptor = RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CONNECTION_ID); + private static final ImageDescriptor defaultLiveDescriptor = RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CONNECTIONLIVE_ID); + private ISubSystemConfigurationProxy proxy = null; + + /** + * Create the adapter. This should be done only by the adapter factory. + * @param proxy The {@link ISubSystemConfigurationProxy} for which to create this adapter. + */ + public SubSystemConfigurationProxyAdapter(ISubSystemConfigurationProxy proxy) { + this.proxy = proxy; + } + + /** + * Get an image descriptor given an image location + * @param url the location of the image + * @param defaultDescriptor the descriptor to use if a resource at this location is not found + * @return an image descriptor + */ + private ImageDescriptor getDescriptor(URL url, ImageDescriptor defaultDescriptor) { + ImageDescriptor result = null; + if (url != null) { + result = ImageDescriptor.createFromURL(url); + } + if (result == null) { + result = defaultDescriptor; + } + return result; + } + + /** + * @return the image descriptor representing the non-connected state of this particular subsystem + */ + public ImageDescriptor getImageDescriptor() { + URL url = proxy.getImageLocation(); + ImageDescriptor result = getDescriptor(url, defaultNormalDescriptor); + return result; + } + + /** + * @return the image descriptor representing the connected state of the particular subsystem + */ + public ImageDescriptor getLiveImageDescriptor() { + URL url = proxy.getLiveImageLocation(); + ImageDescriptor result = getDescriptor(url, defaultLiveDescriptor); + return result; + } + +} diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/internal/ui/subsystems/SubSystemConfigurationProxyAdapterFactory.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/internal/ui/subsystems/SubSystemConfigurationProxyAdapterFactory.java new file mode 100644 index 00000000000..bac1e543798 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/internal/ui/subsystems/SubSystemConfigurationProxyAdapterFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. 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 + * + * Contributors: + * David Dykstal (IBM) - 168870: created adapter for ui portions of SubSystemConfigurationProxy + ********************************************************************************/ +package org.eclipse.rse.internal.ui.subsystems; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy; + +/** + * This class is used to create the adapater for a SubSystemConfigurationProxy. + * It is meant to be used in the AdapterManager framework of the platform. + * Internal Use Only. + */ +public class SubSystemConfigurationProxyAdapterFactory implements IAdapterFactory { + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) { + Object result = null; + if (adaptableObject instanceof ISubSystemConfigurationProxy) { + if (adapterType == SubSystemConfigurationProxyAdapter.class) { + ISubSystemConfigurationProxy proxy = (ISubSystemConfigurationProxy) adaptableObject; + result = new SubSystemConfigurationProxyAdapter(proxy); + } + } + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() { + return new Class[] {SubSystemConfigurationProxyAdapter.class}; + } + +}