1 /******************************************************************************* 2 * Copyright (c) 2000, 2015 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.team.examples.filesystem; 15 16 import java.io.IOException; 17 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.swt.widgets.Display; 20 import org.eclipse.team.core.TeamException; 21 import org.eclipse.team.examples.model.PluginManifestChangeTracker; 22 import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; 23 import org.eclipse.ui.plugin.AbstractUIPlugin; 24 import org.osgi.framework.BundleContext; 25 26 /** 27 * This is the plugin class for the file system examples. It provides the following: 28 * 29 * <ol> 30 * <li>public fields for the plugin and provider IDs as defined in the plugin.xml 31 * <li>initialization on startup of Policy class that provides internationalization of strings 32 * <li>helper methods for outputing IStatus objects to the log 33 * <li>helper methods for converting CoreExceptions and IOExceptions to TeamExceptions 34 * </ol> 35 */ 36 public class FileSystemPlugin extends AbstractUIPlugin { 37 38 /** 39 * This is the ID of the plugin as defined in the plugin.xml 40 */ 41 public static final String ID = "org.eclipse.team.examples.filesystem"; //$NON-NLS-1$ 42 43 /** 44 * This is the provider ID of the plugin as defined in the plugin.xml 45 */ 46 public static final String PROVIDER_ID = ID + ".FileSystemProvider"; //$NON-NLS-1$ 47 48 // This static field will hold the singleton instance of the plugin class 49 private static FileSystemPlugin plugin; 50 51 private PessimisticFilesystemProviderPlugin pessPlugin; 52 53 private PluginManifestChangeTracker tracker; 54 55 /** 56 * Override the standard plugin constructor. 57 */ FileSystemPlugin()58 public FileSystemPlugin() { 59 super(); 60 // record this instance as the singleton 61 plugin = this; 62 // Instanctiate pessimistic provider 63 pessPlugin = new PessimisticFilesystemProviderPlugin(); 64 } 65 66 /** 67 * Return the singlton instance of the plugin class to allow other 68 * classes in the plugin access to plugin instance methods such as 69 * those for logging errors, etc. 70 */ getPlugin()71 public static FileSystemPlugin getPlugin() { 72 return plugin; 73 } 74 75 /** 76 * Helper method to convert a CoreException into a TeamException. 77 * We do this to maintain the core status and code. This type of 78 * mapping may not be appropriate in more complicated exception 79 * handling situations. 80 * 81 * @param e the CoreException 82 */ wrapException(CoreException e)83 public static TeamException wrapException(CoreException e) { 84 return new TeamException(e.getStatus()); 85 } 86 87 /** 88 * Helper method to convert an IOException into a TeamException. 89 * This type of mapping may not be appropriate in more complicated 90 * exception handling situations. 91 * 92 * @param e the CoreException 93 */ wrapException(IOException e)94 public static TeamException wrapException(IOException e) { 95 return new TeamException(new Status(IStatus.ERROR, FileSystemPlugin.ID, 96 TeamException.IO_FAILED, e.getMessage(), e)); 97 } 98 99 /** 100 * Helper method to log an exception status. 101 * 102 * @param status the status to be logged 103 */ log(IStatus status)104 public static void log(IStatus status) { 105 plugin.getLog().log(status); 106 } 107 108 /** 109 * Returns the standard display to be used. The method first checks, if 110 * the thread calling this method has an associated display. If so, this 111 * display is returned. Otherwise the method returns the default display. 112 */ getStandardDisplay()113 public static Display getStandardDisplay() { 114 Display display= Display.getCurrent(); 115 if (display == null) { 116 display= Display.getDefault(); 117 } 118 return display; 119 } 120 start(BundleContext context)121 public void start(BundleContext context) throws Exception { 122 super.start(context); 123 //Call startup on the Pessimistic Plugin 124 pessPlugin.start(context); 125 tracker = new PluginManifestChangeTracker(); 126 tracker.start(); 127 } 128 stop(BundleContext context)129 public void stop(BundleContext context) throws Exception { 130 try { 131 if (pessPlugin != null) 132 pessPlugin.stop(context); 133 } finally { 134 super.stop(context); 135 } 136 tracker.dispose(); 137 tracker = null; 138 } 139 log(CoreException e)140 public static void log(CoreException e) { 141 log (new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, e.getMessage(), e)); 142 } 143 } 144 145