blob: 66636465dbbb9882e9731f382d6215309b6ccec7 [file] [log] [blame]
csalter9b7e1092006-07-29 04:02:26 +00001/*******************************************************************************
2 * Copyright (c) 2001, 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 *******************************************************************************/
11package org.eclipse.wst.xsd.ui.internal.common.commands;
12
csalter9b7e1092006-07-29 04:02:26 +000013import org.eclipse.wst.xml.ui.internal.tabletree.TreeContentHelper;
14import org.w3c.dom.Element;
csalter2a0d5002006-09-20 04:58:29 +000015import org.w3c.dom.Node;
csalter9b7e1092006-07-29 04:02:26 +000016
17/*
18 * This command is used from the extension view to edit extension elements
19 * and which are implemented as DOM objects (not part of the EMF model)
20 */
kchong59966042006-08-21 21:09:18 +000021public class UpdateTextValueCommand extends BaseCommand
csalter9b7e1092006-07-29 04:02:26 +000022{
23 Element element;
24 String value;
25
26 public UpdateTextValueCommand(Element element, String value)
27 {
28 this.element = element;
29 this.value = value;
30 }
31
32
33 public void execute()
34 {
kchong59966042006-08-21 21:09:18 +000035 try
36 {
csalter2a0d5002006-09-20 04:58:29 +000037 beginRecording(element);
38 Node textNode = null;
39 TreeContentHelper helper = new TreeContentHelper();
40 for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling())
41 {
42 if (node.getNodeType() == Node.TEXT_NODE &&
43 !helper.isIgnorableText(node))
44 {
45 textNode = node;
46 break;
47 }
48 }
49 if (textNode == null)
50 {
51 textNode = element.getOwnerDocument().createTextNode("");
52 element.appendChild(textNode);
53 }
54 helper.setNodeValue(textNode, value);
kchong59966042006-08-21 21:09:18 +000055 }
56 finally
57 {
58 endRecording();
59 }
csalter9b7e1092006-07-29 04:02:26 +000060 }
61}