KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > CVSUIPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Philippe Ombredanne - bug 84808
11  * William Mitsuda (wmitsuda@gmail.com) - Bug 153879 [Wizards] configurable size of cvs commit comment history
12  * Brock Janiczak <brockj@tpg.com.au> - Bug 161536 Warn user when committing resources with problem markers
13  *******************************************************************************/

14
15 package org.eclipse.team.internal.ccvs.ui;
16
17 import java.lang.reflect.InvocationTargetException JavaDoc;
18 import java.net.URL JavaDoc;
19 import java.util.*;
20
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IResourceStatus;
23 import org.eclipse.core.runtime.*;
24 import org.eclipse.jface.dialogs.*;
25 import org.eclipse.jface.operation.IRunnableWithProgress;
26 import org.eclipse.jface.preference.IPreferenceStore;
27 import org.eclipse.jface.preference.PreferenceConverter;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.jface.util.IPropertyChangeListener;
30 import org.eclipse.jface.util.PropertyChangeEvent;
31 import org.eclipse.osgi.util.NLS;
32 import org.eclipse.swt.graphics.RGB;
33 import org.eclipse.swt.widgets.Display;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.team.core.TeamException;
36 import org.eclipse.team.core.history.IFileRevision;
37 import org.eclipse.team.internal.ccvs.core.*;
38 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
39 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
40 import org.eclipse.team.internal.ccvs.ui.console.CVSOutputConsole;
41 import org.eclipse.team.internal.ccvs.ui.model.CVSAdapterFactory;
42 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
43 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
44 import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
45 import org.eclipse.team.internal.ui.*;
46 import org.eclipse.ui.*;
47 import org.eclipse.ui.plugin.AbstractUIPlugin;
48 import org.osgi.framework.BundleContext;
49
50 /**
51  * UI Plugin for CVS provider-specific workbench functionality.
52  */

