Skip to main content
summaryrefslogtreecommitdiffstats
blob: df787013fb66b2479fea38b05f8f6652b62bf524 (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
145
146
147
148
149
150
151
152
/*
 * Copyright (c) 2002 IBM Corp.  All rights reserved.
 * This file is made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 */
package org.eclipse.team.examples.pessimistic;
 
import java.util.*;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;

/**
 * The plugin for the <code>PessimisticFilesystemProvider</code>.
 */
public class PessimisticFilesystemProviderPlugin extends AbstractUIPlugin {
	/*
	 * Singleton instance.
	 */
	private static PessimisticFilesystemProviderPlugin instance;
	/*
	 * The resource change listener which notifies the provider of 
	 * added and deleted files.
	 */
	private ResourceChangeListener fListener;
	/*
	 * The provider listeners
	 */
	private List fListeners;

	/**
	 * The plugin identifier
	 */
	public static final String PLUGIN_ID = "org.eclipse.team.examples.pessimistic";
	/**
	 * The nature identifier.
	 */
	public static final String NATURE_ID = PLUGIN_ID + ".pessimisticnature";

	/**
	 * Contstructor required by plugin lifecycle.
	 */
	public PessimisticFilesystemProviderPlugin(IPluginDescriptor pluginDescriptor) {
		super(pluginDescriptor);
		instance = this;
		fListeners= new ArrayList(1);
		//setDebugging(true);
	}

	/**
	 * Answers the singleton instance of this plugin.
	 */	
	public static PessimisticFilesystemProviderPlugin getInstance() {
		return instance;
	}

	/**
	 * Initializes the default preferences for this plugin.
	 */
	protected void initializeDefaultPreferences(IPreferenceStore store) {
		store.setDefault(
			IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED,
			IPessimisticFilesystemConstants.OPTION_PROMPT);
		store.setDefault(
			IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT,
			IPessimisticFilesystemConstants.OPTION_AUTOMATIC);
		store.setDefault(
			IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED,
			IPessimisticFilesystemConstants.OPTION_DO_NOTHING);
		store.setDefault(
			IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL,
			IPessimisticFilesystemConstants.OPTION_PROMPT);			
		store.setDefault(IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT, false);
		store.setDefault(IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT, true);
	}
	
	/**
	 * Convenience method for logging errors.
	 */
	public void logError(Throwable exception, String message) {
		String pluginId= getDescriptor().getUniqueIdentifier();
		Status status= new Status(Status.ERROR, pluginId, Status.OK, message, exception);
		getLog().log(status);
		if (isDebugging()) {
			System.out.println(message);
			exception.printStackTrace();
		}			
	}

	/**
	 * Starts the resource listener.
	 * 
	 * @see Plugin#startup()
	 */
	public void startup() throws CoreException {
		fListener= new ResourceChangeListener();
		fListener.startup();
		super.startup();
	}

	/**
	 * Stops the resource listener.
	 * 
	 * @see Plugin#startup()
	 */
	public void shutdown() throws CoreException {
		fListener.shutdown();
		fListener= null;
		super.shutdown();
	}
	
	/**
	 * Notifies the registered <code>IResourceStateListener</code> objects
	 * that the repository state for the resources has changed.
	 * 
	 * @param resources	Collection of resources that have changed.
	 */
	public void fireResourcesChanged(IResource[] resources) {
		if (resources == null || resources.length == 0 || fListeners.isEmpty())
			return;
		for (Iterator i= fListeners.iterator(); i.hasNext();) {
			IResourceStateListener listener= (IResourceStateListener) i.next();
			listener.stateChanged(resources);
		}
	}
	
	/**
	 * Adds the listener to the list of listeners that are notified when
	 * the repository state of resources change.
	 * 
	 * @param listener
	 */
	public void addProviderListener(IResourceStateListener listener) {
		if (fListeners.contains(listener))
			return;
		fListeners.add(listener);
	}
	
	
	/**
	 * Removes the listener from the list of listeners that are notified when
	 * the repository state of resources change.
	 * 
	 * @param listener
	 */
	public void removeProviderListener(IResourceStateListener listener) {
		fListeners.remove(listener);
	}
}

Back to the top