diff --git a/bundles/org.eclipse.e4.ui.css.swt/plugin.xml b/bundles/org.eclipse.e4.ui.css.swt/plugin.xml index 965de7b1293..5a16ca7c001 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/plugin.xml +++ b/bundles/org.eclipse.e4.ui.css.swt/plugin.xml @@ -290,17 +290,6 @@ name="font-weight"> - - - - - - - initial API and implementation - * IBM Corporation - ******************************************************************************/ -package org.eclipse.e4.ui.css.swt.properties.custom; - -import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; -import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Widget; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; - -public class CSSPropertyShowCloseHandler extends CTabETabHelper implements ICSSPropertyHandler { - - private static final String CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY = "CSS_CTABFOLDER_SELECTED_SHOW_CLOSE_LISTENER_KEY"; //$NON-NLS-1$ - - @Override - public boolean applyCSSProperty(Object element, String property, - CSSValue value, String pseudo, CSSEngine engine) throws Exception { - Widget widget = SWTElementHelpers.getWidget(element); - if (widget instanceof CTabItem) { - Item item = (Item) widget; - boolean showClose = ((Boolean) engine.convert(value, Boolean.class, - null)).booleanValue(); - if ("selected".equals(pseudo)) { - Control parent = getParent(widget); - - ShowCloseSelectionListener listener = (ShowCloseSelectionListener) parent.getData( - CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY); - if (listener == null) { - listener = new ShowCloseSelectionListener(engine); - parent.addListener(SWT.Paint, listener); - parent.setData( - CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY, - listener); - } else { - listener.setEngine(engine); - } - item = getSelection(getParent(widget)); - - listener.setSelection(item); - if (item != null) { - setShowClose(item, showClose); - } - } else { - setShowClose(item, showClose); - } - return true; - } - return false; - } - - @Override - public String retrieveCSSProperty(Object element, String property, - String pseudo, CSSEngine engine) throws Exception { - Widget widget = SWTElementHelpers.getWidget(element); - if (widget instanceof CTabItem) { - CTabItem item = (CTabItem) widget; - return Boolean.toString(item.getShowClose()); - } - return null; - } - - private static class ShowCloseSelectionListener implements Listener { - - private CSSEngine engine; - - private Item selection; - - public ShowCloseSelectionListener(CSSEngine engine) { - this.engine = engine; - } - - public void setSelection(Item selection) { - this.selection = selection; - } - - public void setEngine(CSSEngine engine) { - this.engine = engine; - } - - @Override - public void handleEvent(Event e) { - - Item selection = getSelection(e.widget); - - if (selection == null || selection.isDisposed() - || this.selection == selection) { - return; - } - - Item[] items = getItems(e.widget); - int selectionIndex = getSelectionIndex(e.widget); - - boolean selectionSet = false; - - CSSStyleDeclaration selectedStyle = engine.getViewCSS() - .getComputedStyle(engine.getElement(selection), - "selected"); - if (selectedStyle != null) { - CSSValue value = selectedStyle - .getPropertyCSSValue("show-close"); - if (value != null) { - setShowClose(selection, Boolean.parseBoolean(value.getCssText())); - selectionSet = true; - } - } - - CSSStyleDeclaration unselectedStyle = engine.getViewCSS() - .getComputedStyle(engine.getElement(selection), - null); - if (unselectedStyle == null) { - for (int i = 0; i < items.length; i++) { - if (selectionSet && i != selectionIndex) { - setShowClose(items[i], false); - } - } - } else { - CSSValue value = unselectedStyle - .getPropertyCSSValue("show-close"); - boolean unselectedShowClose = value == null ? false : Boolean - .parseBoolean(value.getCssText()); - for (int i = 0; i < items.length; i++) { - if (selectionSet && i != selectionIndex) { - setShowClose(items[i], unselectedShowClose); - } - } - } - - this.selection = selection; - } - } -} diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java index 7006ec6a212..f13b4381171 100644 --- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java @@ -286,7 +286,6 @@ void testRetrievePropertyNull() { assertEquals(null, engine.retrieveCSSProperty(shell, "swt-maximized", null)); assertEquals(null, engine.retrieveCSSProperty(shell, "swt-maximize-visible", null)); assertEquals(null, engine.retrieveCSSProperty(shell, "swt-minimize-visible", null)); - assertEquals(null, engine.retrieveCSSProperty(shell, "show-close", null)); assertEquals(null, engine.retrieveCSSProperty(shell, "swt-simple", null)); assertEquals(null, engine.retrieveCSSProperty(shell, "swt-single", null)); assertEquals(null, engine.retrieveCSSProperty(shell, "swt-unselected-close-visible", null)); diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java index 0d12c4807bc..6000218aa9b 100644 --- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java @@ -248,115 +248,6 @@ void testSelectedFontMerged3() { } } - private void testShowClose(boolean showClose) { - CTabFolder folder = createTestTabFolder("CTabItem { show-close: " + showClose + " }"); - for (CTabItem item : folder.getItems()) { - assertEquals(showClose, item.getShowClose()); - assertEquals(Boolean.toString(showClose), engine.retrieveCSSProperty(item, "show-close", null)); - } - } - - @Test - void testShowCloseFalse() { - testShowClose(false); - } - - @Test - void testShowCloseTrue() { - testShowClose(true); - } - - @Test - void testShowClose() { - CTabFolder folder = createTestTabFolder("CTabItem { show-close: true }"); - for (CTabItem item : folder.getItems()) { - assertTrue(item.getShowClose()); - } - - engine = createEngine("CTabItem { show-close: false }", folder.getDisplay()); - engine.applyStyles(folder.getShell(), true); - for (CTabItem item : folder.getItems()) { - assertFalse(item.getShowClose()); - } - } - - @Test - void testShowClose2() { - CTabFolder folder = createTestTabFolder(); - CTabFolder folder2 = createFolder(folder.getShell()); - engine = createEngine("CTabItem { swt-show-close: true }", folder.getDisplay()); - engine.applyStyles(folder.getShell(), true); - - for (CTabItem item : folder.getItems()) { - assertTrue(item.getShowClose()); - } - for (CTabItem item : folder2.getItems()) { - assertTrue(item.getShowClose()); - } - - engine = createEngine("CTabItem { show-close: false }", folder.getDisplay()); - engine.applyStyles(folder.getShell(), true); - for (CTabItem item : folder.getItems()) { - assertFalse(item.getShowClose()); - } - for (int i = 0; i < folder.getItemCount(); i++) { - assertFalse(folder2.getItem(i).getShowClose()); - } - } - - private void testSelectedShowClose(CTabFolder folder, int index) { - CTabItem[] items = folder.getItems(); - folder.setSelection(index); - spinEventLoop(); - - for (int i = 0; i < items.length; i++) { - if (i == index) { - assertTrue(items[i].getShowClose()); - assertEquals("true", engine.retrieveCSSProperty(items[i], "show-close", null)); - } else { - assertFalse(items[i].getShowClose()); - assertEquals("false", engine.retrieveCSSProperty(items[i], "show-close", null)); - } - } - } - - @Test - void testSelectedShowClose() { - CTabFolder folder = createTestTabFolder("CTabItem:selected { show-close: true }"); - for (int i = 0; i < folder.getItemCount(); i++) { - testSelectedShowClose(folder, i); - } - - engine = createEngine("CTabItem:selected { show-close: false }", folder.getDisplay()); - engine.applyStyles(folder.getShell(), true); - for (CTabItem item : folder.getItems()) { - assertFalse(item.getShowClose()); - } - } - - @Test - void testSelectedShowClose2() { - CTabFolder folder = createTestTabFolder("CTabItem { show-close: false }\n" - + "CTabItem:selected { show-close: true }"); - for (int i = 0; i < folder.getItemCount(); i++) { - testSelectedShowClose(folder, i); - } - } - - @Disabled("test was commented before bug 443094") - @Test - void testClassSelectedShowClose() { - CTabFolder folder = createTestTabFolder(); - WidgetElement.setCSSClass(folder, "editorStack"); - - CSSEngine engine = createEngine("CTabFolder.editorStack CTabItem { show-close: true }", folder.getDisplay()); - engine.applyStyles(folder.getShell(), true); - - for (CTabItem item : folder.getItems()) { - assertTrue(item.getShowClose()); - } - } - @Disabled("test was commented before bug 443094") @Test void testFontsEditorStackClass() {