01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.cheatsheet.simple.actions;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCS;
14: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSItem;
15: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
16: import org.eclipse.pde.internal.ui.PDEUIMessages;
17:
18: /**
19: * SimpleCSAddStepAction
20: *
21: */
22: public class SimpleCSRemoveStepAction extends Action {
23:
24: private ISimpleCSItem fItem;
25:
26: private ISimpleCSObject fObjectToSelect;
27:
28: /**
29: *
30: */
31: public SimpleCSRemoveStepAction() {
32: setText(PDEUIMessages.SimpleCSRemoveStepAction_0);
33: // TODO: MP: LOW: SimpleCS: Add tool-tip / image ?
34: // setImageDescriptor(PDEPluginImages.DESC_GEL_SC_OBJ);
35: // setToolTipText(PDEUIMessages.SchemaEditor_NewElement_tooltip);
36: fItem = null;
37: fObjectToSelect = null;
38: }
39:
40: /**
41: * @param cheatsheet
42: */
43: public void setItem(ISimpleCSItem item) {
44: fItem = item;
45: }
46:
47: /* (non-Javadoc)
48: * @see org.eclipse.jface.action.Action#run()
49: */
50: public void run() {
51: if (fItem != null) {
52: // Parent can only be a cheat sheet
53: ISimpleCS cheatsheet = (ISimpleCS) fItem.getParent();
54: // Determine the item to select after the deletion takes place
55: determineItemToSelect(cheatsheet);
56: // Remove the item
57: cheatsheet.removeItem(fItem);
58: }
59: }
60:
61: /**
62: * @param cheatsheet
63: */
64: private void determineItemToSelect(ISimpleCS cheatsheet) {
65: // Select the next sibling
66: fObjectToSelect = cheatsheet.getNextSibling(fItem);
67: if (fObjectToSelect == null) {
68: // No next sibling
69: // Select the previous sibling
70: fObjectToSelect = cheatsheet.getPreviousSibling(fItem);
71: if (fObjectToSelect == null) {
72: // No previous sibling
73: // Select the parent
74: fObjectToSelect = cheatsheet;
75: }
76: }
77: }
78:
79: /**
80: * @return
81: */
82: public ISimpleCSObject getObjectToSelect() {
83: return fObjectToSelect;
84: }
85: }
|