1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import org.eclipse.core.runtime.IStatus; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.layout.GridData; 17 import org.eclipse.swt.layout.GridLayout; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 21 import org.eclipse.jface.dialogs.ControlEnableState; 22 import org.eclipse.jface.dialogs.Dialog; 23 24 import org.eclipse.ui.dialogs.PropertyPage; 25 import org.eclipse.ui.help.WorkbenchHelp; 26 27 import org.eclipse.jdt.core.IJavaElement; 28 import org.eclipse.jdt.core.IJavaProject; 29 30 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 31 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 32 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; 33 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 34 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; 35 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; 36 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; 37 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; 38 39 42 public class CompilerPropertyPage extends PropertyPage { 43 44 private CompilerConfigurationBlock fConfigurationBlock; 45 private Control fConfigurationBlockControl; 46 private ControlEnableState fBlockEnableState; 47 private SelectionButtonDialogField fUseWorkspaceSettings; 48 private SelectionButtonDialogField fChangeWorkspaceSettings; 49 private SelectionButtonDialogField fUseProjectSettings; 50 private IStatus fBlockStatus; 51 52 53 public CompilerPropertyPage() { 54 fBlockStatus= new StatusInfo(); 55 fBlockEnableState= null; 56 57 IDialogFieldListener listener= new IDialogFieldListener() { 58 public void dialogFieldChanged(DialogField field) { 59 doDialogFieldChanged(field); 60 } 61 }; 62 63 fUseWorkspaceSettings= new SelectionButtonDialogField(SWT.RADIO); 64 fUseWorkspaceSettings.setDialogFieldListener(listener); 65 fUseWorkspaceSettings.setLabelText(PreferencesMessages.getString("CompilerPropertyPage.useworkspacesettings.label")); 67 fChangeWorkspaceSettings= new SelectionButtonDialogField(SWT.PUSH); 68 fChangeWorkspaceSettings.setLabelText(PreferencesMessages.getString("CompilerPropertyPage.useworkspacesettings.change")); fChangeWorkspaceSettings.setDialogFieldListener(listener); 70 71 fUseWorkspaceSettings.attachDialogField(fChangeWorkspaceSettings); 72 73 fUseProjectSettings= new SelectionButtonDialogField(SWT.RADIO); 74 fUseProjectSettings.setDialogFieldListener(listener); 75 fUseProjectSettings.setLabelText(PreferencesMessages.getString("CompilerPropertyPage.useprojectsettings.label")); } 77 78 81 public void createControl(Composite parent) { 82 super.createControl(parent); 83 WorkbenchHelp.setHelp(getControl(), IJavaHelpContextIds.COMPILER_PROPERTY_PAGE); 84 } 85 86 89 protected Control createContents(Composite parent) { 90 IStatusChangeListener listener= new IStatusChangeListener() { 91 public void statusChanged(IStatus status) { 92 fBlockStatus= status; 93 doStatusChanged(); 94 } 95 }; 96 fConfigurationBlock= new CompilerConfigurationBlock(listener, getProject()); 97 98 Composite composite= new Composite(parent, SWT.NONE); 99 GridLayout layout= new GridLayout(); 100 layout.marginHeight= 0; 101 layout.marginWidth= 0; 102 layout.numColumns= 2; 103 composite.setLayout(layout); 104 105 fUseWorkspaceSettings.doFillIntoGrid(composite, 1); 106 LayoutUtil.setHorizontalGrabbing(fUseWorkspaceSettings.getSelectionButton(null)); 107 108 fChangeWorkspaceSettings.doFillIntoGrid(composite, 1); 109 110 fUseProjectSettings.doFillIntoGrid(composite, 2); 111 112 GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL ); 113 data.horizontalSpan= 2; 114 115 fConfigurationBlockControl= fConfigurationBlock.createContents(composite); 116 fConfigurationBlockControl.setLayoutData(data); 117 118 boolean useProjectSettings= fConfigurationBlock.hasProjectSpecificOptions(); 119 120 fUseProjectSettings.setSelection(useProjectSettings); 121 fUseWorkspaceSettings.setSelection(!useProjectSettings); 122 123 updateEnableState(); 124 Dialog.applyDialogFont(composite); 125 return composite; 126 } 127 128 private boolean useProjectSettings() { 129 return fUseProjectSettings.isSelected(); 130 } 131 132 private void doDialogFieldChanged(DialogField field) { 133 if (field == fChangeWorkspaceSettings) { 134 String id= "org.eclipse.jdt.ui.preferences.CompilerPreferencePage"; CompilerPreferencePage page= new CompilerPreferencePage(); 136 PreferencePageSupport.showPreferencePage(getShell(), id, page); 137 } else { 138 updateEnableState(); 139 doStatusChanged(); 140 } 141 } 142 145 private void doStatusChanged() { 146 updateStatus(useProjectSettings() ? fBlockStatus : new StatusInfo()); 147 } 148 149 152 private IJavaProject getProject() { 153 return (IJavaProject) getElement().getAdapter(IJavaElement.class); 154 } 155 156 private void updateEnableState() { 157 if (useProjectSettings()) { 158 if (fBlockEnableState != null) { 159 fBlockEnableState.restore(); 160 fBlockEnableState= null; 161 } 162 } else { 163 if (fBlockEnableState == null) { 164 fBlockEnableState= ControlEnableState.disable(fConfigurationBlockControl); 165 } 166 } 167 } 168 169 172 protected void performDefaults() { 173 if (useProjectSettings()) { 174 fUseProjectSettings.setSelection(false); 175 fUseWorkspaceSettings.setSelection(true); 176 fConfigurationBlock.performDefaults(); 177 } 178 super.performDefaults(); 179 } 180 181 184 public boolean performOk() { 185 return fConfigurationBlock.performOk(useProjectSettings()); 186 } 187 188 private void updateStatus(IStatus status) { 189 setValid(!status.matches(IStatus.ERROR)); 190 StatusUtil.applyToStatusLine(this, status); 191 } 192 193 } 194 | Popular Tags |