1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.gltrace.views.detail; 18 19 import com.android.ide.eclipse.gltrace.state.GLCompositeProperty; 20 import com.android.ide.eclipse.gltrace.state.GLStateType; 21 import com.android.ide.eclipse.gltrace.state.GLStringProperty; 22 import com.android.ide.eclipse.gltrace.state.IGLProperty; 23 24 import org.eclipse.jface.action.IContributionItem; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.swt.widgets.Text; 29 30 import java.util.Collections; 31 import java.util.List; 32 33 public class ShaderSourceDetailsProvider implements IStateDetailProvider { 34 private Text mTextControl; 35 36 @Override isApplicable(IGLProperty state)37 public boolean isApplicable(IGLProperty state) { 38 return getShaderSourceProperty(state) != null; 39 } 40 41 @Override createControl(Composite parent)42 public void createControl(Composite parent) { 43 mTextControl = new Text(parent, SWT.BORDER| SWT.READ_ONLY 44 | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); 45 mTextControl.setEditable(false); 46 } 47 48 @Override disposeControl()49 public void disposeControl() { 50 } 51 52 @Override getControl()53 public Control getControl() { 54 return mTextControl; 55 } 56 57 @Override updateControl(IGLProperty state)58 public void updateControl(IGLProperty state) { 59 IGLProperty shaderSrcProperty = getShaderSourceProperty(state); 60 if (shaderSrcProperty instanceof GLStringProperty) { 61 String shaderSrc = ((GLStringProperty) shaderSrcProperty).getStringValue(); 62 mTextControl.setText(shaderSrc); 63 mTextControl.setEnabled(true); 64 } else { 65 mTextControl.setText(""); //$NON-NLS-1$ 66 mTextControl.setEnabled(false); 67 } 68 } 69 70 /** 71 * Get the {@link GLStateType#SHADER_SOURCE} property given a node in 72 * the state hierarchy. 73 * @param state any node in the GL state hierarchy 74 * @return The {@link GLStateType#SHADER_SOURCE} property if a unique instance 75 * of it can be accessed from the given node, null otherwise. 76 * A unique instance can be accessed if the given node is 77 * either the requested node itself, or its parent or sibling. 78 */ getShaderSourceProperty(IGLProperty state)79 private IGLProperty getShaderSourceProperty(IGLProperty state) { 80 if (state.getType() == GLStateType.SHADER_SOURCE) { 81 // given node is the requested node 82 return state; 83 } 84 85 if (state.getType() != GLStateType.PER_SHADER_STATE) { 86 // if it is not the parent, then it could be a sibling, in which case 87 // we go up a level to its parent 88 state = state.getParent(); 89 } 90 91 if (state != null && state.getType() == GLStateType.PER_SHADER_STATE) { 92 // if it is the parent, we can access the required property 93 return ((GLCompositeProperty) state).getProperty(GLStateType.SHADER_SOURCE); 94 } 95 96 return null; 97 } 98 99 @Override getToolBarItems()100 public List<IContributionItem> getToolBarItems() { 101 return Collections.emptyList(); 102 } 103 } 104