KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > JavaCategoryPropertyPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.preferences;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.IAdaptable;
16
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.SWTException;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.preference.IPreferencePageContainer;
24 import org.eclipse.jface.preference.PreferenceDialog;
25
26 import org.eclipse.ui.dialogs.PropertyPage;
27 import org.eclipse.ui.forms.events.HyperlinkAdapter;
28 import org.eclipse.ui.forms.events.HyperlinkEvent;
29 import org.eclipse.ui.forms.widgets.FormText;
30 import org.eclipse.ui.forms.widgets.FormToolkit;
31 import org.eclipse.ui.forms.widgets.TableWrapData;
32 import org.eclipse.ui.forms.widgets.TableWrapLayout;
33
34 import org.eclipse.jdt.internal.corext.util.Messages;
35
36 /**
37  * Top level node for Java property pages
38  */

39 public class JavaCategoryPropertyPage extends PropertyPage {
40     
41     private IProject fProject;
42
43     private final static String JavaDoc HREF_BUILDPATH= BuildPathsPropertyPage.PROP_ID;
44     private final static String JavaDoc HREF_COMPILER= CompliancePreferencePage.PROP_ID;
45     private final static String JavaDoc HREF_CODESTYLE= CodeStylePreferencePage.PROP_ID;
46     private final static String JavaDoc HREF_JLOC= JavadocConfigurationPropertyPage.PROP_ID;
47     private final static String JavaDoc HREF_TODO= TodoTaskPreferencePage.PROP_ID;
48     private final static String JavaDoc HREF_PSEVERITIES= ProblemSeveritiesPreferencePage.PROP_ID;
49     private final static String JavaDoc HREF_JAVADOC= JavadocProblemsPreferencePage.PROP_ID;
50     private final static String JavaDoc HREF_FORMATTER= CodeFormatterPreferencePage.PROP_ID;
51     private final static String JavaDoc HREF_TEMPLATES= ""; // Code //$NON-NLS-1$
52
private final static String JavaDoc HREF_IMPORTORDER= ImportOrganizePreferencePage.PROP_ID;
53     private final static String JavaDoc HREF_BUILDING= JavaBuildPreferencePage.PROP_ID;
54     
55     /*
56      * @see PreferencePage#createControl(Composite)
57      */

58     protected Control createContents(Composite parent) {
59         Composite composite= new Composite(parent, SWT.NONE);
60         composite.setLayout(new TableWrapLayout());
61
62         FormToolkit toolkit= new FormToolkit(parent.getDisplay());
63         try {
64             String JavaDoc[] args= {
65                     fProject.getName(), HREF_BUILDPATH, HREF_COMPILER, HREF_TODO, HREF_PSEVERITIES, HREF_JAVADOC, HREF_BUILDING,
66                     HREF_CODESTYLE, HREF_FORMATTER, HREF_TEMPLATES, HREF_IMPORTORDER, HREF_JLOC
67             };
68             String JavaDoc msg= Messages.format(PreferencesMessages.JavaCategoryPropertyPage_text, args);
69             
70             FormText formText = toolkit.createFormText(composite, true);
71             try {
72                 formText.setText(msg, true, false);
73             } catch (SWTException e) {
74                 formText.setText(e.getMessage(), false, false);
75             }
76             
77             formText.setBackground(null);
78             formText.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
79             formText.addHyperlinkListener(new HyperlinkAdapter() {
80                 public void linkActivated(HyperlinkEvent e) {
81                     doLinkActivated(e.data.toString());
82                 }
83             });
84         } finally {
85             toolkit.dispose();
86         }
87         
88         Dialog.applyDialogFont(composite);
89         return composite;
90     }
91     
92     protected void doLinkActivated(String JavaDoc string) {
93         if (string.length() > 0) {
94             IPreferencePageContainer container= getContainer();
95             if (container instanceof PreferenceDialog) {
96                 //see bug 80689: ((PreferenceDialog) container).setCurrentPageId(string);
97
}
98         }
99     }
100
101
102
103     /* (non-Javadoc)
104      * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
105      */

106     public IAdaptable getElement() {
107         return fProject;
108     }
109
110     /* (non-Javadoc)
111      * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
112      */

113     public void setElement(IAdaptable element) {
114         fProject= (IProject) element.getAdapter(IResource.class);
115     }
116
117 }
118
Popular Tags