View | Details | Raw Unified | Return to bug 261716 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/texteditor/AbstractTextEditor.java (-7 / +75 lines)
Lines 13-18 Link Here
13
 *     Benjamin Muskalla <b.muskalla@gmx.net> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=41573
13
 *     Benjamin Muskalla <b.muskalla@gmx.net> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=41573
14
 *     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
14
 *     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
15
 *     Tom Eicher (Avaloq Evolution AG) - block selection mode
15
 *     Tom Eicher (Avaloq Evolution AG) - block selection mode
16
 *     Renato Silva - out-of-sync extension point (http://bugs.eclipse.org/bugs/show_bug.cgi?id=261716)
17
 *      
16
 *******************************************************************************/
18
 *******************************************************************************/
17
package org.eclipse.ui.texteditor;
19
package org.eclipse.ui.texteditor;
18
20
Lines 104-112 Link Here
104
import org.eclipse.jface.viewers.ISelection;
106
import org.eclipse.jface.viewers.ISelection;
105
import org.eclipse.jface.viewers.ISelectionChangedListener;
107
import org.eclipse.jface.viewers.ISelectionChangedListener;
106
import org.eclipse.jface.viewers.ISelectionProvider;
108
import org.eclipse.jface.viewers.ISelectionProvider;
109
import org.eclipse.jface.viewers.LabelProvider;
107
import org.eclipse.jface.viewers.SelectionChangedEvent;
110
import org.eclipse.jface.viewers.SelectionChangedEvent;
108
import org.eclipse.jface.viewers.StructuredSelection;
111
import org.eclipse.jface.viewers.StructuredSelection;
109
import org.eclipse.jface.window.IShellProvider;
112
import org.eclipse.jface.window.IShellProvider;
113
import org.eclipse.jface.window.Window;
110
114
111
import org.eclipse.jface.text.AbstractInformationControlManager;
115
import org.eclipse.jface.text.AbstractInformationControlManager;
112
import org.eclipse.jface.text.BadLocationException;
116
import org.eclipse.jface.text.BadLocationException;
Lines 198-203 Link Here
198
import org.eclipse.ui.actions.ActionFactory;
202
import org.eclipse.ui.actions.ActionFactory;
199
import org.eclipse.ui.actions.CommandNotMappedException;
203
import org.eclipse.ui.actions.CommandNotMappedException;
200
import org.eclipse.ui.actions.ContributedAction;
204
import org.eclipse.ui.actions.ContributedAction;
205
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
201
import org.eclipse.ui.dialogs.PropertyDialogAction;
206
import org.eclipse.ui.dialogs.PropertyDialogAction;
202
import org.eclipse.ui.dnd.IDragAndDropService;
207
import org.eclipse.ui.dnd.IDragAndDropService;
203
import org.eclipse.ui.internal.texteditor.EditPosition;
208
import org.eclipse.ui.internal.texteditor.EditPosition;
Lines 4943-4954 Link Here
4943
			}
4948
			}
4944
4949
4945
			if (isNotSynchronizedException(exception) && fErrorCorrectionOnSave == 1 && !isSynchronized) {
4950
			if (isNotSynchronizedException(exception) && fErrorCorrectionOnSave == 1 && !isSynchronized) {
4946
				String title= EditorMessages.Editor_error_save_outofsync_title;
4951
				
4947
				String msg= NLSUtility.format(EditorMessages.Editor_error_save_outofsync_message, getEditorInput().getToolTipText());
4952
				OutOfSyncHandler handler = selectOutOfSycHandler(OutOfSyncHandler.getContributors());
4948
4953
				if (handler != null) 
4949
				if (MessageDialog.openQuestion(getSite().getShell(), title, msg))
4954
					handler.handle(progressMonitor);
4950
					performSave(true, progressMonitor);
4955
				else 
4951
				else {
4952
					/*
4956
					/*
4953
					 * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits
4957
					 * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits
4954
					 * Set progress monitor to canceled in order to report back
4958
					 * Set progress monitor to canceled in order to report back
Lines 4956-4962 Link Here
4956
					 */
4960
					 */
4957
					if (progressMonitor != null)
4961
					if (progressMonitor != null)
4958
						progressMonitor.setCanceled(true);
4962
						progressMonitor.setCanceled(true);
4959
				}
4963
				
4960
			} else {
4964
			} else {
4961
				String title= EditorMessages.Editor_error_save_title;
4965
				String title= EditorMessages.Editor_error_save_title;
4962
				String msg= EditorMessages.Editor_error_save_message;
4966
				String msg= EditorMessages.Editor_error_save_message;
Lines 4974-4979 Link Here
4974
			-- fErrorCorrectionOnSave;
4978
			-- fErrorCorrectionOnSave;
4975
		}
4979
		}
