KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > views > actions > RemoveProjectAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ant.internal.ui.views.actions;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import org.eclipse.ant.internal.ui.AntUIImages;
16 import org.eclipse.ant.internal.ui.IAntUIConstants;
17 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
18 import org.eclipse.ant.internal.ui.model.AntProjectNode;
19 import org.eclipse.ant.internal.ui.views.AntView;
20 import org.eclipse.jface.action.Action;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.texteditor.IUpdate;
24
25 /**
26  * Action that removes selected build files from an <code>AntView</code>
27  */

28 public class RemoveProjectAction extends Action implements IUpdate {
29     
30     private AntView view;
31     
32     public RemoveProjectAction(AntView view) {
33         super(AntViewActionMessages.RemoveProjectAction_Remove, AntUIImages.getImageDescriptor(IAntUIConstants.IMG_REMOVE));
34         this.view= view;
35         setToolTipText(AntViewActionMessages.RemoveProjectAction_Remove_2);
36         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IAntUIHelpContextIds.REMOVE_PROJECT_ACTION);
37     }
38
39     /**
40      * @see org.eclipse.jface.action.IAction#run()
41      */

42     public void run() {
43         IStructuredSelection selection= (IStructuredSelection) view.getViewer().getSelection();
44         Iterator JavaDoc iter= selection.iterator();
45         Object JavaDoc element;
46         List JavaDoc projectNodes= new ArrayList JavaDoc();
47         while (iter.hasNext()) {
48             element= iter.next();
49             if (element instanceof AntProjectNode) {
50                 projectNodes.add(element);
51             }
52         }
53         view.removeProjects(projectNodes);
54     }
55     
56     /**
57      * @see org.eclipse.ui.texteditor.IUpdate#update()
58      */

59     public void update() {
60         IStructuredSelection selection= (IStructuredSelection) view.getViewer().getSelection();
61         if (selection.isEmpty()) {
62             setEnabled(false);
63             return;
64         }
65         Object JavaDoc element;
66         Iterator JavaDoc iter= selection.iterator();
67         while (iter.hasNext()) {
68             element= iter.next();
69             if (!(element instanceof AntProjectNode)) {
70                 setEnabled(false);
71                 return;
72             }
73         }
74         setEnabled(true);
75     }
76     
77 }
78
Popular Tags