KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > comp > actions > CompCSRemoveTaskObjectAction


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.pde.internal.ui.editor.cheatsheet.comp.actions;
13
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
16 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
17 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskGroup;
18 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20
21 /**
22  * SimpleCSAddStepAction
23  *
24  */

25 public class CompCSRemoveTaskObjectAction extends Action {
26
27     private ICompCSTaskObject fTaskObject;
28
29     private ICompCSObject fObjectToSelect;
30     
31     /**
32      *
33      */

34     public CompCSRemoveTaskObjectAction() {
35         setText(PDEUIMessages.SimpleCSRemoveSubStepAction_0);
36         fTaskObject = null;
37         fObjectToSelect = null;
38     }
39
40     /**
41      * @param subitem
42      */

43     public void setTaskObject(ICompCSTaskObject taskObject) {
44         fTaskObject = taskObject;
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.jface.action.Action#run()
49      */

50     public void run() {
51         if (fTaskObject != null) {
52             ICompCSObject parent = fTaskObject.getParent();
53             if (parent.getType() == ICompCSConstants.TYPE_TASKGROUP) {
54                 // Parent is a group
55
ICompCSTaskGroup group = (ICompCSTaskGroup)parent;
56                 // Determine the object to select after the deletion
57
// takes place
58
determineItemToSelect(group);
59                 // Remove the subitem
60
group.removeFieldTaskObject(fTaskObject);
61             }
62         }
63     }
64
65     /**
66      * @param item
67      */

68     private void determineItemToSelect(ICompCSTaskGroup group) {
69         // Select the next sibling
70
fObjectToSelect = group.getNextSibling(fTaskObject);
71         if (fObjectToSelect == null) {
72             // No next sibling
73
// Select the previous sibling
74
fObjectToSelect = group.getPreviousSibling(fTaskObject);
75             if (fObjectToSelect == null) {
76                 // No previous sibling
77
// Select the parent
78
fObjectToSelect = group;
79             }
80         }
81     }
82     
83     /**
84      * @return
85      */

86     public ICompCSObject getObjectToSelect() {
87         return fObjectToSelect;
88     }
89     
90 }
91
Popular Tags