]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/VTKSelectionItem.java
222da8b92012de4a404d0d3f862b84ed926768e3
[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 IG3DNode node;
26         private DBObject resource;
27         
28         public VTKSelectionItem(vtkProp prop, IG3DNode node, DBObject res) {
29                 this.prop = prop;
30                 this.node = node;
31                 this.resource = res;
32         }
33
34         @SuppressWarnings("rawtypes")
35         @Override
36         public Object getAdapter(Class adapter) {
37                 if (adapter == Resource.class)
38                         if (resource instanceof Resource)
39                                 return resource;
40                         else
41                                 return null;
42                 if (adapter == StructuralResource.class)
43                         if (resource instanceof StructuralResource)
44                                 return resource;
45                         else
46                                 return null;
47                 if (adapter == vtkProp.class)
48                         return prop;
49                 if (adapter == IG3DNode.class)
50                         return node;
51                 if (adapter == INode.class)
52                         return node;
53                 return null;
54         }
55         
56         @SuppressWarnings("rawtypes")
57         @Override
58         public boolean equals(Object obj) {
59                 if (obj == null)
60                         return false;
61                 if (obj.getClass() != this.getClass())
62                         return false;
63                 VTKSelectionItem other = (VTKSelectionItem)obj;
64                 if (prop != null)
65                         if (!prop.equals(other.prop))
66                             return false;
67                 if (node != null)
68                         if (!node.equals(other.node))
69                             return false;
70                 if (resource != null)
71                     return resource.equals(other.resource);
72                 return true;
73                         
74         }
75 }