/******************************************************************************* * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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 * *******************************************************************************/ package com.cisco.yangide.ui; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class YangUIPlugin extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "com.cisco.yangide.ui"; //$NON-NLS-1$ // The shared instance private static YangUIPlugin plugin; /** * The constructor */ public YangUIPlugin() { } @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * * @return the shared instance */ public static YangUIPlugin getDefault() { return plugin; } public static IWorkspace getWorkspace() { return ResourcesPlugin.getWorkspace(); } public static IWorkbenchPage getActivePage() { IWorkbenchWindow window = getDefault().getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; } return window.getActivePage(); } public static IWorkbenchWindow getActiveWorkbenchWindow() { return getDefault().getWorkbench().getActiveWorkbenchWindow(); } public static Shell getActiveWorkbenchShell() { IWorkbenchWindow window = getActiveWorkbenchWindow(); if (window != null) { return window.getShell(); } return null; } public static void log(String message, Throwable e) { log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e)); } public static void log(int statusErrorID, String message) { log(new Status(statusErrorID, PLUGIN_ID, message)); } /* * Add a log entry */ public static void log(IStatus status) { getDefault().getLog().log(status); } public static void log(Throwable e) { log(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e)); } /** * Returns the standard display to be used. The method first checks, if the thread calling this * method has an associated display. If so, this display is returned. Otherwise the method * returns the default display. */ public static Display getStandardDisplay() { Display display = Display.getCurrent(); if (display == null) { display = Display.getDefault(); } return display; } /** * Configurable option value: {@value} . * * @category OptionValue */ public static final String TAB = "tab"; //$NON-NLS-1$ /** * Configurable option value: {@value} . * * @category OptionValue */ public static final String SPACE = "space"; //$NON-NLS-1$ }