Author: dgeraskov
Date: 2008-01-18 06:36:30 -0500 (Fri, 18 Jan 2008)
New Revision: 5796
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
Log:
http://jira.jboss.com/jira/browse/JBIDE-1649
"instance of" changed to getClass = Property.class
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-18
11:19:11 UTC (rev 5795)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingAction.java 2008-01-18
11:36:30 UTC (rev 5796)
@@ -77,7 +77,7 @@
}
public static void run(TreePath path, ConsoleConfiguration consoleConfiguration) throws
PartInitException, JavaModelException, FileNotFoundException {
- boolean isPropertySel = (path.getLastSegment() instanceof Property);
+ boolean isPropertySel = (path.getLastSegment().getClass() == Property.class);
if (isPropertySel){
Property propertySel = (Property)path.getLastSegment();
PersistentClass persClass = propertySel.getPersistentClass();
@@ -153,8 +153,8 @@
* @throws FileNotFoundException
* @throws BadLocationException
*/
- public static boolean run(Property compositeProperty, Property parentProperty,
ConsoleConfiguration consoleConfiguration) throws PartInitException, JavaModelException,
FileNotFoundException{
- if (parentProperty.getPersistentClass() == null) return false;
+ public static IEditorPart run(Property compositeProperty, Property parentProperty,
ConsoleConfiguration consoleConfiguration) throws PartInitException, JavaModelException,
FileNotFoundException{
+ if (parentProperty.getPersistentClass() == null) return null;
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
IResource resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, parentProperty.getPersistentClass());
@@ -164,7 +164,7 @@
editorPart = openMapping(resource);
if (editorPart != null){
ITextEditor[] textEditors = getTextEditors(editorPart);
- if (textEditors.length == 0) return false;
+ if (textEditors.length == 0) return editorPart;
textEditors[0].selectAndReveal(0, 0);
FindReplaceDocumentAdapter findAdapter = null;
ITextEditor textEditor = null;
@@ -172,22 +172,36 @@
textEditor = textEditors[i];
findAdapter = getFindDocAdapter(textEditor);
}
- if (findAdapter == null) return false;
+ if (findAdapter == null) return null;
IRegion parentRegion = findSelection(parentProperty, findAdapter);
- if (parentRegion == null) return false;
+ if (parentRegion == null) return editorPart;
IRegion propRegion = null;
try {
propRegion = findAdapter.find(parentRegion.getOffset()+parentRegion.getLength(),
generatePattern(compositeProperty), true, true, false, true);
+ if (propRegion == null){
+ // try to use key-property
+ String pattern =
generatePattern(compositeProperty).replaceFirst("property",
"key-property");
+ propRegion = findAdapter.find(parentRegion.getOffset()+parentRegion.getLength(),
pattern, true, true, false, true);
+ }
+ /*if (propRegion == null){
+ // try to find name = "<name>"
+ String pattern = HIBERNATE_TAG_NAME + "[\\s]*=[\\s]*\"" +
property.getNodeName() + '\"';
+ propRegion = findAdapter.find(parentRegion.getOffset()+parentRegion.getLength(),
pattern, true, true, false, true);
+ }*/
} catch (BadLocationException e) {
HibernateConsolePlugin.getDefault().logErrorMessage("Selection not
found.", e);
- }
+ }
+
if (propRegion != null){
+ int length = compositeProperty.getNodeName().length();
+ int offset = propRegion.getOffset() + propRegion.getLength() - length - 1;
+ propRegion = new Region(offset, length);
textEditor.selectAndReveal(propRegion.getOffset(), propRegion.getLength());
- return true;
+ return editorPart;
}
}
- return false;
+ return editorPart;
}
if (parentProperty.getPersistentClass() != null &&
parentProperty.isComposite()){
@@ -195,10 +209,13 @@
if (OpenFileActionUtils.rootClassHasAnnotations(consoleConfiguration, configXMLFile,
rootClass)) {
String fullyQualifiedName =((Component)((Property)
parentProperty).getValue()).getComponentClassName();
IEditorPart editor = new OpenSourceAction().run(compositeProperty, proj,
fullyQualifiedName);
- if (editor != null) return true;
+ return editor;
}
}
- return false;
+ if (editorPart == null) {
+ throw new FileNotFoundException("Mapping file for property '" +
compositeProperty.getNodeName() + "' not found.");
+ }
+ return null;
}
/**
@@ -369,7 +386,11 @@
StringBuffer pattern = new StringBuffer("<");
if(property.getPersistentClass() != null &&
property.getPersistentClass().getIdentifierProperty()==property) {
- pattern.append("id");
+ if (property.isComposite()){
+ pattern.append("composite-id");
+ } else {
+ pattern.append("id");
+ }
} else{
pattern.append(tool.getTag(property));
}
@@ -387,7 +408,7 @@
* @param editorPart
* @return
*/
- private static ITextEditor[] getTextEditors(IEditorPart editorPart) {
+ public static ITextEditor[] getTextEditors(IEditorPart editorPart) {
/*
* if EditorPart is MultiPageEditorPart then get ITextEditor from it.
*/
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-18
11:19:11 UTC (rev 5795)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceAction.java 2008-01-18
11:36:30 UTC (rev 5796)
@@ -53,15 +53,18 @@
ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(path.getSegment(0));
IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
- String fullyQualifiedName = persClass.getClassName();
- if (fullyQualifiedName.length() == 0
- && lastSegment instanceof Property){
+ String fullyQualifiedName = null;
+ if (lastSegment instanceof Property){
Object prevSegment = path.getParentPath().getLastSegment();
if (prevSegment instanceof Property
&& ((Property)prevSegment).isComposite()){
fullyQualifiedName =((Component)((Property)
prevSegment).getValue()).getComponentClassName();
}
}
+ if (fullyQualifiedName == null && persClass != null){
+ fullyQualifiedName = persClass.getClassName();
+ }
+
try {
run(lastSegment, proj, fullyQualifiedName);
} catch (JavaModelException e) {
@@ -84,8 +87,23 @@
*/
public IEditorPart run(Object selection, IJavaProject proj,
String fullyQualifiedName) throws JavaModelException, PartInitException,
FileNotFoundException {
+ if (fullyQualifiedName == null) return null;
+ String remainder = null;
+ IType type = null;
+ if (fullyQualifiedName.indexOf("$") > 0) {
+ remainder = fullyQualifiedName.substring(fullyQualifiedName.indexOf("$") +
1);
+ fullyQualifiedName = fullyQualifiedName.substring(0,
fullyQualifiedName.indexOf("$"));
+ type = proj.findType(fullyQualifiedName);
+ while ( remainder.indexOf("$") > 0 ){
+ String subtype = remainder.substring(0, fullyQualifiedName.indexOf("$"));
+ type = type.getType(subtype);
+ remainder = remainder.substring(fullyQualifiedName.indexOf("$") + 1);
+ }
+ type = type.getType(remainder);
+ } else {
+ type = proj.findType(fullyQualifiedName);
+ }
IResource resource = null;
- IType type = proj.findType(fullyQualifiedName);
if (type != null) resource = type.getResource();
IEditorPart editorPart = null;
@@ -126,4 +144,5 @@
}
}
+
}
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 2008-01-18
11:19:11 UTC (rev 5795)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java 2008-01-18
11:36:30 UTC (rev 5796)
@@ -139,7 +139,7 @@
}
menu.add(new Separator() );
if (first instanceof PersistentClass
- || first instanceof Property){
+ || first.getClass() == Property.class){
menu.add(openSourceAction);
menu.add(openMappingAction);
}