1 /******************************************************************************* 2 * Copyright (c) 2000, 2011 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.debug.ui.actions; 15 16 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 19 import org.eclipse.jdt.internal.debug.core.model.JDIArrayEntryVariable; 20 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; 21 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 22 import org.eclipse.jface.viewers.Viewer; 23 24 /** 25 * Shows non-final static variables 26 */ 27 public class ShowNullArrayEntriesAction extends ViewFilterAction { 28 ShowNullArrayEntriesAction()29 public ShowNullArrayEntriesAction() { 30 super(); 31 } 32 33 /** 34 * @see ViewFilterAction#getPreferenceKey() 35 */ 36 @Override getPreferenceKey()37 protected String getPreferenceKey() { 38 return IJDIPreferencesConstants.PREF_SHOW_NULL_ARRAY_ENTRIES; 39 } 40 41 /** 42 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) 43 */ 44 @Override select(Viewer viewer, Object parentElement, Object element)45 public boolean select(Viewer viewer, Object parentElement, Object element) { 46 if (getValue()) { 47 // when on, filter nothing 48 return true; 49 } 50 if (element instanceof JDIArrayEntryVariable) { 51 JDIArrayEntryVariable variable = (JDIArrayEntryVariable)element; 52 try { 53 return !variable.getValue().equals(((IJavaDebugTarget)variable.getDebugTarget()).nullValue()); 54 } catch (DebugException e) { 55 JDIDebugUIPlugin.log(e); 56 } 57 } 58 return true; 59 } 60 } 61