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

[cleanup] [161195] Polished API for approving programmatical menu action contributions from system type provider

This commit is contained in:
Uwe Stieber 2007-03-06 15:44:05 +00:00
parent c0cd48ed0c
commit d546610333
2 changed files with 145 additions and 32 deletions

View file

@ -37,6 +37,8 @@ import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemMenuManager;
import org.eclipse.rse.ui.SystemResources;
import org.eclipse.rse.ui.actions.SystemClearAllPasswordsAction;
import org.eclipse.rse.ui.actions.SystemCommonDeleteAction;
import org.eclipse.rse.ui.actions.SystemCommonRenameAction;
import org.eclipse.rse.ui.actions.SystemConnectAllSubSystemsAction;
import org.eclipse.rse.ui.actions.SystemCopyConnectionAction;
import org.eclipse.rse.ui.actions.SystemDisconnectAllSubSystemsAction;
@ -44,6 +46,10 @@ import org.eclipse.rse.ui.actions.SystemMoveConnectionAction;
import org.eclipse.rse.ui.actions.SystemMoveDownConnectionAction;
import org.eclipse.rse.ui.actions.SystemMoveUpConnectionAction;
import org.eclipse.rse.ui.actions.SystemNewConnectionFromExistingConnectionAction;
import org.eclipse.rse.ui.actions.SystemOpenExplorerPerspectiveAction;
import org.eclipse.rse.ui.actions.SystemRefreshAction;
import org.eclipse.rse.ui.actions.SystemShowInMonitorAction;
import org.eclipse.rse.ui.actions.SystemShowInTableAction;
import org.eclipse.rse.ui.actions.SystemWorkOfflineAction;
import org.eclipse.rse.ui.validators.ISystemValidator;
import org.eclipse.rse.ui.validators.ValidatorSpecialChar;
@ -53,6 +59,7 @@ import org.eclipse.rse.ui.view.ISystemPropertyConstants;
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
import org.eclipse.rse.ui.view.ISystemViewInputProvider;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.framelist.GoIntoAction;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
@ -93,7 +100,18 @@ public class SystemViewConnectionAdapter
// -------------------
private static PropertyDescriptor[] propertyDescriptorArray = null;
/**
* Returns the system type object for the specified host.
*
* @param host The host to get the system type object from.
* @return The system type object or <code>null</code>.
*/
private IRSESystemType getSystemTypeForHost(IHost host) {
if (host != null) {
return RSECorePlugin.getDefault().getRegistry().getSystemType((host.getSystemType()));
}
return null;
}
/**
* Returns any actions that should be contributed to the popup menu
* for the given element.
@ -108,46 +126,46 @@ public class SystemViewConnectionAdapter
// 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);
IRSESystemType sysType = getSystemTypeForHost(host);
Object adapter = sysType != null ? sysType.getAdapter(IRSESystemType.class) : null;
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
//updateAction.setValue(null); // reset
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), anotherConnectionAction))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, anotherConnectionAction.getClass()))
menu.add(menuGroup, anotherConnectionAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), copyAction))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, copyAction.getClass()))
menu.add(menuGroup, copyAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), moveAction))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, moveAction.getClass()))
menu.add(menuGroup, moveAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), upAction))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, upAction.getClass()))
menu.add(menuGroup, upAction);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), downAction))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, downAction.getClass()))
menu.add(menuGroup, downAction);
// MJB: RE defect 40854
addConnectOrDisconnectAction(menu, menuGroup, selection);
if (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), clearPasswordAction))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, clearPasswordAction.getClass()))
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))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, offlineAction.getClass()))
menu.add(menuGroup, offlineAction);
}
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);
IRSESystemType sysType = getSystemTypeForHost(host);
Object adapter = sysType != null ? sysType.getAdapter(IRSESystemType.class) : null;
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
ISystemRegistry sysReg = RSEUIPlugin.getTheSystemRegistry();
@ -158,11 +176,11 @@ public class SystemViewConnectionAdapter
boolean allConnected = sysReg.areAllSubSystemsConnected(host);
if (!allConnected && (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), connectAction)))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, connectAction.getClass())))
menu.add(menuGroup, connectAction);
if (anyConnected && (sysTypeAdapter == null
|| sysTypeAdapter.acceptContextMenuActionContribution(host, sysType, menu.getMenuManager(), disconnectAction)))
|| sysTypeAdapter.acceptContextMenuActionContribution(host, disconnectAction.getClass())))
menu.add(menuGroup, disconnectAction);
}
}
@ -182,17 +200,111 @@ public class SystemViewConnectionAdapter
actionsCreated = true;
}
/* (non-Javadoc)
* @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showDelete(java.lang.Object)
*/
public boolean showDelete(Object element) {
// 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.
if (element instanceof IHost) {
IRSESystemType sysType = getSystemTypeForHost((IHost)element);
Object adapter = sysType != null ? sysType.getAdapter(IRSESystemType.class) : null;
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
if (sysTypeAdapter != null) {
return sysTypeAdapter.acceptContextMenuActionContribution((IHost)element, SystemCommonDeleteAction.class);
}
}
return super.showDelete(element);
}
/* (non-Javadoc)
* @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showGenericShowInTableAction(java.lang.Object)
*/
public boolean showGenericShowInTableAction(Object element) {
// 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.
if (element instanceof IHost) {
IRSESystemType sysType = getSystemTypeForHost((IHost)element);
Object adapter = sysType != null ? sysType.getAdapter(IRSESystemType.class) : null;
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
if (sysTypeAdapter != null) {
boolean accepted = false;
Class[] affectedClasses = new Class[] { SystemShowInTableAction.class, SystemShowInMonitorAction.class };
for (int i = 0; i < affectedClasses.length && accepted == false; i++) {
accepted |= sysTypeAdapter.acceptContextMenuActionContribution((IHost)element, affectedClasses[i]);
}
return accepted;
}
}
return super.showGenericShowInTableAction(element);
}
/* (non-Javadoc)
* @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showOpenViewActions(java.lang.Object)
*/
public boolean showOpenViewActions(Object element) {
// 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.
if (element instanceof IHost) {
IRSESystemType sysType = getSystemTypeForHost((IHost)element);
Object adapter = sysType != null ? sysType.getAdapter(IRSESystemType.class) : null;
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
if (sysTypeAdapter != null) {
boolean accepted = false;
Class[] affectedClasses = new Class[] { GoIntoAction.class, SystemOpenExplorerPerspectiveAction.class };
for (int i = 0; i < affectedClasses.length && accepted == false; i++) {
accepted |= sysTypeAdapter.acceptContextMenuActionContribution((IHost)element, affectedClasses[i]);
}
return accepted;
}
}
return super.showOpenViewActions(element);
}
/* (non-Javadoc)
* @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showRefresh(java.lang.Object)
*/
public boolean showRefresh(Object element) {
// 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.
if (element instanceof IHost) {
IRSESystemType sysType = getSystemTypeForHost((IHost)element);
Object adapter = sysType != null ? sysType.getAdapter(IRSESystemType.class) : null;
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
if (sysTypeAdapter != null) {
return sysTypeAdapter.acceptContextMenuActionContribution((IHost)element, SystemRefreshAction.class);
}
}
return super.showRefresh(element);
}
/* (non-Javadoc)
* @see org.eclipse.rse.ui.view.AbstractSystemViewAdapter#showRename(java.lang.Object)
*/
public boolean showRename(Object element) {
// 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.
if (element instanceof IHost) {
IRSESystemType sysType = getSystemTypeForHost((IHost)element);
Object adapter = sysType != null ? sysType.getAdapter(IRSESystemType.class) : null;
RSESystemTypeAdapter sysTypeAdapter = adapter instanceof RSESystemTypeAdapter ? (RSESystemTypeAdapter)adapter : null;
if (sysTypeAdapter != null) {
return sysTypeAdapter.acceptContextMenuActionContribution((IHost)element, SystemCommonRenameAction.class);
}
}
return super.showRename(element);
}
/**
* Returns an image descriptor for the image. More efficient than getting the image.
* @param element The element for which an image is desired
*/
public ImageDescriptor getImageDescriptor(Object element) {
IHost connection = (IHost)element;
String systemTypeName = connection.getSystemType();
boolean anyConnected = RSEUIPlugin.getTheSystemRegistry().isAnySubSystemConnected(connection);
ImageDescriptor descriptor = null;
IRSESystemType systemType = RSECorePlugin.getDefault().getRegistry().getSystemType(systemTypeName);
IRSESystemType systemType = getSystemTypeForHost(connection);
if (systemType != null) {
RSESystemTypeAdapter sysTypeAdapter = (RSESystemTypeAdapter)(systemType.getAdapter(IRSESystemType.class));
if (anyConnected) {

View file

@ -23,11 +23,10 @@ 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.RSECorePlugin;
import org.eclipse.rse.core.RSEPreferencesManager;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry;
@ -244,32 +243,34 @@ public class RSESystemTypeAdapter extends RSEAdapter implements IRSESystemTypeCo
/**
* 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.
* Called to approve the contribution of the specified action class to the context menu of the
* specified host.
* <p>
* <b>Note:</b> 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>
* <li>SystemViewConnectionAdapter.addActions(...)</li>
* <li>SystemViewConnectionAdapter.showDelete(...)</li>
* </ul>
*
* @param host The host object.
* @param systemType The system type object.
* @param menuManager The menu manager.
* @param action The contributed action.
* @param host The host object. Must be not <code>null</code>.
* @param actionClass The contributed action. Must be not <code>null</code>.
*
* @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) {
public boolean acceptContextMenuActionContribution(IHost host, Class actionClass) {
assert host != null && actionClass != null;
// The SystemWorkOfflineAction is accepted if isEnabledOffline is returning true
if (action instanceof SystemWorkOfflineAction) {
return isEnableOffline(systemType);
if (actionClass.equals(SystemWorkOfflineAction.class)) {
return isEnableOffline(RSECorePlugin.getDefault().getRegistry().getSystemType(host.getSystemType()));
}
// SystemClearAllPasswordsAction is accepted only if passwords are supported
// by any of the sub systems.
if (action instanceof SystemClearAllPasswordsAction) {
if (actionClass.equals(SystemClearAllPasswordsAction.class)) {
ISystemRegistry registry = RSEUIPlugin.getDefault().getSystemRegistry();
IConnectorService[] connectorServices = registry.getConnectorServices(host);
boolean passwordsSupported = false;