KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > LinkedResourcesPreferencePage


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
12 package org.eclipse.ui.internal.ide.dialogs;
13
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.resources.ResourcesPlugin;
16 import org.eclipse.core.runtime.Preferences;
17 import org.eclipse.jface.dialogs.MessageDialog;
18 import org.eclipse.jface.preference.PreferencePage;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.SelectionAdapter;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.graphics.Font;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.ui.IWorkbench;
30 import org.eclipse.ui.IWorkbenchPreferencePage;
31 import org.eclipse.ui.PlatformUI;
32 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
33 import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
34
35 /**
36  * Preference page for linked resources.
37  * This preference page allows enabling and disabling the workbench linked
38  * resource support.
39  * It also shows all path variables currently defined in the workspace's path
40  * variable manager. The user may add, edit and remove path variables.
41  *
42  * @see org.eclipse.ui.internal.ide.dialogs.PathVariableDialog
43  */

44 public class LinkedResourcesPreferencePage extends PreferencePage implements
45         IWorkbenchPreferencePage {
46     private Label topLabel;
47
48     private PathVariablesGroup pathVariablesGroup;
49
50     /**
51      * Constructs a preference page of path variables.
52      * Omits "Restore Defaults"/"Apply Changes" buttons.
53      */

54     public LinkedResourcesPreferencePage() {
55         pathVariablesGroup = new PathVariablesGroup(true, IResource.FILE
56                 | IResource.FOLDER);
57
58         this.noDefaultAndApplyButton();
59     }
60
61     /**
62      * Resets this page's internal state and creates its UI contents.
63      *
64      * @see PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
65      */

66     protected Control createContents(Composite parent) {
67         Font font = parent.getFont();
68
69         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
70                 IIDEHelpContextIds.LINKED_RESOURCE_PREFERENCE_PAGE);
71         // define container & its gridding
72
Composite pageComponent = new Composite(parent, SWT.NULL);
73         GridLayout layout = new GridLayout();
74         layout.marginWidth = 0;
75         layout.marginHeight = 0;
76         pageComponent.setLayout(layout);
77         GridData data = new GridData();
78         data.verticalAlignment = GridData.FILL;
79         data.horizontalAlignment = GridData.FILL;
80         pageComponent.setLayoutData(data);
81         pageComponent.setFont(font);
82
83         final Button enableLinkedResourcesButton = new Button(pageComponent,
84                 SWT.CHECK);
85         enableLinkedResourcesButton.setText(IDEWorkbenchMessages.LinkedResourcesPreference_enableLinkedResources);
86         enableLinkedResourcesButton.setFont(font);
87         enableLinkedResourcesButton
88                 .addSelectionListener(new SelectionAdapter() {
89                     public void widgetSelected(SelectionEvent e) {
90                         boolean enabled = enableLinkedResourcesButton
91                                 .getSelection();
92                         Preferences preferences = ResourcesPlugin.getPlugin()
93                                 .getPluginPreferences();
94                         preferences.setValue(
95                                 ResourcesPlugin.PREF_DISABLE_LINKING, !enabled);
96
97                         updateWidgetState(enabled);
98                         if (enabled) {
99                             MessageDialog
100                                     .openWarning(
101                                             getShell(),
102                                             IDEWorkbenchMessages.LinkedResourcesPreference_linkedResourcesWarningTitle,
103                                             IDEWorkbenchMessages.LinkedResourcesPreference_linkedResourcesWarningMessage);
104                         }
105                     }
106                 });
107
108         createSpace(pageComponent);
109
110         topLabel = new Label(pageComponent, SWT.NONE);
111         topLabel.setText(IDEWorkbenchMessages.LinkedResourcesPreference_explanation);
112         data = new GridData();
113         data.verticalAlignment = GridData.FILL;
114         data.horizontalAlignment = GridData.FILL;
115         topLabel.setLayoutData(data);
116         topLabel.setFont(font);
117
118         pathVariablesGroup.createContents(pageComponent);
119
120         Preferences preferences = ResourcesPlugin.getPlugin()
121                 .getPluginPreferences();
122         boolean enableLinking = !preferences
123                 .getBoolean(ResourcesPlugin.PREF_DISABLE_LINKING);
124         enableLinkedResourcesButton.setSelection(enableLinking);
125         updateWidgetState(enableLinking);
126         return pageComponent;
127     }
128
129     /**
130      * Creates a tab of one horizontal spans.
131      *
132      * @param parent the parent in which the tab should be created
133      */

134     protected static void createSpace(Composite parent) {
135         Label vfiller = new Label(parent, SWT.LEFT);
136         GridData gridData = new GridData();
137         gridData = new GridData();
138         gridData.horizontalAlignment = GridData.BEGINNING;
139         gridData.grabExcessHorizontalSpace = false;
140         gridData.verticalAlignment = GridData.CENTER;
141         gridData.grabExcessVerticalSpace = false;
142         vfiller.setLayoutData(gridData);
143     }
144
145     /**
146      * Disposes the path variables group.
147      * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
148      */

149     public void dispose() {
150         pathVariablesGroup.dispose();
151         super.dispose();
152     }
153
154     /**
155      * Empty implementation. This page does not use the workbench.
156      *
157      * @see IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
158      */

159     public void init(IWorkbench workbench) {
160     }
161
162     /**
163      * Commits the temporary state to the path variable manager in response to user
164      * confirmation.
165      *
166      * @see PreferencePage#performOk()
167      * @see PathVariablesGroup#performOk()
168      */

169     public boolean performOk() {
170         return pathVariablesGroup.performOk();
171     }
172
173     /**
174      * Set the widget enabled state
175      *
176      * @param enableLinking the new widget enabled state
177      */

178     protected void updateWidgetState(boolean enableLinking) {
179         topLabel.setEnabled(enableLinking);
180         pathVariablesGroup.setEnabled(enableLinking);
181     }
182 }
183
Popular Tags