1 11 package org.eclipse.ltk.internal.ui.refactoring.history; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.core.resources.IProject; 16 17 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 18 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 19 20 import org.eclipse.ltk.internal.core.refactoring.history.IRefactoringDescriptorDeleteQuery; 21 import org.eclipse.ltk.internal.ui.refactoring.Messages; 22 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; 23 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin; 24 import org.eclipse.ltk.internal.ui.refactoring.scripting.ScriptingMessages; 25 26 import org.eclipse.swt.widgets.Shell; 27 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 30 import org.eclipse.jface.preference.IPreferenceStore; 31 32 37 public final class RefactoringDescriptorDeleteQuery implements IRefactoringDescriptorDeleteQuery { 38 39 40 private static final String PREFERENCE_DO_NOT_WARN_DELETE= RefactoringUIPlugin.getPluginId() + ".do.not.warn.delete.descriptor"; 42 43 private final int fCount; 44 45 46 private final IProject fProject; 47 48 49 private int fReturnCode= -1; 50 51 52 private final Shell fShell; 53 54 55 private boolean fWarned= false; 56 57 67 public RefactoringDescriptorDeleteQuery(final Shell shell, final IProject project, final int count) { 68 Assert.isNotNull(shell); 69 Assert.isTrue(count >= 0); 70 fShell= shell; 71 fProject= project; 72 fCount= count; 73 } 74 75 78 public boolean hasDeletions() { 79 return fReturnCode == IDialogConstants.YES_ID; 80 } 81 82 85 public RefactoringStatus proceed(final RefactoringDescriptorProxy proxy) { 86 final IPreferenceStore store= RefactoringUIPlugin.getDefault().getPreferenceStore(); 87 if (!fWarned) { 88 if (!store.getBoolean(PREFERENCE_DO_NOT_WARN_DELETE)) { 89 fShell.getDisplay().syncExec(new Runnable () { 90 91 public final void run() { 92 if (!fShell.isDisposed()) { 93 final String count= new Integer (fCount).toString(); 94 String message= null; 95 if (fProject != null) 96 message= Messages.format(RefactoringUIMessages.RefactoringPropertyPage_confirm_delete_pattern, new String [] { count, fProject.getName()}); 97 else 98 message= Messages.format(ScriptingMessages.ShowRefactoringHistoryWizard_confirm_deletion, count); 99 final MessageDialogWithToggle dialog= MessageDialogWithToggle.openYesNoQuestion(fShell, RefactoringUIMessages.RefactoringPropertyPage_confirm_delete_caption, message, RefactoringUIMessages.RefactoringHistoryWizard_do_not_show_message, store.getBoolean(PREFERENCE_DO_NOT_WARN_DELETE), null, null); 100 store.setValue(PREFERENCE_DO_NOT_WARN_DELETE, dialog.getToggleState()); 101 fReturnCode= dialog.getReturnCode(); 102 } 103 } 104 }); 105 } else 106 fReturnCode= IDialogConstants.YES_ID; 107 } 108 fWarned= true; 109 if (fReturnCode == IDialogConstants.YES_ID) 110 return new RefactoringStatus(); 111 return RefactoringStatus.createErrorStatus(IDialogConstants.NO_LABEL); 112 } 113 } | Popular Tags |