4976
	}
4980
	}
4981
	
4982
	/**
4983
	 * Represents the out-of-sync handler option together with the associated handler. 
4984
	 */
4985
	private class OutOfSyncHandlerOption {
4986
		
4987
		private OutOfSyncHandler handler;
4988
		
4989
		public OutOfSyncHandlerOption(OutOfSyncHandler handler) {
4990
			this.handler = handler;
4991
		}
4992
		
4993
		public OutOfSyncHandler getHandler() {
4994
			return handler;
4995
		}
4996
4997
		public String toString() {
4998
			return (handler != null)? handler.getAnswer() : null;
4999
		}
5000
		
5001
	}
5002
	
5003
	/**
5004
	 * Presents a dialog for asking what to do on out-of-sync saving errors.
5005
	 * @param handlers the available handlers
5006
	 * @return the selected handler 
5007
	 */
5008
	protected OutOfSyncHandler selectOutOfSycHandler(OutOfSyncHandler[] handlers) {
5009
		
5010
		OutOfSyncHandlerOption[] answers = new OutOfSyncHandlerOption[handlers.length + 1];
5011
		
5012
		answers[handlers.length] = new OutOfSyncHandlerOption(new OutOfSyncHandler(){			
5013
			public String getAnswer() {
5014
				return EditorMessages.Editor_error_save_outofsync_overwrite;
5015
			}			
5016
			public boolean handle(IProgressMonitor progressMonitor) {
5017
				performSave(true, progressMonitor); 
5018
				return true;
5019
			}			
5020
		});
5021
		
5022
		for (int i= 0; i < handlers.length; i++) 
5023
			answers[i] = new OutOfSyncHandlerOption(handlers[i]);
5024
		
5025
		// TODO Option icons and better font size
5026
		// Use another kind of dialog? For example, with radio buttons for each option 
5027
		
5028
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(getSite().getShell(), new LabelProvider());
5029
		dialog.setElements(answers);
5030
		dialog.setHelpAvailable(false);
5031
		dialog.setAllowDuplicates(true);
5032
		dialog.setMultipleSelection(false);
5033
		dialog.setSize(60, 10);
5034
		dialog.setTitle(EditorMessages.Editor_error_save_outofsync_title);
5035
		dialog.setMessage(NLSUtility.format(EditorMessages.Editor_error_save_outofsync_message, getEditorInput().getToolTipText()));
5036
		dialog.setEmptySelectionMessage(EditorMessages.Editor_error_save_outofsync_no_action_selected);
5037
		
5038
		if (dialog.open() == Window.OK) {
5039
			Object[] answer = dialog.getResult();
5040
			if (answer != null) 
5041
				return ((OutOfSyncHandlerOption)answer[0]).getHandler();
5042
		}
5043
		return null;
5044
	}
