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