1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import org.eclipse.core.resources.IResource; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.layout.GridData; 17 import org.eclipse.swt.layout.GridLayout; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Label; 21 22 import org.eclipse.jface.dialogs.Dialog; 23 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.dialogs.PropertyPage; 26 27 import org.eclipse.jdt.core.IClasspathEntry; 28 import org.eclipse.jdt.core.ICompilationUnit; 29 import org.eclipse.jdt.core.IJavaElement; 30 import org.eclipse.jdt.core.IJavaProject; 31 import org.eclipse.jdt.core.IPackageFragment; 32 import org.eclipse.jdt.core.IPackageFragmentRoot; 33 import org.eclipse.jdt.core.JavaModelException; 34 35 import org.eclipse.jdt.internal.corext.util.Resources; 36 37 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 38 39 40 44 public class JavaElementInfoPage extends PropertyPage { 45 46 49 public void createControl(Composite parent) { 50 super.createControl(parent); 51 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.JAVA_ELEMENT_INFO_PAGE); 52 } 53 54 58 protected Control createContents(Composite parent) { 59 noDefaultAndApplyButton(); 61 62 IJavaElement element= (IJavaElement)getElement(); 63 64 IResource resource= element.getResource(); 65 66 Composite composite= new Composite(parent, SWT.NONE); 67 GridLayout layout= new GridLayout(); 68 layout.numColumns= 2; 69 composite.setLayout(layout); 70 composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); 71 72 Label nameLabel= new Label(composite, SWT.NONE); 73 nameLabel.setText(PreferencesMessages.JavaElementInfoPage_nameLabel); 74 75 Label nameValueLabel= new Label(composite, SWT.NONE); 76 nameValueLabel.setText(element.getElementName()); 77 78 if (resource != null) { 79 Label pathLabel= new Label(composite, SWT.NONE); 81 pathLabel.setText(PreferencesMessages.JavaElementInfoPage_resource_path); 82 83 Label pathValueLabel= new Label(composite, SWT.NONE); 85 pathValueLabel.setText(resource.getFullPath().toString()); 86 } 87 if (element instanceof ICompilationUnit) { 88 ICompilationUnit unit= (ICompilationUnit)element; 89 Label packageLabel= new Label(composite, SWT.NONE); 90 packageLabel.setText(PreferencesMessages.JavaElementInfoPage_package); 91 Label packageName= new Label(composite, SWT.NONE); 92 packageName.setText(unit.getParent().getElementName()); 93 94 } else if (element instanceof IPackageFragment) { 95 IPackageFragment packageFragment= (IPackageFragment)element; 96 Label packageContents= new Label(composite, SWT.NONE); 97 packageContents.setText(PreferencesMessages.JavaElementInfoPage_package_contents); 98 Label packageContentsType= new Label(composite, SWT.NONE); 99 try { 100 if (packageFragment.getKind() == IPackageFragmentRoot.K_SOURCE) 101 packageContentsType.setText(PreferencesMessages.JavaElementInfoPage_source); 102 else 103 packageContentsType.setText(PreferencesMessages.JavaElementInfoPage_binary); 104 } catch (JavaModelException e) { 105 packageContentsType.setText(PreferencesMessages.JavaElementInfoPage_not_present); 106 } 107 } else if (element instanceof IPackageFragmentRoot) { 108 Label rootContents= new Label(composite, SWT.NONE); 109 rootContents.setText(PreferencesMessages.JavaElementInfoPage_classpath_entry_kind); 110 Label rootContentsType= new Label(composite, SWT.NONE); 111 try { 112 IClasspathEntry entry= ((IPackageFragmentRoot)element).getRawClasspathEntry(); 113 if (entry != null) { 114 switch (entry.getEntryKind()) { 115 case IClasspathEntry.CPE_SOURCE: 116 rootContentsType.setText(PreferencesMessages.JavaElementInfoPage_source); break; 117 case IClasspathEntry.CPE_PROJECT: 118 rootContentsType.setText(PreferencesMessages.JavaElementInfoPage_project); break; 119 case IClasspathEntry.CPE_LIBRARY: 120 rootContentsType.setText(PreferencesMessages.JavaElementInfoPage_library); break; 121 case IClasspathEntry.CPE_VARIABLE: 122 rootContentsType.setText(PreferencesMessages.JavaElementInfoPage_variable); 123 Label varPath= new Label(composite, SWT.NONE); 124 varPath.setText(PreferencesMessages.JavaElementInfoPage_variable_path); 125 Label varPathVar= new Label(composite, SWT.NONE); 126 varPathVar.setText(entry.getPath().makeRelative().toString()); 127 break; 128 } 129 } else { 130 rootContentsType.setText(PreferencesMessages.JavaElementInfoPage_not_present); 131 } 132 } catch (JavaModelException e) { 133 rootContentsType.setText(PreferencesMessages.JavaElementInfoPage_not_present); 134 } 135 } else if (element instanceof IJavaProject) { 136 Label packageLabel= new Label(composite, SWT.NONE); 137 packageLabel.setText(PreferencesMessages.JavaElementInfoPage_location); 138 String location= Resources.getLocationString(((IJavaProject)element).getProject()); 139 if (location != null) { 140 Label packageName= new Label(composite, SWT.NONE); 141 packageName.setText(location); 142 } 143 } 144 Dialog.applyDialogFont(composite); 145 return composite; 146 } 147 148 } 149 | Popular Tags |