1 11 package org.eclipse.jdt.internal.ui.dialogs; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.events.SelectionAdapter; 15 import org.eclipse.swt.events.SelectionEvent; 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.layout.GridLayout; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.swt.widgets.Label; 22 import org.eclipse.swt.widgets.Link; 23 import org.eclipse.swt.widgets.Shell; 24 25 import org.eclipse.jface.dialogs.Dialog; 26 import org.eclipse.jface.dialogs.IDialogConstants; 27 import org.eclipse.jface.dialogs.IDialogSettings; 28 import org.eclipse.jface.window.Window; 29 30 import org.eclipse.ui.PlatformUI; 31 import org.eclipse.ui.dialogs.PreferencesUtil; 32 33 import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType; 34 35 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 36 import org.eclipse.jdt.internal.ui.JavaPlugin; 37 import org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferencePage; 38 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; 39 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; 40 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; 41 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; 42 43 public class SortMembersMessageDialog extends OptionalMessageDialog { 44 45 private final static String OPTIONAL_ID= "SortMembersMessageDialog.optionalDialog.id"; 47 private final static String DIALOG_SETTINGS_SORT_ALL= "SortMembers.sort_all"; 49 private SelectionButtonDialogField fNotSortAllRadio; 50 private SelectionButtonDialogField fSortAllRadio; 51 52 private final IDialogSettings fDialogSettings; 53 54 public SortMembersMessageDialog(Shell parentShell) { 55 super(OPTIONAL_ID, parentShell, DialogsMessages.SortMembersMessageDialog_dialog_title, null, new String (), INFORMATION, new String [] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 0); 56 57 setShellStyle(getShellStyle() | SWT.RESIZE); 58 59 fDialogSettings= JavaPlugin.getDefault().getDialogSettings(); 60 61 boolean isSortAll= fDialogSettings.getBoolean(DIALOG_SETTINGS_SORT_ALL); 62 63 fNotSortAllRadio= new SelectionButtonDialogField(SWT.RADIO); 64 fNotSortAllRadio.setLabelText(DialogsMessages.SortMembersMessageDialog_do_not_sort_fields_label); 65 fNotSortAllRadio.setSelection(!isSortAll); 66 67 fSortAllRadio= new SelectionButtonDialogField(SWT.RADIO); 68 fSortAllRadio.setLabelText(DialogsMessages.SortMembersMessageDialog_sort_all_label); 69 fSortAllRadio.setSelection(isSortAll); 70 } 71 72 private Control createLinkControl(Composite composite) { 73 Link link= new Link(composite, SWT.WRAP | SWT.RIGHT); 74 link.setText(DialogsMessages.SortMembersMessageDialog_description); 75 link.addSelectionListener(new SelectionAdapter() { 76 public void widgetSelected(SelectionEvent e) { 77 openCodeTempatePage(CodeTemplateContextType.CONSTRUCTORCOMMENT_ID); 78 } 79 }); 80 link.setToolTipText(DialogsMessages.SortMembersMessageDialog_link_tooltip); 81 GridData gridData= new GridData(GridData.FILL, GridData.CENTER, true, false); 82 gridData.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); link.setLayoutData(gridData); 84 link.setFont(composite.getFont()); 85 86 return link; 87 } 88 89 protected void openCodeTempatePage(String id) { 90 PreferencesUtil.createPreferenceDialogOn(getShell(), MembersOrderPreferencePage.PREF_ID, null, null).open(); 91 } 92 93 96 protected Control createContents(Composite parent) { 97 Control contents= super.createContents(parent); 98 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.SORT_MEMBERS_DIALOG); 99 return contents; 100 } 101 102 105 protected Control createMessageArea(Composite parent) { 106 initializeDialogUnits(parent); 107 108 Composite messageComposite= new Composite(parent, SWT.NONE); 109 messageComposite.setFont(parent.getFont()); 110 GridLayout layout= new GridLayout(); 111 layout.numColumns= 1; 112 layout.marginHeight= 0; 113 layout.marginWidth= 0; 114 layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 115 layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 116 messageComposite.setLayout(layout); 117 messageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 118 119 createLinkControl(messageComposite); 120 121 int indent= convertWidthInCharsToPixels(3); 122 123 fNotSortAllRadio.doFillIntoGrid(messageComposite, 1); 124 LayoutUtil.setHorizontalIndent(fNotSortAllRadio.getSelectionButton(null), indent); 125 126 fSortAllRadio.doFillIntoGrid(messageComposite, 1); 127 LayoutUtil.setHorizontalIndent(fSortAllRadio.getSelectionButton(null), indent); 128 129 final Composite warningComposite= new Composite(messageComposite, SWT.NONE); 130 layout= new GridLayout(); 131 layout.numColumns= 2; 132 layout.marginWidth= 0; 133 layout.marginHeight= 0; 134 warningComposite.setLayout(layout); 135 warningComposite.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); 136 warningComposite.setFont(messageComposite.getFont()); 137 138 Image image= Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING); 139 final Label imageLabel1= new Label(warningComposite, SWT.LEFT | SWT.WRAP); 140 imageLabel1.setImage(image); 141 imageLabel1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 1, 1)); 142 143 final Label label= new Label(warningComposite, SWT.WRAP); 144 label.setText(DialogsMessages.SortMembersMessageDialog_sort_warning_label); 145 GridData gridData= new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1); 146 gridData.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); 147 label.setLayoutData(gridData); 148 label.setFont(warningComposite.getFont()); 149 150 fNotSortAllRadio.setDialogFieldListener(new IDialogFieldListener() { 151 public void dialogFieldChanged(DialogField field) { 152 imageLabel1.setEnabled(!fNotSortAllRadio.isSelected()); 153 label.setEnabled(!fNotSortAllRadio.isSelected()); 154 } 155 }); 156 imageLabel1.setEnabled(!fNotSortAllRadio.isSelected()); 157 label.setEnabled(!fNotSortAllRadio.isSelected()); 158 159 return messageComposite; 160 } 161 162 165 public int open() { 166 if (isDialogEnabled(OPTIONAL_ID)) { 167 int res= super.open(); 168 if (res != Window.OK) { 169 setDialogEnabled(OPTIONAL_ID, true); } 171 return res; 172 } 173 return Window.OK; 174 } 175 176 177 180 public boolean close() { 181 fDialogSettings.put(DIALOG_SETTINGS_SORT_ALL, fSortAllRadio.isSelected()); 182 return super.close(); 183 } 184 185 186 public boolean isNotSortingFieldsEnabled() { 187 return fNotSortAllRadio.isSelected(); 188 } 189 190 } 191 | Popular Tags |