Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » setIcon NullPointerException(Calling setIcon in my command handler throws a NullPointerException)
setIcon NullPointerException [message #822538] Fri, 16 March 2012 21:18 Go to next message
Terry Jahelka is currently offline Terry JahelkaFriend
Messages: 23
Registered: February 2012
Junior Member

I'm fairly new to Eclipse RCP. I'm creating an application that connects to several JMS topics. On the toolbar I have 2 commands that have an icon and when clicked will pop a dialog with details on the JMS connection.
The icon is a stoplight-type indicator. If red, then no messages have been received, if yellow it's been longer than a defined threshold, if green then data is being received. The state red, yellow, green is stored in a session provider and updated
when a new message is received from the topic. Via debugging I've verified that the session source is being updated and the fireSourceChanged is executing. However, these commands are always visible and always enabled
so I don't know how to connect them to the source provider. The command handler implements IElementUpdated and in the updateElement method I attempt to change the icon. After setting the property on my session source provider I called the command service refreshElements().
When I do this, the setIcon throws a NullPointerException.

I've verified that all 3 icons are in icons/ folder, and the Activator.getImageDescriptor(...) appears to be returning a valid imagedescriptor.

Plugin.xml, session source provider, handler, and snippet from my model are below.

Any help would be greatly appreciated.
Thanks,

Terry

eclipse.buildId=unknown
java.version=1.6.0_26
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments: -product com.issinc.tnsClient.core.product
Command-line arguments: -product com.issinc.tnsClient.core.product -data C:\tnsClient/../runtime-com.issinc.tnsClient.product -dev file:C:/tnsClient/.metadata/.plugins/org.eclipse.pde.core/com.issinc.tnsClient.product/dev.properties -os win32 -ws win32 -arch x86 -consoleLog

!ENTRY org.eclipse.ui.workbench 4 2 2012-03-16 15:05:07.255
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench".
!STACK 0
java.lang.NullPointerException
at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:207)
at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:232)
at org.eclipse.ui.menus.CommandContributionItem.updateIcons(CommandContributionItem.java:925)
at org.eclipse.ui.menus.CommandContributionItem.setIcon(CommandContributionItem.java:902)
at org.eclipse.ui.menus.CommandContributionItem.access$3(CommandContributionItem.java:900)
at org.eclipse.ui.menus.CommandContributionItem$2.setIcon(CommandContributionItem.java:235)
at com.issinc.tnsClient.commands.toolbar.handler.ConnectionStatusHandler.updateElement(ConnectionStatusHandler.java:54)
at org.eclipse.ui.internal.handlers.HandlerProxy.updateElement(HandlerProxy.java:456)
at org.eclipse.ui.internal.commands.CommandService$1.run(CommandService.java:242)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.commands.CommandService.refreshElements(CommandService.java:258)
at com.issinc.tnsClient.model.ConnectionModelProvider.updateStatus(ConnectionModelProvider.java:180)
at com.issinc.tnsClient.core.ConnectionStatus.onMessage(ConnectionStatus.java:71)
at org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:91)
at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:866)
at org.hornetq.core.client.impl.ClientConsumerImpl.access$100(ClientConsumerImpl.java:44)
at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:983)
at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

!ENTRY org.eclipse.ui 4 4 2012-03-16 15:05:07.272
!MESSAGE Failed to update callback: com.issinc.tnsClient.commands.toolbar.ConnectionStatus


Plugin.xml

<extension
point="org.eclipse.ui.services">
<sourceProvider
provider="com.issinc.tnsClient.common.SessionSourceProvider">
<variable
name="com.issinc.tnsClient.sessionState"
priorityLevel="workbench">
</variable>
<variable
name="com.issinc.tnsClient.link16rcv.connectionState"
priorityLevel="workbench">
</variable>
<variable
name="com.issinc.tnsClient.ada.connectionState"
priorityLevel="workbench">
</variable>
</sourceProvider>
</extension>

<extension
id="com.issinc.tnsClient.link16rcv.connectionState"
point="org.eclipse.ui.commands">
<command
defaultHandler="com.issinc.tnsClient.commands.toolbar.handler.SettingsHandler"
id="com.issinc.tnsClient.commands.toolbar.Settings"
name="Settings Command">
</command>
<command
defaultHandler="com.issinc.tnsClient.commands.toolbar.handler.ConnectionStatusHandler"
id="com.issinc.tnsClient.commands.toolbar.ConnectionStatus"
name="Connection Status">
<commandParameter
id="com.issinc.tnsClient.commands.ConnectionId"
name="Connection Id">
</commandParameter>
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="com.issinc.tnsCient.toolbar">
<command
commandId="com.issinc.tnsClient.commands.toolbar.ConnectionStatus"
icon="icons/red.png"
id="tnsClient.link16RcvStatus"
label="Link 16 Receive Connection Status"
mode="FORCE_TEXT"
style="push"
tooltip="Click to view Link 16 receive connection status details">
<parameter
name="com.issinc.tnsClient.commands.ConnectionId"
value="Link16">
</parameter>
</command>
<command
commandId="com.issinc.tnsClient.commands.toolbar.ConnectionStatus"
icon="icons/red.png"
id="tnsClient.adaStatus"
label="ADA Connection Status"
mode="FORCE_TEXT"
style="push"
tooltip="Click to view ADA connection status details">
<parameter
name="com.issinc.tnsClient.commands.ConnectionId"
value="AdaSocketIngester">
</parameter>
</command>
</toolbar>
</menuContribution>
</extension>