4977
5045
4978
	/**
5046
	/**
4979
	 * Presents an error dialog to the user when a problem
5047
	 * Presents an error dialog to the user when a problem
(-)src/org/eclipse/ui/texteditor/EditorMessages.properties (-1 / +3 lines)
Lines 23-29 Link Here
23
Editor_error_init= Editor could not be initialized.
23
Editor_error_init= Editor could not be initialized.
24
24
25
Editor_error_save_outofsync_title=Update conflict
25
Editor_error_save_outofsync_title=Update conflict
26
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?
26
Editor_error_save_outofsync_message=The file ''{0}'' has been changed on the file system. What do you want to do?
27
Editor_error_save_outofsync_no_action_selected=Please select an action.
28
Editor_error_save_outofsync_overwrite=Overwrite file system changes anyway
27
29
28
Editor_error_activated_outofsync_title=File Changed
30
Editor_error_activated_outofsync_title=File Changed
29
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?
31
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?
(-)src/org/eclipse/ui/texteditor/EditorMessages.java (+2 lines)
Lines 46-51 Link Here
46
	public static String Editor_error_init;
46
	public static String Editor_error_init;
47
	public static String Editor_error_save_outofsync_title;
47
	public static String Editor_error_save_outofsync_title;
48
	public static String Editor_error_save_outofsync_message;
48
	public static String Editor_error_save_outofsync_message;
49
	public static String Editor_error_save_outofsync_no_action_selected;
50
	public static String Editor_error_save_outofsync_overwrite;
49
	public static String Editor_error_activated_outofsync_title;
51
	public static String Editor_error_activated_outofsync_title;
50
	public static String Editor_error_activated_outofsync_message;
52
	public static String Editor_error_activated_outofsync_message;
51
	public static String Editor_error_activated_deleted_save_title;
53
	public static String Editor_error_activated_deleted_save_title;
(-)plugin.xml (+1 lines)
Lines 7-12 Link Here
7
    <extension-point id="rulerColumns" name="%ExtPoint.rulerColumns" schema="schema/rulerColumns.exsd"/>
7
    <extension-point id="rulerColumns" name="%ExtPoint.rulerColumns" schema="schema/rulerColumns.exsd"/>
8
    <extension-point id="hyperlinkDetectors" name="%ExtPoint.hyperlinkDetectors" schema="schema/hyperlinkDetectors.exsd"/>
8
    <extension-point id="hyperlinkDetectors" name="%ExtPoint.hyperlinkDetectors" schema="schema/hyperlinkDetectors.exsd"/>
9
    <extension-point id="hyperlinkDetectorTargets" name="%ExtPoint.hyperlinkDetectorTargets" schema="schema/hyperlinkDetectorTargets.exsd"/>
9
    <extension-point id="hyperlinkDetectorTargets" name="%ExtPoint.hyperlinkDetectorTargets" schema="schema/hyperlinkDetectorTargets.exsd"/>
10
    <extension-point id="outOfSyncHandler" name="Out Of Sync Handler" schema="schema/outOfSyncHandler.exsd"/>
10
11
11
	<extension
12
	<extension
12
	     point="org.eclipse.ui.commands">
13
	     point="org.eclipse.ui.commands">
(-)schema/outOfSyncHandler.exsd (+111 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ui.workbench.texteditor" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ui.workbench.texteditor" id="outOfSyncHandler" name="Out Of Sync Handler"/>
7
      </appInfo>
8
      <documentation>
9
         Allows contributors to handle out-of-sync file savings.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <choice>
21
            <element ref="handler"/>
22
         </choice>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="handler">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="java" basedOn="org.eclipse.ui.texteditor.OutOfSyncHandler:"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="answer" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  Users will be prompted for what to do, and each implementation will be listed as an available action, using this attribute as action description.
66
67
For example, the value for a compare and merge handler could be &quot;Compare and merge the versions&quot;.
68
               </documentation>
69
            </annotation>
70
         </attribute>
71
      </complexType>
72
   </element>
73
74
   <annotation>
75
      <appInfo>
76
         <meta.section type="since"/>
77
      </appInfo>
78
      <documentation>
79
         3.5
80
      </documentation>
81
   </annotation>
82
83
   <annotation>
84
      <appInfo>
85
         <meta.section type="examples"/>
86
      </appInfo>
87
      <documentation>
88
         [Enter extension point usage example here.]
89
      </documentation>
90
   </annotation>
91
92
   <annotation>
93
      <appInfo>
94
         <meta.section type="apiinfo"/>
95
      </appInfo>
96
      <documentation>
97
         [Enter API information here.]
98
      </documentation>
99
   </annotation>
100
101
   <annotation>
102
      <appInfo>
103
         <meta.section type="implementation"/>
104
      </appInfo>
105
      <documentation>
106
         [Enter information about supplied implementation of this extension point.]
107
      </documentation>
108
   </annotation>
109
110
111
</schema>
(-)src/org/eclipse/ui/texteditor/OutOfSyncHandler.java (+75 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 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
 *     Renato Silva - initial API and implementation 
10
 *                    (http://bugs.eclipse.org/bugs/show_bug.cgi?id=261716)
11
 *                    
12
 *******************************************************************************/
