Search in sources :

Example 11 with EntityInfo

use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo in project jbosstools-hibernate by jbosstools.

the class TypeVisitor method createConfiguration.

protected IConfiguration createConfiguration(IJavaProject project, Map<String, EntityInfo> entities) {
    IConfiguration result = null;
    IService service = getService(project);
    if (service != null) {
        result = service.newDefaultConfiguration();
        ProcessEntityInfo processor = new ProcessEntityInfo(service);
        processor.setEntities(entities);
        for (Entry<String, EntityInfo> entry : entities.entrySet()) {
            String fullyQualifiedName = entry.getValue().getFullyQualifiedName();
            ICompilationUnit icu = Utils.findCompilationUnit(project, fullyQualifiedName);
            if (icu != null) {
                CompilationUnit cu = Utils.getCompilationUnit(icu, true);
                processor.setEntityInfo(entry.getValue());
                cu.accept(processor);
            }
        }
        Collection<IPersistentClass> classesCollection = createHierarhyStructure(project, processor.getRootClasses());
        for (IPersistentClass persistentClass : classesCollection) {
            result.addClass(persistentClass);
        }
    }
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefEntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IService(org.jboss.tools.hibernate.runtime.spi.IService) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 12 with EntityInfo

use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo in project jbosstools-hibernate by jbosstools.

the class NewHibernateMappingFileWizard method initEntitiesInfo.

protected void initEntitiesInfo() {
    if (selectionCU.size() == 0) {
        return;
    }
    AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
    Iterator<ICompilationUnit> it = selectionCU.iterator();
    Map<IJavaProject, Set<ICompilationUnit>> mapJP_CUSet = new HashMap<IJavaProject, Set<ICompilationUnit>>();
    // separate by parent project
    while (it.hasNext()) {
        ICompilationUnit cu = it.next();
        Set<ICompilationUnit> set = mapJP_CUSet.get(cu.getJavaProject());
        if (set == null) {
            set = new HashSet<ICompilationUnit>();
            mapJP_CUSet.put(cu.getJavaProject(), set);
        }
        set.add(cu);
    }
    Iterator<Map.Entry<IJavaProject, Set<ICompilationUnit>>> mapIt = mapJP_CUSet.entrySet().iterator();
    while (mapIt.hasNext()) {
        Map.Entry<IJavaProject, Set<ICompilationUnit>> entry = mapIt.next();
        IJavaProject javaProject = entry.getKey();
        Iterator<ICompilationUnit> setIt = entry.getValue().iterator();
        collector.initCollector();
        while (setIt.hasNext()) {
            ICompilationUnit icu = setIt.next();
            collector.collect(icu, processDepth);
        }
        collector.resolveRelations();
        Collection<EntityInfo> c = new ArrayList<EntityInfo>();
        for (Iterator<EntityInfo> i = collector.getMapCUs_Info().values().iterator(); i.hasNext(); ) {
            c.add(i.next());
        }
        project_infos.put(javaProject, c);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) IJavaProject(org.eclipse.jdt.core.IJavaProject) AllEntitiesInfoCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with EntityInfo

use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo in project jbosstools-hibernate by jbosstools.

the class HibernateJPAWizardDataFactory method createHibernateJPAWizardData.

public static IHibernateJPAWizardData createHibernateJPAWizardData(final IStructuredSelection selection2Update, IHibernateJPAWizardParams params, int depth) {
    CompilationUnitCollector compileUnitCollector = new CompilationUnitCollector();
    @SuppressWarnings("rawtypes") Iterator itSelection2Update = selection2Update.iterator();
    while (itSelection2Update.hasNext()) {
        Object obj = itSelection2Update.next();
        compileUnitCollector.processJavaElements(obj, true);
    }
    Iterator<ICompilationUnit> it = compileUnitCollector.setSelectionCUIterator();
    AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
    collector.initCollector();
    while (it.hasNext()) {
        ICompilationUnit cu = it.next();
        collector.collect(cu, depth);
    }
    collector.resolveRelations();
    final Map<String, EntityInfo> entities = collector.getMapCUs_Info();
    params.performDisconnect();
    params.reCollectModification(entities);
    final ArrayList<ChangeStructure> changes = params.getChanges();
    IHibernateJPAWizardData data = new IHibernateJPAWizardData() {

        public Map<String, EntityInfo> getEntities() {
            return entities;
        }

        public ArrayList<ChangeStructure> getChanges() {
            return changes;
        }

        public IStructuredSelection getSelection2Update() {
            return selection2Update;
        }
    };
    return data;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnitCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.CompilationUnitCollector) ChangeStructure(org.hibernate.eclipse.jdt.ui.internal.jpa.process.ChangeStructure) AllEntitiesInfoCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) Iterator(java.util.Iterator)

Example 14 with EntityInfo

use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo in project jbosstools-hibernate by jbosstools.

the class JPAMapToolActor method updateSelected.

/**
 * updates selected compilation units collection
 * @param depth - process depth
 */
public void updateSelected(int depth) {
    if (selection != null) {
        updateSelectedItems(selection);
        selection = null;
    } else {
        if (getSelectionCUSize() == 0) {
            updateOpen(depth);
            return;
        }
    }
    if (getSelectionCUSize() == 0) {
        Map<String, EntityInfo> mapCUs_Info = new HashMap<String, EntityInfo>();
        IStructuredSelection selection2Update = createSelection2Update();
        processor.modify(mapCUs_Info, true, selection2Update);
        return;
    }
    Iterator<ICompilationUnit> it = compileUnitCollector.setSelectionCUIterator();
    collector.initCollector();
    while (it.hasNext()) {
        ICompilationUnit cu = it.next();
        collector.collect(cu, depth);
    }
    collector.resolveRelations();
    if (collector.getNonInterfaceCUNumber() > 0) {
        processor.setAnnotationStylePreference(collector.getAnnotationStylePreference());
        Map<String, EntityInfo> mapCUs_Info = collector.getMapCUs_Info();
        IStructuredSelection selection2Update = createSelection2Update();
        processor.modify(mapCUs_Info, true, selection2Update);
    } else {
        MessageDialog.openInformation(getShell(), JdtUiMessages.JPAMapToolActor_message_title, JdtUiMessages.JPAMapToolActor_message);
    }
    processor.savePreferences();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HashMap(java.util.HashMap) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 15 with EntityInfo

use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo in project jbosstools-hibernate by jbosstools.

the class AllEntitiesInfoCollector method adjustParentId.

public void adjustParentId(EntityInfo ei) {
    if (ei == null) {
        return;
    }
    // $NON-NLS-1$
    EntityInfo parentEI = mapCUs_Info.get(ei.getJavaProjectName() + "/" + ei.getFullyQualifiedParentName());
    adjustParentId(parentEI);
    ei.adjustPrimaryId(parentEI);
}
Also used : EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) RefEntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo)

Aggregations

EntityInfo (org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo)16 RefEntityInfo (org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo)10 Map (java.util.Map)7 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 HashMap (java.util.HashMap)4 TreeMap (java.util.TreeMap)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 AllEntitiesInfoCollector (org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector)2 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)1