Search in sources :

Example 41 with IProperty

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

the class OpenMappingAction method run.

public void run() {
    DiagramEditorInput objectEditorInput = (DiagramEditorInput) ((DiagramViewer) getWorkbenchPart()).getEditorInput();
    ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
    DiagramViewer part = (DiagramViewer) getWorkbenchPart();
    Set<Shape> selectedElements = part.getSelectedElements();
    IEditorPart editorPart = null;
    Iterator<Shape> iterator = selectedElements.iterator();
    // open only first editor - no sense to open all of them
    while (iterator.hasNext() && editorPart == null) {
        Shape shape = iterator.next();
        Object selection = shape.getOrmElement();
        if (selection instanceof IProperty && ((IProperty) selection).getPersistentClass().isInstanceOfSpecialRootClass()) {
            IProperty compositSel = ((IProperty) selection);
            IProperty parentProperty = ((IPersistentClass) compositSel.getPersistentClass()).getProperty();
            try {
                editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, compositSel, parentProperty);
            } catch (CoreException e) {
                HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
            } catch (FileNotFoundException e) {
                HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
            }
            continue;
        }
        if (selection instanceof IPersistentClass && ((IPersistentClass) selection).isInstanceOfSpecialRootClass()) {
            selection = ((IPersistentClass) selection).getProperty();
        }
        Shape shapeParent = null;
        Object selectionParent = null;
        if (selection instanceof IColumn) {
            shapeParent = (Shape) shape.getParent();
            selectionParent = shapeParent.getOrmElement();
        }
        try {
            editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, selection, selectionParent);
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_file, e);
        }
    }
}
Also used : DiagramEditorInput(org.jboss.tools.hibernate.ui.view.DiagramEditorInput) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) CoreException(org.eclipse.core.runtime.CoreException) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn)

Example 42 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() {
    DiagramEditorInput objectEditorInput = (DiagramEditorInput) ((DiagramViewer) getWorkbenchPart()).getEditorInput();
    ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
    DiagramViewer part = (DiagramViewer) getWorkbenchPart();
    Set<Shape> selectedElements = part.getSelectedElements();
    IEditorPart editorPart = null;
    Iterator<Shape> iterator = selectedElements.iterator();
    // open only first editor - no sense to open all of them
    while (iterator.hasNext() && editorPart == null) {
        Shape shape = iterator.next();
        Object selection = shape.getOrmElement();
        if (selection instanceof IColumn || selection instanceof ITable) {
            Iterator<Connection> targetConnections = shape.getTargetConnections().iterator();
            while (targetConnections.hasNext()) {
                Connection connection = targetConnections.next();
                Shape sh1 = connection.getSource();
                Shape sh2 = connection.getTarget();
                if (shape == sh1 && sh2 != null) {
                    shape = sh2;
                    break;
                } else if (shape == sh2 && sh1 != null) {
                    shape = sh1;
                    break;
                }
            }
            selection = shape.getOrmElement();
        }
        IPersistentClass rootClass = null;
        if (selection instanceof IPersistentClass) {
            rootClass = (IPersistentClass) selection;
        } else if (selection instanceof IProperty) {
            rootClass = ((IProperty) selection).getPersistentClass();
        } else {
            continue;
        }
        // HibernateUtils.getPersistentClassName(rootClass);
        String fullyQualifiedName = rootClass.getClassName();
        /*if (fullyQualifiedName.indexOf("$") > 0) {
				fullyQualifiedName = fullyQualifiedName.substring(0, fullyQualifiedName.indexOf("$"));
			}*/
        try {
            editorPart = org.hibernate.eclipse.console.actions.OpenSourceAction.run(consoleConfig, selection, fullyQualifiedName);
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_open_source_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_find_source_file, e);
        }
    }
}
Also used : DiagramEditorInput(org.jboss.tools.hibernate.ui.view.DiagramEditorInput) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) Connection(org.jboss.tools.hibernate.ui.diagram.editors.model.Connection) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) CoreException(org.eclipse.core.runtime.CoreException) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Example 43 with IProperty

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

the class SpecialRootClassFacadeImpl method getMetadataBuildingContext.

private static MetadataBuildingContext getMetadataBuildingContext(IProperty property) {
    Property target = (Property) ((IFacade) property).getTarget();
    PersistentClass pc = target.getPersistentClass();
    MetadataBuildingContext result = null;
    try {
        Field field = PersistentClass.class.getDeclaredField("metadataBuildingContext");
        field.setAccessible(true);
        result = (MetadataBuildingContext) field.get(pc);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException("Problem while trying to retrieve MetadataBuildingContext from field", e);
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 44 with IProperty

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

the class ElementsFactory method createConnections.

@SuppressWarnings("rawtypes")
private boolean createConnections(ExpandableShape persistentClass, ExpandableShape dbTable) {
    boolean res = false;
    if (persistentClass == null || dbTable == null) {
        return res;
    }
    IProperty parentProperty = null;
    if (persistentClass.getOrmElement() instanceof IPersistentClass && ((IPersistentClass) persistentClass.getOrmElement()).isInstanceOfSpecialRootClass()) {
        parentProperty = ((IPersistentClass) persistentClass.getOrmElement()).getParentProperty();
    }
    Iterator<Shape> itFields = persistentClass.getChildrenIterator();
    Set<Shape> processed = new HashSet<Shape>();
    while (itFields.hasNext()) {
        final Shape shape = itFields.next();
        Object element = shape.getOrmElement();
        if (!(element instanceof IProperty && parentProperty != element)) {
            continue;
        }
        IValue value = ((IProperty) element).getValue();
        Iterator iterator = value.getColumnIterator();
        while (iterator.hasNext()) {
            Object o = iterator.next();
            if (!(o instanceof IColumn)) {
                continue;
            }
            IColumn dbColumn = (IColumn) o;
            Iterator<Shape> itColumns = dbTable.getChildrenIterator();
            while (itColumns.hasNext()) {
                final Shape shapeCol = itColumns.next();
                if (processed.contains(shapeCol)) {
                    continue;
                }
                if (shape.equals(shapeCol)) {
                    continue;
                }
                Object ormElement = shapeCol.getOrmElement();
                // $NON-NLS-1$
                String name2 = "";
                if (ormElement instanceof IColumn) {
                    IColumn dbColumn2 = (IColumn) ormElement;
                    name2 = dbColumn2.getName();
                } else if (ormElement instanceof IProperty) {
                    IProperty property2 = (IProperty) ormElement;
                    name2 = property2.getName();
                }
                if (dbColumn.getName().equals(name2)) {
                    if (shouldCreateConnection(shape, shapeCol)) {
                        connections.add(new Connection(shape, shapeCol));
                        res = true;
                    }
                    processed.add(shapeCol);
                }
            }
        }
    }
    return res;
}
Also used : IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 45 with IProperty

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

the class ElementsFactory method getShape.

public OrmShape getShape(Object ormElement) {
    OrmShape ormShape = null;
    if (ormElement instanceof IProperty) {
        IPersistentClass specialRootClass = getService().newSpecialRootClass((IProperty) ormElement);
        ormShape = elements.get(Utils.getName(specialRootClass.getEntityName()));
    } else {
        ormShape = elements.get(Utils.getName(ormElement));
    }
    return ormShape;
}
Also used : IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

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