Author: dazarov
Date: 2011-11-16 20:41:44 -0500 (Wed, 16 Nov 2011)
New Revision: 36400
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddQualifiersToBeanProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactoringProcessor.java
Log:
Quickfix and Wizard for fixing ambigious injection warning is confusing
https://issues.jboss.org/browse/JBIDE-9940
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddQualifiersToBeanProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddQualifiersToBeanProcessor.java 2011-11-17
00:49:48 UTC (rev 36399)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddQualifiersToBeanProcessor.java 2011-11-17
01:41:44 UTC (rev 36400)
@@ -22,17 +22,12 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
-import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.text.edits.UndoEdit;
import org.jboss.tools.cdi.core.CDICoreMessages;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IInjectionPoint;
@@ -108,8 +103,8 @@
ICompilationUnit compilationUnit = original.getWorkingCopy(pm);
- TextFileChange fileChange = new TextFileChange(file.getName(), file);
- if(isEditorOpened(file))
+ TextFileChange fileChange = new CDIFileChange(file.getName(), file);
+ if(getEditor(file) != null)
fileChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
else
fileChange.setSaveMode(TextFileChange.FORCE_SAVE);
@@ -128,8 +123,8 @@
fileChange.setEdit(edit);
rootChange.add(fileChange);
}
- fileChange = new TextFileChange(file2.getName(), file2);
- if(isEditorOpened(file2))
+ fileChange = new CDIFileChange(file2.getName(), file2);
+ if(getEditor(file2) != null)
fileChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
else
fileChange.setSaveMode(TextFileChange.FORCE_SAVE);
@@ -172,4 +167,5 @@
public void setDeployedQualifiers(ArrayList<ValuedQualifier> qualifiers){
this.qualifiers = qualifiers;
}
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactoringProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactoringProcessor.java 2011-11-17
00:49:48 UTC (rev 36399)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactoringProcessor.java 2011-11-17
01:41:44 UTC (rev 36400)
@@ -10,14 +10,20 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.refactoring;
+import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
@@ -30,6 +36,7 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.jboss.tools.cdi.core.CDICoreMessages;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
@@ -60,9 +67,9 @@
protected void createRootChange(){
rootChange = new CompositeChange(label);
- change = new TextFileChange(file.getName(), file);
+ change = new CDIFileChange(file.getName(), file);
- if(isEditorOpened(file))
+ if(getEditor(file) != null)
change.setSaveMode(TextFileChange.LEAVE_DIRTY);
else
change.setSaveMode(TextFileChange.FORCE_SAVE);
@@ -73,16 +80,16 @@
rootChange.markAsSynthetic();
}
- protected boolean isEditorOpened(IFile file){
+ protected IEditorPart getEditor(IFile file){
IEditorInput ii = EditorUtility.getEditorInput(file);
IWorkbenchWindow[] windows =
CDIUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
for(IWorkbenchWindow window : windows){
IEditorPart editor = window.getActivePage().findEditor(ii);
if(editor != null)
- return true;
+ return editor;
}
- return false;
+ return null;
}
private IClassBean findClassBean(){
@@ -166,5 +173,39 @@
SharableParticipants sharedParticipants) throws CoreException {
return EMPTY_REF_PARTICIPANT;
}
+
+ protected class CDIFileChange extends TextFileChange{
+ public CDIFileChange(String name, IFile file) {
+ super(name, file);
+ }
+
+ protected void releaseDocument(IDocument document, IProgressMonitor pm)
+ throws CoreException {
+ super.releaseDocument(document, pm);
+
+ final IEditorPart editor = getEditor(getFile());
+
+ IRunnableContext context = new ProgressMonitorDialog(editor.getSite().getShell());
+
+ IRunnableWithProgress resolutionsRunnable = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ IEditorPart editor = getEditor(getFile());
+ if(editor != null){
+ editor.doSave(new NullProgressMonitor());
+ }
+ }
+ };
+ try {
+ PlatformUI.getWorkbench().getProgressService().runInUI(context,
+ resolutionsRunnable, null);
+ } catch (InvocationTargetException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ } catch (InterruptedException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ }
+ }
+
+ }
+
}