1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 07:35:24 +02:00

[fix] [176481] [api] "Clear Passwords" action must be removed from context menu if passwords are not supported for the selected system

This commit is contained in:
Uwe Stieber 2007-03-06 12:56:08 +00:00
parent 4b024caabd
commit 7314d6858c
2 changed files with 106 additions and 33 deletions

View file

@ -102,43 +102,68 @@ public class SystemViewConnectionAdapter
* @param shell Shell of viewer
* @param menuGroup recommended menu group to add actions to. If added to another group, you must be sure to create that group first.
*/
public void addActions(SystemMenuManager menu, IStructuredSelection selection, Shell shell, String menuGroup)
{
if (!actionsCreated)
createActions();
//updateAction.setValue(null); // reset
menu.add(menuGroup, anotherConnectionAction);
menu.add(menuGroup, copyAction);
menu.add(menuGroup, moveAction);
menu.add(menuGroup, upAction);
menu.add(menuGroup, downAction);
// MJB: RE defect 40854
addConnectOrDisconnectAction(menu, menuGroup, selection);
menu.add(menuGroup, clearPasswordAction);
IRSESystemType sysType = RSECorePlugin.getDefault().getRegistry().getSystemType((((IHost)selection.getFirstElement()).getSystemType()));
RSESystemTypeAdapter sysTypeAdapter = (RSESystemTypeAdapter)(sysType.getAdapter(IRSESystemType.class));
// yantzi: artemis 6.0, offline support, only add work offline action for system types that support offline mode
if (sysTypeAdapter.isEnableOffline(sysType))
{
menu.add(menuGroup, offlineAction);
}
public void addActions(SystemMenuManager menu, IStructuredSelection selection, Shell shell, String menuGroup) {
if (!actionsCreated) createActions();
// bugzilla#161195: _ALL_ actions needs to be passed to the system type for approval.
// _Never_ add any action without the system type provider having said ok to this.
IHost host = (IHost)selection.getFirstElement();
IRSESystemType sysType = RSECorePlugin.getDefault().getRegistry().getSystemType((host.getSystemType()));
Object adapter = sysType.getAdapter(IRSESystemType.class);
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
//updateAction.setValue(null); // reset
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), anotherConnectionAction))
menu.add(menuGroup, anotherConnectionAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), copyAction))
menu.add(menuGroup, copyAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), moveAction))
menu.add(menuGroup, moveAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), upAction))
menu.add(menuGroup, upAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), downAction))
menu.add(menuGroup, downAction);
// MJB: RE defect 40854
addConnectOrDisconnectAction(menu, menuGroup, selection);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), clearPasswordAction))
menu.add(menuGroup, clearPasswordAction);
// yantzi: artemis 6.0, offline support, only add work offline action for system types that support offline mode
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), offlineAction))
menu.add(menuGroup, offlineAction);
}
private void addConnectOrDisconnectAction(SystemMenuManager menu, String menuGroup, IStructuredSelection selection)
{
IHost sysCon = (IHost) selection.getFirstElement();
ISystemRegistry sysReg = RSEUIPlugin.getTheSystemRegistry();
boolean anySupportsConnect = sysReg.isAnySubSystemSupportsConnect(sysCon);
private void addConnectOrDisconnectAction(SystemMenuManager menu, String menuGroup, IStructuredSelection selection) {
IHost host = (IHost)selection.getFirstElement();
IRSESystemType sysType = RSECorePlugin.getDefault().getRegistry().getSystemType((host.getSystemType()));
Object adapter = sysType.getAdapter(IRSESystemType.class);
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
ISystemRegistry sysReg = RSEUIPlugin.getTheSystemRegistry();
boolean anySupportsConnect = sysReg.isAnySubSystemSupportsConnect(host);
if (anySupportsConnect) {
boolean anyConnected = sysReg.isAnySubSystemConnected(sysCon);
boolean allConnected = sysReg.areAllSubSystemsConnected(sysCon);
if (!allConnected) menu.add(menuGroup, connectAction);
if (anyConnected) menu.add(menuGroup, disconnectAction);
boolean anyConnected = sysReg.isAnySubSystemConnected(host);
boolean allConnected = sysReg.areAllSubSystemsConnected(host);
if (!allConnected && (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), connectAction)))
menu.add(menuGroup, connectAction);
if (anyConnected && (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), disconnectAction)))
menu.add(menuGroup, disconnectAction);
}
}

View file

@ -23,10 +23,17 @@ import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.IRSESystemTypeConstants;
import org.eclipse.rse.core.RSEPreferencesManager;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.rse.ui.actions.SystemClearAllPasswordsAction;
import org.eclipse.rse.ui.actions.SystemWorkOfflineAction;
import org.eclipse.rse.ui.wizards.registries.IRSEWizardDescriptor;
import org.osgi.framework.Bundle;
@ -235,6 +242,47 @@ public class RSESystemTypeAdapter extends RSEAdapter implements IRSESystemTypeCo
return result;
}
/**
* Called to approve the contribution of the specified action to the context menu of the
* specified host of the specified system type. System type providers should implement
* this method in a way that specific actions might be denied, but all other action contributions,
* including unknown action contributions, should be accepted.
* <p>
* This method is called from:<br>
* <ul>
* <li>SystemViewConnectioAdapter.addActions(...)</li>
* </ul>
*
* @param host The host object.
* @param systemType The system type object.
* @param menuManager The menu manager.
* @param action The contributed action.
*
* @return <code>True</code> if the contributed action is accepted for the specified context, <code>false</code> otherwise.
*/
public boolean acceptContextMenuActionContribution(IHost host, IRSESystemType systemType, IMenuManager menuManager, IAction action) {
// The SystemWorkOfflineAction is accepted if isEnabledOffline is returning true
if (action instanceof SystemWorkOfflineAction) {
return isEnableOffline(systemType);
}
// SystemClearAllPasswordsAction is accepted only if passwords are supported
// by any of the sub systems.
if (action instanceof SystemClearAllPasswordsAction) {
ISystemRegistry registry = RSEUIPlugin.getDefault().getSystemRegistry();
IConnectorService[] connectorServices = registry.getConnectorServices(host);
boolean passwordsSupported = false;
for (int i = 0; i < connectorServices.length && passwordsSupported == false; i++) {
passwordsSupported |= !connectorServices[i].isSuppressSignonPrompt();
}
return passwordsSupported;
}
// Accept all the rest not special handled here.
return true;
}
/**
* Checks if the given wizard descriptor is accepted for the system types the
* adapter is covering.