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.ui.internal.ide.dialogs;
011:
012: import org.eclipse.core.resources.IResource;
013: import org.eclipse.core.resources.ResourcesPlugin;
014: import org.eclipse.core.runtime.Preferences;
015: import org.eclipse.jface.dialogs.MessageDialog;
016: import org.eclipse.jface.preference.PreferencePage;
017: import org.eclipse.swt.SWT;
018: import org.eclipse.swt.events.SelectionAdapter;
019: import org.eclipse.swt.events.SelectionEvent;
020: import org.eclipse.swt.graphics.Font;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.layout.GridLayout;
023: import org.eclipse.swt.widgets.Button;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Control;
026: import org.eclipse.swt.widgets.Label;
027: import org.eclipse.ui.IWorkbench;
028: import org.eclipse.ui.IWorkbenchPreferencePage;
029: import org.eclipse.ui.PlatformUI;
030: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
031: import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
032:
033: /**
034: * Preference page for linked resources.
035: * This preference page allows enabling and disabling the workbench linked
036: * resource support.
037: * It also shows all path variables currently defined in the workspace's path
038: * variable manager. The user may add, edit and remove path variables.
039: *
040: * @see org.eclipse.ui.internal.ide.dialogs.PathVariableDialog
041: */
042: public class LinkedResourcesPreferencePage extends PreferencePage
043: implements IWorkbenchPreferencePage {
044: private Label topLabel;
045:
046: private PathVariablesGroup pathVariablesGroup;
047:
048: /**
049: * Constructs a preference page of path variables.
050: * Omits "Restore Defaults"/"Apply Changes" buttons.
051: */
052: public LinkedResourcesPreferencePage() {
053: pathVariablesGroup = new PathVariablesGroup(true,
054: IResource.FILE | IResource.FOLDER);
055:
056: this .noDefaultAndApplyButton();
057: }
058:
059: /**
060: * Resets this page's internal state and creates its UI contents.
061: *
062: * @see PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
063: */
064: protected Control createContents(Composite parent) {
065: Font font = parent.getFont();
066:
067: PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
068: IIDEHelpContextIds.LINKED_RESOURCE_PREFERENCE_PAGE);
069: // define container & its gridding
070: Composite pageComponent = new Composite(parent, SWT.NULL);
071: GridLayout layout = new GridLayout();
072: layout.marginWidth = 0;
073: layout.marginHeight = 0;
074: pageComponent.setLayout(layout);
075: GridData data = new GridData();
076: data.verticalAlignment = GridData.FILL;
077: data.horizontalAlignment = GridData.FILL;
078: pageComponent.setLayoutData(data);
079: pageComponent.setFont(font);
080:
081: final Button enableLinkedResourcesButton = new Button(
082: pageComponent, SWT.CHECK);
083: enableLinkedResourcesButton
084: .setText(IDEWorkbenchMessages.LinkedResourcesPreference_enableLinkedResources);
085: enableLinkedResourcesButton.setFont(font);
086: enableLinkedResourcesButton
087: .addSelectionListener(new SelectionAdapter() {
088: public void widgetSelected(SelectionEvent e) {
089: boolean enabled = enableLinkedResourcesButton
090: .getSelection();
091: Preferences preferences = ResourcesPlugin
092: .getPlugin().getPluginPreferences();
093: preferences.setValue(
094: ResourcesPlugin.PREF_DISABLE_LINKING,
095: !enabled);
096:
097: updateWidgetState(enabled);
098: if (enabled) {
099: 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
112: .setText(IDEWorkbenchMessages.LinkedResourcesPreference_explanation);
113: data = new GridData();
114: data.verticalAlignment = GridData.FILL;
115: data.horizontalAlignment = GridData.FILL;
116: topLabel.setLayoutData(data);
117: topLabel.setFont(font);
118:
119: pathVariablesGroup.createContents(pageComponent);
120:
121: Preferences preferences = ResourcesPlugin.getPlugin()
122: .getPluginPreferences();
123: boolean enableLinking = !preferences
124: .getBoolean(ResourcesPlugin.PREF_DISABLE_LINKING);
125: enableLinkedResourcesButton.setSelection(enableLinking);
126: updateWidgetState(enableLinking);
127: return pageComponent;
128: }
129:
130: /**
131: * Creates a tab of one horizontal spans.
132: *
133: * @param parent the parent in which the tab should be created
134: */
135: protected static void createSpace(Composite parent) {
136: Label vfiller = new Label(parent, SWT.LEFT);
137: GridData gridData = new GridData();
138: gridData = new GridData();
139: gridData.horizontalAlignment = GridData.BEGINNING;
140: gridData.grabExcessHorizontalSpace = false;
141: gridData.verticalAlignment = GridData.CENTER;
142: gridData.grabExcessVerticalSpace = false;
143: vfiller.setLayoutData(gridData);
144: }
145:
146: /**
147: * Disposes the path variables group.
148: * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
149: */
150: public void dispose() {
151: pathVariablesGroup.dispose();
152: super .dispose();
153: }
154:
155: /**
156: * Empty implementation. This page does not use the workbench.
157: *
158: * @see IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
159: */
160: public void init(IWorkbench workbench) {
161: }
162:
163: /**
164: * Commits the temporary state to the path variable manager in response to user
165: * confirmation.
166: *
167: * @see PreferencePage#performOk()
168: * @see PathVariablesGroup#performOk()
169: */
170: public boolean performOk() {
171: return pathVariablesGroup.performOk();
172: }
173:
174: /**
175: * Set the widget enabled state
176: *
177: * @param enableLinking the new widget enabled state
178: */
179: protected void updateWidgetState(boolean enableLinking) {
180: topLabel.setEnabled(enableLinking);
181: pathVariablesGroup.setEnabled(enableLinking);
182: }
183: }
|