KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > history > RefactoringDescriptorDeleteQuery


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
33  * Default implementation of a refactoring descriptor delete query.
34  *
35  * @since 3.3
36  */

37 public final class RefactoringDescriptorDeleteQuery implements IRefactoringDescriptorDeleteQuery {
38
39     /** Preference key for the warn delete preference */
40     private static final String JavaDoc PREFERENCE_DO_NOT_WARN_DELETE= RefactoringUIPlugin.getPluginId() + ".do.not.warn.delete.descriptor"; //$NON-NLS-1$;
41

42     /** The number of descriptors to delete */
43     private final int fCount;
44
45     /** The project to use */
46     private final IProject fProject;
47
48     /** The return code */
49     private int fReturnCode= -1;
50
51     /** The shell to use */
52     private final Shell fShell;
53
54     /** Has the user already been warned once? */
55     private boolean fWarned= false;
56
57     /**
58      * Creates a new refactoring descriptor delete query.
59      *
60      * @param shell
61      * the shell to use
62      * @param project
63      * the project to use, or <code>null</code>
64      * @param count
65      * the number of descriptors to delete
66      */

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     /**
76      * {@inheritDoc}
77      */

78     public boolean hasDeletions() {
79         return fReturnCode == IDialogConstants.YES_ID;
80     }
81
82     /**
83      * {@inheritDoc}
84      */

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 JavaDoc() {
90
91                     public final void run() {
92                         if (!fShell.isDisposed()) {
93                             final String JavaDoc count= new Integer JavaDoc(fCount).toString();
94                             String JavaDoc message= null;
95                             if (fProject != null)
96                                 message= Messages.format(RefactoringUIMessages.RefactoringPropertyPage_confirm_delete_pattern, new String JavaDoc[] { 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