Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartThemePanel.java @ 9416:05405292a7ca
Navigationtheme panel now shows themes of dWt and WQ charts grayed out, if the current station is outside the valid range of the theme.
author | gernotbelger |
---|---|
date | Thu, 16 Aug 2018 16:28:03 +0200 |
parents | 5e38e2924c07 |
children |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartThemePanel.java Thu Aug 16 16:27:53 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartThemePanel.java Thu Aug 16 16:28:03 2018 +0200 @@ -8,25 +8,12 @@ package org.dive4elements.river.client.client.ui.chart; -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.menu.Menu; -import com.smartgwt.client.widgets.menu.MenuItem; -import com.smartgwt.client.widgets.menu.events.ClickHandler; -import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; - import org.dive4elements.river.client.client.Config; -import org.dive4elements.river.client.client.FLYSConstants; import org.dive4elements.river.client.client.services.FeedServiceAsync; import org.dive4elements.river.client.client.services.LoadArtifactService; import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; import org.dive4elements.river.client.client.ui.CollectionView; +import org.dive4elements.river.client.client.ui.IThemeRecordHandler; import org.dive4elements.river.client.client.ui.ThemePanel; import org.dive4elements.river.client.shared.model.Artifact; import org.dive4elements.river.client.shared.model.Data; @@ -38,6 +25,18 @@ import org.dive4elements.river.client.shared.model.Theme; import org.dive4elements.river.client.shared.model.ThemeList; +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.menu.Menu; +import com.smartgwt.client.widgets.menu.MenuItem; +import com.smartgwt.client.widgets.menu.events.ClickHandler; +import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; /** * ThemePanel on the left in CollectionView. @@ -48,348 +47,272 @@ */ public class ChartThemePanel extends ThemePanel { /** Artifact Clone/Creation service. */ - protected LoadArtifactServiceAsync loadService = - GWT.create(LoadArtifactService.class); - - /** The interface that provides i18n messages. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public static final String GRID_FIELD_ACTIVE = "active"; - public static final String GRID_FIELD_NAME = "name"; - public static final String GRID_FIELD_ACTIONS = "actions"; + private final LoadArtifactServiceAsync loadService = GWT.create(LoadArtifactService.class); - FeedServiceAsync feedService = GWT.create( - org.dive4elements.river.client.client.services.FeedService.class); - + protected static final String GRID_FIELD_ACTIVE = "active"; + protected static final String GRID_FIELD_NAME = "name"; + protected static final String GRID_FIELD_ACTIONS = "actions"; - /** Constructor for a ChartThemePanel. */ - public ChartThemePanel( - OutputMode mode, - CollectionView view - ) { - super(mode, view); + protected final FeedServiceAsync feedService = GWT.create(org.dive4elements.river.client.client.services.FeedService.class); - initGrid(); + /** Constructor for a ChartThemePanel. + * @param recordHandler */ + public ChartThemePanel(final OutputMode mode, final CollectionView view, final IThemeRecordHandler recordHandler) { + super(mode, view, recordHandler); + + initGrid(recordHandler); initLayout(); updateGrid(); } - /** Creates Layout with theme list and navigation bar inside. */ protected VLayout createLayout() { - VLayout layout = new VLayout(); + final VLayout layout = new VLayout(); layout.setWidth100(); layout.setHeight100(); - layout.addMember(list); - layout.addMember(navigation); + layout.addMember(this.list); + layout.addMember(this.navigation); return layout; } - /** * Initializes the layout of this panel. */ - protected void initLayout() { + private void initLayout() { setWidth100(); setHeight100(); addChild(createLayout()); } - /** * Initializes the components (columns) of the theme grid. + * @param recordHandler */ - protected void initGrid() { - list.setCanEdit(true); - list.setCanSort(false); - list.setShowRecordComponents(false); - list.setShowRecordComponentsByCell(true); - list.setShowHeader(true); - list.setShowHeaderContextMenu(false); - list.setWidth100(); - list.setHeight100(); + protected void initGrid( final IThemeRecordHandler recordHandler ) { + this.list.setCanEdit(true); + this.list.setCanSort(false); + this.list.setShowRecordComponents(false); + this.list.setShowRecordComponentsByCell(true); + this.list.setShowHeader(true); + this.list.setShowHeaderContextMenu(false); + this.list.setWidth100(); + this.list.setHeight100(); - list.addEditCompleteHandler(this); + this.list.addEditCompleteHandler(this); - ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); + final ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); active.setType(ListGridFieldType.BOOLEAN); - ListGridField name = new ListGridField( - GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); + final ListGridField name = new ListGridField(GRID_FIELD_NAME, this.MSG.chart_themepanel_header_themes()); name.setType(ListGridFieldType.TEXT); - list.setFields(active, name); + if( recordHandler instanceof CellFormatter) + name.setCellFormatter((CellFormatter) recordHandler); + + this.list.setFields(active, name); } - /** Set theme active/inactive. */ @Override - public void activateTheme(Theme theme, boolean active) { + public void activateTheme(final Theme theme, final boolean active) { theme.setActive(active ? 1 : 0); } - /** Returns name of longitudinal section area facets. */ protected String getAreaFacetName() { return "longitudinal_section.area"; } - /** Create the DataProvider ('Blackboard') key for a theme. */ - public static String areaKey(Theme theme) { - return theme.getArtifact() + ":" + theme.getFacet() + ":" - + theme.getIndex(); + public static String areaKey(final Theme theme) { + return theme.getArtifact() + ":" + theme.getFacet() + ":" + theme.getIndex(); } - /** * Tell an area artifact where to get the upper and lower curve from. - * @param artifact UUID of area-artifact. + * + * @param artifact + * UUID of area-artifact. */ - public void feedTellArea( - final String artifact, - Theme under, - Theme over, - boolean between - ) { + public void feedTellArea(final String artifact, final Theme under, final Theme over, final boolean between) { Data[] feedData; if (over != null && under != null) { - feedData = new Data[] { - DefaultData.createSimpleStringData("area.curve_under", - areaKey(under)), - DefaultData.createSimpleStringData("area.curve_over", - areaKey(over)), - DefaultData.createSimpleStringData("area.name", - over.getDescription() + " / " + under.getDescription()), - DefaultData.createSimpleStringData("area.facet", - getAreaFacetName()), - DefaultData.createSimpleStringData("area.between", - (between)? "true" : "false") - }; + feedData = new Data[] { DefaultData.createSimpleStringData("area.curve_under", areaKey(under)), + DefaultData.createSimpleStringData("area.curve_over", areaKey(over)), + DefaultData.createSimpleStringData("area.name", over.getDescription() + " / " + under.getDescription()), + DefaultData.createSimpleStringData("area.facet", getAreaFacetName()), + DefaultData.createSimpleStringData("area.between", (between) ? "true" : "false") }; GWT.log("Have 'over' and 'under' curve"); - } - else if (over == null && under != null) { - feedData = new Data[] { - DefaultData.createSimpleStringData("area.curve_under", - areaKey(under)), - DefaultData.createSimpleStringData("area.name", - under.getDescription() + " / " + MSG.getString("x_axis")), - DefaultData.createSimpleStringData("area.facet", - getAreaFacetName()), - DefaultData.createSimpleStringData("area.between", - (between)? "true" : "false") - }; + } else if (over == null && under != null) { + feedData = new Data[] { DefaultData.createSimpleStringData("area.curve_under", areaKey(under)), + DefaultData.createSimpleStringData("area.name", under.getDescription() + " / " + this.MSG.getString("x_axis")), + DefaultData.createSimpleStringData("area.facet", getAreaFacetName()), + DefaultData.createSimpleStringData("area.between", (between) ? "true" : "false") }; GWT.log("Have 'under' curve only"); - } - else if (over != null && under == null) { - feedData = new Data[] { - DefaultData.createSimpleStringData("area.curve_over", - areaKey(over)), - DefaultData.createSimpleStringData("area.name", - MSG.getString("x_axis") + " / " + over.getDescription()), - DefaultData.createSimpleStringData("area.facet", - getAreaFacetName()), - DefaultData.createSimpleStringData("area.between", - (between)? "true" : "false") - }; + } else if (over != null && under == null) { + feedData = new Data[] { DefaultData.createSimpleStringData("area.curve_over", areaKey(over)), + DefaultData.createSimpleStringData("area.name", this.MSG.getString("x_axis") + " / " + over.getDescription()), + DefaultData.createSimpleStringData("area.facet", getAreaFacetName()), + DefaultData.createSimpleStringData("area.between", (between) ? "true" : "false") }; GWT.log("Have 'over' curve only"); - } - else { + } else { GWT.log("Missing Data for area painting."); return; } - feedService.feed( - Config.getInstance().getLocale(), - new DefaultArtifact(artifact, "TODO:hash"), - feedData, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not feed artifact (" + artifact - + ") with area info: " + caught.getMessage()); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - @Override - public void onSuccess(Artifact fartifact) { - GWT.log("Successfully set area params to " + artifact); - requestRedraw(); - updateCollection(); - updateGrid(); - enable(); - } - }); + this.feedService.feed(Config.getInstance().getLocale(), new DefaultArtifact(artifact, "TODO:hash"), feedData, new AsyncCallback<Artifact>() { + @Override + public void onFailure(final Throwable caught) { + GWT.log("Could not feed artifact (" + artifact + ") with area info: " + caught.getMessage()); + SC.warn(ChartThemePanel.this.MSG.getString(caught.getMessage())); + enable(); + } + + @Override + public void onSuccess(final Artifact fartifact) { + GWT.log("Successfully set area params to " + artifact); + requestRedraw(); + updateCollection(); + updateGrid(); + enable(); + } + }); } - /** * Create and parameterize a new area artifact. + * * @param under - * @param over if null, against axis. - * @param between if true, ignore under/over order. + * @param over + * if null, against axis. + * @param between + * if true, ignore under/over order. */ - public void createAreaArtifact( - final Theme over, - final Theme under, - final boolean between - ) { - Config config = Config.getInstance(); - String locale = config.getLocale(); + public void createAreaArtifact(final Theme over, final Theme under, final boolean between) { + final Config config = Config.getInstance(); + final String locale = config.getLocale(); - Recommendation area = new Recommendation( - "area", - "", - "", - null); + final Recommendation area = new Recommendation("area", "", "", null); // Set target out dynamically. area.setTargetOut(getMode().getName()); - Recommendation[] recommendations = new Recommendation[] {area}; + final Recommendation[] recommendations = new Recommendation[] { area }; - loadService.loadMany( - this.getCollection(), - recommendations, - null, //use individual factories. - locale, - new AsyncCallback<Artifact[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Failed, no area artifact: " + caught.getMessage()); - enable(); - // TODO i18n - SC.warn("Failed, no area artifact: " + caught.getMessage()); - } - @Override - public void onSuccess(Artifact[] artifacts) { - GWT.log("Success, created area artifact: " - + artifacts[0].getUuid()); - // Now, feed the artifact with the relevant data. - feedTellArea(artifacts[0].getUuid(), under, over, between); - } - } - ); + this.loadService.loadMany(this.getCollection(), recommendations, null, // use individual factories. + locale, new AsyncCallback<Artifact[]>() { + @Override + public void onFailure(final Throwable caught) { + GWT.log("Failed, no area artifact: " + caught.getMessage()); + enable(); + // TODO i18n + SC.warn("Failed, no area artifact: " + caught.getMessage()); + } + + @Override + public void onSuccess(final Artifact[] artifacts) { + GWT.log("Success, created area artifact: " + artifacts[0].getUuid()); + // Now, feed the artifact with the relevant data. + feedTellArea(artifacts[0].getUuid(), under, over, between); + } + }); } - /** * Return true if two themes are canditates for an area being * rendered between them. * TODO join with canArea, generalize to allow easier modification - * in subclasses. + * in subclasses. */ - protected boolean areAreaCompatible(Theme a, Theme b) { + protected boolean areAreaCompatible(final Theme a, final Theme b) { if (a.equals(b)) { return false; } - if (a.getFacet().equals("w_differences") && - b.getFacet().equals("w_differences")) { + if (a.getFacet().equals("w_differences") && b.getFacet().equals("w_differences")) { return true; } - if (a.getFacet().equals("longitudinal_section.w") || - a.getFacet().equals("other.wqkms.w") || - a.getFacet().equals("other.wqkms") || - a.getFacet().equals("discharge_longitudinal_section.w") || - a.getFacet().equals("discharge_longitudinal_section.c") || - a.getFacet().equals("other.wkms")) { - return b.getFacet().equals("longitudinal_section.w") - || b.getFacet().equals("other.wqkms") - || b.getFacet().equals("other.wqkms.w") - || b.getFacet().equals("discharge_longitudinal_section.w") - || b.getFacet().equals("discharge_longitudinal_section.c") - || b.getFacet().equals("other.wkms"); - } - else if (a.getFacet().equals("longitudinal_section.q") || - a.getFacet().equals("discharge_longitudinal_section.q") || - a.getFacet().equals("other.wqkms.q")) { - return b.getFacet().equals("longitudinal_section.q") - || b.getFacet().equals("discharge_longitudinal_section.q") + if (a.getFacet().equals("longitudinal_section.w") || a.getFacet().equals("other.wqkms.w") || a.getFacet().equals("other.wqkms") + || a.getFacet().equals("discharge_longitudinal_section.w") || a.getFacet().equals("discharge_longitudinal_section.c") + || a.getFacet().equals("other.wkms")) { + return b.getFacet().equals("longitudinal_section.w") || b.getFacet().equals("other.wqkms") || b.getFacet().equals("other.wqkms.w") + || b.getFacet().equals("discharge_longitudinal_section.w") || b.getFacet().equals("discharge_longitudinal_section.c") + || b.getFacet().equals("other.wkms"); + } else if (a.getFacet().equals("longitudinal_section.q") || a.getFacet().equals("discharge_longitudinal_section.q") + || a.getFacet().equals("other.wqkms.q")) { + return b.getFacet().equals("longitudinal_section.q") || b.getFacet().equals("discharge_longitudinal_section.q") || b.getFacet().equals("other.wqkms.q"); } return false; } - /** * True if context menu should contain 'create area' submenu on * this theme. */ - protected boolean canArea(Theme a) { - return a.getFacet().equals("longitudinal_section.q") - || a.getFacet().equals("longitudinal_section.w") - || a.getFacet().equals("discharge_longitudinal_section.w") - || a.getFacet().equals("discharge_longitudinal_section.q") - || a.getFacet().equals("discharge_longitudinal_section.c") - || a.getFacet().startsWith("other.wqkms") - || a.getFacet().equals("other.wkms") - || a.getFacet().equals("w_differences"); + protected boolean canArea(final Theme a) { + return a.getFacet().equals("longitudinal_section.q") || a.getFacet().equals("longitudinal_section.w") + || a.getFacet().equals("discharge_longitudinal_section.w") || a.getFacet().equals("discharge_longitudinal_section.q") + || a.getFacet().equals("discharge_longitudinal_section.c") || a.getFacet().startsWith("other.wqkms") || a.getFacet().equals("other.wkms") + || a.getFacet().equals("w_differences"); } - /** Attach menu/item to open editor for Manual Points. */ - protected void attachManualPointsMenu(Menu menu) { + protected void attachManualPointsMenu(final Menu menu) { menu.addItem(createSeparator()); - MenuItem editManualPoints = new MenuItem(MSG.editpoints()); + final MenuItem editManualPoints = new MenuItem(this.MSG.editpoints()); editManualPoints.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - if(mode.getName().equals("historical_discharge")) { - new ManualDatePointsEditor(view.getCollection(), - redrawRequestHandlers.get(0), - mode.getName()).show(); - } - else { - new ManualPointsEditor(view.getCollection(), - redrawRequestHandlers.get(0), - mode.getName()).show(); - } + @Override + public void onClick(final MenuItemClickEvent evt) { + if (ChartThemePanel.this.mode.getName().equals("historical_discharge")) { + new ManualDatePointsEditor(ChartThemePanel.this.view.getCollection(), ChartThemePanel.this.redrawRequestHandlers.get(0), + ChartThemePanel.this.mode.getName()).show(); + } else { + new ManualPointsEditor(ChartThemePanel.this.view.getCollection(), ChartThemePanel.this.redrawRequestHandlers.get(0), + ChartThemePanel.this.mode.getName()).show(); } - }); + } + }); menu.addItem(editManualPoints); } - /** * Include area specific menu items and manual point editor, depending * on facet. */ @Override protected Menu getSingleContextMenu(final ListGridRecord[] records) { - Menu menu = super.getSingleContextMenu(records); + final Menu menu = super.getSingleContextMenu(records); - final Theme facetTheme = ((FacetRecord)records[0]).getTheme(); + final Theme facetTheme = ((FacetRecord) records[0]).getTheme(); if (!canArea(facetTheme)) { if (facetTheme.getFacet().endsWith("manualpoints")) { attachManualPointsMenu(menu); return menu; - } - else { + } else { return menu; } } menu.addItem(createSeparator()); - MenuItem areaMenuItem = new MenuItem(MSG.chart_themepanel_new_area()); - Menu areaMenu = new Menu(); + final MenuItem areaMenuItem = new MenuItem(this.MSG.chart_themepanel_new_area()); + final Menu areaMenu = new Menu(); - ThemeList themes = getThemeList(); - int nThemes = themes.getThemeCount(); + final ThemeList themes = getThemeList(); + final int nThemes = themes.getThemeCount(); // Create the "under..." submenu. - MenuItem underMenuItem = new MenuItem( - MSG.chart_themepanel_area_under()); - Menu underMenu = new Menu(); - for (int i = 0; i < nThemes; i++) { - final Theme theme = themes.getThemeAt(i+1); + final MenuItem underMenuItem = new MenuItem(this.MSG.chart_themepanel_area_under()); + final Menu underMenu = new Menu(); + for (int i = 0; i < nThemes; i++) { + final Theme theme = themes.getThemeAt(i + 1); if (theme.getVisible() == 0) { continue; @@ -399,12 +322,12 @@ continue; } - MenuItem againster = new MenuItem(theme.getDescription()); + final MenuItem againster = new MenuItem(theme.getDescription()); underMenu.addItem(againster); againster.addClickHandler(new ClickHandler() { @Override - public void onClick(MenuItemClickEvent evt) { + public void onClick(final MenuItemClickEvent evt) { disable(); createAreaArtifact(theme, facetTheme, false); } @@ -412,32 +335,32 @@ } // Create the "over..." submenu. - MenuItem overMenuItem = new MenuItem(MSG.chart_themepanel_area_over()); - Menu overMenu = new Menu(); - for (int i = 0; i < nThemes; i++) { - final Theme theme = themes.getThemeAt(i+1); + final MenuItem overMenuItem = new MenuItem(this.MSG.chart_themepanel_area_over()); + final Menu overMenu = new Menu(); + for (int i = 0; i < nThemes; i++) { + final Theme theme = themes.getThemeAt(i + 1); if (theme.getVisible() == 0) { continue; } if (!areAreaCompatible(facetTheme, theme)) { continue; } - MenuItem againster = new MenuItem(theme.getDescription()); + final MenuItem againster = new MenuItem(theme.getDescription()); overMenu.addItem(againster); againster.addClickHandler(new ClickHandler() { @Override - public void onClick(MenuItemClickEvent evt) { + public void onClick(final MenuItemClickEvent evt) { disable(); createAreaArtifact(facetTheme, theme, false); } }); } overMenu.addItem(createSeparator()); - MenuItem againstAxis = new MenuItem(MSG.getString("x_axis")); + final MenuItem againstAxis = new MenuItem(this.MSG.getString("x_axis")); againstAxis.addClickHandler(new ClickHandler() { @Override - public void onClick(MenuItemClickEvent evt) { + public void onClick(final MenuItemClickEvent evt) { disable(); createAreaArtifact(null, facetTheme, false); } @@ -445,23 +368,22 @@ overMenu.addItem(againstAxis); // Create the "between..." submenu. - MenuItem betweenMenuItem = new MenuItem( - MSG.chart_themepanel_area_between()); - Menu betweenMenu = new Menu(); - for (int i = 0; i < nThemes; i++) { - final Theme theme = themes.getThemeAt(i+1); + final MenuItem betweenMenuItem = new MenuItem(this.MSG.chart_themepanel_area_between()); + final Menu betweenMenu = new Menu(); + for (int i = 0; i < nThemes; i++) { + final Theme theme = themes.getThemeAt(i + 1); if (theme.getVisible() == 0) { continue; } if (!areAreaCompatible(facetTheme, theme)) { continue; } - MenuItem againster = new MenuItem(theme.getDescription()); + final MenuItem againster = new MenuItem(theme.getDescription()); betweenMenu.addItem(againster); againster.addClickHandler(new ClickHandler() { @Override - public void onClick(MenuItemClickEvent evt) { + public void onClick(final MenuItemClickEvent evt) { disable(); createAreaArtifact(facetTheme, theme, true); } @@ -478,11 +400,10 @@ areaMenu.addItem(overMenuItem); areaMenu.addItem(underMenuItem); areaMenu.addItem(createSeparator()); - MenuItem standAloneAgainstAxis = new MenuItem( - MSG.getString("against_x_axis")); + final MenuItem standAloneAgainstAxis = new MenuItem(this.MSG.getString("against_x_axis")); standAloneAgainstAxis.addClickHandler(new ClickHandler() { @Override - public void onClick(MenuItemClickEvent evt) { + public void onClick(final MenuItemClickEvent evt) { disable(); createAreaArtifact(null, facetTheme, false); } @@ -494,5 +415,4 @@ return menu; } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +} \ No newline at end of file