getDefault()
method.
*
* @see IDetailPaneFactory
* @see IDetailPane
* @since 3.3
*/
public class DetailPaneManager {
/**
* Acts as a proxy between the detail pane manager and the factories contributed
* to the extension point. Only loads information from the plug-in xml and only
* instantiates the specified factory if required (lazy loading).
*/
private class DetailPaneFactoryExtension implements IDetailPaneFactory{
private IConfigurationElement fConfigElement;
private IDetailPaneFactory fFactory;
private Expression fEnablementExpression;
public DetailPaneFactoryExtension(IConfigurationElement configElement){
fConfigElement = configElement;
}
/**
* Instantiates the factory and asks it to produce the IDetailPane for
* the given ID
* @param paneID the identifier of the detail pane to create
* @return the new detail pane or null
if the backing {@link IDetailPaneFactory} is null
*/
@Override
public IDetailPane createDetailPane(String paneID){
if (getFactory() != null){
return getFactory().createDetailPane(paneID);
}
return null;
}
/**
* Instantiates the factory and asks it for the set of detail pane
* IDs that the factory can produce for the given selection.
* @param selection the current view selection
* @return the set of detail pane type for the given selection or an empty set, never null
*/
@Override
public Setnull
if the backing {@link IDetailPaneFactory} is null
*/
@Override
public String getDefaultDetailPane(IStructuredSelection selection) {
if (getFactory() != null){
return getFactory().getDefaultDetailPane(selection);
}
return null;
}
/**
* Instantiates the factory and asks it to produce the name of the detail pane
* for the given ID.
* @param paneID the detail pane identifier
* @return the name of the detail pane or null
if the backing {@link IDetailPaneFactory} is null
*/
@Override
public String getDetailPaneName(String paneID) {
if (getFactory() != null){
return getFactory().getDetailPaneName(paneID);
}
return null;
}
/**
* Instantiates the factory and asks it to produce the description of the
* detail pane for the given ID.
* @param paneID the detail pane identifier
* @return the description of the detail pane or null
if the backing {@link IDetailPaneFactory} is null
*/
@Override
public String getDetailPaneDescription(String paneID) {
if (getFactory() != null){
return getFactory().getDetailPaneDescription(paneID);
}
return null;
}
/**
* Returns the instantiated factory specified by the class property.
* @return the singleton {@link IDetailPaneFactory}
*/
private IDetailPaneFactory getFactory(){
if (fFactory != null) {
return fFactory;
}
try{
Object obj = fConfigElement.createExecutableExtension(IConfigurationElementConstants.CLASS);
if(obj instanceof IDetailPaneFactory) {
fFactory = (IDetailPaneFactory)obj;
} else {
throw new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.INTERNAL_ERROR, "org.eclipse.debug.ui.detailFactories extension failed to load a detail factory because the specified class does not implement org.eclipse.debug.ui.IDetailPaneFactory. Class specified was: " + obj, null)); //$NON-NLS-1$
}
} catch (CoreException e){
DebugUIPlugin.log(e.getStatus());
fFactory = null;
}
return fFactory;
}
/**
* Checks if the enablement expression for the factory evaluates to true for the
* given selection.
* @param selection the current view selection
* @return true
if the backing {@link IDetailPaneFactory} applies to the given selection, false
otherwise
*/
public boolean isEnabled(IStructuredSelection selection) {
boolean enabled = false;
// Only the default factory should be enabled for null selections
if (selection == null || selection.isEmpty()){
return "org.eclipse.debug.ui.defaultDetailPaneFactory".equals(fConfigElement.getAttribute(IConfigurationElementConstants.ID)); //$NON-NLS-1$
}
Expression expression = getEnablementExpression();
if (expression != null) {
List> list = selection.toList();
IEvaluationContext context = DebugUIPlugin.createEvaluationContext(list);
context.addVariable("selection", list); //$NON-NLS-1$
enabled = evalEnablementExpression(context, expression);
} else {
enabled = true;
}
return enabled;
}
/**
* Evaluate the given expression within the given context and return
* the result. Returns true
iff result is either TRUE or NOT_LOADED.
* This allows optimistic inclusion of shortcuts before plug-ins are loaded.
* Returns false
if expression is null
.
*
* @param exp the enablement expression to evaluate or null
* @param context the context of the evaluation. Usually, the
* user's selection.
* @return the result of evaluating the expression
*/
private boolean evalEnablementExpression(IEvaluationContext context, Expression exp) {
try{
if (exp != null){
EvaluationResult result = exp.evaluate(context);
if (result == EvaluationResult.TRUE || result == EvaluationResult.NOT_LOADED){
return true;
}
}
} catch (CoreException e){
DebugUIPlugin.log(e.getStatus());
}
return false;
}
/**
* Returns an expression that represents the enablement logic for the
* detail pane factory or null
if none.
*
* @return an evaluatable expression or null
*/
private Expression getEnablementExpression(){
// all of this stuff is optional, so...tedious testing is required
if (fEnablementExpression == null) {
try{
IConfigurationElement[] elements = fConfigElement.getChildren(ExpressionTagNames.ENABLEMENT);
IConfigurationElement enablement = elements.length > 0 ? elements[0] : null;
if (enablement != null) {
fEnablementExpression = ExpressionConverter.getDefault().perform(enablement);
}
} catch (CoreException e){
DebugUIPlugin.log(e.getStatus());
fEnablementExpression = null;
}
}
return fEnablementExpression;
}
}
/**
* There should only ever be once instance of this manager for the workbench.
*/
private static DetailPaneManager fgSingleton;
/**
* Maps the IDs of types of detail panes to the factory that can create them.
* There can currently only be one factory for a given type of details pane.
*/
private Map* This method will not call the init() method of the IDetailsPane. *
* * @param ID The ID of the requested pane * @return The instantiated pane or null */ public IDetailPane getDetailPaneFromID(String ID){ IDetailPaneFactory factory = fFactoriesByPaneID.get(ID); if (factory != null){ return factory.createDetailPane(ID); } return null; } /** * Given the ID of a details pane, this method will try to find the factory * that creates it and ask it for the name of the details pane. * * @param ID The ID of the requested pane * @return The name of the details pane or null */ public String getNameFromID(String ID){ IDetailPaneFactory factory = fFactoriesByPaneID.get(ID); if (factory != null){ return factory.getDetailPaneName(ID); } return null; } /** * Given the ID of a details pane, this method will try to find the factory * that creates it and ask it for the description of the details pane. * * @param ID The ID of the requested pane * @return The description of the details pane or null */ public String getDescriptionFromID(String ID){ IDetailPaneFactory factory = fFactoriesByPaneID.get(ID); if (factory != null){ return factory.getDetailPaneDescription(ID); } return null; } /** * Returns the set of IDetailPaneFactories (they will be DetailPaneFactoryDelegates) that were * contributed to the extension point and are enabled for the given selection * (enabled if the factory does not have an enablement expression or if the * enablement expression evaluates to true). * @param selection the current view selection * * @return The factories enabled for the selection or an empty collection. */ private List