1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.message.ui;
14 import java.io.PrintWriter;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.eclipse.core.runtime.PlatformObject;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.ui.model.IWorkbenchAdapter;
23 * Everything that appears in LogView is Abstract Entry. It provides composite pattern.
25 public abstract class AbstractEntry extends PlatformObject implements IWorkbenchAdapter {
28 * The collection of direct children of this entry
30 private List<Object> children = new ArrayList<Object>();
31 protected Object parent;
34 * Adds the specified child entry to the listing of children.
35 * If the specified child is <code>null</code>, no work is done
39 public void addChild(AbstractEntry child) {
41 children.add(0, child);
42 child.setParent(this);
47 * @see IWorkbenchAdapter#getChildren(Object)
49 public Object[] getChildren(Object parent) {
50 return children.toArray();
54 * @return true if this entry has children, false otherwise
56 public boolean hasChildren() {
57 return children.size() > 0;
61 * @return the size of the child array
63 * TODO rename to getChildCount(), or something more meaningful
66 return children.size();
70 * @see IWorkbenchAdapter#getImageDescriptor(Object)
72 public ImageDescriptor getImageDescriptor(Object object) {
77 * @see IWorkbenchAdapter#getLabel(Object)
79 public String getLabel(Object o) {
84 * @see IWorkbenchAdapter#getParent(Object)
86 public Object getParent(Object o) {
91 * Sets the parent of this entry
94 public void setParent(AbstractEntry parent) {
99 * removes all of the children specified in the given listing
101 * @param list the list of children to remove
103 public void removeChildren(List<?> list) {
104 children.removeAll(list);
108 * Removes all of the children from this entry
110 public void removeAllChildren() {
115 * Writes this entry information into the given {@link PrintWriter}
119 public abstract void write(PrintWriter writer);