From 7f877835ad1ce840f4f66e8be79cc5bd82c16549 Mon Sep 17 00:00:00 2001 From: Daniel Ratiu <ratiu@fortiss.org> Date: Thu, 20 Oct 2011 07:24:33 +0000 Subject: [PATCH] cleaning the code, a better packaging and more reuse refs 233 --- .../trunk/META-INF/MANIFEST.MF | 1 + .../TreeContentProviderBase.java | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/contentprovider/TreeContentProviderBase.java diff --git a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF index cae25eee5..ac48d19c5 100644 --- a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF @@ -13,6 +13,7 @@ Export-Package: org.fortiss.tooling.base.ui, org.fortiss.tooling.base.ui.action, org.fortiss.tooling.base.ui.command, org.fortiss.tooling.base.ui.compose, + org.fortiss.tooling.base.ui.contentprovider, org.fortiss.tooling.base.ui.dnd, org.fortiss.tooling.base.ui.editor, org.fortiss.tooling.base.ui.editor.gef, diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/contentprovider/TreeContentProviderBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/contentprovider/TreeContentProviderBase.java new file mode 100644 index 000000000..0a1024e97 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/contentprovider/TreeContentProviderBase.java @@ -0,0 +1,90 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2011 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.base.ui.contentprovider; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * Base implementation of a tree content provider that has an empty default + * implementation for some methods. Some of the methods require implementation + * almost always (e.g. {@link #getElements(Object)} and + * {@link #getParent(Object)}), but for simple content providers the base + * implementation is sufficient. + * + * This class is taken from ConQAT. + * + * @author hummelb + * @author $Author: deissenb $ + * @version $Rev: 34252 $ + * @ConQAT.Rating RED Hash: + */ +public abstract class TreeContentProviderBase implements ITreeContentProvider { + + /** + * {@inheritDoc} + * <p> + * Default implementation returns null, which makes automatic expansion of + * externally set selection impossible. + */ + @Override + public Object getParent(Object inputElement) { + return null; + } + + /** + * {@inheritDoc} + * <p> + * Uses the result of {@link #getChildren(Object)} to determine result. + */ + @Override + public boolean hasChildren(Object inputElement) { + Object[] children = getChildren(inputElement); + return children != null && children.length > 0; + } + + /** + * {@inheritDoc} + * <p> + * Just calls {@link #getChildren(Object)}. + */ + @Override + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + /** + * {@inheritDoc} + * <p> + * Empty implementation. + */ + @Override + public void dispose() { + // not needed + } + + /** + * {@inheritDoc} + * <p> + * Empty implementation. + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // not needed + } +} \ No newline at end of file -- GitLab