Author: vyemialyanchyk
Date: 2008-10-24 12:47:44 -0400 (Fri, 24 Oct 2008)
New Revision: 11172
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionPulldownDelegate.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/Utils.java
Log:
JBIDE-2987
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java 2008-10-24
16:46:09 UTC (rev 11171)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java 2008-10-24
16:47:44 UTC (rev 11172)
@@ -42,15 +42,15 @@
}
public void selectionChanged(IAction action, ISelection selection) {
- actor.updateSelectedItems(selection);
+ actor.setSelection(selection);
if (action != null) {
- action.setEnabled(actor.getSelectedSize() > 0);
+ action.setEnabled(actor.getSelectedSourceSize() > 0);
}
}
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
if (action != null) {
- action.setEnabled(actor.getSelectedSize() > 0);
+ action.setEnabled(actor.getSelectedSourceSize() > 0);
}
}
@@ -67,7 +67,7 @@
}
public boolean isEnabled() {
- return (actor.getSelectedSize() > 0);
+ return (actor.getSelectedSourceSize() > 0);
}
public boolean isHandled() {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionPulldownDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionPulldownDelegate.java 2008-10-24
16:46:09 UTC (rev 11171)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionPulldownDelegate.java 2008-10-24
16:47:44 UTC (rev 11172)
@@ -70,9 +70,9 @@
}
public void selectionChanged(IAction action, ISelection selection) {
- actor.updateSelectedItems(selection);
+ actor.setSelection(selection);
if (action != null) {
- action.setEnabled(actor.getSelectedSize() > 0);
+ action.setEnabled(actor.getSelectedSourceSize() > 0);
}
}
@@ -114,10 +114,10 @@
fillMenu(m);
fRecreateMenu = false;
}
- m.setEnabled(actor.getSelectedSize() > 0);
+ m.setEnabled(actor.getSelectedSourceSize() > 0);
MenuItem[] items = m.getItems();
for (int i = 0; i < items.length; i++) {
- items[i].setEnabled(actor.getSelectedSize() > 0);
+ items[i].setEnabled(actor.getSelectedSourceSize() > 0);
}
}
public void menuHidden(MenuEvent e) {
@@ -135,7 +135,7 @@
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
if (action != null) {
- action.setEnabled(actor.getSelectedSize() > 0);
+ action.setEnabled(actor.getSelectedSourceSize() > 0);
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java 2008-10-24
16:46:09 UTC (rev 11171)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java 2008-10-24
16:47:44 UTC (rev 11172)
@@ -46,6 +46,7 @@
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.jdt.ui.Activator;
import org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.Utils;
import org.hibernate.eclipse.jdt.ui.internal.jpa.process.AllEntitiesProcessor;
@@ -57,6 +58,7 @@
public class JPAMapToolActor {
protected static JPAMapToolActor actor = null;
+ protected ISelection selection = null;
protected Set<ICompilationUnit> selectionCU = new
HashSet<ICompilationUnit>();
protected AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
protected AllEntitiesProcessor processor = new AllEntitiesProcessor();
@@ -89,6 +91,14 @@
}
public void updateSelected() {
+ if (selection != null) {
+ updateSelectedItems(selection);
+ selection = null;
+ }
+ if (selectionCU.size() == 0) {
+ processor.modify(null, new HashMap<String, EntityInfo>(), true);
+ return;
+ }
Iterator<ICompilationUnit> it = selectionCU.iterator();
Map<IJavaProject, Set<ICompilationUnit>> mapJP_CUSet =
new HashMap<IJavaProject, Set<ICompilationUnit>>();
@@ -141,18 +151,29 @@
collector.collect(cu);
}
- public int getSelectedSize() {
- return selectionCU.size();
+ synchronized public int getSelectedSourceSize() {
+ int res = 0;
+ if (selection == null) {
+ res = selectionCU.size();
+ }
+ else if (selection instanceof TextSelection) {
+ res = 1;
+ }
+ else if (selection instanceof TreeSelection) {
+ TreeSelection treeSelection = (TreeSelection)selection;
+ res = treeSelection.size();
+ }
+ return res;
}
- synchronized public void updateSelectedItems(ISelection selection) {
+ private void updateSelectedItems(ISelection sel) {
//System.out.println("Blah! " + selection); //$NON-NLS-1$
- if (selection instanceof TextSelection) {
+ if (sel instanceof TextSelection) {
String fullyQualifiedName = ""; //$NON-NLS-1$
IDocument fDocument = null;
SynchronizableDocument sDocument = null;
org.eclipse.jdt.core.dom.CompilationUnit resultCU = null;
- Class clazz = selection.getClass();
+ Class clazz = sel.getClass();
Field fd = null;
try {
fd = clazz.getDeclaredField("fDocument"); //$NON-NLS-1$
@@ -162,7 +183,7 @@
if (fd != null) {
try {
fd.setAccessible(true);
- fDocument = (IDocument)fd.get(selection);
+ fDocument = (IDocument)fd.get(sel);
if (fDocument instanceof SynchronizableDocument) {
sDocument = (SynchronizableDocument)fDocument;
}
@@ -202,9 +223,9 @@
addCompilationUnit(cu);
}
}
- else if (selection instanceof TreeSelection) {
+ else if (sel instanceof TreeSelection) {
clearSelectionCU();
- TreeSelection treeSelection = (TreeSelection)selection;
+ TreeSelection treeSelection = (TreeSelection)sel;
Iterator it = treeSelection.iterator();
while (it.hasNext()) {
Object obj = it.next();
@@ -213,7 +234,7 @@
}
else {
//System.out.println("2 Blah! " + selection); //$NON-NLS-1$
- selection = null;
+ sel = null;
}
}
@@ -241,7 +262,8 @@
try {
pfr = javaProject.getAllPackageFragmentRoots();
} catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ",
e); //$NON-NLS-1$
+ // just ignore it!
+ //HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
if (pfr != null) {
for (int i = 0; i < pfr.length; i++) {
@@ -255,7 +277,8 @@
try {
cus = packageFragment.getCompilationUnits();
} catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ",
e); //$NON-NLS-1$
+ // just ignore it!
+ //HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
if (cus != null) {
for (int i = 0; i < cus.length; i++) {
@@ -270,7 +293,8 @@
try {
javaElementInfo = (JavaElementInfo)javaElement.getElementInfo();
} catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ",
e); //$NON-NLS-1$
+ // just ignore it!
+ //HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
if (javaElementInfo != null) {
IJavaElement[] je = javaElementInfo.getChildren();
@@ -289,4 +313,9 @@
//System.out.println("1 Blah! " + selection); //$NON-NLS-1$
}
}
+
+ synchronized public void setSelection(ISelection selection) {
+ this.selection = selection;
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/Utils.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/Utils.java 2008-10-24
16:46:09 UTC (rev 11171)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/Utils.java 2008-10-24
16:47:44 UTC (rev 11172)
@@ -48,7 +48,8 @@
try {
lwType = javaProject.findType(fullyQualifiedName);
} catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ",
e); //$NON-NLS-1$
+ // just ignore it!
+ //HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
ICompilationUnit resCompilationUnit = null;
if (lwType != null) {
@@ -80,21 +81,25 @@
try {
javaElement = javaProject.findElement(path.makeRelative());
} catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ",
e); //$NON-NLS-1$
+ // just ignore it!
+ //HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
ICompilationUnit[] res = null;
- if (javaElement instanceof ICompilationUnit) {
- res = new ICompilationUnit[]{ (ICompilationUnit)javaElement };
- }
- else if (javaElement instanceof IPackageFragment) {
- try {
- res = ((IPackageFragment)javaElement).getCompilationUnits();
- } catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ",
e); //$NON-NLS-1$
+ if (javaElement != null) {
+ if (javaElement instanceof ICompilationUnit) {
+ res = new ICompilationUnit[]{ (ICompilationUnit)javaElement };
}
+ else if (javaElement instanceof IPackageFragment) {
+ try {
+ res = ((IPackageFragment)javaElement).getCompilationUnits();
+ } catch (JavaModelException e) {
+ // just ignore it!
+ //HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
+ }
+ }
+ else if (javaElement instanceof IClassFile) {
+ }
}
- else if (javaElement instanceof IClassFile) {
- }
return res;
}