53 public class CVSUIPlugin extends AbstractUIPlugin {
54     /**
55      * The id of the CVS plug-in
56      */

57     public static final String JavaDoc ID = "org.eclipse.team.cvs.ui"; //$NON-NLS-1$
58
public static final String JavaDoc DECORATOR_ID = "org.eclipse.team.cvs.ui.decorator"; //$NON-NLS-1$
59

60     /**
61      * Property constant indicating the decorator configuration has changed.
62      */

63     public static final String JavaDoc P_DECORATORS_CHANGED = CVSUIPlugin.ID + ".P_DECORATORS_CHANGED"; //$NON-NLS-1$
64

65     private Hashtable imageDescriptors = new Hashtable(20);
66     private static List propertyChangeListeners = new ArrayList(5);
67     
68     /**
69      * The singleton plug-in instance
70      */

71     private static CVSUIPlugin plugin;
72     
73     /**
74      * The CVS console
75      */

76     private CVSOutputConsole console;
77     
78     /**
79      * The repository manager
80      */

81     private RepositoryManager repositoryManager;
82
83     /**
84      * CVSUIPlugin constructor
85      *
86      * @param descriptor the plugin descriptor
87      */

88     public CVSUIPlugin() {
89         super();
90         plugin = this;
91     }
92     
93     /**
94      * Returns the standard display to be used. The method first checks, if
95      * the thread calling this method has an associated display. If so, this
96      * display is returned. Otherwise the method returns the default display.
97      */

98     public static Display getStandardDisplay() {
99         Display display= Display.getCurrent();
100         if (display == null) {
101             display= Display.getDefault();
102         }
103         return display;
104     }
105     
106     /**
107      * Creates an image and places it in the image registry.
108      */

109     protected void createImageDescriptor(String JavaDoc id) {
110         URL JavaDoc url = FileLocator.find(CVSUIPlugin.getPlugin().getBundle(), new Path(ICVSUIConstants.ICON_PATH + id), null);
111         ImageDescriptor desc = ImageDescriptor.createFromURL(url);
112         imageDescriptors.put(id, desc);
113     }
114     
115     /**
116      * Returns the active workbench page. Note that the active page may not be
117      * the one that the user perceives as active in some situations so this
118      * method of obtaining the activate page should only be used if no other
119      * method is available.
120      *
121      * @return the active workbench page
122      */

123     public static IWorkbenchPage getActivePage() {
124         return TeamUIPlugin.getActivePage();
125     }
126     
127     /**
128      * Register for changes made to Team properties.
129      */

130     public static void addPropertyChangeListener(IPropertyChangeListener listener) {
131         propertyChangeListeners.add(listener);
132     }
133     
134     /**
135      * Remove a Team property changes.
136      */

137     public static void removePropertyChangeListener(IPropertyChangeListener listener) {
138         propertyChangeListeners.remove(listener);
139     }
140     
141     /**
142      * Broadcast a Team property change.
143      */

144     public static void broadcastPropertyChange(PropertyChangeEvent event) {
145         for (Iterator it = propertyChangeListeners.iterator(); it.hasNext();) {
146             IPropertyChangeListener listener = (IPropertyChangeListener)it.next();
147             listener.propertyChange(event);
148         }
149     }
150     
151     /**
152      * Run an operation involving the given resource. If an exception is thrown
153      * and the code on the status is IResourceStatus.OUT_OF_SYNC_LOCAL then
154      * the user will be prompted to refresh and try again. If they agree, then the
155      * supplied operation will be run again.
156      */

157     public static void runWithRefresh(Shell parent, IResource[] resources,
158                                       IRunnableWithProgress runnable, IProgressMonitor monitor)
159     throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
160         boolean firstTime = true;
161         while(true) {
162             try {
163                 runnable.run(monitor);
164                 return;
165             } catch (InvocationTargetException JavaDoc e) {
166                 if (! firstTime) throw e;
167                 IStatus status = null;
168                 if (e.getTargetException() instanceof CoreException) {
169                     status = ((CoreException)e.getTargetException()).getStatus();
170                 } else if (e.getTargetException() instanceof TeamException) {
171                     status = ((TeamException)e.getTargetException()).getStatus();
172                 } else {
173                     throw e;
174                 }
175                 if (status.getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) {
176                     if (promptToRefresh(parent, resources, status)) {
177                         try {
178                             for (int i = 0; i < resources.length; i++) {
179                                 resources[i].refreshLocal(IResource.DEPTH_INFINITE, null);
180                             }
181                         } catch (CoreException coreEx) {
182                             // Throw the original exception to the caller
183
log(coreEx);
184                             throw e;
185                         }
186                         firstTime = false;
187                         // Fall through and the operation will be tried again
188
} else {
189                         // User chose not to continue. Treat it as a cancel.
190
throw new InterruptedException JavaDoc();
191                     }
192                 } else {
193                     throw e;
194                 }
195             }
196         }
197     }
198     
199     private static boolean promptToRefresh(final Shell shell, final IResource[] resources, final IStatus status) {
200         final boolean[] result = new boolean[] { false};
201         Runnable JavaDoc runnable = new Runnable JavaDoc() {
202             public void run() {
203                 Shell shellToUse = shell;
204                 if (shell == null) {
205                     shellToUse = new Shell(Display.getCurrent());
206                 }
207                 String JavaDoc question;
208                 if (resources.length == 1) {
209                     question = NLS.bind(CVSUIMessages.CVSUIPlugin_refreshQuestion, new String JavaDoc[] { status.getMessage(), resources[0].getFullPath().toString() });
210                 } else {
211                     question = NLS.bind(CVSUIMessages.CVSUIPlugin_refreshMultipleQuestion, new String JavaDoc[] { status.getMessage() });
212                 }
213                 result[0] = MessageDialog.openQuestion(shellToUse, CVSUIMessages.CVSUIPlugin_refreshTitle, question);
214             }
215         };
216         Display.getDefault().syncExec(runnable);
217         return result[0];
218     }
219     
220     /**
221      * Creates a busy cursor and runs the specified runnable.
222      * May be called from a non-UI thread.
223      *
224      * @param parent the parent Shell for the dialog
225      * @param cancelable if true, the dialog will support cancelation
226      * @param runnable the runnable
227      *
228      * @exception InvocationTargetException when an exception is thrown from the runnable
229      * @exception InterruptedException when the progress monitor is canceled
230      */

231     public static void runWithProgress(Shell parent, boolean cancelable,
232                                        final IRunnableWithProgress runnable) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
233         Utils.runWithProgress(parent, cancelable, runnable);
234     }
235     
236     /**
237      * Returns the image descriptor for the given image ID.
238      * Returns null if there is no such image.
239      */

240     public ImageDescriptor getImageDescriptor(String JavaDoc id) {
241         return (ImageDescriptor)imageDescriptors.get(id);
242     }
243     
244     /**
245      * Returns the singleton plug-in instance.
246      *
247      * @return the plugin instance
248      */

249     public static CVSUIPlugin getPlugin() {
250         return plugin;
251     }
252     
253     /**
254      * Returns the repository manager
255      *
256      * @return the repository manager
257      */

258     public synchronized RepositoryManager getRepositoryManager() {
259         if (repositoryManager == null) {
260             repositoryManager = new RepositoryManager();
261             repositoryManager.startup();
262         }
263         return repositoryManager;
264     }
265     
266     /**
267      * Initializes the table of images used in this plugin.
268      */

