1 11 12 package org.eclipse.pde.internal.core.cheatsheet.simple; 13 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.List ; 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 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 TAG_EXCEPTIONS = new HashSet (3); 37 38 protected static final HashMap SUBSTITUTE_CHARS = new HashMap (5); 39 40 41 static { 42 TAG_EXCEPTIONS.add("b"); TAG_EXCEPTIONS.add("/b"); TAG_EXCEPTIONS.add("br/"); 46 SUBSTITUTE_CHARS.put(new Character ('&'), "&"); SUBSTITUTE_CHARS.put(new Character ('<'), "<"); SUBSTITUTE_CHARS.put(new Character ('>'), ">"); SUBSTITUTE_CHARS.put(new Character ('\''), "'"); SUBSTITUTE_CHARS.put(new Character ('\"'), """); } 52 53 56 public SimpleCSObject(ISimpleCSModel model, ISimpleCSObject parent) { 57 fModel = model; 58 fParent = parent; 59 } 60 61 64 public ISimpleCSModel getModel() { 65 return fModel; 66 } 67 68 71 public ISimpleCS getSimpleCS() { 72 return fModel.getSimpleCS(); 73 } 74 75 78 public void setModel(ISimpleCSModel model) { 79 fModel = model; 80 } 81 82 87 protected void firePropertyChanged(String property, Object oldValue, 88 Object newValue) { 89 firePropertyChanged(this, property, oldValue, newValue); 90 } 91 92 98 private void firePropertyChanged(ISimpleCSObject object, String property, 99 Object oldValue, Object newValue) { 100 if (fModel.isEditable()) { 101 IModelChangeProvider provider = fModel; 102 provider.fireModelObjectChanged(object, property, oldValue, newValue); 103 } 104 } 105 106 110 protected void fireStructureChanged(ISimpleCSObject child, int changeType) { 111 fireStructureChanged(new ISimpleCSObject[] { child }, changeType); 112 } 113 114 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 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 150 protected boolean isEditable() { 151 return fModel.isEditable(); 152 } 153 154 157 public ISimpleCSObject getParent() { 158 return fParent; 159 } 160 161 164 public abstract int getType(); 165 166 169 public abstract String getName(); 170 171 174 public abstract List getChildren(); 175 176 } 177 | Popular Tags |