Search in sources :

Example 1 with EntityInfo

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

the class ResolveAmbiguous method createControl.

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 1;
    Label label = new Label(container, SWT.NULL);
    label.setText(JdtUiMessages.ResolveAmbiguous_message);
    table = new Table(container, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    createTableColumns(table);
    TableItem ti = null;
    Iterator<Map.Entry<String, EntityInfo>> it = data.getEntities().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, EntityInfo> entry = it.next();
        if (entry.getValue().isAbstractFlag()) {
            continue;
        }
        // collectModification(bufferManager, entry.getKey(), entry.getValue());
        Iterator<Map.Entry<String, RefEntityInfo>> referencesIt = entry.getValue().getReferences().entrySet().iterator();
        while (referencesIt.hasNext()) {
            Map.Entry<String, RefEntityInfo> entryRef = referencesIt.next();
            RefEntityInfo rei = entryRef.getValue();
            ti = new TableItem(table, SWT.NONE);
            ti.setData(rei);
            ti.setText(COLUMN_CLASS, entry.getKey());
            String shortName = getShortName(rei.fullyQualifiedName);
            // $NON-NLS-1$
            ti.setText(COLUMN_PROPERTY, shortName + " " + entryRef.getKey());
            ti.setText(COLUMN_TYPE, Utils.refTypeToStr(rei.refType));
            if (null != rei.mappedBy) {
                ti.setText(COLUMN_RELATED, rei.mappedBy);
            } else {
                ti.setText(COLUMN_RELATED, JdtUiMessages.ResolveAmbiguous_empty);
            }
            ti.setText(COLUMN_OWNER, Utils.ownerTypeToStr(rei.owner));
        }
    }
    // 
    editorType = new TableEditor(table);
    // The editor must have the same size as the cell and must
    // not be any smaller than 50 pixels.
    editorType.horizontalAlignment = SWT.LEFT;
    editorType.grabHorizontal = true;
    editorType.minimumWidth = 50;
    // 
    editorRel = new TableEditor(table);
    // The editor must have the same size as the cell and must
    // not be any smaller than 50 pixels.
    editorRel.horizontalAlignment = SWT.LEFT;
    editorRel.grabHorizontal = true;
    editorRel.minimumWidth = 50;
    // 
    editorOwner = new TableEditor(table);
    // The editor must have the same size as the cell and must
    // not be any smaller than 50 pixels.
    editorOwner.horizontalAlignment = SWT.LEFT;
    editorOwner.grabHorizontal = true;
    editorOwner.minimumWidth = 50;
    // editing the second column
    table.addSelectionListener(new TableSelectionListener());
    GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    data.heightHint = convertHeightInCharsToPixels(10);
    table.setLayoutData(data);
    setControl(container);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) TableEditor(org.eclipse.swt.custom.TableEditor) RefEntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo) GridLayout(org.eclipse.swt.layout.GridLayout) RefEntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) GridData(org.eclipse.swt.layout.GridData) Map(java.util.Map)

Example 2 with EntityInfo

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

the class JPAMapToolActor method updateOpen.

/**
 * update compilation unit of currently opened editor
 * @param depth - process depth
 */
