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.Button; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.swt.widgets.Shell; 23 24 import org.eclipse.jface.dialogs.IDialogConstants; 25 import org.eclipse.jface.dialogs.IDialogSettings; 26 import org.eclipse.jface.dialogs.MessageDialog; 27 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 import org.eclipse.jdt.internal.ui.JavaUIMessages; 30 31 35 public class OptionalMessageDialog extends MessageDialog { 36 37 private static final String CHECKBOX_TEXT= JavaUIMessages.OptionalMessageDialog_dontShowAgain; 39 40 private static final String STORE_ID= "OptionalMessageDialog.hide."; 43 public static final int NOT_SHOWN= IDialogConstants.CLIENT_ID + 1; 44 45 private Button fHideDialogCheckBox; 46 private String fId; 47 48 52 public static int open(String id, Shell parent, String title, Image titleImage, String message, int dialogType, String [] buttonLabels, int defaultButtonIndex) { 53 if (!isDialogEnabled(id)) 54 return OptionalMessageDialog.NOT_SHOWN; 55 56 MessageDialog dialog= new OptionalMessageDialog(id, parent, title, titleImage, message, dialogType, buttonLabels, defaultButtonIndex); 57 return dialog.open(); 58 } 59 60 protected OptionalMessageDialog(String id, Shell parent, String title, Image titleImage, String message, int dialogType, String [] buttonLabels, int defaultButtonIndex) { 61 super(parent, title, titleImage, message, dialogType, buttonLabels, defaultButtonIndex); 62 fId= id; 63 } 64 65 protected Control createCustomArea(Composite parent) { 66 Composite composite= new Composite(parent, SWT.NONE); 67 GridLayout layout= new GridLayout(); 68 layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 69 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 70 layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 71 composite.setLayout(layout); 72 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 73 74 fHideDialogCheckBox= new Button(composite, SWT.CHECK | SWT.LEFT); 75 fHideDialogCheckBox.setText(CHECKBOX_TEXT); 76 fHideDialogCheckBox.addSelectionListener(new SelectionAdapter() { 77 public void widgetSelected(SelectionEvent e) { 78 setDialogEnabled(fId, !((Button)e.widget).getSelection()); 79 } 80 }); 81 applyDialogFont(fHideDialogCheckBox); 82 return fHideDialogCheckBox; 83 } 84 85 87 92 private static IDialogSettings getDialogSettings() { 93 IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings(); 94 settings= settings.getSection(STORE_ID); 95 if (settings == null) 96 settings= JavaPlugin.getDefault().getDialogSettings().addNewSection(STORE_ID); 97 return settings; 98 } 99 100 103 public static boolean isDialogEnabled(String key) { 104 IDialogSettings settings= getDialogSettings(); 105 return !settings.getBoolean(key); 106 } 107 108 111 public static void setDialogEnabled(String key, boolean isEnabled) { 112 IDialogSettings settings= getDialogSettings(); 113 settings.put(key, !isEnabled); 114 } 115 116 119 public static void clearAllRememberedStates() { 120 IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings(); 121 settings.addNewSection(STORE_ID); 122 } 123 } 124 | Popular Tags |