/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.g3d.vtk.property; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchSite; import org.simantics.db.management.ISessionContext; import org.simantics.selectionview.IPropertyTab; import org.simantics.selectionview.PropertyTabContributor; import org.simantics.utils.threads.IThreadWorkQueue; import org.simantics.utils.threads.ThreadUtils; import vtk.vtkActor; import vtk.vtkAlgorithm; import vtk.vtkAlgorithmOutput; import vtk.vtkMapper; import vtk.vtkProp; public class VTKPropertyTabContributor implements PropertyTabContributor{ private IThreadWorkQueue tq; public VTKPropertyTabContributor(IThreadWorkQueue tq) { this.tq = tq; } public org.simantics.selectionview.IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) { IPropertyTab tab = new VTKPropertyTab((vtkProp)input); tab.createControl(parent, context); return tab; }; public class VTKPropertyTab implements IPropertyTab { private Composite composite; private Text text; private vtkProp prop; public VTKPropertyTab(vtkProp prop) { this.prop = prop; } @Override public void createControl(Composite parent, ISessionContext context) { composite = new Composite(parent, SWT.NONE); composite.setLayout(new FillLayout()); text = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY); ThreadUtils.asyncExec(tq, new Runnable() { @Override public void run() { String string = ""; if (prop instanceof vtkActor) { vtkActor act = (vtkActor)prop; vtkMapper mapper = act.GetMapper(); vtkAlgorithmOutput out = mapper.GetInputConnection(0, 0); vtkAlgorithm producer = out.GetProducer(); string += producer.GetClassName() +"\n"; out.Delete(); mapper.Delete(); producer.Delete(); } string += prop.Print(); final String s = string; Display.getDefault().asyncExec(new Runnable() { @Override public void run() { if (!text.isDisposed()) text.setText(s); } }); } });; } @Override public void requestFocus() { composite.setFocus(); } @Override public void dispose() { composite.dispose(); } @Override public boolean isDisposed() { return composite.isDisposed(); } @Override public Control getControl() { return composite; } @Override public void setInput(ISessionContext context, ISelection selection, boolean force) { } @Override public ISelectionProvider getSelectionProvider() { return null; } } }