1 package org.hibernate.eclipse.mapper.extractor; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 import org.eclipse.core.runtime.CoreException; 8 import org.eclipse.jdt.core.IJavaElement; 9 import org.eclipse.jdt.core.IJavaProject; 10 import org.eclipse.jface.text.contentassist.CompletionProposal; 11 import org.eclipse.jface.text.contentassist.ICompletionProposal; 12 import org.hibernate.cfg.Configuration; 13 import org.hibernate.console.ConsoleConfiguration; 14 import org.hibernate.eclipse.console.HibernateConsolePlugin; 15 import org.hibernate.eclipse.nature.HibernateNature; 16 import org.hibernate.mapping.Table; 17 import org.w3c.dom.Attr ; 18 import org.w3c.dom.Node ; 19 20 public class TableNameHandler implements HBMInfoHandler { 21 22 23 public ICompletionProposal[] attributeCompletionProposals( 24 IJavaProject javaProject, Node node, String attributeName, 25 String start, int offset) { 26 27 List tables = new ArrayList (); 28 29 try { 30 if(javaProject.getProject().hasNature(HibernateNature.ID)) { 31 HibernateNature nature = (HibernateNature) javaProject.getProject().getNature(HibernateNature.ID); 32 Iterator tableMappings = nature.getTables().iterator(); 33 while (tableMappings.hasNext()) { 34 Table table = (Table) tableMappings.next(); 35 if(table.getName().startsWith(start)) { 36 tables.add(table); 37 } 38 } 39 } 40 } catch (CoreException e) { 41 HibernateConsolePlugin.getDefault().logErrorMessage("Error while fetching table completions", e); 42 } 43 44 List proposals = new ArrayList (); 45 for (Iterator iter = tables.iterator(); iter.hasNext();) { 46 Table element = (Table) iter.next(); 47 proposals.add(new CompletionProposal(element.getName(), offset, start.length(), element.getName().length(), null, null, null, null)); 48 } 49 50 return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); 51 } 52 53 public IJavaElement getJavaElement(IJavaProject project, Node currentNode, 54 Attr currentAttrNode) { 55 return null; 56 } 57 58 } 59 | Popular Tags |