-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements ToolItem styling support via CSS
Allows to style ToolItems background color and foreground color. SWT style-bits can also be used for selecting the tool items which should be styled. ToolItemTest contains tests for these elements, an TODO has been added so enable the styling also via a styling call on the parent, this would require additional changes in ToolBarElement to handle also its children. Pseudo-handing styling similar to the button, e.g. :checked has not yet been implemented. ToolItem { background-color: pink; color:blue; } ToolItem [style~='SWT.PUSH'], ToolItem[style~='SWT.CHECK'] { background-color: blue; color:red; }
- Loading branch information
Showing
7 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ToolItemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 vogella 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: | ||
* Lars Vogel- initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.e4.ui.tests.css.swt; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.layout.FillLayout; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.swt.widgets.ToolBar; | ||
import org.eclipse.swt.widgets.ToolItem; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class ToolItemTest extends CSSSWTTestCase { | ||
|
||
protected ToolItem createTestToolItem(String styleSheet, int styleBit) { | ||
engine = createEngine(styleSheet, display); | ||
|
||
// Create widgets | ||
var shell = new Shell(display, SWT.SHELL_TRIM); | ||
var layout = new FillLayout(); | ||
shell.setLayout(layout); | ||
|
||
var panel = new Composite(shell, SWT.NONE); | ||
panel.setLayout(new FillLayout()); | ||
|
||
ToolBar toolBar = new ToolBar(panel, SWT.FLAT); | ||
var toolItemToTest = new ToolItem(toolBar, styleBit); | ||
toolItemToTest.setText("Some text"); | ||
|
||
// Apply styles | ||
// TODO should call on shell but ToolBar is currently not styling its children | ||
// works in a real application via CSSSWTApplyStylesListener SWT.Skin event | ||
engine.applyStyles(toolItemToTest, true); | ||
shell.pack(); | ||
return toolItemToTest; | ||
} | ||
|
||
@Test | ||
public void testBackgroundColor() { | ||
var toolItemToTest = createTestToolItem("ToolItem { background-color: #FF0000;}", | ||
SWT.PUSH); | ||
assertEquals(RED, toolItemToTest.getBackground().getRGB()); | ||
} | ||
|
||
@Test | ||
public void testForegroundColor() { | ||
var toolItemToTest = createTestToolItem("ToolItem { color: #FF0000;}", SWT.PUSH); | ||
assertEquals(RED, toolItemToTest.getForeground().getRGB()); | ||
} | ||
|
||
@Test | ||
@Ignore("Not yet implemented") | ||
public void testSelectedPseudo() { | ||
var toolItemToTest = createTestToolItem( | ||
"ToolItem { color: #FF0000; }\n" + "ToolItem:checked { color: #0000FF; }", SWT.PUSH); | ||
assertEquals(RED, toolItemToTest.getForeground().getRGB()); | ||
toolItemToTest.setSelection(true); | ||
engine.applyStyles(toolItemToTest, false); | ||
assertEquals(BLUE, toolItemToTest.getForeground().getRGB()); | ||
} | ||
|
||
@Test | ||
public void ensurePseudoAttributeAllowsToSelectionPushButton() { | ||
var toolItemToTest = createTestToolItem( | ||
"ToolItem[style~='SWT.CHECK'] { background-color: #FF0000; color: #0000FF }", SWT.CHECK); | ||
|
||
assertEquals(RED, toolItemToTest.getBackground().getRGB()); | ||
assertEquals(BLUE, toolItemToTest.getForeground().getRGB()); | ||
|
||
var unStyledBToolItem = createTestToolItem( | ||
"ToolItem[style~='SWT.PUSH'] { background-color: #FF0000; color: #0000FF }", SWT.CHECK); | ||
|
||
assertNotEquals(RED, unStyledBToolItem.getBackground().getRGB()); | ||
assertNotEquals(BLUE, unStyledBToolItem.getForeground().getRGB()); | ||
|
||
} | ||
} |