KickJava   Java API By Example, From Geeks To Geeks.

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


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.ISimpleCSConditionalSubItem;
16 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
17 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSItem;
18 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
19 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSRepeatedSubItem;
20 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSSubItem;
21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSSubItemObject;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23
24 /**
25  * SimpleCSAddStepAction
26  *
27  */

28 public class SimpleCSRemoveSubStepAction extends Action {
29
30     private ISimpleCSSubItemObject fSubItem;
31
32     private ISimpleCSObject fObjectToSelect;
33     
34     /**
35      *
36      */

37     public SimpleCSRemoveSubStepAction() {
38         // TODO: MP: LOW: SimpleCS: Add tool-tip / image ?
39
setText(PDEUIMessages.SimpleCSRemoveSubStepAction_0);
40 // setImageDescriptor(PDEPluginImages.DESC_GEL_SC_OBJ);
41
// setToolTipText(PDEUIMessages.SchemaEditor_NewElement_tooltip);
42
fSubItem = null;
43         fObjectToSelect = null;
44     }
45
46     /**
47      * @param subitem
48      */

49     public void setSubItem(ISimpleCSSubItemObject subitem) {
50         fSubItem = subitem;
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.jface.action.Action#run()
55      */

56     public void run() {
57         if (fSubItem != null) {
58             // Determine parent type and remove accordingly
59
ISimpleCSObject parent = fSubItem.getParent();
60             if (parent.getType() == ISimpleCSConstants.TYPE_ITEM) {
61                 // Parent is an item
62
ISimpleCSItem item = (ISimpleCSItem)parent;
63                 // Determine the item to select after the deletion takes place
64
determineItemToSelect(item);
65                 // Remove the subitem
66
item.removeSubItem(fSubItem);
67             } else if ((parent.getType() == ISimpleCSConstants.TYPE_REPEATED_SUBITEM) &&
68                     (fSubItem.getType() == ISimpleCSConstants.TYPE_SUBITEM)) {
69                 // Parent is a repeated subitem
70
ISimpleCSRepeatedSubItem subitem = (ISimpleCSRepeatedSubItem)parent;
71                 // Determine the item to select after the deletion takes place
72
determineItemToSelect(subitem);
73                 // Remove the subitem
74
subitem.setSubItem(null);
75             } else if ((parent.getType() == ISimpleCSConstants.TYPE_CONDITIONAL_SUBITEM) &&
76                     (fSubItem.getType() == ISimpleCSConstants.TYPE_SUBITEM)) {
77                 // Parent is a conditional subitem
78
ISimpleCSConditionalSubItem subitem = (ISimpleCSConditionalSubItem)parent;
79                 // Determine the item to select after the deletion takes place
80
determineItemToSelect(subitem);
81                 // Remove the subitem
82
subitem.removeSubItem((ISimpleCSSubItem)fSubItem);
83             }
84         }
85     }
86
87     /**
88      * @param item
89      */

90     private void determineItemToSelect(ISimpleCSItem item) {
91         // Select the next sibling
92
fObjectToSelect = item.getNextSibling(fSubItem);
93         if (fObjectToSelect == null) {
94             // No next sibling
95
// Select the previous sibling
96
fObjectToSelect = item.getPreviousSibling(fSubItem);
97             if (fObjectToSelect == null) {
98                 // No previous sibling
99
// Select the parent
100
fObjectToSelect = item;
101             }
102         }
103     }
104     
105     /**
106      * @param item
107      */

108     private void determineItemToSelect(ISimpleCSObject object) {
109         // The parent itself
110
fObjectToSelect = object;
111     }
112     
113     /**
114      * @return
115      */

116     public ISimpleCSObject getObjectToSelect() {
117         return fObjectToSelect;
118     }
119     
120 }
121
Popular Tags