1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.common.node;
\r
14 import org.eclipse.core.runtime.IAdaptable;
\r
15 import org.simantics.browsing.ui.common.imagers.ImageURLs;
\r
16 import org.simantics.browsing.ui.content.Imager;
\r
17 import org.simantics.browsing.ui.content.Labeler;
\r
18 import org.simantics.utils.ReflectionUtils;
\r
20 public abstract class AbstractNode<T> implements IAdaptable {
\r
22 public final T data;
\r
23 public final Class<?> clazz;
\r
25 public AbstractNode(T data) {
\r
26 assert(data != null);
\r
28 clazz = ReflectionUtils.getSingleParameterType(getClass());
\r
32 public int hashCode() {
\r
33 return data.hashCode() + getClass().hashCode();
\r
37 public boolean equals(Object obj) {
\r
42 if (getClass() != obj.getClass())
\r
44 AbstractNode<?> other = (AbstractNode<?>) obj;
\r
45 return data.equals(other.data);
\r
48 @SuppressWarnings({ "rawtypes" })
\r
50 public Object getAdapter(Class adapter) {
\r
51 if(clazz == adapter)
\r
53 if(Imager.class == adapter)
\r
55 if(ImageURLs.class == adapter)
\r
56 return getImageURLs();
\r
57 if(Labeler.class == adapter)
\r
58 return getLabeler();
\r
62 protected Imager getImager() {
\r
66 protected ImageURLs getImageURLs() {
\r
70 protected Labeler getLabeler() {
\r
75 public String toString() {
\r
76 return getClass().getSimpleName();
\r