269     private void initializeImages() {
270         // objects
271
createImageDescriptor(ICVSUIConstants.IMG_REPOSITORY);
272         createImageDescriptor(ICVSUIConstants.IMG_REFRESH);
273         createImageDescriptor(ICVSUIConstants.IMG_REFRESH_ENABLED);
274         createImageDescriptor(ICVSUIConstants.IMG_REFRESH_DISABLED);
275         createImageDescriptor(ICVSUIConstants.IMG_LINK_WITH_EDITOR);
276         createImageDescriptor(ICVSUIConstants.IMG_LINK_WITH_EDITOR_ENABLED);
277         createImageDescriptor(ICVSUIConstants.IMG_COLLAPSE_ALL);
278         createImageDescriptor(ICVSUIConstants.IMG_COLLAPSE_ALL_ENABLED);
279         createImageDescriptor(ICVSUIConstants.IMG_NEWLOCATION);
280         createImageDescriptor(ICVSUIConstants.IMG_CVSLOGO);
281         createImageDescriptor(ICVSUIConstants.IMG_TAG);
282         createImageDescriptor(ICVSUIConstants.IMG_MODULE);
283         createImageDescriptor(ICVSUIConstants.IMG_CLEAR);
284         createImageDescriptor(ICVSUIConstants.IMG_CLEAR_ENABLED);
285         createImageDescriptor(ICVSUIConstants.IMG_CLEAR_DISABLED);
286         createImageDescriptor(ICVSUIConstants.IMG_BRANCHES_CATEGORY);
287         createImageDescriptor(ICVSUIConstants.IMG_VERSIONS_CATEGORY);
288         createImageDescriptor(ICVSUIConstants.IMG_DATES_CATEGORY);
289         createImageDescriptor(ICVSUIConstants.IMG_PROJECT_VERSION);
290         createImageDescriptor(ICVSUIConstants.IMG_WIZBAN_MERGE);
291         createImageDescriptor(ICVSUIConstants.IMG_WIZBAN_SHARE);
292         createImageDescriptor(ICVSUIConstants.IMG_WIZBAN_DIFF);
293         createImageDescriptor(ICVSUIConstants.IMG_WIZBAN_KEYWORD);
294         createImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION);
295         createImageDescriptor(ICVSUIConstants.IMG_WIZBAN_IMPORT);
296         createImageDescriptor(ICVSUIConstants.IMG_MERGEABLE_CONFLICT);
297         createImageDescriptor(ICVSUIConstants.IMG_QUESTIONABLE);
298         createImageDescriptor(ICVSUIConstants.IMG_MERGED);
299         createImageDescriptor(ICVSUIConstants.IMG_EDITED);
300         createImageDescriptor(ICVSUIConstants.IMG_NO_REMOTEDIR);
301         createImageDescriptor(ICVSUIConstants.IMG_CVS_CONSOLE);
302         createImageDescriptor(ICVSUIConstants.IMG_DATE);
303         createImageDescriptor(ICVSUIConstants.IMG_CHANGELOG);
304         createImageDescriptor(ICVSUIConstants.IMG_FILTER_HISTORY);
305         createImageDescriptor(ICVSUIConstants.IMG_LOCALMODE);
306         createImageDescriptor(ICVSUIConstants.IMG_LOCALREMOTE_MODE);
307         createImageDescriptor(ICVSUIConstants.IMG_REMOTEMODE);
308         createImageDescriptor(ICVSUIConstants.IMG_LOCALMODE_DISABLED);
309         createImageDescriptor(ICVSUIConstants.IMG_LOCALREMOTE_MODE_DISABLED);
310         createImageDescriptor(ICVSUIConstants.IMG_REMOTEMODE_DISABLED);
311         createImageDescriptor(ICVSUIConstants.IMG_LOCALREVISION_TABLE);
312         createImageDescriptor(ICVSUIConstants.IMG_REMOTEREVISION_TABLE);
313         createImageDescriptor(ICVSUIConstants.IMG_COMPARE_VIEW);
314         
315         // special
316
createImageDescriptor("glyphs/glyph1.gif"); //$NON-NLS-1$
317
createImageDescriptor("glyphs/glyph2.gif"); //$NON-NLS-1$
318
createImageDescriptor("glyphs/glyph3.gif"); //$NON-NLS-1$
319
createImageDescriptor("glyphs/glyph4.gif"); //$NON-NLS-1$
320
createImageDescriptor("glyphs/glyph5.gif"); //$NON-NLS-1$
321
createImageDescriptor("glyphs/glyph6.gif"); //$NON-NLS-1$
322
createImageDescriptor("glyphs/glyph7.gif"); //$NON-NLS-1$
323
createImageDescriptor("glyphs/glyph8.gif"); //$NON-NLS-1$
324
}
325     /**
326      * Convenience method for logging statuses to the plugin log
327      *
328      * @param status the status to log
329      */

