| /*=============================================================================# |
| # Copyright (c) 2006, 2021 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.internal.nico.ui; |
| |
| import org.osgi.framework.BundleContext; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.jface.resource.ImageRegistry; |
| import org.eclipse.ui.plugin.AbstractUIPlugin; |
| import org.eclipse.ui.statushandlers.StatusManager; |
| |
| import org.eclipse.statet.ecommons.ts.ui.workbench.WorkbenchToolRegistryListener; |
| import org.eclipse.statet.ecommons.ts.ui.workbench.WorkbenchToolSessionData; |
| import org.eclipse.statet.ecommons.ui.actions.WindowContributionsProvider; |
| import org.eclipse.statet.ecommons.ui.util.ImageRegistryUtil; |
| |
| import org.eclipse.statet.internal.nico.ui.actions.NicoWindowContributions; |
| import org.eclipse.statet.nico.core.NicoCore; |
| import org.eclipse.statet.nico.ui.NicoUI; |
| |
| |
| /** |
| * The activator class controls the plug-in life cycle |
| */ |
| public final class NicoUIPlugin extends AbstractUIPlugin { |
| |
| |
| public static final int INTERNAL_ERROR = 100; |
| |
| |
| private static NicoUIPlugin instance; |
| |
| /** |
| * Returns the shared plug-in instance |
| * |
| * @return the shared instance |
| */ |
| public static NicoUIPlugin getInstance() { |
| return instance; |
| } |
| |
| |
| public static void logError(final int code, final String message, final Throwable e) { |
| StatusManager.getManager().handle(new Status(IStatus.ERROR, NicoCore.BUNDLE_ID, code, message, e)); |
| } |
| |
| |
| private ToolRegistry fToolRegistry; |
| private WindowContributionsProvider fContributionProvider; |
| |
| private DecoratorsRegistry fUIDecoratorsRegistry; |
| |
| |
| /** |
| * The constructor |
| */ |
| public NicoUIPlugin() { |
| instance= this; |
| } |
| |
| |
| @Override |
| public void start(final BundleContext context) throws Exception { |
| super.start(context); |
| |
| fToolRegistry = new ToolRegistry(); |
| fToolRegistry.addListener(new WorkbenchToolRegistryListener() { |
| @Override |
| public void toolSessionActivated(final WorkbenchToolSessionData sessionData) { |
| if (sessionData.getTool() != null) { |
| fToolRegistry.removeListener(this); |
| |
| if (fContributionProvider == null) { |
| fContributionProvider = new NicoWindowContributions(); |
| } |
| } |
| } |
| @Override |
| public void toolTerminated(final WorkbenchToolSessionData sessionData) { |
| } |
| }, null); |
| } |
| |
| @Override |
| public void stop(final BundleContext context) throws Exception { |
| try { |
| if (fToolRegistry != null) { |
| fToolRegistry.dispose(); |
| fToolRegistry = null; |
| } |
| if (fContributionProvider != null) { |
| fContributionProvider.dispose(); |
| fContributionProvider = null; |
| } |
| if (fUIDecoratorsRegistry != null) { |
| fUIDecoratorsRegistry = null; |
| } |
| } |
| finally { |
| instance= null; |
| super.stop(context); |
| } |
| } |
| |
| |
| @Override |
| protected void initializeImageRegistry(final ImageRegistry reg) { |
| final ImageRegistryUtil util = new ImageRegistryUtil(this); |
| |
| util.register(NicoUI.LOCTOOL_CANCEL_IMAGE_ID, ImageRegistryUtil.T_LOCTOOL, "cancel.png"); //$NON-NLS-1$ |
| util.register(NicoUI.LOCTOOLD_CANCEL_IMAGE_ID, ImageRegistryUtil.T_LOCTOOL_D, "cancel.png"); //$NON-NLS-1$ |
| util.register(NicoUI.LOCTOOL_PAUSE_IMAGE_ID, ImageRegistryUtil.T_LOCTOOL, "pause.png"); //$NON-NLS-1$ |
| util.register(NicoUI.LOCTOOLD_PAUSE_IMAGE_ID, ImageRegistryUtil.T_LOCTOOL_D, "pause.png"); //$NON-NLS-1$ |
| util.register(NicoUI.LOCTOOL_TERMINATE_IMAGE_ID, ImageRegistryUtil.T_LOCTOOL, "terminate.png"); //$NON-NLS-1$ |
| util.register(NicoUI.LOCTOOLD_TERMINATE_IMAGE_ID, ImageRegistryUtil.T_LOCTOOL_D, "terminate.png"); //$NON-NLS-1$ |
| |
| util.register(NicoUI.OBJ_TASK_CONSOLECOMMAND_IMAGE_ID, ImageRegistryUtil.T_OBJ, "task-consolecommand.png"); //$NON-NLS-1$ |
| util.register(NicoUI.OBJ_TASK_DUMMY_IMAGE_ID, ImageRegistryUtil.T_OBJ, "task-dummy.png"); //$NON-NLS-1$ |
| util.register(NicoUI.OBJ_CONSOLECOMMAND_IMAGE_ID, ImageRegistryUtil.T_OBJ, "consolecommand.png"); //$NON-NLS-1$ |
| } |
| |
| public ToolRegistry getToolRegistry() { |
| return fToolRegistry; |
| } |
| |
| public synchronized DecoratorsRegistry getUIDecoratorsRegistry() { |
| if (fUIDecoratorsRegistry == null) { |
| fUIDecoratorsRegistry = new DecoratorsRegistry(); |
| } |
| return fUIDecoratorsRegistry; |
| } |
| |
| } |