Author: dazarov
Date: 2011-12-29 19:35:28 -0500 (Thu, 29 Dec 2011)
New Revision: 37582
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/JBDSFileChange.java
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
Log:
Java Seam and CDI quick fixes: after quick fix, editor is scrolled to the beginning. If
Undo/Redo commands are used, the entire file content gets selected
https://issues.jboss.org/browse/JBIDE-10536
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2011-12-29
23:00:25 UTC (rev 37581)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2011-12-30
00:35:28 UTC (rev 37582)
@@ -131,11 +131,11 @@
CompositeChange rootChange = (CompositeChange)processor.createChange(new
NullProgressMonitor());
- for(Change fileChange : rootChange.getChildren()){
- if(fileChange instanceof JBDSFileChange){
- ((JBDSFileChange)fileChange).setSaveMode(TextFileChange.FORCE_SAVE);
- }
- }
+// for(Change fileChange : rootChange.getChildren()){
+// if(fileChange instanceof JBDSFileChange){
+// ((JBDSFileChange)fileChange).setSaveMode(TextFileChange.FORCE_SAVE);
+// }
+// }
rootChange.perform(new NullProgressMonitor());
} else if(resolution instanceof TestableResolutionWithDialog){
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/JBDSFileChange.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/JBDSFileChange.java 2011-12-29
23:00:25 UTC (rev 37581)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/JBDSFileChange.java 2011-12-30
00:35:28 UTC (rev 37582)
@@ -13,7 +13,10 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.MultiStateTextFileChange;
@@ -22,6 +25,15 @@
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.text.edits.UndoEdit;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.UIJob;
+import org.jboss.tools.common.CommonPlugin;
public class JBDSFileChange extends MultiStateTextFileChange{
private IFile file;
@@ -30,9 +42,44 @@
public JBDSFileChange(IFile file) {
super(file.getName(), file);
this.file = file;
- setSaveMode(TextFileChange.LEAVE_DIRTY);
+
+ setSaveMode();
}
+ private void setSaveMode(){
+ UIJob job = new UIJob("setSaveMode"){ //$NON-NLS-1$
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ try {
+ if(isOpenInEditor(file)){
+ setSaveMode(TextFileChange.LEAVE_DIRTY);
+ }else{
+ setSaveMode(TextFileChange.FORCE_SAVE);
+ }
+ } catch (PartInitException e) {
+ CommonPlugin.getDefault().logError(e);
+ }
+ return Status.OK_STATUS;
+ }};
+
+ job.setSystem(true);
+ job.schedule();
+ }
+
+ private static boolean isOpenInEditor(IFile file) throws PartInitException{
+ IEditorInput input = EditorUtility.getEditorInput(file);
+ for(IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()){
+ for(IWorkbenchPage page : window.getPages()){
+ for(IEditorReference editorReference : page.getEditorReferences()){
+ IEditorPart editor = editorReference.getEditor(true);
+ if(editor != null && editor.getEditorInput().equals(input)){
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
public IFile getFile(){
return file;
}
Modified:
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java 2011-12-29
23:00:25 UTC (rev 37581)
+++
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractRefactorTest.java 2011-12-30
00:35:28 UTC (rev 37582)
@@ -152,7 +152,7 @@
if(fileChange instanceof JBDSFileChange){
edit = (MultiTextEdit)((JBDSFileChange)fileChange).getEdit();
file = ((JBDSFileChange)fileChange).getFile();
- ((JBDSFileChange)fileChange).setSaveMode(TextFileChange.FORCE_SAVE);
+ //((JBDSFileChange)fileChange).setSaveMode(TextFileChange.FORCE_SAVE);
}else if(fileChange instanceof TextFileChange){
edit = (MultiTextEdit)((TextFileChange)fileChange).getEdit();
file = ((TextFileChange)fileChange).getFile();