Author: max.andersen(a)jboss.com
Date: 2007-11-07 12:12:45 -0500 (Wed, 07 Nov 2007)
New Revision: 4759
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/HTConstants.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenActionDelegate.java
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/OpenMappingActionDelegate.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceActionDelegate.java
Removed:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/HTConstants.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF
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/OpenSourceAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/plugin.xml
Log:
JBIDE-1275 Double click on entity in conosle tree should open mapping
+ moved the open src/mapping into hibernate console since they are not dependent on the
diagram.
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2007-11-07
15:17:26 UTC (rev 4758)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2007-11-07
17:12:45 UTC (rev 4759)
@@ -133,6 +133,26 @@
</page>
</extension>
+
+ <extension point="org.eclipse.ui.popupMenus">
+ <objectContribution id="mappingEditorAction"
objectClass="org.hibernate.mapping.RootClass">
+ <menu id="org.hibernate.eclipse.console.actions.openMappingMenu"
label="Open Mapping File" path="mappingEditorAction"/>
+ <action
+ id="org.hibernate.eclipse.console.actions.openMappingAction"
+ label="Open Mapping File"
+
class="org.hibernate.eclipse.console.actions.OpenMappingActionDelegate">
+ </action>
+ </objectContribution>
+ <objectContribution id="sourceEditorAction"
objectClass="org.hibernate.mapping.RootClass">
+ <menu id="org.hibernate.eclipse.console.actions.openSourceMenu"
label="Open Source File" path="sourceEditorAction"/>
+ <action
+ id="org.hibernate.eclipse.console.actions.openSourceAction"
+ label="Open Source File"
+
class="org.hibernate.eclipse.console.actions.OpenSourceActionDelegate">
+ </action>
+ </objectContribution>
+ </extension>
+
<extension
id="hibernateNature"
name="Hibernate Nature"
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/HTConstants.java
(from rev 4752,
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/HTConstants.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/HTConstants.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/HTConstants.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -0,0 +1,5 @@
+package org.hibernate.eclipse.console.actions;
+
+public interface HTConstants {
+
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenActionDelegate.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenActionDelegate.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -0,0 +1,21 @@
+package org.hibernate.eclipse.console.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+public abstract class OpenActionDelegate implements IObjectActionDelegate {
+ private IWorkbenchPart part;
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ this.part = targetPart;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ public IWorkbenchPart getPart() {
+ return part;
+ }
+}
\ No newline at end of file
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java
(from rev 4752,
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenFileActionUtils.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -0,0 +1,282 @@
+package org.hibernate.eclipse.console.actions;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.VisitorSupport;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Subclass;
+import org.hibernate.mapping.Table;
+import org.hibernate.util.StringHelper;
+import org.hibernate.util.XMLHelper;
+import org.xml.sax.InputSource;
+
+public class OpenFileActionUtils {
+ private static XMLHelper helper = new XMLHelper();
+
+ private static final String HIBERNATE_TAG_CLASS = "class";
+ private static final String HIBERNATE_TAG_TABLE = "table";
+ private static final String HIBERNATE_TAG_SUBCLASS = "subclass";
+ private static final String HIBERNATE_TAG_JOINED_SUBCLASS =
"joined-subclass";
+ private static final String HIBERNATE_TAG_UNION_SUBCLASS = "union-subclass";
+ private static final String HIBERNATE_TAG_NAME = "name";
+ private static final String HIBERNATE_TAG_ENTITY_NAME = "entity-name";
+ private static final String HIBERNATE_TAG_SESSION_FACTORY =
"session-factory";
+ private static final String HIBERNATE_TAG_MAPPING = "mapping";
+ private static final String HIBERNATE_TAG_RESOURCE = "resource";
+ private static final String HIBERNATE_TAG_CATALOG = "catalog";
+ private static final String HIBERNATE_TAG_SCHEMA = "schema";
+
+ public static void openEditor(IWorkbenchPage page, IResource resource) throws
PartInitException {
+ IDE.openEditor(page, (IFile) resource);
+ }
+
+
+ public static boolean rootClassHasAnnotations(ConsoleConfiguration consoleConfiguration,
java.io.File configXMLFile, RootClass rootClass) {
+ if (configXMLFile == null) return true;
+ Document doc = getDocument(consoleConfiguration, configXMLFile);
+ return getElements(doc, HIBERNATE_TAG_MAPPING, HIBERNATE_TAG_CLASS,
getPersistentClassName(rootClass)).hasNext();
+ }
+
+ static String getPersistentClassName(PersistentClass rootClass) {
+ if (rootClass == null) {
+ return "";
+ } else {
+ return rootClass.getEntityName() != null ? rootClass.getEntityName() :
rootClass.getClassName();
+ }
+ }
+
+ private static String getTableName(String catalog, String schema, String name) {
+ return (catalog != null ? catalog + "." : "") + (schema != null ?
schema + "." : "") + name;
+ }
+
+ private static String getTableName(Table table) {
+ return getTableName(table.getCatalog(), table.getSchema(), table.getName());
+ }
+
+
+ private static boolean elementInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Object element) {
+ if (element instanceof RootClass) {
+ return rootClassInResource(consoleConfiguration, resource, (RootClass)element);
+ } else if (element instanceof Subclass) {
+ return subclassInResource(consoleConfiguration, resource, (Subclass)element);
+ } else if (element instanceof Table) {
+ return tableInResource(consoleConfiguration, resource, (Table)element);
+ } else {
+ return false;
+ }
+ }
+
+ private static boolean rootClassInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, RootClass persistentClass) {
+ Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
+ return getElements(doc, OpenFileActionUtils.HIBERNATE_TAG_CLASS, HIBERNATE_TAG_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, OpenFileActionUtils.HIBERNATE_TAG_CLASS, HIBERNATE_TAG_NAME,
getPersistentClassName(persistentClass)).hasNext() ||
+ getElements(doc, OpenFileActionUtils.HIBERNATE_TAG_CLASS,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, OpenFileActionUtils.HIBERNATE_TAG_CLASS,
getPersistentClassName(persistentClass)).hasNext() ||
+ getElements(doc, OpenFileActionUtils.HIBERNATE_TAG_CLASS, HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, OpenFileActionUtils.HIBERNATE_TAG_CLASS, HIBERNATE_TAG_ENTITY_NAME,
getPersistentClassName(persistentClass)).hasNext();
+ }
+
+ private static boolean subclassInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Subclass persistentClass) {
+ Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
+ return getElements(doc, HIBERNATE_TAG_SUBCLASS, HIBERNATE_TAG_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_SUBCLASS, HIBERNATE_TAG_NAME,
getPersistentClassName(persistentClass)).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_SUBCLASS, HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_SUBCLASS, HIBERNATE_TAG_ENTITY_NAME,
getPersistentClassName(persistentClass)).hasNext() ||
+
+ getElements(doc, HIBERNATE_TAG_JOINED_SUBCLASS, HIBERNATE_TAG_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_JOINED_SUBCLASS, HIBERNATE_TAG_NAME,
getPersistentClassName(persistentClass)).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_JOINED_SUBCLASS, HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_JOINED_SUBCLASS, HIBERNATE_TAG_ENTITY_NAME,
getPersistentClassName(persistentClass)).hasNext() ||
+
+ getElements(doc, HIBERNATE_TAG_UNION_SUBCLASS, HIBERNATE_TAG_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_UNION_SUBCLASS, HIBERNATE_TAG_NAME,
getPersistentClassName(persistentClass)).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_UNION_SUBCLASS, HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(getPersistentClassName(persistentClass))).hasNext() ||
+ getElements(doc, HIBERNATE_TAG_UNION_SUBCLASS, HIBERNATE_TAG_ENTITY_NAME,
getPersistentClassName(persistentClass)).hasNext();
+ }
+
+ private static boolean tableInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Table table) {
+ Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
+
+ Iterator classes = getElements(doc, OpenFileActionUtils.HIBERNATE_TAG_CLASS);
+ while (classes.hasNext()) {
+ Element element = (Element) classes.next();
+
+ Attribute tableAttr = element.attribute( HIBERNATE_TAG_TABLE );
+ if (tableAttr != null) {
+ Attribute catalogAttr = element.attribute( HIBERNATE_TAG_CATALOG );
+ if (catalogAttr == null) catalogAttr =
doc.getRootElement().attribute(HIBERNATE_TAG_CATALOG);
+ Attribute schemaAttr = element.attribute( HIBERNATE_TAG_SCHEMA );
+ if (schemaAttr == null) schemaAttr =
doc.getRootElement().attribute(HIBERNATE_TAG_SCHEMA);
+ if (
+ getTableName(
+ (catalogAttr != null ? catalogAttr.getValue() : null),
+ (schemaAttr != null ? schemaAttr.getValue() : null),
+ tableAttr.getValue()
+ ).equals(getTableName(table))
+ ) {
+ return true;
+ }
+
+
+ }
+
+ Attribute classNameAttr = element.attribute( HIBERNATE_TAG_NAME );
+ if (classNameAttr == null) classNameAttr = element.attribute(
HIBERNATE_TAG_ENTITY_NAME);
+ if (classNameAttr != null) {
+ String physicalTableName =
consoleConfiguration.getConfiguration().getNamingStrategy().classToTableName(classNameAttr.getValue());
+ if (table.getName().equals(physicalTableName)) {
+ return true;
+ }
+ }
+ }
+
+ if (getElements(doc, HIBERNATE_TAG_TABLE, table.getName()).hasNext()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private static Iterator getElements(Document doc, String elementName) {
+ return getElements(doc, elementName, null, null);
+ }
+
+ private static Iterator getElements(Document doc, String attrName, String attrValue) {
+ return getElements(doc, null, attrName, attrValue);
+ }
+
+ private static Iterator getElements(Document doc, String elementName, String attrName,
String attrValue) {
+ LVS visitor = new LVS(elementName, attrName, attrValue);
+ doc.accept( visitor );
+ return visitor.iterator();
+ }
+
+ static class LVS extends VisitorSupport {
+ private String nodeName;
+ private String attrName;
+ private String attrValue;
+ private List ret = new ArrayList();
+
+ public LVS(String nodeName, String attrName, String attrValue) {
+ super();
+ this.nodeName = nodeName;
+ this.attrName = attrName;
+ this.attrValue = attrValue;
+ }
+
+ public void visit(Element element) {
+ if (nodeName == null) {
+ if (attrName != null && attrValue != null) {
+ if (attrIsCorrect(element, attrName, attrValue)) {
+ ret.add(element);
+ }
+ }
+ } else {
+ if (nodeName.equals(element.getName())) {
+ if (attrName != null) {
+ if (attrIsCorrect(element, attrName, attrValue)) {
+ ret.add(element);
+ }
+ } else {
+ ret.add(element);
+ }
+ }
+ }
+
+ }
+
+ public Iterator iterator() {
+ return ret.iterator();
+ }
+ }
+
+ private static boolean attrIsCorrect(Element element, String attrName, String attrValue)
{
+ Attribute attr = element.attribute(attrName);
+ if (attr != null && attrValue.equals(attr.getValue())) {
+ return attrValue.equals(attr.getValue());
+ }
+ return false;
+ }
+
+ public static Document getDocument(ConsoleConfiguration consoleConfiguration,
java.io.File configXMLFile) {
+ Document doc = null;
+ if (consoleConfiguration != null && configXMLFile != null) {
+ InputStream stream = null;
+ try {
+ stream = new FileInputStream( configXMLFile );
+ } catch (FileNotFoundException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Configuration file not
found", e);
+ }
+ try {
+ List errors = new ArrayList();
+ doc = helper.createSAXReader( configXMLFile.getPath(), errors,
consoleConfiguration.getConfiguration().getEntityResolver() )
+ .read( new InputSource( stream ) );
+ if ( errors.size() != 0 ) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("invalid
configuration", (Throwable)null);
+ }
+ }
+ catch (DocumentException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Could not parse
configuration", e);
+ }
+ finally {
+ try {
+ stream.close();
+ }
+ catch (IOException ioe) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("could not close input
stream for", ioe);
+ }
+ }
+ }
+ return doc;
+ }
+
+ public static IResource getResource(ConsoleConfiguration consoleConfiguration,
IJavaProject proj, java.io.File configXMLFile, Object element) {
+ Document doc = getDocument(consoleConfiguration, configXMLFile);
+ IResource resource = null;
+ if (consoleConfiguration != null && proj != null && doc != null) {
+ Element sfNode = doc.getRootElement().element( HIBERNATE_TAG_SESSION_FACTORY );
+ Iterator elements = sfNode.elements(HIBERNATE_TAG_MAPPING).iterator();
+ while ( elements.hasNext() ) {
+ Element subelement = (Element) elements.next();
+ Attribute file = subelement.attribute( HIBERNATE_TAG_RESOURCE );
+ if (file != null) {
+ resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(configXMLFile.getParent()).append(file.getValue()));
+ if (elementInResource(consoleConfiguration, resource, element)) return resource;
+ }
+ }
+
+ 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 (OpenFileActionUtils.elementInResource(consoleConfiguration, resource, element))
return resource;
+ }
+ }
+ }
+ return null;
+ }
+
+
+}
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingActionDelegate.java
(from rev 4752,
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingActionDelegate.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenMappingActionDelegate.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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 org.dom4j.Document;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.internal.ObjectPluginAction;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.util.XMLHelper;
+
+public class OpenMappingActionDelegate extends OpenActionDelegate {
+ private static XMLHelper helper = new XMLHelper();
+
+ public void run(IAction action) {
+ ObjectPluginAction objectPluginAction = (ObjectPluginAction)action;
+ TreeSelection selection = (TreeSelection)objectPluginAction.getSelection();
+ RootClass rootClass = (RootClass)(selection).getFirstElement();
+ ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)((selection).getPaths()[0]).getSegment(0);
+ openMapping(rootClass, consoleConfiguration);
+ }
+
+ static public void openMapping(RootClass rootClass,
+ ConsoleConfiguration consoleConfiguration) {
+ IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
+ java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
+ Document doc = OpenFileActionUtils.getDocument(consoleConfiguration, configXMLFile);
+// IResource resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
doc, configXMLFile, rootClass);
+ IResource resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, rootClass);
+
+ if (resource == null) {
+ String fullyQualifiedName = OpenFileActionUtils.getPersistentClassName(rootClass);
+ try {
+ resource = proj.findType(fullyQualifiedName).getResource();
+ } catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping
file.", e);
+ }
+ }
+
+ if (resource != null && resource instanceof IFile){
+ try {
+
OpenFileActionUtils.openEditor(HibernateConsolePlugin.getDefault().getActiveWorkbenchWindow().getActivePage(),
(IFile) resource);
+ } catch (PartInitException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't open
mapping or source file.", e);
+ }
+ }
+ }
+}
\ No newline at end of file
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceActionDelegate.java
(from rev 4752,
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceActionDelegate.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/OpenSourceActionDelegate.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.internal.ObjectPluginAction;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.mapping.RootClass;
+
+public class OpenSourceActionDelegate extends OpenActionDelegate {
+
+ public void run(IAction action) {
+ ObjectPluginAction objectPluginAction = (ObjectPluginAction)action;
+ RootClass rootClass =
(RootClass)((TreeSelection)objectPluginAction.getSelection()).getFirstElement();
+ ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(((TreeSelection)objectPluginAction.getSelection()).getPaths()[0]).getSegment(0);
+ IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
+
+ IResource resource = null;
+ String fullyQualifiedName = OpenFileActionUtils.getPersistentClassName(rootClass);
+ try {
+ IType 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 {
+
OpenFileActionUtils.openEditor(HibernateConsolePlugin.getDefault().getActiveWorkbenchWindow().getActivePage(),
(IFile) resource);
+ } 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.");
+ }
+ }
+}
\ No newline at end of file
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-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -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.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
@@ -39,6 +40,7 @@
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.internal.ObjectPluginAction;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.PropertySheetPage;
@@ -46,7 +48,10 @@
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.node.BaseNode;
import org.hibernate.eclipse.console.actions.EditConsoleConfiguration;
+import org.hibernate.eclipse.console.actions.OpenMappingActionDelegate;
import org.hibernate.eclipse.console.workbench.xpl.AnyAdaptableLabelProvider;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.RootClass;
import org.hibernate.util.StringHelper;
@@ -152,6 +157,9 @@
consoleConfiguration.executeHQLQuery( hql );
}
}
+ } else if (firstElement instanceof RootClass) {
+ ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)((TreeSelection)selection).getPaths()[0].getSegment(0);
+ OpenMappingActionDelegate.openMapping((RootClass) firstElement,
consoleConfiguration);
}
}
};
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF 2007-11-07
17:12:45 UTC (rev 4759)
@@ -15,7 +15,8 @@
org.eclipse.core.resources,
org.hibernate.eclipse,
org.eclipse.jdt.core,
- org.jboss.tools.hibernate.ui.view
+ org.jboss.tools.hibernate.ui.view,
+ org.hibernate.eclipse.console
Bundle-Version: 2.0.0
Export-Package: org.jboss.tools.hibernate.ui.veditor,
org.jboss.tools.hibernate.ui.veditor.editors,
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 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -3,7 +3,6 @@
import java.util.Iterator;
import java.util.Set;
-import org.dom4j.Document;
import org.eclipse.core.resources.IResource;
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.jdt.core.IJavaProject;
@@ -11,19 +10,17 @@
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.actions.OpenFileActionUtils;
import org.hibernate.mapping.Collection;
-import org.hibernate.mapping.Map;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
import org.jboss.tools.hibernate.ui.veditor.VisualEditorPlugin;
import org.jboss.tools.hibernate.ui.veditor.editors.VisualEditor;
-import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
import org.jboss.tools.hibernate.ui.veditor.editors.model.SpecialRootClass;
import org.jboss.tools.hibernate.ui.view.views.HibernateUtils;
import org.jboss.tools.hibernate.ui.view.views.ObjectEditorInput;
-import org.jboss.tools.hibernate.ui.view.views.OpenFileActionUtils;
public class OpenMappingAction extends SelectionAction {
public static String ACTION_ID =
"org.jboss.tools.hibernate.ui.veditor.editors.actions.open.mapping";
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -13,6 +13,7 @@
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.actions.OpenFileActionUtils;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass;
import org.jboss.tools.hibernate.ui.veditor.VisualEditorPlugin;
@@ -21,7 +22,7 @@
import org.jboss.tools.hibernate.ui.view.ViewPlugin;
import org.jboss.tools.hibernate.ui.view.views.HibernateUtils;
import org.jboss.tools.hibernate.ui.view.views.ObjectEditorInput;
-import org.jboss.tools.hibernate.ui.view.views.OpenFileActionUtils;
+import org.hibernate.eclipse.console.actions.OpenFileActionUtils;
public class OpenSourceAction extends SelectionAction {
public static String ACTION_ID =
"org.jboss.tools.hibernate.ui.veditor.editors.actions.open.source";
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -19,6 +19,7 @@
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
+// TODO: What is this ? And why is it extending mapping classes ?!
public class SpecialRootClass extends RootClass {
private Property property;
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/plugin.xml 2007-11-07
15:17:26 UTC (rev 4758)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/plugin.xml 2007-11-07
17:12:45 UTC (rev 4759)
@@ -11,23 +11,5 @@
class="org.jboss.tools.hibernate.ui.view.views.OpenDiagramActionDelegate">
</action>
</objectContribution>
- <objectContribution id="mappingEditorAction"
objectClass="org.hibernate.mapping.RootClass">
- <menu id="org.jboss.tools.hibernate.ui.view.openMapping"
label="Open Mapping File" path="mappingEditorAction"/>
- <action
- id="org.jboss.tools.hibernate.ui.view.openMappingAction"
- label="Open Mapping File"
- icon="icons/runOpenMapping.gif"
-
class="org.jboss.tools.hibernate.ui.view.views.OpenMappingActionDelegate">
- </action>
- </objectContribution>
- <objectContribution id="sourceEditorAction"
objectClass="org.hibernate.mapping.RootClass">
- <menu id="org.jboss.tools.hibernate.ui.view.openSource"
label="Open Source File" path="sourceEditorAction"/>
- <action
- id="org.jboss.tools.hibernate.ui.view.openSourceAction"
- label="Open Source File"
- icon="icons/runOpenSource.gif"
-
class="org.jboss.tools.hibernate.ui.view.views.OpenSourceActionDelegate">
- </action>
- </objectContribution>
</extension>
</plugin>
Deleted:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/HTConstants.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/HTConstants.java 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/HTConstants.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -1,16 +0,0 @@
-package org.jboss.tools.hibernate.ui.view.views;
-
-public class HTConstants {
- public static String HIBERNATE_TAG_CLASS = "class";
- public static String HIBERNATE_TAG_TABLE = "table";
- public static String HIBERNATE_TAG_SUBCLASS = "subclass";
- public static String HIBERNATE_TAG_JOINED_SUBCLASS = "joined-subclass";
- public static String HIBERNATE_TAG_UNION_SUBCLASS = "union-subclass";
- public static String HIBERNATE_TAG_NAME = "name";
- public static String HIBERNATE_TAG_ENTITY_NAME = "entity-name";
- public static String HIBERNATE_TAG_SESSION_FACTORY = "session-factory";
- public static String HIBERNATE_TAG_MAPPING = "mapping";
- public static String HIBERNATE_TAG_RESOURCE = "resource";
- public static String HIBERNATE_TAG_CATALOG = "catalog";
- public static String HIBERNATE_TAG_SCHEMA = "schema";
-}
Deleted:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenFileActionUtils.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -1,248 +0,0 @@
-package org.jboss.tools.hibernate.ui.view.views;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.VisitorSupport;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.ide.IDE;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.mapping.RootClass;
-import org.hibernate.mapping.Subclass;
-import org.hibernate.mapping.Table;
-import org.hibernate.util.StringHelper;
-import org.hibernate.util.XMLHelper;
-import org.jboss.tools.hibernate.ui.view.ViewPlugin;
-import org.xml.sax.InputSource;
-
-public class OpenFileActionUtils {
- private static XMLHelper helper = new XMLHelper();
-
- public static void openEditor(IWorkbenchPage page, IResource resource) throws
PartInitException {
- IDE.openEditor(page, (IFile) resource);
- }
-
- public static boolean rootClassHasAnnotations(ConsoleConfiguration consoleConfiguration,
java.io.File configXMLFile, RootClass rootClass) {
- if (configXMLFile == null) return true;
- Document doc = getDocument(consoleConfiguration, configXMLFile);
- return getElements(doc, HTConstants.HIBERNATE_TAG_MAPPING,
HTConstants.HIBERNATE_TAG_CLASS,
HibernateUtils.getPersistentClassName(rootClass)).hasNext();
- }
-
- private static boolean elementInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Object element) {
- if (element instanceof RootClass) {
- return rootClassInResource(consoleConfiguration, resource, (RootClass)element);
- } else if (element instanceof Subclass) {
- return subclassInResource(consoleConfiguration, resource, (Subclass)element);
- } else if (element instanceof Table) {
- return tableInResource(consoleConfiguration, resource, (Table)element);
- } else {
- return false;
- }
- }
-
- public static boolean rootClassInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, RootClass persistentClass) {
- Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
- return getElements(doc, HTConstants.HIBERNATE_TAG_CLASS,
HTConstants.HIBERNATE_TAG_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_CLASS, HTConstants.HIBERNATE_TAG_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext() ||
- getElements(doc, HTConstants.HIBERNATE_TAG_CLASS,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_CLASS,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext() ||
- getElements(doc, HTConstants.HIBERNATE_TAG_CLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_CLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext();
- }
-
- public static boolean subclassInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Subclass persistentClass) {
- Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
- return getElements(doc, HTConstants.HIBERNATE_TAG_SUBCLASS,
HTConstants.HIBERNATE_TAG_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_SUBCLASS, HTConstants.HIBERNATE_TAG_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext() ||
- getElements(doc, HTConstants.HIBERNATE_TAG_SUBCLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_SUBCLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext() ||
-
- getElements(doc, HTConstants.HIBERNATE_TAG_JOINED_SUBCLASS,
HTConstants.HIBERNATE_TAG_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_JOINED_SUBCLASS,
HTConstants.HIBERNATE_TAG_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext() ||
- getElements(doc, HTConstants.HIBERNATE_TAG_JOINED_SUBCLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_JOINED_SUBCLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext() ||
-
- getElements(doc, HTConstants.HIBERNATE_TAG_UNION_SUBCLASS,
HTConstants.HIBERNATE_TAG_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_UNION_SUBCLASS,
HTConstants.HIBERNATE_TAG_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext() ||
- getElements(doc, HTConstants.HIBERNATE_TAG_UNION_SUBCLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
StringHelper.unqualify(HibernateUtils.getPersistentClassName(persistentClass))).hasNext()
||
- getElements(doc, HTConstants.HIBERNATE_TAG_UNION_SUBCLASS,
HTConstants.HIBERNATE_TAG_ENTITY_NAME,
HibernateUtils.getPersistentClassName(persistentClass)).hasNext();
- }
-
- public static boolean tableInResource(ConsoleConfiguration consoleConfiguration,
IResource resource, Table table) {
- Document doc = getDocument(consoleConfiguration, resource.getLocation().toFile());
-
- Iterator classes = getElements(doc, HTConstants.HIBERNATE_TAG_CLASS);
- while (classes.hasNext()) {
- Element element = (Element) classes.next();
-
- Attribute tableAttr = element.attribute( HTConstants.HIBERNATE_TAG_TABLE );
- if (tableAttr != null) {
- Attribute catalogAttr = element.attribute( HTConstants.HIBERNATE_TAG_CATALOG );
- if (catalogAttr == null) catalogAttr =
doc.getRootElement().attribute(HTConstants.HIBERNATE_TAG_CATALOG);
- Attribute schemaAttr = element.attribute( HTConstants.HIBERNATE_TAG_SCHEMA );
- if (schemaAttr == null) schemaAttr =
doc.getRootElement().attribute(HTConstants.HIBERNATE_TAG_SCHEMA);
- if (HibernateUtils.
- getTableName(
- (catalogAttr != null ? catalogAttr.getValue() : null),
- (schemaAttr != null ? schemaAttr.getValue() : null),
- tableAttr.getValue()
- ).equals(HibernateUtils.getTableName(table))
- ) {
- return true;
- }
-
-
- }
-
- Attribute classNameAttr = element.attribute( HTConstants.HIBERNATE_TAG_NAME );
- if (classNameAttr == null) classNameAttr = element.attribute(
HTConstants.HIBERNATE_TAG_ENTITY_NAME);
- if (classNameAttr != null) {
- String physicalTableName =
consoleConfiguration.getConfiguration().getNamingStrategy().classToTableName(classNameAttr.getValue());
- if (table.getName().equals(physicalTableName)) {
- return true;
- }
- }
- }
-
- if (getElements(doc, HTConstants.HIBERNATE_TAG_TABLE, table.getName()).hasNext()) {
- return true;
- }
-
- return false;
- }
-
- private static Iterator getElements(Document doc, String elementName) {
- return getElements(doc, elementName, null, null);
- }
-
- private static Iterator getElements(Document doc, String attrName, String attrValue) {
- return getElements(doc, null, attrName, attrValue);
- }
-
- private static Iterator getElements(Document doc, String elementName, String attrName,
String attrValue) {
- LVS visitor = new LVS(elementName, attrName, attrValue);
- doc.accept( visitor );
- return visitor.iterator();
- }
-
- static class LVS extends VisitorSupport {
- private String nodeName;
- private String attrName;
- private String attrValue;
- private List ret = new ArrayList();
-
- public LVS(String nodeName, String attrName, String attrValue) {
- super();
- this.nodeName = nodeName;
- this.attrName = attrName;
- this.attrValue = attrValue;
- }
-
- public void visit(Element element) {
- if (nodeName == null) {
- if (attrName != null && attrValue != null) {
- if (attrIsCorrect(element, attrName, attrValue)) {
- ret.add(element);
- }
- }
- } else {
- if (nodeName.equals(element.getName())) {
- if (attrName != null) {
- if (attrIsCorrect(element, attrName, attrValue)) {
- ret.add(element);
- }
- } else {
- ret.add(element);
- }
- }
- }
-
- }
-
- public Iterator iterator() {
- return ret.iterator();
- }
- }
-
- private static boolean attrIsCorrect(Element element, String attrName, String attrValue)
{
- Attribute attr = element.attribute(attrName);
- if (attr != null && attrValue.equals(attr.getValue())) {
- return attrValue.equals(attr.getValue());
- }
- return false;
- }
-
- public static Document getDocument(ConsoleConfiguration consoleConfiguration,
java.io.File configXMLFile) {
- Document doc = null;
- if (consoleConfiguration != null && configXMLFile != null) {
- InputStream stream = null;
- try {
- stream = new FileInputStream( configXMLFile );
- } catch (FileNotFoundException e) {
- ViewPlugin.getDefault().logError("Configuration file not found", e);
- }
- try {
- List errors = new ArrayList();
- doc = helper.createSAXReader( configXMLFile.getPath(), errors,
consoleConfiguration.getConfiguration().getEntityResolver() )
- .read( new InputSource( stream ) );
- if ( errors.size() != 0 ) {
- ViewPlugin.getDefault().logError("invalid configuration");
- }
- }
- catch (DocumentException e) {
- ViewPlugin.getDefault().logError("Could not parse configuration", e);
- }
- finally {
- try {
- stream.close();
- }
- catch (IOException ioe) {
- ViewPlugin.getDefault().logError("could not close input stream for",
ioe);
- }
- }
- }
- return doc;
- }
-
- public static IResource getResource(ConsoleConfiguration consoleConfiguration,
IJavaProject proj, java.io.File configXMLFile, Object element) {
- Document doc = getDocument(consoleConfiguration, configXMLFile);
- IResource resource = null;
- if (consoleConfiguration != null && proj != null && doc != null) {
- Element sfNode = doc.getRootElement().element(
HTConstants.HIBERNATE_TAG_SESSION_FACTORY );
- Iterator elements = sfNode.elements(HTConstants.HIBERNATE_TAG_MAPPING).iterator();
- while ( elements.hasNext() ) {
- Element subelement = (Element) elements.next();
- Attribute file = subelement.attribute( HTConstants.HIBERNATE_TAG_RESOURCE );
- if (file != null) {
- resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(configXMLFile.getParent()).append(file.getValue()));
- if (elementInResource(consoleConfiguration, resource, element)) return resource;
- }
- }
-
- 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 (OpenFileActionUtils.elementInResource(consoleConfiguration, resource, element))
return resource;
- }
- }
- }
- return null;
- }
-}
Deleted:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenMappingActionDelegate.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * 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.jboss.tools.hibernate.ui.view.views;
-
-import org.dom4j.Document;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.internal.ObjectPluginAction;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.eclipse.console.utils.ProjectUtils;
-import org.hibernate.mapping.RootClass;
-import org.hibernate.util.XMLHelper;
-import org.jboss.tools.hibernate.ui.view.ViewPlugin;
-
-public class OpenMappingActionDelegate extends OpenActionDelegate {
- private static XMLHelper helper = new XMLHelper();
-
- public void run(IAction action) {
- ObjectPluginAction objectPluginAction = (ObjectPluginAction)action;
- RootClass rootClass =
(RootClass)((TreeSelection)objectPluginAction.getSelection()).getFirstElement();
- ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(((TreeSelection)objectPluginAction.getSelection()).getPaths()[0]).getSegment(0);
- IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
- java.io.File configXMLFile = consoleConfiguration.getPreferences().getConfigXMLFile();
- Document doc = OpenFileActionUtils.getDocument(consoleConfiguration, configXMLFile);
-// IResource resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
doc, configXMLFile, rootClass);
- IResource resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, rootClass);
-
- if (resource == null) {
- String fullyQualifiedName = HibernateUtils.getPersistentClassName(rootClass);
- try {
- resource = proj.findType(fullyQualifiedName).getResource();
- } catch (JavaModelException e) {
- ViewPlugin.getDefault().logError("Can't find mapping file.", e);
- }
- }
-
- if (resource != null && resource instanceof IFile){
- try {
- OpenFileActionUtils.openEditor(ViewPlugin.getPage(), (IFile) resource);
- } catch (PartInitException e) {
- ViewPlugin.getDefault().logError("Can't open mapping or source
file.", e);
- }
- }
- }
-}
\ No newline at end of file
Deleted:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java 2007-11-07
15:17:26 UTC (rev 4758)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OpenSourceActionDelegate.java 2007-11-07
17:12:45 UTC (rev 4759)
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * 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.jboss.tools.hibernate.ui.view.views;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.internal.ObjectPluginAction;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.eclipse.console.utils.ProjectUtils;
-import org.hibernate.mapping.RootClass;
-import org.jboss.tools.hibernate.ui.view.ViewPlugin;
-
-public class OpenSourceActionDelegate extends OpenActionDelegate {
-
- public void run(IAction action) {
- ObjectPluginAction objectPluginAction = (ObjectPluginAction)action;
- RootClass rootClass =
(RootClass)((TreeSelection)objectPluginAction.getSelection()).getFirstElement();
- ConsoleConfiguration consoleConfiguration =
(ConsoleConfiguration)(((TreeSelection)objectPluginAction.getSelection()).getPaths()[0]).getSegment(0);
- IJavaProject proj = ProjectUtils.findJavaProject(consoleConfiguration);
-
- IResource resource = null;
- String fullyQualifiedName = HibernateUtils.getPersistentClassName(rootClass);
- try {
- IType type = proj.findType(fullyQualifiedName);
- if (type != null) resource = type.getResource();
- } catch (JavaModelException e) {
- ViewPlugin.getDefault().logError("Can't find source file.", e);
- }
-
- if (resource instanceof IFile){
- try {
- OpenFileActionUtils.openEditor(ViewPlugin.getPage(), (IFile) resource);
- } catch (PartInitException e) {
- ViewPlugin.getDefault().logError("Can't open source file.", e);
- }
- }
- if (resource == null) {
- MessageDialog.openInformation(ViewPlugin.getActiveWorkbenchShell(), "Open Source
File", "Source file for class '" + fullyQualifiedName + "' not
found.");
- }
- }
-}
\ No newline at end of file