Skip to main content
summaryrefslogtreecommitdiffstats
blob: ef16c3f02728d9b1ca953dd8675a268924c7003c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2002 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 * IBM - Initial API and implementation
 ******************************************************************************/

package org.eclipse.team.internal.ccvs.ui;
 
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.team.ccvs.core.CVSTeamProvider;
import org.eclipse.team.ccvs.core.ICVSResource;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.client.Command;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.ui.IMarkerResolution;

/**
 * Generate marker resoultions for a cvs remove marker
 */
public class CVSAddResolutionGenerator extends CVSAbstractResolutionGenerator {
	/*
	 * @see IMarkerResolutionGenerator#getResolutions(IMarker)
	 */
	public IMarkerResolution[] getResolutions(IMarker marker) {
		IMarkerResolution manage = new IMarkerResolution() {
			public String getLabel() {
				return Policy.bind("CVSAddResolutionGenerator.Add_Resource_to_CVS_1"); //$NON-NLS-1$
			}
			public void run(IMarker marker) {
				try {
					final IResource resource = marker.getResource();
					ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
					final TeamException[] exception = new TeamException[] {null};
					if ( ! cvsResource.isManaged()) {
						CVSAddResolutionGenerator.this.run(new IRunnableWithProgress() {
							public void run(IProgressMonitor monitor)throws InvocationTargetException, InterruptedException {
								try {
									((CVSTeamProvider)RepositoryProvider.getProvider(resource.getProject())).add(new IResource[] {resource}, IResource.DEPTH_ZERO, monitor);
								} catch (TeamException e) {
									exception[0] = e;
								}
							}
						});
					}
					if (exception[0] != null) {
						throw exception[0];
					}
					marker.delete();
				} catch (TeamException e) {
					handle(e, null, null);
				} catch (CoreException e) {
					handle(e, null, null);
				} catch (InvocationTargetException e) {
					handle(e, null, null);
				}  catch (InterruptedException e) {
					// do nothing
				}
			}
		};
		IMarkerResolution manageDeep = new IMarkerResolution() {
			public String getLabel() {
				return Policy.bind("CVSAddResolutionGenerator.Add_Resource_and_Children_to_CVS_2"); //$NON-NLS-1$
			}
			public void run(IMarker marker) {
				try {
					final IResource resource = marker.getResource();
					ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
					final TeamException[] exception = new TeamException[] {null};
					if ( ! cvsResource.isManaged()) {
						CVSAddResolutionGenerator.this.run(new IRunnableWithProgress() {
							public void run(IProgressMonitor monitor)throws InvocationTargetException, InterruptedException {
								try {
									((CVSTeamProvider)RepositoryProvider.getProvider(resource.getProject())).add(new IResource[] {resource}, IResource.DEPTH_INFINITE, monitor);
								} catch (TeamException e) {
									exception[0] = e;
								}
							}
						});
					}
					if (exception[0] != null) {
						throw exception[0];
					}
					marker.delete();
				} catch (TeamException e) {
					handle(e, null, null);
				} catch (CoreException e) {
					handle(e, null, null);
				} catch (InvocationTargetException e) {
					handle(e, null, null);
				}  catch (InterruptedException e) {
					// do nothing
				}
			}

		};
		IMarkerResolution ignore =  new IMarkerResolution() {
			public String getLabel() {
				return Policy.bind("CVSAddResolutionGenerator.Add_to_.cvsignore_3"); //$NON-NLS-1$
			}
			public void run(IMarker marker) {
				try {
					ICVSResource resource = CVSWorkspaceRoot.getCVSResourceFor(marker.getResource());
					if ( resource.isManaged()) {
						resource.unmanage(null);
					}
					resource.setIgnored();
					marker.delete();
				} catch (CVSException e) {
					handle(e, null, null);
				} catch (CoreException e) {
					handle(e, null, null);
				}
			}

		};
		if (marker.getResource().getType() == IResource.FILE) {
			return new IMarkerResolution[] {manage, ignore};
		} else {
			return new IMarkerResolution[] {manageDeep, manage, ignore};
		}
	}
}

Back to the top