Search in sources :

Example 31 with IProperty

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

the class ServiceImplTest method testNewSpecialRootClass.

@Test
public void testNewSpecialRootClass() {
    IProperty property = service.newProperty();
    IPersistentClass pc = service.newRootClass();
    property.setPersistentClass(pc);
    IPersistentClass specialRootClass = service.newSpecialRootClass(property);
    Assert.assertNotNull(specialRootClass);
    Object target = ((IFacade) specialRootClass).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof RootClass);
    Assert.assertSame(property, specialRootClass.getProperty());
}
Also used : RootClass(org.hibernate.mapping.RootClass) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.Test)

Example 32 with IProperty

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

the class PropertyEditPart method createFigure.

protected IFigure createFigure() {
    IProperty property = ((PropertyViewAdapter) getModel()).getProperty();
    String label = property.getName();
    Label propertyLabel = new EditableLabel(label);
    propertyLabel.setIcon(((PropertyViewAdapter) getModel()).getImage());
    return propertyLabel;
}
Also used : EditableLabel(org.hibernate.eclipse.graph.figures.EditableLabel) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) EditableLabel(org.hibernate.eclipse.graph.figures.EditableLabel) Label(org.eclipse.draw2d.Label) PropertyViewAdapter(org.hibernate.eclipse.graph.model.PropertyViewAdapter)

Example 33 with IProperty

use of org.jboss.tools.hibernate.runtime.spi.IProperty 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 34 with IProperty

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

the class OpenSourceAction method run.

/**
 * @param consoleConfig
 * @param selection
 * @param fullyQualifiedName
 * @throws JavaModelException
 * @throws PartInitException
 * @throws FileNotFoundException
 */
public static IEditorPart run(ConsoleConfiguration consoleConfig, Object selection, String fullyQualifiedName) throws JavaModelException, PartInitException, FileNotFoundException {
    if (fullyQualifiedName == null) {
        return null;
    }
    IJavaProject[] projs = ProjectUtils.findJavaProjects(consoleConfig);
    String remainder = null;
    IType type = null;
    IJavaProject proj = null;
    if (fullyQualifiedName.indexOf("$") > 0) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        remainder = fullyQualifiedName.substring(fullyQualifiedName.indexOf("$") + 1);
        // $NON-NLS-1$
        fullyQualifiedName = fullyQualifiedName.substring(0, fullyQualifiedName.indexOf("$"));
        for (int i = 0; i < projs.length && type == null; i++) {
            proj = projs[i];
            type = ProjectUtils.findType(proj, fullyQualifiedName);
        }
        while (remainder.indexOf("$") > 0) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String subtype = remainder.substring(0, fullyQualifiedName.indexOf("$"));
            type = type.getType(subtype);
            // $NON-NLS-1$
            remainder = remainder.substring(fullyQualifiedName.indexOf("$") + 1);
        }
        type = type.getType(remainder);
    } else {
        for (int i = 0; i < projs.length && type == null; i++) {
            proj = projs[i];
            type = ProjectUtils.findType(proj, fullyQualifiedName);
        }
    }
    IJavaElement jElement = null;
    if (selection instanceof IProperty) {
        final String selectionName = ((IProperty) selection).getName();
        final IType typeSave = type;
        while (true) {
            jElement = type.getField(selectionName);
            if (jElement != null && jElement.exists()) {
                break;
            }
            String parentClassName = ProjectUtils.getParentTypename(proj, type.getFullyQualifiedName());
            if (parentClassName == null) {
                break;
            }
            type = ProjectUtils.findType(proj, parentClassName);
            for (int i = 0; i < projs.length && type == null; i++) {
                proj = projs[i];
                type = ProjectUtils.findType(proj, fullyQualifiedName);
            }
            if (type == null) {
                break;
            }
        }
        ;
        // do not find element - restore type
        if (jElement == null || !jElement.exists()) {
            type = typeSave;
        }
    }
    if (jElement == null) {
        jElement = type;
    }
    IEditorPart editorPart = JavaUI.openInEditor(type);
    if (editorPart instanceof JavaEditor) {
        JavaEditor jEditor = (JavaEditor) editorPart;
        selectionToEditor(jElement, jEditor);
    }
    if (editorPart == null) {
        String out = NLS.bind(HibernateConsoleMessages.OpenSourceAction_source_file_for_class_not_found, fullyQualifiedName);
        throw new FileNotFoundException(out);
    }
    return editorPart;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) IType(org.eclipse.jdt.core.IType) JavaEditor(org.eclipse.jdt.internal.ui.javaeditor.JavaEditor)

Example 35 with IProperty

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

the class OpenSourceAction method run.

public void run() {
    IStructuredSelection sel = getStructuredSelection();
    if (!(sel instanceof TreeSelection)) {
        return;
    }
    TreePath[] paths = ((TreeSelection) sel).getPaths();
    for (int i = 0; i < paths.length; i++) {
        TreePath path = paths[i];
        Object lastSegment = path.getLastSegment();
        IPersistentClass persClass = getPersistentClass(lastSegment);
        ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
        String fullyQualifiedName = null;
        if (lastSegment instanceof IProperty) {
            Object prevSegment = path.getParentPath().getLastSegment();
            if (prevSegment instanceof IProperty && ((IProperty) prevSegment).isComposite()) {
                fullyQualifiedName = ((IValue) ((IProperty) prevSegment).getValue()).getComponentClassName();
            }
        }
        if (fullyQualifiedName == null && persClass != null) {
            fullyQualifiedName = persClass.getClassName();
        }
        try {
            run(consoleConfig, lastSegment, fullyQualifiedName);
        } catch (JavaModelException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
        } catch (PartInitException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_open_source_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) FileNotFoundException(java.io.FileNotFoundException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) TreePath(org.eclipse.jface.viewers.TreePath) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) TreeSelection(org.eclipse.jface.viewers.TreeSelection) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)93 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)53 Property (org.hibernate.mapping.Property)40 Test (org.junit.Test)33 RootClass (org.hibernate.mapping.RootClass)27 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)20 PersistentClass (org.hibernate.mapping.PersistentClass)18 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)12 SimpleValue (org.hibernate.mapping.SimpleValue)12 AbstractPropertyFacade (org.jboss.tools.hibernate.runtime.common.AbstractPropertyFacade)12 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)12 FileNotFoundException (java.io.FileNotFoundException)9 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)9 Component (org.hibernate.mapping.Component)8 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)8 IEditorPart (org.eclipse.ui.IEditorPart)7 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)7 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 Mappings (org.hibernate.cfg.Mappings)6 PartInitException (org.eclipse.ui.PartInitException)5