1 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 44 public class LinkedResourcesPreferencePage extends PreferencePage implements 45 IWorkbenchPreferencePage { 46 private Label topLabel; 47 48 private PathVariablesGroup pathVariablesGroup; 49 50 54 public LinkedResourcesPreferencePage() { 55 pathVariablesGroup = new PathVariablesGroup(true, IResource.FILE 56 | IResource.FOLDER); 57 58 this.noDefaultAndApplyButton(); 59 } 60 61 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 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 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 149 public void dispose() { 150 pathVariablesGroup.dispose(); 151 super.dispose(); 152 } 153 154 159 public void init(IWorkbench workbench) { 160 } 161 162 169 public boolean performOk() { 170 return pathVariablesGroup.performOk(); 171 } 172 173 178 protected void updateWidgetState(boolean enableLinking) { 179 topLabel.setEnabled(enableLinking); 180 pathVariablesGroup.setEnabled(enableLinking); 181 } 182 } 183 | Popular Tags |