KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > mapper > extractor > TableNameHandler


1 package org.hibernate.eclipse.mapper.extractor;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
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 JavaDoc;
18 import org.w3c.dom.Node JavaDoc;
19
20 public class TableNameHandler implements HBMInfoHandler {
21
22     
23     public ICompletionProposal[] attributeCompletionProposals(
24             IJavaProject javaProject, Node JavaDoc node, String JavaDoc attributeName,
25             String JavaDoc start, int offset) {
26
27         List JavaDoc tables = new ArrayList JavaDoc();
28         
29         try {
30             if(javaProject.getProject().hasNature(HibernateNature.ID)) {
31                 HibernateNature nature = (HibernateNature) javaProject.getProject().getNature(HibernateNature.ID);
32                 Iterator JavaDoc 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 JavaDoc proposals = new ArrayList JavaDoc();
45         for (Iterator JavaDoc 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 JavaDoc currentNode,
54             Attr JavaDoc currentAttrNode) {
55         return null;
56     }
57
58 }
59
Popular Tags