330     public static void log(IStatus status) {
331         getPlugin().getLog().log(status);
332     }
333     
334     public static void log(CoreException e) {
335         log(e.getStatus().getSeverity(), CVSUIMessages.simpleInternal, e);
336     }
337     
338     /**
339      * Log the given exception along with the provided message and severity indicator
340      */

341     public static void log(int severity, String JavaDoc message, Throwable JavaDoc e) {
342         log(new Status(severity, ID, 0, message, e));
343     }
344     
345     // flags to tailor error reporting
346
public static final int PERFORM_SYNC_EXEC = 1;
347     public static final int LOG_TEAM_EXCEPTIONS = 2;
348     public static final int LOG_CORE_EXCEPTIONS = 4;
349     public static final int LOG_OTHER_EXCEPTIONS = 8;
350     public static final int LOG_NONTEAM_EXCEPTIONS = LOG_CORE_EXCEPTIONS | LOG_OTHER_EXCEPTIONS;
351     
352     /**
353      * Convenience method for showing an error dialog
354      * @param shell a valid shell or null
355      * @param exception the exception to be report
356      * @param title the title to be displayed
357      * @return IStatus the status that was displayed to the user
358      */

359     public static IStatus openError(Shell shell, String JavaDoc title, String JavaDoc message, Throwable JavaDoc exception) {
360         return openError(shell, title, message, exception, LOG_OTHER_EXCEPTIONS);
361     }
362     
363     /**
364      * Convenience method for showing an error dialog
365      * @param shell a valid shell or null
366      * @param exception the exception to be report
367      * @param title the title to be displayed
368      * @param flags customized attributes for the error handling
369      * @return IStatus the status that was displayed to the user
370      */

371     public static IStatus openError(Shell providedShell, String JavaDoc title, String JavaDoc message, Throwable JavaDoc exception, int flags) {
372         // Unwrap InvocationTargetExceptions
373
if (exception instanceof InvocationTargetException JavaDoc) {
374             Throwable JavaDoc target = ((InvocationTargetException JavaDoc)exception).getTargetException();
375             // re-throw any runtime exceptions or errors so they can be handled by the workbench
376
if (target instanceof RuntimeException JavaDoc) {
377                 throw (RuntimeException JavaDoc)target;
378             }
379             if (target instanceof Error JavaDoc) {
380                 throw (Error JavaDoc)target;
381             }
382             return openError(providedShell, title, message, target, flags);
383         }
384         
385         // Determine the status to be displayed (and possibly logged)
386
IStatus status = null;
387         boolean log = false;
388         if (exception instanceof CoreException) {
389             status = ((CoreException)exception).getStatus();
390             log = ((flags & LOG_CORE_EXCEPTIONS) > 0);
391         } else if (exception instanceof TeamException) {
392             status = ((TeamException)exception).getStatus();
393             log = ((flags & LOG_TEAM_EXCEPTIONS) > 0);
394         } else if (exception instanceof InterruptedException JavaDoc) {
395             return new CVSStatus(IStatus.OK, CVSUIMessages.ok);
396         } else if (exception != null) {
397             status = new CVSStatus(IStatus.ERROR, CVSUIMessages.internal, exception);
398             log = ((flags & LOG_OTHER_EXCEPTIONS) > 0);
399             if (title == null) title = CVSUIMessages.internal;
400         }
401         
402         // Check for a build error and report it differently
403
if (status.getCode() == IResourceStatus.BUILD_FAILED) {
404             message = CVSUIMessages.buildError;
405             log = true;
406         }
407         
408         // Check for multi-status with only one child
409
if (status.isMultiStatus() && status.getChildren().length == 1) {
410             status = status.getChildren()[0];
411         }
412         if (status.isOK()) return status;
413         
414         // Log if the user requested it
415
if (log) CVSUIPlugin.log(status.getSeverity(), status.getMessage(), exception);
416         
417         // Create a runnable that will display the error status
418
final String JavaDoc displayTitle = title;
419         final String JavaDoc displayMessage = message;
420         final IStatus displayStatus = status;
421         final IOpenableInShell openable = new IOpenableInShell() {
422             public void open(Shell shell) {
423                 if (displayStatus.getSeverity() == IStatus.INFO && !displayStatus.isMultiStatus()) {
424                     MessageDialog.openInformation(shell, CVSUIMessages.information, displayStatus.getMessage());
425                 } else {
426                     ErrorDialog.openError(shell, displayTitle, displayMessage, displayStatus);
427                 }
428             }
429         };
430         openDialog(providedShell, openable, flags);
431         
432         // return the status we display
433
return status;
434     }
435     
436     /**
437      * Interface that allows a shell to be passed to an open method. The
438      * provided shell can be used without sync-execing, etc.
439      */

