Author: vyemialyanchyk
Date: 2009-05-05 10:12:32 -0400 (Tue, 05 May 2009)
New Revision: 15022
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:
https://jira.jboss.org/jira/browse/JBIDE-4228 bugfix
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 2009-05-05
14:00:39 UTC (rev 15021)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java 2009-05-05
14:12:32 UTC (rev 15022)
@@ -258,12 +258,15 @@
}
public static IResource getResource(ConsoleConfiguration consoleConfiguration,
IJavaProject proj, java.io.File configXMLFile, Object element) {
+ IResource resource = null;
+ if (consoleConfiguration == null) {
+ return resource;
+ }
Document doc = getDocument(consoleConfiguration, configXMLFile);
- IResource resource = null;
- if (consoleConfiguration != null && proj != null && doc != null) {
+ if (proj != null && doc != null) {
Element sfNode = doc.getRootElement().element( HIBERNATE_TAG_SESSION_FACTORY );
Iterator elements = sfNode.elements(HIBERNATE_TAG_MAPPING).iterator();
- while ( elements.hasNext() ) {
+ while (elements.hasNext() && resource == null) {
Element subelement = (Element) elements.next();
Attribute file = subelement.attribute( HIBERNATE_TAG_RESOURCE );
if (file != null) {
@@ -276,30 +279,40 @@
IPackageFragmentRoot packageFragmentRoot = packageFragmentRoots[i];
IPath path = packageFragmentRoot.getPath().append(file.getValue());
resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
-
- if (resource != null && resource.exists() &&
- elementInResource(consoleConfiguration, resource, element)) return resource;
+ if (resource != null) {
+ if (resource.exists() && elementInResource(consoleConfiguration,
resource, element)) {
+ break;
+ }
+ else {
+ resource = null;
+ }
+ }
}
}
+ } catch (JavaModelException e) {
resource = null;
- } catch (JavaModelException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenFileActionUtils_problems_while_get_project_package_fragment_roots,
e);
}
}
- }
-
- java.io.File[] files = consoleConfiguration.getPreferences().getMappingFiles();
- for (int i = 0; i < files.length; i++) {
- java.io.File file = files[i];
+ }
+ }
+ if (resource == null) {
+ java.io.File[] files = consoleConfiguration.getPreferences().getMappingFiles();
+ for (int i = 0; i < files.length; i++) {
+ java.io.File file = files[i];
if (file != null) {
resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(file.getPath()));
- if (resource != null &&
- OpenFileActionUtils.elementInResource(consoleConfiguration, resource, element))
return resource;
+ if (resource != null) {
+ if (resource.exists() && elementInResource(consoleConfiguration, resource,
element)) {
+ break;
+ }
+ else {
+ resource = null;
+ }
+ }
}
}
- }
- return null;
+ }
+ return resource;
}
-
-
}
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 2009-05-05
14:00:39 UTC (rev 15021)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java 2009-05-05
14:12:32 UTC (rev 15022)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.hibernate.eclipse.console.actions;
+import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
@@ -107,26 +108,24 @@
IEditorPart editorPart = null;
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
- if (configXMLFile != null) {
- IResource resource = null;
- if (selection instanceof Property) {
- Property p = (Property)selection;
- if (p.getPersistentClass() != null) {
- //use PersistentClass to open editor
- resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, p.getPersistentClass());
- //editorPart = openMapping(p.getPersistentClass(), consoleConfiguration);
- }
+ IResource resource = null;
+ if (selection instanceof Property) {
+ Property p = (Property)selection;
+ if (p.getPersistentClass() != null) {
+ //use PersistentClass to open editor
+ resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
p.getPersistentClass());
+ //editorPart = openMapping(p.getPersistentClass(), consoleConfiguration);
}
- else {
- resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
selection);
- //editorPart = openMapping(selection, consoleConfiguration);
+ }
+ else {
+ resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
selection);
+ //editorPart = openMapping(selection, consoleConfiguration);
+ }
+ if (resource != null) {
+ editorPart = openMapping(resource);
+ if (editorPart != null){
+ applySelectionToEditor(selection, editorPart);
}
- if (resource != null) {
- editorPart = openMapping(resource);
- if (editorPart != null){
- applySelectionToEditor(selection, editorPart);
- }
- }
}
if (editorPart == null) {
//try to find hibernate-annotations