13
14
package org.eclipse.ui.texteditor;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.Platform;
20
21
/**
22
 * 
23
 * A handler for file saving when editor content is out-of-sync with the file system.
24
 */
25
public abstract class OutOfSyncHandler {
26
	
27
	private static String EXTENSION_POINT_ID = "org.eclipse.ui.workbench.texteditor.outOfSyncHandler"; //$NON-NLS-1$
28
	private static String ANSWER_ATTRIBUTE = "answer"; //$NON-NLS-1$
29
	private static String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$	
30
	private String answer;
31
	
32
	public static OutOfSyncHandler[] getContributors() {
33
		OutOfSyncHandler[] result;
34
		IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID);
35
		result = new OutOfSyncHandler[elements.length];
36
		for (int i= 0; i < elements.length; i++) {
37
			IConfigurationElement element = elements[i];
38
			Object executable;
39
			try {
40
				executable= elements[i].createExecutableExtension(CLASS_ATTRIBUTE);
41
				if (executable instanceof OutOfSyncHandler) {
42
					OutOfSyncHandler handler = ((OutOfSyncHandler) executable);
43
					handler.answer = element.getAttribute(ANSWER_ATTRIBUTE);
44
					result[i] = handler;
45
				}
46
			} catch (CoreException e) {
47
				// TODO Log failed contributor instantiation
48
			}
49
		}
50
		return result;
51
	}
52
53
	/** 
54
	 *  Users will be prompted for what to do on out-of-sync situations.
55
	 *  This will return the matching answer for the underlying handler.  
56
	 *  @return the contributed answer
57
	 */
58
	public String getAnswer() {
59
		return answer;
60
	}
61
62
	/**
63
	 * Handles the file saving when editor content is out-of-sync with the file system. 
64
	 * Must be implemented appropriately by contributors.
65
	 * @param monitor the progress monitor
66
	 * 
67
	 * @return true for handle success, false for any error
68
	 */
69
	
70
	//TODO Define parameters (need to include the current text and a 
71
	//     file system reference to the underlying document
72
	
73
	public abstract boolean handle(IProgressMonitor monitor); 	
74
75
}
(-)plugin.xml (+7 lines)
Lines 348-352 Link Here
348
            class="org.eclipse.compare.internal.ComparePreferenceInitializer">
348
            class="org.eclipse.compare.internal.ComparePreferenceInitializer">
349
      </initializer>
349
      </initializer>
350
   </extension>
350
   </extension>
351
   <extension
352
         point="org.eclipse.ui.workbench.texteditor.outOfSyncHandler">
353
      <handler
354
            answer="Compare file system and editor versions"
355
            class="org.eclipse.compare.CompareOutOfSyncHandler">
356
      </handler>
357
   </extension>
351
358
352
</plugin>
359
</plugin>
(-)compare/org/eclipse/compare/CompareOutOfSyncHandler.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 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
 *     Renato Silva - initial prototype  
10
 *                    (http://bugs.eclipse.org/bugs/show_bug.cgi?id=261716)
11
 *******************************************************************************/
12
13
package org.eclipse.compare;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.texteditor.OutOfSyncHandler;
19
20
public class CompareOutOfSyncHandler extends OutOfSyncHandler {
21
22
	public boolean handle(IProgressMonitor monitor) {
23
		
24
		//TODO Actual implementation
25
		
26
		MessageDialog.openInformation(
27
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
28
			"Compare", //$NON-NLS-1$
29
			"Compare plug-in handled file saving."); //$NON-NLS-1$
30
		return true;
31
	}
32
33
}

Return to bug 261716