440     public interface IOpenableInShell {
441         public void open(Shell shell);
442     }
443     
444     /**
445      * Open the dialog code provided in the IOpenableInShell, ensuring that
446      * the provided shell is valid. This method will provide a shell to the
447      * IOpenableInShell if one is not provided to the method.
448      *
449      * @param providedShell
450      * @param openable
451      * @param flags
452      */

453     public static void openDialog(Shell providedShell, final IOpenableInShell openable, int flags) {
454         // If no shell was provided, try to get one from the active window
455
if (providedShell == null) {
456             IWorkbenchWindow window = CVSUIPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow();
457             if (window != null) {
458                 providedShell = window.getShell();
459                 // sync-exec when we do this just in case
460
flags = flags | PERFORM_SYNC_EXEC;
461             }
462         }
463         
464         // Create a runnable that will display the error status
465
final Shell shell = providedShell;
466         Runnable JavaDoc outerRunnable = new Runnable JavaDoc() {
467             public void run() {
468                 Shell displayShell;
469                 if (shell == null) {
470                     Display display = Display.getCurrent();
471                     displayShell = new Shell(display);
472                 } else {
473                     displayShell = shell;
474                 }
475                 openable.open(displayShell);
476                 if (shell == null) {
477                     displayShell.dispose();
478                 }
479             }
480         };
481         
482         // Execute the above runnable as determined by the parameters
483
if (shell == null || (flags & PERFORM_SYNC_EXEC) > 0) {
484             Display display;
485             if (shell == null) {
486                 display = Display.getCurrent();
487                 if (display == null) {
488                     display = Display.getDefault();
489                 }
490             } else {
491                 display = shell.getDisplay();
492             }
493             display.syncExec(outerRunnable);
494         } else {
495             outerRunnable.run();
496         }
497     }
498     
499     
500     /**
501      * Initializes the preferences for this plugin if necessary.
502      */

