KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > cheatsheet > simple > SimpleCSObject


1 /*******************************************************************************
2  * Copyright (c) 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  *******************************************************************************/

11
12 package org.eclipse.pde.internal.core.cheatsheet.simple;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.runtime.PlatformObject;
19 import org.eclipse.pde.core.IModelChangeProvider;
20 import org.eclipse.pde.core.IModelChangedEvent;
21 import org.eclipse.pde.core.ModelChangedEvent;
22 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCS;
23 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
24 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
25
26 /**
27  * SimpleCSObject
28  *
29  */

30 public abstract class SimpleCSObject extends PlatformObject implements ISimpleCSObject {
31
32     private transient ISimpleCSModel fModel;
33     
34     private transient ISimpleCSObject fParent;
35
36     protected static final HashSet JavaDoc TAG_EXCEPTIONS = new HashSet JavaDoc(3);
37     
38     protected static final HashMap JavaDoc SUBSTITUTE_CHARS = new HashMap JavaDoc(5);
39
40     
41     static {
42         TAG_EXCEPTIONS.add("b"); //$NON-NLS-1$
43
TAG_EXCEPTIONS.add("/b"); //$NON-NLS-1$
44
TAG_EXCEPTIONS.add("br/"); //$NON-NLS-1$
45

46         SUBSTITUTE_CHARS.put(new Character JavaDoc('&'), "&"); //$NON-NLS-1$
47
SUBSTITUTE_CHARS.put(new Character JavaDoc('<'), "&lt;"); //$NON-NLS-1$
48
SUBSTITUTE_CHARS.put(new Character JavaDoc('>'), "&gt;"); //$NON-NLS-1$
49
SUBSTITUTE_CHARS.put(new Character JavaDoc('\''), "&apos;"); //$NON-NLS-1$
50
SUBSTITUTE_CHARS.put(new Character JavaDoc('\"'), "&quot;"); //$NON-NLS-1$
51
}
52     
53     /**
54      *
55      */

56     public SimpleCSObject(ISimpleCSModel model, ISimpleCSObject parent) {
57         fModel = model;
58         fParent = parent;
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getModel()
63      */

64     public ISimpleCSModel getModel() {
65         return fModel;
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getSimpleCS()
70      */

71     public ISimpleCS getSimpleCS() {
72         return fModel.getSimpleCS();
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#setModel(org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel)
77      */

78     public void setModel(ISimpleCSModel model) {
79         fModel = model;
80     }
81
82     /**
83      * @param property
84      * @param oldValue
85      * @param newValue
86      */

87     protected void firePropertyChanged(String JavaDoc property, Object JavaDoc oldValue,
88             Object JavaDoc newValue) {
89         firePropertyChanged(this, property, oldValue, newValue);
90     }
91         
92     /**
93      * @param object
94      * @param property
95      * @param oldValue
96      * @param newValue
97      */

98     private void firePropertyChanged(ISimpleCSObject object, String JavaDoc property,
99         Object JavaDoc oldValue, Object JavaDoc newValue) {
100         if (fModel.isEditable()) {
101             IModelChangeProvider provider = fModel;
102             provider.fireModelObjectChanged(object, property, oldValue, newValue);
103         }
104     }
105         
106     /**
107      * @param child
108      * @param changeType
109      */

110     protected void fireStructureChanged(ISimpleCSObject child, int changeType) {
111         fireStructureChanged(new ISimpleCSObject[] { child }, changeType);
112     }
113     
114     /**
115      * @param newValue
116      * @param oldValue
117      * @param changeType
118      */

119     protected void fireStructureChanged(ISimpleCSObject newValue,
120             ISimpleCSObject oldValue) {
121
122         int changeType = -1;
123         ISimpleCSObject object = null;
124         if (newValue == null) {
125             changeType = IModelChangedEvent.REMOVE;
126             object = oldValue;
127         } else {
128             changeType = IModelChangedEvent.INSERT;
129             object = newValue;
130         }
131         fireStructureChanged(object, changeType);
132     }
133     
134     /**
135      * @param children
136      * @param changeType
137      */

138     private void fireStructureChanged(ISimpleCSObject[] children,
139             int changeType) {
140         if (fModel.isEditable()) {
141             IModelChangeProvider provider = fModel;
142             provider.fireModelChanged(new ModelChangedEvent(provider,
143                     changeType, children, null));
144         }
145     }
146         
147     /**
148      * @return
149      */

150     protected boolean isEditable() {
151         return fModel.isEditable();
152     }
153     
154     /* (non-Javadoc)
155      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getParent()
156      */

157     public ISimpleCSObject getParent() {
158         return fParent;
159     }
160     
161     /* (non-Javadoc)
162      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getType()
163      */

164     public abstract int getType();
165     
166     /* (non-Javadoc)
167      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getName()
168      */

169     public abstract String JavaDoc getName();
170     
171     /* (non-Javadoc)
172      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getChildren()
173      */

174     public abstract List JavaDoc getChildren();
175
176 }
177
Popular Tags