1 11 package org.eclipse.jdt.internal.ui.browsing; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.resources.ResourcesPlugin; 16 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.widgets.Composite; 19 20 import org.eclipse.jface.viewers.DoubleClickEvent; 21 import org.eclipse.jface.viewers.IContentProvider; 22 import org.eclipse.jface.viewers.IDoubleClickListener; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.jface.viewers.StructuredSelection; 26 import org.eclipse.jface.viewers.StructuredViewer; 27 import org.eclipse.jface.viewers.TreeViewer; 28 29 import org.eclipse.ui.IPageLayout; 30 import org.eclipse.ui.IWorkbenchPart; 31 import org.eclipse.ui.part.IShowInTargetList; 32 33 import org.eclipse.jdt.core.IJavaElement; 34 import org.eclipse.jdt.core.IJavaModel; 35 import org.eclipse.jdt.core.IJavaProject; 36 import org.eclipse.jdt.core.IPackageFragmentRoot; 37 import org.eclipse.jdt.core.JavaCore; 38 39 import org.eclipse.jdt.ui.JavaUI; 40 import org.eclipse.jdt.ui.PreferenceConstants; 41 import org.eclipse.jdt.ui.actions.ProjectActionGroup; 42 43 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 44 import org.eclipse.jdt.internal.ui.JavaPlugin; 45 import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager; 46 import org.eclipse.jdt.internal.ui.viewsupport.FilterUpdater; 47 import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer; 48 49 public class ProjectsView extends JavaBrowsingPart { 50 51 private FilterUpdater fFilterUpdater; 52 53 56 protected StructuredViewer createViewer(Composite parent) { 57 ProblemTreeViewer result= new ProblemTreeViewer(parent, SWT.MULTI); 58 ColoredViewersManager.install(result); 59 fFilterUpdater= new FilterUpdater(result); 60 ResourcesPlugin.getWorkspace().addResourceChangeListener(fFilterUpdater); 61 return result; 62 } 63 64 67 public void dispose() { 68 if (fFilterUpdater != null) 69 ResourcesPlugin.getWorkspace().removeResourceChangeListener(fFilterUpdater); 70 super.dispose(); 71 } 72 73 76 public Object getAdapter(Class key) { 77 if (key == IShowInTargetList.class) { 78 return new IShowInTargetList() { 79 public String [] getShowInTargetIds() { 80 return new String [] { JavaUI.ID_PACKAGES, IPageLayout.ID_RES_NAV }; 81 } 82 83 }; 84 } 85 return super.getAdapter(key); 86 } 87 88 89 92 protected IContentProvider createContentProvider() { 93 return new ProjectAndSourceFolderContentProvider(this); 94 } 95 96 101 protected String getHelpContextId() { 102 return IJavaHelpContextIds.PROJECTS_VIEW; 103 } 104 105 protected String getLinkToEditorKey() { 106 return PreferenceConstants.LINK_BROWSING_PROJECTS_TO_EDITOR; 107 } 108 109 110 113 protected void hookViewerListeners() { 114 super.hookViewerListeners(); 115 getViewer().addDoubleClickListener(new IDoubleClickListener() { 116 public void doubleClick(DoubleClickEvent event) { 117 TreeViewer viewer= (TreeViewer)getViewer(); 118 Object element= ((IStructuredSelection)event.getSelection()).getFirstElement(); 119 if (viewer.isExpandable(element)) 120 viewer.setExpandedState(element, !viewer.getExpandedState(element)); 121 } 122 }); 123 } 124 125 protected void setInitialInput() { 126 IJavaElement root= JavaCore.create(JavaPlugin.getWorkspace().getRoot()); 127 getViewer().setInput(root); 128 updateTitle(); 129 } 130 131 138 protected boolean isValidInput(Object element) { 139 return element instanceof IJavaModel; 140 } 141 142 149 protected boolean isValidElement(Object element) { 150 return element instanceof IJavaProject || element instanceof IPackageFragmentRoot; 151 } 152 153 159 protected IJavaElement findElementToSelect(IJavaElement je) { 160 if (je == null) 161 return null; 162 163 switch (je.getElementType()) { 164 case IJavaElement.JAVA_MODEL : 165 return null; 166 case IJavaElement.JAVA_PROJECT: 167 return je; 168 case IJavaElement.PACKAGE_FRAGMENT_ROOT: 169 if (je.getElementName().equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) 170 return je.getParent(); 171 else 172 return je; 173 default : 174 return findElementToSelect(je.getParent()); 175 } 176 } 177 178 181 protected void setInput(Object input) { 182 if (input != null) 184 super.setInput(input); 185 else 186 getViewer().setSelection(null); 187 } 188 189 protected void createActions() { 190 super.createActions(); 191 fActionGroups.addGroup(new ProjectActionGroup(this)); 192 } 193 194 200 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 201 if (!needsToProcessSelectionChanged(part, selection)) 202 return; 203 204 if (selection instanceof IStructuredSelection) { 205 IStructuredSelection sel= (IStructuredSelection)selection; 206 Iterator iter= sel.iterator(); 207 while (iter.hasNext()) { 208 Object selectedElement= iter.next(); 209 if (selectedElement instanceof LogicalPackage) { 210 selection= new StructuredSelection(((LogicalPackage)selectedElement).getJavaProject()); 211 break; 212 } 213 } 214 } 215 super.selectionChanged(part, selection); 216 } 217 } 218 | Popular Tags |