]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui.workbench/src/org/simantics/utils/ui/workbench/WorkbenchUtils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.ui.workbench / src / org / simantics / utils / ui / workbench / WorkbenchUtils.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.utils.ui.workbench;
13
14 import java.util.ArrayList;
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.Set;
18
19 import org.eclipse.core.runtime.IAdaptable;
20 import org.eclipse.jface.action.IStatusLineManager;
21 import org.eclipse.jface.viewers.IFilter;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.ui.IActionBars;
25 import org.eclipse.ui.IEditorDescriptor;
26 import org.eclipse.ui.IEditorInput;
27 import org.eclipse.ui.IEditorPart;
28 import org.eclipse.ui.IEditorSite;
29 import org.eclipse.ui.IPerspectiveDescriptor;
30 import org.eclipse.ui.IViewPart;
31 import org.eclipse.ui.IViewReference;
32 import org.eclipse.ui.IViewSite;
33 import org.eclipse.ui.IWorkbench;
34 import org.eclipse.ui.IWorkbenchPage;
35 import org.eclipse.ui.IWorkbenchPart;
36 import org.eclipse.ui.IWorkbenchPartSite;
37 import org.eclipse.ui.IWorkbenchSite;
38 import org.eclipse.ui.IWorkbenchWindow;
39 import org.eclipse.ui.PartInitException;
40 import org.eclipse.ui.PlatformUI;
41 import org.eclipse.ui.WorkbenchException;
42 import org.eclipse.ui.intro.IIntroSite;
43 import org.eclipse.ui.part.IPageSite;
44 import org.simantics.utils.ui.SWTUtils;
45
46 /**
47  * Some eclipse workspace utils
48  * 
49  * @author Toni Kalajainen
50  */
51 public class WorkbenchUtils {
52
53     /**
54      * Find open viewpart
55      * 
56      * @param primaryID primary view id
57      * @param secondaryID secondary view id
58      * @return view part if it exists
59      */
60     public static IViewPart findView(String primaryID, String secondaryID) {
61         if (secondaryID==null)
62             return _findView(primaryID, false);
63         else
64             return _findView(primaryID + ":" + secondaryID, false);
65     }
66
67     /**
68      * Find open viewpart
69      * 
70      * @param id full id (example "primaryid:secondaryid")
71      * @return <code>IViewPart</code> or null if view wasn't found
72      */
73     public static IViewPart findView(String id) {
74         return _findView(id, false);
75     }
76
77     /**
78      * Finds (and restores) all views that have a specific primary Id
79      * 
80      * @param primaryId primary Id
81      * @return all views
82      */
83     public static IViewPart[] findAllViews(String primaryId) {
84         List<IViewPart> result = new ArrayList<IViewPart>();
85         for (IViewReference ref : getViewReferences())
86             if (primaryId.equals(ref.getId()))
87                 result.add(ref.getView(true));
88         return result.toArray(new IViewPart[0]);
89     }
90
91     /**
92      * Find viewpart, opens view if view is closed
93      * 
94      * @param id full id
95      * @return <code>IViewPart</code> or null if view wasn't found
96      */
97     public static IViewPart getView(String id) {
98         return _findView(id, true);
99     }
100
101     public static IWorkbenchWindow getWorkbenchWindow(Shell shell)
102     {
103         for (IWorkbenchWindow w : PlatformUI.getWorkbench().getWorkbenchWindows())
104             if (w.getShell()==shell) return w;
105         return null;
106     }
107
108     /**
109      * Try to get the {@link Shell} of the currently active workbench window.
110      * Must be invoked from the SWT UI thread to receive results.
111      * 
112      * @return Shell of the currently active workbench window or
113      *         <code>null</code> if there is no active window or if called from
114      *         a non-UI thread
115      */
116     public static Shell getActiveWorkbenchWindowShell() {
117         IWorkbench wb = PlatformUI.getWorkbench();
118         IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
119         if (window == null)
120             return null;
121         return window.getShell();
122     }
123
124     /**
125      * Get the active workbench part in currently active workbench window /
126      * active page
127      * 
128      * @return active workbench part of the active workbench window
129      */
130     public static IWorkbenchPart getActiveWorkbenchPart()
131     {
132         IWorkbench wb = PlatformUI.getWorkbench();
133         if (wb==null) return null;
134         IWorkbenchWindow wbw = wb.getActiveWorkbenchWindow();
135         if (wbw==null) return null;
136         IWorkbenchPage wbp = wbw.getActivePage();
137         if (wbp==null) return null;
138         return wbp.getActivePart();
139     }
140
141
142     /**
143      * Get the active workbench part in currently active workbench window /
144      * active page
145      * 
146      * @return active workbench part of the active workbench window
147      */
148     public static IEditorPart getActiveEditor()
149     {
150         IWorkbench wb = PlatformUI.getWorkbench();
151         if (wb==null) return null;
152         IWorkbenchWindow wbw = wb.getActiveWorkbenchWindow();
153         if (wbw==null) return null;
154         IWorkbenchPage wbp = wbw.getActivePage();
155         if (wbp==null) return null;
156         return wbp.getActiveEditor();
157     }
158
159     /**
160      * Get the perspective in current active workbench window / active page
161      * @return Current perspective
162      */
163     public static IPerspectiveDescriptor getCurrentPerspective()
164     {
165         IWorkbench wb = PlatformUI.getWorkbench();
166         if (wb==null) return null;
167         IWorkbenchWindow wbw = wb.getActiveWorkbenchWindow();
168         if (wbw==null) return null;
169         IWorkbenchPage wbp = wbw.getActivePage();
170         if (wbp==null) return null;
171         return wbp.getPerspective();
172     }
173
174     /**
175      * Get the perspective in current active workbench window / active page
176      * @return Current perspective Id
177      */
178     public static String getCurrentPerspectiveId()
179     {
180         IPerspectiveDescriptor p = getCurrentPerspective();
181         if (p==null) return null;
182         return p.getId();
183     }
184
185     /**
186      * Returns all <code>IViewReference</code>s
187      * @return array of all <code>IViewReference</code>s
188      */
189     public static IViewReference[] getViewReferences() {
190         Set<IViewReference> result = new HashSet<IViewReference>();
191
192         IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
193         if (windows == null)
194             return null;
195         for (IWorkbenchWindow wb : windows) {
196             if (wb == null)
197                 return null;
198             IWorkbenchPage pages[] = wb.getPages();
199             if (pages == null)
200                 return null;
201             for (IWorkbenchPage page : pages) {
202                 if (page == null)
203                     continue;
204                 IViewReference refs[] = page.getViewReferences();
205                 for (IViewReference ref : refs)
206                     result.add(ref);
207             }
208         }
209         return result.toArray(new IViewReference[0]);
210     }
211
212     /**
213      * Returns all <code>IViewReference</code>s for the specified workbench
214      * window
215      * 
216      * @return array of all <code>IViewReference</code>s for the specified
217      *         window
218      */
219     public static IViewReference[] getViewReferences(IWorkbenchWindow window) {
220         Set<IViewReference> result = new HashSet<IViewReference>();
221         for (IWorkbenchPage page : window.getPages()) {
222             IViewReference refs[] = page.getViewReferences();
223             for (IViewReference ref : refs)
224                 result.add(ref);
225         }
226         return result.toArray(new IViewReference[0]);
227     }
228
229     /**
230      * Finds a <code>IViewPart</code>. Opens the view if it's closed
231      * @param primaryID primary ID of the view
232      * @param secondaryID secondary ID of the view or null if view has no secondary ID
233      * @return <code>IViewPart</code> if view was found or opened, else returns null
234      */
235     public static IViewPart getView(String primaryID, String secondaryID) {
236         if (secondaryID==null)
237             return _findView(primaryID, true);
238         return _findView(primaryID+":"+secondaryID, true);
239     }
240
241     /**
242      * Finds a <code>IViewPart</code>
243      * @param id id of the View
244      * @param restore set to true if you want to open closed view
245      * @return the <code>IViewPart</code> if view was found or restored, else returns null
246      */
247     private static IViewPart _findView(String id, boolean restore) {
248         String primaryId = getPrimaryID(id);
249         String secondaryId = getSecondaryID(id);
250         IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
251         if (windows == null)
252             return null;
253         for (IWorkbenchWindow wb : windows) {
254             if (wb == null)
255                 return null;
256             IWorkbenchPage pages[] = wb.getPages();
257             if (pages == null)
258                 return null;
259             for (IWorkbenchPage page : pages) {
260                 if (page == null)
261                     continue;
262
263                 IViewReference vr = page.findViewReference(primaryId, secondaryId);
264                 if (vr == null)
265                     continue;
266
267                 IViewPart vp = vr.getView(restore);
268                 if (vp != null)
269                     return vp;
270             }
271         }
272         return null;
273     }
274
275     /**
276      * Hides a view
277      * @param id the id of the view
278      * @return true if view was hidden, returns false if view with id wasn't found
279      */
280     public static boolean hideView(String id) {
281         IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
282         if (windows == null)
283             return false;
284         for (IWorkbenchWindow wb : windows) {
285             if (wb == null)
286                 return false;
287             IWorkbenchPage pages[] = wb.getPages();
288             if (pages == null)
289                 return false;
290             for (IWorkbenchPage page : pages) {
291                 if (page == null)
292                     continue;
293
294                 IViewReference vr = page.findViewReference(getPrimaryID(id), getSecondaryID(id));
295                 if (vr == null)
296                     continue;
297                 page.hideView(vr);
298                 return true;
299
300             }
301         }
302         return false;
303     }
304
305     /**
306      * @param viewPart
307      * @return
308      */
309     public static boolean hideView(IViewPart viewPart) {
310         IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
311         if (windows == null)
312             return false;
313         for (IWorkbenchWindow wb : windows) {
314             if (wb == null)
315                 return false;
316             IWorkbenchPage pages[] = wb.getPages();
317             if (pages == null)
318                 return false;
319             for (IWorkbenchPage page : pages) {
320                 if (page == null)
321                     continue;
322                 page.hideView(viewPart);
323                 return true;
324             }
325         }
326         return false;
327     }
328
329     /**
330      * @param view
331      * @return
332      */
333     public static boolean hideView(IWorkbenchWindow window, IViewPart view) {
334         for (IWorkbenchPage page : window.getPages()) {
335             if (page == null)
336                 continue;
337             page.hideView(view);
338             return true;
339         }
340         return false;
341     }
342
343     /**
344      * @param view
345      * @return
346      */
347     public static boolean hideView(IWorkbenchWindow window, IViewReference view) {
348         for (IWorkbenchPage page : window.getPages()) {
349             if (page == null)
350                 continue;
351             page.hideView(view);
352             return true;
353         }
354         return false;
355     }
356
357     /**
358      * Gets the primary id from view id "prim:secon"
359      * 
360      * @param id full id
361      * @return primary id
362      */
363     public static String getPrimaryID(String id) {
364         String splitted[] = id.split(":");
365         if (splitted == null || splitted.length < 1)
366             return null;
367         return splitted[0];
368     }
369
370     /**
371      * Gets the secondary id from view id "prim:secon"
372      * 
373      * @param id full id
374      * @return secondary id
375      */
376     public static String getSecondaryID(String id) {
377         String splitted[] = id.split(":");
378         if (splitted == null || splitted.length < 2)
379             return null;
380         return splitted[1];
381     }
382
383     /**
384      * Creates the view
385      * @param id the id of the view
386      * @return <code>IViewPart</code> or null if view couldn't be created
387      * @throws PartInitException
388      */
389     public static IViewPart showView(String id) throws PartInitException {
390         return showView(id, IWorkbenchPage.VIEW_CREATE);
391     }
392
393     /**
394      * Activates the view
395      * @param id the id of the view
396      * @return <code>IViewPart</code> or null if view couldn't be activated
397      * @throws PartInitException
398      */
399     public static IViewPart activateView(String id) throws PartInitException {
400         IViewPart vp = showView(id, IWorkbenchPage.VIEW_ACTIVATE);
401         return vp;
402     }
403
404     /**
405      * Shows the view
406      * @param id the id of the view
407      * @param mode <code>IWorkbenchPage.VIEW_CREATE</code> or <code>IWorkbenchPage.VIEW_ACTIVATE</code>
408      * @return the <code>IViewPart</code> or null if showing the view failed
409      * @throws PartInitException
410      */
411     public static IViewPart showView(String id, final int mode) throws PartInitException {
412         // Is view already created
413         IViewPart vp = findView(id);
414         if (vp != null) {
415             if (mode == IWorkbenchPage.VIEW_CREATE)
416                 return vp;
417
418             Display display = Display.getCurrent();
419             if (Thread.currentThread() == display.getThread()) {
420                 // This is the UI-thread
421                 //System.out.println("In UI thread");
422                 IWorkbenchPage page = vp.getViewSite().getPage();
423
424                 if (mode == IWorkbenchPage.VIEW_VISIBLE) {
425                     page.bringToTop(vp);
426                 } else if (mode == IWorkbenchPage.VIEW_ACTIVATE) {
427                     page.activate(vp);
428                 }
429             } else {
430                 //System.out.println("NOT in UI thread!");
431                 final IViewPart fvp = vp;
432                 display.asyncExec(new Runnable() {
433                     @Override
434                     public void run() {
435                         final IWorkbenchWindow wb = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
436                         IWorkbenchPage page = wb.getActivePage();
437                         if (mode == IWorkbenchPage.VIEW_VISIBLE) {
438                             page.bringToTop(fvp);
439                         } else {
440                             page.activate(fvp);
441                         }
442                     }
443                 });
444             }
445             return vp;
446         }
447
448         final String primaryID = getPrimaryID(id);
449         final String secondaryID = getSecondaryID(id);
450         if (primaryID == null/* || secondaryID == null*/)
451             return null;
452
453         // Create the view on active page
454         final IWorkbenchWindow wb = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
455         if (wb == null)
456             return null;
457         IWorkbenchPage page = wb.getActivePage();
458         if (page == null) {
459             IWorkbenchPage pages[] = wb.getPages();
460             if (pages==null || pages.length == 0) return null;
461             page = pages[0];
462         }
463
464         vp = page.showView(primaryID, secondaryID, mode);
465         return vp;
466     }
467
468
469     /**
470      * IMPORTANT: If you're using multiple workbench windows, use
471      * {@link #showPerspective(IWorkbenchWindow, String, IAdaptable)} instead.
472      * 
473      * @param perspectiveId the ID of the perspective to activate in the
474      *        currently active workbench window
475      * @throws WorkbenchException if perspective activation fails
476      */
477     public static void showPerspective(String perspectiveId) throws WorkbenchException {
478         showPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), perspectiveId);
479     }
480
481     /**
482      * Opens the specified perspective in the specified workbench window
483      * according to the description of
484      * {@link IWorkbench#showPerspective(String, IWorkbenchWindow)}.
485      * 
486      * <p>
487      * IMPORTANT: If you're using multiple workbench windows, use
488      * {@link #showPerspective(IWorkbenchWindow, String, IAdaptable)} instead.
489      * </p>
490      * 
491      * @param window the window in which to show the specified perspective
492      * @param perspectiveId the ID of the perspective to activate in the
493      *        currently active workbench window
494      * @throws WorkbenchException if perspective activation fails
495      */
496     public static void showPerspective(IWorkbenchWindow window, String perspectiveId) throws WorkbenchException {
497         PlatformUI.getWorkbench().showPerspective(perspectiveId, window);
498     }
499
500     /**
501      * Opens the specified perspective in the specified workbench window with
502      * the specified page input according to the description of
503      * {@link IWorkbench#showPerspective(String, IWorkbenchWindow, IAdaptable)}.
504      * 
505      * <p>
506      * This is the only <code>showPerspective</code> that will force the
507      * specified perspective to open in exactly the specified window. The other
508      * methods cannot guarantee this. See
509      * {@link IWorkbench#showPerspective(String, IWorkbenchWindow, IAdaptable)}
510      * for an explanation why.
511      * </p>
512      * 
513      * <p>
514      * Example:
515      * 
516      * <pre>
517      * WorkbenchUtils.showPerspective(window, myPerspective, window.getActivePage().getInput());
518      * </pre>
519      * 
520      * </p>
521      * 
522      * @param window the window in which to show the specified perspective
523      * @param perspectiveId the ID of the perspective to activate in the
524      *        currently active workbench window
525      * @param the page input, or <code>null</code> if there is no current input.
526      *        This is used to seed the input for the page's views
527      * @throws WorkbenchException if perspective activation fails
528      */
529     public static void showPerspective(IWorkbenchWindow window, String perspectiveId, IAdaptable input) throws WorkbenchException {
530         PlatformUI.getWorkbench().showPerspective(perspectiveId, window, input);
531     }
532
533     /**
534      * Close all perspectives in all open workbench windows that do not pass the
535      * specified filter. The filter will get IPerspectiveDescriptor instances as
536      * input.
537      * 
538      * @param perspectiveFilter a filter for <code>IPerspectiveDescriptor</code>s.
539      */
540     public static void closeFilteredPerspectives(IFilter perspectiveFilter) {
541         for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
542             closeFilteredPerspectives(window, perspectiveFilter);
543         }
544     }
545
546     /**
547      * Close all perspectives in the specified workbench window that do not pass
548      * the specified filter. The filter will get IPerspectiveDescriptor
549      * instances as input.
550      * 
551      * @param perspectiveFilter a filter for <code>IPerspectiveDescriptor</code>s.
552      */
553     public static void closeFilteredPerspectives(IWorkbenchWindow window, IFilter perspectiveFilter) {
554         for (IWorkbenchPage page : window.getPages()) {
555             for (IPerspectiveDescriptor desc : page.getOpenPerspectives()) {
556                 if (!perspectiveFilter.select(desc)) {
557                     page.closePerspective(desc, true, false);
558                 }
559             }
560         }
561     }
562
563     public static IActionBars getActionBars(IWorkbenchPart part) {
564         if (part instanceof IViewPart) {
565             return ((IViewPart) part).getViewSite().getActionBars();
566         } else if (part instanceof IEditorPart) {
567             return ((IEditorPart) part).getEditorSite().getActionBars();
568         }
569         throw new IllegalArgumentException("Specified IWorkbenchPart is neither IViewPart nor IEditorPart");
570     }
571
572     /**
573      * @param editorId
574      * @param input
575      * @throws PartInitException
576      *             if editor opening fails
577      * @throws IllegalArgumentException
578      *             if an editor (IEditorDescription) with the specified id is
579      *             not found
580      * @throws IllegalStateException
581      *             if either current workbench window or current workbench page
582      *             returns <code>null</code>.
583      */
584     public static IEditorPart openEditor(String editorId, IEditorInput input) throws PartInitException {
585         IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().findEditor(editorId);
586         if (desc == null) {
587             throw new IllegalArgumentException("editor with id '" + editorId + "' not found");
588         }
589
590         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
591         if (window == null) {
592             throw new IllegalStateException("active workbench window is null");
593         }
594
595         IWorkbenchPage page = window.getActivePage();
596         if (page == null) {
597             throw new IllegalStateException("active workbench page is null");
598         }
599
600         return page.openEditor(input, desc.getId());
601     }
602
603     /**
604      * @param editorId
605      * @param input
606      * @param perspectiveId
607      * @throws Exception
608      */
609     public static void openEditorInPerspective(String editorId, IEditorInput input, String perspectiveId) throws Exception {
610         WorkbenchUtils.showPerspective(perspectiveId);
611         openEditor(editorId, input);
612     }
613
614     /**
615      * Closes an editor part.
616      * 
617      * @param editorPart
618      *            editor part instance to close
619      * @param save <code>true</code> to save changes before closing,
620      *         <code>false</code> to discard any changes
621      * @return <code>true</code> if the part was closed successfully
622      */
623     public static boolean closeAllEditors(boolean save) {
624         IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
625         if (windows == null)
626             return false;
627         for (IWorkbenchWindow wb : windows) {
628             if (wb == null)
629                 return false;
630             IWorkbenchPage pages[] = wb.getPages();
631             if (pages == null)
632                 return false;
633             for (IWorkbenchPage page : pages) {
634                 if (page == null)
635                     continue;
636                 return page.closeAllEditors(save);
637             }
638         }
639         return false;
640     }
641
642     /**
643      * Closes an editor part.
644      * 
645      * @param editorPart
646      *            editor part instance to close
647      * @param save <code>true</code> to save changes before closing,
648      *         <code>false</code> to discard any changes
649      * @return <code>true</code> if the part was closed successfully
650      */
651     public static boolean closeEditor(IEditorPart editorPart, boolean save) {
652         IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
653         if (windows == null)
654             return false;
655         for (IWorkbenchWindow wb : windows) {
656             if (wb == null)
657                 return false;
658             IWorkbenchPage pages[] = wb.getPages();
659             if (pages == null)
660                 return false;
661             for (IWorkbenchPage page : pages) {
662                 if (page == null)
663                     continue;
664                 return page.closeEditor(editorPart, save);
665             }
666         }
667         return false;
668     }
669
670     /**
671      * Closes all editor parts in the specified workbench window.
672      * 
673      * @param window editor part instance to close
674      * @param save <code>true</code> to save changes before closing,
675      *        <code>false</code> to discard any changes
676      * @return <code>true</code> if all editor parts were closed properly,
677      *         <code>false</code> otherwise
678      */
679     public static boolean closeEditors(IWorkbenchWindow window, boolean save) {
680         boolean result = true;
681         for (IWorkbenchPage page : window.getPages()) {
682             if (page == null)
683                 continue;
684             result &= page.closeAllEditors(false);
685         }
686         return result;
687     }
688
689     /**
690      * Try to get {@link IActionBars} from the specified {@link IWorkbenchSite}.
691      * There are four alternatives to what the site can be: {@link IViewSite},
692      * {@link IPageSite}, {@link IEditorSite} or {@link IIntroSite}. All of them
693      * have a method for retrieving {@link IActionBars}.
694      * 
695      * @return the action bars of the specified workbench site or
696      *         <code>null</code> if the site is unrecognized or does not have an
697      *         action bar
698      */
699     public static IActionBars getActionBars(IWorkbenchSite site) {
700         if (site instanceof IViewSite)
701             return ((IViewSite) site).getActionBars();
702         else if (site instanceof IPageSite)
703             return ((IPageSite) site).getActionBars();
704         else if (site instanceof IEditorSite)
705             return ((IEditorSite) site).getActionBars();
706         else if (site instanceof IIntroSite)
707             return ((IIntroSite) site).getActionBars();
708         return null;
709     }
710
711     /**
712      * Try to get {@link IStatusLineManager} from the specified
713      * {@link IWorkbenchSite}.
714      * 
715      * @return the status line if available or <code>null</code> if not
716      */
717     public static IStatusLineManager getStatusLine(IWorkbenchPart part) {
718         IActionBars bars = getActionBars(part);
719         return bars != null ? bars.getStatusLineManager() : null;
720     }
721
722     /**
723      * Try to get {@link IStatusLineManager} from the specified
724      * {@link IWorkbenchSite}.
725      * 
726      * @return the status line if available or <code>null</code> if not
727      */
728     public static IStatusLineManager getStatusLine(IWorkbenchSite site) {
729         IActionBars bars = getActionBars(site);
730         return bars != null ? bars.getStatusLineManager() : null;
731     }
732
733     /**
734      * @param partSite site of workbench part to activate
735      * @return <code>false</code> if the activation was scheduled
736      *         asynchronously, <code>true</code> if the part was synchronously
737      *         activated
738      * @throws NullPointerException
739      *             if partSite is <code>null</code>
740      */
741     public static boolean activatePart(final IWorkbenchPartSite partSite) {
742         final IWorkbenchPart part = partSite.getPart();
743         IWorkbench workbench = partSite.getWorkbenchWindow().getWorkbench();
744         Display display = workbench.getDisplay();
745         Runnable activator = new Runnable() {
746             @Override
747             public void run() {
748                 partSite.getPage().activate(part);
749             }
750         };
751         if (Thread.currentThread() == display.getThread()) {
752             activator.run();
753             return true;
754         } else {
755             SWTUtils.asyncExec(display, activator);
756             return false;
757         }
758     }
759
760 }