david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2001, 2005 IBM Corporation and others. |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 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 |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 7 | * |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 15 | package org.eclipse.wst.dtd.ui.internal.views.contentoutline.actions; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 16 | |
| 17 | import org.eclipse.jface.viewers.IStructuredSelection; |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 18 | import org.eclipse.wst.dtd.core.internal.CMGroupNode; |
| 19 | import org.eclipse.wst.dtd.core.internal.DTDNode; |
| 20 | import org.eclipse.wst.dtd.core.internal.Element; |
nitind | cff4940 | 2005-12-29 21:11:28 +0000 | [diff] [blame] | 21 | import org.eclipse.wst.dtd.core.internal.document.DTDModelImpl; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 22 | |
| 23 | |
| 24 | public class AddElementToContentModelAction extends BaseAction { |
| 25 | |
nitind | cff4940 | 2005-12-29 21:11:28 +0000 | [diff] [blame] | 26 | public AddElementToContentModelAction(DTDModelImpl model, String label) { |
| 27 | super(model, label); |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | public void run() { |
| 31 | DTDNode node = getFirstNodeSelected(); |
| 32 | |
| 33 | if (node instanceof CMGroupNode) { |
| 34 | ((CMGroupNode) node).addChild(); |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 35 | } |
| 36 | else if (node instanceof Element) { |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 37 | ((Element) node).addChild(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | protected boolean updateSelection(IStructuredSelection selection) { |
| 42 | boolean rc = super.updateSelection(selection); |
| 43 | DTDNode node = getFirstNodeSelected(selection); |
| 44 | if (node instanceof CMGroupNode) { |
| 45 | setEnabled(true); |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 46 | } |
| 47 | else { |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 48 | setEnabled(false); |
| 49 | } |
| 50 | return rc; |
| 51 | } |
| 52 | } |