diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java index c18151cc809..f6ab8262179 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java @@ -45,11 +45,6 @@ import org.eclipse.jdt.internal.ui.util.StringMatcher; public class CallHierarchyCore { - - public static final String PREF_SHOW_ALL_CODE = "PREF_SHOW_ALL_CODE"; //$NON-NLS-1$ - public static final String PREF_HIDE_TEST_CODE = "PREF_HIDE_TEST_CODE"; //$NON-NLS-1$ - public static final String PREF_SHOW_TEST_CODE_ONLY = "PREF_SHOW_TEST_CODE_ONLY"; //$NON-NLS-1$ - public static final String PREF_USE_IMPLEMENTORS= "PREF_USE_IMPLEMENTORS"; //$NON-NLS-1$ public static final String PREF_USE_FILTERS= "PREF_USE_FILTERS"; //$NON-NLS-1$ public static final String PREF_FILTERS_LIST= "PREF_FILTERS_LIST"; //$NON-NLS-1$ @@ -72,15 +67,23 @@ public boolean isSearchUsingImplementorsEnabled() { } public boolean isShowTestCode() { - return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_SHOW_TEST_CODE_ONLY, null)); + return Boolean.parseBoolean(JavaManipulation.getPreference(CallHierarchyFilterOptions.SHOW_TEST_CODE_ONLY.getId(), null)); } public boolean isShowAll() { - return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_SHOW_ALL_CODE, null)); + return Boolean.parseBoolean(JavaManipulation.getPreference(CallHierarchyFilterOptions.SHOW_ALL_CODE.getId(), null)); } public boolean isHideTestCode() { - return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_HIDE_TEST_CODE, null)); + return Boolean.parseBoolean(JavaManipulation.getPreference(CallHierarchyFilterOptions.HIDE_TEST_CODE.getId(), null)); + } + + public String getActiveFilter() { + for (CallHierarchyFilterOptions option: CallHierarchyFilterOptions.values()) { //must be one of the threee + if(Boolean.parseBoolean(JavaManipulation.getPreference(option.getId(), null))) { + return option.getId(); + } + } return null; } public Collection getImplementingMethods(IMethod method) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyFilterOptions.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyFilterOptions.java new file mode 100644 index 00000000000..efc2b7872b6 --- /dev/null +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyFilterOptions.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2024 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Vector Informatik GmbH - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jdt.internal.corext.callhierarchy; + +/** + * These are the filter Options for the Call Hierarchy + */ +public enum CallHierarchyFilterOptions { + SHOW_ALL_CODE("PREF_SHOW_ALL_CODE", "Show All Code"), //$NON-NLS-1$ //$NON-NLS-2$ + HIDE_TEST_CODE("PREF_HIDE_TEST_CODE", "Hide Test Code"), //$NON-NLS-1$ //$NON-NLS-2$ + SHOW_TEST_CODE_ONLY("PREF_SHOW_TEST_CODE_ONLY", "Test Code only"); //$NON-NLS-1$ //$NON-NLS-2$ + + private final String identifyString; + private final String text; + + CallHierarchyFilterOptions(String identifyString, String text) { + this.identifyString = identifyString; + this.text = text; + } + + public String getId() { + return identifyString; + } + + public String getText() { + return text; + } +} diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java index e6ba4815373..6808cc46f43 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java @@ -18,9 +18,6 @@ package org.eclipse.jdt.internal.corext.callhierarchy; import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_FILTERS_LIST; -import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_HIDE_TEST_CODE; -import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_SHOW_ALL_CODE; -import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY; import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_USE_FILTERS; import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_USE_IMPLEMENTORS; @@ -36,6 +33,7 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.manipulation.JavaManipulation; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.internal.corext.dom.IASTSharedValues; @@ -60,19 +58,16 @@ public static CallHierarchy getDefault() { return fgInstance; } - public void setShowAll(boolean value) { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - settings.setValue(PREF_SHOW_ALL_CODE, value); - } - - public void setHideTestCode(boolean value) { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - settings.setValue(PREF_HIDE_TEST_CODE, value); - } + public void setActiveFilter(CallHierarchyFilterOptions filter) { + IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - public void setShowTestCode(boolean value) { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - settings.setValue(PREF_SHOW_TEST_CODE_ONLY, value); + for(CallHierarchyFilterOptions option : CallHierarchyFilterOptions.values()) { + if(option == filter) { + settings.setValue(option.getId(), true); + } else { + settings.setValue(option.getId(), false); + } + } } public boolean isSearchUsingImplementorsEnabled() { @@ -139,21 +134,13 @@ public boolean isFilterEnabled() { return settings.getBoolean(PREF_USE_FILTERS); } - public boolean isShowAll() { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - return settings.getBoolean(PREF_SHOW_ALL_CODE); - } - - public boolean isHideTestCode() { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - return settings.getBoolean(PREF_HIDE_TEST_CODE); - } - - public boolean isShowTestCode() { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - return settings.getBoolean(PREF_SHOW_TEST_CODE_ONLY); - } - + public CallHierarchyFilterOptions getActiveFilter() { + for (CallHierarchyFilterOptions option: CallHierarchyFilterOptions.values()) { //must be one of the threee + if(Boolean.parseBoolean(JavaManipulation.getPreference(option.getId(), null))) { + return option; + } + } return null; + } public void setFilterEnabled(boolean filterEnabled) { IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java index 5c7be2431bb..548fbc617b6 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java @@ -31,6 +31,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy; +import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyFilterOptions; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; @@ -43,6 +44,7 @@ class FiltersDialog extends StatusDialog { private Button fShowAll; private Button fHideTest; private Button fShowTest; + private Button[] buttons = {fShowAll, fHideTest, fShowTest}; //important what comes when protected FiltersDialog(Shell parentShell) { super(parentShell); @@ -118,30 +120,28 @@ private void createTestCodeArea(Composite parent) { layout.numColumns= 1; radioGroup.setLayout(layout); - fShowAll= new Button(radioGroup, SWT.RADIO); - fShowAll.setText(CallHierarchyMessages.FiltersDialog_ShowAllCode); + for (int i = 0; i < buttons.length; i++) { + buttons[i] = new Button(radioGroup, SWT.RADIO); + buttons[i].setText(getFilterOptions(buttons[i]).getText()); + } - fHideTest= new Button(radioGroup, SWT.RADIO); - fHideTest.setText(CallHierarchyMessages.FiltersDialog_HideTestCode); - - fShowTest= new Button(radioGroup, SWT.RADIO); - fShowTest.setText(CallHierarchyMessages.FiltersDialog_TestCodeOnly); setSelection(); GridData gridData= new GridData(); gridData.horizontalIndent= 0; - fShowAll.setLayoutData(gridData); - fHideTest.setLayoutData(gridData); - fShowTest.setLayoutData(gridData); + + for (Button button : buttons) { + button.setLayoutData(gridData); + } } private void setSelection() { - fShowAll.setSelection(CallHierarchy.getDefault().isShowAll()); - fHideTest.setSelection(CallHierarchy.getDefault().isHideTestCode()); - fShowTest.setSelection(CallHierarchy.getDefault().isShowTestCode()); - + for (Button button : buttons) { + button.setSelection(CallHierarchy.getDefault().getActiveFilter() == getFilterOptions(button)); + } } + /** * Creates a check box button with the given parent and text. * @@ -191,9 +191,13 @@ private void updateFilterFromUI() { CallHierarchy.getDefault().setFilters(fNames.getText()); CallHierarchy.getDefault().setFilterEnabled(fFilterOnNames.getSelection()); - CallHierarchy.getDefault().setShowAll(fShowAll.getSelection()); - CallHierarchy.getDefault().setHideTestCode(fHideTest.getSelection()); - CallHierarchy.getDefault().setShowTestCode(fShowTest.getSelection()); + CallHierarchyFilterOptions activeFilter = null; + for (Button button : buttons) { + if(button.getSelection()) { + activeFilter = getFilterOptions(button); + } + } + CallHierarchy.getDefault().setActiveFilter(activeFilter); } /** @@ -205,10 +209,18 @@ private void updateUIFromFilter() { fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled()); setSelection(); - updateEnabledState(); } + private CallHierarchyFilterOptions getFilterOptions(Button B) { + if(B == buttons[0]) { + return CallHierarchyFilterOptions.SHOW_ALL_CODE; + } else if (B == buttons[1]) { + return CallHierarchyFilterOptions.HIDE_TEST_CODE; + } else { + return CallHierarchyFilterOptions.SHOW_TEST_CODE_ONLY; + } + } /** * Updates the filter from the UI state.