503     protected void initializeDefaultPluginPreferences() {
504         IPreferenceStore store = getPreferenceStore();
505         // Get the plugin preferences for CVS Core
506
Preferences corePrefs = CVSProviderPlugin.getPlugin().getPluginPreferences();
507         
508         store.setDefault(ICVSUIConstants.PREF_REPOSITORIES_ARE_BINARY, false);
509         store.setDefault(ICVSUIConstants.PREF_SHOW_COMMENTS, true);
510         store.setDefault(ICVSUIConstants.PREF_WRAP_COMMENTS, true);
511         store.setDefault(ICVSUIConstants.PREF_SHOW_TAGS, true);
512         store.setDefault(ICVSUIConstants.PREF_SHOW_SEARCH, false);
513         store.setDefault(ICVSUIConstants.PREF_REVISION_MODE, 0);
514         store.setDefault(ICVSUIConstants.PREF_GROUPBYDATE_MODE, true);
515         store.setDefault(ICVSUIConstants.PREF_HISTORY_VIEW_EDITOR_LINKING, false);
516         store.setDefault(ICVSUIConstants.PREF_PRUNE_EMPTY_DIRECTORIES, CVSProviderPlugin.DEFAULT_PRUNE);
517         store.setDefault(ICVSUIConstants.PREF_TIMEOUT, CVSProviderPlugin.DEFAULT_TIMEOUT);
518         store.setDefault(ICVSUIConstants.PREF_CONSIDER_CONTENTS, true);
519         store.setDefault(ICVSUIConstants.PREF_COMPRESSION_LEVEL, CVSProviderPlugin.DEFAULT_COMPRESSION_LEVEL);
520         store.setDefault(ICVSUIConstants.PREF_TEXT_KSUBST, CVSProviderPlugin.DEFAULT_TEXT_KSUBST_OPTION.toMode());
521         store.setDefault(ICVSUIConstants.PREF_USE_PLATFORM_LINEEND, true);
522         store.setDefault(ICVSUIConstants.PREF_REPLACE_UNMANAGED, true);
523         store.setDefault(ICVSUIConstants.PREF_CVS_RSH, CVSProviderPlugin.DEFAULT_CVS_RSH);
524         store.setDefault(ICVSUIConstants.PREF_CVS_RSH_PARAMETERS, CVSProviderPlugin.DEFAULT_CVS_RSH_PARAMETERS);
525         store.setDefault(ICVSUIConstants.PREF_CVS_SERVER, CVSProviderPlugin.DEFAULT_CVS_SERVER);
526         store.setDefault(ICVSUIConstants.PREF_EXT_CONNECTION_METHOD_PROXY, "ext"); //$NON-NLS-1$
527
store.setDefault(ICVSUIConstants.PREF_PROMPT_ON_CHANGE_GRANULARITY, true);
528         store.setDefault(ICVSUIConstants.PREF_DETERMINE_SERVER_VERSION, true);
529         store.setDefault(ICVSUIConstants.PREF_CONFIRM_MOVE_TAG, CVSProviderPlugin.DEFAULT_CONFIRM_MOVE_TAG);
530         store.setDefault(ICVSUIConstants.PREF_DEBUG_PROTOCOL, false);
531         store.setDefault(ICVSUIConstants.PREF_WARN_REMEMBERING_MERGES, true);
532         store.setDefault(ICVSUIConstants.PREF_SHOW_COMPARE_REVISION_IN_DIALOG, false);
533         store.setDefault(ICVSUIConstants.PREF_COMMIT_SET_DEFAULT_ENABLEMENT, false);
534         store.setDefault(ICVSUIConstants.PREF_AUTO_REFRESH_TAGS_IN_TAG_SELECTION_DIALOG, false);
535         store.setDefault(ICVSUIConstants.PREF_AUTO_SHARE_ON_IMPORT, true);
536         store.setDefault(ICVSUIConstants.PREF_ENABLE_WATCH_ON_EDIT, false);
537         store.setDefault(ICVSUIConstants.PREF_USE_PROJECT_NAME_ON_CHECKOUT, false);
538         store.setDefault(ICVSUIConstants.PREF_COMMIT_FILES_DISPLAY_THRESHOLD, 1000);
539         store.setDefault(ICVSUIConstants.PREF_COMMIT_COMMENTS_MAX_HISTORY, RepositoryManager.DEFAULT_MAX_COMMENTS);
540         
541         PreferenceConverter.setDefault(store, ICVSUIConstants.PREF_CONSOLE_COMMAND_COLOR, new RGB(0, 0, 0));
542         PreferenceConverter.setDefault(store, ICVSUIConstants.PREF_CONSOLE_MESSAGE_COLOR, new RGB(0, 0, 255));
543         PreferenceConverter.setDefault(store, ICVSUIConstants.PREF_CONSOLE_ERROR_COLOR, new RGB(255, 0, 0));
544         store.setDefault(ICVSUIConstants.PREF_CONSOLE_SHOW_ON_MESSAGE, false);
545         store.setDefault(ICVSUIConstants.PREF_CONSOLE_LIMIT_OUTPUT, true);
546         store.setDefault(ICVSUIConstants.PREF_CONSOLE_HIGH_WATER_MARK, 500000);
547         store.setDefault(ICVSUIConstants.PREF_CONSOLE_WRAP, false);
548         store.setDefault(ICVSUIConstants.PREF_CONSOLE_WIDTH, 80);
549             
550         store.setDefault(ICVSUIConstants.PREF_FILETEXT_DECORATION, CVSDecoratorConfiguration.DEFAULT_FILETEXTFORMAT);
551         store.setDefault(ICVSUIConstants.PREF_FOLDERTEXT_DECORATION, CVSDecoratorConfiguration.DEFAULT_FOLDERTEXTFORMAT);
552         store.setDefault(ICVSUIConstants.PREF_PROJECTTEXT_DECORATION, CVSDecoratorConfiguration.DEFAULT_PROJECTTEXTFORMAT);
553         
554         store.setDefault(ICVSUIConstants.PREF_FIRST_STARTUP, true);
555         store.setDefault(ICVSUIConstants.PREF_ADDED_FLAG, CVSDecoratorConfiguration.DEFAULT_ADDED_FLAG);
556         store.setDefault(ICVSUIConstants.PREF_DIRTY_FLAG, CVSDecoratorConfiguration.DEFAULT_DIRTY_FLAG);
557         store.setDefault(ICVSUIConstants.PREF_SHOW_ADDED_DECORATION, true);
558         store.setDefault(ICVSUIConstants.PREF_SHOW_HASREMOTE_DECORATION, true);
559         store.setDefault(ICVSUIConstants.PREF_SHOW_DIRTY_DECORATION, false);
560         store.setDefault(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION, true);
561         store.setDefault(ICVSUIConstants.PREF_CALCULATE_DIRTY, true);
562         store.setDefault(ICVSUIConstants.PREF_USE_FONT_DECORATORS, false);
563         store.setDefault(ICVSUIConstants.PREF_PROMPT_ON_MIXED_TAGS, true);
564         store.setDefault(ICVSUIConstants.PREF_PROMPT_ON_SAVING_IN_SYNC, true);
565         store.setDefault(ICVSUIConstants.PREF_SAVE_DIRTY_EDITORS, ICVSUIConstants.OPTION_PROMPT);
566         
567         store.setDefault(ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS, CVSPerspective.ID);
568         store.setDefault(ICVSUIConstants.PREF_CHANGE_PERSPECTIVE_ON_SHOW_ANNOTATIONS, MessageDialogWithToggle.PROMPT);
569         store.setDefault(ICVSUIConstants.PREF_USE_QUICKDIFFANNOTATE, MessageDialogWithToggle.ALWAYS);
570         store.setDefault(ICVSUIConstants.PREF_ANNOTATE_PROMPTFORBINARY, MessageDialogWithToggle.PROMPT);
571         store.setDefault(ICVSUIConstants.PREF_ALLOW_EMPTY_COMMIT_COMMENTS, MessageDialogWithToggle.PROMPT);
572         store.setDefault(ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT, MessageDialogWithToggle.NEVER);
573         store.setDefault(ICVSUIConstants.PREF_ALLOW_COMMIT_WITH_WARNINGS, MessageDialogWithToggle.ALWAYS);
574         store.setDefault(ICVSUIConstants.PREF_ALLOW_COMMIT_WITH_ERRORS, MessageDialogWithToggle.PROMPT);
575         
576         store.setDefault(ICVSUIConstants.PREF_UPDATE_HANDLING, ICVSUIConstants.PREF_UPDATE_HANDLING_TRADITIONAL);
577         store.setDefault(ICVSUIConstants.PREF_UPDATE_PREVIEW, ICVSUIConstants.PREF_UPDATE_PREVIEW_IN_SYNCVIEW);
578         
579         store.setDefault(ICVSUIConstants.PREF_ENABLE_MODEL_SYNC, true);
580         store.setDefault(ICVSUIConstants.PREF_OPEN_COMPARE_EDITOR_FOR_SINGLE_FILE, true);
581         
582         // Set the watch/edit preferences defaults and values
583
store.setDefault(ICVSUIConstants.PREF_CHECKOUT_READ_ONLY, corePrefs.getDefaultBoolean(CVSProviderPlugin.READ_ONLY));
584         store.setDefault(ICVSUIConstants.PREF_EDIT_ACTION, ICVSUIConstants.PREF_EDIT_IN_BACKGROUND);
585         store.setDefault(ICVSUIConstants.PREF_EDIT_PROMPT, ICVSUIConstants.PREF_EDIT_PROMPT_IF_EDITORS);
586         store.setDefault(ICVSUIConstants.PREF_UPDATE_PROMPT, ICVSUIConstants.PREF_UPDATE_PROMPT_NEVER);
587         // Ensure that the preference values in UI match Core
588
store.setValue(ICVSUIConstants.PREF_CHECKOUT_READ_ONLY, corePrefs.getBoolean(CVSProviderPlugin.READ_ONLY));
589         
590         // Forward the values to the CVS plugin
591
CVSProviderPlugin.getPlugin().setPruneEmptyDirectories(store.getBoolean(ICVSUIConstants.PREF_PRUNE_EMPTY_DIRECTORIES));
592         CVSProviderPlugin.getPlugin().setTimeout(store.getInt(ICVSUIConstants.PREF_TIMEOUT));
593         CVSProviderPlugin.getPlugin().setCvsRshCommand(store.getString(ICVSUIConstants.PREF_CVS_RSH));
594         CVSProviderPlugin.getPlugin().setCvsRshParameters(store.getString(ICVSUIConstants.PREF_CVS_RSH_PARAMETERS));
595         CVSProviderPlugin.getPlugin().setCvsServer(store.getString(ICVSUIConstants.PREF_CVS_SERVER));
596         CVSRepositoryLocation.setExtConnectionMethodProxy(store.getString(ICVSUIConstants.PREF_EXT_CONNECTION_METHOD_PROXY));
597         CVSProviderPlugin.getPlugin().setQuietness(CVSPreferencesPage.getQuietnessOptionFor(store.getInt(ICVSUIConstants.PREF_QUIETNESS)));
598         CVSProviderPlugin.getPlugin().setCompressionLevel(store.getInt(ICVSUIConstants.PREF_COMPRESSION_LEVEL));
599         CVSProviderPlugin.getPlugin().setReplaceUnmanaged(store.getBoolean(ICVSUIConstants.PREF_REPLACE_UNMANAGED));
600         CVSProviderPlugin.getPlugin().setDefaultTextKSubstOption(KSubstOption.fromMode(store.getString(ICVSUIConstants.PREF_TEXT_KSUBST)));
601         CVSProviderPlugin.getPlugin().setUsePlatformLineend(store.getBoolean(ICVSUIConstants.PREF_USE_PLATFORM_LINEEND));
602         CVSProviderPlugin.getPlugin().setRepositoriesAreBinary(store.getBoolean(ICVSUIConstants.PREF_REPOSITORIES_ARE_BINARY));
603         CVSProviderPlugin.getPlugin().setDetermineVersionEnabled(store.getBoolean(ICVSUIConstants.PREF_DETERMINE_SERVER_VERSION));
604         CVSProviderPlugin.getPlugin().setDebugProtocol(CVSProviderPlugin.getPlugin().isDebugProtocol() || store.getBoolean(ICVSUIConstants.PREF_DEBUG_PROTOCOL));
605         CVSProviderPlugin.getPlugin().setAutoshareOnImport(store.getBoolean(ICVSUIConstants.PREF_AUTO_SHARE_ON_IMPORT));
606         
607         // code to transfer CVS preference to Team preference
608
if (store.getBoolean(ICVSUIConstants.PREF_SHOW_AUTHOR_IN_EDITOR)) {
609             store.setValue(ICVSUIConstants.PREF_SHOW_AUTHOR_IN_EDITOR, false);
610             IPreferenceStore teamStore = TeamUIPlugin.getPlugin().getPreferenceStore();
611             if (teamStore.isDefault(IPreferenceIds.SHOW_AUTHOR_IN_COMPARE_EDITOR))
612                 teamStore.setValue(IPreferenceIds.SHOW_AUTHOR_IN_COMPARE_EDITOR, true);
613         }
614     }
615     
616     /**
617      * @see Plugin#start(BundleContext)
618      */

