X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.message.ui%2Fsrc%2Forg%2Fsimantics%2Fmessage%2Fui%2FAbstractEntry.java;fp=bundles%2Forg.simantics.message.ui%2Fsrc%2Forg%2Fsimantics%2Fmessage%2Fui%2FAbstractEntry.java;h=3a94a0ecc3df516aa90ba8e0f00d3c4986710403;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.message.ui/src/org/simantics/message/ui/AbstractEntry.java b/bundles/org.simantics.message.ui/src/org/simantics/message/ui/AbstractEntry.java new file mode 100644 index 000000000..3a94a0ecc --- /dev/null +++ b/bundles/org.simantics.message.ui/src/org/simantics/message/ui/AbstractEntry.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.message.ui; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; + +/** + * Everything that appears in LogView is Abstract Entry. It provides composite pattern. + */ +public abstract class AbstractEntry extends PlatformObject implements IWorkbenchAdapter { + + /** + * The collection of direct children of this entry + */ + private List children = new ArrayList(); + protected Object parent; + + /** + * Adds the specified child entry to the listing of children. + * If the specified child is null, no work is done + * + * @param child + */ + public void addChild(AbstractEntry child) { + if (child != null) { + children.add(0, child); + child.setParent(this); + } + } + + /** + * @see IWorkbenchAdapter#getChildren(Object) + */ + public Object[] getChildren(Object parent) { + return children.toArray(); + } + + /** + * @return true if this entry has children, false otherwise + */ + public boolean hasChildren() { + return children.size() > 0; + } + + /** + * @return the size of the child array + * + * TODO rename to getChildCount(), or something more meaningful + */ + public int size() { + return children.size(); + } + + /** + * @see IWorkbenchAdapter#getImageDescriptor(Object) + */ + public ImageDescriptor getImageDescriptor(Object object) { + return null; + } + + /** + * @see IWorkbenchAdapter#getLabel(Object) + */ + public String getLabel(Object o) { + return null; + } + + /** + * @see IWorkbenchAdapter#getParent(Object) + */ + public Object getParent(Object o) { + return parent; + } + + /** + * Sets the parent of this entry + * @param parent + */ + public void setParent(AbstractEntry parent) { + this.parent = parent; + } + + /** + * removes all of the children specified in the given listing + * + * @param list the list of children to remove + */ + public void removeChildren(List list) { + children.removeAll(list); + } + + /** + * Removes all of the children from this entry + */ + public void removeAllChildren() { + children.clear(); + } + + /** + * Writes this entry information into the given {@link PrintWriter} + * + * @param writer + */ + public abstract void write(PrintWriter writer); +}