|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.ui; |
|
6 |
|
7 import org.chromium.debug.core.ChromiumDebugPlugin; |
|
8 import org.chromium.debug.core.util.ChromiumDebugPluginUtil; |
|
9 import org.eclipse.core.resources.IFile; |
|
10 import org.eclipse.core.resources.IProject; |
|
11 import org.eclipse.core.runtime.CoreException; |
|
12 import org.eclipse.swt.widgets.Display; |
|
13 import org.eclipse.ui.IWorkbench; |
|
14 import org.eclipse.ui.IWorkbenchWindow; |
|
15 import org.eclipse.ui.PartInitException; |
|
16 import org.eclipse.ui.PlatformUI; |
|
17 |
|
18 /** |
|
19 * This class provides generic plugin-wide services. |
|
20 */ |
|
21 public class PluginUtil { |
|
22 |
|
23 private static final String PROJECT_EXPLORER_ID = "org.eclipse.ui.navigator.ProjectExplorer"; //$NON-NLS-1$ |
|
24 |
|
25 /** |
|
26 * Brings up the "Project Explorer" view in the active workbench window. |
|
27 */ |
|
28 public static void openProjectExplorerView() { |
|
29 Display.getDefault().asyncExec(new Runnable() { |
|
30 public void run() { |
|
31 IWorkbench workbench = PlatformUI.getWorkbench(); |
|
32 IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); |
|
33 if (window == null) { |
|
34 if (workbench.getWorkbenchWindowCount() == 1) { |
|
35 window = workbench.getWorkbenchWindows()[0]; |
|
36 } |
|
37 } |
|
38 if (window != null) { |
|
39 try { |
|
40 window.getActivePage().showView(PROJECT_EXPLORER_ID); |
|
41 } catch (PartInitException e) { |
|
42 // ignore |
|
43 } |
|
44 } |
|
45 } |
|
46 }); |
|
47 } |
|
48 |
|
49 /** |
|
50 * Determines whether {@code file} is a .chromium file in a |
|
51 * JavaScript debug project. |
|
52 * |
|
53 * @param file to test |
|
54 * @return whether the file extension is ".chromium" and its project has the |
|
55 * ChromiumDebugPluginUtil#JS_DEBUG_PROJECT_NATURE nature |
|
56 */ |
|
57 public static boolean isChromiumDebugFile(IFile file) { |
|
58 IProject project = file.getProject(); |
|
59 try { |
|
60 return (project.hasNature(ChromiumDebugPluginUtil.JS_DEBUG_PROJECT_NATURE) && |
|
61 file.getName().endsWith(ChromiumDebugPluginUtil.CHROMIUM_EXTENSION_SUFFIX)); |
|
62 } catch (CoreException e) { |
|
63 ChromiumDebugPlugin.log(e); |
|
64 return false; |
|
65 } |
|
66 } |
|
67 |
|
68 |
|
69 /** |
|
70 * Removes the ".chromium" extension from the fileName. |
|
71 * |
|
72 * @param fileName to remove the extension from |
|
73 * @return a file name without the ".chromium" extension |
|
74 */ |
|
75 public static String stripChromiumExtension(String fileName) { |
|
76 return fileName.substring( |
|
77 0, fileName.length() - ChromiumDebugPluginUtil.CHROMIUM_EXTENSION_SUFFIX.length()); |
|
78 } |
|
79 |
|
80 private PluginUtil() { |
|
81 // not instantiable |
|
82 } |
|
83 } |