public void updateOpen(int depth) {
    IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return;
    }
    IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
    if (page == null) {
        return;
    }
    IEditorPart editor = page.getActiveEditor();
    if (editor instanceof CompilationUnitEditor) {
        CompilationUnitEditor cue = (CompilationUnitEditor) editor;
        ICompilationUnit cu = (ICompilationUnit) cue.getViewPartInput();
        if (cu != null) {
            addCompilationUnit(cu);
            collector.initCollector();
            collector.collect(cu, depth);
            collector.resolveRelations();
            if (collector.getNonInterfaceCUNumber() > 0) {
                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);
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CompilationUnitEditor(org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with EntityInfo

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

the class AllEntitiesInfoCollector method collect.

/**
 * start to collect information from particular entity class and
 * its dependencies
 * @param icu - startup point entity compilation unit
 * @param depth - process depth
 */
public void collect(ICompilationUnit icu, int depth) {
    if (icu == null || depth < 0) {
        return;
    }
    org.eclipse.jdt.core.dom.CompilationUnit cu = Utils.getCompilationUnit(icu, true);
    if (cu == null) {
        return;
    }
    if (cu.types() == null || cu.types().size() == 0) {
        return;
    }
    boolean hasTypeDeclaration = false;
    Iterator<?> it = cu.types().iterator();
    while (it.hasNext()) {
        Object tmp = it.next();
        if (tmp instanceof TypeDeclaration) {
            hasTypeDeclaration = true;
            break;
        }
    }
    if (!hasTypeDeclaration) {
        // ignore EnumDeclaration & AnnotationTypeDeclaration
        return;
    }
    IJavaProject javaProject = icu.getJavaProject();
    // $NON-NLS-1$
    String projectName = (javaProject != null) ? javaProject.getProject().getName() : "";
    ArrayList<String> fullyQualifiedNames = new ArrayList<String>();
    // TODO: should inspect all types in cu? so next method to get fullyQualifiedName:
    if (cu.getTypeRoot() == null || cu.getTypeRoot().findPrimaryType() == null) {
        it = cu.types().iterator();
        while (it.hasNext()) {
            Object tmp = it.next();
            if (tmp instanceof TypeDeclaration) {
                fullyQualifiedNames.add(((TypeDeclaration) tmp).resolveBinding().getBinaryName());
            }
        }
    } else {
        fullyQualifiedNames.add(cu.getTypeRoot().findPrimaryType().getFullyQualifiedName());
    }
    Iterator<String> itFQNames = fullyQualifiedNames.iterator();
    while (itFQNames.hasNext()) {
        String fullyQualifiedName = itFQNames.next();
        if (!mapCUs_Info.containsKey(projectName + "/" + fullyQualifiedName)) {
            // $NON-NLS-1$
            CollectEntityInfo finder = new CollectEntityInfo(fullyQualifiedName);
            cu.accept(finder);
            EntityInfo result = finder.getEntityInfo();
            if (result != null) {
                result.adjustParameters();
                result.setJavaProjectName(projectName);
                // $NON-NLS-1$
                mapCUs_Info.put(projectName + "/" + fullyQualifiedName, result);
                if (depth > 0) {
                    Iterator<String> itDep = result.getDependences();
                    while (itDep.hasNext()) {
                        String fullyQualifiedNameTmp = itDep.next();
                        collect(fullyQualifiedNameTmp, projectName, depth - 1);
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IJavaProject(org.eclipse.jdt.core.IJavaProject) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) RefEntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration)

Example 4 with EntityInfo

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

the class AllEntitiesInfoCollector method getNonAbstractCUNumber.

public int getNonAbstractCUNumber() {
    Iterator<Map.Entry<String, EntityInfo>> it = null;
    int nonAbstractCUNumber = 0;
    // generate RefFieldInfoMap (for simple process)
    it = mapCUs_Info.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, EntityInfo> entry = it.next();
        EntityInfo entryInfo = entry.getValue();
        if (!entryInfo.isAbstractFlag()) {
            nonAbstractCUNumber++;
        }
    }
    return nonAbstractCUNumber;
}
Also used : EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) RefEntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 5 with EntityInfo

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

the class AllEntitiesInfoCollector method getNonInterfaceCUNumber.

public int getNonInterfaceCUNumber() {
    Iterator<Map.Entry<String, EntityInfo>> it = null;
    int nonInterfaceCUNumber = 0;
    // generate RefFieldInfoMap (for simple process)
    it = mapCUs_Info.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, EntityInfo> entry = it.next();
        EntityInfo entryInfo = entry.getValue();
        if (!entryInfo.isInterfaceFlag()) {
            nonInterfaceCUNumber++;
        }
    }
    return nonInterfaceCUNumber;
}
Also used : EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) RefEntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo) TreeMap(java.util.TreeMap) Map(java.util.Map)

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