|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2022 Enda O'Brien and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License 2.0 which accompanies this distribution, |
| 6 | + * and is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: IBM Corporation - initial API and implementation |
| 11 | + *******************************************************************************/ |
| 12 | + |
| 13 | +package org.eclipse.ui.tests.markers; |
| 14 | + |
| 15 | +import static org.junit.Assert.assertFalse; |
| 16 | +import static org.junit.Assert.assertTrue; |
| 17 | + |
| 18 | +import java.lang.reflect.InvocationTargetException; |
| 19 | +import java.lang.reflect.Method; |
| 20 | + |
| 21 | +import org.eclipse.swt.widgets.Button; |
| 22 | +import org.eclipse.swt.widgets.Composite; |
| 23 | +import org.eclipse.swt.widgets.Control; |
| 24 | +import org.eclipse.ui.PlatformUI; |
| 25 | +import org.eclipse.ui.internal.views.markers.ExtendedMarkersView; |
| 26 | +import org.eclipse.ui.tests.ScopeAreaTestView; |
| 27 | +import org.eclipse.ui.views.markers.MarkerSupportView; |
| 28 | +import org.eclipse.ui.views.markers.internal.MarkerMessages; |
| 29 | +import org.junit.After; |
| 30 | +import org.junit.Test; |
| 31 | + |
| 32 | +public class ScopeAreaTest { |
| 33 | + ScopeAreaTestView view; |
| 34 | + Composite composite; |
| 35 | + |
| 36 | + @After |
| 37 | + public void cleanup() { |
| 38 | + if (view.getDialog() != null) { |
| 39 | + view.getDialog().close(); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void canCreateCustomScopeArea() throws Exception { |
| 45 | + view = (ScopeAreaTestView) PlatformUI.getWorkbench().getActiveWorkbenchWindow() |
| 46 | + .getActivePage().showView(ScopeAreaTestView.ID); |
| 47 | + |
| 48 | + openFiltersDialog(view); |
| 49 | + |
| 50 | + assertTrue(MarkerMessages.filtersDialog_anyResource, |
| 51 | + isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_anyResource)); |
| 52 | + assertFalse(MarkerMessages.filtersDialog_anyResourceInSameProject, |
| 53 | + isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_anyResourceInSameProject)); |
| 54 | + assertFalse(MarkerMessages.filtersDialog_anyResourceInSameProject, |
| 55 | + isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_anyResourceInSameProject)); |
| 56 | + assertFalse(MarkerMessages.filtersDialog_selectedAndChildren, |
| 57 | + isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_selectedAndChildren)); |
| 58 | + assertTrue(MarkerMessages.filtersDialog_selectedResource, |
| 59 | + isButtonAvailable(view.getScopeArea(), MarkerMessages.filtersDialog_selectedResource)); |
| 60 | + } |
| 61 | + |
| 62 | + void openFiltersDialog(MarkerSupportView view) { |
| 63 | + Method openFiltersDialog; |
| 64 | + try { |
| 65 | + openFiltersDialog = ExtendedMarkersView.class.getDeclaredMethod("openFiltersDialog"); |
| 66 | + openFiltersDialog.setAccessible(true); |
| 67 | + openFiltersDialog.invoke(view); |
| 68 | + } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException |
| 69 | + | InvocationTargetException e) { |
| 70 | + throw new RuntimeException(e); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + boolean isButtonAvailable(Composite composite, String buttonText) { |
| 75 | + Control[] children = composite.getChildren(); |
| 76 | + for (Control ctrl : children) { |
| 77 | + if (ctrl instanceof Button) { |
| 78 | + if (((Button) ctrl).getText().contains(buttonText)) { |
| 79 | + return true; |
| 80 | + } |
| 81 | + } else if (ctrl instanceof Composite && isButtonAvailable((Composite) ctrl, buttonText)) { |
| 82 | + return true; |
| 83 | + } |
| 84 | + } |
| 85 | + return false; |
| 86 | + } |
| 87 | +} |
0 commit comments