PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/eclipse_SDK-3.7.1/plugins/org.eclipse.pde.ua.core.source_1.0.100.v20110516/org/eclipse/pde/internal/ua/core/cheatsheet/comp/CompCSTaskObject.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 422 lines | 179 code | 40 blank | 203 comment | 29 complexity | 1e3e0e7dffd40a4137fdde55e48dd638 MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2006, 2008 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. package org.eclipse.pde.internal.ua.core.cheatsheet.comp;
  12. import java.io.PrintWriter;
  13. import java.util.ArrayList;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import org.eclipse.pde.core.IModelChangedEvent;
  17. import org.eclipse.pde.internal.core.XMLPrintHandler;
  18. import org.eclipse.pde.internal.core.util.PDETextHelper;
  19. import org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSDependency;
  20. import org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSIntro;
  21. import org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSModel;
  22. import org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSModelFactory;
  23. import org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSObject;
  24. import org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSOnCompletion;
  25. import org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject;
  26. import org.w3c.dom.Element;
  27. import org.w3c.dom.Text;
  28. public abstract class CompCSTaskObject extends CompCSObject implements
  29. ICompCSTaskObject {
  30. private static final long serialVersionUID = 1L;
  31. protected String fFieldId;
  32. protected String fFieldKind;
  33. protected ICompCSIntro fFieldIntro;
  34. protected ICompCSOnCompletion fFieldOnCompletion;
  35. protected String fFieldName;
  36. protected boolean fFieldSkip;
  37. protected ArrayList fFieldDependencies;
  38. /**
  39. * @param model
  40. * @param parent
  41. */
  42. public CompCSTaskObject(ICompCSModel model, ICompCSObject parent) {
  43. super(model, parent);
  44. // Reset called by child class
  45. }
  46. /*
  47. * (non-Javadoc)
  48. *
  49. * @see
  50. * org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#getChildren()
  51. */
  52. public abstract List getChildren();
  53. /*
  54. * (non-Javadoc)
  55. *
  56. * @see org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#getName()
  57. */
  58. public abstract String getName();
  59. /*
  60. * (non-Javadoc)
  61. *
  62. * @see org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#getType()
  63. */
  64. public abstract int getType();
  65. /*
  66. * (non-Javadoc)
  67. *
  68. * @see org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#reset()
  69. */
  70. public void reset() {
  71. fFieldId = null;
  72. fFieldKind = null;
  73. fFieldIntro = null;
  74. fFieldOnCompletion = null;
  75. fFieldName = null;
  76. fFieldSkip = false;
  77. fFieldDependencies = new ArrayList();
  78. }
  79. /*
  80. * (non-Javadoc)
  81. *
  82. * @see org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#
  83. * addFieldDependency
  84. * (org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSDependency)
  85. */
  86. public void addFieldDependency(ICompCSDependency dependency) {
  87. fFieldDependencies.add(dependency);
  88. if (isEditable()) {
  89. fireStructureChanged(dependency, IModelChangedEvent.INSERT);
  90. }
  91. }
  92. /*
  93. * (non-Javadoc)
  94. *
  95. * @see
  96. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#getFieldId
  97. * ()
  98. */
  99. public String getFieldId() {
  100. return fFieldId;
  101. }
  102. /*
  103. * (non-Javadoc)
  104. *
  105. * @see org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#
  106. * getFieldIntro()
  107. */
  108. public ICompCSIntro getFieldIntro() {
  109. return fFieldIntro;
  110. }
  111. /*
  112. * (non-Javadoc)
  113. *
  114. * @see
  115. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#getFieldKind
  116. * ()
  117. */
  118. public String getFieldKind() {
  119. return fFieldKind;
  120. }
  121. /*
  122. * (non-Javadoc)
  123. *
  124. * @see
  125. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#getFieldName
  126. * ()
  127. */
  128. public String getFieldName() {
  129. return fFieldName;
  130. }
  131. /*
  132. * (non-Javadoc)
  133. *
  134. * @see org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#
  135. * getFieldOnCompletion()
  136. */
  137. public ICompCSOnCompletion getFieldOnCompletion() {
  138. return fFieldOnCompletion;
  139. }
  140. /*
  141. * (non-Javadoc)
  142. *
  143. * @see
  144. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#getFieldSkip
  145. * ()
  146. */
  147. public boolean getFieldSkip() {
  148. return fFieldSkip;
  149. }
  150. /*
  151. * (non-Javadoc)
  152. *
  153. * @see org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#
  154. * removeFieldDepedency
  155. * (org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSDependency)
  156. */
  157. public void removeFieldDepedency(ICompCSDependency dependency) {
  158. fFieldDependencies.remove(dependency);
  159. if (isEditable()) {
  160. fireStructureChanged(dependency, IModelChangedEvent.REMOVE);
  161. }
  162. }
  163. /*
  164. * (non-Javadoc)
  165. *
  166. * @see
  167. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#setFieldId
  168. * (java.lang.String)
  169. */
  170. public void setFieldId(String id) {
  171. String old = fFieldId;
  172. fFieldId = id;
  173. if (isEditable()) {
  174. firePropertyChanged(ATTRIBUTE_ID, old, fFieldId);
  175. }
  176. }
  177. /*
  178. * (non-Javadoc)
  179. *
  180. * @see org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#
  181. * setFieldIntro
  182. * (org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSIntro)
  183. */
  184. public void setFieldIntro(ICompCSIntro intro) {
  185. ICompCSObject old = fFieldIntro;
  186. fFieldIntro = intro;
  187. if (isEditable()) {
  188. fireStructureChanged(intro, old);
  189. }
  190. }
  191. /*
  192. * (non-Javadoc)
  193. *
  194. * @see
  195. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#setFieldKind
  196. * (java.lang.String)
  197. */
  198. public void setFieldKind(String kind) {
  199. String old = fFieldKind;
  200. fFieldKind = kind;
  201. if (isEditable()) {
  202. firePropertyChanged(ATTRIBUTE_KIND, old, fFieldKind);
  203. }
  204. }
  205. /*
  206. * (non-Javadoc)
  207. *
  208. * @see
  209. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#setFieldName
  210. * (java.lang.String)
  211. */
  212. public void setFieldName(String name) {
  213. String old = fFieldName;
  214. fFieldName = name;
  215. if (isEditable()) {
  216. firePropertyChanged(ATTRIBUTE_NAME, old, fFieldName);
  217. }
  218. }
  219. /*
  220. * (non-Javadoc)
  221. *
  222. * @see org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#
  223. * setFieldOnCompletion
  224. * (org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSOnCompletion)
  225. */
  226. public void setFieldOnCompletion(ICompCSOnCompletion onCompletion) {
  227. ICompCSObject old = fFieldOnCompletion;
  228. fFieldOnCompletion = onCompletion;
  229. if (isEditable()) {
  230. fireStructureChanged(onCompletion, old);
  231. }
  232. }
  233. /*
  234. * (non-Javadoc)
  235. *
  236. * @see
  237. * org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#setFieldSkip
  238. * (boolean)
  239. */
  240. public void setFieldSkip(boolean skip) {
  241. Boolean old = Boolean.valueOf(fFieldSkip);
  242. fFieldSkip = skip;
  243. if (isEditable()) {
  244. firePropertyChanged(ATTRIBUTE_SKIP, old, Boolean
  245. .valueOf(fFieldSkip));
  246. }
  247. }
  248. /*
  249. * (non-Javadoc)
  250. *
  251. * @see org.eclipse.pde.internal.ua.core.icheatsheet.comp.ICompCSTaskObject#
  252. * getFieldDependencies()
  253. */
  254. public ICompCSDependency[] getFieldDependencies() {
  255. return (ICompCSDependency[]) fFieldDependencies
  256. .toArray(new ICompCSDependency[fFieldDependencies.size()]);
  257. }
  258. /*
  259. * (non-Javadoc)
  260. *
  261. * @see
  262. * org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#parseText(
  263. * org.w3c.dom.Text)
  264. */
  265. protected void parseText(Text text) {
  266. // NO-OP
  267. }
  268. /*
  269. * (non-Javadoc)
  270. *
  271. * @see
  272. * org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#parseAttributes
  273. * (org.w3c.dom.Element)
  274. */
  275. protected void parseAttributes(Element element) {
  276. // Process id attribute
  277. // Trim leading and trailing whitespace
  278. fFieldId = element.getAttribute(ATTRIBUTE_ID).trim();
  279. // Process kind attribute
  280. // Trim leading and trailing whitespace
  281. fFieldKind = element.getAttribute(ATTRIBUTE_KIND).trim();
  282. // Process name attribute
  283. // Trim leading and trailing whitespace
  284. fFieldName = element.getAttribute(ATTRIBUTE_NAME).trim();
  285. // Process skip attribute
  286. if (element.getAttribute(ATTRIBUTE_SKIP)
  287. .compareTo(ATTRIBUTE_VALUE_TRUE) == 0) {
  288. fFieldSkip = true;
  289. }
  290. }
  291. /*
  292. * (non-Javadoc)
  293. *
  294. * @see
  295. * org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#writeAttributes
  296. * (java.lang.StringBuffer)
  297. */
  298. protected void writeAttributes(StringBuffer buffer) {
  299. // Print id attribute
  300. if ((fFieldId != null) && (fFieldId.length() > 0)) {
  301. // Trim leading and trailing whitespace
  302. // Encode characters
  303. buffer.append(XMLPrintHandler.wrapAttribute(ATTRIBUTE_ID,
  304. PDETextHelper.translateWriteText(fFieldId.trim(),
  305. DEFAULT_SUBSTITUTE_CHARS)));
  306. }
  307. // Print kind attribute
  308. if ((fFieldKind != null) && (fFieldKind.length() > 0)) {
  309. // No trim required
  310. // No encode required
  311. buffer.append(XMLPrintHandler.wrapAttribute(ATTRIBUTE_KIND,
  312. fFieldKind));
  313. }
  314. // Print name attribute
  315. if ((fFieldName != null) && (fFieldName.length() > 0)) {
  316. // Trim leading and trailing whitespace
  317. // Encode characters
  318. buffer.append(XMLPrintHandler.wrapAttribute(ATTRIBUTE_NAME,
  319. PDETextHelper.translateWriteText(fFieldName.trim(),
  320. DEFAULT_SUBSTITUTE_CHARS)));
  321. }
  322. // Print skip attribute
  323. buffer.append(XMLPrintHandler.wrapAttribute(ATTRIBUTE_SKIP,
  324. new Boolean(fFieldSkip).toString()));
  325. }
  326. /*
  327. * (non-Javadoc)
  328. *
  329. * @see
  330. * org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#parseElement
  331. * (org.w3c.dom.Element)
  332. */
  333. protected void parseElement(Element element) {
  334. String name = element.getNodeName();
  335. ICompCSModelFactory factory = getModel().getFactory();
  336. if (name.equals(ELEMENT_INTRO)) {
  337. // Process intro element
  338. fFieldIntro = factory.createCompCSIntro(this);
  339. fFieldIntro.parse(element);
  340. } else if (name.equals(ELEMENT_ONCOMPLETION)) {
  341. // Process onCompletion element
  342. fFieldOnCompletion = factory.createCompCSOnCompletion(this);
  343. fFieldOnCompletion.parse(element);
  344. } else if (name.equals(ELEMENT_DEPENDENCY)) {
  345. // Process dependency element
  346. ICompCSDependency dependency = factory.createCompCSDependency(this);
  347. fFieldDependencies.add(dependency);
  348. dependency.parse(element);
  349. }
  350. }
  351. /*
  352. * (non-Javadoc)
  353. *
  354. * @see
  355. * org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#writeElements
  356. * (java.lang.String, java.io.PrintWriter)
  357. */
  358. protected void writeElements(String indent, PrintWriter writer) {
  359. String newIndent = indent + XMLPrintHandler.XML_INDENT;
  360. // Print intro element
  361. if (fFieldIntro != null) {
  362. fFieldIntro.write(newIndent, writer);
  363. }
  364. // Print onCompletion element
  365. if (fFieldOnCompletion != null) {
  366. fFieldOnCompletion.write(newIndent, writer);
  367. }
  368. // Print dependency elements
  369. Iterator iterator = fFieldDependencies.iterator();
  370. while (iterator.hasNext()) {
  371. ICompCSDependency dependency = (ICompCSDependency) iterator.next();
  372. dependency.write(newIndent, writer);
  373. }
  374. }
  375. /*
  376. * (non-Javadoc)
  377. *
  378. * @see
  379. * org.eclipse.pde.internal.ua.core.cheatsheet.comp.CompCSObject#getElement()
  380. */
  381. public abstract String getElement();
  382. }