### Eclipse Workspace Patch 1.0 #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 1 Mar 2009 11:56:59 -0000 @@ -348,5 +348,12 @@ class="org.eclipse.compare.internal.ComparePreferenceInitializer"> + + + + Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/META-INF/MANIFEST.MF,v retrieving revision 1.24 diff -u -r1.24 MANIFEST.MF --- META-INF/MANIFEST.MF 23 Feb 2009 16:50:02 -0000 1.24 +++ META-INF/MANIFEST.MF 1 Mar 2009 11:56:59 -0000 @@ -23,7 +23,8 @@ org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui.editors;bundle-version="[3.3.0,4.0.0)", org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)", - org.eclipse.compare.core;bundle-version="[3.5.0,4.0.0)";visibility:=reexport + org.eclipse.compare.core;bundle-version="[3.5.0,4.0.0)";visibility:=reexport, + org.eclipse.core.filesystem;bundle-version="1.2.0" Bundle-ActivationPolicy: lazy Import-Package: com.ibm.icu.util, com.ibm.icu.text 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,55 @@ +/******************************************************************************* + * 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 java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.editors.text.TextFileDocumentProvider; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.OutOfSyncHandler; + +public class CompareOutOfSyncHandler extends OutOfSyncHandler { + + public boolean handle(IDocumentProvider documentProvider, IEditorInput editorInput, IProgressMonitor monitor) { + + //TODO Actual implementation + + TextFileDocumentProvider provider = (TextFileDocumentProvider) documentProvider; + StringBuilder sb = new StringBuilder(); + try { + InputStream is = provider.getFileStore(editorInput).openInputStream(EFS.NONE, monitor); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + String line; + while ((line = reader.readLine()) != null) + sb.append(line + '\n'); + } catch (Exception e1) { + e1.printStackTrace(); + } + + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + MessageDialog.openInformation(shell, "Editor version", documentProvider.getDocument(editorInput).get()); //$NON-NLS-1$ + MessageDialog.openInformation(shell, "File system version", sb.toString()); //$NON-NLS-1$ + MessageDialog.openInformation(shell, "Compare", "Compare plug-in handled file saving."); //$NON-NLS-1$ //$NON-NLS-2$ + return true; + + } + +} #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 1 Mar 2009 11:57:04 -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; @@ -107,6 +109,7 @@ 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; @@ -4943,12 +4946,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(p, getEditorInput(), progressMonitor); + } else /* * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits * Set progress monitor to canceled in order to report back @@ -4956,7 +4958,7 @@ */ if (progressMonitor != null) progressMonitor.setCanceled(true); - } + } else { String title= EditorMessages.Editor_error_save_title; String msg= EditorMessages.Editor_error_save_message; @@ -4974,6 +4976,27 @@ -- fErrorCorrectionOnSave; } } + + /** + * Presents a dialog for asking what to do on out-of-sync saving errors. + * @param handlers the available handlers + * @return the selected handler or null otherwise + */ + protected OutOfSyncHandler selectOutOfSycHandler(OutOfSyncHandler[] handlers) { + OutOfSyncHandler defaultHandler = new OutOfSyncHandler(){ + public String getAnswer() { + return EditorMessages.Editor_error_save_outofsync_overwrite; + } + public boolean handle(IDocumentProvider documentProvider, IEditorInput editorInput, IProgressMonitor progressMonitor) { + performSave(true, progressMonitor); + return true; + } + }; + OutOfSyncHandlerSelectionDialog dialog = new OutOfSyncHandlerSelectionDialog(getSite().getShell(), handlers, defaultHandler, getEditorInput().getToolTipText()); + if (dialog.open() == Window.OK) + return dialog.getSelected(); + 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 1 Mar 2009 11:57:05 -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. \nWhat 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? @@ -118,3 +120,5 @@ Editor_MoveLines_IllegalMove_status= Move not possible - Uncheck "Show Source of Selected Element Only" to see the entire document Editor_error_clipboard_copy_failed_message= Copy to clipboard failed. +OutOfSyncHandlerSelectionDialog_cancel=Cancel +OutOfSyncHandlerSelectionDialog_ok=Ok 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 1 Mar 2009 11:57:05 -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; @@ -119,6 +121,9 @@ public static String Editor_MoveLines_IllegalMove_status; public static String Editor_error_clipboard_copy_failed_message; + public static String OutOfSyncHandlerSelectionDialog_cancel; + public static String OutOfSyncHandlerSelectionDialog_ok; + static { NLS.initializeMessages(BUNDLE_NAME, EditorMessages.class); } 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 1 Mar 2009 11:57:00 -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,79 @@ +/******************************************************************************* + * 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; + +import org.eclipse.ui.IEditorInput; + +/** + * + * 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 documentProvider the document provider + * @param editorInput the editor input object + * @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(IDocumentProvider documentProvider, IEditorInput editorInput, IProgressMonitor monitor); + +} Index: src/org/eclipse/ui/texteditor/OutOfSyncHandlerSelectionDialog.java =================================================================== RCS file: src/org/eclipse/ui/texteditor/OutOfSyncHandlerSelectionDialog.java diff -N src/org/eclipse/ui/texteditor/OutOfSyncHandlerSelectionDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/texteditor/OutOfSyncHandlerSelectionDialog.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,97 @@ +/******************************************************************************* + * 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.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.jface.dialogs.MessageDialog; + +import org.eclipse.ui.internal.texteditor.NLSUtility; + +/** + * Presents a dialog asking the user to choose an action to be performed + * when an out-of-sync file saving occurs. Each option is related to + * a out-of-sync handler extension. + */ +public class OutOfSyncHandlerSelectionDialog extends MessageDialog { + + private OutOfSyncHandler[] handlers; + private OutOfSyncHandler defaultHandler; + private OutOfSyncHandler selectedHandler; + + /** + * Initializes the dialog. + * + * @param parentShell the parent shell + * @param handlers the available out-of-sync handlers + * @param defaultHandler an additional, non-registered default handler + * @param fileName The underlying file name + */ + public OutOfSyncHandlerSelectionDialog(Shell parentShell, OutOfSyncHandler[] handlers, OutOfSyncHandler defaultHandler, String fileName) { + + super(parentShell, EditorMessages.Editor_error_save_outofsync_title, + null, NLSUtility.format(EditorMessages.Editor_error_save_outofsync_message, fileName), WARNING, + new String[] { EditorMessages.OutOfSyncHandlerSelectionDialog_ok, + EditorMessages.OutOfSyncHandlerSelectionDialog_cancel }, 0); + this.handlers = handlers; + this.defaultHandler = defaultHandler; + } + + private void updateSelection(OutOfSyncHandler selected) { + this.selectedHandler = selected; + } + + private void createOption(Composite buttonArea, final OutOfSyncHandler handler) { + Button radioButton = new Button(buttonArea, SWT.RADIO); + radioButton.setText(handler.getAnswer()); + radioButton.addSelectionListener(new SelectionListener(){ + public void widgetSelected(SelectionEvent e) { + updateSelection(handler); + } + public void widgetDefaultSelected(SelectionEvent e) { + updateSelection(handler); + } + }); + } + + protected Control createCustomArea(Composite parent) { + Composite buttonArea = new Composite(parent, SWT.NULL); + buttonArea.setLayout(new GridLayout(1, true)); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalIndent = 38; + buttonArea.setLayoutData(data); + for (int i = 0; i < handlers.length; i++) + if (handlers[i] != null) + createOption(buttonArea, handlers[i]); + createOption(buttonArea, defaultHandler); + return parent; + } + + /** + * Gets the selected handler. Should normally be called after an open(). + * @return the selected handler + */ + public OutOfSyncHandler getSelected() { + return selectedHandler; + } + +} \ No newline at end of file #P org.eclipse.ui.editors Index: src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java,v retrieving revision 1.97 diff -u -r1.97 TextFileDocumentProvider.java --- src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java 11 Sep 2008 12:00:15 -0000 1.97 +++ src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java 1 Mar 2009 11:57:20 -0000 @@ -1277,9 +1277,14 @@ * @return the {@link IFileStore} for the given file info * @since 3.2 */ - protected IFileStore getFileStore(FileInfo info) { + protected IFileStore getFileStore(FileInfo info) { return info.fTextFileBuffer.getFileStore(); } + + public IFileStore getFileStore(Object element) { + FileInfo info= (FileInfo) fFileInfoMap.get(element); + return getFileStore(info); + } /** * Returns the system file denoted by the given info.