Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f3a3333309dd4a32ce7a40aa714199159fcfd575 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.examples.filesystem;

import java.io.IOException;

import org.eclipse.core.runtime.*;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.examples.model.PluginManifestChangeTracker;
import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * This is the plugin class for the file system examples. It provides the following:
 * 
 * <ol>
 * <li>public fields for the plugin and provider IDs as defined in the plugin.xml
 * <li>initialization on startup of Policy class that provides internationalization of strings
 * <li>helper methods for outputing IStatus objects to the log
 * <li>helper methods for converting CoreExceptions and IOExceptions to TeamExceptions
 * </ol>
 */
public class FileSystemPlugin extends AbstractUIPlugin {
	
	/**
	 * This is the ID of the plugin as defined in the plugin.xml
	 */
	public static final String ID = "org.eclipse.team.examples.filesystem"; //$NON-NLS-1$
	
	/**
	 * This is the provider ID of the plugin as defined in the plugin.xml
	 */
	public static final String PROVIDER_ID = ID + ".FileSystemProvider"; //$NON-NLS-1$
	
	// This static field will hold the singleton instance of the plugin class
	private static FileSystemPlugin plugin;
	
	private PessimisticFilesystemProviderPlugin pessPlugin;
	
	private PluginManifestChangeTracker tracker;
	
	/**
	 * Override the standard plugin constructor.
	 */
	public FileSystemPlugin() {
		super();
		// record this instance as the singleton
		plugin = this;
		// Instanctiate pessimistic provider
		pessPlugin = new PessimisticFilesystemProviderPlugin();
	}
	
	/**
	 * Return the singlton instance of the plugin class to allow other
	 * classes in the plugin access to plugin instance methods such as 
	 * those for logging errors, etc.
	 */
	public static FileSystemPlugin getPlugin() {
		return plugin;
	}
	
	/**
	 * Helper method to convert a CoreException into a TeamException.
	 * We do this to maintain the core status and code. This type of
	 * mapping may not be appropriate in more complicated exception 
	 * handling situations.
	 * 
	 * @param e the CoreException
	 */
	public static TeamException wrapException(CoreException e) {
		return new TeamException(e.getStatus());
	}

	/**
	 * Helper method to convert an IOException into a TeamException.
	 * This type of mapping may not be appropriate in more complicated 
	 * exception handling situations.
	 * 
	 * @param e the CoreException
	 */
	public static TeamException wrapException(IOException e) {
		return new TeamException(new Status(IStatus.ERROR, FileSystemPlugin.ID, 
			TeamException.IO_FAILED, e.getMessage(), e));
	}
	
	/**
	 * Helper method to log an exception status.
	 * 
	 * @param status the status to be logged
	 */
	public static void log(IStatus status) {
		plugin.getLog().log(status);
	}
	
	/**
	 * 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;		
	}
	
	public void start(BundleContext context) throws Exception {
		super.start(context);
		//Call startup on the Pessimistic Plugin
		pessPlugin.start(context);
		tracker = new PluginManifestChangeTracker();
		tracker.start();
	}
	
	public void stop(BundleContext context) throws Exception {
		try {
			if (pessPlugin != null)
				pessPlugin.stop(context);
		} finally {
			super.stop(context);
		}
		tracker.dispose();
		tracker = null;
	}

	public static void log(CoreException e) {
		log (new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, e.getMessage(), e));
	}
}

Back to the top