1 4 package org.terracotta.dso.views; 5 6 import org.eclipse.core.resources.IProject; 7 import org.eclipse.jdt.core.IField; 8 import org.eclipse.jdt.core.IJavaElement; 9 import org.eclipse.jdt.core.IJavaProject; 10 import org.eclipse.jdt.core.IMember; 11 import org.eclipse.jdt.core.JavaModelException; 12 import org.eclipse.jdt.internal.ui.JavaPlugin; 13 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; 14 import org.eclipse.jdt.ui.JavaUI; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.viewers.StructuredSelection; 18 import org.eclipse.ui.IEditorPart; 19 import org.eclipse.ui.PartInitException; 20 import org.terracotta.dso.ConfigurationHelper; 21 import org.terracotta.dso.TcPlugin; 22 import org.terracotta.dso.actions.ActionUtil; 23 24 import com.terracottatech.config.Root; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 public class ConfigUI { 31 static ISelection convertSelection(ISelection selection) { 32 if (selection.isEmpty()) { 33 return selection; 34 } 35 36 IJavaProject javaProject = ActionUtil.locateSelectedJavaProject(selection); 37 IProject project = (javaProject != null) ? javaProject.getProject() : null; 38 39 if (project != null && selection instanceof IStructuredSelection) { 40 IStructuredSelection structuredSelection= (IStructuredSelection) selection; 41 List <IJavaElement> javaElements= new ArrayList <IJavaElement>(); 42 for (Iterator iter= structuredSelection.iterator(); iter.hasNext();) { 43 Object element= iter.next(); 44 if (element instanceof Root) { 45 String rootField= ((Root)element).getFieldName(); 46 if (rootField != null) { 47 TcPlugin plugin = TcPlugin.getDefault(); 48 ConfigurationHelper configHelper = plugin.getConfigurationHelper(project); 49 IField field = configHelper.getField(rootField); 50 if(field != null) { 51 javaElements.add(field); 52 } 53 } 54 } else if (element instanceof IMember) { 55 javaElements.add((IMember)element); 56 } 57 } 58 return new StructuredSelection(javaElements); 59 } 60 return StructuredSelection.EMPTY; 61 } 62 63 public static void jumpToMember(IJavaElement element) { 64 if (element != null) { 65 try { 66 IEditorPart editor = EditorUtility.openInEditor(element, false); 67 JavaUI.revealInEditor(editor, element); 68 } catch (JavaModelException e) { 69 JavaPlugin.log(e); 70 } catch (PartInitException e) { 71 JavaPlugin.log(e); 72 } 73 } 74 } 75 } 76 | Popular Tags |