619     public void start(BundleContext context) throws Exception JavaDoc {
620         super.start(context);
621         
622         initializeImages();
623         
624         CVSAdapterFactory factory = new CVSAdapterFactory();
625         Platform.getAdapterManager().registerAdapters(factory, ICVSRemoteFile.class);
626         Platform.getAdapterManager().registerAdapters(factory, ICVSRemoteFolder.class);
627         Platform.getAdapterManager().registerAdapters(factory, ICVSRepositoryLocation.class);
628         Platform.getAdapterManager().registerAdapters(factory, RepositoryRoot.class);
629         
630         try {
631             console = new CVSOutputConsole();
632         } catch (RuntimeException JavaDoc e) {
633             // Don't let the console bring down the CVS UI
634
log(IStatus.ERROR, "Errors occurred starting the CVS console", e); //$NON-NLS-1$
635
}
636         
637         IPreferenceStore store = getPreferenceStore();
638         if (store.getBoolean(ICVSUIConstants.PREF_FIRST_STARTUP)) {
639             // If we enable the decorator in the XML, the CVS plugin will be loaded
640
// on startup even if the user never uses CVS. Therefore, we enable the
641
// decorator on the first start of the CVS plugin since this indicates that
642
// the user has done something with CVS. Subsequent startups will load
643
// the CVS plugin unless the user disables the decorator. In this case,
644
// we will not re-enable since we only enable automatically on the first startup.
645
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(CVSLightweightDecorator.ID, true);
646             store.setValue(ICVSUIConstants.PREF_FIRST_STARTUP, false);
647         }
648
649     }
650     
651     /**
652      * @see Plugin#stop(BundleContext)
653      */

