Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 692159068bfe42a3d8d5a924b3ecfd7f5f67d9ea (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
/*******************************************************************************
 * Copyright (c) 2003, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.repo;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ccvs.ui.actions.CVSAction;
import org.eclipse.team.internal.ccvs.ui.model.CVSTagElement;
import org.eclipse.ui.actions.SelectionListenerAction;


public class RemoveDateTagAction extends SelectionListenerAction {
	private IStructuredSelection selection;
	
	public RemoveDateTagAction() {
		super(Policy.bind("RemoveDateTagAction.0")); //$NON-NLS-1$
	}

	public void run() {
		CVSTagElement[] elements = getSelectedCVSTagElements();
		if (elements.length == 0) return;
		for(int i = 0; i < elements.length; i++){
			RepositoryManager mgr = CVSUIPlugin.getPlugin().getRepositoryManager();
			CVSTag tag = elements[i].getTag();
			if(tag.getType() == CVSTag.DATE){
				mgr.removeDateTag(elements[i].getRoot(),tag);
			}				
		}
	}

	protected boolean updateSelection(IStructuredSelection selection) {
		this.selection = selection;
		boolean b = containsDataTag();
		setEnabled(b);
		return b;
	}
	
	private boolean containsDataTag(){
		CVSTagElement[] elements = getSelectedCVSTagElements();
		if (elements.length > 0){ 		
			for(int i = 0; i < elements.length; i++){
				CVSTag tag = elements[i].getTag();
				if(tag.getType() == CVSTag.DATE){
					return true;
				}				
			}
		}
		return false;
	}
	
	/**
	 * Returns the selected CVS date tag elements
	 */
	private CVSTagElement[] getSelectedCVSTagElements() {
		ArrayList cvsTagElements = null;
		if (selection!=null && !selection.isEmpty()) {
			cvsTagElements = new ArrayList();
			Iterator elements = selection.iterator();
			while (elements.hasNext()) {
				Object next = CVSAction.getAdapter(elements.next(), CVSTagElement.class);
				if (next instanceof CVSTagElement) {
					cvsTagElements.add(next);
				}
			}
		}
		if (cvsTagElements != null && !cvsTagElements.isEmpty()) {
			CVSTagElement[] result = new CVSTagElement[cvsTagElements.size()];
			cvsTagElements.toArray(result);
			return result;
		}
		return new CVSTagElement[0];
	}
}

Back to the top