]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/property/VTKPropertyTabContributor.java
10176616a37149569fc045a81686428774473818
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / property / VTKPropertyTabContributor.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
3  * 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g3d.vtk.property;\r
13 \r
14 import org.eclipse.jface.viewers.ISelection;\r
15 import org.eclipse.jface.viewers.ISelectionProvider;\r
16 import org.eclipse.swt.SWT;\r
17 import org.eclipse.swt.layout.FillLayout;\r
18 import org.eclipse.swt.widgets.Composite;\r
19 import org.eclipse.swt.widgets.Control;\r
20 import org.eclipse.swt.widgets.Display;\r
21 import org.eclipse.swt.widgets.Text;\r
22 import org.eclipse.ui.IWorkbenchSite;\r
23 import org.simantics.db.management.ISessionContext;\r
24 import org.simantics.selectionview.IPropertyTab;\r
25 import org.simantics.selectionview.PropertyTabContributor;\r
26 import org.simantics.utils.threads.AWTThread;\r
27 import org.simantics.utils.threads.ThreadUtils;\r
28 \r
29 import vtk.vtkActor;\r
30 import vtk.vtkAlgorithm;\r
31 import vtk.vtkAlgorithmOutput;\r
32 import vtk.vtkMapper;\r
33 import vtk.vtkProp;\r
34 \r
35 public class VTKPropertyTabContributor implements PropertyTabContributor{\r
36         \r
37         public org.simantics.selectionview.IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {\r
38                 IPropertyTab tab = new VTKPropertyTab((vtkProp)input);\r
39                 tab.createControl(parent, context);\r
40                 return tab;\r
41         };\r
42         \r
43         \r
44         public class VTKPropertyTab implements IPropertyTab {\r
45                 private Composite composite;\r
46                 private Text text;\r
47                 private vtkProp prop;\r
48                 \r
49                 public VTKPropertyTab(vtkProp prop) {\r
50                         this.prop = prop;\r
51                 }\r
52                 \r
53                 @Override\r
54                 public void createControl(Composite parent, ISessionContext context) {\r
55                         \r
56                         composite = new Composite(parent, SWT.NONE);\r
57                         composite.setLayout(new FillLayout());\r
58                         text = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);\r
59                         ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
60                                 \r
61                                 @Override\r
62                                 public void run() {\r
63                                         String string = "";\r
64                                         if (prop instanceof vtkActor) {\r
65                                                 vtkActor act = (vtkActor)prop;\r
66                                                 vtkMapper mapper = act.GetMapper();\r
67                                                 vtkAlgorithmOutput out = mapper.GetInputConnection(0, 0);\r
68                                                 vtkAlgorithm producer = out.GetProducer();\r
69                                                 string += producer.GetClassName() +"\n";\r
70                                                 out.Delete();\r
71                                                 mapper.Delete();\r
72                                                 producer.Delete();\r
73                                         }\r
74                                         string += prop.Print();\r
75                                         final String s = string;\r
76                                         Display.getDefault().asyncExec(new Runnable() {\r
77                                                 @Override\r
78                                                 public void run() {\r
79                                                         if (!text.isDisposed())\r
80                                                                 text.setText(s);\r
81                                                 }\r
82                                         });\r
83                                 }\r
84                         });;\r
85                         \r
86                         \r
87                 }\r
88                 \r
89                 @Override\r
90                 public void requestFocus() {\r
91                         composite.setFocus();\r
92                 }\r
93                 \r
94                 @Override\r
95                 public void dispose() {\r
96                         composite.dispose();\r
97                 }\r
98                 \r
99                 @Override\r
100                 public boolean isDisposed() {\r
101                         return composite.isDisposed();\r
102                 }\r
103                 \r
104                 @Override\r
105                 public Control getControl() {\r
106                         return composite;\r
107                 }\r
108                 \r
109                 @Override\r
110                 public void setInput(ISessionContext context, ISelection selection,\r
111                                 boolean force) {\r
112                         \r
113                 }\r
114                 \r
115                 @Override\r
116                 public ISelectionProvider getSelectionProvider() {\r
117                         return null;\r
118                 }\r
119         }\r
120 \r
121 }\r