1 11 package org.eclipse.team.internal.ccvs.ui.repo; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 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 67 private CVSTagElement[] getSelectedCVSTagElements() { 68 ArrayList cvsTagElements = null; 69 if (selection!=null && !selection.isEmpty()) { 70 cvsTagElements = new ArrayList (); 71 Iterator elements = selection.iterator(); 72 while (elements.hasNext()) { 73 Object 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 |