KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > simple > actions > SimpleCSRemoveStepAction


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.simple.actions;
13
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCS;
16 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSItem;
17 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
18 import org.eclipse.pde.internal.ui.PDEUIMessages;
19
20 /**
21  * SimpleCSAddStepAction
22  *
23  */

24 public class SimpleCSRemoveStepAction extends Action {
25
26     private ISimpleCSItem fItem;
27     
28     private ISimpleCSObject fObjectToSelect;
29     
30     /**
31      *
32      */

33     public SimpleCSRemoveStepAction() {
34         setText(PDEUIMessages.SimpleCSRemoveStepAction_0);
35         // TODO: MP: LOW: SimpleCS: Add tool-tip / image ?
36
// setImageDescriptor(PDEPluginImages.DESC_GEL_SC_OBJ);
37
// setToolTipText(PDEUIMessages.SchemaEditor_NewElement_tooltip);
38
fItem = null;
39         fObjectToSelect = null;
40     }
41
42     /**
43      * @param cheatsheet
44      */

45     public void setItem(ISimpleCSItem item) {
46         fItem = item;
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.jface.action.Action#run()
51      */

52     public void run() {
53         if (fItem != null) {
54             // Parent can only be a cheat sheet
55
ISimpleCS cheatsheet = (ISimpleCS)fItem.getParent();
56             // Determine the item to select after the deletion takes place
57
determineItemToSelect(cheatsheet);
58             // Remove the item
59
cheatsheet.removeItem(fItem);
60         }
61     }
62     
63     /**
64      * @param cheatsheet
65      */

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

84     public ISimpleCSObject getObjectToSelect() {
85         return fObjectToSelect;
86     }
87 }
88
Popular Tags