### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.workbench.texteditor Index: src/org/eclipse/ui/texteditor/AbstractTextEditor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java,v retrieving revision 1.302 diff -u -r1.302 AbstractTextEditor.java --- src/org/eclipse/ui/texteditor/AbstractTextEditor.java 19 Feb 2009 13:43:48 -0000 1.302 +++ src/org/eclipse/ui/texteditor/AbstractTextEditor.java 28 Feb 2009 23:50:03 -0000 @@ -13,6 +13,8 @@ * Benjamin Muskalla - https://bugs.eclipse.org/bugs/show_bug.cgi?id=41573 * Stephan Wahlbrink - Wrong operations mode/feedback for text drag over/drop in text editors - https://bugs.eclipse.org/bugs/show_bug.cgi?id=206043 * Tom Eicher (Avaloq Evolution AG) - block selection mode + * Renato Silva - out-of-sync extension point (http://bugs.eclipse.org/bugs/show_bug.cgi?id=261716) + * *******************************************************************************/ package org.eclipse.ui.texteditor; @@ -104,9 +106,11 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.window.IShellProvider; +import org.eclipse.jface.window.Window; import org.eclipse.jface.text.AbstractInformationControlManager; import org.eclipse.jface.text.BadLocationException; @@ -198,6 +202,7 @@ import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.CommandNotMappedException; import org.eclipse.ui.actions.ContributedAction; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.ui.dialogs.PropertyDialogAction; import org.eclipse.ui.dnd.IDragAndDropService; import org.eclipse.ui.internal.texteditor.EditPosition; @@ -4943,12 +4948,11 @@ } if (isNotSynchronizedException(exception) && fErrorCorrectionOnSave == 1 && !isSynchronized) { - String title= EditorMessages.Editor_error_save_outofsync_title; - String msg= NLSUtility.format(EditorMessages.Editor_error_save_outofsync_message, getEditorInput().getToolTipText()); - - if (MessageDialog.openQuestion(getSite().getShell(), title, msg)) - performSave(true, progressMonitor); - else { + + OutOfSyncHandler handler = selectOutOfSycHandler(OutOfSyncHandler.getContributors()); + if (handler != null) + handler.handle(progressMonitor); + else /* * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits * Set progress monitor to canceled in order to report back @@ -4956,7 +4960,7 @@ */ if (progressMonitor != null) progressMonitor.setCanceled(true); - } + } else { String title= EditorMessages.Editor_error_save_title; String msg= EditorMessages.Editor_error_save_message; @@ -4974,6 +4978,70 @@ -- fErrorCorrectionOnSave; } } + + /** + * Represents the out-of-sync handler option together with the associated handler. + */ + private class OutOfSyncHandlerOption { + + private OutOfSyncHandler handler; + + public OutOfSyncHandlerOption(OutOfSyncHandler handler) { + this.handler = handler; + } + + public OutOfSyncHandler getHandler() { + return handler; + } + + public String toString() { + return (handler != null)? handler.getAnswer() : null; + } + + } + + /** + * Presents a dialog for asking what to do on out-of-sync saving errors. + * @param handlers the available handlers + * @return the selected handler + */ + protected OutOfSyncHandler selectOutOfSycHandler(OutOfSyncHandler[] handlers) { + + OutOfSyncHandlerOption[] answers = new OutOfSyncHandlerOption[handlers.length + 1]; + + answers[handlers.length] = new OutOfSyncHandlerOption(new OutOfSyncHandler(){ + public String getAnswer() { + return EditorMessages.Editor_error_save_outofsync_overwrite; + } + public boolean handle(IProgressMonitor progressMonitor) { + performSave(true, progressMonitor); + return true; + } + }); + + for (int i= 0; i < handlers.length; i++) + answers[i] = new OutOfSyncHandlerOption(handlers[i]); + + // TODO Option icons and better font size + // Use another kind of dialog? For example, with radio buttons for each option + + ElementListSelectionDialog dialog = new ElementListSelectionDialog(getSite().getShell(), new LabelProvider()); + dialog.setElements(answers); + dialog.setHelpAvailable(false); + dialog.setAllowDuplicates(true); + dialog.setMultipleSelection(false); + dialog.setSize(60, 10); + dialog.setTitle(EditorMessages.Editor_error_save_outofsync_title); + dialog.setMessage(NLSUtility.format(EditorMessages.Editor_error_save_outofsync_message, getEditorInput().getToolTipText())); + dialog.setEmptySelectionMessage(EditorMessages.Editor_error_save_outofsync_no_action_selected); + + if (dialog.open() == Window.OK) { + Object[] answer = dialog.getResult(); + if (answer != null) + return ((OutOfSyncHandlerOption)answer[0]).getHandler(); + } + return null; + } /** * Presents an error dialog to the user when a problem Index: src/org/eclipse/ui/texteditor/EditorMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.properties,v retrieving revision 1.42 diff -u -r1.42 EditorMessages.properties --- src/org/eclipse/ui/texteditor/EditorMessages.properties 22 Oct 2007 13:19:48 -0000 1.42 +++ src/org/eclipse/ui/texteditor/EditorMessages.properties 28 Feb 2009 23:50:03 -0000 @@ -23,7 +23,9 @@ Editor_error_init= Editor could not be initialized. Editor_error_save_outofsync_title=Update conflict -Editor_error_save_outofsync_message=The file ''{0}'' has been changed on the file system. Do you want to overwrite the changes made on the file system? +Editor_error_save_outofsync_message=The file ''{0}'' has been changed on the file system. What do you want to do? +Editor_error_save_outofsync_no_action_selected=Please select an action. +Editor_error_save_outofsync_overwrite=Overwrite file system changes anyway Editor_error_activated_outofsync_title=File Changed Editor_error_activated_outofsync_message=The file has been changed on the file system. Do you want to replace the editor contents with these changes? Index: src/org/eclipse/ui/texteditor/EditorMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.java,v retrieving revision 1.8 diff -u -r1.8 EditorMessages.java --- src/org/eclipse/ui/texteditor/EditorMessages.java 26 Jan 2007 12:41:54 -0000 1.8 +++ src/org/eclipse/ui/texteditor/EditorMessages.java 28 Feb 2009 23:50:03 -0000 @@ -46,6 +46,8 @@ public static String Editor_error_init; public static String Editor_error_save_outofsync_title; public static String Editor_error_save_outofsync_message; + public static String Editor_error_save_outofsync_no_action_selected; + public static String Editor_error_save_outofsync_overwrite; public static String Editor_error_activated_outofsync_title; public static String Editor_error_activated_outofsync_message; public static String Editor_error_activated_deleted_save_title; Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/plugin.xml,v retrieving revision 1.96 diff -u -r1.96 plugin.xml --- plugin.xml 10 Feb 2009 08:48:36 -0000 1.96 +++ plugin.xml 28 Feb 2009 23:49:59 -0000 @@ -7,6 +7,7 @@ + Index: schema/outOfSyncHandler.exsd =================================================================== RCS file: schema/outOfSyncHandler.exsd diff -N schema/outOfSyncHandler.exsd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ schema/outOfSyncHandler.exsd 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,111 @@ + + + + + + + + + Allows contributors to handle out-of-sync file savings. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Users will be prompted for what to do, and each implementation will be listed as an available action, using this attribute as action description. + +For example, the value for a compare and merge handler could be "Compare and merge the versions". + + + + + + + + + + + + 3.5 + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + Index: src/org/eclipse/ui/texteditor/OutOfSyncHandler.java =================================================================== RCS file: src/org/eclipse/ui/texteditor/OutOfSyncHandler.java diff -N src/org/eclipse/ui/texteditor/OutOfSyncHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/texteditor/OutOfSyncHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Renato Silva - initial API and implementation + * (http://bugs.eclipse.org/bugs/show_bug.cgi?id=261716) + * + *******************************************************************************/ + +package org.eclipse.ui.texteditor; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Platform; + +/** + * + * A handler for file saving when editor content is out-of-sync with the file system. + */ +public abstract class OutOfSyncHandler { + + private static String EXTENSION_POINT_ID = "org.eclipse.ui.workbench.texteditor.outOfSyncHandler"; //$NON-NLS-1$ + private static String ANSWER_ATTRIBUTE = "answer"; //$NON-NLS-1$ + private static String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ + private String answer; + + public static OutOfSyncHandler[] getContributors() { + OutOfSyncHandler[] result; + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); + result = new OutOfSyncHandler[elements.length]; + for (int i= 0; i < elements.length; i++) { + IConfigurationElement element = elements[i]; + Object executable; + try { + executable= elements[i].createExecutableExtension(CLASS_ATTRIBUTE); + if (executable instanceof OutOfSyncHandler) { + OutOfSyncHandler handler = ((OutOfSyncHandler) executable); + handler.answer = element.getAttribute(ANSWER_ATTRIBUTE); + result[i] = handler; + } + } catch (CoreException e) { + // TODO Log failed contributor instantiation + } + } + return result; + } + + /** + * Users will be prompted for what to do on out-of-sync situations. + * This will return the matching answer for the underlying handler. + * @return the contributed answer + */ + public String getAnswer() { + return answer; + } + + /** + * Handles the file saving when editor content is out-of-sync with the file system. + * Must be implemented appropriately by contributors. + * @param monitor the progress monitor + * + * @return true for handle success, false for any error + */ + + //TODO Define parameters (need to include the current text and a + // file system reference to the underlying document + + public abstract boolean handle(IProgressMonitor monitor); + +} #P org.eclipse.compare Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml,v retrieving revision 1.69 diff -u -r1.69 plugin.xml --- plugin.xml 27 Feb 2009 12:44:07 -0000 1.69 +++ plugin.xml 28 Feb 2009 23:50:05 -0000 @@ -348,5 +348,12 @@ class="org.eclipse.compare.internal.ComparePreferenceInitializer"> + + + + Index: compare/org/eclipse/compare/CompareOutOfSyncHandler.java =================================================================== RCS file: compare/org/eclipse/compare/CompareOutOfSyncHandler.java diff -N compare/org/eclipse/compare/CompareOutOfSyncHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ compare/org/eclipse/compare/CompareOutOfSyncHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Renato Silva - initial prototype + * (http://bugs.eclipse.org/bugs/show_bug.cgi?id=261716) + *******************************************************************************/ + +package org.eclipse.compare; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.texteditor.OutOfSyncHandler; + +public class CompareOutOfSyncHandler extends OutOfSyncHandler { + + public boolean handle(IProgressMonitor monitor) { + + //TODO Actual implementation + + MessageDialog.openInformation( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + "Compare", //$NON-NLS-1$ + "Compare plug-in handled file saving."); //$NON-NLS-1$ + return true; + } + +}