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: d1735482056cf465aa99ed22bdb62e9aea01cbc3 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2001, 2007 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.properties.sections.appinfo;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeCustomizationRegistry;
import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;

public class DOMExtensionTreeLabelProvider extends LabelProvider
{
  protected static final Image DEFAULT_ELEMENT_ICON = XSDEditorPlugin.getXSDImage("icons/XSDElement.gif"); //$NON-NLS-1$
  protected static final Image DEFAULT_ATTR_ICON = XSDEditorPlugin.getXSDImage("icons/XSDAttribute.gif"); //$NON-NLS-1$
    
  public DOMExtensionTreeLabelProvider()
  {    
  }
  
  public Image getImage(Object element)
  {
    NodeCustomizationRegistry registry = XSDEditorPlugin.getDefault().getNodeCustomizationRegistry();
    if (element instanceof Element)
    {
      Element domElement = (Element) element;
      String namespace = domElement.getNamespaceURI();
      if (namespace != null)
      {  
        ILabelProvider lp = registry.getLabelProvider(namespace);
        if (lp != null)
        {
          Image img = lp.getImage(domElement);
          if (img != null)
            return img;
        }  
      }
      return DEFAULT_ELEMENT_ICON;
    }
    if (element instanceof Attr)
    return DEFAULT_ATTR_ICON;
    return null;
  }

  public String getText(Object input)
  {
    if (input instanceof Element)
    {
      Element domElement = (Element) input;
      String textVal = "";

      if (domElement.hasChildNodes())
      {
        Node node = domElement.getChildNodes().item(0);
        if (node instanceof Text)
        {
          Text textNode = (Text) node;
          try
          {
            if (!textNode.getNodeValue().contains("\n"))
              textVal = " [" + textNode.getNodeValue() + "]";
          }
          catch (DOMException e)
          {
            textVal = "";
          }
        }
      }
      return domElement.getLocalName() + textVal;
    }
    if ( input instanceof Attr){
      return ((Attr) input).getLocalName();
    }
    return ""; //$NON-NLS-1$
  }
}

Back to the top