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.Dialog; 22 23 import org.eclipse.ui.dialogs.PropertyPage; 24 import org.eclipse.ui.help.WorkbenchHelp; 25 26 import org.eclipse.jdt.core.IJavaElement; 27 import org.eclipse.jdt.core.IJavaProject; 28 29 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 30 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 31 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; 32 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 33 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; 34 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; 35 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; 36 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; 37 38 41 public class TodoTaskPropertyPage extends PropertyPage { 42 43 private TodoTaskConfigurationBlock fConfigurationBlock; 44 private Control fConfigurationBlockControl; 45 private SelectionButtonDialogField fUseWorkspaceSettings; 46 private SelectionButtonDialogField fChangeWorkspaceSettings; 47 private SelectionButtonDialogField fUseProjectSettings; 48 private IStatus fBlockStatus; 49 50 51 public TodoTaskPropertyPage() { 52 setDescription(PreferencesMessages.getString("TodoTaskPropertyPage.description")); 54 fBlockStatus= new StatusInfo(); 55 IDialogFieldListener listener= new IDialogFieldListener() { 56 public void dialogFieldChanged(DialogField field) { 57 doDialogFieldChanged(field); 58 } 59 }; 60 61 fUseWorkspaceSettings= new SelectionButtonDialogField(SWT.RADIO); 62 fUseWorkspaceSettings.setDialogFieldListener(listener); 63 fUseWorkspaceSettings.setLabelText(PreferencesMessages.getString("TodoTaskPropertyPage.useworkspacesettings.label")); 65 fChangeWorkspaceSettings= new SelectionButtonDialogField(SWT.PUSH); 66 fChangeWorkspaceSettings.setLabelText(PreferencesMessages.getString("TodoTaskPropertyPage.useworkspacesettings.change")); fChangeWorkspaceSettings.setDialogFieldListener(listener); 68 69 fUseWorkspaceSettings.attachDialogField(fChangeWorkspaceSettings); 70 71 fUseProjectSettings= new SelectionButtonDialogField(SWT.RADIO); 72 fUseProjectSettings.setDialogFieldListener(listener); 73 fUseProjectSettings.setLabelText(PreferencesMessages.getString("TodoTaskPropertyPage.useprojectsettings.label")); } 75 76 79 public void createControl(Composite parent) { 80 super.createControl(parent); 81 WorkbenchHelp.setHelp(getControl(), IJavaHelpContextIds.TODOTASK_PROPERTY_PAGE); 82 } 83 84 87 protected Control createContents(Composite parent) { 88 IStatusChangeListener listener= new IStatusChangeListener() { 89 public void statusChanged(IStatus status) { 90 fBlockStatus= status; 91 doStatusChanged(); 92 } 93 }; 94 fConfigurationBlock= new TodoTaskConfigurationBlock(listener, getProject()); 95 96 Composite composite= new Composite(parent, SWT.NONE); 97 GridLayout layout= new GridLayout(); 98 layout.marginHeight= 0; 99 layout.marginWidth= 0; 100 layout.numColumns= 1; 101 composite.setLayout(layout); 102 103 fUseWorkspaceSettings.doFillIntoGrid(composite, 1); 104 LayoutUtil.setHorizontalGrabbing(fUseWorkspaceSettings.getSelectionButton(null)); 105 106 fChangeWorkspaceSettings.doFillIntoGrid(composite, 1); 107 GridData data= (GridData) fChangeWorkspaceSettings.getSelectionButton(null).getLayoutData(); 108 data.horizontalIndent= convertWidthInCharsToPixels(3); 109 data.horizontalAlignment= GridData.BEGINNING; 110 111 fUseProjectSettings.doFillIntoGrid(composite, 1); 112 113 data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL ); 114 data.horizontalSpan= 1; 115 data.horizontalIndent= convertWidthInCharsToPixels(2); 116 117 fConfigurationBlockControl= fConfigurationBlock.createContents(composite); 118 fConfigurationBlockControl.setLayoutData(data); 119 120 boolean useProjectSettings= fConfigurationBlock.hasProjectSpecificOptions(); 121 122 fUseProjectSettings.setSelection(useProjectSettings); 123 fUseWorkspaceSettings.setSelection(!useProjectSettings); 124 125 updateEnableState(); 126 Dialog.applyDialogFont(composite); 127 return composite; 128 } 129 130 private boolean useProjectSettings() { 131 return fUseProjectSettings.isSelected(); 132 } 133 134 private void doDialogFieldChanged(DialogField field) { 135 if (field == fChangeWorkspaceSettings) { 136 TodoTaskPreferencePage page= new TodoTaskPreferencePage(); 137 PreferencePageSupport.showPreferencePage(getShell(), TodoTaskPreferencePage.ID, page); 138 } else { 139 updateEnableState(); 140 doStatusChanged(); 141 } 142 } 143 146 private void doStatusChanged() { 147 updateStatus(useProjectSettings() ? fBlockStatus : new StatusInfo()); 148 } 149 150 153 private IJavaProject getProject() { 154 return (IJavaProject) getElement().getAdapter(IJavaElement.class); 155 } 156 157 private void updateEnableState() { 158 fConfigurationBlock.setEnabled(useProjectSettings()); 159 } 160 161 164 protected void performDefaults() { 165 if (useProjectSettings()) { 166 fConfigurationBlock.performDefaults(); 167 fUseProjectSettings.setSelection(false); 168 fUseWorkspaceSettings.setSelection(true); 169 } 170 super.performDefaults(); 171 } 172 173 176 public boolean performOk() { 177 return fConfigurationBlock.performOk(useProjectSettings()); 178 } 179 180 private void updateStatus(IStatus status) { 181 setValid(!status.matches(IStatus.ERROR)); 182 StatusUtil.applyToStatusLine(this, status); 183 } 184 185 } 186 | Popular Tags |