1 /*******************************************************************************2 * Copyright (c) 2006 IBM Corporation and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Eclipse Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/epl-v10.html7 *8 * Contributors:9 * IBM Corporation - initial API and implementation10 *******************************************************************************/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 * SimpleCSAddStepAction26 *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 subitem48 */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 item62 ISimpleCSItem item = (ISimpleCSItem)parent;63 // Determine the item to select after the deletion takes place 64 determineItemToSelect(item);65 // Remove the subitem66 item.removeSubItem(fSubItem);67 } else if ((parent.getType() == ISimpleCSConstants.TYPE_REPEATED_SUBITEM) &&68 (fSubItem.getType() == ISimpleCSConstants.TYPE_SUBITEM)) {69 // Parent is a repeated subitem70 ISimpleCSRepeatedSubItem subitem = (ISimpleCSRepeatedSubItem)parent;71 // Determine the item to select after the deletion takes place 72 determineItemToSelect(subitem);73 // Remove the subitem74 subitem.setSubItem(null);75 } else if ((parent.getType() == ISimpleCSConstants.TYPE_CONDITIONAL_SUBITEM) &&76 (fSubItem.getType() == ISimpleCSConstants.TYPE_SUBITEM)) {77 // Parent is a conditional subitem78 ISimpleCSConditionalSubItem subitem = (ISimpleCSConditionalSubItem)parent;79 // Determine the item to select after the deletion takes place 80 determineItemToSelect(subitem);81 // Remove the subitem82 subitem.removeSubItem((ISimpleCSSubItem)fSubItem);83 }84 }85 }86 87 /**88 * @param item89 */90 private void determineItemToSelect(ISimpleCSItem item) {91 // Select the next sibling92 fObjectToSelect = item.getNextSibling(fSubItem);93 if (fObjectToSelect == null) {94 // No next sibling95 // Select the previous sibling96 fObjectToSelect = item.getPreviousSibling(fSubItem);97 if (fObjectToSelect == null) {98 // No previous sibling99 // Select the parent100 fObjectToSelect = item;101 }102 }103 }104 105 /**106 * @param item107 */108 private void determineItemToSelect(ISimpleCSObject object) {109 // The parent itself110 fObjectToSelect = object;111 }112 113 /**114 * @return115 */116 public ISimpleCSObject getObjectToSelect() {117 return fObjectToSelect;118 } 119 120 }121