654     public void stop(BundleContext context) throws Exception JavaDoc {
655         try {
656             try {
657                 if (repositoryManager != null)
658                     repositoryManager.shutdown();
659             } catch (TeamException e) {
660                 throw new CoreException(e.getStatus());
661             }
662             
663             if (console != null)
664                 console.shutdown();
665         } finally {
666             super.stop(context);
667         }
668     }
669     
670     /**
671      * @return the CVS console
672      */

673     public CVSOutputConsole getConsole() {
674         return console;
675     }
676     
677     public IEditorPart openEditor(ICVSRemoteFile file, IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
678         IWorkbench workbench = getWorkbench();
679         IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
680         try {
681             return Utils.openEditor(page, (IFileRevision)file.getAdapter(IFileRevision.class), monitor);
682         } catch (CoreException e) {
683             throw new InvocationTargetException JavaDoc(e);
684         }
685     }
686
687     /**
688      * Helper method which access the preference store to determine if the
689      * project name from the project description file (.project) should be used
690      * as the project name on checkout.
691      */

692     public boolean isUseProjectNameOnCheckout() {
693         return getPreferenceStore().getBoolean(ICVSUIConstants.PREF_USE_PROJECT_NAME_ON_CHECKOUT);
694     }
695
696     public ActiveChangeSetManager getChangeSetManager() {
697         return CVSProviderPlugin.getPlugin().getChangeSetManager();
698     }
699 }
700
Popular Tags