KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > actions > RemoveFromViewAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.team.internal.ui.synchronize.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.compare.structuremergeviewer.IDiffElement;
16 import org.eclipse.core.resources.IWorkspaceRunnable;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.window.Window;
22 import org.eclipse.team.core.synchronize.SyncInfoSet;
23 import org.eclipse.team.internal.core.subscribers.WorkingSetFilteredSyncInfoCollector;
24 import org.eclipse.team.internal.ui.*;
25 import org.eclipse.team.internal.ui.synchronize.SubscriberParticipantPage;
26 import org.eclipse.team.ui.synchronize.ISynchronizePage;
27 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
28 import org.eclipse.team.ui.synchronize.SynchronizeModelAction;
29 import org.eclipse.team.ui.synchronize.SynchronizeModelOperation;
30
31 /**
32  * Remove the selected elemements from the page
33  */

34 public class RemoveFromViewAction extends SynchronizeModelAction {
35
36     public RemoveFromViewAction(ISynchronizePageConfiguration configuration) {
37         super(null, configuration);
38         Utils.initAction(this, "action.removeFromView."); //$NON-NLS-1$
39
}
40
41     /* (non-Javadoc)
42      * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#run()
43      */

44     public void run() {
45         if (confirmRemove()) {
46             super.run();
47         }
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[])
52      */

53     protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
54         return new SynchronizeModelOperation(configuration, elements) {
55             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
56                 SyncInfoSet set = getSyncInfoSet();
57                 removeFromView(set);
58             }
59             protected boolean canRunAsJob() {
60                 return false;
61             }
62             /**
63              * Remove the sync info contained in the given set from the view.
64              * @param set the sync info set
65              */

66             private void removeFromView(final SyncInfoSet set) {
67                 ISynchronizePage page = getConfiguration().getPage();
68                 if (page instanceof SubscriberParticipantPage) {
69                     final WorkingSetFilteredSyncInfoCollector collector = ((SubscriberParticipantPage)page).getCollector();
70                     collector.run(new IWorkspaceRunnable() {
71                         public void run(IProgressMonitor monitor) throws CoreException {
72                             collector.getWorkingSetSyncInfoSet().removeAll(set.getResources());
73                         }
74                     });
75                 }
76             }
77         };
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#needsToSaveDirtyEditors()
82      */

83     protected boolean needsToSaveDirtyEditors() {
84         return false;
85     }
86     
87     private boolean confirmRemove() {
88         IPreferenceStore store = TeamUIPlugin.getPlugin().getPreferenceStore();
89         if (store.getBoolean(IPreferenceIds.SYNCVIEW_REMOVE_FROM_VIEW_NO_PROMPT)) {
90             return true;
91         } else {
92             MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(
93                     getConfiguration().getSite().getShell(),
94                     TeamUIMessages.RemoveFromView_warningTitle,
95                     TeamUIMessages.RemoveFromView_warningMessage,
96                     TeamUIMessages.RemoveFromView_warningDontShow,
97                     false,
98                     null,
99                     null);
100             store.setValue(IPreferenceIds.SYNCVIEW_REMOVE_FROM_VIEW_NO_PROMPT, dialog.getToggleState());
101             return dialog.getReturnCode() == Window.OK;
102         }
103     }
104 }
105
Popular Tags