Author: vyemialyanchyk
Date: 2009-04-24 10:45:21 -0400 (Fri, 24 Apr 2009)
New Revision: 14902
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/OpenSourceAction.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
Log:
JBIDE-4221
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-04-24
13:47:00 UTC (rev 14901)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java 2009-04-24
14:45:21 UTC (rev 14902)
@@ -33,7 +33,6 @@
import org.eclipse.ui.actions.SelectionListenerAction;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
-import org.hibernate.EntityMode;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
@@ -81,7 +80,7 @@
}
}
- public static void run(TreePath path, ConsoleConfiguration consoleConfiguration) throws
PartInitException, JavaModelException, FileNotFoundException {
+ public static IEditorPart run(TreePath path, ConsoleConfiguration consoleConfiguration)
throws PartInitException, JavaModelException, FileNotFoundException {
boolean isPropertySel = (path.getLastSegment().getClass() == Property.class);
if (isPropertySel){
Property propertySel = (Property)path.getLastSegment();
@@ -90,11 +89,10 @@
|| (RootClass.class.isAssignableFrom(persClass.getClass())
&& persClass.getClass() != RootClass.class)){
Property parentProp = (Property)path.getParentPath().getLastSegment();
- run(propertySel, parentProp, consoleConfiguration);
- return;
+ return run(propertySel, parentProp, consoleConfiguration);
}
}
- run(path.getLastSegment(), consoleConfiguration);
+ return run(path.getLastSegment(), consoleConfiguration);
}
/**
@@ -109,46 +107,51 @@
IEditorPart editorPart = null;
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
- if (configXMLFile == null) return null;
- IResource resource = null;
- if (selection instanceof Property){
- Property p = (Property)selection;
- if (p.getPersistentClass() == null) return 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);
- }
- if (resource != null){
- editorPart = openMapping(resource);
- if (editorPart != null){
- applySelectionToEditor(selection, editorPart);
+ 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);
+ }
}
- return editorPart;
+ else {
+ resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
selection);
+ //editorPart = openMapping(selection, consoleConfiguration);
+ }
+ if (resource != null) {
+ editorPart = openMapping(resource);
+ if (editorPart != null){
+ applySelectionToEditor(selection, editorPart);
+ }
+ }
}
-
- //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 null;
- rootClass = (PersistentClass)p.getPersistentClass();
- }
- if (rootClass != null){
- if (OpenFileActionUtils.rootClassHasAnnotations(consoleConfiguration, configXMLFile,
rootClass)) {
- String fullyQualifiedName = rootClass.getClassName();
- editorPart = new OpenSourceAction().run(selection, proj, fullyQualifiedName);
- return editorPart;
+ if (editorPart == null) {
+ //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) {
+ rootClass = (PersistentClass)p.getPersistentClass();
+ }
+ }
+ if (rootClass != null){
+ if (OpenFileActionUtils.rootClassHasAnnotations(consoleConfiguration, configXMLFile,
rootClass)) {
+ String fullyQualifiedName = rootClass.getClassName();
+ editorPart = OpenSourceAction.run(selection, proj, fullyQualifiedName);
+ }
}
- } else {
- String out =
NLS.bind(HibernateConsoleMessages.OpenMappingAction_mapping_for_not_found, selection);
- throw new FileNotFoundException(out);
+ else {
+ String out =
NLS.bind(HibernateConsoleMessages.OpenMappingAction_mapping_for_not_found, selection);
+ throw new FileNotFoundException(out);
+ }
}
- return null;
+ return editorPart;
}
/**
@@ -218,7 +221,7 @@
PersistentClass rootClass = parentProperty.getPersistentClass();
if (OpenFileActionUtils.rootClassHasAnnotations(consoleConfiguration, configXMLFile,
rootClass)) {
String fullyQualifiedName =((Component)((Property)
parentProperty).getValue()).getComponentClassName();
- IEditorPart editor = new OpenSourceAction().run(compositeProperty, proj,
fullyQualifiedName);
+ IEditorPart editor = OpenSourceAction.run(compositeProperty, proj,
fullyQualifiedName);
return editor;
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceAction.java 2009-04-24
13:47:00 UTC (rev 14901)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceAction.java 2009-04-24
14:45:21 UTC (rev 14902)
@@ -92,7 +92,7 @@
* @throws PartInitException
* @throws FileNotFoundException
*/
- public IEditorPart run(Object selection, IJavaProject proj,
+ public static IEditorPart run(Object selection, IJavaProject proj,
String fullyQualifiedName) throws JavaModelException, PartInitException,
FileNotFoundException {
if (fullyQualifiedName == null) return null;
String remainder = null;
@@ -141,7 +141,7 @@
}
}
- private void selectionToEditor(IJavaElement jElement, JavaEditor jEditor) {
+ private static void selectionToEditor(IJavaElement jElement, JavaEditor jEditor) {
if (jEditor != null) {
jEditor.setSelection(jElement);
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java 2009-04-24
13:47:00 UTC (rev 14901)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java 2009-04-24
14:45:21 UTC (rev 14902)
@@ -38,6 +38,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.ActionGroup;
@@ -169,8 +170,9 @@
Object last = path.getLastSegment();
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
if (last instanceof PersistentClass || last.getClass() == Property.class){
+ IEditorPart res = null;
try {
- OpenMappingAction.run(path, consoleConfiguration);
+ res = OpenMappingAction.run(path, consoleConfiguration);
} catch (Exception e) {
HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping
file.", e); //$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java 2009-04-24
13:47:00 UTC (rev 14901)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java 2009-04-24
14:45:21 UTC (rev 14902)
@@ -10,11 +10,14 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.veditor.editors.actions;
+import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.gef.ui.actions.SelectionAction;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.mapping.Property;
@@ -56,8 +59,12 @@
Property parentProperty =
((SpecialRootClass)((Property)selection).getPersistentClass()).getProperty();
try {
org.hibernate.eclipse.console.actions.OpenMappingAction.run(compositSel,
parentProperty, consoleConfiguration);
- } catch (Exception e) {
+ } catch (PartInitException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(UIVEditorMessages.OpenMappingAction_canot_find_or_open_mapping_file,
e);
+ } catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage(UIVEditorMessages.OpenMappingAction_canot_find_or_open_mapping_file,
e);
+ } catch (FileNotFoundException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage(UIVEditorMessages.OpenMappingAction_canot_find_or_open_mapping_file,
e);
}
continue;
}
@@ -66,8 +73,12 @@
}
try {
org.hibernate.eclipse.console.actions.OpenMappingAction.run(selection,
consoleConfiguration);
- } catch (Exception e) {
+ } catch (PartInitException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(UIVEditorMessages.OpenMappingAction_open_mapping_file,
e);
+ } catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage(UIVEditorMessages.OpenMappingAction_open_mapping_file,
e);
+ } catch (FileNotFoundException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage(UIVEditorMessages.OpenMappingAction_open_mapping_file,
e);
}
/*IResource resource = null;
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2009-04-24
13:47:00 UTC (rev 14901)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2009-04-24
14:45:21 UTC (rev 14902)
@@ -91,7 +91,7 @@
IEditorPart editor = null;
Throwable ex = null;
try {
- editor = new OpenSourceAction().run(selection,
MappingTestProject.getTestProject().getIJavaProject(),
+ editor = OpenSourceAction.run(selection,
MappingTestProject.getTestProject().getIJavaProject(),
fullyQualifiedName);
boolean highlighted = ProjectUtil.checkHighlighting(editor);
if (!highlighted) {