]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/participant/WorkbenchStatusLine.java
Fixed invalid comparisons which were identified by Eclipse IDE 2018-09
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / participant / WorkbenchStatusLine.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.participant;
13
14 import org.eclipse.jface.action.IStatusLineManager;
15 import org.eclipse.swt.widgets.Display;
16 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
17 import org.simantics.utils.threads.SWTThread;
18 import org.simantics.utils.threads.ThreadUtils;
19
20 /**
21  * A utility participant for accessing the workbench status line.
22  * 
23  * @author Tuukka Lehtonen
24  * 
25  * TODO: add scheduled task to remove messages from status bar
26  */
27 public class WorkbenchStatusLine extends AbstractCanvasParticipant {
28
29     private final IStatusLineManager statusLine;
30
31     public WorkbenchStatusLine(IStatusLineManager statusLine) {
32         this.statusLine = statusLine;
33     }
34
35     public IStatusLineManager getStatusLine() {
36         return statusLine;
37     }
38
39     public void message(final String message) {
40         if (statusLine == null)
41             return;
42
43         swtExec(new Runnable() {
44             @Override
45             public void run() {
46                 statusLine.setMessage(message);
47                 statusLine.setErrorMessage(null);
48             }
49         });
50     }
51
52     public void error(final String message) {
53         if (statusLine == null)
54             return;
55
56         swtExec(new Runnable() {
57             @Override
58             public void run() {
59                 statusLine.setErrorMessage(message);
60             }
61         });
62     }
63
64     protected void swtExec(Runnable r) {
65         ThreadUtils.asyncExec(SWTThread.getThreadAccess(Display.getDefault()), r);
66     }
67
68 }