Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 127098 Details for
Bug 261716
[misc] Comparison for file changed on disk
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Partial implementation
eclipse.patch (text/plain), 20.79 KB, created by
Renato Silva
on 2009-02-28 21:42:54 EST
(
hide
)
Description:
Partial implementation
Filename:
MIME Type:
Creator:
Renato Silva
Created:
2009-02-28 21:42:54 EST
Size:
20.79 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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 02:42:23 -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. >#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 02:42:29 -0000 >@@ -13,6 +13,8 @@ > * Benjamin Muskalla <b.muskalla@gmx.net> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=41573 > * Stephan Wahlbrink <stephan.wahlbrink@walware.de> - 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(p, getEditorInput(), 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(IDocumentProvider documentProvider, IEditorInput editorInput, 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 1 Mar 2009 02:42:29 -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 1 Mar 2009 02:42:29 -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 1 Mar 2009 02:42:25 -0000 >@@ -7,6 +7,7 @@ > <extension-point id="rulerColumns" name="%ExtPoint.rulerColumns" schema="schema/rulerColumns.exsd"/> > <extension-point id="hyperlinkDetectors" name="%ExtPoint.hyperlinkDetectors" schema="schema/hyperlinkDetectors.exsd"/> > <extension-point id="hyperlinkDetectorTargets" name="%ExtPoint.hyperlinkDetectorTargets" schema="schema/hyperlinkDetectorTargets.exsd"/> >+ <extension-point id="outOfSyncHandler" name="Out Of Sync Handler" schema="schema/outOfSyncHandler.exsd"/> > > <extension > point="org.eclipse.ui.commands"> >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 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<!-- Schema file written by PDE --> >+<schema targetNamespace="org.eclipse.ui.workbench.texteditor" xmlns="http://www.w3.org/2001/XMLSchema"> >+<annotation> >+ <appInfo> >+ <meta.schema plugin="org.eclipse.ui.workbench.texteditor" id="outOfSyncHandler" name="Out Of Sync Handler"/> >+ </appInfo> >+ <documentation> >+ Allows contributors to handle out-of-sync file savings. >+ </documentation> >+ </annotation> >+ >+ <element name="extension"> >+ <annotation> >+ <appInfo> >+ <meta.element /> >+ </appInfo> >+ </annotation> >+ <complexType> >+ <choice> >+ <element ref="handler"/> >+ </choice> >+ <attribute name="point" type="string" use="required"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="id" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="name" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ <appInfo> >+ <meta.attribute translatable="true"/> >+ </appInfo> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="handler"> >+ <complexType> >+ <attribute name="class" type="string" use="required"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ <appInfo> >+ <meta.attribute kind="java" basedOn="org.eclipse.ui.texteditor.OutOfSyncHandler:"/> >+ </appInfo> >+ </annotation> >+ </attribute> >+ <attribute name="answer" type="string" use="required"> >+ <annotation> >+ <documentation> >+ 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". >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="since"/> >+ </appInfo> >+ <documentation> >+ 3.5 >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="examples"/> >+ </appInfo> >+ <documentation> >+ [Enter extension point usage example here.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="apiinfo"/> >+ </appInfo> >+ <documentation> >+ [Enter API information here.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="implementation"/> >+ </appInfo> >+ <documentation> >+ [Enter information about supplied implementation of this extension point.] >+ </documentation> >+ </annotation> >+ >+ >+</schema> >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,77 @@ >+/******************************************************************************* >+ * 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 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); >+ >+} >#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 02:42:31 -0000 >@@ -348,5 +348,12 @@ > class="org.eclipse.compare.internal.ComparePreferenceInitializer"> > </initializer> > </extension> >+ <extension >+ point="org.eclipse.ui.workbench.texteditor.outOfSyncHandler"> >+ <handler >+ answer="Compare file system and editor versions" >+ class="org.eclipse.compare.CompareOutOfSyncHandler"> >+ </handler> >+ </extension> > > </plugin> >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 02:42:31 -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; >+ >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 261716
:
127096
|
127098
|
127104
|
127105
|
127106