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.IProject;
013: import org.eclipse.core.resources.IResource;
014: import org.eclipse.core.runtime.IAdaptable;
015:
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.SWTException;
018: import org.eclipse.swt.widgets.Composite;
019: import org.eclipse.swt.widgets.Control;
020:
021: import org.eclipse.jface.dialogs.Dialog;
022: import org.eclipse.jface.preference.IPreferencePageContainer;
023: import org.eclipse.jface.preference.PreferenceDialog;
024:
025: import org.eclipse.ui.dialogs.PropertyPage;
026: import org.eclipse.ui.forms.events.HyperlinkAdapter;
027: import org.eclipse.ui.forms.events.HyperlinkEvent;
028: import org.eclipse.ui.forms.widgets.FormText;
029: import org.eclipse.ui.forms.widgets.FormToolkit;
030: import org.eclipse.ui.forms.widgets.TableWrapData;
031: import org.eclipse.ui.forms.widgets.TableWrapLayout;
032:
033: import org.eclipse.jdt.internal.corext.util.Messages;
034:
035: /**
036: * Top level node for Java property pages
037: */
038: public class JavaCategoryPropertyPage extends PropertyPage {
039:
040: private IProject fProject;
041:
042: private final static String HREF_BUILDPATH = BuildPathsPropertyPage.PROP_ID;
043: private final static String HREF_COMPILER = CompliancePreferencePage.PROP_ID;
044: private final static String HREF_CODESTYLE = CodeStylePreferencePage.PROP_ID;
045: private final static String HREF_JLOC = JavadocConfigurationPropertyPage.PROP_ID;
046: private final static String HREF_TODO = TodoTaskPreferencePage.PROP_ID;
047: private final static String HREF_PSEVERITIES = ProblemSeveritiesPreferencePage.PROP_ID;
048: private final static String HREF_JAVADOC = JavadocProblemsPreferencePage.PROP_ID;
049: private final static String HREF_FORMATTER = CodeFormatterPreferencePage.PROP_ID;
050: private final static String HREF_TEMPLATES = ""; // Code //$NON-NLS-1$
051: private final static String HREF_IMPORTORDER = ImportOrganizePreferencePage.PROP_ID;
052: private final static String HREF_BUILDING = JavaBuildPreferencePage.PROP_ID;
053:
054: /*
055: * @see PreferencePage#createControl(Composite)
056: */
057: protected Control createContents(Composite parent) {
058: Composite composite = new Composite(parent, SWT.NONE);
059: composite.setLayout(new TableWrapLayout());
060:
061: FormToolkit toolkit = new FormToolkit(parent.getDisplay());
062: try {
063: String[] args = { fProject.getName(), HREF_BUILDPATH,
064: HREF_COMPILER, HREF_TODO, HREF_PSEVERITIES,
065: HREF_JAVADOC, HREF_BUILDING, HREF_CODESTYLE,
066: HREF_FORMATTER, HREF_TEMPLATES, HREF_IMPORTORDER,
067: HREF_JLOC };
068: String msg = Messages.format(
069: PreferencesMessages.JavaCategoryPropertyPage_text,
070: args);
071:
072: FormText formText = toolkit.createFormText(composite, true);
073: try {
074: formText.setText(msg, true, false);
075: } catch (SWTException e) {
076: formText.setText(e.getMessage(), false, false);
077: }
078:
079: formText.setBackground(null);
080: formText.setLayoutData(new TableWrapData(
081: TableWrapData.FILL_GRAB));
082: formText.addHyperlinkListener(new HyperlinkAdapter() {
083: public void linkActivated(HyperlinkEvent e) {
084: doLinkActivated(e.data.toString());
085: }
086: });
087: } finally {
088: toolkit.dispose();
089: }
090:
091: Dialog.applyDialogFont(composite);
092: return composite;
093: }
094:
095: protected void doLinkActivated(String string) {
096: if (string.length() > 0) {
097: IPreferencePageContainer container = getContainer();
098: if (container instanceof PreferenceDialog) {
099: //see bug 80689: ((PreferenceDialog) container).setCurrentPageId(string);
100: }
101: }
102: }
103:
104: /* (non-Javadoc)
105: * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
106: */
107: public IAdaptable getElement() {
108: return fProject;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
113: */
114: public void setElement(IAdaptable element) {
115: fProject = (IProject) element.getAdapter(IResource.class);
116: }
117:
118: }
|