KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > repo > RemoveDateTagAction


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.ccvs.ui.repo;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.team.internal.ccvs.core.CVSTag;
18 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
19 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
20 import org.eclipse.team.internal.ccvs.ui.model.CVSTagElement;
21 import org.eclipse.team.internal.ui.actions.TeamAction;
22 import org.eclipse.ui.actions.SelectionListenerAction;
23
24
25 public class RemoveDateTagAction extends SelectionListenerAction {
26     private IStructuredSelection selection;
27     
28     public RemoveDateTagAction() {
29         super(CVSUIMessages.RemoveDateTagAction_0);
30     }
31
32     public void run() {
33         CVSTagElement[] elements = getSelectedCVSTagElements();
34         if (elements.length == 0) return;
35         for(int i = 0; i < elements.length; i++){
36             RepositoryManager mgr = CVSUIPlugin.getPlugin().getRepositoryManager();
37             CVSTag tag = elements[i].getTag();
38             if(tag.getType() == CVSTag.DATE){
39                 mgr.removeDateTag(elements[i].getRoot(),tag);
40             }
41         }
42     }
43
44     protected boolean updateSelection(IStructuredSelection selection) {
45         this.selection = selection;
46         boolean b = containsDataTag();
47         setEnabled(b);
48         return b;
49     }
50     
51     private boolean containsDataTag(){
52         CVSTagElement[] elements = getSelectedCVSTagElements();
53         if (elements.length > 0){
54             for(int i = 0; i < elements.length; i++){
55                 CVSTag tag = elements[i].getTag();
56                 if(tag.getType() == CVSTag.DATE){
57                     return true;
58                 }
59             }
60         }
61         return false;
62     }
63     
64     /**
65      * Returns the selected CVS date tag elements
66      */

67     private CVSTagElement[] getSelectedCVSTagElements() {
68         ArrayList JavaDoc cvsTagElements = null;
69         if (selection!=null && !selection.isEmpty()) {
70             cvsTagElements = new ArrayList JavaDoc();
71             Iterator JavaDoc elements = selection.iterator();
72             while (elements.hasNext()) {
73                 Object JavaDoc next = TeamAction.getAdapter(elements.next(), CVSTagElement.class);
74                 if (next instanceof CVSTagElement) {
75                     cvsTagElements.add(next);
76                 }
77             }
78         }
79         if (cvsTagElements != null && !cvsTagElements.isEmpty()) {
80             CVSTagElement[] result = new CVSTagElement[cvsTagElements.size()];
81             cvsTagElements.toArray(result);
82             return result;
83         }
84         return new CVSTagElement[0];
85     }
86 }
87
Popular Tags