Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed() always return false(isContextHelpDisplayed() doesn't behave as its API description. Even though the context sensitive help is open, it returns false.)
PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed() always return false [message #948085] Wed, 17 October 2012 18:47 Go to next message
Cory Huang is currently offline Cory HuangFriend
Messages: 2
Registered: October 2012
Junior Member
Hi guys,

I was trying to use IWorkbenchHelpSystem.isContextHelpDisplayed() (http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fui%2Fhelp%2FIWorkbenchHelpSystem.html) to check if the context sensitive help is open alreay or not. However, I came across a problem that this method doesn't work properly as its description "Returns whether the context-sensitive help window is currently being displayed."

Basically, the problem is: when the context sensitive help is shown, this method also returns false. I looked into the source code, and here is my findings.
---------------------------------------------------------------------------------
Problem 1:
First, the entry of the isContextHelpDisplay() method.
WorkbenchHelpSystem.java
public boolean isContextHelpDisplayed() {
if (!isInitialized) {
return false;
}
AbstractHelpUI helpUI = getHelpUI();
return helpUI != null && helpUI.isContextHelpDisplayed();
}

When isInitialized = true and helpUI != null, we goes into DefaultHelpUI.isContextHelpDisplayed()
/**
* Returns <code>true</code> if the context-sensitive help window is currently being
* displayed, <code>false</code> if not.
*/
public boolean isContextHelpDisplayed() {
if (f1Dialog == null) {
return false;
}
return f1Dialog.isShowing();
}

However, f1Dialog = null, even though I have already pressed F1 and the Help view is shown out there. Then, I checked the code where f1Dialog is created, it is in the function

private void displayContextAsInfopop(IContext context, int x, int y, IWorkbenchPart activePart, Control c){
...
else {
f1Dialog = new ContextHelpDialog(context, x, y);
f1Dialog.open();
}
...
}
,

which is only called in

void displayContext(IContext context, int x, int y, boolean noInfopop) {
...
if (!noInfopop && winfopop) {
IWorkbenchPart activePart = page.getActivePart();
Control c = window.getShell().getDisplay().getFocusControl();
displayContextAsInfopop(context, x, y, activePart, c);
return;
}
...
}

It seems that we need to have winfopop=true to get f1Dialog created. I guess that's why no matter how I press F1 to open the Help view, f1Dialog is still null. I am not sure if my understanding here is correct. If it is correct, why we need winfopop if the Help view is already open?

---------------------------------------------------------------------------------
Problem 2: when Help is open at startup, it seems something should be initialized as true while it is false. Please see below:
WorkbenchHelpSystem.java
public boolean isContextHelpDisplayed() {
if (!isInitialized) {
return false; // here return false
}
AbstractHelpUI helpUI = getHelpUI();
return helpUI != null && helpUI.isContextHelpDisplayed();
}

isInitialized is only evaluated in the getHelpUI() as below:
private AbstractHelpUI getHelpUI() {
if (!isInitialized) {
isInitialized = initializePluggableHelpUI();
if (!isInitialized)
WorkbenchPlugin.log("Unable to instantiate help UI");//$NON-NLS-1$

}
return pluggableHelpUI;
}

I don't know why isInitialized is supposed to not to be initialized as true if the Help view is open at startup. This is not a problem if I reopen the Help view by hand (aka press F1).

---------------------------------------------------------------------------------
For those people who have the same problems of using PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed(), I found a workaround here http://www.eclipse.org/forums/index.php/m/720403/. So, my code which checks if the Help view is shown or not is:
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart helpView = activePage.findView("org.eclipse.help.ui.HelpView");
if (helpView == null) {
return;
}




But I still want to know why isContextHelpDisplayed() doesn't behave properly (or my understanding is incorrect). Thank you all guys for viewing my post and I really appreciate if someone can come up and help me with this. Razz


Cory
Re: PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed() always return false [message #1058904 is a reply to message #948085] Wed, 15 May 2013 16:31 Go to previous messageGo to next message
tony burton is currently offline tony burtonFriend
Messages: 26
Registered: April 2012
Location: France
Junior Member
Hi there,
I have the same problem (Indigo). Did you find a solution? The work around you posted doesn't seem to work for me,

Thanks

Antony
Re: PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed() always return false [message #1058918 is a reply to message #1058904] Wed, 15 May 2013 18:31 Go to previous messageGo to next message
Cory Huang is currently offline Cory HuangFriend
Messages: 2
Registered: October 2012
Junior Member
The workaround works for me, it checks whether the Help view is open or not.

What do you mean it doesn't work for you?
Re: PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed() always return false [message #1059201 is a reply to message #1058918] Fri, 17 May 2013 09:16 Go to previous message
tony burton is currently offline tony burtonFriend
Messages: 26
Registered: April 2012
Location: France
Junior Member
Yes, in fact, the help I'm talking about is the help that appears in a tray on the right of the new c project wizard when the "?" button or F1 is pressed, not the help view. I found another workaround, which is to test if the tray is open or not:

IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
			
// test if help tray is open
Display display = Display.getCurrent();
			
Shell activeShell = display.getActiveShell();
TrayDialog dialog = (TrayDialog)activeShell.getData();
			
DialogTray tray = dialog.getTray();

if (tray != null) {
   helpSystem.displayHelp(contextID);
}


regards,

Antony
Previous Topic:RCP app with Worldwind - Globe vanishes
Next Topic:Disable the .history folder
Goto Forum:
  


Current Time: Sat Dec 20 19:40:30 GMT 2014

Powered by FUDForum. Page generated in 0.01550 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software