Author: dgeraskov
Date: 2007-12-12 09:32:04 -0500 (Wed, 12 Dec 2007)
New Revision: 5258
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/ConfigurationsViewActionGroup.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
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-12
13:14:07 UTC (rev 5257)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java 2007-12-12
14:32:04 UTC (rev 5258)
@@ -46,11 +46,31 @@
if (sel instanceof TreeSelection){
TreePath path = ((TreeSelection)sel).getPaths()[0];
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
- run(path.getLastSegment(), consoleConfiguration);
- }
+ run(path, consoleConfiguration);
+ }
}
- public void run(Object selection, ConsoleConfiguration consoleConfiguration) {
+ public static void run(TreePath path, ConsoleConfiguration consoleConfiguration) {
+ boolean isPropertySel = (path.getLastSegment() instanceof Property);
+ if (isPropertySel){
+ Property propertySel = (Property)path.getLastSegment();
+ PersistentClass persClass = propertySel.getPersistentClass();
+ if ( persClass == null
+ || (RootClass.class.isAssignableFrom(persClass.getClass())
+ && persClass.getClass() != RootClass.class)){
+ Property parentProp = (Property)path.getParentPath().getLastSegment();
+ run(propertySel, parentProp, consoleConfiguration);
+ return;
+ }
+ }
+ run(path.getLastSegment(), consoleConfiguration);
+ }
+
+ /**
+ * @param selection
+ * @param consoleConfiguration
+ */
+ public static void run(Object selection, ConsoleConfiguration consoleConfiguration) {
IEditorPart editorPart = null;
if (selection instanceof Property){
Property p = (Property)selection;
@@ -60,12 +80,43 @@
} else {
editorPart = openMapping(selection, consoleConfiguration);
}
-
+ applySelectionToEditor(selection, editorPart);
+ }
+
+ /**
+ * @param compositeProperty
+ * @param parentProperty
+ * @param consoleConfiguration
+ */
+ public static void run(Property compositeProperty, Property parentProperty,
ConsoleConfiguration consoleConfiguration) {
+ if (parentProperty.getPersistentClass() == null) return;
+ IEditorPart editorPart = openMapping(parentProperty.getPersistentClass(),
consoleConfiguration);
+ ITextEditor textEditor = getTextEditor(editorPart);
+ if (textEditor == null) return;
+ textEditor.selectAndReveal(0, 0);
+ FindReplaceDocumentAdapter findAdapter = getFindDocAdapter(textEditor);
+ IRegion parentRegion = findSelection(parentProperty, findAdapter);
+ if (parentRegion == null) return;
+ try {
+ IRegion propRegion =
findAdapter.find(parentRegion.getOffset()+parentRegion.getLength(),
generatePattern(compositeProperty), true, true, false, true);
+ if (propRegion != null){
+ textEditor.selectAndReveal(propRegion.getOffset(), propRegion.getLength());
+ }
+ } catch (BadLocationException e) {
+ return;
+ }
+ }
+
+ /**
+ * @param selection
+ * @param editorPart
+ */
+ static public void applySelectionToEditor(Object selection, IEditorPart editorPart) {
Assert.isNotNull(editorPart);
ITextEditor textEditor = getTextEditor(editorPart);
if (textEditor == null) return;
- IDocument document =
textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
- FindReplaceDocumentAdapter findAdapter = new FindReplaceDocumentAdapter(document);
+ textEditor.selectAndReveal(0, 0);
+ FindReplaceDocumentAdapter findAdapter = getFindDocAdapter(textEditor);
IRegion selectRegion = null;
if (selection instanceof RootClass
@@ -80,6 +131,17 @@
}
}
+ /**
+ * @param textEditor
+ * @return
+ */
+ private static FindReplaceDocumentAdapter getFindDocAdapter(
+ ITextEditor textEditor) {
+ IDocument document =
textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ FindReplaceDocumentAdapter findAdapter = new FindReplaceDocumentAdapter(document);
+ return findAdapter;
+ }
+
static public IEditorPart openMapping(Object selElement,
ConsoleConfiguration consoleConfiguration) {
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
@@ -186,7 +248,8 @@
private static String generatePattern(Property property){
Cfg2HbmTool tool = new Cfg2HbmTool();
StringBuilder pattern = new StringBuilder("<");
- if(property.getPersistentClass().getIdentifierProperty()==property) {
+ if(property.getPersistentClass() != null &&
+ property.getPersistentClass().getIdentifierProperty()==property) {
pattern.append("id");
} else{
pattern.append(tool.getTag(property));
@@ -199,7 +262,7 @@
return pattern.toString();
}
- private ITextEditor getTextEditor(IEditorPart editorPart) {
+ private static ITextEditor getTextEditor(IEditorPart editorPart) {
/*
* if EditorPart is MultiPageEditorPart then get ITextEditor from it.
*/
@@ -216,4 +279,5 @@
}
return null;
}
+
}
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 2007-12-12
13:14:07 UTC (rev 5257)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceAction.java 2007-12-12
14:32:04 UTC (rev 5258)
@@ -2,7 +2,6 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
@@ -18,6 +17,7 @@
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
@@ -39,53 +39,72 @@
IStructuredSelection sel = getStructuredSelection();
if (sel instanceof TreeSelection){
TreePath path = ((TreeSelection)sel).getPaths()[0];
- PersistentClass persClass = getPersistentClass(path.getLastSegment());
- Assert.isNotNull(persClass);
+ Object lastSegment = path.getLastSegment();
+ PersistentClass persClass = getPersistentClass(lastSegment);
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
-
- IResource resource = null;
+
String fullyQualifiedName = OpenFileActionUtils.getPersistentClassName(persClass);
- IType type = null;
- try {
- type = proj.findType(fullyQualifiedName);
- if (type != null) resource = type.getResource();
-
- } catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("Can't find source
file.", e);
+ if (fullyQualifiedName.length() == 0
+ && lastSegment instanceof Property){
+ Object prevSegment = path.getParentPath().getLastSegment();
+ if (prevSegment instanceof Property
+ && ((Property)prevSegment).isComposite()){
+ fullyQualifiedName =((Component)((Property)
prevSegment).getValue()).getComponentClassName();
+ }
}
-
- if (resource instanceof IFile){
- try {
- IEditorPart editorPart =
OpenFileActionUtils.openEditor(HibernateConsolePlugin.getDefault().getActiveWorkbenchWindow().getActivePage(),
(IFile) resource);
- if (editorPart instanceof JavaEditor) {
- IJavaElement jElement = null;
- if (path.getLastSegment() instanceof Property){
- jElement = type.getField(((Property)path.getLastSegment()).getName());
- } else {
- jElement = type;
- }
- JavaEditor jEditor = (JavaEditor) editorPart;
- selectionToEditor(jElement, jEditor);
- }
- } catch (PartInitException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("Can't open source
file.", e);
- }
- }
-
- if (resource == null) {
- MessageDialog.openInformation(HibernateConsolePlugin.getDefault().getShell(),
"Open Source File", "Source file for class '" + fullyQualifiedName
+ "' not found.");
- }
+
+ run(lastSegment, proj, fullyQualifiedName);
}
}
+
+ /**
+ * @param selection
+ * @param proj
+ * @param fullyQualifiedName
+ */
+ public void run(Object selection, IJavaProject proj,
+ String fullyQualifiedName) {
+ IResource resource = null;
+ IType type = null;
+ try {
+ type = proj.findType(fullyQualifiedName);
+ if (type != null) resource = type.getResource();
+
+ } catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't find source
file.", e);
+ }
+
+ if (resource instanceof IFile){
+ try {
+ IEditorPart editorPart =
OpenFileActionUtils.openEditor(HibernateConsolePlugin.getDefault().getActiveWorkbenchWindow().getActivePage(),
(IFile) resource);
+ if (editorPart instanceof JavaEditor) {
+ IJavaElement jElement = null;
+ if (selection instanceof Property){
+ jElement = type.getField(((Property)selection).getName());
+ } else {
+ jElement = type;
+ }
+ JavaEditor jEditor = (JavaEditor) editorPart;
+ selectionToEditor(jElement, jEditor);
+ }
+ } catch (PartInitException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't open source
file.", e);
+ }
+ }
+
+ if (resource == null) {
+ MessageDialog.openInformation(HibernateConsolePlugin.getDefault().getShell(),
"Open Source File", "Source file for class '" + fullyQualifiedName
+ "' not found.");
+ }
+ }
private PersistentClass getPersistentClass(Object selection){
if (selection instanceof Property){
return ((Property)selection).getPersistentClass();
- } else if (selection instanceof Subclass){
+ } else if (selection instanceof PersistentClass){
return (PersistentClass)selection;
} else {
- return (RootClass)selection;
+ return null;
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java 2007-12-12
13:14:07 UTC (rev 5257)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java 2007-12-12
14:32:04 UTC (rev 5258)
@@ -40,6 +40,7 @@
import org.hibernate.eclipse.console.actions.OpenMappingAction;
import org.hibernate.eclipse.console.actions.OpenSourceAction;
import org.hibernate.eclipse.console.actions.RefreshAction;
+import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.Subclass;
@@ -137,17 +138,11 @@
menu.add(schemaExportAction);
}
menu.add(new Separator() );
- if (first instanceof RootClass
- //|| first instanceof Property
- || first instanceof Subclass){
+ if (first instanceof PersistentClass
+ || first instanceof Property){
menu.add(openSourceAction);
menu.add(openMappingAction);
}
- if (first instanceof Property
- && ((Property)first).getPersistentClass() != null){
- menu.add(openSourceAction);
- menu.add(openMappingAction);
- }
}
public void fillActionBars(IActionBars actionBars) {
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 2007-12-12
13:14:07 UTC (rev 5257)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java 2007-12-12
14:32:04 UTC (rev 5258)
@@ -31,6 +31,7 @@
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
@@ -157,13 +158,10 @@
consoleConfiguration.executeHQLQuery( hql );
}
}
- } else if (firstElement instanceof RootClass
- || firstElement instanceof Subclass
- || (firstElement instanceof Property
- && ((Property)firstElement).getPersistentClass() != null)) {
- ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)((TreeSelection)selection).getPaths()[0].getSegment(0);
- //OpenMappingActionDelegate.openMapping((RootClass) firstElement,
consoleConfiguration);
- new OpenMappingAction().run(firstElement, consoleConfiguration);
+ } else if (selection instanceof TreeSelection){
+ TreePath path = ((TreeSelection)selection).getPaths()[0];
+ ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
+ OpenMappingAction.run(path, consoleConfiguration);
}
}
};