Author: dgeraskov
Date: 2008-01-15 09:32:21 -0500 (Tue, 15 Jan 2008)
New Revision: 5690
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
Log:
http://jira.jboss.com/jira/browse/JBIDE-1412
Didn't work when entityName specified.
Conceal exceptions - impossible to test.
Add return editor to the open methods.
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 2008-01-15
14:32:15 UTC (rev 5689)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java 2008-01-15
14:32:21 UTC (rev 5690)
@@ -1,9 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.hibernate.eclipse.console.actions;
+import java.io.FileNotFoundException;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IDocument;
@@ -47,11 +61,19 @@
if (sel instanceof TreeSelection){
TreePath path = ((TreeSelection)sel).getPaths()[0];
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
- run(path, consoleConfiguration);
+ try {
+ run(path, consoleConfiguration);
+ } catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping
file.", e);
+ } catch (PartInitException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't open mapping
file.", e);
+ } catch (FileNotFoundException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping
file.", e);
+ }
}
}
- public static void run(TreePath path, ConsoleConfiguration consoleConfiguration) {
+ public static void run(TreePath path, ConsoleConfiguration consoleConfiguration) throws
PartInitException, JavaModelException, FileNotFoundException {
boolean isPropertySel = (path.getLastSegment() instanceof Property);
if (isPropertySel){
Property propertySel = (Property)path.getLastSegment();
@@ -70,15 +92,19 @@
/**
* @param selection
* @param consoleConfiguration
+ * @throws JavaModelException
+ * @throws PartInitException
+ * @throws PresistanceClassNotFoundException
+ * @throws FileNotFoundException
*/
- public static void run(Object selection, ConsoleConfiguration consoleConfiguration) {
+ public static IEditorPart run(Object selection, ConsoleConfiguration
consoleConfiguration) throws PartInitException, JavaModelException, FileNotFoundException
{
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;
+ if (p.getPersistentClass() == null) return null;
//use PersistentClass to open editor
resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
p.getPersistentClass());
//editorPart = openMapping(p.getPersistentClass(), consoleConfiguration);
@@ -91,7 +117,7 @@
if (editorPart != null){
applySelectionToEditor(selection, editorPart);
}
- return;
+ return editorPart;
}
//try to find hibernate-annotations
@@ -100,23 +126,31 @@
rootClass = (PersistentClass)selection;
} else if (selection instanceof Property) {
Property p = (Property)selection;
- if (p.getPersistentClass() == null) return;
+ if (p.getPersistentClass() == null) return null;
rootClass = (PersistentClass)p.getPersistentClass();
}
if (rootClass != null){
if (OpenFileActionUtils.rootClassHasAnnotations(consoleConfiguration, configXMLFile,
rootClass)) {
- String fullyQualifiedName = OpenFileActionUtils.getPersistentClassName(rootClass);
- new OpenSourceAction().run(selection, proj, fullyQualifiedName);
+ String fullyQualifiedName = rootClass.getClassName();
+ editorPart = new OpenSourceAction().run(selection, proj, fullyQualifiedName);
+ return editorPart;
}
+ } else {
+ throw new FileNotFoundException("Mapping for " + selection + " not
found.");
}
+ return null;
}
/**
* @param compositeProperty
* @param parentProperty
* @param consoleConfiguration
+ * @throws JavaModelException
+ * @throws PartInitException
+ * @throws FileNotFoundException
+ * @throws BadLocationException
*/
- public static void run(Property compositeProperty, Property parentProperty,
ConsoleConfiguration consoleConfiguration) {
+ public static void run(Property compositeProperty, Property parentProperty,
ConsoleConfiguration consoleConfiguration) throws PartInitException, JavaModelException,
FileNotFoundException{
if (parentProperty.getPersistentClass() == null) return;
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
@@ -132,13 +166,16 @@
FindReplaceDocumentAdapter findAdapter = getFindDocAdapter(textEditor);
IRegion parentRegion = findSelection(parentProperty, findAdapter);
if (parentRegion == null) return;
+
+ IRegion propRegion = null;
try {
- IRegion propRegion =
findAdapter.find(parentRegion.getOffset()+parentRegion.getLength(),
generatePattern(compositeProperty), true, true, false, true);
- if (propRegion != null){
- textEditor.selectAndReveal(propRegion.getOffset(), propRegion.getLength());
- }
+ propRegion = findAdapter.find(parentRegion.getOffset()+parentRegion.getLength(),
generatePattern(compositeProperty), true, true, false, true);
} catch (BadLocationException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Selection not
found.", e);
}
+ if (propRegion != null){
+ textEditor.selectAndReveal(propRegion.getOffset(), propRegion.getLength());
+ }
}
return;
}
@@ -191,7 +228,7 @@
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);
@@ -224,7 +261,8 @@
if (classRegion == null) return null;
IRegion finalRegion =
findAdapter.find(classRegion.getOffset()+classRegion.getLength(), "</class",
true, true, false, false);
IRegion propRegion =
findAdapter.find(classRegion.getOffset()+classRegion.getLength(),
generatePattern(property), true, true, false, true);
- if (propRegion != null && finalRegion != null
+ if (propRegion == null) return null;
+ if (finalRegion != null
&& propRegion.getOffset() > finalRegion.getOffset()){
return null;
} else {
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 2008-01-15
14:32:15 UTC (rev 5689)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceAction.java 2008-01-15
14:32:21 UTC (rev 5690)
@@ -1,5 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.hibernate.eclipse.console.actions;
+import java.io.FileNotFoundException;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IJavaElement;
@@ -7,7 +19,6 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
@@ -20,8 +31,6 @@
import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
-import org.hibernate.mapping.RootClass;
-import org.hibernate.mapping.Subclass;
/**
* @author Dmitry Geraskov
@@ -44,7 +53,7 @@
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
- String fullyQualifiedName = OpenFileActionUtils.getPersistentClassName(persClass);
+ String fullyQualifiedName = persClass.getClassName();
if (fullyQualifiedName.length() == 0
&& lastSegment instanceof Property){
Object prevSegment = path.getParentPath().getLastSegment();
@@ -53,8 +62,15 @@
fullyQualifiedName =((Component)((Property)
prevSegment).getValue()).getComponentClassName();
}
}
-
- run(lastSegment, proj, fullyQualifiedName);
+ try {
+ run(lastSegment, proj, fullyQualifiedName);
+ } catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't find source
file.", e);
+ } catch (PartInitException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't open source
file.", e);
+ } catch (FileNotFoundException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't find source
file.", e);
+ }
}
}
@@ -62,22 +78,19 @@
* @param selection
* @param proj
* @param fullyQualifiedName
+ * @throws JavaModelException
+ * @throws PartInitException
+ * @throws FileNotFoundException
*/
- public void run(Object selection, IJavaProject proj,
- String fullyQualifiedName) {
+ public IEditorPart run(Object selection, IJavaProject proj,
+ String fullyQualifiedName) throws JavaModelException, PartInitException,
FileNotFoundException {
IResource resource = null;
- IType type = null;
- try {
- type = proj.findType(fullyQualifiedName);
- if (type != null) resource = type.getResource();
+ IType type = proj.findType(fullyQualifiedName);
+ if (type != null) resource = type.getResource();
- } catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("Can't find source
file.", e);
- }
-
+ IEditorPart editorPart = null;
if (resource instanceof IFile){
- try {
- IEditorPart editorPart =
OpenFileActionUtils.openEditor(HibernateConsolePlugin.getDefault().getActiveWorkbenchWindow().getActivePage(),
(IFile) resource);
+ editorPart =
OpenFileActionUtils.openEditor(HibernateConsolePlugin.getDefault().getActiveWorkbenchWindow().getActivePage(),
(IFile) resource);
if (editorPart instanceof JavaEditor) {
IJavaElement jElement = null;
if (selection instanceof Property){
@@ -88,14 +101,13 @@
JavaEditor jEditor = (JavaEditor) editorPart;
selectionToEditor(jElement, jEditor);
}
- } catch (PartInitException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("Can't open source
file.", e);
}
+
+ if (editorPart == null) {
+ throw new FileNotFoundException("Source file for class '" +
fullyQualifiedName + "' not found.");
}
+ return editorPart;
- if (resource == null) {
- MessageDialog.openInformation(HibernateConsolePlugin.getDefault().getShell(),
"Open Source File", "Source file for class '" + fullyQualifiedName
+ "' not found.");
- }
}
private PersistentClass getPersistentClass(Object selection){
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 2008-01-15
14:32:15 UTC (rev 5689)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java 2008-01-15
14:32:21 UTC (rev 5690)
@@ -47,13 +47,11 @@
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.node.BaseNode;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.actions.EditConsoleConfiguration;
import org.hibernate.eclipse.console.actions.OpenMappingAction;
import org.hibernate.eclipse.console.viewers.xpl.MTreeViewer;
import org.hibernate.eclipse.console.workbench.xpl.AnyAdaptableLabelProvider;
-import org.hibernate.mapping.Property;
-import org.hibernate.mapping.RootClass;
-import org.hibernate.mapping.Subclass;
import org.hibernate.util.StringHelper;
@@ -163,7 +161,11 @@
} else if (selection instanceof TreeSelection){
TreePath path = ((TreeSelection)selection).getPaths()[0];
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
- OpenMappingAction.run(path, consoleConfiguration);
+ try {
+ OpenMappingAction.run(path, consoleConfiguration);
+ } catch (Exception e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping
file.", e);
+ }
}
}
};