mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-21 19:50:01 +00:00
formatting and single point of exit pattern in AbstractLeaderboardViewer
This commit is contained in:
1 parent
39d2fc1ea5
commit
9d35ff37a5
1 file changed
+45
-55
+45
-55
@@ -21,8 +21,8 @@ import com.sap.sse.gwt.client.player.Timer;
|
||||
|
||||
/**
|
||||
* A base class for a leaderboard viewer.
|
||||
*
|
||||
* @author Frank Mittag (c163874)
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractLeaderboardViewer extends SimplePanel {
|
||||
protected final StringMessages stringMessages;
|
||||
@@ -50,74 +50,64 @@ public abstract class AbstractLeaderboardViewer extends SimplePanel {
|
||||
protected FlowPanel createViewerPanel() {
|
||||
FlowPanel mainPanel = new FlowPanel();
|
||||
mainPanel.setSize("100%", "100%");
|
||||
|
||||
getElement().getStyle().setMarginLeft(12, Unit.PX);
|
||||
getElement().getStyle().setMarginRight(12, Unit.PX);
|
||||
|
||||
if(!hideToolbar) {
|
||||
componentsNavigationPanel = new FlowPanel();
|
||||
componentsNavigationPanel.addStyleName(STYLE_VIEWER_TOOLBAR);
|
||||
mainPanel.add(componentsNavigationPanel);
|
||||
}
|
||||
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
protected <SettingsType> void addComponentToNavigationMenu(final Component<SettingsType> component, boolean isCheckboxEnabled,
|
||||
String componentDisplayName, final boolean hasSettingsWhenComponentIsInvisible) {
|
||||
if(hideToolbar) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String componentName = componentDisplayName != null ? componentDisplayName : component.getLocalizedShortName();
|
||||
final String debugIdPrefix = DebugIdHelper.createDebugId(componentName);
|
||||
final CheckBox checkBox= new CheckBox(componentName);
|
||||
checkBox.ensureDebugId(debugIdPrefix + "DisplayCheckBox");
|
||||
final Button settingsButton = new Button("");
|
||||
settingsButton.ensureDebugId(debugIdPrefix + "SettingsButton");
|
||||
|
||||
checkBox.getElement().getStyle().setFloat(Style.Float.LEFT);
|
||||
|
||||
checkBox.setEnabled(isCheckboxEnabled);
|
||||
checkBox.setValue(component.isVisible());
|
||||
checkBox.setTitle(stringMessages.showHideComponent(componentName));
|
||||
checkBox.addStyleName(STYLE_VIEWER_TOOLBAR_INNERELEMENT);
|
||||
|
||||
checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
||||
@Override
|
||||
public void onValueChange(ValueChangeEvent<Boolean> newValue) {
|
||||
boolean visible = checkBox.getValue();
|
||||
component.setVisible(visible);
|
||||
|
||||
if (visible && component instanceof TimeListener) {
|
||||
// trigger the component to update its data
|
||||
((TimeListener) component).timeChanged(timer.getTime(), null);
|
||||
}
|
||||
if(component.hasSettings() && !hasSettingsWhenComponentIsInvisible) {
|
||||
settingsButton.setEnabled(visible);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
componentsNavigationPanel.add(checkBox);
|
||||
|
||||
if(component.hasSettings()) {
|
||||
settingsButton.addClickHandler(new ClickHandler() {
|
||||
if (!hideToolbar) {
|
||||
final String componentName = componentDisplayName != null ? componentDisplayName : component
|
||||
.getLocalizedShortName();
|
||||
final String debugIdPrefix = DebugIdHelper.createDebugId(componentName);
|
||||
final CheckBox checkBox = new CheckBox(componentName);
|
||||
checkBox.ensureDebugId(debugIdPrefix + "DisplayCheckBox");
|
||||
final Button settingsButton = new Button("");
|
||||
settingsButton.ensureDebugId(debugIdPrefix + "SettingsButton");
|
||||
checkBox.getElement().getStyle().setFloat(Style.Float.LEFT);
|
||||
checkBox.setEnabled(isCheckboxEnabled);
|
||||
checkBox.setValue(component.isVisible());
|
||||
checkBox.setTitle(stringMessages.showHideComponent(componentName));
|
||||
checkBox.addStyleName(STYLE_VIEWER_TOOLBAR_INNERELEMENT);
|
||||
checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
SettingsDialog<SettingsType> dialog = new SettingsDialog<SettingsType>(component, stringMessages);
|
||||
dialog.ensureDebugId(debugIdPrefix + "SettingsDialog");
|
||||
dialog.show();
|
||||
}
|
||||
public void onValueChange(ValueChangeEvent<Boolean> newValue) {
|
||||
boolean visible = checkBox.getValue();
|
||||
component.setVisible(visible);
|
||||
|
||||
if (visible && component instanceof TimeListener) {
|
||||
// trigger the component to update its data
|
||||
((TimeListener) component).timeChanged(timer.getTime(), null);
|
||||
}
|
||||
if (component.hasSettings() && !hasSettingsWhenComponentIsInvisible) {
|
||||
settingsButton.setEnabled(visible);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
settingsButton.setEnabled(component.hasSettings() && hasSettingsWhenComponentIsInvisible);
|
||||
settingsButton.addStyleName(STYLE_VIEWER_TOOLBAR_SETTINGS_BUTTON);
|
||||
settingsButton.getElement().getStyle().setFloat(Style.Float.LEFT);
|
||||
settingsButton.setTitle(stringMessages.settingsForComponent(componentName));
|
||||
|
||||
componentsNavigationPanel.add(settingsButton);
|
||||
componentsNavigationPanel.add(checkBox);
|
||||
if (component.hasSettings()) {
|
||||
settingsButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
SettingsDialog<SettingsType> dialog = new SettingsDialog<SettingsType>(component,
|
||||
stringMessages);
|
||||
dialog.ensureDebugId(debugIdPrefix + "SettingsDialog");
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
settingsButton.setEnabled(component.hasSettings() && hasSettingsWhenComponentIsInvisible);
|
||||
settingsButton.addStyleName(STYLE_VIEWER_TOOLBAR_SETTINGS_BUTTON);
|
||||
settingsButton.getElement().getStyle().setFloat(Style.Float.LEFT);
|
||||
settingsButton.setTitle(stringMessages.settingsForComponent(componentName));
|
||||
componentsNavigationPanel.add(settingsButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user