public class SessionSourceProvider extends AbstractSourceProvider {

public final static String WARNING = "Yellow";
public final static String ERROR = "Red";
public final static String OK = "Green";

public final static String SESSION_STATE = "com.issinc.tnsClient.sessionState";
public final static String LINK16_RCV_CONNECTION_STATE = "com.issinc.tnsClient.link16rcv.connectionState";
public final static String ADA_CONNECTION_STATE = "com.issinc.tnsClient.ada.connectionState";

public final static String AUTHENTICATED = "AUTHENTICATED";
public final static String NOT_AUTHENTICATED = "NOT AUTHENTICATED";

public String link16IngesterName;
public String adaIngesterName;

private String encodedLogin;
private List<Cookie> cookies;
private String link16ConnectionState;
private String adaConnectionState;

private Map<String, Map<String,Integer>> connectionStatusDeltas;

public SessionSourceProvider() {
connectionStatusDeltas = new HashMap<String, Map<String,Integer>>();
link16ConnectionState = ERROR;
adaConnectionState = ERROR;
}

/**
* @return the encodedLogin
*/
public String getEncodedLogin() {
return encodedLogin;
}

/**
* @param encodedLogin
* the encodedLogin to set
*/
public void setEncodedLogin(String encodedLogin) {
this.encodedLogin = Base64Coder.encodeString(encodedLogin);
}

@Override
public Map<String, String> getCurrentState() {
Map<String, String> map = new HashMap<String, String>(3);
if (encodedLogin != null) {
map.put(SESSION_STATE, AUTHENTICATED);
} else {
map.put(SESSION_STATE, NOT_AUTHENTICATED);
}

map.put(LINK16_RCV_CONNECTION_STATE, link16ConnectionState);
map.put(ADA_CONNECTION_STATE, adaConnectionState);

return map;
}

@Override
public String[] getProvidedSourceNames() {
return new String[] { SESSION_STATE, LINK16_RCV_CONNECTION_STATE, ADA_CONNECTION_STATE };
}

.
.
.


/**
* @param link16ConnectionState the link16ConnectionState to set
*/
public void setLink16ConnectionState(String link16ConnectionState) {
if (this.link16ConnectionState == link16ConnectionState) {
return;
}

this.link16ConnectionState = link16ConnectionState;
fireSourceChanged(ISources.WORKBENCH, LINK16_RCV_CONNECTION_STATE, link16ConnectionState);
}

/**
* @return the adaConnectonState
*/
public String getAdaConnectionState() {
return adaConnectionState;
}

/**
* @param adaConnectonState the adaConnectonState to set
*/
public void setAdaConnectionState(String adaConnectionState) {
if (this.adaConnectionState == adaConnectionState) {
return;
}

this.adaConnectionState = adaConnectionState;
fireSourceChanged(ISources.WORKBENCH, ADA_CONNECTION_STATE, adaConnectionState);
}
}

public class ConnectionStatusHandler extends AbstractHandler implements
IElementUpdater {

@Override
public void updateElement(UIElement element, Map parameters) {
String connectionType = (String) parameters
.get("com.issinc.tnsClient.commands.ConnectionId");
IWorkbenchWindow window = (IWorkbenchWindow) parameters
.get("org.eclipse.ui.IWorkbenchWindow");
ISourceProviderService service = (ISourceProviderService) window
.getService(ISourceProviderService.class);
SessionSourceProvider sessionSourceProvider = (SessionSourceProvider) service
.getSourceProvider(SessionSourceProvider.SESSION_STATE);

Map<String, String> sessionState = sessionSourceProvider
.getCurrentState();

String connectionState = SessionSourceProvider.ERROR;
if (connectionType.equals(sessionSourceProvider.link16IngesterName)) {
connectionState = sessionState
.get(SessionSourceProvider.LINK16_RCV_CONNECTION_STATE);
} else if (connectionType.equals(sessionSourceProvider.adaIngesterName)) {
connectionState = sessionState
.get(SessionSourceProvider.ADA_CONNECTION_STATE);
}

ImageDescriptor image = null;
if (connectionState.equals(SessionSourceProvider.OK)) {
image = Activator.getImageDescriptor("icons/green.png");
} else if (connectionState.equals(SessionSourceProvider.WARNING)) {
image = Activator.getImageDescriptor("icons/yellow.png");
} else {
image = Activator.getImageDescriptor("icons/red.png");
}

element.setIcon(image);

}
}


In my model, I added the following to try to force the command to update:

sessionSource.setLink16ConnectionState(connectionState);

// Refresh command PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ICommandService service = (ICommandService) PlatformUI.getWorkbench()
.getService(ICommandService.class);
if (service != null) {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("com.issinc.tnsClient.commands.ConnectionId",
ingesterName);
service.refreshElements(
"com.issinc.tnsClient.commands.toolbar.ConnectionStatus",
parameters);
}

Re: setIcon NullPointerException [message #822544 is a reply to message #822538] Fri, 16 March 2012 22:03 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
I would say that you are probably getting the NullPointer because you are trying to create the image from a non UI thread. The NullPointer is caused by a missing Display. Other than in RCP you cannot access the Display from whereever you want in RAP. Try to pre-create the images from within an UI Thread prior to accessing them from the handler.
Re: setIcon NullPointerException [message #824286 is a reply to message #822544] Mon, 19 March 2012 13:49 Go to previous messageGo to next message
Terry Jahelka is currently offline Terry JahelkaFriend
Messages: 23
Registered: February 2012
Junior Member
That worked. Thank you so much!
Re: setIcon NullPointerException [message #824289 is a reply to message #822544] Mon, 19 March 2012 13:49 Go to previous message
Terry Jahelka is currently offline Terry JahelkaFriend
Messages: 23
Registered: February 2012
Junior Member
That worked. Thank you so much!
Previous Topic:How to redirect to a logout page
Next Topic:Can't install from repository
Goto Forum:
  


Current Time: Tue Apr 23 08:56:41 GMT 2024

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

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

Back to the top