Skip to main content
summaryrefslogtreecommitdiffstats
blob: bfb9a4d7c310e54a23b48b5d0cbdd977ad3cb9d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Martin Fluegge - initial API and implementation
 */
package org.eclipse.emf.cdo.dawn.helper;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

/**
 * TODO move this one to the dawn.util bundle
 * 
 * @author Martin Fluegge
 */
public class DawnEditorHelper
{
  /**
   * Delivers the active shell from the current display.
   * 
   * @return the active shell on the current display
   */
  public static Shell getActiveShell()
  {
    Shell shell = Display.getCurrent().getActiveShell();
    return shell;
  }

  /**
   * This method returns the active editor from the active workbench page
   * 
   * @return the active editor from the active workbench page or null if there is none
   */
  public static IEditorPart getActiveEditor()
  {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorPart editor = null;
    if (window != null)
    {
      IWorkbenchPage page = window.getActivePage();
      if (page != null)
      {
        editor = page.getActiveEditor();
      }
    }
    return editor;
  }

  /**
   * This method tries to retrieve a Display. First it tries to get the current display. If this fails it will return
   * the default display.
   * 
   * @return the current display, if not null. If the current Display is null then the default Display.
   * @since 2.0
   */
  public static Display getDisplay()
  {
    Display display = Display.getCurrent();
    if (display == null)
    {
      display = Display.getDefault();
    }
    return display;
  }
}

Back to the top