]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKSelectionItem.java
Compiler warning elimination
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / common / VTKSelectionItem.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g3d.vtk.common;
13
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.simantics.db.Resource;
16 import org.simantics.g3d.scenegraph.IG3DNode;
17 import org.simantics.g3d.scenegraph.base.INode;
18 import org.simantics.objmap.structural.StructuralResource;
19
20 import vtk.vtkProp;
21
22 public class VTKSelectionItem<DBObject> implements IAdaptable{
23
24         private vtkProp prop;
25         private INode node;
26         private DBObject resource;
27         
28         public VTKSelectionItem(vtkProp prop, INode node, DBObject res) {
29                 this.prop = prop;
30                 this.node = node;
31                 this.resource = res;
32         }
33
34         @Override
35         public <T> T getAdapter(Class<T> adapter) {
36                 if (adapter.isAssignableFrom(Resource.class))
37                         if (resource instanceof Resource)
38                                 return adapter.cast(resource);
39                         else
40                                 return null;
41                 if (adapter.isAssignableFrom(StructuralResource.class))
42                         if (resource instanceof StructuralResource)
43                                 return adapter.cast(resource);
44                         else
45                                 return null;
46                 if (adapter.isAssignableFrom(vtkProp.class))
47                         return adapter.cast(prop);
48                 if (adapter.isAssignableFrom(IG3DNode.class) && node instanceof IG3DNode)
49                         return adapter.cast(node);
50                 if (adapter.isAssignableFrom(INode.class))
51                         return adapter.cast(node);
52                 return null;
53         }
54         
55         @SuppressWarnings("rawtypes")
56         @Override
57         public boolean equals(Object obj) {
58                 if (obj == null)
59                         return false;
60                 if (obj.getClass() != this.getClass())
61                         return false;
62                 VTKSelectionItem other = (VTKSelectionItem)obj;
63                 if (prop != null)
64                         if (!prop.equals(other.prop))
65                             return false;
66                 if (node != null)
67                         if (!node.equals(other.node))
68                             return false;
69                 if (resource != null)
70                     return resource.equals(other.resource);
71                 return true;
72                         
73         }
74 }