Author: dgeraskov
Date: 2007-12-19 08:52:51 -0500 (Wed, 19 Dec 2007)
New Revision: 5369
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1412
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java 2007-12-19
13:07:03 UTC (rev 5368)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java 2007-12-19
13:52:51 UTC (rev 5369)
@@ -53,7 +53,7 @@
}
- public static boolean rootClassHasAnnotations(ConsoleConfiguration consoleConfiguration,
java.io.File configXMLFile, RootClass rootClass) {
+ public static boolean rootClassHasAnnotations(ConsoleConfiguration consoleConfiguration,
java.io.File configXMLFile, PersistentClass rootClass) {
if (configXMLFile == null) return true;
Document doc = getDocument(consoleConfiguration, configXMLFile);
return getElements(doc, HIBERNATE_TAG_MAPPING, HIBERNATE_TAG_CLASS,
getPersistentClassName(rootClass)).hasNext();
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java 2007-12-19
13:07:03 UTC (rev 5368)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java 2007-12-19
13:52:51 UTC (rev 5369)
@@ -72,15 +72,42 @@
*/
public static void run(Object selection, ConsoleConfiguration consoleConfiguration) {
IEditorPart editorPart = null;
+ IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
+ java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
+ IResource resource = null;
if (selection instanceof Property){
Property p = (Property)selection;
if (p.getPersistentClass() == null) return;
//use PersistentClass to open editor
- editorPart = openMapping(p.getPersistentClass(), consoleConfiguration);
+ resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
p.getPersistentClass());
+ //editorPart = openMapping(p.getPersistentClass(), consoleConfiguration);
} else {
- editorPart = openMapping(selection, consoleConfiguration);
+ resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
selection);
+ //editorPart = openMapping(selection, consoleConfiguration);
}
- applySelectionToEditor(selection, editorPart);
+ if (resource != null){
+ editorPart = openMapping(resource);
+ if (editorPart != null){
+ applySelectionToEditor(selection, editorPart);
+ }
+ return;
+ }
+
+ //try to find hibernate-annotations
+ PersistentClass rootClass = null;
+ if (selection instanceof PersistentClass) {
+ rootClass = (PersistentClass)selection;
+ } else if (selection instanceof Property) {
+ Property p = (Property)selection;
+ if (p.getPersistentClass() == null) return;
+ rootClass = (PersistentClass)p.getPersistentClass();
+ }
+ if (rootClass != null){
+ if (OpenFileActionUtils.rootClassHasAnnotations(consoleConfiguration, configXMLFile,
rootClass)) {
+ String fullyQualifiedName = OpenFileActionUtils.getPersistentClassName(rootClass);
+ new OpenSourceAction().run(selection, proj, fullyQualifiedName);
+ }
+ }
}
/**
@@ -90,7 +117,11 @@
*/
public static void run(Property compositeProperty, Property parentProperty,
ConsoleConfiguration consoleConfiguration) {
if (parentProperty.getPersistentClass() == null) return;
- IEditorPart editorPart = openMapping(parentProperty.getPersistentClass(),
consoleConfiguration);
+ IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
+ java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
+ IResource resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, parentProperty.getPersistentClass());
+
+ IEditorPart editorPart = openMapping(resource);
ITextEditor textEditor = getTextEditor(editorPart);
if (textEditor == null) return;
textEditor.selectAndReveal(0, 0);
@@ -112,7 +143,6 @@
* @param editorPart
*/
static public void applySelectionToEditor(Object selection, IEditorPart editorPart) {
- Assert.isNotNull(editorPart);
ITextEditor textEditor = getTextEditor(editorPart);
if (textEditor == null) return;
textEditor.selectAndReveal(0, 0);
@@ -141,8 +171,21 @@
FindReplaceDocumentAdapter findAdapter = new FindReplaceDocumentAdapter(document);
return findAdapter;
}
+
+ static public IEditorPart openMapping(IResource resource) {
+ if (resource != null && resource instanceof IFile){
+ try {
+ return
OpenFileActionUtils.openEditor(HibernateConsolePlugin.getDefault().getActiveWorkbenchWindow().getActivePage(),
(IFile) resource);
+ } catch (PartInitException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't open
mapping or source file.", e);
+ }
+ } else {
+ HibernateConsolePlugin.getDefault().log("Can't open mapping file "
+ resource);
+ }
+ return null;
+ }
- static public IEditorPart openMapping(Object selElement,
+ /*static public IEditorPart openMapping(Object selElement,
ConsoleConfiguration consoleConfiguration) {
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
@@ -158,7 +201,7 @@
HibernateConsolePlugin.getDefault().log("Can't open mapping file for
" + selElement);
}
return null;
- }
+ }*/
public static IRegion findSelection(Property property, FindReplaceDocumentAdapter
findAdapter) {
Assert.isNotNull(property.getPersistentClass());