|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-2016 Angelo ZERR. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | + * Angelo Zerr <[email protected]> - initial API and implementation |
| 10 | + */ |
| 11 | +package ts.eclipse.ide.ui.editor; |
| 12 | + |
| 13 | +import org.eclipse.core.runtime.IStatus; |
| 14 | +import org.eclipse.core.runtime.MultiStatus; |
| 15 | +import org.eclipse.core.runtime.Status; |
| 16 | +import org.eclipse.swt.widgets.Display; |
| 17 | +import org.eclipse.swt.widgets.Shell; |
| 18 | +import org.eclipse.ui.IWorkbenchPage; |
| 19 | +import org.eclipse.ui.IWorkbenchWindow; |
| 20 | +import org.eclipse.ui.forms.FormColors; |
| 21 | +import org.eclipse.ui.forms.widgets.FormToolkit; |
| 22 | +import org.eclipse.ui.plugin.AbstractUIPlugin; |
| 23 | +import org.eclipse.ui.texteditor.IDocumentProvider; |
| 24 | +import org.osgi.framework.BundleContext; |
| 25 | + |
| 26 | +import ts.eclipse.ide.ui.editor.internal.TypeScriptDocumentProvider; |
| 27 | +import ts.eclipse.ide.ui.editor.internal.TypeScriptUIMessages; |
| 28 | + |
| 29 | +/** |
| 30 | + * The activator class controls the plug-in life cycle |
| 31 | + */ |
| 32 | +public class TypeScriptUIEditorPlugin extends AbstractUIPlugin { |
| 33 | + |
| 34 | + // The plug-in ID |
| 35 | + public static final String PLUGIN_ID = "ts.eclipse.ide.ui.editor"; //$NON-NLS-1$ |
| 36 | + |
| 37 | + private static final int INTERNAL_ERROR = 10001; |
| 38 | + |
| 39 | + // The shared instance |
| 40 | + private static TypeScriptUIEditorPlugin plugin; |
| 41 | + |
| 42 | + private FormToolkit fDialogsFormToolkit; |
| 43 | + |
| 44 | + private TypeScriptDocumentProvider documentProvider; |
| 45 | + |
| 46 | + /** |
| 47 | + * The constructor |
| 48 | + */ |
| 49 | + public TypeScriptUIEditorPlugin() { |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void start(BundleContext context) throws Exception { |
| 54 | + super.start(context); |
| 55 | + plugin = this; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public void stop(BundleContext context) throws Exception { |
| 60 | + try { |
| 61 | + if (fDialogsFormToolkit != null) { |
| 62 | + fDialogsFormToolkit.dispose(); |
| 63 | + fDialogsFormToolkit = null; |
| 64 | + } |
| 65 | + } finally { |
| 66 | + plugin = null; |
| 67 | + super.stop(context); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Returns the shared instance |
| 73 | + * |
| 74 | + * @return the shared instance |
| 75 | + */ |
| 76 | + public static TypeScriptUIEditorPlugin getDefault() { |
| 77 | + return plugin; |
| 78 | + } |
| 79 | + |
| 80 | + public static IWorkbenchWindow getActiveWorkbenchWindow() { |
| 81 | + return getDefault().getWorkbench().getActiveWorkbenchWindow(); |
| 82 | + } |
| 83 | + |
| 84 | + public static Shell getActiveWorkbenchShell() { |
| 85 | + IWorkbenchWindow window = getActiveWorkbenchWindow(); |
| 86 | + if (window != null) { |
| 87 | + return window.getShell(); |
| 88 | + } |
| 89 | + return null; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @return Returns the active workbench window's currrent page. |
| 94 | + */ |
| 95 | + public static IWorkbenchPage getActivePage() { |
| 96 | + return getActiveWorkbenchWindow().getActivePage(); |
| 97 | + } |
| 98 | + |
| 99 | + public FormToolkit getDialogsFormToolkit() { |
| 100 | + if (fDialogsFormToolkit == null) { |
| 101 | + FormColors colors = new FormColors(Display.getCurrent()); |
| 102 | + colors.setBackground(null); |
| 103 | + colors.setForeground(null); |
| 104 | + fDialogsFormToolkit = new FormToolkit(colors); |
| 105 | + } |
| 106 | + return fDialogsFormToolkit; |
| 107 | + } |
| 108 | + |
| 109 | + public static void log(IStatus status) { |
| 110 | + getDefault().getLog().log(status); |
| 111 | + } |
| 112 | + |
| 113 | + public static void logErrorMessage(String message) { |
| 114 | + log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, null)); |
| 115 | + } |
| 116 | + |
| 117 | + public static void logErrorStatus(String message, IStatus status) { |
| 118 | + if (status == null) { |
| 119 | + logErrorMessage(message); |
| 120 | + return; |
| 121 | + } |
| 122 | + MultiStatus multi = new MultiStatus(PLUGIN_ID, INTERNAL_ERROR, message, null); |
| 123 | + multi.add(status); |
| 124 | + log(multi); |
| 125 | + } |
| 126 | + |
| 127 | + public static void log(String message, Throwable e) { |
| 128 | + log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, e)); |
| 129 | + } |
| 130 | + |
| 131 | + public static void log(Throwable e) { |
| 132 | + log(TypeScriptUIMessages.TypeScriptUIPlugin_internal_error, e); |
| 133 | + } |
| 134 | + |
| 135 | + public synchronized IDocumentProvider getTypeScriptDocumentProvider() { |
| 136 | + if (documentProvider == null) { |
| 137 | + documentProvider = new TypeScriptDocumentProvider(); |
| 138 | + } |
| 139 | + return documentProvider; |
| 140 | + } |
| 141 | +} |
0 commit comments