]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.message.ui/src/org/simantics/message/ui/AbstractEntry.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.message.ui / src / org / simantics / message / ui / AbstractEntry.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.message.ui;
13
14 import java.io.PrintWriter;
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.core.runtime.PlatformObject;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.ui.model.IWorkbenchAdapter;
21
22 /**
23  * Everything that appears in LogView is Abstract Entry. It provides composite pattern.
24  */
25 public abstract class AbstractEntry extends PlatformObject implements IWorkbenchAdapter {
26
27         /**
28          * The collection of direct children of this entry
29          */
30         private List<Object> children = new ArrayList<Object>();
31         protected Object parent;
32
33         /**
34          * Adds the specified child entry to the listing of children.
35          * If the specified child is <code>null</code>, no work is done
36          * 
37          * @param child
38          */
39         public void addChild(AbstractEntry child) {
40                 if (child != null) {
41                         children.add(0, child);
42                         child.setParent(this);
43                 }
44         }
45
46         /**
47          * @see IWorkbenchAdapter#getChildren(Object)
48          */
49         public Object[] getChildren(Object parent) {
50                 return children.toArray();
51         }
52
53         /**
54          * @return true if this entry has children, false otherwise
55          */
56         public boolean hasChildren() {
57                 return children.size() > 0;
58         }
59
60         /**
61          * @return the size of the child array
62          * 
63          * TODO rename to getChildCount(), or something more meaningful
64          */
65         public int size() {
66                 return children.size();
67         }
68
69         /**
70          * @see IWorkbenchAdapter#getImageDescriptor(Object)
71          */
72         public ImageDescriptor getImageDescriptor(Object object) {
73                 return null;
74         }
75
76         /**
77          * @see IWorkbenchAdapter#getLabel(Object)
78          */
79         public String getLabel(Object o) {
80                 return null;
81         }
82
83         /**
84          * @see IWorkbenchAdapter#getParent(Object)
85          */
86         public Object getParent(Object o) {
87                 return parent;
88         }
89
90         /**
91          * Sets the parent of this entry
92          * @param parent
93          */
94         public void setParent(AbstractEntry parent) {
95                 this.parent = parent;
96         }
97
98         /**
99          * removes all of the children specified in the given listing
100          * 
101          * @param list the list of children to remove
102          */
103         public void removeChildren(List<?> list) {
104                 children.removeAll(list);
105         }
106
107         /**
108          * Removes all of the children from this entry
109          */
110         public void removeAllChildren() {
111                 children.clear();
112         }
113
114         /**
115          * Writes this entry information into the given {@link PrintWriter}
116          * 
117          * @param writer
118          */
119         public abstract void write(PrintWriter writer);
120 }