1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 13:05:22 +02:00

[216266] Consider stateless subsystems (supportsSubSystemConnect==false) for delete-host and connect-all actions

This commit is contained in:
Martin Oberhuber 2008-01-23 13:44:15 +00:00
parent 10515e6501
commit a1b0c1d252
4 changed files with 99 additions and 68 deletions

View file

@ -13,6 +13,7 @@
* Contributors: * Contributors:
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
* Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect() * Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect()
* Martin Oberhuber (Wind River) - [216266] Consider stateless subsystems (supportsSubSystemConnect==false)
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.ui.actions; package org.eclipse.rse.internal.ui.actions;
@ -57,12 +58,15 @@ public class SystemConnectAllSubSystemsAction extends SystemBaseAction
List failedSystems = new ArrayList(); List failedSystems = new ArrayList();
try try
{ {
//forced instantiation of all subsystems
ISubSystem[] subsystems = _connection.getSubSystems(); ISubSystem[] subsystems = _connection.getSubSystems();
for (int i = 0; i < subsystems.length; i++) for (int i = 0; i < subsystems.length; i++)
{ {
ISubSystem subsystem = subsystems[i]; ISubSystem subsystem = subsystems[i];
IConnectorService system = subsystem.getConnectorService(); IConnectorService system = subsystem.getConnectorService();
if (!subsystem.isConnected() && !failedSystems.contains(system)) if (!subsystem.isConnected()
&& subsystem.getSubSystemConfiguration().supportsSubSystemConnect()
&& !failedSystems.contains(system))
{ {
try try
{ {

View file

@ -17,11 +17,14 @@
package org.eclipse.rse.internal.ui.actions; package org.eclipse.rse.internal.ui.actions;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry; import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.internal.ui.SystemResources; import org.eclipse.rse.internal.ui.SystemResources;
import org.eclipse.rse.ui.ISystemContextMenuConstants; import org.eclipse.rse.ui.ISystemContextMenuConstants;
import org.eclipse.rse.ui.actions.SystemBaseAction; import org.eclipse.rse.ui.actions.SystemBaseAction;
@ -29,7 +32,7 @@ import org.eclipse.swt.widgets.Shell;
/** /**
* This is the action forconnecting all subsystems for a given connection. * This is the action for disconnecting all subsystems for a given connection.
*/ */
public class SystemDisconnectAllSubSystemsAction extends SystemBaseAction public class SystemDisconnectAllSubSystemsAction extends SystemBaseAction
{ {
@ -49,6 +52,25 @@ public class SystemDisconnectAllSubSystemsAction extends SystemBaseAction
// TODO help for connect all // TODO help for connect all
//setHelp(RSEUIPlugin.HELPPREFIX+"actn0022"); //setHelp(RSEUIPlugin.HELPPREFIX+"actn0022");
} }
private static ISubSystem[] getDisconnectableSubsystems(Object element)
{
ISubSystem[] result = null;
if (element instanceof IHost) {
IHost host = (IHost)element;
ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry();
ISubSystem[] ss = sr.getSubSystems(host, false);
List l = new ArrayList();
for (int i=0; i<ss.length; i++) {
if (ss[i].isConnected() && ss[i].getSubSystemConfiguration().supportsSubSystemConnect()) {
l.add(ss[i]);
}
}
result = (ISubSystem[])l.toArray(new ISubSystem[l.size()]);
}
return result;
}
/** /**
* Override of parent. Called when testing if action should be enabled base on current * Override of parent. Called when testing if action should be enabled base on current
* selection. We check the selected object is one of our subsystems, and if we are * selection. We check the selected object is one of our subsystems, and if we are
@ -59,8 +81,10 @@ public class SystemDisconnectAllSubSystemsAction extends SystemBaseAction
if ( !(obj instanceof IHost) || if ( !(obj instanceof IHost) ||
!(sr.isAnySubSystemConnected((IHost)obj) )) !(sr.isAnySubSystemConnected((IHost)obj) ))
return false; return false;
else else {
return true; ISubSystem[] ss = getDisconnectableSubsystems(obj);
return (ss!=null && ss.length>0);
}
} }
/** /**

View file

@ -29,6 +29,7 @@
* David McKnight (IBM) - [191288] Up To Action doesn't go all the way back to the connections * David McKnight (IBM) - [191288] Up To Action doesn't go all the way back to the connections
* Uwe Stieber (Wind River) - [199032] [api] Remove method acceptContextMenuActionContribution(...) from RSESystemTypeAdapter * Uwe Stieber (Wind River) - [199032] [api] Remove method acceptContextMenuActionContribution(...) from RSESystemTypeAdapter
* Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread
* Martin Oberhuber (Wind River) - [216266] Consider stateless subsystems (supportsSubSystemConnect==false)
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.ui.view; package org.eclipse.rse.internal.ui.view;
@ -592,13 +593,17 @@ public class SystemViewConnectionAdapter
{ {
if (element instanceof IHost) if (element instanceof IHost)
{ {
IHost host = (IHost)element;
ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry(); ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry();
if (((IHost)element).getSystemType().isLocal()) //do not allow delete if any subsystem is connected but supports disconnect.
{ //specifically, this allows deletion of "Local" which is always connected (but does not support disconnect)
// local is always connected so always allow delete //need to get subsystems from registry instead of host in order to be lazy:
return true; //subsystems which are not yet instantiated do not need to be considered.
ISubSystem[] ss = sr.getSubSystems(host, false);
for (int i=0; i<ss.length; i++) {
if (ss[i].isConnected() && ss[i].getSubSystemConfiguration().supportsSubSystemConnect())
return false;
} }
return !sr.isAnySubSystemConnected((IHost)element);
} }
return true; return true;
} }

View file

@ -38,6 +38,7 @@
* David McKnight (IBM) - [207100] adding ISystemRegistry.isRegisteredSystemRemoteChangeListener * David McKnight (IBM) - [207100] adding ISystemRegistry.isRegisteredSystemRemoteChangeListener
* Martin Oberhuber (Wind River) - [206742] Make SystemHostPool thread-safe * Martin Oberhuber (Wind River) - [206742] Make SystemHostPool thread-safe
* David Dykstal (IBM) - [210537] removed exception handling for SystemHostPool, no longer needed * David Dykstal (IBM) - [210537] removed exception handling for SystemHostPool, no longer needed
* Martin Oberhuber (Wind River) - [216266] improved non-forced getSubSystems() code, removed getSubSystemsLazily()
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.ui.internal.model; package org.eclipse.rse.ui.internal.model;
@ -912,30 +913,30 @@ public class SystemRegistry implements ISystemRegistry
public ISubSystem[] getSubSystems(IHost conn, boolean force) public ISubSystem[] getSubSystems(IHost conn, boolean force)
{ {
ISubSystem[] subsystems = null; ISubSystem[] subsystems = null;
Vector v = new Vector();
if (subsystemConfigurationProxies != null) if (subsystemConfigurationProxies != null)
{ {
List v = new ArrayList();
for (int idx = 0; idx < subsystemConfigurationProxies.length; idx++) for (int idx = 0; idx < subsystemConfigurationProxies.length; idx++)
{ {
// if (subsystemConfigurationProxies[idx].appliesToSystemType(conn.getSystemType())) if (!force && !subsystemConfigurationProxies[idx].isSubSystemConfigurationActive()) {
// { //avoid instantiation if not forced.
continue;
}
if (subsystemConfigurationProxies[idx].appliesToSystemType(conn.getSystemType()))
{
ISubSystemConfiguration factory = subsystemConfigurationProxies[idx].getSubSystemConfiguration(); ISubSystemConfiguration factory = subsystemConfigurationProxies[idx].getSubSystemConfiguration();
if (factory != null) if (factory != null)
{ {
ISubSystem[] sss = factory.getSubSystems(conn, force); ISubSystem[] sss = factory.getSubSystems(conn, force);
if (sss != null) if (sss != null)
for (int jdx = 0; jdx < sss.length; jdx++) for (int jdx = 0; jdx < sss.length; jdx++)
v.addElement(sss[jdx]); v.add(sss[jdx]);
} }
// }
} }
//if (v.size() > 0) }
//{ subsystems = (ISubSystem[])v.toArray(new ISubSystem[v.size()]);
subsystems = new ISubSystem[v.size()];
for (int idx = 0; idx < v.size(); idx++)
subsystems[idx] = (ISubSystem) v.elementAt(idx);
//}
} }
return subsystems; return subsystems;
} }
@ -1148,44 +1149,6 @@ public class SystemRegistry implements ISystemRegistry
return dataStream.toString(); return dataStream.toString();
} }
/**
* Return list of subsystem objects for a given connection, but does not force
* as-yet-non-restored subsystems to come to life.
* <p>
* To protect against crashes, if there are no subsystems, an array of length zero is returned.
*/
public ISubSystem[] getSubSystemsLazily(IHost conn)
{
ISubSystem[] subsystems = null;
Vector v = new Vector();
if (subsystemConfigurationProxies != null)
{
for (int idx = 0; idx < subsystemConfigurationProxies.length; idx++)
{
if (subsystemConfigurationProxies[idx].appliesToSystemType(conn.getSystemType()) && subsystemConfigurationProxies[idx].isSubSystemConfigurationActive())
{
ISubSystemConfiguration factory = subsystemConfigurationProxies[idx].getSubSystemConfiguration();
if (factory != null)
{
ISubSystem[] sss = factory.getSubSystems(conn, ISubSystemConfiguration.LAZILY);
if (sss != null)
for (int jdx = 0; jdx < sss.length; jdx++)
v.addElement(sss[jdx]);
}
}
}
//if (v.size() > 0)
//{
subsystems = new ISubSystem[v.size()];
for (int idx = 0; idx < v.size(); idx++)
subsystems[idx] = (ISubSystem) v.elementAt(idx);
//}
}
return subsystems;
}
public ISubSystem[] getSubsystems(IHost connection, Class subsystemInterface) public ISubSystem[] getSubsystems(IHost connection, Class subsystemInterface)
{ {
List matches = new ArrayList(); List matches = new ArrayList();
@ -2355,7 +2318,7 @@ public class SystemRegistry implements ISystemRegistry
public boolean isAnySubSystemConnected(IHost conn) public boolean isAnySubSystemConnected(IHost conn)
{ {
boolean any = false; boolean any = false;
ISubSystem[] subsystems = getSubSystemsLazily(conn); ISubSystem[] subsystems = getSubSystems(conn, false);
if (subsystems == null) if (subsystems == null)
return false; return false;
for (int idx = 0; !any && (idx < subsystems.length); idx++) for (int idx = 0; !any && (idx < subsystems.length); idx++)
@ -2367,6 +2330,29 @@ public class SystemRegistry implements ISystemRegistry
return any; return any;
} }
/**
* Check if there are any subsystem configurations that have not yet been instantiated
* and apply to the given system type.
* @param systemType the system type to check
* @return <code>true</code> if there are any matching subsystem configurations not yet instantiated.
*/
public boolean hasInactiveSubsystemConfigurations(IRSESystemType systemType)
{
if (subsystemConfigurationProxies != null)
{
for (int idx = 0; idx < subsystemConfigurationProxies.length; idx++)
{
if (!subsystemConfigurationProxies[idx].isSubSystemConfigurationActive()
&& subsystemConfigurationProxies[idx].appliesToSystemType(systemType))
{
return true;
}
}
}
return false;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.core.model.ISystemRegistry#areAllSubSystemsConnected(org.eclipse.rse.core.model.IHost) * @see org.eclipse.rse.core.model.ISystemRegistry#areAllSubSystemsConnected(org.eclipse.rse.core.model.IHost)
@ -2374,15 +2360,27 @@ public class SystemRegistry implements ISystemRegistry
public boolean areAllSubSystemsConnected(IHost conn) public boolean areAllSubSystemsConnected(IHost conn)
{ {
boolean all = true; boolean all = true;
ISubSystem[] subsystems = getSubSystemsLazily(conn); if (hasInactiveSubsystemConfigurations(conn.getSystemType())) {
if (subsystems == null) //any uninitialized subsystem configuration that applies to the system type can not be connected.
//TODO this may change in the future: We might want to have markup in the plugin.xml
//to check whether a subsystem configuration is actually connectable or not
return false; return false;
}
//May force load subsystem configurations here because there are no inactive ones for our system type.
//Do we need to force load actual subsystems too, just to check if they are connected?
ISubSystem[] subsystems = getSubSystems(conn);
if (subsystems == null) {
//If there are no subsystems, they are all connected.
return true;
}
for (int idx = 0; all && (idx < subsystems.length); idx++) for (int idx = 0; all && (idx < subsystems.length); idx++)
{ {
ISubSystem ss = subsystems[idx]; ISubSystem ss = subsystems[idx];
if (!ss.isConnected()) if (!ss.isConnected() && ss.getSubSystemConfiguration().supportsSubSystemConnect())
{ {
//we ignore unconnected subsystems that can not be connected anyways.
return false; return false;
} }
} }
@ -2395,18 +2393,18 @@ public class SystemRegistry implements ISystemRegistry
*/ */
public void disconnectAllSubSystems(IHost conn) public void disconnectAllSubSystems(IHost conn)
{ {
// get subsystems lazily, because not instantiated ones cannot be disconnected anyways.
ISubSystem[] subsystems = getSubSystemsLazily(conn); ISubSystem[] subsystems = getSubSystems(conn, false);
if (subsystems == null) if (subsystems == null)
return; return;
// dy: defect 47281, user repeaetedly prompted to disconnect if there is an open file // dy: defect 47281, user repeatedly prompted to disconnect if there is an open file
// and they keep hitting cancel. // and they keep hitting cancel.
boolean cancelled = false; boolean cancelled = false;
for (int idx = 0; idx < subsystems.length && !cancelled; idx++) for (int idx = 0; idx < subsystems.length && !cancelled; idx++)
{ {
ISubSystem ss = subsystems[idx]; ISubSystem ss = subsystems[idx];
if (ss.isConnected()) if (ss.isConnected() && ss.getSubSystemConfiguration().supportsSubSystemConnect())
{ {
try try
{ {
@ -2415,7 +2413,7 @@ public class SystemRegistry implements ISystemRegistry
} }
catch (InterruptedException exc) catch (InterruptedException exc)
{ {
System.out.println("Cacnelled"); //$NON-NLS-1$ System.out.println("Cancelled"); //$NON-NLS-1$
cancelled = true; cancelled = true;
} }
catch (Exception exc) catch (Exception exc)