001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012: import org.eclipse.core.resources.IResource;
013:
014: import org.eclipse.swt.SWT;
015: import org.eclipse.swt.layout.GridData;
016: import org.eclipse.swt.layout.GridLayout;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.swt.widgets.Control;
019: import org.eclipse.swt.widgets.Label;
020:
021: import org.eclipse.jface.dialogs.Dialog;
022:
023: import org.eclipse.ui.PlatformUI;
024: import org.eclipse.ui.dialogs.PropertyPage;
025:
026: import org.eclipse.jdt.core.IClasspathEntry;
027: import org.eclipse.jdt.core.ICompilationUnit;
028: import org.eclipse.jdt.core.IJavaElement;
029: import org.eclipse.jdt.core.IJavaProject;
030: import org.eclipse.jdt.core.IPackageFragment;
031: import org.eclipse.jdt.core.IPackageFragmentRoot;
032: import org.eclipse.jdt.core.JavaModelException;
033:
034: import org.eclipse.jdt.internal.corext.util.Resources;
035:
036: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
037:
038: /**
039: * This is a dummy PropertyPage for JavaElements.
040: * Copied from the ResourceInfoPage
041: */
042: public class JavaElementInfoPage extends PropertyPage {
043:
044: /*
045: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
046: */
047: public void createControl(Composite parent) {
048: super .createControl(parent);
049: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
050: IJavaHelpContextIds.JAVA_ELEMENT_INFO_PAGE);
051: }
052:
053: /*
054: * (non-Javadoc)
055: * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
056: */
057: protected Control createContents(Composite parent) {
058: // ensure the page has no special buttons
059: noDefaultAndApplyButton();
060:
061: IJavaElement element = (IJavaElement) getElement();
062:
063: IResource resource = element.getResource();
064:
065: Composite composite = new Composite(parent, SWT.NONE);
066: GridLayout layout = new GridLayout();
067: layout.numColumns = 2;
068: composite.setLayout(layout);
069: composite.setLayoutData(new GridData(
070: GridData.VERTICAL_ALIGN_FILL
071: | GridData.HORIZONTAL_ALIGN_FILL));
072:
073: Label nameLabel = new Label(composite, SWT.NONE);
074: nameLabel
075: .setText(PreferencesMessages.JavaElementInfoPage_nameLabel);
076:
077: Label nameValueLabel = new Label(composite, SWT.NONE);
078: nameValueLabel.setText(element.getElementName());
079:
080: if (resource != null) {
081: // path label
082: Label pathLabel = new Label(composite, SWT.NONE);
083: pathLabel
084: .setText(PreferencesMessages.JavaElementInfoPage_resource_path);
085:
086: // path value label
087: Label pathValueLabel = new Label(composite, SWT.NONE);
088: pathValueLabel.setText(resource.getFullPath().toString());
089: }
090: if (element instanceof ICompilationUnit) {
091: ICompilationUnit unit = (ICompilationUnit) element;
092: Label packageLabel = new Label(composite, SWT.NONE);
093: packageLabel
094: .setText(PreferencesMessages.JavaElementInfoPage_package);
095: Label packageName = new Label(composite, SWT.NONE);
096: packageName.setText(unit.getParent().getElementName());
097:
098: } else if (element instanceof IPackageFragment) {
099: IPackageFragment packageFragment = (IPackageFragment) element;
100: Label packageContents = new Label(composite, SWT.NONE);
101: packageContents
102: .setText(PreferencesMessages.JavaElementInfoPage_package_contents);
103: Label packageContentsType = new Label(composite, SWT.NONE);
104: try {
105: if (packageFragment.getKind() == IPackageFragmentRoot.K_SOURCE)
106: packageContentsType
107: .setText(PreferencesMessages.JavaElementInfoPage_source);
108: else
109: packageContentsType
110: .setText(PreferencesMessages.JavaElementInfoPage_binary);
111: } catch (JavaModelException e) {
112: packageContentsType
113: .setText(PreferencesMessages.JavaElementInfoPage_not_present);
114: }
115: } else if (element instanceof IPackageFragmentRoot) {
116: Label rootContents = new Label(composite, SWT.NONE);
117: rootContents
118: .setText(PreferencesMessages.JavaElementInfoPage_classpath_entry_kind);
119: Label rootContentsType = new Label(composite, SWT.NONE);
120: try {
121: IClasspathEntry entry = ((IPackageFragmentRoot) element)
122: .getRawClasspathEntry();
123: if (entry != null) {
124: switch (entry.getEntryKind()) {
125: case IClasspathEntry.CPE_SOURCE:
126: rootContentsType
127: .setText(PreferencesMessages.JavaElementInfoPage_source);
128: break;
129: case IClasspathEntry.CPE_PROJECT:
130: rootContentsType
131: .setText(PreferencesMessages.JavaElementInfoPage_project);
132: break;
133: case IClasspathEntry.CPE_LIBRARY:
134: rootContentsType
135: .setText(PreferencesMessages.JavaElementInfoPage_library);
136: break;
137: case IClasspathEntry.CPE_VARIABLE:
138: rootContentsType
139: .setText(PreferencesMessages.JavaElementInfoPage_variable);
140: Label varPath = new Label(composite, SWT.NONE);
141: varPath
142: .setText(PreferencesMessages.JavaElementInfoPage_variable_path);
143: Label varPathVar = new Label(composite,
144: SWT.NONE);
145: varPathVar.setText(entry.getPath()
146: .makeRelative().toString());
147: break;
148: }
149: } else {
150: rootContentsType
151: .setText(PreferencesMessages.JavaElementInfoPage_not_present);
152: }
153: } catch (JavaModelException e) {
154: rootContentsType
155: .setText(PreferencesMessages.JavaElementInfoPage_not_present);
156: }
157: } else if (element instanceof IJavaProject) {
158: Label packageLabel = new Label(composite, SWT.NONE);
159: packageLabel
160: .setText(PreferencesMessages.JavaElementInfoPage_location);
161: String location = Resources
162: .getLocationString(((IJavaProject) element)
163: .getProject());
164: if (location != null) {
165: Label packageName = new Label(composite, SWT.NONE);
166: packageName.setText(location);
167: }
168: }
169: Dialog.applyDialogFont(composite);
170: return composite;
171: }
172:
173: }
|