Skip to content

Commit

Permalink
Add missing HasEnabled implementation to HighchartsWidget.java (#600)
Browse files Browse the repository at this point in the history
- Add missing HasEnabled implementation to HighchartsWidget.java
- Add missing styles for disabled Charts component

Fixes: #427
  • Loading branch information
TatuLund authored Nov 6, 2020
1 parent f59f2a2 commit 403a0f9
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Document;
import com.google.gwt.user.client.ui.HasEnabled;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.addon.charts.client.HighchartsScriptLoader;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.StyleConstants;

public class HighchartWidget extends Widget {
public class HighchartWidget extends Widget implements HasEnabled {

private HighchartJsOverlay jsOverlay;
private boolean enabled;

public HighchartWidget() {
HighchartsScriptLoader.ensureInjected();
Expand Down Expand Up @@ -207,4 +210,17 @@ public int getXAxisIndex(HighchartAxis axis) {
public int getNumberOfSeries() {
return jsOverlay.getSeries().length();
}

@Override
public boolean isEnabled() {
return enabled;
}

@Override
public void setEnabled(boolean enabled) {
if (this.enabled != enabled) {
this.enabled = enabled;
setStyleName(StyleConstants.DISABLED, !enabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
<inherits name="com.vaadin.DefaultWidgetSet" />
<inherits name="com.google.gwt.json.JSON" />

<!-- Widget styles in public -directory -->
<stylesheet src="charts/styles.css"/>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.v-disabled {
.vaadin-chart {
pointer-events: none;
opacity: 70%;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.vaadin.addon.charts.examples.columnandbar;

import com.vaadin.addon.charts.examples.SkipFromDemo;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;

@SuppressWarnings("serial")
@SkipFromDemo
public class BarWithDisabledState extends BasicBarNoTitle {

private Component chart;

@Override
protected Component getChart() {
chart = super.getChart();
chart.setId("bar-with-disabled-state");

return chart;
}

@Override
protected void setup() {
super.setup();

Button button = new Button("toggle enabled", e -> chart.setEnabled(!chart.isEnabled()));
button.setId("disable-button");
addComponent(button);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.vaadin.addon.charts.testbenchtests;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.addon.charts.examples.columnandbar.BarWithDisabledState;
import com.vaadin.client.StyleConstants;
import com.vaadin.testbench.elements.ButtonElement;

public class BarWithDisabledStateTBTest extends AbstractParallelTest {

@Test
public void test() throws IOException, AssertionError {
driver.get(getTestUrl());

waitForVaadin();

WebElement chart = findElement(By.id("bar-with-disabled-state"));

ButtonElement disableButton = $(ButtonElement.class).id("disable-button");
disableButton.click();
waitForVaadin();

Assert.assertTrue(chart.getAttribute("class").contains(StyleConstants.DISABLED));

disableButton.click();
waitForVaadin();

Assert.assertFalse(chart.getAttribute("class").contains(StyleConstants.DISABLED));

}

@Override
protected String getTestViewName() {
return BarWithDisabledState.class.getSimpleName();
}

@Override
protected String getPackageName() {
return "columnandbar";
}

}

0 comments on commit 403a0f9

Please sign in to comment.