Search in sources :

Example 71 with IPersistentClass

use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.

the class IndexRebuildHandler method execute.

@SuppressWarnings("unchecked")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    if (sel.isEmpty()) {
        return null;
    }
    ITreeSelection selection = (ITreeSelection) sel;
    if (selection.getFirstElement() instanceof ConsoleConfiguration) {
        indexRebuildForConfiguration(selection.iterator());
    }
    if (selection.getFirstElement() instanceof IPersistentClass) {
        indexRebuildForPersistentClass((ConsoleConfiguration) selection.getPaths()[0].getFirstSegment(), selection.iterator());
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ISelection(org.eclipse.jface.viewers.ISelection) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 72 with IPersistentClass

use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.

the class IndexRebuildHandler method indexRebuildForPersistentClass.

@SuppressWarnings("rawtypes")
protected void indexRebuildForPersistentClass(ConsoleConfiguration consoleConfig, Iterator<IPersistentClass> persistClasses) {
    if (!ConsoleConfigurationUtils.loadSessionFactorySafely(consoleConfig)) {
        return;
    }
    ;
    ClassLoader classloader = ConsoleConfigurationUtils.getClassLoader(consoleConfig);
    final Set<Class> classes = new HashSet<Class>();
    try {
        while (persistClasses.hasNext()) {
            IPersistentClass clazz = persistClasses.next();
            classes.add(Class.forName(clazz.getClassName(), true, classloader));
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    run(consoleConfig, classes);
}
Also used : IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HashSet(java.util.HashSet)

Example 73 with IPersistentClass

use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.

the class OpenMappingAction method updateEditorSelection.

/**
 * @param editorPart
 * @param compositeProperty
 * @param parentProperty
 */
public static boolean updateEditorSelection(IEditorPart editorPart, IProperty compositeProperty, IProperty parentProperty, IService service) {
    ITextEditor[] textEditors = OpenMappingUtils.getTextEditors(editorPart);
    if (textEditors.length == 0) {
        return false;
    }
    textEditors[0].selectAndReveal(0, 0);
    FindReplaceDocumentAdapter findAdapter = null;
    ITextEditor textEditor = null;
    for (int i = 0; i < textEditors.length && findAdapter == null; i++) {
        textEditor = textEditors[i];
        findAdapter = OpenMappingUtils.createFindDocAdapter(textEditor);
    }
    if (findAdapter == null) {
        return false;
    }
    IJavaProject proj = ProjectUtils.findJavaProject(editorPart);
    IRegion parentRegion = OpenMappingUtils.findSelectRegion(proj, findAdapter, parentProperty, service);
    if (parentRegion == null) {
        return false;
    }
    int startOffset = parentRegion.getOffset() + parentRegion.getLength();
    IRegion propRegion = null;
    try {
        final String hbmPropertyPattern = OpenMappingUtils.generateHbmPropertyPattern(compositeProperty, service);
        propRegion = findAdapter.find(startOffset, hbmPropertyPattern, true, true, false, true);
        IPersistentClass rootClass = parentProperty.getPersistentClass();
        if (propRegion == null && parentProperty.isComposite() && (parentProperty.equals(rootClass.getIdentifierProperty()) || !rootClass.hasIdentifierProperty())) {
            // try to use key-property
            // $NON-NLS-1$ //$NON-NLS-2$
            String pattern = hbmPropertyPattern.replaceFirst("<property", "<key-property");
            propRegion = findAdapter.find(startOffset, pattern, true, true, false, true);
            if (propRegion == null) {
                // try to use key-many-to-one
                // $NON-NLS-1$ //$NON-NLS-2$
                pattern = hbmPropertyPattern.replaceFirst("<many-to-one", "<key-many-to-one");
                propRegion = findAdapter.find(startOffset, pattern, true, true, false, true);
            }
        }
    } catch (BadLocationException e) {
        HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenMappingAction_selection_not_found, e);
    }
    if (propRegion == null && parentProperty.isComposite()) {
        String[] componentPatterns = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
        OpenMappingUtils.createPattern("embeddable", "class", parentProperty.getValue().getComponentClassName()), OpenMappingUtils.createPattern("embeddable", "class", // $NON-NLS-1$//$NON-NLS-2$
        OpenMappingUtils.getShortClassName(parentProperty.getValue().getComponentClassName())) };
        IRegion componentRegion = null;
        for (int i = 0; i < componentPatterns.length && componentRegion == null; i++) {
            try {
                componentRegion = findAdapter.find(0, componentPatterns[i], true, true, false, true);
            } catch (BadLocationException e) {
            // ignore
            }
        }
        if (componentRegion != null) {
            try {
                propRegion = findAdapter.find(parentRegion.getOffset() + parentRegion.getLength(), OpenMappingUtils.generateOrmEmbeddablePropertyPattern(compositeProperty), true, true, false, true);
            } catch (BadLocationException e) {
            // ignore
            }
        }
    }
    if (propRegion == null) {
        return false;
    }
    int length = compositeProperty.getName().length();
    int offset = propRegion.getOffset() + propRegion.getLength() - length - 1;
    propRegion = new Region(offset, length);
    if (editorPart instanceof MultiPageEditorPart) {
        ((MultiPageEditorPart) editorPart).setActiveEditor(textEditor);
    }
    textEditor.selectAndReveal(propRegion.getOffset(), propRegion.getLength());
    return true;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IJavaProject(org.eclipse.jdt.core.IJavaProject) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 74 with IPersistentClass

use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.

the class OpenMappingAction method run.

/**
 * @param path
 * @param consoleConfig
 * @return
 * @throws PartInitException
 * @throws JavaModelException
 * @throws FileNotFoundException
 */
public static IEditorPart run(ConsoleConfiguration consoleConfig, TreePath path) throws PartInitException, JavaModelException, FileNotFoundException {
    boolean isPropertySel = (path.getLastSegment() instanceof IProperty && ((IProperty) path.getLastSegment()).classIsPropertyClass());
    if (isPropertySel) {
        IProperty propertySel = (IProperty) path.getLastSegment();
        IPersistentClass persClass = propertySel.getPersistentClass();
        if (persClass == null || (persClass.isAssignableToRootClass() && !persClass.isRootClass())) {
            IProperty parentProp = (IProperty) path.getParentPath().getLastSegment();
            return run(consoleConfig, propertySel, parentProp);
        }
    }
    return run(consoleConfig, path.getLastSegment(), null);
}
Also used : IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 75 with IPersistentClass

use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.

the class OpenMappingAction method run.

/**
 * @param consoleConfig
 * @param compositeProperty
 * @param parentProperty
 * @throws JavaModelException
 * @throws PartInitException
 * @throws FileNotFoundException
 * @throws BadLocationException
 */
public static IEditorPart run(ConsoleConfiguration consoleConfig, IProperty compositeProperty, IProperty parentProperty) throws PartInitException, JavaModelException, FileNotFoundException {
    IPersistentClass rootClass = parentProperty.getPersistentClass();
    IFile file = OpenMappingUtils.searchFileToOpen(consoleConfig, rootClass);
    IEditorPart editorPart = null;
    if (file != null) {
        editorPart = OpenMappingUtils.openFileInEditor(file);
        IService service = consoleConfig.getHibernateExtension().getHibernateService();
        updateEditorSelection(editorPart, compositeProperty, parentProperty, service);
    }
    if (editorPart == null && parentProperty.isComposite()) {
        if (OpenMappingUtils.hasConfigXMLMappingClassAnnotation(consoleConfig, rootClass)) {
            String fullyQualifiedName = parentProperty.getValue().getComponentClassName();
            editorPart = OpenSourceAction.run(consoleConfig, compositeProperty, fullyQualifiedName);
        }
    }
    if (editorPart == null) {
        final String title = HibernateConsoleMessages.OpenMappingAction_open_mapping_file;
        final String msg = NLS.bind(HibernateConsoleMessages.OpenMappingAction_mapping_file_for_property_not_found, compositeProperty.getName());
        MessageDialog.openError(null, title, msg);
        throw new FileNotFoundException(msg);
    }
    return editorPart;
}
Also used : IFile(org.eclipse.core.resources.IFile) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Aggregations

IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)175 Test (org.junit.Test)97 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)60 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)51 RootClass (org.hibernate.mapping.RootClass)47 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)46 PersistentClass (org.hibernate.mapping.PersistentClass)43 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)19 AbstractPersistentClassFacade (org.jboss.tools.hibernate.runtime.common.AbstractPersistentClassFacade)16 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)16 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)14 OneToMany (org.hibernate.mapping.OneToMany)12 HashMap (java.util.HashMap)8 Iterator (java.util.Iterator)8 JoinedSubclass (org.hibernate.mapping.JoinedSubclass)8 PrimitiveArray (org.hibernate.mapping.PrimitiveArray)8 Property (org.hibernate.mapping.Property)8 SingleTableSubclass (org.hibernate.mapping.SingleTableSubclass)8 IEditorPart (org.eclipse.ui.IEditorPart)7 PartInitException (org.eclipse.ui.PartInitException)7