Author: vyemialyanchyk
Date: 2009-03-23 13:28:12 -0400 (Mon, 23 Mar 2009)
New Revision: 14294
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/plugin.xml
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/collect/AllEntitiesInfoCollector.java
Log:
JBIDE-3999
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/plugin.xml 2009-03-23
15:31:42 UTC (rev 14293)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/plugin.xml 2009-03-23
17:28:12 UTC (rev 14294)
@@ -105,9 +105,27 @@
</action>
</viewerContribution>
<!-- java element context menu -->
- <objectContribution adaptable="false"
- id="org.hibernate.eclipse.jdt.ui.run_jpa.popupMenu.IJavaElementContribution"
+ <objectContribution adaptable="false"
+ id="org.hibernate.eclipse.jdt.ui.run_jpa.popupMenu.IJavaElementContribution"
objectClass="org.eclipse.jdt.core.IJavaElement">
+ <visibility>
+ <or>
+ <objectClass name="org.eclipse.jdt.core.ICompilationUnit"/>
+ <objectClass name="org.eclipse.jdt.internal.core.JavaProject"/>
+ <objectClass name="org.eclipse.jdt.internal.core.PackageFragment"/>
+ <and>
+ <objectClass name="org.eclipse.jdt.internal.core.JavaElement"/>
+ <not>
+ <or>
+ <objectClass
name="org.eclipse.jdt.internal.core.ExternalPackageFragmentRoot"/>
+ <objectClass
name="org.eclipse.jdt.internal.core.JarPackageFragmentRoot"/>
+ <objectClass name="org.eclipse.jdt.internal.core.ClassFile"/>
+ <objectClass
name="org.eclipse.jdt.internal.core.ExternalJavaProject"/>
+ </or>
+ </not>
+ </and>
+ </or>
+ </visibility>
<menu label="%Menu_Source" path="edit"
id="org.eclipse.jdt.ui.source.menu">
<separator name="commentGroup"/>
<separator name="editGroup"/>
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 2009-03-23
15:31:42 UTC (rev 14293)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java 2009-03-23
17:28:12 UTC (rev 14294)
@@ -31,6 +31,9 @@
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.internal.core.ClassFile;
+import org.eclipse.jdt.internal.core.ExternalPackageFragmentRoot;
+import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.JavaElementInfo;
import org.eclipse.jdt.internal.core.JavaProject;
@@ -45,8 +48,8 @@
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.jdt.ui.Activator;
import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
@@ -59,7 +62,7 @@
* Actor to execute annotation generation.
* It is singleton.
*
- * @author Vitali
+ * @author Vitali Yemialyanchyk
*/
public class JPAMapToolActor {
@@ -101,10 +104,17 @@
return actor;
}
+ /**
+ * Cleanup collection of selected elements for processing
+ */
public void clearSelectionCU() {
selectionCU.clear();
}
+ /**
+ * Adds compilation unit into collection of selected elements for processing
+ * @param cu compilation unit
+ */
public void addCompilationUnit(ICompilationUnit cu) {
if (cu != null) {
IType[] types = null;
@@ -176,14 +186,30 @@
processor.saveAnnotationStylePreference();
}
+ private IWorkbenchWindow getActiveWorkbenchWindow() {
+ return Activator.getDefault().getWorkbench().getActiveWorkbenchWindow();
+ }
+
private Shell getShell() {
- return Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
+ IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow != null) {
+ return activeWorkbenchWindow.getShell();
+ }
+ return null;
}
+ /**
+ * update compilation unit of currently opened editor
+ */
public void updateOpen() {
- IWorkbench workbench = Activator.getDefault().getWorkbench();
- IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
-
+ IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow == null) {
+ return;
+ }
+ IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
+ if (page == null) {
+ return;
+ }
IEditorPart editor = page.getActiveEditor();
if (editor instanceof CompilationUnitEditor) {
CompilationUnitEditor cue = (CompilationUnitEditor)editor;
@@ -209,6 +235,9 @@
collector.collect(cu);
}
+ /**
+ * @return probable number of available item to process
+ */
synchronized public int getSelectedSourceSize() {
int res = 0;
if (selection == null) {
@@ -221,10 +250,20 @@
else if (selection instanceof TreeSelection) {
TreeSelection treeSelection = (TreeSelection)selection;
res = treeSelection.size();
+ Iterator it = treeSelection.iterator();
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (excludeElement(obj)) {
+ res--;
+ }
+ }
}
return res;
}
+ /**
+ * @param sel - current selected workspace element for processing
+ */
synchronized private void updateSelectedItems(ISelection sel) {
//System.out.println("Blah! " + selection); //$NON-NLS-1$
if (sel instanceof TextSelection) {
@@ -296,7 +335,40 @@
sel = null;
}
}
+
+ /**
+ * Check is the object in set of excluded elements
+ * @param obj
+ * @return exclusion result
+ */
+ protected boolean excludeElement(Object obj) {
+ boolean res = false;
+ if (obj instanceof JarPackageFragmentRoot) {
+ res = true;
+ }
+ else if (obj instanceof ClassFile) {
+ res = true;
+ }
+ else if (obj instanceof PackageFragment) {
+ PackageFragment pf = (PackageFragment)obj;
+ try {
+ if (pf.getKind() == IPackageFragmentRoot.K_BINARY) {
+ res = true;
+ }
+ } catch (JavaModelException e) {
+ // ignore
+ }
+ }
+ else if (obj instanceof ExternalPackageFragmentRoot) {
+ res = true;
+ }
+ return res;
+ }
+ /**
+ * Process object - java element to collect all it's children CompilationUnits
+ * @param obj
+ */
protected void processJavaElements(Object obj) {
if (obj instanceof ICompilationUnit) {
ICompilationUnit cu = (ICompilationUnit)obj;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-03-23
15:31:42 UTC (rev 14293)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-03-23
17:28:12 UTC (rev 14294)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.hibernate.eclipse.jdt.ui.internal.jpa.collect;
-import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -31,7 +30,7 @@
/**
* Collect information about JPA entity and it's dependences.
*
- * @author Vitali
+ * @author Vitali Yemialyanchyk
*/
public class AllEntitiesInfoCollector {
Show replies by date