Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: f6dbe8117f2bdee001f59d1f7fcbe4ff47998e70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.commands;

import org.w3c.dom.Element;

/*
 * This command is used from the extension view to edit extension elements
 * and attributes which are implemented as DOM objects (not part of the EMF model)
 * 
 * (trung) also used in XSDComplexTypeAdvancedSection to change attribute of
 * specical attributes like block, restriction which is not part of EMF Model
 */
public class UpdateAttributeValueCommand  extends BaseCommand
{
  Element element;
  String attributeName;
  String attributeValue;
  
  /** Whether the attribute should be deleted if value to 
   *   be set is an empty String or null  */
  protected boolean deleteIfValueEmpty = false;
  
  public UpdateAttributeValueCommand(Element element, String attributeName, String attributeValue, boolean deleteIfValueEmpty)
  {
    this.element = element;
    this.attributeName = attributeName;
    this.attributeValue = attributeValue;
    this.deleteIfValueEmpty = deleteIfValueEmpty;
  }
  
  public UpdateAttributeValueCommand(Element element, String attributeName, String attributeValue)
  {
    this(element, attributeName, attributeValue, false);       
  }

  public void setDeleteIfEmpty(boolean v)
  {
	deleteIfValueEmpty = v;
  }
  
  public void execute()
  {
    try
    {
      beginRecording(element);
      if (deleteIfValueEmpty && 
    		  (attributeValue == null || attributeValue.equals("") ) )
      {
    	element.removeAttribute(attributeName);
      }
      else
      {
        element.setAttribute(attributeName, attributeValue);
      }
    }
    finally
    {
      endRecording();
    }
  } 
}

Back to the top