~verterok/bzr-eclipse/pluginpath-fix

« back to all changes in this revision

Viewing changes to org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/IgnoredAction.java

  • Committer: Guillermo Gonzalez
  • Date: 2009-07-09 20:40:43 UTC
  • mfrom: (212.1.4 add-ignore)
  • Revision ID: guillo.gonzo@gmail.com-20090709204043-9l55py1bij7799s0
mergeĀ lp:~verterok/bzr-eclipse/add-ignore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* Copyright (C) 2009 Canonical Ltd
 
3
 
4
* This program is free software; you can redistribute it and/or modify
 
5
* it under the terms of the GNU General Public License as published by
 
6
* the Free Software Foundation; either version 2 of the License, or
 
7
* (at your option) any later version.
 
8
*
 
9
* This program is distributed in the hope that it will be useful,
 
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
* GNU General Public License for more details.
 
13
*
 
14
* You should have received a copy of the GNU General Public License
 
15
* along with this program; if not, write to the Free Software
 
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
*/
 
18
package org.vcs.bazaar.eclipse.ui.actions;
 
19
 
 
20
import java.lang.reflect.InvocationTargetException;
 
21
import java.util.HashMap;
 
22
import java.util.List;
 
23
import java.util.Map;
 
24
 
 
25
import org.eclipse.core.resources.IProject;
 
26
import org.eclipse.core.resources.IResource;
 
27
import org.eclipse.core.runtime.IProgressMonitor;
 
28
import org.eclipse.jface.action.IAction;
 
29
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
30
import org.eclipse.ui.actions.WorkspaceModifyOperation;
 
31
import org.vcs.bazaar.eclipse.BzrWorkspaceRoot;
 
32
import org.vcs.bazaar.eclipse.core.commands.AddCommand;
 
33
import org.vcs.bazaar.eclipse.core.commands.IgnoredCommand;
 
34
import org.vcs.bazaar.eclipse.internal.core.BazaarException;
 
35
import org.vcs.bazaar.eclipse.ui.dialogs.IgnoredDialog;
 
36
 
 
37
/**
 
38
 * @authors Javier Der Derian<javierder AT gmail DOT com><br>
 
39
 *          Guillermo Gonzalez <guillo.gonzo@gmail.com>
 
40
 * @BasedOn RevertAction from BzrEclipse
 
41
 * 
 
42
 * TODO: add support for multiple projects(?)
 
43
 */
 
44
public class IgnoredAction extends WorkbenchAction {
 
45
 
 
46
        /**
 
47
         * <p>
 
48
         * The action has been activated. The argument of the method represents the
 
49
         * 'real' action sitting in the workbench UI.
 
50
         * </p>
 
51
         * 
 
52
         * @throws BazaarException
 
53
         * @see IWorkbenchWindowActionDelegate#run
 
54
         */
 
55
        @Override
 
56
        protected void execute(IAction action) throws BazaarException, InvocationTargetException, InterruptedException {
 
57
                IProject[] projects = getEnclosingProjectsForSelectedResources(); 
 
58
                // Added IgnoredCommand to get the ignored list
 
59
                final IgnoredCommand cmd = new IgnoredCommand(projects[0]);
 
60
                final Map<IResource, String> ignored = new HashMap<IResource, String>();
 
61
                
 
62
                // Is this necesary to run every command???
 
63
                run(new WorkspaceModifyOperation() {
 
64
                        public void execute(IProgressMonitor monitor) throws InvocationTargetException {
 
65
                                try {
 
66
                                        cmd.run(monitor);
 
67
                        ignored.putAll(cmd.getIgnored());
 
68
                                } catch (BazaarException e) {
 
69
                                        // FIXME: exception handling
 
70
                                        throw new InvocationTargetException(e);
 
71
                                } finally {
 
72
                                        monitor.done();
 
73
                                }
 
74
                        }
 
75
                }, false /* no cancelable */, PROGRESS_BUSYCURSOR);
 
76
                // If it's null it's because there was a previous error.
 
77
                if(ignored != null) {
 
78
                        IgnoredDialog dialog = new IgnoredDialog(this.getShell(), ignored);
 
79
                        
 
80
                        if(dialog.open() != IgnoredDialog.OK) {
 
81
                                return;
 
82
                        }
 
83
                        
 
84
                        final List<IResource> unchecked = dialog.getUnChecked();
 
85
                        if(unchecked.size() > 0)
 
86
                        {
 
87
                                // Changed AddIgnoredCommand for AddCommand  
 
88
                                final AddCommand cmd_add = new AddCommand(BzrWorkspaceRoot.getBzrWorkspaceRootFor(projects[0]), unchecked);
 
89
                                run(new WorkspaceModifyOperation() {
 
90
                                        public void execute(IProgressMonitor monitor) throws InvocationTargetException {
 
91
                                                try {
 
92
                                                        cmd_add.run(monitor);
 
93
                                                } catch (BazaarException e) {
 
94
                                                        // FIXME: exception handling
 
95
                                                        throw new InvocationTargetException(e);
 
96
                                                } finally {
 
97
                                                        monitor.done();
 
98
                                                }
 
99
                                        }
 
100
                                }, false /* no cancelable */, PROGRESS_DIALOG);
 
101
                        }
 
102
                }
 
103
 
 
104
 
 
105
 
 
106
        }
 
107
        
 
108
        protected boolean isEnabledForUnmanagedResources() {
 
109
                return false;
 
110
        }
 
111
 
 
112
        @Override
 
113
        protected boolean isEnabledForUnmodifiedResources() {
 
114
                if(getSelectedProjects().length == 1) {
 
115
                        return true;
 
116
                }
 
117
                return false;
 
118
        }
 
119
        
 
120
        @Override
 
121
        protected boolean isEnabledForMultipleEclosingProjects() {
 
122
                return false;
 
123
        }
 
124
}