blob: c398cf9fb2ea3e005b20b925657918c24cf07d8b [file] [log] [blame]
david_williamscfdb2cd2004-11-11 08:37:49 +00001/*******************************************************************************
amywuecebb042007-04-10 20:07:35 +00002 * Copyright (c) 2001, 2005 IBM Corporation and others.
david_williamscfdb2cd2004-11-11 08:37:49 +00003 * 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
amywuecebb042007-04-10 20:07:35 +00007 *
david_williamscfdb2cd2004-11-11 08:37:49 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
13
14
nitindd6e591d2005-03-14 22:21:57 +000015package org.eclipse.wst.dtd.ui.internal.views.contentoutline.actions;
david_williamscfdb2cd2004-11-11 08:37:49 +000016
17import org.eclipse.jface.viewers.IStructuredSelection;
nitindd6e591d2005-03-14 22:21:57 +000018import org.eclipse.wst.dtd.core.internal.CMGroupNode;
19import org.eclipse.wst.dtd.core.internal.DTDNode;
20import org.eclipse.wst.dtd.core.internal.Element;
nitindcff49402005-12-29 21:11:28 +000021import org.eclipse.wst.dtd.core.internal.document.DTDModelImpl;
david_williamscfdb2cd2004-11-11 08:37:49 +000022
23
24public class AddElementToContentModelAction extends BaseAction {
25
nitindcff49402005-12-29 21:11:28 +000026 public AddElementToContentModelAction(DTDModelImpl model, String label) {
27 super(model, label);
david_williamscfdb2cd2004-11-11 08:37:49 +000028 }
29
30 public void run() {
31 DTDNode node = getFirstNodeSelected();
32
33 if (node instanceof CMGroupNode) {
34 ((CMGroupNode) node).addChild();
nitindd6e591d2005-03-14 22:21:57 +000035 }
36 else if (node instanceof Element) {
david_williamscfdb2cd2004-11-11 08:37:49 +000037 ((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);
nitindd6e591d2005-03-14 22:21:57 +000046 }
47 else {
david_williamscfdb2cd2004-11-11 08:37:49 +000048 setEnabled(false);
49 }
50 return rc;
51 }
52}