intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.css.ui / src / net / sourceforge / phpeclipse / css / ui / internal / compare / CssNode.java
1 /*
2  * Copyright (c) 2003-2004 Christopher Lenz and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: CssNode.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.css.ui.internal.compare;
15
16 import net.sourceforge.phpeclipse.css.ui.CssUI;
17 import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
18
19 import org.eclipse.compare.ITypedElement;
20 import org.eclipse.compare.structuremergeviewer.DocumentRangeNode;
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.swt.graphics.Image;
23
24 /**
25  * 
26  */
27 public class CssNode extends DocumentRangeNode implements ITypedElement {
28
29         // Constants ---------------------------------------------------------------
30
31         /**
32          * Type code for the top-level style sheet.
33          */
34         public static final int STYLE_SHEET = 0;
35
36         /**
37          * Type code for at rules.
38          */
39         public static final int AT_RULE = 1;
40
41         /**
42          * Type code for style rules.
43          */
44         public static final int STYLE_RULE = 2;
45
46         /**
47          * Type code for declarations (property-value assignment).
48          */
49         public static final int DECLARATION = 3;
50
51         // Instance Variables ------------------------------------------------------
52
53         /**
54          * The display name of the node.
55          */
56         private String name;
57
58         // Constructors ------------------------------------------------------------
59
60         /**
61          * Constructor for the top-level style sheet node.
62          * 
63          * @param document The document
64          */
65         public CssNode(IDocument document) {
66                 super(STYLE_SHEET, "root", document, 0, //$NON-NLS-1$
67                         document.getLength());
68         }
69
70         /**
71          * Constructor.
72          * 
73          * @param parent 
74          * @param typeCode
75          * @param id
76          * @param name
77          * @param start
78          * @param length
79          */
80         public CssNode(CssNode parent, int typeCode, String id, String name,
81                 int start, int length) {
82                 super(typeCode, parent.getId() + Integer.toString(typeCode) + id,
83                         parent.getDocument(), start, length);
84                 this.name = name;
85         }
86
87         /**
88          * @see org.eclipse.compare.ITypedElement#getName()
89          */
90         public String getName() {
91                 if (getTypeCode() == STYLE_SHEET) {
92                         return CssUIMessages.getString(
93                                 "CssStructureViewer.styleSheet"); //$NON-NLS-1$
94                 }
95                 return name;
96         }
97
98         /**
99          * @see org.eclipse.compare.ITypedElement#getImage()
100          */
101         public Image getImage() {
102                 String key = null;
103                 switch (getTypeCode()) {
104                         case STYLE_SHEET: {
105                                 key = CssUI.ICON_STYLE_SHEET;
106                                 break;
107                         }
108                         case AT_RULE: {
109                                 key = CssUI.ICON_AT_RULE;
110                                 break;
111                         }
112                         case STYLE_RULE: {
113                                 key = CssUI.ICON_STYLE_RULE;
114                                 break;
115                         }
116                         case DECLARATION: {
117                                 key = CssUI.ICON_PROPERTY;
118                                 break;
119                         }
120                         default: {
121                                 // we'll just return null
122                         }
123                 }
124                 return CssUI.getDefault().getImageRegistry().get(key);
125         }
126
127         /**
128          * @see org.eclipse.compare.ITypedElement#getType()
129          */
130         public String getType() {
131                 return "css"; //$NON-NLS-1$
132         }
133
134 }