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.browsing.ui.common.node;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.simantics.browsing.ui.common.imagers.ImageURLs;
16 import org.simantics.browsing.ui.content.Imager;
17 import org.simantics.browsing.ui.content.Labeler;
18 import org.simantics.utils.ReflectionUtils;
20 public abstract class AbstractNode<T> implements IAdaptable {
23 public final Class<?> clazz;
25 public AbstractNode(T data) {
28 clazz = ReflectionUtils.getSingleParameterType(getClass());
32 public int hashCode() {
33 return data.hashCode() + getClass().hashCode();
37 public boolean equals(Object obj) {
42 if (getClass() != obj.getClass())
44 AbstractNode<?> other = (AbstractNode<?>) obj;
45 return data.equals(other.data);
48 @SuppressWarnings("unchecked")
50 public <A> A getAdapter(Class<A> adapter) {
53 if(Imager.class == adapter)
54 return (A) getImager();
55 if(ImageURLs.class == adapter)
56 return (A) getImageURLs();
57 if(Labeler.class == adapter)
58 return (A) getLabeler();
62 protected Imager getImager() {
66 protected ImageURLs getImageURLs() {
70 protected Labeler getLabeler() {
75 public String toString() {
76 return getClass().getSimpleName();