use of eu.esdihumboldt.hale.ui.common.help.internal.ContextImpl in project hale by halestudio.
the class SelectionContextProvider method getContext.
/**
* @see IContextProvider#getContext(Object)
*/
@Override
public IContext getContext(Object target) {
// provide a context based on the selection
ISelection selection = selectionProvider.getSelection();
IContext defaultContext = null;
if (defaultContextId != null) {
defaultContext = HelpSystem.getContext(defaultContextId);
}
List<IContext> contexts = new ArrayList<IContext>();
if (selection instanceof IStructuredSelection) {
for (Object object : ((IStructuredSelection) selection).toList()) {
IContext context = getSelectionContext(object);
if (context != null) {
contexts.add(context);
}
}
}
if (contexts.size() == 1) {
if (defaultContext == null) {
return contexts.get(0);
} else {
// create context enhanced with default topics
return new ContextWrapper(contexts.get(0), Arrays.asList(defaultContext.getRelatedTopics()));
}
} else if (!contexts.isEmpty()) {
LinkedHashSet<IHelpResource> topics = new LinkedHashSet<IHelpResource>();
Set<String> hrefs = new HashSet<String>();
// collect topics
for (IContext context : contexts) {
for (IHelpResource topic : context.getRelatedTopics()) {
if (!hrefs.contains(topic.getHref())) {
// ensure that the
// same topic is
// only added once
topics.add(topic);
hrefs.add(topic.getHref());
}
}
}
if (!topics.isEmpty()) {
if (defaultContext == null) {
return new ContextImpl(// XXX
"Multiple selected objects, see below for related topics.", // improve?!
topics.toArray(new IHelpResource[topics.size()]));
} else {
// create a context enhanced with the selection topics
return new ContextWrapper(defaultContext, topics);
}
}
}
// by default, get the view context
return defaultContext;
}
Aggregations