Search in sources :

Example 16 with IPersistentClass

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

the class OpenDiagramActionDelegate method run.

public void run(IAction action) {
    ObjectPluginAction objectPluginAction = (ObjectPluginAction) action;
    Map<ConsoleConfiguration, Set<IPersistentClass>> mapCC_PCs = new HashMap<ConsoleConfiguration, Set<IPersistentClass>>();
    TreePath[] paths = ((TreeSelection) objectPluginAction.getSelection()).getPaths();
    for (int i = 0; i < paths.length; i++) {
        final Object firstSegment = paths[i].getFirstSegment();
        if (!(firstSegment instanceof ConsoleConfiguration)) {
            continue;
        }
        final ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (firstSegment);
        Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfig);
        if (null == setPC) {
            setPC = new HashSet<IPersistentClass>();
            mapCC_PCs.put(consoleConfig, setPC);
        }
        Object last_el = paths[i].getLastSegment();
        if (last_el instanceof IPersistentClass) {
            IPersistentClass persClass = (IPersistentClass) last_el;
            setPC.add(persClass);
        } else if (last_el instanceof IConfiguration) {
            IConfiguration config = (IConfiguration) last_el;
            Iterator<IPersistentClass> it = config.getClassMappings();
            while (it.hasNext()) {
                setPC.add(it.next());
            }
        } else if (last_el instanceof ConsoleConfiguration) {
            IConfiguration config = consoleConfig.getConfiguration();
            if (config == null) {
                try {
                    consoleConfig.build();
                } catch (Exception he) {
                    HibernateConsolePlugin.getDefault().showError(HibernateConsolePlugin.getShell(), DiagramViewerMessages.OpenDiagramActionDelegate_could_not_load_configuration + ' ' + consoleConfig.getName(), he);
                }
                if (consoleConfig.hasConfiguration()) {
                    consoleConfig.buildMappings();
                }
                config = consoleConfig.getConfiguration();
            }
            if (config != null) {
                Iterator<IPersistentClass> it = config.getClassMappings();
                while (it.hasNext()) {
                    setPC.add(it.next());
                }
            }
        }
    }
    for (Iterator<ConsoleConfiguration> it = mapCC_PCs.keySet().iterator(); it.hasNext(); ) {
        ConsoleConfiguration consoleConfiguration = it.next();
        Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfiguration);
        try {
            openEditor(setPC, consoleConfiguration);
        } catch (PartInitException e) {
            // $NON-NLS-1$
            HibernateConsolePlugin.getDefault().logErrorMessage("Can't open mapping view.", e);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PartInitException(org.eclipse.ui.PartInitException) ObjectPluginAction(org.eclipse.ui.internal.ObjectPluginAction) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) PartInitException(org.eclipse.ui.PartInitException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 17 with IPersistentClass

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

the class OrmImageMap method getImageName.

/**
 * the image name for hierarchy:
 * Property
 * @param field
 * @return
 */
public static String getImageName(IProperty field, final ConsoleConfiguration cfg) {
    // $NON-NLS-1$
    String str = "Image_PersistentFieldSimple";
    if (field == null) {
        return str;
    }
    final IPersistentClass persistentClass = field.getPersistentClass();
    if (persistentClass != null && persistentClass.getVersion() == field) {
        // $NON-NLS-1$
        str = "Image_PersistentFieldSimple_version";
    } else if (persistentClass != null && persistentClass.getIdentifierProperty() == field) {
        // $NON-NLS-1$
        str = "Image_PersistentFieldSimple_id";
    } else if (field.getValue() != null) {
        final IValue value = field.getValue();
        if (value.isOneToMany()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldOne-to-many";
        } else if (value.isOneToOne()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldOne-to-one";
        } else if (value.isManyToOne()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldMany-to-one";
        } else if (value.isAny()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldAny";
        } else {
            IType type = UtilTypeExtract.getTypeUsingExecContext(value, cfg);
            if (type != null && type.isCollectionType()) {
                if (value.isPrimitiveArray()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_primitive_array";
                } else if (value.isArray()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_array";
                } else if (value.isList()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_list";
                } else if (value.isSet()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_set";
                } else if (value.isMap()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_map";
                } else if (value.isBag()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_bag";
                } else if (value.isIdentifierBag()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_idbag";
                } else {
                    // $NON-NLS-1$
                    str = "Image_Collection";
                }
            }
        }
    } else if ("parent".equals(field.getName())) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        str = "Image_PersistentFieldParent";
    }
    return str;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IType(org.jboss.tools.hibernate.runtime.spi.IType)

Example 18 with IPersistentClass

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

the class ShapeEditPart method getSelectionColor.

protected Color getSelectionColor() {
    Color result = ResourceManager.getInstance().getColor(new RGB(255, 0, 0));
    final Object el = getElement();
    if (el instanceof IPersistentClass || el instanceof IProperty) {
        result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
    } else if (el instanceof IValue) {
        IValue value = (IValue) el;
        if (value.isSimpleValue() || value.isOneToMany()) {
            result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
        }
    } else if (el instanceof ITable || el instanceof IColumn) {
        result = ResourceManager.getInstance().getColor(new RGB(66, 173, 247));
    }
    return result;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Color(org.eclipse.swt.graphics.Color) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) RGB(org.eclipse.swt.graphics.RGB) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 19 with IPersistentClass

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

the class HbmExporterTest method testList.

public void testList() {
    // $NON-NLS-1$
    IConfiguration config = getConfigurationFor("pack.A");
    // $NON-NLS-1$ //$NON-NLS-2$
    checkClassesMaped(config, "pack.A", "pack.B");
    // $NON-NLS-1$
    IPersistentClass a = config.getClassMapping("pack.A");
    // $NON-NLS-1$
    IPersistentClass b = config.getClassMapping("pack.B");
    // $NON-NLS-1$
    IProperty listProp = a.getProperty("list");
    assertNotNull(listProp.getValue());
    IValue value = listProp.getValue();
    assertTrue("Expected to get List-type mapping", value.isList());
    assertTrue(value.getCollectionElement().isOneToMany());
    assertTrue(value.getCollectionTable().equals(b.getTable()));
    assertNotNull(value.getIndex());
    assertNotNull(value.getKey());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 20 with IPersistentClass

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

the class HbmExporterTest method testMap.

public void testMap() {
    // $NON-NLS-1$
    IConfiguration config = getConfigurationFor("pack.A");
    // $NON-NLS-1$ //$NON-NLS-2$
    checkClassesMaped(config, "pack.A", "pack.B");
    // $NON-NLS-1$
    IPersistentClass a = config.getClassMapping("pack.A");
    // $NON-NLS-1$
    IPersistentClass b = config.getClassMapping("pack.B");
    // $NON-NLS-1$
    IProperty mapValue = a.getProperty("mapValue");
    assertNotNull(mapValue.getValue());
    IValue value = mapValue.getValue();
    assertTrue("Expected to get Map-type mapping", value.isMap());
    assertTrue(value.getCollectionElement().isOneToMany());
    assertTrue(value.getCollectionTable().equals(b.getTable()));
    assertNotNull(value.getKey());
    // $NON-NLS-1$
    assertEquals("string", value.getKey().getType().getName());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

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