1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import org.eclipse.core.runtime.preferences.IScopeContext; 14 15 import org.eclipse.core.resources.IProject; 16 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 20 import org.eclipse.jface.dialogs.Dialog; 21 import org.eclipse.jface.preference.IPreferencePageContainer; 22 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 25 import org.eclipse.ui.preferences.IWorkingCopyManager; 26 import org.eclipse.ui.preferences.WorkingCopyManager; 27 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 30 import org.osgi.service.prefs.BackingStoreException; 31 32 38 public abstract class AbstractConfigurationBlockPreferenceAndPropertyPage extends PropertyAndPreferencePage { 39 40 private IPreferenceAndPropertyConfigurationBlock fConfigurationBlock; 41 private PreferencesAccess fAccess; 42 43 public AbstractConfigurationBlockPreferenceAndPropertyPage() { 44 } 45 46 52 protected abstract IPreferenceAndPropertyConfigurationBlock createConfigurationBlock(IScopeContext context); 53 54 protected abstract String getHelpId(); 55 56 59 public void createControl(Composite parent) { 60 super.createControl(parent); 61 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpId()); 62 } 63 64 67 protected Control createPreferenceContent(Composite parent) { 68 69 IPreferencePageContainer container= getContainer(); 70 IWorkingCopyManager manager; 71 if (container instanceof IWorkbenchPreferenceContainer) { 72 manager= ((IWorkbenchPreferenceContainer)container).getWorkingCopyManager(); 73 } else { 74 manager= new WorkingCopyManager(); } 76 fAccess= PreferencesAccess.getWorkingCopyPreferences(manager); 77 IProject project= getProject(); 78 IScopeContext context; 79 if (project != null) { 80 context= fAccess.getProjectScope(project); 81 } else { 82 context= fAccess.getInstanceScope(); 83 } 84 85 fConfigurationBlock= createConfigurationBlock(context); 86 87 Control content= fConfigurationBlock.createControl(parent); 88 89 fConfigurationBlock.initialize(); 90 91 Dialog.applyDialogFont(content); 92 return content; 93 } 94 95 98 public boolean performOk() { 99 fConfigurationBlock.performOk(); 100 101 try { 102 fAccess.applyChanges(); 103 } catch (BackingStoreException e) { 104 JavaPlugin.log(e); 105 } 106 107 return true; 108 } 109 110 113 public void performDefaults() { 114 fConfigurationBlock.performDefaults(); 115 super.performDefaults(); 116 } 117 118 121 public void dispose() { 122 fConfigurationBlock.dispose(); 123 super.dispose(); 124 } 125 126 129 protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) { 130 super.enableProjectSpecificSettings(useProjectSpecificSettings); 131 if (useProjectSpecificSettings) { 132 fConfigurationBlock.enableProjectSettings(); 133 } else { 134 fConfigurationBlock.disableProjectSettings(); 135 } 136 } 137 } 138 | Popular Tags |