Mercurial > dive4elements > river
changeset 5834:f507086aa94b
Repaired internal references.
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module rename-to='flys'> - <!-- Inherit the core Web Toolkit stuff. --> - <inherits name='com.google.gwt.user.User'/> - - <!-- Inherit the i18n google stuff. --> - <inherits name="com.google.gwt.i18n.I18N"/> - - <!-- Inherit the XML stuff of GWT --> - <inherits name="com.google.gwt.xml.XML"/> - - <!-- Inherit the Resource module of GWT --> - <inherits name="com.google.gwt.resources.Resources"/> - - <inherits name="de.intevation.artifacts.common.Common"/> - - <!-- Inherit the smartgwt Enterprise Theme. --> - <inherits name="com.smartgwt.SmartGwtNoTheme" /> - <!--inherits name="com.smartclient.theme.enterprise.Enterprise"/> - <inherits name="com.smartclient.theme.enterprise.EnterpriseResources"/--> - - <!-- Works again with smart-gwt2.5 patch from maven repository--> - <inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlue"/> - <inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlueResources"/> - - <!-- Works: - <inherits name="com.smartclient.theme.graphite.Graphite"/> - <inherits name="com.smartclient.theme.graphite.GraphiteResources"/> - --> - - <!-- Inherit the gwtopenlayers stuff --> - <inherits name="org.gwtopenmaps.openlayers.OpenLayers"/> - - <!-- Other module inherits --> - - <!-- Specify the app entry point class. --> - <entry-point class='de.intevation.flys.client.client.FLYS'/> - - <!-- Specify the paths for translatable code --> - <source path='client'/> - <source path='shared'/> - - <extend-property name="locale" values="de,en"/> -</module>
--- a/flys-client/src/main/java/de/intevation/flys/client/client/Config.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -package de.intevation.flys.client.client; - -import com.google.gwt.i18n.client.LocaleInfo; - -import com.google.gwt.xml.client.Document; -import com.google.gwt.xml.client.Node; - - -/** - * A class that is used to handle the global configuration of this client. You - * can retrieve an instance of this class using the <code>getInstance</code> - * methods. <b>NOTE:</b> the configuration is initialized using {@link - * getInstance(Document)} the first time. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class Config { - - /** The instance of the configuration. */ - protected static Config INSTANCE; - - /** The xml document that contains the configuration options. */ - protected Document config; - - - /** - * Get an instance by using {@link getInstance(Document)} or {@link - * getInstance()}. - */ - private Config(Document config) { - this.config = config; - } - - - /** - * Returns an instance of this class and initializes the configuration of - * this has not been done so far. - * - * @param config The client configuration. - * - * @return an instance of this Config class. - */ - public static Config getInstance(Document config) { - if (INSTANCE == null) { - INSTANCE = new Config(config); - } - - return INSTANCE; - } - - - /** - * Returns an instance of this class. If it has not been initialized with a - * valid configuration, null is returned. - * - * @return an instance of this class or null, if the Config has not been - * initialized using {@link getInstance(Document)} so far. - */ - public static Config getInstance() { - return INSTANCE; - } - - - /** - * Returns the URL of the artifact server. - * - * @return the artifact server url. - */ - public String getServerUrl() { - Node server = config.getElementsByTagName("server").item(0); - return server.getFirstChild().getNodeValue(); - } - - - /** - * Returns the name of the current locale. - * - * @return the name of the current locale. - */ - public String getLocale() { - return LocaleInfo.getCurrentLocale().getLocaleName(); - } - - - /** - * Returns the integer configured at - * <i>/config/projectlist/update-interval/text()</i> or -1 if an error - * occured or no such option is defined. - * - * @return the update interval of the project list. - */ - public int getProjectListUpdateInterval() { - Node projectlist = config.getElementsByTagName("projectlist").item(0); - - if (projectlist == null) { - return -1; - } - - Node interval = config.getElementsByTagName("update-interval").item(0); - - if (interval == null) { - return -1; - } - - String value = interval.getFirstChild().getNodeValue(); - - return value != null ? Integer.valueOf(value) : -1; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,629 +0,0 @@ -package de.intevation.flys.client.client; - -import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.core.client.GWT; -import com.google.gwt.event.shared.UmbrellaException; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.xml.client.XMLParser; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.HTMLPane; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.events.CloseClickEvent; -import com.smartgwt.client.widgets.events.CloseClickHandler; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.event.CollectionChangeEvent; -import de.intevation.flys.client.client.event.CollectionChangeHandler; -import de.intevation.flys.client.client.services.ArtifactService; -import de.intevation.flys.client.client.services.ArtifactServiceAsync; -import de.intevation.flys.client.client.services.CreateCollectionService; -import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; -import de.intevation.flys.client.client.services.DescribeCollectionService; -import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; -import de.intevation.flys.client.client.services.GetArtifactService; -import de.intevation.flys.client.client.services.GetArtifactServiceAsync; -import de.intevation.flys.client.client.services.RiverService; -import de.intevation.flys.client.client.services.RiverServiceAsync; -import de.intevation.flys.client.client.services.UserService; -import de.intevation.flys.client.client.services.UserServiceAsync; -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.FLYSHeader; -import de.intevation.flys.client.client.ui.FLYSView; -import de.intevation.flys.client.client.ui.FLYSWorkspace; -import de.intevation.flys.client.client.ui.ProjectList; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItem; -import de.intevation.flys.client.shared.model.GaugeInfo; -import de.intevation.flys.client.shared.model.River; -import de.intevation.flys.client.shared.model.User; - -import de.intevation.flys.client.client.ui.wq.WQAutoTabSet; - -import java.util.ArrayList; -import java.util.List; -import java.util.MissingResourceException; -import java.util.Set; - - -/** - * Entry point classes define <code>onModuleLoad()</code>. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class FLYS implements EntryPoint, CollectionChangeHandler { - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** The UserService used to retrieve information about the current user. */ - protected UserServiceAsync userService = GWT.create(UserService.class); - - /** The RiverService used to retrieve the supported rivers of the server.*/ - protected RiverServiceAsync riverService = GWT.create(RiverService.class); - - /** The ArtifactService used to communicate with the Artifact server. */ - protected ArtifactServiceAsync artifactService = - GWT.create(ArtifactService.class); - - /** The ArtifactService used to communicate with the Artifact server. */ - protected DescribeCollectionServiceAsync describeCollectionService = - GWT.create(DescribeCollectionService.class); - - /** The GetArtifactService used to open an existing collection. */ - protected GetArtifactServiceAsync getArtifactService = - GWT.create(GetArtifactService.class); - - /** The CreateCollectionServiceAsync used to create a new collection */ - protected CreateCollectionServiceAsync collectionService = - GWT.create(CreateCollectionService.class); - - /** The content window. It takes the whole space beneath the header. */ - protected FLYSView view; - - /** The project list that displays the projects of the user. */ - protected ProjectList projectList; - - /** The FLYSWorkspace. */ - protected FLYSWorkspace workspace; - - /** The user who is currently logged in. */ - protected User currentUser; - - /** The list of rivers supported by the server. */ - protected River[] rivers; - - /** This list is used to track the opened projects. */ - protected List<String> openProjects; - - private FLYSHeader header; - - - public static String getExceptionString(FLYSConstants msg, Throwable caught) { - try { - return msg.getString(caught.getMessage()); - } - catch(MissingResourceException ex) { - // There are some server error exceptions with - // varying text messages that cannot be localized - // easily. In this rare cases, use the plain - // exception message. - GWT.log("Missing resource for: " + caught.getMessage()); - return caught.getLocalizedMessage(); - } - } - - /** - * This is the entry point method. - */ - @Override - public void onModuleLoad() { - openProjects = new ArrayList<String>(); - - //GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { - // public void onUncaughtException(Throwable e) { - // showWarning(e); - // } - //}); - - VLayout vertical = new VLayout(); - vertical.setLayoutMargin(1); - vertical.setWidth100(); - vertical.setHeight100(); - - view = new FLYSView(); - header = new FLYSHeader(this); - - vertical.addMember(header); - vertical.addMember(view); - - vertical.draw(); - - initConfiguration(); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - userService.getCurrentUser(locale, new AsyncCallback<User>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not find a logged in user."); - String msg = getExceptionString(MSG, caught); - SC.warn(msg); - } - - @Override - public void onSuccess(User user) { - GWT.log("Found a user. Set '"+ user.getName() + "'"); - setCurrentUser(user); - - header.setCurrentUser(user); - - projectList = new ProjectList(FLYS.this, user); - workspace = new FLYSWorkspace(FLYS.this); - view.setProjectList(projectList); - view.setFLYSWorkspace(workspace); - - readRivers(); - } - }); - } - - - public void showWarning(Throwable e) { - StringBuilder sb = new StringBuilder(); - sb.append("<tt>"); - - if (e instanceof UmbrellaException) { - UmbrellaException u = (UmbrellaException) e; - Set<Throwable> throwables = u.getCauses(); - - for (Throwable t: throwables) { - sb.append(t.getLocalizedMessage()); - sb.append("<br>"); - } - } - else { - sb.append(e.getLocalizedMessage()); - } - - sb.append("</tt>"); - - Window w = new Window(); - w.setTitle(MSG.unexpected_exception()); - w.setWidth(550); - w.setHeight(300); - w.centerInPage(); - w.setCanDragResize(true); - - HTMLPane p = new HTMLPane(); - p.setContents(sb.toString()); - - w.addItem(p); - w.show(); - } - - - /** - * This method should be called at system start. It initialzes the client - * configuration. - */ - protected void initConfiguration() { - String xml = FLYSResources.INSTANCE.initialConfiguration().getText(); - Config.getInstance(XMLParser.parse(xml)); - } - - - /** - * Returns the user that is currently logged in. - * - * @return the current user. - */ - public User getCurrentUser() { - return currentUser; - } - - - /** - * Sets the current user. - */ - public void setCurrentUser(User user) { - currentUser = user; - } - - - /** - * Returns the project list. - */ - public ProjectList getProjectList() { - return projectList; - } - - - /** - * Returns the projects workspace that contains all project windows. - * - * @return the FLYSWorkspace. - */ - public FLYSWorkspace getWorkspace() { - return workspace; - } - - - /** - * Returns a list of rivers supported by the artifact server. - * - * @return a list of rivers supported by the artifact server. - */ - public River[] getRivers() { - return rivers; - } - - - protected void readRivers() { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - riverService.list(locale, new AsyncCallback<River[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve a list of rivers."); - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(River[] newRivers) { - GWT.log("Retrieved " + newRivers.length + " new rivers."); - rivers = newRivers; - } - }); - } - - - /** - * This method creates a new CollectionView and adds it to the workspace. - * <b>NOTE</b>The user needs to be logged in and there need to at least one - * river - otherwise a warning is displayed and no CollectionView is - * created. - */ - public void newProject() { - if (getCurrentUser() == null) { - SC.warn(MSG.error_not_logged_in()); - return; - } - - if (getRivers() == null) { - SC.warn(MSG.error_no_rivers_found()); - readRivers(); - - return; - } - - CollectionView view = new CollectionView(this); - workspace.addView("new-project", view); - - view.addCollectionChangeHandler(getProjectList()); - } - - - protected void lockProject(String uuid) { - if (isProjectLocked(uuid)) { - return; - } - - openProjects.add(uuid); - } - - - protected void unlockProject(String uuid) { - openProjects.remove(uuid); - } - - - /** Whether project uuid is currently opened. */ - protected boolean isProjectLocked(String uuid) { - return openProjects.contains(uuid); - } - - - /** Opens (or bring into foreground) project with given id. */ - public void openProject(final String collectionID) { - if (collectionID == null) { - return; - } - - if (isProjectLocked(collectionID)) { - workspace.bringUp(collectionID); - return; - } - - lockProject(collectionID); - - GWT.log("Open existing project: " + collectionID); - - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - describeCollectionService.describe(collectionID, locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Collection c) { - final Collection collection = c; - - if (collection.getItemLength() == 0) { - CollectionView view = new CollectionView( - FLYS.this, collection, null); - - view.addCollectionChangeHandler( - getProjectList()); - view.addCloseClickHandler( - new CloseCollectionViewHandler( - FLYS.this, collectionID)); - - workspace.addView(collectionID, view); - - return; - } - - final CollectionItem item = c.getItem(0); - - if (item == null) { - SC.warn(MSG.error_load_parameterization()); - return; - } - - getArtifactService.getArtifact( - locale, - item.identifier(), - item.hash(), - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - unlockProject(collectionID); - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - CollectionView view = new CollectionView( - FLYS.this, collection, artifact); - - view.addCollectionChangeHandler( - getProjectList()); - view.addCloseClickHandler( - new CloseCollectionViewHandler( - FLYS.this, collectionID)); - - workspace.addView(collectionID, view); - } - }); - - } - }); - } - - - public void closeProject(String uuid) { - unlockProject(uuid); - workspace.destroyProject(uuid); - } - - - /** - * Create a new Artifact. - */ - public void newArtifact(String factory) { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - artifactService.create(locale, factory, null, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not create the new artifact."); - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully created a new artifact."); - } - }); - } - - - /** Opens a window with Main Values from gauge. */ - public void newGaugeMainValueTable(GaugeInfo gauge) { - Window mainValueView = new Window(); - - // Take middle to avoid issues at borders. - double km = (gauge.getKmEnd() + gauge.getKmStart())/2d; - mainValueView.addItem(new WQAutoTabSet(gauge.getRiverName(), - new double[] {km, km})); - mainValueView.setWidth(450); - mainValueView.setHeight(600); - - mainValueView.setMaximized(false); - mainValueView.centerInPage(); - mainValueView.setCanDragReposition(true); - mainValueView.setCanDragResize(true); - mainValueView.setShowMaximizeButton(true); - mainValueView.setKeepInParentRect(true); - - mainValueView.setTitle(MSG.mainvalues() + " " + gauge.getName() + " (" + gauge.getRiverName() + ")" ); - workspace.addChild(mainValueView); - } - - public void newGaugeDischargeCurve(String river, Long gaugeref) { - Config config = Config.getInstance(); - - final String locale = config.getLocale(); - final String riv = river; - final Long ref = gaugeref; - final FLYS flys = this; - - User user = getCurrentUser(); - - if (user == null) { - SC.warn(MSG.error_not_logged_in()); - return; - } - - collectionService.create(locale, user.identifier(), - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not create new collection."); - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Collection collection) { - GWT.log("Successfully created a new collection."); - final Collection col = collection; - artifactService.createGaugeDischargeCurveArtifact( - col, locale, riv, ref, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not create the new artifact."); - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully created a new artifact."); - CollectionView view = new CollectionView(flys, - col, artifact); - workspace.addView(col.identifier(), view); - - view.addCollectionChangeHandler(getProjectList()); - view.addCloseClickHandler( - new CloseCollectionViewHandler( - FLYS.this, col.identifier())); - projectList.updateUserCollections(); - } - }); - } - }); - } - - public void newSQRelation(String river, int measurementStation) { - Config config = Config.getInstance(); - - final String locale = config.getLocale(); - final String riv = river; - final int mStation = measurementStation; - final FLYS flys = this; - - User user = getCurrentUser(); - - if (user == null) { - SC.warn(MSG.error_not_logged_in()); - return; - } - - collectionService.create(locale, user.identifier(), - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not create new collection."); - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Collection collection) { - GWT.log("Successfully created a new collection."); - final Collection col = collection; - artifactService.createSQRelationArtifact( - col, locale, riv, mStation, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not create the new artifact."); - SC.warn(getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully created a new artifact."); - CollectionView view = new CollectionView(flys, - col, artifact); - workspace.addView(col.identifier(), view); - - view.addCollectionChangeHandler(getProjectList()); - view.addCloseClickHandler( - new CloseCollectionViewHandler( - FLYS.this, col.identifier())); - projectList.updateUserCollections(); - } - }); - } - }); - } - - @Override - public void onCollectionChange(CollectionChangeEvent event) { - Collection oldC = event.getOldValue(); - - if (oldC == null) { - Collection newC = event.getNewValue(); - lockProject(newC.identifier()); - } - } - - - - /** - * This CloseClickHandler is used to remove lock on a specific Collection so - * that is might be opened again. - */ - public class CloseCollectionViewHandler implements CloseClickHandler { - protected FLYS flys; - protected String uuid; - - public CloseCollectionViewHandler(FLYS flys, String uuid) { - this.flys = flys; - this.uuid = uuid; - } - - @Override - public void onCloseClick(CloseClickEvent event) { - flys.closeProject(uuid); - } - } - - public boolean isProjectListVisible() { - if (this.projectList == null) { - return true; - } - return this.projectList.isVisible(); - } - - public void hideProjectList() { - if (this.projectList != null) { - this.projectList.hide(); - } - } - - public void openProjectList() { - if (this.projectList != null) { - this.projectList.show(); - } - } - - public void hideHeaderProjectButton() { - this.header.hideProjectButton(); - } - - public void shoHeaderProjectButton() { - this.header.showProjectButton(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1268 +0,0 @@ -package de.intevation.flys.client.client; - -import com.google.gwt.i18n.client.ConstantsWithLookup; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface FLYSConstants extends ConstantsWithLookup { - - String static_sqrelation(); - - String add(); - - String unexpected_exception(); - - String title(); - - String fullname(); - - String user(); - - String guest(); - - String projects(); - - String open_project(); - - String delete_project(); - - String rename_project(); - - String clone_project(); - - String copy_of (); - - String manage_projects(); - - String favorite_tooltip(); - - String favorite_tooltip_meaning(); - - String projectlist_creationTime(); - - String projectlist_title(); - - String projectlist_favorite(); - - String really_delete(); - - String project_name_too_long(); - - String logout(); - - String switch_language(); - - String info(); - - String warning(); - - String warning_language(); - - String warning_no_wsp_selected(); - - String warning_cannot_parse_date(); - - String no_projects(); - - String load_projects(); - - String empty_table(); - - String empty_filter(); - - String date_format(); - - String datetime_format(); - - String new_project(); - - String new_calculation(); - - String module_selection(); - - String river_selection(); - - String winfo(); - - String minfo(); - - String map(); - - String new_map(); - - String new_chart(); - - String diagram(); - - String axes(); - - String legend(); - - String chart_title(); - - String chart_subtitle(); - - String grid(); - - String antialiasing(); - - String axis_name(); - - String chart_start(); - - String chart_end(); - - String x_axis(); - - String y1_axis(); - - String y2_axis(); - - String y3_axis(); - - String legend_name(); - - String show_legend(); - - String aggregation_threshold(); - - String scale(); - - String databasket(); - - String databasket_loading(); - - String theme_top(); - - String theme_up(); - - String theme_down(); - - String theme_bottom(); - - String zoom_all(); - - String zoom_in(); - - String zoom_out(); - - String zoom_back(); - - String properties_ico(); - - String pan(); - - String askThemeRemove(); - - String fix(); - - String fixanalysis(); - - String next(); - - String river_km(); - - String uesk_profile_distance(); - - String location_distance_state(); - - String distance_state(); - - String waterlevel_ground_state(); - - String location(); - - String locations(); - - String single_location(); - - String distance(); - - String unitFrom(); - - String unitTo(); - - String dpLabelFrom(); - - String dpUnitFrom(); - - String dpLabelTo(); - - String dpUnitTo(); - - String dpLabelStep(); - - String dpUnitStep(); - - String wgLabelFrom(); - - String wgUnitFrom(); - - String wgLabelTo(); - - String wgUnitTo(); - - String wgLabelStep(); - - String wgUnitStep(); - - String unitWidth(); - - String unitFromInM(); - - String unitToInM(); - - String unitDiffInM(); - - String unitLocation(); - - String wrongFormat(); - - String atLeastOneValue(); - - String missingInput(); - - String too_many_values (); - - String from(); - - String to(); - - String riverside(); - - String calcTableTitle(); - - String helperPanelTitle(); - - String gaugePanelTitle(); - - String measurementStationPanelTitle(); - - String wqTitle(); - - String wqadaptedTitle(); - - String wqHistorical(); - - String unitWNN(); - - String wqWFree(); - - String wqW(); - - String wqQ(); - - String wqQatGauge(); - - String wqQGauge(); - - String wqSingle(); - - String wqRange(); - - String unitWSingle(); - - String unitWFrom(); - - String unitWTo(); - - String unitWStep(); - - String unitQSingle(); - - String unitQFrom(); - - String unitQTo(); - - String unitQStep(); - - String main_channel(); - - String total_channel(); - - String footerHome(); - - String footerContact(); - - String footerImpressum(); - - String projectListMin(); - - String projectListAdd(); - - String buttonNext(); - - String imageBack(); - - String imageSave(); - - String search(); - - String properties(); - - String activateTheme(); - - String deactivateTheme(); - - String removeTheme(); - - String manageThemes(); - - String label_ok(); - - String label_cancel(); - - String cancelCalculationLabel(); - - String calculationCanceled(); - - String flysLogo(); - - String bfgLogo(); - - String bfgLogoSmall(); - - String downloadPNG(); - - String downloadPDF(); - - String downloadSVG(); - - String downloadCSV(); - - String downloadAT(); - - String downloadWST(); - - String loadingImg(); - - String cancelCalculation(); - - String markerRed(); - - String markerGreen(); - - String riverMap(); - - String range(); - - String description(); - - String resultCount(); - - String start_year(); - - String end_year(); - - String period(); - - String gauge_class(); - - String eventselect(); - - String events(); - - String kmchart(); - - String addPointsTooltip(); - - String addWSPTooltip(); - - String downloadPNGTooltip(); - - String downloadPDFTooltip(); - - String downloadSVGTooltip(); - - String downloadCSVTooltip(); - - String zoomToMaxExtentTooltip(); - - String zoomOutTooltip(); - - String historyBackTooltip(); - - String panControlTooltip(); - - String zoomboxTooltip(); - - String chartPropertiesTooltip(); - - String year(); - - String sedimentload_ls(); - - // Gauges - - String gauge_mnq(); - - String gauge_mq(); - - String gauge_mhq(); - - String gauge_hq5(); - - // Elevation window - - String ele_window_title(); - - String ele_window_label(); - - String ele_window_x_col(); - - String ele_window_y_col(); - - String ele_window_z_col(); - - String ele_window_ok_button(); - - String ele_window_cancel_button(); - - String ele_window_format_error(); - - String ele_window_save_error(); - - String ele_window_geometry_error(); - - // OUTPUT TYPES - - String discharge_curve_gaugeless(); - - String discharge_curve(); - - String gauge_discharge_curve(); - - String computed_discharge_curve(); - - String computed_discharge_curves(); - - String longitudinal_section(); - - String duration_curve(); - - String reference_curve(); - - String reference_curve_normalized(); - - String reference_endpoint(); - - String reference_startpoint(); - - String name(); - - String type(); - - String wq_table_w(); - - String wq_waterlevel_label(); - - String wq_table_q(); - - String wq_value_w(); - - String wq_value_q(); - - String discharge_longitudinal_section(); - - String floodmap(); - - String cross_section(); - - String cross_sections(); - - String w_differences(); - - String historical_discharge(); - - String historical_discharge_wq(); - - String extreme_wq_curve(); - - String showextramark(); - - String fix_wq_curve(); - - String fix_deltawt_curve(); - - String fix_longitudinal_section_curve(); - - String fix_derivate_curve(); - - String fix_vollmer_wq_curve(); - - // EXPORTS - - String waterlevel_export(); - - String waterlevel_report(); - - String computed_dischargecurve_at_export(); - - String discharge_longitudinal_section_export(); - - String discharge_longitudinal_section_report(); - - String computed_dischargecurve_export(); - - String computed_dischargecurve_report(); - - String durationcurve_export(); - - String durationcurve_report(); - - String dataexport(); - - String reference_curve_export(); - - String w_differences_export(); - - String historical_discharge_export(); - - String csv(); - - String wst(); - - String at(); - - String pdf(); - - String chart_themepanel_header_themes(); - - String chart_themepanel_header_actions(); - - String chart_themepanel_synchron(); - - String chart_themepanel_asynchron(); - - String chart_themepanel_set_master(); - - String chart_themepanel_new_area(); - - String chart_themepanel_area_under(); - - String chart_themepanel_area_over(); - - String chart_themepanel_area_between(); - - String against_x_axis(); - - String discharge(); - - String flow_velocity(); - - String flow_velocity_export(); - - String bedheight_middle(); - - String bedheight_middle_export(); - - String bed_longitudinal_section(); - - String bed_longitudinal_section_export(); - - String sq_relation_a(); - - String sq_relation_b(); - - String sq_relation_c(); - - String sq_relation_d(); - - String sq_relation_e(); - - String sq_relation_f(); - - String sq_relation_export(); - - String exportATTooltip(); - - String load_diameter(); - - String bed_diameter(); - - String soundings(); - - String soundings_width(); - - String bed_difference_year(); - - String bed_difference_epoch(); - - String bed_difference_height_year(); - - // ERRORS - - String error_years_wrong(); - - String error_read_minmax_values(); - - String error_validate_range(); - - String error_validate_date_range(); - - String error_validate_date_range_invalid(); - - String error_validate_lower_range(); - - String error_validate_upper_range(); - - String error_create_artifact(); - - String error_describe_artifact(); - - String error_feed_data(); - - String error_advance_artifact(); - - String error_add_artifact(); - - String error_remove_artifact(); - - String error_create_collection(); - - String error_describe_collection(); - - String error_no_rivers_found(); - - String error_no_gaugeoverviewinfo_found(); - - String error_no_such_user(); - - String error_no_users(); - - String error_no_waterlevel_pair_selected(); - - String error_same_waterlevels_in_pair(); - - String error_not_logged_in(); - - String error_load_parameterization(); - - String error_feed_no_data(); - - String error_feed_from_out_of_range(); - - String error_feed_to_out_of_range(); - - String error_feed_from_bigger_to(); - - String error_feed_invalid_wq_mode(); - - String error_feed_number_format_float(); - - String error_feed_invalid_calculation_mode(); - - String error_feed_no_calculation_mode(); - - String error_feed_no_such_river(); - - String error_feed_no_river_selected(); - - String error_feed_no_wq_mode_selected(); - - String error_feed_q_values_invalid(); - - String error_feed_w_values_invalid(); - - String error_no_meta_data_found(); - - String error_chart_info_service(); - - String error_invalid_double_value(); - - String error_load_artifact(); - - String error_no_calc_result(); - - String error_no_theme_styles_found(); - - String error_no_feature_selected(); - - String error_no_map_config(); - - String error_no_map_output_type(); - - String error_no_module_found(); - - String warning_use_first_feature(); - - String warning_select_two_values(); - - String error_no_valid_gfi_url(); - - String error_gfi_req_failed(); - - String error_gfi_parsing_failed(); - - String error_gc_req_failed(); - - String error_gc_doc_not_valid(); - - String error_malformed_url(); - - String error_no_dgm_selected(); - - String error_invalid_dgm_selected(); - - String error_bad_dgm_range(); - - String error_bad_dgm_river(); - - String error_dialog_not_valid(); - - String error_invalid_date(); - - String error_wrong_date(); - - String bottom_edge(); - - String top_edge(); - - String error_same_location(); - - String error_contains_same_location(); - - String error_update_collection_attribute(); - - String error_values_needed(); - - // MAP RELATED STRINGS - - String digitize(); - - String pipe1(); - - String pipe2(); - - String ditch(); - - String dam(); - - String ring_dike(); - - String selectFeature(); - - String removeFeature(); - - String getFeatureInfo(); - - String getFeatureInfoTooltip(); - - String getFeatureInfoWindowTitle(); - - String addWMS(); - - String printMapSettings(); - - String addWMSTooltip(); - - String adjustElevation(); - - String adjustElevationTooltip(); - - String measureLine(); - - String measurePolygon(); - - String step(); - - String calculationStarted(); - - String zoomMaxExtent(); - - String zoomIn(); - - String zoomOut(); - - String zoomLayer(); - - String moveMap(); - - String digitizeObjects(); - - String selectObject(); - - String removeObject(); - - String measureDistance(); - - String measureArea(); - - String map_themepanel_header_style(); - - String zoomToLayer(); - - String requireDGM(); - - String upload_file(); - - String shape_file_upload(); - - // data cage - - String waterlevels(); - - String old_calculations(); - - String officiallines(); - - String datacageAdd(); - - String fixations(); - - String flood_protections(); - - String columns(); - - String basedata(); - - String heightmarks(); - - String annotation(); - - String annotations(); - - String all_annotations(); - - String flowvelocitymeasurement(); - - String bed_quality_bed(); - - String bed_quality_load(); - - String additionals(); - - String differences(); - - String kilometrage(); - - String riveraxis(); - - String km(); - - String qps(); - - String hws(); - - String catchments(); - - String catchment_wms(); - - String floodplain(); - - String lines(); - - String buildings(); - - String fixpoints(); - - String uesk(); - - String calculations(); - - String current(); - - String bfg(); - - String land(); - - String potential(); - - String rastermap(); - - String background(); - - String discharge_tables_chart(); - - String discharge_table_nn(); - - String discharge_table_gauge(); - - String mainvalue(); - - String mainvalues(); - - String wmainvalue(); - - String qmainvalue(); - - String show_mainvalues(); - - String dems(); - - String hydrboundaries(); - - String gaugelocations(); - - String single(); - - String epoch(); - - String bedheights(); - - String morph_width(); - - String datacage(); - - String datacage_add_pair(); - - // Capabilities Information Panel - - String addwmsInputTitle(); - - String addwmsInfoTitle(); - - String addwmsLayerTitle(); - - String addwmsBack(); - - String addwmsContinue(); - - String addwmsCancel(); - - String addwmsInvalidURL(); - - String capabilitiesHint(); - - String capabilitiesTitle(); - - String capabilitiesURL(); - - String capabilitiesAccessConstraints(); - - String capabilitiesFees(); - - String capabilitiesContactInformation(); - - String capabilitiesEmail(); - - String capabilitiesPhone(); - - String chart(); - - String export(); - - String width(); - - String height(); - - String visibility(); - - String upper(); - - String lower(); - - String fixation(); - - String font_size(); - - String label(); - - String subtitle(); - - String display_grid(); - - String display_logo(); - - String logo_placeh(); - - String logo_placev(); - - String top(); - - String bottom(); - - String center(); - - String left(); - - String right(); - - String none(); - - String notselected(); - - String linetype(); - - String textstyle(); - - String linecolor(); - - String showhorizontalline(); - - String showverticalline(); - - String horizontal(); - - String vertical(); - - String textcolor(); - - String textsize(); - - String font(); - - String showborder(); - - String showpoints(); - - String showbackground(); - - String textshowbg(); - - String backgroundcolor(); - - String bandwidthcolor(); - - String textbgcolor(); - - String textorientation(); - - String linesize(); - - String pointsize(); - - String bandwidth(); - - String pointcolor(); - - String showlines(); - - String showlinelabel(); - - String showpointlabel(); - - String labelfontsize(); - - String labelfontcolor(); - - String labelfontface(); - - String labelfontstyle(); - - String labelbgcolor(); - - String labelshowbg(); - - String showwidth(); - - String showlevel(); - - String showminimum(); - - String showmaximum(); - - String transparent(); - - String transparency(); - - String showarea(); - - String showarealabel(); - - String showmiddleheight(); - - String fillcolor(); - - String wsplgen_cat1(); - - String wsplgen_cat2(); - - String wsplgen_cat3(); - - String wsplgen_cat4(); - - String wsplgen_cat5(); - - String areabgcolor(); - - String areashowborder(); - - String areashowbg(); - - String areabordercolor(); - - String areatransparency(); - - String attribution(); - - // Manual Points editor - - String addpoints(); - - String pointname(); - - String removepoint(); - - String newpoint(); - - String standby(); - - String points(); - - String editpoints(); - - // Manual WaterLine (WSP) Editor. - - String addWSPButton(); - - String addWSP(); - - String selection(); - - String fix_deltawt_export(); - - String select(); - - String add_date(); - - String fix_parameters_export(); - - String fix_parameters(); - - String sq_overview(); - - // Gauge Overview Info - - String gauge_zero(); - - String gauge_q_unit(); - - String gauge_info_link(); - - String gauge_river_info_link(); - - String gauge_river_url(); - - String gauge_url(); - - String gauge_curve_link(); - - String gauge_discharge_curve_at_export(); - - // Measurement Station Info - - String measurement_station_type(); - - String measurement_station_operator(); - - String measurement_station_start_time(); - - String measurement_station_url(); - - String measurement_station_info_link(); - - String measurement_station_gauge_name(); - - String discharge_timeranges(); - - String discharge_chart(); - - String projectlist_close(); - - String startcolor(); - - String endcolor(); - - String numclasses(); - - String welcome(); - - String welcome_open_or_create(); - - String official(); - - String inofficial(); - - String custom_lines(); - - String hws_lines(); - - String hws_points(); - - String hws_fed_unknown(); - - String jetties(); - - String route_data(); - - String other(); - - String axis(); - - String bfg_model(); - - String federal(); - - String areas(); - - String sobek_areas(); - - String sobek_flooded(); - - String measurements(); - - String floodmarks(); - - String pegel_had_measurement_points(); - - String gauge_points(); - - String gauge_names(); - - String gauge_level(); - - String gauge_tendency(); - - String printTooltip(); - - String print(); - - String printWindowTitle(); - - String mapfish_data_range(); - - String mapfish_data_subtitle(); - - String mapfish_data_strech(); - - String mapfish_data_institution(); - - String mapfish_data_source(); - - String mapfish_data_creator(); - - String mapfish_data_dateplace(); - - String mapfish_data_river(); - - String mapTitle(); - - String mapSubtitle(); - - String mapRange(); - - String mapStretch(); - - String mapCreator(); - - String mapInstitution(); - - String mapSource(); - - String mapDate(); - - String mapLogo(); - - String wmsURLMenuItem(); - - String wmsURLBoxTitle(); - - String requireTheme(); - - String PATH(); - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,668 +0,0 @@ -fullname = Flusshydrologische Software -user = User: -guest = guest -logout = Logout -projects = Projects -open_project = Open Project -delete_project = Delete Project -rename_project = Rename Project -clone_project = Clone Project -copy_of = Copy -manage_projects = Manage Projects -favorite_tooltip = Permanently store? -favorite_tooltip_meaning = Golden star: stored -projectlist_creationTime = Creation time -projectlist_title = Title -projectlist_favorite = Permanent -projectlist_close = Close -really_delete = Do you really want to delete this project? -project_name_too_long = The entered project name is too long. Max length is $LEN characters. -switch_language = German -info = Info -warning = Attention -warning_language = Choosing a new language starts a new session. All open windows will be closed. -no_projects = No existing calculations found. -load_projects = Load calculations... -empty_table = Loading data... -empty_filter = No data found. -date_format = yyyy-MM-dd -datetime_format = yyyy-MM-dd HH:mm -new_project = New Project -new_calculation = New Calculation -module_selection = Module -river_selection = Rivers -winfo = W-INFO -minfo = M-INFO -new_map = New Map -map = Map -new_chart = New Chart -diagram = Chart -axes = Axes -legend = Legend -chart_title = Title -chart_subtitle = Subtitle -grid = Grid -antialiasing = Antialiasing -axis_name = Name -chart_start = start -chart_end = end -x_axis = X-Axis -y1_axis = Y1-Axis -y2_axis = Y2-Axis -y3_axis = Y3-Axis -legend_name = Name -show_legend = Show -aggregation_threshold = Threshold for aggregation of legend entries -scale = Scale -databasket = Databasket -databasket_loading = Loading Databasket content -fix = Fixing -fixanalysis = Fixing Analysis -next = Next -location_distance_state = Choose calculation location(s) / range [km] -distance_state = Choose calculation range [km] -waterlevel_ground_state = Choose differences betweeen waterlevel and ground [m] -location = Location(s) -locations = Locations -single_location = Location -distance = Range -unitFrom = km -unitTo = km a -unitWidth = m -search = Search -discharge = Discharge Name -properties = Properties -activateTheme = Activate -deactivateTheme = Deactivate -removeTheme = Remove -manageThemes = Manage themes -label_ok = Ok -label_cancel = Cancel -cancelCalculationLabel = Stop the current calculation. -calculationCanceled = The calculation has been canceled. -range = Range -resultCount = Hits -start_year = Start -end_year = End -period = Period -year = Year -sedimentload_ls = Sediment Load -welcome = Welcome to Flusshydrologische Software -welcome_open_or_create = Please open a project from the project list or create a -# Header images -flysLogo = images/flys_logo.gif -bfgLogo = images/bfg_logo.gif -bfgLogoSmall = images/bfg_logo_small.png - -# Images -downloadPNG = images/png_export.png -downloadPDF = images/pdf_export.png -downloadSVG = images/svg_export.png -downloadCSV = images/save_csv.png -downloadAT = images/save_at.png -downloadWST = images/save_wst.png -loadingImg = images/loading.gif -loadingImg = images/loading.gif -cancelCalculation = images/cancelCalculation.png -markerRed = images/marker_red.png -markerGreen = images/marker_green.png -riverMap = images/FLYS_Karte.png -properties_ico = images/properties.png - -dpLabelFrom = from -dpUnitFrom = km -dpLabelTo = to -dpUnitTo = km -dpLabelStep = a -dpUnitStep = m - -wgLabelFrom = From -wgUnitFrom = m -wgLabelTo = To -wgUnitTo = m -wgLabelStep = a -wgUnitStep = m - -unitFromInM = From [m]: -unitToInM = To [m]: -unitDiffInM = Diff [m]: -unitLocation = km -wrongFormat = Wrong format -atLeastOneValue = You need to insert at least one value. -missingInput = You need to enter a value. -too_many_values = Only one value allowed - -addPointsTooltip = Add manual points -addWSPTooltip = Add manual LS -downloadPNGTooltip = Download chart as PNG -downloadPDFTooltip = Download chart as PDF -downloadSVGTooltip = Download chart as SVG -downloadCSVTooltip = Download data as CSV -zoomToMaxExtentTooltip = Zoom to max extent -zoomOutTooltip = Zoom out -historyBackTooltip = Previous zoom -panControlTooltip = Pan -zoomboxTooltip = Zoombox -chartPropertiesTooltip = Chartproperties -printTooltip = Print - -description = Description -from = From -to = To -riverside = Riverside -bottom_edge = Bottom edge -top_edge = Top edge -name = Name -type = Type -wq_table_w = Characteristic Waterlevels -wq_waterlevel_label = Characteristic Waterlevel -wq_table_q = Characteristic Discharges / Durations -wq_value_w = W [cm at Gauge] -wq_value_q = Q [m\u00b3/s] -river_km = River-Km -uesk_profile_distance = Distance [m] - -wqTitle = Input for W/Q Data -wqadaptedTitle = Input for W/Q Data -wqHistorical = Selection of Analyse Type -calcTableTitle = Values -helperPanelTitle = Input Support -gaugePanelTitle = Gauge Information -measurementStationPanelTitle = Measurement Station Information -wqW = W at Gauge [cm] -wqQ = Q [m\u00b3/s] -wqQatGauge = Q at Gauge [m\u00b3/s] -wqWFree = W free position [m+NHN] -wqQGauge = Discharge at Gauge -wqSingle = Single values -wqRange = Range -unitWNN = W [NN+m] -unitWSingle = cm -unitWFrom = cm - -unitWTo = cm a -unitWStep = cm -unitQSingle = m³/s -unitQFrom = m³/s - -unitQTo = m³/s a -unitQStep = m³/s -main_channel = Main Channel -total_channel = Total Channel -footerHome = Home -footerContact = Contact -footerImpressum = Legal info -print = Print -printWindowTitle = PDF-Print Settings - -projectListMin = format-indent-less.png -projectListAdd = list-add.png -buttonNext = Next -imageBack = images/back_en.png -imageSave = images/save.png -theme_top = images/go-first.png -theme_up = images/go-up.png -theme_down = images/go-down.png -theme_bottom = images/go-bottom.png -zoom_all = images/mag_100.png -zoom_in = images/mag_zoom_box.png -zoom_out = images/mag_zoom_minus.png -zoom_back = images/mag_zoom_back.png -pan = images/hand.png -askThemeRemove = Are you sure that you want to remove the selected theme / themes? -add = Add - -static_sqrelation = SQ relation -discharge_curve = Discharge Curve at Gauge -discharge_curve_gaugeless = Discharge Curve -gauge_discharge_curve = Discharge Table at Gauge -computed_discharge_curve = Discharge Curve -computed_discharge_curves = Discharge Curves -longitudinal_section = Longitudinal Section Curve -duration_curve = Duration Curve -discharge_longitudinal_section = Discharge Longitudinal Section -floodmap = Floodmap -historical_discharge = Time-Chart -historical_discharge_wq = W/Q-Chart -flow_velocity = Flow Velocity -flow_velocity_export = Flow Velocity Export -bedheight_middle = Middle Bed Height -bedheight_middle_export = Middle Bed Height Export -bed_longitudinal_section = Bed Quality -bed_longitudinal_section_export = Bed Quality Export -sq_relation_a = A Feinkornanteil -sq_relation_b = B Sand (Suspensionstransport) -sq_relation_c = C Sand (Geschiebetransport) -sq_relation_d = D Fein- und Mittelkies -sq_relation_e = E Grobkornanteil (> Mittelkies) -sq_relation_f = F Geschiebetransport Gesamt -sq_relation_export = SQ Export -cross_section = Cross Section -cross_sections = Cross Sections -w_differences = Differences -w_differences_export = Differences Export -reference_curve_export = Reference Curve Export -historical_discharge_export = Historical Discharge Curve Export -showextramark = Show begin of extrapolation -extreme_wq_curve = W/Q -fix_wq_curve = W/Q-Diagram -fix_deltawt_curve = \u0394 W/t -fix_longitudinal_section_curve = Longitudinal Section -fix_derivate_curve = Derivate -fix_vollmer_wq_curve = W/Q-Diagram -datacage_add_pair = Add difference pair -load_diameter = Bedload Diameter -bed_diameter = Bed Diameter -soundings = Soundings -soundings_width = Soundings Width -bed_difference_year = Single Bedheight Differences -bed_difference_epoch = Epoch Bedheight Differences -bed_difference_height_year = Bedheight Differences per year - -exportATTooltip = Export as AT file - -waterlevel_export = Waterlevel Export -waterlevel_report = Waterlevel Report -computed_dischargecurve_export = Discharge Curve Export -computed_dischargecurve_report = Discharge Curve Report -discharge_longitudinal_section_export = Discharge Longitudinal Section Export -discharge_longitudinal_section_report = Discharge Longitudinal Section Report -durationcurve_export = Duration Curve Export -durationcurve_report = Duration Curve Report -dataexport = Data export -csv = CSV -wst = WST -at = AT -pdf = PDF -computed_dischargecurve_at_export = AT Export -gauge_discharge_curve_at_export = Gauge Discharge Curve -gauge_class = Gauge Class -eventselect = Eventselection -events = Events -kmchart = W/Q-Preview - -chart_themepanel_header_themes = Theme -chart_themepanel_header_actions = Actions -chart_themepanel_synchron = Navigate synchronously -chart_themepanel_asynchron = Navigate independently -chart_themepanel_set_master = Reference -chart_themepanel_new_area = New Area... -chart_themepanel_area_under = under ... -chart_themepanel_area_over = over ... -chart_themepanel_area_between = between ... -against_x_axis = Over X-Axis - -gauge_mnq = around MNQ -gauge_mq = around MQ -gauge_mhq = around MHQ -gauge_hq5 = above HQ5 - -ele_window_title = Elevation Node -ele_window_label = Elevation settings in m \u00fc. NN. -ele_window_x_col = X -ele_window_y_col = Y -ele_window_z_col = Z-Coordinate -ele_window_ok_button = Set elevations -ele_window_cancel_button = Cancel -ele_window_format_error = The elevation you have entered is invalid: -ele_window_save_error = Error while saving elevations. -ele_window_geometry_error = The geometry is not supported: - -unexpected_exception = There occured an unexpected exception -error_years_wrong = The second year needs to be bigger than the first year. -error_read_minmax_values = Error while reading min/max values for the location input. -error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2. -error_validate_date_range = Start date needs to be before end date. -error_validate_date_range_invalid = The specified timerange is invalid. -error_validate_lower_range = The lower value $1 needs to be bigger than $2. -error_validate_upper_range = The upper value $1 needs to be smaller than $2. -error_empty_state = Required inputs are missing. -error_invalid_double_value = Wrong format for a floating point number. -error_create_artifact = Error while creating new project. -error_describe_artifact = Error while loading the parameterization. -error_feed_data = Error while inserting new data. -error_advance_artifact = Error while changing the project's state. -error_add_artifact = Error while inserting new data. -error_remove_artifact = Error while removing data. -error_create_collection = Error while creating a new collection. -error_describe_collection = Error while fetching the projects state. -error_no_rivers_found = Error while reading supported rivers. -error_no_such_user = Error - no such user found. -error_no_users = Error - no users found. -error_no_waterlevel_pair_selected = Error - no waterlevel pair for building differences selected. -error_same_waterlevels_in_pair = Error - minuend and subtrahend have to differ. -error_not_logged_in = You need to log in before you are allowed to start your work. -error_load_parameterization = Could not load the parameterization. -error_wrong_date = Please enter valid dates. -error_no_gaugeoverviewinfo_found = Error while fetching the river and gauge info - -error_feed_no_data = No input data found. -error_feed_from_out_of_range = The lower value is bigger than the upper value. -error_feed_to_out_of_range = The upper value is out or the valid range. -error_feed_from_bigger_to = The lower value is bigger than the upper value. -error_feed_invalid_wq_mode = Invalid WQ-Mode selected. -error_feed_number_format_float = The inserted value is no floating point number. -error_feed_invalid_calculation_mode = The chosen calculation method is invalid. -error_feed_no_calculation_mode = No calculation method chosen. -error_feed_no_such_river = The selected river is not provided. -error_feed_no_river_selected = No river selected. -error_feed_no_wq_mode_selected = No W/Q mode selected. -error_feed_q_values_invalid = Selected Q values are outside the valid range. -error_feed_w_values_invalid = Selected W values are outside the valid range. -error_chart_info_service = Could not fetch meta information of the chart. -error_no_meta_data_found = No meta data found. -error_load_artifact = Error while adding data to the current project. -error_no_calc_result=No calculation results found. -error_no_theme_styles_found=No style for the selected theme found. -error_no_feature_selected = No object selected. -error_no_map_config = No Map configuration found. -error_no_map_output_type = No Map output found. -error_no_valid_gfi_url = No valid GetFeatureInfo response found. -error_gfi_req_failed = GetFeatureInfo request failed. -error_gfi_parsing_failed = Failed to read GetFeatureInfo response. -error_gc_req_failed = Error while loading Capabilities document. -error_gc_doc_not_valid = Capabilities document is not valid. -error_malformed_url = The URL you have entered is not valid. -error_no_dgm_selected = No DEM selected. -error_invalid_dgm_selected = You have selected an invalid DEM. -error_bad_dgm_range = You have selected a DEM with an invalid range. -error_bad_dgm_river = You have selected a DEM for a wrong river. -error_dialog_not_valid = One or more values are not valid. -error_invalid_date = The entered date is not valid. -error_same_location = Reference location equals selected location. -error_contains_same_location = Target locations contains reference location. -error_update_collection_attribute = Error while updating the collection attribut -error_values_needed = You must provide values. -error_no_module_found = No modules found - -warning_use_first_feature = You have more that one object selected. The first one is used. -warning_no_wsp_selected = No waterlevel selected! -warning_cannot_parse_date = Invalid date! -warning_select_two_values = Please select two values! - -## map related strings -digitize = images/digitize.png -pipe1 = Pipe1 -pipe2 = Pipe12 -ditch = Ditch -dam = Dam -ring_dike = Ringdike -selectFeature = images/selectFeature.png -removeFeature = images/removeFeature.png -getFeatureInfo = images/info.png -getFeatureInfoTooltip = Information Tool -getFeatureInfoWindowTitle = Information for Map Layer: -addWMS = images/add_map.png -printMapSettings = images/print_map_settings.png -addWMSTooltip = Load layers from external WMS service. -adjustElevation = images/adjustElevation.png -measureLine = images/measure_line.png -measurePolygon = images/measure_plane.png -step = Step -calculationStarted = Calculation started. -zoomMaxExtent = Max extent -zoomIn = Zoom in -zoomOut = Zoom out -zoomLayer = Zoom to layer -moveMap = Move -digitizeObjects = Creation of pipes, ditches, dams and ringdikes -selectObject = Select tool -removeObject = Remove selected object -adjustElevationTooltip = Define elevations for barriers -measureDistance = Measure line -measureArea = Measure area -map_themepanel_header_style = Style -zoomToLayer = Layer-Zoom -requireDGM = You need to choose a DEM. -upload_file = upload -shape_file_upload = Upload shapefile - -# data cage -waterlevels = Waterlevels -old_calculations = Former Calculations -officiallines = Official lines -datacageAdd = Add data -heightmarks = Height Marks -basedata = Base Data -fixations = Fixations -flood_protections = Flood Protections -columns = Columns -annotation = Annotations -annotations = Annotations -all_annotations = All annotations -flowvelocitymeasurement = Flowvelocity measurements -bed_quality_bed = Quality - Bed -bed_quality_load = Quality - Load -additionals = Additional Longitudinal Section Curves -differences = Differences -kilometrage = Kilometrage -riveraxis = Riveraxis -km = Km -qps = Crosssection Tracks -hws = Floodplain Protection Work -catchments = Catchments -catchment_wms = Catchments (WMS) -floodplain = Floodplain -lines = Lines -buildings = Buildings -fixpoints = Fixpoints -uesk = Floodmaps -calculations = Calculations -current = Current -potential = Potential -bfg = BfG -land = Land -rastermap = Rastermap -background = Background Map -discharge_tables_chart = W/Q-Preview -discharge_table_nn = Discharge Tables at Gauge -discharge_table_gauge = Discharge Table at Gauge -mainvalue = Mainvalue -mainvalues = Mainvalues -wmainvalue = Mainvalues (W) -qmainvalue = Mainvalues (Q) -show_mainvalues = Show Mainvalues -dems = Digital Elevation Models -hydrboundaries = Hydrological Boundaries -gaugelocations = Location of Gauges -single = Year -epoch = Epoch -bedheights = Bedheights -morph_width = morphologic Width -datacage = Datacage -official = Offical -inofficial = Inofficiall -custom_lines = Own Digitalizations -hws_lines = Lines -hws_points = Points -hws_fed_unknown = Unknown State -jetties = Jetties -route_data = Route Data -other = Other -axis = Axis -bfg_model = BfG-Model -federal = Federal States -areas = Areas -sobek_flooded = SOBEK-Boundary flooded / not flooded -sobek_areas = SOBEK-Areas -measurements = Measurements -floodmarks = Flood Marks -pegel_had_measurement_points = HAD Discharge-Measurement points -# No translation for the pegelonline wms service layer names. -gauge_points = Pegelpunkte (WSV) -gauge_level = Aktueller Wasserstand (WSV) -gauge_names = Pegelnamen (WSV) -gauge_tendency = Tendenz des Wasserstands (WSV) - -startcolor = Colorrange start color -endcolor = Colorrange end color -numclasses = Number of classes - -# capabilities information panel -addwmsInputTitle = Base URL of WMS service -addwmsInfoTitle = Information about WMS service -addwmsLayerTitle = Choose Layer -addwmsBack = Back -addwmsContinue = Continue -addwmsCancel = Cancel -addwmsInvalidURL = The URL is not valid. -capabilitiesHint = Please notice the information of the WMS service. -capabilitiesTitle = Title -capabilitiesURL = URL -capabilitiesAccessConstraints = Access Constraints -capabilitiesFees = Fees -capabilitiesContactInformation = Further Information -capabilitiesEmail = Email -capabilitiesPhone = Phone - -#Properties dialog -chart = Chart -export = Export -width = Width -height = Height -visibility = Visibility -upper = to -lower = from -fixation = Fix -font_size = Fontsize -label = Title -title = Title -subtitle = Subtitle -display_grid = Display grid -display_logo = Display logo -logo_placeh = Horiz. Place for logo -logo_placev = Vertic. Place for logo -top = top -bottom = bottom -center = center -left = left -right = right -none = none - -notselected = none - -linetype = Linetype -textstyle = Textstyle -linecolor = Linecolor -showhorizontalline = Show horizonal line -showverticalline = Show vertical line -textcolor = Textcolor -textsize = Textsize -font = Font -showpoints = Show points -showbackground = Show background -textshowbg = Show background -backgroundcolor = Backgroundcolor -bandwidthcolor = Bandwidthcolor -textbgcolor = Backgroundcolor -textorientation = Textorientation -linesize = Linesize -pointsize = Pointsize -bandwidth = Bandwidth -pointcolor = Punktfarbe -showlines = Show lines -showlinelabel = Show line label -showpointlabel = Show point label -labelfontface = Label: Font -labelfontcolor = Label: Color -labelfontsize = Label: Size -labelfontstyle = Label: Style -labelbgcolor = Label: Background Color -labelshowbg = Label: Show Background -horizontal = horizontal -vertical = vertical -showwidth = Show width -showlevel = Show waterlevel -showminimum = Show minimum -showmaximum = Show maximum -showborder = Show line -transparent = Transparency -transparency = Transparency -showarea = Show area -showarealabel = Show area label -showmiddleheight = Show middle depth -fillcolor = Fill Color -areabgcolor = Fill Color -areashowborder = Show area border -areashowbg = Show area background -areabordercolor = Border color -areatransparency = Tranparency -wsplgen_cat1 = Fill Color 0.0 <= DIFF < 1 -wsplgen_cat2 = Fill Color 1.0 <= DIFF < 2 -wsplgen_cat3 = Fill Color 2.0 <= DIFF < 3 -wsplgen_cat4 = Fill Color 3.0 <= DIFF < 4 -wsplgen_cat5 = Fill Color 4.0 <= DIFF -attribution = ©Intevation GmbH 2013<br>Data ©<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> -wmsURLMenuItem = WMS URL -wmsURLBoxTitle = Layer WMS URL -requireTheme = You need to choose a Layer. - -# Manual Points Editor -addpoints = Add points -pointname = Name -removepoint = Remove -newpoint = New Point -standby = Creating Artifact ... please wait. -points = Points -editpoints = Edit Points -addWSPButton = Add Manual LS -addWSP = Add Manual LS -selection = Selection - -# Reference Curves -reference_curve = Reference Curve -reference_curve_normalized = Reduced Reference Curve -reference_startpoint = Point of reference -reference_endpoint = Point(s) of projection - -fix_deltawt_export = \u0394 W/t -select=Selected -add_date=Add - -fix_parameters_export = Adjusted coefficient -fix_parameters = CSV - -sq_overview=Overview - -gauge_zero = GZG -gauge_q_unit = m\u00b3/s -gauge_river_info_link = Riverinfo -gauge_info_link = Gaugeinfo -gauge_url = https://flys-intern.intevation.de/PegelInfo/ -gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ -gauge_curve_link = Dischargecurve/-table -discharge_timeranges = DC-Timeranges -discharge_chart = W/Q-Preview - -measurement_station_type = Type of Measurement Station -measurement_station_operator = Operator -measurement_station_start_time = Observation Start Time -measurement_station_url = https://flys-intern.intevation.de/MessstellenInfo/ -measurement_station_info_link = Measurement Station Info -measurement_station_gauge_name = Reference Gauge - -# The prefix is used to classify them and will be stripped -# If the payload part sarts with a number it will be sorted -# By this number and the number will be stripped. -# Number must be a single digit 0-9. This hack was made necessary -# by the usage of an attribute table in mapfish - -mapfish_data_range = mapfish_data_3Range -mapfish_data_subtitle = mapfish_data_0Subtitle -mapfish_data_strech = mapfish_data_2Stretch -mapfish_data_institution = mapfish_data_5Institution -mapfish_data_source = mapfish_data_6Source -mapfish_data_creator = mapfish_data_5Creator -mapfish_data_dateplace = mapfish_data_7Place, Date -mapfish_data_river = mapfish_data_1River - -mapTitle = Title -mapSubtitle = Subtitle -mapRange = Range -mapStretch = Stretch -mapCreator = Creator -mapInstitution = Institution -mapSource = Source -mapDate = Place, Date -mapLogo = Logo - -# Get Feature Info Window -PATH = Path
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,667 +0,0 @@ -fullname = Flusshydrologische Software -user = Benutzer: -guest = Gast -logout = Abmelden -projects = Projekte -open_project = Projekt \u00f6ffnen -delete_project = Projekt l\u00f6schen -rename_project = Projekt umbenennen -clone_project = Projekt duplizieren -copy_of = Kopie -manage_projects = Projekte verwalten -favorite_tooltip = Dauerhaft speichern? -favorite_tooltip_meaning = Goldener Stern: gespeichert -projectlist_creationTime = Anlegezeitpunkt -projectlist_title = Titel -projectlist_favorite = Dauerhaft -projectlist_close = Schlie\u1E9Een -really_delete = Wollen Sie dieses Projekt wirklich l\u00f6schen? -project_name_too_long = Der eingegebene Projektname ist zu lang. Die maximale L\u00e4nge betr\u00e4gt $LEN Zeichen. -switch_language = Englisch -info = Info -warning = Achtung -warning_language = Das \u00c4ndern der Sprache startet eine neue Sitzung des Programms. Alle offenen Fenster werden geschlossen. -no_projects = Keine alten Berechnungen gefunden. -load_projects = Lade Berechnungen... -empty_table = Lade Daten... -empty_filter = Keine Daten gefunden. -date_format = dd.MM.yyyy -datetime_format = dd.MM.yyyy HH:mm -new_project = Neues Projekt -new_calculation = Neue Berechnung -module_selection = Modul -river_selection = Gew\u00e4sser -winfo = W-INFO -minfo = M-INFO -map = Karte -new_map = Neue Karte -new_chart = Neues Diagramm -diagram = Diagramm -axes = Achsen -legend = Legende -chart_title = Titel -chart_subtitle = Untertitel -grid = Gitternetz -antialiasing = Kantengl\u00e4ttung -axis_name = Name -chart_start = von -chart_end = bis -x_axis = X-Achse -y1_axis = Y1-Achse -y2_axis = Y2-Achse -y3_axis = Y3-Achse -legend_name = Name -show_legend = Anzeigen -aggregation_threshold = Schwellwert zur Aggregation von Legendeneintr\u00e4gen -scale = Skalierung -databasket = Datenkorb -databasket_loading=Lade Datenkorb Inhalt -fix = Fixierungsanalyse -fixanalysis = Fixierungsanalyse -next = Weiter -location_distance_state = Berechnungsort(e) / strecke w\u00e4hlen [km] -distance_state = Berechnungsstrecke w\u00e4hlen [km] -waterlevel_ground_state = Differenzen zwischen Wasserspiegel und Gel\u00e4nde [m] -location = Ort(e) -locations = Orte -single_location = Ort -distance = Strecke -unitFrom = km - -unitTo = km a -unitWidth = m -search = Suchbegriff -discharge = Kennzeichnender Abfluss -properties = Eigenschaften -activateTheme = Aktivieren -deactivateTheme = Deaktivieren -removeTheme = Entfernen -manageThemes = Themen verwalten -label_ok = Ok -label_cancel = Abbrechen -cancelCalculationLabel = Aktuelle Berechnung abbrechen. -calculationCanceled = Die Berechnung wurde abgebrochen. -range = Bereich -resultCount = Treffer -start_year = Start -end_year = Ende -period = Zeitraum -year = Jahr -sedimentload_ls = Sediment Fracht -welcome = Willkommen bei der Flusshydrologischen Software -welcome_open_or_create = Bitte \u00f6ffnen Sie ein bestehendes Projekt aus der Projektliste oder erstellen Sie ein - -# Header images -flysLogo = images/flys_logo.gif -bfgLogo = images/bfg_logo.gif -bfgLogoSmall = images/bfg_logo_small.png - -# Images -downloadPNG = images/png_export.png -downloadPDF = images/pdf_export.png -downloadSVG = images/svg_export.png -downloadCSV = images/save_csv.png -downloadAT = images/save_at.png -downloadWST = images/save_wst.png -loadingImg = images/loading.gif -cancelCalculation = images/cancelCalculation.png -markerRed = images/marker_red.png -markerGreen = images/marker_green.png -riverMap = images/FLYS_Karte.png -properties_ico = images/properties.png - -dpLabelFrom = von -dpUnitFrom = km -dpLabelTo = bis -dpUnitTo = km -dpLabelStep = a -dpUnitStep = m - -wgLabelFrom = Von -wgUnitFrom = m -wgLabelTo = Bis -wgUnitTo = m -wgLabelStep = a -wgUnitStep = m - -unitFromInM = Von [m]: -unitToInM = Bis [m]: -unitDiffInM = Diff [m]: -unitLocation = km -wrongFormat = Falsches Format -atLeastOneValue = Sie m\u00fcssen mindestens einen Wert eingeben. -missingInput = Sie m\u00fcssen einen Wert eingeben. -too_many_values = Nur ein Eingabewert erlaubt - -description = Beschreibung -from = von -to = bis -bottom_edge = Unterkante -top_edge = Oberkante -riverside = Flussseite -name = Name -type = Typ -wq_waterlevel_label = Kennzeichnender Wassterstand -wq_table_w = Kennzeichnende Wasserst\u00e4nde -wq_table_q = Kennzeichnende Abfl\u00fcsse / Dauerzahlen -wq_value_w = W [cm am Pegel] -wq_value_q = Q [m\u00b3/s] -river_km = Fluss-Km -uesk_profile_distance = Abstand [m] - -wqTitle = Eingabe f\u00fcr W/Q Daten -wqadaptedTitle = Eingabe f\u00fcr W/Q Daten -wqHistorical = Auswahl der Analyseart -calcTableTitle = Ergebnisausgabe -helperPanelTitle = Eingabeunterst\u00fctzung -gaugePanelTitle = Gew\u00e4sser/Pegel-Info -measurementStationPanelTitle = Gew\u00e4sser/Messstellen-Info -wqW = W am Pegel [cm] -wqQ = Q [m\u00b3/s] -wqQatGauge = Q am Pegel [m\u00b3/s] -wqWFree = W auf freier Strecke [m+NHN] -wqQGauge = Kennzeichnender Abfluss am Pegel -wqSingle = Einzelwerte -wqRange = Wertebereich -unitWNN = W [NN+m] -unitWSingle = cm -unitWFrom = cm - -unitWTo = cm a -unitWStep = cm -unitQSingle = m\u00b3/s -unitQFrom = m\u00b3/s - -unitQTo = m\u00b3/s a -unitQStep = m\u00b3/s -main_channel = Hauptgerinne -total_channel = Gesamtgerinne -footerHome = Home -footerContact = Kontakt -footerImpressum = Impressum -print = Drucken -printWindowTitle = PDF-Druckeinstellungen - -projectListMin = format-indent-less.png -projectListAdd = list-add.png -buttonNext = \u00dcbernehmen -imageBack = images/back_de.png -imageSave = images/save.png -theme_top = images/go-first.png -theme_up = images/go-up.png -theme_down = images/go-down.png -theme_bottom = images/go-bottom.png -zoom_all = images/mag_100.png -zoom_in = images/mag_zoom_box.png -zoom_out = images/mag_zoom_minus.png -zoom_back = images/mag_zoom_back.png -pan = images/hand.png -askThemeRemove = Sind Sie sicher, dass sie die gew\u00e4hlten / das gew\u00e4lte Thema l\u00f6eschen wollen? -add = Hinzuf\u00fcgen - -addPointsTooltip = Manuelle Punkte hinzuf\u00fcgen -addWSPTooltip = Manuelle WSP hinzuf\u00fcgen -downloadPNGTooltip = Diagramm als PNG herunterladen -downloadPDFTooltip = Diagramm als PDF herunterladen -downloadSVGTooltip = Diagramm als SVG herunterladen -downloadCSVTooltip = Daten als CSV herunterladen -zoomToMaxExtentTooltip = Auf maximale Ausdehnung zoomen -zoomOutTooltip = Herauszoomen -historyBackTooltip = Voriger Zoom -panControlTooltip = Verschieben -zoomboxTooltip = Ausschnitt vergr\u00f6\u00dfern -chartPropertiesTooltip = Diagrammeigenschaften -printTooltip = Drucken - -static_sqrelation = Transport-Abfluss Beziehung -discharge_curve = Abflusskurve am Pegel -discharge_curve_gaugeless = Abflusskurve -gauge_discharge_curve = Abflusstafel am Pegel -computed_discharge_curve = Abflusskurve -computed_discharge_curves = Abflusskurven -longitudinal_section = L\u00e4ngsschnitt -duration_curve = Dauerlinie -discharge_longitudinal_section = W f\u00fcr benutzerdefinierten Abflussl\u00e4ngsschnitt -floodmap = \u00dcberschwemmungsfl\u00e4che -historical_discharge = Zeit-Diagramm -historical_discharge_wq = W/Q-Diagramm -flow_velocity = Flie\u00dfgeschwindigkeiten -flow_velocity_export = Flie\u00dfgeschwindigkeiten Export -bedheight_middle = Mittlere Sohlh\u00f6he -bedheight_middle_export = Mittlere Sohlh\u00f6he Export -bed_longitudinal_section = Sohlbeschaffenheit -bed_longitudinal_section_export = Sohlbeschaffenheit Export -sq_relation_a = A Feinkornanteil -sq_relation_b = B Sand (Suspensionstransport) -sq_relation_c = C Sand (Geschiebetransport) -sq_relation_d = D Fein- und Mittelkies -sq_relation_e = E Grobkornanteil (> Mittelkies) -sq_relation_f = F Geschiebetransport Gesamt -sq_relation_export = SQ Export -cross_section = Querprofil -cross_sections = Querprofile -w_differences = Differenzen -w_differences_export = Differenzen Export -reference_curve_export = Bezugslinien Export -historical_discharge_export = Historische Abflusskurven Export -showextramark = Zeige Anfang der Extrapolation -extreme_wq_curve = W/Q -fix_wq_curve = W/Q-Diagramm -fix_deltawt_curve = \u0394 W/t -fix_longitudinal_section_curve = L\u00e4ngsschnitt -fix_derivate_curve = Ableitungskurve -fix_vollmer_wq_curve = W/Q-Diagramm -datacage_add_pair = Differenzenpaar hinzuf\u00fcgen -load_diameter = Geschiebedurchmesser -bed_diameter = Sohldurchmesser -soundings = Peilungen -soundings_width = Gepeilte Breite -bed_difference_year = Sohlh\u00f6hendifferenz (Jahr) -bed_difference_epoch = Sohlh\u00f6hendifferenz (Epoche) -bed_difference_height_year = Sohlh\u00f6hendifferenz pro Jahr - -waterlevel_export = Wasserstand/Wasserspiegellagen Export -waterlevel_report = Wasserstand/Wasserspiegellagen Bericht -computed_dischargecurve_export = Abflusskurven Export -computed_dischargecurve_report = Abflusskurven Bericht -discharge_longitudinal_section_export = Abflussl\u00e4ngsschnitt Export -discharge_longitudinal_section_report = Abflussl\u00e4ngsschnitt Bericht -durationcurve_export = Dauerzahlen Export -durationcurve_report = Dauerzahlen Bereicht -dataexport = Datenexport -csv = CSV -wst = WST -at = AT -pdf = PDF -computed_dischargecurve_at_export = AT Export -gauge_discharge_curve_at_export = Abflusskurve am Pegel -gauge_class = Abflussklasse -eventselect = Ereignisauswahl -events = Ereignisse -kmchart = W/Q-Vorschau - -exportATTooltip = Daten als AT Datei exportieren - -chart_themepanel_header_themes = Thema -chart_themepanel_header_actions = Aktionen -chart_themepanel_synchron = Synchron navigieren -chart_themepanel_asynchron = Einzeln navigieren -chart_themepanel_set_master = Referenz -chart_themepanel_new_area = Erzeuge Fl\u00e4che ... -chart_themepanel_area_under = unter ... -chart_themepanel_area_over = \u00fcber ... -chart_themepanel_area_between = zwischen ... -against_x_axis = \u00fcber X-Achse - -gauge_mnq = um MNQ -gauge_mq = um MQ -gauge_mhq = um MHQ -gauge_hq5 = \u00fcber HQ5 - -ele_window_title = H\u00f6henknoten setzen -ele_window_label = H\u00f6henangaben in m \u00fc. NN. -ele_window_x_col = X -ele_window_y_col = Y -ele_window_z_col = Z-Koordinate -ele_window_ok_button = H\u00f6he setzen -ele_window_cancel_button = Abbrechen -ele_window_format_error = Die von Ihnen eigegebene H\u00f6he ist ung\u00fcltig: -ele_window_save_error = Fehler beim Speichern der H\u00f6hen. -ele_window_geometry_error = Die Geometrie wird nicht unterst\u00fctzt: - -unexpected_exception = Ein unerwarteter Fehler ist aufgetreten -error_years_wrong = Das zweite Jahr muss gr\u00f6\u00dfer als das erste sein. -error_read_minmax_values = Fehler beim Lesen der min/max Werte. Es kann keine Validierung der eingegebenen Strecke durchgef\u00fchrt werden. -error_validate_range = Der Wert $1 muss kleiner als $3 und gr\u00f6\u00dfer als $2 sein. -error_validate_date_range = Anfangsdatum muss fr\u00fcher sein als Enddatum. -error_validate_date_range_invalid = Der eingegebene Zeitbereich ist ung\u00fcltig. -error_validate_lower_range = Der untere Wert $1 muss gr\u00f6\u00dfer sein als $2. -error_validate_upper_range = Der obere Wert $1 muss kleiner sein als $2. -error_empty_state = Es wurden nicht alle ben\u00d6tigten Daten eingegeben. -error_invalid_double_value = Falsches Format f\u00fc eine Flie\u00dfkommazahl. -error_create_artifact = Fehler beim Erstellen eines neuen Projekts. -error_describe_artifact = Fehler beim Laden der Parametrisierung. -error_feed_data = Fehler beim Hinzuf\u00fcgen neuer Daten. -error_advance_artifact = Fehler beim Wechseln des Zustands des Projektes. -error_add_artifact = Fehler beim Hinzuf\u00fcgen einer Parametrisierung. -error_remove_artifact = Fehler beim Entfernen einer Parametrisierung. -error_create_collection = Fehler beim Erstellen eines neuen Projektes. -error_describe_collection = Fehler beim Laden des Projektzustandes. -error_no_rivers_found = Fehler beim Lesen der unterst\u00fctzten Fl\u00fcsse. -error_no_such_user = Fehler - Kein solcher Benutzer vorhanden. -error_no_users = Fehler - Keine Benutzer vorhanden. -error_no_waterlevel_pair_selected = Fehler - kein Paar zur Differenzenbildung gew\u00e4hlt. -error_same_waterlevels_in_pair = Error - minuend and subtrahend m\u00fcssen sich unterscheiden. -error_not_logged_in = Sie m\u00fcssen sich erst einloggen um mit der Arbeit beginnen zu k\u00f6nnen. -error_load_parameterization = Fehler beim Laden der Parametrisierung. -error_wrong_date = Bitte geben Sie gültige Daten ein. -error_no_gaugeoverviewinfo_found = Fehler beim Laden der Fluss- und Pegelinformationen - -error_feed_no_data = Keine Eingabedaten gefunden. -error_feed_from_out_of_range = Der untere Wert liegt au\u00dferhalb des g\u00fcltigen Wertebereiches. -error_feed_to_out_of_range = Der obere Wert liegt au\u00dferhalb des g\u00fcltigen Wertebereiches. -error_feed_from_bigger_to = Der untere Wert ist gr\u00f6\u00dfer als der obere Wert. -error_feed_invalid_wq_mode = Ung\u00fcltiger Modus f\u00fcr die WQ-Eingabe gew\u00e4hlt. -error_feed_number_format_float = Der eingegebene Wert ist keine Flie\u00dfkommazahl. -error_feed_invalid_calculation_mode = Die gew\u00e4hlte Berechnungsart ist ung\u00fcltig. -error_feed_no_calculation_mode = Es ist keine Berechnungsart gew\u00e4hlt. -error_feed_no_such_river = Der gew\u00e4hlte Fluss wird nicht unterst\u00fctzt. -error_feed_no_river_selected = Es wurde kein Fluss gew\u00e4hlt. -error_feed_no_wq_mode_selected = Es ist kein W/Q Modus gew\u00e4hlt. -error_feed_q_values_invalid = Die gew\u00e4hlten Q Werte liegen au\u00dferhalb des g\u00fcltigen Bereiches. -error_feed_w_values_invalid = Die gew\u00e4hlten W Werte liegen au\u00dferhalb des g\u00fcltigen Bereiches. -error_chart_info_service = Meta Informationen des Diagramms konnten nicht geladen werden. -error_no_meta_data_found = Keine Meta-Daten gefunden. -error_load_artifact = Fehler beim Hinzu\u00fcgen neuer Daten in das aktuelle Projekt. -error_no_calc_result=Es wurden keine Berechnungsergebnisse gefunden. -error_no_theme_styles_found=Es konnten keine Stile f\u00fcr das gew\u00e4hlte Thema gefunden werden. -error_no_feature_selected = Kein Objekt ausgew\u00e4hlt. -error_no_map_config = Es konnte keine Kartenkonfiguration gefunden werden. -error_no_map_output_type = Es konnte kein Ausgabemodus f\u00fcr Karten gefunden werden. -error_no_valid_gfi_url = Ung\u00fcltige GetFeatureInfo URL. -error_gfi_req_failed = Die GetFeatureInfo Anfrage ist fehlgeschlagen. -error_gfi_parsing_failed = Fehler beim Lesen der GetFeatureInfo Antwort. -error_gc_req_failed = Fehler beim Laden des Capabilities Dokuments. -error_gc_doc_not_valid = Das Capabilities Dokument ist nicht valide. -error_malformed_url = Die eingegebene URL ist ung\u00fcltig. -error_no_dgm_selected = Sie haben kein DGM gew\u00e4hlt. -error_invalid_dgm_selected = Sie haben ein falsches DGM gew\u00e4hlt. -error_bad_dgm_range = Das gew\u00e4hlte DGM passt nicht zur gew\u00e4hlten Berechnungsstrecke. -error_bad_dgm_river = Das gew\u00e4hlte DGM passt nicht zum gew\u00e4hlten Fluss. -error_dialog_not_valid = Eine oder mehrere Daten sind nicht korrekt. -error_invalid_date = Das eingegebene Datum ist nicht korrekt. -error_same_location = Der gew\u00e4hlte Ort ist der Bezugsort. -error_contains_same_location = Zielorte beinhalten den Bezugsort. -error_update_collection_attribute = Fehler beim Aktualisieren des Collection-Attributs. -error_values_needed = Es muss mindestens ein Wert selektiert sein. -error_no_module_found = Keine nutzbaren Module gefunden. - -warning_use_first_feature = Sie haben mehr als ein Objekt ausgew\u00e4hlt. Das erste Objekt wird benutzt. -warning_no_wsp_selected = Kein Wasserstand ausgew\u00e4hlt! -warning_cannot_parse_date = Datum ist ung\u00fcltig! -warning_select_two_values = Bitte zwei Werte w\u00e4hlen! - -## map related strings -digitize = images/digitize.png -pipe1 = Rohr1 -pipe2 = Rohr2 -ditch = Graben -dam = Damm -ring_dike = Ringdeich -selectFeature = images/selectFeature.png -removeFeature = images/removeFeature.png -getFeatureInfo = images/info.png -getFeatureInfoTooltip = Informationswerkzeug -getFeatureInfoWindowTitle = Information zur Kartenebene: -addWMS = images/add_map.png -printMapSettings = images/print_map_settings.png -addWMSTooltip = Laden von Kartenebenen eines externen WMS Dienstes. -adjustElevation = images/adjustElevation.png -measureLine = images/measure_line.png -measurePolygon = images/measure_plane.png -step = Schritt -calculationStarted = Berechnung wurde gestarted. -zoomMaxExtent = Gesamtausschnitt -zoomIn = Hereinzoomen -zoomOut = Herauszoomen -zoomLayer = Zoom auf Layer -moveMap = Verschieben -digitizeObjects = Erstellung von Rohren, Gr\u00e4ben, D\u00e4mmen und Ringdeichen -selectObject = Auswahlwerkzeug -removeObject = Ausgew\u00e4hltes Objekt l\u00f6schen -adjustElevationTooltip = Festlegen von H\u00f6hen f\u00fcr D\u00e4mme, Ringeiche, Gr\u00e4ben und Rohre -measureDistance = L\u00e4ngenmessung -measureArea = Fl\u00e4chenmessung -map_themepanel_header_style = Stil -zoomToLayer = Layer-Zoom -requireDGM = Sie m\u00fcssen ein DGM ausw\u00e4hlen. -upload_file = hochladen -shape_file_upload = Shapedatei hochladen -attribution = ©Intevation GmbH 2013<br>Data ©<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> -wmsURLMenuItem = WMS URL -wmsURLBoxTitle = WMS URL der Kartenebene -requireTheme = Sie m\u00fcssen ein Thema ausw\u00e4hlen. - -# data cage -waterlevels = Wasserst\u00e4nde -old_calculations = Fr\u00fchere Berechnungen -officiallines = Amtliche Linien -datacageAdd = Daten laden -heightmarks = Hochwassermarken -basedata = Basis-Daten -fixations = Fixierungen -flood_protections = HW-Schutzanlagen -columns = Spalten -annotation = Streckenfavoriten -annotation = Streckenfavoriten - Typen -annotations = Streckenfavoriten -all_annotations = Alle Streckenfavoriten -flowvelocitymeasurement = gemessene Flie\u00dfgeschwindigkeiten -bed_quality_bed = Sohlbeschaffenheit - Sohle -bed_quality_load = Sohlbeschaffenheit - Geschiebe -additionals = Zus\u00e4tzliche L\u00e4ngsschnitte -differences = Differenzen -kilometrage = Stationierung -riveraxis = Flussachse -km = Km -qps = Querprofilspuren -hws = Hochwasserschutzanlagen -catchments = Einzugsgebiete -catchment_wms = Einzugsgebiete (WMS) -floodplain = Talaue -lines = Darstellungstyp: Linien -buildings = Bauwerke -fixpoints = Festpunkte -uesk = \u00dcberschwemmungsfl\u00e4chen -calculations = Berechnungen -current = Aktuell -potential = Potenziell -bfg = BfG -land = Land -rastermap = Rasterkarte -background = Hintergrundkarte (WMS) -discharge_tables_chart = W/Q-Vorschau -discharge_table_nn = Abflusstafeln am Pegel -discharge_table_gauge = Abflusstafel am Pegel -mainvalue = Hauptwerte -mainvalues = Hauptwerte -wmainvalue = Hauptwerte (W) -qmainvalue = Hauptwerte (Q) -show_mainvalues = Hauptwerte anzeigen -dems = Digitale Gel\u00e4ndemodelle -hydrboundaries = Hydrologische Grenzen -gaugelocations = PEGELONLINE aktuell (WMS) -single = Jahr -epoch = Epoche -bedheights = Sohlh\u00f6hen -morph_width = Morphologische Breite -datacage = Datenkorb -official = Offiziell -inofficial = Inoffiziell -custom_lines = Eigene Digitalisierungen -hws_lines = Liniendaten -hws_points = Punktdaten -hws_fed_unknown = Unbekanntes Bundesland -jetties = Buhnen -route_data = Streckendaten -other = Sonstige -axis = Achse -bfg_model = BfG-Modell -federal = Bundesländer -areas = Darstellungstyp: Flächen -sobek_flooded = SOBEK-Grenzlinie durchflutet / nicht durchflutet -sobek_areas = SOBEK-Bereiche -measurements = Messungen -floodmarks = HW-Marken -pegel_had_measurement_points = HAD Abflussmessstellen (WMS) -gauge_points = Pegelmessstelle (WMS) -gauge_level = Wasserstand (WMS) -gauge_names = Pegelname (WMS) -gauge_tendency = Tendenz des Wasserstands (WMS) - -startcolor = Farbverlauf Startfarbe -endcolor = Farbverlauf Endfarbe -numclasses = Anzahl Klassen - -# capabilities information panel -addwmsInputTitle = Basis URL des WMS Dienstes -addwmsInfoTitle = Informationen des WMS Dienstes -addwmsLayerTitle = Ebene ausw\u00e4hlen -addwmsBack = Zur\u00fcck -addwmsContinue = Weiter -addwmsCancel = Abbrechen -addwmsInvalidURL = Die URL ist nicht g\u00fcltig. -capabilitiesHint = Bitte beachten Sie die folgenden Informationen des WMS-Dienstes. -capabilitiesTitle = Titel -capabilitiesURL = URL -capabilitiesAccessConstraints = Nutzungsbedingungen -capabilitiesFees = Geb\u00fchren -capabilitiesContactInformation = Weitere Informationen -capabilitiesEmail = Email -capabilitiesPhone = Telefon - -#Property dialog -chart = Diagramm -export = Export -width = Breite -height = H\u00f6he -visibility = Sichtbarkeit -upper = bis -lower = von -fixation = Fix -font_size = Schriftgr\u00f6\u00dfe -label = Titel -title = Titel -subtitle = Untertitel -display_grid = Gitterlinien anzeigen -display_logo = Logo anzeigen -logo_placeh = Horizontale Ausrichtung Logo -logo_placev = Vertikale Ausrichtung Logo -top = oben -bottom = unten -center = mittig -left = links -right = rechts -none = keines - -notselected = keine - -linetype = Linientyp -textstyle = Textstil -linecolor = Linienfarbe -showhorizontalline = Horizontale Linie -showverticalline = Vertikale Linie -textcolor = Textfarbe -textsize = Textgr\u00f6\u00dfe -font = Schriftart -showpoints = Punkte anzeigen -showbackground = Hintergrund anzeigen -textshowbg = Hintergrund anzeigen -backgroundcolor = Hintergrundfarbe -bandwidthcolor = Bandbreitenfarbe -textbgcolor = Hintergrundfarbe -textorientation = Textausrichtung -linesize = Liniendicke -pointsize = Punktdicke -bandwidth = Bandbreite -pointcolor = Punktfarbe -showlines = Linien anzeigen -showlinelabel = Linienbeschriftung anzeigen -showpointlabel = Punktbeschriftung anzeigen -labelfontface = Beschriftung: Schriftart -labelfontcolor = Beschriftung: Schriftfarbe -labelfontsize = Beschriftung: Schriftgr\u00f6\u00dfe -labelfontstyle = Beschriftung: Schriftstil -labelbgcolor = Beschriftung: Hintergrundfarbe -labelshowbg = Beschriftung: Hintergrund f\u00fcllen -horizontal = horizontal -vertical = vertikal -showwidth = Breite anzeigen -showlevel = Wasserstand anzeigen -showminimum = Minimum anzeigen -showmaximum = Maximum anzeigen -showborder = Linie anzeigen -transparent = Transparent -transparency = Transparenz -showarea = Show area -showarealabel = Fl\u00e4che beschriften -showmiddleheight = Mittlere Tiefe anzeigen -fillcolor = F\u00fcllfarbe -areabgcolor = F\u00fcllfarbe -areashowborder = Fl\u00e4chenumrandung -areashowbg = Fl\u00e4chenhintergrund -areabordercolor = Umrandungsfarbe -areatransparency = Tranparenz -wsplgen_cat1 = F\u00fcllfarbe 0.0 <= DIFF < 1 -wsplgen_cat2 = F\u00fcllfarbe 1.0 <= DIFF < 2 -wsplgen_cat3 = F\u00fcllfarbe 2.0 <= DIFF < 3 -wsplgen_cat4 = F\u00fcllfarbe 3.0 <= DIFF < 4 -wsplgen_cat5 = F\u00fcllfarbe 4.0 <= DIFF - -# Manual Points Editor -addpoints = Punkte hinzuf\u00fcgen -pointname = Bezeichner -removepoint = Entfernen -newpoint = Neuer Punkt -standby = Erstelle Parameterisierung ... bitte warten. -points = Punktthema -editpoints = Eintr\u00e4ge editieren -addWSP = Neues WSP Thema anlegen -addWSPButton = WSP Thema -selection = Auswahl - -# Reference Curves -reference_curve = Bezugslinie -reference_curve_normalized = Reduzierte Bezugslinie -reference_startpoint = Bezugsort/pegel -reference_endpoint = Zielort/pegel - -fix_deltawt_export = \u0394 W/t -select=Ausgewählt -add_date=Hinzuf\u00fcgen - -fix_parameters_export = Angepasste Koeffizienten -fix_parameters = CSV -sq_overview=\u00dcbersicht - -gauge_zero = PNP -gauge_q_unit = m\u00b3/s -gauge_river_info_link = Gew\u00e4sserinfo -gauge_info_link = Pegelinfo -gauge_url = https://flys-intern.intevation.de/PegelInfo/ -gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ -gauge_curve_link = Abflusskurve/-tafel -discharge_timeranges = AK-Zeitr\u00e4ume -discharge_chart = W/Q-Vorschau - -measurement_station_type = Messstellenart -measurement_station_operator = Betreiber -measurement_station_start_time = Beginn der Aufzeichnung -measurement_station_url = https://flys-intern.intevation.de/MessstellenInfo/ -measurement_station_info_link = Messstelleninfo -measurement_station_gauge_name = hydrologischer Bezugspegel - -# The prefix is used to classify them and will be stripped -# If the payload part sarts with a number it will be sorted -# By this number and the number will be stripped. -# Number must be a single digit 0-9. This hack was made necessary -# by the usage of an attribute table in mapfish - -mapfish_data_range = mapfish_data_3Bereich -mapfish_data_subtitle = mapfish_data_0Untertitel -mapfish_data_strech = mapfish_data_2Strecke -mapfish_data_institution = mapfish_data_5Institution -mapfish_data_source = mapfish_data_6Datenquelle -mapfish_data_creator = mapfish_data_4Bearbeiter -mapfish_data_dateplace = mapfish_data_7Ort, Datum -mapfish_data_river = mapfish_data_1Gew\u00e4sser - -mapTitle = Titel -mapSubtitle = Untertitel -mapRange = Bereich -mapStretch = Strecke -mapCreator = Bearbeiter -mapInstitution = Institution -mapSource = Datenquelle -mapDate = Ort, Datum -mapLogo = Logo - -# Get Feature Info Window -PATH = Dateipfad
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,618 +0,0 @@ -fullname = Flusshydrologische Software -user = User: -guest = guest -logout = Logout -projects = Projects -open_project = Open Project -delete_project = Delete Project -rename_project = Rename Project -clone_project = Clone Project -copy_of = Copy -manage_projects = Manage Projects -favorite_tooltip = Permanently store? -favorite_tooltip_meaning = Golden star: stored -projectlist_creationTime = Creation time -projectlist_title = Title -projectlist_favorite = Permanent -projectlist_close = Close -really_delete = Do you really want to delete this project? -project_name_too_long = The entered project name is too long. Max length is $LEN characters. -switch_language = German -info = Info -warning = Attention -warning_language = Choosing a new language starts a new session. All open windows will be closed. -no_projects = No existing calculations found. -load_projects = Load calculations... -empty_table = Loading data... -empty_filter = No data found. -date_format = yyyy-MM-dd -datetime_format = yyyy-MM-dd HH:mm -new_project = New Project -new_calculation = New Calculation -module_selection = Module -river_selection = Rivers -winfo = WINFO -minfo = MINFO -map = Map -new_map = New Map -new_chart = New Chart -diagram = Chart -axes = Axes -legend = Legend -chart_title = Title -chart_subtitle = Subtitle -grid = Grid -antialiasing = Antialiasing -axis_name = Name -chart_start = Start -chart_end = End -x_axis = X-Axis -y1_axis = Y1-Axis -y2_axis = Y2-Axis -y3_axis = Y3-Axis -legend_name = Name -show_legend = Show -aggregation_threshold = Threshold for aggregation of legend entries -scale = Scale -databasket = Databasket -databasket_loading = Loading Databasket content -fix = Fixing -fixanalysis = Fixing Analysis -next = Next -location_distance_state = Choose calculation location(s) / range [km] -distance_state = Choose calculation range [km] -waterlevel_ground_state = Choose differences betweeen waterlevel and ground [m] -location = Location(s) -locations = Locations -single_location = Location -distance = Range -unitFrom = km -unitTo = km a -unitWidth = m -search = Search -discharge = FIXME(Name) -properties = Properties -activateTheme = Activate -deactivateTheme = Deactivate -removeTheme = Remove -manageThemes = Manage themes -label_ok = Ok -label_cancel = Cancel -cancelCalculationLabel = Stop the current calculation. -calculationCanceled = The calculation has been canceled. -range = Range -resultCount = Hits -start_year = Start -end_year = end -period = Period -year = Year -sedimentload_ls = Sediment Load -welcome = Welcome to Flusshydrologische Software -welcome_open_or_create = Please open a project from the project list or create a - -# Header images -flysLogo = images/flys_logo.gif -bfgLogo = images/bfg_logo.gif -bfgLogoSmall = images/bfg_logo_small.png - -# Images -downloadPNG = images/png_export.png -downloadPDF = images/pdf_export.png -downloadSVG = images/svg_export.png -downloadCSV = images/save.png -downloadAT = images/save_at.png -downloadWST = images/save_wst.png -loadingImg = images/loading.gif -loadingImg = images/loading.gif -cancelCalculation = images/cancelCalculation.png -markerRed = images/marker_red.png -markerGreen = images/marker_green.png -riverMap = images/FLYS_Karte.png -properties_ico = images/properties.png - -dpLabelFrom = from -dpUnitFrom = km -dpLabelTo = to -dpUnitTo = km -dpLabelStep = a -dpUnitStep = m - -wgLabelFrom = From -wgUnitFrom = m -wgLabelTo = To -wgUnitTo = m -wgLabelStep = a -wgUnitStep = m - -unitFromInM = From [m]: -unitToInM = To [m]: -unitDiffInM = Diff [m]: -unitLocation = km -wrongFormat = Wrong format -atLeastOneValue = You need to insert at least one value. -missingInput = You need to enter a value. -too_many_values = Only one value allowed - -addPointsTooltip = Add manual points -addWSPTooltip = Add manual LS -downloadPNGTooltip = Download chart as PNG -downloadPDFTooltip = Download chart as PDF -downloadSVGTooltip = Download chart as SVG -downloadCSVTooltip = Download data as CSV -zoomToMaxExtentTooltip = Zoom to max extent -zoomOutTooltip = Zoom out -historyBackTooltip = Previous zoom -panControlTooltip = Pan -zoomboxTooltip = Zoombox -chartPropertiesTooltip = Chartproperties - -description = Description -from = From -to = To -riverside = Riverside -bottom_edge = Bottom edge -top_edge = Top edge -name = Name -type = Type -wq_waterlevel_label = Characteristic Waterlevel -wq_table_w = Characteristic Waterlevels -wq_table_q = Characteristic Discharges / Durations -wq_value_w = W [cm at Gauge] -wq_value_q = Q [m\u00b3/s] -river_km = River-Km -uesk_profile_distance = Distance [m] - -wqTitle = Input for W/Q Data -wqadaptedTitle = Input for W/Q Data -wqHistorical = Selection of Analyse Type -calcTableTitle = Values -helperPanelTitle = Input Support -gaugePanelTitle = Gauge Information -measurementStationPanelTitle = Measurement Station Information -wqW = W at Gauge [cm] -wqQ = Q [m\u00b3/s] -wqQatGauge = Q at Gauge [m\u00b3/s] -wqWFree = W at free position [m+NHN] -wqQGauge = Discharge at Gauge -wqSingle = Single values -wqRange = Range -unitWNN = W [NN+m] -unitWSingle = cm -unitWFrom = cm - -unitWTo = cm a -unitWStep = cm -unitQSingle = m³/s -unitQFrom = m³/s - -unitQTo = m³/s a -unitQStep = m³/s -main_channel = Main Channel -total_channel = Total Channel -footerHome = Home -footerContact = Contact -footerImpressum = Legal info - -projectListMin = format-indent-less.png -projectListAdd = list-add.png -buttonNext = Next -imageBack = images/back_en.png -imageSave = images/save.png -theme_top = images/go-first.png -theme_up = images/go-up.png -theme_down = images/go-down.png -theme_bottom = images/go-bottom.png -zoom_all = images/mag_100.png -zoom_in = images/mag_zoom_box.png -zoom_out = images/mag_zoom_minus.png -zoom_back = images/mag_zoom_back.png -pan = images/hand.png -askThemeRemove = Are you sure that you want to remove the selected theme / themes? -add = Add - -static_sqrelation = SQ relation -discharge_curve = Discharge Curve at Gauge -discharge_curve_gaugeless = Discharge Curve -gauge_discharge_curve = Discharge Table at Gauge -computed_discharge_curve = Discharge Curve -computed_discharge_curves = Discharge Curves -longitudinal_section = Longitudinal Section Curve -duration_curve = Duration Curve -discharge_longitudinal_section = Discharge Longitudinal Section -floodmap = Floodmap -historical_discharge = Time Chart -historical_discharge_wq = W/Q Chart -flow_velocity = Flow Velocity -flow_velocity_export = Flow Velocity Export -bedheight_middle = Middle Bed Height -bedheight_middle_export = Middle Bed Height Export -bed_longitudinal_section = Bed Quality -bed_longitudinal_section_export = Bed Quality Export -sq_relation_a = A Feinkornanteil -sq_relation_b = B Sand (Suspensionstransport) -sq_relation_c = C Sand (Geschiebetransport) -sq_relation_d = D Fein- und Mittelkies -sq_relation_e = E Grobkornanteil (> Mittelkies) -sq_relation_f = F Geschiebetransport Gesamt -sq_relation_export = SQ Export -cross_section = Cross Section -cross_sections = Cross Sections -w_differences = Differences -w_differences_export = Differences Export -reference_curve_export = Reference Curve Export -historical_discharge_export = Historical Discharge Curve Export -showextramark = Show begin of extrapolation -extreme_wq_curve = W/Q -fix_wq_curve = W/Q-Diagram -fix_deltawt_curve = \u0394 W/t -fix_longitudinal_section_curve = Longitudinal Section -fix_derivate_curve = Derivate -fix_vollmer_wq_curve = W/Q-Diagram -datacage_add_pair = Add difference pair -load_diameter = Bedload Diameter -bed_diameter = Bed Diameter -soundings = Soundings -soundings_width = Soundings Width -bed_difference_year = Single Bedheight Differences -bed_difference_epoch = Epoch Bedheight Differences -bed_difference_height_year = Bedheight Difference per year - -exportATTooltip = Export as AT file - -waterlevel_export = Waterlevel Export -waterlevel_report = Waterlevel Report -computed_dischargecurve_export = Discharge Curve Export -computed_dischargecurve_report = Discharge Curve Report -discharge_longitudinal_section_export = Discharge Longitudinal Section Export -discharge_longitudinal_section_report = Discharge Longitudinal Section Report -durationcurve_export = Duration Curve Export -durationcurve_report = Duration Curve Report -dataexport = Data export -csv = CSV -wst = WST -at = AT -pdf = PDF -computed_dischargecurve_at_export = AT Export -gauge_discharge_curve_at_export = Gauge Discharge Curve -gauge_class = Gauge Class -eventselect = Eventselection -events = Events -kmchart = W/Q-Preview - -chart_themepanel_header_themes = Theme -chart_themepanel_header_actions = Actions -chart_themepanel_synchron = Navigate synchronously -chart_themepanel_asynchron = Navigate independently -chart_themepanel_set_master = Reference -chart_themepanel_new_area = New Area... -chart_themepanel_area_under = under ... -chart_themepanel_area_over = over ... -chart_themepanel_area_between = between ... -against_x_axis = Over X-Axis - -gauge_mnq = around MNQ -gauge_mq = around MQ -gauge_mhq = around MHQ -gauge_hq5 = above HQ5 - -ele_window_title = Elevation Node -ele_window_label = Elevation settings in m \u00fc. NN. -ele_window_x_col = X -ele_window_y_col = Y -ele_window_z_col = Z-Coordinate -ele_window_ok_button = Set elevations -ele_window_cancel_button = Cancel -ele_window_format_error = The elevation you have entered is invalid: -ele_window_save_error = Error while saving elevations. -ele_window_geometry_error = The geometry is not supported: - -unexpected_exception = There occured an unexpected exception -error_years_wrong = The second year needs to be bigger than the first year. -error_read_minmax_values = Error while reading min/max values for the location input. -error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2. -error_validate_date_range = Start date needs to be before end date. -error_validate_date_range_invalid = The specified timerange is invalid. -error_validate_lower_range = The lower value $1 needs to be bigger than $2. -error_validate_upper_range = The upper value $1 needs to be smaller than $2. -error_empty_state = Required inputs are missing. -error_invalid_double_value = Wrong format for a floating point number. -error_create_artifact = Error while creating new project. -error_describe_artifact = Error while loading the parameterization. -error_feed_data = Error while inserting new data. -error_advance_artifact = Error while changing the project's state. -error_add_artifact = Error while inserting new data. -error_remove_artifact = Error while removing data. -error_create_collection = Error while creating a new collection. -error_describe_collection = Error while fetching the projects state. -error_no_rivers_found = Error while reading supported rivers. -error_no_such_user = Error - no such user found. -error_no_users = Error - no users found. -error_no_waterlevel_pair_selected = Error - no waterlevel pair for building differences selected. -error_same_waterlevels_in_pair = Error - minuend and subtrahend have to differ. -error_not_logged_in = You need to log in before you are allowed to start your work. -error_load_parameterization = Could not load the parameterization. -error_wrong_date = Please enter valid dates. -error_no_gaugeoverviewinfo_found = Error while fetching the river and gauge info - -error_feed_no_data = No input data found. -error_feed_from_out_of_range = The lower value is bigger than the upper value. -error_feed_to_out_of_range = The upper value is out or the valid range. -error_feed_from_bigger_to = The lower value is bigger than the upper value. -error_feed_invalid_wq_mode = Invalid WQ-Mode selected. -error_feed_number_format_float = The inserted value is no floating point number. -error_feed_invalid_calculation_mode = The chosen calculation method is invalid. -error_feed_no_calculation_mode = No calculation method chosen. -error_feed_no_such_river = The selected river is not provided. -error_feed_no_river_selected = No river selected. -error_feed_no_wq_mode_selected = No W/Q mode selected. -error_feed_q_values_invalid = Selected Q values are outside the valid range. -error_feed_w_values_invalid = Selected W values are outside the valid range. -error_chart_info_service = Could not fetch meta information of the chart. -error_no_meta_data_found = No meta data found. -error_load_artifact = Error while adding data to the current project. -error_no_calc_result=No calculation results found. -error_no_theme_styles_found=No style for the selected theme found. -error_no_feature_selected = No object selected. -error_no_map_config = No Map configuration found. -error_no_map_output_type = No Map output found. -error_no_valid_gfi_url = No valid GetFeatureInfo response found. -error_gfi_req_failed = GetFeatureInfo request failed. -error_gfi_parsing_failed = Failed to read GetFeatureInfo response. -error_gc_req_failed = Error while loading Capabilities document. -error_gc_doc_not_valid = Capabilities document is not valid. -error_malformed_url = The URL you have entered is not valid. -error_no_dgm_selected = No DEM selected. -error_invalid_dgm_selected = You have selected an invalid DEM. -error_bad_dgm_range = You have selected a DEM with an invalid range. -error_bad_dgm_river = You have selected a DEM for a wrong river. -error_dialog_not_valid = One or more values are not valid. -error_invalid_date = The entered date is not valid. -error_same_location = Reference location equals selected location. -error_contains_same_location = Target locations contains reference location. -error_update_collection_attribute = Error while updating the collection attribut -error_values_needed = You must provide values. -error_no_module_found = No modules found - -warning_use_first_feature = You have more that one object selected. The first one is used. -warning_no_wsp_selected = No waterlevel selected! -warning_cannot_parse_date = Date is invalid! -warning_select_two_values = Please select two values! - -## map related strings -digitize = images/digitize.png -pipe1 = Pipe1 -pipe2 = Pipe12 -ditch = Ditch -dam = Dam -ring_dike = Ringdike -selectFeature = images/selectFeature.png -removeFeature = images/removeFeature.png -getFeatureInfo = images/info.png -getFeatureInfoTooltip = Information Tool -getFeatureInfoWindowTitle = Information for Map Layer: -addWMS = images/add_map.png -printMapSettings = images/print_map_settings.png -addWMSTooltip = Load layers from external WMS service. -adjustElevation = images/adjustElevation.png -measureLine = images/measure_line.png -measurePolygon = images/measure_plane.png -step = Step -calculationStarted = Calculation started. -zoomMaxExtent = Max extent -zoomIn = Zoom in -zoomOut = Zoom out -zoomLayer = Zoom to layer -moveMap = Move -digitizeObjects = Creation of pipes, ditches, dams and ringdikes -selectObject = Select tool -removeObject = Remove selected object -adjustElevationTooltip = Define elevations for barriers -measureDistance = Measure line -measureArea = Measure area -map_themepanel_header_style = Style -zoomToLayer = Layer-Zoom -requireDGM = You need to choose a DEM. -upload_file = upload -shape_file_upload = Upload shapefile -attribution = ©Intevation GmbH 2013<br>Data ©<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> -wmsURLMenuItem = WMS URL -wmsURLBoxTitle = Layer WMS URL -requireTheme = You need to choose a Layer. - -# data cage -waterlevels = Waterlevels -old_calculations = Former Calculations -officiallines = Official lines -datacageAdd = Add data -heightmarks = Height Marks -basedata = Base Data -fixations = Fixations -flood_protections = Flood Protections -columns = Columns -annotation = Annotations -annotations = Annotations -all_annotations = All annotations -flowvelocitymeasurement = Flowvelocity measurements -bed_quality_bed = Quality - Bed -bed_quality_load = Quality - Load -additionals = Additional Longitudinal Section Curves -differences = Differences -kilometrage = Kilometrage -riveraxis = Riveraxis -km = Km -qps = Crosssection Tracks -hws = Floodplain Protection Work -catchments = Catchments -catchment_wms = Catchment (WMS) -floodplain = Floodplain -lines = Lines -buildings = Buildings -fixpoints = Fixpoints -uesk = Floodmaps -calculations = Calculations -current = Current -potentiel = Potentiel -bfg = BfG -land = Land -rastermap = Rastermap -background = Background Layer (WMS) -discharge_tables_chart = W/Q-Preview -discharge_table_nn = Discharge Tables at Gauge -discharge_table_gauge = Discharge Table at Gauge -mainvalue = Mainvalue -mainvalues = Mainvalues -wmainvalue = Mainvalues (W) -qmainvalue = Mainvalues (Q) -show_mainvalues = Show Mainvalues -dems = Digital Elevation Models -hydrboundaries = Hydrological Boundaries -gaugelocations = Location of Gauges (WMS) -single = Year -epoch = Epoch -bedheights = Bedheights -morph_width = morphologic Width -datacage = Datacage - -startcolor = Colorrange start color -endcolor = Colorrange end color -numclasses = Number of classes - -# capabilities information panel -addwmsInputTitle = Base URL of WMS service -addwmsInfoTitle = Information about WMS service -addwmsLayerTitle = Choose Layer -addwmsBack = Back -addwmsContinue = Continue -addwmsCancel = Cancel -addwmsInvalidURL = The URL is not valid. -capabilitiesHint = Please notice the information of the WMS service. -capabilitiesTitle = Title -capabilitiesURL = URL -capabilitiesAccessConstraints = Access Constraints -capabilitiesFees = Fees -capabilitiesContactInformation = Further Information -capabilitiesEmail = Email -capabilitiesPhone = Phone - -#Properties dialog -chart = Chart -export = Export -width = Width -height = Height -visibility = Visibility -upper = to -lower = from -fixation = Fix -font_size = Fontsize -label = Title -title = Title -subtitle = Subtitle -display_grid = Display grid -display_logo = Display logo -logo_placeh = Horiz. Place for logo -logo_placev = Vertic. Place for logo -top = top -bottom = bottom -center = center -left = left -right = right -none = none - -notselected = none - -linetype = Linetype -textstyle = Textstyle -linecolor = Linecolor -showhorizontalline = Show horizonal line -showverticalline = Show vertical line -textcolor = Textcolor -textsize = Textsize -font = Font -showpoints = Show points -showbackground = Show background -textshowbg = Show background -backgroundcolor = Backgroundcolor -bandwidthcolot = Bandwidthcolor -textbgcolor = Backgroundcolor -textorientation = Textorientation -linesize = Linesize -pointsize = Pointsize -bandwidth = Bandwidth -pointcolor = Pointcolor -showlines = Show lines -showlinelabel = Show label -showpointlabel = Show point label -labelfontface = Label: Font -labelfontcolor = Label: Color -labelfontsize = Label: Size -labelfontstyle = Label: Style -labelbgcolor = Label: Background Color -labelshowbg = Label: Show Background -horizontal = horizontal -vertical = vertical -showwidth = Show width -showlevel = Show waterlevel -showminimum = Show minimum -showmaximum = Show maximum -showborder = Show line -transparent = Transparency -transparency = Transparency -showarea = Show area -showarealabel = Show area label -showmiddleheight = Show middle depth -fillcolor = Fill Color -areabgcolor = Fill Color -areashowborder = Show area border -areashowbg = Show area background -areabordercolor = Border color -areatransparency = Tranparency -wsplgen_cat1 = Fill Color 0.0 <= DIFF < 1 -wsplgen_cat2 = Fill Color 1.0 <= DIFF < 2 -wsplgen_cat3 = Fill Color 2.0 <= DIFF < 3 -wsplgen_cat4 = Fill Color 3.0 <= DIFF < 4 -wsplgen_cat5 = Fill Color 4.0 <= DIFF - -# Manual Points Editor -addpoints = Add points -pointname = Name -removepoint = Remove -newpoint = New Point -standby = Creating Artifact ... please wait. -points = Points -editpoints = Edit Points -addWSP = Add Manual LS -addWSPButton = Add Manual LS -selection = Selection - -# Reference Curves -reference_curve = Reference Curve -reference_curve_normalized = Reduced Reference Curve -reference_startpoint = Point of reference -reference_endpoint = Point(s) of projection - -fix_deltawt_export = \u0394 W/t -select=Selected -add_date=Add - -fix_parameters_export = Adjusted coefficient -fix_parameters = CSV -sq_overview=Overview - -gauge_zero = GZG -gauge_q_unit = m\u00b3/s -gauge_river_info_link = Riverinfo -gauge_info_link = Gaugeinfo -gauge_url = https://flys-intern.intevation.de/PegelInfo/ -gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ -gauge_curve_link = Dischargecurve/-table -discharge_timeranges = DC-Timeranges -discharge_chart = W/Q-Preview - -measurement_station_type = Type of Measurement Station -measurement_station_operator = Operator -measurement_station_start_time = Observation Start Time -measurement_station_url = https://flys-intern.intevation.de/MessstellenInfo/ -measurement_station_info_link = Measurement Station Info -measurement_station_gauge_name = Reference Gauge - -# Get Feature Info Window -PATH = Path -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSImages.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.client; - -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.ImageResource; - - -/** - * This interface grants access to the images used in this application. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface FLYSImages extends ClientBundle { - - @Source("images/bfg_logo.gif") - ImageResource logoBfg(); - - @Source("images/flys_logo.gif") - ImageResource logoFlys(); - - @Source("images/FLYS_Karte.png") - ImageResource riverMap(); - - @Source("images/marker_red.png") - ImageResource markerRed (); - - @Source("images/marker_green.png") - ImageResource markerGreen (); - - @Source("images/loading.gif") - ImageResource loading(); - - @Source("images/downloadPNG.png") - ImageResource downloadPNG(); - - @Source("images/downloadPDF.png") - ImageResource downloadPDF(); - - @Source("images/downloadSVG.png") - ImageResource downloadSVG(); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSResources.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.client; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.TextResource; - - -/** - * A {@link ClientBundle} that is used to handle resources in this client. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface FLYSResources extends ClientBundle { - - public static final FLYSResources INSTANCE = - GWT.create(FLYSResources.class); - - @Source("config.xml") - public TextResource initialConfiguration(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/config.xml Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -<config> - <server>http://localhost:8181</server> - - <projectlist> - <!-- The interval to update the user's projects (in ms) --> - <update-interval>300000</update-interval> - </projectlist> -</config>
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/AdvanceHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.event; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface AdvanceHandler extends Serializable { - - public void onAdvance(String target); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/CollectionChangeEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package de.intevation.flys.client.client.event; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This events stores references to the old collection and the new one. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class CollectionChangeEvent { - - protected Collection oldCollection; - protected Collection newCollection; - - public CollectionChangeEvent(Collection old, Collection newArt) { - oldCollection = old; - newCollection = newArt; - } - - public Collection getOldValue() { - return oldCollection; - } - - public Collection getNewValue() { - return newCollection; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/CollectionChangeHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * Handler interface for CollectionChangeEvent events. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface CollectionChangeHandler { - - /** - * Called when a CollectionChangeEvent is fired. - * - * @param event The CollectionChangeEvent. - */ - public void onCollectionChange(CollectionChangeEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/DatacageDoubleClickHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -package de.intevation.flys.client.client.event; - -import de.intevation.flys.client.shared.model.ToLoad; - - -public interface DatacageDoubleClickHandler { - - void onDoubleClick(ToLoad toLoad); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/DatacageHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -package de.intevation.flys.client.client.event; - -import de.intevation.flys.client.shared.model.ToLoad; - -public interface DatacageHandler -{ - void toLoad(ToLoad toLoad); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/FilterHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface FilterHandler { - - void onFilterCriteriaChanged(StringFilterEvent event); - - void onFilterCriteriaChanged(RangeFilterEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasCollectionChangeHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasCollectionChangeHandlers { - - /** - * Adds a new CollectionChangeHandler. - * - * @param handler The new CollectionChangeHandler. - */ - public void addCollectionChangeHandler(CollectionChangeHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasOutputModesChangeHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasOutputModesChangeHandlers { - - /** - * Adds a new OutputModesChangeHandler. - * - * @param handler The new OutputModesChangeHandler. - */ - public void addOutputModesChangeHandler(OutputModesChangeHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasOutputParameterChangeHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasOutputParameterChangeHandlers { - - /** - * Registers a new OutputParameterChangeHandler. - * - * @param handler The new handler. - */ - void addOutputParameterChangeHandler(OutputParameterChangeHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasPanHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasPanHandlers { - - void addPanHandler(PanHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasParameterChangeHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasParameterChangeHandler { - - /** - * Adds a new ParameterChangeHandler. - * - * @param handler The new ParameterChangeHandler. - */ - public void addParameterChangeHandler(ParameterChangeHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasRedrawRequestHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * Implements function to add a RedrawRequestHandler. - */ -public interface HasRedrawRequestHandlers { - - /** - * Adds a new RedrawRequestHandler. - * - * @param handler The new RedrawRequestHandler - */ - public void addRedrawRequestHandler(RedrawRequestHandler rrh); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasStepBackHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.event; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasStepBackHandlers extends Serializable { - - public void addStepBackHandler(StepBackHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasStepForwardHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.event; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasStepForwardHandlers extends Serializable { - - public void addStepForwardHandler(StepForwardHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/HasZoomHandlers.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface HasZoomHandlers { - - void addZoomHandler(ZoomHandler handler); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/OnMoveEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class OnMoveEvent { - - public static final int TOP = 0; - public static final int UP = 1; - public static final int DOWN = 2; - public static final int BOTTOM = 3; - - - protected int type; - - - public OnMoveEvent(int type) { - this.type = type; - } - - - public int getType() { - return type; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/OnMoveHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface OnMoveHandler { - - void onMove(OnMoveEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/OutputModesChangeEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package de.intevation.flys.client.client.event; - -import de.intevation.flys.client.shared.model.OutputMode; - - -/** - * An event that is thrown if the output modes of a collection or an artifact - * have changed. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class OutputModesChangeEvent { - - protected OutputMode[] outs; - - - public OutputModesChangeEvent(OutputMode[] outs) { - this.outs = outs; - } - - - public OutputMode[] getOutputModes() { - return outs; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/OutputModesChangeHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * Handler interface for OutputModesChangeEvent events. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface OutputModesChangeHandler { - - /** - * Called when a OutputModesChangeEvent is fired. - * - * @param event The OutputModesChangeEvent. - */ - public void onOutputModesChange(OutputModesChangeEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/OutputParameterChangeEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class OutputParameterChangeEvent { - - public OutputParameterChangeEvent() { - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/OutputParameterChangeHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface OutputParameterChangeHandler { - - /** - * Called when the parameter of an output have changed. E.g. when the state - * of themes in a theme panel changed. - * - * @param event The event that is fired. - */ - void onOutputParameterChanged(OutputParameterChangeEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/PanEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class PanEvent { - - protected int[] startPos; - protected int[] endPos; - - - public PanEvent(int[] startPos, int[] endPos) { - this.startPos = startPos; - this.endPos = endPos; - } - - - public int[] getStartPos() { - return startPos; - } - - - public int[] getEndPos() { - return endPos; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/PanHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface PanHandler { - - void onPan(PanEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/ParameterChangeEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package de.intevation.flys.client.client.event; - -import de.intevation.flys.client.shared.model.Artifact; - - -/** - * This events stores references to the old artifact and the new one. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ParameterChangeEvent { - - public static enum Type { - FORWARD, BACK - } - - - protected Artifact oldArtifact; - protected Artifact newArtifact; - - protected Type type; - - - public ParameterChangeEvent(Artifact old, Artifact newArt) { - this(old, newArt, Type.FORWARD); - } - - - public ParameterChangeEvent(Artifact oArt, Artifact nArt, Type type) { - oldArtifact = oArt; - newArtifact = nArt; - this.type = type; - } - - - public Artifact getOldValue() { - return oldArtifact; - } - - public Artifact getNewValue() { - return newArtifact; - } - - public Type getType() { - return type; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/ParameterChangeHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * Handler interface for ParameterChangeEvent events. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface ParameterChangeHandler { - - /** - * Called when a ParameterChangeEvent is fired. - * - * @param event The ParameterChangeEvent. - */ - public void onParameterChange(ParameterChangeEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/RangeFilterEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -package de.intevation.flys.client.client.event; - -import com.google.gwt.i18n.client.NumberFormat; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class RangeFilterEvent { - - protected Float from; - protected Float to; - - - public RangeFilterEvent(String from, String to) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double d; - - try { - d = nf.parse(from); - this.from = Float.valueOf(String.valueOf(d)); - } - catch(NumberFormatException nfe) { - this.from = Float.NaN; - } - try { - d = nf.parse(to); - this.to = Float.valueOf(String.valueOf(d)); - } - catch(NumberFormatException nfe) { - this.to = Float.NaN; - } - } - - - public Float getFrom() { - return this.from; - } - - - public Float getTo() { - return this.to; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/RedrawRequestEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.event; - - -public class RedrawRequestEvent { - - public static enum Type { - RESET, DEFAULT - } - - - protected Type type; - - - public RedrawRequestEvent() { - this.type = Type.DEFAULT; - } - - - public RedrawRequestEvent(Type type) { - this.type = type; - } - - - public Type getType() { - return type; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/RedrawRequestHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * Handler interface for RedrawRequests. - */ -public interface RedrawRequestHandler { - - /** - * Handle the redraw request. - */ - public void onRedrawRequest(RedrawRequestEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -package de.intevation.flys.client.client.event; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class StepBackEvent implements Serializable { - - private static final long serialVersionUID = 7895180143662002198L; - - /** The identifier of the target state.*/ - protected String target; - - - /** - * Creates a new StepBackEvent with the identifier of the target state. - * - * @param target The identifier of the target state. - */ - public StepBackEvent(String target) { - this.target = target; - } - - - /** - * A method to retrieve the target identifier. - * - * @return the target identifier. - */ - public String getTarget() { - return target; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.event; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface StepBackHandler extends Serializable { - - public void onStepBack(StepBackEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/StepForwardEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -package de.intevation.flys.client.client.event; - -import de.intevation.flys.client.shared.model.Data; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class StepForwardEvent implements Serializable { - - private static final long serialVersionUID = -5527511690213770954L; - - /** The selected data.*/ - protected Data[] data; - - /** - * Creates a new StepForwardEvent with the Data that has been selected in - * the UI. - * - * @param data The selected data. - */ - public StepForwardEvent(Data[] data) { - this.data = data; - } - - - /** - * A method to retrieve the data stored in the event. - * - * @return the data. - */ - public Data[] getData() { - return data; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/StepForwardHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.event; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface StepForwardHandler extends Serializable { - - public void onStepForward(StepForwardEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/StringFilterEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.event; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class StringFilterEvent { - - protected String filter; - - - public StringFilterEvent(String filter) { - this.filter = filter; - } - - - public String getFilter() { - return filter; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/ZoomEvent.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ZoomEvent { - - protected int xmin; - protected int ymin; - - protected int xmax; - protected int ymax; - - - public ZoomEvent(int xmin, int ymin, int xmax, int ymax) { - this.xmin = xmin; - this.xmax = xmax; - this.ymin = ymin; - this.ymax = ymax; - } - - - public int getStartX() { - return xmin; - } - - - public int getEndX() { - return xmax; - } - - - public int getStartY() { - return ymin; - } - - - public int getEndY() { - return ymax; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/ZoomHandler.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package de.intevation.flys.client.client.event; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface ZoomHandler { - - void onZoom(ZoomEvent event); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/AddArtifactService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes the service to add an existing artifact to an - * existing collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("add-artifact") -public interface AddArtifactService extends RemoteService { - - /** - * Adds an artifact to a collection. - * - * @param collection The Collection that should be extended. - * @param artifact The artifact that should be added. - * @param url The url of the artifact server. - * - * @return the Collection after the operation. - */ - Collection add( - Collection collection, - Artifact artifact, - String locale) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/AddArtifactServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface AddArtifactServiceAsync { - - public void add( - Collection collection, - Artifact artifact, - String locale, - AsyncCallback<Collection> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/AdvanceService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; - -/** - * This interface provides artifact specific operation ADVANCE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("advance") -public interface AdvanceService extends RemoteService { - - /** - * This method inserts new data into the an existing artifact. - * - * @param serverUrl The url of the artifact server. - * @param locale The locale used for the request. - * @param artifact The artifact. - * @param target The identifier of the target state. - * - * @return the artifact which description might have been changed. - */ - public Artifact advance( - String locale, - Artifact artifact, - String target) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/AdvanceServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; - - -/** - * This interface provides artifact specific operation ADVANCE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface AdvanceServiceAsync { - - public void advance( - String locale, - Artifact artifact, - String target, - AsyncCallback<Artifact> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; - -import de.intevation.flys.client.shared.model.Recommendation; - -/** - * This interface provides artifact specific services as CREATE, DESCRIBE, FEED, - * ADVANCE and OUT. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("artifact") -public interface ArtifactService extends RemoteService { - - /** - * This method creates a new artifact based on the given <i>factory</i>. - * - * @param serverUrl The url of the artifact server. - * @param locale The locale used for the request. - * @param factory The factory that should be used for the artifact creation. - * - * @return the new artifact. - */ - public Artifact create( - String locale, - String factory, - Recommendation recommendation - ) throws ServerException; - - /** - * Create a new GaugeDischageCurveArtifact - * - * @param collection the collection to add the artifact to - * @param river the river - * @param gaugeref reference id of the gauge - */ - public Artifact createGaugeDischargeCurveArtifact( - Collection collection, - String locale, - String river, - Long gaugeref - ) throws ServerException; - - /** - * Create a new SQRelationArtifact - * - * @param collection the collection to add the artifact to - * @param river the river - * @param measurementStation the measurement station id - */ - public Artifact createSQRelationArtifact( - Collection collection, - String locale, - String river, - int measurementStation - ) throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; - -import de.intevation.flys.client.shared.model.Recommendation; - -/** - * This interface provides artifact specific services as CREATE, DESCRIBE, FEED, - * ADVANCE and OUT. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface ArtifactServiceAsync { - - public void create( - String locale, - String factory, - Recommendation recommendation, - AsyncCallback<Artifact> callback); - - public void createGaugeDischargeCurveArtifact( - Collection collection, - String locale, - String river, - Long gaugeref, - AsyncCallback<Artifact> callback - ); - - public void createSQRelationArtifact( - Collection collection, - String locale, - String river, - int measurementStation, - AsyncCallback<Artifact> callback - ); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CSVExportService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import java.util.List; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -/** - * This service is used to fetch a list of DistanceInfoObjects from artifact - * server for a specific river. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@RemoteServiceRelativePath("csv") -public interface CSVExportService extends RemoteService { - - /** - * This method returns a list of DistanceInfoObjects for a specific river. - */ - List<String[]> getCSV( - String locale, - String uuid, - String name) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CSVExportServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import java.util.List; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface CSVExportServiceAsync { - - void getCSV( - String locale, - String uuid, - String name, - AsyncCallback<List<String[]>> cb); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.ChartInfo; -import de.intevation.flys.client.shared.model.Collection; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("chart-info") -public interface ChartInfoService extends RemoteService { - - ChartInfo getChartInfo( - Collection collection, - String locale, - String type, - Map<String, String> attr) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.ChartInfo; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface ChartInfoServiceAsync { - - public void getChartInfo( - Collection collection, - String locale, - String type, - Map<String, String> attr, - AsyncCallback<ChartInfo> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionAttributeService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("collection-attribute") -public interface CollectionAttributeService extends RemoteService { - - Collection update(Collection collection, String locale) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionAttributeServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface CollectionAttributeServiceAsync { - - void update( - Collection collection, - String locale, - AsyncCallback<Collection> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItemAttribute; - -/** - * This interface provides a method to retrieve an artifact based on its uuid. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@RemoteServiceRelativePath("collection-item-attribute") -public interface CollectionItemAttributeService extends RemoteService { - - CollectionItemAttribute getCollectionItemAttribute( - Collection collection, - String artifact, - String locale) - throws ServerException; - - void setCollectionItemAttribute( - Collection collection, - String artifact, - String locale, - CollectionItemAttribute attribute) - throws ServerException; - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItemAttribute; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface CollectionItemAttributeServiceAsync { - - public void getCollectionItemAttribute( - Collection collection, - String artifact, - String locale, - AsyncCallback<CollectionItemAttribute> callback); - - public void setCollectionItemAttribute( - Collection collection, - String artifact, - String locale, - CollectionItemAttribute attributes, - AsyncCallback<Void> callback); - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CreateCollectionService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes the service for creating new collections. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("create-collection") -public interface CreateCollectionService extends RemoteService { - - /** - * This method creates a new collection in the artifact server and returns - * the uuid of this collection. - * - * @return the uuid of the created collection. - */ - Collection create(String locale, String ownerId) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CreateCollectionServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes the service for creating new collections. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface CreateCollectionServiceAsync { - - void create( - String locale, - String owner, - AsyncCallback<Collection> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CrossSectionKMService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -/** - * This interface provides access to CrossSectionKMService . - */ -@RemoteServiceRelativePath("cross-section-km") -public interface CrossSectionKMService extends RemoteService { - - /** - * @param serverUrl The url of the artifact server. - * @param locale The locale used for the request. - * @param artifact The artifact. - * @param data The data that should be inserted. - * - * @return the artifact which description might have been changed. - */ - public Map<Integer,Double[]> getCrossSectionKMs( - String locale, - Map<Integer, Double> data, - int nNeightbours) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CrossSectionKMServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -/** - * Talk-to interface for crosssectionkm service. - */ -public interface CrossSectionKMServiceAsync { - - void getCrossSectionKMs( - String locale, - Map<Integer, Double> data, - int nNeighbours, - AsyncCallback<Map<Integer, Double[]>> cb); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DeleteCollectionService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes the service to add an existing artifact to an - * existing collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("delete-collection") -public interface DeleteCollectionService extends RemoteService { - - /** - * Deletes a collection. - * - * @param collection The Collection that should be deleted. - */ - void delete(Collection collection) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DeleteCollectionServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface DeleteCollectionServiceAsync { - - public void delete( - Collection collection, - AsyncCallback<Void> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeArtifactService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; - -/** - * This interface provides artifact specific operation DESCRIBE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("describe") -public interface DescribeArtifactService extends RemoteService { - - /** - * This method inserts new data into the an existing artifact. - * - * @param url The url of the artifact server. - * @param locale The locale used for the request. - * @param artifact The artifact. - * - * @return the artifact which description might have been changed. - */ - public Artifact describe( - String locale, - Artifact artifact) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeArtifactServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; - - -/** - * This interface provides artifact specific operation DESCRIBE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface DescribeArtifactServiceAsync { - - public void describe( - String locale, - Artifact artifact, - AsyncCallback<Artifact> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeCollectionService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This service describes an operation the fetches the DESCRIBE document of a - * specific collection and returns a Collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("describe-collection") -public interface DescribeCollectionService extends RemoteService { - - /** - * Adds an artifact to a collection. - * - * @param uuid The uuid of the desired collection. - * @param url The url of the artifact server. - * @param locale The name of the locale used for the request. - * - * @return the Collection after the operation. - */ - Collection describe(String uuid, String locale) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeCollectionServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface DescribeCollectionServiceAsync { - - public void describe( - String uuid, - String locale, - AsyncCallback<Collection> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DischargeInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.DischargeInfoObject; - -/** - * This service is used to fetch a list of DischargeInfoObjects from artifact - * server for a specific gauge. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@RemoteServiceRelativePath("dischargeinfo") -public interface DischargeInfoService extends RemoteService { - - /** - * This method returns a list of DischargeInfoObjects for a specific gauge. - */ - DischargeInfoObject[] getDischargeInfo( - String locale, - long gauge) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DischargeInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.DischargeInfoObject; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface DischargeInfoServiceAsync { - - void getDischargeInfo( - String locale, - long gauge, - AsyncCallback<DischargeInfoObject[]> cb); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DistanceInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.DistanceInfoObject; - -/** - * This service is used to fetch a list of DistanceInfoObjects from artifact - * server for a specific river. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("distanceinfo") -public interface DistanceInfoService extends RemoteService { - - /** - * This method returns a list of DistanceInfoObjects for a specific river. - */ - DistanceInfoObject[] getDistanceInfo( - String locale, - String river) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/DistanceInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.DistanceInfoObject; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface DistanceInfoServiceAsync { - - void getDistanceInfo( - String locale, - String river, - AsyncCallback<DistanceInfoObject[]> cb); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FeedService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.List; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Data; - -/** - * This interface provides artifact specific operation FEED. - */ -@RemoteServiceRelativePath("feed") -public interface FeedService extends RemoteService { - - /** - * Inserts new data into an existing artifact. - * - * @param locale The locale used for the request. - * @param artifact The artifact. - * @param data The data that should be inserted. - * - * @return the artifact which description might have been changed. - */ - public Artifact feed( - String locale, - Artifact artifact, - Data[] data) - throws ServerException; - - - /** - * Inserts (the same) new data into existing artifacts. - * - * @param locale The locale used for the request. - * @param artifact The artifact. - * @param data The data that should be inserted. - * - * @return the artifact which description might have been changed. - */ - public List<Artifact> feedMany( - String locale, - List<Artifact> artifacts, - Data[] data) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FeedServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.List; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Data; - - -/** - * This interface provides artifact specific operation FEED. - */ -public interface FeedServiceAsync { - - /** - * Inserts new data into an existing artifact. - * - * @param locale The locale used for the request. - * @param artifact The artifact. - * @param data The data that should be inserted. - */ - public void feed( - String locale, - Artifact artifact, - Data[] data, - AsyncCallback<Artifact> callback); - - /** - * Inserts (the same) new data into existing artifacts. - * - * @param locale The locale used for the request. - * @param artifact The artifact. - * @param data The data that should be inserted. - */ - public void feedMany( - String locale, - List<Artifact> artifacts, - Data[] data, - AsyncCallback<List<Artifact>> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -import de.intevation.flys.client.shared.model.FixingsOverviewInfo; - -@RemoteServiceRelativePath("fixings-overview") -public interface FixingsOverviewService extends RemoteService { - - FixingsOverviewInfo generateOverview( - String locale, - String uuid, - String filter, - boolean checkbox, - String callback - ) throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.FixingsOverviewInfo; - -public interface FixingsOverviewServiceAsync { - - void generateOverview( - String locale, - String uuid, - String filter, - boolean checkbox, - String callbackFunction, - AsyncCallback<FixingsOverviewInfo> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GCService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Capabilities; - - -@RemoteServiceRelativePath("getcapabilities") -public interface GCService extends RemoteService { - - public Capabilities query(String path) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GCServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Capabilities; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface GCServiceAsync { - - void query(String path, AsyncCallback<Capabilities> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.List; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.FeatureInfoResponse; -import de.intevation.flys.client.shared.model.Theme; - - -@RemoteServiceRelativePath("getfeatureinfo") -public interface GFIService extends RemoteService { - - public FeatureInfoResponse query( - Theme theme, - String format, - String bbox, - String projection, - int height, - int width, - int x, - int y - ) throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.List; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.FeatureInfoResponse; -import de.intevation.flys.client.shared.model.Theme; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface GFIServiceAsync { - - void query( - Theme theme, - String format, - String bbox, - String projection, - int height, - int width, - int x, - int y, - AsyncCallback<FeatureInfoResponse> callback - ); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GaugeInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.List; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Gauge; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@RemoteServiceRelativePath("gaugeinfo") -public interface GaugeInfoService extends RemoteService { - - List<Gauge> getGaugeInfo(String river, String refnumber) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GaugeInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.List; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Gauge; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface GaugeInfoServiceAsync { - - void getGaugeInfo( - String river, - String refnumber, - AsyncCallback<List<Gauge>> gauges); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GetArtifactService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; - -/** - * This interface provides a method to retrieve an artifact based on its uuid. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("getartifact") -public interface GetArtifactService extends RemoteService { - - /** - * This method inserts new data into the an existing artifact. - * - * @param url The url of the artifact server. - * @param locale The string representation of a locale that is used for the - * request. - * @param uuid The artifact's identifier. - * @param hash The artifact's hash. - * - * @return the artifact. - */ - Artifact getArtifact(String locale, String uuid, String hash) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GetArtifactServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface GetArtifactServiceAsync { - - public void getArtifact( - String locale, - String uuid, - String hash, - AsyncCallback<Artifact> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/LoadArtifactService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Recommendation; - -/** @see LoadArtifactServiceImpl */ -@RemoteServiceRelativePath("load-artifact") -public interface LoadArtifactService extends RemoteService { - - /** @see LoadArtifactServiceImpl */ - Artifact load( - Collection parent, - Recommendation recom, - String factory, - String locale) - throws ServerException; - - /** @see LoadArtifactServiceImpl */ - Artifact[] loadMany( - Collection parent, - Recommendation[] recom, - String factory, - String locale) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/LoadArtifactServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Recommendation; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface LoadArtifactServiceAsync { - - public void load( - Collection parent, - Recommendation recom, - String factory, - String locale, - AsyncCallback<Artifact> callback); - - public void loadMany( - Collection parent, - Recommendation[] recom, - String factory, - String locale, - AsyncCallback<Artifact[]> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.MapInfo; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("map-info") -public interface MapInfoService extends RemoteService { - - MapInfo getMapInfo(String locale, String river) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.MapInfo; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface MapInfoServiceAsync { - - public void getMapInfo( - String locale, - String river, - AsyncCallback<MapInfo> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.MapConfig; - - -/** - * This interface describes the service to add an existing artifact to an - * existing collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("map") -public interface MapOutputService extends RemoteService { - - MapConfig doOut(Collection collection) throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.MapConfig; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface MapOutputServiceAsync { - - public void doOut(Collection collection, AsyncCallback<MapConfig> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapUrlService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -/** - * This interface describes the service to get wms urls for UESK and new maps. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@RemoteServiceRelativePath("map-urls") -public interface MapUrlService extends RemoteService { - - Map<String, String> getUrls() throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapUrlServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.AsyncCallback; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface MapUrlServiceAsync { - - public void getUrls(AsyncCallback<Map<String, String> > callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -import de.intevation.flys.client.shared.model.DataCageTree; - -@RemoteServiceRelativePath("meta-data") -public interface MetaDataService extends RemoteService -{ - DataCageTree getMetaData( - String locale, - String artifactId, - String userId, - String outs, - String parameters - ) throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.DataCageTree; - -public interface MetaDataServiceAsync { - void getMetaData( - String locale, - String artifactId, - String userId, - String outs, - String parameters, - AsyncCallback<DataCageTree> cb); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : - -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ModuleService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Module; - -@RemoteServiceRelativePath("modules") -public interface ModuleService extends RemoteService { - - /** - * Returns the list of available modules of a user - * - * @param locale The locale used for the request - * @return a String array of all available modules - * - */ - public Module[] list(String locale) throws ServerException; -} - -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ModuleServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Module; - -public interface ModuleServiceAsync { - - public void list(String locale, - AsyncCallback<Module[]> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/RemoveArtifactService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes the service to remove an existing artifact to an - * existing collection. - * - */ -@RemoteServiceRelativePath("remove-artifact") -public interface RemoveArtifactService extends RemoteService { - - /** - * Removes an artifact from a collection. - * - * @param collection The Collection that should be modified. - * @param artifactId The artifact that should be removed. - * @param url The url of the artifact server. - * @param locale locae to use (for localized responses). - * - * @return the Collection after the operation. - */ - Collection remove( - Collection collection, - String artifactId, - String locale) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/RemoveArtifactServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - -/** - * @see RemoveArtifactService, RemoveArtifactServiceImpl - */ -public interface RemoveArtifactServiceAsync { - - public void remove( - Collection collection, - String artifactId, - String locale, - AsyncCallback<Collection> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ReportService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -@RemoteServiceRelativePath("report") -public interface ReportService -extends RemoteService -{ - String report( - String collectionId, - String locale, - String out); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ReportServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -public interface ReportServiceAsync -{ - void report( - String collectionId, - String locale, - String out, - AsyncCallback<String> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.RiverInfo; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -@RemoteServiceRelativePath("riverinfo") -public interface RiverInfoService extends RemoteService { - - /** - * Returns a RiverInfo object with GaugeInfos - */ - public RiverInfo getGauges(String river) - throws ServerException; - - /** - * Returns a RiverInfo object with MeasurementStations - */ - public RiverInfo getMeasurementStations(String river) - throws ServerException; - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.RiverInfo; - - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public interface RiverInfoServiceAsync { - - public void getGauges(String river, AsyncCallback<RiverInfo> callback); - - public void getMeasurementStations(String river, - AsyncCallback<RiverInfo> callback); -} - -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.River; - -/** - * This interface provides a method to list the supported rivers of the artifact - * server. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("rivers") -public interface RiverService extends RemoteService { - - /** - * This method returns a list of rivers provided by the artifact server. - * - * @param locale The locale used for the request. - * - * @return a list of rivers provided by the artifact server. - */ - public River[] list(String locale) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.River; - - -/** - * This interface provides a method to list the supported rivers of the artifact - * server. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface RiverServiceAsync { - - public void list( - String locale, - AsyncCallback<River[]> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/SedimentLoadInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; - -/** - * This service is used to fetch a list of SedimentLoadInfoObjects from artifact - * server for a specific river. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@RemoteServiceRelativePath("sedimentloadinfo") -public interface SedimentLoadInfoService extends RemoteService { - - /** - * This method returns a list of SedimentLoadInfoObjects for a specific river. - */ - SedimentLoadInfoObject[] getSedimentLoadInfo( - String locale, - String river, - String type, - double startKm, - double endKm) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/SedimentLoadInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface SedimentLoadInfoServiceAsync { - - void getSedimentLoadInfo( - String locale, - String river, - String type, - double startKm, - double endKm, - AsyncCallback<SedimentLoadInfoObject[]> cb); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/SetCollectionNameService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes the service to add an existing artifact to an - * existing collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("set-collectionname") -public interface SetCollectionNameService extends RemoteService { - - /** - * Set the name of a collection. - * - * @param collection The Collection that should be extended. - */ - void setName(Collection collection) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/SetCollectionNameServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface SetCollectionNameServiceAsync { - - public void setName( - Collection collection, - AsyncCallback<Void> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/SetCollectionTTLService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("set-collectionttl") -public interface SetCollectionTTLService extends RemoteService { - - void setTTL(Collection c) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/SetCollectionTTLServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface SetCollectionTTLServiceAsync { - - public void setTTL( - Collection collection, - AsyncCallback<Void> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/StepForwardService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Data; - -/** - * This interface provides artifact specific operations FEED and ADVANCE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("forward") -public interface StepForwardService extends RemoteService { - - /** - * This method inserts new data into the an existing artifact and - * advances its state. - * - * @param locale The locale used for the request. - * @param artifact The artifact. - * @param data The data that should be inserted. - * - * @return the artifact which description might have been changed. - */ - public Artifact go( - String locale, - Artifact artifact, - Data[] data) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/StepForwardServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Data; - - -/** - * This interface provides artifact specific operation FEED and ADVANCE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface StepForwardServiceAsync { - - public void go( - String locale, - Artifact artifact, - Data[] data, - AsyncCallback<Artifact> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ThemeListingService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Style; - -/** - * This interface provides a method to list themes filtered by name. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund.Renkert</a> - */ -@RemoteServiceRelativePath("themelisting") -public interface ThemeListingService extends RemoteService { - - /** - * This method returns a list of themes filtered by name. - * - * @param locale The locale used for the request. - * - * @return a list of themes provided by the artifact server. - */ - public Map<String, Style> list(String locale, String name) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ThemeListingServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package de.intevation.flys.client.client.services; - -import java.util.Map; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Style; - - -/** - * This interface provides a method to list themes filterd by name. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface ThemeListingServiceAsync { - - public void list( - String locale, - String name, - AsyncCallback<Map<String, Style>> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserCollectionsService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes a method that retrieves a list of Collections owned - * by a specified user. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("user-collections") -public interface UserCollectionsService extends RemoteService { - - /** - * This method retrieves the user that is currently logged in. - * - * @param serverUrl The url of the artifact server. - * @param locale The locale used for the request object. - * @param userid The identifier of the owner. - * - * @return the current {@link User}. - */ - Collection[] getUserCollections(String locale, String userid); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserCollectionsServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.Collection; - - -/** - * This interface describes a method that retrieves a list of Collections owned - * by a specified user. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface UserCollectionsServiceAsync { - - void getUserCollections( - String locale, - String userid, - AsyncCallback<Collection[]> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.AuthenticationException; -import de.intevation.flys.client.shared.model.User; - - -/** - * This interface describes services for the user. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -@RemoteServiceRelativePath("user") -public interface UserService extends RemoteService { - - /** - * This method retrieves the user that is currently logged in. - * - * @param locale The current locale. - * - * @return the current {@link User}. - */ - User getCurrentUser(String locale) - throws AuthenticationException; - - /** - * Removes the current user object from the session - */ - void logoutCurrentUser(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.User; - - -/** - * This interface describes services for the user. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface UserServiceAsync { - - void getCurrentUser( - String locale, - AsyncCallback<User> callback); - - void logoutCurrentUser(AsyncCallback<Void> callback); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/WQInfoService.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.WQInfoObject; - -/** - * This service is used to fetch a list of DistanceInfoObjects from artifact - * server for a specific river. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@RemoteServiceRelativePath("mainvalues") -public interface WQInfoService extends RemoteService { - - /** - * This method returns a list of DistanceInfoObjects for a specific river. - */ - WQInfoObject[] getWQInfo( - String locale, - String river, - double start, - double end) - throws ServerException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/WQInfoServiceAsync.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.client.services; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.shared.model.WQInfoObject; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface WQInfoServiceAsync { - - void getWQInfo( - String locale, - String river, - double start, - double end, - AsyncCallback<WQInfoObject[]> cb); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,341 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.HasStepBackHandlers; -import de.intevation.flys.client.client.event.HasStepForwardHandlers; -import de.intevation.flys.client.client.event.StepBackEvent; -import de.intevation.flys.client.client.event.StepBackHandler; -import de.intevation.flys.client.client.event.StepForwardEvent; -import de.intevation.flys.client.client.event.StepForwardHandler; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.List; - - -/** - * An abstract UIProvider that provides some basic methods. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public abstract class AbstractUIProvider -implements UIProvider, HasStepForwardHandlers, ClickHandler, - HasStepBackHandlers -{ - private static final long serialVersionUID = -1610874613377494184L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** The StepForwardHandlers. */ - protected List<StepForwardHandler> forwardHandlers; - - /** The StepForwardHandlers. */ - protected List<StepBackHandler> backHandlers; - - /** The container that is used to position helper widgets. */ - protected VLayout helperContainer; - - /** The artifact that contains status information. */ - protected Artifact artifact; - - /** The Collection. */ - protected Collection collection; - - /** The ParameterList. */ - protected ParameterList parameterList; - - /** - * Creates a new UIProvider instance of this class. - */ - public AbstractUIProvider() { - forwardHandlers = new ArrayList<StepForwardHandler>(); - backHandlers = new ArrayList<StepBackHandler>(); - } - - - /** - * Appends a StepBackHandler that wants to listen to StepBackEvents. - * - * @param handler A new StepBackHandler. - */ - @Override - public void addStepBackHandler(StepBackHandler handler) { - if (handler != null) { - backHandlers.add(handler); - } - } - - - /** - * Appends a StepForwardHandler that wants to listen to StepForwardEvents. - * - * @param handler A new StepForwardHandler. - */ - @Override - public void addStepForwardHandler(StepForwardHandler handler) { - if (handler != null) { - forwardHandlers.add(handler); - } - } - - - /** - * This method is called after the user has clicked one of the buttons to - * step back to a previous state. - * - * @param e The StepBackEvent. - */ - protected void fireStepBackEvent(StepBackEvent e) { - GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: " + backHandlers.size()); - for (StepBackHandler handler: backHandlers) { - handler.onStepBack(e); - } - } - - - /** - * This method is called after the user has clicked on the 'next' button to - * step to the next state. - * - * @param e The StepForwardEvent. - */ - protected void fireStepForwardEvent(StepForwardEvent e) { - GWT.log("AbstractUIProvider - fireStepForwardEvent() handlers: " + forwardHandlers.size()); - for (StepForwardHandler handler: forwardHandlers) { - handler.onStepForward(e); - } - } - - - /** - * This method is used to listen to click events on the 'next' button. The - * fireStepForwardEvent() method is called here. - * - * @param e The click event. - */ - @Override - public void onClick(ClickEvent e) { - List<String> errors = validate(); - if (errors == null || errors.isEmpty()) { - Data[] data = getData(); - fireStepForwardEvent(new StepForwardEvent(data)); - } - else { - showErrors(errors); - } - } - - - protected void showErrors(List<String> errors) { - StringBuilder sb = new StringBuilder(); - - for (String error: errors) { - sb.append(error); - sb.append("<br>"); - } - - SC.warn(sb.toString()); - } - - - /** - * Creates the 'next' button to step forward to the next state. - * - * @return the 'next' button. - */ - protected Canvas getNextButton() { - Button next = new Button(MSG.buttonNext()); - next.addClickHandler(this); - - return next; - } - - - @Override - public Canvas createHelpLink(DataList dataList, Data data) { - String iUrl = GWT.getHostPageBaseURL() + MSG.getFeatureInfo(); - String helpUrl = dataList.getHelpText(); - - return new ImgLink(iUrl, helpUrl, 30, 30, true); - } - - - /** - * Creates the 'back' button to step back to a previous state. - * - * @param targetState The identifier of the target state. - * - * @return the 'back' button. - */ - protected Canvas getBackButton(final String targetState) { - String url = GWT.getHostPageBaseURL() + MSG.imageBack(); - Img back = new Img(url, 16, 16); - - back.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - fireStepBackEvent(new StepBackEvent(targetState)); - } - }); - - return back; - } - - - /** - * This method injects a container that is used to position helper widgets. - * - * @param helperContainer A container that is used to position helper - * widgets. - */ - @Override - public void setContainer(VLayout helperContainer) { - this.helperContainer = helperContainer; - } - - - /** - * This method injects an artifact that contains the status information. - * - * @param art An artifact containing status information. - */ - @Override - public void setArtifact(Artifact art) { - this.artifact = art; - } - - - @Override - public void setCollection(Collection collection) { - this.collection = collection; - } - - - @Override - public void setParameterList(ParameterList list) { - this.parameterList = list; - } - - - public Collection getCollection() { - return collection; - } - - - /** - * This method greps the Data with name <i>name</i> from the list and - * returns it. - * - * @param items A list of Data. - * @param name The name of the Data that we are searching for. - * - * @return the Data with the name <i>name</i>. - */ - protected Data getData(List<Data> data, String name) { - for (Data d: data) { - if (name.equals(d.getLabel())) { - return d; - } - } - - return null; - } - - - protected String getDataValue(String state, String name) { - ArtifactDescription desc = artifact.getArtifactDescription(); - - DataList[] old = desc.getOldData(); - - for (DataList list: old) { - if (list == null) { - continue; - } - Data d = getData(list.getAll(), name); - - if (d != null) { - return d.getItems()[0].getStringValue(); - } - } - - return null; - } - - /** - * This method greps the DataItem with name <i>name</i> from the list and - * returns it. - * - * @param items A list of DataItems. - * @param name The name of the DataItem that we are searching for. - * - * @return the DataItem with the name <i>name</i>. - */ - protected DataItem getDataItem(DataItem[] items, String name) { - for (DataItem item: items) { - if (name.equals(item.getLabel())) { - return item; - } - } - - return null; - } - - - public List<String> validate() { - return new ArrayList<String>(); // FIXME: What's this? - } - - - /** Create simple DefaultData with single DataItem inside. */ - public static DefaultData createDataArray(String name, String value) { - DataItem item = new DefaultDataItem( - name, - name, - value); - - return new DefaultData(name, - null, - null, - new DataItem[] {item}); - } - - - /** - * This method needs to be implemented by concrete subclasses. It should - * create a new Canvas object with a representation of <i>data</i>. - * - * @param data The data that should be displayed. - * - * @return a Canvas object that displays <i>data</i>. - */ - @Override - public abstract Canvas create(DataList data); - - - /** - * This method needs to be implemented by concrete subclasses. It should - * return the selected data. - * - * @return the selected data. - */ - protected abstract Data[] getData(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.validator.CustomValidator; -import com.smartgwt.client.widgets.form.validator.Validator; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class AutoIntegerPanel extends TextProvider { - - private static final long serialVersionUID = -6525461829035465820L; - - public static final String FIELD_NAME = "integer_field"; - - public static final String FIELD_DEFAULT_VALUE = "auto"; - - - protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected String dataName; - - - @Override - public Canvas create(DataList dataList) { - Data data = dataList.get(0); - this.dataName = data.getLabel(); - - Canvas label = new Label(data.getDescription()); - Canvas form = createForm(getTitle()); - Canvas submit = getNextButton(); - - VLayout layout = new VLayout(); - layout.setHeight(35); - label.setHeight(35); - - layout.addMember(label); - layout.addMember(form); - layout.addMember(submit); - layout.setMembersMargin(10); - - initDefaultValues(dataList); - - return layout; - } - - - @Override - protected void initDefaultValues(DataList dataList) { - super.initDefaultValues(dataList); - - String def = getValueAsString(); - - if (def == null || def.length() == 0) { - form.setValue(getFieldName(), FIELD_DEFAULT_VALUE); - } - } - - - protected String getTitle() { - return MSG.uesk_profile_distance(); - } - - - @Override - protected String getDataName() { - return dataName; - } - - - @Override - protected String getValueAsString() { - String v = (String) form.getValue(getFieldName()); - return v.toLowerCase(); - } - - - @Override - protected Validator getValidator() { - Validator v = new AutoIntegerValidator(); - v.setValidateOnChange(false); - - return v; - } - - - public class AutoIntegerValidator extends CustomValidator { - @Override - protected boolean condition(Object value) { - String v = (String) value; - - if (v == null || v.length() == 0) { - return false; - } - - if (v.trim().equalsIgnoreCase("auto")) { - return true; - } - - try { - Integer.parseInt(v); - return true; - } - catch (NumberFormatException nfe) { - return false; - } - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/BooleanPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.types.FieldType; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class BooleanPanel extends TextProvider { - - private static final long serialVersionUID = -8448442865635399232L; - - public static final String FIELD_NAME = "boolean_field"; - public static final int TITLE_WIDTH = 0; - - protected String dataName; - - - @Override - public Canvas create(DataList dataList) { - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - this.dataName = data.getLabel(); - - VLayout layout = new VLayout(); - Label label = new Label(data.getDescription()); - Canvas form = createForm(getTitle(items[0])); - - layout.setMembersMargin(10); - layout.setHeight(35); - label.setHeight(35); - - layout.addMember(label); - layout.addMember(form); - layout.addMember(getNextButton()); - layout.setMembersMargin(10); - - initDefaultValues(dataList); - - return layout; - } - - - protected String getTitle(DataItem item) { - return item.getLabel(); - } - - - @Override - protected void initDefaultValues(DataList dataList) { - Data data = dataList.get(0); - DataItem item = data.getDefault(); - - String value = item.getStringValue(); - Boolean bool = Boolean.valueOf(value); - - if (bool) { - form.setValue(getFieldName(), bool); - } - } - - - @Override - protected FieldType getFieldType() { - return FieldType.BOOLEAN; - } - - - @Override - protected String getFieldName() { - return FIELD_NAME; - } - - - @Override - protected String getDataName() { - return dataName; - } - - - @Override - protected String getValueAsString() { - Boolean aBool = (Boolean) form.getValue(getFieldName()); - - return aBool != null ? aBool.toString() : "false"; - } - - - @Override - protected int getTitleWidth() { - return TITLE_WIDTH; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,790 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.SC; - -import com.smartgwt.client.widgets.Window; - -import com.smartgwt.client.widgets.events.CloseClickEvent; -import com.smartgwt.client.widgets.events.CloseClickHandler; - -import com.smartgwt.client.widgets.layout.Layout; -import com.smartgwt.client.widgets.layout.VLayout; - -import com.smartgwt.client.widgets.tab.TabSet; - -import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; - -import de.intevation.flys.client.client.event.CollectionChangeEvent; -import de.intevation.flys.client.client.event.CollectionChangeHandler; -import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; -import de.intevation.flys.client.client.event.HasOutputModesChangeHandlers; -import de.intevation.flys.client.client.event.OutputModesChangeEvent; -import de.intevation.flys.client.client.event.OutputModesChangeHandler; -import de.intevation.flys.client.client.event.ParameterChangeEvent; -import de.intevation.flys.client.client.event.ParameterChangeHandler; - -import de.intevation.flys.client.client.services.AddArtifactService; -import de.intevation.flys.client.client.services.AddArtifactServiceAsync; -import de.intevation.flys.client.client.services.ArtifactService; -import de.intevation.flys.client.client.services.ArtifactServiceAsync; -import de.intevation.flys.client.client.services.CollectionAttributeService; -import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; -import de.intevation.flys.client.client.services.CreateCollectionService; -import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; -import de.intevation.flys.client.client.services.DescribeCollectionService; -import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; -import de.intevation.flys.client.client.services.LoadArtifactService; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; - -import de.intevation.flys.client.client.ui.ScreenLock; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.ExportMode; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.ReportMode; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Stack; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class CollectionView -extends Window -implements CollectionChangeHandler, HasCollectionChangeHandlers, - OutputModesChangeHandler, HasOutputModesChangeHandlers, - ParameterChangeHandler, CloseClickHandler -{ - /** The ArtifactService used to communicate with the Artifact server. */ - protected CreateCollectionServiceAsync createCollectionService = - GWT.create(CreateCollectionService.class); - - /** The ArtifactService used to communicate with the Artifact server. */ - protected ArtifactServiceAsync createArtifactService = - GWT.create(ArtifactService.class); - - /** The AddArtifactService used to add an artifact to a collection. */ - protected AddArtifactServiceAsync addArtifactService = - GWT.create(AddArtifactService.class); - - /** The DescribeCollectionService used to update the existing collection. */ - protected DescribeCollectionServiceAsync describeCollectionService = - GWT.create(DescribeCollectionService.class); - - protected CollectionAttributeServiceAsync updater = - GWT.create(CollectionAttributeService.class); - - /** The LoadArtifactService used to load recommendations*/ - protected LoadArtifactServiceAsync loadArtifactService = - GWT.create(LoadArtifactService.class); - - /** The message class that provides i18n strings. */ - protected FLYSConstants messages = GWT.create(FLYSConstants.class); - - /** The FLYS instance used to call services. */ - protected FLYS flys; - - /** The ParameterList. */ - protected ParameterList parameterList; - - /** The list of CollectionChangeHandlers. */ - protected List<CollectionChangeHandler> handlers; - - /** The list of OutputModesChangeHandlers. */ - protected List<OutputModesChangeHandler> outHandlers; - - /** The collection to be displayed. */ - protected Collection collection; - - /** The artifact that handles the parameterization. */ - protected Artifact artifact; - - protected TabSet tabs; - - /** The output tab. */ - protected Map<String, OutputTab> outputTabs; - - /** The layout. */ - protected Layout layout; - - /** Layout to show spinning wheel of joy. */ - protected VLayout lockScreen; - - protected int artifactsQueue; - protected int recommendationQueue; - protected Stack<Recommendation> newRecommendations; - - /** Values for fix analysis charts*/ - protected double currentKm; - protected double minKm; - protected double maxKm; - protected double steps; - - /** - * This constructor creates a new CollectionView that is used to display the - * <i>collection</i>. - */ - public CollectionView(FLYS flys) { - this.flys = flys; - this.tabs = new TabSet(); - this.outputTabs = new HashMap<String, OutputTab>(); - this.handlers = new ArrayList<CollectionChangeHandler>(); - this.outHandlers = new ArrayList<OutputModesChangeHandler>(); - this.layout = new VLayout(); - this.parameterList = new ParameterList( - flys, this, messages.new_project()); - this.artifactsQueue = 0; - this.recommendationQueue = 0; - this.newRecommendations = new Stack<Recommendation>(); - - this.currentKm = -1d; - this.minKm = -1d; - this.maxKm = -1d; - this.steps = -1d; - - addCollectionChangeHandler(this); - addCollectionChangeHandler(parameterList); - addCollectionChangeHandler(flys); - addOutputModesChangeHandler(this); - addOutputModesChangeHandler(parameterList); - addCloseClickHandler(this); - - parameterList.addParameterChangeHandler(this); - - init(); - } - - /** - * @param collection The collection to be displayed. - */ - public CollectionView(FLYS flys, Collection collection, Artifact artifact) { - this.flys = flys; - this.artifact = artifact; - this.collection = collection; - this.tabs = new TabSet(); - this.outputTabs = new HashMap<String, OutputTab>(); - this.handlers = new ArrayList<CollectionChangeHandler>(); - this.outHandlers = new ArrayList<OutputModesChangeHandler>(); - this.layout = new VLayout(); - - this.currentKm = -1d; - this.minKm = -1d; - this.maxKm = -1d; - this.steps = -1d; - - if (artifact != null) { - this.parameterList = new ParameterList( - flys, - this, - messages.getString(artifact.getName()), - artifact); - } - else { - this.parameterList = new ParameterList( - flys, this, messages.new_project()); - } - - this.artifactsQueue = 0; - this.newRecommendations = new Stack<Recommendation>(); - - addCollectionChangeHandler(this); - addCollectionChangeHandler(parameterList); - addCollectionChangeHandler(flys); - addOutputModesChangeHandler(this); - addOutputModesChangeHandler(parameterList); - addCloseClickHandler(this); - - parameterList.addParameterChangeHandler(this); - - init(); - - setCollection(collection); - - if (artifact != null) { - setArtifact(artifact); - } - } - - - /** - * This method handles the initial layout stuff. - */ - protected void init() { - setWidth(1010); - setHeight(700); - - setMaximized(true); - - layout.setWidth100(); - - setCanDragReposition(true); - setCanDragResize(true); - setShowMaximizeButton(true); - setKeepInParentRect(true); - - setTitle(""); - - addItem(layout); - - layout.addMember(tabs); - tabs.addTab(parameterList); - } - - protected FLYS getFlys() { - return flys; - } - - - /** - * This method registers a new CollectionChangeHandler. - * - * @param handler The new CollectionChangeHandler. - */ - @Override - public void addCollectionChangeHandler(CollectionChangeHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - /** - * This method registers a new OutputModesChangeHandler. - * - * @param handler The new OutputModesChangeHandler. - */ - @Override - public void addOutputModesChangeHandler(OutputModesChangeHandler handler) { - if (handler != null) { - outHandlers.add(handler); - } - } - - - /** - * This method calls the <code>onValueChange()</code> method of all - * registered ValueChangeHanders. - */ - protected void fireCollectionChangeEvent( - Collection old, Collection newCol) - { - for (CollectionChangeHandler handler: handlers) { - handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); - } - } - - - protected void fireOutputModesChangeEvent(OutputMode[] outputs) { - if (collection == null) { - return; - } - - for (OutputModesChangeHandler handler: outHandlers) { - handler.onOutputModesChange(new OutputModesChangeEvent(outputs)); - } - } - - - /** Disables input, grey out, show spinning wheel of joy. */ - public void lockUI() { - lockScreen = ScreenLock.lockUI(layout, lockScreen); - } - - - /** Enable input, remove grey, remove spinning wheel of joy. */ - public void unlockUI() { - ScreenLock.unlockUI(layout, lockScreen); - } - - - /** - * This method returns true, if the Collection is new and no plugins has - * been chosen. - * - * @return true, if the Collection is new. - */ - public boolean isNew() { - return collection.hasItems(); - } - - - /** - * Returns the artifact that is used for the parameterization. - * - * @return the artifact that is used for the parameterization. - */ - public Artifact getArtifact() { - return artifact; - } - - - public User getUser() { - return getFlys().getCurrentUser(); - } - - - /** - * Set the current artifact that is the master of the parameterization. - * - * @param artifact The new artifact. - */ - public void setArtifact(Artifact artifact) { - this.artifact = artifact; - - onArtifactChanged(artifact); - } - - - public void onArtifactChanged(Artifact artifact) { - artifactChanged(); - - if (artifact.isInBackground()) { - LoadingPanel p = new LoadingPanel(this, artifact); - p.addStepBackHandler(parameterList); - } - } - - - /** - * Implements the onCollectionChange() method to do update the GUI after the - * parameterization has changed. - * - * @param event The ParameterChangeEvent. - */ - @Override - public void onParameterChange(ParameterChangeEvent event) { - GWT.log("CollectionView.onParameterChange"); - setArtifact(event.getNewValue()); - } - - - protected void artifactChanged() { - Collection c = getCollection(); - - if (c != null) { - loadCollection(c); - } - else { - updateView(); - } - } - - /** - * Loads all information of a collection - * @param c the Collection - */ - private void loadCollection(Collection c) { - ArtifactDescription desc = getArtifact().getArtifactDescription(); - final Recommendation[] recom = desc.getRecommendations(); - Config config = Config.getInstance(); - String locale = config.getLocale(); - - describeCollectionService.describe(c.identifier(), locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not DESCRIBE collection."); - SC.warn(FLYS.getExceptionString(messages, caught)); - } - - @Override - public void onSuccess(Collection newCollection) { - GWT.log("Successfully DESCRIBED collection."); - boolean loaded = true; - for (Recommendation r: recom) { - if(!newCollection.loadedRecommendation(r)) { - loaded = false; - } - } - if (!loaded) { - loadRecommendedArtifacts(recom); - } - else { - setCollection(newCollection); - } - } - } - ); - } - - - /** - * Returns the collection of displayed by this view. - * - * @return the collection of this view. - */ - public Collection getCollection() { - return collection; - } - - - protected void setCollection(Collection collection) { - setCollection(collection, false); - } - - - /** - * Set the current collection. - * - * @param collection The new collection. - * @param suppress Whether to fire a collectionchangeevent. - */ - protected void setCollection(Collection collection, boolean suppress) { - if (collection != null && this.collection == null) { - flys.getWorkspace().addView(collection.identifier(), this); - } - - Collection tmp = this.collection; - this.collection = collection; - - setTitle(collection.getDisplayName()); - - if (!suppress) { - fireCollectionChangeEvent(tmp, this.collection); - } - } - - - @Override - public void onCollectionChange(CollectionChangeEvent event) { - if (artifactsQueue > 0) { - GWT.log("Do not update UI because we are still loading Artifacts."); - return; - } - - Collection newCol = event.getNewValue(); - - Map<String, OutputMode> outs = newCol.getOutputModes(); - - Set<String> keys = outs.keySet(); - OutputMode[] prepared = new OutputMode[outs.size()]; - - int idx = 0; - for (String outname: keys) { - prepared[idx++] = outs.get(outname); - } - - fireOutputModesChangeEvent(prepared); - - updateView(); - } - - - @Override - public void onOutputModesChange(OutputModesChangeEvent event) { - clearOutputTabs(); - OutputMode[] outs = event.getOutputModes(); - - if (outs == null) { - return; - } - - boolean hasCSV = false; - - for (OutputMode out: outs) { - addOutputTab(out.getName(), out); - - if (out instanceof ExportMode) { - ExportMode export = (ExportMode) out; - - if (export.getFacet("csv") != null) { - hasCSV = true; - parameterList.contractInfoPanel(); - } - } - } - - if (!hasCSV) { - parameterList.removeTable(); - } - } - - - /** - * Adds a new tab for the OutputMode <i>out</i>. - * - * @param name The name and title of the output. - */ - protected void addOutputTab(String name, OutputMode out) { - if (out instanceof ExportMode) { - ExportMode export = (ExportMode) out; - - if (export.getFacet("csv") != null && !parameterList.hasTable()) { - TableDataPanel p = new TableDataPanel(); - p.setUuid(collection.identifier()); - p.setName(out.getName()); - parameterList.setTable(p); - } - - return; - } - - if (out instanceof ReportMode) { - // we don't want to display report modes at all - return; - } - - GWT.log("Add new output tab for '" + name + "'"); - - String title = messages.getString(name); - OutputTab tab = out.createOutputTab(title, getCollection(), this); - - if (tab != null) { - outputTabs.put(name, tab); - } - } - - - /** - * Removes all output mode tabs from tab bar. - */ - protected void clearOutputTabs() { - GWT.log("Clear OutputTabs."); - - int num = tabs.getNumTabs(); - - for (int i = num-1; i >= 1; i--) { - tabs.removeTab(i); - } - - outputTabs.clear(); - } - - - /** - * Update the view (refresh the list of old and current data). - */ - protected void updateView() { - GWT.log("CollectionView.updateView()"); - updateOutputTabs(); - } - - - /** - * This method is used to update the tabs to show specific output modes. - */ - protected void updateOutputTabs() { - GWT.log("Update output tabs."); - if (outputTabs != null) { - Set<String> keys = outputTabs.keySet(); - - for (String key: keys) { - tabs.addTab(outputTabs.get(key)); - } - } - } - - - @Override - public void onCloseClick(CloseClickEvent event) { - if (collection != null) { - if(artifact != null) { - flys.closeProject(collection.identifier()); - } - else { - flys.getProjectList().deleteCollection(collection); - } - } - else { - hide(); - destroy(); - } - } - - - public void addArtifactToCollection(Artifact artifact) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - final Collection collection = getCollection(); - - GWT.log("CollectionView.addArtifactToCollection " + collection); - - if (collection != null) { - addArtifactService.add( - collection, artifact, locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("An error occured while adding artifact."); - SC.warn(FLYS.getExceptionString(messages, caught)); - } - - @Override - public void onSuccess(Collection newCollection) { - GWT.log("Successfully added artifacts."); - setCollection(newCollection, true); - } - } - ); - } - else { - // Create new collection and add artifact - final Artifact art = artifact; - createCollectionService.create( - locale, - flys.getCurrentUser().identifier(), - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not create the new collection."); - SC.warn(FLYS.getExceptionString(messages, caught)); - } - - @Override - public void onSuccess(Collection collection) { - GWT.log("Successfully created a new collection."); - addArtifactService.add( - collection, art, locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("An error occured while adding artifact."); - SC.warn(FLYS.getExceptionString(messages, caught)); - } - - @Override - public void onSuccess(Collection newCollection) { - GWT.log("Successfully added artifacts."); - setCollection(newCollection); - } - } - ); - } - } - ); - } - } - - - protected void addRecommendationsToCollection() { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - final Collection collection = getCollection(); - - collection.addRecommendations(newRecommendations); - - updater.update(collection, locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - newRecommendations.removeAllElements(); - setCollection(collection); - - GWT.log("An error occured while saving recommendations."); - SC.warn(FLYS.getExceptionString(messages, caught)); - } - - @Override - public void onSuccess(Collection newCol) { - GWT.log("Successfully saved recommendations."); - newRecommendations.removeAllElements(); - setCollection(newCol); - } - } - ); - } - - - protected void loadRecommendedArtifacts(Recommendation[] recommendations) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - final Collection collection = getCollection(); - - Artifact masterArtifact = getArtifact(); - - if (recommendations == null) { - GWT.log("WARNING: Currently no recommendations."); - return; - } - - for (final Recommendation recommendation: recommendations) { - if (collection.loadedRecommendation(recommendation)) { - continue; - } - newRecommendations.push(recommendation); - - // XXX: UGLY! If no reference artifact given use uuid of - // current artifact as reference. - if (recommendation.getMasterArtifact() == null) { - recommendation.setMasterArtifact(masterArtifact.getUuid()); - } - - } - - loadArtifactService.loadMany( - collection, - recommendations, - null, - locale, - new AsyncCallback<Artifact[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Error loading recommendations: " + - caught.getMessage()); - SC.warn(FLYS.getExceptionString(messages, caught)); - } - - @Override - public void onSuccess(Artifact[] artifacts) { - GWT.log("Loaded artifacts: " + artifacts.length); - addRecommendationsToCollection(); - } - }); - } - - - public void registerTabHandler(TabSelectedHandler tse) { - tabs.addTabSelectedHandler(tse); - } - - - public void setCurrentKm(double currentKm) { - this.currentKm = currentKm; - } - - public double getCurrentKm() { - return this.currentKm; - } - - public void setMinKm(double km) { - this.minKm = km; - } - - public double getMinKm() { - return this.minKm; - } - - public void setMaxKm(double km) { - this.maxKm = km; - } - - public double getMaxKm() { - return this.maxKm; - } - - public void setSteps(double step) { - this.steps = step; - } - - public double getSteps() { - return this.steps; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ContinuePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.LinkItem; -import com.smartgwt.client.widgets.form.fields.events.ClickEvent; -import com.smartgwt.client.widgets.form.fields.events.ClickHandler; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.AdvanceHandler; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; - -import java.util.ArrayList; -import java.util.List; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ContinuePanel extends AbstractUIProvider { - - private static final long serialVersionUID = -5882814816875137397L; - - protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected List<AdvanceHandler> advHandlers; - - - @Override - public Canvas create(DataList dataList) { - DynamicForm form = new DynamicForm(); - form.setWidth(200); - form.setHeight(35); - - LinkItem next = new LinkItem(); - next.setShowTitle(false); - next.setLinkTitle(MSG.next()); - - final ArtifactDescription desc = artifact.getArtifactDescription(); - final String[] reachable = desc.getReachableStates(); - - next.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - fireOnAdvance(reachable[0]); - } - }); - - form.setFields(next); - - return form; - } - - - @Override - public Canvas createOld(DataList dataList) { - return null; - } - - - @Override - protected Data[] getData() { - return new Data[0]; - } - - - public void addAdvanceHandler(AdvanceHandler handler) { - if (advHandlers == null) { - advHandlers = new ArrayList<AdvanceHandler>(); - } - - if (handler != null) { - advHandlers.add(handler); - } - } - - - public void fireOnAdvance(String target) { - if (advHandlers == null || advHandlers.isEmpty()) { - return; - } - - for (AdvanceHandler handler: advHandlers) { - handler.onAdvance(target); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageButton.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.events.CloseClickHandler; -import com.smartgwt.client.widgets.events.CloseClickEvent; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.User; - -/** Button that opens view of datacage (DataCageWindow). */ -public class DatacageButton extends Button implements ClickHandler { - - protected Artifact artifact; - protected User user; - protected CollectionView view; - - public DatacageButton( - String title, - Artifact artifact, - User user, - CollectionView view - ) { - super(title); - - this.artifact = artifact; - this.user = user; - this.view = view; - - addClickHandler(this); - } - - - public void onClick(ClickEvent event) { - // TODO: fetch outs! - String outs = ""; - - final DatacageWindow dc = new DatacageWindow( - artifact, user, outs, view); - dc.addCloseClickHandler(new CloseClickHandler() { - public void onCloseClick(CloseClickEvent event) { - dc.destroy(); - } - }); - dc.show(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ToLoad; -import de.intevation.flys.client.shared.model.User; - - -/** - * Widget showing two Datacages and a add-this-button. - * Insert a record into a listgrid when add-this-button clicked. - */ -public class DatacagePairWidget -extends VLayout -{ - /** i18n resource. */ - protected FLYSConstants MSG = - GWT.create(FLYSConstants.class); - - /** The "remote" ListGrid to insert data to when add-button is clicked. */ - protected ListGrid grid; - - /** First (upper) DataCage Grid. */ - protected DatacageWidget firstDatacageWidget; - - /** Second (lower) DataCage Grid. */ - protected DatacageWidget secondDatacageWidget; - - - /** - * - * @param artifact Artifact to query datacage with. - * @param user User to query datacage with. - * @param outs outs to query datacage with. - * @param grid Grid into which to insert selection of pairs. - */ - public DatacagePairWidget(Artifact artifact, - User user, - String outs, - ListGrid grid) { - this.grid = grid; - - HLayout hLayout = new HLayout(); - firstDatacageWidget = new DatacageWidget( - artifact, - user, - outs, - "load-system:true", - false); - secondDatacageWidget = new DatacageWidget( - artifact, - user, - outs, - "load-system:true", - false); - firstDatacageWidget.setIsMutliSelectable(false); - secondDatacageWidget.setIsMutliSelectable(false); - - hLayout.addMember(firstDatacageWidget); - hLayout.addMember(secondDatacageWidget); - - // TODO: icon - Button plusBtn = new Button(MSG.datacage_add_pair()); - plusBtn.setAutoFit(true); - plusBtn.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - plusClicked(); - } - }); - - addMember(hLayout); - addMember(plusBtn); - } - - - /** - * Callback for add-button. - * Fires to load for every selected element and handler. - */ - public void plusClicked() { - ToLoad toLoad1 = firstDatacageWidget.getSelection(); - ToLoad toLoad2 = secondDatacageWidget.getSelection(); - - if (toLoad1 == null || toLoad2 == null || - toLoad1.toRecommendations().isEmpty() || - toLoad2.toRecommendations().isEmpty()) { - SC.say(MSG.warning_select_two_values()); - return; - } - - grid.addData(new RecommendationPairRecord( - toLoad1.toRecommendations().get(0), - toLoad2.toRecommendations().get(0))); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.List; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public abstract class DatacagePanel extends TextProvider { - - private static final long serialVersionUID = 6937994648371673222L; - - protected String dataName; - - protected User user; - - protected DatacageWidget widget; - - - public DatacagePanel() { - super(); - } - - - public DatacagePanel(User user) { - super(); - this.user = user; - } - - - @Override - public Canvas create(DataList dataList) { - Data data = dataList.get(0); - this.dataName = data.getLabel(); - - createWidget(); - - Canvas label = new Label(data.getDescription()); - Canvas submit = getNextButton(); - VLayout layout = new VLayout(); - label.setHeight(25); - - layout.addMember(label); - layout.addMember(submit); - layout.setMembersMargin(10); - - return layout; - } - - - protected void createWidget() { - widget = new DatacageWidget( - artifact, - getUser(), - getOuts(), - getParameters(), - false); - - widget.setHeight100(); - - helperContainer.addMember(widget); - } - - - @Override - public List<String> validate() { - return new ArrayList<String>(); - } - - - public User getUser() { - return user; - } - - - public String getOuts() { - return null; - } - - - public String getParameters() { - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,492 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.StepForwardEvent; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.client.services.RemoveArtifactServiceAsync; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.Recommendation.Facet; -import de.intevation.flys.client.shared.model.Recommendation.Filter; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -// TODO Probably better to branch off AbstractUIProvider. -// TODO Merge with other datacage-widget impls. -/** - * Panel containing a Grid and a "next" button. The Grid is fed by a - * DatacagePairWidget which is put in the input-helper area. - */ -public class DatacageTwinPanel -extends TextProvider { - - private static final long serialVersionUID = 8906629596491827857L; - - protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected String dataName; - - protected User user; - - /** ListGrid that displays user-selected pairs to build differences with. */ - protected ListGrid differencesList; - - /** - * List to track previously selected but now removed pairs. (Needed to - * be able to identify artifacts that can be removed from the collection. - */ - protected List<RecommendationPairRecord> removedPairs = - new ArrayList<RecommendationPairRecord>(); - - /** Service handle to clone and add artifacts to collection. */ - LoadArtifactServiceAsync loadArtifactService = GWT.create( - de.intevation.flys.client.client.services.LoadArtifactService.class); - - /** Service to remove artifacts from collection. */ - RemoveArtifactServiceAsync removeArtifactService = GWT.create( - de.intevation.flys.client.client.services.RemoveArtifactService.class); - - - public DatacageTwinPanel(User user) { - super(); - this.user = user; - } - - - /** - * Remove first occurrence of "[" and "]" (if both do occur). - * @param value String to be stripped of [] (might be null). - * @return input string but with [ and ] removed, or input string if no - * brackets were found. - * @see StringUtil.unbracket - */ - public static final String unbracket(String value) { - // null- guard. - if (value == null) return value; - - int start = value.indexOf("["); - int end = value.indexOf("]"); - - if (start < 0 || end < 0) { - return value; - } - - value = value.substring(start + 1, end); - - return value; - } - - - /** - * Create a recommendation from a string representation of it. - * @TODO describe format of input string - * @param from string in format as shown above. - * @return recommendation from input string. - */ - public Recommendation createRecommendationFromString(String from) { - // TODO Construct "real" filter. - String[] parts = unbracket(from).split(";"); - Recommendation.Filter filter = new Recommendation.Filter(); - Recommendation.Facet facet = new Recommendation.Facet( - parts[1], - parts[2]); - - List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet> - (); - facets.add(facet); - filter.add("longitudinal_section", facets); - Recommendation r = new Recommendation("waterlevel", parts[0], - this.artifact.getUuid(), filter); - r.setDisplayName(parts[3]); - return r; - } - - - /** - * Add RecomendationPairRecords from input String to the ListGrid. - */ - public void populateGridFromString(String from){ - // Split this string. - // Create according recommendations and display strings. - String[] recs = from.split("#"); - if (recs.length % 2 != 0) return; - for (int i = 0; i < recs.length; i+=2) { - Recommendation minuend = - createRecommendationFromString(recs[i+0]); - Recommendation subtrahend = - createRecommendationFromString(recs[i+1]); - - RecommendationPairRecord pr = new RecommendationPairRecord( - minuend, subtrahend); - // This Recommendation Pair comes from the data string and was thus - // already cloned. - pr.setIsAlreadyLoaded(true); - this.differencesList.addData(pr); - } - } - - - /** - * Creates the graphical representation and interaction widgets for the data. - * @param dataList the data. - * @return graphical representation and interaction widgets for data. - */ - @Override - public Canvas create(DataList dataList) { - GWT.log("createData()"); - - Canvas widget = createWidget(); - Canvas submit = getNextButton(); - - VLayout layout = new VLayout(); - HLayout helperLayout = new HLayout(); - helperLayout.addMember(new DatacagePairWidget(this.artifact, - user, "waterlevels", differencesList)); - - layout.addMember(widget); - layout.addMember(submit); - layout.setMembersMargin(10); - this.helperContainer.addMember(helperLayout); - - // Find old data, if any, handle "diffids". - Data data = dataList.get(0); - this.dataName = data.getLabel(); - for (int i = 0; i < dataList.size(); i++) { - if (dataList.get(i) != null && dataList.get(i).getItems() != null) { - if (dataList.get(i).getItems() != null) { - populateGridFromString( - dataList.get(i).getItems()[0].getStringValue()); - } - } - } - - return layout; - } - - - /** - * Validates the selection. - * @return List of internationalized errror messages (if any). - */ - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - if (differencesList.getRecords().length == 0) { - errors.add(MSG.error_no_waterlevel_pair_selected()); - } - // Check whether minuend and subtrahend are equal. - for (ListGridRecord record: differencesList.getRecords()) { - RecommendationPairRecord r = (RecommendationPairRecord) record; - if (r.getFirst().equals(r.getSecond())) { - errors.add(MSG.error_same_waterlevels_in_pair()); - } - } - - return errors; - } - - - /** - * Creates layout with grid that displays selection inside. - */ - public Canvas createWidget() { - VLayout layout = new VLayout(); - differencesList = new ListGrid(); - - differencesList.setCanEdit(false); - differencesList.setCanSort(false); - differencesList.setShowHeaderContextMenu(false); - differencesList.setHeight(150); - differencesList.setShowAllRecords(true); - - ListGridField nameField = new ListGridField("first", "Minuend"); - ListGridField capitalField = new ListGridField("second", "Subtrahend"); - // Track removed rows, therefore more or less reimplement - // setCanRecomeRecords. - final ListGridField removeField = - new ListGridField("_removeRecord", "Remove Record"){{ - setType(ListGridFieldType.ICON); - setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); - setCanEdit(false); - setCanFilter(false); - setCanSort(false); - setCanGroupBy(false); - setCanFreeze(false); - setWidth(25); - }}; - - differencesList.setFields(new ListGridField[] {nameField, - capitalField, removeField}); - - differencesList.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(final RecordClickEvent event) { - // Just handle remove-clicks - if(!event.getField().getName().equals(removeField.getName())) { - return; - } - trackRemoved(event.getRecord()); - event.getViewer().removeData(event.getRecord()); - } - }); - layout.addMember(differencesList); - - return layout; - } - - - /** - * Add record to list of removed records. - */ - public void trackRemoved(Record r) { - RecommendationPairRecord pr = (RecommendationPairRecord) r; - this.removedPairs.add(pr); - } - - - /** - * Validates data, does nothing if invalid, otherwise clones new selected - * waterlevels and add them to collection, forward the artifact. - */ - @Override - public void onClick(ClickEvent e) { - GWT.log("DatacageTwinPanel.onClick"); - - List<String> errors = validate(); - if (errors != null && !errors.isEmpty()) { - showErrors(errors); - return; - } - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - ListGridRecord[] records = differencesList.getRecords(); - - List<Recommendation> ar = new ArrayList<Recommendation>(); - List<Recommendation> all = new ArrayList<Recommendation>(); - - for (ListGridRecord record : records) { - RecommendationPairRecord r = - (RecommendationPairRecord) record; - // Do not add "old" recommendations. - if (!r.isAlreadyLoaded()) { - // Check whether one of those is a dike or similar. - // TODO differentiate and merge: new clones, new, old. - Recommendation firstR = r.getFirst(); - if(firstR.getIDs() != null) { - GWT.log("First IDs: " + firstR.getIDs() + " factory: " - + firstR.getFactory()); - } - if(firstR.getIDs() != null) { - // These do not get cloned but loaded ("spawned"). - firstR.setFactory("staticwkms"); - } - else { - firstR.setFactory("waterlevel"); - } - Recommendation secondR = r.getSecond(); - if(secondR.getIDs() != null) { - GWT.log("Second IDs: " + secondR.getIDs() + " factory: " - + secondR.getFactory()); - } - if (secondR.getIDs() != null) { - // These do not get cloned but loaded ("spawned"). - secondR.setFactory("staticwkms"); - } - else { - secondR.setFactory("waterlevel"); - } - - ar.add(firstR); - ar.add(secondR); - } - else { - all.add(r.getFirst()); - all.add(r.getSecond()); - } - } - - final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]); - final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]); - - // Find out whether "old" artifacts have to be removed. - List<String> artifactIdsToRemove = new ArrayList<String>(); - for (RecommendationPairRecord rp: this.removedPairs) { - Recommendation first = rp.getFirst(); - Recommendation second = rp.getSecond(); - - for (Recommendation recommendation: toUse) { - if (first != null && first.getIDs().equals(recommendation.getIDs())) { - first = null; - } - if (second != null && second.getIDs().equals(recommendation.getIDs())) { - second = null; - } - - if (first == null && second == null) { - break; - } - } - if (first != null) { - artifactIdsToRemove.add(first.getIDs()); - } - if (second != null) { - artifactIdsToRemove.add(second.getIDs()); - } - } - - // Remove old artifacts, if any. Do this asychronously without much - // feedback. - for(final String uuid: artifactIdsToRemove) { - removeArtifactService.remove(this.collection, - uuid, - locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("RemoveArtifact (" + uuid + ") failed."); - } - @Override - public void onSuccess(Collection collection) { - GWT.log("RemoveArtifact succeeded"); - } - }); - } - - // Clone new ones (and spawn statics), go forward. - loadArtifactService.loadMany( - this.collection, - toClone, - //"staticwkms" and "waterlevel" - null, - locale, - new AsyncCallback<Artifact[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Failure of cloning with factories!"); - } - @Override - public void onSuccess(Artifact[] artifacts) { - GWT.log("Successfully cloned " + toClone.length + - " with factories."); - - fireStepForwardEvent(new StepForwardEvent( - getData(toClone, artifacts, toUse))); - } - }); - } - - - /** - * Create Data and DataItem from selection (a long string with identifiers - * to construct diff-pairs). - * - * @param newRecommendations "new" recommendations (did not survive a - * backjump). - * @param newArtifacts artifacts cloned from newRecommendations. - * @param oldRecommendations old recommendations that survived a backjump. - * - * @return dataitem with a long string with identifiers to construct - * diff-pairs. - */ - protected Data[] getData( - Recommendation[] newRecommendations, - Artifact[] newArtifacts, - Recommendation[] oldRecommendations) - { - // Construct string with info about selections. - String dataItemString = ""; - for (int i = 0; i < newRecommendations.length; i++) { - Recommendation r = newRecommendations[i]; - Artifact newArtifact = newArtifacts[i]; - String uuid = newArtifact.getUuid(); - r.setMasterArtifact(uuid); - if (i>0) dataItemString += "#"; - - dataItemString += createDataString(uuid, r); - } - - for (int i = 0; i < oldRecommendations.length; i++) { - Recommendation r = oldRecommendations[i]; - String uuid = r.getIDs(); - if (dataItemString.length() > 0) dataItemString += "#"; - - dataItemString += createDataString(uuid, r); - } - - // TODO some hassle could be resolved by using multiple DataItems - // (e.g. one per pair). - DataItem item = new DefaultDataItem(dataName, dataName, dataItemString); - return new Data[] { new DefaultData( - dataName, null, null, new DataItem[] {item}) }; - } - - - /** - * Creates part of the String that encodes minuend or subtrahend. - * @param artifact Artifacts UUID. - * @param recommendation Recommendation to wrap in string. - */ - protected String createDataString( - String artifact, - Recommendation recommendation) - { - Filter filter = recommendation.getFilter(); - Facet f = null; - - if(filter != null) { - Map<String, List<Facet>> outs = filter.getOuts(); - Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); - - for (Map.Entry<String, List<Facet>> entry: entries) { - List<Facet> fs = entry.getValue(); - - f = fs.get(0); - if (f != null) { - break; - } - } - - return "[" + artifact + ";" - + f.getName() - + ";" - + f.getIndex() - + ";" - + recommendation.getDisplayName() + "]"; - } - else { - return "[" - + artifact - + ";staticwkms;0;" - + recommendation.getDisplayName() + "]"; - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,504 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.types.TreeModelType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.grid.HoverCustomizer; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tree.Tree; -import com.smartgwt.client.widgets.tree.TreeGrid; -import com.smartgwt.client.widgets.tree.TreeNode; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.DatacageDoubleClickHandler; -import de.intevation.flys.client.client.event.DatacageHandler; -import de.intevation.flys.client.client.services.MetaDataService; -import de.intevation.flys.client.client.services.MetaDataServiceAsync; -import de.intevation.flys.client.client.ui.ScreenLock; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.AttrList; -import de.intevation.flys.client.shared.model.DataCageNode; -import de.intevation.flys.client.shared.model.DataCageTree; -import de.intevation.flys.client.shared.model.ToLoad; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.List; -import java.util.MissingResourceException; -import java.util.Stack; - -// TODO: refactor, extract ~DataCageGrid -/** - * Display tree of, for example, previous calculations and allows - * selection in order to access/clone these. - */ -public class DatacageWidget -extends VLayout -{ - public static final int MAX_OPEN = 30; - - protected MetaDataServiceAsync metaDataService = - GWT.create(MetaDataService.class); - - protected FLYSConstants messages = - GWT.create(FLYSConstants.class); - - protected Artifact artifact; - protected User user; - protected String outs; - protected String parameters; - - protected TreeGrid treeGrid; - protected Tree tree; - - protected ToLoad toLoad; - - protected List<DatacageHandler> handlers; - protected List<DatacageDoubleClickHandler> doubleHandlers; - - /** Layout to show spinning wheel of joy. */ - protected VLayout lockScreen; - - - public DatacageWidget() { - handlers = new ArrayList<DatacageHandler>(); - doubleHandlers = new ArrayList<DatacageDoubleClickHandler>(); - } - - - public DatacageWidget(Artifact artifact, User user) { - this(artifact, user, null); - } - - public DatacageWidget(Artifact artifact, User user, String outs) { - this(artifact, user, outs, true); - } - - public DatacageWidget( - Artifact artifact, - User user, - String outs, - boolean showButton - ) { - this(artifact, user, outs, null, showButton); - } - - - public DatacageWidget( - Artifact artifact, - User user, - String outs, - String parameters, - boolean showButton - ) { - this(); - - this.artifact = artifact; - this.user = user; - this.outs = outs; - this.parameters = parameters; - - toLoad = new ToLoad(); - - setWidth100(); - - tree = new Tree(); - tree.setModelType(TreeModelType.CHILDREN); - tree.setNameProperty("name"); - tree.setIdField("id"); - tree.setChildrenProperty("children-nodes"); - tree.setShowRoot(false); - - treeGrid = new TreeGrid(); - treeGrid.setLoadDataOnDemand(false); - treeGrid.setWidth100(); - treeGrid.setHeight100(); - treeGrid.setShowRoot(false); - treeGrid.setNodeIcon("[SKIN]/../blank.gif"); - treeGrid.setShowConnectors(true); - treeGrid.setLoadingMessage(messages.databasket_loading()); - treeGrid.setEmptyMessage(messages.databasket_loading()); - treeGrid.setLoadingDataMessage(messages.databasket_loading()); - - treeGrid.setHoverMoveWithMouse(true); - treeGrid.setCanHover(true); - treeGrid.setShowHover(true); - treeGrid.setHoverOpacity(75); - treeGrid.setHoverWidth(120); - - treeGrid.setHoverCustomizer(new HoverCustomizer() { - @Override - public String hoverHTML(Object value, - ListGridRecord record, - int rowNum, - int colNum - ) { - if(record instanceof TreeNode) { - TreeNode hoveredTreeNode = (TreeNode)record; - String info = hoveredTreeNode.getAttribute("info"); - if (info == null) { - info = hoveredTreeNode.getName(); - } - return info; - } - else { - return "";// should not happen - } - } - }); - - treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { - @Override - public void onRecordDoubleClick(RecordDoubleClickEvent event) { - doubleClickedOnTree(event); - } - }); - - addMember(treeGrid); - - if (showButton) { - addMember(createPlusButton()); - } - - triggerTreeBuilding(); - } - - public void lockUI() { - lockScreen = ScreenLock.lockUI(this, lockScreen); - } - - /** Enable input, remove grey, remove spinning wheel of joy. */ - public void unlockUI() { - ScreenLock.unlockUI(this, lockScreen); - } - - /** - * @param handler Handler to be added (notified on add-action). - */ - public DatacageWidget(Artifact artifact, User user, String outs, - DatacageHandler handler) { - this(artifact, user, outs); - this.addDatacageHandler(handler); - } - - - public DatacageWidget( - Artifact artifact, - User user, - String outs, - DatacageHandler handler, - String parameters - ) { - this(artifact, user, outs, handler); - this.parameters = parameters; - } - - - /** - * Sets whether more than one item can be selected. - * @param multi if true, allow mutliple selections. - */ - public void setIsMutliSelectable(boolean multi) { - if (multi) { - treeGrid.setSelectionType(SelectionStyle.MULTIPLE); - } - else { - treeGrid.setSelectionType(SelectionStyle.SINGLE); - } - } - - - /** - * @param handler Handler to be added (notified on add-action). - */ - public void addDatacageHandler(DatacageHandler handler) { - if (!handlers.contains(handler)) { - handlers.add(handler); - } - } - - - /** - * @param h Handler to be added (notified on Double click on node). - */ - public void addDatacageDoubleClickHandler(DatacageDoubleClickHandler h) { - if (!doubleHandlers.contains(h)) { - doubleHandlers.add(h); - } - } - - - /** - * @param handler Handler to remove from list. - */ - public void removeDatacageHandler(DatacageHandler handler) { - handlers.remove(handler); - } - - - public ToLoad getToLoad() { - return toLoad; - } - - - public ToLoad getSelection() { - // Reset content of toLoads. - toLoad = new ToLoad(); - - if (treeGrid == null) { - return toLoad; - } - - ListGridRecord [] selection = treeGrid.getSelectedRecords(); - - if (selection != null) { - for (ListGridRecord record: selection) { - if (record instanceof TreeNode) { - collectToLoads((TreeNode)record); - } - } - } - - return toLoad; - } - - - /** - * Returns the titles of selected items (if any). - */ - public String[] getSelectionTitles() { - if (treeGrid == null) { - return new String[] {}; - } - - ListGridRecord [] selection = treeGrid.getSelectedRecords(); - - if (selection == null) { - return new String[] {}; - } - - List<String> titleList = new ArrayList<String>(); - for (ListGridRecord record: selection) { - if (record instanceof TreeNode) { - titleList.add(((TreeNode)record).getAttribute("name")); - } - } - - return titleList.toArray(new String[titleList.size()]); - } - - - /** - * Callback for add-button. - * Fires to load for every selected element and handler. - */ - public void plusClicked() { - if (!getSelection().isEmpty()) { - fireToLoad(); - } - } - - - protected Button createPlusButton() { - Button plusBtn = new Button(messages.datacageAdd()); - plusBtn.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - plusClicked(); - } - }); - return plusBtn; - } - - - protected void fireToLoad() { - for (DatacageHandler handler: handlers) { - handler.toLoad(toLoad); - } - } - - - /** Notify DatacageDoubleClickHandlers that a doubleclick happened. */ - protected void fireOnDoubleClick() { - for (DatacageDoubleClickHandler handler: doubleHandlers) { - handler.onDoubleClick(toLoad); - } - } - - - protected void doubleClickedOnTree(RecordDoubleClickEvent event) { - TreeNode node = (TreeNode)event.getRecord(); - collectToLoads(node); - fireOnDoubleClick(); - } - - - /** - * Adds to toLoad, from info in node. - * Afterwards, add all children of node to stack to parse (next time - * collectToLoads is called). - */ - protected void collectToLoads(TreeNode node) { - Stack<TreeNode> stack = new Stack<TreeNode>(); - - stack.push(node); - - while (!stack.isEmpty()) { - node = stack.pop(); - String factory = node.getAttribute("factory"); - if (factory != null) { // we need at least a factory - String artifact = node.getAttribute("artifact-id"); - String out = node.getAttribute("out"); - String name = node.getAttribute("facet"); - String ids = node.getAttribute("ids"); - String displayname = node.getAttribute("name"); - String debugAttributeValues = ""; - for (String attr: node.getAttributes()) { - debugAttributeValues += ("[" + attr +": " - + node.getAttributeAsString(attr) + "] "); - } - GWT.log("DatacageWidget.collectToLoad, attributes are " - + debugAttributeValues); - - toLoad.add(artifact, - factory, - out, - name, - ids, - displayname); - } - TreeNode [] children = tree.getChildren(node); - if (children != null) { - for (TreeNode child: children) { - stack.push(child); - } - } - } - } - - - /** Get meta-data and populate tree with it. */ - protected void triggerTreeBuilding() { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - String artifactId = artifact.getUuid(); - String userId = (user != null) ? user.identifier() : null; - - lockUI(); - - metaDataService.getMetaData( - locale, - artifactId, - userId, - outs, - parameters, - new AsyncCallback<DataCageTree>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not load meta data."); - SC.warn(caught.getMessage()); - unlockUI(); - } - - @Override - public void onSuccess(DataCageTree dcTree) { - GWT.log("Successfully loaded meta data."); - IdGenerator idGenerator = new IdGenerator(); - DataCageNode dcRoot = dcTree.getRoot(); - TreeNode root = buildRecursiveChildren( - dcRoot, idGenerator); - tree.setRoot(root); - - TreeNode[] nodes = tree.getChildren(root); - for (TreeNode node: nodes) { - if (node.getAttribute("factory") == null && - !tree.hasChildren(node)) { - node.setIsFolder(true); - } - } - - if (idGenerator.current() < MAX_OPEN) { - tree.openAll(); - } - treeGrid.setData(tree); - unlockUI(); - } - }); - } - - private static final class IdGenerator { - protected int current; - - public IdGenerator() { - } - - public int next() { - return current++; - } - - public int current() { - return current; - } - } // class IdGenerator - - private String i18n(String s) { - if (!(s.startsWith("${") && s.endsWith("}"))) { - return s; - } - - s = s.substring(2, s.length()-1); - - try { - return messages.getString(s); - } - catch (MissingResourceException mre) { - GWT.log("cannot find i18n for + '" + s + "'"); - return s; - } - } - - protected TreeNode buildRecursiveChildren( - DataCageNode node, - IdGenerator idGenerator - ) { - TreeNode tn = new TreeNode(); - tn.setAttribute("id", idGenerator.next()); - - List<DataCageNode> children = node.getChildren(); - - if (children != null) { - TreeNode [] tns = new TreeNode[children.size()]; - for (int i = 0; i < tns.length; ++i) { - DataCageNode child = children.get(i); - tns[i] = buildRecursiveChildren(child, idGenerator); - } - tn.setAttribute("children-nodes", tns); - } - - tn.setAttribute("name", i18n(node.getDescription())); - tn.setAttribute("facet", node.getName()); - - AttrList attrs = node.getAttributes(); - if (attrs != null) { - for (int i = 0, N = attrs.size(); i < N; ++i) { - String key = attrs.getKey(i); - String value = attrs.getValue(i); - tn.setAttribute(key, value); - } - } - - return tn; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,201 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Window; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; - -import de.intevation.flys.client.client.event.DatacageHandler; -import de.intevation.flys.client.client.event.DatacageDoubleClickHandler; -import de.intevation.flys.client.client.event.HasRedrawRequestHandlers; -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.client.event.RedrawRequestEvent; -import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; - -import de.intevation.flys.client.client.services.LoadArtifactService; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.ToLoad; -import de.intevation.flys.client.shared.model.User; -import de.intevation.flys.client.shared.model.Recommendation; - - -/** Window that access the datacageservice and shows a datacagewidget. */ -public class DatacageWindow -extends Window -implements DatacageHandler, - DatacageDoubleClickHandler, - HasRedrawRequestHandlers -{ - /** i18ner. */ - protected FLYSConstants messages = - GWT.create(FLYSConstants.class); - - /** Service to create/clone artifacts. */ - protected LoadArtifactServiceAsync loadService = - GWT.create(LoadArtifactService.class); - - protected CollectionView view; - - protected List<RedrawRequestHandler> handlers; - - protected int inProgress; - - - public DatacageWindow( - Artifact artifact, - User user, - String outs, - CollectionView view - ) { - this.view = view; - this.handlers = new ArrayList<RedrawRequestHandler>(); - this.inProgress = 0; - - setWidth(400); - setHeight(500); - - DatacageWidget dw = new DatacageWidget( - artifact, - user, - outs, - "load-system:true", - true); - dw.addDatacageHandler(this); - dw.addDatacageDoubleClickHandler(this); - - addItem(dw); - - String river = findRiver(artifact); - // TODO: i18n - setTitle("Datenkorb: " + river); - setShowMinimizeButton(false); - setIsModal(true); - setShowModalMask(true); - setCanDragResize(true); - - centerInPage(); - } - - - @Override - public void toLoad(ToLoad toLoad) { - destroy(); - List<Recommendation> recs = toLoad.toRecommendations(); - loadArtifacts(recs); - } - - - @Override - public void onDoubleClick(ToLoad toLoad) { - destroy(); - List<Recommendation> recs = toLoad.toRecommendations(); - loadArtifacts(recs); - } - - - @Override - public void addRedrawRequestHandler(RedrawRequestHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - protected String findRiver(Artifact artifact) { - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList [] data = adescr.getOldData(); - - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - if (dl.getState().equals("state.winfo.river")) { - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - DataItem [] di = d.getItems(); - if (di != null && di.length == 1) { - return d.getItems()[0].getStringValue(); - } - } - } - } - } - - return ""; - } - - - protected void decreateInProgress() { - if (this.inProgress > 0) { - this.inProgress--; - } - - if (this.inProgress == 0) { - fireRedrawRequest(); - } - } - - - protected void fireRedrawRequest() { - RedrawRequestEvent evt = new RedrawRequestEvent(Type.DEFAULT); - - for (RedrawRequestHandler handler: handlers) { - handler.onRedrawRequest(evt); - } - } - - - protected void loadArtifacts(List<Recommendation> recommendations) { - Config cfg = Config.getInstance(); - - final Collection collection = view.getCollection(); - final Artifact masterArtifact = view.getArtifact(); - final String locale = cfg.getLocale(); - - this.inProgress = recommendations.size(); - - for (final Recommendation recommendation: recommendations) { - // XXX: UGLY! If no reference artifact given use uuid of - // current artifact as reference. - if (recommendation.getMasterArtifact() == null) { - recommendation.setMasterArtifact(masterArtifact.getUuid()); - } - - final String factory = recommendation.getFactory(); - - GWT.log("Load new artifact with factory: " + factory); - - loadService.load( - collection, - recommendation, - factory, - locale, - new AsyncCallback<Artifact>() { - public void onFailure(Throwable caught) { - decreateInProgress(); - GWT.log("Create-artifact failed: " + caught.getMessage()); - SC.warn(caught.getMessage()); - } - - public void onSuccess(Artifact artifact) { - decreateInProgress(); - GWT.log("Created new artifact: " + artifact.getUuid()); - } - }); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DemDatacagePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.ToLoad; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.List; - - -public class DemDatacagePanel extends DatacagePanel { - - private static final long serialVersionUID = -2301633938080411687L; - - public static final String OUT = "floodmap"; - public static final String PARAMETERS = "dem:true"; - - - public DemDatacagePanel() { - super(); - } - - - public DemDatacagePanel(User user) { - super(user); - } - - - @Override - protected void createWidget() { - super.createWidget(); - widget.setIsMutliSelectable(false); - } - - - @Override - public User getUser() { - return null; - } - - - @Override - public String getOuts() { - return OUT; - } - - - @Override - public String getParameters() { - return PARAMETERS; - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - - Recommendation r = getSelectedRecommendation(); - if (r == null) { - errors.add(MSG.requireDGM()); - } - - return errors; - } - - - @Override - protected Data[] getData() { - Recommendation r = getSelectedRecommendation(); - - DataItem item = new DefaultDataItem(dataName, dataName, r.getIDs()); - return new Data[] { new DefaultData( - dataName, null, null, new DataItem[] { item }) }; - } - - - protected Recommendation getSelectedRecommendation() { - ToLoad toLoad = widget.getSelection(); - List<Recommendation> recoms = toLoad.toRecommendations(); - - return recoms != null && recoms.size() >= 1 ? recoms.get(0) : null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,260 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ParentMovedEvent; -import com.smartgwt.client.widgets.events.ParentMovedHandler; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.events.VisibilityChangedEvent; -import com.smartgwt.client.widgets.events.VisibilityChangedHandler; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; -import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.MapInfoService; -import de.intevation.flys.client.client.services.MapInfoServiceAsync; -import de.intevation.flys.client.client.ui.map.FloodMap; -import de.intevation.flys.client.client.ui.map.MapPanel; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.MapInfo; - -import java.util.List; - -import org.gwtopenmaps.openlayers.client.Map; -import org.gwtopenmaps.openlayers.client.control.Attribution; -import org.gwtopenmaps.openlayers.client.layer.TransitionEffect; -import org.gwtopenmaps.openlayers.client.layer.WMS; -import org.gwtopenmaps.openlayers.client.layer.WMSOptions; -import org.gwtopenmaps.openlayers.client.layer.WMSParams; - - -public class DigitizePanel -extends SelectProvider -implements TabSelectedHandler, VisibilityChangedHandler { - - private static final long serialVersionUID = 3529775660871273314L; - - protected MapInfoServiceAsync mapInfo = GWT.create(MapInfoService.class); - - protected FloodMap floodMap; - - protected MapPanel mapPanel; - - public static final String UESK_BARRIERS = "uesk.barriers"; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public DigitizePanel() { - } - - - @Override - public Canvas create(DataList list) { - helperContainer.addVisibilityChangedHandler(this); - - DataList clone = (DataList) list.clone(); - List<Data> all = clone.getAll(); - all.remove(UESK_BARRIERS); - - Canvas widget = createWidget(list); - - final Config cfg = Config.getInstance(); - final String locale = cfg.getLocale(); - - String river = getDataValue("state.winfo.river", "river"); - mapInfo.getMapInfo(locale, river, new AsyncCallback<MapInfo>() { - @Override - public void onFailure(Throwable caught) { - String msg = caught.getMessage(); - - GWT.log("Error while fetching MapInfo: " + msg); - SC.warn(FLYS.getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(MapInfo info) { - createMapWidget(info); - } - }); - - return widget; - } - - - /** - * This method creates the content of the widget. - * - * @param data The {@link DataList} object. - * - * @return a combobox. - */ - @Override - protected Canvas createWidget(DataList data) { - GWT.log("DigitizePanel - createWidget()"); - - VLayout layout = new VLayout(); - layout.setAlign(VerticalAlignment.TOP); - layout.setHeight(25); - - int size = data.size(); - - for (int i = 0; i < size; i++) { - Data d = data.get(i); - - Label label = new Label(d.getDescription()); - label.setValign(VerticalAlignment.TOP); - label.setHeight(20); - label.setWidth(400); - - layout.addMember(label); - layout.addMember(getNextButton()); - } - - layout.setAlign(VerticalAlignment.TOP); - - return layout; - } - - - @Override - protected Data[] getData() { - final Data[] total = new Data[1]; - - if (floodMap != null) { - DataItem item = new DefaultDataItem( - UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON()); - total[0] = new DefaultData( - UESK_BARRIERS, null, null, new DataItem[] { item }); - } - else { - // Happens when OpenLayers is missing - GWT.log("floodMap is null -> OpenLayers missing?"); - } - - return total; - } - - - public void createMapWidget(MapInfo mapInfo) { - mapPanel = new MapPanel(mapInfo, true); - - floodMap = mapPanel.getFloodMap(); - Map map = floodMap.getMap(); - - helperContainer.addResizedHandler(new ResizedHandler() { - @Override - public void onResized(ResizedEvent event) { - mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); - } - }); - helperContainer.addParentMovedHandler(new ParentMovedHandler() { - @Override - public void onParentMoved(ParentMovedEvent event) { - mapPanel.getFloodMap().updateSize(); - } - }); - helperContainer.addVisibilityChangedHandler(new VisibilityChangedHandler() { - @Override - public void onVisibilityChanged(VisibilityChangedEvent event) { - mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); - } - }); - helperContainer.addMember(mapPanel); - - parameterList.registerCollectionViewTabHandler(this); - - WMS axis = getLayer( - mapInfo.getWmsUrl(), mapInfo.getWmsLayers(), - mapInfo.getProjection(), false, true); - WMS back = getLayer( - mapInfo.getBackgroundWmsUrl(), mapInfo.getBackgroundWmsLayers(), - mapInfo.getProjection(), false, false); - - map.addLayer(back); - map.addLayer(axis); - - String hws = getDataValue("state.winfo.uesk.dc-hws", "uesk.hws"); - if (hws != null && hws.length() > 0) { - WMS hwsLayer = getLayer( - //TODO: Use Mapinfo to get hws layer infos. - mapInfo.getWmsUrl().replace("river", "user"), - "ms_layer-hws-lines" + artifact.getUuid(), - mapInfo.getProjection(), - false, true); - map.addLayer(hwsLayer); - } - String userRgd = getDataValue("state.winfo.uesk.user-rgd", "uesk.user-rgd"); - if (userRgd != null && userRgd.length() > 0) { - WMS userLayer = getLayer( - //TODO: Use Mapinfo to get hws layer infos. - mapInfo.getWmsUrl().replace("river", "user"), - "ms_layer-user-rgd" + artifact.getUuid(), - mapInfo.getProjection(), - false, true); - map.addLayer(userLayer); - } - map.addControl(new Attribution()); - map.zoomToMaxExtent(); - - mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); - } - - - protected WMS getLayer(String url, String layers, String proj, boolean isBaseLayer, boolean singleTiled) { - final WMSParams params = new WMSParams(); - params.setLayers(layers); - params.setFormat("image/png"); - params.setIsTransparent(!isBaseLayer); - - final WMSOptions opts = new WMSOptions(); - opts.setProjection(proj); - opts.setSingleTile(false); // FIXME: Make working... - opts.setTransitionEffect(TransitionEffect.RESIZE); - opts.setRatio(1); - opts.setBuffer(0); - if (layers.equals("OSM-WMS-Dienst")) { - opts.setAttribution(MSG.attribution()); - } - final WMS wms = new WMS(layers, url, params, opts); - wms.setIsVisible(true); - wms.setIsBaseLayer(isBaseLayer); - - return wms; - } - - - @Override - public void onTabSelected(TabSelectedEvent tse) { - if (tse.getTabNum () != 0) { - floodMap.hideBarrierLayer(); - } - else { - floodMap.showBarrierLayer(); - } - } - - @Override - public void onVisibilityChanged(VisibilityChangedEvent vce) { - if (!vce.getIsVisible()) { - floodMap.hideBarrierLayer(); - mapPanel.getMapToolbar().activateDrawFeature(false); - } - else { - floodMap.showBarrierLayer(); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DistanceOnlyPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; - -import java.util.List; - - -public class DistanceOnlyPanel extends DistancePanel { - - private static final long serialVersionUID = -5794138573892656947L; - - - public DistanceOnlyPanel() { - this("right"); - } - - - public DistanceOnlyPanel(String labelOrientation) { - distancePanel = new DoubleRangeOnlyPanel( - labelFrom(), labelTo(), 0d, 0d, 250, this, labelOrientation); - } - - - @Override - protected String getOldSelectionString(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data dFrom = getData(items, getLowerField()); - Data dTo = getData(items, getUpperField()); - - DataItem[] from = dFrom.getItems(); - DataItem[] to = dTo.getItems(); - - StringBuilder sb = new StringBuilder(); - sb.append(from[0].getLabel()); - sb.append(" " + getUnitFrom() + " - "); - sb.append(to[0].getLabel()); - sb.append(" " + getUnitTo()); - - return sb.toString(); - } - - - @Override - protected void initDefaultStep(DataList data) { - // do nothing - } - - - @Override - public Data[] getData() { - Data[] data = new Data[2]; - - data[0] = getDataFrom(); - data[1] = getDataTo(); - - return data; - } - - - @Override - protected String labelFrom() { - return getUnitFrom() + " - "; - } - - - @Override - protected String labelTo() { - return getUnitTo(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DistancePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,647 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.data.AdvancedCriteria; -import com.smartgwt.client.data.Criteria; -import com.smartgwt.client.data.Criterion; -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.OperatorId; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; -import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; -import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.FilterHandler; -import de.intevation.flys.client.client.event.RangeFilterEvent; -import de.intevation.flys.client.client.event.StringFilterEvent; -import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; -import de.intevation.flys.client.client.ui.range.LocationsTable; -import de.intevation.flys.client.client.ui.range.RangeTable; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - - -public class DistancePanel extends AbstractUIProvider implements BlurHandler, FilterHandler -{ - - private static final long serialVersionUID = -883142387908664588L; - - public static final int DEFAULT_STEP_WIDTH = 100; - - public static final String FIELD_LOWER = "ld_from"; - public static final String FIELD_UPPER = "ld_to"; - public static final String FIELD_STEP = "ld_step"; - - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected RangeTable distancesTable; - protected LocationsTable locationsTable; - - protected DoubleRangePanel distancePanel; - - protected TableFilter filterDescription; - protected RangeTableFilter filterRange; - - protected TabSet tabs; - - protected double min; - protected double max; - - protected StaticTextItem filterResultCount; - protected ListGrid currentFiltered; - - public DistancePanel() { - this("right"); - } - - - public DistancePanel(String labelOrientation) { - distancePanel = new DoubleRangePanel( - labelFrom(), labelTo(), labelStep(), - 0d, 0d, 0d, 250, this, labelOrientation); - } - - - @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - - Label label = new Label(getLabel()); - - Canvas submit = getNextButton(); - - label.setHeight(25); - distancePanel.setHeight(50); - - layout.addMember(label); - layout.addMember(distancePanel); - layout.addMember(submit); - - initMinMaxValues(data); - initDefaultValues(data); - initHelperPanel(); - - return layout; - } - - - @Override - public Canvas createOld(DataList dataList) { - String s = getOldSelectionString(dataList); - String l = dataList.getLabel(); - - Label label = new Label(l); - Label selected = new Label(s); - - HLayout layout = new HLayout(); - - layout.setWidth(400); - label.setWidth(200); - selected.setWidth(130); - - layout.addMember(label); - layout.addMember(selected); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - - protected String getOldSelectionString(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data dFrom = getData(items, getLowerField()); - Data dTo = getData(items, getUpperField()); - Data dStep = getData(items, getStepField()); - - DataItem[] from = dFrom.getItems(); - DataItem[] to = dTo.getItems(); - DataItem[] step = dStep.getItems(); - - StringBuilder sb = new StringBuilder(); - sb.append(from[0].getLabel()); - sb.append(" " + getUnitFrom() + " - "); - sb.append(to[0].getLabel()); - sb.append(" " + getUnitTo() + " - "); - sb.append(step[0].getLabel()); - sb.append(" " + getUnitStep()); - - return sb.toString(); - } - - - protected String getLabel() { - return MSG.distance_state(); - } - - - protected String labelFrom() { - return getLabelFrom() + " [" + getUnitFrom() + "]"; - } - - - protected String getLabelFrom() { - return MSG.dpLabelFrom(); - } - - - protected String getUnitFrom() { - return MSG.dpUnitFrom(); - } - - - protected String labelTo() { - return getLabelTo() + " [" + getUnitTo() + "]"; - } - - - protected String getLabelTo() { - return MSG.dpLabelTo(); - } - - - protected String getUnitTo() { - return MSG.dpUnitTo(); - } - - - protected String labelStep() { - return getLabelStep() + " [" + getUnitStep() + "]"; - } - - - protected String getLabelStep() { - return MSG.dpLabelStep(); - } - - - protected String getUnitStep() { - return MSG.dpUnitStep(); - } - - - protected String getLowerField() { - return FIELD_LOWER; - } - - - protected String getUpperField() { - return FIELD_UPPER; - } - - - protected String getStepField() { - return FIELD_STEP; - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - - if (!distancePanel.validateForm()) { - errors.add(MSG.wrongFormat()); - - return errors; - } - - validateFrom(errors); - validateTo(errors); - - return errors; - } - - - protected void validateFrom(List<String> errors) { - double from = distancePanel.getFrom(); - - if (from < min || from > max) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - - String tmp = MSG.error_validate_lower_range(); - tmp = tmp.replace("$1", nf.format(from)); - tmp = tmp.replace("$2", nf.format(min)); - - distancePanel.setFrom(min); - errors.add(tmp); - } - } - - - protected void validateTo(List<String> errors) { - double to = distancePanel.getTo(); - - if (to < min || to > max) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - - String tmp = MSG.error_validate_upper_range(); - tmp = tmp.replace("$1", nf.format(to)); - tmp = tmp.replace("$2", nf.format(max)); - - distancePanel.setTo(max); - errors.add(tmp); - } - } - - - @Override - public Data[] getData() { - Data[] data = new Data[4]; - - data[0] = getDataFrom(); - data[1] = getDataTo(); - data[2] = getDataStep(); - - DataItem item = new DefaultDataItem("ld_mode","ld_mode", "distance"); - data[3] = new DefaultData( - "ld_mode", null, null, new DataItem[] { item }); - - return data; - } - - - protected Data getDataFrom() { - String value = String.valueOf(distancePanel.getFrom()); - String field = getLowerField(); - - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); - } - - - protected Data getDataTo() { - String value = String.valueOf(distancePanel.getTo()); - String field = getUpperField(); - - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); - } - - - protected Data getDataStep() { - String value = String.valueOf(distancePanel.getStep()); - String field = getStepField(); - - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); - } - - - @Override - public void onBlur(BlurEvent event) { - distancePanel.validateForm(); - } - - - protected void initMinMaxValues(DataList data) { - Data f = getData(data.getAll(), getLowerField()); - Data t = getData(data.getAll(), getUpperField()); - - DataItem[] fItems = f.getItems(); - DataItem[] tItems = t.getItems(); - - try { - min = Double.valueOf(fItems[0].getStringValue()); - max = Double.valueOf(tItems[0].getStringValue()); - } - catch (NumberFormatException nfe) { - min = -Double.MAX_VALUE; - max = Double.MAX_VALUE; - } - } - - - protected void initDefaultValues(DataList data) { - initDefaultFrom(data); - initDefaultTo(data); - initDefaultStep(data); - } - - - protected void initDefaultFrom(DataList data) { - Data f = getData(data.getAll(), getLowerField()); - - double from = getDefaultFrom(); - - try { - from = getDefaultValue(f); - } - catch (NumberFormatException nfe) { - // do nothing - } - - distancePanel.setFrom(from); - } - - - protected double getDefaultFrom() { - return min; - } - - - protected void initDefaultTo(DataList data) { - Data t = getData(data.getAll(), getUpperField()); - - double to = getDefaultTo(); - - try { - to = getDefaultValue(t); - } - catch (NumberFormatException nfe) { - // do nothing - } - - distancePanel.setTo(to); - } - - - protected double getDefaultTo() { - return max; - } - - - protected void initDefaultStep(DataList data) { - Data s = getData(data.getAll(), getStepField()); - - double step = getDefaultStep(); - - try { - step = getDefaultValue(s); - } - catch (NumberFormatException nfe) { - // do nothing - } - - distancePanel.setStep(step); - } - - - protected double getDefaultStep() { - return DEFAULT_STEP_WIDTH; - } - - - protected double getDefaultValue(Data data) - throws NumberFormatException - { - DataItem def = data.getDefault(); - String defValue = def != null ? def.getStringValue() : null; - - return Double.valueOf(defValue); - } - - - protected void initHelperPanel() { - distancesTable = new RangeTable(); - locationsTable = new LocationsTable(); - - Config config = Config.getInstance(); - String url = config.getServerUrl(); - String river = getRiverName(); - - distancesTable.setAutoFetchData(true); - locationsTable.setAutoFetchData(true); - distancesTable.setDataSource(new DistanceInfoDataSource( - url, river, "distances")); - locationsTable.setDataSource(new DistanceInfoDataSource( - url, river, "locations")); - - distancesTable.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(RecordClickEvent e) { - Record r = e.getRecord(); - - String from = r.getAttribute("from"); - String to = r.getAttribute("to"); - - try { - distancePanel.setFrom(Double.valueOf(from)); - distancePanel.setTo(Double.valueOf(to)); - } - catch (NumberFormatException nfe) { - SC.warn(MSG.wrongFormat()); - } - } - }); - - locationsTable.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(RecordClickEvent e) { - Record r = e.getRecord(); - int field = e.getFieldNum(); - - try { - String value = r.getAttribute("from"); - - switch (field) { - case 0: - distancePanel.setFrom(Double.valueOf(value)); - break; - case 1: - distancePanel.setTo(Double.valueOf(value)); - break; - } - } - catch (NumberFormatException nfe) { - SC.warn(MSG.wrongFormat()); - } - } - }); - - tabs = new TabSet(); - tabs.setWidth100(); - tabs.setHeight100(); - - Tab locations = new Tab(MSG.locations()); - Tab distances = new Tab(MSG.distance()); - - locations.setPane(locationsTable); - distances.setPane(distancesTable); - - tabs.addTab(locations, 0); - tabs.addTab(distances, 1); - - filterResultCount = new StaticTextItem(MSG.resultCount()); - filterResultCount.setTitleAlign(Alignment.LEFT); - filterResultCount.setTitleStyle("color: #000"); - - filterDescription = new TableFilter(); - filterDescription.setHeight("30px"); - filterDescription.addFilterHandler(this); - - filterRange = new RangeTableFilter(); - filterRange.setHeight("30px"); - filterRange.addFilterHandler(this); - filterRange.setVisible(false); - - SelectItem filterCriteria = new SelectItem(); - filterCriteria.setShowTitle(false); - filterCriteria.setWidth(100); - filterCriteria.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent e) { - if(e.getValue().toString().equals("range")) { - filterRange.setVisible(true); - filterDescription.setVisible(false); - filterDescription.clear(); - } - else { - filterRange.setVisible(false); - filterRange.clear(); - filterDescription.setVisible(true); - } - } - }); - - LinkedHashMap<String, String> filterMap = - new LinkedHashMap<String, String>(); - filterMap.put("description", MSG.description()); - filterMap.put("range", MSG.range()); - filterCriteria.setValueMap(filterMap); - filterCriteria.setValue("description"); - - DynamicForm form = new DynamicForm(); - form.setFields(filterCriteria); - - DynamicForm form2 = new DynamicForm(); - form2.setFields(filterResultCount); - - HLayout filterLayout = new HLayout(); - filterLayout.addMember(form); - filterLayout.addMember(filterDescription); - filterLayout.addMember(filterRange); - filterLayout.setHeight(30); - tabs.addTabSelectedHandler(new TabSelectedHandler() { - @Override - public void onTabSelected(TabSelectedEvent evt) { - filterDescription.clear(); - filterRange.clear(); - filterResultCount.setValue(""); - - Canvas c = evt.getTabPane(); - if(c instanceof ListGrid) { - currentFiltered = (ListGrid)c; - } - } - }); - - helperContainer.addMember(tabs); - helperContainer.addMember(filterLayout); - helperContainer.addMember(form2); - } - - - @Override - public void onFilterCriteriaChanged(StringFilterEvent event) { - String search = event.getFilter(); - - if (search != null && search.length() > 0) { - Criteria c = new Criteria("description", search); - locationsTable.filterData(c); - distancesTable.filterData(c); - filterResultCount.setValue(currentFiltered.getRecords().length); - } - else { - locationsTable.clearCriteria(); - distancesTable.clearCriteria(); - filterResultCount.setValue(""); - } - } - - - @Override - public void onFilterCriteriaChanged(RangeFilterEvent event) { - Float from = event.getFrom() - 0.001f; - Float to = event.getTo() + 0.001f; - - Criterion combinedFilter = null; - Criterion locationFilter = null; - if (from.equals(Float.NaN) && to.equals(Float.NaN)) { - locationsTable.clearCriteria(); - distancesTable.clearCriteria(); - filterResultCount.setValue(""); - return; - } - else if (from.equals(Float.NaN)) { - combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); - locationFilter = - new Criterion("from", OperatorId.LESS_OR_EQUAL, to); - locationsTable.filterData(locationFilter); - distancesTable.filterData(combinedFilter); - filterResultCount.setValue(currentFiltered.getRecords().length); - return; - } - else if (to.equals(Float.NaN)) { - combinedFilter = - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); - } - else { - AdvancedCriteria c1 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), - new Criterion("from", OperatorId.LESS_OR_EQUAL, to) - }); - - AdvancedCriteria c2 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), - new Criterion("to", OperatorId.LESS_OR_EQUAL, to) - }); - - AdvancedCriteria c3 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("from", OperatorId.LESS_OR_EQUAL, to), - new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) - }); - - combinedFilter = - new AdvancedCriteria(OperatorId.OR, new Criterion[] { - c1, c2, c3 - }); - } - locationsTable.filterData(combinedFilter); - distancesTable.filterData(combinedFilter); - filterResultCount.setValue(currentFiltered.getRecords().length); - - } - - - protected String getRiverName() { - ArtifactDescription adescr = artifact.getArtifactDescription(); - return adescr.getRiver(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,280 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.TitleOrientation; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.FocusHandler; - -import de.intevation.flys.client.client.FLYSConstants; - -import java.util.Map; - -public class DoubleArrayPanel -extends DynamicForm -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected TextItem ti; - - private String title; - - /** The constant input field name. */ - public static final String FIELD_NAME = "doublearray"; - - - public DoubleArrayPanel( - String title, - double[] values, - BlurHandler handler) - { - this(title, values, handler, null, TitleOrientation.RIGHT); - } - - - /** - * Creates a new form with a single input field that displays an array of - * double values. - * - * @param name The name of the TextItem. - * @param title The title of the TextItem. - * @param values The double values that should be displayed initially. - * @param blurHandler The BlurHandler that is used to valide the input. - * @param focusHandler The FocueHandler that is used to valide the input. - */ - public DoubleArrayPanel( - String title, - double[] values, - BlurHandler blurHandler, - FocusHandler focusHandler, - TitleOrientation titleOrientation) - { - this.title = title; - ti = new TextItem(FIELD_NAME); - StaticTextItem sti = new StaticTextItem("staticarray"); - - ti.setShowTitle(false); - sti.setShowTitle(false); - sti.setValue(title); - - ti.addBlurHandler(blurHandler); - if (focusHandler != null) { - ti.addFocusHandler(focusHandler); - } - - if (titleOrientation == TitleOrientation.RIGHT) { - setFields(ti, sti); - } - else { - setFields(sti, ti); - } - - setTitleOrientation(titleOrientation); - setNumCols(2); - - if (values == null) { - return; - } - - NumberFormat f = NumberFormat.getDecimalFormat(); - - StringBuilder text = new StringBuilder(); - boolean firstItem = true; - - for (double val: values) { - if (!firstItem) { - text.append(" "); - } - - text.append(f.format(val)); - - firstItem = false; - } - - ti.setValue(text.toString()); - } - - - /** - * This method takes the double array to set the values to the textbox. - * - * @param values The double values. - */ - public void setValues(double[] values) { - NumberFormat f = NumberFormat.getDecimalFormat(); - - if(values == null || values.length == 0) { - ti.clearValue(); - return; - } - StringBuilder text = new StringBuilder(); - boolean firstItem = true; - if (values != null) { - for (double val: values) { - if (!firstItem) { - text.append(" "); - } - - text.append(f.format(val)); - - firstItem = false; - } - } - - ti.clearValue(); - ti.setValue(text.toString()); - } - - - /** - * This method appends a double value to the current list of values. - * - * @param value A new value. - */ - public void addValue(double value) { - NumberFormat f = NumberFormat.getDecimalFormat(); - - String current = ti.getValueAsString(); - - if (current == null || current.length() == 0) { - current = f.format(value); - } - else { - current += " " + f.format(value); - } - - ti.setValue(current); - } - - - protected boolean validateForm() { - return validateForm(ti); - } - - - /** - * This method validates the entered text in the location input field. If - * there are values that doesn't represent a valid location, an error is - * displayed. - * - * @param item The FormItem. - */ - @SuppressWarnings("unchecked") - protected boolean validateForm(FormItem item) { - if (item instanceof StaticTextItem) { - return true; - } - - boolean valid = true; - String value = (String) item.getValue(); - - if (value == null) { - return valid; - } - - String[] parts = value.split("\\s+"); - - if (parts == null) { - return valid; - } - - NumberFormat nf = NumberFormat.getDecimalFormat(); - @SuppressWarnings("rawtypes") - Map errors = getErrors(); - - try { - for (String part: parts) { - - if (part.length() == 0) { - continue; - } - - nf.parse(part); - } - - errors.remove(item.getFieldName()); - } - catch (NumberFormatException nfe) { - errors.put(item.getFieldName(), MESSAGES.wrongFormat()); - - valid = false; - } - - setErrors(errors, true); - - return valid; - } - - - /** - * This method returns the double array that has been entered in - * <i>item</i>. - * - * @param item The item that contains the desired values. - * - * @return the values as double array. - */ - public double[] getInputValues(FormItem item) { - String value = (String) item.getValue(); - - if (value == null) { - return null; - } - - String[] parts = value.split("\\s+"); - - if (parts == null) { - return null; - } - - NumberFormat f = NumberFormat.getDecimalFormat(); - - double[] values = new double[parts.length]; - - int i = 0; - OUTER: for (String part: parts) { - if (part.length() == 0) { - continue; - } - - try { - double x = f.parse(part); - for (int j = 0; j < i; ++j) { - if (values[j] == x) { - continue OUTER; - } - } - values[i++] = x; - } - catch (NumberFormatException nfe) { - // do nothing - } - } - - double [] out = new double[i]; - System.arraycopy(values, 0, out, 0, i); - - return out; - } - - - /** - * Returns the double values of this panel. - * - * @return the double values of this panel. - */ - public double[] getInputValues() { - return getInputValues(ti); - } - - public String getItemTitle() { - return this.title; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleInputPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.List; - -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class DoubleInputPanel -extends AbstractUIProvider -{ - - private static final long serialVersionUID = 2006773072352563622L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - private TextItem inputPanel; - - private double value; - - protected String dataName; - - - public DoubleInputPanel() { - dataName = "outliers"; - } - - - public DoubleInputPanel(String dataName) { - this.dataName = dataName; - } - - - @Override - public Canvas create(DataList list) { - VLayout layout = new VLayout(); - - Canvas helper = createHelper(); - this.helperContainer.addMember(helper); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(list); - - layout.addMember(widget); - layout.addMember(submit); - return layout; - } - - - /** Create a labelled input-panel. */ - public Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - - Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - DataItem defaultItem = data.get(0).getDefault(); - - DynamicForm form = new DynamicForm(); - inputPanel = new TextItem(); - inputPanel.setTitle(dataName); - inputPanel.setShowTitle(false); - - if (defaultItem != null) { - inputPanel.setValue(defaultItem.getStringValue()); - } - - form.setFields(inputPanel); - - layout.addMember(title); - layout.addMember(form); - - return layout; - } - - - protected Canvas createHelper() { - return new VLayout(); - } - - - /** Create canvas to show previously entered value. */ - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data d = getData(items, dataName); - DataItem[] item = d.getItems(); - - String v = item[0].getLabel(); - - Label old = new Label(v); - old.setWidth(130); - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - boolean valid = saveDataValues(); - if(valid) { - - String vs = Double.valueOf(this.value).toString(); - DataItem item = new DefaultDataItem(dataName, dataName, vs); - data.add(new DefaultData( - dataName, - null, - null, - new DataItem[] { item })); - } - - return data.toArray(new Data[data.size()]); - } - - - protected boolean saveDataValues() { - String st = inputPanel.getValueAsString(); - if (st == null) { - SC.warn("fehler... TODO"); - return false; - } - - try { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double d = nf.parse(st); - this.value = d; - } - catch(NumberFormatException nfe) { - SC.warn("fehler... nfe... TODO"); - return false; - } - return true; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangeOnlyPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.widgets.form.fields.FloatItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; - - -public class DoubleRangeOnlyPanel extends DoubleRangePanel { - - public DoubleRangeOnlyPanel( - String titleFrom, - String titleTo, - double from, - double to, - int width, - BlurHandler handler - ) { - this(titleFrom, titleTo, from, to, width, handler, "right"); - } - - - public DoubleRangeOnlyPanel( - String titleFrom, - String titleTo, - double from, - double to, - int width, - BlurHandler handler, - String labelOrientation - ) { - super(); - - fromItem = new FloatItem(FIELD_FROM); - toItem = new FloatItem(FIELD_TO); - stepItem = new FloatItem(FIELD_WIDTH); - - fromItem.addBlurHandler(handler); - toItem.addBlurHandler(handler); - - NumberFormat nf = NumberFormat.getDecimalFormat(); - - fromItem.setValue(nf.format(from)); - toItem.setValue(nf.format(to)); - - StaticTextItem fromText = new StaticTextItem("staticFrom"); - fromText.setValue(titleFrom); - fromText.setShowTitle(false); - fromItem.setShowTitle(false); - - StaticTextItem toText = new StaticTextItem("staticTo"); - toText.setValue(titleTo); - toText.setShowTitle(false); - toItem.setShowTitle(false); - - int itemWidth = width / 4; - fromItem.setWidth(itemWidth); - fromText.setWidth(itemWidth); - toItem.setWidth(itemWidth); - toText.setWidth(itemWidth); - - if (labelOrientation.equals("right")) { - setFields(fromItem, fromText, toItem, toText); - } - else { - setFields(fromText, fromItem, toText, toItem); - } - - setFixedColWidths(false); - setNumCols(4); - setWidth(width); - setAlign(Alignment.CENTER); - } - - - @Override - public boolean validateForm() { - return validateForm(fromItem) && validateForm(toItem); - } - - - @Override - public double getStep() { - return -1; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,296 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.FloatItem; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; - -import de.intevation.flys.client.client.FLYSConstants; - -import java.util.Map; - - -/** - * This class creates a DynamicForm with three input fields. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DoubleRangePanel -extends DynamicForm -{ - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - - /** The constant name of the input field to enter the start of a distance.*/ - public static final String FIELD_FROM = "from"; - - /** The constant name of the input field to enter the end of a distance.*/ - public static final String FIELD_TO = "to"; - - /** The constant name of the input field to enter the step width of a - * distance.*/ - public static final String FIELD_WIDTH = "step"; - - /** The textboxes */ - protected FloatItem fromItem; - protected FloatItem toItem; - protected FloatItem stepItem; - - - public DoubleRangePanel() { - } - - - /** - * Creates a new form with a single input field that displays an array of - * double values. - * - * @param name The name of the TextItem. - * @param title The title of the TextItem. - * @param values The double values that should be displayed initially. - * @param handler The BlurHandler that is used to valide the input. - */ - public DoubleRangePanel( - String titleFrom, String titleTo, String titleStep, - double from, double to, double step, - int width, - BlurHandler handler) - { - this( - titleFrom, titleTo, titleStep, - from, to, step, - width, - handler, - "right"); - } - - - public DoubleRangePanel( - String titleFrom, String titleTo, String titleStep, - double from, double to, double step, - int width, - BlurHandler handler, - String labelOrientation) - { - fromItem = new FloatItem(FIELD_FROM); - toItem = new FloatItem(FIELD_TO); - stepItem = new FloatItem(FIELD_WIDTH); - - fromItem.addBlurHandler(handler); - toItem.addBlurHandler(handler); - stepItem.addBlurHandler(handler); - - NumberFormat f = NumberFormat.getDecimalFormat(); - - fromItem.setValue(f.format(from)); - toItem.setValue(f.format(to)); - stepItem.setValue(f.format(step)); - - StaticTextItem fromText = new StaticTextItem("staticFrom"); - fromText.setValue(titleFrom); - fromText.setShowTitle(false); - fromItem.setShowTitle(false); - - StaticTextItem toText = new StaticTextItem("staticTo"); - toText.setValue(titleTo); - toText.setShowTitle(false); - toItem.setShowTitle(false); - - StaticTextItem stepText = new StaticTextItem("staticStep"); - stepText.setValue(titleStep); - stepText.setShowTitle(false); - stepItem.setShowTitle(false); - - int itemWidth = width / 6; - fromItem.setWidth(itemWidth); - fromText.setWidth(itemWidth); - toItem.setWidth(itemWidth); - toText.setWidth(itemWidth); - stepItem.setWidth(itemWidth); - stepText.setWidth(itemWidth); - - if (labelOrientation.equals("right")) { - setFields(fromItem, fromText, toItem, toText, stepItem, stepText); - } - else { - setFields(fromText, fromItem, toText, toItem, stepText, stepItem); - } - - setFixedColWidths(false); - setNumCols(6); - setWidth(width); - setAlign(Alignment.CENTER); - } - - - /** - * This method takes distances values and sets them to the textboxes - * visualizied by this widget. - * - * @param from The from value. - * @param to The to value. - * @param steps The max steps. - */ - public void setValues(double from, double to, double steps) { - NumberFormat f = NumberFormat.getDecimalFormat(); - - fromItem.setValue(f.format(from)); - toItem.setValue(f.format(to)); - stepItem.setValue(f.format(steps)); - } - - - public boolean validateForm() { - try { - return - validateForm(fromItem) && - validateForm(toItem) && - validateForm(stepItem); - } - catch (NumberFormatException nfe) { - return false; - } - } - - /** - * This method validates the entered text in the input fields. If - * there are values that doesn't represent a valid float, an error is - * displayed. - * - * @param item The FormItem. - */ - @SuppressWarnings("unchecked") - protected boolean validateForm(FormItem item) { - if (item instanceof StaticTextItem) { - return true; - } - - boolean valid = true; - - String v = (String) item.getValue(); - - NumberFormat f = NumberFormat.getDecimalFormat(); - @SuppressWarnings("rawtypes") - Map errors = getErrors(); - - try { - if (v == null) { - throw new NumberFormatException("empty"); - } - - f.parse(v); - - errors.remove(item.getFieldName()); - } - catch (NumberFormatException nfe) { - errors.put(item.getFieldName(), MESSAGES.wrongFormat()); - - item.focusInItem(); - - valid = false; - } - - setErrors(errors, true); - - return valid; - } - - - /** - * Returns the double value of <i>value</i>. - * - * @return the double value of <i>value</i>. - */ - protected double getDouble(String value) { - NumberFormat f = NumberFormat.getDecimalFormat(); - - String[] splitted = value.split(" "); - - return f.parse(splitted[0]); - } - - - /** - * Returns the start value. - * - * @return the start value. - */ - public double getFrom() throws NullPointerException { - String v = getValueAsString(FIELD_FROM); - - return getDouble(v); - } - - - /** - * Returns the end value. - * - * @return the end value. - */ - public double getTo() throws NullPointerException { - String v = getValueAsString(FIELD_TO); - - return getDouble(v); - } - - - /** - * Returns the step width. - * - * @return the step width. - */ - public double getStep() throws NullPointerException { - String v = getValueAsString(FIELD_WIDTH); - - return getDouble(v); - } - - - /** - * Sets the value of the field with name <i>fieldname</i>. - * - * @param value The new value. - * @param fieldname The name of the field. - */ - public void setDoubleValue(double value, String fieldname) { - NumberFormat f = NumberFormat.getDecimalFormat(); - setValue(fieldname, f.format(value)); - } - - - /** - * Sets a new start value. - * - * @param value The new start value. - */ - public void setFrom(double value) { - setDoubleValue(value, FIELD_FROM); - } - - - /** - * Sets a new end value. - * - * @param value The new end value. - */ - public void setTo(double value) { - setDoubleValue(value, FIELD_TO); - } - - - /** - * Sets a new step width. - * - * @param value The new step width. - */ - public void setStep(double value) { - setDoubleValue(value, FIELD_WIDTH); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ExportPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.List; -import java.util.MissingResourceException; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.ExportMode; -import de.intevation.flys.client.shared.model.Facet; -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; - - -/** - * A panel that displays an download icon for all available export modes of a - * Collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ExportPanel extends VLayout { - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected Collection c; - protected List<ExportMode> exports; - - /** This layout will store a list of available export types.*/ - protected HLayout container; - - - public ExportPanel(Collection c, List<ExportMode> exports) { - super(); - - this.c = c; - this.exports = exports; - this.container = new HLayout(); - - Label title = new Label(MSG.dataexport()); - title.setHeight(15); - title.setStyleName("fontNormalSmallUnderlined"); - - addMember(title); - addMember(createExportItems()); - - setHeight(45); - setMembersMargin(5); - } - - - /** - * This method is used to create an item (created by createExportButton) for - * each facet for each export mode. - * - * @return a horizontal list of buttons. - */ - protected HLayout createExportItems() { - HLayout layout = new HLayout(); - - for (ExportMode mode: exports) { - String name = mode.getName(); - List<Facet> facets = mode.getFacets(); - - for (Facet facet: facets) { - if (name.equals("fix_wq_curve_at_export")) { - continue; - } - String filename = name; - if (name.equals("computed_dischargecurve_at_export")) { - filename = "dischargecurve"; - } - layout.addMember(createExportButton( - name, - facet.getName(), - filename)); - } - } - - return layout; - } - - - /** - * This method is used to create a button (with click handler) for a - * concrete export mode / type. - * - * @param name The name of the export. - * @param facet The name of the export type (e.g. CSV, WST). - * - * @return an image with click handler. - */ - protected Canvas createExportButton( - String name, - String facet, - String filename - ) { - String url = getExportUrl(name, facet, filename); - String imgUrl = GWT.getHostPageBaseURL(); - if (facet.equals("pdf")) { - imgUrl += MSG.downloadPDF(); - } - else if (facet.equals("at")) { - imgUrl += MSG.downloadAT(); - } - else if (facet.equals("wst")) { - imgUrl += MSG.downloadWST(); - } - else if (facet.equals("csv")) { - imgUrl += MSG.downloadCSV(); - } - else { - imgUrl += MSG.imageSave(); - } - ImgLink link = new ImgLink(imgUrl, url, 30, 30); - link.setTooltip(getTooltipText(name, facet)); - - return link; - } - - - /** - * Creates the URL used to trigger an export. - * - * @param name The name of the export. - * @param facet The name of the export type (e.g. CSV, WST). - * - * @return the export URL. - */ - protected String getExportUrl(String name, String facet, String filename) { - Config config = Config.getInstance(); - - String url = GWT.getModuleBaseURL(); - url += "export"; - url += "?uuid=" + c.identifier(); - url += "&name=" + filename; - url += "&mode=" + name; - url += "&type=" + facet; - url += "&server=" + config.getServerUrl(); - url += "&locale=" + config.getLocale(); - - return url; - } - - - /** - * Creates a text used as tooltip for a specific export and type. - * - * @param name The name of the export. - * @param facet The name of the export type (e.g. CSV, WST). - * - * @return a tooltip text. - */ - protected String getTooltipText(String name, String facet) { - try { - return MSG.getString(name) + " | " + MSG.getString(facet); - } - catch (MissingResourceException mre) { - return name + " | " + facet; - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/FLYSHeader.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,291 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.LocaleInfo; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.util.BooleanCallback; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; - -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.UserService; -import de.intevation.flys.client.client.services.UserServiceAsync; -import de.intevation.flys.client.shared.model.User; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class FLYSHeader extends HLayout { - - /** The interface that provides the message resources. */ - private FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - /** The height used for this header.*/ - public static final int HEIGHT = 56; - - /** The height used for the images.*/ - public static final int IMG_HEIGHT = 50; - - /** The user that is currently logged in. */ - private User currentUser; - - /** The label that displays the current logged in user. */ - private Label userText; - - /** The button to log the current user out.*/ - private Button logout; - - /** The button to open the project list.*/ - private Button projectList; - - /** The button to switch between the english and german version.*/ - private Button language; - - /** The button to open an info panel.*/ - private Button info; - - private UserServiceAsync userService = - GWT.create(UserService.class); - - /** An instance to FLYS.*/ - private FLYS flys; - - - public FLYSHeader(FLYS flys) { - this.flys = flys; - - String guest = MESSAGES.user() + " " + MESSAGES.guest(); - - userText = new Label(guest); - projectList = new Button(MESSAGES.manage_projects()); - logout = new Button(MESSAGES.logout()); - language = new Button(MESSAGES.switch_language()); - info = new Button(MESSAGES.info()); - - projectList.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - GWT.log("Clicked 'Open ProjectList' button."); - getFlys().openProjectList(); - } - }); - - logout.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - GWT.log("Clicked 'logout' button."); - userService.logoutCurrentUser(new AsyncCallback<Void>() { - public void onFailure(Throwable caught) { - } - - public void onSuccess(Void result) { - /* Just reload the page. GGInAFilter is goint to redirect - * to the correct login page */ - Window.Location.reload(); - } - }); - - } - }); - - language.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - LocaleInfo info = LocaleInfo.getCurrentLocale(); - final String currentLocale = info.getLocaleName(); - final String newLocale = currentLocale.equals("de") - ? "en" - : "de"; - - SC.confirm(MESSAGES.warning(), MESSAGES.warning_language(), - new BooleanCallback() { - @Override - public void execute(Boolean value) { - if (value) { - switchLanguage(currentLocale, newLocale); - } - } - }); - } - }); - - info.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - GWT.log("Clicked 'info' button."); - GWT.log("IMPLEMENT the 'open info panel' function."); - } - }); - init(); - } - - public void init() { - setStyleName("header"); - setWidth100(); - setHeight(HEIGHT); - setBackgroundColor("#a9c9e6"); - setLayoutLeftMargin(5); - setLayoutRightMargin(5); - - String baseUrl = GWT.getHostPageBaseURL(); - - Img flys = new Img( - baseUrl + MESSAGES.flysLogo(), - 50, - IMG_HEIGHT); - - Img bfg = new Img( - baseUrl + MESSAGES.bfgLogoSmall(), - 150, - IMG_HEIGHT); - - Label fullname = new Label(MESSAGES.fullname()); - fullname.setHeight(HEIGHT - IMG_HEIGHT); - fullname.setStyleName("fontBlackMid"); - - HLayout left = new HLayout(); - left.setDefaultLayoutAlign(VerticalAlignment.CENTER); - left.setMembersMargin(3); - left.addMember(flys); - left.addMember(fullname); - - HLayout right = new HLayout(); - right.setAlign(Alignment.RIGHT); - right.setDefaultLayoutAlign(Alignment.RIGHT); - right.setDefaultLayoutAlign(VerticalAlignment.CENTER); - right.setMembersMargin(3); - right.setLayoutRightMargin(5); - - projectList.setStyleName("manageProjects"); - userText.setStyleName("fontBlackSmall"); - logout.setStyleName("fontLightSmall"); - language.setStyleName("fontLightSmall"); - info.setStyleName("fontLightSmall"); - - userText.setAlign(Alignment.RIGHT); - userText.setWidth(200); - logout.setWidth(70); - info.setWidth(40); - language.setWidth(70); - - left.addMember(projectList); - if (this.flys.isProjectListVisible()) { - hideProjectButton(); - } - else { - showProjectButton(); - } - - right.addMember(userText); - right.addMember(logout); - right.addMember(language); - right.addMember(info); - right.addMember(bfg); - - addMember(left); - addMember(right); - } - - /** - * Returns the FLYS instance stored in this class. - * - * @return the flys instance. - */ - private FLYS getFlys() { - return flys; - } - - /** - * This method triggers the language switch between the <i>currentLocale</i> - * and the <i>newLocale</i>. The switch is done by replacing a "locale=" - * parameter in the url of the application. We could use the GWT UrlBuilder - * class to create a new URL, but - in my eyes - this class is a bit - * inconsistens in its implementation. - * - * @param currentLocale The current locale string (e.g. "en"). - * @param newLocale The new locale string (e.g. "de"). - */ - private void switchLanguage(String currentLocale, String newLocale) { - String newLocation = Window.Location.getHref(); - - if (newLocation.endsWith("/")) { - newLocation = newLocation.substring(0, newLocation.length()-1); - } - - String replace = null; - String replaceWith = null; - - if (newLocation.indexOf("&locale=") >= 0) { - replace = currentLocale.equals("de") - ? "&locale=de" - : "&locale=en"; - - replaceWith = "&locale=" + newLocale; - } - else if (newLocation.indexOf("?locale=") >= 0) { - replace = currentLocale.equals("de") - ? "?locale=de" - : "?locale=en"; - - replaceWith = "?locale=" + newLocale; - } - else { - newLocation += newLocation.indexOf("?") >= 0 - ? "&locale=" + newLocale - : "?locale=" + newLocale; - } - - if (replace != null && replaceWith != null) { - newLocation = newLocation.replace(replace, replaceWith); - } - - Window.open(newLocation, "_self", ""); - } - - /** - * Update the text field that shows the current user. If no user is - * currently logged in, the text will display {@link FLYSConstants.guest()}. - */ - private void updateCurrentUser() { - String name = currentUser != null - ? currentUser.getName() - : MESSAGES.guest(); - - GWT.log("Update the current user: " + name); - - String username = MESSAGES.user() + " " + name; - userText.setContents(username); - } - - /** - * Set the current {@link User} and call {@link updateCurrentUser()} - * afterwards. - * - * @param user the new user. - */ - public void setCurrentUser(User currentUser) { - this.currentUser = currentUser; - - updateCurrentUser(); - } - - public void hideProjectButton() { - this.projectList.hide(); - } - - public void showProjectButton() { - this.projectList.show(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/FLYSView.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.layout.HLayout; - - -/** - * Vertically speaking the main part of the ui (containing projectlist - * and workspace). - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class FLYSView extends Canvas { - - /** The project list displaying the projects of a user.*/ - protected ProjectList projectList; - - /** The workspace that handles the artifact collection views.*/ - protected FLYSWorkspace workspace; - - /** The layout provided by this widget.*/ - protected HLayout layout; - - - /** - * The default constructor for creating a new empty FLYSView. After creating - * the components, {@link init()} is called to do the layout work. - */ - public FLYSView() { - layout = new HLayout(); - - init(); - } - - - /** - * This method is called to do the layout work. - */ - protected void init() { - setWidth("100%"); - setHeight("*"); - - setStyleName("bgWhite"); - setBorder("1px solid #808080"); - - layout.setHeight("100%"); - layout.setWidth("100%"); - - addChild(layout); - } - - - /** - * Set the current project list. Previous ProjectLists are replaced by the - * new one. - */ - public void setProjectList(ProjectList projectList) { - if (this.projectList != null) { - removeChild(this.projectList); - } - - this.projectList = projectList; - layout.addMember(this.projectList); - } - - - /** - * Set the current FLYSWorkspace. Previous workspaces are replaced by the - * new one. - * - * @param workspaces The new FLYSWorkspace. - */ - public void setFLYSWorkspace(FLYSWorkspace workspace) { - if (this.workspace != null) { - removeChild(this.workspace); - } - - this.workspace = workspace; - layout.addMember(this.workspace); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/FLYSWorkspace.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; - -import java.util.HashMap; -import java.util.Map; - - -/** - * "Workspace" canvas showing the CollectionViews (subwindows). - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class FLYSWorkspace extends Canvas { - - /** The maximal number of windows that fit into the browser view when an - * offset is used to move windows initially.*/ - public static int MAX_WINDOWS = 10; - - /** The number of pixels used to move windows.*/ - public static int WINDOW_OFFSET = 20; - - /** A map that contains the open CollectionViews. */ - protected Map<String, CollectionView> views; - - /** The interface that provides the message resources. */ - private FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - /** Application instance. */ - private FLYS flys; - - - /** - * The default constructor creates an empty FLYSWorkspace with no - * CollectionViews opened. - */ - public FLYSWorkspace(FLYS flys) { - this.flys = flys; - views = new HashMap<String, CollectionView>(); - - setWidth("100%"); - setHeight("100%"); - - addBackgroundWorkspace(); - } - - - /** - * This method adds a new CollectionView to this workspace and stores a - * reference in {@link views}. - * - * @param collectionView A new CollectionView. - */ - public void addView(String uuid, CollectionView collectionView) { - collectionView.moveTo(0, 0); - collectionView.setMaximized(true); - - views.put(uuid, collectionView); - addChild(collectionView); - } - - - public void removeProject(String uuid) { - views.remove(uuid); - } - - - public void bringUp(String uuid) { - CollectionView view = views.get(uuid); - - if (view != null) { - view.show(); - view.restore(); - } - else { - GWT.log("FLYSWorkspace.bringUp() failed!"); - } - } - - - /** - * Removes a project from workspace (view) and clears its reference from - * hash map. - * - * @param uuid The project's uuid. - */ - public void destroyProject(String uuid) { - CollectionView project = views.get(uuid); - - if (project != null) { - removeProject(uuid); - project.destroy(); - } - } - - - public void updateTitle(String uuid, String title) { - CollectionView view = views.get(uuid); - view.setTitle(title); - } - - - public boolean hasView(String uuid) { - if(views.get(uuid) != null) { - return true; - } - return false; - } - - private void addBackgroundWorkspace() { - String baseUrl = GWT.getHostPageBaseURL(); - Img bfg = new Img( - baseUrl + MESSAGES.bfgLogo()); - bfg.setWidth(150); - bfg.setHeight(100); - bfg.setLayoutAlign(Alignment.RIGHT); - - HLayout backgroundlayout = new HLayout(); - backgroundlayout.setHeight100(); - backgroundlayout.setWidth100(); - backgroundlayout.setDefaultLayoutAlign(Alignment.CENTER); - backgroundlayout.setDefaultLayoutAlign(VerticalAlignment.CENTER); - - Canvas spacer = new Canvas(); - spacer.setWidth("33%"); - - VLayout infobox = new VLayout(); - infobox.setHeight("*"); - infobox.setWidth("*"); - infobox.setDefaultLayoutAlign(Alignment.CENTER); - - Label welcome = new Label(MESSAGES.welcome()); - welcome.setAlign(Alignment.CENTER); - welcome.setStyleName("fontNormalBig"); - - Label lcreate = new Label(MESSAGES.welcome_open_or_create()); - lcreate.setStyleName("welcomeCreateText"); - lcreate.setWidth100(); - lcreate.setAlign(Alignment.CENTER); - - Button addbutton = new Button(MESSAGES.new_project()); - addbutton.setStyleName("projectsAddButton"); - addbutton.setAlign(Alignment.CENTER); - addbutton.setTitle(MESSAGES.new_project()); - addbutton.setAutoFit(true); - addbutton.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - flys.newProject(); - } - }); - - - infobox.addMember(welcome); - infobox.addMember(lcreate); - infobox.addMember(addbutton); - - backgroundlayout.addMember(spacer); - backgroundlayout.addMember(infobox); - backgroundlayout.addMember(spacer); - - addChild(backgroundlayout); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,405 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.DateRangeItem; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.ui.range.DischargeInfoDataSource; -import de.intevation.flys.client.client.widgets.DischargeTablesChart; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.LongRangeData; -import de.intevation.flys.client.shared.model.RangeData; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class GaugeTimeRangePanel extends RangePanel { - - private static final long serialVersionUID = -157571967010594739L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected ListGrid yearTable; - - protected DateRangeItem dateRange; - - protected Long maxUpper; - protected Long maxLower; - - - public GaugeTimeRangePanel() { - GWT.log("Creating YearInputPanel"); - yearTable = new ListGrid(); - yearTable.setAutoFetchData(true); - yearTable.setShowHeaderContextMenu(false); - } - - protected void setMaxUpper(DataList dataList) { - LongRangeData range = (LongRangeData) dataList.get(0); - setMaxUpper((Long) range.getUpper()); - } - - protected void setMaxUpper(Long maxUpper) { - this.maxUpper = maxUpper; - } - - protected void setMaxLower(DataList dataList) { - LongRangeData range = (LongRangeData) dataList.get(0); - setMaxLower((Long) range.getLower()); - } - - protected void setMaxLower(Long maxLower) { - this.maxLower = maxLower; - } - - @Override - public Canvas create(DataList data) { - setDataName(data); - - VLayout root = new VLayout(); - - root.addMember(createLabel(data)); - root.addMember(createForm(data)); - root.addMember(getNextButton()); - - initDefaults(data); - - initYearTable(); - - long gauge = getGaugeNumber(); - - Config config = Config.getInstance(); - String url = config.getServerUrl(); - yearTable.setDataSource(new DischargeInfoDataSource(url, gauge)); - - helperContainer.addMember(createHelperPanel()); - - setMaxUpper(data); - setMaxLower(data); - - return root; - } - - - protected Canvas createHelperPanel() { - TabSet tabs = new TabSet(); - - Tab table = new Tab(MSG.discharge_timeranges()); - Tab chart = new Tab(MSG.discharge_chart()); - - table.setPane(yearTable); - chart.setPane(new DischargeTablesChart(artifact)); - - tabs.addTab(table, 0); - tabs.addTab(chart, 1); - - return tabs; - } - - - /** Put defaults in form. */ - @Override - protected void initDefaults(DataList dataList) { - RangeData data = findRangeData(dataList); - - if (data != null) { - dateRange.setFromDate(new Date((Long)data.getLower())); - } - - dateRange.setToDate(new Date()); - } - - - @Override - public Canvas createOld(DataList dataList) { - GWT.log("create old date."); - Data data = dataList.get(0); - HLayout layout = new HLayout(); - - Label label = new Label(dataList.getLabel()); - label.setWidth(200); - label.setHeight(20); - - Date dl = new Date((Long)((LongRangeData)data).getLower()); - Date du = new Date((Long)((LongRangeData)data).getUpper()); - - @SuppressWarnings("deprecation") - DateTimeFormat dtf = DateTimeFormat.getMediumDateFormat(); - Label value = new Label(dtf.format(dl) + " - " + dtf.format(du)); - value.setHeight(20); - - layout.addMember(label); - layout.addMember(value); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - - @Override - protected Data[] getData() { - long lo = getLowerAsLong(); - long up = getUpperAsLong(); - - return new Data[] { new LongRangeData(getDataName(), null, lo, up) }; - } - - - @Override - protected Canvas createForm(DataList dataList) { - HLayout layout = new HLayout(); - DynamicForm form = new DynamicForm(); - dateRange = new DateRangeItem(); - dateRange.setToTitle(MESSAGES.to()); - dateRange.setFromTitle(MESSAGES.from()); - dateRange.setShowTitle(false); - form.setFields(dateRange); - - layout.addMember(form); - return layout; - - } - - - @Override - public Object getMaxLower() { - return maxLower; - } - - - protected long getLowerAsLong() { - Date d = dateRange.getFromDate(); - return d.getTime(); - } - - - protected long getUpperAsLong() { - Date d = dateRange.getToDate(); - return d.getTime(); - } - - - @Override - public Object getMaxUpper() { - Date d = dateRange.getToDate(); - return new Long(d.getTime()); - } - - - @Override - public void setLower(String lower) { - try { - long value = Long.valueOf(lower); - dateRange.setFromDate(new Date(value)); - } - catch (NumberFormatException nfe) { - GWT.log("could not parse lower date."); - SC.warn(MESSAGES.warning_cannot_parse_date()); - } - } - - - @Override - public void setUpper(String upper) { - try { - long value = Long.valueOf(upper); - dateRange.setToDate(new Date(value)); - } - catch (NumberFormatException nfe) { - GWT.log("could not parse upper date."); - SC.warn(MESSAGES.warning_cannot_parse_date()); - } - } - - - protected String buildDateString(String raw) { - if (raw == null || raw.length() == 0) { - return ""; - } - - long value = Long.valueOf(raw); - Date date = new Date(value); - @SuppressWarnings("deprecation") - DateTimeFormat dtf = DateTimeFormat.getMediumDateFormat(); - - return dtf.format(date); - } - - - protected ListGrid initYearTable() { - String baseUrl = GWT.getHostPageBaseURL(); - - yearTable.setWidth100(); - yearTable.setHeight100(); - yearTable.setShowRecordComponents(true); - yearTable.setShowRecordComponentsByCell(true); - yearTable.setEmptyMessage(MESSAGES.empty_filter()); - yearTable.setCanReorderFields(false); - - CellFormatter cf = new CellFormatter() { - @Override - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum - ) { - if (value == null) { - return null; - } - else if (value.toString().equals("-1")) { - return ""; - } - else if (colNum == 3 || colNum == 4) { - return buildDateString(value.toString()); - } - else { - return value.toString(); - } - } - }; - - - ListGridField addstart = new ListGridField ("", MESSAGES.from()); - addstart.setType (ListGridFieldType.ICON); - addstart.setWidth (20); - addstart.setCellIcon(baseUrl + MESSAGES.markerGreen()); - addstart.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(RecordClickEvent e) { - Record r = e.getRecord(); - if (r.getAttribute("start").equals("-1")) { - return; - } - else { - setLower(r.getAttribute("start")); - } - } - }); - - ListGridField addend = new ListGridField ("", MESSAGES.to()); - addend.setType (ListGridFieldType.ICON); - addend.setWidth (20); - addend.setCellIcon(baseUrl + MESSAGES.markerRed()); - addend.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(RecordClickEvent e) { - Record r = e.getRecord(); - if (r.getAttribute("end").equals("-1")) { - return; - } - else { - setUpper(r.getAttribute("end")); - } - } - }); - - ListGridField desc = - new ListGridField("description", MESSAGES.discharge_curve_gaugeless()); - desc.setType(ListGridFieldType.TEXT); - desc.setWidth("*"); - - ListGridField start = - new ListGridField("start", MESSAGES.start_year()); - start.setType(ListGridFieldType.INTEGER); - start.setWidth(100); - start.setCellFormatter(cf); - - ListGridField end = - new ListGridField("end", MESSAGES.end_year()); - end.setType(ListGridFieldType.INTEGER); - end.setWidth(100); - end.setCellFormatter(cf); - - yearTable.setFields(addstart, addend, desc, start, end); - - return yearTable; - } - - - protected long getGaugeNumber() { - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - String gauge = ""; - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - if (dl.getState().equals("state.winfo.historicalq.reference_gauge")) { - for (int j = 0; j < dl.size(); j++) { - Data d = dl.get(j); - DataItem[] di = d.getItems(); - if (di != null && di.length == 1) { - gauge = d.getItems()[0].getStringValue(); - } - } - } - } - } - try { - return Long.parseLong(gauge); - } - catch (NumberFormatException nfe) { - GWT.log("Error parsing gauge."); - return 0; - } - } - - - /** Return List of error messages, if not validated. */ - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - - Date from = dateRange.getFromDate(); - Date to = dateRange.getToDate(); - - if (from == null || to == null) { - String msg = MSG.error_validate_date_range(); - errors.add(msg); - } - - long maxLow = (Long) getMaxLower(); - long maxUpper = (Long) getMaxUpper(); - long inLow = from.getTime(); - long inUpper = to.getTime(); - - if (inLow < maxLow) { - errors.add(MSG.error_validate_date_range_invalid()); - } - else if (inUpper > maxUpper) { - errors.add(MSG.error_validate_date_range_invalid()); - } - else if (inLow > inUpper) { - errors.add(MSG.error_validate_date_range_invalid()); - } - - return errors; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/HWSDatacagePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; - -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.List; - - -public class HWSDatacagePanel -extends DatacagePanel -{ - public static final String OUT = "floodmap-hws"; - public static final String PARAMETERS = "hws:true;load-system:true"; - - - public HWSDatacagePanel() { - super(); - } - - - public HWSDatacagePanel(User user) { - super(user); - } - - - @Override - protected void createWidget() { - super.createWidget(); - widget.setIsMutliSelectable(true); - } - - - @Override - public String getOuts() { - return OUT; - } - - - @Override - public String getParameters() { - return PARAMETERS; - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - - return errors; - } - - @Override - public Canvas createOld(DataList dataList) { - GWT.log("old datacage##########################################"); - HLayout layout = new HLayout(); - VLayout vLayout = new VLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - int size = dataList.size(); - for (int i = 0; i < size; i++) { - Data data = dataList.get(i); - DataItem[] items = data.getItems(); - - for (DataItem item: items) { - HLayout hLayout = new HLayout(); - - hLayout.addMember(label); - hLayout.addMember(new Label(item.getLabel())); - - vLayout.addMember(hLayout); - vLayout.setWidth("130px"); - } - } - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - - @Override - protected Data[] getData() { - String[] selection = this.widget.getSelectionTitles(); - String result = ""; - boolean first = true; - if (selection != null) { - for (String record: selection) { - if (first) { - result += record; - first = false; - } - else { - result += ";" + record; - } - } - } - if (result.length() == 0) { - result = MSG.notselected(); - } - Data[] data = new Data[1]; - DataItem item = new DefaultDataItem( - "uesk.hws", "uesk.hws", result); - data[0] = new DefaultData("uesk.hws", null, null, new DataItem[] {item}); - - return data; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ImgLink.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.types.Overflow; -import com.smartgwt.client.widgets.HTMLPane; - - -public class ImgLink extends HTMLPane { - - private int width; - private int height; - - private String href; - private String imgUrl; - - private boolean newTab; - - - public ImgLink(String imgUrl, String href, int width, int height) { - super(); - - this.width = width; - this.height = height; - this.href = href; - this.imgUrl = imgUrl; - this.newTab = false; - - update(); - } - - - public ImgLink(String imgUrl, String href, int w, int h, boolean newTab) { - this(imgUrl, href, w, h); - this.newTab = newTab; - - update(); - } - - - protected void update() { - String target = newTab ? "_blank" : "_self"; - - setContents("<a target='" + target + "' href='" + href + "'><img src='" + imgUrl + "'></a>"); - setWidth(width); - setHeight(height); - setOverflow(Overflow.VISIBLE); - } - - - public void setSource(String href) { - this.href = href; - update(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.IntegerItem; -import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator; -import com.smartgwt.client.widgets.form.validator.Validator; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.IntegerRangeData; - - -public class IntegerRangePanel extends RangePanel { - - private static final long serialVersionUID = -7471199535764887461L; - - protected Integer maxLower; - protected Integer maxUpper; - - - @Override - protected Data[] getData() { - Integer lo = getLowerAsInt(); - Integer up = getUpperAsInt(); - - return new Data[] { new IntegerRangeData(getDataName(), null, lo, up) }; - } - - - @Override - protected FormItem newFormItem(String name) { - IntegerItem item = new IntegerItem(name, ""); - item.setShowTitle(false); - - return item; - } - - - @Override - protected Validator[] createLowerValidators(DataList dataList) { - setMaxLower(dataList); - setMaxUpper(dataList); - - Validator validator = newRangeValidator(); - - if (validator != null) { - return new Validator[] { validator }; - } - - return null; - } - - - @Override - protected Validator[] createUpperValidators(DataList dataList) { - setMaxLower(dataList); - setMaxUpper(dataList); - - Validator validator = newRangeValidator(); - - if (validator != null) { - return new Validator[] { validator }; - } - - return null; - } - - - @Override - public Object getMaxLower() { - return maxLower; - } - - - @Override - public Object getMaxUpper() { - return maxUpper; - } - - - public Integer getLowerAsInt() { - String raw = getLower(); - - if (raw != null && raw.length() > 0) { - try { - return Integer.valueOf(raw); - } - catch (NumberFormatException nfe) { - // do nothing - } - } - - return null; - } - - - public Integer getUpperAsInt() { - String raw = getUpper(); - - if (raw != null && raw.length() > 0) { - try { - return Integer.valueOf(raw); - } - catch (NumberFormatException nfe) { - // do nothing - } - } - - return null; - } - - - protected Validator newRangeValidator() { - Integer maxLower = getMaxLowerAsInt(); - Integer maxUpper = getMaxUpperAsInt(); - - if (maxLower != null && maxUpper != null) { - IntegerRangeValidator validator = new IntegerRangeValidator(); - validator.setMax(maxUpper); - validator.setMin(maxLower); - - return validator; - } - - return null; - } - - - public Integer getMaxLowerAsInt() { - return maxLower; - } - - - protected void setMaxLower(DataList dataList) { - IntegerRangeData range = (IntegerRangeData) dataList.get(0); - setMaxLower((Integer) range.getLower()); - } - - - public void setMaxLower(Integer maxLower) { - this.maxLower = maxLower; - } - - - public Integer getMaxUpperAsInt() { - return maxUpper; - } - - - protected void setMaxUpper(DataList dataList) { - IntegerRangeData range = (IntegerRangeData) dataList.get(0); - setMaxUpper((Integer) range.getUpper()); - } - - - public void setMaxUpper(Integer maxUpper) { - this.maxUpper = maxUpper; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LinkSelection.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.LinkItem; -import com.smartgwt.client.widgets.form.fields.events.ClickEvent; -import com.smartgwt.client.widgets.form.fields.events.ClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.StepForwardEvent; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - - -/** - * This UIProvider displays the DataItems of the Data object in a list of links. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class LinkSelection -extends MapSelection -{ - - private static final long serialVersionUID = -7138270638349711024L; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants messages = GWT.create(FLYSConstants.class); - - /** The selected river*/ - protected Data river; - - /** - * This method currently returns a - * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all - * data items in a list of links stored in <i>data</i>. - * - * @param data The {@link Data} object. - * - * @return a combobox. - */ - @Override - public Canvas create(DataList data) { - VLayout v = new VLayout(); - v.setMembersMargin(10); - v.setAlign(VerticalAlignment.TOP); - if (data.getState() == null) { - Canvas module = super.createWidget(data); - v.addMember(module); - } - Canvas content = createWidget(data); - v.addMember(content); - - return v; - } - - - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - VLayout vLayout = new VLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - int size = dataList.size(); - for (int i = 0; i < size; i++) { - Data data = dataList.get(i); - DataItem[] items = data.getItems(); - - for (DataItem item: items) { - HLayout hLayout = new HLayout(); - - hLayout.addMember(label); - hLayout.addMember(new Label(item.getLabel())); - - vLayout.addMember(hLayout); - vLayout.setWidth("130px"); - } - } - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - - /** - * This method creates the content of the widget. - * - * @param data The {@link Data} object. - * - * @return a list of links - */ - @Override - protected Canvas createWidget(DataList data) { - GWT.log("LinkSelection - create()"); - - VLayout layout = new VLayout(); - layout.setAlign(VerticalAlignment.TOP); - layout.setHeight(25); - - VLayout formLayout = new VLayout(); - - formLayout.setLayoutLeftMargin(60); - int size = data.size(); - - for (int i = 0; i < size; i++) { - Data d = data.get(i); - - Label label = new Label(d.getDescription()); - label.setValign(VerticalAlignment.TOP); - label.setHeight(20); - - for (DataItem item: d.getItems()) { - LinkItem link = new LinkItem("river"); - link.setLinkTitle(item.getLabel()); - link.setTarget(item.getStringValue()); - link.setShowTitle(false); - DynamicForm f = new DynamicForm(); - f.setItems(link); - formLayout.addMember(f); - link.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - DataItem item = new DefaultDataItem( - ((LinkItem)event.getItem()).getLinkTitle(), - null, - ((LinkItem)event.getItem()).getLinkTitle()); - - river = new DefaultData( - "river", - null, - null, - new DataItem [] {item}); - fireStepForwardEvent (new StepForwardEvent (getData())); - } - }); - - } - label.setWidth(50); - - layout.addMember(label); - layout.addMember(formLayout); - } - layout.setAlign(VerticalAlignment.TOP); - - String baseUrl = GWT.getHostPageBaseURL(); - Img map = new Img(baseUrl + messages.riverMap(), 494, 582); - helperContainer.addMember(map); - - return layout; - } - - - @Override - protected Data[] getData() { - Data[] module = super.getData(); - if (module != null) { - return new Data[] {module[0], river}; - } - else { - return new Data[] {river}; - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,257 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.Positioning; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.HasStepBackHandlers; -import de.intevation.flys.client.client.event.StepBackEvent; -import de.intevation.flys.client.client.event.StepBackHandler; -import de.intevation.flys.client.client.services.DescribeArtifactService; -import de.intevation.flys.client.client.services.DescribeArtifactServiceAsync; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.CalculationMessage; -import de.intevation.flys.client.shared.model.DataList; - -import java.util.ArrayList; -import java.util.List; - - -public class LoadingPanel extends Canvas implements HasStepBackHandlers { - - private static final long serialVersionUID = -7806425431408987601L; - - public static final int UPDATE_INTERVAL = 1000 * 3; - - public static final DescribeArtifactServiceAsync describe = - GWT.create(DescribeArtifactService.class); - - private FLYSConstants MSG = GWT.create(FLYSConstants.class); - - - protected List<StepBackHandler> handlers; - - protected CollectionView parent; - protected Artifact artifact; - - protected VLayout dialog; - protected HLayout cancelRow; - protected Label msg; - protected Label title; - - protected int i; - - - public LoadingPanel(CollectionView parent, Artifact artifact) { - super(); - - this.handlers = new ArrayList<StepBackHandler>(); - this.parent = parent; - this.artifact = artifact; - this.msg = new Label(""); - this.title = new Label(""); - this.dialog = createDialog(); - - this.i = 0; - - initLayout(); - startTimer(); - } - - - private void initLayout() { - setWidth("100%"); - setHeight("98%"); - setBackgroundColor("#7f7f7f"); - setOpacity(50); - setPosition(Positioning.RELATIVE); - - parent.addChild(this); - parent.addChild(dialog); - dialog.moveTo(0, 20); - moveTo(0, 7); - } - - - public void setArtifact(Artifact artifact) { - this.artifact = artifact; - } - - - public Artifact getArtifact() { - return artifact; - } - - - @Override - public void addStepBackHandler(StepBackHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - /** - * This method is called after the user has clicked the button to cancel the - * current process. - * - * @param e The StepBackEvent. - */ - protected void fireStepBackEvent(StepBackEvent e) { - for (StepBackHandler handler: handlers) { - handler.onStepBack(e); - } - } - - - protected VLayout createDialog() { - - String baseUrl = GWT.getHostPageBaseURL(); - - title.setStyleName("loading-title"); - title.setHeight(25); - title.setWidth100(); - - msg.setStyleName("loading-message"); - msg.setValign(VerticalAlignment.TOP); - msg.setWidth100(); - msg.setHeight(100); - - Img img = new Img(baseUrl + MSG.loadingImg(), 25, 25); - - Label cancelLabel = new Label(MSG.cancelCalculationLabel()); - Img cancel = new Img(baseUrl + MSG.cancelCalculation(), 25, 25); - cancel.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - cancel(); - } - }); - - cancelRow = new HLayout(); - cancelRow.setHeight(27); - cancelRow.setWidth100(); - cancelRow.addMember(cancel); - cancelRow.addMember(cancelLabel); - - VLayout box = new VLayout(); - box.setStyleName("loading-box"); - box.setAlign(VerticalAlignment.TOP); - box.setDefaultLayoutAlign(VerticalAlignment.TOP); - box.addMember(title); - box.addMember(msg); - box.addMember(cancelRow); - box.setMembersMargin(0); - box.setHeight(125); - box.setWidth(275); - - dialog = new VLayout(); - dialog.setAlign(Alignment.CENTER); - dialog.setDefaultLayoutAlign(Alignment.CENTER); - dialog.setMembersMargin(5); - dialog.setHeight100(); - dialog.setWidth100(); - - dialog.addMember(img); - dialog.addMember(box); - - return dialog; - } - - - public String getTargetState() { - ArtifactDescription desc = getArtifact().getArtifactDescription(); - DataList[] oldData = desc.getOldData(); - - return oldData[oldData.length -1].getState(); - } - - - private void startTimer() { - Timer t = new Timer() { - @Override - public void run() { - update(); - } - }; - t.schedule(UPDATE_INTERVAL); - } - - - protected void update() { - updateMessage(); - - final Config config = Config.getInstance(); - final String locale = config.getLocale(); - - describe.describe(locale, artifact, new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable t) { - GWT.log("Error while DESCRIBE artifact: " + t.getMessage()); - - startTimer(); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully DESCRIBE artifact."); - - setArtifact(artifact); - - if (artifact.isInBackground()) { - startTimer(); - } - else { - finish(); - } - } - }); - } - - - protected void updateMessage() { - List<CalculationMessage> messages = artifact.getBackgroundMessages(); - if (messages != null && messages.size() > 0) { - CalculationMessage calcMsg = messages.get(0); - title.setContents(getStepTitle(calcMsg)); - msg.setContents(calcMsg.getMessage()); - } - else { - title.setContents(MSG.calculationStarted()); - } - } - - - protected String getStepTitle(CalculationMessage msg) { - return MSG.step() + " " + msg.getCurrentStep() + "/" + msg.getSteps(); - } - - - private void cancel() { - fireStepBackEvent(new StepBackEvent(getTargetState())); - parent.removeChild(dialog); - parent.removeChild(this); - } - - - private void finish() { - parent.removeChild(dialog); - parent.removeChild(this); - parent.setArtifact(artifact); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1439 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.data.AdvancedCriteria; -import com.smartgwt.client.data.Criteria; -import com.smartgwt.client.data.Criterion; -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.OperatorId; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.RadioGroupItem; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; -import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; -import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.FilterHandler; -import de.intevation.flys.client.client.event.RangeFilterEvent; -import de.intevation.flys.client.client.event.StringFilterEvent; -import de.intevation.flys.client.client.services.DistanceInfoService; -import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; -import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.DistanceInfoObject; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - - -/** - * This UIProvider creates a widget to enter locations or a distance. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class LocationDistancePanel -extends AbstractUIProvider -implements ChangeHandler, BlurHandler, FilterHandler -{ - private static final long serialVersionUID = -10820092176039372L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - /** The DistanceInfoService used to retrieve locations about rivers. */ - protected DistanceInfoServiceAsync distanceInfoService = - GWT.create(DistanceInfoService.class); - - public static final String FIELD_MODE = "mode"; - - /** The constant name of the input field to enter the start of a distance.*/ - public static final String FIELD_FROM = "from"; - - /** The constant name of the input field to enter the end of a distance.*/ - public static final String FIELD_TO = "to"; - - /** The constant name of the input field to enter locations.*/ - public static final String FIELD_VALUE_LOCATION = "location"; - - /** The constant name of the input field to enter distance.*/ - public static final String FIELD_VALUE_DISTANCE = "distance"; - - /** The constant name of the input field to enter the step width of a - * distance.*/ - public static final String FIELD_WIDTH = "width"; - - public static final int WIDTH = 250; - - - /** The radio group for input mode selection.*/ - protected DynamicForm mode; - - /** A container that will contain the location or the distance panel.*/ - protected HLayout container; - - /** The min value for a distance.*/ - protected double min; - - /** The max value for a distance.*/ - protected double max; - - /** The 'from' value entered in the distance mode.*/ - protected double from; - - /** The 'to' value entered in the distance mode.*/ - protected double to; - - /** The 'step' value entered in the distance mode.*/ - protected double step; - - /** The values entered in the location mode.*/ - protected double[] values; - - /** The input panel for locations. */ - protected DoubleArrayPanel locationPanel; - - /** The input panel for distances. */ - protected DoubleRangePanel distancePanel; - - /** The tab set containing the location and distance table. */ - protected TabSet inputTables; - - /** The distance table. */ - protected ListGrid distanceTable; - - /** The locations table. */ - protected ListGrid locationsTable; - - /** The locations table for distance input. */ - protected ListGrid locationDistanceTable; - - /** The table data. */ - protected DistanceInfoObject[] tableData; - - /** The table filter.*/ - protected TableFilter filterDescription; - protected RangeTableFilter filterRange; - - /** The Combobox for table filter criteria. */ - protected SelectItem filterCriteria; - protected StaticTextItem filterResultCount; - protected ListGrid currentFiltered; - - /** - * Creates a new LocationDistancePanel instance. - */ - public LocationDistancePanel() { - distanceTable = new ListGrid(); - distanceTable.setAutoFetchData(true); - - locationsTable = new ListGrid(); - locationsTable.setAutoFetchData(true); - - locationDistanceTable = new ListGrid(); - locationDistanceTable.setAutoFetchData(true); - - locationDistanceTable.setShowHeaderContextMenu(false); - distanceTable.setShowHeaderContextMenu(false); - locationsTable.setShowHeaderContextMenu(false); - } - - - /** - * This method creates a widget that contains a label, a panel with - * checkboxes to switch the input mode between location and distance input, - * and a the mode specific panel. - * - * @param data The data that might be inserted. - * - * @return a panel. - */ - @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - - Label label = new Label(MESSAGES.location_distance_state()); - Canvas widget = createWidget(data); - Canvas submit = getNextButton(); - createDistanceInputPanel(); - - initDefaults(data); - - createLocationTableDistance (); - createDistanceTable(); - createLocationTable(); - - widget.setHeight(50); - label.setHeight(25); - - layout.addMember(label); - layout.addMember(widget); - layout.addMember(submit); - - return layout; - } - - - /** - * This method creates a table that contains the distance values. - */ - protected void createDistanceTable() { - - String baseUrl = GWT.getHostPageBaseURL(); - - distanceTable.setWidth100(); - distanceTable.setShowRecordComponents(true); - distanceTable.setShowRecordComponentsByCell(true); - distanceTable.setHeight100(); - distanceTable.setEmptyMessage(MESSAGES.empty_filter()); - distanceTable.setCanReorderFields(false); - - CellFormatter cf = new CellFormatter() { - @Override - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum) { - if (value == null) return null; - try { - NumberFormat nf; - double v = Double.parseDouble((String)value); - nf = NumberFormat.getFormat("###0.00##"); - return nf.format(v); - } - catch (Exception e) { - return value.toString(); - } - } - }; - - ListGridField addDistance = new ListGridField ("", ""); - addDistance.setType (ListGridFieldType.ICON); - addDistance.setWidth (20); - addDistance.addRecordClickHandler (new RecordClickHandler () { - @Override - public void onRecordClick (RecordClickEvent e) { - if (!isLocationMode ()) { - Record r = e.getRecord(); - try { - double min = Double.parseDouble(r.getAttribute("from")); - double max = Double.parseDouble(r.getAttribute("to")); - setDistanceValues(min, max); - } - catch(NumberFormatException nfe) { - // Is there anything to do? - } - } - else { - double[] selected; - Record r = e.getRecord(); - double min = 0, max = 0; - try { - min = Double.parseDouble(r.getAttribute("from")); - max = Double.parseDouble(r.getAttribute("to")); - } - catch(NumberFormatException nfe) { - // Is there anything to do? - } - if (getLocationValues() != null) { - double[] val = getLocationValues(); - selected = new double[val.length + 2]; - for(int i = 0; i < val.length; i++){ - selected[i] = val[i]; - } - selected[val.length] = min; - selected[val.length + 1] = max; - } - else { - selected = new double[2]; - selected[0] = min; - selected[1] = max; - } - setLocationValues(selected); - } - } - }); - addDistance.setCellIcon(baseUrl + MESSAGES.markerGreen()); - - ListGridField ddescr = new ListGridField("description", - MESSAGES.description()); - ddescr.setType(ListGridFieldType.TEXT); - ddescr.setWidth("*"); - ListGridField from = new ListGridField("from", MESSAGES.from()); - from.setCellFormatter(cf); - - from.setWidth("12%"); - ListGridField to = new ListGridField("to", MESSAGES.to()); - to.setType(ListGridFieldType.FLOAT); - to.setCellFormatter(cf); - - to.setWidth("12%"); - to.setAlign(Alignment.LEFT); - ListGridField dside = new ListGridField("riverside", - MESSAGES.riverside()); - dside.setType(ListGridFieldType.TEXT); - dside.setWidth("12%"); - - ListGridField bottom = - new ListGridField("bottom", MESSAGES.bottom_edge()); - bottom.setType(ListGridFieldType.TEXT); - bottom.setWidth("10%"); - bottom.setCellFormatter(cf); - - ListGridField top = - new ListGridField("top", MESSAGES.top_edge()); - top.setType(ListGridFieldType.TEXT); - top.setWidth("10%"); - top.setCellFormatter(cf); - - distanceTable.setFields( - addDistance, ddescr, from, to, dside, bottom, top); - } - - - /** - * This method creates a table that contains the location values. - */ - protected void createLocationTable() { - - String baseUrl = GWT.getHostPageBaseURL(); - - locationsTable.setWidth100(); - locationsTable.setShowRecordComponents(true); - locationsTable.setShowRecordComponentsByCell(true); - locationsTable.setHeight100(); - locationsTable.setEmptyMessage(MESSAGES.empty_filter()); - locationsTable.setCanReorderFields(false); - - CellFormatter cf = new CellFormatter() { - @Override - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum) { - if (value == null) return null; - try { - NumberFormat nf; - double v = Double.parseDouble((String)value); - nf = NumberFormat.getFormat("###0.00##"); - return nf.format(v); - } - catch (Exception e) { - return value.toString(); - } - } - }; - - - - ListGridField addLocation = new ListGridField ("", ""); - addLocation.setType (ListGridFieldType.ICON); - addLocation.setWidth (20); - - addLocation.addRecordClickHandler (new RecordClickHandler () { - @Override - public void onRecordClick (RecordClickEvent e) { - Record record = e.getRecord(); - double[] selected; - if (getLocationValues() != null) { - double[] val = getLocationValues(); - selected = new double[val.length + 1]; - for(int i = 0; i < val.length; i++){ - selected[i] = val[i]; - } - try { - selected[val.length] = - Double.parseDouble(record.getAttribute("from")); - } - catch(NumberFormatException nfe) { - // Is there anything to do here? - } - } - else { - selected = new double[1]; - selected[0] = - Double.parseDouble(record.getAttribute("from")); - } - setLocationValues(selected); - } - }); - addLocation.setCellIcon (baseUrl + MESSAGES.markerGreen ()); - - ListGridField ldescr = new ListGridField("description", - MESSAGES.description()); - ldescr.setType(ListGridFieldType.TEXT); - ldescr.setWidth("*"); - ListGridField lside = new ListGridField("riverside", - MESSAGES.riverside()); - lside.setType(ListGridFieldType.TEXT); - lside.setWidth("12%"); - ListGridField loc = new ListGridField("from", MESSAGES.locations()); - loc.setAlign(Alignment.LEFT); - loc.setType(ListGridFieldType.FLOAT); - loc.setWidth("12%"); - loc.setCellFormatter(cf); - - ListGridField bottom = - new ListGridField("bottom", MESSAGES.bottom_edge()); - bottom.setType(ListGridFieldType.TEXT); - bottom.setWidth("10%"); - bottom.setCellFormatter(cf); - - ListGridField top = - new ListGridField("top", MESSAGES.top_edge()); - top.setType(ListGridFieldType.TEXT); - top.setWidth("10%"); - top.setCellFormatter(cf); - - locationsTable.setFields(addLocation, ldescr, loc, lside, bottom, top); - } - - - /** - * This method creates a table that contains the location values. - */ - protected void createLocationTableDistance (){ - - String baseUrl = GWT.getHostPageBaseURL(); - - locationDistanceTable.setWidth100(); - locationDistanceTable.setShowRecordComponents(true); - locationDistanceTable.setShowRecordComponentsByCell(true); - locationDistanceTable.setHeight100(); - locationDistanceTable.setEmptyMessage(MESSAGES.empty_filter()); - locationDistanceTable.setCanReorderFields(false); - - CellFormatter cf = new CellFormatter() { - @Override - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum) { - if (value == null) return null; - try { - NumberFormat nf; - double v = Double.parseDouble((String)value); - nf = NumberFormat.getFormat("###0.00##"); - return nf.format(v); - } - catch (Exception e) { - return value.toString(); - } - } - }; - - ListGridField addfrom = new ListGridField ("from", MESSAGES.from()); - addfrom.setType (ListGridFieldType.ICON); - addfrom.setWidth (30); - addfrom.setCellIcon(baseUrl + MESSAGES.markerGreen()); - - ListGridField addto2 = new ListGridField ("to", MESSAGES.to()); - addto2.setType (ListGridFieldType.ICON); - addto2.setWidth (30); - addto2.setCellIcon(baseUrl + MESSAGES.markerRed()); - - locationDistanceTable.addCellClickHandler (new CellClickHandler () { - @Override - public void onCellClick (CellClickEvent e) { - if (e.getColNum() == 0) { - Record r = e.getRecord (); - try { - double fromvalue = - Double.parseDouble(r.getAttribute("from")); - double tovalue = getTo (); - setDistanceValues (fromvalue, tovalue); - } - catch(NumberFormatException nfe) { - // Is there anything to do in here? - } - } - else if (e.getColNum() == 1) { - Record r = e.getRecord (); - try { - double fromvalue = getFrom (); - double tovalue = - Double.parseDouble(r.getAttribute("from")); - setDistanceValues (fromvalue, tovalue); - } - catch(NumberFormatException nfe) { - // Is there anything to do in here? - } - } - } - }); - ListGridField bottom = - new ListGridField("bottom", MESSAGES.bottom_edge()); - bottom.setType(ListGridFieldType.TEXT); - bottom.setWidth("10%"); - bottom.setCellFormatter(cf); - - ListGridField top = - new ListGridField("top", MESSAGES.top_edge()); - top.setType(ListGridFieldType.TEXT); - top.setWidth("10%"); - top.setCellFormatter(cf); - - ListGridField ldescr = new ListGridField("description", - MESSAGES.description()); - ldescr.setType(ListGridFieldType.TEXT); - ldescr.setWidth("*"); - ListGridField lside = new ListGridField("riverside", - MESSAGES.riverside()); - lside.setType(ListGridFieldType.TEXT); - lside.setWidth("12%"); - ListGridField loc = new ListGridField("from", MESSAGES.locations()); - loc.setType(ListGridFieldType.FLOAT); - loc.setAlign(Alignment.LEFT); - loc.setWidth("12%"); - loc.setCellFormatter(cf); - - locationDistanceTable.setFields( - addfrom, addto2, ldescr, loc, lside, bottom, top); - } - - - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data dMode = getData(items, "ld_mode"); - DataItem[] dItems = dMode.getItems(); - - boolean rangeMode = true; - if (dItems != null && dItems[0] != null) { - rangeMode = FIELD_VALUE_DISTANCE.equals(dItems[0].getStringValue()); - } - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - - if (rangeMode) { - layout.addMember(getOldRangeSelection(dataList)); - } - else { - layout.addMember(getOldLocationSelection(dataList)); - } - - layout.addMember(back); - - return layout; - } - - - /** - * Creates a label for the selected range. - * - * @param dataList The DataList containing all values for this state. - * - * @return A label displaying the selected values. - */ - protected Label getOldRangeSelection(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data dFrom = getData(items, "ld_from"); - Data dTo = getData(items, "ld_to"); - Data dStep = getData(items, "ld_step"); - - DataItem[] from = dFrom.getItems(); - DataItem[] to = dTo.getItems(); - DataItem[] step = dStep.getItems(); - - StringBuilder sb = new StringBuilder(); - sb.append(from[0].getLabel()); - sb.append(" " + MESSAGES.unitFrom() + " "); - sb.append(to[0].getLabel()); - sb.append(" " + MESSAGES.unitTo() + " "); - sb.append(step[0].getLabel()); - sb.append(" " + MESSAGES.unitWidth()); - - Label selected = new Label(sb.toString()); - selected.setWidth("130px"); - - return selected; - } - - - /** - * Creates a label for the selected locations. - * - * @param dataList The DataList containing all values for this state. - * - * @return A label displaying the selected values. - */ - protected Label getOldLocationSelection(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data dLocations = getData(items, "ld_locations"); - DataItem[] lItems = dLocations.getItems(); - - String[] splitted = lItems[0].getStringValue().split(" "); - String value = ""; - for (int i = 0; i < splitted.length; i++) { - try { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double dv = Double.parseDouble(splitted[i]); - value += nf.format(dv) + " "; - } - catch(NumberFormatException nfe) { - value += splitted[i] + " "; - } - } - - Label selected = new Label(value); - selected.setWidth(130); - - return selected; - } - - - /** - * This method reads the default values defined in the DataItems of the Data - * objects in <i>list</i>. - * - * @param list The DataList container that stores the Data objects. - */ - protected void initDefaults(DataList list) { - Data m = getData(list.getAll(), "ld_mode"); - Data l = getData(list.getAll(), "ld_locations"); - Data f = getData(list.getAll(), "ld_from"); - Data t = getData(list.getAll(), "ld_to"); - Data s = getData(list.getAll(), "ld_step"); - - DataItem[] fItems = f.getItems(); - DataItem[] tItems = t.getItems(); - DataItem[] sItems = s.getItems(); - - min = Double.valueOf(fItems[0].getStringValue()); - max = Double.valueOf(tItems[0].getStringValue()); - step = Double.valueOf(sItems[0].getStringValue()); - - DataItem mDef = m.getDefault(); - DataItem lDef = l.getDefault(); - DataItem fDef = f.getDefault(); - DataItem tDef = t.getDefault(); - DataItem sDef = s.getDefault(); - - String mDefValue = mDef != null ? mDef.getStringValue() : null; - String theMode = mDefValue != null && mDefValue.length() > 0 - ? mDef.getStringValue() - : FIELD_VALUE_DISTANCE; - - mode.setValue(FIELD_MODE, theMode); - - String fDefValue = fDef != null ? fDef.getStringValue() : null; - setFrom(fDefValue != null && fDefValue.length() > 0 - ? Double.valueOf(fDef.getStringValue()) - : min); - - String tDefValue = tDef != null ? tDef.getStringValue() : null; - setTo(tDefValue != null && tDefValue.length() > 0 - ? Double.valueOf(tDef.getStringValue()) - : max); - - String sDefValue = sDef != null ? sDef.getStringValue() : null; - setStep(sDefValue != null && sDefValue.length() > 0 - ? Double.valueOf(sDef.getStringValue()) - : step); - - if (lDef != null) { - String lDefValue = lDef != null ? lDef.getStringValue() : null; - - if (lDefValue != null && lDefValue.length() > 0) { - setLocationValues(lDef.getStringValue()); - } - } - - if (theMode.equals(FIELD_VALUE_DISTANCE)) { - enableDistancePanel(); - inputTables.selectTab(1); - } - currentFiltered = (ListGrid)inputTables.getSelectedTab().getPane(); - } - - - protected Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - container = new HLayout(); - Canvas checkboxPanel = createRadioButtonPanel(); - - // the initial view will display the location input mode - locationPanel = new DoubleArrayPanel( - MESSAGES.unitLocation(), - getLocationValues(), - this); - container.addMember(locationPanel); - - layout.addMember(checkboxPanel); - layout.addMember(container); - - container.setMembersMargin(30); - - inputTables = new TabSet(); - inputTables.addTabSelectedHandler(new TabSelectedHandler() { - @Override - public void onTabSelected(TabSelectedEvent evt) { - filterDescription.clear(); - filterRange.clear(); - filterResultCount.setValue(""); - - Canvas c = evt.getTabPane(); - if(c instanceof ListGrid) { - currentFiltered = (ListGrid)c; - } - } - }); - - Tab locations = new Tab(MESSAGES.locations()); - Tab distances = new Tab(MESSAGES.distance()); - - inputTables.setWidth100(); - inputTables.setHeight100(); - - locations.setPane(locationDistanceTable); - distances.setPane(distanceTable); - - inputTables.addTab(locations); - inputTables.addTab(distances); - - filterResultCount = new StaticTextItem(MESSAGES.resultCount()); - filterResultCount.setTitleAlign(Alignment.LEFT); - filterResultCount.setTitleStyle("color: #000"); - - filterDescription = new TableFilter(); - filterDescription.setHeight("30px"); - filterDescription.addFilterHandler(this); - - filterRange = new RangeTableFilter(); - filterRange.setHeight("30px"); - filterRange.addFilterHandler(this); - filterRange.setVisible(false); - - filterCriteria = new SelectItem(); - filterCriteria.setShowTitle(false); - filterCriteria.setWidth(100); - filterCriteria.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent e) { - if(e.getValue().toString().equals("range")) { - filterRange.setVisible(true); - filterDescription.setVisible(false); - filterDescription.clear(); - filterResultCount.setValue(""); - } - else { - filterRange.setVisible(false); - filterRange.clear(); - filterDescription.setVisible(true); - filterResultCount.setValue(""); - } - } - }); - - LinkedHashMap<String, String> filterMap = - new LinkedHashMap<String, String>(); - filterMap.put("description", MESSAGES.description()); - filterMap.put("range", MESSAGES.range()); - filterCriteria.setValueMap(filterMap); - filterCriteria.setValue("description"); - - DynamicForm form = new DynamicForm(); - form.setFields(filterCriteria); - inputTables.setHeight("*"); - DynamicForm form2 = new DynamicForm(); - form2.setFields(filterResultCount); - - VLayout helper = new VLayout(); - HLayout filterLayout = new HLayout(); - - filterLayout.addMember(form); - filterLayout.addMember(filterDescription); - filterLayout.addMember(filterRange); - filterLayout.setHeight("30px"); - helper.addMember(inputTables); - helper.addMember(filterLayout); - helper.addMember(form2); - helper.setHeight100(); - helper.setWidth100(); - - helperContainer.addMember(helper); - filterLayout.setWidth("200"); - - return layout; - } - - - @Override - public void onFilterCriteriaChanged(StringFilterEvent event) { - String search = event.getFilter(); - - if (search != null && search.length() > 0) { - Criteria c = new Criteria("description", search); - - locationsTable.filterData(c); - distanceTable.filterData(c); - locationDistanceTable.filterData(c); - filterResultCount.setValue(currentFiltered.getRecords().length); - } - else { - locationsTable.clearCriteria(); - distanceTable.clearCriteria(); - locationDistanceTable.clearCriteria(); - filterResultCount.setValue(""); - } - } - - - @Override - public void onFilterCriteriaChanged(RangeFilterEvent event) { - Float from = event.getFrom() - 0.001f; - Float to = event.getTo() + 0.001f; - GWT.log("filtering range: " + from + " to " + to); - - - Criterion combinedFilter = null; - Criterion locationFilter = null; - if (from.equals(Float.NaN) && to.equals(Float.NaN)) { - locationsTable.clearCriteria(); - distanceTable.clearCriteria(); - locationDistanceTable.clearCriteria(); - filterResultCount.setValue(""); - return; - } - else if (from.equals(Float.NaN)) { - combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); - locationFilter = - new Criterion("from", OperatorId.LESS_OR_EQUAL, to); - locationsTable.filterData(locationFilter); - distanceTable.filterData(combinedFilter); - locationDistanceTable.filterData(combinedFilter); - filterResultCount.setValue(currentFiltered.getRecords().length); - return; - } - else if (to.equals(Float.NaN)) { - combinedFilter = - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); - locationsTable.filterData(combinedFilter); - distanceTable.filterData(combinedFilter); - locationDistanceTable.filterData(combinedFilter); - } - else { - AdvancedCriteria c1 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), - new Criterion("from", OperatorId.LESS_OR_EQUAL, to) - }); - - AdvancedCriteria c2 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), - new Criterion("to", OperatorId.LESS_OR_EQUAL, to) - }); - - AdvancedCriteria c3 = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("from", OperatorId.LESS_OR_EQUAL, to), - new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) - }); - - combinedFilter = - new AdvancedCriteria(OperatorId.OR, new Criterion[] { - c1, c2, c3 - }); - } - locationsTable.filterData(combinedFilter); - distanceTable.filterData(combinedFilter); - locationDistanceTable.filterData(combinedFilter); - filterResultCount.setValue(currentFiltered.getRecords().length); - } - - - @Override - public List<String> validate() { - if (isLocationMode()) { - return validateLocations(); - } - else { - return validateRange(); - } - } - - - protected List<String> validateLocations() { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - try { - saveLocationValues(locationPanel); - } - catch (Exception e) { - errors.add(MESSAGES.wrongFormat()); - } - - double[] values = getLocationValues(); - double[] good = new double[values.length]; - int idx = 0; - - for (double value: values) { - if (value < min || value > max) { - String tmp = MESSAGES.error_validate_range(); - tmp = tmp.replace("$1", nf.format(value)); - tmp = tmp.replace("$2", nf.format(min)); - tmp = tmp.replace("$3", nf.format(max)); - errors.add(tmp); - } - else { - good[idx++] = value; - } - } - - double[] justGood = new double[idx]; - for (int i = 0; i < justGood.length; i++) { - justGood[i] = good[i]; - } - - if (!errors.isEmpty()) { - locationPanel.setValues(justGood); - } - - return errors; - } - - - protected List<String> validateRange() { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - try { - saveDistanceValues(distancePanel); - } - catch (Exception e) { - errors.add(MESSAGES.wrongFormat()); - } - - double from = getFrom(); - double to = getTo(); - double step = getStep(); - - if (from < min || from > max) { - String tmp = MESSAGES.error_validate_lower_range(); - tmp = tmp.replace("$1", nf.format(from)); - tmp = tmp.replace("$2", nf.format(min)); - errors.add(tmp); - from = min; - } - - if (to < min || to > max) { - String tmp = MESSAGES.error_validate_upper_range(); - tmp = tmp.replace("$1", nf.format(to)); - tmp = tmp.replace("$2", nf.format(max)); - errors.add(tmp); - to = max; - } - - if (!errors.isEmpty()) { - distancePanel.setValues(from, to, step); - } - - return errors; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - // If we have entered a value and click right afterwards on the - // 'next' button, the BlurEvent is not fired, and the values are not - // saved. So, we gonna save those values explicitly. - if (isLocationMode()) { - Canvas member = container.getMember(0); - if (member instanceof DoubleArrayPanel) { - DoubleArrayPanel form = (DoubleArrayPanel) member; - saveLocationValues(form); - } - - Data dLocations = getDataLocations(); - DataItem dFrom = new DefaultDataItem("ld_from", "ld_from", ""); - DataItem dTo = new DefaultDataItem("ld_to", "ld_to", ""); - DataItem dStep = new DefaultDataItem("ld_step", "ld_step", ""); - - data.add(dLocations); - data.add(new DefaultData( - "ld_from", null, null, new DataItem[] { dFrom } )); - data.add(new DefaultData( - "ld_to", null, null, new DataItem[] { dTo } )); - data.add(new DefaultData( - "ld_step", null, null, new DataItem[] { dStep } )); - } - else { - Canvas member = container.getMember(0); - if (member instanceof DoubleRangePanel) { - DoubleRangePanel form = (DoubleRangePanel) member; - saveDistanceValues(form); - } - - Data dFrom = getDataFrom(); - Data dTo = getDataTo(); - Data dStep = getDataStep(); - DataItem loc = new DefaultDataItem("ld_locations", "ld_locations",""); - - data.add(dFrom); - data.add(dTo); - data.add(dStep); - data.add(new DefaultData( - "ld_locations", null, null, new DataItem[] { loc } )); - } - - Data dMode = getDataMode(); - if (dMode != null) { - data.add(dMode); - } - - return data.toArray(new Data[data.size()]); - } - - - /** - * Returns the Data object for the 'mode' attribute. - * - * @return the Data object for the 'mode' attribute. - */ - protected Data getDataMode() { - String value = mode.getValueAsString(FIELD_MODE); - DataItem item = new DefaultDataItem("ld_mode", "ld_mode", value); - return new DefaultData("ld_mode", null, null, new DataItem[] { item }); - } - - - protected Data getDataLocations() { - double[] locations = getLocationValues(); - boolean first = true; - - if (locations == null) { - return null; - } - - StringBuilder sb = new StringBuilder(); - - for (double l: locations) { - if (!first) { - sb.append(" "); - } - - sb.append(l); - - first = false; - } - - DataItem item = new DefaultDataItem( - "ld_locations", - "ld_locations", - sb.toString()); - - return new DefaultData( - "ld_locations", - null, - null, - new DataItem[] { item }); - } - - - /** - * Returns the Data object for the 'from' attribute. - * - * @return the Data object for the 'from' attribute. - */ - protected Data getDataFrom() { - String value = Double.valueOf(getFrom()).toString(); - DataItem item = new DefaultDataItem("ld_from", "ld_from", value); - return new DefaultData( - "ld_from", null, null, new DataItem[] { item }); - } - - - /** - * Returns the Data object for the 'to' attribute. - * - * @return the Data object for the 'to' attribute. - */ - protected Data getDataTo() { - String value = Double.valueOf(getTo()).toString(); - DataItem item = new DefaultDataItem("ld_to", "ld_to", value); - return new DefaultData( - "ld_to", null, null, new DataItem[] { item }); - } - - - /** - * Returns the Data object for the 'step' attribute. - * - * @return the Data object for the 'step' attribute. - */ - protected Data getDataStep() { - String value = Double.valueOf(getStep()).toString(); - DataItem item = new DefaultDataItem("ld_step","ld_step", value); - return new DefaultData( - "ld_step", null, null, new DataItem[] { item }); - } - - - /** - * Determines the current input mode. - * - * @return true, if 'location' is the current input mode, otherwise false. - */ - public boolean isLocationMode() { - String inputMode = mode.getValueAsString(FIELD_MODE); - - return inputMode.equals(FIELD_VALUE_LOCATION) ? true : false; - } - - - /** - * Activates the location panel. - */ - protected void enableLocationPanel() { - locationPanel = new DoubleArrayPanel( - MESSAGES.unitLocation(), - getLocationValues(), - this); - - container.removeMembers(container.getMembers()); - container.addMember(locationPanel); - } - - - /** - * Activates the distance panel. - */ - protected void enableDistancePanel() { - distancePanel = new DoubleRangePanel( - MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), - getFrom(), getTo(), getStep(), - 400, - this); - - container.removeMembers(container.getMembers()); - container.addMember(distancePanel); - } - - - /** - * This method switches the input mode between location and distance input. - * - * @param event The click event fired by a RadioButtonGroupItem. - */ - @Override - public void onChange(ChangeEvent event) { - String value = (String) event.getValue(); - - if (value == null) { - return; - } - if (value.equals(FIELD_VALUE_LOCATION)) { - enableLocationPanel(); - filterDescription.clear(); - filterRange.clear(); - filterResultCount.setValue(""); - - // Remove the tab containing the locationDistanceTable. - // The 'updateTab()' avoids the tab content to be destroyed. - inputTables.updateTab(0, null); - inputTables.removeTab(0); - - // Create a new tab containing the locationTable - Tab t1 = new Tab (MESSAGES.locations()); - t1.setPane(locationsTable); - inputTables.addTab(t1, 0); - - // Bring this tab to front. - inputTables.selectTab(0); - } - else { - enableDistancePanel(); - filterDescription.clear(); - filterRange.clear(); - filterResultCount.setValue(""); - - // Remove the tab containing the locationTable. - // The 'updateTab()' avoids the tab content to be destroyed. - inputTables.updateTab(0, null); - inputTables.removeTab(0); - - // Create a new tab containing the locationDistanceTable. - Tab t1 = new Tab(MESSAGES.locations()); - t1.setPane(locationDistanceTable); - inputTables.addTab(t1, 0); - - // Bring the distanceTable tab to front. - inputTables.selectTab(1); - } - } - - - /** - * This method is used to validate the inserted data in the form fields. - * - * @param event The BlurEvent that gives information about the FormItem that - * has been modified and its value. - */ - @Override - public void onBlur(BlurEvent event) { - FormItem item = event.getItem(); - String field = item.getFieldName(); - - if (field == null) { - return; - } - - if (field.equals(DoubleArrayPanel.FIELD_NAME)) { - DoubleArrayPanel p = (DoubleArrayPanel) event.getForm(); - - saveLocationValue(p, item); - } - else { - DoubleRangePanel p = (DoubleRangePanel) event.getForm(); - - saveDistanceValue(p, item); - } - } - - - - /** - * Validates and stores all values entered in the location mode. - * - * @param p The DoubleArrayPanel. - */ - protected void saveLocationValues(DoubleArrayPanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { - saveLocationValue(p, item); - } - } - } - - - /** - * Validates and stores all values entered in the distance mode. - * - * @param p The DoubleRangePanel. - */ - protected void saveDistanceValues(DoubleRangePanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - saveDistanceValue(p, item); - } - } - - - /** - * Validates and stores a value entered in the location mode. - * - * @param p The DoubleArrayPanel. - * @param item The item that needs to be validated. - */ - protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { - if (p.validateForm(item)) { - setLocationValues(p.getInputValues(item)); - } - } - - - /** - * Validates and stores value entered in the distance mode. - * - * @param p The DoubleRangePanel. - * @param item The item that needs to be validated. - */ - protected void saveDistanceValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm(item)) { - setFrom(p.getFrom()); - setTo(p.getTo()); - setStep(p.getStep()); - } - } - - - /** - * This method creates the panel that contains the checkboxes to switch - * between the input mode 'location' and 'distance'. - * - * @return the checkbox panel. - */ - protected Canvas createRadioButtonPanel() { - mode = new DynamicForm(); - - RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); - radio.setShowTitle(false); - radio.setVertical(false); - radio.setWrap(false); - - LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); - values.put(FIELD_VALUE_LOCATION, MESSAGES.location()); - values.put(FIELD_VALUE_DISTANCE, MESSAGES.distance()); - - LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); - initial.put(FIELD_MODE, FIELD_VALUE_DISTANCE); - - radio.setValueMap(values); - radio.addChangeHandler(this); - - mode.setFields(radio); - mode.setValues(initial); - - return mode; - } - - - protected void createDistanceInputPanel() { - Config config = Config.getInstance(); - String url = config.getServerUrl(); - String river = ""; - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - if (dl.getState().endsWith("river")) { - for (int j = 0; j < dl.size(); j++) { - Data d = dl.get(j); - DataItem[] di = d.getItems(); - if (di != null && di.length == 1) { - river = d.getItems()[0].getStringValue(); - } - } - } - } - } - - distanceTable.setDataSource(new DistanceInfoDataSource( - url, river, "distances")); - locationsTable.setDataSource(new DistanceInfoDataSource( - url, river, "locations")); - locationDistanceTable.setDataSource(new DistanceInfoDataSource( - url, river, "locations")); - } - - - protected double getFrom() { - return from; - } - - - protected void setFrom(double from) { - this.from = from; - } - - - protected double getTo() { - return to; - } - - - protected void setTo(double to) { - this.to = to; - } - - - protected double getStep() { - return step; - } - - - protected void setStep(double step) { - this.step = step; - } - - - protected double[] getLocationValues() { - return values; - } - - - protected void setLocationValues(double[] values) { - this.values = values; - locationPanel.setValues(values); - } - - - protected void setLocationValues(String values) { - String[] vs = values.split(" "); - - if (vs == null) { - return; - } - - double[] ds = new double[vs.length]; - int idx = 0; - - for (String s: vs) { - try { - ds[idx++] = Double.valueOf(s); - } - catch (NumberFormatException nfe) { - // do nothing - } - } - - setLocationValues(ds); - } - - - protected void setDistanceValues (double from, double to) { - setFrom(from); - setTo(to); - distancePanel.setValues(from, to, getStep()); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,328 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; - -import java.util.ArrayList; -import java.util.List; - -/** - * This UIProvider serves as base for UI Providers to enter a single location (km). - */ -public abstract class LocationPanel -extends AbstractUIProvider -{ - private static final long serialVersionUID = -5306604428440015046L; - - /** A container that will contain the location or the distance panel. */ - protected HLayout inputLayout; - - /** The minimal value that the user is allowed to enter. */ - protected double min; - - /** The maximal value that the user is allowed to enter. */ - protected double max; - - /** The values entered in the location mode. */ - protected double[] values; - - /** Name of the data item that keeps this location(s). */ - protected String dataItemName; - - /** The input panel for locations. */ - protected DoubleArrayPanel locationPanel; - - - /** - * Creates a new LocationDistancePanel instance. - */ - public LocationPanel() { - values = new double[0]; - } - - - /** - * This method creates a widget that contains a label, a panel with - * checkboxes to switch the input mode between location and distance input, - * and a mode specific panel. - * - * @param data The data that might be inserted. - * - * @return a panel. - */ - @Override - public Canvas create(DataList data) { - findDataItemName(data); - - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - - // Subclass uses translated data items name as label. - Label label = new Label(MSG.location()); - Canvas widget = createWidget(data); - Canvas submit = getNextButton(); - - initDefaults(data); - - widget.setHeight(50); - label.setHeight(25); - - layout.addMember(label); - layout.addMember(widget); - layout.addMember(submit); - - return layout; - } - - - /** Store label of first data item in list. */ - public void findDataItemName(DataList list) { - this.dataItemName = list.getAll().get(0).getLabel(); - } - - - /** Get label of first data item that this uiprovider has seen. */ - public String getDataItemName() { - return this.dataItemName; - } - - - /** - * This method creates a Canvas element showing the old Data objects in the - * DataList <i>data</i>. - */ - @Override - public Canvas createOld(DataList dataList) { - findDataItemName(dataList); - - List<Data> items = dataList.getAll(); - Data dLocation = getData(items, getDataItemName()); - DataItem[] loc = dLocation.getItems(); - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - // TODO evaluate: isn't this what findDataItemName is doing? - Label selected = new Label(loc[0].getLabel()); - selected.setWidth("130px"); - - layout.addMember(label); - layout.addMember(selected); - layout.addMember(back); - - return layout; - } - - - /** - * This method reads the default values defined in the DataItems of the Data - * objects in <i>list</i>. - * - * @param list The DataList container that stores the Data objects. - */ - protected void initDefaults(DataList list) { - Data data = list.get(0); - - DataItem[] items = data.getItems(); - DataItem iMin = getDataItem(items, "min"); - DataItem iMax = getDataItem(items, "max"); - - try { - min = Double.parseDouble(iMin.getStringValue()); - max = Double.parseDouble(iMax.getStringValue()); - } - catch (NumberFormatException nfe) { - SC.warn(MSG.error_read_minmax_values()); - min = -Double.MAX_VALUE; - max = Double.MAX_VALUE; - } - - DataItem def = data.getDefault(); - String value = def.getStringValue(); - - try { - double d = Double.parseDouble(value); - setLocationValues(new double[] { d } ); - } - catch (NumberFormatException nfe) { - // could not parse, don't know what else to do - GWT.log("LocationPanel", nfe); - } - } - - - /** - * This method grabs the Data with name <i>name</i> from the list and - * returns it. - * - * @param items A list of Data. - * @param name The name of the Data that we are searching for. - * - * @return the Data with the name <i>name</i>. - */ - @Override - protected Data getData(List<Data> data, String name) { - for (Data d: data) { - if (name.equals(d.getLabel())) { - return d; - } - } - - return null; - } - - - protected Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - inputLayout = new HLayout(); - - // The initial view will display the location input mode. - locationPanel = new DoubleArrayPanel( - MSG.unitLocation(), - getLocationValues(), - new BlurHandler(){@Override - public void onBlur(BlurEvent be) {}}); - - // TODO Remove picker references, refactor such that subclasses can - // easily use their picker if they want. - //picker.getLocationTable().setAutoFetchData(true); - - inputLayout.addMember(locationPanel); - - layout.addMember(inputLayout); - - inputLayout.setMembersMargin(30); - - /* - //picker.prepareFilter(); - helperContainer.addMember(picker.getLocationTable()); - helperContainer.addMember(picker.getFilterLayout()); - helperContainer.addMember(picker.getResultCountForm()); - */ - return layout; - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - saveLocationValues(locationPanel); - - if (!locationPanel.validateForm()) { - errors.add(MSG.wrongFormat()); - return errors; - } - - double[] values = getLocationValues(); - double[] good = new double[values.length]; - int idx = 0; - - for (double value: values) { - if (value < min || value > max) { - String tmp = MSG.error_validate_range(); - tmp = tmp.replace("$1", nf.format(value)); - tmp = tmp.replace("$2", nf.format(min)); - tmp = tmp.replace("$3", nf.format(max)); - errors.add(tmp); - } - else { - good[idx++] = value; - } - } - - double[] justGood = new double[idx]; - for (int i = 0; i < justGood.length; i++) { - justGood[i] = good[i]; - } - - if (!errors.isEmpty()) { - locationPanel.setValues(justGood); - } - - return errors; - } - - - /** - * Validates and stores all values entered in the location mode. - * - * @param p The DoubleArrayPanel. - */ - protected void saveLocationValues(DoubleArrayPanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { - saveLocationValue(p, item); - } - } - } - - - /** - * Validates and stores a value entered in the location mode. - * - * @param p The DoubleArrayPanel. - * @param item The item that needs to be validated. - */ - protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { - if (p.validateForm(item)) { - setLocationValues(p.getInputValues(item)); - } - } - - - /** Get the location values. */ - protected double[] getLocationValues() { - return values; - } - - - /** Sets Location values and updates the panel. */ - protected void setLocationValues(double[] values) { - this.values = values; - locationPanel.setValues(values); - } - - - /** - * Callback when an item from the input helper was clicked. - * Set the respective km-value in the location value field. - * @param e event passed. - */ - public void onRecordClick (RecordClickEvent e) { - Record record = e.getRecord(); - double[] selected = new double[1]; - try { - selected[0] = - Double.parseDouble(record.getAttribute("from")); - } - catch(NumberFormatException nfe) { - GWT.log("onRecordClick", nfe); - } - setLocationValues(selected); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationPicker.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,267 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.LinkedHashMap; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.smartgwt.client.data.AdvancedCriteria; -import com.smartgwt.client.data.Criteria; -import com.smartgwt.client.data.Criterion; -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.OperatorId; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.FilterHandler; -import de.intevation.flys.client.client.event.RangeFilterEvent; -import de.intevation.flys.client.client.event.StringFilterEvent; - -/** - * Bundle widgets and handler for a lacation input helper. - * - * Note that the construction is weird and driven by issues that arose due to - * reasons not understood. - */ -public class LocationPicker -implements FilterHandler -{ - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** The locations table. */ - protected ListGrid locationTable; - - protected HLayout filterLayout; - - DynamicForm resultCountForm; - - CellClickHandler handler; - - boolean isDistance = false; - - /** Text to show number of matched items when filtered. */ - protected StaticTextItem filterResultCount; - - - public LocationPicker(CellClickHandler handler) { - locationTable = new ListGrid(); - locationTable.setShowHeaderContextMenu(false); - this.handler = handler; - } - - public void prepareFilter() { - - filterResultCount = new StaticTextItem(MSG.resultCount()); - filterResultCount.setTitleAlign(Alignment.LEFT); - filterResultCount.setTitleStyle("color: #000"); - - final TableFilter filter = new TableFilter(); - filter.setHeight("30px"); - filter.addFilterHandler(this); - - final RangeTableFilter filterRange = new RangeTableFilter(); - filterRange.setHeight("30px"); - filterRange.addFilterHandler(this); - filterRange.setVisible(false); - - SelectItem filterCriteria = new SelectItem(); - filterCriteria.setShowTitle(false); - filterCriteria.setWidth(100); - filterCriteria.addChangedHandler(new ChangedHandler() { - public void onChanged(ChangedEvent e) { - if(e.getValue().toString().equals("range")) { - filterRange.setVisible(true); - filter.setVisible(false); - filter.clear(); - filterResultCount.setValue(""); - } - else { - filterRange.setVisible(false); - filterRange.clear(); - filter.setVisible(true); - filterResultCount.setValue(""); - } - } - }); - - LinkedHashMap<String, String> filterMap = - new LinkedHashMap<String, String>(); - filterMap.put("description", MSG.description()); - filterMap.put("range", MSG.range()); - filterCriteria.setValueMap(filterMap); - filterCriteria.setValue("description"); - - DynamicForm form = new DynamicForm(); - form.setFields(filterCriteria); - - resultCountForm = new DynamicForm(); - resultCountForm.setFields(filterResultCount); - - filterLayout = new HLayout(); - filterLayout.addMember(form); - filterLayout.addMember(filter); - filterLayout.addMember(filterRange); - } - - - /** Access the main widget, a table in which locations can be chosen. */ - public ListGrid getLocationTable() { - return locationTable; - } - - - /** Access the 'form' that shows the filter result count. */ - public DynamicForm getResultCountForm() { - return resultCountForm; - } - - - /** Access the layout containing filter stuff. */ - public HLayout getFilterLayout() { - return filterLayout; - } - - - /** - * This method creates a table that contains the location values. - */ - public void createLocationTable(/*RecordClickHandler handler*/) { - GWT.log("Create Location Table in LocationPicker"); - - String baseUrl = GWT.getHostPageBaseURL(); - - locationTable.setWidth100(); - locationTable.setShowRecordComponents(true); - locationTable.setShowRecordComponentsByCell(true); - locationTable.setHeight100(); - locationTable.setEmptyMessage(MSG.empty_filter()); - locationTable.setCanReorderFields(false); - - ListGridField addLocation = new ListGridField ("", ""); - addLocation.setType (ListGridFieldType.ICON); - addLocation.setWidth (20); - addLocation.setCellIcon (baseUrl + MSG.markerGreen()); - ListGridField addTo = new ListGridField ("", ""); - addTo.setType (ListGridFieldType.ICON); - addTo.setWidth (20); - addTo.setCellIcon (baseUrl + MSG.markerRed()); - - ListGridField ldescr = new ListGridField("description", - MSG.description()); - ldescr.setType(ListGridFieldType.TEXT); - ldescr.setWidth("*"); - ListGridField lside = new ListGridField("riverside", - MSG.riverside()); - lside.setType(ListGridFieldType.TEXT); - lside.setWidth("10%"); - - ListGridField loc = new ListGridField("from", MSG.location()); - loc.setCellFormatter(new CellFormatter() { - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum) { - if (value == null) return null; - try { - NumberFormat nf; - double v = Double.parseDouble((String)value); - nf = NumberFormat.getFormat("###0.00##"); - return nf.format(v); - } - catch (Exception e) { - return value.toString(); - } - } - } - ); - loc.setType(ListGridFieldType.FLOAT); - - loc.setWidth("10%"); - - ListGridField bottom = - new ListGridField("bottom", MSG.bottom_edge()); - bottom.setType(ListGridFieldType.TEXT); - bottom.setWidth("10%"); - - ListGridField top = - new ListGridField("top", MSG.top_edge()); - top.setType(ListGridFieldType.TEXT); - top.setWidth("10%"); - locationTable.addCellClickHandler(handler); - if (isDistance) { - locationTable.setFields( - addLocation, addTo, ldescr, loc, lside, bottom, top); - } - else { - locationTable.setFields( - addLocation, ldescr, loc, lside, bottom, top); - } - } - - - @Override - public void onFilterCriteriaChanged(StringFilterEvent event) { - String search = event.getFilter(); - - if (search != null && search.length() > 0) { - Criteria c = new Criteria("description", search); - locationTable.filterData(c); - filterResultCount.setValue(locationTable.getRecords().length); - } - else { - locationTable.clearCriteria(); - filterResultCount.setValue(""); - } - } - - - @Override - public void onFilterCriteriaChanged(RangeFilterEvent event) { - Float from = event.getFrom() - 0.001f; - Float to = event.getTo() + 0.001f; - - Criterion combinedFilter = null; - if (from.equals(Float.NaN) && to.equals(Float.NaN)) { - locationTable.clearCriteria(); - filterResultCount.setValue(""); - return; - } - else if (from.equals(Float.NaN)) { - combinedFilter = - new Criterion("from", OperatorId.LESS_OR_EQUAL, to); - } - else if (to.equals(Float.NaN)) { - combinedFilter = - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); - } - else { - combinedFilter = - new AdvancedCriteria(OperatorId.AND, new Criterion[] { - new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), - new Criterion("from", OperatorId.LESS_OR_EQUAL, to) - }); - } - locationTable.filterData(combinedFilter); - filterResultCount.setValue(locationTable.getRecords().length); - } - - public void setIsDistance(boolean value) { - this.isDistance = value; - } - - public boolean isDistance() { - return this.isDistance; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; - - -/** - * This UIProvider displays the DataItems contained in the Data object in a - * combo box as SelectProvider does. Furthermore, there is a map displayed that - * lets the user choose a river by selecting it on the map. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MapSelection extends SelectProvider { - - private static final long serialVersionUID = 1261822454641198692L; - - protected ModuleSelection moduleSelection; - - public MapSelection() { - } - - - /** - * This method currently returns a - * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all - * data items in a combobox stored in <i>data</i>.<br> - * - * <b>TODO: The map panel for the river selection needs to be - * implemented!</b> - * - * @param data The {@link DataList} object. - * - * @return a combobox. - */ - @Override - protected Canvas createWidget(DataList data) { - GWT.log("MapSelection - create()"); - - HLayout h = new HLayout(); - h.setAlign(VerticalAlignment.TOP); - h.setHeight(100); - moduleSelection = new ModuleSelection(); - - Canvas form = moduleSelection.create(data); - form.setWidth(400); - form.setLayoutAlign(VerticalAlignment.TOP); - - // TODO implement event handling in the river map (here? or in LinkSelection) - - h.addMember(form); - - return h; - } - - @Override - protected Data[] getData() { - if (moduleSelection != null) { - return moduleSelection.getData(); - } - else { - return null; - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.RadioGroupItem; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.ModuleService; -import de.intevation.flys.client.client.services.ModuleServiceAsync; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.Module; - -import java.util.LinkedHashMap; - -/** - * The ModuleSelection combines the river selection and the module selection in - * one widget. It will display a vertical splitted widget - the upper part will - * render checkboxes for each module, the lower one will display a combobox at - * the left and a map panel on the right to choose the river. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ModuleSelection extends MapSelection { - - private static final long serialVersionUID = -5634831815175543328L; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - /** The module checkboxes.*/ - protected RadioGroupItem radio; - - /** */ - protected Module[] modules; - - /** The ModuleService used to retrieve the available modules of a user.*/ - protected ModuleServiceAsync moduleService = GWT.create(ModuleService.class); - - - /** - * The default constructor. - */ - public ModuleSelection() { - readModules(); - } - - - /** - * This method returns a widget that renders the checkboxes for each module - * and the MapSelection that lets the user choose the river. - * - * @param data The provided rivers. - * - * @return the module selection combined with the river selection. - */ - @Override - public Canvas create(DataList data) { - GWT.log("ModuleSelection - create()"); - VLayout newLayout = new VLayout(); - newLayout.setMembersMargin(10); - newLayout.setAlign(VerticalAlignment.TOP); - Canvas moduleSelection = createWidget(); - - moduleSelection.setHeight(100); - newLayout.setHeight(70); - newLayout.addMember(moduleSelection); - - return newLayout; - } - - private void readModules() { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - moduleService.list(locale, new AsyncCallback<Module[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve a list of modules."); - SC.warn(MSG.getString(caught.getMessage())); - } - - @Override - public void onSuccess(Module[] newmodules) { - GWT.log("Retrieved " + newmodules.length + " modules."); - modules = newmodules; - setModules(); - } - }); - } - - private void setModules() { - LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); - - if (this.modules!= null) { - for(Module module : this.modules) { - values.put(module.getName(), module.getLocalizedName()); - if (module.isSelected()) { - GWT.log("Module " + module.getName() + " is selected."); - if (radio != null) { - radio.setDefaultValue(module.getName()); - GWT.log("Setting " + module.getName() + " as selected."); - } - } - } - } - if (radio != null) { - radio.setValueMap(values); - } - } - - /** - * Creates a widget that displays a checkbox for each module. - * - * @return a widget with checkboxes. - */ - protected Canvas createWidget() { - HLayout layout = new HLayout(); - - Label label = new Label(MESSAGES.module_selection()); - DynamicForm form = new DynamicForm(); - - radio = new RadioGroupItem("plugin"); - - label.setWidth(50); - label.setHeight(25); - - - radio.setShowTitle(false); - radio.setVertical(true); - - setModules(); - - form.setFields(radio); - - layout.addMember(label); - layout.addMember(form); - - return layout; - } - - - /** - * This method prepares the data of two widgets - the module selection and - * the river selection. The returning field will contain the Data that - * represents the module selection at first position, the second position - * stores the Data object that represents the river selection. - * - * @return the Data that was chosen in this widget. - */ - @Override - protected Data[] getData() { - - String module = radio.getValueAsString(); - - DataItem[] items = new DefaultDataItem[1]; - items[0] = new DefaultDataItem(module, module, module); - - Data data = new DefaultData("module", null, null, items); - - return new Data[] {data}; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MultiPeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,242 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class MultiPeriodPanel -extends PeriodPanel -{ - - private static final long serialVersionUID = 1811025931934462457L; - - protected ListGrid elements; - - protected String values; - - public MultiPeriodPanel() { - this("", ""); - } - - public MultiPeriodPanel(String startName, String endName) { - super(startName, endName); - } - - @Override - public Canvas createWidget(DataList data) { - HLayout input = new HLayout(); - VLayout root = new VLayout(); - VLayout grid = new VLayout(); - VLayout layout = (VLayout) super.createWidget(data); - Button add = new Button(MSG.add_date()); - elements = new ListGrid(); - - add.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent ce) { - Date f = inputPanel.getFromDate(); - Date t = inputPanel.getToDate(); - if (f == null || t == null) { - return; - } - DateRangeRecord drr = new DateRangeRecord(f, t); - elements.addData(drr); - } - }); - layout.addMember(add); - - Label sel = new Label(MSG.select()); - sel.setHeight(25); - elements.setWidth(185); - elements.setHeight(120); - elements.setShowHeaderContextMenu(false); - elements.setCanReorderFields(false); - elements.setCanSort(false); - elements.setCanEdit(false); - ListGridField from = new ListGridField("from", MSG.from()); - ListGridField to = new ListGridField("to", MSG.to()); - from.setWidth(70); - to.setWidth(70); - - final ListGridField removeField = - new ListGridField("_removeRecord", "Remove Record"){{ - setType(ListGridFieldType.ICON); - setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); - setCanEdit(false); - setCanFilter(false); - setCanSort(false); - setCanGroupBy(false); - setCanFreeze(false); - setWidth(25); - }}; - - elements.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(final RecordClickEvent event) { - // Just handle remove-clicks - if(!event.getField().getName().equals(removeField.getName())) { - return; - } - event.getViewer().removeData(event.getRecord()); - } - }); - - elements.setFields(from, to, removeField); - - grid.addMember(sel); - grid.addMember(elements); - input.addMember(layout); - input.addMember(grid); - root.addMember(input); - - return root; - } - - @SuppressWarnings("deprecation") - @Override - public Canvas createOld(DataList dataList) { - GWT.log("old............................"); - HLayout layout = new HLayout(); - layout.setWidth("400px"); - VLayout vLayout = new VLayout(); - vLayout.setWidth(130); - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - label.setHeight(25); - - List<Data> items = dataList.getAll(); - Data str = getData(items, "periods"); - DataItem[] strItems = str.getItems(); - - String[] pairs = strItems[0].getLabel().split(";"); - for (int i = 0; i < pairs.length; i++) { - String[] vals = pairs[i].split(","); - long f = Long.valueOf(vals[0]).longValue(); - long t = Long.valueOf(vals[1]).longValue(); - Date from = new Date(f); - Date to = new Date(t); - String fromString = - DateTimeFormat.getMediumDateFormat().format(from); - String toString = - DateTimeFormat.getMediumDateFormat().format(to); - - Label dateLabel = new Label(fromString + " - " + toString); - dateLabel.setHeight(20); - vLayout.addMember(dateLabel); - } - Canvas back = getBackButton(dataList.getState()); - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - boolean valid = saveDateValues(); - if(valid) { - DataItem item = new DefaultDataItem("periods", null, this.values); - data.add(new DefaultData( - "periods", - null, - null, - new DataItem[] { item })); - } - return data.toArray(new Data[data.size()]); - } - - - @Override - protected boolean saveDateValues() { - ListGridRecord[] lgr = elements.getRecords(); - if (lgr.length == 0) { - return false; - } - String data = ""; - for (int i = 0; i < lgr.length; i++) { - DateRangeRecord drr = (DateRangeRecord) lgr[i]; - data += drr.getFrom() + "," + drr.getTo(); - data += ";"; - } - values = data; - return true; - } - - - protected static class DateRangeRecord extends ListGridRecord { - protected Date from; - protected Date to; - - protected final static String FROM_FIELD = "from"; - protected final static String TO_FIELD = "to"; - - public DateRangeRecord (Date from, Date to) { - setFrom(from); - setTo(to); - } - - @SuppressWarnings("deprecation") - public void setFrom(Date from) { - this.from = from; - setAttribute( - FROM_FIELD, - DateTimeFormat.getMediumDateFormat().format(from)); - } - - - @SuppressWarnings("deprecation") - public void setTo(Date to) { - this.to = to; - setAttribute( - TO_FIELD, - DateTimeFormat.getMediumDateFormat().format(to)); - } - - - public long getFrom() { - return this.from.getTime(); - } - - - public long getTo() { - return this.to.getTime(); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MultipleLocationPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,354 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.services.DistanceInfoService; -import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; -import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; -import de.intevation.flys.client.shared.DoubleUtils; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DistanceInfoObject; -import de.intevation.flys.client.shared.model.RangeData; - -import java.util.ArrayList; -import java.util.List; - - -/** - * This UIProvider creates a widget to enter a single location (km). - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class MultipleLocationPanel -extends LocationPanel -implements CellClickHandler -{ - private static final long serialVersionUID = -3359966826794082718L; - - /** The DistanceInfoService used to retrieve locations about rivers. */ - protected DistanceInfoServiceAsync distanceInfoService = - GWT.create(DistanceInfoService.class); - - /** The table data. */ - protected DistanceInfoObject[] tableData; - - /** The input helper (usually right side, table to click on, values are - * then entered in the texfield. */ - protected LocationPicker picker; - - - /** - * Creates a new LocationDistancePanel instance. - */ - public MultipleLocationPanel() { - picker = new LocationPicker(this); - } - - - /** - * This method creates a widget that contains a label, a panel with - * checkboxes to switch the input mode between location and distance input, - * and a mode specific panel. - * - * @param data The data that might be inserted. - * - * @return a panel. - */ - @Override - public Canvas create(DataList data) { - findDataItemName(data); - - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - - // Take translated data item name as label, if translation available. - String labelString; - try { - labelString = MSG.getString(getDataItemName()); - } - catch(java.util.MissingResourceException mre) { - GWT.log("Cannot find translation for data item name : " + getDataItemName()); - labelString = getLabelString(); - } - Label label = new Label(labelString); - Canvas widget = createWidget(data); - Canvas submit = getNextButton(); - - initDefaults(data); - - picker.createLocationTable(); - - widget.setHeight(50); - label.setHeight(25); - - layout.addMember(label); - layout.addMember(widget); - layout.addMember(submit); - - return layout; - } - - - /** - * This method reads the default values defined in the DataItems of the Data - * objects in <i>list</i>. - * - * @param list The DataList container that stores the Data objects. - */ - @Override - protected void initDefaults(DataList list) { - Data data = list.get(0); - - // Compatibility with MinMax- DataItems: - RangeData rangeData = null; - - for (int i = 0, n = list.size(); i < n; i++) { - Data tmp = list.get(i); - - if (tmp instanceof RangeData) { - rangeData = (RangeData) tmp; - } - } - - if (rangeData != null) { - min = Double.parseDouble(rangeData.getDefaultLower().toString()); - max = Double.parseDouble(rangeData.getDefaultUpper().toString()); - // catch ..? - } - else { - DataItem[] items = data.getItems(); - DataItem iMin = getDataItem(items, "min"); - DataItem iMax = getDataItem(items, "max"); - - try { - min = Double.parseDouble(iMin.getStringValue()); - max = Double.parseDouble(iMax.getStringValue()); - } - catch (NumberFormatException nfe) { - SC.warn(MSG.error_read_minmax_values()); - min = -Double.MAX_VALUE; - max = Double.MAX_VALUE; - } - } - - DataItem def = data.getDefault(); - if (def != null) { - String value = def.getStringValue(); - - try { - double d = Double.parseDouble(value); - setLocationValues(new double[] { d } ); - } - catch (NumberFormatException nfe) { - // could not parse, dont know what to do else - } - } - } - - - @Override - protected Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - inputLayout = new HLayout(); - - // The initial view will display the location input mode. - locationPanel = new DoubleArrayPanel( - MSG.unitLocation(), - getLocationValues(), - new BlurHandler(){@Override - public void onBlur(BlurEvent be) {validate();}}); - - picker.getLocationTable().setAutoFetchData(true); - - inputLayout.addMember(locationPanel); - - layout.addMember(inputLayout); - - inputLayout.setMembersMargin(30); - - picker.prepareFilter(); - - helperContainer.addMember(picker.getLocationTable()); - helperContainer.addMember(picker.getFilterLayout()); - helperContainer.addMember(picker.getResultCountForm()); - setPickerDataSource(); - return layout; - } - - - /** Overridden to restrict to one entered value. */ - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - DataList[] ref = artifact.getArtifactDescription().getOldData(); - String mode = ref[1].get(0).getStringValue(); - - saveLocationValues(locationPanel); - - if (!locationPanel.validateForm()) { - errors.add(MSG.wrongFormat()); - return errors; - } - - double[] lValues = getLocationValues(); - double[] good = new double[lValues.length]; - int idx = 0; - - double reference = - Double.valueOf(ref[2].get(0).getStringValue()).doubleValue(); - for (double value: lValues) { - if (mode.equals("calc.reference.curve") && - value == reference) { - errors.add(MSG.error_contains_same_location()); - return errors; - } - if (value < min || value > max) { - String tmp = MSG.error_validate_range(); - tmp = tmp.replace("$1", nf.format(value)); - tmp = tmp.replace("$2", nf.format(min)); - tmp = tmp.replace("$3", nf.format(max)); - errors.add(tmp); - } - else { - good[idx++] = value; - } - } - - double[] justGood = new double[idx]; - for (int i = 0; i < justGood.length; i++) { - justGood[i] = good[i]; - } - - if (!errors.isEmpty()) { - locationPanel.setValues(justGood); - } - - return errors; - } - - - /** - * This method returns the selected data (to feed). - * - * @return the selected/inserted data in feedable form. - */ - @Override - public Data[] getData() { - saveLocationValues(locationPanel); - double[] lValues = getLocationValues(); - Data[] data = new Data[2]; - boolean first = true; - String valueString = ""; - - for (int i = 0; i < lValues.length; i++) { - if (!first) valueString += " "; - else first = false; - valueString += Double.valueOf(lValues[i]).toString(); - } - - data[0] = createDataArray(getDataItemName(), valueString); - - data[1] = createDataArray("ld_mode", "locations"); - - return data; - } - - - /** Hook service to the listgrid with possible input values. */ - protected void setPickerDataSource() { - Config config = Config.getInstance(); - String url = config.getServerUrl(); - String river = ""; - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - // Try to find a "river" data item to set the source for the - // list grid. - String dataFilter = "locations"; - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - if (dl.getState().equals("state.minfo.river")) { - dataFilter = "measuringpoint"; - } - if (dl.getState().equals("state.winfo.river") || - dl.getState().equals("state.chart.river") || - dl.getState().equals("state.minfo.river")) { - for (int j = 0; j < dl.size(); j++) { - Data d = dl.get(j); - DataItem[] di = d.getItems(); - if (di != null && di.length == 1) { - river = d.getItems()[0].getStringValue(); - break; - } - } - } - } - } - - picker.getLocationTable().setDataSource(new DistanceInfoDataSource( - url, river, dataFilter)); - } - - - // TODO allow multiple selections here or in LocationPanel - /** - * Callback when an item from the input helper was clicked. - * Set the respective km-value in the location value field. - * @param e event passed. - */ - @Override - public void onCellClick (CellClickEvent e) { - Record record = e.getRecord(); - double[] old = getLocationValues(); - double[] selected = DoubleUtils.copyOf(old, old.length + 1); - try { - selected[old.length] = - Double.parseDouble(record.getAttribute("from")); - } - catch(NumberFormatException nfe) { - // Is there anything else to do here? - GWT.log(nfe.getMessage()); - } - - // compare reference location and target location. - DataList[] ref = artifact.getArtifactDescription().getOldData(); - String mode = ref[1].get(0).getStringValue(); - if (mode.equals("calc.reference.curve") && - ref[2].get(0).getStringValue().equals(record.getAttribute("from"))) - { - SC.warn(MSG.error_same_location()); - return; - } - - setLocationValues(selected); - } - - - /** - * Returns the label string for the input panel. - */ - protected String getLabelString() { - return MSG.location(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/NoInputPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.widgets.Canvas; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; - - -public class NoInputPanel -extends AbstractUIProvider -{ - private static final long serialVersionUID = -8789143404415288132L; - - - @Override - public Canvas create(DataList data) { - return new Canvas(); - } - - - @Override - public Canvas createOld(DataList dataList) { - return new Canvas(); - } - - - @Override - protected Data[] getData() { - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/OutputTab.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.tab.Tab; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.OutputMode; - - -public class OutputTab extends Tab { - - /** The OutputMode that should be displayed in this tab.*/ - protected OutputMode mode; - - /** The Collection that should be displayed in this tab.*/ - protected Collection collection; - - /** The CollectionView containing this tab. */ - protected CollectionView collectionView; - - - /** - * The default constructor that creates a new Tab for displaying a specific - * OutputMode of a Collection. - * - * @param title The title of the tab. - * @param collection The collection that need to be displayed. - * @param outputmode The OutputMode that need to be displayed. - */ - public OutputTab( - String title, - Collection collection, - CollectionView collectionView, - OutputMode mode - ) { - super(title); - - this.collection = collection; - this.mode = mode; - this.collectionView = collectionView; - - setPane(new Label("Implement concrete subclasses to vary the output.")); - } - - - public CollectionView getCollectionView() { - return collectionView; - } - - - public String getOutputName() { - return mode.getName(); - } - - - public Artifact getArtifact() { - return getCollectionView().getArtifact(); - } - - - public Collection getCollection() { - return collection; - } - - - public OutputMode getMode() { - return mode; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1023 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.types.VisibilityMode; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.SectionStack; -import com.smartgwt.client.widgets.layout.SectionStackSection; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.AdvanceHandler; -import de.intevation.flys.client.client.event.CollectionChangeEvent; -import de.intevation.flys.client.client.event.CollectionChangeHandler; -import de.intevation.flys.client.client.event.HasParameterChangeHandler; -import de.intevation.flys.client.client.event.HasStepBackHandlers; -import de.intevation.flys.client.client.event.HasStepForwardHandlers; -import de.intevation.flys.client.client.event.OutputModesChangeEvent; -import de.intevation.flys.client.client.event.OutputModesChangeHandler; -import de.intevation.flys.client.client.event.ParameterChangeEvent; -import de.intevation.flys.client.client.event.ParameterChangeHandler; -import de.intevation.flys.client.client.event.StepBackEvent; -import de.intevation.flys.client.client.event.StepBackHandler; -import de.intevation.flys.client.client.event.StepForwardEvent; -import de.intevation.flys.client.client.event.StepForwardHandler; -import de.intevation.flys.client.client.services.AdvanceService; -import de.intevation.flys.client.client.services.AdvanceServiceAsync; -import de.intevation.flys.client.client.services.ArtifactService; -import de.intevation.flys.client.client.services.ArtifactServiceAsync; -import de.intevation.flys.client.client.services.ReportService; -import de.intevation.flys.client.client.services.ReportServiceAsync; -import de.intevation.flys.client.client.services.StepForwardService; -import de.intevation.flys.client.client.services.StepForwardServiceAsync; -import de.intevation.flys.client.client.ui.stationinfo.GaugePanel; -import de.intevation.flys.client.client.ui.stationinfo.InfoPanel; -import de.intevation.flys.client.client.ui.stationinfo.MeasurementStationPanel; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.ExportMode; -import de.intevation.flys.client.shared.model.FixAnalysisArtifact; -import de.intevation.flys.client.shared.model.MINFOArtifact; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.ReportMode; -import de.intevation.flys.client.shared.model.River; -import de.intevation.flys.client.shared.model.WINFOArtifact; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - - -public class ParameterList -extends Tab -implements StepBackHandler, StepForwardHandler, ParameterChangeHandler, - HasParameterChangeHandler, CollectionChangeHandler, - OutputModesChangeHandler, AdvanceHandler -{ - private static final long serialVersionUID = 5204784727239299980L; - - public static final String STYLENAME_OLD_PARAMETERS = "oldParameters"; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** The ArtifactService used to communicate with the Artifact server. */ - protected ArtifactServiceAsync artifactService = - GWT.create(ArtifactService.class); - - /** The StepForwardService used to put data into an existing artifact. */ - protected StepForwardServiceAsync forwardService = - GWT.create(StepForwardService.class); - - /** The StepForwardService used to put data into an existing artifact. */ - protected AdvanceServiceAsync advanceService = - GWT.create(AdvanceService.class); - - - protected ReportServiceAsync reportService = - GWT.create(ReportService.class); - - - /** The list of ParameterizationChangeHandler.*/ - protected List<ParameterChangeHandler> parameterHandlers; - - protected FLYS flys; - - protected CollectionView cView; - - protected Artifact artifact; - - protected List<DataList> old; - protected Map<String, Canvas> oldStorage; - protected DataList current; - - protected UIProvider uiProvider; - - protected VLayout topLayout; - protected VLayout oldItems; - protected VLayout currentItems; - protected VLayout exportModes; - protected VLayout report; - protected VLayout helperPanel; - protected VLayout tablePanel; - protected InfoPanel infoPanel; - protected Canvas reportPanel; - - private SectionStack stack; - - public ParameterList(FLYS flys, CollectionView cView, String title) { - super(title); - - this.cView = cView; - this.flys = flys; - - parameterHandlers = new ArrayList<ParameterChangeHandler>(); - old = new ArrayList<DataList>(); - oldStorage = new TreeMap<String, Canvas>(); - topLayout = new VLayout(); - oldItems = new VLayout(); - currentItems = new VLayout(); - exportModes = new VLayout(); - report = new VLayout(); - - addParameterChangeHandler(this); - - init(); - } - - - public ParameterList( - FLYS flys, - CollectionView cView, - String title, - Artifact artifact) - { - super(title); - - this.cView = cView; - this.flys = flys; - this.artifact = artifact; - - parameterHandlers = new ArrayList<ParameterChangeHandler>(); - old = new ArrayList<DataList>(); - oldStorage = new TreeMap<String, Canvas>(); - topLayout = new VLayout(); - oldItems = new VLayout(); - currentItems = new VLayout(); - exportModes = new VLayout(); - report = new VLayout(); - - init(); - - addParameterChangeHandler(this); - - setArtifact(artifact, false); - } - - - protected void init() { - HLayout rootLayout = new HLayout(); - rootLayout.setMembersMargin(20); - - VLayout left = new VLayout(); - - if (old == null || old.size() == 0) { - oldItems.setHeight(1); - } - - oldItems.setMembersMargin(10); - oldItems.setStyleName(STYLENAME_OLD_PARAMETERS); - currentItems.setAlign(VerticalAlignment.TOP); - - left.setMembersMargin(20); - left.setWidth(300); - - left.addMember(oldItems); - left.addMember(currentItems); - left.addMember(exportModes); - left.addMember(report); - - reportPanel = new Canvas(); - reportPanel.setHeight("*"); - report.addMember(reportPanel); - - rootLayout.addMember(left); - rootLayout.addMember(createSectionStack()); - - topLayout.addMember(rootLayout); - if (artifact == null) { - Canvas moduleSelection = renderNew(); - moduleSelection.setLayoutAlign(VerticalAlignment.TOP); - currentItems.addMember(moduleSelection); - } - - setPane(topLayout); - } - - - protected SectionStack createSectionStack() { - stack = new SectionStack(); - stack.setHeight100(); - stack.setCanResizeSections(true); - stack.setVisibilityMode(VisibilityMode.MULTIPLE); - - // This canvas is used to render helper widgets. - final SectionStackSection helperSection = new SectionStackSection(); - helperSection.setExpanded(false); - helperSection.setTitle(MSG.helperPanelTitle()); - helperPanel = new VLayout() { - @Override - public void addMember(Canvas component) { - super.addMember(component); - stack.expandSection(helperSection.getID()); - } - - @Override - public void removeMembers(Canvas[] components) { - super.removeMembers(components); - helperSection.setExpanded(false); - } - }; - helperPanel.setWidth100(); - helperPanel.setHeight100(); - helperSection.setItems(helperPanel); - - // This canvas is used to render calculation results. - final SectionStackSection tableSection = new SectionStackSection(); - tableSection.setExpanded(false); - tableSection.setTitle(MSG.calcTableTitle()); - tablePanel = new VLayout() { - @Override - public void addMember(Canvas component) { - super.addMember(component); - tableSection.setExpanded(true); - } - - @Override - public void removeMembers(Canvas[] components) { - super.removeMembers(components); - tableSection.setExpanded(false); - } - }; - tablePanel.setHeight100(); - tablePanel.setWidth100(); - tableSection.setItems(tablePanel); - - stack.setSections(helperSection, tableSection); - - return stack; - } - - - /** Sets and forwards artifact. */ - protected void setArtifact(Artifact artifact) { - setArtifact(artifact, true); - } - - - protected void setArtifact(Artifact artifact, boolean forward) { - Artifact tmp = this.artifact; - this.artifact = artifact; - - if (forward) { - fireParameterChangeEvent( - tmp, this.artifact, ParameterChangeEvent.Type.FORWARD); - } - else { - fireParameterChangeEvent( - tmp, this.artifact, ParameterChangeEvent.Type.BACK); - } - } - - - /** - * This method registers a new ParameterChangeHandler. - * - * @param handler The new ParameterChangeHandler. - */ - @Override - public void addParameterChangeHandler(ParameterChangeHandler handler) { - if (handler != null) { - parameterHandlers.add(handler); - } - } - - - /** - * This method calls the <code>onParameterChange()</code> method of all - * registered ParameterChangeHandler. - */ - protected void fireParameterChangeEvent( - Artifact old, - Artifact newArt, - ParameterChangeEvent.Type type) - { - ParameterChangeEvent e = new ParameterChangeEvent(old, newArt, type); - - for (ParameterChangeHandler handler: parameterHandlers) { - handler.onParameterChange(e); - } - } - - - /** - * This method creates a Canvas displaying the plugins of FLYS combined with - * a widget to select a river. - * - * @return a Canvas that displays the supported plugins and rivers of FLYS. - */ - protected Canvas renderNew() { - River[] rivers = flys.getRivers(); - DataItem[] items = new DataItem[rivers.length]; - - int i = 0; - for (River river: rivers) { - String name = river.getName(); - items[i++] = new DefaultDataItem(name, null, name); - } - - Data data = new DefaultData( - "river", - MSG.river_selection(), - null, - items); - - LinkSelection widget = new LinkSelection(); - HasStepForwardHandlers handler = widget; - - widget.setContainer(helperPanel); - - handler.addStepForwardHandler(new StepForwardHandler() { - private static final long serialVersionUID = -6210719844707004860L; - - @Override - public void onStepForward(StepForwardEvent event) { - lockUI(); - Data[] data = event.getData(); - - DataItem[] moduleItems = data[0].getItems(); - DataItem[] riversItems = data[1].getItems(); - - String module = moduleItems[0].getStringValue(); - String river = riversItems[0].getStringValue(); - - if (module == null || river == null) { - GWT.log("ParameterList.renderNew(): module == null || river == null"); - unlockUI(); - return; - } - - String newTitle = MSG.getString(module); - setTitle(newTitle); - - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - final Data[] feedData = new Data[] { data[1] }; - - artifactService.create( - locale, module.toLowerCase(), null, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - unlockUI(); - GWT.log("Could not create the new artifact."); - SC.warn(FLYS.getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully created a new artifact."); - - forwardService.go(locale, artifact, feedData, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - unlockUI(); - GWT.log("Could not feed the artifact."); - SC.warn(caught.getMessage()); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully feed the artifact."); - old.clear(); - cView.addArtifactToCollection(artifact); - setArtifact(artifact); - unlockUI(); - } - }); - } - }); - } - }); - - DataList list = new DataList(); - list.add(data); - - return widget.create(list); - } - - - protected void clearOldData() { - old.clear(); - } - - - public void addOldData(DataList old) { - addOldData(old, true); - } - - - public void addOldData(DataList old, boolean redraw) { - if (old != null) { - this.old.add(old); - } - - refreshOld(redraw); - } - - - public void addOldDatas(DataList[] old) { - addOldDatas(old, true); - } - - - public void addOldDatas(DataList[] old, boolean redraw) { - if (old != null && old.length > 0) { - for (DataList o: old) { - if (o == null) { - continue; - } - - if (!exists(o)) { - GWT.log("Data '" + o.getLabel() + "' is new."); - addOldData(o, false); - } - } - - if (redraw) { - addOldData(null, true); - } - - return; - } - - addOldData(null, true); - } - - - public boolean exists(DataList data) { - if (data == null) { - return false; - } - - String stateName = data.getState(); - - for (DataList o: old) { - if (stateName.equals(o.getState())) { - return true; - } - } - - return false; - } - - - public void setCurrentData(DataList current, UIProvider uiProvider) { - this.current = current; - this.uiProvider = uiProvider; - - refreshCurrent(); - } - - - public void refreshOld(boolean redrawAll) { - if (redrawAll) { - refreshAllOld(); - } - else { - DataList dataList = old.get(old.size()-1); - String state = dataList.getState(); - - if (oldStorage.get(state) == null) { - String provider = dataList.getUIProvider(); - UIProvider uiprovider = UIProviderFactory.getProvider( - provider, - flys.getCurrentUser()); - ((HasStepBackHandlers) uiprovider).addStepBackHandler(this); - - Canvas c = uiprovider.createOld(dataList); - if (c != null) { - oldStorage.put(dataList.getState(), c); - oldItems.addMember(c); - } - } - } - - updateOldHeight(); - } - - - protected void refreshAllOld() { - List<String> not = new ArrayList<String>(); - - for (DataList data: old) { - String state = data.getState(); - - Canvas c = oldStorage.get(state); - - if (c != null) { - not.add(state); - } - } - - Map<String, Canvas> newOld = new TreeMap<String, Canvas>(); - - Set<Map.Entry<String, Canvas>> entries = oldStorage.entrySet(); - for (Map.Entry<String, Canvas> entry: entries) { - String state = entry.getKey(); - Canvas value = entry.getValue(); - - if (not.indexOf(state) < 0) { - oldItems.removeMember(value); - } - else { - newOld.put(state, value); - } - } - - oldStorage = newOld; - } - - - protected void updateOldHeight() { - int minHeight = oldItems.getMinHeight(); - if (minHeight <= 20) { - oldItems.setHeight(20); - } - else { - oldItems.setHeight(minHeight); - } - } - - - /** - * This method refreshes the part displaying the data of the current state. - * The UI is created using the UIProvider stored in the Data object. - */ - public void refreshCurrent() { - currentItems.removeMembers(currentItems.getMembers()); - - if (current != null && uiProvider != null) { - Canvas c = uiProvider.create(current); - Canvas h = uiProvider.createHelpLink(current, null); - - HLayout wrapper = new HLayout(); - wrapper.addMember(h); - wrapper.addMember(c); - - currentItems.addMember(wrapper); - } - else if (uiProvider != null) { - Canvas c = uiProvider.create(null); - c.setLayoutAlign(VerticalAlignment.TOP); - - currentItems.addMember(c); - } - else { - currentItems.setHeight(1); - } - - Canvas[] members = currentItems.getMembers(); - if (members == null || members.length == 0) { - currentItems.setHeight(1); - } - else { - int height = 0; - - for (Canvas member: members) { - height += member.getHeight(); - } - - currentItems.setHeight(height); - } - } - - - /** - * This method is called if the user clicks on the 'next' button to advance - * to the next state. - * - * @param event The StepForwardEvent. - */ - @Override - public void onStepForward(StepForwardEvent event) { - GWT.log("CollectionView - onStepForward()"); - lockUI(); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - forwardService.go(locale, artifact, event.getData(), - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - unlockUI(); - GWT.log("Could not feed the artifact."); - SC.warn(FLYS.getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully feed the artifact."); - old.clear(); - - setArtifact(artifact, true); - unlockUI(); - } - }); - } - - - /** - * This method is used to remove all old items from this list after the user - * has clicked the step back button. - * - * @param e The StepBackEvent that holds the identifier of the target state. - */ - @Override - public void onStepBack(StepBackEvent e) { - lockUI(); - final String target = e.getTarget(); - - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - advanceService.advance(locale, artifact, target, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - unlockUI(); - GWT.log("Could not go back to '" + target + "'"); - SC.warn(FLYS.getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully step back to '" + target + "'"); - - old.clear(); - - setArtifact(artifact, false); - unlockUI(); - } - } - ); - } - - - @Override - public void onAdvance(final String target) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - advanceService.advance(locale, artifact, target, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not go to '" + target + "'"); - SC.warn(FLYS.getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully advanced to '" + target + "'"); - - old.clear(); - - setArtifact(artifact, true); - } - } - ); - } - - - /** - * Implements the onCollectionChange() method to do update the GUI after the - * parameterization has changed. - * - * @param event The ParameterChangeEvent. - */ - @Override - public void onParameterChange(ParameterChangeEvent event) { - GWT.log("ParameterList.onParameterChange"); - - Canvas[] c = helperPanel.getMembers(); - if (c != null && c.length > 0) { - helperPanel.removeMembers(c); - } - - Artifact art = event.getNewValue(); - ArtifactDescription desc = art.getArtifactDescription(); - - DataList currentData = desc.getCurrentData(); - if (currentData != null) { - // the user has to enter some attributes - String uiProvider = currentData.getUIProvider(); - UIProvider provider = UIProviderFactory.getProvider( - uiProvider, - flys.getCurrentUser()); - - provider.setContainer(helperPanel); - provider.setArtifact(art); - provider.setCollection(cView.getCollection()); - provider.setParameterList(this); - - ((HasStepForwardHandlers) provider).addStepForwardHandler(this); - ((HasStepBackHandlers) provider).addStepBackHandler(this); - - setCurrentData(currentData, provider); - } - else { - String[] reachable = desc.getReachableStates(); - if (reachable != null && reachable.length > 0) { - // We have reached a final state with the option to step to - // further to a next state. But in the current state, no user - // data is required. - UIProvider ui = UIProviderFactory.getProvider("continue", null); - ui.setArtifact(art); - ui.setCollection(cView.getCollection()); - ui.setParameterList(this); - - ((ContinuePanel) ui).addAdvanceHandler(this); - - setCurrentData(null, ui); - } - else { - // we have reached a final state with no more user input - setCurrentData(null, null); - } - } - if (art instanceof WINFOArtifact - || art instanceof FixAnalysisArtifact) { - createGaugePanel(); - renderInfo(desc.getRiver(), desc.getOldData()); - } - else if (art instanceof MINFOArtifact) { - createMeasurementStationPanel(); - renderInfo(desc.getRiver(), desc.getOldData()); - } - else { - removeInfoPanel(); - } - - addOldDatas( - desc.getOldData(), - event.getType() == ParameterChangeEvent.Type.BACK); - } - - - @Override - public void onCollectionChange(CollectionChangeEvent event) { - Collection c = event.getNewValue(); - Map<String, OutputMode> outs = c.getOutputModes(); - Set<String> keys = outs.keySet(); - - OutputMode[] outputs = new OutputMode[outs.size()]; - - int idx = 0; - for (String outname: keys) { - outputs[idx++] = outs.get(outname); - } - - updateExportModes(c, getExportModes(outputs)); - updateReportModes(c, getReportModes(outputs)); - } - - - @Override - public void onOutputModesChange(OutputModesChangeEvent event) { - - Collection c = cView.getCollection(); - - if (c != null) { - OutputMode [] outs = event.getOutputModes(); - updateExportModes(c, getExportModes(outs)); - updateReportModes(c, getReportModes(outs)); - } - } - - - protected List<ReportMode> getReportModes(OutputMode [] outs) { - - List<ReportMode> reports = new ArrayList<ReportMode>(); - - if (outs == null || outs.length == 0) { - return reports; - } - - for (OutputMode out: outs) { - if (out instanceof ReportMode) { - reports.add((ReportMode)out); - } - } - - return reports; - } - - - protected List<ExportMode> getExportModes(OutputMode[] outs) { - List<ExportMode> exports = new ArrayList<ExportMode>(); - - if (outs == null || outs.length == 0) { - return exports; - } - - for (OutputMode out: outs) { - if (out instanceof ExportMode) { - exports.add((ExportMode) out); - } - } - - return exports; - } - - - protected void updateExportModes(Collection c, List<ExportMode> exports) { - int num = exports != null ? exports.size() : 0; - GWT.log("Update export modes: " + num); - - exportModes.removeMembers(exportModes.getMembers()); - - if (exports.size() > 0) { - exportModes.addMember(new ExportPanel(c, exports)); - } - else { - exportModes.setHeight(1); - } - } - - protected void updateReportModes(Collection c, List<ReportMode> reports) { - int num = reports != null ? reports.size() : 0; - GWT.log("Update report modes: " + num); - - if (num == 0) { - reportPanel.setContents(""); - return; - } - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - String cid = c.identifier(); - - for (ReportMode report: reports) { - GWT.log("report '" + report.toString() + "'"); - - reportService.report(cid, locale, report.getName(), - new AsyncCallback<String>() { - @Override - public void onFailure(Throwable caught) { - SC.warn(FLYS.getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(String msg) { - setReportMessage(msg); - } - }); - } - } - - - /** Sets content of reportPanel. */ - protected void setReportMessage(String msg) { - GWT.log("returned from service: " + msg); - if (msg == null) { - msg = ""; - } - reportPanel.setContents(msg); - } - - - /** - * Adds a table to the parameterlist to show calculated data. - * - * @param table The table data panel. - */ - public void setTable(TableDataPanel table) { - removeTable(); - - Canvas c = table.create(); - c.setHeight100(); - c.setWidth100(); - - tablePanel.addMember(c); - } - - - public boolean hasTable() { - Canvas[] members = tablePanel.getMembers(); - - return members != null && members.length > 0; - } - - - /** - * Removes the table from the parameter list. - */ - public void removeTable() { - Canvas[] members = tablePanel.getMembers(); - - if (members != null && members.length > 0) { - tablePanel.removeMembers(members); - } - } - - - public void registerCollectionViewTabHandler(TabSelectedHandler tsh) { - this.cView.registerTabHandler(tsh); - } - - - protected void lockUI() { - cView.lockUI(); - } - - - protected void unlockUI() { - cView.unlockUI(); - } - - - private void createGaugePanel() { - GWT.log("ParameterList - createGaugePanel"); - if (infoPanel == null) { - infoPanel = new GaugePanel(flys); - infoPanel.setWidth100(); - infoPanel.setHeight100(); - } - } - - private void createMeasurementStationPanel() { - GWT.log("ParameterList - createMeasurementStationPanel"); - if (infoPanel == null) { - infoPanel = new MeasurementStationPanel(flys); - infoPanel.setWidth100(); - infoPanel.setHeight100(); - } - } - - private void showInfoPanel() { - GWT.log("ParameterList - showInfoPanel"); - - /* Don't add InfoPanel twice */ - SectionStackSection exists = stack.getSection(InfoPanel.SECTION_ID); - if (exists == null) { - stack.addSection(infoPanel.getSection(), 0); - } - - infoPanel.show(); - } - - private void hideInfoPanel() { - GWT.log("ParameterList - hideInfoPanel"); - - if (infoPanel != null) { - infoPanel.hide(); - } - } - - private void removeInfoPanel() { - GWT.log("ParameterList - removeInfoPanel"); - SectionStackSection exists = stack.getSection(InfoPanel.SECTION_ID); - if (exists != null) { - stack.removeSection(InfoPanel.SECTION_ID); - } - } - - - private void renderInfo(String river, DataList[] data) { - GWT.log("ParameterList - renderInfo"); - - if (river != null) { - showInfoPanel(); - infoPanel.setRiver(river); - infoPanel.setData(data); - } - else { - GWT.log("ParameterList - renderInfo no river"); - hideInfoPanel(); - } - } - - /** - * Allow to close all folds of the info panel. - * This is necessary e.g. if a csv result should be shown. - */ - public void contractInfoPanel() { - if (infoPanel != null) { - infoPanel.contract(); - } - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,285 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.user.client.ui.CheckBox; -import com.google.gwt.user.client.ui.Grid; -import com.google.gwt.user.client.ui.Widget; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.IntegerOptionsData; -import de.intevation.flys.client.shared.model.StringOptionsData; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -/** - * Some parameters take the form of on/off options that can also be seen - * as a matrix. - * - * This class helps to survive the underlying objects and create a visual - * representation of this matrix. Later can happen in two ways to overcome - * shortcomings of GWT/SmartGWT combination. - */ -public class ParameterMatrix { - - protected ListGrid listGrid = null; - - public static class Column implements Serializable { - - private static final long serialVersionUID = -3493426383086860118L; - - protected String name; - protected Map<String, String> values; - - private Column() { - this.values = new HashMap<String, String>(); - } - - public Column(String name) { - this(); - this.name = name; - } - - public void addValue(String label, String value) { - values.put(label, value); - } - - public String getValue(String label) { - return values.get(label); - } - } // end of class Column - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - public static final int CELL_HEIGHT = 25; - - private Map<String, Column> columns; - private List<String> columnNames; - private List<String> valueNames; - - /** Maps column names to list of rows' first fields. */ - private Map<String, List<String>> selected; - - public ParameterMatrix() { - super(); - this.columns = new HashMap<String, Column>(); - this.columnNames = new ArrayList<String>(); - this.valueNames = new ArrayList<String>(); - this.selected = new HashMap<String, List<String>>(); - } - - - public void addColumn(IntegerOptionsData group) { - String groupTitle = group.getLabel(); - - Column col = new Column(groupTitle); - DataItem[] items = group.getItems(); - - if (items == null) { - GWT.log("No items found in StringOptionsData '" + groupTitle + "'"); - return; - } - - for (DataItem item: items) { - String title = item.getLabel(); - - if (valueNames.indexOf(title) < 0) { - valueNames.add(title); - } - - col.addValue(item.getLabel(), item.getStringValue()); - } - - columnNames.add(groupTitle); - columns.put(groupTitle, col); - } - - - public void addColumn(StringOptionsData options) { - String groupTitle = options.getLabel(); - - Column col = new Column(groupTitle); - DataItem[] items = options.getItems(); - - if (items == null) { - GWT.log("No items found in StringOptionsData '" + groupTitle + "'"); - return; - } - - for (DataItem item: items) { - String title = item.getLabel(); - - if (valueNames.indexOf(title) < 0) { - valueNames.add(title); - } - - col.addValue(item.getLabel(), item.getStringValue()); - } - - columnNames.add(groupTitle); - columns.put(groupTitle, col); - } - - - public Widget createParameterGrid() { - listGrid = new ListGrid(); - listGrid.setShowAllRecords(true); - listGrid.setWrapCells(true); - listGrid.setShowHeaderContextMenu(false); - listGrid.setCanReorderFields(false); - listGrid.setCanSort(false); - //listGrid.setAutoFitData(Autofit.VERTICAL); - listGrid.setFixedRecordHeights(false); - // TODO: Then also need "autofit" (when wrapping) - - ListGridField itemNameField = new ListGridField("itemname", " "); - ArrayList<ListGridField> fields = new ArrayList<ListGridField>(); - fields.add(itemNameField); - - for (int i = 0, n = columnNames.size(); i < n; i++) { - ListGridField field = new ListGridField(columnNames.get(i), MESSAGE.getString(columnNames.get(i))); - field.setType(ListGridFieldType.BOOLEAN); - field.setCanEdit(true); - fields.add(field); - selected.put(columnNames.get(i), new ArrayList<String>()); - } - - ListGridField[] fieldsArray = fields.toArray(new ListGridField[fields.size()]); - listGrid.setFields(fieldsArray); - - int nVals = valueNames.size(); - - ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>(); - for (int j = 0; j < nVals; j++) { - String valueName = valueNames.get(j); - ListGridRecord record = new ListGridRecord(); - record.setAttribute("itemname", valueName); - for (int i = 0, n = columnNames.size(); i < n; i++) { - String columnName = columnNames.get(i); - Column col = columns.get(columnName); - String value = col.getValue(valueName); - record.setAttribute(columnName, false); - record.setAttribute(columnName+"-value", value); - } - records.add(record); - } - - listGrid.setData(records.toArray(new ListGridRecord[records.size()])); - - return listGrid; - - } - - - /** - * Returns a widget with matrix of checkboxes and labels. - * @param asListGrid if true, use a ListGrid (for inclusion in SmartGWT - * containers, avoiding scrollbar-issues. - */ - public Widget create(boolean asListGrid) { - if (asListGrid) { - return createParameterGrid(); - } - Grid grid = new Grid(valueNames.size() + 1, columnNames.size() + 1); - - for (int i = 0, n = columnNames.size(); i < n; i++) { - String columnName = columnNames.get(i); - Column col = columns.get(columnName); - - selected.put(columnName, new ArrayList<String>()); - - grid.setWidget(0, i+1, createLabel(MESSAGE.getString(columnName))); - - for (int j = 0, o = valueNames.size(); j < o; j++) { - String valueName = valueNames.get(j); - String value = col.getValue(valueName); - - if (i == 0) { - grid.setWidget(j+1, 0, createLabel(valueName)); - } - - if (value != null && value.length() > 0) { - grid.setWidget(j+1, i+1, createCheckBox(columnName, value)); - } - } - } - - return grid; - } - - - /** Creates label with given text. */ - protected Label createLabel(String text) { - Label label = new Label(text); - label.setHeight(CELL_HEIGHT); - - return label; - } - - - /** Create Checkbox for column/value. */ - protected Canvas createCheckBox(final String colName, final String value) { - CheckBox box = new CheckBox(); - box.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - Map<String, List<String>> selection = getSelection(); - - List<String> values = selection.get(colName); - if (values.indexOf(value) >= 0) { - values.remove(value); - } - else { - values.add(value); - } - } - }); - - Canvas c = new Canvas(); - c.addChild(box); - return c; - } - - - public Map<String, List<String>> getSelection() { - if (listGrid == null) { - return selected; - } - - ListGridRecord[] records = listGrid.getRecords(); - Map<String, List<String>> result = new HashMap<String, List<String>>(); - for (ListGridRecord record : records) { - for (int i = 0, n = columnNames.size(); i < n; i++) { - String columnName = columnNames.get(i); - if (Boolean.valueOf(record.getAttribute(columnName)) == true) { - if (result.containsKey(columnName)) { - result.get(columnName).add(record.getAttribute(columnName + "-value")); - } - else { - List<String> items = new ArrayList<String>(); - items.add(record.getAttribute(columnName + "-value")); - result.put(columnName, items); - } - } - } - } - return result; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrixPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.ui.HTML; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.IntegerOptionsData; -import de.intevation.flys.client.shared.model.StringOptionsData; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ParameterMatrixPanel extends AbstractUIProvider { - - private static final long serialVersionUID = -5827445025768340371L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - private ParameterMatrix matrix; - - @Override - protected Data[] getData() { - Map<String, List<String>> selection = matrix.getSelection(); - Set<Map.Entry<String, List<String>>> entries = selection.entrySet(); - - Data[] list = new Data[selection.size()]; - - int i = 0; - - for (Map.Entry<String, List<String>> entry: entries) { - String value = buildValueString(entry.getValue()); - - DataItem item = new DefaultDataItem( - entry.getKey(), - null, - value); - - list[i++] = new DefaultData( - entry.getKey(), null, null, new DataItem[] { item }); - } - - return list; - } - - - protected String buildValueString(List<String> values) { - StringBuilder sb = new StringBuilder(); - - boolean first = true; - - for (String value: values) { - if (!first) { - sb.append(";"); - } - - sb.append(value); - - first = false; - } - - return sb.toString(); - } - - - /** Canvas to show in non-edit mode. */ - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - VLayout vLayout = new VLayout(); - - layout.setWidth(300); - vLayout.setWidth(280); - - for (int i = 0, n = dataList.size(); i < n; i++) { - HLayout row = new HLayout(); - VLayout cols = new VLayout(); - - row.setWidth(300); - cols.setWidth(100); - - Data data = dataList.get(i); - DataItem[] items = data.getItems(); - - Label parameter = new Label(data.getDescription()); - parameter.setWidth(200); - - for (int j = 0, m = items.length; j < m; j++) { - DataItem item = items[j]; - Label value = new Label(item.getLabel()); - - value.setValign(com.smartgwt.client.types.VerticalAlignment.TOP); - value.setWidth(130); - value.setHeight(20); - - cols.addMember(value); - HTML hr = new HTML("<hr>"); - hr.setHeight("3px"); - cols.addMember(hr); - } - - row.addMember(parameter); - row.addMember(cols); - - vLayout.addMember(row); - } - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - - /** Create the main canvas in the "editing" mode. */ - @Override - public Canvas create(DataList dataList) { - VLayout v = new VLayout(); - v.addMember(createTitle(dataList)); - - matrix = new ParameterMatrix(); - - for (Data data: dataList.getAll()) { - if (data instanceof IntegerOptionsData) { - matrix.addColumn((IntegerOptionsData) data); - } - else if (data instanceof StringOptionsData) { - matrix.addColumn((StringOptionsData) data); - } - } - - // If too many items are shown, show it in the helper Panel. - // TODO its not about the datalist, but about the "rows" in the data. - if (dataList.getAll().size() > 5) { - v.addMember(matrix.create(false)); - } - else { - helperContainer.addMember(matrix.create(true)); - } - v.addMember(getNextButton()); - - return v; - } - - - /** Reaturns a label with description of first Data. */ - protected Canvas createTitle(DataList dataList) { - Data data = dataList.get(0); - Label label = new Label(data.getDescription()); - label.setHeight(35); - - return label; - } - - - /** Selection shall not be empty. */ - @Override - public List<String> validate() { - GWT.log ("validation. validation. validation. "); - List<String> errors = new ArrayList<String>(); - // Early stop on one (only) error. - boolean ok = false; - for (Map.Entry<String, List<String>> entry : matrix.getSelection().entrySet()) { - /* single entries are allowed!! - if (entry.getValue() == null || entry.getValue().size() == 0) { - errors.add(MESSAGES.error_values_needed()); - return errors; - } - */ - if (entry.getValue() != null && entry.getValue().size() > 0) { - ok = true; - } - } - if (!ok) { - errors.add(MESSAGES.error_values_needed()); - } - return errors; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/PeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,194 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.DateRangeItem; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class PeriodPanel -extends AbstractUIProvider -{ - private static final long serialVersionUID = -5249560815807538821L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - DateRangeItem inputPanel; - - long start; - long end; - - protected String startName; - protected String endName; - - public PeriodPanel() { - this("start", "end"); - } - - public PeriodPanel(String startName, String endName) { - this.startName = startName; - this.endName = endName; - } - - - @Override - public Canvas create(DataList list) { - VLayout layout = new VLayout(); - - Canvas helper = createHelper(); - this.helperContainer.addMember(helper); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(list); - - layout.addMember(widget); - layout.addMember(submit); - return layout; - } - - - public Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - - Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - DynamicForm form = new DynamicForm(); - inputPanel = new DateRangeItem(); - inputPanel.setToTitle(MSG.to()); - inputPanel.setFromTitle(MSG.from()); - inputPanel.setShowTitle(false); - form.setFields(inputPanel); - - layout.addMember(title); - layout.addMember(form); - - return layout; - } - - protected Canvas createHelper() { - return new VLayout(); - } - - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data start = getData(items, startName); - Data end = getData(items, endName); - DataItem[] startItem = start.getItems(); - DataItem[] endItem = end.getItems(); - - String v1 = startItem[0].getStringValue(); - String v2 = endItem[0].getStringValue(); - - long v1l = 0; - long v2l = 0; - try { - v1l = Long.parseLong(v1); - v2l = Long.parseLong(v2); - } - catch(NumberFormatException nfe) { - GWT.log(nfe.toString()); - } - Date d1 = new Date(v1l); - Date d2 = new Date(v2l); - - DateTimeFormat f = - DateTimeFormat.getFormat( - DateTimeFormat.PredefinedFormat.DATE_MEDIUM); - StringBuilder sb = new StringBuilder(); - sb.append(f.format(d1) + " - "); - sb.append(f.format(d2)); - - Label old = new Label(sb.toString()); - old.setWidth(130); - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - boolean valid = saveDateValues(); - if(valid) { - String start = Long.valueOf(this.start).toString(); - String end = Long.valueOf(this.end).toString(); - DataItem startItem = new DefaultDataItem(startName, startName, start); - DataItem endItem = new DefaultDataItem(endName, endName, end); - data.add(new DefaultData( - startName, - null, - null, - new DataItem[] { startItem })); - data.add(new DefaultData( - endName, - null, - null, - new DataItem[] { endItem })); - } - - return data.toArray(new Data[data.size()]); - } - - - protected boolean saveDateValues() { - Date st = inputPanel.getFromDate(); - Date en = inputPanel.getToDate(); - if (st == null || en == null) { - SC.warn(MSG.error_wrong_date()); - return false; - } - - long start = st.getTime(); - long end = en.getTime(); - - if (start <= end) { - this.start = start; - this.end = end; - return true; - } - return false; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,956 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.Autofit; -import com.smartgwt.client.types.ListGridEditEvent; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.Overflow; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.types.SortArrow; -import com.smartgwt.client.types.SortDirection; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.util.BooleanCallback; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.IconButton; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.VisibilityChangedEvent; -import com.smartgwt.client.widgets.events.VisibilityChangedHandler; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.HoverCustomizer; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; -import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent; -import com.smartgwt.client.widgets.grid.events.CellDoubleClickHandler; -import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; -import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; -import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickEvent; -import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickHandler; -import com.smartgwt.client.widgets.grid.events.RowContextClickEvent; -import com.smartgwt.client.widgets.grid.events.RowContextClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -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.MenuItemSeparator; -import com.smartgwt.client.widgets.menu.events.ClickHandler; -import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.CollectionChangeEvent; -import de.intevation.flys.client.client.event.CollectionChangeHandler; -import de.intevation.flys.client.client.event.FilterHandler; -import de.intevation.flys.client.client.event.RangeFilterEvent; -import de.intevation.flys.client.client.event.StringFilterEvent; -import de.intevation.flys.client.client.services.AddArtifactService; -import de.intevation.flys.client.client.services.AddArtifactServiceAsync; -import de.intevation.flys.client.client.services.ArtifactService; -import de.intevation.flys.client.client.services.ArtifactServiceAsync; -import de.intevation.flys.client.client.services.CreateCollectionService; -import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; -import de.intevation.flys.client.client.services.DeleteCollectionService; -import de.intevation.flys.client.client.services.DeleteCollectionServiceAsync; -import de.intevation.flys.client.client.services.DescribeCollectionService; -import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; -import de.intevation.flys.client.client.services.GetArtifactService; -import de.intevation.flys.client.client.services.GetArtifactServiceAsync; -import de.intevation.flys.client.client.services.SetCollectionNameService; -import de.intevation.flys.client.client.services.SetCollectionNameServiceAsync; -import de.intevation.flys.client.client.services.SetCollectionTTLService; -import de.intevation.flys.client.client.services.SetCollectionTTLServiceAsync; -import de.intevation.flys.client.client.services.UserCollectionsService; -import de.intevation.flys.client.client.services.UserCollectionsServiceAsync; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItem; -import de.intevation.flys.client.shared.model.CollectionRecord; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.MissingResourceException; - - -/** - * The project list shows a list of projects of a specific user. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ProjectList -extends VLayout -implements CollectionChangeHandler, EditCompleteHandler, FilterHandler, - VisibilityChangedHandler -{ - /** Interval to refresh the user's projects.*/ - public static final int UPDATE_INTERVAL = 30000; - - /** Min Interval to refresh the user's projects.*/ - public static final int MIN_UPDATE_INTERVAL = 5000; - - /** The initial width of this panel.*/ - public static final int MIN_WIDTH = 300; - - /** The max length for new project names.*/ - public static final int MAX_NAME_LENGTH = 50; - - public static final String COLUMN_DATE_WIDTH = "100px"; - - public static final String COLUMN_TITLE_WIDTH = "*"; - - public static final String COLUMN_FAVORITE_WIDTH = "75px"; - - /** The interface that provides i18n messages. */ - private final FLYSConstants messages = GWT.create(FLYSConstants.class); - - /** The UserService used to retrieve information about the current user. */ - protected UserCollectionsServiceAsync userCollectionsService = - GWT.create(UserCollectionsService.class); - - /** The service used to set the name of a project.*/ - protected SetCollectionNameServiceAsync nameService = - GWT.create(SetCollectionNameService.class); - - /** The service used to set the name of a project.*/ - protected SetCollectionTTLServiceAsync ttlService = - GWT.create(SetCollectionTTLService.class); - - /** The service used to set the name of a project.*/ - protected DeleteCollectionServiceAsync deleteService = - GWT.create(DeleteCollectionService.class); - - /** The DescribeCollectionService used to update the existing collection. */ - protected DescribeCollectionServiceAsync describeCollectionService = - GWT.create(DescribeCollectionService.class); - - /** The ArtifactService used to communicate with the Artifact server. */ - protected ArtifactServiceAsync createArtifactService = - GWT.create(ArtifactService.class); - - /** The ArtifactService used to communicate with the Artifact server. */ - protected CreateCollectionServiceAsync createCollectionService = - GWT.create(CreateCollectionService.class); - - /** The AddArtifactService used to add an artifact to a collection. */ - protected AddArtifactServiceAsync addArtifactService = - GWT.create(AddArtifactService.class); - - /** The GetArtifactService used to open an existing collection. */ - protected GetArtifactServiceAsync getArtifactService = - GWT.create(GetArtifactService.class); - - /** A pointer to the FLYS instance.*/ - protected FLYS flys; - - /** The user whose projects should be displayed.*/ - protected User user; - - /** The grid that contains the project rows.*/ - protected ListGrid grid; - - /** All user collections.*/ - protected List<Collection> collections; - - /** The collection to clone*/ - protected Collection cloneCollection; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - private String filter; - - - /** - * The default constructor that creates a new ProjectList for a specific - * user. - * - * @param user The user. - */ - public ProjectList(FLYS flys, User user) { - super(); - this.flys = flys; - this.user = user; - - collections = new ArrayList<Collection>(); - grid = new ListGrid(); - initGrid(); - init(); - initTimer(); - - grid.addEditCompleteHandler(this); - - addVisibilityChangedHandler(this); - - updateUserCollections(); - } - - - protected void initGrid() { - grid.setWidth100(); - grid.setAutoFitData(Autofit.VERTICAL); - grid.setAutoFitMaxWidth(500); - grid.setEmptyMessage(messages.no_projects()); - grid.setLoadingDataMessage(messages.load_projects()); - grid.setCanEdit(false); - grid.setEditEvent(ListGridEditEvent.NONE); - grid.setShowHeaderContextMenu(false); - grid.setShowSortArrow(SortArrow.NONE); - grid.setSortDirection(SortDirection.DESCENDING); - grid.setSortField(0); - grid.setSelectionType(SelectionStyle.SINGLE); - grid.setCanReorderFields(false); - grid.setLeaveScrollbarGap(false); - grid.setBorder("0px"); - - ListGridField date = buildDateField(); - ListGridField name = buildNameField(); - ListGridField fav = buildFavoriteField(); - - grid.setFields(date, name, fav); - - grid.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() { - @Override - public void onHeaderDoubleClick(HeaderDoubleClickEvent event) { - // Cancel the event. - return; - } - }); - - // Add a handler to set / unset the favorite state of a project. - grid.addCellClickHandler(new CellClickHandler() { - @Override - public void onCellClick(CellClickEvent event) { - if (event.getColNum() != 2) { - return; - } - - CollectionRecord r = (CollectionRecord) event.getRecord(); - Collection c = r.getCollection(); - - c.setTTL(c.getTTL() == 0 ? -1 : 0); - updateCollectionTTL(c); - } - }); - - // Add a handler to open a project. - grid.addCellDoubleClickHandler(new CellDoubleClickHandler() { - @Override - public void onCellDoubleClick(CellDoubleClickEvent e) { - CollectionRecord record = (CollectionRecord) e.getRecord(); - String uuid = record != null - ? record.getCollection().identifier() - : ""; - getFlys().openProject(uuid); - } - }); - - // Add a handler to open a context menu. - grid.addRowContextClickHandler(new RowContextClickHandler() { - @Override - public void onRowContextClick(RowContextClickEvent event) { - CollectionRecord record = (CollectionRecord) event.getRecord(); - - Menu menu = createContextMenu(record); - grid.setContextMenu(menu); - menu.showContextMenu(); - - event.cancel(); - } - }); - } - - - /** - * Initializes a repeating timer that updates the user's collections. The - * interval is specified by the constant <i>UPDATE_INTERVAL</i>. - */ - protected void initTimer() { - Config config = Config.getInstance(); - int interval = config.getProjectListUpdateInterval(); - - interval = interval > MIN_UPDATE_INTERVAL ? interval : UPDATE_INTERVAL; - - GWT.log("Update project list every " + interval + " milliseconds."); - - Timer t = new Timer() { - @Override - public void run() { - updateUserCollections(); - } - }; - - t.scheduleRepeating(interval); - } - - - public FLYS getFlys() { - return flys; - } - - - /** - * Creates a new context menu that interacts with a CollectionRecord. - * - * @param record The selected record. - * - * @return the context menu with operations that interact with - * <i>record</i>. - */ - protected Menu createContextMenu(final CollectionRecord record) { - Menu menu = new Menu(); - - MenuItem open = new MenuItem(messages.open_project()); - open.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - getFlys().openProject(record.getCollection().identifier()); - } - }); - - MenuItem del = new MenuItem(messages.delete_project()); - del.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - SC.ask(messages.really_delete(), new BooleanCallback() { - @Override - public void execute(Boolean value) { - if (value) { - deleteCollection(record.getCollection()); - } - } - }); - } - }); - - MenuItem rename = new MenuItem(messages.rename_project()); - rename.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - int row = grid.getRecordIndex(record); - grid.startEditing(row, 1, false); - } - }); - - MenuItem clone = new MenuItem(messages.clone_project()); - clone.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - cloneProject(record.getCollection()); - } - }); - - menu.addItem(open); - menu.addItem(rename); - menu.addItem(clone); - menu.addItem(new MenuItemSeparator()); - menu.addItem(del); - - return menu; - } - - - /** - * The init() method handles the layout stuff for this widget. - */ - protected void init() { - setWidth(MIN_WIDTH); - setMinWidth(MIN_WIDTH); - setHeight100(); - setShowResizeBar(true); - setShowEdges(false); - setLayoutMargin(0); - setLayoutAlign(VerticalAlignment.TOP); - setOverflow(Overflow.AUTO); - - Label title = new Label(messages.projects()); - title.setHeight("20"); - title.setMargin(5); - title.setWidth100(); - title.setStyleName("projectHeader"); - - HLayout buttonWrapper = new HLayout(); - - IconButton addButton = new IconButton(""); - addButton.setIcon(messages.projectListAdd()); - addButton.setTooltip(messages.new_project()); - addButton.setWidth("30px"); - - IconButton closeButton = new IconButton(""); - closeButton.setIcon(messages.projectListMin()); - closeButton.setTooltip(messages.projectlist_close()); - closeButton.setWidth("30px"); - - buttonWrapper.addMember(addButton); - buttonWrapper.addMember(closeButton); - buttonWrapper.setAlign(Alignment.RIGHT); - buttonWrapper.setAutoWidth(); - - HLayout titleWrapper = new HLayout(); - titleWrapper.setStyleName("bgBlueMid"); - titleWrapper.setWidth100(); - titleWrapper.setHeight("20px"); - titleWrapper.addMember(title); - titleWrapper.addMember(buttonWrapper); - - Canvas gridWrapper = new Canvas(); - gridWrapper.setPadding(0); - titleWrapper.setWidth100(); - gridWrapper.addChild(grid); - - TableFilter filterpanel = new TableFilter(); - filterpanel.setHeight("30px"); - filterpanel.addFilterHandler(this); - filterpanel.setBorder("1px solid gray"); - - addMember(titleWrapper); - addMember(gridWrapper); - addMember(filterpanel); - - addButton.addClickHandler( - new com.smartgwt.client.widgets.events.ClickHandler() { - - @Override - public void onClick(ClickEvent ev) { - flys.newProject(); - } - }); - - closeButton.addClickHandler( - new com.smartgwt.client.widgets.events.ClickHandler() { - - @Override - public void onClick(ClickEvent ev) { - hide(); - } - }); - } - - - @Override - public void onFilterCriteriaChanged(StringFilterEvent event) { - String search = event.getFilter(); - // Filter the records. - setFilter(search); - updateGrid(); - } - - - @Override - public void onFilterCriteriaChanged(RangeFilterEvent event) { - //Empty. No Ranges to filter. - } - - - /** On collection change, update list (probably name change or similar). */ - @Override - public void onCollectionChange(CollectionChangeEvent event) { - if (event.getOldValue() == null) { - updateUserCollections(); - } - } - - - @Override - public void onEditComplete(EditCompleteEvent event) { - if (event.getColNum() != 1) { - return; - } - - int row = event.getRowNum(); - - CollectionRecord r = (CollectionRecord) grid.getRecord(row); - Collection c = r.getCollection(); - - Map<?, ?> newValues = event.getNewValues(); - String name = (String) newValues.get("name"); - - int maxLength = getMaxNameLength(); - int length = name != null ? name.length() : 0; - - if (length <= 0 || length > maxLength) { - String msg = messages.project_name_too_long(); - msg = msg.replace("$LEN", String.valueOf(maxLength)); - SC.warn(msg); - - ListGridRecord[] rs = grid.getRecords(); - rs[row] = (ListGridRecord) event.getOldRecord(); - grid.setRecords(rs); - - return; - } - - updateCollectionName(c, name); - } - - - /** - * Set the name of the collection <i>c</i> to a new value. If the update - * process succeeded, the project list is refreshed. - * - * @param c The Collection with a new name. - * @param name Name to set on the collection - */ - private void updateCollectionName(final Collection c, String name) { - if (c == null) { - return; - } - - c.setName(name); - - GWT.log("Update Collection name: " + c.identifier()); - GWT.log("=> New name = " + c.getName()); - - nameService.setName(c, new AsyncCallback<Void>(){ - @Override - public void onFailure(Throwable caught) { - String msg = caught.getMessage(); - - try { - SC.warn(messages.getString(msg)); - } - catch (MissingResourceException mre) { - SC.warn(msg); - } - } - - @Override - public void onSuccess(Void v) { - updateUserCollections(); - if(flys.getWorkspace().hasView(c.identifier())) { - flys.getWorkspace().updateTitle(c.identifier(), c.getName()); - } - } - }); - } - - - /** - * Set the ttl of the collection <i>c</i> to a new value. If the update - * process succeeded, the project list is refreshed. - * - * @param c The Collection with a new ttl. - */ - protected void updateCollectionTTL(Collection c) { - if (c == null) { - return; - } - - GWT.log("Update Collection TTL: " + c.identifier()); - GWT.log("=> New ttl = " + c.getTTL()); - - ttlService.setTTL(c, new AsyncCallback<Void>() { - @Override - public void onFailure(Throwable caught) { - String msg = caught.getMessage(); - - try { - SC.warn(messages.getString(msg)); - } - catch (MissingResourceException mre) { - SC.warn(msg); - } - } - - @Override - public void onSuccess(Void v) { - updateUserCollections(); - } - }); - } - - - /** - * Delete the collection <i>c</i>. - * - * @param c The Collection that should be deleted. - */ - public void deleteCollection(final Collection c) { - if (c == null) { - return; - } - - GWT.log("Delete Collection: " + c.identifier()); - - deleteService.delete(c, new AsyncCallback<Void>(){ - @Override - public void onFailure(Throwable caught) { - String msg = caught.getMessage(); - - try { - SC.warn(messages.getString(msg)); - } - catch (MissingResourceException mre) { - SC.warn(msg); - } - } - - @Override - public void onSuccess(Void v) { - flys.getWorkspace().destroyProject(c.identifier()); - updateUserCollections(); - } - }); - } - - - public void updateUserCollections() { - GWT.log("==> ProjectList updates user collections!"); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - userCollectionsService.getUserCollections(locale, user.identifier(), - new AsyncCallback<Collection[]>() { - @Override - public void onFailure(Throwable caught) { - String msg = caught.getMessage(); - - try { - SC.warn(messages.getString(msg)); - } - catch (MissingResourceException mre) { - SC.warn(msg); - } - } - - @Override - public void onSuccess(Collection[] collections) { - int num = collections != null ? collections.length : 0; - - GWT.log("Received " + num + " user collections."); - - updateGridDataSource(collections); - } - } - ); - } - - - /** - * Delete all entries in the ListGrid. - */ - private void clearGrid() { - ListGridRecord[] records = grid.getRecords(); - - for (ListGridRecord record: records) { - grid.removeData(record); - } - } - - - /** - * Update the collections data source. - * - * First removes all collections to avoid duplicates, then add new entries. - * - * @param c Collections to set to the data source. - */ - private void updateGridDataSource(Collection[] c) { - collections.clear(); - if(c == null) { - clearGrid(); - return; - } - for (Collection coll : c) { - this.collections.add(coll); - } - updateGrid(); - } - - - /** - * Updates the ListGrid. - */ - private void updateGrid() { - clearGrid(); - - if (collections == null || collections.isEmpty()) { - return; - } - - for (Collection col: collections) { - String name; - - name = col.getDisplayName().toLowerCase(); - - // Add a collection to the filtered list if the search string - // matches. - if (filter == null || filter.isEmpty() || - name.contains(filter.toLowerCase())) { - grid.addData(new CollectionRecord(col)); - } - } - } - - public int getMaxNameLength() { - return MAX_NAME_LENGTH; - } - - - /** - * Builds the field in the grid that displays the creation time of a - * project. - * - * @return the grid field. - */ - protected ListGridField buildDateField() { - ListGridField date = new ListGridField( - "creationTime", messages.projectlist_creationTime()); - - date.setType(ListGridFieldType.DATE); - date.setCanEdit(false); - - date.setCellFormatter(new CellFormatter() { - @Override - public String format(Object value, ListGridRecord rec, int r, int c) { - if (value == null) { - return null; - } - - DateTimeFormat dtf = DateTimeFormat.getFormat( - messages.datetime_format()); - - return dtf.format((Date)value); - } - }); - - date.setWidth(COLUMN_DATE_WIDTH); - date.setAlign(Alignment.CENTER); - - return date; - } - - - /** - * Builds the field in the grid that displays the name of a project. - * - * @return the grid field. - */ - protected ListGridField buildNameField() { - ListGridField name = new ListGridField( - "name", messages.projectlist_title()); - - name.setType(ListGridFieldType.TEXT); - name.setShowHover(true); - name.setHoverCustomizer(new HoverCustomizer() { - @Override - public String hoverHTML( - Object value, - ListGridRecord record, - int row, - int col) - { - CollectionRecord r = (CollectionRecord) record; - Collection c = r.getCollection(); - - String name = r.getName(); - - return name != null && name.length() > 0 - ? name - : c.identifier(); - } - }); - - name.setWidth(COLUMN_TITLE_WIDTH); - name.setAlign(Alignment.LEFT); - - return name; - } - - - protected ListGridField buildFavoriteField() { - ListGridField fav = new ListGridField( - "ttl", messages.projectlist_favorite()); - - fav.setType(ListGridFieldType.IMAGE); - String base = GWT.getHostPageBaseURL(); - fav.setImageURLPrefix(base + "images/"); - fav.setImageURLSuffix(".png"); - fav.setWidth(COLUMN_FAVORITE_WIDTH); - fav.setAlign(Alignment.CENTER); - fav.setCanEdit(false); - - return fav; - } - - - protected void cloneProject(Collection c) { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - cloneCollection = c; - - describeCollectionService.describe(c.identifier(), locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not DESCRIBE collection."); - SC.warn(messages.getString(caught.getMessage())); - } - - - @Override - public void onSuccess(Collection newCollection) { - GWT.log("Successfully DESCRIBED collection."); - String uuid = getMasterArtifact(newCollection); - cloneArtifact(uuid, newCollection); - } - } - ); - } - - - /** Get master artifacts UUID of a collection. */ - protected String getMasterArtifact(Collection newCollection) { - String uuid = newCollection.getItem(0).identifier(); - // The master artifact uuid. - return uuid; - } - - - /** Clone artifact/create collection, using the refArtifacts factory. */ - protected void cloneArtifact(String uuid, Artifact refArtifact, - final String locale) { - Recommendation recommendation = new Recommendation( - refArtifact.getName(), - null, - uuid, - null); - - String factory = recommendation.getFactory(); - createArtifactService.create( - locale, factory, recommendation, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Error loading recommendations: " + - caught.getMessage()); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Created new artifact: " + artifact.getUuid()); - createClonedCollection(artifact); - } - } - ); - } - - - /** - * Clone a project (collection). - */ - private void cloneArtifact(final String uuid, Collection newCollection) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - // Find out which factory to use for cloning. - CollectionItem master = newCollection.getItem(0); - getArtifactService.getArtifact( - locale, - master.identifier(), - master.hash(), - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - SC.warn(MSG.getString(caught.getMessage())); - } - - @Override - public void onSuccess(Artifact artifact) { - cloneArtifact(uuid, artifact, locale); - } - }); - } - - - /** - * Creates a {@link Collection} with the passed {@link Artifact} - * @param artifact {@link Artifact} to add to the new {@link Collection} - */ - private void createClonedCollection(final Artifact artifact) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - final String ownerid = user.identifier(); - - createCollectionService.create( - locale, - ownerid, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not create the new collection."); - SC.warn(messages.getString(caught.getMessage())); - } - - @Override - public void onSuccess(Collection collection) { - GWT.log("Successfully created a new collection."); - addArtifactToClonedCollection(artifact, collection); - } - } - ); - } - - - private void addArtifactToClonedCollection(Artifact a, Collection c) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - addArtifactService.add( - c, a, locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("An error occured while adding artifact."); - SC.warn(messages.getString(caught.getMessage())); - } - - @Override - public void onSuccess(Collection newColl) { - String name = cloneCollection.getName(); - if(name == null || name.equals("")) { - name = cloneCollection.identifier(); - } - - String colname = messages.copy_of() + ": " + name; - - updateCollectionName(newColl, colname); - if(cloneCollection.getTTL() == 0) { - newColl.setTTL(0); - updateCollectionTTL(newColl); - } - } - } - ); - } - - - @Override - public void onVisibilityChanged(VisibilityChangedEvent event) { - if (event.getIsVisible()) { - this.flys.hideHeaderProjectButton(); - } - else { - this.flys.shoHeaderProjectButton(); - } - } - - private void setFilter(String filter) { - this.filter = filter; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/PropertyEditor.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.io.Serializable; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface PropertyEditor extends Serializable { - - String getI18NString(String name); - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/QSegmentedInputPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,490 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.TitleOrientation; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.WQInfoService; -import de.intevation.flys.client.client.services.WQInfoServiceAsync; -import de.intevation.flys.client.client.ui.wq.QDTable; -import de.intevation.flys.client.client.ui.wq.WTable; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.WQDataItem; -import de.intevation.flys.client.shared.model.WQInfoObject; -import de.intevation.flys.client.shared.model.WQInfoRecord; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - - -/** - * This UIProvider creates a widget to enter Q values per segment. - */ -public class QSegmentedInputPanel -extends AbstractUIProvider -implements ChangeHandler, BlurHandler -{ - - private static final long serialVersionUID = -8627825064071479905L; - - public static final String FIELD_WQ_MODE = "wq_isq"; - public static final String FIELD_WQ_Q = "Q"; - - public static final String GAUGE_SEPARATOR = ":"; - - public static final String GAUGE_PART_SEPARATOR = ";"; - - public static final String VALUE_SEPARATOR = ","; - - public static final int ROW_HEIGHT = 20; - - /** The constant field name for choosing single values or range.*/ - public static final String FIELD_MODE = "mode"; - - /** The constant field value for range input mode.*/ - public static final String FIELD_MODE_RANGE = "range"; - - protected WQInfoServiceAsync wqInfoService = - GWT.create(WQInfoService.class); - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** Stores the input panels related to their keys.*/ - protected Map<String, DoubleArrayPanel> wqranges; - - /** Stores the min/max values for each q range.*/ - protected Map<String, double[]> qranges; - - protected QDTable qdTable; - - protected WTable wTable; - - protected TabSet tabs; - - - public QSegmentedInputPanel() { - wqranges = new HashMap<String, DoubleArrayPanel>(); - qranges = new HashMap<String, double[]>(); - qdTable = new QDTable(); - wTable = new WTable(); - } - - - /** Create main UI Canvas. */ - @Override - public Canvas create(DataList data) { - initHelperPanel(); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(data); - Label label = new Label(MSG.wqadaptedTitle()); - - label.setHeight(25); - - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - layout.setWidth(350); - - layout.addMember(label); - layout.addMember(widget); - layout.addMember(submit); - - return layout; - } - - - protected void initHelperPanel() { - tabs = new TabSet(); - tabs.setWidth100(); - tabs.setHeight100(); - - // TODO i18n - Tab qTab = new Tab("Q / D"); - - qTab.setPane(qdTable); - qdTable.hideIconFields(); - - tabs.addTab(qTab, 1); - - helperContainer.addMember(tabs); - - // TODO Q only would suffice. - fetchWQData(); - } - - - /** Create display for passive mode. */ - @Override - public Canvas createOld(DataList dataList) { - List<Data> all = dataList.getAll(); - Data wqData = getData(all, "ranges"); - - Canvas back = getBackButton(dataList.getState()); - - HLayout valLayout = new HLayout(); - VLayout vlayout = new VLayout(); - Label wqLabel = new Label(dataList.getLabel()); - - wqLabel.setValign(VerticalAlignment.TOP); - - wqLabel.setWidth(200); - wqLabel.setHeight(25); - - valLayout.addMember(wqLabel); - valLayout.addMember(createOldWQValues(wqData)); - valLayout.addMember(back); - - vlayout.addMember(valLayout); - - return vlayout; - } - - - /** Create canvas showing previously entered values. */ - protected Canvas createOldWQValues(Data wqData) { - VLayout layout = new VLayout(); - - //TODO: Sort by first field, numerically. - - DataItem item = wqData.getItems()[0]; - String value = item.getStringValue(); - - String[] gauges = value.split(GAUGE_SEPARATOR); - - for (String gauge: gauges) { - HLayout h = new HLayout(); - - String[] parts = gauge.split(GAUGE_PART_SEPARATOR); - String[] values = parts[3].split(VALUE_SEPARATOR); - - Label l = new Label(parts[0] + " - " + parts[1] + ": "); - - StringBuilder sb = new StringBuilder(); - boolean first = true; - - for (String v: values) { - if (!first) { - sb.append(", "); - } - - sb.append(v); - - first = false; - } - - Label v = new Label(sb.toString()); - - l.setWidth(65); - v.setWidth(65); - - h.addMember(l); - h.addMember(v); - - layout.addMember(h); - } - - return layout; - } - - - protected Canvas createWidget(DataList dataList) { - VLayout layout = new VLayout(); - - Canvas list = createList(dataList); - - DataItem[] items = getWQItems(dataList); - int listHeight = ROW_HEIGHT * items.length; - - layout.addMember(list); - - layout.setHeight(25 + listHeight); - layout.setWidth(350); - - return layout; - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - Iterator<String> iter = wqranges.keySet().iterator(); - - while (iter.hasNext()) { - List<String> tmpErrors = new ArrayList<String>(); - - String key = iter.next(); - DoubleArrayPanel dap = wqranges.get(key); - - if (!dap.validateForm()) { - errors.add(MSG.error_invalid_double_value()); - return errors; - } - - double[] mm = qranges.get(key); - if (mm == null) { - SC.warn(MSG.error_read_minmax_values()); - continue; - } - - double[] values = dap.getInputValues(); - // might geht npe here if one field not filled - double[] good = new double[values.length]; - - int idx = 0; - - for (double value: values) { - if (value < mm[0] || value > mm[1]) { - String tmp = MSG.error_validate_range(); - tmp = tmp.replace("$1", nf.format(value)); - tmp = tmp.replace("$2", nf.format(mm[0])); - tmp = tmp.replace("$3", nf.format(mm[1])); - tmpErrors.add(tmp); - } - else { - good[idx++] = value; - } - } - - double[] justGood = new double[idx]; - for (int i = 0; i < justGood.length; i++) { - justGood[i] = good[i]; - } - - if (!tmpErrors.isEmpty()) { - dap.setValues(justGood); - - errors.addAll(tmpErrors); - } - } - - return errors; - } - - - protected Canvas createList(DataList dataList) { - VLayout layout = new VLayout(); - - DataItem[] items = getWQItems(dataList); - - for (DataItem item: items) { - String title = item.getLabel(); - - DoubleArrayPanel dap = new DoubleArrayPanel( - createLineTitle(title), null, this, null, TitleOrientation.LEFT); - - wqranges.put(title, dap); - - if (item instanceof WQDataItem) { - WQDataItem wq = (WQDataItem) item; - double[] mmQ = wq.getQRange(); - - qranges.put(title, mmQ); - } - - layout.addMember(dap); - } - - layout.setHeight(items.length * ROW_HEIGHT); - - return layout; - } - - - protected DataItem[] getWQItems(DataList dataList) { - List<Data> data = dataList.getAll(); - - for (Data d: data) { - String name = d.getLabel(); - - // TODO to be gone - if (name.equals(FIELD_WQ_MODE)) { - continue; - } - - return d.getItems(); - } - - return null; - } - - - - public String createLineTitle(String key) { - String[] splitted = key.split(";"); - - return splitted[0] + " - " + splitted[1]; - } - - - @Override - public Data[] getData() { - Data values = getWQValues(); - - return new Data[] { values }; - } - - - protected Data getWQValues() { - String wqvalue = null; - - Iterator<String> iter = wqranges.keySet().iterator(); - while (iter.hasNext()) { - String key = iter.next(); - DoubleArrayPanel dap = wqranges.get(key); - - double[] values = dap.getInputValues(); - if (wqvalue == null) { - wqvalue = createValueString(key + "; ", values); - } - else { - wqvalue += GAUGE_SEPARATOR + createValueString(key + "; ", values); - } - } - - // TODO probably ranges - DataItem valueItem = new DefaultDataItem( - "ranges", "ranges", wqvalue); - Data values = new DefaultData( - "ranges", null, null, new DataItem[] { valueItem }); - - return values; - } - - - protected String createValueString(String key, double[] values) { - StringBuilder sb = new StringBuilder(); - - boolean first = true; - - for (double value: values) { - if (!first) { - sb.append(","); - } - - sb.append(Double.toString(value)); - - first = false; - } - - return key + ";" + sb.toString(); - } - - - @Override - public void onChange(ChangeEvent event) { - // TODO IMPLEMENT ME - } - - - @Override - public void onBlur(BlurEvent event) { - DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); - dap.validateForm(event.getItem()); - } - - - protected void fetchWQData() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - double[] mm = getMinMaxKM(data); - String river = getRiverName(data); - - wqInfoService.getWQInfo(locale, river, mm[0], mm[0], - new AsyncCallback<WQInfoObject[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve wq informations."); - SC.warn(caught.getMessage()); - } - - @Override - public void onSuccess(WQInfoObject[] wqi) { - int num = wqi != null ? wqi.length :0; - GWT.log("Recieved " + num + " wq informations."); - - if (num == 0) { - return; - } - - addWQInfo(wqi); - - } - } - ); - } - - - protected void addWQInfo (WQInfoObject[] wqi) { - for(WQInfoObject wi: wqi) { - WQInfoRecord rec = new WQInfoRecord(wi); - - if (wi.getType().equals("W")) { - wTable.addData(rec); - } - else { - qdTable.addData(rec); - } - } - } - - - /** - * Determines the min and max kilometer value selected in a former state. A - * bit silly, but we need to run over each value of the "old data" to find - * such values because it is not available here. - * - * @param data The DataList which contains the whole data inserted for the - * current artifact. - * - * @return a double array with [min, max]. - */ - protected double[] getMinMaxKM(DataList[] data) { - ArtifactDescription adesc = artifact.getArtifactDescription(); - return adesc.getKMRange(); - } - - - /** - * Returns the name of the selected river. - * - * @param data The DataList with all data. - * - * @return the name of the current river. - */ - protected String getRiverName(DataList[] data) { - ArtifactDescription adesc = artifact.getArtifactDescription(); - return adesc.getRiver(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RadioPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.RadioGroupItem; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.LinkedHashMap; - -public class RadioPanel extends AbstractUIProvider { - - private static final long serialVersionUID = 3357071563224461043L; - - protected String dataName; - protected DynamicForm form; - - @Override - public Canvas createOld(DataList dataList) { - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - HLayout layout = new HLayout(); - Label label = new Label(dataList.getLabel()); - Label value = new Label(items[0].getLabel()); - - layout.setHeight(35); - layout.setWidth(400); - label.setWidth(200); - - layout.addMember(label); - layout.addMember(value); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - @Override - public Canvas create(DataList dataList) { - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - this.dataName = data.getLabel(); - - VLayout layout = new VLayout(); - Label label = new Label(data.getDescription()); - RadioGroupItem rgi = new RadioGroupItem("selection"); - rgi.setShowTitle(false); - GWT.log("items: " + items.length); - LinkedHashMap<String, String> elems = new LinkedHashMap<String, String>(); - for (int i = 0; i < items.length; i++) { - GWT.log(items[i].getStringValue() + "; " + items[i].getLabel()); - elems.put(items[i].getStringValue(), items[i].getLabel()); - } - rgi.setValueMap(elems); - rgi.setDefaultValue(items[0].getStringValue()); - - form = new DynamicForm(); - form.setFields(rgi); - layout.setMembersMargin(10); - layout.setHeight(35); - label.setHeight(35); - - layout.addMember(label); - layout.addMember(form); - layout.addMember(getNextButton()); - layout.setMembersMargin(10); - - //initDefaultValues(dataList); - - return layout; - } - - @Override - protected Data[] getData() { - String value = form.getValueAsString("selection"); - DataItem item = new DefaultDataItem(this.dataName, this.dataName, value); - return new Data[] { new DefaultData( - this.dataName, null, null, new DataItem[]{item})}; - } - - protected String getTitle(DataItem item) { - return item.getLabel(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RangePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,282 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.validator.Validator; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.RangeData; - -import java.util.ArrayList; -import java.util.List; - - -/** - * An UIProvider for inserting ranges. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public abstract class RangePanel extends AbstractUIProvider { - - private static final long serialVersionUID = -9213089589150335651L; - - public static final String FIELD_LOWER = "field_lower"; - public static final String FIELD_UPPER = "field_upper"; - - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected DynamicForm lowerForm; - protected DynamicForm upperForm; - - protected String dataName; - - - public abstract Object getMaxLower(); - - public abstract Object getMaxUpper(); - - - - @Override - public Canvas create(DataList data) { - setDataName(data); - - VLayout root = new VLayout(); - - root.addMember(createLabel(data)); - root.addMember(createForm(data)); - root.addMember(getNextButton()); - - initDefaults(data); - - return root; - } - - - @Override - public Canvas createOld(DataList dataList) { - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - HLayout layout = new HLayout(); - - Label label = new Label(dataList.getLabel()); - label.setWidth(200); - label.setHeight(20); - - Label value = new Label(items[0].getLabel()); - value.setHeight(20); - - layout.addMember(label); - layout.addMember(value); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - - if (!lowerForm.validate()) { - String msg = MSG.error_validate_range(); - msg = msg.replace("$1", getLower()); - msg = msg.replace("$2", String.valueOf(getMaxLower())); - msg = msg.replace("$3", String.valueOf(getMaxLower())); - errors.add(msg); - } - - if (!upperForm.validate()) { - String msg = MSG.error_validate_range(); - msg = msg.replace("$1", getUpper()); - msg = msg.replace("$2", String.valueOf(getMaxLower())); - msg = msg.replace("$3", String.valueOf(getMaxUpper())); - errors.add(msg); - } - - return errors; - } - - - @Override - protected Data[] getData() { - return new Data[0]; - } - - - protected void initDefaults(DataList dataList) { - RangeData data = findRangeData(dataList); - - if (data != null) { - setLower(String.valueOf(data.getDefaultLower())); - setUpper(String.valueOf(data.getDefaultUpper())); - } - } - - - protected RangeData findRangeData(DataList dataList) { - for (int i = 0, n = dataList.size(); i < n; i++) { - Data tmp = dataList.get(i); - - if (tmp instanceof RangeData) { - return (RangeData) tmp; - } - } - return null; - } - - - protected void setDataName(DataList dataList) { - Data data = dataList.get(0); - - this.dataName = data.getLabel(); - } - - - public String getDataName() { - return dataName; - } - - - public String getLower() { - return lowerForm.getValueAsString(FIELD_LOWER); - } - - - public void setLower(String lower) { - lowerForm.setValue(FIELD_LOWER, lower); - } - - - public String getUpper() { - return upperForm.getValueAsString(FIELD_UPPER); - } - - - public void setUpper(String upper) { - upperForm.setValue(FIELD_UPPER, upper); - } - - - protected Canvas createLabel(DataList dataList) { - RangeData rangeData = findRangeData(dataList); - - if (rangeData == null) { - return new Canvas(); - } - - Label label = new Label(rangeData.getDescription()); - - label.setWidth100(); - label.setHeight(25); - - return label; - } - - - protected Canvas createForm(DataList dataList) { - lowerForm = createLowerForm(dataList); - upperForm = createUpperForm(dataList); - - HLayout formLayout = new HLayout(); - formLayout.addMember(lowerForm); - formLayout.addMember(createSpacer()); - formLayout.addMember(upperForm); - - return formLayout; - } - - - protected DynamicForm newForm() { - DynamicForm form = new DynamicForm(); - form.setTitlePrefix(""); - form.setTitleSuffix(""); - form.setTitle(""); - form.setTitleField(""); - - return form; - } - - - protected FormItem newFormItem(String name) { - TextItem item = new TextItem(name, ""); - item.setShowTitle(false); - - return item; - } - - - protected DynamicForm createLowerForm(DataList dataList) { - DynamicForm lowerForm = newForm(); - FormItem lower = createLowerField(dataList); - - lowerForm.setFields(lower); - - return lowerForm; - } - - - protected DynamicForm createUpperForm(DataList dataList) { - DynamicForm upperForm = newForm(); - FormItem upper = createUpperField(dataList); - - upperForm.setFields(upper); - - return upperForm; - } - - - protected Canvas createSpacer() { - Label spacer = new Label("-"); - spacer.setWidth(25); - spacer.setHeight(25); - spacer.setAlign(Alignment.CENTER); - - return spacer; - } - - - protected FormItem createLowerField(DataList dataList) { - return createField(FIELD_LOWER, createLowerValidators(dataList)); - } - - - protected FormItem createUpperField(DataList dataList) { - return createField(FIELD_UPPER, createUpperValidators(dataList)); - } - - - protected FormItem createField(String name, Validator[] validators) { - FormItem field = newFormItem(name); - - if (validators != null && validators.length > 0) { - field.setValidators(validators); - } - - return field; - } - - - protected Validator[] createLowerValidators(DataList dataList) { - return null; - } - - - protected Validator[] createUpperValidators(DataList dataList) { - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RangeTableFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent; -import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.FilterHandler; -import de.intevation.flys.client.client.event.RangeFilterEvent; -import de.intevation.flys.client.client.utils.DoubleValidator; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class RangeTableFilter -extends HLayout -implements ChangedHandler, KeyUpHandler -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected List<FilterHandler> handlers; - - protected TextItem fromField; - protected TextItem toField; - protected DynamicForm filterForm; - - public RangeTableFilter() { - super(); - fromField = new TextItem(); - fromField.setTitle(MESSAGES.from()); - fromField.setWidth(60); - toField = new TextItem(); - toField.setTitle(MESSAGES.to()); - toField.setWidth(60); - - - handlers = new ArrayList<FilterHandler>(); - - fromField.addChangedHandler(this); - fromField.addKeyUpHandler(this); - toField.addChangedHandler(this); - toField.addKeyUpHandler(this); - - filterForm = new DynamicForm(); - filterForm.setNumCols(4); - filterForm.setFields(fromField, toField); - - addMember(filterForm); - } - - - @Override - public void onChanged(ChangedEvent event) { - // This event handler is to slow... -// fireFilterCriteriaChanged(getSearchString()); - } - - - @Override - public void onKeyUp(KeyUpEvent event) { - DoubleValidator validator = new DoubleValidator(); - Map<?,?> errors = filterForm.getErrors(); - if(event.getItem().getValue() != null && - !validator.validate(event.getItem(), errors)) { - filterForm.setErrors(errors, true); - GWT.log("no valid input!"); - return; - } - else { - errors.clear(); - filterForm.setErrors(errors, true); - } - //To deactivate "As you type" filter add - // ' && event.getKeyName().equals("Enter")' - // to the if-clause. - if (event != null) { - fireFilterCriteriaChanged(getFrom(), getTo()); - } - } - - - public String getFrom() { - if (fromField.getValueAsString() == null) { - return ""; - } - else { - return fromField.getValueAsString(); - } - } - - - public String getTo() { - if (toField.getValueAsString() == null) { - return ""; - } - else { - return toField.getValueAsString(); - } - } - - - public void addFilterHandler(FilterHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - protected void fireFilterCriteriaChanged(String from, String to) { - RangeFilterEvent filter = new RangeFilterEvent(from, to); - - for (FilterHandler handler: handlers) { - handler.onFilterCriteriaChanged(filter); - } - } - - - @Override - public void clear() { - fromField.clearValue(); - toField.clearValue(); - fireFilterCriteriaChanged("", ""); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import de.intevation.flys.client.shared.model.Recommendation; - - -/** - * Two strings to be displayed in a GridList, derived from two - * Recommendations. - */ -public class RecommendationPairRecord extends ListGridRecord { - - /** First attribute-name for StringPairRecord. */ - protected static final String ATTRIBUTE_FIRST = "first"; - - /** Second attribute-name for StringPairRecord. */ - protected static final String ATTRIBUTE_SECOND = "second"; - - /** The "first" recommendation (typically the minuend). */ - Recommendation first; - - /** The "second" recommendation (typically the subtrahend). */ - Recommendation second; - - /** - * Whether the RecommendationPairRecord was restored from data and thus - * already loaded (usually cloned) in an ArtifactCollection or not. - */ - boolean alreadyLoaded; - - - /** Trivial, blocked constructor. */ - @SuppressWarnings("unused") - private RecommendationPairRecord() { - } - - - /** - * Create a new RecommendationPairRecord. - * - * @param first The first recommendation (typically the minuend). - * @param second The second recommendation (typically the subtrahend). - */ - public RecommendationPairRecord( - Recommendation first, - Recommendation second) - { - setFirst(first); - setSecond(second); - alreadyLoaded = false; - } - - - /** - * Sets the first recommendation with info (minuend). - * @param first Recommendation to store. - */ - public void setFirst(Recommendation first) { - this.first = first; - setAttribute(ATTRIBUTE_FIRST, first.getDisplayName()); - } - - - /** - * Sets the second recommendation with info (subtrahend). - * @param second Recommendation to store. - */ - public void setSecond(Recommendation second) { - this.second = second; - setAttribute(ATTRIBUTE_SECOND, second.getDisplayName()); - } - - - /** - * Get first recommendation (typically the minuend). - * @return first recommendation (typically the minuend). - */ - public Recommendation getFirst() { - return first; - } - - - /** - * Get second recommendation (typically the subtrahend). - * @return second recommendation (typically the subtrahend). - */ - public Recommendation getSecond() { - return second; - } - - - /** - * Get name of first recommendation (typically the minuend). - * @return name of first recommendation (typically the minuend). - */ - public String getFirstName() { - return first.getDisplayName(); - } - - - /** - * Get name of second recommendation (typically the subtrahend). - * @return name of second recommendation (typically the subtrahend). - */ - public String getSecondName() { - return second.getDisplayName(); - } - - - /** - * Sets whether or not the Recommendation is already loaded (in contrast - * to not yet loaded). - * @param isAlreadyLoaded new value. - */ - public void setIsAlreadyLoaded(boolean isAlreadyLoaded) { - this.alreadyLoaded = isAlreadyLoaded; - } - - - /** - * Whether or not this pair of recommendations is already laoded (usually - * cloned) in an ArtifactCollection. - * @return whether pair of recommendations is already loaded. - */ - public boolean isAlreadyLoaded() { - return this.alreadyLoaded; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RiverInfoPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.Iterator; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.user.client.ui.Anchor; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.Widget; - -import de.intevation.flys.client.client.FLYSConstants; - -import de.intevation.flys.client.shared.model.RiverInfo; - -/** - * Panel to display information about a river. - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class RiverInfoPanel extends HorizontalPanel { - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public final static int HEIGHT = 30; - public final static int BORDER_WIDTH = 3; - public final static int PADDING = 8; - public final static int MARGIN = 10; - - public RiverInfoPanel(RiverInfo riverinfo) { - setStyleName("riverinfopanel"); - setHeight("" + HEIGHT + "px"); - setVerticalAlignment(ALIGN_MIDDLE); - - setRiverInfo(riverinfo); - } - - public void setRiverInfo(RiverInfo riverinfo) { - GWT.log("RiverInfoPanel - setRiverInfo"); - - NumberFormat nf = NumberFormat.getDecimalFormat(); - - removeAllLabels(); - - addLabel(riverinfo.getName(), false); - - String kmtext = ""; - Double start = riverinfo.getKmStart(); - Double end = riverinfo.getKmEnd(); - - if (!riverinfo.isKmUp()) { - Double tmp = end; - end = start; - start = tmp; - } - if (end != null) { - kmtext += nf.format(end); - kmtext += " - "; - } - if (start != null) { - kmtext += nf.format(start); - } - kmtext += " km"; - - addLabel(kmtext, false); - - String qtext = ""; - Double qmin = riverinfo.getMinQ(); - Double qmax = riverinfo.getMaxQ(); - if (qmin != null) { - qtext += nf.format(qmin); - qtext += " " + MSG.gauge_q_unit(); - qtext += " - "; - } - if (qmax != null) { - qtext += nf.format(qmax); - qtext += " " + MSG.gauge_q_unit(); - } - - addLabel(qtext, false); - - Long number = riverinfo.getOfficialNumber(); - String url = number != null ? - MSG.gauge_river_url() + number : - MSG.gauge_river_url(); - Anchor anchor = new Anchor(MSG.gauge_river_info_link(), url, "_blank"); - add(anchor); - } - - public static int getStaticHeight() { - return RiverInfoPanel.HEIGHT + - (2 * RiverInfoPanel.BORDER_WIDTH) + - (2 * RiverInfoPanel.PADDING) + - (2 * RiverInfoPanel.MARGIN); - } - - private void addLabel(String text, boolean wordwrap) { - Label label = new Label(text, wordwrap); - add(label); - setCellHeight(label, "" + HEIGHT + "px"); - } - - private void removeAllLabels() { - GWT.log("RiverInfoPanel - removeAllLabels"); - - Iterator<Widget> it = this.iterator(); - while(it.hasNext()) { - it.next(); - it.remove(); - } - /* for (Widget wid: this) { */ - /* this.remove(wid); */ - /* } */ - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ScreenLock.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.Layout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; - -/** Basic static functionality to show spinning wheel. */ -public class ScreenLock { - - /** The message class that provides i18n strings. */ - protected static FLYSConstants messages = GWT.create(FLYSConstants.class); - - /** Disables input, grey out, show spinning wheel of joy. */ - public static VLayout lockUI(Layout layout, VLayout lockScreen) { - if (lockScreen == null) { - lockScreen = new VLayout(); - lockScreen.setWidth100(); - lockScreen.setHeight100(); - lockScreen.setBackgroundColor("#7f7f7f"); - lockScreen.setOpacity(50); - lockScreen.setAlign(VerticalAlignment.CENTER); - lockScreen.setDefaultLayoutAlign(VerticalAlignment.CENTER); - - HLayout inner = new HLayout(); - inner.setAlign(Alignment.CENTER); - inner.setDefaultLayoutAlign(Alignment.CENTER); - inner.setOpacity(100); - - Img img = new Img( - GWT.getHostPageBaseURL() + messages.loadingImg(), - 25, 25); - - inner.addMember(img); - - lockScreen.addMember(inner); - } - - layout.addChild(lockScreen); - return lockScreen; - } - - /** Enable input, remove grey, remove spinning wheel of joy. */ - public static void unlockUI(Layout layout, VLayout lockScreen) { - layout.removeChild(lockScreen); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,273 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.LinkItem; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.SpacerItem; -import com.smartgwt.client.widgets.form.fields.events.ClickEvent; -import com.smartgwt.client.widgets.form.fields.events.ClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.StepForwardEvent; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - - -/** - * This UIProvider displays the DataItems of the Data object in a combo box. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class SelectProvider -extends AbstractUIProvider -{ - private static final long serialVersionUID = 4696637534424070726L; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants messages = GWT.create(FLYSConstants.class); - - /** The combobox.*/ - protected DynamicForm form = new DynamicForm(); - - public static final int COMBOBOX_THRESHOLD = 20; - - - /** - * This method currently returns a - * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all - * data items in a combobox stored in <i>data</i>. - * - * @param data The {@link Data} object. - * - * @return a combobox. - */ - @Override - public Canvas create(DataList data) { - VLayout v = new VLayout(); - v.setMembersMargin(10); - v.addMember(createWidget(data)); - if(data.size() > COMBOBOX_THRESHOLD) { - v.addMember(getNextButton()); - } - return v; - } - - - protected Canvas createWidget(DataList data) { - if (data.size() > COMBOBOX_THRESHOLD) { - return createComboboxWidget(data); - } - else { - return createListWidget(data); - } - } - - - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - VLayout vLayout = new VLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - int size = dataList.size(); - for (int i = 0; i < size; i++) { - Data data = dataList.get(i); - DataItem[] items = data.getItems(); - - for (DataItem item: items) { - HLayout hLayout = new HLayout(); - - hLayout.addMember(label); - hLayout.addMember(new Label(item.getLabel())); - - vLayout.addMember(hLayout); - vLayout.setWidth("130px"); - } - } - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - - protected Canvas createListWidget(DataList data) { - VLayout layout = new VLayout(); - layout.setAlign(VerticalAlignment.TOP); - layout.setHeight(25); - layout.setWidth("100%"); - - VLayout formLayout = new VLayout(); - formLayout.setLayoutTopMargin(20); - formLayout.setLayoutLeftMargin(50); - - ClickHandler handler = new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - LinkItem li = (LinkItem)event.getItem(); - String attr = li.getAttribute(li.getName()); - GWT.log("li.getTarget: " + attr + " " + li.getName()); - DataItem item = new DefaultDataItem( - attr, - null, - attr); - - Data d = new DefaultData( - li.getName(), - null, - null, - new DataItem [] { item }); - - Data [] odata = getData(); - Data [] ndata = new Data[odata.length+1]; - System.arraycopy(odata, 0, ndata, 0, odata.length); - ndata[odata.length] = d; - - fireStepForwardEvent(new StepForwardEvent(ndata)); - } - }; - - for (int i = 0, size = data.size(); i < size; i++) { - Data d = data.get(i); - - Label label = new Label(d.getDescription()); - label.setValign(VerticalAlignment.TOP); - label.setHeight(20); - label.setWidth(400); - - LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); - ArrayList<FormItem> formItems = new ArrayList<FormItem>(); - - for (DataItem item: d.getItems()) { - initial.put(item.getLabel().replace(' ', '_'), item.getStringValue()); - GWT.log("put: " + item.getLabel().replace(' ', '_') + "=" + item.getStringValue()); - - LinkItem link = new LinkItem(d.getLabel()); - link.setLinkTitle(item.getLabel()); // i18n text of the link - link.setAttribute(d.getLabel(), item.getStringValue()); // e.g. "calculation_mode":"foo" - link.setShowTitle(false); - link.setEndRow(true); - link.setWidth("350px"); - - SpacerItem space = new SpacerItem(); - space.setWidth(15); - formItems.add(space); - formItems.add(link); - - link.addClickHandler(handler); - } - - form.setFields(formItems.toArray(new FormItem[0])); - form.setValues(initial); - - layout.addMember(label); - layout.addMember(form); - } - return layout; - } - - protected Canvas createComboboxWidget(DataList data) { - GWT.log("SelectProvider.createComboboxWidget()"); - - VLayout layout = new VLayout(); - layout.setAlign(VerticalAlignment.TOP); - layout.setHeight(25); - - LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); - - int size = data.size(); - - for (int i = 0; i < size; i++) { - Data d = data.get(i); - - Label label = new Label(d.getDescription()); - label.setValign(VerticalAlignment.TOP); - label.setHeight(20); - label.setWidth(400); - - SelectItem combobox = new SelectItem(d.getLabel()); - combobox.setWidth(250); - - LinkedHashMap<String, String> it = new LinkedHashMap<String, String>(); - - boolean defaultSet = false; - boolean first = true; - - DataItem def = d.getDefault(); - String defValue = def != null ? def.getStringValue() : null; - - if (defValue != null && defValue.length() > 0) { - initial.put(d.getLabel(), def.getStringValue()); - defaultSet = true; - } - - for (DataItem item: d.getItems()) { - if (!defaultSet && first) { - initial.put(d.getLabel(), item.getStringValue()); - first = false; - } - - it.put(item.getStringValue(), item.getLabel()); - } - - label.setWidth(50); - combobox.setValueMap(it); - combobox.setShowTitle(false); - form.setItems(combobox); - - layout.addMember(label); - layout.addMember(form); - } - - form.setValues(initial); - - layout.setAlign(VerticalAlignment.TOP); - - return layout; - } - - - @Override - protected Data[] getData() { - Map<?,?> values = form.getValues(); - Iterator<?> keys = values.keySet().iterator(); - - Data[] list = new Data[values.size()]; - int i = 0; - - while (keys.hasNext()) { - String fieldname = ((String) keys.next()).replace('_', ' '); - String selection = (String) values.get(fieldname); - - DataItem item = new DefaultDataItem(fieldname, null, selection); - - list[i++] = new DefaultData( - fieldname, null, null, new DataItem[] { item }); - } - - return list; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.data.Record; - -import com.smartgwt.client.widgets.grid.events.CellClickEvent; - -import de.intevation.flys.client.shared.model.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * This UIProvider creates a widget to enter a single location (km). - */ -public class SingleLocationPanel -extends MultipleLocationPanel -{ - private static final long serialVersionUID = -300641333561787454L; - - - /** - * Creates a new SingleLocationPanel instance. - */ - public SingleLocationPanel() { - picker = new LocationPicker(this); - } - - - /** Overridden to restrict to one entered value. */ - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - saveLocationValues(locationPanel); - - if (!locationPanel.validateForm()) { - errors.add(MSG.wrongFormat()); - return errors; - } - - double[] values = getLocationValues(); - double[] good = new double[values.length]; - int idx = 0; - - // We want just one value to be allowed. - if (values.length > 1) { - errors.add(MSG.too_many_values()); - } - - for (double value: values) { - if (value < min || value > max) { - String tmp = MSG.error_validate_range(); - tmp = tmp.replace("$1", nf.format(value)); - tmp = tmp.replace("$2", nf.format(min)); - tmp = tmp.replace("$3", nf.format(max)); - errors.add(tmp); - } - else { - good[idx++] = value; - } - } - - double[] justGood = new double[idx]; - for (int i = 0; i < justGood.length; i++) { - justGood[i] = good[i]; - } - - if (!errors.isEmpty()) { - locationPanel.setValues(justGood); - } - - return errors; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - saveLocationValues(locationPanel); - double[] values = getLocationValues(); - Data[] data = new Data[values.length+1]; - - for (int i = 0; i < values.length; i++) { - data[i] = createDataArray(getDataItemName(), - Double.valueOf(values[i]).toString()); - } - - data[values.length] = createDataArray("ld_mode", "locations"); - - return data; - } - - - /* This is a copy of super.super.onRecordClick. Straighten out - this weird family. */ - /** - * Callback when an item from the input helper was clicked. - * Set the respective km-value in the location value field. - * @param e event passed. - */ - @Override - public void onCellClick (CellClickEvent e) { - Record record = e.getRecord(); - double[] selected = new double[1]; - try { - selected[0] = - Double.parseDouble(record.getAttribute("from")); - } - catch(NumberFormatException nfe) { - // Is there anything else to do here? - } - setLocationValues(selected); - } - - - @Override - protected String getLabelString() { - return MSG.single_location(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/StaticDataPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; - - -/** - * This UIProvider displays the old DataItems of GaugeDischargeCurveArtifact - * - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class StaticDataPanel -extends AbstractUIProvider -{ - private static final long serialVersionUID = 7411866539525588336L; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants messages = GWT.create(FLYSConstants.class); - - /** The combobox.*/ - protected DynamicForm form; - - @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); - return layout; - } - - @Override - public Canvas createOld(DataList dataList) { - VLayout vLayout = new VLayout(); - vLayout.setWidth("400px"); - - int size = dataList.size(); - for (int i = 0; i < size; i++) { - Data data = dataList.get(i); - DataItem[] items = data.getItems(); - - for (DataItem item: items) { - HLayout hLayout = new HLayout(); - - hLayout.addMember(new Label(item.getLabel())); - hLayout.addMember(new Label(item.getStringValue())); - - vLayout.addMember(hLayout); - vLayout.setWidth("130px"); - } - } - - return vLayout; - } - - @Override - protected Data[] getData() { - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,700 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.events.ItemChangedEvent; -import com.smartgwt.client.widgets.form.events.ItemChangedHandler; -import com.smartgwt.client.widgets.form.fields.CheckboxItem; -import com.smartgwt.client.widgets.form.fields.ColorPickerItem; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.form.validator.IsFloatValidator; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.CollectionItemAttributeService; -import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; -import de.intevation.flys.client.client.services.ThemeListingService; -import de.intevation.flys.client.client.services.ThemeListingServiceAsync; -import de.intevation.flys.client.client.utils.DoubleValidator; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItemAttribute; -import de.intevation.flys.client.shared.model.FacetRecord; -import de.intevation.flys.client.shared.model.Style; -import de.intevation.flys.client.shared.model.StyleSetting; -import de.intevation.flys.client.shared.model.Theme; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; - -/** - * Editor window for styles. - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class StyleEditorWindow -extends Window -implements ClickHandler -{ - /** The interface that provides i18n messages. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** The collection. */ - protected Collection collection; - - /** The parent ThemePanel. */ - protected ThemePanel panel; - - /** The attributes. */ - protected CollectionItemAttribute attributes; - - /** The selected facet. */ - protected FacetRecord facet; - - /** Main layout. */ - protected VLayout layout; - - /** The form that contains all the input widgets. */ - protected DynamicForm df; - - protected VLayout properties; - - protected Canvas container; - - protected Map<String, Style> styleGroups; - - protected Style current; - - protected SelectItem styleChooser; - - /** The service used to set collection item attributes. */ - protected CollectionItemAttributeServiceAsync itemAttributeService = - GWT.create(CollectionItemAttributeService.class); - - /** The service used to request a list of themes. */ - protected ThemeListingServiceAsync themeListingService = - GWT.create(ThemeListingService.class); - - - /** - * Setup editor dialog. - * @param collection The collection the current theme belongs to. - * @param attributes The collection attributes. - * @param facet The selected facet. - */ - public StyleEditorWindow ( - Collection collection, - CollectionItemAttribute attributes, - FacetRecord facet) - { - this.collection = collection; - this.attributes = attributes; - this.facet = facet; - this.layout = new VLayout(); - this.properties = new VLayout(); - this.container = new Canvas(); - this.styleChooser = new SelectItem("style", "Style"); - - styleChooser.setTitleStyle("color:#000;"); - styleChooser.setTitleAlign(Alignment.LEFT); - styleChooser.setValue("aktuell"); - styleChooser.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent ce) { - String value = ce.getValue().toString(); - Style s = null; - if (value.equals("aktuell")) { - s = current; - } - else if (styleGroups.containsKey(value)) { - s = styleGroups.get(value); - } - - if (s != null) { - setNewStyle(s); - properties.removeMember(container); - container = createPropertyGrid(s); - properties.addMember(container); - } - } - }); - - DynamicForm f = new DynamicForm(); - f.setFields(styleChooser); - f.setColWidths("40%", "60%"); - - layout.addMember(f); - init(); - initPanels(); - } - - - /** - * Initialize the window and set the layout. - */ - protected void init() { - setTitle(MSG.properties()); - setCanDragReposition(true); - setCanDragResize(true); - layout.setMargin(10); - - layout.setWidth100(); - layout.setHeight100(); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - Theme theme = facet.getTheme(); - Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); - if(style == null) { - GWT.log("StyleEditorWindow.init(): style == null"); - return; - } - String name = style.getName(); - this.current = style; - - themeListingService.list( - locale, - name, - new AsyncCallback<Map<String, Style> >() { - @Override - public void onFailure(Throwable caught) { - GWT.log("No listloaded."); - } - @Override - public void onSuccess(Map<String, Style> list) { - GWT.log("Successfully loaded list."); - - styleGroups = list; - Set<String> keys = list.keySet(); - LinkedHashMap<String, String> valueMap = - new LinkedHashMap<String, String>(); - valueMap.put("aktuell", "Aktuell"); - Iterator<String> iter = keys.iterator(); - while (iter.hasNext()) { - String s = iter.next().toString(); - Style tmp = styleGroups.get(s); - tmp.setFacet(current.getFacet()); - tmp.setIndex(current.getIndex()); - valueMap.put(s, s); - } - styleChooser.setValueMap(valueMap); - } - }); - } - - - /** - * Initialize the static window content like buttons and main layout. - */ - protected void initPanels() { - HLayout buttons = new HLayout(); - Button accept = new Button(MSG.label_ok()); - Button cancel = new Button(MSG.label_cancel()); - cancel.addClickHandler(this); - accept.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - // TODO Fix this, for whatever reason it doesnt work - // (always valid). - if (df == null) { - return; - } - if (!df.hasErrors() && df.validate()) { - saveStyle(); - } - } - }); - - buttons.addMember(accept); - buttons.addMember(cancel); - buttons.setAlign(Alignment.CENTER); - buttons.setHeight(30); - - Theme theme = facet.getTheme(); - Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); - - container = createPropertyGrid(style); - properties.addMember(container); - layout.addMember(properties); - layout.addMember(buttons); - addItem(layout); - setWidth(400); - setHeight(410); - } - - - /** - * Setter for the parent panel. - * @param panel The panel. - */ - public void setThemePanel (ThemePanel panel) { - this.panel = panel; - } - - - /** - * this method is called when the user aborts theming. - * @param event The event. - */ - @Override - public void onClick(ClickEvent event) { - this.hide(); - } - - - /** - * This method creates the property grid for available styling attributes. - * @return The layout containing the UI elements. - */ - protected VLayout createPropertyGrid(Style style) { - VLayout vl = new VLayout(); - - StaticTextItem name = new StaticTextItem("name", "Name"); - name.setValue(facet.getName()); - name.setTitleStyle("color:#000;"); - name.setTitleAlign(Alignment.LEFT); - name.setDisabled(true); - name.setShowDisabled(false); - - DynamicForm form = new DynamicForm(); - form.setFields(name); - form.setColWidths("40%", "60%"); - - - vl.addMember(form); - - if (style == null) { - SC.warn("No style found."); - return vl; - } - - // Done via array to keep the order. - String[] sets = {"showlines", - "showpoints", - "linetype", - "linesize", - "linecolor", - "font", - "textstyle", - "textsize", - "pointcolor", - "pointsize", - "showpointlabel", - "textcolor", - "backgroundcolor", - "showbackground", - "showlinelabel", - "labelfontface", - "labelfontcolor", - "labelfontsize", - "labelfontstyle", - "textorientation", - "labelshowbg", - "labelbgcolor", - "bandwidth", - "bandwidthcolor", - "transparency", - "showminimum", - "showmaximum"}; - - for (String settingName: sets) { - StyleSetting set = style.getSetting(settingName); - - if (set == null || set.isHidden()) { - continue; - } - - DynamicForm property = createPropertyUI( - set.getDisplayName(), - set.getName(), - set.getType(), - set.getDefaultValue()); - if (property != null) { - vl.addMember(property); - } - } - - // Add settings not in whitelist above. - for (StyleSetting set: style.getSettings()) { - - if (Arrays.asList(sets).contains(set.getName()) || - set == null || - set.isHidden() - ) { - continue; - } - - DynamicForm property = createPropertyUI( - set.getDisplayName(), - set.getName(), - set.getType(), - set.getDefaultValue()); - if (property != null) { - vl.addMember(property); - } - } - - return vl; - } - - - /** - * Create a property form. - * @param dname The display name. - * @param name The property name. - * @param type The property type. - * @param value The current value. - * - * @return The dynamic form for the attribute property. - */ - protected DynamicForm createPropertyUI( - String dname, - String name, - String type, - String value) - { - df = new DynamicForm(); - df.setColWidths("40%", "60%"); - - FormItem f; - if(type.equals("int")) { - f = new SelectItem(name, MSG.getString(name)); - if (name.equals("linesize")) { - f = createLineSizeUI(f); - f.setValue(value); - } - else if (name.equals("labelfontsize")) { - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("3", "3"); - valueMap.put("5", "5"); - valueMap.put("8", "8"); - valueMap.put("10", "10"); - valueMap.put("12", "12"); - valueMap.put("14", "14"); - valueMap.put("18", "18"); - valueMap.put("24", "24"); - f.setValueMap(valueMap); - f.setValue(value); - } - else if (name.equals("bandwidth")) { - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("0", "0"); - valueMap.put("1", "1"); - valueMap.put("2", "2"); - valueMap.put("3", "3"); - valueMap.put("4", "4"); - valueMap.put("5", "5"); - valueMap.put("6", "6"); - valueMap.put("7", "7"); - valueMap.put("8", "8"); - valueMap.put("9", "9"); - valueMap.put("10", "10"); - valueMap.put("11", "11"); - f.setValueMap(valueMap); - f.setValue(value); - } - else if (name.equals("pointsize")) { - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("1", "1"); - valueMap.put("2", "2"); - valueMap.put("3", "3"); - valueMap.put("4", "4"); - valueMap.put("5", "5"); - valueMap.put("6", "6"); - valueMap.put("7", "7"); - f.setValueMap(valueMap); - f.setValue(value); - } - else if (name.equals("numclasses")) { - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("5", "5"); - valueMap.put("6", "6"); - valueMap.put("7", "7"); - valueMap.put("8", "8"); - valueMap.put("9", "9"); - valueMap.put("10", "10"); - valueMap.put("12", "12"); - valueMap.put("14", "14"); - valueMap.put("16", "16"); - valueMap.put("18", "18"); - valueMap.put("20", "20"); - f.setValueMap(valueMap); - f.setValue(value); - // FIXME: Make that work again - return null; - } - else if (name.contains("transparency")) { - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - for (int n = 10; n < 100; n += 10) { - valueMap.put(Integer.toString(n), n + "%"); - } - f.setValueMap(valueMap); - f.setValue(value); - } - } - else if (type.equals("boolean")) { - if(name.equals("textorientation")) { - f = new SelectItem(name, MSG.getString(name)); - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("true", MSG.getString("horizontal")); - valueMap.put("false", MSG.getString("vertical")); - f.setValueMap(valueMap); - f.setValue(value); - } - else { - CheckboxItem c = new CheckboxItem(name, MSG.getString(name)); - if(value.equals("true")) { - c.setValue(true); - } - else { - c.setValue(false); - } - c.setLabelAsTitle(true); - f = c; - } - } - else if (type.equals("Color")) { - ColorPickerItem c = new ColorPickerItem(name, MSG.getString(name)); - c.setValue(rgbToHtml(value)); - f = c; - } - else if (type.equals("double")) { - f = new FormItem(name); - IsFloatValidator fpv = new IsFloatValidator(); - - f.setValidators(fpv); - f.setValidateOnChange(true); - f.setTitle(MSG.getString(name)); - f.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - DoubleValidator validator = new DoubleValidator(); - Map<?, ?> errors = e.getForm().getErrors(); - if(validator.validate(e.getItem(), errors)) { - e.getForm().setErrors(errors, true); - } - else { - e.getForm().setErrors(errors, true); - } - } - }); - f.setValue(value); - } - else if (type.equals("Dash")) { - f = new SelectItem(name, MSG.getString(name)); - LinkedHashMap<String, String> valueIcons = new LinkedHashMap<String, String>(); - f.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/linestyle-dash-"); - f.setImageURLSuffix(".png"); - f.setValueIconHeight(20); - f.setValueIconWidth(80); - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("10", ""); - valueMap.put("10,5", ""); - valueMap.put("20,10", ""); - valueMap.put("30,10", ""); - valueMap.put("20,5,15,5", ""); - valueIcons.put("10", "10"); - valueIcons.put("10,5", "10-5"); - valueIcons.put("20,10", "20-10"); - valueIcons.put("30,10", "30-10"); - valueIcons.put("20,5,15,5", "20-5-15-5"); - f.setValueIcons(valueIcons); - f.setValueMap(valueMap); - f.setValue(value); - } - else if (type.equals("Font")) { - f = new SelectItem(name, MSG.getString(name)); - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("arial", "<span style='font-family:arial'>Arial</span>"); - valueMap.put("courier", "<span style='font-family:courier'>Courier</span>"); - valueMap.put("verdana", "<span style='font-family:verdana'>Verdana</span>"); - valueMap.put("times", "<span style='font-family:times'>Times</span>"); - f.setValueMap(valueMap); - f.setValue(value); - } - else if (type.equals("Style")) { - f = new SelectItem(name, MSG.getString(name)); - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("standard", "<span style='font-style:normal'>Normal</span>"); - valueMap.put("bold", "<span style='font-weight:bold'>Bold</span>"); - valueMap.put("italic", "<span style='font-style:italic'>Italic</span>"); - f.setValueMap(valueMap); - f.setValue(value); - } - else if (type.equals("Symbol")) { - //create an empty element as long as this property can not be - //changed. - f = new StaticTextItem(""); - } - else { - f = new FormItem(); - } - f.setTitleStyle("color:#000;"); - f.setTitleAlign(Alignment.LEFT); - df.setFields(f); - df.addItemChangedHandler(new ItemChangedHandler() { - @Override - public void onItemChanged(ItemChangedEvent e) { - String name = e.getItem().getName(); - String newValue = e.getNewValue().toString(); - setNewValue(name, newValue); - } - }); - - return df; - } - - - protected FormItem createLineSizeUI(FormItem f) { - LinkedHashMap<String, String> valueIcons = new LinkedHashMap<String, String>(); - f.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/linestyle-"); - f.setImageURLSuffix("px.png"); - f.setValueIconHeight(20); - f.setValueIconWidth(80); - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - valueMap.put("1", ""); - valueMap.put("2", ""); - valueMap.put("3", ""); - valueMap.put("4", ""); - valueMap.put("5", ""); - valueMap.put("6", ""); - valueMap.put("7", ""); - valueMap.put("8", ""); - valueIcons.put("1", "1"); - valueIcons.put("2", "2"); - valueIcons.put("3", "3"); - valueIcons.put("4", "4"); - valueIcons.put("5", "5"); - valueIcons.put("6", "6"); - valueIcons.put("7", "7"); - valueIcons.put("8", "8"); - f.setValueIcons(valueIcons); - f.setValueMap(valueMap); - return f; - } - - - /** - * Static method to convert a color from RGB to HTML notation. - * @param rgb String in RGB notation. - * - * @return String in HTML notation. - */ - protected static String rgbToHtml(String rgb) { - String[] parts = rgb.split(","); - int values[] = new int[parts.length]; - for (int i = 0; i < parts.length; i++) { - parts[i] = parts[i].trim(); - try { - values[i] = Integer.parseInt(parts[i]); - } - catch(NumberFormatException nfe) { - return "#000000"; - } - } - String hex = "#"; - for (int i = 0; i < values.length; i++) { - if (values[i] < 16) { - hex += "0"; - } - hex += Integer.toHexString(values[i]); - } - return hex; - } - - - /** - * Static method to convert a color from HTML to RGB notation. - * @param html String in HTML notation. - * - * @return String in RGB notation. - */ - protected static String htmlToRgb(String html) { - if (!html.startsWith("#")) { - return "0, 0, 0"; - } - - int r = Integer.valueOf(html.substring(1, 3), 16); - int g = Integer.valueOf(html.substring(3, 5), 16); - int b = Integer.valueOf(html.substring(5, 7), 16); - - return r + ", " + g + ", " + b; - } - - - /** - * Saves the current style attributes and requests a redraw. - */ - protected void saveStyle () { - GWT.log("StyleEditorWindow.saveStyle()"); - Config config = Config.getInstance(); - String locale = config.getLocale(); - - itemAttributeService.setCollectionItemAttribute( - this.collection, - attributes.getArtifact(), - locale, - attributes, - new AsyncCallback<Void>() { - @Override - public void onFailure (Throwable caught) { - GWT.log("Could not set Collection item attributes."); - } - @Override - public void onSuccess(Void v) { - GWT.log("Successfully saved collection item attributes."); - panel.requestRedraw(); - } - }); - - - this.hide(); - } - - - /** - * Sets a new value for an attribute. - * @param name Attribute name. - * @param value The new value. - */ - protected final void setNewValue(String name, String value) { - Theme t = facet.getTheme(); - Style s = attributes.getStyle(t.getFacet(), t.getIndex()); - StyleSetting set = s.getSetting(name); - String type = set.getType(); - - if(name.indexOf("color") != -1 - || (type != null && type.toLowerCase().indexOf("color") > -1)) { - value = htmlToRgb(value); - } - set.setDefaultValue(value); - } - - - protected final void setNewStyle(Style style) { - Theme t = facet.getTheme(); - Style s = attributes.getStyle(t.getFacet(), t.getIndex()); - attributes.removeStyle(s.getName()); - attributes.appendStyle(style); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -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.Canvas; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.CSVExportService; -import de.intevation.flys.client.client.services.CSVExportServiceAsync; -import de.intevation.flys.client.shared.model.DataList; - -import java.util.List; - -/** - * This UIProvider creates a widget that displays calculated data in a table. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class TableDataPanel -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected CSVExportServiceAsync exportService = - GWT.create(CSVExportService.class); - - /** A container that will contain the location or the distance panel. */ - protected VLayout container; - - /** The export type. */ - protected String name; - - /** The UUID of the collection. */ - protected String uuid; - - /** The table. */ - protected ListGrid dataTable; - - - /** - * Creates a new LocationDistancePanel instance. - */ - public TableDataPanel() { - container = new VLayout(); - dataTable = new ListGrid(); - name = ""; - } - - - /** - * This method creates a widget that contains a table. - * - * @return a panel. - */ - public Canvas create() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - dataTable.setEmptyMessage(MESSAGES.empty_table()); - dataTable.setShowHeaderContextMenu(false); - dataTable.setCanDragSelectText(true); - - exportService.getCSV(locale, uuid, name, - new AsyncCallback<List<String[]>>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve csv."); - SC.warn(caught.getMessage()); - } - - @Override - public void onSuccess(List<String[]> l) { - GWT.log("Recieved csv with " + l.size() + " lines."); - setData(l); - } - } - ); - - container.addMember(dataTable); - - return container; - } - - - public void setName(String name) { - this.name = name; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - - public Canvas createOld(DataList dataList) { - return null; - } - - - protected Canvas createWidget(DataList data) { - return null; - } - - - /** - * This method sets the data to a dynamic table. - * - * @param list List if String[] containing the data. - */ - public void setData(List<String[]> list) { - if (list == null || list.size() < 2) { - dataTable.setEmptyMessage(MESSAGES.error_no_calc_result()); - dataTable.redraw(); - return; - } - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - NumberFormat nf; - if (locale.equals("de")) { - nf = NumberFormat.getFormat("#,##"); - } - else { - nf = NumberFormat.getFormat("#.##"); - } - - String[] header = list.get(0); - String[] firstValues = list.get(1); - - ListGridField[] fields = new ListGridField[header.length]; - - for(int i = 0; i < header.length; i++) { - ListGridField f = new ListGridField(String.valueOf(i)); - fields[i] = f; - f.setTitle(header[i]); - - try { - nf.parse(firstValues[i]); - f.setType(ListGridFieldType.FLOAT); - } - catch (NumberFormatException nfe) { - f.setType(ListGridFieldType.TEXT); - } - } - - dataTable.setFields(fields); - - for(int i = 1; i < list.size(); i++) { - String[] sItem = list.get(i); - ListGridRecord r = new ListGridRecord(); - for(int j = 0; j < sItem.length; j++) { - r.setAttribute(String.valueOf(j), sItem[j]); - } - dataTable.addData(r); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/TableFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent; -import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.event.FilterHandler; -import de.intevation.flys.client.client.event.StringFilterEvent; -import de.intevation.flys.client.client.FLYSConstants; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class TableFilter -extends HLayout -implements ChangedHandler, KeyUpHandler -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected List<FilterHandler> handlers; - - protected TextItem searchfield; - - - public TableFilter() { - super(); - searchfield = new TextItem(MESSAGES.search()); - handlers = new ArrayList<FilterHandler>(); - - searchfield.addChangedHandler(this); - searchfield.addKeyUpHandler(this); - searchfield.setWidth(120); - - DynamicForm form = new DynamicForm(); - form.setFields(searchfield); - - addMember(form); - } - - - public void onChanged(ChangedEvent event) { - // This event handler is to slow... -// fireFilterCriteriaChanged(getSearchString()); - } - - - public void onKeyUp(KeyUpEvent event) { - //To deactivate "As you type" filter add - // ' && event.getKeyName().equals("Enter")' - // to the if-clause. - if (event != null) { - fireFilterCriteriaChanged(getSearchString()); - } - } - - - public String getSearchString() { - if (searchfield.getValueAsString() == null) { - return ""; - } - else { - return searchfield.getValueAsString(); - } - } - - - public void addFilterHandler(FilterHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - protected void fireFilterCriteriaChanged(String searchstring) { - StringFilterEvent filter = new StringFilterEvent(searchstring); - - for (FilterHandler handler: handlers) { - handler.onFilterCriteriaChanged(filter); - } - } - - - public void clear() { - searchfield.clearValue(); - fireFilterCriteriaChanged(""); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/TextProvider.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.data.DataSource; -import com.smartgwt.client.data.DataSourceField; -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.FieldType; -import com.smartgwt.client.types.TitleOrientation; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.events.ItemChangedEvent; -import com.smartgwt.client.widgets.form.events.ItemChangedHandler; -import com.smartgwt.client.widgets.form.validator.Validator; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.List; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class TextProvider -extends AbstractUIProvider -implements ItemChangedHandler -{ - private static final long serialVersionUID = -6868303464989138497L; - - public static final String FIELD_NAME = "textprovider_inputfield"; - public static final int FORM_WIDTH = 400; - public static final int TITLE_WIDTH = 75; - - - protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected DynamicForm form; - - - @Override - public Canvas create(DataList dataList) { - Canvas form = createForm(); - - initDefaultValues(dataList); - - return form; - } - - - protected Canvas createForm() { - return createForm(null); - } - - - protected Canvas createForm(String title) { - form = new DynamicForm(); - form.addItemChangedHandler(this); - form.setTitlePrefix(""); - form.setTitleSuffix(": "); - form.setTitleAlign(Alignment.LEFT); - form.setTitleOrientation(TitleOrientation.LEFT); - form.setTitleWidth(getTitleWidth()); - form.setWidth(getFormWidth()); - - DataSourceField item = createField(); - item.setTitle(title); - - Validator validator = getValidator(); - if (validator != null) { - item.setValidators(validator); - } - - DataSource source = new DataSource(); - source.setFields(item); - - form.setDataSource(source); - - return form; - } - - - protected void initDefaultValues(DataList dataList) { - Data data = dataList.get(0); - DataItem item = data.getDefault(); - - String value = item.getStringValue(); - - form.setValue(getFieldName(), value); - } - - - protected DataSourceField createField() { - return new DataSourceField(getFieldName(), getFieldType()); - } - - - /** - * Get field name. - * @return fields name (developer-centric). - */ - protected String getFieldName() { - return FIELD_NAME; - } - - - /** - * Get field type. - * @return fields type. - */ - protected FieldType getFieldType() { - return FieldType.TEXT; - } - - - protected Validator getValidator() { - return null; - } - - - protected int getFormWidth() { - return FORM_WIDTH; - } - - - protected int getTitleWidth() { - return TITLE_WIDTH; - } - - - /** @return null. */ - protected String getDataName() { - return null; - } - - - protected String getValueAsString() { - return (String) form.getValue(getFieldName()); - } - - - @Override - public Canvas createOld(DataList dataList) { - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - HLayout layout = new HLayout(); - Label label = new Label(dataList.getLabel()); - Label value = new Label(items[0].getLabel()); - - layout.setHeight(35); - layout.setWidth(400); - label.setWidth(200); - - layout.addMember(label); - layout.addMember(value); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - - if (!form.validate()) { - errors.add(MSG.wrongFormat()); - } - - return errors; - } - - - @Override - protected Data[] getData() { - String value = getValueAsString(); - String name = getDataName(); - - DataItem item = new DefaultDataItem(name, name, value); - return new Data[] { new DefaultData( - name, null, null, new DataItem[] { item }) }; - } - - - @Override - public void onItemChanged(ItemChangedEvent event) { - form.validate(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemeNavigationPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.ImgButton; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.OnMoveEvent; -import de.intevation.flys.client.client.event.OnMoveHandler; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ThemeNavigationPanel extends Canvas { - - public static final int PANEL_MARGIN = 5; - public static final int BUTTON_HEIGHT = 20; - public static final int BUTTON_MARGIN = 5; - private static final int BOTTON_WIDTH = 20; - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected List<OnMoveHandler> handlers; - - - public ThemeNavigationPanel() { - this.handlers = new ArrayList<OnMoveHandler>(); - - setWidth100(); - setHeight(BUTTON_HEIGHT); - setMargin(PANEL_MARGIN); - - HLayout layout = new HLayout(); - layout.setWidth100(); - layout.setHeight(BUTTON_HEIGHT); - layout.setMembersMargin(BUTTON_MARGIN); - layout.setDefaultLayoutAlign(VerticalAlignment.CENTER); - layout.setDefaultLayoutAlign(Alignment.CENTER); - - Canvas cu = createButton(MSG.theme_top(), OnMoveEvent.TOP); - Canvas u = createButton(MSG.theme_up(), OnMoveEvent.UP); - Canvas d = createButton(MSG.theme_down(), OnMoveEvent.DOWN); - Canvas cd = createButton(MSG.theme_bottom(), OnMoveEvent.BOTTOM); - - HLayout left = new HLayout(); - left.setMembersMargin(BUTTON_MARGIN); - left.setLayoutAlign(Alignment.LEFT); - left.setDefaultLayoutAlign(Alignment.LEFT); - left.setAlign(Alignment.LEFT); - left.addMember(cu); - left.addMember(u); - - HLayout right = new HLayout(); - right.setMembersMargin(BUTTON_MARGIN); - right.setLayoutAlign(Alignment.RIGHT); - right.setDefaultLayoutAlign(Alignment.RIGHT); - right.setAlign(Alignment.RIGHT); - right.addMember(d); - right.addMember(cd); - - layout.addMember(left); - layout.addMember(right); - - addChild(layout); - } - - - protected Canvas createButton(final String title, final int moveType) { - String url = GWT.getHostPageBaseURL() + title; - - ImgButton b = new ImgButton(); - b.setSrc(url); - b.setWidth(BOTTON_WIDTH); - b.setHeight(BUTTON_HEIGHT); - b.setIconHeight(BUTTON_HEIGHT); - b.setIconWidth(BOTTON_WIDTH); - b.setShowDown(false); - b.setShowRollOver(false); - b.setShowDisabled(false); - b.setShowDisabledIcon(true); - b.setShowDownIcon(false); - b.setShowFocusedIcon(false); - b.setValign(VerticalAlignment.CENTER); - - b.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent event) { - fireOnMoveEvent(moveType); - } - }); - - return b; - } - - - protected void addOnMoveHandler(OnMoveHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - protected void fireOnMoveEvent(int type) { - OnMoveEvent event = new OnMoveEvent(type); - - for (OnMoveHandler handler: handlers) { - handler.onMove(event); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,671 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.BooleanCallback; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; -import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; -import com.smartgwt.client.widgets.grid.events.RowContextClickEvent; -import com.smartgwt.client.widgets.grid.events.RowContextClickHandler; -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 de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.HasOutputParameterChangeHandlers; -import de.intevation.flys.client.client.event.HasRedrawRequestHandlers; -import de.intevation.flys.client.client.event.OnMoveEvent; -import de.intevation.flys.client.client.event.OnMoveHandler; -import de.intevation.flys.client.client.event.OutputParameterChangeEvent; -import de.intevation.flys.client.client.event.OutputParameterChangeHandler; -import de.intevation.flys.client.client.event.RedrawRequestEvent; -import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.client.services.CollectionAttributeService; -import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; -import de.intevation.flys.client.client.services.CollectionItemAttributeService; -import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItemAttribute; -import de.intevation.flys.client.shared.model.FacetRecord; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Theme; -import de.intevation.flys.client.shared.model.ThemeList; - -import java.util.ArrayList; -import java.util.List; - -/** - * ThemePanel on the left in CollectionView. - * Contains control widgets for "themes", which are plotted in a diagram (chart). - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public abstract class ThemePanel -extends Canvas -implements OnMoveHandler, - EditCompleteHandler, - HasOutputParameterChangeHandlers, - HasRedrawRequestHandlers -{ - protected CollectionAttributeServiceAsync updater = - GWT.create(CollectionAttributeService.class); - - /** The service used to get collection item attributes. */ - protected CollectionItemAttributeServiceAsync itemAttributeService = - GWT.create(CollectionItemAttributeService.class); - - /** i18ner. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** List of OutParameterChangedHandler. */ - protected List<OutputParameterChangeHandler> outHandlers; - - /** List of ChartShallRedrawHandler. */ - protected List<RedrawRequestHandler> redrawRequestHandlers; - - protected OutputMode mode; - - protected ThemeNavigationPanel navigation; - protected ListGrid list; - - /** The collection view*/ - protected CollectionView view; - - /** - * Setup Grid, navigation bar. - * @param collection Collection for which to show themes. - */ - public ThemePanel( - OutputMode mode, - CollectionView view - ) { - this.mode = mode; - this.list = createGrid(); - this.view = view; - list.addRowContextClickHandler(new RowContextClickHandler() { - @Override - public void onRowContextClick(RowContextClickEvent event) { - ListGridRecord[] records = list.getSelectedRecords(); - - Menu menu = null; - - if (records == null || records.length == 0) { - return; - } - else if (records.length == 1) { - menu = getSingleContextMenu(records); - } - else if (records.length > 1) { - menu = getMultiContextMenu(records); - } - - if (menu != null) { - list.setContextMenu(menu); - menu.showContextMenu(); - - event.cancel(); - } - } - }); - - this.redrawRequestHandlers = new ArrayList<RedrawRequestHandler>(); - this.outHandlers = new ArrayList<OutputParameterChangeHandler>(); - this.navigation = new ThemeNavigationPanel(); - this.navigation.addOnMoveHandler(this); - - this.setShowResizeBar(true); - } - - - public abstract void activateTheme(Theme theme, boolean active); - - - /** - * Replace the current collection with a new one. <b>NOTE: this operation - * triggers updateGrid() which modifies the themes in the grid.</b> - * - * @param collection The new collection object. - */ - protected void setCollection(Collection collection) { - // Set collection of view, but do not trigger event shooting. - this.view.setCollection(collection, true); - - updateGrid(); - } - - - /** Get Collection. */ - public Collection getCollection() { - return view.getCollection(); - } - - - /** - * Returns the ThemeList of the current collection and output mode. - * - * @return the current ThemeList. - */ - public ThemeList getThemeList() { - return getCollection().getThemeList(mode.getName()); - } - - public ListGridRecord[] getSelectedRecords() { - return list.getSelectedRecords(); - } - - /** - * Registers a new OutputParameterChangeHandler. - * - * @param h The new handler. - */ - @Override - public void addOutputParameterChangeHandler(OutputParameterChangeHandler h){ - if (h != null) { - outHandlers.add(h); - } - } - - - /** - * Registers a RedrawRequestHandler. - * - * @param h The new handler. - */ - @Override - public void addRedrawRequestHandler(RedrawRequestHandler h){ - if (h != null) { - redrawRequestHandlers.add(h); - } - } - - - /** - * Request a redraw of e.g. a Chart. - */ - final public void requestRedraw() { - for (RedrawRequestHandler handler: redrawRequestHandlers) { - handler.onRedrawRequest(new RedrawRequestEvent(Type.DEFAULT)); - } - } - - - /** - * Called when the attribution of an output changed. It informs the - * registered handlers about the changes. - */ - protected void fireOutputParameterChanged() { - OutputParameterChangeEvent evt = new OutputParameterChangeEvent(); - - for (OutputParameterChangeHandler handler: outHandlers) { - handler.onOutputParameterChanged(evt); - } - } - - - /** Registers the CollectionView associated to this ThemePanel. */ - public void setCollectionView(CollectionView view) { - this.view = view; - } - - - /** - * This method is used to clear the current theme grid and add new updated - * data. - */ - protected void updateGrid() { - GWT.log("ThemePanel.updateGrid"); - - ListGridRecord[] selected = list.getSelectedRecords(); - - clearGrid(); - - ThemeList themeList = getThemeList(); - - if (themeList == null) { - GWT.log("ERROR: No theme list."); - return; - } - - int count = themeList.getThemeCount(); - - for (int i = 1; i <= count; i++) { - Theme theme = themeList.getThemeAt(i); - - if (theme == null) { - continue; - } - - if (theme.getFacet().equals("empty.facet")) { - theme.setVisible(0); - } - - if (theme.getVisible() == 0) { - continue; - } - - FacetRecord newRecord = createRecord(theme); - addFacetRecord(newRecord); - - String newArtifact = theme.getArtifact(); - String newFacet = theme.getFacet(); - int newIndex = theme.getIndex(); - - for (ListGridRecord r: selected) { - FacetRecord sel = (FacetRecord) r; - Theme oldTheme = sel.getTheme(); - - if (oldTheme.getArtifact().equals(newArtifact) - && oldTheme.getFacet().equals(newFacet) - && oldTheme.getIndex() == newIndex) { - list.selectRecord(newRecord); - } - } - } - - fireOutputParameterChanged(); - } - - - /** Adds given Record to the list (table). */ - protected void addFacetRecord(FacetRecord rec) { - list.addData(rec); - } - - - /** Create a FacetRecord that wraps given theme. */ - protected FacetRecord createRecord(Theme theme) { - return new FacetRecord(theme); - } - - - /** - * This method triggers the CollectionAttributeService. Based on the current - * collectin settings, the attribute of the collection is modified or not. - * But in every case, we will get a new collection object - which might be - * the same as the current one. - */ - public void updateCollection() { - final Config config = Config.getInstance(); - final String loc = config.getLocale(); - - GWT.log("ThemePanel.updateCollection via RPC now"); - - // Don't forget to enable the panel after the request has finished! - disable(); - - updater.update(getCollection(), loc, new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not update collection attributes."); - SC.warn(MSG.getString(caught.getMessage())); - - enable(); - } - - - @Override - public void onSuccess(Collection collection) { - setCollection(collection); - - enable(); - } - }); - } - - - /** - * Create and configure the Grid to display. - */ - protected ListGrid createGrid() { - ListGrid grid = createNewGrid(); - grid.setLeaveScrollbarGap(false); - - return grid; - } - - - protected ListGrid createNewGrid() { - return new ListGrid(); - } - - - /** - * A method that removes all records from theme grid. - */ - protected void clearGrid() { - ListGridRecord[] records = list.getRecords(); - - if (records == null || records.length == 0) { - return; - } - - for (ListGridRecord record: records) { - list.removeData(record); - } - } - - /** Return 'separator'- menu-item. */ - protected MenuItem createSeparator() { - MenuItem separator = new MenuItem(); - separator.setIsSeparator(true); - return separator; - } - - - /** - * Get the context menu for a (right mouse button)click on a single item. - */ - protected Menu getSingleContextMenu(final ListGridRecord[] records) { - Menu menu = new Menu(); - - menu.addItem(createActivateItem(records)); - menu.addItem(createDeactivateItem(records)); - menu.addItem(createRemoveItem(records)); - menu.addItem(createSeparator()); - menu.addItem(createPropertiesItem(records)); - - return menu; - } - - - protected Menu getMultiContextMenu(final ListGridRecord[] records) { - Menu menu = new Menu(); - - menu.addItem(createActivateItem(records)); - menu.addItem(createDeactivateItem(records)); - menu.addItem(createRemoveItem(records)); - - return menu; - } - - - /** The properties menu item (opens style editor on click). */ - protected MenuItem createPropertiesItem(final ListGridRecord[] records) { - MenuItem properties = new MenuItem(MSG.properties()); - - properties.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - GWT.log("clicked properties"); - for (ListGridRecord record: records) { - openStyleEditor((FacetRecord) record); - } - } - }); - - return properties; - } - - - protected MenuItem createActivateItem(final ListGridRecord[] records) { - MenuItem activate = new MenuItem(MSG.activateTheme()); - - activate.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - for (ListGridRecord record: records) { - FacetRecord facet = (FacetRecord) record; - activateTheme(facet.getTheme(), true); - } - - updateCollection(); - } - }); - - return activate; - } - - - protected MenuItem createDeactivateItem(final ListGridRecord[] records) { - MenuItem deactivate = new MenuItem(MSG.deactivateTheme()); - - deactivate.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - for (ListGridRecord record: records) { - FacetRecord facet = (FacetRecord) record; - activateTheme(facet.getTheme(), false); - } - - updateCollection(); - } - }); - - return deactivate; - } - - - /** Remove given themes (not asking for confirmation). */ - protected void removeThemes(final ListGridRecord[] records) { - for (ListGridRecord record: records) { - FacetRecord facet = (FacetRecord) record; - Theme theme = facet.getTheme(); - theme.setVisible(0); - theme.setActive(0); - updateCollection(); - } - } - - - /** Create menu item for removing theme(s). Will ask for confirmation. */ - protected MenuItem createRemoveItem(final ListGridRecord[] records) { - MenuItem remove = new MenuItem(MSG.removeTheme()); - - remove.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - SC.ask(MSG.askThemeRemove(), new BooleanCallback() { - @Override - public void execute(Boolean value) { - if (value) { - removeThemes(records); - } - } - }); - } - }); - - return remove; - } - - - /** - * This method is called after a cell in the theme grid has been modified. - * - * @param event The event that stores information about the modified record. - */ - @Override - public void onEditComplete(EditCompleteEvent event) { - GWT.log("Edited record."); - - int row = event.getRowNum(); - FacetRecord rec = (FacetRecord) list.getRecord(row); - - Theme theme = rec.getTheme(); - - theme.setDescription(rec.getName()); - activateTheme(theme, rec.getActive()); - - updateCollection(); - } - - - /** - * This method should be defined in subclasses that wants to listen to this - * event. - * - * @param theme The theme that is moved. - * @param oldIdx The index of the theme before it was moved. - * @param newIdx The index of the theme after it was moved. - */ - protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) { - // Do nothing - } - - - @Override - public void onMove(OnMoveEvent event) { - int type = event.getType(); - - GWT.log("ThemePanel.onMove: " + type); - - ListGridRecord[] records = list.getSelectedRecords(); - - if (records == null || records.length == 0) { - GWT.log("ThemePanel.onMove: No records selected."); - return; - } - - switch (type) { - case 0: moveRecordsTop(records); break; - case 1: moveRecordsUp(records); break; - case 2: moveRecordsDown(records); break; - case 3: moveRecordsBottom(records); break; - } - - updateCollection(); - } - - - /** - * Moves the selected grid records (themes) to the top of the grid. - * - * @param records The selected themes in the list. Null not permitted. - */ - protected void moveRecordsTop(ListGridRecord[] records) { - ThemeList themeList = getThemeList(); - - int idx = 1; - - for (ListGridRecord record: records) { - Theme theme = ((FacetRecord) record).getTheme(); - fireThemeMoved(theme, theme.getPosition(), idx); - themeList.setThemePosition(theme, idx++); - } - - updateGrid(); - } - - - /** - * Moves the selected grid records (themes) one step up. - * - * @param records The selected themes in the list. Null not permitted. - */ - protected void moveRecordsUp(ListGridRecord[] records) { - ThemeList themeList = getThemeList(); - - int[] newPos = new int[records.length]; - - for (int i = 0; i < records.length ; i++) { - Theme theme = ((FacetRecord) records[i]).getTheme(); - newPos[i] = theme.getPosition() - 1; - } - - for (int i = 0; i < records.length ; i++) { - Theme theme = ((FacetRecord) records[i]).getTheme(); - fireThemeMoved(theme, theme.getPosition(), newPos[i]); - themeList.setThemePosition(theme, newPos[i]); - } - - updateGrid(); - } - - - /** - * Moves the selected grid records (themes) one step down. - * - * @param records The selected themes in the list. Null not permitted. - */ - protected void moveRecordsDown(ListGridRecord[] records) { - ThemeList themeList = getThemeList(); - - int[] newPos = new int[records.length]; - - for (int i = records.length-1; i >= 0; i--) { - Theme theme = ((FacetRecord) records[i]).getTheme(); - newPos[i] = theme.getPosition()+1; - } - - for (int i = records.length-1; i >= 0; i--) { - Theme theme = ((FacetRecord) records[i]).getTheme(); - fireThemeMoved(theme, theme.getPosition(), newPos[i]); - themeList.setThemePosition(theme, newPos[i]); - } - - updateGrid(); - } - - - /** - * Moves the selected grid records (themes) to the bottom of the grid. - * - * @param records The selected themes in the list. Null not permitted. - */ - protected void moveRecordsBottom(ListGridRecord[] records) { - ThemeList themeList = getThemeList(); - - int idx = themeList.getThemeCount(); - - for (int i = records.length-1; i >= 0; i--) { - Theme theme = ((FacetRecord) records[i]).getTheme(); - fireThemeMoved(theme, theme.getPosition(), idx); - themeList.setThemePosition(theme, idx--); - } - - updateGrid(); - } - - - protected void openStyleEditor(final FacetRecord record) { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - String artifact = record.getTheme().getArtifact(); - - itemAttributeService.getCollectionItemAttribute( - this.getCollection(), - artifact, - locale, - new AsyncCallback<CollectionItemAttribute>() { - @Override - public void onFailure (Throwable caught) { - SC.warn(MSG.getString(caught.getMessage())); - } - @Override - public void onSuccess(CollectionItemAttribute cia) { - GWT.log("Successfully loaded collectionitem attributes."); - showStyleEditor(cia, record); - } - }); - } - - - protected void showStyleEditor( - CollectionItemAttribute cia, - FacetRecord record) - { - StyleEditorWindow win = new StyleEditorWindow( - getCollection(), - cia, - record); - win.setThemePanel(this); - win.centerInPage(); - win.show(); - } - - - /** Get OutputMode of this Panel. */ - public OutputMode getMode() { - return this.mode; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/Toolbar.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.smartgwt.client.types.Overflow; -import com.smartgwt.client.widgets.events.CloseClickEvent; -import com.smartgwt.client.widgets.events.CloseClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.User; - - -public abstract class Toolbar extends HLayout { - - protected OutputTab outputTab; - - - public Toolbar(OutputTab outputTab) { - super(); - - // Set overflow to hidden in order to prevent nasty scrollbars in IE - setOverflow(Overflow.HIDDEN); - - this.outputTab = outputTab; - } - - - public OutputTab getOutputTab() { - return outputTab; - } - - - public Artifact getArtifact() { - return outputTab.getCollectionView().getArtifact(); - } - - - public User getUser() { - return outputTab.getCollectionView().getUser(); - } - - - protected void openDatacageWindow(RedrawRequestHandler handler) { - Artifact artifact = getArtifact(); - User user = getUser(); - - String outs = getOutputTab().getOutputName(); - - final DatacageWindow dc = new DatacageWindow( - artifact, user, outs, outputTab.getCollectionView()); - dc.addRedrawRequestHandler(handler); - dc.addCloseClickHandler(new CloseClickHandler() { - @Override - public void onCloseClick(CloseClickEvent event) { - dc.destroy(); - } - }); - dc.show(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProvider.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.io.Serializable; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; - -/** - * This interface describes a method that creates a Canvas element displaying - * DataItems for a current state of the artifact. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface UIProvider extends Serializable { - - /** - * This method creates a Canvas element showing the DataItems in - * <i>data</i>. - * - * @param data The DataList object. - * - * @return the Canvas showing the Data. - */ - public Canvas create(DataList data); - - - /** - * This method creates a Canvas element showing the old Data objects in the - * DataList <i>data</i>. - * - * @param dataList The DataList which elements should be displayed. - * - * @return a Canvas displaying the Data. - */ - public Canvas createOld(DataList dataList); - - - public Canvas createHelpLink(DataList dataList, Data data); - - - /** - * This method injects a container that is used to position helper widgets. - * - * @param container A container that is used to position helper widgets. - */ - public void setContainer(VLayout container); - - - /** - * Sets an artifact that contains the status data information for a project. - * - * @param artifact The artifact containing status information. - */ - public void setArtifact(Artifact artifact); - - - /** - * Sets the parent Collection of the Artifact. - */ - public void setCollection(Collection collection); - - public void setParameterList(ParameterList list); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; - -import de.intevation.flys.client.client.ui.fixation.FixEventSelect; -import de.intevation.flys.client.client.ui.fixation.FixFunctionSelect; -import de.intevation.flys.client.client.ui.fixation.FixGaugeSelectPanel; -import de.intevation.flys.client.client.ui.fixation.FixLocationPanel; -import de.intevation.flys.client.client.ui.fixation.FixMultiPeriodPanel; -import de.intevation.flys.client.client.ui.fixation.FixPeriodPanel; -import de.intevation.flys.client.client.ui.fixation.FixQSelectPanel; -import de.intevation.flys.client.client.ui.minfo.BedHeightsDatacagePanel; -import de.intevation.flys.client.client.ui.minfo.BedMultiPeriodPanel; -import de.intevation.flys.client.client.ui.minfo.CheckboxPanel; -import de.intevation.flys.client.client.ui.minfo.SedLoadDistancePanel; -import de.intevation.flys.client.client.ui.minfo.SedLoadEpochPanel; -import de.intevation.flys.client.client.ui.minfo.SedLoadOffEpochPanel; -import de.intevation.flys.client.client.ui.minfo.SedLoadPeriodPanel; -import de.intevation.flys.client.client.ui.sq.SQPeriodPanel; -import de.intevation.flys.client.shared.model.User; - -/** - * Depending on the provider the state declared, return a UIProvider. - * - * A UIProvider provides widgets and input helpers to guide input to an - * artifacts state. - */ -public class UIProviderFactory { - - private UIProviderFactory() { - } - - /** @param uiProvider uiprovider demanded for by state. */ - public static UIProvider getProvider(String uiProvider, User user) { - if (uiProvider == null || uiProvider.equals("")) { - return new SelectProvider(); - } - else if (uiProvider.equals("select_with_map")) { - return new MapSelection(); - } - else if (uiProvider.equals("location_distance_panel")) { - return new LocationDistancePanel(); - } - else if (uiProvider.equals("location_panel")) { - return new SingleLocationPanel(); - } - else if (uiProvider.equals("multi_location_panel")) { - return new MultipleLocationPanel(); - } - else if (uiProvider.equals("distance_panel")) { - return new DistancePanel(); - } - else if (uiProvider.equals("distance_only_panel")) { - return new DistanceOnlyPanel(); - } - else if (uiProvider.equals("waterlevel_ground_panel")) { - return new WaterlevelGroundPanel(); - } - else if (uiProvider.equals("wq_panel")) { - return new WQInputPanel(); - } - else if (uiProvider.equals("wq_panel_adapted")) { - return new WQAdaptedInputPanel(); - } - else if (uiProvider.equals("q_segmented_panel")) { - return new QSegmentedInputPanel(); - } - else if (uiProvider.equals("river_panel")) { - return new LinkSelection(); - } - else if (uiProvider.equals("continue")) { - return new ContinuePanel(); - } - else if (uiProvider.equals("wsp_datacage_panel")) { - return new WspDatacagePanel(user); - } - else if (uiProvider.equals("dgm_datacage_panel")) { - return new DemDatacagePanel(user); - } - else if (uiProvider.equals("datacage_twin_panel")) { - return new DatacageTwinPanel(user); - } - else if (uiProvider.equals("auto_integer")) { - return new AutoIntegerPanel(); - } - else if (uiProvider.equals("boolean_panel")) { - return new BooleanPanel(); - } - else if (uiProvider.equals("noinput")) { - return new NoInputPanel(); - } - else if (uiProvider.equals("map_digitize")) { - return new DigitizePanel(); - } - else if (uiProvider.equals("timerange")) { - return new IntegerRangePanel(); - } - else if (uiProvider.equals("wq_simple_array")) { - return new WQSimpleArrayPanel(); - } - else if (uiProvider.equals("gaugetimerange")) { - return new GaugeTimeRangePanel(); - } - else if (uiProvider.equals("fix.location_panel")) { - return new FixLocationPanel(); - } - else if (uiProvider.equals("fix.period_panel")) { - return new FixPeriodPanel(); - } - else if (uiProvider.equals("fix.period_ref_panel")) { - return new FixPeriodPanel("ref_start", "ref_end"); - } - else if (uiProvider.equals("fix.period_ana_panel")) { - return new FixMultiPeriodPanel(); - } - else if (uiProvider.equals("fix.qselect_panel")) { - return new FixQSelectPanel(); - } - else if (uiProvider.equals("fix.gaugeselect_panel")) { - return new FixGaugeSelectPanel(); - } - else if (uiProvider.equals("fix.event_panel")) { - return new FixEventSelect(); - } - else if (uiProvider.equals("fix.preprocessing_panel")) { - return new BooleanPanel(); - } - else if (uiProvider.equals("fix.functionselect")) { - return new FixFunctionSelect(); - } - else if (uiProvider.equals("period_select")) { - return new PeriodPanel(); - } - else if (uiProvider.equals("periods_select")) { - return new MultiPeriodPanel(); - } - else if (uiProvider.equals("sq.period.select")) { - return new SQPeriodPanel(); - } - else if (uiProvider.equals("outliers_input")) { - return new DoubleInputPanel(); - } - else if (uiProvider.equals("percent_input")) { - return new DoubleInputPanel("percent"); - } - else if (uiProvider.equals("parameter-matrix")) { - return new ParameterMatrixPanel(); - } - else if (uiProvider.equals("minfo.bed.year_epoch")) { - return new RadioPanel(); - } - else if (uiProvider.equals("bedquality_periods_select")) { - return new BedMultiPeriodPanel(); - } - else if (uiProvider.equals("bedheights_twin_panel")) { - return new BedHeightsDatacagePanel(user); - } - else if (uiProvider.equals("minfo.bed.char_diameter")) { - return new CheckboxPanel(); - } - else if (uiProvider.equals("minfo.sedimentload_unit_select")) { - return new RadioPanel(); - } - else if (uiProvider.equals("gauge_discharge_curve")) { - return new StaticDataPanel(); - } - else if (uiProvider.equals("minfo.sedimentload_distance_select")) { - return new SedLoadDistancePanel(); - } - else if (uiProvider.equals("minfo.sedimentload_year_select")) { - return new SedLoadPeriodPanel(); - } - else if (uiProvider.equals("minfo.sedimentload_epoch_select")) { - return new SedLoadEpochPanel(); - } - else if (uiProvider.equals("minfo.sedimentload_offepoch_select")) { - return new SedLoadOffEpochPanel(); - } - else if (uiProvider.equals("hws_datacage_panel")) { - return new HWSDatacagePanel(user); - } - else if (uiProvider.equals("user_rgd_panel")) { - return new UserRGDProvider(); - } - else if (uiProvider.equals("static_sqrelation")) { - return new StaticDataPanel(); - } - else { - //GWT.log("Picked default provider."); - return new SelectProvider(); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UserRGDProvider.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.types.Encoding; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.HTMLPane; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.UploadItem; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - - -public class UserRGDProvider -extends SelectProvider -{ - - private HTMLPane uploadTargetFrame; - private String uploadFile; - - public UserRGDProvider() { - uploadTargetFrame = new HTMLPane(); - } - - @Override - public Canvas create(DataList list) { - List<Data> data = list.getAll(); - - //Canvas selectBox = super.create(clone); - Canvas widget = createWidget(list); - - return widget; - } - - - /** - * This method creates the content of the widget. - * - * @param data The {@link DataList} object. - * - * @return a combobox. - */ - @Override - protected Canvas createWidget(DataList data) { - GWT.log("DigitizePanel - createWidget()"); - - VLayout layout = new VLayout(); - layout.setAlign(VerticalAlignment.TOP); - layout.setHeight(25); - - int size = data.size(); - - for (int i = 0; i < size; i++) { - Data d = data.get(i); - - Label label = new Label(d.getDescription()); - label.setValign(VerticalAlignment.TOP); - label.setHeight(20); - label.setWidth(400); - - uploadTargetFrame.setWidth("200px"); - uploadTargetFrame.setHeight("50px"); - uploadTargetFrame.setContents( - "<iframe id='uploadTarget' name='uploadTarget' scrolling='no' width=200 height=50 style='border: 0px'></iframe>"); - uploadTargetFrame.setBorder("0px"); - uploadTargetFrame.setScrollbarSize(0); - - final DynamicForm uploadForm = new DynamicForm(); - uploadForm.setAction("flys/fileupload?uuid=" + artifact.getUuid()); - uploadForm.setTarget("uploadTarget"); - uploadForm.setEncoding(Encoding.MULTIPART); - Label uploadLabel = new Label(MSG.shape_file_upload()); - uploadLabel.setHeight(20); - final UploadItem uploadItem = new UploadItem(); - uploadItem.setShowTitle(false); - uploadForm.setFields(uploadItem); - Button submit = new Button(MSG.upload_file()); - submit.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - uploadFile = uploadItem.getValueAsString(); - uploadForm.submitForm(); - } - }); - - layout.addMember(label); - layout.addMember(form); - layout.addMember(uploadLabel); - layout.addMember(uploadForm); - layout.addMember(submit); - layout.addMember(getNextButton()); - - layout.setMembersMargin(10); - layout.addMember(uploadTargetFrame); - } - - layout.setAlign(VerticalAlignment.TOP); - - return layout; - } - - @Override - protected Data[] getData() { - Data[] total = new Data[1]; - - if (uploadFile != null && uploadFile.length() > 0) { - DataItem item = new DefaultDataItem( - "uesk.user-rgd", "uesk.user-rgd", uploadFile); - total[0] = new DefaultData( - "uesk.user-rgd", null, null, new DataItem[] { item }); - } - else { - // Happens when OpenLayers is missing - DataItem item = new DefaultDataItem( - "uesk.user-rgd", "uesk.user-rgd", MSG.notselected()); - total[0] = new DefaultData( - "uesk.user-rgd", null, null, new DataItem[] { item }); - } - - return total; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,828 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.TitleOrientation; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.RadioGroupItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; -import com.smartgwt.client.widgets.form.fields.events.FocusEvent; -import com.smartgwt.client.widgets.form.fields.events.FocusHandler; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.WQInfoService; -import de.intevation.flys.client.client.services.WQInfoServiceAsync; -import de.intevation.flys.client.client.ui.wq.QDTable; -import de.intevation.flys.client.client.ui.wq.WTable; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.WQDataItem; -import de.intevation.flys.client.shared.model.WQInfoObject; -import de.intevation.flys.client.shared.model.WQInfoRecord; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - - -/** - * This UIProvider creates a widget to enter W or Q data for discharge - * longitudinal section computations. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class WQAdaptedInputPanel -extends AbstractUIProvider -implements ChangeHandler, BlurHandler, FocusHandler -{ - private static final long serialVersionUID = -3218827566805476423L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - public static final String FIELD_WQ_MODE = "wq_isq"; - public static final String FIELD_WQ_W = "W"; - public static final String FIELD_WQ_Q = "Q"; - - public static final String GAUGE_SEPARATOR = ":"; - - public static final String GAUGE_PART_SEPARATOR = ";"; - - public static final String VALUE_SEPARATOR = ","; - - public static final int ROW_HEIGHT = 20; - - /** The constant field name for choosing w or q mode. */ - public static final String FIELD_WQ = "wq"; - - /** The constant field name for choosing single values or range. */ - public static final String FIELD_MODE = "mode"; - - /** The constant field value for range input mode. */ - public static final String FIELD_MODE_RANGE = "range"; - - /** Service to fetch W/Q MainValues. */ - protected WQInfoServiceAsync wqInfoService = - GWT.create(WQInfoService.class); - - /** The message class that provides i18n strings. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** Stores the input panels related to their keys. */ - protected Map<String, DoubleArrayPanel> wqranges; - - /** List of doubleArrayPanels shown. */ - protected ArrayList<DoubleArrayPanel> doubleArrayPanels; - - /** [startkm,endkm] per gauge in selected range. */ - protected double[][] gaugeRanges; - - /** Stores the min/max values for each q range (gauge). */ - protected Map<String, double[]> qranges; - - /** Stores the min/max values for each w range (gauge). */ - protected Map<String, double[]> wranges; - - /** The RadioGroupItem that determines the w/q input mode. */ - protected DynamicForm modes; - - /** List of wTables in inputhelper section. */ - protected List<WTable> wTables; - - /** List of QDTables in inputhelper section. */ - protected List<QDTable> qdTables; - - /** Tabs in inputhelper area. */ - protected TabSet tabs; - - /** The currently focussed Input element. */ - protected DoubleArrayPanel itemWithFocus; - - - public WQAdaptedInputPanel() { - wqranges = new HashMap<String, DoubleArrayPanel>(); - doubleArrayPanels = new ArrayList<DoubleArrayPanel>(); - qranges = new HashMap<String, double[]>(); - wranges = new HashMap<String, double[]>(); - wTables = new ArrayList<WTable>(); - qdTables = new ArrayList<QDTable>(); - } - - - @Override - public Canvas create(DataList data) { - readGaugeRanges(data); - initHelperPanel(); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(data); - Label label = new Label(MSG.wqadaptedTitle()); - - label.setHeight(25); - - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - layout.setWidth(350); - - layout.addMember(label); - layout.addMember(widget); - layout.addMember(submit); - - fetchWQData(); - - initTableListeners(); - - return layout; - } - - - /** Inits the helper panel. */ - // TODO duplicate in WQInputPanel - protected void initHelperPanel() { - tabs = new TabSet(); - tabs.setWidth100(); - tabs.setHeight100(); - - // For each gauge, add two tabs with helper tables. - - for (int i = 0; i< gaugeRanges.length; i++) { - // Later the tabs title will get adjusted to include gauges name. - // TODO the tabs title becomes rather long through that (i18n). - Tab wTab = new Tab(MESSAGE.wq_table_w()); - Tab qTab = new Tab(MESSAGE.wq_table_q()); - - QDTable qdTable = new QDTable(); - WTable wTable = new WTable(); - - wTables.add(wTable); - qdTables.add(qdTable); - - qdTable.showSelect(); - //wTable.showSelect(); - wTab.setPane(wTable); - qTab.setPane(qdTable); - - tabs.addTab(wTab, i*2+0); - tabs.addTab(qTab, i*2+1); - } - - helperContainer.addMember(tabs); - } - - - /** - * Initializes the listeners of the WQD tables. - */ - // TODO dupe from WQInputPanel - protected void initTableListeners() { - int i = 0; - for (QDTable qdTable: qdTables) { - // Register listener such that values are filled in on click. - final QDTable table = qdTable; - final int fi = i; - CellClickHandler handler = new CellClickHandler() { - @Override - public void onCellClick(CellClickEvent e) { - if (isWMode() || table.isLocked()) { - return; - } - - int idx = e.getColNum(); - Record r = e.getRecord(); - double val = r.getAttributeAsDouble("value"); - - doubleArrayPanels.get(fi).setValues(new double[]{val}); - // If a named value for first gauge is chosen, try to find and set - // the values to the other panels too. - if (fi == 0) { - String valueName = r.getAttribute("name"); - int oi = 0; - // TODO instead of oi use random access. - for (QDTable otherQDTable: qdTables) { - if (oi == 0) { - oi++; - continue; - } - Double value = otherQDTable.findRecordValue(valueName); - if (value == null) { - // TODO i18n - SC.warn("No Value for <name> at <gauge>"); - } - else { - doubleArrayPanels.get(oi).setValues(new double[]{value}); - } - oi++; - } - } - else { - // Focus next. - if (fi != doubleArrayPanels.size()-1) { - doubleArrayPanels.get(fi+1).focusInItem(1); - } - } - } - }; - - qdTable.addCellClickHandler(handler); - i++; - } - } - - - @Override - public Canvas createOld(DataList dataList) { - List<Data> all = dataList.getAll(); - Data wqData = getData(all, "wq_values"); - Data wqMode = getData(all, "wq_isq"); - boolean isQ = wqMode.getItems()[0].getStringValue().equals("true"); - Canvas back = getBackButton(dataList.getState()); - - HLayout valLayout = new HLayout(); - HLayout modeLayout = new HLayout(); - VLayout vlayout = new VLayout(); - - Label wqLabel = new Label(dataList.getLabel()); - Label modeLabel = new Label(""); - - wqLabel.setValign(VerticalAlignment.TOP); - - wqLabel.setWidth(200); - wqLabel.setHeight(25); - modeLabel.setHeight(25); - modeLabel.setWidth(200); - - valLayout.addMember(wqLabel); - valLayout.addMember(createOldWQValues(wqData, isQ)); - - valLayout.addMember(back); - modeLayout.addMember(modeLabel); - - vlayout.addMember(valLayout); - vlayout.addMember(modeLayout); - - return vlayout; - } - - - /** Create area showing previously entered w or q data. */ - protected Canvas createOldWQValues(Data wqData, boolean isQ) { - VLayout layout = new VLayout(); - - DataItem item = wqData.getItems()[0]; - String value = item.getStringValue(); - - String[] gauges = value.split(GAUGE_SEPARATOR); - - String unit = isQ ? "m³/s" : "cm"; - - for (String gauge: gauges) { - HLayout h = new HLayout(); - - String[] parts = gauge.split(GAUGE_PART_SEPARATOR); - String[] values = parts[3].split(VALUE_SEPARATOR); - - Label l = new Label(parts[2] + ": "); - - StringBuilder sb = new StringBuilder(); - boolean first = true; - - for (String v: values) { - if (!first) { - sb.append(", "); - } - - sb.append(v); - sb.append(" "); - sb.append(unit); - - first = false; - } - - Label v = new Label(sb.toString()); - - l.setWidth(65); - v.setWidth(65); - - h.addMember(l); - h.addMember(v); - - layout.addMember(h); - } - - return layout; - } - - - /** Create non-input helper part of the UI. */ - protected Canvas createWidget(DataList dataList) { - VLayout layout = new VLayout(); - - Canvas mode = createMode(dataList); - Canvas list = createList(dataList); - - DataItem[] items = getWQItems(dataList); - int listHeight = ROW_HEIGHT * items.length; - - mode.setHeight(25); - mode.setWidth(200); - - layout.addMember(mode); - layout.addMember(list); - - layout.setHeight(25 + listHeight); - layout.setWidth(350); - - initUserDefaults(dataList); - - return layout; - } - - - @Override - public List<String> validate() { - if (isWMode()) { - return validateW(); - } - else { - return validateQ(); - } - } - - - protected List<String> validateRange(Map<String, double[]> ranges) { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - Iterator<String> iter = wqranges.keySet().iterator(); - - while (iter.hasNext()) { - List<String> tmpErrors = new ArrayList<String>(); - - String key = iter.next(); - DoubleArrayPanel dap = wqranges.get(key); - - if (!dap.validateForm()) { - errors.add(MSG.error_invalid_double_value()); - return errors; - } - - double[] mm = ranges.get(key); - if (mm == null) { - SC.warn(MSG.error_read_minmax_values()); - continue; - } - - double[] values = dap.getInputValues(); - double[] good = new double[values.length]; - - int idx = 0; - - for (double value: values) { - if (value < mm[0] || value > mm[1]) { - String tmp = MSG.error_validate_range(); - tmp = tmp.replace("$1", nf.format(value)); - tmp = tmp.replace("$2", nf.format(mm[0])); - tmp = tmp.replace("$3", nf.format(mm[1])); - tmpErrors.add(tmp); - } - else { - good[idx++] = value; - } - } - - double[] justGood = new double[idx]; - for (int i = 0; i < justGood.length; i++) { - justGood[i] = good[i]; - } - - if (!tmpErrors.isEmpty()) { - dap.setValues(justGood); - - errors.addAll(tmpErrors); - } - } - - return errors; - } - - - protected List<String> validateW() { - return validateRange(wranges); - } - - - protected List<String> validateQ() { - return validateRange(qranges); - } - - - protected void initUserDefaults(DataList dataList) { - initUserWQValues(dataList); - initUserWQMode(dataList); - } - - - protected void initUserWQMode(DataList dataList) { - List<Data> allData = dataList.getAll(); - - Data dDef = getData(allData, "wq_mode"); - DataItem def = dDef != null ? dDef.getDefault() : null; - String value = def != null ? def.getStringValue() : null; - - if (value != null && value.equals(FIELD_WQ_W)) { - modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W); - } - else { - modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q); - } - } - - - protected void initUserWQValues(DataList dataList) { - List<Data> allData = dataList.getAll(); - - Data dDef = getData(allData, "wq_values"); - DataItem def = dDef != null ? dDef.getDefault() : null; - String value = def != null ? def.getStringValue() : null; - - if (value == null || value.length() == 0) { - return; - } - - String[] lines = value.split(GAUGE_SEPARATOR); - - if (lines == null || lines.length == 0) { - return; - } - - for (String line: lines) { - String[] cols = line.split(GAUGE_PART_SEPARATOR); - String title = createLineTitle(line); - - if (cols == null || cols.length < 3) { - continue; - } - - String[] strValues = cols[2].split(VALUE_SEPARATOR); - double[] values = new double[strValues.length]; - - int idx = 0; - - for (String strValue: strValues) { - try { - values[idx++] = Double.valueOf(strValue); - } - catch (NumberFormatException nfe) { - // do nothing - } - } - - String key = cols[0] + GAUGE_PART_SEPARATOR + cols[1]; - DoubleArrayPanel dap = wqranges.get(key); - - if (dap == null) { - continue; - } - - dap.setValues(values); - } - } - - /** Populate Gauge Ranges array. */ - private void readGaugeRanges(DataList dataList) { - DataItem[] items = getWQItems(dataList); - gaugeRanges = new double[items.length][2]; - - int i = 0; - - for (DataItem item: items) { - String[] startEndKm = item.getLabel().split(";"); - - gaugeRanges[i][0] = Double.parseDouble(startEndKm[0]); - gaugeRanges[i][1] = Double.parseDouble(startEndKm[1]); - i++; - } - } - - - protected Canvas createList(DataList dataList) { - VLayout layout = new VLayout(); - - DataItem[] items = getWQItems(dataList); - - int i = 0; - - for (DataItem item: items) { - String title = item.getLabel(); // of form: 70.5;112.0 - String label = item.getStringValue(); - - // Rename W and Q tab to include gauges name. - tabs.getTab(i*2).setTitle(tabs.getTab(i*2).getTitle() - + " (" + label + ")"); - tabs.getTab(i*2+1).setTitle(tabs.getTab(i*2+1).getTitle() - + " (" + label + ")"); - - DoubleArrayPanel dap = new DoubleArrayPanel( - label, null, this, this, TitleOrientation.LEFT); - - wqranges.put(title, dap); - doubleArrayPanels.add(dap); - - if (item instanceof WQDataItem) { - WQDataItem wq = (WQDataItem) item; - double[] mmQ = wq.getQRange(); - double[] mmW = wq.getWRange(); - - qranges.put(title, mmQ); - wranges.put(title, mmW); - } - - layout.addMember(dap); - i++; - } - - layout.setHeight(items.length * ROW_HEIGHT); - - return layout; - } - - - /** Get items which are not WQ_MODE. */ - protected DataItem[] getWQItems(DataList dataList) { - List<Data> data = dataList.getAll(); - - for (Data d: data) { - String name = d.getLabel(); - - if (name.equals(FIELD_WQ_MODE)) { - continue; - } - - return d.getItems(); - } - - return null; - } - - - /** - * Create radio button for switching w and q input. - * Radiobutton-change also triggers helper panel tab selection. - */ - protected Canvas createMode(DataList dataList) { - RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE); - wq.setShowTitle(false); - wq.setVertical(false); - wq.setWidth(200); - - LinkedHashMap wqValues = new LinkedHashMap(); - wqValues.put(FIELD_WQ_W, MSG.wqW()); - wqValues.put(FIELD_WQ_Q, MSG.wqQatGauge()); - - wq.setValueMap(wqValues); - - modes = new DynamicForm(); - modes.setFields(wq); - modes.setWidth(200); - wq.addChangeHandler(new ChangeHandler() { - @Override - public void onChange(ChangeEvent e) { - DynamicForm form = e.getForm(); - - if(form.getValueAsString(FIELD_WQ_MODE).contains("Q")) { - tabs.selectTab(0); - } - else { - tabs.selectTab(1); - } - } - }); - - - LinkedHashMap initial = new LinkedHashMap(); - initial.put(FIELD_WQ_MODE, FIELD_WQ_Q); - modes.setValues(initial); - tabs.selectTab(1); - return modes; - } - - - public String createLineTitle(String key) { - String[] splitted = key.split(";"); - - return splitted[0] + " - " + splitted[1]; - } - - - @Override - public Data[] getData() { - Data mode = getWQMode(); - Data values = getWQValues(); - - return new Data[] { mode, values }; - } - - - public boolean isWMode() { - String mode = (String) modes.getValue(FIELD_WQ_MODE); - - return FIELD_WQ_W.equals(mode); - } - - - protected Data getWQMode() { - String wqMode = modes.getValueAsString(FIELD_WQ_MODE); - String value = "false"; - if (wqMode.equals("Q")) { - value = "true"; - } - DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value); - Data mode = new DefaultData( - "wq_isq", null, null, new DataItem[] { item }); - - return mode; - } - - - protected Data getWQValues() { - String wqvalue = null; - - Iterator<String> iter = wqranges.keySet().iterator(); - while (iter.hasNext()) { - String key = iter.next(); - DoubleArrayPanel dap = wqranges.get(key); - String label = dap.getItemTitle(); - - double[] values = dap.getInputValues(); - if (wqvalue == null) { - wqvalue = createValueString(key + ";" + label, values); - } - else { - wqvalue += GAUGE_SEPARATOR + createValueString(key + ";" + label, values); - } - } - - DataItem valueItem = new DefaultDataItem( - "wq_values", "wq_values", wqvalue); - Data values = new DefaultData( - "wq_values", null, null, new DataItem[] { valueItem }); - - return values; - } - - - protected String createValueString(String key, double[] values) { - StringBuilder sb = new StringBuilder(); - - boolean first = true; - - for (double value: values) { - if (!first) { - sb.append(","); - } - - sb.append(Double.toString(value)); - - first = false; - } - - return key + ";" + sb.toString(); - } - - - @Override - public void onChange(ChangeEvent event) { - // TODO IMPLEMENT ME - } - - - /** Store the currently focussed DoubleArrayPanel and focus helper tab. */ - @Override - public void onFocus(FocusEvent event) { - itemWithFocus = (DoubleArrayPanel) event.getForm(); - // Switch to respective tab. - // TODO which makes a focus loss - int inputIndex = doubleArrayPanels.indexOf(itemWithFocus); - tabs.selectTab(inputIndex*2 + (isWMode() ? 0 : 1)); - } - - - @Override - public void onBlur(BlurEvent event) { - DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); - dap.validateForm(event.getItem()); - } - - - /** Get the WQD data from service and stuck them up that tables. */ - protected void fetchWQData() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - double[] mm = getMinMaxKM(data); - String river = getRiverName(data); - - int i = 0; - - // Get Data for respective gauge. - for (double[] range : gaugeRanges){ - // Gauge ranges overlap, move start and end a bit closer to each other. - final double rDiff = (range[1] - range[0]) / 10d; - final int fi = i; - wqInfoService.getWQInfo(locale, river, range[0]+rDiff, range[1]-rDiff, - new AsyncCallback<WQInfoObject[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve wq informations."); - SC.warn(caught.getMessage()); - } - - @Override - public void onSuccess(WQInfoObject[] wqi) { - int num = wqi != null ? wqi.length :0; - GWT.log("Received " + num + " wq informations (" + fi + "."); - - if (num == 0) { - return; - } - - addWQInfo(wqi, fi); - } - } - ); - i++; - } - } - - - /** Add Info to helper table for gauge at index gaugeIdx. */ - protected void addWQInfo (WQInfoObject[] wqi, int gaugeIdx) { - for(WQInfoObject wi: wqi) { - WQInfoRecord rec = new WQInfoRecord(wi); - - if (wi.getType().equals("W")) { - wTables.get(gaugeIdx).addData(rec); - } - else { - qdTables.get(gaugeIdx).addData(rec); - } - } - } - - - /** - * Determines the min and max kilometer value selected in a former state. A - * bit silly, but we need to run over each value of the "old data" to find - * such values because it is not available here. - * - * @param data The DataList which contains the whole data inserted for the - * current artifact. - * - * @return a double array with [min, max]. - */ - protected double[] getMinMaxKM(DataList[] data) { - ArtifactDescription adesc = artifact.getArtifactDescription(); - return adesc.getKMRange(); - } - - - /** - * Returns the name of the selected river. - * - * @param data The DataList with all data. - * - * @return the name of the current river. - */ - protected String getRiverName(DataList[] data) { - ArtifactDescription adesc = artifact.getArtifactDescription(); - return adesc.getRiver(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1848 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.RadioGroupItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.WQInfoService; -import de.intevation.flys.client.client.services.WQInfoServiceAsync; -import de.intevation.flys.client.client.ui.wq.QDTable; -import de.intevation.flys.client.client.ui.wq.WTable; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.WQInfoObject; -import de.intevation.flys.client.shared.model.WQInfoRecord; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - - -/** - * This UIProvider creates a widget to enter W or Q data. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class WQInputPanel -extends AbstractUIProvider -implements ChangeHandler, BlurHandler -{ - private static final long serialVersionUID = 4797387993390350341L; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - protected WQInfoServiceAsync wqInfoService = - GWT.create(WQInfoService.class); - - /** The constant field name for choosing w or q mode.*/ - public static final String FIELD_WQ_W_FREE = "WFREE"; - - /** The constant field name for choosing w or q mode.*/ - public static final String FIELD_WQ = "wq"; - - /** The constant field value for W input mode.*/ - public static final String FIELD_WQ_W = "W"; - - /** The constant field value for Q input mode.*/ - public static final String FIELD_WQ_Q = "Q"; - - /** The constant field value for Q input mode.*/ - public static final String FIELD_WQ_Q_FREE = "QFREE"; - - /** The constant field name for choosing single values or range.*/ - public static final String FIELD_MODE = "mode"; - - /** The constant field value for single input mode.*/ - public static final String FIELD_MODE_SINGLE = "single"; - - /** The constant field value for range input mode.*/ - public static final String FIELD_MODE_RANGE = "range"; - - /** The constant value that determines the width of the left panel.*/ - public static final int WIDTH_LEFT_UPPER = 400; - - public static final int WIDTH_LEFT_LOWER = 223; - - /** The container that manages the w and q panels.*/ - protected HLayout container; - - /** The RadioGroupItem that determines the w/q input mode.*/ - protected DynamicForm modes; - - /** The min values for the 'from' property in the W-Range input mode.*/ - protected double minW; - - /** The min values for the 'from' property in the Q-Range input mode.*/ - protected double minQ; - - /** The min value for the 'from' property in the free Q-Range input mode.*/ - protected double minQFree; - - /** The min value for the 'from' property in the free W-Range input mode.*/ - protected double minWFree; - - /** The max values for the 'from' property in the W-Range input mode.*/ - protected double maxW; - - /** The max values for the 'from' property in the Q-Range input mode.*/ - protected double maxQ; - - /** The max value for the 'from' property in the free Q-Range input mode.*/ - protected double maxQFree; - - /** The max value for the 'from' property in the free W-Range input mode.*/ - protected double maxWFree; - - /** The 'from' value entered in the range W mode.*/ - protected double fromW; - - /** The 'to' value entered in the range W mode.*/ - protected double toW; - - /** The 'step' value entered in the range W mode.*/ - protected double stepW; - - /** The values entered in the single W mode.*/ - protected double[] valuesW; - - /** The values entered in the single W mode.*/ - protected double[] valuesWFree; - - /** The 'from' value entered in the range Q mode.*/ - protected double fromQ; - - /** The 'from' value entered in the range free Q mode.*/ - protected double fromQFree; - - /** The 'from' value entered in the range free W mode.*/ - protected double fromWFree; - - /** The 'to' value entered in the range Q mode.*/ - protected double toQ; - - /** The 'to' value entered in the range free Q mode.*/ - protected double toQFree; - - /** The 'to' value entered in the range free W mode.*/ - protected double toWFree; - - /** The 'step' value entered in the range Q mode.*/ - protected double stepQ; - - /** The 'step' value entered in the range free Q mode.*/ - protected double stepQFree; - - /** The 'step' value entered in the range free W mode.*/ - protected double stepWFree; - - /** The values entered in the single Q mode.*/ - protected double[] valuesQ; - - /** The values entered in the single free Q mode.*/ - protected double[] valuesQFree; - - /** The input panel for W values*/ - protected DoubleArrayPanel wArrayPanel; - - /** The input panel for q values*/ - protected DoubleArrayPanel qArrayPanel; - - /** The input panel for free q values*/ - protected DoubleArrayPanel qFreeArrayPanel; - - /** The input panel for free w values*/ - protected DoubleArrayPanel wFreeArrayPanel; - - /** The input panel for w range*/ - protected DoubleRangePanel wRangePanel; - - /** The input panel for q range*/ - protected DoubleRangePanel qRangePanel; - - /** The input panel for free q range*/ - protected DoubleRangePanel qFreeRangePanel; - - /** The input panel for free w range*/ - protected DoubleRangePanel wFreeRangePanel; - - protected QDTable qdTable; - - protected WTable wTable; - - protected TabSet tabs; - - /** - * Creates a new WQInputPanel instance. - */ - public WQInputPanel() { - qdTable = new QDTable(); - wTable = new WTable(); - - initTableListeners(); - } - - - /** - * Initializes the listeners of the WQD tables. - */ - protected void initTableListeners() { - CellClickHandler handler = new CellClickHandler() { - @Override - public void onCellClick(CellClickEvent e) { - if (isWMode() || qdTable.isLocked()) { - return; - } - - int idx = e.getColNum(); - Record r = e.getRecord (); - double val = r.getAttributeAsDouble("value"); - - if (idx == 0) { - if (isRangeMode()) { - qRangePanel.setFrom(val); - } - else { - qArrayPanel.addValue(val); - } - } - else if (idx == 1) { - if (isRangeMode()) { - qRangePanel.setTo(val); - } - else { - qArrayPanel.addValue(val); - } - } - } - }; - - qdTable.addCellClickHandler(handler); - } - - - /** - * This method calls createWidget and puts a 'next' button to the bottom. - * - * @param data The data that is displayed. - * - * @return the widget. - */ - @Override - public Canvas create(DataList data) { - initDefaults(data); - - Canvas widget = createWidget(data); - Canvas submit = getNextButton(); - Label label = new Label(MESSAGE.wqTitle()); - - label.setHeight(25); - - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - - layout.addMember(label); - layout.addMember(widget); - layout.addMember(submit); - - initHelperPanel(); - initUserDefaults(data); - - return layout; - } - - - /** Inits the helper panel. */ - // TODO duplicate in WQAdaptedInputPanel - protected void initHelperPanel() { - tabs = new TabSet(); - tabs.setWidth100(); - tabs.setHeight100(); - - Tab wTab = new Tab(MESSAGE.wq_table_w()); - Tab qTab = new Tab(MESSAGE.wq_table_q()); - - qdTable.showSelect(); - wTab.setPane(wTable); - qTab.setPane(qdTable); - - tabs.addTab(wTab, 0); - tabs.addTab(qTab, 1); - - helperContainer.addMember(tabs); - - fetchWQData(); - } - - - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data dMode = getData(items, "wq_isq"); - Data dFree = getData(items, "wq_isfree"); - Data dSelection = getData(items, "wq_isrange"); - Data dSingle = getData(items, "wq_single"); - Data dFrom = getData(items, "wq_from"); - Data dTo = getData(items, "wq_to"); - Data dStep = getData(items, "wq_step"); - - DataItem[] mode = dMode.getItems(); - String strMode = mode[0].getStringValue(); - boolean isQMode = Boolean.valueOf(strMode); - - DataItem[] free = dFree.getItems(); - String strFree = free[0].getStringValue(); - boolean isFree = Boolean.valueOf(strFree); - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - VLayout vLabel = null; - - DataItem[] selItem = dSelection.getItems(); - boolean isRange = selItem != null - ? Boolean.valueOf(selItem[0].getStringValue()) - : false; - - if (!isRange) { - DataItem[] single = dSingle.getItems(); - - vLabel = !isQMode - ? createWString(single[0]) - : createQString(single[0]); - } - else { - DataItem[] from = dFrom.getItems(); - DataItem[] to = dTo.getItems(); - DataItem[] step = dStep.getItems(); - - vLabel = !isQMode - ? createWString(from[0], to[0], step[0]) - : createQString(from[0], to[0], step[0]); - } - - VLayout selectedLayout = new VLayout(); - String wqMode = null; - - if (!isQMode) { - wqMode = isFree ? MESSAGE.wqWFree() : MESSAGE.wqW(); - } - else { - wqMode = isFree ? MESSAGE.wqQ() : MESSAGE.wqQGauge(); - } - - Label mLabel = new Label(wqMode); - mLabel.setWidth(175); - mLabel.setHeight(20); - - selectedLayout.addMember(mLabel); - selectedLayout.addMember(vLabel); - selectedLayout.setHeight(40); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(selectedLayout); - layout.addMember(back); - - return layout; - } - - - /** - * This method reads the default values defined in the DataItems of the Data - * objects in <i>list</i>. - * - * @param list The DataList container that stores the Data objects. - */ - protected void initDefaults(DataList list) { - Data f = getData(list.getAll(), "wq_from"); - Data t = getData(list.getAll(), "wq_to"); - Data s = getData(list.getAll(), "wq_step"); - - DataItem fQItem = getDataItem(f.getItems(), "minQ"); - DataItem fWItem = getDataItem(f.getItems(), "minW"); - DataItem tQItem = getDataItem(t.getItems(), "maxQ"); - DataItem tWItem = getDataItem(t.getItems(), "maxW"); - DataItem sQItem = getDataItem(s.getItems(), "stepQ"); - DataItem sWItem = getDataItem(s.getItems(), "stepW"); - DataItem fQFItem = getDataItem(f.getItems(), "minQFree"); - DataItem tQFItem = getDataItem(t.getItems(), "maxQFree"); - DataItem sQFItem = getDataItem(s.getItems(), "stepQFree"); - DataItem fWFItem = getDataItem(f.getItems(), "minWFree"); - DataItem tWFItem = getDataItem(t.getItems(), "maxWFree"); - DataItem sWFItem = getDataItem(s.getItems(), "stepWFree"); - - minW = Double.valueOf(fWItem.getStringValue()); - maxW = Double.valueOf(tWItem.getStringValue()); - stepW = Double.valueOf(sWItem.getStringValue()); - - minQ = Double.valueOf(fQItem.getStringValue()); - maxQ = Double.valueOf(tQItem.getStringValue()); - stepQ = Double.valueOf(sQItem.getStringValue()); - - minQFree = Double.valueOf(fQFItem.getStringValue()); - maxQFree = Double.valueOf(tQFItem.getStringValue()); - stepQFree = Double.valueOf(sQFItem.getStringValue()); - - minWFree = Double.valueOf(fWFItem.getStringValue()); - maxWFree = Double.valueOf(tWFItem.getStringValue()); - stepWFree = Double.valueOf(sWFItem.getStringValue()); - - this.fromW = minW; - this.toW = maxW; - - this.fromQ = minQ; - this.toQ = maxQ; - - this.fromQFree = minQFree; - this.toQFree = maxQFree; - - this.fromWFree = minWFree; - this.toWFree = maxWFree; - } - - - /** - * Initializes the form items with former inserted user data. - * - * @param list The DataList that contains the user data. - */ - protected void initUserDefaults(DataList list) { - List<Data> allData = list.getAll(); - - Data m = getData(allData, "wq_isq"); - DataItem modeItem = m != null ? m.getDefault() : null; - boolean isQ = modeItem != null - ? Boolean.valueOf(modeItem.getStringValue()) - : false; - - Data f = getData(allData, "wq_isfree"); - DataItem freeItem = f != null ? f.getDefault() : null; - boolean isFree = freeItem != null - ? Boolean.valueOf(freeItem.getStringValue()) - : false; - - Data s = getData(allData, "wq_isrange"); - DataItem sI = s != null ? s.getDefault() : null; - boolean isRange = sI != null - ? Boolean.valueOf(sI.getStringValue()) - : false; - - initUserSingleValues(list, isQ); - initUserRangeValues(list, isQ); - - if (isQ) { - modes.setValue(FIELD_WQ, isQ); - } - else { - modes.setValue(FIELD_WQ, isFree ? FIELD_WQ_Q_FREE : FIELD_WQ_Q); - } - - if(isRange) { - modes.setValue(FIELD_MODE, FIELD_MODE_RANGE); - } - else { - modes.setValue(FIELD_MODE, FIELD_MODE_SINGLE); - } - updatePanels(isQ, isFree, isRange); - } - - - /** - * Initializes the single values of W or Q from DataList. - * - * @param list The DataList that contains the 'wq_single' object. - * @param isQ W or Q mode? - */ - protected void initUserSingleValues(DataList list, boolean isQ) { - List<Data> allData = list.getAll(); - - - Data s = getData(allData, "wq_single"); - DataItem i = s != null ? s.getDefault() : null; - GWT.log("init values: " + i.getStringValue()); - - if (i != null) { - String value = i.getStringValue(); - String[] split = value.split(" "); - - int num = split != null ? split.length : 0; - - double[] values = new double[num]; - - for (int j = 0; j < num; j++) { - try { - values[j] = Double.valueOf(split[j]); - } - catch (NumberFormatException nfe) { - // nothing to do - } - } - - if (!isQ) { - setSingleW(values); - } - else { - setSingleQ(values); - } - } - } - - - /** - * Initializes the range values of W or Q from DataList. - * - * @param list The DataList that contains the 'wq_single' object. - * @param isQ W or Q mode? - */ - protected void initUserRangeValues(DataList list, boolean isQ) { - List<Data> allData = list.getAll(); - - // init range mode values - Data f = getData(allData, "wq_from"); - Data t = getData(allData, "wq_to"); - Data s = getData(allData, "wq_step"); - - if (f != null && t != null && s != null) { - DataItem dF = f.getDefault(); - DataItem dT = t.getDefault(); - DataItem dS = s.getDefault(); - - String fS = dF != null ? dF.getStringValue() : null; - String tS = dT != null ? dT.getStringValue() : null; - String sS = dS != null ? dS.getStringValue() : null; - - try { - double from = Double.valueOf(fS); - double to = Double.valueOf(tS); - double step = Double.valueOf(sS); - - if (!isQ) { - setWRangeValues(from, to, step); - } - else { - setQRangeValues(from, to, step); - } - } - catch (NumberFormatException nfe) { - // do nothing - } - } - } - - - protected void setQRangeValues(double f, double t, double s) { - setFromQ(f); - setToQ(t); - setStepQ(s); - } - - - protected void setWRangeValues(double f, double t, double s) { - setFromW(f); - setToW(t); - setStepW(s); - } - - - protected VLayout createWString(DataItem from, DataItem to, DataItem step) { - VLayout v = new VLayout(); - - StringBuilder sb = new StringBuilder(); - sb.append(from.getLabel()); - sb.append(" " + MESSAGE.unitWFrom() + " "); - sb.append(to.getLabel()); - sb.append(" " + MESSAGE.unitWTo() + " "); - sb.append(step.getLabel()); - sb.append(" " + MESSAGE.unitWStep()); - - v.addMember(new Label(sb.toString())); - - return v; - } - - - protected VLayout createWString(DataItem single) { - String label = single.getLabel().trim(); - String[] cols = label.split(";"); - - VLayout v = new VLayout(); - - for (String col: cols) { - Label l = new Label(col + " " + MESSAGE.unitWSingle()); - l.setHeight(20); - - v.addMember(l); - } - - return v; - } - - - protected VLayout createQString(DataItem from, DataItem to, DataItem step) { - VLayout v = new VLayout(); - - StringBuilder sb = new StringBuilder(); - sb.append(from.getLabel()); - sb.append(" " + MESSAGE.unitQFrom() + " "); - sb.append(to.getLabel()); - sb.append(" " + MESSAGE.unitQTo() + " "); - sb.append(step.getLabel()); - sb.append(" " + MESSAGE.unitQStep()); - - v.addMember(new Label(sb.toString())); - - return v; - } - - - protected VLayout createQString(DataItem single) { - String label = single.getLabel().trim(); - String[] cols = label.split(";"); - - VLayout v = new VLayout(); - - for (String col: cols) { - Label l = new Label(col + " " + MESSAGE.unitQSingle()); - l.setHeight(20); - - v.addMember(l); - } - - return v; - } - - - /** - * This method creates the whole widget. There is a panel on the left, that - * allows the user to enter values manually by keyboard. On the right, there - * is a table that allows the user to enter values by mouse click. - * - * @param data The data that is displayed in the table on the right. - * - * @return the widget. - */ - protected Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - container = new HLayout(); - Canvas modeForm = createModePanel(); - - container.setMembersMargin(30); - - // the initial panel is the Single-W panel. - double[] values = getSingleQ(); - qArrayPanel = new DoubleArrayPanel( - MESSAGE.unitQSingle(), values, this); - container.addMember(qArrayPanel); - - layout.addMember(modeForm); - layout.addMember(container); - - return layout; - } - - - /** - * This method creates the mode panel. It contains two radio button panels - * that allows the user to switch the input mode between w/q and - * single/range input. - * - * @return a panel. - */ - protected Canvas createModePanel() { - RadioGroupItem wq = new RadioGroupItem(FIELD_WQ); - wq.setShowTitle(false); - wq.setVertical(true); - wq.setWidth(WIDTH_LEFT_UPPER); - wq.setWrap(false); - - RadioGroupItem mode = new RadioGroupItem(FIELD_MODE); - mode.setShowTitle(false); - mode.setVertical(false); - mode.setWidth(WIDTH_LEFT_LOWER); - - LinkedHashMap wqValues = new LinkedHashMap(); - wqValues.put(FIELD_WQ_W, MESSAGE.wqW()); - wqValues.put(FIELD_WQ_W_FREE, MESSAGE.wqWFree()); - wqValues.put(FIELD_WQ_Q_FREE, MESSAGE.wqQ()); - wqValues.put(FIELD_WQ_Q, MESSAGE.wqQGauge()); - - LinkedHashMap modeValues = new LinkedHashMap(); - modeValues.put(FIELD_MODE_SINGLE, MESSAGE.wqSingle()); - modeValues.put(FIELD_MODE_RANGE, MESSAGE.wqRange()); - - wq.setValueMap(wqValues); - mode.setValueMap(modeValues); - - wq.addChangeHandler(this); - mode.addChangeHandler(this); - - modes = new DynamicForm(); - modes.setFields(wq, mode); - modes.setWidth(WIDTH_LEFT_UPPER); - modes.setNumCols(1); - - LinkedHashMap initial = new LinkedHashMap(); - initial.put(FIELD_WQ, FIELD_WQ_Q); - initial.put(FIELD_MODE, FIELD_MODE_SINGLE); - modes.setValues(initial); - - return modes; - } - - - @Override - public List<String> validate() { - if (isRangeMode()) { - return validateRangeValues(); - } - else { - return validateSingleValues(); - } - } - - - protected List<String> validateRangeValues() { - if (isWFree()) { - return validateRange(wFreeRangePanel, minWFree, maxWFree); - } - else if (isQFree()) { - return validateRange(qFreeRangePanel, minQFree, maxQFree); - } - else if (isWMode()) { - return validateRange(wRangePanel, minW, maxW); - } - else { - return validateRange(qRangePanel, minQ, maxQ); - } - } - - protected List<String> validateSingleValues() { - if (isWFree()) { - return validateSingle(wFreeArrayPanel, minWFree, maxWFree); - } - else if (isWMode()) { - return validateSingle(wArrayPanel, minW, maxW); - //return validateSingle(wArrayPanel, 0, 100000); - } - else if (isQFree()) { - return validateSingle(qFreeArrayPanel, minQFree, maxQFree); - } - else { - return validateSingle(qArrayPanel, minQ, maxQ); - } - } - - - protected List<String> validateRange( - DoubleRangePanel panel, - double min, double max) - { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - if (!panel.validateForm()) { - errors.add(MESSAGE.wrongFormat()); - } - - double from; - double to; - double step; - - try { - from = panel.getFrom(); - to = panel.getTo(); - step = panel.getStep(); - } - catch (NullPointerException npe) { - errors.add(MESSAGE.missingInput()); - return errors; - } - - if (from < min || from > max) { - String tmp = MESSAGE.error_validate_lower_range(); - tmp = tmp.replace("$1", nf.format(from)); - tmp = tmp.replace("$2", nf.format(min)); - errors.add(tmp); - from = min; - } - - if (to < min || to > max) { - String tmp = MESSAGE.error_validate_upper_range(); - tmp = tmp.replace("$1", nf.format(to)); - tmp = tmp.replace("$2", nf.format(max)); - errors.add(tmp); - to = max; - } - - if (!errors.isEmpty()) { - panel.setValues(from, to, step); - } - - return errors; - } - - - protected List<String> validateSingle( - DoubleArrayPanel panel, - double min, double max) - { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - if (!panel.validateForm()) { - errors.add(MESSAGE.wrongFormat()); - } - - double[] values = panel.getInputValues(); - - if (values == null || values.length == 0) { - errors.add(MESSAGE.atLeastOneValue()); - return errors; - } - - double[] good = new double[values.length]; - int idx = 0; - - for (double value: values) { - if (value < min || value > max) { - String tmp = MESSAGE.error_validate_range(); - tmp = tmp.replace("$1", nf.format(value)); - tmp = tmp.replace("$2", nf.format(min)); - tmp = tmp.replace("$3", nf.format(max)); - errors.add(tmp); - } - else { - good[idx++] = value; - } - } - - double[] justGood = new double[idx]; - for (int i = 0; i < justGood.length; i++) { - justGood[i] = good[i]; - } - - if (!errors.isEmpty()) { - panel.setValues(justGood); - } - - return errors; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - // XXX If we have entered a value and click right afterwards on the - // 'next' button, the BlurEvent is not fired, and the values are not - // saved. So, we gonna save those values explicitly. - if (!isRangeMode()) { - Canvas member = container.getMember(0); - if (member instanceof DoubleArrayPanel) { - DoubleArrayPanel form = (DoubleArrayPanel) member; - if (isWFree()) { - saveSingleWFreeValues(form); - } - else if (isWMode()) { - saveSingleWValues(form); - } - else if (isQFree()) { - saveSingleQFreeValues(form); - } - else { - saveSingleQValues(form); - } - } - - return getSingleData(); - } - else { - Canvas member = container.getMember(0); - if (member instanceof DoubleRangePanel) { - DoubleRangePanel form = (DoubleRangePanel) member; - - if (isWFree()) { - saveRangeWFreeValues(form); - } - else if (isWMode()) { - saveRangeWValues(form); - } - else if (isQFree()) { - saveRangeQFreeValues(form); - } - else { - saveRangeQValues(form); - } - } - - return getRangeData(); - } - } - - - /** - * Collects the required data for single mode and resets the data for range - * mode. - */ - protected Data[] getSingleData() { - DataItem from = new DefaultDataItem("wq_from", "wq_from", ""); - DataItem to = new DefaultDataItem("wq_to", "wq_to", ""); - DataItem step = new DefaultDataItem("wq_step", "wq_step", ""); - - return new Data[] { - getDataMode(), - getFree(), - getDataSelectionMode(), - getDataSingle(), - new DefaultData( - "wq_from", - null, - null, - new DataItem[] {from}), - new DefaultData( - "wq_to", - null, - null, - new DataItem[] {to}), - new DefaultData( - "wq_step", - null, - null, - new DataItem[] {step}) }; - } - - - /** - * Collects the required data for range mode and resets the data for single - * mode. - */ - protected Data[] getRangeData() { - DataItem item = new DefaultDataItem("wq_single", "wq_single", ""); - - return new Data[] { - getDataMode(), - getFree(), - getDataSelectionMode(), - getDataFrom(), - getDataTo(), - getDataStep(), - new DefaultData( - "wq_single", - null, - null, - new DataItem[] {item}) }; - } - - - /** - * Returns the Data object for the 'mode' attribute. - * - * @return the Data object for the 'mode' attribute. - */ - protected Data getDataMode() { - String wqMode = modes.getValueAsString(FIELD_WQ); - - String value = null; - if (wqMode.equals(FIELD_WQ_Q_FREE) || wqMode.equals(FIELD_WQ_Q)) { - GWT.log("getData: FIELD_WQ_Q || FIELD_WQ_Q_FREE"); - value = "true"; - } - else { - GWT.log("getData: FIELD_WQ_W || FIELD_WQ_W_FREE"); - value = "false"; - } - - DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value); - return new DefaultData( - "wq_isq", null, null, new DataItem[] { item }); - } - - - /** - * Returns the Q mode. The Q mode can be "true" or "false". True means, the - * calculation is not based on a gauge, false means the calculation should - * be based on a gauge. - * - * @return the Data object for the 'wq_free' attribute. - */ - protected Data getFree() { - String value = ""; - if(!isWMode()) { - value = isQFree() ? "true" : "false"; - } - else { - value = isWFree() ? "true" : "false"; - } - DataItem item = new DefaultDataItem("wq_isfree", "wq_isfree", value); - return new DefaultData( - "wq_isfree", null, null, new DataItem[] { item }); - } - - - /** - * Returns the Data object for the 'mode' attribute. - * - * @return the Data object for the 'mode' attribute. - */ - protected Data getDataSelectionMode() { - String wqSelection = modes.getValueAsString(FIELD_MODE); - - String isRange = "true"; - if (wqSelection.equals(FIELD_MODE_SINGLE)) { - isRange = "false"; - } - DataItem item = new DefaultDataItem( - "wq_isrange", "wq_isrange", isRange); - - return new DefaultData( - "wq_isrange", null, null, new DataItem[] { item }); - } - - - /** - * Returns the data object for the 'single' attribute. - * - * @return the Data object for the 'single' attribute. - */ - protected Data getDataSingle() { - double[] values = getFinalSingle(); - StringBuilder sb = new StringBuilder(); - for (double value: values) { - sb.append(Double.toString(value)); - sb.append(" "); - } - - DataItem item = new DefaultDataItem( - "wq_single", "wq_single", sb.toString()); - - return new DefaultData( - "wq_single", null, null, new DataItem[] { item }); - } - - - /** - * Returns the Data object for the 'from' attribute. - * - * @return the Data object for the 'from' attribute. - */ - protected Data getDataFrom() { - String value = Double.valueOf(getFinalFrom()).toString(); - DataItem item = new DefaultDataItem("wq_from", "wq_from", value); - return new DefaultData( - "wq_from", null, null, new DataItem[] { item }); - } - - - /** - * Returns the Data object for the 'to' attribute. - * - * @return the Data object for the 'to' attribute. - */ - protected Data getDataTo() { - String value = Double.valueOf(getFinalTo()).toString(); - DataItem item = new DefaultDataItem("wq_to", "wq_to", value); - return new DefaultData( - "wq_to", null, null, new DataItem[] { item }); - } - - - /** - * Returns the Data object for the 'step' attribute. - * - * @return the Data object for the 'step' attribute. - */ - protected Data getDataStep() { - String value = Double.valueOf(getFinalStep()).toString(); - DataItem item = new DefaultDataItem("wq_step","wq_step", value); - return new DefaultData( - "wq_step", null, null, new DataItem[] { item }); - } - - - protected double[] getFinalSingle() { - if (isWFree()) { - return getSingleWFree(); - } - else if (isWMode()) { - return getSingleW(); - } - else if (isQFree()) { - return getSingleQFree(); - } - else { - return getSingleQ(); - } - } - - - /** - * Returns the value of 'from' depending on the selected input mode. - * - * @return the value of 'from' depending on the selected input mode. - */ - protected double getFinalFrom() { - if (isRangeMode()) { - if (isWFree()) { - return getFromWFree(); - } - else if (isWMode()) { - return getFromW(); - } - else if (isQFree()) { - return getFromQFree(); - } - else { - return getFromQ(); - } - } - else { - double[] values = null; - - if (isWFree()) { - values = getSingleWFree(); - } - else if (isWMode()) { - values = getSingleW(); - } - else if (isQFree()) { - values = getSingleQFree(); - } - else { - values = getSingleQ(); - } - - double value = Double.MAX_VALUE; - for (double v: values) { - value = value < v ? value : v; - } - - return value; - } - } - - - /** - * Returns the value of 'to' depending on the selected input mode. - * - * @return the value of 'to' depending on the selected input mode. - */ - protected double getFinalTo() { - if (isRangeMode()) { - if (isWFree()) { - return getToWFree(); - } - else if (isWMode()) { - return getToW(); - } - else if (isQFree()) { - return getToQFree(); - } - else { - return getToQ(); - } - } - else { - double[] values = null; - - if (isWFree()) { - values = getSingleWFree(); - } - else if (isWMode()) { - values = getSingleW(); - } - else if (isQFree()) { - values = getSingleQFree(); - } - else { - values = getSingleQ(); - } - - double value = Double.MIN_VALUE; - for (double v: values) { - value = value > v ? value : v; - } - - return value; - } - } - - - /** - * Returns the value of 'step' depending on the selected input mode. - * - * @return the value of 'step' depending on the selected input mode. - */ - protected double getFinalStep() { - if (isRangeMode()) { - if (isWFree()) { - return getStepWFree(); - } - else if (isWMode()) { - return getStepW(); - } - else if (isQFree()) { - return getStepQFree(); - } - else { - return getStepQ(); - } - } - else { - // we have no field to enter the 'step' attribute in the - // single mode - return 0d; - } - } - - - /** - * Determines the range/single mode. - * - * @return true if the range mode is activated. - */ - public boolean isRangeMode() { - String rMode = modes.getValueAsString(FIELD_MODE); - - return rMode.equals(FIELD_MODE_RANGE); - } - - - /** - * Determines the w/q mode. - * - * @return true, if the W mode is activated. - */ - public boolean isWMode() { - String wq = modes.getValueAsString(FIELD_WQ); - return wq.contains("W"); - } - - - public boolean isQFree() { - String wqMode = modes.getValueAsString(FIELD_WQ); - return wqMode.equals(FIELD_WQ_Q_FREE); - } - - protected boolean isWFree() { - String wqMode = modes.getValueAsString(FIELD_WQ); - return wqMode.equals(FIELD_WQ_W_FREE); - } - - - /** - * This method changes the lower panel with the input fields depending on - * the combination of the two radio button panels. - * - * @param event The ChangeEvent. - */ - @Override - public void onChange(ChangeEvent event) { - DynamicForm form = event.getForm(); - FormItem item = event.getItem(); - - boolean isQ = false; - boolean isFree = false; - boolean isRange = false; - - if (item.getFieldName().equals(FIELD_MODE)) { - String wq = form.getValueAsString(FIELD_WQ); - isQ = wq.contains("Q"); - isFree = wq.contains("FREE"); - isRange = ((String) event.getValue()).equals(FIELD_MODE_RANGE); - } - else { - String wq = ((String) event.getValue()); - isQ = wq.contains("Q"); - isFree = wq.contains("FREE"); - isRange = - form.getValueAsString(FIELD_MODE).equals(FIELD_MODE_RANGE); - } - - if (isQ && isFree) { - qdTable.hideIconFields(); - } - else { - qdTable.showIconFields(); - } - - if (!isRange) { - qdTable.showSelect(); - } - else { - qdTable.showIconFields(); - } - - updatePanels(isQ, isFree, isRange); - } - - - protected void updatePanels(boolean isQ, boolean isFree, boolean isRange) { - container.removeMembers(container.getMembers()); - - if (!isQ && isFree) { - if (!isRange) { - // Single W mode - double[] values = getSingleWFree(); - - wFreeArrayPanel = new DoubleArrayPanel( - MESSAGE.unitWSingle(), values, this); - - container.addMember(wFreeArrayPanel); - } - else { - // Range W mode - double from = getFromWFree(); - double to = getToWFree(); - double step = getStepWFree(); - - wFreeRangePanel = new DoubleRangePanel( - MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), - from, to, step, - 250, - this); - container.addMember(wFreeRangePanel); - } - - tabs.selectTab(0); - } - else if (!isQ) { - if (!isRange) { - // Single W mode - double[] values = getSingleW(); - - wArrayPanel = new DoubleArrayPanel( - MESSAGE.unitWSingle(), values, this); - - container.addMember(wArrayPanel); - } - else { - // Range W mode - double from = getFromW(); - double to = getToW(); - double step = getStepW(); - - wRangePanel = new DoubleRangePanel( - MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), - from, to, step, - 250, - this); - container.addMember(wRangePanel); - } - - tabs.selectTab(0); - } - else if (isQ && isFree) { - if (!isRange) { - // Single Q mode - double[] values = getSingleQFree(); - - qFreeArrayPanel = new DoubleArrayPanel( - MESSAGE.unitQSingle(), values, this); - container.addMember(qFreeArrayPanel); - } - else { - // Range Q mode - double from = getFromQFree(); - double to = getToQFree(); - double step = getStepQFree(); - - qFreeRangePanel = new DoubleRangePanel( - MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), - from, to, step, - 250, - this); - container.addMember(qFreeRangePanel); - } - - tabs.selectTab(1); - } - else { - if (!isRange) { - // Single Q mode - double[] values = getSingleQ(); - - qArrayPanel = new DoubleArrayPanel( - MESSAGE.unitQSingle(), values, this); - container.addMember(qArrayPanel); - } - else { - // Range Q mode - double from = getFromQ(); - double to = getToQ(); - double step = getStepQ(); - - qRangePanel = new DoubleRangePanel( - MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), - from, to, step, - 250, - this); - container.addMember(qRangePanel); - } - - tabs.selectTab(1); - } - } - - /** - * This method is called if the value of one of the input fields might have - * changed. The entered values are validated and stored. - * - * @param event The BlurEvent. - */ - @Override - public void onBlur(BlurEvent event) { - DynamicForm form = event.getForm(); - FormItem item = event.getItem(); - - String wqMode = (String) modes.getValue(FIELD_WQ); - String inputMode = (String) modes.getValue(FIELD_MODE); - - if (wqMode.equals(FIELD_WQ_W)) { - if (inputMode.equals(FIELD_MODE_SINGLE)) { - DoubleArrayPanel p = (DoubleArrayPanel) form; - saveSingleWValue(p, item); - } - else { - DoubleRangePanel p = (DoubleRangePanel) form; - saveRangeWValue(p, item); - } - } - else if (wqMode.equals(FIELD_WQ_W_FREE)) { - if (inputMode.equals(FIELD_MODE_SINGLE)) { - DoubleArrayPanel p = (DoubleArrayPanel) form; - saveSingleWFreeValue(p, item); - } - else { - DoubleRangePanel p = (DoubleRangePanel) form; - saveRangeWFreeValue(p, item); - } - } - else if (wqMode.equals(FIELD_WQ_Q_FREE)) { - if (inputMode.equals(FIELD_MODE_SINGLE)) { - DoubleArrayPanel p = (DoubleArrayPanel) form; - saveSingleQFreeValue(p, item); - } - else { - DoubleRangePanel p = (DoubleRangePanel) form; - saveRangeQFreeValue(p, item); - } - } - else { - if (inputMode.equals(FIELD_MODE_SINGLE)) { - DoubleArrayPanel p = (DoubleArrayPanel) form; - saveSingleQValue(p, item); - } - else { - DoubleRangePanel p = (DoubleRangePanel) form; - saveRangeQValue(p, item); - } - } - } - - - protected void saveSingleWValues(DoubleArrayPanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { - saveSingleWValue(p, item); - } - } - } - - - protected void saveSingleWFreeValues(DoubleArrayPanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { - saveSingleWFreeValue(p, item); - } - } - } - - - protected void saveSingleQValues(DoubleArrayPanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { - saveSingleQValue(p, item); - } - } - } - - - protected void saveSingleQFreeValues(DoubleArrayPanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { - saveSingleQFreeValue(p, item); - } - } - } - - - protected void saveSingleWValue(DoubleArrayPanel p, FormItem item) { - if (p.validateForm(item)) { - setSingleW(p.getInputValues(item)); - } - } - - - protected void saveSingleWFreeValue(DoubleArrayPanel p, FormItem item) { - if (p.validateForm(item)) { - setSingleWFree(p.getInputValues(item)); - } - } - - - protected void saveSingleQValue(DoubleArrayPanel p, FormItem item) { - if (p.validateForm(item)) { - setSingleQ(p.getInputValues(item)); - } - } - - - protected void saveSingleQFreeValue(DoubleArrayPanel p, FormItem item) { - if (p.validateForm(item)) { - setSingleQFree(p.getInputValues(item)); - } - } - - - protected void saveRangeWValues(DoubleRangePanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - saveRangeWValue(p, item); - } - } - - - protected void saveRangeWFreeValues(DoubleRangePanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - saveRangeWFreeValue(p, item); - } - } - - - protected void saveRangeQValues(DoubleRangePanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - saveRangeQValue(p, item); - } - } - - - protected void saveRangeQFreeValues(DoubleRangePanel p) { - FormItem[] formItems = p.getFields(); - - for (FormItem item: formItems) { - saveRangeQFreeValue(p, item); - } - } - - - protected void saveRangeWValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm()) { - setFromW(p.getFrom()); - setToW(p.getTo()); - setStepW(p.getStep()); - } - } - - - protected void saveRangeWFreeValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm()) { - setFromWFree(p.getFrom()); - setToWFree(p.getTo()); - setStepWFree(p.getStep()); - } - } - - - protected void saveRangeQValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm()) { - setFromQ(p.getFrom()); - setToQ(p.getTo()); - setStepQ(p.getStep()); - } - } - - - protected void saveRangeQFreeValue(DoubleRangePanel p, FormItem item) { - if (p.validateForm()) { - setFromQFree(p.getFrom()); - setToQFree(p.getTo()); - setStepQFree(p.getStep()); - } - } - - - protected double[] getSingleQ() { - return valuesQ; - } - - - protected double[] getSingleQFree() { - return valuesQFree; - } - - - protected void setSingleQ(double[] values) { - valuesQ = values; - } - - - protected void setSingleQFree(double[] values) { - valuesQFree = values; - } - - - protected double getFromQ() { - return fromQ; - } - - - protected double getFromQFree() { - return fromQFree; - } - - - protected void setFromQ(double fromQ) { - this.fromQ = fromQ; - } - - - protected void setFromQFree(double fromQ) { - this.fromQFree = fromQ; - } - - - protected double getToQ() { - return toQ; - } - - - protected double getToQFree() { - return toQFree; - } - - - protected void setToQ(double toQ) { - this.toQ = toQ; - } - - - protected void setToQFree(double toQ) { - this.toQFree = toQ; - } - - - protected double getStepQ() { - return stepQ; - } - - - protected double getStepQFree() { - return stepQFree; - } - - - protected void setStepQ(double stepQ) { - this.stepQ = stepQ; - } - - - protected void setStepQFree(double stepQ) { - this.stepQFree = stepQ; - } - - protected double[] getSingleW() { - return valuesW; - } - - protected double[] getSingleWFree() { - return valuesWFree; - } - - protected void setSingleW(double[] values) { - valuesW = values; - } - - protected void setSingleWFree(double[] values) { - valuesWFree = values; - } - - protected double getFromW() { - return fromW; - } - - protected double getFromWFree() { - return fromWFree; - } - - protected void setFromW(double fromW) { - this.fromW = fromW; - } - - protected void setFromWFree(double fromW) { - this.fromW = fromW; - } - - protected double getToW() { - return toW; - } - - protected double getToWFree() { - return toWFree; - } - - protected void setToW(double toW) { - this.toW = toW; - } - - protected void setToWFree(double toW) { - this.toWFree = toW; - } - - protected double getStepW() { - return stepW; - } - - protected double getStepWFree() { - return stepWFree; - } - - protected void setStepW(double stepW) { - this.stepW = stepW; - } - - protected void setStepWFree(double stepW) { - this.stepWFree = stepW; - } - - /** - * Determines the min and max kilometer value selected in a former state. A - * bit silly, but we need to run over each value of the "old data" to find - * such values because it is not available here. - * - * @param data The DataList which contains the whole data inserted for the - * current artifact. - * - * @return a double array with [min, max]. - */ - protected double[] getMinMaxKM(DataList[] data) { - ArtifactDescription adesc = artifact.getArtifactDescription(); - return adesc.getKMRange(); - } - - - /** - * Returns the name of the selected river. - * - * @param data The DataList with all data. - * - * @return the name of the current river. - */ - protected String getRiverName() { - ArtifactDescription adesc = artifact.getArtifactDescription(); - return adesc.getRiver(); - } - - - protected void fetchWQData() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - double[] mm = getMinMaxKM(data); - String river = getRiverName(); - - wqInfoService.getWQInfo(locale, river, mm[0], mm[1], - new AsyncCallback<WQInfoObject[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve wq informations."); - SC.warn(caught.getMessage()); - } - - @Override - public void onSuccess(WQInfoObject[] wqi) { - int num = wqi != null ? wqi.length :0; - GWT.log("Recieved " + num + " wq informations."); - - if (num == 0) { - return; - } - - addWQInfo(wqi); - - String wq = (String) modes.getValue(FIELD_WQ); - String sr = (String) modes.getValue(FIELD_MODE); - GWT.log("sending: " + wq + ", " + sr); - boolean isQ = wq.contains("Q"); - boolean isFree = wq.contains("FREE"); - boolean isRange = sr.equals(FIELD_MODE_RANGE); - - updatePanels(isQ, isFree, isRange); - } - } - ); - } - - - protected void addWQInfo (WQInfoObject[] wqi) { - for(WQInfoObject wi: wqi) { - WQInfoRecord rec = new WQInfoRecord(wi); - - if (wi.getType().equals("W")) { - wTable.addData(rec); - } - else { - qdTable.addData(rec); - } - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,497 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.RadioGroupItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.GaugeInfoService; -import de.intevation.flys.client.client.services.GaugeInfoServiceAsync; -import de.intevation.flys.client.client.services.WQInfoService; -import de.intevation.flys.client.client.services.WQInfoServiceAsync; -import de.intevation.flys.client.client.ui.wq.ClickableQDTable; -import de.intevation.flys.client.client.ui.wq.ClickableWTable; -import de.intevation.flys.client.client.ui.wq.ClickableWTable.ClickMode; -import de.intevation.flys.client.client.widgets.DischargeTablesChart; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.DoubleArrayData; -import de.intevation.flys.client.shared.model.Gauge; -import de.intevation.flys.client.shared.model.IntegerOptionsData; -import de.intevation.flys.client.shared.model.WQInfoObject; -import de.intevation.flys.client.shared.model.WQInfoRecord; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - - -/** - * An UIProvider for inserting a mode for W or Q and an array of values for each - * mode. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class WQSimpleArrayPanel -extends AbstractUIProvider -implements BlurHandler -{ - private static final long serialVersionUID = 3223369196267895010L; - - public static final String FIELD_MODE = "field_mode"; - public static final String FIELD_VALUES = "field_values"; - - public static final int MODE_W = 0; - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected GaugeInfoServiceAsync gaugeService = - GWT.create(GaugeInfoService.class); - - protected WQInfoServiceAsync wqInfoService = - GWT.create(WQInfoService.class); - - protected String modeName; - protected String valuesName; - - protected Canvas valuesWrapper; - - protected TabSet tabs; - - protected DynamicForm modeForm; - protected DoubleArrayPanel panelW; - protected DoubleArrayPanel panelQ; - - protected ClickableWTable wTable; - protected ClickableQDTable qTable; - - - @Override - public Canvas create(DataList data) { - VLayout rootLayout = new VLayout(); - rootLayout.addMember(createLabel(data)); - rootLayout.addMember(createModeForm(data)); - rootLayout.addMember(createValuesForm(data)); - rootLayout.addMember(getNextButton()); - - initializeMode(data); - initializeTables(); - initializeHelperPanel(); - - return rootLayout; - } - - - @Override - public Canvas createOld(DataList dataList) { - IntegerOptionsData modeData = findOptionsData(dataList); - DoubleArrayData valuesData = findValuesData(dataList); - - DataItem[] modeItems = modeData.getItems(); - - HLayout layout = new HLayout(); - VLayout valueContainer = new VLayout(); - - Label label = new Label(dataList.getLabel()); - label.setWidth(200); - label.setHeight(20); - - Label mode = new Label(modeItems[0].getLabel()); - mode.setHeight(20); - mode.setWidth(150); - - Canvas values = createOldValues(modeData, valuesData); - values.setWidth(150); - - valueContainer.addMember(mode); - valueContainer.addMember(values); - - layout.addMember(label); - layout.addMember(valueContainer); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - - @Override - protected Data[] getData() { - Data mode = getModeAsData(); - - if (getMode() == MODE_W) { - return new Data[] { mode, getWValuesAsData() }; - } - else { - return new Data[] { mode, getQValuesAsData() }; - } - } - - - @Override - public List<String> validate() { - List<String> errors = new ArrayList<String>(); - - // TODO IMPLEMENT ME - - return errors; - } - - - @Override - public void onBlur(BlurEvent event) { - // TODO TRIGGER VALIDATION HERE - } - - - protected void initializeMode(DataList dataList) { - IntegerOptionsData data = findOptionsData(dataList); - DataItem[] items = data != null ? data.getItems() : null; - - if (items != null) { - String value = items[0].getStringValue(); - modeForm.setValue(modeName, value); - switchMode(value); - } - } - - - /** Initialize the w/q/d tables for the helper area. */ - protected void initializeTables() { - wTable = new ClickableWTable(new ClickableWTable.WClickedListener() { - @Override - public void clickedUpper(double value) { - // nothing to do here - } - - @Override - public void clickedLower(double value) { - panelW.addValue(value); - } - }, ClickMode.SINGLE, true); - - qTable = new ClickableQDTable(new ClickableQDTable.QClickedListener() { - - @Override - public void clickedUpper(double value) { - // nothing to do here - } - - @Override - public void clickedLower(double value) { - panelQ.addValue(value); - } - }, ClickableQDTable.ClickMode.SINGLE); - - fetchWQData(); - } - - - /** Put interactive tables to the helper area. */ - protected void initializeHelperPanel() { - tabs = new TabSet(); - tabs.setWidth100(); - tabs.setHeight100(); - - Tab w = new Tab(MSG.wq_table_w()); - Tab q = new Tab(MSG.wq_table_q()); - Tab c = new Tab(MSG.discharge_tables_chart()); - - w.setPane(wTable); - q.setPane(qTable); - c.setPane(new DischargeTablesChart(this.artifact)); - - tabs.addTab(w, 0); - tabs.addTab(q, 1); - tabs.addTab(c, 2); - - helperContainer.addMember(tabs); - } - - - protected void fetchWQData() { - ArtifactDescription desc = artifact.getArtifactDescription(); - - final String river = desc.getRiver(); - final String refGauge = desc.getReferenceGauge(); - - gaugeService.getGaugeInfo(river, refGauge, new AsyncCallback<List<Gauge>>() { - @Override - public void onFailure(Throwable throwable) { - GWT.log("ERROR WHILE FETCHING GAUGES!"); - } - - @Override - public void onSuccess(List<Gauge> gauges) { - Gauge g = gauges.get(0); - updateWQData(river, g.getLower(), g.getUpper()); - } - }); - } - - - protected void updateWQData(String river, double lower, double upper) { - GWT.log("FETCH WQ INFO FOR " + lower + " - " + upper + " now!"); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - wqInfoService.getWQInfo(locale, river, lower, upper, - new AsyncCallback<WQInfoObject[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve wq informations."); - } - - @Override - public void onSuccess(WQInfoObject[] wqi) { - int num = wqi != null ? wqi.length :0; - GWT.log("Recieved " + num + " wq informations."); - - if (num == 0) { - return; - } - - addWQInfo(wqi); - } - } - ); - } - - - protected void addWQInfo (WQInfoObject[] wqi) { - for(WQInfoObject wi: wqi) { - WQInfoRecord rec = new WQInfoRecord(wi); - - if (wi.getType().equals("W")) { - wTable.addData(rec); - } - else { - qTable.addData(rec); - } - } - } - - - protected Canvas createLabel(DataList dataList) { - Label label = new Label(MSG.wqHistorical()); - label.setWidth100(); - label.setHeight(25); - - return label; - } - - - protected Canvas createOldValues( - IntegerOptionsData modeData, - DoubleArrayData valuesData - ) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - - DataItem[] items = modeData.getItems(); - String unit = items[0].getStringValue().equals("0") ? "cm" : "m³/s"; - - VLayout layout = new VLayout(); - - for (double val: valuesData.getValues()) { - Label tmp = new Label(nf.format(val) + " " + unit); - tmp.setHeight(20); - layout.addMember(tmp); - } - - return layout; - } - - - protected DoubleArrayData findValuesData(DataList dataList) { - for (int i = 0, n = dataList.size(); i < n; i++) { - Data tmp = dataList.get(i); - - if (tmp instanceof DoubleArrayData) { - return (DoubleArrayData) tmp; - } - } - - return null; - } - - - protected IntegerOptionsData findOptionsData(DataList dataList) { - for (int i = 0, n = dataList.size(); i < n; i++) { - Data tmp = dataList.get(i); - - if (tmp instanceof IntegerOptionsData) { - return (IntegerOptionsData) tmp; - } - } - - return null; - } - - - protected Canvas createModeForm(DataList dataList) { - IntegerOptionsData data = findOptionsData(dataList); - DataItem[] opts = data != null ? data.getItems() : null; - - if (data == null || opts == null) { - return new Label("NO MODES FOUND"); - } - - modeName = data.getLabel(); - modeForm = new DynamicForm(); - - RadioGroupItem items = new RadioGroupItem(data.getLabel()); - LinkedHashMap values = new LinkedHashMap(); - - for (DataItem opt: opts) { - values.put(opt.getStringValue(), opt.getLabel()); - } - - items.setValueMap(values); - items.setVertical(false); - items.setShowTitle(false); - items.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent event) { - switchMode((String) event.getValue()); - } - }); - - modeForm.setFields(items); - - return modeForm; - } - - - protected Canvas createValuesForm(DataList dataList) { - DoubleArrayData data = findValuesData(dataList); - - if (data == null) { - return new Label("NO VALUES GIVEN!"); - } - - valuesName = data.getLabel(); - panelW = new DoubleArrayPanel(MSG.unitWSingle(), null, this); - panelQ = new DoubleArrayPanel(MSG.unitQSingle(), null, this); - - valuesWrapper = new Canvas(); - valuesWrapper.setWidth100(); - valuesWrapper.setHeight(35); - - return valuesWrapper; - } - - - public void switchMode(String newMode) { - for (Canvas child: valuesWrapper.getChildren()) { - valuesWrapper.removeChild(child); - } - - if (newMode.equals("0")) { - valuesWrapper.addChild(panelW); - showWTable(); - } - else if (newMode.equals("1")) { - valuesWrapper.addChild(panelQ); - showQDTable(); - } - } - - public void showWTable() { - if (tabs != null) { - tabs.selectTab(0); - } - } - - public void showQDTable() { - if (tabs != null) { - tabs.selectTab(1); - } - } - - - public String getModeAsString() { - return (String) modeForm.getValue(modeName); - } - - - public int getMode() { - String modeValue = getModeAsString(); - - try { - return Integer.valueOf(modeValue); - } - catch (NumberFormatException nfe) { - // do something - } - catch (NullPointerException npe) { - // do something - } - - return -1; - } - - - public Data getModeAsData() { - String value = getModeAsString(); - DataItem item = new DefaultDataItem(value, value, value); - - return new DefaultData(modeName, null, null, new DataItem[] { item }); - } - - - public Data getWValuesAsData() { - double[] values = panelW.getInputValues(); - String valueStr = getStringValue(values); - - DataItem item = new DefaultDataItem(valueStr, valueStr, valueStr); - - return new DefaultData(valuesName, null, null, new DataItem[] { item }); - } - - - public Data getQValuesAsData() { - double[] values = panelQ.getInputValues(); - String valueStr = getStringValue(values); - - DataItem item = new DefaultDataItem(valueStr, valueStr, valueStr); - - return new DefaultData(valuesName, null, null, new DataItem[] { item }); - } - - - protected static String getStringValue(double[] values) { - StringBuilder sb = new StringBuilder(); - boolean first = true; - - for (double value: values) { - if (first) { - sb.append(String.valueOf(value)); - first = false; - } - else { - sb.append(";" + String.valueOf(value)); - } - } - - return sb.toString(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WaterlevelGroundPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -package de.intevation.flys.client.client.ui; - -public class WaterlevelGroundPanel extends DistancePanel { - - private static final long serialVersionUID = 6598703468619862469L; - - public static final String FIELD_LOWER = "diff_from"; - public static final String FIELD_UPPER = "diff_to"; - public static final String FIELD_STEP = "diff_diff"; - - - public WaterlevelGroundPanel() { - super("left"); - } - - - @Override - protected String getLowerField() { - return FIELD_LOWER; - } - - - @Override - protected String getUpperField() { - return FIELD_UPPER; - } - - - @Override - protected String getStepField() { - return FIELD_STEP; - } - - - @Override - protected String getLabel() { - return MSG.waterlevel_ground_state(); - } - - - @Override - protected String labelFrom() { - return getLabelFrom() + " [" + getUnitFrom() + "]"; - } - - - @Override - protected String getLabelFrom() { - return MSG.wgLabelFrom(); - } - - - @Override - protected String getUnitFrom() { - return MSG.wgUnitFrom(); - } - - - @Override - protected String labelTo() { - return getLabelTo() + " [" + getUnitTo() + "]"; - } - - - @Override - protected String getLabelTo() { - return MSG.wgLabelTo(); - } - - - @Override - protected String getUnitTo() { - return MSG.wgUnitTo(); - } - - - @Override - protected String labelStep() { - return getLabelStep() + " [" + getUnitStep() + "]"; - } - - - @Override - protected String getLabelStep() { - return MSG.wgLabelStep(); - } - - - @Override - protected String getUnitStep() { - return MSG.wgUnitStep(); - } - - - @Override - protected double getDefaultFrom() { - return 0; - } - - - @Override - protected double getDefaultTo() { - return 0; - } - - - @Override - protected double getDefaultStep() { - return 0; - } - - - @Override - protected void initHelperPanel() { - // We don't need a helper panel here. But we have to override this - // method to avoid the table creation in the parent class. - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WspDatacagePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.events.ClickEvent; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.StepForwardEvent; -import de.intevation.flys.client.client.services.LoadArtifactService; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.Recommendation.Facet; -import de.intevation.flys.client.shared.model.Recommendation.Filter; -import de.intevation.flys.client.shared.model.ToLoad; -import de.intevation.flys.client.shared.model.User; - -import java.util.List; -import java.util.Map; -import java.util.Set; - - -public class WspDatacagePanel extends DatacagePanel { - - private static final long serialVersionUID = 2494432743877141135L; - - public static final String WATERLEVEL_OUTS = "waterlevels"; - - public static final FLYSConstants MSG = GWT.create(FLYSConstants.class); - - - protected LoadArtifactServiceAsync loadService = - GWT.create(LoadArtifactService.class); - - protected Recommendation recommendation; - protected Artifact artifact; - - - public WspDatacagePanel() { - super(); - } - - - public WspDatacagePanel(User user) { - super(user); - } - - - @Override - public String getOuts() { - return WATERLEVEL_OUTS; - } - - - @Override - protected void createWidget() { - super.createWidget(); - widget.setIsMutliSelectable(false); - } - - - /** - * We need to override this method (defined in AbstractUIProvider) because - * we have to create a new Artifact specified by the Datacage selection via - * Async request. - * - * @param e The ClickEvent. - */ - @Override - public void onClick(ClickEvent e) { - List<String> errors = validate(); - if (errors == null || errors.isEmpty()) { - // 1) Fetch selected recommendation - Config config = Config.getInstance(); - final String locale = config.getLocale(); - final Collection c = this.collection; - final Recommendation r = getSelectedRecommendation(); - - - if (r == null) { - SC.warn(MSG.warning_no_wsp_selected()); - return; - } - - // 2) Create, load Artifact and fire event - loadService.load( - c, r, "winfo", locale, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("WspDatacagePanel", caught); - SC.warn(FLYS.getExceptionString(MSG, caught)); - } - - @Override - public void onSuccess(Artifact artifact) { - fireStepForwardEvent(new StepForwardEvent( - getData(r, artifact))); - } - } - ); - } - else { - showErrors(errors); - } - } - - - protected Recommendation getSelectedRecommendation() { - ToLoad toLoad = widget.getSelection(); - List<Recommendation> recoms = toLoad.toRecommendations(); - - return recoms.size() > 0 ? recoms.get(0) : null; - } - - - /** - * Nothing is done in this method. It returns null, because we serve the - * Data another way! - * - * @return always null! - */ - @Override - protected Data[] getData() { - // do nothing here, the Data is fetched on another way in this panel. - return null; - } - - - protected Data[] getData(Recommendation r, Artifact newArtifact) { - String uuid = newArtifact.getUuid(); - r.setMasterArtifact(uuid); - - String value = createDataString(uuid, r.getFilter()); - - DataItem item = new DefaultDataItem(dataName, dataName, value); - return new Data[] { new DefaultData( - dataName, null, null, new DataItem[] { item }) }; - } - - - protected String createDataString(String artifact, Filter filter) { - Facet f = null; - - Map<String, List<Facet>> outs = filter.getOuts(); - Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); - - for (Map.Entry<String, List<Facet>> entry: entries) { - List<Facet> fs = entry.getValue(); - - f = fs.get(0); - if (f != null) { - break; - } - } - - return "[" + artifact + ";" + f.getName() + ";" + f.getIndex() + "]"; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,762 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.smartgwt.client.types.Overflow; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.event.OutputParameterChangeEvent; -import de.intevation.flys.client.client.event.OutputParameterChangeHandler; -import de.intevation.flys.client.client.event.PanEvent; -import de.intevation.flys.client.client.event.PanHandler; -import de.intevation.flys.client.client.event.RedrawRequestEvent; -import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.client.event.ZoomEvent; -import de.intevation.flys.client.client.event.ZoomHandler; -import de.intevation.flys.client.client.services.ChartInfoService; -import de.intevation.flys.client.client.services.ChartInfoServiceAsync; -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.OutputTab; -import de.intevation.flys.client.shared.Transform2D; -import de.intevation.flys.client.shared.model.Axis; -import de.intevation.flys.client.shared.model.ChartInfo; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.ZoomObj; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; - - -/** - * Tab representing and showing one Chart-output (diagram). - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ChartOutputTab -extends OutputTab -implements ResizedHandler, - OutputParameterChangeHandler, - ZoomHandler, - PanHandler, - RedrawRequestHandler -{ - public static final int DEFAULT_CHART_WIDTH = 600; - public static final int DEFAULT_CHART_HEIGHT = 500; - - public static final int THEMEPANEL_MIN_WIDTH = 250; - - /** The service that is used to fetch chart information. */ - protected ChartInfoServiceAsync info = GWT.create(ChartInfoService.class); - - /** The ChartInfo object that provides information about the current - * chart. */ - protected ChartInfo chartInfo; - - /** Transformer used to transform image pixels into chart (data) coordinates. */ - protected Transform2D[] transformer; - - /** The collection view.*/ - protected CollectionView view; - - /** The ThemePanel to expose control over themes (facettes). */ - protected ChartThemePanel ctp; - - /** The canvas that wraps the chart toolbar. */ - protected ChartToolbar tbarPanel; - - /** The canvas that wraps the theme editor. */ - protected Canvas left; - - /** The canvas that wraps the chart. */ - protected Canvas right; - - protected Img chart; - - /** Chart zoom options. */ - protected int[] xrange; - protected int[] yrange; - - /** Stack of ZoomObj to allow 'redo last zoom'-kind of actions. */ - protected Stack<ZoomObj> zoomStack; - protected Number[] zoom; - - - /** - * The default constructor to create a new ChartOutputTab. - * - * @param title The title of this tab. - * @param collection The Collection which this chart belongs to. - * @param mode The OutputMode. - * @param collectionView The shown collection. - */ - public ChartOutputTab( - String title, - Collection collection, - OutputMode mode, - CollectionView collectionView - ){ - super(title, collection, collectionView, mode); - - view = collectionView; - left = new Canvas(); - right = new Canvas(); - xrange = new int[2]; - yrange = new int[2]; - zoomStack = new Stack<ZoomObj>(); - - zoom = new Number[] { - new Double(0), new Double(1), - new Double(0), new Double(1) }; - - left.setBorder("1px solid gray"); - left.setWidth(THEMEPANEL_MIN_WIDTH); - left.setMinWidth(THEMEPANEL_MIN_WIDTH); - right.setWidth("*"); - - VLayout vLayout = new VLayout(); - vLayout.setMembersMargin(2); - - HLayout hLayout = new HLayout(); - hLayout.setWidth100(); - hLayout.setHeight100(); - hLayout.setMembersMargin(10); - - hLayout.addMember(left); - hLayout.addMember(right); - - ctp = createThemePanel(mode, collectionView); - if (ctp != null) { - ctp.addRedrawRequestHandler(this); - ctp.addOutputParameterChangeHandler(this); - left.addChild(ctp); - } - else { - left.setVisible(false); - } - - chart = createChartImg(); - right.addChild(chart); - right.setOverflow(Overflow.HIDDEN); - - left.setShowResizeBar(true); - - tbarPanel = createChartToolbar(this); - vLayout.addMember(tbarPanel); - vLayout.addMember(hLayout); - vLayout.setOverflow(Overflow.HIDDEN); - - setPane(vLayout); - - right.addResizedHandler(this); - } - - - public ChartThemePanel createThemePanel( - OutputMode mode, CollectionView view - ) { - // Output "cross_section" needs slightly modified ThemePanel - // (with action buttons). - if (mode.getName().equals("cross_section")) { - return new CrossSectionChartThemePanel(mode, view); - } - else { - return new ChartThemePanel(mode, view); - } - } - - - public ChartToolbar createChartToolbar(ChartOutputTab tab) { - return new ChartToolbar(tab); - } - - - public void toggleThemePanel() { - this.left.setVisible(!left.isVisible()); - } - - - /** - * This method is called after the chart panel has resized. It removes the - * chart - if existing - and requests a new one with adjusted size. - * - * @param event The resize event. - */ - @Override - public void onResized(ResizedEvent event) { - updateChartPanel(); - updateChartInfo(); - } - - - /** For RESET type of events, just reset the ranges, otherwise do a - * complete refresh of panel, info and collection. */ - @Override - public void onRedrawRequest(RedrawRequestEvent event) { - if (event.getType() == Type.RESET) { - resetRanges(); - } - else { - ctp.updateCollection(); - updateChartPanel(); - updateChartInfo(); - } - } - - - /** - * Listens to change event in the chart them panel and updates chart after - * receiving such an event. - * - * @param event The OutputParameterChangeEvent. - */ - @Override - public void onOutputParameterChanged(OutputParameterChangeEvent event) { - updateChartInfo(); - updateChartPanel(); - } - - - /** - * Listens to zoom events and refreshes the current chart in such case. - * - * @param evt The ZoomEvent that stores the coordinates for zooming. - */ - @Override - public void onZoom(ZoomEvent evt) { - zoomStack.push(new ZoomObj(zoom[0], zoom[1], zoom[2], zoom[3])); - - xrange[0] = evt.getStartX(); - xrange[1] = evt.getEndX(); - yrange[0] = evt.getStartY(); - yrange[1] = evt.getEndY(); - - xrange[0] = xrange[0] < xrange[1] ? xrange[0] : xrange[1]; - yrange[0] = yrange[0] < yrange[1] ? yrange[0] : yrange[1]; - - translateCoordinates(); - - updateChartInfo(); - updateChartPanel(); - } - - - protected Number[] translateCoordinates() { - if (xrange == null || (xrange[0] == 0 && xrange[1] == 0)) { - zoom[0] = 0d; - zoom[1] = 1d; - } - else { - translateXCoordinates(); - } - - if (yrange == null || (yrange[0] == 0 && yrange[1] == 0)) { - zoom[2] = 0d; - zoom[3] = 1d; - } - else { - translateYCoordinates(); - } - - return zoom; - } - - - protected void translateXCoordinates() { - Axis xAxis = chartInfo.getXAxis(0); - - Number xmin = xAxis.getMin(); - Number xmax = xAxis.getMax(); - Number xRange = subtract(xmax, xmin); - - Transform2D transformer = getTransformer(0); - - double[] start = transformer.transform(xrange[0], yrange[0]); - double[] end = transformer.transform(xrange[1], yrange[1]); - - zoom[0] = divide(subtract(start[0], xmin), xRange); - zoom[1] = divide(subtract(end[0], xmin), xRange); - } - - - protected void translateYCoordinates() { - Axis yAxis = chartInfo.getYAxis(0); - - Number ymin = yAxis.getMin(); - Number ymax = yAxis.getMax(); - Number yRange = subtract(ymax, ymin); - - Transform2D transformer = getTransformer(0); - - double[] start = transformer.transform(xrange[0], yrange[0]); - double[] end = transformer.transform(xrange[1], yrange[1]); - - zoom[2] = divide(subtract(start[1], ymin), yRange); - zoom[3] = divide(subtract(end[1], ymin), yRange); - } - - - @Override - public void onPan(PanEvent event) { - if (chartInfo == null) { - return; - } - - int[] start = event.getStartPos(); - int[] end = event.getEndPos(); - - Transform2D t = getTransformer(); - - double[] ts = t.transform(start[0], start[1]); - double[] tt = t.transform(end[0], end[1]); - - double diffX = ts[0] - tt[0]; - double diffY = ts[1] - tt[1]; - - Axis xAxis = chartInfo.getXAxis(0); - Axis yAxis = chartInfo.getYAxis(0); - - Number[] x = panAxis(xAxis, diffX); - Number[] y = panAxis(yAxis, diffY); - - // Set the zoom coordinates. - zoom[0] = x[0]; - zoom[1] = x[1]; - zoom[2] = y[0]; - zoom[3] = y[1]; - - updateChartInfo(); - updateChartPanel(); - } - - - protected Number[] panAxis(Axis axis, double diff) { - Number min = axis.getFrom(); - Number max = axis.getTo(); - - min = add(min, diff); - max = add(max, diff); - - return computeZoom(axis, min, max); - } - - - public void resetRanges() { - zoomStack.push(new ZoomObj(zoom[0], zoom[1], zoom[2], zoom[3])); - - zoom[0] = 0d; - zoom[1] = 1d; - zoom[2] = 0d; - zoom[3] = 1d; - - updateChartInfo(); - updateChartPanel(); - } - - - /** - * This method zooms the current chart out by a given <i>factor</i>. - * - * @param factor The factor should be between 0-100. - */ - public void zoomOut(int factor) { - if (factor < 0 || factor > 100 || chartInfo == null) { - return; - } - - zoomStack.push(new ZoomObj(zoom[0], zoom[1], zoom[2], zoom[3])); - - Axis xAxis = chartInfo.getXAxis(0); - Axis yAxis = chartInfo.getYAxis(0); - - Number[] x = zoomAxis(xAxis, factor); - Number[] y = zoomAxis(yAxis, factor); - - zoom[0] = x[0]; - zoom[1] = x[1]; - zoom[2] = y[0]; - zoom[3] = y[1]; - - updateChartInfo(); - updateChartPanel(); - } - - - /** - * This method is used to zoom out. Zooming out is realized with a stacked - * logic. Initially, you cannot zoom out. For each time you start a zoom-in - * action, the extent of the chart is stored and pushed onto a stack. A - * zoom-out will now lead you to the last extent that is popped from stack. - */ - public void zoomOut() { - if (!zoomStack.empty()) { - zoom = zoomStack.pop().getZoom(); - - updateChartInfo(); - updateChartPanel(); - } - } - - - public Number[] zoomAxis(Axis axis, int factor) { - GWT.log("Prepare Axis for zooming (factor: " + factor + ")"); - - Number min = axis.getMin(); - Number max = axis.getMax(); - Number range = isBigger(max, min) ? subtract(max, min) : subtract(min, max); - - Number curFrom = axis.getFrom(); - Number curTo = axis.getTo(); - - Number diff = isBigger(curTo, curFrom) - ? subtract(curTo, curFrom) - : subtract(curFrom, curTo); - - GWT.log(" max from : " + min); - GWT.log(" max to : " + max); - GWT.log(" max range : " + range); - GWT.log(" current from: " + curFrom); - GWT.log(" current to : " + curTo); - GWT.log(" current diff: " + diff); - - Number newFrom = subtract(curFrom, divide(multi(diff, factor), 100)); - Number newTo = add(curTo, divide(multi(diff, factor), 100)); - - GWT.log(" new from: " + newFrom); - GWT.log(" new to : " + newTo); - - return new Number[] { - divide(subtract(newFrom, min), range), - divide(subtract(newTo, min), range) - }; - } - - - public static Number[] computeZoom(Axis axis, Number min, Number max) { - Number[] hereZoom = new Number[2]; - - Number absMin = axis.getMin(); - Number absMax = axis.getMax(); - Number diff = isBigger(absMax, absMin) - ? subtract(absMax, absMin) - : subtract(absMin, absMax); - - hereZoom[0] = divide(subtract(min, absMin), diff); - hereZoom[1] = divide(subtract(max, absMin), diff); - - return hereZoom; - } - - - /** Get Collection from ChartThemePanel. .*/ - public Collection getCtpCollection() { - return this.ctp.getCollection(); - } - - - /** - * Updates the Transform2D object using the chart info service. - */ - public void updateChartInfo() { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - info.getChartInfo( - view.getCollection(), - locale, - mode.getName(), - getChartAttributes(), - new AsyncCallback<ChartInfo>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("ChartInfo ERROR: " + caught.getMessage()); - } - - @Override - public void onSuccess(ChartInfo chartInfo) { - setChartInfo(chartInfo); - } - }); - } - - - public void updateChartPanel() { - int w = right.getWidth(); - int h = right.getHeight(); - - chart.setSrc(getImgUrl(w, h)); - } - - - /** - * Returns the existing chart panel. - * - * @return the existing chart panel. - */ - public Canvas getChartPanel() { - return right; - } - - - /** Access the Canvas holding the rendered Chart. */ - public Canvas getChartImg() { - return chart; - } - - - /** Get associated ChartInfo object. */ - public ChartInfo getChartInfo() { - return chartInfo; - } - - - protected void setChartInfo(ChartInfo chartInfo) { - this.chartInfo = chartInfo; - } - - - public Transform2D getTransformer() { - return getTransformer(0); - } - - - /** - * Returns the Transform2D object used to transform image coordinates into - * chart (data) coordinates. - * - * @param pos The index of a specific transformer. - * - * @return the Transform2D object. - */ - public Transform2D getTransformer(int pos) { - if (chartInfo == null) { - return null; - } - - return chartInfo.getTransformer(pos); - } - - - /** - * Returns the Transform2D count. - * - * @return the Transformer2D count - */ - public int getTransformerCount() { - if (chartInfo == null) { - return 0; - } - - return chartInfo.getTransformerCount(); - } - - - /** - * Creates a new chart panel with default size. - * - * @return the created chart panel. - */ - protected Img createChartImg() { - return createChartImg(DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT); - } - - - /** - * Creates a new chart panel with specified width and height. - * - * @param width The width for the chart panel. - * @param height The height for the chart panel. - * - * @return the created chart panel. - */ - protected Img createChartImg(int width, int height) { - Img chart = getChartImg(width, height); - chart.setWidth100(); - chart.setHeight100(); - - return chart; - } - - - /** - * Builds the chart image and returns it. - * - * @param width The chart width. - * @param height The chart height. - * - * @return the chart image. - */ - protected Img getChartImg(int width, int height) { - return new Img(getImgUrl(width, height)); - } - - - /** - * Builds the URL that points to the chart image. - * - * @param width The width of the requested chart. - * @param height The height of the requested chart. - * @param xr Optional x range (used for zooming). - * @param yr Optional y range (used for zooming). - * - * @return the URL to the chart image. - */ - protected String getImgUrl(int width, int height) { - Config config = Config.getInstance(); - - String imgUrl = GWT.getModuleBaseURL(); - imgUrl += "chart"; - imgUrl += "?uuid=" + collection.identifier(); - imgUrl += "&type=" + mode.getName(); - imgUrl += "&locale=" + config.getLocale(); - imgUrl += "×tamp=" + new Date().getTime(); - imgUrl += "&width=" + Integer.toString(width); - imgUrl += "&height=" + Integer.toString(height); - - Number[] zoom = getZoomValues(); - - if (zoom != null) { - if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { - // a zoom range of 0-1 means displaying the whole range. In such - // case we don't need to zoom. - imgUrl += "&minx=" + zoom[0]; - imgUrl += "&maxx=" + zoom[1]; - } - - if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { - // a zoom range of 0-1 means displaying the whole range. In such - // case we don't need to zoom. - imgUrl += "&miny=" + zoom[2]; - imgUrl += "&maxy=" + zoom[3]; - } - } - - return imgUrl; - } - - - /** Get link to export image in given dimension and format. */ - public String getExportUrl(int width, int height, String format) { - String url = getImgUrl(width, height); - url += "&format=" + format; - url += "&export=true"; - - return url; - } - - - public Map <String, String> getChartAttributes() { - Map<String, String> attr = new HashMap<String, String>(); - - Canvas chart = getChartPanel(); - attr.put("width", chart.getWidth().toString()); - attr.put("height", chart.getHeight().toString()); - - Number[] zoom = getZoomValues(); - - if (zoom != null) { - if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { - // a zoom range of 0-1 means displaying the whole range. In such - // case we don't need to zoom. - attr.put("minx", zoom[0].toString()); - attr.put("maxx", zoom[1].toString()); - } - if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { - // a zoom range of 0-1 means displaying the whole range. In such - // case we don't need to zoom. - attr.put("miny", zoom[2].toString()); - attr.put("maxy", zoom[3].toString()); - } - } - - return attr; - } - - - protected Number[] getZoomValues() { - return zoom; - } - - - /** Return the 'parent' CollectionView. */ - public CollectionView getView() { - return this.view; - } - - - public static Number subtract(Number left, Number right) { - if (left instanceof Double) { - return new Double(left.doubleValue() - right.doubleValue()); - } - else if (left instanceof Long) { - return new Long(left.longValue() - right.longValue()); - } - else { - return new Integer(left.intValue() - right.intValue()); - } - } - - - /** Add two numbers, casting to Type of param left. */ - public static Number add(Number left, Number right) { - if (left instanceof Double) { - return new Double(left.doubleValue() + right.doubleValue()); - } - else if (left instanceof Long) { - return new Long(left.longValue() + right.longValue()); - } - else { - return new Integer(left.intValue() + right.intValue()); - } - } - - - /** Divde left by right. Note that Long will be casted to double. */ - public static Number divide(Number left, Number right) { - if (left instanceof Double) { - return new Double(left.doubleValue() / right.doubleValue()); - } - else if (left instanceof Long) { - return new Double(left.doubleValue() / right.doubleValue()); - } - else { - return new Integer(left.intValue() / right.intValue()); - } - } - - - public static Number multi(Number left, Number right) { - if (left instanceof Double) { - return new Double(left.doubleValue() * right.doubleValue()); - } - else if (left instanceof Long) { - return new Long(left.longValue() * right.longValue()); - } - else { - return new Integer(left.intValue() * right.intValue()); - } - } - - - public static boolean isBigger(Number left, Number right) { - if (left instanceof Double) { - return left.doubleValue() > right.doubleValue(); - } - else if (left instanceof Long) { - return left.longValue() > right.longValue(); - } - else { - return left.intValue() > right.intValue(); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,601 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.CheckboxItem; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.CollectionAttributeService; -import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; -import de.intevation.flys.client.client.utils.DoubleValidator; -import de.intevation.flys.client.client.utils.IntegerValidator; -import de.intevation.flys.client.shared.model.BooleanProperty; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.DoubleProperty; -import de.intevation.flys.client.shared.model.IntegerProperty; -import de.intevation.flys.client.shared.model.OutputSettings; -import de.intevation.flys.client.shared.model.Property; -import de.intevation.flys.client.shared.model.PropertyGroup; -import de.intevation.flys.client.shared.model.PropertySetting; -import de.intevation.flys.client.shared.model.Settings; -import de.intevation.flys.client.shared.model.StringProperty; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * Dialog for the Chart-Properties, constructed from respective xml document. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class ChartPropertiesEditor -extends Window -implements ClickHandler -{ - /** The interface that provides i18n messages. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** CollectionAttribute Update Service. */ - protected CollectionAttributeServiceAsync updater = - GWT.create(CollectionAttributeService.class); - - /** The tab called the editor window. */ - protected ChartOutputTab tab; - - /** The tabset for chart properties. */ - protected TabSet tabs; - - /** The collection. */ - protected Collection collection; - - /** The cloned output settings. */ - protected OutputSettings settings; - - /** The original output settings. */ - protected OutputSettings origSettings; - - - - /** - * Setup editor dialog. - * @param callerTab The tab called the editor window. - */ - public ChartPropertiesEditor(ChartOutputTab callerTab) { - this.tab = callerTab; - this.tabs = new TabSet(); - - init(); - } - - - /** - * Initialize the editor window and its components. - */ - protected void init() { - setTitle(MSG.properties()); - setCanDragReposition(true); - setCanDragResize(true); - - collection = tab.getCollectionView().getCollection(); - String outputName = tab.getOutputName(); - origSettings = (OutputSettings)collection.getSettings(outputName); - - settings = (OutputSettings)origSettings.clone(); - if (settings == null) { - return; - } - List<String> list = settings.getCategories(); - - for (int i = 0; i < list.size(); i++) { - Tab t = new Tab(MSG.getString(list.get(i))); - List<Property> props = settings.getSettings(list.get(i)); - List<Property> origProps = origSettings.getSettings(list.get(i)); - VLayout layout = new VLayout(); - for (int j = 0; j < props.size(); j++) { - if (props.get(j) instanceof PropertyGroup) { - layout.addMember(generatePropertyGroup(props.get(j), - origProps.get(j))); - } - else if (props.get(j) instanceof PropertySetting) { - PropertySetting p = (PropertySetting)props.get(j); - if (p.getAttribute("display").equals("false")) { - continue; - } - layout.addMember(generatePropertySetting(props.get(j), - origProps.get(j))); - } - } - t.setPane(layout); - tabs.addTab(t); - } - - Button accept = new Button(MSG.label_ok()); - Button cancel = new Button(MSG.label_cancel()); - cancel.addClickHandler(this); - accept.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - if(isDialogValid()) { - updateCollection(); - } - else { - GWT.log("Dialog not valid"); - SC.warn(MSG.error_dialog_not_valid()); - } - } - }); - - HLayout buttons = new HLayout(); - buttons.addMember(accept); - buttons.addMember(cancel); - buttons.setAlign(Alignment.CENTER); - buttons.setHeight(30); - - addItem(tabs); - addItem(buttons); - setWidth(380); - setHeight(470); - centerInPage(); - } - - - /** - * This method is called when the user aborts theming. - * @param event The event. - */ - @Override - public void onClick(ClickEvent event) { - this.destroy(); - } - - - /** - * Create a section from group (usually axis properties). - */ - protected Canvas generatePropertyGroup(Property group, Property orig) { - PropertyGroup pg = (PropertyGroup)group; - PropertyGroup origPg = (PropertyGroup)orig; - - if (pg.getName().equals("axis")) { - Label scale = new Label(MSG.scale() + " :"); - scale.setHeight(25); - scale.setMargin(2); - - DynamicForm form1 = new DynamicForm(); - DynamicForm form2 = new DynamicForm(); - form2.setNumCols(6); - - StringProperty label = - (StringProperty)pg.getPropertyByName("label"); - FormItem title = createStringProperty(label); - title.setValue( - ((StringProperty)origPg.getPropertyByName("label")).getValue()); - - IntegerProperty fontsize = - (IntegerProperty)pg.getPropertyByName("font-size"); - FormItem fs = createIntegerProperty(fontsize); - fs.setValue( - ((IntegerProperty) - origPg.getPropertyByName("font-size")).getValue()); - - DoubleProperty upper = - (DoubleProperty)pg.getPropertyByName("upper"); - final FormItem range1 = createDoubleProperty(upper); - range1.setName("rangeupper"); - range1.setWidth(70); - range1.setValue( - ((DoubleProperty) - origPg.getPropertyByName("upper")).toUIString()); - - DoubleProperty lower = - (DoubleProperty)pg.getPropertyByName("lower"); - final FormItem range2 = createDoubleProperty(lower); - range2.setName("rangelower"); - range2.setWidth(70); - range2.setValue( - ((DoubleProperty) - origPg.getPropertyByName("lower")).toUIString()); - - BooleanProperty fixation = - (BooleanProperty)pg.getPropertyByName("fixation"); - FormItem fix = createBooleanProperty(fixation); - fix.setValue(((BooleanProperty) - origPg.getPropertyByName("fixation")).getValue().booleanValue()); - - fix.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent e) { - if ((Boolean)e.getValue()) { - range1.enable(); - range2.enable(); - } - else { - range1.disable(); - range2.disable(); - } - } - }); - if (fix.getValue().toString().equals("true")) { - range1.enable(); - range2.enable(); - } - else { - range1.disable(); - range2.disable(); - } - - form1.setFields(title, fs); - form2.setFields(fix, range2, range1); - - HLayout scaleLayout = new HLayout(); - scaleLayout.setHeight(30); - scaleLayout.addMember(scale); - scaleLayout.addMember(form2); - scaleLayout.setStyleName("property-dialog-axis"); - - VLayout root = new VLayout(); - root.addMember(form1); - root.addMember(scaleLayout); - root.setHeight(90); - - return root; - } - return null; - } - - - /** - * Generate a form with items for the properties/settings, preset with - * values. - */ - protected DynamicForm generatePropertySetting( - Property setting, - Property orig) - { - DynamicForm form = new DynamicForm(); - FormItem item = new FormItem(); - if (setting instanceof BooleanProperty) { - item = createBooleanProperty((BooleanProperty)setting); - item.setValue(((BooleanProperty)orig).getValue().booleanValue()); - } - else if (setting instanceof DoubleProperty) { - item = createDoubleProperty((DoubleProperty)setting); - item.setValue(((DoubleProperty)orig).toUIString()); - } - else if (setting instanceof IntegerProperty) { - item = createIntegerProperty((IntegerProperty)setting); - item.setValue(((IntegerProperty)orig).getValue()); - } - else if (setting instanceof StringProperty) { - StringProperty property = (StringProperty) setting; - item = createStringProperty(property); - item.setValue(((StringProperty)orig).getValue()); - } - else { - GWT.log("generatePropertySetting: unknown setting type."); - } - form.setFields(item); - return form; - } - - - protected FormItem createStringProperty(final StringProperty sp) { - String name = sp.getName(); - if (name.contains("-")) { - name = name.replace("-", "_"); - } - - String choiceAttribute = sp.getAttribute("choice"); - - if (choiceAttribute != null && choiceAttribute.equals("logo")) { - SelectItem logoChooser = new SelectItem(); - logoChooser.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/logo-"); - logoChooser.setValueIconHeight(50); - logoChooser.setValueIconWidth(100); - - LinkedHashMap valueMap = new LinkedHashMap<String, String>(); - LinkedHashMap<String, String> valueIcons = new LinkedHashMap<String, String>(); - valueMap.put("none", MSG.getString("none")); - /* - If you want to add images, remember to change code in these places: - flys-artifacts: - XYChartGenerator.java - Timeseries*Generator.java and - in the flys-client projects Chart*Propert*Editor.java. - Also, these images have to be put in - flys-artifacts/src/main/resources/images/ - flys-client/src/main/webapp/images/ - */ - valueMap.put("BfG", ""); - valueMap.put("Intevation", ""); - valueIcons.put("BfG", "bfg.gif"); - valueIcons.put("Intevation", "intevation.png"); - logoChooser.setValueIcons(valueIcons); - logoChooser.setValueMap(valueMap); - logoChooser.setTitleStyle("color:#000;"); - logoChooser.setTitleAlign(Alignment.LEFT); - logoChooser.setTitle(MSG.getString(name)); - logoChooser.setTitleAlign(Alignment.LEFT); - logoChooser.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - String val; - if (e.getItem().getValue() == null) { - val = ""; - } - else { - val = e.getItem().getValue().toString(); - } - sp.setValue(val); - } - }); - return logoChooser; - } - else if (choiceAttribute != null && choiceAttribute.equals("placeh")) { - SelectItem placeChooser = new SelectItem(); - LinkedHashMap valueMap = new LinkedHashMap<String, String>(); - valueMap.put("right", MSG.getString("right")); - valueMap.put("left", MSG.getString("left")); - valueMap.put("center", MSG.getString("center")); - placeChooser.setValueMap(valueMap); - placeChooser.setTitleStyle("color:#000;"); - placeChooser.setTitleAlign(Alignment.LEFT); - placeChooser.setTitle(MSG.getString(name)); - placeChooser.setTitleAlign(Alignment.LEFT); - placeChooser.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - String val; - if (e.getItem().getValue() == null) { - val = ""; - } - else { - val = e.getItem().getValue().toString(); - } - sp.setValue(val); - } - }); - return placeChooser; - } - else if (choiceAttribute != null && choiceAttribute.equals("placev")) { - SelectItem placeChooser = new SelectItem(); - LinkedHashMap valueMap = new LinkedHashMap<String, String>(); - valueMap.put("top", MSG.getString("top")); - valueMap.put("bottom", MSG.getString("bottom")); - valueMap.put("center", MSG.getString("center")); - placeChooser.setValueMap(valueMap); - placeChooser.setTitleStyle("color:#000;"); - placeChooser.setTitleAlign(Alignment.LEFT); - placeChooser.setTitle(MSG.getString(name)); - placeChooser.setTitleAlign(Alignment.LEFT); - placeChooser.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - String val; - if (e.getItem().getValue() == null) { - val = ""; - } - else { - val = e.getItem().getValue().toString(); - } - sp.setValue(val); - } - }); - return placeChooser; - } - - TextItem item = new TextItem(); - item.setTitle(MSG.getString(name)); - item.setTitleAlign(Alignment.LEFT); - item.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - String val; - if (e.getItem().getValue() == null) { - val = ""; - } - else { - val = e.getItem().getValue().toString(); - } - sp.setValue(val); - } - }); - return item; - } - - - /** - * - */ - protected FormItem createBooleanProperty(final BooleanProperty bp) { - String name = bp.getName(); - if (name.contains("-")) { - name = name.replace("-", "_"); - } - - CheckboxItem item = new CheckboxItem("item", MSG.getString(name)); - item.setLabelAsTitle(true); - item.setTitleStyle("color:#000;"); - item.setTitleAlign(Alignment.LEFT); - item.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - String val; - if (e.getItem().getValue() == null) { - val = ""; - } - else { - val = e.getItem().getValue().toString(); - } - bp.setValue(val); - } - }); - return item; - } - - - /** - * - */ - protected FormItem createDoubleProperty(final DoubleProperty dp) { - String name = dp.getName(); - if (name.contains("-")) { - name = name.replace("-", "_"); - } - - TextItem item = new TextItem(); - item.setTitle(MSG.getString(name)); - item.setTitleAlign(Alignment.LEFT); - item.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - DoubleValidator validator = new DoubleValidator(); - Map errors = e.getForm().getErrors(); - if(validator.validate(e.getItem(), errors)) { - dp.setValueFromUI(e.getItem().getValue().toString()); - } - e.getForm().setErrors(errors, true); - } - }); - return item; - } - - - /** - * - */ - protected FormItem createIntegerProperty(final IntegerProperty ip) { - String name = ip.getName(); - if (name.contains("-")) { - name = name.replace("-", "_"); - } - - TextItem item = new TextItem(); - item.setTitle(MSG.getString(name)); - item.setTitleAlign(Alignment.LEFT); - item.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - IntegerValidator validator = new IntegerValidator(); - Map errors = e.getForm().getErrors(); - if(validator.validate(e.getItem(), errors)) { - ip.setValue(e.getItem().getValue().toString()); - } - e.getForm().setErrors(errors, true); - } - }); - return item; - } - - - protected void updateCollection() { - final Config config = Config.getInstance(); - final String loc = config.getLocale(); - - GWT.log("PropertiesEditor.updateCollection via RPC now"); - - Settings s = settings; - collection.addSettings(this.tab.getOutputName(), s); - updater.update(collection, loc, new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not update collection attributes."); - SC.warn(MSG.getString(caught.getMessage())); - } - @Override - public void onSuccess(Collection collection) { - updateChartTab(); - } - }); - } - - protected void updateChartTab() { - this.tab.updateChartInfo(); - this.tab.updateChartPanel(); - this.destroy(); - } - - - protected boolean isDialogValid() { - boolean valid = true; - for (int i = 0; i < tabs.getNumTabs(); i++) { - Tab t = tabs.getTab(i); - Canvas container = t.getPane(); - Canvas[] children = container.getChildren(); - for (Canvas c: children) { - valid = validateCanvas(c); - if(!valid) { - return valid; - } - } - } - return valid; - } - - - protected boolean validateCanvas(Canvas c) { - boolean valid = true; - if(c instanceof DynamicForm) { - DynamicForm f = (DynamicForm) c; - FormItem up = f.getItem("rangeupper"); - FormItem lo = f.getItem("rangelower"); - - if(up != null && lo != null && - !up.isDisabled() && !lo.isDisabled()) - { - validateRange(f); - } - return !f.hasErrors(); - } - else if(c.getChildren().length > 0) { - for (Canvas child: c.getChildren()) { - valid = validateCanvas(child); - if(!valid) { - return valid; - } - } - } - return valid; - } - - protected boolean validateRange(DynamicForm form) { - Map errors = form.getErrors(); - FormItem up = form.getItem("rangeupper"); - FormItem lo = form.getItem("rangelower"); - - String v1 = up.getValue().toString(); - String v2 = lo.getValue().toString(); - - if(v1.equals(v2)) { - errors.put(up.getFieldName(), MSG.wrongFormat()); - errors.put(lo.getFieldName(), MSG.wrongFormat()); - form.setErrors(errors, true); - return false; - } - return true; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,461 +0,0 @@ -package de.intevation.flys.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 de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.FeedServiceAsync; -import de.intevation.flys.client.client.services.LoadArtifactService; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.ThemePanel; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DefaultArtifact; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.FacetRecord; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.Theme; -import de.intevation.flys.client.shared.model.ThemeList; - - -/** - * ThemePanel on the left in CollectionView. - * Contains control widgets for "themes", which are plotted in a diagram (chart). - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -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"; - - FeedServiceAsync feedService = GWT.create( - de.intevation.flys.client.client.services.FeedService.class); - - - /** Constructor for a ChartThemePanel. */ - public ChartThemePanel( - OutputMode mode, - CollectionView view - ) { - super(mode, view); - - initGrid(); - initLayout(); - - updateGrid(); - } - - - /** Creates Layout with theme list and navigation bar inside. */ - protected VLayout createLayout() { - VLayout layout = new VLayout(); - layout.setWidth100(); - layout.setHeight100(); - - layout.addMember(list); - layout.addMember(navigation); - - return layout; - } - - - /** - * Initializes the layout of this panel. - */ - protected void initLayout() { - setWidth100(); - setHeight100(); - - addChild(createLayout()); - } - - - /** - * Initializes the components (columns) of the theme grid. - */ - 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(); - - list.addEditCompleteHandler(this); - - ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); - active.setType(ListGridFieldType.BOOLEAN); - - ListGridField name = new ListGridField( - GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); - name.setType(ListGridFieldType.TEXT); - - list.setFields(active, name); - } - - - /** Set theme active/inactive. */ - @Override - public void activateTheme(Theme theme, 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(); - } - - - /** - * Tell an area artifact where to get the upper and lower curve from. - * @param artifact UUID of area-artifact. - */ - public void feedTellArea( - final String artifact, - Theme under, - Theme over, - 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") - }; - 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") - }; - 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") - }; - GWT.log("Have 'over' curve only"); - } - 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(); - } - }); - } - - - /** - * Create and parameterize a new area artifact. - * @param under - * @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(); - - Recommendation area = new Recommendation( - "area", - "", - "", - null); - 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); - } - } - ); - } - - - /** - * 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. - */ - protected boolean areAreaCompatible(Theme a, Theme b) { - if (a.equals(b)) { - return false; - } - if (a.getFacet().equals("longitudinal_section.w") || - a.getFacet().equals("other.wkms")) { - return b.getFacet().equals("longitudinal_section.w") - || b.getFacet().equals("other.wkms"); - } - else if (a.getFacet().equals("longitudinal_section.q")) { - return b.getFacet().equals("longitudinal_section.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("other.wkms"); - } - - - /** Attach menu/item to open editor for Manual Points. */ - protected void attachManualPointsMenu(Menu menu) { - menu.addItem(createSeparator()); - MenuItem editManualPoints = new MenuItem(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(); - } - } - }); - 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 Theme facetTheme = ((FacetRecord)records[0]).getTheme(); - - if (!canArea(facetTheme)) { - if (facetTheme.getFacet().endsWith("manualpoints")) { - attachManualPointsMenu(menu); - return menu; - } - else { - return menu; - } - } - - menu.addItem(createSeparator()); - - MenuItem areaMenuItem = new MenuItem(MSG.chart_themepanel_new_area()); - Menu areaMenu = new Menu(); - - ThemeList themes = getThemeList(); - 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); - - if (theme.getVisible() == 0) { - continue; - } - - if (!areAreaCompatible(facetTheme, theme)) { - continue; - } - - MenuItem againster = new MenuItem(theme.getDescription()); - underMenu.addItem(againster); - - againster.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - disable(); - createAreaArtifact(theme, facetTheme, false); - } - }); - } - - // 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); - if (theme.getVisible() == 0) { - continue; - } - if (!areAreaCompatible(facetTheme, theme)) { - continue; - } - MenuItem againster = new MenuItem(theme.getDescription()); - overMenu.addItem(againster); - - againster.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - disable(); - createAreaArtifact(facetTheme, theme, false); - } - }); - } - overMenu.addItem(createSeparator()); - MenuItem againstAxis = new MenuItem(MSG.getString("x_axis")); - againstAxis.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - disable(); - createAreaArtifact(null, facetTheme, false); - } - }); - 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); - if (theme.getVisible() == 0) { - continue; - } - if (!areAreaCompatible(facetTheme, theme)) { - continue; - } - MenuItem againster = new MenuItem(theme.getDescription()); - betweenMenu.addItem(againster); - - againster.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - disable(); - createAreaArtifact(facetTheme, theme, true); - } - }); - } - betweenMenu.addItem(createSeparator()); - betweenMenu.addItem(againstAxis); - - overMenuItem.setSubmenu(overMenu); - underMenuItem.setSubmenu(underMenu); - betweenMenuItem.setSubmenu(betweenMenu); - - areaMenu.addItem(betweenMenuItem); - areaMenu.addItem(overMenuItem); - areaMenu.addItem(underMenuItem); - areaMenu.addItem(createSeparator()); - MenuItem standAloneAgainstAxis = new MenuItem(MSG.getString("against_x_axis")); - standAloneAgainstAxis.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - disable(); - createAreaArtifact(null, facetTheme, false); - } - }); - areaMenu.addItem(standAloneAgainstAxis); - - areaMenuItem.setSubmenu(areaMenu); - menu.addItem(areaMenuItem); - - return menu; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,338 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.ImgButton; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.ZoomEvent; -import de.intevation.flys.client.client.event.ZoomHandler; -import de.intevation.flys.client.client.ui.ImgLink; -import de.intevation.flys.client.client.ui.Toolbar; - - -/** - * Toolbar with buttons/icons to open datacage, switch to zoom mode, zoom out - * etc. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ChartToolbar extends Toolbar implements ZoomHandler { - - protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public static final int PANEL_HEIGHT = 35; - - protected Button manageThemes; - protected Button datacage; - protected ImgLink downloadPNG; - protected ImgLink downloadPDF; - protected ImgLink downloadSVG; - protected Canvas downloadCSV; - protected MousePositionPanel position; - protected ZoomboxControl zoombox; - protected ImgButton zoomToMaxExtent; - protected ImgButton historyBack; - protected ImgButton zoomOut; - protected ImgButton chartProperties; - protected Button addPoints; - protected Button addWSP; - protected ImgLink exportAT; - protected PanControl panControl; - - - /** @param chartTab Output-Tab on which this toolbar is located. */ - public ChartToolbar(ChartOutputTab chartTab) { - super(chartTab); - initTools(); - } - - - protected void initTools() { - ChartOutputTab chartTab = getChartOutputTab(); - - manageThemes = new Button(MSG.manageThemes()); - datacage = new Button(MSG.databasket()); - position = new MousePositionPanel(chartTab); - zoombox = new ZoomboxControl(chartTab, MSG.zoom_in()); - zoomToMaxExtent = new ImgButton(); - zoomOut = new ImgButton(); - historyBack = new ImgButton(); - panControl = new PanControl(chartTab, MSG.pan()); - chartProperties = new ImgButton(); - addPoints = new Button(MSG.points()); - - if (chartTab.getMode().getName().equals("cross_section")) { - addWSP = new Button(MSG.addWSPButton()); - addWSP.setTooltip(MSG.addWSPTooltip()); - final ChartOutputTab finalChartTab = chartTab; - addWSP.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent ce) { - new ManualWSPEditor(finalChartTab.getView().getCollection(), - finalChartTab, finalChartTab.getMode().getName()).show(); - }}); - } - - addPoints.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - openPointWindow(); - } - }); - addPoints.setTooltip(MSG.addPointsTooltip()); - - manageThemes.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - getChartOutputTab().toggleThemePanel(); - } - }); - - datacage.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - GWT.log("Clicked 'datacage' button."); - openDatacageWindow((ChartOutputTab) getOutputTab()); - } - }); - - String baseUrl = GWT.getHostPageBaseURL(); - String moduleUrl = GWT.getModuleBaseURL(); - Config config = Config.getInstance(); - - if (chartTab.getMode().getName().equals("fix_wq_curve")) { - exportAT = new ImgLink( - baseUrl + MSG.downloadCSV(), - moduleUrl + "export" + - "?uuid=" + chartTab.getCollection().identifier() + - "&name=" + chartTab.getMode().getName() + - "&mode=" + chartTab.getMode().getName() + "_at_export" + - "&type=at" + - "&server=" + config.getServerUrl() + - "&locale=" + config.getLocale() + - "&km=" + chartTab.getCollectionView().getCurrentKm(), - 20, - 20 - ); - exportAT.setTooltip(MSG.exportATTooltip()); - } - - downloadPNG = new ImgLink( - baseUrl + MSG.downloadPNG(), - chartTab.getExportUrl(-1, -1, "png"), - 20, - 20); - downloadPNG.setTooltip(MSG.downloadPNGTooltip()); - - downloadPDF = new ImgLink( - baseUrl + MSG.downloadPDF(), - chartTab.getExportUrl(1280, 1024, "pdf"), - 20, - 20); - downloadPDF.setTooltip(MSG.downloadPDFTooltip()); - - downloadSVG = new ImgLink( - baseUrl + MSG.downloadSVG(), - chartTab.getExportUrl(1280, 1024, "svg"), - 20, - 20); - downloadSVG.setTooltip(MSG.downloadSVGTooltip()); - - downloadCSV = new ImgLink( - baseUrl + MSG.downloadCSV(), - chartTab.getExportUrl(-1, -1, "csv"), - 20, - 20); - downloadCSV.setTooltip(MSG.downloadCSVTooltip()); - - zoomToMaxExtent.setSrc(baseUrl + MSG.zoom_all()); - adjustImageButton(zoomToMaxExtent); - zoomToMaxExtent.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - getChartOutputTab().resetRanges(); - // Relink the export buttons. - onZoom(null); - } - }); - zoomToMaxExtent.setTooltip(MSG.zoomToMaxExtentTooltip()); - - zoomOut.setSrc(baseUrl + MSG.zoom_out()); - adjustImageButton(zoomOut); - zoomOut.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - getChartOutputTab().zoomOut(10); - // Relink the export buttons. - onZoom(null); - } - }); - zoomOut.setTooltip(MSG.zoomOutTooltip()); - - historyBack.setSrc(baseUrl + MSG.zoom_back()); - adjustImageButton(historyBack); - historyBack.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - getChartOutputTab().zoomOut(); - // Relink the export buttons. - onZoom(null); - } - }); - historyBack.setTooltip(MSG.historyBackTooltip()); - - zoombox.addZoomHandler(chartTab); - zoombox.addZoomHandler(this); - zoombox.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - panControl.deselect(); - } - }); - zoombox.setTooltip(MSG.zoomboxTooltip()); - - panControl.addPanHandler(chartTab); - panControl.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - zoombox.deselect(); - } - }); - panControl.setTooltip(MSG.panControlTooltip()); - - chartProperties.setSrc(baseUrl + MSG.properties_ico()); - adjustImageButton(chartProperties); - chartProperties.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - openPropertiesEditor(); - } - }); - chartProperties.setTooltip(MSG.chartPropertiesTooltip()); - - initLayout(); - } - - /** Set width, height and other properties of an imagebutton. */ - public void adjustImageButton(ImgButton imgButton) { - imgButton.setWidth(20); - imgButton.setHeight(20); - imgButton.setShowDown(false); - imgButton.setShowRollOver(false); - imgButton.setShowRollOverIcon(false); - imgButton.setShowDisabled(false); - imgButton.setShowDisabledIcon(true); - imgButton.setShowDownIcon(false); - imgButton.setShowFocusedIcon(false); - } - - - protected ChartOutputTab getChartOutputTab() { - return (ChartOutputTab)getOutputTab(); - } - - - protected void initLayout() { - setWidth100(); - setHeight(PANEL_HEIGHT); - setMembersMargin(10); - setPadding(5); - setBorder("1px solid black"); - - Label spacer = new Label(); - spacer.setWidth("*"); - datacage.setWidth("95px"); - position.setWidth("200px"); - - addMember(manageThemes); - addMember(datacage); - addMember(downloadPNG); - addMember(downloadPDF); - addMember(downloadSVG); - addMember(downloadCSV); - if (getChartOutputTab().getMode().getName().equals("fix_wq_curve")) { - addMember(exportAT); - } - addMember(zoomToMaxExtent); - addMember(historyBack); - addMember(zoomOut); - addMember(zoombox); - addMember(panControl); - addMember(chartProperties); - addMember(addPoints); - - if (getChartOutputTab().getMode().getName().equals("cross_section")) { - addMember(addWSP); - } - - addMember(spacer); - addMember(position); - } - - /** - * Open the chart property editor dialog. - */ - protected void openPropertiesEditor() { - ChartPropertiesEditor editor = - new ChartPropertiesEditor(getChartOutputTab()); - editor.show(); - } - - - /** Open editor for custom points. */ - protected void openPointWindow() { - ChartOutputTab chartTab = getChartOutputTab(); - if (chartTab.getMode().getName().equals("historical_discharge")) { - new ManualDatePointsEditor(chartTab.getView().getCollection(), - chartTab, chartTab.getMode().getName()).show(); - } - else { - new ManualPointsEditor(chartTab.getView().getCollection(), - chartTab, chartTab.getMode().getName()).show(); - } - } - - - /** - * Sets new sources to the export button/images, such that the - * correct zoom values are included in the request when clicked. - * @param evt ignored. - */ - @Override - public void onZoom(ZoomEvent evt) { - ChartOutputTab chartTab = getChartOutputTab(); - downloadPNG.setSource(chartTab.getExportUrl(-1, -1, "png")); - downloadPDF.setSource(chartTab.getExportUrl(-1, -1, "pdf")); - downloadSVG.setSource(chartTab.getExportUrl(-1, -1, "svg")); - } - - public void deselectControls() { - zoombox.deselect(); - } - - public void updateLinks() { - ChartOutputTab chartTab = getChartOutputTab(); - String moduleUrl = GWT.getModuleBaseURL(); - Config config = Config.getInstance(); - - if (chartTab.getMode().getName().equals("fix_wq_curve")) { - exportAT.setSource( - moduleUrl + "export" + - "?uuid=" + chartTab.getCollection().identifier() + - "&mode=" + chartTab.getMode().getName() + "_at_export" + - "&type=at" + - "&server=" + config.getServerUrl() + - "&locale=" + config.getLocale() + - "&km=" + chartTab.getCollectionView().getCurrentKm()); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,722 +0,0 @@ -package de.intevation.flys.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.Canvas; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; -import com.smartgwt.client.widgets.grid.ListGrid; -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 de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.services.CrossSectionKMServiceAsync; -import de.intevation.flys.client.client.services.LoadArtifactService; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.widgets.KMSpinner; -import de.intevation.flys.client.client.widgets.KMSpinnerChangeListener; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DefaultArtifact; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.FacetRecord; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Theme; -import de.intevation.flys.client.shared.model.ThemeList; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - - -/** - * ThemePanel much like ChartThemePanel, but shows an "Actions" column, - * needed for interaction in the CrossSection Charts and a selector to - * declare which cross section profile is "master" (waterlevels refer to the - * chosen kilometer of that cross section profile). - * Also can show 'area creation' context menus. - */ -public class CrossSectionChartThemePanel -extends ChartThemePanel -implements KMSpinnerChangeListener -{ - /** Artifact Clone/Creation service. */ - protected LoadArtifactServiceAsync loadService = - GWT.create(LoadArtifactService.class); - - /** Service to query measurement points of cross sections. */ - CrossSectionKMServiceAsync kmService = GWT.create( - de.intevation.flys.client.client.services.CrossSectionKMService.class); - - /** UUID of the current "master" cross section. */ - protected String currentCSMasterUUID; - - /** The layout (used for visual active/inactive feedback). */ - protected VLayout layout; - - /** Data item name for CrossSections selected km. */ - protected static String CS_KM = "cross_section.km"; - - /** Data item name for CrossSections selected km. */ - protected static String CS_IS_MASTER = "cross_section.master?"; - - /** List of cross-section themes through which is moved through synchronously. */ - protected HashSet synchronCrossSectionThemes = new HashSet(); - - /** Data for master artifact combobox.*/ - protected LinkedHashMap<String, String> masters; - - /** Combobox for master artifacts.*/ - protected SelectItem masterCb; - - - /** - * Trivial constructor. - */ - public CrossSectionChartThemePanel( - OutputMode mode, - CollectionView view) - { - super(mode, view); - } - - - /** Create DefaultArtifact. */ - public static DefaultArtifact artifactReference(String uuid) { - return new DefaultArtifact(uuid, "TODO:hash"); - } - - - /** Access data of collection item of theme. */ - public static String dataOf(Theme theme, String dataItemName) { - if (theme != null && theme.getCollectionItem() != null - && theme.getCollectionItem().getData() != null - ) { - return theme.getCollectionItem().getData().get(dataItemName); - } - - return null; - } - - - /** - * Feed an artifact to let it know that it is master wrt cross-sections. - * @param artifact uuid of an artifact. - */ - public void feedTellMaster(final String artifact) { - Data[] feedData = DefaultData.createSimpleStringDataArray( - CS_IS_MASTER, "1"); - - feedService.feed( - Config.getInstance().getLocale(), - artifactReference(artifact), - feedData, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not feed artifact (" + artifact - + ") with master marker: " + caught.getMessage()); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully injected master mark to " + artifact); - setCurrentCSMaster(artifact.getUuid()); - requestRedraw(); - enable(); - } - }); - } - - - /** - * Sets currentCSMasterUUID. - */ - public String findCurrentCSMaster() { - ThemeList themeList = getThemeList(); - int count = getThemeList().getThemeCount(); - String firstCSUuid = null; - - for (int i = 1; i <= count; i++) { - Theme theme = themeList.getThemeAt(i); - String value = dataOf(theme, CS_IS_MASTER); - - if (value != null) { - if (firstCSUuid == null) { - firstCSUuid = theme.getArtifact(); - } - if (!value.equals("0")) { - setCurrentCSMaster(theme.getArtifact()); - GWT.log("found a master: " + currentCSMasterUUID - + "/" + theme.getDescription()); - return theme.getDescription(); - } - } - } - // There is none selected. Take the first one. - if (firstCSUuid != null) { - setCurrentCSMaster(firstCSUuid); - feedTellMaster(firstCSUuid); - } - return null; - } - - - /** - * Create Layout, add a master selection box beneath. - */ - @Override - protected VLayout createLayout() { - layout = super.createLayout(); - - // Create "set master" combobox. - masterCb = new SelectItem(); - - masterCb.setTitle(MSG.chart_themepanel_set_master()); - masterCb.setType("comboBox"); - masters = getThemeList().toMapArtifactUUIDDescription("cross_section"); - masterCb.setValueMap(masters); - - final DynamicForm form = new DynamicForm(); - form.setWidth(200); - form.setFields(masterCb); - layout.addMember(form, 0); - - Config config = Config.getInstance(); - final String locale = config.getLocale(); - findCurrentCSMaster(); - masterCb.setValue(getCurrentCSMaster()); - - // Add Change Handler to first unset the old master and then set the - // new master. - masterCb.addChangeHandler(new ChangeHandler() { - @Override - public void onChange(ChangeEvent event) { - String selectedItem = (String) event.getValue(); - final String artifact = selectedItem; - - disable(); - - // Tell current master that he is not master anymore. - if (getCurrentCSMaster() != null) { - Data[] feedData = DefaultData.createSimpleStringDataArray( - CS_IS_MASTER, "0"); - feedService.feed( - locale, - artifactReference(getCurrentCSMaster()), - feedData, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not un-master artifact (" - + getCurrentCSMaster() + "): " + - caught.getMessage()); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - @Override - public void onSuccess(Artifact oldMaster) { - GWT.log("Successfully un-mastered artifact."); - feedTellMaster(artifact); - } - }); - } - else { - feedTellMaster(artifact); - } - } - }); - - return layout; - } - - - /** Disable the UI (becomes gray, inresponsive to user input). */ - @Override - public void disable() { - this.layout.setDisabled(true); - } - - - /** DisDisable the UI (becomes ungray, responsive to user input). */ - @Override - public void enable() { - this.layout.setDisabled(false); - } - - - /** - * Returns a double from the list that has the smallest distance to the - * given to value. In case of multiple values with the same difference, - * the last one is taken. - * @param in possible return values. - * @param to the value to be as close to as possible. - * @param up if true, prefer numerically higher values in case of two - * values with equal distance to \param to. - * @return value from in that is closest to to, -1 if none. - */ - public static double closest(Double[] in, double to, boolean up) { - if (in == null || in.length == 0) { - return -1; - } - if (in[0] == to) { - return to; - } - for (int i = 0; i < in.length; i++) { - GWT.log ("Close? " + in[i]); - } - - double minDiff = Math.abs(to - in[0]); - double bestMatch = in[0]; - for (int i = 1; i < in.length; i++) { - if (in[i] == to) { - return to; - } - if ((in[i] < to && up) - || (in[i] > to && !up)) { - continue; - } - double diff = Math.abs(to - in[i]); - if (diff <= minDiff) { - minDiff = diff; - bestMatch = in[i]; - } - } - return bestMatch; - } - - - /** - * Feed a single artifact with the km of the crosssection to display. - * If its the selected master, also feed the collectionmaster. - * - * @param artifacts List of artifacts to feed. - * @param kmD The km to set. - */ - public void sendFeed(final List<Artifact> artifacts, final double kmD) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - Data[] feedData = - DefaultData.createSimpleStringDataArray(CS_KM, - Double.valueOf(kmD).toString()); - - disable(); - // TODO - // The ones who do not have data for this km should not show line! - feedService.feedMany( - locale, - artifacts, - feedData, - new AsyncCallback<List<Artifact>>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not feed many artifacts " + caught.getMessage()); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - @Override - public void onSuccess(List<Artifact> artifact) { - GWT.log("Successfully fed many with km"); - requestRedraw(); - enable(); - } - }); - } - - - /** - * Feed a single artifact with the km of the crosssection to display. - * If its the selected master, also feed the collectionmaster. - * @param artUUID The UUID of the artifact to feed. - * @param kmD The km to set. - */ - public void sendFeed(final String artUUID, final double kmD) { - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - Data[] feedData = - DefaultData.createSimpleStringDataArray(CS_KM, - Double.valueOf(kmD).toString()); - - disable(); - feedService.feed( - locale, - artifactReference(artUUID), - feedData, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not feed artifact " + caught.getMessage()); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully fed with km"); - requestRedraw(); - enable(); - } - }); - } - - - /** Remove the themes, also from the master (reference) select box. */ - @Override - protected void removeThemes(final ListGridRecord[] records) { - // TODO take care of what happens if that was the last - // cross section and/or the cross section currently selected as master. - for (ListGridRecord record: records) { - FacetRecord facet = (FacetRecord) record; - Theme theme = facet.getTheme(); - masters.remove(theme.getArtifact()); - } - masterCb.setValueMap(masters); - super.removeThemes(records); - } - - - /** - * Callback for when a value has been accepted in the km-spinner - * of a Cross-Section Profile theme. - * @param item The SpinnerItem which was manipulated. - * @param enteredKm The double-parsed value that has been entered. - * @param facetRecord The underlying datastores record. - * @param up If true, numerically higher values are preferred if - * two values in \param in are in the same distance to - * \param to. - */ - @Override - public void spinnerValueEntered(KMSpinner spinner, final double enteredKm, final FacetRecord facetRecord, final boolean up) { - disable(); - Config config = Config.getInstance(); - final String locale = config.getLocale(); - - Map<Integer, Double> map = new HashMap<Integer,Double>(); - int _dbid = -1; - try { - _dbid = Integer.valueOf(facetRecord.getTheme() - .getCollectionItem() - .getData().get("cross_section.dbid")); - } - catch (NumberFormatException nfe) { - GWT.log("Could not extract cross-section db id from data."); - } - final int dbid = _dbid; - - map.put(dbid, enteredKm); - - // Query the available cross section measurements. - kmService.getCrossSectionKMs(locale, map, 2, - new AsyncCallback<Map<Integer, Double[]>>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not get single km for " - + dbid + ": "+ caught.getMessage()); - SC.warn(MSG.getString(caught.getMessage())); - updateCollection(); - //updateGrid(); - enable(); - } - - @Override - public void onSuccess(Map<Integer, Double[]> obj) { - Double[] kms = obj.get(dbid); - double closest = - CrossSectionChartThemePanel.closest(kms, enteredKm, up); - GWT.log("Got single km close to " + enteredKm + " for " + dbid + ", it is " - + closest); - - // Do not set value, as it will trigger strange - // "javascript" bugs. /*item.setValue(closest);*/ - if (synchronCrossSectionThemes.contains (themeHash - (facetRecord.getTheme()))) { - // Move all other synchrons - ThemeList themes = getThemeList(); - int nThemes = themes.getThemeCount(); - List<Artifact> artifacts = new ArrayList<Artifact>(); - for (int i = 0; i < nThemes; i++) { - final Theme theme = themes.getThemeAt(i+1); - if (theme.getFacet().equals("cross_section") && - theme.getActive() == 1 && - synchronCrossSectionThemes.contains(themeHash(theme)) - ) { - artifacts.add(artifactReference(theme.getArtifact())); - } - } - sendFeed(artifacts, closest); - } - else { - sendFeed(facetRecord.getTheme().getArtifact(), - closest); - } - } - }); - } - - - /** - * Create and configure the Grid to display. - * @return ListGrid with Themes and related controls inside. - */ - @Override - protected ListGrid createGrid() { - final CrossSectionChartThemePanel parent = this; - - ListGrid list = new ListGrid() { - @Override - protected Canvas createRecordComponent( - final ListGridRecord record, - Integer colNum) - { - // Only cross_section Facets display an action widget. - final FacetRecord facetRecord = (FacetRecord) record; - if (!facetRecord.getTheme().getFacet().equals( - "cross_section")) - { - return null; - } - - String fieldName = this.getFieldName(colNum); - - if (fieldName.equals(GRID_FIELD_ACTIONS)) { - double currentValue = - Double.valueOf(facetRecord.getTheme().getCollectionItem().getData().get(CS_KM)); - KMSpinner kmSpinner = new KMSpinner(currentValue, facetRecord); - kmSpinner.addChangeListener(parent); - return kmSpinner; - } - else { - return null; - } - } - }; - list.setCanResizeFields(true); - list.setShowRecordComponents(true); - list.setShowRecordComponentsByCell(true); - list.setShowAllRecords(true); - list.setShowHeaderContextMenu(false); - list.setLeaveScrollbarGap(false); - return list; - } - - - /** - * Initializes the components (columns) of the theme grid. - */ - @Override - protected void initGrid() { - list.setCanEdit(true); - list.setCanSort(false); - list.setShowRecordComponents(true); - list.setShowRecordComponentsByCell(true); - list.setShowHeader(true); - list.setWidth100(); - list.setHeight100(); - - list.addEditCompleteHandler(this); - - ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); - active.setType(ListGridFieldType.BOOLEAN); - - ListGridField name = new ListGridField( - GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); - name.setType(ListGridFieldType.TEXT); - - ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS, - MSG.chart_themepanel_header_actions(), 100); - - list.setFields(active, name, actions); - } - - - /** Get Current Cross-section Masters uuid. */ - public String getCurrentCSMaster() { - return currentCSMasterUUID; - } - - - /** Set Current Cross-section Masters uuid. */ - public void setCurrentCSMaster(String currentMasterUuid) { - this.currentCSMasterUUID = currentMasterUuid; - } - - - /** Returns name of cross section area facets. */ - @Override - protected String getAreaFacetName() { - return "cross_section.area"; - } - - - /** - * 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. - */ - @Override - protected boolean areAreaCompatible(Theme a, Theme b) { - if (a.equals(b)) { - return false; - } - return (a.getFacet().equals("cross_section") - || a.getFacet().endsWith("line")) - && (b.getFacet().equals("cross_section") - || b.getFacet().endsWith("line")); - } - - - /** - * True if context menu should contain 'create area' submenu on - * this theme. - */ - @Override - protected boolean canArea(Theme a) { - return a.getFacet().equals("cross_section") - || a.getFacet().equals("cross_section_water_line") - || a.getFacet().endsWith("line"); - } - - - protected String themeHash(Theme theme) { - return theme.getArtifact() + theme.getFacet() + theme.getIndex(); - } - - - /** - * Include synchron navigation item. - */ - @Override - protected Menu getSingleContextMenu(final ListGridRecord[] records) { - Menu contextMenu = super.getSingleContextMenu(records); - - Theme facetTheme = ((FacetRecord)records[0]).getTheme(); - String item = facetTheme.getFacet(); - - if (item.equals("cross_section")) { - // Synchron checking. - MenuItem synchronNavigationMenuItem = new MenuItem(); - final String themeHash = themeHash(facetTheme); - if (synchronCrossSectionThemes.contains(themeHash)) { - synchronNavigationMenuItem.setTitle(MSG.chart_themepanel_asynchron()); - synchronNavigationMenuItem.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - synchronCrossSectionThemes.remove (themeHash); - } - }); - } - else { - synchronNavigationMenuItem.setTitle(MSG.chart_themepanel_synchron()); - synchronNavigationMenuItem.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - synchronCrossSectionThemes.add (themeHash); - } - }); - } - contextMenu.addItem(synchronNavigationMenuItem); - } - - return contextMenu; - } - - - /** - * This method is used to clear the current theme grid and add new updated - * data. - */ - @Override - protected void updateGrid() { - GWT.log("CrossSectionChartThemePanel.updateGrid"); - - ListGridRecord[] selected = list.getSelectedRecords(); - - clearGrid(); - - ThemeList themeList = getThemeList(); - - if (themeList == null) { - GWT.log("ERROR: No theme list."); - return; - } - - int count = themeList.getThemeCount(); - - for (int i = 1; i <= count; i++) { - Theme theme = themeList.getThemeAt(i); - - if (theme == null) { - continue; - } - - if (theme.getFacet().equals("empty.facet")) { - theme.setVisible(0); - } - - if (theme.getVisible() == 0) { - continue; - } - - if (theme.getFacet().equals("cross_section")) { - addToReferences(theme); - } - - FacetRecord newRecord = createRecord(theme); - addFacetRecord(newRecord); - - String newArtifact = theme.getArtifact(); - String newFacet = theme.getFacet(); - int newIndex = theme.getIndex(); - - for (ListGridRecord r: selected) { - FacetRecord sel = (FacetRecord) r; - Theme oldTheme = sel.getTheme(); - - if (oldTheme.getArtifact().equals(newArtifact) - && oldTheme.getFacet().equals(newFacet) - && oldTheme.getIndex() == newIndex) { - list.selectRecord(newRecord); - } - } - } - - fireOutputParameterChanged(); - - } - - - /** - * Adds a cross section theme to the master artifacts combobox and finds - * a new master if necessary. - * - * @param theme The cross section theme. - */ - protected void addToReferences(Theme theme) { - if (theme.getVisible() != 0) { - masters.put(theme.getArtifact(), theme.getDescription()); - masterCb.setValueMap(masters); - } - findCurrentCSMaster(); - if (masterCb.getSelectedRecord() == null) { - masterCb.setValue(getCurrentCSMaster()); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualDatePointsEditor.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,408 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONBoolean; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.json.client.JSONString; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.IButton; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.grid.CellEditValueFormatter; -import com.smartgwt.client.widgets.grid.CellEditValueParser; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItem; -import de.intevation.flys.client.shared.model.Property; -import de.intevation.flys.client.shared.model.PropertyGroup; -import de.intevation.flys.client.shared.model.Settings; -import de.intevation.flys.client.shared.model.StringProperty; - -import java.util.Date; -import java.util.List; - -/** - * UI to enter point data and save it to an PointArtifact. - */ -public class ManualDatePointsEditor -extends ManualPointsEditor -{ - - public ManualDatePointsEditor(Collection collection, - RedrawRequestHandler handler, String outputModeName - ) { - super (collection, handler, outputModeName); - } - - - /** Create and setup/add the ui. */ - @Override - public void createUI() { - Button accept = new Button(MSG.label_ok()); - Button cancel = new Button(MSG.label_cancel()); - cancel.addClickHandler(this); - - accept.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - okClicked(); - } - }); - - HLayout buttons = new HLayout(); - buttons.addMember(accept); - buttons.addMember(cancel); - buttons.setAlign(Alignment.CENTER); - buttons.setHeight(30); - - VLayout layout = new VLayout(); - listGrid = new ListGrid(); - listGrid.setWidth100(); - listGrid.setHeight("*"); - listGrid.setCanSort(false); - listGrid.setCanEdit(true); - listGrid.setShowHeaderContextMenu(false); - - CellFormatter doubleFormat = new CellFormatter() { - @Override - public String format(Object value, ListGridRecord record, int rowNum, int colNum) { - if(value != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(value.toString()).doubleValue(); - return nf.format(d); - } catch (Exception e) { - return value.toString(); - } - } else { - return null; - } - }}; - - CellFormatter dateFormat = new CellFormatter() { - @Override - public String format(Object value, ListGridRecord record, int rowNum, int colNum) { - if(value != null && !value.toString().equals("")) { - try { - DateTimeFormat df = - DateTimeFormat.getFormat("dd.MM.yyyy"); - Date d = df.parse(value.toString()); - DateTimeFormat df2 = - DateTimeFormat.getFormat( - DateTimeFormat.PredefinedFormat.DATE_MEDIUM); - return df2.format(d); - - } - catch(IllegalArgumentException iae) { - SC.warn(MSG.error_invalid_date()); - record.setAttribute(DatePointRecord.ATTRIBUTE_X, ""); - return ""; - } - } - else { - return null; - } - }}; - - - CellEditValueParser cevp = new CellEditValueParser() { - @Override - public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { - if (value == null) - return null; - try { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double d = nf.parse(value.toString()); - return (new Double(d)).toString(); - } - catch(NumberFormatException nfe) { - return value; - } - } - }; - - CellEditValueFormatter cevf = new CellEditValueFormatter() { - @Override - public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { - if (value != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(value.toString()).doubleValue(); - return nf.format(d); - } catch (Exception e) { - return value.toString(); - } - } - return null; - } - }; - - // Use X and Y as default fallback. - String xAxis = "X"; - String yAxis = "Y"; - - // Get header text from collection settings. - Settings settings = this.collection.getSettings(outputModeName); - List<Property> axes = settings.getSettings("axes"); - if(axes != null) { - for (Property p: axes) { - PropertyGroup pg = (PropertyGroup)p; - StringProperty id = - (StringProperty)pg.getPropertyByName("id"); - if(id.getValue().equals("X")) { - StringProperty name = - (StringProperty)pg.getPropertyByName("label"); - xAxis = name.getValue(); - } - else if (yAxis.equals("Y")) { - StringProperty name = - (StringProperty)pg.getPropertyByName("label"); - yAxis = name.getValue(); - } - } - } - ListGridField xField = - new ListGridField(PointRecord.ATTRIBUTE_X, xAxis); - xField.setType(ListGridFieldType.TEXT); - xField.setCellFormatter(dateFormat); - - ListGridField yField = - new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis); - yField.setType(ListGridFieldType.FLOAT); - yField.setCellFormatter(doubleFormat); - yField.setEditValueParser(cevp); - yField.setEditValueFormatter(cevf); - - ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME, - MSG.pointname()); - final ListGridField removeField = - new ListGridField("_removeRecord", MSG.removepoint()){{ - setType(ListGridFieldType.ICON); - setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); - setCanEdit(false); - setCanFilter(false); - setCanSort(false); - setCanGroupBy(false); - setCanFreeze(false); - setWidth(25); - }}; - - ListGridField activeField = new ListGridField( - PointRecord.ATTRIBUTE_ACTIVE, MSG.selection()); - activeField.setType(ListGridFieldType.BOOLEAN); - activeField.setDefaultValue(true); - - listGrid.setFields(new ListGridField[] {activeField, xField, yField, - nameField, removeField}); - - listGrid.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(final RecordClickEvent event) { - // Just handle remove-clicks - if(!event.getField().getName().equals(removeField.getName())) { - return; - } - event.getViewer().removeData(event.getRecord()); - } - }); - - // Find the artifacts uuid. - findManualPointsUUID(); - CollectionItem item = collection.getItem(uuid); - - // Add points to grid. - if (item != null) { - String jsonData = item.getData().get(outputModeName + "." + POINT_DATA); - JSONArray jsonArray = (JSONArray) JSONParser.parse(jsonData); - for (int i = 0; i < jsonArray.size(); i++) { - JSONArray point = (JSONArray) jsonArray.get(i); - listGrid.addData(datePointRecordFromJSON(point)); - } - } - else { - GWT.log("No item found for " + uuid); - } - - IButton button = new IButton(MSG.newpoint()); - button.setTop(250); - button.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - listGrid.startEditingNew(); - } - }); - - layout.addMember(listGrid); - layout.addMember(button); - - addItem(layout); - - addItem(buttons); - setWidth(380); - setHeight(470); - centerInPage(); - } - - - /** Create JSON representation of the points present in the list grid. */ - @Override - protected JSONArray jsonArrayFromListGrid() { - JSONArray list = new JSONArray(); - int idx = 0; - - for(ListGridRecord record : listGrid.getRecords()) { - if (record instanceof DatePointRecord) { - JSONArray data = new JSONArray(); - - DatePointRecord point = (DatePointRecord) record; - String dateString = point.getX(); - DateTimeFormat df = DateTimeFormat.getFormat( - DateTimeFormat.PredefinedFormat.DATE_MEDIUM); - - Date d = df.parse(dateString); - double dv = d.getTime(); - - data.set(0, new JSONNumber(dv)); - data.set(1, new JSONNumber(point.getY())); - data.set(2, new JSONString(point.getName())); - data.set(3, JSONBoolean.getInstance(point.isActive())); - - list.set(idx, data); - idx++; - } - else { - JSONArray data = new JSONArray(); - - String nameString = record.getAttributeAsString(PointRecord.ATTRIBUTE_NAME); - // Apply default name if none set. - if (nameString == null || nameString.equals("")) { - String xString = record.getAttributeAsString( - PointRecord.ATTRIBUTE_X); - String yString = record.getAttributeAsString( - PointRecord.ATTRIBUTE_Y); - nameString = xString + "/" + yString; - } - - String dateString = record.getAttributeAsString(PointRecord.ATTRIBUTE_X); - DateTimeFormat df = DateTimeFormat.getFormat( - DateTimeFormat.PredefinedFormat.DATE_MEDIUM); - - Date d = df.parse(dateString); - double dv = d.getTime(); - data.set(0, new JSONNumber(dv)); - data.set(1, new JSONNumber(record. - getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); - data.set(2, new JSONString(nameString)); - data.set(3, JSONBoolean.getInstance(record.getAttributeAsBoolean( - PointRecord.ATTRIBUTE_ACTIVE))); - - list.set(idx, data); - idx++; - } - } - return list; - } - - /** From a JSON-encoded point, create a PointRecord. */ - public DatePointRecord datePointRecordFromJSON(JSONArray jsonArray) { - JSONNumber x = (JSONNumber) jsonArray.get(0); - JSONNumber y = (JSONNumber) jsonArray.get(1); - JSONString s = (JSONString) jsonArray.get(2); - JSONBoolean b = (JSONBoolean) jsonArray.get(3); - - Date d = new Date (Long.valueOf(x.toString()).longValue()); - DateTimeFormat df = DateTimeFormat.getFormat( - DateTimeFormat.PredefinedFormat.DATE_MEDIUM); - - return new DatePointRecord(b.booleanValue(), df.format(d), - y.doubleValue(), s.stringValue()); - } - - - /** Return false if x or y attribute is missing. */ - @Override - protected boolean isDialogValid() { - boolean valid = true; - for (ListGridRecord record : listGrid.getRecords()) { - if (record.getAttributeAsString(PointRecord.ATTRIBUTE_X) == null || - record.getAttributeAsString( - DatePointRecord.ATTRIBUTE_X).equals("") || - record.getAttributeAsDouble(PointRecord.ATTRIBUTE_Y) == null) { - return false; - } - } - if (listGrid.hasErrors()) { - valid = false; - } - return valid; - } - - - /** Simple record to store points. */ - public class DatePointRecord extends ListGridRecord { - protected static final String ATTRIBUTE_X = "X"; - protected static final String ATTRIBUTE_Y = "Y"; - protected static final String ATTRIBUTE_NAME = "name"; - protected static final String ATTRIBUTE_ACTIVE = "active"; - - private DatePointRecord() {;} - - public DatePointRecord(boolean b, String x, double y, String name) { - setActive(b); - setName(name); - setX(x); - setY(y); - } - - public void setActive(boolean b) { - setAttribute(ATTRIBUTE_ACTIVE, b); - } - - public boolean isActive() { - return getAttributeAsBoolean(ATTRIBUTE_ACTIVE); - } - - public void setName(String name) { - setAttribute(ATTRIBUTE_NAME, name); - } - - public String getName() { - return getAttributeAsString(ATTRIBUTE_NAME); - } - - public void setX(String x) { - setAttribute(ATTRIBUTE_X, x); - } - - public void setY(double y) { - setAttribute(ATTRIBUTE_Y, y); - } - - public String getX() { - return getAttributeAsString(ATTRIBUTE_X); - } - - public double getY() { - return getAttributeAsDouble(ATTRIBUTE_Y); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,535 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONBoolean; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.json.client.JSONString; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.IButton; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.grid.CellEditValueFormatter; -import com.smartgwt.client.widgets.grid.CellEditValueParser; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.RedrawRequestEvent; -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.client.services.FeedServiceAsync; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItem; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DefaultArtifact; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.Property; -import de.intevation.flys.client.shared.model.PropertyGroup; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.Settings; -import de.intevation.flys.client.shared.model.StringProperty; - -import java.util.Date; -import java.util.List; - - -/** - * UI to enter point data and save it to an PointArtifact. - */ -public class ManualPointsEditor -extends Window -implements ClickHandler -{ - /** The interface that provides i18n messages. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** Part of name of the main data item to be fed. */ - public static final String POINT_DATA = "manualpoints.data"; - - /** When we chaged something, we need a RedrawRequest(Handler). */ - protected RedrawRequestHandler redrawRequestHandler; - - /** The collection */ - protected Collection collection; - - /** The listGrid showing point entries. */ - protected ListGrid listGrid; - - protected ListGridFieldType fieldTypeX = ListGridFieldType.FLOAT; - - /** Service handle to clone and add artifacts to collection. */ - LoadArtifactServiceAsync loadArtifactService = GWT.create( - de.intevation.flys.client.client.services.LoadArtifactService.class); - - /** Service to feed the artifact with new point-data. */ - FeedServiceAsync feedService = GWT.create( - de.intevation.flys.client.client.services.FeedService.class); - - /** UUID of artifact to feed. */ - protected String uuid; - - /** Name of the outputmode, important when feeding data. */ - protected String outputModeName; - - /** Name of the point data item. */ - protected String pointDataItemName; - - - /** - * Setup editor dialog. - * @param collection The collection to use. - */ - public ManualPointsEditor(Collection collection, - RedrawRequestHandler handler, String outputModeName - ) { - this.collection = collection; - this.redrawRequestHandler = handler; - this.outputModeName = outputModeName; - this.pointDataItemName = outputModeName + "." + POINT_DATA; - init(); - } - - - /** Searches collection for first artifact to serve (manual) point data. */ - public String findManualPointsUUID() { - // TODO Need to be more picky (different points in different diagrams) - int size = collection.getItemLength(); - - for (int i = 0; i < size; i++) { - CollectionItem item = collection.getItem(i); - String dataValue = item.getData().get(pointDataItemName); - if (dataValue != null) { - // Found it. - uuid = item.identifier(); - return uuid; - } - } - - return null; - } - - - /** - * Initialize the editor window and its components. - */ - protected void init() { - setTitle(MSG.addpoints()); - setCanDragReposition(true); - setCanDragResize(true); - - // If no manualpoints artifact found, create it now. - if(findManualPointsUUID() == null) { - addArtifactCreateUI(); - } - else { - createUI(); - } - } - - - /** Create and setup/add the ui. */ - public void createUI() { - Button accept = new Button(MSG.label_ok()); - Button cancel = new Button(MSG.label_cancel()); - cancel.addClickHandler(this); - - accept.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - okClicked(); - } - }); - - HLayout buttons = new HLayout(); - buttons.addMember(accept); - buttons.addMember(cancel); - buttons.setAlign(Alignment.CENTER); - buttons.setHeight(30); - - VLayout layout = new VLayout(); - listGrid = new ListGrid(); - listGrid.setWidth100(); - listGrid.setHeight("*"); - listGrid.setCanSort(false); - listGrid.setCanEdit(true); - listGrid.setShowHeaderContextMenu(false); - - // Use X and Y as default fallback. - String xAxis = "X"; - String yAxis = "Y"; - - // Get header text from collection settings - Settings settings = this.collection.getSettings(outputModeName); - List<Property> axes = settings.getSettings("axes"); - if(axes != null) { - for (Property p: axes) { - PropertyGroup pg = (PropertyGroup)p; - GWT.log(pg.toString()); - StringProperty id = - (StringProperty)pg.getPropertyByName("id"); - if(id.getValue().equals("X")) { - StringProperty name = - (StringProperty)pg.getPropertyByName("label"); - xAxis = name.getValue(); - } - else if (yAxis.equals("Y")) { - StringProperty name = - (StringProperty)pg.getPropertyByName("label"); - yAxis = name.getValue(); - } - } - } - - CellFormatter format = createCellFormatter(); - CellEditValueParser cevp = createCellEditValueParser(); - CellEditValueFormatter cevf = createCellEditValueFormatter(); - - ListGridField xField = - new ListGridField(PointRecord.ATTRIBUTE_X, xAxis); - if(xAxis.equalsIgnoreCase("date") || xAxis.equalsIgnoreCase("Datum")) { - // FIXME: This is a hack for Timeseries charts with Date types on the x axis - xField.setType(ListGridFieldType.DATE); - this.fieldTypeX = ListGridFieldType.DATE; - } - else { - xField.setType(ListGridFieldType.FLOAT); - xField.setCellFormatter(format); - xField.setEditValueParser(cevp); - xField.setEditValueFormatter(cevf); - } - - ListGridField yField = - new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis); - yField.setType(ListGridFieldType.FLOAT); - yField.setCellFormatter(format); - yField.setEditValueParser(cevp); - yField.setEditValueFormatter(cevf); - - ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME, - MSG.pointname()); - final ListGridField removeField = - new ListGridField("_removeRecord", MSG.removepoint()){{ - setType(ListGridFieldType.ICON); - setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); - setCanEdit(false); - setCanFilter(false); - setCanSort(false); - setCanGroupBy(false); - setCanFreeze(false); - setWidth(25); - }}; - - ListGridField activeField = new ListGridField( - PointRecord.ATTRIBUTE_ACTIVE, MSG.selection()); - activeField.setType(ListGridFieldType.BOOLEAN); - activeField.setDefaultValue(true); - - listGrid.setFields(new ListGridField[] {activeField, xField, yField, - nameField, removeField}); - - listGrid.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(final RecordClickEvent event) { - // Just handle remove-clicks - if(!event.getField().getName().equals(removeField.getName())) { - return; - } - event.getViewer().removeData(event.getRecord()); - } - }); - - // Find the artifacts uuid - findManualPointsUUID(); - CollectionItem item = collection.getItem(uuid); - - // Add points to grid - if (item != null) { - // TODO store this from findPointUUID instead (we touched these). - String jsonData = item.getData().get(pointDataItemName); - JSONArray jsonArray = (JSONArray) JSONParser.parse(jsonData); - for (int i = 0; i < jsonArray.size(); i++) { - JSONArray point = (JSONArray) jsonArray.get(i); - listGrid.addData(PointRecord.fromJSON(point)); - } - } - else { - GWT.log("ManualPointsEditor: No item found for " + uuid); - } - - IButton button = new IButton(MSG.newpoint()); - button.setTop(250); - button.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - listGrid.startEditingNew(); - } - }); - - layout.addMember(listGrid); - layout.addMember(button); - - addItem(layout); - - addItem(buttons); - setWidth(380); - setHeight(470); - centerInPage(); - } - - - protected CellFormatter createCellFormatter() { - return new CellFormatter() { - @Override - public String format(Object value, ListGridRecord record, int rowNum, int colNum) { - if(value != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(value.toString()).doubleValue(); - return nf.format(d); - } catch (Exception e) { - return value.toString(); - } - } else { - return null; - } - }}; - } - - - protected CellEditValueParser createCellEditValueParser() { - return new CellEditValueParser() { - @Override - public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { - if (value == null) - return null; - try { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double d = nf.parse(value.toString()); - return (new Double(d)).toString(); - } - catch(NumberFormatException nfe) { - return value; - } - } - }; - } - - - protected CellEditValueFormatter createCellEditValueFormatter() { - return new CellEditValueFormatter() { - @Override - public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { - if (value == null) { - return ""; - } - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(value.toString()).doubleValue(); - return nf.format(d); - } - catch(NumberFormatException nfe) { - return value; - } - } - }; - } - - protected String getLocaleDateFormat() { - String loc = Config.getInstance().getLocale(); - if ("de".equals(loc)) { - return "yy.MM.yyyy"; - } - else { - return "MM/dd/yyyy"; - } - } - - protected String formatDate(Date date) { - DateTimeFormat dtf = DateTimeFormat.getFormat(getLocaleDateFormat()); - return dtf.format(date); - } - - /** Create JSON representation of the points present in the list grid. */ - protected JSONArray jsonArrayFromListGrid() { - JSONArray list = new JSONArray(); - int idx = 0; - - for(ListGridRecord record : listGrid.getRecords()) { - if (record instanceof PointRecord) { - JSONArray data = new JSONArray(); - - PointRecord point = (PointRecord) record; - if(point.isTimeseriesPoint()) { - data.set(0, new JSONString(point.getXAsDate())); - GWT.log("Date: " + point.getXAsDate()); - } - else { - data.set(0, new JSONNumber(point.getX())); - } - data.set(1, new JSONNumber(point.getY())); - data.set(2, new JSONString(point.getName())); - data.set(3, JSONBoolean.getInstance(point.isActive())); - - list.set(idx, data); - idx++; - } - else { - JSONArray data = new JSONArray(); - - String nameString = record.getAttributeAsString(PointRecord.ATTRIBUTE_NAME); - // Apply default name if none set. - if (nameString == null || nameString.equals("")) { - String xString = record.getAttributeAsString( - PointRecord.ATTRIBUTE_X); - String yString = record.getAttributeAsString( - PointRecord.ATTRIBUTE_Y); - nameString = xString + "/" + yString; - } - - if(fieldTypeX.equals(ListGridFieldType.DATE)) { - Date date = record.getAttributeAsDate(PointRecord.ATTRIBUTE_X); - data.set(0, new JSONString(formatDate(date))); - GWT.log("Date: " + formatDate(date)); - } - else { - data.set(0, new JSONNumber(record. - getAttributeAsDouble(PointRecord.ATTRIBUTE_X))); - } - data.set(1, new JSONNumber(record. - getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); - data.set(2, new JSONString(nameString)); - data.set(3, JSONBoolean.getInstance(record.getAttributeAsBoolean( - PointRecord.ATTRIBUTE_ACTIVE))); - - list.set(idx, data); - idx++; - } - } - return list; - } - - - /** - * Called when OK Button was clicked. Then, if entered values are valid, - * fire a RedrawRequest and destroy. - */ - protected void okClicked() { - if(isDialogValid()) { - // Feed JSON-encoded content of listgrid. - JSONArray list = jsonArrayFromListGrid(); - - Data[] feedData = new Data[] { - DefaultData.createSimpleStringData(pointDataItemName, - list.toString()) - }; - - feedService.feed( - Config.getInstance().getLocale(), - new DefaultArtifact(uuid, "TODO:hash"), - feedData, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not feed artifact with points."); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - @Override - public void onSuccess(Artifact fartifact) { - GWT.log("Successfully set points"); - redrawRequestHandler.onRedrawRequest( - new RedrawRequestEvent()); - destroy(); - } - }); - } - else { - GWT.log("Dialog not valid"); - SC.warn(MSG.error_dialog_not_valid()); - } - } - - - /** Add a ManualPointArtifact to Collection. */ - public void addArtifactCreateUI() { - final Label standByLabel = new Label(MSG.standby()); - addItem(standByLabel); - - setWidth(380); - setHeight(470); - centerInPage(); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - loadArtifactService.load( - this.collection, - new Recommendation("manualpoints", ""), - "manualpoints", - locale, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Creating manualpoint artifact failed!"); - } - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully created artifact."); - removeItem(standByLabel); - uuid = artifact.getUuid(); - createUI(); - } - }); - } - - - /** - * This method is called when the user aborts point editing. - * @param event The event. - */ - @Override - public void onClick(ClickEvent event) { - this.destroy(); - } - - - /** Return false if x or y attribute is missing. */ - protected boolean isDialogValid() { - boolean valid = true; - for (ListGridRecord record : listGrid.getRecords()) { - try { - if (record.getAttribute(PointRecord.ATTRIBUTE_X) == null - || record.getAttribute(PointRecord.ATTRIBUTE_Y) == null) { - return false; - } - } - catch(IllegalArgumentException ex) { - - } - } - if (listGrid.hasErrors()) { - valid = false; - } - return valid; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,355 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.json.client.JSONString; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.RedrawRequestEvent; -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.client.services.FeedServiceAsync; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.client.utils.DoubleValidator; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItem; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DefaultArtifact; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.Property; -import de.intevation.flys.client.shared.model.PropertyGroup; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.Settings; -import de.intevation.flys.client.shared.model.StringProperty; - -import java.util.List; -import java.util.Map; - -/** - * UI to enter point data and save it to an PointArtifact. - */ -public class ManualWSPEditor -extends Window -implements ClickHandler -{ - /** The interface that provides i18n messages. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** Name of the main data item to be fed. */ - public static final String LINE_DATA = "manualpoints.lines"; - - /** When we change something, we need a RedrawRequest(Handler). */ - protected RedrawRequestHandler redrawRequestHandler; - - /** The collection */ - protected Collection collection; - - /** Service handle to clone and add artifacts to collection. */ - LoadArtifactServiceAsync loadArtifactService = GWT.create( - de.intevation.flys.client.client.services.LoadArtifactService.class); - - /** Service to feed the artifact with new point-data. */ - FeedServiceAsync feedService = GWT.create( - de.intevation.flys.client.client.services.FeedService.class); - - /** UUID of artifact to feed. */ - protected String uuid; - - /** Name of the outputmode, important when feeding data. */ - protected String outputModeName; - - /** Name of the data item for lines in this context. */ - protected String dataItemName; - - /** Input Field for y-coor of line. */ - protected TextItem valueInputPanel; - - /** Input Field for name of line. */ - protected TextItem nameInputPanel; - - /** Line data that is not added in this session. */ - protected JSONArray oldLines = null; - - - /** - * Setup editor dialog. - * @param collection The collection to use. - */ - public ManualWSPEditor(Collection collection, - RedrawRequestHandler handler, String outputModeName - ) { - this.collection = collection; - this.redrawRequestHandler = handler; - this.outputModeName = outputModeName; - this.dataItemName = outputModeName + "." + LINE_DATA; - init(); - } - - - /** Searches collection for first artifact to serve (manual) line data. */ - public String findManualPointsUUID() { - int size = collection.getItemLength(); - - for (int i = 0; i < size; i++) { - CollectionItem item = collection.getItem(i); - String dataValue = item.getData().get(dataItemName); - if (dataValue != null) { - // Found it. - uuid = item.identifier(); - return uuid; - } - } - - return null; - } - - - /** - * Initialize the editor window and its components. - */ - protected void init() { - setTitle(MSG.addWSP()); - setCanDragReposition(true); - setCanDragResize(true); - - if(findManualPointsUUID() == null) { - addArtifactCreateUI(); - } - else { - createUI(); - } - } - - - /** Create and setup/add the ui. */ - public void createUI() { - Button accept = new Button(MSG.label_ok()); - Button cancel = new Button(MSG.label_cancel()); - cancel.addClickHandler(this); - - accept.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - okClicked(); - } - }); - - HLayout buttons = new HLayout(); - buttons.addMember(accept); - buttons.addMember(cancel); - buttons.setAlign(Alignment.CENTER); - buttons.setHeight(30); - - // Use X and Y as default fallback. - String yAxis = "Y"; - - // Get header text from collection settings. - Settings settings = this.collection.getSettings(outputModeName); - List<Property> axes = settings.getSettings("axes"); - if(axes != null) { - for (Property p: axes) { - PropertyGroup pg = (PropertyGroup)p; - StringProperty id = - (StringProperty)pg.getPropertyByName("id"); - if (id.getValue().equals("W")) { - StringProperty name = - (StringProperty)pg.getPropertyByName("label"); - yAxis = name.getValue(); - } - } - } - - DynamicForm form = new DynamicForm(); - valueInputPanel = new TextItem(); - valueInputPanel.setTitle(yAxis); - valueInputPanel.setShowTitle(true); - valueInputPanel.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent e) { - DoubleValidator validator = new DoubleValidator(); - Map errors = e.getForm().getErrors(); - validator.validate(e.getItem(), errors); - e.getForm().setErrors(errors, true); - } - }); - nameInputPanel = new TextItem(); - nameInputPanel.setTitle(MSG.pointname()); - nameInputPanel.setShowTitle(true); - form.setFields(valueInputPanel, nameInputPanel); - - VLayout layout = new VLayout(); - layout.addMember(form); - - // Find the artifacts uuid. - // TODO this has been called already, why call it again? - findManualPointsUUID(); - CollectionItem item = collection.getItem(uuid); - - // Store the old line data. - if (item != null) { - String jsonData = item.getData().get(dataItemName); - oldLines = (JSONArray) JSONParser.parse(jsonData); - } - else { - GWT.log("No old lines found for " + uuid); - } - - addItem(layout); - - addItem(buttons); - setWidth(360); - setHeight(120); - centerInPage(); - } - - - /** - * Create JSON representation of the points present in the form. - * Add old data, too. - * @return a jsonarray with the old and the new lines. - */ - protected JSONArray jsonArrayFromForm() { - if (oldLines == null) { - oldLines = new JSONArray(); - } - - double val; - if (valueInputPanel.getValue() == null) - return oldLines; - try { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double d = nf.parse(valueInputPanel.getValue().toString()); - val = d; - } - catch(NumberFormatException nfe) { - GWT.log("fehler... nfe... TODO"); - return oldLines; - } - - JSONArray data = new JSONArray(); - data.set(0, new JSONNumber(val)); - if (nameInputPanel.getValue() == null) { - data.set(1, new JSONString(valueInputPanel.getValue().toString())); - } - else { - data.set(1, new JSONString(nameInputPanel.getValue().toString())); - } - oldLines.set(oldLines.size(), data); - - return oldLines; - } - - - /** - * Called when OK Button was clicked. Then, if entered values are valid, - * fire a RedrawRequest and destroy. - */ - protected void okClicked() { - if (valueInputPanel.getValue() == null) { - return; - } - GWT.log(valueInputPanel.getValue().toString()); - if(isDialogValid()) { - // Feed JSON-encoded content of form. - JSONArray list = jsonArrayFromForm(); - - Data[] feedData = new Data[] { - DefaultData.createSimpleStringData(dataItemName, - list.toString()) - }; - - feedService.feed( - Config.getInstance().getLocale(), - new DefaultArtifact(uuid, "TODO:hash"), - feedData, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not feed artifact with lines."); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - @Override - public void onSuccess(Artifact fartifact) { - GWT.log("Successfully set lines "); - redrawRequestHandler.onRedrawRequest( - new RedrawRequestEvent()); - destroy(); - } - }); - } - else { - GWT.log("Dialog not valid"); - SC.warn(MSG.error_dialog_not_valid()); - } - } - - - /** Add a ManualPointArtifact to Collection. */ - public void addArtifactCreateUI() { - final Label standByLabel = new Label(MSG.standby()); - addItem(standByLabel); - - setWidth(360); - setHeight(120); - centerInPage(); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - loadArtifactService.load( - this.collection, - new Recommendation("manualpoints", ""), - "manualpoints", - locale, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Creating manualpoint artifact failed!"); - } - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully created artifact."); - removeItem(standByLabel); - uuid = artifact.getUuid(); - createUI(); - } - }); - } - - - /** - * This method is called when the user aborts point editing. - * @param event The event. - */ - @Override - public void onClick(ClickEvent event) { - this.destroy(); - } - - - /** Return false if x or y attribute is missing. */ - protected boolean isDialogValid() { - return (DoubleValidator.isDouble(valueInputPanel.getValue())); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import java.util.ArrayList; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.events.MouseMoveEvent; -import com.smartgwt.client.widgets.events.MouseMoveHandler; - -import de.intevation.flys.client.shared.Transform2D; - - -/** - * Panel showing the mouse position in data space. - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MousePositionPanel extends HLayout implements MouseMoveHandler { - - /** Is associated to a ChartTab. */ - protected ChartOutputTab chartTab; - - protected HLayout xLayout; - protected ArrayList<HLayout> yLayouts; - - - public MousePositionPanel(ChartOutputTab chartTab) { - super(); - - this.chartTab = chartTab; - - chartTab.getChartPanel().addMouseMoveHandler(this); - - initLayout(); - } - - - /** - * Initializes the layout of this component. <b>Note:</b> This layout has a - * fixed width of 195px plus a margin of 5px. - */ - protected void initLayout() { - setMembersMargin(5); - - xLayout = null; - yLayouts = new ArrayList<HLayout>(); - } - - - /** - * Listens to mouse move events to refresh the xy position. - * - * @param event The move event. - */ - public void onMouseMove(MouseMoveEvent event) { - updateMousePosition(event.getX(), event.getY()); - } - - - /** - * This method takes pixel coordinates, transforms those values into chart - * coordinates using the Transform2D class and updates the mouse position. - * - * @param x The x part of the pixel. - * @param y The y part of the pixel. - */ - public void updateMousePosition(double x, double y) { - int transformerCount = chartTab.getTransformerCount(); - - Canvas chart = chartTab.getChartPanel(); - int xOffset = chart.getPageLeft(); - int yOffset = chart.getPageTop(); - - x = x - xOffset; - y = y - yOffset; - - // Create Layout for x coordinates. - if (xLayout == null){ - Label xDesc = new Label("Position: X = "); - Label xLabel = new Label(); - xLayout = new HLayout(); - xLayout.setWidth(125); - xLayout.addMember(xDesc); - xLayout.addMember(xLabel); - xDesc.setWidth(70); - xLabel.setWidth(55); - addMember(xLayout); - } - - for (int i = 0; i < transformerCount; i++) { - HLayout yLayout = null; - // If no layout exists for this y axis, create one. - // else use the existing one. - if (yLayouts.size() <= i) { - Label yDesc = new Label("Y" + (i+1) + " = "); - Label yLabel = new Label(); - yLayout = new HLayout(); - yLayout.setWidth(80); - yLayout.addMember(yDesc); - yLayout.addMember(yLabel); - yDesc.setWidth(30); - yLabel.setWidth(50); - addMember(yLayout); - yLayouts.add(i, yLayout); - } - else { - yLayout = yLayouts.get(i); - } - - Transform2D transformer = chartTab.getTransformer(i); - - if (transformer == null) { - return; - } - - // Get the label for the coordinates. - Canvas xLabel = xLayout.getMember(1); - Canvas yLabel = yLayout.getMember(1); - - double[] xy = transformer.transform(x, y); - String[] xyStr = transformer.format(new Number[] { - new Double(xy[0]), new Double(xy[1]) }); - // Set the coordinates. - xLabel.setContents(xyStr[0]); - yLabel.setContents(xyStr[1]); - } - - // Remove y coordinates. - if (yLayouts.size() > transformerCount) { - for (int i = yLayouts.size() - 1; i >= transformerCount; i--) { - removeMember(yLayouts.get(i)); - yLayouts.remove(i); - } - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,336 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import java.util.Map; -import java.util.HashMap; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.Alignment; - -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; - -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; - -import com.smartgwt.client.widgets.form.DynamicForm; - -import com.smartgwt.client.widgets.form.fields.TextItem; - -import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; -import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; - -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; -import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; - -import de.intevation.flys.client.client.Config; - -import de.intevation.flys.client.client.ui.CollectionView; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.FixAnalysisArtifact; -import de.intevation.flys.client.shared.model.FixFilter; -import de.intevation.flys.client.shared.model.OutputMode; - -import java.util.Date; - - -/** - * Tab representing and showing one Chart-output with a "navi" thing. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class NaviChartOutputTab -extends ChartOutputTab -implements TabSelectedHandler -{ - protected TextItem currentkm; - - public NaviChartOutputTab( - String title, - Collection collection, - OutputMode mode, - CollectionView collectionView - ){ - super(title, collection, mode, collectionView); - right.removeChild(chart); - right.addChild(createNaviChart()); - collectionView.registerTabHandler(this); - } - - - protected Canvas createNaviChart() { - final Artifact art = collectionView.getArtifact(); - VLayout root = new VLayout(); - root.setWidth100(); - root.setHeight100(); - - HLayout layout = new HLayout(); - layout.setAlign(Alignment.CENTER); - - DynamicForm form = new DynamicForm(); - Button lower = new Button("<<"); - lower.setWidth(30); - Button upper = new Button(">>"); - upper.setWidth(30); - currentkm = new TextItem(); - currentkm.setWidth(60); - currentkm.setShowTitle(false); - - form.setFields(currentkm); - form.setWidth(60); - - double fromKm; - double toKm; - - if (art instanceof FixAnalysisArtifact) { - FixAnalysisArtifact fix = (FixAnalysisArtifact) art; - FixFilter fixFilter = fix.getFilter(); - String s = fix.getArtifactDescription().getDataValueAsString("ld_step"); - try { - double ds = Double.parseDouble(s); - collectionView.setSteps(ds); - } - catch(NumberFormatException nfe) { - collectionView.setSteps(100d); - } - fromKm = fixFilter.getFromKm(); - toKm = fixFilter.getToKm(); - } - else { - // Probably WINFOArtifact kind of artifact. - String ld_step = - art.getArtifactDescription().getDataValueAsString("ld_step"); - try { - collectionView.setSteps(Double.valueOf(ld_step)); - } - catch (Exception e) { - GWT.log("No ld_steps data or not parsable."); - return root; - } - - double[] kmRange = art.getArtifactDescription().getKMRange(); - if (kmRange == null || kmRange.length == 2) { - fromKm = kmRange[0]; - toKm = kmRange[1]; - } - else { - GWT.log("No KM range in description found."); - return root; - } - } - - collectionView.setMinKm(fromKm); - collectionView.setMaxKm(toKm); - - final NumberFormat nf = NumberFormat.getDecimalFormat(); - if (collectionView.getCurrentKm() == -1d) { - try { - double d = Double.valueOf(fromKm); - currentkm.setValue(nf.format(d)); - } catch (NumberFormatException e) { - currentkm.setValue(fromKm); - } - collectionView.setCurrentKm(fromKm); - } - else { - try { - double d = Double.valueOf(fromKm); - currentkm.setValue(nf.format(d)); - } catch (NumberFormatException e) { - currentkm.setValue(fromKm); - } - currentkm.setValue(collectionView.getCurrentKm()); - } - - lower.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent ce) { - tbarPanel.deselectControls(); - updateChartDown(); - try { - double d = Double.valueOf(collectionView.getCurrentKm()); - currentkm.setValue(nf.format(d)); - } catch (NumberFormatException e) { - currentkm.setValue(collectionView.getCurrentKm()); - } - } - }); - - upper.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent ce) { - tbarPanel.deselectControls(); - updateChartUp(); - try { - double d = Double.valueOf(collectionView.getCurrentKm()); - currentkm.setValue(nf.format(d)); - } catch (NumberFormatException e) { - currentkm.setValue(collectionView.getCurrentKm()); - } - } - }); - - currentkm.addKeyPressHandler(new KeyPressHandler() { - public void onKeyPress(KeyPressEvent kpe) { - if (!kpe.getKeyName().equals("Enter")) { - return; - } - if(kpe.getItem().getValue() != null) { - tbarPanel.deselectControls(); - try { - String s = kpe.getItem().getValue().toString(); - double d; - try { - d = nf.parse(s); - currentkm.setValue(nf.format(d)); - } catch (NumberFormatException e) { - d = -1d; - } - if (d <= collectionView.getMaxKm() && - d >= collectionView.getMinKm()) { - collectionView.setCurrentKm(d); - tbarPanel.updateLinks(); - if (right != null) { - updateChartPanel(); - updateChartInfo(); - } - } - } - catch(NumberFormatException nfe) { - // Do nothing. - } - } - } - }); - layout.addMember(lower); - layout.addMember(form); - layout.addMember(upper); - - root.addMember(chart); - root.addMember(layout); - return root; - } - - - /** Callback when km-up-button is clicked. - * Increases collectionViews KM and refreshes view. */ - protected void updateChartUp() { - double currentKm = collectionView.getCurrentKm(); - if (currentKm < collectionView.getMaxKm()) { - // Why this math? - double newVal = currentKm * 100; - newVal += (collectionView.getSteps() / 10); - collectionView.setCurrentKm((double)Math.round(newVal) / 100); - tbarPanel.updateLinks(); - updateChartPanel(); - updateChartInfo(); - } - } - - /** Callback when km-down-button is clicked. - * Decreases collectionViews KM and refreshes view. */ - protected void updateChartDown() { - double currentKm = collectionView.getCurrentKm(); - if (currentKm > collectionView.getMinKm()) { - // Why this math? - double newVal = currentKm * 100; - newVal -= (collectionView.getSteps() / 10); - collectionView.setCurrentKm((double)Math.round(newVal) / 100); - tbarPanel.updateLinks(); - updateChartPanel(); - updateChartInfo(); - } - - } - - /** - * Returns the existing chart panel. - * - * @return the existing chart panel. - */ - @Override - public Canvas getChartPanel() { - return chart; - } - - /** - * Builds the URL that points to the chart image. - * - * @param width The width of the requested chart. - * @param height The height of the requested chart. - * @param xr Optional x range (used for zooming). - * @param yr Optional y range (used for zooming). - * - * @return the URL to the chart image. - */ - @Override - protected String getImgUrl(int width, int height) { - Config config = Config.getInstance(); - - String imgUrl = GWT.getModuleBaseURL(); - imgUrl += "chart"; - imgUrl += "?uuid=" + collection.identifier(); - imgUrl += "&type=" + mode.getName(); - imgUrl += "&locale=" + config.getLocale(); - imgUrl += "×tamp=" + new Date().getTime(); - imgUrl += "&width=" + Integer.toString(width); - imgUrl += "&height=" + Integer.toString(height - 40); - - Number[] zoom = getZoomValues(); - - if (zoom != null) { - if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { - // a zoom range of 0-1 means displaying the whole range. In such - // case we don't need to zoom. - imgUrl += "&minx=" + zoom[0]; - imgUrl += "&maxx=" + zoom[1]; - } - - if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { - // a zoom range of 0-1 means displaying the whole range. In such - // case we don't need to zoom. - imgUrl += "&miny=" + zoom[2]; - imgUrl += "&maxy=" + zoom[3]; - } - } - - if (collectionView.getArtifact() instanceof FixAnalysisArtifact) { - if (collectionView.getCurrentKm() == -1) { - FixAnalysisArtifact fix = - (FixAnalysisArtifact) collectionView.getArtifact(); - collectionView.setCurrentKm(fix.getFilter().getFromKm()); - } - } - else if (collectionView.getCurrentKm() == -1) { - collectionView.setCurrentKm(collectionView.getArtifact().getArtifactDescription().getKMRange()[0]); - } - if (collectionView.getCurrentKm() != -1) { - imgUrl += "¤tKm=" + collectionView.getCurrentKm(); - } - - return imgUrl; - } - - public void onTabSelected(TabSelectedEvent tse) { - if (this.equals(tse.getTab())) { - updateChartPanel(); - updateChartInfo(); - currentkm.setValue(collectionView.getCurrentKm()); - } - } - - @Override - public Map<String, String> getChartAttributes() { - Map<String, String> attr = new HashMap<String, String>(); - - attr = super.getChartAttributes(); - attr.put("km", String.valueOf(collectionView.getCurrentKm())); - - return attr; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/OverviewOutputTab.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.core.client.GWT; - -import de.intevation.flys.client.client.event.OutputParameterChangeHandler; -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.ImgLink; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Theme; - - -public class OverviewOutputTab extends ChartOutputTab { - - private class NoChartThemePanel extends ChartThemePanel { - - public NoChartThemePanel(OutputMode mode, CollectionView view) { - super(mode, view); - } - - @Override - public void activateTheme(Theme theme, boolean active) { } - - @Override - public void feedTellArea( - final String artifact, - Theme under, - Theme over, - boolean between - ) { } - - @Override - public void createAreaArtifact( - final Theme over, - final Theme under, - final boolean between - ) { } - - @Override - public void addOutputParameterChangeHandler(OutputParameterChangeHandler h) { } - - @Override - public void addRedrawRequestHandler(RedrawRequestHandler h){ } - } - - - - private class MinimumChartToolbar extends ChartToolbar { - - public MinimumChartToolbar(ChartOutputTab tab) { - super(tab); - } - - @Override - protected void initTools() { - GWT.log("CREATE NEW MINIMALISTIC CHART TOOLBAR"); - ChartOutputTab chartTab = getChartOutputTab(); - - String baseUrl = GWT.getHostPageBaseURL(); - - downloadPNG = new ImgLink( - baseUrl + MSG.downloadPNG(), - chartTab.getExportUrl(-1, -1, "png"), - 20, - 20); - downloadPNG.setTooltip(MSG.downloadPNGTooltip()); - - initLayout(); - } - - - @Override - protected void initLayout() { - setWidth100(); - setHeight(PANEL_HEIGHT); - setMembersMargin(10); - setPadding(5); - setBorder("1px solid black"); - - addMember(downloadPNG); - } - } - - - - public OverviewOutputTab( - String title, - Collection collection, - OutputMode mode, - CollectionView collectionView - ){ - super(title, collection, mode, collectionView); - left.setVisible(false); - } - - - @Override - public ChartThemePanel createThemePanel( - OutputMode mode, CollectionView view - ) { - return new NoChartThemePanel(mode, view); - } - - @Override - public ChartToolbar createChartToolbar(ChartOutputTab tab) { - return new MinimumChartToolbar(tab); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/PanControl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,210 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.SelectionType; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.ImgButton; -import com.smartgwt.client.widgets.events.MouseDownEvent; -import com.smartgwt.client.widgets.events.MouseDownHandler; -import com.smartgwt.client.widgets.events.MouseMoveEvent; -import com.smartgwt.client.widgets.events.MouseMoveHandler; -import com.smartgwt.client.widgets.events.MouseOutEvent; -import com.smartgwt.client.widgets.events.MouseOutHandler; -import com.smartgwt.client.widgets.events.MouseUpEvent; -import com.smartgwt.client.widgets.events.MouseUpHandler; - -import de.intevation.flys.client.client.event.HasPanHandlers; -import de.intevation.flys.client.client.event.PanEvent; -import de.intevation.flys.client.client.event.PanHandler; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class PanControl -extends ImgButton -implements MouseDownHandler, MouseMoveHandler, MouseUpHandler, - MouseOutHandler, HasPanHandlers -{ - protected ChartOutputTab chartTab; - - protected List<PanHandler> handlers; - - protected int[] start; - protected int[] end; - - - public PanControl(ChartOutputTab chartTab, String imageUrl) { - super(); - - this.chartTab = chartTab; - this.handlers = new ArrayList<PanHandler>(); - this.start = new int[] { -1, -1 }; - this.end = new int[] { -1, -1 }; - - String baseUrl = GWT.getHostPageBaseURL(); - setSrc(baseUrl + imageUrl); - setActionType(SelectionType.CHECKBOX); - setSize(20); - setShowRollOver(false); - setSelected(false); - - chartTab.getChartPanel().addMouseDownHandler(this); - chartTab.getChartPanel().addMouseMoveHandler(this); - chartTab.getChartPanel().addMouseUpHandler(this); - chartTab.getChartPanel().addMouseOutHandler(this); - } - - - /** - * Method used to register a new PanHandler. - * - * @param handler A new PanHandler. - */ - public void addPanHandler(PanHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - /** - * This event starts the dragging operation if the control is activated. - * - * @param event The mouse down event which contains the start coordinates. - */ - public void onMouseDown(MouseDownEvent event) { - if (!isSelected()) { - return; - } - - start[0] = event.getX(); - start[1] = event.getY(); - - end[0] = start[0]; - end[1] = start[1]; - } - - - /** - * This event is used to reposition the chart image based on the current - * drag operation. - * - * @param event The move event which contains the new coordinates to update - * the chart image position. - */ - public void onMouseMove(MouseMoveEvent event) { - if (!isSelected() || start[0] == -1 || start[1] == -1) { - return; - } - - int x = event.getX() - end[0]; - int y = event.getY() - end[1]; - - end[0] = end[0] + x; - end[1] = end[1] + y; - - Canvas c = chartTab.getChartImg(); - c.moveBy(x, y); - } - - - /** - * This event stops the dragging operation and fires a DragEnd event to the - * registered listeners. - * - * @param event The mouse up event which contains the end coordinates. - */ - public void onMouseUp(MouseUpEvent event) { - if (!isSelected()) { - return; - } - - end[0] = event.getX(); - end[1] = event.getY(); - - Canvas c = chartTab.getChartImg(); - c.setLeft(0); - c.setTop(0); - - fireOnPan(); - - start[0] = -1; - start[1] = -1; - } - - - /** - * This event is used to cancel the current dragging operation. - * - * @param event The mouse out event. - */ - public void onMouseOut(MouseOutEvent event) { - int x = event.getX(); - int y = event.getY(); - - if (!isSelected() || !isMouseOut(x, y) || start[0] == -1) { - return; - } - - Canvas c = chartTab.getChartImg(); - c.setLeft(0); - c.setTop(0); - - fireOnPan(); - - start[0] = -1; - start[1] = -1; - } - - - /** - * This method is required to check manually if the mouse pointer really - * moves out the chart area. The MouseOutEvent is also fired if the mouse - * goes down which doesn't seem to be correct. So, we gonna check this - * manually. - * - * @param x The x coordinate. - * @param y The y coordinate. - * - * @return true, if the mouse is really out of the chart area, otherwise - * false. - */ - protected boolean isMouseOut(int x, int y) { - Canvas chart = chartTab.getChartImg(); - - if (chart instanceof Img) { - chart = chart.getParentElement(); - } - - int left = chart.getPageLeft(); - int right = chart.getPageRight(); - int top = chart.getPageTop(); - int bottom = chart.getPageBottom(); - - if (x <= left || x >= right || y <= top || y >= bottom) { - return true; - } - - return false; - } - - - /** - * A pan event is fired to inform the registered listeners about a pan - * operation has finished. - */ - protected void fireOnPan() { - PanEvent event = new PanEvent(start, end); - - for (PanHandler handler: handlers) { - handler.onPan(event); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/PointRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONBoolean; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONString; -import com.google.gwt.json.client.JSONValue; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - -/** Simple record to store points. */ -public class PointRecord extends ListGridRecord { - protected static final String ATTRIBUTE_X = "X"; - protected static final String ATTRIBUTE_Y = "Y"; - protected static final String ATTRIBUTE_NAME = "name"; - protected static final String ATTRIBUTE_ACTIVE = "active"; - - /** From a JSON-encoded point, create a PointRecord. */ - public static PointRecord fromJSON(JSONArray jsonArray) { - JSONValue x = jsonArray.get(0); - JSONNumber y = (JSONNumber) jsonArray.get(1); - JSONString s = (JSONString) jsonArray.get(2); - JSONBoolean b = (JSONBoolean)jsonArray.get(3); - - if(x instanceof JSONNumber) { - return new PointRecord( - b.booleanValue(), ((JSONNumber)x).doubleValue(), - y.doubleValue(), s.stringValue()); - } - else { - return new PointRecord( - b.booleanValue(), ((JSONString)x).stringValue(), - y.doubleValue(), s.stringValue()); - } - } - - protected boolean isTimeseriesPoint = false; - - public PointRecord(boolean isActive, double x, double y, String name) { - setActive(isActive); - setName(name); - setX(x); - setY(y); - } - - /** - * Constructor taking the x axis value as String representing a Date value. - * @param isActive - * @param x - * @param y - * @param name - */ - public PointRecord(boolean isActive, String x, double y, String name) { - setActive(isActive); - setName(name); - setX(x); - setY(y); - - this.isTimeseriesPoint = true; - } - - public void setActive(boolean isActive) { - setAttribute(ATTRIBUTE_ACTIVE, isActive); - } - - public boolean isActive() { - return getAttributeAsBoolean(ATTRIBUTE_ACTIVE); - } - - public boolean isTimeseriesPoint() { - return this.isTimeseriesPoint; - } - - public void setName(String name) { - setAttribute(ATTRIBUTE_NAME, name); - } - - public String getName() { - return getAttributeAsString(ATTRIBUTE_NAME); - } - - public void setX(double x) { - setAttribute(ATTRIBUTE_X, x); - } - - public void setX(String date) { - setAttribute(ATTRIBUTE_X, date); - } - - public void setY(double y) { - setAttribute(ATTRIBUTE_Y, y); - } - - public double getX() { - return getAttributeAsDouble(ATTRIBUTE_X); - } - - public String getXAsDate() { - return getAttributeAsString(ATTRIBUTE_X); - } - - public double getY() { - return getAttributeAsDouble(ATTRIBUTE_Y); - } -} \ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,324 +0,0 @@ -package de.intevation.flys.client.client.ui.chart; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.Positioning; -import com.smartgwt.client.types.SelectionType; -import com.smartgwt.client.widgets.ImgButton; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.events.MouseDownEvent; -import com.smartgwt.client.widgets.events.MouseDownHandler; -import com.smartgwt.client.widgets.events.MouseMoveEvent; -import com.smartgwt.client.widgets.events.MouseMoveHandler; -import com.smartgwt.client.widgets.events.MouseOutEvent; -import com.smartgwt.client.widgets.events.MouseOutHandler; -import com.smartgwt.client.widgets.events.MouseUpEvent; -import com.smartgwt.client.widgets.events.MouseUpHandler; - -import de.intevation.flys.client.client.event.HasZoomHandlers; -import de.intevation.flys.client.client.event.ZoomEvent; -import de.intevation.flys.client.client.event.ZoomHandler; - - -/** - * This control observes that panel retrieved by ChartOutputTab.getChartPanel(). - * If activated, a zoombox is drawn. One of the two edges is the position of the - * mouse down event on the observed panel. The other edge is specified by the - * current mouse position. If the mouse up event occurs, start and end point - * relative to the left and upper border of the observed panel is determined and - * a ZoomEvent is fired. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ZoomboxControl -extends ImgButton -implements MouseDownHandler, MouseUpHandler, MouseMoveHandler, HasZoomHandlers, - MouseOutHandler -{ - protected List<ZoomHandler> handlers; - - protected ChartOutputTab chartTab; - - protected Canvas zoombox; - - protected int[] start; - protected int[] end; - - - public ZoomboxControl(ChartOutputTab chartTab, String imageUrl) { - super(); - - this.handlers = new ArrayList<ZoomHandler>(); - this.chartTab = chartTab; - this.start = new int[] { -1, -1 }; - this.end = new int[2]; - this.zoombox = new Canvas(); - - initZoombox(); - - String baseUrl = GWT.getHostPageBaseURL(); - setSrc(baseUrl + imageUrl); - setActionType(SelectionType.CHECKBOX); - setSize(20); - setShowRollOver(false); - setSelected(false); - - Canvas chart = chartTab.getChartPanel(); - chart.addMouseDownHandler(this); - chart.addMouseOutHandler(this); - chart.addMouseMoveHandler(this); - chart.addMouseUpHandler(this); - } - - - /** - * Initializes the zoombox that is displayed over the observed area. The - * zoombox has an opaque background. Its height/width and x/y values are - * determined by the start point (mouse down) and the current mouse - * position. - */ - protected void initZoombox() { - Canvas chart = chartTab.getChartPanel(); - chart.addChild(zoombox); - - zoombox.setPosition(Positioning.ABSOLUTE); - zoombox.setBorder("2px solid black"); - zoombox.setOpacity(50); - zoombox.setWidth(1); - zoombox.setHeight(1); - zoombox.setLeft(-10000); - zoombox.setTop(-10000); - } - - - /** - * Registers a new ZoomHandler that wants to listen to ZoomEvents. - * - * @param handler A new ZoomHandler. - */ - public void addZoomHandler(ZoomHandler handler) { - if (handler != null) { - handlers.add(handler); - } - } - - - /** - * A mouse down event on the specified area will set the start point for the - * zoombox. - * - * @param event The mouse down event which contains the xy coordinates of - * the observed area. - */ - public void onMouseDown(MouseDownEvent event) { - if (!isSelected()) { - return; - } - - start[0] = getRelativeX(event.getX()) - 1; - start[1] = getRelativeY(event.getY()) + 1; - - end[0] = start[0]; - end[1] = start[1]; - } - - - /** - * A mouse move event on the specified area will set the end point for the - * zoombox. If the end point differs from the start point, an opaque box is - * displayed. - * - * @param event The mouse move event which contains the xy coordinates of - * the observed area. - */ - public void onMouseMove(MouseMoveEvent event) { - if (!isSelected() || !isZooming()) { - return; - } - - int x = getRelativeX(event.getX()); - int y = getRelativeY(event.getY()); - - end[0] = x > start[0] ? x-1 : x+1; - end[1] = y > start[1] ? y-1 : y+1; - - positionZoombox(); - } - - - /** - * The mouse up event finalizes the zoom operation. It sets the end point - * for this operation, clears the zoombox and fires a ZoomEvent. - * - * @param event The mouse up event which contains the xy coordinates of the - * observed area. - */ - public void onMouseUp(MouseUpEvent event) { - if (!isSelected()) { - return; - } - - end[0] = getRelativeX(event.getX()); - end[1] = getRelativeY(event.getY()); - - fireZoomEvent(); - - reset(); - } - - - /** - * The mouse out event is used to cancel an active zoom operation. - * - * @param event The mouse out event. - */ - public void onMouseOut(MouseOutEvent event) { - if (!isSelected() || !isMouseOut(event.getX(), event.getY())) { - return; - } - - reset(); - } - - - /** - * Returns the chart panel. - * - * @return the chart panel. - */ - protected Canvas getChartPanel() { - return chartTab.getChartPanel(); - } - - - /** - * This method is required to check manually if the mouse pointer really - * moves out the chart area. The MouseOutEvent is also fired if the mouse - * goes down which doesn't seem to be correct. So, we gonna check this - * manually. - * - * @param x The x coordinate. - * @param y The y coordinate. - * - * @return true, if the mouse is really out of the chart area, otherwise - * false. - */ - protected boolean isMouseOut(int x, int y) { - Canvas chart = getChartPanel(); - - int left = chart.getPageLeft(); - int right = chart.getPageRight(); - int top = chart.getPageTop(); - int bottom = chart.getPageBottom(); - - if (x <= left || x >= right || y <= top || y >= bottom) { - return true; - } - - return false; - } - - - /** - * Returns true, if a zoom action is in process. - * - * @return true, if a zoom action is in process. - */ - public boolean isZooming() { - return start[0] > 0 && start[1] > 0; - } - - - /** - * Returns the X coordinate relative to the left border. - * - * @param x The X coordinate relative to the window. - * - * @return the X coordinate relative to the left border. - */ - protected int getRelativeX(int x) { - return x - chartTab.getChartPanel().getPageLeft(); - } - - - /** - * Returns the Y coordinate relative to the top border. - * - * @param y The Y coordinate relative to the window. - * - * @return the Y coordinate relative to the top border. - */ - protected int getRelativeY(int y) { - return y - chartTab.getChartPanel().getPageTop(); - } - - - /** - * Returns min and max x/y values based on the stored values in <i>start</i> - * and <i>end</i>. - * - * @return an int[] as follows: [xmin, ymin, xmax, ymax]. - */ - protected int[] orderPositions() { - int xmin = start[0] < end[0] ? start[0] : end[0]; - int ymin = start[1] < end[1] ? start[1] : end[1]; - - int xmax = start[0] >= end[0] ? start[0] : end[0]; - int ymax = start[1] >= end[1] ? start[1] : end[1]; - - return new int[] { xmin, ymin, xmax, ymax }; - } - - - /** - * Sets the width, height, x and y values of the zoombox. - */ - protected void positionZoombox() { - int[] values = orderPositions(); - - zoombox.setLeft(values[0]); - zoombox.setTop(values[1]); - zoombox.setWidth(values[2] - values[0]); - zoombox.setHeight(values[3] - values[1]); - } - - - /** - * Clears the zoombox (set position and size to null). - */ - protected void clearZoombox() { - zoombox.setLeft(-10000); - zoombox.setTop(-10000); - zoombox.setWidth(1); - zoombox.setHeight(1); - } - - - /** - * Resets the zoom control (start point and zoombox). - */ - protected void reset() { - start[0] = -1; - start[1] = -1; - - clearZoombox(); - } - - - /** - * Fires a ZoomEvent to all registered listeners. - */ - protected void fireZoomEvent() { - int[] pos = orderPositions(); - - ZoomEvent event = new ZoomEvent(pos[0], pos[1], pos[2], pos[3]); - - for (ZoomHandler handler: handlers) { - handler.onZoom(event); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixEventSelect.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import java.util.List; -import java.util.ArrayList; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; - -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.IntDataItem; -import de.intevation.flys.client.shared.model.IntegerArrayData; -import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; - -import de.intevation.flys.client.client.services.FixingsOverviewService; -import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync; - -/** - * This UIProvider lets you select events. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class FixEventSelect -extends FixationPanel -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - public static final int MAX_DISPLAYED_ITEMS = 5; - - protected FixingsOverviewServiceAsync overviewService = - GWT.create(FixingsOverviewService.class); - - protected List<String> events; - - public FixEventSelect() { - htmlOverview = ""; - events = new ArrayList<String>(); - } - - public Canvas createWidget(DataList data) { - instances.put(this.artifact.getUuid(), this); - - VLayout layout = new VLayout(); - - Canvas title = new Label(MESSAGES.eventselect()); - title.setHeight("25px"); - - layout.addMember(title); - return layout; - } - - @Override - public Canvas createOld(DataList dataList) { - List<Data> list = dataList.getAll(); - - Data data = getData(list, "events"); - - VLayout dataLayout = new VLayout(); - dataLayout.setWidth(130); - - DataItem[] items = data.getItems(); - - if (items.length > MAX_DISPLAYED_ITEMS) { - for (int i = 0; i < MAX_DISPLAYED_ITEMS-2; ++i) { - Label l = new Label(items[i].getLabel()); - l.setHeight(25); - dataLayout.addMember(l); - } - Label l = new Label("..."); - l.setHeight(25); - dataLayout.addMember(l); - l = new Label(items[items.length-1].getLabel()); - l.setHeight(25); - dataLayout.addMember(l); - } - else { - for (int i = 0; i < items.length; i++) { - Label l = new Label(items[i].getLabel()); - l.setHeight(25); - dataLayout.addMember(l); - } - } - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(dataLayout); - layout.addMember(back); - - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - if (events.size() > 0) { - IntDataItem[] arr = new IntDataItem[events.size()]; - for (int i = 0, E = events.size(); i < E; i++) { - try { - Integer v = new Integer(events.get(i)); - arr[i] = new IntDataItem("id", "id", v.intValue()); - } - catch (NumberFormatException nfe) { - return data.toArray(new Data[data.size()]); - } - } - - IntegerArrayData iad = - new IntegerArrayData("events", "events", arr); - - data.add(iad); - } - - return data.toArray(new Data[data.size()]); - } - - - @Override - public void setValues(String cid, boolean checked) { - if (checked) { - events.add(cid); - } - else { - if (events.contains(cid)) { - events.remove(cid); - } - } - } - - - @Override - public boolean renderCheckboxes() { - return true; - } - - - public void success() { - for (FixEvent fe: fixInfo.getEvents()) { - events.add(fe.getCId()); - } - } - - public void dumpGWT(String cid) { - GWT.log("Setting values for cId: " + cid); - GWT.log("River: " + fixInfo.getRiver()); - GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); - GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription()); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixFunctionSelect.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -public class FixFunctionSelect extends FixationPanel { - private static final Map<String, String> funcDesc = new HashMap<String, String>(); - - static { - funcDesc.put("log", "W(Q) = m*ln(Q + b)"); - funcDesc.put("linear", "W(Q) = m * Q + b"); - funcDesc.put("log-linear", "W(Q) = a*ln(m*Q+b)"); - funcDesc.put("exp", "W(Q) = m * a^Q + b"); - funcDesc.put("quad", "W(Q) = n*Q^2+m*Q+b"); - funcDesc.put("pow", "W(Q) = a * Q^c + d"); - funcDesc.put("sq-pow", "S(Q) = a * Q^b"); - } - - /** The combobox.*/ - protected DynamicForm form; - - @Override - public Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - layout.setAlign(VerticalAlignment.TOP); - layout.setHeight(25); - - LinkedHashMap initial = new LinkedHashMap(); - - form = new DynamicForm(); - - int size = data.size(); - - for (int i = 0; i < size; i++) { - Data d = data.get(i); - - Label label = new Label(d.getDescription()); - label.setValign(VerticalAlignment.TOP); - label.setHeight(20); - label.setWidth(400); - - SelectItem combobox = new SelectItem(d.getLabel()); - combobox.setWidth(250); - - LinkedHashMap<String, String> funcTypes = new LinkedHashMap<String, String>(); - - boolean defaultSet = false; - boolean first = true; - - DataItem def = d.getDefault(); - String defValue = def != null ? def.getStringValue() : null; - - if (defValue != null && defValue.length() > 0) { - initial.put(d.getLabel(), def.getStringValue()); - defaultSet = true; - } - - // I was here. Me 2. - for (DataItem item: d.getItems()) { - if (!defaultSet && first) { - initial.put(d.getLabel(), item.getStringValue()); - first = false; - } - - funcTypes.put(item.getStringValue(), item.getLabel()); - } - - label.setWidth(50); - combobox.setValueMap(funcTypes); - combobox.setShowTitle(false); - form.setItems(combobox); - - layout.addMember(label); - layout.addMember(form); - } - - form.setValues(initial); - - layout.setAlign(VerticalAlignment.TOP); - - return layout; - } - - - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - VLayout vLayout = new VLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - int size = dataList.size(); - for (int i = 0; i < size; i++) { - Data data = dataList.get(i); - DataItem[] items = data.getItems(); - - for (DataItem item: items) { - HLayout hLayout = new HLayout(); - - String desc = funcDesc.containsKey(item.getLabel()) ? - funcDesc.get(item.getLabel()) : item.getLabel(); - hLayout.addMember(label); - hLayout.addMember(new Label(desc)); - - vLayout.addMember(hLayout); - vLayout.setWidth("130px"); - } - } - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - - @Override - public Data[] getData() { - Map values = form.getValues(); - Iterator keys = values.keySet().iterator(); - - Data[] list = new Data[values.size()]; - int i = 0; - - while (keys.hasNext()) { - String fieldname = (String) keys.next(); - String selection = (String) values.get(fieldname); - - DataItem item = new DefaultDataItem(fieldname, null, selection); - - list[i++] = new DefaultData( - fieldname, null, null, new DataItem[] { item }); - } - - return list; - } - - - @Override - public void setValues(String cid, boolean checked) { - } - - @Override - public boolean renderCheckboxes() { - return false; - } - - @Override - public void success() { - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.StaticTextItem; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class FixGaugeSelectPanel -extends FixationPanel -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected String first; - protected String second; - - protected SelectItem from; - protected SelectItem to; - - protected LinkedHashMap<String, String> mapValues; - - public FixGaugeSelectPanel() { - htmlOverview = ""; - - mapValues = new LinkedHashMap<String, String>(); - mapValues.put("0", MESSAGES.gauge_mnq()); - mapValues.put("1", MESSAGES.gauge_mq()); - mapValues.put("2", MESSAGES.gauge_mhq()); - mapValues.put("3", MESSAGES.gauge_hq5()); - } - - @Override - public Canvas createWidget(DataList data) { - instances.put(this.artifact.getUuid(), this); - - VLayout layout = new VLayout(); - - Label title = new Label(MESSAGES.gauge_class()); - title.setHeight(25); - - from = new SelectItem(MESSAGES.from()); - to = new SelectItem(MESSAGES.to()); - - from.setShowTitle(false); - to.setShowTitle(false); - from.setValueMap(mapValues); - from.setDefaultValues("0"); - from.setWidth(160); - to.setValueMap(mapValues); - to.setDefaultValues("3"); - to.setWidth(160); - - DynamicForm form = new DynamicForm(); - StaticTextItem separator = new StaticTextItem("separator"); - separator.setShowTitle(false); - separator.setValue(MESSAGES.to()); - form.setNumCols(5); - form.setFields(from, separator, to); - - layout.addMember(title); - layout.addMember(form); - - return layout; - } - - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data f = getData(items, "q1"); - Data t = getData(items, "q2"); - DataItem[] fItems = f.getItems(); - DataItem[] tItems = t.getItems(); - - StringBuilder sb = new StringBuilder(); - sb.append(mapValues.get(fItems[0].getLabel())); - sb.append(" " + MESSAGES.to() + " "); - sb.append(mapValues.get(tItems[0].getLabel())); - - Label old = new Label(sb.toString()); - old.setWidth(130); - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - boolean valid = saveClassValues(); - if (valid) { - DataItem firstItem = new DefaultDataItem("q1", "q1", this.first); - DataItem secItem = new DefaultDataItem("q2", "q2", this.second); - data.add(new DefaultData( - "q1", - null, - null, - new DataItem[] { firstItem })); - data.add(new DefaultData( - "q2", - null, - null, - new DataItem[] { secItem })); - } - return data.toArray(new Data[data.size()]); - } - - - @Override - public void setValues(String cid, boolean checked) { - // No user interaction, do nothing. - } - - - @Override - public boolean renderCheckboxes() { - // No selection, return false. - return false; - } - - - @Override - public void success() {} - - protected boolean saveClassValues() { - String v1 = from.getValueAsString(); - String v2 = to.getValueAsString(); - try { - int v1i = Integer.parseInt(v1); - int v2i = Integer.parseInt(v2); - if (v1i <= v2i) { - this.first = v1; - this.second = v2; - return true; - } - } - catch(NumberFormatException nfe) { - return false; - } - return false; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,193 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import java.util.List; -import java.util.ArrayList; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; - -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.ui.DoubleRangePanel; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class FixLocationPanel -extends FixationPanel -implements BlurHandler -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - /** The constant name of the input field to enter locations.*/ - public static final String FIELD_VALUE_LOCATION = "location"; - - /** The constant name of the input field to enter distance.*/ - public static final String FIELD_VALUE_DISTANCE = "distance"; - - DoubleRangePanel inputPanel; - - double from; - double to; - double step; - - public FixLocationPanel() { - htmlOverview = ""; - } - - public Canvas createWidget(DataList data) { - instances.put(this.artifact.getUuid(), this); - - VLayout layout = new VLayout(); - - Canvas title = new Label(MESSAGES.distance()); - title.setHeight("25px"); - - inputPanel = new DoubleRangePanel( - MESSAGES.unitFrom(), - MESSAGES.unitTo(), - MESSAGES.unitWidth(), - 0d, - 0d, - 0d, - 240, - this); - - layout.addMember(title); - layout.addMember(inputPanel); - return layout; - } - - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data f = getData(items, "ld_from"); - Data t = getData(items, "ld_to"); - Data s = getData(items, "ld_step"); - DataItem[] fItems = f.getItems(); - DataItem[] tItems = t.getItems(); - DataItem[] sItems = s.getItems(); - - StringBuilder sb = new StringBuilder(); - sb.append(fItems[0].getLabel()); - sb.append(" " + MESSAGES.unitFrom() + " "); - sb.append(tItems[0].getLabel()); - sb.append(" " + MESSAGES.unitTo() + " "); - sb.append(sItems[0].getLabel()); - sb.append(" " + MESSAGES.unitWidth()); - - Label old = new Label(sb.toString()); - old.setWidth(130); - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - boolean valid = saveRangeValues(inputPanel); - if (valid) { - String f = Double.valueOf(this.from).toString(); - String t = Double.valueOf(this.to).toString(); - String s = Double.valueOf(this.step).toString(); - DataItem fi = new DefaultDataItem("ld_from", "ld_from", f); - DataItem ti = new DefaultDataItem("ld_to", "ld_to", t); - DataItem si = new DefaultDataItem("ld_step", "ld_step", s); - data.add(new DefaultData("ld_from", null, null, new DataItem[]{ fi })); - data.add(new DefaultData("ld_to", null, null, new DataItem[]{ ti })); - data.add(new DefaultData("ld_step", null, null, new DataItem[]{ si })); - } - // what else? - return data.toArray(new Data[data.size()]); - } - - - protected boolean saveRangeValues(DoubleRangePanel p) { - FormItem[] items = p.getFields(); - boolean valid = p.validateForm(); - - if(valid) { - this.from = p.getFrom(); - this.to = p.getTo(); - this.step = p.getStep(); - } - return valid; - } - - - @Override - public void setValues(String cid, boolean checked) { - // No user interaction, do nothing. - } - - - @Override - public boolean renderCheckboxes() { - // No selection, return false. - return false; - } - - - public void success() { - inputPanel.setValues(fixInfo.getFrom(), fixInfo.getTo(), 100d); - } - - /** - * This method is used to validate the inserted data in the form fields. - * - * @param event The BlurEvent that gives information about the FormItem that - * has been modified and its value. - */ - public void onBlur(BlurEvent event) { - FormItem item = event.getItem(); - String field = item.getFieldName(); - - if (field == null) { - return; - } - DoubleRangePanel p = (DoubleRangePanel) event.getForm(); - } - - - public void dumpGWT(String cid) { - GWT.log("Setting values for cId: " + cid); - GWT.log("River: " + fixInfo.getRiver()); - GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); - GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription()); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class FixMultiPeriodPanel -extends FixPeriodPanel -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected ListGrid elements; - - protected String values; - - public FixMultiPeriodPanel() { - this("", ""); - } - - public FixMultiPeriodPanel(String startName, String endName) { - super(startName, endName); - } - - @Override - public Canvas createWidget(DataList data) { - HLayout input = new HLayout(); - VLayout root = new VLayout(); - VLayout grid = new VLayout(); - VLayout layout = (VLayout) super.createWidget(data); - Button add = new Button(MESSAGES.add()); - elements = new ListGrid(); - - add.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent ce) { - Date f = inputPanel.getFromDate(); - Date t = inputPanel.getToDate(); - if (f == null || t == null) { - return; - } - DateRangeRecord drr = new DateRangeRecord(f, t); - elements.addData(drr); - } - }); - layout.addMember(add); - - Label sel = new Label("Selected"); - sel.setHeight(25); - elements.setWidth(185); - elements.setHeight(120); - elements.setShowHeaderContextMenu(false); - elements.setCanReorderFields(false); - elements.setCanSort(false); - elements.setCanEdit(false); - ListGridField from = new ListGridField("from", "From"); - ListGridField to = new ListGridField("to", "To"); - from.setWidth(70); - to.setWidth(70); - - final ListGridField removeField = - new ListGridField("_removeRecord", "Remove Record"){{ - setType(ListGridFieldType.ICON); - setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); - setCanEdit(false); - setCanFilter(false); - setCanSort(false); - setCanGroupBy(false); - setCanFreeze(false); - setWidth(25); - }}; - - elements.addRecordClickHandler(new RecordClickHandler() { - public void onRecordClick(final RecordClickEvent event) { - // Just handle remove-clicks - if(!event.getField().getName().equals(removeField.getName())) { - return; - } - event.getViewer().removeData(event.getRecord()); - } - }); - - elements.setFields(from, to, removeField); - - grid.addMember(sel); - grid.addMember(elements); - input.addMember(layout); - input.addMember(grid); - root.addMember(input); - - return root; - } - - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - layout.setWidth("400px"); - VLayout vLayout = new VLayout(); - vLayout.setWidth(130); - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - label.setHeight(25); - - List<Data> items = dataList.getAll(); - Data str = getData(items, "ana_data"); - DataItem[] strItems = str.getItems(); - - String[] pairs = strItems[0].getLabel().split(";"); - for (int i = 0; i < pairs.length; i++) { - String[] vals = pairs[i].split(","); - try { - long f = Long.valueOf(vals[0]).longValue(); - long t = Long.valueOf(vals[1]).longValue(); - Date from = new Date(f); - Date to = new Date(t); - String fromString = - DateTimeFormat.getMediumDateFormat().format(from); - String toString = - DateTimeFormat.getMediumDateFormat().format(to); - - Label dateLabel = new Label(fromString + " - " + toString); - dateLabel.setHeight(20); - vLayout.addMember(dateLabel); - } - catch(NumberFormatException nfe) { - } - } - Canvas back = getBackButton(dataList.getState()); - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - boolean valid = saveDateValues(); - if(valid) { - DataItem item = new DefaultDataItem("ana_data", null, this.values); - data.add(new DefaultData( - "ana_data", - null, - null, - new DataItem[] { item })); - } - return data.toArray(new Data[data.size()]); - } - - - @Override - protected boolean saveDateValues() { - ListGridRecord[] lgr = elements.getRecords(); - if (lgr.length == 0) { - return false; - } - String data = ""; - for (int i = 0; i < lgr.length; i++) { - DateRangeRecord drr = (DateRangeRecord) lgr[i]; - data += drr.getFrom() + "," + drr.getTo(); - data += ";"; - } - values = data; - return true; - } - - - protected static class DateRangeRecord extends ListGridRecord { - protected Date from; - protected Date to; - - protected final static String FROM_FIELD = "from"; - protected final static String TO_FIELD = "to"; - - public DateRangeRecord (Date from, Date to) { - setFrom(from); - setTo(to); - } - - public void setFrom(Date from) { - this.from = from; - setAttribute( - FROM_FIELD, - DateTimeFormat.getMediumDateFormat().format(from)); - } - - - public void setTo(Date to) { - this.to = to; - setAttribute( - TO_FIELD, - DateTimeFormat.getMediumDateFormat().format(to)); - } - - - public long getFrom() { - return this.from.getTime(); - } - - - public long getTo() { - return this.to.getTime(); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,231 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.DateRangeItem; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class FixPeriodPanel -extends FixationPanel -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - DateRangeItem inputPanel; - - long start; - long end; - - protected String startName; - protected String endName; - - public FixPeriodPanel() { - this("start", "end"); - } - - public FixPeriodPanel(String startName, String endName) { - this.startName = startName; - this.endName = endName; - htmlOverview = ""; - } - - @Override - public Canvas createWidget(DataList data) { - instances.put(this.artifact.getUuid(), this); - - VLayout layout = new VLayout(); - - Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - DynamicForm form = new DynamicForm(); - inputPanel = new DateRangeItem(); - inputPanel.setToTitle(MESSAGES.to()); - inputPanel.setFromTitle(MESSAGES.from()); - inputPanel.setShowTitle(false); - form.setFields(inputPanel); - - layout.addMember(title); - layout.addMember(form); - - return layout; - } - - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data start = getData(items, startName); - Data end = getData(items, endName); - DataItem[] startItem = start.getItems(); - DataItem[] endItem = end.getItems(); - - String v1 = startItem[0].getStringValue(); - String v2 = endItem[0].getStringValue(); - - long v1l = 0; - long v2l = 0; - try { - v1l = Long.parseLong(v1); - v2l = Long.parseLong(v2); - } - catch(NumberFormatException nfe) { - GWT.log(nfe.toString()); - } - Date d1 = new Date(v1l); - Date d2 = new Date(v2l); - - DateTimeFormat f = - DateTimeFormat.getFormat( - DateTimeFormat.PredefinedFormat.DATE_MEDIUM); - StringBuilder sb = new StringBuilder(); - sb.append(f.format(d1) + " - "); - sb.append(f.format(d2)); - - Label old = new Label(sb.toString()); - old.setWidth(130); - - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - - return layout; - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - boolean valid = saveDateValues(); - if(valid) { - String start = Long.valueOf(this.start).toString(); - String end = Long.valueOf(this.end).toString(); - DataItem startItem = new DefaultDataItem(startName, startName, start); - DataItem endItem = new DefaultDataItem(endName, endName, end); - data.add(new DefaultData( - startName, - null, - null, - new DataItem[] { startItem })); - data.add(new DefaultData( - endName, - null, - null, - new DataItem[] { endItem })); - } - - return data.toArray(new Data[data.size()]); - } - - - @Override - public void setValues(String cid, boolean checked) { - // No user interaction, do nothing. - } - - - @Override - public boolean renderCheckboxes() { - // No selection, return false. - return false; - } - - @Override - public void success() { - List<FixEvent> list = fixInfo.getEvents(); - - // The date in FixEvent is always "de" locale, so it seems... - DateTimeFormat df = DateTimeFormat.getFormat("yy.MM.yyyy"); - - if (!setFromAndToDate(list, df)) { - // or perhaps "en"? - df = DateTimeFormat.getFormat("MM/dd/yyyy"); - - if (!setFromAndToDate(list, df)) { - GWT.log("FixPeriodPanel::success(): could not set from and to dates!"); - } - } - } - - protected boolean setFromAndToDate(List<FixEvent> list, DateTimeFormat df) { - try { - setFromDate(list.get(0).getDate(), df); - setToDate(list.get(list.size() - 1).getDate(), df); - return true; - } - catch(IllegalArgumentException ex) { - GWT.log("FixPeriodPanel::setFromAndToDate(): " + ex.toString()); - return false; - } - } - - protected void setFromDate(String date, DateTimeFormat df) - throws IllegalArgumentException - { - Date from = df.parse(date); - this.inputPanel.setFromDate(from); - } - - protected void setToDate(String date, DateTimeFormat df) - throws IllegalArgumentException - { - Date to = df.parse(date); - this.inputPanel.setToDate(to); - } - - protected boolean saveDateValues() { - Date st = inputPanel.getFromDate(); - Date en = inputPanel.getToDate(); - if (st == null || en == null) { - SC.warn(MESSAGES.error_wrong_date()); - return false; - } - - long start = st.getTime(); - long end = en.getTime(); - - if (start <= end) { - this.start = start; - this.end = end; - return true; - } - return false; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixQSelectPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; - -import de.intevation.flys.client.client.FLYSConstants; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; - -/** - * This UIProvider creates a panel for location or distance input. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class FixQSelectPanel -extends FixationPanel -{ - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - public FixQSelectPanel() { - htmlOverview = ""; - } - - public Canvas createWidget(DataList data) { - instances.put(this.artifact.getUuid(), this); - - return new Canvas(); - } - - @Override - public Canvas createOld(DataList dataList) { - return new Canvas(); - } - - - /** - * This method returns the selected data. - * - * @return the selected/inserted data. - */ - public Data[] getData() { - return new Data[0]; - } - - - @Override - public void setValues(String cid, boolean checked) { - // No user interaction, do nothing. - } - - - @Override - public boolean renderCheckboxes() { - // No selection, return false. - return false; - } - - - public void success() {} -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,484 +0,0 @@ -package de.intevation.flys.client.client.ui.fixation; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONString; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.HTMLPane; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.FixingsOverviewService; -import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync; -import de.intevation.flys.client.client.ui.AbstractUIProvider; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.FixAnalysisArtifact; -import de.intevation.flys.client.shared.model.FixFilter; -import de.intevation.flys.client.shared.model.FixingsOverviewInfo; - -import java.util.Date; -import java.util.HashMap; - - -/** - * This UIProvider creates helper panel for fixation analysis without input - * elements. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public abstract class FixationPanel -extends AbstractUIProvider -implements ResizedHandler -{ - private static final long serialVersionUID = -3667553404493415619L; - - protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>(); - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected FixingsOverviewServiceAsync overviewService = - GWT.create(FixingsOverviewService.class); - - protected String htmlOverview; - protected FixingsOverviewInfo fixInfo; - protected TabSet tabs; - protected Tab events; - protected Tab chart; - protected VLayout chartContainer; - protected Img chartImg; - protected TextItem kmText; - - public static final DateTimeFormat DTF = DateTimeFormat.getFormat("dd.MM.yyyy"); - - - public FixationPanel() { - chartImg = new Img(); - htmlOverview = ""; - } - - - /** Get the (master) artifact UUID. */ - protected String getArtifactUuid() { - return this.artifact.getUuid(); - } - - protected void init() { - } - - @Override - public Data[] getData() { - return null; - } - - @Override - public Canvas create(DataList list) { - VLayout layout = new VLayout(); - - Canvas helper = createHelper(); - this.helperContainer.addMember(helper); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(list); - - layout.addMember(widget); - layout.addMember(submit); - return layout; - } - - @Override - public Canvas createOld(DataList list) { - return new DynamicForm(); - } - - protected Canvas createHelper() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - tabs = new TabSet(); - events = new Tab(MESSAGES.events()); - chart = new Tab(MESSAGES.kmchart()); - - chartContainer = new VLayout(); - Canvas scroll = createChartHelper(); - - VLayout layout = new VLayout(); - layout.addResizedHandler(this); - layout.addMember(chartContainer); - layout.addMember(scroll); - layout.setAlign(Alignment.CENTER); - chart.setPane(layout); - - final HTMLPane eventPane = new HTMLPane(); - - String river = artifact.getArtifactDescription().getRiver(); - createCallback(); - - String callBack = "fixationCallback(this.checked, this.name)"; - - if (this.artifact instanceof FixAnalysisArtifact == false) - return chartContainer; - - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; - - overviewService.generateOverview( - locale, - artifact.getUuid(), - getOverviewFilter(art.getFilter()), - renderCheckboxes(), - callBack, - new AsyncCallback<FixingsOverviewInfo>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not receive overview."); - SC.warn(caught.getMessage()); - } - @Override - public void onSuccess(FixingsOverviewInfo info) { - GWT.log("Successfully loaded overview."); - fixInfo = info; - htmlOverview = info.getHTML(); - FixAnalysisArtifact art = (FixAnalysisArtifact)artifact; - FixFilter filter = art.getFilter(); - filter.setRiver(info.getRiver()); - if (filter.getCurrentKm() == -Double.MAX_VALUE || - filter.getCurrentKm() == -1d) { - filter.setCurrentKm(info.getFrom()); - filter.setToKm(info.getTo()); - } - if (kmText != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(filter.getCurrentKm()); - kmText.setValue(nf.format(d)); - } catch (NumberFormatException e) { - kmText.setValue(filter.getCurrentKm()); - } - } - eventPane.setContents(htmlOverview); - updateChartTab(fixInfo.getFrom()); - events.setPane(eventPane); - success(); - } - }); - - tabs.addTab(events); - tabs.addTab(chart); - - return tabs; - } - - - protected Canvas createChartHelper() { - DynamicForm form = new DynamicForm(); - Button lower = new Button("<<"); - lower.setWidth(30); - Button upper = new Button(">>"); - upper.setWidth(30); - kmText = new TextItem(); - kmText.setWidth(60); - kmText.setShowTitle(false); - - - form.setFields(kmText); - form.setWidth(60); - lower.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent ce) { - FixFilter filter = updateChartTabLow(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(filter.getCurrentKm()); - kmText.setValue(nf.format(d)); - } catch (NumberFormatException e) { - kmText.setValue(filter.getCurrentKm()); - } - } - }); - - upper.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent ce) { - FixFilter filter = updateChartTabUp(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(filter.getCurrentKm()); - kmText.setValue(nf.format(d)); - } catch (NumberFormatException e) { - kmText.setValue(filter.getCurrentKm()); - } - } - }); - - kmText.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent ce) { - //TODO: get current value. - if(ce.getItem().getValue() != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = nf.parse(ce.getItem().getValue().toString()); - updateChartTab(d); - } - catch(NumberFormatException nfe) { - // Do nothing. - } - } - } - }); - - HLayout layout = new HLayout(); - layout.setAlign(Alignment.CENTER); - - layout.addMember(lower); - layout.addMember(form); - layout.addMember(upper); - return layout; - } - - protected void updateChartTab(double km) { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; - - if (fixInfo != null) { - if (km < fixInfo.getFrom()) km = fixInfo.getFrom(); - if (km > fixInfo.getTo()) km = fixInfo.getTo(); - } - - FixFilter filter = art.getFilter(); - - if (km < filter.getFromKm()) km = filter.getFromKm(); - if (km > filter.getToKm()) km = filter.getToKm(); - - filter.setCurrentKm(km); - - int hWidth = helperContainer.getWidth() - 12; - int hHeight = helperContainer.getHeight() - 62; - - if ((int)(hHeight *4f/3) < hWidth) { - hWidth = (int)(hHeight * 4f/3); - } - else { - hHeight = (int)(hWidth *3f/4); - } - - String imgUrl = GWT.getModuleBaseURL(); - imgUrl += "fixings-km-chart"; - imgUrl += "?locale=" + locale; - imgUrl += "&filter=" + getChartFilter(filter, hWidth, hHeight); - - if (chartContainer.hasMember(chartImg)) { - chartImg.setWidth(hWidth); - chartImg.setHeight(hHeight); - chartImg.setSrc(imgUrl); - } - else { - chartImg = new Img(imgUrl, hWidth, hHeight); - chartContainer.addMember(chartImg); - } - } - - - protected FixFilter updateChartTabLow() { - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; - - FixFilter filter = art.getFilter(); - - double curr = filter.getCurrentKm(); - if (curr > filter.getFromKm()) { - double newVal = (curr - 0.1) * 10; - long round = Math.round(newVal); - updateChartTab(((double)round) / 10); - } - return filter; - } - - - protected FixFilter updateChartTabUp() { - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; - - FixFilter filter = art.getFilter(); - - double curr = filter.getCurrentKm(); - if (curr < filter.getToKm()) { - double newVal = (curr + 0.1) * 10; - long round = Math.round(newVal); - updateChartTab(((double)round) / 10); - } - return filter; - } - - - @Override - public void onResized(ResizedEvent re) { - FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; - - updateChartTab(art.getFilter().getCurrentKm()); - } - - - private native void createCallback() /*-{ - $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); - }-*/; - - private static void helperCallback(boolean checked, String name) { - String[] parts = name.split(":"); - String uuid = parts[0]; - String cid = parts[1]; - - FixationPanel p = FixationPanel.getInstance(uuid); - if (p != null) { - p.setValues(cid, checked); - } - } - - private static FixationPanel getInstance(String uuid) { - return instances.get(uuid); - } - - public abstract Canvas createWidget(DataList data); - public abstract void setValues(String cid, boolean checked); - public abstract boolean renderCheckboxes(); - public abstract void success(); - - - /** Creates JSON string from filter. */ - public static String getOverviewFilter(FixFilter filter) { - String river = filter.getRiver(); - - if (river != null && river.length() > 0) { - JSONObject jfix = new JSONObject(); - JSONObject jfilter = new JSONObject(); - JSONObject jrName = new JSONObject(); - JSONString jrValue = new JSONString(river); - jrName.put("name", jrValue); - jfilter.put("river", jrName); - jfix.put("fixings", createFilter(filter, jfilter)); - return jfix.toString(); - } - return ""; - } - - public String getChartFilter(FixFilter filter, int width, int height) { - String river = filter.getRiver(); - double currentKm = filter.getCurrentKm(); - double fromKm = filter.getFromKm(); - double toKm = filter.getToKm(); - - if (river != null && river.length() > 0 && - currentKm >= fromKm && currentKm <= toKm) - { - JSONObject jfix = new JSONObject(); - JSONObject jfilter = new JSONObject(); - JSONObject jrName = new JSONObject(); - JSONString jrValue = new JSONString(river); - JSONObject jkm = new JSONObject(); - JSONNumber jkmValue = new JSONNumber(currentKm); - JSONObject jextent = new JSONObject(); - JSONNumber jwidth = new JSONNumber(width); - JSONNumber jheight = new JSONNumber(height); - - jkm.put("value", jkmValue); - jrName.put("name", jrValue); - jfilter.put("river", jrName); - jfilter.put("km", jkm); - jextent.put("width", jwidth); - jextent.put("height", jheight); - jfilter.put("extent", jextent); - jfix.put("fixings", createFilter(filter, jfilter)); - return jfix.toString(); - } - return ""; - } - - protected static JSONObject createFilter(FixFilter filter, JSONObject root) { - double fromKm = filter.getFromKm(); - double toKm = filter.getToKm(); - boolean hasDate = filter.getFromDate() > 0 && filter.getToDate() > 0; - - if (fromKm >= 0 && toKm >= 0 && fromKm <= toKm) { - JSONObject range = new JSONObject(); - JSONObject fromtokm = new JSONObject(); - JSONNumber f = new JSONNumber(fromKm); - JSONNumber t = new JSONNumber(toKm); - fromtokm.put("from", f); - fromtokm.put("to", t); - root.put("range", fromtokm); - } - - JSONObject and = new JSONObject(); - if (hasDate) { - long fromDate = filter.getFromDate(); - long toDate = filter.getToDate(); - - Date df = new Date(fromDate); - Date dt = new Date(toDate); - - JSONObject daterange = new JSONObject(); - JSONString f = new JSONString(DTF.format(df)); - JSONString t = new JSONString(DTF.format(dt)); - - daterange.put("from", f); - daterange.put("to", t); - and.put("date-range", daterange); - } - - int fromClass = filter.getFromClass(); - int toClass = filter.getToClass(); - - if (fromClass >= 0 && toClass >= 0 && fromClass <= toClass) { - JSONObject classrange = new JSONObject(); - JSONNumber f = new JSONNumber(fromClass); - JSONNumber t = new JSONNumber(toClass); - - classrange.put("from", f); - classrange.put("to", t); - and.put("sector-range", classrange); - } - - int[] events = filter.getEvents(); - - if (events.length > 0) { - StringBuilder cids = new StringBuilder(); - - for (int i = 0; i < events.length; i++) { - if (i > 0) cids.append(' '); - cids.append(events[i]); - } - JSONObject columns = new JSONObject(); - columns.put("cids", new JSONString(cids.toString())); - and.put("columns", columns); - } - if (and.size() > 0) { - JSONObject jFilter = new JSONObject(); - jFilter.put("and", and); - root.put("filter", jFilter); - } - return root; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/CapabilitiesPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.ui.Grid; - -import com.smartgwt.client.types.Overflow; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.Layout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Capabilities; -import de.intevation.flys.client.shared.model.ContactInformation; -import de.intevation.flys.client.client.FLYSConstants; - - -public class CapabilitiesPanel extends VLayout { - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected Capabilities capabilites; - - - public CapabilitiesPanel(Capabilities capabilites) { - super(); - this.capabilites = capabilites; - - initLayout(); - } - - - protected void initLayout() { - setMargin(5); - setOverflow(Overflow.AUTO); - initContent(); - } - - - protected void initContent() { - Grid grid = new Grid(10, 2); - grid.setCellPadding(10); - - grid.setText(0, 0, MSG.capabilitiesTitle() + ":"); - grid.setText(0, 1, capabilites.getTitle()); - grid.setText(1, 0, MSG.capabilitiesURL() + ":"); - grid.setText(1, 1, capabilites.getOnlineResource()); - grid.setText(2, 0, MSG.capabilitiesAccessConstraints() + ":"); - grid.setText(2, 1, capabilites.getAccessConstraints()); - grid.setText(3, 0, MSG.capabilitiesFees() + ":"); - grid.setText(3, 1, capabilites.getFees()); - - int row = 4; - - ContactInformation ci = capabilites.getContactInformation(); - - grid.setText(row, 0, MSG.capabilitiesContactInformation() + ":"); - - String person = ci.getPerson(); - if (person != null && person.length() > 0) { - grid.setText(row++, 1, person); - } - - String organization = ci.getOrganization(); - if (organization != null && organization.length() > 0) { - grid.setText(row++, 1, organization); - } - - String address = ci.getAddress(); - if (address != null && address.length() > 0) { - grid.setText(row++, 1, address); - } - - String pc = ci.getPostcode(); - String c = ci.getCity(); - if ((pc != null && pc.length() > 0) || (c != null && c.length() > 0)) { - grid.setText(row++, 1, pc + " " + c); - } - - String email = ci.getEmail(); - if (email != null && email.length() > 0) { - grid.setText(row++, 1, MSG.capabilitiesEmail() + ": " + email); - } - - String phone = ci.getPhone(); - if (phone != null && phone.length() > 0) { - grid.setText(row++, 1, MSG.capabilitiesPhone() + ": " + phone); - } - - Label title = new Label(MSG.capabilitiesHint()); - title.setHeight(25); - title.setStyleName("capabilities-info-title"); - - addMember(title); - addMember(grid); - } - - - protected Layout createRow(Label title, Label content) { - title.setWidth(100); - - HLayout layout = new HLayout(); - layout.addMember(title); - layout.addMember(content); - - return layout; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,251 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.types.SelectionType; -import com.smartgwt.client.widgets.ImgButton; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.utils.EnableDisableCmd; - -import java.util.LinkedHashMap; - -import org.gwtopenmaps.openlayers.client.Map; -import org.gwtopenmaps.openlayers.client.Style; -import org.gwtopenmaps.openlayers.client.control.Control; -import org.gwtopenmaps.openlayers.client.control.DrawFeature; -import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; -import org.gwtopenmaps.openlayers.client.feature.VectorFeature; -import org.gwtopenmaps.openlayers.client.handler.Handler; -import org.gwtopenmaps.openlayers.client.handler.PathHandler; -import org.gwtopenmaps.openlayers.client.handler.PolygonHandler; -import org.gwtopenmaps.openlayers.client.layer.Vector; -import org.gwtopenmaps.openlayers.client.util.Attributes; - -/** - * Widget that handles the drawing of pipes and dikes in the DigitizePanel (MapPanel). - */ -public class DrawControl extends HLayout implements VectorFeatureAddedListener { - - public static final String BARRIER_PIPE1 = "pipe1"; - public static final String BARRIER_PIPE2 = "pipe2"; - public static final String BARRIER_DITCH = "ditch"; - public static final String BARRIER_DAM = "dam"; - public static final String BARRIER_RINGDIKE = "ring_dike"; - - // FIXME: i18n - public static final String BARRIER_PIPE1_VALUE = "Rohr 1"; - public static final String BARRIER_PIPE2_VALUE = "Rohr 2"; - public static final String BARRIER_DITCH_VALUE = "Graben"; - public static final String BARRIER_DAM_VALUE = "Damm"; - public static final String BARRIER_RINGDIKE_VALUE = "Ringdeich"; - - public static final String FIELD_BARRIER_TYPE = "field_barrier_type"; - - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected EnableDisableCmd cmd; - - protected ImgButton button; - protected DynamicForm form; - - protected Map map; - protected Vector layer; - - protected Control control; - - - public DrawControl(Map map, Vector layer, EnableDisableCmd cmd) { - this.map = map; - this.layer = layer; - this.cmd = cmd; - - initialize(); - } - - - protected void initialize() { - setWidth(100); - setMembersMargin(0); - - button = new ImgButton(); - - final String baseUrl = GWT.getHostPageBaseURL(); - button.setSrc(baseUrl + MSG.digitize()); - button.setActionType(SelectionType.CHECKBOX); - button.setSize(20); - button.setShowRollOver(false); - button.setSelected(false); - button.setTooltip(MSG.digitizeObjects()); - - button.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - if (button.isSelected()) { - cmd.enable(); - } - else { - cmd.disable(); - } - } - }); - - form = new DynamicForm(); - form.setWidth(100); - form.setTitlePrefix(""); - form.setTitleSuffix(""); - - final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); - map.put(BARRIER_PIPE1, MSG.getString(BARRIER_PIPE1)); - map.put(BARRIER_PIPE2, MSG.getString(BARRIER_PIPE2)); - map.put(BARRIER_DITCH, MSG.getString(BARRIER_DITCH)); - map.put(BARRIER_DAM, MSG.getString(BARRIER_DAM)); - map.put(BARRIER_RINGDIKE, MSG.getString(BARRIER_RINGDIKE)); - - final LinkedHashMap<String, String> ics = new LinkedHashMap<String, String>(); - ics.put(BARRIER_PIPE1, BARRIER_PIPE1); - ics.put(BARRIER_PIPE2, BARRIER_PIPE2); - ics.put(BARRIER_DITCH, BARRIER_DITCH); - ics.put(BARRIER_DAM, BARRIER_DAM); - ics.put(BARRIER_RINGDIKE, BARRIER_RINGDIKE); - - final SelectItem box = new SelectItem(FIELD_BARRIER_TYPE); - box.setTitle(""); - box.setWidth(100); - box.setValueMap(map); - box.setImageURLSuffix(".png"); - box.setValueIcons(ics); - - box.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent e) { - setSelectedControl(); - } - }); - - form.setFields(box); - - addMember(button); - addMember(form); - - layer.addVectorFeatureAddedListener(this); - - activate(false); - } - - - protected String getSelectedType() { - return form.getValueAsString(FIELD_BARRIER_TYPE); - } - - - @Override - public void onFeatureAdded(FeatureAddedEvent evt) { - setCurrentType(evt.getVectorFeature()); - } - - - protected void setCurrentType(VectorFeature feature) { - final Attributes attrs = feature.getAttributes(); - String type = attrs.getAttributeAsString("typ"); - - if (type == null || type.length() == 0) { - type = getSelectedType(); - - final Style style = FloodMap.getStyle(type); - if (style != null) { - feature.setStyle(style); - } - - if (type.equals(BARRIER_PIPE1)) { - attrs.setAttribute("typ", BARRIER_PIPE1_VALUE); - } - else if (type.equals(BARRIER_PIPE2)) { - attrs.setAttribute("typ", BARRIER_PIPE2_VALUE); - } - else if (type.equals(BARRIER_DAM)) { - attrs.setAttribute("typ", BARRIER_DAM_VALUE); - } - else if (type.equals(BARRIER_DITCH)) { - attrs.setAttribute("typ", BARRIER_DITCH_VALUE); - } - else if (type.equals(BARRIER_RINGDIKE)) { - attrs.setAttribute("typ", BARRIER_RINGDIKE_VALUE); - } - - layer.redraw(); - } - } - - - protected void removeControl() { - if (control != null) { - control.deactivate(); - map.removeControl(control); - } - } - - - protected void setSelectedControl() { - removeControl(); - - final String type = getSelectedType(); - - if (type == null || type.length() == 0) { - return; - } - - if (type.equalsIgnoreCase(BARRIER_RINGDIKE)) { - control = createDrawPolygonControl(); - } - else { - control = createDrawLineControl(); - } - - map.addControl(control); - control.activate(); - - // Make sure the barrier layer is on top; sometime it looses it z-index... - layer.setZIndex(1000); - } - - - protected Control createDrawControl(Handler handler) { - return new DrawFeature(layer, handler); - } - - - protected Control createDrawPolygonControl() { - return createDrawControl(new PolygonHandler()); - } - - - protected Control createDrawLineControl() { - return createDrawControl(new PathHandler()); - } - - - public void activate(boolean activate) { - final FormItem item = form.getField(FIELD_BARRIER_TYPE); - - if (activate) { - button.select(); - item.enable(); - setSelectedControl(); - } - else { - removeControl(); - button.deselect(); - item.disable(); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ElevationWindow.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,432 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.types.SortArrow; -import com.smartgwt.client.types.SortDirection; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.IButton; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.events.CloseClickEvent; -import com.smartgwt.client.widgets.events.CloseClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; -import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; -import com.smartgwt.client.widgets.grid.events.RowOutEvent; -import com.smartgwt.client.widgets.grid.events.RowOutHandler; -import com.smartgwt.client.widgets.grid.events.RowOverEvent; -import com.smartgwt.client.widgets.grid.events.RowOverHandler; - -import org.gwtopenmaps.openlayers.client.Style; -import org.gwtopenmaps.openlayers.client.feature.VectorFeature; -import org.gwtopenmaps.openlayers.client.geometry.Geometry; -import org.gwtopenmaps.openlayers.client.geometry.LinearRing; -import org.gwtopenmaps.openlayers.client.geometry.LineString; -import org.gwtopenmaps.openlayers.client.geometry.Point; -import org.gwtopenmaps.openlayers.client.geometry.Polygon; -import org.gwtopenmaps.openlayers.client.layer.Vector; -import org.gwtopenmaps.openlayers.client.layer.VectorOptions; -import org.gwtopenmaps.openlayers.client.util.Attributes; - -import de.intevation.flys.client.client.FLYSConstants; - - - -public class ElevationWindow extends Window { - - public static FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public static final int WINDOW_WIDTH = 250; - public static final int WINDOW_HEIGHT = 250; - - protected FloodMap floodmap; - protected Vector layer; - protected VectorFeature feature; - - protected ListGrid grid; - - - private class PointRecord extends ListGridRecord { - protected VectorFeature point; - - public PointRecord(VectorFeature point, double x, double y, String z) { - super(); - - this.point = point; - setAttribute("x", x); - setAttribute("y", y); - setAttribute("z", z); - } - - public VectorFeature getPoint() { - return point; - } - } - - - public ElevationWindow(FloodMap floodmap, VectorFeature feature) { - super(); - this.feature = feature; - this.floodmap = floodmap; - - init(); - } - - - protected void init() { - addCloseClickHandler(new CloseClickHandler() { - public void onCloseClick(CloseClickEvent evt) { - doClose(); - } - }); - - initLayout(); - initEdit(); - updateGrid(); - } - - - protected void initLayout() { - setWidth(WINDOW_WIDTH); - setHeight(WINDOW_HEIGHT); - setTitle(MSG.ele_window_title()); - - VLayout root = new VLayout(); - root.setMembersMargin(5); - root.setPadding(5); - - root.addMember(getLabel()); - root.addMember(getGrid()); - root.addMember(getButtonBar()); - - addItem(root); - centerInPage(); - } - - - protected void initEdit() { - VectorOptions opts = new VectorOptions(); - opts.setProjection(floodmap.getRiverProjection()); - opts.setMaxExtent(floodmap.getMaxExtent()); - - layer = new Vector("tmp", opts); - layer.setIsBaseLayer(false); - - floodmap.getMap().addLayer(layer); - } - - - public Style getStyle() { - Style style = new Style(); - style.setStrokeColor("#000000"); - style.setStrokeWidth(1); - style.setFillColor("#FF0000"); - style.setFillOpacity(0.5); - style.setPointRadius(5); - style.setStrokeOpacity(1.0); - return style; - } - - - public Style getHighStyle() { - Style style = new Style(); - style.setStrokeColor("#000000"); - style.setStrokeWidth(1); - style.setFillColor("#FFFF22"); - style.setFillOpacity(0.5); - style.setPointRadius(5); - style.setStrokeOpacity(1.0); - return style; - } - - - protected Label getLabel() { - Label label = new Label(MSG.ele_window_label()); - label.setHeight(25); - - return label; - } - - - protected ListGrid getGrid() { - if (grid == null) { - grid = new ListGrid(); - grid.setCanEdit(true); - grid.setCanReorderFields(false); - grid.setAutoFitMaxWidth(WINDOW_WIDTH); - grid.setShowHeaderContextMenu(false); - grid.setShowSortArrow(SortArrow.NONE); - grid.setSortDirection(SortDirection.DESCENDING); - grid.setSelectionType(SelectionStyle.NONE); - - ListGridField x = new ListGridField("x", MSG.ele_window_x_col()); - x.setCanEdit(false); - - ListGridField y = new ListGridField("y", MSG.ele_window_y_col()); - y.setCanEdit(false); - - ListGridField z = new ListGridField("z", MSG.ele_window_z_col()); - z.setCanEdit(true); - - grid.setFields(x, y, z); - - grid.addRowOverHandler(new RowOverHandler() { - public void onRowOver(RowOverEvent evt) { - PointRecord pr = (PointRecord) evt.getRecord(); - VectorFeature p = pr.getPoint(); - - p.setStyle(getHighStyle()); - layer.redraw(); - } - }); - - grid.addRowOutHandler(new RowOutHandler() { - public void onRowOut(RowOutEvent evt) { - PointRecord pr = (PointRecord) evt.getRecord(); - VectorFeature p = pr.getPoint(); - - p.setStyle(getStyle()); - layer.redraw(); - } - }); - - grid.addEditCompleteHandler(new EditCompleteHandler() { - public void onEditComplete(EditCompleteEvent evt) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - String z = (String) evt.getNewValues().get("z"); - - try { - nf.parse(z); - } - catch (NumberFormatException nfe) { - SC.warn(MSG.ele_window_format_error() + " " + z); - - PointRecord old = (PointRecord) evt.getOldRecord(); - - ListGridRecord[] records = grid.getRecords(); - records[evt.getRowNum()] = old; - - grid.setRecords(records); - } - - } - }); - } - - return grid; - } - - - protected HLayout getButtonBar() { - HLayout bar = new HLayout(); - bar.setAlign(Alignment.CENTER); - bar.setHeight(25); - bar.setMembersMargin(15); - - bar.addMember(getOKButton()); - bar.addMember(getCancelButton()); - - return bar; - } - - - protected IButton getOKButton() { - IButton btn = new IButton(MSG.ele_window_ok_button()); - - btn.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent evt) { - if (saveElevation()) { - doClose(); - } - - } - }); - - return btn; - } - - - protected IButton getCancelButton() { - IButton btn = new IButton(MSG.ele_window_cancel_button()); - - btn.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent evt) { - doClose(); - } - }); - - return btn; - } - - - public void updateGrid() { - Attributes attr = feature.getAttributes(); - Geometry geom = feature.getGeometry(); - - String barrierType = null; - - if (attr != null) { - barrierType = attr.getAttributeAsString("typ"); - } - else { - barrierType = DrawControl.BARRIER_DAM_VALUE; - } - - GWT.log("Geometry is from type: " + geom.getClassName()); - GWT.log("Barrier is from type: " + barrierType); - - double[][] points = getPointsFromGeometry(geom); - double[] ele = extractElevations(attr); - - if (points == null) { - return; - } - - NumberFormat nf = NumberFormat.getDecimalFormat(); - - ListGrid grid = getGrid(); - - int zLen = ele != null ? ele.length : 0; - - for (int i = 0, len = points.length; i < len; i++) { - double[] point = points[i]; - VectorFeature p = addPoint(point[0], point[1]); - - String value = null; - - if (zLen > i) { - value = nf.format(ele[i]); - } - else if (barrierType.equals(DrawControl.BARRIER_DITCH_VALUE)) { - value = "-9999"; - } - else { - value = "9999"; - } - - grid.addData(new PointRecord(p, point[0], point[1], value)); - } - - grid.redraw(); - } - - - public static double[] extractElevations(Attributes attr) { - if (attr == null) { - return null; - } - - String elevationStr = attr.getAttributeAsString("elevation"); - - if (elevationStr == null || elevationStr.length() == 0) { - return null; - } - - String[] elevations = elevationStr.split(" "); - - int len = elevations != null ? elevations.length : 0; - - if (len == 0) { - return null; - } - - double[] res = new double[len]; - - for (int i = 0; i < len; i++) { - try { - res[i] = Double.valueOf(elevations[i]); - } - catch (NumberFormatException nfe) { - // go on - } - } - - return res; - } - - - public static double[][] getPointsFromGeometry(Geometry geom) { - String clazz = geom.getClassName(); - - if (clazz != null && clazz.equals(Geometry.LINESTRING_CLASS_NAME)) { - return getPointsFromLineString( - LineString.narrowToLineString(geom.getJSObject())); - } - else if (clazz != null && clazz.equals(Geometry.POLYGON_CLASS_NAME)) { - return getPointsFromPolygon( - Polygon.narrowToPolygon(geom.getJSObject())); - } - else { - SC.warn(MSG.ele_window_geometry_error() + " " + clazz); - } - - return null; - } - - - public static double[][] getPointsFromLineString(LineString line) { - return line.getCoordinateArray(); - } - - - public static double[][] getPointsFromPolygon(Polygon polygon) { - LinearRing[] rings = polygon.getComponents(); - - return getPointsFromLineString(rings[0]); - } - - - protected VectorFeature addPoint(double x, double y) { - VectorFeature point = new VectorFeature(new Point(x, y), getStyle()); - layer.addFeature(point); - - return point; - } - - - protected boolean saveElevation() { - ListGridRecord[] records = grid.getRecords(); - - NumberFormat nf = NumberFormat.getDecimalFormat(); - - StringBuilder sb = new StringBuilder(); - - for (ListGridRecord record: records) { - PointRecord pr = (PointRecord) record; - String value = pr.getAttributeAsString("z"); - - try { - double z = nf.parse(value); - sb.append(String.valueOf(z)); - } - catch (NumberFormatException nfe) { - SC.warn(MSG.ele_window_save_error()); - return false; - } - - sb.append(" "); - } - - Attributes attr = feature.getAttributes(); - attr.setAttribute("elevation", sb.toString()); - - return true; - } - - - protected void doClose() { - floodmap.getMap().removeLayer(layer); - destroy(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,394 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.LinkedHashMap; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.ComboBoxItem; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.Layout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.model.Capabilities; -import de.intevation.flys.client.shared.model.WMSLayer; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.GCService; -import de.intevation.flys.client.client.services.GCServiceAsync; -import de.intevation.flys.client.client.services.MapUrlService; -import de.intevation.flys.client.client.services.MapUrlServiceAsync; - - -public class ExternalWMSWindow extends Window { - - public interface LayerLoader { - void load(List<WMSLayer> toLoad); - } // end of interface WMSLayerLoader - - - protected GCServiceAsync gcService = GWT.create(GCService.class); - protected MapUrlServiceAsync muService = GWT.create(MapUrlService.class); - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected Layout inputPanel; - protected Layout infoPanel; - protected Layout layersPanel; - - protected Capabilities capabilites; - - protected String srs; - - protected LinkedHashMap<String, String> urls; - protected String url; - - protected LayerLoader loader; - - - public ExternalWMSWindow(LayerLoader loader) { - super(); - this.urls = new LinkedHashMap<String, String>(); - this.loader = loader; - } - - - public ExternalWMSWindow(LayerLoader loader, String srs) { - this(loader); - this.srs = srs; - } - - - protected void setUrl(String url) { - this.url = url; - } - - - protected String getUrl() { - return url; - } - - - protected String getCapabilitiesUrl() { - String cUrl = url; - - if (url.indexOf("?") >= 0) { - cUrl += "&SERVICE=WMS&REQUEST=GetCapabilities"; - } - else { - cUrl += "?SERVICE=WMS&REQUEST=GetCapabilities"; - } - - return cUrl; - } - - - protected void setCapabilites(Capabilities capabilites) { - this.capabilites = capabilites; - } - - - public void start() { - show(); - centerInPage(); - - goToInputPanel(); - } - - - protected void goToInputPanel() { - clearItems(); - - inputPanel = createInputPanel(); - - addItem(inputPanel); - - setWidth(380); - setHeight(140); - } - - - protected void goToInfoPanel() { - clearItems(); - - infoPanel = createInfoPanel(); - - addItem(infoPanel); - - setWidth(500); - setHeight(500); - - centerInPage(); - } - - - protected void goToLayersPanel() { - clearItems(); - - layersPanel = createLayersPanel(); - - addItem(layersPanel); - - setWidth(500); - setHeight(500); - } - - - protected void clearItems() { - Canvas[] items = getItems(); - - if (items != null) { - for (Canvas item: items) { - removeItem(item); - } - } - } - - - protected void setUrls(Map<String, String> urls) { - this.urls.putAll(urls); - } - - protected void readUrls() { - } - - - protected Layout createInputPanel() { - setTitle(MSG.addwmsInputTitle()); - - readUrls(); - - DynamicForm form = new DynamicForm(); - final ComboBoxItem url = new ComboBoxItem("Url:"); - url.setRedrawOnChange(true); - muService.getUrls(new AsyncCallback<Map<String, String> >() { - public void onFailure(Throwable caught) { - GWT.log("Error reading WMS-Services" + caught.getMessage()); - } - public void onSuccess(Map<String, String> wms) { - urls.putAll(wms); - url.setValueMap(urls); - - } - }); - - String oldUrl = getUrl(); - if (oldUrl != null && oldUrl.length() > 0) { - url.setValue(oldUrl); - } - - ClickHandler goHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - String newUrl = url.getValue().toString(); - - if (!isUrlValid(newUrl)) { - SC.warn(MSG.addwmsInvalidURL()); - return; - } - - setUrl(newUrl); - - doCapabilitesRequest(); - } - }; - - ClickHandler cancelHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - quit(); - } - }; - - VLayout root = new VLayout(); - root.setHeight(75); - root.setMargin(10); - root.setLayoutMargin(10); - - form.setFields(url); - root.addMember(form); - root.addMember(createButtonPanel(null, goHandler, cancelHandler)); - - return root; - } - - - protected Layout createInfoPanel() { - setTitle(MSG.addwmsInfoTitle()); - - ClickHandler backHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - goToInputPanel(); - } - }; - - ClickHandler goHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - goToLayersPanel(); - } - }; - - ClickHandler cancelHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - quit(); - } - }; - - VLayout root = new VLayout(); - VLayout panel = new CapabilitiesPanel(capabilites); - - root.setLayoutMargin(10); - panel.setHeight(420); - - root.addMember(panel); - root.addMember(createButtonPanel(backHandler, goHandler, cancelHandler)); - - return root; - } - - - protected Layout createLayersPanel() { - setTitle(MSG.addwmsLayerTitle()); - - final WMSLayersTree tree = new WMSLayersTree(capabilites, srs); - - ClickHandler backHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - goToInfoPanel(); - } - }; - - ClickHandler goHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - ListGridRecord[] selection = tree.getSelectedRecords(); - - if (selection == null || selection.length == 0) { - return; - } - - List<WMSLayer> toLoad = new ArrayList<WMSLayer>(); - - for (ListGridRecord record: selection) { - toLoad.add( - ((WMSLayersTree.WMSLayerNode) record).getWMSLayer()); - - } - - finish(toLoad); - } - }; - - ClickHandler cancelHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - quit(); - } - }; - - VLayout root = new VLayout(); - - root.setLayoutMargin(10); - tree.setHeight(420); - - root.addMember(tree); - root.addMember(createButtonPanel(backHandler, goHandler, cancelHandler)); - - return root; - } - - - /** - * @param back - * @param ok - * @param cancel - * - * @return - */ - protected Layout createButtonPanel( - ClickHandler backHandler, - ClickHandler goHandler, - ClickHandler cancelHandler - ) { - Button back = new Button(MSG.addwmsBack()); - Button go = new Button(MSG.addwmsContinue()); - Button cancel = new Button(MSG.addwmsCancel()); - - if (backHandler != null) { - back.addClickHandler(backHandler); - } - else { - back.setDisabled(true); - } - - if (goHandler != null) { - go.addClickHandler(goHandler); - } - else { - go.setDisabled(true); - } - - if (cancelHandler != null) { - cancel.addClickHandler(cancelHandler); - } - else { - cancel.setDisabled(true); - } - - HLayout buttonPanel = new HLayout(); - buttonPanel.setHeight(25); - buttonPanel.setMembersMargin(15); - buttonPanel.setLayoutTopMargin(10); - buttonPanel.addMember(back); - buttonPanel.addMember(go); - buttonPanel.addMember(cancel); - - return buttonPanel; - } - - - protected boolean isUrlValid(String url) { - // TODO Improve URL validation - return !(url == null || url.length() == 0); - } - - - protected void finish(List<WMSLayer> toLoad) { - loader.load(toLoad); - - quit(); - } - - - protected void quit() { - destroy(); - } - - - protected void doCapabilitesRequest() { - gcService.query(getCapabilitiesUrl(),new AsyncCallback<Capabilities>() { - public void onFailure(Throwable e) { - SC.warn(MSG.getString(e.getMessage())); - } - - public void onSuccess(Capabilities capabilites) { - setCapabilites(capabilites); - goToInfoPanel(); - } - }); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,330 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import org.gwtopenmaps.openlayers.client.Bounds; -import org.gwtopenmaps.openlayers.client.LonLat; -import org.gwtopenmaps.openlayers.client.Map; -import org.gwtopenmaps.openlayers.client.MapOptions; -import org.gwtopenmaps.openlayers.client.MapWidget; -import org.gwtopenmaps.openlayers.client.Style; -import org.gwtopenmaps.openlayers.client.control.Attribution; -import org.gwtopenmaps.openlayers.client.control.ScaleLine; -import org.gwtopenmaps.openlayers.client.control.ScaleLineOptions; -import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; -import org.gwtopenmaps.openlayers.client.feature.VectorFeature; -import org.gwtopenmaps.openlayers.client.format.GeoJSON; -import org.gwtopenmaps.openlayers.client.layer.Layer; -import org.gwtopenmaps.openlayers.client.layer.Vector; -import org.gwtopenmaps.openlayers.client.layer.VectorOptions; -import org.gwtopenmaps.openlayers.client.util.Attributes; -import org.gwtopenmaps.openlayers.client.util.JObjectArray; -import org.gwtopenmaps.openlayers.client.util.JSObject; - - -public class FloodMap implements VectorFeatureAddedListener { - - public static final String LAYER_BARRIERS = "vector_layer_barriers"; - - public static final String MARK_SELECTED = "mark.selected"; - - public static final int SELECTED_STROKE_WIDTH = 2; - - protected MapWidget mapWidget; - protected Map map; - protected Vector barrierLayer; - protected String srid; - protected Bounds maxExtent; - protected ScaleLine scaleLine; - - public FloodMap(String srid, Bounds maxExtent, int width, int height) { - this.srid = srid; - this.maxExtent = maxExtent; - recreateWidget(width, height); - getBarrierLayer(); - } - - - public void recreateWidget(int width, int height) { - final MapOptions opts = new MapOptions(); - opts.setControls(new JObjectArray(new JSObject[] {})); - opts.setNumZoomLevels(16); - opts.setProjection(getRiverProjection()); - opts.setMaxExtent(maxExtent); - opts.setUnits("m"); - opts.setMaxResolution(500); // TODO DO THIS ON THE FLY - - mapWidget = new MapWidget( - Integer.toString(width - 4), - Integer.toString(height), - opts); - map = mapWidget.getMap(); - map.addControl(new Attribution()); - } - - - @Override - public void onFeatureAdded(FeatureAddedEvent evt) { - final VectorFeature feature = evt.getVectorFeature(); - - final Attributes attrs = feature.getAttributes(); - final String type = attrs.getAttributeAsString("typ"); - - if (type == null || type.length() == 0) { - return; - } - - final Style style = getStyle(type); - if (style != null) { - feature.setStyle(style); - } - - // necessary, otherwise the setStyle() has no effect - getBarrierLayer().redraw(); - } - - - /** - * Returns an OpenLayers.Style based on a given type. - * - * @param type Type can be one of "pipe1", "pipe2", "ditch", "dam", - * "ringdike". - * - * @return an OpenLayers.Style object. - */ - public static Style getStyle(String type) { - final Style style = new Style(); - - if (type == null) { - return null; - } - - if (type.equals(DrawControl.BARRIER_PIPE1) - || type.equals(DrawControl.BARRIER_PIPE1_VALUE) - ) { - style.setFillColor("#800080"); - style.setStrokeColor("#800080"); - } - else if (type.equals(DrawControl.BARRIER_PIPE2) - || type.equals(DrawControl.BARRIER_PIPE2_VALUE) - ) { - style.setFillColor("#808080"); - style.setStrokeColor("#808080"); - } - else if (type.equals(DrawControl.BARRIER_DAM) - || type.equals(DrawControl.BARRIER_DAM_VALUE) - ) { - style.setFillColor("#008000"); - style.setStrokeColor("#008000"); - } - else if (type.equals(DrawControl.BARRIER_DITCH) - || type.equals(DrawControl.BARRIER_DITCH_VALUE) - ) { - style.setFillColor("#800000"); - style.setStrokeColor("#800000"); - } - else if (type.equals(DrawControl.BARRIER_RINGDIKE) - || type.equals(DrawControl.BARRIER_RINGDIKE_VALUE) - ) { - style.setFill(false); - style.setStrokeColor("#FF8000"); - } - - return style; - } - - - public MapWidget getMapWidget() { - return mapWidget; - } - - - public Map getMap() { - return map; - } - - - public String getRiverProjection() { - return "EPSG:" + srid; - } - - - public Bounds getMaxExtent() { - return maxExtent; - } - - - public Vector getBarrierLayer() { - if (barrierLayer == null) { - final VectorOptions opts = new VectorOptions(); - opts.setProjection(getRiverProjection()); - opts.setMaxExtent(getMaxExtent()); - - barrierLayer = new Vector(LAYER_BARRIERS, opts); - barrierLayer.setIsBaseLayer(true); - - map.addLayer(barrierLayer); - map.setLayerZIndex(barrierLayer, 1000); - - barrierLayer.addVectorFeatureAddedListener(this); - } - - return barrierLayer; - } - - - public String getFeaturesAsGeoJSON() { - // disable features before exporting to GeoJSON - disableFeatures(); - - final VectorFeature[] features = barrierLayer.getFeatures(); - - if (features == null || features.length == 0) { - return null; - } - - return new GeoJSON().write(features); - } - - - public void setSize(String width, String height) { - mapWidget.setWidth(width); - mapWidget.setHeight(height); - final int currentZoom = map.getZoom(); - final LonLat currentCenter = map.getCenter(); - map.updateSize(); - map.zoomTo(currentZoom); - map.setCenter(currentCenter); - } - - - public void addLayer(Layer layer) { - if (layer != null) { - map.addLayer(layer); - - final int index = map.getLayerIndex(layer); - final int newIndex = index * (-1) + 1; - - map.raiseLayer(layer, newIndex); - - update(); - } - } - - - public void hideBarrierLayer () { - if (getBarrierLayer() != null) { - barrierLayer.setIsVisible(false); - } - } - - public void showBarrierLayer () { - if (getBarrierLayer() != null) { - barrierLayer.setIsVisible(true); - } - } - - - public void selectFeature(VectorFeature feature) { - if (feature != null) { - selectFeatures(new VectorFeature[] { feature } ); - } - } - - - public void selectFeatures(VectorFeature[] features) { - if (features == null || features.length == 0) { - return; - } - - for (final VectorFeature feature: features) { - final Attributes attr = feature.getAttributes(); - - if (attr.getAttributeAsInt(MARK_SELECTED) == 1) { - continue; - } - - attr.setAttribute(MARK_SELECTED, 1); - - final Style style = feature.getStyle(); - final double strokeWidth = style.getStrokeWidth(); - - style.setStrokeWidth(strokeWidth+SELECTED_STROKE_WIDTH); - } - - getBarrierLayer().redraw(); - } - - - public void disableFeatures() { - final Vector barriers = getBarrierLayer(); - final VectorFeature[] features = barriers.getFeatures(); - - if (features == null || features.length == 0) { - return; - } - - disableFeatures(features); - } - - - public void disableFeature(VectorFeature feature) { - if (feature != null) { - disableFeatures(new VectorFeature[] { feature }); - } - } - - - public void disableFeatures(VectorFeature[] features) { - if (features == null || features.length == 0) { - return; - } - - for (final VectorFeature feature: features) { - final Attributes attr = feature.getAttributes(); - - if (attr.getAttributeAsInt(MARK_SELECTED) == 0) { - continue; - } - - attr.setAttribute(FloodMap.MARK_SELECTED, 0); - - final Style style = feature.getStyle(); - final double strokeWidth = style.getStrokeWidth(); - - style.setStrokeWidth(strokeWidth-SELECTED_STROKE_WIDTH); - } - - getBarrierLayer().redraw(); - } - - - public void update() { - final Layer[] layers = map.getLayers(); - - for (final Layer l: layers) { - l.redraw(); - } - } - - - public void updateSize() { - this.map.updateSize(); - } - - - public void activateScaleLine(boolean activate) { - if (activate) { - final ScaleLineOptions slOpts = new ScaleLineOptions(); - slOpts.setBottomInUnits("m"); - slOpts.setBottomOutUnits("km"); - slOpts.setTopInUnits(""); - slOpts.setTopOutUnits(""); - - scaleLine = new ScaleLine(slOpts); - this.map.addControl(scaleLine); - } - else if (!activate && scaleLine != null){ - this.map.removeControl(scaleLine); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import org.gwtopenmaps.openlayers.client.Map; -import org.gwtopenmaps.openlayers.client.LonLat; -import org.gwtopenmaps.openlayers.client.Pixel; -import org.gwtopenmaps.openlayers.client.event.MapClickListener; - -import de.intevation.flys.client.shared.model.FeatureInfo; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.GFIService; -import de.intevation.flys.client.client.services.GFIServiceAsync; -import de.intevation.flys.client.shared.model.FacetRecord; -import de.intevation.flys.client.shared.model.Theme; -import de.intevation.flys.client.shared.model.AttributedTheme; -import de.intevation.flys.client.shared.model.FeatureInfoResponse; -import de.intevation.flys.client.client.ui.ThemePanel; - - -public class GetFeatureInfo implements MapClickListener { - - protected GFIServiceAsync gfiService = GWT.create(GFIService.class); - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected GetFeatureInfoWindow gfiWindow; - - protected Map map; - protected ThemePanel themePanel; - protected String infoFormat; - - - /** - * @param map - * @param themes - * @param url - * @param infoFormat - */ - public GetFeatureInfo(Map map, ThemePanel themePanel, String infoFormat) { - this.map = map; - this.themePanel = themePanel; - this.infoFormat = infoFormat; - } - - - public void activate(boolean activate) { - if (activate) { - map.addMapClickListener(this); - } - else { - map.removeListener(this); - } - } - - - protected void newGetFeatureInfoWindow(List<FeatureInfo> features, String title) { - if (gfiWindow != null) { - gfiWindow.destroy(); - } - - gfiWindow = new GetFeatureInfoWindow(features, title); - gfiWindow.show(); - } - - protected void newGetFeatureInfoWindow(String response, String title) { - if (gfiWindow != null) { - gfiWindow.destroy(); - } - - gfiWindow = new GetFeatureInfoWindow(response, title); - gfiWindow.show(); - } - - @Override - public void onClick(MapClickListener.MapClickEvent e) { - LonLat lonlat = e.getLonLat(); - Pixel pixel = map.getPixelFromLonLat(lonlat); - - if (themePanel.getSelectedRecords().length == 0) { - SC.say(MSG.requireTheme()); - } - - for (ListGridRecord rec : themePanel.getSelectedRecords()) { - Theme act_theme = ((FacetRecord)rec).getTheme(); - final AttributedTheme at = (AttributedTheme)act_theme; - gfiService.query( - act_theme, - infoFormat, - map.getExtent().toString(), - map.getProjection(), - (int) map.getSize().getHeight(), - (int) map.getSize().getWidth(), - pixel.x(), pixel.y(), - new AsyncCallback<FeatureInfoResponse>() { - @Override - public void onFailure(Throwable e) { - SC.warn(MSG.getString(e.getMessage())); - } - - @Override - public void onSuccess(FeatureInfoResponse response) { - List<FeatureInfo> features = response.getFeatures(); - if (features != null && !features.isEmpty()) { - newGetFeatureInfoWindow(features, at.getAttr("description")); - } else if (response.getFeatureInfoHTML() != null) { - newGetFeatureInfoWindow(response.getFeatureInfoHTML(), - at.getAttr("description")); - } else { - GWT.log("GetFeatureInfo returned neither a list of features nor a string"); - } - } - } - ); - break; // More intelligent handling when more then one is selected - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.HTMLPane; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.viewer.DetailViewer; -import com.smartgwt.client.widgets.viewer.DetailViewerField; -import com.smartgwt.client.widgets.viewer.DetailViewerRecord; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.FeatureInfo; -import de.intevation.flys.client.shared.model.FeatureInfoResponse; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.MissingResourceException; - -import org.gwtopenmaps.openlayers.client.feature.VectorFeature; -import org.gwtopenmaps.openlayers.client.util.Attributes; -import org.gwtopenmaps.openlayers.client.util.JSObject; - - -public class GetFeatureInfoWindow extends Window { - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected List<FeatureInfo> features; - - protected String title; - - protected String featureInfoHTML; - - - public static final int ROW_HEIGHT = 25; - - - public GetFeatureInfoWindow(List<FeatureInfo> features, String title) { - super(); - this.features = features; - this.title = title; - - initLayout(); - } - - public GetFeatureInfoWindow(String featureInfoHTML, String title) { - super(); - features = null; - this.title = title; - this.featureInfoHTML = featureInfoHTML; - - initLayoutHTML(); - } - - protected void initLayoutHTML() { - HTMLPane pane = new HTMLPane(); - pane.setContents(featureInfoHTML); - addItem(pane); - setWidth(500); - setHeight(300); - - setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); - - setIsModal(false); -// setShowModalMask(true); - - centerInPage(); - } - - protected void initLayout() { - VLayout root = new VLayout(); - - for (FeatureInfo feature: features) { - // Currently this should alway be only one - root.addMember(createFeatureViewer(feature)); - setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); - } - - addItem(root); - - setWidth(500); - setHeight(300); - - setIsModal(false); -// setShowModalMask(true); - - centerInPage(); - } - - - protected DetailViewer createFeatureViewer(FeatureInfo feature) { - DetailViewer detailViewer = new DetailViewer(); - detailViewer.setWidth(487); - - Map<String, String> attrs = feature.getAttrs(); - Set<Map.Entry<String, String>> entries = attrs.entrySet(); - List <DetailViewerField> fields = new ArrayList<DetailViewerField>(); - DetailViewerRecord dr = new DetailViewerRecord(); - - DetailViewerField path_field = null; // Make sure path is always the last element - - for (Map.Entry<String, String> entry: entries) { - String localized; - try { - localized = MSG.getString(entry.getKey()); - } catch (MissingResourceException mre) { - localized = entry.getKey(); -// We filter unwanted information by localization -// Uncomment to filter out unlocalized elements -// continue; - } - if (entry.getKey().equals("PATH")) { - path_field = new DetailViewerField(entry.getKey(), localized); - } else { - fields.add(new DetailViewerField(entry.getKey(), localized)); - } - dr.setAttribute(entry.getKey(), entry.getValue()); - } - if (path_field != null) - fields.add(path_field); - - DetailViewerField[] fieldArray = new DetailViewerField[fields.size()]; - detailViewer.setFields(fields.toArray(fieldArray)); - detailViewer.setData(new DetailViewerRecord[]{dr}); - detailViewer.setCanSelectText(true); - - return detailViewer; - } - - - protected String[][] extractProperties(VectorFeature feature) { - Attributes tmp = feature.getAttributes(); - JSObject jsobj = tmp.getJSObject(); - - String tmpNames = jsobj.getPropertyNames(); - String[] allNames = tmpNames.split(","); - - String[][] attr = new String[allNames.length][]; - - for (int i = 0, n = attr.length; i < n; i++) { - attr[i] = new String[] { - allNames[i], - jsobj.getPropertyAsString(allNames[i]) }; - } - - return attr; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/LegendWindow.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import java.util.List; - -import com.smartgwt.client.types.ImageStyle; -import com.smartgwt.client.types.VerticalAlignment; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.shared.MapUtils; -import de.intevation.flys.client.shared.model.AttributedTheme; -import de.intevation.flys.client.shared.model.Theme; -import de.intevation.flys.client.shared.model.ThemeList; - - -public class LegendWindow extends Window { - - private ThemeList themeList; - - private VLayout legendContainer; - - public LegendWindow(ThemeList themeList) { - this.themeList = themeList; - this.legendContainer = new VLayout(); - - init(); - } - - public void update(ThemeList themeList) { - this.themeList = themeList; - - Canvas[] legends = legendContainer.getMembers(); - legendContainer.removeMembers(legends); - - addLegends(); - } - - private void addLegends() { - List<Theme> themes = themeList.getActiveThemes(); - - for (Theme theme : themes) { - if (theme.getActive() == 0) { - continue; - } - - if (theme instanceof AttributedTheme) { - legendContainer - .addMember(createLegendGraphicsRow((AttributedTheme) theme)); - } - } - } - - private Canvas createLegendGraphicsRow(AttributedTheme at) { - Label label = new Label(at.getDescription()); - Img img = createLegendGraphics(at); - - HLayout row = new HLayout(); - row.addMember(label); - row.addMember(img); - - row.setHeight(150); - row.setWidth(400); - - return row; - } - - private Img createLegendGraphics(AttributedTheme at) { - String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), - at.getAttr("layers")); - - Img img = new Img(imgUrl); - img.setImageType(ImageStyle.CENTER); - img.setAutoFit(true); - - return img; - } - - private void init() { - legendContainer.setAutoHeight(); - legendContainer.setLayoutAlign(VerticalAlignment.TOP); - legendContainer.setAlign(VerticalAlignment.CENTER); - - setTitle("WMS Legend"); - setAutoSize(true); - setCanDragResize(true); - setIsModal(false); - setShowModalMask(false); - setLayoutAlign(VerticalAlignment.TOP); - setAlign(VerticalAlignment.TOP); - - addItem(legendContainer); - addLegends(); - - centerInPage(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,636 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.AbsolutePanel; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.events.ParentMovedEvent; -import com.smartgwt.client.widgets.events.ParentMovedHandler; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; -import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.event.OutputParameterChangeEvent; -import de.intevation.flys.client.client.event.OutputParameterChangeHandler; -import de.intevation.flys.client.client.event.RedrawRequestEvent; -import de.intevation.flys.client.client.event.RedrawRequestHandler; -import de.intevation.flys.client.client.services.LoadArtifactService; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.client.services.MapOutputService; -import de.intevation.flys.client.client.services.MapOutputServiceAsync; -import de.intevation.flys.client.client.services.StepForwardService; -import de.intevation.flys.client.client.services.StepForwardServiceAsync; -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.OutputTab; -import de.intevation.flys.client.client.ui.ThemePanel; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.AttributedTheme; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.MapConfig; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.Theme; -import de.intevation.flys.client.shared.model.ThemeList; -import de.intevation.flys.client.shared.model.WMSLayer; - -import java.util.HashMap; -import java.util.List; - -import org.gwtopenmaps.openlayers.client.Bounds; -import org.gwtopenmaps.openlayers.client.Map; -import org.gwtopenmaps.openlayers.client.MapWidget; -import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; -import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener; -import org.gwtopenmaps.openlayers.client.feature.VectorFeature; -import org.gwtopenmaps.openlayers.client.format.GeoJSON; -import org.gwtopenmaps.openlayers.client.layer.Layer; -import org.gwtopenmaps.openlayers.client.layer.TransitionEffect; -import org.gwtopenmaps.openlayers.client.layer.Vector; -import org.gwtopenmaps.openlayers.client.layer.WMS; -import org.gwtopenmaps.openlayers.client.layer.WMSOptions; -import org.gwtopenmaps.openlayers.client.layer.WMSParams; - - -public class MapOutputTab -extends OutputTab -implements RedrawRequestHandler, ExternalWMSWindow.LayerLoader, TabSelectedHandler, OutputParameterChangeHandler { - - public static final String DEFAULT_SRID = "4326"; - - public static final String BARRIERS_PARAMETER_KEY = "uesk.barriers"; - - public static final String WSPLGEN_FACET = "floodmap.wsplgen"; - - public static final String EXTERNAL_WMS_FACTORY = "externalwmsfactory"; - - - protected StepForwardServiceAsync feedService = - GWT.create(StepForwardService.class); - - protected MapOutputServiceAsync mapService = - GWT.create(MapOutputService.class); - - /** Service handle to clone and add artifacts to collection. */ - protected LoadArtifactServiceAsync loadArtifactService = - GWT.create(LoadArtifactService.class); - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected MapToolbar controlPanel; - protected ThemePanel themePanel; - protected Canvas themePanelCanvas; - protected MapWidget mapPanel; - protected Canvas mapPanelCanvas; - protected VLayout rootLayout = new VLayout(); - protected AbsolutePanel absPan = new AbsolutePanel(); - protected FloodMap floodMap; - protected java.util.Map<String, String> wmsUrls = new HashMap<String, String>(); - - - public MapOutputTab( - String title, - Collection collection, - OutputMode mode, - CollectionView collectionView - ){ - super(title, collection, collectionView, mode); - - collectionView.registerTabHandler(this); - - mapService.doOut(collection, new AsyncCallback<MapConfig>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("MAP ERROR: " + caught.getMessage()); - } - - @Override - public void onSuccess(MapConfig c) { - GWT.log("MAP SUCCESS!"); - - Bounds max = boundsFromString(c.getMaxExtent()); - Bounds initial = boundsFromString(c.getInitialExtent()); - - if (initial == null) { - GWT.log("Warning: No initial extent set."); - initial = max; - } - - setFloodmap(new FloodMap(c.getSrid(), max, 640, 480)); - - initLayout(); - initBarriers(); - - GWT.log("MAX EXTENT: " + max); - GWT.log("ZOOM TO: " + initial); - getMap().zoomToExtent(initial); - } - } - ); - } - - - protected void initLayout() { - rootLayout.setHeight100(); - rootLayout.setWidth100(); - rootLayout.setMembersMargin(2); - - HLayout hlayout = new HLayout(); - hlayout.setMembersMargin(0); - - this.themePanelCanvas = createThemePanel(); - - controlPanel = createControlPanel(); - mapPanel = floodMap.getMapWidget(); - - rootLayout.addMember(controlPanel); - rootLayout.addMember(absPan); - absPan.setWidth("100%"); - absPan.setHeight("100%"); - absPan.add(themePanelCanvas); - absPan.add(mapPanel); - - rootLayout.addResizedHandler(new ResizedHandler() { - @Override - public void onResized(ResizedEvent e) { - doLayout(); - } - }); - - rootLayout.addParentMovedHandler(new ParentMovedHandler() { - @Override - public void onParentMoved(ParentMovedEvent event) { - mapPanel.getMap().updateSize(); - } - }); - - setPane(rootLayout); - } - - - protected void doLayout() { - if(!rootLayout.isVisible()) { - return; - } - - // Manually set the height of the AbsolutePanel, somehow this is necessary - absPan.setHeight(String.valueOf( - rootLayout.getHeight() - controlPanel.getHeight() - 2) + "px"); - - // Calculate bounds of Map - int height = rootLayout.getHeight() - - controlPanel.getHeight() - 6; - int width = controlPanel.getWidth() - - (themePanelCanvas.isVisible() ? themePanelCanvas.getWidth() + 4 : 2); - - // Set size and position of Map - String w = String.valueOf(width) + "px"; - String h = String.valueOf(height) + "px"; - GWT.log("width=" + w); - - mapPanel.setSize(w, h); - mapPanel.getMap().updateSize(); - if(themePanelCanvas.isVisible()) { - absPan.setWidgetPosition(mapPanel, themePanelCanvas.getWidth() + 2, 0); - } - else { - absPan.setWidgetPosition(mapPanel, 0, 0); - } - - // Set bounds of ThemePanelCanvas - themePanelCanvas.setSize(themePanelCanvas.getWidthAsString(), String.valueOf(height + 2) + "px"); - } - - - protected void initBarriers() { - Vector vector = floodMap.getBarrierLayer(); - vector.addVectorFeatureAddedListener( - new VectorFeatureAddedListener() { - @Override - public void onFeatureAdded(FeatureAddedEvent e) { - saveBarriers(); - } - } - ); - - vector.addVectorFeatureRemovedListener( - new VectorFeatureRemovedListener() { - @Override - public void onFeatureRemoved(FeatureRemovedEvent e) { - saveBarriers(); - } - } - ); - - - Artifact artifact = getArtifact(); - - if (artifact == null) { - return; - } - - ArtifactDescription desc = artifact.getArtifactDescription(); - - String geojson = getGeoJSONFromStatic(desc); - geojson = geojson != null ? geojson : getGeoJSONFromDynamic(desc); - - if (geojson == null || geojson.length() == 0) { - GWT.log("No geojson string found -> no barriers existing."); - return; - } - - GeoJSON reader = new GeoJSON(); - VectorFeature[] features = reader.read(geojson); - - vector.addFeatures(features); - } - - - public void addLayer(Layer layer) { - FloodMap map = getFloodmap(); - - if (map != null) { - GWT.log("Add new layer '" + layer.getName() + "' to map."); - map.addLayer(layer); - if (layer instanceof WMS) { - wmsUrls.put(layer.getName(), - ((WMS)layer).getFullRequestString(new WMSParams(), null)); - } - } - } - - - public void removeLayer(String name) { - Map map = getMap(); - - Layer[] layers = map.getLayers(); - - for (Layer layer: layers) { - if (name.equals(layer.getName())) { - map.removeLayer(layer); - } - } - } - - - @Override - public void onRedrawRequest(RedrawRequestEvent event) { - mapService.doOut(collection, new AsyncCallback<MapConfig>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("MAP ERROR: " + caught.getMessage()); - } - - @Override - public void onSuccess(MapConfig c) { - GWT.log("We want to refresh the map now!"); - themePanel.updateCollection(); - getFloodmap().update(); - } - }); - } - - - @Override - public void load(List<WMSLayer> toLoad) { - GWT.log("The user wants to add " + toLoad.size() + " new WMS layers."); - - int len = toLoad.size(); - - Recommendation[] recom = new Recommendation[len]; - - for (int i = 0; i < len; i++) { - WMSLayer w = toLoad.get(i); - - String ids = w.getServer() + ";" + w.getName() + ";" + w.getTitle(); - recom[i] = new Recommendation(EXTERNAL_WMS_FACTORY, ids); - } - - Collection c = getCollection(); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - loadArtifactService.loadMany(c, recom, EXTERNAL_WMS_FACTORY, locale, - new AsyncCallback<Artifact[]>() { - - @Override - public void onFailure(Throwable throwable) { - SC.warn(MSG.getString(throwable.getMessage())); - } - - @Override - public void onSuccess(Artifact[] newArtifacts) { - getThemePanel().updateCollection(); - } - } - ); - } - - - protected void setFloodmap(FloodMap floodMap) { - this.floodMap = floodMap; - } - - - protected FloodMap getFloodmap() { - return floodMap; - } - - - protected Map getMap() { - return floodMap.getMap(); - } - - - protected ThemePanel getThemePanel() { - return themePanel; - } - - - protected String getGeoJSONFromDynamic(ArtifactDescription desc) { - DataList list = desc.getCurrentData(); - - if (list == null) { - return null; - } - - List<Data> datas = list.getAll(); - for (Data data: datas) { - String key = data.getLabel(); - - if (key != null && key.equals(BARRIERS_PARAMETER_KEY)) { - DataItem def = data.getDefault(); - - if (def != null) { - return def.getStringValue(); - } - } - } - - return null; - } - - - protected String getGeoJSONFromStatic(ArtifactDescription desc) { - // TODO Implement this method, if there are reachable states right after - // the floodmap state - which is currently not the case. - return null; - } - - - public ThemeList getThemeList() { - return collection.getThemeList(mode.getName()); - } - - - public String getSrid() { - ThemeList themeList = getThemeList(); - - int num = themeList.getThemeCount(); - - for (int i = 1; i <= num; i++) { - AttributedTheme theme = (AttributedTheme) themeList.getThemeAt(i); - - if (theme == null) { - continue; - } - - String srid = theme.getAttr("srid"); - - if (srid != null && srid.length() > 0) { - return srid; - } - } - - return DEFAULT_SRID; - } - - - protected Bounds boundsFromString(String bounds) { - GWT.log("Create Bounds from String: '" + bounds + "'"); - if (bounds == null || bounds.length() == 0) { - return null; - } - - String[] values = bounds.split(" "); - - if (values == null || values.length < 4) { - return null; - } - - try { - return new Bounds( - Double.valueOf(values[0]), - Double.valueOf(values[1]), - Double.valueOf(values[2]), - Double.valueOf(values[3])); - } - catch (NumberFormatException nfe) {} - - return null; - } - - - public Layer createWMSLayer(Theme theme) { - if (!(theme instanceof AttributedTheme)) { - return null; - } - - AttributedTheme at = (AttributedTheme) theme; - - String name = at.getAttr("name"); - String desc = at.getAttr("description"); - String url = at.getAttr("url"); - String layers = at.getAttr("layers"); - - if (url == null || layers == null) { - return null; - } - - WMSParams params = new WMSParams(); - params.setLayers(layers); - params.setFormat("image/png"); - params.setIsTransparent(true); - - WMSOptions opts = new WMSOptions(); - opts.setProjection("EPSG:" + getSrid()); - opts.setSingleTile(true); - opts.setRatio(1); - if (layers.equals("OSM-WMS-Dienst")) { - opts.setAttribution(MSG.attribution()); - opts.setSingleTile(true); - opts.setTransitionEffect(TransitionEffect.RESIZE); - } - WMS wms = new WMS(layers, url, params, opts); - wms.setIsVisible(at.getActive() == 1); - wms.setIsBaseLayer(false); - // We can't set the full_url attribute here because map is not set - // at.addAttr("full_url", wms.getFullRequestString(params, null)); - return wms; - } - - - public java.util.Map<String, String> wmsUrls() { - return this.wmsUrls; - } - - - protected MapToolbar createControlPanel() { - return new MapToolbar(this, floodMap, false); - } - - - protected Canvas createThemePanel() { - Canvas c = new Canvas(); - c.setMinWidth(300); - c.setWidth(200); - c.setHeight100(); - c.setCanDragResize(true); - c.setBorder("1px solid black"); - - themePanel = new MapThemePanel( - this.getCollectionView(), - mode, - this, - new MapThemePanel.ActivateCallback() { - @Override - public void activate(Theme theme, boolean active) { - fireActivateTheme(theme, active); - } - }, - new MapThemePanel.ThemeMovedCallback() { - @Override - public void onThemeMoved(Theme theme, int oldIdx, int newIdx) { - // this code synchronizes the ThemePanel and the OpenLayers - // internal order of layers. - AttributedTheme at = (AttributedTheme) theme; - - String name = at.getAttr("layers"); - Map map = getMap(); - Layer[] layers = map.getLayersByName(name); - - if (layers == null || layers.length == 0) { - GWT.log("Error: Cannot find layer '" + name + "'"); - return; - } - - map.raiseLayer(layers[0], (newIdx-oldIdx)*-1); - map.zoomTo(map.getZoom()-1); - map.zoomTo(map.getZoom()+1); - } - }, - new MapThemePanel.LayerZoomCallback() { - @Override - public void onLayerZoom(Theme theme, String extent) { - Bounds zoomTo = boundsFromString(extent); - - if (zoomTo == null) { - GWT.log("WARNING: No valid bounds for zooming found!"); - return; - } - - getMap().zoomToExtent(zoomTo); - } - } - ); - themePanel.addRedrawRequestHandler(this); - themePanel.addOutputParameterChangeHandler(this); - c.addChild(themePanel); - - return c; - } - - - private void fireActivateTheme(Theme theme, boolean active) { - activateTheme(theme, active); - } - - - protected void activateTheme(Theme theme, boolean active) { - AttributedTheme at = (AttributedTheme) theme; - - String name = at.getAttr("layers"); - Layer layer = floodMap.getMap().getLayerByName(name); - - GWT.log("Set visibility of '" + name + "': " + active); - - if (layer != null) { - layer.setIsVisible(active); - } - } - - - protected void saveBarriers() { - Vector layer = floodMap.getBarrierLayer(); - - GeoJSON format = new GeoJSON(); - String features = format.write(layer.getFeatures()); - - DataItem item = new DefaultDataItem( - BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, features); - - Data data = new DefaultData( - BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, "String", - new DataItem[] {item} ); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - feedService.go(locale, getArtifact(), new Data[] { data }, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not save barrier geometries: " + - caught.getMessage()); - } - - @Override - public void onSuccess(Artifact artifact) { - GWT.log("Successfully saved barrier geometries."); - } - } - ); - } - - - @Override - public void onTabSelected(TabSelectedEvent tse) { - if(floodMap == null) { - return; - } - if(this.equals(tse.getTab())) { - floodMap.activateScaleLine(true); - } - else { - controlPanel.activateMeasureControl(false); - floodMap.activateScaleLine(false); - } - } - - public void toogleThemePanel() { - this.themePanelCanvas.setVisible(!themePanelCanvas.isVisible()); - - // Trigger resize event handler - doLayout(); - } - - - @Override - public void onOutputParameterChanged(OutputParameterChangeEvent evt) { - GWT.log("OutputParameterChanged"); - controlPanel.updateThemes(getThemePanel().getThemeList()); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.ui.AbsolutePanel; - -import de.intevation.flys.client.shared.model.BBox; -import de.intevation.flys.client.shared.model.MapInfo; - -import org.gwtopenmaps.openlayers.client.Bounds; -import org.gwtopenmaps.openlayers.client.MapWidget; - -/** - * Panel that contains a MapWidget and a MapToolbar. - * This panel is used by the flood map calculation input helper. - */ -public class MapPanel extends AbsolutePanel { - - protected MapToolbar toolbar; - - protected FloodMap floodMap; - protected MapWidget floodMapWidget; - protected boolean digitizeEnabled; - - public MapPanel(MapInfo mapInfo, boolean digitizeEnabled) { - BBox bbox = mapInfo.getBBox(); - - this.digitizeEnabled = digitizeEnabled; - this.floodMap = new FloodMap( - String.valueOf(mapInfo.getSrid()), - new Bounds( - bbox.getLowerX(), - bbox.getLowerY(), - bbox.getUpperX(), - bbox.getUpperY()), - 640, 480); - - initLayout(); - } - - - private void initLayout() { - setWidth("100%"); - setHeight("100%"); - - floodMapWidget = floodMap.getMapWidget(); - toolbar = new MapToolbar(floodMap, digitizeEnabled); - - add(toolbar); - add(floodMapWidget); - } - - public void doLayout(int w, int h) { - int width = w; - int height = h; - GWT.log("MapPanel.size: " + width + "x" + height); - - width -= 2; // minus black borders - height -= toolbar.getHeight() + 4; - - if (width < 0 || height < 0) { - GWT.log("MapPanel: Oops what a size!"); - return; - } - - floodMapWidget.setSize(Integer.toString(width), Integer.toString(height)); - floodMapWidget.getMap().updateSize(); - } - - - public FloodMap getFloodMap() { - return floodMap; - } - - public MapToolbar getMapToolbar () { - return toolbar; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPositionPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.HLayout; - -import org.gwtopenmaps.openlayers.client.LonLat; -import org.gwtopenmaps.openlayers.client.Map; -import org.gwtopenmaps.openlayers.client.MapWidget; -import org.gwtopenmaps.openlayers.client.Pixel; -import org.gwtopenmaps.openlayers.client.event.EventHandler; -import org.gwtopenmaps.openlayers.client.event.EventObject; -import org.gwtopenmaps.openlayers.client.util.JSObject; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MapPositionPanel extends HLayout { - - protected MapWidget mapWidget; - protected final Map map; - - protected Label x; - protected Label y; - - - public MapPositionPanel(MapWidget mapWidget) { - this.mapWidget = mapWidget; - this.map = mapWidget.getMap(); - - this.x = new Label(); - this.y = new Label(); - Label d = new Label("|"); - - setAlign(Alignment.RIGHT); - setMembersMargin(2); - - setWidth(150); - x.setWidth(25); - y.setWidth(25); - d.setWidth(5); - - addMember(x); - addMember(d); - addMember(y); - - // TODO This is not an optimal way to get the mouse position but makes - // the wrapper canvas superfluous. - this.map.getEvents().register("mousemove", map, new EventHandler() { - - @Override - public void onHandle(EventObject eventObject) { - JSObject xy = eventObject.getJSObject().getProperty("xy"); - Pixel px = Pixel.narrowToPixel(xy); - LonLat lonlat = map.getLonLatFromPixel(px); - - setX(lonlat.lon()); - setY(lonlat.lat()); - } - }); - } - - - protected void setX(double x) { - NumberFormat f = NumberFormat.getFormat("#0.0000"); - this.x.setContents(f.format(x).toString()); - } - - - protected void setY(double y) { - NumberFormat f = NumberFormat.getFormat("#0.0000"); - this.y.setContents(f.format(y).toString()); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,356 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.Window; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.ButtonItem; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.events.ClickEvent; -import com.smartgwt.client.widgets.form.fields.events.ClickHandler; -import com.smartgwt.client.types.Alignment; - -import org.gwtopenmaps.openlayers.client.Bounds; -import org.gwtopenmaps.openlayers.client.Map; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.CollectionAttributeService; -import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.OutputSettings; -import de.intevation.flys.client.shared.model.Property; -import de.intevation.flys.client.shared.model.PropertySetting; -import de.intevation.flys.client.shared.model.Settings; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; - - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.MissingResourceException; - -public class MapPrintPanel extends Canvas { - - private static final String MAPFISH_MAPTITLE = "mapfish_mapTitle"; - private static final String MAPFISH_RANGE = "mapfish_data_range"; - private static final String MAPFISH_SUBTITLE = "mapfish_data_subtitle"; - private static final String MAPFISH_STRETCH = "mapfish_data_strech"; - private static final String MAPFISH_INSTITUTION = "mapfish_data_institution"; - private static final String MAPFISH_SOURCE = "mapfish_data_source"; - private static final String MAPFISH_CREATOR = "mapfish_data_creator"; - private static final String MAPFISH_DATEPLACE = "mapfish_data_dateplace"; - private static final String MAPFISH_RIVER = "mapfish_data_river"; - private static final String MAPFISH_LOGO = "mapfish_logo"; - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** CollectionAttribute Update Service. */ - protected CollectionAttributeServiceAsync updater = - GWT.create(CollectionAttributeService.class); - - - protected Collection collection; - protected Settings settings; - protected TextItem pageTitle = new TextItem(); - protected TextItem pageRange = new TextItem(); - protected TextItem pageSubtitle = new TextItem(); - protected TextItem pageStretch = new TextItem(); - protected TextItem pageInstitution = new TextItem(); - protected TextItem pageSource = new TextItem(); - protected TextItem pageCreator = new TextItem(); - protected TextItem pageDatePlace = new TextItem(); - protected SelectItem pageLogo = createPageLogoSelectItem(); -// protected SelectItem pageFormat = createPageFormatSelectItem(); - protected MapToolbar mapToolbar; - protected MapPrintWindow parent; - - public MapPrintPanel(Collection collection, MapToolbar mapToolbar, MapPrintWindow parent) { - this.collection = collection; - this.mapToolbar = mapToolbar; - this.parent = parent; - initLayout(); - - this.settings = collection.getSettings("print-settings"); - if (settings == null) { - settings = new OutputSettings(); - GWT.log("settings are empty"); - } - else { - List<Property> properties = settings.getSettings("default"); - for (Property prop : properties) { - PropertySetting props = (PropertySetting)prop; - GWT.log(props.getName() + "=" + props.getValue()); - if (props.getName().equals(MAPFISH_MAPTITLE)) { - this.pageTitle.setValue(props.getValue()); - } - else if (props.getName().equals(MAPFISH_RANGE)) { - this.pageRange.setValue(props.getValue()); - } - else if (props.getName().equals(MAPFISH_SUBTITLE)) { - this.pageSubtitle.setValue(props.getValue()); - } - else if (props.getName().equals(MAPFISH_STRETCH)) { - this.pageStretch.setValue(props.getValue()); - } - else if (props.getName().equals(MAPFISH_INSTITUTION)) { - this.pageInstitution.setValue(props.getValue()); - } - else if (props.getName().equals(MAPFISH_SOURCE)) { - this.pageSource.setValue(props.getValue()); - } - else if (props.getName().equals(MAPFISH_CREATOR)) { - this.pageCreator.setValue(props.getValue()); - } - else if (props.getName().equals(MAPFISH_DATEPLACE)) { - this.pageDatePlace.setValue(props.getValue()); - } else { - GWT.log("Unknown Print property: " + prop.getName()); - } - } - } - } - - protected void initLayout() { - // TODO: i18n - this.pageTitle.setTitle(MSG.mapTitle()); - this.pageSubtitle.setTitle(MSG.mapSubtitle()); - this.pageRange.setTitle(MSG.mapRange()); - this.pageStretch.setTitle(MSG.mapStretch()); - this.pageInstitution.setTitle(MSG.mapInstitution()); - this.pageSource.setTitle(MSG.mapSource()); - this.pageCreator.setTitle(MSG.mapCreator()); - this.pageDatePlace.setTitle(MSG.mapDate()); - - pageTitle.setLength(30); - pageSubtitle.setLength(30); - pageRange.setLength(30); - pageStretch.setLength(30); - pageInstitution.setLength(30); - pageSource.setLength(30); - pageCreator.setLength(30); - pageDatePlace.setLength(30); - ButtonItem printButton = createPrintButtonItem(); - - printButton.setAlign(Alignment.RIGHT); - - DynamicForm df = new DynamicForm(); - df.setFields( -// this.pageFormat, - this.pageTitle, - this.pageSubtitle, - this.pageRange, - this.pageStretch, - this.pageInstitution, - this.pageSource, - this.pageCreator, - this.pageDatePlace, - this.pageLogo, - printButton); - addChild(df); - } - - protected SelectItem createPageLogoSelectItem() { - LinkedHashMap values = new LinkedHashMap(); - // TODO: this should be configurable - values.put(MSG.bfgLogo(), "BfG Logo"); - - SelectItem selItem = new SelectItem(); - selItem.setTitle(MSG.mapLogo()); - selItem.setValueMap(values); - selItem.setDefaultToFirstOption(true); - - return selItem; - } - -/* - * Commented out because we only provide a layout for A4 Landscape atm - - protected SelectItem createPageFormatSelectItem() { - LinkedHashMap values = new LinkedHashMap(); - // TODO: i18n - values.put("A4 landscape", "DIN A4 (Querformat)"); - //values.put("A4 portrait", "DIN A4 (Hochformat)"); - //values.put("A0 portrait", "DIN A0 (Hochformat)"); - - SelectItem selItem = new SelectItem(); - selItem.setTitle("Seitengröße:"); // TODO: i18n - selItem.setValueMap(values); - selItem.setDefaultToFirstOption(true); - - return selItem; - } -*/ - protected ButtonItem createPrintButtonItem() { - ButtonItem btn = new ButtonItem(); - btn.addClickHandler(new ClickHandler() { - - public void onClick(ClickEvent event) { - updateCollection(); - Window.open(createPrintUrl(), "_blank", ""); - parent.destroy(); - } - }); - btn.setTitle(MSG.print()); - return btn; - } - - private String createPrintUrl() { - MapOutputTab ot = (MapOutputTab)mapToolbar.getOutputTab(); - Collection collection = ot.getCollection(); - String uuid = collection.identifier(); - - String mapType = collection.getOutputModes().containsKey("floodmap") - ? "floodmap" - : "map"; - - StringBuilder url = new StringBuilder(); - url.append(GWT.getModuleBaseURL()); - url.append("map-print?"); - - Map map = mapToolbar.getMap(); - Bounds bounds = map.getExtent(); - - if (bounds != null) { - try { - url.append("minx="); - url.append(bounds.getLowerLeftX()); - url.append("&"); - - url.append("maxx="); - url.append(bounds.getUpperRightX()); - url.append("&"); - - url.append("miny="); - url.append(bounds.getLowerLeftY()); - url.append("&"); - - url.append("maxy="); - url.append(bounds.getUpperRightY()); - url.append("&"); - } - catch (Exception e) { - // XXX: Ignore it. bounds.getXXX() throw - // exceptions when bound is invalid. :-/ - } - } - - url.append("uuid="); - url.append(uuid); - url.append("&maptype="); - url.append(mapType); - - appendPrintToUrl(collection, url); - - return url.toString(); - } - - private void appendPrintToUrl(Collection collection, StringBuilder url) { - Settings settings = collection.getSettings("print-settings"); - if (settings != null) { - List<Property> properties = settings.getSettings("default"); - for (Property prop : properties) { - PropertySetting props = (PropertySetting)prop; - url.append("&"); - String localized; - try { - localized = MSG.getString(props.getName()); - } - catch (MissingResourceException mre) { - localized = props.getName(); - } - url.append(toJavaEncodedString(localized)); - url.append("="); - url.append(props.getValue()); - } - } - // O.o - String river = findRiver(((MapOutputTab)mapToolbar.getOutputTab() - ).getCollectionView().getArtifact()); - url.append("&" + toJavaEncodedString(MSG.getString(MAPFISH_RIVER)) + "=" + river); - } - - // Copy of DatacageWindow's findRiver - protected String findRiver(Artifact artifact) { - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList [] data = adescr.getOldData(); - - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - if (dl.getState().equals("state.winfo.river")) { - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - DataItem [] di = d.getItems(); - if (di != null && di.length == 1) { - return d.getItems()[0].getStringValue(); - } - } - } - } - } - - return ""; - } - - public static String toJavaEncodedString(String str) { - if (str == null) { - return null; - } - StringBuilder sb = new StringBuilder(); - for (int i = 0, len = str.length(); i < len; i++) { - int unipoint = Character.codePointAt(str, i); - if ((unipoint < 32) || (unipoint > 127)) { - sb.append("\\u"); - sb.append(Integer.toHexString((unipoint >> 3*4) & 0xf)); - sb.append(Integer.toHexString((unipoint >> 2*4) & 0xf)); - sb.append(Integer.toHexString((unipoint >> 1*4) & 0xf)); - sb.append(Integer.toHexString((unipoint >> 0*4) & 0xf)); - } else { - sb.append(str.charAt(i)); - } - } - return sb.toString(); - } - - protected void updateCollection() { - final Config config = Config.getInstance(); - final String loc = config.getLocale(); - - GWT.log("MapPrintPanel.updateCollection via RPC now"); - - List<Property> properties = new ArrayList<Property>(); - properties.add(new PropertySetting(MAPFISH_MAPTITLE, toJavaEncodedString(pageTitle.getValueAsString()))); -// properties.add(new PropertySetting(MAPFISH_LAYOUT, toJavaEncodedString(pageFormat.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_SUBTITLE, toJavaEncodedString(pageSubtitle.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_RANGE, toJavaEncodedString(pageRange.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_STRETCH, toJavaEncodedString(pageStretch.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_INSTITUTION, toJavaEncodedString(pageInstitution.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_SOURCE, toJavaEncodedString(pageSource.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_CREATOR, toJavaEncodedString(pageCreator.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_DATEPLACE, toJavaEncodedString(pageDatePlace.getValueAsString()))); - properties.add(new PropertySetting(MAPFISH_LOGO, toJavaEncodedString(pageLogo.getValueAsString()))); - settings.setSettings("default", properties); - - collection.addSettings("print-settings", settings); - updater.update(collection, loc, new AsyncCallback<Collection>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not update collection attributes."); - SC.warn(MSG.getString(caught.getMessage())); - } - @Override - public void onSuccess(Collection collection) { - GWT.log("MapPrint: collection attributes updated"); - } - }); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintWindow.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.smartgwt.client.widgets.Window; -import com.google.gwt.core.client.GWT; - -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.client.FLYSConstants; - -public class MapPrintWindow extends Window { - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected MapPrintPanel panel; - - public MapPrintWindow(Collection collection, MapToolbar mapToolbar) { - setWidth(255); - setHeight(300); - - setTitle(MSG.printWindowTitle()); - centerInPage(); - - this.panel = new MapPrintPanel(collection, mapToolbar, this); - this.panel.setPadding(20); - addItem(this.panel); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,294 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.util.BooleanCallback; -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.grid.events.HeaderDoubleClickEvent; -import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickHandler; -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 de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.ThemePanel; -import de.intevation.flys.client.shared.model.AttributedTheme; -import de.intevation.flys.client.shared.model.FacetRecord; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Theme; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MapThemePanel extends ThemePanel { - - public static final int CELL_HEIGHT = 25; - - - public interface ActivateCallback { - void activate(Theme theme, boolean activate); - } - - - public interface ThemeMovedCallback { - void onThemeMoved(Theme theme, int oldIdx, int newIdx); - } - - public interface LayerZoomCallback { - void onLayerZoom(Theme theme, String extent); - } - - - - private FLYSConstants MSG = GWT.create(FLYSConstants.class); - - - protected ActivateCallback activateCallback; - protected ThemeMovedCallback themeMovedCallback; - protected LayerZoomCallback layerZoomCallback; - - protected ListGridRecord[] oldRecords; - - - public static final String GRID_FIELD_ACTIVE = "active"; - public static final String GRID_FIELD_NAME = "name"; - - - protected MapOutputTab mapOut; - - - public MapThemePanel( - CollectionView view, - OutputMode mode, - MapOutputTab mapOut, - ActivateCallback activateCallback, - ThemeMovedCallback themeMovedCallback, - LayerZoomCallback layerZoomCallback - ) { - super(mode, view); - - this.mapOut = mapOut; - this.activateCallback = activateCallback; - this.themeMovedCallback = themeMovedCallback; - this.layerZoomCallback = layerZoomCallback; - - initGrid(); - initLayout(); - - updateGrid(); - } - - - protected void initLayout() { - setWidth100(); - setHeight100(); - - VLayout layout = new VLayout(); - layout.setWidth100(); - layout.setHeight100(); - - layout.addMember(list); - layout.addMember(navigation); - - addChild(layout); - } - - - protected void initGrid() { - list.setCanEdit(true); - list.setCanSort(false); - list.setShowRecordComponents(false); - list.setShowRecordComponentsByCell(true); - list.setShowHeader(true); - list.setShowHeaderContextMenu(false); - list.setCanReorderFields(false); - list.setWidth100(); - list.setHeight100(); - - list.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() { - @Override - public void onHeaderDoubleClick(HeaderDoubleClickEvent event) { - // cancel the event. - return; - } - }); - - list.setCellHeight(CELL_HEIGHT); - list.setShowRecordComponents(true); - list.setShowRecordComponentsByCell(true); - list.setShowAllRecords(true); - - list.addEditCompleteHandler(this); - - ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); - active.setType(ListGridFieldType.BOOLEAN); - active.setCanDragResize(false); - - ListGridField name = new ListGridField( - GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); - name.setType(ListGridFieldType.TEXT); - - list.setFields(active, name); - } - - - @Override - protected void clearGrid() { - oldRecords = list.getRecords(); - super.clearGrid(); - } - - - @Override - protected void addFacetRecord(FacetRecord rec) { - Theme newTheme = rec.getTheme(); - boolean isNew = true; - - for (ListGridRecord old: getOldRecords()) { - FacetRecord fr = (FacetRecord) old; - - if (newTheme.equals(fr.getTheme())) { - isNew = false; - break; - } - } - - if (isNew && mapOut != null) { - mapOut.addLayer(mapOut.createWMSLayer(newTheme)); - } - - super.addFacetRecord(rec); - } - - - @Override - protected Menu getSingleContextMenu(final ListGridRecord[] records) { - Menu menu = super.getSingleContextMenu(records); - - MenuItem layerZoom = createLayerZoomItem(records); - if (layerZoom != null) { - menu.addItem(layerZoom); - } - menu.addItem(createMapURLItem(records)); - - return menu; - } - - - protected MenuItem createMapURLItem(final ListGridRecord[] records) { - final FacetRecord fr = (FacetRecord) records[0]; - final AttributedTheme at = (AttributedTheme) fr.getTheme(); - - MenuItem item = new MenuItem(MSG.wmsURLMenuItem()); - item.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - String url = getMapOutputTab().wmsUrls().get(at.getAttr("layers")); - SC.say(MSG.wmsURLBoxTitle(), url); - } - }); - - return item; - } - - - @Override - protected MenuItem createRemoveItem(final ListGridRecord[] records) { - MenuItem item = super.createRemoveItem(records); - item.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - SC.ask(MSG.askThemeRemove(), new BooleanCallback() { - @Override - public void execute(Boolean value) { - if (value) { - for (ListGridRecord record: records) { - FacetRecord facet = (FacetRecord) record; - - Theme theme = facet.getTheme(); - theme.setVisible(0); - theme.setActive(0); - - AttributedTheme at = (AttributedTheme) theme; - getMapOutputTab().removeLayer(at.getAttr("layers")); - } - - updateCollection(); - } - } - }); - } - }); - - return item; - } - - - protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) { - final FacetRecord fr = (FacetRecord) recs[0]; - final AttributedTheme at = (AttributedTheme) fr.getTheme(); - - final String extent = at.getAttr("extent"); - - if (extent == null || extent.length() == 0) { - return null; - } - - MenuItem zoom = new MenuItem(MSG.zoomToLayer()); - zoom.addClickHandler(new ClickHandler() { - @Override - public void onClick(MenuItemClickEvent evt) { - if (layerZoomCallback != null) { - layerZoomCallback.onLayerZoom(at, extent); - } - } - }); - - return zoom; - } - - @Override - public String getWidthAsString() { - if(!isVisible()) { - return "0"; - } - else { - return super.getWidthAsString(); - } - } - - @Override - public void activateTheme(Theme theme, boolean active) { - if (activateCallback != null) { - activateCallback.activate(theme, active); - } - - theme.setActive(active ? 1 : 0); - } - - - @Override - protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) { - if (themeMovedCallback != null) { - themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx); - } - } - - - protected ListGridRecord[] getOldRecords() { - return oldRecords != null ? oldRecords : new ListGridRecord[0]; - } - - - protected MapOutputTab getMapOutputTab() { - return mapOut; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,686 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.types.SelectionType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.ImgButton; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.ui.ImgLink; -import de.intevation.flys.client.client.ui.Toolbar; -import de.intevation.flys.client.client.utils.EnableDisableCmd; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Property; -import de.intevation.flys.client.shared.model.PropertySetting; -import de.intevation.flys.client.shared.model.Settings; -import de.intevation.flys.client.shared.model.ThemeList; - -import java.util.List; - -import org.gwtopenmaps.openlayers.client.Map; -import org.gwtopenmaps.openlayers.client.control.DragPan; -import org.gwtopenmaps.openlayers.client.control.SelectFeature; -import org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions; -import org.gwtopenmaps.openlayers.client.control.ZoomBox; -import org.gwtopenmaps.openlayers.client.event.MapZoomListener; -import org.gwtopenmaps.openlayers.client.feature.VectorFeature; -import org.gwtopenmaps.openlayers.client.layer.Vector; -import org.gwtopenmaps.openlayers.client.util.Attributes; - - -/** - * Toolbar for the Map views. - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MapToolbar -extends Toolbar -implements MapZoomListener -{ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected FloodMap floodMap; - protected DragPan pan; - protected ZoomBox zoomBox; - protected SelectFeature selectFeature; - protected GetFeatureInfo getFeatureInfo; - - protected Button manageThemesButton; - protected Button datacageButton; - protected Button legendButton; - - protected ImgButton addWMSButton; - protected ImgButton zoomToMaxButton; - protected ImgButton zoomBoxButton; - protected ImgButton zoomOutButton; - protected ImgButton panButton; - protected ImgButton selectButton; - protected ImgButton infoButton; - protected ImgButton removeButton; - protected ImgButton elevationButton; - protected ImgButton printMap; - - protected Label epsgLabel; - - protected DrawControl drawControl; - protected MeasureControl measureControl; - - protected LegendWindow legendWindow; - - protected Canvas position; - - - public MapToolbar(FloodMap floodMap, boolean digitize) { - this(null, floodMap, digitize); - } - - - public MapToolbar( - MapOutputTab mapTab, - FloodMap floodMap, - boolean digitize) - { - super(mapTab); - - setWidth100(); - setHeight(38); - setMembersMargin(10); - setPadding(5); - setBorder("1px solid black"); - this.floodMap = floodMap; - - zoomToMaxButton = createMaxExtentControl(); - zoomBoxButton = createZoomBoxControl(); - zoomOutButton = createZoomOutControl(); - panButton = createPanControl(); - drawControl = createDrawControl(); - selectButton = createSelectFeatureControl(); - infoButton = createGetFeatureInfo(); - measureControl = createMeasureControl(); - position = createMousePosition(); - removeButton = createRemoveFeatureControl(); - elevationButton = createElevationControl(); - epsgLabel = createEPSGLabel(); - - if (mapTab != null) { - manageThemesButton = createManageThemesControl(); - addMember(manageThemesButton); - - datacageButton = createDatacageControl(); - addMember(datacageButton); - - legendButton = createLegendControl(); - addMember(legendButton); - - addWMSButton = createWMSControl(); - addMember(addWMSButton); - - printMap = createMapPrintControl(); - addMember(printMap); - } - - addMember(zoomToMaxButton); - addMember(zoomBoxButton); - addMember(zoomOutButton); - addMember(panButton); - - if (digitize) { - addMember(drawControl); - addMember(selectButton); - addMember(removeButton); - addMember(elevationButton); - } - - if (infoButton != null) { - addMember(infoButton); - } - - addMember(measureControl); - addMember(createRightPanel()); - } - - - protected HLayout createRightPanel() { - HLayout right = new HLayout(); - right.setAlign(Alignment.RIGHT); - - right.addMember(epsgLabel); - right.addMember(position); - - return right; - } - - - protected Map getMap() { - return floodMap.getMap(); - } - - - protected void activatePan(boolean activate) { - if (activate) { - panButton.select(); - pan.activate(); - } - else { - panButton.deselect(); - pan.deactivate(); - } - } - - - protected void activateZoomBox(boolean activate) { - if (activate) { - zoomBoxButton.select(); - zoomBox.activate(); - } - else { - zoomBoxButton.deselect(); - zoomBox.deactivate(); - } - } - - - public void activateDrawFeature(boolean activate) { - drawControl.activate(activate); - } - - - protected void activateSelectFeature(boolean activate) { - if (activate) { - selectButton.select(); - selectFeature.activate(); - } - else { - selectButton.deselect(); - selectFeature.deactivate(); - } - } - - - protected void activateMeasureControl(boolean activate) { - measureControl.activate(activate); - } - - - protected void activateGetFeatureInfo(boolean activate) { - if (infoButton == null) { - return; - } - - if (activate) { - infoButton.select(); - } - else { - infoButton.deselect(); - } - - getFeatureInfo.activate(activate); - } - - - protected ImgButton createButton(String img, ClickHandler handler) { - ImgButton btn = new ImgButton(); - - String baseUrl = GWT.getHostPageBaseURL(); - btn.setSrc(baseUrl + img); - btn.setWidth(20); - btn.setHeight(20); - btn.setShowDown(false); - btn.setShowRollOver(false); - btn.setShowRollOverIcon(false); - btn.setShowDisabled(false); - btn.setShowDisabledIcon(true); - btn.setShowDownIcon(false); - btn.setShowFocusedIcon(false); - - if (handler != null) { - btn.addClickHandler(handler); - } - - return btn; - } - - - protected ImgButton createToggleButton( - String img, - final EnableDisableCmd cmd - ) { - final ImgButton btn = new ImgButton(); - - String baseUrl = GWT.getHostPageBaseURL(); - btn.setSrc(baseUrl + img); - btn.setActionType(SelectionType.CHECKBOX); - btn.setSize(20); - btn.setShowRollOver(false); - btn.setShowRollOverIcon(false); - btn.setSelected(false); - btn.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent e) { - if (btn.isSelected()) { - cmd.enable(); - } - else { - cmd.disable(); - } - } - }); - - return btn; - } - - - protected ImgButton createMaxExtentControl() { - ImgButton zoomToMax = createButton(MSG.zoom_all(), new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - floodMap.getMap().zoomToMaxExtent(); - } - }); - - zoomToMax.setTooltip(MSG.zoomMaxExtent()); - - return zoomToMax; - } - - - protected ImgButton createZoomBoxControl() { - zoomBox = new ZoomBox(); - - EnableDisableCmd cmd = new EnableDisableCmd() { - @Override - public void enable() { - activatePan(false); - activateDrawFeature(false); - activateSelectFeature(false); - activateMeasureControl(false); - activateGetFeatureInfo(false); - activateZoomBox(true); - } - - @Override - public void disable() { - activateZoomBox(false); - } - }; - - ImgButton button = createToggleButton(MSG.zoom_in(), cmd); - button.setTooltip(MSG.zoomIn()); - - Map map = getMap(); - map.addControl(zoomBox); - - return button; - } - - - protected ImgButton createZoomOutControl() { - ImgButton zoomOut = createButton(MSG.zoom_out(), new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - Map map = floodMap.getMap(); - int level = map.getZoom(); - - if (level > 1) { - map.zoomTo(level-1); - } - } - }); - - zoomOut.setTooltip(MSG.zoomOut()); - - return zoomOut; - } - - - protected ImgButton createPanControl() { - pan = new DragPan(); - getMap().addControl(pan); - - EnableDisableCmd cmd = new EnableDisableCmd() { - @Override - public void enable() { - activateZoomBox(false); - activateDrawFeature(false); - activateSelectFeature(false); - activateMeasureControl(false); - activateGetFeatureInfo(false); - activatePan(true); - } - - @Override - public void disable() { - activatePan(false); - } - }; - - final ImgButton button = createToggleButton(MSG.pan(), cmd); - button.setTooltip(MSG.moveMap()); - - return button; - } - - - protected DrawControl createDrawControl() { - EnableDisableCmd cmd = new EnableDisableCmd() { - @Override - public void enable() { - activateZoomBox(false); - activatePan(false); - activateDrawFeature(true); - activateSelectFeature(false); - activateMeasureControl(false); - } - - @Override - public void disable() { - activateDrawFeature(false); - } - }; - return new DrawControl(getMap(), floodMap.getBarrierLayer(), cmd); - } - - - protected ImgButton createSelectFeatureControl() { - SelectFeatureOptions opts = new SelectFeatureOptions(); - opts.setBox(true); - - // VectorFeatures selected by the SelectFeature control are manually - // marked with the string "mark.delete". The control to remove selected - // features makes use of this string to determine if the feature should - // be deleted (is marked) or not. Actually, we would like to use the - // OpenLayers native mechanism to select features, but for some reason - // this doesn't work here. After a feature has been selected, the layer - // still has no selected features. - opts.onSelect(new SelectFeature.SelectFeatureListener() { - @Override - public void onFeatureSelected(VectorFeature feature) { - floodMap.selectFeature(feature); - } - }); - - opts.onUnSelect(new SelectFeature.UnselectFeatureListener() { - @Override - public void onFeatureUnselected(VectorFeature feature) { - floodMap.disableFeature(feature); - } - }); - - selectFeature = new SelectFeature(floodMap.getBarrierLayer(), opts); - getMap().addControl(selectFeature); - - EnableDisableCmd cmd = new EnableDisableCmd() { - @Override - public void enable() { - activateDrawFeature(false); - activatePan(false); - activateZoomBox(false); - activateSelectFeature(true); - activateMeasureControl(false); - } - - @Override - public void disable() { - activateSelectFeature(false); - floodMap.disableFeatures(); - } - }; - - ImgButton button = createToggleButton(MSG.selectFeature(), cmd); - button.setTooltip(MSG.selectObject()); - - return button; - } - - - protected ImgButton createRemoveFeatureControl() { - ImgButton remove = createButton(MSG.removeFeature(),new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - Vector barriers = floodMap.getBarrierLayer(); - VectorFeature[] features = barriers.getFeatures(); - - if (features == null || features.length == 0) { - return; - } - - for (int i = features.length-1; i >= 0; i--) { - VectorFeature feature = features[i]; - - Attributes attr = feature.getAttributes(); - int del = attr.getAttributeAsInt(FloodMap.MARK_SELECTED); - - if (del == 1) { - barriers.removeFeature(feature); - feature.destroy(); - } - } - } - }); - - remove.setTooltip(MSG.removeObject()); - - return remove; - } - - - protected ImgButton createElevationControl() { - ImgButton btn = createButton(MSG.adjustElevation(), new ClickHandler() { - @Override - public void onClick(ClickEvent evt) { - Vector barriers = floodMap.getBarrierLayer(); - VectorFeature[] features = barriers.getFeatures(); - - VectorFeature feature = null; - - if (features == null || features.length == 0) { - SC.warn(MSG.error_no_feature_selected()); - return; - } - - boolean multipleFeatures = false; - - for (VectorFeature f: features) { - Attributes attr = f.getAttributes(); - if (attr.getAttributeAsInt(FloodMap.MARK_SELECTED) == 1) { - if (feature == null) { - feature = f; - } - else { - multipleFeatures = true; - } - } - } - - if (feature == null) { - SC.warn(MSG.error_no_feature_selected()); - return; - } - - new ElevationWindow(floodMap, feature).show(); - - if (multipleFeatures) { - SC.warn(MSG.warning_use_first_feature()); - } - } - }); - - btn.setTooltip(MSG.adjustElevationTooltip()); - - return btn; - } - - - protected Canvas createMousePosition() { - return new MapPositionPanel(floodMap.getMapWidget()); - } - - - protected MeasureControl createMeasureControl() { - EnableDisableCmd cmd = new EnableDisableCmd() { - @Override - public void enable() { - activateDrawFeature(false); - activatePan(false); - activateZoomBox(false); - activateSelectFeature(false); - activateGetFeatureInfo(false); - } - - @Override - public void disable() { - // do nothing - } - }; - - return new MeasureControl(floodMap, cmd); - } - - - protected Button createDatacageControl() { - Button btn = new Button(MSG.databasket()); - btn.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent evt) { - openDatacageWindow((MapOutputTab) getOutputTab()); - } - }); - - return btn; - } - - - protected Button createLegendControl() { - Button btn = new Button(MSG.legend()); - btn.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - openLegendWindow(); - } - }); - - return btn; - } - - - protected void openLegendWindow() { - if (legendWindow == null) { - MapOutputTab tab = (MapOutputTab) getOutputTab(); - legendWindow = new LegendWindow(tab.getThemePanel().getThemeList()); - } - - legendWindow.show(); - } - - - protected ImgButton createGetFeatureInfo() { - MapOutputTab ot = (MapOutputTab) getOutputTab(); - if (ot == null) { - return null; - } - - //ThemeList tl = ot.getCollection().getThemeList("floodmap"); - - getFeatureInfo = new GetFeatureInfo( - getMap(), - ot.getThemePanel(), - "gml"); - - EnableDisableCmd cmd = new EnableDisableCmd() { - @Override - public void enable() { - activateDrawFeature(false); - activatePan(false); - activateZoomBox(false); - activateSelectFeature(false); - activateMeasureControl(false); - activateGetFeatureInfo(true); - } - - @Override - public void disable() { - activateGetFeatureInfo(false); - } - }; - - ImgButton button = createToggleButton(MSG.getFeatureInfo(), cmd); - button.setTooltip(MSG.getFeatureInfoTooltip()); - - return button; - } - - - protected Button createManageThemesControl() { - Button btn = new Button(MSG.manageThemes()); - btn.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - ((MapOutputTab)getOutputTab()).toogleThemePanel(); - } - }); - return btn; - } - - - protected ImgButton createMapPrintControl() { - final MapToolbar mtb = this; - ImgButton btn = createButton(MSG.printMapSettings(), new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - MapPrintWindow mpsw = - new MapPrintWindow(outputTab.getCollection(), mtb); - outputTab.getCollectionView().addChild(mpsw); - } - }); - btn.setTooltip(MSG.printTooltip()); - - return btn; - } - - - protected ImgButton createWMSControl() { - final String srs = floodMap.getRiverProjection(); - - ImgButton add = createButton(MSG.addWMS(), new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - MapOutputTab ot = (MapOutputTab) getOutputTab(); - new ExternalWMSWindow(ot, srs).start(); - } - }); - - add.setTooltip(MSG.addWMSTooltip()); - - return add; - } - - - protected Label createEPSGLabel() { - Label epsgLabel = new Label(floodMap.getRiverProjection()); - - epsgLabel.setAlign(Alignment.RIGHT); - epsgLabel.setWidth(75); - - return epsgLabel; - } - - @Override - public void onMapZoom(MapZoomListener.MapZoomEvent e) { -// updatePrintUrl(); - } - - public void updateThemes(ThemeList themeList) { - if (legendWindow != null) { - legendWindow.update(themeList); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MeasureControl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,219 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.SelectionType; -import com.smartgwt.client.widgets.ImgButton; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import org.gwtopenmaps.openlayers.client.control.Measure; -import org.gwtopenmaps.openlayers.client.event.MeasureEvent; -import org.gwtopenmaps.openlayers.client.event.MeasureListener; -import org.gwtopenmaps.openlayers.client.event.MeasurePartialListener; -import org.gwtopenmaps.openlayers.client.handler.PathHandler; -import org.gwtopenmaps.openlayers.client.handler.PolygonHandler; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.utils.EnableDisableCmd; - - -public class MeasureControl extends HLayout { - - public static final String NUMBER_FORMAT_PATTERN = "#.##"; - - public static final String AREA_UNIT = "ha"; - public static final int AREA_FACTOR_M = 10000; - public static final int AREA_FACTOR_KM = 100; - - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected FloodMap floodMap; - - protected Measure measureLine; - protected Measure measurePolygon; - - protected ImgButton measureLineButton; - protected ImgButton measurePolyButton; - protected Label label; - - protected NumberFormat formatter; - - - public MeasureControl(FloodMap floodMap, EnableDisableCmd cmd) { - this.floodMap = floodMap; - - measureLineButton = createMeasureLineControl(cmd); - measurePolyButton = createMeasurePolyControl(cmd); - - formatter = NumberFormat.getFormat(NUMBER_FORMAT_PATTERN); - - label = new Label(); - - initLayout(); - } - - - protected void initLayout() { - setWidth(100); - setMembersMargin(2); - - label.setWidth(75); - - addMember(measureLineButton); - addMember(measurePolyButton); - addMember(label); - } - - - protected ImgButton createMeasureLineControl(final EnableDisableCmd cmd) { - measureLine = new Measure(new PathHandler()); - measureLine.setPersist(true); - measureLine.addMeasureListener(new MeasureListener() { - public void onMeasure(MeasureEvent e) { - updateMeasure(e.getMeasure(), e.getUnits()); - } - }); - measureLine.addMeasurePartialListener(new MeasurePartialListener() { - public void onMeasurePartial(MeasureEvent e) { - updateMeasure(e.getMeasure(), e.getUnits()); - } - }); - - floodMap.getMap().addControl(measureLine); - - final ImgButton btn = new ImgButton(); - String baseUrl = GWT.getHostPageBaseURL(); - btn.setSrc(baseUrl + MSG.measureLine()); - btn.setActionType(SelectionType.CHECKBOX); - btn.setSize(20); - btn.setShowRollOver(false); - btn.setShowRollOverIcon(false); - btn.setSelected(false); - btn.setTooltip(MSG.measureDistance()); - btn.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent e) { - if (btn.isSelected()) { - cmd.enable(); - activateMeasurePolygon(false); - activateMeasureLine(true); - } - else { - cmd.disable(); - activateMeasureLine(false); - } - } - }); - - return btn; - } - - - protected ImgButton createMeasurePolyControl(final EnableDisableCmd cmd) { - measurePolygon = new Measure(new PolygonHandler()); - measurePolygon.setPersist(true); - measurePolygon.addMeasureListener(new MeasureListener() { - public void onMeasure(MeasureEvent e) { - updateMeasureArea(e.getMeasure(), e.getUnits()); - } - }); - measurePolygon.addMeasurePartialListener(new MeasurePartialListener() { - public void onMeasurePartial(MeasureEvent e) { - updateMeasureArea(e.getMeasure(), e.getUnits()); - } - }); - - floodMap.getMap().addControl(measurePolygon); - - final ImgButton btn = new ImgButton(); - String baseUrl = GWT.getHostPageBaseURL(); - btn.setSrc(baseUrl + MSG.measurePolygon()); - btn.setActionType(SelectionType.CHECKBOX); - btn.setSize(20); - btn.setShowRollOver(false); - btn.setShowRollOverIcon(false); - btn.setSelected(false); - btn.setTooltip(MSG.measureArea()); - btn.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent e) { - if (btn.isSelected()) { - cmd.enable(); - activateMeasureLine(false); - activateMeasurePolygon(true); - } - else { - cmd.disable(); - activateMeasurePolygon(false); - } - } - }); - - return btn; - } - - - protected void clearMeasure() { - label.setContents(""); - } - - - protected void updateMeasure(float value, String unit) { - label.setContents(formatter.format(value) + " " + unit); - } - - - protected void updateMeasureArea(float value, String unit) { - float ha = value; - String ha_unit = unit; - - if (unit.equals("m")) { - ha = (float) value / AREA_FACTOR_M; - ha_unit = AREA_UNIT; - } - else if (unit.equals("km")) { - ha = (float) value * AREA_FACTOR_KM; - ha_unit = AREA_UNIT; - } - - label.setContents(formatter.format(ha) + " " + ha_unit); - } - - - public void activate(boolean activate) { - if (!activate) { - clearMeasure(); - activateMeasureLine(activate); - activateMeasurePolygon(activate); - } - } - - - protected void activateMeasureLine(boolean activate) { - if (activate) { - clearMeasure(); - measureLineButton.select(); - measureLine.activate(); - } - else { - measureLineButton.deselect(); - measureLine.deactivate(); - } - } - - - protected void activateMeasurePolygon(boolean activate) { - if (activate) { - clearMeasure(); - measurePolyButton.select(); - measurePolygon.activate(); - } - else { - measurePolyButton.deselect(); - measurePolygon.deactivate(); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -package de.intevation.flys.client.client.ui.map; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.TreeModelType; -import com.smartgwt.client.widgets.tree.Tree; -import com.smartgwt.client.widgets.tree.TreeGrid; -import com.smartgwt.client.widgets.tree.TreeNode; - -import de.intevation.flys.client.shared.model.Capabilities; -import de.intevation.flys.client.shared.model.WMSLayer; - - -public class WMSLayersTree extends TreeGrid { - - /** - * An internal TreeNode that stores besides some string attribute a WMSLayer - * object. - */ - public static class WMSLayerNode extends TreeNode { - - protected WMSLayer wms; - - public WMSLayerNode(WMSLayer wms) { - super(); - this.wms = wms; - - setAttribute("name", wms.getName()); - setAttribute("title", wms.getTitle()); - } - - public WMSLayer getWMSLayer() { - return wms; - } - } // end of class WMSLayerNode - - - protected Capabilities capabilites; - protected String srs; - - - public WMSLayersTree(Capabilities capabilites) { - super(); - this.capabilites = capabilites; - - initTree(); - } - - - public WMSLayersTree(Capabilities capabilites, String srs) { - super(); - - this.capabilites = capabilites; - this.srs = srs; - - initTree(); - } - - - protected void initTree() { - setLoadDataOnDemand(false); - setWidth100(); - setHeight100(); - setShowRoot(false); - setShowConnectors(true); - setNodeIcon("[SKIN]/images/blank.gif"); - - Tree tree = new Tree(); - tree.setChildrenProperty("children-nodes"); - tree.setNameProperty("title"); - tree.setIdField("title"); - tree.setModelType(TreeModelType.CHILDREN); - tree.setShowRoot(false); - - TreeNode root = new TreeNode("Root"); - TreeNode[] layers = buildTree(capabilites.getLayers()); - - root.setAttribute("children-nodes", layers); - tree.setRoot(root); - - setData(tree); - - if (layers != null && layers.length == 1) { - tree.openFolder(layers[0]); - } - } - - - protected TreeNode[] buildTree(List<WMSLayer> layers) { - List<TreeNode> layerNodes = new ArrayList<TreeNode>(); - - for (WMSLayer layer: layers) { - WMSLayerNode tn = buildTreeNode(layer); - - if (tn != null) { - TreeNode[] tns = buildTree(layer.getLayers()); - - if (tns != null && tns.length > 0) { - tn.setAttribute("children-nodes", tns); - } - - layerNodes.add(tn); - } - } - - return layerNodes.toArray(new TreeNode[layerNodes.size()]); - } - - - protected WMSLayerNode buildTreeNode(WMSLayer wms) { - if (srs != null && srs.length() > 0) { - return wms.supportsSrs(srs) ? new WMSLayerNode(wms) : null; - } - else { - GWT.log("No target SRS specified."); - return new WMSLayerNode(wms); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedCampaignChart.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONString; -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.shared.model.Artifact; - -public class BedCampaignChart extends VLayout { - - private final Artifact artifact; - - protected Img chartImg; - - public BedCampaignChart(Artifact artifact, ResizedHandler resizeHandler) { - super(); - - this.artifact = artifact; - this.chartImg = new Img(); - - addResizedHandler(resizeHandler); - setAlign(Alignment.CENTER); - } - - public void update() { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - int hWidth = getWidth() - 12; - int hHeight = getHeight() - 12; - - if ((int) (hHeight * 4f / 3) < hWidth) { - hWidth = (int) (hHeight * 4f / 3); - } - else { - hHeight = (int) (hWidth * 3f / 4); - } - - String river = artifact.getArtifactDescription().getRiver(); - - JSONObject jfix = new JSONObject(); - JSONObject jfilter = new JSONObject(); - JSONObject jrName = new JSONObject(); - JSONString jrValue = new JSONString(river); - JSONObject jextent = new JSONObject(); - JSONNumber jwidth = new JSONNumber(hWidth); - JSONNumber jheight = new JSONNumber(hHeight); - - jrName.put("name", jrValue); - jfilter.put("river", jrName); - jextent.put("width", jwidth); - jextent.put("height", jheight); - jfilter.put("extent", jextent); - jfix.put("bed", jfilter); - String filter = jfix.toString(); - - String imgUrl = GWT.getModuleBaseURL(); - imgUrl += "bed-km-chart"; - imgUrl += "?locale=" + locale; - imgUrl += "&filter=" + filter; - - if (chartImg != null && hasMember(chartImg)) { - chartImg.setWidth(hWidth); - chartImg.setHeight(hHeight); - chartImg.setSrc(imgUrl); - } - else { - chartImg = new Img(imgUrl, hWidth, hHeight); - addMember(chartImg); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedHeightsDatacagePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import com.google.gwt.core.client.GWT; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.data.Record; - -import com.smartgwt.client.widgets.Canvas; - -import com.smartgwt.client.widgets.events.ClickEvent; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.FLYSConstants; - -import de.intevation.flys.client.client.event.StepForwardEvent; - -import de.intevation.flys.client.client.services.LoadArtifactService; -import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.client.services.RemoveArtifactService; -import de.intevation.flys.client.client.services.RemoveArtifactServiceAsync; - -import de.intevation.flys.client.client.ui.DatacagePairWidget; -import de.intevation.flys.client.client.ui.DatacageTwinPanel; -import de.intevation.flys.client.client.ui.RecommendationPairRecord; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; - -import de.intevation.flys.client.shared.model.Recommendation.Facet; -import de.intevation.flys.client.shared.model.Recommendation.Filter; - -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.User; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -// TODO Probably better to branch off AbstractUIProvider. -// TODO Merge with other datacage-widget impls. -/** - * Panel containing a Grid and a "next" button. The Grid is fed by a - * DatacagePairWidget which is put in the input-helper area. - */ -public class BedHeightsDatacagePanel -extends DatacageTwinPanel { - - protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** - * List to track previously selected but now removed pairs. (Needed to - * be able to identify artifacts that can be removed from the collection. - */ - protected List<RecommendationPairRecord> removedPairs = - new ArrayList<RecommendationPairRecord>(); - - /** Service handle to clone and add artifacts to collection. */ - LoadArtifactServiceAsync loadArtifactService = GWT.create( - de.intevation.flys.client.client.services.LoadArtifactService.class); - - /** Service to remove artifacts from collection. */ - RemoveArtifactServiceAsync removeArtifactService = GWT.create( - de.intevation.flys.client.client.services.RemoveArtifactService.class); - - - public BedHeightsDatacagePanel(User user) { - super(user); - } - - - /** - * Create a recommendation from a string representation of it. - * @TODO describe format of input string - * @param from string in format as shown above. - * @return recommendation from input string. - */ - public Recommendation createRecommendationFromString(String from) { - // TODO Construct "real" filter. - String[] parts = unbracket(from).split(";"); - Recommendation.Filter filter = new Recommendation.Filter(); - Recommendation.Facet facet = new Recommendation.Facet( - parts[1], - parts[2]); - - List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet> - (); - facets.add(facet); - filter.add("longitudinal_section", facets); - Recommendation r = new Recommendation("bedheight", parts[0], - this.artifact.getUuid(), filter); - r.setDisplayName(parts[3]); - return r; - } - - - /** - * Creates the graphical representation and interaction widgets for the data. - * @param dataList the data. - * @return graphical representation and interaction widgets for data. - */ - @Override - public Canvas create(DataList dataList) { - GWT.log("createData()"); - - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - String value = items[0].getStringValue(); - - String filter = "minfo-heights"; - if (value.equals("epoch")) { - filter = "minfo-heights-epoch"; - } - Canvas widget = createWidget(); - Canvas submit = getNextButton(); - - VLayout layout = new VLayout(); - HLayout helperLayout = new HLayout(); - helperLayout.addMember(new DatacagePairWidget(this.artifact, - user, filter, differencesList)); - - layout.addMember(widget); - layout.addMember(submit); - layout.setMembersMargin(10); - this.helperContainer.addMember(helperLayout); - - this.dataName = "diffids"; - - return layout; - } - - - /** - * Add record to list of removed records. - */ - public void trackRemoved(Record r) { - RecommendationPairRecord pr = (RecommendationPairRecord) r; - this.removedPairs.add(pr); - } - - - /** - * Validates data, does nothing if invalid, otherwise clones new selected - * waterlevels and add them to collection, forward the artifact. - */ - @Override - public void onClick(ClickEvent e) { - GWT.log("DatacageTwinPanel.onClick"); - - List<String> errors = validate(); - if (errors != null && !errors.isEmpty()) { - showErrors(errors); - return; - } - - Config config = Config.getInstance(); - String locale = config.getLocale(); - - ListGridRecord[] records = differencesList.getRecords(); - - List<Recommendation> ar = new ArrayList<Recommendation>(); - List<Recommendation> all = new ArrayList<Recommendation>(); - - for (ListGridRecord record : records) { - RecommendationPairRecord r = - (RecommendationPairRecord) record; - // Do not add "old" recommendations. - if (!r.isAlreadyLoaded()) { - // Check whether one of those is a dike or similar. - // TODO differentiate and merge: new clones, new, old. - Recommendation firstR = r.getFirst(); - if(firstR.getIDs() != null) { - GWT.log("First IDs: " + firstR.getIDs() + " factory: " - + firstR.getFactory()); - } - firstR.setFactory("bedheight"); - Recommendation secondR = r.getSecond(); - if(secondR.getIDs() != null) { - GWT.log("Second IDs: " + secondR.getIDs() + " factory: " - + secondR.getFactory()); - } - secondR.setFactory("bedheight"); - - ar.add(firstR); - ar.add(secondR); - } - else { - all.add(r.getFirst()); - all.add(r.getSecond()); - } - } - - final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]); - final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]); - - // Find out whether "old" artifacts have to be removed. - List<String> artifactIdsToRemove = new ArrayList<String>(); - for (RecommendationPairRecord rp: this.removedPairs) { - Recommendation first = rp.getFirst(); - Recommendation second = rp.getSecond(); - - for (Recommendation recommendation: toUse) { - if (first != null && first.getIDs().equals(recommendation.getIDs())) { - first = null; - } - if (second != null && second.getIDs().equals(recommendation.getIDs())) { - second = null; - } - - if (first == null && second == null) { - break; - } - } - if (first != null) { - artifactIdsToRemove.add(first.getIDs()); - } - if (second != null) { - artifactIdsToRemove.add(second.getIDs()); - } - } - - // Remove old artifacts, if any. Do this asychronously without much - // feedback. - for(final String uuid: artifactIdsToRemove) { - removeArtifactService.remove(this.collection, - uuid, - locale, - new AsyncCallback<Collection>() { - public void onFailure(Throwable caught) { - GWT.log("RemoveArtifact (" + uuid + ") failed."); - } - public void onSuccess(Collection collection) { - GWT.log("RemoveArtifact succeeded"); - } - }); - } - - // Clone new ones (and spawn statics), go forward. - loadArtifactService.loadMany( - this.collection, - toClone, - //"staticwkms" and "waterlevel" - null, - locale, - new AsyncCallback<Artifact[]>() { - public void onFailure(Throwable caught) { - GWT.log("Failure of cloning with factories!"); - } - public void onSuccess(Artifact[] artifacts) { - GWT.log("Successfully cloned " + toClone.length + - " with factories."); - - fireStepForwardEvent(new StepForwardEvent( - getData(toClone, artifacts, toUse))); - } - }); - } - - - /** - * Creates part of the String that encodes minuend or subtrahend. - * @param artifact Artifacts UUID. - * @param recommendation Recommendation to wrap in string. - */ - protected String createDataString( - String artifact, - Recommendation recommendation) - { - Filter filter = recommendation.getFilter(); - Facet f = null; - - if(filter != null) { - Map<String, List<Facet>> outs = filter.getOuts(); - Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); - - for (Map.Entry<String, List<Facet>> entry: entries) { - List<Facet> fs = entry.getValue(); - - f = fs.get(0); - if (f != null) { - break; - } - } - - return "[" + artifact + ";" - + f.getName() - + ";" - + f.getIndex() - + ";" - + recommendation.getDisplayName() + "]"; - } - else { - return "[" - + artifact - + ";bedheight;0;" - + recommendation.getDisplayName() + "]"; - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedMultiPeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.ui.MultiPeriodPanel; - -public class BedMultiPeriodPanel -extends MultiPeriodPanel -implements ResizedHandler { - protected BedCampaignChart chartContainer1; - protected BedloadCampaignChart chartContainer2; - - public BedMultiPeriodPanel() { - } - - @Override - protected Canvas createHelper() { - chartContainer1 = new BedCampaignChart(artifact, this); - chartContainer2 = new BedloadCampaignChart(artifact, this); - VLayout layout = new VLayout(); - layout.addMember(chartContainer1); - layout.addMember(chartContainer2); - return layout; - } - - @Override - public void onResized(ResizedEvent re) { - chartContainer1.update(); - chartContainer2.update(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedloadCampaignChart.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONString; -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.shared.model.Artifact; - -public class BedloadCampaignChart extends VLayout { - - private final Artifact artifact; - - protected Img chartImg; - - public BedloadCampaignChart(Artifact artifact, ResizedHandler resizeHandler) { - super(); - - this.artifact = artifact; - this.chartImg = new Img(); - - addResizedHandler(resizeHandler); - setAlign(Alignment.CENTER); - } - - public void update() { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - int hWidth = getWidth() - 12; - int hHeight = getHeight() - 12; - - if ((int) (hHeight * 4f / 3) < hWidth) { - hWidth = (int) (hHeight * 4f / 3); - } - else { - hHeight = (int) (hWidth * 3f / 4); - } - - String river = artifact.getArtifactDescription().getRiver(); - - JSONObject jfix = new JSONObject(); - JSONObject jfilter = new JSONObject(); - JSONObject jrName = new JSONObject(); - JSONString jrValue = new JSONString(river); - JSONObject jextent = new JSONObject(); - JSONNumber jwidth = new JSONNumber(hWidth); - JSONNumber jheight = new JSONNumber(hHeight); - - jrName.put("name", jrValue); - jfilter.put("river", jrName); - jextent.put("width", jwidth); - jextent.put("height", jheight); - jfilter.put("extent", jextent); - jfix.put("bedload", jfilter); - String filter = jfix.toString(); - - String imgUrl = GWT.getModuleBaseURL(); - imgUrl += "bedload-km-chart"; - imgUrl += "?locale=" + locale; - imgUrl += "&filter=" + filter; - - if (chartImg != null && hasMember(chartImg)) { - chartImg.setWidth(hWidth); - chartImg.setHeight(hHeight); - chartImg.setSrc(imgUrl); - } - else { - chartImg = new Img(imgUrl, hWidth, hHeight); - addMember(chartImg); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/CheckboxPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Set; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.CheckboxItem; -import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.ui.AbstractUIProvider; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - -public class CheckboxPanel extends AbstractUIProvider { - - private String dataName; - HashMap<String, Boolean> values; - - protected DynamicForm form; - - public CheckboxPanel() { - super(); - values = new HashMap<String, Boolean>(); - } - - @Override - public Canvas createOld(DataList dataList) { - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - HLayout layout = new HLayout(); - Label label = new Label(dataList.getLabel()); - Label value = new Label(items[0].getLabel()); - - layout.setHeight(35); - layout.setWidth(400); - label.setWidth(200); - - layout.addMember(label); - layout.addMember(value); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - @Override - public Canvas create(DataList dataList) { - Data data = dataList.get(0); - DataItem[] items = data.getItems(); - - this.dataName = data.getLabel(); - form = new DynamicForm(); - - VLayout layout = new VLayout(); - Label label = new Label(data.getDescription()); - LinkedList<CheckboxItem> cbItems = new LinkedList<CheckboxItem>(); - for (int i = 0; i < items.length; i++) { - CheckboxItem item = new CheckboxItem(items[i].getLabel()); - GWT.log(items[i].getStringValue() + "; " + items[i].getLabel()); - item.addChangedHandler(new ChangedHandler() { - @Override - public void onChanged(ChangedEvent event) { - values.put( - event.getItem().getName(), - (Boolean)event.getItem().getValue()); - } - }); - cbItems.add(item); - } - - form.setFields(cbItems.toArray(new CheckboxItem[cbItems.size()])); - layout.setMembersMargin(10); - layout.setHeight(35); - label.setHeight(35); - - layout.addMember(label); - layout.addMember(form); - layout.addMember(getNextButton()); - layout.setMembersMargin(10); - - return layout; - } - - @Override - protected Data[] getData() { - String value = ""; - Set<String> entries = values.keySet(); - boolean first = true; - for (String s: values.keySet()) { - if (!first) { - value += ";"; - } - if ((Boolean)values.get(s) == true) { - value += s; - } - first = false; - } - DataItem item = new DefaultDataItem("diameter", "diameter", value); - - return new Data[] {new DefaultData( - "diameter", - null, - null, - new DataItem[]{item})}; - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadDistancePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,276 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import java.util.List; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.ui.AbstractUIProvider; -import de.intevation.flys.client.client.ui.DoubleRangeOnlyPanel; -import de.intevation.flys.client.client.ui.DoubleRangePanel; -import de.intevation.flys.client.client.ui.LocationPicker; -import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; - - -public class SedLoadDistancePanel -extends AbstractUIProvider -implements BlurHandler, CellClickHandler -{ - public static final String FIELD_LOWER = "ld_from"; - public static final String FIELD_UPPER = "ld_to"; - - protected DoubleRangePanel distancePanel; - protected double min; - protected double max; - protected LocationPicker picker; - - @Override - public Canvas createOld(DataList dataList) { - String s = getOldSelectionString(dataList); - String l = dataList.getLabel(); - - Label label = new Label(l); - Label selected = new Label(s); - - HLayout layout = new HLayout(); - - layout.setWidth(400); - label.setWidth(200); - selected.setWidth(130); - - layout.addMember(label); - layout.addMember(selected); - layout.addMember(getBackButton(dataList.getState())); - - return layout; - } - - protected String getOldSelectionString(DataList dataList) { - List<Data> items = dataList.getAll(); - - Data dFrom = getData(items, FIELD_LOWER); - Data dTo = getData(items, FIELD_UPPER); - - DataItem[] from = dFrom.getItems(); - DataItem[] to = dTo.getItems(); - - StringBuilder sb = new StringBuilder(); - sb.append(from[0].getLabel()); - sb.append(" " + MSG.dpUnitFrom() + " - "); - sb.append(to[0].getLabel()); - sb.append(" " + MSG.dpUnitTo()); - - return sb.toString(); - } - - @Override - public Canvas create(DataList data) { - picker = new LocationPicker(this); - distancePanel = new DoubleRangeOnlyPanel( - MSG.dpUnitFrom() + " - ", MSG.dpUnitTo(), 0d, 0d, 250, this, "right"); - VLayout layout = new VLayout(); - layout.setMembersMargin(10); - - Label label = new Label(MSG.distance_state()); - - Canvas submit = getNextButton(); - - label.setHeight(25); - distancePanel.setHeight(50); - - layout.addMember(label); - layout.addMember(distancePanel); - layout.addMember(submit); - - initMinMaxValues(data); - initDefaultValues(data); - - - picker.setIsDistance(true); - picker.getLocationTable().setAutoFetchData(true); - picker.prepareFilter(); - - helperContainer.addMember(picker.getLocationTable()); - helperContainer.addMember(picker.getFilterLayout()); - helperContainer.addMember(picker.getResultCountForm()); - - setPickerDataSource(); - picker.createLocationTable(); - - return layout; - } - - protected void initMinMaxValues(DataList data) { - Data f = getData(data.getAll(), FIELD_LOWER); - Data t = getData(data.getAll(), FIELD_UPPER); - - DataItem[] fItems = f.getItems(); - DataItem[] tItems = t.getItems(); - - try { - min = Double.valueOf(fItems[0].getStringValue()); - max = Double.valueOf(tItems[0].getStringValue()); - } - catch (NumberFormatException nfe) { - min = -Double.MAX_VALUE; - max = Double.MAX_VALUE; - } - } - - protected void initDefaultValues(DataList data) { - initDefaultFrom(data); - initDefaultTo(data); - } - - protected void initDefaultFrom(DataList data) { - Data f = getData(data.getAll(), FIELD_LOWER); - - double from = getDefaultFrom(); - - try { - from = getDefaultValue(f); - } - catch (NumberFormatException nfe) { - // do nothing - } - - distancePanel.setFrom(from); - } - - - protected double getDefaultFrom() { - return min; - } - - - protected void initDefaultTo(DataList data) { - Data t = getData(data.getAll(), FIELD_UPPER); - - double to = getDefaultTo(); - - try { - to = getDefaultValue(t); - } - catch (NumberFormatException nfe) { - // do nothing - } - - distancePanel.setTo(to); - } - - - protected double getDefaultTo() { - return max; - } - - protected double getDefaultValue(Data data) - throws NumberFormatException - { - DataItem def = data.getDefault(); - String defValue = def != null ? def.getStringValue() : null; - - return Double.valueOf(defValue); - } - - /** Hook service to the listgrid with possible input values. */ - protected void setPickerDataSource() { - Config config = Config.getInstance(); - String url = config.getServerUrl(); - String river = ""; - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - // Try to find a "river" data item to set the source for the - // list grid. - String dataFilter = "locations"; - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - if (dl.getState().equals("state.minfo.river")) { - dataFilter = "measuringpoint"; - } - if (dl.getState().equals("state.winfo.river") || - dl.getState().equals("state.chart.river") || - dl.getState().equals("state.minfo.river")) { - for (int j = 0; j < dl.size(); j++) { - Data d = dl.get(j); - DataItem[] di = d.getItems(); - if (di != null && di.length == 1) { - river = d.getItems()[0].getStringValue(); - break; - } - } - } - } - } - - picker.getLocationTable().setDataSource(new DistanceInfoDataSource( - url, river, dataFilter)); - } - - @Override - protected Data[] getData() { - Data[] data = new Data[2]; - - data[0] = getDataFrom(); - data[1] = getDataTo(); - - return data; - } - - protected Data getDataFrom() { - String value = String.valueOf(distancePanel.getFrom()); - String field = FIELD_LOWER; - - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); - } - - protected Data getDataTo() { - String value = String.valueOf(distancePanel.getTo()); - String field = FIELD_UPPER; - - DataItem item = new DefaultDataItem(field, field, value); - return new DefaultData( - field, null, null, new DataItem[] { item }); - } - - @Override - public void onBlur(BlurEvent event) { - distancePanel.validateForm(); - } - - @Override - public void onCellClick(CellClickEvent e) { - Record record = e.getRecord(); - int ndx = e.getColNum(); - String from = record.getAttribute("from"); - try { - double value = Double.valueOf(from); - switch (ndx) { - case 0: distancePanel.setFrom(value); break; - case 1: distancePanel.setTo(value); break; - } - } - catch(NumberFormatException nfe) { - SC.warn(MSG.wrongFormat()); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadEpochPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,277 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.services.SedimentLoadInfoService; -import de.intevation.flys.client.client.services.SedimentLoadInfoServiceAsync; -import de.intevation.flys.client.client.ui.AbstractUIProvider; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; -import de.intevation.flys.client.shared.model.SedimentLoadInfoRecord; - - -public class SedLoadEpochPanel -extends AbstractUIProvider -{ - protected SedimentLoadInfoServiceAsync sedLoadInfoService = - GWT.create(SedimentLoadInfoService.class); - - protected ListGrid elements; - private TextItem start; - private TextItem end; - private ListGrid sedLoadTable; - - public Canvas createWidget(DataList data) { - HLayout input = new HLayout(); - VLayout root = new VLayout(); - VLayout grid = new VLayout(); - VLayout intFields = new VLayout(); - Button add = new Button(MSG.add_date()); - elements = new ListGrid(); - - Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - DynamicForm form = new DynamicForm(); - form.setNumCols(4); - start = new TextItem(MSG.from()); - start.setWidth(60); - start.setValidators(new IsIntegerValidator()); - end = new TextItem(MSG.to()); - end.setWidth(60); - end.setValidators(new IsIntegerValidator()); - form.setFields(start, end); - add.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent ce) { - String v1 = start.getValueAsString(); - String v2 = end.getValueAsString(); - //TODO: better validation. - if (v1 == null || v2 == null) { - return; - } - try { - int v1i = Integer.parseInt(v1); - int v2i = Integer.parseInt(v2); - } - catch(NumberFormatException nfe) { - return; - } - Record r = new Record(); - r.setAttribute("from", v1); - r.setAttribute("to", v2); - elements.addData(r); - } - }); - - Label sel = new Label(MSG.select()); - sel.setHeight(25); - elements.setWidth(185); - elements.setHeight(120); - elements.setShowHeaderContextMenu(false); - elements.setCanReorderFields(false); - elements.setCanSort(false); - elements.setCanEdit(false); - ListGridField from = new ListGridField("from", MSG.from()); - ListGridField to = new ListGridField("to", MSG.to()); - from.setWidth(70); - to.setWidth(70); - - final ListGridField removeField = - new ListGridField("_removeRecord", "Remove Record"){{ - setType(ListGridFieldType.ICON); - setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); - setCanEdit(false); - setCanFilter(false); - setCanSort(false); - setCanGroupBy(false); - setCanFreeze(false); - setWidth(25); - }}; - - elements.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(final RecordClickEvent event) { - // Just handle remove-clicks - if(!event.getField().getName().equals(removeField.getName())) { - return; - } - event.getViewer().removeData(event.getRecord()); - } - }); - - elements.setFields(from, to, removeField); - - intFields.addMember(form); - intFields.addMember(add); - grid.addMember(sel); - grid.addMember(elements); - input.addMember(intFields); - input.addMember(grid); - root.addMember(title); - root.addMember(input); - - return root; - } - - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - layout.setWidth("400px"); - VLayout vLayout = new VLayout(); - vLayout.setWidth(130); - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - label.setHeight(25); - - List<Data> items = dataList.getAll(); - Data str = getData(items, "epochs"); - DataItem[] strItems = str.getItems(); - - String[] pairs = strItems[0].getLabel().split(";"); - for (int i = 0; i < pairs.length; i++) { - String[] vals = pairs[i].split(","); - Label dateLabel = new Label(vals[0] + " - " + vals[1]); - dateLabel.setHeight(20); - vLayout.addMember(dateLabel); - } - Canvas back = getBackButton(dataList.getState()); - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); - Canvas helper = createHelper(); - this.helperContainer.addMember(helper); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(data); - - layout.addMember(widget); - layout.addMember(submit); - - fetchSedimentLoadData(); - - return layout; - } - - private Canvas createHelper() { - sedLoadTable = new ListGrid(); - sedLoadTable.setShowHeaderContextMenu(false); - sedLoadTable.setWidth100(); - sedLoadTable.setShowRecordComponents(true); - sedLoadTable.setShowRecordComponentsByCell(true); - sedLoadTable.setHeight100(); - sedLoadTable.setEmptyMessage(MSG.empty_table()); - sedLoadTable.setCanReorderFields(false); - - ListGridField date = new ListGridField("date", MSG.year()); - date.setType(ListGridFieldType.TEXT); - date.setWidth(100); - - ListGridField descr = - new ListGridField("description", MSG.description()); - descr.setType(ListGridFieldType.TEXT); - descr.setWidth("*"); - - sedLoadTable.setFields(date, descr); - return sedLoadTable; - } - - @Override - protected Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - ListGridRecord[] lgr = elements.getRecords(); - if (lgr.length == 0) { - return new Data[0]; - } - String d = ""; - for (int i = 0; i < lgr.length; i++) { - Record r = (Record) lgr[i]; - d += r.getAttribute("from") + "," + r.getAttribute("to"); - d += ";"; - } - - DataItem item = new DefaultDataItem("epochs", null, d); - data.add(new DefaultData( - "epochs", - null, - null, - new DataItem[] { item })); - return data.toArray(new Data[data.size()]); - } - - protected void fetchSedimentLoadData() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - double[] km = artifact.getArtifactDescription().getKMRange(); - String river = artifact.getArtifactDescription().getRiver(); - - sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], - new AsyncCallback<SedimentLoadInfoObject[]>() { - public void onFailure(Throwable caught) { - GWT.log("Could not recieve sediment load informations."); - SC.warn(caught.getMessage()); - } - - public void onSuccess(SedimentLoadInfoObject[] sedLoad) { - int num = sedLoad != null ? sedLoad.length :0; - GWT.log("Recieved " + num + " sediment load informations."); - - if (num == 0) { - return; - } - - addSedimentLoadInfo(sedLoad); - } - } - ); - } - - - protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { - for(SedimentLoadInfoObject sl: sedLoad) { - SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); - sedLoadTable.addData(rec); - } - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadOffEpochPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,187 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.SelectionAppearance; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.services.SedimentLoadInfoService; -import de.intevation.flys.client.client.services.SedimentLoadInfoServiceAsync; -import de.intevation.flys.client.client.ui.PeriodPanel; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; -import de.intevation.flys.client.shared.model.SedimentLoadInfoRecord; - - -public class SedLoadOffEpochPanel -extends PeriodPanel -{ - protected SedimentLoadInfoServiceAsync sedLoadInfoService = - GWT.create(SedimentLoadInfoService.class); - - private ListGrid sedLoadTable; - - public Canvas createWidget(DataList data) { - VLayout root = new VLayout(); - - Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - root.addMember(title); - - return root; - } - - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - layout.setWidth("400px"); - VLayout vLayout = new VLayout(); - vLayout.setWidth(130); - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - label.setHeight(25); - - List<Data> items = dataList.getAll(); - Data str = getData(items, "epochs"); - DataItem[] strItems = str.getItems(); - - String[] pairs = strItems[0].getLabel().split(";"); - for (int i = 0; i < pairs.length; i++) { - String[] vals = pairs[i].split(","); - Label dateLabel = new Label(vals[0] + " - " + vals[1]); - dateLabel.setHeight(20); - vLayout.addMember(dateLabel); - } - Canvas back = getBackButton(dataList.getState()); - layout.addMember(label); - layout.addMember(vLayout); - layout.addMember(back); - - return layout; - } - - @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); - Canvas helper = createHelper(); - this.helperContainer.addMember(helper); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(data); - - layout.addMember(widget); - layout.addMember(submit); - - fetchSedimentLoadData(); - - return layout; - } - - protected Canvas createHelper() { - sedLoadTable = new ListGrid(); - sedLoadTable.setShowHeaderContextMenu(false); - sedLoadTable.setWidth100(); - sedLoadTable.setShowRecordComponents(true); - sedLoadTable.setShowRecordComponentsByCell(true); - sedLoadTable.setHeight100(); - sedLoadTable.setEmptyMessage(MSG.empty_table()); - sedLoadTable.setCanReorderFields(false); - sedLoadTable.setSelectionAppearance(SelectionAppearance.CHECKBOX); - - ListGridField date = new ListGridField("date", MSG.year()); - date.setType(ListGridFieldType.TEXT); - date.setWidth(100); - - ListGridField descr = - new ListGridField("description", MSG.description()); - descr.setType(ListGridFieldType.TEXT); - descr.setWidth("*"); - - sedLoadTable.setFields(date, descr); - return sedLoadTable; - } - - @Override - public Data[] getData() { - List<Data> data = new ArrayList<Data>(); - - ListGridRecord[] lgr = sedLoadTable.getSelectedRecords(); - if (lgr.length == 0) { - return new Data[0]; - } - String d = ""; - for (int i = 0; i < lgr.length; i++) { - Record r = (Record) lgr[i]; - String date = r.getAttribute("date"); - String[] range = date.split(" - "); - d += range[0] + "," + range[1]; - d += ";"; - } - DataItem item = new DefaultDataItem("epochs", null, d); - data.add(new DefaultData( - "epochs", - null, - null, - new DataItem[] { item })); - return data.toArray(new Data[data.size()]); - } - - protected void fetchSedimentLoadData() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - double[] km = artifact.getArtifactDescription().getKMRange(); - String river = artifact.getArtifactDescription().getRiver(); - - sedLoadInfoService.getSedimentLoadInfo(locale, river, "epoch", km[0], km[1], - new AsyncCallback<SedimentLoadInfoObject[]>() { - public void onFailure(Throwable caught) { - GWT.log("Could not recieve sediment load informations."); - SC.warn(caught.getMessage()); - } - - public void onSuccess(SedimentLoadInfoObject[] sedLoad) { - int num = sedLoad != null ? sedLoad.length :0; - GWT.log("Recieved " + num + " sediment load informations."); - - if (num == 0) { - return; - } - - addSedimentLoadInfo(sedLoad); - } - } - ); - } - - - protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { - for(SedimentLoadInfoObject sl: sedLoad) { - SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); - sedLoadTable.addData(rec); - } - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadPeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,230 +0,0 @@ -package de.intevation.flys.client.client.ui.minfo; - -import java.util.ArrayList; -import java.util.List; - -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.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.client.services.SedimentLoadInfoService; -import de.intevation.flys.client.client.services.SedimentLoadInfoServiceAsync; -import de.intevation.flys.client.client.ui.AbstractUIProvider; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; -import de.intevation.flys.client.shared.model.SedimentLoadInfoRecord; - - -public class SedLoadPeriodPanel -extends AbstractUIProvider -{ - protected SedimentLoadInfoServiceAsync sedLoadInfoService = - GWT.create(SedimentLoadInfoService.class); - - private TextItem start; - private TextItem end; - - private ListGrid sedLoadTable; - - public SedLoadPeriodPanel () { - } - - @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - Data start = getData(items, "start"); - Data end = getData(items, "end"); - DataItem[] startItem = start.getItems(); - DataItem[] endItem = end.getItems(); - - String v1 = startItem[0].getStringValue(); - String v2 = endItem[0].getStringValue(); - - int v1i = 0; - int v2i = 0; - try { - v1i = Integer.parseInt(v1); - v2i = Integer.parseInt(v2); - } - catch (NumberFormatException nfe) { - GWT.log(nfe.toString()); - } - Label old = new Label(v1i + " - " + v2i); - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - - return layout; - } - - @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); - - Canvas helper = createHelper(); - this.helperContainer.addMember(helper); - - Canvas submit = getNextButton(); - Canvas widget = createWidget(data); - - layout.addMember(widget); - layout.addMember(submit); - - fetchSedimentLoadData(); - - return layout; - } - - private Canvas createHelper() { - sedLoadTable = new ListGrid(); - sedLoadTable.setShowHeaderContextMenu(false); - sedLoadTable.setWidth100(); - sedLoadTable.setShowRecordComponents(true); - sedLoadTable.setShowRecordComponentsByCell(true); - sedLoadTable.setHeight100(); - sedLoadTable.setEmptyMessage(MSG.empty_table()); - sedLoadTable.setCanReorderFields(false); - - ListGridField date = new ListGridField("date", MSG.year()); - date.setType(ListGridFieldType.TEXT); - date.setWidth(100); - - ListGridField descr = - new ListGridField("description", MSG.description()); - descr.setType(ListGridFieldType.TEXT); - descr.setWidth("*"); - - sedLoadTable.setFields(date, descr); - return sedLoadTable; - } - - public Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); - - Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - DynamicForm form = new DynamicForm(); - form.setNumCols(4); - start = new TextItem(MSG.from()); - start.setValidators(new IsIntegerValidator()); - end = new TextItem(MSG.to()); - end.setValidators(new IsIntegerValidator()); - form.setFields(start, end); -// inputPanel.setToTitle(MSG.to()); -// inputPanel.setFromTitle(MSG.from()); -// inputPanel.setShowTitle(false); - - layout.addMember(title); - layout.addMember(form); - - return layout; - } - - @Override - protected Data[] getData() { - int v1; - int v2; - try { - v1 = Integer.parseInt(start.getValueAsString()); - v2 = Integer.parseInt(end.getValueAsString()); - } - catch(NumberFormatException nfe) { - // warn the user... - return new Data[0]; - } - if (validateRange(v1, v2)) { - List<Data> data = new ArrayList<Data>(); - - DataItem startItem = new DefaultDataItem("start", "start", start.getValueAsString()); - DataItem endItem = new DefaultDataItem("end", "end", end.getValueAsString()); - data.add(new DefaultData( - "start", - null, - null, - new DataItem[] { startItem })); - data.add(new DefaultData( - "end", - null, - null, - new DataItem[] { endItem })); - - return data.toArray(new Data[data.size()]); - } - return new Data[0]; - } - - protected boolean validateRange(int v1, int v2) { - // TODO: Set useful years for validation. Current range is between start - // of gregorian calendar and a year in the future... - if ((v1 > 1582 && v1 < 2100) - && (v2 > 1582 && v2 < 2100)) { - return true; - } - return false; - } - - protected void fetchSedimentLoadData() { - Config config = Config.getInstance(); - String locale = config.getLocale (); - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); - - double[] km = artifact.getArtifactDescription().getKMRange(); - String river = artifact.getArtifactDescription().getRiver(); - - sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], - new AsyncCallback<SedimentLoadInfoObject[]>() { - public void onFailure(Throwable caught) { - GWT.log("Could not recieve sediment load informations."); - SC.warn(caught.getMessage()); - } - - public void onSuccess(SedimentLoadInfoObject[] sedLoad) { - int num = sedLoad != null ? sedLoad.length :0; - GWT.log("Recieved " + num + " sediment load informations."); - - if (num == 0) { - return; - } - - addSedimentLoadInfo(sedLoad); - } - } - ); - } - - - protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { - for(SedimentLoadInfoObject sl: sedLoad) { - SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); - sedLoadTable.addData(rec); - } - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/DischargeInfoDataSource.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -package de.intevation.flys.client.client.ui.range; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.data.DataSource; -import com.smartgwt.client.data.DataSourceField; -import com.smartgwt.client.types.DSDataFormat; -import com.smartgwt.client.types.FieldType; - -public class DischargeInfoDataSource extends DataSource { - - public static final String XPATH_DISCHARGE_DEFAULT = "/discharges/discharge"; - - - public DischargeInfoDataSource(String url, long gauge) { - setDataFormat(DSDataFormat.XML); - setRecordXPath(XPATH_DISCHARGE_DEFAULT); - - DataSourceField desc = new DataSourceField( - "description", FieldType.TEXT, "description"); - - DataSourceField start = new DataSourceField( - "start", FieldType.TEXT, "start"); - - DataSourceField end = new DataSourceField( - "end", FieldType.TEXT, "end"); - - setFields(desc, start, end); - setDataURL(getServiceURL(url, gauge)); - } - - - protected String getServiceURL(String server, long gauge) { - String url = GWT.getModuleBaseURL(); - url += "dischargeinfoxml"; - url += "?server=" + server; - url += "&gauge=" + String.valueOf(gauge); - - return url; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/DistanceInfoDataSource.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -package de.intevation.flys.client.client.ui.range; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.data.DataSource; -import com.smartgwt.client.data.DataSourceField; -import com.smartgwt.client.types.DSDataFormat; -import com.smartgwt.client.types.FieldType; - - -public class DistanceInfoDataSource extends DataSource { - - public static final String XPATH_DISTANCE_DEFAULT = "/distances/distance"; - - - public DistanceInfoDataSource(String url, String river, String filter) { - setDataFormat(DSDataFormat.XML); - setRecordXPath(XPATH_DISTANCE_DEFAULT); - - DataSourceField desc = new DataSourceField( - "description", FieldType.TEXT, "description"); - - DataSourceField from = new DataSourceField( - "from", FieldType.TEXT, "from"); - - DataSourceField to = new DataSourceField( - "to", FieldType.TEXT, "to"); - - DataSourceField side = new DataSourceField( - "riverside", FieldType.TEXT, "riverside"); - - DataSourceField top = new DataSourceField( - "top", FieldType.TEXT, "top"); - - DataSourceField bottom = new DataSourceField( - "bottom", FieldType.TEXT, "bottom"); - - setFields(desc, from, to, side, top, bottom); - setDataURL(getServiceURL(url, river, filter)); - } - - - protected String getServiceURL(String server, String river, String filter) { - String url = GWT.getModuleBaseURL(); - url += "distanceinfoxml"; - url += "?server=" + server; - url += "&river=" + river; - url += "&filter=" + filter; - - return url; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/LocationsTable.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -package de.intevation.flys.client.client.ui.range; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import com.smartgwt.client.widgets.grid.CellFormatter; - -import de.intevation.flys.client.client.FLYSConstants; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class LocationsTable extends ListGrid { - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - - public LocationsTable() { - String baseUrl = GWT.getHostPageBaseURL(); - - setWidth100(); - setHeight100(); - setSelectionType(SelectionStyle.SINGLE); - setSelectionType(SelectionStyle.SINGLE); - setShowHeaderContextMenu(false); - setShowRecordComponents(true); - setShowRecordComponentsByCell(true); - setEmptyMessage(MSG.empty_filter()); - setCanReorderFields(false); - - ListGridField addfrom = new ListGridField ("from", MSG.from()); - addfrom.setType(ListGridFieldType.ICON); - addfrom.setWidth(30); - addfrom.setCellIcon(baseUrl + MSG.markerGreen()); - - ListGridField addto = new ListGridField("to", MSG.to()); - addto.setType(ListGridFieldType.ICON); - addto.setWidth(30); - addto.setCellIcon(baseUrl + MSG.markerRed()); - - ListGridField ldescr = new ListGridField( - "description", MSG.description()); - ldescr.setType(ListGridFieldType.TEXT); - ldescr.setWidth("*"); - - ListGridField lside = new ListGridField("riverside", MSG.riverside()); - lside.setType(ListGridFieldType.TEXT); - lside.setWidth("12%"); - - ListGridField loc = new ListGridField("from", MSG.locations()); - loc.setType(ListGridFieldType.FLOAT); - loc.setCellFormatter(new CellFormatter() { - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum) { - if (value == null) return null; - try { - NumberFormat nf; - double v = Double.parseDouble((String)value); - nf = NumberFormat.getFormat("###0.00##"); - return nf.format(v); - } - catch (Exception e) { - return value.toString(); - } - } - } - ); - - loc.setWidth("12%"); - - ListGridField bottom = new ListGridField("bottom", MSG.bottom_edge()); - bottom.setType(ListGridFieldType.TEXT); - bottom.setWidth("10%"); - - ListGridField top = new ListGridField("top", MSG.top_edge()); - top.setType(ListGridFieldType.TEXT); - top.setWidth("10%"); - - setFields(addfrom, addto, ldescr, loc, lside, bottom, top); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/RangeTable.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -package de.intevation.flys.client.client.ui.range; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.CellFormatter; - -import de.intevation.flys.client.client.FLYSConstants; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class RangeTable extends ListGrid { - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - - public RangeTable() { - String baseUrl = GWT.getHostPageBaseURL(); - - setWidth100(); - setHeight100(); - setSelectionType(SelectionStyle.SINGLE); - setSelectionType(SelectionStyle.SINGLE); - setShowHeaderContextMenu(false); - setShowRecordComponents(true); - setShowRecordComponentsByCell(true); - setEmptyMessage(MESSAGES.empty_filter()); - setCanReorderFields(false); - - ListGridField addDistance = new ListGridField ("", ""); - addDistance.setType (ListGridFieldType.ICON); - addDistance.setWidth (20); - addDistance.setCellIcon(baseUrl + MESSAGES.markerGreen()); - - ListGridField ddescr = new ListGridField( - "description", MESSAGES.description()); - ddescr.setType(ListGridFieldType.TEXT); - ddescr.setWidth("*"); - ListGridField from = new ListGridField("from", MESSAGES.from()); - from.setType(ListGridFieldType.FLOAT); - from.setCellFormatter(new CellFormatter() { - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum) { - if (value == null) return null; - try { - NumberFormat nf; - double v = Double.parseDouble((String)value); - nf = NumberFormat.getFormat("###0.00##"); - return nf.format(v); - } - catch (Exception e) { - return value.toString(); - } - } - } - ); - - from.setWidth("12%"); - - ListGridField to = new ListGridField("to", MESSAGES.to()); - to.setType(ListGridFieldType.FLOAT); - to.setCellFormatter(new CellFormatter() { - public String format( - Object value, - ListGridRecord record, - int rowNum, int colNum) { - if (value == null) return null; - GWT.log((String)value); - try { - NumberFormat nf; - double v = Double.parseDouble((String)value); - nf = NumberFormat.getFormat("###0.00##"); - return nf.format(v); - } - catch (Exception e) { - return value.toString(); - } - } - } - ); - - to.setWidth("12%"); - - ListGridField dside = new ListGridField( - "riverside", MESSAGES.riverside()); - dside.setType(ListGridFieldType.TEXT); - dside.setWidth("12%"); - - ListGridField bottom = new ListGridField( - "bottom", MESSAGES.bottom_edge()); - bottom.setType(ListGridFieldType.TEXT); - bottom.setWidth("10%"); - - ListGridField top = new ListGridField("top", MESSAGES.top_edge()); - top.setType(ListGridFieldType.TEXT); - top.setWidth("10%"); - - setFields(addDistance, ddescr, from, to, dside, bottom, top); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQCampaignChart.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -package de.intevation.flys.client.client.ui.sq; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONString; -import com.smartgwt.client.types.Alignment; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.events.ResizedHandler; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.Config; -import de.intevation.flys.client.shared.model.Artifact; - - -public class SQCampaignChart extends VLayout { - - private final Artifact artifact; - - protected Img chartImg; - - public SQCampaignChart(Artifact artifact, ResizedHandler resizeHandler) { - super(); - - this.artifact = artifact; - this.chartImg = new Img(); - - addResizedHandler(resizeHandler); - setAlign(Alignment.CENTER); - } - - public void update() { - Config config = Config.getInstance(); - String locale = config.getLocale(); - - int hWidth = getWidth() - 12; - int hHeight = getHeight() - 12; - - if ((int) (hHeight * 4f / 3) < hWidth) { - hWidth = (int) (hHeight * 4f / 3); - } - else { - hHeight = (int) (hWidth * 3f / 4); - } - - String river = artifact.getArtifactDescription().getRiver(); - - JSONObject jfix = new JSONObject(); - JSONObject jfilter = new JSONObject(); - JSONObject jrName = new JSONObject(); - JSONString jrValue = new JSONString(river); - JSONObject jextent = new JSONObject(); - JSONNumber jwidth = new JSONNumber(hWidth); - JSONNumber jheight = new JSONNumber(hHeight); - - jrName.put("name", jrValue); - jfilter.put("river", jrName); - jextent.put("width", jwidth); - jextent.put("height", jheight); - jfilter.put("extent", jextent); - jfix.put("sq", jfilter); - String filter = jfix.toString(); - - String imgUrl = GWT.getModuleBaseURL(); - imgUrl += "sq-km-chart"; - imgUrl += "?locale=" + locale; - imgUrl += "&filter=" + filter; - - if (chartImg != null && hasMember(chartImg)) { - chartImg.setWidth(hWidth); - chartImg.setHeight(hHeight); - chartImg.setSrc(imgUrl); - } - else { - chartImg = new Img(imgUrl, hWidth, hHeight); - addMember(chartImg); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package de.intevation.flys.client.client.ui.sq; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; - -import de.intevation.flys.client.client.ui.MultiPeriodPanel; - - -/** - * This UIProvider creates helper panel for sq relation. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class SQMultiPeriodPanel extends MultiPeriodPanel implements - ResizedHandler { - protected SQCampaignChart chartContainer; - - public SQMultiPeriodPanel() { - } - - @Override - protected Canvas createHelper() { - chartContainer = new SQCampaignChart(artifact, this); - return chartContainer; - } - - @Override - public void onResized(ResizedEvent re) { - chartContainer.update(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQPeriodPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package de.intevation.flys.client.client.ui.sq; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; - -import de.intevation.flys.client.client.ui.PeriodPanel; - -public class SQPeriodPanel extends PeriodPanel implements ResizedHandler { - - private SQCampaignChart chartLayout; - - @Override - protected Canvas createHelper() { - GWT.log("Create new SQCampaignChart as Helper Widget"); - chartLayout = new SQCampaignChart(artifact, this); - return chartLayout; - } - - - @Override - public void onResized(ResizedEvent re) { - chartLayout.update(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/GaugeInfoPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.user.client.ui.Anchor; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.Label; - -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.GaugeInfo; - -public class GaugeInfoPanel extends VLayout { - - /** The message class that provides i18n strings.*/ - private FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** Application instance. */ - private FLYS flys; - - public GaugeInfoPanel(GaugeInfo gauge, FLYS flys) { - this.flys = flys; - setStyleName("gaugeinfopanel"); - - NumberFormat nf = NumberFormat.getDecimalFormat(); - - VLayout grid = new VLayout(); - HLayout line1 = new HLayout(); - - Double minw = gauge.getMinW(); - Double maxw = gauge.getMaxW(); - if (minw != null && maxw != null) { - Label key = new Label(MSG.wq_value_q()); - Label value = new Label(nf.format(minw) + - " - " + nf.format(maxw)); - key.setWidth(150); - line1.addMember(key); - line1.addMember(value); - } - - HLayout line2 = new HLayout(); - Double minq = gauge.getMinQ(); - Double maxq = gauge.getMaxQ(); - if (minq != null && maxq != null) { - Label key = new Label(MSG.wq_value_w()); - Label value = new Label( nf.format(minq) + - " - " + nf.format(maxq)); - key.setWidth(150); - line2.addMember(key); - line2.addMember(value); - } - - HLayout line3 = new HLayout(); - Double aeo = gauge.getAeo(); - if (aeo != null) { - Label key = new Label("AEO [km²]"); - Label value = new Label(nf.format(aeo)); - key.setWidth(150); - line3.addMember(key); - line3.addMember(value); - } - - HLayout line4 = new HLayout(); - Double datum = gauge.getDatum(); - if (datum != null) { - Label key = new Label(MSG.gauge_zero() + " [" + - gauge.getWstUnit() + "]"); - Label value = new Label(nf.format(datum)); - key.setWidth(150); - line4.addMember(key); - line4.addMember(value); - } - - HLayout line5 = new HLayout(); - line5.addMember(new GaugeMainValueAnchor(flys, gauge)); - - grid.addMember(line1); - grid.addMember(line2); - grid.addMember(line3); - grid.addMember(line4); - grid.addMember(line5); - addMember(grid); - } - - - /** - * Clickable anchor that asks application to show window with - * main values for gauge. - */ - class GaugeMainValueAnchor extends Anchor implements ClickHandler { - - private FLYS flys; - private GaugeInfo gauge; - - public GaugeMainValueAnchor(FLYS flys, GaugeInfo gauge) { - super(MSG.show_mainvalues()); - this.flys = flys; - this.gauge = gauge; - this.setHeight("5"); - - addClickHandler(this); - } - - @Override - public void onClick(ClickEvent ev) { - GWT.log("GaugeMainValueAnchor - onClick " + gauge.getRiverName() + - " " + gauge.getOfficialNumber()); - flys.newGaugeMainValueTable(gauge); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/GaugeListGrid.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,320 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.WidgetCanvas; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; - -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.GaugeInfo; -import de.intevation.flys.client.shared.model.RiverInfo; - - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class GaugeListGrid extends InfoListGrid implements RecordClickHandler { - - private static final int ABFLUSSTAFEL_COLUMN = 6; - - public GaugeListGrid(FLYS flys) { - super(flys); - //TODO i18n!!! - ListGridField nfield = new ListGridField("name", "Pegel"); - ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60); - ListGridField efield = new ListGridField("kmend", "Ende [km]", 60); - ListGridField stfield = new ListGridField("station", "Station [km]"); - ListGridField lfield = new ListGridField("link", "Info"); - lfield.setType(ListGridFieldType.LINK); - ListGridField cfield = new ListGridField("curvelink", MSG.gauge_curve_link()); - cfield.addRecordClickHandler(this); - - this.setFields(nfield, sfield, efield, stfield, lfield, cfield); - } - - public void setRiverInfo(RiverInfo riverinfo) { - List<GaugeInfo> gauges = riverinfo.getGauges(); - - if (gauges != null && !gauges.isEmpty()) { - - ArrayList<GaugeInfo> emptygauges = new ArrayList<GaugeInfo>(); - - if (!riverinfo.isKmUp()) { - for (GaugeInfo gauge : gauges) { - addGauge(gauge, emptygauges); - } - } - else { - for (int i = gauges.size()-1; i >= 0; i--) { - GaugeInfo gauge = gauges.get(i); - addGauge(gauge, emptygauges); - } - } - - // put empty gauges to the end - for (GaugeInfo gauge : emptygauges) { - addGauge(gauge); - } - } - } - - private void addGauge(GaugeInfo gauge, List<GaugeInfo> empty) { - if (gauge.getKmStart() != null && gauge.getKmEnd() != null) { - addGauge(gauge); - } - else { - empty.add(gauge); - } - } - - private void addGauge(GaugeInfo gauge) { - this.addData(new GaugeRecord(gauge)); - } - - public void open() { - ArrayList<Double> locations = new ArrayList<Double>(); - - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - String state = dl.getState(); - GWT.log("GaugeListGrid - open " + state); - if (state.equals("state.winfo.location_distance")) { - Double ldfrom = null; - Double ldto = null; - - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue()); - if (label.equals("ld_from")) { - ldfrom = getDoubleValue(d); - } - else if (label.equals("ld_to")) { - ldto = getDoubleValue(d); - } - else if (label.equals("ld_locations")) { - getLocationsFromData(locations, d); - openOnLocations(locations); - return; - } - } - if (ldfrom != null) { - openOnDistance(ldfrom, ldto); - return; - } - } - else if(state.equals("state.winfo.distance_only") || - state.equals("state.winfo.distance")) { - Double ldfrom = null; - Double ldto = null; - - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue()); - if (label.equals("ld_from")) { - ldfrom = getDoubleValue(d); - } - else if (label.equals("ld_to")) { - ldto = getDoubleValue(d); - } - } - - if (ldfrom != null) { - openOnDistance(ldfrom, ldto); - return; - } - } - else if (state.equals("state.winfo.location")) { - getLocations("ld_locations", locations, dl); - openOnLocations(locations); - return; - } - else if (state.equals("state.winfo.reference.curve.input.start")) { - getLocations("reference_startpoint", locations, dl); - } - else if (state.equals("state.winfo.reference.curve.input.end")) { - getLocations("reference_endpoint", locations, dl); - } - else if (state.equals("state.winfo.historicalq.reference_gauge")) { - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - if (label.equals("reference_gauge")) { - String tmp = d.getStringValue(); - if (tmp != null) { - Long gaugereference = Long.valueOf(tmp); - if (gaugereference != null) { - openOnReference(gaugereference); - return; - } - } - } - } - } - } - } - if (!locations.isEmpty()) { - openOnLocations(locations); - } - else { - openAll(); - } - } - - void getLocations(String labelname, List<Double> locations, DataList dl) { - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - if (label.equals(labelname)) { - getLocationsFromData(locations, d); - } - } - } - - void getLocationsFromData(List<Double> locations, Data data) { - DataItem[] items = data.getItems(); - for (int k = 0; k < items.length; k++) { - String tmp = items[k].getStringValue(); - GWT.log("GaugeListGrid - getLocationsFromData " + tmp); - if (tmp != null) { - if (tmp.contains(" ")) { - // string contains several values ... - String[] values = tmp.split(" "); - for(int i=0; i < values.length; i++) { - Double value = Double.valueOf(values[i]); - if (value != null) { - locations.add(value); - } - } - } - else { - Double value = Double.valueOf(tmp); - if (value != null) { - locations.add(value); - } - } - } - } - } - - public void openOnReference(Long number) { - GWT.log("GaugeListGrid - openOnReference " + number); - for (ListGridRecord record: this.getRecords()) { - GaugeRecord item = (GaugeRecord)record; - if (item.getOfficialNumber().equals(number)) { - expandRecord(item); - } - else { - collapseRecord(item); - } - } - } - - public void openOnDistance(Double start, Double end) { - GWT.log("GaugeListGrid - openOnDistance " + start + " " + end); - - for (ListGridRecord record: this.getRecords()) { - GaugeRecord item = (GaugeRecord)record; - if (end == null && item.getKmStart() != null) { - if (item.getKmStart() >= start) { - expandRecord(item); - } - else { - collapseRecord(item); - } - } - else if (item.getKmStart() != null && item.getKmEnd() != null) { - // as getStart()/getEnd() return Double objects, they can be null and - // can cause NPEs when comparing with double... strange... - GWT.log("GaugeListGrid - openOnDistance item " + item.getKmStart() + " " + item.getKmEnd()); - if ((start >= item.getKmStart() && start <= item.getKmEnd()) || - (end >= item.getKmStart() && end <= item.getKmEnd()) || - (start <= item.getKmStart() && end >= item.getKmEnd())) { - expandRecord(item); - } - else { - collapseRecord(item); - } - } - else { - collapseRecord(item); - } - } - } - - /** - * Open Gauge entry if a location fits to the gauge. - */ - public void openOnLocations(List<Double> locations) { - GWT.log("GaugeListGrid - openOnLocations " + locations); - - if (locations == null || locations.isEmpty()) { - return; - } - - for (ListGridRecord record: this.getRecords()) { - GaugeRecord item = (GaugeRecord)record; - boolean isset = false; - for (Double location: locations) { - if (locations == null) { - continue; - } - - Double start = item.getKmStart(); - Double end = item.getKmEnd(); - if (start == null || end == null) { - // should not occur but avoid NullPointerException - continue; - } - - if (location >= start && location <= end) { - isset = true; - break; - } - } - if (isset) { - expandRecord(item); - } - else { - collapseRecord(item); - } - } - } - - @Override - protected Canvas getExpandPanel(ListGridRecord record) { - GaugeRecord item = (GaugeRecord)record; - return new WidgetCanvas(new GaugeInfoPanel(item, flys)); - } - - @Override - public void onRecordClick(RecordClickEvent event) { - GaugeRecord gauge = (GaugeRecord)event.getRecord(); - flys.newGaugeDischargeCurve(gauge.getRiverName(), - gauge.getOfficialNumber()); - } - - @Override - public String getCellCSSText(ListGridRecord record, int rowNum, - int colNum) { - if (colNum == ABFLUSSTAFEL_COLUMN) { - // display the ablfusstafel cell like a link - return "text-decoration: underline; color: #0000EE; cursor: pointer;"; - } - else { - return super.getCellCSSText(record, rowNum, colNum); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/GaugePanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.shared.model.RiverInfo; - - -/** - * The GaugePanel is intended to be used within a SectionStackSection - * - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class GaugePanel extends InfoPanel { - - /** - * GaugePanel loads the GaugeInfo from the RiverInfoService and - * displays them in a tree underneath a RiverInfoPanel - * - * @param flys The FLYS object - */ - public GaugePanel(FLYS flys) { - super(new GaugeListGrid(flys)); - } - - - @Override - public String getSectionTitle() { - return MSG.gaugePanelTitle(); - } - - /** - * Loads the river info and renders it afterwards. - */ - public void refresh() { - contract(); - - riverInfoService.getGauges(this.river, new AsyncCallback<RiverInfo>() { - @Override - public void onFailure(Throwable e) { - GWT.log("Could not load the river info." + e); - } - - @Override - public void onSuccess(RiverInfo riverinfo) { - GWT.log("Loaded river info"); - render(riverinfo); - expand(); - } - }); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/GaugeRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,165 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.GaugeInfo; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class GaugeRecord extends ListGridRecord implements GaugeInfo { - - /** The message class that provides i18n strings.*/ - private FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public GaugeRecord(GaugeInfo gauge) { - setCanExpand(true); - Long number = gauge.getOfficialNumber(); - String url = number != null ? - MSG.gauge_url() + number : - MSG.gauge_url(); - setLink(url); - setLinkText(MSG.gauge_info_link()); - setName(gauge.getName()); - setKmStart(gauge.getKmStart()); - setKmEnd(gauge.getKmEnd()); - setMinQ(gauge.getMinQ()); - setMaxQ(gauge.getMaxQ()); - setMinW(gauge.getMinW()); - setMaxW(gauge.getMaxW()); - setAeo(gauge.getAeo()); - setDatum(gauge.getDatum()); - setKmUp(gauge.isKmUp()); - setOfficialNumber(gauge.getOfficialNumber()); - setRiverName(gauge.getRiverName()); - setStation(gauge.getStation()); - setWstUnit(gauge.getWstUnit()); - setCurveLink(MSG.gauge_curve_link()); - } - - private void setCurveLink(String value) { - this.setAttribute("curvelink", value); - } - - private void setLink(String url) { - this.setAttribute("link", url); - } - - public String getLink() { - return this.getAttributeAsString("link"); - } - - public String getName() { - return this.getAttributeAsString("name"); - } - - private void setName(String value) { - this.setAttribute("name", value); - } - - public Double getKmStart() { - return this.getAttributeAsDouble("kmstart"); - } - - private void setKmStart(Double value) { - this.setAttribute("kmstart", value); - } - - public Double getKmEnd() { - return this.getAttributeAsDouble("kmend"); - } - - private void setKmEnd(Double value) { - this.setAttribute("kmend", value); - } - - public Double getMinQ() { - return this.getAttributeAsDouble("minq"); - } - - private void setMinQ(Double value) { - this.setAttribute("minq", value); - } - - public Double getMaxQ() { - return this.getAttributeAsDouble("maxq"); - } - - private void setMaxQ(Double value) { - this.setAttribute("maxq", value); - } - - public Double getMinW() { - return this.getAttributeAsDouble("minw"); - } - - private void setMinW(Double value) { - this.setAttribute("minw", value); - } - - public Double getMaxW() { - return this.getAttributeAsDouble("maxw"); - } - - private void setMaxW(Double value) { - this.setAttribute("maxw", value); - } - - public Double getDatum() { - return this.getAttributeAsDouble("datum"); - } - - private void setDatum(Double value) { - this.setAttribute("datum", value); - } - - public Double getAeo() { - return this.getAttributeAsDouble("aeo"); - } - - private void setAeo(Double value) { - this.setAttribute("aeo", value); - } - - public boolean isKmUp() { - return this.getAttributeAsBoolean("kmup"); - } - - private void setKmUp(boolean value) { - this.setAttribute("kmup", value); - } - - public Double getStation() { - return this.getAttributeAsDouble("station"); - } - - private void setStation(Double value) { - this.setAttribute("station", value); - } - - public String getWstUnit() { - return this.getAttributeAsString("wstunit"); - } - - private void setWstUnit(String value) { - this.setAttribute("wstunit", value); - } - - public Long getOfficialNumber() { - return this.getAttributeAsLong("officialnumber"); - } - - private void setOfficialNumber(Long number) { - this.setAttribute("officialnumber", number); - } - - public String getRiverName() { - return this.getAttributeAsString("rivername"); - } - - private void setRiverName(String rivername) { - this.setAttribute("rivername", rivername); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/InfoListGrid.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.RiverInfo; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public abstract class InfoListGrid extends ListGrid { - - protected FLYS flys; - protected DataList[] data; - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - - public InfoListGrid(FLYS flys) { - super(); - this.flys = flys; - this.setCanExpandRecords(true); - this.setCanExpandMultipleRecords(true); - } - - public void openAll() { - GWT.log("InfoListGrid - openAll"); - for (ListGridRecord record: this.getRecords()) { - expandRecord(record); - } - } - - public void setData(DataList[] data) { - GWT.log("InfoListGrid - setData"); - this.data = data; - this.open(); - } - - protected Double getDoubleValue(Data d) { - String tmp = d.getStringValue(); - if (tmp != null) { - return Double.valueOf(tmp); - } - return null; - } - - @Override - protected Canvas getExpansionComponent(ListGridRecord record) { - VLayout layout = new VLayout(); - layout.setPadding(5); - layout.addMember(this.getExpandPanel(record)); - return layout; - } - - public abstract void open(); - - public abstract void setRiverInfo(RiverInfo riverinfo); - - protected abstract Canvas getExpandPanel(ListGridRecord record); -} \ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/InfoPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.Overflow; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.layout.SectionStackSection; -import com.smartgwt.client.widgets.layout.VLayout; -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.services.RiverInfoService; -import de.intevation.flys.client.client.services.RiverInfoServiceAsync; -import de.intevation.flys.client.client.ui.RiverInfoPanel; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.RiverInfo; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public abstract class InfoPanel extends VLayout { - - /** SectionStackSection where this InfoPanel belongs in*/ - protected SectionStackSection section; - - /** Name of the river */ - protected String river; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected RiverInfoServiceAsync riverInfoService = GWT.create(RiverInfoService.class); - - /** Panel to show the info about the river */ - protected RiverInfoPanel riverinfopanel; - - protected InfoListGrid listgrid; - - public final static String SECTION_ID = "InfoPanelSection"; - - public InfoPanel(InfoListGrid listgrid) { - SectionStackSection section = new SectionStackSection(); - section.setExpanded(false); - section.setTitle(getSectionTitle()); - section.setName(SECTION_ID); - section.setID(SECTION_ID); - - setOverflow(Overflow.HIDDEN); - setStyleName("infopanel"); - - section.setHidden(true); - section.setItems(this); - this.section = section; - this.listgrid = listgrid; - this.addMember(listgrid); - } - - /** - * Sets and loads the river data if river is not the current set river. - */ - public void setRiver(String river) { - if (!river.equals(this.river)) { - this.river = river; - this.refresh(); - } - } - - /** - * Sets the data and closes not corresponding folds in the gauge tree. - */ - public void setData(DataList[] data) { - this.listgrid.setData(data); - } - - protected void render(RiverInfo riverinfo) { - if (this.riverinfopanel == null) { - this.riverinfopanel = new RiverInfoPanel(riverinfo); - - this.addMember(this.riverinfopanel, 0); - } - else { - riverinfopanel.setRiverInfo(riverinfo); - } - this.listgrid.setRiverInfo(riverinfo); - } - - /** - * Hide the section stack section. - */ - @Override - public void hide() { - GWT.log("InfoPanel - hide"); - this.section.setHidden(true); - } - - /** - * Show the section stack section. - */ - @Override - public void show() { - GWT.log("InfoPanel - show"); - this.section.setHidden(false); - } - - @Override - public void addMember(Canvas component) { - super.addMember(component); - expand(); - } - - @Override - public void removeMembers(Canvas[] components) { - super.removeMembers(components); - contract(); - } - - public SectionStackSection getSection() { - return this.section; - } - - protected void removeAllMembers() { - removeMembers(getMembers()); - } - - /** - * Expands the gauge section. - */ - public void expand() { - section.setExpanded(true); - } - - /** - * Contracts/shrinks the expanded gauge section. - */ - public void contract() { - section.setExpanded(false); - } - - protected abstract void refresh(); - - protected abstract String getSectionTitle(); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationInfoPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import java.util.Date; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; -import com.google.gwt.user.client.ui.Grid; -import com.smartgwt.client.widgets.layout.VLayout; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.MeasurementStation; - -public class MeasurementStationInfoPanel extends VLayout { - - /** The message class that provides i18n strings.*/ - private FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public MeasurementStationInfoPanel(MeasurementStation station) { - setStyleName("infopanel"); - setWidth100(); - - Grid grid = new Grid(5, 2); - - String type = station.getMeasurementType(); - if (type != null) { - grid.setText(0, 0, MSG.measurement_station_type()); - grid.setText(0, 1, type); - } - - String riverside = station.getRiverSide(); - if (riverside != null) { - grid.setText(1, 0, MSG.riverside()); - grid.setText(1, 1, riverside); - } - - String gaugename = station.getGaugeName(); - if (gaugename != null) { - grid.setText(2, 0, MSG.measurement_station_gauge_name()); - grid.setText(2, 1, gaugename); - } - - DateTimeFormat df = DateTimeFormat.getFormat( - PredefinedFormat.DATE_MEDIUM); - - Date starttime = station.getStartTime(); - if (starttime != null) { - grid.setText(3, 0, MSG.measurement_station_start_time()); - grid.setText(3, 1, df.format(starttime)); - } - - String moperator = station.getOperator(); - if (moperator != null) { - grid.setText(4, 0, MSG.measurement_station_operator()); - grid.setText(4, 1, moperator); - } - - addMember(grid); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.WidgetCanvas; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; - -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.shared.model.MeasurementStation; -import de.intevation.flys.client.shared.model.RiverInfo; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class MeasurementStationListGrid -extends InfoListGrid -implements RecordClickHandler { - - public MeasurementStationListGrid(FLYS flys) { - super(flys); - ListGridField nfield = new ListGridField("name", "Messtelle"); - ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60); - ListGridField efield = new ListGridField("kmend", "Ende [km]", 60); - ListGridField stfield = new ListGridField("station", "Station [km]"); - ListGridField lfield = new ListGridField("link", "Link"); - lfield.setType(ListGridFieldType.LINK); - ListGridField cfield = new ListGridField("curvelink", "SQ"); - cfield.addRecordClickHandler(this); - this.setFields(nfield, sfield, efield, stfield, lfield, cfield); - } - - /** - * Resets the items of the tree. - * If the list of gauges is empty or null the tree will be empty. - */ - @Override - public void setRiverInfo(RiverInfo riverinfo) { - List<MeasurementStation> stations = riverinfo.getMeasurementStations(); - GWT.log("MeasurmentStationListGrid - setRiverInfo " + stations); - - if (stations != null && !stations.isEmpty()) { - - ArrayList<MeasurementStation> emptystations = - new ArrayList<MeasurementStation>(); - - if (!riverinfo.isKmUp()) { - for (MeasurementStation station : stations) { - addStation(station, emptystations); - } - } - else { - for (int i = stations.size()-1; i >= 0; i--) { - MeasurementStation station = stations.get(i); - addStation(station, emptystations); - } - } - - // put empty stations to the end - for (MeasurementStation station : emptystations) { - addStation(station); - } - } - } - - private void addStation(MeasurementStation station, - List<MeasurementStation> empty) { - if (station.getKmStart() != null && station.getKmEnd() != null) { - addStation(station); - } - else { - empty.add(station); - } - } - - private void addStation(MeasurementStation station) { - ListGridRecord record = new MeasurementStationRecord(station); - this.addData(record); - } - - @Override - public void open() { - } - - @Override - protected Canvas getExpandPanel(ListGridRecord record) { - MeasurementStationRecord station = (MeasurementStationRecord)record; - return new WidgetCanvas(new MeasurementStationInfoPanel(station)); - } - - @Override - public void onRecordClick(RecordClickEvent event) { - MeasurementStationRecord station = - (MeasurementStationRecord)event.getRecord(); - flys.newSQRelation(station.getRiverName(), station.getID()); - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationPanel.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.shared.model.RiverInfo; - -/** - * A Panel to show info about the MeasurementStations of a river - * - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class MeasurementStationPanel extends InfoPanel { - - /** - * MeasurementStationPanel loads the MeasurementStations from the - * RiverInfoService and displays them in a tree underneath a RiverInfoPanel - * - * @param flys The FLYS object - */ - public MeasurementStationPanel(FLYS flys) { - super(new MeasurementStationListGrid(flys)); - } - - /** - * Returns the title which should be displayed in the section - */ - @Override - public String getSectionTitle() { - return MSG.measurementStationPanelTitle(); - } - - /** - * Loads the river info and renders it afterwards - */ - @Override - public void refresh() { - GWT.log("MeasurementStationPanel - refresh"); - contract(); - - riverInfoService.getMeasurementStations(this.river, - new AsyncCallback<RiverInfo>() { - @Override - public void onFailure(Throwable e) { - GWT.log("Could not load the river info." + e); - } - - @Override - public void onSuccess(RiverInfo riverinfo) { - GWT.log("MeasurementStationPanel - Loaded river info"); - render(riverinfo); - expand(); - } - }); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +0,0 @@ -package de.intevation.flys.client.client.ui.stationinfo; - -import java.util.Date; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.shared.model.MeasurementStation; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class MeasurementStationRecord -extends ListGridRecord -implements MeasurementStation { - - /** The message class that provides i18n strings.*/ - private FLYSConstants MSG = GWT.create(FLYSConstants.class); - - public MeasurementStationRecord(MeasurementStation station) { - this.setCanExpand(true); - - Integer number = station.getID(); - String link = number != null ? - MSG.measurement_station_url() + number : - MSG.measurement_station_url(); - this.setLink(link); - this.setLinkText(MSG.measurement_station_info_link()); - this.setCurveLink(MSG.static_sqrelation()); - this.setID(number); - this.setName(station.getName()); - if (station.isKmUp()) { - this.setKmEnd(station.getKmStart()); - this.setKmStart(station.getKmEnd()); - } - else { - this.setKmEnd(station.getKmEnd()); - this.setKmStart(station.getKmStart()); - } - this.setKmUp(station.isKmUp()); - this.setRiverName(station.getRiverName()); - this.setStation(station.getStation()); - this.setGaugeName(station.getGaugeName()); - this.setMeasurementType(station.getMeasurementType()); - this.setOperator(station.getOperator()); - this.setRiverSide(station.getRiverSide()); - this.setStartTime(station.getStartTime()); - this.setStopTime(station.getStopTime()); - } - - @Override - public Integer getID() { - return this.getAttributeAsInt("stationid"); - } - - private void setID(Integer value) { - this.setAttribute("stationid", value); - } - - @Override - public String getName() { - return this.getAttributeAsString("name"); - } - - private void setName(String value) { - this.setAttribute("name", value); - } - - @Override - public Double getKmStart() { - return this.getAttributeAsDouble("kmstart"); - } - - private void setKmStart(Double value) { - this.setAttribute("kmstart", value); - } - - @Override - public Double getKmEnd() { - return this.getAttributeAsDouble("kmend"); - } - - private void setKmEnd(Double value) { - this.setAttribute("kmend", value); - } - - @Override - public boolean isKmUp() { - return this.getAttributeAsBoolean("kmup"); - } - - private void setKmUp(boolean value) { - this.setAttribute("kmup", value); - } - - @Override - public Double getStation() { - return this.getAttributeAsDouble("station"); - } - - private void setStation(Double station) { - this.setAttribute("station", station); - } - - @Override - public String getRiverName() { - return this.getAttributeAsString("rivername"); - } - - private void setRiverName(String rivername) { - this.setAttribute("rivername", rivername); - } - - @Override - public String getRiverSide() { - return this.getAttributeAsString("riverside"); - } - - private void setRiverSide(String riverside) { - this.setAttribute("riverside", riverside); - } - - @Override - public String getMeasurementType() { - return this.getAttributeAsString("measurementtype"); - } - - private void setMeasurementType(String value) { - this.setAttribute("measurementtype", value); - } - - @Override - public String getOperator() { - return this.getAttributeAsString("operator"); - } - - private void setOperator(String value) { - this.setAttribute("operator", value); - } - - @Override - public Date getStartTime() { - return this.getAttributeAsDate("starttime"); - } - - private void setStartTime(Date value) { - this.setAttribute("starttime", value); - } - - @Override - public Date getStopTime() { - return this.getAttributeAsDate("stoptime"); - } - - private void setStopTime(Date value) { - this.setAttribute("stoptime", value); - } - - @Override - public String getGaugeName() { - return this.getAttributeAsString("gaugename"); - } - - private void setGaugeName(String value) { - this.setAttribute("gaugename", value); - } - - public String getLink() { - return this.getAttributeAsString("link"); - } - - public void setLink(String link) { - this.setAttribute("link", link); - } - - public void setCurveLink(String link) { - this.setAttribute("curvelink", link); - } - - public String getCurveLink() { - return this.getAttribute("curvelink"); - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/ClickableQDTable.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,171 +0,0 @@ -package de.intevation.flys.client.client.ui.wq; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; - -import de.intevation.flys.client.client.FLYSConstants; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ClickableQDTable extends ListGrid { - - public static enum ClickMode { - NONE, SINGLE, RANGE - } - - public static interface QClickedListener { - - void clickedLower(double value); - - void clickedUpper(double value); - } - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - private QClickedListener qClickedListener; - private ClickMode clickMode; - - protected boolean lockClick; - - public ClickableQDTable() { - this.clickMode = ClickMode.NONE; - init(); - } - - public ClickableQDTable(QClickedListener qClickedListener, - ClickMode clickMode) { - this.qClickedListener = qClickedListener; - this.clickMode = clickMode; - init(); - } - - private void init() { - setWidth100(); - setHeight100(); - setSelectionType(SelectionStyle.SINGLE); - setSelectionType(SelectionStyle.SINGLE); - setShowHeaderContextMenu(false); - setShowRecordComponents(true); - setShowRecordComponentsByCell(true); - setEmptyMessage(MESSAGE.empty_table()); - - ListGridField name = new ListGridField("name", MESSAGE.discharge()); - name.setType(ListGridFieldType.TEXT); - name.setWidth("*"); - - ListGridField type = new ListGridField("type", MESSAGE.type()); - type.setType(ListGridFieldType.TEXT); - type.setWidth("20%"); - - final NumberFormat nf = NumberFormat.getDecimalFormat(); - - ListGridField value = new ListGridField("value", MESSAGE.wq_value_q()); - value.setType(ListGridFieldType.FLOAT); - value.setCellFormatter(new CellFormatter() { - - @Override - public String format(Object v, ListGridRecord r, int row, int col) { - if (v == null) { - return null; - } - - try { - double value = Double.valueOf(v.toString()); - return nf.format(value); - } - catch (NumberFormatException nfe) { - return v.toString(); - } - } - }); - value.setWidth("20%"); - - switch (clickMode) { - case NONE: - setFields(name, type, value); - break; - case SINGLE: - initSingleClickMode(name, type, value); - break; - case RANGE: - initRangeClickMode(name, type, value); - break; - } - } - - private void initSingleClickMode(ListGridField name, ListGridField type, - ListGridField value) { - ListGridField select = new ListGridField("select", MESSAGE.selection()); - select.setType(ListGridFieldType.ICON); - select.setWidth(70); - select.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); - - addCellClickHandler(new CellClickHandler() { - - @Override - public void onCellClick(CellClickEvent event) { - if (event.getColNum() == 0) { - ListGridRecord r = event.getRecord(); - fireLowerClickEvent(r.getAttributeAsDouble("value")); - } - } - }); - - setFields(select, name, type, value); - } - - private void initRangeClickMode(ListGridField name, ListGridField type, - ListGridField value) { - ListGridField addMin = new ListGridField("min", MESSAGE.to()); - addMin.setType(ListGridFieldType.ICON); - addMin.setWidth(30); - addMin.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); - - ListGridField addMax = new ListGridField("max", MESSAGE.from()); - addMax.setType(ListGridFieldType.ICON); - addMax.setWidth(30); - addMax.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerRed()); - - addCellClickHandler(new CellClickHandler() { - - @Override - public void onCellClick(CellClickEvent event) { - if (event.getColNum() == 0) { - ListGridRecord r = event.getRecord(); - fireLowerClickEvent(r.getAttributeAsDouble("value")); - } - - if (event.getColNum() == 1) { - ListGridRecord r = event.getRecord(); - fireUpperClickEvent(r.getAttributeAsDouble("value")); - } - } - }); - - setFields(addMin, addMax, name, type, value); - } - - private void fireLowerClickEvent(double value) { - if (qClickedListener != null) { - qClickedListener.clickedLower(value); - } - } - - private void fireUpperClickEvent(double value) { - if (qClickedListener != null) { - qClickedListener.clickedUpper(value); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/ClickableWTable.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -package de.intevation.flys.client.client.ui.wq; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; - -import de.intevation.flys.client.client.FLYSConstants; - - -public class ClickableWTable extends ListGrid { - - public static enum ClickMode { - NONE, SINGLE, RANGE - } - - private boolean useWaterlevelLabel = false; - - public static interface WClickedListener { - - void clickedLower(double value); - - void clickedUpper(double value); - } - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - private WClickedListener wClickedListener; - private ClickMode clickMode; - - public ClickableWTable() { - this.clickMode = ClickMode.NONE; - init(); - } - - public ClickableWTable(WClickedListener lowerListener, - ClickMode selectionMode, boolean alternativeLabel) { - this.wClickedListener = lowerListener; - this.clickMode = selectionMode; - this.useWaterlevelLabel = alternativeLabel; - init(); - } - - private void init() { - setWidth100(); - setHeight100(); - setSelectionType(SelectionStyle.NONE); - setSelectionType(SelectionStyle.NONE); - setShowHeaderContextMenu(false); - setShowRecordComponents(true); - setShowRecordComponentsByCell(true); - setEmptyMessage(MESSAGE.empty_table()); - - ListGridField name = new ListGridField("name", - useWaterlevelLabel ? MESSAGE.wq_waterlevel_label() : MESSAGE.name() ); - name.setType(ListGridFieldType.TEXT); - name.setWidth("*"); - - ListGridField type = new ListGridField("type", MESSAGE.type()); - type.setType(ListGridFieldType.TEXT); - type.setWidth("50"); - - final NumberFormat nf = NumberFormat.getDecimalFormat(); - - ListGridField value = new ListGridField("value", MESSAGE.wq_value_w()); - value.setType(ListGridFieldType.FLOAT); - value.setCellFormatter(new CellFormatter() { - - @Override - public String format(Object v, ListGridRecord r, int row, int col) { - if (v == null) { - return null; - } - - try { - double value = Double.valueOf(v.toString()); - return nf.format(value); - } - catch (NumberFormatException nfe) { - return v.toString(); - } - } - }); - - switch (clickMode) { - case NONE: - setFields(name, type, value); - break; - case SINGLE: - initSingleClickMode(name, type, value); - break; - case RANGE: - initRangeClickMode(name, type, value); - break; - } - } - - private void initSingleClickMode(ListGridField name, ListGridField type, - ListGridField value) { - ListGridField lower = new ListGridField("selection", - MESSAGE.selection()); - lower.setType(ListGridFieldType.ICON); - lower.setWidth("65"); - lower.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); - addCellClickHandler(new CellClickHandler() { - - @Override - public void onCellClick(CellClickEvent event) { - if (event.getColNum() == 0) { - Record r = event.getRecord(); - double val = r.getAttributeAsDouble("value"); - fireLowerClickEvent(val); - } - } - }); - - setFields(lower, name, type, value); - } - - private void initRangeClickMode(ListGridField name, ListGridField type, - ListGridField value) { - ListGridField lower = new ListGridField("lower", MESSAGE.lower()); - lower.setType(ListGridFieldType.ICON); - lower.setWidth("50"); - lower.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerRed()); - addCellClickHandler(new CellClickHandler() { - - @Override - public void onCellClick(CellClickEvent event) { - if (event.getColNum() == 0) { - Record r = event.getRecord(); - double val = r.getAttributeAsDouble("value"); - fireLowerClickEvent(val); - } - } - }); - - ListGridField upper = new ListGridField("upper", MESSAGE.upper()); - upper.setType(ListGridFieldType.ICON); - upper.setWidth("50"); - upper.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); - addCellClickHandler(new CellClickHandler() { - - @Override - public void onCellClick(CellClickEvent event) { - if (event.getColNum() == 1) { - Record r = event.getRecord(); - double val = r.getAttributeAsDouble("value"); - fireUpperClickEvent(val); - } - } - }); - - setFields(lower, upper, name, type, value); - } - - private void fireLowerClickEvent(double value) { - if (wClickedListener != null) { - wClickedListener.clickedLower(value); - } - } - - private void fireUpperClickEvent(double value) { - if (wClickedListener != null) { - wClickedListener.clickedUpper(value); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/QDTable.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -package de.intevation.flys.client.client.ui.wq; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import de.intevation.flys.client.client.FLYSConstants; - - -/** - * Table showing Q and D main values, allowing for selection. - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class QDTable extends ListGrid { - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - - protected boolean lockClick; - - public QDTable() { - String baseUrl = GWT.getHostPageBaseURL(); - - setWidth100(); - setHeight100(); - setSelectionType(SelectionStyle.SINGLE); - setSelectionType(SelectionStyle.SINGLE); - setShowHeaderContextMenu(false); - setShowRecordComponents(true); - setShowRecordComponentsByCell(true); - setEmptyMessage(MESSAGE.empty_table()); - - ListGridField addMax = new ListGridField("max", MESSAGE.from()); - addMax.setType(ListGridFieldType.ICON); - addMax.setWidth(30); - addMax.setCellIcon(baseUrl + MESSAGE.markerRed()); - - ListGridField addMin = new ListGridField("min", MESSAGE.to()); - addMin.setType(ListGridFieldType.ICON); - addMin.setWidth(30); - addMin.setCellIcon(baseUrl + MESSAGE.markerGreen()); - - ListGridField select = new ListGridField("select", MESSAGE.selection()); - select.setType(ListGridFieldType.ICON); - select.setWidth(70); - select.setCellIcon(baseUrl + MESSAGE.markerGreen()); - - ListGridField name = new ListGridField("name", MESSAGE.discharge()); - name.setType(ListGridFieldType.TEXT); - name.setWidth("*"); - - ListGridField type = new ListGridField("type", MESSAGE.type()); - type.setType(ListGridFieldType.TEXT); - type.setWidth("20%"); - - final NumberFormat nf = NumberFormat.getDecimalFormat(); - - ListGridField value = new ListGridField("value", MESSAGE.wq_value_q()); - value.setType(ListGridFieldType.FLOAT); - value.setCellFormatter(new CellFormatter() { - @Override - public String format(Object v, ListGridRecord r, int row, int col) { - if (v == null) { - return null; - } - - try { - double value = Double.valueOf(v.toString()); - return nf.format(value); - } - catch (NumberFormatException nfe) { - return v.toString(); - } - } - }); - value.setWidth("20%"); - - setFields(addMax, addMin, select, name, type, value); - } - - public void hideIconFields () { - hideField("max"); - hideField("min"); - hideField("select"); - lockClick = true; - } - - - public void showIconFields() { - showField("max"); - showField("min"); - hideField("select"); - lockClick = false; - } - - public void showSelect() { - showField("select"); - hideField("max"); - hideField("min"); - } - - public boolean isLocked() { - return lockClick; - } - - /** - * Search all records for one with attribute name equals to given name. - * @return null if none found. - * */ - public Double findRecordValue(String name) { - for (ListGridRecord record : getRecords()) { - if (record.getAttribute("name").equals(name)) { - return record.getAttributeAsDouble("value"); - } - } - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/WQAutoTabSet.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -package de.intevation.flys.client.client.ui.wq; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -import de.intevation.flys.client.client.services.WQInfoService; -import de.intevation.flys.client.client.services.WQInfoServiceAsync; - -import de.intevation.flys.client.shared.model.WQInfoObject; -import de.intevation.flys.client.shared.model.WQInfoRecord; - -import de.intevation.flys.client.client.FLYSConstants; - -import de.intevation.flys.client.client.Config; - -/** Tabset showing non-selectable W and Q/D values for a gauge. */ -public class WQAutoTabSet extends TabSet { - - /** Service to fetch W/Q/D values. */ - WQInfoServiceAsync wqInfoService = - GWT.create(WQInfoService.class); - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - /** Table showing Q/D values. */ - protected QDTable qdTable; - - /** Table showing W values. */ - protected WTable wTable; - - - /** Set up two tabs showing W and Q/D values, fetch and populate tables. */ - public WQAutoTabSet(String riverName, double[] dist) { - super(); - - this.setWidth100(); - this.setHeight100(); - - Tab wTab = new Tab(MESSAGE.wq_table_w()); - Tab qTab = new Tab(MESSAGE.wq_table_q()); - - qdTable = new QDTable(); - qdTable.hideIconFields(); - wTable = new WTable(); - - wTab.setPane(wTable); - qTab.setPane(qdTable); - - this.addTab(wTab, 0); - this.addTab(qTab, 1); - - Config config = Config.getInstance(); - String locale = config.getLocale(); - wqInfoService.getWQInfo(locale, riverName, dist[0], dist[1], - new AsyncCallback<WQInfoObject[]>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("Could not recieve wq informations."); - SC.warn(caught.getMessage()); - } - - @Override - public void onSuccess(WQInfoObject[] wqi) { - int num = wqi != null ? wqi.length :0; - GWT.log("Recieved " + num + " wq informations."); - - if (num == 0) { - return; - } - - addWQInfo(wqi); - } - } - ); - } - - - /** Populate tables with one value. */ - private void addWQInfo (WQInfoObject[] wqi) { - for(WQInfoObject wi: wqi) { - WQInfoRecord rec = new WQInfoRecord(wi); - - if (wi.getType().equals("W")) { - wTable.addData(rec); - } - else { - qdTable.addData(rec); - } - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/WTable.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -package de.intevation.flys.client.client.ui.wq; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.types.SelectionStyle; -import com.smartgwt.client.widgets.grid.CellFormatter; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import de.intevation.flys.client.client.FLYSConstants; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class WTable extends ListGrid { - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - - public WTable() { - setWidth100(); - setHeight100(); - setSelectionType(SelectionStyle.NONE); - setSelectionType(SelectionStyle.NONE); - setShowHeaderContextMenu(false); - setShowRecordComponents(true); - setShowRecordComponentsByCell(true); - setEmptyMessage(MESSAGE.empty_table()); - - ListGridField name = new ListGridField("name", MESSAGE.name()); - name.setType(ListGridFieldType.TEXT); - name.setWidth("*"); - - ListGridField type = new ListGridField("type", MESSAGE.type()); - type.setType(ListGridFieldType.TEXT); - type.setWidth("50"); - - final NumberFormat nf = NumberFormat.getDecimalFormat(); - - ListGridField value = new ListGridField("value", MESSAGE.wq_value_w()); - value.setType(ListGridFieldType.FLOAT); - value.setCellFormatter(new CellFormatter() { - @Override - public String format(Object v, ListGridRecord r, int row, int col) { - if (v == null) { - return null; - } - - try { - double value = Double.valueOf(v.toString()); - return nf.format(value); - } - catch (NumberFormatException nfe) { - return v.toString(); - } - } - }); - - setFields(name, type, value); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -package de.intevation.flys.client.client.utils; - -import java.util.Map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.widgets.form.fields.FormItem; - -import de.intevation.flys.client.client.FLYSConstants; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class DoubleValidator implements Validator { - - /** The interface that provides i18n messages. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - - /** Statically determine doubility of String value. */ - public static boolean isDouble(Object obj) { - if (obj == null) { - return false; - } - - boolean valid = true; - String v = obj.toString(); - - NumberFormat f = NumberFormat.getDecimalFormat(); - - try { - if (v == null) { - throw new NumberFormatException("empty"); - } - - double value = f.parse(v); - } - catch (NumberFormatException nfe) { - valid = false; - } - return valid; - - } - - - /** - * @return true if items value can be converted to double, if false, - * expect error message in \param errors map. - */ - public boolean validate(FormItem item, Map errors) { - boolean valid = true; - - if(item.getValue() == null) { - return false; - } - String v = item.getValue().toString(); - - NumberFormat f = NumberFormat.getDecimalFormat(); - - try { - if (v == null) { - throw new NumberFormatException("empty"); - } - - double value = f.parse(v); - - errors.remove(item.getFieldName()); - } - catch (NumberFormatException nfe) { - errors.put(item.getFieldName(), MSG.wrongFormat()); - - item.focusInItem(); - - valid = false; - } - return valid; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/EnableDisableCmd.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.client.utils; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface EnableDisableCmd { - - void enable(); - - void disable(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/IntegerValidator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -package de.intevation.flys.client.client.utils; - -import java.util.Map; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.form.fields.FormItem; - -import de.intevation.flys.client.client.FLYSConstants; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class IntegerValidator implements Validator { - - /** The interface that provides i18n messages. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** - * - */ - public boolean validate(FormItem item, Map errors) { - boolean valid = true; - - String v = item.getValue().toString(); - - try { - if (v == null) { - throw new NumberFormatException("empty"); - } - - int value = Integer.parseInt(v); - - errors.remove(item.getFieldName()); - } - catch (NumberFormatException nfe) { - errors.put(item.getFieldName(), MSG.wrongFormat()); - - item.focusInItem(); - - valid = false; - } - return valid; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/Validator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package de.intevation.flys.client.client.utils; - -import java.util.Map; - -import com.smartgwt.client.widgets.form.fields.FormItem; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - * - * This validator is used for SmartGWT FormItems. - */ -public interface Validator { - - boolean validate(FormItem item, Map errors); -} -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/widgets/DischargeTablesChart.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -package de.intevation.flys.client.client.widgets; - -import com.google.gwt.core.client.GWT; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; -import com.smartgwt.client.widgets.events.ResizedEvent; -import com.smartgwt.client.widgets.events.ResizedHandler; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; - - -public class DischargeTablesChart extends Canvas implements ResizedHandler { - - protected Artifact artifact; - - protected Img img; - - public DischargeTablesChart() { - super(); - } - - public DischargeTablesChart(Artifact artifact) { - super(); - this.artifact = artifact; - init(); - } - - private void init() { - addChild(createImage()); - addResizedHandler(this); - setSize("100%", "100%"); - } - - protected Img createImage() { - img = new Img(getUrl()); - img.setSize("100%", "100%"); - - return img; - } - - protected String getUrl() { - String url = GWT.getModuleBaseURL(); - url += "dischargetablesoverview"; - url += "?gauge=" + getGauge(); - url += "&format=png"; - - String[] timerange = getTimerange(); - url += "&lower=" + timerange[0]; - url += "&upper=" + timerange[1]; - - int width = 600; - int height = 400; - if (img != null) { - width = img.getWidth(); - height = img.getHeight(); - } - - url += "&width=" + String.valueOf(width); - url += "&height=" + String.valueOf(height); - - // add time millis to 'deactivate' caching - url += "&timemillis" + System.currentTimeMillis(); - - GWT.log("DischargeTablesService URL = '" + url + "'"); - return url; - } - - protected String getGauge() { - ArtifactDescription desc = artifact.getArtifactDescription(); - return desc.getReferenceGauge(); - } - - protected String[] getTimerange() { - ArtifactDescription desc = artifact.getArtifactDescription(); - String yearStr = desc.getDataValueAsString("year_range"); - - if (yearStr != null && yearStr.length() > 0) { - return yearStr.split(";"); - } - - return new String[2]; - } - - @Override - public void onResized(ResizedEvent event) { - GWT.log("resized discharge tables overview chart"); - img.setSrc(getUrl()); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/widgets/KMSpinner.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -package de.intevation.flys.client.client.widgets; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import com.smartgwt.client.data.Record; -import com.smartgwt.client.widgets.Button; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.events.ClickEvent; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.FormItemValueFormatter; -import com.smartgwt.client.widgets.form.FormItemValueParser; -import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; -import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; -import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; -import com.smartgwt.client.widgets.layout.HLayout; - -import de.intevation.flys.client.shared.model.FacetRecord; - -import java.util.ArrayList; -import java.util.List; - -/** - * SpinnerItem-like element with text label and up/down buttons. - */ -public class KMSpinner extends HLayout { - protected List<KMSpinnerChangeListener> listeners = new ArrayList<KMSpinnerChangeListener>(); - - protected Label label; - protected FacetRecord facetRecord; - protected double value; - - public KMSpinner(double initialValue, FacetRecord facetRecord) { - super(2); - this.facetRecord = facetRecord; - this.value = initialValue; - - setWidth("99%"); - setHeight(18); - - // minusButton shall ask service for previous available cs. - Button minusButton = new Button("-"); - minusButton.setWidth(18); - minusButton.setHeight(18); - minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { - public void onClick(ClickEvent evt) { - fireChangedEvent(value - 0.1d, false); - } - }); - - DynamicForm form = new DynamicForm(); - final TextItem kmField = new TextItem(); - kmField.setValue(initialValue); - kmField.setWidth("*"); - kmField.setTitle(""); - kmField.setHeight(16); - - FormItemValueFormatter doubleFormat = new FormItemValueFormatter() { - public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { - if (value != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(value.toString()).doubleValue(); - return nf.format(d); - } - catch (Exception e) { - GWT.log("EditorValueFormatter exception: " + e.toString()); - - // Remove junk chars from input string - return doublefyString(value.toString()); - } - } - else { - return null; - } - } - }; - kmField.setEditorValueFormatter(doubleFormat); - - FormItemValueParser doubleParser = new FormItemValueParser() { - public Object parseValue(String value, DynamicForm form, FormItem item) { - if (value == null) - return null; - try { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double d = nf.parse(value.toString()); - return Double.toString(d); - } - catch(NumberFormatException nfe) { - return value; - } - } - }; - kmField.setEditorValueParser(doubleParser); - - // Update on focus lost and enter-pressed. - kmField.addBlurHandler(new BlurHandler() { - @Override - public void onBlur(BlurEvent be) { - if (kmField.getValue() != null) { - try { - fireChangedEvent(Double.parseDouble(kmField.getValue().toString()), true); - } - catch(NumberFormatException nfe) { - GWT.log("entered string cannot be parsed to double."); - } - } - } - }); - kmField.addKeyPressHandler(new KeyPressHandler() { - @Override - public void onKeyPress(KeyPressEvent kpe) { - if (kpe.getKeyName().equals("Enter")) { - kmField.blurItem(); - } - } - }); - - // TODO: i18n Now add all the validators, formatters, editors/parsers etc. - form.setFields(kmField); - form.setTitle(""); - form.setTitlePrefix(""); - form.setTitleSuffix(""); - form.setTitleWidth(0); - form.setWidth(50); - form.setHeight(18); - - // PlusButton shall ask service for next available cs. - Button plusButton = new Button("+"); - plusButton.setWidth(18); - plusButton.setHeight(18); - plusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { - public void onClick(ClickEvent evt) { - fireChangedEvent(value + 0.1d, true); - } - }); - - this.addMember(minusButton); - this.addMember(form); - this.addMember(plusButton); - } - - public void addChangeListener(KMSpinnerChangeListener listener) { - this.listeners.add(listener); - } - - protected void fireChangedEvent(double val, boolean up) { - for(KMSpinnerChangeListener listener : listeners) { - listener.spinnerValueEntered(this, val, facetRecord, up); - } - } - - /** - * Remove junk chars from double string. - * This method should work for most locales, but not for - * exotic ones that do not use "." or "," as decimal - * separator. - * @return - */ - protected String doublefyString(String str) { - StringBuilder buf = new StringBuilder(str.length()); - - for (int n = 0; n < str.length(); n++) { - char c = str.charAt(n); - if ((c >= '0' && c <= '9') || c == '.' || c == ',') { - buf.append(c); - } - } - - return buf.toString(); - } -} -
--- a/flys-client/src/main/java/de/intevation/flys/client/client/widgets/KMSpinnerChangeListener.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -package de.intevation.flys.client.client.widgets; - -import de.intevation.flys.client.client.widgets.KMSpinner; - -import de.intevation.flys.client.shared.model.FacetRecord; - -public interface KMSpinnerChangeListener { - public void spinnerValueEntered(KMSpinner spinner, double km, FacetRecord facetRecord, boolean up); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/AddArtifactServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package de.intevation.flys.client.server; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.client.services.AddArtifactService; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class AddArtifactServiceImpl -extends DescribeCollectionServiceImpl -implements AddArtifactService -{ - private static final Logger logger = - Logger.getLogger(AddArtifactService.class); - - - public Collection add( - Collection collection, - Artifact artifact, - String locale) - throws ServerException - { - logger.info("AddArtifactServiceImpl.add"); - String url = getServletContext().getInitParameter("server-url"); - - return CollectionHelper.addArtifact(collection, artifact, url, locale); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/AdvanceServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.client.services.AdvanceService; - - -/** - * This interface provides artifact specific operation ADVANCE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class AdvanceServiceImpl -extends RemoteServiceServlet -implements AdvanceService -{ - private static final Logger logger = Logger.getLogger(AdvanceService.class); - - public static final String XPATH_RESULT = "/art:result/text()"; - - public static final String OPERATION_FAILURE = "FAILED"; - - public static final String ERROR_ADVANCE_ARTIFACT = "error_advance_artifact"; - - - public Artifact advance( - String locale, - Artifact artifact, - String target) - throws ServerException - { - logger.info("AdvanceServiceImpl.advance"); - - String url = getServletContext().getInitParameter("server-url"); - - Document advance = ClientProtocolUtils.newAdvanceDocument( - artifact.getUuid(), - artifact.getHash(), - target); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document description = (Document) client.advance( - new de.intevation.artifacts.httpclient.objects.Artifact( - artifact.getUuid(), - artifact.getHash()), - advance, - new DocumentResponseHandler()); - - if (description == null) { - throw new ServerException(ERROR_ADVANCE_ARTIFACT); - } - - String result = XMLUtils.xpathString( - description, - XPATH_RESULT, - ArtifactNamespaceContext.INSTANCE); - - if (result == null || !result.equals(OPERATION_FAILURE)) { - return (Artifact) new FLYSArtifactCreator().create(description); - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_ADVANCE_ARTIFACT); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,582 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DefaultArtifactDescription; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.DefaultOutputMode; -import de.intevation.flys.client.shared.model.DoubleArrayData; -import de.intevation.flys.client.shared.model.DoubleRangeData; -import de.intevation.flys.client.shared.model.IntegerArrayData; -import de.intevation.flys.client.shared.model.IntegerRangeData; -import de.intevation.flys.client.shared.model.IntegerOptionsData; -import de.intevation.flys.client.shared.model.LongRangeData; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.WQDataItem; - - -/** - * This factory class helps creating an {@link ArtifactDescription} based on the - * DESCRIBE document of an artifact returned by the artifact server. Use the - * {@link createArtifactDescription(org.w3c.dom.Document)} method with the - * DESCRIBE document to create such an {@link ArtifactDescription}. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ArtifactDescriptionFactory { - - private static final Logger logger = - Logger.getLogger(ArtifactDescriptionFactory.class); - - - public static final String XPATH_STATE_NAME = "@art:name"; - - public static final String XPATH_UIPROVIDER = "@art:uiprovider"; - - public static final String XPATH_HELP_TEXT = "@art:helpText"; - - public static final String XPATH_REACHABLE_STATE = "art:state"; - - public static final String XPATH_STATIC_STATE_NODE = "art:state"; - - public static final String XPATH_STATIC_DATA_NODE = "art:data"; - - public static final String XPATH_STATIC_ITEM_NODE = "art:item"; - - public static final String XPATH_RECOMMENDED_ARTIFACTS = - "/art:result/art:recommended-artifacts//*[@factory]"; - - /** - * This method creates the {@link ArtifactDescription} of the DESCRIBE - * document <i>doc</i>. - * - * @param doc A DESCRIBE document. - * - * @return the {@link ArtifactDescription}. - */ - public static ArtifactDescription createArtifactDescription(Document doc) { - logger.debug("ArtifactDescriptionFactory.createArtifactDescription"); - - Node currentState = ClientProtocolUtils.getCurrentState(doc); - Node staticNode = ClientProtocolUtils.getStaticUI(doc); - Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc); - Node reachable = ClientProtocolUtils.getReachableStates(doc); - NodeList outputs = ClientProtocolUtils.getOutputModes(doc); - - String state = (String) XMLUtils.xpath( - currentState, - XPATH_STATE_NAME, - XPathConstants.STRING, - ArtifactNamespaceContext.INSTANCE); - - logger.debug("Current state name: " + state); - - DataList currentData = extractCurrentData(dynamicNode, state); - DataList[] old = extractOldData(staticNode); - String[] states = extractReachableStates(reachable); - OutputMode[] outs = extractOutputModes(outputs); - Recommendation[] rec = extractRecommendedArtifacts(doc); - - return new DefaultArtifactDescription( - old, - currentData, - state, - states, - outs, - rec); - } - - - /** - * This method extracts the data that the user is able to enter in the - * current state of the artifact. - * - * @param dynamicNode The dynamic node of the DESCRIBE document. - * @param state The name of the current state. - * - * @return A {@link Data} object that represents the data which might be - * entered by the user in the current state or null, if no data might be - * entered. - */ - protected static DataList extractCurrentData(Node dynamicNode, String state) { - logger.debug("ArtifactDescriptionFactory.extractCurrentData"); - - NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode); - String help = extractHelpText(dynamicNode); - String uiProvider = extractUIProvider(dynamicNode); - - if (data == null || data.getLength() == 0) { - return null; - } - - int dataNum = data.getLength(); - DataList list = new DataList(state, dataNum, uiProvider, null, help); - - for (int i = 0; i < dataNum; i++) { - Element d = (Element) data.item(i); - String label = ClientProtocolUtils.getLabel(d); - String name = XMLUtils.xpathString( - d, "@art:name", ArtifactNamespaceContext.INSTANCE); - String type = XMLUtils.xpathString( - d, "@art:type", ArtifactNamespaceContext.INSTANCE); - - logger.debug("Create new IntegerRangeData object for: " + name); - logger.debug("New Data is from type: " + type); - - // TODO replace with DataFactory. - - if (type == null || type.length() == 0) { - NodeList choices = ClientProtocolUtils.getItemNodes(d); - DataItem[] dataItems = extractCurrentDataItems(choices); - DataItem def = extractDefaultDataItem(d); - - list.add(new DefaultData(name, label, null, dataItems, def)); - } - else if (type.equals("intrange")) { - String min = ClientProtocolUtils.getMinNode(d); - String max = ClientProtocolUtils.getMaxNode(d); - - String defMin = ClientProtocolUtils.getDefMin(d); - String defMax = ClientProtocolUtils.getDefMax(d); - - try { - int lower = Integer.parseInt(min); - int upper = Integer.parseInt(max); - - if (defMin != null && defMax != null) { - list.add(new IntegerRangeData( - name, label, - lower, upper, - Integer.parseInt(defMin), - Integer.parseInt(defMax))); - } - else { - list.add( - new IntegerRangeData(name, label, lower, upper)); - } - } - catch (NumberFormatException nfe) { - logger.warn("NumberFormatException: ", nfe); - } - } - else if (type.equals("longrange")) { - String min = ClientProtocolUtils.getMinNode(d); - String max = ClientProtocolUtils.getMaxNode(d); - - String defMin = ClientProtocolUtils.getDefMin(d); - String defMax = ClientProtocolUtils.getDefMax(d); - - try { - long lower = Long.valueOf(min); - long upper = Long.valueOf(max); - - if (defMin != null && defMax != null) { - list.add(new LongRangeData( - name, label, - lower, upper, - Long.valueOf(defMin), - Long.valueOf(defMax))); - } - } - catch (NumberFormatException nfe) { - logger.warn("NumberFormatException: ", nfe); - } - } - else if (type.equals("intarray")) { - list.add(new IntegerArrayData(name, label, null)); - } - else if (type.equals("intoptions") && uiProvider.equals("parameter-matrix")) { - list.add(DataFactory.createIntegerOptionsData(d, name, label)); - } - else if (type.equals("options")) { - list.add(DataFactory.createStringOptionsData(d, name, label)); - } - else if (type.equals("intoptions")) { - NodeList choices = ClientProtocolUtils.getItemNodes(d); - DataItem[] opts = extractCurrentDataItems(choices); - - list.add(new IntegerOptionsData(name, label, opts)); - } - else if (type.equals("doublearray")) { - list.add(new DoubleArrayData(name, label, null)); - } - else { - logger.warn("Unrecognized Dynamic data type."); - NodeList choices = ClientProtocolUtils.getItemNodes(d); - DataItem[] dataItems = extractCurrentDataItems(choices); - DataItem def = extractDefaultDataItem(d); - - String min = ClientProtocolUtils.getMinNode(d); - String max = ClientProtocolUtils.getMaxNode(d); - if (min != null && max != null) { - list.add(new DoubleRangeData( - name, label, - Double.valueOf(min), Double.valueOf(max), - Double.valueOf(min), Double.valueOf(max))); - } - - list.add(new DefaultData(name, label, null, dataItems, def)); - } - - } - - return list; - } - - - /** - * This method extracts the default value of a Data object. - * - * @param data The data object node. - * - * @return the default DataItem. - */ - protected static DataItem extractDefaultDataItem(Node data) { - logger.debug("ArtifactDescriptionFactory.extractDefaultDataItem"); - - String value = XMLUtils.xpathString( - data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE); - - String label = XMLUtils.xpathString( - data, "@art:defaultLabel", ArtifactNamespaceContext.INSTANCE); - - if (value != null && label != null) { - return new DefaultDataItem(label, null, value); - } - - return null; - } - - - /** - * This method extract the {@link DataItem}s of the DESCRIBE document. - * - * @param items The items in the DESCRIBE document. - * - * @return the {@link DataItem}s. - */ - protected static DataItem[] extractCurrentDataItems(NodeList items) { - logger.debug("ArtifactDescriptionFactory.extractCurrentDataItems"); - - if (items == null || items.getLength() == 0) { - logger.debug("No data items found."); - return null; - } - - int count = items.getLength(); - - List<DataItem> dataItems = new ArrayList<DataItem>(count); - - for (int i = 0; i < count; i++) { - Node item = items.item(i); - String label = ClientProtocolUtils.getLabel(item); - String value = ClientProtocolUtils.getValue(item); - - double[] mmQ = extractMinMaxQValues(item); - double[] mmW = extractMinMaxWValues(item); - - if (mmQ != null || mmW != null) { - dataItems.add(new WQDataItem(label, null, value, mmQ, mmW)); - } - else { - dataItems.add(new DefaultDataItem(label, null, value)); - } - } - - return dataItems.toArray(new DataItem[count]); - } - - - protected static double[] extractMinMaxQValues(Node item) { - logger.debug("ArtifactDescriptionFactory.extractMinMaxQValues"); - - if (item == null) { - logger.debug("This node is empty - no min/max Q values."); - return null; - } - - Node node = (Node) XMLUtils.xpath( - item, - "art:range[@art:type='Q']", - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE); - - if (node == null) { - logger.debug("No min/max Q values found."); - return null; - } - - return extractMinMaxValues(node); - } - - - protected static double[] extractMinMaxWValues(Node item) { - logger.debug("ArtifactDescriptionFactory.extractMinMaxWValues"); - - if (item == null) { - logger.debug("This node is empty - no min/max W values."); - return null; - } - - Node node = (Node) XMLUtils.xpath( - item, - "art:range[@art:type='W']", - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE); - - if (node == null) { - logger.debug("No min/max W values found."); - return null; - } - - return extractMinMaxValues(node); - } - - - protected static double[] extractMinMaxValues(Node node) { - logger.debug("ArtifactDescriptionFactory.extractMinMaxValues"); - - String minStr = XMLUtils.xpathString( - node, "art:min/text()", ArtifactNamespaceContext.INSTANCE); - - String maxStr = XMLUtils.xpathString( - node, "art:max/text()", ArtifactNamespaceContext.INSTANCE); - - if (maxStr == null || minStr == null) { - logger.debug("No min/max values found."); - return null; - } - - try { - double min = Double.valueOf(minStr); - double max = Double.valueOf(maxStr); - - return new double[] { min, max }; - } - catch (NumberFormatException nfe) { - logger.debug("Error while parsing min/max values."); - } - - return null; - } - - - /** - * This method extracts the data objects from the data node of the static ui - * part of the DESCRIBE document. - * - * @param staticNode The static ui node of the DESCRIBE. - * - * @return the DataList objects. - */ - protected static DataList[] extractOldData(Node staticNode) { - logger.debug("ArtifactDescriptionFactory.extractOldData()"); - - NodeList stateNodes = (NodeList) XMLUtils.xpath( - staticNode, - XPATH_STATIC_STATE_NODE, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (stateNodes == null || stateNodes.getLength() == 0) { - logger.debug("No old items found."); - return null; - } - - int count = stateNodes.getLength(); - DataList[] data = new DataList[count]; - - for (int i = 0; i < count; i++) { - Node tmp = stateNodes.item(i); - - String name = XMLUtils.xpathString( - tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); - String uiprovider = XMLUtils.xpathString( - tmp, "@art:uiprovider", ArtifactNamespaceContext.INSTANCE); - String label = XMLUtils.xpathString( - tmp, "@art:label", ArtifactNamespaceContext.INSTANCE); - String help = XMLUtils.xpathString( - tmp, "@art:helpText", ArtifactNamespaceContext.INSTANCE); - - NodeList dataNodes = (NodeList) XMLUtils.xpath( - tmp, - XPATH_STATIC_DATA_NODE, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (dataNodes == null || dataNodes.getLength() == 0) { - continue; - } - - int size = dataNodes.getLength(); - DataList list = new DataList(name, size, uiprovider, label, help); - - for (int j = 0; j < size; j++) { - Node dataNode = dataNodes.item(j); - - list.add(DataFactory.createDataFromElement((Element) dataNode)); - - data[i] = list; - } - } - - return data; - } - - - /** - * This method extracts the UIProvider specified by the data node. - * - * @param data The data node. - * - * @return the UIProvider that is specified in the data node. - */ - protected static String extractUIProvider(Node ui) { - return (String) XMLUtils.xpath( - ui, - XPATH_UIPROVIDER, - XPathConstants.STRING, - ArtifactNamespaceContext.INSTANCE); - } - - - /** - * This method extracts the help text specified by the data node. - * - * @param ui The data node. - * - * @return the help text. - */ - protected static String extractHelpText(Node ui) { - return (String) XMLUtils.xpath( - ui, - XPATH_HELP_TEXT, - XPathConstants.STRING, - ArtifactNamespaceContext.INSTANCE); - } - - - /** - * This method extracts the reachable states of the current artifact. - * - * @param reachable The reachable states node. - * - * @return an array with identifiers of reachable states. - */ - protected static String[] extractReachableStates(Node reachable) { - logger.debug("ArtifactDescriptionFactory.extractReachableStates()"); - - NodeList list = (NodeList) XMLUtils.xpath( - reachable, - XPATH_REACHABLE_STATE, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (list == null || list.getLength() == 0) { - return null; - } - - int count = list.getLength(); - - String[] states = new String[count]; - - for (int i = 0; i < count; i++) { - Node state = list.item(i); - - String name = XMLUtils.xpathString( - state, "@art:name", ArtifactNamespaceContext.INSTANCE); - - states[i] = name; - } - - return states; - } - - - /** - * This method extract available output modes of the the current artifact. - * - * @param outputs A list of nodes that contain information about output - * modes. - * - * @return an array of Output modes. - */ - protected static OutputMode[] extractOutputModes(NodeList outputs) { - logger.debug("ArtifactDescriptionFactory.extractOutputModes"); - - if (outputs == null || outputs.getLength() == 0) { - return null; - } - - int size = outputs.getLength(); - - List<OutputMode> outs = new ArrayList<OutputMode>(size); - - for (int i = 0; i < size; i++) { - Node out = outputs.item(i); - - String name = XMLUtils.xpathString( - out, "@art:name", ArtifactNamespaceContext.INSTANCE); - String desc = XMLUtils.xpathString( - out, "@art:description", ArtifactNamespaceContext.INSTANCE); - String mimeType = XMLUtils.xpathString( - out, "@art:mime-type", ArtifactNamespaceContext.INSTANCE); - - if (name != null) { - outs.add(new DefaultOutputMode(name, desc, mimeType)); - } - else { - logger.debug("Found an invalid output mode."); - } - } - - return (OutputMode[]) outs.toArray(new OutputMode[size]); - } - - - protected static Recommendation[] extractRecommendedArtifacts(Document doc){ - logger.debug("ArtifactDescriptionFactory.extractRecommendedArtifacts."); - - NodeList list = (NodeList) XMLUtils.xpath( - doc, - XPATH_RECOMMENDED_ARTIFACTS, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = list != null ? list.getLength() : 0; - - Recommendation[] rec = new Recommendation[num]; - - for (int i = 0; i < num; i++) { - Element e = (Element) list.item(i); - String factory = e.getAttribute("factory"); - String index = e.getAttribute("ids"); - - if (factory != null && factory.length() > 0) { - rec[i] = new Recommendation(factory, index); - } - } - - return rec; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,196 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.CreationFilter; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.utils.ArtifactNamespaceContext; -import de.intevation.artifacts.httpclient.utils.XMLUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; - -import de.intevation.flys.client.shared.model.Recommendation; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ArtifactHelper { - - private static final Logger logger = Logger.getLogger(ArtifactHelper.class); - - - /** The error message key that is thrown if an error occured while artifact - * creation.*/ - public static final String ERROR_CREATE_ARTIFACT = "error_create_artifact"; - - /** - * Name of the factory to generate a GaugeDischargeCurveArtifact - */ - private static final String GAUGE_DISCHARGE_CURVE_ARTIFACT = "gaugedischargecurve"; - private static final String SQ_RELATION_ARTIFACT = "staticsqrelation"; - - private ArtifactHelper() { - } - - - /** - * @param factory ArtifactFactory to use. - */ - public static Artifact createArtifact( - String serverUrl, - String locale, - String factory, - Recommendation recommendation) - throws ServerException - { - logger.debug("ArtifactHelper.create"); - - String uuid; - String ids; - CreationFilter filter; - - if (recommendation != null) { - uuid = recommendation.getMasterArtifact(); - ids = recommendation.getIDs(); - filter = convertFilter(recommendation.getFilter()); - } - else { - uuid = null; - ids = null; - filter = null; - } - - Document create = ClientProtocolUtils.newCreateDocument( - factory, uuid, ids, filter); - - return sendCreate(serverUrl, locale, create); - - } - - /** - * Creates a new GaugeDischargeCurverArtifact - * - * @param river the name of the river - * @param reference the reference id of the gauge (official number) - */ - public static Artifact createGaugeDischargeCurveArtifact( - String serverUrl, - String locale, - String river, - Long reference) - throws ServerException - { - Document create = ClientProtocolUtils.newCreateDocument( - GAUGE_DISCHARGE_CURVE_ARTIFACT); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - create, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element root = create.getDocumentElement(); - - Element eriver = ec.create("river"); - ec.addAttr(eriver, "name", river); - - Element egauge = ec.create("gauge"); - ec.addAttr(egauge, "reference", reference.toString()); - - root.appendChild(eriver); - root.appendChild(egauge); - - return sendCreate(serverUrl, locale, create); - } - - /** - * Sends a create document to the artifact server - */ - private static Artifact sendCreate( - String serverUrl, - String locale, - Document doc) - throws ServerException - { - HttpClient client = new HttpClientImpl(serverUrl, locale); - - try { - return (Artifact) client.create(doc, new FLYSArtifactCreator()); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_CREATE_ARTIFACT); - } - - - /** - * Create CreationFilter from Recommendation.Filter. - */ - public static CreationFilter convertFilter(Recommendation.Filter filter) { - - if (filter == null) { - return null; - } - - CreationFilter cf = new CreationFilter(); - - Map<String, List<Recommendation.Facet>> outs = filter.getOuts(); - - for (Map.Entry<String, List<Recommendation.Facet>> entry: - outs.entrySet()) { - List<Recommendation.Facet> rfs = entry.getValue(); - List<CreationFilter.Facet> cfs = - new ArrayList<CreationFilter.Facet>(rfs.size()); - for (Recommendation.Facet rf: rfs) { - cfs.add(new CreationFilter.Facet(rf.getName(), rf.getIndex())); - } - cf.add(entry.getKey(), cfs); - } - - return cf; - } - - - public static Artifact createSQRelationArtifact( - String serverUrl, - String locale, - String river, - int measurementStation) - throws ServerException - { - Document create = ClientProtocolUtils.newCreateDocument( - SQ_RELATION_ARTIFACT); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - create, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element root = create.getDocumentElement(); - - Element eriver = ec.create("river"); - ec.addAttr(eriver, "name", river); - - Element estation = ec.create("measurement_station"); - ec.addAttr(estation, "number", String.valueOf(measurementStation)); - - root.appendChild(eriver); - root.appendChild(estation); - - return sendCreate(serverUrl, locale, create); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -package de.intevation.flys.client.server; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.client.services.ArtifactService; - -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Recommendation; - -/** - * This interface provides artifact specific services as CREATE, DESCRIBE, FEED, - * ADVANCE and OUT. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ArtifactServiceImpl -extends RemoteServiceServlet -implements ArtifactService -{ - /** Private logger. */ - private static final Logger logger = - Logger.getLogger(ArtifactServiceImpl.class); - - - /** - * Creates new Artifacts based on a given Recommendation and factory. - * <b>Note, that all the work is done in ArtifactHelper!</b> - * - * @param locale The locale used for HTTP request. - * @param factory The factory that is used to create the new Artifact. - * @param recom Recommendation with details of the artifact to create. - * - * @return a new Artifact. - */ - public Artifact create( - String locale, - String factory, - Recommendation recom - ) - throws ServerException - { - logger.info("ArtifactServiceImpl.create"); - - String url = getServletContext().getInitParameter("server-url"); - - return ArtifactHelper.createArtifact(url, locale, factory, recom); - } - - /** - * Create a new GaugeDischageCurveArtifact - * - * @param river the river - * @param gaugeref reference id of the gauge - */ - public Artifact createGaugeDischargeCurveArtifact( - Collection collection, - String locale, - String river, - Long gaugeref) - throws ServerException - { - logger.info("ArtifactServiceImpl.createGaugeDischargeCurverArtifact"); - String url = getServletContext().getInitParameter("server-url"); - - Artifact artifact = ArtifactHelper.createGaugeDischargeCurveArtifact(url, - locale, river, gaugeref); - if (artifact == null) { - return null; - } - logger.info("GaugeDischargeCurveArtifact created successfully"); - - CollectionHelper.addArtifact(collection, artifact, url, locale); - - return artifact; - } - - @Override - public Artifact createSQRelationArtifact( - Collection collection, - String locale, - String river, - int measurementStation) - throws ServerException - { - logger.info("ArtifactServiceImpl.createSQRelationArtifact"); - String url = getServletContext().getInitParameter("server-url"); - - Artifact artifact = ArtifactHelper.createSQRelationArtifact(url, - locale, river, measurementStation); - if (artifact == null) { - return null; - } - logger.info("SQRelationArtifact created successfully"); - - CollectionHelper.addArtifact(collection, artifact, url, locale); - - return artifact; - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/BaseServletContextListener.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.IOException; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.server.LoggingConfigurator; -import de.intevation.flys.client.server.features.Features; -import de.intevation.flys.client.server.features.XMLFileFeatures; - -/** - * ServletContextListenter to initalize the Features globally for - * all Servlets - */ -public class BaseServletContextListener implements ServletContextListener { - - public static final String LOG4J_PROPERTIES = "FLYS_CLIENT_LOG4J_PROPERIES"; - - public static final Logger logger = Logger.getLogger(BaseServletContextListener.class); - - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext sc = sce.getServletContext(); - - this.initLogging(sc); - - String filename = sc.getInitParameter("features-file"); - - logger.debug("Initializing ServletContext"); - try { - XMLFileFeatures features = new XMLFileFeatures(sc.getRealPath(filename)); - sc.setAttribute(Features.CONTEXT_ATTRIBUTE, features); - } catch(IOException e) { - logger.error(e); - } - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - //DO NOTHING - } - - - private void initLogging(ServletContext sc) { - String log4jProperties = System.getenv(LOG4J_PROPERTIES); - - if (log4jProperties == null || log4jProperties.length() == 0) { - String file = sc.getInitParameter("log4j-properties"); - - if (file != null && file.length() > 0) { - log4jProperties = sc.getRealPath(file); - } - } - System.out.println(log4jProperties); - - LoggingConfigurator.init(log4jProperties); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/BedKMChartServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; - -public class BedKMChartServiceImpl extends HttpServlet { - private static final Logger log = - Logger.getLogger(FixingsKMChartServiceImpl.class); - - public static final String SERVICE_NAME = "bed-km-chart"; - - public BedKMChartServiceImpl() { - } - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - - log.info("BedKMChartServiceImpl.doGet"); - - String url = getServletContext().getInitParameter("server-url"); - String locale = req.getParameter("locale"); - String filter = req.getParameter("filter"); - - if (filter == null || filter.length() == 0) { - log.warn("Missing 'filter' parameter."); - return; - } - - if (locale == null || locale.length() == 0) { - locale = "de"; - } - - Document filterDoc = XMLUtils.jsonToXML(filter); - - if (filterDoc == null) { - log.warn("Creating filter document failed."); - return; - } - - InputStream in; - - try { - HttpClient client = new HttpClientImpl(url, locale); - in = (InputStream)client.callService( - url, // XXX: Why? The URL is passed by construction already. - SERVICE_NAME, - filterDoc, - new StreamResponseHandler()); - } - catch (ConnectionException ce) { - log.error(ce); - return; - } - - resp.setHeader("Content-Type", guessMIMEType(filterDoc)); - - try { - OutputStream out = resp.getOutputStream(); - - byte [] buf = new byte[4096]; - int i = -1; - while ((i = in.read(buf)) >= 0) { - out.write(buf, 0, i); - } - out.flush(); - } - catch (IOException ioe) { - log.error(ioe); - } - finally { - try { in.close(); } - catch (IOException ioe) { /* ignored */ } - } - } - - protected static String guessMIMEType(Document document) { - - NodeList formats = document.getElementsByTagName("format"); - - String format = "png"; - - if (formats.getLength() > 0) { - String type = ((Element)formats.item(0)).getAttribute("type"); - if (type.length() > 0) { - format = type; - } - } - - return "image/" + format; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/BedloadKMChartServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; - -public class BedloadKMChartServiceImpl extends HttpServlet { - private static final Logger log = - Logger.getLogger(FixingsKMChartServiceImpl.class); - - public static final String SERVICE_NAME = "bedload-km-chart"; - - public BedloadKMChartServiceImpl() { - } - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - - log.info("BedloadKMChartServiceImpl.doGet"); - - String url = getServletContext().getInitParameter("server-url"); - String locale = req.getParameter("locale"); - String filter = req.getParameter("filter"); - - if (filter == null || filter.length() == 0) { - log.warn("Missing 'filter' parameter."); - return; - } - - if (locale == null || locale.length() == 0) { - locale = "de"; - } - - Document filterDoc = XMLUtils.jsonToXML(filter); - - if (filterDoc == null) { - log.warn("Creating filter document failed."); - return; - } - - InputStream in; - - try { - HttpClient client = new HttpClientImpl(url, locale); - in = (InputStream)client.callService( - url, // XXX: Why? The URL is passed by construction already. - SERVICE_NAME, - filterDoc, - new StreamResponseHandler()); - } - catch (ConnectionException ce) { - log.error(ce); - return; - } - - resp.setHeader("Content-Type", guessMIMEType(filterDoc)); - - try { - OutputStream out = resp.getOutputStream(); - - byte [] buf = new byte[4096]; - int i = -1; - while ((i = in.read(buf)) >= 0) { - out.write(buf, 0, i); - } - out.flush(); - } - catch (IOException ioe) { - log.error(ioe); - } - finally { - try { in.close(); } - catch (IOException ioe) { /* ignored */ } - } - } - - protected static String guessMIMEType(Document document) { - - NodeList formats = document.getElementsByTagName("format"); - - String format = "png"; - - if (formats.getLength() > 0) { - String type = ((Element)formats.item(0)).getAttribute("type"); - if (type.length() > 0) { - format = type; - } - } - - return "image/" + format; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CSVExportServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import java.io.Reader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import au.com.bytecode.opencsv.CSVReader; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.CSVExportService; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class CSVExportServiceImpl -extends RemoteServiceServlet -implements CSVExportService -{ - private static final Logger logger = - Logger.getLogger(CSVExportServiceImpl.class); - - - public static final String ERROR_NO_EXPORT_FOUND = - "error_no_export_found"; - - public List<String[]> getCSV( - String locale, - String uuid, - String name) - throws ServerException - { - logger.info("CSVExportServiceImpl.getCSV"); - - String url = getServletContext().getInitParameter("server-url"); - - Document requestDoc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - requestDoc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element action = ec.create("action"); - ec.addAttr(action, "type", "csv", true); - ec.addAttr(action, "name", name, true); - - requestDoc.appendChild(action); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - InputStream in = client.collectionOut(requestDoc, uuid, "export"); - Reader reader = new InputStreamReader (in, "UTF-8"); - CSVReader csvReader = new CSVReader (reader); - - List<String[]> lines = new ArrayList<String[]>(); - String[] line = null; - - while ((line = csvReader.readNext()) != null) { - if (line != null) { - if (!line[0].startsWith("#") && line.length > 0) { - if (line[0].replace("'", "").length() > 0) { - lines.add(line); - } - } - } - } - - return lines; - } - catch (IOException ce) { - logger.error(ce.getLocalizedMessage()); - } - - throw new ServerException(ERROR_NO_EXPORT_FOUND); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CapabilitiesParser.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,401 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Capabilities; -import de.intevation.flys.client.shared.model.ContactInformation; -import de.intevation.flys.client.shared.model.WMSLayer; - - -public class CapabilitiesParser { - - private static final Logger logger = - Logger.getLogger(CapabilitiesParser.class); - - - public static final String ERR_GC_REQUEST_FAILED = - "error_gc_req_failed"; - - public static final String ERR_GC_DOC_NOT_VALID = - "error_gc_doc_not_valid"; - - public static final String ERR_MALFORMED_URL = - "error_malformed_url"; - - - public static final String XPATH_WMS_CAPS = - "/WMS_Capabilities"; - - public static final String XPATH_WMT_CAPS = - "/WMT_MS_Capabilities"; - - public static final String XPATH_TITLE = - "Service/Title/text()"; - - public static final String XPATH_ONLINE_RESOURCE = - "Service/OnlineResource/@href"; - - public static final String XPATH_CONTACT_INFORMATION = - "Service/ContactInformation"; - - public static final String XPATH_CI_PERSON = - "ContactPersonPrimary/ContactPerson/text()"; - - public static final String XPATH_CI_ORGANIZATION = - "ContactPersonPrimary/ContactOrganization/text()"; - - public static final String XPATH_CI_ADDRESS = - "ContactAddress/Address/text()"; - - public static final String XPATH_CI_CITY = - "ContactAddress/City/text()"; - - public static final String XPATH_CI_POSTCODE = - "ContactAddress/PostCode/text()"; - - public static final String XPATH_CI_PHONE = - "ContactVoiceTelephone/text()"; - - public static final String XPATH_CI_EMAIL = - "ContactElectronicMailAddress/text()"; - - public static final String XPATH_FEES = - "Service/Fees/text()"; - - public static final String XPATH_ACCESS_CONSTRAINTS = - "Service/AccessConstraints/text()"; - - public static final String XPATH_LAYERS = - "Capability/Layer"; - - public static final Pattern SRS_PATTERN = Pattern.compile("(EPSG:\\d+)*"); - - - private CapabilitiesParser() { - } - - - public static void main(String[] args) { - logger.info("Do static Capabilities request/parsing."); - - String log4jProperties = System.getenv(BaseServletContextListener.LOG4J_PROPERTIES); - LoggingConfigurator.init(log4jProperties); - - try { - Capabilities caps = getCapabilities(System.getProperty("test.wms")); - - logger.debug(caps.toString()); - } - catch (ServerException se) { - se.printStackTrace(); - } - - logger.info("Finished fetching capabiltiies."); - } - - - public static Capabilities getCapabilities(String urlStr) - throws ServerException - { - try { - URL url = new URL(urlStr); - - logger.debug("Open connection to url: " + urlStr); - - URLConnection conn = url.openConnection(); - conn.connect(); - - InputStream is = conn.getInputStream(); - - return parse(is); - } - catch (MalformedURLException mue) { - logger.warn(mue, mue); - throw new ServerException(ERR_MALFORMED_URL); - } - catch (IOException ioe) { - logger.warn(ioe, ioe); - } - - throw new ServerException(ERR_GC_REQUEST_FAILED); - } - - - protected static Capabilities parse(InputStream is) - throws ServerException - { - logger.debug("GCServiceImpl.parseCapabilitiesResponse"); - - Document doc = XMLUtils.parseDocument(is, false); - - if (doc == null) { - throw new ServerException(ERR_GC_DOC_NOT_VALID); - } - - return CapabilitiesParser.parse(doc); - } - - - public static Capabilities parse(Document doc) - throws ServerException - { - Node capabilities = getCapabilitiesNode(doc); - - String title = (String) XMLUtils.xpath( - capabilities, - XPATH_TITLE, - XPathConstants.STRING); - - String onlineResource = (String) XMLUtils.xpath( - capabilities, - XPATH_ONLINE_RESOURCE, - XPathConstants.STRING); - - String fees = (String) XMLUtils.xpath( - capabilities, - XPATH_FEES, - XPathConstants.STRING); - - String accessConstraints = (String) XMLUtils.xpath( - capabilities, - XPATH_ACCESS_CONSTRAINTS, - XPathConstants.STRING); - - Node contactInformation = (Node) XMLUtils.xpath( - capabilities, - XPATH_CONTACT_INFORMATION, - XPathConstants.NODE); - - ContactInformation ci = parseContactInformation(contactInformation); - - logger.debug("Found fees: " + fees); - logger.debug("Found access constraints: " + accessConstraints); - - NodeList layerNodes = (NodeList) XMLUtils.xpath( - capabilities, - XPATH_LAYERS, - XPathConstants.NODESET); - - List<WMSLayer> layers = parseLayers(layerNodes, onlineResource); - - return new Capabilities( - title, - onlineResource, - ci, - fees, - accessConstraints, - layers); - } - - - protected static Node getCapabilitiesNode(Document doc) - throws ServerException { - Node capabilities = (Node) XMLUtils.xpath( - doc, - XPATH_WMS_CAPS, - XPathConstants.NODE); - - if (capabilities == null) { - logger.info("No '/WMS_Capabilities' node found."); - logger.info("Try to find a '/WMT_MS_Capabilities' node."); - - capabilities = (Node) XMLUtils.xpath( - doc, - XPATH_WMT_CAPS, - XPathConstants.NODE); - } - - if (capabilities == null) { - throw new ServerException(ERR_GC_DOC_NOT_VALID); - } - - return capabilities; - } - - - protected static ContactInformation parseContactInformation(Node node) { - String person = (String) XMLUtils.xpath( - node, - XPATH_CI_PERSON, - XPathConstants.STRING); - - String organization = (String) XMLUtils.xpath( - node, - XPATH_CI_ORGANIZATION, - XPathConstants.STRING); - - String address = (String) XMLUtils.xpath( - node, - XPATH_CI_ADDRESS, - XPathConstants.STRING); - - String postcode = (String) XMLUtils.xpath( - node, - XPATH_CI_POSTCODE, - XPathConstants.STRING); - - String city = (String) XMLUtils.xpath( - node, - XPATH_CI_CITY, - XPathConstants.STRING); - - String phone = (String) XMLUtils.xpath( - node, - XPATH_CI_PHONE, - XPathConstants.STRING); - - String email = (String) XMLUtils.xpath( - node, - XPATH_CI_EMAIL, - XPathConstants.STRING); - - ContactInformation ci = new ContactInformation(); - ci.setPerson(person); - ci.setOrganization(organization); - ci.setAddress(address); - ci.setPostcode(postcode); - ci.setCity(city); - ci.setPhone(phone); - ci.setEmail(email); - - return ci; - } - - - /** - * @param layersNode - * @param onlineResource - * - * @return - */ - protected static List<WMSLayer> parseLayers( - NodeList layersNode, - String onlineResource - ) { - int len = layersNode != null ? layersNode.getLength() : 0; - - logger.debug("Node has " + len + " layers."); - - List<WMSLayer> layers = new ArrayList<WMSLayer>(len); - - for (int i = 0; i < len; i++) { - layers.add(parseLayer(layersNode.item(i), onlineResource)); - } - - return layers; - } - - - protected static WMSLayer parseLayer(Node layerNode, String onlineResource) { - String title = (String) XMLUtils.xpath( - layerNode, - "Title/text()", - XPathConstants.STRING); - - String name = (String) XMLUtils.xpath( - layerNode, - "Name/text()", - XPathConstants.STRING); - - logger.debug("Found layer: " + title + "(" + name + ")"); - - List<String> srs = parseSRS(layerNode); - - NodeList layersNodes = (NodeList) XMLUtils.xpath( - layerNode, - "Layer", - XPathConstants.NODESET); - - List<WMSLayer> layers = parseLayers(layersNodes, onlineResource); - - return new WMSLayer(onlineResource, title, name, srs, layers); - } - - - protected static List<String> parseSRS(Node layerNode) { - NodeList srsNodes = ((Element) layerNode).getElementsByTagName("SRS"); - - if (srsNodes.getLength() == 0) { - srsNodes = ((Element) layerNode).getElementsByTagName("CRS"); - - if (srsNodes.getLength() == 0) { - logger.debug("No explicit SRS for this layer specified."); - return null; - } - } - - List<String> allSRS = new ArrayList<String>(); - - for (int i = 0, n = srsNodes.getLength(); i < n; i++) { - List<String> srs = parseSRSItem(srsNodes.item(i).getTextContent()); - - if (srs != null && srs.size() > 0) { - allSRS.addAll(srs); - } - } - - return allSRS; - } - - - protected static List<String> parseSRSItem(String srsStr) { - if (srsStr == null || srsStr.length() == 0) { - return null; - } - - List<String> allSRS = new ArrayList<String>(); - - if (srsStr.indexOf(" ") <= 0) { - String srs = getSRSFromString(srsStr); - if (srs != null && srs.length() > 0) { - allSRS.add(srs); - } - - return allSRS; - } - - String[] splittedSrs = srsStr.split(" "); - - for (String singleSrs: splittedSrs) { - String srs = getSRSFromString(singleSrs); - if (srs != null && srs.length() > 0) { - allSRS.add(srs); - } - } - - return allSRS; - } - - - protected static String getSRSFromString(String singleSrs) { - Matcher m = SRS_PATTERN.matcher(singleSrs); - - if (m.matches()) { - logger.debug("Found SRS '" + m.group(1) + "'"); - return m.group(1); - } - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,283 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.Transform2D; -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Axis; -import de.intevation.flys.client.shared.model.DateAxis; -import de.intevation.flys.client.shared.model.NumberAxis; -import de.intevation.flys.client.shared.model.ChartInfo; -import de.intevation.flys.client.shared.model.Collection; - -import de.intevation.flys.client.client.services.ChartInfoService; - - -/** - * This service fetches a document that contains meta information for a specific - * chart. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ChartInfoServiceImpl -extends RemoteServiceServlet -implements ChartInfoService -{ - private static final Logger logger = - Logger.getLogger(ChartInfoServiceImpl.class); - - public static final String XPATH_TRANSFORM_MATRIX = - "/art:chartinfo/art:transformation-matrix/art:matrix"; - - public static final String XPATH_X_AXES = - "/art:chartinfo/art:axes/art:domain"; - - public static final String XPATH_Y_AXES = - "/art:chartinfo/art:axes/art:range"; - - public static final String EXCEPTION_STRING = "error_chart_info_service"; - - - public ChartInfo getChartInfo( - Collection collection, - String locale, - String type, - Map<String, String> attr) - throws ServerException - { - logger.info("ChartInfoServiceImpl.getChartInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document request = ClientProtocolUtils.newOutCollectionDocument( - collection.identifier(), - type, - type, - ChartServiceHelper.getChartAttributes(attr)); - - try { - HttpClient client = new HttpClientImpl(url, locale); - InputStream in = client.collectionOut( - request, - collection.identifier(), - type + "_chartinfo"); - - Document info = XMLUtils.parseDocument(in); - - return parseInfoDocument(info); - } - catch (IOException ioe) { - ioe.printStackTrace(); - } - catch (Exception e) { - e.printStackTrace(); - } - - logger.debug("Error while fetching chart info."); - - throw new ServerException(EXCEPTION_STRING); - } - - - /** - * Parse ChartInfo-Part of document, create Transforms and axes - * from it. - */ - protected ChartInfo parseInfoDocument(Document doc) { - Transform2D[] transformer = parseTransformationMatrix(doc); - Axis[] xAxes = parseXAxes(doc); - Axis[] yAxes = parseYAxes(doc); - - return new ChartInfo(xAxes, yAxes, transformer); - } - - - protected Axis[] parseXAxes(Document doc) { - logger.debug("ChartInfoServiceImpl.parseXAxes"); - - NodeList axes = (NodeList) XMLUtils.xpath( - doc, - XPATH_X_AXES, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - return parseAxes(axes); - } - - - protected Axis[] parseYAxes(Document doc) { - logger.debug("ChartInfoServiceImpl.parseYAxes"); - - NodeList axes = (NodeList) XMLUtils.xpath( - doc, - XPATH_Y_AXES, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - return parseAxes(axes); - } - - - protected Axis[] parseAxes(NodeList axes) { - logger.debug("ChartInfoServiceImpl.parseAxes"); - - int count = axes != null ? axes.getLength() : 0; - - logger.debug("Chart has " + count + " axes."); - - if (count == 0) { - return null; - } - - Axis[] result = new Axis[count]; - - String ns = ArtifactNamespaceContext.NAMESPACE_URI; - - for (int i = 0; i < count; i++) { - Element node = (Element) axes.item(i); - - String posStr = node.getAttributeNS(ns, "pos"); - String fromStr = node.getAttributeNS(ns, "from"); - String toStr = node.getAttributeNS(ns, "to"); - String minStr = node.getAttributeNS(ns, "min"); - String maxStr = node.getAttributeNS(ns, "max"); - String axisType = node.getAttributeNS(ns, "axistype"); - - try { - int pos = Integer.parseInt(posStr); - - if (pos >= result.length) { - // this should never happen - logger.debug("The axis is out of valid range: " + pos); - continue; - } - - if (axisType != null && axisType.equals(DateAxis.TYPE)) { - long from = Long.parseLong(fromStr); - long to = Long.parseLong(toStr); - long min = Long.parseLong(minStr); - long max = Long.parseLong(maxStr); - - if (logger.isDebugEnabled()) { - logger.debug("date axis from: " + new Date(from)); - logger.debug("date axis to : " + new Date(to)); - logger.debug("date axis min : " + new Date(min)); - logger.debug("date axis max : " + new Date(max)); - } - - result[pos] = new DateAxis(pos, from, to, min, max); - } - else { - double from = Double.parseDouble(fromStr); - double to = Double.parseDouble(toStr); - double min = Double.parseDouble(minStr); - double max = Double.parseDouble(maxStr); - - result[pos] = new NumberAxis(pos, from, to, min, max); - } - } - catch (NumberFormatException nfe) { - nfe.printStackTrace(); - } - } - - logger.debug("Parsed " + result.length + " axes"); - - return result; - } - - - /** - * Parses the chart info document and extract the Transform2D values. - * - * @param doc The chart info document. - * - * @return a Transform2D object to transfrom pixel coordinates into chart - * coordinates. - */ - protected Transform2D[] parseTransformationMatrix(Document doc) { - logger.debug("ChartInfoServiceImpl.parseTransformationMatrix"); - - NodeList matrix = (NodeList) XMLUtils.xpath( - doc, - XPATH_TRANSFORM_MATRIX, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = matrix != null ? matrix.getLength() : 0; - - List<Transform2D> transformer = new ArrayList<Transform2D>(num); - - for (int i = 0; i < num; i++) { - Transform2D t = createTransformer((Element) matrix.item(i)); - - if (t == null) { - logger.warn("Broken transformation matrix at pos: " + i); - continue; - } - - transformer.add(t); - } - - return transformer.toArray(new Transform2D[num]); - } - - - protected Transform2D createTransformer(Element matrix) { - String ns = ArtifactNamespaceContext.NAMESPACE_URI; - - String sx = matrix.getAttributeNS(ns, "sx"); - String sy = matrix.getAttributeNS(ns, "sy"); - String tx = matrix.getAttributeNS(ns, "tx"); - String ty = matrix.getAttributeNS(ns, "ty"); - String xType = matrix.getAttributeNS(ns, "xtype"); - String yType = matrix.getAttributeNS(ns, "ytype"); - - xType = xType == null || xType.length() == 0 ? "number" : xType; - yType = yType == null || yType.length() == 0 ? "number" : yType; - - if (sx != null && sy != null && tx != null && ty != null) { - try { - logger.debug("Create new Transform2D with x format: " + xType); - logger.debug("Create new Transform2D with y format: " + yType); - - return new Transform2D( - Double.parseDouble(sx), - Double.parseDouble(sy), - Double.parseDouble(tx), - Double.parseDouble(ty), - xType, yType); - } - catch (NumberFormatException nfe) { - logger.warn("Error while parsing matrix values."); - } - } - - logger.warn("No matrix values found."); - - return new Transform2D(1d, 1d, 0d, 0d); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.OutputStream; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - - -/** - * This service is used to request a chart from the artifact server. The - * response is directed directly to the output stream, so the image that is - * retrieved is displayed in the UI afterwards. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ChartOutputServiceImpl -extends HttpServlet -{ - private static final Logger logger = - Logger.getLogger(ChartOutputServiceImpl.class); - - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - logger.info("ChartOutputServiceImpl.doGet"); - - try { - OutputStream out = resp.getOutputStream(); - - String url = getServletContext().getInitParameter("server-url"); - - String uuid = req.getParameter("uuid"); - String type = req.getParameter("type"); - String locale = req.getParameter("locale"); - - prepareHeader(req, resp); - - Document request = ClientProtocolUtils.newOutCollectionDocument( - uuid, type, type, - ChartServiceHelper.getChartAttributes(prepareChartAttributes(req))); - - HttpClient client = new HttpClientImpl(url, locale); - client.collectionOut(request, uuid, "chart", out); - - out.close(); - out.flush(); - } - catch (IOException ioe) { - logger.error(ioe, ioe); - } - catch (Exception e) { - logger.error(e, e); - } - } - - - protected Map<String, String> prepareChartAttributes(HttpServletRequest req) { - Map<String, String> attr = new HashMap<String, String>(); - - Map params = req.getParameterMap(); - - attr.put("width", req.getParameter("width")); - attr.put("height", req.getParameter("height")); - attr.put("minx", req.getParameter("minx")); - attr.put("maxx", req.getParameter("maxx")); - attr.put("miny", req.getParameter("miny")); - attr.put("maxy", req.getParameter("maxy")); - attr.put("format", req.getParameter("format")); - attr.put("km", req.getParameter("currentKm")); - - if (logger.isDebugEnabled()) { - logger.debug("====== ZOOM VALUES ======="); - logger.debug(" min x: " + req.getParameter("minx")); - logger.debug(" max x: " + req.getParameter("maxx")); - logger.debug(" min y: " + req.getParameter("miny")); - logger.debug(" max y: " + req.getParameter("maxy")); - } - - return attr; - } - - - protected void prepareHeader( - HttpServletRequest req, - HttpServletResponse resp - ) { - String export = req.getParameter("export"); - - if (export != null && export.equals("true")) { - String format = req.getParameter("format"); - - if (format == null || format.length() == 0) { - format = "png"; - } - - String fn = "chart_export" + getFileExtension(format); - - resp.setHeader("Content-Disposition", "attachment;filename=" + fn); - resp.setHeader("Content-Type", getMimeType(format)); - } - } - - - protected String getFileExtension(String format) { - if (format.equals("png")) { - return ".png"; - } - else if (format.equals("pdf")) { - return ".pdf"; - } - else if (format.equals("svg")) { - return ".svg"; - } - else if (format.equals("csv")) { - return ".csv"; - } - - return ".png"; - } - - - protected String getMimeType(String format) { - if (format.equals("png")) { - return "image/png"; - } - else if (format.equals("pdf")) { - return "application/pdf"; - } - else if (format.equals("svg")) { - return "svg+xml"; - } - else if (format.equals("csv")) { - return "text/plain"; - } - - return "image/png"; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,217 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.Map; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ChartServiceHelper { - - private static final Logger logger = - Logger.getLogger(ChartServiceHelper.class); - - - /** The default chart width if no value is specified in the request.*/ - public static final int DEFAULT_CHART_WIDTH = 600; - - /** The default chart height if no value is specified in the request.*/ - public static final int DEFAULT_CHART_HEIGHT = 400; - - - private ChartServiceHelper() { - } - - /** - * This method returns a document which might contain parameters to adjust - * chart settings. The document is created using the information that are - * contained in the request object. - * - * @param req The request document. - * - * @return a document to adjust chart settings. - */ - protected static Document getChartAttributes(Map<String, String> req) { - logger.debug("ChartServiceHelper.getChartAttributes"); - - Document doc = XMLUtils.newDocument(); - - ElementCreator ec = new ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element attributes = ec.create("attributes"); - - appendChartSize(req, attributes, ec); - appendFormat(req, attributes, ec); - appendXRange(req, attributes, ec); - appendYRange(req, attributes, ec); - appendCurrentKm(req, attributes, ec); - - doc.appendChild(attributes); - - return doc; - } - - - /** - * This method extracts the size (width/height) of a chart from request - * object and append those values - if they exist - to the attribute - * document used to adjust chart settings. - * - * @param req The request object that might contain the chart size. - * @param attributes The attributes element used to adjust chart settings. - * @param ec The ElementCreator that might be used to create new Elements. - */ - protected static void appendChartSize( - Map<String, String> req, - Element attributes, - ElementCreator ec) - { - logger.debug("ChartServiceHelper.appendChartSize"); - - Element size = ec.create("size"); - - String width = req.get("width"); - String height = req.get("height"); - - if (width == null || height == null) { - width = String.valueOf(DEFAULT_CHART_WIDTH); - height = String.valueOf(DEFAULT_CHART_HEIGHT); - } - - ec.addAttr(size, "width", width, true); - ec.addAttr(size, "height", height, true); - - attributes.appendChild(size); - } - - - /** - * This method extracts the x range for the chart from request object and - * appends those range - if it exists - to the attribute document used to - * adjust the chart settings. - * - * @param req The request object that might contain the chart size. - * @param doc The attribute document used to adjust chart settings. - * @param ec The ElementCreator that might be used to create new Elements. - */ - protected static void appendXRange( - Map<String, String> req, - Element attributes, - ElementCreator ec) - { - logger.debug("ChartServiceHelper.appendXRange"); - - Element range = ec.create("xrange"); - - String from = req.get("minx"); - String to = req.get("maxx"); - - if (from != null && to != null) { - ec.addAttr(range, "from", from, true); - ec.addAttr(range, "to", to, true); - - attributes.appendChild(range); - } - } - - - /** - * This method extracts the x range for the chart from request object and - * appends those range - if it exists - to the attribute document used to - * adjust the chart settings. - * - * @param req The request object that might contain the chart size. - * @param doc The attribute document used to adjust chart settings. - * @param ec The ElementCreator that might be used to create new Elements. - */ - protected static void appendYRange( - Map<String, String> req, - Element attributes, - ElementCreator ec) - { - logger.debug("ChartServiceHelper.appendYRange"); - - Element range = ec.create("yrange"); - - String from = req.get("miny"); - String to = req.get("maxy"); - - if (from != null && to != null) { - ec.addAttr(range, "from", from, true); - ec.addAttr(range, "to", to, true); - - attributes.appendChild(range); - } - } - - - /** - * This method extracts the format string from request object and appends - * those format - if existing - to the attribute document used to adjust - * the chart settings. - * - * @param req The request object that might contain the chart format. - * @param doc The attribute document used to adjust chart settings. - * @param ec The ElementCreator that might be used to create new Elements. - */ - protected static void appendFormat( - Map<String, String> req, - Element attributes, - ElementCreator ec - - ) { - logger.debug("ChartServiceHelper.appendFormat"); - - String formatStr = req.get("format"); - if (formatStr == null || formatStr.length() == 0) { - return; - } - - Element format = ec.create("format"); - ec.addAttr(format, "value", formatStr, true); - - attributes.appendChild(format); - } - - - /** - * This method extracts the current km for the chart from request object and - * appends this km - if it exists - to the attribute document used to - * adjust the chart settings. - * - * @param req The request object that might contain the chart size. - * @param doc The attribute document used to adjust chart settings. - * @param ec The ElementCreator that might be used to create new Elements. - */ - protected static void appendCurrentKm( - Map<String, String> req, - Element attributes, - ElementCreator ec) - { - logger.debug("ChartServiceHelper.appendCurrentKm"); - - Element currentKm = ec.create("currentKm"); - - String km = req.get("km"); - - if (km != null) { - ec.addAttr(currentKm, "km", km, true); - - attributes.appendChild(currentKm); - } - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionAttributeServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - -import de.intevation.flys.client.client.services.CollectionAttributeService; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class CollectionAttributeServiceImpl -extends DescribeCollectionServiceImpl -implements CollectionAttributeService -{ - private static final Logger logger = - Logger.getLogger(CollectionAttributeServiceImpl.class); - - - public static final String ERROR_UPDATING_COLLECTION_ATTRIBUTE = - "error_update_collection_attribute"; - - - public Collection update(Collection collection, String locale) - throws ServerException - { - logger.info("CollectionAttributeServiceImpl.update"); - - String url = getServletContext().getInitParameter("server-url"); - - Document attribute = CollectionHelper.createAttribute(collection); - Document action = ClientProtocolUtils.newSetAttributeDocument( - collection.identifier(), - attribute); - - try { - HttpClient http = new HttpClientImpl(url, locale); - Document res = (Document) http.doCollectionAction( - action, - collection.identifier(), - new DocumentResponseHandler()); - - logger.debug("Collection attribute successfully set."); - - return describe(collection.identifier(), locale); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_UPDATING_COLLECTION_ATTRIBUTE); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1082 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.AttributedTheme; -import de.intevation.flys.client.shared.model.ChartMode; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItem; -import de.intevation.flys.client.shared.model.DefaultCollection; -import de.intevation.flys.client.shared.model.DefaultCollectionItem; -import de.intevation.flys.client.shared.model.DefaultFacet; -import de.intevation.flys.client.shared.model.ExportMode; -import de.intevation.flys.client.shared.model.Facet; -import de.intevation.flys.client.shared.model.MapMode; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.shared.model.OverviewMode; -import de.intevation.flys.client.shared.model.ReportMode; -import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.Theme; -import de.intevation.flys.client.shared.model.ThemeList; -import de.intevation.flys.client.shared.model.Settings; -import de.intevation.flys.client.shared.model.Property; -import de.intevation.flys.client.shared.model.PropertyGroup; -import de.intevation.flys.client.shared.model.PropertySetting; -import de.intevation.flys.client.shared.model.StringProperty; -import de.intevation.flys.client.shared.model.DoubleProperty; -import de.intevation.flys.client.shared.model.IntegerProperty; -import de.intevation.flys.client.shared.model.BooleanProperty; -import de.intevation.flys.client.shared.model.OutputSettings; - -//temporary - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class CollectionHelper { - - private static final Logger logger = - Logger.getLogger(CollectionHelper.class); - - public static final String ERROR_ADD_ARTIFACT = "error_add_artifact"; - - public static final String ERROR_REMOVE_ARTIFACT = "error_remove_artifact"; - - public static final String XPATH_FACETS = "art:facets/art:facet"; - - public static final String XPATH_LOADED_RECOMMENDATIONS = - "/art:artifact-collection/art:attribute/art:loaded-recommendations/art:recommendation"; - - - public static Document createAttribute(Collection collection) { - logger.debug("CollectionHelper.createAttribute"); - - Document doc = XMLUtils.newDocument(); - - ElementCreator cr = new ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element attr = cr.create("attribute"); - - doc.appendChild(attr); - - Map<String, OutputMode> tmpOuts = collection.getOutputModes(); - - Element outs = createOutputElements(cr, collection, tmpOuts); - Element recs = createRecommendationsElements(cr, collection); - - if (outs != null) { - attr.appendChild(outs); - } - - if (recs != null) { - attr.appendChild(recs); - } - - return doc; - } - - - /** - * Creates a whole block with art:output nodes. - * - * @param cr The ElementCreator used to create new elements. - * @param c The collection. - * @param modes The OutputModes that should be included. - * - * @return an element with output modes. - */ - protected static Element createOutputElements( - ElementCreator cr, - Collection c, - Map<String, OutputMode> mmodes) - { - logger.debug("CollectionHelper.createOutputElements"); - - java.util.Collection<OutputMode> modes = mmodes != null - ? mmodes.values() - : null; - - if (modes == null || modes.size() == 0) { - logger.debug("Collection has no modes: " + c.identifier()); - return null; - } - - Element outs = cr.create("outputs"); - - for (OutputMode mode: modes) { - Element out = createOutputElement(cr, c, mode); - - if (out != null) { - outs.appendChild(out); - } - } - - return outs; - } - - - /** - * Create a node art:output that further consist of art:theme nodes. - * - * @param cr The ElementCreator used to create new elements. - * @param c The collection. - * @param mode The OutputMode. - * - * @return an element that represents an output mode with its themes. - */ - protected static Element createOutputElement( - ElementCreator cr, - Collection collection, - OutputMode mode) - { - logger.debug("CollectionHelper.createOutputElement"); - - Element out = cr.create("output"); - cr.addAttr(out, "name", mode.getName(), false); - - ThemeList themeList = collection.getThemeList(mode.getName()); - List<Theme> themes = themeList != null ? themeList.getThemes() : null; - - if (themes == null || themes.size() == 0) { - logger.debug("No themes for output mode: " + mode.getName()); - return null; - } - - for (Theme theme: themes) { - Element t = createThemeElement(cr, collection, theme); - - if (t != null) { - out.appendChild(t); - } - } - - Document doc = out.getOwnerDocument(); - - ElementCreator settingscr = new ElementCreator(doc, "", ""); - - Settings settings = collection.getSettings(mode.getName()); - if (settings == null || - settings.getCategories().size() == 0) - { - logger.debug("No settings for output mode: " + mode.getName()); - } - else { - Element s = createSettingsElement(settingscr, collection, settings); - if (s != null) { - out.appendChild(s); - } - } - logger.info(XMLUtils.toString(out)); - return out; - } - - - /** - * Creates a theme node art:theme that represents a curve in a chart or map. - * - * @param cr The ElementCreator used to create new elements. - * @param collection The collection. - * @param theme The theme whose attributes should be written to an element. - * - * @return an element that contains the informtion of the given theme. - */ - protected static Element createThemeElement( - ElementCreator cr, - Collection collection, - Theme theme) - { - if (theme == null) { - return null; - } - - Element t = cr.create("facet"); - - if (theme instanceof AttributedTheme) { - AttributedTheme at = (AttributedTheme) theme; - Set<String> keys = at.getKeys(); - - for (String key: keys) { - cr.addAttr(t, key, at.getAttr(key), true); - } - } - else { - cr.addAttr(t, "active", Integer.toString(theme.getActive()), true); - cr.addAttr(t, "artifact", theme.getArtifact(), true); - cr.addAttr(t, "facet", theme.getFacet(), true); - cr.addAttr(t, "pos", Integer.toString(theme.getPosition()), true); - cr.addAttr(t, "index", Integer.toString(theme.getIndex()), true); - cr.addAttr(t, "description", theme.getDescription(), true); - cr.addAttr(t, "visible", Integer.toString(theme.getVisible()), true); - } - - return t; - } - - - /** - * Creates a whole block with art:loaded-recommendations nodes. - * - * @param cr The ElementCreator used to create new elements. - * @param c The collection. - * - * @return an element with loaded recommendations. - */ - protected static Element createRecommendationsElements( - ElementCreator cr, - Collection c) - { - logger.debug("CollectionHelper.createRecommendationsElements"); - - List<Recommendation> rs = c.getRecommendations(); - - if (rs == null || rs.size() == 0) { - logger.debug("Collection did not load recommendations: " + - c.identifier()); - return null; - } - - Element loaded = cr.create("loaded-recommendations"); - - for (Recommendation r: rs) { - Element recommendation = createRecommendationElement(cr, c, r); - - if (recommendation != null) { - loaded.appendChild(recommendation); - } - } - - return loaded; - } - - - /** - * Create a node art:recommended. - * - * @param cr The ElementCreator used to create new elements. - * @param c The collection. - * @param r The Recommendation. - * - * @return an element that represents an output mode with its themes. - */ - protected static Element createRecommendationElement( - ElementCreator cr, - Collection c, - Recommendation r) - { - logger.debug("CollectionHelper.createRecommendationElement"); - - Element recommendation = cr.create("recommendation"); - cr.addAttr(recommendation, "factory", r.getFactory(), true); - cr.addAttr(recommendation, "ids", r.getIDs(), true); - - return recommendation; - } - - - /** - * - */ - protected static Element createSettingsElement( - ElementCreator cr, - Collection c, - Settings s) - { - logger.debug("CollectionHelper.createSettingsElement"); - Element settings = cr.create("settings"); - - List<String> categories = s.getCategories(); - - for (String category: categories) { - Element cat =cr.create(category); - settings.appendChild(cat); - List<Property> props = s.getSettings(category); - for (Property p: props) { - if (p instanceof PropertyGroup) { - Element prop = createPropertyGroupElement(cr, - (PropertyGroup)p); - cat.appendChild(prop); - } - else if (p instanceof PropertySetting) { - Element prop = createPropertyElement (cr, - (PropertySetting)p); - cat.appendChild(prop); - } - } - } - return settings; - } - - - /** - * - */ - protected static Element createPropertyGroupElement( - ElementCreator cr, - PropertyGroup pg) - { - Element e = cr.create(pg.getName()); - - List<Property> list = pg.getProperties(); - for (Property p: list) { - Element pe = createPropertyElement(cr, (PropertySetting)p); - e.appendChild(pe); - } - return e; - } - - - /** - * - */ - protected static Element createPropertyElement( - ElementCreator cr, - PropertySetting p) - { - Element e = cr.create(p.getName()); - - if(p instanceof BooleanProperty) { - cr.addAttr(e, "type", "boolean", false); - } - else if(p instanceof DoubleProperty) { - cr.addAttr(e, "type", "double", false); - } - else if(p instanceof IntegerProperty) { - cr.addAttr(e, "type", "integer", false); - } - else if(p instanceof StringProperty) { - cr.addAttr(e, "type", "string", false); - } - - e.setTextContent(p.getValue().toString()); - cr.addAttr(e, "display", p.getAttribute("display"), false); - return e; - } - - - /** - * Take the DESCRIBE document of the Collections describe() - * operation and extracts the information about the collection itself and - * the collection items. - * - * @param description The DESCRIBE document of the Collections describe() - * operation. - * - * @return a Collection with CollectionItems. - */ - public static Collection parseCollection(Document description) { - logger.debug("CollectionHelper.parseCollection"); - - if (description == null) { - logger.warn("The DESCRIBE of the Collection is null!"); - return null; - } - - String uuid = XMLUtils.xpathString( - description, - "art:artifact-collection/@art:uuid", - ArtifactNamespaceContext.INSTANCE); - - String ttlStr = XMLUtils.xpathString( - description, - "art:artifact-collection/@art:ttl", - ArtifactNamespaceContext.INSTANCE); - - String name = XMLUtils.xpathString( - description, - "art:artifact-collection/@art:name", - ArtifactNamespaceContext.INSTANCE); - - if (uuid.length() == 0) { - logger.warn("Found an invalid (zero length uuid) Collection!"); - return null; - } - - if (ttlStr.length() == 0) { - logger.warn("Found an invalid Collection (zero length ttl)!"); - return null; - } - - - long ttl = -1; - try { - ttl = Long.valueOf(ttlStr); - } - catch (NumberFormatException nfe) { - // do nothing - } - - List<Recommendation> recommended = parseRecommendations(description); - Map<String, CollectionItem> collectionItems = - new HashMap<String, CollectionItem>(); - - name = (name != null && name.length() > 0) ? name : uuid; - - Collection c = new DefaultCollection(uuid, ttl, name, recommended); - - NodeList items = (NodeList) XMLUtils.xpath( - description, - "art:artifact-collection/art:artifacts/art:artifact", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (items == null || items.getLength() == 0) { - logger.debug("No collection item found for this collection."); - - return c; - } - - int size = items.getLength(); - - for (int i = 0; i < size; i++) { - CollectionItem item = parseCollectionItem( - (Element)items.item(i), - i == 0); - - if (item != null) { - c.addItem(item); - collectionItems.put(item.identifier() ,item); - } - } - - Map<String, ThemeList> themeLists = parseThemeLists(description, collectionItems); - c.setThemeLists(themeLists); - - Map<String, Settings> outSettings = parseSettings(description); - c.setSettings(outSettings); - logger.debug( - "Found " + c.getItemLength() + " collection items " + - "for the Collection '" + c.identifier() + "'."); - - return c; - } - - - /** - * @param collectionItems map to look up collection item mapping a themes - * (artifact) uuid. - */ - protected static Map<String, ThemeList> parseThemeLists( - Document desc, Map<String, CollectionItem> collectionItems - ) { - logger.debug("CollectionHelper.parseThemeLists"); - - NodeList lists = (NodeList) XMLUtils.xpath( - desc, - "/art:artifact-collection/art:attribute/art:outputs/art:output", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = lists != null ? lists.getLength() : 0; - - Map<String, ThemeList> themeList = new HashMap<String, ThemeList>(num); - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - for (int i = 0; i < num; i++) { - Element node = (Element)lists.item(i); - - String outName = node.getAttribute("name"); - - if (outName.length() > 0) { - ThemeList list = parseThemeList(node, collectionItems); - - if (list.getThemeCount() > 0) { - themeList.put(outName, list); - } - } - } - - return themeList; - } - - - /** - * @param collectionItems map to look up collection item mapping a themes - * (artifact) uuid. - */ - protected static ThemeList parseThemeList( - Element node, Map<String, CollectionItem> collectionItems - ) { - logger.debug("CollectionHelper.parseThemeList"); - - NodeList themes = node.getElementsByTagNameNS( - ArtifactNamespaceContext.NAMESPACE_URI, - "facet"); - - int num = themes != null ? themes.getLength() : 0; - - List<Theme> themeList = new ArrayList<Theme>(num); - - for (int i = 0; i < num; i++) { - Theme theme = parseTheme((Element)themes.item(i)); - theme.setCollectionItem(collectionItems.get(theme.getArtifact())); - - if (theme != null) { - themeList.add(theme); - } - } - - return new ThemeList(themeList); - } - - - protected static Theme parseTheme(Element ele) { - logger.debug("CollectionHelper.parseTheme"); - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - NamedNodeMap attrMap = ele.getAttributes(); - int attrNum = attrMap != null ? attrMap.getLength() : 0; - - AttributedTheme t = new AttributedTheme(); - - for (int i = 0; i < attrNum; i++) { - Node attr = attrMap.item(i); - - String prefix = attr.getPrefix(); - String name = attr.getNodeName().replace(prefix + ":", ""); - String value = attr.getNodeValue(); - - t.addAttr(name, value); - } - - return t; - } - - - /** - * Parse Settings elements. - * - * @param description The collection description. - * - * @return Map containing the settings. - */ - protected static Map<String, Settings> parseSettings(Document description) { - logger.info("parseSettings"); - - NodeList lists = (NodeList) XMLUtils.xpath( - description, - "/art:artifact-collection/art:attribute/art:outputs/art:output", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = lists != null ? lists.getLength() : 0; - - Map<String, Settings> list = new HashMap<String, Settings>(num); - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - for (int i = 0; i < num; i++) { - Element node = (Element)lists.item(i); - String outName = node.getAttribute("name"); - Settings s = parseSettings(outName, node); - list.put(outName, s); - } - - return list; - } - - - /** - * From a document, parse the settings for an output and create an - * OutputSettings object. - */ - protected static Settings parseSettings(String outName, Element node) { - OutputSettings set = new OutputSettings(outName); - - NodeList elements = node.getElementsByTagName("settings"); - - if (elements.getLength() == 0 || elements.getLength() > 1) { - return set; - } - - Element settings = (Element)elements.item(0); - - // Get the categories - NodeList catNodes = settings.getChildNodes(); - for (int i = 0; i < catNodes.getLength(); i++) { - Element catNode = (Element)catNodes.item(i); - - // The category name - String category = catNode.getTagName(); - - // list of properties or groups (groups have child nodes). - NodeList list = catNode.getChildNodes(); - - // iterate through all properties or groups. - List<Property> props = new ArrayList<Property> (); - for (int j = 0; j < list.getLength(); j++) { - Property p; - Element e = (Element)list.item(j); - if (e.hasChildNodes() && - e.getFirstChild().getNodeType() != Node.TEXT_NODE) { - p = parseSettingsGroup(e); - } - else { - p = parseSetting(e); - } - props.add(p); - } - set.setSettings(category, props); - } - return set; - } - - - /** - * - */ - protected static Property parseSettingsGroup(Element group) { - PropertyGroup p = new PropertyGroup(); - p.setName(group.getTagName()); - - NodeList list = group.getChildNodes(); - ArrayList<Property> props = new ArrayList<Property>(); - for (int i = 0; i < list.getLength(); i++) { - props.add(parseSetting((Element)list.item(i))); - } - p.setProperties(props); - return p; - } - - - /** - * From a property element create a Property object. - */ - protected static Property parseSetting(Element property){ - NamedNodeMap attrMap = property.getAttributes(); - int attrNum = attrMap != null ? attrMap.getLength() : 0; - - Node type = attrMap.getNamedItem("type"); - String t = type.getNodeValue(); - PropertySetting ps = new PropertySetting(); - - if(t.equals("string")) { - ps = new StringProperty(); - } - else if (t.equals("integer")) { - ps = new IntegerProperty(); - } - else if (t.equals("double")) { - ps = new DoubleProperty(); - } - else if (t.equals("boolean")) { - ps = new BooleanProperty(); - } - ps.setName(property.getTagName()); - ps.setValue(property.getTextContent()); - - for (int i = 0; i < attrNum; i++) { - Node attr = attrMap.item(i); - - String name = attr.getNodeName(); - String value = attr.getNodeValue(); - if(name.equals("type")) { - continue; - } - ps.setAttribute(name, value); - } - return ps; - } - - - /** - * This method extracts the CollectionItem from <i>node</i> with its output - * modes. The output modes are parsed using the parseOutputModes() method. - * - * @param node A node that contains information about a CollectionItem. - * - * @return a CollectionItem. - */ - protected static CollectionItem parseCollectionItem( - Element node, - boolean outs - ) { - logger.debug("CollectionHelper.parseCollectionItem"); - - if (node == null) { - logger.debug("The node for parsing CollectionItem is null!"); - return null; - } - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - String uuid = node.getAttributeNS(uri, "uuid"); - String hash = node.getAttributeNS(uri, "hash"); - - if (uuid == null || uuid.length() == 0) { - logger.warn("Found an invalid CollectionItem!"); - return null; - } - - List<OutputMode> modes = new ArrayList<OutputMode>(); - - if (outs) { - NodeList outputmodes = node.getElementsByTagNameNS( - uri, "outputmodes"); - - if (outputmodes.getLength() < 1) { - return null; - } - - Element om = (Element)outputmodes.item(0); - - modes = parseOutputModes(om); - } - - HashMap<String, String> dataItems = new HashMap<String, String>(); - - NodeList dataItemNodes = node.getElementsByTagNameNS( - uri, "data-items"); - - Element di = (Element)dataItemNodes.item(0); - dataItems = parseDataItems(di); - - return new DefaultCollectionItem(uuid, hash, modes, dataItems); - } - - - /** - * This method extracts the OutputModes available for a specific - * CollectionItem and returns them as list. - * - * @param node The root node of the outputmodes list. - * - * @return a list of OutputModes. - */ - protected static List<OutputMode> parseOutputModes(Element node) { - logger.debug("CollectionHelper.parseOutputModes"); - - if (node == null) { - logger.debug("The node for parsing OutputModes is null!"); - return null; - } - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - NodeList list = node.getElementsByTagNameNS(uri, "output"); - - int size = list.getLength(); - - if (size == 0) { - logger.debug("No outputmode nodes found!"); - return null; - } - - List<OutputMode> modes = new ArrayList<OutputMode>(size); - - for (int i = 0; i < size; i++) { - Element tmp = (Element)list.item(i); - - String name = tmp.getAttributeNS(uri, "name"); - String desc = tmp.getAttributeNS(uri, "description"); - String mime = tmp.getAttributeNS(uri, "mime-type"); - String type = tmp.getAttributeNS(uri, "type"); - - if (name.length() == 0) { - logger.warn("Found an invalid output mode."); - continue; - } - - OutputMode outmode = null; - List<Facet> fs = extractFacets(tmp); - - if (type.equals("export")) { - outmode = new ExportMode(name, desc, mime, fs); - } - else if (type.equals("report")) { - outmode = new ReportMode(name, desc, mime, fs); - } - else if (type.equals("chart")){ - outmode = new ChartMode(name, desc, mime, fs, type); - } - else if (type.equals("map")){ - outmode = new MapMode(name, desc, mime, fs); - } - else if (type.equals("overview")) { - outmode = new OverviewMode(name, desc, mime, fs, type); - } - else { - logger.warn("Broken Output mode without type found."); - continue; - } - - modes.add(outmode); - } - - return modes; - } - - - /** - * Create a Key/Value map for data nodes of artifact/collectionitem. - */ - protected static HashMap<String, String> parseDataItems(Element node) { - logger.debug("CollectionHelper.parseDataItems"); - - if (node == null) { - logger.debug("The node for parsing DataItems is null!"); - return null; - } - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - NodeList list = node.getElementsByTagNameNS(uri, "data"); - - int size = list.getLength(); - - if (size == 0) { - logger.debug("No static data-item nodes found!"); - } - - HashMap<String, String> data = new HashMap<String, String>(size*2); - - for (int i = 0; i < size; i++) { - Element tmp = (Element)list.item(i); - - String key = tmp.getAttributeNS(uri, "name"); - - if (key.length() == 0) { - logger.warn("Found an invalid data item mode."); - continue; - } - - // XXX We are restricted on 1/1 key/values in the data map here. - NodeList valueNodes = tmp.getElementsByTagName("art:item"); - - Element item = (Element) valueNodes.item(0); - String value = item.getAttributeNS(uri, "value"); - logger.debug("Found a data item " + key + " : " + value); - - data.put(key, value); - } - - - // Dynamic data. - list = node.getElementsByTagNameNS(uri, "select"); - - size = list.getLength(); - - if (size == 0) { - logger.debug("No dynamic data-item nodes found!"); - } - - for (int i = 0; i < size; i++) { - Element tmp = (Element)list.item(i); - - String key = tmp.getAttributeNS(uri, "name"); - - if (key.length() == 0) { - logger.warn("Found an invalid data item node (missing key)."); - continue; - } - - String value = tmp.getAttributeNS(uri, "defaultValue"); - - if (value.length() == 0) { - logger.warn("Found an invalid data item node (missing value)."); - continue; - } - - logger.debug("Found a (dyn) data item " + key + " : " + value); - - data.put(key, value); - } - - return data; - } - - protected static List<Facet> extractFacets(Element outmode) { - logger.debug("CollectionHelper - extractFacets()"); - - NodeList facetList = (NodeList) XMLUtils.xpath( - outmode, - XPATH_FACETS, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = facetList != null ? facetList.getLength() : 0; - - List<Facet> facets = new ArrayList<Facet>(num); - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - for (int i = 0; i < num; i++) { - Element facetEl = (Element) facetList.item(i); - - String name = facetEl.getAttributeNS(uri, "name"); - String desc = facetEl.getAttributeNS(uri, "description"); - String index = facetEl.getAttributeNS(uri, "index"); - - if (name != null && name.length() > 0 && index != null) { - facets.add(new DefaultFacet(name, Integer.valueOf(index),desc)); - } - } - - return facets; - } - - - public static List<Recommendation> parseRecommendations(Document doc) { - logger.debug("CollectionHelper.parseRecommendations"); - - NodeList list = (NodeList) XMLUtils.xpath( - doc, - XPATH_LOADED_RECOMMENDATIONS, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = list != null ? list.getLength() : 0; - - List<Recommendation> recs = new ArrayList<Recommendation>(num); - - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - for (int i = 0; i < num; i++) { - Element rec = (Element) list.item(i); - - String factory = rec.getAttributeNS(uri, "factory"); - String dbids = rec.getAttributeNS(uri, "ids"); - - if (factory != null && factory.length() > 0) { - recs.add(new Recommendation(factory, dbids)); - } - } - - return recs; - } - - - /** - * Add an artifact to a collection. - * @param collection Collection to add artifact to. - * @param artifact Artifact to add to collection - */ - public static Collection addArtifact( - Collection collection, - Artifact artifact, - String url, - String locale) - throws ServerException - { - logger.debug("CollectionHelper.addArtifact"); - - if (collection == null) { - logger.warn("The given Collection is null!"); - return null; - } - - Document add = ClientProtocolUtils.newAddArtifactDocument( - artifact.getUuid(), null); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - logger.debug("Do HTTP request now."); - - Document response = (Document) client.doCollectionAction( - add, collection.identifier(), new DocumentResponseHandler()); - - logger.debug( - "Finished HTTP request successfully. Parse Collection now."); - - Collection c = CollectionHelper.parseCollection(response); - - if (c == null) { - throw new ServerException(ERROR_ADD_ARTIFACT); - } - - return c; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - catch (Exception e) { - logger.error(e, e); - } - - throw new ServerException(ERROR_ADD_ARTIFACT); - } - - - /** - * Remove an artifact from a collection. - * @param collection Collection to remove artifact to. - * @param artifact Artifact to add to collection - */ - public static Collection removeArtifact( - Collection collection, - String artifactId, - String url, - String locale) - throws ServerException - { - logger.debug("CollectionHelper.removeArtifact"); - - if (collection == null) { - logger.warn("The given Collection is null!"); - return null; - } - - Document remove = ClientProtocolUtils.newRemoveArtifactDocument( - artifactId); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - logger.debug("Do HTTP request now."); - - Document response = (Document) client.doCollectionAction( - remove, collection.identifier(), new DocumentResponseHandler()); - - logger.debug( - "Finished HTTP request successfully. Parse Collection now."); - logger.debug(XMLUtils.toString(response)); - - Collection c = CollectionHelper.parseCollection(response); - - if (c == null) { - throw new ServerException(ERROR_REMOVE_ARTIFACT); - } - - return c; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - catch (Exception e) { - logger.error(e, e); - } - throw new ServerException(ERROR_REMOVE_ARTIFACT); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,202 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.CollectionItemAttributeService; - -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.CollectionItemAttribute; -import de.intevation.flys.client.shared.model.Style; -import de.intevation.flys.client.shared.model.StyleSetting; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class CollectionItemAttributeServiceImpl -extends RemoteServiceServlet -implements CollectionItemAttributeService -{ - private static final Logger logger = - Logger.getLogger(CollectionItemAttributeServiceImpl.class); - - - public static final String XPATH_RESULT = "/art:result/text()"; - - public static final String OPERATION_FAILURE = "FAILED"; - - public static final String ERROR_NO_STYLES_FOUND = - "error_no_theme_styles_found"; - - - public CollectionItemAttribute getCollectionItemAttribute( - Collection collection, - String artifact, - String locale) - throws ServerException - { - logger.info( - "CollectionItemAttributeServiceImpl.getCollectionItemAttribute"); - - String url = getServletContext().getInitParameter("server-url"); - - Document requestDoc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - requestDoc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element action = ec.create("action"); - - Element type = ec.create("type"); - ec.addAttr(type, "name", "getitemattribute", false); - - Element art = ec.create("artifact"); - ec.addAttr(art, "uuid", artifact, false); - - type.appendChild(art); - action.appendChild(type); - requestDoc.appendChild (action); - - try { - HttpClient client = new HttpClientImpl(url, locale); - Document res = (Document) client.doCollectionAction( - requestDoc, - collection.identifier(), - new DocumentResponseHandler()); - return readXML (res, artifact); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_STYLES_FOUND); - } - - - public void setCollectionItemAttribute( - Collection collection, - String artifact, - String locale, - CollectionItemAttribute attributes) - throws ServerException - { - logger.info( - "CollectionItemAttributeServiceImpl.setCollectionItemAttribute"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = writeXML(attributes, artifact); - - try { - HttpClient client = new HttpClientImpl(url, locale); - Document res = (Document) client.doCollectionAction( - doc, - collection.identifier(), - new DocumentResponseHandler()); - - return; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - throw new ServerException(ce.getLocalizedMessage()); - } - } - - protected CollectionItemAttribute readXML(Document doc, String artifact) - throws ServerException - { - CollectionItemAttribute cia = new CollectionItemAttribute(); - cia.setArtifact(artifact); - - Element root = doc.getDocumentElement(); - NodeList themes = root.getElementsByTagName("art:themes"); - - if (themes == null || themes.getLength() == 0) { - throw new ServerException(ERROR_NO_STYLES_FOUND); - } - - Element e = (Element) themes.item(0); - NodeList items = e.getElementsByTagName("theme"); - - for (int i = 0; i < items.getLength(); i++) { - Style s = StyleHelper.getStyle ((Element) items.item(i)); - if(s == null) { - throw new ServerException(ERROR_NO_STYLES_FOUND); - } - else { - cia.appendStyle(s); - } - } - - return cia; - } - - - protected Document writeXML ( - CollectionItemAttribute attributes, - String artifact) - { - Document styles = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - styles, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - Element action = ec.create("action"); - Element type = ec.create("type"); - type.setAttribute("name", "setitemattribute"); - Element art = ec.create("artifact"); - art.setAttribute("uuid", artifact); - Element attr = ec.create("attribute"); - Element themes = ec.create("themes"); - action.appendChild(type); - type.appendChild(art); - art.appendChild(attr); - attr.appendChild(themes); - - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( - styles, - "", - ""); - - for (int i = 0; i < attributes.getNumStyles(); i++) { - Style s = attributes.getStyle(i); - Element theme = creator.create("theme"); - theme.setAttribute("name", s.getName()); - theme.setAttribute("facet", s.getFacet()); - theme.setAttribute("index", String.valueOf(s.getIndex())); - for (int j = 0; j < s.getNumSettings(); j++) { - StyleSetting set = s.getSetting(j); - Element field = creator.create("field"); - field.setAttribute("name", set.getName()); - field.setAttribute("display", set.getDisplayName()); - field.setAttribute("default", set.getDefaultValue()); - field.setAttribute("hints", set.getHints()); - field.setAttribute("type", set.getType()); - field.setAttribute("hidden", String.valueOf(set.isHidden())); - theme.appendChild(field); - } - themes.appendChild(theme); - } - styles.appendChild(action); - return styles; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CreateCollectionServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.DefaultCollection; -import de.intevation.flys.client.client.services.CreateCollectionService; - - -/** - * This interface provides the createCollection service to create new - * collections in the artifact server. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class CreateCollectionServiceImpl -extends RemoteServiceServlet -implements CreateCollectionService -{ - /** Private logger. */ - private static final Logger logger = - Logger.getLogger(CreateCollectionServiceImpl.class); - - /** XPath to figure out the uuid of the created collection.*/ - public static final String XPATH_COLLECTION_UUID = - "/art:result/art:artifact-collection/@art:uuid"; - - /** XPath to figure out the ttl of the created collection.*/ - public static final String XPATH_COLLECTION_TTL = - "/art:result/art:artifact-collection/@art:ttl"; - - /** Error message key that is thrown if an error occured while creating - * a new collection.*/ - public static final String ERROR_CREATE_COLLECTION = - "error_create_collection"; - - - /** Attempt creation of Collection. */ - public Collection create(String locale, String ownerId) - throws ServerException - { - logger.info("Start creating a new collection."); - - String url = getServletContext().getInitParameter("server-url"); - - Document create = - ClientProtocolUtils.newCreateCollectionDocument(null); - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document doc = (Document) client.createCollection( - create, ownerId, new DocumentResponseHandler()); - - String uuid = XMLUtils.xpathString( - doc, XPATH_COLLECTION_UUID, ArtifactNamespaceContext.INSTANCE); - - String ttlStr = XMLUtils.xpathString( - doc, XPATH_COLLECTION_TTL, ArtifactNamespaceContext.INSTANCE); - - if (uuid.trim().length() == 0 || ttlStr.length() == 0) { - throw new ServerException(ERROR_CREATE_COLLECTION); - } - - return new DefaultCollection(uuid, Long.valueOf(ttlStr), uuid); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_CREATE_COLLECTION); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CrossSectionKMServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.CrossSectionKMService; - -/** - * Interact with not documented service. - */ -public class CrossSectionKMServiceImpl -extends RemoteServiceServlet -implements CrossSectionKMService -{ - private static final Logger logger = - Logger.getLogger(CrossSectionKMServiceImpl.class); - - /** XPath that points to the found cross section measurements. */ - public static final String XPATH_CROSS_SECTIONS - = "/cross-sections/cross-section"; - - /** The error message key that is thrown if an error occured while getting - * new data. */ - public static final String ERROR_GET_CROSS_SECTION - = "error_get_cross_section"; - - - /** - * Fetches positions (kms) at which measurements for given cross-sections - * exists. - * - * @param data Map of Integer (cross-section-id) to km. - * - */ - public Map<Integer,Double[]> getCrossSectionKMs( - String locale, - Map<Integer, Double> data, - int nNeighbours) - throws ServerException - { - logger.info("CrossSectionKMService.getCrossSectionKMs"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - Element crossSection = ec.create("cross-sections"); - - doc.appendChild(crossSection); - - for(Map.Entry<Integer, Double> oneCrossSection : data.entrySet()) { - Element cs = ec.create("cross-section"); - cs.setAttribute("id", oneCrossSection.getKey().toString()); - cs.setAttribute("km", oneCrossSection.getValue().toString()); - cs.setAttribute("n", Integer.valueOf(nNeighbours).toString()); - crossSection.appendChild(cs); - } - - HttpClient client = new HttpClientImpl(url, locale); - logger.debug("Created httpclient"); - - try { - // Document should contain: - // crosse-sections: - // attribute(id), attribute(km) attribute(n) - Document response = client.callService(url, "cross-section-km", doc); - //<cross-sections><cross-section id="1"><line km="19.5" line-id="189"/>... - - NodeList nodeList = (NodeList) XMLUtils.xpath(response, - XPATH_CROSS_SECTIONS, - XPathConstants.NODESET); - - int num = nodeList.getLength(); - - Map<Integer, Double[]> result = new HashMap<Integer, Double[]>(); - - try{ - for (int i = 0; i < num; i++) { - Element csElement = (Element) nodeList.item(i); - - int idx = Integer.parseInt(csElement.getAttribute("id")); - ArrayList<Double> kms = new ArrayList<Double>(); - - NodeList lineNodes = csElement.getElementsByTagName("line"); - int numLines = lineNodes.getLength(); - for (int k = 0; k < numLines; k++) { - Element line = (Element) lineNodes.item(k); - double d = Double.parseDouble(line.getAttribute("km")); - kms.add(d); - } - - Double[] doubles = new Double[kms.size()]; - kms.toArray(doubles); - result.put(Integer.valueOf(idx), doubles); - } - } - catch(NumberFormatException nfe) { - logger.error("Response was not parsable"); - } - - return result; - } - catch (ConnectionException ce) { - logger.error("ConnectionExsp", ce); - } - - logger.warn("CrossSectionKMService.getCrossSectionKMS() - FAILED"); - throw new ServerException(ERROR_GET_CROSS_SECTION); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,341 +0,0 @@ -package de.intevation.flys.client.server; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.shared.model.DefaultData; -import de.intevation.flys.client.shared.model.DefaultDataItem; -import de.intevation.flys.client.shared.model.DoubleArrayData; -import de.intevation.flys.client.shared.model.IntegerArrayData; -import de.intevation.flys.client.shared.model.IntegerData; -import de.intevation.flys.client.shared.model.IntegerOptionsData; -import de.intevation.flys.client.shared.model.IntegerRangeData; -import de.intevation.flys.client.shared.model.StringData; -import de.intevation.flys.client.shared.model.StringOptionsData; -import de.intevation.flys.client.shared.model.LongRangeData; - -import de.intevation.flys.client.shared.model.IntDataItem; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DataFactory { - - private static final Logger logger = Logger.getLogger(DataFactory.class); - - public static final String NS_URI = ArtifactNamespaceContext.NAMESPACE_URI; - - - /** - * Creates a new Data instance based on the <i>art:type</i> attribute of - * <i>element</i>. - * - * @param element The Data element. - * - * @return a Data instance. - */ - public static Data createDataFromElement(Element element) { - String name = element.getAttributeNS(NS_URI, "name"); - String type = element.getAttributeNS(NS_URI, "type"); - String label = element.getAttributeNS(NS_URI, "label"); - - label = label != null && label.length() > 0 ? label : name; - - try { - logger.debug("Create Data instance for: " + name + " | " + type); - - if (type == null || type.length() == 0) { - return createDefaultData(element, name, label); - } - - type = type.toLowerCase(); - - if (type.equals(StringData.TYPE)) { - return createStringData(element, name, label); - } - else if (type.equals(IntegerData.TYPE)) { - return createIntegerData(element, name, label); - } - else if (type.equals(StringOptionsData.TYPE)) { - return createStringOptionsData(element, name, label); - } - else if (type.equals(IntegerOptionsData.TYPE)) { - return createIntegerOptionsData(element, name, label); - } - else if (type.equals(IntegerRangeData.TYPE)) { - return createIntegerRangeData(element, name, label); - } - else if (type.equals(IntegerArrayData.TYPE)) { - return createIntegerArrayData(element, name, label); - } - else if (type.equals(DoubleArrayData.TYPE)) { - return createDoubleArrayData(element, name, label); - } - else if (type.equals(LongRangeData.TYPE)) { - return createLongRangeData(element, name, label); - } - else { - return createDefaultData(element, name, label); - } - } - catch (Exception e) { - logger.error("Error while data creation for: " + name); - } - - return null; - } - - - /** - * This method creates a new instance of DefaultData which has no real type - * set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of DefaultData. - */ - protected static Data createDefaultData(Element ele, String name, String label) { - logger.debug("Create new DefaultData"); - return new DefaultData(name, label, "default", extractDataItems(ele)); - } - - - /** - * This method creates a new instance of StringData which has a type - * "string" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of StringData. - */ - protected static Data createStringData(Element ele, String name, String label) { - return new StringData(name, label, extractDataItems(ele)); - } - - - /** - * This method creates a new instance of DefaultData which has a type - * "integer" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of IntegerData. - */ - protected static Data createIntegerData(Element ele, String name, String label) { - return new IntegerData(name, label, extractDataItems(ele)); - } - - - /** - * This method creates a new instance of StringOptionsData which has a type - * "options" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of StringOptionsData. - */ - protected static Data createStringOptionsData(Element ele, String name, String label) { - return new StringOptionsData(name, label, extractDataItems(ele)); - } - - - /** - * This method creates a new instance of DefaultData which has a type - * "intoptions" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of IntegerOptionsData. - */ - protected static Data createIntegerOptionsData(Element ele, String name, String label) { - return new IntegerOptionsData(name, label, extractDataItems(ele)); - } - - - /** - * This method creates a new instance of DefaultData which has a type - * "intrange" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of IntegerRangeData. - */ - protected static Data createIntegerRangeData(Element ele, String name, String label) { - DataItem[] items = extractDataItems(ele); - String rawValue = items[0].getStringValue(); - - String[] minmax = rawValue.split(";"); - - return new IntegerRangeData( - name, - label, - Integer.valueOf(minmax[0]), - Integer.valueOf(minmax[1])); - } - - - /** - * This method creates a new instance of DefaultData which has a type - * "integerarray" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of IntegerArrayData. - */ - protected static Data createIntegerArrayData(Element ele, String name, String label) { - IntDataItem[] items = extractIntDataItems(ele); - return new IntegerArrayData(name, label, items); - } - - - /** - * This method creates a new instance of DefaultData which has a type - * "doublearray" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of DoubleArrayData. - */ - protected static Data createDoubleArrayData(Element ele, String name, String label) { - DataItem[] items = extractDataItems(ele); - String rawValue = items[0].getStringValue(); - - String[] values = rawValue.split(";"); - double[] doubles = new double[values.length]; - - for (int i = 0; i < values.length; i++) { - try { - doubles[i] = Double.valueOf(values[i]); - } - catch (NumberFormatException nfe) { - logger.warn("Error while parsing DoubleArrayData: " + nfe); - } - } - - return new DoubleArrayData(name, label, doubles); - } - - - /** - * This method extracts the art:item elements placed under <i>elements</i>. - * - * @param element A data node that contains items. - * - * @return a list of DataItems. - */ - protected static DataItem[] extractDataItems(Element element) { - NodeList itemList = (NodeList) XMLUtils.xpath( - element, - "art:item", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (itemList == null || itemList.getLength() == 0) { - logger.debug("No data items found."); - return null; - } - - int count = itemList.getLength(); - - DataItem[] items = new DataItem[count]; - - logger.debug("There are " + count + " data items in element."); - - for (int i = 0; i < count; i++) { - Element tmp = (Element) itemList.item(i); - - String value = tmp.getAttributeNS(NS_URI, "value"); - String label = tmp.getAttributeNS(NS_URI, "label"); - - logger.debug("Found data item:"); - logger.debug(" label: " + label); - logger.debug(" value: " + value); - - items[i] = new DefaultDataItem(label, label, value); - } - - return items; - } - - - /** - * This method extracts the art:item elements placed under <i>elements</i>. - * - * @param element A data node that contains items. - * - * @return a list of DataItems. - */ - protected static IntDataItem[] extractIntDataItems(Element element) { - NodeList itemList = (NodeList) XMLUtils.xpath( - element, - "art:item", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (itemList == null || itemList.getLength() == 0) { - logger.debug("No old data items found."); - return null; - } - - int count = itemList.getLength(); - - IntDataItem[] items = new IntDataItem[count]; - - for (int i = 0; i < count; i++) { - Element tmp = (Element) itemList.item(i); - - String value = tmp.getAttributeNS(NS_URI, "value"); - String label = tmp.getAttributeNS(NS_URI, "label"); - - try { - int data = Integer.parseInt(value); - items[i] = new IntDataItem(label, label, data); - } - catch(NumberFormatException nfe) { - logger.debug(nfe, nfe); - } - } - return items; - } - - /** - * This method creates a new instance of LongRangeData which has a type - * "longrange" set. - * - * @param ele The Data element. - * @param name The name of the Data instance. - * - * @return an instance of IntegerRangeData. - */ - protected static Data createLongRangeData(Element ele, String name, String label) { - DataItem[] items = extractDataItems(ele); - String rawValue = items[0].getStringValue(); - - String[] minmax = rawValue.split(";"); - - return new LongRangeData( - name, - label, - Long.valueOf(minmax[0]), - Long.valueOf(minmax[1])); - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.client.services.DeleteCollectionService; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DeleteCollectionServiceImpl -extends DoCollectionAction -implements DeleteCollectionService -{ - private static final Logger logger = - Logger.getLogger(DeleteCollectionServiceImpl.class); - - - public static final String XPATH_RESULT = "/art:result/text()"; - public static final String OPERATION_FAILURE = "FAILED"; - - public void delete(Collection c) - throws ServerException - { - logger.info("Delete collection: " + c.identifier()); - - String url = getServletContext().getInitParameter("server-url"); - - Document del = ClientProtocolUtils.newDeleteCollectionDocument(); - - doAction(c, del, url); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DescribeArtifactServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.client.services.DescribeArtifactService; - - -/** - * This interface provides artifact specific operation DESCRIBE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DescribeArtifactServiceImpl -extends RemoteServiceServlet -implements DescribeArtifactService -{ - private static final Logger logger = - Logger.getLogger(DescribeArtifactServiceImpl.class); - - - public static final String ERROR_DESCRIBE_ARTIFACT = - "error_describe_artifact"; - - - public Artifact describe(String locale, Artifact artifact) - throws ServerException - { - logger.info("DescribeArtifactServiceImpl.describe"); - - String url = getServletContext().getInitParameter("server-url"); - - Document describe = ClientProtocolUtils.newDescribeDocument( - artifact.getUuid(), - artifact.getHash(), - true); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - logger.debug("Start Http request now."); - - Document description = (Document) client.describe( - new de.intevation.artifacts.httpclient.objects.Artifact( - artifact.getUuid(), - artifact.getHash()), - describe, - new DocumentResponseHandler()); - - if (description != null) { - logger.debug("Finished Http request sucessfully!"); - - return (Artifact) new FLYSArtifactCreator().create(description); - } - } - catch (ConnectionException ce) { - ce.printStackTrace(); - } - - throw new ServerException(ERROR_DESCRIBE_ARTIFACT); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - -import de.intevation.flys.client.client.services.DescribeCollectionService; - - -/** - * This service implements a method that queries the DESCRIBE document of a - * specific collection and returns a Collection object with the information of - * the document. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DescribeCollectionServiceImpl -extends RemoteServiceServlet -implements DescribeCollectionService -{ - private static final Logger logger = - Logger.getLogger(DescribeCollectionServiceImpl.class); - - - /** The error message key that is thrown if an error occured while - * describe() a Collection.*/ - public static final String ERROR_DESCRIBE_COLLECTION = - "error_describe_collection"; - - - public Collection describe(String uuid, String locale) - throws ServerException - { - logger.info("DescribeCollectionServiceImpl.describe"); - - String url = getServletContext().getInitParameter("server-url"); - - Document describe = ClientProtocolUtils.newDescribeCollectionDocument( - uuid); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document response = (Document) client.doCollectionAction( - describe, uuid, new DocumentResponseHandler()); - - Collection c = CollectionHelper.parseCollection(response); - - if (c == null) { - throw new ServerException(ERROR_DESCRIBE_COLLECTION); - } - - logger.debug("Collection successfully parsed."); - - return c; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_DESCRIBE_COLLECTION); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DischargeInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.DischargeInfoService; -import de.intevation.flys.client.shared.model.DischargeInfoObject; -import de.intevation.flys.client.shared.model.DischargeInfoObjectImpl; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class DischargeInfoServiceImpl -extends RemoteServiceServlet -implements DischargeInfoService -{ - private static final Logger logger = - Logger.getLogger(DischargeInfoServiceImpl.class); - - public static final String ERROR_NO_DISCHARGEINFO_FOUND = - "error_no_dischargeinfo_found"; - - public static final String XPATH_DISTANCES = "art:discharges/art:discharge"; - - - public DischargeInfoObject[] getDischargeInfo( - String locale, - long gauge) - throws ServerException - { - logger.info("DichargeInfoServiceImpl.getDischargeInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element gaugeEl = ec.create("gauge"); - gaugeEl.setTextContent(String.valueOf(gauge)); - - doc.appendChild(gaugeEl); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document result = client.callService(url, "dischargeinfo", doc); - - logger.debug("Extract discharge info objects now."); - DischargeInfoObject[] objects = extractDischargeInfoObjects(result); - - if (objects != null && objects.length > 0) { - return objects; - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_DISCHARGEINFO_FOUND); - } - - protected DischargeInfoObject[] extractDischargeInfoObjects( - Document result - ) - throws ServerException { - NodeList list = result.getElementsByTagName("discharge"); - - if (list == null || list.getLength() == 0) { - logger.warn("No discharge info found."); - throw new ServerException(ERROR_NO_DISCHARGEINFO_FOUND); - } - - int num = list.getLength(); - logger.debug("Response contains " + num + " objects."); - - List<DischargeInfoObject> objects = - new ArrayList<DischargeInfoObject>(num); - - for (int i = 0; i < num; i++) { - DischargeInfoObject obj = buildDischargeInfoObject( - (Element)list.item(i)); - - if (obj != null) { - objects.add(obj); - } - } - - logger.debug("Retrieved " + objects.size() + " discharges."); - - return (DischargeInfoObject[]) - objects.toArray(new DischargeInfoObject[num]); - - } - - protected DischargeInfoObject buildDischargeInfoObject(Element node) { - - String desc = node.getAttribute("description").trim(); - String start = node.getAttribute("start").trim(); - String end = node.getAttribute("end").trim(); - - if (start.length() > 0 && end.length() > 0) { - try { - Integer startYear = new Integer(start); - Integer endYear = new Integer(end); - return new DischargeInfoObjectImpl(desc, startYear, endYear); - } - catch (NumberFormatException nfe) { - logger.warn(nfe.getLocalizedMessage()); - } - } - - logger.warn("Invalid distance info object found."); - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DischargeInfoXML.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class DischargeInfoXML -extends HttpServlet -{ - private static final Logger logger = Logger.getLogger(DischargeInfoXML.class); - - - public static final String ERROR_NO_DISTANCEINFO_FOUND = - "error_no_dischargeinfo_found"; - - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - logger.info("DischargeInfoXML.doGet"); - - String url = getServletContext().getInitParameter("server-url"); - - String gauge = req.getParameter("gauge"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element gaugeEl = ec.create("gauge"); - gaugeEl.setTextContent(gauge); - - doc.appendChild(gaugeEl); - - HttpClient client = new HttpClientImpl(url); - - try { - InputStream in = (InputStream) client.callService( - url, "dischargeinfo", doc, new StreamResponseHandler()); - - OutputStream out = resp.getOutputStream(); - - byte[] b = new byte[4096]; - int i; - while ((i = in.read(b)) >= 0) { - out.write(b, 0, i); - } - - out.flush(); - out.close(); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - catch (IOException ioe) { - logger.error(ioe, ioe); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DischargeTablesServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.DateFormat; -import java.util.Date; -import java.util.Locale; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; - - -public class DischargeTablesServiceImpl extends HttpServlet { - - private static final Logger logger = Logger - .getLogger(DischargeInfoServiceImpl.class); - - private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( - DateFormat.MEDIUM, Locale.GERMANY); - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - logger.info("ChartOutputServiceImpl.doGet"); - - String url = getServletContext().getInitParameter("server-url"); - String locale = req.getParameter("locale"); - - prepareHeader(req, resp); - - Document requestDoc = createRequestDoc(req); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - OutputStream out = resp.getOutputStream(); - InputStream stream = (InputStream) client.callService(url, - "dischargetablesoverview", requestDoc, - new StreamResponseHandler()); - - byte[] b = new byte[4096]; - try { - int i; - while ((i = stream.read(b)) >= 0) { - out.write(b, 0, i); - } - } - finally { - stream.close(); - } - } - catch (IOException ioe) { - logger.error("Error while fetching discharge tables chart!", ioe); - } - } - - protected void prepareHeader(HttpServletRequest req, - HttpServletResponse resp) { - resp.setHeader("Content-Type", "image/png"); - } - - protected Document createRequestDoc(HttpServletRequest req) { - Document request = XMLUtils.newDocument(); - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(request, - null, null); - - Element service = creator.create("service"); - Element gauge = creator.create("gauge"); - Element extent = creator.create("extent"); - Element format = creator.create("format"); - Element timerange = creator.create("timerange"); - - creator.addAttr(gauge, "name", extractRequestGauge(req)); - creator.addAttr(extent, "width", extractRequestWidth(req)); - creator.addAttr(extent, "height", extractRequestHeight(req)); - creator.addAttr(format, "type", extractRequestFormat(req)); - creator.addAttr(timerange, "lower", extractRequestLowerTime(req)); - creator.addAttr(timerange, "upper", extractRequestUpperTime(req)); - - request.appendChild(service); - service.appendChild(gauge); - service.appendChild(extent); - service.appendChild(format); - service.appendChild(timerange); - - return request; - } - - protected String extractRequestGauge(HttpServletRequest req) { - return req.getParameter("gauge"); - } - - protected String extractRequestWidth(HttpServletRequest req) { - return req.getParameter("width"); - } - - protected String extractRequestHeight(HttpServletRequest req) { - return req.getParameter("height"); - } - - protected String extractRequestFormat(HttpServletRequest req) { - return req.getParameter("format"); - } - - protected String extractRequestLowerTime(HttpServletRequest req) { - String lowerStr = req.getParameter("lower"); - try { - long lowerMillis = Long.parseLong(lowerStr); - Date lower = new Date(lowerMillis); - - return DATE_FORMAT.format(lower); - } - catch (NumberFormatException nfe) { - logger.warn("Cannot parse time millies.", nfe); - } - - return null; - } - - protected String extractRequestUpperTime(HttpServletRequest req) { - String upperStr = req.getParameter("upper"); - try { - long upperMillis = Long.parseLong(upperStr); - Date upper = new Date(upperMillis); - - return DATE_FORMAT.format(upper); - } - catch (NumberFormatException nfe) { - logger.warn("Cannot parse time millies.", nfe); - } - - return null; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.DistanceInfoService; -import de.intevation.flys.client.shared.model.DistanceInfoObject; -import de.intevation.flys.client.shared.model.DistanceInfoObjectImpl; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DistanceInfoServiceImpl -extends RemoteServiceServlet -implements DistanceInfoService -{ - private static final Logger logger = - Logger.getLogger(DistanceInfoServiceImpl.class); - - public static final String ERROR_NO_DISTANCEINFO_FOUND = - "error_no_distanceinfo_found"; - - public static final String XPATH_DISTANCES = "art:distances/art:distance"; - - - public DistanceInfoObject[] getDistanceInfo( - String locale, - String river) - throws ServerException - { - logger.info("DistanceInfoServiceImpl.getDistanceInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element riverEl = ec.create("river"); - - riverEl.setTextContent(river); - - doc.appendChild(riverEl); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document result = client.callService(url, "distanceinfo", doc); - - logger.debug("Extract distance info objects now."); - DistanceInfoObject[] objects = extractDistanceInfoObjects(result); - - if (objects != null && objects.length > 0) { - return objects; - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); - } - - - /** - * Extracts all distance info objects from <i>result</i> document. - * - * @param result The document retrieved by the server. - * - * @return a list of DistanceInfoObjects. - */ - protected DistanceInfoObject[] extractDistanceInfoObjects(Document result) - throws ServerException - { - NodeList list = result.getElementsByTagName("distance"); - - if (list == null || list.getLength() == 0) { - logger.warn("No distance info found."); - throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); - } - - int num = list.getLength(); - logger.debug("Response contains " + num + " objects."); - - List<DistanceInfoObject> objects = - new ArrayList<DistanceInfoObject>(num); - - for (int i = 0; i < num; i++) { - DistanceInfoObject obj = buildDistanceInfoObject( - (Element)list.item(i)); - - if (obj != null) { - objects.add(obj); - } - } - - logger.debug("Retrieved " + objects.size() + " distances."); - - return (DistanceInfoObject[]) - objects.toArray(new DistanceInfoObject[num]); - } - - - /** - * Extracts information for a single distance info object and intializes an - * DistanceInfoObject with them. - * - * @param node The node that contains the information. - * - * @return a valid DistanceInfoObject. - */ - protected DistanceInfoObject buildDistanceInfoObject(Element node) { - - String desc = node.getAttribute("description").trim(); - String from = node.getAttribute("from").trim(); - String to = node.getAttribute("to").trim(); - String riverside = node.getAttribute("riverside").trim(); - String bottom = node.getAttribute("bottom").trim(); - String top = node.getAttribute("top").trim(); - - if (desc.length() > 0 && from.length() > 0) { - try { - Double f = new Double(from); - Double t = to .length() > 0 ? new Double(to) : null; - Double b = bottom.length() > 0 ? new Double(bottom) : null; - Double tp = top .length() > 0 ? new Double(top) : null; - - return new DistanceInfoObjectImpl(desc, f, t, riverside, b, tp); - } - catch (NumberFormatException nfe) { - logger.warn(nfe.getLocalizedMessage()); - } - } - - logger.warn("Invalid distance info object found."); - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoXML.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DistanceInfoXML -extends HttpServlet -{ - private static final Logger logger = Logger.getLogger(DistanceInfoXML.class); - - - public static final String ERROR_NO_DISTANCEINFO_FOUND = - "error_no_distanceinfo_found"; - - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - logger.info("DistanceInfoXML.doGet"); - - String url = getServletContext().getInitParameter("server-url"); - - String river = req.getParameter("river"); - String filter = req.getParameter("filter"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element riverEl = ec.create("river"); - riverEl.setTextContent(river); - - doc.appendChild(riverEl); - - if (filter != null && filter.length() > 0) { - Element typeEl = ec.create("filter"); - typeEl.setTextContent(filter); - - riverEl.appendChild(typeEl); - } - - HttpClient client = new HttpClientImpl(url); - - try { - InputStream in = (InputStream) client.callService( - url, "distanceinfo", doc, new StreamResponseHandler()); - - OutputStream out = resp.getOutputStream(); - - byte[] b = new byte[4096]; - int i; - while ((i = in.read(b)) >= 0) { - out.write(b, 0, i); - } - - out.flush(); - out.close(); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - catch (IOException ioe) { - logger.error(ioe, ioe); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DoCollectionAction.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DoCollectionAction extends RemoteServiceServlet { - - private static final Logger logger = - Logger.getLogger(DoCollectionAction.class); - - - public static final String XPATH_RESULT = "/art:result/text()"; - public static final String OPERATION_FAILURE = "FAILED"; - public static final String FAILURE_EXCEPTION = "collection_action_failed"; - - - protected void doAction(Collection c, Document action, String url) - throws ServerException - { - logger.info("DoCollectionAction.doAction"); - - HttpClient client = new HttpClientImpl(url); - - try { - Document res = (Document) client.doCollectionAction( - action, c.identifier(), - new DocumentResponseHandler()); - - String result = XMLUtils.xpathString( - res, - XPATH_RESULT, - ArtifactNamespaceContext.INSTANCE); - - if (result == null || result.equals(OPERATION_FAILURE)) { - logger.error("Operation failed."); - throw new ServerException(FAILURE_EXCEPTION); - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - throw new ServerException(FAILURE_EXCEPTION); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ExportServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.OutputStream; -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - - -/** - * This service is used to request a data export from the artifact server. The - * response is directed directly to the output stream, so that a file dialog is - * opened. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ExportServiceImpl -extends HttpServlet -{ - private static final Logger logger = - Logger.getLogger(ExportServiceImpl.class); - - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - logger.info("ExportServiceImpl.doGet"); - - try { - OutputStream out = resp.getOutputStream(); - - String url = getServletContext().getInitParameter("server-url"); - String uuid = req.getParameter("uuid"); - String name = req.getParameter("name"); - String mode = req.getParameter("mode"); - String type = req.getParameter("type"); - String locale = req.getParameter("locale"); - String km = req.getParameter("km"); - String fn = name + "." + type; - - resp.setHeader("Content-Disposition", "attachment;filename=" + fn); - - if (logger.isDebugEnabled()) { - logger.debug("Request " + type + " export."); - } - - Document attr = null; - if (km != null && km.length() > 0) { - attr = XMLUtils.newDocument(); - XMLUtils.ElementCreator ec = - new XMLUtils.ElementCreator(attr, null, null); - Element e = ec.create("km"); - e.setTextContent(km); - attr.appendChild(e); - } - Document request = ClientProtocolUtils.newOutCollectionDocument( - uuid, mode, type, attr); - HttpClient client = new HttpClientImpl(url, locale); - client.collectionOut(request, uuid, mode, out); - - out.close(); - out.flush(); - } - catch (IOException ioe) { - logger.error(ioe, ioe); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,211 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.common.ArtifactNamespaceContext; - -import de.intevation.artifacts.httpclient.utils.ArtifactCreator; - -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.CalculationMessage; -import de.intevation.flys.client.shared.model.ChartArtifact; -import de.intevation.flys.client.shared.model.DefaultArtifact; -import de.intevation.flys.client.shared.model.FixAnalysisArtifact; -import de.intevation.flys.client.shared.model.GaugeDischargeCurveArtifact; -import de.intevation.flys.client.shared.model.MapArtifact; -import de.intevation.flys.client.shared.model.MINFOArtifact; -import de.intevation.flys.client.shared.model.StaticSQRelationArtifact; -import de.intevation.flys.client.shared.model.WINFOArtifact; - - -/** - * An implementation of an {@link ArtifactCreator}. This class uses the document - * that is returned by the artifact server to parse important information (like - * uuid, hash) and returns a new {@link Artifact} instance. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class FLYSArtifactCreator implements ArtifactCreator { - - private static final Logger logger = - Logger.getLogger(FLYSArtifactCreator.class); - - - /** The XPath to the artifact's uuid.*/ - public static final String XPATH_UUID = "/art:result/art:uuid/@art:value"; - - /** The XPath to the artifact's hash value.*/ - public static final String XPATH_HASH = "/art:result/art:hash/@art:value"; - - /** The XPath to the artifact's name value.*/ - public static final String XPATH_NAME = "/art:result/art:name/@art:value"; - - /** The XPath to the value that determines if the artifact is processing in - * background.*/ - public static final String XPATH_BACKGROUND_VALUE = - "/art:result/art:background-processing/@art:value"; - - /** The XPath that points to the (if existing) background messages.*/ - public static final String XPATH_BACKGROUND = - "/art:result/art:background-processing"; - - - /** - * Creates a new instance of an {@link ArtifactCreator}. - */ - public FLYSArtifactCreator() { - } - - - /** - * This concreate implementation returns an instance of {@link Artifact} - * that is used in the FLYS GWT Client code. - * - * @param doc A document that describes the artifact that has been created - * in the artifact server. - * - * @return an instance if {@link Artifact}. - */ - public Object create(Document doc) { - Artifact artifact = extractArtifact(doc); - artifact.setArtifactDescription( - ArtifactDescriptionFactory.createArtifactDescription(doc)); - - return artifact; - } - - - /** - * This method extracts the UUID und HASH information of the returned - * artifact document. - * - * @param doc The result of the CREATE operation. - * - * @return an instance of an {@link Artifact}. - */ - protected Artifact extractArtifact(Document doc) { - logger.debug("FLYSArtifactCreator - extractArtifact()"); - - String uuid = XMLUtils.xpathString( - doc, XPATH_UUID, ArtifactNamespaceContext.INSTANCE); - - String hash = XMLUtils.xpathString( - doc, XPATH_HASH, ArtifactNamespaceContext.INSTANCE); - - String name = XMLUtils.xpathString( - doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE); - - String backgroundStr = XMLUtils.xpathString( - doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE); - - boolean background = false; - if (backgroundStr != null && backgroundStr.length() > 0) { - background = Boolean.valueOf(backgroundStr); - } - - List<CalculationMessage> msg = parseBackgroundMessages(doc); - - logger.debug("NEW Artifact UUID: " + uuid); - logger.debug("NEW Artifact HASH: " + hash); - logger.debug("NEW Artifact NAME: " + name); - logger.debug("NEW Artifact IN BACKGROUND: " + background); - - if (name == null) { - return new DefaultArtifact(uuid, hash, background, msg); - } - - name = name.trim(); - - if (name.length() > 0 && name.equals("winfo")) { - logger.debug("+++++ NEW WINFO ARTIFACT."); - return new WINFOArtifact(uuid, hash, background, msg); - } - else if (name.length() > 0 && name.equals("new_map")) { - logger.debug("+++++ NEW MAP ARTIFACT."); - return new MapArtifact(uuid, hash, background, msg); - } - else if (name.length() > 0 && name.equals("new_chart")) { - logger.debug("+++++ NEW CHART ARTIFACT."); - return new ChartArtifact(uuid, hash, background, msg); - } - else if (name.length() > 0 && name.equals("minfo")) { - logger.debug("+++++ NEW MINFO ARTIFACT."); - return new MINFOArtifact(uuid, hash, background, msg); - } - else if (name.length() > 0 && name.equals("fixanalysis")) { - logger.debug("+++++ NEW FIXANALYSIS ARTIFACT."); - return new FixAnalysisArtifact(uuid, hash, background, msg); - } - else if (name.length() > 0 && name.equals("gaugedischargecurve")) { - logger.debug("+++++ NEW GAUGEDISCHARGECURVE ARTIFACT."); - return new GaugeDischargeCurveArtifact(uuid, hash, background, msg); - } - else if (name.length() > 0 && name.equals("staticsqrelation")) { - logger.debug("+++++ STATICSQRELATION ARTIFACT."); - return new StaticSQRelationArtifact(uuid, hash, background, msg); - } - - return new DefaultArtifact(uuid, hash, background, msg); - } - - - public static List<CalculationMessage> parseBackgroundMessages(Document d) { - NodeList list = (NodeList) XMLUtils.xpath( - d, XPATH_BACKGROUND, XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int len = list != null ? list.getLength() : 0; - - logger.debug("Found " + len + " background messages."); - - List<CalculationMessage> res = new ArrayList<CalculationMessage>(len); - - for (int i = 0; i < len; i++) { - CalculationMessage msg = parseBackgroundMessage( - (Element) list.item(i)); - - if (msg != null) { - res.add(msg); - } - } - - return res; - } - - - public static CalculationMessage parseBackgroundMessage(Element e) { - String steps = e.getAttribute("art:steps"); - String currentStep = e.getAttribute("art:currentStep"); - String message = e.getTextContent(); - - int lenCurStep = currentStep != null ? currentStep.length() : 0; - int lenSteps = steps != null ? steps.length() : 0; - int lenMessage = message != null ? message.length() : 0; - - if (lenSteps > 0 && lenMessage > 0 && lenCurStep > 0) { - try { - return new CalculationMessage( - Integer.parseInt(steps), - Integer.parseInt(currentStep), - message); - - } - catch (NumberFormatException nfe) { - nfe.printStackTrace(); - } - } - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FeedServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.client.services.FeedService; - -/** - * This interface provides a method that bundles the artifact specific - * operation FEED. - */ -public class FeedServiceImpl -extends RemoteServiceServlet -implements FeedService -{ - private static final Logger logger = Logger.getLogger(FeedServiceImpl.class); - - - /** XPath that points to the result type of a feed or advance operation.*/ - public static final String XPATH_RESULT = "/art:result/@art:type"; - - /** XPath that points to the result type of a feed or advance operation.*/ - public static final String XPATH_RESULT_MSG = "/art:result/text()"; - - /** A constant that marks errors.*/ - public static final String OPERATION_FAILURE = "FAILURE"; - - /** The error message key that is thrown if an error occured while feeding - * new data.*/ - public static final String ERROR_FEED_DATA = "error_feed_data"; - - - /** - * This method triggers the FEED operation. - * - * @param artifact The artifact that needs to be fed. - * @param data An array of Data objects that contain the information that - * are used for the FEED operation. - * - * @return a new artifact parsed from the description of FEED. - */ - public Artifact feed( - String locale, - Artifact artifact, - Data[] data) - throws ServerException - { - logger.info("StepForwardServiceImpl.feed"); - - String url = getServletContext().getInitParameter("server-url"); - - Document feed = ClientProtocolUtils.newFeedDocument( - artifact.getUuid(), - artifact.getHash(), - createKVP(data)); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document description = (Document) client.feed( - new de.intevation.artifacts.httpclient.objects.Artifact( - artifact.getUuid(), - artifact.getHash()), - feed, - new DocumentResponseHandler()); - - if (description == null) { - logger.warn("StepForwardService.feed() - FAILED"); - throw new ServerException(ERROR_FEED_DATA); - } - - String result = XMLUtils.xpathString( - description, - XPATH_RESULT, - ArtifactNamespaceContext.INSTANCE); - - if (result == null || !result.equals(OPERATION_FAILURE)) { - logger.debug("StepForwardService.feed() - SUCCESS"); - return (Artifact) new FLYSArtifactCreator().create(description); - } - else if (result != null && result.equals(OPERATION_FAILURE)) { - String msg = XMLUtils.xpathString( - description, - XPATH_RESULT_MSG, - ArtifactNamespaceContext.INSTANCE); - throw new ServerException(msg); - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - logger.warn("StepForwardService.feed() - FAILED"); - throw new ServerException(ERROR_FEED_DATA); - } - - - /** - * Triggers FEED operation, many artifacts, same data item(s). - * - * @param artifacts Artifacts that shall be fed. - * @param data An array of Data objects that contain the information that - * are used for the FEED operation. - * - * @return a new artifact parsed from the description of FEED. - */ - public List<Artifact> feedMany( - String locale, - List<Artifact> artifacts, - Data[] data) - throws ServerException - { - logger.info("StepForwardServiceImpl.feedMany"); - - String url = getServletContext().getInitParameter("server-url"); - - List<Artifact> resultArtifacts = new ArrayList<Artifact>(); - - for (Artifact artifact: artifacts) { - logger.info("feedMany: Relay to StepForwardServiceImpl.feed"); - Artifact fedArtifact = feed(locale, artifact, data); - resultArtifacts.add(fedArtifact); - } - - return resultArtifacts; - } - - - /** - * This method creates an array of key/value pairs from an array of Data - * objects. The string array is used as parameter for the feed() operation. - * - * @param data The data that should be transformed into the string array. - * - * @return a string array that contains key/value pairs. - */ - protected String[][] createKVP(Data[] data) { - String[][] kvp = new String[data.length][]; - - int i = 0; - - for (Data d: data) { - DataItem[] items = d.getItems(); - String key = d.getLabel(); - String value = d.getStringValue(); - - kvp[i++] = new String[] { key, value }; - } - - return kvp; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FileUploadServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -package de.intevation.flys.client.server; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.fileupload.FileItemIterator; -import org.apache.commons.fileupload.FileItemStream; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class FileUploadServiceImpl -extends HttpServlet -{ - private static final Logger logger = Logger.getLogger(FileUploadServiceImpl.class); - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) { - logger.debug("handling post request."); - - String url = getServletContext().getInitParameter("server-url"); - - Document request = createFileXML(req); - - if (request == null) { - return; - } - HttpClient client = new HttpClientImpl(url); - - try { - Document result = client.callService(url, "fileupload", request); - - PrintWriter respWriter = resp.getWriter(); - respWriter.write("<html><link href='FLYS.css' rel='stylesheet' type='text/css'>"); - respWriter.write("<body><div style='font-face: Arial,Verdana,sans-serif; font-size: 11px'>"); - - if (result == null) { - logger.warn("FileUpload service returned no result."); - respWriter.write("FileUpload service returned no result"); - } - else { - String status = result.getElementsByTagName("status") - .item(0).getTextContent(); - respWriter.write(status); - } - - respWriter.write("</div></body></html>"); - respWriter.flush(); - - return; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - catch (IOException e) { - logger.error(e, e); - } - } - - - protected Document createFileXML(HttpServletRequest req) { - ServletFileUpload upload = new ServletFileUpload(); - - try{ - FileItemIterator iter = upload.getItemIterator(req); - - while (iter.hasNext()) { - FileItemStream item = iter.next(); - InputStream stream = item.openStream(); - - // Process the input stream - ByteArrayOutputStream out = new ByteArrayOutputStream(); - int len; - byte[] buffer = new byte[stream.available()]; - while ((len = stream.read(buffer, 0, buffer.length)) != -1) { - out.write(buffer, 0, len); - } - - buffer = Base64.encodeBase64(buffer); - String b64File = new String(buffer); - - Document fileDoc = XMLUtils.newDocument(); - - ElementCreator ec = new ElementCreator(fileDoc, null, null); - Element root = ec.create("upload"); - Element id = ec.create("artifact-uuid"); - id.setTextContent(req.getParameter("uuid")); - - Element data = ec.create("data"); - data.setTextContent(b64File); - - fileDoc.appendChild(root); - root.appendChild(id); - root.appendChild(data); - - return fileDoc; - } - } - catch(Exception e){ - logger.debug("Failed to create xml document containing the file."); - logger.debug(e, e); - } - return null; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -package de.intevation.flys.client.server; - -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; - -import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.log4j.Logger; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -public class FixingsKMChartServiceImpl -extends HttpServlet -{ - private static final Logger log = - Logger.getLogger(FixingsKMChartServiceImpl.class); - - public static final String SERVICE_NAME = "fixings-km-chart"; - - public FixingsKMChartServiceImpl() { - } - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - - log.info("FixingsKMChartServiceImpl.doGet"); - - String url = getServletContext().getInitParameter("server-url"); - String locale = req.getParameter("locale"); - String filter = req.getParameter("filter"); - - if (filter == null || filter.length() == 0) { - log.warn("Missing 'filter' parameter."); - return; - } - - if (locale == null || locale.length() == 0) { - locale = "de"; - } - - Document filterDoc = XMLUtils.jsonToXML(filter); - - if (filterDoc == null) { - log.warn("Creating filter document failed."); - return; - } - - InputStream in; - - try { - HttpClient client = new HttpClientImpl(url, locale); - in = (InputStream)client.callService( - url, // XXX: Why? The URL is passed by construction already. - SERVICE_NAME, - filterDoc, - new StreamResponseHandler()); - } - catch (ConnectionException ce) { - log.error(ce); - return; - } - - resp.setHeader("Content-Type", guessMIMEType(filterDoc)); - - try { - OutputStream out = resp.getOutputStream(); - - byte [] buf = new byte[4096]; - int i = -1; - while ((i = in.read(buf)) >= 0) { - out.write(buf, 0, i); - } - out.flush(); - } - catch (IOException ioe) { - log.error(ioe); - } - finally { - try { in.close(); } - catch (IOException ioe) { /* ignored */ } - } - } - - protected static String guessMIMEType(Document document) { - - NodeList formats = document.getElementsByTagName("format"); - - String format = "png"; - - if (formats.getLength() > 0) { - String type = ((Element)formats.item(0)).getAttribute("type"); - if (type.length() > 0) { - format = type; - } - } - - return "image/" + format; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,240 +0,0 @@ -package de.intevation.flys.client.server; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.common.utils.XSLTransformer; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.client.services.FixingsOverviewService; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; -import de.intevation.flys.client.shared.model.FixingsOverviewInfo.Sector; - -import de.intevation.flys.client.shared.model.FixingsOverviewInfo; - -import java.io.IOException; -import java.io.InputStream; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.apache.log4j.Logger; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -public class FixingsOverviewServiceImpl -extends RemoteServiceServlet -implements FixingsOverviewService -{ - private static final Logger log = - Logger.getLogger(FixingsOverviewServiceImpl.class); - - public static final String SERVICE_NAME = "fixings-overview"; - - public static final String XSL_TRANSFORM = - "/WEB-INF/stylesheets/fixoverview2html.xsl"; - - protected static final String XPATH_RID = "/fixings/river/@rid"; - protected static final String XPATH_RIVER = "/fixings/river/@name"; - protected static final String XPATH_RFROM = "/fixings/river/@from"; - protected static final String XPATH_RTO = "/fixings/river/@to"; - - protected static final String XPATH_EVENT = "/fixings/events/event"; - - - @Override - public FixingsOverviewInfo generateOverview( - String locale, - String uuid, - String filter, - boolean checkboxes, - String callback - ) - throws ServerException - { - log.info("FixingsOverviewServiceImpl.doGet"); - - if (filter == null || filter.length() == 0) { - log.warn("Missing 'filter' parameter."); - return null; - } - - boolean debug = log.isDebugEnabled(); - - if (debug) { - log.debug("JSON filter: ------------------"); - log.debug(filter); - } - - Document filterDoc = XMLUtils.jsonToXML(filter); - - if (filterDoc == null) { - log.warn("Creating filter document failed."); - return null; - } - - if (debug) { - log.debug("XML filter: ------------------"); - log.debug(XMLUtils.toString(filterDoc)); - } - - try { - String url = getServletContext().getInitParameter("server-url"); - HttpClient client = new HttpClientImpl(url, locale); - Document resultDoc = - client.callService(url, SERVICE_NAME, filterDoc); - - if (debug) { - log.debug("Result XML: -----------"); - log.debug(XMLUtils.toString(resultDoc)); - } - - FixingsOverviewInfo i = getInfo( - locale, resultDoc, uuid, checkboxes, callback); - return i; - } - catch (ConnectionException ce) { - log.error(ce); - } - return null; - } - - - protected FixingsOverviewInfo getInfo( - String locale, - Document doc, - String uuid, - boolean checkboxes, - String callback - ) { - // TODO: Find a more general solution. - locale = locale == null || locale.toLowerCase().startsWith("de") - ? "de" - : "en"; - - InputStream transform = getServletContext() - .getResourceAsStream(XSL_TRANSFORM); - - if (transform == null) { - log.warn("transform not found"); - return null; - } - - String result = null; - try { - XSLTransformer xformer = new XSLTransformer(); - xformer.addParameter("locale", locale); - xformer.addParameter("project-uuid", uuid); - xformer.addParameter( - "render-checkboxes", - checkboxes ? Boolean.TRUE : Boolean.FALSE); - xformer.addParameter("callback", callback); - result = xformer.transform(doc, transform); - } - finally { - try { transform.close(); } - catch (IOException ioe) {} - } - - if (log.isDebugEnabled()) { - log.debug("--------------------------------------"); - log.debug(result); - log.debug("--------------------------------------"); - } - - int rid = -1; - double from = -1; - double to = -1; - - String rid_str = XMLUtils.xpathString(doc, XPATH_RID, null); - String river = XMLUtils.xpathString(doc, XPATH_RIVER, null); - String from_str = XMLUtils.xpathString(doc, XPATH_RFROM, null); - String to_str = XMLUtils.xpathString(doc, XPATH_RTO, null); - - try { - rid = Integer.parseInt(rid_str); - from = Double.parseDouble(from_str); - to = Double.parseDouble(to_str); - } - catch(NumberFormatException nfe) { - log.warn(nfe, nfe); - } - - List<FixEvent> fixEvents = getFixEvents(doc); - return new FixingsOverviewInfo( - rid, - river, - from, - to, - fixEvents, - result); - } - - - protected List<FixEvent> getFixEvents(Document doc) { - List<FixEvent> list = new ArrayList<FixEvent>(); - - NodeList events = (NodeList) XMLUtils.xpath( - doc, - XPATH_EVENT, - XPathConstants.NODESET, - null); - - if (events == null || events.getLength() == 0) { - log.warn("No events in Overview!"); - return list; - } - - for (int i = 0, E = events.getLength(); i < E; i++) { - Element n = (Element)events.item(i); - List<Sector> sectors = getSectors(n); - String cid = n.getAttribute("cid"); - String date = n.getAttribute("date");; - String name = n.getAttribute("description"); - list.add(new FixEvent( cid, date, name, sectors)); - } - return list; - } - - protected List<Sector> getSectors(Element event) { - NodeList sectors = event.getElementsByTagName("sector"); - - if (sectors.getLength() == 0) { - log.warn("No Sectors in Event!"); - return null; - } - - List<Sector> list = new ArrayList<Sector>(); - for (int i = 0, S = sectors.getLength(); i < S; i++) { - Element n = (Element)sectors.item(i); - int cls = -1; - double from = -1; - double to = -1; - String cls_str = n.getAttribute("class"); - String from_str = n.getAttribute("from"); - String to_str = n.getAttribute("to"); - try { - cls = Integer.parseInt(cls_str); - from = Double.parseDouble(from_str); - to = Double.parseDouble(to_str); - } - catch(NumberFormatException nfe) { - log.warn(nfe, nfe); - } - list.add(new Sector(cls, from, to)); - } - return list; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -package de.intevation.flys.client.server; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Capabilities; -import de.intevation.flys.client.client.services.GCService; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class GCServiceImpl -extends RemoteServiceServlet -implements GCService -{ - private static Logger logger = Logger.getLogger(GCServiceImpl.class); - - - public Capabilities query(String path) - throws ServerException - { - logger.info("GCServiceImpl.query"); - - return CapabilitiesParser.getCapabilities(path); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,275 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.AttributedTheme; -import de.intevation.flys.client.shared.model.FeatureInfo; -import de.intevation.flys.client.shared.model.FeatureInfoResponse; -import de.intevation.flys.client.shared.model.Theme; - -import de.intevation.flys.client.client.services.GFIService; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class GFIServiceImpl -extends RemoteServiceServlet -implements GFIService -{ - public static final String ERR_NO_VALID_GFI_URL = - "error_no_valid_gfi_url"; - - public static final String ERR_GFI_REQUEST_FAILED = - "error_gfi_req_failed"; - - public static final String ERR_PARSING_RESPONSE_FAILED = - "error_gfi_parsing_failed"; - - - private static final Logger logger = - Logger.getLogger(GFIServiceImpl.class); - - - /** - * @param theme - * @param format - * @param bbox - * @param height - * @param width - * @param x - * @param y - * - * @return - */ - public FeatureInfoResponse query( - Theme theme, - String format, - String bbox, - String projection, - int height, - int width, - int x, - int y - ) throws ServerException - { - logger.info("GFIServiceImpl.query"); - - String path = createGetFeautureInfoURL( - theme, format, bbox, projection, height, width, x, y); - - logger.debug("URL=" + path); - - try { - URL url = new URL(path); - - URLConnection conn = url.openConnection(); - conn.connect(); - - InputStream is = conn.getInputStream(); - - return parseResponse(is); - - } - catch (IOException ioe) { - logger.warn(ioe, ioe); - } - - throw new ServerException(ERR_GFI_REQUEST_FAILED); - } - - - /** - * @param map - * @param theme - * @param format - * @param x - * @param y - * - * @return - */ - protected String createGetFeautureInfoURL( - Theme theme, - String infoFormat, - String bbox, - String projection, - int height, - int width, - int x, - int y - ) throws ServerException - { - String url = getUrl(theme); - - if (url == null || url.length() == 0) { - throw new ServerException(ERR_NO_VALID_GFI_URL); - } - - String layers = ((AttributedTheme)theme).getAttr("layers"); - - StringBuilder sb = new StringBuilder(); - sb.append(url); - - if (url.indexOf("?") < 0) { - sb.append("?SERVICE=WMS"); - } - else { - sb.append("&SERVICE=WMS"); - } - - sb.append("&VERSION=1.1.1"); - sb.append("&REQUEST=GetFeatureInfo"); - sb.append("&LAYERS=" + layers); - sb.append("&QUERY_LAYERS=" + layers); - sb.append("&BBOX=" + bbox); - sb.append("&HEIGHT=" + height); - sb.append("&WIDTH=" + width); - sb.append("&FORMAT=image/png"); - sb.append("&INFO_FORMAT=" + infoFormat); - sb.append("&SRS=" + projection); - sb.append("&X=" + String.valueOf(x)); - sb.append("&Y=" + String.valueOf(y)); - - return sb.toString(); - } - - - protected String getUrl(Theme theme) { - AttributedTheme attr = (AttributedTheme) theme; - return attr.getAttr("url"); - } - - - protected FeatureInfoResponse parseResponse(InputStream is) { - logger.debug("GFIServiceImpl.parseResponse"); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - byte [] buf = new byte[1024]; - - int r = -1; - try { - while ((r = is.read(buf)) >= 0) { - baos.write(buf, 0, r); - } - } catch (IOException ex) { - logger.warn("GetFeatureInfo response could not be read: ", ex); - return new FeatureInfoResponse(); - } - - String content; - try { - content = baos.toString("UTF-8"); - } - catch (UnsupportedEncodingException uee) { - content = baos.toString(); - } - - Document response = XMLUtils.parseDocument(content); - if (response != null) { - List<FeatureInfo> features = new ArrayList<FeatureInfo>(); - parseFeatureInfos(response, features); - return new FeatureInfoResponse(features, null); - } - // Unable to parse just return the response as is - return new FeatureInfoResponse(new ArrayList<FeatureInfo>(), content); - } - - - protected void parseFeatureInfos(Node node, List<FeatureInfo> features) { - logger.debug("GFIServiceImpl.parseFeatureInfos"); - - String name = node.getNodeName(); - - if (name.endsWith("_layer")) { - features.add(parseFeature(node)); - - return; - } - - NodeList children = node.getChildNodes(); - - if (children != null && children.getLength() > 0) { - for (int i = 0, n = children.getLength(); i < n; i++) { - parseFeatureInfos(children.item(i), features); - } - } - } - - - protected FeatureInfo parseFeature(Node node) { - logger.debug("GFIServiceImpl.parseFeature"); - - String layername = node.getNodeName(); - - FeatureInfo f = new FeatureInfo(layername); - - NodeList children = node.getChildNodes(); - int numChildren = children != null ? children.getLength() : 0; - - logger.debug("Feature '" + layername + "' has " + numChildren + " nodes."); - - for (int i = 0; i < numChildren; i++) { - Node tmp = children.item(i); - String nodeName = tmp.getNodeName(); - - logger.debug(" node name: '" + nodeName + "'"); - - if (nodeName.equals("gml:name")) { - logger.debug("NAME node has child: " + tmp.getFirstChild().getNodeValue()); - f.setLayername(tmp.getFirstChild().getNodeValue()); - } - else if (nodeName.endsWith("_feature")) { - parseFeatureAttributes(tmp, f); - } - } - - return f; - } - - - protected void parseFeatureAttributes(Node node, FeatureInfo f) { - logger.debug("GFIServiceImpl.parseFeatureAttributes"); - - NodeList children = node.getChildNodes(); - int numChildren = children != null ? children.getLength() : 0; - - logger.debug("Has " + numChildren + " attributes."); - - for (int i = 0; i < numChildren; i++) { - Node tmp = children.item(i); - String name = tmp.getNodeName(); - - logger.debug(" tmp attribute name: '" + name + "'"); - - if (name.equals("gml:boundedBy")) { - // TODO - } - else { - Node child = tmp.getFirstChild(); - if (child != null) { - f.addAttr(name, child.getNodeValue()); - } - } - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GGInATrustStrategy.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package de.intevation.flys.client.server; - -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -import org.apache.http.conn.ssl.TrustStrategy; - -public class GGInATrustStrategy implements TrustStrategy { - - /** - * Tempoary class to accept all certificates for GGinA Authentication - */ - - @Override - public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { - // FIXME validate Certificate - return true; - } -} -
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GaugeInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.GaugeInfoService; -import de.intevation.flys.client.shared.model.Gauge; -import de.intevation.flys.client.shared.model.GaugeImpl; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class GaugeInfoServiceImpl -extends RemoteServiceServlet -implements GaugeInfoService -{ - private static final Logger logger = - Logger.getLogger(GaugeInfoServiceImpl.class); - - - public static final String ERROR_NO_GAUGES_FOUND = - "error_no_gaugeinfo_found"; - - public static final String XPATH_GAUGES = "art:service/art:gauge"; - - - public List<Gauge> getGaugeInfo(String rivername, String refnumber) - throws ServerException - { - logger.info("GaugeInfoServiceImpl.getGaugeInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element river = ec.create("river"); - ec.addAttr(river, "name", rivername); - - if (refnumber != null && refnumber.length() > 0) { - Element filter = ec.create("filter"); - Element gauge = ec.create("gauge"); - gauge.setTextContent(refnumber); - - filter.appendChild(gauge); - river.appendChild(filter); - } - - doc.appendChild(river); - - HttpClient client = new HttpClientImpl(url); - - try { - Document result = client.callService(url, "gaugeinfo", doc); - - logger.debug("Extract gauge info now."); - List<Gauge> gauges = extractGauges(result); - - if (gauges != null && gauges.size() > 0) { - return gauges; - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_GAUGES_FOUND); - } - - - /** - * Extracts all wq info objects from <i>result</i> document. - * - * @param result The document retrieved by the server. - * - * @return a list of WQInfoObjects. - */ - protected List<Gauge> extractGauges(Document result) - throws ServerException - { - List<Gauge> gauges = new ArrayList<Gauge>(); - - NodeList list = (NodeList) XMLUtils.xpath( - result, - XPATH_GAUGES, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (list == null || list.getLength() == 0) { - logger.warn("No gauges found."); - - throw new ServerException(ERROR_NO_GAUGES_FOUND); - } - - int num = list.getLength(); - logger.debug("Response contains " + num + " objects."); - - for (int i = 0; i < num; i++) { - Gauge obj = buildGauge((Element) list.item(i)); - - if (obj != null) { - gauges.add(obj); - } - } - - logger.debug("Retrieved " + gauges.size() + " gauges."); - - return gauges; - } - - - protected Gauge buildGauge(Element ele) { - String name = ele.getAttribute("name"); - String lowerStr = ele.getAttribute("lower"); - String upperStr = ele.getAttribute("upper"); - - if (lowerStr != null && upperStr != null) { - try { - return new GaugeImpl( - name, - Double.valueOf(lowerStr), - Double.valueOf(upperStr)); - } - catch (NumberFormatException nfe) { - logger.warn("Error while Gauge creation: " + nfe.getMessage()); - } - } - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GetArtifactServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.client.services.GetArtifactService; - - -/** - * This service provides a method that returns an artifact based on its - * identifier. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class GetArtifactServiceImpl -extends RemoteServiceServlet -implements GetArtifactService -{ - private static final Logger logger = - Logger.getLogger(GetArtifactServiceImpl.class); - - - public static final String ERROR_DESCRIBE_ARTIFACT = - "error_describe_artifact"; - - public static final String XPATH_RESULT = "/art:result/text()"; - - public static final String OPERATION_FAILURE = "FAILED"; - - - public Artifact getArtifact( - String locale, - String uuid, - String hash) - throws ServerException - { - logger.info("GetArtifactServiceImpl.getArtifact"); - - String url = getServletContext().getInitParameter("server-url"); - - Document describe = ClientProtocolUtils.newDescribeDocument( - uuid, hash, true); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document description = (Document) client.describe( - new de.intevation.artifacts.httpclient.objects.Artifact( - uuid, hash), - describe, - new DocumentResponseHandler()); - - if (description == null) { - throw new ServerException(ERROR_DESCRIBE_ARTIFACT); - } - - String result = XMLUtils.xpathString( - description, - XPATH_RESULT, - ArtifactNamespaceContext.INSTANCE); - - if (result == null || !result.equals(OPERATION_FAILURE)) { - return (Artifact) new FLYSArtifactCreator().create(description); - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_DESCRIBE_ARTIFACT); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/LoadArtifactServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.HashMap; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.Recommendation; - -import de.intevation.flys.client.client.services.LoadArtifactService; - -/** - * This service creates a new Artifact based on a given Recommendation and puts - * this new artifact into a specified Collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class LoadArtifactServiceImpl -extends ArtifactServiceImpl -implements LoadArtifactService -{ - private static final Logger logger = - Logger.getLogger(LoadArtifactServiceImpl.class); - - /** Error. */ - public static final String ERROR_LOAD_ARTIFACT = "error_load_artifact"; - - - /** - * Clones or creates a single artifact and adds it to a collection. - * - * Note that in contrast to loadMany, always the given factory is used - * to clone the artifact. - * - * @param parent collection to add recommendation to. - * @param recom recommendation to create clone for. - * @param factory factory to use. - * @param locale the locale to translate messages. - */ - public Artifact load( - Collection parent, - Recommendation recom, - String factory, - String locale - ) - throws ServerException { - logger.info( - "LoadArtifactServiceImpl.load: " + recom.getMasterArtifact()); - - String url = getServletContext().getInitParameter("server-url"); - - // 1) Clone the Artifact specified in >>recom<< - Artifact clone = ArtifactHelper.createArtifact( - url, locale, factory, recom); - - if (clone != null) { - logger.debug("Successfully create Artifact Clone. Add now!"); - Collection c = CollectionHelper.addArtifact( - parent, clone, url, locale); - - if (c != null) { - logger.debug("Successfully added Clone to Collection."); - - return clone; - } - } - - throw new ServerException(ERROR_LOAD_ARTIFACT); - } - - - /** - * Clone/create one or more artifacts and add it to a collection, avoiding - * duplicates. - * - * @param parent Collection where clones will be added to. - * @param recoms definitions of source of clone. - * @param factory name of factory to use when cloning artifacts (can be - * null in which case the recommendations getFactory() will - * be used. - * @param locale the locale to translate messages. - * - * @return cloned artifacts (same artifact might be contained multiple - * times). - */ - public Artifact[] loadMany( - Collection parent, - Recommendation[] recoms, - String factory, - String locale - ) - throws ServerException { - logger.debug("LoadArtifactServiceImpl.loadMany"); - - String url = getServletContext().getInitParameter("server-url"); - - ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); - HashMap<Recommendation, Artifact> cloneMap = - new HashMap<Recommendation, Artifact>(); - - // TODO Respect the index of what to clone. - - // 1) Clone the Artifacts specified in >>recoms<< - for (Recommendation recom : recoms) { - // Do not do two clones of two identical recommendations. - Artifact prevClone = cloneMap.get(recom); - if (prevClone != null) { - // Already cloned a recommendation like this. - logger.debug("LoadArtifactServiceImpl: Avoid reclones, " - + "clone already exists."); - artifacts.add(prevClone); - } - else { - // Not already cloned. - String realFactory = factory != null - ? factory - : recom.getFactory(); - - logger.debug("One will be cloned with : " + realFactory); - - Artifact clone = ArtifactHelper.createArtifact( - url, locale, realFactory, recom); - - if (clone != null) { - logger.debug("LoadArtifactServiceImple: Successfully " - + "loaded Artifact Clone."); - Collection c = CollectionHelper.addArtifact( - parent, clone, url, locale); - - if (c != null) { - artifacts.add(clone); - // Remember we cloned a recommendation like this. - cloneMap.put(recom, clone); - } - else { - throw new ServerException(ERROR_LOAD_ARTIFACT); - } - } - } - } - return artifacts.toArray(new Artifact[artifacts.size()]); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/LoggingConfigurator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package de.intevation.flys.client.server; - -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; - - -public class LoggingConfigurator { - - private static final Logger logger = - Logger.getLogger(LoggingConfigurator.class); - - - private LoggingConfigurator() { - } - - public static void init(String log4jProperties) { - if (log4jProperties != null && log4jProperties.length() > 0) { - PropertyConfigurator.configure(log4jProperties); - logger.info("Log4J logging initialized."); - } - else { - System.out.println("Error while setting up Log4J configuration."); - } - - System.out.println("LoggingConfigurator.init finished"); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.server.auth.Authentication; -import de.intevation.flys.client.server.auth.AuthenticationException; -import de.intevation.flys.client.server.auth.AuthenticationFactory; -import de.intevation.flys.client.server.auth.User; -import de.intevation.flys.client.server.auth.UserClient; -import de.intevation.flys.client.server.features.Features; - -public class LoginServlet extends HttpServlet { - - private static Logger logger = Logger.getLogger(LoginServlet.class); - - private static final String FLYS_PAGE = "FLYS.html"; - private static final String LOGIN_PAGE = "login.jsp"; - - private void redirectFailure(HttpServletResponse resp, String path) - throws IOException { - resp.sendRedirect(path + "/" + LOGIN_PAGE); - } - - private void redirectFailure(HttpServletResponse resp, String path, - Exception e) throws IOException { - this.redirectFailure(resp, path, e.getMessage()); - } - - private void redirectFailure(HttpServletResponse resp, String path, - String message) throws IOException { - resp.sendRedirect(path + "/" + LOGIN_PAGE + "?error=" + message); - } - - private void redirectSuccess(HttpServletResponse resp, String path, - String uri) throws IOException { - if (uri == null) { - String redirecturl = getServletContext().getInitParameter("redirect-url"); - if (redirecturl == null) { - redirecturl = FLYS_PAGE; - } - uri = "/" + redirecturl; - } - resp.sendRedirect(uri); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - logger.debug("Processing get request"); - this.redirectFailure(resp, req.getContextPath()); - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException - { - String encoding = req.getCharacterEncoding(); - String username = req.getParameter("username"); - String password = req.getParameter("password"); - - logger.debug("Processing post request"); - - if (username == null || password == null) { - logger.debug("No username or password provided"); - this.redirectFailure(resp, req.getContextPath()); - return; - } - - try { - Authentication aresp = this.auth(username, password, encoding); - if (aresp == null || !aresp.isSuccess()) { - logger.debug("Authentication not successful"); - this.redirectFailure(resp, req.getContextPath()); - return; - } - User user = aresp.getUser(); - - String url = getServletContext().getInitParameter("server-url"); - UserClient client = new UserClient(url); - if (!client.userExists(user)) { - logger.debug("Creating db user"); - if (!client.createUser(user)) { - this.redirectFailure(resp, req.getContextPath(), - "Could not create new user"); - return; - } - } - - HttpSession session = req.getSession(); - session.setAttribute("user", user); - - String uri = (String)session.getAttribute("requesturi"); - - this.redirectSuccess(resp, req.getContextPath(), uri); - } - catch(AuthenticationException e) { - logger.error(e, e); - this.redirectFailure(resp, req.getContextPath(), e); - } - } - - private Authentication auth(String username, String password, String encoding) - throws AuthenticationException, IOException - { - ServletContext sc = this.getServletContext(); - Features features = (Features)sc.getAttribute(Features.CONTEXT_ATTRIBUTE); - String auth = sc.getInitParameter("authentication"); - return AuthenticationFactory.getInstance(auth).auth(username, password, - encoding, features); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapHelper.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.model.MapConfig; - - -public class MapHelper { - - private static final Logger logger = Logger.getLogger(MapHelper.class); - - - public static final String XPATH_SRID = - "/art:floodmap/art:srid/text()"; - - public static final String XPATH_MAX_EXTENT = - "/art:floodmap/art:maxExtent/text()"; - - public static final String XPATH_INITIAL_EXTENT = - "/art:floodmap/art:initialExtent/text()"; - - - private MapHelper() { - } - - - public static MapConfig parseConfig(Document raw) { - logger.debug("MapHelper.parseConfig"); - - if (logger.isDebugEnabled()) { - logger.debug(XMLUtils.toString(raw)); - } - - MapConfig config = new MapConfig(); - - setSrid(config, raw); - setMaxExtent(config, raw); - setInitialExtent(config, raw); - - return config; - } - - - protected static void setSrid(MapConfig config, Document raw) { - String srid = (String) XMLUtils.xpathString( - raw, - XPATH_SRID, - ArtifactNamespaceContext.INSTANCE); - - logger.debug("Found srid: '" + srid + "'"); - - if (srid != null && srid.length() > 0) { - logger.debug("Set srid: '" + srid + "'"); - config.setSrid(srid); - } - } - - - protected static void setMaxExtent(MapConfig config, Document raw) { - String maxExtent = (String) XMLUtils.xpathString( - raw, - XPATH_MAX_EXTENT, - ArtifactNamespaceContext.INSTANCE); - - logger.debug("Found max extent: '" + maxExtent + "'"); - - if (maxExtent != null && maxExtent.length() > 0) { - logger.debug("Set max extent: '" + maxExtent + "'"); - config.setMaxExtent(maxExtent); - } - } - - - protected static void setInitialExtent(MapConfig config, Document raw) { - String initialExtent = (String) XMLUtils.xpathString( - raw, - XPATH_INITIAL_EXTENT, - ArtifactNamespaceContext.INSTANCE); - - if (initialExtent != null && initialExtent.length() > 0) { - logger.debug("Set initial extent: '" + initialExtent + "'"); - config.setInitialExtent(initialExtent); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -package de.intevation.flys.client.server; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.flys.client.client.services.MapInfoService; -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.BBox; -import de.intevation.flys.client.shared.model.MapInfo; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - - -/** - * This service fetches a document that contains meta information for a specific - * chart. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MapInfoServiceImpl -extends RemoteServiceServlet -implements MapInfoService -{ - private static final Logger logger = - Logger.getLogger(MapInfoServiceImpl.class); - - - public static final String XPATH_RIVER = - "/mapinfo/river/@name"; - - public static final String XPATH_SRID = - "/mapinfo/river/srid/@value"; - - public static final String XPATH_BBOX = - "/mapinfo/river/bbox/@value"; - - public static final String XPATH_RIVER_WMS = - "/mapinfo/river/river-wms/@url"; - - public static final String XPATH_RIVER_LAYERS = - "/mapinfo/river/river-wms/@layers"; - - public static final String XPATH_WMS_URL = - "/mapinfo/river/background-wms/@url"; - - public static final String XPATH_WMS_LAYERS = - "/mapinfo/river/background-wms/@layers"; - - public static final String ERROR_NO_MAPINFO_FOUND = - "mapinfo_service_no_result"; - - - @Override - public MapInfo getMapInfo(String locale, String river) - throws ServerException - { - logger.info("MapInfoServiceImpl.getMapInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document request = getRequestDocument(river, "rivermap"); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - logger.debug("MapInfoServiceImpl.callService"); - Document result = client.callService(url, "mapinfo", request); - - if (result == null) { - logger.warn("MapInfo service returned no result."); - throw new ServerException(ERROR_NO_MAPINFO_FOUND); - } - - return getMapInfo(result); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_MAPINFO_FOUND); - } - - - public static Document getRequestDocument(String rivername, String maptypeStr) { - logger.debug("MapInfoServiceImpl.getRequestDocument"); - - Document request = XMLUtils.newDocument(); - ElementCreator cr = new ElementCreator(request, null, null); - - Element root = cr.create("mapinfo"); - Element river = cr.create("river"); - Element maptype = cr.create("maptype"); - - river.setTextContent(rivername); - maptype.setTextContent(maptypeStr); - - request.appendChild(root); - root.appendChild(river); - root.appendChild(maptype); - - return request; - } - - - public static MapInfo getMapInfo(Document result) { - logger.debug("MapInfoServiceImpl.getMapInfo"); - - String river = XMLUtils.xpathString(result, XPATH_RIVER, null); - String sridStr = XMLUtils.xpathString(result, XPATH_SRID, null); - String bboxS = XMLUtils.xpathString(result, XPATH_BBOX, null); - BBox bbox = BBox.getBBoxFromString(bboxS); - - String riverWMS = XMLUtils.xpathString(result, XPATH_RIVER_WMS, null); - String riverLayers = XMLUtils.xpathString(result, XPATH_RIVER_LAYERS, null); - String wmsURL = XMLUtils.xpathString(result, XPATH_WMS_URL, null); - String wmsLayers = XMLUtils.xpathString(result, XPATH_WMS_LAYERS, null); - - int srid = 4326; - - try { - srid = Integer.parseInt(sridStr); - } - catch (NumberFormatException nfe) { - GWT.log("Could not parse SRID String: " + sridStr); - } - - return new MapInfo( - river, srid, bbox, riverWMS, riverLayers, wmsURL, wmsLayers); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapOutputServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.IOException; - -import java.util.Map; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.MapConfig; -import de.intevation.flys.client.shared.model.OutputMode; -import de.intevation.flys.client.client.services.MapOutputService; - - -public class MapOutputServiceImpl -extends RemoteServiceServlet -implements MapOutputService -{ - - private static final Logger logger = - Logger.getLogger(MapOutputServiceImpl.class); - - - public static final String ERROR_NO_MAP_CONFIG = "error_no_map_config"; - - public static final String ERROR_NO_MAP_OUTPUT_TYPE = "error_no_map_output_type"; - - public MapConfig doOut(Collection collection) - throws ServerException - { - logger.info("MapOutputServiceImpl.doOut"); - - String url = getServletContext().getInitParameter("server-url"); - String uuid = collection.identifier(); - - Map<String, OutputMode> modes = collection.getOutputModes(); - String requestMode = ""; - if (modes.containsKey("floodmap")) { - requestMode = "floodmap"; - } - else if (modes.containsKey("map")) { - requestMode = "map"; - } - else { - throw new ServerException(ERROR_NO_MAP_OUTPUT_TYPE); - } - - try { - Document request = ClientProtocolUtils.newOutCollectionDocument( - uuid, requestMode, requestMode); - - HttpClient client = new HttpClientImpl(url); - InputStream is = client.collectionOut(request, uuid, requestMode); - - Document response = XMLUtils.parseDocument(is); - - return MapHelper.parseConfig(response); - } - catch (ConnectionException e) { - logger.error(e, e); - } - catch (IOException ioe) { - logger.error(ioe, ioe); - } - - throw new ServerException(ERROR_NO_MAP_CONFIG); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,532 +0,0 @@ -package de.intevation.flys.client.server; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.JSON; -import de.intevation.artifacts.common.utils.StringUtils; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; -import de.intevation.flys.client.shared.MapUtils; -import de.intevation.flys.client.shared.model.MapConfig; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -/* -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -*/ -/* Used by direct API call. -> Enforce GPLv3 -import org.mapfish.print.MapPrinter; -import org.mapfish.print.output.OutputFactory; -import org.mapfish.print.output.OutputFormat; - -import org.mapfish.print.utils.PJsonObject; -*/ - -public class MapPrintServiceImpl -extends HttpServlet -{ - private static final Logger log = - Logger.getLogger(MapPrintServiceImpl.class); - - protected static class Layer implements Comparable<Layer> { - - protected int pos; - protected String url; - protected String layers; - protected String description; - - public Layer() { - } - - public boolean setup(Element element) { - - Element parent = (Element)element.getParentNode(); - String parentName = parent.getAttribute("name"); - if (!(parentName.equals("map") - || parentName.equals("floodmap"))) { - return false; - } - - String ns = ArtifactNamespaceContext.NAMESPACE_URI; - - String visible = element.getAttributeNS(ns, "visible"); - String active = element.getAttributeNS(ns, "active"); - - if (visible.equals("0") || active.equals("0")) { - return false; - } - - url = element.getAttributeNS(ns, "url"); - layers = element.getAttributeNS(ns, "layers"); - description = element.getAttributeNS(ns, "description"); - - try { - pos = Integer.parseInt(element.getAttributeNS(ns, "pos")); - } - catch (NumberFormatException nfe) { - return false; - } - - return true; - } - - public Map<String, Object> toMap() { - Map<String, Object> layer = new LinkedHashMap<String, Object>(); - - layer.put("type", "WMS"); - List<Object> subLayers = new ArrayList<Object>(1); - subLayers.add(layers); - layer.put("layers", subLayers); - // XXX: osm.intevation.de mapache only offers low dpi maps - // so we need to use the uncached service - layer.put("baseURL", url.replace("http://osm.intevation.de/mapcache/?", - "http://osm.intevation.de/cgi-bin/germany.fcgi?")); - layer.put("format", "image/png"); // TODO: Make configurable. - - return layer; - } - - @Override - public int compareTo(Layer other) { - int d = pos - other.pos; - if (d < 0) return -1; - return d > 0 ? +1 : 0; - } - } // class Layer - - protected static String generateSpec( - Document descDocument, - MapConfig mapConfig, - Double minX, Double minY, - Double maxX, Double maxY, - Map<String, Object> pageSpecs - ) { - Map<String, Object> spec = new LinkedHashMap<String, Object>(); - int dpi = 254; - spec.put("layout", "A4 landscape"); - spec.put("pageSize", "A4"); - spec.put("landscape", "true"); - spec.put("srs", "EPSG:" + mapConfig.getSrid()); - spec.put("dpi", dpi); - spec.put("units", "m"); - spec.put("geodaetic", "true"); - spec.put("outputFormat", "pdf"); - - spec.putAll(pageSpecs); - - String ns = ArtifactNamespaceContext.NAMESPACE_URI; - - List<Layer> ls = new ArrayList<Layer>(); - Layer l = new Layer(); - - NodeList facets = descDocument.getElementsByTagNameNS(ns, "facet"); - - for (int i = 0, N = facets.getLength(); i < N; ++i) { - Element element = (Element)facets.item(i); - if (l.setup(element)) { - ls.add(l); - l = new Layer(); - } - } - - // Establish Z order. - Collections.sort(ls); - - List<Object> layers = new ArrayList<Object>(ls.size()); - - for (int i = ls.size()-1; i >= 0; --i) { - layers.add(ls.get(i).toMap()); - } - - spec.put("layers", layers); - spec.put("name", "Name"); - - List<Object> pages = new ArrayList<Object>(1); - - - Map<String, Object> page = new LinkedHashMap<String, Object>(); - - List<Object> bounds = new ArrayList<Object>(4); - bounds.add(minX); - bounds.add(minY); - bounds.add(maxX); - bounds.add(maxY); - page.put("bbox", bounds); - - /* - bounds.add(Double.valueOf((minX+maxX)*0.5)); - bounds.add(Double.valueOf((minY+maxY)*0.5)); - - page.put("center", bounds); - page.put("scale", Integer.valueOf(50000)); - */ - - page.put("rotation", Integer.valueOf(0)); - - // This may overwrite default settings above - page.putAll(pageSpecs); - - pages.add(page); - spec.put("pages", pages); - - List<Object> legends = new ArrayList<Object>(layers.size()); - - for (Layer layer: ls) { - Map<String, Object> legend = new LinkedHashMap<String, Object>(); - List<Object> classes = new ArrayList<Object>(1); - Map<String, Object> clazz = new LinkedHashMap<String, Object>(); - String lgu = MapUtils.getLegendGraphicUrl(layer.url, layer.layers, dpi); - clazz.put("icon", lgu); - clazz.put("name", layer.description); - classes.add(clazz); - legend.put("classes", classes); - legend.put("name", layer.description); - legends.add(legend); - } - - spec.put("legends", legends); - - return JSON.toJSONString(spec); - } - - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException - { - log.info("MapPrintServiceImpl.doGet"); - - String uuid = req.getParameter("uuid"); - - if (uuid == null || !StringUtils.checkUUID(uuid)) { - throw new ServletException("Missing or misspelled UUID"); - } - - String minXS = req.getParameter("minx"); - String maxXS = req.getParameter("maxx"); - String minYS = req.getParameter("miny"); - String maxYS = req.getParameter("maxy"); - - Double minX = null; - Double maxX = null; - Double minY = null; - Double maxY = null; - - if (minXS != null && maxXS != null - && minYS != null && maxYS != null) { - log.debug("all parameters found -> parsing"); - try { - minX = Double.parseDouble(minXS); - minY = Double.parseDouble(minYS); - maxX = Double.parseDouble(maxXS); - maxY = Double.parseDouble(maxYS); - } - catch (NumberFormatException nfe) { - throw new ServletException("Misspelled minX, minY, maxX or maxY"); - } - } - - String mapType = req.getParameter("maptype"); - - if (mapType == null || !mapType.equals("floodmap")) { - mapType = "map"; - } - - // Retrieve print settings from request - Map<String, Object> pageSpecs = new HashMap<String, Object>(); - Map<String, Object> data = new HashMap<String, Object>(); - List<Object> payload = new ArrayList<Object>(); - data.put("data", payload); - Enumeration paramNames = req.getParameterNames(); - List<String> params = Collections.list(paramNames); - Collections.sort(params); - for (String paramName : params) { - if (paramName.startsWith("mapfish_data_")) { - // You can add mapfish_data variables that will be mapped - // to a info value pairs to provide meta data for the map - // The the info part starts with a number for sorting that - // number will be stripped - String paramValue = req.getParameter(paramName); - Map<String, Object> data3 = new HashMap<String, Object>(); - int order = 0; - try { - order = Integer.parseInt(paramName.substring(13, 14)); - data3.put("info", paramName.substring(14)); - } catch (NumberFormatException nfe) { - data3.put("info", paramName.substring(13)); - payload.add(data3); - } - if (paramValue.equals("null")) - data3.put("value", ""); - else - data3.put("value", paramValue); - payload.add(data3); - } else if (paramName.startsWith("mapfish_")) { - String paramValue = req.getParameter(paramName); - if (paramValue.equals("null")) - paramValue = ""; - pageSpecs.put(paramName.substring(8), paramValue); - } - } - if (!payload.isEmpty()) { - pageSpecs.put("data", data); - List<Object> columns = new ArrayList<Object>(); - columns.add("info"); - columns.add("value"); - data.put("columns", columns); - } - - String url = getURL(); - - Document requestOut = - ClientProtocolUtils.newOutCollectionDocument( - uuid, mapType, mapType); - Document requestDesc = - ClientProtocolUtils.newDescribeCollectionDocument(uuid); - - Document outDocument; - Document descDocument; - - try { - HttpClient client = new HttpClientImpl(url); - - descDocument = (Document)client.doCollectionAction( - requestDesc, uuid, new DocumentResponseHandler()); - - InputStream is = client.collectionOut( - requestOut, uuid, mapType); - - try { - outDocument = XMLUtils.parseDocument(is); - } - finally { - is.close(); - is = null; - } - - } - catch (ConnectionException ce) { - log.error(ce); - throw new ServletException(ce); - } - - MapConfig mapConfig = MapHelper.parseConfig(outDocument); - - if (minX == null) { - log.debug("parameters missing -> fallback to max extent"); - String [] parts = mapConfig.getMaxExtent().split("\\s+"); - if (parts.length < 4) { - throw new ServletException( - "Max extent has less than 4 values"); - } - try { - minX = Double.valueOf(parts[0]); - minY = Double.valueOf(parts[1]); - maxX = Double.valueOf(parts[2]); - maxY = Double.valueOf(parts[3]); - } - catch (NumberFormatException nfe) { - throw new ServletException(nfe); - } - } - if (log.isDebugEnabled()) { - log.debug("minX: " + minX); - log.debug("maxX: " + maxX); - log.debug("minY: " + minY); - log.debug("maxY: " + maxY); - } - - String spec = generateSpec( - descDocument, - mapConfig, - minX, minY, - maxX, maxY, - pageSpecs); - - if (log.isDebugEnabled()) { - log.debug("Generated spec:"); - log.debug(spec); - //System.err.println(spec); - } - - producePDF(spec, resp); - } - - protected String getURL() throws ServletException { - String url = getServletContext().getInitParameter("server-url"); - if (url == null) { - throw new ServletException("Missing server-url"); - } - return url; - } - - private static final String encode(String s) { - try { - return URLEncoder.encode(s, "UTF-8"); - } - catch (UnsupportedEncodingException usee) { - // Should not happen. - return s; - } - } - - protected void producePDF(String json, HttpServletResponse resp) - throws ServletException, IOException - { - String printUrl = getInitParameter("print-url"); - - if (printUrl == null) { - throw new ServletException("Missing 'print-url' in web.xml"); - } - - String url = printUrl + "/print.pdf?spec=" + encode(json); - - org.apache.commons.httpclient.HttpClient client = - new org.apache.commons.httpclient.HttpClient( - new MultiThreadedHttpConnectionManager()); - - // FIXME: The request is not authenticated. - // Currently this is not a problem because /flys/map-print - // is whitelisted in GGInAFilter. - GetMethod get = new GetMethod(url); - int result = client.executeMethod(get); - InputStream in = get.getResponseBodyAsStream(); - - if (in != null) { - try { - OutputStream out = resp.getOutputStream(); - try { - byte [] buf = new byte[4096]; - int r; - if (result < 200 || result >= 300) { - resp.setContentType("text/plain"); - } else { - // Only send content disposition and filename content - // type when we have a pdf - resp.setHeader("Content-Disposition", - "attachment;filename=flys-karte.pdf"); - resp.setContentType("application/pdf"); - } - while ((r = in.read(buf)) >= 0) { - out.write(buf, 0, r); - } - out.flush(); - } - finally { - out.close(); - } - } - finally { - in.close(); - } - } - } - - /* Use this if you want directly call the MapPrinter. Enforces GPLv3! - - protected MapPrinter getMapPrinter() throws ServletException, IOException { - String configPath = getInitParameter("config"); - if (configPath == null) { - throw new ServletException("Missing configuration in web.xml"); - } - - File configFile = new File(configPath); - if (!configFile.isAbsolute()) { - configFile = new File(getServletContext().getRealPath(configPath)); - } - - if (!configFile.isFile() || !configFile.canRead()) { - throw new ServletException("Cannot read '" + configFile + "'"); - } - - return new MapPrinter(configFile); - } - - protected void producePDF(String json, HttpServletResponse resp) - throws ServletException, IOException - { - PJsonObject jsonSpec = MapPrinter.parseSpec(json); - - MapPrinter printer = getMapPrinter(); - - OutputFormat outputFormat = OutputFactory.create( - printer.getConfig(), jsonSpec); - - resp.setHeader("Content-Disposition", "attachment;filename=print.pdf"); - resp.setHeader("Content-Type", "application/pdf"); - - // XXX: Streaming the generated PDF directly - // to the request out does not work. :-/ - File tmpFile = File.createTempFile("map-printing", null); - - try { - OutputStream out = - new BufferedOutputStream( - new FileOutputStream(tmpFile)); - try { - outputFormat.print(printer, jsonSpec, out, ""); - out.flush(); - } - catch (Exception e) { - log.error(e); - throw new ServletException(e); - } - finally { - printer.stop(); - out.close(); - } - InputStream in = - new BufferedInputStream( - new FileInputStream(tmpFile)); - out = resp.getOutputStream(); - try { - byte [] buf = new byte[4096]; - int r; - while ((r = in.read(buf)) >= 0) { - out.write(buf, 0, r); - } - out.flush(); - } - finally { - in.close(); - out.close(); - } - } - finally { - if (tmpFile.exists()) { - tmpFile.delete(); - } - } - } - */ -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapUrlServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; - -import java.util.Map; -import java.util.HashMap; - -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.MapUrlService; - - -public class MapUrlServiceImpl -extends RemoteServiceServlet -implements MapUrlService -{ - - private static final Logger logger = - Logger.getLogger(MapUrlServiceImpl.class); - - - public Map<String, String> getUrls() - throws ServerException - { - logger.info("MapUrlServiceImpl.getUrls"); - Map<String, String> urls = new HashMap<String, String>(); - - InputStream in = getServletContext().getResourceAsStream("/WEB-INF/wms-services.xml"); - - Document doc = XMLUtils.parseDocument(in); - - NodeList list = doc.getElementsByTagName("wms"); - for (int i = 0; i < list.getLength(); i++) { - Element e = (Element) list.item(i); - urls.put(e.getAttribute("url"), e.getAttribute("name")); - } - - return urls; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; - -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -import de.intevation.flys.client.client.services.MetaDataService; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.model.DataCageTree; - -import de.intevation.flys.client.server.meta.Converter; - -/** - * Service that returns certain meta-data from the backends data, polished to - * inclusion into current project. - */ -public class MetaDataServiceImpl -extends RemoteServiceServlet -implements MetaDataService -{ - /** Our very own logger. */ - private static final Logger logger = - Logger.getLogger(MetaDataServiceImpl.class); - - public static final String ERROR_NO_META_DATA_FOUND = - "error_no_meta_data_found"; - - - /** - * @param locale needed for i18n. - * @param artifactId ID of masterartifact (can be null) - * @param userId can be null - * @param outs can be null - * @param parameters can be null or parameters like "load-system:true;key:value" - */ - @Override - public DataCageTree getMetaData( - String locale, - String artifactId, - String userId, - String outs, - String parameters - ) throws ServerException - { - logger.info("MetaDataService.getMetaData"); - - // Create the query document. - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element meta = ec.create("meta"); - - if (artifactId != null) { - Element artifactEl = ec.create("artifact-id"); - artifactEl.setAttribute("value", artifactId); - meta.appendChild(artifactEl); - } - - if (userId != null) { - Element userEl = ec.create("user-id"); - userEl.setAttribute("value", userId); - meta.appendChild(userEl); - } - - if (outs != null) { - Element outsEl = ec.create("outs"); - outsEl.setAttribute("value", outs); - meta.appendChild(outsEl); - } - - if (parameters != null) { - Element paramsEl = ec.create("parameters"); - paramsEl.setAttribute("value", parameters); - meta.appendChild(paramsEl); - } - - doc.appendChild(meta); - - // Fire. - HttpClient client = new HttpClientImpl(url, locale); - - try { - Converter converter = new Converter(); - return converter.convert(client.callService(url, "metadata", doc)); - } - catch (ConnectionException ce) { - ce.printStackTrace(); - } - - throw new ServerException(ERROR_NO_META_DATA_FOUND); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ModuleServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -package de.intevation.flys.client.server; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.flys.client.client.services.ModuleService; -import de.intevation.flys.client.server.auth.User; -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.DefaultModule; -import de.intevation.flys.client.shared.model.Module; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -public class ModuleServiceImpl -extends RemoteServiceServlet -implements ModuleService -{ - private static final Logger logger = - Logger.getLogger(ModuleServiceImpl.class); - - public static final String XPATH_MODULES = "/art:modules/art:module"; - - public static final String ERROR_NO_MODULES_FOUND = - "error_no_module_found"; - - @Override - public Module[] list(String locale) throws ServerException { - User user = this.getUser(); - - logger.info("ModuleService.list"); - - String url = getServletContext().getInitParameter("server-url"); - - // create dummy xml - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element dummy = ec.create("modules"); - doc.appendChild(dummy); - - HttpClient client = new HttpClientImpl(url, locale); - try { - Document result = client.callService(url, "modules", doc); - - NodeList list = (NodeList) XMLUtils.xpath( - result, - XPATH_MODULES, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (list == null) { - logger.warn("No modules found."); - - throw new ServerException(ERROR_NO_MODULES_FOUND); - } - - int num = list.getLength(); - - List<Module> modules = new ArrayList<Module>(list.getLength()); - for(int i =0; i < num; i++) { - Element em = (Element)list.item(i); - String name = em.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); - String localname = em.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "localname"); - String strselected = em.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "selected"); - boolean selected = strselected == null ? false : - strselected.equalsIgnoreCase("true"); - logger.debug("Found module " + name + " " + localname); - if (user == null || user.canUseFeature("module:" + name)) { - modules.add(new DefaultModule(name, localname, selected)); - } - } - return modules.toArray(new Module[modules.size()]); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_MODULES_FOUND); - } -} - -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ProxyServlet.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; - -import javax.servlet.ServletConfig; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.server.auth.User; - -/** - * Implements a Proxy for HTTP Requests - */ -public class ProxyServlet -extends HttpServlet -{ - private static Logger logger = Logger.getLogger(ProxyServlet.class); - private String remoteurl; - - @Override - public void init(ServletConfig config) { - this.remoteurl = config.getInitParameter("remoteurl"); - } - - @Override - public void doPost(HttpServletRequest req, HttpServletResponse resp) { - } - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) - throws IOException { - HttpClient httpclient = new DefaultHttpClient(); - - String requesturi = req.getRequestURI(); - String query = req.getQueryString(); - - HttpGet httpget = new HttpGet(this.remoteurl + "?" + query); - - boolean debug = logger.isDebugEnabled(); - - for (Enumeration e = req.getHeaderNames(); e.hasMoreElements();) { - String name = (String)e.nextElement(); - for (Enumeration f = req.getHeaders(name); f.hasMoreElements();) { - String value = (String)f.nextElement(); - if (debug) { - logger.debug( - "Adding request header " + name + " : " + value); - } - httpget.addHeader(name, value); - } - } - - HttpResponse response = httpclient.execute(httpget); - - StatusLine statusline = response.getStatusLine(); - if (debug) { - logger.debug("Response statuscode " + statusline.getStatusCode()); - } - resp.setStatus(statusline.getStatusCode()); - - Header[] headers = response.getAllHeaders(); - for(Header header : headers) { - if (debug) { - logger.debug( - "Adding response header " + header.getName() + - " : " + header.getValue()); - } - resp.setHeader(header.getName(), header.getValue()); - } - - HttpEntity entity = response.getEntity(); - if (entity != null) { - InputStream instream = entity.getContent(); - byte [] buf = new byte[4096]; - try { - OutputStream outstream = resp.getOutputStream(); - try { - int read; - while ((read = instream.read(buf)) >= 0) { - outstream.write(buf, 0, read); - } - outstream.flush(); - } - finally { - outstream.close(); - } - } - finally { - instream.close(); - } - } - } - - private User getUser(HttpServletRequest req) { - HttpSession session = req.getSession(); - return (User)session.getAttribute("user"); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/RemoteServiceServlet.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package de.intevation.flys.client.server; - -import de.intevation.flys.client.server.auth.User; - -import javax.servlet.http.HttpSession; - -public class RemoteServiceServlet -extends com.google.gwt.user.server.rpc.RemoteServiceServlet -{ - /** - * Return the current logged in user from the HTTP Session - */ - public User getUser() { - HttpSession session = this.getThreadLocalRequest().getSession(); - return (User)session.getAttribute("user"); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/RemoveArtifactServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package de.intevation.flys.client.server; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.client.services.RemoveArtifactService; - - -/** - * Implementation of RemoveArtifactService . - */ -public class RemoveArtifactServiceImpl -extends DescribeCollectionServiceImpl -implements RemoveArtifactService -{ - private static final Logger logger = - Logger.getLogger(RemoveArtifactServiceImpl.class); - - - public Collection remove( - Collection collection, - String artifactId, - String locale) - throws ServerException - { - logger.info("RemoveArtifactServiceImpl.remove"); - - String url = getServletContext().getInitParameter("server-url"); - - return CollectionHelper.removeArtifact(collection, artifactId, url, locale); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -package de.intevation.flys.client.server; - -import java.io.InputStream; -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import org.apache.commons.lang.StringEscapeUtils; - -import de.intevation.flys.client.client.services.ReportService; - -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -public class ReportServiceImpl -extends RemoteServiceServlet -implements ReportService -{ - private static final Logger logger = - Logger.getLogger(ReportServiceImpl.class); - - - @Override - public String report( - String collectionId, - String locale, - String out - ) { - logger.info("report: " + collectionId + " " + out); - - String url = getServletContext().getInitParameter("server-url"); - - Document request = ClientProtocolUtils.newOutCollectionDocument( - collectionId, - out, - "report"); - - InputStream in = null; - try { - HttpClient client = new HttpClientImpl(url, locale); - in = client.collectionOut(request, collectionId, out); - - if (in == null) { - logger.debug("report: no report"); - return null; - } - - Document report = XMLUtils.parseDocument(in); - - return buildReport(report); - } - catch (IOException ioe) { - ioe.printStackTrace(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally { - if (in != null) { - try { - in.close(); - } - catch (IOException ioe) { - } - } - } - - return "error processing error report"; - } - - - /** Returns String containing markup that shows the report message. */ - protected static String buildReport(Document document) { - - NodeList problems = document.getElementsByTagName("problem"); - - StringBuilder global = new StringBuilder(); - StringBuilder kms = new StringBuilder(); - - for (int i = 0, N = problems.getLength(); i < N; ++i) { - - Element element = (Element)problems.item(i); - - String km = element.getAttribute("km"); - String msg = element.getTextContent(); - - if (km.length() > 0) { - kms.append("<li><strong>KM ") - .append(StringEscapeUtils.escapeHtml(km)) - .append("</strong>: ") - .append(StringEscapeUtils.escapeHtml(msg)) - .append("</li>"); - } - else { - global.append("<li>") - .append(StringEscapeUtils.escapeHtml(msg)) - .append("</li>"); - } - } - - StringBuilder sb = new StringBuilder("<ul>") - .append(global) - .append(kms) - .append("</ul>"); - - return sb.toString(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/RiverInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,380 +0,0 @@ -package de.intevation.flys.client.server; - -import java.text.DateFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import javax.xml.xpath.XPathConstants; - -import org.apache.log4j.Logger; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.client.services.RiverInfoService; -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.DefaultGaugeInfo; -import de.intevation.flys.client.shared.model.DefaultMeasurementStation; -import de.intevation.flys.client.shared.model.DefaultRiverInfo; -import de.intevation.flys.client.shared.model.GaugeInfo; -import de.intevation.flys.client.shared.model.MeasurementStation; -import de.intevation.flys.client.shared.model.RiverInfo; - - -/** - * GWT Service to serve the gauge and measurement station info - * - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class RiverInfoServiceImpl -extends RemoteServiceServlet -implements RiverInfoService -{ - private static final Logger logger = - Logger.getLogger(RiverInfoServiceImpl.class); - - public static final String ERROR_NO_RIVER_INFO_FOUND = - "error_no_riverinfo_found"; - - private static final String XPATH_RIVER = - "/art:river-info/art:river"; - - private static final String XPATH_STATIONS = - "/art:river-info/art:measurement-stations/art:measurement-station"; - - private static final String XPATH_GAUGES = "/art:river-info/art:gauges/art:gauge"; - - public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( - DateFormat.SHORT, Locale.GERMANY); - - public RiverInfo getGauges(String river) throws ServerException { - logger.info("RiverInfoServiceImpl.getRiverInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element riverele = ec.create("river"); - riverele.setTextContent(river); - - doc.appendChild(riverele); - - HttpClient client = new HttpClientImpl(url); - - try { - Document result = client.callService(url, "gaugeoverviewinfo", doc); - - DefaultRiverInfo riverinfo = getRiverInfo(result); - List<GaugeInfo>gauges = createGauges(result, riverinfo.getName(), - riverinfo.isKmUp(), riverinfo.getWstUnit()); - - - riverinfo.setGauges(gauges); - - logger.debug("Finished RiverInfoService.getGauges."); - - return riverinfo; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - logger.warn("No gauge found"); - throw new ServerException(ERROR_NO_RIVER_INFO_FOUND); - } - - public RiverInfo getMeasurementStations(String river) throws ServerException { - logger.info("RiverInfoServiceImpl.getMeasurementStations"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element riverele = ec.create("river"); - riverele.setTextContent(river); - - doc.appendChild(riverele); - - HttpClient client = new HttpClientImpl(url); - - try { - Document result = client.callService(url, "measurementstationinfo", doc); - - DefaultRiverInfo riverinfo = getRiverInfo(result); - List<MeasurementStation> mstations = createMeasurementStations( - result, riverinfo.getName(), riverinfo.isKmUp()); - - riverinfo.setMeasurementStations(mstations); - - logger.debug("Finished MeasurementStationInfoService."); - - return riverinfo; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - logger.warn("No measurement station found"); - throw new ServerException(ERROR_NO_RIVER_INFO_FOUND); - } - - /** - * Avoids NullPointerException when parsing double value - */ - private Double parseDouble(String value) { - if (value == null || value.isEmpty()) { - return null; - } - try { - return Double.valueOf(value); - } - catch(NumberFormatException e) { - logger.error(e, e); - return null; - } - } - - private Long parseLong(String value) { - if (value == null || value.isEmpty()) { - return null; - } - try { - return Long.valueOf(value); - } - catch(NumberFormatException e) { - logger.error(e, e); - return null; - } - } - - private Integer parseInteger(String value) { - if (value == null || value.isEmpty()) { - return null; - } - try { - return Integer.valueOf(value); - } - catch(NumberFormatException e) { - logger.error(e, e); - return null; - } - } - - private Date parseDate(String value) { - if (value == null || value.isEmpty()) { - return null; - } - try { - return DATE_FORMAT.parse(value); - } - catch(ParseException e) { - logger.error(e, e); - return null; - } - } - - private List<MeasurementStation> createMeasurementStations( - Document result, String rivername, boolean kmup) { - - NodeList stationnodes = (NodeList) XMLUtils.xpath( - result, - XPATH_STATIONS, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = stationnodes == null ? 0 : stationnodes.getLength(); - - ArrayList<MeasurementStation> mstations = new ArrayList<MeasurementStation>(num); - - if (num == 0) { - logger.warn("No measurement station found."); - } - else { - logger.debug("Found " + num + " measurement stations."); - - for (int i = 0; i < num; i++) { - Element stationele = (Element)stationnodes.item(i); - - String mname = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); - String mstart = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "start"); - String mend = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "end"); - String mstation = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "station"); - String mtype = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "type"); - String riverside = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "riverside"); - String mid = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "id"); - String moperator = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "operator"); - String mstarttime = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "starttime"); - String mstoptime = stationele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "stoptime"); - - String gaugename = null; - - Element gaugeele = (Element)stationele.getFirstChild(); - if (gaugeele != null) { - gaugename = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); - } - - - logger.debug("Found measurement station with name " + mname); - - MeasurementStation station = new DefaultMeasurementStation( - rivername, - mname, - parseInteger(mid), - parseDouble(mstation), - parseDouble(mstart), - parseDouble(mend), - kmup, - riverside, - mtype, - moperator, - parseDate(mstarttime), - parseDate(mstoptime), - gaugename - ); - - mstations.add(station); - } - } - return mstations; - } - - private List<GaugeInfo> createGauges( - Document result, String rivername, Boolean kmup, String rwstunit) { - NodeList gaugenodes = (NodeList) XMLUtils.xpath( - result, - XPATH_GAUGES, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - int num = gaugenodes == null ? 0 : gaugenodes.getLength(); - - ArrayList<GaugeInfo> gauges = new ArrayList<GaugeInfo>(num); - - if (num == 0) { - logger.warn("No gauge info found."); - } - else { - logger.debug("Found " + num + " gauges."); - - for (int i = 0; i < num; i++) { - Element gaugeele = (Element)gaugenodes.item(i); - - String gname = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); - String gstart = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "start"); - String gend = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "end"); - String gdatum = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "datum"); - String gaeo = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "aeo"); - String gminq = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "minq"); - String gminw = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "minw"); - String gmaxq = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "maxq"); - String gmaxw = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "maxw"); - String gstation = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "station"); - String gofficial = gaugeele.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "official"); - - logger.debug("Found gauge with name " + gname); - - GaugeInfo gaugeinfo = new DefaultGaugeInfo( - rivername, - gname, - kmup, - parseDouble(gstation), - parseDouble(gstart), - parseDouble(gend), - parseDouble(gdatum), - parseDouble(gaeo), - parseDouble(gminq), - parseDouble(gmaxq), - parseDouble(gminw), - parseDouble(gmaxw), - rwstunit, - parseLong(gofficial) - ); - - gauges.add(gaugeinfo); - } - } - return gauges; - } - - private DefaultRiverInfo getRiverInfo(Document result) { - Element riverresp = (Element) XMLUtils.xpath( - result, - XPATH_RIVER, - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE); - - String rname = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); - String rkmup = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "kmup"); - String rstart = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "start"); - String rend = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "end"); - String rwstunit = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "wstunit"); - String rminq = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "minq"); - String rmaxq = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "maxq"); - String rofficial = riverresp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "official"); - - logger.debug("River is " + rname); - - boolean kmup = rkmup.equalsIgnoreCase("true"); - DefaultRiverInfo riverinfo = new DefaultRiverInfo( - rname, - kmup, - parseDouble(rstart), - parseDouble(rend), - rwstunit, - parseDouble(rminq), - parseDouble(rmaxq), - parseLong(rofficial) - ); - - return riverinfo; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -package de.intevation.flys.client.server; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.flys.client.client.services.RiverService; -import de.intevation.flys.client.server.auth.User; -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.DefaultRiver; -import de.intevation.flys.client.shared.model.River; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - - -/** - * This interface provides a method to list the supported rivers of the artifact - * server. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class RiverServiceImpl -extends RemoteServiceServlet -implements RiverService -{ - /** Private logger. */ - private static final Logger logger = - Logger.getLogger(RiverServiceImpl.class); - - /** The XPath string that points to the rivers in the resulting document.*/ - public static final String XPATH_RIVERS = "/art:rivers/art:river"; - - /** The error message key that is thrown if an error occured while reading - * the supported rivers from server.*/ - public static final String ERROR_NO_RIVERS_FOUND = "error_no_rivers_found"; - - - /** Get river list. */ - @Override - public River[] list(String locale) - throws ServerException - { - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - doc.appendChild(ec.create("action")); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document res = client.callService(url, "rivers", doc); - - NodeList rivers = (NodeList) XMLUtils.xpath( - res, - XPATH_RIVERS, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (rivers == null || rivers.getLength() == 0) { - throw new ServerException(ERROR_NO_RIVERS_FOUND); - } - - int count = rivers.getLength(); - - List<River> theRivers = new ArrayList<River>(count); - User user = this.getUser(); - - for (int i = 0; i < count; i++) { - Element tmp = (Element)rivers.item(i); - - String name = tmp.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); - - if (name.length() > 0 - && (user == null || user.canUseFeature("river:" + name))) { - theRivers.add(new DefaultRiver(name)); - } - } - - return theRivers.toArray(new River[theRivers.size()]); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_RIVERS_FOUND); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/SQKMChartServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -package de.intevation.flys.client.server; - -import org.apache.log4j.Logger; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; - -public class SQKMChartServiceImpl -extends HttpServlet -{ - private static final Logger log = - Logger.getLogger(FixingsKMChartServiceImpl.class); - - public static final String SERVICE_NAME = "sq-km-chart"; - - public SQKMChartServiceImpl() { - } - - public void doGet(HttpServletRequest req, HttpServletResponse resp) { - - log.info("SQKMChartServiceImpl.doGet"); - - String url = getServletContext().getInitParameter("server-url"); - String locale = req.getParameter("locale"); - String filter = req.getParameter("filter"); - - if (filter == null || filter.length() == 0) { - log.warn("Missing 'filter' parameter."); - return; - } - - if (locale == null || locale.length() == 0) { - locale = "de"; - } - - Document filterDoc = XMLUtils.jsonToXML(filter); - - if (filterDoc == null) { - log.warn("Creating filter document failed."); - return; - } - - InputStream in; - - try { - HttpClient client = new HttpClientImpl(url, locale); - in = (InputStream)client.callService( - url, // XXX: Why? The URL is passed by construction already. - SERVICE_NAME, - filterDoc, - new StreamResponseHandler()); - } - catch (ConnectionException ce) { - log.error(ce); - return; - } - - resp.setHeader("Content-Type", guessMIMEType(filterDoc)); - - try { - OutputStream out = resp.getOutputStream(); - - byte [] buf = new byte[4096]; - int i = -1; - while ((i = in.read(buf)) >= 0) { - out.write(buf, 0, i); - } - out.flush(); - } - catch (IOException ioe) { - log.error(ioe); - } - finally { - try { in.close(); } - catch (IOException ioe) { /* ignored */ } - } - } - - protected static String guessMIMEType(Document document) { - - NodeList formats = document.getElementsByTagName("format"); - - String format = "png"; - - if (formats.getLength() > 0) { - String type = ((Element)formats.item(0)).getAttribute("type"); - if (type.length() > 0) { - format = type; - } - } - - return "image/" + format; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/SedimentLoadInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.flys.client.client.services.SedimentLoadInfoService; -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; -import de.intevation.flys.client.shared.model.SedimentLoadInfoObjectImpl; - - -public class SedimentLoadInfoServiceImpl -extends RemoteServiceServlet -implements SedimentLoadInfoService -{ - private static final Logger logger = - Logger.getLogger(SedimentLoadInfoServiceImpl.class); - - public static final String ERROR_NO_SEDIMENTLOADINFO_FOUND = - "error_no_sedimentloadinfo_found"; - - @Override - public SedimentLoadInfoObject[] getSedimentLoadInfo( - String locale, - String river, - String type, - double startKm, - double endKm) - throws ServerException - { - logger.info("SedimentLoadInfoServiceImpl.getSedimentLoadInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element riverEl = ec.create("river"); - Element location = ec.create("location"); - Element from = ec.create("from"); - Element to = ec.create("to"); - Element typeEl = ec.create("type"); - riverEl.setTextContent(river); - from.setTextContent(String.valueOf(startKm)); - to.setTextContent(String.valueOf(endKm)); - typeEl.setTextContent(type); - - location.appendChild(from); - location.appendChild(to); - riverEl.appendChild(location); - riverEl.appendChild(typeEl); - doc.appendChild(riverEl); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document result = client.callService(url, "sedimentloadinfo", doc); - - logger.debug("Extract sedimentload info objects now."); - SedimentLoadInfoObject[] objects = - extractSedimentLoadInfoObjects(result); - - if (objects != null && objects.length > 0) { - return objects; - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_SEDIMENTLOADINFO_FOUND); - } - - - /** - * Extracts all distance info objects from <i>result</i> document. - * - * @param result The document retrieved by the server. - * - * @return a list of DistanceInfoObjects. - */ - protected SedimentLoadInfoObject[] extractSedimentLoadInfoObjects( - Document result) - throws ServerException - { - NodeList list = result.getElementsByTagName("sedimentload"); - - if (list == null || list.getLength() == 0) { - logger.warn("No sedimentload info found."); - throw new ServerException(ERROR_NO_SEDIMENTLOADINFO_FOUND); - } - - int num = list.getLength(); - logger.debug("Response contains " + num + " objects."); - - List<SedimentLoadInfoObject> objects = - new ArrayList<SedimentLoadInfoObject>(num); - - for (int i = 0; i < num; i++) { - SedimentLoadInfoObject obj = buildSedimentLoadInfoObject( - (Element)list.item(i)); - - if (obj != null) { - objects.add(obj); - } - } - - logger.debug("Retrieved " + objects.size() + " sediment loads."); - - return (SedimentLoadInfoObject[]) - objects.toArray(new SedimentLoadInfoObject[num]); - } - - - /** - * Extracts information for a single distance info object and intializes an - * DistanceInfoObject with them. - * - * @param node The node that contains the information. - * - * @return a valid DistanceInfoObject. - */ - protected SedimentLoadInfoObject buildSedimentLoadInfoObject(Element node) { - - String desc = node.getAttribute("description").trim(); - String date = node.getAttribute("date").trim(); - - if (desc.length() > 0 && date.length() > 0) { - return new SedimentLoadInfoObjectImpl(desc, date); - } - - logger.warn("Invalid sediment load info object found."); - - return null; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.client.services.SetCollectionNameService; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class SetCollectionNameServiceImpl -extends DoCollectionAction -implements SetCollectionNameService -{ - private static final Logger logger = - Logger.getLogger(SetCollectionNameServiceImpl.class); - - - public void setName(Collection c) - throws ServerException - { - logger.info("Set name of collection: " + c.identifier()); - - String url = getServletContext().getInitParameter("server-url"); - - String name = c.getName(); - Document set = ClientProtocolUtils.newSetCollectionNameDocument(name); - - doAction(c, set, url); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.utils.ClientProtocolUtils; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.client.services.SetCollectionTTLService; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class SetCollectionTTLServiceImpl -extends DoCollectionAction -implements SetCollectionTTLService -{ - private static final Logger logger = - Logger.getLogger(SetCollectionTTLServiceImpl.class); - - - public static final String XPATH_RESULT = "/art:result/text()"; - public static final String OPERATION_FAILURE = "FAILED"; - - public void setTTL(Collection c) - throws ServerException - { - logger.info("Set ttl of collection: " + c.identifier()); - - String url = getServletContext().getInitParameter("server-url"); - - long ttl = c.getTTL(); - String value = null; - - if (ttl == 0) { - value = "INF"; - } - else if (ttl < 0) { - value = "DEFAULT"; - } - else { - value = String.valueOf(ttl); - } - - Document set = ClientProtocolUtils.newSetCollectionTTLDocument(value); - - doAction(c, set, url); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/StepForwardServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ -package de.intevation.flys.client.server; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; -import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.shared.model.Artifact; -import de.intevation.flys.client.shared.model.ArtifactDescription; -import de.intevation.flys.client.shared.model.Data; -import de.intevation.flys.client.shared.model.DataItem; -import de.intevation.flys.client.client.services.StepForwardService; - - -/** - * This interface provides a method that bundles the artifact specific - * operations FEED and ADVANCE. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class StepForwardServiceImpl -extends AdvanceServiceImpl -implements StepForwardService -{ - private static final Logger logger = - Logger.getLogger(StepForwardServiceImpl.class); - - - /** XPath that points to the result type of a feed or advance operation.*/ - public static final String XPATH_RESULT = "/art:result/@art:type"; - - /** XPath that points to the result type of a feed or advance operation.*/ - public static final String XPATH_RESULT_MSG = "/art:result/text()"; - - /** A constant that marks errors.*/ - public static final String OPERATION_FAILURE = "FAILURE"; - - /** The error message key that is thrown if an error occured while feeding - * new data.*/ - public static final String ERROR_FEED_DATA = "error_feed_data"; - - - /** - * This method wraps the artifact operations FEED and ADVANCE. FEED is - * always triggerd, ADVANCE only, if there is at least one reachable state. - * - * @param locale The locale used for the request. - * @param artifact The artifact that needs to be fed. - * @param data An array of Data objects that contain the information that - * - * @return the modified artifact. - */ - public Artifact go(String locale, Artifact artifact, Data[] data) - throws ServerException - { - logger.info("StepForwardServiceImpl.go"); - - String url = getServletContext().getInitParameter("server-url"); - - Artifact afterFeed = feed(url, locale, artifact, data); - - if (afterFeed == null) { - logger.warn("StepForwardService.feed() - FAILED"); - throw new ServerException(ERROR_FEED_DATA); - } - - ArtifactDescription desc = afterFeed.getArtifactDescription(); - String[] reachable = desc.getReachableStates(); - - if (reachable == null || reachable.length == 0) { - logger.debug("Did not find any reachable state."); - return afterFeed; - } - - // We use the first reachable state as default target, maybe we need to - // change this later. - return advance(locale, afterFeed, reachable[0]); - } - - - /** - * This method triggers the FEED operation. - * - * @param url The url of the artifact server. - * @param artifact The artifact that needs to be fed. - * @param data An array of Data objects that contain the information that - * are used for the FEED operation. - * - * @return a new artifact parsed from the description of FEED. - */ - protected Artifact feed( - String url, - String locale, - Artifact artifact, - Data[] data) - throws ServerException - { - logger.info("StepForwardServiceImpl.feed"); - - Document feed = ClientProtocolUtils.newFeedDocument( - artifact.getUuid(), - artifact.getHash(), - createKVP(data)); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document description = (Document) client.feed( - new de.intevation.artifacts.httpclient.objects.Artifact( - artifact.getUuid(), - artifact.getHash()), - feed, - new DocumentResponseHandler()); - - if (description == null) { - logger.warn("StepForwardService.feed() - FAILED"); - throw new ServerException(ERROR_FEED_DATA); - } - - String result = XMLUtils.xpathString( - description, - XPATH_RESULT, - ArtifactNamespaceContext.INSTANCE); - - if (result == null || !result.equals(OPERATION_FAILURE)) { - logger.debug("StepForwardService.feed() - SUCCESS"); - return (Artifact) new FLYSArtifactCreator().create(description); - } - else if (result != null && result.equals(OPERATION_FAILURE)) { - String msg = XMLUtils.xpathString( - description, - XPATH_RESULT_MSG, - ArtifactNamespaceContext.INSTANCE); - throw new ServerException(msg); - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - logger.warn("StepForwardService.feed() - FAILED"); - throw new ServerException(ERROR_FEED_DATA); - } - - - /** - * This method creates an array of key/value pairs from an array of Data - * objects. The string array is used as parameter for the feed() operation. - * - * @param data The data that should be transformed into the string array. - * - * @return a string array that contains key/value pairs. - */ - protected String[][] createKVP(Data[] data) { - String[][] kvp = new String[data.length][]; - - int i = 0; - - for (Data d: data) { - DataItem[] items = d.getItems(); - String key = d.getLabel(); - String value = d.getStringValue(); - - kvp[i++] = new String[] { key, value }; - } - - return kvp; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/StyleHelper.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package de.intevation.flys.client.server; - -import de.intevation.flys.client.shared.model.Style; -import de.intevation.flys.client.shared.model.StyleSetting; - -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - - -public class StyleHelper { - - public static Style getStyle (Element element) { - if (!element.getTagName().equals("theme")) { - return null; - } - - NodeList list = element.getElementsByTagName("field"); - Style style = new Style(); - - style.setName (element.getAttribute("name")); - style.setFacet (element.getAttribute("facet")); - - try { - int ndx = Integer.parseInt(element.getAttribute("index")); - style.setIndex (ndx); - } - catch(NumberFormatException nfe) { - return null; - } - - for(int i = 0; i < list.getLength(); i++) { - Element e = (Element) list.item(i); - String hints = e.getAttribute("hints"); - - StyleSetting set = new StyleSetting ( - e.getAttribute("name"), - e.getAttribute("default"), - e.getAttribute("display"), - e.getAttribute("hints"), - e.getAttribute("type"), - (hints != null && hints.contains("hidden") ? true : false) - ); - style.appendStyleSetting(set); - } - return style; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ThemeListingServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -package de.intevation.flys.client.server; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; - -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.client.services.ThemeListingService; - -import de.intevation.flys.client.shared.exceptions.ServerException; - -import de.intevation.flys.client.shared.model.Style; - -import java.util.HashMap; -import java.util.Map; - -import javax.xml.xpath.XPathConstants; - -import org.apache.log4j.Logger; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * This interface provides a method to list themes filtered by name. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class ThemeListingServiceImpl -extends RemoteServiceServlet -implements ThemeListingService -{ - private static final Logger logger = - Logger.getLogger(ThemeListingServiceImpl.class); - - - private static final String XPATH_THEME_GROUPS = "/themes/themegroup"; - /** The error message key that is thrown if an error occured while reading - * the supported rivers from server.*/ - public static final String ERROR_NO_GROUPS_FOUND = "error_no_groups_found"; - - - public Map<String, Style> list(String locale, String name) - throws ServerException - { - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - null, - null); - - Element e = ec.create("theme"); - ec.addAttr(e, "name", name); - doc.appendChild(e); - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document res = client.callService(url, "themelisting", doc); - - NodeList themeGroups = (NodeList) XMLUtils.xpath( - res, - XPATH_THEME_GROUPS, - XPathConstants.NODESET, - null); - - if (themeGroups == null || themeGroups.getLength() == 0) { - throw new ServerException(ERROR_NO_GROUPS_FOUND); - } - - int count = themeGroups.getLength(); - - Map<String, Style> theStyles = new HashMap<String, Style>(count); - - for (int i = 0; i < count; i++) { - Element tmp = (Element)themeGroups.item(i); - - String groupName = tmp.getAttribute("name"); - NodeList theTheme = (NodeList) XMLUtils.xpath( - tmp, - "theme", - XPathConstants.NODESET, - null); - - for (int j = 0; j < theTheme.getLength(); j++) { - Element elem = (Element) theTheme.item(j); - theStyles.put(groupName, StyleHelper.getStyle(elem)); - } - } - - return theStyles; - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_GROUPS_FOUND); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/UserCollectionsServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.shared.model.DefaultCollection; -import de.intevation.flys.client.client.services.UserCollectionsService; - - -/** - * This service returns a list of collections owned by a specified user. - * <b>NOTE:</b> The Collections returned by this service provide no information - * about the CollectionItems or OutputModes of the Collection. You need to fetch - * these information explicitly using another service. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class UserCollectionsServiceImpl -extends RemoteServiceServlet -implements UserCollectionsService -{ - private static final Logger logger = Logger.getLogger( - UserCollectionsServiceImpl.class); - - - public Collection[] getUserCollections(String locale, String userid) { - logger.info("UserCollectionsServiceImpl.getUserCollections"); - - String serverUrl = getServletContext().getInitParameter("server-url"); - HttpClient client = new HttpClientImpl(serverUrl, locale); - - try { - Document result = client.listUserCollections(userid); - - NodeList list = (NodeList) XMLUtils.xpath( - result, - "/art:artifact-collections/art:artifact-collection", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (list == null || list.getLength() == 0) { - logger.debug("No collection found for user: " + userid); - return null; - } - - int num = list.getLength(); - - List<Collection> all = new ArrayList<Collection>(num); - - for (int i = 0; i < num; i++) { - Collection c = createCollection((Element) list.item(i)); - - if (c != null) { - all.add(c); - } - } - - logger.debug("User has " + all.size() + " collections."); - - return all.toArray(new Collection[all.size()]); - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - logger.debug("No user collections found."); - return null; - } - - - /** - * Extracts a SimpleCollection from <i>node</i>. - * - * @param node Contains information about a collection. - * - * @return a list of Simplecollections. - */ - protected Collection createCollection(Element node) { - String uri = ArtifactNamespaceContext.NAMESPACE_URI; - - String creationStr = node.getAttributeNS(uri, "creation"); - String name = node.getAttributeNS(uri, "name"); - String uuid = node.getAttributeNS(uri, "uuid"); - String ttlStr = node.getAttributeNS(uri, "ttl"); - - if (!uuid.isEmpty() && !ttlStr.isEmpty() && !creationStr.isEmpty()) { - try { - long time = Long.parseLong(creationStr); - long ttl = Long.parseLong(ttlStr); - return new DefaultCollection(uuid, ttl, name, new Date(time)); - } - catch (NumberFormatException nfe) { - logger.warn("Error while parsing collection attributes."); - return null; - } - } - - logger.warn("Found an invalid Collection."); - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -package de.intevation.flys.client.server; - -import javax.servlet.http.HttpSession; - -import org.w3c.dom.Element; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; - -import de.intevation.flys.client.client.services.UserService; -import de.intevation.flys.client.server.auth.UserClient; -import de.intevation.flys.client.shared.exceptions.AuthenticationException; -import de.intevation.flys.client.shared.model.DefaultUser; -import de.intevation.flys.client.shared.model.User; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class UserServiceImpl -extends RemoteServiceServlet -implements UserService -{ - /** Private logger. */ - private static final Logger logger = Logger.getLogger(UserServiceImpl.class); - - public static final String ERROR_NO_SUCH_USER = "error_no_such_user"; - - public static final String ERROR_NO_USERS = "error_no_users"; - - public User getCurrentUser(String locale) - throws AuthenticationException - { - String url = getServletContext().getInitParameter("server-url"); - - UserClient client = new UserClient(url); - de.intevation.flys.client.server.auth.User loginuser = getUser(); - - if (loginuser == null) { - logger.debug("no session user"); - throw new AuthenticationException(ERROR_NO_SUCH_USER); - } - - try { - Element user = client.findUser(loginuser); - - if (user != null) { - String uuid = user.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "uuid"); - String name = user.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); - - return new DefaultUser(uuid, name); - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - logger.error("No users existing in the server."); - throw new AuthenticationException(ERROR_NO_USERS); - } - - public void logoutCurrentUser() { - HttpSession session = this.getThreadLocalRequest().getSession(); - session.setAttribute("user", null); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -package de.intevation.flys.client.server; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import javax.xml.xpath.XPathConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.apache.log4j.Logger; - -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -import de.intevation.flys.client.shared.exceptions.ServerException; -import de.intevation.flys.client.client.services.WQInfoService; -import de.intevation.flys.client.shared.model.WQInfoObject; -import de.intevation.flys.client.shared.model.WQInfoObjectImpl; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class WQInfoServiceImpl -extends RemoteServiceServlet -implements WQInfoService -{ - private static final Logger logger = - Logger.getLogger(WQInfoServiceImpl.class); - - public static final String ERROR_NO_WQINFO_FOUND = - "error_no_wqinfo_found"; - - public static final String XPATH_WQS = "art:service/art:mainvalues/art:mainvalue"; - - - public WQInfoObject[] getWQInfo( - String locale, - String river, - double from, - double to) - throws ServerException - { - logger.info("WQInfoServiceImpl.getWQInfo"); - - String url = getServletContext().getInitParameter("server-url"); - - Document doc = XMLUtils.newDocument(); - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element mainvalues = ec.create("mainvalues"); - Element riverEl = ec.create("river"); - Element startEl = ec.create("start"); - Element endEl = ec.create("end"); - - riverEl.setTextContent(river); - startEl.setTextContent(Double.valueOf(from).toString()); - endEl.setTextContent(Double.valueOf(to).toString()); - - mainvalues.appendChild(riverEl); - mainvalues.appendChild(startEl); - mainvalues.appendChild(endEl); - - doc.appendChild(mainvalues); - - HttpClient client = new HttpClientImpl(url, locale); - - try { - Document result = client.callService(url, "mainvalues", doc); - - logger.debug("Extract wq info objects now."); - WQInfoObject[] objects = extractWQInfoObjects(result); - - if (objects.length > 0) { - return objects; - } - } - catch (ConnectionException ce) { - logger.error(ce, ce); - } - - throw new ServerException(ERROR_NO_WQINFO_FOUND); - } - - - /** - * Extracts all wq info objects from <i>result</i> document. - * - * @param result The document retrieved by the server. - * - * @return a list of WQInfoObjects. - */ - protected WQInfoObject[] extractWQInfoObjects(Document result) - throws ServerException - { - NodeList list = (NodeList) XMLUtils.xpath( - result, - XPATH_WQS, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (list == null || list.getLength() == 0) { - logger.warn("No wq info found."); - - throw new ServerException(ERROR_NO_WQINFO_FOUND); - } - - boolean debug = logger.isDebugEnabled(); - - int num = list.getLength(); - if (debug) { - logger.debug("Response contains " + num + " objects."); - } - - List<WQInfoObject> objects = - new ArrayList<WQInfoObject>(num); - - for (int i = 0; i < num; i++) { - WQInfoObject obj = buildWQInfoObject(list.item(i)); - - if (obj != null) { - objects.add(obj); - } - } - - if (debug) { - logger.debug("Retrieved " + objects.size() + " wq values"); - } - - WQInfoObject [] array = (WQInfoObject[]) - objects.toArray(new WQInfoObject[objects.size()]); - - Arrays.sort(array, WQ_INFO_OBJECT_CMP); - - return array; - } - - public static final Comparator<WQInfoObject> WQ_INFO_OBJECT_CMP = - new Comparator<WQInfoObject>() { - @Override - public int compare(WQInfoObject a, WQInfoObject b) { - - // Descending by type: Qs before Ds - int cmp = a.getType().compareTo(b.getType()); - if (cmp < 0) return +1; - if (cmp > 0) return -1; - - // Ascending by value - double diff = a.getValue() - b.getValue(); - if (diff < 0d) return -1; - if (diff > 0d) return +1; - return 0; - } - }; - - /** - * Extracts information for a single wq info object and intializes an - * WQInfoObject with them. - * - * @param node The node that contains the information. - * - * @return a valid WQInfoObject. - */ - protected static WQInfoObject buildWQInfoObject(Node node) { - - String name = XMLUtils.xpathString( - node, "@name", ArtifactNamespaceContext.INSTANCE); - - String type = XMLUtils.xpathString( - node, "@type", ArtifactNamespaceContext.INSTANCE); - - String value = XMLUtils.xpathString( - node, "@value", ArtifactNamespaceContext.INSTANCE); - - if (name != null && type != null) { - try { - return new WQInfoObjectImpl( - name, - type, - new Double(value)); - } - catch (NumberFormatException nfe) { - logger.warn(nfe.getLocalizedMessage()); - } - } - - logger.warn("Invalid wq info object found."); - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/Authentication.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package de.intevation.flys.client.server.auth; - -/** Interface to represent user authentications - */ -public interface Authentication { - - /** Returns true if the authentication was successfull - */ - public boolean isSuccess(); - - /** Returns a new User object - */ - public User getUser() throws AuthenticationException; - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/AuthenticationException.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.server.auth; - -/** - * Base class for Authentication related Exceptions - */ -public class AuthenticationException extends Exception { - - public AuthenticationException(String message) { - super(message); - } - - public AuthenticationException(Exception e) { - super(e); - } -} -// vim: set fileencoding=utf-8 ts=4 sw=4 tw=80: -
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/AuthenticationFactory.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package de.intevation.flys.client.server.auth; - -import org.apache.log4j.Logger; - -public class AuthenticationFactory { - - private static final Logger log = - Logger.getLogger(AuthenticationFactory.class); - - public static Authenticator getInstance(String name) - throws IllegalArgumentException - { - if (name == null) { - throw new IllegalArgumentException("Authentication type name is null"); - } - - if (name.equalsIgnoreCase("was") || - name.equalsIgnoreCase("ggina")) { - log.debug("Using GGinA authenticator."); - return - new de.intevation.flys.client.server.auth.was.Authenticator(); - } - else if (name.equalsIgnoreCase("plain")) { - log.debug("Using plain authenticator."); - return - new de.intevation.flys.client.server.auth.plain.Authenticator(); - } - - throw new IllegalArgumentException("Unkown Authentication " + name); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/Authenticator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package de.intevation.flys.client.server.auth; - -import java.io.IOException; - -import de.intevation.flys.client.server.features.Features; - -public interface Authenticator { - - public Authentication auth(String username, String password, String encoding, Features features) - throws AuthenticationException, IOException; - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/DefaultUser.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -package de.intevation.flys.client.server.auth; - -import java.util.List; - -public class DefaultUser -implements User -{ - protected String name; - protected String account; - protected String password; - protected boolean expired; - protected List<String> roles; - protected List<String> features; - - public DefaultUser() { - } - - public DefaultUser( - String name, - String password, - boolean expired, - List<String> roles, - List<String> features - ) { - this.name = name; - this.password = password; - this.expired = expired; - this.roles = roles; - this.features = features; - this.account = name; - } - - @Override - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - @Override - public boolean hasExpired() { - return expired; - } - - public void setExpired(boolean expired) { - this.expired = expired; - } - - @Override - public List<String> getRoles() { - // XXX: return clone of the list? - return this.roles; - } - - public void setRoles(List<String> roles) { - this.roles = roles; - } - - @Override - public boolean canUseFeature(String feature) { - return this.features.contains(feature); - } - - public void setAllowedFeatures(List<String> features) { - this.features = features; - } - - @Override - public String getAccount() { - return this.account; - } - - public void setAccount(String account) { - this.account = account; - } -} -// vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/User.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -package de.intevation.flys.client.server.auth; - -import java.util.List; - -/** - * User representation after a succesfull login - */ -public interface User { - - /** - * Returns the username as String - */ - public String getName(); - - /** - * Returns the password of the user as String - */ - public String getPassword(); - - /** - * Returns True if the authentication for the user - * has expired. - */ - public boolean hasExpired(); - - /** - * Returns a list of roles corresponsing the the user - */ - public List<String> getRoles(); - - - /** - * Returns true if the user is allowed access the feature - */ - public boolean canUseFeature(String feature); - - /** - * Returns the users account name - */ - public String getAccount(); -} -// vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ -package de.intevation.flys.client.server.auth; - -import javax.xml.xpath.XPathConstants; - -import org.apache.log4j.Logger; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifacts.httpclient.exceptions.ConnectionException; -import de.intevation.artifacts.httpclient.http.HttpClient; -import de.intevation.artifacts.httpclient.http.HttpClientImpl; - -/** - * UserClient is a class to allow easier communication - * with the REST based artifact user protocol - */ -public class UserClient { - - private static final Logger logger = Logger.getLogger(UserClient.class); - - private String url; - - public UserClient(String url) { - this.url = url; - } - - public boolean userExists(User user) throws ConnectionException { - if (user == null) { - return false; - } - - Element data = this.findUser(user); - - String XPATH_USERACCOUNT = "/art:user/art:account/@art:name"; - - String account = XMLUtils.xpathString( - data, XPATH_USERACCOUNT, ArtifactNamespaceContext.INSTANCE); - - if (account == null) { - return false; - } - - return account.equals(user.getAccount()); - } - - public boolean createUser(User user) throws ConnectionException { - if(user == null) { - logger.warn("createUser: given user is null"); - return false; - } - - logger.debug("Creating new user " + user.getName()); - HttpClient client = new HttpClientImpl(this.url); - - Document document = XMLUtils.newDocument(); - - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( - document, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX - ); - - Element action = creator.create("action"); - - Element type = creator.create("type"); - type.setAttribute("name", "create"); - Element artuser = creator.create("user"); - artuser.setAttribute("name", user.getName()); - Element account = creator.create("account"); - account.setAttribute("name", user.getAccount()); - - //TODO create roles - artuser.appendChild(account); - action.appendChild(type); - action.appendChild(artuser); - document.appendChild(action); - - logger.debug("Create user request xml: " + XMLUtils.toString(document)); - - Document resp = client.createUser(document); - - logger.debug("Create user response xml: " + XMLUtils.toString(resp)); - - String XPATH_RESPONSE = "/art:result"; - Node nresult = (Node) XMLUtils.xpath( - resp, - XPATH_RESPONSE, - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE); - String result = nresult.getTextContent(); - return (result != null && result.equalsIgnoreCase("success")); - } - - public NodeList listUsers() throws ConnectionException { - HttpClient client = new HttpClientImpl(this.url); - - Document users = (Document) client.listUsers(); - - String XPATH_USERS = "/art:users/art:user"; - - return (NodeList) XMLUtils.xpath( - users, - XPATH_USERS, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - } - - public Element findUser(User user) throws ConnectionException { - if(user == null) { - throw new IllegalArgumentException("user is null"); - } - - HttpClient client = new HttpClientImpl(this.url); - - Document document = XMLUtils.newDocument(); - - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( - document, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX - ); - - Element action = creator.create("action"); - - Element type = creator.create("type"); - type.setAttribute("name", "find"); - Element account = creator.create("account"); - account.setAttribute("name", user.getAccount()); - - action.appendChild(type); - action.appendChild(account); - document.appendChild(action); - - boolean debug = logger.isDebugEnabled(); - - if (debug) { - logger.debug("Find user request xml: " + - XMLUtils.toString(document)); - } - - Document resp = client.findUser(document); - - if (debug) { - logger.debug("Find user request response xml: " + - XMLUtils.toString(resp)); - } - - return resp.getDocumentElement(); - } -} -// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80: -
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/plain/Authenticator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -package de.intevation.flys.client.server.auth.plain; - -import de.intevation.flys.client.server.auth.AuthenticationException; -import de.intevation.flys.client.server.auth.DefaultUser; -import de.intevation.flys.client.server.auth.User; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.server.features.Features; - -/** - * Authenticator that uses a local file as user backend. - */ -public class Authenticator -implements de.intevation.flys.client.server.auth.Authenticator -{ - private static final Logger log = - Logger.getLogger(Authenticator.class); - - public static class Authentication - implements de.intevation.flys.client.server.auth.Authentication - { - protected String user; - protected String password; - protected List<String> roles; - protected Features features; - - public Authentication( - String user, - String password, - List<String> roles, - Features features - ) { - this.user = user; - this.password = password; - this.roles = roles; - this.features = features; - } - - @Override - public boolean isSuccess() { - return user != null; - } - - @Override - public User getUser() { - return isSuccess() - ? new DefaultUser(user, password, false, roles, this.features.getFeatures(roles)) - : null; - } - } // class Authentication - - public Authenticator() { - } - - private static File credentialsFile() { - String env = System.getenv("FLYS_USER_FILE"); - if (env == null) { - env = System.getProperty( - "flys.user.file", - System.getProperty("user.home", ".") - + System.getProperty("file.separator") - + "flys_user_file"); - } - log.debug("Using credentials file " + env); - return new File(env); - - } - - @Override - public de.intevation.flys.client.server.auth.Authentication auth( - String username, - String password, - String encoding, - Features features - ) - throws AuthenticationException, IOException - { - File file = credentialsFile(); - if (!file.canRead() || !file.isFile()) { - log.error("cannot find user file '" + file + "'"); - return new Authentication(null, null, new ArrayList<String>(0), features); - } - - BufferedReader reader = - new BufferedReader( - new FileReader(file)); - try { - String line; - while ((line = reader.readLine()) != null) { - if ((line = line.trim()).length() == 0 - || line.startsWith("#")) { - continue; - } - - String[] parts = line.split("\\s+"); - if (parts.length < 2) { - continue; - } - - if (parts[0].equals(username)) { - log.debug("user '" + username + "' found."); - if (parts[1].equals(password)) { - List<String> roles = - new ArrayList<String>(parts.length - 2); - - for (int i = 2; i < parts.length; i++) { - roles.add(parts[i]); - } - - log.debug("success"); - return new Authentication(username, password, roles, features); - } - // Stop: user found, wrong password - break; - } - } - } - finally { - reader.close(); - } - log.debug("failed"); - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Assertion.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Iterator; -import java.util.Date; -import java.util.List; -import java.util.LinkedList; - -import org.apache.log4j.Logger; - -import org.jdom.Element; - -public class Assertion { - - private static Logger logger = Logger.getLogger(Assertion.class); - - private Element assertion; - private LinkedList<String> roles; - private String assertion_id; - private String user_id; - private String name_id; - private String group_id; - private String group_name; - private Date notbefore; - private Date notonorafter; - private Signature signature; - - private static final String ATTR_CONT_USER_ID = - "urn:conterra:names:sdi-suite:policy:attribute:user-id"; - private static final String ATTR_CONT_GROUP_ID = - "urn:conterra:names:sdi-suite:policy:attribute:group-id"; - private static final String ATTR_CONT_GROUP_NAME = - "urn:conterra:names:sdi-suite:policy:attribute:group-name"; - private static final String ATTR_CONT_ROLE = - "urn:conterra:names:sdi-suite:policy:attribute:role"; - - - public Assertion(Element assertion) { - this.assertion = assertion; - this.roles = new LinkedList<String>(); - - this.assertion_id = assertion.getAttributeValue("AssertionID"); - - this.parseContition(); - this.parseAttributeStatement(); - } - - private void parseContition() { - Element condition = this.assertion.getChild("Conditions", - Namespaces.SAML_NS_ASSERT); - if (condition != null) { - SimpleDateFormat dateformat = new SimpleDateFormat(); - // format should be "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" but that's only - // available in java 7+ - dateformat.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - String from = condition.getAttributeValue("NotBefore"); - if (from != null) { - try { - this.notbefore = dateformat.parse(from); - } - catch(ParseException e) { - logger.error("Unknown datetime format for Condition " + - "NotBefore " + from); - } - } - - String until = condition.getAttributeValue("NotOnOrAfter"); - logger.debug("Session is valid until " + until); - if (until != null) { - try { - this.notonorafter = dateformat.parse(until); - } - catch(ParseException e) { - logger.error("Unknown datetime format for Condition " + - "NotOnOrAfter " + until); - } - } - } - } - - private void parseAttributeStatement() { - Element attrstatement = this.assertion.getChild("AttributeStatement", - Namespaces.SAML_NS_ASSERT); - if (attrstatement != null) { - - Element subject = attrstatement.getChild("Subject", - Namespaces.SAML_NS_ASSERT); - if (subject != null) { - this.name_id = subject.getChildText("NameIdentifier", - Namespaces.SAML_NS_ASSERT); - } - - List attributes = attrstatement.getChildren("Attribute", - Namespaces.SAML_NS_ASSERT); - for(Iterator i = attributes.iterator(); i.hasNext();) { - Element attr = (Element)i.next(); - String attrname = attr.getAttributeValue("AttributeName"); - if (attrname.equals(ATTR_CONT_USER_ID)) { - this.user_id = this.getAttributeValue(attr); - } - else if (attrname.equals(ATTR_CONT_GROUP_ID)) { - this.group_id = this.getAttributeValue(attr); - } - else if (attrname.equals(ATTR_CONT_GROUP_NAME)) { - this.group_name = this.getAttributeValue(attr); - } - else if (attrname.equals(ATTR_CONT_ROLE)) { - List roles = attr.getChildren("AttributeValue", - Namespaces.SAML_NS_ASSERT); - for(Iterator j = roles.iterator(); j.hasNext();) { - Element role = (Element)j.next(); - this.roles.add(role.getText()); - } - } - else { - logger.debug("Unknown AttributeName " + attrname + - " found while parsing AttributeStatement."); - } - } - } - } - - private String getAttributeValue(Element attr) { - return attr.getChildText("AttributeValue", Namespaces.SAML_NS_ASSERT); - } - - public List<String> getRoles() { - return this.roles; - } - - public Boolean isValid() { - // TODO: - // check signature digest - // check signature value - // check signature cert - return false; - } - - public Signature getSiganture() { - if (this.signature == null) { - Element signature = this.assertion.getChild("Signature", - Namespaces.XML_SIG_NS); - if (signature != null) { - this.signature = new Signature(signature); - } - } - return this.signature; - } - - public String getUserID() { - return this.user_id; - } - - public String getNameID() { - return this.name_id; - } - - public String getGroupID() { - return this.group_id; - } - - public String getGroupName() { - return this.group_name; - } - - public String getID() { - return this.assertion_id; - } - - public Date getFrom() { - return this.notbefore; - } - - public Date getUntil() { - return this.notonorafter; - } -} -// vim: set fileencoding=utf-8 ts=4 sw=4 et si tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Authenticator.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import java.io.IOException; -import java.security.GeneralSecurityException; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; -import org.apache.http.client.HttpClient; -import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.ssl.SSLSocketFactory; -import org.apache.http.impl.client.DefaultHttpClient; - -import de.intevation.flys.client.server.GGInATrustStrategy; -import de.intevation.flys.client.server.auth.Authentication; -import de.intevation.flys.client.server.auth.AuthenticationException; -import de.intevation.flys.client.server.features.Features; - -public class Authenticator -implements de.intevation.flys.client.server.auth.Authenticator { - - @Override - public Authentication auth( - String username, - String password, - String encoding, - Features features - ) throws - AuthenticationException, - IOException - { - try { - SSLSocketFactory sf = new SSLSocketFactory( - new GGInATrustStrategy()); - Scheme https = new Scheme("https", 443, sf); - HttpClient httpclient = new DefaultHttpClient(); - httpclient.getConnectionManager().getSchemeRegistry().register( - https); - - Request httpget = new Request("https://geoportal.bafg.de/" + - "administration/WAS", username, password, encoding); - HttpResponse response = httpclient.execute(httpget); - StatusLine stline = response.getStatusLine(); - if (stline.getStatusCode() != 200) { - throw new AuthenticationException("GGInA Server Error. " + - "Statuscode: " + stline.getStatusCode() + - ". Reason: " + stline.getReasonPhrase()); - } - HttpEntity entity = response.getEntity(); - if (entity == null) { - //FIXME throw AuthenticationException - return null; - } - else { - return new Response(entity, username, password, features); - } - } - catch(GeneralSecurityException e) { - throw new AuthenticationException(e); - } - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Namespaces.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import org.jdom.Namespace; - -public class Namespaces { - - public static final Namespace SAML_NS_ASSERT = - Namespace.getNamespace("urn:oasis:names:tc:SAML:1.0:assertion"); - public static final Namespace SAML_NS_PROTO = - Namespace.getNamespace("urn:oasis:names:tc:SAML:1.0:protocol"); - public static final Namespace XML_SIG_NS = - Namespace.getNamespace("http://www.w3.org/2000/09/xmldsig#"); - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Request.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import java.io.UnsupportedEncodingException; -import java.net.URI; - -import org.apache.commons.codec.binary.Base64; -import org.apache.http.client.methods.HttpGet; -import org.apache.log4j.Logger; - -public class Request extends HttpGet { - - private final static String VERSION = "1.1"; - private final static String REQUEST_SAML_RESPONSE = "GetSAMLResponse"; - private final static String METHOD_AUTH_PASSWORD = - "urn:opengeospatial:authNMethod:OWS:1.0:password"; - - private static Logger logger = Logger.getLogger(Request.class); - - public Request(String uri) { - String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + - REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + - "&ANONYMOUS=TRUE&CREDENTIALS="; - this.setURI(URI.create(request)); - } - - public Request(String uri, String user, String pass, String encoding) { - try { - String base64user = this.toBase64(user, encoding); - String base64pass = this.toBase64(pass, encoding); - - String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + - REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + - "&CREDENTIALS=" + base64user + "," + base64pass; - - this.setURI(URI.create(request)); - } - catch(UnsupportedEncodingException e) { - logger.error(e); - } - } - - private String toBase64(String value, String encoding) throws - UnsupportedEncodingException { - if (encoding == null) { - encoding = "utf-8"; - } - try { - return new String(Base64.encodeBase64(value.getBytes(encoding))); - } - catch(UnsupportedEncodingException e) { - logger.warn("Can't encode string with encoding " + encoding + - ". Falling back to utf-8. " + e); - return this.toBase64(value, "utf-8"); - } - } - -} -// vim: set et si fileencoding=utf-8 ts=4 sw=4 tw=80: -
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Response.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.apache.commons.codec.binary.Base64InputStream; - -import org.apache.http.HttpEntity; - -import org.apache.log4j.Logger; - -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.input.SAXBuilder; - -import de.intevation.flys.client.server.auth.Authentication; -import de.intevation.flys.client.server.auth.AuthenticationException; - -import de.intevation.flys.client.server.features.Features; - -public class Response implements Authentication { - - private static Logger logger = Logger.getLogger(Response.class); - - private Element root; - private Assertion assertion; - private String username; - private String password; - private Features features; - - - public Response(HttpEntity entity, String username, String password, Features features) throws AuthenticationException, IOException { - - if (entity == null) { - throw new ServiceException("Invalid response"); - } - - String contenttype = entity.getContentType().getValue(); - - try { - InputStream in = entity.getContent(); - - if (!contenttype.equals("application/vnd.ogc.se_xml")) { - // XXX: Assume base64 encoded content. - in = new Base64InputStream(in); - } - - SAXBuilder builder = new SAXBuilder(); - Document doc = builder.build(in); - Element root = doc.getRootElement(); - String rname = root.getName(); - - if (rname != null && rname.equals("ServiceExceptionReport")) { - throw new ServiceException(root.getChildText("ServiceException")); - } - - this.root = root; - this.username = username; - this.password = password; - this.features = features; - - } - catch(JDOMException e) { - throw new AuthenticationException(e); - } - } - - public Element getRoot() { - return this.root; - } - - @Override - public boolean isSuccess() { - String status = getStatus(); - return status != null && status.equals("samlp:Success"); - } - - public String getStatus() { - Element status = this.root.getChild("Status", Namespaces.SAML_NS_PROTO); - if (status == null) { - return null; - } - Element statuscode = status.getChild("StatusCode", - Namespaces.SAML_NS_PROTO); - if (statuscode == null) { - return null; - } - return statuscode.getAttributeValue("Value"); - } - - public Assertion getAssertion() { - if (this.assertion == null && this.root != null) { - Element assertion = this.root.getChild("Assertion", - Namespaces.SAML_NS_ASSERT); - if (assertion != null) { - this.assertion = new Assertion(assertion); - } - } - return this.assertion; - } - - @Override - public User getUser() throws AuthenticationException { - Assertion assertion = this.getAssertion(); - if (assertion == null) { - throw new AuthenticationException("Response doesn't contain an assertion"); - } - List<String> features = this.features.getFeatures( - this.assertion.getRoles()); - logger.debug("User " + this.username + " with features " + features + - " successfully authenticated."); - return new User(this.username, this.password, assertion.getNameID(), - this.assertion.getRoles(), assertion, features); - } -} -// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/ServiceException.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import de.intevation.flys.client.server.auth.AuthenticationException; - -public class ServiceException extends AuthenticationException { - - public ServiceException(String message) { - super(message); - } - - public ServiceException(Exception e) { - super(e); - } -} -// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Signature.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import java.io.ByteArrayInputStream; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; - -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; -import org.jdom.Element; - -public class Signature { - - private static Logger logger = Logger.getLogger(Signature.class); - - private static final String XML_SIG_DIGEST_SHA1 = - "http://www.w3.org/2000/09/xmldsig#sha1"; - private static final String XML_SIG_SIGNATURE_RSA_SHA1 = - "http://www.w3.org/2000/09/xmldsig#rsa-sha1"; - - private final Element signature; - private Certificate cert; - private byte[] value; - private byte[] digestvalue; - private String reference; - - public Signature(Element signature) { - this.signature = signature; - this.parseSignatureInfo(); - this.parseSignatureValue(); - this.parseCertificate(); - } - - private void parseSignatureInfo() { - Element signatureinfo = this.signature.getChild("SignedInfo", - Namespaces.XML_SIG_NS); - if (signatureinfo != null) { - Element signaturemethod = signatureinfo.getChild("SignatureMethod", - Namespaces.XML_SIG_NS); - String algorithm = signaturemethod.getAttributeValue("Algorithm"); - if (!algorithm.equals(XML_SIG_SIGNATURE_RSA_SHA1)) { - logger.warn("Unkown signature alorithm " + algorithm); - } - - // There could be several references in XML-Sig spec but for me it - // doesn't make sense to have more then one in a SAML Assertion - Element reference = signatureinfo.getChild("Reference", - Namespaces.XML_SIG_NS); - // reference must be present but its better to check - if (reference != null) { - String digestvalue = reference.getChildText("DigestValue", - Namespaces.XML_SIG_NS); - String digestmethod = reference.getChildText("DigestMethod", - Namespaces.XML_SIG_NS); - if (!digestmethod.equals(XML_SIG_DIGEST_SHA1)) { - logger.warn("Unknown digest method " + digestmethod); - } - this.digestvalue = Base64.decodeBase64(digestvalue); - - String referenceuri = reference.getAttributeValue("URI"); - if (referenceuri.startsWith("#")) { - this.reference = referenceuri.substring(1); - } - else { - logger.warn("Unkown reference type " + referenceuri); - this.reference = referenceuri; - } - } - } - } - - private void parseSignatureValue() { - String signaturevalue = this.signature.getChildText("SignatureValue", - Namespaces.XML_SIG_NS); - this.value = Base64.decodeBase64(signaturevalue); - } - - private void parseCertificate() { - Element keyinfo = this.signature.getChild("KeyInfo", - Namespaces.XML_SIG_NS); - if (keyinfo != null) { - Element data = keyinfo.getChild("X509Data", Namespaces.XML_SIG_NS); - if (data != null) { - String base64cert = data.getChildText("X509Certificate", - Namespaces.XML_SIG_NS); - if (base64cert != null) { - byte[] bytes = Base64.decodeBase64(base64cert); - try { - CertificateFactory cf = CertificateFactory.getInstance( - "X.509"); - this.cert = cf.generateCertificate( - new ByteArrayInputStream(bytes)); - } - catch(CertificateException e) { - // should never occur - logger.error(e); - } - } - } - } - } - - public Certificate getCertificate() { - return this.cert; - } - - public byte[] getValue() { - return this.value; - } - - public String getReference() { - // In theory there could be several references with digestvalues, ... - return this.reference; - } - - public byte[] getDigestValue() { - return this.digestvalue; - } -} -// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/User.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.server.auth.was; - -import java.util.Date; -import java.util.List; - -import de.intevation.flys.client.server.auth.DefaultUser; - -public class User -extends DefaultUser -implements de.intevation.flys.client.server.auth.User { - - private Assertion assertion; - - public User(String name, - String password, - String account, - List<String> roles, - Assertion assertion, - List<String> features - ) { - this.setName(name); - this.setPassword(password); - this.setRoles(roles); - this.assertion = assertion; - this.setAllowedFeatures(features); - this.setAccount(account); - } - - @Override - public boolean hasExpired() { - Date until = this.assertion.getUntil(); - if (until != null) { - Date current = new Date(); - return !current.after(until); - } - return false; - } -} - -// vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/features/Features.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.server.features; - -import java.util.List; - -public interface Features { - - public static final String CONTEXT_ATTRIBUTE = "de.intevation.flys.client.server.features"; - - /** - * Returns all allowed features to a list of roles - */ - public List<String> getFeatures(List<String> roles); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/features/FeaturesNamespaceContext.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -package de.intevation.flys.client.server.features; - -import java.util.Iterator; - -import javax.xml.XMLConstants; - -import javax.xml.namespace.NamespaceContext; - -public class FeaturesNamespaceContext -implements NamespaceContext { - - /** - * The URI of the namespace of the features. - */ - public final static String NAMESPACE_URI = - "http://www.intevation.de/2012/flys/features"; - - /** - * The XML prefix for the features namespace. - */ - public final static String NAMESPACE_PREFIX = "ftr"; - - /** - * Final instance to be easily used to avoid creation - * of instances. - */ - public static final FeaturesNamespaceContext INSTANCE = - new FeaturesNamespaceContext(); - - /** - * The default constructor. - */ - public FeaturesNamespaceContext() { - } - - /** - * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(String) - * @param prefix The prefix - * @return The corresponing URI - */ - @Override - public String getNamespaceURI(String prefix) { - - if (prefix == null) { - throw new NullPointerException("Null prefix"); - } - - if (NAMESPACE_PREFIX.equals(prefix)) { - return NAMESPACE_URI; - } - - if ("xml".equals(prefix)) { - return XMLConstants.XML_NS_URI; - } - - return XMLConstants.NULL_NS_URI; - } - - /** - * @see javax.xml.namespace.NamespaceContext#getPrefix(String) - * @param uri The URI - * @return nothing. - * @throws java.lang.UnsupportedOperationException - */ - @Override - public String getPrefix(String uri) { - throw new UnsupportedOperationException(); - } - - /** - * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) - * @param uri The URI - * @return nothing - * @throws java.lang.UnsupportedOperationException - */ - @Override - public Iterator getPrefixes(String uri) { - throw new UnsupportedOperationException(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/features/XMLFileFeatures.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -package de.intevation.flys.client.server.features; - -import java.io.FileInputStream; -import java.io.IOException; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.xpath.XPathConstants; - -import org.apache.log4j.Logger; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import de.intevation.artifacts.common.utils.XMLUtils; - -public class XMLFileFeatures implements Features { - - private static final Logger logger = - Logger.getLogger(XMLFileFeatures.class); - - private Map<String, List<String>> featuremap = - new HashMap<String, List<String>>(); - - private final static String XPATH_FEATURES = "ftr:feature/child::text()"; - private final static String XPATH_ROLES = "/ftr:features/ftr:role"; - - public XMLFileFeatures(String filename) throws IOException { - FileInputStream finput = new FileInputStream(filename); - logger.debug("XMLFileFeatures: " + filename); - try { - Document doc = XMLUtils.parseDocument(finput); - - NodeList roles = (NodeList) XMLUtils.xpath( - doc, - XPATH_ROLES, - XPathConstants.NODESET, - FeaturesNamespaceContext.INSTANCE); - - for(int i = 0, m = roles.getLength(); i < m; i++) { - Element rolenode = (Element)roles.item(i); - - String name = rolenode.getAttribute("name"); - - logger.debug("Found role: " + name); - - NodeList features = (NodeList) XMLUtils.xpath( - rolenode, - XPATH_FEATURES, - XPathConstants.NODESET, - FeaturesNamespaceContext.INSTANCE); - - if (features == null) { - continue; - } - - int N = features.getLength(); - - if (N > 0) { - List<String> allowed = new ArrayList<String>(N); - for (int j = 0; j < N; j++) { - Node featurenode = features.item(j); - String featurename = featurenode.getNodeValue(); - - logger.debug("Found feature: " + featurename); - - allowed.add(featurename); - } - featuremap.put(name, allowed); - } - } - logger.debug("Loaded all features"); - } - finally { - finput.close(); - } - } - - @Override - public List<String> getFeatures(List<String> roles) { - List<String> features = new ArrayList<String>(); - - for (String role: roles) { - List<String> allowed = this.featuremap.get(role); - if (allowed != null) { - features.addAll(allowed); - } - } - return features; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/filter/GGInAFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,206 +0,0 @@ -package de.intevation.flys.client.server.filter; - -import de.intevation.flys.client.server.auth.Authentication; -import de.intevation.flys.client.server.auth.AuthenticationException; -import de.intevation.flys.client.server.auth.AuthenticationFactory; -import de.intevation.flys.client.server.auth.User; -import de.intevation.flys.client.server.features.Features; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Enumeration; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.log4j.Logger; - - -/** ServletFilter used for GGInA authentification and certain authorisation. */ -public class GGInAFilter implements Filter { - - /** Private logger. */ - private static Logger logger = Logger.getLogger(GGInAFilter.class); - - private boolean deactivate = false; - private String authmethod; - private String redirecturl; - private ServletContext sc; - - private static final String LOGIN_JSP = "/login.jsp"; - private static final String LOGIN_SERVLET = "/flys/login"; - private static final String FLYS_CSS = "/FLYS.css"; - - - /** - * Initialize. - * - * Read FilterConfig parameter deactivate - */ - @Override - public void init(FilterConfig config) - throws ServletException - { - String deactivate = config.getInitParameter("deactivate"); - this.sc = config.getServletContext(); - logger.debug("GGInAFilter context " + this.sc.getContextPath()); - this.authmethod = sc.getInitParameter("authentication"); - this.redirecturl = sc.getInitParameter("redirect-url"); - if (deactivate != null && deactivate.equalsIgnoreCase("true")) { - this.deactivate = true; - } - - } - - - /** - * Called when filter in chain invoked. - * @param req request to servlet - * @param resp response of servlet - * @param chain the filter chain - */ - @Override - public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) - throws IOException, ServletException - { - if (this.deactivate) { - logger.debug("GGinAFilter is deactivated"); - chain.doFilter(req, resp); - return; - } - - HttpServletRequest sreq = (HttpServletRequest) req; - - String requesturi = sreq.getRequestURI(); - if (logger.isDebugEnabled()) { - for (Enumeration e = req.getAttributeNames() ; e.hasMoreElements() ;) { - logger.debug(e.nextElement()); - } - } - - logger.debug("Request for: " + requesturi); - - // Allow access to localhost - if (isLocalAddress(req)) { - logger.debug("Request to localhost"); - chain.doFilter(req, resp); - return; - } - - // Allow access to login pages - String path = this.sc.getContextPath(); - if (requesturi.equals(path + LOGIN_JSP) - || requesturi.equals(path + LOGIN_SERVLET) - || requesturi.equals(path + FLYS_CSS)) { - logger.debug("Request for login " + requesturi); - chain.doFilter(req, resp); - return; - } - - boolean redirect = false; - - HttpSession session = sreq.getSession(); - - String uri = path + "/" + this.redirecturl; - - /* Redirect if uri is root or redirecturl */ - if (requesturi.equals(uri) || requesturi.equals(path + "/")) { - redirect = true; - } - - String queryString = sreq.getQueryString(); - - if (queryString != null) { - uri += "?" + queryString; - } - session.setAttribute("requesturi", uri); - - User user = (User)session.getAttribute("user"); - if (user == null) { - logger.debug("No user in session: " + requesturi); - this.handleResponse(resp, redirect); - return; - } - if (user.hasExpired()) { - // try to re-authenticate the user - logger.debug("User ticket has expired: " + requesturi); - String encoding = sreq.getCharacterEncoding(); - try { - Authentication auth = this.auth(user, encoding); - if (auth == null || !auth.isSuccess()) { - logger.debug("Re-athentication not successful"); - this.handleResponse(resp, redirect); - } - } - catch(AuthenticationException e) { - logger.error("Failure during re-authentication", e); - this.handleResponse(resp, redirect); - return; - } - } - - chain.doFilter(req, resp); - return; - } - - private void redirect(ServletResponse resp) throws IOException { - logger.debug("Redirect to login"); - ((HttpServletResponse) resp).sendRedirect(this.sc.getContextPath() + - "/login.jsp"); - } - - private void sendNotAuthenticated(ServletResponse resp) throws IOException { - logger.debug("Send not authenticated"); - ((HttpServletResponse)resp).sendError(HttpServletResponse.SC_FORBIDDEN, "User not authenticated"); - } - - private void handleResponse(ServletResponse resp, boolean redirect) throws IOException { - if (redirect) { - this.redirect(resp); - } - else { - this.sendNotAuthenticated(resp); - } - } - - - /** - * Do nothing at destruction. - */ - @Override - public void destroy() { - } - - private Authentication auth(User user, String encoding) - throws AuthenticationException, IOException { - Features features = (Features)sc.getAttribute(Features.CONTEXT_ATTRIBUTE); - return AuthenticationFactory.getInstance(this.authmethod).auth( - user.getName(), user.getPassword(), encoding, features); - } - - /** - * Returns true if the request is from our machine - * @param req The ServletRequest - * @return true if the request is from a loopback interface or from one of - * the interface addresses of the machine - */ - private boolean isLocalAddress(ServletRequest req) { - try { - InetAddress addr = InetAddress.getByName(req.getRemoteAddr()); - return addr.isAnyLocalAddress() || addr.isLoopbackAddress(); - } catch (UnknownHostException e) { - logger.error(e, e); - return false; - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/filter/NoCacheFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -package de.intevation.flys.client.server.filter; - -import java.io.IOException; -import java.util.Date; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.log4j.Logger; - -/** ServletFilter to avoid caching for GWTs *.nocache.* files. */ -public class NoCacheFilter implements Filter { - - private static final long DAY = 86400000L; - - private static final String NO_CACHE = ".nocache."; - - private static Logger log = Logger.getLogger(NoCacheFilter.class); - - /** - * Initialize. - */ - @Override - public void init(FilterConfig config) - throws ServletException - { - } - - - /** - * Called when filter in chain invoked. - * @param req request to servlet - * @param resp response of servlet - * @param chain the filter chain - */ - @Override - public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) - throws IOException, ServletException - { - HttpServletRequest httpreq = (HttpServletRequest)req; - String uri = httpreq.getRequestURI(); - - if (uri.contains(NO_CACHE)) { - log.debug("Set no-cache for " + uri); - - Date now = new Date(); - HttpServletResponse httpresp = (HttpServletResponse)resp; - httpresp.setDateHeader("Date", now.getTime()); - httpresp.setDateHeader("Expires", now.getTime() - DAY); - httpresp.setHeader("Pragma", "no-cache"); - httpresp.setHeader("Cache-control", - "no-cache, no-store, must-revalidate"); - } - - chain.doFilter(req, resp); - } - - - /** - * Do nothing at destruction. - */ - @Override - public void destroy() { - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -package de.intevation.flys.client.server.meta; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Attr; -import org.w3c.dom.NamedNodeMap; - -import org.apache.log4j.Logger; - -import de.intevation.flys.client.shared.model.DataCageTree; -import de.intevation.flys.client.shared.model.DataCageNode; -import de.intevation.flys.client.shared.model.AttrList; - -import java.util.ArrayList; -import java.util.Map; -import java.util.HashMap; - -import de.intevation.artifacts.common.utils.XMLUtils; - -/** - * Converts document parts (meta-data xml) to datacagenodes/trees, - * which are shown in datacage widgets. - */ -public class Converter -{ - private static final Logger logger = Logger.getLogger(Converter.class); - - - public interface NodeConverter - { - DataCageNode convert(Element node, Converter converter); - - } // interface NodeConverter - - public static class NameConverter implements NodeConverter { - public DataCageNode convert(Element node, Converter converter) { - //System.err.println("NameConverter called"); - DataCageNode out = new DataCageNode( - node.getAttribute("name"), - toAttrList(node.getAttributes())); - converter.convertChildren(out, node); - return out; - } - } // class NameConverter - - public static class I18NConverter implements NodeConverter { - public DataCageNode convert(Element node, Converter converter) { - //System.err.println("I18NConverter called"); - - String name = node.getLocalName(); - String desc = node.hasAttribute("description") - ? node.getAttribute("description") - : "${" + name + "}"; - - DataCageNode out = - new DataCageNode(name, desc, toAttrList(node.getAttributes())); - - converter.convertChildren(out, node); - return out; - } - } // I18NConverter - - private static Map<String, NodeConverter> converters = new HashMap<String, NodeConverter>(); - - public static final NodeConverter NAME_CONVERTER = new NameConverter(); - public static final NodeConverter I18N_CONVERTER = new I18NConverter(); - - static { - converters.put("river", NAME_CONVERTER); - converters.put("gauge", NAME_CONVERTER); - converters.put("historical", NAME_CONVERTER); - converters.put("column", NAME_CONVERTER); - } - - - /** Trivial constructor. */ - public Converter() { - } - - - public DataCageTree convert(Document document) { - logger.debug("convert called"); - - if (logger.isDebugEnabled()) { - logger.debug(XMLUtils.toString(document)); - } - - ArrayList<DataCageNode> roots = new ArrayList<DataCageNode>(); - NodeList nodes = document.getChildNodes(); - for (int i = 0, N = nodes.getLength(); i < N; ++i) { - Node node = nodes.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element ele = (Element)node; - roots.add(convertElement(ele)); - } - } - return roots.isEmpty() - ? new DataCageTree() - : new DataCageTree(roots.get(0)); - } - - protected void convertChildren(DataCageNode parent, Element sub) { - //System.err.println("convertChildren called"); - NodeList children = sub.getChildNodes(); - for (int i = 0, N = children.getLength(); i < N; ++i) { - Node child = children.item(i); - if (child.getNodeType() == Node.ELEMENT_NODE) { - Element childele = (Element)child; - parent.addChild(convertElement(childele)); - - if (childele.hasAttribute("description")) - logger.debug("nwd: " + childele.getAttribute("description")); - } - } // for all children - } - - private DataCageNode convertElement(Element element) { - String name = element.getLocalName(); - - logger.debug("search for name: " + name); - - NodeConverter converter = converters.get(name); - if (converter == null) { - converter = I18N_CONVERTER; - } - return converter.convert(element, this); - - } - - - /** - * Creates key/value pairs from Nodes Attributes. - */ - public static AttrList toAttrList(NamedNodeMap nodeMap) { - if (nodeMap == null) { - return null; - } - int N = nodeMap.getLength(); - - if (N == 0) { - return null; - } - - AttrList result = new AttrList(N); - - for (int i = 0; i < N; ++i) { - Node node = nodeMap.item(i); - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - Attr attr = (Attr)node; - String key = attr.getName(); - String value = attr.getValue(); - result.add(key, value); - } - } - - return result; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -package de.intevation.flys.client.shared; - - -public final class DoubleUtils { - - public static final String DEFAULT_DELIM = " "; - - - private DoubleUtils() { - } - - - public static Double getDouble(String value) { - try { - return Double.valueOf(value); - } - catch (NumberFormatException nfe) { - // do nothing - } - - return null; - } - - - public static double[] getMinMax(String value) { - return getMinMax(value, DEFAULT_DELIM); - } - - - public static double[] getMinMax(String value, String delim) { - if (value == null) { - return null; - } - - String[] values = value.split(delim); - - int len = values != null ? values.length : 0; - double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; - - for (int i = 0; i < len; i++) { - Double d = getDouble(values[i]); - - if (d != null) { - mm[0] = mm[0] < d ? mm[0] : d; - mm[1] = mm[1] > d ? mm[1] : d; - } - } - - return mm[0] != Double.MAX_VALUE && mm[1] != -Double.MAX_VALUE - ? mm - : null; - } - - /** toIndex is not inclusive, fromIndex is. */ - static void fill(double[] array, int fromIndex, int toIndex, double val) { - for (int i = fromIndex; i < toIndex; i++) { - array[i] = val; - } - } - - /** @see java.util.Arrays.copyOf */ - public static double[] copyOf(double[] toCopy, int newLen) { - double[] nArray = new double[newLen]; - - if (toCopy == null) { - fill(nArray, 0, nArray.length, 0d); - return nArray; - } - - int goTo = (newLen < toCopy.length) - ? newLen - : toCopy.length; - - for (int i = 0; i < goTo; i++) { - nArray[i] = toCopy[i]; - } - fill (nArray, goTo, nArray.length, 0d); - return nArray; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/FieldVerifier.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -package de.intevation.flys.client.shared; - -/** - * <p> - * FieldVerifier validates that the name the user enters is valid. - * </p> - * <p> - * This class is in the <code>shared</code> package because we use it in both - * the client code and on the server. On the client, we verify that the name is - * valid before sending an RPC request so the user doesn't have to wait for a - * network round trip to get feedback. On the server, we verify that the name is - * correct to ensure that the input is correct regardless of where the RPC - * originates. - * </p> - * <p> - * When creating a class that is used on both the client and the server, be sure - * that all code is translatable and does not use native JavaScript. Code that - * is note translatable (such as code that interacts with a database or the file - * system) cannot be compiled into client side JavaScript. Code that uses native - * JavaScript (such as Widgets) cannot be run on the server. - * </p> - */ -public class FieldVerifier { - - /** - * Verifies that the specified name is valid for our service. - * - * In this example, we only require that the name is at least four - * characters. In your application, you can use more complex checks to ensure - * that usernames, passwords, email addresses, URLs, and other fields have the - * proper syntax. - * - * @param name the name to validate - * @return true if valid, false if invalid - */ - public static boolean isValidName(String name) { - if (name == null) { - return false; - } - return name.length() > 3; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/MapUtils.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package de.intevation.flys.client.shared; - -import java.util.Date; - - -public class MapUtils { - - public static final String GET_LEGEND_GRAPHIC_TEMPLATE = - "${SERVER}SERVICE=WMS&VERSION=1.1.1&layer=${LAYER}" + - "&REQUEST=getLegendGraphic&FORMAT=image/png"; - - - private MapUtils() { - } - - public static String getLegendGraphicUrl(String server, String layer) { - return getLegendGraphicUrl(server, layer, -1); - } - - public static String getLegendGraphicUrl(String server, String layer, int dpi) { - if (server == null || layer == null) { - return null; - } - - if (server.contains("osm.intevation.de")) { - // GetLegend is not implemented at osm.intevation.de - // This avoids an error in the print log - return null; - } - server = server.indexOf("?") >= 0 ? server : server + "?"; - - String url = GET_LEGEND_GRAPHIC_TEMPLATE; - url = url.replace("${SERVER}", server); - url = url.replace("${LAYER}", layer); - url = url + "×tamp=" + new Date().getTime(); - if (dpi != -1) { - url+="&legend_options=dpi:" + dpi; - } - - return url; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/Transform2D.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -package de.intevation.flys.client.shared; - -import java.io.Serializable; -import java.util.Date; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; -import com.google.gwt.i18n.client.NumberFormat; - - -/** - * This object supports a linear transformation to transform xy coordinates into - * an other coordinate system based on scale and translation values. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class Transform2D implements Serializable { - - protected String xType; - protected String yType; - - protected double sx; - protected double sy; - - protected double tx; - protected double ty; - - - public Transform2D() { - } - - - /** - * Creates a new transformation with scale and translation factors. - * - * @param sx The scale factor for the x axis. - * @param sy The scale factor for the y axis. - * @param tx The translation factor for the x axis. - * @param ty The translation factor for the y axis. - */ - public Transform2D(double sx, double sy, double tx, double ty) { - this(sx, sy, tx, ty, "number", "number"); - } - - - public Transform2D( - double sx, double sy, - double tx, double ty, - String xType, - String yType - ) { - this.xType = xType; - this.yType = yType; - - this.sx = sx; - this.sy = sy; - this.tx = tx; - this.ty = ty; - } - - - /** - * Transforms the pixel x and y into a new coordinate system based on the - * scale and translation values specified in the constructor. - */ - public double[] transform(double x, double y) { - double resX = sx * x + tx; - double resY = sy * y + ty; - - return new double[] { resX, resY }; - } - - - public String[] format(Number[] xy) { - String x = null; - String y = null; - - if (xType.equals("date")) { - x = formatDate(xy[0].longValue()); - } - else { - x = formatNumber(xy[0].doubleValue()); - } - - if (yType.equals("date")) { - y = formatDate(xy[1].longValue()); - } - else { - y = formatNumber(xy[1].doubleValue()); - } - - return new String[] { x, y }; - } - - - protected String formatDate(long time) { - Date date = new Date(time); - DateTimeFormat df = getDateTimeFormat(); - - return df.format(date); - } - - - protected String formatNumber(double number) { - NumberFormat nf = getNumberFormat(); - - return nf.format(number); - } - - - public DateTimeFormat getDateTimeFormat() { - return DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT); - } - - - public NumberFormat getNumberFormat() { - return NumberFormat.getDecimalFormat(); - } - - - public void dumpGWT() { - GWT.log("SX = " + sx); - GWT.log("SY = " + sy); - GWT.log("TX = " + tx); - GWT.log("TY = " + ty); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/exceptions/AuthenticationException.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -package de.intevation.flys.client.shared.exceptions; - -import java.io.Serializable; - - -/** - * This exception class is used if an error occured while user authentication. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class AuthenticationException -extends Exception -implements Serializable -{ - public AuthenticationException() { - } - - - public AuthenticationException(String msg) { - super(msg); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/exceptions/ServerException.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.shared.exceptions; - -import java.io.Serializable; - - -public class ServerException -extends Exception -implements Serializable -{ - public ServerException() { - } - - - public ServerException(String msg) { - super(msg); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Artifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.List; - - -/** - * This class represents an artifact for the client. It contains the necessary - * information for the client and the communication with the artifact server. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface Artifact extends Serializable { - - /** - * Returns the UUID of the artifact. - * - * @return the UUID. - */ - public String getUuid(); - - - /** - * Returns the hash of the artifact. - * - * @return the hash. - */ - public String getHash(); - - - /** - * Returns the name of the artifact. - * This happens to be the factory name, too. - * - * @return the name. - */ - public String getName(); - - /** - * Returns the ArtifactDescription. - * - * @return the artifact description. - */ - public ArtifactDescription getArtifactDescription(); - - - /** - * Returns true, if the Artifact is in Background mode. - * - * @return true, if the artifact is in background mode. - */ - public boolean isInBackground(); - - - /** - * Return a list of background messages. - * - * @return a list of background messages. - */ - public List<CalculationMessage> getBackgroundMessages(); - - - /** - * Sets a new ArtifactDescription. - * - * @param artifactDescription The new artifact description. - */ - public void setArtifactDescription(ArtifactDescription artifactDescription); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * The artifact description describes a state of an artifact. There are - * operations defined that return former inserted data, possible input values - * and output targets that are available in the current state of the artifact. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface ArtifactDescription extends Serializable { - - /** - * Returns the data that have been inserted in former states of the - * artifact. - * - * @return the old data of former states. - */ - public DataList[] getOldData(); - - - /** - * Returns the data with all its options that might be inserted in the - * current state of the artifact. - * - * @return the current data. - */ - public DataList getCurrentData(); - - - /** - * Returns the current state as string. - * - * @return the current state. - */ - public String getCurrentState(); - - - /** - * Returns the reachable states as string. - * - * @return the reachable states. - */ - public String[] getReachableStates(); - - - /** - * Returns the name of the selected river. - * - * @return the selected river. - */ - public String getRiver(); - - - /** - * Returns the selected min and max kilomter if existing otherwise null. - * - * @return an array of [min-km, max-km] if existing otherwise null. - */ - public double[] getKMRange(); - - - /** - * Returns the selected reference gauge (which needs to be a data named - * 'reference_gauge'. - * - * @return the selected reference gauge (which needs to be a data named - * 'reference_gauge'. - */ - public String getReferenceGauge(); - - - /** - * Returns the string value of a data object with name <i>dataName</i>. - * - * @return the string value of a data object with name <i>dataName</i>. - */ - public String getDataValueAsString(String dataName); - - - /** - * Returns the available output modes. - * - * @return the available output modes. - */ - public OutputMode[] getOutputModes(); - - - /** - * Returns the recommended artifacts suggested by the server. - * - * @return the recommended artifacts. - */ - public Recommendation[] getRecommendations(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import java.util.HashMap; -import java.util.Map; -import java.util.List; - -public class ArtifactFilter -implements Serializable -{ - protected String factoryName; - - protected Map<String, OutFilter> outFilters; - - public ArtifactFilter() { - outFilters = new HashMap<String, OutFilter>(); - } - - public ArtifactFilter(String factoryName) { - this(); - this.factoryName = factoryName; - } - - public String getFactoryName() { - return factoryName; - } - - public void setFactoryName(String factoryName) { - this.factoryName = factoryName; - } - - public void add(String out, String name, String num) { - if (out == null) { - out = ToLoad.uniqueKey(outFilters); - } - - OutFilter outFilter = outFilters.get(out); - - if (outFilter == null) { - outFilter = new OutFilter(out); - outFilters.put(out, outFilter); - } - outFilter.add(name, num); - } - - public String collectIds() { - StringBuilder sb = new StringBuilder(); - for (OutFilter outFilter: outFilters.values()) { - outFilter.collectIds(sb); - } - return sb.toString(); - } - - public Recommendation.Filter toFilter() { - Recommendation.Filter rf = new Recommendation.Filter(); - for (Map.Entry<String, OutFilter> entry: outFilters.entrySet()) { - List<Recommendation.Facet> facets = entry.getValue().toFacets(); - rf.add(entry.getKey(), facets); - } - return rf; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/AttrList.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; -import java.util.ArrayList; - -import java.io.Serializable; - -public class AttrList implements Serializable -{ - protected List<String> keyValues; - - public AttrList() { - this(5); - } - - public AttrList(int size) { - keyValues = new ArrayList<String>(size*2); - } - - public int size() { - return keyValues != null ? keyValues.size()/2 : null; - } - - public String getKey(int index) { - return keyValues.get(index*2); - } - - public String getValue(int index) { - return keyValues.get(index*2 + 1); - } - - public void add(String key, String value) { - keyValues.add(key); - keyValues.add(value); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/AttributedTheme.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class AttributedTheme implements Theme { - - protected Map<String, String> attributes; - - /** CollectionItem associated with this facet/themes artifact. */ - protected CollectionItem collectionItem; - - public AttributedTheme() { - this.attributes = new HashMap<String, String>(); - } - - - public Set<String> getKeys() { - return attributes.keySet(); - } - - - public void addAttr(String name, String value) { - if (name != null && value != null) { - attributes.put(name, value); - } - } - - - public String getAttr(String name) { - return attributes.get(name); - } - - - public Integer getAttrAsInt(String name) { - String attr = getAttr(name); - - if (attr != null && attr.length() > 0) { - try { - return Integer.parseInt(attr); - } - catch (NumberFormatException nfe) { - } - } - - return null; - } - - - public boolean getAttrAsBoolean(String name) { - String attr = getAttr(name); - - if (attr != null) { - try { - int num = Integer.valueOf(attr); - return num > 0; - } - catch (NumberFormatException nfe) { - // do nothing - } - } - - return Boolean.valueOf(attr); - } - - - @Override - public int getPosition() { - Integer pos = getAttrAsInt("pos"); - - return pos != null ? pos.intValue() : -1; - } - - - @Override - public void setPosition(int pos) { - addAttr("pos", String.valueOf(pos)); - } - - - @Override - public int getIndex() { - Integer idx = getAttrAsInt("index"); - - return idx != null ? idx.intValue() : -1; - } - - - @Override - public int getActive() { - return getAttrAsInt("active"); - } - - - @Override - public void setActive(int active) { - addAttr("active", String.valueOf(active)); - } - - - @Override - public String getArtifact() { - return getAttr("artifact"); - } - - - @Override - public String getFacet() { - return getAttr("facet"); - } - - - @Override - public String getDescription() { - return getAttr("description"); - } - - - @Override - public void setDescription(String description) { - if (description != null && description.length() > 0) { - addAttr("description", description); - } - } - - - @Override - public int getVisible() { - return getAttrAsInt("visible"); - } - - - @Override - public void setVisible(int visible) { - addAttr("visible", String.valueOf(visible)); - } - - - @Override - public boolean equals(Object o) { - if (!(o instanceof AttributedTheme)) { - return false; - } - - AttributedTheme other = (AttributedTheme) o; - - if (other.getPosition() != getPosition()) { - return false; - } - - if (!other.getArtifact().equals(getArtifact())) { - return false; - } - - if (other.getActive() != getActive()) { - return false; - } - - if (!other.getFacet().equals(getFacet())) { - return false; - } - - if (!other.getDescription().equals(getDescription())) { - return false; - } - - if (other.getIndex() != getIndex()) { - return false; - } - - if (other.getVisible() != getVisible()) { - return false; - } - - return true; - } - - - /** Get the CollectionItem representing the facets artifact. */ - @Override - public CollectionItem getCollectionItem() { - return collectionItem; - } - - - /** Set the CollectionItem representing the facets artifact. */ - @Override - public void setCollectionItem(CollectionItem ci) { - this.collectionItem = ci; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Axis.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface Axis extends Serializable { - - int getPos(); - - Number getFrom(); - - Number getTo(); - - Number getMin(); - - Number getMax(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/BBox.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -public class BBox implements Serializable { - - public double lowerX; - public double upperX; - public double lowerY; - public double upperY; - - - public BBox() { - } - - - public BBox(double lowerX, double lowerY, double upperX, double upperY) { - this.lowerX = lowerX; - this.lowerY = lowerY; - this.upperX = upperX; - this.upperY = upperY; - } - - - public double getLowerX() { - return lowerX; - } - - - public double getLowerY() { - return lowerY; - } - - - public double getUpperX() { - return upperX; - } - - - public double getUpperY() { - return upperY; - } - - - public String toString() { - return - "(" + lowerX + "," + lowerY + ")" + - "(" + upperX + "," + upperY + ")"; - } - - - public static BBox getBBoxFromString(String bbox) { - String[] coords = bbox != null ? bbox.split(" ") : null; - - if (coords == null || coords.length < 4) { - return null; - } - - try { - return new BBox( - Double.parseDouble(coords[0]), - Double.parseDouble(coords[1]), - Double.parseDouble(coords[2]), - Double.parseDouble(coords[3])); - } - catch (NumberFormatException nfe) { - // do nothing here - } - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/BooleanProperty.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.HashMap; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class BooleanProperty extends PropertySetting { - - /** - * Create a new BooleanProperty for settings. - */ - public BooleanProperty() { - this.attributes = new HashMap<String, String>(); - } - - - /** - * Create a new BooleanProperty. - * @param name The attribute name. - * @param value The current value. - */ - public BooleanProperty( - String name, - Boolean value) - { - this.name = name; - this.value = value.toString(); - this.attributes = new HashMap<String, String>(); - } - - - @Override - public Boolean getValue() { - return Boolean.valueOf(this.value); - } - - - public void setValue(Boolean value) { - this.value = value.toString(); - } - - - public Object clone() { - BooleanProperty clone = new BooleanProperty(this.getName(), - this.getValue()); - for(String s: this.getAttributeList()) { - clone.setAttribute(s, this.getAttribute(s)); - } - return clone; - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/CalculationMessage.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -public class CalculationMessage implements Serializable { - - protected int steps; - protected int currentStep; - protected String message; - - - public CalculationMessage() { - } - - - public CalculationMessage(int steps, int currentStep, String message) { - this.steps = steps; - this.currentStep = currentStep; - this.message = message; - } - - - public int getSteps() { - return steps; - } - - - public int getCurrentStep() { - return currentStep; - } - - - public String getMessage() { - return message; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - - -public class Capabilities implements Serializable { - - protected String title; - protected String onlineResource; - protected String fees; - protected String accessConstraints; - - protected ContactInformation contactInformation; - - protected List<WMSLayer> layers; - - - public Capabilities() { - layers = new ArrayList<WMSLayer>(); - } - - - /** - * @param fees - * @param accessConstraints - * @param layers - */ - public Capabilities( - String title, - String onlineResource, - ContactInformation contactInformation, - String fees, - String accessConstraints, - List<WMSLayer> layers - ) { - this.title = title; - this.onlineResource = onlineResource; - this.contactInformation = contactInformation; - this.fees = fees; - this.accessConstraints = accessConstraints; - this.layers = layers; - } - - - public String getTitle() { - return title; - } - - - public String getOnlineResource() { - return onlineResource; - } - - - public ContactInformation getContactInformation() { - return contactInformation; - } - - - public String getFees() { - return fees; - } - - - public String getAccessConstraints() { - return accessConstraints; - } - - - public List<WMSLayer> getLayers() { - return layers; - } - - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("--- Capabilities ---\n"); - sb.append("Title:.............. " + title + "\n"); - sb.append("Online Resource:.... " + onlineResource + "\n"); - sb.append("Contact Information: " + contactInformation + "\n"); - sb.append("Fees:............... " + fees + "\n"); - sb.append("Access Constraints:. " + accessConstraints + "\n"); - sb.append("Layers: "); - - for (WMSLayer layer: layers) { - sb.append(" - " + layer + "\n"); - } - - return sb.toString(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - - -/** - * The Chart implementation of an Artifact. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class ChartArtifact extends DefaultArtifact { - - /** The name of this artifact: 'new_chart'.*/ - public static final String NAME = "new_chart"; - - - public ChartArtifact() { - } - - - public ChartArtifact(String uuid, String hash) { - super(uuid, hash); - } - - - public ChartArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - super(uuid, hash, inBackground, messages); - } - - - public String getName() { - return NAME; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import com.google.gwt.core.client.GWT; - -import de.intevation.flys.client.shared.Transform2D; - - -/** - * Give information about chart dimension and transform of chart<->pixel - * space. - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ChartInfo implements Serializable { - - protected Axis[] xAxes; - protected Axis[] yAxes; - - protected Transform2D[] transformer; - - - public ChartInfo() { - } - - - public ChartInfo(Axis[] xAxes, Axis[] yAxes, Transform2D[] transformer) { - this.xAxes = xAxes; - this.yAxes = yAxes; - this.transformer = transformer; - } - - - public Transform2D getTransformer(int pos) { - if (pos >= 0 && pos < transformer.length) { - return transformer[pos]; - } - - return null; - } - - - public int getTransformerCount() { - return transformer.length; - } - - - public int getXAxisCount() { - return xAxes.length; - } - - - public int getYAxisCount() { - return yAxes.length; - } - - - public Axis getXAxis(int pos) { - if (pos >= 0 && pos < xAxes.length) { - return xAxes[pos]; - } - - return null; - } - - - public Axis getYAxis(int pos) { - if (pos >= 0 && pos < yAxes.length) { - return yAxes[pos]; - } - - return null; - } - - - public void dumpGWT() { - StringBuilder sb = new StringBuilder(); - - Axis x = getXAxis(0); - - GWT.log("X axis:"); - GWT.log("... from " + x.getFrom() + " to " + x.getTo()); - GWT.log("... min " + x.getMin() + " max " + x.getMax()); - - for (int i = 0, count = getYAxisCount(); i < count; i++) { - Axis y = getYAxis(i); - - GWT.log("Y axis " + i + ":"); - GWT.log("... from " + y.getFrom() + " to " + y.getTo()); - GWT.log("... min " + y.getMin() + " max " + y.getMax()); - } - - for (Transform2D t: transformer) { - t.dumpGWT(); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartMode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.OutputTab; -import de.intevation.flys.client.client.ui.chart.ChartOutputTab; -import de.intevation.flys.client.client.ui.chart.NaviChartOutputTab; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ChartMode extends DefaultOutputMode { - - public ChartMode() { - } - - - public ChartMode(String name, String desc, String mimeType) { - super(name, desc, mimeType); - } - - - public ChartMode( - String name, - String descrition, - String mimeType, - List<Facet> facets, - String type) - { - super(name, descrition, mimeType, facets); - this.type = type; - } - - - /** Create output tab. Some outs feel better inside a specialized one. */ - @Override - public OutputTab createOutputTab(String t, Collection c, CollectionView p) { - if (this.getName().equals("fix_wq_curve") || - this.getName().equals("extreme_wq_curve") || - this.getName().equals("fix_deltawt_curve") || - this.getName().equals("fix_derivate_curve") || - this.getName().equals("fix_vollmer_wq_curve")){ - return new NaviChartOutputTab(t, c, this, p); - } - return new ChartOutputTab(t, c, this, p); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import java.util.Map; - - -/** - * The artifact collection. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface Collection extends Serializable { - - public String identifier(); - - public String getName(); - - public void setName(String name); - - public Date getCreationTime(); - - /** TODO never called, trivial implementation. Can be removed? */ - public Date getLastAccess(); - - public long getTTL(); - - public void setTTL(long ttl); - - public void addItem(CollectionItem item); - - public int getItemLength(); - - public CollectionItem getItem(int idx); - - public CollectionItem getItem(String uuid); - - public Map<String, OutputMode> getOutputModes(); - - public ThemeList getThemeList(String outName); - - public Settings getSettings(String outName); - - public void setSettings(Map<String, Settings> settings); - - public void addSettings(String name, Settings settings); - - /** Sets mapping outputname to ThemeList. */ - public void setThemeLists(Map<String, ThemeList> map); - - public List<Recommendation> getRecommendations(); - - public void addRecommendation(Recommendation recommendation); - - public void addRecommendations(List<Recommendation> recommendations); - - public boolean loadedRecommendation(Recommendation recommendation); - - public boolean hasItems(); - - /** - * Returns the name which should be displayed in the client gui - * @return String display name - */ - public String getDisplayName(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionItem.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.List; -import java.util.Map; - - -/** - * The CollectionItem interface that provides methods to get information about - * artifacts and its output modes. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface CollectionItem extends Serializable { - - /** - * Returns the identifier of the wrapped artifact. - * - * @return the identifier of the wrapped artifact. - */ - String identifier(); - - - /** - * Returns the hash of the wrapped artifact. - * - * @return the hash of the wrapped artifact. - */ - String hash(); - - - /** - * Returns the output modes of the wrapped artifact. - * - * @return the output modes of the wrapped artifact. - */ - List<OutputMode> getOutputModes(); - - - /** - * Returns the facets of the wrapped artifact for a specific output mode. - * - * @param outputmode The name of an output mode that is supported by this - * item. - * - * @return the facets of the wrapped artifact for a specific output mode. - */ - List<Facet> getFacets(String outputmode); - - - /** - * Returns data key/value map. - * @return key/value data map - */ - Map<String, String> getData(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import java.util.List; -import java.util.ArrayList; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class CollectionItemAttribute implements Serializable { - - /** The list of styles. */ - protected List<Style> styles; - - /** The artifact. */ - protected String artifact; - - - /** - * Creates a new CollectionItem Attribute. - */ - public CollectionItemAttribute() { - styles = new ArrayList<Style>(); - } - - - /** - * Append a new Style. - * @param style The style. - */ - public void appendStyle (Style style) { - this.styles.add(style); - } - - - /** - * Remove a style from the attributes. - * @param name The style name. - */ - public void removeStyle (String name) { - for (int i = 0; i < styles.size(); i++) { - if (styles.get(i).getName().equals(name)) { - styles.remove(i); - } - } - } - - - /** - * Get a style from the collection item. - * @param facet The facet this style belongs to. - * @param index The style index. - * - * @return The selected style or 'null'. - */ - public Style getStyle(String facet, int index) { - for (int i = 0; i < styles.size(); i++) { - Style tmp = styles.get(i); - if (tmp.getFacet().equals(facet) && - tmp.getIndex() == index) { - return tmp; - } - } - return null; - } - - - /** - * Get the style at a postion. - * @param i The position index. - * - * @return The selected style. - */ - public Style getStyle(int i) { - return styles.get(i); - } - - - /** - * Get the number of styles. - * @return The number of styles. - */ - public int getNumStyles() { - return styles.size(); - } - - - /** - * Set the current artifact. - * @param The artifact uuid. - */ - public void setArtifact(String artifact) { - this.artifact = artifact; - } - - - /** - * Get the associated artifact. - * @return The artifact. - */ - public String getArtifact () { - return this.artifact; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.Date; - -import com.google.gwt.safehtml.shared.SafeHtml; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - - -/** - * The CollectionRecord is a wrapper to put Collection objects into a ListGrid. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class CollectionRecord extends ListGridRecord { - - /** The artifact collection. */ - protected Collection collection; - - - /** - * The default constructor. - * - * @param collection The artifact collection. - */ - public CollectionRecord(Collection collection) { - this.collection = collection; - - setCreationTime(collection.getCreationTime()); - - String name = collection.getName(); - setName(name != null && name.length() > 0 - ? name - : collection.identifier()); - - setTTL(collection.getTTL()); - } - - - /** - * Sets the creation time. - * - * @param creationTime The creation time. - */ - public void setCreationTime(Date creationTime) { - setAttribute("creationTime", creationTime); - } - - - /** - * Returns the date of the creation. - * - * @return the creation time. - */ - public Date getCreationTime() { - return getAttributeAsDate("creationTime"); - } - - - /** - * Returns the name of the collection. - * - * @return the name of the collection. - */ - public void setName(String name) { - SafeHtmlBuilder b = new SafeHtmlBuilder(); - b.appendEscaped(name); - - SafeHtml html = b.toSafeHtml(); - - setAttribute("name", html.asString()); - } - - - /** - * Returns the name of the collection or the uuid if no name is specified. - * - * @return the name of the collection. - */ - public String getName() { - return getAttributeAsString("name"); - } - - - public void setTTL(long ttl) { - if (ttl == 0) { - setAttribute("ttl", "star_gold"); - } - else { - setAttribute("ttl", "star_silver"); - } - } - - - public String getTTL() { - return getAttribute("ttl"); - } - - - /** - * Returns the collection objects itself. - * - * @return the collection object. - */ - public Collection getCollection() { - return collection; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ContactInformation.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -public class ContactInformation implements Serializable { - - protected String person; - protected String organization; - protected String address; - protected String city; - protected String postcode; - protected String phone; - protected String email; - - - public ContactInformation() { - } - - - public void setPerson(String person) { - this.person = person; - } - - - public String getPerson() { - return person; - } - - - public void setOrganization(String organization) { - this.organization = organization; - } - - - public String getOrganization() { - return organization; - } - - - public void setAddress(String address) { - this.address = address; - } - - - public String getAddress() { - return address; - } - - - public void setCity(String city) { - this.city = city; - } - - - public String getCity() { - return city; - } - - - public void setPostcode(String postcode) { - this.postcode = postcode; - } - - - public String getPostcode() { - return postcode; - } - - - public void setPhone(String phone) { - this.phone = phone; - } - - - public String getPhone() { - return phone; - } - - - public void setEmail(String email) { - this.email = email; - } - - - public String getEmail() { - return email; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Data.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * A Data object represents the necessary data of a single state of the - * artifact. It might provide several DataItems or just a single DataItem. The - * <code>type</code> makes it possible to validate the input in the client. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface Data extends Serializable { - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel(); - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription(); - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType(); - - - /** - * Returns the DataItems provided by this Data object. - * - * @return the DataItems. - */ - public DataItem[] getItems(); - - - /** - * Returns the default value of this data object. - * - * @return the default value. - */ - public DataItem getDefault(); - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DataCageNode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; -import java.util.ArrayList; - -import java.io.Serializable; - -public class DataCageNode implements Serializable -{ - protected String name; - protected String description; - protected List<DataCageNode> children; - protected AttrList attrs; - - public DataCageNode() { - } - - public DataCageNode(String name) { - this(name, null); - } - - public DataCageNode(String name, AttrList attrs) { - this(name, name, attrs); - } - - public DataCageNode(String name, String description, AttrList attrs) { - this.name = name; - this.description = description; - this.attrs = attrs; - } - - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public void setName(String name) { - this.name = name; - } - - public void addChild(DataCageNode child) { - if (children == null) { - children = new ArrayList<DataCageNode>(); - } - children.add(child); - } - - public List<DataCageNode> getChildren() { - return children; - } - - public AttrList getAttributes() { - return attrs; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DataCageTree.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -public class DataCageTree implements Serializable -{ - protected DataCageNode root; - - public DataCageTree() { - } - - public DataCageTree(DataCageNode root) { - this.root = root; - } - - public void setRoot(DataCageNode root) { - this.root = root; - } - - public DataCageNode getRoot() { - return root; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DataItem.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * A DataItem represents a concrete item that might be selected, chosen or - * inserted by the user. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface DataItem extends Serializable { - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel(); - - - /** - * Returns the description of the item. - * - * @return the description; - */ - public String getDescription(); - - - /** - * Returns the value of the item. - * - * @return the value. - */ - public String getStringValue(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DataList.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,213 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DataList implements Serializable, Cloneable { - - /** The list of Data objects managed by this list. */ - protected List<Data> data; - - /** The name of the state that this list belongs to. */ - protected String state; - - /** The name of a UIProvider that is recommended to render this DataList. */ - protected String uiprovider; - - /** The label that should be used to label data objects. */ - protected String label; - - /** The help text (URL) that should be displayed for this data object. */ - protected String helpText; - - - /** - * The default constructor that creates a new DataList without Data objects - * and no UIProvider. - */ - public DataList() { - data = new ArrayList<Data>(); - } - - - /** - * Constructor. - * - * @param state The name of the state that this list belongs to. - * @param size The initial size of the list. - */ - public DataList(String state, int size) { - this.state = state; - this.data = new ArrayList<Data>(size); - } - - - /** - * A constructor that creates a new DataList without Data objects and no - * UIProvider. Size defines the initial size of the list. - * - * @param state The name of the state that this list belongs to. - * @param size The initial size of the list. - * @param uiprovider The UIProvider that should be used to render this list. - */ - public DataList(String state, int size, String uiprovider) { - this(state, size); - this.uiprovider = uiprovider; - } - - - /** - * A constructor that creates a new DataList without Data objects and no - * UIProvider. Size defines the initial size of the list. - * - * @param state The name of the state that this list belongs to. - * @param size The initial size of the list. - * @param uiprovider The UIProvider that should be used to render this list. - * @param label The label. - */ - public DataList(String state, int size, String uiprovider, String label) { - this(state, size, uiprovider); - this.label = label; - } - - - /** - * A constructor that creates a new DataList without Data objects and no - * UIProvider. Size defines the initial size of the list. - * - * @param state The name of the state that this list belongs to. - * @param size The initial size of the list. - * @param uiprovider The UIProvider that should be used to render this list. - * @param label The label. - * @param helpText The help text (should be an URL). - */ - public DataList( - String state, - int size, - String uiprovider, - String label, - String helpText - ) { - this(state, size, uiprovider, label); - this.helpText = helpText; - } - - - /** - * Adds a new Data object to the list. - * - * @param obj The Data object. - */ - public void add(Data obj) { - if (obj != null) { - data.add(obj); - } - } - - - /** - * Adds a new Data objects to the list. - * - * @param obj The Data object. - */ - public void add(Data[] obj) { - if (obj != null) { - for (Data o: obj) { - data.add(o); - } - } - } - - - /** - * Returns the Data element at position <i>idx</i>. - * - * @param idx The position of an element that should be returned. - * - * @return the Data element at position <i>idx</i>. - */ - public Data get(int idx) { - if (idx < size()) { - return data.get(idx); - } - - return null; - } - - - /** - * Returns the whole list of Data objects. - * - * @return the whole list of Data objects. - */ - public List<Data> getAll() { - return data; - } - - /** - * Returns the number of Data objects in the list. - * - * @param the number of Data objects in the list. - */ - public int size() { - return data.size(); - } - - - /** - * Returns the name of the state that this list belongs to. - * - * @return the name of the state that this list belongs to. - */ - public String getState() { - return state; - } - - - /** - * Returns the label for this list. - * - * @return the label of this list. - */ - public String getLabel() { - return label; - } - - - /** - * Retrieves the name of a UIProvider or null if no one is recommended. - * - * @return the name of a UIProvider or null if no one is recommended. - */ - public String getUIProvider() { - return uiprovider; - } - - - /** - * Returns the help text which should be an URL. - * - * @return the help text. - */ - public String getHelpText() { - return helpText; - } - - - public Object clone() { - DataList clone = new DataList( - this.state, - this.data.size(), - this.uiprovider, - this.label, - this.helpText); - clone.data = (List<Data>) ((ArrayList<Data>)data).clone(); - - return clone; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DateAxis.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DateAxis implements Axis { - - public static final String TYPE = "date"; - - - protected int pos; - - protected long from; - protected long to; - - protected long min; - protected long max; - - - public DateAxis() { - } - - - public DateAxis(int pos, long from, long to, long min, long max) { - this.pos = pos; - this.from = from; - this.to = to; - this.min = min; - this.max = max; - } - - - @Override - public int getPos() { - return pos; - } - - - @Override - public Number getFrom() { - return from; - } - - - @Override - public Number getTo() { - return to; - } - - - @Override - public Number getMin() { - return min; - } - - - @Override - public Number getMax() { - return max; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - - -/** - * The default implementation of an artifact that might be used in the client. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultArtifact implements Artifact { - - /** The artifact's uuid. */ - protected String uuid; - - /** The artifacts hash value. */ - protected String hash; - - /** Determines if the artifact is in background mode.*/ - protected boolean inBackground; - - protected List<CalculationMessage> messages; - - /** The current artifact description. */ - protected ArtifactDescription artifactDescription; - - /** - * This constructor should not be used to create new instances of this - * class. An empty artifact without uuid and hash will be the result of - * this constructor call. - */ - public DefaultArtifact() { - } - - - public DefaultArtifact(String uuid, String hash) { - this(uuid, hash, false, null); - } - - - /** - * This constructor creates a new artifact instance with a uuid and a hash. - * - * @param uuid The artifact's uuid. - * @param hash The artifact's hash. - */ - public DefaultArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - this.uuid = uuid; - this.hash = hash; - this.inBackground = inBackground; - this.messages = messages; - } - - - public String getUuid() { - return uuid; - } - - - public String getHash() { - return hash; - } - - - public String getName() { - return "default"; - } - - - public boolean isInBackground() { - return inBackground; - } - - - public List<CalculationMessage> getBackgroundMessages() { - return messages; - } - - - public ArtifactDescription getArtifactDescription() { - return artifactDescription; - } - - - public void setArtifactDescription(ArtifactDescription description) { - this.artifactDescription = description; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -import de.intevation.flys.client.shared.DoubleUtils; - - -/** - * The default implementation of an {@link ArtifactDescription}. This class just - * implements constructors to create new instances and the necessary methods of - * the interface. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultArtifactDescription implements ArtifactDescription { - - /** Data that have been inserted in former states.*/ - protected DataList[] oldData; - - /** The Data that is allowed to be inserted in the current state.*/ - protected DataList currentData; - - /** The current state name.*/ - protected String currentState; - - /** The names of reachable states.*/ - protected String[] reachableStates; - - /** The output modes of this state.*/ - protected OutputMode[] outputModes; - - /** A list of recommendations suggested by the server.*/ - protected Recommendation[] recommendations; - - - public DefaultArtifactDescription() { - } - - - /** - * The default constructor. - * - * @param old The data that have been inserted in former states. - * @param current The data that might be inserted in the current state. - * @param state The name of the current state. - * @param reachableStates The names of the reachable states. - */ - public DefaultArtifactDescription( - DataList[] old, - DataList current, - String state, - String[] reachableStates) - { - this.oldData = old; - this.currentData = current; - this.currentState = state; - this.reachableStates = reachableStates; - } - - - /** - * The default constructor. - * - * @param old The data that have been inserted in former states. - * @param current The data that might be inserted in the current state. - * @param state The name of the current state. - * @param reachableStates The names of the reachable states. - * @param outputModes The available output modes of this artifact. - */ - public DefaultArtifactDescription( - DataList[] old, - DataList current, - String state, - String[] reachableStates, - OutputMode[] outputModes, - Recommendation[] recommendations) - { - this(old, current, state, reachableStates); - this.outputModes = outputModes; - this.recommendations = recommendations; - } - - - public DataList[] getOldData() { - return oldData; - } - - - public DataList getCurrentData() { - return currentData; - } - - - public String getCurrentState() { - return currentState; - } - - - public String[] getReachableStates() { - return reachableStates; - } - - - public OutputMode[] getOutputModes() { - return outputModes; - } - - - public Recommendation[] getRecommendations() { - return recommendations; - } - - - public String getRiver() { - return getDataValueAsString("river"); - } - - - /** Get [min,max] of data items. */ - public double[] getKMRange() { - Double[] mm = new Double[2]; - - for (DataList list: oldData) { - List<Data> dataList = list.getAll(); - - for (Data data: dataList) { - String dataName = data.getLabel(); - DataItem item = data.getItems()[0]; - - if (dataName.equals("ld_from") || dataName.equals("from")) { - Double d = DoubleUtils.getDouble(item.getStringValue()); - - if (d != null) { - mm[0] = d; - } - } - else if (dataName.equals("ld_to") || dataName.equals("to")) { - Double d = DoubleUtils.getDouble(item.getStringValue()); - - if (d != null) { - mm[1] = d; - } - } - else if (dataName.equals("ld_locations")) { - return DoubleUtils.getMinMax(item.getStringValue()); - } - } - - if (mm[0] != null && mm[1] != null) { - return new double[] { mm[0], mm[1] }; - } - } - - return null; - } - - - public String getReferenceGauge() { - return getDataValueAsString("reference_gauge"); - } - - - public String getDataValueAsString(String name) { - if (oldData == null) { - return null; - } - for (DataList list: oldData) { - List<Data> dataList = list.getAll(); - - for (Data d: dataList) { - String dataName = d.getLabel(); - DataItem item = d.getItems()[0]; - - if (dataName.equals(name)) { - return item.getStringValue(); - } - } - } - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,312 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -/** - * The default implementation of a {@link Collection}. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultCollection implements Collection { - - /** The uuid of the collection. */ - protected String uuid; - - /** The name of the collection. */ - protected String name; - - /** The creation time of this collection. */ - protected Date creation; - - /** - * The time to live of the collection. - * If this value is 0, it will never die. - */ - protected long ttl; - - /** The list of artifacts that are managed by this Collection.*/ - protected List<CollectionItem> items; - - protected List<Recommendation> recommendations; - - /** - * ThemeList by outputmode name. - */ - protected Map<String, ThemeList> themeLists; - - /** - * Settings by outputmode name. - */ - protected Map<String, Settings> settings; - - /** - * Constructor without arguments is necessary for GWT. - */ - public DefaultCollection() { - } - - - public DefaultCollection(String uuid, long ttl, String name) { - this.uuid = uuid; - this.ttl = ttl; - this.name = name; - this.items = new ArrayList<CollectionItem>(); - this.themeLists = new HashMap<String, ThemeList>(); - this.recommendations = new ArrayList<Recommendation>(); - this.settings = new HashMap<String, Settings>(); - } - - - /** - * Creates a new DefaultCollection with a UUID. - * - * @param uuid The UUID. - */ - public DefaultCollection( - String uuid, - long ttl, - String name, - List<Recommendation> recs - ) { - this(uuid, ttl, name); - - this.recommendations = recs; - } - - - public DefaultCollection( - String uuid, - long ttl, - String name, - List<Recommendation> recommendations, - Map<String, ThemeList> themeLists) - { - this(uuid, ttl, name, recommendations); - this.themeLists = themeLists; - } - - - public DefaultCollection( - String uuid, - long ttl, - String name, - List<Recommendation> recommendations, - Map<String, ThemeList> themeLists, - Map<String, Settings> settings) - { - this(uuid, ttl, name, recommendations); - this.themeLists = themeLists; - this.settings = settings; - } - - - /** - * Creates a new DefaultCollection with uuid and name. - * - * @param uuid The identifier of this collection. - * @param name The name of this collection. - * @param creation The creation time. - */ - public DefaultCollection(String uuid, long ttl, String name, Date creation){ - this(uuid, ttl, name); - - this.creation = creation; - } - - - public String identifier() { - return uuid; - } - - - public Date getCreationTime() { - return creation; - } - - - /** - * Returns now. - * TODO candidate for removal? - */ - public Date getLastAccess() { - return new Date(); - } - - - public long getTTL() { - return ttl; - } - - - public void setTTL(long ttl) { - this.ttl = ttl; - } - - - public String getName() { - return name; - } - - - public void setName(String name) { - this.name = name; - } - - - public void addItem(CollectionItem item) { - if (item != null) { - items.add(item); - } - } - - - public int getItemLength() { - return items.size(); - } - - - /** Returns item at index (0-based), or null if out of range. */ - public CollectionItem getItem(int idx) { - if (idx >= getItemLength()) { - return null; - } - - return items.get(idx); - } - - - /** - * Get item whose identifier is the given string. - * @param uuid identifier of collection item (artifacts uuid). - * @return CollectionItem whose identifier is given String, null if not found. - */ - public CollectionItem getItem(String uuid) { - int size = getItemLength(); - for (int i = 0; i < size; i++) { - CollectionItem item = getItem(i); - if (item.identifier().equals(uuid)) { - return item; - } - } - return null; - } - - - public Map<String, OutputMode> getOutputModes() { - Map<String, OutputMode> modes = new HashMap<String, OutputMode>(); - - for (CollectionItem item: items) { - List<OutputMode> itemModes = item.getOutputModes(); - - if (itemModes != null) { - for (OutputMode itemMode: itemModes) { - String name = itemMode.getName(); - if (!modes.containsKey(name)) { - // we dont want duplicated OutputModes in our result. - modes.put(name, itemMode); - } - } - } - } - - return modes; - } - - - /** - * Returns ThemeList for given output name. - */ - public ThemeList getThemeList(String outName) { - if (themeLists != null) { - return themeLists.get(outName); - } - - return null; - } - - - /** - * Returns Settings for given output name. - */ - public Settings getSettings(String outName) { - if (settings != null) { - return settings.get(outName); - } - - return null; - } - - - public void setSettings(Map<String, Settings> settings) { - this.settings = settings; - } - - - public void addSettings(String outname, Settings settings) { - if (this.settings == null) { - this.settings = new HashMap<String, Settings>(); - } - this.settings.put(outname, settings); - } - - - /** Set the outputname to themelist map. */ - public void setThemeLists(Map<String, ThemeList> map) { - this.themeLists = map; - } - - - public List<Recommendation> getRecommendations() { - return recommendations; - } - - - public void addRecommendation(Recommendation recommendation) { - recommendations.add(recommendation); - } - - - public void addRecommendations(List<Recommendation> recommendations) { - this.recommendations.addAll(recommendations); - } - - - public boolean loadedRecommendation(Recommendation recommendation) { - String factory = recommendation.getFactory(); - String dbids = recommendation.getIDs(); - - for (Recommendation in: recommendations) { - String inFactory = in.getFactory(); - String inDbids = in.getIDs(); - - if (factory.equals(inFactory) && dbids.equals(inDbids)) { - return true; - } - } - - return false; - } - - - @Override - public boolean hasItems() { - return items.isEmpty(); - } - - /** - * Returns the name of the collection or uuid if no name is set - */ - @Override - public String getDisplayName() { - if (this.name != null) { - return this.name; - } - return this.uuid; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollectionItem.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; -import java.util.Map; - - -/** - * The default implementation of a CollectionItem (artifact). - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultCollectionItem implements CollectionItem { - - /** The identifier that specifies the artifact related to this item. */ - protected String identifier; - - /** The hash that specifies the artifact related to this item. */ - protected String hash; - - /** The list of output modes supported by the artifact of this item. */ - protected List<OutputMode> outputModes; - - /** The map of datanames to data values. */ - protected Map<String, String> data; - - - /** - * An empty constructor. - */ - public DefaultCollectionItem() { - } - - - /** - * The default constructor to create a new CollectionItem related to an - * artifact with output modes. - * - * @param identifier The identifier of an artifact. - * @param outputModes The output modes supported by this item. - */ - public DefaultCollectionItem( - String identifier, - String hash, - List<OutputMode> modes, - Map<String,String> data - ) { - this.identifier = identifier; - this.hash = hash; - this.outputModes = modes; - this.data = data; - } - - - - public String identifier() { - return identifier; - } - - - public String hash() { - return hash; - } - - - public List<OutputMode> getOutputModes() { - return outputModes; - } - - - public List<Facet> getFacets(String outputmode) { - for (OutputMode mode: outputModes) { - if (outputmode.equals(mode.getName())) { - // TODO Return facets, but facets are not implemented for - // OutputModes yet! - } - } - - return null; - } - - - /** - * Returns artifact data. - * @return key/value data map - */ - public Map<String, String> getData() { - return this.data; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -package de.intevation.flys.client.shared.model; - -/** - * The default implementation of a {@link Data} item. This class just implements - * constructors to create instances and the necessary methods of the interface. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultData implements Data { - - /** The label of this Data object. */ - protected String label; - - /** The description. */ - protected String description; - - /** The type. */ - protected String type; - - /** The DataItems. */ - protected DataItem[] items; - - /** The default DataItem. */ - protected DataItem defaultItem; - - - public DefaultData() { - } - - - /** - * The default constructor to create new DefaultData objects. - * - * @param label The label. - * @param description The description. - * @param type The type. - * @param items The DataItems. - */ - public DefaultData( - String label, - String description, - String type, - DataItem[] items) - { - this(label, description, type, items, null); - } - - - /** - * The constructor to create new DefaultData objects with a default value. - * - * @param label The label. - * @param description The description. - * @param type The type. - * @param items The DataItems. - * @param defaultItem The default DataItem. - */ - public DefaultData( - String label, - String description, - String type, - DataItem[] items, - DataItem defaultItem) - { - this.label = label; - this.description = description; - this.type = type; - this.items = items; - this.defaultItem = defaultItem; - } - - - public String getLabel() { - return label; - } - - - public String getDescription() { - return description; - } - - - public String getType() { - return type; - } - - - public DataItem[] getItems() { - return items; - } - - - public DataItem getDefault() { - return defaultItem; - } - - - /** Conveniently create simplistic data. */ - public static DefaultData createSimpleStringData( - String name, - String value - ) { - DefaultDataItem d = new DefaultDataItem(name, name, value); - return new DefaultData(name, null, null, new DataItem[] {d}); - } - - /** Conveniently create simplistic data array. */ - public static Data[] createSimpleStringDataArray( - String name, - String value - ) { - DefaultDataItem d = new DefaultDataItem(name, name, value); - return new Data[] - { new DefaultData(name, null, null, new DataItem[] {d})}; - } - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = ""; - boolean first = true; - for (int i = 0; i < items.length; i++) { - if (!first) { - data += ";"; - } - data += items[i].getStringValue(); - first = false; - } - return data; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultDataItem.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * The default implementation of a {@link DataItem}. This class just implements - * constructors to create instances and the necessary methods of the interface. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultDataItem implements DataItem { - - /** The label. */ - protected String label; - - /** The description. */ - protected String description; - - /** The value. */ - protected String value; - - - public DefaultDataItem() { - } - - - /** - * The default constructor to create new instances. - * - * @param label The label. - * @param description The description. - * @param value The value. - */ - public DefaultDataItem(String label, String description, String value) { - this.label = label; - this.description = description; - this.value = value; - } - - - public String getLabel() { - return label; - } - - - public String getDescription() { - return description; - } - - - public String getStringValue() { - return value; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultFacet.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * The default implementation of a Facet. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultFacet implements Facet { - - /** The name of the facet.*/ - protected String name; - - /** The description of the facet.*/ - protected String description; - - /** The index of the facet.*/ - protected int index; - - - /** - * An empty constructor. - */ - public DefaultFacet() { - } - - - /** - * The default constructor to create new DefaultFacets. - * - * @param name The name of the facet. - */ - public DefaultFacet(String name) { - this.name = name; - } - - - public DefaultFacet(String name, int index, String description) { - this(name); - - this.index = index; - this.description = description; - } - - - public String getName() { - return name; - } - - - public String getDescription() { - return description; - } - - - public int getIndex() { - return index; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultGaugeInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +0,0 @@ -package de.intevation.flys.client.shared.model; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class DefaultGaugeInfo implements GaugeInfo { - - private String name; - private Double start; - private Double end; - private Double aeo; - private Double datum; - private Double minq; - private Double maxq; - private Double minw; - private Double maxw; - private boolean kmup; - private Double station; - private String wstunit; - private Long officialnumber; - private String rivername; - - public DefaultGaugeInfo() { - } - - public DefaultGaugeInfo( - String rivername, - String name, - boolean kmup, - Double station, - Double start, - Double end, - Double datum, - Double aeo, - Double minq, - Double maxq, - Double minw, - Double maxw, - String wstunit, - Long official) - { - this.rivername = rivername; - this.name = name; - this.kmup = kmup; - this.station = station; - this.start = start; - this.end = end; - this.datum = datum; - this.aeo = aeo; - this.minq = minq; - this.maxq = maxq; - this.minw = minw; - this.maxw = maxw; - this.wstunit = wstunit; - this.officialnumber = official; - } - /** - * Returns the name of the gauge - */ - public String getName() { - return this.name; - } - - /** - * Returns the start KM of the gauge or null if not available - */ - public Double getKmStart() { - return this.start; - } - - /** - * Returns the end KM of the gauge or null if not available - */ - public Double getKmEnd() { - return this.end; - } - - /** - * Returns the mimimum Q value at this gauge or null if not available - */ - public Double getMinQ() { - return this.minq; - } - - /** - * Returns the maximum Q value at this gauge or null if not available - */ - public Double getMaxQ() { - return this.maxq; - } - - /** - * Returns the mimimum W value at this gauge or null if not available - */ - public Double getMinW() { - return this.minw; - } - - /** - * Returns the maximim W value at this gauge or null if not available - */ - public Double getMaxW() { - return this.maxw; - } - - /** - * Returns the datum value or null if not available - */ - public Double getDatum() { - return this.datum; - } - - /** - * Returns the aeo value or null if not available - */ - public Double getAeo() { - return this.aeo; - } - - public boolean isKmUp() { - return this.kmup; - } - - /** - * Returns the station km of the gauge or null if not available - */ - public Double getStation() { - return this.station; - } - - /** - * Returns the wst unit as a String - */ - public String getWstUnit() { - return this.wstunit; - } - - /** - * Returns the official number of this gauge - */ - public Long getOfficialNumber() { - return this.officialnumber; - } - - /** - * Returns the river to which this gauge belongs - */ - public String getRiverName() { - return this.rivername; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultMeasurementStation.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.Date; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class DefaultMeasurementStation implements MeasurementStation { - - private String name; - private Double start; - private Double end; - private Double station; - private String rivername; - private String measurementtype; - private String riverside; - private Integer id; - private boolean kmup; - private String moperator; - private Date starttime; - private Date stoptime; - private String gaugename; - - public DefaultMeasurementStation() { - } - - public DefaultMeasurementStation( - String rivername, - String name, - Integer id, - Double station, - Double start, - Double end, - boolean kmup, - String riverside, - String measurementtype, - String moperator, - Date starttime, - Date stoptime, - String gaugename) - { - this.rivername = rivername; - this.name = name; - this.station = station; - this.start = start; - this.end = end; - this.riverside = riverside; - this.measurementtype = measurementtype; - this.id = id; - this.kmup = kmup; - this.moperator = moperator; - this.starttime = starttime; - this.stoptime = stoptime; - this.gaugename = gaugename; - } - - /** - * Returns the name of the measurement station - */ - @Override - public String getName() { - return this.name; - } - - /** - * Returns the start KM of the measurement station or null if not available - */ - @Override - public Double getKmStart() { - return this.start; - } - - /** - * Returns the end KM of the measurement station or null if not available - */ - @Override - public Double getKmEnd() { - return this.end; - } - - /** - * Returns the river to which this measurement station belongs - */ - @Override - public String getRiverName() { - return this.rivername; - } - - /** - * Returns the type of the measurement station - */ - @Override - public String getMeasurementType() { - return this.measurementtype; - } - - /** - * Returns the station km of this measurement station - */ - @Override - public Double getStation() { - return this.station; - } - - - /** - * Returns the side of the river where this measurement station belongs - */ - @Override - public String getRiverSide() { - return this.riverside; - } - - /** - * Returns the ID of the measurement station - */ - @Override - public Integer getID() { - return this.id; - } - - @Override - public boolean isKmUp() { - return this.kmup; - } - - /** - * Returns the operator of the measurement station - */ - @Override - public String getOperator() { - return this.moperator; - } - - /** - * Returns the start time of the observation at this measurement station - */ - @Override - public Date getStartTime() { - return this.starttime; - } - - /** - * Returns the end time of the observation at this measurement station - */ - @Override - public Date getStopTime() { - return this.stoptime; - } - - /** - * Returns the name of the gauge in reference to this measurement station - */ - @Override - public String getGaugeName() { - return this.gaugename; - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultModule.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -package de.intevation.flys.client.shared.model; - -public class DefaultModule implements Module { - - private String name; - private String localname; - private boolean selected = false; - - public DefaultModule() { - } - - public DefaultModule(String name, String localname, boolean selected) { - this.name = name; - this.localname = localname; - this.selected = selected; - } - - /** - * Returns the name of the module - */ - public String getName() { - return this.name; - } - - /** - * Returns the localized name of the module - */ - public String getLocalizedName() { - return this.localname; - } - - /** - * Returns true if the module should be selected - */ - public boolean isSelected() { - return this.selected; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultOutputMode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.ArrayList; -import java.util.List; - -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.OutputTab; - - -/** - * The default implementation of an Output. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultOutputMode implements OutputMode { - - /** The name of this mode.*/ - protected String name; - - /** The description of this mode.*/ - protected String description; - - /** The mime-type of this mode.*/ - protected String mimeType; - - /** The type that this output mode represents.*/ - protected String type; - - /** The list of available facets of this export mode.*/ - protected List<Facet> facets; - - - /** A convinience constructor.*/ - public DefaultOutputMode() { - facets = new ArrayList<Facet>(); - } - - - /** - * The default constructor. - * - * @param name The name of this mode. - * @param description The description of this mode. - * @param mimeType The mime-type of this mode. - */ - public DefaultOutputMode(String name, String description, String mimeType) { - this.name = name; - this.description = description; - this.mimeType = mimeType; - } - - - public DefaultOutputMode( - String name, - String description, - String mimeType, - String type) - { - this(name, description, mimeType); - - this.type = type; - } - - - public DefaultOutputMode( - String name, - String description, - String mimeType, - List<Facet> facets) - { - this(name, description, mimeType); - this.type = ""; - this.facets = facets; - } - - - public String getName() { - return name; - } - - - public String getDescription() { - return description; - } - - - public String getMimeType() { - return mimeType; - } - - - public String getType() { - return type; - } - - - /** - * Adds a new facet to this export. - * - * @param facet The new facet. - */ - public void addFacet(Facet facet) { - facets.add(facet); - } - - - /** - * Returns the number of facets supported by this export. - * - * @return the number of facets. - */ - public int getFacetCount() { - return facets.size(); - } - - - /** - * Returns the facet at a given position. - * - * @param idx The position of a facet. - * - * @return a facet. - */ - public Facet getFacet(int idx) { - if (idx < getFacetCount()) { - return facets.get(idx); - } - - return null; - } - - - public Facet getFacet(String name) { - for (Facet facet: facets) { - if (name.equals(facet.getName())) { - return facet; - } - } - - return null; - } - - - public List<Facet> getFacets() { - return facets; - } - - - public OutputTab createOutputTab(String t, Collection c, CollectionView p) { - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultRiver.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * The simpliest default implementation of a River that just stores a name. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultRiver implements River { - - /** The name of the river.*/ - protected String name; - - /** - * The default constructor that creates empty river objects. - */ - public DefaultRiver() { - } - - - /** - * This constructor should be used to create new rivers. - * - * @param name The name of the river. - */ - public DefaultRiver(String name) { - this.name = name; - } - - - /** - * Sets the name of the river. - * - * @param name The name of the river. - */ - public void setName(String name) { - this.name = name; - } - - - /** - * Returns the name of the river. - * - * @return the name of the river. - */ - public String getName() { - return name; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultRiverInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ - -public class DefaultRiverInfo implements RiverInfo { - - private String name; - private boolean kmup; - private Double start; - private Double end; - private String wstunit; - private Double minq; - private Double maxq; - private Long officialnumber; - - private List<GaugeInfo> gaugeinfo; - private List<MeasurementStation> mstations; - - public DefaultRiverInfo() { - } - - public DefaultRiverInfo( - String name, - boolean kmup, - Double start, - Double end, - String wstunit, - Double minq, - Double maxq, - Long official) - { - this.name = name; - this.kmup = kmup; - this.start = start; - this.end = end; - this.wstunit = wstunit; - this.minq = minq; - this.maxq = maxq; - this.officialnumber = official; - } - - public boolean isKmUp() { - return this.kmup; - } - - /** - * Start KM of the river - */ - public Double getKmStart() { - return this.start; - } - - /** - * End KM of the river - */ - public Double getKmEnd() { - return this.end; - } - - /** - * Returns the name of the river - */ - public String getName() { - return this.name; - } - - /** - * Returns the name of the WST unit - */ - public String getWstUnit() { - return this.wstunit; - } - - /** - * Return all gauge info of the river or null if they aren't available. - */ - public List<GaugeInfo> getGauges() { - return this.gaugeinfo; - } - - /** - * Returns the min q value of the river - */ - public Double getMinQ() { - return this.minq; - } - - /** - * Returns the max q value of the river - */ - public Double getMaxQ() { - return maxq; - } - - /** - * Returns the official number of the river - */ - public Long getOfficialNumber() { - return this.officialnumber; - } - - /** - * Returns the MeasurementStations on this river or null if they aren't - * available. - */ - @Override - public List<MeasurementStation> getMeasurementStations() { - return this.mstations; - } - - public void setGauges(List<GaugeInfo> gauges) { - this.gaugeinfo = gauges; - } - - public void setMeasurementStations(List<MeasurementStation> mstations) { - this.mstations = mstations; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultTheme.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -package de.intevation.flys.client.shared.model; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultTheme implements Theme { - - protected int position; - - protected int index; - - protected int active; - - protected int visible; - - protected String artifact; - - protected String facet; - - protected String description; - - /** CollectionItem associated with this facet/themes artifact. */ - protected CollectionItem collectionItem; - - - public DefaultTheme() { - } - - - public DefaultTheme( - int pos, - int index, - int active, - int visible, - String art, - String facet, - String description) - { - this.position = pos; - this.index = index; - this.active = active; - this.visible = visible; - this.artifact = art; - this.facet = facet; - this.description = description; - this.collectionItem = null; - } - - - public int getPosition() { - return position; - } - - - public void setPosition(int pos) { - this.position = pos; - } - - - public int getIndex() { - return index; - } - - - public int getActive() { - return active; - } - - - public void setActive(int active) { - this.active = active; - } - - - public String getArtifact() { - return artifact; - } - - - public String getFacet() { - return facet; - } - - - public String getDescription() { - return description; - } - - - public void setDescription(String description) { - this.description = description; - } - - - public int getVisible() { - return visible; - } - - - public void setVisible(int visible) { - this.visible = visible; - } - - - public boolean equals(Object o) { - if (!(o instanceof DefaultTheme)) { - return false; - } - - DefaultTheme other = (DefaultTheme) o; - - if (other.position != position) { - return false; - } - - if (!other.artifact.equals(artifact)) { - return false; - } - - if (other.active != active) { - return false; - } - - if (!other.facet.equals(facet)) { - return false; - } - - if (!other.description.equals(description)) { - return false; - } - - if (other.index != index) { - return false; - } - - if (other.visible != visible) { - return false; - } - - return true; - } - - /** Get the CollectionItem representing the facets artifact. */ - @Override - public CollectionItem getCollectionItem() { - return collectionItem; - } - - /** Set the CollectionItem representing the facets artifact. */ - @Override - public void setCollectionItem(CollectionItem ci) { - this.collectionItem = ci; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultUser.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2011 by Intevation GmbH - * - * This program is free software under the LGPL (>=v2.1) - * Read the file LGPL.txt coming with the software for details - * or visit http://www.gnu.org/licenses/ if it does not exist. - */ -package de.intevation.flys.client.shared.model; - - -/** - * Trivial implementation of a user. Useful to be subclassed. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DefaultUser -implements User -{ - /** The identifier of the user.*/ - protected String identifier; - - /** The name of the user.*/ - protected String name; - - - /** - * The default constructor. - */ - public DefaultUser() { - } - - - /** - * A constructor that creates a new user. - * - * @param identifier The uuid of the user. - * @param name The name of the user. - */ - public DefaultUser(String identifier, String name) { - this.identifier = identifier; - this.name = name; - } - - - /** - * Returns the identifier of this user. - * - * @return the identifier of this user. - */ - public String identifier() { - return identifier; - } - - - /** - * Returns the name of the user. - * - * @return the name of the user. - */ - public String getName() { - return name; - } - - - /** - * Set the identifier of the user. - * - * @param identifier The new identifier. - */ - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - - /** - * Set the name of the user. - * - * @param name The name for this user. - */ - public void setName(String name) { - this.name = name; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DischargeInfoObject.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface DischargeInfoObject extends Serializable { - - String getDescription(); - - Integer getStartYear(); - - Integer getEndYear(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DischargeInfoObjectImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class DischargeInfoObjectImpl implements DischargeInfoObject { - - protected String description; - - protected Integer startYear; - - protected Integer endYear; - - - public DischargeInfoObjectImpl() { - } - - - public DischargeInfoObjectImpl( - String description, - Integer startYear, - Integer endYear - ) { - this.description = description; - this.startYear = startYear; - this.endYear = endYear; - } - - public String getDescription() { - return description; - } - - - public Integer getStartYear() { - return startYear; - } - - - public Integer getEndYear() { - return endYear; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DistanceInfoObject.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface DistanceInfoObject extends Serializable { - - String getDescription(); - - Double getFrom(); - - Double getTo(); - - String getRiverside(); - - Double getBottom(); - - Double getTop(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DistanceInfoObjectImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DistanceInfoObjectImpl implements DistanceInfoObject { - - protected String description; - - protected Double from; - - protected Double to; - - protected String riverside; - - protected Double bottom; - - protected Double top; - - - public DistanceInfoObjectImpl() { - } - - - public DistanceInfoObjectImpl( - String description, - Double from, - Double to, - String riverside, - Double bottom, - Double top - ) { - this.description = description; - this.from = from; - this.to = to; - this.riverside = riverside; - this.bottom = bottom; - this.top = top; - } - - public String getDescription() { - return description; - } - - - public Double getFrom() { - return from; - } - - - public Double getTo() { - return to; - } - - - public String getRiverside() { - return riverside; - } - - public Double getBottom() { - return bottom; - } - - public Double getTop() { - return top; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DistanceInfoRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - - -/** - * The DistanceInfoRecord is a wrapper to put DistanceInfo objects into - * a ListGrid. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class DistanceInfoRecord extends ListGridRecord { - - /** The artifact collection. */ - protected DistanceInfoObject distanceInfo; - - - /** - * The default constructor. - * - * @param info The distance info object. - */ - public DistanceInfoRecord(DistanceInfoObject info) { - this.distanceInfo = info; - - setDescription(info.getDescription()); - setFrom(info.getFrom()); - if (info.getTo() != null) - setTo(info.getTo()); - else - setTo(info.getFrom()); - setRiverside(info.getRiverside()); - setBottom(info.getBottom()); - setTop(info.getTop()); - } - - - /** - * Sets the creation time. - * - * @param creationTime The creation time. - */ - public void setDescription(String description) { - setAttribute("description", description); - } - - - /** - * Returns the description. - * - * @return the description. - */ - public String getDescription() { - return getAttributeAsString("description"); - } - - - public void setFrom(double from) { - setAttribute("from", from); - } - - - public double getFrom() { - return getAttributeAsDouble("from"); - } - - public void setTo(double to) { - setAttribute("to", to); - } - - - public double getTo() { - return getAttributeAsDouble("to"); - } - - - public void setRiverside(String side) { - setAttribute("riverside", side); - } - - - public String getRiverside() { - return getAttributeAsString("riverside"); - } - - public void setBottom(Double bottom) { - setAttribute("bottom", bottom != null ? bottom.toString() : "-"); - } - - public String getBottom() { - return getAttributeAsString("bottom"); - } - - public void setTop(Double top) { - setAttribute("top", top != null ? top.toString() : "-"); - } - - public String getTop() { - return getAttributeAsString("top"); - } - - - public DistanceInfoObject getDistanceInfo() { - return distanceInfo; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class DoubleArrayData implements Data { - - public static final String TYPE = "doublearray"; - - - protected String label; - protected String description; - - protected double[] values; - - - public DoubleArrayData() { - } - - - public DoubleArrayData(String label, String description, double[] values) { - this.label = label; - this.description = description; - this.values = values; - } - - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel() { - return label; - } - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription() { - return description; - } - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType() { - return TYPE; - } - - - /** - * Returns a DataItem which value is a string that consists of the double - * values separated by a ';'. - * - * @return the DataItem. - */ - public DataItem[] getItems() { - if (values == null || values.length == 0) { - return new DataItem[0]; - } - - StringBuilder sb = new StringBuilder(); - boolean first = true; - - for (double value: values) { - if (first) { - sb.append(String.valueOf(value)); - } - else { - sb.append(";" + String.valueOf(value)); - } - } - - String value = sb.toString(); - DataItem item = new DefaultDataItem(value, value, value); - - return new DataItem[] { item }; - } - - - /** - * Returns the values as array. - * - * @return the values as array. - */ - public double[] getValues() { - return values; - } - - - /** - * @return always null. - */ - public DataItem getDefault() { - return null; - } - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = ""; - boolean first = true; - for (int i = 0; i < values.length; i++) { - if (!first) { - data += ";"; - } - data += String.valueOf(values[i]); - first = false; - } - return data; - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; - -import java.util.HashMap; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class DoubleProperty extends PropertySetting { - - /** - * Create a new DoubleProperty for settings. - */ - public DoubleProperty() { - this.attributes = new HashMap<String, String>(); - } - - - /** - * Create a new DoubleProperty. - * @param name The attribute name. - * @param value The current value. - */ - public DoubleProperty( - String name, - Double value) - { - this.name = name; - this.value = value.toString(); - this.attributes = new HashMap<String, String>(); - } - - @Override - public Double getValue() { - try { - Double value = Double.valueOf(this.value); - GWT.log("returning: " + value); - return value; - } - catch(NumberFormatException nfe) { - //Should never happen, if property is used correctly. - return null; - } - } - - - public void setValueFromUI(String value) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - double d; - try { - d = nf.parse(value); - GWT.log("setting " + value + " as " + d); - this.value = Double.toString(d); - } - catch(NumberFormatException nfe) {} - } - - public void setValue(Double value) { - this.value = value.toString(); - } - - - public String toUIString() { - double dv; - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - dv = Double.parseDouble(this.value); - } - catch (NumberFormatException nfe) { - return null; - } - return nf.format(dv); - } - - @Override - public Object clone() { - DoubleProperty clone = new DoubleProperty(this.getName(), - this.getValue()); - for(String s: this.getAttributeList()) { - clone.setAttribute(s, this.getAttribute(s)); - } - return clone; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleRangeData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -public class DoubleRangeData implements RangeData { - - public static final String TYPE = "doublerange"; - - - protected String label; - protected String description; - - protected double lower; - protected double upper; - - protected Double defLower; - protected Double defUpper; - - - public DoubleRangeData() { - } - - - public DoubleRangeData(String label, String desc, double lower, double upper) { - this(label, desc, lower, upper, null, null); - } - - - public DoubleRangeData( - String label, - String desc, - double lower, - double upper, - Double defLower, - Double defUpper - ) { - this.label = label; - this.description = desc; - this.lower = lower; - this.upper = upper; - this.defLower = defLower; - this.defUpper = defUpper; - } - - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel() { - return label; - } - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription() { - return description; - } - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType() { - return "doublerange"; - } - - - /** - * Returns a DataItem which value is a string that consists of the min and - * max value separated by a ';'. - * - * @return the DataItem. - */ - public DataItem[] getItems() { - String theMin = String.valueOf(lower); - String theMax = String.valueOf(upper); - - String label = theMin + " - " + theMax; - String value = theMin + ";" + theMax; - - DataItem item = new DefaultDataItem(label, label, value); - - return new DataItem[] { item }; - } - - - /** - * @return always null. - */ - public DataItem getDefault() { - return null; - } - - - public Object getLower() { - return lower; - } - - - public Object getUpper() { - return upper; - } - - - public Object getDefaultLower() { - return defLower; - } - - - public Object getDefaultUpper() { - return defUpper; - } - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = lower + ";" + upper; - return data; - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ExportMode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - - -/** - * An derived OutputMode that marks an OutputMode as an export. An export mode - * should at least support one (or more) facet which specify the type of export - * (e.g. CSV, WST). - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ExportMode extends DefaultOutputMode { - - public ExportMode() { - } - - - public ExportMode(String name, String desc, String mimeType) { - super(name, desc, mimeType); - } - - - public ExportMode( - String name, - String descrition, - String mimeType, - List<Facet> facets) - { - super(name, descrition, mimeType, facets); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Facet.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * The interface that provides methods to retrieve information about a Facet. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface Facet extends Serializable { - - /** - * Returns the name of a facet. - * - * @return the name of a facet. - */ - String getName(); - - /** - * Returns the index of this facet. - * - * @return the index. - */ - int getIndex(); - - /** - * Returns the description of this facet. - * - * @return the description. - */ - String getDescription(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -public class FacetFilter -implements Serializable -{ - protected String name; - protected String ids; - - public FacetFilter() { - } - - public FacetFilter(String name, String ids) { - this.name = name; - this.ids = ids; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getIds() { - return ids; - } - - public void setIds(String ids) { - this.ids = ids; - } - - protected static boolean equals(String a, String b) { - if (a == null && b == null) return true; - if (a == null && b != null) return false; - if (a != null && b == null) return false; - return a.equals(b); - } - - public boolean equals(Object other) { - if (!(other instanceof FacetFilter)) { - return false; - } - FacetFilter o = (FacetFilter)other; - return equals(o.name, name) && equals(o.ids, ids); - } - - public void collectIds(StringBuilder sb) { - if (ids != null) { - if (sb.length() > 0) { - sb.append(' '); - } - sb.append(ids); - } - } - - public Recommendation.Facet toFacet() { - return new Recommendation.Facet(name, ids); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - -/** - * ListGridRecord for Facets. - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class FacetRecord extends ListGridRecord { - - /** Underlying theme. */ - protected Theme theme; - - - public FacetRecord(Theme theme) { - this.theme = theme; - - setActive(theme.getActive() == 1); - setName(theme.getDescription()); - } - - - public Theme getTheme() { - return theme; - } - - - public void setName(String description) { - // TODO Add a setter method setName() to Facet - // facet.setName(name); - setAttribute("name", description); - } - - - public String getName() { - return getAttribute("name"); - } - - - public boolean getActive() { - return getAttributeAsBoolean("active"); - } - - - public void setActive(boolean active) { - setAttribute("active", active); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FeatureInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import java.util.HashMap; -import java.util.Map; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class FeatureInfo implements Serializable { - - protected String layername; - - protected Map<String, String> attrs; - - - public FeatureInfo() { - } - - - public FeatureInfo(String layername) { - this.layername = layername; - this.attrs = new HashMap<String, String>(); - } - - - public void setLayername(String layername) { - this.layername = layername; - } - - - public String getLayername() { - return layername; - } - - - public void addAttr(String key, String value) { - if (key != null && key.length() > 0) { - attrs.put(key, value); - } - } - - - public Map<String, String> getAttrs() { - return attrs; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FeatureInfoResponse.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a> - */ -public class FeatureInfoResponse implements Serializable { - - // Wrapper class to transport the response of a feature info call - - protected String featureInfoHTML; - - protected List<FeatureInfo> features; - - public FeatureInfoResponse() { - } - - public FeatureInfoResponse(List<FeatureInfo> features, String featureInfoHTML) { - this.featureInfoHTML = featureInfoHTML; - this.features = features; - } - - public List<FeatureInfo> getFeatures() { - return features; - } - - public String getFeatureInfoHTML() { - return featureInfoHTML; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -import com.google.gwt.core.client.GWT; - - -/** - * The Fixanalysis implementation of an Artifact (client side). - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class FixAnalysisArtifact extends DefaultArtifact { - - /** The name of this artifact: 'fixanalysis'.*/ - public static final String NAME = "fixanalysis"; - - protected FixFilter filter; - - - public FixAnalysisArtifact() { - this.filter = null; - } - - - public FixAnalysisArtifact(String uuid, String hash) { - super(uuid, hash); - this.filter = null; - } - - - public FixAnalysisArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - super(uuid, hash, inBackground, messages); - } - - - public String getName() { - return NAME; - } - - - public FixFilter getFilter () { - return createFilter(); - } - - - protected FixFilter createFilter() { - if (this.filter == null) { - this.filter = new FixFilter(); - } - DataList[] old = artifactDescription.getOldData(); - - String river = artifactDescription.getDataValueAsString("river"); - if (river != null) { - this.filter.setRiver(river); - } - - String from = artifactDescription.getDataValueAsString("ld_from"); - if (from != null) { - try { - double fkm = Double.parseDouble(from); - this.filter.setFromKm(fkm); - } - catch(NumberFormatException nfe) { - GWT.log("Could not parse from km."); - } - } - - String to = artifactDescription.getDataValueAsString("ld_to"); - if (to != null) { - try { - double tkm = Double.parseDouble(to); - this.filter.setToKm(tkm); - } - catch(NumberFormatException nfe) { - GWT.log("Could not parse to km"); - } - } - - String start = artifactDescription.getDataValueAsString("start"); - if (start != null) { - try { - long s = Long.parseLong(start); - this.filter.setFromDate(s); - } - catch(NumberFormatException nfe) { - GWT.log("Could not parse start date"); - } - } - - String end = artifactDescription.getDataValueAsString("end"); - if (end != null) { - try { - long e = Long.parseLong(end); - this.filter.setToDate(e); - } - catch(NumberFormatException nfe) { - GWT.log("Could not parse end date"); - } - } - - String q1 = artifactDescription.getDataValueAsString("q1"); - if (q1 != null) { - try { - int q1i = Integer.parseInt(q1); - this.filter.setFromClass(q1i); - } - catch(NumberFormatException nfe) { - GWT.log("Could not parse start class"); - } - } - - String q2 = artifactDescription.getDataValueAsString("q2"); - if (q2 != null) { - try { - int q2i = Integer.parseInt(q2); - this.filter.setToClass(q2i); - } - catch(NumberFormatException nfe) { - GWT.log("could not parse end class"); - } - } - - for (DataList list: old) { - List<Data> items = list.getAll(); - String state = list.getState(); - if(state.equals("state.fix.eventselect")) { - Data de = getData(items, "events"); - IntegerArrayData iad = (IntegerArrayData) de; - this.filter.setEvents(iad.getValues()); - } - } - - return this.filter; - } - - protected Data getData(List<Data> data, String name) { - for (Data d: data) { - if (name.equals(d.getLabel())) { - return d; - } - } - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -/** Probably something like *Access, but from client side. */ -public class FixFilter implements Serializable{ - - protected String river; - protected double fromKm; - protected double toKm; - protected double currentKm; - protected int fromClass; - protected int toClass; - protected long fromDate; - protected long toDate; - protected boolean hasDate; - protected int[] events; - - public FixFilter() { - this.river = ""; - this.fromKm = -Double.MAX_VALUE; - this.toKm = -1; - this.currentKm = -1; - this.fromClass = -1; - this.toClass = -1; - this.fromDate = -1; - this.toDate = -1; - this.hasDate = false; - this.events = new int[0]; - } - - public void setRiver(String river) { - this.river = river; - } - - public void setFromKm(double from) { - this.fromKm = from; - } - - public void setToKm(double to) { - this.toKm = to; - } - - public void setCurrentKm(double km) { - this.currentKm = km; - } - - public void setFromClass(int from) { - this.fromClass = from; - } - - public void setToClass(int to) { - this.toClass = to; - } - - public void setFromDate(long from) { - this.hasDate = true; - this.fromDate = from; - } - - public void setToDate(long to) { - this.hasDate = true; - this.toDate = to; - } - - public void setEvents(int[] ev) { - this.events = ev; - } - - public String getRiver() { - return this.river; - } - - public double getFromKm() { - return this.fromKm; - } - - public double getToKm() { - return this.toKm; - } - - public double getCurrentKm() { - return this.currentKm; - } - - public int getFromClass() { - return this.fromClass; - } - - public int getToClass() { - return this.toClass; - } - - public long getFromDate() { - return this.fromDate; - } - - public long getToDate() { - return this.toDate; - } - - public int[] getEvents() { - return this.events; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixingsOverviewInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import java.util.List; -import java.util.ArrayList; - -public class FixingsOverviewInfo implements Serializable { - - protected List<FixEvent> events; - protected String river; - protected double from; - protected double to; - protected int rid; - protected String html; - - protected FixingsOverviewInfo() {} - - public FixingsOverviewInfo( - int rid, - String river, - double from, - double to, - List<FixEvent> events, - String html - ) { - this.rid = rid; - this.river = river; - this.from = from; - this.to = to; - this.events = new ArrayList<FixEvent>(events); - this.html = html; - } - - public int getRId() { - return this.rid; - } - - public String getRiver() { - return this.river; - } - - public double getFrom() { - return this.from; - } - - public double getTo() { - return this.to; - } - - public List<FixEvent> getEvents() { - return this.events; - } - - public FixEvent getEventByCId(String cid) { - for (int i = 0; i < events.size(); i++) { - if (events.get(i).getCId().equals(cid)) { - return events.get(i); - } - } - return null; - } - - public String getHTML() { - return this.html; - } - - - public static class FixEvent implements Serializable { - protected String cid; - protected String date; - protected String description; - protected List<Sector> sectors; - - protected FixEvent () {} - - public FixEvent( - String cid, - String date, - String description, - List<Sector> sectors - ) { - this.cid = cid; - this.date = date; - this.description = description; - this.sectors = new ArrayList<Sector>(sectors); - } - - public String getCId() { - return this.cid; - } - - public String getDate() { - return this.date; - } - - public String getDescription() { - return this.description; - } - - public List<Sector> getSectors() { - return this.sectors; - } - } - - public static class Sector implements Serializable { - protected int cls; - protected double from; - protected double to; - - protected Sector () {} - - public Sector( - int cls, - double from, - double to - ) { - this.cls = cls; - this.from = from; - this.to = to; - } - - public int getCls() { - return this.cls; - } - - public double getFrom() { - return this.from; - } - - public double getTo() { - return this.to; - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Gauge.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -public interface Gauge extends Serializable { - - String getName(); - - double getLower(); - - double getUpper(); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/GaugeDischargeCurveArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -/** - * The GaugeDischargeCurveArtifact implementation of an Artifact. - * - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public class GaugeDischargeCurveArtifact extends DefaultArtifact { - - /** The name of this artifact */ - public static final String NAME = "gauge_discharge_curve"; - - - public GaugeDischargeCurveArtifact() { - } - - - public GaugeDischargeCurveArtifact(String uuid, String hash) { - super(uuid, hash); - } - - - public GaugeDischargeCurveArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - super(uuid, hash, inBackground, messages); - } - - - public String getName() { - return NAME; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/GaugeImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -public class GaugeImpl implements Gauge { - - private String name; - - private double lower; - private double upper; - - - public GaugeImpl() { - } - - - public GaugeImpl(String name, double lower, double upper) { - this.name = name; - this.lower = lower; - this.upper = upper; - } - - - public void setName(String name) { - this.name = name; - } - - - public String getName() { - return name; - } - - - public void setLower(double lower) { - this.lower = lower; - } - - - public double getLower() { - return lower; - } - - - public void setUpper(double upper) { - this.upper = upper; - } - - - public double getUpper() { - return upper; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/GaugeInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public interface GaugeInfo extends Serializable { - - /** - * Returns the name of the gauge. - */ - String getName(); - - /** - * Returns the start KM of the gauge or null if not available. - */ - Double getKmStart(); - - /** - * Returns the end KM of the gauge or null if not available. - */ - Double getKmEnd(); - - /** - * Returns the mimimum Q value at this gauge or null if not available. - */ - Double getMinQ(); - - /** - * Returns the maximum Q value at this gauge or null if not available. - */ - Double getMaxQ(); - - /** - * Returns the mimimum W value at this gauge or null if not available. - */ - Double getMinW(); - - /** - * Returns the maximim W value at this gauge or null if not available. - */ - Double getMaxW(); - - /** - * Returns the datum value or null if not available. - */ - Double getDatum(); - - /** - * Returns the aeo value or null if not available. - */ - Double getAeo(); - - boolean isKmUp(); - - /** - * Returns the station km of the gauge or null if not available. - */ - Double getStation(); - - /** - * Returns the wst unit as a String. - */ - String getWstUnit(); - - /** - * Returns the official number of this gauge. - */ - Long getOfficialNumber(); - - /** - * Returns the river to which this gauge belongs. - */ - String getRiverName(); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntDataItem.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * The integer implementation of a {@link DataItem}. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class IntDataItem implements DataItem { - - /** The label. */ - protected String label; - - /** The description. */ - protected String description; - - /** The value. */ - protected int value; - - - public IntDataItem() { - } - - - /** - * The default constructor to create new instances. - * - * @param label The label. - * @param description The description. - * @param value The value. - */ - public IntDataItem(String label, String description, int value) { - this.label = label; - this.description = description; - this.value = value; - } - - - public String getLabel() { - return label; - } - - - public String getDescription() { - return description; - } - - - public String getStringValue() { - return String.valueOf(value); - } - - public int getValue() { - return value; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -public class IntegerArrayData implements Data { - - public static final String TYPE = "intarray"; - - - protected String label; - protected String description; - - protected IntDataItem[] values; - - - public IntegerArrayData() { - } - - - public IntegerArrayData( - String label, - String description, - IntDataItem[] values - ) { - this.label = label; - this.description = description; - this.values = values; - } - - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel() { - return label; - } - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription() { - return description; - } - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType() { - return "intarray"; - } - - - /** - * Returns a DataItem which value is a string that consists of the integer - * values separated by a ';'. - * - * @return the DataItem. - */ - public DataItem[] getItems() { - return values; - } - - - /** - * Returns the values as array. - * - * @return the values as array. - */ - public int[] getValues() { - int[] data = new int[values.length]; - for (int i = 0; i < values.length; i++) { - data[i] = values[i].getValue(); - } - return data; - } - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = ""; - boolean first = true; - for (int i = 0; i < values.length; i++) { - if (!first) { - data += ";"; - } - data += values[i].getStringValue(); - first = false; - } - return data; - } - - /** - * @return always null. - */ - public DataItem getDefault() { - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class IntegerData extends DefaultData { - - public static final String TYPE = "integer"; - - - public IntegerData() { - super(); - } - - - public IntegerData(String name, String description, DataItem[] items) { - super(name, description, TYPE, items); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerOptionsData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** Data matching to labelled integer(s). */ -public class IntegerOptionsData implements Data { - - public static final String TYPE = "intoptions"; - - protected String label; - protected String description; - - public DataItem[] opts; - - - public IntegerOptionsData() { - } - - - public IntegerOptionsData(String label, String desc, DataItem[] opts) { - this.label = label; - this.description = desc; - this.opts = opts; - } - - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel() { - return label; - } - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription() { - return description; - } - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType() { - return TYPE; - } - - - /** - * Returns the data items which represent the allowed options for this Data. - * - * @return the allowed options as DataItem array. - */ - public DataItem[] getItems() { - return opts; - } - - - /** - * @return always null. - */ - public DataItem getDefault() { - return null; - } - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = ""; - boolean first = true; - for (int i = 0; i < opts.length; i++) { - if (!first) { - data += ";"; - } - data += opts[i].getStringValue(); - first = false; - } - return data; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerProperty.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.HashMap; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class IntegerProperty extends PropertySetting { - - /** - * Create a new IntegerProperty for settings. - */ - public IntegerProperty() { - this.attributes = new HashMap<String, String>(); - } - - - /** - * Create a new IntegerProperty. - * @param name The attribute name. - * @param value The current value. - */ - public IntegerProperty( - String name, - Integer value) - { - this.name = name; - this.value = value.toString(); - this.attributes = new HashMap<String, String>(); - } - - - @Override - public Integer getValue() { - try { - return Integer.valueOf(this.value); - } - catch(NumberFormatException nfe) { - return null; - } - } - - - public void setValue(Integer value) { - this.value = value.toString(); - } - - public Object clone() { - IntegerProperty clone = new IntegerProperty(this.getName(), - this.getValue()); - for(String s: this.getAttributeList()) { - clone.setAttribute(s, this.getAttribute(s)); - } - return clone; - } - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class IntegerRangeData implements RangeData { - - public static final String TYPE = "intrange"; - - - protected String label; - protected String description; - - protected int lower; - protected int upper; - - protected Integer defLower; - protected Integer defUpper; - - - public IntegerRangeData() { - } - - - public IntegerRangeData(String label, String desc, int lower, int upper) { - this(label, desc, lower, upper, null, null); - } - - - /** - * @param label - * @param desc - * @param lower - * @param upper - * @param defLower - * @param defUpper - */ - public IntegerRangeData( - String label, - String desc, - int lower, - int upper, - Integer defLower, - Integer defUpper - ) { - this.label = label; - this.description = desc; - this.lower = lower; - this.upper = upper; - this.defLower = defLower; - this.defUpper = defUpper; - } - - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel() { - return label; - } - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription() { - return description; - } - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType() { - return "intrange"; - } - - - /** - * Returns a DataItem which value is a string that consists of the min and - * max value separated by a ';'. - * - * @return the DataItem. - */ - public DataItem[] getItems() { - String theMin = String.valueOf(lower); - String theMax = String.valueOf(upper); - - String label = theMin + " - " + theMax; - String value = theMin + ";" + theMax; - - DataItem item = new DefaultDataItem(label, label, value); - - return new DataItem[] { item }; - } - - - /** - * @return always null. - */ - public DataItem getDefault() { - return null; - } - - - public Object getLower() { - return lower; - } - - - public Object getUpper() { - return upper; - } - - - public Object getDefaultLower() { - return defLower; - } - - - public Object getDefaultUpper() { - return defUpper; - } - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = lower + ";" + upper; - return data; - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/LongRangeData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * Long Range (e.g. storing dates). - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class LongRangeData implements RangeData { - - public static final String TYPE = "longrange"; - - protected String label; - protected String description; - - protected long lower; - protected long upper; - - protected Long defLower; - protected Long defUpper; - - - public LongRangeData() { - } - - - public LongRangeData(String label, String desc, long lower, long upper) { - this(label, desc, lower, upper, null, null); - } - - - /** - * @param label - * @param desc - * @param lower - * @param upper - * @param defLower - * @param defUpper - */ - public LongRangeData( - String label, - String desc, - long lower, - long upper, - Long defLower, - Long defUpper - ) { - this.label = label; - this.description = desc; - this.lower = lower; - this.upper = upper; - this.defLower = defLower; - this.defUpper = defUpper; - } - - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel() { - return label; - } - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription() { - return description; - } - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType() { - return "longrange"; - } - - - /** - * Returns a DataItem which value is a string that consists of the min and - * max value separated by a ';'. - * - * @return the DataItem. - */ - public DataItem[] getItems() { - String theMin = String.valueOf(lower); - String theMax = String.valueOf(upper); - - String label = theMin + " - " + theMax; - String value = theMin + ";" + theMax; - - DataItem item = new DefaultDataItem(label, label, value); - - return new DataItem[] { item }; - } - - - /** - * @return always null. - */ - public DataItem getDefault() { - return null; - } - - - public Object getLower() { - return lower; - } - - - public Object getUpper() { - return upper; - } - - - public Object getDefaultLower() { - return defLower; - } - - - public Object getDefaultUpper() { - return defUpper; - } - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = lower + ";" + upper; - return data; - } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/MINFOArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - - -/** - * The WINFO implementation of an Artifact. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MINFOArtifact extends DefaultArtifact { - - /** The name of this artifact: 'minfo'.*/ - public static final String NAME = "minfo"; - - - public MINFOArtifact() { - } - - - public MINFOArtifact(String uuid, String hash) { - super(uuid, hash); - } - - - public MINFOArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - super(uuid, hash, inBackground, messages); - } - - - public String getName() { - return NAME; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - - -/** - * The MAP implementation of an Artifact. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class MapArtifact extends DefaultArtifact { - - /** The name of this artifact: 'map'.*/ - public static final String NAME = "new_map"; - - - public MapArtifact() { - } - - - public MapArtifact(String uuid, String hash) { - super(uuid, hash); - } - - - public MapArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - super(uuid, hash, inBackground, messages); - } - - - public String getName() { - return NAME; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapConfig.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - - -public class MapConfig implements Serializable { - - public static final String ATTR_SRID = "srid"; - public static final String ATTR_MAX_EXTENT = "max_extent"; - public static final String ATTR_INITIAL_EXTENT = "initial_extent"; - - - protected Map<String, String> attributes; - - - public MapConfig() { - attributes = new HashMap<String, String>(); - } - - - public void setAttribute(String key, String value) { - attributes.put(key, value); - } - - - public String getAttribute(String key) { - return attributes.get(key); - } - - - public void setSrid(String srid) { - setAttribute(ATTR_SRID, srid); - } - - - public String getSrid() { - return getAttribute(ATTR_SRID); - } - - - public void setMaxExtent(String maxExtent) { - setAttribute(ATTR_MAX_EXTENT, maxExtent); - } - - - public String getMaxExtent() { - return getAttribute(ATTR_MAX_EXTENT); - } - - - public void setInitialExtent(String initialExtent) { - setAttribute(ATTR_INITIAL_EXTENT, initialExtent); - } - - - public String getInitialExtent() { - return getAttribute(ATTR_INITIAL_EXTENT); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -public class MapInfo implements Serializable { - - private static final long serialVersionUID = 6691651180549280493L; - - protected String river; - protected int srid; - protected BBox bbox; - protected String wmsUrl; - protected String wmsLayers; - protected String backgroundWmsUrl; - protected String backgroundWmsLayers; - - - public MapInfo() { - } - - - public MapInfo( - String river, - int srid, - BBox bbox, - String wmsUrl, - String wmsLayers, - String backgroundWmsUrl, - String backgroundWmsLayers) - { - this.river = river; - this.srid = srid; - this.bbox = bbox; - this.wmsUrl = wmsUrl; - this.wmsLayers = wmsLayers; - this.backgroundWmsUrl = backgroundWmsUrl; - this.backgroundWmsLayers = backgroundWmsLayers; - } - - - public String getRiver() { - return river; - } - - - public int getSrid() { - return srid; - } - - - public String getProjection() { - return "EPSG:" + srid; - } - - - public BBox getBBox() { - return bbox; - } - - - public String getWmsUrl() { - return wmsUrl; - } - - - public String getWmsLayers() { - return this.wmsLayers; - } - - - public String getBackgroundWmsUrl() { - return backgroundWmsUrl; - } - - - public String getBackgroundWmsLayers() { - return backgroundWmsLayers; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapMode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.OutputTab; -import de.intevation.flys.client.client.ui.map.MapOutputTab; - -import java.util.List; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class MapMode extends DefaultOutputMode { - - /** - * Default constructor required for serialization. - */ - public MapMode() { - } - - public MapMode(String name, String desc, String mimeType) { - super(name, desc, mimeType); - } - - - public MapMode( - String name, - String descrition, - String mimeType, - List<Facet> facets) - { - super(name, descrition, mimeType, facets); - } - - - @Override - public OutputTab createOutputTab(String t, Collection c, CollectionView p) { - return new MapOutputTab(t, c, this, p); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/MeasurementStation.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.Date; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ -public interface MeasurementStation extends Serializable { - - /** - * Returns the name of the measurement station - */ - String getName(); - - /** - * Returns the start KM of the measurement station or null if not available - */ - Double getKmStart(); - - /** - * Returns the end KM of the measurement station or null if not available - */ - Double getKmEnd(); - - boolean isKmUp(); - - /** - * Returns the station km of the measurement station or null if not - * available - */ - Double getStation(); - - /** - * Returns the river to which this measurement station belongs - */ - String getRiverName(); - - /** - * Returns the side of the river which this measurement station belongs - */ - String getRiverSide(); - - /** - * Returns the type of the measurement station - */ - String getMeasurementType(); - - /** - * Returns the ID of the measurement station - */ - Integer getID(); - - /** - * Returns the operator of the measurement station - */ - String getOperator(); - - /** - * Returns the start time of the observation at this measurement station - */ - Date getStartTime(); - - /** - * Returns the end time of the observation at this measurement station - */ - Date getStopTime(); - - /** - * Returns the name of the gauge in reference to this measurement station - */ - String getGaugeName(); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Module.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -public interface Module extends Serializable { - - String getName(); - - String getLocalizedName(); - - boolean isSelected(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/NumberAxis.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class NumberAxis implements Axis { - - protected int pos; - - protected double from; - protected double to; - - protected double min; - protected double max; - - - public NumberAxis() { - } - - - public NumberAxis(int pos, double from, double to, double min, double max) { - this.pos = pos; - this.from = from; - this.to = to; - this.min = min; - this.max = max; - } - - - @Override - public int getPos() { - return pos; - } - - - @Override - public Number getFrom() { - return from; - } - - - @Override - public Number getTo() { - return to; - } - - - @Override - public Number getMin() { - return min; - } - - - @Override - public Number getMax() { - return max; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutFilter.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import java.util.ArrayList; -import java.util.List; - -public class OutFilter -implements Serializable -{ - protected String out; - - protected List<FacetFilter> facetFilters; - - public OutFilter() { - facetFilters = new ArrayList<FacetFilter>(); - } - - public OutFilter(String out) { - this(); - this.out = out; - } - - public String getOut() { - return out; - } - - public void setOut(String out) { - this.out = out; - } - - public void add(String name, String num) { - FacetFilter facetFilter = new FacetFilter(name, num); - if (!facetFilters.contains(facetFilter)) { - facetFilters.add(facetFilter); - } - } - - public List<FacetFilter> getFacetFilters() { - return facetFilters; - } - - public void setFacetFilters(List<FacetFilter> facetFilters) { - this.facetFilters = facetFilters; - } - - public void collectIds(StringBuilder sb) { - for (FacetFilter facetFilter: facetFilters) { - facetFilter.collectIds(sb); - } - } - - public List<Recommendation.Facet> toFacets() { - List<Recommendation.Facet> facets = - new ArrayList<Recommendation.Facet>(facetFilters.size()); - for (FacetFilter facetFilter: facetFilters) { - facets.add(facetFilter.toFacet()); - } - return facets; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputMode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.List; - -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.OutputTab; - - -/** - * This interface describes an output mode of an artifact. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface OutputMode extends Serializable { - - /** - * Retrieves the name of this mode. - * - * @return the name of this mode. - */ - String getName(); - - - /** - * Retrieves the description of this mode. - * - * @return the description of this mode. - */ - String getDescription(); - - - /** - * Retrieves the mime-type of this mode. - * - * - * @return the mime-type of this mode. - */ - String getMimeType(); - - - /** - * Returns the type of this mode. - * - * @return the type of this mode. - */ - String getType(); - - - /** - * Adds a new facet to this mode. - * - * @param facet The new facet. - */ - void addFacet(Facet facet); - - - /** - * Returns the number of facets supported by this mode. - * - * @return the number of facets. - */ - int getFacetCount(); - - - /** - * Returns the facet at a given position. - * - * @param idx The position of a facet. - * - * @return a facet. - */ - Facet getFacet(int idx); - - - /** - * Returns a facet based on its name. - * - * @param name The name of the facet. - * - * @return a facet or null if no such facet is available. - */ - Facet getFacet(String name); - - - /** - * Returns all facets of this mode. - * - * @return all facets. - */ - List<Facet> getFacets(); - - - /** - * Returns an OutputTab that is used to render the output mode. - * - * @param t The title. - * @param c The Collection. - * @param p The parent CollectionView. - * - * @return an OutputTab. - */ - OutputTab createOutputTab(String t, Collection c, CollectionView p); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.HashMap; -import java.util.List; -import java.util.ArrayList; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class OutputSettings implements Settings, Cloneable { - - /** The output name. */ - protected String name; - - /** The categories and settings container. */ - protected HashMap<String, List<Property> > categories; - - - public OutputSettings() { - this.categories = new HashMap<String, List<Property> >(); - } - - - public OutputSettings(String name) { - this.name = name; - this.categories = new HashMap<String, List<Property> >(); - } - - - /** Set output name. */ - public void setName(String name) { - this.name = name; - } - - - /** Get output name. */ - public String getName() { - return this.name; - } - - - public void setSettings(String category, List<Property> settings) { - if (this.categories == null) { - this.categories = new HashMap<String, List<Property> >(); - } - this.categories.put(category, settings); - } - - - public List<Property> getSettings(String category) { - return categories.get(category); - } - - - public List<String> getCategories() { - ArrayList<String> list = new ArrayList<String>(categories.keySet()); - return list; - } - - - public Object clone() { - OutputSettings clone = new OutputSettings(this.getName()); - for (String s: this.getCategories()) { - ArrayList cloneList = new ArrayList<Property>(); - for(Property p: this.getSettings(s)) { - cloneList.add((Property)p.clone()); - } - clone.setSettings(s, cloneList); - } - return clone; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OverviewMode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -import de.intevation.flys.client.client.ui.CollectionView; -import de.intevation.flys.client.client.ui.OutputTab; -import de.intevation.flys.client.client.ui.chart.OverviewOutputTab; - - -/** - * Output mode for chart overviews. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class OverviewMode -extends -DefaultOutputMode { - - public OverviewMode() { - } - - - public OverviewMode(String name, String desc, String mimeType) { - super(name, desc, mimeType); - } - - - public OverviewMode( - String name, - String descrition, - String mimeType, - List<Facet> facets, - String type) - { - super(name, descrition, mimeType, facets); - this.type = type; - } - - - @Override - public OutputTab createOutputTab(String t, Collection c, CollectionView p) { - return new OverviewOutputTab(t, c, this, p); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Property.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -/** - * This interface describes a Property of an output mode. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface Property extends Serializable { - - String getName(); - - void setName(String name); - - Object clone(); -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.ArrayList; -import java.util.List; - -/** - * A group of properties. - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class PropertyGroup implements Property, Cloneable { - - /** The group name */ - protected String name; - - protected List<Property> properties; - - public PropertyGroup() { - } - - public PropertyGroup(String name) { - this.name = name; - } - - public PropertyGroup(String name, List<Property> properties) { - this.name = name; - this.properties = properties; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public List<Property> getProperties() { - return this.properties; - } - - public void setProperties(List<Property> properties) { - this.properties = properties; - } - - public Property getPropertyByName(String name) { - for (int i = 0; i < properties.size(); i++) { - if (properties.get(i).getName().equals(name)) { - return properties.get(i); - } - } - return null; - } - - @Override - public Object clone() { - PropertyGroup clone = new PropertyGroup(this.getName()); - List<Property> cloneList = new ArrayList<Property>(); - for(Property p: properties) { - cloneList.add((Property)p.clone()); - } - clone.setProperties(cloneList); - return clone; - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder(); - - for(Property p : properties) { - buf.append(p.getName()); - buf.append("="); - if(p instanceof PropertySetting) { - buf.append(((PropertySetting)p).getValue().toString()); - } - buf.append(" "); - } - - return buf.toString(); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class PropertySetting implements Property, Cloneable { - - /**The settings name.*/ - protected String name; - - /** The default value.*/ - protected String value; - - /** Additional attributes.*/ - protected HashMap<String, String> attributes; - - /** - * Create a new StyleSetting for theme attribution. - */ - public PropertySetting() { - this.attributes = new HashMap<String, String>(); - } - - - /** - * Create a new PropertySet. - * @param name The attribute name. - * @param value The current value. - */ - public PropertySetting( - String name, - String value) - { - this.name = name; - this.value = value; - this.attributes = new HashMap<String, String>(); - } - - public void setName(String name) { - this.name = name; - } - - public void setValue(String value) { - this.value = value; - } - - public void setAttribute(String k, String v) { - attributes.put(k, v); - } - - public String getName() { - return this.name; - } - - public Object getValue() { - return this.value; - } - - public String getAttribute(String key) { - return attributes.get(key); - } - - public List<String> getAttributeList() { - return new ArrayList<String>(attributes.keySet()); - } - - @Override - public Object clone() { - PropertySetting clone = new PropertySetting(this.getName(), - this.getValue().toString()); - for(String s: this.getAttributeList()) { - clone.setAttribute(s, this.getAttribute(s)); - } - return clone; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/RangeData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface RangeData extends Data { - - Object getLower(); - - Object getUpper(); - - Object getDefaultLower(); - - Object getDefaultUpper(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Recommendation.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,219 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -import java.io.Serializable; - -/** - * Information bundle to let client create/clone an artifact with facets. - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class Recommendation implements Serializable { - - /** Index and name of a facet. */ - public static class Facet implements Serializable { - - /** Facet name. */ - protected String name; - - /** Facet index. */ - protected String index; - - public Facet() { - } - - public Facet(String name, String index) { - this.name = name; - this.index = index; - } - - public String getName() { - return name; - } - - public String getIndex() { - return index; - } - - - @Override - public int hashCode() { - int hash = 0; - if (getName() != null) { - hash += getName().hashCode(); - } - if (getIndex() != null) { - hash += getIndex().hashCode(); - } - return hash; - } - - - @Override - public boolean equals(Object other) { - if (!(other instanceof Facet) || other == null) { - return false; - } - Facet facet = (Facet) other; - return (same(facet.getIndex(), this.getIndex())) - && (same(facet.getName(), this.getName())); - } - } // class Facet - - - /** Mapping of outnames to Facet-Lists. */ - public static class Filter implements Serializable { - - protected Map<String, List<Facet>> outs; - - public Filter() { - outs = new HashMap<String, List<Facet>>(); - } - - public void add(String out, List<Facet> facets) { - outs.put(out, facets); - } - - public Map<String, List<Facet>> getOuts() { - return outs; - } - - - @Override - public int hashCode() { - if (getOuts() != null) { - return getOuts().hashCode(); - } - return 0; - } - - - @Override - public boolean equals(Object other) { - if (!(other instanceof Filter) || other == null) { - return false; - } - Filter filter = (Filter) other; - return Recommendation.same(filter.getOuts(), this.getOuts()); - } - } // class Filter - - /** Factory to speak to when creating/cloning. */ - protected String factory; - /** Sometimes database ids, sometimes other freeform text. */ - protected String ids; - /** Artifacts uuid that should serve as master artifact. */ - protected String masterArtifact; - /** Optional facet filter. */ - protected Filter filter; - protected String displayName = null; - - public Recommendation() { - } - - public Recommendation(String factory, String ids) { - this(factory, ids, null, null); - } - - public Recommendation( - String factory, - String ids, - String masterArtifact, - Filter filter - ) { - this.factory = factory; - this.ids = ids; - this.masterArtifact = masterArtifact; - this.filter = filter; - } - - public String getFactory() { - return factory; - } - - public void setFactory(String factory) { - this.factory = factory; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public String getDisplayName() { - return this.displayName; - } - - public String getIDs() { - return ids; - } - - public String getMasterArtifact() { - return masterArtifact; - } - - public void setMasterArtifact(String masterArtifact) { - this.masterArtifact = masterArtifact; - } - - public Filter getFilter() { - return filter; - } - - public void setFilter(Filter filter) { - this.filter = filter; - } - - - @Override - public int hashCode() { - int hash = 0; - hash += (getFactory() != null) - ? getFactory().hashCode() - : 0; - hash += (getIDs() != null) - ? getIDs().hashCode() - : 0; - hash += (getFilter() != null) - ? getFilter().hashCode() - : 0; - hash += (getMasterArtifact() != null) - ? getMasterArtifact().hashCode() - : 0; - return hash; - } - - - /** - * Null-pointer guarded equals. - * Two null's are assumed equal (returns true); - * @param a Object to compare against parameter b. - * @param b Object to compare against parameter a. - * @return true if either a and b are null or a.equals(b) returns true. - */ - protected static boolean same(Object a, Object b) { - // Do null-check. - if (a == null) { - return b == null; - } else if (b == null) { - return false; - } - return a.equals(b); - } - - - @Override - public boolean equals(Object other) { - if (!(other instanceof Recommendation) || other == null) { - return false; - } - Recommendation rec = (Recommendation) other; - return (same(this.getFactory(), rec.getFactory())) - && (same(this.getIDs(), rec.getIDs())) - && (same(this.getFilter(), rec.getFilter())) - && (same(this.getMasterArtifact(), rec.getMasterArtifact())); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ReportMode.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - -public class ReportMode -extends DefaultOutputMode -{ - public ReportMode() { - } - - - public ReportMode(String name, String desc, String mimeType) { - super(name, desc, mimeType); - } - - - public ReportMode( - String name, - String description, - String mimeType, - List<Facet> facets - ) { - super(name, description, mimeType, facets); - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Facet f: facets) { - if (first) first = false; - else sb.append(", "); - sb.append("(name = '").append(f.getName()) - .append("', index = ").append(f.getIndex()) - .append(", desc = '").append(f.getDescription()).append("')"); - } - return sb.toString(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/River.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface River extends Serializable { - - String getName(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/RiverInfo.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.List; - -/** - * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> - */ - -public interface RiverInfo extends Serializable { - - boolean isKmUp(); - - /** - * Start KM of the river - */ - Double getKmStart(); - - /** - * End KM of the river - */ - Double getKmEnd(); - - /** - * Returns the name of the river - */ - String getName(); - - /** - * Returns the name of the WST unit - */ - String getWstUnit(); - - /** - * Return all gauge info of the river - */ - List<GaugeInfo> getGauges(); - - /** - * Returns the min q value of the river - */ - Double getMinQ(); - - /** - * Returns the max q value of the river - */ - Double getMaxQ(); - - /** - * Returns the official number of the river - */ - Long getOfficialNumber(); - - /** - * Returns the MeasurementStations on this river or null if they aren't - * available. - */ - List<MeasurementStation> getMeasurementStations(); -} - -
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/SedimentLoadInfoObject.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface SedimentLoadInfoObject extends Serializable { - - String getDescription(); - - String getDate(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/SedimentLoadInfoObjectImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class SedimentLoadInfoObjectImpl implements SedimentLoadInfoObject { - - protected String description; - protected String dateString; - - public SedimentLoadInfoObjectImpl() { - } - - public SedimentLoadInfoObjectImpl( - String description, - String dateString - ) { - this.description = description; - this.dateString = dateString; - } - - public String getDescription() { - return description; - } - - public String getDate() { - return this.dateString; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/SedimentLoadInfoRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - - -public class SedimentLoadInfoRecord -extends ListGridRecord -{ - protected SedimentLoadInfoObject sedimentLoadInfo; - - public SedimentLoadInfoRecord(SedimentLoadInfoObject info) { - this.sedimentLoadInfo = info; - setDescription(info.getDescription()); - setDate(info.getDate()); - } - - public void setDescription(String description) { - setAttribute("description", description); - } - - public void setDate(String date) { - setAttribute("date", date); - } - - public String getDescription() { - return getAttribute("description"); - } - - public String getDate() { - return getAttribute("date"); - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Settings.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.List; - -/** - * This interface describes an output settings of an artifact. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface Settings extends Serializable { - - /** The output name */ - String getName(); - - /** */ - List<String> getCategories(); - - /** */ - void setSettings(String category, List<Property> settings); - - /** */ - List<Property> getSettings(String category); - -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/StaticSQRelationArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - - -public class StaticSQRelationArtifact -extends DefaultArtifact -{ - - /** The name of this artifact */ - public static final String NAME = "static_sqrelation"; - - - - public StaticSQRelationArtifact() { - } - - public StaticSQRelationArtifact(String uuid, String hash) { - super(uuid, hash); - } - - - public StaticSQRelationArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - super(uuid, hash, inBackground, messages); - } - - - public String getName() { - return NAME; - } -}
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/StringData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class StringData extends DefaultData { - - public static final String TYPE = "string"; - - - public StringData() { - super(); - } - - - public StringData(String name, String description, DataItem[] items) { - super(name, description, TYPE, items); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/StringOptionsData.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -public class StringOptionsData implements Data { - - public static final String TYPE = "options"; - - protected String label; - protected String description; - - public DataItem[] opts; - - - public StringOptionsData() { - } - - - public StringOptionsData(String label, String desc, DataItem[] opts) { - this.label = label; - this.description = desc; - this.opts = opts; - } - - - /** - * Returns the label of the item. - * - * @return the label. - */ - public String getLabel() { - return label; - } - - - /** - * Returns the description of the item. - * - * @return the description. - */ - public String getDescription() { - return description; - } - - - /** - * Returns the type of the item. - * - * @return the type. - */ - public String getType() { - return TYPE; - } - - - /** - * Returns the data items which represent the allowed options for this Data. - * - * @return the allowed options as DataItem array. - */ - public DataItem[] getItems() { - return opts; - } - - - /** - * @return always null. - */ - public DataItem getDefault() { - return null; - } - - - /** - * Returns the values as colon separated string. - * - * @return colon separated string. - */ - public String getStringValue() { - String data = ""; - boolean first = true; - for (int i = 0; i < opts.length; i++) { - if (!first) { - data += ";"; - } - data += opts[i].getStringValue(); - first = false; - } - return data; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/StringProperty.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.HashMap; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class StringProperty extends PropertySetting { - - /** - * Create a new StringProperty for settings. - */ - public StringProperty() { - this.attributes = new HashMap<String, String>(); - } - - - /** - * Create a new StringProperty. - * @param name The attribute name. - * @param value The current value. - */ - public StringProperty( - String name, - String value) - { - this.name = name; - this.value = value; - this.attributes = new HashMap<String, String>(); - } - - - @Override - public String getValue() { - return this.value; - } - - - public Object clone() { - StringProperty clone = new StringProperty(this.getName(), - this.getValue()); - for(String s: this.getAttributeList()) { - clone.setAttribute(s, this.getAttribute(s)); - } - return clone; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : -
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Style.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import java.util.List; -import java.util.ArrayList; - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class Style implements Serializable { - - /** The theme name. */ - protected String name; - - /** The facet. */ - protected String facet; - - /** The theme index. */ - protected int index; - - /** List of theme attribute settings. */ - protected List<StyleSetting> settings; - - - /** - * Create a new style for theme attribution. - */ - public Style() { - settings = new ArrayList<StyleSetting>(); - } - - - /** - * Append a new style setting. - * @param setting A theme attribution setting. - */ - public void appendStyleSetting(StyleSetting setting) { - settings.add(setting); - } - - public void setName(String name) { - this.name = name; - } - - public void setFacet(String facet) { - this.facet = facet; - } - - public void setIndex(int index) { - this.index = index; - } - - public String getName() { - return this.name; - } - - public String getFacet() { - return this.facet; - } - - public int getIndex() { - return this.index; - } - - - /** - * Getter for a theme attribution setting. - * @return The style setting. - */ - public StyleSetting getSetting(String name) { - for (int i = 0; i < settings.size (); i++) { - if (settings.get(i).getName().equals(name)) { - return settings.get(i); - } - } - return null; - } - - - /** - * Getter for number of settings. - * @return The size of the settings list. - */ - public int getNumSettings () { - return settings.size(); - } - - - /** - * Getter for style settings. - * - * @return The list of style settings. - */ - public List<StyleSetting> getSettings() { - return this.settings; - } - - - /** - * Getter for style setting. - * @param i The index in the settings list. - * - * @return The style setting at the given index. - */ - public StyleSetting getSetting(int i) { - return this.settings.get(i); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/StyleSetting.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class StyleSetting implements Serializable { - - /**The settings name.*/ - protected String name; - - /** The default value.*/ - protected String defaultValue; - - /**The display name*/ - protected String displayName; - - /**Hints.*/ - protected String hints; - - /**The type*/ - protected String type; - - /** Determines, if the property should be visible in UI or not.*/ - protected boolean hidden; - - - /** - * Create a new StyleSetting for theme attribution. - */ - public StyleSetting() { - } - - - /** - * Create a new StyleSetting for theme attribution. - * @param name The attribute name. - * @param defaultValue The current value. - * @param displayName The name to show in a dialog. - * @param hints Hints. - * @param type The attribute type. - */ - public StyleSetting( - String name, - String defaultValue, - String displayName, - String hints, - String type, - boolean hidden) - { - this.name = name; - this.defaultValue = defaultValue; - this.displayName = displayName; - this.hints = hints; - this.type = type; - this.hidden = hidden; - } - - public void setName(String name) { - this.name = name; - } - - public void setDefaultValue(String value) { - this.defaultValue = value; - } - - public void setDisplayName(String name) { - this.displayName = name; - } - - public void setHints(String hints) { - this.hints = hints; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return this.name; - } - - public String getDefaultValue() { - return this.defaultValue; - } - - public String getDisplayName() { - return this.displayName; - } - - public String getHints() { - return this.hints; - } - - public String getType() { - return this.type; - } - - public boolean isHidden() { - return hidden; - } -} - -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Theme.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * A 'Theme' is something displayed in a Chart. It can be activated or - * deactivated to show/hide in the resultant visual representation in the - * chart. - * - * A Theme maps more or less directly to a Facet of an Artifact in a - * Collection (certain attributes are added at Collection-Level). - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface Theme extends Serializable { - - int getPosition(); - - void setPosition(int pos); - - int getIndex(); - - int getActive(); - - void setActive(int active); - - int getVisible(); - - void setVisible(int visible); - - String getArtifact(); - - String getFacet(); - - String getDescription(); - - void setDescription(String description); - - boolean equals(Object o); - - /** Get the CollectionItem representing the facets artifact. */ - CollectionItem getCollectionItem(); - - /** Set the CollectionItem representing the facets artifact. */ - void setCollectionItem(CollectionItem ci); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - - -/** - * Data Model for list of themes (shown facets). - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class ThemeList implements Serializable { - - public List<Theme> themes; - - - public ThemeList() { - } - - - public ThemeList(List<Theme> themes) { - this.themes = themes; - } - - - public List<Theme> getThemes() { - return themes; - } - - - public List<Theme> getActiveThemes() { - List<Theme> active = new ArrayList<Theme>(); - List<Theme> all = getThemes(); - - if (all == null || all.isEmpty()) { - return active; - } - - for (Theme theme: all) { - if (theme.getActive() == 1) { - active.add(theme); - } - } - - return active; - } - - - public int getThemeCount() { - return themes.size(); - } - - - /** - * Returns (first) theme of which the artifact has given uuid, null if none - * found. - * @param uuid Artifacts identifier for which to search theme. - * @return theme of which getArtifact() equals given uuid. - */ - public Theme getTheme(String uuid) { - for (Theme theme: themes) { - if (theme.getArtifact().equals(uuid)) { - return theme; - } - } - return null; - } - - - /** - * Returns a theme at a specific position. <b>NOTE: Themes start at position - * 1. So, take care in loops, that might start at index 0!</b> - * - * @param pos The position of the desired theme. - * - * @return a theme. - */ - public Theme getThemeAt(int pos) { - for (Theme theme: themes) { - if (theme.getPosition() == pos) { - return theme; - } - } - - return null; - } - - - public void removeTheme(Theme theme) { - if (theme != null) { - themes.remove(theme); - } - } - - - public void addTheme(Theme theme) { - if (theme != null) { - themes.add(theme); - } - } - - - /** - * Modifies the order of themes in this list and the position of the - * <i>theme</i> itself. - * - * @param theme The theme which position has to be modified. - * @param newPos The new position. - */ - public void setThemePosition(Theme theme, int newPos) { - int count = getThemeCount(); - int oldPos = theme.getPosition(); - - if (newPos == oldPos || newPos > count || newPos < 1) { - return; - } - - boolean moveUp = newPos < oldPos; - - for (Theme aTheme: themes) { - int tmpPos = aTheme.getPosition(); - - if (theme.equals(aTheme)) { - theme.setPosition(newPos); - } - else if (tmpPos >= newPos && tmpPos < oldPos && moveUp) { - aTheme.setPosition(tmpPos+1); - } - else if (tmpPos <= newPos && tmpPos > oldPos && !moveUp) { - aTheme.setPosition(tmpPos-1); - } - } - } - - - /** - * Create a map from index to description of facets that have a given name. - * Only visible facets are taken into account. - * @param facetName name to match against facets whose info to put in map. - * @return mapping of index to description - */ - public LinkedHashMap<String, String> toMapIndexDescription(String facetName) { - int count = getThemeCount(); - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - for (int i = 0; i <= count; i++) { - Theme theme = getThemeAt(i + 1); - - if (theme == null || theme.getVisible() == 0) { - continue; - } - - if (theme.getFacet().equals(facetName)) { - valueMap.put(String.valueOf(theme.getIndex()), - theme.getDescription()); - } - } - return valueMap; - } - - - public LinkedHashMap<String, String> - toMapArtifactUUIDDescription(String facetName - ) { - int count = getThemeCount(); - LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); - for (int i = 0; i <= count; i++) { - Theme theme = getThemeAt(i + 1); - - if (theme == null || theme.getVisible() == 0) { - continue; - } - - if (theme.getFacet().equals(facetName)) { - valueMap.put(theme.getArtifact(), - theme.getDescription()); - } - } - return valueMap; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -import java.io.Serializable; - -public class ToLoad implements Serializable -{ - - public class StringPair { - public String first; - public String second; - public StringPair(String first, String second) { - this.first = first; - this.second = second; - } - public int hashCode() { - return first.hashCode() + second.hashCode(); - } - public boolean equals(StringPair other) { - return (this.second.equals(other.second)) && (this.first.equals(other.first)); - } - } - public static final String SYNTHETIC_KEY = "key-"; - - protected Map<String, Map<StringPair, ArtifactFilter>> artifacts; - - public ToLoad() { - artifacts = new HashMap<String, Map<StringPair, ArtifactFilter>>(); - } - - public static final String uniqueKey(Map<?, ?> map) { - int idx = map.size(); - - String key = SYNTHETIC_KEY + idx; - while (map.containsKey(key)) { - key = SYNTHETIC_KEY + ++idx; - } - return key; - } - - public void add( - String artifactName, - String factory, - String out, - String name, - String ids, - String displayName - ) { - if (artifactName == null) { - artifactName = uniqueKey(artifacts); - } - - Map<StringPair, ArtifactFilter> artifact = artifacts.get(artifactName); - - if (artifact == null) { - artifact = new HashMap<StringPair, ArtifactFilter>(); - artifacts.put(artifactName, artifact); - } - - ArtifactFilter filter = artifact.get(factory); - if (filter == null) { - filter = new ArtifactFilter(factory); - artifact.put(new StringPair(factory, displayName), filter); - } - - filter.add(out, name, ids); - } - - public boolean isEmpty() { - return artifacts.isEmpty(); - } - - public List<Recommendation> toRecommendations() { - List<Recommendation> recommendations = new ArrayList<Recommendation>(); - - for (Map.Entry<String, Map<StringPair, ArtifactFilter>> all: - artifacts.entrySet() - ) { - String masterArtifact = all.getKey(); - - if (masterArtifact.startsWith(SYNTHETIC_KEY)) { // system data - masterArtifact = null; - } - - for (Map.Entry<StringPair, ArtifactFilter> entry: - all.getValue().entrySet() - ) { - StringPair pair = entry.getKey(); - String factory = pair.first; - ArtifactFilter artifactFilter = entry.getValue(); - - String ids; - Recommendation.Filter filter; - - if (masterArtifact == null) { // system data - ids = artifactFilter.collectIds(); - filter = null; - } - else { // user specific - ids = null; - filter = artifactFilter.toFilter(); - } - - Recommendation recommendation = new Recommendation( - factory, ids, masterArtifact, filter); - recommendation.setDisplayName(pair.second); - - recommendations.add(recommendation); - } - } - - return recommendations; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/User.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2011 by Intevation GmbH - * - * This program is free software under the LGPL (>=v2.1) - * Read the file LGPL.txt coming with the software for details - * or visit http://www.gnu.org/licenses/ if it does not exist. - */ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -public interface User -extends Serializable -{ - String identifier(); - - String getName(); - - void setName(String name); - - void setIdentifier(String identifier); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/WINFOArtifact.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.util.List; - - -/** - * The WINFO implementation of an Artifact. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class WINFOArtifact extends DefaultArtifact { - - /** The name of this artifact: 'winfo'.*/ - public static final String NAME = "winfo"; - - - public WINFOArtifact() { - } - - - public WINFOArtifact(String uuid, String hash) { - super(uuid, hash); - } - - - public WINFOArtifact( - String uuid, - String hash, - boolean inBackground, - List<CalculationMessage> messages - ) { - super(uuid, hash, inBackground, messages); - } - - - public String getName() { - return NAME; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - - -public class WMSLayer implements Serializable { - - protected String server; - protected String name; - protected String title; - - protected List<String> srs; - protected List<WMSLayer> layers; - - - public WMSLayer() { - layers = new ArrayList<WMSLayer>(); - } - - - /** - * @param server - * @param title - * @param name - * @param layers - */ - public WMSLayer( - String server, - String title, - String name, - List<String> srs, - List<WMSLayer> layers - ) { - this.server = server; - this.title = title; - this.name = name; - this.srs = srs; - this.layers = layers; - } - - - public String getServer() { - return server; - } - - - public String getName() { - return name; - } - - - public String getTitle() { - return title; - } - - - public List<String> getSrs() { - return srs; - } - - - public List<WMSLayer> getLayers() { - return layers; - } - - - public boolean supportsSrs(String srs) { - if (this.srs == null || this.srs.size() == 0) { - return true; - } - - if (!srs.startsWith("EPSG:")) { - srs = "EPSG:" + srs; - } - - return this.srs.contains(srs); - } - - - @Override - public String toString() { - return "WMS Layer: " + title + " (" + name + ") " + server; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQDataItem.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -package de.intevation.flys.client.shared.model; - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class WQDataItem extends DefaultDataItem { - - protected double[] qRange; - protected double[] wRange; - - public WQDataItem() { - } - - - public WQDataItem( - String label, - String description, - String value, - double[] qRange, - double[] wRange) - { - super(label, description, value); - - this.qRange = qRange; - this.wRange = wRange; - } - - - public double[] getQRange() { - return qRange; - } - - - public double[] getWRange() { - return wRange; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoObject.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public interface WQInfoObject extends Serializable { - - String getName(); - - String getType(); - - Double getValue(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoObjectImpl.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -package de.intevation.flys.client.shared.model; - - -/** - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class WQInfoObjectImpl implements WQInfoObject { - - protected String name; - - protected String type; - - protected Double value; - - - public WQInfoObjectImpl() { - } - - - public WQInfoObjectImpl( - String name, - String type, - Double value) - { - this.name = name; - this.type = type; - this.value = value; - } - - - public String getName() { - return name; - } - - - public String getType() { - return type; - } - - - public Double getValue() { - return value; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoRecord.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - - -/** - * The WQInfoRecord is a wrapper to put WQ Info objects into - * a ListGrid. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -public class WQInfoRecord extends ListGridRecord { - - /** The artifact collection. */ - protected WQInfoObject wqInfo; - - - /** - * The default constructor. - * - * @param info The wq info object. - */ - public WQInfoRecord(WQInfoObject info) { - this.wqInfo = info; - - setName(info.getName()); - setType(info.getType()); - if (info.getValue() != null) - setValue(info.getValue()); - else - setValue(info.getValue()); - } - - - public void setName(String name) { - setAttribute("name", name); - } - - - public String getName() { - return getAttributeAsString("name"); - } - - - public void setType(String type) { - setAttribute("type", type); - } - - - public String getType() { - return getAttributeAsString("type"); - } - - public void setValue(double value) { - setAttribute("value", value); - } - - - public double getValue() { - return getAttributeAsDouble("value"); - } - - - public WQInfoObject getWQInfo() { - return wqInfo; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ZoomObj.java Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -package de.intevation.flys.client.shared.model; - -import java.io.Serializable; - - -public class ZoomObj implements Serializable { - - protected Number a; - protected Number b; - protected Number c; - protected Number d; - - - public ZoomObj() { - } - - - public ZoomObj(Number a, Number b, Number c, Number d) { - this.a = a; - this.b = b; - this.c = c; - this.d = d; - } - - - public Number[] getZoom() { - return new Number[] { a, b, c, d }; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/FLYS.gwt.xml Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module rename-to='flys'> + <!-- Inherit the core Web Toolkit stuff. --> + <inherits name='com.google.gwt.user.User'/> + + <!-- Inherit the i18n google stuff. --> + <inherits name="com.google.gwt.i18n.I18N"/> + + <!-- Inherit the XML stuff of GWT --> + <inherits name="com.google.gwt.xml.XML"/> + + <!-- Inherit the Resource module of GWT --> + <inherits name="com.google.gwt.resources.Resources"/> + + <inherits name="de.intevation.artifacts.common.Common"/> + + <!-- Inherit the smartgwt Enterprise Theme. --> + <inherits name="com.smartgwt.SmartGwtNoTheme" /> + <!--inherits name="com.smartclient.theme.enterprise.Enterprise"/> + <inherits name="com.smartclient.theme.enterprise.EnterpriseResources"/--> + + <!-- Works again with smart-gwt2.5 patch from maven repository--> + <inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlue"/> + <inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlueResources"/> + + <!-- Works: + <inherits name="com.smartclient.theme.graphite.Graphite"/> + <inherits name="com.smartclient.theme.graphite.GraphiteResources"/> + --> + + <!-- Inherit the gwtopenlayers stuff --> + <inherits name="org.gwtopenmaps.openlayers.OpenLayers"/> + + <!-- Other module inherits --> + + <!-- Specify the app entry point class. --> + <entry-point class='de.intevation.flys.client.client.FLYS'/> + + <!-- Specify the paths for translatable code --> + <source path='client'/> + <source path='shared'/> + + <extend-property name="locale" values="de,en"/> +</module>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/Config.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,110 @@ +package de.intevation.flys.client.client; + +import com.google.gwt.i18n.client.LocaleInfo; + +import com.google.gwt.xml.client.Document; +import com.google.gwt.xml.client.Node; + + +/** + * A class that is used to handle the global configuration of this client. You + * can retrieve an instance of this class using the <code>getInstance</code> + * methods. <b>NOTE:</b> the configuration is initialized using {@link + * getInstance(Document)} the first time. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class Config { + + /** The instance of the configuration. */ + protected static Config INSTANCE; + + /** The xml document that contains the configuration options. */ + protected Document config; + + + /** + * Get an instance by using {@link getInstance(Document)} or {@link + * getInstance()}. + */ + private Config(Document config) { + this.config = config; + } + + + /** + * Returns an instance of this class and initializes the configuration of + * this has not been done so far. + * + * @param config The client configuration. + * + * @return an instance of this Config class. + */ + public static Config getInstance(Document config) { + if (INSTANCE == null) { + INSTANCE = new Config(config); + } + + return INSTANCE; + } + + + /** + * Returns an instance of this class. If it has not been initialized with a + * valid configuration, null is returned. + * + * @return an instance of this class or null, if the Config has not been + * initialized using {@link getInstance(Document)} so far. + */ + public static Config getInstance() { + return INSTANCE; + } + + + /** + * Returns the URL of the artifact server. + * + * @return the artifact server url. + */ + public String getServerUrl() { + Node server = config.getElementsByTagName("server").item(0); + return server.getFirstChild().getNodeValue(); + } + + + /** + * Returns the name of the current locale. + * + * @return the name of the current locale. + */ + public String getLocale() { + return LocaleInfo.getCurrentLocale().getLocaleName(); + } + + + /** + * Returns the integer configured at + * <i>/config/projectlist/update-interval/text()</i> or -1 if an error + * occured or no such option is defined. + * + * @return the update interval of the project list. + */ + public int getProjectListUpdateInterval() { + Node projectlist = config.getElementsByTagName("projectlist").item(0); + + if (projectlist == null) { + return -1; + } + + Node interval = config.getElementsByTagName("update-interval").item(0); + + if (interval == null) { + return -1; + } + + String value = interval.getFirstChild().getNodeValue(); + + return value != null ? Integer.valueOf(value) : -1; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/FLYS.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,629 @@ +package de.intevation.flys.client.client; + +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.UmbrellaException; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.xml.client.XMLParser; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.HTMLPane; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.events.CloseClickEvent; +import com.smartgwt.client.widgets.events.CloseClickHandler; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.event.CollectionChangeEvent; +import de.intevation.flys.client.client.event.CollectionChangeHandler; +import de.intevation.flys.client.client.services.ArtifactService; +import de.intevation.flys.client.client.services.ArtifactServiceAsync; +import de.intevation.flys.client.client.services.CreateCollectionService; +import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; +import de.intevation.flys.client.client.services.DescribeCollectionService; +import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; +import de.intevation.flys.client.client.services.GetArtifactService; +import de.intevation.flys.client.client.services.GetArtifactServiceAsync; +import de.intevation.flys.client.client.services.RiverService; +import de.intevation.flys.client.client.services.RiverServiceAsync; +import de.intevation.flys.client.client.services.UserService; +import de.intevation.flys.client.client.services.UserServiceAsync; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.FLYSHeader; +import de.intevation.flys.client.client.ui.FLYSView; +import de.intevation.flys.client.client.ui.FLYSWorkspace; +import de.intevation.flys.client.client.ui.ProjectList; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; +import de.intevation.flys.client.shared.model.GaugeInfo; +import de.intevation.flys.client.shared.model.River; +import de.intevation.flys.client.shared.model.User; + +import de.intevation.flys.client.client.ui.wq.WQAutoTabSet; + +import java.util.ArrayList; +import java.util.List; +import java.util.MissingResourceException; +import java.util.Set; + + +/** + * Entry point classes define <code>onModuleLoad()</code>. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FLYS implements EntryPoint, CollectionChangeHandler { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** The UserService used to retrieve information about the current user. */ + protected UserServiceAsync userService = GWT.create(UserService.class); + + /** The RiverService used to retrieve the supported rivers of the server.*/ + protected RiverServiceAsync riverService = GWT.create(RiverService.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected ArtifactServiceAsync artifactService = + GWT.create(ArtifactService.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected DescribeCollectionServiceAsync describeCollectionService = + GWT.create(DescribeCollectionService.class); + + /** The GetArtifactService used to open an existing collection. */ + protected GetArtifactServiceAsync getArtifactService = + GWT.create(GetArtifactService.class); + + /** The CreateCollectionServiceAsync used to create a new collection */ + protected CreateCollectionServiceAsync collectionService = + GWT.create(CreateCollectionService.class); + + /** The content window. It takes the whole space beneath the header. */ + protected FLYSView view; + + /** The project list that displays the projects of the user. */ + protected ProjectList projectList; + + /** The FLYSWorkspace. */ + protected FLYSWorkspace workspace; + + /** The user who is currently logged in. */ + protected User currentUser; + + /** The list of rivers supported by the server. */ + protected River[] rivers; + + /** This list is used to track the opened projects. */ + protected List<String> openProjects; + + private FLYSHeader header; + + + public static String getExceptionString(FLYSConstants msg, Throwable caught) { + try { + return msg.getString(caught.getMessage()); + } + catch(MissingResourceException ex) { + // There are some server error exceptions with + // varying text messages that cannot be localized + // easily. In this rare cases, use the plain + // exception message. + GWT.log("Missing resource for: " + caught.getMessage()); + return caught.getLocalizedMessage(); + } + } + + /** + * This is the entry point method. + */ + @Override + public void onModuleLoad() { + openProjects = new ArrayList<String>(); + + //GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { + // public void onUncaughtException(Throwable e) { + // showWarning(e); + // } + //}); + + VLayout vertical = new VLayout(); + vertical.setLayoutMargin(1); + vertical.setWidth100(); + vertical.setHeight100(); + + view = new FLYSView(); + header = new FLYSHeader(this); + + vertical.addMember(header); + vertical.addMember(view); + + vertical.draw(); + + initConfiguration(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + userService.getCurrentUser(locale, new AsyncCallback<User>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not find a logged in user."); + String msg = getExceptionString(MSG, caught); + SC.warn(msg); + } + + @Override + public void onSuccess(User user) { + GWT.log("Found a user. Set '"+ user.getName() + "'"); + setCurrentUser(user); + + header.setCurrentUser(user); + + projectList = new ProjectList(FLYS.this, user); + workspace = new FLYSWorkspace(FLYS.this); + view.setProjectList(projectList); + view.setFLYSWorkspace(workspace); + + readRivers(); + } + }); + } + + + public void showWarning(Throwable e) { + StringBuilder sb = new StringBuilder(); + sb.append("<tt>"); + + if (e instanceof UmbrellaException) { + UmbrellaException u = (UmbrellaException) e; + Set<Throwable> throwables = u.getCauses(); + + for (Throwable t: throwables) { + sb.append(t.getLocalizedMessage()); + sb.append("<br>"); + } + } + else { + sb.append(e.getLocalizedMessage()); + } + + sb.append("</tt>"); + + Window w = new Window(); + w.setTitle(MSG.unexpected_exception()); + w.setWidth(550); + w.setHeight(300); + w.centerInPage(); + w.setCanDragResize(true); + + HTMLPane p = new HTMLPane(); + p.setContents(sb.toString()); + + w.addItem(p); + w.show(); + } + + + /** + * This method should be called at system start. It initialzes the client + * configuration. + */ + protected void initConfiguration() { + String xml = FLYSResources.INSTANCE.initialConfiguration().getText(); + Config.getInstance(XMLParser.parse(xml)); + } + + + /** + * Returns the user that is currently logged in. + * + * @return the current user. + */ + public User getCurrentUser() { + return currentUser; + } + + + /** + * Sets the current user. + */ + public void setCurrentUser(User user) { + currentUser = user; + } + + + /** + * Returns the project list. + */ + public ProjectList getProjectList() { + return projectList; + } + + + /** + * Returns the projects workspace that contains all project windows. + * + * @return the FLYSWorkspace. + */ + public FLYSWorkspace getWorkspace() { + return workspace; + } + + + /** + * Returns a list of rivers supported by the artifact server. + * + * @return a list of rivers supported by the artifact server. + */ + public River[] getRivers() { + return rivers; + } + + + protected void readRivers() { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + riverService.list(locale, new AsyncCallback<River[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve a list of rivers."); + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(River[] newRivers) { + GWT.log("Retrieved " + newRivers.length + " new rivers."); + rivers = newRivers; + } + }); + } + + + /** + * This method creates a new CollectionView and adds it to the workspace. + * <b>NOTE</b>The user needs to be logged in and there need to at least one + * river - otherwise a warning is displayed and no CollectionView is + * created. + */ + public void newProject() { + if (getCurrentUser() == null) { + SC.warn(MSG.error_not_logged_in()); + return; + } + + if (getRivers() == null) { + SC.warn(MSG.error_no_rivers_found()); + readRivers(); + + return; + } + + CollectionView view = new CollectionView(this); + workspace.addView("new-project", view); + + view.addCollectionChangeHandler(getProjectList()); + } + + + protected void lockProject(String uuid) { + if (isProjectLocked(uuid)) { + return; + } + + openProjects.add(uuid); + } + + + protected void unlockProject(String uuid) { + openProjects.remove(uuid); + } + + + /** Whether project uuid is currently opened. */ + protected boolean isProjectLocked(String uuid) { + return openProjects.contains(uuid); + } + + + /** Opens (or bring into foreground) project with given id. */ + public void openProject(final String collectionID) { + if (collectionID == null) { + return; + } + + if (isProjectLocked(collectionID)) { + workspace.bringUp(collectionID); + return; + } + + lockProject(collectionID); + + GWT.log("Open existing project: " + collectionID); + + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + describeCollectionService.describe(collectionID, locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Collection c) { + final Collection collection = c; + + if (collection.getItemLength() == 0) { + CollectionView view = new CollectionView( + FLYS.this, collection, null); + + view.addCollectionChangeHandler( + getProjectList()); + view.addCloseClickHandler( + new CloseCollectionViewHandler( + FLYS.this, collectionID)); + + workspace.addView(collectionID, view); + + return; + } + + final CollectionItem item = c.getItem(0); + + if (item == null) { + SC.warn(MSG.error_load_parameterization()); + return; + } + + getArtifactService.getArtifact( + locale, + item.identifier(), + item.hash(), + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + unlockProject(collectionID); + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + CollectionView view = new CollectionView( + FLYS.this, collection, artifact); + + view.addCollectionChangeHandler( + getProjectList()); + view.addCloseClickHandler( + new CloseCollectionViewHandler( + FLYS.this, collectionID)); + + workspace.addView(collectionID, view); + } + }); + + } + }); + } + + + public void closeProject(String uuid) { + unlockProject(uuid); + workspace.destroyProject(uuid); + } + + + /** + * Create a new Artifact. + */ + public void newArtifact(String factory) { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + artifactService.create(locale, factory, null, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create the new artifact."); + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created a new artifact."); + } + }); + } + + + /** Opens a window with Main Values from gauge. */ + public void newGaugeMainValueTable(GaugeInfo gauge) { + Window mainValueView = new Window(); + + // Take middle to avoid issues at borders. + double km = (gauge.getKmEnd() + gauge.getKmStart())/2d; + mainValueView.addItem(new WQAutoTabSet(gauge.getRiverName(), + new double[] {km, km})); + mainValueView.setWidth(450); + mainValueView.setHeight(600); + + mainValueView.setMaximized(false); + mainValueView.centerInPage(); + mainValueView.setCanDragReposition(true); + mainValueView.setCanDragResize(true); + mainValueView.setShowMaximizeButton(true); + mainValueView.setKeepInParentRect(true); + + mainValueView.setTitle(MSG.mainvalues() + " " + gauge.getName() + " (" + gauge.getRiverName() + ")" ); + workspace.addChild(mainValueView); + } + + public void newGaugeDischargeCurve(String river, Long gaugeref) { + Config config = Config.getInstance(); + + final String locale = config.getLocale(); + final String riv = river; + final Long ref = gaugeref; + final FLYS flys = this; + + User user = getCurrentUser(); + + if (user == null) { + SC.warn(MSG.error_not_logged_in()); + return; + } + + collectionService.create(locale, user.identifier(), + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create new collection."); + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Collection collection) { + GWT.log("Successfully created a new collection."); + final Collection col = collection; + artifactService.createGaugeDischargeCurveArtifact( + col, locale, riv, ref, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create the new artifact."); + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created a new artifact."); + CollectionView view = new CollectionView(flys, + col, artifact); + workspace.addView(col.identifier(), view); + + view.addCollectionChangeHandler(getProjectList()); + view.addCloseClickHandler( + new CloseCollectionViewHandler( + FLYS.this, col.identifier())); + projectList.updateUserCollections(); + } + }); + } + }); + } + + public void newSQRelation(String river, int measurementStation) { + Config config = Config.getInstance(); + + final String locale = config.getLocale(); + final String riv = river; + final int mStation = measurementStation; + final FLYS flys = this; + + User user = getCurrentUser(); + + if (user == null) { + SC.warn(MSG.error_not_logged_in()); + return; + } + + collectionService.create(locale, user.identifier(), + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create new collection."); + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Collection collection) { + GWT.log("Successfully created a new collection."); + final Collection col = collection; + artifactService.createSQRelationArtifact( + col, locale, riv, mStation, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create the new artifact."); + SC.warn(getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created a new artifact."); + CollectionView view = new CollectionView(flys, + col, artifact); + workspace.addView(col.identifier(), view); + + view.addCollectionChangeHandler(getProjectList()); + view.addCloseClickHandler( + new CloseCollectionViewHandler( + FLYS.this, col.identifier())); + projectList.updateUserCollections(); + } + }); + } + }); + } + + @Override + public void onCollectionChange(CollectionChangeEvent event) { + Collection oldC = event.getOldValue(); + + if (oldC == null) { + Collection newC = event.getNewValue(); + lockProject(newC.identifier()); + } + } + + + + /** + * This CloseClickHandler is used to remove lock on a specific Collection so + * that is might be opened again. + */ + public class CloseCollectionViewHandler implements CloseClickHandler { + protected FLYS flys; + protected String uuid; + + public CloseCollectionViewHandler(FLYS flys, String uuid) { + this.flys = flys; + this.uuid = uuid; + } + + @Override + public void onCloseClick(CloseClickEvent event) { + flys.closeProject(uuid); + } + } + + public boolean isProjectListVisible() { + if (this.projectList == null) { + return true; + } + return this.projectList.isVisible(); + } + + public void hideProjectList() { + if (this.projectList != null) { + this.projectList.hide(); + } + } + + public void openProjectList() { + if (this.projectList != null) { + this.projectList.show(); + } + } + + public void hideHeaderProjectButton() { + this.header.hideProjectButton(); + } + + public void shoHeaderProjectButton() { + this.header.showProjectButton(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,1268 @@ +package de.intevation.flys.client.client; + +import com.google.gwt.i18n.client.ConstantsWithLookup; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface FLYSConstants extends ConstantsWithLookup { + + String static_sqrelation(); + + String add(); + + String unexpected_exception(); + + String title(); + + String fullname(); + + String user(); + + String guest(); + + String projects(); + + String open_project(); + + String delete_project(); + + String rename_project(); + + String clone_project(); + + String copy_of (); + + String manage_projects(); + + String favorite_tooltip(); + + String favorite_tooltip_meaning(); + + String projectlist_creationTime(); + + String projectlist_title(); + + String projectlist_favorite(); + + String really_delete(); + + String project_name_too_long(); + + String logout(); + + String switch_language(); + + String info(); + + String warning(); + + String warning_language(); + + String warning_no_wsp_selected(); + + String warning_cannot_parse_date(); + + String no_projects(); + + String load_projects(); + + String empty_table(); + + String empty_filter(); + + String date_format(); + + String datetime_format(); + + String new_project(); + + String new_calculation(); + + String module_selection(); + + String river_selection(); + + String winfo(); + + String minfo(); + + String map(); + + String new_map(); + + String new_chart(); + + String diagram(); + + String axes(); + + String legend(); + + String chart_title(); + + String chart_subtitle(); + + String grid(); + + String antialiasing(); + + String axis_name(); + + String chart_start(); + + String chart_end(); + + String x_axis(); + + String y1_axis(); + + String y2_axis(); + + String y3_axis(); + + String legend_name(); + + String show_legend(); + + String aggregation_threshold(); + + String scale(); + + String databasket(); + + String databasket_loading(); + + String theme_top(); + + String theme_up(); + + String theme_down(); + + String theme_bottom(); + + String zoom_all(); + + String zoom_in(); + + String zoom_out(); + + String zoom_back(); + + String properties_ico(); + + String pan(); + + String askThemeRemove(); + + String fix(); + + String fixanalysis(); + + String next(); + + String river_km(); + + String uesk_profile_distance(); + + String location_distance_state(); + + String distance_state(); + + String waterlevel_ground_state(); + + String location(); + + String locations(); + + String single_location(); + + String distance(); + + String unitFrom(); + + String unitTo(); + + String dpLabelFrom(); + + String dpUnitFrom(); + + String dpLabelTo(); + + String dpUnitTo(); + + String dpLabelStep(); + + String dpUnitStep(); + + String wgLabelFrom(); + + String wgUnitFrom(); + + String wgLabelTo(); + + String wgUnitTo(); + + String wgLabelStep(); + + String wgUnitStep(); + + String unitWidth(); + + String unitFromInM(); + + String unitToInM(); + + String unitDiffInM(); + + String unitLocation(); + + String wrongFormat(); + + String atLeastOneValue(); + + String missingInput(); + + String too_many_values (); + + String from(); + + String to(); + + String riverside(); + + String calcTableTitle(); + + String helperPanelTitle(); + + String gaugePanelTitle(); + + String measurementStationPanelTitle(); + + String wqTitle(); + + String wqadaptedTitle(); + + String wqHistorical(); + + String unitWNN(); + + String wqWFree(); + + String wqW(); + + String wqQ(); + + String wqQatGauge(); + + String wqQGauge(); + + String wqSingle(); + + String wqRange(); + + String unitWSingle(); + + String unitWFrom(); + + String unitWTo(); + + String unitWStep(); + + String unitQSingle(); + + String unitQFrom(); + + String unitQTo(); + + String unitQStep(); + + String main_channel(); + + String total_channel(); + + String footerHome(); + + String footerContact(); + + String footerImpressum(); + + String projectListMin(); + + String projectListAdd(); + + String buttonNext(); + + String imageBack(); + + String imageSave(); + + String search(); + + String properties(); + + String activateTheme(); + + String deactivateTheme(); + + String removeTheme(); + + String manageThemes(); + + String label_ok(); + + String label_cancel(); + + String cancelCalculationLabel(); + + String calculationCanceled(); + + String flysLogo(); + + String bfgLogo(); + + String bfgLogoSmall(); + + String downloadPNG(); + + String downloadPDF(); + + String downloadSVG(); + + String downloadCSV(); + + String downloadAT(); + + String downloadWST(); + + String loadingImg(); + + String cancelCalculation(); + + String markerRed(); + + String markerGreen(); + + String riverMap(); + + String range(); + + String description(); + + String resultCount(); + + String start_year(); + + String end_year(); + + String period(); + + String gauge_class(); + + String eventselect(); + + String events(); + + String kmchart(); + + String addPointsTooltip(); + + String addWSPTooltip(); + + String downloadPNGTooltip(); + + String downloadPDFTooltip(); + + String downloadSVGTooltip(); + + String downloadCSVTooltip(); + + String zoomToMaxExtentTooltip(); + + String zoomOutTooltip(); + + String historyBackTooltip(); + + String panControlTooltip(); + + String zoomboxTooltip(); + + String chartPropertiesTooltip(); + + String year(); + + String sedimentload_ls(); + + // Gauges + + String gauge_mnq(); + + String gauge_mq(); + + String gauge_mhq(); + + String gauge_hq5(); + + // Elevation window + + String ele_window_title(); + + String ele_window_label(); + + String ele_window_x_col(); + + String ele_window_y_col(); + + String ele_window_z_col(); + + String ele_window_ok_button(); + + String ele_window_cancel_button(); + + String ele_window_format_error(); + + String ele_window_save_error(); + + String ele_window_geometry_error(); + + // OUTPUT TYPES + + String discharge_curve_gaugeless(); + + String discharge_curve(); + + String gauge_discharge_curve(); + + String computed_discharge_curve(); + + String computed_discharge_curves(); + + String longitudinal_section(); + + String duration_curve(); + + String reference_curve(); + + String reference_curve_normalized(); + + String reference_endpoint(); + + String reference_startpoint(); + + String name(); + + String type(); + + String wq_table_w(); + + String wq_waterlevel_label(); + + String wq_table_q(); + + String wq_value_w(); + + String wq_value_q(); + + String discharge_longitudinal_section(); + + String floodmap(); + + String cross_section(); + + String cross_sections(); + + String w_differences(); + + String historical_discharge(); + + String historical_discharge_wq(); + + String extreme_wq_curve(); + + String showextramark(); + + String fix_wq_curve(); + + String fix_deltawt_curve(); + + String fix_longitudinal_section_curve(); + + String fix_derivate_curve(); + + String fix_vollmer_wq_curve(); + + // EXPORTS + + String waterlevel_export(); + + String waterlevel_report(); + + String computed_dischargecurve_at_export(); + + String discharge_longitudinal_section_export(); + + String discharge_longitudinal_section_report(); + + String computed_dischargecurve_export(); + + String computed_dischargecurve_report(); + + String durationcurve_export(); + + String durationcurve_report(); + + String dataexport(); + + String reference_curve_export(); + + String w_differences_export(); + + String historical_discharge_export(); + + String csv(); + + String wst(); + + String at(); + + String pdf(); + + String chart_themepanel_header_themes(); + + String chart_themepanel_header_actions(); + + String chart_themepanel_synchron(); + + String chart_themepanel_asynchron(); + + String chart_themepanel_set_master(); + + String chart_themepanel_new_area(); + + String chart_themepanel_area_under(); + + String chart_themepanel_area_over(); + + String chart_themepanel_area_between(); + + String against_x_axis(); + + String discharge(); + + String flow_velocity(); + + String flow_velocity_export(); + + String bedheight_middle(); + + String bedheight_middle_export(); + + String bed_longitudinal_section(); + + String bed_longitudinal_section_export(); + + String sq_relation_a(); + + String sq_relation_b(); + + String sq_relation_c(); + + String sq_relation_d(); + + String sq_relation_e(); + + String sq_relation_f(); + + String sq_relation_export(); + + String exportATTooltip(); + + String load_diameter(); + + String bed_diameter(); + + String soundings(); + + String soundings_width(); + + String bed_difference_year(); + + String bed_difference_epoch(); + + String bed_difference_height_year(); + + // ERRORS + + String error_years_wrong(); + + String error_read_minmax_values(); + + String error_validate_range(); + + String error_validate_date_range(); + + String error_validate_date_range_invalid(); + + String error_validate_lower_range(); + + String error_validate_upper_range(); + + String error_create_artifact(); + + String error_describe_artifact(); + + String error_feed_data(); + + String error_advance_artifact(); + + String error_add_artifact(); + + String error_remove_artifact(); + + String error_create_collection(); + + String error_describe_collection(); + + String error_no_rivers_found(); + + String error_no_gaugeoverviewinfo_found(); + + String error_no_such_user(); + + String error_no_users(); + + String error_no_waterlevel_pair_selected(); + + String error_same_waterlevels_in_pair(); + + String error_not_logged_in(); + + String error_load_parameterization(); + + String error_feed_no_data(); + + String error_feed_from_out_of_range(); + + String error_feed_to_out_of_range(); + + String error_feed_from_bigger_to(); + + String error_feed_invalid_wq_mode(); + + String error_feed_number_format_float(); + + String error_feed_invalid_calculation_mode(); + + String error_feed_no_calculation_mode(); + + String error_feed_no_such_river(); + + String error_feed_no_river_selected(); + + String error_feed_no_wq_mode_selected(); + + String error_feed_q_values_invalid(); + + String error_feed_w_values_invalid(); + + String error_no_meta_data_found(); + + String error_chart_info_service(); + + String error_invalid_double_value(); + + String error_load_artifact(); + + String error_no_calc_result(); + + String error_no_theme_styles_found(); + + String error_no_feature_selected(); + + String error_no_map_config(); + + String error_no_map_output_type(); + + String error_no_module_found(); + + String warning_use_first_feature(); + + String warning_select_two_values(); + + String error_no_valid_gfi_url(); + + String error_gfi_req_failed(); + + String error_gfi_parsing_failed(); + + String error_gc_req_failed(); + + String error_gc_doc_not_valid(); + + String error_malformed_url(); + + String error_no_dgm_selected(); + + String error_invalid_dgm_selected(); + + String error_bad_dgm_range(); + + String error_bad_dgm_river(); + + String error_dialog_not_valid(); + + String error_invalid_date(); + + String error_wrong_date(); + + String bottom_edge(); + + String top_edge(); + + String error_same_location(); + + String error_contains_same_location(); + + String error_update_collection_attribute(); + + String error_values_needed(); + + // MAP RELATED STRINGS + + String digitize(); + + String pipe1(); + + String pipe2(); + + String ditch(); + + String dam(); + + String ring_dike(); + + String selectFeature(); + + String removeFeature(); + + String getFeatureInfo(); + + String getFeatureInfoTooltip(); + + String getFeatureInfoWindowTitle(); + + String addWMS(); + + String printMapSettings(); + + String addWMSTooltip(); + + String adjustElevation(); + + String adjustElevationTooltip(); + + String measureLine(); + + String measurePolygon(); + + String step(); + + String calculationStarted(); + + String zoomMaxExtent(); + + String zoomIn(); + + String zoomOut(); + + String zoomLayer(); + + String moveMap(); + + String digitizeObjects(); + + String selectObject(); + + String removeObject(); + + String measureDistance(); + + String measureArea(); + + String map_themepanel_header_style(); + + String zoomToLayer(); + + String requireDGM(); + + String upload_file(); + + String shape_file_upload(); + + // data cage + + String waterlevels(); + + String old_calculations(); + + String officiallines(); + + String datacageAdd(); + + String fixations(); + + String flood_protections(); + + String columns(); + + String basedata(); + + String heightmarks(); + + String annotation(); + + String annotations(); + + String all_annotations(); + + String flowvelocitymeasurement(); + + String bed_quality_bed(); + + String bed_quality_load(); + + String additionals(); + + String differences(); + + String kilometrage(); + + String riveraxis(); + + String km(); + + String qps(); + + String hws(); + + String catchments(); + + String catchment_wms(); + + String floodplain(); + + String lines(); + + String buildings(); + + String fixpoints(); + + String uesk(); + + String calculations(); + + String current(); + + String bfg(); + + String land(); + + String potential(); + + String rastermap(); + + String background(); + + String discharge_tables_chart(); + + String discharge_table_nn(); + + String discharge_table_gauge(); + + String mainvalue(); + + String mainvalues(); + + String wmainvalue(); + + String qmainvalue(); + + String show_mainvalues(); + + String dems(); + + String hydrboundaries(); + + String gaugelocations(); + + String single(); + + String epoch(); + + String bedheights(); + + String morph_width(); + + String datacage(); + + String datacage_add_pair(); + + // Capabilities Information Panel + + String addwmsInputTitle(); + + String addwmsInfoTitle(); + + String addwmsLayerTitle(); + + String addwmsBack(); + + String addwmsContinue(); + + String addwmsCancel(); + + String addwmsInvalidURL(); + + String capabilitiesHint(); + + String capabilitiesTitle(); + + String capabilitiesURL(); + + String capabilitiesAccessConstraints(); + + String capabilitiesFees(); + + String capabilitiesContactInformation(); + + String capabilitiesEmail(); + + String capabilitiesPhone(); + + String chart(); + + String export(); + + String width(); + + String height(); + + String visibility(); + + String upper(); + + String lower(); + + String fixation(); + + String font_size(); + + String label(); + + String subtitle(); + + String display_grid(); + + String display_logo(); + + String logo_placeh(); + + String logo_placev(); + + String top(); + + String bottom(); + + String center(); + + String left(); + + String right(); + + String none(); + + String notselected(); + + String linetype(); + + String textstyle(); + + String linecolor(); + + String showhorizontalline(); + + String showverticalline(); + + String horizontal(); + + String vertical(); + + String textcolor(); + + String textsize(); + + String font(); + + String showborder(); + + String showpoints(); + + String showbackground(); + + String textshowbg(); + + String backgroundcolor(); + + String bandwidthcolor(); + + String textbgcolor(); + + String textorientation(); + + String linesize(); + + String pointsize(); + + String bandwidth(); + + String pointcolor(); + + String showlines(); + + String showlinelabel(); + + String showpointlabel(); + + String labelfontsize(); + + String labelfontcolor(); + + String labelfontface(); + + String labelfontstyle(); + + String labelbgcolor(); + + String labelshowbg(); + + String showwidth(); + + String showlevel(); + + String showminimum(); + + String showmaximum(); + + String transparent(); + + String transparency(); + + String showarea(); + + String showarealabel(); + + String showmiddleheight(); + + String fillcolor(); + + String wsplgen_cat1(); + + String wsplgen_cat2(); + + String wsplgen_cat3(); + + String wsplgen_cat4(); + + String wsplgen_cat5(); + + String areabgcolor(); + + String areashowborder(); + + String areashowbg(); + + String areabordercolor(); + + String areatransparency(); + + String attribution(); + + // Manual Points editor + + String addpoints(); + + String pointname(); + + String removepoint(); + + String newpoint(); + + String standby(); + + String points(); + + String editpoints(); + + // Manual WaterLine (WSP) Editor. + + String addWSPButton(); + + String addWSP(); + + String selection(); + + String fix_deltawt_export(); + + String select(); + + String add_date(); + + String fix_parameters_export(); + + String fix_parameters(); + + String sq_overview(); + + // Gauge Overview Info + + String gauge_zero(); + + String gauge_q_unit(); + + String gauge_info_link(); + + String gauge_river_info_link(); + + String gauge_river_url(); + + String gauge_url(); + + String gauge_curve_link(); + + String gauge_discharge_curve_at_export(); + + // Measurement Station Info + + String measurement_station_type(); + + String measurement_station_operator(); + + String measurement_station_start_time(); + + String measurement_station_url(); + + String measurement_station_info_link(); + + String measurement_station_gauge_name(); + + String discharge_timeranges(); + + String discharge_chart(); + + String projectlist_close(); + + String startcolor(); + + String endcolor(); + + String numclasses(); + + String welcome(); + + String welcome_open_or_create(); + + String official(); + + String inofficial(); + + String custom_lines(); + + String hws_lines(); + + String hws_points(); + + String hws_fed_unknown(); + + String jetties(); + + String route_data(); + + String other(); + + String axis(); + + String bfg_model(); + + String federal(); + + String areas(); + + String sobek_areas(); + + String sobek_flooded(); + + String measurements(); + + String floodmarks(); + + String pegel_had_measurement_points(); + + String gauge_points(); + + String gauge_names(); + + String gauge_level(); + + String gauge_tendency(); + + String printTooltip(); + + String print(); + + String printWindowTitle(); + + String mapfish_data_range(); + + String mapfish_data_subtitle(); + + String mapfish_data_strech(); + + String mapfish_data_institution(); + + String mapfish_data_source(); + + String mapfish_data_creator(); + + String mapfish_data_dateplace(); + + String mapfish_data_river(); + + String mapTitle(); + + String mapSubtitle(); + + String mapRange(); + + String mapStretch(); + + String mapCreator(); + + String mapInstitution(); + + String mapSource(); + + String mapDate(); + + String mapLogo(); + + String wmsURLMenuItem(); + + String wmsURLBoxTitle(); + + String requireTheme(); + + String PATH(); + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,668 @@ +fullname = Flusshydrologische Software +user = User: +guest = guest +logout = Logout +projects = Projects +open_project = Open Project +delete_project = Delete Project +rename_project = Rename Project +clone_project = Clone Project +copy_of = Copy +manage_projects = Manage Projects +favorite_tooltip = Permanently store? +favorite_tooltip_meaning = Golden star: stored +projectlist_creationTime = Creation time +projectlist_title = Title +projectlist_favorite = Permanent +projectlist_close = Close +really_delete = Do you really want to delete this project? +project_name_too_long = The entered project name is too long. Max length is $LEN characters. +switch_language = German +info = Info +warning = Attention +warning_language = Choosing a new language starts a new session. All open windows will be closed. +no_projects = No existing calculations found. +load_projects = Load calculations... +empty_table = Loading data... +empty_filter = No data found. +date_format = yyyy-MM-dd +datetime_format = yyyy-MM-dd HH:mm +new_project = New Project +new_calculation = New Calculation +module_selection = Module +river_selection = Rivers +winfo = W-INFO +minfo = M-INFO +new_map = New Map +map = Map +new_chart = New Chart +diagram = Chart +axes = Axes +legend = Legend +chart_title = Title +chart_subtitle = Subtitle +grid = Grid +antialiasing = Antialiasing +axis_name = Name +chart_start = start +chart_end = end +x_axis = X-Axis +y1_axis = Y1-Axis +y2_axis = Y2-Axis +y3_axis = Y3-Axis +legend_name = Name +show_legend = Show +aggregation_threshold = Threshold for aggregation of legend entries +scale = Scale +databasket = Databasket +databasket_loading = Loading Databasket content +fix = Fixing +fixanalysis = Fixing Analysis +next = Next +location_distance_state = Choose calculation location(s) / range [km] +distance_state = Choose calculation range [km] +waterlevel_ground_state = Choose differences betweeen waterlevel and ground [m] +location = Location(s) +locations = Locations +single_location = Location +distance = Range +unitFrom = km +unitTo = km a +unitWidth = m +search = Search +discharge = Discharge Name +properties = Properties +activateTheme = Activate +deactivateTheme = Deactivate +removeTheme = Remove +manageThemes = Manage themes +label_ok = Ok +label_cancel = Cancel +cancelCalculationLabel = Stop the current calculation. +calculationCanceled = The calculation has been canceled. +range = Range +resultCount = Hits +start_year = Start +end_year = End +period = Period +year = Year +sedimentload_ls = Sediment Load +welcome = Welcome to Flusshydrologische Software +welcome_open_or_create = Please open a project from the project list or create a +# Header images +flysLogo = images/flys_logo.gif +bfgLogo = images/bfg_logo.gif +bfgLogoSmall = images/bfg_logo_small.png + +# Images +downloadPNG = images/png_export.png +downloadPDF = images/pdf_export.png +downloadSVG = images/svg_export.png +downloadCSV = images/save_csv.png +downloadAT = images/save_at.png +downloadWST = images/save_wst.png +loadingImg = images/loading.gif +loadingImg = images/loading.gif +cancelCalculation = images/cancelCalculation.png +markerRed = images/marker_red.png +markerGreen = images/marker_green.png +riverMap = images/FLYS_Karte.png +properties_ico = images/properties.png + +dpLabelFrom = from +dpUnitFrom = km +dpLabelTo = to +dpUnitTo = km +dpLabelStep = a +dpUnitStep = m + +wgLabelFrom = From +wgUnitFrom = m +wgLabelTo = To +wgUnitTo = m +wgLabelStep = a +wgUnitStep = m + +unitFromInM = From [m]: +unitToInM = To [m]: +unitDiffInM = Diff [m]: +unitLocation = km +wrongFormat = Wrong format +atLeastOneValue = You need to insert at least one value. +missingInput = You need to enter a value. +too_many_values = Only one value allowed + +addPointsTooltip = Add manual points +addWSPTooltip = Add manual LS +downloadPNGTooltip = Download chart as PNG +downloadPDFTooltip = Download chart as PDF +downloadSVGTooltip = Download chart as SVG +downloadCSVTooltip = Download data as CSV +zoomToMaxExtentTooltip = Zoom to max extent +zoomOutTooltip = Zoom out +historyBackTooltip = Previous zoom +panControlTooltip = Pan +zoomboxTooltip = Zoombox +chartPropertiesTooltip = Chartproperties +printTooltip = Print + +description = Description +from = From +to = To +riverside = Riverside +bottom_edge = Bottom edge +top_edge = Top edge +name = Name +type = Type +wq_table_w = Characteristic Waterlevels +wq_waterlevel_label = Characteristic Waterlevel +wq_table_q = Characteristic Discharges / Durations +wq_value_w = W [cm at Gauge] +wq_value_q = Q [m\u00b3/s] +river_km = River-Km +uesk_profile_distance = Distance [m] + +wqTitle = Input for W/Q Data +wqadaptedTitle = Input for W/Q Data +wqHistorical = Selection of Analyse Type +calcTableTitle = Values +helperPanelTitle = Input Support +gaugePanelTitle = Gauge Information +measurementStationPanelTitle = Measurement Station Information +wqW = W at Gauge [cm] +wqQ = Q [m\u00b3/s] +wqQatGauge = Q at Gauge [m\u00b3/s] +wqWFree = W free position [m+NHN] +wqQGauge = Discharge at Gauge +wqSingle = Single values +wqRange = Range +unitWNN = W [NN+m] +unitWSingle = cm +unitWFrom = cm - +unitWTo = cm a +unitWStep = cm +unitQSingle = m³/s +unitQFrom = m³/s - +unitQTo = m³/s a +unitQStep = m³/s +main_channel = Main Channel +total_channel = Total Channel +footerHome = Home +footerContact = Contact +footerImpressum = Legal info +print = Print +printWindowTitle = PDF-Print Settings + +projectListMin = format-indent-less.png +projectListAdd = list-add.png +buttonNext = Next +imageBack = images/back_en.png +imageSave = images/save.png +theme_top = images/go-first.png +theme_up = images/go-up.png +theme_down = images/go-down.png +theme_bottom = images/go-bottom.png +zoom_all = images/mag_100.png +zoom_in = images/mag_zoom_box.png +zoom_out = images/mag_zoom_minus.png +zoom_back = images/mag_zoom_back.png +pan = images/hand.png +askThemeRemove = Are you sure that you want to remove the selected theme / themes? +add = Add + +static_sqrelation = SQ relation +discharge_curve = Discharge Curve at Gauge +discharge_curve_gaugeless = Discharge Curve +gauge_discharge_curve = Discharge Table at Gauge +computed_discharge_curve = Discharge Curve +computed_discharge_curves = Discharge Curves +longitudinal_section = Longitudinal Section Curve +duration_curve = Duration Curve +discharge_longitudinal_section = Discharge Longitudinal Section +floodmap = Floodmap +historical_discharge = Time-Chart +historical_discharge_wq = W/Q-Chart +flow_velocity = Flow Velocity +flow_velocity_export = Flow Velocity Export +bedheight_middle = Middle Bed Height +bedheight_middle_export = Middle Bed Height Export +bed_longitudinal_section = Bed Quality +bed_longitudinal_section_export = Bed Quality Export +sq_relation_a = A Feinkornanteil +sq_relation_b = B Sand (Suspensionstransport) +sq_relation_c = C Sand (Geschiebetransport) +sq_relation_d = D Fein- und Mittelkies +sq_relation_e = E Grobkornanteil (> Mittelkies) +sq_relation_f = F Geschiebetransport Gesamt +sq_relation_export = SQ Export +cross_section = Cross Section +cross_sections = Cross Sections +w_differences = Differences +w_differences_export = Differences Export +reference_curve_export = Reference Curve Export +historical_discharge_export = Historical Discharge Curve Export +showextramark = Show begin of extrapolation +extreme_wq_curve = W/Q +fix_wq_curve = W/Q-Diagram +fix_deltawt_curve = \u0394 W/t +fix_longitudinal_section_curve = Longitudinal Section +fix_derivate_curve = Derivate +fix_vollmer_wq_curve = W/Q-Diagram +datacage_add_pair = Add difference pair +load_diameter = Bedload Diameter +bed_diameter = Bed Diameter +soundings = Soundings +soundings_width = Soundings Width +bed_difference_year = Single Bedheight Differences +bed_difference_epoch = Epoch Bedheight Differences +bed_difference_height_year = Bedheight Differences per year + +exportATTooltip = Export as AT file + +waterlevel_export = Waterlevel Export +waterlevel_report = Waterlevel Report +computed_dischargecurve_export = Discharge Curve Export +computed_dischargecurve_report = Discharge Curve Report +discharge_longitudinal_section_export = Discharge Longitudinal Section Export +discharge_longitudinal_section_report = Discharge Longitudinal Section Report +durationcurve_export = Duration Curve Export +durationcurve_report = Duration Curve Report +dataexport = Data export +csv = CSV +wst = WST +at = AT +pdf = PDF +computed_dischargecurve_at_export = AT Export +gauge_discharge_curve_at_export = Gauge Discharge Curve +gauge_class = Gauge Class +eventselect = Eventselection +events = Events +kmchart = W/Q-Preview + +chart_themepanel_header_themes = Theme +chart_themepanel_header_actions = Actions +chart_themepanel_synchron = Navigate synchronously +chart_themepanel_asynchron = Navigate independently +chart_themepanel_set_master = Reference +chart_themepanel_new_area = New Area... +chart_themepanel_area_under = under ... +chart_themepanel_area_over = over ... +chart_themepanel_area_between = between ... +against_x_axis = Over X-Axis + +gauge_mnq = around MNQ +gauge_mq = around MQ +gauge_mhq = around MHQ +gauge_hq5 = above HQ5 + +ele_window_title = Elevation Node +ele_window_label = Elevation settings in m \u00fc. NN. +ele_window_x_col = X +ele_window_y_col = Y +ele_window_z_col = Z-Coordinate +ele_window_ok_button = Set elevations +ele_window_cancel_button = Cancel +ele_window_format_error = The elevation you have entered is invalid: +ele_window_save_error = Error while saving elevations. +ele_window_geometry_error = The geometry is not supported: + +unexpected_exception = There occured an unexpected exception +error_years_wrong = The second year needs to be bigger than the first year. +error_read_minmax_values = Error while reading min/max values for the location input. +error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2. +error_validate_date_range = Start date needs to be before end date. +error_validate_date_range_invalid = The specified timerange is invalid. +error_validate_lower_range = The lower value $1 needs to be bigger than $2. +error_validate_upper_range = The upper value $1 needs to be smaller than $2. +error_empty_state = Required inputs are missing. +error_invalid_double_value = Wrong format for a floating point number. +error_create_artifact = Error while creating new project. +error_describe_artifact = Error while loading the parameterization. +error_feed_data = Error while inserting new data. +error_advance_artifact = Error while changing the project's state. +error_add_artifact = Error while inserting new data. +error_remove_artifact = Error while removing data. +error_create_collection = Error while creating a new collection. +error_describe_collection = Error while fetching the projects state. +error_no_rivers_found = Error while reading supported rivers. +error_no_such_user = Error - no such user found. +error_no_users = Error - no users found. +error_no_waterlevel_pair_selected = Error - no waterlevel pair for building differences selected. +error_same_waterlevels_in_pair = Error - minuend and subtrahend have to differ. +error_not_logged_in = You need to log in before you are allowed to start your work. +error_load_parameterization = Could not load the parameterization. +error_wrong_date = Please enter valid dates. +error_no_gaugeoverviewinfo_found = Error while fetching the river and gauge info + +error_feed_no_data = No input data found. +error_feed_from_out_of_range = The lower value is bigger than the upper value. +error_feed_to_out_of_range = The upper value is out or the valid range. +error_feed_from_bigger_to = The lower value is bigger than the upper value. +error_feed_invalid_wq_mode = Invalid WQ-Mode selected. +error_feed_number_format_float = The inserted value is no floating point number. +error_feed_invalid_calculation_mode = The chosen calculation method is invalid. +error_feed_no_calculation_mode = No calculation method chosen. +error_feed_no_such_river = The selected river is not provided. +error_feed_no_river_selected = No river selected. +error_feed_no_wq_mode_selected = No W/Q mode selected. +error_feed_q_values_invalid = Selected Q values are outside the valid range. +error_feed_w_values_invalid = Selected W values are outside the valid range. +error_chart_info_service = Could not fetch meta information of the chart. +error_no_meta_data_found = No meta data found. +error_load_artifact = Error while adding data to the current project. +error_no_calc_result=No calculation results found. +error_no_theme_styles_found=No style for the selected theme found. +error_no_feature_selected = No object selected. +error_no_map_config = No Map configuration found. +error_no_map_output_type = No Map output found. +error_no_valid_gfi_url = No valid GetFeatureInfo response found. +error_gfi_req_failed = GetFeatureInfo request failed. +error_gfi_parsing_failed = Failed to read GetFeatureInfo response. +error_gc_req_failed = Error while loading Capabilities document. +error_gc_doc_not_valid = Capabilities document is not valid. +error_malformed_url = The URL you have entered is not valid. +error_no_dgm_selected = No DEM selected. +error_invalid_dgm_selected = You have selected an invalid DEM. +error_bad_dgm_range = You have selected a DEM with an invalid range. +error_bad_dgm_river = You have selected a DEM for a wrong river. +error_dialog_not_valid = One or more values are not valid. +error_invalid_date = The entered date is not valid. +error_same_location = Reference location equals selected location. +error_contains_same_location = Target locations contains reference location. +error_update_collection_attribute = Error while updating the collection attribut +error_values_needed = You must provide values. +error_no_module_found = No modules found + +warning_use_first_feature = You have more that one object selected. The first one is used. +warning_no_wsp_selected = No waterlevel selected! +warning_cannot_parse_date = Invalid date! +warning_select_two_values = Please select two values! + +## map related strings +digitize = images/digitize.png +pipe1 = Pipe1 +pipe2 = Pipe12 +ditch = Ditch +dam = Dam +ring_dike = Ringdike +selectFeature = images/selectFeature.png +removeFeature = images/removeFeature.png +getFeatureInfo = images/info.png +getFeatureInfoTooltip = Information Tool +getFeatureInfoWindowTitle = Information for Map Layer: +addWMS = images/add_map.png +printMapSettings = images/print_map_settings.png +addWMSTooltip = Load layers from external WMS service. +adjustElevation = images/adjustElevation.png +measureLine = images/measure_line.png +measurePolygon = images/measure_plane.png +step = Step +calculationStarted = Calculation started. +zoomMaxExtent = Max extent +zoomIn = Zoom in +zoomOut = Zoom out +zoomLayer = Zoom to layer +moveMap = Move +digitizeObjects = Creation of pipes, ditches, dams and ringdikes +selectObject = Select tool +removeObject = Remove selected object +adjustElevationTooltip = Define elevations for barriers +measureDistance = Measure line +measureArea = Measure area +map_themepanel_header_style = Style +zoomToLayer = Layer-Zoom +requireDGM = You need to choose a DEM. +upload_file = upload +shape_file_upload = Upload shapefile + +# data cage +waterlevels = Waterlevels +old_calculations = Former Calculations +officiallines = Official lines +datacageAdd = Add data +heightmarks = Height Marks +basedata = Base Data +fixations = Fixations +flood_protections = Flood Protections +columns = Columns +annotation = Annotations +annotations = Annotations +all_annotations = All annotations +flowvelocitymeasurement = Flowvelocity measurements +bed_quality_bed = Quality - Bed +bed_quality_load = Quality - Load +additionals = Additional Longitudinal Section Curves +differences = Differences +kilometrage = Kilometrage +riveraxis = Riveraxis +km = Km +qps = Crosssection Tracks +hws = Floodplain Protection Work +catchments = Catchments +catchment_wms = Catchments (WMS) +floodplain = Floodplain +lines = Lines +buildings = Buildings +fixpoints = Fixpoints +uesk = Floodmaps +calculations = Calculations +current = Current +potential = Potential +bfg = BfG +land = Land +rastermap = Rastermap +background = Background Map +discharge_tables_chart = W/Q-Preview +discharge_table_nn = Discharge Tables at Gauge +discharge_table_gauge = Discharge Table at Gauge +mainvalue = Mainvalue +mainvalues = Mainvalues +wmainvalue = Mainvalues (W) +qmainvalue = Mainvalues (Q) +show_mainvalues = Show Mainvalues +dems = Digital Elevation Models +hydrboundaries = Hydrological Boundaries +gaugelocations = Location of Gauges +single = Year +epoch = Epoch +bedheights = Bedheights +morph_width = morphologic Width +datacage = Datacage +official = Offical +inofficial = Inofficiall +custom_lines = Own Digitalizations +hws_lines = Lines +hws_points = Points +hws_fed_unknown = Unknown State +jetties = Jetties +route_data = Route Data +other = Other +axis = Axis +bfg_model = BfG-Model +federal = Federal States +areas = Areas +sobek_flooded = SOBEK-Boundary flooded / not flooded +sobek_areas = SOBEK-Areas +measurements = Measurements +floodmarks = Flood Marks +pegel_had_measurement_points = HAD Discharge-Measurement points +# No translation for the pegelonline wms service layer names. +gauge_points = Pegelpunkte (WSV) +gauge_level = Aktueller Wasserstand (WSV) +gauge_names = Pegelnamen (WSV) +gauge_tendency = Tendenz des Wasserstands (WSV) + +startcolor = Colorrange start color +endcolor = Colorrange end color +numclasses = Number of classes + +# capabilities information panel +addwmsInputTitle = Base URL of WMS service +addwmsInfoTitle = Information about WMS service +addwmsLayerTitle = Choose Layer +addwmsBack = Back +addwmsContinue = Continue +addwmsCancel = Cancel +addwmsInvalidURL = The URL is not valid. +capabilitiesHint = Please notice the information of the WMS service. +capabilitiesTitle = Title +capabilitiesURL = URL +capabilitiesAccessConstraints = Access Constraints +capabilitiesFees = Fees +capabilitiesContactInformation = Further Information +capabilitiesEmail = Email +capabilitiesPhone = Phone + +#Properties dialog +chart = Chart +export = Export +width = Width +height = Height +visibility = Visibility +upper = to +lower = from +fixation = Fix +font_size = Fontsize +label = Title +title = Title +subtitle = Subtitle +display_grid = Display grid +display_logo = Display logo +logo_placeh = Horiz. Place for logo +logo_placev = Vertic. Place for logo +top = top +bottom = bottom +center = center +left = left +right = right +none = none + +notselected = none + +linetype = Linetype +textstyle = Textstyle +linecolor = Linecolor +showhorizontalline = Show horizonal line +showverticalline = Show vertical line +textcolor = Textcolor +textsize = Textsize +font = Font +showpoints = Show points +showbackground = Show background +textshowbg = Show background +backgroundcolor = Backgroundcolor +bandwidthcolor = Bandwidthcolor +textbgcolor = Backgroundcolor +textorientation = Textorientation +linesize = Linesize +pointsize = Pointsize +bandwidth = Bandwidth +pointcolor = Punktfarbe +showlines = Show lines +showlinelabel = Show line label +showpointlabel = Show point label +labelfontface = Label: Font +labelfontcolor = Label: Color +labelfontsize = Label: Size +labelfontstyle = Label: Style +labelbgcolor = Label: Background Color +labelshowbg = Label: Show Background +horizontal = horizontal +vertical = vertical +showwidth = Show width +showlevel = Show waterlevel +showminimum = Show minimum +showmaximum = Show maximum +showborder = Show line +transparent = Transparency +transparency = Transparency +showarea = Show area +showarealabel = Show area label +showmiddleheight = Show middle depth +fillcolor = Fill Color +areabgcolor = Fill Color +areashowborder = Show area border +areashowbg = Show area background +areabordercolor = Border color +areatransparency = Tranparency +wsplgen_cat1 = Fill Color 0.0 <= DIFF < 1 +wsplgen_cat2 = Fill Color 1.0 <= DIFF < 2 +wsplgen_cat3 = Fill Color 2.0 <= DIFF < 3 +wsplgen_cat4 = Fill Color 3.0 <= DIFF < 4 +wsplgen_cat5 = Fill Color 4.0 <= DIFF +attribution = ©Intevation GmbH 2013<br>Data ©<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> +wmsURLMenuItem = WMS URL +wmsURLBoxTitle = Layer WMS URL +requireTheme = You need to choose a Layer. + +# Manual Points Editor +addpoints = Add points +pointname = Name +removepoint = Remove +newpoint = New Point +standby = Creating Artifact ... please wait. +points = Points +editpoints = Edit Points +addWSPButton = Add Manual LS +addWSP = Add Manual LS +selection = Selection + +# Reference Curves +reference_curve = Reference Curve +reference_curve_normalized = Reduced Reference Curve +reference_startpoint = Point of reference +reference_endpoint = Point(s) of projection + +fix_deltawt_export = \u0394 W/t +select=Selected +add_date=Add + +fix_parameters_export = Adjusted coefficient +fix_parameters = CSV + +sq_overview=Overview + +gauge_zero = GZG +gauge_q_unit = m\u00b3/s +gauge_river_info_link = Riverinfo +gauge_info_link = Gaugeinfo +gauge_url = https://flys-intern.intevation.de/PegelInfo/ +gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ +gauge_curve_link = Dischargecurve/-table +discharge_timeranges = DC-Timeranges +discharge_chart = W/Q-Preview + +measurement_station_type = Type of Measurement Station +measurement_station_operator = Operator +measurement_station_start_time = Observation Start Time +measurement_station_url = https://flys-intern.intevation.de/MessstellenInfo/ +measurement_station_info_link = Measurement Station Info +measurement_station_gauge_name = Reference Gauge + +# The prefix is used to classify them and will be stripped +# If the payload part sarts with a number it will be sorted +# By this number and the number will be stripped. +# Number must be a single digit 0-9. This hack was made necessary +# by the usage of an attribute table in mapfish + +mapfish_data_range = mapfish_data_3Range +mapfish_data_subtitle = mapfish_data_0Subtitle +mapfish_data_strech = mapfish_data_2Stretch +mapfish_data_institution = mapfish_data_5Institution +mapfish_data_source = mapfish_data_6Source +mapfish_data_creator = mapfish_data_5Creator +mapfish_data_dateplace = mapfish_data_7Place, Date +mapfish_data_river = mapfish_data_1River + +mapTitle = Title +mapSubtitle = Subtitle +mapRange = Range +mapStretch = Stretch +mapCreator = Creator +mapInstitution = Institution +mapSource = Source +mapDate = Place, Date +mapLogo = Logo + +# Get Feature Info Window +PATH = Path
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,667 @@ +fullname = Flusshydrologische Software +user = Benutzer: +guest = Gast +logout = Abmelden +projects = Projekte +open_project = Projekt \u00f6ffnen +delete_project = Projekt l\u00f6schen +rename_project = Projekt umbenennen +clone_project = Projekt duplizieren +copy_of = Kopie +manage_projects = Projekte verwalten +favorite_tooltip = Dauerhaft speichern? +favorite_tooltip_meaning = Goldener Stern: gespeichert +projectlist_creationTime = Anlegezeitpunkt +projectlist_title = Titel +projectlist_favorite = Dauerhaft +projectlist_close = Schlie\u1E9Een +really_delete = Wollen Sie dieses Projekt wirklich l\u00f6schen? +project_name_too_long = Der eingegebene Projektname ist zu lang. Die maximale L\u00e4nge betr\u00e4gt $LEN Zeichen. +switch_language = Englisch +info = Info +warning = Achtung +warning_language = Das \u00c4ndern der Sprache startet eine neue Sitzung des Programms. Alle offenen Fenster werden geschlossen. +no_projects = Keine alten Berechnungen gefunden. +load_projects = Lade Berechnungen... +empty_table = Lade Daten... +empty_filter = Keine Daten gefunden. +date_format = dd.MM.yyyy +datetime_format = dd.MM.yyyy HH:mm +new_project = Neues Projekt +new_calculation = Neue Berechnung +module_selection = Modul +river_selection = Gew\u00e4sser +winfo = W-INFO +minfo = M-INFO +map = Karte +new_map = Neue Karte +new_chart = Neues Diagramm +diagram = Diagramm +axes = Achsen +legend = Legende +chart_title = Titel +chart_subtitle = Untertitel +grid = Gitternetz +antialiasing = Kantengl\u00e4ttung +axis_name = Name +chart_start = von +chart_end = bis +x_axis = X-Achse +y1_axis = Y1-Achse +y2_axis = Y2-Achse +y3_axis = Y3-Achse +legend_name = Name +show_legend = Anzeigen +aggregation_threshold = Schwellwert zur Aggregation von Legendeneintr\u00e4gen +scale = Skalierung +databasket = Datenkorb +databasket_loading=Lade Datenkorb Inhalt +fix = Fixierungsanalyse +fixanalysis = Fixierungsanalyse +next = Weiter +location_distance_state = Berechnungsort(e) / strecke w\u00e4hlen [km] +distance_state = Berechnungsstrecke w\u00e4hlen [km] +waterlevel_ground_state = Differenzen zwischen Wasserspiegel und Gel\u00e4nde [m] +location = Ort(e) +locations = Orte +single_location = Ort +distance = Strecke +unitFrom = km - +unitTo = km a +unitWidth = m +search = Suchbegriff +discharge = Kennzeichnender Abfluss +properties = Eigenschaften +activateTheme = Aktivieren +deactivateTheme = Deaktivieren +removeTheme = Entfernen +manageThemes = Themen verwalten +label_ok = Ok +label_cancel = Abbrechen +cancelCalculationLabel = Aktuelle Berechnung abbrechen. +calculationCanceled = Die Berechnung wurde abgebrochen. +range = Bereich +resultCount = Treffer +start_year = Start +end_year = Ende +period = Zeitraum +year = Jahr +sedimentload_ls = Sediment Fracht +welcome = Willkommen bei der Flusshydrologischen Software +welcome_open_or_create = Bitte \u00f6ffnen Sie ein bestehendes Projekt aus der Projektliste oder erstellen Sie ein + +# Header images +flysLogo = images/flys_logo.gif +bfgLogo = images/bfg_logo.gif +bfgLogoSmall = images/bfg_logo_small.png + +# Images +downloadPNG = images/png_export.png +downloadPDF = images/pdf_export.png +downloadSVG = images/svg_export.png +downloadCSV = images/save_csv.png +downloadAT = images/save_at.png +downloadWST = images/save_wst.png +loadingImg = images/loading.gif +cancelCalculation = images/cancelCalculation.png +markerRed = images/marker_red.png +markerGreen = images/marker_green.png +riverMap = images/FLYS_Karte.png +properties_ico = images/properties.png + +dpLabelFrom = von +dpUnitFrom = km +dpLabelTo = bis +dpUnitTo = km +dpLabelStep = a +dpUnitStep = m + +wgLabelFrom = Von +wgUnitFrom = m +wgLabelTo = Bis +wgUnitTo = m +wgLabelStep = a +wgUnitStep = m + +unitFromInM = Von [m]: +unitToInM = Bis [m]: +unitDiffInM = Diff [m]: +unitLocation = km +wrongFormat = Falsches Format +atLeastOneValue = Sie m\u00fcssen mindestens einen Wert eingeben. +missingInput = Sie m\u00fcssen einen Wert eingeben. +too_many_values = Nur ein Eingabewert erlaubt + +description = Beschreibung +from = von +to = bis +bottom_edge = Unterkante +top_edge = Oberkante +riverside = Flussseite +name = Name +type = Typ +wq_waterlevel_label = Kennzeichnender Wassterstand +wq_table_w = Kennzeichnende Wasserst\u00e4nde +wq_table_q = Kennzeichnende Abfl\u00fcsse / Dauerzahlen +wq_value_w = W [cm am Pegel] +wq_value_q = Q [m\u00b3/s] +river_km = Fluss-Km +uesk_profile_distance = Abstand [m] + +wqTitle = Eingabe f\u00fcr W/Q Daten +wqadaptedTitle = Eingabe f\u00fcr W/Q Daten +wqHistorical = Auswahl der Analyseart +calcTableTitle = Ergebnisausgabe +helperPanelTitle = Eingabeunterst\u00fctzung +gaugePanelTitle = Gew\u00e4sser/Pegel-Info +measurementStationPanelTitle = Gew\u00e4sser/Messstellen-Info +wqW = W am Pegel [cm] +wqQ = Q [m\u00b3/s] +wqQatGauge = Q am Pegel [m\u00b3/s] +wqWFree = W auf freier Strecke [m+NHN] +wqQGauge = Kennzeichnender Abfluss am Pegel +wqSingle = Einzelwerte +wqRange = Wertebereich +unitWNN = W [NN+m] +unitWSingle = cm +unitWFrom = cm - +unitWTo = cm a +unitWStep = cm +unitQSingle = m\u00b3/s +unitQFrom = m\u00b3/s - +unitQTo = m\u00b3/s a +unitQStep = m\u00b3/s +main_channel = Hauptgerinne +total_channel = Gesamtgerinne +footerHome = Home +footerContact = Kontakt +footerImpressum = Impressum +print = Drucken +printWindowTitle = PDF-Druckeinstellungen + +projectListMin = format-indent-less.png +projectListAdd = list-add.png +buttonNext = \u00dcbernehmen +imageBack = images/back_de.png +imageSave = images/save.png +theme_top = images/go-first.png +theme_up = images/go-up.png +theme_down = images/go-down.png +theme_bottom = images/go-bottom.png +zoom_all = images/mag_100.png +zoom_in = images/mag_zoom_box.png +zoom_out = images/mag_zoom_minus.png +zoom_back = images/mag_zoom_back.png +pan = images/hand.png +askThemeRemove = Sind Sie sicher, dass sie die gew\u00e4hlten / das gew\u00e4lte Thema l\u00f6eschen wollen? +add = Hinzuf\u00fcgen + +addPointsTooltip = Manuelle Punkte hinzuf\u00fcgen +addWSPTooltip = Manuelle WSP hinzuf\u00fcgen +downloadPNGTooltip = Diagramm als PNG herunterladen +downloadPDFTooltip = Diagramm als PDF herunterladen +downloadSVGTooltip = Diagramm als SVG herunterladen +downloadCSVTooltip = Daten als CSV herunterladen +zoomToMaxExtentTooltip = Auf maximale Ausdehnung zoomen +zoomOutTooltip = Herauszoomen +historyBackTooltip = Voriger Zoom +panControlTooltip = Verschieben +zoomboxTooltip = Ausschnitt vergr\u00f6\u00dfern +chartPropertiesTooltip = Diagrammeigenschaften +printTooltip = Drucken + +static_sqrelation = Transport-Abfluss Beziehung +discharge_curve = Abflusskurve am Pegel +discharge_curve_gaugeless = Abflusskurve +gauge_discharge_curve = Abflusstafel am Pegel +computed_discharge_curve = Abflusskurve +computed_discharge_curves = Abflusskurven +longitudinal_section = L\u00e4ngsschnitt +duration_curve = Dauerlinie +discharge_longitudinal_section = W f\u00fcr benutzerdefinierten Abflussl\u00e4ngsschnitt +floodmap = \u00dcberschwemmungsfl\u00e4che +historical_discharge = Zeit-Diagramm +historical_discharge_wq = W/Q-Diagramm +flow_velocity = Flie\u00dfgeschwindigkeiten +flow_velocity_export = Flie\u00dfgeschwindigkeiten Export +bedheight_middle = Mittlere Sohlh\u00f6he +bedheight_middle_export = Mittlere Sohlh\u00f6he Export +bed_longitudinal_section = Sohlbeschaffenheit +bed_longitudinal_section_export = Sohlbeschaffenheit Export +sq_relation_a = A Feinkornanteil +sq_relation_b = B Sand (Suspensionstransport) +sq_relation_c = C Sand (Geschiebetransport) +sq_relation_d = D Fein- und Mittelkies +sq_relation_e = E Grobkornanteil (> Mittelkies) +sq_relation_f = F Geschiebetransport Gesamt +sq_relation_export = SQ Export +cross_section = Querprofil +cross_sections = Querprofile +w_differences = Differenzen +w_differences_export = Differenzen Export +reference_curve_export = Bezugslinien Export +historical_discharge_export = Historische Abflusskurven Export +showextramark = Zeige Anfang der Extrapolation +extreme_wq_curve = W/Q +fix_wq_curve = W/Q-Diagramm +fix_deltawt_curve = \u0394 W/t +fix_longitudinal_section_curve = L\u00e4ngsschnitt +fix_derivate_curve = Ableitungskurve +fix_vollmer_wq_curve = W/Q-Diagramm +datacage_add_pair = Differenzenpaar hinzuf\u00fcgen +load_diameter = Geschiebedurchmesser +bed_diameter = Sohldurchmesser +soundings = Peilungen +soundings_width = Gepeilte Breite +bed_difference_year = Sohlh\u00f6hendifferenz (Jahr) +bed_difference_epoch = Sohlh\u00f6hendifferenz (Epoche) +bed_difference_height_year = Sohlh\u00f6hendifferenz pro Jahr + +waterlevel_export = Wasserstand/Wasserspiegellagen Export +waterlevel_report = Wasserstand/Wasserspiegellagen Bericht +computed_dischargecurve_export = Abflusskurven Export +computed_dischargecurve_report = Abflusskurven Bericht +discharge_longitudinal_section_export = Abflussl\u00e4ngsschnitt Export +discharge_longitudinal_section_report = Abflussl\u00e4ngsschnitt Bericht +durationcurve_export = Dauerzahlen Export +durationcurve_report = Dauerzahlen Bereicht +dataexport = Datenexport +csv = CSV +wst = WST +at = AT +pdf = PDF +computed_dischargecurve_at_export = AT Export +gauge_discharge_curve_at_export = Abflusskurve am Pegel +gauge_class = Abflussklasse +eventselect = Ereignisauswahl +events = Ereignisse +kmchart = W/Q-Vorschau + +exportATTooltip = Daten als AT Datei exportieren + +chart_themepanel_header_themes = Thema +chart_themepanel_header_actions = Aktionen +chart_themepanel_synchron = Synchron navigieren +chart_themepanel_asynchron = Einzeln navigieren +chart_themepanel_set_master = Referenz +chart_themepanel_new_area = Erzeuge Fl\u00e4che ... +chart_themepanel_area_under = unter ... +chart_themepanel_area_over = \u00fcber ... +chart_themepanel_area_between = zwischen ... +against_x_axis = \u00fcber X-Achse + +gauge_mnq = um MNQ +gauge_mq = um MQ +gauge_mhq = um MHQ +gauge_hq5 = \u00fcber HQ5 + +ele_window_title = H\u00f6henknoten setzen +ele_window_label = H\u00f6henangaben in m \u00fc. NN. +ele_window_x_col = X +ele_window_y_col = Y +ele_window_z_col = Z-Koordinate +ele_window_ok_button = H\u00f6he setzen +ele_window_cancel_button = Abbrechen +ele_window_format_error = Die von Ihnen eigegebene H\u00f6he ist ung\u00fcltig: +ele_window_save_error = Fehler beim Speichern der H\u00f6hen. +ele_window_geometry_error = Die Geometrie wird nicht unterst\u00fctzt: + +unexpected_exception = Ein unerwarteter Fehler ist aufgetreten +error_years_wrong = Das zweite Jahr muss gr\u00f6\u00dfer als das erste sein. +error_read_minmax_values = Fehler beim Lesen der min/max Werte. Es kann keine Validierung der eingegebenen Strecke durchgef\u00fchrt werden. +error_validate_range = Der Wert $1 muss kleiner als $3 und gr\u00f6\u00dfer als $2 sein. +error_validate_date_range = Anfangsdatum muss fr\u00fcher sein als Enddatum. +error_validate_date_range_invalid = Der eingegebene Zeitbereich ist ung\u00fcltig. +error_validate_lower_range = Der untere Wert $1 muss gr\u00f6\u00dfer sein als $2. +error_validate_upper_range = Der obere Wert $1 muss kleiner sein als $2. +error_empty_state = Es wurden nicht alle ben\u00d6tigten Daten eingegeben. +error_invalid_double_value = Falsches Format f\u00fc eine Flie\u00dfkommazahl. +error_create_artifact = Fehler beim Erstellen eines neuen Projekts. +error_describe_artifact = Fehler beim Laden der Parametrisierung. +error_feed_data = Fehler beim Hinzuf\u00fcgen neuer Daten. +error_advance_artifact = Fehler beim Wechseln des Zustands des Projektes. +error_add_artifact = Fehler beim Hinzuf\u00fcgen einer Parametrisierung. +error_remove_artifact = Fehler beim Entfernen einer Parametrisierung. +error_create_collection = Fehler beim Erstellen eines neuen Projektes. +error_describe_collection = Fehler beim Laden des Projektzustandes. +error_no_rivers_found = Fehler beim Lesen der unterst\u00fctzten Fl\u00fcsse. +error_no_such_user = Fehler - Kein solcher Benutzer vorhanden. +error_no_users = Fehler - Keine Benutzer vorhanden. +error_no_waterlevel_pair_selected = Fehler - kein Paar zur Differenzenbildung gew\u00e4hlt. +error_same_waterlevels_in_pair = Error - minuend and subtrahend m\u00fcssen sich unterscheiden. +error_not_logged_in = Sie m\u00fcssen sich erst einloggen um mit der Arbeit beginnen zu k\u00f6nnen. +error_load_parameterization = Fehler beim Laden der Parametrisierung. +error_wrong_date = Bitte geben Sie gültige Daten ein. +error_no_gaugeoverviewinfo_found = Fehler beim Laden der Fluss- und Pegelinformationen + +error_feed_no_data = Keine Eingabedaten gefunden. +error_feed_from_out_of_range = Der untere Wert liegt au\u00dferhalb des g\u00fcltigen Wertebereiches. +error_feed_to_out_of_range = Der obere Wert liegt au\u00dferhalb des g\u00fcltigen Wertebereiches. +error_feed_from_bigger_to = Der untere Wert ist gr\u00f6\u00dfer als der obere Wert. +error_feed_invalid_wq_mode = Ung\u00fcltiger Modus f\u00fcr die WQ-Eingabe gew\u00e4hlt. +error_feed_number_format_float = Der eingegebene Wert ist keine Flie\u00dfkommazahl. +error_feed_invalid_calculation_mode = Die gew\u00e4hlte Berechnungsart ist ung\u00fcltig. +error_feed_no_calculation_mode = Es ist keine Berechnungsart gew\u00e4hlt. +error_feed_no_such_river = Der gew\u00e4hlte Fluss wird nicht unterst\u00fctzt. +error_feed_no_river_selected = Es wurde kein Fluss gew\u00e4hlt. +error_feed_no_wq_mode_selected = Es ist kein W/Q Modus gew\u00e4hlt. +error_feed_q_values_invalid = Die gew\u00e4hlten Q Werte liegen au\u00dferhalb des g\u00fcltigen Bereiches. +error_feed_w_values_invalid = Die gew\u00e4hlten W Werte liegen au\u00dferhalb des g\u00fcltigen Bereiches. +error_chart_info_service = Meta Informationen des Diagramms konnten nicht geladen werden. +error_no_meta_data_found = Keine Meta-Daten gefunden. +error_load_artifact = Fehler beim Hinzu\u00fcgen neuer Daten in das aktuelle Projekt. +error_no_calc_result=Es wurden keine Berechnungsergebnisse gefunden. +error_no_theme_styles_found=Es konnten keine Stile f\u00fcr das gew\u00e4hlte Thema gefunden werden. +error_no_feature_selected = Kein Objekt ausgew\u00e4hlt. +error_no_map_config = Es konnte keine Kartenkonfiguration gefunden werden. +error_no_map_output_type = Es konnte kein Ausgabemodus f\u00fcr Karten gefunden werden. +error_no_valid_gfi_url = Ung\u00fcltige GetFeatureInfo URL. +error_gfi_req_failed = Die GetFeatureInfo Anfrage ist fehlgeschlagen. +error_gfi_parsing_failed = Fehler beim Lesen der GetFeatureInfo Antwort. +error_gc_req_failed = Fehler beim Laden des Capabilities Dokuments. +error_gc_doc_not_valid = Das Capabilities Dokument ist nicht valide. +error_malformed_url = Die eingegebene URL ist ung\u00fcltig. +error_no_dgm_selected = Sie haben kein DGM gew\u00e4hlt. +error_invalid_dgm_selected = Sie haben ein falsches DGM gew\u00e4hlt. +error_bad_dgm_range = Das gew\u00e4hlte DGM passt nicht zur gew\u00e4hlten Berechnungsstrecke. +error_bad_dgm_river = Das gew\u00e4hlte DGM passt nicht zum gew\u00e4hlten Fluss. +error_dialog_not_valid = Eine oder mehrere Daten sind nicht korrekt. +error_invalid_date = Das eingegebene Datum ist nicht korrekt. +error_same_location = Der gew\u00e4hlte Ort ist der Bezugsort. +error_contains_same_location = Zielorte beinhalten den Bezugsort. +error_update_collection_attribute = Fehler beim Aktualisieren des Collection-Attributs. +error_values_needed = Es muss mindestens ein Wert selektiert sein. +error_no_module_found = Keine nutzbaren Module gefunden. + +warning_use_first_feature = Sie haben mehr als ein Objekt ausgew\u00e4hlt. Das erste Objekt wird benutzt. +warning_no_wsp_selected = Kein Wasserstand ausgew\u00e4hlt! +warning_cannot_parse_date = Datum ist ung\u00fcltig! +warning_select_two_values = Bitte zwei Werte w\u00e4hlen! + +## map related strings +digitize = images/digitize.png +pipe1 = Rohr1 +pipe2 = Rohr2 +ditch = Graben +dam = Damm +ring_dike = Ringdeich +selectFeature = images/selectFeature.png +removeFeature = images/removeFeature.png +getFeatureInfo = images/info.png +getFeatureInfoTooltip = Informationswerkzeug +getFeatureInfoWindowTitle = Information zur Kartenebene: +addWMS = images/add_map.png +printMapSettings = images/print_map_settings.png +addWMSTooltip = Laden von Kartenebenen eines externen WMS Dienstes. +adjustElevation = images/adjustElevation.png +measureLine = images/measure_line.png +measurePolygon = images/measure_plane.png +step = Schritt +calculationStarted = Berechnung wurde gestarted. +zoomMaxExtent = Gesamtausschnitt +zoomIn = Hereinzoomen +zoomOut = Herauszoomen +zoomLayer = Zoom auf Layer +moveMap = Verschieben +digitizeObjects = Erstellung von Rohren, Gr\u00e4ben, D\u00e4mmen und Ringdeichen +selectObject = Auswahlwerkzeug +removeObject = Ausgew\u00e4hltes Objekt l\u00f6schen +adjustElevationTooltip = Festlegen von H\u00f6hen f\u00fcr D\u00e4mme, Ringeiche, Gr\u00e4ben und Rohre +measureDistance = L\u00e4ngenmessung +measureArea = Fl\u00e4chenmessung +map_themepanel_header_style = Stil +zoomToLayer = Layer-Zoom +requireDGM = Sie m\u00fcssen ein DGM ausw\u00e4hlen. +upload_file = hochladen +shape_file_upload = Shapedatei hochladen +attribution = ©Intevation GmbH 2013<br>Data ©<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> +wmsURLMenuItem = WMS URL +wmsURLBoxTitle = WMS URL der Kartenebene +requireTheme = Sie m\u00fcssen ein Thema ausw\u00e4hlen. + +# data cage +waterlevels = Wasserst\u00e4nde +old_calculations = Fr\u00fchere Berechnungen +officiallines = Amtliche Linien +datacageAdd = Daten laden +heightmarks = Hochwassermarken +basedata = Basis-Daten +fixations = Fixierungen +flood_protections = HW-Schutzanlagen +columns = Spalten +annotation = Streckenfavoriten +annotation = Streckenfavoriten - Typen +annotations = Streckenfavoriten +all_annotations = Alle Streckenfavoriten +flowvelocitymeasurement = gemessene Flie\u00dfgeschwindigkeiten +bed_quality_bed = Sohlbeschaffenheit - Sohle +bed_quality_load = Sohlbeschaffenheit - Geschiebe +additionals = Zus\u00e4tzliche L\u00e4ngsschnitte +differences = Differenzen +kilometrage = Stationierung +riveraxis = Flussachse +km = Km +qps = Querprofilspuren +hws = Hochwasserschutzanlagen +catchments = Einzugsgebiete +catchment_wms = Einzugsgebiete (WMS) +floodplain = Talaue +lines = Darstellungstyp: Linien +buildings = Bauwerke +fixpoints = Festpunkte +uesk = \u00dcberschwemmungsfl\u00e4chen +calculations = Berechnungen +current = Aktuell +potential = Potenziell +bfg = BfG +land = Land +rastermap = Rasterkarte +background = Hintergrundkarte (WMS) +discharge_tables_chart = W/Q-Vorschau +discharge_table_nn = Abflusstafeln am Pegel +discharge_table_gauge = Abflusstafel am Pegel +mainvalue = Hauptwerte +mainvalues = Hauptwerte +wmainvalue = Hauptwerte (W) +qmainvalue = Hauptwerte (Q) +show_mainvalues = Hauptwerte anzeigen +dems = Digitale Gel\u00e4ndemodelle +hydrboundaries = Hydrologische Grenzen +gaugelocations = PEGELONLINE aktuell (WMS) +single = Jahr +epoch = Epoche +bedheights = Sohlh\u00f6hen +morph_width = Morphologische Breite +datacage = Datenkorb +official = Offiziell +inofficial = Inoffiziell +custom_lines = Eigene Digitalisierungen +hws_lines = Liniendaten +hws_points = Punktdaten +hws_fed_unknown = Unbekanntes Bundesland +jetties = Buhnen +route_data = Streckendaten +other = Sonstige +axis = Achse +bfg_model = BfG-Modell +federal = Bundesländer +areas = Darstellungstyp: Flächen +sobek_flooded = SOBEK-Grenzlinie durchflutet / nicht durchflutet +sobek_areas = SOBEK-Bereiche +measurements = Messungen +floodmarks = HW-Marken +pegel_had_measurement_points = HAD Abflussmessstellen (WMS) +gauge_points = Pegelmessstelle (WMS) +gauge_level = Wasserstand (WMS) +gauge_names = Pegelname (WMS) +gauge_tendency = Tendenz des Wasserstands (WMS) + +startcolor = Farbverlauf Startfarbe +endcolor = Farbverlauf Endfarbe +numclasses = Anzahl Klassen + +# capabilities information panel +addwmsInputTitle = Basis URL des WMS Dienstes +addwmsInfoTitle = Informationen des WMS Dienstes +addwmsLayerTitle = Ebene ausw\u00e4hlen +addwmsBack = Zur\u00fcck +addwmsContinue = Weiter +addwmsCancel = Abbrechen +addwmsInvalidURL = Die URL ist nicht g\u00fcltig. +capabilitiesHint = Bitte beachten Sie die folgenden Informationen des WMS-Dienstes. +capabilitiesTitle = Titel +capabilitiesURL = URL +capabilitiesAccessConstraints = Nutzungsbedingungen +capabilitiesFees = Geb\u00fchren +capabilitiesContactInformation = Weitere Informationen +capabilitiesEmail = Email +capabilitiesPhone = Telefon + +#Property dialog +chart = Diagramm +export = Export +width = Breite +height = H\u00f6he +visibility = Sichtbarkeit +upper = bis +lower = von +fixation = Fix +font_size = Schriftgr\u00f6\u00dfe +label = Titel +title = Titel +subtitle = Untertitel +display_grid = Gitterlinien anzeigen +display_logo = Logo anzeigen +logo_placeh = Horizontale Ausrichtung Logo +logo_placev = Vertikale Ausrichtung Logo +top = oben +bottom = unten +center = mittig +left = links +right = rechts +none = keines + +notselected = keine + +linetype = Linientyp +textstyle = Textstil +linecolor = Linienfarbe +showhorizontalline = Horizontale Linie +showverticalline = Vertikale Linie +textcolor = Textfarbe +textsize = Textgr\u00f6\u00dfe +font = Schriftart +showpoints = Punkte anzeigen +showbackground = Hintergrund anzeigen +textshowbg = Hintergrund anzeigen +backgroundcolor = Hintergrundfarbe +bandwidthcolor = Bandbreitenfarbe +textbgcolor = Hintergrundfarbe +textorientation = Textausrichtung +linesize = Liniendicke +pointsize = Punktdicke +bandwidth = Bandbreite +pointcolor = Punktfarbe +showlines = Linien anzeigen +showlinelabel = Linienbeschriftung anzeigen +showpointlabel = Punktbeschriftung anzeigen +labelfontface = Beschriftung: Schriftart +labelfontcolor = Beschriftung: Schriftfarbe +labelfontsize = Beschriftung: Schriftgr\u00f6\u00dfe +labelfontstyle = Beschriftung: Schriftstil +labelbgcolor = Beschriftung: Hintergrundfarbe +labelshowbg = Beschriftung: Hintergrund f\u00fcllen +horizontal = horizontal +vertical = vertikal +showwidth = Breite anzeigen +showlevel = Wasserstand anzeigen +showminimum = Minimum anzeigen +showmaximum = Maximum anzeigen +showborder = Linie anzeigen +transparent = Transparent +transparency = Transparenz +showarea = Show area +showarealabel = Fl\u00e4che beschriften +showmiddleheight = Mittlere Tiefe anzeigen +fillcolor = F\u00fcllfarbe +areabgcolor = F\u00fcllfarbe +areashowborder = Fl\u00e4chenumrandung +areashowbg = Fl\u00e4chenhintergrund +areabordercolor = Umrandungsfarbe +areatransparency = Tranparenz +wsplgen_cat1 = F\u00fcllfarbe 0.0 <= DIFF < 1 +wsplgen_cat2 = F\u00fcllfarbe 1.0 <= DIFF < 2 +wsplgen_cat3 = F\u00fcllfarbe 2.0 <= DIFF < 3 +wsplgen_cat4 = F\u00fcllfarbe 3.0 <= DIFF < 4 +wsplgen_cat5 = F\u00fcllfarbe 4.0 <= DIFF + +# Manual Points Editor +addpoints = Punkte hinzuf\u00fcgen +pointname = Bezeichner +removepoint = Entfernen +newpoint = Neuer Punkt +standby = Erstelle Parameterisierung ... bitte warten. +points = Punktthema +editpoints = Eintr\u00e4ge editieren +addWSP = Neues WSP Thema anlegen +addWSPButton = WSP Thema +selection = Auswahl + +# Reference Curves +reference_curve = Bezugslinie +reference_curve_normalized = Reduzierte Bezugslinie +reference_startpoint = Bezugsort/pegel +reference_endpoint = Zielort/pegel + +fix_deltawt_export = \u0394 W/t +select=Ausgewählt +add_date=Hinzuf\u00fcgen + +fix_parameters_export = Angepasste Koeffizienten +fix_parameters = CSV +sq_overview=\u00dcbersicht + +gauge_zero = PNP +gauge_q_unit = m\u00b3/s +gauge_river_info_link = Gew\u00e4sserinfo +gauge_info_link = Pegelinfo +gauge_url = https://flys-intern.intevation.de/PegelInfo/ +gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ +gauge_curve_link = Abflusskurve/-tafel +discharge_timeranges = AK-Zeitr\u00e4ume +discharge_chart = W/Q-Vorschau + +measurement_station_type = Messstellenart +measurement_station_operator = Betreiber +measurement_station_start_time = Beginn der Aufzeichnung +measurement_station_url = https://flys-intern.intevation.de/MessstellenInfo/ +measurement_station_info_link = Messstelleninfo +measurement_station_gauge_name = hydrologischer Bezugspegel + +# The prefix is used to classify them and will be stripped +# If the payload part sarts with a number it will be sorted +# By this number and the number will be stripped. +# Number must be a single digit 0-9. This hack was made necessary +# by the usage of an attribute table in mapfish + +mapfish_data_range = mapfish_data_3Bereich +mapfish_data_subtitle = mapfish_data_0Untertitel +mapfish_data_strech = mapfish_data_2Strecke +mapfish_data_institution = mapfish_data_5Institution +mapfish_data_source = mapfish_data_6Datenquelle +mapfish_data_creator = mapfish_data_4Bearbeiter +mapfish_data_dateplace = mapfish_data_7Ort, Datum +mapfish_data_river = mapfish_data_1Gew\u00e4sser + +mapTitle = Titel +mapSubtitle = Untertitel +mapRange = Bereich +mapStretch = Strecke +mapCreator = Bearbeiter +mapInstitution = Institution +mapSource = Datenquelle +mapDate = Ort, Datum +mapLogo = Logo + +# Get Feature Info Window +PATH = Dateipfad
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,618 @@ +fullname = Flusshydrologische Software +user = User: +guest = guest +logout = Logout +projects = Projects +open_project = Open Project +delete_project = Delete Project +rename_project = Rename Project +clone_project = Clone Project +copy_of = Copy +manage_projects = Manage Projects +favorite_tooltip = Permanently store? +favorite_tooltip_meaning = Golden star: stored +projectlist_creationTime = Creation time +projectlist_title = Title +projectlist_favorite = Permanent +projectlist_close = Close +really_delete = Do you really want to delete this project? +project_name_too_long = The entered project name is too long. Max length is $LEN characters. +switch_language = German +info = Info +warning = Attention +warning_language = Choosing a new language starts a new session. All open windows will be closed. +no_projects = No existing calculations found. +load_projects = Load calculations... +empty_table = Loading data... +empty_filter = No data found. +date_format = yyyy-MM-dd +datetime_format = yyyy-MM-dd HH:mm +new_project = New Project +new_calculation = New Calculation +module_selection = Module +river_selection = Rivers +winfo = WINFO +minfo = MINFO +map = Map +new_map = New Map +new_chart = New Chart +diagram = Chart +axes = Axes +legend = Legend +chart_title = Title +chart_subtitle = Subtitle +grid = Grid +antialiasing = Antialiasing +axis_name = Name +chart_start = Start +chart_end = End +x_axis = X-Axis +y1_axis = Y1-Axis +y2_axis = Y2-Axis +y3_axis = Y3-Axis +legend_name = Name +show_legend = Show +aggregation_threshold = Threshold for aggregation of legend entries +scale = Scale +databasket = Databasket +databasket_loading = Loading Databasket content +fix = Fixing +fixanalysis = Fixing Analysis +next = Next +location_distance_state = Choose calculation location(s) / range [km] +distance_state = Choose calculation range [km] +waterlevel_ground_state = Choose differences betweeen waterlevel and ground [m] +location = Location(s) +locations = Locations +single_location = Location +distance = Range +unitFrom = km +unitTo = km a +unitWidth = m +search = Search +discharge = FIXME(Name) +properties = Properties +activateTheme = Activate +deactivateTheme = Deactivate +removeTheme = Remove +manageThemes = Manage themes +label_ok = Ok +label_cancel = Cancel +cancelCalculationLabel = Stop the current calculation. +calculationCanceled = The calculation has been canceled. +range = Range +resultCount = Hits +start_year = Start +end_year = end +period = Period +year = Year +sedimentload_ls = Sediment Load +welcome = Welcome to Flusshydrologische Software +welcome_open_or_create = Please open a project from the project list or create a + +# Header images +flysLogo = images/flys_logo.gif +bfgLogo = images/bfg_logo.gif +bfgLogoSmall = images/bfg_logo_small.png + +# Images +downloadPNG = images/png_export.png +downloadPDF = images/pdf_export.png +downloadSVG = images/svg_export.png +downloadCSV = images/save.png +downloadAT = images/save_at.png +downloadWST = images/save_wst.png +loadingImg = images/loading.gif +loadingImg = images/loading.gif +cancelCalculation = images/cancelCalculation.png +markerRed = images/marker_red.png +markerGreen = images/marker_green.png +riverMap = images/FLYS_Karte.png +properties_ico = images/properties.png + +dpLabelFrom = from +dpUnitFrom = km +dpLabelTo = to +dpUnitTo = km +dpLabelStep = a +dpUnitStep = m + +wgLabelFrom = From +wgUnitFrom = m +wgLabelTo = To +wgUnitTo = m +wgLabelStep = a +wgUnitStep = m + +unitFromInM = From [m]: +unitToInM = To [m]: +unitDiffInM = Diff [m]: +unitLocation = km +wrongFormat = Wrong format +atLeastOneValue = You need to insert at least one value. +missingInput = You need to enter a value. +too_many_values = Only one value allowed + +addPointsTooltip = Add manual points +addWSPTooltip = Add manual LS +downloadPNGTooltip = Download chart as PNG +downloadPDFTooltip = Download chart as PDF +downloadSVGTooltip = Download chart as SVG +downloadCSVTooltip = Download data as CSV +zoomToMaxExtentTooltip = Zoom to max extent +zoomOutTooltip = Zoom out +historyBackTooltip = Previous zoom +panControlTooltip = Pan +zoomboxTooltip = Zoombox +chartPropertiesTooltip = Chartproperties + +description = Description +from = From +to = To +riverside = Riverside +bottom_edge = Bottom edge +top_edge = Top edge +name = Name +type = Type +wq_waterlevel_label = Characteristic Waterlevel +wq_table_w = Characteristic Waterlevels +wq_table_q = Characteristic Discharges / Durations +wq_value_w = W [cm at Gauge] +wq_value_q = Q [m\u00b3/s] +river_km = River-Km +uesk_profile_distance = Distance [m] + +wqTitle = Input for W/Q Data +wqadaptedTitle = Input for W/Q Data +wqHistorical = Selection of Analyse Type +calcTableTitle = Values +helperPanelTitle = Input Support +gaugePanelTitle = Gauge Information +measurementStationPanelTitle = Measurement Station Information +wqW = W at Gauge [cm] +wqQ = Q [m\u00b3/s] +wqQatGauge = Q at Gauge [m\u00b3/s] +wqWFree = W at free position [m+NHN] +wqQGauge = Discharge at Gauge +wqSingle = Single values +wqRange = Range +unitWNN = W [NN+m] +unitWSingle = cm +unitWFrom = cm - +unitWTo = cm a +unitWStep = cm +unitQSingle = m³/s +unitQFrom = m³/s - +unitQTo = m³/s a +unitQStep = m³/s +main_channel = Main Channel +total_channel = Total Channel +footerHome = Home +footerContact = Contact +footerImpressum = Legal info + +projectListMin = format-indent-less.png +projectListAdd = list-add.png +buttonNext = Next +imageBack = images/back_en.png +imageSave = images/save.png +theme_top = images/go-first.png +theme_up = images/go-up.png +theme_down = images/go-down.png +theme_bottom = images/go-bottom.png +zoom_all = images/mag_100.png +zoom_in = images/mag_zoom_box.png +zoom_out = images/mag_zoom_minus.png +zoom_back = images/mag_zoom_back.png +pan = images/hand.png +askThemeRemove = Are you sure that you want to remove the selected theme / themes? +add = Add + +static_sqrelation = SQ relation +discharge_curve = Discharge Curve at Gauge +discharge_curve_gaugeless = Discharge Curve +gauge_discharge_curve = Discharge Table at Gauge +computed_discharge_curve = Discharge Curve +computed_discharge_curves = Discharge Curves +longitudinal_section = Longitudinal Section Curve +duration_curve = Duration Curve +discharge_longitudinal_section = Discharge Longitudinal Section +floodmap = Floodmap +historical_discharge = Time Chart +historical_discharge_wq = W/Q Chart +flow_velocity = Flow Velocity +flow_velocity_export = Flow Velocity Export +bedheight_middle = Middle Bed Height +bedheight_middle_export = Middle Bed Height Export +bed_longitudinal_section = Bed Quality +bed_longitudinal_section_export = Bed Quality Export +sq_relation_a = A Feinkornanteil +sq_relation_b = B Sand (Suspensionstransport) +sq_relation_c = C Sand (Geschiebetransport) +sq_relation_d = D Fein- und Mittelkies +sq_relation_e = E Grobkornanteil (> Mittelkies) +sq_relation_f = F Geschiebetransport Gesamt +sq_relation_export = SQ Export +cross_section = Cross Section +cross_sections = Cross Sections +w_differences = Differences +w_differences_export = Differences Export +reference_curve_export = Reference Curve Export +historical_discharge_export = Historical Discharge Curve Export +showextramark = Show begin of extrapolation +extreme_wq_curve = W/Q +fix_wq_curve = W/Q-Diagram +fix_deltawt_curve = \u0394 W/t +fix_longitudinal_section_curve = Longitudinal Section +fix_derivate_curve = Derivate +fix_vollmer_wq_curve = W/Q-Diagram +datacage_add_pair = Add difference pair +load_diameter = Bedload Diameter +bed_diameter = Bed Diameter +soundings = Soundings +soundings_width = Soundings Width +bed_difference_year = Single Bedheight Differences +bed_difference_epoch = Epoch Bedheight Differences +bed_difference_height_year = Bedheight Difference per year + +exportATTooltip = Export as AT file + +waterlevel_export = Waterlevel Export +waterlevel_report = Waterlevel Report +computed_dischargecurve_export = Discharge Curve Export +computed_dischargecurve_report = Discharge Curve Report +discharge_longitudinal_section_export = Discharge Longitudinal Section Export +discharge_longitudinal_section_report = Discharge Longitudinal Section Report +durationcurve_export = Duration Curve Export +durationcurve_report = Duration Curve Report +dataexport = Data export +csv = CSV +wst = WST +at = AT +pdf = PDF +computed_dischargecurve_at_export = AT Export +gauge_discharge_curve_at_export = Gauge Discharge Curve +gauge_class = Gauge Class +eventselect = Eventselection +events = Events +kmchart = W/Q-Preview + +chart_themepanel_header_themes = Theme +chart_themepanel_header_actions = Actions +chart_themepanel_synchron = Navigate synchronously +chart_themepanel_asynchron = Navigate independently +chart_themepanel_set_master = Reference +chart_themepanel_new_area = New Area... +chart_themepanel_area_under = under ... +chart_themepanel_area_over = over ... +chart_themepanel_area_between = between ... +against_x_axis = Over X-Axis + +gauge_mnq = around MNQ +gauge_mq = around MQ +gauge_mhq = around MHQ +gauge_hq5 = above HQ5 + +ele_window_title = Elevation Node +ele_window_label = Elevation settings in m \u00fc. NN. +ele_window_x_col = X +ele_window_y_col = Y +ele_window_z_col = Z-Coordinate +ele_window_ok_button = Set elevations +ele_window_cancel_button = Cancel +ele_window_format_error = The elevation you have entered is invalid: +ele_window_save_error = Error while saving elevations. +ele_window_geometry_error = The geometry is not supported: + +unexpected_exception = There occured an unexpected exception +error_years_wrong = The second year needs to be bigger than the first year. +error_read_minmax_values = Error while reading min/max values for the location input. +error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2. +error_validate_date_range = Start date needs to be before end date. +error_validate_date_range_invalid = The specified timerange is invalid. +error_validate_lower_range = The lower value $1 needs to be bigger than $2. +error_validate_upper_range = The upper value $1 needs to be smaller than $2. +error_empty_state = Required inputs are missing. +error_invalid_double_value = Wrong format for a floating point number. +error_create_artifact = Error while creating new project. +error_describe_artifact = Error while loading the parameterization. +error_feed_data = Error while inserting new data. +error_advance_artifact = Error while changing the project's state. +error_add_artifact = Error while inserting new data. +error_remove_artifact = Error while removing data. +error_create_collection = Error while creating a new collection. +error_describe_collection = Error while fetching the projects state. +error_no_rivers_found = Error while reading supported rivers. +error_no_such_user = Error - no such user found. +error_no_users = Error - no users found. +error_no_waterlevel_pair_selected = Error - no waterlevel pair for building differences selected. +error_same_waterlevels_in_pair = Error - minuend and subtrahend have to differ. +error_not_logged_in = You need to log in before you are allowed to start your work. +error_load_parameterization = Could not load the parameterization. +error_wrong_date = Please enter valid dates. +error_no_gaugeoverviewinfo_found = Error while fetching the river and gauge info + +error_feed_no_data = No input data found. +error_feed_from_out_of_range = The lower value is bigger than the upper value. +error_feed_to_out_of_range = The upper value is out or the valid range. +error_feed_from_bigger_to = The lower value is bigger than the upper value. +error_feed_invalid_wq_mode = Invalid WQ-Mode selected. +error_feed_number_format_float = The inserted value is no floating point number. +error_feed_invalid_calculation_mode = The chosen calculation method is invalid. +error_feed_no_calculation_mode = No calculation method chosen. +error_feed_no_such_river = The selected river is not provided. +error_feed_no_river_selected = No river selected. +error_feed_no_wq_mode_selected = No W/Q mode selected. +error_feed_q_values_invalid = Selected Q values are outside the valid range. +error_feed_w_values_invalid = Selected W values are outside the valid range. +error_chart_info_service = Could not fetch meta information of the chart. +error_no_meta_data_found = No meta data found. +error_load_artifact = Error while adding data to the current project. +error_no_calc_result=No calculation results found. +error_no_theme_styles_found=No style for the selected theme found. +error_no_feature_selected = No object selected. +error_no_map_config = No Map configuration found. +error_no_map_output_type = No Map output found. +error_no_valid_gfi_url = No valid GetFeatureInfo response found. +error_gfi_req_failed = GetFeatureInfo request failed. +error_gfi_parsing_failed = Failed to read GetFeatureInfo response. +error_gc_req_failed = Error while loading Capabilities document. +error_gc_doc_not_valid = Capabilities document is not valid. +error_malformed_url = The URL you have entered is not valid. +error_no_dgm_selected = No DEM selected. +error_invalid_dgm_selected = You have selected an invalid DEM. +error_bad_dgm_range = You have selected a DEM with an invalid range. +error_bad_dgm_river = You have selected a DEM for a wrong river. +error_dialog_not_valid = One or more values are not valid. +error_invalid_date = The entered date is not valid. +error_same_location = Reference location equals selected location. +error_contains_same_location = Target locations contains reference location. +error_update_collection_attribute = Error while updating the collection attribut +error_values_needed = You must provide values. +error_no_module_found = No modules found + +warning_use_first_feature = You have more that one object selected. The first one is used. +warning_no_wsp_selected = No waterlevel selected! +warning_cannot_parse_date = Date is invalid! +warning_select_two_values = Please select two values! + +## map related strings +digitize = images/digitize.png +pipe1 = Pipe1 +pipe2 = Pipe12 +ditch = Ditch +dam = Dam +ring_dike = Ringdike +selectFeature = images/selectFeature.png +removeFeature = images/removeFeature.png +getFeatureInfo = images/info.png +getFeatureInfoTooltip = Information Tool +getFeatureInfoWindowTitle = Information for Map Layer: +addWMS = images/add_map.png +printMapSettings = images/print_map_settings.png +addWMSTooltip = Load layers from external WMS service. +adjustElevation = images/adjustElevation.png +measureLine = images/measure_line.png +measurePolygon = images/measure_plane.png +step = Step +calculationStarted = Calculation started. +zoomMaxExtent = Max extent +zoomIn = Zoom in +zoomOut = Zoom out +zoomLayer = Zoom to layer +moveMap = Move +digitizeObjects = Creation of pipes, ditches, dams and ringdikes +selectObject = Select tool +removeObject = Remove selected object +adjustElevationTooltip = Define elevations for barriers +measureDistance = Measure line +measureArea = Measure area +map_themepanel_header_style = Style +zoomToLayer = Layer-Zoom +requireDGM = You need to choose a DEM. +upload_file = upload +shape_file_upload = Upload shapefile +attribution = ©Intevation GmbH 2013<br>Data ©<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> +wmsURLMenuItem = WMS URL +wmsURLBoxTitle = Layer WMS URL +requireTheme = You need to choose a Layer. + +# data cage +waterlevels = Waterlevels +old_calculations = Former Calculations +officiallines = Official lines +datacageAdd = Add data +heightmarks = Height Marks +basedata = Base Data +fixations = Fixations +flood_protections = Flood Protections +columns = Columns +annotation = Annotations +annotations = Annotations +all_annotations = All annotations +flowvelocitymeasurement = Flowvelocity measurements +bed_quality_bed = Quality - Bed +bed_quality_load = Quality - Load +additionals = Additional Longitudinal Section Curves +differences = Differences +kilometrage = Kilometrage +riveraxis = Riveraxis +km = Km +qps = Crosssection Tracks +hws = Floodplain Protection Work +catchments = Catchments +catchment_wms = Catchment (WMS) +floodplain = Floodplain +lines = Lines +buildings = Buildings +fixpoints = Fixpoints +uesk = Floodmaps +calculations = Calculations +current = Current +potentiel = Potentiel +bfg = BfG +land = Land +rastermap = Rastermap +background = Background Layer (WMS) +discharge_tables_chart = W/Q-Preview +discharge_table_nn = Discharge Tables at Gauge +discharge_table_gauge = Discharge Table at Gauge +mainvalue = Mainvalue +mainvalues = Mainvalues +wmainvalue = Mainvalues (W) +qmainvalue = Mainvalues (Q) +show_mainvalues = Show Mainvalues +dems = Digital Elevation Models +hydrboundaries = Hydrological Boundaries +gaugelocations = Location of Gauges (WMS) +single = Year +epoch = Epoch +bedheights = Bedheights +morph_width = morphologic Width +datacage = Datacage + +startcolor = Colorrange start color +endcolor = Colorrange end color +numclasses = Number of classes + +# capabilities information panel +addwmsInputTitle = Base URL of WMS service +addwmsInfoTitle = Information about WMS service +addwmsLayerTitle = Choose Layer +addwmsBack = Back +addwmsContinue = Continue +addwmsCancel = Cancel +addwmsInvalidURL = The URL is not valid. +capabilitiesHint = Please notice the information of the WMS service. +capabilitiesTitle = Title +capabilitiesURL = URL +capabilitiesAccessConstraints = Access Constraints +capabilitiesFees = Fees +capabilitiesContactInformation = Further Information +capabilitiesEmail = Email +capabilitiesPhone = Phone + +#Properties dialog +chart = Chart +export = Export +width = Width +height = Height +visibility = Visibility +upper = to +lower = from +fixation = Fix +font_size = Fontsize +label = Title +title = Title +subtitle = Subtitle +display_grid = Display grid +display_logo = Display logo +logo_placeh = Horiz. Place for logo +logo_placev = Vertic. Place for logo +top = top +bottom = bottom +center = center +left = left +right = right +none = none + +notselected = none + +linetype = Linetype +textstyle = Textstyle +linecolor = Linecolor +showhorizontalline = Show horizonal line +showverticalline = Show vertical line +textcolor = Textcolor +textsize = Textsize +font = Font +showpoints = Show points +showbackground = Show background +textshowbg = Show background +backgroundcolor = Backgroundcolor +bandwidthcolot = Bandwidthcolor +textbgcolor = Backgroundcolor +textorientation = Textorientation +linesize = Linesize +pointsize = Pointsize +bandwidth = Bandwidth +pointcolor = Pointcolor +showlines = Show lines +showlinelabel = Show label +showpointlabel = Show point label +labelfontface = Label: Font +labelfontcolor = Label: Color +labelfontsize = Label: Size +labelfontstyle = Label: Style +labelbgcolor = Label: Background Color +labelshowbg = Label: Show Background +horizontal = horizontal +vertical = vertical +showwidth = Show width +showlevel = Show waterlevel +showminimum = Show minimum +showmaximum = Show maximum +showborder = Show line +transparent = Transparency +transparency = Transparency +showarea = Show area +showarealabel = Show area label +showmiddleheight = Show middle depth +fillcolor = Fill Color +areabgcolor = Fill Color +areashowborder = Show area border +areashowbg = Show area background +areabordercolor = Border color +areatransparency = Tranparency +wsplgen_cat1 = Fill Color 0.0 <= DIFF < 1 +wsplgen_cat2 = Fill Color 1.0 <= DIFF < 2 +wsplgen_cat3 = Fill Color 2.0 <= DIFF < 3 +wsplgen_cat4 = Fill Color 3.0 <= DIFF < 4 +wsplgen_cat5 = Fill Color 4.0 <= DIFF + +# Manual Points Editor +addpoints = Add points +pointname = Name +removepoint = Remove +newpoint = New Point +standby = Creating Artifact ... please wait. +points = Points +editpoints = Edit Points +addWSP = Add Manual LS +addWSPButton = Add Manual LS +selection = Selection + +# Reference Curves +reference_curve = Reference Curve +reference_curve_normalized = Reduced Reference Curve +reference_startpoint = Point of reference +reference_endpoint = Point(s) of projection + +fix_deltawt_export = \u0394 W/t +select=Selected +add_date=Add + +fix_parameters_export = Adjusted coefficient +fix_parameters = CSV +sq_overview=Overview + +gauge_zero = GZG +gauge_q_unit = m\u00b3/s +gauge_river_info_link = Riverinfo +gauge_info_link = Gaugeinfo +gauge_url = https://flys-intern.intevation.de/PegelInfo/ +gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ +gauge_curve_link = Dischargecurve/-table +discharge_timeranges = DC-Timeranges +discharge_chart = W/Q-Preview + +measurement_station_type = Type of Measurement Station +measurement_station_operator = Operator +measurement_station_start_time = Observation Start Time +measurement_station_url = https://flys-intern.intevation.de/MessstellenInfo/ +measurement_station_info_link = Measurement Station Info +measurement_station_gauge_name = Reference Gauge + +# Get Feature Info Window +PATH = Path +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/FLYSImages.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.client; + +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.ImageResource; + + +/** + * This interface grants access to the images used in this application. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface FLYSImages extends ClientBundle { + + @Source("images/bfg_logo.gif") + ImageResource logoBfg(); + + @Source("images/flys_logo.gif") + ImageResource logoFlys(); + + @Source("images/FLYS_Karte.png") + ImageResource riverMap(); + + @Source("images/marker_red.png") + ImageResource markerRed (); + + @Source("images/marker_green.png") + ImageResource markerGreen (); + + @Source("images/loading.gif") + ImageResource loading(); + + @Source("images/downloadPNG.png") + ImageResource downloadPNG(); + + @Source("images/downloadPDF.png") + ImageResource downloadPDF(); + + @Source("images/downloadSVG.png") + ImageResource downloadSVG(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/FLYSResources.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.client; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.TextResource; + + +/** + * A {@link ClientBundle} that is used to handle resources in this client. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface FLYSResources extends ClientBundle { + + public static final FLYSResources INSTANCE = + GWT.create(FLYSResources.class); + + @Source("config.xml") + public TextResource initialConfiguration(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/config.xml Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,8 @@ +<config> + <server>http://localhost:8181</server> + + <projectlist> + <!-- The interval to update the user's projects (in ms) --> + <update-interval>300000</update-interval> + </projectlist> +</config>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/AdvanceHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface AdvanceHandler extends Serializable { + + public void onAdvance(String target); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/CollectionChangeEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,29 @@ +package de.intevation.flys.client.client.event; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This events stores references to the old collection and the new one. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CollectionChangeEvent { + + protected Collection oldCollection; + protected Collection newCollection; + + public CollectionChangeEvent(Collection old, Collection newArt) { + oldCollection = old; + newCollection = newArt; + } + + public Collection getOldValue() { + return oldCollection; + } + + public Collection getNewValue() { + return newCollection; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/CollectionChangeHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.event; + + +/** + * Handler interface for CollectionChangeEvent events. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface CollectionChangeHandler { + + /** + * Called when a CollectionChangeEvent is fired. + * + * @param event The CollectionChangeEvent. + */ + public void onCollectionChange(CollectionChangeEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/DatacageDoubleClickHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,9 @@ +package de.intevation.flys.client.client.event; + +import de.intevation.flys.client.shared.model.ToLoad; + + +public interface DatacageDoubleClickHandler { + + void onDoubleClick(ToLoad toLoad); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/DatacageHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,9 @@ +package de.intevation.flys.client.client.event; + +import de.intevation.flys.client.shared.model.ToLoad; + +public interface DatacageHandler +{ + void toLoad(ToLoad toLoad); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/FilterHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface FilterHandler { + + void onFilterCriteriaChanged(StringFilterEvent event); + + void onFilterCriteriaChanged(RangeFilterEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasCollectionChangeHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,16 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasCollectionChangeHandlers { + + /** + * Adds a new CollectionChangeHandler. + * + * @param handler The new CollectionChangeHandler. + */ + public void addCollectionChangeHandler(CollectionChangeHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasOutputModesChangeHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,16 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasOutputModesChangeHandlers { + + /** + * Adds a new OutputModesChangeHandler. + * + * @param handler The new OutputModesChangeHandler. + */ + public void addOutputModesChangeHandler(OutputModesChangeHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasOutputParameterChangeHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,16 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasOutputParameterChangeHandlers { + + /** + * Registers a new OutputParameterChangeHandler. + * + * @param handler The new handler. + */ + void addOutputParameterChangeHandler(OutputParameterChangeHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasPanHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,11 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasPanHandlers { + + void addPanHandler(PanHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasParameterChangeHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,16 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasParameterChangeHandler { + + /** + * Adds a new ParameterChangeHandler. + * + * @param handler The new ParameterChangeHandler. + */ + public void addParameterChangeHandler(ParameterChangeHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasRedrawRequestHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.client.event; + + +/** + * Implements function to add a RedrawRequestHandler. + */ +public interface HasRedrawRequestHandlers { + + /** + * Adds a new RedrawRequestHandler. + * + * @param handler The new RedrawRequestHandler + */ + public void addRedrawRequestHandler(RedrawRequestHandler rrh); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasStepBackHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasStepBackHandlers extends Serializable { + + public void addStepBackHandler(StepBackHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasStepForwardHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasStepForwardHandlers extends Serializable { + + public void addStepForwardHandler(StepForwardHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/HasZoomHandlers.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,11 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasZoomHandlers { + + void addZoomHandler(ZoomHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/OnMoveEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,27 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class OnMoveEvent { + + public static final int TOP = 0; + public static final int UP = 1; + public static final int DOWN = 2; + public static final int BOTTOM = 3; + + + protected int type; + + + public OnMoveEvent(int type) { + this.type = type; + } + + + public int getType() { + return type; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/OnMoveHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,11 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface OnMoveHandler { + + void onMove(OnMoveEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/OutputModesChangeEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,26 @@ +package de.intevation.flys.client.client.event; + +import de.intevation.flys.client.shared.model.OutputMode; + + +/** + * An event that is thrown if the output modes of a collection or an artifact + * have changed. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class OutputModesChangeEvent { + + protected OutputMode[] outs; + + + public OutputModesChangeEvent(OutputMode[] outs) { + this.outs = outs; + } + + + public OutputMode[] getOutputModes() { + return outs; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/OutputModesChangeHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.event; + + +/** + * Handler interface for OutputModesChangeEvent events. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface OutputModesChangeHandler { + + /** + * Called when a OutputModesChangeEvent is fired. + * + * @param event The OutputModesChangeEvent. + */ + public void onOutputModesChange(OutputModesChangeEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/OutputParameterChangeEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,12 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class OutputParameterChangeEvent { + + public OutputParameterChangeEvent() { + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/OutputParameterChangeHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface OutputParameterChangeHandler { + + /** + * Called when the parameter of an output have changed. E.g. when the state + * of themes in a theme panel changed. + * + * @param event The event that is fired. + */ + void onOutputParameterChanged(OutputParameterChangeEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/PanEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class PanEvent { + + protected int[] startPos; + protected int[] endPos; + + + public PanEvent(int[] startPos, int[] endPos) { + this.startPos = startPos; + this.endPos = endPos; + } + + + public int[] getStartPos() { + return startPos; + } + + + public int[] getEndPos() { + return endPos; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/PanHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,11 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface PanHandler { + + void onPan(PanEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/ParameterChangeEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,48 @@ +package de.intevation.flys.client.client.event; + +import de.intevation.flys.client.shared.model.Artifact; + + +/** + * This events stores references to the old artifact and the new one. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ParameterChangeEvent { + + public static enum Type { + FORWARD, BACK + } + + + protected Artifact oldArtifact; + protected Artifact newArtifact; + + protected Type type; + + + public ParameterChangeEvent(Artifact old, Artifact newArt) { + this(old, newArt, Type.FORWARD); + } + + + public ParameterChangeEvent(Artifact oArt, Artifact nArt, Type type) { + oldArtifact = oArt; + newArtifact = nArt; + this.type = type; + } + + + public Artifact getOldValue() { + return oldArtifact; + } + + public Artifact getNewValue() { + return newArtifact; + } + + public Type getType() { + return type; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/ParameterChangeHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.event; + + +/** + * Handler interface for ParameterChangeEvent events. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface ParameterChangeHandler { + + /** + * Called when a ParameterChangeEvent is fired. + * + * @param event The ParameterChangeEvent. + */ + public void onParameterChange(ParameterChangeEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/RangeFilterEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,44 @@ +package de.intevation.flys.client.client.event; + +import com.google.gwt.i18n.client.NumberFormat; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class RangeFilterEvent { + + protected Float from; + protected Float to; + + + public RangeFilterEvent(String from, String to) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d; + + try { + d = nf.parse(from); + this.from = Float.valueOf(String.valueOf(d)); + } + catch(NumberFormatException nfe) { + this.from = Float.NaN; + } + try { + d = nf.parse(to); + this.to = Float.valueOf(String.valueOf(d)); + } + catch(NumberFormatException nfe) { + this.to = Float.NaN; + } + } + + + public Float getFrom() { + return this.from; + } + + + public Float getTo() { + return this.to; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/RedrawRequestEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.event; + + +public class RedrawRequestEvent { + + public static enum Type { + RESET, DEFAULT + } + + + protected Type type; + + + public RedrawRequestEvent() { + this.type = Type.DEFAULT; + } + + + public RedrawRequestEvent(Type type) { + this.type = type; + } + + + public Type getType() { + return type; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/RedrawRequestHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,15 @@ +package de.intevation.flys.client.client.event; + + +/** + * Handler interface for RedrawRequests. + */ +public interface RedrawRequestHandler { + + /** + * Handle the redraw request. + */ + public void onRedrawRequest(RedrawRequestEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/StepBackEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,36 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StepBackEvent implements Serializable { + + private static final long serialVersionUID = 7895180143662002198L; + + /** The identifier of the target state.*/ + protected String target; + + + /** + * Creates a new StepBackEvent with the identifier of the target state. + * + * @param target The identifier of the target state. + */ + public StepBackEvent(String target) { + this.target = target; + } + + + /** + * A method to retrieve the target identifier. + * + * @return the target identifier. + */ + public String getTarget() { + return target; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/StepBackHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface StepBackHandler extends Serializable { + + public void onStepBack(StepBackEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/StepForwardEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,38 @@ +package de.intevation.flys.client.client.event; + +import de.intevation.flys.client.shared.model.Data; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StepForwardEvent implements Serializable { + + private static final long serialVersionUID = -5527511690213770954L; + + /** The selected data.*/ + protected Data[] data; + + /** + * Creates a new StepForwardEvent with the Data that has been selected in + * the UI. + * + * @param data The selected data. + */ + public StepForwardEvent(Data[] data) { + this.data = data; + } + + + /** + * A method to retrieve the data stored in the event. + * + * @return the data. + */ + public Data[] getData() { + return data; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/StepForwardHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface StepForwardHandler extends Serializable { + + public void onStepForward(StepForwardEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/StringFilterEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.event; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StringFilterEvent { + + protected String filter; + + + public StringFilterEvent(String filter) { + this.filter = filter; + } + + + public String getFilter() { + return filter; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/ZoomEvent.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,43 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ZoomEvent { + + protected int xmin; + protected int ymin; + + protected int xmax; + protected int ymax; + + + public ZoomEvent(int xmin, int ymin, int xmax, int ymax) { + this.xmin = xmin; + this.xmax = xmax; + this.ymin = ymin; + this.ymax = ymax; + } + + + public int getStartX() { + return xmin; + } + + + public int getEndX() { + return xmax; + } + + + public int getStartY() { + return ymin; + } + + + public int getEndY() { + return ymax; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/event/ZoomHandler.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,11 @@ +package de.intevation.flys.client.client.event; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface ZoomHandler { + + void onZoom(ZoomEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/AddArtifactService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,35 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes the service to add an existing artifact to an + * existing collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("add-artifact") +public interface AddArtifactService extends RemoteService { + + /** + * Adds an artifact to a collection. + * + * @param collection The Collection that should be extended. + * @param artifact The artifact that should be added. + * @param url The url of the artifact server. + * + * @return the Collection after the operation. + */ + Collection add( + Collection collection, + Artifact artifact, + String locale) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/AddArtifactServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface AddArtifactServiceAsync { + + public void add( + Collection collection, + Artifact artifact, + String locale, + AsyncCallback<Collection> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/AdvanceService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,33 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; + +/** + * This interface provides artifact specific operation ADVANCE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("advance") +public interface AdvanceService extends RemoteService { + + /** + * This method inserts new data into the an existing artifact. + * + * @param serverUrl The url of the artifact server. + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param target The identifier of the target state. + * + * @return the artifact which description might have been changed. + */ + public Artifact advance( + String locale, + Artifact artifact, + String target) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/AdvanceServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; + + +/** + * This interface provides artifact specific operation ADVANCE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface AdvanceServiceAsync { + + public void advance( + String locale, + Artifact artifact, + String target, + AsyncCallback<Artifact> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,64 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; + +import de.intevation.flys.client.shared.model.Recommendation; + +/** + * This interface provides artifact specific services as CREATE, DESCRIBE, FEED, + * ADVANCE and OUT. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("artifact") +public interface ArtifactService extends RemoteService { + + /** + * This method creates a new artifact based on the given <i>factory</i>. + * + * @param serverUrl The url of the artifact server. + * @param locale The locale used for the request. + * @param factory The factory that should be used for the artifact creation. + * + * @return the new artifact. + */ + public Artifact create( + String locale, + String factory, + Recommendation recommendation + ) throws ServerException; + + /** + * Create a new GaugeDischageCurveArtifact + * + * @param collection the collection to add the artifact to + * @param river the river + * @param gaugeref reference id of the gauge + */ + public Artifact createGaugeDischargeCurveArtifact( + Collection collection, + String locale, + String river, + Long gaugeref + ) throws ServerException; + + /** + * Create a new SQRelationArtifact + * + * @param collection the collection to add the artifact to + * @param river the river + * @param measurementStation the measurement station id + */ + public Artifact createSQRelationArtifact( + Collection collection, + String locale, + String river, + int measurementStation + ) throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; + +import de.intevation.flys.client.shared.model.Recommendation; + +/** + * This interface provides artifact specific services as CREATE, DESCRIBE, FEED, + * ADVANCE and OUT. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface ArtifactServiceAsync { + + public void create( + String locale, + String factory, + Recommendation recommendation, + AsyncCallback<Artifact> callback); + + public void createGaugeDischargeCurveArtifact( + Collection collection, + String locale, + String river, + Long gaugeref, + AsyncCallback<Artifact> callback + ); + + public void createSQRelationArtifact( + Collection collection, + String locale, + String river, + int measurementStation, + AsyncCallback<Artifact> callback + ); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CSVExportService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import java.util.List; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +/** + * This service is used to fetch a list of DistanceInfoObjects from artifact + * server for a specific river. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("csv") +public interface CSVExportService extends RemoteService { + + /** + * This method returns a list of DistanceInfoObjects for a specific river. + */ + List<String[]> getCSV( + String locale, + String uuid, + String name) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CSVExportServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import java.util.List; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface CSVExportServiceAsync { + + void getCSV( + String locale, + String uuid, + String name, + AsyncCallback<List<String[]>> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ChartInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,25 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.ChartInfo; +import de.intevation.flys.client.shared.model.Collection; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("chart-info") +public interface ChartInfoService extends RemoteService { + + ChartInfo getChartInfo( + Collection collection, + String locale, + String type, + Map<String, String> attr) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ChartInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,23 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.ChartInfo; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface ChartInfoServiceAsync { + + public void getChartInfo( + Collection collection, + String locale, + String type, + Map<String, String> attr, + AsyncCallback<ChartInfo> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CollectionAttributeService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("collection-attribute") +public interface CollectionAttributeService extends RemoteService { + + Collection update(Collection collection, String locale) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CollectionAttributeServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface CollectionAttributeServiceAsync { + + void update( + Collection collection, + String locale, + AsyncCallback<Collection> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CollectionItemAttributeService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,32 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItemAttribute; + +/** + * This interface provides a method to retrieve an artifact based on its uuid. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("collection-item-attribute") +public interface CollectionItemAttributeService extends RemoteService { + + CollectionItemAttribute getCollectionItemAttribute( + Collection collection, + String artifact, + String locale) + throws ServerException; + + void setCollectionItemAttribute( + Collection collection, + String artifact, + String locale, + CollectionItemAttribute attribute) + throws ServerException; + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CollectionItemAttributeServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItemAttribute; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface CollectionItemAttributeServiceAsync { + + public void getCollectionItemAttribute( + Collection collection, + String artifact, + String locale, + AsyncCallback<CollectionItemAttribute> callback); + + public void setCollectionItemAttribute( + Collection collection, + String artifact, + String locale, + CollectionItemAttribute attributes, + AsyncCallback<Void> callback); + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CreateCollectionService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,27 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes the service for creating new collections. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("create-collection") +public interface CreateCollectionService extends RemoteService { + + /** + * This method creates a new collection in the artifact server and returns + * the uuid of this collection. + * + * @return the uuid of the created collection. + */ + Collection create(String locale, String ownerId) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CreateCollectionServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes the service for creating new collections. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface CreateCollectionServiceAsync { + + void create( + String locale, + String owner, + AsyncCallback<Collection> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CrossSectionKMService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,30 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +/** + * This interface provides access to CrossSectionKMService . + */ +@RemoteServiceRelativePath("cross-section-km") +public interface CrossSectionKMService extends RemoteService { + + /** + * @param serverUrl The url of the artifact server. + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param data The data that should be inserted. + * + * @return the artifact which description might have been changed. + */ + public Map<Integer,Double[]> getCrossSectionKMs( + String locale, + Map<Integer, Double> data, + int nNeightbours) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/CrossSectionKMServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * Talk-to interface for crosssectionkm service. + */ +public interface CrossSectionKMServiceAsync { + + void getCrossSectionKMs( + String locale, + Map<Integer, Double> data, + int nNeighbours, + AsyncCallback<Map<Integer, Double[]>> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DeleteCollectionService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,27 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes the service to add an existing artifact to an + * existing collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("delete-collection") +public interface DeleteCollectionService extends RemoteService { + + /** + * Deletes a collection. + * + * @param collection The Collection that should be deleted. + */ + void delete(Collection collection) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DeleteCollectionServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface DeleteCollectionServiceAsync { + + public void delete( + Collection collection, + AsyncCallback<Void> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DescribeArtifactService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,31 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; + +/** + * This interface provides artifact specific operation DESCRIBE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("describe") +public interface DescribeArtifactService extends RemoteService { + + /** + * This method inserts new data into the an existing artifact. + * + * @param url The url of the artifact server. + * @param locale The locale used for the request. + * @param artifact The artifact. + * + * @return the artifact which description might have been changed. + */ + public Artifact describe( + String locale, + Artifact artifact) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DescribeArtifactServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; + + +/** + * This interface provides artifact specific operation DESCRIBE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface DescribeArtifactServiceAsync { + + public void describe( + String locale, + Artifact artifact, + AsyncCallback<Artifact> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DescribeCollectionService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,31 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This service describes an operation the fetches the DESCRIBE document of a + * specific collection and returns a Collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("describe-collection") +public interface DescribeCollectionService extends RemoteService { + + /** + * Adds an artifact to a collection. + * + * @param uuid The uuid of the desired collection. + * @param url The url of the artifact server. + * @param locale The name of the locale used for the request. + * + * @return the Collection after the operation. + */ + Collection describe(String uuid, String locale) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DescribeCollectionServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface DescribeCollectionServiceAsync { + + public void describe( + String uuid, + String locale, + AsyncCallback<Collection> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DischargeInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,26 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.DischargeInfoObject; + +/** + * This service is used to fetch a list of DischargeInfoObjects from artifact + * server for a specific gauge. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("dischargeinfo") +public interface DischargeInfoService extends RemoteService { + + /** + * This method returns a list of DischargeInfoObjects for a specific gauge. + */ + DischargeInfoObject[] getDischargeInfo( + String locale, + long gauge) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DischargeInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.DischargeInfoObject; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface DischargeInfoServiceAsync { + + void getDischargeInfo( + String locale, + long gauge, + AsyncCallback<DischargeInfoObject[]> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DistanceInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,26 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.DistanceInfoObject; + +/** + * This service is used to fetch a list of DistanceInfoObjects from artifact + * server for a specific river. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("distanceinfo") +public interface DistanceInfoService extends RemoteService { + + /** + * This method returns a list of DistanceInfoObjects for a specific river. + */ + DistanceInfoObject[] getDistanceInfo( + String locale, + String river) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/DistanceInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.DistanceInfoObject; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface DistanceInfoServiceAsync { + + void getDistanceInfo( + String locale, + String river, + AsyncCallback<DistanceInfoObject[]> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/FeedService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,49 @@ +package de.intevation.flys.client.client.services; + +import java.util.List; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Data; + +/** + * This interface provides artifact specific operation FEED. + */ +@RemoteServiceRelativePath("feed") +public interface FeedService extends RemoteService { + + /** + * Inserts new data into an existing artifact. + * + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param data The data that should be inserted. + * + * @return the artifact which description might have been changed. + */ + public Artifact feed( + String locale, + Artifact artifact, + Data[] data) + throws ServerException; + + + /** + * Inserts (the same) new data into existing artifacts. + * + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param data The data that should be inserted. + * + * @return the artifact which description might have been changed. + */ + public List<Artifact> feedMany( + String locale, + List<Artifact> artifacts, + Data[] data) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/FeedServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,42 @@ +package de.intevation.flys.client.client.services; + +import java.util.List; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Data; + + +/** + * This interface provides artifact specific operation FEED. + */ +public interface FeedServiceAsync { + + /** + * Inserts new data into an existing artifact. + * + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param data The data that should be inserted. + */ + public void feed( + String locale, + Artifact artifact, + Data[] data, + AsyncCallback<Artifact> callback); + + /** + * Inserts (the same) new data into existing artifacts. + * + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param data The data that should be inserted. + */ + public void feedMany( + String locale, + List<Artifact> artifacts, + Data[] data, + AsyncCallback<List<Artifact>> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/FixingsOverviewService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; + +@RemoteServiceRelativePath("fixings-overview") +public interface FixingsOverviewService extends RemoteService { + + FixingsOverviewInfo generateOverview( + String locale, + String uuid, + String filter, + boolean checkbox, + String callback + ) throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/FixingsOverviewServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; + +public interface FixingsOverviewServiceAsync { + + void generateOverview( + String locale, + String uuid, + String filter, + boolean checkbox, + String callbackFunction, + AsyncCallback<FixingsOverviewInfo> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GCService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,16 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Capabilities; + + +@RemoteServiceRelativePath("getcapabilities") +public interface GCService extends RemoteService { + + public Capabilities query(String path) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GCServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,15 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Capabilities; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface GCServiceAsync { + + void query(String path, AsyncCallback<Capabilities> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GFIService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.services; + +import java.util.List; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.FeatureInfoResponse; +import de.intevation.flys.client.shared.model.Theme; + + +@RemoteServiceRelativePath("getfeatureinfo") +public interface GFIService extends RemoteService { + + public FeatureInfoResponse query( + Theme theme, + String format, + String bbox, + String projection, + int height, + int width, + int x, + int y + ) throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GFIServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.services; + +import java.util.List; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.FeatureInfoResponse; +import de.intevation.flys.client.shared.model.Theme; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface GFIServiceAsync { + + void query( + Theme theme, + String format, + String bbox, + String projection, + int height, + int width, + int x, + int y, + AsyncCallback<FeatureInfoResponse> callback + ); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GaugeInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import java.util.List; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Gauge; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("gaugeinfo") +public interface GaugeInfoService extends RemoteService { + + List<Gauge> getGaugeInfo(String river, String refnumber) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GaugeInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import java.util.List; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Gauge; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface GaugeInfoServiceAsync { + + void getGaugeInfo( + String river, + String refnumber, + AsyncCallback<List<Gauge>> gauges); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GetArtifactService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,31 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; + +/** + * This interface provides a method to retrieve an artifact based on its uuid. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("getartifact") +public interface GetArtifactService extends RemoteService { + + /** + * This method inserts new data into the an existing artifact. + * + * @param url The url of the artifact server. + * @param locale The string representation of a locale that is used for the + * request. + * @param uuid The artifact's identifier. + * @param hash The artifact's hash. + * + * @return the artifact. + */ + Artifact getArtifact(String locale, String uuid, String hash) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/GetArtifactServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface GetArtifactServiceAsync { + + public void getArtifact( + String locale, + String uuid, + String hash, + AsyncCallback<Artifact> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/LoadArtifactService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,31 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Recommendation; + +/** @see LoadArtifactServiceImpl */ +@RemoteServiceRelativePath("load-artifact") +public interface LoadArtifactService extends RemoteService { + + /** @see LoadArtifactServiceImpl */ + Artifact load( + Collection parent, + Recommendation recom, + String factory, + String locale) + throws ServerException; + + /** @see LoadArtifactServiceImpl */ + Artifact[] loadMany( + Collection parent, + Recommendation[] recom, + String factory, + String locale) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/LoadArtifactServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,29 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Recommendation; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface LoadArtifactServiceAsync { + + public void load( + Collection parent, + Recommendation recom, + String factory, + String locale, + AsyncCallback<Artifact> callback); + + public void loadMany( + Collection parent, + Recommendation[] recom, + String factory, + String locale, + AsyncCallback<Artifact[]> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MapInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.MapInfo; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("map-info") +public interface MapInfoService extends RemoteService { + + MapInfo getMapInfo(String locale, String river) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MapInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.MapInfo; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface MapInfoServiceAsync { + + public void getMapInfo( + String locale, + String river, + AsyncCallback<MapInfo> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MapOutputService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,22 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.MapConfig; + + +/** + * This interface describes the service to add an existing artifact to an + * existing collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("map") +public interface MapOutputService extends RemoteService { + + MapConfig doOut(Collection collection) throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MapOutputServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,16 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.MapConfig; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface MapOutputServiceAsync { + + public void doOut(Collection collection, AsyncCallback<MapConfig> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MapUrlService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +/** + * This interface describes the service to get wms urls for UESK and new maps. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("map-urls") +public interface MapUrlService extends RemoteService { + + Map<String, String> getUrls() throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MapUrlServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,15 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.AsyncCallback; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface MapUrlServiceAsync { + + public void getUrls(AsyncCallback<Map<String, String> > callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MetaDataService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +import de.intevation.flys.client.shared.model.DataCageTree; + +@RemoteServiceRelativePath("meta-data") +public interface MetaDataService extends RemoteService +{ + DataCageTree getMetaData( + String locale, + String artifactId, + String userId, + String outs, + String parameters + ) throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/MetaDataServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.DataCageTree; + +public interface MetaDataServiceAsync { + void getMetaData( + String locale, + String artifactId, + String userId, + String outs, + String parameters, + AsyncCallback<DataCageTree> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ModuleService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,22 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Module; + +@RemoteServiceRelativePath("modules") +public interface ModuleService extends RemoteService { + + /** + * Returns the list of available modules of a user + * + * @param locale The locale used for the request + * @return a String array of all available modules + * + */ + public Module[] list(String locale) throws ServerException; +} + +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ModuleServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,12 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Module; + +public interface ModuleServiceAsync { + + public void list(String locale, + AsyncCallback<Module[]> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/RemoveArtifactService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,34 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes the service to remove an existing artifact to an + * existing collection. + * + */ +@RemoteServiceRelativePath("remove-artifact") +public interface RemoveArtifactService extends RemoteService { + + /** + * Removes an artifact from a collection. + * + * @param collection The Collection that should be modified. + * @param artifactId The artifact that should be removed. + * @param url The url of the artifact server. + * @param locale locae to use (for localized responses). + * + * @return the Collection after the operation. + */ + Collection remove( + Collection collection, + String artifactId, + String locale) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/RemoveArtifactServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + +/** + * @see RemoveArtifactService, RemoveArtifactServiceImpl + */ +public interface RemoveArtifactServiceAsync { + + public void remove( + Collection collection, + String artifactId, + String locale, + AsyncCallback<Collection> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ReportService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,15 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +@RemoteServiceRelativePath("report") +public interface ReportService +extends RemoteService +{ + String report( + String collectionId, + String locale, + String out); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ReportServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +public interface ReportServiceAsync +{ + void report( + String collectionId, + String locale, + String out, + AsyncCallback<String> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/RiverInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,27 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.RiverInfo; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +@RemoteServiceRelativePath("riverinfo") +public interface RiverInfoService extends RemoteService { + + /** + * Returns a RiverInfo object with GaugeInfos + */ + public RiverInfo getGauges(String river) + throws ServerException; + + /** + * Returns a RiverInfo object with MeasurementStations + */ + public RiverInfo getMeasurementStations(String river) + throws ServerException; + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/RiverInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.RiverInfo; + + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public interface RiverInfoServiceAsync { + + public void getGauges(String river, AsyncCallback<RiverInfo> callback); + + public void getMeasurementStations(String river, + AsyncCallback<RiverInfo> callback); +} + +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/RiverService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.River; + +/** + * This interface provides a method to list the supported rivers of the artifact + * server. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("rivers") +public interface RiverService extends RemoteService { + + /** + * This method returns a list of rivers provided by the artifact server. + * + * @param locale The locale used for the request. + * + * @return a list of rivers provided by the artifact server. + */ + public River[] list(String locale) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/RiverServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.River; + + +/** + * This interface provides a method to list the supported rivers of the artifact + * server. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface RiverServiceAsync { + + public void list( + String locale, + AsyncCallback<River[]> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/SedimentLoadInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,29 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; + +/** + * This service is used to fetch a list of SedimentLoadInfoObjects from artifact + * server for a specific river. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("sedimentloadinfo") +public interface SedimentLoadInfoService extends RemoteService { + + /** + * This method returns a list of SedimentLoadInfoObjects for a specific river. + */ + SedimentLoadInfoObject[] getSedimentLoadInfo( + String locale, + String river, + String type, + double startKm, + double endKm) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/SedimentLoadInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface SedimentLoadInfoServiceAsync { + + void getSedimentLoadInfo( + String locale, + String river, + String type, + double startKm, + double endKm, + AsyncCallback<SedimentLoadInfoObject[]> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/SetCollectionNameService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,27 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes the service to add an existing artifact to an + * existing collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("set-collectionname") +public interface SetCollectionNameService extends RemoteService { + + /** + * Set the name of a collection. + * + * @param collection The Collection that should be extended. + */ + void setName(Collection collection) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/SetCollectionNameServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface SetCollectionNameServiceAsync { + + public void setName( + Collection collection, + AsyncCallback<Void> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/SetCollectionTTLService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("set-collectionttl") +public interface SetCollectionTTLService extends RemoteService { + + void setTTL(Collection c) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/SetCollectionTTLServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface SetCollectionTTLServiceAsync { + + public void setTTL( + Collection collection, + AsyncCallback<Void> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/StepForwardService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,34 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Data; + +/** + * This interface provides artifact specific operations FEED and ADVANCE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("forward") +public interface StepForwardService extends RemoteService { + + /** + * This method inserts new data into the an existing artifact and + * advances its state. + * + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param data The data that should be inserted. + * + * @return the artifact which description might have been changed. + */ + public Artifact go( + String locale, + Artifact artifact, + Data[] data) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/StepForwardServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,22 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Data; + + +/** + * This interface provides artifact specific operation FEED and ADVANCE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface StepForwardServiceAsync { + + public void go( + String locale, + Artifact artifact, + Data[] data, + AsyncCallback<Artifact> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ThemeListingService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,29 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Style; + +/** + * This interface provides a method to list themes filtered by name. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund.Renkert</a> + */ +@RemoteServiceRelativePath("themelisting") +public interface ThemeListingService extends RemoteService { + + /** + * This method returns a list of themes filtered by name. + * + * @param locale The locale used for the request. + * + * @return a list of themes provided by the artifact server. + */ + public Map<String, Style> list(String locale, String name) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/ThemeListingServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,22 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Style; + + +/** + * This interface provides a method to list themes filterd by name. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface ThemeListingServiceAsync { + + public void list( + String locale, + String name, + AsyncCallback<Map<String, Style>> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/UserCollectionsService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,29 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes a method that retrieves a list of Collections owned + * by a specified user. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("user-collections") +public interface UserCollectionsService extends RemoteService { + + /** + * This method retrieves the user that is currently logged in. + * + * @param serverUrl The url of the artifact server. + * @param locale The locale used for the request object. + * @param userid The identifier of the owner. + * + * @return the current {@link User}. + */ + Collection[] getUserCollections(String locale, String userid); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/UserCollectionsServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This interface describes a method that retrieves a list of Collections owned + * by a specified user. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface UserCollectionsServiceAsync { + + void getUserCollections( + String locale, + String userid, + AsyncCallback<Collection[]> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/UserService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,33 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.AuthenticationException; +import de.intevation.flys.client.shared.model.User; + + +/** + * This interface describes services for the user. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("user") +public interface UserService extends RemoteService { + + /** + * This method retrieves the user that is currently logged in. + * + * @param locale The current locale. + * + * @return the current {@link User}. + */ + User getCurrentUser(String locale) + throws AuthenticationException; + + /** + * Removes the current user object from the session + */ + void logoutCurrentUser(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/UserServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.User; + + +/** + * This interface describes services for the user. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface UserServiceAsync { + + void getCurrentUser( + String locale, + AsyncCallback<User> callback); + + void logoutCurrentUser(AsyncCallback<Void> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/WQInfoService.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.WQInfoObject; + +/** + * This service is used to fetch a list of DistanceInfoObjects from artifact + * server for a specific river. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("mainvalues") +public interface WQInfoService extends RemoteService { + + /** + * This method returns a list of DistanceInfoObjects for a specific river. + */ + WQInfoObject[] getWQInfo( + String locale, + String river, + double start, + double end) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/services/WQInfoServiceAsync.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.WQInfoObject; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface WQInfoServiceAsync { + + void getWQInfo( + String locale, + String river, + double start, + double end, + AsyncCallback<WQInfoObject[]> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractUIProvider.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,341 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.HasStepBackHandlers; +import de.intevation.flys.client.client.event.HasStepForwardHandlers; +import de.intevation.flys.client.client.event.StepBackEvent; +import de.intevation.flys.client.client.event.StepBackHandler; +import de.intevation.flys.client.client.event.StepForwardEvent; +import de.intevation.flys.client.client.event.StepForwardHandler; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.List; + + +/** + * An abstract UIProvider that provides some basic methods. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public abstract class AbstractUIProvider +implements UIProvider, HasStepForwardHandlers, ClickHandler, + HasStepBackHandlers +{ + private static final long serialVersionUID = -1610874613377494184L; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** The StepForwardHandlers. */ + protected List<StepForwardHandler> forwardHandlers; + + /** The StepForwardHandlers. */ + protected List<StepBackHandler> backHandlers; + + /** The container that is used to position helper widgets. */ + protected VLayout helperContainer; + + /** The artifact that contains status information. */ + protected Artifact artifact; + + /** The Collection. */ + protected Collection collection; + + /** The ParameterList. */ + protected ParameterList parameterList; + + /** + * Creates a new UIProvider instance of this class. + */ + public AbstractUIProvider() { + forwardHandlers = new ArrayList<StepForwardHandler>(); + backHandlers = new ArrayList<StepBackHandler>(); + } + + + /** + * Appends a StepBackHandler that wants to listen to StepBackEvents. + * + * @param handler A new StepBackHandler. + */ + @Override + public void addStepBackHandler(StepBackHandler handler) { + if (handler != null) { + backHandlers.add(handler); + } + } + + + /** + * Appends a StepForwardHandler that wants to listen to StepForwardEvents. + * + * @param handler A new StepForwardHandler. + */ + @Override + public void addStepForwardHandler(StepForwardHandler handler) { + if (handler != null) { + forwardHandlers.add(handler); + } + } + + + /** + * This method is called after the user has clicked one of the buttons to + * step back to a previous state. + * + * @param e The StepBackEvent. + */ + protected void fireStepBackEvent(StepBackEvent e) { + GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: " + backHandlers.size()); + for (StepBackHandler handler: backHandlers) { + handler.onStepBack(e); + } + } + + + /** + * This method is called after the user has clicked on the 'next' button to + * step to the next state. + * + * @param e The StepForwardEvent. + */ + protected void fireStepForwardEvent(StepForwardEvent e) { + GWT.log("AbstractUIProvider - fireStepForwardEvent() handlers: " + forwardHandlers.size()); + for (StepForwardHandler handler: forwardHandlers) { + handler.onStepForward(e); + } + } + + + /** + * This method is used to listen to click events on the 'next' button. The + * fireStepForwardEvent() method is called here. + * + * @param e The click event. + */ + @Override + public void onClick(ClickEvent e) { + List<String> errors = validate(); + if (errors == null || errors.isEmpty()) { + Data[] data = getData(); + fireStepForwardEvent(new StepForwardEvent(data)); + } + else { + showErrors(errors); + } + } + + + protected void showErrors(List<String> errors) { + StringBuilder sb = new StringBuilder(); + + for (String error: errors) { + sb.append(error); + sb.append("<br>"); + } + + SC.warn(sb.toString()); + } + + + /** + * Creates the 'next' button to step forward to the next state. + * + * @return the 'next' button. + */ + protected Canvas getNextButton() { + Button next = new Button(MSG.buttonNext()); + next.addClickHandler(this); + + return next; + } + + + @Override + public Canvas createHelpLink(DataList dataList, Data data) { + String iUrl = GWT.getHostPageBaseURL() + MSG.getFeatureInfo(); + String helpUrl = dataList.getHelpText(); + + return new ImgLink(iUrl, helpUrl, 30, 30, true); + } + + + /** + * Creates the 'back' button to step back to a previous state. + * + * @param targetState The identifier of the target state. + * + * @return the 'back' button. + */ + protected Canvas getBackButton(final String targetState) { + String url = GWT.getHostPageBaseURL() + MSG.imageBack(); + Img back = new Img(url, 16, 16); + + back.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + fireStepBackEvent(new StepBackEvent(targetState)); + } + }); + + return back; + } + + + /** + * This method injects a container that is used to position helper widgets. + * + * @param helperContainer A container that is used to position helper + * widgets. + */ + @Override + public void setContainer(VLayout helperContainer) { + this.helperContainer = helperContainer; + } + + + /** + * This method injects an artifact that contains the status information. + * + * @param art An artifact containing status information. + */ + @Override + public void setArtifact(Artifact art) { + this.artifact = art; + } + + + @Override + public void setCollection(Collection collection) { + this.collection = collection; + } + + + @Override + public void setParameterList(ParameterList list) { + this.parameterList = list; + } + + + public Collection getCollection() { + return collection; + } + + + /** + * This method greps the Data with name <i>name</i> from the list and + * returns it. + * + * @param items A list of Data. + * @param name The name of the Data that we are searching for. + * + * @return the Data with the name <i>name</i>. + */ + protected Data getData(List<Data> data, String name) { + for (Data d: data) { + if (name.equals(d.getLabel())) { + return d; + } + } + + return null; + } + + + protected String getDataValue(String state, String name) { + ArtifactDescription desc = artifact.getArtifactDescription(); + + DataList[] old = desc.getOldData(); + + for (DataList list: old) { + if (list == null) { + continue; + } + Data d = getData(list.getAll(), name); + + if (d != null) { + return d.getItems()[0].getStringValue(); + } + } + + return null; + } + + /** + * This method greps the DataItem with name <i>name</i> from the list and + * returns it. + * + * @param items A list of DataItems. + * @param name The name of the DataItem that we are searching for. + * + * @return the DataItem with the name <i>name</i>. + */ + protected DataItem getDataItem(DataItem[] items, String name) { + for (DataItem item: items) { + if (name.equals(item.getLabel())) { + return item; + } + } + + return null; + } + + + public List<String> validate() { + return new ArrayList<String>(); // FIXME: What's this? + } + + + /** Create simple DefaultData with single DataItem inside. */ + public static DefaultData createDataArray(String name, String value) { + DataItem item = new DefaultDataItem( + name, + name, + value); + + return new DefaultData(name, + null, + null, + new DataItem[] {item}); + } + + + /** + * This method needs to be implemented by concrete subclasses. It should + * create a new Canvas object with a representation of <i>data</i>. + * + * @param data The data that should be displayed. + * + * @return a Canvas object that displays <i>data</i>. + */ + @Override + public abstract Canvas create(DataList data); + + + /** + * This method needs to be implemented by concrete subclasses. It should + * return the selected data. + * + * @return the selected data. + */ + protected abstract Data[] getData(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/AutoIntegerPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,119 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.validator.CustomValidator; +import com.smartgwt.client.widgets.form.validator.Validator; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class AutoIntegerPanel extends TextProvider { + + private static final long serialVersionUID = -6525461829035465820L; + + public static final String FIELD_NAME = "integer_field"; + + public static final String FIELD_DEFAULT_VALUE = "auto"; + + + protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected String dataName; + + + @Override + public Canvas create(DataList dataList) { + Data data = dataList.get(0); + this.dataName = data.getLabel(); + + Canvas label = new Label(data.getDescription()); + Canvas form = createForm(getTitle()); + Canvas submit = getNextButton(); + + VLayout layout = new VLayout(); + layout.setHeight(35); + label.setHeight(35); + + layout.addMember(label); + layout.addMember(form); + layout.addMember(submit); + layout.setMembersMargin(10); + + initDefaultValues(dataList); + + return layout; + } + + + @Override + protected void initDefaultValues(DataList dataList) { + super.initDefaultValues(dataList); + + String def = getValueAsString(); + + if (def == null || def.length() == 0) { + form.setValue(getFieldName(), FIELD_DEFAULT_VALUE); + } + } + + + protected String getTitle() { + return MSG.uesk_profile_distance(); + } + + + @Override + protected String getDataName() { + return dataName; + } + + + @Override + protected String getValueAsString() { + String v = (String) form.getValue(getFieldName()); + return v.toLowerCase(); + } + + + @Override + protected Validator getValidator() { + Validator v = new AutoIntegerValidator(); + v.setValidateOnChange(false); + + return v; + } + + + public class AutoIntegerValidator extends CustomValidator { + @Override + protected boolean condition(Object value) { + String v = (String) value; + + if (v == null || v.length() == 0) { + return false; + } + + if (v.trim().equalsIgnoreCase("auto")) { + return true; + } + + try { + Integer.parseInt(v); + return true; + } + catch (NumberFormatException nfe) { + return false; + } + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/BooleanPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,101 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.types.FieldType; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class BooleanPanel extends TextProvider { + + private static final long serialVersionUID = -8448442865635399232L; + + public static final String FIELD_NAME = "boolean_field"; + public static final int TITLE_WIDTH = 0; + + protected String dataName; + + + @Override + public Canvas create(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + this.dataName = data.getLabel(); + + VLayout layout = new VLayout(); + Label label = new Label(data.getDescription()); + Canvas form = createForm(getTitle(items[0])); + + layout.setMembersMargin(10); + layout.setHeight(35); + label.setHeight(35); + + layout.addMember(label); + layout.addMember(form); + layout.addMember(getNextButton()); + layout.setMembersMargin(10); + + initDefaultValues(dataList); + + return layout; + } + + + protected String getTitle(DataItem item) { + return item.getLabel(); + } + + + @Override + protected void initDefaultValues(DataList dataList) { + Data data = dataList.get(0); + DataItem item = data.getDefault(); + + String value = item.getStringValue(); + Boolean bool = Boolean.valueOf(value); + + if (bool) { + form.setValue(getFieldName(), bool); + } + } + + + @Override + protected FieldType getFieldType() { + return FieldType.BOOLEAN; + } + + + @Override + protected String getFieldName() { + return FIELD_NAME; + } + + + @Override + protected String getDataName() { + return dataName; + } + + + @Override + protected String getValueAsString() { + Boolean aBool = (Boolean) form.getValue(getFieldName()); + + return aBool != null ? aBool.toString() : "false"; + } + + + @Override + protected int getTitleWidth() { + return TITLE_WIDTH; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/CollectionView.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,790 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.SC; + +import com.smartgwt.client.widgets.Window; + +import com.smartgwt.client.widgets.events.CloseClickEvent; +import com.smartgwt.client.widgets.events.CloseClickHandler; + +import com.smartgwt.client.widgets.layout.Layout; +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.tab.TabSet; + +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.client.event.CollectionChangeEvent; +import de.intevation.flys.client.client.event.CollectionChangeHandler; +import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; +import de.intevation.flys.client.client.event.HasOutputModesChangeHandlers; +import de.intevation.flys.client.client.event.OutputModesChangeEvent; +import de.intevation.flys.client.client.event.OutputModesChangeHandler; +import de.intevation.flys.client.client.event.ParameterChangeEvent; +import de.intevation.flys.client.client.event.ParameterChangeHandler; + +import de.intevation.flys.client.client.services.AddArtifactService; +import de.intevation.flys.client.client.services.AddArtifactServiceAsync; +import de.intevation.flys.client.client.services.ArtifactService; +import de.intevation.flys.client.client.services.ArtifactServiceAsync; +import de.intevation.flys.client.client.services.CollectionAttributeService; +import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; +import de.intevation.flys.client.client.services.CreateCollectionService; +import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; +import de.intevation.flys.client.client.services.DescribeCollectionService; +import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; + +import de.intevation.flys.client.client.ui.ScreenLock; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.ExportMode; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.ReportMode; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Stack; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CollectionView +extends Window +implements CollectionChangeHandler, HasCollectionChangeHandlers, + OutputModesChangeHandler, HasOutputModesChangeHandlers, + ParameterChangeHandler, CloseClickHandler +{ + /** The ArtifactService used to communicate with the Artifact server. */ + protected CreateCollectionServiceAsync createCollectionService = + GWT.create(CreateCollectionService.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected ArtifactServiceAsync createArtifactService = + GWT.create(ArtifactService.class); + + /** The AddArtifactService used to add an artifact to a collection. */ + protected AddArtifactServiceAsync addArtifactService = + GWT.create(AddArtifactService.class); + + /** The DescribeCollectionService used to update the existing collection. */ + protected DescribeCollectionServiceAsync describeCollectionService = + GWT.create(DescribeCollectionService.class); + + protected CollectionAttributeServiceAsync updater = + GWT.create(CollectionAttributeService.class); + + /** The LoadArtifactService used to load recommendations*/ + protected LoadArtifactServiceAsync loadArtifactService = + GWT.create(LoadArtifactService.class); + + /** The message class that provides i18n strings. */ + protected FLYSConstants messages = GWT.create(FLYSConstants.class); + + /** The FLYS instance used to call services. */ + protected FLYS flys; + + /** The ParameterList. */ + protected ParameterList parameterList; + + /** The list of CollectionChangeHandlers. */ + protected List<CollectionChangeHandler> handlers; + + /** The list of OutputModesChangeHandlers. */ + protected List<OutputModesChangeHandler> outHandlers; + + /** The collection to be displayed. */ + protected Collection collection; + + /** The artifact that handles the parameterization. */ + protected Artifact artifact; + + protected TabSet tabs; + + /** The output tab. */ + protected Map<String, OutputTab> outputTabs; + + /** The layout. */ + protected Layout layout; + + /** Layout to show spinning wheel of joy. */ + protected VLayout lockScreen; + + protected int artifactsQueue; + protected int recommendationQueue; + protected Stack<Recommendation> newRecommendations; + + /** Values for fix analysis charts*/ + protected double currentKm; + protected double minKm; + protected double maxKm; + protected double steps; + + /** + * This constructor creates a new CollectionView that is used to display the + * <i>collection</i>. + */ + public CollectionView(FLYS flys) { + this.flys = flys; + this.tabs = new TabSet(); + this.outputTabs = new HashMap<String, OutputTab>(); + this.handlers = new ArrayList<CollectionChangeHandler>(); + this.outHandlers = new ArrayList<OutputModesChangeHandler>(); + this.layout = new VLayout(); + this.parameterList = new ParameterList( + flys, this, messages.new_project()); + this.artifactsQueue = 0; + this.recommendationQueue = 0; + this.newRecommendations = new Stack<Recommendation>(); + + this.currentKm = -1d; + this.minKm = -1d; + this.maxKm = -1d; + this.steps = -1d; + + addCollectionChangeHandler(this); + addCollectionChangeHandler(parameterList); + addCollectionChangeHandler(flys); + addOutputModesChangeHandler(this); + addOutputModesChangeHandler(parameterList); + addCloseClickHandler(this); + + parameterList.addParameterChangeHandler(this); + + init(); + } + + /** + * @param collection The collection to be displayed. + */ + public CollectionView(FLYS flys, Collection collection, Artifact artifact) { + this.flys = flys; + this.artifact = artifact; + this.collection = collection; + this.tabs = new TabSet(); + this.outputTabs = new HashMap<String, OutputTab>(); + this.handlers = new ArrayList<CollectionChangeHandler>(); + this.outHandlers = new ArrayList<OutputModesChangeHandler>(); + this.layout = new VLayout(); + + this.currentKm = -1d; + this.minKm = -1d; + this.maxKm = -1d; + this.steps = -1d; + + if (artifact != null) { + this.parameterList = new ParameterList( + flys, + this, + messages.getString(artifact.getName()), + artifact); + } + else { + this.parameterList = new ParameterList( + flys, this, messages.new_project()); + } + + this.artifactsQueue = 0; + this.newRecommendations = new Stack<Recommendation>(); + + addCollectionChangeHandler(this); + addCollectionChangeHandler(parameterList); + addCollectionChangeHandler(flys); + addOutputModesChangeHandler(this); + addOutputModesChangeHandler(parameterList); + addCloseClickHandler(this); + + parameterList.addParameterChangeHandler(this); + + init(); + + setCollection(collection); + + if (artifact != null) { + setArtifact(artifact); + } + } + + + /** + * This method handles the initial layout stuff. + */ + protected void init() { + setWidth(1010); + setHeight(700); + + setMaximized(true); + + layout.setWidth100(); + + setCanDragReposition(true); + setCanDragResize(true); + setShowMaximizeButton(true); + setKeepInParentRect(true); + + setTitle(""); + + addItem(layout); + + layout.addMember(tabs); + tabs.addTab(parameterList); + } + + protected FLYS getFlys() { + return flys; + } + + + /** + * This method registers a new CollectionChangeHandler. + * + * @param handler The new CollectionChangeHandler. + */ + @Override + public void addCollectionChangeHandler(CollectionChangeHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + /** + * This method registers a new OutputModesChangeHandler. + * + * @param handler The new OutputModesChangeHandler. + */ + @Override + public void addOutputModesChangeHandler(OutputModesChangeHandler handler) { + if (handler != null) { + outHandlers.add(handler); + } + } + + + /** + * This method calls the <code>onValueChange()</code> method of all + * registered ValueChangeHanders. + */ + protected void fireCollectionChangeEvent( + Collection old, Collection newCol) + { + for (CollectionChangeHandler handler: handlers) { + handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); + } + } + + + protected void fireOutputModesChangeEvent(OutputMode[] outputs) { + if (collection == null) { + return; + } + + for (OutputModesChangeHandler handler: outHandlers) { + handler.onOutputModesChange(new OutputModesChangeEvent(outputs)); + } + } + + + /** Disables input, grey out, show spinning wheel of joy. */ + public void lockUI() { + lockScreen = ScreenLock.lockUI(layout, lockScreen); + } + + + /** Enable input, remove grey, remove spinning wheel of joy. */ + public void unlockUI() { + ScreenLock.unlockUI(layout, lockScreen); + } + + + /** + * This method returns true, if the Collection is new and no plugins has + * been chosen. + * + * @return true, if the Collection is new. + */ + public boolean isNew() { + return collection.hasItems(); + } + + + /** + * Returns the artifact that is used for the parameterization. + * + * @return the artifact that is used for the parameterization. + */ + public Artifact getArtifact() { + return artifact; + } + + + public User getUser() { + return getFlys().getCurrentUser(); + } + + + /** + * Set the current artifact that is the master of the parameterization. + * + * @param artifact The new artifact. + */ + public void setArtifact(Artifact artifact) { + this.artifact = artifact; + + onArtifactChanged(artifact); + } + + + public void onArtifactChanged(Artifact artifact) { + artifactChanged(); + + if (artifact.isInBackground()) { + LoadingPanel p = new LoadingPanel(this, artifact); + p.addStepBackHandler(parameterList); + } + } + + + /** + * Implements the onCollectionChange() method to do update the GUI after the + * parameterization has changed. + * + * @param event The ParameterChangeEvent. + */ + @Override + public void onParameterChange(ParameterChangeEvent event) { + GWT.log("CollectionView.onParameterChange"); + setArtifact(event.getNewValue()); + } + + + protected void artifactChanged() { + Collection c = getCollection(); + + if (c != null) { + loadCollection(c); + } + else { + updateView(); + } + } + + /** + * Loads all information of a collection + * @param c the Collection + */ + private void loadCollection(Collection c) { + ArtifactDescription desc = getArtifact().getArtifactDescription(); + final Recommendation[] recom = desc.getRecommendations(); + Config config = Config.getInstance(); + String locale = config.getLocale(); + + describeCollectionService.describe(c.identifier(), locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not DESCRIBE collection."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Collection newCollection) { + GWT.log("Successfully DESCRIBED collection."); + boolean loaded = true; + for (Recommendation r: recom) { + if(!newCollection.loadedRecommendation(r)) { + loaded = false; + } + } + if (!loaded) { + loadRecommendedArtifacts(recom); + } + else { + setCollection(newCollection); + } + } + } + ); + } + + + /** + * Returns the collection of displayed by this view. + * + * @return the collection of this view. + */ + public Collection getCollection() { + return collection; + } + + + protected void setCollection(Collection collection) { + setCollection(collection, false); + } + + + /** + * Set the current collection. + * + * @param collection The new collection. + * @param suppress Whether to fire a collectionchangeevent. + */ + protected void setCollection(Collection collection, boolean suppress) { + if (collection != null && this.collection == null) { + flys.getWorkspace().addView(collection.identifier(), this); + } + + Collection tmp = this.collection; + this.collection = collection; + + setTitle(collection.getDisplayName()); + + if (!suppress) { + fireCollectionChangeEvent(tmp, this.collection); + } + } + + + @Override + public void onCollectionChange(CollectionChangeEvent event) { + if (artifactsQueue > 0) { + GWT.log("Do not update UI because we are still loading Artifacts."); + return; + } + + Collection newCol = event.getNewValue(); + + Map<String, OutputMode> outs = newCol.getOutputModes(); + + Set<String> keys = outs.keySet(); + OutputMode[] prepared = new OutputMode[outs.size()]; + + int idx = 0; + for (String outname: keys) { + prepared[idx++] = outs.get(outname); + } + + fireOutputModesChangeEvent(prepared); + + updateView(); + } + + + @Override + public void onOutputModesChange(OutputModesChangeEvent event) { + clearOutputTabs(); + OutputMode[] outs = event.getOutputModes(); + + if (outs == null) { + return; + } + + boolean hasCSV = false; + + for (OutputMode out: outs) { + addOutputTab(out.getName(), out); + + if (out instanceof ExportMode) { + ExportMode export = (ExportMode) out; + + if (export.getFacet("csv") != null) { + hasCSV = true; + parameterList.contractInfoPanel(); + } + } + } + + if (!hasCSV) { + parameterList.removeTable(); + } + } + + + /** + * Adds a new tab for the OutputMode <i>out</i>. + * + * @param name The name and title of the output. + */ + protected void addOutputTab(String name, OutputMode out) { + if (out instanceof ExportMode) { + ExportMode export = (ExportMode) out; + + if (export.getFacet("csv") != null && !parameterList.hasTable()) { + TableDataPanel p = new TableDataPanel(); + p.setUuid(collection.identifier()); + p.setName(out.getName()); + parameterList.setTable(p); + } + + return; + } + + if (out instanceof ReportMode) { + // we don't want to display report modes at all + return; + } + + GWT.log("Add new output tab for '" + name + "'"); + + String title = messages.getString(name); + OutputTab tab = out.createOutputTab(title, getCollection(), this); + + if (tab != null) { + outputTabs.put(name, tab); + } + } + + + /** + * Removes all output mode tabs from tab bar. + */ + protected void clearOutputTabs() { + GWT.log("Clear OutputTabs."); + + int num = tabs.getNumTabs(); + + for (int i = num-1; i >= 1; i--) { + tabs.removeTab(i); + } + + outputTabs.clear(); + } + + + /** + * Update the view (refresh the list of old and current data). + */ + protected void updateView() { + GWT.log("CollectionView.updateView()"); + updateOutputTabs(); + } + + + /** + * This method is used to update the tabs to show specific output modes. + */ + protected void updateOutputTabs() { + GWT.log("Update output tabs."); + if (outputTabs != null) { + Set<String> keys = outputTabs.keySet(); + + for (String key: keys) { + tabs.addTab(outputTabs.get(key)); + } + } + } + + + @Override + public void onCloseClick(CloseClickEvent event) { + if (collection != null) { + if(artifact != null) { + flys.closeProject(collection.identifier()); + } + else { + flys.getProjectList().deleteCollection(collection); + } + } + else { + hide(); + destroy(); + } + } + + + public void addArtifactToCollection(Artifact artifact) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + final Collection collection = getCollection(); + + GWT.log("CollectionView.addArtifactToCollection " + collection); + + if (collection != null) { + addArtifactService.add( + collection, artifact, locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("An error occured while adding artifact."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Collection newCollection) { + GWT.log("Successfully added artifacts."); + setCollection(newCollection, true); + } + } + ); + } + else { + // Create new collection and add artifact + final Artifact art = artifact; + createCollectionService.create( + locale, + flys.getCurrentUser().identifier(), + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create the new collection."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Collection collection) { + GWT.log("Successfully created a new collection."); + addArtifactService.add( + collection, art, locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("An error occured while adding artifact."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Collection newCollection) { + GWT.log("Successfully added artifacts."); + setCollection(newCollection); + } + } + ); + } + } + ); + } + } + + + protected void addRecommendationsToCollection() { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + final Collection collection = getCollection(); + + collection.addRecommendations(newRecommendations); + + updater.update(collection, locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + newRecommendations.removeAllElements(); + setCollection(collection); + + GWT.log("An error occured while saving recommendations."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Collection newCol) { + GWT.log("Successfully saved recommendations."); + newRecommendations.removeAllElements(); + setCollection(newCol); + } + } + ); + } + + + protected void loadRecommendedArtifacts(Recommendation[] recommendations) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + final Collection collection = getCollection(); + + Artifact masterArtifact = getArtifact(); + + if (recommendations == null) { + GWT.log("WARNING: Currently no recommendations."); + return; + } + + for (final Recommendation recommendation: recommendations) { + if (collection.loadedRecommendation(recommendation)) { + continue; + } + newRecommendations.push(recommendation); + + // XXX: UGLY! If no reference artifact given use uuid of + // current artifact as reference. + if (recommendation.getMasterArtifact() == null) { + recommendation.setMasterArtifact(masterArtifact.getUuid()); + } + + } + + loadArtifactService.loadMany( + collection, + recommendations, + null, + locale, + new AsyncCallback<Artifact[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Error loading recommendations: " + + caught.getMessage()); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Artifact[] artifacts) { + GWT.log("Loaded artifacts: " + artifacts.length); + addRecommendationsToCollection(); + } + }); + } + + + public void registerTabHandler(TabSelectedHandler tse) { + tabs.addTabSelectedHandler(tse); + } + + + public void setCurrentKm(double currentKm) { + this.currentKm = currentKm; + } + + public double getCurrentKm() { + return this.currentKm; + } + + public void setMinKm(double km) { + this.minKm = km; + } + + public double getMinKm() { + return this.minKm; + } + + public void setMaxKm(double km) { + this.maxKm = km; + } + + public double getMaxKm() { + return this.maxKm; + } + + public void setSteps(double step) { + this.steps = step; + } + + public double getSteps() { + return this.steps; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ContinuePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,92 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.LinkItem; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.AdvanceHandler; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; + +import java.util.ArrayList; +import java.util.List; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ContinuePanel extends AbstractUIProvider { + + private static final long serialVersionUID = -5882814816875137397L; + + protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected List<AdvanceHandler> advHandlers; + + + @Override + public Canvas create(DataList dataList) { + DynamicForm form = new DynamicForm(); + form.setWidth(200); + form.setHeight(35); + + LinkItem next = new LinkItem(); + next.setShowTitle(false); + next.setLinkTitle(MSG.next()); + + final ArtifactDescription desc = artifact.getArtifactDescription(); + final String[] reachable = desc.getReachableStates(); + + next.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + fireOnAdvance(reachable[0]); + } + }); + + form.setFields(next); + + return form; + } + + + @Override + public Canvas createOld(DataList dataList) { + return null; + } + + + @Override + protected Data[] getData() { + return new Data[0]; + } + + + public void addAdvanceHandler(AdvanceHandler handler) { + if (advHandlers == null) { + advHandlers = new ArrayList<AdvanceHandler>(); + } + + if (handler != null) { + advHandlers.add(handler); + } + } + + + public void fireOnAdvance(String target) { + if (advHandlers == null || advHandlers.isEmpty()) { + return; + } + + for (AdvanceHandler handler: advHandlers) { + handler.onAdvance(target); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageButton.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,49 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.events.CloseClickHandler; +import com.smartgwt.client.widgets.events.CloseClickEvent; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.User; + +/** Button that opens view of datacage (DataCageWindow). */ +public class DatacageButton extends Button implements ClickHandler { + + protected Artifact artifact; + protected User user; + protected CollectionView view; + + public DatacageButton( + String title, + Artifact artifact, + User user, + CollectionView view + ) { + super(title); + + this.artifact = artifact; + this.user = user; + this.view = view; + + addClickHandler(this); + } + + + public void onClick(ClickEvent event) { + // TODO: fetch outs! + String outs = ""; + + final DatacageWindow dc = new DatacageWindow( + artifact, user, outs, view); + dc.addCloseClickHandler(new CloseClickHandler() { + public void onCloseClick(CloseClickEvent event) { + dc.destroy(); + } + }); + dc.show(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DatacagePairWidget.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,107 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ToLoad; +import de.intevation.flys.client.shared.model.User; + + +/** + * Widget showing two Datacages and a add-this-button. + * Insert a record into a listgrid when add-this-button clicked. + */ +public class DatacagePairWidget +extends VLayout +{ + /** i18n resource. */ + protected FLYSConstants MSG = + GWT.create(FLYSConstants.class); + + /** The "remote" ListGrid to insert data to when add-button is clicked. */ + protected ListGrid grid; + + /** First (upper) DataCage Grid. */ + protected DatacageWidget firstDatacageWidget; + + /** Second (lower) DataCage Grid. */ + protected DatacageWidget secondDatacageWidget; + + + /** + * + * @param artifact Artifact to query datacage with. + * @param user User to query datacage with. + * @param outs outs to query datacage with. + * @param grid Grid into which to insert selection of pairs. + */ + public DatacagePairWidget(Artifact artifact, + User user, + String outs, + ListGrid grid) { + this.grid = grid; + + HLayout hLayout = new HLayout(); + firstDatacageWidget = new DatacageWidget( + artifact, + user, + outs, + "load-system:true", + false); + secondDatacageWidget = new DatacageWidget( + artifact, + user, + outs, + "load-system:true", + false); + firstDatacageWidget.setIsMutliSelectable(false); + secondDatacageWidget.setIsMutliSelectable(false); + + hLayout.addMember(firstDatacageWidget); + hLayout.addMember(secondDatacageWidget); + + // TODO: icon + Button plusBtn = new Button(MSG.datacage_add_pair()); + plusBtn.setAutoFit(true); + plusBtn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + plusClicked(); + } + }); + + addMember(hLayout); + addMember(plusBtn); + } + + + /** + * Callback for add-button. + * Fires to load for every selected element and handler. + */ + public void plusClicked() { + ToLoad toLoad1 = firstDatacageWidget.getSelection(); + ToLoad toLoad2 = secondDatacageWidget.getSelection(); + + if (toLoad1 == null || toLoad2 == null || + toLoad1.toRecommendations().isEmpty() || + toLoad2.toRecommendations().isEmpty()) { + SC.say(MSG.warning_select_two_values()); + return; + } + + grid.addData(new RecommendationPairRecord( + toLoad1.toRecommendations().get(0), + toLoad2.toRecommendations().get(0))); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DatacagePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,94 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.List; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public abstract class DatacagePanel extends TextProvider { + + private static final long serialVersionUID = 6937994648371673222L; + + protected String dataName; + + protected User user; + + protected DatacageWidget widget; + + + public DatacagePanel() { + super(); + } + + + public DatacagePanel(User user) { + super(); + this.user = user; + } + + + @Override + public Canvas create(DataList dataList) { + Data data = dataList.get(0); + this.dataName = data.getLabel(); + + createWidget(); + + Canvas label = new Label(data.getDescription()); + Canvas submit = getNextButton(); + VLayout layout = new VLayout(); + label.setHeight(25); + + layout.addMember(label); + layout.addMember(submit); + layout.setMembersMargin(10); + + return layout; + } + + + protected void createWidget() { + widget = new DatacageWidget( + artifact, + getUser(), + getOuts(), + getParameters(), + false); + + widget.setHeight100(); + + helperContainer.addMember(widget); + } + + + @Override + public List<String> validate() { + return new ArrayList<String>(); + } + + + public User getUser() { + return user; + } + + + public String getOuts() { + return null; + } + + + public String getParameters() { + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageTwinPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,492 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.StepForwardEvent; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.client.services.RemoveArtifactServiceAsync; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Recommendation.Facet; +import de.intevation.flys.client.shared.model.Recommendation.Filter; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +// TODO Probably better to branch off AbstractUIProvider. +// TODO Merge with other datacage-widget impls. +/** + * Panel containing a Grid and a "next" button. The Grid is fed by a + * DatacagePairWidget which is put in the input-helper area. + */ +public class DatacageTwinPanel +extends TextProvider { + + private static final long serialVersionUID = 8906629596491827857L; + + protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected String dataName; + + protected User user; + + /** ListGrid that displays user-selected pairs to build differences with. */ + protected ListGrid differencesList; + + /** + * List to track previously selected but now removed pairs. (Needed to + * be able to identify artifacts that can be removed from the collection. + */ + protected List<RecommendationPairRecord> removedPairs = + new ArrayList<RecommendationPairRecord>(); + + /** Service handle to clone and add artifacts to collection. */ + LoadArtifactServiceAsync loadArtifactService = GWT.create( + de.intevation.flys.client.client.services.LoadArtifactService.class); + + /** Service to remove artifacts from collection. */ + RemoveArtifactServiceAsync removeArtifactService = GWT.create( + de.intevation.flys.client.client.services.RemoveArtifactService.class); + + + public DatacageTwinPanel(User user) { + super(); + this.user = user; + } + + + /** + * Remove first occurrence of "[" and "]" (if both do occur). + * @param value String to be stripped of [] (might be null). + * @return input string but with [ and ] removed, or input string if no + * brackets were found. + * @see StringUtil.unbracket + */ + public static final String unbracket(String value) { + // null- guard. + if (value == null) return value; + + int start = value.indexOf("["); + int end = value.indexOf("]"); + + if (start < 0 || end < 0) { + return value; + } + + value = value.substring(start + 1, end); + + return value; + } + + + /** + * Create a recommendation from a string representation of it. + * @TODO describe format of input string + * @param from string in format as shown above. + * @return recommendation from input string. + */ + public Recommendation createRecommendationFromString(String from) { + // TODO Construct "real" filter. + String[] parts = unbracket(from).split(";"); + Recommendation.Filter filter = new Recommendation.Filter(); + Recommendation.Facet facet = new Recommendation.Facet( + parts[1], + parts[2]); + + List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet> + (); + facets.add(facet); + filter.add("longitudinal_section", facets); + Recommendation r = new Recommendation("waterlevel", parts[0], + this.artifact.getUuid(), filter); + r.setDisplayName(parts[3]); + return r; + } + + + /** + * Add RecomendationPairRecords from input String to the ListGrid. + */ + public void populateGridFromString(String from){ + // Split this string. + // Create according recommendations and display strings. + String[] recs = from.split("#"); + if (recs.length % 2 != 0) return; + for (int i = 0; i < recs.length; i+=2) { + Recommendation minuend = + createRecommendationFromString(recs[i+0]); + Recommendation subtrahend = + createRecommendationFromString(recs[i+1]); + + RecommendationPairRecord pr = new RecommendationPairRecord( + minuend, subtrahend); + // This Recommendation Pair comes from the data string and was thus + // already cloned. + pr.setIsAlreadyLoaded(true); + this.differencesList.addData(pr); + } + } + + + /** + * Creates the graphical representation and interaction widgets for the data. + * @param dataList the data. + * @return graphical representation and interaction widgets for data. + */ + @Override + public Canvas create(DataList dataList) { + GWT.log("createData()"); + + Canvas widget = createWidget(); + Canvas submit = getNextButton(); + + VLayout layout = new VLayout(); + HLayout helperLayout = new HLayout(); + helperLayout.addMember(new DatacagePairWidget(this.artifact, + user, "waterlevels", differencesList)); + + layout.addMember(widget); + layout.addMember(submit); + layout.setMembersMargin(10); + this.helperContainer.addMember(helperLayout); + + // Find old data, if any, handle "diffids". + Data data = dataList.get(0); + this.dataName = data.getLabel(); + for (int i = 0; i < dataList.size(); i++) { + if (dataList.get(i) != null && dataList.get(i).getItems() != null) { + if (dataList.get(i).getItems() != null) { + populateGridFromString( + dataList.get(i).getItems()[0].getStringValue()); + } + } + } + + return layout; + } + + + /** + * Validates the selection. + * @return List of internationalized errror messages (if any). + */ + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + if (differencesList.getRecords().length == 0) { + errors.add(MSG.error_no_waterlevel_pair_selected()); + } + // Check whether minuend and subtrahend are equal. + for (ListGridRecord record: differencesList.getRecords()) { + RecommendationPairRecord r = (RecommendationPairRecord) record; + if (r.getFirst().equals(r.getSecond())) { + errors.add(MSG.error_same_waterlevels_in_pair()); + } + } + + return errors; + } + + + /** + * Creates layout with grid that displays selection inside. + */ + public Canvas createWidget() { + VLayout layout = new VLayout(); + differencesList = new ListGrid(); + + differencesList.setCanEdit(false); + differencesList.setCanSort(false); + differencesList.setShowHeaderContextMenu(false); + differencesList.setHeight(150); + differencesList.setShowAllRecords(true); + + ListGridField nameField = new ListGridField("first", "Minuend"); + ListGridField capitalField = new ListGridField("second", "Subtrahend"); + // Track removed rows, therefore more or less reimplement + // setCanRecomeRecords. + final ListGridField removeField = + new ListGridField("_removeRecord", "Remove Record"){{ + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; + + differencesList.setFields(new ListGridField[] {nameField, + capitalField, removeField}); + + differencesList.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + trackRemoved(event.getRecord()); + event.getViewer().removeData(event.getRecord()); + } + }); + layout.addMember(differencesList); + + return layout; + } + + + /** + * Add record to list of removed records. + */ + public void trackRemoved(Record r) { + RecommendationPairRecord pr = (RecommendationPairRecord) r; + this.removedPairs.add(pr); + } + + + /** + * Validates data, does nothing if invalid, otherwise clones new selected + * waterlevels and add them to collection, forward the artifact. + */ + @Override + public void onClick(ClickEvent e) { + GWT.log("DatacageTwinPanel.onClick"); + + List<String> errors = validate(); + if (errors != null && !errors.isEmpty()) { + showErrors(errors); + return; + } + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + ListGridRecord[] records = differencesList.getRecords(); + + List<Recommendation> ar = new ArrayList<Recommendation>(); + List<Recommendation> all = new ArrayList<Recommendation>(); + + for (ListGridRecord record : records) { + RecommendationPairRecord r = + (RecommendationPairRecord) record; + // Do not add "old" recommendations. + if (!r.isAlreadyLoaded()) { + // Check whether one of those is a dike or similar. + // TODO differentiate and merge: new clones, new, old. + Recommendation firstR = r.getFirst(); + if(firstR.getIDs() != null) { + GWT.log("First IDs: " + firstR.getIDs() + " factory: " + + firstR.getFactory()); + } + if(firstR.getIDs() != null) { + // These do not get cloned but loaded ("spawned"). + firstR.setFactory("staticwkms"); + } + else { + firstR.setFactory("waterlevel"); + } + Recommendation secondR = r.getSecond(); + if(secondR.getIDs() != null) { + GWT.log("Second IDs: " + secondR.getIDs() + " factory: " + + secondR.getFactory()); + } + if (secondR.getIDs() != null) { + // These do not get cloned but loaded ("spawned"). + secondR.setFactory("staticwkms"); + } + else { + secondR.setFactory("waterlevel"); + } + + ar.add(firstR); + ar.add(secondR); + } + else { + all.add(r.getFirst()); + all.add(r.getSecond()); + } + } + + final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]); + final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]); + + // Find out whether "old" artifacts have to be removed. + List<String> artifactIdsToRemove = new ArrayList<String>(); + for (RecommendationPairRecord rp: this.removedPairs) { + Recommendation first = rp.getFirst(); + Recommendation second = rp.getSecond(); + + for (Recommendation recommendation: toUse) { + if (first != null && first.getIDs().equals(recommendation.getIDs())) { + first = null; + } + if (second != null && second.getIDs().equals(recommendation.getIDs())) { + second = null; + } + + if (first == null && second == null) { + break; + } + } + if (first != null) { + artifactIdsToRemove.add(first.getIDs()); + } + if (second != null) { + artifactIdsToRemove.add(second.getIDs()); + } + } + + // Remove old artifacts, if any. Do this asychronously without much + // feedback. + for(final String uuid: artifactIdsToRemove) { + removeArtifactService.remove(this.collection, + uuid, + locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("RemoveArtifact (" + uuid + ") failed."); + } + @Override + public void onSuccess(Collection collection) { + GWT.log("RemoveArtifact succeeded"); + } + }); + } + + // Clone new ones (and spawn statics), go forward. + loadArtifactService.loadMany( + this.collection, + toClone, + //"staticwkms" and "waterlevel" + null, + locale, + new AsyncCallback<Artifact[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Failure of cloning with factories!"); + } + @Override + public void onSuccess(Artifact[] artifacts) { + GWT.log("Successfully cloned " + toClone.length + + " with factories."); + + fireStepForwardEvent(new StepForwardEvent( + getData(toClone, artifacts, toUse))); + } + }); + } + + + /** + * Create Data and DataItem from selection (a long string with identifiers + * to construct diff-pairs). + * + * @param newRecommendations "new" recommendations (did not survive a + * backjump). + * @param newArtifacts artifacts cloned from newRecommendations. + * @param oldRecommendations old recommendations that survived a backjump. + * + * @return dataitem with a long string with identifiers to construct + * diff-pairs. + */ + protected Data[] getData( + Recommendation[] newRecommendations, + Artifact[] newArtifacts, + Recommendation[] oldRecommendations) + { + // Construct string with info about selections. + String dataItemString = ""; + for (int i = 0; i < newRecommendations.length; i++) { + Recommendation r = newRecommendations[i]; + Artifact newArtifact = newArtifacts[i]; + String uuid = newArtifact.getUuid(); + r.setMasterArtifact(uuid); + if (i>0) dataItemString += "#"; + + dataItemString += createDataString(uuid, r); + } + + for (int i = 0; i < oldRecommendations.length; i++) { + Recommendation r = oldRecommendations[i]; + String uuid = r.getIDs(); + if (dataItemString.length() > 0) dataItemString += "#"; + + dataItemString += createDataString(uuid, r); + } + + // TODO some hassle could be resolved by using multiple DataItems + // (e.g. one per pair). + DataItem item = new DefaultDataItem(dataName, dataName, dataItemString); + return new Data[] { new DefaultData( + dataName, null, null, new DataItem[] {item}) }; + } + + + /** + * Creates part of the String that encodes minuend or subtrahend. + * @param artifact Artifacts UUID. + * @param recommendation Recommendation to wrap in string. + */ + protected String createDataString( + String artifact, + Recommendation recommendation) + { + Filter filter = recommendation.getFilter(); + Facet f = null; + + if(filter != null) { + Map<String, List<Facet>> outs = filter.getOuts(); + Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); + + for (Map.Entry<String, List<Facet>> entry: entries) { + List<Facet> fs = entry.getValue(); + + f = fs.get(0); + if (f != null) { + break; + } + } + + return "[" + artifact + ";" + + f.getName() + + ";" + + f.getIndex() + + ";" + + recommendation.getDisplayName() + "]"; + } + else { + return "[" + + artifact + + ";staticwkms;0;" + + recommendation.getDisplayName() + "]"; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,504 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.types.TreeModelType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.grid.HoverCustomizer; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tree.Tree; +import com.smartgwt.client.widgets.tree.TreeGrid; +import com.smartgwt.client.widgets.tree.TreeNode; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.DatacageDoubleClickHandler; +import de.intevation.flys.client.client.event.DatacageHandler; +import de.intevation.flys.client.client.services.MetaDataService; +import de.intevation.flys.client.client.services.MetaDataServiceAsync; +import de.intevation.flys.client.client.ui.ScreenLock; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.AttrList; +import de.intevation.flys.client.shared.model.DataCageNode; +import de.intevation.flys.client.shared.model.DataCageTree; +import de.intevation.flys.client.shared.model.ToLoad; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.List; +import java.util.MissingResourceException; +import java.util.Stack; + +// TODO: refactor, extract ~DataCageGrid +/** + * Display tree of, for example, previous calculations and allows + * selection in order to access/clone these. + */ +public class DatacageWidget +extends VLayout +{ + public static final int MAX_OPEN = 30; + + protected MetaDataServiceAsync metaDataService = + GWT.create(MetaDataService.class); + + protected FLYSConstants messages = + GWT.create(FLYSConstants.class); + + protected Artifact artifact; + protected User user; + protected String outs; + protected String parameters; + + protected TreeGrid treeGrid; + protected Tree tree; + + protected ToLoad toLoad; + + protected List<DatacageHandler> handlers; + protected List<DatacageDoubleClickHandler> doubleHandlers; + + /** Layout to show spinning wheel of joy. */ + protected VLayout lockScreen; + + + public DatacageWidget() { + handlers = new ArrayList<DatacageHandler>(); + doubleHandlers = new ArrayList<DatacageDoubleClickHandler>(); + } + + + public DatacageWidget(Artifact artifact, User user) { + this(artifact, user, null); + } + + public DatacageWidget(Artifact artifact, User user, String outs) { + this(artifact, user, outs, true); + } + + public DatacageWidget( + Artifact artifact, + User user, + String outs, + boolean showButton + ) { + this(artifact, user, outs, null, showButton); + } + + + public DatacageWidget( + Artifact artifact, + User user, + String outs, + String parameters, + boolean showButton + ) { + this(); + + this.artifact = artifact; + this.user = user; + this.outs = outs; + this.parameters = parameters; + + toLoad = new ToLoad(); + + setWidth100(); + + tree = new Tree(); + tree.setModelType(TreeModelType.CHILDREN); + tree.setNameProperty("name"); + tree.setIdField("id"); + tree.setChildrenProperty("children-nodes"); + tree.setShowRoot(false); + + treeGrid = new TreeGrid(); + treeGrid.setLoadDataOnDemand(false); + treeGrid.setWidth100(); + treeGrid.setHeight100(); + treeGrid.setShowRoot(false); + treeGrid.setNodeIcon("[SKIN]/../blank.gif"); + treeGrid.setShowConnectors(true); + treeGrid.setLoadingMessage(messages.databasket_loading()); + treeGrid.setEmptyMessage(messages.databasket_loading()); + treeGrid.setLoadingDataMessage(messages.databasket_loading()); + + treeGrid.setHoverMoveWithMouse(true); + treeGrid.setCanHover(true); + treeGrid.setShowHover(true); + treeGrid.setHoverOpacity(75); + treeGrid.setHoverWidth(120); + + treeGrid.setHoverCustomizer(new HoverCustomizer() { + @Override + public String hoverHTML(Object value, + ListGridRecord record, + int rowNum, + int colNum + ) { + if(record instanceof TreeNode) { + TreeNode hoveredTreeNode = (TreeNode)record; + String info = hoveredTreeNode.getAttribute("info"); + if (info == null) { + info = hoveredTreeNode.getName(); + } + return info; + } + else { + return "";// should not happen + } + } + }); + + treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { + @Override + public void onRecordDoubleClick(RecordDoubleClickEvent event) { + doubleClickedOnTree(event); + } + }); + + addMember(treeGrid); + + if (showButton) { + addMember(createPlusButton()); + } + + triggerTreeBuilding(); + } + + public void lockUI() { + lockScreen = ScreenLock.lockUI(this, lockScreen); + } + + /** Enable input, remove grey, remove spinning wheel of joy. */ + public void unlockUI() { + ScreenLock.unlockUI(this, lockScreen); + } + + /** + * @param handler Handler to be added (notified on add-action). + */ + public DatacageWidget(Artifact artifact, User user, String outs, + DatacageHandler handler) { + this(artifact, user, outs); + this.addDatacageHandler(handler); + } + + + public DatacageWidget( + Artifact artifact, + User user, + String outs, + DatacageHandler handler, + String parameters + ) { + this(artifact, user, outs, handler); + this.parameters = parameters; + } + + + /** + * Sets whether more than one item can be selected. + * @param multi if true, allow mutliple selections. + */ + public void setIsMutliSelectable(boolean multi) { + if (multi) { + treeGrid.setSelectionType(SelectionStyle.MULTIPLE); + } + else { + treeGrid.setSelectionType(SelectionStyle.SINGLE); + } + } + + + /** + * @param handler Handler to be added (notified on add-action). + */ + public void addDatacageHandler(DatacageHandler handler) { + if (!handlers.contains(handler)) { + handlers.add(handler); + } + } + + + /** + * @param h Handler to be added (notified on Double click on node). + */ + public void addDatacageDoubleClickHandler(DatacageDoubleClickHandler h) { + if (!doubleHandlers.contains(h)) { + doubleHandlers.add(h); + } + } + + + /** + * @param handler Handler to remove from list. + */ + public void removeDatacageHandler(DatacageHandler handler) { + handlers.remove(handler); + } + + + public ToLoad getToLoad() { + return toLoad; + } + + + public ToLoad getSelection() { + // Reset content of toLoads. + toLoad = new ToLoad(); + + if (treeGrid == null) { + return toLoad; + } + + ListGridRecord [] selection = treeGrid.getSelectedRecords(); + + if (selection != null) { + for (ListGridRecord record: selection) { + if (record instanceof TreeNode) { + collectToLoads((TreeNode)record); + } + } + } + + return toLoad; + } + + + /** + * Returns the titles of selected items (if any). + */ + public String[] getSelectionTitles() { + if (treeGrid == null) { + return new String[] {}; + } + + ListGridRecord [] selection = treeGrid.getSelectedRecords(); + + if (selection == null) { + return new String[] {}; + } + + List<String> titleList = new ArrayList<String>(); + for (ListGridRecord record: selection) { + if (record instanceof TreeNode) { + titleList.add(((TreeNode)record).getAttribute("name")); + } + } + + return titleList.toArray(new String[titleList.size()]); + } + + + /** + * Callback for add-button. + * Fires to load for every selected element and handler. + */ + public void plusClicked() { + if (!getSelection().isEmpty()) { + fireToLoad(); + } + } + + + protected Button createPlusButton() { + Button plusBtn = new Button(messages.datacageAdd()); + plusBtn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + plusClicked(); + } + }); + return plusBtn; + } + + + protected void fireToLoad() { + for (DatacageHandler handler: handlers) { + handler.toLoad(toLoad); + } + } + + + /** Notify DatacageDoubleClickHandlers that a doubleclick happened. */ + protected void fireOnDoubleClick() { + for (DatacageDoubleClickHandler handler: doubleHandlers) { + handler.onDoubleClick(toLoad); + } + } + + + protected void doubleClickedOnTree(RecordDoubleClickEvent event) { + TreeNode node = (TreeNode)event.getRecord(); + collectToLoads(node); + fireOnDoubleClick(); + } + + + /** + * Adds to toLoad, from info in node. + * Afterwards, add all children of node to stack to parse (next time + * collectToLoads is called). + */ + protected void collectToLoads(TreeNode node) { + Stack<TreeNode> stack = new Stack<TreeNode>(); + + stack.push(node); + + while (!stack.isEmpty()) { + node = stack.pop(); + String factory = node.getAttribute("factory"); + if (factory != null) { // we need at least a factory + String artifact = node.getAttribute("artifact-id"); + String out = node.getAttribute("out"); + String name = node.getAttribute("facet"); + String ids = node.getAttribute("ids"); + String displayname = node.getAttribute("name"); + String debugAttributeValues = ""; + for (String attr: node.getAttributes()) { + debugAttributeValues += ("[" + attr +": " + + node.getAttributeAsString(attr) + "] "); + } + GWT.log("DatacageWidget.collectToLoad, attributes are " + + debugAttributeValues); + + toLoad.add(artifact, + factory, + out, + name, + ids, + displayname); + } + TreeNode [] children = tree.getChildren(node); + if (children != null) { + for (TreeNode child: children) { + stack.push(child); + } + } + } + } + + + /** Get meta-data and populate tree with it. */ + protected void triggerTreeBuilding() { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + String artifactId = artifact.getUuid(); + String userId = (user != null) ? user.identifier() : null; + + lockUI(); + + metaDataService.getMetaData( + locale, + artifactId, + userId, + outs, + parameters, + new AsyncCallback<DataCageTree>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not load meta data."); + SC.warn(caught.getMessage()); + unlockUI(); + } + + @Override + public void onSuccess(DataCageTree dcTree) { + GWT.log("Successfully loaded meta data."); + IdGenerator idGenerator = new IdGenerator(); + DataCageNode dcRoot = dcTree.getRoot(); + TreeNode root = buildRecursiveChildren( + dcRoot, idGenerator); + tree.setRoot(root); + + TreeNode[] nodes = tree.getChildren(root); + for (TreeNode node: nodes) { + if (node.getAttribute("factory") == null && + !tree.hasChildren(node)) { + node.setIsFolder(true); + } + } + + if (idGenerator.current() < MAX_OPEN) { + tree.openAll(); + } + treeGrid.setData(tree); + unlockUI(); + } + }); + } + + private static final class IdGenerator { + protected int current; + + public IdGenerator() { + } + + public int next() { + return current++; + } + + public int current() { + return current; + } + } // class IdGenerator + + private String i18n(String s) { + if (!(s.startsWith("${") && s.endsWith("}"))) { + return s; + } + + s = s.substring(2, s.length()-1); + + try { + return messages.getString(s); + } + catch (MissingResourceException mre) { + GWT.log("cannot find i18n for + '" + s + "'"); + return s; + } + } + + protected TreeNode buildRecursiveChildren( + DataCageNode node, + IdGenerator idGenerator + ) { + TreeNode tn = new TreeNode(); + tn.setAttribute("id", idGenerator.next()); + + List<DataCageNode> children = node.getChildren(); + + if (children != null) { + TreeNode [] tns = new TreeNode[children.size()]; + for (int i = 0; i < tns.length; ++i) { + DataCageNode child = children.get(i); + tns[i] = buildRecursiveChildren(child, idGenerator); + } + tn.setAttribute("children-nodes", tns); + } + + tn.setAttribute("name", i18n(node.getDescription())); + tn.setAttribute("facet", node.getName()); + + AttrList attrs = node.getAttributes(); + if (attrs != null) { + for (int i = 0, N = attrs.size(); i < N; ++i) { + String key = attrs.getKey(i); + String value = attrs.getValue(i); + tn.setAttribute(key, value); + } + } + + return tn; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWindow.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,201 @@ +package de.intevation.flys.client.client.ui; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Window; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.client.event.DatacageHandler; +import de.intevation.flys.client.client.event.DatacageDoubleClickHandler; +import de.intevation.flys.client.client.event.HasRedrawRequestHandlers; +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.event.RedrawRequestEvent; +import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; + +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.ToLoad; +import de.intevation.flys.client.shared.model.User; +import de.intevation.flys.client.shared.model.Recommendation; + + +/** Window that access the datacageservice and shows a datacagewidget. */ +public class DatacageWindow +extends Window +implements DatacageHandler, + DatacageDoubleClickHandler, + HasRedrawRequestHandlers +{ + /** i18ner. */ + protected FLYSConstants messages = + GWT.create(FLYSConstants.class); + + /** Service to create/clone artifacts. */ + protected LoadArtifactServiceAsync loadService = + GWT.create(LoadArtifactService.class); + + protected CollectionView view; + + protected List<RedrawRequestHandler> handlers; + + protected int inProgress; + + + public DatacageWindow( + Artifact artifact, + User user, + String outs, + CollectionView view + ) { + this.view = view; + this.handlers = new ArrayList<RedrawRequestHandler>(); + this.inProgress = 0; + + setWidth(400); + setHeight(500); + + DatacageWidget dw = new DatacageWidget( + artifact, + user, + outs, + "load-system:true", + true); + dw.addDatacageHandler(this); + dw.addDatacageDoubleClickHandler(this); + + addItem(dw); + + String river = findRiver(artifact); + // TODO: i18n + setTitle("Datenkorb: " + river); + setShowMinimizeButton(false); + setIsModal(true); + setShowModalMask(true); + setCanDragResize(true); + + centerInPage(); + } + + + @Override + public void toLoad(ToLoad toLoad) { + destroy(); + List<Recommendation> recs = toLoad.toRecommendations(); + loadArtifacts(recs); + } + + + @Override + public void onDoubleClick(ToLoad toLoad) { + destroy(); + List<Recommendation> recs = toLoad.toRecommendations(); + loadArtifacts(recs); + } + + + @Override + public void addRedrawRequestHandler(RedrawRequestHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + protected String findRiver(Artifact artifact) { + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList [] data = adescr.getOldData(); + + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + if (dl.getState().equals("state.winfo.river")) { + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + DataItem [] di = d.getItems(); + if (di != null && di.length == 1) { + return d.getItems()[0].getStringValue(); + } + } + } + } + } + + return ""; + } + + + protected void decreateInProgress() { + if (this.inProgress > 0) { + this.inProgress--; + } + + if (this.inProgress == 0) { + fireRedrawRequest(); + } + } + + + protected void fireRedrawRequest() { + RedrawRequestEvent evt = new RedrawRequestEvent(Type.DEFAULT); + + for (RedrawRequestHandler handler: handlers) { + handler.onRedrawRequest(evt); + } + } + + + protected void loadArtifacts(List<Recommendation> recommendations) { + Config cfg = Config.getInstance(); + + final Collection collection = view.getCollection(); + final Artifact masterArtifact = view.getArtifact(); + final String locale = cfg.getLocale(); + + this.inProgress = recommendations.size(); + + for (final Recommendation recommendation: recommendations) { + // XXX: UGLY! If no reference artifact given use uuid of + // current artifact as reference. + if (recommendation.getMasterArtifact() == null) { + recommendation.setMasterArtifact(masterArtifact.getUuid()); + } + + final String factory = recommendation.getFactory(); + + GWT.log("Load new artifact with factory: " + factory); + + loadService.load( + collection, + recommendation, + factory, + locale, + new AsyncCallback<Artifact>() { + public void onFailure(Throwable caught) { + decreateInProgress(); + GWT.log("Create-artifact failed: " + caught.getMessage()); + SC.warn(caught.getMessage()); + } + + public void onSuccess(Artifact artifact) { + decreateInProgress(); + GWT.log("Created new artifact: " + artifact.getUuid()); + } + }); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DemDatacagePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,88 @@ +package de.intevation.flys.client.client.ui; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.ToLoad; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.List; + + +public class DemDatacagePanel extends DatacagePanel { + + private static final long serialVersionUID = -2301633938080411687L; + + public static final String OUT = "floodmap"; + public static final String PARAMETERS = "dem:true"; + + + public DemDatacagePanel() { + super(); + } + + + public DemDatacagePanel(User user) { + super(user); + } + + + @Override + protected void createWidget() { + super.createWidget(); + widget.setIsMutliSelectable(false); + } + + + @Override + public User getUser() { + return null; + } + + + @Override + public String getOuts() { + return OUT; + } + + + @Override + public String getParameters() { + return PARAMETERS; + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + + Recommendation r = getSelectedRecommendation(); + if (r == null) { + errors.add(MSG.requireDGM()); + } + + return errors; + } + + + @Override + protected Data[] getData() { + Recommendation r = getSelectedRecommendation(); + + DataItem item = new DefaultDataItem(dataName, dataName, r.getIDs()); + return new Data[] { new DefaultData( + dataName, null, null, new DataItem[] { item }) }; + } + + + protected Recommendation getSelectedRecommendation() { + ToLoad toLoad = widget.getSelection(); + List<Recommendation> recoms = toLoad.toRecommendations(); + + return recoms != null && recoms.size() >= 1 ? recoms.get(0) : null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DigitizePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,260 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ParentMovedEvent; +import com.smartgwt.client.widgets.events.ParentMovedHandler; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.events.VisibilityChangedEvent; +import com.smartgwt.client.widgets.events.VisibilityChangedHandler; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.MapInfoService; +import de.intevation.flys.client.client.services.MapInfoServiceAsync; +import de.intevation.flys.client.client.ui.map.FloodMap; +import de.intevation.flys.client.client.ui.map.MapPanel; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.MapInfo; + +import java.util.List; + +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.control.Attribution; +import org.gwtopenmaps.openlayers.client.layer.TransitionEffect; +import org.gwtopenmaps.openlayers.client.layer.WMS; +import org.gwtopenmaps.openlayers.client.layer.WMSOptions; +import org.gwtopenmaps.openlayers.client.layer.WMSParams; + + +public class DigitizePanel +extends SelectProvider +implements TabSelectedHandler, VisibilityChangedHandler { + + private static final long serialVersionUID = 3529775660871273314L; + + protected MapInfoServiceAsync mapInfo = GWT.create(MapInfoService.class); + + protected FloodMap floodMap; + + protected MapPanel mapPanel; + + public static final String UESK_BARRIERS = "uesk.barriers"; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public DigitizePanel() { + } + + + @Override + public Canvas create(DataList list) { + helperContainer.addVisibilityChangedHandler(this); + + DataList clone = (DataList) list.clone(); + List<Data> all = clone.getAll(); + all.remove(UESK_BARRIERS); + + Canvas widget = createWidget(list); + + final Config cfg = Config.getInstance(); + final String locale = cfg.getLocale(); + + String river = getDataValue("state.winfo.river", "river"); + mapInfo.getMapInfo(locale, river, new AsyncCallback<MapInfo>() { + @Override + public void onFailure(Throwable caught) { + String msg = caught.getMessage(); + + GWT.log("Error while fetching MapInfo: " + msg); + SC.warn(FLYS.getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(MapInfo info) { + createMapWidget(info); + } + }); + + return widget; + } + + + /** + * This method creates the content of the widget. + * + * @param data The {@link DataList} object. + * + * @return a combobox. + */ + @Override + protected Canvas createWidget(DataList data) { + GWT.log("DigitizePanel - createWidget()"); + + VLayout layout = new VLayout(); + layout.setAlign(VerticalAlignment.TOP); + layout.setHeight(25); + + int size = data.size(); + + for (int i = 0; i < size; i++) { + Data d = data.get(i); + + Label label = new Label(d.getDescription()); + label.setValign(VerticalAlignment.TOP); + label.setHeight(20); + label.setWidth(400); + + layout.addMember(label); + layout.addMember(getNextButton()); + } + + layout.setAlign(VerticalAlignment.TOP); + + return layout; + } + + + @Override + protected Data[] getData() { + final Data[] total = new Data[1]; + + if (floodMap != null) { + DataItem item = new DefaultDataItem( + UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON()); + total[0] = new DefaultData( + UESK_BARRIERS, null, null, new DataItem[] { item }); + } + else { + // Happens when OpenLayers is missing + GWT.log("floodMap is null -> OpenLayers missing?"); + } + + return total; + } + + + public void createMapWidget(MapInfo mapInfo) { + mapPanel = new MapPanel(mapInfo, true); + + floodMap = mapPanel.getFloodMap(); + Map map = floodMap.getMap(); + + helperContainer.addResizedHandler(new ResizedHandler() { + @Override + public void onResized(ResizedEvent event) { + mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); + } + }); + helperContainer.addParentMovedHandler(new ParentMovedHandler() { + @Override + public void onParentMoved(ParentMovedEvent event) { + mapPanel.getFloodMap().updateSize(); + } + }); + helperContainer.addVisibilityChangedHandler(new VisibilityChangedHandler() { + @Override + public void onVisibilityChanged(VisibilityChangedEvent event) { + mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); + } + }); + helperContainer.addMember(mapPanel); + + parameterList.registerCollectionViewTabHandler(this); + + WMS axis = getLayer( + mapInfo.getWmsUrl(), mapInfo.getWmsLayers(), + mapInfo.getProjection(), false, true); + WMS back = getLayer( + mapInfo.getBackgroundWmsUrl(), mapInfo.getBackgroundWmsLayers(), + mapInfo.getProjection(), false, false); + + map.addLayer(back); + map.addLayer(axis); + + String hws = getDataValue("state.winfo.uesk.dc-hws", "uesk.hws"); + if (hws != null && hws.length() > 0) { + WMS hwsLayer = getLayer( + //TODO: Use Mapinfo to get hws layer infos. + mapInfo.getWmsUrl().replace("river", "user"), + "ms_layer-hws-lines" + artifact.getUuid(), + mapInfo.getProjection(), + false, true); + map.addLayer(hwsLayer); + } + String userRgd = getDataValue("state.winfo.uesk.user-rgd", "uesk.user-rgd"); + if (userRgd != null && userRgd.length() > 0) { + WMS userLayer = getLayer( + //TODO: Use Mapinfo to get hws layer infos. + mapInfo.getWmsUrl().replace("river", "user"), + "ms_layer-user-rgd" + artifact.getUuid(), + mapInfo.getProjection(), + false, true); + map.addLayer(userLayer); + } + map.addControl(new Attribution()); + map.zoomToMaxExtent(); + + mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); + } + + + protected WMS getLayer(String url, String layers, String proj, boolean isBaseLayer, boolean singleTiled) { + final WMSParams params = new WMSParams(); + params.setLayers(layers); + params.setFormat("image/png"); + params.setIsTransparent(!isBaseLayer); + + final WMSOptions opts = new WMSOptions(); + opts.setProjection(proj); + opts.setSingleTile(false); // FIXME: Make working... + opts.setTransitionEffect(TransitionEffect.RESIZE); + opts.setRatio(1); + opts.setBuffer(0); + if (layers.equals("OSM-WMS-Dienst")) { + opts.setAttribution(MSG.attribution()); + } + final WMS wms = new WMS(layers, url, params, opts); + wms.setIsVisible(true); + wms.setIsBaseLayer(isBaseLayer); + + return wms; + } + + + @Override + public void onTabSelected(TabSelectedEvent tse) { + if (tse.getTabNum () != 0) { + floodMap.hideBarrierLayer(); + } + else { + floodMap.showBarrierLayer(); + } + } + + @Override + public void onVisibilityChanged(VisibilityChangedEvent vce) { + if (!vce.getIsVisible()) { + floodMap.hideBarrierLayer(); + mapPanel.getMapToolbar().activateDrawFeature(false); + } + else { + floodMap.showBarrierLayer(); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,74 @@ +package de.intevation.flys.client.client.ui; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; + +import java.util.List; + + +public class DistanceOnlyPanel extends DistancePanel { + + private static final long serialVersionUID = -5794138573892656947L; + + + public DistanceOnlyPanel() { + this("right"); + } + + + public DistanceOnlyPanel(String labelOrientation) { + distancePanel = new DoubleRangeOnlyPanel( + labelFrom(), labelTo(), 0d, 0d, 250, this, labelOrientation); + } + + + @Override + protected String getOldSelectionString(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data dFrom = getData(items, getLowerField()); + Data dTo = getData(items, getUpperField()); + + DataItem[] from = dFrom.getItems(); + DataItem[] to = dTo.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(from[0].getLabel()); + sb.append(" " + getUnitFrom() + " - "); + sb.append(to[0].getLabel()); + sb.append(" " + getUnitTo()); + + return sb.toString(); + } + + + @Override + protected void initDefaultStep(DataList data) { + // do nothing + } + + + @Override + public Data[] getData() { + Data[] data = new Data[2]; + + data[0] = getDataFrom(); + data[1] = getDataTo(); + + return data; + } + + + @Override + protected String labelFrom() { + return getUnitFrom() + " - "; + } + + + @Override + protected String labelTo() { + return getUnitTo(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,647 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.data.AdvancedCriteria; +import com.smartgwt.client.data.Criteria; +import com.smartgwt.client.data.Criterion; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.OperatorId; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; +import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.FilterHandler; +import de.intevation.flys.client.client.event.RangeFilterEvent; +import de.intevation.flys.client.client.event.StringFilterEvent; +import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; +import de.intevation.flys.client.client.ui.range.LocationsTable; +import de.intevation.flys.client.client.ui.range.RangeTable; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + + +public class DistancePanel extends AbstractUIProvider implements BlurHandler, FilterHandler +{ + + private static final long serialVersionUID = -883142387908664588L; + + public static final int DEFAULT_STEP_WIDTH = 100; + + public static final String FIELD_LOWER = "ld_from"; + public static final String FIELD_UPPER = "ld_to"; + public static final String FIELD_STEP = "ld_step"; + + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected RangeTable distancesTable; + protected LocationsTable locationsTable; + + protected DoubleRangePanel distancePanel; + + protected TableFilter filterDescription; + protected RangeTableFilter filterRange; + + protected TabSet tabs; + + protected double min; + protected double max; + + protected StaticTextItem filterResultCount; + protected ListGrid currentFiltered; + + public DistancePanel() { + this("right"); + } + + + public DistancePanel(String labelOrientation) { + distancePanel = new DoubleRangePanel( + labelFrom(), labelTo(), labelStep(), + 0d, 0d, 0d, 250, this, labelOrientation); + } + + + @Override + public Canvas create(DataList data) { + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + + Label label = new Label(getLabel()); + + Canvas submit = getNextButton(); + + label.setHeight(25); + distancePanel.setHeight(50); + + layout.addMember(label); + layout.addMember(distancePanel); + layout.addMember(submit); + + initMinMaxValues(data); + initDefaultValues(data); + initHelperPanel(); + + return layout; + } + + + @Override + public Canvas createOld(DataList dataList) { + String s = getOldSelectionString(dataList); + String l = dataList.getLabel(); + + Label label = new Label(l); + Label selected = new Label(s); + + HLayout layout = new HLayout(); + + layout.setWidth(400); + label.setWidth(200); + selected.setWidth(130); + + layout.addMember(label); + layout.addMember(selected); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + + protected String getOldSelectionString(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data dFrom = getData(items, getLowerField()); + Data dTo = getData(items, getUpperField()); + Data dStep = getData(items, getStepField()); + + DataItem[] from = dFrom.getItems(); + DataItem[] to = dTo.getItems(); + DataItem[] step = dStep.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(from[0].getLabel()); + sb.append(" " + getUnitFrom() + " - "); + sb.append(to[0].getLabel()); + sb.append(" " + getUnitTo() + " - "); + sb.append(step[0].getLabel()); + sb.append(" " + getUnitStep()); + + return sb.toString(); + } + + + protected String getLabel() { + return MSG.distance_state(); + } + + + protected String labelFrom() { + return getLabelFrom() + " [" + getUnitFrom() + "]"; + } + + + protected String getLabelFrom() { + return MSG.dpLabelFrom(); + } + + + protected String getUnitFrom() { + return MSG.dpUnitFrom(); + } + + + protected String labelTo() { + return getLabelTo() + " [" + getUnitTo() + "]"; + } + + + protected String getLabelTo() { + return MSG.dpLabelTo(); + } + + + protected String getUnitTo() { + return MSG.dpUnitTo(); + } + + + protected String labelStep() { + return getLabelStep() + " [" + getUnitStep() + "]"; + } + + + protected String getLabelStep() { + return MSG.dpLabelStep(); + } + + + protected String getUnitStep() { + return MSG.dpUnitStep(); + } + + + protected String getLowerField() { + return FIELD_LOWER; + } + + + protected String getUpperField() { + return FIELD_UPPER; + } + + + protected String getStepField() { + return FIELD_STEP; + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + + if (!distancePanel.validateForm()) { + errors.add(MSG.wrongFormat()); + + return errors; + } + + validateFrom(errors); + validateTo(errors); + + return errors; + } + + + protected void validateFrom(List<String> errors) { + double from = distancePanel.getFrom(); + + if (from < min || from > max) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + + String tmp = MSG.error_validate_lower_range(); + tmp = tmp.replace("$1", nf.format(from)); + tmp = tmp.replace("$2", nf.format(min)); + + distancePanel.setFrom(min); + errors.add(tmp); + } + } + + + protected void validateTo(List<String> errors) { + double to = distancePanel.getTo(); + + if (to < min || to > max) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + + String tmp = MSG.error_validate_upper_range(); + tmp = tmp.replace("$1", nf.format(to)); + tmp = tmp.replace("$2", nf.format(max)); + + distancePanel.setTo(max); + errors.add(tmp); + } + } + + + @Override + public Data[] getData() { + Data[] data = new Data[4]; + + data[0] = getDataFrom(); + data[1] = getDataTo(); + data[2] = getDataStep(); + + DataItem item = new DefaultDataItem("ld_mode","ld_mode", "distance"); + data[3] = new DefaultData( + "ld_mode", null, null, new DataItem[] { item }); + + return data; + } + + + protected Data getDataFrom() { + String value = String.valueOf(distancePanel.getFrom()); + String field = getLowerField(); + + DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData( + field, null, null, new DataItem[] { item }); + } + + + protected Data getDataTo() { + String value = String.valueOf(distancePanel.getTo()); + String field = getUpperField(); + + DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData( + field, null, null, new DataItem[] { item }); + } + + + protected Data getDataStep() { + String value = String.valueOf(distancePanel.getStep()); + String field = getStepField(); + + DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData( + field, null, null, new DataItem[] { item }); + } + + + @Override + public void onBlur(BlurEvent event) { + distancePanel.validateForm(); + } + + + protected void initMinMaxValues(DataList data) { + Data f = getData(data.getAll(), getLowerField()); + Data t = getData(data.getAll(), getUpperField()); + + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + + try { + min = Double.valueOf(fItems[0].getStringValue()); + max = Double.valueOf(tItems[0].getStringValue()); + } + catch (NumberFormatException nfe) { + min = -Double.MAX_VALUE; + max = Double.MAX_VALUE; + } + } + + + protected void initDefaultValues(DataList data) { + initDefaultFrom(data); + initDefaultTo(data); + initDefaultStep(data); + } + + + protected void initDefaultFrom(DataList data) { + Data f = getData(data.getAll(), getLowerField()); + + double from = getDefaultFrom(); + + try { + from = getDefaultValue(f); + } + catch (NumberFormatException nfe) { + // do nothing + } + + distancePanel.setFrom(from); + } + + + protected double getDefaultFrom() { + return min; + } + + + protected void initDefaultTo(DataList data) { + Data t = getData(data.getAll(), getUpperField()); + + double to = getDefaultTo(); + + try { + to = getDefaultValue(t); + } + catch (NumberFormatException nfe) { + // do nothing + } + + distancePanel.setTo(to); + } + + + protected double getDefaultTo() { + return max; + } + + + protected void initDefaultStep(DataList data) { + Data s = getData(data.getAll(), getStepField()); + + double step = getDefaultStep(); + + try { + step = getDefaultValue(s); + } + catch (NumberFormatException nfe) { + // do nothing + } + + distancePanel.setStep(step); + } + + + protected double getDefaultStep() { + return DEFAULT_STEP_WIDTH; + } + + + protected double getDefaultValue(Data data) + throws NumberFormatException + { + DataItem def = data.getDefault(); + String defValue = def != null ? def.getStringValue() : null; + + return Double.valueOf(defValue); + } + + + protected void initHelperPanel() { + distancesTable = new RangeTable(); + locationsTable = new LocationsTable(); + + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String river = getRiverName(); + + distancesTable.setAutoFetchData(true); + locationsTable.setAutoFetchData(true); + distancesTable.setDataSource(new DistanceInfoDataSource( + url, river, "distances")); + locationsTable.setDataSource(new DistanceInfoDataSource( + url, river, "locations")); + + distancesTable.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(RecordClickEvent e) { + Record r = e.getRecord(); + + String from = r.getAttribute("from"); + String to = r.getAttribute("to"); + + try { + distancePanel.setFrom(Double.valueOf(from)); + distancePanel.setTo(Double.valueOf(to)); + } + catch (NumberFormatException nfe) { + SC.warn(MSG.wrongFormat()); + } + } + }); + + locationsTable.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(RecordClickEvent e) { + Record r = e.getRecord(); + int field = e.getFieldNum(); + + try { + String value = r.getAttribute("from"); + + switch (field) { + case 0: + distancePanel.setFrom(Double.valueOf(value)); + break; + case 1: + distancePanel.setTo(Double.valueOf(value)); + break; + } + } + catch (NumberFormatException nfe) { + SC.warn(MSG.wrongFormat()); + } + } + }); + + tabs = new TabSet(); + tabs.setWidth100(); + tabs.setHeight100(); + + Tab locations = new Tab(MSG.locations()); + Tab distances = new Tab(MSG.distance()); + + locations.setPane(locationsTable); + distances.setPane(distancesTable); + + tabs.addTab(locations, 0); + tabs.addTab(distances, 1); + + filterResultCount = new StaticTextItem(MSG.resultCount()); + filterResultCount.setTitleAlign(Alignment.LEFT); + filterResultCount.setTitleStyle("color: #000"); + + filterDescription = new TableFilter(); + filterDescription.setHeight("30px"); + filterDescription.addFilterHandler(this); + + filterRange = new RangeTableFilter(); + filterRange.setHeight("30px"); + filterRange.addFilterHandler(this); + filterRange.setVisible(false); + + SelectItem filterCriteria = new SelectItem(); + filterCriteria.setShowTitle(false); + filterCriteria.setWidth(100); + filterCriteria.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent e) { + if(e.getValue().toString().equals("range")) { + filterRange.setVisible(true); + filterDescription.setVisible(false); + filterDescription.clear(); + } + else { + filterRange.setVisible(false); + filterRange.clear(); + filterDescription.setVisible(true); + } + } + }); + + LinkedHashMap<String, String> filterMap = + new LinkedHashMap<String, String>(); + filterMap.put("description", MSG.description()); + filterMap.put("range", MSG.range()); + filterCriteria.setValueMap(filterMap); + filterCriteria.setValue("description"); + + DynamicForm form = new DynamicForm(); + form.setFields(filterCriteria); + + DynamicForm form2 = new DynamicForm(); + form2.setFields(filterResultCount); + + HLayout filterLayout = new HLayout(); + filterLayout.addMember(form); + filterLayout.addMember(filterDescription); + filterLayout.addMember(filterRange); + filterLayout.setHeight(30); + tabs.addTabSelectedHandler(new TabSelectedHandler() { + @Override + public void onTabSelected(TabSelectedEvent evt) { + filterDescription.clear(); + filterRange.clear(); + filterResultCount.setValue(""); + + Canvas c = evt.getTabPane(); + if(c instanceof ListGrid) { + currentFiltered = (ListGrid)c; + } + } + }); + + helperContainer.addMember(tabs); + helperContainer.addMember(filterLayout); + helperContainer.addMember(form2); + } + + + @Override + public void onFilterCriteriaChanged(StringFilterEvent event) { + String search = event.getFilter(); + + if (search != null && search.length() > 0) { + Criteria c = new Criteria("description", search); + locationsTable.filterData(c); + distancesTable.filterData(c); + filterResultCount.setValue(currentFiltered.getRecords().length); + } + else { + locationsTable.clearCriteria(); + distancesTable.clearCriteria(); + filterResultCount.setValue(""); + } + } + + + @Override + public void onFilterCriteriaChanged(RangeFilterEvent event) { + Float from = event.getFrom() - 0.001f; + Float to = event.getTo() + 0.001f; + + Criterion combinedFilter = null; + Criterion locationFilter = null; + if (from.equals(Float.NaN) && to.equals(Float.NaN)) { + locationsTable.clearCriteria(); + distancesTable.clearCriteria(); + filterResultCount.setValue(""); + return; + } + else if (from.equals(Float.NaN)) { + combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); + locationFilter = + new Criterion("from", OperatorId.LESS_OR_EQUAL, to); + locationsTable.filterData(locationFilter); + distancesTable.filterData(combinedFilter); + filterResultCount.setValue(currentFiltered.getRecords().length); + return; + } + else if (to.equals(Float.NaN)) { + combinedFilter = + new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); + } + else { + AdvancedCriteria c1 = + new AdvancedCriteria(OperatorId.AND, new Criterion[] { + new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), + new Criterion("from", OperatorId.LESS_OR_EQUAL, to) + }); + + AdvancedCriteria c2 = + new AdvancedCriteria(OperatorId.AND, new Criterion[] { + new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), + new Criterion("to", OperatorId.LESS_OR_EQUAL, to) + }); + + AdvancedCriteria c3 = + new AdvancedCriteria(OperatorId.AND, new Criterion[] { + new Criterion("from", OperatorId.LESS_OR_EQUAL, to), + new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) + }); + + combinedFilter = + new AdvancedCriteria(OperatorId.OR, new Criterion[] { + c1, c2, c3 + }); + } + locationsTable.filterData(combinedFilter); + distancesTable.filterData(combinedFilter); + filterResultCount.setValue(currentFiltered.getRecords().length); + + } + + + protected String getRiverName() { + ArtifactDescription adescr = artifact.getArtifactDescription(); + return adescr.getRiver(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleArrayPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,280 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.TitleOrientation; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.FocusHandler; + +import de.intevation.flys.client.client.FLYSConstants; + +import java.util.Map; + +public class DoubleArrayPanel +extends DynamicForm +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected TextItem ti; + + private String title; + + /** The constant input field name. */ + public static final String FIELD_NAME = "doublearray"; + + + public DoubleArrayPanel( + String title, + double[] values, + BlurHandler handler) + { + this(title, values, handler, null, TitleOrientation.RIGHT); + } + + + /** + * Creates a new form with a single input field that displays an array of + * double values. + * + * @param name The name of the TextItem. + * @param title The title of the TextItem. + * @param values The double values that should be displayed initially. + * @param blurHandler The BlurHandler that is used to valide the input. + * @param focusHandler The FocueHandler that is used to valide the input. + */ + public DoubleArrayPanel( + String title, + double[] values, + BlurHandler blurHandler, + FocusHandler focusHandler, + TitleOrientation titleOrientation) + { + this.title = title; + ti = new TextItem(FIELD_NAME); + StaticTextItem sti = new StaticTextItem("staticarray"); + + ti.setShowTitle(false); + sti.setShowTitle(false); + sti.setValue(title); + + ti.addBlurHandler(blurHandler); + if (focusHandler != null) { + ti.addFocusHandler(focusHandler); + } + + if (titleOrientation == TitleOrientation.RIGHT) { + setFields(ti, sti); + } + else { + setFields(sti, ti); + } + + setTitleOrientation(titleOrientation); + setNumCols(2); + + if (values == null) { + return; + } + + NumberFormat f = NumberFormat.getDecimalFormat(); + + StringBuilder text = new StringBuilder(); + boolean firstItem = true; + + for (double val: values) { + if (!firstItem) { + text.append(" "); + } + + text.append(f.format(val)); + + firstItem = false; + } + + ti.setValue(text.toString()); + } + + + /** + * This method takes the double array to set the values to the textbox. + * + * @param values The double values. + */ + public void setValues(double[] values) { + NumberFormat f = NumberFormat.getDecimalFormat(); + + if(values == null || values.length == 0) { + ti.clearValue(); + return; + } + StringBuilder text = new StringBuilder(); + boolean firstItem = true; + if (values != null) { + for (double val: values) { + if (!firstItem) { + text.append(" "); + } + + text.append(f.format(val)); + + firstItem = false; + } + } + + ti.clearValue(); + ti.setValue(text.toString()); + } + + + /** + * This method appends a double value to the current list of values. + * + * @param value A new value. + */ + public void addValue(double value) { + NumberFormat f = NumberFormat.getDecimalFormat(); + + String current = ti.getValueAsString(); + + if (current == null || current.length() == 0) { + current = f.format(value); + } + else { + current += " " + f.format(value); + } + + ti.setValue(current); + } + + + protected boolean validateForm() { + return validateForm(ti); + } + + + /** + * This method validates the entered text in the location input field. If + * there are values that doesn't represent a valid location, an error is + * displayed. + * + * @param item The FormItem. + */ + @SuppressWarnings("unchecked") + protected boolean validateForm(FormItem item) { + if (item instanceof StaticTextItem) { + return true; + } + + boolean valid = true; + String value = (String) item.getValue(); + + if (value == null) { + return valid; + } + + String[] parts = value.split("\\s+"); + + if (parts == null) { + return valid; + } + + NumberFormat nf = NumberFormat.getDecimalFormat(); + @SuppressWarnings("rawtypes") + Map errors = getErrors(); + + try { + for (String part: parts) { + + if (part.length() == 0) { + continue; + } + + nf.parse(part); + } + + errors.remove(item.getFieldName()); + } + catch (NumberFormatException nfe) { + errors.put(item.getFieldName(), MESSAGES.wrongFormat()); + + valid = false; + } + + setErrors(errors, true); + + return valid; + } + + + /** + * This method returns the double array that has been entered in + * <i>item</i>. + * + * @param item The item that contains the desired values. + * + * @return the values as double array. + */ + public double[] getInputValues(FormItem item) { + String value = (String) item.getValue(); + + if (value == null) { + return null; + } + + String[] parts = value.split("\\s+"); + + if (parts == null) { + return null; + } + + NumberFormat f = NumberFormat.getDecimalFormat(); + + double[] values = new double[parts.length]; + + int i = 0; + OUTER: for (String part: parts) { + if (part.length() == 0) { + continue; + } + + try { + double x = f.parse(part); + for (int j = 0; j < i; ++j) { + if (values[j] == x) { + continue OUTER; + } + } + values[i++] = x; + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + double [] out = new double[i]; + System.arraycopy(values, 0, out, 0, i); + + return out; + } + + + /** + * Returns the double values of this panel. + * + * @return the double values of this panel. + */ + public double[] getInputValues() { + return getInputValues(ti); + } + + public String getItemTitle() { + return this.title; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleInputPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,176 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.List; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DoubleInputPanel +extends AbstractUIProvider +{ + + private static final long serialVersionUID = 2006773072352563622L; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + private TextItem inputPanel; + + private double value; + + protected String dataName; + + + public DoubleInputPanel() { + dataName = "outliers"; + } + + + public DoubleInputPanel(String dataName) { + this.dataName = dataName; + } + + + @Override + public Canvas create(DataList list) { + VLayout layout = new VLayout(); + + Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(list); + + layout.addMember(widget); + layout.addMember(submit); + return layout; + } + + + /** Create a labelled input-panel. */ + public Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + + Label title = new Label(data.get(0).getDescription()); + title.setHeight("25px"); + + DataItem defaultItem = data.get(0).getDefault(); + + DynamicForm form = new DynamicForm(); + inputPanel = new TextItem(); + inputPanel.setTitle(dataName); + inputPanel.setShowTitle(false); + + if (defaultItem != null) { + inputPanel.setValue(defaultItem.getStringValue()); + } + + form.setFields(inputPanel); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + + protected Canvas createHelper() { + return new VLayout(); + } + + + /** Create canvas to show previously entered value. */ + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data d = getData(items, dataName); + DataItem[] item = d.getItems(); + + String v = item[0].getLabel(); + + Label old = new Label(v); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveDataValues(); + if(valid) { + + String vs = Double.valueOf(this.value).toString(); + DataItem item = new DefaultDataItem(dataName, dataName, vs); + data.add(new DefaultData( + dataName, + null, + null, + new DataItem[] { item })); + } + + return data.toArray(new Data[data.size()]); + } + + + protected boolean saveDataValues() { + String st = inputPanel.getValueAsString(); + if (st == null) { + SC.warn("fehler... TODO"); + return false; + } + + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d = nf.parse(st); + this.value = d; + } + catch(NumberFormatException nfe) { + SC.warn("fehler... nfe... TODO"); + return false; + } + return true; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangeOnlyPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,88 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.form.fields.FloatItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; + + +public class DoubleRangeOnlyPanel extends DoubleRangePanel { + + public DoubleRangeOnlyPanel( + String titleFrom, + String titleTo, + double from, + double to, + int width, + BlurHandler handler + ) { + this(titleFrom, titleTo, from, to, width, handler, "right"); + } + + + public DoubleRangeOnlyPanel( + String titleFrom, + String titleTo, + double from, + double to, + int width, + BlurHandler handler, + String labelOrientation + ) { + super(); + + fromItem = new FloatItem(FIELD_FROM); + toItem = new FloatItem(FIELD_TO); + stepItem = new FloatItem(FIELD_WIDTH); + + fromItem.addBlurHandler(handler); + toItem.addBlurHandler(handler); + + NumberFormat nf = NumberFormat.getDecimalFormat(); + + fromItem.setValue(nf.format(from)); + toItem.setValue(nf.format(to)); + + StaticTextItem fromText = new StaticTextItem("staticFrom"); + fromText.setValue(titleFrom); + fromText.setShowTitle(false); + fromItem.setShowTitle(false); + + StaticTextItem toText = new StaticTextItem("staticTo"); + toText.setValue(titleTo); + toText.setShowTitle(false); + toItem.setShowTitle(false); + + int itemWidth = width / 4; + fromItem.setWidth(itemWidth); + fromText.setWidth(itemWidth); + toItem.setWidth(itemWidth); + toText.setWidth(itemWidth); + + if (labelOrientation.equals("right")) { + setFields(fromItem, fromText, toItem, toText); + } + else { + setFields(fromText, fromItem, toText, toItem); + } + + setFixedColWidths(false); + setNumCols(4); + setWidth(width); + setAlign(Alignment.CENTER); + } + + + @Override + public boolean validateForm() { + return validateForm(fromItem) && validateForm(toItem); + } + + + @Override + public double getStep() { + return -1; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,296 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FloatItem; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; + +import de.intevation.flys.client.client.FLYSConstants; + +import java.util.Map; + + +/** + * This class creates a DynamicForm with three input fields. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DoubleRangePanel +extends DynamicForm +{ + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + + /** The constant name of the input field to enter the start of a distance.*/ + public static final String FIELD_FROM = "from"; + + /** The constant name of the input field to enter the end of a distance.*/ + public static final String FIELD_TO = "to"; + + /** The constant name of the input field to enter the step width of a + * distance.*/ + public static final String FIELD_WIDTH = "step"; + + /** The textboxes */ + protected FloatItem fromItem; + protected FloatItem toItem; + protected FloatItem stepItem; + + + public DoubleRangePanel() { + } + + + /** + * Creates a new form with a single input field that displays an array of + * double values. + * + * @param name The name of the TextItem. + * @param title The title of the TextItem. + * @param values The double values that should be displayed initially. + * @param handler The BlurHandler that is used to valide the input. + */ + public DoubleRangePanel( + String titleFrom, String titleTo, String titleStep, + double from, double to, double step, + int width, + BlurHandler handler) + { + this( + titleFrom, titleTo, titleStep, + from, to, step, + width, + handler, + "right"); + } + + + public DoubleRangePanel( + String titleFrom, String titleTo, String titleStep, + double from, double to, double step, + int width, + BlurHandler handler, + String labelOrientation) + { + fromItem = new FloatItem(FIELD_FROM); + toItem = new FloatItem(FIELD_TO); + stepItem = new FloatItem(FIELD_WIDTH); + + fromItem.addBlurHandler(handler); + toItem.addBlurHandler(handler); + stepItem.addBlurHandler(handler); + + NumberFormat f = NumberFormat.getDecimalFormat(); + + fromItem.setValue(f.format(from)); + toItem.setValue(f.format(to)); + stepItem.setValue(f.format(step)); + + StaticTextItem fromText = new StaticTextItem("staticFrom"); + fromText.setValue(titleFrom); + fromText.setShowTitle(false); + fromItem.setShowTitle(false); + + StaticTextItem toText = new StaticTextItem("staticTo"); + toText.setValue(titleTo); + toText.setShowTitle(false); + toItem.setShowTitle(false); + + StaticTextItem stepText = new StaticTextItem("staticStep"); + stepText.setValue(titleStep); + stepText.setShowTitle(false); + stepItem.setShowTitle(false); + + int itemWidth = width / 6; + fromItem.setWidth(itemWidth); + fromText.setWidth(itemWidth); + toItem.setWidth(itemWidth); + toText.setWidth(itemWidth); + stepItem.setWidth(itemWidth); + stepText.setWidth(itemWidth); + + if (labelOrientation.equals("right")) { + setFields(fromItem, fromText, toItem, toText, stepItem, stepText); + } + else { + setFields(fromText, fromItem, toText, toItem, stepText, stepItem); + } + + setFixedColWidths(false); + setNumCols(6); + setWidth(width); + setAlign(Alignment.CENTER); + } + + + /** + * This method takes distances values and sets them to the textboxes + * visualizied by this widget. + * + * @param from The from value. + * @param to The to value. + * @param steps The max steps. + */ + public void setValues(double from, double to, double steps) { + NumberFormat f = NumberFormat.getDecimalFormat(); + + fromItem.setValue(f.format(from)); + toItem.setValue(f.format(to)); + stepItem.setValue(f.format(steps)); + } + + + public boolean validateForm() { + try { + return + validateForm(fromItem) && + validateForm(toItem) && + validateForm(stepItem); + } + catch (NumberFormatException nfe) { + return false; + } + } + + /** + * This method validates the entered text in the input fields. If + * there are values that doesn't represent a valid float, an error is + * displayed. + * + * @param item The FormItem. + */ + @SuppressWarnings("unchecked") + protected boolean validateForm(FormItem item) { + if (item instanceof StaticTextItem) { + return true; + } + + boolean valid = true; + + String v = (String) item.getValue(); + + NumberFormat f = NumberFormat.getDecimalFormat(); + @SuppressWarnings("rawtypes") + Map errors = getErrors(); + + try { + if (v == null) { + throw new NumberFormatException("empty"); + } + + f.parse(v); + + errors.remove(item.getFieldName()); + } + catch (NumberFormatException nfe) { + errors.put(item.getFieldName(), MESSAGES.wrongFormat()); + + item.focusInItem(); + + valid = false; + } + + setErrors(errors, true); + + return valid; + } + + + /** + * Returns the double value of <i>value</i>. + * + * @return the double value of <i>value</i>. + */ + protected double getDouble(String value) { + NumberFormat f = NumberFormat.getDecimalFormat(); + + String[] splitted = value.split(" "); + + return f.parse(splitted[0]); + } + + + /** + * Returns the start value. + * + * @return the start value. + */ + public double getFrom() throws NullPointerException { + String v = getValueAsString(FIELD_FROM); + + return getDouble(v); + } + + + /** + * Returns the end value. + * + * @return the end value. + */ + public double getTo() throws NullPointerException { + String v = getValueAsString(FIELD_TO); + + return getDouble(v); + } + + + /** + * Returns the step width. + * + * @return the step width. + */ + public double getStep() throws NullPointerException { + String v = getValueAsString(FIELD_WIDTH); + + return getDouble(v); + } + + + /** + * Sets the value of the field with name <i>fieldname</i>. + * + * @param value The new value. + * @param fieldname The name of the field. + */ + public void setDoubleValue(double value, String fieldname) { + NumberFormat f = NumberFormat.getDecimalFormat(); + setValue(fieldname, f.format(value)); + } + + + /** + * Sets a new start value. + * + * @param value The new start value. + */ + public void setFrom(double value) { + setDoubleValue(value, FIELD_FROM); + } + + + /** + * Sets a new end value. + * + * @param value The new end value. + */ + public void setTo(double value) { + setDoubleValue(value, FIELD_TO); + } + + + /** + * Sets a new step width. + * + * @param value The new step width. + */ + public void setStep(double value) { + setDoubleValue(value, FIELD_WIDTH); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ExportPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,168 @@ +package de.intevation.flys.client.client.ui; + +import java.util.List; +import java.util.MissingResourceException; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.ExportMode; +import de.intevation.flys.client.shared.model.Facet; +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; + + +/** + * A panel that displays an download icon for all available export modes of a + * Collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ExportPanel extends VLayout { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected Collection c; + protected List<ExportMode> exports; + + /** This layout will store a list of available export types.*/ + protected HLayout container; + + + public ExportPanel(Collection c, List<ExportMode> exports) { + super(); + + this.c = c; + this.exports = exports; + this.container = new HLayout(); + + Label title = new Label(MSG.dataexport()); + title.setHeight(15); + title.setStyleName("fontNormalSmallUnderlined"); + + addMember(title); + addMember(createExportItems()); + + setHeight(45); + setMembersMargin(5); + } + + + /** + * This method is used to create an item (created by createExportButton) for + * each facet for each export mode. + * + * @return a horizontal list of buttons. + */ + protected HLayout createExportItems() { + HLayout layout = new HLayout(); + + for (ExportMode mode: exports) { + String name = mode.getName(); + List<Facet> facets = mode.getFacets(); + + for (Facet facet: facets) { + if (name.equals("fix_wq_curve_at_export")) { + continue; + } + String filename = name; + if (name.equals("computed_dischargecurve_at_export")) { + filename = "dischargecurve"; + } + layout.addMember(createExportButton( + name, + facet.getName(), + filename)); + } + } + + return layout; + } + + + /** + * This method is used to create a button (with click handler) for a + * concrete export mode / type. + * + * @param name The name of the export. + * @param facet The name of the export type (e.g. CSV, WST). + * + * @return an image with click handler. + */ + protected Canvas createExportButton( + String name, + String facet, + String filename + ) { + String url = getExportUrl(name, facet, filename); + String imgUrl = GWT.getHostPageBaseURL(); + if (facet.equals("pdf")) { + imgUrl += MSG.downloadPDF(); + } + else if (facet.equals("at")) { + imgUrl += MSG.downloadAT(); + } + else if (facet.equals("wst")) { + imgUrl += MSG.downloadWST(); + } + else if (facet.equals("csv")) { + imgUrl += MSG.downloadCSV(); + } + else { + imgUrl += MSG.imageSave(); + } + ImgLink link = new ImgLink(imgUrl, url, 30, 30); + link.setTooltip(getTooltipText(name, facet)); + + return link; + } + + + /** + * Creates the URL used to trigger an export. + * + * @param name The name of the export. + * @param facet The name of the export type (e.g. CSV, WST). + * + * @return the export URL. + */ + protected String getExportUrl(String name, String facet, String filename) { + Config config = Config.getInstance(); + + String url = GWT.getModuleBaseURL(); + url += "export"; + url += "?uuid=" + c.identifier(); + url += "&name=" + filename; + url += "&mode=" + name; + url += "&type=" + facet; + url += "&server=" + config.getServerUrl(); + url += "&locale=" + config.getLocale(); + + return url; + } + + + /** + * Creates a text used as tooltip for a specific export and type. + * + * @param name The name of the export. + * @param facet The name of the export type (e.g. CSV, WST). + * + * @return a tooltip text. + */ + protected String getTooltipText(String name, String facet) { + try { + return MSG.getString(name) + " | " + MSG.getString(facet); + } + catch (MissingResourceException mre) { + return name + " | " + facet; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/FLYSHeader.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,291 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.LocaleInfo; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.util.BooleanCallback; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; + +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.UserService; +import de.intevation.flys.client.client.services.UserServiceAsync; +import de.intevation.flys.client.shared.model.User; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FLYSHeader extends HLayout { + + /** The interface that provides the message resources. */ + private FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + /** The height used for this header.*/ + public static final int HEIGHT = 56; + + /** The height used for the images.*/ + public static final int IMG_HEIGHT = 50; + + /** The user that is currently logged in. */ + private User currentUser; + + /** The label that displays the current logged in user. */ + private Label userText; + + /** The button to log the current user out.*/ + private Button logout; + + /** The button to open the project list.*/ + private Button projectList; + + /** The button to switch between the english and german version.*/ + private Button language; + + /** The button to open an info panel.*/ + private Button info; + + private UserServiceAsync userService = + GWT.create(UserService.class); + + /** An instance to FLYS.*/ + private FLYS flys; + + + public FLYSHeader(FLYS flys) { + this.flys = flys; + + String guest = MESSAGES.user() + " " + MESSAGES.guest(); + + userText = new Label(guest); + projectList = new Button(MESSAGES.manage_projects()); + logout = new Button(MESSAGES.logout()); + language = new Button(MESSAGES.switch_language()); + info = new Button(MESSAGES.info()); + + projectList.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + GWT.log("Clicked 'Open ProjectList' button."); + getFlys().openProjectList(); + } + }); + + logout.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + GWT.log("Clicked 'logout' button."); + userService.logoutCurrentUser(new AsyncCallback<Void>() { + public void onFailure(Throwable caught) { + } + + public void onSuccess(Void result) { + /* Just reload the page. GGInAFilter is goint to redirect + * to the correct login page */ + Window.Location.reload(); + } + }); + + } + }); + + language.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + LocaleInfo info = LocaleInfo.getCurrentLocale(); + final String currentLocale = info.getLocaleName(); + final String newLocale = currentLocale.equals("de") + ? "en" + : "de"; + + SC.confirm(MESSAGES.warning(), MESSAGES.warning_language(), + new BooleanCallback() { + @Override + public void execute(Boolean value) { + if (value) { + switchLanguage(currentLocale, newLocale); + } + } + }); + } + }); + + info.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + GWT.log("Clicked 'info' button."); + GWT.log("IMPLEMENT the 'open info panel' function."); + } + }); + init(); + } + + public void init() { + setStyleName("header"); + setWidth100(); + setHeight(HEIGHT); + setBackgroundColor("#a9c9e6"); + setLayoutLeftMargin(5); + setLayoutRightMargin(5); + + String baseUrl = GWT.getHostPageBaseURL(); + + Img flys = new Img( + baseUrl + MESSAGES.flysLogo(), + 50, + IMG_HEIGHT); + + Img bfg = new Img( + baseUrl + MESSAGES.bfgLogoSmall(), + 150, + IMG_HEIGHT); + + Label fullname = new Label(MESSAGES.fullname()); + fullname.setHeight(HEIGHT - IMG_HEIGHT); + fullname.setStyleName("fontBlackMid"); + + HLayout left = new HLayout(); + left.setDefaultLayoutAlign(VerticalAlignment.CENTER); + left.setMembersMargin(3); + left.addMember(flys); + left.addMember(fullname); + + HLayout right = new HLayout(); + right.setAlign(Alignment.RIGHT); + right.setDefaultLayoutAlign(Alignment.RIGHT); + right.setDefaultLayoutAlign(VerticalAlignment.CENTER); + right.setMembersMargin(3); + right.setLayoutRightMargin(5); + + projectList.setStyleName("manageProjects"); + userText.setStyleName("fontBlackSmall"); + logout.setStyleName("fontLightSmall"); + language.setStyleName("fontLightSmall"); + info.setStyleName("fontLightSmall"); + + userText.setAlign(Alignment.RIGHT); + userText.setWidth(200); + logout.setWidth(70); + info.setWidth(40); + language.setWidth(70); + + left.addMember(projectList); + if (this.flys.isProjectListVisible()) { + hideProjectButton(); + } + else { + showProjectButton(); + } + + right.addMember(userText); + right.addMember(logout); + right.addMember(language); + right.addMember(info); + right.addMember(bfg); + + addMember(left); + addMember(right); + } + + /** + * Returns the FLYS instance stored in this class. + * + * @return the flys instance. + */ + private FLYS getFlys() { + return flys; + } + + /** + * This method triggers the language switch between the <i>currentLocale</i> + * and the <i>newLocale</i>. The switch is done by replacing a "locale=" + * parameter in the url of the application. We could use the GWT UrlBuilder + * class to create a new URL, but - in my eyes - this class is a bit + * inconsistens in its implementation. + * + * @param currentLocale The current locale string (e.g. "en"). + * @param newLocale The new locale string (e.g. "de"). + */ + private void switchLanguage(String currentLocale, String newLocale) { + String newLocation = Window.Location.getHref(); + + if (newLocation.endsWith("/")) { + newLocation = newLocation.substring(0, newLocation.length()-1); + } + + String replace = null; + String replaceWith = null; + + if (newLocation.indexOf("&locale=") >= 0) { + replace = currentLocale.equals("de") + ? "&locale=de" + : "&locale=en"; + + replaceWith = "&locale=" + newLocale; + } + else if (newLocation.indexOf("?locale=") >= 0) { + replace = currentLocale.equals("de") + ? "?locale=de" + : "?locale=en"; + + replaceWith = "?locale=" + newLocale; + } + else { + newLocation += newLocation.indexOf("?") >= 0 + ? "&locale=" + newLocale + : "?locale=" + newLocale; + } + + if (replace != null && replaceWith != null) { + newLocation = newLocation.replace(replace, replaceWith); + } + + Window.open(newLocation, "_self", ""); + } + + /** + * Update the text field that shows the current user. If no user is + * currently logged in, the text will display {@link FLYSConstants.guest()}. + */ + private void updateCurrentUser() { + String name = currentUser != null + ? currentUser.getName() + : MESSAGES.guest(); + + GWT.log("Update the current user: " + name); + + String username = MESSAGES.user() + " " + name; + userText.setContents(username); + } + + /** + * Set the current {@link User} and call {@link updateCurrentUser()} + * afterwards. + * + * @param user the new user. + */ + public void setCurrentUser(User currentUser) { + this.currentUser = currentUser; + + updateCurrentUser(); + } + + public void hideProjectButton() { + this.projectList.hide(); + } + + public void showProjectButton() { + this.projectList.show(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/FLYSView.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,81 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.layout.HLayout; + + +/** + * Vertically speaking the main part of the ui (containing projectlist + * and workspace). + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FLYSView extends Canvas { + + /** The project list displaying the projects of a user.*/ + protected ProjectList projectList; + + /** The workspace that handles the artifact collection views.*/ + protected FLYSWorkspace workspace; + + /** The layout provided by this widget.*/ + protected HLayout layout; + + + /** + * The default constructor for creating a new empty FLYSView. After creating + * the components, {@link init()} is called to do the layout work. + */ + public FLYSView() { + layout = new HLayout(); + + init(); + } + + + /** + * This method is called to do the layout work. + */ + protected void init() { + setWidth("100%"); + setHeight("*"); + + setStyleName("bgWhite"); + setBorder("1px solid #808080"); + + layout.setHeight("100%"); + layout.setWidth("100%"); + + addChild(layout); + } + + + /** + * Set the current project list. Previous ProjectLists are replaced by the + * new one. + */ + public void setProjectList(ProjectList projectList) { + if (this.projectList != null) { + removeChild(this.projectList); + } + + this.projectList = projectList; + layout.addMember(this.projectList); + } + + + /** + * Set the current FLYSWorkspace. Previous workspaces are replaced by the + * new one. + * + * @param workspaces The new FLYSWorkspace. + */ + public void setFLYSWorkspace(FLYSWorkspace workspace) { + if (this.workspace != null) { + removeChild(this.workspace); + } + + this.workspace = workspace; + layout.addMember(this.workspace); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/FLYSWorkspace.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,179 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; + +import java.util.HashMap; +import java.util.Map; + + +/** + * "Workspace" canvas showing the CollectionViews (subwindows). + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FLYSWorkspace extends Canvas { + + /** The maximal number of windows that fit into the browser view when an + * offset is used to move windows initially.*/ + public static int MAX_WINDOWS = 10; + + /** The number of pixels used to move windows.*/ + public static int WINDOW_OFFSET = 20; + + /** A map that contains the open CollectionViews. */ + protected Map<String, CollectionView> views; + + /** The interface that provides the message resources. */ + private FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + /** Application instance. */ + private FLYS flys; + + + /** + * The default constructor creates an empty FLYSWorkspace with no + * CollectionViews opened. + */ + public FLYSWorkspace(FLYS flys) { + this.flys = flys; + views = new HashMap<String, CollectionView>(); + + setWidth("100%"); + setHeight("100%"); + + addBackgroundWorkspace(); + } + + + /** + * This method adds a new CollectionView to this workspace and stores a + * reference in {@link views}. + * + * @param collectionView A new CollectionView. + */ + public void addView(String uuid, CollectionView collectionView) { + collectionView.moveTo(0, 0); + collectionView.setMaximized(true); + + views.put(uuid, collectionView); + addChild(collectionView); + } + + + public void removeProject(String uuid) { + views.remove(uuid); + } + + + public void bringUp(String uuid) { + CollectionView view = views.get(uuid); + + if (view != null) { + view.show(); + view.restore(); + } + else { + GWT.log("FLYSWorkspace.bringUp() failed!"); + } + } + + + /** + * Removes a project from workspace (view) and clears its reference from + * hash map. + * + * @param uuid The project's uuid. + */ + public void destroyProject(String uuid) { + CollectionView project = views.get(uuid); + + if (project != null) { + removeProject(uuid); + project.destroy(); + } + } + + + public void updateTitle(String uuid, String title) { + CollectionView view = views.get(uuid); + view.setTitle(title); + } + + + public boolean hasView(String uuid) { + if(views.get(uuid) != null) { + return true; + } + return false; + } + + private void addBackgroundWorkspace() { + String baseUrl = GWT.getHostPageBaseURL(); + Img bfg = new Img( + baseUrl + MESSAGES.bfgLogo()); + bfg.setWidth(150); + bfg.setHeight(100); + bfg.setLayoutAlign(Alignment.RIGHT); + + HLayout backgroundlayout = new HLayout(); + backgroundlayout.setHeight100(); + backgroundlayout.setWidth100(); + backgroundlayout.setDefaultLayoutAlign(Alignment.CENTER); + backgroundlayout.setDefaultLayoutAlign(VerticalAlignment.CENTER); + + Canvas spacer = new Canvas(); + spacer.setWidth("33%"); + + VLayout infobox = new VLayout(); + infobox.setHeight("*"); + infobox.setWidth("*"); + infobox.setDefaultLayoutAlign(Alignment.CENTER); + + Label welcome = new Label(MESSAGES.welcome()); + welcome.setAlign(Alignment.CENTER); + welcome.setStyleName("fontNormalBig"); + + Label lcreate = new Label(MESSAGES.welcome_open_or_create()); + lcreate.setStyleName("welcomeCreateText"); + lcreate.setWidth100(); + lcreate.setAlign(Alignment.CENTER); + + Button addbutton = new Button(MESSAGES.new_project()); + addbutton.setStyleName("projectsAddButton"); + addbutton.setAlign(Alignment.CENTER); + addbutton.setTitle(MESSAGES.new_project()); + addbutton.setAutoFit(true); + addbutton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + flys.newProject(); + } + }); + + + infobox.addMember(welcome); + infobox.addMember(lcreate); + infobox.addMember(addbutton); + + backgroundlayout.addMember(spacer); + backgroundlayout.addMember(infobox); + backgroundlayout.addMember(spacer); + + addChild(backgroundlayout); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/GaugeTimeRangePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,405 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.DateRangeItem; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.ui.range.DischargeInfoDataSource; +import de.intevation.flys.client.client.widgets.DischargeTablesChart; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.LongRangeData; +import de.intevation.flys.client.shared.model.RangeData; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class GaugeTimeRangePanel extends RangePanel { + + private static final long serialVersionUID = -157571967010594739L; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected ListGrid yearTable; + + protected DateRangeItem dateRange; + + protected Long maxUpper; + protected Long maxLower; + + + public GaugeTimeRangePanel() { + GWT.log("Creating YearInputPanel"); + yearTable = new ListGrid(); + yearTable.setAutoFetchData(true); + yearTable.setShowHeaderContextMenu(false); + } + + protected void setMaxUpper(DataList dataList) { + LongRangeData range = (LongRangeData) dataList.get(0); + setMaxUpper((Long) range.getUpper()); + } + + protected void setMaxUpper(Long maxUpper) { + this.maxUpper = maxUpper; + } + + protected void setMaxLower(DataList dataList) { + LongRangeData range = (LongRangeData) dataList.get(0); + setMaxLower((Long) range.getLower()); + } + + protected void setMaxLower(Long maxLower) { + this.maxLower = maxLower; + } + + @Override + public Canvas create(DataList data) { + setDataName(data); + + VLayout root = new VLayout(); + + root.addMember(createLabel(data)); + root.addMember(createForm(data)); + root.addMember(getNextButton()); + + initDefaults(data); + + initYearTable(); + + long gauge = getGaugeNumber(); + + Config config = Config.getInstance(); + String url = config.getServerUrl(); + yearTable.setDataSource(new DischargeInfoDataSource(url, gauge)); + + helperContainer.addMember(createHelperPanel()); + + setMaxUpper(data); + setMaxLower(data); + + return root; + } + + + protected Canvas createHelperPanel() { + TabSet tabs = new TabSet(); + + Tab table = new Tab(MSG.discharge_timeranges()); + Tab chart = new Tab(MSG.discharge_chart()); + + table.setPane(yearTable); + chart.setPane(new DischargeTablesChart(artifact)); + + tabs.addTab(table, 0); + tabs.addTab(chart, 1); + + return tabs; + } + + + /** Put defaults in form. */ + @Override + protected void initDefaults(DataList dataList) { + RangeData data = findRangeData(dataList); + + if (data != null) { + dateRange.setFromDate(new Date((Long)data.getLower())); + } + + dateRange.setToDate(new Date()); + } + + + @Override + public Canvas createOld(DataList dataList) { + GWT.log("create old date."); + Data data = dataList.get(0); + HLayout layout = new HLayout(); + + Label label = new Label(dataList.getLabel()); + label.setWidth(200); + label.setHeight(20); + + Date dl = new Date((Long)((LongRangeData)data).getLower()); + Date du = new Date((Long)((LongRangeData)data).getUpper()); + + @SuppressWarnings("deprecation") + DateTimeFormat dtf = DateTimeFormat.getMediumDateFormat(); + Label value = new Label(dtf.format(dl) + " - " + dtf.format(du)); + value.setHeight(20); + + layout.addMember(label); + layout.addMember(value); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + + @Override + protected Data[] getData() { + long lo = getLowerAsLong(); + long up = getUpperAsLong(); + + return new Data[] { new LongRangeData(getDataName(), null, lo, up) }; + } + + + @Override + protected Canvas createForm(DataList dataList) { + HLayout layout = new HLayout(); + DynamicForm form = new DynamicForm(); + dateRange = new DateRangeItem(); + dateRange.setToTitle(MESSAGES.to()); + dateRange.setFromTitle(MESSAGES.from()); + dateRange.setShowTitle(false); + form.setFields(dateRange); + + layout.addMember(form); + return layout; + + } + + + @Override + public Object getMaxLower() { + return maxLower; + } + + + protected long getLowerAsLong() { + Date d = dateRange.getFromDate(); + return d.getTime(); + } + + + protected long getUpperAsLong() { + Date d = dateRange.getToDate(); + return d.getTime(); + } + + + @Override + public Object getMaxUpper() { + Date d = dateRange.getToDate(); + return new Long(d.getTime()); + } + + + @Override + public void setLower(String lower) { + try { + long value = Long.valueOf(lower); + dateRange.setFromDate(new Date(value)); + } + catch (NumberFormatException nfe) { + GWT.log("could not parse lower date."); + SC.warn(MESSAGES.warning_cannot_parse_date()); + } + } + + + @Override + public void setUpper(String upper) { + try { + long value = Long.valueOf(upper); + dateRange.setToDate(new Date(value)); + } + catch (NumberFormatException nfe) { + GWT.log("could not parse upper date."); + SC.warn(MESSAGES.warning_cannot_parse_date()); + } + } + + + protected String buildDateString(String raw) { + if (raw == null || raw.length() == 0) { + return ""; + } + + long value = Long.valueOf(raw); + Date date = new Date(value); + @SuppressWarnings("deprecation") + DateTimeFormat dtf = DateTimeFormat.getMediumDateFormat(); + + return dtf.format(date); + } + + + protected ListGrid initYearTable() { + String baseUrl = GWT.getHostPageBaseURL(); + + yearTable.setWidth100(); + yearTable.setHeight100(); + yearTable.setShowRecordComponents(true); + yearTable.setShowRecordComponentsByCell(true); + yearTable.setEmptyMessage(MESSAGES.empty_filter()); + yearTable.setCanReorderFields(false); + + CellFormatter cf = new CellFormatter() { + @Override + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum + ) { + if (value == null) { + return null; + } + else if (value.toString().equals("-1")) { + return ""; + } + else if (colNum == 3 || colNum == 4) { + return buildDateString(value.toString()); + } + else { + return value.toString(); + } + } + }; + + + ListGridField addstart = new ListGridField ("", MESSAGES.from()); + addstart.setType (ListGridFieldType.ICON); + addstart.setWidth (20); + addstart.setCellIcon(baseUrl + MESSAGES.markerGreen()); + addstart.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(RecordClickEvent e) { + Record r = e.getRecord(); + if (r.getAttribute("start").equals("-1")) { + return; + } + else { + setLower(r.getAttribute("start")); + } + } + }); + + ListGridField addend = new ListGridField ("", MESSAGES.to()); + addend.setType (ListGridFieldType.ICON); + addend.setWidth (20); + addend.setCellIcon(baseUrl + MESSAGES.markerRed()); + addend.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(RecordClickEvent e) { + Record r = e.getRecord(); + if (r.getAttribute("end").equals("-1")) { + return; + } + else { + setUpper(r.getAttribute("end")); + } + } + }); + + ListGridField desc = + new ListGridField("description", MESSAGES.discharge_curve_gaugeless()); + desc.setType(ListGridFieldType.TEXT); + desc.setWidth("*"); + + ListGridField start = + new ListGridField("start", MESSAGES.start_year()); + start.setType(ListGridFieldType.INTEGER); + start.setWidth(100); + start.setCellFormatter(cf); + + ListGridField end = + new ListGridField("end", MESSAGES.end_year()); + end.setType(ListGridFieldType.INTEGER); + end.setWidth(100); + end.setCellFormatter(cf); + + yearTable.setFields(addstart, addend, desc, start, end); + + return yearTable; + } + + + protected long getGaugeNumber() { + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + String gauge = ""; + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + if (dl.getState().equals("state.winfo.historicalq.reference_gauge")) { + for (int j = 0; j < dl.size(); j++) { + Data d = dl.get(j); + DataItem[] di = d.getItems(); + if (di != null && di.length == 1) { + gauge = d.getItems()[0].getStringValue(); + } + } + } + } + } + try { + return Long.parseLong(gauge); + } + catch (NumberFormatException nfe) { + GWT.log("Error parsing gauge."); + return 0; + } + } + + + /** Return List of error messages, if not validated. */ + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + + Date from = dateRange.getFromDate(); + Date to = dateRange.getToDate(); + + if (from == null || to == null) { + String msg = MSG.error_validate_date_range(); + errors.add(msg); + } + + long maxLow = (Long) getMaxLower(); + long maxUpper = (Long) getMaxUpper(); + long inLow = from.getTime(); + long inUpper = to.getTime(); + + if (inLow < maxLow) { + errors.add(MSG.error_validate_date_range_invalid()); + } + else if (inUpper > maxUpper) { + errors.add(MSG.error_validate_date_range_invalid()); + } + else if (inLow > inUpper) { + errors.add(MSG.error_validate_date_range_invalid()); + } + + return errors; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/HWSDatacagePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,128 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.List; + + +public class HWSDatacagePanel +extends DatacagePanel +{ + public static final String OUT = "floodmap-hws"; + public static final String PARAMETERS = "hws:true;load-system:true"; + + + public HWSDatacagePanel() { + super(); + } + + + public HWSDatacagePanel(User user) { + super(user); + } + + + @Override + protected void createWidget() { + super.createWidget(); + widget.setIsMutliSelectable(true); + } + + + @Override + public String getOuts() { + return OUT; + } + + + @Override + public String getParameters() { + return PARAMETERS; + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + + return errors; + } + + @Override + public Canvas createOld(DataList dataList) { + GWT.log("old datacage##########################################"); + HLayout layout = new HLayout(); + VLayout vLayout = new VLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + int size = dataList.size(); + for (int i = 0; i < size; i++) { + Data data = dataList.get(i); + DataItem[] items = data.getItems(); + + for (DataItem item: items) { + HLayout hLayout = new HLayout(); + + hLayout.addMember(label); + hLayout.addMember(new Label(item.getLabel())); + + vLayout.addMember(hLayout); + vLayout.setWidth("130px"); + } + } + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + + @Override + protected Data[] getData() { + String[] selection = this.widget.getSelectionTitles(); + String result = ""; + boolean first = true; + if (selection != null) { + for (String record: selection) { + if (first) { + result += record; + first = false; + } + else { + result += ";" + record; + } + } + } + if (result.length() == 0) { + result = MSG.notselected(); + } + Data[] data = new Data[1]; + DataItem item = new DefaultDataItem( + "uesk.hws", "uesk.hws", result); + data[0] = new DefaultData("uesk.hws", null, null, new DataItem[] {item}); + + return data; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ImgLink.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,53 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.HTMLPane; + + +public class ImgLink extends HTMLPane { + + private int width; + private int height; + + private String href; + private String imgUrl; + + private boolean newTab; + + + public ImgLink(String imgUrl, String href, int width, int height) { + super(); + + this.width = width; + this.height = height; + this.href = href; + this.imgUrl = imgUrl; + this.newTab = false; + + update(); + } + + + public ImgLink(String imgUrl, String href, int w, int h, boolean newTab) { + this(imgUrl, href, w, h); + this.newTab = newTab; + + update(); + } + + + protected void update() { + String target = newTab ? "_blank" : "_self"; + + setContents("<a target='" + target + "' href='" + href + "'><img src='" + imgUrl + "'></a>"); + setWidth(width); + setHeight(height); + setOverflow(Overflow.VISIBLE); + } + + + public void setSource(String href) { + this.href = href; + update(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/IntegerRangePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,160 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.IntegerItem; +import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator; +import com.smartgwt.client.widgets.form.validator.Validator; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.IntegerRangeData; + + +public class IntegerRangePanel extends RangePanel { + + private static final long serialVersionUID = -7471199535764887461L; + + protected Integer maxLower; + protected Integer maxUpper; + + + @Override + protected Data[] getData() { + Integer lo = getLowerAsInt(); + Integer up = getUpperAsInt(); + + return new Data[] { new IntegerRangeData(getDataName(), null, lo, up) }; + } + + + @Override + protected FormItem newFormItem(String name) { + IntegerItem item = new IntegerItem(name, ""); + item.setShowTitle(false); + + return item; + } + + + @Override + protected Validator[] createLowerValidators(DataList dataList) { + setMaxLower(dataList); + setMaxUpper(dataList); + + Validator validator = newRangeValidator(); + + if (validator != null) { + return new Validator[] { validator }; + } + + return null; + } + + + @Override + protected Validator[] createUpperValidators(DataList dataList) { + setMaxLower(dataList); + setMaxUpper(dataList); + + Validator validator = newRangeValidator(); + + if (validator != null) { + return new Validator[] { validator }; + } + + return null; + } + + + @Override + public Object getMaxLower() { + return maxLower; + } + + + @Override + public Object getMaxUpper() { + return maxUpper; + } + + + public Integer getLowerAsInt() { + String raw = getLower(); + + if (raw != null && raw.length() > 0) { + try { + return Integer.valueOf(raw); + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + return null; + } + + + public Integer getUpperAsInt() { + String raw = getUpper(); + + if (raw != null && raw.length() > 0) { + try { + return Integer.valueOf(raw); + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + return null; + } + + + protected Validator newRangeValidator() { + Integer maxLower = getMaxLowerAsInt(); + Integer maxUpper = getMaxUpperAsInt(); + + if (maxLower != null && maxUpper != null) { + IntegerRangeValidator validator = new IntegerRangeValidator(); + validator.setMax(maxUpper); + validator.setMin(maxLower); + + return validator; + } + + return null; + } + + + public Integer getMaxLowerAsInt() { + return maxLower; + } + + + protected void setMaxLower(DataList dataList) { + IntegerRangeData range = (IntegerRangeData) dataList.get(0); + setMaxLower((Integer) range.getLower()); + } + + + public void setMaxLower(Integer maxLower) { + this.maxLower = maxLower; + } + + + public Integer getMaxUpperAsInt() { + return maxUpper; + } + + + protected void setMaxUpper(DataList dataList) { + IntegerRangeData range = (IntegerRangeData) dataList.get(0); + setMaxUpper((Integer) range.getUpper()); + } + + + public void setMaxUpper(Integer maxUpper) { + this.maxUpper = maxUpper; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/LinkSelection.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,181 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.LinkItem; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.StepForwardEvent; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + + +/** + * This UIProvider displays the DataItems of the Data object in a list of links. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class LinkSelection +extends MapSelection +{ + + private static final long serialVersionUID = -7138270638349711024L; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants messages = GWT.create(FLYSConstants.class); + + /** The selected river*/ + protected Data river; + + /** + * This method currently returns a + * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all + * data items in a list of links stored in <i>data</i>. + * + * @param data The {@link Data} object. + * + * @return a combobox. + */ + @Override + public Canvas create(DataList data) { + VLayout v = new VLayout(); + v.setMembersMargin(10); + v.setAlign(VerticalAlignment.TOP); + if (data.getState() == null) { + Canvas module = super.createWidget(data); + v.addMember(module); + } + Canvas content = createWidget(data); + v.addMember(content); + + return v; + } + + + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + VLayout vLayout = new VLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + int size = dataList.size(); + for (int i = 0; i < size; i++) { + Data data = dataList.get(i); + DataItem[] items = data.getItems(); + + for (DataItem item: items) { + HLayout hLayout = new HLayout(); + + hLayout.addMember(label); + hLayout.addMember(new Label(item.getLabel())); + + vLayout.addMember(hLayout); + vLayout.setWidth("130px"); + } + } + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + + /** + * This method creates the content of the widget. + * + * @param data The {@link Data} object. + * + * @return a list of links + */ + @Override + protected Canvas createWidget(DataList data) { + GWT.log("LinkSelection - create()"); + + VLayout layout = new VLayout(); + layout.setAlign(VerticalAlignment.TOP); + layout.setHeight(25); + + VLayout formLayout = new VLayout(); + + formLayout.setLayoutLeftMargin(60); + int size = data.size(); + + for (int i = 0; i < size; i++) { + Data d = data.get(i); + + Label label = new Label(d.getDescription()); + label.setValign(VerticalAlignment.TOP); + label.setHeight(20); + + for (DataItem item: d.getItems()) { + LinkItem link = new LinkItem("river"); + link.setLinkTitle(item.getLabel()); + link.setTarget(item.getStringValue()); + link.setShowTitle(false); + DynamicForm f = new DynamicForm(); + f.setItems(link); + formLayout.addMember(f); + link.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + DataItem item = new DefaultDataItem( + ((LinkItem)event.getItem()).getLinkTitle(), + null, + ((LinkItem)event.getItem()).getLinkTitle()); + + river = new DefaultData( + "river", + null, + null, + new DataItem [] {item}); + fireStepForwardEvent (new StepForwardEvent (getData())); + } + }); + + } + label.setWidth(50); + + layout.addMember(label); + layout.addMember(formLayout); + } + layout.setAlign(VerticalAlignment.TOP); + + String baseUrl = GWT.getHostPageBaseURL(); + Img map = new Img(baseUrl + messages.riverMap(), 494, 582); + helperContainer.addMember(map); + + return layout; + } + + + @Override + protected Data[] getData() { + Data[] module = super.getData(); + if (module != null) { + return new Data[] {module[0], river}; + } + else { + return new Data[] {river}; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/LoadingPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,257 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.Positioning; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.HasStepBackHandlers; +import de.intevation.flys.client.client.event.StepBackEvent; +import de.intevation.flys.client.client.event.StepBackHandler; +import de.intevation.flys.client.client.services.DescribeArtifactService; +import de.intevation.flys.client.client.services.DescribeArtifactServiceAsync; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.CalculationMessage; +import de.intevation.flys.client.shared.model.DataList; + +import java.util.ArrayList; +import java.util.List; + + +public class LoadingPanel extends Canvas implements HasStepBackHandlers { + + private static final long serialVersionUID = -7806425431408987601L; + + public static final int UPDATE_INTERVAL = 1000 * 3; + + public static final DescribeArtifactServiceAsync describe = + GWT.create(DescribeArtifactService.class); + + private FLYSConstants MSG = GWT.create(FLYSConstants.class); + + + protected List<StepBackHandler> handlers; + + protected CollectionView parent; + protected Artifact artifact; + + protected VLayout dialog; + protected HLayout cancelRow; + protected Label msg; + protected Label title; + + protected int i; + + + public LoadingPanel(CollectionView parent, Artifact artifact) { + super(); + + this.handlers = new ArrayList<StepBackHandler>(); + this.parent = parent; + this.artifact = artifact; + this.msg = new Label(""); + this.title = new Label(""); + this.dialog = createDialog(); + + this.i = 0; + + initLayout(); + startTimer(); + } + + + private void initLayout() { + setWidth("100%"); + setHeight("98%"); + setBackgroundColor("#7f7f7f"); + setOpacity(50); + setPosition(Positioning.RELATIVE); + + parent.addChild(this); + parent.addChild(dialog); + dialog.moveTo(0, 20); + moveTo(0, 7); + } + + + public void setArtifact(Artifact artifact) { + this.artifact = artifact; + } + + + public Artifact getArtifact() { + return artifact; + } + + + @Override + public void addStepBackHandler(StepBackHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + /** + * This method is called after the user has clicked the button to cancel the + * current process. + * + * @param e The StepBackEvent. + */ + protected void fireStepBackEvent(StepBackEvent e) { + for (StepBackHandler handler: handlers) { + handler.onStepBack(e); + } + } + + + protected VLayout createDialog() { + + String baseUrl = GWT.getHostPageBaseURL(); + + title.setStyleName("loading-title"); + title.setHeight(25); + title.setWidth100(); + + msg.setStyleName("loading-message"); + msg.setValign(VerticalAlignment.TOP); + msg.setWidth100(); + msg.setHeight(100); + + Img img = new Img(baseUrl + MSG.loadingImg(), 25, 25); + + Label cancelLabel = new Label(MSG.cancelCalculationLabel()); + Img cancel = new Img(baseUrl + MSG.cancelCalculation(), 25, 25); + cancel.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + cancel(); + } + }); + + cancelRow = new HLayout(); + cancelRow.setHeight(27); + cancelRow.setWidth100(); + cancelRow.addMember(cancel); + cancelRow.addMember(cancelLabel); + + VLayout box = new VLayout(); + box.setStyleName("loading-box"); + box.setAlign(VerticalAlignment.TOP); + box.setDefaultLayoutAlign(VerticalAlignment.TOP); + box.addMember(title); + box.addMember(msg); + box.addMember(cancelRow); + box.setMembersMargin(0); + box.setHeight(125); + box.setWidth(275); + + dialog = new VLayout(); + dialog.setAlign(Alignment.CENTER); + dialog.setDefaultLayoutAlign(Alignment.CENTER); + dialog.setMembersMargin(5); + dialog.setHeight100(); + dialog.setWidth100(); + + dialog.addMember(img); + dialog.addMember(box); + + return dialog; + } + + + public String getTargetState() { + ArtifactDescription desc = getArtifact().getArtifactDescription(); + DataList[] oldData = desc.getOldData(); + + return oldData[oldData.length -1].getState(); + } + + + private void startTimer() { + Timer t = new Timer() { + @Override + public void run() { + update(); + } + }; + t.schedule(UPDATE_INTERVAL); + } + + + protected void update() { + updateMessage(); + + final Config config = Config.getInstance(); + final String locale = config.getLocale(); + + describe.describe(locale, artifact, new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable t) { + GWT.log("Error while DESCRIBE artifact: " + t.getMessage()); + + startTimer(); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully DESCRIBE artifact."); + + setArtifact(artifact); + + if (artifact.isInBackground()) { + startTimer(); + } + else { + finish(); + } + } + }); + } + + + protected void updateMessage() { + List<CalculationMessage> messages = artifact.getBackgroundMessages(); + if (messages != null && messages.size() > 0) { + CalculationMessage calcMsg = messages.get(0); + title.setContents(getStepTitle(calcMsg)); + msg.setContents(calcMsg.getMessage()); + } + else { + title.setContents(MSG.calculationStarted()); + } + } + + + protected String getStepTitle(CalculationMessage msg) { + return MSG.step() + " " + msg.getCurrentStep() + "/" + msg.getSteps(); + } + + + private void cancel() { + fireStepBackEvent(new StepBackEvent(getTargetState())); + parent.removeChild(dialog); + parent.removeChild(this); + } + + + private void finish() { + parent.removeChild(dialog); + parent.removeChild(this); + parent.setArtifact(artifact); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/LocationDistancePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,1439 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.data.AdvancedCriteria; +import com.smartgwt.client.data.Criteria; +import com.smartgwt.client.data.Criterion; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.OperatorId; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.RadioGroupItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; +import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.FilterHandler; +import de.intevation.flys.client.client.event.RangeFilterEvent; +import de.intevation.flys.client.client.event.StringFilterEvent; +import de.intevation.flys.client.client.services.DistanceInfoService; +import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; +import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.DistanceInfoObject; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + + +/** + * This UIProvider creates a widget to enter locations or a distance. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class LocationDistancePanel +extends AbstractUIProvider +implements ChangeHandler, BlurHandler, FilterHandler +{ + private static final long serialVersionUID = -10820092176039372L; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + /** The DistanceInfoService used to retrieve locations about rivers. */ + protected DistanceInfoServiceAsync distanceInfoService = + GWT.create(DistanceInfoService.class); + + public static final String FIELD_MODE = "mode"; + + /** The constant name of the input field to enter the start of a distance.*/ + public static final String FIELD_FROM = "from"; + + /** The constant name of the input field to enter the end of a distance.*/ + public static final String FIELD_TO = "to"; + + /** The constant name of the input field to enter locations.*/ + public static final String FIELD_VALUE_LOCATION = "location"; + + /** The constant name of the input field to enter distance.*/ + public static final String FIELD_VALUE_DISTANCE = "distance"; + + /** The constant name of the input field to enter the step width of a + * distance.*/ + public static final String FIELD_WIDTH = "width"; + + public static final int WIDTH = 250; + + + /** The radio group for input mode selection.*/ + protected DynamicForm mode; + + /** A container that will contain the location or the distance panel.*/ + protected HLayout container; + + /** The min value for a distance.*/ + protected double min; + + /** The max value for a distance.*/ + protected double max; + + /** The 'from' value entered in the distance mode.*/ + protected double from; + + /** The 'to' value entered in the distance mode.*/ + protected double to; + + /** The 'step' value entered in the distance mode.*/ + protected double step; + + /** The values entered in the location mode.*/ + protected double[] values; + + /** The input panel for locations. */ + protected DoubleArrayPanel locationPanel; + + /** The input panel for distances. */ + protected DoubleRangePanel distancePanel; + + /** The tab set containing the location and distance table. */ + protected TabSet inputTables; + + /** The distance table. */ + protected ListGrid distanceTable; + + /** The locations table. */ + protected ListGrid locationsTable; + + /** The locations table for distance input. */ + protected ListGrid locationDistanceTable; + + /** The table data. */ + protected DistanceInfoObject[] tableData; + + /** The table filter.*/ + protected TableFilter filterDescription; + protected RangeTableFilter filterRange; + + /** The Combobox for table filter criteria. */ + protected SelectItem filterCriteria; + protected StaticTextItem filterResultCount; + protected ListGrid currentFiltered; + + /** + * Creates a new LocationDistancePanel instance. + */ + public LocationDistancePanel() { + distanceTable = new ListGrid(); + distanceTable.setAutoFetchData(true); + + locationsTable = new ListGrid(); + locationsTable.setAutoFetchData(true); + + locationDistanceTable = new ListGrid(); + locationDistanceTable.setAutoFetchData(true); + + locationDistanceTable.setShowHeaderContextMenu(false); + distanceTable.setShowHeaderContextMenu(false); + locationsTable.setShowHeaderContextMenu(false); + } + + + /** + * This method creates a widget that contains a label, a panel with + * checkboxes to switch the input mode between location and distance input, + * and a the mode specific panel. + * + * @param data The data that might be inserted. + * + * @return a panel. + */ + @Override + public Canvas create(DataList data) { + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + + Label label = new Label(MESSAGES.location_distance_state()); + Canvas widget = createWidget(data); + Canvas submit = getNextButton(); + createDistanceInputPanel(); + + initDefaults(data); + + createLocationTableDistance (); + createDistanceTable(); + createLocationTable(); + + widget.setHeight(50); + label.setHeight(25); + + layout.addMember(label); + layout.addMember(widget); + layout.addMember(submit); + + return layout; + } + + + /** + * This method creates a table that contains the distance values. + */ + protected void createDistanceTable() { + + String baseUrl = GWT.getHostPageBaseURL(); + + distanceTable.setWidth100(); + distanceTable.setShowRecordComponents(true); + distanceTable.setShowRecordComponentsByCell(true); + distanceTable.setHeight100(); + distanceTable.setEmptyMessage(MESSAGES.empty_filter()); + distanceTable.setCanReorderFields(false); + + CellFormatter cf = new CellFormatter() { + @Override + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum) { + if (value == null) return null; + try { + NumberFormat nf; + double v = Double.parseDouble((String)value); + nf = NumberFormat.getFormat("###0.00##"); + return nf.format(v); + } + catch (Exception e) { + return value.toString(); + } + } + }; + + ListGridField addDistance = new ListGridField ("", ""); + addDistance.setType (ListGridFieldType.ICON); + addDistance.setWidth (20); + addDistance.addRecordClickHandler (new RecordClickHandler () { + @Override + public void onRecordClick (RecordClickEvent e) { + if (!isLocationMode ()) { + Record r = e.getRecord(); + try { + double min = Double.parseDouble(r.getAttribute("from")); + double max = Double.parseDouble(r.getAttribute("to")); + setDistanceValues(min, max); + } + catch(NumberFormatException nfe) { + // Is there anything to do? + } + } + else { + double[] selected; + Record r = e.getRecord(); + double min = 0, max = 0; + try { + min = Double.parseDouble(r.getAttribute("from")); + max = Double.parseDouble(r.getAttribute("to")); + } + catch(NumberFormatException nfe) { + // Is there anything to do? + } + if (getLocationValues() != null) { + double[] val = getLocationValues(); + selected = new double[val.length + 2]; + for(int i = 0; i < val.length; i++){ + selected[i] = val[i]; + } + selected[val.length] = min; + selected[val.length + 1] = max; + } + else { + selected = new double[2]; + selected[0] = min; + selected[1] = max; + } + setLocationValues(selected); + } + } + }); + addDistance.setCellIcon(baseUrl + MESSAGES.markerGreen()); + + ListGridField ddescr = new ListGridField("description", + MESSAGES.description()); + ddescr.setType(ListGridFieldType.TEXT); + ddescr.setWidth("*"); + ListGridField from = new ListGridField("from", MESSAGES.from()); + from.setCellFormatter(cf); + + from.setWidth("12%"); + ListGridField to = new ListGridField("to", MESSAGES.to()); + to.setType(ListGridFieldType.FLOAT); + to.setCellFormatter(cf); + + to.setWidth("12%"); + to.setAlign(Alignment.LEFT); + ListGridField dside = new ListGridField("riverside", + MESSAGES.riverside()); + dside.setType(ListGridFieldType.TEXT); + dside.setWidth("12%"); + + ListGridField bottom = + new ListGridField("bottom", MESSAGES.bottom_edge()); + bottom.setType(ListGridFieldType.TEXT); + bottom.setWidth("10%"); + bottom.setCellFormatter(cf); + + ListGridField top = + new ListGridField("top", MESSAGES.top_edge()); + top.setType(ListGridFieldType.TEXT); + top.setWidth("10%"); + top.setCellFormatter(cf); + + distanceTable.setFields( + addDistance, ddescr, from, to, dside, bottom, top); + } + + + /** + * This method creates a table that contains the location values. + */ + protected void createLocationTable() { + + String baseUrl = GWT.getHostPageBaseURL(); + + locationsTable.setWidth100(); + locationsTable.setShowRecordComponents(true); + locationsTable.setShowRecordComponentsByCell(true); + locationsTable.setHeight100(); + locationsTable.setEmptyMessage(MESSAGES.empty_filter()); + locationsTable.setCanReorderFields(false); + + CellFormatter cf = new CellFormatter() { + @Override + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum) { + if (value == null) return null; + try { + NumberFormat nf; + double v = Double.parseDouble((String)value); + nf = NumberFormat.getFormat("###0.00##"); + return nf.format(v); + } + catch (Exception e) { + return value.toString(); + } + } + }; + + + + ListGridField addLocation = new ListGridField ("", ""); + addLocation.setType (ListGridFieldType.ICON); + addLocation.setWidth (20); + + addLocation.addRecordClickHandler (new RecordClickHandler () { + @Override + public void onRecordClick (RecordClickEvent e) { + Record record = e.getRecord(); + double[] selected; + if (getLocationValues() != null) { + double[] val = getLocationValues(); + selected = new double[val.length + 1]; + for(int i = 0; i < val.length; i++){ + selected[i] = val[i]; + } + try { + selected[val.length] = + Double.parseDouble(record.getAttribute("from")); + } + catch(NumberFormatException nfe) { + // Is there anything to do here? + } + } + else { + selected = new double[1]; + selected[0] = + Double.parseDouble(record.getAttribute("from")); + } + setLocationValues(selected); + } + }); + addLocation.setCellIcon (baseUrl + MESSAGES.markerGreen ()); + + ListGridField ldescr = new ListGridField("description", + MESSAGES.description()); + ldescr.setType(ListGridFieldType.TEXT); + ldescr.setWidth("*"); + ListGridField lside = new ListGridField("riverside", + MESSAGES.riverside()); + lside.setType(ListGridFieldType.TEXT); + lside.setWidth("12%"); + ListGridField loc = new ListGridField("from", MESSAGES.locations()); + loc.setAlign(Alignment.LEFT); + loc.setType(ListGridFieldType.FLOAT); + loc.setWidth("12%"); + loc.setCellFormatter(cf); + + ListGridField bottom = + new ListGridField("bottom", MESSAGES.bottom_edge()); + bottom.setType(ListGridFieldType.TEXT); + bottom.setWidth("10%"); + bottom.setCellFormatter(cf); + + ListGridField top = + new ListGridField("top", MESSAGES.top_edge()); + top.setType(ListGridFieldType.TEXT); + top.setWidth("10%"); + top.setCellFormatter(cf); + + locationsTable.setFields(addLocation, ldescr, loc, lside, bottom, top); + } + + + /** + * This method creates a table that contains the location values. + */ + protected void createLocationTableDistance (){ + + String baseUrl = GWT.getHostPageBaseURL(); + + locationDistanceTable.setWidth100(); + locationDistanceTable.setShowRecordComponents(true); + locationDistanceTable.setShowRecordComponentsByCell(true); + locationDistanceTable.setHeight100(); + locationDistanceTable.setEmptyMessage(MESSAGES.empty_filter()); + locationDistanceTable.setCanReorderFields(false); + + CellFormatter cf = new CellFormatter() { + @Override + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum) { + if (value == null) return null; + try { + NumberFormat nf; + double v = Double.parseDouble((String)value); + nf = NumberFormat.getFormat("###0.00##"); + return nf.format(v); + } + catch (Exception e) { + return value.toString(); + } + } + }; + + ListGridField addfrom = new ListGridField ("from", MESSAGES.from()); + addfrom.setType (ListGridFieldType.ICON); + addfrom.setWidth (30); + addfrom.setCellIcon(baseUrl + MESSAGES.markerGreen()); + + ListGridField addto2 = new ListGridField ("to", MESSAGES.to()); + addto2.setType (ListGridFieldType.ICON); + addto2.setWidth (30); + addto2.setCellIcon(baseUrl + MESSAGES.markerRed()); + + locationDistanceTable.addCellClickHandler (new CellClickHandler () { + @Override + public void onCellClick (CellClickEvent e) { + if (e.getColNum() == 0) { + Record r = e.getRecord (); + try { + double fromvalue = + Double.parseDouble(r.getAttribute("from")); + double tovalue = getTo (); + setDistanceValues (fromvalue, tovalue); + } + catch(NumberFormatException nfe) { + // Is there anything to do in here? + } + } + else if (e.getColNum() == 1) { + Record r = e.getRecord (); + try { + double fromvalue = getFrom (); + double tovalue = + Double.parseDouble(r.getAttribute("from")); + setDistanceValues (fromvalue, tovalue); + } + catch(NumberFormatException nfe) { + // Is there anything to do in here? + } + } + } + }); + ListGridField bottom = + new ListGridField("bottom", MESSAGES.bottom_edge()); + bottom.setType(ListGridFieldType.TEXT); + bottom.setWidth("10%"); + bottom.setCellFormatter(cf); + + ListGridField top = + new ListGridField("top", MESSAGES.top_edge()); + top.setType(ListGridFieldType.TEXT); + top.setWidth("10%"); + top.setCellFormatter(cf); + + ListGridField ldescr = new ListGridField("description", + MESSAGES.description()); + ldescr.setType(ListGridFieldType.TEXT); + ldescr.setWidth("*"); + ListGridField lside = new ListGridField("riverside", + MESSAGES.riverside()); + lside.setType(ListGridFieldType.TEXT); + lside.setWidth("12%"); + ListGridField loc = new ListGridField("from", MESSAGES.locations()); + loc.setType(ListGridFieldType.FLOAT); + loc.setAlign(Alignment.LEFT); + loc.setWidth("12%"); + loc.setCellFormatter(cf); + + locationDistanceTable.setFields( + addfrom, addto2, ldescr, loc, lside, bottom, top); + } + + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data dMode = getData(items, "ld_mode"); + DataItem[] dItems = dMode.getItems(); + + boolean rangeMode = true; + if (dItems != null && dItems[0] != null) { + rangeMode = FIELD_VALUE_DISTANCE.equals(dItems[0].getStringValue()); + } + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + + if (rangeMode) { + layout.addMember(getOldRangeSelection(dataList)); + } + else { + layout.addMember(getOldLocationSelection(dataList)); + } + + layout.addMember(back); + + return layout; + } + + + /** + * Creates a label for the selected range. + * + * @param dataList The DataList containing all values for this state. + * + * @return A label displaying the selected values. + */ + protected Label getOldRangeSelection(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data dFrom = getData(items, "ld_from"); + Data dTo = getData(items, "ld_to"); + Data dStep = getData(items, "ld_step"); + + DataItem[] from = dFrom.getItems(); + DataItem[] to = dTo.getItems(); + DataItem[] step = dStep.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(from[0].getLabel()); + sb.append(" " + MESSAGES.unitFrom() + " "); + sb.append(to[0].getLabel()); + sb.append(" " + MESSAGES.unitTo() + " "); + sb.append(step[0].getLabel()); + sb.append(" " + MESSAGES.unitWidth()); + + Label selected = new Label(sb.toString()); + selected.setWidth("130px"); + + return selected; + } + + + /** + * Creates a label for the selected locations. + * + * @param dataList The DataList containing all values for this state. + * + * @return A label displaying the selected values. + */ + protected Label getOldLocationSelection(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data dLocations = getData(items, "ld_locations"); + DataItem[] lItems = dLocations.getItems(); + + String[] splitted = lItems[0].getStringValue().split(" "); + String value = ""; + for (int i = 0; i < splitted.length; i++) { + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double dv = Double.parseDouble(splitted[i]); + value += nf.format(dv) + " "; + } + catch(NumberFormatException nfe) { + value += splitted[i] + " "; + } + } + + Label selected = new Label(value); + selected.setWidth(130); + + return selected; + } + + + /** + * This method reads the default values defined in the DataItems of the Data + * objects in <i>list</i>. + * + * @param list The DataList container that stores the Data objects. + */ + protected void initDefaults(DataList list) { + Data m = getData(list.getAll(), "ld_mode"); + Data l = getData(list.getAll(), "ld_locations"); + Data f = getData(list.getAll(), "ld_from"); + Data t = getData(list.getAll(), "ld_to"); + Data s = getData(list.getAll(), "ld_step"); + + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + DataItem[] sItems = s.getItems(); + + min = Double.valueOf(fItems[0].getStringValue()); + max = Double.valueOf(tItems[0].getStringValue()); + step = Double.valueOf(sItems[0].getStringValue()); + + DataItem mDef = m.getDefault(); + DataItem lDef = l.getDefault(); + DataItem fDef = f.getDefault(); + DataItem tDef = t.getDefault(); + DataItem sDef = s.getDefault(); + + String mDefValue = mDef != null ? mDef.getStringValue() : null; + String theMode = mDefValue != null && mDefValue.length() > 0 + ? mDef.getStringValue() + : FIELD_VALUE_DISTANCE; + + mode.setValue(FIELD_MODE, theMode); + + String fDefValue = fDef != null ? fDef.getStringValue() : null; + setFrom(fDefValue != null && fDefValue.length() > 0 + ? Double.valueOf(fDef.getStringValue()) + : min); + + String tDefValue = tDef != null ? tDef.getStringValue() : null; + setTo(tDefValue != null && tDefValue.length() > 0 + ? Double.valueOf(tDef.getStringValue()) + : max); + + String sDefValue = sDef != null ? sDef.getStringValue() : null; + setStep(sDefValue != null && sDefValue.length() > 0 + ? Double.valueOf(sDef.getStringValue()) + : step); + + if (lDef != null) { + String lDefValue = lDef != null ? lDef.getStringValue() : null; + + if (lDefValue != null && lDefValue.length() > 0) { + setLocationValues(lDef.getStringValue()); + } + } + + if (theMode.equals(FIELD_VALUE_DISTANCE)) { + enableDistancePanel(); + inputTables.selectTab(1); + } + currentFiltered = (ListGrid)inputTables.getSelectedTab().getPane(); + } + + + protected Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + container = new HLayout(); + Canvas checkboxPanel = createRadioButtonPanel(); + + // the initial view will display the location input mode + locationPanel = new DoubleArrayPanel( + MESSAGES.unitLocation(), + getLocationValues(), + this); + container.addMember(locationPanel); + + layout.addMember(checkboxPanel); + layout.addMember(container); + + container.setMembersMargin(30); + + inputTables = new TabSet(); + inputTables.addTabSelectedHandler(new TabSelectedHandler() { + @Override + public void onTabSelected(TabSelectedEvent evt) { + filterDescription.clear(); + filterRange.clear(); + filterResultCount.setValue(""); + + Canvas c = evt.getTabPane(); + if(c instanceof ListGrid) { + currentFiltered = (ListGrid)c; + } + } + }); + + Tab locations = new Tab(MESSAGES.locations()); + Tab distances = new Tab(MESSAGES.distance()); + + inputTables.setWidth100(); + inputTables.setHeight100(); + + locations.setPane(locationDistanceTable); + distances.setPane(distanceTable); + + inputTables.addTab(locations); + inputTables.addTab(distances); + + filterResultCount = new StaticTextItem(MESSAGES.resultCount()); + filterResultCount.setTitleAlign(Alignment.LEFT); + filterResultCount.setTitleStyle("color: #000"); + + filterDescription = new TableFilter(); + filterDescription.setHeight("30px"); + filterDescription.addFilterHandler(this); + + filterRange = new RangeTableFilter(); + filterRange.setHeight("30px"); + filterRange.addFilterHandler(this); + filterRange.setVisible(false); + + filterCriteria = new SelectItem(); + filterCriteria.setShowTitle(false); + filterCriteria.setWidth(100); + filterCriteria.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent e) { + if(e.getValue().toString().equals("range")) { + filterRange.setVisible(true); + filterDescription.setVisible(false); + filterDescription.clear(); + filterResultCount.setValue(""); + } + else { + filterRange.setVisible(false); + filterRange.clear(); + filterDescription.setVisible(true); + filterResultCount.setValue(""); + } + } + }); + + LinkedHashMap<String, String> filterMap = + new LinkedHashMap<String, String>(); + filterMap.put("description", MESSAGES.description()); + filterMap.put("range", MESSAGES.range()); + filterCriteria.setValueMap(filterMap); + filterCriteria.setValue("description"); + + DynamicForm form = new DynamicForm(); + form.setFields(filterCriteria); + inputTables.setHeight("*"); + DynamicForm form2 = new DynamicForm(); + form2.setFields(filterResultCount); + + VLayout helper = new VLayout(); + HLayout filterLayout = new HLayout(); + + filterLayout.addMember(form); + filterLayout.addMember(filterDescription); + filterLayout.addMember(filterRange); + filterLayout.setHeight("30px"); + helper.addMember(inputTables); + helper.addMember(filterLayout); + helper.addMember(form2); + helper.setHeight100(); + helper.setWidth100(); + + helperContainer.addMember(helper); + filterLayout.setWidth("200"); + + return layout; + } + + + @Override + public void onFilterCriteriaChanged(StringFilterEvent event) { + String search = event.getFilter(); + + if (search != null && search.length() > 0) { + Criteria c = new Criteria("description", search); + + locationsTable.filterData(c); + distanceTable.filterData(c); + locationDistanceTable.filterData(c); + filterResultCount.setValue(currentFiltered.getRecords().length); + } + else { + locationsTable.clearCriteria(); + distanceTable.clearCriteria(); + locationDistanceTable.clearCriteria(); + filterResultCount.setValue(""); + } + } + + + @Override + public void onFilterCriteriaChanged(RangeFilterEvent event) { + Float from = event.getFrom() - 0.001f; + Float to = event.getTo() + 0.001f; + GWT.log("filtering range: " + from + " to " + to); + + + Criterion combinedFilter = null; + Criterion locationFilter = null; + if (from.equals(Float.NaN) && to.equals(Float.NaN)) { + locationsTable.clearCriteria(); + distanceTable.clearCriteria(); + locationDistanceTable.clearCriteria(); + filterResultCount.setValue(""); + return; + } + else if (from.equals(Float.NaN)) { + combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); + locationFilter = + new Criterion("from", OperatorId.LESS_OR_EQUAL, to); + locationsTable.filterData(locationFilter); + distanceTable.filterData(combinedFilter); + locationDistanceTable.filterData(combinedFilter); + filterResultCount.setValue(currentFiltered.getRecords().length); + return; + } + else if (to.equals(Float.NaN)) { + combinedFilter = + new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); + locationsTable.filterData(combinedFilter); + distanceTable.filterData(combinedFilter); + locationDistanceTable.filterData(combinedFilter); + } + else { + AdvancedCriteria c1 = + new AdvancedCriteria(OperatorId.AND, new Criterion[] { + new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), + new Criterion("from", OperatorId.LESS_OR_EQUAL, to) + }); + + AdvancedCriteria c2 = + new AdvancedCriteria(OperatorId.AND, new Criterion[] { + new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), + new Criterion("to", OperatorId.LESS_OR_EQUAL, to) + }); + + AdvancedCriteria c3 = + new AdvancedCriteria(OperatorId.AND, new Criterion[] { + new Criterion("from", OperatorId.LESS_OR_EQUAL, to), + new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) + }); + + combinedFilter = + new AdvancedCriteria(OperatorId.OR, new Criterion[] { + c1, c2, c3 + }); + } + locationsTable.filterData(combinedFilter); + distanceTable.filterData(combinedFilter); + locationDistanceTable.filterData(combinedFilter); + filterResultCount.setValue(currentFiltered.getRecords().length); + } + + + @Override + public List<String> validate() { + if (isLocationMode()) { + return validateLocations(); + } + else { + return validateRange(); + } + } + + + protected List<String> validateLocations() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + try { + saveLocationValues(locationPanel); + } + catch (Exception e) { + errors.add(MESSAGES.wrongFormat()); + } + + double[] values = getLocationValues(); + double[] good = new double[values.length]; + int idx = 0; + + for (double value: values) { + if (value < min || value > max) { + String tmp = MESSAGES.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(min)); + tmp = tmp.replace("$3", nf.format(max)); + errors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!errors.isEmpty()) { + locationPanel.setValues(justGood); + } + + return errors; + } + + + protected List<String> validateRange() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + try { + saveDistanceValues(distancePanel); + } + catch (Exception e) { + errors.add(MESSAGES.wrongFormat()); + } + + double from = getFrom(); + double to = getTo(); + double step = getStep(); + + if (from < min || from > max) { + String tmp = MESSAGES.error_validate_lower_range(); + tmp = tmp.replace("$1", nf.format(from)); + tmp = tmp.replace("$2", nf.format(min)); + errors.add(tmp); + from = min; + } + + if (to < min || to > max) { + String tmp = MESSAGES.error_validate_upper_range(); + tmp = tmp.replace("$1", nf.format(to)); + tmp = tmp.replace("$2", nf.format(max)); + errors.add(tmp); + to = max; + } + + if (!errors.isEmpty()) { + distancePanel.setValues(from, to, step); + } + + return errors; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + // If we have entered a value and click right afterwards on the + // 'next' button, the BlurEvent is not fired, and the values are not + // saved. So, we gonna save those values explicitly. + if (isLocationMode()) { + Canvas member = container.getMember(0); + if (member instanceof DoubleArrayPanel) { + DoubleArrayPanel form = (DoubleArrayPanel) member; + saveLocationValues(form); + } + + Data dLocations = getDataLocations(); + DataItem dFrom = new DefaultDataItem("ld_from", "ld_from", ""); + DataItem dTo = new DefaultDataItem("ld_to", "ld_to", ""); + DataItem dStep = new DefaultDataItem("ld_step", "ld_step", ""); + + data.add(dLocations); + data.add(new DefaultData( + "ld_from", null, null, new DataItem[] { dFrom } )); + data.add(new DefaultData( + "ld_to", null, null, new DataItem[] { dTo } )); + data.add(new DefaultData( + "ld_step", null, null, new DataItem[] { dStep } )); + } + else { + Canvas member = container.getMember(0); + if (member instanceof DoubleRangePanel) { + DoubleRangePanel form = (DoubleRangePanel) member; + saveDistanceValues(form); + } + + Data dFrom = getDataFrom(); + Data dTo = getDataTo(); + Data dStep = getDataStep(); + DataItem loc = new DefaultDataItem("ld_locations", "ld_locations",""); + + data.add(dFrom); + data.add(dTo); + data.add(dStep); + data.add(new DefaultData( + "ld_locations", null, null, new DataItem[] { loc } )); + } + + Data dMode = getDataMode(); + if (dMode != null) { + data.add(dMode); + } + + return data.toArray(new Data[data.size()]); + } + + + /** + * Returns the Data object for the 'mode' attribute. + * + * @return the Data object for the 'mode' attribute. + */ + protected Data getDataMode() { + String value = mode.getValueAsString(FIELD_MODE); + DataItem item = new DefaultDataItem("ld_mode", "ld_mode", value); + return new DefaultData("ld_mode", null, null, new DataItem[] { item }); + } + + + protected Data getDataLocations() { + double[] locations = getLocationValues(); + boolean first = true; + + if (locations == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + + for (double l: locations) { + if (!first) { + sb.append(" "); + } + + sb.append(l); + + first = false; + } + + DataItem item = new DefaultDataItem( + "ld_locations", + "ld_locations", + sb.toString()); + + return new DefaultData( + "ld_locations", + null, + null, + new DataItem[] { item }); + } + + + /** + * Returns the Data object for the 'from' attribute. + * + * @return the Data object for the 'from' attribute. + */ + protected Data getDataFrom() { + String value = Double.valueOf(getFrom()).toString(); + DataItem item = new DefaultDataItem("ld_from", "ld_from", value); + return new DefaultData( + "ld_from", null, null, new DataItem[] { item }); + } + + + /** + * Returns the Data object for the 'to' attribute. + * + * @return the Data object for the 'to' attribute. + */ + protected Data getDataTo() { + String value = Double.valueOf(getTo()).toString(); + DataItem item = new DefaultDataItem("ld_to", "ld_to", value); + return new DefaultData( + "ld_to", null, null, new DataItem[] { item }); + } + + + /** + * Returns the Data object for the 'step' attribute. + * + * @return the Data object for the 'step' attribute. + */ + protected Data getDataStep() { + String value = Double.valueOf(getStep()).toString(); + DataItem item = new DefaultDataItem("ld_step","ld_step", value); + return new DefaultData( + "ld_step", null, null, new DataItem[] { item }); + } + + + /** + * Determines the current input mode. + * + * @return true, if 'location' is the current input mode, otherwise false. + */ + public boolean isLocationMode() { + String inputMode = mode.getValueAsString(FIELD_MODE); + + return inputMode.equals(FIELD_VALUE_LOCATION) ? true : false; + } + + + /** + * Activates the location panel. + */ + protected void enableLocationPanel() { + locationPanel = new DoubleArrayPanel( + MESSAGES.unitLocation(), + getLocationValues(), + this); + + container.removeMembers(container.getMembers()); + container.addMember(locationPanel); + } + + + /** + * Activates the distance panel. + */ + protected void enableDistancePanel() { + distancePanel = new DoubleRangePanel( + MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), + getFrom(), getTo(), getStep(), + 400, + this); + + container.removeMembers(container.getMembers()); + container.addMember(distancePanel); + } + + + /** + * This method switches the input mode between location and distance input. + * + * @param event The click event fired by a RadioButtonGroupItem. + */ + @Override + public void onChange(ChangeEvent event) { + String value = (String) event.getValue(); + + if (value == null) { + return; + } + if (value.equals(FIELD_VALUE_LOCATION)) { + enableLocationPanel(); + filterDescription.clear(); + filterRange.clear(); + filterResultCount.setValue(""); + + // Remove the tab containing the locationDistanceTable. + // The 'updateTab()' avoids the tab content to be destroyed. + inputTables.updateTab(0, null); + inputTables.removeTab(0); + + // Create a new tab containing the locationTable + Tab t1 = new Tab (MESSAGES.locations()); + t1.setPane(locationsTable); + inputTables.addTab(t1, 0); + + // Bring this tab to front. + inputTables.selectTab(0); + } + else { + enableDistancePanel(); + filterDescription.clear(); + filterRange.clear(); + filterResultCount.setValue(""); + + // Remove the tab containing the locationTable. + // The 'updateTab()' avoids the tab content to be destroyed. + inputTables.updateTab(0, null); + inputTables.removeTab(0); + + // Create a new tab containing the locationDistanceTable. + Tab t1 = new Tab(MESSAGES.locations()); + t1.setPane(locationDistanceTable); + inputTables.addTab(t1, 0); + + // Bring the distanceTable tab to front. + inputTables.selectTab(1); + } + } + + + /** + * This method is used to validate the inserted data in the form fields. + * + * @param event The BlurEvent that gives information about the FormItem that + * has been modified and its value. + */ + @Override + public void onBlur(BlurEvent event) { + FormItem item = event.getItem(); + String field = item.getFieldName(); + + if (field == null) { + return; + } + + if (field.equals(DoubleArrayPanel.FIELD_NAME)) { + DoubleArrayPanel p = (DoubleArrayPanel) event.getForm(); + + saveLocationValue(p, item); + } + else { + DoubleRangePanel p = (DoubleRangePanel) event.getForm(); + + saveDistanceValue(p, item); + } + } + + + + /** + * Validates and stores all values entered in the location mode. + * + * @param p The DoubleArrayPanel. + */ + protected void saveLocationValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveLocationValue(p, item); + } + } + } + + + /** + * Validates and stores all values entered in the distance mode. + * + * @param p The DoubleRangePanel. + */ + protected void saveDistanceValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveDistanceValue(p, item); + } + } + + + /** + * Validates and stores a value entered in the location mode. + * + * @param p The DoubleArrayPanel. + * @param item The item that needs to be validated. + */ + protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setLocationValues(p.getInputValues(item)); + } + } + + + /** + * Validates and stores value entered in the distance mode. + * + * @param p The DoubleRangePanel. + * @param item The item that needs to be validated. + */ + protected void saveDistanceValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm(item)) { + setFrom(p.getFrom()); + setTo(p.getTo()); + setStep(p.getStep()); + } + } + + + /** + * This method creates the panel that contains the checkboxes to switch + * between the input mode 'location' and 'distance'. + * + * @return the checkbox panel. + */ + protected Canvas createRadioButtonPanel() { + mode = new DynamicForm(); + + RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); + radio.setShowTitle(false); + radio.setVertical(false); + radio.setWrap(false); + + LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); + values.put(FIELD_VALUE_LOCATION, MESSAGES.location()); + values.put(FIELD_VALUE_DISTANCE, MESSAGES.distance()); + + LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); + initial.put(FIELD_MODE, FIELD_VALUE_DISTANCE); + + radio.setValueMap(values); + radio.addChangeHandler(this); + + mode.setFields(radio); + mode.setValues(initial); + + return mode; + } + + + protected void createDistanceInputPanel() { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String river = ""; + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + if (dl.getState().endsWith("river")) { + for (int j = 0; j < dl.size(); j++) { + Data d = dl.get(j); + DataItem[] di = d.getItems(); + if (di != null && di.length == 1) { + river = d.getItems()[0].getStringValue(); + } + } + } + } + } + + distanceTable.setDataSource(new DistanceInfoDataSource( + url, river, "distances")); + locationsTable.setDataSource(new DistanceInfoDataSource( + url, river, "locations")); + locationDistanceTable.setDataSource(new DistanceInfoDataSource( + url, river, "locations")); + } + + + protected double getFrom() { + return from; + } + + + protected void setFrom(double from) { + this.from = from; + } + + + protected double getTo() { + return to; + } + + + protected void setTo(double to) { + this.to = to; + } + + + protected double getStep() { + return step; + } + + + protected void setStep(double step) { + this.step = step; + } + + + protected double[] getLocationValues() { + return values; + } + + + protected void setLocationValues(double[] values) { + this.values = values; + locationPanel.setValues(values); + } + + + protected void setLocationValues(String values) { + String[] vs = values.split(" "); + + if (vs == null) { + return; + } + + double[] ds = new double[vs.length]; + int idx = 0; + + for (String s: vs) { + try { + ds[idx++] = Double.valueOf(s); + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + setLocationValues(ds); + } + + + protected void setDistanceValues (double from, double to) { + setFrom(from); + setTo(to); + distancePanel.setValues(from, to, getStep()); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/LocationPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,328 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; + +import java.util.ArrayList; +import java.util.List; + +/** + * This UIProvider serves as base for UI Providers to enter a single location (km). + */ +public abstract class LocationPanel +extends AbstractUIProvider +{ + private static final long serialVersionUID = -5306604428440015046L; + + /** A container that will contain the location or the distance panel. */ + protected HLayout inputLayout; + + /** The minimal value that the user is allowed to enter. */ + protected double min; + + /** The maximal value that the user is allowed to enter. */ + protected double max; + + /** The values entered in the location mode. */ + protected double[] values; + + /** Name of the data item that keeps this location(s). */ + protected String dataItemName; + + /** The input panel for locations. */ + protected DoubleArrayPanel locationPanel; + + + /** + * Creates a new LocationDistancePanel instance. + */ + public LocationPanel() { + values = new double[0]; + } + + + /** + * This method creates a widget that contains a label, a panel with + * checkboxes to switch the input mode between location and distance input, + * and a mode specific panel. + * + * @param data The data that might be inserted. + * + * @return a panel. + */ + @Override + public Canvas create(DataList data) { + findDataItemName(data); + + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + + // Subclass uses translated data items name as label. + Label label = new Label(MSG.location()); + Canvas widget = createWidget(data); + Canvas submit = getNextButton(); + + initDefaults(data); + + widget.setHeight(50); + label.setHeight(25); + + layout.addMember(label); + layout.addMember(widget); + layout.addMember(submit); + + return layout; + } + + + /** Store label of first data item in list. */ + public void findDataItemName(DataList list) { + this.dataItemName = list.getAll().get(0).getLabel(); + } + + + /** Get label of first data item that this uiprovider has seen. */ + public String getDataItemName() { + return this.dataItemName; + } + + + /** + * This method creates a Canvas element showing the old Data objects in the + * DataList <i>data</i>. + */ + @Override + public Canvas createOld(DataList dataList) { + findDataItemName(dataList); + + List<Data> items = dataList.getAll(); + Data dLocation = getData(items, getDataItemName()); + DataItem[] loc = dLocation.getItems(); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + // TODO evaluate: isn't this what findDataItemName is doing? + Label selected = new Label(loc[0].getLabel()); + selected.setWidth("130px"); + + layout.addMember(label); + layout.addMember(selected); + layout.addMember(back); + + return layout; + } + + + /** + * This method reads the default values defined in the DataItems of the Data + * objects in <i>list</i>. + * + * @param list The DataList container that stores the Data objects. + */ + protected void initDefaults(DataList list) { + Data data = list.get(0); + + DataItem[] items = data.getItems(); + DataItem iMin = getDataItem(items, "min"); + DataItem iMax = getDataItem(items, "max"); + + try { + min = Double.parseDouble(iMin.getStringValue()); + max = Double.parseDouble(iMax.getStringValue()); + } + catch (NumberFormatException nfe) { + SC.warn(MSG.error_read_minmax_values()); + min = -Double.MAX_VALUE; + max = Double.MAX_VALUE; + } + + DataItem def = data.getDefault(); + String value = def.getStringValue(); + + try { + double d = Double.parseDouble(value); + setLocationValues(new double[] { d } ); + } + catch (NumberFormatException nfe) { + // could not parse, don't know what else to do + GWT.log("LocationPanel", nfe); + } + } + + + /** + * This method grabs the Data with name <i>name</i> from the list and + * returns it. + * + * @param items A list of Data. + * @param name The name of the Data that we are searching for. + * + * @return the Data with the name <i>name</i>. + */ + @Override + protected Data getData(List<Data> data, String name) { + for (Data d: data) { + if (name.equals(d.getLabel())) { + return d; + } + } + + return null; + } + + + protected Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + inputLayout = new HLayout(); + + // The initial view will display the location input mode. + locationPanel = new DoubleArrayPanel( + MSG.unitLocation(), + getLocationValues(), + new BlurHandler(){@Override + public void onBlur(BlurEvent be) {}}); + + // TODO Remove picker references, refactor such that subclasses can + // easily use their picker if they want. + //picker.getLocationTable().setAutoFetchData(true); + + inputLayout.addMember(locationPanel); + + layout.addMember(inputLayout); + + inputLayout.setMembersMargin(30); + + /* + //picker.prepareFilter(); + helperContainer.addMember(picker.getLocationTable()); + helperContainer.addMember(picker.getFilterLayout()); + helperContainer.addMember(picker.getResultCountForm()); + */ + return layout; + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + saveLocationValues(locationPanel); + + if (!locationPanel.validateForm()) { + errors.add(MSG.wrongFormat()); + return errors; + } + + double[] values = getLocationValues(); + double[] good = new double[values.length]; + int idx = 0; + + for (double value: values) { + if (value < min || value > max) { + String tmp = MSG.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(min)); + tmp = tmp.replace("$3", nf.format(max)); + errors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!errors.isEmpty()) { + locationPanel.setValues(justGood); + } + + return errors; + } + + + /** + * Validates and stores all values entered in the location mode. + * + * @param p The DoubleArrayPanel. + */ + protected void saveLocationValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveLocationValue(p, item); + } + } + } + + + /** + * Validates and stores a value entered in the location mode. + * + * @param p The DoubleArrayPanel. + * @param item The item that needs to be validated. + */ + protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setLocationValues(p.getInputValues(item)); + } + } + + + /** Get the location values. */ + protected double[] getLocationValues() { + return values; + } + + + /** Sets Location values and updates the panel. */ + protected void setLocationValues(double[] values) { + this.values = values; + locationPanel.setValues(values); + } + + + /** + * Callback when an item from the input helper was clicked. + * Set the respective km-value in the location value field. + * @param e event passed. + */ + public void onRecordClick (RecordClickEvent e) { + Record record = e.getRecord(); + double[] selected = new double[1]; + try { + selected[0] = + Double.parseDouble(record.getAttribute("from")); + } + catch(NumberFormatException nfe) { + GWT.log("onRecordClick", nfe); + } + setLocationValues(selected); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/LocationPicker.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,267 @@ +package de.intevation.flys.client.client.ui; + +import java.util.LinkedHashMap; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.smartgwt.client.data.AdvancedCriteria; +import com.smartgwt.client.data.Criteria; +import com.smartgwt.client.data.Criterion; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.OperatorId; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.FilterHandler; +import de.intevation.flys.client.client.event.RangeFilterEvent; +import de.intevation.flys.client.client.event.StringFilterEvent; + +/** + * Bundle widgets and handler for a lacation input helper. + * + * Note that the construction is weird and driven by issues that arose due to + * reasons not understood. + */ +public class LocationPicker +implements FilterHandler +{ + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** The locations table. */ + protected ListGrid locationTable; + + protected HLayout filterLayout; + + DynamicForm resultCountForm; + + CellClickHandler handler; + + boolean isDistance = false; + + /** Text to show number of matched items when filtered. */ + protected StaticTextItem filterResultCount; + + + public LocationPicker(CellClickHandler handler) { + locationTable = new ListGrid(); + locationTable.setShowHeaderContextMenu(false); + this.handler = handler; + } + + public void prepareFilter() { + + filterResultCount = new StaticTextItem(MSG.resultCount()); + filterResultCount.setTitleAlign(Alignment.LEFT); + filterResultCount.setTitleStyle("color: #000"); + + final TableFilter filter = new TableFilter(); + filter.setHeight("30px"); + filter.addFilterHandler(this); + + final RangeTableFilter filterRange = new RangeTableFilter(); + filterRange.setHeight("30px"); + filterRange.addFilterHandler(this); + filterRange.setVisible(false); + + SelectItem filterCriteria = new SelectItem(); + filterCriteria.setShowTitle(false); + filterCriteria.setWidth(100); + filterCriteria.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent e) { + if(e.getValue().toString().equals("range")) { + filterRange.setVisible(true); + filter.setVisible(false); + filter.clear(); + filterResultCount.setValue(""); + } + else { + filterRange.setVisible(false); + filterRange.clear(); + filter.setVisible(true); + filterResultCount.setValue(""); + } + } + }); + + LinkedHashMap<String, String> filterMap = + new LinkedHashMap<String, String>(); + filterMap.put("description", MSG.description()); + filterMap.put("range", MSG.range()); + filterCriteria.setValueMap(filterMap); + filterCriteria.setValue("description"); + + DynamicForm form = new DynamicForm(); + form.setFields(filterCriteria); + + resultCountForm = new DynamicForm(); + resultCountForm.setFields(filterResultCount); + + filterLayout = new HLayout(); + filterLayout.addMember(form); + filterLayout.addMember(filter); + filterLayout.addMember(filterRange); + } + + + /** Access the main widget, a table in which locations can be chosen. */ + public ListGrid getLocationTable() { + return locationTable; + } + + + /** Access the 'form' that shows the filter result count. */ + public DynamicForm getResultCountForm() { + return resultCountForm; + } + + + /** Access the layout containing filter stuff. */ + public HLayout getFilterLayout() { + return filterLayout; + } + + + /** + * This method creates a table that contains the location values. + */ + public void createLocationTable(/*RecordClickHandler handler*/) { + GWT.log("Create Location Table in LocationPicker"); + + String baseUrl = GWT.getHostPageBaseURL(); + + locationTable.setWidth100(); + locationTable.setShowRecordComponents(true); + locationTable.setShowRecordComponentsByCell(true); + locationTable.setHeight100(); + locationTable.setEmptyMessage(MSG.empty_filter()); + locationTable.setCanReorderFields(false); + + ListGridField addLocation = new ListGridField ("", ""); + addLocation.setType (ListGridFieldType.ICON); + addLocation.setWidth (20); + addLocation.setCellIcon (baseUrl + MSG.markerGreen()); + ListGridField addTo = new ListGridField ("", ""); + addTo.setType (ListGridFieldType.ICON); + addTo.setWidth (20); + addTo.setCellIcon (baseUrl + MSG.markerRed()); + + ListGridField ldescr = new ListGridField("description", + MSG.description()); + ldescr.setType(ListGridFieldType.TEXT); + ldescr.setWidth("*"); + ListGridField lside = new ListGridField("riverside", + MSG.riverside()); + lside.setType(ListGridFieldType.TEXT); + lside.setWidth("10%"); + + ListGridField loc = new ListGridField("from", MSG.location()); + loc.setCellFormatter(new CellFormatter() { + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum) { + if (value == null) return null; + try { + NumberFormat nf; + double v = Double.parseDouble((String)value); + nf = NumberFormat.getFormat("###0.00##"); + return nf.format(v); + } + catch (Exception e) { + return value.toString(); + } + } + } + ); + loc.setType(ListGridFieldType.FLOAT); + + loc.setWidth("10%"); + + ListGridField bottom = + new ListGridField("bottom", MSG.bottom_edge()); + bottom.setType(ListGridFieldType.TEXT); + bottom.setWidth("10%"); + + ListGridField top = + new ListGridField("top", MSG.top_edge()); + top.setType(ListGridFieldType.TEXT); + top.setWidth("10%"); + locationTable.addCellClickHandler(handler); + if (isDistance) { + locationTable.setFields( + addLocation, addTo, ldescr, loc, lside, bottom, top); + } + else { + locationTable.setFields( + addLocation, ldescr, loc, lside, bottom, top); + } + } + + + @Override + public void onFilterCriteriaChanged(StringFilterEvent event) { + String search = event.getFilter(); + + if (search != null && search.length() > 0) { + Criteria c = new Criteria("description", search); + locationTable.filterData(c); + filterResultCount.setValue(locationTable.getRecords().length); + } + else { + locationTable.clearCriteria(); + filterResultCount.setValue(""); + } + } + + + @Override + public void onFilterCriteriaChanged(RangeFilterEvent event) { + Float from = event.getFrom() - 0.001f; + Float to = event.getTo() + 0.001f; + + Criterion combinedFilter = null; + if (from.equals(Float.NaN) && to.equals(Float.NaN)) { + locationTable.clearCriteria(); + filterResultCount.setValue(""); + return; + } + else if (from.equals(Float.NaN)) { + combinedFilter = + new Criterion("from", OperatorId.LESS_OR_EQUAL, to); + } + else if (to.equals(Float.NaN)) { + combinedFilter = + new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); + } + else { + combinedFilter = + new AdvancedCriteria(OperatorId.AND, new Criterion[] { + new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), + new Criterion("from", OperatorId.LESS_OR_EQUAL, to) + }); + } + locationTable.filterData(combinedFilter); + filterResultCount.setValue(locationTable.getRecords().length); + } + + public void setIsDistance(boolean value) { + this.isDistance = value; + } + + public boolean isDistance() { + return this.isDistance; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/MapSelection.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,72 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; + + +/** + * This UIProvider displays the DataItems contained in the Data object in a + * combo box as SelectProvider does. Furthermore, there is a map displayed that + * lets the user choose a river by selecting it on the map. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MapSelection extends SelectProvider { + + private static final long serialVersionUID = 1261822454641198692L; + + protected ModuleSelection moduleSelection; + + public MapSelection() { + } + + + /** + * This method currently returns a + * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all + * data items in a combobox stored in <i>data</i>.<br> + * + * <b>TODO: The map panel for the river selection needs to be + * implemented!</b> + * + * @param data The {@link DataList} object. + * + * @return a combobox. + */ + @Override + protected Canvas createWidget(DataList data) { + GWT.log("MapSelection - create()"); + + HLayout h = new HLayout(); + h.setAlign(VerticalAlignment.TOP); + h.setHeight(100); + moduleSelection = new ModuleSelection(); + + Canvas form = moduleSelection.create(data); + form.setWidth(400); + form.setLayoutAlign(VerticalAlignment.TOP); + + // TODO implement event handling in the river map (here? or in LinkSelection) + + h.addMember(form); + + return h; + } + + @Override + protected Data[] getData() { + if (moduleSelection != null) { + return moduleSelection.getData(); + } + else { + return null; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,176 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.RadioGroupItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.ModuleService; +import de.intevation.flys.client.client.services.ModuleServiceAsync; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.Module; + +import java.util.LinkedHashMap; + +/** + * The ModuleSelection combines the river selection and the module selection in + * one widget. It will display a vertical splitted widget - the upper part will + * render checkboxes for each module, the lower one will display a combobox at + * the left and a map panel on the right to choose the river. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ModuleSelection extends MapSelection { + + private static final long serialVersionUID = -5634831815175543328L; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + /** The module checkboxes.*/ + protected RadioGroupItem radio; + + /** */ + protected Module[] modules; + + /** The ModuleService used to retrieve the available modules of a user.*/ + protected ModuleServiceAsync moduleService = GWT.create(ModuleService.class); + + + /** + * The default constructor. + */ + public ModuleSelection() { + readModules(); + } + + + /** + * This method returns a widget that renders the checkboxes for each module + * and the MapSelection that lets the user choose the river. + * + * @param data The provided rivers. + * + * @return the module selection combined with the river selection. + */ + @Override + public Canvas create(DataList data) { + GWT.log("ModuleSelection - create()"); + VLayout newLayout = new VLayout(); + newLayout.setMembersMargin(10); + newLayout.setAlign(VerticalAlignment.TOP); + Canvas moduleSelection = createWidget(); + + moduleSelection.setHeight(100); + newLayout.setHeight(70); + newLayout.addMember(moduleSelection); + + return newLayout; + } + + private void readModules() { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + moduleService.list(locale, new AsyncCallback<Module[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve a list of modules."); + SC.warn(MSG.getString(caught.getMessage())); + } + + @Override + public void onSuccess(Module[] newmodules) { + GWT.log("Retrieved " + newmodules.length + " modules."); + modules = newmodules; + setModules(); + } + }); + } + + private void setModules() { + LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); + + if (this.modules!= null) { + for(Module module : this.modules) { + values.put(module.getName(), module.getLocalizedName()); + if (module.isSelected()) { + GWT.log("Module " + module.getName() + " is selected."); + if (radio != null) { + radio.setDefaultValue(module.getName()); + GWT.log("Setting " + module.getName() + " as selected."); + } + } + } + } + if (radio != null) { + radio.setValueMap(values); + } + } + + /** + * Creates a widget that displays a checkbox for each module. + * + * @return a widget with checkboxes. + */ + protected Canvas createWidget() { + HLayout layout = new HLayout(); + + Label label = new Label(MESSAGES.module_selection()); + DynamicForm form = new DynamicForm(); + + radio = new RadioGroupItem("plugin"); + + label.setWidth(50); + label.setHeight(25); + + + radio.setShowTitle(false); + radio.setVertical(true); + + setModules(); + + form.setFields(radio); + + layout.addMember(label); + layout.addMember(form); + + return layout; + } + + + /** + * This method prepares the data of two widgets - the module selection and + * the river selection. The returning field will contain the Data that + * represents the module selection at first position, the second position + * stores the Data object that represents the river selection. + * + * @return the Data that was chosen in this widget. + */ + @Override + protected Data[] getData() { + + String module = radio.getValueAsString(); + + DataItem[] items = new DefaultDataItem[1]; + items[0] = new DefaultDataItem(module, module, module); + + Data data = new DefaultData("module", null, null, items); + + return new Data[] {data}; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/MultiPeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,242 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class MultiPeriodPanel +extends PeriodPanel +{ + + private static final long serialVersionUID = 1811025931934462457L; + + protected ListGrid elements; + + protected String values; + + public MultiPeriodPanel() { + this("", ""); + } + + public MultiPeriodPanel(String startName, String endName) { + super(startName, endName); + } + + @Override + public Canvas createWidget(DataList data) { + HLayout input = new HLayout(); + VLayout root = new VLayout(); + VLayout grid = new VLayout(); + VLayout layout = (VLayout) super.createWidget(data); + Button add = new Button(MSG.add_date()); + elements = new ListGrid(); + + add.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent ce) { + Date f = inputPanel.getFromDate(); + Date t = inputPanel.getToDate(); + if (f == null || t == null) { + return; + } + DateRangeRecord drr = new DateRangeRecord(f, t); + elements.addData(drr); + } + }); + layout.addMember(add); + + Label sel = new Label(MSG.select()); + sel.setHeight(25); + elements.setWidth(185); + elements.setHeight(120); + elements.setShowHeaderContextMenu(false); + elements.setCanReorderFields(false); + elements.setCanSort(false); + elements.setCanEdit(false); + ListGridField from = new ListGridField("from", MSG.from()); + ListGridField to = new ListGridField("to", MSG.to()); + from.setWidth(70); + to.setWidth(70); + + final ListGridField removeField = + new ListGridField("_removeRecord", "Remove Record"){{ + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; + + elements.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + event.getViewer().removeData(event.getRecord()); + } + }); + + elements.setFields(from, to, removeField); + + grid.addMember(sel); + grid.addMember(elements); + input.addMember(layout); + input.addMember(grid); + root.addMember(input); + + return root; + } + + @SuppressWarnings("deprecation") + @Override + public Canvas createOld(DataList dataList) { + GWT.log("old............................"); + HLayout layout = new HLayout(); + layout.setWidth("400px"); + VLayout vLayout = new VLayout(); + vLayout.setWidth(130); + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + label.setHeight(25); + + List<Data> items = dataList.getAll(); + Data str = getData(items, "periods"); + DataItem[] strItems = str.getItems(); + + String[] pairs = strItems[0].getLabel().split(";"); + for (int i = 0; i < pairs.length; i++) { + String[] vals = pairs[i].split(","); + long f = Long.valueOf(vals[0]).longValue(); + long t = Long.valueOf(vals[1]).longValue(); + Date from = new Date(f); + Date to = new Date(t); + String fromString = + DateTimeFormat.getMediumDateFormat().format(from); + String toString = + DateTimeFormat.getMediumDateFormat().format(to); + + Label dateLabel = new Label(fromString + " - " + toString); + dateLabel.setHeight(20); + vLayout.addMember(dateLabel); + } + Canvas back = getBackButton(dataList.getState()); + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveDateValues(); + if(valid) { + DataItem item = new DefaultDataItem("periods", null, this.values); + data.add(new DefaultData( + "periods", + null, + null, + new DataItem[] { item })); + } + return data.toArray(new Data[data.size()]); + } + + + @Override + protected boolean saveDateValues() { + ListGridRecord[] lgr = elements.getRecords(); + if (lgr.length == 0) { + return false; + } + String data = ""; + for (int i = 0; i < lgr.length; i++) { + DateRangeRecord drr = (DateRangeRecord) lgr[i]; + data += drr.getFrom() + "," + drr.getTo(); + data += ";"; + } + values = data; + return true; + } + + + protected static class DateRangeRecord extends ListGridRecord { + protected Date from; + protected Date to; + + protected final static String FROM_FIELD = "from"; + protected final static String TO_FIELD = "to"; + + public DateRangeRecord (Date from, Date to) { + setFrom(from); + setTo(to); + } + + @SuppressWarnings("deprecation") + public void setFrom(Date from) { + this.from = from; + setAttribute( + FROM_FIELD, + DateTimeFormat.getMediumDateFormat().format(from)); + } + + + @SuppressWarnings("deprecation") + public void setTo(Date to) { + this.to = to; + setAttribute( + TO_FIELD, + DateTimeFormat.getMediumDateFormat().format(to)); + } + + + public long getFrom() { + return this.from.getTime(); + } + + + public long getTo() { + return this.to.getTime(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/MultipleLocationPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,354 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.services.DistanceInfoService; +import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; +import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; +import de.intevation.flys.client.shared.DoubleUtils; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DistanceInfoObject; +import de.intevation.flys.client.shared.model.RangeData; + +import java.util.ArrayList; +import java.util.List; + + +/** + * This UIProvider creates a widget to enter a single location (km). + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class MultipleLocationPanel +extends LocationPanel +implements CellClickHandler +{ + private static final long serialVersionUID = -3359966826794082718L; + + /** The DistanceInfoService used to retrieve locations about rivers. */ + protected DistanceInfoServiceAsync distanceInfoService = + GWT.create(DistanceInfoService.class); + + /** The table data. */ + protected DistanceInfoObject[] tableData; + + /** The input helper (usually right side, table to click on, values are + * then entered in the texfield. */ + protected LocationPicker picker; + + + /** + * Creates a new LocationDistancePanel instance. + */ + public MultipleLocationPanel() { + picker = new LocationPicker(this); + } + + + /** + * This method creates a widget that contains a label, a panel with + * checkboxes to switch the input mode between location and distance input, + * and a mode specific panel. + * + * @param data The data that might be inserted. + * + * @return a panel. + */ + @Override + public Canvas create(DataList data) { + findDataItemName(data); + + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + + // Take translated data item name as label, if translation available. + String labelString; + try { + labelString = MSG.getString(getDataItemName()); + } + catch(java.util.MissingResourceException mre) { + GWT.log("Cannot find translation for data item name : " + getDataItemName()); + labelString = getLabelString(); + } + Label label = new Label(labelString); + Canvas widget = createWidget(data); + Canvas submit = getNextButton(); + + initDefaults(data); + + picker.createLocationTable(); + + widget.setHeight(50); + label.setHeight(25); + + layout.addMember(label); + layout.addMember(widget); + layout.addMember(submit); + + return layout; + } + + + /** + * This method reads the default values defined in the DataItems of the Data + * objects in <i>list</i>. + * + * @param list The DataList container that stores the Data objects. + */ + @Override + protected void initDefaults(DataList list) { + Data data = list.get(0); + + // Compatibility with MinMax- DataItems: + RangeData rangeData = null; + + for (int i = 0, n = list.size(); i < n; i++) { + Data tmp = list.get(i); + + if (tmp instanceof RangeData) { + rangeData = (RangeData) tmp; + } + } + + if (rangeData != null) { + min = Double.parseDouble(rangeData.getDefaultLower().toString()); + max = Double.parseDouble(rangeData.getDefaultUpper().toString()); + // catch ..? + } + else { + DataItem[] items = data.getItems(); + DataItem iMin = getDataItem(items, "min"); + DataItem iMax = getDataItem(items, "max"); + + try { + min = Double.parseDouble(iMin.getStringValue()); + max = Double.parseDouble(iMax.getStringValue()); + } + catch (NumberFormatException nfe) { + SC.warn(MSG.error_read_minmax_values()); + min = -Double.MAX_VALUE; + max = Double.MAX_VALUE; + } + } + + DataItem def = data.getDefault(); + if (def != null) { + String value = def.getStringValue(); + + try { + double d = Double.parseDouble(value); + setLocationValues(new double[] { d } ); + } + catch (NumberFormatException nfe) { + // could not parse, dont know what to do else + } + } + } + + + @Override + protected Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + inputLayout = new HLayout(); + + // The initial view will display the location input mode. + locationPanel = new DoubleArrayPanel( + MSG.unitLocation(), + getLocationValues(), + new BlurHandler(){@Override + public void onBlur(BlurEvent be) {validate();}}); + + picker.getLocationTable().setAutoFetchData(true); + + inputLayout.addMember(locationPanel); + + layout.addMember(inputLayout); + + inputLayout.setMembersMargin(30); + + picker.prepareFilter(); + + helperContainer.addMember(picker.getLocationTable()); + helperContainer.addMember(picker.getFilterLayout()); + helperContainer.addMember(picker.getResultCountForm()); + setPickerDataSource(); + return layout; + } + + + /** Overridden to restrict to one entered value. */ + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + DataList[] ref = artifact.getArtifactDescription().getOldData(); + String mode = ref[1].get(0).getStringValue(); + + saveLocationValues(locationPanel); + + if (!locationPanel.validateForm()) { + errors.add(MSG.wrongFormat()); + return errors; + } + + double[] lValues = getLocationValues(); + double[] good = new double[lValues.length]; + int idx = 0; + + double reference = + Double.valueOf(ref[2].get(0).getStringValue()).doubleValue(); + for (double value: lValues) { + if (mode.equals("calc.reference.curve") && + value == reference) { + errors.add(MSG.error_contains_same_location()); + return errors; + } + if (value < min || value > max) { + String tmp = MSG.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(min)); + tmp = tmp.replace("$3", nf.format(max)); + errors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!errors.isEmpty()) { + locationPanel.setValues(justGood); + } + + return errors; + } + + + /** + * This method returns the selected data (to feed). + * + * @return the selected/inserted data in feedable form. + */ + @Override + public Data[] getData() { + saveLocationValues(locationPanel); + double[] lValues = getLocationValues(); + Data[] data = new Data[2]; + boolean first = true; + String valueString = ""; + + for (int i = 0; i < lValues.length; i++) { + if (!first) valueString += " "; + else first = false; + valueString += Double.valueOf(lValues[i]).toString(); + } + + data[0] = createDataArray(getDataItemName(), valueString); + + data[1] = createDataArray("ld_mode", "locations"); + + return data; + } + + + /** Hook service to the listgrid with possible input values. */ + protected void setPickerDataSource() { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String river = ""; + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + // Try to find a "river" data item to set the source for the + // list grid. + String dataFilter = "locations"; + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + if (dl.getState().equals("state.minfo.river")) { + dataFilter = "measuringpoint"; + } + if (dl.getState().equals("state.winfo.river") || + dl.getState().equals("state.chart.river") || + dl.getState().equals("state.minfo.river")) { + for (int j = 0; j < dl.size(); j++) { + Data d = dl.get(j); + DataItem[] di = d.getItems(); + if (di != null && di.length == 1) { + river = d.getItems()[0].getStringValue(); + break; + } + } + } + } + } + + picker.getLocationTable().setDataSource(new DistanceInfoDataSource( + url, river, dataFilter)); + } + + + // TODO allow multiple selections here or in LocationPanel + /** + * Callback when an item from the input helper was clicked. + * Set the respective km-value in the location value field. + * @param e event passed. + */ + @Override + public void onCellClick (CellClickEvent e) { + Record record = e.getRecord(); + double[] old = getLocationValues(); + double[] selected = DoubleUtils.copyOf(old, old.length + 1); + try { + selected[old.length] = + Double.parseDouble(record.getAttribute("from")); + } + catch(NumberFormatException nfe) { + // Is there anything else to do here? + GWT.log(nfe.getMessage()); + } + + // compare reference location and target location. + DataList[] ref = artifact.getArtifactDescription().getOldData(); + String mode = ref[1].get(0).getStringValue(); + if (mode.equals("calc.reference.curve") && + ref[2].get(0).getStringValue().equals(record.getAttribute("from"))) + { + SC.warn(MSG.error_same_location()); + return; + } + + setLocationValues(selected); + } + + + /** + * Returns the label string for the input panel. + */ + protected String getLabelString() { + return MSG.location(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/NoInputPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,32 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.Canvas; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; + + +public class NoInputPanel +extends AbstractUIProvider +{ + private static final long serialVersionUID = -8789143404415288132L; + + + @Override + public Canvas create(DataList data) { + return new Canvas(); + } + + + @Override + public Canvas createOld(DataList dataList) { + return new Canvas(); + } + + + @Override + protected Data[] getData() { + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/OutputTab.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,71 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.tab.Tab; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.OutputMode; + + +public class OutputTab extends Tab { + + /** The OutputMode that should be displayed in this tab.*/ + protected OutputMode mode; + + /** The Collection that should be displayed in this tab.*/ + protected Collection collection; + + /** The CollectionView containing this tab. */ + protected CollectionView collectionView; + + + /** + * The default constructor that creates a new Tab for displaying a specific + * OutputMode of a Collection. + * + * @param title The title of the tab. + * @param collection The collection that need to be displayed. + * @param outputmode The OutputMode that need to be displayed. + */ + public OutputTab( + String title, + Collection collection, + CollectionView collectionView, + OutputMode mode + ) { + super(title); + + this.collection = collection; + this.mode = mode; + this.collectionView = collectionView; + + setPane(new Label("Implement concrete subclasses to vary the output.")); + } + + + public CollectionView getCollectionView() { + return collectionView; + } + + + public String getOutputName() { + return mode.getName(); + } + + + public Artifact getArtifact() { + return getCollectionView().getArtifact(); + } + + + public Collection getCollection() { + return collection; + } + + + public OutputMode getMode() { + return mode; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ParameterList.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,1023 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.types.VisibilityMode; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.SectionStack; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.AdvanceHandler; +import de.intevation.flys.client.client.event.CollectionChangeEvent; +import de.intevation.flys.client.client.event.CollectionChangeHandler; +import de.intevation.flys.client.client.event.HasParameterChangeHandler; +import de.intevation.flys.client.client.event.HasStepBackHandlers; +import de.intevation.flys.client.client.event.HasStepForwardHandlers; +import de.intevation.flys.client.client.event.OutputModesChangeEvent; +import de.intevation.flys.client.client.event.OutputModesChangeHandler; +import de.intevation.flys.client.client.event.ParameterChangeEvent; +import de.intevation.flys.client.client.event.ParameterChangeHandler; +import de.intevation.flys.client.client.event.StepBackEvent; +import de.intevation.flys.client.client.event.StepBackHandler; +import de.intevation.flys.client.client.event.StepForwardEvent; +import de.intevation.flys.client.client.event.StepForwardHandler; +import de.intevation.flys.client.client.services.AdvanceService; +import de.intevation.flys.client.client.services.AdvanceServiceAsync; +import de.intevation.flys.client.client.services.ArtifactService; +import de.intevation.flys.client.client.services.ArtifactServiceAsync; +import de.intevation.flys.client.client.services.ReportService; +import de.intevation.flys.client.client.services.ReportServiceAsync; +import de.intevation.flys.client.client.services.StepForwardService; +import de.intevation.flys.client.client.services.StepForwardServiceAsync; +import de.intevation.flys.client.client.ui.stationinfo.GaugePanel; +import de.intevation.flys.client.client.ui.stationinfo.InfoPanel; +import de.intevation.flys.client.client.ui.stationinfo.MeasurementStationPanel; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.ExportMode; +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; +import de.intevation.flys.client.shared.model.MINFOArtifact; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.ReportMode; +import de.intevation.flys.client.shared.model.River; +import de.intevation.flys.client.shared.model.WINFOArtifact; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + + +public class ParameterList +extends Tab +implements StepBackHandler, StepForwardHandler, ParameterChangeHandler, + HasParameterChangeHandler, CollectionChangeHandler, + OutputModesChangeHandler, AdvanceHandler +{ + private static final long serialVersionUID = 5204784727239299980L; + + public static final String STYLENAME_OLD_PARAMETERS = "oldParameters"; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected ArtifactServiceAsync artifactService = + GWT.create(ArtifactService.class); + + /** The StepForwardService used to put data into an existing artifact. */ + protected StepForwardServiceAsync forwardService = + GWT.create(StepForwardService.class); + + /** The StepForwardService used to put data into an existing artifact. */ + protected AdvanceServiceAsync advanceService = + GWT.create(AdvanceService.class); + + + protected ReportServiceAsync reportService = + GWT.create(ReportService.class); + + + /** The list of ParameterizationChangeHandler.*/ + protected List<ParameterChangeHandler> parameterHandlers; + + protected FLYS flys; + + protected CollectionView cView; + + protected Artifact artifact; + + protected List<DataList> old; + protected Map<String, Canvas> oldStorage; + protected DataList current; + + protected UIProvider uiProvider; + + protected VLayout topLayout; + protected VLayout oldItems; + protected VLayout currentItems; + protected VLayout exportModes; + protected VLayout report; + protected VLayout helperPanel; + protected VLayout tablePanel; + protected InfoPanel infoPanel; + protected Canvas reportPanel; + + private SectionStack stack; + + public ParameterList(FLYS flys, CollectionView cView, String title) { + super(title); + + this.cView = cView; + this.flys = flys; + + parameterHandlers = new ArrayList<ParameterChangeHandler>(); + old = new ArrayList<DataList>(); + oldStorage = new TreeMap<String, Canvas>(); + topLayout = new VLayout(); + oldItems = new VLayout(); + currentItems = new VLayout(); + exportModes = new VLayout(); + report = new VLayout(); + + addParameterChangeHandler(this); + + init(); + } + + + public ParameterList( + FLYS flys, + CollectionView cView, + String title, + Artifact artifact) + { + super(title); + + this.cView = cView; + this.flys = flys; + this.artifact = artifact; + + parameterHandlers = new ArrayList<ParameterChangeHandler>(); + old = new ArrayList<DataList>(); + oldStorage = new TreeMap<String, Canvas>(); + topLayout = new VLayout(); + oldItems = new VLayout(); + currentItems = new VLayout(); + exportModes = new VLayout(); + report = new VLayout(); + + init(); + + addParameterChangeHandler(this); + + setArtifact(artifact, false); + } + + + protected void init() { + HLayout rootLayout = new HLayout(); + rootLayout.setMembersMargin(20); + + VLayout left = new VLayout(); + + if (old == null || old.size() == 0) { + oldItems.setHeight(1); + } + + oldItems.setMembersMargin(10); + oldItems.setStyleName(STYLENAME_OLD_PARAMETERS); + currentItems.setAlign(VerticalAlignment.TOP); + + left.setMembersMargin(20); + left.setWidth(300); + + left.addMember(oldItems); + left.addMember(currentItems); + left.addMember(exportModes); + left.addMember(report); + + reportPanel = new Canvas(); + reportPanel.setHeight("*"); + report.addMember(reportPanel); + + rootLayout.addMember(left); + rootLayout.addMember(createSectionStack()); + + topLayout.addMember(rootLayout); + if (artifact == null) { + Canvas moduleSelection = renderNew(); + moduleSelection.setLayoutAlign(VerticalAlignment.TOP); + currentItems.addMember(moduleSelection); + } + + setPane(topLayout); + } + + + protected SectionStack createSectionStack() { + stack = new SectionStack(); + stack.setHeight100(); + stack.setCanResizeSections(true); + stack.setVisibilityMode(VisibilityMode.MULTIPLE); + + // This canvas is used to render helper widgets. + final SectionStackSection helperSection = new SectionStackSection(); + helperSection.setExpanded(false); + helperSection.setTitle(MSG.helperPanelTitle()); + helperPanel = new VLayout() { + @Override + public void addMember(Canvas component) { + super.addMember(component); + stack.expandSection(helperSection.getID()); + } + + @Override + public void removeMembers(Canvas[] components) { + super.removeMembers(components); + helperSection.setExpanded(false); + } + }; + helperPanel.setWidth100(); + helperPanel.setHeight100(); + helperSection.setItems(helperPanel); + + // This canvas is used to render calculation results. + final SectionStackSection tableSection = new SectionStackSection(); + tableSection.setExpanded(false); + tableSection.setTitle(MSG.calcTableTitle()); + tablePanel = new VLayout() { + @Override + public void addMember(Canvas component) { + super.addMember(component); + tableSection.setExpanded(true); + } + + @Override + public void removeMembers(Canvas[] components) { + super.removeMembers(components); + tableSection.setExpanded(false); + } + }; + tablePanel.setHeight100(); + tablePanel.setWidth100(); + tableSection.setItems(tablePanel); + + stack.setSections(helperSection, tableSection); + + return stack; + } + + + /** Sets and forwards artifact. */ + protected void setArtifact(Artifact artifact) { + setArtifact(artifact, true); + } + + + protected void setArtifact(Artifact artifact, boolean forward) { + Artifact tmp = this.artifact; + this.artifact = artifact; + + if (forward) { + fireParameterChangeEvent( + tmp, this.artifact, ParameterChangeEvent.Type.FORWARD); + } + else { + fireParameterChangeEvent( + tmp, this.artifact, ParameterChangeEvent.Type.BACK); + } + } + + + /** + * This method registers a new ParameterChangeHandler. + * + * @param handler The new ParameterChangeHandler. + */ + @Override + public void addParameterChangeHandler(ParameterChangeHandler handler) { + if (handler != null) { + parameterHandlers.add(handler); + } + } + + + /** + * This method calls the <code>onParameterChange()</code> method of all + * registered ParameterChangeHandler. + */ + protected void fireParameterChangeEvent( + Artifact old, + Artifact newArt, + ParameterChangeEvent.Type type) + { + ParameterChangeEvent e = new ParameterChangeEvent(old, newArt, type); + + for (ParameterChangeHandler handler: parameterHandlers) { + handler.onParameterChange(e); + } + } + + + /** + * This method creates a Canvas displaying the plugins of FLYS combined with + * a widget to select a river. + * + * @return a Canvas that displays the supported plugins and rivers of FLYS. + */ + protected Canvas renderNew() { + River[] rivers = flys.getRivers(); + DataItem[] items = new DataItem[rivers.length]; + + int i = 0; + for (River river: rivers) { + String name = river.getName(); + items[i++] = new DefaultDataItem(name, null, name); + } + + Data data = new DefaultData( + "river", + MSG.river_selection(), + null, + items); + + LinkSelection widget = new LinkSelection(); + HasStepForwardHandlers handler = widget; + + widget.setContainer(helperPanel); + + handler.addStepForwardHandler(new StepForwardHandler() { + private static final long serialVersionUID = -6210719844707004860L; + + @Override + public void onStepForward(StepForwardEvent event) { + lockUI(); + Data[] data = event.getData(); + + DataItem[] moduleItems = data[0].getItems(); + DataItem[] riversItems = data[1].getItems(); + + String module = moduleItems[0].getStringValue(); + String river = riversItems[0].getStringValue(); + + if (module == null || river == null) { + GWT.log("ParameterList.renderNew(): module == null || river == null"); + unlockUI(); + return; + } + + String newTitle = MSG.getString(module); + setTitle(newTitle); + + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + final Data[] feedData = new Data[] { data[1] }; + + artifactService.create( + locale, module.toLowerCase(), null, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + unlockUI(); + GWT.log("Could not create the new artifact."); + SC.warn(FLYS.getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created a new artifact."); + + forwardService.go(locale, artifact, feedData, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + unlockUI(); + GWT.log("Could not feed the artifact."); + SC.warn(caught.getMessage()); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully feed the artifact."); + old.clear(); + cView.addArtifactToCollection(artifact); + setArtifact(artifact); + unlockUI(); + } + }); + } + }); + } + }); + + DataList list = new DataList(); + list.add(data); + + return widget.create(list); + } + + + protected void clearOldData() { + old.clear(); + } + + + public void addOldData(DataList old) { + addOldData(old, true); + } + + + public void addOldData(DataList old, boolean redraw) { + if (old != null) { + this.old.add(old); + } + + refreshOld(redraw); + } + + + public void addOldDatas(DataList[] old) { + addOldDatas(old, true); + } + + + public void addOldDatas(DataList[] old, boolean redraw) { + if (old != null && old.length > 0) { + for (DataList o: old) { + if (o == null) { + continue; + } + + if (!exists(o)) { + GWT.log("Data '" + o.getLabel() + "' is new."); + addOldData(o, false); + } + } + + if (redraw) { + addOldData(null, true); + } + + return; + } + + addOldData(null, true); + } + + + public boolean exists(DataList data) { + if (data == null) { + return false; + } + + String stateName = data.getState(); + + for (DataList o: old) { + if (stateName.equals(o.getState())) { + return true; + } + } + + return false; + } + + + public void setCurrentData(DataList current, UIProvider uiProvider) { + this.current = current; + this.uiProvider = uiProvider; + + refreshCurrent(); + } + + + public void refreshOld(boolean redrawAll) { + if (redrawAll) { + refreshAllOld(); + } + else { + DataList dataList = old.get(old.size()-1); + String state = dataList.getState(); + + if (oldStorage.get(state) == null) { + String provider = dataList.getUIProvider(); + UIProvider uiprovider = UIProviderFactory.getProvider( + provider, + flys.getCurrentUser()); + ((HasStepBackHandlers) uiprovider).addStepBackHandler(this); + + Canvas c = uiprovider.createOld(dataList); + if (c != null) { + oldStorage.put(dataList.getState(), c); + oldItems.addMember(c); + } + } + } + + updateOldHeight(); + } + + + protected void refreshAllOld() { + List<String> not = new ArrayList<String>(); + + for (DataList data: old) { + String state = data.getState(); + + Canvas c = oldStorage.get(state); + + if (c != null) { + not.add(state); + } + } + + Map<String, Canvas> newOld = new TreeMap<String, Canvas>(); + + Set<Map.Entry<String, Canvas>> entries = oldStorage.entrySet(); + for (Map.Entry<String, Canvas> entry: entries) { + String state = entry.getKey(); + Canvas value = entry.getValue(); + + if (not.indexOf(state) < 0) { + oldItems.removeMember(value); + } + else { + newOld.put(state, value); + } + } + + oldStorage = newOld; + } + + + protected void updateOldHeight() { + int minHeight = oldItems.getMinHeight(); + if (minHeight <= 20) { + oldItems.setHeight(20); + } + else { + oldItems.setHeight(minHeight); + } + } + + + /** + * This method refreshes the part displaying the data of the current state. + * The UI is created using the UIProvider stored in the Data object. + */ + public void refreshCurrent() { + currentItems.removeMembers(currentItems.getMembers()); + + if (current != null && uiProvider != null) { + Canvas c = uiProvider.create(current); + Canvas h = uiProvider.createHelpLink(current, null); + + HLayout wrapper = new HLayout(); + wrapper.addMember(h); + wrapper.addMember(c); + + currentItems.addMember(wrapper); + } + else if (uiProvider != null) { + Canvas c = uiProvider.create(null); + c.setLayoutAlign(VerticalAlignment.TOP); + + currentItems.addMember(c); + } + else { + currentItems.setHeight(1); + } + + Canvas[] members = currentItems.getMembers(); + if (members == null || members.length == 0) { + currentItems.setHeight(1); + } + else { + int height = 0; + + for (Canvas member: members) { + height += member.getHeight(); + } + + currentItems.setHeight(height); + } + } + + + /** + * This method is called if the user clicks on the 'next' button to advance + * to the next state. + * + * @param event The StepForwardEvent. + */ + @Override + public void onStepForward(StepForwardEvent event) { + GWT.log("CollectionView - onStepForward()"); + lockUI(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + forwardService.go(locale, artifact, event.getData(), + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + unlockUI(); + GWT.log("Could not feed the artifact."); + SC.warn(FLYS.getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully feed the artifact."); + old.clear(); + + setArtifact(artifact, true); + unlockUI(); + } + }); + } + + + /** + * This method is used to remove all old items from this list after the user + * has clicked the step back button. + * + * @param e The StepBackEvent that holds the identifier of the target state. + */ + @Override + public void onStepBack(StepBackEvent e) { + lockUI(); + final String target = e.getTarget(); + + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + advanceService.advance(locale, artifact, target, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + unlockUI(); + GWT.log("Could not go back to '" + target + "'"); + SC.warn(FLYS.getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully step back to '" + target + "'"); + + old.clear(); + + setArtifact(artifact, false); + unlockUI(); + } + } + ); + } + + + @Override + public void onAdvance(final String target) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + advanceService.advance(locale, artifact, target, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not go to '" + target + "'"); + SC.warn(FLYS.getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully advanced to '" + target + "'"); + + old.clear(); + + setArtifact(artifact, true); + } + } + ); + } + + + /** + * Implements the onCollectionChange() method to do update the GUI after the + * parameterization has changed. + * + * @param event The ParameterChangeEvent. + */ + @Override + public void onParameterChange(ParameterChangeEvent event) { + GWT.log("ParameterList.onParameterChange"); + + Canvas[] c = helperPanel.getMembers(); + if (c != null && c.length > 0) { + helperPanel.removeMembers(c); + } + + Artifact art = event.getNewValue(); + ArtifactDescription desc = art.getArtifactDescription(); + + DataList currentData = desc.getCurrentData(); + if (currentData != null) { + // the user has to enter some attributes + String uiProvider = currentData.getUIProvider(); + UIProvider provider = UIProviderFactory.getProvider( + uiProvider, + flys.getCurrentUser()); + + provider.setContainer(helperPanel); + provider.setArtifact(art); + provider.setCollection(cView.getCollection()); + provider.setParameterList(this); + + ((HasStepForwardHandlers) provider).addStepForwardHandler(this); + ((HasStepBackHandlers) provider).addStepBackHandler(this); + + setCurrentData(currentData, provider); + } + else { + String[] reachable = desc.getReachableStates(); + if (reachable != null && reachable.length > 0) { + // We have reached a final state with the option to step to + // further to a next state. But in the current state, no user + // data is required. + UIProvider ui = UIProviderFactory.getProvider("continue", null); + ui.setArtifact(art); + ui.setCollection(cView.getCollection()); + ui.setParameterList(this); + + ((ContinuePanel) ui).addAdvanceHandler(this); + + setCurrentData(null, ui); + } + else { + // we have reached a final state with no more user input + setCurrentData(null, null); + } + } + if (art instanceof WINFOArtifact + || art instanceof FixAnalysisArtifact) { + createGaugePanel(); + renderInfo(desc.getRiver(), desc.getOldData()); + } + else if (art instanceof MINFOArtifact) { + createMeasurementStationPanel(); + renderInfo(desc.getRiver(), desc.getOldData()); + } + else { + removeInfoPanel(); + } + + addOldDatas( + desc.getOldData(), + event.getType() == ParameterChangeEvent.Type.BACK); + } + + + @Override + public void onCollectionChange(CollectionChangeEvent event) { + Collection c = event.getNewValue(); + Map<String, OutputMode> outs = c.getOutputModes(); + Set<String> keys = outs.keySet(); + + OutputMode[] outputs = new OutputMode[outs.size()]; + + int idx = 0; + for (String outname: keys) { + outputs[idx++] = outs.get(outname); + } + + updateExportModes(c, getExportModes(outputs)); + updateReportModes(c, getReportModes(outputs)); + } + + + @Override + public void onOutputModesChange(OutputModesChangeEvent event) { + + Collection c = cView.getCollection(); + + if (c != null) { + OutputMode [] outs = event.getOutputModes(); + updateExportModes(c, getExportModes(outs)); + updateReportModes(c, getReportModes(outs)); + } + } + + + protected List<ReportMode> getReportModes(OutputMode [] outs) { + + List<ReportMode> reports = new ArrayList<ReportMode>(); + + if (outs == null || outs.length == 0) { + return reports; + } + + for (OutputMode out: outs) { + if (out instanceof ReportMode) { + reports.add((ReportMode)out); + } + } + + return reports; + } + + + protected List<ExportMode> getExportModes(OutputMode[] outs) { + List<ExportMode> exports = new ArrayList<ExportMode>(); + + if (outs == null || outs.length == 0) { + return exports; + } + + for (OutputMode out: outs) { + if (out instanceof ExportMode) { + exports.add((ExportMode) out); + } + } + + return exports; + } + + + protected void updateExportModes(Collection c, List<ExportMode> exports) { + int num = exports != null ? exports.size() : 0; + GWT.log("Update export modes: " + num); + + exportModes.removeMembers(exportModes.getMembers()); + + if (exports.size() > 0) { + exportModes.addMember(new ExportPanel(c, exports)); + } + else { + exportModes.setHeight(1); + } + } + + protected void updateReportModes(Collection c, List<ReportMode> reports) { + int num = reports != null ? reports.size() : 0; + GWT.log("Update report modes: " + num); + + if (num == 0) { + reportPanel.setContents(""); + return; + } + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + String cid = c.identifier(); + + for (ReportMode report: reports) { + GWT.log("report '" + report.toString() + "'"); + + reportService.report(cid, locale, report.getName(), + new AsyncCallback<String>() { + @Override + public void onFailure(Throwable caught) { + SC.warn(FLYS.getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(String msg) { + setReportMessage(msg); + } + }); + } + } + + + /** Sets content of reportPanel. */ + protected void setReportMessage(String msg) { + GWT.log("returned from service: " + msg); + if (msg == null) { + msg = ""; + } + reportPanel.setContents(msg); + } + + + /** + * Adds a table to the parameterlist to show calculated data. + * + * @param table The table data panel. + */ + public void setTable(TableDataPanel table) { + removeTable(); + + Canvas c = table.create(); + c.setHeight100(); + c.setWidth100(); + + tablePanel.addMember(c); + } + + + public boolean hasTable() { + Canvas[] members = tablePanel.getMembers(); + + return members != null && members.length > 0; + } + + + /** + * Removes the table from the parameter list. + */ + public void removeTable() { + Canvas[] members = tablePanel.getMembers(); + + if (members != null && members.length > 0) { + tablePanel.removeMembers(members); + } + } + + + public void registerCollectionViewTabHandler(TabSelectedHandler tsh) { + this.cView.registerTabHandler(tsh); + } + + + protected void lockUI() { + cView.lockUI(); + } + + + protected void unlockUI() { + cView.unlockUI(); + } + + + private void createGaugePanel() { + GWT.log("ParameterList - createGaugePanel"); + if (infoPanel == null) { + infoPanel = new GaugePanel(flys); + infoPanel.setWidth100(); + infoPanel.setHeight100(); + } + } + + private void createMeasurementStationPanel() { + GWT.log("ParameterList - createMeasurementStationPanel"); + if (infoPanel == null) { + infoPanel = new MeasurementStationPanel(flys); + infoPanel.setWidth100(); + infoPanel.setHeight100(); + } + } + + private void showInfoPanel() { + GWT.log("ParameterList - showInfoPanel"); + + /* Don't add InfoPanel twice */ + SectionStackSection exists = stack.getSection(InfoPanel.SECTION_ID); + if (exists == null) { + stack.addSection(infoPanel.getSection(), 0); + } + + infoPanel.show(); + } + + private void hideInfoPanel() { + GWT.log("ParameterList - hideInfoPanel"); + + if (infoPanel != null) { + infoPanel.hide(); + } + } + + private void removeInfoPanel() { + GWT.log("ParameterList - removeInfoPanel"); + SectionStackSection exists = stack.getSection(InfoPanel.SECTION_ID); + if (exists != null) { + stack.removeSection(InfoPanel.SECTION_ID); + } + } + + + private void renderInfo(String river, DataList[] data) { + GWT.log("ParameterList - renderInfo"); + + if (river != null) { + showInfoPanel(); + infoPanel.setRiver(river); + infoPanel.setData(data); + } + else { + GWT.log("ParameterList - renderInfo no river"); + hideInfoPanel(); + } + } + + /** + * Allow to close all folds of the info panel. + * This is necessary e.g. if a csv result should be shown. + */ + public void contractInfoPanel() { + if (infoPanel != null) { + infoPanel.contract(); + } + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ParameterMatrix.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,285 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.Grid; +import com.google.gwt.user.client.ui.Widget; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.IntegerOptionsData; +import de.intevation.flys.client.shared.model.StringOptionsData; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * Some parameters take the form of on/off options that can also be seen + * as a matrix. + * + * This class helps to survive the underlying objects and create a visual + * representation of this matrix. Later can happen in two ways to overcome + * shortcomings of GWT/SmartGWT combination. + */ +public class ParameterMatrix { + + protected ListGrid listGrid = null; + + public static class Column implements Serializable { + + private static final long serialVersionUID = -3493426383086860118L; + + protected String name; + protected Map<String, String> values; + + private Column() { + this.values = new HashMap<String, String>(); + } + + public Column(String name) { + this(); + this.name = name; + } + + public void addValue(String label, String value) { + values.put(label, value); + } + + public String getValue(String label) { + return values.get(label); + } + } // end of class Column + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + public static final int CELL_HEIGHT = 25; + + private Map<String, Column> columns; + private List<String> columnNames; + private List<String> valueNames; + + /** Maps column names to list of rows' first fields. */ + private Map<String, List<String>> selected; + + public ParameterMatrix() { + super(); + this.columns = new HashMap<String, Column>(); + this.columnNames = new ArrayList<String>(); + this.valueNames = new ArrayList<String>(); + this.selected = new HashMap<String, List<String>>(); + } + + + public void addColumn(IntegerOptionsData group) { + String groupTitle = group.getLabel(); + + Column col = new Column(groupTitle); + DataItem[] items = group.getItems(); + + if (items == null) { + GWT.log("No items found in StringOptionsData '" + groupTitle + "'"); + return; + } + + for (DataItem item: items) { + String title = item.getLabel(); + + if (valueNames.indexOf(title) < 0) { + valueNames.add(title); + } + + col.addValue(item.getLabel(), item.getStringValue()); + } + + columnNames.add(groupTitle); + columns.put(groupTitle, col); + } + + + public void addColumn(StringOptionsData options) { + String groupTitle = options.getLabel(); + + Column col = new Column(groupTitle); + DataItem[] items = options.getItems(); + + if (items == null) { + GWT.log("No items found in StringOptionsData '" + groupTitle + "'"); + return; + } + + for (DataItem item: items) { + String title = item.getLabel(); + + if (valueNames.indexOf(title) < 0) { + valueNames.add(title); + } + + col.addValue(item.getLabel(), item.getStringValue()); + } + + columnNames.add(groupTitle); + columns.put(groupTitle, col); + } + + + public Widget createParameterGrid() { + listGrid = new ListGrid(); + listGrid.setShowAllRecords(true); + listGrid.setWrapCells(true); + listGrid.setShowHeaderContextMenu(false); + listGrid.setCanReorderFields(false); + listGrid.setCanSort(false); + //listGrid.setAutoFitData(Autofit.VERTICAL); + listGrid.setFixedRecordHeights(false); + // TODO: Then also need "autofit" (when wrapping) + + ListGridField itemNameField = new ListGridField("itemname", " "); + ArrayList<ListGridField> fields = new ArrayList<ListGridField>(); + fields.add(itemNameField); + + for (int i = 0, n = columnNames.size(); i < n; i++) { + ListGridField field = new ListGridField(columnNames.get(i), MESSAGE.getString(columnNames.get(i))); + field.setType(ListGridFieldType.BOOLEAN); + field.setCanEdit(true); + fields.add(field); + selected.put(columnNames.get(i), new ArrayList<String>()); + } + + ListGridField[] fieldsArray = fields.toArray(new ListGridField[fields.size()]); + listGrid.setFields(fieldsArray); + + int nVals = valueNames.size(); + + ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>(); + for (int j = 0; j < nVals; j++) { + String valueName = valueNames.get(j); + ListGridRecord record = new ListGridRecord(); + record.setAttribute("itemname", valueName); + for (int i = 0, n = columnNames.size(); i < n; i++) { + String columnName = columnNames.get(i); + Column col = columns.get(columnName); + String value = col.getValue(valueName); + record.setAttribute(columnName, false); + record.setAttribute(columnName+"-value", value); + } + records.add(record); + } + + listGrid.setData(records.toArray(new ListGridRecord[records.size()])); + + return listGrid; + + } + + + /** + * Returns a widget with matrix of checkboxes and labels. + * @param asListGrid if true, use a ListGrid (for inclusion in SmartGWT + * containers, avoiding scrollbar-issues. + */ + public Widget create(boolean asListGrid) { + if (asListGrid) { + return createParameterGrid(); + } + Grid grid = new Grid(valueNames.size() + 1, columnNames.size() + 1); + + for (int i = 0, n = columnNames.size(); i < n; i++) { + String columnName = columnNames.get(i); + Column col = columns.get(columnName); + + selected.put(columnName, new ArrayList<String>()); + + grid.setWidget(0, i+1, createLabel(MESSAGE.getString(columnName))); + + for (int j = 0, o = valueNames.size(); j < o; j++) { + String valueName = valueNames.get(j); + String value = col.getValue(valueName); + + if (i == 0) { + grid.setWidget(j+1, 0, createLabel(valueName)); + } + + if (value != null && value.length() > 0) { + grid.setWidget(j+1, i+1, createCheckBox(columnName, value)); + } + } + } + + return grid; + } + + + /** Creates label with given text. */ + protected Label createLabel(String text) { + Label label = new Label(text); + label.setHeight(CELL_HEIGHT); + + return label; + } + + + /** Create Checkbox for column/value. */ + protected Canvas createCheckBox(final String colName, final String value) { + CheckBox box = new CheckBox(); + box.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + Map<String, List<String>> selection = getSelection(); + + List<String> values = selection.get(colName); + if (values.indexOf(value) >= 0) { + values.remove(value); + } + else { + values.add(value); + } + } + }); + + Canvas c = new Canvas(); + c.addChild(box); + return c; + } + + + public Map<String, List<String>> getSelection() { + if (listGrid == null) { + return selected; + } + + ListGridRecord[] records = listGrid.getRecords(); + Map<String, List<String>> result = new HashMap<String, List<String>>(); + for (ListGridRecord record : records) { + for (int i = 0, n = columnNames.size(); i < n; i++) { + String columnName = columnNames.get(i); + if (Boolean.valueOf(record.getAttribute(columnName)) == true) { + if (result.containsKey(columnName)) { + result.get(columnName).add(record.getAttribute(columnName + "-value")); + } + else { + List<String> items = new ArrayList<String>(); + items.add(record.getAttribute(columnName + "-value")); + result.put(columnName, items); + } + } + } + } + return result; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ParameterMatrixPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,197 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.HTML; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.IntegerOptionsData; +import de.intevation.flys.client.shared.model.StringOptionsData; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ParameterMatrixPanel extends AbstractUIProvider { + + private static final long serialVersionUID = -5827445025768340371L; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + private ParameterMatrix matrix; + + @Override + protected Data[] getData() { + Map<String, List<String>> selection = matrix.getSelection(); + Set<Map.Entry<String, List<String>>> entries = selection.entrySet(); + + Data[] list = new Data[selection.size()]; + + int i = 0; + + for (Map.Entry<String, List<String>> entry: entries) { + String value = buildValueString(entry.getValue()); + + DataItem item = new DefaultDataItem( + entry.getKey(), + null, + value); + + list[i++] = new DefaultData( + entry.getKey(), null, null, new DataItem[] { item }); + } + + return list; + } + + + protected String buildValueString(List<String> values) { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + + for (String value: values) { + if (!first) { + sb.append(";"); + } + + sb.append(value); + + first = false; + } + + return sb.toString(); + } + + + /** Canvas to show in non-edit mode. */ + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + VLayout vLayout = new VLayout(); + + layout.setWidth(300); + vLayout.setWidth(280); + + for (int i = 0, n = dataList.size(); i < n; i++) { + HLayout row = new HLayout(); + VLayout cols = new VLayout(); + + row.setWidth(300); + cols.setWidth(100); + + Data data = dataList.get(i); + DataItem[] items = data.getItems(); + + Label parameter = new Label(data.getDescription()); + parameter.setWidth(200); + + for (int j = 0, m = items.length; j < m; j++) { + DataItem item = items[j]; + Label value = new Label(item.getLabel()); + + value.setValign(com.smartgwt.client.types.VerticalAlignment.TOP); + value.setWidth(130); + value.setHeight(20); + + cols.addMember(value); + HTML hr = new HTML("<hr>"); + hr.setHeight("3px"); + cols.addMember(hr); + } + + row.addMember(parameter); + row.addMember(cols); + + vLayout.addMember(row); + } + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + + /** Create the main canvas in the "editing" mode. */ + @Override + public Canvas create(DataList dataList) { + VLayout v = new VLayout(); + v.addMember(createTitle(dataList)); + + matrix = new ParameterMatrix(); + + for (Data data: dataList.getAll()) { + if (data instanceof IntegerOptionsData) { + matrix.addColumn((IntegerOptionsData) data); + } + else if (data instanceof StringOptionsData) { + matrix.addColumn((StringOptionsData) data); + } + } + + // If too many items are shown, show it in the helper Panel. + // TODO its not about the datalist, but about the "rows" in the data. + if (dataList.getAll().size() > 5) { + v.addMember(matrix.create(false)); + } + else { + helperContainer.addMember(matrix.create(true)); + } + v.addMember(getNextButton()); + + return v; + } + + + /** Reaturns a label with description of first Data. */ + protected Canvas createTitle(DataList dataList) { + Data data = dataList.get(0); + Label label = new Label(data.getDescription()); + label.setHeight(35); + + return label; + } + + + /** Selection shall not be empty. */ + @Override + public List<String> validate() { + GWT.log ("validation. validation. validation. "); + List<String> errors = new ArrayList<String>(); + // Early stop on one (only) error. + boolean ok = false; + for (Map.Entry<String, List<String>> entry : matrix.getSelection().entrySet()) { + /* single entries are allowed!! + if (entry.getValue() == null || entry.getValue().size() == 0) { + errors.add(MESSAGES.error_values_needed()); + return errors; + } + */ + if (entry.getValue() != null && entry.getValue().size() > 0) { + ok = true; + } + } + if (!ok) { + errors.add(MESSAGES.error_values_needed()); + } + return errors; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/PeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,194 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.DateRangeItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class PeriodPanel +extends AbstractUIProvider +{ + private static final long serialVersionUID = -5249560815807538821L; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + DateRangeItem inputPanel; + + long start; + long end; + + protected String startName; + protected String endName; + + public PeriodPanel() { + this("start", "end"); + } + + public PeriodPanel(String startName, String endName) { + this.startName = startName; + this.endName = endName; + } + + + @Override + public Canvas create(DataList list) { + VLayout layout = new VLayout(); + + Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(list); + + layout.addMember(widget); + layout.addMember(submit); + return layout; + } + + + public Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + + Label title = new Label(data.get(0).getDescription()); + title.setHeight("25px"); + + DynamicForm form = new DynamicForm(); + inputPanel = new DateRangeItem(); + inputPanel.setToTitle(MSG.to()); + inputPanel.setFromTitle(MSG.from()); + inputPanel.setShowTitle(false); + form.setFields(inputPanel); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + protected Canvas createHelper() { + return new VLayout(); + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data start = getData(items, startName); + Data end = getData(items, endName); + DataItem[] startItem = start.getItems(); + DataItem[] endItem = end.getItems(); + + String v1 = startItem[0].getStringValue(); + String v2 = endItem[0].getStringValue(); + + long v1l = 0; + long v2l = 0; + try { + v1l = Long.parseLong(v1); + v2l = Long.parseLong(v2); + } + catch(NumberFormatException nfe) { + GWT.log(nfe.toString()); + } + Date d1 = new Date(v1l); + Date d2 = new Date(v2l); + + DateTimeFormat f = + DateTimeFormat.getFormat( + DateTimeFormat.PredefinedFormat.DATE_MEDIUM); + StringBuilder sb = new StringBuilder(); + sb.append(f.format(d1) + " - "); + sb.append(f.format(d2)); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveDateValues(); + if(valid) { + String start = Long.valueOf(this.start).toString(); + String end = Long.valueOf(this.end).toString(); + DataItem startItem = new DefaultDataItem(startName, startName, start); + DataItem endItem = new DefaultDataItem(endName, endName, end); + data.add(new DefaultData( + startName, + null, + null, + new DataItem[] { startItem })); + data.add(new DefaultData( + endName, + null, + null, + new DataItem[] { endItem })); + } + + return data.toArray(new Data[data.size()]); + } + + + protected boolean saveDateValues() { + Date st = inputPanel.getFromDate(); + Date en = inputPanel.getToDate(); + if (st == null || en == null) { + SC.warn(MSG.error_wrong_date()); + return false; + } + + long start = st.getTime(); + long end = en.getTime(); + + if (start <= end) { + this.start = start; + this.end = end; + return true; + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ProjectList.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,956 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.Autofit; +import com.smartgwt.client.types.ListGridEditEvent; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.types.SortArrow; +import com.smartgwt.client.types.SortDirection; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.util.BooleanCallback; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.IconButton; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.VisibilityChangedEvent; +import com.smartgwt.client.widgets.events.VisibilityChangedHandler; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.HoverCustomizer; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent; +import com.smartgwt.client.widgets.grid.events.CellDoubleClickHandler; +import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; +import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; +import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickEvent; +import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickHandler; +import com.smartgwt.client.widgets.grid.events.RowContextClickEvent; +import com.smartgwt.client.widgets.grid.events.RowContextClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +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.MenuItemSeparator; +import com.smartgwt.client.widgets.menu.events.ClickHandler; +import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.CollectionChangeEvent; +import de.intevation.flys.client.client.event.CollectionChangeHandler; +import de.intevation.flys.client.client.event.FilterHandler; +import de.intevation.flys.client.client.event.RangeFilterEvent; +import de.intevation.flys.client.client.event.StringFilterEvent; +import de.intevation.flys.client.client.services.AddArtifactService; +import de.intevation.flys.client.client.services.AddArtifactServiceAsync; +import de.intevation.flys.client.client.services.ArtifactService; +import de.intevation.flys.client.client.services.ArtifactServiceAsync; +import de.intevation.flys.client.client.services.CreateCollectionService; +import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; +import de.intevation.flys.client.client.services.DeleteCollectionService; +import de.intevation.flys.client.client.services.DeleteCollectionServiceAsync; +import de.intevation.flys.client.client.services.DescribeCollectionService; +import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; +import de.intevation.flys.client.client.services.GetArtifactService; +import de.intevation.flys.client.client.services.GetArtifactServiceAsync; +import de.intevation.flys.client.client.services.SetCollectionNameService; +import de.intevation.flys.client.client.services.SetCollectionNameServiceAsync; +import de.intevation.flys.client.client.services.SetCollectionTTLService; +import de.intevation.flys.client.client.services.SetCollectionTTLServiceAsync; +import de.intevation.flys.client.client.services.UserCollectionsService; +import de.intevation.flys.client.client.services.UserCollectionsServiceAsync; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; +import de.intevation.flys.client.shared.model.CollectionRecord; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.MissingResourceException; + + +/** + * The project list shows a list of projects of a specific user. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ProjectList +extends VLayout +implements CollectionChangeHandler, EditCompleteHandler, FilterHandler, + VisibilityChangedHandler +{ + /** Interval to refresh the user's projects.*/ + public static final int UPDATE_INTERVAL = 30000; + + /** Min Interval to refresh the user's projects.*/ + public static final int MIN_UPDATE_INTERVAL = 5000; + + /** The initial width of this panel.*/ + public static final int MIN_WIDTH = 300; + + /** The max length for new project names.*/ + public static final int MAX_NAME_LENGTH = 50; + + public static final String COLUMN_DATE_WIDTH = "100px"; + + public static final String COLUMN_TITLE_WIDTH = "*"; + + public static final String COLUMN_FAVORITE_WIDTH = "75px"; + + /** The interface that provides i18n messages. */ + private final FLYSConstants messages = GWT.create(FLYSConstants.class); + + /** The UserService used to retrieve information about the current user. */ + protected UserCollectionsServiceAsync userCollectionsService = + GWT.create(UserCollectionsService.class); + + /** The service used to set the name of a project.*/ + protected SetCollectionNameServiceAsync nameService = + GWT.create(SetCollectionNameService.class); + + /** The service used to set the name of a project.*/ + protected SetCollectionTTLServiceAsync ttlService = + GWT.create(SetCollectionTTLService.class); + + /** The service used to set the name of a project.*/ + protected DeleteCollectionServiceAsync deleteService = + GWT.create(DeleteCollectionService.class); + + /** The DescribeCollectionService used to update the existing collection. */ + protected DescribeCollectionServiceAsync describeCollectionService = + GWT.create(DescribeCollectionService.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected ArtifactServiceAsync createArtifactService = + GWT.create(ArtifactService.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected CreateCollectionServiceAsync createCollectionService = + GWT.create(CreateCollectionService.class); + + /** The AddArtifactService used to add an artifact to a collection. */ + protected AddArtifactServiceAsync addArtifactService = + GWT.create(AddArtifactService.class); + + /** The GetArtifactService used to open an existing collection. */ + protected GetArtifactServiceAsync getArtifactService = + GWT.create(GetArtifactService.class); + + /** A pointer to the FLYS instance.*/ + protected FLYS flys; + + /** The user whose projects should be displayed.*/ + protected User user; + + /** The grid that contains the project rows.*/ + protected ListGrid grid; + + /** All user collections.*/ + protected List<Collection> collections; + + /** The collection to clone*/ + protected Collection cloneCollection; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + private String filter; + + + /** + * The default constructor that creates a new ProjectList for a specific + * user. + * + * @param user The user. + */ + public ProjectList(FLYS flys, User user) { + super(); + this.flys = flys; + this.user = user; + + collections = new ArrayList<Collection>(); + grid = new ListGrid(); + initGrid(); + init(); + initTimer(); + + grid.addEditCompleteHandler(this); + + addVisibilityChangedHandler(this); + + updateUserCollections(); + } + + + protected void initGrid() { + grid.setWidth100(); + grid.setAutoFitData(Autofit.VERTICAL); + grid.setAutoFitMaxWidth(500); + grid.setEmptyMessage(messages.no_projects()); + grid.setLoadingDataMessage(messages.load_projects()); + grid.setCanEdit(false); + grid.setEditEvent(ListGridEditEvent.NONE); + grid.setShowHeaderContextMenu(false); + grid.setShowSortArrow(SortArrow.NONE); + grid.setSortDirection(SortDirection.DESCENDING); + grid.setSortField(0); + grid.setSelectionType(SelectionStyle.SINGLE); + grid.setCanReorderFields(false); + grid.setLeaveScrollbarGap(false); + grid.setBorder("0px"); + + ListGridField date = buildDateField(); + ListGridField name = buildNameField(); + ListGridField fav = buildFavoriteField(); + + grid.setFields(date, name, fav); + + grid.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() { + @Override + public void onHeaderDoubleClick(HeaderDoubleClickEvent event) { + // Cancel the event. + return; + } + }); + + // Add a handler to set / unset the favorite state of a project. + grid.addCellClickHandler(new CellClickHandler() { + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() != 2) { + return; + } + + CollectionRecord r = (CollectionRecord) event.getRecord(); + Collection c = r.getCollection(); + + c.setTTL(c.getTTL() == 0 ? -1 : 0); + updateCollectionTTL(c); + } + }); + + // Add a handler to open a project. + grid.addCellDoubleClickHandler(new CellDoubleClickHandler() { + @Override + public void onCellDoubleClick(CellDoubleClickEvent e) { + CollectionRecord record = (CollectionRecord) e.getRecord(); + String uuid = record != null + ? record.getCollection().identifier() + : ""; + getFlys().openProject(uuid); + } + }); + + // Add a handler to open a context menu. + grid.addRowContextClickHandler(new RowContextClickHandler() { + @Override + public void onRowContextClick(RowContextClickEvent event) { + CollectionRecord record = (CollectionRecord) event.getRecord(); + + Menu menu = createContextMenu(record); + grid.setContextMenu(menu); + menu.showContextMenu(); + + event.cancel(); + } + }); + } + + + /** + * Initializes a repeating timer that updates the user's collections. The + * interval is specified by the constant <i>UPDATE_INTERVAL</i>. + */ + protected void initTimer() { + Config config = Config.getInstance(); + int interval = config.getProjectListUpdateInterval(); + + interval = interval > MIN_UPDATE_INTERVAL ? interval : UPDATE_INTERVAL; + + GWT.log("Update project list every " + interval + " milliseconds."); + + Timer t = new Timer() { + @Override + public void run() { + updateUserCollections(); + } + }; + + t.scheduleRepeating(interval); + } + + + public FLYS getFlys() { + return flys; + } + + + /** + * Creates a new context menu that interacts with a CollectionRecord. + * + * @param record The selected record. + * + * @return the context menu with operations that interact with + * <i>record</i>. + */ + protected Menu createContextMenu(final CollectionRecord record) { + Menu menu = new Menu(); + + MenuItem open = new MenuItem(messages.open_project()); + open.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + getFlys().openProject(record.getCollection().identifier()); + } + }); + + MenuItem del = new MenuItem(messages.delete_project()); + del.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + SC.ask(messages.really_delete(), new BooleanCallback() { + @Override + public void execute(Boolean value) { + if (value) { + deleteCollection(record.getCollection()); + } + } + }); + } + }); + + MenuItem rename = new MenuItem(messages.rename_project()); + rename.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + int row = grid.getRecordIndex(record); + grid.startEditing(row, 1, false); + } + }); + + MenuItem clone = new MenuItem(messages.clone_project()); + clone.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + cloneProject(record.getCollection()); + } + }); + + menu.addItem(open); + menu.addItem(rename); + menu.addItem(clone); + menu.addItem(new MenuItemSeparator()); + menu.addItem(del); + + return menu; + } + + + /** + * The init() method handles the layout stuff for this widget. + */ + protected void init() { + setWidth(MIN_WIDTH); + setMinWidth(MIN_WIDTH); + setHeight100(); + setShowResizeBar(true); + setShowEdges(false); + setLayoutMargin(0); + setLayoutAlign(VerticalAlignment.TOP); + setOverflow(Overflow.AUTO); + + Label title = new Label(messages.projects()); + title.setHeight("20"); + title.setMargin(5); + title.setWidth100(); + title.setStyleName("projectHeader"); + + HLayout buttonWrapper = new HLayout(); + + IconButton addButton = new IconButton(""); + addButton.setIcon(messages.projectListAdd()); + addButton.setTooltip(messages.new_project()); + addButton.setWidth("30px"); + + IconButton closeButton = new IconButton(""); + closeButton.setIcon(messages.projectListMin()); + closeButton.setTooltip(messages.projectlist_close()); + closeButton.setWidth("30px"); + + buttonWrapper.addMember(addButton); + buttonWrapper.addMember(closeButton); + buttonWrapper.setAlign(Alignment.RIGHT); + buttonWrapper.setAutoWidth(); + + HLayout titleWrapper = new HLayout(); + titleWrapper.setStyleName("bgBlueMid"); + titleWrapper.setWidth100(); + titleWrapper.setHeight("20px"); + titleWrapper.addMember(title); + titleWrapper.addMember(buttonWrapper); + + Canvas gridWrapper = new Canvas(); + gridWrapper.setPadding(0); + titleWrapper.setWidth100(); + gridWrapper.addChild(grid); + + TableFilter filterpanel = new TableFilter(); + filterpanel.setHeight("30px"); + filterpanel.addFilterHandler(this); + filterpanel.setBorder("1px solid gray"); + + addMember(titleWrapper); + addMember(gridWrapper); + addMember(filterpanel); + + addButton.addClickHandler( + new com.smartgwt.client.widgets.events.ClickHandler() { + + @Override + public void onClick(ClickEvent ev) { + flys.newProject(); + } + }); + + closeButton.addClickHandler( + new com.smartgwt.client.widgets.events.ClickHandler() { + + @Override + public void onClick(ClickEvent ev) { + hide(); + } + }); + } + + + @Override + public void onFilterCriteriaChanged(StringFilterEvent event) { + String search = event.getFilter(); + // Filter the records. + setFilter(search); + updateGrid(); + } + + + @Override + public void onFilterCriteriaChanged(RangeFilterEvent event) { + //Empty. No Ranges to filter. + } + + + /** On collection change, update list (probably name change or similar). */ + @Override + public void onCollectionChange(CollectionChangeEvent event) { + if (event.getOldValue() == null) { + updateUserCollections(); + } + } + + + @Override + public void onEditComplete(EditCompleteEvent event) { + if (event.getColNum() != 1) { + return; + } + + int row = event.getRowNum(); + + CollectionRecord r = (CollectionRecord) grid.getRecord(row); + Collection c = r.getCollection(); + + Map<?, ?> newValues = event.getNewValues(); + String name = (String) newValues.get("name"); + + int maxLength = getMaxNameLength(); + int length = name != null ? name.length() : 0; + + if (length <= 0 || length > maxLength) { + String msg = messages.project_name_too_long(); + msg = msg.replace("$LEN", String.valueOf(maxLength)); + SC.warn(msg); + + ListGridRecord[] rs = grid.getRecords(); + rs[row] = (ListGridRecord) event.getOldRecord(); + grid.setRecords(rs); + + return; + } + + updateCollectionName(c, name); + } + + + /** + * Set the name of the collection <i>c</i> to a new value. If the update + * process succeeded, the project list is refreshed. + * + * @param c The Collection with a new name. + * @param name Name to set on the collection + */ + private void updateCollectionName(final Collection c, String name) { + if (c == null) { + return; + } + + c.setName(name); + + GWT.log("Update Collection name: " + c.identifier()); + GWT.log("=> New name = " + c.getName()); + + nameService.setName(c, new AsyncCallback<Void>(){ + @Override + public void onFailure(Throwable caught) { + String msg = caught.getMessage(); + + try { + SC.warn(messages.getString(msg)); + } + catch (MissingResourceException mre) { + SC.warn(msg); + } + } + + @Override + public void onSuccess(Void v) { + updateUserCollections(); + if(flys.getWorkspace().hasView(c.identifier())) { + flys.getWorkspace().updateTitle(c.identifier(), c.getName()); + } + } + }); + } + + + /** + * Set the ttl of the collection <i>c</i> to a new value. If the update + * process succeeded, the project list is refreshed. + * + * @param c The Collection with a new ttl. + */ + protected void updateCollectionTTL(Collection c) { + if (c == null) { + return; + } + + GWT.log("Update Collection TTL: " + c.identifier()); + GWT.log("=> New ttl = " + c.getTTL()); + + ttlService.setTTL(c, new AsyncCallback<Void>() { + @Override + public void onFailure(Throwable caught) { + String msg = caught.getMessage(); + + try { + SC.warn(messages.getString(msg)); + } + catch (MissingResourceException mre) { + SC.warn(msg); + } + } + + @Override + public void onSuccess(Void v) { + updateUserCollections(); + } + }); + } + + + /** + * Delete the collection <i>c</i>. + * + * @param c The Collection that should be deleted. + */ + public void deleteCollection(final Collection c) { + if (c == null) { + return; + } + + GWT.log("Delete Collection: " + c.identifier()); + + deleteService.delete(c, new AsyncCallback<Void>(){ + @Override + public void onFailure(Throwable caught) { + String msg = caught.getMessage(); + + try { + SC.warn(messages.getString(msg)); + } + catch (MissingResourceException mre) { + SC.warn(msg); + } + } + + @Override + public void onSuccess(Void v) { + flys.getWorkspace().destroyProject(c.identifier()); + updateUserCollections(); + } + }); + } + + + public void updateUserCollections() { + GWT.log("==> ProjectList updates user collections!"); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + userCollectionsService.getUserCollections(locale, user.identifier(), + new AsyncCallback<Collection[]>() { + @Override + public void onFailure(Throwable caught) { + String msg = caught.getMessage(); + + try { + SC.warn(messages.getString(msg)); + } + catch (MissingResourceException mre) { + SC.warn(msg); + } + } + + @Override + public void onSuccess(Collection[] collections) { + int num = collections != null ? collections.length : 0; + + GWT.log("Received " + num + " user collections."); + + updateGridDataSource(collections); + } + } + ); + } + + + /** + * Delete all entries in the ListGrid. + */ + private void clearGrid() { + ListGridRecord[] records = grid.getRecords(); + + for (ListGridRecord record: records) { + grid.removeData(record); + } + } + + + /** + * Update the collections data source. + * + * First removes all collections to avoid duplicates, then add new entries. + * + * @param c Collections to set to the data source. + */ + private void updateGridDataSource(Collection[] c) { + collections.clear(); + if(c == null) { + clearGrid(); + return; + } + for (Collection coll : c) { + this.collections.add(coll); + } + updateGrid(); + } + + + /** + * Updates the ListGrid. + */ + private void updateGrid() { + clearGrid(); + + if (collections == null || collections.isEmpty()) { + return; + } + + for (Collection col: collections) { + String name; + + name = col.getDisplayName().toLowerCase(); + + // Add a collection to the filtered list if the search string + // matches. + if (filter == null || filter.isEmpty() || + name.contains(filter.toLowerCase())) { + grid.addData(new CollectionRecord(col)); + } + } + } + + public int getMaxNameLength() { + return MAX_NAME_LENGTH; + } + + + /** + * Builds the field in the grid that displays the creation time of a + * project. + * + * @return the grid field. + */ + protected ListGridField buildDateField() { + ListGridField date = new ListGridField( + "creationTime", messages.projectlist_creationTime()); + + date.setType(ListGridFieldType.DATE); + date.setCanEdit(false); + + date.setCellFormatter(new CellFormatter() { + @Override + public String format(Object value, ListGridRecord rec, int r, int c) { + if (value == null) { + return null; + } + + DateTimeFormat dtf = DateTimeFormat.getFormat( + messages.datetime_format()); + + return dtf.format((Date)value); + } + }); + + date.setWidth(COLUMN_DATE_WIDTH); + date.setAlign(Alignment.CENTER); + + return date; + } + + + /** + * Builds the field in the grid that displays the name of a project. + * + * @return the grid field. + */ + protected ListGridField buildNameField() { + ListGridField name = new ListGridField( + "name", messages.projectlist_title()); + + name.setType(ListGridFieldType.TEXT); + name.setShowHover(true); + name.setHoverCustomizer(new HoverCustomizer() { + @Override + public String hoverHTML( + Object value, + ListGridRecord record, + int row, + int col) + { + CollectionRecord r = (CollectionRecord) record; + Collection c = r.getCollection(); + + String name = r.getName(); + + return name != null && name.length() > 0 + ? name + : c.identifier(); + } + }); + + name.setWidth(COLUMN_TITLE_WIDTH); + name.setAlign(Alignment.LEFT); + + return name; + } + + + protected ListGridField buildFavoriteField() { + ListGridField fav = new ListGridField( + "ttl", messages.projectlist_favorite()); + + fav.setType(ListGridFieldType.IMAGE); + String base = GWT.getHostPageBaseURL(); + fav.setImageURLPrefix(base + "images/"); + fav.setImageURLSuffix(".png"); + fav.setWidth(COLUMN_FAVORITE_WIDTH); + fav.setAlign(Alignment.CENTER); + fav.setCanEdit(false); + + return fav; + } + + + protected void cloneProject(Collection c) { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + cloneCollection = c; + + describeCollectionService.describe(c.identifier(), locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not DESCRIBE collection."); + SC.warn(messages.getString(caught.getMessage())); + } + + + @Override + public void onSuccess(Collection newCollection) { + GWT.log("Successfully DESCRIBED collection."); + String uuid = getMasterArtifact(newCollection); + cloneArtifact(uuid, newCollection); + } + } + ); + } + + + /** Get master artifacts UUID of a collection. */ + protected String getMasterArtifact(Collection newCollection) { + String uuid = newCollection.getItem(0).identifier(); + // The master artifact uuid. + return uuid; + } + + + /** Clone artifact/create collection, using the refArtifacts factory. */ + protected void cloneArtifact(String uuid, Artifact refArtifact, + final String locale) { + Recommendation recommendation = new Recommendation( + refArtifact.getName(), + null, + uuid, + null); + + String factory = recommendation.getFactory(); + createArtifactService.create( + locale, factory, recommendation, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Error loading recommendations: " + + caught.getMessage()); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Created new artifact: " + artifact.getUuid()); + createClonedCollection(artifact); + } + } + ); + } + + + /** + * Clone a project (collection). + */ + private void cloneArtifact(final String uuid, Collection newCollection) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + // Find out which factory to use for cloning. + CollectionItem master = newCollection.getItem(0); + getArtifactService.getArtifact( + locale, + master.identifier(), + master.hash(), + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + SC.warn(MSG.getString(caught.getMessage())); + } + + @Override + public void onSuccess(Artifact artifact) { + cloneArtifact(uuid, artifact, locale); + } + }); + } + + + /** + * Creates a {@link Collection} with the passed {@link Artifact} + * @param artifact {@link Artifact} to add to the new {@link Collection} + */ + private void createClonedCollection(final Artifact artifact) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + final String ownerid = user.identifier(); + + createCollectionService.create( + locale, + ownerid, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create the new collection."); + SC.warn(messages.getString(caught.getMessage())); + } + + @Override + public void onSuccess(Collection collection) { + GWT.log("Successfully created a new collection."); + addArtifactToClonedCollection(artifact, collection); + } + } + ); + } + + + private void addArtifactToClonedCollection(Artifact a, Collection c) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + addArtifactService.add( + c, a, locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("An error occured while adding artifact."); + SC.warn(messages.getString(caught.getMessage())); + } + + @Override + public void onSuccess(Collection newColl) { + String name = cloneCollection.getName(); + if(name == null || name.equals("")) { + name = cloneCollection.identifier(); + } + + String colname = messages.copy_of() + ": " + name; + + updateCollectionName(newColl, colname); + if(cloneCollection.getTTL() == 0) { + newColl.setTTL(0); + updateCollectionTTL(newColl); + } + } + } + ); + } + + + @Override + public void onVisibilityChanged(VisibilityChangedEvent event) { + if (event.getIsVisible()) { + this.flys.hideHeaderProjectButton(); + } + else { + this.flys.shoHeaderProjectButton(); + } + } + + private void setFilter(String filter) { + this.filter = filter; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/PropertyEditor.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.ui; + +import java.io.Serializable; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface PropertyEditor extends Serializable { + + String getI18NString(String name); + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/QSegmentedInputPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,490 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.TitleOrientation; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.WQInfoService; +import de.intevation.flys.client.client.services.WQInfoServiceAsync; +import de.intevation.flys.client.client.ui.wq.QDTable; +import de.intevation.flys.client.client.ui.wq.WTable; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.WQDataItem; +import de.intevation.flys.client.shared.model.WQInfoObject; +import de.intevation.flys.client.shared.model.WQInfoRecord; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + + +/** + * This UIProvider creates a widget to enter Q values per segment. + */ +public class QSegmentedInputPanel +extends AbstractUIProvider +implements ChangeHandler, BlurHandler +{ + + private static final long serialVersionUID = -8627825064071479905L; + + public static final String FIELD_WQ_MODE = "wq_isq"; + public static final String FIELD_WQ_Q = "Q"; + + public static final String GAUGE_SEPARATOR = ":"; + + public static final String GAUGE_PART_SEPARATOR = ";"; + + public static final String VALUE_SEPARATOR = ","; + + public static final int ROW_HEIGHT = 20; + + /** The constant field name for choosing single values or range.*/ + public static final String FIELD_MODE = "mode"; + + /** The constant field value for range input mode.*/ + public static final String FIELD_MODE_RANGE = "range"; + + protected WQInfoServiceAsync wqInfoService = + GWT.create(WQInfoService.class); + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** Stores the input panels related to their keys.*/ + protected Map<String, DoubleArrayPanel> wqranges; + + /** Stores the min/max values for each q range.*/ + protected Map<String, double[]> qranges; + + protected QDTable qdTable; + + protected WTable wTable; + + protected TabSet tabs; + + + public QSegmentedInputPanel() { + wqranges = new HashMap<String, DoubleArrayPanel>(); + qranges = new HashMap<String, double[]>(); + qdTable = new QDTable(); + wTable = new WTable(); + } + + + /** Create main UI Canvas. */ + @Override + public Canvas create(DataList data) { + initHelperPanel(); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(data); + Label label = new Label(MSG.wqadaptedTitle()); + + label.setHeight(25); + + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + layout.setWidth(350); + + layout.addMember(label); + layout.addMember(widget); + layout.addMember(submit); + + return layout; + } + + + protected void initHelperPanel() { + tabs = new TabSet(); + tabs.setWidth100(); + tabs.setHeight100(); + + // TODO i18n + Tab qTab = new Tab("Q / D"); + + qTab.setPane(qdTable); + qdTable.hideIconFields(); + + tabs.addTab(qTab, 1); + + helperContainer.addMember(tabs); + + // TODO Q only would suffice. + fetchWQData(); + } + + + /** Create display for passive mode. */ + @Override + public Canvas createOld(DataList dataList) { + List<Data> all = dataList.getAll(); + Data wqData = getData(all, "ranges"); + + Canvas back = getBackButton(dataList.getState()); + + HLayout valLayout = new HLayout(); + VLayout vlayout = new VLayout(); + Label wqLabel = new Label(dataList.getLabel()); + + wqLabel.setValign(VerticalAlignment.TOP); + + wqLabel.setWidth(200); + wqLabel.setHeight(25); + + valLayout.addMember(wqLabel); + valLayout.addMember(createOldWQValues(wqData)); + valLayout.addMember(back); + + vlayout.addMember(valLayout); + + return vlayout; + } + + + /** Create canvas showing previously entered values. */ + protected Canvas createOldWQValues(Data wqData) { + VLayout layout = new VLayout(); + + //TODO: Sort by first field, numerically. + + DataItem item = wqData.getItems()[0]; + String value = item.getStringValue(); + + String[] gauges = value.split(GAUGE_SEPARATOR); + + for (String gauge: gauges) { + HLayout h = new HLayout(); + + String[] parts = gauge.split(GAUGE_PART_SEPARATOR); + String[] values = parts[3].split(VALUE_SEPARATOR); + + Label l = new Label(parts[0] + " - " + parts[1] + ": "); + + StringBuilder sb = new StringBuilder(); + boolean first = true; + + for (String v: values) { + if (!first) { + sb.append(", "); + } + + sb.append(v); + + first = false; + } + + Label v = new Label(sb.toString()); + + l.setWidth(65); + v.setWidth(65); + + h.addMember(l); + h.addMember(v); + + layout.addMember(h); + } + + return layout; + } + + + protected Canvas createWidget(DataList dataList) { + VLayout layout = new VLayout(); + + Canvas list = createList(dataList); + + DataItem[] items = getWQItems(dataList); + int listHeight = ROW_HEIGHT * items.length; + + layout.addMember(list); + + layout.setHeight(25 + listHeight); + layout.setWidth(350); + + return layout; + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + Iterator<String> iter = wqranges.keySet().iterator(); + + while (iter.hasNext()) { + List<String> tmpErrors = new ArrayList<String>(); + + String key = iter.next(); + DoubleArrayPanel dap = wqranges.get(key); + + if (!dap.validateForm()) { + errors.add(MSG.error_invalid_double_value()); + return errors; + } + + double[] mm = qranges.get(key); + if (mm == null) { + SC.warn(MSG.error_read_minmax_values()); + continue; + } + + double[] values = dap.getInputValues(); + // might geht npe here if one field not filled + double[] good = new double[values.length]; + + int idx = 0; + + for (double value: values) { + if (value < mm[0] || value > mm[1]) { + String tmp = MSG.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(mm[0])); + tmp = tmp.replace("$3", nf.format(mm[1])); + tmpErrors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!tmpErrors.isEmpty()) { + dap.setValues(justGood); + + errors.addAll(tmpErrors); + } + } + + return errors; + } + + + protected Canvas createList(DataList dataList) { + VLayout layout = new VLayout(); + + DataItem[] items = getWQItems(dataList); + + for (DataItem item: items) { + String title = item.getLabel(); + + DoubleArrayPanel dap = new DoubleArrayPanel( + createLineTitle(title), null, this, null, TitleOrientation.LEFT); + + wqranges.put(title, dap); + + if (item instanceof WQDataItem) { + WQDataItem wq = (WQDataItem) item; + double[] mmQ = wq.getQRange(); + + qranges.put(title, mmQ); + } + + layout.addMember(dap); + } + + layout.setHeight(items.length * ROW_HEIGHT); + + return layout; + } + + + protected DataItem[] getWQItems(DataList dataList) { + List<Data> data = dataList.getAll(); + + for (Data d: data) { + String name = d.getLabel(); + + // TODO to be gone + if (name.equals(FIELD_WQ_MODE)) { + continue; + } + + return d.getItems(); + } + + return null; + } + + + + public String createLineTitle(String key) { + String[] splitted = key.split(";"); + + return splitted[0] + " - " + splitted[1]; + } + + + @Override + public Data[] getData() { + Data values = getWQValues(); + + return new Data[] { values }; + } + + + protected Data getWQValues() { + String wqvalue = null; + + Iterator<String> iter = wqranges.keySet().iterator(); + while (iter.hasNext()) { + String key = iter.next(); + DoubleArrayPanel dap = wqranges.get(key); + + double[] values = dap.getInputValues(); + if (wqvalue == null) { + wqvalue = createValueString(key + "; ", values); + } + else { + wqvalue += GAUGE_SEPARATOR + createValueString(key + "; ", values); + } + } + + // TODO probably ranges + DataItem valueItem = new DefaultDataItem( + "ranges", "ranges", wqvalue); + Data values = new DefaultData( + "ranges", null, null, new DataItem[] { valueItem }); + + return values; + } + + + protected String createValueString(String key, double[] values) { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + + for (double value: values) { + if (!first) { + sb.append(","); + } + + sb.append(Double.toString(value)); + + first = false; + } + + return key + ";" + sb.toString(); + } + + + @Override + public void onChange(ChangeEvent event) { + // TODO IMPLEMENT ME + } + + + @Override + public void onBlur(BlurEvent event) { + DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); + dap.validateForm(event.getItem()); + } + + + protected void fetchWQData() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + double[] mm = getMinMaxKM(data); + String river = getRiverName(data); + + wqInfoService.getWQInfo(locale, river, mm[0], mm[0], + new AsyncCallback<WQInfoObject[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve wq informations."); + SC.warn(caught.getMessage()); + } + + @Override + public void onSuccess(WQInfoObject[] wqi) { + int num = wqi != null ? wqi.length :0; + GWT.log("Recieved " + num + " wq informations."); + + if (num == 0) { + return; + } + + addWQInfo(wqi); + + } + } + ); + } + + + protected void addWQInfo (WQInfoObject[] wqi) { + for(WQInfoObject wi: wqi) { + WQInfoRecord rec = new WQInfoRecord(wi); + + if (wi.getType().equals("W")) { + wTable.addData(rec); + } + else { + qdTable.addData(rec); + } + } + } + + + /** + * Determines the min and max kilometer value selected in a former state. A + * bit silly, but we need to run over each value of the "old data" to find + * such values because it is not available here. + * + * @param data The DataList which contains the whole data inserted for the + * current artifact. + * + * @return a double array with [min, max]. + */ + protected double[] getMinMaxKM(DataList[] data) { + ArtifactDescription adesc = artifact.getArtifactDescription(); + return adesc.getKMRange(); + } + + + /** + * Returns the name of the selected river. + * + * @param data The DataList with all data. + * + * @return the name of the current river. + */ + protected String getRiverName(DataList[] data) { + ArtifactDescription adesc = artifact.getArtifactDescription(); + return adesc.getRiver(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/RadioPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,94 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.RadioGroupItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.LinkedHashMap; + +public class RadioPanel extends AbstractUIProvider { + + private static final long serialVersionUID = 3357071563224461043L; + + protected String dataName; + protected DynamicForm form; + + @Override + public Canvas createOld(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + HLayout layout = new HLayout(); + Label label = new Label(dataList.getLabel()); + Label value = new Label(items[0].getLabel()); + + layout.setHeight(35); + layout.setWidth(400); + label.setWidth(200); + + layout.addMember(label); + layout.addMember(value); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + @Override + public Canvas create(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + this.dataName = data.getLabel(); + + VLayout layout = new VLayout(); + Label label = new Label(data.getDescription()); + RadioGroupItem rgi = new RadioGroupItem("selection"); + rgi.setShowTitle(false); + GWT.log("items: " + items.length); + LinkedHashMap<String, String> elems = new LinkedHashMap<String, String>(); + for (int i = 0; i < items.length; i++) { + GWT.log(items[i].getStringValue() + "; " + items[i].getLabel()); + elems.put(items[i].getStringValue(), items[i].getLabel()); + } + rgi.setValueMap(elems); + rgi.setDefaultValue(items[0].getStringValue()); + + form = new DynamicForm(); + form.setFields(rgi); + layout.setMembersMargin(10); + layout.setHeight(35); + label.setHeight(35); + + layout.addMember(label); + layout.addMember(form); + layout.addMember(getNextButton()); + layout.setMembersMargin(10); + + //initDefaultValues(dataList); + + return layout; + } + + @Override + protected Data[] getData() { + String value = form.getValueAsString("selection"); + DataItem item = new DefaultDataItem(this.dataName, this.dataName, value); + return new Data[] { new DefaultData( + this.dataName, null, null, new DataItem[]{item})}; + } + + protected String getTitle(DataItem item) { + return item.getLabel(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/RangePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,282 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.validator.Validator; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.RangeData; + +import java.util.ArrayList; +import java.util.List; + + +/** + * An UIProvider for inserting ranges. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public abstract class RangePanel extends AbstractUIProvider { + + private static final long serialVersionUID = -9213089589150335651L; + + public static final String FIELD_LOWER = "field_lower"; + public static final String FIELD_UPPER = "field_upper"; + + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected DynamicForm lowerForm; + protected DynamicForm upperForm; + + protected String dataName; + + + public abstract Object getMaxLower(); + + public abstract Object getMaxUpper(); + + + + @Override + public Canvas create(DataList data) { + setDataName(data); + + VLayout root = new VLayout(); + + root.addMember(createLabel(data)); + root.addMember(createForm(data)); + root.addMember(getNextButton()); + + initDefaults(data); + + return root; + } + + + @Override + public Canvas createOld(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + HLayout layout = new HLayout(); + + Label label = new Label(dataList.getLabel()); + label.setWidth(200); + label.setHeight(20); + + Label value = new Label(items[0].getLabel()); + value.setHeight(20); + + layout.addMember(label); + layout.addMember(value); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + + if (!lowerForm.validate()) { + String msg = MSG.error_validate_range(); + msg = msg.replace("$1", getLower()); + msg = msg.replace("$2", String.valueOf(getMaxLower())); + msg = msg.replace("$3", String.valueOf(getMaxLower())); + errors.add(msg); + } + + if (!upperForm.validate()) { + String msg = MSG.error_validate_range(); + msg = msg.replace("$1", getUpper()); + msg = msg.replace("$2", String.valueOf(getMaxLower())); + msg = msg.replace("$3", String.valueOf(getMaxUpper())); + errors.add(msg); + } + + return errors; + } + + + @Override + protected Data[] getData() { + return new Data[0]; + } + + + protected void initDefaults(DataList dataList) { + RangeData data = findRangeData(dataList); + + if (data != null) { + setLower(String.valueOf(data.getDefaultLower())); + setUpper(String.valueOf(data.getDefaultUpper())); + } + } + + + protected RangeData findRangeData(DataList dataList) { + for (int i = 0, n = dataList.size(); i < n; i++) { + Data tmp = dataList.get(i); + + if (tmp instanceof RangeData) { + return (RangeData) tmp; + } + } + return null; + } + + + protected void setDataName(DataList dataList) { + Data data = dataList.get(0); + + this.dataName = data.getLabel(); + } + + + public String getDataName() { + return dataName; + } + + + public String getLower() { + return lowerForm.getValueAsString(FIELD_LOWER); + } + + + public void setLower(String lower) { + lowerForm.setValue(FIELD_LOWER, lower); + } + + + public String getUpper() { + return upperForm.getValueAsString(FIELD_UPPER); + } + + + public void setUpper(String upper) { + upperForm.setValue(FIELD_UPPER, upper); + } + + + protected Canvas createLabel(DataList dataList) { + RangeData rangeData = findRangeData(dataList); + + if (rangeData == null) { + return new Canvas(); + } + + Label label = new Label(rangeData.getDescription()); + + label.setWidth100(); + label.setHeight(25); + + return label; + } + + + protected Canvas createForm(DataList dataList) { + lowerForm = createLowerForm(dataList); + upperForm = createUpperForm(dataList); + + HLayout formLayout = new HLayout(); + formLayout.addMember(lowerForm); + formLayout.addMember(createSpacer()); + formLayout.addMember(upperForm); + + return formLayout; + } + + + protected DynamicForm newForm() { + DynamicForm form = new DynamicForm(); + form.setTitlePrefix(""); + form.setTitleSuffix(""); + form.setTitle(""); + form.setTitleField(""); + + return form; + } + + + protected FormItem newFormItem(String name) { + TextItem item = new TextItem(name, ""); + item.setShowTitle(false); + + return item; + } + + + protected DynamicForm createLowerForm(DataList dataList) { + DynamicForm lowerForm = newForm(); + FormItem lower = createLowerField(dataList); + + lowerForm.setFields(lower); + + return lowerForm; + } + + + protected DynamicForm createUpperForm(DataList dataList) { + DynamicForm upperForm = newForm(); + FormItem upper = createUpperField(dataList); + + upperForm.setFields(upper); + + return upperForm; + } + + + protected Canvas createSpacer() { + Label spacer = new Label("-"); + spacer.setWidth(25); + spacer.setHeight(25); + spacer.setAlign(Alignment.CENTER); + + return spacer; + } + + + protected FormItem createLowerField(DataList dataList) { + return createField(FIELD_LOWER, createLowerValidators(dataList)); + } + + + protected FormItem createUpperField(DataList dataList) { + return createField(FIELD_UPPER, createUpperValidators(dataList)); + } + + + protected FormItem createField(String name, Validator[] validators) { + FormItem field = newFormItem(name); + + if (validators != null && validators.length > 0) { + field.setValidators(validators); + } + + return field; + } + + + protected Validator[] createLowerValidators(DataList dataList) { + return null; + } + + + protected Validator[] createUpperValidators(DataList dataList) { + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/RangeTableFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,136 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent; +import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.FilterHandler; +import de.intevation.flys.client.client.event.RangeFilterEvent; +import de.intevation.flys.client.client.utils.DoubleValidator; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class RangeTableFilter +extends HLayout +implements ChangedHandler, KeyUpHandler +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected List<FilterHandler> handlers; + + protected TextItem fromField; + protected TextItem toField; + protected DynamicForm filterForm; + + public RangeTableFilter() { + super(); + fromField = new TextItem(); + fromField.setTitle(MESSAGES.from()); + fromField.setWidth(60); + toField = new TextItem(); + toField.setTitle(MESSAGES.to()); + toField.setWidth(60); + + + handlers = new ArrayList<FilterHandler>(); + + fromField.addChangedHandler(this); + fromField.addKeyUpHandler(this); + toField.addChangedHandler(this); + toField.addKeyUpHandler(this); + + filterForm = new DynamicForm(); + filterForm.setNumCols(4); + filterForm.setFields(fromField, toField); + + addMember(filterForm); + } + + + @Override + public void onChanged(ChangedEvent event) { + // This event handler is to slow... +// fireFilterCriteriaChanged(getSearchString()); + } + + + @Override + public void onKeyUp(KeyUpEvent event) { + DoubleValidator validator = new DoubleValidator(); + Map<?,?> errors = filterForm.getErrors(); + if(event.getItem().getValue() != null && + !validator.validate(event.getItem(), errors)) { + filterForm.setErrors(errors, true); + GWT.log("no valid input!"); + return; + } + else { + errors.clear(); + filterForm.setErrors(errors, true); + } + //To deactivate "As you type" filter add + // ' && event.getKeyName().equals("Enter")' + // to the if-clause. + if (event != null) { + fireFilterCriteriaChanged(getFrom(), getTo()); + } + } + + + public String getFrom() { + if (fromField.getValueAsString() == null) { + return ""; + } + else { + return fromField.getValueAsString(); + } + } + + + public String getTo() { + if (toField.getValueAsString() == null) { + return ""; + } + else { + return toField.getValueAsString(); + } + } + + + public void addFilterHandler(FilterHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + protected void fireFilterCriteriaChanged(String from, String to) { + RangeFilterEvent filter = new RangeFilterEvent(from, to); + + for (FilterHandler handler: handlers) { + handler.onFilterCriteriaChanged(filter); + } + } + + + @Override + public void clear() { + fromField.clearValue(); + toField.clearValue(); + fireFilterCriteriaChanged("", ""); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/RecommendationPairRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,129 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import de.intevation.flys.client.shared.model.Recommendation; + + +/** + * Two strings to be displayed in a GridList, derived from two + * Recommendations. + */ +public class RecommendationPairRecord extends ListGridRecord { + + /** First attribute-name for StringPairRecord. */ + protected static final String ATTRIBUTE_FIRST = "first"; + + /** Second attribute-name for StringPairRecord. */ + protected static final String ATTRIBUTE_SECOND = "second"; + + /** The "first" recommendation (typically the minuend). */ + Recommendation first; + + /** The "second" recommendation (typically the subtrahend). */ + Recommendation second; + + /** + * Whether the RecommendationPairRecord was restored from data and thus + * already loaded (usually cloned) in an ArtifactCollection or not. + */ + boolean alreadyLoaded; + + + /** Trivial, blocked constructor. */ + @SuppressWarnings("unused") + private RecommendationPairRecord() { + } + + + /** + * Create a new RecommendationPairRecord. + * + * @param first The first recommendation (typically the minuend). + * @param second The second recommendation (typically the subtrahend). + */ + public RecommendationPairRecord( + Recommendation first, + Recommendation second) + { + setFirst(first); + setSecond(second); + alreadyLoaded = false; + } + + + /** + * Sets the first recommendation with info (minuend). + * @param first Recommendation to store. + */ + public void setFirst(Recommendation first) { + this.first = first; + setAttribute(ATTRIBUTE_FIRST, first.getDisplayName()); + } + + + /** + * Sets the second recommendation with info (subtrahend). + * @param second Recommendation to store. + */ + public void setSecond(Recommendation second) { + this.second = second; + setAttribute(ATTRIBUTE_SECOND, second.getDisplayName()); + } + + + /** + * Get first recommendation (typically the minuend). + * @return first recommendation (typically the minuend). + */ + public Recommendation getFirst() { + return first; + } + + + /** + * Get second recommendation (typically the subtrahend). + * @return second recommendation (typically the subtrahend). + */ + public Recommendation getSecond() { + return second; + } + + + /** + * Get name of first recommendation (typically the minuend). + * @return name of first recommendation (typically the minuend). + */ + public String getFirstName() { + return first.getDisplayName(); + } + + + /** + * Get name of second recommendation (typically the subtrahend). + * @return name of second recommendation (typically the subtrahend). + */ + public String getSecondName() { + return second.getDisplayName(); + } + + + /** + * Sets whether or not the Recommendation is already loaded (in contrast + * to not yet loaded). + * @param isAlreadyLoaded new value. + */ + public void setIsAlreadyLoaded(boolean isAlreadyLoaded) { + this.alreadyLoaded = isAlreadyLoaded; + } + + + /** + * Whether or not this pair of recommendations is already laoded (usually + * cloned) in an ArtifactCollection. + * @return whether pair of recommendations is already loaded. + */ + public boolean isAlreadyLoaded() { + return this.alreadyLoaded; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/RiverInfoPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,115 @@ +package de.intevation.flys.client.client.ui; + +import java.util.Iterator; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.ui.Anchor; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.Widget; + +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.shared.model.RiverInfo; + +/** + * Panel to display information about a river. + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class RiverInfoPanel extends HorizontalPanel { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public final static int HEIGHT = 30; + public final static int BORDER_WIDTH = 3; + public final static int PADDING = 8; + public final static int MARGIN = 10; + + public RiverInfoPanel(RiverInfo riverinfo) { + setStyleName("riverinfopanel"); + setHeight("" + HEIGHT + "px"); + setVerticalAlignment(ALIGN_MIDDLE); + + setRiverInfo(riverinfo); + } + + public void setRiverInfo(RiverInfo riverinfo) { + GWT.log("RiverInfoPanel - setRiverInfo"); + + NumberFormat nf = NumberFormat.getDecimalFormat(); + + removeAllLabels(); + + addLabel(riverinfo.getName(), false); + + String kmtext = ""; + Double start = riverinfo.getKmStart(); + Double end = riverinfo.getKmEnd(); + + if (!riverinfo.isKmUp()) { + Double tmp = end; + end = start; + start = tmp; + } + if (end != null) { + kmtext += nf.format(end); + kmtext += " - "; + } + if (start != null) { + kmtext += nf.format(start); + } + kmtext += " km"; + + addLabel(kmtext, false); + + String qtext = ""; + Double qmin = riverinfo.getMinQ(); + Double qmax = riverinfo.getMaxQ(); + if (qmin != null) { + qtext += nf.format(qmin); + qtext += " " + MSG.gauge_q_unit(); + qtext += " - "; + } + if (qmax != null) { + qtext += nf.format(qmax); + qtext += " " + MSG.gauge_q_unit(); + } + + addLabel(qtext, false); + + Long number = riverinfo.getOfficialNumber(); + String url = number != null ? + MSG.gauge_river_url() + number : + MSG.gauge_river_url(); + Anchor anchor = new Anchor(MSG.gauge_river_info_link(), url, "_blank"); + add(anchor); + } + + public static int getStaticHeight() { + return RiverInfoPanel.HEIGHT + + (2 * RiverInfoPanel.BORDER_WIDTH) + + (2 * RiverInfoPanel.PADDING) + + (2 * RiverInfoPanel.MARGIN); + } + + private void addLabel(String text, boolean wordwrap) { + Label label = new Label(text, wordwrap); + add(label); + setCellHeight(label, "" + HEIGHT + "px"); + } + + private void removeAllLabels() { + GWT.log("RiverInfoPanel - removeAllLabels"); + + Iterator<Widget> it = this.iterator(); + while(it.hasNext()) { + it.next(); + it.remove(); + } + /* for (Widget wid: this) { */ + /* this.remove(wid); */ + /* } */ + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ScreenLock.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,55 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.Layout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; + +/** Basic static functionality to show spinning wheel. */ +public class ScreenLock { + + /** The message class that provides i18n strings. */ + protected static FLYSConstants messages = GWT.create(FLYSConstants.class); + + /** Disables input, grey out, show spinning wheel of joy. */ + public static VLayout lockUI(Layout layout, VLayout lockScreen) { + if (lockScreen == null) { + lockScreen = new VLayout(); + lockScreen.setWidth100(); + lockScreen.setHeight100(); + lockScreen.setBackgroundColor("#7f7f7f"); + lockScreen.setOpacity(50); + lockScreen.setAlign(VerticalAlignment.CENTER); + lockScreen.setDefaultLayoutAlign(VerticalAlignment.CENTER); + + HLayout inner = new HLayout(); + inner.setAlign(Alignment.CENTER); + inner.setDefaultLayoutAlign(Alignment.CENTER); + inner.setOpacity(100); + + Img img = new Img( + GWT.getHostPageBaseURL() + messages.loadingImg(), + 25, 25); + + inner.addMember(img); + + lockScreen.addMember(inner); + } + + layout.addChild(lockScreen); + return lockScreen; + } + + /** Enable input, remove grey, remove spinning wheel of joy. */ + public static void unlockUI(Layout layout, VLayout lockScreen) { + layout.removeChild(lockScreen); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/SelectProvider.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,273 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.LinkItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.SpacerItem; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.StepForwardEvent; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + + +/** + * This UIProvider displays the DataItems of the Data object in a combo box. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class SelectProvider +extends AbstractUIProvider +{ + private static final long serialVersionUID = 4696637534424070726L; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants messages = GWT.create(FLYSConstants.class); + + /** The combobox.*/ + protected DynamicForm form = new DynamicForm(); + + public static final int COMBOBOX_THRESHOLD = 20; + + + /** + * This method currently returns a + * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all + * data items in a combobox stored in <i>data</i>. + * + * @param data The {@link Data} object. + * + * @return a combobox. + */ + @Override + public Canvas create(DataList data) { + VLayout v = new VLayout(); + v.setMembersMargin(10); + v.addMember(createWidget(data)); + if(data.size() > COMBOBOX_THRESHOLD) { + v.addMember(getNextButton()); + } + return v; + } + + + protected Canvas createWidget(DataList data) { + if (data.size() > COMBOBOX_THRESHOLD) { + return createComboboxWidget(data); + } + else { + return createListWidget(data); + } + } + + + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + VLayout vLayout = new VLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + int size = dataList.size(); + for (int i = 0; i < size; i++) { + Data data = dataList.get(i); + DataItem[] items = data.getItems(); + + for (DataItem item: items) { + HLayout hLayout = new HLayout(); + + hLayout.addMember(label); + hLayout.addMember(new Label(item.getLabel())); + + vLayout.addMember(hLayout); + vLayout.setWidth("130px"); + } + } + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + + protected Canvas createListWidget(DataList data) { + VLayout layout = new VLayout(); + layout.setAlign(VerticalAlignment.TOP); + layout.setHeight(25); + layout.setWidth("100%"); + + VLayout formLayout = new VLayout(); + formLayout.setLayoutTopMargin(20); + formLayout.setLayoutLeftMargin(50); + + ClickHandler handler = new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + LinkItem li = (LinkItem)event.getItem(); + String attr = li.getAttribute(li.getName()); + GWT.log("li.getTarget: " + attr + " " + li.getName()); + DataItem item = new DefaultDataItem( + attr, + null, + attr); + + Data d = new DefaultData( + li.getName(), + null, + null, + new DataItem [] { item }); + + Data [] odata = getData(); + Data [] ndata = new Data[odata.length+1]; + System.arraycopy(odata, 0, ndata, 0, odata.length); + ndata[odata.length] = d; + + fireStepForwardEvent(new StepForwardEvent(ndata)); + } + }; + + for (int i = 0, size = data.size(); i < size; i++) { + Data d = data.get(i); + + Label label = new Label(d.getDescription()); + label.setValign(VerticalAlignment.TOP); + label.setHeight(20); + label.setWidth(400); + + LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); + ArrayList<FormItem> formItems = new ArrayList<FormItem>(); + + for (DataItem item: d.getItems()) { + initial.put(item.getLabel().replace(' ', '_'), item.getStringValue()); + GWT.log("put: " + item.getLabel().replace(' ', '_') + "=" + item.getStringValue()); + + LinkItem link = new LinkItem(d.getLabel()); + link.setLinkTitle(item.getLabel()); // i18n text of the link + link.setAttribute(d.getLabel(), item.getStringValue()); // e.g. "calculation_mode":"foo" + link.setShowTitle(false); + link.setEndRow(true); + link.setWidth("350px"); + + SpacerItem space = new SpacerItem(); + space.setWidth(15); + formItems.add(space); + formItems.add(link); + + link.addClickHandler(handler); + } + + form.setFields(formItems.toArray(new FormItem[0])); + form.setValues(initial); + + layout.addMember(label); + layout.addMember(form); + } + return layout; + } + + protected Canvas createComboboxWidget(DataList data) { + GWT.log("SelectProvider.createComboboxWidget()"); + + VLayout layout = new VLayout(); + layout.setAlign(VerticalAlignment.TOP); + layout.setHeight(25); + + LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); + + int size = data.size(); + + for (int i = 0; i < size; i++) { + Data d = data.get(i); + + Label label = new Label(d.getDescription()); + label.setValign(VerticalAlignment.TOP); + label.setHeight(20); + label.setWidth(400); + + SelectItem combobox = new SelectItem(d.getLabel()); + combobox.setWidth(250); + + LinkedHashMap<String, String> it = new LinkedHashMap<String, String>(); + + boolean defaultSet = false; + boolean first = true; + + DataItem def = d.getDefault(); + String defValue = def != null ? def.getStringValue() : null; + + if (defValue != null && defValue.length() > 0) { + initial.put(d.getLabel(), def.getStringValue()); + defaultSet = true; + } + + for (DataItem item: d.getItems()) { + if (!defaultSet && first) { + initial.put(d.getLabel(), item.getStringValue()); + first = false; + } + + it.put(item.getStringValue(), item.getLabel()); + } + + label.setWidth(50); + combobox.setValueMap(it); + combobox.setShowTitle(false); + form.setItems(combobox); + + layout.addMember(label); + layout.addMember(form); + } + + form.setValues(initial); + + layout.setAlign(VerticalAlignment.TOP); + + return layout; + } + + + @Override + protected Data[] getData() { + Map<?,?> values = form.getValues(); + Iterator<?> keys = values.keySet().iterator(); + + Data[] list = new Data[values.size()]; + int i = 0; + + while (keys.hasNext()) { + String fieldname = ((String) keys.next()).replace('_', ' '); + String selection = (String) values.get(fieldname); + + DataItem item = new DefaultDataItem(fieldname, null, selection); + + list[i++] = new DefaultData( + fieldname, null, null, new DataItem[] { item }); + } + + return list; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/SingleLocationPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,128 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.data.Record; + +import com.smartgwt.client.widgets.grid.events.CellClickEvent; + +import de.intevation.flys.client.shared.model.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * This UIProvider creates a widget to enter a single location (km). + */ +public class SingleLocationPanel +extends MultipleLocationPanel +{ + private static final long serialVersionUID = -300641333561787454L; + + + /** + * Creates a new SingleLocationPanel instance. + */ + public SingleLocationPanel() { + picker = new LocationPicker(this); + } + + + /** Overridden to restrict to one entered value. */ + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + saveLocationValues(locationPanel); + + if (!locationPanel.validateForm()) { + errors.add(MSG.wrongFormat()); + return errors; + } + + double[] values = getLocationValues(); + double[] good = new double[values.length]; + int idx = 0; + + // We want just one value to be allowed. + if (values.length > 1) { + errors.add(MSG.too_many_values()); + } + + for (double value: values) { + if (value < min || value > max) { + String tmp = MSG.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(min)); + tmp = tmp.replace("$3", nf.format(max)); + errors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!errors.isEmpty()) { + locationPanel.setValues(justGood); + } + + return errors; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + saveLocationValues(locationPanel); + double[] values = getLocationValues(); + Data[] data = new Data[values.length+1]; + + for (int i = 0; i < values.length; i++) { + data[i] = createDataArray(getDataItemName(), + Double.valueOf(values[i]).toString()); + } + + data[values.length] = createDataArray("ld_mode", "locations"); + + return data; + } + + + /* This is a copy of super.super.onRecordClick. Straighten out + this weird family. */ + /** + * Callback when an item from the input helper was clicked. + * Set the respective km-value in the location value field. + * @param e event passed. + */ + @Override + public void onCellClick (CellClickEvent e) { + Record record = e.getRecord(); + double[] selected = new double[1]; + try { + selected[0] = + Double.parseDouble(record.getAttribute("from")); + } + catch(NumberFormatException nfe) { + // Is there anything else to do here? + } + setLocationValues(selected); + } + + + @Override + protected String getLabelString() { + return MSG.single_location(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/StaticDataPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,68 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; + + +/** + * This UIProvider displays the old DataItems of GaugeDischargeCurveArtifact + * + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class StaticDataPanel +extends AbstractUIProvider +{ + private static final long serialVersionUID = 7411866539525588336L; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants messages = GWT.create(FLYSConstants.class); + + /** The combobox.*/ + protected DynamicForm form; + + @Override + public Canvas create(DataList data) { + VLayout layout = new VLayout(); + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + VLayout vLayout = new VLayout(); + vLayout.setWidth("400px"); + + int size = dataList.size(); + for (int i = 0; i < size; i++) { + Data data = dataList.get(i); + DataItem[] items = data.getItems(); + + for (DataItem item: items) { + HLayout hLayout = new HLayout(); + + hLayout.addMember(new Label(item.getLabel())); + hLayout.addMember(new Label(item.getStringValue())); + + vLayout.addMember(hLayout); + vLayout.setWidth("130px"); + } + } + + return vLayout; + } + + @Override + protected Data[] getData() { + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/StyleEditorWindow.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,700 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.events.ItemChangedEvent; +import com.smartgwt.client.widgets.form.events.ItemChangedHandler; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.ColorPickerItem; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.form.validator.IsFloatValidator; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.CollectionItemAttributeService; +import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; +import de.intevation.flys.client.client.services.ThemeListingService; +import de.intevation.flys.client.client.services.ThemeListingServiceAsync; +import de.intevation.flys.client.client.utils.DoubleValidator; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItemAttribute; +import de.intevation.flys.client.shared.model.FacetRecord; +import de.intevation.flys.client.shared.model.Style; +import de.intevation.flys.client.shared.model.StyleSetting; +import de.intevation.flys.client.shared.model.Theme; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +/** + * Editor window for styles. + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class StyleEditorWindow +extends Window +implements ClickHandler +{ + /** The interface that provides i18n messages. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** The collection. */ + protected Collection collection; + + /** The parent ThemePanel. */ + protected ThemePanel panel; + + /** The attributes. */ + protected CollectionItemAttribute attributes; + + /** The selected facet. */ + protected FacetRecord facet; + + /** Main layout. */ + protected VLayout layout; + + /** The form that contains all the input widgets. */ + protected DynamicForm df; + + protected VLayout properties; + + protected Canvas container; + + protected Map<String, Style> styleGroups; + + protected Style current; + + protected SelectItem styleChooser; + + /** The service used to set collection item attributes. */ + protected CollectionItemAttributeServiceAsync itemAttributeService = + GWT.create(CollectionItemAttributeService.class); + + /** The service used to request a list of themes. */ + protected ThemeListingServiceAsync themeListingService = + GWT.create(ThemeListingService.class); + + + /** + * Setup editor dialog. + * @param collection The collection the current theme belongs to. + * @param attributes The collection attributes. + * @param facet The selected facet. + */ + public StyleEditorWindow ( + Collection collection, + CollectionItemAttribute attributes, + FacetRecord facet) + { + this.collection = collection; + this.attributes = attributes; + this.facet = facet; + this.layout = new VLayout(); + this.properties = new VLayout(); + this.container = new Canvas(); + this.styleChooser = new SelectItem("style", "Style"); + + styleChooser.setTitleStyle("color:#000;"); + styleChooser.setTitleAlign(Alignment.LEFT); + styleChooser.setValue("aktuell"); + styleChooser.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent ce) { + String value = ce.getValue().toString(); + Style s = null; + if (value.equals("aktuell")) { + s = current; + } + else if (styleGroups.containsKey(value)) { + s = styleGroups.get(value); + } + + if (s != null) { + setNewStyle(s); + properties.removeMember(container); + container = createPropertyGrid(s); + properties.addMember(container); + } + } + }); + + DynamicForm f = new DynamicForm(); + f.setFields(styleChooser); + f.setColWidths("40%", "60%"); + + layout.addMember(f); + init(); + initPanels(); + } + + + /** + * Initialize the window and set the layout. + */ + protected void init() { + setTitle(MSG.properties()); + setCanDragReposition(true); + setCanDragResize(true); + layout.setMargin(10); + + layout.setWidth100(); + layout.setHeight100(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + Theme theme = facet.getTheme(); + Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); + if(style == null) { + GWT.log("StyleEditorWindow.init(): style == null"); + return; + } + String name = style.getName(); + this.current = style; + + themeListingService.list( + locale, + name, + new AsyncCallback<Map<String, Style> >() { + @Override + public void onFailure(Throwable caught) { + GWT.log("No listloaded."); + } + @Override + public void onSuccess(Map<String, Style> list) { + GWT.log("Successfully loaded list."); + + styleGroups = list; + Set<String> keys = list.keySet(); + LinkedHashMap<String, String> valueMap = + new LinkedHashMap<String, String>(); + valueMap.put("aktuell", "Aktuell"); + Iterator<String> iter = keys.iterator(); + while (iter.hasNext()) { + String s = iter.next().toString(); + Style tmp = styleGroups.get(s); + tmp.setFacet(current.getFacet()); + tmp.setIndex(current.getIndex()); + valueMap.put(s, s); + } + styleChooser.setValueMap(valueMap); + } + }); + } + + + /** + * Initialize the static window content like buttons and main layout. + */ + protected void initPanels() { + HLayout buttons = new HLayout(); + Button accept = new Button(MSG.label_ok()); + Button cancel = new Button(MSG.label_cancel()); + cancel.addClickHandler(this); + accept.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + // TODO Fix this, for whatever reason it doesnt work + // (always valid). + if (df == null) { + return; + } + if (!df.hasErrors() && df.validate()) { + saveStyle(); + } + } + }); + + buttons.addMember(accept); + buttons.addMember(cancel); + buttons.setAlign(Alignment.CENTER); + buttons.setHeight(30); + + Theme theme = facet.getTheme(); + Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); + + container = createPropertyGrid(style); + properties.addMember(container); + layout.addMember(properties); + layout.addMember(buttons); + addItem(layout); + setWidth(400); + setHeight(410); + } + + + /** + * Setter for the parent panel. + * @param panel The panel. + */ + public void setThemePanel (ThemePanel panel) { + this.panel = panel; + } + + + /** + * this method is called when the user aborts theming. + * @param event The event. + */ + @Override + public void onClick(ClickEvent event) { + this.hide(); + } + + + /** + * This method creates the property grid for available styling attributes. + * @return The layout containing the UI elements. + */ + protected VLayout createPropertyGrid(Style style) { + VLayout vl = new VLayout(); + + StaticTextItem name = new StaticTextItem("name", "Name"); + name.setValue(facet.getName()); + name.setTitleStyle("color:#000;"); + name.setTitleAlign(Alignment.LEFT); + name.setDisabled(true); + name.setShowDisabled(false); + + DynamicForm form = new DynamicForm(); + form.setFields(name); + form.setColWidths("40%", "60%"); + + + vl.addMember(form); + + if (style == null) { + SC.warn("No style found."); + return vl; + } + + // Done via array to keep the order. + String[] sets = {"showlines", + "showpoints", + "linetype", + "linesize", + "linecolor", + "font", + "textstyle", + "textsize", + "pointcolor", + "pointsize", + "showpointlabel", + "textcolor", + "backgroundcolor", + "showbackground", + "showlinelabel", + "labelfontface", + "labelfontcolor", + "labelfontsize", + "labelfontstyle", + "textorientation", + "labelshowbg", + "labelbgcolor", + "bandwidth", + "bandwidthcolor", + "transparency", + "showminimum", + "showmaximum"}; + + for (String settingName: sets) { + StyleSetting set = style.getSetting(settingName); + + if (set == null || set.isHidden()) { + continue; + } + + DynamicForm property = createPropertyUI( + set.getDisplayName(), + set.getName(), + set.getType(), + set.getDefaultValue()); + if (property != null) { + vl.addMember(property); + } + } + + // Add settings not in whitelist above. + for (StyleSetting set: style.getSettings()) { + + if (Arrays.asList(sets).contains(set.getName()) || + set == null || + set.isHidden() + ) { + continue; + } + + DynamicForm property = createPropertyUI( + set.getDisplayName(), + set.getName(), + set.getType(), + set.getDefaultValue()); + if (property != null) { + vl.addMember(property); + } + } + + return vl; + } + + + /** + * Create a property form. + * @param dname The display name. + * @param name The property name. + * @param type The property type. + * @param value The current value. + * + * @return The dynamic form for the attribute property. + */ + protected DynamicForm createPropertyUI( + String dname, + String name, + String type, + String value) + { + df = new DynamicForm(); + df.setColWidths("40%", "60%"); + + FormItem f; + if(type.equals("int")) { + f = new SelectItem(name, MSG.getString(name)); + if (name.equals("linesize")) { + f = createLineSizeUI(f); + f.setValue(value); + } + else if (name.equals("labelfontsize")) { + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("3", "3"); + valueMap.put("5", "5"); + valueMap.put("8", "8"); + valueMap.put("10", "10"); + valueMap.put("12", "12"); + valueMap.put("14", "14"); + valueMap.put("18", "18"); + valueMap.put("24", "24"); + f.setValueMap(valueMap); + f.setValue(value); + } + else if (name.equals("bandwidth")) { + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("0", "0"); + valueMap.put("1", "1"); + valueMap.put("2", "2"); + valueMap.put("3", "3"); + valueMap.put("4", "4"); + valueMap.put("5", "5"); + valueMap.put("6", "6"); + valueMap.put("7", "7"); + valueMap.put("8", "8"); + valueMap.put("9", "9"); + valueMap.put("10", "10"); + valueMap.put("11", "11"); + f.setValueMap(valueMap); + f.setValue(value); + } + else if (name.equals("pointsize")) { + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("1", "1"); + valueMap.put("2", "2"); + valueMap.put("3", "3"); + valueMap.put("4", "4"); + valueMap.put("5", "5"); + valueMap.put("6", "6"); + valueMap.put("7", "7"); + f.setValueMap(valueMap); + f.setValue(value); + } + else if (name.equals("numclasses")) { + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("5", "5"); + valueMap.put("6", "6"); + valueMap.put("7", "7"); + valueMap.put("8", "8"); + valueMap.put("9", "9"); + valueMap.put("10", "10"); + valueMap.put("12", "12"); + valueMap.put("14", "14"); + valueMap.put("16", "16"); + valueMap.put("18", "18"); + valueMap.put("20", "20"); + f.setValueMap(valueMap); + f.setValue(value); + // FIXME: Make that work again + return null; + } + else if (name.contains("transparency")) { + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + for (int n = 10; n < 100; n += 10) { + valueMap.put(Integer.toString(n), n + "%"); + } + f.setValueMap(valueMap); + f.setValue(value); + } + } + else if (type.equals("boolean")) { + if(name.equals("textorientation")) { + f = new SelectItem(name, MSG.getString(name)); + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("true", MSG.getString("horizontal")); + valueMap.put("false", MSG.getString("vertical")); + f.setValueMap(valueMap); + f.setValue(value); + } + else { + CheckboxItem c = new CheckboxItem(name, MSG.getString(name)); + if(value.equals("true")) { + c.setValue(true); + } + else { + c.setValue(false); + } + c.setLabelAsTitle(true); + f = c; + } + } + else if (type.equals("Color")) { + ColorPickerItem c = new ColorPickerItem(name, MSG.getString(name)); + c.setValue(rgbToHtml(value)); + f = c; + } + else if (type.equals("double")) { + f = new FormItem(name); + IsFloatValidator fpv = new IsFloatValidator(); + + f.setValidators(fpv); + f.setValidateOnChange(true); + f.setTitle(MSG.getString(name)); + f.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + DoubleValidator validator = new DoubleValidator(); + Map<?, ?> errors = e.getForm().getErrors(); + if(validator.validate(e.getItem(), errors)) { + e.getForm().setErrors(errors, true); + } + else { + e.getForm().setErrors(errors, true); + } + } + }); + f.setValue(value); + } + else if (type.equals("Dash")) { + f = new SelectItem(name, MSG.getString(name)); + LinkedHashMap<String, String> valueIcons = new LinkedHashMap<String, String>(); + f.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/linestyle-dash-"); + f.setImageURLSuffix(".png"); + f.setValueIconHeight(20); + f.setValueIconWidth(80); + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("10", ""); + valueMap.put("10,5", ""); + valueMap.put("20,10", ""); + valueMap.put("30,10", ""); + valueMap.put("20,5,15,5", ""); + valueIcons.put("10", "10"); + valueIcons.put("10,5", "10-5"); + valueIcons.put("20,10", "20-10"); + valueIcons.put("30,10", "30-10"); + valueIcons.put("20,5,15,5", "20-5-15-5"); + f.setValueIcons(valueIcons); + f.setValueMap(valueMap); + f.setValue(value); + } + else if (type.equals("Font")) { + f = new SelectItem(name, MSG.getString(name)); + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("arial", "<span style='font-family:arial'>Arial</span>"); + valueMap.put("courier", "<span style='font-family:courier'>Courier</span>"); + valueMap.put("verdana", "<span style='font-family:verdana'>Verdana</span>"); + valueMap.put("times", "<span style='font-family:times'>Times</span>"); + f.setValueMap(valueMap); + f.setValue(value); + } + else if (type.equals("Style")) { + f = new SelectItem(name, MSG.getString(name)); + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("standard", "<span style='font-style:normal'>Normal</span>"); + valueMap.put("bold", "<span style='font-weight:bold'>Bold</span>"); + valueMap.put("italic", "<span style='font-style:italic'>Italic</span>"); + f.setValueMap(valueMap); + f.setValue(value); + } + else if (type.equals("Symbol")) { + //create an empty element as long as this property can not be + //changed. + f = new StaticTextItem(""); + } + else { + f = new FormItem(); + } + f.setTitleStyle("color:#000;"); + f.setTitleAlign(Alignment.LEFT); + df.setFields(f); + df.addItemChangedHandler(new ItemChangedHandler() { + @Override + public void onItemChanged(ItemChangedEvent e) { + String name = e.getItem().getName(); + String newValue = e.getNewValue().toString(); + setNewValue(name, newValue); + } + }); + + return df; + } + + + protected FormItem createLineSizeUI(FormItem f) { + LinkedHashMap<String, String> valueIcons = new LinkedHashMap<String, String>(); + f.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/linestyle-"); + f.setImageURLSuffix("px.png"); + f.setValueIconHeight(20); + f.setValueIconWidth(80); + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + valueMap.put("1", ""); + valueMap.put("2", ""); + valueMap.put("3", ""); + valueMap.put("4", ""); + valueMap.put("5", ""); + valueMap.put("6", ""); + valueMap.put("7", ""); + valueMap.put("8", ""); + valueIcons.put("1", "1"); + valueIcons.put("2", "2"); + valueIcons.put("3", "3"); + valueIcons.put("4", "4"); + valueIcons.put("5", "5"); + valueIcons.put("6", "6"); + valueIcons.put("7", "7"); + valueIcons.put("8", "8"); + f.setValueIcons(valueIcons); + f.setValueMap(valueMap); + return f; + } + + + /** + * Static method to convert a color from RGB to HTML notation. + * @param rgb String in RGB notation. + * + * @return String in HTML notation. + */ + protected static String rgbToHtml(String rgb) { + String[] parts = rgb.split(","); + int values[] = new int[parts.length]; + for (int i = 0; i < parts.length; i++) { + parts[i] = parts[i].trim(); + try { + values[i] = Integer.parseInt(parts[i]); + } + catch(NumberFormatException nfe) { + return "#000000"; + } + } + String hex = "#"; + for (int i = 0; i < values.length; i++) { + if (values[i] < 16) { + hex += "0"; + } + hex += Integer.toHexString(values[i]); + } + return hex; + } + + + /** + * Static method to convert a color from HTML to RGB notation. + * @param html String in HTML notation. + * + * @return String in RGB notation. + */ + protected static String htmlToRgb(String html) { + if (!html.startsWith("#")) { + return "0, 0, 0"; + } + + int r = Integer.valueOf(html.substring(1, 3), 16); + int g = Integer.valueOf(html.substring(3, 5), 16); + int b = Integer.valueOf(html.substring(5, 7), 16); + + return r + ", " + g + ", " + b; + } + + + /** + * Saves the current style attributes and requests a redraw. + */ + protected void saveStyle () { + GWT.log("StyleEditorWindow.saveStyle()"); + Config config = Config.getInstance(); + String locale = config.getLocale(); + + itemAttributeService.setCollectionItemAttribute( + this.collection, + attributes.getArtifact(), + locale, + attributes, + new AsyncCallback<Void>() { + @Override + public void onFailure (Throwable caught) { + GWT.log("Could not set Collection item attributes."); + } + @Override + public void onSuccess(Void v) { + GWT.log("Successfully saved collection item attributes."); + panel.requestRedraw(); + } + }); + + + this.hide(); + } + + + /** + * Sets a new value for an attribute. + * @param name Attribute name. + * @param value The new value. + */ + protected final void setNewValue(String name, String value) { + Theme t = facet.getTheme(); + Style s = attributes.getStyle(t.getFacet(), t.getIndex()); + StyleSetting set = s.getSetting(name); + String type = set.getType(); + + if(name.indexOf("color") != -1 + || (type != null && type.toLowerCase().indexOf("color") > -1)) { + value = htmlToRgb(value); + } + set.setDefaultValue(value); + } + + + protected final void setNewStyle(Style style) { + Theme t = facet.getTheme(); + Style s = attributes.getStyle(t.getFacet(), t.getIndex()); + attributes.removeStyle(s.getName()); + attributes.appendStyle(style); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,166 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +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.Canvas; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.CSVExportService; +import de.intevation.flys.client.client.services.CSVExportServiceAsync; +import de.intevation.flys.client.shared.model.DataList; + +import java.util.List; + +/** + * This UIProvider creates a widget that displays calculated data in a table. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class TableDataPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected CSVExportServiceAsync exportService = + GWT.create(CSVExportService.class); + + /** A container that will contain the location or the distance panel. */ + protected VLayout container; + + /** The export type. */ + protected String name; + + /** The UUID of the collection. */ + protected String uuid; + + /** The table. */ + protected ListGrid dataTable; + + + /** + * Creates a new LocationDistancePanel instance. + */ + public TableDataPanel() { + container = new VLayout(); + dataTable = new ListGrid(); + name = ""; + } + + + /** + * This method creates a widget that contains a table. + * + * @return a panel. + */ + public Canvas create() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + dataTable.setEmptyMessage(MESSAGES.empty_table()); + dataTable.setShowHeaderContextMenu(false); + dataTable.setCanDragSelectText(true); + + exportService.getCSV(locale, uuid, name, + new AsyncCallback<List<String[]>>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve csv."); + SC.warn(caught.getMessage()); + } + + @Override + public void onSuccess(List<String[]> l) { + GWT.log("Recieved csv with " + l.size() + " lines."); + setData(l); + } + } + ); + + container.addMember(dataTable); + + return container; + } + + + public void setName(String name) { + this.name = name; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + + public Canvas createOld(DataList dataList) { + return null; + } + + + protected Canvas createWidget(DataList data) { + return null; + } + + + /** + * This method sets the data to a dynamic table. + * + * @param list List if String[] containing the data. + */ + public void setData(List<String[]> list) { + if (list == null || list.size() < 2) { + dataTable.setEmptyMessage(MESSAGES.error_no_calc_result()); + dataTable.redraw(); + return; + } + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + NumberFormat nf; + if (locale.equals("de")) { + nf = NumberFormat.getFormat("#,##"); + } + else { + nf = NumberFormat.getFormat("#.##"); + } + + String[] header = list.get(0); + String[] firstValues = list.get(1); + + ListGridField[] fields = new ListGridField[header.length]; + + for(int i = 0; i < header.length; i++) { + ListGridField f = new ListGridField(String.valueOf(i)); + fields[i] = f; + f.setTitle(header[i]); + + try { + nf.parse(firstValues[i]); + f.setType(ListGridFieldType.FLOAT); + } + catch (NumberFormatException nfe) { + f.setType(ListGridFieldType.TEXT); + } + } + + dataTable.setFields(fields); + + for(int i = 1; i < list.size(); i++) { + String[] sItem = list.get(i); + ListGridRecord r = new ListGridRecord(); + for(int j = 0; j < sItem.length; j++) { + r.setAttribute(String.valueOf(j), sItem[j]); + } + dataTable.addData(r); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/TableFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,99 @@ +package de.intevation.flys.client.client.ui; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent; +import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.event.FilterHandler; +import de.intevation.flys.client.client.event.StringFilterEvent; +import de.intevation.flys.client.client.FLYSConstants; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class TableFilter +extends HLayout +implements ChangedHandler, KeyUpHandler +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected List<FilterHandler> handlers; + + protected TextItem searchfield; + + + public TableFilter() { + super(); + searchfield = new TextItem(MESSAGES.search()); + handlers = new ArrayList<FilterHandler>(); + + searchfield.addChangedHandler(this); + searchfield.addKeyUpHandler(this); + searchfield.setWidth(120); + + DynamicForm form = new DynamicForm(); + form.setFields(searchfield); + + addMember(form); + } + + + public void onChanged(ChangedEvent event) { + // This event handler is to slow... +// fireFilterCriteriaChanged(getSearchString()); + } + + + public void onKeyUp(KeyUpEvent event) { + //To deactivate "As you type" filter add + // ' && event.getKeyName().equals("Enter")' + // to the if-clause. + if (event != null) { + fireFilterCriteriaChanged(getSearchString()); + } + } + + + public String getSearchString() { + if (searchfield.getValueAsString() == null) { + return ""; + } + else { + return searchfield.getValueAsString(); + } + } + + + public void addFilterHandler(FilterHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + protected void fireFilterCriteriaChanged(String searchstring) { + StringFilterEvent filter = new StringFilterEvent(searchstring); + + for (FilterHandler handler: handlers) { + handler.onFilterCriteriaChanged(filter); + } + } + + + public void clear() { + searchfield.clearValue(); + fireFilterCriteriaChanged(""); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/TextProvider.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,198 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.data.DataSource; +import com.smartgwt.client.data.DataSourceField; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.FieldType; +import com.smartgwt.client.types.TitleOrientation; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.events.ItemChangedEvent; +import com.smartgwt.client.widgets.form.events.ItemChangedHandler; +import com.smartgwt.client.widgets.form.validator.Validator; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.List; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class TextProvider +extends AbstractUIProvider +implements ItemChangedHandler +{ + private static final long serialVersionUID = -6868303464989138497L; + + public static final String FIELD_NAME = "textprovider_inputfield"; + public static final int FORM_WIDTH = 400; + public static final int TITLE_WIDTH = 75; + + + protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected DynamicForm form; + + + @Override + public Canvas create(DataList dataList) { + Canvas form = createForm(); + + initDefaultValues(dataList); + + return form; + } + + + protected Canvas createForm() { + return createForm(null); + } + + + protected Canvas createForm(String title) { + form = new DynamicForm(); + form.addItemChangedHandler(this); + form.setTitlePrefix(""); + form.setTitleSuffix(": "); + form.setTitleAlign(Alignment.LEFT); + form.setTitleOrientation(TitleOrientation.LEFT); + form.setTitleWidth(getTitleWidth()); + form.setWidth(getFormWidth()); + + DataSourceField item = createField(); + item.setTitle(title); + + Validator validator = getValidator(); + if (validator != null) { + item.setValidators(validator); + } + + DataSource source = new DataSource(); + source.setFields(item); + + form.setDataSource(source); + + return form; + } + + + protected void initDefaultValues(DataList dataList) { + Data data = dataList.get(0); + DataItem item = data.getDefault(); + + String value = item.getStringValue(); + + form.setValue(getFieldName(), value); + } + + + protected DataSourceField createField() { + return new DataSourceField(getFieldName(), getFieldType()); + } + + + /** + * Get field name. + * @return fields name (developer-centric). + */ + protected String getFieldName() { + return FIELD_NAME; + } + + + /** + * Get field type. + * @return fields type. + */ + protected FieldType getFieldType() { + return FieldType.TEXT; + } + + + protected Validator getValidator() { + return null; + } + + + protected int getFormWidth() { + return FORM_WIDTH; + } + + + protected int getTitleWidth() { + return TITLE_WIDTH; + } + + + /** @return null. */ + protected String getDataName() { + return null; + } + + + protected String getValueAsString() { + return (String) form.getValue(getFieldName()); + } + + + @Override + public Canvas createOld(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + HLayout layout = new HLayout(); + Label label = new Label(dataList.getLabel()); + Label value = new Label(items[0].getLabel()); + + layout.setHeight(35); + layout.setWidth(400); + label.setWidth(200); + + layout.addMember(label); + layout.addMember(value); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + + if (!form.validate()) { + errors.add(MSG.wrongFormat()); + } + + return errors; + } + + + @Override + protected Data[] getData() { + String value = getValueAsString(); + String name = getDataName(); + + DataItem item = new DefaultDataItem(name, name, value); + return new Data[] { new DefaultData( + name, null, null, new DataItem[] { item }) }; + } + + + @Override + public void onItemChanged(ItemChangedEvent event) { + form.validate(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ThemeNavigationPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,120 @@ +package de.intevation.flys.client.client.ui; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.ImgButton; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.OnMoveEvent; +import de.intevation.flys.client.client.event.OnMoveHandler; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ThemeNavigationPanel extends Canvas { + + public static final int PANEL_MARGIN = 5; + public static final int BUTTON_HEIGHT = 20; + public static final int BUTTON_MARGIN = 5; + private static final int BOTTON_WIDTH = 20; + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected List<OnMoveHandler> handlers; + + + public ThemeNavigationPanel() { + this.handlers = new ArrayList<OnMoveHandler>(); + + setWidth100(); + setHeight(BUTTON_HEIGHT); + setMargin(PANEL_MARGIN); + + HLayout layout = new HLayout(); + layout.setWidth100(); + layout.setHeight(BUTTON_HEIGHT); + layout.setMembersMargin(BUTTON_MARGIN); + layout.setDefaultLayoutAlign(VerticalAlignment.CENTER); + layout.setDefaultLayoutAlign(Alignment.CENTER); + + Canvas cu = createButton(MSG.theme_top(), OnMoveEvent.TOP); + Canvas u = createButton(MSG.theme_up(), OnMoveEvent.UP); + Canvas d = createButton(MSG.theme_down(), OnMoveEvent.DOWN); + Canvas cd = createButton(MSG.theme_bottom(), OnMoveEvent.BOTTOM); + + HLayout left = new HLayout(); + left.setMembersMargin(BUTTON_MARGIN); + left.setLayoutAlign(Alignment.LEFT); + left.setDefaultLayoutAlign(Alignment.LEFT); + left.setAlign(Alignment.LEFT); + left.addMember(cu); + left.addMember(u); + + HLayout right = new HLayout(); + right.setMembersMargin(BUTTON_MARGIN); + right.setLayoutAlign(Alignment.RIGHT); + right.setDefaultLayoutAlign(Alignment.RIGHT); + right.setAlign(Alignment.RIGHT); + right.addMember(d); + right.addMember(cd); + + layout.addMember(left); + layout.addMember(right); + + addChild(layout); + } + + + protected Canvas createButton(final String title, final int moveType) { + String url = GWT.getHostPageBaseURL() + title; + + ImgButton b = new ImgButton(); + b.setSrc(url); + b.setWidth(BOTTON_WIDTH); + b.setHeight(BUTTON_HEIGHT); + b.setIconHeight(BUTTON_HEIGHT); + b.setIconWidth(BOTTON_WIDTH); + b.setShowDown(false); + b.setShowRollOver(false); + b.setShowDisabled(false); + b.setShowDisabledIcon(true); + b.setShowDownIcon(false); + b.setShowFocusedIcon(false); + b.setValign(VerticalAlignment.CENTER); + + b.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + fireOnMoveEvent(moveType); + } + }); + + return b; + } + + + protected void addOnMoveHandler(OnMoveHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + protected void fireOnMoveEvent(int type) { + OnMoveEvent event = new OnMoveEvent(type); + + for (OnMoveHandler handler: handlers) { + handler.onMove(event); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/ThemePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,671 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.BooleanCallback; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; +import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; +import com.smartgwt.client.widgets.grid.events.RowContextClickEvent; +import com.smartgwt.client.widgets.grid.events.RowContextClickHandler; +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 de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.HasOutputParameterChangeHandlers; +import de.intevation.flys.client.client.event.HasRedrawRequestHandlers; +import de.intevation.flys.client.client.event.OnMoveEvent; +import de.intevation.flys.client.client.event.OnMoveHandler; +import de.intevation.flys.client.client.event.OutputParameterChangeEvent; +import de.intevation.flys.client.client.event.OutputParameterChangeHandler; +import de.intevation.flys.client.client.event.RedrawRequestEvent; +import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.services.CollectionAttributeService; +import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; +import de.intevation.flys.client.client.services.CollectionItemAttributeService; +import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItemAttribute; +import de.intevation.flys.client.shared.model.FacetRecord; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; + +import java.util.ArrayList; +import java.util.List; + +/** + * ThemePanel on the left in CollectionView. + * Contains control widgets for "themes", which are plotted in a diagram (chart). + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public abstract class ThemePanel +extends Canvas +implements OnMoveHandler, + EditCompleteHandler, + HasOutputParameterChangeHandlers, + HasRedrawRequestHandlers +{ + protected CollectionAttributeServiceAsync updater = + GWT.create(CollectionAttributeService.class); + + /** The service used to get collection item attributes. */ + protected CollectionItemAttributeServiceAsync itemAttributeService = + GWT.create(CollectionItemAttributeService.class); + + /** i18ner. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** List of OutParameterChangedHandler. */ + protected List<OutputParameterChangeHandler> outHandlers; + + /** List of ChartShallRedrawHandler. */ + protected List<RedrawRequestHandler> redrawRequestHandlers; + + protected OutputMode mode; + + protected ThemeNavigationPanel navigation; + protected ListGrid list; + + /** The collection view*/ + protected CollectionView view; + + /** + * Setup Grid, navigation bar. + * @param collection Collection for which to show themes. + */ + public ThemePanel( + OutputMode mode, + CollectionView view + ) { + this.mode = mode; + this.list = createGrid(); + this.view = view; + list.addRowContextClickHandler(new RowContextClickHandler() { + @Override + public void onRowContextClick(RowContextClickEvent event) { + ListGridRecord[] records = list.getSelectedRecords(); + + Menu menu = null; + + if (records == null || records.length == 0) { + return; + } + else if (records.length == 1) { + menu = getSingleContextMenu(records); + } + else if (records.length > 1) { + menu = getMultiContextMenu(records); + } + + if (menu != null) { + list.setContextMenu(menu); + menu.showContextMenu(); + + event.cancel(); + } + } + }); + + this.redrawRequestHandlers = new ArrayList<RedrawRequestHandler>(); + this.outHandlers = new ArrayList<OutputParameterChangeHandler>(); + this.navigation = new ThemeNavigationPanel(); + this.navigation.addOnMoveHandler(this); + + this.setShowResizeBar(true); + } + + + public abstract void activateTheme(Theme theme, boolean active); + + + /** + * Replace the current collection with a new one. <b>NOTE: this operation + * triggers updateGrid() which modifies the themes in the grid.</b> + * + * @param collection The new collection object. + */ + protected void setCollection(Collection collection) { + // Set collection of view, but do not trigger event shooting. + this.view.setCollection(collection, true); + + updateGrid(); + } + + + /** Get Collection. */ + public Collection getCollection() { + return view.getCollection(); + } + + + /** + * Returns the ThemeList of the current collection and output mode. + * + * @return the current ThemeList. + */ + public ThemeList getThemeList() { + return getCollection().getThemeList(mode.getName()); + } + + public ListGridRecord[] getSelectedRecords() { + return list.getSelectedRecords(); + } + + /** + * Registers a new OutputParameterChangeHandler. + * + * @param h The new handler. + */ + @Override + public void addOutputParameterChangeHandler(OutputParameterChangeHandler h){ + if (h != null) { + outHandlers.add(h); + } + } + + + /** + * Registers a RedrawRequestHandler. + * + * @param h The new handler. + */ + @Override + public void addRedrawRequestHandler(RedrawRequestHandler h){ + if (h != null) { + redrawRequestHandlers.add(h); + } + } + + + /** + * Request a redraw of e.g. a Chart. + */ + final public void requestRedraw() { + for (RedrawRequestHandler handler: redrawRequestHandlers) { + handler.onRedrawRequest(new RedrawRequestEvent(Type.DEFAULT)); + } + } + + + /** + * Called when the attribution of an output changed. It informs the + * registered handlers about the changes. + */ + protected void fireOutputParameterChanged() { + OutputParameterChangeEvent evt = new OutputParameterChangeEvent(); + + for (OutputParameterChangeHandler handler: outHandlers) { + handler.onOutputParameterChanged(evt); + } + } + + + /** Registers the CollectionView associated to this ThemePanel. */ + public void setCollectionView(CollectionView view) { + this.view = view; + } + + + /** + * This method is used to clear the current theme grid and add new updated + * data. + */ + protected void updateGrid() { + GWT.log("ThemePanel.updateGrid"); + + ListGridRecord[] selected = list.getSelectedRecords(); + + clearGrid(); + + ThemeList themeList = getThemeList(); + + if (themeList == null) { + GWT.log("ERROR: No theme list."); + return; + } + + int count = themeList.getThemeCount(); + + for (int i = 1; i <= count; i++) { + Theme theme = themeList.getThemeAt(i); + + if (theme == null) { + continue; + } + + if (theme.getFacet().equals("empty.facet")) { + theme.setVisible(0); + } + + if (theme.getVisible() == 0) { + continue; + } + + FacetRecord newRecord = createRecord(theme); + addFacetRecord(newRecord); + + String newArtifact = theme.getArtifact(); + String newFacet = theme.getFacet(); + int newIndex = theme.getIndex(); + + for (ListGridRecord r: selected) { + FacetRecord sel = (FacetRecord) r; + Theme oldTheme = sel.getTheme(); + + if (oldTheme.getArtifact().equals(newArtifact) + && oldTheme.getFacet().equals(newFacet) + && oldTheme.getIndex() == newIndex) { + list.selectRecord(newRecord); + } + } + } + + fireOutputParameterChanged(); + } + + + /** Adds given Record to the list (table). */ + protected void addFacetRecord(FacetRecord rec) { + list.addData(rec); + } + + + /** Create a FacetRecord that wraps given theme. */ + protected FacetRecord createRecord(Theme theme) { + return new FacetRecord(theme); + } + + + /** + * This method triggers the CollectionAttributeService. Based on the current + * collectin settings, the attribute of the collection is modified or not. + * But in every case, we will get a new collection object - which might be + * the same as the current one. + */ + public void updateCollection() { + final Config config = Config.getInstance(); + final String loc = config.getLocale(); + + GWT.log("ThemePanel.updateCollection via RPC now"); + + // Don't forget to enable the panel after the request has finished! + disable(); + + updater.update(getCollection(), loc, new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not update collection attributes."); + SC.warn(MSG.getString(caught.getMessage())); + + enable(); + } + + + @Override + public void onSuccess(Collection collection) { + setCollection(collection); + + enable(); + } + }); + } + + + /** + * Create and configure the Grid to display. + */ + protected ListGrid createGrid() { + ListGrid grid = createNewGrid(); + grid.setLeaveScrollbarGap(false); + + return grid; + } + + + protected ListGrid createNewGrid() { + return new ListGrid(); + } + + + /** + * A method that removes all records from theme grid. + */ + protected void clearGrid() { + ListGridRecord[] records = list.getRecords(); + + if (records == null || records.length == 0) { + return; + } + + for (ListGridRecord record: records) { + list.removeData(record); + } + } + + /** Return 'separator'- menu-item. */ + protected MenuItem createSeparator() { + MenuItem separator = new MenuItem(); + separator.setIsSeparator(true); + return separator; + } + + + /** + * Get the context menu for a (right mouse button)click on a single item. + */ + protected Menu getSingleContextMenu(final ListGridRecord[] records) { + Menu menu = new Menu(); + + menu.addItem(createActivateItem(records)); + menu.addItem(createDeactivateItem(records)); + menu.addItem(createRemoveItem(records)); + menu.addItem(createSeparator()); + menu.addItem(createPropertiesItem(records)); + + return menu; + } + + + protected Menu getMultiContextMenu(final ListGridRecord[] records) { + Menu menu = new Menu(); + + menu.addItem(createActivateItem(records)); + menu.addItem(createDeactivateItem(records)); + menu.addItem(createRemoveItem(records)); + + return menu; + } + + + /** The properties menu item (opens style editor on click). */ + protected MenuItem createPropertiesItem(final ListGridRecord[] records) { + MenuItem properties = new MenuItem(MSG.properties()); + + properties.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + GWT.log("clicked properties"); + for (ListGridRecord record: records) { + openStyleEditor((FacetRecord) record); + } + } + }); + + return properties; + } + + + protected MenuItem createActivateItem(final ListGridRecord[] records) { + MenuItem activate = new MenuItem(MSG.activateTheme()); + + activate.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + for (ListGridRecord record: records) { + FacetRecord facet = (FacetRecord) record; + activateTheme(facet.getTheme(), true); + } + + updateCollection(); + } + }); + + return activate; + } + + + protected MenuItem createDeactivateItem(final ListGridRecord[] records) { + MenuItem deactivate = new MenuItem(MSG.deactivateTheme()); + + deactivate.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + for (ListGridRecord record: records) { + FacetRecord facet = (FacetRecord) record; + activateTheme(facet.getTheme(), false); + } + + updateCollection(); + } + }); + + return deactivate; + } + + + /** Remove given themes (not asking for confirmation). */ + protected void removeThemes(final ListGridRecord[] records) { + for (ListGridRecord record: records) { + FacetRecord facet = (FacetRecord) record; + Theme theme = facet.getTheme(); + theme.setVisible(0); + theme.setActive(0); + updateCollection(); + } + } + + + /** Create menu item for removing theme(s). Will ask for confirmation. */ + protected MenuItem createRemoveItem(final ListGridRecord[] records) { + MenuItem remove = new MenuItem(MSG.removeTheme()); + + remove.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + SC.ask(MSG.askThemeRemove(), new BooleanCallback() { + @Override + public void execute(Boolean value) { + if (value) { + removeThemes(records); + } + } + }); + } + }); + + return remove; + } + + + /** + * This method is called after a cell in the theme grid has been modified. + * + * @param event The event that stores information about the modified record. + */ + @Override + public void onEditComplete(EditCompleteEvent event) { + GWT.log("Edited record."); + + int row = event.getRowNum(); + FacetRecord rec = (FacetRecord) list.getRecord(row); + + Theme theme = rec.getTheme(); + + theme.setDescription(rec.getName()); + activateTheme(theme, rec.getActive()); + + updateCollection(); + } + + + /** + * This method should be defined in subclasses that wants to listen to this + * event. + * + * @param theme The theme that is moved. + * @param oldIdx The index of the theme before it was moved. + * @param newIdx The index of the theme after it was moved. + */ + protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) { + // Do nothing + } + + + @Override + public void onMove(OnMoveEvent event) { + int type = event.getType(); + + GWT.log("ThemePanel.onMove: " + type); + + ListGridRecord[] records = list.getSelectedRecords(); + + if (records == null || records.length == 0) { + GWT.log("ThemePanel.onMove: No records selected."); + return; + } + + switch (type) { + case 0: moveRecordsTop(records); break; + case 1: moveRecordsUp(records); break; + case 2: moveRecordsDown(records); break; + case 3: moveRecordsBottom(records); break; + } + + updateCollection(); + } + + + /** + * Moves the selected grid records (themes) to the top of the grid. + * + * @param records The selected themes in the list. Null not permitted. + */ + protected void moveRecordsTop(ListGridRecord[] records) { + ThemeList themeList = getThemeList(); + + int idx = 1; + + for (ListGridRecord record: records) { + Theme theme = ((FacetRecord) record).getTheme(); + fireThemeMoved(theme, theme.getPosition(), idx); + themeList.setThemePosition(theme, idx++); + } + + updateGrid(); + } + + + /** + * Moves the selected grid records (themes) one step up. + * + * @param records The selected themes in the list. Null not permitted. + */ + protected void moveRecordsUp(ListGridRecord[] records) { + ThemeList themeList = getThemeList(); + + int[] newPos = new int[records.length]; + + for (int i = 0; i < records.length ; i++) { + Theme theme = ((FacetRecord) records[i]).getTheme(); + newPos[i] = theme.getPosition() - 1; + } + + for (int i = 0; i < records.length ; i++) { + Theme theme = ((FacetRecord) records[i]).getTheme(); + fireThemeMoved(theme, theme.getPosition(), newPos[i]); + themeList.setThemePosition(theme, newPos[i]); + } + + updateGrid(); + } + + + /** + * Moves the selected grid records (themes) one step down. + * + * @param records The selected themes in the list. Null not permitted. + */ + protected void moveRecordsDown(ListGridRecord[] records) { + ThemeList themeList = getThemeList(); + + int[] newPos = new int[records.length]; + + for (int i = records.length-1; i >= 0; i--) { + Theme theme = ((FacetRecord) records[i]).getTheme(); + newPos[i] = theme.getPosition()+1; + } + + for (int i = records.length-1; i >= 0; i--) { + Theme theme = ((FacetRecord) records[i]).getTheme(); + fireThemeMoved(theme, theme.getPosition(), newPos[i]); + themeList.setThemePosition(theme, newPos[i]); + } + + updateGrid(); + } + + + /** + * Moves the selected grid records (themes) to the bottom of the grid. + * + * @param records The selected themes in the list. Null not permitted. + */ + protected void moveRecordsBottom(ListGridRecord[] records) { + ThemeList themeList = getThemeList(); + + int idx = themeList.getThemeCount(); + + for (int i = records.length-1; i >= 0; i--) { + Theme theme = ((FacetRecord) records[i]).getTheme(); + fireThemeMoved(theme, theme.getPosition(), idx); + themeList.setThemePosition(theme, idx--); + } + + updateGrid(); + } + + + protected void openStyleEditor(final FacetRecord record) { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + String artifact = record.getTheme().getArtifact(); + + itemAttributeService.getCollectionItemAttribute( + this.getCollection(), + artifact, + locale, + new AsyncCallback<CollectionItemAttribute>() { + @Override + public void onFailure (Throwable caught) { + SC.warn(MSG.getString(caught.getMessage())); + } + @Override + public void onSuccess(CollectionItemAttribute cia) { + GWT.log("Successfully loaded collectionitem attributes."); + showStyleEditor(cia, record); + } + }); + } + + + protected void showStyleEditor( + CollectionItemAttribute cia, + FacetRecord record) + { + StyleEditorWindow win = new StyleEditorWindow( + getCollection(), + cia, + record); + win.setThemePanel(this); + win.centerInPage(); + win.show(); + } + + + /** Get OutputMode of this Panel. */ + public OutputMode getMode() { + return this.mode; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/Toolbar.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,61 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.events.CloseClickEvent; +import com.smartgwt.client.widgets.events.CloseClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.User; + + +public abstract class Toolbar extends HLayout { + + protected OutputTab outputTab; + + + public Toolbar(OutputTab outputTab) { + super(); + + // Set overflow to hidden in order to prevent nasty scrollbars in IE + setOverflow(Overflow.HIDDEN); + + this.outputTab = outputTab; + } + + + public OutputTab getOutputTab() { + return outputTab; + } + + + public Artifact getArtifact() { + return outputTab.getCollectionView().getArtifact(); + } + + + public User getUser() { + return outputTab.getCollectionView().getUser(); + } + + + protected void openDatacageWindow(RedrawRequestHandler handler) { + Artifact artifact = getArtifact(); + User user = getUser(); + + String outs = getOutputTab().getOutputName(); + + final DatacageWindow dc = new DatacageWindow( + artifact, user, outs, outputTab.getCollectionView()); + dc.addRedrawRequestHandler(handler); + dc.addCloseClickHandler(new CloseClickHandler() { + @Override + public void onCloseClick(CloseClickEvent event) { + dc.destroy(); + } + }); + dc.show(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/UIProvider.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,69 @@ +package de.intevation.flys.client.client.ui; + +import java.io.Serializable; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; + +/** + * This interface describes a method that creates a Canvas element displaying + * DataItems for a current state of the artifact. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface UIProvider extends Serializable { + + /** + * This method creates a Canvas element showing the DataItems in + * <i>data</i>. + * + * @param data The DataList object. + * + * @return the Canvas showing the Data. + */ + public Canvas create(DataList data); + + + /** + * This method creates a Canvas element showing the old Data objects in the + * DataList <i>data</i>. + * + * @param dataList The DataList which elements should be displayed. + * + * @return a Canvas displaying the Data. + */ + public Canvas createOld(DataList dataList); + + + public Canvas createHelpLink(DataList dataList, Data data); + + + /** + * This method injects a container that is used to position helper widgets. + * + * @param container A container that is used to position helper widgets. + */ + public void setContainer(VLayout container); + + + /** + * Sets an artifact that contains the status data information for a project. + * + * @param artifact The artifact containing status information. + */ + public void setArtifact(Artifact artifact); + + + /** + * Sets the parent Collection of the Artifact. + */ + public void setCollection(Collection collection); + + public void setParameterList(ParameterList list); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,195 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import de.intevation.flys.client.client.ui.fixation.FixEventSelect; +import de.intevation.flys.client.client.ui.fixation.FixFunctionSelect; +import de.intevation.flys.client.client.ui.fixation.FixGaugeSelectPanel; +import de.intevation.flys.client.client.ui.fixation.FixLocationPanel; +import de.intevation.flys.client.client.ui.fixation.FixMultiPeriodPanel; +import de.intevation.flys.client.client.ui.fixation.FixPeriodPanel; +import de.intevation.flys.client.client.ui.fixation.FixQSelectPanel; +import de.intevation.flys.client.client.ui.minfo.BedHeightsDatacagePanel; +import de.intevation.flys.client.client.ui.minfo.BedMultiPeriodPanel; +import de.intevation.flys.client.client.ui.minfo.CheckboxPanel; +import de.intevation.flys.client.client.ui.minfo.SedLoadDistancePanel; +import de.intevation.flys.client.client.ui.minfo.SedLoadEpochPanel; +import de.intevation.flys.client.client.ui.minfo.SedLoadOffEpochPanel; +import de.intevation.flys.client.client.ui.minfo.SedLoadPeriodPanel; +import de.intevation.flys.client.client.ui.sq.SQPeriodPanel; +import de.intevation.flys.client.shared.model.User; + +/** + * Depending on the provider the state declared, return a UIProvider. + * + * A UIProvider provides widgets and input helpers to guide input to an + * artifacts state. + */ +public class UIProviderFactory { + + private UIProviderFactory() { + } + + /** @param uiProvider uiprovider demanded for by state. */ + public static UIProvider getProvider(String uiProvider, User user) { + if (uiProvider == null || uiProvider.equals("")) { + return new SelectProvider(); + } + else if (uiProvider.equals("select_with_map")) { + return new MapSelection(); + } + else if (uiProvider.equals("location_distance_panel")) { + return new LocationDistancePanel(); + } + else if (uiProvider.equals("location_panel")) { + return new SingleLocationPanel(); + } + else if (uiProvider.equals("multi_location_panel")) { + return new MultipleLocationPanel(); + } + else if (uiProvider.equals("distance_panel")) { + return new DistancePanel(); + } + else if (uiProvider.equals("distance_only_panel")) { + return new DistanceOnlyPanel(); + } + else if (uiProvider.equals("waterlevel_ground_panel")) { + return new WaterlevelGroundPanel(); + } + else if (uiProvider.equals("wq_panel")) { + return new WQInputPanel(); + } + else if (uiProvider.equals("wq_panel_adapted")) { + return new WQAdaptedInputPanel(); + } + else if (uiProvider.equals("q_segmented_panel")) { + return new QSegmentedInputPanel(); + } + else if (uiProvider.equals("river_panel")) { + return new LinkSelection(); + } + else if (uiProvider.equals("continue")) { + return new ContinuePanel(); + } + else if (uiProvider.equals("wsp_datacage_panel")) { + return new WspDatacagePanel(user); + } + else if (uiProvider.equals("dgm_datacage_panel")) { + return new DemDatacagePanel(user); + } + else if (uiProvider.equals("datacage_twin_panel")) { + return new DatacageTwinPanel(user); + } + else if (uiProvider.equals("auto_integer")) { + return new AutoIntegerPanel(); + } + else if (uiProvider.equals("boolean_panel")) { + return new BooleanPanel(); + } + else if (uiProvider.equals("noinput")) { + return new NoInputPanel(); + } + else if (uiProvider.equals("map_digitize")) { + return new DigitizePanel(); + } + else if (uiProvider.equals("timerange")) { + return new IntegerRangePanel(); + } + else if (uiProvider.equals("wq_simple_array")) { + return new WQSimpleArrayPanel(); + } + else if (uiProvider.equals("gaugetimerange")) { + return new GaugeTimeRangePanel(); + } + else if (uiProvider.equals("fix.location_panel")) { + return new FixLocationPanel(); + } + else if (uiProvider.equals("fix.period_panel")) { + return new FixPeriodPanel(); + } + else if (uiProvider.equals("fix.period_ref_panel")) { + return new FixPeriodPanel("ref_start", "ref_end"); + } + else if (uiProvider.equals("fix.period_ana_panel")) { + return new FixMultiPeriodPanel(); + } + else if (uiProvider.equals("fix.qselect_panel")) { + return new FixQSelectPanel(); + } + else if (uiProvider.equals("fix.gaugeselect_panel")) { + return new FixGaugeSelectPanel(); + } + else if (uiProvider.equals("fix.event_panel")) { + return new FixEventSelect(); + } + else if (uiProvider.equals("fix.preprocessing_panel")) { + return new BooleanPanel(); + } + else if (uiProvider.equals("fix.functionselect")) { + return new FixFunctionSelect(); + } + else if (uiProvider.equals("period_select")) { + return new PeriodPanel(); + } + else if (uiProvider.equals("periods_select")) { + return new MultiPeriodPanel(); + } + else if (uiProvider.equals("sq.period.select")) { + return new SQPeriodPanel(); + } + else if (uiProvider.equals("outliers_input")) { + return new DoubleInputPanel(); + } + else if (uiProvider.equals("percent_input")) { + return new DoubleInputPanel("percent"); + } + else if (uiProvider.equals("parameter-matrix")) { + return new ParameterMatrixPanel(); + } + else if (uiProvider.equals("minfo.bed.year_epoch")) { + return new RadioPanel(); + } + else if (uiProvider.equals("bedquality_periods_select")) { + return new BedMultiPeriodPanel(); + } + else if (uiProvider.equals("bedheights_twin_panel")) { + return new BedHeightsDatacagePanel(user); + } + else if (uiProvider.equals("minfo.bed.char_diameter")) { + return new CheckboxPanel(); + } + else if (uiProvider.equals("minfo.sedimentload_unit_select")) { + return new RadioPanel(); + } + else if (uiProvider.equals("gauge_discharge_curve")) { + return new StaticDataPanel(); + } + else if (uiProvider.equals("minfo.sedimentload_distance_select")) { + return new SedLoadDistancePanel(); + } + else if (uiProvider.equals("minfo.sedimentload_year_select")) { + return new SedLoadPeriodPanel(); + } + else if (uiProvider.equals("minfo.sedimentload_epoch_select")) { + return new SedLoadEpochPanel(); + } + else if (uiProvider.equals("minfo.sedimentload_offepoch_select")) { + return new SedLoadOffEpochPanel(); + } + else if (uiProvider.equals("hws_datacage_panel")) { + return new HWSDatacagePanel(user); + } + else if (uiProvider.equals("user_rgd_panel")) { + return new UserRGDProvider(); + } + else if (uiProvider.equals("static_sqrelation")) { + return new StaticDataPanel(); + } + else { + //GWT.log("Picked default provider."); + return new SelectProvider(); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/UserRGDProvider.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,133 @@ +package de.intevation.flys.client.client.ui; + +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.types.Encoding; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.HTMLPane; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.UploadItem; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + + +public class UserRGDProvider +extends SelectProvider +{ + + private HTMLPane uploadTargetFrame; + private String uploadFile; + + public UserRGDProvider() { + uploadTargetFrame = new HTMLPane(); + } + + @Override + public Canvas create(DataList list) { + List<Data> data = list.getAll(); + + //Canvas selectBox = super.create(clone); + Canvas widget = createWidget(list); + + return widget; + } + + + /** + * This method creates the content of the widget. + * + * @param data The {@link DataList} object. + * + * @return a combobox. + */ + @Override + protected Canvas createWidget(DataList data) { + GWT.log("DigitizePanel - createWidget()"); + + VLayout layout = new VLayout(); + layout.setAlign(VerticalAlignment.TOP); + layout.setHeight(25); + + int size = data.size(); + + for (int i = 0; i < size; i++) { + Data d = data.get(i); + + Label label = new Label(d.getDescription()); + label.setValign(VerticalAlignment.TOP); + label.setHeight(20); + label.setWidth(400); + + uploadTargetFrame.setWidth("200px"); + uploadTargetFrame.setHeight("50px"); + uploadTargetFrame.setContents( + "<iframe id='uploadTarget' name='uploadTarget' scrolling='no' width=200 height=50 style='border: 0px'></iframe>"); + uploadTargetFrame.setBorder("0px"); + uploadTargetFrame.setScrollbarSize(0); + + final DynamicForm uploadForm = new DynamicForm(); + uploadForm.setAction("flys/fileupload?uuid=" + artifact.getUuid()); + uploadForm.setTarget("uploadTarget"); + uploadForm.setEncoding(Encoding.MULTIPART); + Label uploadLabel = new Label(MSG.shape_file_upload()); + uploadLabel.setHeight(20); + final UploadItem uploadItem = new UploadItem(); + uploadItem.setShowTitle(false); + uploadForm.setFields(uploadItem); + Button submit = new Button(MSG.upload_file()); + submit.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + uploadFile = uploadItem.getValueAsString(); + uploadForm.submitForm(); + } + }); + + layout.addMember(label); + layout.addMember(form); + layout.addMember(uploadLabel); + layout.addMember(uploadForm); + layout.addMember(submit); + layout.addMember(getNextButton()); + + layout.setMembersMargin(10); + layout.addMember(uploadTargetFrame); + } + + layout.setAlign(VerticalAlignment.TOP); + + return layout; + } + + @Override + protected Data[] getData() { + Data[] total = new Data[1]; + + if (uploadFile != null && uploadFile.length() > 0) { + DataItem item = new DefaultDataItem( + "uesk.user-rgd", "uesk.user-rgd", uploadFile); + total[0] = new DefaultData( + "uesk.user-rgd", null, null, new DataItem[] { item }); + } + else { + // Happens when OpenLayers is missing + DataItem item = new DefaultDataItem( + "uesk.user-rgd", "uesk.user-rgd", MSG.notselected()); + total[0] = new DefaultData( + "uesk.user-rgd", null, null, new DataItem[] { item }); + } + + return total; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,828 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.TitleOrientation; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.RadioGroupItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; +import com.smartgwt.client.widgets.form.fields.events.FocusEvent; +import com.smartgwt.client.widgets.form.fields.events.FocusHandler; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.WQInfoService; +import de.intevation.flys.client.client.services.WQInfoServiceAsync; +import de.intevation.flys.client.client.ui.wq.QDTable; +import de.intevation.flys.client.client.ui.wq.WTable; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.WQDataItem; +import de.intevation.flys.client.shared.model.WQInfoObject; +import de.intevation.flys.client.shared.model.WQInfoRecord; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + + +/** + * This UIProvider creates a widget to enter W or Q data for discharge + * longitudinal section computations. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WQAdaptedInputPanel +extends AbstractUIProvider +implements ChangeHandler, BlurHandler, FocusHandler +{ + private static final long serialVersionUID = -3218827566805476423L; + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + public static final String FIELD_WQ_MODE = "wq_isq"; + public static final String FIELD_WQ_W = "W"; + public static final String FIELD_WQ_Q = "Q"; + + public static final String GAUGE_SEPARATOR = ":"; + + public static final String GAUGE_PART_SEPARATOR = ";"; + + public static final String VALUE_SEPARATOR = ","; + + public static final int ROW_HEIGHT = 20; + + /** The constant field name for choosing w or q mode. */ + public static final String FIELD_WQ = "wq"; + + /** The constant field name for choosing single values or range. */ + public static final String FIELD_MODE = "mode"; + + /** The constant field value for range input mode. */ + public static final String FIELD_MODE_RANGE = "range"; + + /** Service to fetch W/Q MainValues. */ + protected WQInfoServiceAsync wqInfoService = + GWT.create(WQInfoService.class); + + /** The message class that provides i18n strings. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** Stores the input panels related to their keys. */ + protected Map<String, DoubleArrayPanel> wqranges; + + /** List of doubleArrayPanels shown. */ + protected ArrayList<DoubleArrayPanel> doubleArrayPanels; + + /** [startkm,endkm] per gauge in selected range. */ + protected double[][] gaugeRanges; + + /** Stores the min/max values for each q range (gauge). */ + protected Map<String, double[]> qranges; + + /** Stores the min/max values for each w range (gauge). */ + protected Map<String, double[]> wranges; + + /** The RadioGroupItem that determines the w/q input mode. */ + protected DynamicForm modes; + + /** List of wTables in inputhelper section. */ + protected List<WTable> wTables; + + /** List of QDTables in inputhelper section. */ + protected List<QDTable> qdTables; + + /** Tabs in inputhelper area. */ + protected TabSet tabs; + + /** The currently focussed Input element. */ + protected DoubleArrayPanel itemWithFocus; + + + public WQAdaptedInputPanel() { + wqranges = new HashMap<String, DoubleArrayPanel>(); + doubleArrayPanels = new ArrayList<DoubleArrayPanel>(); + qranges = new HashMap<String, double[]>(); + wranges = new HashMap<String, double[]>(); + wTables = new ArrayList<WTable>(); + qdTables = new ArrayList<QDTable>(); + } + + + @Override + public Canvas create(DataList data) { + readGaugeRanges(data); + initHelperPanel(); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(data); + Label label = new Label(MSG.wqadaptedTitle()); + + label.setHeight(25); + + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + layout.setWidth(350); + + layout.addMember(label); + layout.addMember(widget); + layout.addMember(submit); + + fetchWQData(); + + initTableListeners(); + + return layout; + } + + + /** Inits the helper panel. */ + // TODO duplicate in WQInputPanel + protected void initHelperPanel() { + tabs = new TabSet(); + tabs.setWidth100(); + tabs.setHeight100(); + + // For each gauge, add two tabs with helper tables. + + for (int i = 0; i< gaugeRanges.length; i++) { + // Later the tabs title will get adjusted to include gauges name. + // TODO the tabs title becomes rather long through that (i18n). + Tab wTab = new Tab(MESSAGE.wq_table_w()); + Tab qTab = new Tab(MESSAGE.wq_table_q()); + + QDTable qdTable = new QDTable(); + WTable wTable = new WTable(); + + wTables.add(wTable); + qdTables.add(qdTable); + + qdTable.showSelect(); + //wTable.showSelect(); + wTab.setPane(wTable); + qTab.setPane(qdTable); + + tabs.addTab(wTab, i*2+0); + tabs.addTab(qTab, i*2+1); + } + + helperContainer.addMember(tabs); + } + + + /** + * Initializes the listeners of the WQD tables. + */ + // TODO dupe from WQInputPanel + protected void initTableListeners() { + int i = 0; + for (QDTable qdTable: qdTables) { + // Register listener such that values are filled in on click. + final QDTable table = qdTable; + final int fi = i; + CellClickHandler handler = new CellClickHandler() { + @Override + public void onCellClick(CellClickEvent e) { + if (isWMode() || table.isLocked()) { + return; + } + + int idx = e.getColNum(); + Record r = e.getRecord(); + double val = r.getAttributeAsDouble("value"); + + doubleArrayPanels.get(fi).setValues(new double[]{val}); + // If a named value for first gauge is chosen, try to find and set + // the values to the other panels too. + if (fi == 0) { + String valueName = r.getAttribute("name"); + int oi = 0; + // TODO instead of oi use random access. + for (QDTable otherQDTable: qdTables) { + if (oi == 0) { + oi++; + continue; + } + Double value = otherQDTable.findRecordValue(valueName); + if (value == null) { + // TODO i18n + SC.warn("No Value for <name> at <gauge>"); + } + else { + doubleArrayPanels.get(oi).setValues(new double[]{value}); + } + oi++; + } + } + else { + // Focus next. + if (fi != doubleArrayPanels.size()-1) { + doubleArrayPanels.get(fi+1).focusInItem(1); + } + } + } + }; + + qdTable.addCellClickHandler(handler); + i++; + } + } + + + @Override + public Canvas createOld(DataList dataList) { + List<Data> all = dataList.getAll(); + Data wqData = getData(all, "wq_values"); + Data wqMode = getData(all, "wq_isq"); + boolean isQ = wqMode.getItems()[0].getStringValue().equals("true"); + Canvas back = getBackButton(dataList.getState()); + + HLayout valLayout = new HLayout(); + HLayout modeLayout = new HLayout(); + VLayout vlayout = new VLayout(); + + Label wqLabel = new Label(dataList.getLabel()); + Label modeLabel = new Label(""); + + wqLabel.setValign(VerticalAlignment.TOP); + + wqLabel.setWidth(200); + wqLabel.setHeight(25); + modeLabel.setHeight(25); + modeLabel.setWidth(200); + + valLayout.addMember(wqLabel); + valLayout.addMember(createOldWQValues(wqData, isQ)); + + valLayout.addMember(back); + modeLayout.addMember(modeLabel); + + vlayout.addMember(valLayout); + vlayout.addMember(modeLayout); + + return vlayout; + } + + + /** Create area showing previously entered w or q data. */ + protected Canvas createOldWQValues(Data wqData, boolean isQ) { + VLayout layout = new VLayout(); + + DataItem item = wqData.getItems()[0]; + String value = item.getStringValue(); + + String[] gauges = value.split(GAUGE_SEPARATOR); + + String unit = isQ ? "m³/s" : "cm"; + + for (String gauge: gauges) { + HLayout h = new HLayout(); + + String[] parts = gauge.split(GAUGE_PART_SEPARATOR); + String[] values = parts[3].split(VALUE_SEPARATOR); + + Label l = new Label(parts[2] + ": "); + + StringBuilder sb = new StringBuilder(); + boolean first = true; + + for (String v: values) { + if (!first) { + sb.append(", "); + } + + sb.append(v); + sb.append(" "); + sb.append(unit); + + first = false; + } + + Label v = new Label(sb.toString()); + + l.setWidth(65); + v.setWidth(65); + + h.addMember(l); + h.addMember(v); + + layout.addMember(h); + } + + return layout; + } + + + /** Create non-input helper part of the UI. */ + protected Canvas createWidget(DataList dataList) { + VLayout layout = new VLayout(); + + Canvas mode = createMode(dataList); + Canvas list = createList(dataList); + + DataItem[] items = getWQItems(dataList); + int listHeight = ROW_HEIGHT * items.length; + + mode.setHeight(25); + mode.setWidth(200); + + layout.addMember(mode); + layout.addMember(list); + + layout.setHeight(25 + listHeight); + layout.setWidth(350); + + initUserDefaults(dataList); + + return layout; + } + + + @Override + public List<String> validate() { + if (isWMode()) { + return validateW(); + } + else { + return validateQ(); + } + } + + + protected List<String> validateRange(Map<String, double[]> ranges) { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + Iterator<String> iter = wqranges.keySet().iterator(); + + while (iter.hasNext()) { + List<String> tmpErrors = new ArrayList<String>(); + + String key = iter.next(); + DoubleArrayPanel dap = wqranges.get(key); + + if (!dap.validateForm()) { + errors.add(MSG.error_invalid_double_value()); + return errors; + } + + double[] mm = ranges.get(key); + if (mm == null) { + SC.warn(MSG.error_read_minmax_values()); + continue; + } + + double[] values = dap.getInputValues(); + double[] good = new double[values.length]; + + int idx = 0; + + for (double value: values) { + if (value < mm[0] || value > mm[1]) { + String tmp = MSG.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(mm[0])); + tmp = tmp.replace("$3", nf.format(mm[1])); + tmpErrors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!tmpErrors.isEmpty()) { + dap.setValues(justGood); + + errors.addAll(tmpErrors); + } + } + + return errors; + } + + + protected List<String> validateW() { + return validateRange(wranges); + } + + + protected List<String> validateQ() { + return validateRange(qranges); + } + + + protected void initUserDefaults(DataList dataList) { + initUserWQValues(dataList); + initUserWQMode(dataList); + } + + + protected void initUserWQMode(DataList dataList) { + List<Data> allData = dataList.getAll(); + + Data dDef = getData(allData, "wq_mode"); + DataItem def = dDef != null ? dDef.getDefault() : null; + String value = def != null ? def.getStringValue() : null; + + if (value != null && value.equals(FIELD_WQ_W)) { + modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W); + } + else { + modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q); + } + } + + + protected void initUserWQValues(DataList dataList) { + List<Data> allData = dataList.getAll(); + + Data dDef = getData(allData, "wq_values"); + DataItem def = dDef != null ? dDef.getDefault() : null; + String value = def != null ? def.getStringValue() : null; + + if (value == null || value.length() == 0) { + return; + } + + String[] lines = value.split(GAUGE_SEPARATOR); + + if (lines == null || lines.length == 0) { + return; + } + + for (String line: lines) { + String[] cols = line.split(GAUGE_PART_SEPARATOR); + String title = createLineTitle(line); + + if (cols == null || cols.length < 3) { + continue; + } + + String[] strValues = cols[2].split(VALUE_SEPARATOR); + double[] values = new double[strValues.length]; + + int idx = 0; + + for (String strValue: strValues) { + try { + values[idx++] = Double.valueOf(strValue); + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + String key = cols[0] + GAUGE_PART_SEPARATOR + cols[1]; + DoubleArrayPanel dap = wqranges.get(key); + + if (dap == null) { + continue; + } + + dap.setValues(values); + } + } + + /** Populate Gauge Ranges array. */ + private void readGaugeRanges(DataList dataList) { + DataItem[] items = getWQItems(dataList); + gaugeRanges = new double[items.length][2]; + + int i = 0; + + for (DataItem item: items) { + String[] startEndKm = item.getLabel().split(";"); + + gaugeRanges[i][0] = Double.parseDouble(startEndKm[0]); + gaugeRanges[i][1] = Double.parseDouble(startEndKm[1]); + i++; + } + } + + + protected Canvas createList(DataList dataList) { + VLayout layout = new VLayout(); + + DataItem[] items = getWQItems(dataList); + + int i = 0; + + for (DataItem item: items) { + String title = item.getLabel(); // of form: 70.5;112.0 + String label = item.getStringValue(); + + // Rename W and Q tab to include gauges name. + tabs.getTab(i*2).setTitle(tabs.getTab(i*2).getTitle() + + " (" + label + ")"); + tabs.getTab(i*2+1).setTitle(tabs.getTab(i*2+1).getTitle() + + " (" + label + ")"); + + DoubleArrayPanel dap = new DoubleArrayPanel( + label, null, this, this, TitleOrientation.LEFT); + + wqranges.put(title, dap); + doubleArrayPanels.add(dap); + + if (item instanceof WQDataItem) { + WQDataItem wq = (WQDataItem) item; + double[] mmQ = wq.getQRange(); + double[] mmW = wq.getWRange(); + + qranges.put(title, mmQ); + wranges.put(title, mmW); + } + + layout.addMember(dap); + i++; + } + + layout.setHeight(items.length * ROW_HEIGHT); + + return layout; + } + + + /** Get items which are not WQ_MODE. */ + protected DataItem[] getWQItems(DataList dataList) { + List<Data> data = dataList.getAll(); + + for (Data d: data) { + String name = d.getLabel(); + + if (name.equals(FIELD_WQ_MODE)) { + continue; + } + + return d.getItems(); + } + + return null; + } + + + /** + * Create radio button for switching w and q input. + * Radiobutton-change also triggers helper panel tab selection. + */ + protected Canvas createMode(DataList dataList) { + RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE); + wq.setShowTitle(false); + wq.setVertical(false); + wq.setWidth(200); + + LinkedHashMap wqValues = new LinkedHashMap(); + wqValues.put(FIELD_WQ_W, MSG.wqW()); + wqValues.put(FIELD_WQ_Q, MSG.wqQatGauge()); + + wq.setValueMap(wqValues); + + modes = new DynamicForm(); + modes.setFields(wq); + modes.setWidth(200); + wq.addChangeHandler(new ChangeHandler() { + @Override + public void onChange(ChangeEvent e) { + DynamicForm form = e.getForm(); + + if(form.getValueAsString(FIELD_WQ_MODE).contains("Q")) { + tabs.selectTab(0); + } + else { + tabs.selectTab(1); + } + } + }); + + + LinkedHashMap initial = new LinkedHashMap(); + initial.put(FIELD_WQ_MODE, FIELD_WQ_Q); + modes.setValues(initial); + tabs.selectTab(1); + return modes; + } + + + public String createLineTitle(String key) { + String[] splitted = key.split(";"); + + return splitted[0] + " - " + splitted[1]; + } + + + @Override + public Data[] getData() { + Data mode = getWQMode(); + Data values = getWQValues(); + + return new Data[] { mode, values }; + } + + + public boolean isWMode() { + String mode = (String) modes.getValue(FIELD_WQ_MODE); + + return FIELD_WQ_W.equals(mode); + } + + + protected Data getWQMode() { + String wqMode = modes.getValueAsString(FIELD_WQ_MODE); + String value = "false"; + if (wqMode.equals("Q")) { + value = "true"; + } + DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value); + Data mode = new DefaultData( + "wq_isq", null, null, new DataItem[] { item }); + + return mode; + } + + + protected Data getWQValues() { + String wqvalue = null; + + Iterator<String> iter = wqranges.keySet().iterator(); + while (iter.hasNext()) { + String key = iter.next(); + DoubleArrayPanel dap = wqranges.get(key); + String label = dap.getItemTitle(); + + double[] values = dap.getInputValues(); + if (wqvalue == null) { + wqvalue = createValueString(key + ";" + label, values); + } + else { + wqvalue += GAUGE_SEPARATOR + createValueString(key + ";" + label, values); + } + } + + DataItem valueItem = new DefaultDataItem( + "wq_values", "wq_values", wqvalue); + Data values = new DefaultData( + "wq_values", null, null, new DataItem[] { valueItem }); + + return values; + } + + + protected String createValueString(String key, double[] values) { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + + for (double value: values) { + if (!first) { + sb.append(","); + } + + sb.append(Double.toString(value)); + + first = false; + } + + return key + ";" + sb.toString(); + } + + + @Override + public void onChange(ChangeEvent event) { + // TODO IMPLEMENT ME + } + + + /** Store the currently focussed DoubleArrayPanel and focus helper tab. */ + @Override + public void onFocus(FocusEvent event) { + itemWithFocus = (DoubleArrayPanel) event.getForm(); + // Switch to respective tab. + // TODO which makes a focus loss + int inputIndex = doubleArrayPanels.indexOf(itemWithFocus); + tabs.selectTab(inputIndex*2 + (isWMode() ? 0 : 1)); + } + + + @Override + public void onBlur(BlurEvent event) { + DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); + dap.validateForm(event.getItem()); + } + + + /** Get the WQD data from service and stuck them up that tables. */ + protected void fetchWQData() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + double[] mm = getMinMaxKM(data); + String river = getRiverName(data); + + int i = 0; + + // Get Data for respective gauge. + for (double[] range : gaugeRanges){ + // Gauge ranges overlap, move start and end a bit closer to each other. + final double rDiff = (range[1] - range[0]) / 10d; + final int fi = i; + wqInfoService.getWQInfo(locale, river, range[0]+rDiff, range[1]-rDiff, + new AsyncCallback<WQInfoObject[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve wq informations."); + SC.warn(caught.getMessage()); + } + + @Override + public void onSuccess(WQInfoObject[] wqi) { + int num = wqi != null ? wqi.length :0; + GWT.log("Received " + num + " wq informations (" + fi + "."); + + if (num == 0) { + return; + } + + addWQInfo(wqi, fi); + } + } + ); + i++; + } + } + + + /** Add Info to helper table for gauge at index gaugeIdx. */ + protected void addWQInfo (WQInfoObject[] wqi, int gaugeIdx) { + for(WQInfoObject wi: wqi) { + WQInfoRecord rec = new WQInfoRecord(wi); + + if (wi.getType().equals("W")) { + wTables.get(gaugeIdx).addData(rec); + } + else { + qdTables.get(gaugeIdx).addData(rec); + } + } + } + + + /** + * Determines the min and max kilometer value selected in a former state. A + * bit silly, but we need to run over each value of the "old data" to find + * such values because it is not available here. + * + * @param data The DataList which contains the whole data inserted for the + * current artifact. + * + * @return a double array with [min, max]. + */ + protected double[] getMinMaxKM(DataList[] data) { + ArtifactDescription adesc = artifact.getArtifactDescription(); + return adesc.getKMRange(); + } + + + /** + * Returns the name of the selected river. + * + * @param data The DataList with all data. + * + * @return the name of the current river. + */ + protected String getRiverName(DataList[] data) { + ArtifactDescription adesc = artifact.getArtifactDescription(); + return adesc.getRiver(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/WQInputPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,1848 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.RadioGroupItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.WQInfoService; +import de.intevation.flys.client.client.services.WQInfoServiceAsync; +import de.intevation.flys.client.client.ui.wq.QDTable; +import de.intevation.flys.client.client.ui.wq.WTable; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.WQInfoObject; +import de.intevation.flys.client.shared.model.WQInfoRecord; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + + +/** + * This UIProvider creates a widget to enter W or Q data. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WQInputPanel +extends AbstractUIProvider +implements ChangeHandler, BlurHandler +{ + private static final long serialVersionUID = 4797387993390350341L; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + protected WQInfoServiceAsync wqInfoService = + GWT.create(WQInfoService.class); + + /** The constant field name for choosing w or q mode.*/ + public static final String FIELD_WQ_W_FREE = "WFREE"; + + /** The constant field name for choosing w or q mode.*/ + public static final String FIELD_WQ = "wq"; + + /** The constant field value for W input mode.*/ + public static final String FIELD_WQ_W = "W"; + + /** The constant field value for Q input mode.*/ + public static final String FIELD_WQ_Q = "Q"; + + /** The constant field value for Q input mode.*/ + public static final String FIELD_WQ_Q_FREE = "QFREE"; + + /** The constant field name for choosing single values or range.*/ + public static final String FIELD_MODE = "mode"; + + /** The constant field value for single input mode.*/ + public static final String FIELD_MODE_SINGLE = "single"; + + /** The constant field value for range input mode.*/ + public static final String FIELD_MODE_RANGE = "range"; + + /** The constant value that determines the width of the left panel.*/ + public static final int WIDTH_LEFT_UPPER = 400; + + public static final int WIDTH_LEFT_LOWER = 223; + + /** The container that manages the w and q panels.*/ + protected HLayout container; + + /** The RadioGroupItem that determines the w/q input mode.*/ + protected DynamicForm modes; + + /** The min values for the 'from' property in the W-Range input mode.*/ + protected double minW; + + /** The min values for the 'from' property in the Q-Range input mode.*/ + protected double minQ; + + /** The min value for the 'from' property in the free Q-Range input mode.*/ + protected double minQFree; + + /** The min value for the 'from' property in the free W-Range input mode.*/ + protected double minWFree; + + /** The max values for the 'from' property in the W-Range input mode.*/ + protected double maxW; + + /** The max values for the 'from' property in the Q-Range input mode.*/ + protected double maxQ; + + /** The max value for the 'from' property in the free Q-Range input mode.*/ + protected double maxQFree; + + /** The max value for the 'from' property in the free W-Range input mode.*/ + protected double maxWFree; + + /** The 'from' value entered in the range W mode.*/ + protected double fromW; + + /** The 'to' value entered in the range W mode.*/ + protected double toW; + + /** The 'step' value entered in the range W mode.*/ + protected double stepW; + + /** The values entered in the single W mode.*/ + protected double[] valuesW; + + /** The values entered in the single W mode.*/ + protected double[] valuesWFree; + + /** The 'from' value entered in the range Q mode.*/ + protected double fromQ; + + /** The 'from' value entered in the range free Q mode.*/ + protected double fromQFree; + + /** The 'from' value entered in the range free W mode.*/ + protected double fromWFree; + + /** The 'to' value entered in the range Q mode.*/ + protected double toQ; + + /** The 'to' value entered in the range free Q mode.*/ + protected double toQFree; + + /** The 'to' value entered in the range free W mode.*/ + protected double toWFree; + + /** The 'step' value entered in the range Q mode.*/ + protected double stepQ; + + /** The 'step' value entered in the range free Q mode.*/ + protected double stepQFree; + + /** The 'step' value entered in the range free W mode.*/ + protected double stepWFree; + + /** The values entered in the single Q mode.*/ + protected double[] valuesQ; + + /** The values entered in the single free Q mode.*/ + protected double[] valuesQFree; + + /** The input panel for W values*/ + protected DoubleArrayPanel wArrayPanel; + + /** The input panel for q values*/ + protected DoubleArrayPanel qArrayPanel; + + /** The input panel for free q values*/ + protected DoubleArrayPanel qFreeArrayPanel; + + /** The input panel for free w values*/ + protected DoubleArrayPanel wFreeArrayPanel; + + /** The input panel for w range*/ + protected DoubleRangePanel wRangePanel; + + /** The input panel for q range*/ + protected DoubleRangePanel qRangePanel; + + /** The input panel for free q range*/ + protected DoubleRangePanel qFreeRangePanel; + + /** The input panel for free w range*/ + protected DoubleRangePanel wFreeRangePanel; + + protected QDTable qdTable; + + protected WTable wTable; + + protected TabSet tabs; + + /** + * Creates a new WQInputPanel instance. + */ + public WQInputPanel() { + qdTable = new QDTable(); + wTable = new WTable(); + + initTableListeners(); + } + + + /** + * Initializes the listeners of the WQD tables. + */ + protected void initTableListeners() { + CellClickHandler handler = new CellClickHandler() { + @Override + public void onCellClick(CellClickEvent e) { + if (isWMode() || qdTable.isLocked()) { + return; + } + + int idx = e.getColNum(); + Record r = e.getRecord (); + double val = r.getAttributeAsDouble("value"); + + if (idx == 0) { + if (isRangeMode()) { + qRangePanel.setFrom(val); + } + else { + qArrayPanel.addValue(val); + } + } + else if (idx == 1) { + if (isRangeMode()) { + qRangePanel.setTo(val); + } + else { + qArrayPanel.addValue(val); + } + } + } + }; + + qdTable.addCellClickHandler(handler); + } + + + /** + * This method calls createWidget and puts a 'next' button to the bottom. + * + * @param data The data that is displayed. + * + * @return the widget. + */ + @Override + public Canvas create(DataList data) { + initDefaults(data); + + Canvas widget = createWidget(data); + Canvas submit = getNextButton(); + Label label = new Label(MESSAGE.wqTitle()); + + label.setHeight(25); + + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + + layout.addMember(label); + layout.addMember(widget); + layout.addMember(submit); + + initHelperPanel(); + initUserDefaults(data); + + return layout; + } + + + /** Inits the helper panel. */ + // TODO duplicate in WQAdaptedInputPanel + protected void initHelperPanel() { + tabs = new TabSet(); + tabs.setWidth100(); + tabs.setHeight100(); + + Tab wTab = new Tab(MESSAGE.wq_table_w()); + Tab qTab = new Tab(MESSAGE.wq_table_q()); + + qdTable.showSelect(); + wTab.setPane(wTable); + qTab.setPane(qdTable); + + tabs.addTab(wTab, 0); + tabs.addTab(qTab, 1); + + helperContainer.addMember(tabs); + + fetchWQData(); + } + + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data dMode = getData(items, "wq_isq"); + Data dFree = getData(items, "wq_isfree"); + Data dSelection = getData(items, "wq_isrange"); + Data dSingle = getData(items, "wq_single"); + Data dFrom = getData(items, "wq_from"); + Data dTo = getData(items, "wq_to"); + Data dStep = getData(items, "wq_step"); + + DataItem[] mode = dMode.getItems(); + String strMode = mode[0].getStringValue(); + boolean isQMode = Boolean.valueOf(strMode); + + DataItem[] free = dFree.getItems(); + String strFree = free[0].getStringValue(); + boolean isFree = Boolean.valueOf(strFree); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + VLayout vLabel = null; + + DataItem[] selItem = dSelection.getItems(); + boolean isRange = selItem != null + ? Boolean.valueOf(selItem[0].getStringValue()) + : false; + + if (!isRange) { + DataItem[] single = dSingle.getItems(); + + vLabel = !isQMode + ? createWString(single[0]) + : createQString(single[0]); + } + else { + DataItem[] from = dFrom.getItems(); + DataItem[] to = dTo.getItems(); + DataItem[] step = dStep.getItems(); + + vLabel = !isQMode + ? createWString(from[0], to[0], step[0]) + : createQString(from[0], to[0], step[0]); + } + + VLayout selectedLayout = new VLayout(); + String wqMode = null; + + if (!isQMode) { + wqMode = isFree ? MESSAGE.wqWFree() : MESSAGE.wqW(); + } + else { + wqMode = isFree ? MESSAGE.wqQ() : MESSAGE.wqQGauge(); + } + + Label mLabel = new Label(wqMode); + mLabel.setWidth(175); + mLabel.setHeight(20); + + selectedLayout.addMember(mLabel); + selectedLayout.addMember(vLabel); + selectedLayout.setHeight(40); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(selectedLayout); + layout.addMember(back); + + return layout; + } + + + /** + * This method reads the default values defined in the DataItems of the Data + * objects in <i>list</i>. + * + * @param list The DataList container that stores the Data objects. + */ + protected void initDefaults(DataList list) { + Data f = getData(list.getAll(), "wq_from"); + Data t = getData(list.getAll(), "wq_to"); + Data s = getData(list.getAll(), "wq_step"); + + DataItem fQItem = getDataItem(f.getItems(), "minQ"); + DataItem fWItem = getDataItem(f.getItems(), "minW"); + DataItem tQItem = getDataItem(t.getItems(), "maxQ"); + DataItem tWItem = getDataItem(t.getItems(), "maxW"); + DataItem sQItem = getDataItem(s.getItems(), "stepQ"); + DataItem sWItem = getDataItem(s.getItems(), "stepW"); + DataItem fQFItem = getDataItem(f.getItems(), "minQFree"); + DataItem tQFItem = getDataItem(t.getItems(), "maxQFree"); + DataItem sQFItem = getDataItem(s.getItems(), "stepQFree"); + DataItem fWFItem = getDataItem(f.getItems(), "minWFree"); + DataItem tWFItem = getDataItem(t.getItems(), "maxWFree"); + DataItem sWFItem = getDataItem(s.getItems(), "stepWFree"); + + minW = Double.valueOf(fWItem.getStringValue()); + maxW = Double.valueOf(tWItem.getStringValue()); + stepW = Double.valueOf(sWItem.getStringValue()); + + minQ = Double.valueOf(fQItem.getStringValue()); + maxQ = Double.valueOf(tQItem.getStringValue()); + stepQ = Double.valueOf(sQItem.getStringValue()); + + minQFree = Double.valueOf(fQFItem.getStringValue()); + maxQFree = Double.valueOf(tQFItem.getStringValue()); + stepQFree = Double.valueOf(sQFItem.getStringValue()); + + minWFree = Double.valueOf(fWFItem.getStringValue()); + maxWFree = Double.valueOf(tWFItem.getStringValue()); + stepWFree = Double.valueOf(sWFItem.getStringValue()); + + this.fromW = minW; + this.toW = maxW; + + this.fromQ = minQ; + this.toQ = maxQ; + + this.fromQFree = minQFree; + this.toQFree = maxQFree; + + this.fromWFree = minWFree; + this.toWFree = maxWFree; + } + + + /** + * Initializes the form items with former inserted user data. + * + * @param list The DataList that contains the user data. + */ + protected void initUserDefaults(DataList list) { + List<Data> allData = list.getAll(); + + Data m = getData(allData, "wq_isq"); + DataItem modeItem = m != null ? m.getDefault() : null; + boolean isQ = modeItem != null + ? Boolean.valueOf(modeItem.getStringValue()) + : false; + + Data f = getData(allData, "wq_isfree"); + DataItem freeItem = f != null ? f.getDefault() : null; + boolean isFree = freeItem != null + ? Boolean.valueOf(freeItem.getStringValue()) + : false; + + Data s = getData(allData, "wq_isrange"); + DataItem sI = s != null ? s.getDefault() : null; + boolean isRange = sI != null + ? Boolean.valueOf(sI.getStringValue()) + : false; + + initUserSingleValues(list, isQ); + initUserRangeValues(list, isQ); + + if (isQ) { + modes.setValue(FIELD_WQ, isQ); + } + else { + modes.setValue(FIELD_WQ, isFree ? FIELD_WQ_Q_FREE : FIELD_WQ_Q); + } + + if(isRange) { + modes.setValue(FIELD_MODE, FIELD_MODE_RANGE); + } + else { + modes.setValue(FIELD_MODE, FIELD_MODE_SINGLE); + } + updatePanels(isQ, isFree, isRange); + } + + + /** + * Initializes the single values of W or Q from DataList. + * + * @param list The DataList that contains the 'wq_single' object. + * @param isQ W or Q mode? + */ + protected void initUserSingleValues(DataList list, boolean isQ) { + List<Data> allData = list.getAll(); + + + Data s = getData(allData, "wq_single"); + DataItem i = s != null ? s.getDefault() : null; + GWT.log("init values: " + i.getStringValue()); + + if (i != null) { + String value = i.getStringValue(); + String[] split = value.split(" "); + + int num = split != null ? split.length : 0; + + double[] values = new double[num]; + + for (int j = 0; j < num; j++) { + try { + values[j] = Double.valueOf(split[j]); + } + catch (NumberFormatException nfe) { + // nothing to do + } + } + + if (!isQ) { + setSingleW(values); + } + else { + setSingleQ(values); + } + } + } + + + /** + * Initializes the range values of W or Q from DataList. + * + * @param list The DataList that contains the 'wq_single' object. + * @param isQ W or Q mode? + */ + protected void initUserRangeValues(DataList list, boolean isQ) { + List<Data> allData = list.getAll(); + + // init range mode values + Data f = getData(allData, "wq_from"); + Data t = getData(allData, "wq_to"); + Data s = getData(allData, "wq_step"); + + if (f != null && t != null && s != null) { + DataItem dF = f.getDefault(); + DataItem dT = t.getDefault(); + DataItem dS = s.getDefault(); + + String fS = dF != null ? dF.getStringValue() : null; + String tS = dT != null ? dT.getStringValue() : null; + String sS = dS != null ? dS.getStringValue() : null; + + try { + double from = Double.valueOf(fS); + double to = Double.valueOf(tS); + double step = Double.valueOf(sS); + + if (!isQ) { + setWRangeValues(from, to, step); + } + else { + setQRangeValues(from, to, step); + } + } + catch (NumberFormatException nfe) { + // do nothing + } + } + } + + + protected void setQRangeValues(double f, double t, double s) { + setFromQ(f); + setToQ(t); + setStepQ(s); + } + + + protected void setWRangeValues(double f, double t, double s) { + setFromW(f); + setToW(t); + setStepW(s); + } + + + protected VLayout createWString(DataItem from, DataItem to, DataItem step) { + VLayout v = new VLayout(); + + StringBuilder sb = new StringBuilder(); + sb.append(from.getLabel()); + sb.append(" " + MESSAGE.unitWFrom() + " "); + sb.append(to.getLabel()); + sb.append(" " + MESSAGE.unitWTo() + " "); + sb.append(step.getLabel()); + sb.append(" " + MESSAGE.unitWStep()); + + v.addMember(new Label(sb.toString())); + + return v; + } + + + protected VLayout createWString(DataItem single) { + String label = single.getLabel().trim(); + String[] cols = label.split(";"); + + VLayout v = new VLayout(); + + for (String col: cols) { + Label l = new Label(col + " " + MESSAGE.unitWSingle()); + l.setHeight(20); + + v.addMember(l); + } + + return v; + } + + + protected VLayout createQString(DataItem from, DataItem to, DataItem step) { + VLayout v = new VLayout(); + + StringBuilder sb = new StringBuilder(); + sb.append(from.getLabel()); + sb.append(" " + MESSAGE.unitQFrom() + " "); + sb.append(to.getLabel()); + sb.append(" " + MESSAGE.unitQTo() + " "); + sb.append(step.getLabel()); + sb.append(" " + MESSAGE.unitQStep()); + + v.addMember(new Label(sb.toString())); + + return v; + } + + + protected VLayout createQString(DataItem single) { + String label = single.getLabel().trim(); + String[] cols = label.split(";"); + + VLayout v = new VLayout(); + + for (String col: cols) { + Label l = new Label(col + " " + MESSAGE.unitQSingle()); + l.setHeight(20); + + v.addMember(l); + } + + return v; + } + + + /** + * This method creates the whole widget. There is a panel on the left, that + * allows the user to enter values manually by keyboard. On the right, there + * is a table that allows the user to enter values by mouse click. + * + * @param data The data that is displayed in the table on the right. + * + * @return the widget. + */ + protected Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + container = new HLayout(); + Canvas modeForm = createModePanel(); + + container.setMembersMargin(30); + + // the initial panel is the Single-W panel. + double[] values = getSingleQ(); + qArrayPanel = new DoubleArrayPanel( + MESSAGE.unitQSingle(), values, this); + container.addMember(qArrayPanel); + + layout.addMember(modeForm); + layout.addMember(container); + + return layout; + } + + + /** + * This method creates the mode panel. It contains two radio button panels + * that allows the user to switch the input mode between w/q and + * single/range input. + * + * @return a panel. + */ + protected Canvas createModePanel() { + RadioGroupItem wq = new RadioGroupItem(FIELD_WQ); + wq.setShowTitle(false); + wq.setVertical(true); + wq.setWidth(WIDTH_LEFT_UPPER); + wq.setWrap(false); + + RadioGroupItem mode = new RadioGroupItem(FIELD_MODE); + mode.setShowTitle(false); + mode.setVertical(false); + mode.setWidth(WIDTH_LEFT_LOWER); + + LinkedHashMap wqValues = new LinkedHashMap(); + wqValues.put(FIELD_WQ_W, MESSAGE.wqW()); + wqValues.put(FIELD_WQ_W_FREE, MESSAGE.wqWFree()); + wqValues.put(FIELD_WQ_Q_FREE, MESSAGE.wqQ()); + wqValues.put(FIELD_WQ_Q, MESSAGE.wqQGauge()); + + LinkedHashMap modeValues = new LinkedHashMap(); + modeValues.put(FIELD_MODE_SINGLE, MESSAGE.wqSingle()); + modeValues.put(FIELD_MODE_RANGE, MESSAGE.wqRange()); + + wq.setValueMap(wqValues); + mode.setValueMap(modeValues); + + wq.addChangeHandler(this); + mode.addChangeHandler(this); + + modes = new DynamicForm(); + modes.setFields(wq, mode); + modes.setWidth(WIDTH_LEFT_UPPER); + modes.setNumCols(1); + + LinkedHashMap initial = new LinkedHashMap(); + initial.put(FIELD_WQ, FIELD_WQ_Q); + initial.put(FIELD_MODE, FIELD_MODE_SINGLE); + modes.setValues(initial); + + return modes; + } + + + @Override + public List<String> validate() { + if (isRangeMode()) { + return validateRangeValues(); + } + else { + return validateSingleValues(); + } + } + + + protected List<String> validateRangeValues() { + if (isWFree()) { + return validateRange(wFreeRangePanel, minWFree, maxWFree); + } + else if (isQFree()) { + return validateRange(qFreeRangePanel, minQFree, maxQFree); + } + else if (isWMode()) { + return validateRange(wRangePanel, minW, maxW); + } + else { + return validateRange(qRangePanel, minQ, maxQ); + } + } + + protected List<String> validateSingleValues() { + if (isWFree()) { + return validateSingle(wFreeArrayPanel, minWFree, maxWFree); + } + else if (isWMode()) { + return validateSingle(wArrayPanel, minW, maxW); + //return validateSingle(wArrayPanel, 0, 100000); + } + else if (isQFree()) { + return validateSingle(qFreeArrayPanel, minQFree, maxQFree); + } + else { + return validateSingle(qArrayPanel, minQ, maxQ); + } + } + + + protected List<String> validateRange( + DoubleRangePanel panel, + double min, double max) + { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + if (!panel.validateForm()) { + errors.add(MESSAGE.wrongFormat()); + } + + double from; + double to; + double step; + + try { + from = panel.getFrom(); + to = panel.getTo(); + step = panel.getStep(); + } + catch (NullPointerException npe) { + errors.add(MESSAGE.missingInput()); + return errors; + } + + if (from < min || from > max) { + String tmp = MESSAGE.error_validate_lower_range(); + tmp = tmp.replace("$1", nf.format(from)); + tmp = tmp.replace("$2", nf.format(min)); + errors.add(tmp); + from = min; + } + + if (to < min || to > max) { + String tmp = MESSAGE.error_validate_upper_range(); + tmp = tmp.replace("$1", nf.format(to)); + tmp = tmp.replace("$2", nf.format(max)); + errors.add(tmp); + to = max; + } + + if (!errors.isEmpty()) { + panel.setValues(from, to, step); + } + + return errors; + } + + + protected List<String> validateSingle( + DoubleArrayPanel panel, + double min, double max) + { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + if (!panel.validateForm()) { + errors.add(MESSAGE.wrongFormat()); + } + + double[] values = panel.getInputValues(); + + if (values == null || values.length == 0) { + errors.add(MESSAGE.atLeastOneValue()); + return errors; + } + + double[] good = new double[values.length]; + int idx = 0; + + for (double value: values) { + if (value < min || value > max) { + String tmp = MESSAGE.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(min)); + tmp = tmp.replace("$3", nf.format(max)); + errors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!errors.isEmpty()) { + panel.setValues(justGood); + } + + return errors; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + // XXX If we have entered a value and click right afterwards on the + // 'next' button, the BlurEvent is not fired, and the values are not + // saved. So, we gonna save those values explicitly. + if (!isRangeMode()) { + Canvas member = container.getMember(0); + if (member instanceof DoubleArrayPanel) { + DoubleArrayPanel form = (DoubleArrayPanel) member; + if (isWFree()) { + saveSingleWFreeValues(form); + } + else if (isWMode()) { + saveSingleWValues(form); + } + else if (isQFree()) { + saveSingleQFreeValues(form); + } + else { + saveSingleQValues(form); + } + } + + return getSingleData(); + } + else { + Canvas member = container.getMember(0); + if (member instanceof DoubleRangePanel) { + DoubleRangePanel form = (DoubleRangePanel) member; + + if (isWFree()) { + saveRangeWFreeValues(form); + } + else if (isWMode()) { + saveRangeWValues(form); + } + else if (isQFree()) { + saveRangeQFreeValues(form); + } + else { + saveRangeQValues(form); + } + } + + return getRangeData(); + } + } + + + /** + * Collects the required data for single mode and resets the data for range + * mode. + */ + protected Data[] getSingleData() { + DataItem from = new DefaultDataItem("wq_from", "wq_from", ""); + DataItem to = new DefaultDataItem("wq_to", "wq_to", ""); + DataItem step = new DefaultDataItem("wq_step", "wq_step", ""); + + return new Data[] { + getDataMode(), + getFree(), + getDataSelectionMode(), + getDataSingle(), + new DefaultData( + "wq_from", + null, + null, + new DataItem[] {from}), + new DefaultData( + "wq_to", + null, + null, + new DataItem[] {to}), + new DefaultData( + "wq_step", + null, + null, + new DataItem[] {step}) }; + } + + + /** + * Collects the required data for range mode and resets the data for single + * mode. + */ + protected Data[] getRangeData() { + DataItem item = new DefaultDataItem("wq_single", "wq_single", ""); + + return new Data[] { + getDataMode(), + getFree(), + getDataSelectionMode(), + getDataFrom(), + getDataTo(), + getDataStep(), + new DefaultData( + "wq_single", + null, + null, + new DataItem[] {item}) }; + } + + + /** + * Returns the Data object for the 'mode' attribute. + * + * @return the Data object for the 'mode' attribute. + */ + protected Data getDataMode() { + String wqMode = modes.getValueAsString(FIELD_WQ); + + String value = null; + if (wqMode.equals(FIELD_WQ_Q_FREE) || wqMode.equals(FIELD_WQ_Q)) { + GWT.log("getData: FIELD_WQ_Q || FIELD_WQ_Q_FREE"); + value = "true"; + } + else { + GWT.log("getData: FIELD_WQ_W || FIELD_WQ_W_FREE"); + value = "false"; + } + + DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value); + return new DefaultData( + "wq_isq", null, null, new DataItem[] { item }); + } + + + /** + * Returns the Q mode. The Q mode can be "true" or "false". True means, the + * calculation is not based on a gauge, false means the calculation should + * be based on a gauge. + * + * @return the Data object for the 'wq_free' attribute. + */ + protected Data getFree() { + String value = ""; + if(!isWMode()) { + value = isQFree() ? "true" : "false"; + } + else { + value = isWFree() ? "true" : "false"; + } + DataItem item = new DefaultDataItem("wq_isfree", "wq_isfree", value); + return new DefaultData( + "wq_isfree", null, null, new DataItem[] { item }); + } + + + /** + * Returns the Data object for the 'mode' attribute. + * + * @return the Data object for the 'mode' attribute. + */ + protected Data getDataSelectionMode() { + String wqSelection = modes.getValueAsString(FIELD_MODE); + + String isRange = "true"; + if (wqSelection.equals(FIELD_MODE_SINGLE)) { + isRange = "false"; + } + DataItem item = new DefaultDataItem( + "wq_isrange", "wq_isrange", isRange); + + return new DefaultData( + "wq_isrange", null, null, new DataItem[] { item }); + } + + + /** + * Returns the data object for the 'single' attribute. + * + * @return the Data object for the 'single' attribute. + */ + protected Data getDataSingle() { + double[] values = getFinalSingle(); + StringBuilder sb = new StringBuilder(); + for (double value: values) { + sb.append(Double.toString(value)); + sb.append(" "); + } + + DataItem item = new DefaultDataItem( + "wq_single", "wq_single", sb.toString()); + + return new DefaultData( + "wq_single", null, null, new DataItem[] { item }); + } + + + /** + * Returns the Data object for the 'from' attribute. + * + * @return the Data object for the 'from' attribute. + */ + protected Data getDataFrom() { + String value = Double.valueOf(getFinalFrom()).toString(); + DataItem item = new DefaultDataItem("wq_from", "wq_from", value); + return new DefaultData( + "wq_from", null, null, new DataItem[] { item }); + } + + + /** + * Returns the Data object for the 'to' attribute. + * + * @return the Data object for the 'to' attribute. + */ + protected Data getDataTo() { + String value = Double.valueOf(getFinalTo()).toString(); + DataItem item = new DefaultDataItem("wq_to", "wq_to", value); + return new DefaultData( + "wq_to", null, null, new DataItem[] { item }); + } + + + /** + * Returns the Data object for the 'step' attribute. + * + * @return the Data object for the 'step' attribute. + */ + protected Data getDataStep() { + String value = Double.valueOf(getFinalStep()).toString(); + DataItem item = new DefaultDataItem("wq_step","wq_step", value); + return new DefaultData( + "wq_step", null, null, new DataItem[] { item }); + } + + + protected double[] getFinalSingle() { + if (isWFree()) { + return getSingleWFree(); + } + else if (isWMode()) { + return getSingleW(); + } + else if (isQFree()) { + return getSingleQFree(); + } + else { + return getSingleQ(); + } + } + + + /** + * Returns the value of 'from' depending on the selected input mode. + * + * @return the value of 'from' depending on the selected input mode. + */ + protected double getFinalFrom() { + if (isRangeMode()) { + if (isWFree()) { + return getFromWFree(); + } + else if (isWMode()) { + return getFromW(); + } + else if (isQFree()) { + return getFromQFree(); + } + else { + return getFromQ(); + } + } + else { + double[] values = null; + + if (isWFree()) { + values = getSingleWFree(); + } + else if (isWMode()) { + values = getSingleW(); + } + else if (isQFree()) { + values = getSingleQFree(); + } + else { + values = getSingleQ(); + } + + double value = Double.MAX_VALUE; + for (double v: values) { + value = value < v ? value : v; + } + + return value; + } + } + + + /** + * Returns the value of 'to' depending on the selected input mode. + * + * @return the value of 'to' depending on the selected input mode. + */ + protected double getFinalTo() { + if (isRangeMode()) { + if (isWFree()) { + return getToWFree(); + } + else if (isWMode()) { + return getToW(); + } + else if (isQFree()) { + return getToQFree(); + } + else { + return getToQ(); + } + } + else { + double[] values = null; + + if (isWFree()) { + values = getSingleWFree(); + } + else if (isWMode()) { + values = getSingleW(); + } + else if (isQFree()) { + values = getSingleQFree(); + } + else { + values = getSingleQ(); + } + + double value = Double.MIN_VALUE; + for (double v: values) { + value = value > v ? value : v; + } + + return value; + } + } + + + /** + * Returns the value of 'step' depending on the selected input mode. + * + * @return the value of 'step' depending on the selected input mode. + */ + protected double getFinalStep() { + if (isRangeMode()) { + if (isWFree()) { + return getStepWFree(); + } + else if (isWMode()) { + return getStepW(); + } + else if (isQFree()) { + return getStepQFree(); + } + else { + return getStepQ(); + } + } + else { + // we have no field to enter the 'step' attribute in the + // single mode + return 0d; + } + } + + + /** + * Determines the range/single mode. + * + * @return true if the range mode is activated. + */ + public boolean isRangeMode() { + String rMode = modes.getValueAsString(FIELD_MODE); + + return rMode.equals(FIELD_MODE_RANGE); + } + + + /** + * Determines the w/q mode. + * + * @return true, if the W mode is activated. + */ + public boolean isWMode() { + String wq = modes.getValueAsString(FIELD_WQ); + return wq.contains("W"); + } + + + public boolean isQFree() { + String wqMode = modes.getValueAsString(FIELD_WQ); + return wqMode.equals(FIELD_WQ_Q_FREE); + } + + protected boolean isWFree() { + String wqMode = modes.getValueAsString(FIELD_WQ); + return wqMode.equals(FIELD_WQ_W_FREE); + } + + + /** + * This method changes the lower panel with the input fields depending on + * the combination of the two radio button panels. + * + * @param event The ChangeEvent. + */ + @Override + public void onChange(ChangeEvent event) { + DynamicForm form = event.getForm(); + FormItem item = event.getItem(); + + boolean isQ = false; + boolean isFree = false; + boolean isRange = false; + + if (item.getFieldName().equals(FIELD_MODE)) { + String wq = form.getValueAsString(FIELD_WQ); + isQ = wq.contains("Q"); + isFree = wq.contains("FREE"); + isRange = ((String) event.getValue()).equals(FIELD_MODE_RANGE); + } + else { + String wq = ((String) event.getValue()); + isQ = wq.contains("Q"); + isFree = wq.contains("FREE"); + isRange = + form.getValueAsString(FIELD_MODE).equals(FIELD_MODE_RANGE); + } + + if (isQ && isFree) { + qdTable.hideIconFields(); + } + else { + qdTable.showIconFields(); + } + + if (!isRange) { + qdTable.showSelect(); + } + else { + qdTable.showIconFields(); + } + + updatePanels(isQ, isFree, isRange); + } + + + protected void updatePanels(boolean isQ, boolean isFree, boolean isRange) { + container.removeMembers(container.getMembers()); + + if (!isQ && isFree) { + if (!isRange) { + // Single W mode + double[] values = getSingleWFree(); + + wFreeArrayPanel = new DoubleArrayPanel( + MESSAGE.unitWSingle(), values, this); + + container.addMember(wFreeArrayPanel); + } + else { + // Range W mode + double from = getFromWFree(); + double to = getToWFree(); + double step = getStepWFree(); + + wFreeRangePanel = new DoubleRangePanel( + MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), + from, to, step, + 250, + this); + container.addMember(wFreeRangePanel); + } + + tabs.selectTab(0); + } + else if (!isQ) { + if (!isRange) { + // Single W mode + double[] values = getSingleW(); + + wArrayPanel = new DoubleArrayPanel( + MESSAGE.unitWSingle(), values, this); + + container.addMember(wArrayPanel); + } + else { + // Range W mode + double from = getFromW(); + double to = getToW(); + double step = getStepW(); + + wRangePanel = new DoubleRangePanel( + MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), + from, to, step, + 250, + this); + container.addMember(wRangePanel); + } + + tabs.selectTab(0); + } + else if (isQ && isFree) { + if (!isRange) { + // Single Q mode + double[] values = getSingleQFree(); + + qFreeArrayPanel = new DoubleArrayPanel( + MESSAGE.unitQSingle(), values, this); + container.addMember(qFreeArrayPanel); + } + else { + // Range Q mode + double from = getFromQFree(); + double to = getToQFree(); + double step = getStepQFree(); + + qFreeRangePanel = new DoubleRangePanel( + MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), + from, to, step, + 250, + this); + container.addMember(qFreeRangePanel); + } + + tabs.selectTab(1); + } + else { + if (!isRange) { + // Single Q mode + double[] values = getSingleQ(); + + qArrayPanel = new DoubleArrayPanel( + MESSAGE.unitQSingle(), values, this); + container.addMember(qArrayPanel); + } + else { + // Range Q mode + double from = getFromQ(); + double to = getToQ(); + double step = getStepQ(); + + qRangePanel = new DoubleRangePanel( + MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), + from, to, step, + 250, + this); + container.addMember(qRangePanel); + } + + tabs.selectTab(1); + } + } + + /** + * This method is called if the value of one of the input fields might have + * changed. The entered values are validated and stored. + * + * @param event The BlurEvent. + */ + @Override + public void onBlur(BlurEvent event) { + DynamicForm form = event.getForm(); + FormItem item = event.getItem(); + + String wqMode = (String) modes.getValue(FIELD_WQ); + String inputMode = (String) modes.getValue(FIELD_MODE); + + if (wqMode.equals(FIELD_WQ_W)) { + if (inputMode.equals(FIELD_MODE_SINGLE)) { + DoubleArrayPanel p = (DoubleArrayPanel) form; + saveSingleWValue(p, item); + } + else { + DoubleRangePanel p = (DoubleRangePanel) form; + saveRangeWValue(p, item); + } + } + else if (wqMode.equals(FIELD_WQ_W_FREE)) { + if (inputMode.equals(FIELD_MODE_SINGLE)) { + DoubleArrayPanel p = (DoubleArrayPanel) form; + saveSingleWFreeValue(p, item); + } + else { + DoubleRangePanel p = (DoubleRangePanel) form; + saveRangeWFreeValue(p, item); + } + } + else if (wqMode.equals(FIELD_WQ_Q_FREE)) { + if (inputMode.equals(FIELD_MODE_SINGLE)) { + DoubleArrayPanel p = (DoubleArrayPanel) form; + saveSingleQFreeValue(p, item); + } + else { + DoubleRangePanel p = (DoubleRangePanel) form; + saveRangeQFreeValue(p, item); + } + } + else { + if (inputMode.equals(FIELD_MODE_SINGLE)) { + DoubleArrayPanel p = (DoubleArrayPanel) form; + saveSingleQValue(p, item); + } + else { + DoubleRangePanel p = (DoubleRangePanel) form; + saveRangeQValue(p, item); + } + } + } + + + protected void saveSingleWValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveSingleWValue(p, item); + } + } + } + + + protected void saveSingleWFreeValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveSingleWFreeValue(p, item); + } + } + } + + + protected void saveSingleQValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveSingleQValue(p, item); + } + } + } + + + protected void saveSingleQFreeValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveSingleQFreeValue(p, item); + } + } + } + + + protected void saveSingleWValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setSingleW(p.getInputValues(item)); + } + } + + + protected void saveSingleWFreeValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setSingleWFree(p.getInputValues(item)); + } + } + + + protected void saveSingleQValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setSingleQ(p.getInputValues(item)); + } + } + + + protected void saveSingleQFreeValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setSingleQFree(p.getInputValues(item)); + } + } + + + protected void saveRangeWValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveRangeWValue(p, item); + } + } + + + protected void saveRangeWFreeValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveRangeWFreeValue(p, item); + } + } + + + protected void saveRangeQValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveRangeQValue(p, item); + } + } + + + protected void saveRangeQFreeValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveRangeQFreeValue(p, item); + } + } + + + protected void saveRangeWValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm()) { + setFromW(p.getFrom()); + setToW(p.getTo()); + setStepW(p.getStep()); + } + } + + + protected void saveRangeWFreeValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm()) { + setFromWFree(p.getFrom()); + setToWFree(p.getTo()); + setStepWFree(p.getStep()); + } + } + + + protected void saveRangeQValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm()) { + setFromQ(p.getFrom()); + setToQ(p.getTo()); + setStepQ(p.getStep()); + } + } + + + protected void saveRangeQFreeValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm()) { + setFromQFree(p.getFrom()); + setToQFree(p.getTo()); + setStepQFree(p.getStep()); + } + } + + + protected double[] getSingleQ() { + return valuesQ; + } + + + protected double[] getSingleQFree() { + return valuesQFree; + } + + + protected void setSingleQ(double[] values) { + valuesQ = values; + } + + + protected void setSingleQFree(double[] values) { + valuesQFree = values; + } + + + protected double getFromQ() { + return fromQ; + } + + + protected double getFromQFree() { + return fromQFree; + } + + + protected void setFromQ(double fromQ) { + this.fromQ = fromQ; + } + + + protected void setFromQFree(double fromQ) { + this.fromQFree = fromQ; + } + + + protected double getToQ() { + return toQ; + } + + + protected double getToQFree() { + return toQFree; + } + + + protected void setToQ(double toQ) { + this.toQ = toQ; + } + + + protected void setToQFree(double toQ) { + this.toQFree = toQ; + } + + + protected double getStepQ() { + return stepQ; + } + + + protected double getStepQFree() { + return stepQFree; + } + + + protected void setStepQ(double stepQ) { + this.stepQ = stepQ; + } + + + protected void setStepQFree(double stepQ) { + this.stepQFree = stepQ; + } + + protected double[] getSingleW() { + return valuesW; + } + + protected double[] getSingleWFree() { + return valuesWFree; + } + + protected void setSingleW(double[] values) { + valuesW = values; + } + + protected void setSingleWFree(double[] values) { + valuesWFree = values; + } + + protected double getFromW() { + return fromW; + } + + protected double getFromWFree() { + return fromWFree; + } + + protected void setFromW(double fromW) { + this.fromW = fromW; + } + + protected void setFromWFree(double fromW) { + this.fromW = fromW; + } + + protected double getToW() { + return toW; + } + + protected double getToWFree() { + return toWFree; + } + + protected void setToW(double toW) { + this.toW = toW; + } + + protected void setToWFree(double toW) { + this.toWFree = toW; + } + + protected double getStepW() { + return stepW; + } + + protected double getStepWFree() { + return stepWFree; + } + + protected void setStepW(double stepW) { + this.stepW = stepW; + } + + protected void setStepWFree(double stepW) { + this.stepWFree = stepW; + } + + /** + * Determines the min and max kilometer value selected in a former state. A + * bit silly, but we need to run over each value of the "old data" to find + * such values because it is not available here. + * + * @param data The DataList which contains the whole data inserted for the + * current artifact. + * + * @return a double array with [min, max]. + */ + protected double[] getMinMaxKM(DataList[] data) { + ArtifactDescription adesc = artifact.getArtifactDescription(); + return adesc.getKMRange(); + } + + + /** + * Returns the name of the selected river. + * + * @param data The DataList with all data. + * + * @return the name of the current river. + */ + protected String getRiverName() { + ArtifactDescription adesc = artifact.getArtifactDescription(); + return adesc.getRiver(); + } + + + protected void fetchWQData() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + double[] mm = getMinMaxKM(data); + String river = getRiverName(); + + wqInfoService.getWQInfo(locale, river, mm[0], mm[1], + new AsyncCallback<WQInfoObject[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve wq informations."); + SC.warn(caught.getMessage()); + } + + @Override + public void onSuccess(WQInfoObject[] wqi) { + int num = wqi != null ? wqi.length :0; + GWT.log("Recieved " + num + " wq informations."); + + if (num == 0) { + return; + } + + addWQInfo(wqi); + + String wq = (String) modes.getValue(FIELD_WQ); + String sr = (String) modes.getValue(FIELD_MODE); + GWT.log("sending: " + wq + ", " + sr); + boolean isQ = wq.contains("Q"); + boolean isFree = wq.contains("FREE"); + boolean isRange = sr.equals(FIELD_MODE_RANGE); + + updatePanels(isQ, isFree, isRange); + } + } + ); + } + + + protected void addWQInfo (WQInfoObject[] wqi) { + for(WQInfoObject wi: wqi) { + WQInfoRecord rec = new WQInfoRecord(wi); + + if (wi.getType().equals("W")) { + wTable.addData(rec); + } + else { + qdTable.addData(rec); + } + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/WQSimpleArrayPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,497 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.RadioGroupItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.GaugeInfoService; +import de.intevation.flys.client.client.services.GaugeInfoServiceAsync; +import de.intevation.flys.client.client.services.WQInfoService; +import de.intevation.flys.client.client.services.WQInfoServiceAsync; +import de.intevation.flys.client.client.ui.wq.ClickableQDTable; +import de.intevation.flys.client.client.ui.wq.ClickableWTable; +import de.intevation.flys.client.client.ui.wq.ClickableWTable.ClickMode; +import de.intevation.flys.client.client.widgets.DischargeTablesChart; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.DoubleArrayData; +import de.intevation.flys.client.shared.model.Gauge; +import de.intevation.flys.client.shared.model.IntegerOptionsData; +import de.intevation.flys.client.shared.model.WQInfoObject; +import de.intevation.flys.client.shared.model.WQInfoRecord; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + + +/** + * An UIProvider for inserting a mode for W or Q and an array of values for each + * mode. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WQSimpleArrayPanel +extends AbstractUIProvider +implements BlurHandler +{ + private static final long serialVersionUID = 3223369196267895010L; + + public static final String FIELD_MODE = "field_mode"; + public static final String FIELD_VALUES = "field_values"; + + public static final int MODE_W = 0; + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected GaugeInfoServiceAsync gaugeService = + GWT.create(GaugeInfoService.class); + + protected WQInfoServiceAsync wqInfoService = + GWT.create(WQInfoService.class); + + protected String modeName; + protected String valuesName; + + protected Canvas valuesWrapper; + + protected TabSet tabs; + + protected DynamicForm modeForm; + protected DoubleArrayPanel panelW; + protected DoubleArrayPanel panelQ; + + protected ClickableWTable wTable; + protected ClickableQDTable qTable; + + + @Override + public Canvas create(DataList data) { + VLayout rootLayout = new VLayout(); + rootLayout.addMember(createLabel(data)); + rootLayout.addMember(createModeForm(data)); + rootLayout.addMember(createValuesForm(data)); + rootLayout.addMember(getNextButton()); + + initializeMode(data); + initializeTables(); + initializeHelperPanel(); + + return rootLayout; + } + + + @Override + public Canvas createOld(DataList dataList) { + IntegerOptionsData modeData = findOptionsData(dataList); + DoubleArrayData valuesData = findValuesData(dataList); + + DataItem[] modeItems = modeData.getItems(); + + HLayout layout = new HLayout(); + VLayout valueContainer = new VLayout(); + + Label label = new Label(dataList.getLabel()); + label.setWidth(200); + label.setHeight(20); + + Label mode = new Label(modeItems[0].getLabel()); + mode.setHeight(20); + mode.setWidth(150); + + Canvas values = createOldValues(modeData, valuesData); + values.setWidth(150); + + valueContainer.addMember(mode); + valueContainer.addMember(values); + + layout.addMember(label); + layout.addMember(valueContainer); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + + @Override + protected Data[] getData() { + Data mode = getModeAsData(); + + if (getMode() == MODE_W) { + return new Data[] { mode, getWValuesAsData() }; + } + else { + return new Data[] { mode, getQValuesAsData() }; + } + } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + + // TODO IMPLEMENT ME + + return errors; + } + + + @Override + public void onBlur(BlurEvent event) { + // TODO TRIGGER VALIDATION HERE + } + + + protected void initializeMode(DataList dataList) { + IntegerOptionsData data = findOptionsData(dataList); + DataItem[] items = data != null ? data.getItems() : null; + + if (items != null) { + String value = items[0].getStringValue(); + modeForm.setValue(modeName, value); + switchMode(value); + } + } + + + /** Initialize the w/q/d tables for the helper area. */ + protected void initializeTables() { + wTable = new ClickableWTable(new ClickableWTable.WClickedListener() { + @Override + public void clickedUpper(double value) { + // nothing to do here + } + + @Override + public void clickedLower(double value) { + panelW.addValue(value); + } + }, ClickMode.SINGLE, true); + + qTable = new ClickableQDTable(new ClickableQDTable.QClickedListener() { + + @Override + public void clickedUpper(double value) { + // nothing to do here + } + + @Override + public void clickedLower(double value) { + panelQ.addValue(value); + } + }, ClickableQDTable.ClickMode.SINGLE); + + fetchWQData(); + } + + + /** Put interactive tables to the helper area. */ + protected void initializeHelperPanel() { + tabs = new TabSet(); + tabs.setWidth100(); + tabs.setHeight100(); + + Tab w = new Tab(MSG.wq_table_w()); + Tab q = new Tab(MSG.wq_table_q()); + Tab c = new Tab(MSG.discharge_tables_chart()); + + w.setPane(wTable); + q.setPane(qTable); + c.setPane(new DischargeTablesChart(this.artifact)); + + tabs.addTab(w, 0); + tabs.addTab(q, 1); + tabs.addTab(c, 2); + + helperContainer.addMember(tabs); + } + + + protected void fetchWQData() { + ArtifactDescription desc = artifact.getArtifactDescription(); + + final String river = desc.getRiver(); + final String refGauge = desc.getReferenceGauge(); + + gaugeService.getGaugeInfo(river, refGauge, new AsyncCallback<List<Gauge>>() { + @Override + public void onFailure(Throwable throwable) { + GWT.log("ERROR WHILE FETCHING GAUGES!"); + } + + @Override + public void onSuccess(List<Gauge> gauges) { + Gauge g = gauges.get(0); + updateWQData(river, g.getLower(), g.getUpper()); + } + }); + } + + + protected void updateWQData(String river, double lower, double upper) { + GWT.log("FETCH WQ INFO FOR " + lower + " - " + upper + " now!"); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + wqInfoService.getWQInfo(locale, river, lower, upper, + new AsyncCallback<WQInfoObject[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve wq informations."); + } + + @Override + public void onSuccess(WQInfoObject[] wqi) { + int num = wqi != null ? wqi.length :0; + GWT.log("Recieved " + num + " wq informations."); + + if (num == 0) { + return; + } + + addWQInfo(wqi); + } + } + ); + } + + + protected void addWQInfo (WQInfoObject[] wqi) { + for(WQInfoObject wi: wqi) { + WQInfoRecord rec = new WQInfoRecord(wi); + + if (wi.getType().equals("W")) { + wTable.addData(rec); + } + else { + qTable.addData(rec); + } + } + } + + + protected Canvas createLabel(DataList dataList) { + Label label = new Label(MSG.wqHistorical()); + label.setWidth100(); + label.setHeight(25); + + return label; + } + + + protected Canvas createOldValues( + IntegerOptionsData modeData, + DoubleArrayData valuesData + ) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + + DataItem[] items = modeData.getItems(); + String unit = items[0].getStringValue().equals("0") ? "cm" : "m³/s"; + + VLayout layout = new VLayout(); + + for (double val: valuesData.getValues()) { + Label tmp = new Label(nf.format(val) + " " + unit); + tmp.setHeight(20); + layout.addMember(tmp); + } + + return layout; + } + + + protected DoubleArrayData findValuesData(DataList dataList) { + for (int i = 0, n = dataList.size(); i < n; i++) { + Data tmp = dataList.get(i); + + if (tmp instanceof DoubleArrayData) { + return (DoubleArrayData) tmp; + } + } + + return null; + } + + + protected IntegerOptionsData findOptionsData(DataList dataList) { + for (int i = 0, n = dataList.size(); i < n; i++) { + Data tmp = dataList.get(i); + + if (tmp instanceof IntegerOptionsData) { + return (IntegerOptionsData) tmp; + } + } + + return null; + } + + + protected Canvas createModeForm(DataList dataList) { + IntegerOptionsData data = findOptionsData(dataList); + DataItem[] opts = data != null ? data.getItems() : null; + + if (data == null || opts == null) { + return new Label("NO MODES FOUND"); + } + + modeName = data.getLabel(); + modeForm = new DynamicForm(); + + RadioGroupItem items = new RadioGroupItem(data.getLabel()); + LinkedHashMap values = new LinkedHashMap(); + + for (DataItem opt: opts) { + values.put(opt.getStringValue(), opt.getLabel()); + } + + items.setValueMap(values); + items.setVertical(false); + items.setShowTitle(false); + items.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent event) { + switchMode((String) event.getValue()); + } + }); + + modeForm.setFields(items); + + return modeForm; + } + + + protected Canvas createValuesForm(DataList dataList) { + DoubleArrayData data = findValuesData(dataList); + + if (data == null) { + return new Label("NO VALUES GIVEN!"); + } + + valuesName = data.getLabel(); + panelW = new DoubleArrayPanel(MSG.unitWSingle(), null, this); + panelQ = new DoubleArrayPanel(MSG.unitQSingle(), null, this); + + valuesWrapper = new Canvas(); + valuesWrapper.setWidth100(); + valuesWrapper.setHeight(35); + + return valuesWrapper; + } + + + public void switchMode(String newMode) { + for (Canvas child: valuesWrapper.getChildren()) { + valuesWrapper.removeChild(child); + } + + if (newMode.equals("0")) { + valuesWrapper.addChild(panelW); + showWTable(); + } + else if (newMode.equals("1")) { + valuesWrapper.addChild(panelQ); + showQDTable(); + } + } + + public void showWTable() { + if (tabs != null) { + tabs.selectTab(0); + } + } + + public void showQDTable() { + if (tabs != null) { + tabs.selectTab(1); + } + } + + + public String getModeAsString() { + return (String) modeForm.getValue(modeName); + } + + + public int getMode() { + String modeValue = getModeAsString(); + + try { + return Integer.valueOf(modeValue); + } + catch (NumberFormatException nfe) { + // do something + } + catch (NullPointerException npe) { + // do something + } + + return -1; + } + + + public Data getModeAsData() { + String value = getModeAsString(); + DataItem item = new DefaultDataItem(value, value, value); + + return new DefaultData(modeName, null, null, new DataItem[] { item }); + } + + + public Data getWValuesAsData() { + double[] values = panelW.getInputValues(); + String valueStr = getStringValue(values); + + DataItem item = new DefaultDataItem(valueStr, valueStr, valueStr); + + return new DefaultData(valuesName, null, null, new DataItem[] { item }); + } + + + public Data getQValuesAsData() { + double[] values = panelQ.getInputValues(); + String valueStr = getStringValue(values); + + DataItem item = new DefaultDataItem(valueStr, valueStr, valueStr); + + return new DefaultData(valuesName, null, null, new DataItem[] { item }); + } + + + protected static String getStringValue(double[] values) { + StringBuilder sb = new StringBuilder(); + boolean first = true; + + for (double value: values) { + if (first) { + sb.append(String.valueOf(value)); + first = false; + } + else { + sb.append(";" + String.valueOf(value)); + } + } + + return sb.toString(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,119 @@ +package de.intevation.flys.client.client.ui; + +public class WaterlevelGroundPanel extends DistancePanel { + + private static final long serialVersionUID = 6598703468619862469L; + + public static final String FIELD_LOWER = "diff_from"; + public static final String FIELD_UPPER = "diff_to"; + public static final String FIELD_STEP = "diff_diff"; + + + public WaterlevelGroundPanel() { + super("left"); + } + + + @Override + protected String getLowerField() { + return FIELD_LOWER; + } + + + @Override + protected String getUpperField() { + return FIELD_UPPER; + } + + + @Override + protected String getStepField() { + return FIELD_STEP; + } + + + @Override + protected String getLabel() { + return MSG.waterlevel_ground_state(); + } + + + @Override + protected String labelFrom() { + return getLabelFrom() + " [" + getUnitFrom() + "]"; + } + + + @Override + protected String getLabelFrom() { + return MSG.wgLabelFrom(); + } + + + @Override + protected String getUnitFrom() { + return MSG.wgUnitFrom(); + } + + + @Override + protected String labelTo() { + return getLabelTo() + " [" + getUnitTo() + "]"; + } + + + @Override + protected String getLabelTo() { + return MSG.wgLabelTo(); + } + + + @Override + protected String getUnitTo() { + return MSG.wgUnitTo(); + } + + + @Override + protected String labelStep() { + return getLabelStep() + " [" + getUnitStep() + "]"; + } + + + @Override + protected String getLabelStep() { + return MSG.wgLabelStep(); + } + + + @Override + protected String getUnitStep() { + return MSG.wgUnitStep(); + } + + + @Override + protected double getDefaultFrom() { + return 0; + } + + + @Override + protected double getDefaultTo() { + return 0; + } + + + @Override + protected double getDefaultStep() { + return 0; + } + + + @Override + protected void initHelperPanel() { + // We don't need a helper panel here. But we have to override this + // method to avoid the table creation in the parent class. + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,169 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.events.ClickEvent; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.StepForwardEvent; +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Recommendation.Facet; +import de.intevation.flys.client.shared.model.Recommendation.Filter; +import de.intevation.flys.client.shared.model.ToLoad; +import de.intevation.flys.client.shared.model.User; + +import java.util.List; +import java.util.Map; +import java.util.Set; + + +public class WspDatacagePanel extends DatacagePanel { + + private static final long serialVersionUID = 2494432743877141135L; + + public static final String WATERLEVEL_OUTS = "waterlevels"; + + public static final FLYSConstants MSG = GWT.create(FLYSConstants.class); + + + protected LoadArtifactServiceAsync loadService = + GWT.create(LoadArtifactService.class); + + protected Recommendation recommendation; + protected Artifact artifact; + + + public WspDatacagePanel() { + super(); + } + + + public WspDatacagePanel(User user) { + super(user); + } + + + @Override + public String getOuts() { + return WATERLEVEL_OUTS; + } + + + @Override + protected void createWidget() { + super.createWidget(); + widget.setIsMutliSelectable(false); + } + + + /** + * We need to override this method (defined in AbstractUIProvider) because + * we have to create a new Artifact specified by the Datacage selection via + * Async request. + * + * @param e The ClickEvent. + */ + @Override + public void onClick(ClickEvent e) { + List<String> errors = validate(); + if (errors == null || errors.isEmpty()) { + // 1) Fetch selected recommendation + Config config = Config.getInstance(); + final String locale = config.getLocale(); + final Collection c = this.collection; + final Recommendation r = getSelectedRecommendation(); + + + if (r == null) { + SC.warn(MSG.warning_no_wsp_selected()); + return; + } + + // 2) Create, load Artifact and fire event + loadService.load( + c, r, "winfo", locale, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("WspDatacagePanel", caught); + SC.warn(FLYS.getExceptionString(MSG, caught)); + } + + @Override + public void onSuccess(Artifact artifact) { + fireStepForwardEvent(new StepForwardEvent( + getData(r, artifact))); + } + } + ); + } + else { + showErrors(errors); + } + } + + + protected Recommendation getSelectedRecommendation() { + ToLoad toLoad = widget.getSelection(); + List<Recommendation> recoms = toLoad.toRecommendations(); + + return recoms.size() > 0 ? recoms.get(0) : null; + } + + + /** + * Nothing is done in this method. It returns null, because we serve the + * Data another way! + * + * @return always null! + */ + @Override + protected Data[] getData() { + // do nothing here, the Data is fetched on another way in this panel. + return null; + } + + + protected Data[] getData(Recommendation r, Artifact newArtifact) { + String uuid = newArtifact.getUuid(); + r.setMasterArtifact(uuid); + + String value = createDataString(uuid, r.getFilter()); + + DataItem item = new DefaultDataItem(dataName, dataName, value); + return new Data[] { new DefaultData( + dataName, null, null, new DataItem[] { item }) }; + } + + + protected String createDataString(String artifact, Filter filter) { + Facet f = null; + + Map<String, List<Facet>> outs = filter.getOuts(); + Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); + + for (Map.Entry<String, List<Facet>> entry: entries) { + List<Facet> fs = entry.getValue(); + + f = fs.get(0); + if (f != null) { + break; + } + } + + return "[" + artifact + ";" + f.getName() + ";" + f.getIndex() + "]"; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartOutputTab.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,762 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.event.OutputParameterChangeEvent; +import de.intevation.flys.client.client.event.OutputParameterChangeHandler; +import de.intevation.flys.client.client.event.PanEvent; +import de.intevation.flys.client.client.event.PanHandler; +import de.intevation.flys.client.client.event.RedrawRequestEvent; +import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.event.ZoomEvent; +import de.intevation.flys.client.client.event.ZoomHandler; +import de.intevation.flys.client.client.services.ChartInfoService; +import de.intevation.flys.client.client.services.ChartInfoServiceAsync; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; +import de.intevation.flys.client.shared.Transform2D; +import de.intevation.flys.client.shared.model.Axis; +import de.intevation.flys.client.shared.model.ChartInfo; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.ZoomObj; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; + + +/** + * Tab representing and showing one Chart-output (diagram). + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartOutputTab +extends OutputTab +implements ResizedHandler, + OutputParameterChangeHandler, + ZoomHandler, + PanHandler, + RedrawRequestHandler +{ + public static final int DEFAULT_CHART_WIDTH = 600; + public static final int DEFAULT_CHART_HEIGHT = 500; + + public static final int THEMEPANEL_MIN_WIDTH = 250; + + /** The service that is used to fetch chart information. */ + protected ChartInfoServiceAsync info = GWT.create(ChartInfoService.class); + + /** The ChartInfo object that provides information about the current + * chart. */ + protected ChartInfo chartInfo; + + /** Transformer used to transform image pixels into chart (data) coordinates. */ + protected Transform2D[] transformer; + + /** The collection view.*/ + protected CollectionView view; + + /** The ThemePanel to expose control over themes (facettes). */ + protected ChartThemePanel ctp; + + /** The canvas that wraps the chart toolbar. */ + protected ChartToolbar tbarPanel; + + /** The canvas that wraps the theme editor. */ + protected Canvas left; + + /** The canvas that wraps the chart. */ + protected Canvas right; + + protected Img chart; + + /** Chart zoom options. */ + protected int[] xrange; + protected int[] yrange; + + /** Stack of ZoomObj to allow 'redo last zoom'-kind of actions. */ + protected Stack<ZoomObj> zoomStack; + protected Number[] zoom; + + + /** + * The default constructor to create a new ChartOutputTab. + * + * @param title The title of this tab. + * @param collection The Collection which this chart belongs to. + * @param mode The OutputMode. + * @param collectionView The shown collection. + */ + public ChartOutputTab( + String title, + Collection collection, + OutputMode mode, + CollectionView collectionView + ){ + super(title, collection, collectionView, mode); + + view = collectionView; + left = new Canvas(); + right = new Canvas(); + xrange = new int[2]; + yrange = new int[2]; + zoomStack = new Stack<ZoomObj>(); + + zoom = new Number[] { + new Double(0), new Double(1), + new Double(0), new Double(1) }; + + left.setBorder("1px solid gray"); + left.setWidth(THEMEPANEL_MIN_WIDTH); + left.setMinWidth(THEMEPANEL_MIN_WIDTH); + right.setWidth("*"); + + VLayout vLayout = new VLayout(); + vLayout.setMembersMargin(2); + + HLayout hLayout = new HLayout(); + hLayout.setWidth100(); + hLayout.setHeight100(); + hLayout.setMembersMargin(10); + + hLayout.addMember(left); + hLayout.addMember(right); + + ctp = createThemePanel(mode, collectionView); + if (ctp != null) { + ctp.addRedrawRequestHandler(this); + ctp.addOutputParameterChangeHandler(this); + left.addChild(ctp); + } + else { + left.setVisible(false); + } + + chart = createChartImg(); + right.addChild(chart); + right.setOverflow(Overflow.HIDDEN); + + left.setShowResizeBar(true); + + tbarPanel = createChartToolbar(this); + vLayout.addMember(tbarPanel); + vLayout.addMember(hLayout); + vLayout.setOverflow(Overflow.HIDDEN); + + setPane(vLayout); + + right.addResizedHandler(this); + } + + + public ChartThemePanel createThemePanel( + OutputMode mode, CollectionView view + ) { + // Output "cross_section" needs slightly modified ThemePanel + // (with action buttons). + if (mode.getName().equals("cross_section")) { + return new CrossSectionChartThemePanel(mode, view); + } + else { + return new ChartThemePanel(mode, view); + } + } + + + public ChartToolbar createChartToolbar(ChartOutputTab tab) { + return new ChartToolbar(tab); + } + + + public void toggleThemePanel() { + this.left.setVisible(!left.isVisible()); + } + + + /** + * This method is called after the chart panel has resized. It removes the + * chart - if existing - and requests a new one with adjusted size. + * + * @param event The resize event. + */ + @Override + public void onResized(ResizedEvent event) { + updateChartPanel(); + updateChartInfo(); + } + + + /** For RESET type of events, just reset the ranges, otherwise do a + * complete refresh of panel, info and collection. */ + @Override + public void onRedrawRequest(RedrawRequestEvent event) { + if (event.getType() == Type.RESET) { + resetRanges(); + } + else { + ctp.updateCollection(); + updateChartPanel(); + updateChartInfo(); + } + } + + + /** + * Listens to change event in the chart them panel and updates chart after + * receiving such an event. + * + * @param event The OutputParameterChangeEvent. + */ + @Override + public void onOutputParameterChanged(OutputParameterChangeEvent event) { + updateChartInfo(); + updateChartPanel(); + } + + + /** + * Listens to zoom events and refreshes the current chart in such case. + * + * @param evt The ZoomEvent that stores the coordinates for zooming. + */ + @Override + public void onZoom(ZoomEvent evt) { + zoomStack.push(new ZoomObj(zoom[0], zoom[1], zoom[2], zoom[3])); + + xrange[0] = evt.getStartX(); + xrange[1] = evt.getEndX(); + yrange[0] = evt.getStartY(); + yrange[1] = evt.getEndY(); + + xrange[0] = xrange[0] < xrange[1] ? xrange[0] : xrange[1]; + yrange[0] = yrange[0] < yrange[1] ? yrange[0] : yrange[1]; + + translateCoordinates(); + + updateChartInfo(); + updateChartPanel(); + } + + + protected Number[] translateCoordinates() { + if (xrange == null || (xrange[0] == 0 && xrange[1] == 0)) { + zoom[0] = 0d; + zoom[1] = 1d; + } + else { + translateXCoordinates(); + } + + if (yrange == null || (yrange[0] == 0 && yrange[1] == 0)) { + zoom[2] = 0d; + zoom[3] = 1d; + } + else { + translateYCoordinates(); + } + + return zoom; + } + + + protected void translateXCoordinates() { + Axis xAxis = chartInfo.getXAxis(0); + + Number xmin = xAxis.getMin(); + Number xmax = xAxis.getMax(); + Number xRange = subtract(xmax, xmin); + + Transform2D transformer = getTransformer(0); + + double[] start = transformer.transform(xrange[0], yrange[0]); + double[] end = transformer.transform(xrange[1], yrange[1]); + + zoom[0] = divide(subtract(start[0], xmin), xRange); + zoom[1] = divide(subtract(end[0], xmin), xRange); + } + + + protected void translateYCoordinates() { + Axis yAxis = chartInfo.getYAxis(0); + + Number ymin = yAxis.getMin(); + Number ymax = yAxis.getMax(); + Number yRange = subtract(ymax, ymin); + + Transform2D transformer = getTransformer(0); + + double[] start = transformer.transform(xrange[0], yrange[0]); + double[] end = transformer.transform(xrange[1], yrange[1]); + + zoom[2] = divide(subtract(start[1], ymin), yRange); + zoom[3] = divide(subtract(end[1], ymin), yRange); + } + + + @Override + public void onPan(PanEvent event) { + if (chartInfo == null) { + return; + } + + int[] start = event.getStartPos(); + int[] end = event.getEndPos(); + + Transform2D t = getTransformer(); + + double[] ts = t.transform(start[0], start[1]); + double[] tt = t.transform(end[0], end[1]); + + double diffX = ts[0] - tt[0]; + double diffY = ts[1] - tt[1]; + + Axis xAxis = chartInfo.getXAxis(0); + Axis yAxis = chartInfo.getYAxis(0); + + Number[] x = panAxis(xAxis, diffX); + Number[] y = panAxis(yAxis, diffY); + + // Set the zoom coordinates. + zoom[0] = x[0]; + zoom[1] = x[1]; + zoom[2] = y[0]; + zoom[3] = y[1]; + + updateChartInfo(); + updateChartPanel(); + } + + + protected Number[] panAxis(Axis axis, double diff) { + Number min = axis.getFrom(); + Number max = axis.getTo(); + + min = add(min, diff); + max = add(max, diff); + + return computeZoom(axis, min, max); + } + + + public void resetRanges() { + zoomStack.push(new ZoomObj(zoom[0], zoom[1], zoom[2], zoom[3])); + + zoom[0] = 0d; + zoom[1] = 1d; + zoom[2] = 0d; + zoom[3] = 1d; + + updateChartInfo(); + updateChartPanel(); + } + + + /** + * This method zooms the current chart out by a given <i>factor</i>. + * + * @param factor The factor should be between 0-100. + */ + public void zoomOut(int factor) { + if (factor < 0 || factor > 100 || chartInfo == null) { + return; + } + + zoomStack.push(new ZoomObj(zoom[0], zoom[1], zoom[2], zoom[3])); + + Axis xAxis = chartInfo.getXAxis(0); + Axis yAxis = chartInfo.getYAxis(0); + + Number[] x = zoomAxis(xAxis, factor); + Number[] y = zoomAxis(yAxis, factor); + + zoom[0] = x[0]; + zoom[1] = x[1]; + zoom[2] = y[0]; + zoom[3] = y[1]; + + updateChartInfo(); + updateChartPanel(); + } + + + /** + * This method is used to zoom out. Zooming out is realized with a stacked + * logic. Initially, you cannot zoom out. For each time you start a zoom-in + * action, the extent of the chart is stored and pushed onto a stack. A + * zoom-out will now lead you to the last extent that is popped from stack. + */ + public void zoomOut() { + if (!zoomStack.empty()) { + zoom = zoomStack.pop().getZoom(); + + updateChartInfo(); + updateChartPanel(); + } + } + + + public Number[] zoomAxis(Axis axis, int factor) { + GWT.log("Prepare Axis for zooming (factor: " + factor + ")"); + + Number min = axis.getMin(); + Number max = axis.getMax(); + Number range = isBigger(max, min) ? subtract(max, min) : subtract(min, max); + + Number curFrom = axis.getFrom(); + Number curTo = axis.getTo(); + + Number diff = isBigger(curTo, curFrom) + ? subtract(curTo, curFrom) + : subtract(curFrom, curTo); + + GWT.log(" max from : " + min); + GWT.log(" max to : " + max); + GWT.log(" max range : " + range); + GWT.log(" current from: " + curFrom); + GWT.log(" current to : " + curTo); + GWT.log(" current diff: " + diff); + + Number newFrom = subtract(curFrom, divide(multi(diff, factor), 100)); + Number newTo = add(curTo, divide(multi(diff, factor), 100)); + + GWT.log(" new from: " + newFrom); + GWT.log(" new to : " + newTo); + + return new Number[] { + divide(subtract(newFrom, min), range), + divide(subtract(newTo, min), range) + }; + } + + + public static Number[] computeZoom(Axis axis, Number min, Number max) { + Number[] hereZoom = new Number[2]; + + Number absMin = axis.getMin(); + Number absMax = axis.getMax(); + Number diff = isBigger(absMax, absMin) + ? subtract(absMax, absMin) + : subtract(absMin, absMax); + + hereZoom[0] = divide(subtract(min, absMin), diff); + hereZoom[1] = divide(subtract(max, absMin), diff); + + return hereZoom; + } + + + /** Get Collection from ChartThemePanel. .*/ + public Collection getCtpCollection() { + return this.ctp.getCollection(); + } + + + /** + * Updates the Transform2D object using the chart info service. + */ + public void updateChartInfo() { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + info.getChartInfo( + view.getCollection(), + locale, + mode.getName(), + getChartAttributes(), + new AsyncCallback<ChartInfo>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("ChartInfo ERROR: " + caught.getMessage()); + } + + @Override + public void onSuccess(ChartInfo chartInfo) { + setChartInfo(chartInfo); + } + }); + } + + + public void updateChartPanel() { + int w = right.getWidth(); + int h = right.getHeight(); + + chart.setSrc(getImgUrl(w, h)); + } + + + /** + * Returns the existing chart panel. + * + * @return the existing chart panel. + */ + public Canvas getChartPanel() { + return right; + } + + + /** Access the Canvas holding the rendered Chart. */ + public Canvas getChartImg() { + return chart; + } + + + /** Get associated ChartInfo object. */ + public ChartInfo getChartInfo() { + return chartInfo; + } + + + protected void setChartInfo(ChartInfo chartInfo) { + this.chartInfo = chartInfo; + } + + + public Transform2D getTransformer() { + return getTransformer(0); + } + + + /** + * Returns the Transform2D object used to transform image coordinates into + * chart (data) coordinates. + * + * @param pos The index of a specific transformer. + * + * @return the Transform2D object. + */ + public Transform2D getTransformer(int pos) { + if (chartInfo == null) { + return null; + } + + return chartInfo.getTransformer(pos); + } + + + /** + * Returns the Transform2D count. + * + * @return the Transformer2D count + */ + public int getTransformerCount() { + if (chartInfo == null) { + return 0; + } + + return chartInfo.getTransformerCount(); + } + + + /** + * Creates a new chart panel with default size. + * + * @return the created chart panel. + */ + protected Img createChartImg() { + return createChartImg(DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT); + } + + + /** + * Creates a new chart panel with specified width and height. + * + * @param width The width for the chart panel. + * @param height The height for the chart panel. + * + * @return the created chart panel. + */ + protected Img createChartImg(int width, int height) { + Img chart = getChartImg(width, height); + chart.setWidth100(); + chart.setHeight100(); + + return chart; + } + + + /** + * Builds the chart image and returns it. + * + * @param width The chart width. + * @param height The chart height. + * + * @return the chart image. + */ + protected Img getChartImg(int width, int height) { + return new Img(getImgUrl(width, height)); + } + + + /** + * Builds the URL that points to the chart image. + * + * @param width The width of the requested chart. + * @param height The height of the requested chart. + * @param xr Optional x range (used for zooming). + * @param yr Optional y range (used for zooming). + * + * @return the URL to the chart image. + */ + protected String getImgUrl(int width, int height) { + Config config = Config.getInstance(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "chart"; + imgUrl += "?uuid=" + collection.identifier(); + imgUrl += "&type=" + mode.getName(); + imgUrl += "&locale=" + config.getLocale(); + imgUrl += "×tamp=" + new Date().getTime(); + imgUrl += "&width=" + Integer.toString(width); + imgUrl += "&height=" + Integer.toString(height); + + Number[] zoom = getZoomValues(); + + if (zoom != null) { + if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + imgUrl += "&minx=" + zoom[0]; + imgUrl += "&maxx=" + zoom[1]; + } + + if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + imgUrl += "&miny=" + zoom[2]; + imgUrl += "&maxy=" + zoom[3]; + } + } + + return imgUrl; + } + + + /** Get link to export image in given dimension and format. */ + public String getExportUrl(int width, int height, String format) { + String url = getImgUrl(width, height); + url += "&format=" + format; + url += "&export=true"; + + return url; + } + + + public Map <String, String> getChartAttributes() { + Map<String, String> attr = new HashMap<String, String>(); + + Canvas chart = getChartPanel(); + attr.put("width", chart.getWidth().toString()); + attr.put("height", chart.getHeight().toString()); + + Number[] zoom = getZoomValues(); + + if (zoom != null) { + if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + attr.put("minx", zoom[0].toString()); + attr.put("maxx", zoom[1].toString()); + } + if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + attr.put("miny", zoom[2].toString()); + attr.put("maxy", zoom[3].toString()); + } + } + + return attr; + } + + + protected Number[] getZoomValues() { + return zoom; + } + + + /** Return the 'parent' CollectionView. */ + public CollectionView getView() { + return this.view; + } + + + public static Number subtract(Number left, Number right) { + if (left instanceof Double) { + return new Double(left.doubleValue() - right.doubleValue()); + } + else if (left instanceof Long) { + return new Long(left.longValue() - right.longValue()); + } + else { + return new Integer(left.intValue() - right.intValue()); + } + } + + + /** Add two numbers, casting to Type of param left. */ + public static Number add(Number left, Number right) { + if (left instanceof Double) { + return new Double(left.doubleValue() + right.doubleValue()); + } + else if (left instanceof Long) { + return new Long(left.longValue() + right.longValue()); + } + else { + return new Integer(left.intValue() + right.intValue()); + } + } + + + /** Divde left by right. Note that Long will be casted to double. */ + public static Number divide(Number left, Number right) { + if (left instanceof Double) { + return new Double(left.doubleValue() / right.doubleValue()); + } + else if (left instanceof Long) { + return new Double(left.doubleValue() / right.doubleValue()); + } + else { + return new Integer(left.intValue() / right.intValue()); + } + } + + + public static Number multi(Number left, Number right) { + if (left instanceof Double) { + return new Double(left.doubleValue() * right.doubleValue()); + } + else if (left instanceof Long) { + return new Long(left.longValue() * right.longValue()); + } + else { + return new Integer(left.intValue() * right.intValue()); + } + } + + + public static boolean isBigger(Number left, Number right) { + if (left instanceof Double) { + return left.doubleValue() > right.doubleValue(); + } + else if (left instanceof Long) { + return left.longValue() > right.longValue(); + } + else { + return left.intValue() > right.intValue(); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartPropertiesEditor.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,601 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.CollectionAttributeService; +import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; +import de.intevation.flys.client.client.utils.DoubleValidator; +import de.intevation.flys.client.client.utils.IntegerValidator; +import de.intevation.flys.client.shared.model.BooleanProperty; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.DoubleProperty; +import de.intevation.flys.client.shared.model.IntegerProperty; +import de.intevation.flys.client.shared.model.OutputSettings; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertyGroup; +import de.intevation.flys.client.shared.model.PropertySetting; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.StringProperty; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Dialog for the Chart-Properties, constructed from respective xml document. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class ChartPropertiesEditor +extends Window +implements ClickHandler +{ + /** The interface that provides i18n messages. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** CollectionAttribute Update Service. */ + protected CollectionAttributeServiceAsync updater = + GWT.create(CollectionAttributeService.class); + + /** The tab called the editor window. */ + protected ChartOutputTab tab; + + /** The tabset for chart properties. */ + protected TabSet tabs; + + /** The collection. */ + protected Collection collection; + + /** The cloned output settings. */ + protected OutputSettings settings; + + /** The original output settings. */ + protected OutputSettings origSettings; + + + + /** + * Setup editor dialog. + * @param callerTab The tab called the editor window. + */ + public ChartPropertiesEditor(ChartOutputTab callerTab) { + this.tab = callerTab; + this.tabs = new TabSet(); + + init(); + } + + + /** + * Initialize the editor window and its components. + */ + protected void init() { + setTitle(MSG.properties()); + setCanDragReposition(true); + setCanDragResize(true); + + collection = tab.getCollectionView().getCollection(); + String outputName = tab.getOutputName(); + origSettings = (OutputSettings)collection.getSettings(outputName); + + settings = (OutputSettings)origSettings.clone(); + if (settings == null) { + return; + } + List<String> list = settings.getCategories(); + + for (int i = 0; i < list.size(); i++) { + Tab t = new Tab(MSG.getString(list.get(i))); + List<Property> props = settings.getSettings(list.get(i)); + List<Property> origProps = origSettings.getSettings(list.get(i)); + VLayout layout = new VLayout(); + for (int j = 0; j < props.size(); j++) { + if (props.get(j) instanceof PropertyGroup) { + layout.addMember(generatePropertyGroup(props.get(j), + origProps.get(j))); + } + else if (props.get(j) instanceof PropertySetting) { + PropertySetting p = (PropertySetting)props.get(j); + if (p.getAttribute("display").equals("false")) { + continue; + } + layout.addMember(generatePropertySetting(props.get(j), + origProps.get(j))); + } + } + t.setPane(layout); + tabs.addTab(t); + } + + Button accept = new Button(MSG.label_ok()); + Button cancel = new Button(MSG.label_cancel()); + cancel.addClickHandler(this); + accept.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + if(isDialogValid()) { + updateCollection(); + } + else { + GWT.log("Dialog not valid"); + SC.warn(MSG.error_dialog_not_valid()); + } + } + }); + + HLayout buttons = new HLayout(); + buttons.addMember(accept); + buttons.addMember(cancel); + buttons.setAlign(Alignment.CENTER); + buttons.setHeight(30); + + addItem(tabs); + addItem(buttons); + setWidth(380); + setHeight(470); + centerInPage(); + } + + + /** + * This method is called when the user aborts theming. + * @param event The event. + */ + @Override + public void onClick(ClickEvent event) { + this.destroy(); + } + + + /** + * Create a section from group (usually axis properties). + */ + protected Canvas generatePropertyGroup(Property group, Property orig) { + PropertyGroup pg = (PropertyGroup)group; + PropertyGroup origPg = (PropertyGroup)orig; + + if (pg.getName().equals("axis")) { + Label scale = new Label(MSG.scale() + " :"); + scale.setHeight(25); + scale.setMargin(2); + + DynamicForm form1 = new DynamicForm(); + DynamicForm form2 = new DynamicForm(); + form2.setNumCols(6); + + StringProperty label = + (StringProperty)pg.getPropertyByName("label"); + FormItem title = createStringProperty(label); + title.setValue( + ((StringProperty)origPg.getPropertyByName("label")).getValue()); + + IntegerProperty fontsize = + (IntegerProperty)pg.getPropertyByName("font-size"); + FormItem fs = createIntegerProperty(fontsize); + fs.setValue( + ((IntegerProperty) + origPg.getPropertyByName("font-size")).getValue()); + + DoubleProperty upper = + (DoubleProperty)pg.getPropertyByName("upper"); + final FormItem range1 = createDoubleProperty(upper); + range1.setName("rangeupper"); + range1.setWidth(70); + range1.setValue( + ((DoubleProperty) + origPg.getPropertyByName("upper")).toUIString()); + + DoubleProperty lower = + (DoubleProperty)pg.getPropertyByName("lower"); + final FormItem range2 = createDoubleProperty(lower); + range2.setName("rangelower"); + range2.setWidth(70); + range2.setValue( + ((DoubleProperty) + origPg.getPropertyByName("lower")).toUIString()); + + BooleanProperty fixation = + (BooleanProperty)pg.getPropertyByName("fixation"); + FormItem fix = createBooleanProperty(fixation); + fix.setValue(((BooleanProperty) + origPg.getPropertyByName("fixation")).getValue().booleanValue()); + + fix.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent e) { + if ((Boolean)e.getValue()) { + range1.enable(); + range2.enable(); + } + else { + range1.disable(); + range2.disable(); + } + } + }); + if (fix.getValue().toString().equals("true")) { + range1.enable(); + range2.enable(); + } + else { + range1.disable(); + range2.disable(); + } + + form1.setFields(title, fs); + form2.setFields(fix, range2, range1); + + HLayout scaleLayout = new HLayout(); + scaleLayout.setHeight(30); + scaleLayout.addMember(scale); + scaleLayout.addMember(form2); + scaleLayout.setStyleName("property-dialog-axis"); + + VLayout root = new VLayout(); + root.addMember(form1); + root.addMember(scaleLayout); + root.setHeight(90); + + return root; + } + return null; + } + + + /** + * Generate a form with items for the properties/settings, preset with + * values. + */ + protected DynamicForm generatePropertySetting( + Property setting, + Property orig) + { + DynamicForm form = new DynamicForm(); + FormItem item = new FormItem(); + if (setting instanceof BooleanProperty) { + item = createBooleanProperty((BooleanProperty)setting); + item.setValue(((BooleanProperty)orig).getValue().booleanValue()); + } + else if (setting instanceof DoubleProperty) { + item = createDoubleProperty((DoubleProperty)setting); + item.setValue(((DoubleProperty)orig).toUIString()); + } + else if (setting instanceof IntegerProperty) { + item = createIntegerProperty((IntegerProperty)setting); + item.setValue(((IntegerProperty)orig).getValue()); + } + else if (setting instanceof StringProperty) { + StringProperty property = (StringProperty) setting; + item = createStringProperty(property); + item.setValue(((StringProperty)orig).getValue()); + } + else { + GWT.log("generatePropertySetting: unknown setting type."); + } + form.setFields(item); + return form; + } + + + protected FormItem createStringProperty(final StringProperty sp) { + String name = sp.getName(); + if (name.contains("-")) { + name = name.replace("-", "_"); + } + + String choiceAttribute = sp.getAttribute("choice"); + + if (choiceAttribute != null && choiceAttribute.equals("logo")) { + SelectItem logoChooser = new SelectItem(); + logoChooser.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/logo-"); + logoChooser.setValueIconHeight(50); + logoChooser.setValueIconWidth(100); + + LinkedHashMap valueMap = new LinkedHashMap<String, String>(); + LinkedHashMap<String, String> valueIcons = new LinkedHashMap<String, String>(); + valueMap.put("none", MSG.getString("none")); + /* + If you want to add images, remember to change code in these places: + flys-artifacts: + XYChartGenerator.java + Timeseries*Generator.java and + in the flys-client projects Chart*Propert*Editor.java. + Also, these images have to be put in + flys-artifacts/src/main/resources/images/ + flys-client/src/main/webapp/images/ + */ + valueMap.put("BfG", ""); + valueMap.put("Intevation", ""); + valueIcons.put("BfG", "bfg.gif"); + valueIcons.put("Intevation", "intevation.png"); + logoChooser.setValueIcons(valueIcons); + logoChooser.setValueMap(valueMap); + logoChooser.setTitleStyle("color:#000;"); + logoChooser.setTitleAlign(Alignment.LEFT); + logoChooser.setTitle(MSG.getString(name)); + logoChooser.setTitleAlign(Alignment.LEFT); + logoChooser.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + String val; + if (e.getItem().getValue() == null) { + val = ""; + } + else { + val = e.getItem().getValue().toString(); + } + sp.setValue(val); + } + }); + return logoChooser; + } + else if (choiceAttribute != null && choiceAttribute.equals("placeh")) { + SelectItem placeChooser = new SelectItem(); + LinkedHashMap valueMap = new LinkedHashMap<String, String>(); + valueMap.put("right", MSG.getString("right")); + valueMap.put("left", MSG.getString("left")); + valueMap.put("center", MSG.getString("center")); + placeChooser.setValueMap(valueMap); + placeChooser.setTitleStyle("color:#000;"); + placeChooser.setTitleAlign(Alignment.LEFT); + placeChooser.setTitle(MSG.getString(name)); + placeChooser.setTitleAlign(Alignment.LEFT); + placeChooser.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + String val; + if (e.getItem().getValue() == null) { + val = ""; + } + else { + val = e.getItem().getValue().toString(); + } + sp.setValue(val); + } + }); + return placeChooser; + } + else if (choiceAttribute != null && choiceAttribute.equals("placev")) { + SelectItem placeChooser = new SelectItem(); + LinkedHashMap valueMap = new LinkedHashMap<String, String>(); + valueMap.put("top", MSG.getString("top")); + valueMap.put("bottom", MSG.getString("bottom")); + valueMap.put("center", MSG.getString("center")); + placeChooser.setValueMap(valueMap); + placeChooser.setTitleStyle("color:#000;"); + placeChooser.setTitleAlign(Alignment.LEFT); + placeChooser.setTitle(MSG.getString(name)); + placeChooser.setTitleAlign(Alignment.LEFT); + placeChooser.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + String val; + if (e.getItem().getValue() == null) { + val = ""; + } + else { + val = e.getItem().getValue().toString(); + } + sp.setValue(val); + } + }); + return placeChooser; + } + + TextItem item = new TextItem(); + item.setTitle(MSG.getString(name)); + item.setTitleAlign(Alignment.LEFT); + item.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + String val; + if (e.getItem().getValue() == null) { + val = ""; + } + else { + val = e.getItem().getValue().toString(); + } + sp.setValue(val); + } + }); + return item; + } + + + /** + * + */ + protected FormItem createBooleanProperty(final BooleanProperty bp) { + String name = bp.getName(); + if (name.contains("-")) { + name = name.replace("-", "_"); + } + + CheckboxItem item = new CheckboxItem("item", MSG.getString(name)); + item.setLabelAsTitle(true); + item.setTitleStyle("color:#000;"); + item.setTitleAlign(Alignment.LEFT); + item.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + String val; + if (e.getItem().getValue() == null) { + val = ""; + } + else { + val = e.getItem().getValue().toString(); + } + bp.setValue(val); + } + }); + return item; + } + + + /** + * + */ + protected FormItem createDoubleProperty(final DoubleProperty dp) { + String name = dp.getName(); + if (name.contains("-")) { + name = name.replace("-", "_"); + } + + TextItem item = new TextItem(); + item.setTitle(MSG.getString(name)); + item.setTitleAlign(Alignment.LEFT); + item.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + DoubleValidator validator = new DoubleValidator(); + Map errors = e.getForm().getErrors(); + if(validator.validate(e.getItem(), errors)) { + dp.setValueFromUI(e.getItem().getValue().toString()); + } + e.getForm().setErrors(errors, true); + } + }); + return item; + } + + + /** + * + */ + protected FormItem createIntegerProperty(final IntegerProperty ip) { + String name = ip.getName(); + if (name.contains("-")) { + name = name.replace("-", "_"); + } + + TextItem item = new TextItem(); + item.setTitle(MSG.getString(name)); + item.setTitleAlign(Alignment.LEFT); + item.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + IntegerValidator validator = new IntegerValidator(); + Map errors = e.getForm().getErrors(); + if(validator.validate(e.getItem(), errors)) { + ip.setValue(e.getItem().getValue().toString()); + } + e.getForm().setErrors(errors, true); + } + }); + return item; + } + + + protected void updateCollection() { + final Config config = Config.getInstance(); + final String loc = config.getLocale(); + + GWT.log("PropertiesEditor.updateCollection via RPC now"); + + Settings s = settings; + collection.addSettings(this.tab.getOutputName(), s); + updater.update(collection, loc, new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not update collection attributes."); + SC.warn(MSG.getString(caught.getMessage())); + } + @Override + public void onSuccess(Collection collection) { + updateChartTab(); + } + }); + } + + protected void updateChartTab() { + this.tab.updateChartInfo(); + this.tab.updateChartPanel(); + this.destroy(); + } + + + protected boolean isDialogValid() { + boolean valid = true; + for (int i = 0; i < tabs.getNumTabs(); i++) { + Tab t = tabs.getTab(i); + Canvas container = t.getPane(); + Canvas[] children = container.getChildren(); + for (Canvas c: children) { + valid = validateCanvas(c); + if(!valid) { + return valid; + } + } + } + return valid; + } + + + protected boolean validateCanvas(Canvas c) { + boolean valid = true; + if(c instanceof DynamicForm) { + DynamicForm f = (DynamicForm) c; + FormItem up = f.getItem("rangeupper"); + FormItem lo = f.getItem("rangelower"); + + if(up != null && lo != null && + !up.isDisabled() && !lo.isDisabled()) + { + validateRange(f); + } + return !f.hasErrors(); + } + else if(c.getChildren().length > 0) { + for (Canvas child: c.getChildren()) { + valid = validateCanvas(child); + if(!valid) { + return valid; + } + } + } + return valid; + } + + protected boolean validateRange(DynamicForm form) { + Map errors = form.getErrors(); + FormItem up = form.getItem("rangeupper"); + FormItem lo = form.getItem("rangelower"); + + String v1 = up.getValue().toString(); + String v2 = lo.getValue().toString(); + + if(v1.equals(v2)) { + errors.put(up.getFieldName(), MSG.wrongFormat()); + errors.put(lo.getFieldName(), MSG.wrongFormat()); + form.setErrors(errors, true); + return false; + } + return true; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartThemePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,461 @@ +package de.intevation.flys.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 de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.FeedServiceAsync; +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.ThemePanel; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DefaultArtifact; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.FacetRecord; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; + + +/** + * ThemePanel on the left in CollectionView. + * Contains control widgets for "themes", which are plotted in a diagram (chart). + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +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"; + + FeedServiceAsync feedService = GWT.create( + de.intevation.flys.client.client.services.FeedService.class); + + + /** Constructor for a ChartThemePanel. */ + public ChartThemePanel( + OutputMode mode, + CollectionView view + ) { + super(mode, view); + + initGrid(); + initLayout(); + + updateGrid(); + } + + + /** Creates Layout with theme list and navigation bar inside. */ + protected VLayout createLayout() { + VLayout layout = new VLayout(); + layout.setWidth100(); + layout.setHeight100(); + + layout.addMember(list); + layout.addMember(navigation); + + return layout; + } + + + /** + * Initializes the layout of this panel. + */ + protected void initLayout() { + setWidth100(); + setHeight100(); + + addChild(createLayout()); + } + + + /** + * Initializes the components (columns) of the theme grid. + */ + 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(); + + list.addEditCompleteHandler(this); + + ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); + active.setType(ListGridFieldType.BOOLEAN); + + ListGridField name = new ListGridField( + GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); + name.setType(ListGridFieldType.TEXT); + + list.setFields(active, name); + } + + + /** Set theme active/inactive. */ + @Override + public void activateTheme(Theme theme, 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(); + } + + + /** + * Tell an area artifact where to get the upper and lower curve from. + * @param artifact UUID of area-artifact. + */ + public void feedTellArea( + final String artifact, + Theme under, + Theme over, + 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") + }; + 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") + }; + 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") + }; + GWT.log("Have 'over' curve only"); + } + 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(); + } + }); + } + + + /** + * Create and parameterize a new area artifact. + * @param under + * @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(); + + Recommendation area = new Recommendation( + "area", + "", + "", + null); + 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); + } + } + ); + } + + + /** + * 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. + */ + protected boolean areAreaCompatible(Theme a, Theme b) { + if (a.equals(b)) { + return false; + } + if (a.getFacet().equals("longitudinal_section.w") || + a.getFacet().equals("other.wkms")) { + return b.getFacet().equals("longitudinal_section.w") + || b.getFacet().equals("other.wkms"); + } + else if (a.getFacet().equals("longitudinal_section.q")) { + return b.getFacet().equals("longitudinal_section.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("other.wkms"); + } + + + /** Attach menu/item to open editor for Manual Points. */ + protected void attachManualPointsMenu(Menu menu) { + menu.addItem(createSeparator()); + MenuItem editManualPoints = new MenuItem(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(); + } + } + }); + 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 Theme facetTheme = ((FacetRecord)records[0]).getTheme(); + + if (!canArea(facetTheme)) { + if (facetTheme.getFacet().endsWith("manualpoints")) { + attachManualPointsMenu(menu); + return menu; + } + else { + return menu; + } + } + + menu.addItem(createSeparator()); + + MenuItem areaMenuItem = new MenuItem(MSG.chart_themepanel_new_area()); + Menu areaMenu = new Menu(); + + ThemeList themes = getThemeList(); + 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); + + if (theme.getVisible() == 0) { + continue; + } + + if (!areAreaCompatible(facetTheme, theme)) { + continue; + } + + MenuItem againster = new MenuItem(theme.getDescription()); + underMenu.addItem(againster); + + againster.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + disable(); + createAreaArtifact(theme, facetTheme, false); + } + }); + } + + // 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); + if (theme.getVisible() == 0) { + continue; + } + if (!areAreaCompatible(facetTheme, theme)) { + continue; + } + MenuItem againster = new MenuItem(theme.getDescription()); + overMenu.addItem(againster); + + againster.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + disable(); + createAreaArtifact(facetTheme, theme, false); + } + }); + } + overMenu.addItem(createSeparator()); + MenuItem againstAxis = new MenuItem(MSG.getString("x_axis")); + againstAxis.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + disable(); + createAreaArtifact(null, facetTheme, false); + } + }); + 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); + if (theme.getVisible() == 0) { + continue; + } + if (!areAreaCompatible(facetTheme, theme)) { + continue; + } + MenuItem againster = new MenuItem(theme.getDescription()); + betweenMenu.addItem(againster); + + againster.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + disable(); + createAreaArtifact(facetTheme, theme, true); + } + }); + } + betweenMenu.addItem(createSeparator()); + betweenMenu.addItem(againstAxis); + + overMenuItem.setSubmenu(overMenu); + underMenuItem.setSubmenu(underMenu); + betweenMenuItem.setSubmenu(betweenMenu); + + areaMenu.addItem(betweenMenuItem); + areaMenu.addItem(overMenuItem); + areaMenu.addItem(underMenuItem); + areaMenu.addItem(createSeparator()); + MenuItem standAloneAgainstAxis = new MenuItem(MSG.getString("against_x_axis")); + standAloneAgainstAxis.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + disable(); + createAreaArtifact(null, facetTheme, false); + } + }); + areaMenu.addItem(standAloneAgainstAxis); + + areaMenuItem.setSubmenu(areaMenu); + menu.addItem(areaMenuItem); + + return menu; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartToolbar.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,338 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.ImgButton; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.ZoomEvent; +import de.intevation.flys.client.client.event.ZoomHandler; +import de.intevation.flys.client.client.ui.ImgLink; +import de.intevation.flys.client.client.ui.Toolbar; + + +/** + * Toolbar with buttons/icons to open datacage, switch to zoom mode, zoom out + * etc. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartToolbar extends Toolbar implements ZoomHandler { + + protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public static final int PANEL_HEIGHT = 35; + + protected Button manageThemes; + protected Button datacage; + protected ImgLink downloadPNG; + protected ImgLink downloadPDF; + protected ImgLink downloadSVG; + protected Canvas downloadCSV; + protected MousePositionPanel position; + protected ZoomboxControl zoombox; + protected ImgButton zoomToMaxExtent; + protected ImgButton historyBack; + protected ImgButton zoomOut; + protected ImgButton chartProperties; + protected Button addPoints; + protected Button addWSP; + protected ImgLink exportAT; + protected PanControl panControl; + + + /** @param chartTab Output-Tab on which this toolbar is located. */ + public ChartToolbar(ChartOutputTab chartTab) { + super(chartTab); + initTools(); + } + + + protected void initTools() { + ChartOutputTab chartTab = getChartOutputTab(); + + manageThemes = new Button(MSG.manageThemes()); + datacage = new Button(MSG.databasket()); + position = new MousePositionPanel(chartTab); + zoombox = new ZoomboxControl(chartTab, MSG.zoom_in()); + zoomToMaxExtent = new ImgButton(); + zoomOut = new ImgButton(); + historyBack = new ImgButton(); + panControl = new PanControl(chartTab, MSG.pan()); + chartProperties = new ImgButton(); + addPoints = new Button(MSG.points()); + + if (chartTab.getMode().getName().equals("cross_section")) { + addWSP = new Button(MSG.addWSPButton()); + addWSP.setTooltip(MSG.addWSPTooltip()); + final ChartOutputTab finalChartTab = chartTab; + addWSP.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent ce) { + new ManualWSPEditor(finalChartTab.getView().getCollection(), + finalChartTab, finalChartTab.getMode().getName()).show(); + }}); + } + + addPoints.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + openPointWindow(); + } + }); + addPoints.setTooltip(MSG.addPointsTooltip()); + + manageThemes.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + getChartOutputTab().toggleThemePanel(); + } + }); + + datacage.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + GWT.log("Clicked 'datacage' button."); + openDatacageWindow((ChartOutputTab) getOutputTab()); + } + }); + + String baseUrl = GWT.getHostPageBaseURL(); + String moduleUrl = GWT.getModuleBaseURL(); + Config config = Config.getInstance(); + + if (chartTab.getMode().getName().equals("fix_wq_curve")) { + exportAT = new ImgLink( + baseUrl + MSG.downloadCSV(), + moduleUrl + "export" + + "?uuid=" + chartTab.getCollection().identifier() + + "&name=" + chartTab.getMode().getName() + + "&mode=" + chartTab.getMode().getName() + "_at_export" + + "&type=at" + + "&server=" + config.getServerUrl() + + "&locale=" + config.getLocale() + + "&km=" + chartTab.getCollectionView().getCurrentKm(), + 20, + 20 + ); + exportAT.setTooltip(MSG.exportATTooltip()); + } + + downloadPNG = new ImgLink( + baseUrl + MSG.downloadPNG(), + chartTab.getExportUrl(-1, -1, "png"), + 20, + 20); + downloadPNG.setTooltip(MSG.downloadPNGTooltip()); + + downloadPDF = new ImgLink( + baseUrl + MSG.downloadPDF(), + chartTab.getExportUrl(1280, 1024, "pdf"), + 20, + 20); + downloadPDF.setTooltip(MSG.downloadPDFTooltip()); + + downloadSVG = new ImgLink( + baseUrl + MSG.downloadSVG(), + chartTab.getExportUrl(1280, 1024, "svg"), + 20, + 20); + downloadSVG.setTooltip(MSG.downloadSVGTooltip()); + + downloadCSV = new ImgLink( + baseUrl + MSG.downloadCSV(), + chartTab.getExportUrl(-1, -1, "csv"), + 20, + 20); + downloadCSV.setTooltip(MSG.downloadCSVTooltip()); + + zoomToMaxExtent.setSrc(baseUrl + MSG.zoom_all()); + adjustImageButton(zoomToMaxExtent); + zoomToMaxExtent.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + getChartOutputTab().resetRanges(); + // Relink the export buttons. + onZoom(null); + } + }); + zoomToMaxExtent.setTooltip(MSG.zoomToMaxExtentTooltip()); + + zoomOut.setSrc(baseUrl + MSG.zoom_out()); + adjustImageButton(zoomOut); + zoomOut.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + getChartOutputTab().zoomOut(10); + // Relink the export buttons. + onZoom(null); + } + }); + zoomOut.setTooltip(MSG.zoomOutTooltip()); + + historyBack.setSrc(baseUrl + MSG.zoom_back()); + adjustImageButton(historyBack); + historyBack.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + getChartOutputTab().zoomOut(); + // Relink the export buttons. + onZoom(null); + } + }); + historyBack.setTooltip(MSG.historyBackTooltip()); + + zoombox.addZoomHandler(chartTab); + zoombox.addZoomHandler(this); + zoombox.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + panControl.deselect(); + } + }); + zoombox.setTooltip(MSG.zoomboxTooltip()); + + panControl.addPanHandler(chartTab); + panControl.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + zoombox.deselect(); + } + }); + panControl.setTooltip(MSG.panControlTooltip()); + + chartProperties.setSrc(baseUrl + MSG.properties_ico()); + adjustImageButton(chartProperties); + chartProperties.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + openPropertiesEditor(); + } + }); + chartProperties.setTooltip(MSG.chartPropertiesTooltip()); + + initLayout(); + } + + /** Set width, height and other properties of an imagebutton. */ + public void adjustImageButton(ImgButton imgButton) { + imgButton.setWidth(20); + imgButton.setHeight(20); + imgButton.setShowDown(false); + imgButton.setShowRollOver(false); + imgButton.setShowRollOverIcon(false); + imgButton.setShowDisabled(false); + imgButton.setShowDisabledIcon(true); + imgButton.setShowDownIcon(false); + imgButton.setShowFocusedIcon(false); + } + + + protected ChartOutputTab getChartOutputTab() { + return (ChartOutputTab)getOutputTab(); + } + + + protected void initLayout() { + setWidth100(); + setHeight(PANEL_HEIGHT); + setMembersMargin(10); + setPadding(5); + setBorder("1px solid black"); + + Label spacer = new Label(); + spacer.setWidth("*"); + datacage.setWidth("95px"); + position.setWidth("200px"); + + addMember(manageThemes); + addMember(datacage); + addMember(downloadPNG); + addMember(downloadPDF); + addMember(downloadSVG); + addMember(downloadCSV); + if (getChartOutputTab().getMode().getName().equals("fix_wq_curve")) { + addMember(exportAT); + } + addMember(zoomToMaxExtent); + addMember(historyBack); + addMember(zoomOut); + addMember(zoombox); + addMember(panControl); + addMember(chartProperties); + addMember(addPoints); + + if (getChartOutputTab().getMode().getName().equals("cross_section")) { + addMember(addWSP); + } + + addMember(spacer); + addMember(position); + } + + /** + * Open the chart property editor dialog. + */ + protected void openPropertiesEditor() { + ChartPropertiesEditor editor = + new ChartPropertiesEditor(getChartOutputTab()); + editor.show(); + } + + + /** Open editor for custom points. */ + protected void openPointWindow() { + ChartOutputTab chartTab = getChartOutputTab(); + if (chartTab.getMode().getName().equals("historical_discharge")) { + new ManualDatePointsEditor(chartTab.getView().getCollection(), + chartTab, chartTab.getMode().getName()).show(); + } + else { + new ManualPointsEditor(chartTab.getView().getCollection(), + chartTab, chartTab.getMode().getName()).show(); + } + } + + + /** + * Sets new sources to the export button/images, such that the + * correct zoom values are included in the request when clicked. + * @param evt ignored. + */ + @Override + public void onZoom(ZoomEvent evt) { + ChartOutputTab chartTab = getChartOutputTab(); + downloadPNG.setSource(chartTab.getExportUrl(-1, -1, "png")); + downloadPDF.setSource(chartTab.getExportUrl(-1, -1, "pdf")); + downloadSVG.setSource(chartTab.getExportUrl(-1, -1, "svg")); + } + + public void deselectControls() { + zoombox.deselect(); + } + + public void updateLinks() { + ChartOutputTab chartTab = getChartOutputTab(); + String moduleUrl = GWT.getModuleBaseURL(); + Config config = Config.getInstance(); + + if (chartTab.getMode().getName().equals("fix_wq_curve")) { + exportAT.setSource( + moduleUrl + "export" + + "?uuid=" + chartTab.getCollection().identifier() + + "&mode=" + chartTab.getMode().getName() + "_at_export" + + "&type=at" + + "&server=" + config.getServerUrl() + + "&locale=" + config.getLocale() + + "&km=" + chartTab.getCollectionView().getCurrentKm()); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/CrossSectionChartThemePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,722 @@ +package de.intevation.flys.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.Canvas; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; +import com.smartgwt.client.widgets.grid.ListGrid; +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 de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.services.CrossSectionKMServiceAsync; +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.widgets.KMSpinner; +import de.intevation.flys.client.client.widgets.KMSpinnerChangeListener; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DefaultArtifact; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.FacetRecord; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + + +/** + * ThemePanel much like ChartThemePanel, but shows an "Actions" column, + * needed for interaction in the CrossSection Charts and a selector to + * declare which cross section profile is "master" (waterlevels refer to the + * chosen kilometer of that cross section profile). + * Also can show 'area creation' context menus. + */ +public class CrossSectionChartThemePanel +extends ChartThemePanel +implements KMSpinnerChangeListener +{ + /** Artifact Clone/Creation service. */ + protected LoadArtifactServiceAsync loadService = + GWT.create(LoadArtifactService.class); + + /** Service to query measurement points of cross sections. */ + CrossSectionKMServiceAsync kmService = GWT.create( + de.intevation.flys.client.client.services.CrossSectionKMService.class); + + /** UUID of the current "master" cross section. */ + protected String currentCSMasterUUID; + + /** The layout (used for visual active/inactive feedback). */ + protected VLayout layout; + + /** Data item name for CrossSections selected km. */ + protected static String CS_KM = "cross_section.km"; + + /** Data item name for CrossSections selected km. */ + protected static String CS_IS_MASTER = "cross_section.master?"; + + /** List of cross-section themes through which is moved through synchronously. */ + protected HashSet synchronCrossSectionThemes = new HashSet(); + + /** Data for master artifact combobox.*/ + protected LinkedHashMap<String, String> masters; + + /** Combobox for master artifacts.*/ + protected SelectItem masterCb; + + + /** + * Trivial constructor. + */ + public CrossSectionChartThemePanel( + OutputMode mode, + CollectionView view) + { + super(mode, view); + } + + + /** Create DefaultArtifact. */ + public static DefaultArtifact artifactReference(String uuid) { + return new DefaultArtifact(uuid, "TODO:hash"); + } + + + /** Access data of collection item of theme. */ + public static String dataOf(Theme theme, String dataItemName) { + if (theme != null && theme.getCollectionItem() != null + && theme.getCollectionItem().getData() != null + ) { + return theme.getCollectionItem().getData().get(dataItemName); + } + + return null; + } + + + /** + * Feed an artifact to let it know that it is master wrt cross-sections. + * @param artifact uuid of an artifact. + */ + public void feedTellMaster(final String artifact) { + Data[] feedData = DefaultData.createSimpleStringDataArray( + CS_IS_MASTER, "1"); + + feedService.feed( + Config.getInstance().getLocale(), + artifactReference(artifact), + feedData, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not feed artifact (" + artifact + + ") with master marker: " + caught.getMessage()); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully injected master mark to " + artifact); + setCurrentCSMaster(artifact.getUuid()); + requestRedraw(); + enable(); + } + }); + } + + + /** + * Sets currentCSMasterUUID. + */ + public String findCurrentCSMaster() { + ThemeList themeList = getThemeList(); + int count = getThemeList().getThemeCount(); + String firstCSUuid = null; + + for (int i = 1; i <= count; i++) { + Theme theme = themeList.getThemeAt(i); + String value = dataOf(theme, CS_IS_MASTER); + + if (value != null) { + if (firstCSUuid == null) { + firstCSUuid = theme.getArtifact(); + } + if (!value.equals("0")) { + setCurrentCSMaster(theme.getArtifact()); + GWT.log("found a master: " + currentCSMasterUUID + + "/" + theme.getDescription()); + return theme.getDescription(); + } + } + } + // There is none selected. Take the first one. + if (firstCSUuid != null) { + setCurrentCSMaster(firstCSUuid); + feedTellMaster(firstCSUuid); + } + return null; + } + + + /** + * Create Layout, add a master selection box beneath. + */ + @Override + protected VLayout createLayout() { + layout = super.createLayout(); + + // Create "set master" combobox. + masterCb = new SelectItem(); + + masterCb.setTitle(MSG.chart_themepanel_set_master()); + masterCb.setType("comboBox"); + masters = getThemeList().toMapArtifactUUIDDescription("cross_section"); + masterCb.setValueMap(masters); + + final DynamicForm form = new DynamicForm(); + form.setWidth(200); + form.setFields(masterCb); + layout.addMember(form, 0); + + Config config = Config.getInstance(); + final String locale = config.getLocale(); + findCurrentCSMaster(); + masterCb.setValue(getCurrentCSMaster()); + + // Add Change Handler to first unset the old master and then set the + // new master. + masterCb.addChangeHandler(new ChangeHandler() { + @Override + public void onChange(ChangeEvent event) { + String selectedItem = (String) event.getValue(); + final String artifact = selectedItem; + + disable(); + + // Tell current master that he is not master anymore. + if (getCurrentCSMaster() != null) { + Data[] feedData = DefaultData.createSimpleStringDataArray( + CS_IS_MASTER, "0"); + feedService.feed( + locale, + artifactReference(getCurrentCSMaster()), + feedData, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not un-master artifact (" + + getCurrentCSMaster() + "): " + + caught.getMessage()); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + @Override + public void onSuccess(Artifact oldMaster) { + GWT.log("Successfully un-mastered artifact."); + feedTellMaster(artifact); + } + }); + } + else { + feedTellMaster(artifact); + } + } + }); + + return layout; + } + + + /** Disable the UI (becomes gray, inresponsive to user input). */ + @Override + public void disable() { + this.layout.setDisabled(true); + } + + + /** DisDisable the UI (becomes ungray, responsive to user input). */ + @Override + public void enable() { + this.layout.setDisabled(false); + } + + + /** + * Returns a double from the list that has the smallest distance to the + * given to value. In case of multiple values with the same difference, + * the last one is taken. + * @param in possible return values. + * @param to the value to be as close to as possible. + * @param up if true, prefer numerically higher values in case of two + * values with equal distance to \param to. + * @return value from in that is closest to to, -1 if none. + */ + public static double closest(Double[] in, double to, boolean up) { + if (in == null || in.length == 0) { + return -1; + } + if (in[0] == to) { + return to; + } + for (int i = 0; i < in.length; i++) { + GWT.log ("Close? " + in[i]); + } + + double minDiff = Math.abs(to - in[0]); + double bestMatch = in[0]; + for (int i = 1; i < in.length; i++) { + if (in[i] == to) { + return to; + } + if ((in[i] < to && up) + || (in[i] > to && !up)) { + continue; + } + double diff = Math.abs(to - in[i]); + if (diff <= minDiff) { + minDiff = diff; + bestMatch = in[i]; + } + } + return bestMatch; + } + + + /** + * Feed a single artifact with the km of the crosssection to display. + * If its the selected master, also feed the collectionmaster. + * + * @param artifacts List of artifacts to feed. + * @param kmD The km to set. + */ + public void sendFeed(final List<Artifact> artifacts, final double kmD) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + Data[] feedData = + DefaultData.createSimpleStringDataArray(CS_KM, + Double.valueOf(kmD).toString()); + + disable(); + // TODO + // The ones who do not have data for this km should not show line! + feedService.feedMany( + locale, + artifacts, + feedData, + new AsyncCallback<List<Artifact>>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not feed many artifacts " + caught.getMessage()); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + @Override + public void onSuccess(List<Artifact> artifact) { + GWT.log("Successfully fed many with km"); + requestRedraw(); + enable(); + } + }); + } + + + /** + * Feed a single artifact with the km of the crosssection to display. + * If its the selected master, also feed the collectionmaster. + * @param artUUID The UUID of the artifact to feed. + * @param kmD The km to set. + */ + public void sendFeed(final String artUUID, final double kmD) { + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + Data[] feedData = + DefaultData.createSimpleStringDataArray(CS_KM, + Double.valueOf(kmD).toString()); + + disable(); + feedService.feed( + locale, + artifactReference(artUUID), + feedData, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not feed artifact " + caught.getMessage()); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully fed with km"); + requestRedraw(); + enable(); + } + }); + } + + + /** Remove the themes, also from the master (reference) select box. */ + @Override + protected void removeThemes(final ListGridRecord[] records) { + // TODO take care of what happens if that was the last + // cross section and/or the cross section currently selected as master. + for (ListGridRecord record: records) { + FacetRecord facet = (FacetRecord) record; + Theme theme = facet.getTheme(); + masters.remove(theme.getArtifact()); + } + masterCb.setValueMap(masters); + super.removeThemes(records); + } + + + /** + * Callback for when a value has been accepted in the km-spinner + * of a Cross-Section Profile theme. + * @param item The SpinnerItem which was manipulated. + * @param enteredKm The double-parsed value that has been entered. + * @param facetRecord The underlying datastores record. + * @param up If true, numerically higher values are preferred if + * two values in \param in are in the same distance to + * \param to. + */ + @Override + public void spinnerValueEntered(KMSpinner spinner, final double enteredKm, final FacetRecord facetRecord, final boolean up) { + disable(); + Config config = Config.getInstance(); + final String locale = config.getLocale(); + + Map<Integer, Double> map = new HashMap<Integer,Double>(); + int _dbid = -1; + try { + _dbid = Integer.valueOf(facetRecord.getTheme() + .getCollectionItem() + .getData().get("cross_section.dbid")); + } + catch (NumberFormatException nfe) { + GWT.log("Could not extract cross-section db id from data."); + } + final int dbid = _dbid; + + map.put(dbid, enteredKm); + + // Query the available cross section measurements. + kmService.getCrossSectionKMs(locale, map, 2, + new AsyncCallback<Map<Integer, Double[]>>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not get single km for " + + dbid + ": "+ caught.getMessage()); + SC.warn(MSG.getString(caught.getMessage())); + updateCollection(); + //updateGrid(); + enable(); + } + + @Override + public void onSuccess(Map<Integer, Double[]> obj) { + Double[] kms = obj.get(dbid); + double closest = + CrossSectionChartThemePanel.closest(kms, enteredKm, up); + GWT.log("Got single km close to " + enteredKm + " for " + dbid + ", it is " + + closest); + + // Do not set value, as it will trigger strange + // "javascript" bugs. /*item.setValue(closest);*/ + if (synchronCrossSectionThemes.contains (themeHash + (facetRecord.getTheme()))) { + // Move all other synchrons + ThemeList themes = getThemeList(); + int nThemes = themes.getThemeCount(); + List<Artifact> artifacts = new ArrayList<Artifact>(); + for (int i = 0; i < nThemes; i++) { + final Theme theme = themes.getThemeAt(i+1); + if (theme.getFacet().equals("cross_section") && + theme.getActive() == 1 && + synchronCrossSectionThemes.contains(themeHash(theme)) + ) { + artifacts.add(artifactReference(theme.getArtifact())); + } + } + sendFeed(artifacts, closest); + } + else { + sendFeed(facetRecord.getTheme().getArtifact(), + closest); + } + } + }); + } + + + /** + * Create and configure the Grid to display. + * @return ListGrid with Themes and related controls inside. + */ + @Override + protected ListGrid createGrid() { + final CrossSectionChartThemePanel parent = this; + + ListGrid list = new ListGrid() { + @Override + protected Canvas createRecordComponent( + final ListGridRecord record, + Integer colNum) + { + // Only cross_section Facets display an action widget. + final FacetRecord facetRecord = (FacetRecord) record; + if (!facetRecord.getTheme().getFacet().equals( + "cross_section")) + { + return null; + } + + String fieldName = this.getFieldName(colNum); + + if (fieldName.equals(GRID_FIELD_ACTIONS)) { + double currentValue = + Double.valueOf(facetRecord.getTheme().getCollectionItem().getData().get(CS_KM)); + KMSpinner kmSpinner = new KMSpinner(currentValue, facetRecord); + kmSpinner.addChangeListener(parent); + return kmSpinner; + } + else { + return null; + } + } + }; + list.setCanResizeFields(true); + list.setShowRecordComponents(true); + list.setShowRecordComponentsByCell(true); + list.setShowAllRecords(true); + list.setShowHeaderContextMenu(false); + list.setLeaveScrollbarGap(false); + return list; + } + + + /** + * Initializes the components (columns) of the theme grid. + */ + @Override + protected void initGrid() { + list.setCanEdit(true); + list.setCanSort(false); + list.setShowRecordComponents(true); + list.setShowRecordComponentsByCell(true); + list.setShowHeader(true); + list.setWidth100(); + list.setHeight100(); + + list.addEditCompleteHandler(this); + + ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); + active.setType(ListGridFieldType.BOOLEAN); + + ListGridField name = new ListGridField( + GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); + name.setType(ListGridFieldType.TEXT); + + ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS, + MSG.chart_themepanel_header_actions(), 100); + + list.setFields(active, name, actions); + } + + + /** Get Current Cross-section Masters uuid. */ + public String getCurrentCSMaster() { + return currentCSMasterUUID; + } + + + /** Set Current Cross-section Masters uuid. */ + public void setCurrentCSMaster(String currentMasterUuid) { + this.currentCSMasterUUID = currentMasterUuid; + } + + + /** Returns name of cross section area facets. */ + @Override + protected String getAreaFacetName() { + return "cross_section.area"; + } + + + /** + * 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. + */ + @Override + protected boolean areAreaCompatible(Theme a, Theme b) { + if (a.equals(b)) { + return false; + } + return (a.getFacet().equals("cross_section") + || a.getFacet().endsWith("line")) + && (b.getFacet().equals("cross_section") + || b.getFacet().endsWith("line")); + } + + + /** + * True if context menu should contain 'create area' submenu on + * this theme. + */ + @Override + protected boolean canArea(Theme a) { + return a.getFacet().equals("cross_section") + || a.getFacet().equals("cross_section_water_line") + || a.getFacet().endsWith("line"); + } + + + protected String themeHash(Theme theme) { + return theme.getArtifact() + theme.getFacet() + theme.getIndex(); + } + + + /** + * Include synchron navigation item. + */ + @Override + protected Menu getSingleContextMenu(final ListGridRecord[] records) { + Menu contextMenu = super.getSingleContextMenu(records); + + Theme facetTheme = ((FacetRecord)records[0]).getTheme(); + String item = facetTheme.getFacet(); + + if (item.equals("cross_section")) { + // Synchron checking. + MenuItem synchronNavigationMenuItem = new MenuItem(); + final String themeHash = themeHash(facetTheme); + if (synchronCrossSectionThemes.contains(themeHash)) { + synchronNavigationMenuItem.setTitle(MSG.chart_themepanel_asynchron()); + synchronNavigationMenuItem.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + synchronCrossSectionThemes.remove (themeHash); + } + }); + } + else { + synchronNavigationMenuItem.setTitle(MSG.chart_themepanel_synchron()); + synchronNavigationMenuItem.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + synchronCrossSectionThemes.add (themeHash); + } + }); + } + contextMenu.addItem(synchronNavigationMenuItem); + } + + return contextMenu; + } + + + /** + * This method is used to clear the current theme grid and add new updated + * data. + */ + @Override + protected void updateGrid() { + GWT.log("CrossSectionChartThemePanel.updateGrid"); + + ListGridRecord[] selected = list.getSelectedRecords(); + + clearGrid(); + + ThemeList themeList = getThemeList(); + + if (themeList == null) { + GWT.log("ERROR: No theme list."); + return; + } + + int count = themeList.getThemeCount(); + + for (int i = 1; i <= count; i++) { + Theme theme = themeList.getThemeAt(i); + + if (theme == null) { + continue; + } + + if (theme.getFacet().equals("empty.facet")) { + theme.setVisible(0); + } + + if (theme.getVisible() == 0) { + continue; + } + + if (theme.getFacet().equals("cross_section")) { + addToReferences(theme); + } + + FacetRecord newRecord = createRecord(theme); + addFacetRecord(newRecord); + + String newArtifact = theme.getArtifact(); + String newFacet = theme.getFacet(); + int newIndex = theme.getIndex(); + + for (ListGridRecord r: selected) { + FacetRecord sel = (FacetRecord) r; + Theme oldTheme = sel.getTheme(); + + if (oldTheme.getArtifact().equals(newArtifact) + && oldTheme.getFacet().equals(newFacet) + && oldTheme.getIndex() == newIndex) { + list.selectRecord(newRecord); + } + } + } + + fireOutputParameterChanged(); + + } + + + /** + * Adds a cross section theme to the master artifacts combobox and finds + * a new master if necessary. + * + * @param theme The cross section theme. + */ + protected void addToReferences(Theme theme) { + if (theme.getVisible() != 0) { + masters.put(theme.getArtifact(), theme.getDescription()); + masterCb.setValueMap(masters); + } + findCurrentCSMaster(); + if (masterCb.getSelectedRecord() == null) { + masterCb.setValue(getCurrentCSMaster()); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ManualDatePointsEditor.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,408 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONBoolean; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.IButton; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.grid.CellEditValueFormatter; +import com.smartgwt.client.widgets.grid.CellEditValueParser; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertyGroup; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.StringProperty; + +import java.util.Date; +import java.util.List; + +/** + * UI to enter point data and save it to an PointArtifact. + */ +public class ManualDatePointsEditor +extends ManualPointsEditor +{ + + public ManualDatePointsEditor(Collection collection, + RedrawRequestHandler handler, String outputModeName + ) { + super (collection, handler, outputModeName); + } + + + /** Create and setup/add the ui. */ + @Override + public void createUI() { + Button accept = new Button(MSG.label_ok()); + Button cancel = new Button(MSG.label_cancel()); + cancel.addClickHandler(this); + + accept.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + okClicked(); + } + }); + + HLayout buttons = new HLayout(); + buttons.addMember(accept); + buttons.addMember(cancel); + buttons.setAlign(Alignment.CENTER); + buttons.setHeight(30); + + VLayout layout = new VLayout(); + listGrid = new ListGrid(); + listGrid.setWidth100(); + listGrid.setHeight("*"); + listGrid.setCanSort(false); + listGrid.setCanEdit(true); + listGrid.setShowHeaderContextMenu(false); + + CellFormatter doubleFormat = new CellFormatter() { + @Override + public String format(Object value, ListGridRecord record, int rowNum, int colNum) { + if(value != null) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(value.toString()).doubleValue(); + return nf.format(d); + } catch (Exception e) { + return value.toString(); + } + } else { + return null; + } + }}; + + CellFormatter dateFormat = new CellFormatter() { + @Override + public String format(Object value, ListGridRecord record, int rowNum, int colNum) { + if(value != null && !value.toString().equals("")) { + try { + DateTimeFormat df = + DateTimeFormat.getFormat("dd.MM.yyyy"); + Date d = df.parse(value.toString()); + DateTimeFormat df2 = + DateTimeFormat.getFormat( + DateTimeFormat.PredefinedFormat.DATE_MEDIUM); + return df2.format(d); + + } + catch(IllegalArgumentException iae) { + SC.warn(MSG.error_invalid_date()); + record.setAttribute(DatePointRecord.ATTRIBUTE_X, ""); + return ""; + } + } + else { + return null; + } + }}; + + + CellEditValueParser cevp = new CellEditValueParser() { + @Override + public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { + if (value == null) + return null; + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d = nf.parse(value.toString()); + return (new Double(d)).toString(); + } + catch(NumberFormatException nfe) { + return value; + } + } + }; + + CellEditValueFormatter cevf = new CellEditValueFormatter() { + @Override + public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { + if (value != null) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(value.toString()).doubleValue(); + return nf.format(d); + } catch (Exception e) { + return value.toString(); + } + } + return null; + } + }; + + // Use X and Y as default fallback. + String xAxis = "X"; + String yAxis = "Y"; + + // Get header text from collection settings. + Settings settings = this.collection.getSettings(outputModeName); + List<Property> axes = settings.getSettings("axes"); + if(axes != null) { + for (Property p: axes) { + PropertyGroup pg = (PropertyGroup)p; + StringProperty id = + (StringProperty)pg.getPropertyByName("id"); + if(id.getValue().equals("X")) { + StringProperty name = + (StringProperty)pg.getPropertyByName("label"); + xAxis = name.getValue(); + } + else if (yAxis.equals("Y")) { + StringProperty name = + (StringProperty)pg.getPropertyByName("label"); + yAxis = name.getValue(); + } + } + } + ListGridField xField = + new ListGridField(PointRecord.ATTRIBUTE_X, xAxis); + xField.setType(ListGridFieldType.TEXT); + xField.setCellFormatter(dateFormat); + + ListGridField yField = + new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis); + yField.setType(ListGridFieldType.FLOAT); + yField.setCellFormatter(doubleFormat); + yField.setEditValueParser(cevp); + yField.setEditValueFormatter(cevf); + + ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME, + MSG.pointname()); + final ListGridField removeField = + new ListGridField("_removeRecord", MSG.removepoint()){{ + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; + + ListGridField activeField = new ListGridField( + PointRecord.ATTRIBUTE_ACTIVE, MSG.selection()); + activeField.setType(ListGridFieldType.BOOLEAN); + activeField.setDefaultValue(true); + + listGrid.setFields(new ListGridField[] {activeField, xField, yField, + nameField, removeField}); + + listGrid.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + event.getViewer().removeData(event.getRecord()); + } + }); + + // Find the artifacts uuid. + findManualPointsUUID(); + CollectionItem item = collection.getItem(uuid); + + // Add points to grid. + if (item != null) { + String jsonData = item.getData().get(outputModeName + "." + POINT_DATA); + JSONArray jsonArray = (JSONArray) JSONParser.parse(jsonData); + for (int i = 0; i < jsonArray.size(); i++) { + JSONArray point = (JSONArray) jsonArray.get(i); + listGrid.addData(datePointRecordFromJSON(point)); + } + } + else { + GWT.log("No item found for " + uuid); + } + + IButton button = new IButton(MSG.newpoint()); + button.setTop(250); + button.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + listGrid.startEditingNew(); + } + }); + + layout.addMember(listGrid); + layout.addMember(button); + + addItem(layout); + + addItem(buttons); + setWidth(380); + setHeight(470); + centerInPage(); + } + + + /** Create JSON representation of the points present in the list grid. */ + @Override + protected JSONArray jsonArrayFromListGrid() { + JSONArray list = new JSONArray(); + int idx = 0; + + for(ListGridRecord record : listGrid.getRecords()) { + if (record instanceof DatePointRecord) { + JSONArray data = new JSONArray(); + + DatePointRecord point = (DatePointRecord) record; + String dateString = point.getX(); + DateTimeFormat df = DateTimeFormat.getFormat( + DateTimeFormat.PredefinedFormat.DATE_MEDIUM); + + Date d = df.parse(dateString); + double dv = d.getTime(); + + data.set(0, new JSONNumber(dv)); + data.set(1, new JSONNumber(point.getY())); + data.set(2, new JSONString(point.getName())); + data.set(3, JSONBoolean.getInstance(point.isActive())); + + list.set(idx, data); + idx++; + } + else { + JSONArray data = new JSONArray(); + + String nameString = record.getAttributeAsString(PointRecord.ATTRIBUTE_NAME); + // Apply default name if none set. + if (nameString == null || nameString.equals("")) { + String xString = record.getAttributeAsString( + PointRecord.ATTRIBUTE_X); + String yString = record.getAttributeAsString( + PointRecord.ATTRIBUTE_Y); + nameString = xString + "/" + yString; + } + + String dateString = record.getAttributeAsString(PointRecord.ATTRIBUTE_X); + DateTimeFormat df = DateTimeFormat.getFormat( + DateTimeFormat.PredefinedFormat.DATE_MEDIUM); + + Date d = df.parse(dateString); + double dv = d.getTime(); + data.set(0, new JSONNumber(dv)); + data.set(1, new JSONNumber(record. + getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); + data.set(2, new JSONString(nameString)); + data.set(3, JSONBoolean.getInstance(record.getAttributeAsBoolean( + PointRecord.ATTRIBUTE_ACTIVE))); + + list.set(idx, data); + idx++; + } + } + return list; + } + + /** From a JSON-encoded point, create a PointRecord. */ + public DatePointRecord datePointRecordFromJSON(JSONArray jsonArray) { + JSONNumber x = (JSONNumber) jsonArray.get(0); + JSONNumber y = (JSONNumber) jsonArray.get(1); + JSONString s = (JSONString) jsonArray.get(2); + JSONBoolean b = (JSONBoolean) jsonArray.get(3); + + Date d = new Date (Long.valueOf(x.toString()).longValue()); + DateTimeFormat df = DateTimeFormat.getFormat( + DateTimeFormat.PredefinedFormat.DATE_MEDIUM); + + return new DatePointRecord(b.booleanValue(), df.format(d), + y.doubleValue(), s.stringValue()); + } + + + /** Return false if x or y attribute is missing. */ + @Override + protected boolean isDialogValid() { + boolean valid = true; + for (ListGridRecord record : listGrid.getRecords()) { + if (record.getAttributeAsString(PointRecord.ATTRIBUTE_X) == null || + record.getAttributeAsString( + DatePointRecord.ATTRIBUTE_X).equals("") || + record.getAttributeAsDouble(PointRecord.ATTRIBUTE_Y) == null) { + return false; + } + } + if (listGrid.hasErrors()) { + valid = false; + } + return valid; + } + + + /** Simple record to store points. */ + public class DatePointRecord extends ListGridRecord { + protected static final String ATTRIBUTE_X = "X"; + protected static final String ATTRIBUTE_Y = "Y"; + protected static final String ATTRIBUTE_NAME = "name"; + protected static final String ATTRIBUTE_ACTIVE = "active"; + + private DatePointRecord() {;} + + public DatePointRecord(boolean b, String x, double y, String name) { + setActive(b); + setName(name); + setX(x); + setY(y); + } + + public void setActive(boolean b) { + setAttribute(ATTRIBUTE_ACTIVE, b); + } + + public boolean isActive() { + return getAttributeAsBoolean(ATTRIBUTE_ACTIVE); + } + + public void setName(String name) { + setAttribute(ATTRIBUTE_NAME, name); + } + + public String getName() { + return getAttributeAsString(ATTRIBUTE_NAME); + } + + public void setX(String x) { + setAttribute(ATTRIBUTE_X, x); + } + + public void setY(double y) { + setAttribute(ATTRIBUTE_Y, y); + } + + public String getX() { + return getAttributeAsString(ATTRIBUTE_X); + } + + public double getY() { + return getAttributeAsDouble(ATTRIBUTE_Y); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ManualPointsEditor.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,535 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONBoolean; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.IButton; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.grid.CellEditValueFormatter; +import com.smartgwt.client.widgets.grid.CellEditValueParser; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.RedrawRequestEvent; +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.services.FeedServiceAsync; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DefaultArtifact; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertyGroup; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.StringProperty; + +import java.util.Date; +import java.util.List; + + +/** + * UI to enter point data and save it to an PointArtifact. + */ +public class ManualPointsEditor +extends Window +implements ClickHandler +{ + /** The interface that provides i18n messages. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** Part of name of the main data item to be fed. */ + public static final String POINT_DATA = "manualpoints.data"; + + /** When we chaged something, we need a RedrawRequest(Handler). */ + protected RedrawRequestHandler redrawRequestHandler; + + /** The collection */ + protected Collection collection; + + /** The listGrid showing point entries. */ + protected ListGrid listGrid; + + protected ListGridFieldType fieldTypeX = ListGridFieldType.FLOAT; + + /** Service handle to clone and add artifacts to collection. */ + LoadArtifactServiceAsync loadArtifactService = GWT.create( + de.intevation.flys.client.client.services.LoadArtifactService.class); + + /** Service to feed the artifact with new point-data. */ + FeedServiceAsync feedService = GWT.create( + de.intevation.flys.client.client.services.FeedService.class); + + /** UUID of artifact to feed. */ + protected String uuid; + + /** Name of the outputmode, important when feeding data. */ + protected String outputModeName; + + /** Name of the point data item. */ + protected String pointDataItemName; + + + /** + * Setup editor dialog. + * @param collection The collection to use. + */ + public ManualPointsEditor(Collection collection, + RedrawRequestHandler handler, String outputModeName + ) { + this.collection = collection; + this.redrawRequestHandler = handler; + this.outputModeName = outputModeName; + this.pointDataItemName = outputModeName + "." + POINT_DATA; + init(); + } + + + /** Searches collection for first artifact to serve (manual) point data. */ + public String findManualPointsUUID() { + // TODO Need to be more picky (different points in different diagrams) + int size = collection.getItemLength(); + + for (int i = 0; i < size; i++) { + CollectionItem item = collection.getItem(i); + String dataValue = item.getData().get(pointDataItemName); + if (dataValue != null) { + // Found it. + uuid = item.identifier(); + return uuid; + } + } + + return null; + } + + + /** + * Initialize the editor window and its components. + */ + protected void init() { + setTitle(MSG.addpoints()); + setCanDragReposition(true); + setCanDragResize(true); + + // If no manualpoints artifact found, create it now. + if(findManualPointsUUID() == null) { + addArtifactCreateUI(); + } + else { + createUI(); + } + } + + + /** Create and setup/add the ui. */ + public void createUI() { + Button accept = new Button(MSG.label_ok()); + Button cancel = new Button(MSG.label_cancel()); + cancel.addClickHandler(this); + + accept.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + okClicked(); + } + }); + + HLayout buttons = new HLayout(); + buttons.addMember(accept); + buttons.addMember(cancel); + buttons.setAlign(Alignment.CENTER); + buttons.setHeight(30); + + VLayout layout = new VLayout(); + listGrid = new ListGrid(); + listGrid.setWidth100(); + listGrid.setHeight("*"); + listGrid.setCanSort(false); + listGrid.setCanEdit(true); + listGrid.setShowHeaderContextMenu(false); + + // Use X and Y as default fallback. + String xAxis = "X"; + String yAxis = "Y"; + + // Get header text from collection settings + Settings settings = this.collection.getSettings(outputModeName); + List<Property> axes = settings.getSettings("axes"); + if(axes != null) { + for (Property p: axes) { + PropertyGroup pg = (PropertyGroup)p; + GWT.log(pg.toString()); + StringProperty id = + (StringProperty)pg.getPropertyByName("id"); + if(id.getValue().equals("X")) { + StringProperty name = + (StringProperty)pg.getPropertyByName("label"); + xAxis = name.getValue(); + } + else if (yAxis.equals("Y")) { + StringProperty name = + (StringProperty)pg.getPropertyByName("label"); + yAxis = name.getValue(); + } + } + } + + CellFormatter format = createCellFormatter(); + CellEditValueParser cevp = createCellEditValueParser(); + CellEditValueFormatter cevf = createCellEditValueFormatter(); + + ListGridField xField = + new ListGridField(PointRecord.ATTRIBUTE_X, xAxis); + if(xAxis.equalsIgnoreCase("date") || xAxis.equalsIgnoreCase("Datum")) { + // FIXME: This is a hack for Timeseries charts with Date types on the x axis + xField.setType(ListGridFieldType.DATE); + this.fieldTypeX = ListGridFieldType.DATE; + } + else { + xField.setType(ListGridFieldType.FLOAT); + xField.setCellFormatter(format); + xField.setEditValueParser(cevp); + xField.setEditValueFormatter(cevf); + } + + ListGridField yField = + new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis); + yField.setType(ListGridFieldType.FLOAT); + yField.setCellFormatter(format); + yField.setEditValueParser(cevp); + yField.setEditValueFormatter(cevf); + + ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME, + MSG.pointname()); + final ListGridField removeField = + new ListGridField("_removeRecord", MSG.removepoint()){{ + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; + + ListGridField activeField = new ListGridField( + PointRecord.ATTRIBUTE_ACTIVE, MSG.selection()); + activeField.setType(ListGridFieldType.BOOLEAN); + activeField.setDefaultValue(true); + + listGrid.setFields(new ListGridField[] {activeField, xField, yField, + nameField, removeField}); + + listGrid.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + event.getViewer().removeData(event.getRecord()); + } + }); + + // Find the artifacts uuid + findManualPointsUUID(); + CollectionItem item = collection.getItem(uuid); + + // Add points to grid + if (item != null) { + // TODO store this from findPointUUID instead (we touched these). + String jsonData = item.getData().get(pointDataItemName); + JSONArray jsonArray = (JSONArray) JSONParser.parse(jsonData); + for (int i = 0; i < jsonArray.size(); i++) { + JSONArray point = (JSONArray) jsonArray.get(i); + listGrid.addData(PointRecord.fromJSON(point)); + } + } + else { + GWT.log("ManualPointsEditor: No item found for " + uuid); + } + + IButton button = new IButton(MSG.newpoint()); + button.setTop(250); + button.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + listGrid.startEditingNew(); + } + }); + + layout.addMember(listGrid); + layout.addMember(button); + + addItem(layout); + + addItem(buttons); + setWidth(380); + setHeight(470); + centerInPage(); + } + + + protected CellFormatter createCellFormatter() { + return new CellFormatter() { + @Override + public String format(Object value, ListGridRecord record, int rowNum, int colNum) { + if(value != null) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(value.toString()).doubleValue(); + return nf.format(d); + } catch (Exception e) { + return value.toString(); + } + } else { + return null; + } + }}; + } + + + protected CellEditValueParser createCellEditValueParser() { + return new CellEditValueParser() { + @Override + public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { + if (value == null) + return null; + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d = nf.parse(value.toString()); + return (new Double(d)).toString(); + } + catch(NumberFormatException nfe) { + return value; + } + } + }; + } + + + protected CellEditValueFormatter createCellEditValueFormatter() { + return new CellEditValueFormatter() { + @Override + public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { + if (value == null) { + return ""; + } + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(value.toString()).doubleValue(); + return nf.format(d); + } + catch(NumberFormatException nfe) { + return value; + } + } + }; + } + + protected String getLocaleDateFormat() { + String loc = Config.getInstance().getLocale(); + if ("de".equals(loc)) { + return "yy.MM.yyyy"; + } + else { + return "MM/dd/yyyy"; + } + } + + protected String formatDate(Date date) { + DateTimeFormat dtf = DateTimeFormat.getFormat(getLocaleDateFormat()); + return dtf.format(date); + } + + /** Create JSON representation of the points present in the list grid. */ + protected JSONArray jsonArrayFromListGrid() { + JSONArray list = new JSONArray(); + int idx = 0; + + for(ListGridRecord record : listGrid.getRecords()) { + if (record instanceof PointRecord) { + JSONArray data = new JSONArray(); + + PointRecord point = (PointRecord) record; + if(point.isTimeseriesPoint()) { + data.set(0, new JSONString(point.getXAsDate())); + GWT.log("Date: " + point.getXAsDate()); + } + else { + data.set(0, new JSONNumber(point.getX())); + } + data.set(1, new JSONNumber(point.getY())); + data.set(2, new JSONString(point.getName())); + data.set(3, JSONBoolean.getInstance(point.isActive())); + + list.set(idx, data); + idx++; + } + else { + JSONArray data = new JSONArray(); + + String nameString = record.getAttributeAsString(PointRecord.ATTRIBUTE_NAME); + // Apply default name if none set. + if (nameString == null || nameString.equals("")) { + String xString = record.getAttributeAsString( + PointRecord.ATTRIBUTE_X); + String yString = record.getAttributeAsString( + PointRecord.ATTRIBUTE_Y); + nameString = xString + "/" + yString; + } + + if(fieldTypeX.equals(ListGridFieldType.DATE)) { + Date date = record.getAttributeAsDate(PointRecord.ATTRIBUTE_X); + data.set(0, new JSONString(formatDate(date))); + GWT.log("Date: " + formatDate(date)); + } + else { + data.set(0, new JSONNumber(record. + getAttributeAsDouble(PointRecord.ATTRIBUTE_X))); + } + data.set(1, new JSONNumber(record. + getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); + data.set(2, new JSONString(nameString)); + data.set(3, JSONBoolean.getInstance(record.getAttributeAsBoolean( + PointRecord.ATTRIBUTE_ACTIVE))); + + list.set(idx, data); + idx++; + } + } + return list; + } + + + /** + * Called when OK Button was clicked. Then, if entered values are valid, + * fire a RedrawRequest and destroy. + */ + protected void okClicked() { + if(isDialogValid()) { + // Feed JSON-encoded content of listgrid. + JSONArray list = jsonArrayFromListGrid(); + + Data[] feedData = new Data[] { + DefaultData.createSimpleStringData(pointDataItemName, + list.toString()) + }; + + feedService.feed( + Config.getInstance().getLocale(), + new DefaultArtifact(uuid, "TODO:hash"), + feedData, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not feed artifact with points."); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + @Override + public void onSuccess(Artifact fartifact) { + GWT.log("Successfully set points"); + redrawRequestHandler.onRedrawRequest( + new RedrawRequestEvent()); + destroy(); + } + }); + } + else { + GWT.log("Dialog not valid"); + SC.warn(MSG.error_dialog_not_valid()); + } + } + + + /** Add a ManualPointArtifact to Collection. */ + public void addArtifactCreateUI() { + final Label standByLabel = new Label(MSG.standby()); + addItem(standByLabel); + + setWidth(380); + setHeight(470); + centerInPage(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + loadArtifactService.load( + this.collection, + new Recommendation("manualpoints", ""), + "manualpoints", + locale, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Creating manualpoint artifact failed!"); + } + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created artifact."); + removeItem(standByLabel); + uuid = artifact.getUuid(); + createUI(); + } + }); + } + + + /** + * This method is called when the user aborts point editing. + * @param event The event. + */ + @Override + public void onClick(ClickEvent event) { + this.destroy(); + } + + + /** Return false if x or y attribute is missing. */ + protected boolean isDialogValid() { + boolean valid = true; + for (ListGridRecord record : listGrid.getRecords()) { + try { + if (record.getAttribute(PointRecord.ATTRIBUTE_X) == null + || record.getAttribute(PointRecord.ATTRIBUTE_Y) == null) { + return false; + } + } + catch(IllegalArgumentException ex) { + + } + } + if (listGrid.hasErrors()) { + valid = false; + } + return valid; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ManualWSPEditor.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,355 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.RedrawRequestEvent; +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.services.FeedServiceAsync; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.client.utils.DoubleValidator; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DefaultArtifact; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertyGroup; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.StringProperty; + +import java.util.List; +import java.util.Map; + +/** + * UI to enter point data and save it to an PointArtifact. + */ +public class ManualWSPEditor +extends Window +implements ClickHandler +{ + /** The interface that provides i18n messages. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** Name of the main data item to be fed. */ + public static final String LINE_DATA = "manualpoints.lines"; + + /** When we change something, we need a RedrawRequest(Handler). */ + protected RedrawRequestHandler redrawRequestHandler; + + /** The collection */ + protected Collection collection; + + /** Service handle to clone and add artifacts to collection. */ + LoadArtifactServiceAsync loadArtifactService = GWT.create( + de.intevation.flys.client.client.services.LoadArtifactService.class); + + /** Service to feed the artifact with new point-data. */ + FeedServiceAsync feedService = GWT.create( + de.intevation.flys.client.client.services.FeedService.class); + + /** UUID of artifact to feed. */ + protected String uuid; + + /** Name of the outputmode, important when feeding data. */ + protected String outputModeName; + + /** Name of the data item for lines in this context. */ + protected String dataItemName; + + /** Input Field for y-coor of line. */ + protected TextItem valueInputPanel; + + /** Input Field for name of line. */ + protected TextItem nameInputPanel; + + /** Line data that is not added in this session. */ + protected JSONArray oldLines = null; + + + /** + * Setup editor dialog. + * @param collection The collection to use. + */ + public ManualWSPEditor(Collection collection, + RedrawRequestHandler handler, String outputModeName + ) { + this.collection = collection; + this.redrawRequestHandler = handler; + this.outputModeName = outputModeName; + this.dataItemName = outputModeName + "." + LINE_DATA; + init(); + } + + + /** Searches collection for first artifact to serve (manual) line data. */ + public String findManualPointsUUID() { + int size = collection.getItemLength(); + + for (int i = 0; i < size; i++) { + CollectionItem item = collection.getItem(i); + String dataValue = item.getData().get(dataItemName); + if (dataValue != null) { + // Found it. + uuid = item.identifier(); + return uuid; + } + } + + return null; + } + + + /** + * Initialize the editor window and its components. + */ + protected void init() { + setTitle(MSG.addWSP()); + setCanDragReposition(true); + setCanDragResize(true); + + if(findManualPointsUUID() == null) { + addArtifactCreateUI(); + } + else { + createUI(); + } + } + + + /** Create and setup/add the ui. */ + public void createUI() { + Button accept = new Button(MSG.label_ok()); + Button cancel = new Button(MSG.label_cancel()); + cancel.addClickHandler(this); + + accept.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + okClicked(); + } + }); + + HLayout buttons = new HLayout(); + buttons.addMember(accept); + buttons.addMember(cancel); + buttons.setAlign(Alignment.CENTER); + buttons.setHeight(30); + + // Use X and Y as default fallback. + String yAxis = "Y"; + + // Get header text from collection settings. + Settings settings = this.collection.getSettings(outputModeName); + List<Property> axes = settings.getSettings("axes"); + if(axes != null) { + for (Property p: axes) { + PropertyGroup pg = (PropertyGroup)p; + StringProperty id = + (StringProperty)pg.getPropertyByName("id"); + if (id.getValue().equals("W")) { + StringProperty name = + (StringProperty)pg.getPropertyByName("label"); + yAxis = name.getValue(); + } + } + } + + DynamicForm form = new DynamicForm(); + valueInputPanel = new TextItem(); + valueInputPanel.setTitle(yAxis); + valueInputPanel.setShowTitle(true); + valueInputPanel.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent e) { + DoubleValidator validator = new DoubleValidator(); + Map errors = e.getForm().getErrors(); + validator.validate(e.getItem(), errors); + e.getForm().setErrors(errors, true); + } + }); + nameInputPanel = new TextItem(); + nameInputPanel.setTitle(MSG.pointname()); + nameInputPanel.setShowTitle(true); + form.setFields(valueInputPanel, nameInputPanel); + + VLayout layout = new VLayout(); + layout.addMember(form); + + // Find the artifacts uuid. + // TODO this has been called already, why call it again? + findManualPointsUUID(); + CollectionItem item = collection.getItem(uuid); + + // Store the old line data. + if (item != null) { + String jsonData = item.getData().get(dataItemName); + oldLines = (JSONArray) JSONParser.parse(jsonData); + } + else { + GWT.log("No old lines found for " + uuid); + } + + addItem(layout); + + addItem(buttons); + setWidth(360); + setHeight(120); + centerInPage(); + } + + + /** + * Create JSON representation of the points present in the form. + * Add old data, too. + * @return a jsonarray with the old and the new lines. + */ + protected JSONArray jsonArrayFromForm() { + if (oldLines == null) { + oldLines = new JSONArray(); + } + + double val; + if (valueInputPanel.getValue() == null) + return oldLines; + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d = nf.parse(valueInputPanel.getValue().toString()); + val = d; + } + catch(NumberFormatException nfe) { + GWT.log("fehler... nfe... TODO"); + return oldLines; + } + + JSONArray data = new JSONArray(); + data.set(0, new JSONNumber(val)); + if (nameInputPanel.getValue() == null) { + data.set(1, new JSONString(valueInputPanel.getValue().toString())); + } + else { + data.set(1, new JSONString(nameInputPanel.getValue().toString())); + } + oldLines.set(oldLines.size(), data); + + return oldLines; + } + + + /** + * Called when OK Button was clicked. Then, if entered values are valid, + * fire a RedrawRequest and destroy. + */ + protected void okClicked() { + if (valueInputPanel.getValue() == null) { + return; + } + GWT.log(valueInputPanel.getValue().toString()); + if(isDialogValid()) { + // Feed JSON-encoded content of form. + JSONArray list = jsonArrayFromForm(); + + Data[] feedData = new Data[] { + DefaultData.createSimpleStringData(dataItemName, + list.toString()) + }; + + feedService.feed( + Config.getInstance().getLocale(), + new DefaultArtifact(uuid, "TODO:hash"), + feedData, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not feed artifact with lines."); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + @Override + public void onSuccess(Artifact fartifact) { + GWT.log("Successfully set lines "); + redrawRequestHandler.onRedrawRequest( + new RedrawRequestEvent()); + destroy(); + } + }); + } + else { + GWT.log("Dialog not valid"); + SC.warn(MSG.error_dialog_not_valid()); + } + } + + + /** Add a ManualPointArtifact to Collection. */ + public void addArtifactCreateUI() { + final Label standByLabel = new Label(MSG.standby()); + addItem(standByLabel); + + setWidth(360); + setHeight(120); + centerInPage(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + loadArtifactService.load( + this.collection, + new Recommendation("manualpoints", ""), + "manualpoints", + locale, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Creating manualpoint artifact failed!"); + } + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created artifact."); + removeItem(standByLabel); + uuid = artifact.getUuid(); + createUI(); + } + }); + } + + + /** + * This method is called when the user aborts point editing. + * @param event The event. + */ + @Override + public void onClick(ClickEvent event) { + this.destroy(); + } + + + /** Return false if x or y attribute is missing. */ + protected boolean isDialogValid() { + return (DoubleValidator.isDouble(valueInputPanel.getValue())); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/MousePositionPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,137 @@ +package de.intevation.flys.client.client.ui.chart; + +import java.util.ArrayList; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.events.MouseMoveEvent; +import com.smartgwt.client.widgets.events.MouseMoveHandler; + +import de.intevation.flys.client.shared.Transform2D; + + +/** + * Panel showing the mouse position in data space. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MousePositionPanel extends HLayout implements MouseMoveHandler { + + /** Is associated to a ChartTab. */ + protected ChartOutputTab chartTab; + + protected HLayout xLayout; + protected ArrayList<HLayout> yLayouts; + + + public MousePositionPanel(ChartOutputTab chartTab) { + super(); + + this.chartTab = chartTab; + + chartTab.getChartPanel().addMouseMoveHandler(this); + + initLayout(); + } + + + /** + * Initializes the layout of this component. <b>Note:</b> This layout has a + * fixed width of 195px plus a margin of 5px. + */ + protected void initLayout() { + setMembersMargin(5); + + xLayout = null; + yLayouts = new ArrayList<HLayout>(); + } + + + /** + * Listens to mouse move events to refresh the xy position. + * + * @param event The move event. + */ + public void onMouseMove(MouseMoveEvent event) { + updateMousePosition(event.getX(), event.getY()); + } + + + /** + * This method takes pixel coordinates, transforms those values into chart + * coordinates using the Transform2D class and updates the mouse position. + * + * @param x The x part of the pixel. + * @param y The y part of the pixel. + */ + public void updateMousePosition(double x, double y) { + int transformerCount = chartTab.getTransformerCount(); + + Canvas chart = chartTab.getChartPanel(); + int xOffset = chart.getPageLeft(); + int yOffset = chart.getPageTop(); + + x = x - xOffset; + y = y - yOffset; + + // Create Layout for x coordinates. + if (xLayout == null){ + Label xDesc = new Label("Position: X = "); + Label xLabel = new Label(); + xLayout = new HLayout(); + xLayout.setWidth(125); + xLayout.addMember(xDesc); + xLayout.addMember(xLabel); + xDesc.setWidth(70); + xLabel.setWidth(55); + addMember(xLayout); + } + + for (int i = 0; i < transformerCount; i++) { + HLayout yLayout = null; + // If no layout exists for this y axis, create one. + // else use the existing one. + if (yLayouts.size() <= i) { + Label yDesc = new Label("Y" + (i+1) + " = "); + Label yLabel = new Label(); + yLayout = new HLayout(); + yLayout.setWidth(80); + yLayout.addMember(yDesc); + yLayout.addMember(yLabel); + yDesc.setWidth(30); + yLabel.setWidth(50); + addMember(yLayout); + yLayouts.add(i, yLayout); + } + else { + yLayout = yLayouts.get(i); + } + + Transform2D transformer = chartTab.getTransformer(i); + + if (transformer == null) { + return; + } + + // Get the label for the coordinates. + Canvas xLabel = xLayout.getMember(1); + Canvas yLabel = yLayout.getMember(1); + + double[] xy = transformer.transform(x, y); + String[] xyStr = transformer.format(new Number[] { + new Double(xy[0]), new Double(xy[1]) }); + // Set the coordinates. + xLabel.setContents(xyStr[0]); + yLabel.setContents(xyStr[1]); + } + + // Remove y coordinates. + if (yLayouts.size() > transformerCount) { + for (int i = yLayouts.size() - 1; i >= transformerCount; i--) { + removeMember(yLayouts.get(i)); + yLayouts.remove(i); + } + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,336 @@ +package de.intevation.flys.client.client.ui.chart; + +import java.util.Map; +import java.util.HashMap; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.Alignment; + +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; + +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; + +import com.smartgwt.client.widgets.form.DynamicForm; + +import com.smartgwt.client.widgets.form.fields.TextItem; + +import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; +import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; + +import de.intevation.flys.client.client.Config; + +import de.intevation.flys.client.client.ui.CollectionView; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; +import de.intevation.flys.client.shared.model.FixFilter; +import de.intevation.flys.client.shared.model.OutputMode; + +import java.util.Date; + + +/** + * Tab representing and showing one Chart-output with a "navi" thing. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class NaviChartOutputTab +extends ChartOutputTab +implements TabSelectedHandler +{ + protected TextItem currentkm; + + public NaviChartOutputTab( + String title, + Collection collection, + OutputMode mode, + CollectionView collectionView + ){ + super(title, collection, mode, collectionView); + right.removeChild(chart); + right.addChild(createNaviChart()); + collectionView.registerTabHandler(this); + } + + + protected Canvas createNaviChart() { + final Artifact art = collectionView.getArtifact(); + VLayout root = new VLayout(); + root.setWidth100(); + root.setHeight100(); + + HLayout layout = new HLayout(); + layout.setAlign(Alignment.CENTER); + + DynamicForm form = new DynamicForm(); + Button lower = new Button("<<"); + lower.setWidth(30); + Button upper = new Button(">>"); + upper.setWidth(30); + currentkm = new TextItem(); + currentkm.setWidth(60); + currentkm.setShowTitle(false); + + form.setFields(currentkm); + form.setWidth(60); + + double fromKm; + double toKm; + + if (art instanceof FixAnalysisArtifact) { + FixAnalysisArtifact fix = (FixAnalysisArtifact) art; + FixFilter fixFilter = fix.getFilter(); + String s = fix.getArtifactDescription().getDataValueAsString("ld_step"); + try { + double ds = Double.parseDouble(s); + collectionView.setSteps(ds); + } + catch(NumberFormatException nfe) { + collectionView.setSteps(100d); + } + fromKm = fixFilter.getFromKm(); + toKm = fixFilter.getToKm(); + } + else { + // Probably WINFOArtifact kind of artifact. + String ld_step = + art.getArtifactDescription().getDataValueAsString("ld_step"); + try { + collectionView.setSteps(Double.valueOf(ld_step)); + } + catch (Exception e) { + GWT.log("No ld_steps data or not parsable."); + return root; + } + + double[] kmRange = art.getArtifactDescription().getKMRange(); + if (kmRange == null || kmRange.length == 2) { + fromKm = kmRange[0]; + toKm = kmRange[1]; + } + else { + GWT.log("No KM range in description found."); + return root; + } + } + + collectionView.setMinKm(fromKm); + collectionView.setMaxKm(toKm); + + final NumberFormat nf = NumberFormat.getDecimalFormat(); + if (collectionView.getCurrentKm() == -1d) { + try { + double d = Double.valueOf(fromKm); + currentkm.setValue(nf.format(d)); + } catch (NumberFormatException e) { + currentkm.setValue(fromKm); + } + collectionView.setCurrentKm(fromKm); + } + else { + try { + double d = Double.valueOf(fromKm); + currentkm.setValue(nf.format(d)); + } catch (NumberFormatException e) { + currentkm.setValue(fromKm); + } + currentkm.setValue(collectionView.getCurrentKm()); + } + + lower.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent ce) { + tbarPanel.deselectControls(); + updateChartDown(); + try { + double d = Double.valueOf(collectionView.getCurrentKm()); + currentkm.setValue(nf.format(d)); + } catch (NumberFormatException e) { + currentkm.setValue(collectionView.getCurrentKm()); + } + } + }); + + upper.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent ce) { + tbarPanel.deselectControls(); + updateChartUp(); + try { + double d = Double.valueOf(collectionView.getCurrentKm()); + currentkm.setValue(nf.format(d)); + } catch (NumberFormatException e) { + currentkm.setValue(collectionView.getCurrentKm()); + } + } + }); + + currentkm.addKeyPressHandler(new KeyPressHandler() { + public void onKeyPress(KeyPressEvent kpe) { + if (!kpe.getKeyName().equals("Enter")) { + return; + } + if(kpe.getItem().getValue() != null) { + tbarPanel.deselectControls(); + try { + String s = kpe.getItem().getValue().toString(); + double d; + try { + d = nf.parse(s); + currentkm.setValue(nf.format(d)); + } catch (NumberFormatException e) { + d = -1d; + } + if (d <= collectionView.getMaxKm() && + d >= collectionView.getMinKm()) { + collectionView.setCurrentKm(d); + tbarPanel.updateLinks(); + if (right != null) { + updateChartPanel(); + updateChartInfo(); + } + } + } + catch(NumberFormatException nfe) { + // Do nothing. + } + } + } + }); + layout.addMember(lower); + layout.addMember(form); + layout.addMember(upper); + + root.addMember(chart); + root.addMember(layout); + return root; + } + + + /** Callback when km-up-button is clicked. + * Increases collectionViews KM and refreshes view. */ + protected void updateChartUp() { + double currentKm = collectionView.getCurrentKm(); + if (currentKm < collectionView.getMaxKm()) { + // Why this math? + double newVal = currentKm * 100; + newVal += (collectionView.getSteps() / 10); + collectionView.setCurrentKm((double)Math.round(newVal) / 100); + tbarPanel.updateLinks(); + updateChartPanel(); + updateChartInfo(); + } + } + + /** Callback when km-down-button is clicked. + * Decreases collectionViews KM and refreshes view. */ + protected void updateChartDown() { + double currentKm = collectionView.getCurrentKm(); + if (currentKm > collectionView.getMinKm()) { + // Why this math? + double newVal = currentKm * 100; + newVal -= (collectionView.getSteps() / 10); + collectionView.setCurrentKm((double)Math.round(newVal) / 100); + tbarPanel.updateLinks(); + updateChartPanel(); + updateChartInfo(); + } + + } + + /** + * Returns the existing chart panel. + * + * @return the existing chart panel. + */ + @Override + public Canvas getChartPanel() { + return chart; + } + + /** + * Builds the URL that points to the chart image. + * + * @param width The width of the requested chart. + * @param height The height of the requested chart. + * @param xr Optional x range (used for zooming). + * @param yr Optional y range (used for zooming). + * + * @return the URL to the chart image. + */ + @Override + protected String getImgUrl(int width, int height) { + Config config = Config.getInstance(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "chart"; + imgUrl += "?uuid=" + collection.identifier(); + imgUrl += "&type=" + mode.getName(); + imgUrl += "&locale=" + config.getLocale(); + imgUrl += "×tamp=" + new Date().getTime(); + imgUrl += "&width=" + Integer.toString(width); + imgUrl += "&height=" + Integer.toString(height - 40); + + Number[] zoom = getZoomValues(); + + if (zoom != null) { + if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + imgUrl += "&minx=" + zoom[0]; + imgUrl += "&maxx=" + zoom[1]; + } + + if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { + // a zoom range of 0-1 means displaying the whole range. In such + // case we don't need to zoom. + imgUrl += "&miny=" + zoom[2]; + imgUrl += "&maxy=" + zoom[3]; + } + } + + if (collectionView.getArtifact() instanceof FixAnalysisArtifact) { + if (collectionView.getCurrentKm() == -1) { + FixAnalysisArtifact fix = + (FixAnalysisArtifact) collectionView.getArtifact(); + collectionView.setCurrentKm(fix.getFilter().getFromKm()); + } + } + else if (collectionView.getCurrentKm() == -1) { + collectionView.setCurrentKm(collectionView.getArtifact().getArtifactDescription().getKMRange()[0]); + } + if (collectionView.getCurrentKm() != -1) { + imgUrl += "¤tKm=" + collectionView.getCurrentKm(); + } + + return imgUrl; + } + + public void onTabSelected(TabSelectedEvent tse) { + if (this.equals(tse.getTab())) { + updateChartPanel(); + updateChartInfo(); + currentkm.setValue(collectionView.getCurrentKm()); + } + } + + @Override + public Map<String, String> getChartAttributes() { + Map<String, String> attr = new HashMap<String, String>(); + + attr = super.getChartAttributes(); + attr.put("km", String.valueOf(collectionView.getCurrentKm())); + + return attr; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/OverviewOutputTab.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,109 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.core.client.GWT; + +import de.intevation.flys.client.client.event.OutputParameterChangeHandler; +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.ImgLink; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Theme; + + +public class OverviewOutputTab extends ChartOutputTab { + + private class NoChartThemePanel extends ChartThemePanel { + + public NoChartThemePanel(OutputMode mode, CollectionView view) { + super(mode, view); + } + + @Override + public void activateTheme(Theme theme, boolean active) { } + + @Override + public void feedTellArea( + final String artifact, + Theme under, + Theme over, + boolean between + ) { } + + @Override + public void createAreaArtifact( + final Theme over, + final Theme under, + final boolean between + ) { } + + @Override + public void addOutputParameterChangeHandler(OutputParameterChangeHandler h) { } + + @Override + public void addRedrawRequestHandler(RedrawRequestHandler h){ } + } + + + + private class MinimumChartToolbar extends ChartToolbar { + + public MinimumChartToolbar(ChartOutputTab tab) { + super(tab); + } + + @Override + protected void initTools() { + GWT.log("CREATE NEW MINIMALISTIC CHART TOOLBAR"); + ChartOutputTab chartTab = getChartOutputTab(); + + String baseUrl = GWT.getHostPageBaseURL(); + + downloadPNG = new ImgLink( + baseUrl + MSG.downloadPNG(), + chartTab.getExportUrl(-1, -1, "png"), + 20, + 20); + downloadPNG.setTooltip(MSG.downloadPNGTooltip()); + + initLayout(); + } + + + @Override + protected void initLayout() { + setWidth100(); + setHeight(PANEL_HEIGHT); + setMembersMargin(10); + setPadding(5); + setBorder("1px solid black"); + + addMember(downloadPNG); + } + } + + + + public OverviewOutputTab( + String title, + Collection collection, + OutputMode mode, + CollectionView collectionView + ){ + super(title, collection, mode, collectionView); + left.setVisible(false); + } + + + @Override + public ChartThemePanel createThemePanel( + OutputMode mode, CollectionView view + ) { + return new NoChartThemePanel(mode, view); + } + + @Override + public ChartToolbar createChartToolbar(ChartOutputTab tab) { + return new MinimumChartToolbar(tab); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/PanControl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,210 @@ +package de.intevation.flys.client.client.ui.chart; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.SelectionType; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.ImgButton; +import com.smartgwt.client.widgets.events.MouseDownEvent; +import com.smartgwt.client.widgets.events.MouseDownHandler; +import com.smartgwt.client.widgets.events.MouseMoveEvent; +import com.smartgwt.client.widgets.events.MouseMoveHandler; +import com.smartgwt.client.widgets.events.MouseOutEvent; +import com.smartgwt.client.widgets.events.MouseOutHandler; +import com.smartgwt.client.widgets.events.MouseUpEvent; +import com.smartgwt.client.widgets.events.MouseUpHandler; + +import de.intevation.flys.client.client.event.HasPanHandlers; +import de.intevation.flys.client.client.event.PanEvent; +import de.intevation.flys.client.client.event.PanHandler; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class PanControl +extends ImgButton +implements MouseDownHandler, MouseMoveHandler, MouseUpHandler, + MouseOutHandler, HasPanHandlers +{ + protected ChartOutputTab chartTab; + + protected List<PanHandler> handlers; + + protected int[] start; + protected int[] end; + + + public PanControl(ChartOutputTab chartTab, String imageUrl) { + super(); + + this.chartTab = chartTab; + this.handlers = new ArrayList<PanHandler>(); + this.start = new int[] { -1, -1 }; + this.end = new int[] { -1, -1 }; + + String baseUrl = GWT.getHostPageBaseURL(); + setSrc(baseUrl + imageUrl); + setActionType(SelectionType.CHECKBOX); + setSize(20); + setShowRollOver(false); + setSelected(false); + + chartTab.getChartPanel().addMouseDownHandler(this); + chartTab.getChartPanel().addMouseMoveHandler(this); + chartTab.getChartPanel().addMouseUpHandler(this); + chartTab.getChartPanel().addMouseOutHandler(this); + } + + + /** + * Method used to register a new PanHandler. + * + * @param handler A new PanHandler. + */ + public void addPanHandler(PanHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + /** + * This event starts the dragging operation if the control is activated. + * + * @param event The mouse down event which contains the start coordinates. + */ + public void onMouseDown(MouseDownEvent event) { + if (!isSelected()) { + return; + } + + start[0] = event.getX(); + start[1] = event.getY(); + + end[0] = start[0]; + end[1] = start[1]; + } + + + /** + * This event is used to reposition the chart image based on the current + * drag operation. + * + * @param event The move event which contains the new coordinates to update + * the chart image position. + */ + public void onMouseMove(MouseMoveEvent event) { + if (!isSelected() || start[0] == -1 || start[1] == -1) { + return; + } + + int x = event.getX() - end[0]; + int y = event.getY() - end[1]; + + end[0] = end[0] + x; + end[1] = end[1] + y; + + Canvas c = chartTab.getChartImg(); + c.moveBy(x, y); + } + + + /** + * This event stops the dragging operation and fires a DragEnd event to the + * registered listeners. + * + * @param event The mouse up event which contains the end coordinates. + */ + public void onMouseUp(MouseUpEvent event) { + if (!isSelected()) { + return; + } + + end[0] = event.getX(); + end[1] = event.getY(); + + Canvas c = chartTab.getChartImg(); + c.setLeft(0); + c.setTop(0); + + fireOnPan(); + + start[0] = -1; + start[1] = -1; + } + + + /** + * This event is used to cancel the current dragging operation. + * + * @param event The mouse out event. + */ + public void onMouseOut(MouseOutEvent event) { + int x = event.getX(); + int y = event.getY(); + + if (!isSelected() || !isMouseOut(x, y) || start[0] == -1) { + return; + } + + Canvas c = chartTab.getChartImg(); + c.setLeft(0); + c.setTop(0); + + fireOnPan(); + + start[0] = -1; + start[1] = -1; + } + + + /** + * This method is required to check manually if the mouse pointer really + * moves out the chart area. The MouseOutEvent is also fired if the mouse + * goes down which doesn't seem to be correct. So, we gonna check this + * manually. + * + * @param x The x coordinate. + * @param y The y coordinate. + * + * @return true, if the mouse is really out of the chart area, otherwise + * false. + */ + protected boolean isMouseOut(int x, int y) { + Canvas chart = chartTab.getChartImg(); + + if (chart instanceof Img) { + chart = chart.getParentElement(); + } + + int left = chart.getPageLeft(); + int right = chart.getPageRight(); + int top = chart.getPageTop(); + int bottom = chart.getPageBottom(); + + if (x <= left || x >= right || y <= top || y >= bottom) { + return true; + } + + return false; + } + + + /** + * A pan event is fired to inform the registered listeners about a pan + * operation has finished. + */ + protected void fireOnPan() { + PanEvent event = new PanEvent(start, end); + + for (PanHandler handler: handlers) { + handler.onPan(event); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/PointRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,105 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONBoolean; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + +/** Simple record to store points. */ +public class PointRecord extends ListGridRecord { + protected static final String ATTRIBUTE_X = "X"; + protected static final String ATTRIBUTE_Y = "Y"; + protected static final String ATTRIBUTE_NAME = "name"; + protected static final String ATTRIBUTE_ACTIVE = "active"; + + /** From a JSON-encoded point, create a PointRecord. */ + public static PointRecord fromJSON(JSONArray jsonArray) { + JSONValue x = jsonArray.get(0); + JSONNumber y = (JSONNumber) jsonArray.get(1); + JSONString s = (JSONString) jsonArray.get(2); + JSONBoolean b = (JSONBoolean)jsonArray.get(3); + + if(x instanceof JSONNumber) { + return new PointRecord( + b.booleanValue(), ((JSONNumber)x).doubleValue(), + y.doubleValue(), s.stringValue()); + } + else { + return new PointRecord( + b.booleanValue(), ((JSONString)x).stringValue(), + y.doubleValue(), s.stringValue()); + } + } + + protected boolean isTimeseriesPoint = false; + + public PointRecord(boolean isActive, double x, double y, String name) { + setActive(isActive); + setName(name); + setX(x); + setY(y); + } + + /** + * Constructor taking the x axis value as String representing a Date value. + * @param isActive + * @param x + * @param y + * @param name + */ + public PointRecord(boolean isActive, String x, double y, String name) { + setActive(isActive); + setName(name); + setX(x); + setY(y); + + this.isTimeseriesPoint = true; + } + + public void setActive(boolean isActive) { + setAttribute(ATTRIBUTE_ACTIVE, isActive); + } + + public boolean isActive() { + return getAttributeAsBoolean(ATTRIBUTE_ACTIVE); + } + + public boolean isTimeseriesPoint() { + return this.isTimeseriesPoint; + } + + public void setName(String name) { + setAttribute(ATTRIBUTE_NAME, name); + } + + public String getName() { + return getAttributeAsString(ATTRIBUTE_NAME); + } + + public void setX(double x) { + setAttribute(ATTRIBUTE_X, x); + } + + public void setX(String date) { + setAttribute(ATTRIBUTE_X, date); + } + + public void setY(double y) { + setAttribute(ATTRIBUTE_Y, y); + } + + public double getX() { + return getAttributeAsDouble(ATTRIBUTE_X); + } + + public String getXAsDate() { + return getAttributeAsString(ATTRIBUTE_X); + } + + public double getY() { + return getAttributeAsDouble(ATTRIBUTE_Y); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ZoomboxControl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,324 @@ +package de.intevation.flys.client.client.ui.chart; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Positioning; +import com.smartgwt.client.types.SelectionType; +import com.smartgwt.client.widgets.ImgButton; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.events.MouseDownEvent; +import com.smartgwt.client.widgets.events.MouseDownHandler; +import com.smartgwt.client.widgets.events.MouseMoveEvent; +import com.smartgwt.client.widgets.events.MouseMoveHandler; +import com.smartgwt.client.widgets.events.MouseOutEvent; +import com.smartgwt.client.widgets.events.MouseOutHandler; +import com.smartgwt.client.widgets.events.MouseUpEvent; +import com.smartgwt.client.widgets.events.MouseUpHandler; + +import de.intevation.flys.client.client.event.HasZoomHandlers; +import de.intevation.flys.client.client.event.ZoomEvent; +import de.intevation.flys.client.client.event.ZoomHandler; + + +/** + * This control observes that panel retrieved by ChartOutputTab.getChartPanel(). + * If activated, a zoombox is drawn. One of the two edges is the position of the + * mouse down event on the observed panel. The other edge is specified by the + * current mouse position. If the mouse up event occurs, start and end point + * relative to the left and upper border of the observed panel is determined and + * a ZoomEvent is fired. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ZoomboxControl +extends ImgButton +implements MouseDownHandler, MouseUpHandler, MouseMoveHandler, HasZoomHandlers, + MouseOutHandler +{ + protected List<ZoomHandler> handlers; + + protected ChartOutputTab chartTab; + + protected Canvas zoombox; + + protected int[] start; + protected int[] end; + + + public ZoomboxControl(ChartOutputTab chartTab, String imageUrl) { + super(); + + this.handlers = new ArrayList<ZoomHandler>(); + this.chartTab = chartTab; + this.start = new int[] { -1, -1 }; + this.end = new int[2]; + this.zoombox = new Canvas(); + + initZoombox(); + + String baseUrl = GWT.getHostPageBaseURL(); + setSrc(baseUrl + imageUrl); + setActionType(SelectionType.CHECKBOX); + setSize(20); + setShowRollOver(false); + setSelected(false); + + Canvas chart = chartTab.getChartPanel(); + chart.addMouseDownHandler(this); + chart.addMouseOutHandler(this); + chart.addMouseMoveHandler(this); + chart.addMouseUpHandler(this); + } + + + /** + * Initializes the zoombox that is displayed over the observed area. The + * zoombox has an opaque background. Its height/width and x/y values are + * determined by the start point (mouse down) and the current mouse + * position. + */ + protected void initZoombox() { + Canvas chart = chartTab.getChartPanel(); + chart.addChild(zoombox); + + zoombox.setPosition(Positioning.ABSOLUTE); + zoombox.setBorder("2px solid black"); + zoombox.setOpacity(50); + zoombox.setWidth(1); + zoombox.setHeight(1); + zoombox.setLeft(-10000); + zoombox.setTop(-10000); + } + + + /** + * Registers a new ZoomHandler that wants to listen to ZoomEvents. + * + * @param handler A new ZoomHandler. + */ + public void addZoomHandler(ZoomHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + /** + * A mouse down event on the specified area will set the start point for the + * zoombox. + * + * @param event The mouse down event which contains the xy coordinates of + * the observed area. + */ + public void onMouseDown(MouseDownEvent event) { + if (!isSelected()) { + return; + } + + start[0] = getRelativeX(event.getX()) - 1; + start[1] = getRelativeY(event.getY()) + 1; + + end[0] = start[0]; + end[1] = start[1]; + } + + + /** + * A mouse move event on the specified area will set the end point for the + * zoombox. If the end point differs from the start point, an opaque box is + * displayed. + * + * @param event The mouse move event which contains the xy coordinates of + * the observed area. + */ + public void onMouseMove(MouseMoveEvent event) { + if (!isSelected() || !isZooming()) { + return; + } + + int x = getRelativeX(event.getX()); + int y = getRelativeY(event.getY()); + + end[0] = x > start[0] ? x-1 : x+1; + end[1] = y > start[1] ? y-1 : y+1; + + positionZoombox(); + } + + + /** + * The mouse up event finalizes the zoom operation. It sets the end point + * for this operation, clears the zoombox and fires a ZoomEvent. + * + * @param event The mouse up event which contains the xy coordinates of the + * observed area. + */ + public void onMouseUp(MouseUpEvent event) { + if (!isSelected()) { + return; + } + + end[0] = getRelativeX(event.getX()); + end[1] = getRelativeY(event.getY()); + + fireZoomEvent(); + + reset(); + } + + + /** + * The mouse out event is used to cancel an active zoom operation. + * + * @param event The mouse out event. + */ + public void onMouseOut(MouseOutEvent event) { + if (!isSelected() || !isMouseOut(event.getX(), event.getY())) { + return; + } + + reset(); + } + + + /** + * Returns the chart panel. + * + * @return the chart panel. + */ + protected Canvas getChartPanel() { + return chartTab.getChartPanel(); + } + + + /** + * This method is required to check manually if the mouse pointer really + * moves out the chart area. The MouseOutEvent is also fired if the mouse + * goes down which doesn't seem to be correct. So, we gonna check this + * manually. + * + * @param x The x coordinate. + * @param y The y coordinate. + * + * @return true, if the mouse is really out of the chart area, otherwise + * false. + */ + protected boolean isMouseOut(int x, int y) { + Canvas chart = getChartPanel(); + + int left = chart.getPageLeft(); + int right = chart.getPageRight(); + int top = chart.getPageTop(); + int bottom = chart.getPageBottom(); + + if (x <= left || x >= right || y <= top || y >= bottom) { + return true; + } + + return false; + } + + + /** + * Returns true, if a zoom action is in process. + * + * @return true, if a zoom action is in process. + */ + public boolean isZooming() { + return start[0] > 0 && start[1] > 0; + } + + + /** + * Returns the X coordinate relative to the left border. + * + * @param x The X coordinate relative to the window. + * + * @return the X coordinate relative to the left border. + */ + protected int getRelativeX(int x) { + return x - chartTab.getChartPanel().getPageLeft(); + } + + + /** + * Returns the Y coordinate relative to the top border. + * + * @param y The Y coordinate relative to the window. + * + * @return the Y coordinate relative to the top border. + */ + protected int getRelativeY(int y) { + return y - chartTab.getChartPanel().getPageTop(); + } + + + /** + * Returns min and max x/y values based on the stored values in <i>start</i> + * and <i>end</i>. + * + * @return an int[] as follows: [xmin, ymin, xmax, ymax]. + */ + protected int[] orderPositions() { + int xmin = start[0] < end[0] ? start[0] : end[0]; + int ymin = start[1] < end[1] ? start[1] : end[1]; + + int xmax = start[0] >= end[0] ? start[0] : end[0]; + int ymax = start[1] >= end[1] ? start[1] : end[1]; + + return new int[] { xmin, ymin, xmax, ymax }; + } + + + /** + * Sets the width, height, x and y values of the zoombox. + */ + protected void positionZoombox() { + int[] values = orderPositions(); + + zoombox.setLeft(values[0]); + zoombox.setTop(values[1]); + zoombox.setWidth(values[2] - values[0]); + zoombox.setHeight(values[3] - values[1]); + } + + + /** + * Clears the zoombox (set position and size to null). + */ + protected void clearZoombox() { + zoombox.setLeft(-10000); + zoombox.setTop(-10000); + zoombox.setWidth(1); + zoombox.setHeight(1); + } + + + /** + * Resets the zoom control (start point and zoombox). + */ + protected void reset() { + start[0] = -1; + start[1] = -1; + + clearZoombox(); + } + + + /** + * Fires a ZoomEvent to all registered listeners. + */ + protected void fireZoomEvent() { + int[] pos = orderPositions(); + + ZoomEvent event = new ZoomEvent(pos[0], pos[1], pos[2], pos[3]); + + for (ZoomHandler handler: handlers) { + handler.onZoom(event); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixEventSelect.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,170 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.IntDataItem; +import de.intevation.flys.client.shared.model.IntegerArrayData; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; + +import de.intevation.flys.client.client.services.FixingsOverviewService; +import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync; + +/** + * This UIProvider lets you select events. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixEventSelect +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + public static final int MAX_DISPLAYED_ITEMS = 5; + + protected FixingsOverviewServiceAsync overviewService = + GWT.create(FixingsOverviewService.class); + + protected List<String> events; + + public FixEventSelect() { + htmlOverview = ""; + events = new ArrayList<String>(); + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Canvas title = new Label(MESSAGES.eventselect()); + title.setHeight("25px"); + + layout.addMember(title); + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> list = dataList.getAll(); + + Data data = getData(list, "events"); + + VLayout dataLayout = new VLayout(); + dataLayout.setWidth(130); + + DataItem[] items = data.getItems(); + + if (items.length > MAX_DISPLAYED_ITEMS) { + for (int i = 0; i < MAX_DISPLAYED_ITEMS-2; ++i) { + Label l = new Label(items[i].getLabel()); + l.setHeight(25); + dataLayout.addMember(l); + } + Label l = new Label("..."); + l.setHeight(25); + dataLayout.addMember(l); + l = new Label(items[items.length-1].getLabel()); + l.setHeight(25); + dataLayout.addMember(l); + } + else { + for (int i = 0; i < items.length; i++) { + Label l = new Label(items[i].getLabel()); + l.setHeight(25); + dataLayout.addMember(l); + } + } + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(dataLayout); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + if (events.size() > 0) { + IntDataItem[] arr = new IntDataItem[events.size()]; + for (int i = 0, E = events.size(); i < E; i++) { + try { + Integer v = new Integer(events.get(i)); + arr[i] = new IntDataItem("id", "id", v.intValue()); + } + catch (NumberFormatException nfe) { + return data.toArray(new Data[data.size()]); + } + } + + IntegerArrayData iad = + new IntegerArrayData("events", "events", arr); + + data.add(iad); + } + + return data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + if (checked) { + events.add(cid); + } + else { + if (events.contains(cid)) { + events.remove(cid); + } + } + } + + + @Override + public boolean renderCheckboxes() { + return true; + } + + + public void success() { + for (FixEvent fe: fixInfo.getEvents()) { + events.add(fe.getCId()); + } + } + + public void dumpGWT(String cid) { + GWT.log("Setting values for cId: " + cid); + GWT.log("River: " + fixInfo.getRiver()); + GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); + GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixFunctionSelect.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,173 @@ +package de.intevation.flys.client.client.ui.fixation; + +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + +public class FixFunctionSelect extends FixationPanel { + private static final Map<String, String> funcDesc = new HashMap<String, String>(); + + static { + funcDesc.put("log", "W(Q) = m*ln(Q + b)"); + funcDesc.put("linear", "W(Q) = m * Q + b"); + funcDesc.put("log-linear", "W(Q) = a*ln(m*Q+b)"); + funcDesc.put("exp", "W(Q) = m * a^Q + b"); + funcDesc.put("quad", "W(Q) = n*Q^2+m*Q+b"); + funcDesc.put("pow", "W(Q) = a * Q^c + d"); + funcDesc.put("sq-pow", "S(Q) = a * Q^b"); + } + + /** The combobox.*/ + protected DynamicForm form; + + @Override + public Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + layout.setAlign(VerticalAlignment.TOP); + layout.setHeight(25); + + LinkedHashMap initial = new LinkedHashMap(); + + form = new DynamicForm(); + + int size = data.size(); + + for (int i = 0; i < size; i++) { + Data d = data.get(i); + + Label label = new Label(d.getDescription()); + label.setValign(VerticalAlignment.TOP); + label.setHeight(20); + label.setWidth(400); + + SelectItem combobox = new SelectItem(d.getLabel()); + combobox.setWidth(250); + + LinkedHashMap<String, String> funcTypes = new LinkedHashMap<String, String>(); + + boolean defaultSet = false; + boolean first = true; + + DataItem def = d.getDefault(); + String defValue = def != null ? def.getStringValue() : null; + + if (defValue != null && defValue.length() > 0) { + initial.put(d.getLabel(), def.getStringValue()); + defaultSet = true; + } + + // I was here. Me 2. + for (DataItem item: d.getItems()) { + if (!defaultSet && first) { + initial.put(d.getLabel(), item.getStringValue()); + first = false; + } + + funcTypes.put(item.getStringValue(), item.getLabel()); + } + + label.setWidth(50); + combobox.setValueMap(funcTypes); + combobox.setShowTitle(false); + form.setItems(combobox); + + layout.addMember(label); + layout.addMember(form); + } + + form.setValues(initial); + + layout.setAlign(VerticalAlignment.TOP); + + return layout; + } + + + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + VLayout vLayout = new VLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + int size = dataList.size(); + for (int i = 0; i < size; i++) { + Data data = dataList.get(i); + DataItem[] items = data.getItems(); + + for (DataItem item: items) { + HLayout hLayout = new HLayout(); + + String desc = funcDesc.containsKey(item.getLabel()) ? + funcDesc.get(item.getLabel()) : item.getLabel(); + hLayout.addMember(label); + hLayout.addMember(new Label(desc)); + + vLayout.addMember(hLayout); + vLayout.setWidth("130px"); + } + } + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + + @Override + public Data[] getData() { + Map values = form.getValues(); + Iterator keys = values.keySet().iterator(); + + Data[] list = new Data[values.size()]; + int i = 0; + + while (keys.hasNext()) { + String fieldname = (String) keys.next(); + String selection = (String) values.get(fieldname); + + DataItem item = new DefaultDataItem(fieldname, null, selection); + + list[i++] = new DefaultData( + fieldname, null, null, new DataItem[] { item }); + } + + return list; + } + + + @Override + public void setValues(String cid, boolean checked) { + } + + @Override + public boolean renderCheckboxes() { + return false; + } + + @Override + public void success() { + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixGaugeSelectPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,179 @@ +package de.intevation.flys.client.client.ui.fixation; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixGaugeSelectPanel +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected String first; + protected String second; + + protected SelectItem from; + protected SelectItem to; + + protected LinkedHashMap<String, String> mapValues; + + public FixGaugeSelectPanel() { + htmlOverview = ""; + + mapValues = new LinkedHashMap<String, String>(); + mapValues.put("0", MESSAGES.gauge_mnq()); + mapValues.put("1", MESSAGES.gauge_mq()); + mapValues.put("2", MESSAGES.gauge_mhq()); + mapValues.put("3", MESSAGES.gauge_hq5()); + } + + @Override + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Label title = new Label(MESSAGES.gauge_class()); + title.setHeight(25); + + from = new SelectItem(MESSAGES.from()); + to = new SelectItem(MESSAGES.to()); + + from.setShowTitle(false); + to.setShowTitle(false); + from.setValueMap(mapValues); + from.setDefaultValues("0"); + from.setWidth(160); + to.setValueMap(mapValues); + to.setDefaultValues("3"); + to.setWidth(160); + + DynamicForm form = new DynamicForm(); + StaticTextItem separator = new StaticTextItem("separator"); + separator.setShowTitle(false); + separator.setValue(MESSAGES.to()); + form.setNumCols(5); + form.setFields(from, separator, to); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data f = getData(items, "q1"); + Data t = getData(items, "q2"); + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(mapValues.get(fItems[0].getLabel())); + sb.append(" " + MESSAGES.to() + " "); + sb.append(mapValues.get(tItems[0].getLabel())); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveClassValues(); + if (valid) { + DataItem firstItem = new DefaultDataItem("q1", "q1", this.first); + DataItem secItem = new DefaultDataItem("q2", "q2", this.second); + data.add(new DefaultData( + "q1", + null, + null, + new DataItem[] { firstItem })); + data.add(new DefaultData( + "q2", + null, + null, + new DataItem[] { secItem })); + } + return data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + + @Override + public void success() {} + + protected boolean saveClassValues() { + String v1 = from.getValueAsString(); + String v2 = to.getValueAsString(); + try { + int v1i = Integer.parseInt(v1); + int v2i = Integer.parseInt(v2); + if (v1i <= v2i) { + this.first = v1; + this.second = v2; + return true; + } + } + catch(NumberFormatException nfe) { + return false; + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixLocationPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,193 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.ui.DoubleRangePanel; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixLocationPanel +extends FixationPanel +implements BlurHandler +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + /** The constant name of the input field to enter locations.*/ + public static final String FIELD_VALUE_LOCATION = "location"; + + /** The constant name of the input field to enter distance.*/ + public static final String FIELD_VALUE_DISTANCE = "distance"; + + DoubleRangePanel inputPanel; + + double from; + double to; + double step; + + public FixLocationPanel() { + htmlOverview = ""; + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Canvas title = new Label(MESSAGES.distance()); + title.setHeight("25px"); + + inputPanel = new DoubleRangePanel( + MESSAGES.unitFrom(), + MESSAGES.unitTo(), + MESSAGES.unitWidth(), + 0d, + 0d, + 0d, + 240, + this); + + layout.addMember(title); + layout.addMember(inputPanel); + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data f = getData(items, "ld_from"); + Data t = getData(items, "ld_to"); + Data s = getData(items, "ld_step"); + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + DataItem[] sItems = s.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(fItems[0].getLabel()); + sb.append(" " + MESSAGES.unitFrom() + " "); + sb.append(tItems[0].getLabel()); + sb.append(" " + MESSAGES.unitTo() + " "); + sb.append(sItems[0].getLabel()); + sb.append(" " + MESSAGES.unitWidth()); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveRangeValues(inputPanel); + if (valid) { + String f = Double.valueOf(this.from).toString(); + String t = Double.valueOf(this.to).toString(); + String s = Double.valueOf(this.step).toString(); + DataItem fi = new DefaultDataItem("ld_from", "ld_from", f); + DataItem ti = new DefaultDataItem("ld_to", "ld_to", t); + DataItem si = new DefaultDataItem("ld_step", "ld_step", s); + data.add(new DefaultData("ld_from", null, null, new DataItem[]{ fi })); + data.add(new DefaultData("ld_to", null, null, new DataItem[]{ ti })); + data.add(new DefaultData("ld_step", null, null, new DataItem[]{ si })); + } + // what else? + return data.toArray(new Data[data.size()]); + } + + + protected boolean saveRangeValues(DoubleRangePanel p) { + FormItem[] items = p.getFields(); + boolean valid = p.validateForm(); + + if(valid) { + this.from = p.getFrom(); + this.to = p.getTo(); + this.step = p.getStep(); + } + return valid; + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + + public void success() { + inputPanel.setValues(fixInfo.getFrom(), fixInfo.getTo(), 100d); + } + + /** + * This method is used to validate the inserted data in the form fields. + * + * @param event The BlurEvent that gives information about the FormItem that + * has been modified and its value. + */ + public void onBlur(BlurEvent event) { + FormItem item = event.getItem(); + String field = item.getFieldName(); + + if (field == null) { + return; + } + DoubleRangePanel p = (DoubleRangePanel) event.getForm(); + } + + + public void dumpGWT(String cid) { + GWT.log("Setting values for cId: " + cid); + GWT.log("River: " + fixInfo.getRiver()); + GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); + GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixMultiPeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,241 @@ +package de.intevation.flys.client.client.ui.fixation; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixMultiPeriodPanel +extends FixPeriodPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected ListGrid elements; + + protected String values; + + public FixMultiPeriodPanel() { + this("", ""); + } + + public FixMultiPeriodPanel(String startName, String endName) { + super(startName, endName); + } + + @Override + public Canvas createWidget(DataList data) { + HLayout input = new HLayout(); + VLayout root = new VLayout(); + VLayout grid = new VLayout(); + VLayout layout = (VLayout) super.createWidget(data); + Button add = new Button(MESSAGES.add()); + elements = new ListGrid(); + + add.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent ce) { + Date f = inputPanel.getFromDate(); + Date t = inputPanel.getToDate(); + if (f == null || t == null) { + return; + } + DateRangeRecord drr = new DateRangeRecord(f, t); + elements.addData(drr); + } + }); + layout.addMember(add); + + Label sel = new Label("Selected"); + sel.setHeight(25); + elements.setWidth(185); + elements.setHeight(120); + elements.setShowHeaderContextMenu(false); + elements.setCanReorderFields(false); + elements.setCanSort(false); + elements.setCanEdit(false); + ListGridField from = new ListGridField("from", "From"); + ListGridField to = new ListGridField("to", "To"); + from.setWidth(70); + to.setWidth(70); + + final ListGridField removeField = + new ListGridField("_removeRecord", "Remove Record"){{ + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; + + elements.addRecordClickHandler(new RecordClickHandler() { + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + event.getViewer().removeData(event.getRecord()); + } + }); + + elements.setFields(from, to, removeField); + + grid.addMember(sel); + grid.addMember(elements); + input.addMember(layout); + input.addMember(grid); + root.addMember(input); + + return root; + } + + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + layout.setWidth("400px"); + VLayout vLayout = new VLayout(); + vLayout.setWidth(130); + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + label.setHeight(25); + + List<Data> items = dataList.getAll(); + Data str = getData(items, "ana_data"); + DataItem[] strItems = str.getItems(); + + String[] pairs = strItems[0].getLabel().split(";"); + for (int i = 0; i < pairs.length; i++) { + String[] vals = pairs[i].split(","); + try { + long f = Long.valueOf(vals[0]).longValue(); + long t = Long.valueOf(vals[1]).longValue(); + Date from = new Date(f); + Date to = new Date(t); + String fromString = + DateTimeFormat.getMediumDateFormat().format(from); + String toString = + DateTimeFormat.getMediumDateFormat().format(to); + + Label dateLabel = new Label(fromString + " - " + toString); + dateLabel.setHeight(20); + vLayout.addMember(dateLabel); + } + catch(NumberFormatException nfe) { + } + } + Canvas back = getBackButton(dataList.getState()); + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveDateValues(); + if(valid) { + DataItem item = new DefaultDataItem("ana_data", null, this.values); + data.add(new DefaultData( + "ana_data", + null, + null, + new DataItem[] { item })); + } + return data.toArray(new Data[data.size()]); + } + + + @Override + protected boolean saveDateValues() { + ListGridRecord[] lgr = elements.getRecords(); + if (lgr.length == 0) { + return false; + } + String data = ""; + for (int i = 0; i < lgr.length; i++) { + DateRangeRecord drr = (DateRangeRecord) lgr[i]; + data += drr.getFrom() + "," + drr.getTo(); + data += ";"; + } + values = data; + return true; + } + + + protected static class DateRangeRecord extends ListGridRecord { + protected Date from; + protected Date to; + + protected final static String FROM_FIELD = "from"; + protected final static String TO_FIELD = "to"; + + public DateRangeRecord (Date from, Date to) { + setFrom(from); + setTo(to); + } + + public void setFrom(Date from) { + this.from = from; + setAttribute( + FROM_FIELD, + DateTimeFormat.getMediumDateFormat().format(from)); + } + + + public void setTo(Date to) { + this.to = to; + setAttribute( + TO_FIELD, + DateTimeFormat.getMediumDateFormat().format(to)); + } + + + public long getFrom() { + return this.from.getTime(); + } + + + public long getTo() { + return this.to.getTime(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixPeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,231 @@ +package de.intevation.flys.client.client.ui.fixation; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.DateRangeItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixPeriodPanel +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + DateRangeItem inputPanel; + + long start; + long end; + + protected String startName; + protected String endName; + + public FixPeriodPanel() { + this("start", "end"); + } + + public FixPeriodPanel(String startName, String endName) { + this.startName = startName; + this.endName = endName; + htmlOverview = ""; + } + + @Override + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Label title = new Label(data.get(0).getDescription()); + title.setHeight("25px"); + + DynamicForm form = new DynamicForm(); + inputPanel = new DateRangeItem(); + inputPanel.setToTitle(MESSAGES.to()); + inputPanel.setFromTitle(MESSAGES.from()); + inputPanel.setShowTitle(false); + form.setFields(inputPanel); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data start = getData(items, startName); + Data end = getData(items, endName); + DataItem[] startItem = start.getItems(); + DataItem[] endItem = end.getItems(); + + String v1 = startItem[0].getStringValue(); + String v2 = endItem[0].getStringValue(); + + long v1l = 0; + long v2l = 0; + try { + v1l = Long.parseLong(v1); + v2l = Long.parseLong(v2); + } + catch(NumberFormatException nfe) { + GWT.log(nfe.toString()); + } + Date d1 = new Date(v1l); + Date d2 = new Date(v2l); + + DateTimeFormat f = + DateTimeFormat.getFormat( + DateTimeFormat.PredefinedFormat.DATE_MEDIUM); + StringBuilder sb = new StringBuilder(); + sb.append(f.format(d1) + " - "); + sb.append(f.format(d2)); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveDateValues(); + if(valid) { + String start = Long.valueOf(this.start).toString(); + String end = Long.valueOf(this.end).toString(); + DataItem startItem = new DefaultDataItem(startName, startName, start); + DataItem endItem = new DefaultDataItem(endName, endName, end); + data.add(new DefaultData( + startName, + null, + null, + new DataItem[] { startItem })); + data.add(new DefaultData( + endName, + null, + null, + new DataItem[] { endItem })); + } + + return data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + @Override + public void success() { + List<FixEvent> list = fixInfo.getEvents(); + + // The date in FixEvent is always "de" locale, so it seems... + DateTimeFormat df = DateTimeFormat.getFormat("yy.MM.yyyy"); + + if (!setFromAndToDate(list, df)) { + // or perhaps "en"? + df = DateTimeFormat.getFormat("MM/dd/yyyy"); + + if (!setFromAndToDate(list, df)) { + GWT.log("FixPeriodPanel::success(): could not set from and to dates!"); + } + } + } + + protected boolean setFromAndToDate(List<FixEvent> list, DateTimeFormat df) { + try { + setFromDate(list.get(0).getDate(), df); + setToDate(list.get(list.size() - 1).getDate(), df); + return true; + } + catch(IllegalArgumentException ex) { + GWT.log("FixPeriodPanel::setFromAndToDate(): " + ex.toString()); + return false; + } + } + + protected void setFromDate(String date, DateTimeFormat df) + throws IllegalArgumentException + { + Date from = df.parse(date); + this.inputPanel.setFromDate(from); + } + + protected void setToDate(String date, DateTimeFormat df) + throws IllegalArgumentException + { + Date to = df.parse(date); + this.inputPanel.setToDate(to); + } + + protected boolean saveDateValues() { + Date st = inputPanel.getFromDate(); + Date en = inputPanel.getToDate(); + if (st == null || en == null) { + SC.warn(MESSAGES.error_wrong_date()); + return false; + } + + long start = st.getTime(); + long end = en.getTime(); + + if (start <= end) { + this.start = start; + this.end = end; + return true; + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixQSelectPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,63 @@ +package de.intevation.flys.client.client.ui.fixation; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; + +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixQSelectPanel +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + public FixQSelectPanel() { + htmlOverview = ""; + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + return new Canvas(); + } + + @Override + public Canvas createOld(DataList dataList) { + return new Canvas(); + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + return new Data[0]; + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + + public void success() {} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,484 @@ +package de.intevation.flys.client.client.ui.fixation; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.HTMLPane; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.FixingsOverviewService; +import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync; +import de.intevation.flys.client.client.ui.AbstractUIProvider; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; +import de.intevation.flys.client.shared.model.FixFilter; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; + +import java.util.Date; +import java.util.HashMap; + + +/** + * This UIProvider creates helper panel for fixation analysis without input + * elements. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public abstract class FixationPanel +extends AbstractUIProvider +implements ResizedHandler +{ + private static final long serialVersionUID = -3667553404493415619L; + + protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>(); + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected FixingsOverviewServiceAsync overviewService = + GWT.create(FixingsOverviewService.class); + + protected String htmlOverview; + protected FixingsOverviewInfo fixInfo; + protected TabSet tabs; + protected Tab events; + protected Tab chart; + protected VLayout chartContainer; + protected Img chartImg; + protected TextItem kmText; + + public static final DateTimeFormat DTF = DateTimeFormat.getFormat("dd.MM.yyyy"); + + + public FixationPanel() { + chartImg = new Img(); + htmlOverview = ""; + } + + + /** Get the (master) artifact UUID. */ + protected String getArtifactUuid() { + return this.artifact.getUuid(); + } + + protected void init() { + } + + @Override + public Data[] getData() { + return null; + } + + @Override + public Canvas create(DataList list) { + VLayout layout = new VLayout(); + + Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(list); + + layout.addMember(widget); + layout.addMember(submit); + return layout; + } + + @Override + public Canvas createOld(DataList list) { + return new DynamicForm(); + } + + protected Canvas createHelper() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + tabs = new TabSet(); + events = new Tab(MESSAGES.events()); + chart = new Tab(MESSAGES.kmchart()); + + chartContainer = new VLayout(); + Canvas scroll = createChartHelper(); + + VLayout layout = new VLayout(); + layout.addResizedHandler(this); + layout.addMember(chartContainer); + layout.addMember(scroll); + layout.setAlign(Alignment.CENTER); + chart.setPane(layout); + + final HTMLPane eventPane = new HTMLPane(); + + String river = artifact.getArtifactDescription().getRiver(); + createCallback(); + + String callBack = "fixationCallback(this.checked, this.name)"; + + if (this.artifact instanceof FixAnalysisArtifact == false) + return chartContainer; + + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + overviewService.generateOverview( + locale, + artifact.getUuid(), + getOverviewFilter(art.getFilter()), + renderCheckboxes(), + callBack, + new AsyncCallback<FixingsOverviewInfo>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not receive overview."); + SC.warn(caught.getMessage()); + } + @Override + public void onSuccess(FixingsOverviewInfo info) { + GWT.log("Successfully loaded overview."); + fixInfo = info; + htmlOverview = info.getHTML(); + FixAnalysisArtifact art = (FixAnalysisArtifact)artifact; + FixFilter filter = art.getFilter(); + filter.setRiver(info.getRiver()); + if (filter.getCurrentKm() == -Double.MAX_VALUE || + filter.getCurrentKm() == -1d) { + filter.setCurrentKm(info.getFrom()); + filter.setToKm(info.getTo()); + } + if (kmText != null) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(filter.getCurrentKm()); + kmText.setValue(nf.format(d)); + } catch (NumberFormatException e) { + kmText.setValue(filter.getCurrentKm()); + } + } + eventPane.setContents(htmlOverview); + updateChartTab(fixInfo.getFrom()); + events.setPane(eventPane); + success(); + } + }); + + tabs.addTab(events); + tabs.addTab(chart); + + return tabs; + } + + + protected Canvas createChartHelper() { + DynamicForm form = new DynamicForm(); + Button lower = new Button("<<"); + lower.setWidth(30); + Button upper = new Button(">>"); + upper.setWidth(30); + kmText = new TextItem(); + kmText.setWidth(60); + kmText.setShowTitle(false); + + + form.setFields(kmText); + form.setWidth(60); + lower.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent ce) { + FixFilter filter = updateChartTabLow(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(filter.getCurrentKm()); + kmText.setValue(nf.format(d)); + } catch (NumberFormatException e) { + kmText.setValue(filter.getCurrentKm()); + } + } + }); + + upper.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent ce) { + FixFilter filter = updateChartTabUp(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(filter.getCurrentKm()); + kmText.setValue(nf.format(d)); + } catch (NumberFormatException e) { + kmText.setValue(filter.getCurrentKm()); + } + } + }); + + kmText.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent ce) { + //TODO: get current value. + if(ce.getItem().getValue() != null) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = nf.parse(ce.getItem().getValue().toString()); + updateChartTab(d); + } + catch(NumberFormatException nfe) { + // Do nothing. + } + } + } + }); + + HLayout layout = new HLayout(); + layout.setAlign(Alignment.CENTER); + + layout.addMember(lower); + layout.addMember(form); + layout.addMember(upper); + return layout; + } + + protected void updateChartTab(double km) { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + if (fixInfo != null) { + if (km < fixInfo.getFrom()) km = fixInfo.getFrom(); + if (km > fixInfo.getTo()) km = fixInfo.getTo(); + } + + FixFilter filter = art.getFilter(); + + if (km < filter.getFromKm()) km = filter.getFromKm(); + if (km > filter.getToKm()) km = filter.getToKm(); + + filter.setCurrentKm(km); + + int hWidth = helperContainer.getWidth() - 12; + int hHeight = helperContainer.getHeight() - 62; + + if ((int)(hHeight *4f/3) < hWidth) { + hWidth = (int)(hHeight * 4f/3); + } + else { + hHeight = (int)(hWidth *3f/4); + } + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "fixings-km-chart"; + imgUrl += "?locale=" + locale; + imgUrl += "&filter=" + getChartFilter(filter, hWidth, hHeight); + + if (chartContainer.hasMember(chartImg)) { + chartImg.setWidth(hWidth); + chartImg.setHeight(hHeight); + chartImg.setSrc(imgUrl); + } + else { + chartImg = new Img(imgUrl, hWidth, hHeight); + chartContainer.addMember(chartImg); + } + } + + + protected FixFilter updateChartTabLow() { + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + FixFilter filter = art.getFilter(); + + double curr = filter.getCurrentKm(); + if (curr > filter.getFromKm()) { + double newVal = (curr - 0.1) * 10; + long round = Math.round(newVal); + updateChartTab(((double)round) / 10); + } + return filter; + } + + + protected FixFilter updateChartTabUp() { + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + FixFilter filter = art.getFilter(); + + double curr = filter.getCurrentKm(); + if (curr < filter.getToKm()) { + double newVal = (curr + 0.1) * 10; + long round = Math.round(newVal); + updateChartTab(((double)round) / 10); + } + return filter; + } + + + @Override + public void onResized(ResizedEvent re) { + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + updateChartTab(art.getFilter().getCurrentKm()); + } + + + private native void createCallback() /*-{ + $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); + }-*/; + + private static void helperCallback(boolean checked, String name) { + String[] parts = name.split(":"); + String uuid = parts[0]; + String cid = parts[1]; + + FixationPanel p = FixationPanel.getInstance(uuid); + if (p != null) { + p.setValues(cid, checked); + } + } + + private static FixationPanel getInstance(String uuid) { + return instances.get(uuid); + } + + public abstract Canvas createWidget(DataList data); + public abstract void setValues(String cid, boolean checked); + public abstract boolean renderCheckboxes(); + public abstract void success(); + + + /** Creates JSON string from filter. */ + public static String getOverviewFilter(FixFilter filter) { + String river = filter.getRiver(); + + if (river != null && river.length() > 0) { + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jfix.put("fixings", createFilter(filter, jfilter)); + return jfix.toString(); + } + return ""; + } + + public String getChartFilter(FixFilter filter, int width, int height) { + String river = filter.getRiver(); + double currentKm = filter.getCurrentKm(); + double fromKm = filter.getFromKm(); + double toKm = filter.getToKm(); + + if (river != null && river.length() > 0 && + currentKm >= fromKm && currentKm <= toKm) + { + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + JSONObject jkm = new JSONObject(); + JSONNumber jkmValue = new JSONNumber(currentKm); + JSONObject jextent = new JSONObject(); + JSONNumber jwidth = new JSONNumber(width); + JSONNumber jheight = new JSONNumber(height); + + jkm.put("value", jkmValue); + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jfilter.put("km", jkm); + jextent.put("width", jwidth); + jextent.put("height", jheight); + jfilter.put("extent", jextent); + jfix.put("fixings", createFilter(filter, jfilter)); + return jfix.toString(); + } + return ""; + } + + protected static JSONObject createFilter(FixFilter filter, JSONObject root) { + double fromKm = filter.getFromKm(); + double toKm = filter.getToKm(); + boolean hasDate = filter.getFromDate() > 0 && filter.getToDate() > 0; + + if (fromKm >= 0 && toKm >= 0 && fromKm <= toKm) { + JSONObject range = new JSONObject(); + JSONObject fromtokm = new JSONObject(); + JSONNumber f = new JSONNumber(fromKm); + JSONNumber t = new JSONNumber(toKm); + fromtokm.put("from", f); + fromtokm.put("to", t); + root.put("range", fromtokm); + } + + JSONObject and = new JSONObject(); + if (hasDate) { + long fromDate = filter.getFromDate(); + long toDate = filter.getToDate(); + + Date df = new Date(fromDate); + Date dt = new Date(toDate); + + JSONObject daterange = new JSONObject(); + JSONString f = new JSONString(DTF.format(df)); + JSONString t = new JSONString(DTF.format(dt)); + + daterange.put("from", f); + daterange.put("to", t); + and.put("date-range", daterange); + } + + int fromClass = filter.getFromClass(); + int toClass = filter.getToClass(); + + if (fromClass >= 0 && toClass >= 0 && fromClass <= toClass) { + JSONObject classrange = new JSONObject(); + JSONNumber f = new JSONNumber(fromClass); + JSONNumber t = new JSONNumber(toClass); + + classrange.put("from", f); + classrange.put("to", t); + and.put("sector-range", classrange); + } + + int[] events = filter.getEvents(); + + if (events.length > 0) { + StringBuilder cids = new StringBuilder(); + + for (int i = 0; i < events.length; i++) { + if (i > 0) cids.append(' '); + cids.append(events[i]); + } + JSONObject columns = new JSONObject(); + columns.put("cids", new JSONString(cids.toString())); + and.put("columns", columns); + } + if (and.size() > 0) { + JSONObject jFilter = new JSONObject(); + jFilter.put("and", and); + root.put("filter", jFilter); + } + return root; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/CapabilitiesPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,108 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Grid; + +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.Layout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Capabilities; +import de.intevation.flys.client.shared.model.ContactInformation; +import de.intevation.flys.client.client.FLYSConstants; + + +public class CapabilitiesPanel extends VLayout { + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected Capabilities capabilites; + + + public CapabilitiesPanel(Capabilities capabilites) { + super(); + this.capabilites = capabilites; + + initLayout(); + } + + + protected void initLayout() { + setMargin(5); + setOverflow(Overflow.AUTO); + initContent(); + } + + + protected void initContent() { + Grid grid = new Grid(10, 2); + grid.setCellPadding(10); + + grid.setText(0, 0, MSG.capabilitiesTitle() + ":"); + grid.setText(0, 1, capabilites.getTitle()); + grid.setText(1, 0, MSG.capabilitiesURL() + ":"); + grid.setText(1, 1, capabilites.getOnlineResource()); + grid.setText(2, 0, MSG.capabilitiesAccessConstraints() + ":"); + grid.setText(2, 1, capabilites.getAccessConstraints()); + grid.setText(3, 0, MSG.capabilitiesFees() + ":"); + grid.setText(3, 1, capabilites.getFees()); + + int row = 4; + + ContactInformation ci = capabilites.getContactInformation(); + + grid.setText(row, 0, MSG.capabilitiesContactInformation() + ":"); + + String person = ci.getPerson(); + if (person != null && person.length() > 0) { + grid.setText(row++, 1, person); + } + + String organization = ci.getOrganization(); + if (organization != null && organization.length() > 0) { + grid.setText(row++, 1, organization); + } + + String address = ci.getAddress(); + if (address != null && address.length() > 0) { + grid.setText(row++, 1, address); + } + + String pc = ci.getPostcode(); + String c = ci.getCity(); + if ((pc != null && pc.length() > 0) || (c != null && c.length() > 0)) { + grid.setText(row++, 1, pc + " " + c); + } + + String email = ci.getEmail(); + if (email != null && email.length() > 0) { + grid.setText(row++, 1, MSG.capabilitiesEmail() + ": " + email); + } + + String phone = ci.getPhone(); + if (phone != null && phone.length() > 0) { + grid.setText(row++, 1, MSG.capabilitiesPhone() + ": " + phone); + } + + Label title = new Label(MSG.capabilitiesHint()); + title.setHeight(25); + title.setStyleName("capabilities-info-title"); + + addMember(title); + addMember(grid); + } + + + protected Layout createRow(Label title, Label content) { + title.setWidth(100); + + HLayout layout = new HLayout(); + layout.addMember(title); + layout.addMember(content); + + return layout; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/DrawControl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,251 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.types.SelectionType; +import com.smartgwt.client.widgets.ImgButton; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.utils.EnableDisableCmd; + +import java.util.LinkedHashMap; + +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.Style; +import org.gwtopenmaps.openlayers.client.control.Control; +import org.gwtopenmaps.openlayers.client.control.DrawFeature; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; +import org.gwtopenmaps.openlayers.client.feature.VectorFeature; +import org.gwtopenmaps.openlayers.client.handler.Handler; +import org.gwtopenmaps.openlayers.client.handler.PathHandler; +import org.gwtopenmaps.openlayers.client.handler.PolygonHandler; +import org.gwtopenmaps.openlayers.client.layer.Vector; +import org.gwtopenmaps.openlayers.client.util.Attributes; + +/** + * Widget that handles the drawing of pipes and dikes in the DigitizePanel (MapPanel). + */ +public class DrawControl extends HLayout implements VectorFeatureAddedListener { + + public static final String BARRIER_PIPE1 = "pipe1"; + public static final String BARRIER_PIPE2 = "pipe2"; + public static final String BARRIER_DITCH = "ditch"; + public static final String BARRIER_DAM = "dam"; + public static final String BARRIER_RINGDIKE = "ring_dike"; + + // FIXME: i18n + public static final String BARRIER_PIPE1_VALUE = "Rohr 1"; + public static final String BARRIER_PIPE2_VALUE = "Rohr 2"; + public static final String BARRIER_DITCH_VALUE = "Graben"; + public static final String BARRIER_DAM_VALUE = "Damm"; + public static final String BARRIER_RINGDIKE_VALUE = "Ringdeich"; + + public static final String FIELD_BARRIER_TYPE = "field_barrier_type"; + + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected EnableDisableCmd cmd; + + protected ImgButton button; + protected DynamicForm form; + + protected Map map; + protected Vector layer; + + protected Control control; + + + public DrawControl(Map map, Vector layer, EnableDisableCmd cmd) { + this.map = map; + this.layer = layer; + this.cmd = cmd; + + initialize(); + } + + + protected void initialize() { + setWidth(100); + setMembersMargin(0); + + button = new ImgButton(); + + final String baseUrl = GWT.getHostPageBaseURL(); + button.setSrc(baseUrl + MSG.digitize()); + button.setActionType(SelectionType.CHECKBOX); + button.setSize(20); + button.setShowRollOver(false); + button.setSelected(false); + button.setTooltip(MSG.digitizeObjects()); + + button.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + if (button.isSelected()) { + cmd.enable(); + } + else { + cmd.disable(); + } + } + }); + + form = new DynamicForm(); + form.setWidth(100); + form.setTitlePrefix(""); + form.setTitleSuffix(""); + + final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); + map.put(BARRIER_PIPE1, MSG.getString(BARRIER_PIPE1)); + map.put(BARRIER_PIPE2, MSG.getString(BARRIER_PIPE2)); + map.put(BARRIER_DITCH, MSG.getString(BARRIER_DITCH)); + map.put(BARRIER_DAM, MSG.getString(BARRIER_DAM)); + map.put(BARRIER_RINGDIKE, MSG.getString(BARRIER_RINGDIKE)); + + final LinkedHashMap<String, String> ics = new LinkedHashMap<String, String>(); + ics.put(BARRIER_PIPE1, BARRIER_PIPE1); + ics.put(BARRIER_PIPE2, BARRIER_PIPE2); + ics.put(BARRIER_DITCH, BARRIER_DITCH); + ics.put(BARRIER_DAM, BARRIER_DAM); + ics.put(BARRIER_RINGDIKE, BARRIER_RINGDIKE); + + final SelectItem box = new SelectItem(FIELD_BARRIER_TYPE); + box.setTitle(""); + box.setWidth(100); + box.setValueMap(map); + box.setImageURLSuffix(".png"); + box.setValueIcons(ics); + + box.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent e) { + setSelectedControl(); + } + }); + + form.setFields(box); + + addMember(button); + addMember(form); + + layer.addVectorFeatureAddedListener(this); + + activate(false); + } + + + protected String getSelectedType() { + return form.getValueAsString(FIELD_BARRIER_TYPE); + } + + + @Override + public void onFeatureAdded(FeatureAddedEvent evt) { + setCurrentType(evt.getVectorFeature()); + } + + + protected void setCurrentType(VectorFeature feature) { + final Attributes attrs = feature.getAttributes(); + String type = attrs.getAttributeAsString("typ"); + + if (type == null || type.length() == 0) { + type = getSelectedType(); + + final Style style = FloodMap.getStyle(type); + if (style != null) { + feature.setStyle(style); + } + + if (type.equals(BARRIER_PIPE1)) { + attrs.setAttribute("typ", BARRIER_PIPE1_VALUE); + } + else if (type.equals(BARRIER_PIPE2)) { + attrs.setAttribute("typ", BARRIER_PIPE2_VALUE); + } + else if (type.equals(BARRIER_DAM)) { + attrs.setAttribute("typ", BARRIER_DAM_VALUE); + } + else if (type.equals(BARRIER_DITCH)) { + attrs.setAttribute("typ", BARRIER_DITCH_VALUE); + } + else if (type.equals(BARRIER_RINGDIKE)) { + attrs.setAttribute("typ", BARRIER_RINGDIKE_VALUE); + } + + layer.redraw(); + } + } + + + protected void removeControl() { + if (control != null) { + control.deactivate(); + map.removeControl(control); + } + } + + + protected void setSelectedControl() { + removeControl(); + + final String type = getSelectedType(); + + if (type == null || type.length() == 0) { + return; + } + + if (type.equalsIgnoreCase(BARRIER_RINGDIKE)) { + control = createDrawPolygonControl(); + } + else { + control = createDrawLineControl(); + } + + map.addControl(control); + control.activate(); + + // Make sure the barrier layer is on top; sometime it looses it z-index... + layer.setZIndex(1000); + } + + + protected Control createDrawControl(Handler handler) { + return new DrawFeature(layer, handler); + } + + + protected Control createDrawPolygonControl() { + return createDrawControl(new PolygonHandler()); + } + + + protected Control createDrawLineControl() { + return createDrawControl(new PathHandler()); + } + + + public void activate(boolean activate) { + final FormItem item = form.getField(FIELD_BARRIER_TYPE); + + if (activate) { + button.select(); + item.enable(); + setSelectedControl(); + } + else { + removeControl(); + button.deselect(); + item.disable(); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/ElevationWindow.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,432 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.types.SortArrow; +import com.smartgwt.client.types.SortDirection; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.IButton; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.events.CloseClickEvent; +import com.smartgwt.client.widgets.events.CloseClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; +import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; +import com.smartgwt.client.widgets.grid.events.RowOutEvent; +import com.smartgwt.client.widgets.grid.events.RowOutHandler; +import com.smartgwt.client.widgets.grid.events.RowOverEvent; +import com.smartgwt.client.widgets.grid.events.RowOverHandler; + +import org.gwtopenmaps.openlayers.client.Style; +import org.gwtopenmaps.openlayers.client.feature.VectorFeature; +import org.gwtopenmaps.openlayers.client.geometry.Geometry; +import org.gwtopenmaps.openlayers.client.geometry.LinearRing; +import org.gwtopenmaps.openlayers.client.geometry.LineString; +import org.gwtopenmaps.openlayers.client.geometry.Point; +import org.gwtopenmaps.openlayers.client.geometry.Polygon; +import org.gwtopenmaps.openlayers.client.layer.Vector; +import org.gwtopenmaps.openlayers.client.layer.VectorOptions; +import org.gwtopenmaps.openlayers.client.util.Attributes; + +import de.intevation.flys.client.client.FLYSConstants; + + + +public class ElevationWindow extends Window { + + public static FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public static final int WINDOW_WIDTH = 250; + public static final int WINDOW_HEIGHT = 250; + + protected FloodMap floodmap; + protected Vector layer; + protected VectorFeature feature; + + protected ListGrid grid; + + + private class PointRecord extends ListGridRecord { + protected VectorFeature point; + + public PointRecord(VectorFeature point, double x, double y, String z) { + super(); + + this.point = point; + setAttribute("x", x); + setAttribute("y", y); + setAttribute("z", z); + } + + public VectorFeature getPoint() { + return point; + } + } + + + public ElevationWindow(FloodMap floodmap, VectorFeature feature) { + super(); + this.feature = feature; + this.floodmap = floodmap; + + init(); + } + + + protected void init() { + addCloseClickHandler(new CloseClickHandler() { + public void onCloseClick(CloseClickEvent evt) { + doClose(); + } + }); + + initLayout(); + initEdit(); + updateGrid(); + } + + + protected void initLayout() { + setWidth(WINDOW_WIDTH); + setHeight(WINDOW_HEIGHT); + setTitle(MSG.ele_window_title()); + + VLayout root = new VLayout(); + root.setMembersMargin(5); + root.setPadding(5); + + root.addMember(getLabel()); + root.addMember(getGrid()); + root.addMember(getButtonBar()); + + addItem(root); + centerInPage(); + } + + + protected void initEdit() { + VectorOptions opts = new VectorOptions(); + opts.setProjection(floodmap.getRiverProjection()); + opts.setMaxExtent(floodmap.getMaxExtent()); + + layer = new Vector("tmp", opts); + layer.setIsBaseLayer(false); + + floodmap.getMap().addLayer(layer); + } + + + public Style getStyle() { + Style style = new Style(); + style.setStrokeColor("#000000"); + style.setStrokeWidth(1); + style.setFillColor("#FF0000"); + style.setFillOpacity(0.5); + style.setPointRadius(5); + style.setStrokeOpacity(1.0); + return style; + } + + + public Style getHighStyle() { + Style style = new Style(); + style.setStrokeColor("#000000"); + style.setStrokeWidth(1); + style.setFillColor("#FFFF22"); + style.setFillOpacity(0.5); + style.setPointRadius(5); + style.setStrokeOpacity(1.0); + return style; + } + + + protected Label getLabel() { + Label label = new Label(MSG.ele_window_label()); + label.setHeight(25); + + return label; + } + + + protected ListGrid getGrid() { + if (grid == null) { + grid = new ListGrid(); + grid.setCanEdit(true); + grid.setCanReorderFields(false); + grid.setAutoFitMaxWidth(WINDOW_WIDTH); + grid.setShowHeaderContextMenu(false); + grid.setShowSortArrow(SortArrow.NONE); + grid.setSortDirection(SortDirection.DESCENDING); + grid.setSelectionType(SelectionStyle.NONE); + + ListGridField x = new ListGridField("x", MSG.ele_window_x_col()); + x.setCanEdit(false); + + ListGridField y = new ListGridField("y", MSG.ele_window_y_col()); + y.setCanEdit(false); + + ListGridField z = new ListGridField("z", MSG.ele_window_z_col()); + z.setCanEdit(true); + + grid.setFields(x, y, z); + + grid.addRowOverHandler(new RowOverHandler() { + public void onRowOver(RowOverEvent evt) { + PointRecord pr = (PointRecord) evt.getRecord(); + VectorFeature p = pr.getPoint(); + + p.setStyle(getHighStyle()); + layer.redraw(); + } + }); + + grid.addRowOutHandler(new RowOutHandler() { + public void onRowOut(RowOutEvent evt) { + PointRecord pr = (PointRecord) evt.getRecord(); + VectorFeature p = pr.getPoint(); + + p.setStyle(getStyle()); + layer.redraw(); + } + }); + + grid.addEditCompleteHandler(new EditCompleteHandler() { + public void onEditComplete(EditCompleteEvent evt) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + String z = (String) evt.getNewValues().get("z"); + + try { + nf.parse(z); + } + catch (NumberFormatException nfe) { + SC.warn(MSG.ele_window_format_error() + " " + z); + + PointRecord old = (PointRecord) evt.getOldRecord(); + + ListGridRecord[] records = grid.getRecords(); + records[evt.getRowNum()] = old; + + grid.setRecords(records); + } + + } + }); + } + + return grid; + } + + + protected HLayout getButtonBar() { + HLayout bar = new HLayout(); + bar.setAlign(Alignment.CENTER); + bar.setHeight(25); + bar.setMembersMargin(15); + + bar.addMember(getOKButton()); + bar.addMember(getCancelButton()); + + return bar; + } + + + protected IButton getOKButton() { + IButton btn = new IButton(MSG.ele_window_ok_button()); + + btn.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent evt) { + if (saveElevation()) { + doClose(); + } + + } + }); + + return btn; + } + + + protected IButton getCancelButton() { + IButton btn = new IButton(MSG.ele_window_cancel_button()); + + btn.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent evt) { + doClose(); + } + }); + + return btn; + } + + + public void updateGrid() { + Attributes attr = feature.getAttributes(); + Geometry geom = feature.getGeometry(); + + String barrierType = null; + + if (attr != null) { + barrierType = attr.getAttributeAsString("typ"); + } + else { + barrierType = DrawControl.BARRIER_DAM_VALUE; + } + + GWT.log("Geometry is from type: " + geom.getClassName()); + GWT.log("Barrier is from type: " + barrierType); + + double[][] points = getPointsFromGeometry(geom); + double[] ele = extractElevations(attr); + + if (points == null) { + return; + } + + NumberFormat nf = NumberFormat.getDecimalFormat(); + + ListGrid grid = getGrid(); + + int zLen = ele != null ? ele.length : 0; + + for (int i = 0, len = points.length; i < len; i++) { + double[] point = points[i]; + VectorFeature p = addPoint(point[0], point[1]); + + String value = null; + + if (zLen > i) { + value = nf.format(ele[i]); + } + else if (barrierType.equals(DrawControl.BARRIER_DITCH_VALUE)) { + value = "-9999"; + } + else { + value = "9999"; + } + + grid.addData(new PointRecord(p, point[0], point[1], value)); + } + + grid.redraw(); + } + + + public static double[] extractElevations(Attributes attr) { + if (attr == null) { + return null; + } + + String elevationStr = attr.getAttributeAsString("elevation"); + + if (elevationStr == null || elevationStr.length() == 0) { + return null; + } + + String[] elevations = elevationStr.split(" "); + + int len = elevations != null ? elevations.length : 0; + + if (len == 0) { + return null; + } + + double[] res = new double[len]; + + for (int i = 0; i < len; i++) { + try { + res[i] = Double.valueOf(elevations[i]); + } + catch (NumberFormatException nfe) { + // go on + } + } + + return res; + } + + + public static double[][] getPointsFromGeometry(Geometry geom) { + String clazz = geom.getClassName(); + + if (clazz != null && clazz.equals(Geometry.LINESTRING_CLASS_NAME)) { + return getPointsFromLineString( + LineString.narrowToLineString(geom.getJSObject())); + } + else if (clazz != null && clazz.equals(Geometry.POLYGON_CLASS_NAME)) { + return getPointsFromPolygon( + Polygon.narrowToPolygon(geom.getJSObject())); + } + else { + SC.warn(MSG.ele_window_geometry_error() + " " + clazz); + } + + return null; + } + + + public static double[][] getPointsFromLineString(LineString line) { + return line.getCoordinateArray(); + } + + + public static double[][] getPointsFromPolygon(Polygon polygon) { + LinearRing[] rings = polygon.getComponents(); + + return getPointsFromLineString(rings[0]); + } + + + protected VectorFeature addPoint(double x, double y) { + VectorFeature point = new VectorFeature(new Point(x, y), getStyle()); + layer.addFeature(point); + + return point; + } + + + protected boolean saveElevation() { + ListGridRecord[] records = grid.getRecords(); + + NumberFormat nf = NumberFormat.getDecimalFormat(); + + StringBuilder sb = new StringBuilder(); + + for (ListGridRecord record: records) { + PointRecord pr = (PointRecord) record; + String value = pr.getAttributeAsString("z"); + + try { + double z = nf.parse(value); + sb.append(String.valueOf(z)); + } + catch (NumberFormatException nfe) { + SC.warn(MSG.ele_window_save_error()); + return false; + } + + sb.append(" "); + } + + Attributes attr = feature.getAttributes(); + attr.setAttribute("elevation", sb.toString()); + + return true; + } + + + protected void doClose() { + floodmap.getMap().removeLayer(layer); + destroy(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/ExternalWMSWindow.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,394 @@ +package de.intevation.flys.client.client.ui.map; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.LinkedHashMap; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.ComboBoxItem; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.Layout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Capabilities; +import de.intevation.flys.client.shared.model.WMSLayer; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.GCService; +import de.intevation.flys.client.client.services.GCServiceAsync; +import de.intevation.flys.client.client.services.MapUrlService; +import de.intevation.flys.client.client.services.MapUrlServiceAsync; + + +public class ExternalWMSWindow extends Window { + + public interface LayerLoader { + void load(List<WMSLayer> toLoad); + } // end of interface WMSLayerLoader + + + protected GCServiceAsync gcService = GWT.create(GCService.class); + protected MapUrlServiceAsync muService = GWT.create(MapUrlService.class); + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected Layout inputPanel; + protected Layout infoPanel; + protected Layout layersPanel; + + protected Capabilities capabilites; + + protected String srs; + + protected LinkedHashMap<String, String> urls; + protected String url; + + protected LayerLoader loader; + + + public ExternalWMSWindow(LayerLoader loader) { + super(); + this.urls = new LinkedHashMap<String, String>(); + this.loader = loader; + } + + + public ExternalWMSWindow(LayerLoader loader, String srs) { + this(loader); + this.srs = srs; + } + + + protected void setUrl(String url) { + this.url = url; + } + + + protected String getUrl() { + return url; + } + + + protected String getCapabilitiesUrl() { + String cUrl = url; + + if (url.indexOf("?") >= 0) { + cUrl += "&SERVICE=WMS&REQUEST=GetCapabilities"; + } + else { + cUrl += "?SERVICE=WMS&REQUEST=GetCapabilities"; + } + + return cUrl; + } + + + protected void setCapabilites(Capabilities capabilites) { + this.capabilites = capabilites; + } + + + public void start() { + show(); + centerInPage(); + + goToInputPanel(); + } + + + protected void goToInputPanel() { + clearItems(); + + inputPanel = createInputPanel(); + + addItem(inputPanel); + + setWidth(380); + setHeight(140); + } + + + protected void goToInfoPanel() { + clearItems(); + + infoPanel = createInfoPanel(); + + addItem(infoPanel); + + setWidth(500); + setHeight(500); + + centerInPage(); + } + + + protected void goToLayersPanel() { + clearItems(); + + layersPanel = createLayersPanel(); + + addItem(layersPanel); + + setWidth(500); + setHeight(500); + } + + + protected void clearItems() { + Canvas[] items = getItems(); + + if (items != null) { + for (Canvas item: items) { + removeItem(item); + } + } + } + + + protected void setUrls(Map<String, String> urls) { + this.urls.putAll(urls); + } + + protected void readUrls() { + } + + + protected Layout createInputPanel() { + setTitle(MSG.addwmsInputTitle()); + + readUrls(); + + DynamicForm form = new DynamicForm(); + final ComboBoxItem url = new ComboBoxItem("Url:"); + url.setRedrawOnChange(true); + muService.getUrls(new AsyncCallback<Map<String, String> >() { + public void onFailure(Throwable caught) { + GWT.log("Error reading WMS-Services" + caught.getMessage()); + } + public void onSuccess(Map<String, String> wms) { + urls.putAll(wms); + url.setValueMap(urls); + + } + }); + + String oldUrl = getUrl(); + if (oldUrl != null && oldUrl.length() > 0) { + url.setValue(oldUrl); + } + + ClickHandler goHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + String newUrl = url.getValue().toString(); + + if (!isUrlValid(newUrl)) { + SC.warn(MSG.addwmsInvalidURL()); + return; + } + + setUrl(newUrl); + + doCapabilitesRequest(); + } + }; + + ClickHandler cancelHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + quit(); + } + }; + + VLayout root = new VLayout(); + root.setHeight(75); + root.setMargin(10); + root.setLayoutMargin(10); + + form.setFields(url); + root.addMember(form); + root.addMember(createButtonPanel(null, goHandler, cancelHandler)); + + return root; + } + + + protected Layout createInfoPanel() { + setTitle(MSG.addwmsInfoTitle()); + + ClickHandler backHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + goToInputPanel(); + } + }; + + ClickHandler goHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + goToLayersPanel(); + } + }; + + ClickHandler cancelHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + quit(); + } + }; + + VLayout root = new VLayout(); + VLayout panel = new CapabilitiesPanel(capabilites); + + root.setLayoutMargin(10); + panel.setHeight(420); + + root.addMember(panel); + root.addMember(createButtonPanel(backHandler, goHandler, cancelHandler)); + + return root; + } + + + protected Layout createLayersPanel() { + setTitle(MSG.addwmsLayerTitle()); + + final WMSLayersTree tree = new WMSLayersTree(capabilites, srs); + + ClickHandler backHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + goToInfoPanel(); + } + }; + + ClickHandler goHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + ListGridRecord[] selection = tree.getSelectedRecords(); + + if (selection == null || selection.length == 0) { + return; + } + + List<WMSLayer> toLoad = new ArrayList<WMSLayer>(); + + for (ListGridRecord record: selection) { + toLoad.add( + ((WMSLayersTree.WMSLayerNode) record).getWMSLayer()); + + } + + finish(toLoad); + } + }; + + ClickHandler cancelHandler = new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + quit(); + } + }; + + VLayout root = new VLayout(); + + root.setLayoutMargin(10); + tree.setHeight(420); + + root.addMember(tree); + root.addMember(createButtonPanel(backHandler, goHandler, cancelHandler)); + + return root; + } + + + /** + * @param back + * @param ok + * @param cancel + * + * @return + */ + protected Layout createButtonPanel( + ClickHandler backHandler, + ClickHandler goHandler, + ClickHandler cancelHandler + ) { + Button back = new Button(MSG.addwmsBack()); + Button go = new Button(MSG.addwmsContinue()); + Button cancel = new Button(MSG.addwmsCancel()); + + if (backHandler != null) { + back.addClickHandler(backHandler); + } + else { + back.setDisabled(true); + } + + if (goHandler != null) { + go.addClickHandler(goHandler); + } + else { + go.setDisabled(true); + } + + if (cancelHandler != null) { + cancel.addClickHandler(cancelHandler); + } + else { + cancel.setDisabled(true); + } + + HLayout buttonPanel = new HLayout(); + buttonPanel.setHeight(25); + buttonPanel.setMembersMargin(15); + buttonPanel.setLayoutTopMargin(10); + buttonPanel.addMember(back); + buttonPanel.addMember(go); + buttonPanel.addMember(cancel); + + return buttonPanel; + } + + + protected boolean isUrlValid(String url) { + // TODO Improve URL validation + return !(url == null || url.length() == 0); + } + + + protected void finish(List<WMSLayer> toLoad) { + loader.load(toLoad); + + quit(); + } + + + protected void quit() { + destroy(); + } + + + protected void doCapabilitesRequest() { + gcService.query(getCapabilitiesUrl(),new AsyncCallback<Capabilities>() { + public void onFailure(Throwable e) { + SC.warn(MSG.getString(e.getMessage())); + } + + public void onSuccess(Capabilities capabilites) { + setCapabilites(capabilites); + goToInfoPanel(); + } + }); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/FloodMap.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,330 @@ +package de.intevation.flys.client.client.ui.map; + +import org.gwtopenmaps.openlayers.client.Bounds; +import org.gwtopenmaps.openlayers.client.LonLat; +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.MapOptions; +import org.gwtopenmaps.openlayers.client.MapWidget; +import org.gwtopenmaps.openlayers.client.Style; +import org.gwtopenmaps.openlayers.client.control.Attribution; +import org.gwtopenmaps.openlayers.client.control.ScaleLine; +import org.gwtopenmaps.openlayers.client.control.ScaleLineOptions; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; +import org.gwtopenmaps.openlayers.client.feature.VectorFeature; +import org.gwtopenmaps.openlayers.client.format.GeoJSON; +import org.gwtopenmaps.openlayers.client.layer.Layer; +import org.gwtopenmaps.openlayers.client.layer.Vector; +import org.gwtopenmaps.openlayers.client.layer.VectorOptions; +import org.gwtopenmaps.openlayers.client.util.Attributes; +import org.gwtopenmaps.openlayers.client.util.JObjectArray; +import org.gwtopenmaps.openlayers.client.util.JSObject; + + +public class FloodMap implements VectorFeatureAddedListener { + + public static final String LAYER_BARRIERS = "vector_layer_barriers"; + + public static final String MARK_SELECTED = "mark.selected"; + + public static final int SELECTED_STROKE_WIDTH = 2; + + protected MapWidget mapWidget; + protected Map map; + protected Vector barrierLayer; + protected String srid; + protected Bounds maxExtent; + protected ScaleLine scaleLine; + + public FloodMap(String srid, Bounds maxExtent, int width, int height) { + this.srid = srid; + this.maxExtent = maxExtent; + recreateWidget(width, height); + getBarrierLayer(); + } + + + public void recreateWidget(int width, int height) { + final MapOptions opts = new MapOptions(); + opts.setControls(new JObjectArray(new JSObject[] {})); + opts.setNumZoomLevels(16); + opts.setProjection(getRiverProjection()); + opts.setMaxExtent(maxExtent); + opts.setUnits("m"); + opts.setMaxResolution(500); // TODO DO THIS ON THE FLY + + mapWidget = new MapWidget( + Integer.toString(width - 4), + Integer.toString(height), + opts); + map = mapWidget.getMap(); + map.addControl(new Attribution()); + } + + + @Override + public void onFeatureAdded(FeatureAddedEvent evt) { + final VectorFeature feature = evt.getVectorFeature(); + + final Attributes attrs = feature.getAttributes(); + final String type = attrs.getAttributeAsString("typ"); + + if (type == null || type.length() == 0) { + return; + } + + final Style style = getStyle(type); + if (style != null) { + feature.setStyle(style); + } + + // necessary, otherwise the setStyle() has no effect + getBarrierLayer().redraw(); + } + + + /** + * Returns an OpenLayers.Style based on a given type. + * + * @param type Type can be one of "pipe1", "pipe2", "ditch", "dam", + * "ringdike". + * + * @return an OpenLayers.Style object. + */ + public static Style getStyle(String type) { + final Style style = new Style(); + + if (type == null) { + return null; + } + + if (type.equals(DrawControl.BARRIER_PIPE1) + || type.equals(DrawControl.BARRIER_PIPE1_VALUE) + ) { + style.setFillColor("#800080"); + style.setStrokeColor("#800080"); + } + else if (type.equals(DrawControl.BARRIER_PIPE2) + || type.equals(DrawControl.BARRIER_PIPE2_VALUE) + ) { + style.setFillColor("#808080"); + style.setStrokeColor("#808080"); + } + else if (type.equals(DrawControl.BARRIER_DAM) + || type.equals(DrawControl.BARRIER_DAM_VALUE) + ) { + style.setFillColor("#008000"); + style.setStrokeColor("#008000"); + } + else if (type.equals(DrawControl.BARRIER_DITCH) + || type.equals(DrawControl.BARRIER_DITCH_VALUE) + ) { + style.setFillColor("#800000"); + style.setStrokeColor("#800000"); + } + else if (type.equals(DrawControl.BARRIER_RINGDIKE) + || type.equals(DrawControl.BARRIER_RINGDIKE_VALUE) + ) { + style.setFill(false); + style.setStrokeColor("#FF8000"); + } + + return style; + } + + + public MapWidget getMapWidget() { + return mapWidget; + } + + + public Map getMap() { + return map; + } + + + public String getRiverProjection() { + return "EPSG:" + srid; + } + + + public Bounds getMaxExtent() { + return maxExtent; + } + + + public Vector getBarrierLayer() { + if (barrierLayer == null) { + final VectorOptions opts = new VectorOptions(); + opts.setProjection(getRiverProjection()); + opts.setMaxExtent(getMaxExtent()); + + barrierLayer = new Vector(LAYER_BARRIERS, opts); + barrierLayer.setIsBaseLayer(true); + + map.addLayer(barrierLayer); + map.setLayerZIndex(barrierLayer, 1000); + + barrierLayer.addVectorFeatureAddedListener(this); + } + + return barrierLayer; + } + + + public String getFeaturesAsGeoJSON() { + // disable features before exporting to GeoJSON + disableFeatures(); + + final VectorFeature[] features = barrierLayer.getFeatures(); + + if (features == null || features.length == 0) { + return null; + } + + return new GeoJSON().write(features); + } + + + public void setSize(String width, String height) { + mapWidget.setWidth(width); + mapWidget.setHeight(height); + final int currentZoom = map.getZoom(); + final LonLat currentCenter = map.getCenter(); + map.updateSize(); + map.zoomTo(currentZoom); + map.setCenter(currentCenter); + } + + + public void addLayer(Layer layer) { + if (layer != null) { + map.addLayer(layer); + + final int index = map.getLayerIndex(layer); + final int newIndex = index * (-1) + 1; + + map.raiseLayer(layer, newIndex); + + update(); + } + } + + + public void hideBarrierLayer () { + if (getBarrierLayer() != null) { + barrierLayer.setIsVisible(false); + } + } + + public void showBarrierLayer () { + if (getBarrierLayer() != null) { + barrierLayer.setIsVisible(true); + } + } + + + public void selectFeature(VectorFeature feature) { + if (feature != null) { + selectFeatures(new VectorFeature[] { feature } ); + } + } + + + public void selectFeatures(VectorFeature[] features) { + if (features == null || features.length == 0) { + return; + } + + for (final VectorFeature feature: features) { + final Attributes attr = feature.getAttributes(); + + if (attr.getAttributeAsInt(MARK_SELECTED) == 1) { + continue; + } + + attr.setAttribute(MARK_SELECTED, 1); + + final Style style = feature.getStyle(); + final double strokeWidth = style.getStrokeWidth(); + + style.setStrokeWidth(strokeWidth+SELECTED_STROKE_WIDTH); + } + + getBarrierLayer().redraw(); + } + + + public void disableFeatures() { + final Vector barriers = getBarrierLayer(); + final VectorFeature[] features = barriers.getFeatures(); + + if (features == null || features.length == 0) { + return; + } + + disableFeatures(features); + } + + + public void disableFeature(VectorFeature feature) { + if (feature != null) { + disableFeatures(new VectorFeature[] { feature }); + } + } + + + public void disableFeatures(VectorFeature[] features) { + if (features == null || features.length == 0) { + return; + } + + for (final VectorFeature feature: features) { + final Attributes attr = feature.getAttributes(); + + if (attr.getAttributeAsInt(MARK_SELECTED) == 0) { + continue; + } + + attr.setAttribute(FloodMap.MARK_SELECTED, 0); + + final Style style = feature.getStyle(); + final double strokeWidth = style.getStrokeWidth(); + + style.setStrokeWidth(strokeWidth-SELECTED_STROKE_WIDTH); + } + + getBarrierLayer().redraw(); + } + + + public void update() { + final Layer[] layers = map.getLayers(); + + for (final Layer l: layers) { + l.redraw(); + } + } + + + public void updateSize() { + this.map.updateSize(); + } + + + public void activateScaleLine(boolean activate) { + if (activate) { + final ScaleLineOptions slOpts = new ScaleLineOptions(); + slOpts.setBottomInUnits("m"); + slOpts.setBottomOutUnits("km"); + slOpts.setTopInUnits(""); + slOpts.setTopOutUnits(""); + + scaleLine = new ScaleLine(slOpts); + this.map.addControl(scaleLine); + } + else if (!activate && scaleLine != null){ + this.map.removeControl(scaleLine); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/GetFeatureInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,125 @@ +package de.intevation.flys.client.client.ui.map; + +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.LonLat; +import org.gwtopenmaps.openlayers.client.Pixel; +import org.gwtopenmaps.openlayers.client.event.MapClickListener; + +import de.intevation.flys.client.shared.model.FeatureInfo; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.GFIService; +import de.intevation.flys.client.client.services.GFIServiceAsync; +import de.intevation.flys.client.shared.model.FacetRecord; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.AttributedTheme; +import de.intevation.flys.client.shared.model.FeatureInfoResponse; +import de.intevation.flys.client.client.ui.ThemePanel; + + +public class GetFeatureInfo implements MapClickListener { + + protected GFIServiceAsync gfiService = GWT.create(GFIService.class); + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected GetFeatureInfoWindow gfiWindow; + + protected Map map; + protected ThemePanel themePanel; + protected String infoFormat; + + + /** + * @param map + * @param themes + * @param url + * @param infoFormat + */ + public GetFeatureInfo(Map map, ThemePanel themePanel, String infoFormat) { + this.map = map; + this.themePanel = themePanel; + this.infoFormat = infoFormat; + } + + + public void activate(boolean activate) { + if (activate) { + map.addMapClickListener(this); + } + else { + map.removeListener(this); + } + } + + + protected void newGetFeatureInfoWindow(List<FeatureInfo> features, String title) { + if (gfiWindow != null) { + gfiWindow.destroy(); + } + + gfiWindow = new GetFeatureInfoWindow(features, title); + gfiWindow.show(); + } + + protected void newGetFeatureInfoWindow(String response, String title) { + if (gfiWindow != null) { + gfiWindow.destroy(); + } + + gfiWindow = new GetFeatureInfoWindow(response, title); + gfiWindow.show(); + } + + @Override + public void onClick(MapClickListener.MapClickEvent e) { + LonLat lonlat = e.getLonLat(); + Pixel pixel = map.getPixelFromLonLat(lonlat); + + if (themePanel.getSelectedRecords().length == 0) { + SC.say(MSG.requireTheme()); + } + + for (ListGridRecord rec : themePanel.getSelectedRecords()) { + Theme act_theme = ((FacetRecord)rec).getTheme(); + final AttributedTheme at = (AttributedTheme)act_theme; + gfiService.query( + act_theme, + infoFormat, + map.getExtent().toString(), + map.getProjection(), + (int) map.getSize().getHeight(), + (int) map.getSize().getWidth(), + pixel.x(), pixel.y(), + new AsyncCallback<FeatureInfoResponse>() { + @Override + public void onFailure(Throwable e) { + SC.warn(MSG.getString(e.getMessage())); + } + + @Override + public void onSuccess(FeatureInfoResponse response) { + List<FeatureInfo> features = response.getFeatures(); + if (features != null && !features.isEmpty()) { + newGetFeatureInfoWindow(features, at.getAttr("description")); + } else if (response.getFeatureInfoHTML() != null) { + newGetFeatureInfoWindow(response.getFeatureInfoHTML(), + at.getAttr("description")); + } else { + GWT.log("GetFeatureInfo returned neither a list of features nor a string"); + } + } + } + ); + break; // More intelligent handling when more then one is selected + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/GetFeatureInfoWindow.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,153 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.HTMLPane; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.viewer.DetailViewer; +import com.smartgwt.client.widgets.viewer.DetailViewerField; +import com.smartgwt.client.widgets.viewer.DetailViewerRecord; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.FeatureInfo; +import de.intevation.flys.client.shared.model.FeatureInfoResponse; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.MissingResourceException; + +import org.gwtopenmaps.openlayers.client.feature.VectorFeature; +import org.gwtopenmaps.openlayers.client.util.Attributes; +import org.gwtopenmaps.openlayers.client.util.JSObject; + + +public class GetFeatureInfoWindow extends Window { + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected List<FeatureInfo> features; + + protected String title; + + protected String featureInfoHTML; + + + public static final int ROW_HEIGHT = 25; + + + public GetFeatureInfoWindow(List<FeatureInfo> features, String title) { + super(); + this.features = features; + this.title = title; + + initLayout(); + } + + public GetFeatureInfoWindow(String featureInfoHTML, String title) { + super(); + features = null; + this.title = title; + this.featureInfoHTML = featureInfoHTML; + + initLayoutHTML(); + } + + protected void initLayoutHTML() { + HTMLPane pane = new HTMLPane(); + pane.setContents(featureInfoHTML); + addItem(pane); + setWidth(500); + setHeight(300); + + setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); + + setIsModal(false); +// setShowModalMask(true); + + centerInPage(); + } + + protected void initLayout() { + VLayout root = new VLayout(); + + for (FeatureInfo feature: features) { + // Currently this should alway be only one + root.addMember(createFeatureViewer(feature)); + setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); + } + + addItem(root); + + setWidth(500); + setHeight(300); + + setIsModal(false); +// setShowModalMask(true); + + centerInPage(); + } + + + protected DetailViewer createFeatureViewer(FeatureInfo feature) { + DetailViewer detailViewer = new DetailViewer(); + detailViewer.setWidth(487); + + Map<String, String> attrs = feature.getAttrs(); + Set<Map.Entry<String, String>> entries = attrs.entrySet(); + List <DetailViewerField> fields = new ArrayList<DetailViewerField>(); + DetailViewerRecord dr = new DetailViewerRecord(); + + DetailViewerField path_field = null; // Make sure path is always the last element + + for (Map.Entry<String, String> entry: entries) { + String localized; + try { + localized = MSG.getString(entry.getKey()); + } catch (MissingResourceException mre) { + localized = entry.getKey(); +// We filter unwanted information by localization +// Uncomment to filter out unlocalized elements +// continue; + } + if (entry.getKey().equals("PATH")) { + path_field = new DetailViewerField(entry.getKey(), localized); + } else { + fields.add(new DetailViewerField(entry.getKey(), localized)); + } + dr.setAttribute(entry.getKey(), entry.getValue()); + } + if (path_field != null) + fields.add(path_field); + + DetailViewerField[] fieldArray = new DetailViewerField[fields.size()]; + detailViewer.setFields(fields.toArray(fieldArray)); + detailViewer.setData(new DetailViewerRecord[]{dr}); + detailViewer.setCanSelectText(true); + + return detailViewer; + } + + + protected String[][] extractProperties(VectorFeature feature) { + Attributes tmp = feature.getAttributes(); + JSObject jsobj = tmp.getJSObject(); + + String tmpNames = jsobj.getPropertyNames(); + String[] allNames = tmpNames.split(","); + + String[][] attr = new String[allNames.length][]; + + for (int i = 0, n = attr.length; i < n; i++) { + attr[i] = new String[] { + allNames[i], + jsobj.getPropertyAsString(allNames[i]) }; + } + + return attr; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,100 @@ +package de.intevation.flys.client.client.ui.map; + +import java.util.List; + +import com.smartgwt.client.types.ImageStyle; +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.MapUtils; +import de.intevation.flys.client.shared.model.AttributedTheme; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; + + +public class LegendWindow extends Window { + + private ThemeList themeList; + + private VLayout legendContainer; + + public LegendWindow(ThemeList themeList) { + this.themeList = themeList; + this.legendContainer = new VLayout(); + + init(); + } + + public void update(ThemeList themeList) { + this.themeList = themeList; + + Canvas[] legends = legendContainer.getMembers(); + legendContainer.removeMembers(legends); + + addLegends(); + } + + private void addLegends() { + List<Theme> themes = themeList.getActiveThemes(); + + for (Theme theme : themes) { + if (theme.getActive() == 0) { + continue; + } + + if (theme instanceof AttributedTheme) { + legendContainer + .addMember(createLegendGraphicsRow((AttributedTheme) theme)); + } + } + } + + private Canvas createLegendGraphicsRow(AttributedTheme at) { + Label label = new Label(at.getDescription()); + Img img = createLegendGraphics(at); + + HLayout row = new HLayout(); + row.addMember(label); + row.addMember(img); + + row.setHeight(150); + row.setWidth(400); + + return row; + } + + private Img createLegendGraphics(AttributedTheme at) { + String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), + at.getAttr("layers")); + + Img img = new Img(imgUrl); + img.setImageType(ImageStyle.CENTER); + img.setAutoFit(true); + + return img; + } + + private void init() { + legendContainer.setAutoHeight(); + legendContainer.setLayoutAlign(VerticalAlignment.TOP); + legendContainer.setAlign(VerticalAlignment.CENTER); + + setTitle("WMS Legend"); + setAutoSize(true); + setCanDragResize(true); + setIsModal(false); + setShowModalMask(false); + setLayoutAlign(VerticalAlignment.TOP); + setAlign(VerticalAlignment.TOP); + + addItem(legendContainer); + addLegends(); + + centerInPage(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapOutputTab.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,636 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.AbsolutePanel; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.events.ParentMovedEvent; +import com.smartgwt.client.widgets.events.ParentMovedHandler; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; +import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.event.OutputParameterChangeEvent; +import de.intevation.flys.client.client.event.OutputParameterChangeHandler; +import de.intevation.flys.client.client.event.RedrawRequestEvent; +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.client.services.MapOutputService; +import de.intevation.flys.client.client.services.MapOutputServiceAsync; +import de.intevation.flys.client.client.services.StepForwardService; +import de.intevation.flys.client.client.services.StepForwardServiceAsync; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; +import de.intevation.flys.client.client.ui.ThemePanel; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.AttributedTheme; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.MapConfig; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; +import de.intevation.flys.client.shared.model.WMSLayer; + +import java.util.HashMap; +import java.util.List; + +import org.gwtopenmaps.openlayers.client.Bounds; +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.MapWidget; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener; +import org.gwtopenmaps.openlayers.client.feature.VectorFeature; +import org.gwtopenmaps.openlayers.client.format.GeoJSON; +import org.gwtopenmaps.openlayers.client.layer.Layer; +import org.gwtopenmaps.openlayers.client.layer.TransitionEffect; +import org.gwtopenmaps.openlayers.client.layer.Vector; +import org.gwtopenmaps.openlayers.client.layer.WMS; +import org.gwtopenmaps.openlayers.client.layer.WMSOptions; +import org.gwtopenmaps.openlayers.client.layer.WMSParams; + + +public class MapOutputTab +extends OutputTab +implements RedrawRequestHandler, ExternalWMSWindow.LayerLoader, TabSelectedHandler, OutputParameterChangeHandler { + + public static final String DEFAULT_SRID = "4326"; + + public static final String BARRIERS_PARAMETER_KEY = "uesk.barriers"; + + public static final String WSPLGEN_FACET = "floodmap.wsplgen"; + + public static final String EXTERNAL_WMS_FACTORY = "externalwmsfactory"; + + + protected StepForwardServiceAsync feedService = + GWT.create(StepForwardService.class); + + protected MapOutputServiceAsync mapService = + GWT.create(MapOutputService.class); + + /** Service handle to clone and add artifacts to collection. */ + protected LoadArtifactServiceAsync loadArtifactService = + GWT.create(LoadArtifactService.class); + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected MapToolbar controlPanel; + protected ThemePanel themePanel; + protected Canvas themePanelCanvas; + protected MapWidget mapPanel; + protected Canvas mapPanelCanvas; + protected VLayout rootLayout = new VLayout(); + protected AbsolutePanel absPan = new AbsolutePanel(); + protected FloodMap floodMap; + protected java.util.Map<String, String> wmsUrls = new HashMap<String, String>(); + + + public MapOutputTab( + String title, + Collection collection, + OutputMode mode, + CollectionView collectionView + ){ + super(title, collection, collectionView, mode); + + collectionView.registerTabHandler(this); + + mapService.doOut(collection, new AsyncCallback<MapConfig>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("MAP ERROR: " + caught.getMessage()); + } + + @Override + public void onSuccess(MapConfig c) { + GWT.log("MAP SUCCESS!"); + + Bounds max = boundsFromString(c.getMaxExtent()); + Bounds initial = boundsFromString(c.getInitialExtent()); + + if (initial == null) { + GWT.log("Warning: No initial extent set."); + initial = max; + } + + setFloodmap(new FloodMap(c.getSrid(), max, 640, 480)); + + initLayout(); + initBarriers(); + + GWT.log("MAX EXTENT: " + max); + GWT.log("ZOOM TO: " + initial); + getMap().zoomToExtent(initial); + } + } + ); + } + + + protected void initLayout() { + rootLayout.setHeight100(); + rootLayout.setWidth100(); + rootLayout.setMembersMargin(2); + + HLayout hlayout = new HLayout(); + hlayout.setMembersMargin(0); + + this.themePanelCanvas = createThemePanel(); + + controlPanel = createControlPanel(); + mapPanel = floodMap.getMapWidget(); + + rootLayout.addMember(controlPanel); + rootLayout.addMember(absPan); + absPan.setWidth("100%"); + absPan.setHeight("100%"); + absPan.add(themePanelCanvas); + absPan.add(mapPanel); + + rootLayout.addResizedHandler(new ResizedHandler() { + @Override + public void onResized(ResizedEvent e) { + doLayout(); + } + }); + + rootLayout.addParentMovedHandler(new ParentMovedHandler() { + @Override + public void onParentMoved(ParentMovedEvent event) { + mapPanel.getMap().updateSize(); + } + }); + + setPane(rootLayout); + } + + + protected void doLayout() { + if(!rootLayout.isVisible()) { + return; + } + + // Manually set the height of the AbsolutePanel, somehow this is necessary + absPan.setHeight(String.valueOf( + rootLayout.getHeight() - controlPanel.getHeight() - 2) + "px"); + + // Calculate bounds of Map + int height = rootLayout.getHeight() - + controlPanel.getHeight() - 6; + int width = controlPanel.getWidth() - + (themePanelCanvas.isVisible() ? themePanelCanvas.getWidth() + 4 : 2); + + // Set size and position of Map + String w = String.valueOf(width) + "px"; + String h = String.valueOf(height) + "px"; + GWT.log("width=" + w); + + mapPanel.setSize(w, h); + mapPanel.getMap().updateSize(); + if(themePanelCanvas.isVisible()) { + absPan.setWidgetPosition(mapPanel, themePanelCanvas.getWidth() + 2, 0); + } + else { + absPan.setWidgetPosition(mapPanel, 0, 0); + } + + // Set bounds of ThemePanelCanvas + themePanelCanvas.setSize(themePanelCanvas.getWidthAsString(), String.valueOf(height + 2) + "px"); + } + + + protected void initBarriers() { + Vector vector = floodMap.getBarrierLayer(); + vector.addVectorFeatureAddedListener( + new VectorFeatureAddedListener() { + @Override + public void onFeatureAdded(FeatureAddedEvent e) { + saveBarriers(); + } + } + ); + + vector.addVectorFeatureRemovedListener( + new VectorFeatureRemovedListener() { + @Override + public void onFeatureRemoved(FeatureRemovedEvent e) { + saveBarriers(); + } + } + ); + + + Artifact artifact = getArtifact(); + + if (artifact == null) { + return; + } + + ArtifactDescription desc = artifact.getArtifactDescription(); + + String geojson = getGeoJSONFromStatic(desc); + geojson = geojson != null ? geojson : getGeoJSONFromDynamic(desc); + + if (geojson == null || geojson.length() == 0) { + GWT.log("No geojson string found -> no barriers existing."); + return; + } + + GeoJSON reader = new GeoJSON(); + VectorFeature[] features = reader.read(geojson); + + vector.addFeatures(features); + } + + + public void addLayer(Layer layer) { + FloodMap map = getFloodmap(); + + if (map != null) { + GWT.log("Add new layer '" + layer.getName() + "' to map."); + map.addLayer(layer); + if (layer instanceof WMS) { + wmsUrls.put(layer.getName(), + ((WMS)layer).getFullRequestString(new WMSParams(), null)); + } + } + } + + + public void removeLayer(String name) { + Map map = getMap(); + + Layer[] layers = map.getLayers(); + + for (Layer layer: layers) { + if (name.equals(layer.getName())) { + map.removeLayer(layer); + } + } + } + + + @Override + public void onRedrawRequest(RedrawRequestEvent event) { + mapService.doOut(collection, new AsyncCallback<MapConfig>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("MAP ERROR: " + caught.getMessage()); + } + + @Override + public void onSuccess(MapConfig c) { + GWT.log("We want to refresh the map now!"); + themePanel.updateCollection(); + getFloodmap().update(); + } + }); + } + + + @Override + public void load(List<WMSLayer> toLoad) { + GWT.log("The user wants to add " + toLoad.size() + " new WMS layers."); + + int len = toLoad.size(); + + Recommendation[] recom = new Recommendation[len]; + + for (int i = 0; i < len; i++) { + WMSLayer w = toLoad.get(i); + + String ids = w.getServer() + ";" + w.getName() + ";" + w.getTitle(); + recom[i] = new Recommendation(EXTERNAL_WMS_FACTORY, ids); + } + + Collection c = getCollection(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + loadArtifactService.loadMany(c, recom, EXTERNAL_WMS_FACTORY, locale, + new AsyncCallback<Artifact[]>() { + + @Override + public void onFailure(Throwable throwable) { + SC.warn(MSG.getString(throwable.getMessage())); + } + + @Override + public void onSuccess(Artifact[] newArtifacts) { + getThemePanel().updateCollection(); + } + } + ); + } + + + protected void setFloodmap(FloodMap floodMap) { + this.floodMap = floodMap; + } + + + protected FloodMap getFloodmap() { + return floodMap; + } + + + protected Map getMap() { + return floodMap.getMap(); + } + + + protected ThemePanel getThemePanel() { + return themePanel; + } + + + protected String getGeoJSONFromDynamic(ArtifactDescription desc) { + DataList list = desc.getCurrentData(); + + if (list == null) { + return null; + } + + List<Data> datas = list.getAll(); + for (Data data: datas) { + String key = data.getLabel(); + + if (key != null && key.equals(BARRIERS_PARAMETER_KEY)) { + DataItem def = data.getDefault(); + + if (def != null) { + return def.getStringValue(); + } + } + } + + return null; + } + + + protected String getGeoJSONFromStatic(ArtifactDescription desc) { + // TODO Implement this method, if there are reachable states right after + // the floodmap state - which is currently not the case. + return null; + } + + + public ThemeList getThemeList() { + return collection.getThemeList(mode.getName()); + } + + + public String getSrid() { + ThemeList themeList = getThemeList(); + + int num = themeList.getThemeCount(); + + for (int i = 1; i <= num; i++) { + AttributedTheme theme = (AttributedTheme) themeList.getThemeAt(i); + + if (theme == null) { + continue; + } + + String srid = theme.getAttr("srid"); + + if (srid != null && srid.length() > 0) { + return srid; + } + } + + return DEFAULT_SRID; + } + + + protected Bounds boundsFromString(String bounds) { + GWT.log("Create Bounds from String: '" + bounds + "'"); + if (bounds == null || bounds.length() == 0) { + return null; + } + + String[] values = bounds.split(" "); + + if (values == null || values.length < 4) { + return null; + } + + try { + return new Bounds( + Double.valueOf(values[0]), + Double.valueOf(values[1]), + Double.valueOf(values[2]), + Double.valueOf(values[3])); + } + catch (NumberFormatException nfe) {} + + return null; + } + + + public Layer createWMSLayer(Theme theme) { + if (!(theme instanceof AttributedTheme)) { + return null; + } + + AttributedTheme at = (AttributedTheme) theme; + + String name = at.getAttr("name"); + String desc = at.getAttr("description"); + String url = at.getAttr("url"); + String layers = at.getAttr("layers"); + + if (url == null || layers == null) { + return null; + } + + WMSParams params = new WMSParams(); + params.setLayers(layers); + params.setFormat("image/png"); + params.setIsTransparent(true); + + WMSOptions opts = new WMSOptions(); + opts.setProjection("EPSG:" + getSrid()); + opts.setSingleTile(true); + opts.setRatio(1); + if (layers.equals("OSM-WMS-Dienst")) { + opts.setAttribution(MSG.attribution()); + opts.setSingleTile(true); + opts.setTransitionEffect(TransitionEffect.RESIZE); + } + WMS wms = new WMS(layers, url, params, opts); + wms.setIsVisible(at.getActive() == 1); + wms.setIsBaseLayer(false); + // We can't set the full_url attribute here because map is not set + // at.addAttr("full_url", wms.getFullRequestString(params, null)); + return wms; + } + + + public java.util.Map<String, String> wmsUrls() { + return this.wmsUrls; + } + + + protected MapToolbar createControlPanel() { + return new MapToolbar(this, floodMap, false); + } + + + protected Canvas createThemePanel() { + Canvas c = new Canvas(); + c.setMinWidth(300); + c.setWidth(200); + c.setHeight100(); + c.setCanDragResize(true); + c.setBorder("1px solid black"); + + themePanel = new MapThemePanel( + this.getCollectionView(), + mode, + this, + new MapThemePanel.ActivateCallback() { + @Override + public void activate(Theme theme, boolean active) { + fireActivateTheme(theme, active); + } + }, + new MapThemePanel.ThemeMovedCallback() { + @Override + public void onThemeMoved(Theme theme, int oldIdx, int newIdx) { + // this code synchronizes the ThemePanel and the OpenLayers + // internal order of layers. + AttributedTheme at = (AttributedTheme) theme; + + String name = at.getAttr("layers"); + Map map = getMap(); + Layer[] layers = map.getLayersByName(name); + + if (layers == null || layers.length == 0) { + GWT.log("Error: Cannot find layer '" + name + "'"); + return; + } + + map.raiseLayer(layers[0], (newIdx-oldIdx)*-1); + map.zoomTo(map.getZoom()-1); + map.zoomTo(map.getZoom()+1); + } + }, + new MapThemePanel.LayerZoomCallback() { + @Override + public void onLayerZoom(Theme theme, String extent) { + Bounds zoomTo = boundsFromString(extent); + + if (zoomTo == null) { + GWT.log("WARNING: No valid bounds for zooming found!"); + return; + } + + getMap().zoomToExtent(zoomTo); + } + } + ); + themePanel.addRedrawRequestHandler(this); + themePanel.addOutputParameterChangeHandler(this); + c.addChild(themePanel); + + return c; + } + + + private void fireActivateTheme(Theme theme, boolean active) { + activateTheme(theme, active); + } + + + protected void activateTheme(Theme theme, boolean active) { + AttributedTheme at = (AttributedTheme) theme; + + String name = at.getAttr("layers"); + Layer layer = floodMap.getMap().getLayerByName(name); + + GWT.log("Set visibility of '" + name + "': " + active); + + if (layer != null) { + layer.setIsVisible(active); + } + } + + + protected void saveBarriers() { + Vector layer = floodMap.getBarrierLayer(); + + GeoJSON format = new GeoJSON(); + String features = format.write(layer.getFeatures()); + + DataItem item = new DefaultDataItem( + BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, features); + + Data data = new DefaultData( + BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, "String", + new DataItem[] {item} ); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + feedService.go(locale, getArtifact(), new Data[] { data }, + new AsyncCallback<Artifact>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not save barrier geometries: " + + caught.getMessage()); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully saved barrier geometries."); + } + } + ); + } + + + @Override + public void onTabSelected(TabSelectedEvent tse) { + if(floodMap == null) { + return; + } + if(this.equals(tse.getTab())) { + floodMap.activateScaleLine(true); + } + else { + controlPanel.activateMeasureControl(false); + floodMap.activateScaleLine(false); + } + } + + public void toogleThemePanel() { + this.themePanelCanvas.setVisible(!themePanelCanvas.isVisible()); + + // Trigger resize event handler + doLayout(); + } + + + @Override + public void onOutputParameterChanged(OutputParameterChangeEvent evt) { + GWT.log("OutputParameterChanged"); + controlPanel.updateThemes(getThemePanel().getThemeList()); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,78 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.AbsolutePanel; + +import de.intevation.flys.client.shared.model.BBox; +import de.intevation.flys.client.shared.model.MapInfo; + +import org.gwtopenmaps.openlayers.client.Bounds; +import org.gwtopenmaps.openlayers.client.MapWidget; + +/** + * Panel that contains a MapWidget and a MapToolbar. + * This panel is used by the flood map calculation input helper. + */ +public class MapPanel extends AbsolutePanel { + + protected MapToolbar toolbar; + + protected FloodMap floodMap; + protected MapWidget floodMapWidget; + protected boolean digitizeEnabled; + + public MapPanel(MapInfo mapInfo, boolean digitizeEnabled) { + BBox bbox = mapInfo.getBBox(); + + this.digitizeEnabled = digitizeEnabled; + this.floodMap = new FloodMap( + String.valueOf(mapInfo.getSrid()), + new Bounds( + bbox.getLowerX(), + bbox.getLowerY(), + bbox.getUpperX(), + bbox.getUpperY()), + 640, 480); + + initLayout(); + } + + + private void initLayout() { + setWidth("100%"); + setHeight("100%"); + + floodMapWidget = floodMap.getMapWidget(); + toolbar = new MapToolbar(floodMap, digitizeEnabled); + + add(toolbar); + add(floodMapWidget); + } + + public void doLayout(int w, int h) { + int width = w; + int height = h; + GWT.log("MapPanel.size: " + width + "x" + height); + + width -= 2; // minus black borders + height -= toolbar.getHeight() + 4; + + if (width < 0 || height < 0) { + GWT.log("MapPanel: Oops what a size!"); + return; + } + + floodMapWidget.setSize(Integer.toString(width), Integer.toString(height)); + floodMapWidget.getMap().updateSize(); + } + + + public FloodMap getFloodMap() { + return floodMap; + } + + public MapToolbar getMapToolbar () { + return toolbar; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapPositionPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,77 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; + +import org.gwtopenmaps.openlayers.client.LonLat; +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.MapWidget; +import org.gwtopenmaps.openlayers.client.Pixel; +import org.gwtopenmaps.openlayers.client.event.EventHandler; +import org.gwtopenmaps.openlayers.client.event.EventObject; +import org.gwtopenmaps.openlayers.client.util.JSObject; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MapPositionPanel extends HLayout { + + protected MapWidget mapWidget; + protected final Map map; + + protected Label x; + protected Label y; + + + public MapPositionPanel(MapWidget mapWidget) { + this.mapWidget = mapWidget; + this.map = mapWidget.getMap(); + + this.x = new Label(); + this.y = new Label(); + Label d = new Label("|"); + + setAlign(Alignment.RIGHT); + setMembersMargin(2); + + setWidth(150); + x.setWidth(25); + y.setWidth(25); + d.setWidth(5); + + addMember(x); + addMember(d); + addMember(y); + + // TODO This is not an optimal way to get the mouse position but makes + // the wrapper canvas superfluous. + this.map.getEvents().register("mousemove", map, new EventHandler() { + + @Override + public void onHandle(EventObject eventObject) { + JSObject xy = eventObject.getJSObject().getProperty("xy"); + Pixel px = Pixel.narrowToPixel(xy); + LonLat lonlat = map.getLonLatFromPixel(px); + + setX(lonlat.lon()); + setY(lonlat.lat()); + } + }); + } + + + protected void setX(double x) { + NumberFormat f = NumberFormat.getFormat("#0.0000"); + this.x.setContents(f.format(x).toString()); + } + + + protected void setY(double y) { + NumberFormat f = NumberFormat.getFormat("#0.0000"); + this.y.setContents(f.format(y).toString()); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapPrintPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,356 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.Window; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.ButtonItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; +import com.smartgwt.client.types.Alignment; + +import org.gwtopenmaps.openlayers.client.Bounds; +import org.gwtopenmaps.openlayers.client.Map; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.CollectionAttributeService; +import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.OutputSettings; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertySetting; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; + + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.MissingResourceException; + +public class MapPrintPanel extends Canvas { + + private static final String MAPFISH_MAPTITLE = "mapfish_mapTitle"; + private static final String MAPFISH_RANGE = "mapfish_data_range"; + private static final String MAPFISH_SUBTITLE = "mapfish_data_subtitle"; + private static final String MAPFISH_STRETCH = "mapfish_data_strech"; + private static final String MAPFISH_INSTITUTION = "mapfish_data_institution"; + private static final String MAPFISH_SOURCE = "mapfish_data_source"; + private static final String MAPFISH_CREATOR = "mapfish_data_creator"; + private static final String MAPFISH_DATEPLACE = "mapfish_data_dateplace"; + private static final String MAPFISH_RIVER = "mapfish_data_river"; + private static final String MAPFISH_LOGO = "mapfish_logo"; + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** CollectionAttribute Update Service. */ + protected CollectionAttributeServiceAsync updater = + GWT.create(CollectionAttributeService.class); + + + protected Collection collection; + protected Settings settings; + protected TextItem pageTitle = new TextItem(); + protected TextItem pageRange = new TextItem(); + protected TextItem pageSubtitle = new TextItem(); + protected TextItem pageStretch = new TextItem(); + protected TextItem pageInstitution = new TextItem(); + protected TextItem pageSource = new TextItem(); + protected TextItem pageCreator = new TextItem(); + protected TextItem pageDatePlace = new TextItem(); + protected SelectItem pageLogo = createPageLogoSelectItem(); +// protected SelectItem pageFormat = createPageFormatSelectItem(); + protected MapToolbar mapToolbar; + protected MapPrintWindow parent; + + public MapPrintPanel(Collection collection, MapToolbar mapToolbar, MapPrintWindow parent) { + this.collection = collection; + this.mapToolbar = mapToolbar; + this.parent = parent; + initLayout(); + + this.settings = collection.getSettings("print-settings"); + if (settings == null) { + settings = new OutputSettings(); + GWT.log("settings are empty"); + } + else { + List<Property> properties = settings.getSettings("default"); + for (Property prop : properties) { + PropertySetting props = (PropertySetting)prop; + GWT.log(props.getName() + "=" + props.getValue()); + if (props.getName().equals(MAPFISH_MAPTITLE)) { + this.pageTitle.setValue(props.getValue()); + } + else if (props.getName().equals(MAPFISH_RANGE)) { + this.pageRange.setValue(props.getValue()); + } + else if (props.getName().equals(MAPFISH_SUBTITLE)) { + this.pageSubtitle.setValue(props.getValue()); + } + else if (props.getName().equals(MAPFISH_STRETCH)) { + this.pageStretch.setValue(props.getValue()); + } + else if (props.getName().equals(MAPFISH_INSTITUTION)) { + this.pageInstitution.setValue(props.getValue()); + } + else if (props.getName().equals(MAPFISH_SOURCE)) { + this.pageSource.setValue(props.getValue()); + } + else if (props.getName().equals(MAPFISH_CREATOR)) { + this.pageCreator.setValue(props.getValue()); + } + else if (props.getName().equals(MAPFISH_DATEPLACE)) { + this.pageDatePlace.setValue(props.getValue()); + } else { + GWT.log("Unknown Print property: " + prop.getName()); + } + } + } + } + + protected void initLayout() { + // TODO: i18n + this.pageTitle.setTitle(MSG.mapTitle()); + this.pageSubtitle.setTitle(MSG.mapSubtitle()); + this.pageRange.setTitle(MSG.mapRange()); + this.pageStretch.setTitle(MSG.mapStretch()); + this.pageInstitution.setTitle(MSG.mapInstitution()); + this.pageSource.setTitle(MSG.mapSource()); + this.pageCreator.setTitle(MSG.mapCreator()); + this.pageDatePlace.setTitle(MSG.mapDate()); + + pageTitle.setLength(30); + pageSubtitle.setLength(30); + pageRange.setLength(30); + pageStretch.setLength(30); + pageInstitution.setLength(30); + pageSource.setLength(30); + pageCreator.setLength(30); + pageDatePlace.setLength(30); + ButtonItem printButton = createPrintButtonItem(); + + printButton.setAlign(Alignment.RIGHT); + + DynamicForm df = new DynamicForm(); + df.setFields( +// this.pageFormat, + this.pageTitle, + this.pageSubtitle, + this.pageRange, + this.pageStretch, + this.pageInstitution, + this.pageSource, + this.pageCreator, + this.pageDatePlace, + this.pageLogo, + printButton); + addChild(df); + } + + protected SelectItem createPageLogoSelectItem() { + LinkedHashMap values = new LinkedHashMap(); + // TODO: this should be configurable + values.put(MSG.bfgLogo(), "BfG Logo"); + + SelectItem selItem = new SelectItem(); + selItem.setTitle(MSG.mapLogo()); + selItem.setValueMap(values); + selItem.setDefaultToFirstOption(true); + + return selItem; + } + +/* + * Commented out because we only provide a layout for A4 Landscape atm + + protected SelectItem createPageFormatSelectItem() { + LinkedHashMap values = new LinkedHashMap(); + // TODO: i18n + values.put("A4 landscape", "DIN A4 (Querformat)"); + //values.put("A4 portrait", "DIN A4 (Hochformat)"); + //values.put("A0 portrait", "DIN A0 (Hochformat)"); + + SelectItem selItem = new SelectItem(); + selItem.setTitle("Seitengröße:"); // TODO: i18n + selItem.setValueMap(values); + selItem.setDefaultToFirstOption(true); + + return selItem; + } +*/ + protected ButtonItem createPrintButtonItem() { + ButtonItem btn = new ButtonItem(); + btn.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + updateCollection(); + Window.open(createPrintUrl(), "_blank", ""); + parent.destroy(); + } + }); + btn.setTitle(MSG.print()); + return btn; + } + + private String createPrintUrl() { + MapOutputTab ot = (MapOutputTab)mapToolbar.getOutputTab(); + Collection collection = ot.getCollection(); + String uuid = collection.identifier(); + + String mapType = collection.getOutputModes().containsKey("floodmap") + ? "floodmap" + : "map"; + + StringBuilder url = new StringBuilder(); + url.append(GWT.getModuleBaseURL()); + url.append("map-print?"); + + Map map = mapToolbar.getMap(); + Bounds bounds = map.getExtent(); + + if (bounds != null) { + try { + url.append("minx="); + url.append(bounds.getLowerLeftX()); + url.append("&"); + + url.append("maxx="); + url.append(bounds.getUpperRightX()); + url.append("&"); + + url.append("miny="); + url.append(bounds.getLowerLeftY()); + url.append("&"); + + url.append("maxy="); + url.append(bounds.getUpperRightY()); + url.append("&"); + } + catch (Exception e) { + // XXX: Ignore it. bounds.getXXX() throw + // exceptions when bound is invalid. :-/ + } + } + + url.append("uuid="); + url.append(uuid); + url.append("&maptype="); + url.append(mapType); + + appendPrintToUrl(collection, url); + + return url.toString(); + } + + private void appendPrintToUrl(Collection collection, StringBuilder url) { + Settings settings = collection.getSettings("print-settings"); + if (settings != null) { + List<Property> properties = settings.getSettings("default"); + for (Property prop : properties) { + PropertySetting props = (PropertySetting)prop; + url.append("&"); + String localized; + try { + localized = MSG.getString(props.getName()); + } + catch (MissingResourceException mre) { + localized = props.getName(); + } + url.append(toJavaEncodedString(localized)); + url.append("="); + url.append(props.getValue()); + } + } + // O.o + String river = findRiver(((MapOutputTab)mapToolbar.getOutputTab() + ).getCollectionView().getArtifact()); + url.append("&" + toJavaEncodedString(MSG.getString(MAPFISH_RIVER)) + "=" + river); + } + + // Copy of DatacageWindow's findRiver + protected String findRiver(Artifact artifact) { + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList [] data = adescr.getOldData(); + + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + if (dl.getState().equals("state.winfo.river")) { + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + DataItem [] di = d.getItems(); + if (di != null && di.length == 1) { + return d.getItems()[0].getStringValue(); + } + } + } + } + } + + return ""; + } + + public static String toJavaEncodedString(String str) { + if (str == null) { + return null; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0, len = str.length(); i < len; i++) { + int unipoint = Character.codePointAt(str, i); + if ((unipoint < 32) || (unipoint > 127)) { + sb.append("\\u"); + sb.append(Integer.toHexString((unipoint >> 3*4) & 0xf)); + sb.append(Integer.toHexString((unipoint >> 2*4) & 0xf)); + sb.append(Integer.toHexString((unipoint >> 1*4) & 0xf)); + sb.append(Integer.toHexString((unipoint >> 0*4) & 0xf)); + } else { + sb.append(str.charAt(i)); + } + } + return sb.toString(); + } + + protected void updateCollection() { + final Config config = Config.getInstance(); + final String loc = config.getLocale(); + + GWT.log("MapPrintPanel.updateCollection via RPC now"); + + List<Property> properties = new ArrayList<Property>(); + properties.add(new PropertySetting(MAPFISH_MAPTITLE, toJavaEncodedString(pageTitle.getValueAsString()))); +// properties.add(new PropertySetting(MAPFISH_LAYOUT, toJavaEncodedString(pageFormat.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_SUBTITLE, toJavaEncodedString(pageSubtitle.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_RANGE, toJavaEncodedString(pageRange.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_STRETCH, toJavaEncodedString(pageStretch.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_INSTITUTION, toJavaEncodedString(pageInstitution.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_SOURCE, toJavaEncodedString(pageSource.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_CREATOR, toJavaEncodedString(pageCreator.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_DATEPLACE, toJavaEncodedString(pageDatePlace.getValueAsString()))); + properties.add(new PropertySetting(MAPFISH_LOGO, toJavaEncodedString(pageLogo.getValueAsString()))); + settings.setSettings("default", properties); + + collection.addSettings("print-settings", settings); + updater.update(collection, loc, new AsyncCallback<Collection>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not update collection attributes."); + SC.warn(MSG.getString(caught.getMessage())); + } + @Override + public void onSuccess(Collection collection) { + GWT.log("MapPrint: collection attributes updated"); + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapPrintWindow.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,25 @@ +package de.intevation.flys.client.client.ui.map; + +import com.smartgwt.client.widgets.Window; +import com.google.gwt.core.client.GWT; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.FLYSConstants; + +public class MapPrintWindow extends Window { + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected MapPrintPanel panel; + + public MapPrintWindow(Collection collection, MapToolbar mapToolbar) { + setWidth(255); + setHeight(300); + + setTitle(MSG.printWindowTitle()); + centerInPage(); + + this.panel = new MapPrintPanel(collection, mapToolbar, this); + this.panel.setPadding(20); + addItem(this.panel); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapThemePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,294 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.util.BooleanCallback; +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.grid.events.HeaderDoubleClickEvent; +import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickHandler; +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 de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.ThemePanel; +import de.intevation.flys.client.shared.model.AttributedTheme; +import de.intevation.flys.client.shared.model.FacetRecord; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Theme; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MapThemePanel extends ThemePanel { + + public static final int CELL_HEIGHT = 25; + + + public interface ActivateCallback { + void activate(Theme theme, boolean activate); + } + + + public interface ThemeMovedCallback { + void onThemeMoved(Theme theme, int oldIdx, int newIdx); + } + + public interface LayerZoomCallback { + void onLayerZoom(Theme theme, String extent); + } + + + + private FLYSConstants MSG = GWT.create(FLYSConstants.class); + + + protected ActivateCallback activateCallback; + protected ThemeMovedCallback themeMovedCallback; + protected LayerZoomCallback layerZoomCallback; + + protected ListGridRecord[] oldRecords; + + + public static final String GRID_FIELD_ACTIVE = "active"; + public static final String GRID_FIELD_NAME = "name"; + + + protected MapOutputTab mapOut; + + + public MapThemePanel( + CollectionView view, + OutputMode mode, + MapOutputTab mapOut, + ActivateCallback activateCallback, + ThemeMovedCallback themeMovedCallback, + LayerZoomCallback layerZoomCallback + ) { + super(mode, view); + + this.mapOut = mapOut; + this.activateCallback = activateCallback; + this.themeMovedCallback = themeMovedCallback; + this.layerZoomCallback = layerZoomCallback; + + initGrid(); + initLayout(); + + updateGrid(); + } + + + protected void initLayout() { + setWidth100(); + setHeight100(); + + VLayout layout = new VLayout(); + layout.setWidth100(); + layout.setHeight100(); + + layout.addMember(list); + layout.addMember(navigation); + + addChild(layout); + } + + + protected void initGrid() { + list.setCanEdit(true); + list.setCanSort(false); + list.setShowRecordComponents(false); + list.setShowRecordComponentsByCell(true); + list.setShowHeader(true); + list.setShowHeaderContextMenu(false); + list.setCanReorderFields(false); + list.setWidth100(); + list.setHeight100(); + + list.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() { + @Override + public void onHeaderDoubleClick(HeaderDoubleClickEvent event) { + // cancel the event. + return; + } + }); + + list.setCellHeight(CELL_HEIGHT); + list.setShowRecordComponents(true); + list.setShowRecordComponentsByCell(true); + list.setShowAllRecords(true); + + list.addEditCompleteHandler(this); + + ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); + active.setType(ListGridFieldType.BOOLEAN); + active.setCanDragResize(false); + + ListGridField name = new ListGridField( + GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); + name.setType(ListGridFieldType.TEXT); + + list.setFields(active, name); + } + + + @Override + protected void clearGrid() { + oldRecords = list.getRecords(); + super.clearGrid(); + } + + + @Override + protected void addFacetRecord(FacetRecord rec) { + Theme newTheme = rec.getTheme(); + boolean isNew = true; + + for (ListGridRecord old: getOldRecords()) { + FacetRecord fr = (FacetRecord) old; + + if (newTheme.equals(fr.getTheme())) { + isNew = false; + break; + } + } + + if (isNew && mapOut != null) { + mapOut.addLayer(mapOut.createWMSLayer(newTheme)); + } + + super.addFacetRecord(rec); + } + + + @Override + protected Menu getSingleContextMenu(final ListGridRecord[] records) { + Menu menu = super.getSingleContextMenu(records); + + MenuItem layerZoom = createLayerZoomItem(records); + if (layerZoom != null) { + menu.addItem(layerZoom); + } + menu.addItem(createMapURLItem(records)); + + return menu; + } + + + protected MenuItem createMapURLItem(final ListGridRecord[] records) { + final FacetRecord fr = (FacetRecord) records[0]; + final AttributedTheme at = (AttributedTheme) fr.getTheme(); + + MenuItem item = new MenuItem(MSG.wmsURLMenuItem()); + item.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + String url = getMapOutputTab().wmsUrls().get(at.getAttr("layers")); + SC.say(MSG.wmsURLBoxTitle(), url); + } + }); + + return item; + } + + + @Override + protected MenuItem createRemoveItem(final ListGridRecord[] records) { + MenuItem item = super.createRemoveItem(records); + item.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + SC.ask(MSG.askThemeRemove(), new BooleanCallback() { + @Override + public void execute(Boolean value) { + if (value) { + for (ListGridRecord record: records) { + FacetRecord facet = (FacetRecord) record; + + Theme theme = facet.getTheme(); + theme.setVisible(0); + theme.setActive(0); + + AttributedTheme at = (AttributedTheme) theme; + getMapOutputTab().removeLayer(at.getAttr("layers")); + } + + updateCollection(); + } + } + }); + } + }); + + return item; + } + + + protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) { + final FacetRecord fr = (FacetRecord) recs[0]; + final AttributedTheme at = (AttributedTheme) fr.getTheme(); + + final String extent = at.getAttr("extent"); + + if (extent == null || extent.length() == 0) { + return null; + } + + MenuItem zoom = new MenuItem(MSG.zoomToLayer()); + zoom.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + if (layerZoomCallback != null) { + layerZoomCallback.onLayerZoom(at, extent); + } + } + }); + + return zoom; + } + + @Override + public String getWidthAsString() { + if(!isVisible()) { + return "0"; + } + else { + return super.getWidthAsString(); + } + } + + @Override + public void activateTheme(Theme theme, boolean active) { + if (activateCallback != null) { + activateCallback.activate(theme, active); + } + + theme.setActive(active ? 1 : 0); + } + + + @Override + protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) { + if (themeMovedCallback != null) { + themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx); + } + } + + + protected ListGridRecord[] getOldRecords() { + return oldRecords != null ? oldRecords : new ListGridRecord[0]; + } + + + protected MapOutputTab getMapOutputTab() { + return mapOut; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapToolbar.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,686 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.SelectionType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.ImgButton; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.ui.ImgLink; +import de.intevation.flys.client.client.ui.Toolbar; +import de.intevation.flys.client.client.utils.EnableDisableCmd; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertySetting; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.ThemeList; + +import java.util.List; + +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.control.DragPan; +import org.gwtopenmaps.openlayers.client.control.SelectFeature; +import org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions; +import org.gwtopenmaps.openlayers.client.control.ZoomBox; +import org.gwtopenmaps.openlayers.client.event.MapZoomListener; +import org.gwtopenmaps.openlayers.client.feature.VectorFeature; +import org.gwtopenmaps.openlayers.client.layer.Vector; +import org.gwtopenmaps.openlayers.client.util.Attributes; + + +/** + * Toolbar for the Map views. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MapToolbar +extends Toolbar +implements MapZoomListener +{ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected FloodMap floodMap; + protected DragPan pan; + protected ZoomBox zoomBox; + protected SelectFeature selectFeature; + protected GetFeatureInfo getFeatureInfo; + + protected Button manageThemesButton; + protected Button datacageButton; + protected Button legendButton; + + protected ImgButton addWMSButton; + protected ImgButton zoomToMaxButton; + protected ImgButton zoomBoxButton; + protected ImgButton zoomOutButton; + protected ImgButton panButton; + protected ImgButton selectButton; + protected ImgButton infoButton; + protected ImgButton removeButton; + protected ImgButton elevationButton; + protected ImgButton printMap; + + protected Label epsgLabel; + + protected DrawControl drawControl; + protected MeasureControl measureControl; + + protected LegendWindow legendWindow; + + protected Canvas position; + + + public MapToolbar(FloodMap floodMap, boolean digitize) { + this(null, floodMap, digitize); + } + + + public MapToolbar( + MapOutputTab mapTab, + FloodMap floodMap, + boolean digitize) + { + super(mapTab); + + setWidth100(); + setHeight(38); + setMembersMargin(10); + setPadding(5); + setBorder("1px solid black"); + this.floodMap = floodMap; + + zoomToMaxButton = createMaxExtentControl(); + zoomBoxButton = createZoomBoxControl(); + zoomOutButton = createZoomOutControl(); + panButton = createPanControl(); + drawControl = createDrawControl(); + selectButton = createSelectFeatureControl(); + infoButton = createGetFeatureInfo(); + measureControl = createMeasureControl(); + position = createMousePosition(); + removeButton = createRemoveFeatureControl(); + elevationButton = createElevationControl(); + epsgLabel = createEPSGLabel(); + + if (mapTab != null) { + manageThemesButton = createManageThemesControl(); + addMember(manageThemesButton); + + datacageButton = createDatacageControl(); + addMember(datacageButton); + + legendButton = createLegendControl(); + addMember(legendButton); + + addWMSButton = createWMSControl(); + addMember(addWMSButton); + + printMap = createMapPrintControl(); + addMember(printMap); + } + + addMember(zoomToMaxButton); + addMember(zoomBoxButton); + addMember(zoomOutButton); + addMember(panButton); + + if (digitize) { + addMember(drawControl); + addMember(selectButton); + addMember(removeButton); + addMember(elevationButton); + } + + if (infoButton != null) { + addMember(infoButton); + } + + addMember(measureControl); + addMember(createRightPanel()); + } + + + protected HLayout createRightPanel() { + HLayout right = new HLayout(); + right.setAlign(Alignment.RIGHT); + + right.addMember(epsgLabel); + right.addMember(position); + + return right; + } + + + protected Map getMap() { + return floodMap.getMap(); + } + + + protected void activatePan(boolean activate) { + if (activate) { + panButton.select(); + pan.activate(); + } + else { + panButton.deselect(); + pan.deactivate(); + } + } + + + protected void activateZoomBox(boolean activate) { + if (activate) { + zoomBoxButton.select(); + zoomBox.activate(); + } + else { + zoomBoxButton.deselect(); + zoomBox.deactivate(); + } + } + + + public void activateDrawFeature(boolean activate) { + drawControl.activate(activate); + } + + + protected void activateSelectFeature(boolean activate) { + if (activate) { + selectButton.select(); + selectFeature.activate(); + } + else { + selectButton.deselect(); + selectFeature.deactivate(); + } + } + + + protected void activateMeasureControl(boolean activate) { + measureControl.activate(activate); + } + + + protected void activateGetFeatureInfo(boolean activate) { + if (infoButton == null) { + return; + } + + if (activate) { + infoButton.select(); + } + else { + infoButton.deselect(); + } + + getFeatureInfo.activate(activate); + } + + + protected ImgButton createButton(String img, ClickHandler handler) { + ImgButton btn = new ImgButton(); + + String baseUrl = GWT.getHostPageBaseURL(); + btn.setSrc(baseUrl + img); + btn.setWidth(20); + btn.setHeight(20); + btn.setShowDown(false); + btn.setShowRollOver(false); + btn.setShowRollOverIcon(false); + btn.setShowDisabled(false); + btn.setShowDisabledIcon(true); + btn.setShowDownIcon(false); + btn.setShowFocusedIcon(false); + + if (handler != null) { + btn.addClickHandler(handler); + } + + return btn; + } + + + protected ImgButton createToggleButton( + String img, + final EnableDisableCmd cmd + ) { + final ImgButton btn = new ImgButton(); + + String baseUrl = GWT.getHostPageBaseURL(); + btn.setSrc(baseUrl + img); + btn.setActionType(SelectionType.CHECKBOX); + btn.setSize(20); + btn.setShowRollOver(false); + btn.setShowRollOverIcon(false); + btn.setSelected(false); + btn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent e) { + if (btn.isSelected()) { + cmd.enable(); + } + else { + cmd.disable(); + } + } + }); + + return btn; + } + + + protected ImgButton createMaxExtentControl() { + ImgButton zoomToMax = createButton(MSG.zoom_all(), new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + floodMap.getMap().zoomToMaxExtent(); + } + }); + + zoomToMax.setTooltip(MSG.zoomMaxExtent()); + + return zoomToMax; + } + + + protected ImgButton createZoomBoxControl() { + zoomBox = new ZoomBox(); + + EnableDisableCmd cmd = new EnableDisableCmd() { + @Override + public void enable() { + activatePan(false); + activateDrawFeature(false); + activateSelectFeature(false); + activateMeasureControl(false); + activateGetFeatureInfo(false); + activateZoomBox(true); + } + + @Override + public void disable() { + activateZoomBox(false); + } + }; + + ImgButton button = createToggleButton(MSG.zoom_in(), cmd); + button.setTooltip(MSG.zoomIn()); + + Map map = getMap(); + map.addControl(zoomBox); + + return button; + } + + + protected ImgButton createZoomOutControl() { + ImgButton zoomOut = createButton(MSG.zoom_out(), new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + Map map = floodMap.getMap(); + int level = map.getZoom(); + + if (level > 1) { + map.zoomTo(level-1); + } + } + }); + + zoomOut.setTooltip(MSG.zoomOut()); + + return zoomOut; + } + + + protected ImgButton createPanControl() { + pan = new DragPan(); + getMap().addControl(pan); + + EnableDisableCmd cmd = new EnableDisableCmd() { + @Override + public void enable() { + activateZoomBox(false); + activateDrawFeature(false); + activateSelectFeature(false); + activateMeasureControl(false); + activateGetFeatureInfo(false); + activatePan(true); + } + + @Override + public void disable() { + activatePan(false); + } + }; + + final ImgButton button = createToggleButton(MSG.pan(), cmd); + button.setTooltip(MSG.moveMap()); + + return button; + } + + + protected DrawControl createDrawControl() { + EnableDisableCmd cmd = new EnableDisableCmd() { + @Override + public void enable() { + activateZoomBox(false); + activatePan(false); + activateDrawFeature(true); + activateSelectFeature(false); + activateMeasureControl(false); + } + + @Override + public void disable() { + activateDrawFeature(false); + } + }; + return new DrawControl(getMap(), floodMap.getBarrierLayer(), cmd); + } + + + protected ImgButton createSelectFeatureControl() { + SelectFeatureOptions opts = new SelectFeatureOptions(); + opts.setBox(true); + + // VectorFeatures selected by the SelectFeature control are manually + // marked with the string "mark.delete". The control to remove selected + // features makes use of this string to determine if the feature should + // be deleted (is marked) or not. Actually, we would like to use the + // OpenLayers native mechanism to select features, but for some reason + // this doesn't work here. After a feature has been selected, the layer + // still has no selected features. + opts.onSelect(new SelectFeature.SelectFeatureListener() { + @Override + public void onFeatureSelected(VectorFeature feature) { + floodMap.selectFeature(feature); + } + }); + + opts.onUnSelect(new SelectFeature.UnselectFeatureListener() { + @Override + public void onFeatureUnselected(VectorFeature feature) { + floodMap.disableFeature(feature); + } + }); + + selectFeature = new SelectFeature(floodMap.getBarrierLayer(), opts); + getMap().addControl(selectFeature); + + EnableDisableCmd cmd = new EnableDisableCmd() { + @Override + public void enable() { + activateDrawFeature(false); + activatePan(false); + activateZoomBox(false); + activateSelectFeature(true); + activateMeasureControl(false); + } + + @Override + public void disable() { + activateSelectFeature(false); + floodMap.disableFeatures(); + } + }; + + ImgButton button = createToggleButton(MSG.selectFeature(), cmd); + button.setTooltip(MSG.selectObject()); + + return button; + } + + + protected ImgButton createRemoveFeatureControl() { + ImgButton remove = createButton(MSG.removeFeature(),new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + Vector barriers = floodMap.getBarrierLayer(); + VectorFeature[] features = barriers.getFeatures(); + + if (features == null || features.length == 0) { + return; + } + + for (int i = features.length-1; i >= 0; i--) { + VectorFeature feature = features[i]; + + Attributes attr = feature.getAttributes(); + int del = attr.getAttributeAsInt(FloodMap.MARK_SELECTED); + + if (del == 1) { + barriers.removeFeature(feature); + feature.destroy(); + } + } + } + }); + + remove.setTooltip(MSG.removeObject()); + + return remove; + } + + + protected ImgButton createElevationControl() { + ImgButton btn = createButton(MSG.adjustElevation(), new ClickHandler() { + @Override + public void onClick(ClickEvent evt) { + Vector barriers = floodMap.getBarrierLayer(); + VectorFeature[] features = barriers.getFeatures(); + + VectorFeature feature = null; + + if (features == null || features.length == 0) { + SC.warn(MSG.error_no_feature_selected()); + return; + } + + boolean multipleFeatures = false; + + for (VectorFeature f: features) { + Attributes attr = f.getAttributes(); + if (attr.getAttributeAsInt(FloodMap.MARK_SELECTED) == 1) { + if (feature == null) { + feature = f; + } + else { + multipleFeatures = true; + } + } + } + + if (feature == null) { + SC.warn(MSG.error_no_feature_selected()); + return; + } + + new ElevationWindow(floodMap, feature).show(); + + if (multipleFeatures) { + SC.warn(MSG.warning_use_first_feature()); + } + } + }); + + btn.setTooltip(MSG.adjustElevationTooltip()); + + return btn; + } + + + protected Canvas createMousePosition() { + return new MapPositionPanel(floodMap.getMapWidget()); + } + + + protected MeasureControl createMeasureControl() { + EnableDisableCmd cmd = new EnableDisableCmd() { + @Override + public void enable() { + activateDrawFeature(false); + activatePan(false); + activateZoomBox(false); + activateSelectFeature(false); + activateGetFeatureInfo(false); + } + + @Override + public void disable() { + // do nothing + } + }; + + return new MeasureControl(floodMap, cmd); + } + + + protected Button createDatacageControl() { + Button btn = new Button(MSG.databasket()); + btn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent evt) { + openDatacageWindow((MapOutputTab) getOutputTab()); + } + }); + + return btn; + } + + + protected Button createLegendControl() { + Button btn = new Button(MSG.legend()); + btn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + openLegendWindow(); + } + }); + + return btn; + } + + + protected void openLegendWindow() { + if (legendWindow == null) { + MapOutputTab tab = (MapOutputTab) getOutputTab(); + legendWindow = new LegendWindow(tab.getThemePanel().getThemeList()); + } + + legendWindow.show(); + } + + + protected ImgButton createGetFeatureInfo() { + MapOutputTab ot = (MapOutputTab) getOutputTab(); + if (ot == null) { + return null; + } + + //ThemeList tl = ot.getCollection().getThemeList("floodmap"); + + getFeatureInfo = new GetFeatureInfo( + getMap(), + ot.getThemePanel(), + "gml"); + + EnableDisableCmd cmd = new EnableDisableCmd() { + @Override + public void enable() { + activateDrawFeature(false); + activatePan(false); + activateZoomBox(false); + activateSelectFeature(false); + activateMeasureControl(false); + activateGetFeatureInfo(true); + } + + @Override + public void disable() { + activateGetFeatureInfo(false); + } + }; + + ImgButton button = createToggleButton(MSG.getFeatureInfo(), cmd); + button.setTooltip(MSG.getFeatureInfoTooltip()); + + return button; + } + + + protected Button createManageThemesControl() { + Button btn = new Button(MSG.manageThemes()); + btn.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + ((MapOutputTab)getOutputTab()).toogleThemePanel(); + } + }); + return btn; + } + + + protected ImgButton createMapPrintControl() { + final MapToolbar mtb = this; + ImgButton btn = createButton(MSG.printMapSettings(), new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + MapPrintWindow mpsw = + new MapPrintWindow(outputTab.getCollection(), mtb); + outputTab.getCollectionView().addChild(mpsw); + } + }); + btn.setTooltip(MSG.printTooltip()); + + return btn; + } + + + protected ImgButton createWMSControl() { + final String srs = floodMap.getRiverProjection(); + + ImgButton add = createButton(MSG.addWMS(), new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + MapOutputTab ot = (MapOutputTab) getOutputTab(); + new ExternalWMSWindow(ot, srs).start(); + } + }); + + add.setTooltip(MSG.addWMSTooltip()); + + return add; + } + + + protected Label createEPSGLabel() { + Label epsgLabel = new Label(floodMap.getRiverProjection()); + + epsgLabel.setAlign(Alignment.RIGHT); + epsgLabel.setWidth(75); + + return epsgLabel; + } + + @Override + public void onMapZoom(MapZoomListener.MapZoomEvent e) { +// updatePrintUrl(); + } + + public void updateThemes(ThemeList themeList) { + if (legendWindow != null) { + legendWindow.update(themeList); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MeasureControl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,219 @@ +package de.intevation.flys.client.client.ui.map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.SelectionType; +import com.smartgwt.client.widgets.ImgButton; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import org.gwtopenmaps.openlayers.client.control.Measure; +import org.gwtopenmaps.openlayers.client.event.MeasureEvent; +import org.gwtopenmaps.openlayers.client.event.MeasureListener; +import org.gwtopenmaps.openlayers.client.event.MeasurePartialListener; +import org.gwtopenmaps.openlayers.client.handler.PathHandler; +import org.gwtopenmaps.openlayers.client.handler.PolygonHandler; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.utils.EnableDisableCmd; + + +public class MeasureControl extends HLayout { + + public static final String NUMBER_FORMAT_PATTERN = "#.##"; + + public static final String AREA_UNIT = "ha"; + public static final int AREA_FACTOR_M = 10000; + public static final int AREA_FACTOR_KM = 100; + + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected FloodMap floodMap; + + protected Measure measureLine; + protected Measure measurePolygon; + + protected ImgButton measureLineButton; + protected ImgButton measurePolyButton; + protected Label label; + + protected NumberFormat formatter; + + + public MeasureControl(FloodMap floodMap, EnableDisableCmd cmd) { + this.floodMap = floodMap; + + measureLineButton = createMeasureLineControl(cmd); + measurePolyButton = createMeasurePolyControl(cmd); + + formatter = NumberFormat.getFormat(NUMBER_FORMAT_PATTERN); + + label = new Label(); + + initLayout(); + } + + + protected void initLayout() { + setWidth(100); + setMembersMargin(2); + + label.setWidth(75); + + addMember(measureLineButton); + addMember(measurePolyButton); + addMember(label); + } + + + protected ImgButton createMeasureLineControl(final EnableDisableCmd cmd) { + measureLine = new Measure(new PathHandler()); + measureLine.setPersist(true); + measureLine.addMeasureListener(new MeasureListener() { + public void onMeasure(MeasureEvent e) { + updateMeasure(e.getMeasure(), e.getUnits()); + } + }); + measureLine.addMeasurePartialListener(new MeasurePartialListener() { + public void onMeasurePartial(MeasureEvent e) { + updateMeasure(e.getMeasure(), e.getUnits()); + } + }); + + floodMap.getMap().addControl(measureLine); + + final ImgButton btn = new ImgButton(); + String baseUrl = GWT.getHostPageBaseURL(); + btn.setSrc(baseUrl + MSG.measureLine()); + btn.setActionType(SelectionType.CHECKBOX); + btn.setSize(20); + btn.setShowRollOver(false); + btn.setShowRollOverIcon(false); + btn.setSelected(false); + btn.setTooltip(MSG.measureDistance()); + btn.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent e) { + if (btn.isSelected()) { + cmd.enable(); + activateMeasurePolygon(false); + activateMeasureLine(true); + } + else { + cmd.disable(); + activateMeasureLine(false); + } + } + }); + + return btn; + } + + + protected ImgButton createMeasurePolyControl(final EnableDisableCmd cmd) { + measurePolygon = new Measure(new PolygonHandler()); + measurePolygon.setPersist(true); + measurePolygon.addMeasureListener(new MeasureListener() { + public void onMeasure(MeasureEvent e) { + updateMeasureArea(e.getMeasure(), e.getUnits()); + } + }); + measurePolygon.addMeasurePartialListener(new MeasurePartialListener() { + public void onMeasurePartial(MeasureEvent e) { + updateMeasureArea(e.getMeasure(), e.getUnits()); + } + }); + + floodMap.getMap().addControl(measurePolygon); + + final ImgButton btn = new ImgButton(); + String baseUrl = GWT.getHostPageBaseURL(); + btn.setSrc(baseUrl + MSG.measurePolygon()); + btn.setActionType(SelectionType.CHECKBOX); + btn.setSize(20); + btn.setShowRollOver(false); + btn.setShowRollOverIcon(false); + btn.setSelected(false); + btn.setTooltip(MSG.measureArea()); + btn.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent e) { + if (btn.isSelected()) { + cmd.enable(); + activateMeasureLine(false); + activateMeasurePolygon(true); + } + else { + cmd.disable(); + activateMeasurePolygon(false); + } + } + }); + + return btn; + } + + + protected void clearMeasure() { + label.setContents(""); + } + + + protected void updateMeasure(float value, String unit) { + label.setContents(formatter.format(value) + " " + unit); + } + + + protected void updateMeasureArea(float value, String unit) { + float ha = value; + String ha_unit = unit; + + if (unit.equals("m")) { + ha = (float) value / AREA_FACTOR_M; + ha_unit = AREA_UNIT; + } + else if (unit.equals("km")) { + ha = (float) value * AREA_FACTOR_KM; + ha_unit = AREA_UNIT; + } + + label.setContents(formatter.format(ha) + " " + ha_unit); + } + + + public void activate(boolean activate) { + if (!activate) { + clearMeasure(); + activateMeasureLine(activate); + activateMeasurePolygon(activate); + } + } + + + protected void activateMeasureLine(boolean activate) { + if (activate) { + clearMeasure(); + measureLineButton.select(); + measureLine.activate(); + } + else { + measureLineButton.deselect(); + measureLine.deactivate(); + } + } + + + protected void activateMeasurePolygon(boolean activate) { + if (activate) { + clearMeasure(); + measurePolyButton.select(); + measurePolygon.activate(); + } + else { + measurePolyButton.deselect(); + measurePolygon.deactivate(); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/WMSLayersTree.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,122 @@ +package de.intevation.flys.client.client.ui.map; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.TreeModelType; +import com.smartgwt.client.widgets.tree.Tree; +import com.smartgwt.client.widgets.tree.TreeGrid; +import com.smartgwt.client.widgets.tree.TreeNode; + +import de.intevation.flys.client.shared.model.Capabilities; +import de.intevation.flys.client.shared.model.WMSLayer; + + +public class WMSLayersTree extends TreeGrid { + + /** + * An internal TreeNode that stores besides some string attribute a WMSLayer + * object. + */ + public static class WMSLayerNode extends TreeNode { + + protected WMSLayer wms; + + public WMSLayerNode(WMSLayer wms) { + super(); + this.wms = wms; + + setAttribute("name", wms.getName()); + setAttribute("title", wms.getTitle()); + } + + public WMSLayer getWMSLayer() { + return wms; + } + } // end of class WMSLayerNode + + + protected Capabilities capabilites; + protected String srs; + + + public WMSLayersTree(Capabilities capabilites) { + super(); + this.capabilites = capabilites; + + initTree(); + } + + + public WMSLayersTree(Capabilities capabilites, String srs) { + super(); + + this.capabilites = capabilites; + this.srs = srs; + + initTree(); + } + + + protected void initTree() { + setLoadDataOnDemand(false); + setWidth100(); + setHeight100(); + setShowRoot(false); + setShowConnectors(true); + setNodeIcon("[SKIN]/images/blank.gif"); + + Tree tree = new Tree(); + tree.setChildrenProperty("children-nodes"); + tree.setNameProperty("title"); + tree.setIdField("title"); + tree.setModelType(TreeModelType.CHILDREN); + tree.setShowRoot(false); + + TreeNode root = new TreeNode("Root"); + TreeNode[] layers = buildTree(capabilites.getLayers()); + + root.setAttribute("children-nodes", layers); + tree.setRoot(root); + + setData(tree); + + if (layers != null && layers.length == 1) { + tree.openFolder(layers[0]); + } + } + + + protected TreeNode[] buildTree(List<WMSLayer> layers) { + List<TreeNode> layerNodes = new ArrayList<TreeNode>(); + + for (WMSLayer layer: layers) { + WMSLayerNode tn = buildTreeNode(layer); + + if (tn != null) { + TreeNode[] tns = buildTree(layer.getLayers()); + + if (tns != null && tns.length > 0) { + tn.setAttribute("children-nodes", tns); + } + + layerNodes.add(tn); + } + } + + return layerNodes.toArray(new TreeNode[layerNodes.size()]); + } + + + protected WMSLayerNode buildTreeNode(WMSLayer wms) { + if (srs != null && srs.length() > 0) { + return wms.supportsSrs(srs) ? new WMSLayerNode(wms) : null; + } + else { + GWT.log("No target SRS specified."); + return new WMSLayerNode(wms); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedCampaignChart.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,78 @@ +package de.intevation.flys.client.client.ui.minfo; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONString; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.shared.model.Artifact; + +public class BedCampaignChart extends VLayout { + + private final Artifact artifact; + + protected Img chartImg; + + public BedCampaignChart(Artifact artifact, ResizedHandler resizeHandler) { + super(); + + this.artifact = artifact; + this.chartImg = new Img(); + + addResizedHandler(resizeHandler); + setAlign(Alignment.CENTER); + } + + public void update() { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + int hWidth = getWidth() - 12; + int hHeight = getHeight() - 12; + + if ((int) (hHeight * 4f / 3) < hWidth) { + hWidth = (int) (hHeight * 4f / 3); + } + else { + hHeight = (int) (hWidth * 3f / 4); + } + + String river = artifact.getArtifactDescription().getRiver(); + + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + JSONObject jextent = new JSONObject(); + JSONNumber jwidth = new JSONNumber(hWidth); + JSONNumber jheight = new JSONNumber(hHeight); + + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jextent.put("width", jwidth); + jextent.put("height", jheight); + jfilter.put("extent", jextent); + jfix.put("bed", jfilter); + String filter = jfix.toString(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "bed-km-chart"; + imgUrl += "?locale=" + locale; + imgUrl += "&filter=" + filter; + + if (chartImg != null && hasMember(chartImg)) { + chartImg.setWidth(hWidth); + chartImg.setHeight(hHeight); + chartImg.setSrc(imgUrl); + } + else { + chartImg = new Img(imgUrl, hWidth, hHeight); + addMember(chartImg); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedHeightsDatacagePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,310 @@ +package de.intevation.flys.client.client.ui.minfo; + +import com.google.gwt.core.client.GWT; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.data.Record; + +import com.smartgwt.client.widgets.Canvas; + +import com.smartgwt.client.widgets.events.ClickEvent; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.client.event.StepForwardEvent; + +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.client.services.RemoveArtifactService; +import de.intevation.flys.client.client.services.RemoveArtifactServiceAsync; + +import de.intevation.flys.client.client.ui.DatacagePairWidget; +import de.intevation.flys.client.client.ui.DatacageTwinPanel; +import de.intevation.flys.client.client.ui.RecommendationPairRecord; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; + +import de.intevation.flys.client.shared.model.Recommendation.Facet; +import de.intevation.flys.client.shared.model.Recommendation.Filter; + +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.User; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +// TODO Probably better to branch off AbstractUIProvider. +// TODO Merge with other datacage-widget impls. +/** + * Panel containing a Grid and a "next" button. The Grid is fed by a + * DatacagePairWidget which is put in the input-helper area. + */ +public class BedHeightsDatacagePanel +extends DatacageTwinPanel { + + protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** + * List to track previously selected but now removed pairs. (Needed to + * be able to identify artifacts that can be removed from the collection. + */ + protected List<RecommendationPairRecord> removedPairs = + new ArrayList<RecommendationPairRecord>(); + + /** Service handle to clone and add artifacts to collection. */ + LoadArtifactServiceAsync loadArtifactService = GWT.create( + de.intevation.flys.client.client.services.LoadArtifactService.class); + + /** Service to remove artifacts from collection. */ + RemoveArtifactServiceAsync removeArtifactService = GWT.create( + de.intevation.flys.client.client.services.RemoveArtifactService.class); + + + public BedHeightsDatacagePanel(User user) { + super(user); + } + + + /** + * Create a recommendation from a string representation of it. + * @TODO describe format of input string + * @param from string in format as shown above. + * @return recommendation from input string. + */ + public Recommendation createRecommendationFromString(String from) { + // TODO Construct "real" filter. + String[] parts = unbracket(from).split(";"); + Recommendation.Filter filter = new Recommendation.Filter(); + Recommendation.Facet facet = new Recommendation.Facet( + parts[1], + parts[2]); + + List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet> + (); + facets.add(facet); + filter.add("longitudinal_section", facets); + Recommendation r = new Recommendation("bedheight", parts[0], + this.artifact.getUuid(), filter); + r.setDisplayName(parts[3]); + return r; + } + + + /** + * Creates the graphical representation and interaction widgets for the data. + * @param dataList the data. + * @return graphical representation and interaction widgets for data. + */ + @Override + public Canvas create(DataList dataList) { + GWT.log("createData()"); + + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + String value = items[0].getStringValue(); + + String filter = "minfo-heights"; + if (value.equals("epoch")) { + filter = "minfo-heights-epoch"; + } + Canvas widget = createWidget(); + Canvas submit = getNextButton(); + + VLayout layout = new VLayout(); + HLayout helperLayout = new HLayout(); + helperLayout.addMember(new DatacagePairWidget(this.artifact, + user, filter, differencesList)); + + layout.addMember(widget); + layout.addMember(submit); + layout.setMembersMargin(10); + this.helperContainer.addMember(helperLayout); + + this.dataName = "diffids"; + + return layout; + } + + + /** + * Add record to list of removed records. + */ + public void trackRemoved(Record r) { + RecommendationPairRecord pr = (RecommendationPairRecord) r; + this.removedPairs.add(pr); + } + + + /** + * Validates data, does nothing if invalid, otherwise clones new selected + * waterlevels and add them to collection, forward the artifact. + */ + @Override + public void onClick(ClickEvent e) { + GWT.log("DatacageTwinPanel.onClick"); + + List<String> errors = validate(); + if (errors != null && !errors.isEmpty()) { + showErrors(errors); + return; + } + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + ListGridRecord[] records = differencesList.getRecords(); + + List<Recommendation> ar = new ArrayList<Recommendation>(); + List<Recommendation> all = new ArrayList<Recommendation>(); + + for (ListGridRecord record : records) { + RecommendationPairRecord r = + (RecommendationPairRecord) record; + // Do not add "old" recommendations. + if (!r.isAlreadyLoaded()) { + // Check whether one of those is a dike or similar. + // TODO differentiate and merge: new clones, new, old. + Recommendation firstR = r.getFirst(); + if(firstR.getIDs() != null) { + GWT.log("First IDs: " + firstR.getIDs() + " factory: " + + firstR.getFactory()); + } + firstR.setFactory("bedheight"); + Recommendation secondR = r.getSecond(); + if(secondR.getIDs() != null) { + GWT.log("Second IDs: " + secondR.getIDs() + " factory: " + + secondR.getFactory()); + } + secondR.setFactory("bedheight"); + + ar.add(firstR); + ar.add(secondR); + } + else { + all.add(r.getFirst()); + all.add(r.getSecond()); + } + } + + final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]); + final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]); + + // Find out whether "old" artifacts have to be removed. + List<String> artifactIdsToRemove = new ArrayList<String>(); + for (RecommendationPairRecord rp: this.removedPairs) { + Recommendation first = rp.getFirst(); + Recommendation second = rp.getSecond(); + + for (Recommendation recommendation: toUse) { + if (first != null && first.getIDs().equals(recommendation.getIDs())) { + first = null; + } + if (second != null && second.getIDs().equals(recommendation.getIDs())) { + second = null; + } + + if (first == null && second == null) { + break; + } + } + if (first != null) { + artifactIdsToRemove.add(first.getIDs()); + } + if (second != null) { + artifactIdsToRemove.add(second.getIDs()); + } + } + + // Remove old artifacts, if any. Do this asychronously without much + // feedback. + for(final String uuid: artifactIdsToRemove) { + removeArtifactService.remove(this.collection, + uuid, + locale, + new AsyncCallback<Collection>() { + public void onFailure(Throwable caught) { + GWT.log("RemoveArtifact (" + uuid + ") failed."); + } + public void onSuccess(Collection collection) { + GWT.log("RemoveArtifact succeeded"); + } + }); + } + + // Clone new ones (and spawn statics), go forward. + loadArtifactService.loadMany( + this.collection, + toClone, + //"staticwkms" and "waterlevel" + null, + locale, + new AsyncCallback<Artifact[]>() { + public void onFailure(Throwable caught) { + GWT.log("Failure of cloning with factories!"); + } + public void onSuccess(Artifact[] artifacts) { + GWT.log("Successfully cloned " + toClone.length + + " with factories."); + + fireStepForwardEvent(new StepForwardEvent( + getData(toClone, artifacts, toUse))); + } + }); + } + + + /** + * Creates part of the String that encodes minuend or subtrahend. + * @param artifact Artifacts UUID. + * @param recommendation Recommendation to wrap in string. + */ + protected String createDataString( + String artifact, + Recommendation recommendation) + { + Filter filter = recommendation.getFilter(); + Facet f = null; + + if(filter != null) { + Map<String, List<Facet>> outs = filter.getOuts(); + Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); + + for (Map.Entry<String, List<Facet>> entry: entries) { + List<Facet> fs = entry.getValue(); + + f = fs.get(0); + if (f != null) { + break; + } + } + + return "[" + artifact + ";" + + f.getName() + + ";" + + f.getIndex() + + ";" + + recommendation.getDisplayName() + "]"; + } + else { + return "[" + + artifact + + ";bedheight;0;" + + recommendation.getDisplayName() + "]"; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedMultiPeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,34 @@ +package de.intevation.flys.client.client.ui.minfo; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.ui.MultiPeriodPanel; + +public class BedMultiPeriodPanel +extends MultiPeriodPanel +implements ResizedHandler { + protected BedCampaignChart chartContainer1; + protected BedloadCampaignChart chartContainer2; + + public BedMultiPeriodPanel() { + } + + @Override + protected Canvas createHelper() { + chartContainer1 = new BedCampaignChart(artifact, this); + chartContainer2 = new BedloadCampaignChart(artifact, this); + VLayout layout = new VLayout(); + layout.addMember(chartContainer1); + layout.addMember(chartContainer2); + return layout; + } + + @Override + public void onResized(ResizedEvent re) { + chartContainer1.update(); + chartContainer2.update(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedloadCampaignChart.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,78 @@ +package de.intevation.flys.client.client.ui.minfo; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONString; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.shared.model.Artifact; + +public class BedloadCampaignChart extends VLayout { + + private final Artifact artifact; + + protected Img chartImg; + + public BedloadCampaignChart(Artifact artifact, ResizedHandler resizeHandler) { + super(); + + this.artifact = artifact; + this.chartImg = new Img(); + + addResizedHandler(resizeHandler); + setAlign(Alignment.CENTER); + } + + public void update() { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + int hWidth = getWidth() - 12; + int hHeight = getHeight() - 12; + + if ((int) (hHeight * 4f / 3) < hWidth) { + hWidth = (int) (hHeight * 4f / 3); + } + else { + hHeight = (int) (hWidth * 3f / 4); + } + + String river = artifact.getArtifactDescription().getRiver(); + + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + JSONObject jextent = new JSONObject(); + JSONNumber jwidth = new JSONNumber(hWidth); + JSONNumber jheight = new JSONNumber(hHeight); + + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jextent.put("width", jwidth); + jextent.put("height", jheight); + jfilter.put("extent", jextent); + jfix.put("bedload", jfilter); + String filter = jfix.toString(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "bedload-km-chart"; + imgUrl += "?locale=" + locale; + imgUrl += "&filter=" + filter; + + if (chartImg != null && hasMember(chartImg)) { + chartImg.setWidth(hWidth); + chartImg.setHeight(hHeight); + chartImg.setSrc(imgUrl); + } + else { + chartImg = new Img(imgUrl, hWidth, hHeight); + addMember(chartImg); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/CheckboxPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,117 @@ +package de.intevation.flys.client.client.ui.minfo; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Set; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.ui.AbstractUIProvider; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +public class CheckboxPanel extends AbstractUIProvider { + + private String dataName; + HashMap<String, Boolean> values; + + protected DynamicForm form; + + public CheckboxPanel() { + super(); + values = new HashMap<String, Boolean>(); + } + + @Override + public Canvas createOld(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + HLayout layout = new HLayout(); + Label label = new Label(dataList.getLabel()); + Label value = new Label(items[0].getLabel()); + + layout.setHeight(35); + layout.setWidth(400); + label.setWidth(200); + + layout.addMember(label); + layout.addMember(value); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + @Override + public Canvas create(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + this.dataName = data.getLabel(); + form = new DynamicForm(); + + VLayout layout = new VLayout(); + Label label = new Label(data.getDescription()); + LinkedList<CheckboxItem> cbItems = new LinkedList<CheckboxItem>(); + for (int i = 0; i < items.length; i++) { + CheckboxItem item = new CheckboxItem(items[i].getLabel()); + GWT.log(items[i].getStringValue() + "; " + items[i].getLabel()); + item.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent event) { + values.put( + event.getItem().getName(), + (Boolean)event.getItem().getValue()); + } + }); + cbItems.add(item); + } + + form.setFields(cbItems.toArray(new CheckboxItem[cbItems.size()])); + layout.setMembersMargin(10); + layout.setHeight(35); + label.setHeight(35); + + layout.addMember(label); + layout.addMember(form); + layout.addMember(getNextButton()); + layout.setMembersMargin(10); + + return layout; + } + + @Override + protected Data[] getData() { + String value = ""; + Set<String> entries = values.keySet(); + boolean first = true; + for (String s: values.keySet()) { + if (!first) { + value += ";"; + } + if ((Boolean)values.get(s) == true) { + value += s; + } + first = false; + } + DataItem item = new DefaultDataItem("diameter", "diameter", value); + + return new Data[] {new DefaultData( + "diameter", + null, + null, + new DataItem[]{item})}; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadDistancePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,276 @@ +package de.intevation.flys.client.client.ui.minfo; + +import java.util.List; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.ui.AbstractUIProvider; +import de.intevation.flys.client.client.ui.DoubleRangeOnlyPanel; +import de.intevation.flys.client.client.ui.DoubleRangePanel; +import de.intevation.flys.client.client.ui.LocationPicker; +import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + + +public class SedLoadDistancePanel +extends AbstractUIProvider +implements BlurHandler, CellClickHandler +{ + public static final String FIELD_LOWER = "ld_from"; + public static final String FIELD_UPPER = "ld_to"; + + protected DoubleRangePanel distancePanel; + protected double min; + protected double max; + protected LocationPicker picker; + + @Override + public Canvas createOld(DataList dataList) { + String s = getOldSelectionString(dataList); + String l = dataList.getLabel(); + + Label label = new Label(l); + Label selected = new Label(s); + + HLayout layout = new HLayout(); + + layout.setWidth(400); + label.setWidth(200); + selected.setWidth(130); + + layout.addMember(label); + layout.addMember(selected); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + protected String getOldSelectionString(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data dFrom = getData(items, FIELD_LOWER); + Data dTo = getData(items, FIELD_UPPER); + + DataItem[] from = dFrom.getItems(); + DataItem[] to = dTo.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(from[0].getLabel()); + sb.append(" " + MSG.dpUnitFrom() + " - "); + sb.append(to[0].getLabel()); + sb.append(" " + MSG.dpUnitTo()); + + return sb.toString(); + } + + @Override + public Canvas create(DataList data) { + picker = new LocationPicker(this); + distancePanel = new DoubleRangeOnlyPanel( + MSG.dpUnitFrom() + " - ", MSG.dpUnitTo(), 0d, 0d, 250, this, "right"); + VLayout layout = new VLayout(); + layout.setMembersMargin(10); + + Label label = new Label(MSG.distance_state()); + + Canvas submit = getNextButton(); + + label.setHeight(25); + distancePanel.setHeight(50); + + layout.addMember(label); + layout.addMember(distancePanel); + layout.addMember(submit); + + initMinMaxValues(data); + initDefaultValues(data); + + + picker.setIsDistance(true); + picker.getLocationTable().setAutoFetchData(true); + picker.prepareFilter(); + + helperContainer.addMember(picker.getLocationTable()); + helperContainer.addMember(picker.getFilterLayout()); + helperContainer.addMember(picker.getResultCountForm()); + + setPickerDataSource(); + picker.createLocationTable(); + + return layout; + } + + protected void initMinMaxValues(DataList data) { + Data f = getData(data.getAll(), FIELD_LOWER); + Data t = getData(data.getAll(), FIELD_UPPER); + + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + + try { + min = Double.valueOf(fItems[0].getStringValue()); + max = Double.valueOf(tItems[0].getStringValue()); + } + catch (NumberFormatException nfe) { + min = -Double.MAX_VALUE; + max = Double.MAX_VALUE; + } + } + + protected void initDefaultValues(DataList data) { + initDefaultFrom(data); + initDefaultTo(data); + } + + protected void initDefaultFrom(DataList data) { + Data f = getData(data.getAll(), FIELD_LOWER); + + double from = getDefaultFrom(); + + try { + from = getDefaultValue(f); + } + catch (NumberFormatException nfe) { + // do nothing + } + + distancePanel.setFrom(from); + } + + + protected double getDefaultFrom() { + return min; + } + + + protected void initDefaultTo(DataList data) { + Data t = getData(data.getAll(), FIELD_UPPER); + + double to = getDefaultTo(); + + try { + to = getDefaultValue(t); + } + catch (NumberFormatException nfe) { + // do nothing + } + + distancePanel.setTo(to); + } + + + protected double getDefaultTo() { + return max; + } + + protected double getDefaultValue(Data data) + throws NumberFormatException + { + DataItem def = data.getDefault(); + String defValue = def != null ? def.getStringValue() : null; + + return Double.valueOf(defValue); + } + + /** Hook service to the listgrid with possible input values. */ + protected void setPickerDataSource() { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String river = ""; + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + // Try to find a "river" data item to set the source for the + // list grid. + String dataFilter = "locations"; + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + if (dl.getState().equals("state.minfo.river")) { + dataFilter = "measuringpoint"; + } + if (dl.getState().equals("state.winfo.river") || + dl.getState().equals("state.chart.river") || + dl.getState().equals("state.minfo.river")) { + for (int j = 0; j < dl.size(); j++) { + Data d = dl.get(j); + DataItem[] di = d.getItems(); + if (di != null && di.length == 1) { + river = d.getItems()[0].getStringValue(); + break; + } + } + } + } + } + + picker.getLocationTable().setDataSource(new DistanceInfoDataSource( + url, river, dataFilter)); + } + + @Override + protected Data[] getData() { + Data[] data = new Data[2]; + + data[0] = getDataFrom(); + data[1] = getDataTo(); + + return data; + } + + protected Data getDataFrom() { + String value = String.valueOf(distancePanel.getFrom()); + String field = FIELD_LOWER; + + DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData( + field, null, null, new DataItem[] { item }); + } + + protected Data getDataTo() { + String value = String.valueOf(distancePanel.getTo()); + String field = FIELD_UPPER; + + DataItem item = new DefaultDataItem(field, field, value); + return new DefaultData( + field, null, null, new DataItem[] { item }); + } + + @Override + public void onBlur(BlurEvent event) { + distancePanel.validateForm(); + } + + @Override + public void onCellClick(CellClickEvent e) { + Record record = e.getRecord(); + int ndx = e.getColNum(); + String from = record.getAttribute("from"); + try { + double value = Double.valueOf(from); + switch (ndx) { + case 0: distancePanel.setFrom(value); break; + case 1: distancePanel.setTo(value); break; + } + } + catch(NumberFormatException nfe) { + SC.warn(MSG.wrongFormat()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadEpochPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,277 @@ +package de.intevation.flys.client.client.ui.minfo; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.services.SedimentLoadInfoService; +import de.intevation.flys.client.client.services.SedimentLoadInfoServiceAsync; +import de.intevation.flys.client.client.ui.AbstractUIProvider; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; +import de.intevation.flys.client.shared.model.SedimentLoadInfoRecord; + + +public class SedLoadEpochPanel +extends AbstractUIProvider +{ + protected SedimentLoadInfoServiceAsync sedLoadInfoService = + GWT.create(SedimentLoadInfoService.class); + + protected ListGrid elements; + private TextItem start; + private TextItem end; + private ListGrid sedLoadTable; + + public Canvas createWidget(DataList data) { + HLayout input = new HLayout(); + VLayout root = new VLayout(); + VLayout grid = new VLayout(); + VLayout intFields = new VLayout(); + Button add = new Button(MSG.add_date()); + elements = new ListGrid(); + + Label title = new Label(data.get(0).getDescription()); + title.setHeight("25px"); + + DynamicForm form = new DynamicForm(); + form.setNumCols(4); + start = new TextItem(MSG.from()); + start.setWidth(60); + start.setValidators(new IsIntegerValidator()); + end = new TextItem(MSG.to()); + end.setWidth(60); + end.setValidators(new IsIntegerValidator()); + form.setFields(start, end); + add.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent ce) { + String v1 = start.getValueAsString(); + String v2 = end.getValueAsString(); + //TODO: better validation. + if (v1 == null || v2 == null) { + return; + } + try { + int v1i = Integer.parseInt(v1); + int v2i = Integer.parseInt(v2); + } + catch(NumberFormatException nfe) { + return; + } + Record r = new Record(); + r.setAttribute("from", v1); + r.setAttribute("to", v2); + elements.addData(r); + } + }); + + Label sel = new Label(MSG.select()); + sel.setHeight(25); + elements.setWidth(185); + elements.setHeight(120); + elements.setShowHeaderContextMenu(false); + elements.setCanReorderFields(false); + elements.setCanSort(false); + elements.setCanEdit(false); + ListGridField from = new ListGridField("from", MSG.from()); + ListGridField to = new ListGridField("to", MSG.to()); + from.setWidth(70); + to.setWidth(70); + + final ListGridField removeField = + new ListGridField("_removeRecord", "Remove Record"){{ + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; + + elements.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + event.getViewer().removeData(event.getRecord()); + } + }); + + elements.setFields(from, to, removeField); + + intFields.addMember(form); + intFields.addMember(add); + grid.addMember(sel); + grid.addMember(elements); + input.addMember(intFields); + input.addMember(grid); + root.addMember(title); + root.addMember(input); + + return root; + } + + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + layout.setWidth("400px"); + VLayout vLayout = new VLayout(); + vLayout.setWidth(130); + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + label.setHeight(25); + + List<Data> items = dataList.getAll(); + Data str = getData(items, "epochs"); + DataItem[] strItems = str.getItems(); + + String[] pairs = strItems[0].getLabel().split(";"); + for (int i = 0; i < pairs.length; i++) { + String[] vals = pairs[i].split(","); + Label dateLabel = new Label(vals[0] + " - " + vals[1]); + dateLabel.setHeight(20); + vLayout.addMember(dateLabel); + } + Canvas back = getBackButton(dataList.getState()); + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + @Override + public Canvas create(DataList data) { + VLayout layout = new VLayout(); + Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(data); + + layout.addMember(widget); + layout.addMember(submit); + + fetchSedimentLoadData(); + + return layout; + } + + private Canvas createHelper() { + sedLoadTable = new ListGrid(); + sedLoadTable.setShowHeaderContextMenu(false); + sedLoadTable.setWidth100(); + sedLoadTable.setShowRecordComponents(true); + sedLoadTable.setShowRecordComponentsByCell(true); + sedLoadTable.setHeight100(); + sedLoadTable.setEmptyMessage(MSG.empty_table()); + sedLoadTable.setCanReorderFields(false); + + ListGridField date = new ListGridField("date", MSG.year()); + date.setType(ListGridFieldType.TEXT); + date.setWidth(100); + + ListGridField descr = + new ListGridField("description", MSG.description()); + descr.setType(ListGridFieldType.TEXT); + descr.setWidth("*"); + + sedLoadTable.setFields(date, descr); + return sedLoadTable; + } + + @Override + protected Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + ListGridRecord[] lgr = elements.getRecords(); + if (lgr.length == 0) { + return new Data[0]; + } + String d = ""; + for (int i = 0; i < lgr.length; i++) { + Record r = (Record) lgr[i]; + d += r.getAttribute("from") + "," + r.getAttribute("to"); + d += ";"; + } + + DataItem item = new DefaultDataItem("epochs", null, d); + data.add(new DefaultData( + "epochs", + null, + null, + new DataItem[] { item })); + return data.toArray(new Data[data.size()]); + } + + protected void fetchSedimentLoadData() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + double[] km = artifact.getArtifactDescription().getKMRange(); + String river = artifact.getArtifactDescription().getRiver(); + + sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], + new AsyncCallback<SedimentLoadInfoObject[]>() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve sediment load informations."); + SC.warn(caught.getMessage()); + } + + public void onSuccess(SedimentLoadInfoObject[] sedLoad) { + int num = sedLoad != null ? sedLoad.length :0; + GWT.log("Recieved " + num + " sediment load informations."); + + if (num == 0) { + return; + } + + addSedimentLoadInfo(sedLoad); + } + } + ); + } + + + protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { + for(SedimentLoadInfoObject sl: sedLoad) { + SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); + sedLoadTable.addData(rec); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadOffEpochPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,187 @@ +package de.intevation.flys.client.client.ui.minfo; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionAppearance; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.services.SedimentLoadInfoService; +import de.intevation.flys.client.client.services.SedimentLoadInfoServiceAsync; +import de.intevation.flys.client.client.ui.PeriodPanel; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; +import de.intevation.flys.client.shared.model.SedimentLoadInfoRecord; + + +public class SedLoadOffEpochPanel +extends PeriodPanel +{ + protected SedimentLoadInfoServiceAsync sedLoadInfoService = + GWT.create(SedimentLoadInfoService.class); + + private ListGrid sedLoadTable; + + public Canvas createWidget(DataList data) { + VLayout root = new VLayout(); + + Label title = new Label(data.get(0).getDescription()); + title.setHeight("25px"); + + root.addMember(title); + + return root; + } + + @Override + public Canvas createOld(DataList dataList) { + HLayout layout = new HLayout(); + layout.setWidth("400px"); + VLayout vLayout = new VLayout(); + vLayout.setWidth(130); + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + label.setHeight(25); + + List<Data> items = dataList.getAll(); + Data str = getData(items, "epochs"); + DataItem[] strItems = str.getItems(); + + String[] pairs = strItems[0].getLabel().split(";"); + for (int i = 0; i < pairs.length; i++) { + String[] vals = pairs[i].split(","); + Label dateLabel = new Label(vals[0] + " - " + vals[1]); + dateLabel.setHeight(20); + vLayout.addMember(dateLabel); + } + Canvas back = getBackButton(dataList.getState()); + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + @Override + public Canvas create(DataList data) { + VLayout layout = new VLayout(); + Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(data); + + layout.addMember(widget); + layout.addMember(submit); + + fetchSedimentLoadData(); + + return layout; + } + + protected Canvas createHelper() { + sedLoadTable = new ListGrid(); + sedLoadTable.setShowHeaderContextMenu(false); + sedLoadTable.setWidth100(); + sedLoadTable.setShowRecordComponents(true); + sedLoadTable.setShowRecordComponentsByCell(true); + sedLoadTable.setHeight100(); + sedLoadTable.setEmptyMessage(MSG.empty_table()); + sedLoadTable.setCanReorderFields(false); + sedLoadTable.setSelectionAppearance(SelectionAppearance.CHECKBOX); + + ListGridField date = new ListGridField("date", MSG.year()); + date.setType(ListGridFieldType.TEXT); + date.setWidth(100); + + ListGridField descr = + new ListGridField("description", MSG.description()); + descr.setType(ListGridFieldType.TEXT); + descr.setWidth("*"); + + sedLoadTable.setFields(date, descr); + return sedLoadTable; + } + + @Override + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + ListGridRecord[] lgr = sedLoadTable.getSelectedRecords(); + if (lgr.length == 0) { + return new Data[0]; + } + String d = ""; + for (int i = 0; i < lgr.length; i++) { + Record r = (Record) lgr[i]; + String date = r.getAttribute("date"); + String[] range = date.split(" - "); + d += range[0] + "," + range[1]; + d += ";"; + } + DataItem item = new DefaultDataItem("epochs", null, d); + data.add(new DefaultData( + "epochs", + null, + null, + new DataItem[] { item })); + return data.toArray(new Data[data.size()]); + } + + protected void fetchSedimentLoadData() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + double[] km = artifact.getArtifactDescription().getKMRange(); + String river = artifact.getArtifactDescription().getRiver(); + + sedLoadInfoService.getSedimentLoadInfo(locale, river, "epoch", km[0], km[1], + new AsyncCallback<SedimentLoadInfoObject[]>() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve sediment load informations."); + SC.warn(caught.getMessage()); + } + + public void onSuccess(SedimentLoadInfoObject[] sedLoad) { + int num = sedLoad != null ? sedLoad.length :0; + GWT.log("Recieved " + num + " sediment load informations."); + + if (num == 0) { + return; + } + + addSedimentLoadInfo(sedLoad); + } + } + ); + } + + + protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { + for(SedimentLoadInfoObject sl: sedLoad) { + SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); + sedLoadTable.addData(rec); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadPeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,230 @@ +package de.intevation.flys.client.client.ui.minfo; + +import java.util.ArrayList; +import java.util.List; + +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.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.services.SedimentLoadInfoService; +import de.intevation.flys.client.client.services.SedimentLoadInfoServiceAsync; +import de.intevation.flys.client.client.ui.AbstractUIProvider; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; +import de.intevation.flys.client.shared.model.SedimentLoadInfoRecord; + + +public class SedLoadPeriodPanel +extends AbstractUIProvider +{ + protected SedimentLoadInfoServiceAsync sedLoadInfoService = + GWT.create(SedimentLoadInfoService.class); + + private TextItem start; + private TextItem end; + + private ListGrid sedLoadTable; + + public SedLoadPeriodPanel () { + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + Data start = getData(items, "start"); + Data end = getData(items, "end"); + DataItem[] startItem = start.getItems(); + DataItem[] endItem = end.getItems(); + + String v1 = startItem[0].getStringValue(); + String v2 = endItem[0].getStringValue(); + + int v1i = 0; + int v2i = 0; + try { + v1i = Integer.parseInt(v1); + v2i = Integer.parseInt(v2); + } + catch (NumberFormatException nfe) { + GWT.log(nfe.toString()); + } + Label old = new Label(v1i + " - " + v2i); + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + + return layout; + } + + @Override + public Canvas create(DataList data) { + VLayout layout = new VLayout(); + + Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + Canvas submit = getNextButton(); + Canvas widget = createWidget(data); + + layout.addMember(widget); + layout.addMember(submit); + + fetchSedimentLoadData(); + + return layout; + } + + private Canvas createHelper() { + sedLoadTable = new ListGrid(); + sedLoadTable.setShowHeaderContextMenu(false); + sedLoadTable.setWidth100(); + sedLoadTable.setShowRecordComponents(true); + sedLoadTable.setShowRecordComponentsByCell(true); + sedLoadTable.setHeight100(); + sedLoadTable.setEmptyMessage(MSG.empty_table()); + sedLoadTable.setCanReorderFields(false); + + ListGridField date = new ListGridField("date", MSG.year()); + date.setType(ListGridFieldType.TEXT); + date.setWidth(100); + + ListGridField descr = + new ListGridField("description", MSG.description()); + descr.setType(ListGridFieldType.TEXT); + descr.setWidth("*"); + + sedLoadTable.setFields(date, descr); + return sedLoadTable; + } + + public Canvas createWidget(DataList data) { + VLayout layout = new VLayout(); + + Label title = new Label(data.get(0).getDescription()); + title.setHeight("25px"); + + DynamicForm form = new DynamicForm(); + form.setNumCols(4); + start = new TextItem(MSG.from()); + start.setValidators(new IsIntegerValidator()); + end = new TextItem(MSG.to()); + end.setValidators(new IsIntegerValidator()); + form.setFields(start, end); +// inputPanel.setToTitle(MSG.to()); +// inputPanel.setFromTitle(MSG.from()); +// inputPanel.setShowTitle(false); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + @Override + protected Data[] getData() { + int v1; + int v2; + try { + v1 = Integer.parseInt(start.getValueAsString()); + v2 = Integer.parseInt(end.getValueAsString()); + } + catch(NumberFormatException nfe) { + // warn the user... + return new Data[0]; + } + if (validateRange(v1, v2)) { + List<Data> data = new ArrayList<Data>(); + + DataItem startItem = new DefaultDataItem("start", "start", start.getValueAsString()); + DataItem endItem = new DefaultDataItem("end", "end", end.getValueAsString()); + data.add(new DefaultData( + "start", + null, + null, + new DataItem[] { startItem })); + data.add(new DefaultData( + "end", + null, + null, + new DataItem[] { endItem })); + + return data.toArray(new Data[data.size()]); + } + return new Data[0]; + } + + protected boolean validateRange(int v1, int v2) { + // TODO: Set useful years for validation. Current range is between start + // of gregorian calendar and a year in the future... + if ((v1 > 1582 && v1 < 2100) + && (v2 > 1582 && v2 < 2100)) { + return true; + } + return false; + } + + protected void fetchSedimentLoadData() { + Config config = Config.getInstance(); + String locale = config.getLocale (); + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + double[] km = artifact.getArtifactDescription().getKMRange(); + String river = artifact.getArtifactDescription().getRiver(); + + sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], + new AsyncCallback<SedimentLoadInfoObject[]>() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve sediment load informations."); + SC.warn(caught.getMessage()); + } + + public void onSuccess(SedimentLoadInfoObject[] sedLoad) { + int num = sedLoad != null ? sedLoad.length :0; + GWT.log("Recieved " + num + " sediment load informations."); + + if (num == 0) { + return; + } + + addSedimentLoadInfo(sedLoad); + } + } + ); + } + + + protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { + for(SedimentLoadInfoObject sl: sedLoad) { + SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); + sedLoadTable.addData(rec); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/range/DischargeInfoDataSource.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,42 @@ +package de.intevation.flys.client.client.ui.range; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.data.DataSource; +import com.smartgwt.client.data.DataSourceField; +import com.smartgwt.client.types.DSDataFormat; +import com.smartgwt.client.types.FieldType; + +public class DischargeInfoDataSource extends DataSource { + + public static final String XPATH_DISCHARGE_DEFAULT = "/discharges/discharge"; + + + public DischargeInfoDataSource(String url, long gauge) { + setDataFormat(DSDataFormat.XML); + setRecordXPath(XPATH_DISCHARGE_DEFAULT); + + DataSourceField desc = new DataSourceField( + "description", FieldType.TEXT, "description"); + + DataSourceField start = new DataSourceField( + "start", FieldType.TEXT, "start"); + + DataSourceField end = new DataSourceField( + "end", FieldType.TEXT, "end"); + + setFields(desc, start, end); + setDataURL(getServiceURL(url, gauge)); + } + + + protected String getServiceURL(String server, long gauge) { + String url = GWT.getModuleBaseURL(); + url += "dischargeinfoxml"; + url += "?server=" + server; + url += "&gauge=" + String.valueOf(gauge); + + return url; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/range/DistanceInfoDataSource.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,53 @@ +package de.intevation.flys.client.client.ui.range; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.data.DataSource; +import com.smartgwt.client.data.DataSourceField; +import com.smartgwt.client.types.DSDataFormat; +import com.smartgwt.client.types.FieldType; + + +public class DistanceInfoDataSource extends DataSource { + + public static final String XPATH_DISTANCE_DEFAULT = "/distances/distance"; + + + public DistanceInfoDataSource(String url, String river, String filter) { + setDataFormat(DSDataFormat.XML); + setRecordXPath(XPATH_DISTANCE_DEFAULT); + + DataSourceField desc = new DataSourceField( + "description", FieldType.TEXT, "description"); + + DataSourceField from = new DataSourceField( + "from", FieldType.TEXT, "from"); + + DataSourceField to = new DataSourceField( + "to", FieldType.TEXT, "to"); + + DataSourceField side = new DataSourceField( + "riverside", FieldType.TEXT, "riverside"); + + DataSourceField top = new DataSourceField( + "top", FieldType.TEXT, "top"); + + DataSourceField bottom = new DataSourceField( + "bottom", FieldType.TEXT, "bottom"); + + setFields(desc, from, to, side, top, bottom); + setDataURL(getServiceURL(url, river, filter)); + } + + + protected String getServiceURL(String server, String river, String filter) { + String url = GWT.getModuleBaseURL(); + url += "distanceinfoxml"; + url += "?server=" + server; + url += "&river=" + river; + url += "&filter=" + filter; + + return url; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/range/LocationsTable.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,92 @@ +package de.intevation.flys.client.client.ui.range; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import com.smartgwt.client.widgets.grid.CellFormatter; + +import de.intevation.flys.client.client.FLYSConstants; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class LocationsTable extends ListGrid { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + + public LocationsTable() { + String baseUrl = GWT.getHostPageBaseURL(); + + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.SINGLE); + setSelectionType(SelectionStyle.SINGLE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MSG.empty_filter()); + setCanReorderFields(false); + + ListGridField addfrom = new ListGridField ("from", MSG.from()); + addfrom.setType(ListGridFieldType.ICON); + addfrom.setWidth(30); + addfrom.setCellIcon(baseUrl + MSG.markerGreen()); + + ListGridField addto = new ListGridField("to", MSG.to()); + addto.setType(ListGridFieldType.ICON); + addto.setWidth(30); + addto.setCellIcon(baseUrl + MSG.markerRed()); + + ListGridField ldescr = new ListGridField( + "description", MSG.description()); + ldescr.setType(ListGridFieldType.TEXT); + ldescr.setWidth("*"); + + ListGridField lside = new ListGridField("riverside", MSG.riverside()); + lside.setType(ListGridFieldType.TEXT); + lside.setWidth("12%"); + + ListGridField loc = new ListGridField("from", MSG.locations()); + loc.setType(ListGridFieldType.FLOAT); + loc.setCellFormatter(new CellFormatter() { + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum) { + if (value == null) return null; + try { + NumberFormat nf; + double v = Double.parseDouble((String)value); + nf = NumberFormat.getFormat("###0.00##"); + return nf.format(v); + } + catch (Exception e) { + return value.toString(); + } + } + } + ); + + loc.setWidth("12%"); + + ListGridField bottom = new ListGridField("bottom", MSG.bottom_edge()); + bottom.setType(ListGridFieldType.TEXT); + bottom.setWidth("10%"); + + ListGridField top = new ListGridField("top", MSG.top_edge()); + top.setType(ListGridFieldType.TEXT); + top.setWidth("10%"); + + setFields(addfrom, addto, ldescr, loc, lside, bottom, top); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/range/RangeTable.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,111 @@ +package de.intevation.flys.client.client.ui.range; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.CellFormatter; + +import de.intevation.flys.client.client.FLYSConstants; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class RangeTable extends ListGrid { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + + public RangeTable() { + String baseUrl = GWT.getHostPageBaseURL(); + + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.SINGLE); + setSelectionType(SelectionStyle.SINGLE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MESSAGES.empty_filter()); + setCanReorderFields(false); + + ListGridField addDistance = new ListGridField ("", ""); + addDistance.setType (ListGridFieldType.ICON); + addDistance.setWidth (20); + addDistance.setCellIcon(baseUrl + MESSAGES.markerGreen()); + + ListGridField ddescr = new ListGridField( + "description", MESSAGES.description()); + ddescr.setType(ListGridFieldType.TEXT); + ddescr.setWidth("*"); + ListGridField from = new ListGridField("from", MESSAGES.from()); + from.setType(ListGridFieldType.FLOAT); + from.setCellFormatter(new CellFormatter() { + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum) { + if (value == null) return null; + try { + NumberFormat nf; + double v = Double.parseDouble((String)value); + nf = NumberFormat.getFormat("###0.00##"); + return nf.format(v); + } + catch (Exception e) { + return value.toString(); + } + } + } + ); + + from.setWidth("12%"); + + ListGridField to = new ListGridField("to", MESSAGES.to()); + to.setType(ListGridFieldType.FLOAT); + to.setCellFormatter(new CellFormatter() { + public String format( + Object value, + ListGridRecord record, + int rowNum, int colNum) { + if (value == null) return null; + GWT.log((String)value); + try { + NumberFormat nf; + double v = Double.parseDouble((String)value); + nf = NumberFormat.getFormat("###0.00##"); + return nf.format(v); + } + catch (Exception e) { + return value.toString(); + } + } + } + ); + + to.setWidth("12%"); + + ListGridField dside = new ListGridField( + "riverside", MESSAGES.riverside()); + dside.setType(ListGridFieldType.TEXT); + dside.setWidth("12%"); + + ListGridField bottom = new ListGridField( + "bottom", MESSAGES.bottom_edge()); + bottom.setType(ListGridFieldType.TEXT); + bottom.setWidth("10%"); + + ListGridField top = new ListGridField("top", MESSAGES.top_edge()); + top.setType(ListGridFieldType.TEXT); + top.setWidth("10%"); + + setFields(addDistance, ddescr, from, to, dside, bottom, top); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/sq/SQCampaignChart.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,79 @@ +package de.intevation.flys.client.client.ui.sq; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONString; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.shared.model.Artifact; + + +public class SQCampaignChart extends VLayout { + + private final Artifact artifact; + + protected Img chartImg; + + public SQCampaignChart(Artifact artifact, ResizedHandler resizeHandler) { + super(); + + this.artifact = artifact; + this.chartImg = new Img(); + + addResizedHandler(resizeHandler); + setAlign(Alignment.CENTER); + } + + public void update() { + Config config = Config.getInstance(); + String locale = config.getLocale(); + + int hWidth = getWidth() - 12; + int hHeight = getHeight() - 12; + + if ((int) (hHeight * 4f / 3) < hWidth) { + hWidth = (int) (hHeight * 4f / 3); + } + else { + hHeight = (int) (hWidth * 3f / 4); + } + + String river = artifact.getArtifactDescription().getRiver(); + + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + JSONObject jextent = new JSONObject(); + JSONNumber jwidth = new JSONNumber(hWidth); + JSONNumber jheight = new JSONNumber(hHeight); + + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jextent.put("width", jwidth); + jextent.put("height", jheight); + jfilter.put("extent", jextent); + jfix.put("sq", jfilter); + String filter = jfix.toString(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "sq-km-chart"; + imgUrl += "?locale=" + locale; + imgUrl += "&filter=" + filter; + + if (chartImg != null && hasMember(chartImg)) { + chartImg.setWidth(hWidth); + chartImg.setHeight(hHeight); + chartImg.setSrc(imgUrl); + } + else { + chartImg = new Img(imgUrl, hWidth, hHeight); + addMember(chartImg); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/sq/SQMultiPeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,32 @@ +package de.intevation.flys.client.client.ui.sq; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; + +import de.intevation.flys.client.client.ui.MultiPeriodPanel; + + +/** + * This UIProvider creates helper panel for sq relation. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class SQMultiPeriodPanel extends MultiPeriodPanel implements + ResizedHandler { + protected SQCampaignChart chartContainer; + + public SQMultiPeriodPanel() { + } + + @Override + protected Canvas createHelper() { + chartContainer = new SQCampaignChart(artifact, this); + return chartContainer; + } + + @Override + public void onResized(ResizedEvent re) { + chartContainer.update(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/sq/SQPeriodPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,26 @@ +package de.intevation.flys.client.client.ui.sq; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; + +import de.intevation.flys.client.client.ui.PeriodPanel; + +public class SQPeriodPanel extends PeriodPanel implements ResizedHandler { + + private SQCampaignChart chartLayout; + + @Override + protected Canvas createHelper() { + GWT.log("Create new SQCampaignChart as Helper Widget"); + chartLayout = new SQCampaignChart(artifact, this); + return chartLayout; + } + + + @Override + public void onResized(ResizedEvent re) { + chartLayout.update(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeInfoPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,114 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.ui.Anchor; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.Label; + +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.GaugeInfo; + +public class GaugeInfoPanel extends VLayout { + + /** The message class that provides i18n strings.*/ + private FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** Application instance. */ + private FLYS flys; + + public GaugeInfoPanel(GaugeInfo gauge, FLYS flys) { + this.flys = flys; + setStyleName("gaugeinfopanel"); + + NumberFormat nf = NumberFormat.getDecimalFormat(); + + VLayout grid = new VLayout(); + HLayout line1 = new HLayout(); + + Double minw = gauge.getMinW(); + Double maxw = gauge.getMaxW(); + if (minw != null && maxw != null) { + Label key = new Label(MSG.wq_value_q()); + Label value = new Label(nf.format(minw) + + " - " + nf.format(maxw)); + key.setWidth(150); + line1.addMember(key); + line1.addMember(value); + } + + HLayout line2 = new HLayout(); + Double minq = gauge.getMinQ(); + Double maxq = gauge.getMaxQ(); + if (minq != null && maxq != null) { + Label key = new Label(MSG.wq_value_w()); + Label value = new Label( nf.format(minq) + + " - " + nf.format(maxq)); + key.setWidth(150); + line2.addMember(key); + line2.addMember(value); + } + + HLayout line3 = new HLayout(); + Double aeo = gauge.getAeo(); + if (aeo != null) { + Label key = new Label("AEO [km²]"); + Label value = new Label(nf.format(aeo)); + key.setWidth(150); + line3.addMember(key); + line3.addMember(value); + } + + HLayout line4 = new HLayout(); + Double datum = gauge.getDatum(); + if (datum != null) { + Label key = new Label(MSG.gauge_zero() + " [" + + gauge.getWstUnit() + "]"); + Label value = new Label(nf.format(datum)); + key.setWidth(150); + line4.addMember(key); + line4.addMember(value); + } + + HLayout line5 = new HLayout(); + line5.addMember(new GaugeMainValueAnchor(flys, gauge)); + + grid.addMember(line1); + grid.addMember(line2); + grid.addMember(line3); + grid.addMember(line4); + grid.addMember(line5); + addMember(grid); + } + + + /** + * Clickable anchor that asks application to show window with + * main values for gauge. + */ + class GaugeMainValueAnchor extends Anchor implements ClickHandler { + + private FLYS flys; + private GaugeInfo gauge; + + public GaugeMainValueAnchor(FLYS flys, GaugeInfo gauge) { + super(MSG.show_mainvalues()); + this.flys = flys; + this.gauge = gauge; + this.setHeight("5"); + + addClickHandler(this); + } + + @Override + public void onClick(ClickEvent ev) { + GWT.log("GaugeMainValueAnchor - onClick " + gauge.getRiverName() + + " " + gauge.getOfficialNumber()); + flys.newGaugeMainValueTable(gauge); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,320 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.WidgetCanvas; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; + +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.GaugeInfo; +import de.intevation.flys.client.shared.model.RiverInfo; + + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class GaugeListGrid extends InfoListGrid implements RecordClickHandler { + + private static final int ABFLUSSTAFEL_COLUMN = 6; + + public GaugeListGrid(FLYS flys) { + super(flys); + //TODO i18n!!! + ListGridField nfield = new ListGridField("name", "Pegel"); + ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60); + ListGridField efield = new ListGridField("kmend", "Ende [km]", 60); + ListGridField stfield = new ListGridField("station", "Station [km]"); + ListGridField lfield = new ListGridField("link", "Info"); + lfield.setType(ListGridFieldType.LINK); + ListGridField cfield = new ListGridField("curvelink", MSG.gauge_curve_link()); + cfield.addRecordClickHandler(this); + + this.setFields(nfield, sfield, efield, stfield, lfield, cfield); + } + + public void setRiverInfo(RiverInfo riverinfo) { + List<GaugeInfo> gauges = riverinfo.getGauges(); + + if (gauges != null && !gauges.isEmpty()) { + + ArrayList<GaugeInfo> emptygauges = new ArrayList<GaugeInfo>(); + + if (!riverinfo.isKmUp()) { + for (GaugeInfo gauge : gauges) { + addGauge(gauge, emptygauges); + } + } + else { + for (int i = gauges.size()-1; i >= 0; i--) { + GaugeInfo gauge = gauges.get(i); + addGauge(gauge, emptygauges); + } + } + + // put empty gauges to the end + for (GaugeInfo gauge : emptygauges) { + addGauge(gauge); + } + } + } + + private void addGauge(GaugeInfo gauge, List<GaugeInfo> empty) { + if (gauge.getKmStart() != null && gauge.getKmEnd() != null) { + addGauge(gauge); + } + else { + empty.add(gauge); + } + } + + private void addGauge(GaugeInfo gauge) { + this.addData(new GaugeRecord(gauge)); + } + + public void open() { + ArrayList<Double> locations = new ArrayList<Double>(); + + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + String state = dl.getState(); + GWT.log("GaugeListGrid - open " + state); + if (state.equals("state.winfo.location_distance")) { + Double ldfrom = null; + Double ldto = null; + + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue()); + if (label.equals("ld_from")) { + ldfrom = getDoubleValue(d); + } + else if (label.equals("ld_to")) { + ldto = getDoubleValue(d); + } + else if (label.equals("ld_locations")) { + getLocationsFromData(locations, d); + openOnLocations(locations); + return; + } + } + if (ldfrom != null) { + openOnDistance(ldfrom, ldto); + return; + } + } + else if(state.equals("state.winfo.distance_only") || + state.equals("state.winfo.distance")) { + Double ldfrom = null; + Double ldto = null; + + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue()); + if (label.equals("ld_from")) { + ldfrom = getDoubleValue(d); + } + else if (label.equals("ld_to")) { + ldto = getDoubleValue(d); + } + } + + if (ldfrom != null) { + openOnDistance(ldfrom, ldto); + return; + } + } + else if (state.equals("state.winfo.location")) { + getLocations("ld_locations", locations, dl); + openOnLocations(locations); + return; + } + else if (state.equals("state.winfo.reference.curve.input.start")) { + getLocations("reference_startpoint", locations, dl); + } + else if (state.equals("state.winfo.reference.curve.input.end")) { + getLocations("reference_endpoint", locations, dl); + } + else if (state.equals("state.winfo.historicalq.reference_gauge")) { + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + if (label.equals("reference_gauge")) { + String tmp = d.getStringValue(); + if (tmp != null) { + Long gaugereference = Long.valueOf(tmp); + if (gaugereference != null) { + openOnReference(gaugereference); + return; + } + } + } + } + } + } + } + if (!locations.isEmpty()) { + openOnLocations(locations); + } + else { + openAll(); + } + } + + void getLocations(String labelname, List<Double> locations, DataList dl) { + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + if (label.equals(labelname)) { + getLocationsFromData(locations, d); + } + } + } + + void getLocationsFromData(List<Double> locations, Data data) { + DataItem[] items = data.getItems(); + for (int k = 0; k < items.length; k++) { + String tmp = items[k].getStringValue(); + GWT.log("GaugeListGrid - getLocationsFromData " + tmp); + if (tmp != null) { + if (tmp.contains(" ")) { + // string contains several values ... + String[] values = tmp.split(" "); + for(int i=0; i < values.length; i++) { + Double value = Double.valueOf(values[i]); + if (value != null) { + locations.add(value); + } + } + } + else { + Double value = Double.valueOf(tmp); + if (value != null) { + locations.add(value); + } + } + } + } + } + + public void openOnReference(Long number) { + GWT.log("GaugeListGrid - openOnReference " + number); + for (ListGridRecord record: this.getRecords()) { + GaugeRecord item = (GaugeRecord)record; + if (item.getOfficialNumber().equals(number)) { + expandRecord(item); + } + else { + collapseRecord(item); + } + } + } + + public void openOnDistance(Double start, Double end) { + GWT.log("GaugeListGrid - openOnDistance " + start + " " + end); + + for (ListGridRecord record: this.getRecords()) { + GaugeRecord item = (GaugeRecord)record; + if (end == null && item.getKmStart() != null) { + if (item.getKmStart() >= start) { + expandRecord(item); + } + else { + collapseRecord(item); + } + } + else if (item.getKmStart() != null && item.getKmEnd() != null) { + // as getStart()/getEnd() return Double objects, they can be null and + // can cause NPEs when comparing with double... strange... + GWT.log("GaugeListGrid - openOnDistance item " + item.getKmStart() + " " + item.getKmEnd()); + if ((start >= item.getKmStart() && start <= item.getKmEnd()) || + (end >= item.getKmStart() && end <= item.getKmEnd()) || + (start <= item.getKmStart() && end >= item.getKmEnd())) { + expandRecord(item); + } + else { + collapseRecord(item); + } + } + else { + collapseRecord(item); + } + } + } + + /** + * Open Gauge entry if a location fits to the gauge. + */ + public void openOnLocations(List<Double> locations) { + GWT.log("GaugeListGrid - openOnLocations " + locations); + + if (locations == null || locations.isEmpty()) { + return; + } + + for (ListGridRecord record: this.getRecords()) { + GaugeRecord item = (GaugeRecord)record; + boolean isset = false; + for (Double location: locations) { + if (locations == null) { + continue; + } + + Double start = item.getKmStart(); + Double end = item.getKmEnd(); + if (start == null || end == null) { + // should not occur but avoid NullPointerException + continue; + } + + if (location >= start && location <= end) { + isset = true; + break; + } + } + if (isset) { + expandRecord(item); + } + else { + collapseRecord(item); + } + } + } + + @Override + protected Canvas getExpandPanel(ListGridRecord record) { + GaugeRecord item = (GaugeRecord)record; + return new WidgetCanvas(new GaugeInfoPanel(item, flys)); + } + + @Override + public void onRecordClick(RecordClickEvent event) { + GaugeRecord gauge = (GaugeRecord)event.getRecord(); + flys.newGaugeDischargeCurve(gauge.getRiverName(), + gauge.getOfficialNumber()); + } + + @Override + public String getCellCSSText(ListGridRecord record, int rowNum, + int colNum) { + if (colNum == ABFLUSSTAFEL_COLUMN) { + // display the ablfusstafel cell like a link + return "text-decoration: underline; color: #0000EE; cursor: pointer;"; + } + else { + return super.getCellCSSText(record, rowNum, colNum); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugePanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,53 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.shared.model.RiverInfo; + + +/** + * The GaugePanel is intended to be used within a SectionStackSection + * + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class GaugePanel extends InfoPanel { + + /** + * GaugePanel loads the GaugeInfo from the RiverInfoService and + * displays them in a tree underneath a RiverInfoPanel + * + * @param flys The FLYS object + */ + public GaugePanel(FLYS flys) { + super(new GaugeListGrid(flys)); + } + + + @Override + public String getSectionTitle() { + return MSG.gaugePanelTitle(); + } + + /** + * Loads the river info and renders it afterwards. + */ + public void refresh() { + contract(); + + riverInfoService.getGauges(this.river, new AsyncCallback<RiverInfo>() { + @Override + public void onFailure(Throwable e) { + GWT.log("Could not load the river info." + e); + } + + @Override + public void onSuccess(RiverInfo riverinfo) { + GWT.log("Loaded river info"); + render(riverinfo); + expand(); + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,165 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.GaugeInfo; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class GaugeRecord extends ListGridRecord implements GaugeInfo { + + /** The message class that provides i18n strings.*/ + private FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public GaugeRecord(GaugeInfo gauge) { + setCanExpand(true); + Long number = gauge.getOfficialNumber(); + String url = number != null ? + MSG.gauge_url() + number : + MSG.gauge_url(); + setLink(url); + setLinkText(MSG.gauge_info_link()); + setName(gauge.getName()); + setKmStart(gauge.getKmStart()); + setKmEnd(gauge.getKmEnd()); + setMinQ(gauge.getMinQ()); + setMaxQ(gauge.getMaxQ()); + setMinW(gauge.getMinW()); + setMaxW(gauge.getMaxW()); + setAeo(gauge.getAeo()); + setDatum(gauge.getDatum()); + setKmUp(gauge.isKmUp()); + setOfficialNumber(gauge.getOfficialNumber()); + setRiverName(gauge.getRiverName()); + setStation(gauge.getStation()); + setWstUnit(gauge.getWstUnit()); + setCurveLink(MSG.gauge_curve_link()); + } + + private void setCurveLink(String value) { + this.setAttribute("curvelink", value); + } + + private void setLink(String url) { + this.setAttribute("link", url); + } + + public String getLink() { + return this.getAttributeAsString("link"); + } + + public String getName() { + return this.getAttributeAsString("name"); + } + + private void setName(String value) { + this.setAttribute("name", value); + } + + public Double getKmStart() { + return this.getAttributeAsDouble("kmstart"); + } + + private void setKmStart(Double value) { + this.setAttribute("kmstart", value); + } + + public Double getKmEnd() { + return this.getAttributeAsDouble("kmend"); + } + + private void setKmEnd(Double value) { + this.setAttribute("kmend", value); + } + + public Double getMinQ() { + return this.getAttributeAsDouble("minq"); + } + + private void setMinQ(Double value) { + this.setAttribute("minq", value); + } + + public Double getMaxQ() { + return this.getAttributeAsDouble("maxq"); + } + + private void setMaxQ(Double value) { + this.setAttribute("maxq", value); + } + + public Double getMinW() { + return this.getAttributeAsDouble("minw"); + } + + private void setMinW(Double value) { + this.setAttribute("minw", value); + } + + public Double getMaxW() { + return this.getAttributeAsDouble("maxw"); + } + + private void setMaxW(Double value) { + this.setAttribute("maxw", value); + } + + public Double getDatum() { + return this.getAttributeAsDouble("datum"); + } + + private void setDatum(Double value) { + this.setAttribute("datum", value); + } + + public Double getAeo() { + return this.getAttributeAsDouble("aeo"); + } + + private void setAeo(Double value) { + this.setAttribute("aeo", value); + } + + public boolean isKmUp() { + return this.getAttributeAsBoolean("kmup"); + } + + private void setKmUp(boolean value) { + this.setAttribute("kmup", value); + } + + public Double getStation() { + return this.getAttributeAsDouble("station"); + } + + private void setStation(Double value) { + this.setAttribute("station", value); + } + + public String getWstUnit() { + return this.getAttributeAsString("wstunit"); + } + + private void setWstUnit(String value) { + this.setAttribute("wstunit", value); + } + + public Long getOfficialNumber() { + return this.getAttributeAsLong("officialnumber"); + } + + private void setOfficialNumber(Long number) { + this.setAttribute("officialnumber", number); + } + + public String getRiverName() { + return this.getAttributeAsString("rivername"); + } + + private void setRiverName(String rivername) { + this.setAttribute("rivername", rivername); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/InfoListGrid.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,67 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.RiverInfo; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public abstract class InfoListGrid extends ListGrid { + + protected FLYS flys; + protected DataList[] data; + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + + public InfoListGrid(FLYS flys) { + super(); + this.flys = flys; + this.setCanExpandRecords(true); + this.setCanExpandMultipleRecords(true); + } + + public void openAll() { + GWT.log("InfoListGrid - openAll"); + for (ListGridRecord record: this.getRecords()) { + expandRecord(record); + } + } + + public void setData(DataList[] data) { + GWT.log("InfoListGrid - setData"); + this.data = data; + this.open(); + } + + protected Double getDoubleValue(Data d) { + String tmp = d.getStringValue(); + if (tmp != null) { + return Double.valueOf(tmp); + } + return null; + } + + @Override + protected Canvas getExpansionComponent(ListGridRecord record) { + VLayout layout = new VLayout(); + layout.setPadding(5); + layout.addMember(this.getExpandPanel(record)); + return layout; + } + + public abstract void open(); + + public abstract void setRiverInfo(RiverInfo riverinfo); + + protected abstract Canvas getExpandPanel(ListGridRecord record); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/InfoPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,140 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.layout.VLayout; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.RiverInfoService; +import de.intevation.flys.client.client.services.RiverInfoServiceAsync; +import de.intevation.flys.client.client.ui.RiverInfoPanel; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.RiverInfo; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public abstract class InfoPanel extends VLayout { + + /** SectionStackSection where this InfoPanel belongs in*/ + protected SectionStackSection section; + + /** Name of the river */ + protected String river; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected RiverInfoServiceAsync riverInfoService = GWT.create(RiverInfoService.class); + + /** Panel to show the info about the river */ + protected RiverInfoPanel riverinfopanel; + + protected InfoListGrid listgrid; + + public final static String SECTION_ID = "InfoPanelSection"; + + public InfoPanel(InfoListGrid listgrid) { + SectionStackSection section = new SectionStackSection(); + section.setExpanded(false); + section.setTitle(getSectionTitle()); + section.setName(SECTION_ID); + section.setID(SECTION_ID); + + setOverflow(Overflow.HIDDEN); + setStyleName("infopanel"); + + section.setHidden(true); + section.setItems(this); + this.section = section; + this.listgrid = listgrid; + this.addMember(listgrid); + } + + /** + * Sets and loads the river data if river is not the current set river. + */ + public void setRiver(String river) { + if (!river.equals(this.river)) { + this.river = river; + this.refresh(); + } + } + + /** + * Sets the data and closes not corresponding folds in the gauge tree. + */ + public void setData(DataList[] data) { + this.listgrid.setData(data); + } + + protected void render(RiverInfo riverinfo) { + if (this.riverinfopanel == null) { + this.riverinfopanel = new RiverInfoPanel(riverinfo); + + this.addMember(this.riverinfopanel, 0); + } + else { + riverinfopanel.setRiverInfo(riverinfo); + } + this.listgrid.setRiverInfo(riverinfo); + } + + /** + * Hide the section stack section. + */ + @Override + public void hide() { + GWT.log("InfoPanel - hide"); + this.section.setHidden(true); + } + + /** + * Show the section stack section. + */ + @Override + public void show() { + GWT.log("InfoPanel - show"); + this.section.setHidden(false); + } + + @Override + public void addMember(Canvas component) { + super.addMember(component); + expand(); + } + + @Override + public void removeMembers(Canvas[] components) { + super.removeMembers(components); + contract(); + } + + public SectionStackSection getSection() { + return this.section; + } + + protected void removeAllMembers() { + removeMembers(getMembers()); + } + + /** + * Expands the gauge section. + */ + public void expand() { + section.setExpanded(true); + } + + /** + * Contracts/shrinks the expanded gauge section. + */ + public void contract() { + section.setExpanded(false); + } + + protected abstract void refresh(); + + protected abstract String getSectionTitle(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationInfoPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,60 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import java.util.Date; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; +import com.google.gwt.user.client.ui.Grid; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.MeasurementStation; + +public class MeasurementStationInfoPanel extends VLayout { + + /** The message class that provides i18n strings.*/ + private FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public MeasurementStationInfoPanel(MeasurementStation station) { + setStyleName("infopanel"); + setWidth100(); + + Grid grid = new Grid(5, 2); + + String type = station.getMeasurementType(); + if (type != null) { + grid.setText(0, 0, MSG.measurement_station_type()); + grid.setText(0, 1, type); + } + + String riverside = station.getRiverSide(); + if (riverside != null) { + grid.setText(1, 0, MSG.riverside()); + grid.setText(1, 1, riverside); + } + + String gaugename = station.getGaugeName(); + if (gaugename != null) { + grid.setText(2, 0, MSG.measurement_station_gauge_name()); + grid.setText(2, 1, gaugename); + } + + DateTimeFormat df = DateTimeFormat.getFormat( + PredefinedFormat.DATE_MEDIUM); + + Date starttime = station.getStartTime(); + if (starttime != null) { + grid.setText(3, 0, MSG.measurement_station_start_time()); + grid.setText(3, 1, df.format(starttime)); + } + + String moperator = station.getOperator(); + if (moperator != null) { + grid.setText(4, 0, MSG.measurement_station_operator()); + grid.setText(4, 1, moperator); + } + + addMember(grid); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,105 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.WidgetCanvas; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; + +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.shared.model.MeasurementStation; +import de.intevation.flys.client.shared.model.RiverInfo; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class MeasurementStationListGrid +extends InfoListGrid +implements RecordClickHandler { + + public MeasurementStationListGrid(FLYS flys) { + super(flys); + ListGridField nfield = new ListGridField("name", "Messtelle"); + ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60); + ListGridField efield = new ListGridField("kmend", "Ende [km]", 60); + ListGridField stfield = new ListGridField("station", "Station [km]"); + ListGridField lfield = new ListGridField("link", "Link"); + lfield.setType(ListGridFieldType.LINK); + ListGridField cfield = new ListGridField("curvelink", "SQ"); + cfield.addRecordClickHandler(this); + this.setFields(nfield, sfield, efield, stfield, lfield, cfield); + } + + /** + * Resets the items of the tree. + * If the list of gauges is empty or null the tree will be empty. + */ + @Override + public void setRiverInfo(RiverInfo riverinfo) { + List<MeasurementStation> stations = riverinfo.getMeasurementStations(); + GWT.log("MeasurmentStationListGrid - setRiverInfo " + stations); + + if (stations != null && !stations.isEmpty()) { + + ArrayList<MeasurementStation> emptystations = + new ArrayList<MeasurementStation>(); + + if (!riverinfo.isKmUp()) { + for (MeasurementStation station : stations) { + addStation(station, emptystations); + } + } + else { + for (int i = stations.size()-1; i >= 0; i--) { + MeasurementStation station = stations.get(i); + addStation(station, emptystations); + } + } + + // put empty stations to the end + for (MeasurementStation station : emptystations) { + addStation(station); + } + } + } + + private void addStation(MeasurementStation station, + List<MeasurementStation> empty) { + if (station.getKmStart() != null && station.getKmEnd() != null) { + addStation(station); + } + else { + empty.add(station); + } + } + + private void addStation(MeasurementStation station) { + ListGridRecord record = new MeasurementStationRecord(station); + this.addData(record); + } + + @Override + public void open() { + } + + @Override + protected Canvas getExpandPanel(ListGridRecord record) { + MeasurementStationRecord station = (MeasurementStationRecord)record; + return new WidgetCanvas(new MeasurementStationInfoPanel(station)); + } + + @Override + public void onRecordClick(RecordClickEvent event) { + MeasurementStationRecord station = + (MeasurementStationRecord)event.getRecord(); + flys.newSQRelation(station.getRiverName(), station.getID()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationPanel.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,56 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import de.intevation.flys.client.client.FLYS; +import de.intevation.flys.client.shared.model.RiverInfo; + +/** + * A Panel to show info about the MeasurementStations of a river + * + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class MeasurementStationPanel extends InfoPanel { + + /** + * MeasurementStationPanel loads the MeasurementStations from the + * RiverInfoService and displays them in a tree underneath a RiverInfoPanel + * + * @param flys The FLYS object + */ + public MeasurementStationPanel(FLYS flys) { + super(new MeasurementStationListGrid(flys)); + } + + /** + * Returns the title which should be displayed in the section + */ + @Override + public String getSectionTitle() { + return MSG.measurementStationPanelTitle(); + } + + /** + * Loads the river info and renders it afterwards + */ + @Override + public void refresh() { + GWT.log("MeasurementStationPanel - refresh"); + contract(); + + riverInfoService.getMeasurementStations(this.river, + new AsyncCallback<RiverInfo>() { + @Override + public void onFailure(Throwable e) { + GWT.log("Could not load the river info." + e); + } + + @Override + public void onSuccess(RiverInfo riverinfo) { + GWT.log("MeasurementStationPanel - Loaded river info"); + render(riverinfo); + expand(); + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,185 @@ +package de.intevation.flys.client.client.ui.stationinfo; + +import java.util.Date; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.MeasurementStation; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class MeasurementStationRecord +extends ListGridRecord +implements MeasurementStation { + + /** The message class that provides i18n strings.*/ + private FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public MeasurementStationRecord(MeasurementStation station) { + this.setCanExpand(true); + + Integer number = station.getID(); + String link = number != null ? + MSG.measurement_station_url() + number : + MSG.measurement_station_url(); + this.setLink(link); + this.setLinkText(MSG.measurement_station_info_link()); + this.setCurveLink(MSG.static_sqrelation()); + this.setID(number); + this.setName(station.getName()); + if (station.isKmUp()) { + this.setKmEnd(station.getKmStart()); + this.setKmStart(station.getKmEnd()); + } + else { + this.setKmEnd(station.getKmEnd()); + this.setKmStart(station.getKmStart()); + } + this.setKmUp(station.isKmUp()); + this.setRiverName(station.getRiverName()); + this.setStation(station.getStation()); + this.setGaugeName(station.getGaugeName()); + this.setMeasurementType(station.getMeasurementType()); + this.setOperator(station.getOperator()); + this.setRiverSide(station.getRiverSide()); + this.setStartTime(station.getStartTime()); + this.setStopTime(station.getStopTime()); + } + + @Override + public Integer getID() { + return this.getAttributeAsInt("stationid"); + } + + private void setID(Integer value) { + this.setAttribute("stationid", value); + } + + @Override + public String getName() { + return this.getAttributeAsString("name"); + } + + private void setName(String value) { + this.setAttribute("name", value); + } + + @Override + public Double getKmStart() { + return this.getAttributeAsDouble("kmstart"); + } + + private void setKmStart(Double value) { + this.setAttribute("kmstart", value); + } + + @Override + public Double getKmEnd() { + return this.getAttributeAsDouble("kmend"); + } + + private void setKmEnd(Double value) { + this.setAttribute("kmend", value); + } + + @Override + public boolean isKmUp() { + return this.getAttributeAsBoolean("kmup"); + } + + private void setKmUp(boolean value) { + this.setAttribute("kmup", value); + } + + @Override + public Double getStation() { + return this.getAttributeAsDouble("station"); + } + + private void setStation(Double station) { + this.setAttribute("station", station); + } + + @Override + public String getRiverName() { + return this.getAttributeAsString("rivername"); + } + + private void setRiverName(String rivername) { + this.setAttribute("rivername", rivername); + } + + @Override + public String getRiverSide() { + return this.getAttributeAsString("riverside"); + } + + private void setRiverSide(String riverside) { + this.setAttribute("riverside", riverside); + } + + @Override + public String getMeasurementType() { + return this.getAttributeAsString("measurementtype"); + } + + private void setMeasurementType(String value) { + this.setAttribute("measurementtype", value); + } + + @Override + public String getOperator() { + return this.getAttributeAsString("operator"); + } + + private void setOperator(String value) { + this.setAttribute("operator", value); + } + + @Override + public Date getStartTime() { + return this.getAttributeAsDate("starttime"); + } + + private void setStartTime(Date value) { + this.setAttribute("starttime", value); + } + + @Override + public Date getStopTime() { + return this.getAttributeAsDate("stoptime"); + } + + private void setStopTime(Date value) { + this.setAttribute("stoptime", value); + } + + @Override + public String getGaugeName() { + return this.getAttributeAsString("gaugename"); + } + + private void setGaugeName(String value) { + this.setAttribute("gaugename", value); + } + + public String getLink() { + return this.getAttributeAsString("link"); + } + + public void setLink(String link) { + this.setAttribute("link", link); + } + + public void setCurveLink(String link) { + this.setAttribute("curvelink", link); + } + + public String getCurveLink() { + return this.getAttribute("curvelink"); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/wq/ClickableQDTable.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,171 @@ +package de.intevation.flys.client.client.ui.wq; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; + +import de.intevation.flys.client.client.FLYSConstants; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ClickableQDTable extends ListGrid { + + public static enum ClickMode { + NONE, SINGLE, RANGE + } + + public static interface QClickedListener { + + void clickedLower(double value); + + void clickedUpper(double value); + } + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + private QClickedListener qClickedListener; + private ClickMode clickMode; + + protected boolean lockClick; + + public ClickableQDTable() { + this.clickMode = ClickMode.NONE; + init(); + } + + public ClickableQDTable(QClickedListener qClickedListener, + ClickMode clickMode) { + this.qClickedListener = qClickedListener; + this.clickMode = clickMode; + init(); + } + + private void init() { + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.SINGLE); + setSelectionType(SelectionStyle.SINGLE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MESSAGE.empty_table()); + + ListGridField name = new ListGridField("name", MESSAGE.discharge()); + name.setType(ListGridFieldType.TEXT); + name.setWidth("*"); + + ListGridField type = new ListGridField("type", MESSAGE.type()); + type.setType(ListGridFieldType.TEXT); + type.setWidth("20%"); + + final NumberFormat nf = NumberFormat.getDecimalFormat(); + + ListGridField value = new ListGridField("value", MESSAGE.wq_value_q()); + value.setType(ListGridFieldType.FLOAT); + value.setCellFormatter(new CellFormatter() { + + @Override + public String format(Object v, ListGridRecord r, int row, int col) { + if (v == null) { + return null; + } + + try { + double value = Double.valueOf(v.toString()); + return nf.format(value); + } + catch (NumberFormatException nfe) { + return v.toString(); + } + } + }); + value.setWidth("20%"); + + switch (clickMode) { + case NONE: + setFields(name, type, value); + break; + case SINGLE: + initSingleClickMode(name, type, value); + break; + case RANGE: + initRangeClickMode(name, type, value); + break; + } + } + + private void initSingleClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField select = new ListGridField("select", MESSAGE.selection()); + select.setType(ListGridFieldType.ICON); + select.setWidth(70); + select.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + ListGridRecord r = event.getRecord(); + fireLowerClickEvent(r.getAttributeAsDouble("value")); + } + } + }); + + setFields(select, name, type, value); + } + + private void initRangeClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField addMin = new ListGridField("min", MESSAGE.to()); + addMin.setType(ListGridFieldType.ICON); + addMin.setWidth(30); + addMin.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + + ListGridField addMax = new ListGridField("max", MESSAGE.from()); + addMax.setType(ListGridFieldType.ICON); + addMax.setWidth(30); + addMax.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerRed()); + + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + ListGridRecord r = event.getRecord(); + fireLowerClickEvent(r.getAttributeAsDouble("value")); + } + + if (event.getColNum() == 1) { + ListGridRecord r = event.getRecord(); + fireUpperClickEvent(r.getAttributeAsDouble("value")); + } + } + }); + + setFields(addMin, addMax, name, type, value); + } + + private void fireLowerClickEvent(double value) { + if (qClickedListener != null) { + qClickedListener.clickedLower(value); + } + } + + private void fireUpperClickEvent(double value) { + if (qClickedListener != null) { + qClickedListener.clickedUpper(value); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/wq/ClickableWTable.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,176 @@ +package de.intevation.flys.client.client.ui.wq; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellClickEvent; +import com.smartgwt.client.widgets.grid.events.CellClickHandler; + +import de.intevation.flys.client.client.FLYSConstants; + + +public class ClickableWTable extends ListGrid { + + public static enum ClickMode { + NONE, SINGLE, RANGE + } + + private boolean useWaterlevelLabel = false; + + public static interface WClickedListener { + + void clickedLower(double value); + + void clickedUpper(double value); + } + + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + private WClickedListener wClickedListener; + private ClickMode clickMode; + + public ClickableWTable() { + this.clickMode = ClickMode.NONE; + init(); + } + + public ClickableWTable(WClickedListener lowerListener, + ClickMode selectionMode, boolean alternativeLabel) { + this.wClickedListener = lowerListener; + this.clickMode = selectionMode; + this.useWaterlevelLabel = alternativeLabel; + init(); + } + + private void init() { + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.NONE); + setSelectionType(SelectionStyle.NONE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MESSAGE.empty_table()); + + ListGridField name = new ListGridField("name", + useWaterlevelLabel ? MESSAGE.wq_waterlevel_label() : MESSAGE.name() ); + name.setType(ListGridFieldType.TEXT); + name.setWidth("*"); + + ListGridField type = new ListGridField("type", MESSAGE.type()); + type.setType(ListGridFieldType.TEXT); + type.setWidth("50"); + + final NumberFormat nf = NumberFormat.getDecimalFormat(); + + ListGridField value = new ListGridField("value", MESSAGE.wq_value_w()); + value.setType(ListGridFieldType.FLOAT); + value.setCellFormatter(new CellFormatter() { + + @Override + public String format(Object v, ListGridRecord r, int row, int col) { + if (v == null) { + return null; + } + + try { + double value = Double.valueOf(v.toString()); + return nf.format(value); + } + catch (NumberFormatException nfe) { + return v.toString(); + } + } + }); + + switch (clickMode) { + case NONE: + setFields(name, type, value); + break; + case SINGLE: + initSingleClickMode(name, type, value); + break; + case RANGE: + initRangeClickMode(name, type, value); + break; + } + } + + private void initSingleClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField lower = new ListGridField("selection", + MESSAGE.selection()); + lower.setType(ListGridFieldType.ICON); + lower.setWidth("65"); + lower.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + Record r = event.getRecord(); + double val = r.getAttributeAsDouble("value"); + fireLowerClickEvent(val); + } + } + }); + + setFields(lower, name, type, value); + } + + private void initRangeClickMode(ListGridField name, ListGridField type, + ListGridField value) { + ListGridField lower = new ListGridField("lower", MESSAGE.lower()); + lower.setType(ListGridFieldType.ICON); + lower.setWidth("50"); + lower.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerRed()); + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 0) { + Record r = event.getRecord(); + double val = r.getAttributeAsDouble("value"); + fireLowerClickEvent(val); + } + } + }); + + ListGridField upper = new ListGridField("upper", MESSAGE.upper()); + upper.setType(ListGridFieldType.ICON); + upper.setWidth("50"); + upper.setCellIcon(GWT.getHostPageBaseURL() + MESSAGE.markerGreen()); + addCellClickHandler(new CellClickHandler() { + + @Override + public void onCellClick(CellClickEvent event) { + if (event.getColNum() == 1) { + Record r = event.getRecord(); + double val = r.getAttributeAsDouble("value"); + fireUpperClickEvent(val); + } + } + }); + + setFields(lower, upper, name, type, value); + } + + private void fireLowerClickEvent(double value) { + if (wClickedListener != null) { + wClickedListener.clickedLower(value); + } + } + + private void fireUpperClickEvent(double value) { + if (wClickedListener != null) { + wClickedListener.clickedUpper(value); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/wq/QDTable.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,126 @@ +package de.intevation.flys.client.client.ui.wq; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import de.intevation.flys.client.client.FLYSConstants; + + +/** + * Table showing Q and D main values, allowing for selection. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class QDTable extends ListGrid { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + + protected boolean lockClick; + + public QDTable() { + String baseUrl = GWT.getHostPageBaseURL(); + + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.SINGLE); + setSelectionType(SelectionStyle.SINGLE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MESSAGE.empty_table()); + + ListGridField addMax = new ListGridField("max", MESSAGE.from()); + addMax.setType(ListGridFieldType.ICON); + addMax.setWidth(30); + addMax.setCellIcon(baseUrl + MESSAGE.markerRed()); + + ListGridField addMin = new ListGridField("min", MESSAGE.to()); + addMin.setType(ListGridFieldType.ICON); + addMin.setWidth(30); + addMin.setCellIcon(baseUrl + MESSAGE.markerGreen()); + + ListGridField select = new ListGridField("select", MESSAGE.selection()); + select.setType(ListGridFieldType.ICON); + select.setWidth(70); + select.setCellIcon(baseUrl + MESSAGE.markerGreen()); + + ListGridField name = new ListGridField("name", MESSAGE.discharge()); + name.setType(ListGridFieldType.TEXT); + name.setWidth("*"); + + ListGridField type = new ListGridField("type", MESSAGE.type()); + type.setType(ListGridFieldType.TEXT); + type.setWidth("20%"); + + final NumberFormat nf = NumberFormat.getDecimalFormat(); + + ListGridField value = new ListGridField("value", MESSAGE.wq_value_q()); + value.setType(ListGridFieldType.FLOAT); + value.setCellFormatter(new CellFormatter() { + @Override + public String format(Object v, ListGridRecord r, int row, int col) { + if (v == null) { + return null; + } + + try { + double value = Double.valueOf(v.toString()); + return nf.format(value); + } + catch (NumberFormatException nfe) { + return v.toString(); + } + } + }); + value.setWidth("20%"); + + setFields(addMax, addMin, select, name, type, value); + } + + public void hideIconFields () { + hideField("max"); + hideField("min"); + hideField("select"); + lockClick = true; + } + + + public void showIconFields() { + showField("max"); + showField("min"); + hideField("select"); + lockClick = false; + } + + public void showSelect() { + showField("select"); + hideField("max"); + hideField("min"); + } + + public boolean isLocked() { + return lockClick; + } + + /** + * Search all records for one with attribute name equals to given name. + * @return null if none found. + * */ + public Double findRecordValue(String name) { + for (ListGridRecord record : getRecords()) { + if (record.getAttribute("name").equals(name)) { + return record.getAttributeAsDouble("value"); + } + } + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WQAutoTabSet.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,98 @@ +package de.intevation.flys.client.client.ui.wq; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.tab.Tab; +import com.smartgwt.client.widgets.tab.TabSet; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.client.services.WQInfoService; +import de.intevation.flys.client.client.services.WQInfoServiceAsync; + +import de.intevation.flys.client.shared.model.WQInfoObject; +import de.intevation.flys.client.shared.model.WQInfoRecord; + +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.client.Config; + +/** Tabset showing non-selectable W and Q/D values for a gauge. */ +public class WQAutoTabSet extends TabSet { + + /** Service to fetch W/Q/D values. */ + WQInfoServiceAsync wqInfoService = + GWT.create(WQInfoService.class); + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + /** Table showing Q/D values. */ + protected QDTable qdTable; + + /** Table showing W values. */ + protected WTable wTable; + + + /** Set up two tabs showing W and Q/D values, fetch and populate tables. */ + public WQAutoTabSet(String riverName, double[] dist) { + super(); + + this.setWidth100(); + this.setHeight100(); + + Tab wTab = new Tab(MESSAGE.wq_table_w()); + Tab qTab = new Tab(MESSAGE.wq_table_q()); + + qdTable = new QDTable(); + qdTable.hideIconFields(); + wTable = new WTable(); + + wTab.setPane(wTable); + qTab.setPane(qdTable); + + this.addTab(wTab, 0); + this.addTab(qTab, 1); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + wqInfoService.getWQInfo(locale, riverName, dist[0], dist[1], + new AsyncCallback<WQInfoObject[]>() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not recieve wq informations."); + SC.warn(caught.getMessage()); + } + + @Override + public void onSuccess(WQInfoObject[] wqi) { + int num = wqi != null ? wqi.length :0; + GWT.log("Recieved " + num + " wq informations."); + + if (num == 0) { + return; + } + + addWQInfo(wqi); + } + } + ); + } + + + /** Populate tables with one value. */ + private void addWQInfo (WQInfoObject[] wqi) { + for(WQInfoObject wi: wqi) { + WQInfoRecord rec = new WQInfoRecord(wi); + + if (wi.getType().equals("W")) { + wTable.addData(rec); + } + else { + qdTable.addData(rec); + } + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,66 @@ +package de.intevation.flys.client.client.ui.wq; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SelectionStyle; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import de.intevation.flys.client.client.FLYSConstants; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WTable extends ListGrid { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); + + + public WTable() { + setWidth100(); + setHeight100(); + setSelectionType(SelectionStyle.NONE); + setSelectionType(SelectionStyle.NONE); + setShowHeaderContextMenu(false); + setShowRecordComponents(true); + setShowRecordComponentsByCell(true); + setEmptyMessage(MESSAGE.empty_table()); + + ListGridField name = new ListGridField("name", MESSAGE.name()); + name.setType(ListGridFieldType.TEXT); + name.setWidth("*"); + + ListGridField type = new ListGridField("type", MESSAGE.type()); + type.setType(ListGridFieldType.TEXT); + type.setWidth("50"); + + final NumberFormat nf = NumberFormat.getDecimalFormat(); + + ListGridField value = new ListGridField("value", MESSAGE.wq_value_w()); + value.setType(ListGridFieldType.FLOAT); + value.setCellFormatter(new CellFormatter() { + @Override + public String format(Object v, ListGridRecord r, int row, int col) { + if (v == null) { + return null; + } + + try { + double value = Double.valueOf(v.toString()); + return nf.format(value); + } + catch (NumberFormatException nfe) { + return v.toString(); + } + } + }); + + setFields(name, type, value); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/utils/DoubleValidator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,81 @@ +package de.intevation.flys.client.client.utils; + +import java.util.Map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.widgets.form.fields.FormItem; + +import de.intevation.flys.client.client.FLYSConstants; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DoubleValidator implements Validator { + + /** The interface that provides i18n messages. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + + /** Statically determine doubility of String value. */ + public static boolean isDouble(Object obj) { + if (obj == null) { + return false; + } + + boolean valid = true; + String v = obj.toString(); + + NumberFormat f = NumberFormat.getDecimalFormat(); + + try { + if (v == null) { + throw new NumberFormatException("empty"); + } + + double value = f.parse(v); + } + catch (NumberFormatException nfe) { + valid = false; + } + return valid; + + } + + + /** + * @return true if items value can be converted to double, if false, + * expect error message in \param errors map. + */ + public boolean validate(FormItem item, Map errors) { + boolean valid = true; + + if(item.getValue() == null) { + return false; + } + String v = item.getValue().toString(); + + NumberFormat f = NumberFormat.getDecimalFormat(); + + try { + if (v == null) { + throw new NumberFormatException("empty"); + } + + double value = f.parse(v); + + errors.remove(item.getFieldName()); + } + catch (NumberFormatException nfe) { + errors.put(item.getFieldName(), MSG.wrongFormat()); + + item.focusInItem(); + + valid = false; + } + return valid; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/utils/EnableDisableCmd.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.utils; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface EnableDisableCmd { + + void enable(); + + void disable(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/utils/IntegerValidator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,45 @@ +package de.intevation.flys.client.client.utils; + +import java.util.Map; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.form.fields.FormItem; + +import de.intevation.flys.client.client.FLYSConstants; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class IntegerValidator implements Validator { + + /** The interface that provides i18n messages. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** + * + */ + public boolean validate(FormItem item, Map errors) { + boolean valid = true; + + String v = item.getValue().toString(); + + try { + if (v == null) { + throw new NumberFormatException("empty"); + } + + int value = Integer.parseInt(v); + + errors.remove(item.getFieldName()); + } + catch (NumberFormatException nfe) { + errors.put(item.getFieldName(), MSG.wrongFormat()); + + item.focusInItem(); + + valid = false; + } + return valid; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/utils/Validator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,16 @@ +package de.intevation.flys.client.client.utils; + +import java.util.Map; + +import com.smartgwt.client.widgets.form.fields.FormItem; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + * + * This validator is used for SmartGWT FormItems. + */ +public interface Validator { + + boolean validate(FormItem item, Map errors); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/widgets/DischargeTablesChart.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,90 @@ +package de.intevation.flys.client.client.widgets; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; + + +public class DischargeTablesChart extends Canvas implements ResizedHandler { + + protected Artifact artifact; + + protected Img img; + + public DischargeTablesChart() { + super(); + } + + public DischargeTablesChart(Artifact artifact) { + super(); + this.artifact = artifact; + init(); + } + + private void init() { + addChild(createImage()); + addResizedHandler(this); + setSize("100%", "100%"); + } + + protected Img createImage() { + img = new Img(getUrl()); + img.setSize("100%", "100%"); + + return img; + } + + protected String getUrl() { + String url = GWT.getModuleBaseURL(); + url += "dischargetablesoverview"; + url += "?gauge=" + getGauge(); + url += "&format=png"; + + String[] timerange = getTimerange(); + url += "&lower=" + timerange[0]; + url += "&upper=" + timerange[1]; + + int width = 600; + int height = 400; + if (img != null) { + width = img.getWidth(); + height = img.getHeight(); + } + + url += "&width=" + String.valueOf(width); + url += "&height=" + String.valueOf(height); + + // add time millis to 'deactivate' caching + url += "&timemillis" + System.currentTimeMillis(); + + GWT.log("DischargeTablesService URL = '" + url + "'"); + return url; + } + + protected String getGauge() { + ArtifactDescription desc = artifact.getArtifactDescription(); + return desc.getReferenceGauge(); + } + + protected String[] getTimerange() { + ArtifactDescription desc = artifact.getArtifactDescription(); + String yearStr = desc.getDataValueAsString("year_range"); + + if (yearStr != null && yearStr.length() > 0) { + return yearStr.split(";"); + } + + return new String[2]; + } + + @Override + public void onResized(ResizedEvent event) { + GWT.log("resized discharge tables overview chart"); + img.setSrc(getUrl()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/widgets/KMSpinner.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,176 @@ +package de.intevation.flys.client.client.widgets; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.FormItemValueFormatter; +import com.smartgwt.client.widgets.form.FormItemValueParser; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.fields.events.BlurEvent; +import com.smartgwt.client.widgets.form.fields.events.BlurHandler; +import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; +import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.shared.model.FacetRecord; + +import java.util.ArrayList; +import java.util.List; + +/** + * SpinnerItem-like element with text label and up/down buttons. + */ +public class KMSpinner extends HLayout { + protected List<KMSpinnerChangeListener> listeners = new ArrayList<KMSpinnerChangeListener>(); + + protected Label label; + protected FacetRecord facetRecord; + protected double value; + + public KMSpinner(double initialValue, FacetRecord facetRecord) { + super(2); + this.facetRecord = facetRecord; + this.value = initialValue; + + setWidth("99%"); + setHeight(18); + + // minusButton shall ask service for previous available cs. + Button minusButton = new Button("-"); + minusButton.setWidth(18); + minusButton.setHeight(18); + minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { + public void onClick(ClickEvent evt) { + fireChangedEvent(value - 0.1d, false); + } + }); + + DynamicForm form = new DynamicForm(); + final TextItem kmField = new TextItem(); + kmField.setValue(initialValue); + kmField.setWidth("*"); + kmField.setTitle(""); + kmField.setHeight(16); + + FormItemValueFormatter doubleFormat = new FormItemValueFormatter() { + public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { + if (value != null) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(value.toString()).doubleValue(); + return nf.format(d); + } + catch (Exception e) { + GWT.log("EditorValueFormatter exception: " + e.toString()); + + // Remove junk chars from input string + return doublefyString(value.toString()); + } + } + else { + return null; + } + } + }; + kmField.setEditorValueFormatter(doubleFormat); + + FormItemValueParser doubleParser = new FormItemValueParser() { + public Object parseValue(String value, DynamicForm form, FormItem item) { + if (value == null) + return null; + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d = nf.parse(value.toString()); + return Double.toString(d); + } + catch(NumberFormatException nfe) { + return value; + } + } + }; + kmField.setEditorValueParser(doubleParser); + + // Update on focus lost and enter-pressed. + kmField.addBlurHandler(new BlurHandler() { + @Override + public void onBlur(BlurEvent be) { + if (kmField.getValue() != null) { + try { + fireChangedEvent(Double.parseDouble(kmField.getValue().toString()), true); + } + catch(NumberFormatException nfe) { + GWT.log("entered string cannot be parsed to double."); + } + } + } + }); + kmField.addKeyPressHandler(new KeyPressHandler() { + @Override + public void onKeyPress(KeyPressEvent kpe) { + if (kpe.getKeyName().equals("Enter")) { + kmField.blurItem(); + } + } + }); + + // TODO: i18n Now add all the validators, formatters, editors/parsers etc. + form.setFields(kmField); + form.setTitle(""); + form.setTitlePrefix(""); + form.setTitleSuffix(""); + form.setTitleWidth(0); + form.setWidth(50); + form.setHeight(18); + + // PlusButton shall ask service for next available cs. + Button plusButton = new Button("+"); + plusButton.setWidth(18); + plusButton.setHeight(18); + plusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { + public void onClick(ClickEvent evt) { + fireChangedEvent(value + 0.1d, true); + } + }); + + this.addMember(minusButton); + this.addMember(form); + this.addMember(plusButton); + } + + public void addChangeListener(KMSpinnerChangeListener listener) { + this.listeners.add(listener); + } + + protected void fireChangedEvent(double val, boolean up) { + for(KMSpinnerChangeListener listener : listeners) { + listener.spinnerValueEntered(this, val, facetRecord, up); + } + } + + /** + * Remove junk chars from double string. + * This method should work for most locales, but not for + * exotic ones that do not use "." or "," as decimal + * separator. + * @return + */ + protected String doublefyString(String str) { + StringBuilder buf = new StringBuilder(str.length()); + + for (int n = 0; n < str.length(); n++) { + char c = str.charAt(n); + if ((c >= '0' && c <= '9') || c == '.' || c == ',') { + buf.append(c); + } + } + + return buf.toString(); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/client/widgets/KMSpinnerChangeListener.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,9 @@ +package de.intevation.flys.client.client.widgets; + +import de.intevation.flys.client.client.widgets.KMSpinner; + +import de.intevation.flys.client.shared.model.FacetRecord; + +public interface KMSpinnerChangeListener { + public void spinnerValueEntered(KMSpinner spinner, double km, FacetRecord facetRecord, boolean up); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/AddArtifactServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,34 @@ +package de.intevation.flys.client.server; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.services.AddArtifactService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class AddArtifactServiceImpl +extends DescribeCollectionServiceImpl +implements AddArtifactService +{ + private static final Logger logger = + Logger.getLogger(AddArtifactService.class); + + + public Collection add( + Collection collection, + Artifact artifact, + String locale) + throws ServerException + { + logger.info("AddArtifactServiceImpl.add"); + String url = getServletContext().getInitParameter("server-url"); + + return CollectionHelper.addArtifact(collection, artifact, url, locale); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/AdvanceServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,86 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.client.services.AdvanceService; + + +/** + * This interface provides artifact specific operation ADVANCE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class AdvanceServiceImpl +extends RemoteServiceServlet +implements AdvanceService +{ + private static final Logger logger = Logger.getLogger(AdvanceService.class); + + public static final String XPATH_RESULT = "/art:result/text()"; + + public static final String OPERATION_FAILURE = "FAILED"; + + public static final String ERROR_ADVANCE_ARTIFACT = "error_advance_artifact"; + + + public Artifact advance( + String locale, + Artifact artifact, + String target) + throws ServerException + { + logger.info("AdvanceServiceImpl.advance"); + + String url = getServletContext().getInitParameter("server-url"); + + Document advance = ClientProtocolUtils.newAdvanceDocument( + artifact.getUuid(), + artifact.getHash(), + target); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document description = (Document) client.advance( + new de.intevation.artifacts.httpclient.objects.Artifact( + artifact.getUuid(), + artifact.getHash()), + advance, + new DocumentResponseHandler()); + + if (description == null) { + throw new ServerException(ERROR_ADVANCE_ARTIFACT); + } + + String result = XMLUtils.xpathString( + description, + XPATH_RESULT, + ArtifactNamespaceContext.INSTANCE); + + if (result == null || !result.equals(OPERATION_FAILURE)) { + return (Artifact) new FLYSArtifactCreator().create(description); + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_ADVANCE_ARTIFACT); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ArtifactDescriptionFactory.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,582 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultArtifactDescription; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.DefaultOutputMode; +import de.intevation.flys.client.shared.model.DoubleArrayData; +import de.intevation.flys.client.shared.model.DoubleRangeData; +import de.intevation.flys.client.shared.model.IntegerArrayData; +import de.intevation.flys.client.shared.model.IntegerRangeData; +import de.intevation.flys.client.shared.model.IntegerOptionsData; +import de.intevation.flys.client.shared.model.LongRangeData; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.WQDataItem; + + +/** + * This factory class helps creating an {@link ArtifactDescription} based on the + * DESCRIBE document of an artifact returned by the artifact server. Use the + * {@link createArtifactDescription(org.w3c.dom.Document)} method with the + * DESCRIBE document to create such an {@link ArtifactDescription}. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ArtifactDescriptionFactory { + + private static final Logger logger = + Logger.getLogger(ArtifactDescriptionFactory.class); + + + public static final String XPATH_STATE_NAME = "@art:name"; + + public static final String XPATH_UIPROVIDER = "@art:uiprovider"; + + public static final String XPATH_HELP_TEXT = "@art:helpText"; + + public static final String XPATH_REACHABLE_STATE = "art:state"; + + public static final String XPATH_STATIC_STATE_NODE = "art:state"; + + public static final String XPATH_STATIC_DATA_NODE = "art:data"; + + public static final String XPATH_STATIC_ITEM_NODE = "art:item"; + + public static final String XPATH_RECOMMENDED_ARTIFACTS = + "/art:result/art:recommended-artifacts//*[@factory]"; + + /** + * This method creates the {@link ArtifactDescription} of the DESCRIBE + * document <i>doc</i>. + * + * @param doc A DESCRIBE document. + * + * @return the {@link ArtifactDescription}. + */ + public static ArtifactDescription createArtifactDescription(Document doc) { + logger.debug("ArtifactDescriptionFactory.createArtifactDescription"); + + Node currentState = ClientProtocolUtils.getCurrentState(doc); + Node staticNode = ClientProtocolUtils.getStaticUI(doc); + Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc); + Node reachable = ClientProtocolUtils.getReachableStates(doc); + NodeList outputs = ClientProtocolUtils.getOutputModes(doc); + + String state = (String) XMLUtils.xpath( + currentState, + XPATH_STATE_NAME, + XPathConstants.STRING, + ArtifactNamespaceContext.INSTANCE); + + logger.debug("Current state name: " + state); + + DataList currentData = extractCurrentData(dynamicNode, state); + DataList[] old = extractOldData(staticNode); + String[] states = extractReachableStates(reachable); + OutputMode[] outs = extractOutputModes(outputs); + Recommendation[] rec = extractRecommendedArtifacts(doc); + + return new DefaultArtifactDescription( + old, + currentData, + state, + states, + outs, + rec); + } + + + /** + * This method extracts the data that the user is able to enter in the + * current state of the artifact. + * + * @param dynamicNode The dynamic node of the DESCRIBE document. + * @param state The name of the current state. + * + * @return A {@link Data} object that represents the data which might be + * entered by the user in the current state or null, if no data might be + * entered. + */ + protected static DataList extractCurrentData(Node dynamicNode, String state) { + logger.debug("ArtifactDescriptionFactory.extractCurrentData"); + + NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode); + String help = extractHelpText(dynamicNode); + String uiProvider = extractUIProvider(dynamicNode); + + if (data == null || data.getLength() == 0) { + return null; + } + + int dataNum = data.getLength(); + DataList list = new DataList(state, dataNum, uiProvider, null, help); + + for (int i = 0; i < dataNum; i++) { + Element d = (Element) data.item(i); + String label = ClientProtocolUtils.getLabel(d); + String name = XMLUtils.xpathString( + d, "@art:name", ArtifactNamespaceContext.INSTANCE); + String type = XMLUtils.xpathString( + d, "@art:type", ArtifactNamespaceContext.INSTANCE); + + logger.debug("Create new IntegerRangeData object for: " + name); + logger.debug("New Data is from type: " + type); + + // TODO replace with DataFactory. + + if (type == null || type.length() == 0) { + NodeList choices = ClientProtocolUtils.getItemNodes(d); + DataItem[] dataItems = extractCurrentDataItems(choices); + DataItem def = extractDefaultDataItem(d); + + list.add(new DefaultData(name, label, null, dataItems, def)); + } + else if (type.equals("intrange")) { + String min = ClientProtocolUtils.getMinNode(d); + String max = ClientProtocolUtils.getMaxNode(d); + + String defMin = ClientProtocolUtils.getDefMin(d); + String defMax = ClientProtocolUtils.getDefMax(d); + + try { + int lower = Integer.parseInt(min); + int upper = Integer.parseInt(max); + + if (defMin != null && defMax != null) { + list.add(new IntegerRangeData( + name, label, + lower, upper, + Integer.parseInt(defMin), + Integer.parseInt(defMax))); + } + else { + list.add( + new IntegerRangeData(name, label, lower, upper)); + } + } + catch (NumberFormatException nfe) { + logger.warn("NumberFormatException: ", nfe); + } + } + else if (type.equals("longrange")) { + String min = ClientProtocolUtils.getMinNode(d); + String max = ClientProtocolUtils.getMaxNode(d); + + String defMin = ClientProtocolUtils.getDefMin(d); + String defMax = ClientProtocolUtils.getDefMax(d); + + try { + long lower = Long.valueOf(min); + long upper = Long.valueOf(max); + + if (defMin != null && defMax != null) { + list.add(new LongRangeData( + name, label, + lower, upper, + Long.valueOf(defMin), + Long.valueOf(defMax))); + } + } + catch (NumberFormatException nfe) { + logger.warn("NumberFormatException: ", nfe); + } + } + else if (type.equals("intarray")) { + list.add(new IntegerArrayData(name, label, null)); + } + else if (type.equals("intoptions") && uiProvider.equals("parameter-matrix")) { + list.add(DataFactory.createIntegerOptionsData(d, name, label)); + } + else if (type.equals("options")) { + list.add(DataFactory.createStringOptionsData(d, name, label)); + } + else if (type.equals("intoptions")) { + NodeList choices = ClientProtocolUtils.getItemNodes(d); + DataItem[] opts = extractCurrentDataItems(choices); + + list.add(new IntegerOptionsData(name, label, opts)); + } + else if (type.equals("doublearray")) { + list.add(new DoubleArrayData(name, label, null)); + } + else { + logger.warn("Unrecognized Dynamic data type."); + NodeList choices = ClientProtocolUtils.getItemNodes(d); + DataItem[] dataItems = extractCurrentDataItems(choices); + DataItem def = extractDefaultDataItem(d); + + String min = ClientProtocolUtils.getMinNode(d); + String max = ClientProtocolUtils.getMaxNode(d); + if (min != null && max != null) { + list.add(new DoubleRangeData( + name, label, + Double.valueOf(min), Double.valueOf(max), + Double.valueOf(min), Double.valueOf(max))); + } + + list.add(new DefaultData(name, label, null, dataItems, def)); + } + + } + + return list; + } + + + /** + * This method extracts the default value of a Data object. + * + * @param data The data object node. + * + * @return the default DataItem. + */ + protected static DataItem extractDefaultDataItem(Node data) { + logger.debug("ArtifactDescriptionFactory.extractDefaultDataItem"); + + String value = XMLUtils.xpathString( + data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE); + + String label = XMLUtils.xpathString( + data, "@art:defaultLabel", ArtifactNamespaceContext.INSTANCE); + + if (value != null && label != null) { + return new DefaultDataItem(label, null, value); + } + + return null; + } + + + /** + * This method extract the {@link DataItem}s of the DESCRIBE document. + * + * @param items The items in the DESCRIBE document. + * + * @return the {@link DataItem}s. + */ + protected static DataItem[] extractCurrentDataItems(NodeList items) { + logger.debug("ArtifactDescriptionFactory.extractCurrentDataItems"); + + if (items == null || items.getLength() == 0) { + logger.debug("No data items found."); + return null; + } + + int count = items.getLength(); + + List<DataItem> dataItems = new ArrayList<DataItem>(count); + + for (int i = 0; i < count; i++) { + Node item = items.item(i); + String label = ClientProtocolUtils.getLabel(item); + String value = ClientProtocolUtils.getValue(item); + + double[] mmQ = extractMinMaxQValues(item); + double[] mmW = extractMinMaxWValues(item); + + if (mmQ != null || mmW != null) { + dataItems.add(new WQDataItem(label, null, value, mmQ, mmW)); + } + else { + dataItems.add(new DefaultDataItem(label, null, value)); + } + } + + return dataItems.toArray(new DataItem[count]); + } + + + protected static double[] extractMinMaxQValues(Node item) { + logger.debug("ArtifactDescriptionFactory.extractMinMaxQValues"); + + if (item == null) { + logger.debug("This node is empty - no min/max Q values."); + return null; + } + + Node node = (Node) XMLUtils.xpath( + item, + "art:range[@art:type='Q']", + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + if (node == null) { + logger.debug("No min/max Q values found."); + return null; + } + + return extractMinMaxValues(node); + } + + + protected static double[] extractMinMaxWValues(Node item) { + logger.debug("ArtifactDescriptionFactory.extractMinMaxWValues"); + + if (item == null) { + logger.debug("This node is empty - no min/max W values."); + return null; + } + + Node node = (Node) XMLUtils.xpath( + item, + "art:range[@art:type='W']", + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + if (node == null) { + logger.debug("No min/max W values found."); + return null; + } + + return extractMinMaxValues(node); + } + + + protected static double[] extractMinMaxValues(Node node) { + logger.debug("ArtifactDescriptionFactory.extractMinMaxValues"); + + String minStr = XMLUtils.xpathString( + node, "art:min/text()", ArtifactNamespaceContext.INSTANCE); + + String maxStr = XMLUtils.xpathString( + node, "art:max/text()", ArtifactNamespaceContext.INSTANCE); + + if (maxStr == null || minStr == null) { + logger.debug("No min/max values found."); + return null; + } + + try { + double min = Double.valueOf(minStr); + double max = Double.valueOf(maxStr); + + return new double[] { min, max }; + } + catch (NumberFormatException nfe) { + logger.debug("Error while parsing min/max values."); + } + + return null; + } + + + /** + * This method extracts the data objects from the data node of the static ui + * part of the DESCRIBE document. + * + * @param staticNode The static ui node of the DESCRIBE. + * + * @return the DataList objects. + */ + protected static DataList[] extractOldData(Node staticNode) { + logger.debug("ArtifactDescriptionFactory.extractOldData()"); + + NodeList stateNodes = (NodeList) XMLUtils.xpath( + staticNode, + XPATH_STATIC_STATE_NODE, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (stateNodes == null || stateNodes.getLength() == 0) { + logger.debug("No old items found."); + return null; + } + + int count = stateNodes.getLength(); + DataList[] data = new DataList[count]; + + for (int i = 0; i < count; i++) { + Node tmp = stateNodes.item(i); + + String name = XMLUtils.xpathString( + tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); + String uiprovider = XMLUtils.xpathString( + tmp, "@art:uiprovider", ArtifactNamespaceContext.INSTANCE); + String label = XMLUtils.xpathString( + tmp, "@art:label", ArtifactNamespaceContext.INSTANCE); + String help = XMLUtils.xpathString( + tmp, "@art:helpText", ArtifactNamespaceContext.INSTANCE); + + NodeList dataNodes = (NodeList) XMLUtils.xpath( + tmp, + XPATH_STATIC_DATA_NODE, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (dataNodes == null || dataNodes.getLength() == 0) { + continue; + } + + int size = dataNodes.getLength(); + DataList list = new DataList(name, size, uiprovider, label, help); + + for (int j = 0; j < size; j++) { + Node dataNode = dataNodes.item(j); + + list.add(DataFactory.createDataFromElement((Element) dataNode)); + + data[i] = list; + } + } + + return data; + } + + + /** + * This method extracts the UIProvider specified by the data node. + * + * @param data The data node. + * + * @return the UIProvider that is specified in the data node. + */ + protected static String extractUIProvider(Node ui) { + return (String) XMLUtils.xpath( + ui, + XPATH_UIPROVIDER, + XPathConstants.STRING, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * This method extracts the help text specified by the data node. + * + * @param ui The data node. + * + * @return the help text. + */ + protected static String extractHelpText(Node ui) { + return (String) XMLUtils.xpath( + ui, + XPATH_HELP_TEXT, + XPathConstants.STRING, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * This method extracts the reachable states of the current artifact. + * + * @param reachable The reachable states node. + * + * @return an array with identifiers of reachable states. + */ + protected static String[] extractReachableStates(Node reachable) { + logger.debug("ArtifactDescriptionFactory.extractReachableStates()"); + + NodeList list = (NodeList) XMLUtils.xpath( + reachable, + XPATH_REACHABLE_STATE, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (list == null || list.getLength() == 0) { + return null; + } + + int count = list.getLength(); + + String[] states = new String[count]; + + for (int i = 0; i < count; i++) { + Node state = list.item(i); + + String name = XMLUtils.xpathString( + state, "@art:name", ArtifactNamespaceContext.INSTANCE); + + states[i] = name; + } + + return states; + } + + + /** + * This method extract available output modes of the the current artifact. + * + * @param outputs A list of nodes that contain information about output + * modes. + * + * @return an array of Output modes. + */ + protected static OutputMode[] extractOutputModes(NodeList outputs) { + logger.debug("ArtifactDescriptionFactory.extractOutputModes"); + + if (outputs == null || outputs.getLength() == 0) { + return null; + } + + int size = outputs.getLength(); + + List<OutputMode> outs = new ArrayList<OutputMode>(size); + + for (int i = 0; i < size; i++) { + Node out = outputs.item(i); + + String name = XMLUtils.xpathString( + out, "@art:name", ArtifactNamespaceContext.INSTANCE); + String desc = XMLUtils.xpathString( + out, "@art:description", ArtifactNamespaceContext.INSTANCE); + String mimeType = XMLUtils.xpathString( + out, "@art:mime-type", ArtifactNamespaceContext.INSTANCE); + + if (name != null) { + outs.add(new DefaultOutputMode(name, desc, mimeType)); + } + else { + logger.debug("Found an invalid output mode."); + } + } + + return (OutputMode[]) outs.toArray(new OutputMode[size]); + } + + + protected static Recommendation[] extractRecommendedArtifacts(Document doc){ + logger.debug("ArtifactDescriptionFactory.extractRecommendedArtifacts."); + + NodeList list = (NodeList) XMLUtils.xpath( + doc, + XPATH_RECOMMENDED_ARTIFACTS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = list != null ? list.getLength() : 0; + + Recommendation[] rec = new Recommendation[num]; + + for (int i = 0; i < num; i++) { + Element e = (Element) list.item(i); + String factory = e.getAttribute("factory"); + String index = e.getAttribute("ids"); + + if (factory != null && factory.length() > 0) { + rec[i] = new Recommendation(factory, index); + } + } + + return rec; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,196 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.CreationFilter; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.utils.ArtifactNamespaceContext; +import de.intevation.artifacts.httpclient.utils.XMLUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; + +import de.intevation.flys.client.shared.model.Recommendation; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ArtifactHelper { + + private static final Logger logger = Logger.getLogger(ArtifactHelper.class); + + + /** The error message key that is thrown if an error occured while artifact + * creation.*/ + public static final String ERROR_CREATE_ARTIFACT = "error_create_artifact"; + + /** + * Name of the factory to generate a GaugeDischargeCurveArtifact + */ + private static final String GAUGE_DISCHARGE_CURVE_ARTIFACT = "gaugedischargecurve"; + private static final String SQ_RELATION_ARTIFACT = "staticsqrelation"; + + private ArtifactHelper() { + } + + + /** + * @param factory ArtifactFactory to use. + */ + public static Artifact createArtifact( + String serverUrl, + String locale, + String factory, + Recommendation recommendation) + throws ServerException + { + logger.debug("ArtifactHelper.create"); + + String uuid; + String ids; + CreationFilter filter; + + if (recommendation != null) { + uuid = recommendation.getMasterArtifact(); + ids = recommendation.getIDs(); + filter = convertFilter(recommendation.getFilter()); + } + else { + uuid = null; + ids = null; + filter = null; + } + + Document create = ClientProtocolUtils.newCreateDocument( + factory, uuid, ids, filter); + + return sendCreate(serverUrl, locale, create); + + } + + /** + * Creates a new GaugeDischargeCurverArtifact + * + * @param river the name of the river + * @param reference the reference id of the gauge (official number) + */ + public static Artifact createGaugeDischargeCurveArtifact( + String serverUrl, + String locale, + String river, + Long reference) + throws ServerException + { + Document create = ClientProtocolUtils.newCreateDocument( + GAUGE_DISCHARGE_CURVE_ARTIFACT); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + create, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = create.getDocumentElement(); + + Element eriver = ec.create("river"); + ec.addAttr(eriver, "name", river); + + Element egauge = ec.create("gauge"); + ec.addAttr(egauge, "reference", reference.toString()); + + root.appendChild(eriver); + root.appendChild(egauge); + + return sendCreate(serverUrl, locale, create); + } + + /** + * Sends a create document to the artifact server + */ + private static Artifact sendCreate( + String serverUrl, + String locale, + Document doc) + throws ServerException + { + HttpClient client = new HttpClientImpl(serverUrl, locale); + + try { + return (Artifact) client.create(doc, new FLYSArtifactCreator()); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_CREATE_ARTIFACT); + } + + + /** + * Create CreationFilter from Recommendation.Filter. + */ + public static CreationFilter convertFilter(Recommendation.Filter filter) { + + if (filter == null) { + return null; + } + + CreationFilter cf = new CreationFilter(); + + Map<String, List<Recommendation.Facet>> outs = filter.getOuts(); + + for (Map.Entry<String, List<Recommendation.Facet>> entry: + outs.entrySet()) { + List<Recommendation.Facet> rfs = entry.getValue(); + List<CreationFilter.Facet> cfs = + new ArrayList<CreationFilter.Facet>(rfs.size()); + for (Recommendation.Facet rf: rfs) { + cfs.add(new CreationFilter.Facet(rf.getName(), rf.getIndex())); + } + cf.add(entry.getKey(), cfs); + } + + return cf; + } + + + public static Artifact createSQRelationArtifact( + String serverUrl, + String locale, + String river, + int measurementStation) + throws ServerException + { + Document create = ClientProtocolUtils.newCreateDocument( + SQ_RELATION_ARTIFACT); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + create, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = create.getDocumentElement(); + + Element eriver = ec.create("river"); + ec.addAttr(eriver, "name", river); + + Element estation = ec.create("measurement_station"); + ec.addAttr(estation, "number", String.valueOf(measurementStation)); + + root.appendChild(eriver); + root.appendChild(estation); + + return sendCreate(serverUrl, locale, create); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ArtifactServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,105 @@ +package de.intevation.flys.client.server; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.client.services.ArtifactService; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Recommendation; + +/** + * This interface provides artifact specific services as CREATE, DESCRIBE, FEED, + * ADVANCE and OUT. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ArtifactServiceImpl +extends RemoteServiceServlet +implements ArtifactService +{ + /** Private logger. */ + private static final Logger logger = + Logger.getLogger(ArtifactServiceImpl.class); + + + /** + * Creates new Artifacts based on a given Recommendation and factory. + * <b>Note, that all the work is done in ArtifactHelper!</b> + * + * @param locale The locale used for HTTP request. + * @param factory The factory that is used to create the new Artifact. + * @param recom Recommendation with details of the artifact to create. + * + * @return a new Artifact. + */ + public Artifact create( + String locale, + String factory, + Recommendation recom + ) + throws ServerException + { + logger.info("ArtifactServiceImpl.create"); + + String url = getServletContext().getInitParameter("server-url"); + + return ArtifactHelper.createArtifact(url, locale, factory, recom); + } + + /** + * Create a new GaugeDischageCurveArtifact + * + * @param river the river + * @param gaugeref reference id of the gauge + */ + public Artifact createGaugeDischargeCurveArtifact( + Collection collection, + String locale, + String river, + Long gaugeref) + throws ServerException + { + logger.info("ArtifactServiceImpl.createGaugeDischargeCurverArtifact"); + String url = getServletContext().getInitParameter("server-url"); + + Artifact artifact = ArtifactHelper.createGaugeDischargeCurveArtifact(url, + locale, river, gaugeref); + if (artifact == null) { + return null; + } + logger.info("GaugeDischargeCurveArtifact created successfully"); + + CollectionHelper.addArtifact(collection, artifact, url, locale); + + return artifact; + } + + @Override + public Artifact createSQRelationArtifact( + Collection collection, + String locale, + String river, + int measurementStation) + throws ServerException + { + logger.info("ArtifactServiceImpl.createSQRelationArtifact"); + String url = getServletContext().getInitParameter("server-url"); + + Artifact artifact = ArtifactHelper.createSQRelationArtifact(url, + locale, river, measurementStation); + if (artifact == null) { + return null; + } + logger.info("SQRelationArtifact created successfully"); + + CollectionHelper.addArtifact(collection, artifact, url, locale); + + return artifact; + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/BaseServletContextListener.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,62 @@ +package de.intevation.flys.client.server; + +import java.io.IOException; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.server.LoggingConfigurator; +import de.intevation.flys.client.server.features.Features; +import de.intevation.flys.client.server.features.XMLFileFeatures; + +/** + * ServletContextListenter to initalize the Features globally for + * all Servlets + */ +public class BaseServletContextListener implements ServletContextListener { + + public static final String LOG4J_PROPERTIES = "FLYS_CLIENT_LOG4J_PROPERIES"; + + public static final Logger logger = Logger.getLogger(BaseServletContextListener.class); + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext sc = sce.getServletContext(); + + this.initLogging(sc); + + String filename = sc.getInitParameter("features-file"); + + logger.debug("Initializing ServletContext"); + try { + XMLFileFeatures features = new XMLFileFeatures(sc.getRealPath(filename)); + sc.setAttribute(Features.CONTEXT_ATTRIBUTE, features); + } catch(IOException e) { + logger.error(e); + } + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + //DO NOTHING + } + + + private void initLogging(ServletContext sc) { + String log4jProperties = System.getenv(LOG4J_PROPERTIES); + + if (log4jProperties == null || log4jProperties.length() == 0) { + String file = sc.getInitParameter("log4j-properties"); + + if (file != null && file.length() > 0) { + log4jProperties = sc.getRealPath(file); + } + } + System.out.println(log4jProperties); + + LoggingConfigurator.init(log4jProperties); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/BedKMChartServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,106 @@ +package de.intevation.flys.client.server; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + +public class BedKMChartServiceImpl extends HttpServlet { + private static final Logger log = + Logger.getLogger(FixingsKMChartServiceImpl.class); + + public static final String SERVICE_NAME = "bed-km-chart"; + + public BedKMChartServiceImpl() { + } + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + + log.info("BedKMChartServiceImpl.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + String locale = req.getParameter("locale"); + String filter = req.getParameter("filter"); + + if (filter == null || filter.length() == 0) { + log.warn("Missing 'filter' parameter."); + return; + } + + if (locale == null || locale.length() == 0) { + locale = "de"; + } + + Document filterDoc = XMLUtils.jsonToXML(filter); + + if (filterDoc == null) { + log.warn("Creating filter document failed."); + return; + } + + InputStream in; + + try { + HttpClient client = new HttpClientImpl(url, locale); + in = (InputStream)client.callService( + url, // XXX: Why? The URL is passed by construction already. + SERVICE_NAME, + filterDoc, + new StreamResponseHandler()); + } + catch (ConnectionException ce) { + log.error(ce); + return; + } + + resp.setHeader("Content-Type", guessMIMEType(filterDoc)); + + try { + OutputStream out = resp.getOutputStream(); + + byte [] buf = new byte[4096]; + int i = -1; + while ((i = in.read(buf)) >= 0) { + out.write(buf, 0, i); + } + out.flush(); + } + catch (IOException ioe) { + log.error(ioe); + } + finally { + try { in.close(); } + catch (IOException ioe) { /* ignored */ } + } + } + + protected static String guessMIMEType(Document document) { + + NodeList formats = document.getElementsByTagName("format"); + + String format = "png"; + + if (formats.getLength() > 0) { + String type = ((Element)formats.item(0)).getAttribute("type"); + if (type.length() > 0) { + format = type; + } + } + + return "image/" + format; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/BedloadKMChartServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,106 @@ +package de.intevation.flys.client.server; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + +public class BedloadKMChartServiceImpl extends HttpServlet { + private static final Logger log = + Logger.getLogger(FixingsKMChartServiceImpl.class); + + public static final String SERVICE_NAME = "bedload-km-chart"; + + public BedloadKMChartServiceImpl() { + } + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + + log.info("BedloadKMChartServiceImpl.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + String locale = req.getParameter("locale"); + String filter = req.getParameter("filter"); + + if (filter == null || filter.length() == 0) { + log.warn("Missing 'filter' parameter."); + return; + } + + if (locale == null || locale.length() == 0) { + locale = "de"; + } + + Document filterDoc = XMLUtils.jsonToXML(filter); + + if (filterDoc == null) { + log.warn("Creating filter document failed."); + return; + } + + InputStream in; + + try { + HttpClient client = new HttpClientImpl(url, locale); + in = (InputStream)client.callService( + url, // XXX: Why? The URL is passed by construction already. + SERVICE_NAME, + filterDoc, + new StreamResponseHandler()); + } + catch (ConnectionException ce) { + log.error(ce); + return; + } + + resp.setHeader("Content-Type", guessMIMEType(filterDoc)); + + try { + OutputStream out = resp.getOutputStream(); + + byte [] buf = new byte[4096]; + int i = -1; + while ((i = in.read(buf)) >= 0) { + out.write(buf, 0, i); + } + out.flush(); + } + catch (IOException ioe) { + log.error(ioe); + } + finally { + try { in.close(); } + catch (IOException ioe) { /* ignored */ } + } + } + + protected static String guessMIMEType(Document document) { + + NodeList formats = document.getElementsByTagName("format"); + + String format = "png"; + + if (formats.getLength() > 0) { + String type = ((Element)formats.item(0)).getAttribute("type"); + if (type.length() > 0) { + format = type; + } + } + + return "image/" + format; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/CSVExportServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,96 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import java.io.Reader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import au.com.bytecode.opencsv.CSVReader; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.CSVExportService; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class CSVExportServiceImpl +extends RemoteServiceServlet +implements CSVExportService +{ + private static final Logger logger = + Logger.getLogger(CSVExportServiceImpl.class); + + + public static final String ERROR_NO_EXPORT_FOUND = + "error_no_export_found"; + + public List<String[]> getCSV( + String locale, + String uuid, + String name) + throws ServerException + { + logger.info("CSVExportServiceImpl.getCSV"); + + String url = getServletContext().getInitParameter("server-url"); + + Document requestDoc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + requestDoc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element action = ec.create("action"); + ec.addAttr(action, "type", "csv", true); + ec.addAttr(action, "name", name, true); + + requestDoc.appendChild(action); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + InputStream in = client.collectionOut(requestDoc, uuid, "export"); + Reader reader = new InputStreamReader (in, "UTF-8"); + CSVReader csvReader = new CSVReader (reader); + + List<String[]> lines = new ArrayList<String[]>(); + String[] line = null; + + while ((line = csvReader.readNext()) != null) { + if (line != null) { + if (!line[0].startsWith("#") && line.length > 0) { + if (line[0].replace("'", "").length() > 0) { + lines.add(line); + } + } + } + } + + return lines; + } + catch (IOException ce) { + logger.error(ce.getLocalizedMessage()); + } + + throw new ServerException(ERROR_NO_EXPORT_FOUND); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/CapabilitiesParser.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,401 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Capabilities; +import de.intevation.flys.client.shared.model.ContactInformation; +import de.intevation.flys.client.shared.model.WMSLayer; + + +public class CapabilitiesParser { + + private static final Logger logger = + Logger.getLogger(CapabilitiesParser.class); + + + public static final String ERR_GC_REQUEST_FAILED = + "error_gc_req_failed"; + + public static final String ERR_GC_DOC_NOT_VALID = + "error_gc_doc_not_valid"; + + public static final String ERR_MALFORMED_URL = + "error_malformed_url"; + + + public static final String XPATH_WMS_CAPS = + "/WMS_Capabilities"; + + public static final String XPATH_WMT_CAPS = + "/WMT_MS_Capabilities"; + + public static final String XPATH_TITLE = + "Service/Title/text()"; + + public static final String XPATH_ONLINE_RESOURCE = + "Service/OnlineResource/@href"; + + public static final String XPATH_CONTACT_INFORMATION = + "Service/ContactInformation"; + + public static final String XPATH_CI_PERSON = + "ContactPersonPrimary/ContactPerson/text()"; + + public static final String XPATH_CI_ORGANIZATION = + "ContactPersonPrimary/ContactOrganization/text()"; + + public static final String XPATH_CI_ADDRESS = + "ContactAddress/Address/text()"; + + public static final String XPATH_CI_CITY = + "ContactAddress/City/text()"; + + public static final String XPATH_CI_POSTCODE = + "ContactAddress/PostCode/text()"; + + public static final String XPATH_CI_PHONE = + "ContactVoiceTelephone/text()"; + + public static final String XPATH_CI_EMAIL = + "ContactElectronicMailAddress/text()"; + + public static final String XPATH_FEES = + "Service/Fees/text()"; + + public static final String XPATH_ACCESS_CONSTRAINTS = + "Service/AccessConstraints/text()"; + + public static final String XPATH_LAYERS = + "Capability/Layer"; + + public static final Pattern SRS_PATTERN = Pattern.compile("(EPSG:\\d+)*"); + + + private CapabilitiesParser() { + } + + + public static void main(String[] args) { + logger.info("Do static Capabilities request/parsing."); + + String log4jProperties = System.getenv(BaseServletContextListener.LOG4J_PROPERTIES); + LoggingConfigurator.init(log4jProperties); + + try { + Capabilities caps = getCapabilities(System.getProperty("test.wms")); + + logger.debug(caps.toString()); + } + catch (ServerException se) { + se.printStackTrace(); + } + + logger.info("Finished fetching capabiltiies."); + } + + + public static Capabilities getCapabilities(String urlStr) + throws ServerException + { + try { + URL url = new URL(urlStr); + + logger.debug("Open connection to url: " + urlStr); + + URLConnection conn = url.openConnection(); + conn.connect(); + + InputStream is = conn.getInputStream(); + + return parse(is); + } + catch (MalformedURLException mue) { + logger.warn(mue, mue); + throw new ServerException(ERR_MALFORMED_URL); + } + catch (IOException ioe) { + logger.warn(ioe, ioe); + } + + throw new ServerException(ERR_GC_REQUEST_FAILED); + } + + + protected static Capabilities parse(InputStream is) + throws ServerException + { + logger.debug("GCServiceImpl.parseCapabilitiesResponse"); + + Document doc = XMLUtils.parseDocument(is, false); + + if (doc == null) { + throw new ServerException(ERR_GC_DOC_NOT_VALID); + } + + return CapabilitiesParser.parse(doc); + } + + + public static Capabilities parse(Document doc) + throws ServerException + { + Node capabilities = getCapabilitiesNode(doc); + + String title = (String) XMLUtils.xpath( + capabilities, + XPATH_TITLE, + XPathConstants.STRING); + + String onlineResource = (String) XMLUtils.xpath( + capabilities, + XPATH_ONLINE_RESOURCE, + XPathConstants.STRING); + + String fees = (String) XMLUtils.xpath( + capabilities, + XPATH_FEES, + XPathConstants.STRING); + + String accessConstraints = (String) XMLUtils.xpath( + capabilities, + XPATH_ACCESS_CONSTRAINTS, + XPathConstants.STRING); + + Node contactInformation = (Node) XMLUtils.xpath( + capabilities, + XPATH_CONTACT_INFORMATION, + XPathConstants.NODE); + + ContactInformation ci = parseContactInformation(contactInformation); + + logger.debug("Found fees: " + fees); + logger.debug("Found access constraints: " + accessConstraints); + + NodeList layerNodes = (NodeList) XMLUtils.xpath( + capabilities, + XPATH_LAYERS, + XPathConstants.NODESET); + + List<WMSLayer> layers = parseLayers(layerNodes, onlineResource); + + return new Capabilities( + title, + onlineResource, + ci, + fees, + accessConstraints, + layers); + } + + + protected static Node getCapabilitiesNode(Document doc) + throws ServerException { + Node capabilities = (Node) XMLUtils.xpath( + doc, + XPATH_WMS_CAPS, + XPathConstants.NODE); + + if (capabilities == null) { + logger.info("No '/WMS_Capabilities' node found."); + logger.info("Try to find a '/WMT_MS_Capabilities' node."); + + capabilities = (Node) XMLUtils.xpath( + doc, + XPATH_WMT_CAPS, + XPathConstants.NODE); + } + + if (capabilities == null) { + throw new ServerException(ERR_GC_DOC_NOT_VALID); + } + + return capabilities; + } + + + protected static ContactInformation parseContactInformation(Node node) { + String person = (String) XMLUtils.xpath( + node, + XPATH_CI_PERSON, + XPathConstants.STRING); + + String organization = (String) XMLUtils.xpath( + node, + XPATH_CI_ORGANIZATION, + XPathConstants.STRING); + + String address = (String) XMLUtils.xpath( + node, + XPATH_CI_ADDRESS, + XPathConstants.STRING); + + String postcode = (String) XMLUtils.xpath( + node, + XPATH_CI_POSTCODE, + XPathConstants.STRING); + + String city = (String) XMLUtils.xpath( + node, + XPATH_CI_CITY, + XPathConstants.STRING); + + String phone = (String) XMLUtils.xpath( + node, + XPATH_CI_PHONE, + XPathConstants.STRING); + + String email = (String) XMLUtils.xpath( + node, + XPATH_CI_EMAIL, + XPathConstants.STRING); + + ContactInformation ci = new ContactInformation(); + ci.setPerson(person); + ci.setOrganization(organization); + ci.setAddress(address); + ci.setPostcode(postcode); + ci.setCity(city); + ci.setPhone(phone); + ci.setEmail(email); + + return ci; + } + + + /** + * @param layersNode + * @param onlineResource + * + * @return + */ + protected static List<WMSLayer> parseLayers( + NodeList layersNode, + String onlineResource + ) { + int len = layersNode != null ? layersNode.getLength() : 0; + + logger.debug("Node has " + len + " layers."); + + List<WMSLayer> layers = new ArrayList<WMSLayer>(len); + + for (int i = 0; i < len; i++) { + layers.add(parseLayer(layersNode.item(i), onlineResource)); + } + + return layers; + } + + + protected static WMSLayer parseLayer(Node layerNode, String onlineResource) { + String title = (String) XMLUtils.xpath( + layerNode, + "Title/text()", + XPathConstants.STRING); + + String name = (String) XMLUtils.xpath( + layerNode, + "Name/text()", + XPathConstants.STRING); + + logger.debug("Found layer: " + title + "(" + name + ")"); + + List<String> srs = parseSRS(layerNode); + + NodeList layersNodes = (NodeList) XMLUtils.xpath( + layerNode, + "Layer", + XPathConstants.NODESET); + + List<WMSLayer> layers = parseLayers(layersNodes, onlineResource); + + return new WMSLayer(onlineResource, title, name, srs, layers); + } + + + protected static List<String> parseSRS(Node layerNode) { + NodeList srsNodes = ((Element) layerNode).getElementsByTagName("SRS"); + + if (srsNodes.getLength() == 0) { + srsNodes = ((Element) layerNode).getElementsByTagName("CRS"); + + if (srsNodes.getLength() == 0) { + logger.debug("No explicit SRS for this layer specified."); + return null; + } + } + + List<String> allSRS = new ArrayList<String>(); + + for (int i = 0, n = srsNodes.getLength(); i < n; i++) { + List<String> srs = parseSRSItem(srsNodes.item(i).getTextContent()); + + if (srs != null && srs.size() > 0) { + allSRS.addAll(srs); + } + } + + return allSRS; + } + + + protected static List<String> parseSRSItem(String srsStr) { + if (srsStr == null || srsStr.length() == 0) { + return null; + } + + List<String> allSRS = new ArrayList<String>(); + + if (srsStr.indexOf(" ") <= 0) { + String srs = getSRSFromString(srsStr); + if (srs != null && srs.length() > 0) { + allSRS.add(srs); + } + + return allSRS; + } + + String[] splittedSrs = srsStr.split(" "); + + for (String singleSrs: splittedSrs) { + String srs = getSRSFromString(singleSrs); + if (srs != null && srs.length() > 0) { + allSRS.add(srs); + } + } + + return allSRS; + } + + + protected static String getSRSFromString(String singleSrs) { + Matcher m = SRS_PATTERN.matcher(singleSrs); + + if (m.matches()) { + logger.debug("Found SRS '" + m.group(1) + "'"); + return m.group(1); + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ChartInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,283 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.Transform2D; +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Axis; +import de.intevation.flys.client.shared.model.DateAxis; +import de.intevation.flys.client.shared.model.NumberAxis; +import de.intevation.flys.client.shared.model.ChartInfo; +import de.intevation.flys.client.shared.model.Collection; + +import de.intevation.flys.client.client.services.ChartInfoService; + + +/** + * This service fetches a document that contains meta information for a specific + * chart. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartInfoServiceImpl +extends RemoteServiceServlet +implements ChartInfoService +{ + private static final Logger logger = + Logger.getLogger(ChartInfoServiceImpl.class); + + public static final String XPATH_TRANSFORM_MATRIX = + "/art:chartinfo/art:transformation-matrix/art:matrix"; + + public static final String XPATH_X_AXES = + "/art:chartinfo/art:axes/art:domain"; + + public static final String XPATH_Y_AXES = + "/art:chartinfo/art:axes/art:range"; + + public static final String EXCEPTION_STRING = "error_chart_info_service"; + + + public ChartInfo getChartInfo( + Collection collection, + String locale, + String type, + Map<String, String> attr) + throws ServerException + { + logger.info("ChartInfoServiceImpl.getChartInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document request = ClientProtocolUtils.newOutCollectionDocument( + collection.identifier(), + type, + type, + ChartServiceHelper.getChartAttributes(attr)); + + try { + HttpClient client = new HttpClientImpl(url, locale); + InputStream in = client.collectionOut( + request, + collection.identifier(), + type + "_chartinfo"); + + Document info = XMLUtils.parseDocument(in); + + return parseInfoDocument(info); + } + catch (IOException ioe) { + ioe.printStackTrace(); + } + catch (Exception e) { + e.printStackTrace(); + } + + logger.debug("Error while fetching chart info."); + + throw new ServerException(EXCEPTION_STRING); + } + + + /** + * Parse ChartInfo-Part of document, create Transforms and axes + * from it. + */ + protected ChartInfo parseInfoDocument(Document doc) { + Transform2D[] transformer = parseTransformationMatrix(doc); + Axis[] xAxes = parseXAxes(doc); + Axis[] yAxes = parseYAxes(doc); + + return new ChartInfo(xAxes, yAxes, transformer); + } + + + protected Axis[] parseXAxes(Document doc) { + logger.debug("ChartInfoServiceImpl.parseXAxes"); + + NodeList axes = (NodeList) XMLUtils.xpath( + doc, + XPATH_X_AXES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + return parseAxes(axes); + } + + + protected Axis[] parseYAxes(Document doc) { + logger.debug("ChartInfoServiceImpl.parseYAxes"); + + NodeList axes = (NodeList) XMLUtils.xpath( + doc, + XPATH_Y_AXES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + return parseAxes(axes); + } + + + protected Axis[] parseAxes(NodeList axes) { + logger.debug("ChartInfoServiceImpl.parseAxes"); + + int count = axes != null ? axes.getLength() : 0; + + logger.debug("Chart has " + count + " axes."); + + if (count == 0) { + return null; + } + + Axis[] result = new Axis[count]; + + String ns = ArtifactNamespaceContext.NAMESPACE_URI; + + for (int i = 0; i < count; i++) { + Element node = (Element) axes.item(i); + + String posStr = node.getAttributeNS(ns, "pos"); + String fromStr = node.getAttributeNS(ns, "from"); + String toStr = node.getAttributeNS(ns, "to"); + String minStr = node.getAttributeNS(ns, "min"); + String maxStr = node.getAttributeNS(ns, "max"); + String axisType = node.getAttributeNS(ns, "axistype"); + + try { + int pos = Integer.parseInt(posStr); + + if (pos >= result.length) { + // this should never happen + logger.debug("The axis is out of valid range: " + pos); + continue; + } + + if (axisType != null && axisType.equals(DateAxis.TYPE)) { + long from = Long.parseLong(fromStr); + long to = Long.parseLong(toStr); + long min = Long.parseLong(minStr); + long max = Long.parseLong(maxStr); + + if (logger.isDebugEnabled()) { + logger.debug("date axis from: " + new Date(from)); + logger.debug("date axis to : " + new Date(to)); + logger.debug("date axis min : " + new Date(min)); + logger.debug("date axis max : " + new Date(max)); + } + + result[pos] = new DateAxis(pos, from, to, min, max); + } + else { + double from = Double.parseDouble(fromStr); + double to = Double.parseDouble(toStr); + double min = Double.parseDouble(minStr); + double max = Double.parseDouble(maxStr); + + result[pos] = new NumberAxis(pos, from, to, min, max); + } + } + catch (NumberFormatException nfe) { + nfe.printStackTrace(); + } + } + + logger.debug("Parsed " + result.length + " axes"); + + return result; + } + + + /** + * Parses the chart info document and extract the Transform2D values. + * + * @param doc The chart info document. + * + * @return a Transform2D object to transfrom pixel coordinates into chart + * coordinates. + */ + protected Transform2D[] parseTransformationMatrix(Document doc) { + logger.debug("ChartInfoServiceImpl.parseTransformationMatrix"); + + NodeList matrix = (NodeList) XMLUtils.xpath( + doc, + XPATH_TRANSFORM_MATRIX, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = matrix != null ? matrix.getLength() : 0; + + List<Transform2D> transformer = new ArrayList<Transform2D>(num); + + for (int i = 0; i < num; i++) { + Transform2D t = createTransformer((Element) matrix.item(i)); + + if (t == null) { + logger.warn("Broken transformation matrix at pos: " + i); + continue; + } + + transformer.add(t); + } + + return transformer.toArray(new Transform2D[num]); + } + + + protected Transform2D createTransformer(Element matrix) { + String ns = ArtifactNamespaceContext.NAMESPACE_URI; + + String sx = matrix.getAttributeNS(ns, "sx"); + String sy = matrix.getAttributeNS(ns, "sy"); + String tx = matrix.getAttributeNS(ns, "tx"); + String ty = matrix.getAttributeNS(ns, "ty"); + String xType = matrix.getAttributeNS(ns, "xtype"); + String yType = matrix.getAttributeNS(ns, "ytype"); + + xType = xType == null || xType.length() == 0 ? "number" : xType; + yType = yType == null || yType.length() == 0 ? "number" : yType; + + if (sx != null && sy != null && tx != null && ty != null) { + try { + logger.debug("Create new Transform2D with x format: " + xType); + logger.debug("Create new Transform2D with y format: " + yType); + + return new Transform2D( + Double.parseDouble(sx), + Double.parseDouble(sy), + Double.parseDouble(tx), + Double.parseDouble(ty), + xType, yType); + } + catch (NumberFormatException nfe) { + logger.warn("Error while parsing matrix values."); + } + } + + logger.warn("No matrix values found."); + + return new Transform2D(1d, 1d, 0d, 0d); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,151 @@ +package de.intevation.flys.client.server; + +import java.io.OutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + + +/** + * This service is used to request a chart from the artifact server. The + * response is directed directly to the output stream, so the image that is + * retrieved is displayed in the UI afterwards. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartOutputServiceImpl +extends HttpServlet +{ + private static final Logger logger = + Logger.getLogger(ChartOutputServiceImpl.class); + + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + logger.info("ChartOutputServiceImpl.doGet"); + + try { + OutputStream out = resp.getOutputStream(); + + String url = getServletContext().getInitParameter("server-url"); + + String uuid = req.getParameter("uuid"); + String type = req.getParameter("type"); + String locale = req.getParameter("locale"); + + prepareHeader(req, resp); + + Document request = ClientProtocolUtils.newOutCollectionDocument( + uuid, type, type, + ChartServiceHelper.getChartAttributes(prepareChartAttributes(req))); + + HttpClient client = new HttpClientImpl(url, locale); + client.collectionOut(request, uuid, "chart", out); + + out.close(); + out.flush(); + } + catch (IOException ioe) { + logger.error(ioe, ioe); + } + catch (Exception e) { + logger.error(e, e); + } + } + + + protected Map<String, String> prepareChartAttributes(HttpServletRequest req) { + Map<String, String> attr = new HashMap<String, String>(); + + Map params = req.getParameterMap(); + + attr.put("width", req.getParameter("width")); + attr.put("height", req.getParameter("height")); + attr.put("minx", req.getParameter("minx")); + attr.put("maxx", req.getParameter("maxx")); + attr.put("miny", req.getParameter("miny")); + attr.put("maxy", req.getParameter("maxy")); + attr.put("format", req.getParameter("format")); + attr.put("km", req.getParameter("currentKm")); + + if (logger.isDebugEnabled()) { + logger.debug("====== ZOOM VALUES ======="); + logger.debug(" min x: " + req.getParameter("minx")); + logger.debug(" max x: " + req.getParameter("maxx")); + logger.debug(" min y: " + req.getParameter("miny")); + logger.debug(" max y: " + req.getParameter("maxy")); + } + + return attr; + } + + + protected void prepareHeader( + HttpServletRequest req, + HttpServletResponse resp + ) { + String export = req.getParameter("export"); + + if (export != null && export.equals("true")) { + String format = req.getParameter("format"); + + if (format == null || format.length() == 0) { + format = "png"; + } + + String fn = "chart_export" + getFileExtension(format); + + resp.setHeader("Content-Disposition", "attachment;filename=" + fn); + resp.setHeader("Content-Type", getMimeType(format)); + } + } + + + protected String getFileExtension(String format) { + if (format.equals("png")) { + return ".png"; + } + else if (format.equals("pdf")) { + return ".pdf"; + } + else if (format.equals("svg")) { + return ".svg"; + } + else if (format.equals("csv")) { + return ".csv"; + } + + return ".png"; + } + + + protected String getMimeType(String format) { + if (format.equals("png")) { + return "image/png"; + } + else if (format.equals("pdf")) { + return "application/pdf"; + } + else if (format.equals("svg")) { + return "svg+xml"; + } + else if (format.equals("csv")) { + return "text/plain"; + } + + return "image/png"; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ChartServiceHelper.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,217 @@ +package de.intevation.flys.client.server; + +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartServiceHelper { + + private static final Logger logger = + Logger.getLogger(ChartServiceHelper.class); + + + /** The default chart width if no value is specified in the request.*/ + public static final int DEFAULT_CHART_WIDTH = 600; + + /** The default chart height if no value is specified in the request.*/ + public static final int DEFAULT_CHART_HEIGHT = 400; + + + private ChartServiceHelper() { + } + + /** + * This method returns a document which might contain parameters to adjust + * chart settings. The document is created using the information that are + * contained in the request object. + * + * @param req The request document. + * + * @return a document to adjust chart settings. + */ + protected static Document getChartAttributes(Map<String, String> req) { + logger.debug("ChartServiceHelper.getChartAttributes"); + + Document doc = XMLUtils.newDocument(); + + ElementCreator ec = new ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element attributes = ec.create("attributes"); + + appendChartSize(req, attributes, ec); + appendFormat(req, attributes, ec); + appendXRange(req, attributes, ec); + appendYRange(req, attributes, ec); + appendCurrentKm(req, attributes, ec); + + doc.appendChild(attributes); + + return doc; + } + + + /** + * This method extracts the size (width/height) of a chart from request + * object and append those values - if they exist - to the attribute + * document used to adjust chart settings. + * + * @param req The request object that might contain the chart size. + * @param attributes The attributes element used to adjust chart settings. + * @param ec The ElementCreator that might be used to create new Elements. + */ + protected static void appendChartSize( + Map<String, String> req, + Element attributes, + ElementCreator ec) + { + logger.debug("ChartServiceHelper.appendChartSize"); + + Element size = ec.create("size"); + + String width = req.get("width"); + String height = req.get("height"); + + if (width == null || height == null) { + width = String.valueOf(DEFAULT_CHART_WIDTH); + height = String.valueOf(DEFAULT_CHART_HEIGHT); + } + + ec.addAttr(size, "width", width, true); + ec.addAttr(size, "height", height, true); + + attributes.appendChild(size); + } + + + /** + * This method extracts the x range for the chart from request object and + * appends those range - if it exists - to the attribute document used to + * adjust the chart settings. + * + * @param req The request object that might contain the chart size. + * @param doc The attribute document used to adjust chart settings. + * @param ec The ElementCreator that might be used to create new Elements. + */ + protected static void appendXRange( + Map<String, String> req, + Element attributes, + ElementCreator ec) + { + logger.debug("ChartServiceHelper.appendXRange"); + + Element range = ec.create("xrange"); + + String from = req.get("minx"); + String to = req.get("maxx"); + + if (from != null && to != null) { + ec.addAttr(range, "from", from, true); + ec.addAttr(range, "to", to, true); + + attributes.appendChild(range); + } + } + + + /** + * This method extracts the x range for the chart from request object and + * appends those range - if it exists - to the attribute document used to + * adjust the chart settings. + * + * @param req The request object that might contain the chart size. + * @param doc The attribute document used to adjust chart settings. + * @param ec The ElementCreator that might be used to create new Elements. + */ + protected static void appendYRange( + Map<String, String> req, + Element attributes, + ElementCreator ec) + { + logger.debug("ChartServiceHelper.appendYRange"); + + Element range = ec.create("yrange"); + + String from = req.get("miny"); + String to = req.get("maxy"); + + if (from != null && to != null) { + ec.addAttr(range, "from", from, true); + ec.addAttr(range, "to", to, true); + + attributes.appendChild(range); + } + } + + + /** + * This method extracts the format string from request object and appends + * those format - if existing - to the attribute document used to adjust + * the chart settings. + * + * @param req The request object that might contain the chart format. + * @param doc The attribute document used to adjust chart settings. + * @param ec The ElementCreator that might be used to create new Elements. + */ + protected static void appendFormat( + Map<String, String> req, + Element attributes, + ElementCreator ec + + ) { + logger.debug("ChartServiceHelper.appendFormat"); + + String formatStr = req.get("format"); + if (formatStr == null || formatStr.length() == 0) { + return; + } + + Element format = ec.create("format"); + ec.addAttr(format, "value", formatStr, true); + + attributes.appendChild(format); + } + + + /** + * This method extracts the current km for the chart from request object and + * appends this km - if it exists - to the attribute document used to + * adjust the chart settings. + * + * @param req The request object that might contain the chart size. + * @param doc The attribute document used to adjust chart settings. + * @param ec The ElementCreator that might be used to create new Elements. + */ + protected static void appendCurrentKm( + Map<String, String> req, + Element attributes, + ElementCreator ec) + { + logger.debug("ChartServiceHelper.appendCurrentKm"); + + Element currentKm = ec.create("currentKm"); + + String km = req.get("km"); + + if (km != null) { + ec.addAttr(currentKm, "km", km, true); + + attributes.appendChild(currentKm); + } + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/CollectionAttributeServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,65 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + +import de.intevation.flys.client.client.services.CollectionAttributeService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CollectionAttributeServiceImpl +extends DescribeCollectionServiceImpl +implements CollectionAttributeService +{ + private static final Logger logger = + Logger.getLogger(CollectionAttributeServiceImpl.class); + + + public static final String ERROR_UPDATING_COLLECTION_ATTRIBUTE = + "error_update_collection_attribute"; + + + public Collection update(Collection collection, String locale) + throws ServerException + { + logger.info("CollectionAttributeServiceImpl.update"); + + String url = getServletContext().getInitParameter("server-url"); + + Document attribute = CollectionHelper.createAttribute(collection); + Document action = ClientProtocolUtils.newSetAttributeDocument( + collection.identifier(), + attribute); + + try { + HttpClient http = new HttpClientImpl(url, locale); + Document res = (Document) http.doCollectionAction( + action, + collection.identifier(), + new DocumentResponseHandler()); + + logger.debug("Collection attribute successfully set."); + + return describe(collection.identifier(), locale); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_UPDATING_COLLECTION_ATTRIBUTE); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/CollectionHelper.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,1082 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.AttributedTheme; +import de.intevation.flys.client.shared.model.ChartMode; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; +import de.intevation.flys.client.shared.model.DefaultCollection; +import de.intevation.flys.client.shared.model.DefaultCollectionItem; +import de.intevation.flys.client.shared.model.DefaultFacet; +import de.intevation.flys.client.shared.model.ExportMode; +import de.intevation.flys.client.shared.model.Facet; +import de.intevation.flys.client.shared.model.MapMode; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.OverviewMode; +import de.intevation.flys.client.shared.model.ReportMode; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertyGroup; +import de.intevation.flys.client.shared.model.PropertySetting; +import de.intevation.flys.client.shared.model.StringProperty; +import de.intevation.flys.client.shared.model.DoubleProperty; +import de.intevation.flys.client.shared.model.IntegerProperty; +import de.intevation.flys.client.shared.model.BooleanProperty; +import de.intevation.flys.client.shared.model.OutputSettings; + +//temporary + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CollectionHelper { + + private static final Logger logger = + Logger.getLogger(CollectionHelper.class); + + public static final String ERROR_ADD_ARTIFACT = "error_add_artifact"; + + public static final String ERROR_REMOVE_ARTIFACT = "error_remove_artifact"; + + public static final String XPATH_FACETS = "art:facets/art:facet"; + + public static final String XPATH_LOADED_RECOMMENDATIONS = + "/art:artifact-collection/art:attribute/art:loaded-recommendations/art:recommendation"; + + + public static Document createAttribute(Collection collection) { + logger.debug("CollectionHelper.createAttribute"); + + Document doc = XMLUtils.newDocument(); + + ElementCreator cr = new ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element attr = cr.create("attribute"); + + doc.appendChild(attr); + + Map<String, OutputMode> tmpOuts = collection.getOutputModes(); + + Element outs = createOutputElements(cr, collection, tmpOuts); + Element recs = createRecommendationsElements(cr, collection); + + if (outs != null) { + attr.appendChild(outs); + } + + if (recs != null) { + attr.appendChild(recs); + } + + return doc; + } + + + /** + * Creates a whole block with art:output nodes. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * @param modes The OutputModes that should be included. + * + * @return an element with output modes. + */ + protected static Element createOutputElements( + ElementCreator cr, + Collection c, + Map<String, OutputMode> mmodes) + { + logger.debug("CollectionHelper.createOutputElements"); + + java.util.Collection<OutputMode> modes = mmodes != null + ? mmodes.values() + : null; + + if (modes == null || modes.size() == 0) { + logger.debug("Collection has no modes: " + c.identifier()); + return null; + } + + Element outs = cr.create("outputs"); + + for (OutputMode mode: modes) { + Element out = createOutputElement(cr, c, mode); + + if (out != null) { + outs.appendChild(out); + } + } + + return outs; + } + + + /** + * Create a node art:output that further consist of art:theme nodes. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * @param mode The OutputMode. + * + * @return an element that represents an output mode with its themes. + */ + protected static Element createOutputElement( + ElementCreator cr, + Collection collection, + OutputMode mode) + { + logger.debug("CollectionHelper.createOutputElement"); + + Element out = cr.create("output"); + cr.addAttr(out, "name", mode.getName(), false); + + ThemeList themeList = collection.getThemeList(mode.getName()); + List<Theme> themes = themeList != null ? themeList.getThemes() : null; + + if (themes == null || themes.size() == 0) { + logger.debug("No themes for output mode: " + mode.getName()); + return null; + } + + for (Theme theme: themes) { + Element t = createThemeElement(cr, collection, theme); + + if (t != null) { + out.appendChild(t); + } + } + + Document doc = out.getOwnerDocument(); + + ElementCreator settingscr = new ElementCreator(doc, "", ""); + + Settings settings = collection.getSettings(mode.getName()); + if (settings == null || + settings.getCategories().size() == 0) + { + logger.debug("No settings for output mode: " + mode.getName()); + } + else { + Element s = createSettingsElement(settingscr, collection, settings); + if (s != null) { + out.appendChild(s); + } + } + logger.info(XMLUtils.toString(out)); + return out; + } + + + /** + * Creates a theme node art:theme that represents a curve in a chart or map. + * + * @param cr The ElementCreator used to create new elements. + * @param collection The collection. + * @param theme The theme whose attributes should be written to an element. + * + * @return an element that contains the informtion of the given theme. + */ + protected static Element createThemeElement( + ElementCreator cr, + Collection collection, + Theme theme) + { + if (theme == null) { + return null; + } + + Element t = cr.create("facet"); + + if (theme instanceof AttributedTheme) { + AttributedTheme at = (AttributedTheme) theme; + Set<String> keys = at.getKeys(); + + for (String key: keys) { + cr.addAttr(t, key, at.getAttr(key), true); + } + } + else { + cr.addAttr(t, "active", Integer.toString(theme.getActive()), true); + cr.addAttr(t, "artifact", theme.getArtifact(), true); + cr.addAttr(t, "facet", theme.getFacet(), true); + cr.addAttr(t, "pos", Integer.toString(theme.getPosition()), true); + cr.addAttr(t, "index", Integer.toString(theme.getIndex()), true); + cr.addAttr(t, "description", theme.getDescription(), true); + cr.addAttr(t, "visible", Integer.toString(theme.getVisible()), true); + } + + return t; + } + + + /** + * Creates a whole block with art:loaded-recommendations nodes. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * + * @return an element with loaded recommendations. + */ + protected static Element createRecommendationsElements( + ElementCreator cr, + Collection c) + { + logger.debug("CollectionHelper.createRecommendationsElements"); + + List<Recommendation> rs = c.getRecommendations(); + + if (rs == null || rs.size() == 0) { + logger.debug("Collection did not load recommendations: " + + c.identifier()); + return null; + } + + Element loaded = cr.create("loaded-recommendations"); + + for (Recommendation r: rs) { + Element recommendation = createRecommendationElement(cr, c, r); + + if (recommendation != null) { + loaded.appendChild(recommendation); + } + } + + return loaded; + } + + + /** + * Create a node art:recommended. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * @param r The Recommendation. + * + * @return an element that represents an output mode with its themes. + */ + protected static Element createRecommendationElement( + ElementCreator cr, + Collection c, + Recommendation r) + { + logger.debug("CollectionHelper.createRecommendationElement"); + + Element recommendation = cr.create("recommendation"); + cr.addAttr(recommendation, "factory", r.getFactory(), true); + cr.addAttr(recommendation, "ids", r.getIDs(), true); + + return recommendation; + } + + + /** + * + */ + protected static Element createSettingsElement( + ElementCreator cr, + Collection c, + Settings s) + { + logger.debug("CollectionHelper.createSettingsElement"); + Element settings = cr.create("settings"); + + List<String> categories = s.getCategories(); + + for (String category: categories) { + Element cat =cr.create(category); + settings.appendChild(cat); + List<Property> props = s.getSettings(category); + for (Property p: props) { + if (p instanceof PropertyGroup) { + Element prop = createPropertyGroupElement(cr, + (PropertyGroup)p); + cat.appendChild(prop); + } + else if (p instanceof PropertySetting) { + Element prop = createPropertyElement (cr, + (PropertySetting)p); + cat.appendChild(prop); + } + } + } + return settings; + } + + + /** + * + */ + protected static Element createPropertyGroupElement( + ElementCreator cr, + PropertyGroup pg) + { + Element e = cr.create(pg.getName()); + + List<Property> list = pg.getProperties(); + for (Property p: list) { + Element pe = createPropertyElement(cr, (PropertySetting)p); + e.appendChild(pe); + } + return e; + } + + + /** + * + */ + protected static Element createPropertyElement( + ElementCreator cr, + PropertySetting p) + { + Element e = cr.create(p.getName()); + + if(p instanceof BooleanProperty) { + cr.addAttr(e, "type", "boolean", false); + } + else if(p instanceof DoubleProperty) { + cr.addAttr(e, "type", "double", false); + } + else if(p instanceof IntegerProperty) { + cr.addAttr(e, "type", "integer", false); + } + else if(p instanceof StringProperty) { + cr.addAttr(e, "type", "string", false); + } + + e.setTextContent(p.getValue().toString()); + cr.addAttr(e, "display", p.getAttribute("display"), false); + return e; + } + + + /** + * Take the DESCRIBE document of the Collections describe() + * operation and extracts the information about the collection itself and + * the collection items. + * + * @param description The DESCRIBE document of the Collections describe() + * operation. + * + * @return a Collection with CollectionItems. + */ + public static Collection parseCollection(Document description) { + logger.debug("CollectionHelper.parseCollection"); + + if (description == null) { + logger.warn("The DESCRIBE of the Collection is null!"); + return null; + } + + String uuid = XMLUtils.xpathString( + description, + "art:artifact-collection/@art:uuid", + ArtifactNamespaceContext.INSTANCE); + + String ttlStr = XMLUtils.xpathString( + description, + "art:artifact-collection/@art:ttl", + ArtifactNamespaceContext.INSTANCE); + + String name = XMLUtils.xpathString( + description, + "art:artifact-collection/@art:name", + ArtifactNamespaceContext.INSTANCE); + + if (uuid.length() == 0) { + logger.warn("Found an invalid (zero length uuid) Collection!"); + return null; + } + + if (ttlStr.length() == 0) { + logger.warn("Found an invalid Collection (zero length ttl)!"); + return null; + } + + + long ttl = -1; + try { + ttl = Long.valueOf(ttlStr); + } + catch (NumberFormatException nfe) { + // do nothing + } + + List<Recommendation> recommended = parseRecommendations(description); + Map<String, CollectionItem> collectionItems = + new HashMap<String, CollectionItem>(); + + name = (name != null && name.length() > 0) ? name : uuid; + + Collection c = new DefaultCollection(uuid, ttl, name, recommended); + + NodeList items = (NodeList) XMLUtils.xpath( + description, + "art:artifact-collection/art:artifacts/art:artifact", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (items == null || items.getLength() == 0) { + logger.debug("No collection item found for this collection."); + + return c; + } + + int size = items.getLength(); + + for (int i = 0; i < size; i++) { + CollectionItem item = parseCollectionItem( + (Element)items.item(i), + i == 0); + + if (item != null) { + c.addItem(item); + collectionItems.put(item.identifier() ,item); + } + } + + Map<String, ThemeList> themeLists = parseThemeLists(description, collectionItems); + c.setThemeLists(themeLists); + + Map<String, Settings> outSettings = parseSettings(description); + c.setSettings(outSettings); + logger.debug( + "Found " + c.getItemLength() + " collection items " + + "for the Collection '" + c.identifier() + "'."); + + return c; + } + + + /** + * @param collectionItems map to look up collection item mapping a themes + * (artifact) uuid. + */ + protected static Map<String, ThemeList> parseThemeLists( + Document desc, Map<String, CollectionItem> collectionItems + ) { + logger.debug("CollectionHelper.parseThemeLists"); + + NodeList lists = (NodeList) XMLUtils.xpath( + desc, + "/art:artifact-collection/art:attribute/art:outputs/art:output", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = lists != null ? lists.getLength() : 0; + + Map<String, ThemeList> themeList = new HashMap<String, ThemeList>(num); + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + for (int i = 0; i < num; i++) { + Element node = (Element)lists.item(i); + + String outName = node.getAttribute("name"); + + if (outName.length() > 0) { + ThemeList list = parseThemeList(node, collectionItems); + + if (list.getThemeCount() > 0) { + themeList.put(outName, list); + } + } + } + + return themeList; + } + + + /** + * @param collectionItems map to look up collection item mapping a themes + * (artifact) uuid. + */ + protected static ThemeList parseThemeList( + Element node, Map<String, CollectionItem> collectionItems + ) { + logger.debug("CollectionHelper.parseThemeList"); + + NodeList themes = node.getElementsByTagNameNS( + ArtifactNamespaceContext.NAMESPACE_URI, + "facet"); + + int num = themes != null ? themes.getLength() : 0; + + List<Theme> themeList = new ArrayList<Theme>(num); + + for (int i = 0; i < num; i++) { + Theme theme = parseTheme((Element)themes.item(i)); + theme.setCollectionItem(collectionItems.get(theme.getArtifact())); + + if (theme != null) { + themeList.add(theme); + } + } + + return new ThemeList(themeList); + } + + + protected static Theme parseTheme(Element ele) { + logger.debug("CollectionHelper.parseTheme"); + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + NamedNodeMap attrMap = ele.getAttributes(); + int attrNum = attrMap != null ? attrMap.getLength() : 0; + + AttributedTheme t = new AttributedTheme(); + + for (int i = 0; i < attrNum; i++) { + Node attr = attrMap.item(i); + + String prefix = attr.getPrefix(); + String name = attr.getNodeName().replace(prefix + ":", ""); + String value = attr.getNodeValue(); + + t.addAttr(name, value); + } + + return t; + } + + + /** + * Parse Settings elements. + * + * @param description The collection description. + * + * @return Map containing the settings. + */ + protected static Map<String, Settings> parseSettings(Document description) { + logger.info("parseSettings"); + + NodeList lists = (NodeList) XMLUtils.xpath( + description, + "/art:artifact-collection/art:attribute/art:outputs/art:output", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = lists != null ? lists.getLength() : 0; + + Map<String, Settings> list = new HashMap<String, Settings>(num); + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + for (int i = 0; i < num; i++) { + Element node = (Element)lists.item(i); + String outName = node.getAttribute("name"); + Settings s = parseSettings(outName, node); + list.put(outName, s); + } + + return list; + } + + + /** + * From a document, parse the settings for an output and create an + * OutputSettings object. + */ + protected static Settings parseSettings(String outName, Element node) { + OutputSettings set = new OutputSettings(outName); + + NodeList elements = node.getElementsByTagName("settings"); + + if (elements.getLength() == 0 || elements.getLength() > 1) { + return set; + } + + Element settings = (Element)elements.item(0); + + // Get the categories + NodeList catNodes = settings.getChildNodes(); + for (int i = 0; i < catNodes.getLength(); i++) { + Element catNode = (Element)catNodes.item(i); + + // The category name + String category = catNode.getTagName(); + + // list of properties or groups (groups have child nodes). + NodeList list = catNode.getChildNodes(); + + // iterate through all properties or groups. + List<Property> props = new ArrayList<Property> (); + for (int j = 0; j < list.getLength(); j++) { + Property p; + Element e = (Element)list.item(j); + if (e.hasChildNodes() && + e.getFirstChild().getNodeType() != Node.TEXT_NODE) { + p = parseSettingsGroup(e); + } + else { + p = parseSetting(e); + } + props.add(p); + } + set.setSettings(category, props); + } + return set; + } + + + /** + * + */ + protected static Property parseSettingsGroup(Element group) { + PropertyGroup p = new PropertyGroup(); + p.setName(group.getTagName()); + + NodeList list = group.getChildNodes(); + ArrayList<Property> props = new ArrayList<Property>(); + for (int i = 0; i < list.getLength(); i++) { + props.add(parseSetting((Element)list.item(i))); + } + p.setProperties(props); + return p; + } + + + /** + * From a property element create a Property object. + */ + protected static Property parseSetting(Element property){ + NamedNodeMap attrMap = property.getAttributes(); + int attrNum = attrMap != null ? attrMap.getLength() : 0; + + Node type = attrMap.getNamedItem("type"); + String t = type.getNodeValue(); + PropertySetting ps = new PropertySetting(); + + if(t.equals("string")) { + ps = new StringProperty(); + } + else if (t.equals("integer")) { + ps = new IntegerProperty(); + } + else if (t.equals("double")) { + ps = new DoubleProperty(); + } + else if (t.equals("boolean")) { + ps = new BooleanProperty(); + } + ps.setName(property.getTagName()); + ps.setValue(property.getTextContent()); + + for (int i = 0; i < attrNum; i++) { + Node attr = attrMap.item(i); + + String name = attr.getNodeName(); + String value = attr.getNodeValue(); + if(name.equals("type")) { + continue; + } + ps.setAttribute(name, value); + } + return ps; + } + + + /** + * This method extracts the CollectionItem from <i>node</i> with its output + * modes. The output modes are parsed using the parseOutputModes() method. + * + * @param node A node that contains information about a CollectionItem. + * + * @return a CollectionItem. + */ + protected static CollectionItem parseCollectionItem( + Element node, + boolean outs + ) { + logger.debug("CollectionHelper.parseCollectionItem"); + + if (node == null) { + logger.debug("The node for parsing CollectionItem is null!"); + return null; + } + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + String uuid = node.getAttributeNS(uri, "uuid"); + String hash = node.getAttributeNS(uri, "hash"); + + if (uuid == null || uuid.length() == 0) { + logger.warn("Found an invalid CollectionItem!"); + return null; + } + + List<OutputMode> modes = new ArrayList<OutputMode>(); + + if (outs) { + NodeList outputmodes = node.getElementsByTagNameNS( + uri, "outputmodes"); + + if (outputmodes.getLength() < 1) { + return null; + } + + Element om = (Element)outputmodes.item(0); + + modes = parseOutputModes(om); + } + + HashMap<String, String> dataItems = new HashMap<String, String>(); + + NodeList dataItemNodes = node.getElementsByTagNameNS( + uri, "data-items"); + + Element di = (Element)dataItemNodes.item(0); + dataItems = parseDataItems(di); + + return new DefaultCollectionItem(uuid, hash, modes, dataItems); + } + + + /** + * This method extracts the OutputModes available for a specific + * CollectionItem and returns them as list. + * + * @param node The root node of the outputmodes list. + * + * @return a list of OutputModes. + */ + protected static List<OutputMode> parseOutputModes(Element node) { + logger.debug("CollectionHelper.parseOutputModes"); + + if (node == null) { + logger.debug("The node for parsing OutputModes is null!"); + return null; + } + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + NodeList list = node.getElementsByTagNameNS(uri, "output"); + + int size = list.getLength(); + + if (size == 0) { + logger.debug("No outputmode nodes found!"); + return null; + } + + List<OutputMode> modes = new ArrayList<OutputMode>(size); + + for (int i = 0; i < size; i++) { + Element tmp = (Element)list.item(i); + + String name = tmp.getAttributeNS(uri, "name"); + String desc = tmp.getAttributeNS(uri, "description"); + String mime = tmp.getAttributeNS(uri, "mime-type"); + String type = tmp.getAttributeNS(uri, "type"); + + if (name.length() == 0) { + logger.warn("Found an invalid output mode."); + continue; + } + + OutputMode outmode = null; + List<Facet> fs = extractFacets(tmp); + + if (type.equals("export")) { + outmode = new ExportMode(name, desc, mime, fs); + } + else if (type.equals("report")) { + outmode = new ReportMode(name, desc, mime, fs); + } + else if (type.equals("chart")){ + outmode = new ChartMode(name, desc, mime, fs, type); + } + else if (type.equals("map")){ + outmode = new MapMode(name, desc, mime, fs); + } + else if (type.equals("overview")) { + outmode = new OverviewMode(name, desc, mime, fs, type); + } + else { + logger.warn("Broken Output mode without type found."); + continue; + } + + modes.add(outmode); + } + + return modes; + } + + + /** + * Create a Key/Value map for data nodes of artifact/collectionitem. + */ + protected static HashMap<String, String> parseDataItems(Element node) { + logger.debug("CollectionHelper.parseDataItems"); + + if (node == null) { + logger.debug("The node for parsing DataItems is null!"); + return null; + } + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + NodeList list = node.getElementsByTagNameNS(uri, "data"); + + int size = list.getLength(); + + if (size == 0) { + logger.debug("No static data-item nodes found!"); + } + + HashMap<String, String> data = new HashMap<String, String>(size*2); + + for (int i = 0; i < size; i++) { + Element tmp = (Element)list.item(i); + + String key = tmp.getAttributeNS(uri, "name"); + + if (key.length() == 0) { + logger.warn("Found an invalid data item mode."); + continue; + } + + // XXX We are restricted on 1/1 key/values in the data map here. + NodeList valueNodes = tmp.getElementsByTagName("art:item"); + + Element item = (Element) valueNodes.item(0); + String value = item.getAttributeNS(uri, "value"); + logger.debug("Found a data item " + key + " : " + value); + + data.put(key, value); + } + + + // Dynamic data. + list = node.getElementsByTagNameNS(uri, "select"); + + size = list.getLength(); + + if (size == 0) { + logger.debug("No dynamic data-item nodes found!"); + } + + for (int i = 0; i < size; i++) { + Element tmp = (Element)list.item(i); + + String key = tmp.getAttributeNS(uri, "name"); + + if (key.length() == 0) { + logger.warn("Found an invalid data item node (missing key)."); + continue; + } + + String value = tmp.getAttributeNS(uri, "defaultValue"); + + if (value.length() == 0) { + logger.warn("Found an invalid data item node (missing value)."); + continue; + } + + logger.debug("Found a (dyn) data item " + key + " : " + value); + + data.put(key, value); + } + + return data; + } + + protected static List<Facet> extractFacets(Element outmode) { + logger.debug("CollectionHelper - extractFacets()"); + + NodeList facetList = (NodeList) XMLUtils.xpath( + outmode, + XPATH_FACETS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = facetList != null ? facetList.getLength() : 0; + + List<Facet> facets = new ArrayList<Facet>(num); + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + for (int i = 0; i < num; i++) { + Element facetEl = (Element) facetList.item(i); + + String name = facetEl.getAttributeNS(uri, "name"); + String desc = facetEl.getAttributeNS(uri, "description"); + String index = facetEl.getAttributeNS(uri, "index"); + + if (name != null && name.length() > 0 && index != null) { + facets.add(new DefaultFacet(name, Integer.valueOf(index),desc)); + } + } + + return facets; + } + + + public static List<Recommendation> parseRecommendations(Document doc) { + logger.debug("CollectionHelper.parseRecommendations"); + + NodeList list = (NodeList) XMLUtils.xpath( + doc, + XPATH_LOADED_RECOMMENDATIONS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = list != null ? list.getLength() : 0; + + List<Recommendation> recs = new ArrayList<Recommendation>(num); + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + for (int i = 0; i < num; i++) { + Element rec = (Element) list.item(i); + + String factory = rec.getAttributeNS(uri, "factory"); + String dbids = rec.getAttributeNS(uri, "ids"); + + if (factory != null && factory.length() > 0) { + recs.add(new Recommendation(factory, dbids)); + } + } + + return recs; + } + + + /** + * Add an artifact to a collection. + * @param collection Collection to add artifact to. + * @param artifact Artifact to add to collection + */ + public static Collection addArtifact( + Collection collection, + Artifact artifact, + String url, + String locale) + throws ServerException + { + logger.debug("CollectionHelper.addArtifact"); + + if (collection == null) { + logger.warn("The given Collection is null!"); + return null; + } + + Document add = ClientProtocolUtils.newAddArtifactDocument( + artifact.getUuid(), null); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + logger.debug("Do HTTP request now."); + + Document response = (Document) client.doCollectionAction( + add, collection.identifier(), new DocumentResponseHandler()); + + logger.debug( + "Finished HTTP request successfully. Parse Collection now."); + + Collection c = CollectionHelper.parseCollection(response); + + if (c == null) { + throw new ServerException(ERROR_ADD_ARTIFACT); + } + + return c; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + catch (Exception e) { + logger.error(e, e); + } + + throw new ServerException(ERROR_ADD_ARTIFACT); + } + + + /** + * Remove an artifact from a collection. + * @param collection Collection to remove artifact to. + * @param artifact Artifact to add to collection + */ + public static Collection removeArtifact( + Collection collection, + String artifactId, + String url, + String locale) + throws ServerException + { + logger.debug("CollectionHelper.removeArtifact"); + + if (collection == null) { + logger.warn("The given Collection is null!"); + return null; + } + + Document remove = ClientProtocolUtils.newRemoveArtifactDocument( + artifactId); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + logger.debug("Do HTTP request now."); + + Document response = (Document) client.doCollectionAction( + remove, collection.identifier(), new DocumentResponseHandler()); + + logger.debug( + "Finished HTTP request successfully. Parse Collection now."); + logger.debug(XMLUtils.toString(response)); + + Collection c = CollectionHelper.parseCollection(response); + + if (c == null) { + throw new ServerException(ERROR_REMOVE_ARTIFACT); + } + + return c; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + catch (Exception e) { + logger.error(e, e); + } + throw new ServerException(ERROR_REMOVE_ARTIFACT); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/CollectionItemAttributeServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,202 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.CollectionItemAttributeService; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItemAttribute; +import de.intevation.flys.client.shared.model.Style; +import de.intevation.flys.client.shared.model.StyleSetting; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class CollectionItemAttributeServiceImpl +extends RemoteServiceServlet +implements CollectionItemAttributeService +{ + private static final Logger logger = + Logger.getLogger(CollectionItemAttributeServiceImpl.class); + + + public static final String XPATH_RESULT = "/art:result/text()"; + + public static final String OPERATION_FAILURE = "FAILED"; + + public static final String ERROR_NO_STYLES_FOUND = + "error_no_theme_styles_found"; + + + public CollectionItemAttribute getCollectionItemAttribute( + Collection collection, + String artifact, + String locale) + throws ServerException + { + logger.info( + "CollectionItemAttributeServiceImpl.getCollectionItemAttribute"); + + String url = getServletContext().getInitParameter("server-url"); + + Document requestDoc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + requestDoc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element action = ec.create("action"); + + Element type = ec.create("type"); + ec.addAttr(type, "name", "getitemattribute", false); + + Element art = ec.create("artifact"); + ec.addAttr(art, "uuid", artifact, false); + + type.appendChild(art); + action.appendChild(type); + requestDoc.appendChild (action); + + try { + HttpClient client = new HttpClientImpl(url, locale); + Document res = (Document) client.doCollectionAction( + requestDoc, + collection.identifier(), + new DocumentResponseHandler()); + return readXML (res, artifact); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_STYLES_FOUND); + } + + + public void setCollectionItemAttribute( + Collection collection, + String artifact, + String locale, + CollectionItemAttribute attributes) + throws ServerException + { + logger.info( + "CollectionItemAttributeServiceImpl.setCollectionItemAttribute"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = writeXML(attributes, artifact); + + try { + HttpClient client = new HttpClientImpl(url, locale); + Document res = (Document) client.doCollectionAction( + doc, + collection.identifier(), + new DocumentResponseHandler()); + + return; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + throw new ServerException(ce.getLocalizedMessage()); + } + } + + protected CollectionItemAttribute readXML(Document doc, String artifact) + throws ServerException + { + CollectionItemAttribute cia = new CollectionItemAttribute(); + cia.setArtifact(artifact); + + Element root = doc.getDocumentElement(); + NodeList themes = root.getElementsByTagName("art:themes"); + + if (themes == null || themes.getLength() == 0) { + throw new ServerException(ERROR_NO_STYLES_FOUND); + } + + Element e = (Element) themes.item(0); + NodeList items = e.getElementsByTagName("theme"); + + for (int i = 0; i < items.getLength(); i++) { + Style s = StyleHelper.getStyle ((Element) items.item(i)); + if(s == null) { + throw new ServerException(ERROR_NO_STYLES_FOUND); + } + else { + cia.appendStyle(s); + } + } + + return cia; + } + + + protected Document writeXML ( + CollectionItemAttribute attributes, + String artifact) + { + Document styles = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + styles, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + Element action = ec.create("action"); + Element type = ec.create("type"); + type.setAttribute("name", "setitemattribute"); + Element art = ec.create("artifact"); + art.setAttribute("uuid", artifact); + Element attr = ec.create("attribute"); + Element themes = ec.create("themes"); + action.appendChild(type); + type.appendChild(art); + art.appendChild(attr); + attr.appendChild(themes); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + styles, + "", + ""); + + for (int i = 0; i < attributes.getNumStyles(); i++) { + Style s = attributes.getStyle(i); + Element theme = creator.create("theme"); + theme.setAttribute("name", s.getName()); + theme.setAttribute("facet", s.getFacet()); + theme.setAttribute("index", String.valueOf(s.getIndex())); + for (int j = 0; j < s.getNumSettings(); j++) { + StyleSetting set = s.getSetting(j); + Element field = creator.create("field"); + field.setAttribute("name", set.getName()); + field.setAttribute("display", set.getDisplayName()); + field.setAttribute("default", set.getDefaultValue()); + field.setAttribute("hints", set.getHints()); + field.setAttribute("type", set.getType()); + field.setAttribute("hidden", String.valueOf(set.isHidden())); + theme.appendChild(field); + } + themes.appendChild(theme); + } + styles.appendChild(action); + return styles; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/CreateCollectionServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,87 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.DefaultCollection; +import de.intevation.flys.client.client.services.CreateCollectionService; + + +/** + * This interface provides the createCollection service to create new + * collections in the artifact server. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CreateCollectionServiceImpl +extends RemoteServiceServlet +implements CreateCollectionService +{ + /** Private logger. */ + private static final Logger logger = + Logger.getLogger(CreateCollectionServiceImpl.class); + + /** XPath to figure out the uuid of the created collection.*/ + public static final String XPATH_COLLECTION_UUID = + "/art:result/art:artifact-collection/@art:uuid"; + + /** XPath to figure out the ttl of the created collection.*/ + public static final String XPATH_COLLECTION_TTL = + "/art:result/art:artifact-collection/@art:ttl"; + + /** Error message key that is thrown if an error occured while creating + * a new collection.*/ + public static final String ERROR_CREATE_COLLECTION = + "error_create_collection"; + + + /** Attempt creation of Collection. */ + public Collection create(String locale, String ownerId) + throws ServerException + { + logger.info("Start creating a new collection."); + + String url = getServletContext().getInitParameter("server-url"); + + Document create = + ClientProtocolUtils.newCreateCollectionDocument(null); + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document doc = (Document) client.createCollection( + create, ownerId, new DocumentResponseHandler()); + + String uuid = XMLUtils.xpathString( + doc, XPATH_COLLECTION_UUID, ArtifactNamespaceContext.INSTANCE); + + String ttlStr = XMLUtils.xpathString( + doc, XPATH_COLLECTION_TTL, ArtifactNamespaceContext.INSTANCE); + + if (uuid.trim().length() == 0 || ttlStr.length() == 0) { + throw new ServerException(ERROR_CREATE_COLLECTION); + } + + return new DefaultCollection(uuid, Long.valueOf(ttlStr), uuid); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_CREATE_COLLECTION); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/CrossSectionKMServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,134 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.CrossSectionKMService; + +/** + * Interact with not documented service. + */ +public class CrossSectionKMServiceImpl +extends RemoteServiceServlet +implements CrossSectionKMService +{ + private static final Logger logger = + Logger.getLogger(CrossSectionKMServiceImpl.class); + + /** XPath that points to the found cross section measurements. */ + public static final String XPATH_CROSS_SECTIONS + = "/cross-sections/cross-section"; + + /** The error message key that is thrown if an error occured while getting + * new data. */ + public static final String ERROR_GET_CROSS_SECTION + = "error_get_cross_section"; + + + /** + * Fetches positions (kms) at which measurements for given cross-sections + * exists. + * + * @param data Map of Integer (cross-section-id) to km. + * + */ + public Map<Integer,Double[]> getCrossSectionKMs( + String locale, + Map<Integer, Double> data, + int nNeighbours) + throws ServerException + { + logger.info("CrossSectionKMService.getCrossSectionKMs"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + Element crossSection = ec.create("cross-sections"); + + doc.appendChild(crossSection); + + for(Map.Entry<Integer, Double> oneCrossSection : data.entrySet()) { + Element cs = ec.create("cross-section"); + cs.setAttribute("id", oneCrossSection.getKey().toString()); + cs.setAttribute("km", oneCrossSection.getValue().toString()); + cs.setAttribute("n", Integer.valueOf(nNeighbours).toString()); + crossSection.appendChild(cs); + } + + HttpClient client = new HttpClientImpl(url, locale); + logger.debug("Created httpclient"); + + try { + // Document should contain: + // crosse-sections: + // attribute(id), attribute(km) attribute(n) + Document response = client.callService(url, "cross-section-km", doc); + //<cross-sections><cross-section id="1"><line km="19.5" line-id="189"/>... + + NodeList nodeList = (NodeList) XMLUtils.xpath(response, + XPATH_CROSS_SECTIONS, + XPathConstants.NODESET); + + int num = nodeList.getLength(); + + Map<Integer, Double[]> result = new HashMap<Integer, Double[]>(); + + try{ + for (int i = 0; i < num; i++) { + Element csElement = (Element) nodeList.item(i); + + int idx = Integer.parseInt(csElement.getAttribute("id")); + ArrayList<Double> kms = new ArrayList<Double>(); + + NodeList lineNodes = csElement.getElementsByTagName("line"); + int numLines = lineNodes.getLength(); + for (int k = 0; k < numLines; k++) { + Element line = (Element) lineNodes.item(k); + double d = Double.parseDouble(line.getAttribute("km")); + kms.add(d); + } + + Double[] doubles = new Double[kms.size()]; + kms.toArray(doubles); + result.put(Integer.valueOf(idx), doubles); + } + } + catch(NumberFormatException nfe) { + logger.error("Response was not parsable"); + } + + return result; + } + catch (ConnectionException ce) { + logger.error("ConnectionExsp", ce); + } + + logger.warn("CrossSectionKMService.getCrossSectionKMS() - FAILED"); + throw new ServerException(ERROR_GET_CROSS_SECTION); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DataFactory.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,341 @@ +package de.intevation.flys.client.server; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.DoubleArrayData; +import de.intevation.flys.client.shared.model.IntegerArrayData; +import de.intevation.flys.client.shared.model.IntegerData; +import de.intevation.flys.client.shared.model.IntegerOptionsData; +import de.intevation.flys.client.shared.model.IntegerRangeData; +import de.intevation.flys.client.shared.model.StringData; +import de.intevation.flys.client.shared.model.StringOptionsData; +import de.intevation.flys.client.shared.model.LongRangeData; + +import de.intevation.flys.client.shared.model.IntDataItem; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DataFactory { + + private static final Logger logger = Logger.getLogger(DataFactory.class); + + public static final String NS_URI = ArtifactNamespaceContext.NAMESPACE_URI; + + + /** + * Creates a new Data instance based on the <i>art:type</i> attribute of + * <i>element</i>. + * + * @param element The Data element. + * + * @return a Data instance. + */ + public static Data createDataFromElement(Element element) { + String name = element.getAttributeNS(NS_URI, "name"); + String type = element.getAttributeNS(NS_URI, "type"); + String label = element.getAttributeNS(NS_URI, "label"); + + label = label != null && label.length() > 0 ? label : name; + + try { + logger.debug("Create Data instance for: " + name + " | " + type); + + if (type == null || type.length() == 0) { + return createDefaultData(element, name, label); + } + + type = type.toLowerCase(); + + if (type.equals(StringData.TYPE)) { + return createStringData(element, name, label); + } + else if (type.equals(IntegerData.TYPE)) { + return createIntegerData(element, name, label); + } + else if (type.equals(StringOptionsData.TYPE)) { + return createStringOptionsData(element, name, label); + } + else if (type.equals(IntegerOptionsData.TYPE)) { + return createIntegerOptionsData(element, name, label); + } + else if (type.equals(IntegerRangeData.TYPE)) { + return createIntegerRangeData(element, name, label); + } + else if (type.equals(IntegerArrayData.TYPE)) { + return createIntegerArrayData(element, name, label); + } + else if (type.equals(DoubleArrayData.TYPE)) { + return createDoubleArrayData(element, name, label); + } + else if (type.equals(LongRangeData.TYPE)) { + return createLongRangeData(element, name, label); + } + else { + return createDefaultData(element, name, label); + } + } + catch (Exception e) { + logger.error("Error while data creation for: " + name); + } + + return null; + } + + + /** + * This method creates a new instance of DefaultData which has no real type + * set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of DefaultData. + */ + protected static Data createDefaultData(Element ele, String name, String label) { + logger.debug("Create new DefaultData"); + return new DefaultData(name, label, "default", extractDataItems(ele)); + } + + + /** + * This method creates a new instance of StringData which has a type + * "string" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of StringData. + */ + protected static Data createStringData(Element ele, String name, String label) { + return new StringData(name, label, extractDataItems(ele)); + } + + + /** + * This method creates a new instance of DefaultData which has a type + * "integer" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of IntegerData. + */ + protected static Data createIntegerData(Element ele, String name, String label) { + return new IntegerData(name, label, extractDataItems(ele)); + } + + + /** + * This method creates a new instance of StringOptionsData which has a type + * "options" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of StringOptionsData. + */ + protected static Data createStringOptionsData(Element ele, String name, String label) { + return new StringOptionsData(name, label, extractDataItems(ele)); + } + + + /** + * This method creates a new instance of DefaultData which has a type + * "intoptions" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of IntegerOptionsData. + */ + protected static Data createIntegerOptionsData(Element ele, String name, String label) { + return new IntegerOptionsData(name, label, extractDataItems(ele)); + } + + + /** + * This method creates a new instance of DefaultData which has a type + * "intrange" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of IntegerRangeData. + */ + protected static Data createIntegerRangeData(Element ele, String name, String label) { + DataItem[] items = extractDataItems(ele); + String rawValue = items[0].getStringValue(); + + String[] minmax = rawValue.split(";"); + + return new IntegerRangeData( + name, + label, + Integer.valueOf(minmax[0]), + Integer.valueOf(minmax[1])); + } + + + /** + * This method creates a new instance of DefaultData which has a type + * "integerarray" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of IntegerArrayData. + */ + protected static Data createIntegerArrayData(Element ele, String name, String label) { + IntDataItem[] items = extractIntDataItems(ele); + return new IntegerArrayData(name, label, items); + } + + + /** + * This method creates a new instance of DefaultData which has a type + * "doublearray" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of DoubleArrayData. + */ + protected static Data createDoubleArrayData(Element ele, String name, String label) { + DataItem[] items = extractDataItems(ele); + String rawValue = items[0].getStringValue(); + + String[] values = rawValue.split(";"); + double[] doubles = new double[values.length]; + + for (int i = 0; i < values.length; i++) { + try { + doubles[i] = Double.valueOf(values[i]); + } + catch (NumberFormatException nfe) { + logger.warn("Error while parsing DoubleArrayData: " + nfe); + } + } + + return new DoubleArrayData(name, label, doubles); + } + + + /** + * This method extracts the art:item elements placed under <i>elements</i>. + * + * @param element A data node that contains items. + * + * @return a list of DataItems. + */ + protected static DataItem[] extractDataItems(Element element) { + NodeList itemList = (NodeList) XMLUtils.xpath( + element, + "art:item", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (itemList == null || itemList.getLength() == 0) { + logger.debug("No data items found."); + return null; + } + + int count = itemList.getLength(); + + DataItem[] items = new DataItem[count]; + + logger.debug("There are " + count + " data items in element."); + + for (int i = 0; i < count; i++) { + Element tmp = (Element) itemList.item(i); + + String value = tmp.getAttributeNS(NS_URI, "value"); + String label = tmp.getAttributeNS(NS_URI, "label"); + + logger.debug("Found data item:"); + logger.debug(" label: " + label); + logger.debug(" value: " + value); + + items[i] = new DefaultDataItem(label, label, value); + } + + return items; + } + + + /** + * This method extracts the art:item elements placed under <i>elements</i>. + * + * @param element A data node that contains items. + * + * @return a list of DataItems. + */ + protected static IntDataItem[] extractIntDataItems(Element element) { + NodeList itemList = (NodeList) XMLUtils.xpath( + element, + "art:item", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (itemList == null || itemList.getLength() == 0) { + logger.debug("No old data items found."); + return null; + } + + int count = itemList.getLength(); + + IntDataItem[] items = new IntDataItem[count]; + + for (int i = 0; i < count; i++) { + Element tmp = (Element) itemList.item(i); + + String value = tmp.getAttributeNS(NS_URI, "value"); + String label = tmp.getAttributeNS(NS_URI, "label"); + + try { + int data = Integer.parseInt(value); + items[i] = new IntDataItem(label, label, data); + } + catch(NumberFormatException nfe) { + logger.debug(nfe, nfe); + } + } + return items; + } + + /** + * This method creates a new instance of LongRangeData which has a type + * "longrange" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of IntegerRangeData. + */ + protected static Data createLongRangeData(Element ele, String name, String label) { + DataItem[] items = extractDataItems(ele); + String rawValue = items[0].getStringValue(); + + String[] minmax = rawValue.split(";"); + + return new LongRangeData( + name, + label, + Long.valueOf(minmax[0]), + Long.valueOf(minmax[1])); + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DeleteCollectionServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.services.DeleteCollectionService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DeleteCollectionServiceImpl +extends DoCollectionAction +implements DeleteCollectionService +{ + private static final Logger logger = + Logger.getLogger(DeleteCollectionServiceImpl.class); + + + public static final String XPATH_RESULT = "/art:result/text()"; + public static final String OPERATION_FAILURE = "FAILED"; + + public void delete(Collection c) + throws ServerException + { + logger.info("Delete collection: " + c.identifier()); + + String url = getServletContext().getInitParameter("server-url"); + + Document del = ClientProtocolUtils.newDeleteCollectionDocument(); + + doAction(c, del, url); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DescribeArtifactServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,75 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.client.services.DescribeArtifactService; + + +/** + * This interface provides artifact specific operation DESCRIBE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DescribeArtifactServiceImpl +extends RemoteServiceServlet +implements DescribeArtifactService +{ + private static final Logger logger = + Logger.getLogger(DescribeArtifactServiceImpl.class); + + + public static final String ERROR_DESCRIBE_ARTIFACT = + "error_describe_artifact"; + + + public Artifact describe(String locale, Artifact artifact) + throws ServerException + { + logger.info("DescribeArtifactServiceImpl.describe"); + + String url = getServletContext().getInitParameter("server-url"); + + Document describe = ClientProtocolUtils.newDescribeDocument( + artifact.getUuid(), + artifact.getHash(), + true); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + logger.debug("Start Http request now."); + + Document description = (Document) client.describe( + new de.intevation.artifacts.httpclient.objects.Artifact( + artifact.getUuid(), + artifact.getHash()), + describe, + new DocumentResponseHandler()); + + if (description != null) { + logger.debug("Finished Http request sucessfully!"); + + return (Artifact) new FLYSArtifactCreator().create(description); + } + } + catch (ConnectionException ce) { + ce.printStackTrace(); + } + + throw new ServerException(ERROR_DESCRIBE_ARTIFACT); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DescribeCollectionServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,76 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + +import de.intevation.flys.client.client.services.DescribeCollectionService; + + +/** + * This service implements a method that queries the DESCRIBE document of a + * specific collection and returns a Collection object with the information of + * the document. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DescribeCollectionServiceImpl +extends RemoteServiceServlet +implements DescribeCollectionService +{ + private static final Logger logger = + Logger.getLogger(DescribeCollectionServiceImpl.class); + + + /** The error message key that is thrown if an error occured while + * describe() a Collection.*/ + public static final String ERROR_DESCRIBE_COLLECTION = + "error_describe_collection"; + + + public Collection describe(String uuid, String locale) + throws ServerException + { + logger.info("DescribeCollectionServiceImpl.describe"); + + String url = getServletContext().getInitParameter("server-url"); + + Document describe = ClientProtocolUtils.newDescribeCollectionDocument( + uuid); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document response = (Document) client.doCollectionAction( + describe, uuid, new DocumentResponseHandler()); + + Collection c = CollectionHelper.parseCollection(response); + + if (c == null) { + throw new ServerException(ERROR_DESCRIBE_COLLECTION); + } + + logger.debug("Collection successfully parsed."); + + return c; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_DESCRIBE_COLLECTION); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DischargeInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,138 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.DischargeInfoService; +import de.intevation.flys.client.shared.model.DischargeInfoObject; +import de.intevation.flys.client.shared.model.DischargeInfoObjectImpl; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DischargeInfoServiceImpl +extends RemoteServiceServlet +implements DischargeInfoService +{ + private static final Logger logger = + Logger.getLogger(DischargeInfoServiceImpl.class); + + public static final String ERROR_NO_DISCHARGEINFO_FOUND = + "error_no_dischargeinfo_found"; + + public static final String XPATH_DISTANCES = "art:discharges/art:discharge"; + + + public DischargeInfoObject[] getDischargeInfo( + String locale, + long gauge) + throws ServerException + { + logger.info("DichargeInfoServiceImpl.getDischargeInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element gaugeEl = ec.create("gauge"); + gaugeEl.setTextContent(String.valueOf(gauge)); + + doc.appendChild(gaugeEl); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document result = client.callService(url, "dischargeinfo", doc); + + logger.debug("Extract discharge info objects now."); + DischargeInfoObject[] objects = extractDischargeInfoObjects(result); + + if (objects != null && objects.length > 0) { + return objects; + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_DISCHARGEINFO_FOUND); + } + + protected DischargeInfoObject[] extractDischargeInfoObjects( + Document result + ) + throws ServerException { + NodeList list = result.getElementsByTagName("discharge"); + + if (list == null || list.getLength() == 0) { + logger.warn("No discharge info found."); + throw new ServerException(ERROR_NO_DISCHARGEINFO_FOUND); + } + + int num = list.getLength(); + logger.debug("Response contains " + num + " objects."); + + List<DischargeInfoObject> objects = + new ArrayList<DischargeInfoObject>(num); + + for (int i = 0; i < num; i++) { + DischargeInfoObject obj = buildDischargeInfoObject( + (Element)list.item(i)); + + if (obj != null) { + objects.add(obj); + } + } + + logger.debug("Retrieved " + objects.size() + " discharges."); + + return (DischargeInfoObject[]) + objects.toArray(new DischargeInfoObject[num]); + + } + + protected DischargeInfoObject buildDischargeInfoObject(Element node) { + + String desc = node.getAttribute("description").trim(); + String start = node.getAttribute("start").trim(); + String end = node.getAttribute("end").trim(); + + if (start.length() > 0 && end.length() > 0) { + try { + Integer startYear = new Integer(start); + Integer endYear = new Integer(end); + return new DischargeInfoObjectImpl(desc, startYear, endYear); + } + catch (NumberFormatException nfe) { + logger.warn(nfe.getLocalizedMessage()); + } + } + + logger.warn("Invalid distance info object found."); + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DischargeInfoXML.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,82 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DischargeInfoXML +extends HttpServlet +{ + private static final Logger logger = Logger.getLogger(DischargeInfoXML.class); + + + public static final String ERROR_NO_DISTANCEINFO_FOUND = + "error_no_dischargeinfo_found"; + + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + logger.info("DischargeInfoXML.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + + String gauge = req.getParameter("gauge"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element gaugeEl = ec.create("gauge"); + gaugeEl.setTextContent(gauge); + + doc.appendChild(gaugeEl); + + HttpClient client = new HttpClientImpl(url); + + try { + InputStream in = (InputStream) client.callService( + url, "dischargeinfo", doc, new StreamResponseHandler()); + + OutputStream out = resp.getOutputStream(); + + byte[] b = new byte[4096]; + int i; + while ((i = in.read(b)) >= 0) { + out.write(b, 0, i); + } + + out.flush(); + out.close(); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + catch (IOException ioe) { + logger.error(ioe, ioe); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DischargeTablesServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,143 @@ +package de.intevation.flys.client.server; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.DateFormat; +import java.util.Date; +import java.util.Locale; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + + +public class DischargeTablesServiceImpl extends HttpServlet { + + private static final Logger logger = Logger + .getLogger(DischargeInfoServiceImpl.class); + + private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( + DateFormat.MEDIUM, Locale.GERMANY); + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + logger.info("ChartOutputServiceImpl.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + String locale = req.getParameter("locale"); + + prepareHeader(req, resp); + + Document requestDoc = createRequestDoc(req); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + OutputStream out = resp.getOutputStream(); + InputStream stream = (InputStream) client.callService(url, + "dischargetablesoverview", requestDoc, + new StreamResponseHandler()); + + byte[] b = new byte[4096]; + try { + int i; + while ((i = stream.read(b)) >= 0) { + out.write(b, 0, i); + } + } + finally { + stream.close(); + } + } + catch (IOException ioe) { + logger.error("Error while fetching discharge tables chart!", ioe); + } + } + + protected void prepareHeader(HttpServletRequest req, + HttpServletResponse resp) { + resp.setHeader("Content-Type", "image/png"); + } + + protected Document createRequestDoc(HttpServletRequest req) { + Document request = XMLUtils.newDocument(); + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(request, + null, null); + + Element service = creator.create("service"); + Element gauge = creator.create("gauge"); + Element extent = creator.create("extent"); + Element format = creator.create("format"); + Element timerange = creator.create("timerange"); + + creator.addAttr(gauge, "name", extractRequestGauge(req)); + creator.addAttr(extent, "width", extractRequestWidth(req)); + creator.addAttr(extent, "height", extractRequestHeight(req)); + creator.addAttr(format, "type", extractRequestFormat(req)); + creator.addAttr(timerange, "lower", extractRequestLowerTime(req)); + creator.addAttr(timerange, "upper", extractRequestUpperTime(req)); + + request.appendChild(service); + service.appendChild(gauge); + service.appendChild(extent); + service.appendChild(format); + service.appendChild(timerange); + + return request; + } + + protected String extractRequestGauge(HttpServletRequest req) { + return req.getParameter("gauge"); + } + + protected String extractRequestWidth(HttpServletRequest req) { + return req.getParameter("width"); + } + + protected String extractRequestHeight(HttpServletRequest req) { + return req.getParameter("height"); + } + + protected String extractRequestFormat(HttpServletRequest req) { + return req.getParameter("format"); + } + + protected String extractRequestLowerTime(HttpServletRequest req) { + String lowerStr = req.getParameter("lower"); + try { + long lowerMillis = Long.parseLong(lowerStr); + Date lower = new Date(lowerMillis); + + return DATE_FORMAT.format(lower); + } + catch (NumberFormatException nfe) { + logger.warn("Cannot parse time millies.", nfe); + } + + return null; + } + + protected String extractRequestUpperTime(HttpServletRequest req) { + String upperStr = req.getParameter("upper"); + try { + long upperMillis = Long.parseLong(upperStr); + Date upper = new Date(upperMillis); + + return DATE_FORMAT.format(upper); + } + catch (NumberFormatException nfe) { + logger.warn("Cannot parse time millies.", nfe); + } + + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DistanceInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,160 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.DistanceInfoService; +import de.intevation.flys.client.shared.model.DistanceInfoObject; +import de.intevation.flys.client.shared.model.DistanceInfoObjectImpl; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DistanceInfoServiceImpl +extends RemoteServiceServlet +implements DistanceInfoService +{ + private static final Logger logger = + Logger.getLogger(DistanceInfoServiceImpl.class); + + public static final String ERROR_NO_DISTANCEINFO_FOUND = + "error_no_distanceinfo_found"; + + public static final String XPATH_DISTANCES = "art:distances/art:distance"; + + + public DistanceInfoObject[] getDistanceInfo( + String locale, + String river) + throws ServerException + { + logger.info("DistanceInfoServiceImpl.getDistanceInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element riverEl = ec.create("river"); + + riverEl.setTextContent(river); + + doc.appendChild(riverEl); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document result = client.callService(url, "distanceinfo", doc); + + logger.debug("Extract distance info objects now."); + DistanceInfoObject[] objects = extractDistanceInfoObjects(result); + + if (objects != null && objects.length > 0) { + return objects; + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); + } + + + /** + * Extracts all distance info objects from <i>result</i> document. + * + * @param result The document retrieved by the server. + * + * @return a list of DistanceInfoObjects. + */ + protected DistanceInfoObject[] extractDistanceInfoObjects(Document result) + throws ServerException + { + NodeList list = result.getElementsByTagName("distance"); + + if (list == null || list.getLength() == 0) { + logger.warn("No distance info found."); + throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); + } + + int num = list.getLength(); + logger.debug("Response contains " + num + " objects."); + + List<DistanceInfoObject> objects = + new ArrayList<DistanceInfoObject>(num); + + for (int i = 0; i < num; i++) { + DistanceInfoObject obj = buildDistanceInfoObject( + (Element)list.item(i)); + + if (obj != null) { + objects.add(obj); + } + } + + logger.debug("Retrieved " + objects.size() + " distances."); + + return (DistanceInfoObject[]) + objects.toArray(new DistanceInfoObject[num]); + } + + + /** + * Extracts information for a single distance info object and intializes an + * DistanceInfoObject with them. + * + * @param node The node that contains the information. + * + * @return a valid DistanceInfoObject. + */ + protected DistanceInfoObject buildDistanceInfoObject(Element node) { + + String desc = node.getAttribute("description").trim(); + String from = node.getAttribute("from").trim(); + String to = node.getAttribute("to").trim(); + String riverside = node.getAttribute("riverside").trim(); + String bottom = node.getAttribute("bottom").trim(); + String top = node.getAttribute("top").trim(); + + if (desc.length() > 0 && from.length() > 0) { + try { + Double f = new Double(from); + Double t = to .length() > 0 ? new Double(to) : null; + Double b = bottom.length() > 0 ? new Double(bottom) : null; + Double tp = top .length() > 0 ? new Double(top) : null; + + return new DistanceInfoObjectImpl(desc, f, t, riverside, b, tp); + } + catch (NumberFormatException nfe) { + logger.warn(nfe.getLocalizedMessage()); + } + } + + logger.warn("Invalid distance info object found."); + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DistanceInfoXML.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,90 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DistanceInfoXML +extends HttpServlet +{ + private static final Logger logger = Logger.getLogger(DistanceInfoXML.class); + + + public static final String ERROR_NO_DISTANCEINFO_FOUND = + "error_no_distanceinfo_found"; + + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + logger.info("DistanceInfoXML.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + + String river = req.getParameter("river"); + String filter = req.getParameter("filter"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element riverEl = ec.create("river"); + riverEl.setTextContent(river); + + doc.appendChild(riverEl); + + if (filter != null && filter.length() > 0) { + Element typeEl = ec.create("filter"); + typeEl.setTextContent(filter); + + riverEl.appendChild(typeEl); + } + + HttpClient client = new HttpClientImpl(url); + + try { + InputStream in = (InputStream) client.callService( + url, "distanceinfo", doc, new StreamResponseHandler()); + + OutputStream out = resp.getOutputStream(); + + byte[] b = new byte[4096]; + int i; + while ((i = in.read(b)) >= 0) { + out.write(b, 0, i); + } + + out.flush(); + out.close(); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + catch (IOException ioe) { + logger.error(ioe, ioe); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/DoCollectionAction.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,62 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DoCollectionAction extends RemoteServiceServlet { + + private static final Logger logger = + Logger.getLogger(DoCollectionAction.class); + + + public static final String XPATH_RESULT = "/art:result/text()"; + public static final String OPERATION_FAILURE = "FAILED"; + public static final String FAILURE_EXCEPTION = "collection_action_failed"; + + + protected void doAction(Collection c, Document action, String url) + throws ServerException + { + logger.info("DoCollectionAction.doAction"); + + HttpClient client = new HttpClientImpl(url); + + try { + Document res = (Document) client.doCollectionAction( + action, c.identifier(), + new DocumentResponseHandler()); + + String result = XMLUtils.xpathString( + res, + XPATH_RESULT, + ArtifactNamespaceContext.INSTANCE); + + if (result == null || result.equals(OPERATION_FAILURE)) { + logger.error("Operation failed."); + throw new ServerException(FAILURE_EXCEPTION); + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + throw new ServerException(FAILURE_EXCEPTION); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,79 @@ +package de.intevation.flys.client.server; + +import java.io.OutputStream; +import java.io.IOException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + + +/** + * This service is used to request a data export from the artifact server. The + * response is directed directly to the output stream, so that a file dialog is + * opened. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ExportServiceImpl +extends HttpServlet +{ + private static final Logger logger = + Logger.getLogger(ExportServiceImpl.class); + + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + logger.info("ExportServiceImpl.doGet"); + + try { + OutputStream out = resp.getOutputStream(); + + String url = getServletContext().getInitParameter("server-url"); + String uuid = req.getParameter("uuid"); + String name = req.getParameter("name"); + String mode = req.getParameter("mode"); + String type = req.getParameter("type"); + String locale = req.getParameter("locale"); + String km = req.getParameter("km"); + String fn = name + "." + type; + + resp.setHeader("Content-Disposition", "attachment;filename=" + fn); + + if (logger.isDebugEnabled()) { + logger.debug("Request " + type + " export."); + } + + Document attr = null; + if (km != null && km.length() > 0) { + attr = XMLUtils.newDocument(); + XMLUtils.ElementCreator ec = + new XMLUtils.ElementCreator(attr, null, null); + Element e = ec.create("km"); + e.setTextContent(km); + attr.appendChild(e); + } + Document request = ClientProtocolUtils.newOutCollectionDocument( + uuid, mode, type, attr); + HttpClient client = new HttpClientImpl(url, locale); + client.collectionOut(request, uuid, mode, out); + + out.close(); + out.flush(); + } + catch (IOException ioe) { + logger.error(ioe, ioe); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/FLYSArtifactCreator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,211 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.ArtifactNamespaceContext; + +import de.intevation.artifacts.httpclient.utils.ArtifactCreator; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.CalculationMessage; +import de.intevation.flys.client.shared.model.ChartArtifact; +import de.intevation.flys.client.shared.model.DefaultArtifact; +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; +import de.intevation.flys.client.shared.model.GaugeDischargeCurveArtifact; +import de.intevation.flys.client.shared.model.MapArtifact; +import de.intevation.flys.client.shared.model.MINFOArtifact; +import de.intevation.flys.client.shared.model.StaticSQRelationArtifact; +import de.intevation.flys.client.shared.model.WINFOArtifact; + + +/** + * An implementation of an {@link ArtifactCreator}. This class uses the document + * that is returned by the artifact server to parse important information (like + * uuid, hash) and returns a new {@link Artifact} instance. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FLYSArtifactCreator implements ArtifactCreator { + + private static final Logger logger = + Logger.getLogger(FLYSArtifactCreator.class); + + + /** The XPath to the artifact's uuid.*/ + public static final String XPATH_UUID = "/art:result/art:uuid/@art:value"; + + /** The XPath to the artifact's hash value.*/ + public static final String XPATH_HASH = "/art:result/art:hash/@art:value"; + + /** The XPath to the artifact's name value.*/ + public static final String XPATH_NAME = "/art:result/art:name/@art:value"; + + /** The XPath to the value that determines if the artifact is processing in + * background.*/ + public static final String XPATH_BACKGROUND_VALUE = + "/art:result/art:background-processing/@art:value"; + + /** The XPath that points to the (if existing) background messages.*/ + public static final String XPATH_BACKGROUND = + "/art:result/art:background-processing"; + + + /** + * Creates a new instance of an {@link ArtifactCreator}. + */ + public FLYSArtifactCreator() { + } + + + /** + * This concreate implementation returns an instance of {@link Artifact} + * that is used in the FLYS GWT Client code. + * + * @param doc A document that describes the artifact that has been created + * in the artifact server. + * + * @return an instance if {@link Artifact}. + */ + public Object create(Document doc) { + Artifact artifact = extractArtifact(doc); + artifact.setArtifactDescription( + ArtifactDescriptionFactory.createArtifactDescription(doc)); + + return artifact; + } + + + /** + * This method extracts the UUID und HASH information of the returned + * artifact document. + * + * @param doc The result of the CREATE operation. + * + * @return an instance of an {@link Artifact}. + */ + protected Artifact extractArtifact(Document doc) { + logger.debug("FLYSArtifactCreator - extractArtifact()"); + + String uuid = XMLUtils.xpathString( + doc, XPATH_UUID, ArtifactNamespaceContext.INSTANCE); + + String hash = XMLUtils.xpathString( + doc, XPATH_HASH, ArtifactNamespaceContext.INSTANCE); + + String name = XMLUtils.xpathString( + doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE); + + String backgroundStr = XMLUtils.xpathString( + doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE); + + boolean background = false; + if (backgroundStr != null && backgroundStr.length() > 0) { + background = Boolean.valueOf(backgroundStr); + } + + List<CalculationMessage> msg = parseBackgroundMessages(doc); + + logger.debug("NEW Artifact UUID: " + uuid); + logger.debug("NEW Artifact HASH: " + hash); + logger.debug("NEW Artifact NAME: " + name); + logger.debug("NEW Artifact IN BACKGROUND: " + background); + + if (name == null) { + return new DefaultArtifact(uuid, hash, background, msg); + } + + name = name.trim(); + + if (name.length() > 0 && name.equals("winfo")) { + logger.debug("+++++ NEW WINFO ARTIFACT."); + return new WINFOArtifact(uuid, hash, background, msg); + } + else if (name.length() > 0 && name.equals("new_map")) { + logger.debug("+++++ NEW MAP ARTIFACT."); + return new MapArtifact(uuid, hash, background, msg); + } + else if (name.length() > 0 && name.equals("new_chart")) { + logger.debug("+++++ NEW CHART ARTIFACT."); + return new ChartArtifact(uuid, hash, background, msg); + } + else if (name.length() > 0 && name.equals("minfo")) { + logger.debug("+++++ NEW MINFO ARTIFACT."); + return new MINFOArtifact(uuid, hash, background, msg); + } + else if (name.length() > 0 && name.equals("fixanalysis")) { + logger.debug("+++++ NEW FIXANALYSIS ARTIFACT."); + return new FixAnalysisArtifact(uuid, hash, background, msg); + } + else if (name.length() > 0 && name.equals("gaugedischargecurve")) { + logger.debug("+++++ NEW GAUGEDISCHARGECURVE ARTIFACT."); + return new GaugeDischargeCurveArtifact(uuid, hash, background, msg); + } + else if (name.length() > 0 && name.equals("staticsqrelation")) { + logger.debug("+++++ STATICSQRELATION ARTIFACT."); + return new StaticSQRelationArtifact(uuid, hash, background, msg); + } + + return new DefaultArtifact(uuid, hash, background, msg); + } + + + public static List<CalculationMessage> parseBackgroundMessages(Document d) { + NodeList list = (NodeList) XMLUtils.xpath( + d, XPATH_BACKGROUND, XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int len = list != null ? list.getLength() : 0; + + logger.debug("Found " + len + " background messages."); + + List<CalculationMessage> res = new ArrayList<CalculationMessage>(len); + + for (int i = 0; i < len; i++) { + CalculationMessage msg = parseBackgroundMessage( + (Element) list.item(i)); + + if (msg != null) { + res.add(msg); + } + } + + return res; + } + + + public static CalculationMessage parseBackgroundMessage(Element e) { + String steps = e.getAttribute("art:steps"); + String currentStep = e.getAttribute("art:currentStep"); + String message = e.getTextContent(); + + int lenCurStep = currentStep != null ? currentStep.length() : 0; + int lenSteps = steps != null ? steps.length() : 0; + int lenMessage = message != null ? message.length() : 0; + + if (lenSteps > 0 && lenMessage > 0 && lenCurStep > 0) { + try { + return new CalculationMessage( + Integer.parseInt(steps), + Integer.parseInt(currentStep), + message); + + } + catch (NumberFormatException nfe) { + nfe.printStackTrace(); + } + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/FeedServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,172 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.client.services.FeedService; + +/** + * This interface provides a method that bundles the artifact specific + * operation FEED. + */ +public class FeedServiceImpl +extends RemoteServiceServlet +implements FeedService +{ + private static final Logger logger = Logger.getLogger(FeedServiceImpl.class); + + + /** XPath that points to the result type of a feed or advance operation.*/ + public static final String XPATH_RESULT = "/art:result/@art:type"; + + /** XPath that points to the result type of a feed or advance operation.*/ + public static final String XPATH_RESULT_MSG = "/art:result/text()"; + + /** A constant that marks errors.*/ + public static final String OPERATION_FAILURE = "FAILURE"; + + /** The error message key that is thrown if an error occured while feeding + * new data.*/ + public static final String ERROR_FEED_DATA = "error_feed_data"; + + + /** + * This method triggers the FEED operation. + * + * @param artifact The artifact that needs to be fed. + * @param data An array of Data objects that contain the information that + * are used for the FEED operation. + * + * @return a new artifact parsed from the description of FEED. + */ + public Artifact feed( + String locale, + Artifact artifact, + Data[] data) + throws ServerException + { + logger.info("StepForwardServiceImpl.feed"); + + String url = getServletContext().getInitParameter("server-url"); + + Document feed = ClientProtocolUtils.newFeedDocument( + artifact.getUuid(), + artifact.getHash(), + createKVP(data)); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document description = (Document) client.feed( + new de.intevation.artifacts.httpclient.objects.Artifact( + artifact.getUuid(), + artifact.getHash()), + feed, + new DocumentResponseHandler()); + + if (description == null) { + logger.warn("StepForwardService.feed() - FAILED"); + throw new ServerException(ERROR_FEED_DATA); + } + + String result = XMLUtils.xpathString( + description, + XPATH_RESULT, + ArtifactNamespaceContext.INSTANCE); + + if (result == null || !result.equals(OPERATION_FAILURE)) { + logger.debug("StepForwardService.feed() - SUCCESS"); + return (Artifact) new FLYSArtifactCreator().create(description); + } + else if (result != null && result.equals(OPERATION_FAILURE)) { + String msg = XMLUtils.xpathString( + description, + XPATH_RESULT_MSG, + ArtifactNamespaceContext.INSTANCE); + throw new ServerException(msg); + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + logger.warn("StepForwardService.feed() - FAILED"); + throw new ServerException(ERROR_FEED_DATA); + } + + + /** + * Triggers FEED operation, many artifacts, same data item(s). + * + * @param artifacts Artifacts that shall be fed. + * @param data An array of Data objects that contain the information that + * are used for the FEED operation. + * + * @return a new artifact parsed from the description of FEED. + */ + public List<Artifact> feedMany( + String locale, + List<Artifact> artifacts, + Data[] data) + throws ServerException + { + logger.info("StepForwardServiceImpl.feedMany"); + + String url = getServletContext().getInitParameter("server-url"); + + List<Artifact> resultArtifacts = new ArrayList<Artifact>(); + + for (Artifact artifact: artifacts) { + logger.info("feedMany: Relay to StepForwardServiceImpl.feed"); + Artifact fedArtifact = feed(locale, artifact, data); + resultArtifacts.add(fedArtifact); + } + + return resultArtifacts; + } + + + /** + * This method creates an array of key/value pairs from an array of Data + * objects. The string array is used as parameter for the feed() operation. + * + * @param data The data that should be transformed into the string array. + * + * @return a string array that contains key/value pairs. + */ + protected String[][] createKVP(Data[] data) { + String[][] kvp = new String[data.length][]; + + int i = 0; + + for (Data d: data) { + DataItem[] items = d.getItems(); + String key = d.getLabel(); + String value = d.getStringValue(); + + kvp[i++] = new String[] { key, value }; + } + + return kvp; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/FileUploadServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,119 @@ +package de.intevation.flys.client.server; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.fileupload.FileItemIterator; +import org.apache.commons.fileupload.FileItemStream; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class FileUploadServiceImpl +extends HttpServlet +{ + private static final Logger logger = Logger.getLogger(FileUploadServiceImpl.class); + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) { + logger.debug("handling post request."); + + String url = getServletContext().getInitParameter("server-url"); + + Document request = createFileXML(req); + + if (request == null) { + return; + } + HttpClient client = new HttpClientImpl(url); + + try { + Document result = client.callService(url, "fileupload", request); + + PrintWriter respWriter = resp.getWriter(); + respWriter.write("<html><link href='FLYS.css' rel='stylesheet' type='text/css'>"); + respWriter.write("<body><div style='font-face: Arial,Verdana,sans-serif; font-size: 11px'>"); + + if (result == null) { + logger.warn("FileUpload service returned no result."); + respWriter.write("FileUpload service returned no result"); + } + else { + String status = result.getElementsByTagName("status") + .item(0).getTextContent(); + respWriter.write(status); + } + + respWriter.write("</div></body></html>"); + respWriter.flush(); + + return; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + catch (IOException e) { + logger.error(e, e); + } + } + + + protected Document createFileXML(HttpServletRequest req) { + ServletFileUpload upload = new ServletFileUpload(); + + try{ + FileItemIterator iter = upload.getItemIterator(req); + + while (iter.hasNext()) { + FileItemStream item = iter.next(); + InputStream stream = item.openStream(); + + // Process the input stream + ByteArrayOutputStream out = new ByteArrayOutputStream(); + int len; + byte[] buffer = new byte[stream.available()]; + while ((len = stream.read(buffer, 0, buffer.length)) != -1) { + out.write(buffer, 0, len); + } + + buffer = Base64.encodeBase64(buffer); + String b64File = new String(buffer); + + Document fileDoc = XMLUtils.newDocument(); + + ElementCreator ec = new ElementCreator(fileDoc, null, null); + Element root = ec.create("upload"); + Element id = ec.create("artifact-uuid"); + id.setTextContent(req.getParameter("uuid")); + + Element data = ec.create("data"); + data.setTextContent(b64File); + + fileDoc.appendChild(root); + root.appendChild(id); + root.appendChild(data); + + return fileDoc; + } + } + catch(Exception e){ + logger.debug("Failed to create xml document containing the file."); + logger.debug(e, e); + } + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/FixingsKMChartServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,113 @@ +package de.intevation.flys.client.server; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; + +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class FixingsKMChartServiceImpl +extends HttpServlet +{ + private static final Logger log = + Logger.getLogger(FixingsKMChartServiceImpl.class); + + public static final String SERVICE_NAME = "fixings-km-chart"; + + public FixingsKMChartServiceImpl() { + } + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + + log.info("FixingsKMChartServiceImpl.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + String locale = req.getParameter("locale"); + String filter = req.getParameter("filter"); + + if (filter == null || filter.length() == 0) { + log.warn("Missing 'filter' parameter."); + return; + } + + if (locale == null || locale.length() == 0) { + locale = "de"; + } + + Document filterDoc = XMLUtils.jsonToXML(filter); + + if (filterDoc == null) { + log.warn("Creating filter document failed."); + return; + } + + InputStream in; + + try { + HttpClient client = new HttpClientImpl(url, locale); + in = (InputStream)client.callService( + url, // XXX: Why? The URL is passed by construction already. + SERVICE_NAME, + filterDoc, + new StreamResponseHandler()); + } + catch (ConnectionException ce) { + log.error(ce); + return; + } + + resp.setHeader("Content-Type", guessMIMEType(filterDoc)); + + try { + OutputStream out = resp.getOutputStream(); + + byte [] buf = new byte[4096]; + int i = -1; + while ((i = in.read(buf)) >= 0) { + out.write(buf, 0, i); + } + out.flush(); + } + catch (IOException ioe) { + log.error(ioe); + } + finally { + try { in.close(); } + catch (IOException ioe) { /* ignored */ } + } + } + + protected static String guessMIMEType(Document document) { + + NodeList formats = document.getElementsByTagName("format"); + + String format = "png"; + + if (formats.getLength() > 0) { + String type = ((Element)formats.item(0)).getAttribute("type"); + if (type.length() > 0) { + format = type; + } + } + + return "image/" + format; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/FixingsOverviewServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,240 @@ +package de.intevation.flys.client.server; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XSLTransformer; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.client.services.FixingsOverviewService; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; +import de.intevation.flys.client.shared.model.FixingsOverviewInfo.Sector; + +import de.intevation.flys.client.shared.model.FixingsOverviewInfo; + +import java.io.IOException; +import java.io.InputStream; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class FixingsOverviewServiceImpl +extends RemoteServiceServlet +implements FixingsOverviewService +{ + private static final Logger log = + Logger.getLogger(FixingsOverviewServiceImpl.class); + + public static final String SERVICE_NAME = "fixings-overview"; + + public static final String XSL_TRANSFORM = + "/WEB-INF/stylesheets/fixoverview2html.xsl"; + + protected static final String XPATH_RID = "/fixings/river/@rid"; + protected static final String XPATH_RIVER = "/fixings/river/@name"; + protected static final String XPATH_RFROM = "/fixings/river/@from"; + protected static final String XPATH_RTO = "/fixings/river/@to"; + + protected static final String XPATH_EVENT = "/fixings/events/event"; + + + @Override + public FixingsOverviewInfo generateOverview( + String locale, + String uuid, + String filter, + boolean checkboxes, + String callback + ) + throws ServerException + { + log.info("FixingsOverviewServiceImpl.doGet"); + + if (filter == null || filter.length() == 0) { + log.warn("Missing 'filter' parameter."); + return null; + } + + boolean debug = log.isDebugEnabled(); + + if (debug) { + log.debug("JSON filter: ------------------"); + log.debug(filter); + } + + Document filterDoc = XMLUtils.jsonToXML(filter); + + if (filterDoc == null) { + log.warn("Creating filter document failed."); + return null; + } + + if (debug) { + log.debug("XML filter: ------------------"); + log.debug(XMLUtils.toString(filterDoc)); + } + + try { + String url = getServletContext().getInitParameter("server-url"); + HttpClient client = new HttpClientImpl(url, locale); + Document resultDoc = + client.callService(url, SERVICE_NAME, filterDoc); + + if (debug) { + log.debug("Result XML: -----------"); + log.debug(XMLUtils.toString(resultDoc)); + } + + FixingsOverviewInfo i = getInfo( + locale, resultDoc, uuid, checkboxes, callback); + return i; + } + catch (ConnectionException ce) { + log.error(ce); + } + return null; + } + + + protected FixingsOverviewInfo getInfo( + String locale, + Document doc, + String uuid, + boolean checkboxes, + String callback + ) { + // TODO: Find a more general solution. + locale = locale == null || locale.toLowerCase().startsWith("de") + ? "de" + : "en"; + + InputStream transform = getServletContext() + .getResourceAsStream(XSL_TRANSFORM); + + if (transform == null) { + log.warn("transform not found"); + return null; + } + + String result = null; + try { + XSLTransformer xformer = new XSLTransformer(); + xformer.addParameter("locale", locale); + xformer.addParameter("project-uuid", uuid); + xformer.addParameter( + "render-checkboxes", + checkboxes ? Boolean.TRUE : Boolean.FALSE); + xformer.addParameter("callback", callback); + result = xformer.transform(doc, transform); + } + finally { + try { transform.close(); } + catch (IOException ioe) {} + } + + if (log.isDebugEnabled()) { + log.debug("--------------------------------------"); + log.debug(result); + log.debug("--------------------------------------"); + } + + int rid = -1; + double from = -1; + double to = -1; + + String rid_str = XMLUtils.xpathString(doc, XPATH_RID, null); + String river = XMLUtils.xpathString(doc, XPATH_RIVER, null); + String from_str = XMLUtils.xpathString(doc, XPATH_RFROM, null); + String to_str = XMLUtils.xpathString(doc, XPATH_RTO, null); + + try { + rid = Integer.parseInt(rid_str); + from = Double.parseDouble(from_str); + to = Double.parseDouble(to_str); + } + catch(NumberFormatException nfe) { + log.warn(nfe, nfe); + } + + List<FixEvent> fixEvents = getFixEvents(doc); + return new FixingsOverviewInfo( + rid, + river, + from, + to, + fixEvents, + result); + } + + + protected List<FixEvent> getFixEvents(Document doc) { + List<FixEvent> list = new ArrayList<FixEvent>(); + + NodeList events = (NodeList) XMLUtils.xpath( + doc, + XPATH_EVENT, + XPathConstants.NODESET, + null); + + if (events == null || events.getLength() == 0) { + log.warn("No events in Overview!"); + return list; + } + + for (int i = 0, E = events.getLength(); i < E; i++) { + Element n = (Element)events.item(i); + List<Sector> sectors = getSectors(n); + String cid = n.getAttribute("cid"); + String date = n.getAttribute("date");; + String name = n.getAttribute("description"); + list.add(new FixEvent( cid, date, name, sectors)); + } + return list; + } + + protected List<Sector> getSectors(Element event) { + NodeList sectors = event.getElementsByTagName("sector"); + + if (sectors.getLength() == 0) { + log.warn("No Sectors in Event!"); + return null; + } + + List<Sector> list = new ArrayList<Sector>(); + for (int i = 0, S = sectors.getLength(); i < S; i++) { + Element n = (Element)sectors.item(i); + int cls = -1; + double from = -1; + double to = -1; + String cls_str = n.getAttribute("class"); + String from_str = n.getAttribute("from"); + String to_str = n.getAttribute("to"); + try { + cls = Integer.parseInt(cls_str); + from = Double.parseDouble(from_str); + to = Double.parseDouble(to_str); + } + catch(NumberFormatException nfe) { + log.warn(nfe, nfe); + } + list.add(new Sector(cls, from, to)); + } + return list; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/GCServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,30 @@ +package de.intevation.flys.client.server; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Capabilities; +import de.intevation.flys.client.client.services.GCService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class GCServiceImpl +extends RemoteServiceServlet +implements GCService +{ + private static Logger logger = Logger.getLogger(GCServiceImpl.class); + + + public Capabilities query(String path) + throws ServerException + { + logger.info("GCServiceImpl.query"); + + return CapabilitiesParser.getCapabilities(path); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/GFIServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,275 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.AttributedTheme; +import de.intevation.flys.client.shared.model.FeatureInfo; +import de.intevation.flys.client.shared.model.FeatureInfoResponse; +import de.intevation.flys.client.shared.model.Theme; + +import de.intevation.flys.client.client.services.GFIService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class GFIServiceImpl +extends RemoteServiceServlet +implements GFIService +{ + public static final String ERR_NO_VALID_GFI_URL = + "error_no_valid_gfi_url"; + + public static final String ERR_GFI_REQUEST_FAILED = + "error_gfi_req_failed"; + + public static final String ERR_PARSING_RESPONSE_FAILED = + "error_gfi_parsing_failed"; + + + private static final Logger logger = + Logger.getLogger(GFIServiceImpl.class); + + + /** + * @param theme + * @param format + * @param bbox + * @param height + * @param width + * @param x + * @param y + * + * @return + */ + public FeatureInfoResponse query( + Theme theme, + String format, + String bbox, + String projection, + int height, + int width, + int x, + int y + ) throws ServerException + { + logger.info("GFIServiceImpl.query"); + + String path = createGetFeautureInfoURL( + theme, format, bbox, projection, height, width, x, y); + + logger.debug("URL=" + path); + + try { + URL url = new URL(path); + + URLConnection conn = url.openConnection(); + conn.connect(); + + InputStream is = conn.getInputStream(); + + return parseResponse(is); + + } + catch (IOException ioe) { + logger.warn(ioe, ioe); + } + + throw new ServerException(ERR_GFI_REQUEST_FAILED); + } + + + /** + * @param map + * @param theme + * @param format + * @param x + * @param y + * + * @return + */ + protected String createGetFeautureInfoURL( + Theme theme, + String infoFormat, + String bbox, + String projection, + int height, + int width, + int x, + int y + ) throws ServerException + { + String url = getUrl(theme); + + if (url == null || url.length() == 0) { + throw new ServerException(ERR_NO_VALID_GFI_URL); + } + + String layers = ((AttributedTheme)theme).getAttr("layers"); + + StringBuilder sb = new StringBuilder(); + sb.append(url); + + if (url.indexOf("?") < 0) { + sb.append("?SERVICE=WMS"); + } + else { + sb.append("&SERVICE=WMS"); + } + + sb.append("&VERSION=1.1.1"); + sb.append("&REQUEST=GetFeatureInfo"); + sb.append("&LAYERS=" + layers); + sb.append("&QUERY_LAYERS=" + layers); + sb.append("&BBOX=" + bbox); + sb.append("&HEIGHT=" + height); + sb.append("&WIDTH=" + width); + sb.append("&FORMAT=image/png"); + sb.append("&INFO_FORMAT=" + infoFormat); + sb.append("&SRS=" + projection); + sb.append("&X=" + String.valueOf(x)); + sb.append("&Y=" + String.valueOf(y)); + + return sb.toString(); + } + + + protected String getUrl(Theme theme) { + AttributedTheme attr = (AttributedTheme) theme; + return attr.getAttr("url"); + } + + + protected FeatureInfoResponse parseResponse(InputStream is) { + logger.debug("GFIServiceImpl.parseResponse"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte [] buf = new byte[1024]; + + int r = -1; + try { + while ((r = is.read(buf)) >= 0) { + baos.write(buf, 0, r); + } + } catch (IOException ex) { + logger.warn("GetFeatureInfo response could not be read: ", ex); + return new FeatureInfoResponse(); + } + + String content; + try { + content = baos.toString("UTF-8"); + } + catch (UnsupportedEncodingException uee) { + content = baos.toString(); + } + + Document response = XMLUtils.parseDocument(content); + if (response != null) { + List<FeatureInfo> features = new ArrayList<FeatureInfo>(); + parseFeatureInfos(response, features); + return new FeatureInfoResponse(features, null); + } + // Unable to parse just return the response as is + return new FeatureInfoResponse(new ArrayList<FeatureInfo>(), content); + } + + + protected void parseFeatureInfos(Node node, List<FeatureInfo> features) { + logger.debug("GFIServiceImpl.parseFeatureInfos"); + + String name = node.getNodeName(); + + if (name.endsWith("_layer")) { + features.add(parseFeature(node)); + + return; + } + + NodeList children = node.getChildNodes(); + + if (children != null && children.getLength() > 0) { + for (int i = 0, n = children.getLength(); i < n; i++) { + parseFeatureInfos(children.item(i), features); + } + } + } + + + protected FeatureInfo parseFeature(Node node) { + logger.debug("GFIServiceImpl.parseFeature"); + + String layername = node.getNodeName(); + + FeatureInfo f = new FeatureInfo(layername); + + NodeList children = node.getChildNodes(); + int numChildren = children != null ? children.getLength() : 0; + + logger.debug("Feature '" + layername + "' has " + numChildren + " nodes."); + + for (int i = 0; i < numChildren; i++) { + Node tmp = children.item(i); + String nodeName = tmp.getNodeName(); + + logger.debug(" node name: '" + nodeName + "'"); + + if (nodeName.equals("gml:name")) { + logger.debug("NAME node has child: " + tmp.getFirstChild().getNodeValue()); + f.setLayername(tmp.getFirstChild().getNodeValue()); + } + else if (nodeName.endsWith("_feature")) { + parseFeatureAttributes(tmp, f); + } + } + + return f; + } + + + protected void parseFeatureAttributes(Node node, FeatureInfo f) { + logger.debug("GFIServiceImpl.parseFeatureAttributes"); + + NodeList children = node.getChildNodes(); + int numChildren = children != null ? children.getLength() : 0; + + logger.debug("Has " + numChildren + " attributes."); + + for (int i = 0; i < numChildren; i++) { + Node tmp = children.item(i); + String name = tmp.getNodeName(); + + logger.debug(" tmp attribute name: '" + name + "'"); + + if (name.equals("gml:boundedBy")) { + // TODO + } + else { + Node child = tmp.getFirstChild(); + if (child != null) { + f.addAttr(name, child.getNodeValue()); + } + } + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/GGInATrustStrategy.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,20 @@ +package de.intevation.flys.client.server; + +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import org.apache.http.conn.ssl.TrustStrategy; + +public class GGInATrustStrategy implements TrustStrategy { + + /** + * Tempoary class to accept all certificates for GGinA Authentication + */ + + @Override + public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { + // FIXME validate Certificate + return true; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/GaugeInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,155 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.GaugeInfoService; +import de.intevation.flys.client.shared.model.Gauge; +import de.intevation.flys.client.shared.model.GaugeImpl; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class GaugeInfoServiceImpl +extends RemoteServiceServlet +implements GaugeInfoService +{ + private static final Logger logger = + Logger.getLogger(GaugeInfoServiceImpl.class); + + + public static final String ERROR_NO_GAUGES_FOUND = + "error_no_gaugeinfo_found"; + + public static final String XPATH_GAUGES = "art:service/art:gauge"; + + + public List<Gauge> getGaugeInfo(String rivername, String refnumber) + throws ServerException + { + logger.info("GaugeInfoServiceImpl.getGaugeInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element river = ec.create("river"); + ec.addAttr(river, "name", rivername); + + if (refnumber != null && refnumber.length() > 0) { + Element filter = ec.create("filter"); + Element gauge = ec.create("gauge"); + gauge.setTextContent(refnumber); + + filter.appendChild(gauge); + river.appendChild(filter); + } + + doc.appendChild(river); + + HttpClient client = new HttpClientImpl(url); + + try { + Document result = client.callService(url, "gaugeinfo", doc); + + logger.debug("Extract gauge info now."); + List<Gauge> gauges = extractGauges(result); + + if (gauges != null && gauges.size() > 0) { + return gauges; + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_GAUGES_FOUND); + } + + + /** + * Extracts all wq info objects from <i>result</i> document. + * + * @param result The document retrieved by the server. + * + * @return a list of WQInfoObjects. + */ + protected List<Gauge> extractGauges(Document result) + throws ServerException + { + List<Gauge> gauges = new ArrayList<Gauge>(); + + NodeList list = (NodeList) XMLUtils.xpath( + result, + XPATH_GAUGES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (list == null || list.getLength() == 0) { + logger.warn("No gauges found."); + + throw new ServerException(ERROR_NO_GAUGES_FOUND); + } + + int num = list.getLength(); + logger.debug("Response contains " + num + " objects."); + + for (int i = 0; i < num; i++) { + Gauge obj = buildGauge((Element) list.item(i)); + + if (obj != null) { + gauges.add(obj); + } + } + + logger.debug("Retrieved " + gauges.size() + " gauges."); + + return gauges; + } + + + protected Gauge buildGauge(Element ele) { + String name = ele.getAttribute("name"); + String lowerStr = ele.getAttribute("lower"); + String upperStr = ele.getAttribute("upper"); + + if (lowerStr != null && upperStr != null) { + try { + return new GaugeImpl( + name, + Double.valueOf(lowerStr), + Double.valueOf(upperStr)); + } + catch (NumberFormatException nfe) { + logger.warn("Error while Gauge creation: " + nfe.getMessage()); + } + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/GetArtifactServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,87 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.client.services.GetArtifactService; + + +/** + * This service provides a method that returns an artifact based on its + * identifier. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class GetArtifactServiceImpl +extends RemoteServiceServlet +implements GetArtifactService +{ + private static final Logger logger = + Logger.getLogger(GetArtifactServiceImpl.class); + + + public static final String ERROR_DESCRIBE_ARTIFACT = + "error_describe_artifact"; + + public static final String XPATH_RESULT = "/art:result/text()"; + + public static final String OPERATION_FAILURE = "FAILED"; + + + public Artifact getArtifact( + String locale, + String uuid, + String hash) + throws ServerException + { + logger.info("GetArtifactServiceImpl.getArtifact"); + + String url = getServletContext().getInitParameter("server-url"); + + Document describe = ClientProtocolUtils.newDescribeDocument( + uuid, hash, true); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document description = (Document) client.describe( + new de.intevation.artifacts.httpclient.objects.Artifact( + uuid, hash), + describe, + new DocumentResponseHandler()); + + if (description == null) { + throw new ServerException(ERROR_DESCRIBE_ARTIFACT); + } + + String result = XMLUtils.xpathString( + description, + XPATH_RESULT, + ArtifactNamespaceContext.INSTANCE); + + if (result == null || !result.equals(OPERATION_FAILURE)) { + return (Artifact) new FLYSArtifactCreator().create(description); + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_DESCRIBE_ARTIFACT); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/LoadArtifactServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,147 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Recommendation; + +import de.intevation.flys.client.client.services.LoadArtifactService; + +/** + * This service creates a new Artifact based on a given Recommendation and puts + * this new artifact into a specified Collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class LoadArtifactServiceImpl +extends ArtifactServiceImpl +implements LoadArtifactService +{ + private static final Logger logger = + Logger.getLogger(LoadArtifactServiceImpl.class); + + /** Error. */ + public static final String ERROR_LOAD_ARTIFACT = "error_load_artifact"; + + + /** + * Clones or creates a single artifact and adds it to a collection. + * + * Note that in contrast to loadMany, always the given factory is used + * to clone the artifact. + * + * @param parent collection to add recommendation to. + * @param recom recommendation to create clone for. + * @param factory factory to use. + * @param locale the locale to translate messages. + */ + public Artifact load( + Collection parent, + Recommendation recom, + String factory, + String locale + ) + throws ServerException { + logger.info( + "LoadArtifactServiceImpl.load: " + recom.getMasterArtifact()); + + String url = getServletContext().getInitParameter("server-url"); + + // 1) Clone the Artifact specified in >>recom<< + Artifact clone = ArtifactHelper.createArtifact( + url, locale, factory, recom); + + if (clone != null) { + logger.debug("Successfully create Artifact Clone. Add now!"); + Collection c = CollectionHelper.addArtifact( + parent, clone, url, locale); + + if (c != null) { + logger.debug("Successfully added Clone to Collection."); + + return clone; + } + } + + throw new ServerException(ERROR_LOAD_ARTIFACT); + } + + + /** + * Clone/create one or more artifacts and add it to a collection, avoiding + * duplicates. + * + * @param parent Collection where clones will be added to. + * @param recoms definitions of source of clone. + * @param factory name of factory to use when cloning artifacts (can be + * null in which case the recommendations getFactory() will + * be used. + * @param locale the locale to translate messages. + * + * @return cloned artifacts (same artifact might be contained multiple + * times). + */ + public Artifact[] loadMany( + Collection parent, + Recommendation[] recoms, + String factory, + String locale + ) + throws ServerException { + logger.debug("LoadArtifactServiceImpl.loadMany"); + + String url = getServletContext().getInitParameter("server-url"); + + ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); + HashMap<Recommendation, Artifact> cloneMap = + new HashMap<Recommendation, Artifact>(); + + // TODO Respect the index of what to clone. + + // 1) Clone the Artifacts specified in >>recoms<< + for (Recommendation recom : recoms) { + // Do not do two clones of two identical recommendations. + Artifact prevClone = cloneMap.get(recom); + if (prevClone != null) { + // Already cloned a recommendation like this. + logger.debug("LoadArtifactServiceImpl: Avoid reclones, " + + "clone already exists."); + artifacts.add(prevClone); + } + else { + // Not already cloned. + String realFactory = factory != null + ? factory + : recom.getFactory(); + + logger.debug("One will be cloned with : " + realFactory); + + Artifact clone = ArtifactHelper.createArtifact( + url, locale, realFactory, recom); + + if (clone != null) { + logger.debug("LoadArtifactServiceImple: Successfully " + + "loaded Artifact Clone."); + Collection c = CollectionHelper.addArtifact( + parent, clone, url, locale); + + if (c != null) { + artifacts.add(clone); + // Remember we cloned a recommendation like this. + cloneMap.put(recom, clone); + } + else { + throw new ServerException(ERROR_LOAD_ARTIFACT); + } + } + } + } + return artifacts.toArray(new Artifact[artifacts.size()]); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/LoggingConfigurator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.server; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + + +public class LoggingConfigurator { + + private static final Logger logger = + Logger.getLogger(LoggingConfigurator.class); + + + private LoggingConfigurator() { + } + + public static void init(String log4jProperties) { + if (log4jProperties != null && log4jProperties.length() > 0) { + PropertyConfigurator.configure(log4jProperties); + logger.info("Log4J logging initialized."); + } + else { + System.out.println("Error while setting up Log4J configuration."); + } + + System.out.println("LoggingConfigurator.init finished"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/LoginServlet.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,120 @@ +package de.intevation.flys.client.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.server.auth.Authentication; +import de.intevation.flys.client.server.auth.AuthenticationException; +import de.intevation.flys.client.server.auth.AuthenticationFactory; +import de.intevation.flys.client.server.auth.User; +import de.intevation.flys.client.server.auth.UserClient; +import de.intevation.flys.client.server.features.Features; + +public class LoginServlet extends HttpServlet { + + private static Logger logger = Logger.getLogger(LoginServlet.class); + + private static final String FLYS_PAGE = "FLYS.html"; + private static final String LOGIN_PAGE = "login.jsp"; + + private void redirectFailure(HttpServletResponse resp, String path) + throws IOException { + resp.sendRedirect(path + "/" + LOGIN_PAGE); + } + + private void redirectFailure(HttpServletResponse resp, String path, + Exception e) throws IOException { + this.redirectFailure(resp, path, e.getMessage()); + } + + private void redirectFailure(HttpServletResponse resp, String path, + String message) throws IOException { + resp.sendRedirect(path + "/" + LOGIN_PAGE + "?error=" + message); + } + + private void redirectSuccess(HttpServletResponse resp, String path, + String uri) throws IOException { + if (uri == null) { + String redirecturl = getServletContext().getInitParameter("redirect-url"); + if (redirecturl == null) { + redirecturl = FLYS_PAGE; + } + uri = "/" + redirecturl; + } + resp.sendRedirect(uri); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + logger.debug("Processing get request"); + this.redirectFailure(resp, req.getContextPath()); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException + { + String encoding = req.getCharacterEncoding(); + String username = req.getParameter("username"); + String password = req.getParameter("password"); + + logger.debug("Processing post request"); + + if (username == null || password == null) { + logger.debug("No username or password provided"); + this.redirectFailure(resp, req.getContextPath()); + return; + } + + try { + Authentication aresp = this.auth(username, password, encoding); + if (aresp == null || !aresp.isSuccess()) { + logger.debug("Authentication not successful"); + this.redirectFailure(resp, req.getContextPath()); + return; + } + User user = aresp.getUser(); + + String url = getServletContext().getInitParameter("server-url"); + UserClient client = new UserClient(url); + if (!client.userExists(user)) { + logger.debug("Creating db user"); + if (!client.createUser(user)) { + this.redirectFailure(resp, req.getContextPath(), + "Could not create new user"); + return; + } + } + + HttpSession session = req.getSession(); + session.setAttribute("user", user); + + String uri = (String)session.getAttribute("requesturi"); + + this.redirectSuccess(resp, req.getContextPath(), uri); + } + catch(AuthenticationException e) { + logger.error(e, e); + this.redirectFailure(resp, req.getContextPath(), e); + } + } + + private Authentication auth(String username, String password, String encoding) + throws AuthenticationException, IOException + { + ServletContext sc = this.getServletContext(); + Features features = (Features)sc.getAttribute(Features.CONTEXT_ATTRIBUTE); + String auth = sc.getInitParameter("authentication"); + return AuthenticationFactory.getInstance(auth).auth(username, password, + encoding, features); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/MapHelper.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,91 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.model.MapConfig; + + +public class MapHelper { + + private static final Logger logger = Logger.getLogger(MapHelper.class); + + + public static final String XPATH_SRID = + "/art:floodmap/art:srid/text()"; + + public static final String XPATH_MAX_EXTENT = + "/art:floodmap/art:maxExtent/text()"; + + public static final String XPATH_INITIAL_EXTENT = + "/art:floodmap/art:initialExtent/text()"; + + + private MapHelper() { + } + + + public static MapConfig parseConfig(Document raw) { + logger.debug("MapHelper.parseConfig"); + + if (logger.isDebugEnabled()) { + logger.debug(XMLUtils.toString(raw)); + } + + MapConfig config = new MapConfig(); + + setSrid(config, raw); + setMaxExtent(config, raw); + setInitialExtent(config, raw); + + return config; + } + + + protected static void setSrid(MapConfig config, Document raw) { + String srid = (String) XMLUtils.xpathString( + raw, + XPATH_SRID, + ArtifactNamespaceContext.INSTANCE); + + logger.debug("Found srid: '" + srid + "'"); + + if (srid != null && srid.length() > 0) { + logger.debug("Set srid: '" + srid + "'"); + config.setSrid(srid); + } + } + + + protected static void setMaxExtent(MapConfig config, Document raw) { + String maxExtent = (String) XMLUtils.xpathString( + raw, + XPATH_MAX_EXTENT, + ArtifactNamespaceContext.INSTANCE); + + logger.debug("Found max extent: '" + maxExtent + "'"); + + if (maxExtent != null && maxExtent.length() > 0) { + logger.debug("Set max extent: '" + maxExtent + "'"); + config.setMaxExtent(maxExtent); + } + } + + + protected static void setInitialExtent(MapConfig config, Document raw) { + String initialExtent = (String) XMLUtils.xpathString( + raw, + XPATH_INITIAL_EXTENT, + ArtifactNamespaceContext.INSTANCE); + + if (initialExtent != null && initialExtent.length() > 0) { + logger.debug("Set initial extent: '" + initialExtent + "'"); + config.setInitialExtent(initialExtent); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/MapInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,138 @@ +package de.intevation.flys.client.server; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.flys.client.client.services.MapInfoService; +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.BBox; +import de.intevation.flys.client.shared.model.MapInfo; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * This service fetches a document that contains meta information for a specific + * chart. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MapInfoServiceImpl +extends RemoteServiceServlet +implements MapInfoService +{ + private static final Logger logger = + Logger.getLogger(MapInfoServiceImpl.class); + + + public static final String XPATH_RIVER = + "/mapinfo/river/@name"; + + public static final String XPATH_SRID = + "/mapinfo/river/srid/@value"; + + public static final String XPATH_BBOX = + "/mapinfo/river/bbox/@value"; + + public static final String XPATH_RIVER_WMS = + "/mapinfo/river/river-wms/@url"; + + public static final String XPATH_RIVER_LAYERS = + "/mapinfo/river/river-wms/@layers"; + + public static final String XPATH_WMS_URL = + "/mapinfo/river/background-wms/@url"; + + public static final String XPATH_WMS_LAYERS = + "/mapinfo/river/background-wms/@layers"; + + public static final String ERROR_NO_MAPINFO_FOUND = + "mapinfo_service_no_result"; + + + @Override + public MapInfo getMapInfo(String locale, String river) + throws ServerException + { + logger.info("MapInfoServiceImpl.getMapInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document request = getRequestDocument(river, "rivermap"); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + logger.debug("MapInfoServiceImpl.callService"); + Document result = client.callService(url, "mapinfo", request); + + if (result == null) { + logger.warn("MapInfo service returned no result."); + throw new ServerException(ERROR_NO_MAPINFO_FOUND); + } + + return getMapInfo(result); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_MAPINFO_FOUND); + } + + + public static Document getRequestDocument(String rivername, String maptypeStr) { + logger.debug("MapInfoServiceImpl.getRequestDocument"); + + Document request = XMLUtils.newDocument(); + ElementCreator cr = new ElementCreator(request, null, null); + + Element root = cr.create("mapinfo"); + Element river = cr.create("river"); + Element maptype = cr.create("maptype"); + + river.setTextContent(rivername); + maptype.setTextContent(maptypeStr); + + request.appendChild(root); + root.appendChild(river); + root.appendChild(maptype); + + return request; + } + + + public static MapInfo getMapInfo(Document result) { + logger.debug("MapInfoServiceImpl.getMapInfo"); + + String river = XMLUtils.xpathString(result, XPATH_RIVER, null); + String sridStr = XMLUtils.xpathString(result, XPATH_SRID, null); + String bboxS = XMLUtils.xpathString(result, XPATH_BBOX, null); + BBox bbox = BBox.getBBoxFromString(bboxS); + + String riverWMS = XMLUtils.xpathString(result, XPATH_RIVER_WMS, null); + String riverLayers = XMLUtils.xpathString(result, XPATH_RIVER_LAYERS, null); + String wmsURL = XMLUtils.xpathString(result, XPATH_WMS_URL, null); + String wmsLayers = XMLUtils.xpathString(result, XPATH_WMS_LAYERS, null); + + int srid = 4326; + + try { + srid = Integer.parseInt(sridStr); + } + catch (NumberFormatException nfe) { + GWT.log("Could not parse SRID String: " + sridStr); + } + + return new MapInfo( + river, srid, bbox, riverWMS, riverLayers, wmsURL, wmsLayers); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/MapOutputServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,82 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.IOException; + +import java.util.Map; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.MapConfig; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.client.services.MapOutputService; + + +public class MapOutputServiceImpl +extends RemoteServiceServlet +implements MapOutputService +{ + + private static final Logger logger = + Logger.getLogger(MapOutputServiceImpl.class); + + + public static final String ERROR_NO_MAP_CONFIG = "error_no_map_config"; + + public static final String ERROR_NO_MAP_OUTPUT_TYPE = "error_no_map_output_type"; + + public MapConfig doOut(Collection collection) + throws ServerException + { + logger.info("MapOutputServiceImpl.doOut"); + + String url = getServletContext().getInitParameter("server-url"); + String uuid = collection.identifier(); + + Map<String, OutputMode> modes = collection.getOutputModes(); + String requestMode = ""; + if (modes.containsKey("floodmap")) { + requestMode = "floodmap"; + } + else if (modes.containsKey("map")) { + requestMode = "map"; + } + else { + throw new ServerException(ERROR_NO_MAP_OUTPUT_TYPE); + } + + try { + Document request = ClientProtocolUtils.newOutCollectionDocument( + uuid, requestMode, requestMode); + + HttpClient client = new HttpClientImpl(url); + InputStream is = client.collectionOut(request, uuid, requestMode); + + Document response = XMLUtils.parseDocument(is); + + return MapHelper.parseConfig(response); + } + catch (ConnectionException e) { + logger.error(e, e); + } + catch (IOException ioe) { + logger.error(ioe, ioe); + } + + throw new ServerException(ERROR_NO_MAP_CONFIG); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/MapPrintServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,532 @@ +package de.intevation.flys.client.server; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.JSON; +import de.intevation.artifacts.common.utils.StringUtils; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; +import de.intevation.flys.client.shared.MapUtils; +import de.intevation.flys.client.shared.model.MapConfig; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +/* +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +*/ +/* Used by direct API call. -> Enforce GPLv3 +import org.mapfish.print.MapPrinter; +import org.mapfish.print.output.OutputFactory; +import org.mapfish.print.output.OutputFormat; + +import org.mapfish.print.utils.PJsonObject; +*/ + +public class MapPrintServiceImpl +extends HttpServlet +{ + private static final Logger log = + Logger.getLogger(MapPrintServiceImpl.class); + + protected static class Layer implements Comparable<Layer> { + + protected int pos; + protected String url; + protected String layers; + protected String description; + + public Layer() { + } + + public boolean setup(Element element) { + + Element parent = (Element)element.getParentNode(); + String parentName = parent.getAttribute("name"); + if (!(parentName.equals("map") + || parentName.equals("floodmap"))) { + return false; + } + + String ns = ArtifactNamespaceContext.NAMESPACE_URI; + + String visible = element.getAttributeNS(ns, "visible"); + String active = element.getAttributeNS(ns, "active"); + + if (visible.equals("0") || active.equals("0")) { + return false; + } + + url = element.getAttributeNS(ns, "url"); + layers = element.getAttributeNS(ns, "layers"); + description = element.getAttributeNS(ns, "description"); + + try { + pos = Integer.parseInt(element.getAttributeNS(ns, "pos")); + } + catch (NumberFormatException nfe) { + return false; + } + + return true; + } + + public Map<String, Object> toMap() { + Map<String, Object> layer = new LinkedHashMap<String, Object>(); + + layer.put("type", "WMS"); + List<Object> subLayers = new ArrayList<Object>(1); + subLayers.add(layers); + layer.put("layers", subLayers); + // XXX: osm.intevation.de mapache only offers low dpi maps + // so we need to use the uncached service + layer.put("baseURL", url.replace("http://osm.intevation.de/mapcache/?", + "http://osm.intevation.de/cgi-bin/germany.fcgi?")); + layer.put("format", "image/png"); // TODO: Make configurable. + + return layer; + } + + @Override + public int compareTo(Layer other) { + int d = pos - other.pos; + if (d < 0) return -1; + return d > 0 ? +1 : 0; + } + } // class Layer + + protected static String generateSpec( + Document descDocument, + MapConfig mapConfig, + Double minX, Double minY, + Double maxX, Double maxY, + Map<String, Object> pageSpecs + ) { + Map<String, Object> spec = new LinkedHashMap<String, Object>(); + int dpi = 254; + spec.put("layout", "A4 landscape"); + spec.put("pageSize", "A4"); + spec.put("landscape", "true"); + spec.put("srs", "EPSG:" + mapConfig.getSrid()); + spec.put("dpi", dpi); + spec.put("units", "m"); + spec.put("geodaetic", "true"); + spec.put("outputFormat", "pdf"); + + spec.putAll(pageSpecs); + + String ns = ArtifactNamespaceContext.NAMESPACE_URI; + + List<Layer> ls = new ArrayList<Layer>(); + Layer l = new Layer(); + + NodeList facets = descDocument.getElementsByTagNameNS(ns, "facet"); + + for (int i = 0, N = facets.getLength(); i < N; ++i) { + Element element = (Element)facets.item(i); + if (l.setup(element)) { + ls.add(l); + l = new Layer(); + } + } + + // Establish Z order. + Collections.sort(ls); + + List<Object> layers = new ArrayList<Object>(ls.size()); + + for (int i = ls.size()-1; i >= 0; --i) { + layers.add(ls.get(i).toMap()); + } + + spec.put("layers", layers); + spec.put("name", "Name"); + + List<Object> pages = new ArrayList<Object>(1); + + + Map<String, Object> page = new LinkedHashMap<String, Object>(); + + List<Object> bounds = new ArrayList<Object>(4); + bounds.add(minX); + bounds.add(minY); + bounds.add(maxX); + bounds.add(maxY); + page.put("bbox", bounds); + + /* + bounds.add(Double.valueOf((minX+maxX)*0.5)); + bounds.add(Double.valueOf((minY+maxY)*0.5)); + + page.put("center", bounds); + page.put("scale", Integer.valueOf(50000)); + */ + + page.put("rotation", Integer.valueOf(0)); + + // This may overwrite default settings above + page.putAll(pageSpecs); + + pages.add(page); + spec.put("pages", pages); + + List<Object> legends = new ArrayList<Object>(layers.size()); + + for (Layer layer: ls) { + Map<String, Object> legend = new LinkedHashMap<String, Object>(); + List<Object> classes = new ArrayList<Object>(1); + Map<String, Object> clazz = new LinkedHashMap<String, Object>(); + String lgu = MapUtils.getLegendGraphicUrl(layer.url, layer.layers, dpi); + clazz.put("icon", lgu); + clazz.put("name", layer.description); + classes.add(clazz); + legend.put("classes", classes); + legend.put("name", layer.description); + legends.add(legend); + } + + spec.put("legends", legends); + + return JSON.toJSONString(spec); + } + + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException + { + log.info("MapPrintServiceImpl.doGet"); + + String uuid = req.getParameter("uuid"); + + if (uuid == null || !StringUtils.checkUUID(uuid)) { + throw new ServletException("Missing or misspelled UUID"); + } + + String minXS = req.getParameter("minx"); + String maxXS = req.getParameter("maxx"); + String minYS = req.getParameter("miny"); + String maxYS = req.getParameter("maxy"); + + Double minX = null; + Double maxX = null; + Double minY = null; + Double maxY = null; + + if (minXS != null && maxXS != null + && minYS != null && maxYS != null) { + log.debug("all parameters found -> parsing"); + try { + minX = Double.parseDouble(minXS); + minY = Double.parseDouble(minYS); + maxX = Double.parseDouble(maxXS); + maxY = Double.parseDouble(maxYS); + } + catch (NumberFormatException nfe) { + throw new ServletException("Misspelled minX, minY, maxX or maxY"); + } + } + + String mapType = req.getParameter("maptype"); + + if (mapType == null || !mapType.equals("floodmap")) { + mapType = "map"; + } + + // Retrieve print settings from request + Map<String, Object> pageSpecs = new HashMap<String, Object>(); + Map<String, Object> data = new HashMap<String, Object>(); + List<Object> payload = new ArrayList<Object>(); + data.put("data", payload); + Enumeration paramNames = req.getParameterNames(); + List<String> params = Collections.list(paramNames); + Collections.sort(params); + for (String paramName : params) { + if (paramName.startsWith("mapfish_data_")) { + // You can add mapfish_data variables that will be mapped + // to a info value pairs to provide meta data for the map + // The the info part starts with a number for sorting that + // number will be stripped + String paramValue = req.getParameter(paramName); + Map<String, Object> data3 = new HashMap<String, Object>(); + int order = 0; + try { + order = Integer.parseInt(paramName.substring(13, 14)); + data3.put("info", paramName.substring(14)); + } catch (NumberFormatException nfe) { + data3.put("info", paramName.substring(13)); + payload.add(data3); + } + if (paramValue.equals("null")) + data3.put("value", ""); + else + data3.put("value", paramValue); + payload.add(data3); + } else if (paramName.startsWith("mapfish_")) { + String paramValue = req.getParameter(paramName); + if (paramValue.equals("null")) + paramValue = ""; + pageSpecs.put(paramName.substring(8), paramValue); + } + } + if (!payload.isEmpty()) { + pageSpecs.put("data", data); + List<Object> columns = new ArrayList<Object>(); + columns.add("info"); + columns.add("value"); + data.put("columns", columns); + } + + String url = getURL(); + + Document requestOut = + ClientProtocolUtils.newOutCollectionDocument( + uuid, mapType, mapType); + Document requestDesc = + ClientProtocolUtils.newDescribeCollectionDocument(uuid); + + Document outDocument; + Document descDocument; + + try { + HttpClient client = new HttpClientImpl(url); + + descDocument = (Document)client.doCollectionAction( + requestDesc, uuid, new DocumentResponseHandler()); + + InputStream is = client.collectionOut( + requestOut, uuid, mapType); + + try { + outDocument = XMLUtils.parseDocument(is); + } + finally { + is.close(); + is = null; + } + + } + catch (ConnectionException ce) { + log.error(ce); + throw new ServletException(ce); + } + + MapConfig mapConfig = MapHelper.parseConfig(outDocument); + + if (minX == null) { + log.debug("parameters missing -> fallback to max extent"); + String [] parts = mapConfig.getMaxExtent().split("\\s+"); + if (parts.length < 4) { + throw new ServletException( + "Max extent has less than 4 values"); + } + try { + minX = Double.valueOf(parts[0]); + minY = Double.valueOf(parts[1]); + maxX = Double.valueOf(parts[2]); + maxY = Double.valueOf(parts[3]); + } + catch (NumberFormatException nfe) { + throw new ServletException(nfe); + } + } + if (log.isDebugEnabled()) { + log.debug("minX: " + minX); + log.debug("maxX: " + maxX); + log.debug("minY: " + minY); + log.debug("maxY: " + maxY); + } + + String spec = generateSpec( + descDocument, + mapConfig, + minX, minY, + maxX, maxY, + pageSpecs); + + if (log.isDebugEnabled()) { + log.debug("Generated spec:"); + log.debug(spec); + //System.err.println(spec); + } + + producePDF(spec, resp); + } + + protected String getURL() throws ServletException { + String url = getServletContext().getInitParameter("server-url"); + if (url == null) { + throw new ServletException("Missing server-url"); + } + return url; + } + + private static final String encode(String s) { + try { + return URLEncoder.encode(s, "UTF-8"); + } + catch (UnsupportedEncodingException usee) { + // Should not happen. + return s; + } + } + + protected void producePDF(String json, HttpServletResponse resp) + throws ServletException, IOException + { + String printUrl = getInitParameter("print-url"); + + if (printUrl == null) { + throw new ServletException("Missing 'print-url' in web.xml"); + } + + String url = printUrl + "/print.pdf?spec=" + encode(json); + + org.apache.commons.httpclient.HttpClient client = + new org.apache.commons.httpclient.HttpClient( + new MultiThreadedHttpConnectionManager()); + + // FIXME: The request is not authenticated. + // Currently this is not a problem because /flys/map-print + // is whitelisted in GGInAFilter. + GetMethod get = new GetMethod(url); + int result = client.executeMethod(get); + InputStream in = get.getResponseBodyAsStream(); + + if (in != null) { + try { + OutputStream out = resp.getOutputStream(); + try { + byte [] buf = new byte[4096]; + int r; + if (result < 200 || result >= 300) { + resp.setContentType("text/plain"); + } else { + // Only send content disposition and filename content + // type when we have a pdf + resp.setHeader("Content-Disposition", + "attachment;filename=flys-karte.pdf"); + resp.setContentType("application/pdf"); + } + while ((r = in.read(buf)) >= 0) { + out.write(buf, 0, r); + } + out.flush(); + } + finally { + out.close(); + } + } + finally { + in.close(); + } + } + } + + /* Use this if you want directly call the MapPrinter. Enforces GPLv3! + + protected MapPrinter getMapPrinter() throws ServletException, IOException { + String configPath = getInitParameter("config"); + if (configPath == null) { + throw new ServletException("Missing configuration in web.xml"); + } + + File configFile = new File(configPath); + if (!configFile.isAbsolute()) { + configFile = new File(getServletContext().getRealPath(configPath)); + } + + if (!configFile.isFile() || !configFile.canRead()) { + throw new ServletException("Cannot read '" + configFile + "'"); + } + + return new MapPrinter(configFile); + } + + protected void producePDF(String json, HttpServletResponse resp) + throws ServletException, IOException + { + PJsonObject jsonSpec = MapPrinter.parseSpec(json); + + MapPrinter printer = getMapPrinter(); + + OutputFormat outputFormat = OutputFactory.create( + printer.getConfig(), jsonSpec); + + resp.setHeader("Content-Disposition", "attachment;filename=print.pdf"); + resp.setHeader("Content-Type", "application/pdf"); + + // XXX: Streaming the generated PDF directly + // to the request out does not work. :-/ + File tmpFile = File.createTempFile("map-printing", null); + + try { + OutputStream out = + new BufferedOutputStream( + new FileOutputStream(tmpFile)); + try { + outputFormat.print(printer, jsonSpec, out, ""); + out.flush(); + } + catch (Exception e) { + log.error(e); + throw new ServletException(e); + } + finally { + printer.stop(); + out.close(); + } + InputStream in = + new BufferedInputStream( + new FileInputStream(tmpFile)); + out = resp.getOutputStream(); + try { + byte [] buf = new byte[4096]; + int r; + while ((r = in.read(buf)) >= 0) { + out.write(buf, 0, r); + } + out.flush(); + } + finally { + in.close(); + out.close(); + } + } + finally { + if (tmpFile.exists()) { + tmpFile.delete(); + } + } + } + */ +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/MapUrlServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,50 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; + +import java.util.Map; +import java.util.HashMap; + +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.MapUrlService; + + +public class MapUrlServiceImpl +extends RemoteServiceServlet +implements MapUrlService +{ + + private static final Logger logger = + Logger.getLogger(MapUrlServiceImpl.class); + + + public Map<String, String> getUrls() + throws ServerException + { + logger.info("MapUrlServiceImpl.getUrls"); + Map<String, String> urls = new HashMap<String, String>(); + + InputStream in = getServletContext().getResourceAsStream("/WEB-INF/wms-services.xml"); + + Document doc = XMLUtils.parseDocument(in); + + NodeList list = doc.getElementsByTagName("wms"); + for (int i = 0; i < list.getLength(); i++) { + Element e = (Element) list.item(i); + urls.put(e.getAttribute("url"), e.getAttribute("name")); + } + + return urls; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,113 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +import de.intevation.flys.client.client.services.MetaDataService; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.model.DataCageTree; + +import de.intevation.flys.client.server.meta.Converter; + +/** + * Service that returns certain meta-data from the backends data, polished to + * inclusion into current project. + */ +public class MetaDataServiceImpl +extends RemoteServiceServlet +implements MetaDataService +{ + /** Our very own logger. */ + private static final Logger logger = + Logger.getLogger(MetaDataServiceImpl.class); + + public static final String ERROR_NO_META_DATA_FOUND = + "error_no_meta_data_found"; + + + /** + * @param locale needed for i18n. + * @param artifactId ID of masterartifact (can be null) + * @param userId can be null + * @param outs can be null + * @param parameters can be null or parameters like "load-system:true;key:value" + */ + @Override + public DataCageTree getMetaData( + String locale, + String artifactId, + String userId, + String outs, + String parameters + ) throws ServerException + { + logger.info("MetaDataService.getMetaData"); + + // Create the query document. + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element meta = ec.create("meta"); + + if (artifactId != null) { + Element artifactEl = ec.create("artifact-id"); + artifactEl.setAttribute("value", artifactId); + meta.appendChild(artifactEl); + } + + if (userId != null) { + Element userEl = ec.create("user-id"); + userEl.setAttribute("value", userId); + meta.appendChild(userEl); + } + + if (outs != null) { + Element outsEl = ec.create("outs"); + outsEl.setAttribute("value", outs); + meta.appendChild(outsEl); + } + + if (parameters != null) { + Element paramsEl = ec.create("parameters"); + paramsEl.setAttribute("value", parameters); + meta.appendChild(paramsEl); + } + + doc.appendChild(meta); + + // Fire. + HttpClient client = new HttpClientImpl(url, locale); + + try { + Converter converter = new Converter(); + return converter.convert(client.callService(url, "metadata", doc)); + } + catch (ConnectionException ce) { + ce.printStackTrace(); + } + + throw new ServerException(ERROR_NO_META_DATA_FOUND); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ModuleServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,99 @@ +package de.intevation.flys.client.server; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.flys.client.client.services.ModuleService; +import de.intevation.flys.client.server.auth.User; +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.DefaultModule; +import de.intevation.flys.client.shared.model.Module; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class ModuleServiceImpl +extends RemoteServiceServlet +implements ModuleService +{ + private static final Logger logger = + Logger.getLogger(ModuleServiceImpl.class); + + public static final String XPATH_MODULES = "/art:modules/art:module"; + + public static final String ERROR_NO_MODULES_FOUND = + "error_no_module_found"; + + @Override + public Module[] list(String locale) throws ServerException { + User user = this.getUser(); + + logger.info("ModuleService.list"); + + String url = getServletContext().getInitParameter("server-url"); + + // create dummy xml + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element dummy = ec.create("modules"); + doc.appendChild(dummy); + + HttpClient client = new HttpClientImpl(url, locale); + try { + Document result = client.callService(url, "modules", doc); + + NodeList list = (NodeList) XMLUtils.xpath( + result, + XPATH_MODULES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (list == null) { + logger.warn("No modules found."); + + throw new ServerException(ERROR_NO_MODULES_FOUND); + } + + int num = list.getLength(); + + List<Module> modules = new ArrayList<Module>(list.getLength()); + for(int i =0; i < num; i++) { + Element em = (Element)list.item(i); + String name = em.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "name"); + String localname = em.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "localname"); + String strselected = em.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "selected"); + boolean selected = strselected == null ? false : + strselected.equalsIgnoreCase("true"); + logger.debug("Found module " + name + " " + localname); + if (user == null || user.canUseFeature("module:" + name)) { + modules.add(new DefaultModule(name, localname, selected)); + } + } + return modules.toArray(new Module[modules.size()]); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_MODULES_FOUND); + } +} + +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ProxyServlet.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,113 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Enumeration; + +import javax.servlet.ServletConfig; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.server.auth.User; + +/** + * Implements a Proxy for HTTP Requests + */ +public class ProxyServlet +extends HttpServlet +{ + private static Logger logger = Logger.getLogger(ProxyServlet.class); + private String remoteurl; + + @Override + public void init(ServletConfig config) { + this.remoteurl = config.getInitParameter("remoteurl"); + } + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) { + } + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException { + HttpClient httpclient = new DefaultHttpClient(); + + String requesturi = req.getRequestURI(); + String query = req.getQueryString(); + + HttpGet httpget = new HttpGet(this.remoteurl + "?" + query); + + boolean debug = logger.isDebugEnabled(); + + for (Enumeration e = req.getHeaderNames(); e.hasMoreElements();) { + String name = (String)e.nextElement(); + for (Enumeration f = req.getHeaders(name); f.hasMoreElements();) { + String value = (String)f.nextElement(); + if (debug) { + logger.debug( + "Adding request header " + name + " : " + value); + } + httpget.addHeader(name, value); + } + } + + HttpResponse response = httpclient.execute(httpget); + + StatusLine statusline = response.getStatusLine(); + if (debug) { + logger.debug("Response statuscode " + statusline.getStatusCode()); + } + resp.setStatus(statusline.getStatusCode()); + + Header[] headers = response.getAllHeaders(); + for(Header header : headers) { + if (debug) { + logger.debug( + "Adding response header " + header.getName() + + " : " + header.getValue()); + } + resp.setHeader(header.getName(), header.getValue()); + } + + HttpEntity entity = response.getEntity(); + if (entity != null) { + InputStream instream = entity.getContent(); + byte [] buf = new byte[4096]; + try { + OutputStream outstream = resp.getOutputStream(); + try { + int read; + while ((read = instream.read(buf)) >= 0) { + outstream.write(buf, 0, read); + } + outstream.flush(); + } + finally { + outstream.close(); + } + } + finally { + instream.close(); + } + } + } + + private User getUser(HttpServletRequest req) { + HttpSession session = req.getSession(); + return (User)session.getAttribute("user"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/RemoteServiceServlet.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.server; + +import de.intevation.flys.client.server.auth.User; + +import javax.servlet.http.HttpSession; + +public class RemoteServiceServlet +extends com.google.gwt.user.server.rpc.RemoteServiceServlet +{ + /** + * Return the current logged in user from the HTTP Session + */ + public User getUser() { + HttpSession session = this.getThreadLocalRequest().getSession(); + return (User)session.getAttribute("user"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/RemoveArtifactServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,34 @@ +package de.intevation.flys.client.server; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.services.RemoveArtifactService; + + +/** + * Implementation of RemoveArtifactService . + */ +public class RemoveArtifactServiceImpl +extends DescribeCollectionServiceImpl +implements RemoveArtifactService +{ + private static final Logger logger = + Logger.getLogger(RemoveArtifactServiceImpl.class); + + + public Collection remove( + Collection collection, + String artifactId, + String locale) + throws ServerException + { + logger.info("RemoveArtifactServiceImpl.remove"); + + String url = getServletContext().getInitParameter("server-url"); + + return CollectionHelper.removeArtifact(collection, artifactId, url, locale); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ReportServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,118 @@ +package de.intevation.flys.client.server; + +import java.io.InputStream; +import java.io.IOException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import org.apache.commons.lang.StringEscapeUtils; + +import de.intevation.flys.client.client.services.ReportService; + +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +public class ReportServiceImpl +extends RemoteServiceServlet +implements ReportService +{ + private static final Logger logger = + Logger.getLogger(ReportServiceImpl.class); + + + @Override + public String report( + String collectionId, + String locale, + String out + ) { + logger.info("report: " + collectionId + " " + out); + + String url = getServletContext().getInitParameter("server-url"); + + Document request = ClientProtocolUtils.newOutCollectionDocument( + collectionId, + out, + "report"); + + InputStream in = null; + try { + HttpClient client = new HttpClientImpl(url, locale); + in = client.collectionOut(request, collectionId, out); + + if (in == null) { + logger.debug("report: no report"); + return null; + } + + Document report = XMLUtils.parseDocument(in); + + return buildReport(report); + } + catch (IOException ioe) { + ioe.printStackTrace(); + } + catch (Exception e) { + e.printStackTrace(); + } + finally { + if (in != null) { + try { + in.close(); + } + catch (IOException ioe) { + } + } + } + + return "error processing error report"; + } + + + /** Returns String containing markup that shows the report message. */ + protected static String buildReport(Document document) { + + NodeList problems = document.getElementsByTagName("problem"); + + StringBuilder global = new StringBuilder(); + StringBuilder kms = new StringBuilder(); + + for (int i = 0, N = problems.getLength(); i < N; ++i) { + + Element element = (Element)problems.item(i); + + String km = element.getAttribute("km"); + String msg = element.getTextContent(); + + if (km.length() > 0) { + kms.append("<li><strong>KM ") + .append(StringEscapeUtils.escapeHtml(km)) + .append("</strong>: ") + .append(StringEscapeUtils.escapeHtml(msg)) + .append("</li>"); + } + else { + global.append("<li>") + .append(StringEscapeUtils.escapeHtml(msg)) + .append("</li>"); + } + } + + StringBuilder sb = new StringBuilder("<ul>") + .append(global) + .append(kms) + .append("</ul>"); + + return sb.toString(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/RiverInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,380 @@ +package de.intevation.flys.client.server; + +import java.text.DateFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.client.services.RiverInfoService; +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.DefaultGaugeInfo; +import de.intevation.flys.client.shared.model.DefaultMeasurementStation; +import de.intevation.flys.client.shared.model.DefaultRiverInfo; +import de.intevation.flys.client.shared.model.GaugeInfo; +import de.intevation.flys.client.shared.model.MeasurementStation; +import de.intevation.flys.client.shared.model.RiverInfo; + + +/** + * GWT Service to serve the gauge and measurement station info + * + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class RiverInfoServiceImpl +extends RemoteServiceServlet +implements RiverInfoService +{ + private static final Logger logger = + Logger.getLogger(RiverInfoServiceImpl.class); + + public static final String ERROR_NO_RIVER_INFO_FOUND = + "error_no_riverinfo_found"; + + private static final String XPATH_RIVER = + "/art:river-info/art:river"; + + private static final String XPATH_STATIONS = + "/art:river-info/art:measurement-stations/art:measurement-station"; + + private static final String XPATH_GAUGES = "/art:river-info/art:gauges/art:gauge"; + + public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( + DateFormat.SHORT, Locale.GERMANY); + + public RiverInfo getGauges(String river) throws ServerException { + logger.info("RiverInfoServiceImpl.getRiverInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element riverele = ec.create("river"); + riverele.setTextContent(river); + + doc.appendChild(riverele); + + HttpClient client = new HttpClientImpl(url); + + try { + Document result = client.callService(url, "gaugeoverviewinfo", doc); + + DefaultRiverInfo riverinfo = getRiverInfo(result); + List<GaugeInfo>gauges = createGauges(result, riverinfo.getName(), + riverinfo.isKmUp(), riverinfo.getWstUnit()); + + + riverinfo.setGauges(gauges); + + logger.debug("Finished RiverInfoService.getGauges."); + + return riverinfo; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + logger.warn("No gauge found"); + throw new ServerException(ERROR_NO_RIVER_INFO_FOUND); + } + + public RiverInfo getMeasurementStations(String river) throws ServerException { + logger.info("RiverInfoServiceImpl.getMeasurementStations"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element riverele = ec.create("river"); + riverele.setTextContent(river); + + doc.appendChild(riverele); + + HttpClient client = new HttpClientImpl(url); + + try { + Document result = client.callService(url, "measurementstationinfo", doc); + + DefaultRiverInfo riverinfo = getRiverInfo(result); + List<MeasurementStation> mstations = createMeasurementStations( + result, riverinfo.getName(), riverinfo.isKmUp()); + + riverinfo.setMeasurementStations(mstations); + + logger.debug("Finished MeasurementStationInfoService."); + + return riverinfo; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + logger.warn("No measurement station found"); + throw new ServerException(ERROR_NO_RIVER_INFO_FOUND); + } + + /** + * Avoids NullPointerException when parsing double value + */ + private Double parseDouble(String value) { + if (value == null || value.isEmpty()) { + return null; + } + try { + return Double.valueOf(value); + } + catch(NumberFormatException e) { + logger.error(e, e); + return null; + } + } + + private Long parseLong(String value) { + if (value == null || value.isEmpty()) { + return null; + } + try { + return Long.valueOf(value); + } + catch(NumberFormatException e) { + logger.error(e, e); + return null; + } + } + + private Integer parseInteger(String value) { + if (value == null || value.isEmpty()) { + return null; + } + try { + return Integer.valueOf(value); + } + catch(NumberFormatException e) { + logger.error(e, e); + return null; + } + } + + private Date parseDate(String value) { + if (value == null || value.isEmpty()) { + return null; + } + try { + return DATE_FORMAT.parse(value); + } + catch(ParseException e) { + logger.error(e, e); + return null; + } + } + + private List<MeasurementStation> createMeasurementStations( + Document result, String rivername, boolean kmup) { + + NodeList stationnodes = (NodeList) XMLUtils.xpath( + result, + XPATH_STATIONS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = stationnodes == null ? 0 : stationnodes.getLength(); + + ArrayList<MeasurementStation> mstations = new ArrayList<MeasurementStation>(num); + + if (num == 0) { + logger.warn("No measurement station found."); + } + else { + logger.debug("Found " + num + " measurement stations."); + + for (int i = 0; i < num; i++) { + Element stationele = (Element)stationnodes.item(i); + + String mname = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "name"); + String mstart = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "start"); + String mend = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "end"); + String mstation = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "station"); + String mtype = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "type"); + String riverside = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "riverside"); + String mid = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "id"); + String moperator = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "operator"); + String mstarttime = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "starttime"); + String mstoptime = stationele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "stoptime"); + + String gaugename = null; + + Element gaugeele = (Element)stationele.getFirstChild(); + if (gaugeele != null) { + gaugename = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "name"); + } + + + logger.debug("Found measurement station with name " + mname); + + MeasurementStation station = new DefaultMeasurementStation( + rivername, + mname, + parseInteger(mid), + parseDouble(mstation), + parseDouble(mstart), + parseDouble(mend), + kmup, + riverside, + mtype, + moperator, + parseDate(mstarttime), + parseDate(mstoptime), + gaugename + ); + + mstations.add(station); + } + } + return mstations; + } + + private List<GaugeInfo> createGauges( + Document result, String rivername, Boolean kmup, String rwstunit) { + NodeList gaugenodes = (NodeList) XMLUtils.xpath( + result, + XPATH_GAUGES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = gaugenodes == null ? 0 : gaugenodes.getLength(); + + ArrayList<GaugeInfo> gauges = new ArrayList<GaugeInfo>(num); + + if (num == 0) { + logger.warn("No gauge info found."); + } + else { + logger.debug("Found " + num + " gauges."); + + for (int i = 0; i < num; i++) { + Element gaugeele = (Element)gaugenodes.item(i); + + String gname = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "name"); + String gstart = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "start"); + String gend = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "end"); + String gdatum = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "datum"); + String gaeo = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "aeo"); + String gminq = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "minq"); + String gminw = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "minw"); + String gmaxq = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "maxq"); + String gmaxw = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "maxw"); + String gstation = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "station"); + String gofficial = gaugeele.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "official"); + + logger.debug("Found gauge with name " + gname); + + GaugeInfo gaugeinfo = new DefaultGaugeInfo( + rivername, + gname, + kmup, + parseDouble(gstation), + parseDouble(gstart), + parseDouble(gend), + parseDouble(gdatum), + parseDouble(gaeo), + parseDouble(gminq), + parseDouble(gmaxq), + parseDouble(gminw), + parseDouble(gmaxw), + rwstunit, + parseLong(gofficial) + ); + + gauges.add(gaugeinfo); + } + } + return gauges; + } + + private DefaultRiverInfo getRiverInfo(Document result) { + Element riverresp = (Element) XMLUtils.xpath( + result, + XPATH_RIVER, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + String rname = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "name"); + String rkmup = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "kmup"); + String rstart = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "start"); + String rend = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "end"); + String rwstunit = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "wstunit"); + String rminq = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "minq"); + String rmaxq = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "maxq"); + String rofficial = riverresp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "official"); + + logger.debug("River is " + rname); + + boolean kmup = rkmup.equalsIgnoreCase("true"); + DefaultRiverInfo riverinfo = new DefaultRiverInfo( + rname, + kmup, + parseDouble(rstart), + parseDouble(rend), + rwstunit, + parseDouble(rminq), + parseDouble(rmaxq), + parseLong(rofficial) + ); + + return riverinfo; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/RiverServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,104 @@ +package de.intevation.flys.client.server; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.flys.client.client.services.RiverService; +import de.intevation.flys.client.server.auth.User; +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.DefaultRiver; +import de.intevation.flys.client.shared.model.River; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * This interface provides a method to list the supported rivers of the artifact + * server. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class RiverServiceImpl +extends RemoteServiceServlet +implements RiverService +{ + /** Private logger. */ + private static final Logger logger = + Logger.getLogger(RiverServiceImpl.class); + + /** The XPath string that points to the rivers in the resulting document.*/ + public static final String XPATH_RIVERS = "/art:rivers/art:river"; + + /** The error message key that is thrown if an error occured while reading + * the supported rivers from server.*/ + public static final String ERROR_NO_RIVERS_FOUND = "error_no_rivers_found"; + + + /** Get river list. */ + @Override + public River[] list(String locale) + throws ServerException + { + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + doc.appendChild(ec.create("action")); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document res = client.callService(url, "rivers", doc); + + NodeList rivers = (NodeList) XMLUtils.xpath( + res, + XPATH_RIVERS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (rivers == null || rivers.getLength() == 0) { + throw new ServerException(ERROR_NO_RIVERS_FOUND); + } + + int count = rivers.getLength(); + + List<River> theRivers = new ArrayList<River>(count); + User user = this.getUser(); + + for (int i = 0; i < count; i++) { + Element tmp = (Element)rivers.item(i); + + String name = tmp.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "name"); + + if (name.length() > 0 + && (user == null || user.canUseFeature("river:" + name))) { + theRivers.add(new DefaultRiver(name)); + } + } + + return theRivers.toArray(new River[theRivers.size()]); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_RIVERS_FOUND); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/SQKMChartServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,111 @@ +package de.intevation.flys.client.server; + +import org.apache.log4j.Logger; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + +public class SQKMChartServiceImpl +extends HttpServlet +{ + private static final Logger log = + Logger.getLogger(FixingsKMChartServiceImpl.class); + + public static final String SERVICE_NAME = "sq-km-chart"; + + public SQKMChartServiceImpl() { + } + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + + log.info("SQKMChartServiceImpl.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + String locale = req.getParameter("locale"); + String filter = req.getParameter("filter"); + + if (filter == null || filter.length() == 0) { + log.warn("Missing 'filter' parameter."); + return; + } + + if (locale == null || locale.length() == 0) { + locale = "de"; + } + + Document filterDoc = XMLUtils.jsonToXML(filter); + + if (filterDoc == null) { + log.warn("Creating filter document failed."); + return; + } + + InputStream in; + + try { + HttpClient client = new HttpClientImpl(url, locale); + in = (InputStream)client.callService( + url, // XXX: Why? The URL is passed by construction already. + SERVICE_NAME, + filterDoc, + new StreamResponseHandler()); + } + catch (ConnectionException ce) { + log.error(ce); + return; + } + + resp.setHeader("Content-Type", guessMIMEType(filterDoc)); + + try { + OutputStream out = resp.getOutputStream(); + + byte [] buf = new byte[4096]; + int i = -1; + while ((i = in.read(buf)) >= 0) { + out.write(buf, 0, i); + } + out.flush(); + } + catch (IOException ioe) { + log.error(ioe); + } + finally { + try { in.close(); } + catch (IOException ioe) { /* ignored */ } + } + } + + protected static String guessMIMEType(Document document) { + + NodeList formats = document.getElementsByTagName("format"); + + String format = "png"; + + if (formats.getLength() > 0) { + String type = ((Element)formats.item(0)).getAttribute("type"); + if (type.length() > 0) { + format = type; + } + } + + return "image/" + format; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/SedimentLoadInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,152 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.flys.client.client.services.SedimentLoadInfoService; +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; +import de.intevation.flys.client.shared.model.SedimentLoadInfoObjectImpl; + + +public class SedimentLoadInfoServiceImpl +extends RemoteServiceServlet +implements SedimentLoadInfoService +{ + private static final Logger logger = + Logger.getLogger(SedimentLoadInfoServiceImpl.class); + + public static final String ERROR_NO_SEDIMENTLOADINFO_FOUND = + "error_no_sedimentloadinfo_found"; + + @Override + public SedimentLoadInfoObject[] getSedimentLoadInfo( + String locale, + String river, + String type, + double startKm, + double endKm) + throws ServerException + { + logger.info("SedimentLoadInfoServiceImpl.getSedimentLoadInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element riverEl = ec.create("river"); + Element location = ec.create("location"); + Element from = ec.create("from"); + Element to = ec.create("to"); + Element typeEl = ec.create("type"); + riverEl.setTextContent(river); + from.setTextContent(String.valueOf(startKm)); + to.setTextContent(String.valueOf(endKm)); + typeEl.setTextContent(type); + + location.appendChild(from); + location.appendChild(to); + riverEl.appendChild(location); + riverEl.appendChild(typeEl); + doc.appendChild(riverEl); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document result = client.callService(url, "sedimentloadinfo", doc); + + logger.debug("Extract sedimentload info objects now."); + SedimentLoadInfoObject[] objects = + extractSedimentLoadInfoObjects(result); + + if (objects != null && objects.length > 0) { + return objects; + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_SEDIMENTLOADINFO_FOUND); + } + + + /** + * Extracts all distance info objects from <i>result</i> document. + * + * @param result The document retrieved by the server. + * + * @return a list of DistanceInfoObjects. + */ + protected SedimentLoadInfoObject[] extractSedimentLoadInfoObjects( + Document result) + throws ServerException + { + NodeList list = result.getElementsByTagName("sedimentload"); + + if (list == null || list.getLength() == 0) { + logger.warn("No sedimentload info found."); + throw new ServerException(ERROR_NO_SEDIMENTLOADINFO_FOUND); + } + + int num = list.getLength(); + logger.debug("Response contains " + num + " objects."); + + List<SedimentLoadInfoObject> objects = + new ArrayList<SedimentLoadInfoObject>(num); + + for (int i = 0; i < num; i++) { + SedimentLoadInfoObject obj = buildSedimentLoadInfoObject( + (Element)list.item(i)); + + if (obj != null) { + objects.add(obj); + } + } + + logger.debug("Retrieved " + objects.size() + " sediment loads."); + + return (SedimentLoadInfoObject[]) + objects.toArray(new SedimentLoadInfoObject[num]); + } + + + /** + * Extracts information for a single distance info object and intializes an + * DistanceInfoObject with them. + * + * @param node The node that contains the information. + * + * @return a valid DistanceInfoObject. + */ + protected SedimentLoadInfoObject buildSedimentLoadInfoObject(Element node) { + + String desc = node.getAttribute("description").trim(); + String date = node.getAttribute("date").trim(); + + if (desc.length() > 0 && date.length() > 0) { + return new SedimentLoadInfoObjectImpl(desc, date); + } + + logger.warn("Invalid sediment load info object found."); + + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/SetCollectionNameServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,38 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.services.SetCollectionNameService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class SetCollectionNameServiceImpl +extends DoCollectionAction +implements SetCollectionNameService +{ + private static final Logger logger = + Logger.getLogger(SetCollectionNameServiceImpl.class); + + + public void setName(Collection c) + throws ServerException + { + logger.info("Set name of collection: " + c.identifier()); + + String url = getServletContext().getInitParameter("server-url"); + + String name = c.getName(); + Document set = ClientProtocolUtils.newSetCollectionNameDocument(name); + + doAction(c, set, url); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/SetCollectionTTLServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,53 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.services.SetCollectionTTLService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class SetCollectionTTLServiceImpl +extends DoCollectionAction +implements SetCollectionTTLService +{ + private static final Logger logger = + Logger.getLogger(SetCollectionTTLServiceImpl.class); + + + public static final String XPATH_RESULT = "/art:result/text()"; + public static final String OPERATION_FAILURE = "FAILED"; + + public void setTTL(Collection c) + throws ServerException + { + logger.info("Set ttl of collection: " + c.identifier()); + + String url = getServletContext().getInitParameter("server-url"); + + long ttl = c.getTTL(); + String value = null; + + if (ttl == 0) { + value = "INF"; + } + else if (ttl < 0) { + value = "DEFAULT"; + } + else { + value = String.valueOf(ttl); + } + + Document set = ClientProtocolUtils.newSetCollectionTTLDocument(value); + + doAction(c, set, url); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/StepForwardServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,179 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.client.services.StepForwardService; + + +/** + * This interface provides a method that bundles the artifact specific + * operations FEED and ADVANCE. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StepForwardServiceImpl +extends AdvanceServiceImpl +implements StepForwardService +{ + private static final Logger logger = + Logger.getLogger(StepForwardServiceImpl.class); + + + /** XPath that points to the result type of a feed or advance operation.*/ + public static final String XPATH_RESULT = "/art:result/@art:type"; + + /** XPath that points to the result type of a feed or advance operation.*/ + public static final String XPATH_RESULT_MSG = "/art:result/text()"; + + /** A constant that marks errors.*/ + public static final String OPERATION_FAILURE = "FAILURE"; + + /** The error message key that is thrown if an error occured while feeding + * new data.*/ + public static final String ERROR_FEED_DATA = "error_feed_data"; + + + /** + * This method wraps the artifact operations FEED and ADVANCE. FEED is + * always triggerd, ADVANCE only, if there is at least one reachable state. + * + * @param locale The locale used for the request. + * @param artifact The artifact that needs to be fed. + * @param data An array of Data objects that contain the information that + * + * @return the modified artifact. + */ + public Artifact go(String locale, Artifact artifact, Data[] data) + throws ServerException + { + logger.info("StepForwardServiceImpl.go"); + + String url = getServletContext().getInitParameter("server-url"); + + Artifact afterFeed = feed(url, locale, artifact, data); + + if (afterFeed == null) { + logger.warn("StepForwardService.feed() - FAILED"); + throw new ServerException(ERROR_FEED_DATA); + } + + ArtifactDescription desc = afterFeed.getArtifactDescription(); + String[] reachable = desc.getReachableStates(); + + if (reachable == null || reachable.length == 0) { + logger.debug("Did not find any reachable state."); + return afterFeed; + } + + // We use the first reachable state as default target, maybe we need to + // change this later. + return advance(locale, afterFeed, reachable[0]); + } + + + /** + * This method triggers the FEED operation. + * + * @param url The url of the artifact server. + * @param artifact The artifact that needs to be fed. + * @param data An array of Data objects that contain the information that + * are used for the FEED operation. + * + * @return a new artifact parsed from the description of FEED. + */ + protected Artifact feed( + String url, + String locale, + Artifact artifact, + Data[] data) + throws ServerException + { + logger.info("StepForwardServiceImpl.feed"); + + Document feed = ClientProtocolUtils.newFeedDocument( + artifact.getUuid(), + artifact.getHash(), + createKVP(data)); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document description = (Document) client.feed( + new de.intevation.artifacts.httpclient.objects.Artifact( + artifact.getUuid(), + artifact.getHash()), + feed, + new DocumentResponseHandler()); + + if (description == null) { + logger.warn("StepForwardService.feed() - FAILED"); + throw new ServerException(ERROR_FEED_DATA); + } + + String result = XMLUtils.xpathString( + description, + XPATH_RESULT, + ArtifactNamespaceContext.INSTANCE); + + if (result == null || !result.equals(OPERATION_FAILURE)) { + logger.debug("StepForwardService.feed() - SUCCESS"); + return (Artifact) new FLYSArtifactCreator().create(description); + } + else if (result != null && result.equals(OPERATION_FAILURE)) { + String msg = XMLUtils.xpathString( + description, + XPATH_RESULT_MSG, + ArtifactNamespaceContext.INSTANCE); + throw new ServerException(msg); + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + logger.warn("StepForwardService.feed() - FAILED"); + throw new ServerException(ERROR_FEED_DATA); + } + + + /** + * This method creates an array of key/value pairs from an array of Data + * objects. The string array is used as parameter for the feed() operation. + * + * @param data The data that should be transformed into the string array. + * + * @return a string array that contains key/value pairs. + */ + protected String[][] createKVP(Data[] data) { + String[][] kvp = new String[data.length][]; + + int i = 0; + + for (Data d: data) { + DataItem[] items = d.getItems(); + String key = d.getLabel(); + String value = d.getStringValue(); + + kvp[i++] = new String[] { key, value }; + } + + return kvp; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/StyleHelper.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,48 @@ +package de.intevation.flys.client.server; + +import de.intevation.flys.client.shared.model.Style; +import de.intevation.flys.client.shared.model.StyleSetting; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +public class StyleHelper { + + public static Style getStyle (Element element) { + if (!element.getTagName().equals("theme")) { + return null; + } + + NodeList list = element.getElementsByTagName("field"); + Style style = new Style(); + + style.setName (element.getAttribute("name")); + style.setFacet (element.getAttribute("facet")); + + try { + int ndx = Integer.parseInt(element.getAttribute("index")); + style.setIndex (ndx); + } + catch(NumberFormatException nfe) { + return null; + } + + for(int i = 0; i < list.getLength(); i++) { + Element e = (Element) list.item(i); + String hints = e.getAttribute("hints"); + + StyleSetting set = new StyleSetting ( + e.getAttribute("name"), + e.getAttribute("default"), + e.getAttribute("display"), + e.getAttribute("hints"), + e.getAttribute("type"), + (hints != null && hints.contains("hidden") ? true : false) + ); + style.appendStyleSetting(set); + } + return style; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/ThemeListingServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,107 @@ +package de.intevation.flys.client.server; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.client.services.ThemeListingService; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +import de.intevation.flys.client.shared.model.Style; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * This interface provides a method to list themes filtered by name. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class ThemeListingServiceImpl +extends RemoteServiceServlet +implements ThemeListingService +{ + private static final Logger logger = + Logger.getLogger(ThemeListingServiceImpl.class); + + + private static final String XPATH_THEME_GROUPS = "/themes/themegroup"; + /** The error message key that is thrown if an error occured while reading + * the supported rivers from server.*/ + public static final String ERROR_NO_GROUPS_FOUND = "error_no_groups_found"; + + + public Map<String, Style> list(String locale, String name) + throws ServerException + { + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + null, + null); + + Element e = ec.create("theme"); + ec.addAttr(e, "name", name); + doc.appendChild(e); + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document res = client.callService(url, "themelisting", doc); + + NodeList themeGroups = (NodeList) XMLUtils.xpath( + res, + XPATH_THEME_GROUPS, + XPathConstants.NODESET, + null); + + if (themeGroups == null || themeGroups.getLength() == 0) { + throw new ServerException(ERROR_NO_GROUPS_FOUND); + } + + int count = themeGroups.getLength(); + + Map<String, Style> theStyles = new HashMap<String, Style>(count); + + for (int i = 0; i < count; i++) { + Element tmp = (Element)themeGroups.item(i); + + String groupName = tmp.getAttribute("name"); + NodeList theTheme = (NodeList) XMLUtils.xpath( + tmp, + "theme", + XPathConstants.NODESET, + null); + + for (int j = 0; j < theTheme.getLength(); j++) { + Element elem = (Element) theTheme.item(j); + theStyles.put(groupName, StyleHelper.getStyle(elem)); + } + } + + return theStyles; + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_GROUPS_FOUND); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/UserCollectionsServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,121 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.DefaultCollection; +import de.intevation.flys.client.client.services.UserCollectionsService; + + +/** + * This service returns a list of collections owned by a specified user. + * <b>NOTE:</b> The Collections returned by this service provide no information + * about the CollectionItems or OutputModes of the Collection. You need to fetch + * these information explicitly using another service. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class UserCollectionsServiceImpl +extends RemoteServiceServlet +implements UserCollectionsService +{ + private static final Logger logger = Logger.getLogger( + UserCollectionsServiceImpl.class); + + + public Collection[] getUserCollections(String locale, String userid) { + logger.info("UserCollectionsServiceImpl.getUserCollections"); + + String serverUrl = getServletContext().getInitParameter("server-url"); + HttpClient client = new HttpClientImpl(serverUrl, locale); + + try { + Document result = client.listUserCollections(userid); + + NodeList list = (NodeList) XMLUtils.xpath( + result, + "/art:artifact-collections/art:artifact-collection", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (list == null || list.getLength() == 0) { + logger.debug("No collection found for user: " + userid); + return null; + } + + int num = list.getLength(); + + List<Collection> all = new ArrayList<Collection>(num); + + for (int i = 0; i < num; i++) { + Collection c = createCollection((Element) list.item(i)); + + if (c != null) { + all.add(c); + } + } + + logger.debug("User has " + all.size() + " collections."); + + return all.toArray(new Collection[all.size()]); + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + logger.debug("No user collections found."); + return null; + } + + + /** + * Extracts a SimpleCollection from <i>node</i>. + * + * @param node Contains information about a collection. + * + * @return a list of Simplecollections. + */ + protected Collection createCollection(Element node) { + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + String creationStr = node.getAttributeNS(uri, "creation"); + String name = node.getAttributeNS(uri, "name"); + String uuid = node.getAttributeNS(uri, "uuid"); + String ttlStr = node.getAttributeNS(uri, "ttl"); + + if (!uuid.isEmpty() && !ttlStr.isEmpty() && !creationStr.isEmpty()) { + try { + long time = Long.parseLong(creationStr); + long ttl = Long.parseLong(ttlStr); + return new DefaultCollection(uuid, ttl, name, new Date(time)); + } + catch (NumberFormatException nfe) { + logger.warn("Error while parsing collection attributes."); + return null; + } + } + + logger.warn("Found an invalid Collection."); + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/UserServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,71 @@ +package de.intevation.flys.client.server; + +import javax.servlet.http.HttpSession; + +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; + +import de.intevation.flys.client.client.services.UserService; +import de.intevation.flys.client.server.auth.UserClient; +import de.intevation.flys.client.shared.exceptions.AuthenticationException; +import de.intevation.flys.client.shared.model.DefaultUser; +import de.intevation.flys.client.shared.model.User; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class UserServiceImpl +extends RemoteServiceServlet +implements UserService +{ + /** Private logger. */ + private static final Logger logger = Logger.getLogger(UserServiceImpl.class); + + public static final String ERROR_NO_SUCH_USER = "error_no_such_user"; + + public static final String ERROR_NO_USERS = "error_no_users"; + + public User getCurrentUser(String locale) + throws AuthenticationException + { + String url = getServletContext().getInitParameter("server-url"); + + UserClient client = new UserClient(url); + de.intevation.flys.client.server.auth.User loginuser = getUser(); + + if (loginuser == null) { + logger.debug("no session user"); + throw new AuthenticationException(ERROR_NO_SUCH_USER); + } + + try { + Element user = client.findUser(loginuser); + + if (user != null) { + String uuid = user.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "uuid"); + String name = user.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "name"); + + return new DefaultUser(uuid, name); + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + logger.error("No users existing in the server."); + throw new AuthenticationException(ERROR_NO_USERS); + } + + public void logoutCurrentUser() { + HttpSession session = this.getThreadLocalRequest().getSession(); + session.setAttribute("user", null); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/WQInfoServiceImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,207 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.WQInfoService; +import de.intevation.flys.client.shared.model.WQInfoObject; +import de.intevation.flys.client.shared.model.WQInfoObjectImpl; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WQInfoServiceImpl +extends RemoteServiceServlet +implements WQInfoService +{ + private static final Logger logger = + Logger.getLogger(WQInfoServiceImpl.class); + + public static final String ERROR_NO_WQINFO_FOUND = + "error_no_wqinfo_found"; + + public static final String XPATH_WQS = "art:service/art:mainvalues/art:mainvalue"; + + + public WQInfoObject[] getWQInfo( + String locale, + String river, + double from, + double to) + throws ServerException + { + logger.info("WQInfoServiceImpl.getWQInfo"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element mainvalues = ec.create("mainvalues"); + Element riverEl = ec.create("river"); + Element startEl = ec.create("start"); + Element endEl = ec.create("end"); + + riverEl.setTextContent(river); + startEl.setTextContent(Double.valueOf(from).toString()); + endEl.setTextContent(Double.valueOf(to).toString()); + + mainvalues.appendChild(riverEl); + mainvalues.appendChild(startEl); + mainvalues.appendChild(endEl); + + doc.appendChild(mainvalues); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document result = client.callService(url, "mainvalues", doc); + + logger.debug("Extract wq info objects now."); + WQInfoObject[] objects = extractWQInfoObjects(result); + + if (objects.length > 0) { + return objects; + } + } + catch (ConnectionException ce) { + logger.error(ce, ce); + } + + throw new ServerException(ERROR_NO_WQINFO_FOUND); + } + + + /** + * Extracts all wq info objects from <i>result</i> document. + * + * @param result The document retrieved by the server. + * + * @return a list of WQInfoObjects. + */ + protected WQInfoObject[] extractWQInfoObjects(Document result) + throws ServerException + { + NodeList list = (NodeList) XMLUtils.xpath( + result, + XPATH_WQS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (list == null || list.getLength() == 0) { + logger.warn("No wq info found."); + + throw new ServerException(ERROR_NO_WQINFO_FOUND); + } + + boolean debug = logger.isDebugEnabled(); + + int num = list.getLength(); + if (debug) { + logger.debug("Response contains " + num + " objects."); + } + + List<WQInfoObject> objects = + new ArrayList<WQInfoObject>(num); + + for (int i = 0; i < num; i++) { + WQInfoObject obj = buildWQInfoObject(list.item(i)); + + if (obj != null) { + objects.add(obj); + } + } + + if (debug) { + logger.debug("Retrieved " + objects.size() + " wq values"); + } + + WQInfoObject [] array = (WQInfoObject[]) + objects.toArray(new WQInfoObject[objects.size()]); + + Arrays.sort(array, WQ_INFO_OBJECT_CMP); + + return array; + } + + public static final Comparator<WQInfoObject> WQ_INFO_OBJECT_CMP = + new Comparator<WQInfoObject>() { + @Override + public int compare(WQInfoObject a, WQInfoObject b) { + + // Descending by type: Qs before Ds + int cmp = a.getType().compareTo(b.getType()); + if (cmp < 0) return +1; + if (cmp > 0) return -1; + + // Ascending by value + double diff = a.getValue() - b.getValue(); + if (diff < 0d) return -1; + if (diff > 0d) return +1; + return 0; + } + }; + + /** + * Extracts information for a single wq info object and intializes an + * WQInfoObject with them. + * + * @param node The node that contains the information. + * + * @return a valid WQInfoObject. + */ + protected static WQInfoObject buildWQInfoObject(Node node) { + + String name = XMLUtils.xpathString( + node, "@name", ArtifactNamespaceContext.INSTANCE); + + String type = XMLUtils.xpathString( + node, "@type", ArtifactNamespaceContext.INSTANCE); + + String value = XMLUtils.xpathString( + node, "@value", ArtifactNamespaceContext.INSTANCE); + + if (name != null && type != null) { + try { + return new WQInfoObjectImpl( + name, + type, + new Double(value)); + } + catch (NumberFormatException nfe) { + logger.warn(nfe.getLocalizedMessage()); + } + } + + logger.warn("Invalid wq info object found."); + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/Authentication.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,15 @@ +package de.intevation.flys.client.server.auth; + +/** Interface to represent user authentications + */ +public interface Authentication { + + /** Returns true if the authentication was successfull + */ + public boolean isSuccess(); + + /** Returns a new User object + */ + public User getUser() throws AuthenticationException; + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/AuthenticationException.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.server.auth; + +/** + * Base class for Authentication related Exceptions + */ +public class AuthenticationException extends Exception { + + public AuthenticationException(String message) { + super(message); + } + + public AuthenticationException(Exception e) { + super(e); + } +} +// vim: set fileencoding=utf-8 ts=4 sw=4 tw=80: +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/AuthenticationFactory.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,31 @@ +package de.intevation.flys.client.server.auth; + +import org.apache.log4j.Logger; + +public class AuthenticationFactory { + + private static final Logger log = + Logger.getLogger(AuthenticationFactory.class); + + public static Authenticator getInstance(String name) + throws IllegalArgumentException + { + if (name == null) { + throw new IllegalArgumentException("Authentication type name is null"); + } + + if (name.equalsIgnoreCase("was") || + name.equalsIgnoreCase("ggina")) { + log.debug("Using GGinA authenticator."); + return + new de.intevation.flys.client.server.auth.was.Authenticator(); + } + else if (name.equalsIgnoreCase("plain")) { + log.debug("Using plain authenticator."); + return + new de.intevation.flys.client.server.auth.plain.Authenticator(); + } + + throw new IllegalArgumentException("Unkown Authentication " + name); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/Authenticator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,12 @@ +package de.intevation.flys.client.server.auth; + +import java.io.IOException; + +import de.intevation.flys.client.server.features.Features; + +public interface Authenticator { + + public Authentication auth(String username, String password, String encoding, Features features) + throws AuthenticationException, IOException; + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/DefaultUser.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,88 @@ +package de.intevation.flys.client.server.auth; + +import java.util.List; + +public class DefaultUser +implements User +{ + protected String name; + protected String account; + protected String password; + protected boolean expired; + protected List<String> roles; + protected List<String> features; + + public DefaultUser() { + } + + public DefaultUser( + String name, + String password, + boolean expired, + List<String> roles, + List<String> features + ) { + this.name = name; + this.password = password; + this.expired = expired; + this.roles = roles; + this.features = features; + this.account = name; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public boolean hasExpired() { + return expired; + } + + public void setExpired(boolean expired) { + this.expired = expired; + } + + @Override + public List<String> getRoles() { + // XXX: return clone of the list? + return this.roles; + } + + public void setRoles(List<String> roles) { + this.roles = roles; + } + + @Override + public boolean canUseFeature(String feature) { + return this.features.contains(feature); + } + + public void setAllowedFeatures(List<String> features) { + this.features = features; + } + + @Override + public String getAccount() { + return this.account; + } + + public void setAccount(String account) { + this.account = account; + } +} +// vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/User.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,42 @@ +package de.intevation.flys.client.server.auth; + +import java.util.List; + +/** + * User representation after a succesfull login + */ +public interface User { + + /** + * Returns the username as String + */ + public String getName(); + + /** + * Returns the password of the user as String + */ + public String getPassword(); + + /** + * Returns True if the authentication for the user + * has expired. + */ + public boolean hasExpired(); + + /** + * Returns a list of roles corresponsing the the user + */ + public List<String> getRoles(); + + + /** + * Returns true if the user is allowed access the feature + */ + public boolean canUseFeature(String feature); + + /** + * Returns the users account name + */ + public String getAccount(); +} +// vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/UserClient.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,158 @@ +package de.intevation.flys.client.server.auth; + +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +/** + * UserClient is a class to allow easier communication + * with the REST based artifact user protocol + */ +public class UserClient { + + private static final Logger logger = Logger.getLogger(UserClient.class); + + private String url; + + public UserClient(String url) { + this.url = url; + } + + public boolean userExists(User user) throws ConnectionException { + if (user == null) { + return false; + } + + Element data = this.findUser(user); + + String XPATH_USERACCOUNT = "/art:user/art:account/@art:name"; + + String account = XMLUtils.xpathString( + data, XPATH_USERACCOUNT, ArtifactNamespaceContext.INSTANCE); + + if (account == null) { + return false; + } + + return account.equals(user.getAccount()); + } + + public boolean createUser(User user) throws ConnectionException { + if(user == null) { + logger.warn("createUser: given user is null"); + return false; + } + + logger.debug("Creating new user " + user.getName()); + HttpClient client = new HttpClientImpl(this.url); + + Document document = XMLUtils.newDocument(); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + Element action = creator.create("action"); + + Element type = creator.create("type"); + type.setAttribute("name", "create"); + Element artuser = creator.create("user"); + artuser.setAttribute("name", user.getName()); + Element account = creator.create("account"); + account.setAttribute("name", user.getAccount()); + + //TODO create roles + artuser.appendChild(account); + action.appendChild(type); + action.appendChild(artuser); + document.appendChild(action); + + logger.debug("Create user request xml: " + XMLUtils.toString(document)); + + Document resp = client.createUser(document); + + logger.debug("Create user response xml: " + XMLUtils.toString(resp)); + + String XPATH_RESPONSE = "/art:result"; + Node nresult = (Node) XMLUtils.xpath( + resp, + XPATH_RESPONSE, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + String result = nresult.getTextContent(); + return (result != null && result.equalsIgnoreCase("success")); + } + + public NodeList listUsers() throws ConnectionException { + HttpClient client = new HttpClientImpl(this.url); + + Document users = (Document) client.listUsers(); + + String XPATH_USERS = "/art:users/art:user"; + + return (NodeList) XMLUtils.xpath( + users, + XPATH_USERS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + } + + public Element findUser(User user) throws ConnectionException { + if(user == null) { + throw new IllegalArgumentException("user is null"); + } + + HttpClient client = new HttpClientImpl(this.url); + + Document document = XMLUtils.newDocument(); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + Element action = creator.create("action"); + + Element type = creator.create("type"); + type.setAttribute("name", "find"); + Element account = creator.create("account"); + account.setAttribute("name", user.getAccount()); + + action.appendChild(type); + action.appendChild(account); + document.appendChild(action); + + boolean debug = logger.isDebugEnabled(); + + if (debug) { + logger.debug("Find user request xml: " + + XMLUtils.toString(document)); + } + + Document resp = client.findUser(document); + + if (debug) { + logger.debug("Find user request response xml: " + + XMLUtils.toString(resp)); + } + + return resp.getDocumentElement(); + } +} +// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80: +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/plain/Authenticator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,134 @@ +package de.intevation.flys.client.server.auth.plain; + +import de.intevation.flys.client.server.auth.AuthenticationException; +import de.intevation.flys.client.server.auth.DefaultUser; +import de.intevation.flys.client.server.auth.User; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.server.features.Features; + +/** + * Authenticator that uses a local file as user backend. + */ +public class Authenticator +implements de.intevation.flys.client.server.auth.Authenticator +{ + private static final Logger log = + Logger.getLogger(Authenticator.class); + + public static class Authentication + implements de.intevation.flys.client.server.auth.Authentication + { + protected String user; + protected String password; + protected List<String> roles; + protected Features features; + + public Authentication( + String user, + String password, + List<String> roles, + Features features + ) { + this.user = user; + this.password = password; + this.roles = roles; + this.features = features; + } + + @Override + public boolean isSuccess() { + return user != null; + } + + @Override + public User getUser() { + return isSuccess() + ? new DefaultUser(user, password, false, roles, this.features.getFeatures(roles)) + : null; + } + } // class Authentication + + public Authenticator() { + } + + private static File credentialsFile() { + String env = System.getenv("FLYS_USER_FILE"); + if (env == null) { + env = System.getProperty( + "flys.user.file", + System.getProperty("user.home", ".") + + System.getProperty("file.separator") + + "flys_user_file"); + } + log.debug("Using credentials file " + env); + return new File(env); + + } + + @Override + public de.intevation.flys.client.server.auth.Authentication auth( + String username, + String password, + String encoding, + Features features + ) + throws AuthenticationException, IOException + { + File file = credentialsFile(); + if (!file.canRead() || !file.isFile()) { + log.error("cannot find user file '" + file + "'"); + return new Authentication(null, null, new ArrayList<String>(0), features); + } + + BufferedReader reader = + new BufferedReader( + new FileReader(file)); + try { + String line; + while ((line = reader.readLine()) != null) { + if ((line = line.trim()).length() == 0 + || line.startsWith("#")) { + continue; + } + + String[] parts = line.split("\\s+"); + if (parts.length < 2) { + continue; + } + + if (parts[0].equals(username)) { + log.debug("user '" + username + "' found."); + if (parts[1].equals(password)) { + List<String> roles = + new ArrayList<String>(parts.length - 2); + + for (int i = 2; i < parts.length; i++) { + roles.add(parts[i]); + } + + log.debug("success"); + return new Authentication(username, password, roles, features); + } + // Stop: user found, wrong password + break; + } + } + } + finally { + reader.close(); + } + log.debug("failed"); + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/Assertion.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,179 @@ +package de.intevation.flys.client.server.auth.was; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Iterator; +import java.util.Date; +import java.util.List; +import java.util.LinkedList; + +import org.apache.log4j.Logger; + +import org.jdom.Element; + +public class Assertion { + + private static Logger logger = Logger.getLogger(Assertion.class); + + private Element assertion; + private LinkedList<String> roles; + private String assertion_id; + private String user_id; + private String name_id; + private String group_id; + private String group_name; + private Date notbefore; + private Date notonorafter; + private Signature signature; + + private static final String ATTR_CONT_USER_ID = + "urn:conterra:names:sdi-suite:policy:attribute:user-id"; + private static final String ATTR_CONT_GROUP_ID = + "urn:conterra:names:sdi-suite:policy:attribute:group-id"; + private static final String ATTR_CONT_GROUP_NAME = + "urn:conterra:names:sdi-suite:policy:attribute:group-name"; + private static final String ATTR_CONT_ROLE = + "urn:conterra:names:sdi-suite:policy:attribute:role"; + + + public Assertion(Element assertion) { + this.assertion = assertion; + this.roles = new LinkedList<String>(); + + this.assertion_id = assertion.getAttributeValue("AssertionID"); + + this.parseContition(); + this.parseAttributeStatement(); + } + + private void parseContition() { + Element condition = this.assertion.getChild("Conditions", + Namespaces.SAML_NS_ASSERT); + if (condition != null) { + SimpleDateFormat dateformat = new SimpleDateFormat(); + // format should be "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" but that's only + // available in java 7+ + dateformat.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + String from = condition.getAttributeValue("NotBefore"); + if (from != null) { + try { + this.notbefore = dateformat.parse(from); + } + catch(ParseException e) { + logger.error("Unknown datetime format for Condition " + + "NotBefore " + from); + } + } + + String until = condition.getAttributeValue("NotOnOrAfter"); + logger.debug("Session is valid until " + until); + if (until != null) { + try { + this.notonorafter = dateformat.parse(until); + } + catch(ParseException e) { + logger.error("Unknown datetime format for Condition " + + "NotOnOrAfter " + until); + } + } + } + } + + private void parseAttributeStatement() { + Element attrstatement = this.assertion.getChild("AttributeStatement", + Namespaces.SAML_NS_ASSERT); + if (attrstatement != null) { + + Element subject = attrstatement.getChild("Subject", + Namespaces.SAML_NS_ASSERT); + if (subject != null) { + this.name_id = subject.getChildText("NameIdentifier", + Namespaces.SAML_NS_ASSERT); + } + + List attributes = attrstatement.getChildren("Attribute", + Namespaces.SAML_NS_ASSERT); + for(Iterator i = attributes.iterator(); i.hasNext();) { + Element attr = (Element)i.next(); + String attrname = attr.getAttributeValue("AttributeName"); + if (attrname.equals(ATTR_CONT_USER_ID)) { + this.user_id = this.getAttributeValue(attr); + } + else if (attrname.equals(ATTR_CONT_GROUP_ID)) { + this.group_id = this.getAttributeValue(attr); + } + else if (attrname.equals(ATTR_CONT_GROUP_NAME)) { + this.group_name = this.getAttributeValue(attr); + } + else if (attrname.equals(ATTR_CONT_ROLE)) { + List roles = attr.getChildren("AttributeValue", + Namespaces.SAML_NS_ASSERT); + for(Iterator j = roles.iterator(); j.hasNext();) { + Element role = (Element)j.next(); + this.roles.add(role.getText()); + } + } + else { + logger.debug("Unknown AttributeName " + attrname + + " found while parsing AttributeStatement."); + } + } + } + } + + private String getAttributeValue(Element attr) { + return attr.getChildText("AttributeValue", Namespaces.SAML_NS_ASSERT); + } + + public List<String> getRoles() { + return this.roles; + } + + public Boolean isValid() { + // TODO: + // check signature digest + // check signature value + // check signature cert + return false; + } + + public Signature getSiganture() { + if (this.signature == null) { + Element signature = this.assertion.getChild("Signature", + Namespaces.XML_SIG_NS); + if (signature != null) { + this.signature = new Signature(signature); + } + } + return this.signature; + } + + public String getUserID() { + return this.user_id; + } + + public String getNameID() { + return this.name_id; + } + + public String getGroupID() { + return this.group_id; + } + + public String getGroupName() { + return this.group_name; + } + + public String getID() { + return this.assertion_id; + } + + public Date getFrom() { + return this.notbefore; + } + + public Date getUntil() { + return this.notonorafter; + } +} +// vim: set fileencoding=utf-8 ts=4 sw=4 et si tw=80:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/Authenticator.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,62 @@ +package de.intevation.flys.client.server.auth.was; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.impl.client.DefaultHttpClient; + +import de.intevation.flys.client.server.GGInATrustStrategy; +import de.intevation.flys.client.server.auth.Authentication; +import de.intevation.flys.client.server.auth.AuthenticationException; +import de.intevation.flys.client.server.features.Features; + +public class Authenticator +implements de.intevation.flys.client.server.auth.Authenticator { + + @Override + public Authentication auth( + String username, + String password, + String encoding, + Features features + ) throws + AuthenticationException, + IOException + { + try { + SSLSocketFactory sf = new SSLSocketFactory( + new GGInATrustStrategy()); + Scheme https = new Scheme("https", 443, sf); + HttpClient httpclient = new DefaultHttpClient(); + httpclient.getConnectionManager().getSchemeRegistry().register( + https); + + Request httpget = new Request("https://geoportal.bafg.de/" + + "administration/WAS", username, password, encoding); + HttpResponse response = httpclient.execute(httpget); + StatusLine stline = response.getStatusLine(); + if (stline.getStatusCode() != 200) { + throw new AuthenticationException("GGInA Server Error. " + + "Statuscode: " + stline.getStatusCode() + + ". Reason: " + stline.getReasonPhrase()); + } + HttpEntity entity = response.getEntity(); + if (entity == null) { + //FIXME throw AuthenticationException + return null; + } + else { + return new Response(entity, username, password, features); + } + } + catch(GeneralSecurityException e) { + throw new AuthenticationException(e); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/Namespaces.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,14 @@ +package de.intevation.flys.client.server.auth.was; + +import org.jdom.Namespace; + +public class Namespaces { + + public static final Namespace SAML_NS_ASSERT = + Namespace.getNamespace("urn:oasis:names:tc:SAML:1.0:assertion"); + public static final Namespace SAML_NS_PROTO = + Namespace.getNamespace("urn:oasis:names:tc:SAML:1.0:protocol"); + public static final Namespace XML_SIG_NS = + Namespace.getNamespace("http://www.w3.org/2000/09/xmldsig#"); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/Request.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,59 @@ +package de.intevation.flys.client.server.auth.was; + +import java.io.UnsupportedEncodingException; +import java.net.URI; + +import org.apache.commons.codec.binary.Base64; +import org.apache.http.client.methods.HttpGet; +import org.apache.log4j.Logger; + +public class Request extends HttpGet { + + private final static String VERSION = "1.1"; + private final static String REQUEST_SAML_RESPONSE = "GetSAMLResponse"; + private final static String METHOD_AUTH_PASSWORD = + "urn:opengeospatial:authNMethod:OWS:1.0:password"; + + private static Logger logger = Logger.getLogger(Request.class); + + public Request(String uri) { + String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + + REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + + "&ANONYMOUS=TRUE&CREDENTIALS="; + this.setURI(URI.create(request)); + } + + public Request(String uri, String user, String pass, String encoding) { + try { + String base64user = this.toBase64(user, encoding); + String base64pass = this.toBase64(pass, encoding); + + String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + + REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + + "&CREDENTIALS=" + base64user + "," + base64pass; + + this.setURI(URI.create(request)); + } + catch(UnsupportedEncodingException e) { + logger.error(e); + } + } + + private String toBase64(String value, String encoding) throws + UnsupportedEncodingException { + if (encoding == null) { + encoding = "utf-8"; + } + try { + return new String(Base64.encodeBase64(value.getBytes(encoding))); + } + catch(UnsupportedEncodingException e) { + logger.warn("Can't encode string with encoding " + encoding + + ". Falling back to utf-8. " + e); + return this.toBase64(value, "utf-8"); + } + } + +} +// vim: set et si fileencoding=utf-8 ts=4 sw=4 tw=80: +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/Response.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,118 @@ +package de.intevation.flys.client.server.auth.was; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import org.apache.commons.codec.binary.Base64InputStream; + +import org.apache.http.HttpEntity; + +import org.apache.log4j.Logger; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; + +import de.intevation.flys.client.server.auth.Authentication; +import de.intevation.flys.client.server.auth.AuthenticationException; + +import de.intevation.flys.client.server.features.Features; + +public class Response implements Authentication { + + private static Logger logger = Logger.getLogger(Response.class); + + private Element root; + private Assertion assertion; + private String username; + private String password; + private Features features; + + + public Response(HttpEntity entity, String username, String password, Features features) throws AuthenticationException, IOException { + + if (entity == null) { + throw new ServiceException("Invalid response"); + } + + String contenttype = entity.getContentType().getValue(); + + try { + InputStream in = entity.getContent(); + + if (!contenttype.equals("application/vnd.ogc.se_xml")) { + // XXX: Assume base64 encoded content. + in = new Base64InputStream(in); + } + + SAXBuilder builder = new SAXBuilder(); + Document doc = builder.build(in); + Element root = doc.getRootElement(); + String rname = root.getName(); + + if (rname != null && rname.equals("ServiceExceptionReport")) { + throw new ServiceException(root.getChildText("ServiceException")); + } + + this.root = root; + this.username = username; + this.password = password; + this.features = features; + + } + catch(JDOMException e) { + throw new AuthenticationException(e); + } + } + + public Element getRoot() { + return this.root; + } + + @Override + public boolean isSuccess() { + String status = getStatus(); + return status != null && status.equals("samlp:Success"); + } + + public String getStatus() { + Element status = this.root.getChild("Status", Namespaces.SAML_NS_PROTO); + if (status == null) { + return null; + } + Element statuscode = status.getChild("StatusCode", + Namespaces.SAML_NS_PROTO); + if (statuscode == null) { + return null; + } + return statuscode.getAttributeValue("Value"); + } + + public Assertion getAssertion() { + if (this.assertion == null && this.root != null) { + Element assertion = this.root.getChild("Assertion", + Namespaces.SAML_NS_ASSERT); + if (assertion != null) { + this.assertion = new Assertion(assertion); + } + } + return this.assertion; + } + + @Override + public User getUser() throws AuthenticationException { + Assertion assertion = this.getAssertion(); + if (assertion == null) { + throw new AuthenticationException("Response doesn't contain an assertion"); + } + List<String> features = this.features.getFeatures( + this.assertion.getRoles()); + logger.debug("User " + this.username + " with features " + features + + " successfully authenticated."); + return new User(this.username, this.password, assertion.getNameID(), + this.assertion.getRoles(), assertion, features); + } +} +// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/ServiceException.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,15 @@ +package de.intevation.flys.client.server.auth.was; + +import de.intevation.flys.client.server.auth.AuthenticationException; + +public class ServiceException extends AuthenticationException { + + public ServiceException(String message) { + super(message); + } + + public ServiceException(Exception e) { + super(e); + } +} +// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/Signature.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,120 @@ +package de.intevation.flys.client.server.auth.was; + +import java.io.ByteArrayInputStream; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; + +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; +import org.jdom.Element; + +public class Signature { + + private static Logger logger = Logger.getLogger(Signature.class); + + private static final String XML_SIG_DIGEST_SHA1 = + "http://www.w3.org/2000/09/xmldsig#sha1"; + private static final String XML_SIG_SIGNATURE_RSA_SHA1 = + "http://www.w3.org/2000/09/xmldsig#rsa-sha1"; + + private final Element signature; + private Certificate cert; + private byte[] value; + private byte[] digestvalue; + private String reference; + + public Signature(Element signature) { + this.signature = signature; + this.parseSignatureInfo(); + this.parseSignatureValue(); + this.parseCertificate(); + } + + private void parseSignatureInfo() { + Element signatureinfo = this.signature.getChild("SignedInfo", + Namespaces.XML_SIG_NS); + if (signatureinfo != null) { + Element signaturemethod = signatureinfo.getChild("SignatureMethod", + Namespaces.XML_SIG_NS); + String algorithm = signaturemethod.getAttributeValue("Algorithm"); + if (!algorithm.equals(XML_SIG_SIGNATURE_RSA_SHA1)) { + logger.warn("Unkown signature alorithm " + algorithm); + } + + // There could be several references in XML-Sig spec but for me it + // doesn't make sense to have more then one in a SAML Assertion + Element reference = signatureinfo.getChild("Reference", + Namespaces.XML_SIG_NS); + // reference must be present but its better to check + if (reference != null) { + String digestvalue = reference.getChildText("DigestValue", + Namespaces.XML_SIG_NS); + String digestmethod = reference.getChildText("DigestMethod", + Namespaces.XML_SIG_NS); + if (!digestmethod.equals(XML_SIG_DIGEST_SHA1)) { + logger.warn("Unknown digest method " + digestmethod); + } + this.digestvalue = Base64.decodeBase64(digestvalue); + + String referenceuri = reference.getAttributeValue("URI"); + if (referenceuri.startsWith("#")) { + this.reference = referenceuri.substring(1); + } + else { + logger.warn("Unkown reference type " + referenceuri); + this.reference = referenceuri; + } + } + } + } + + private void parseSignatureValue() { + String signaturevalue = this.signature.getChildText("SignatureValue", + Namespaces.XML_SIG_NS); + this.value = Base64.decodeBase64(signaturevalue); + } + + private void parseCertificate() { + Element keyinfo = this.signature.getChild("KeyInfo", + Namespaces.XML_SIG_NS); + if (keyinfo != null) { + Element data = keyinfo.getChild("X509Data", Namespaces.XML_SIG_NS); + if (data != null) { + String base64cert = data.getChildText("X509Certificate", + Namespaces.XML_SIG_NS); + if (base64cert != null) { + byte[] bytes = Base64.decodeBase64(base64cert); + try { + CertificateFactory cf = CertificateFactory.getInstance( + "X.509"); + this.cert = cf.generateCertificate( + new ByteArrayInputStream(bytes)); + } + catch(CertificateException e) { + // should never occur + logger.error(e); + } + } + } + } + } + + public Certificate getCertificate() { + return this.cert; + } + + public byte[] getValue() { + return this.value; + } + + public String getReference() { + // In theory there could be several references with digestvalues, ... + return this.reference; + } + + public byte[] getDigestValue() { + return this.digestvalue; + } +} +// vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/User.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.server.auth.was; + +import java.util.Date; +import java.util.List; + +import de.intevation.flys.client.server.auth.DefaultUser; + +public class User +extends DefaultUser +implements de.intevation.flys.client.server.auth.User { + + private Assertion assertion; + + public User(String name, + String password, + String account, + List<String> roles, + Assertion assertion, + List<String> features + ) { + this.setName(name); + this.setPassword(password); + this.setRoles(roles); + this.assertion = assertion; + this.setAllowedFeatures(features); + this.setAccount(account); + } + + @Override + public boolean hasExpired() { + Date until = this.assertion.getUntil(); + if (until != null) { + Date current = new Date(); + return !current.after(until); + } + return false; + } +} + +// vim:set ts=4 sw=4 si et fenc=utf8 tw=80:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/features/Features.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.server.features; + +import java.util.List; + +public interface Features { + + public static final String CONTEXT_ATTRIBUTE = "de.intevation.flys.client.server.features"; + + /** + * Returns all allowed features to a list of roles + */ + public List<String> getFeatures(List<String> roles); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/features/FeaturesNamespaceContext.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,80 @@ +package de.intevation.flys.client.server.features; + +import java.util.Iterator; + +import javax.xml.XMLConstants; + +import javax.xml.namespace.NamespaceContext; + +public class FeaturesNamespaceContext +implements NamespaceContext { + + /** + * The URI of the namespace of the features. + */ + public final static String NAMESPACE_URI = + "http://www.intevation.de/2012/flys/features"; + + /** + * The XML prefix for the features namespace. + */ + public final static String NAMESPACE_PREFIX = "ftr"; + + /** + * Final instance to be easily used to avoid creation + * of instances. + */ + public static final FeaturesNamespaceContext INSTANCE = + new FeaturesNamespaceContext(); + + /** + * The default constructor. + */ + public FeaturesNamespaceContext() { + } + + /** + * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(String) + * @param prefix The prefix + * @return The corresponing URI + */ + @Override + public String getNamespaceURI(String prefix) { + + if (prefix == null) { + throw new NullPointerException("Null prefix"); + } + + if (NAMESPACE_PREFIX.equals(prefix)) { + return NAMESPACE_URI; + } + + if ("xml".equals(prefix)) { + return XMLConstants.XML_NS_URI; + } + + return XMLConstants.NULL_NS_URI; + } + + /** + * @see javax.xml.namespace.NamespaceContext#getPrefix(String) + * @param uri The URI + * @return nothing. + * @throws java.lang.UnsupportedOperationException + */ + @Override + public String getPrefix(String uri) { + throw new UnsupportedOperationException(); + } + + /** + * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) + * @param uri The URI + * @return nothing + * @throws java.lang.UnsupportedOperationException + */ + @Override + public Iterator getPrefixes(String uri) { + throw new UnsupportedOperationException(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/features/XMLFileFeatures.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,96 @@ +package de.intevation.flys.client.server.features; + +import java.io.FileInputStream; +import java.io.IOException; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import de.intevation.artifacts.common.utils.XMLUtils; + +public class XMLFileFeatures implements Features { + + private static final Logger logger = + Logger.getLogger(XMLFileFeatures.class); + + private Map<String, List<String>> featuremap = + new HashMap<String, List<String>>(); + + private final static String XPATH_FEATURES = "ftr:feature/child::text()"; + private final static String XPATH_ROLES = "/ftr:features/ftr:role"; + + public XMLFileFeatures(String filename) throws IOException { + FileInputStream finput = new FileInputStream(filename); + logger.debug("XMLFileFeatures: " + filename); + try { + Document doc = XMLUtils.parseDocument(finput); + + NodeList roles = (NodeList) XMLUtils.xpath( + doc, + XPATH_ROLES, + XPathConstants.NODESET, + FeaturesNamespaceContext.INSTANCE); + + for(int i = 0, m = roles.getLength(); i < m; i++) { + Element rolenode = (Element)roles.item(i); + + String name = rolenode.getAttribute("name"); + + logger.debug("Found role: " + name); + + NodeList features = (NodeList) XMLUtils.xpath( + rolenode, + XPATH_FEATURES, + XPathConstants.NODESET, + FeaturesNamespaceContext.INSTANCE); + + if (features == null) { + continue; + } + + int N = features.getLength(); + + if (N > 0) { + List<String> allowed = new ArrayList<String>(N); + for (int j = 0; j < N; j++) { + Node featurenode = features.item(j); + String featurename = featurenode.getNodeValue(); + + logger.debug("Found feature: " + featurename); + + allowed.add(featurename); + } + featuremap.put(name, allowed); + } + } + logger.debug("Loaded all features"); + } + finally { + finput.close(); + } + } + + @Override + public List<String> getFeatures(List<String> roles) { + List<String> features = new ArrayList<String>(); + + for (String role: roles) { + List<String> allowed = this.featuremap.get(role); + if (allowed != null) { + features.addAll(allowed); + } + } + return features; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/filter/GGInAFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,206 @@ +package de.intevation.flys.client.server.filter; + +import de.intevation.flys.client.server.auth.Authentication; +import de.intevation.flys.client.server.auth.AuthenticationException; +import de.intevation.flys.client.server.auth.AuthenticationFactory; +import de.intevation.flys.client.server.auth.User; +import de.intevation.flys.client.server.features.Features; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Enumeration; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; + + +/** ServletFilter used for GGInA authentification and certain authorisation. */ +public class GGInAFilter implements Filter { + + /** Private logger. */ + private static Logger logger = Logger.getLogger(GGInAFilter.class); + + private boolean deactivate = false; + private String authmethod; + private String redirecturl; + private ServletContext sc; + + private static final String LOGIN_JSP = "/login.jsp"; + private static final String LOGIN_SERVLET = "/flys/login"; + private static final String FLYS_CSS = "/FLYS.css"; + + + /** + * Initialize. + * + * Read FilterConfig parameter deactivate + */ + @Override + public void init(FilterConfig config) + throws ServletException + { + String deactivate = config.getInitParameter("deactivate"); + this.sc = config.getServletContext(); + logger.debug("GGInAFilter context " + this.sc.getContextPath()); + this.authmethod = sc.getInitParameter("authentication"); + this.redirecturl = sc.getInitParameter("redirect-url"); + if (deactivate != null && deactivate.equalsIgnoreCase("true")) { + this.deactivate = true; + } + + } + + + /** + * Called when filter in chain invoked. + * @param req request to servlet + * @param resp response of servlet + * @param chain the filter chain + */ + @Override + public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) + throws IOException, ServletException + { + if (this.deactivate) { + logger.debug("GGinAFilter is deactivated"); + chain.doFilter(req, resp); + return; + } + + HttpServletRequest sreq = (HttpServletRequest) req; + + String requesturi = sreq.getRequestURI(); + if (logger.isDebugEnabled()) { + for (Enumeration e = req.getAttributeNames() ; e.hasMoreElements() ;) { + logger.debug(e.nextElement()); + } + } + + logger.debug("Request for: " + requesturi); + + // Allow access to localhost + if (isLocalAddress(req)) { + logger.debug("Request to localhost"); + chain.doFilter(req, resp); + return; + } + + // Allow access to login pages + String path = this.sc.getContextPath(); + if (requesturi.equals(path + LOGIN_JSP) + || requesturi.equals(path + LOGIN_SERVLET) + || requesturi.equals(path + FLYS_CSS)) { + logger.debug("Request for login " + requesturi); + chain.doFilter(req, resp); + return; + } + + boolean redirect = false; + + HttpSession session = sreq.getSession(); + + String uri = path + "/" + this.redirecturl; + + /* Redirect if uri is root or redirecturl */ + if (requesturi.equals(uri) || requesturi.equals(path + "/")) { + redirect = true; + } + + String queryString = sreq.getQueryString(); + + if (queryString != null) { + uri += "?" + queryString; + } + session.setAttribute("requesturi", uri); + + User user = (User)session.getAttribute("user"); + if (user == null) { + logger.debug("No user in session: " + requesturi); + this.handleResponse(resp, redirect); + return; + } + if (user.hasExpired()) { + // try to re-authenticate the user + logger.debug("User ticket has expired: " + requesturi); + String encoding = sreq.getCharacterEncoding(); + try { + Authentication auth = this.auth(user, encoding); + if (auth == null || !auth.isSuccess()) { + logger.debug("Re-athentication not successful"); + this.handleResponse(resp, redirect); + } + } + catch(AuthenticationException e) { + logger.error("Failure during re-authentication", e); + this.handleResponse(resp, redirect); + return; + } + } + + chain.doFilter(req, resp); + return; + } + + private void redirect(ServletResponse resp) throws IOException { + logger.debug("Redirect to login"); + ((HttpServletResponse) resp).sendRedirect(this.sc.getContextPath() + + "/login.jsp"); + } + + private void sendNotAuthenticated(ServletResponse resp) throws IOException { + logger.debug("Send not authenticated"); + ((HttpServletResponse)resp).sendError(HttpServletResponse.SC_FORBIDDEN, "User not authenticated"); + } + + private void handleResponse(ServletResponse resp, boolean redirect) throws IOException { + if (redirect) { + this.redirect(resp); + } + else { + this.sendNotAuthenticated(resp); + } + } + + + /** + * Do nothing at destruction. + */ + @Override + public void destroy() { + } + + private Authentication auth(User user, String encoding) + throws AuthenticationException, IOException { + Features features = (Features)sc.getAttribute(Features.CONTEXT_ATTRIBUTE); + return AuthenticationFactory.getInstance(this.authmethod).auth( + user.getName(), user.getPassword(), encoding, features); + } + + /** + * Returns true if the request is from our machine + * @param req The ServletRequest + * @return true if the request is from a loopback interface or from one of + * the interface addresses of the machine + */ + private boolean isLocalAddress(ServletRequest req) { + try { + InetAddress addr = InetAddress.getByName(req.getRemoteAddr()); + return addr.isAnyLocalAddress() || addr.isLoopbackAddress(); + } catch (UnknownHostException e) { + logger.error(e, e); + return false; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/filter/NoCacheFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,72 @@ +package de.intevation.flys.client.server.filter; + +import java.io.IOException; +import java.util.Date; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +/** ServletFilter to avoid caching for GWTs *.nocache.* files. */ +public class NoCacheFilter implements Filter { + + private static final long DAY = 86400000L; + + private static final String NO_CACHE = ".nocache."; + + private static Logger log = Logger.getLogger(NoCacheFilter.class); + + /** + * Initialize. + */ + @Override + public void init(FilterConfig config) + throws ServletException + { + } + + + /** + * Called when filter in chain invoked. + * @param req request to servlet + * @param resp response of servlet + * @param chain the filter chain + */ + @Override + public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) + throws IOException, ServletException + { + HttpServletRequest httpreq = (HttpServletRequest)req; + String uri = httpreq.getRequestURI(); + + if (uri.contains(NO_CACHE)) { + log.debug("Set no-cache for " + uri); + + Date now = new Date(); + HttpServletResponse httpresp = (HttpServletResponse)resp; + httpresp.setDateHeader("Date", now.getTime()); + httpresp.setDateHeader("Expires", now.getTime() - DAY); + httpresp.setHeader("Pragma", "no-cache"); + httpresp.setHeader("Cache-control", + "no-cache, no-store, must-revalidate"); + } + + chain.doFilter(req, resp); + } + + + /** + * Do nothing at destruction. + */ + @Override + public void destroy() { + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/server/meta/Converter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,161 @@ +package de.intevation.flys.client.server.meta; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; + +import org.apache.log4j.Logger; + +import de.intevation.flys.client.shared.model.DataCageTree; +import de.intevation.flys.client.shared.model.DataCageNode; +import de.intevation.flys.client.shared.model.AttrList; + +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + +import de.intevation.artifacts.common.utils.XMLUtils; + +/** + * Converts document parts (meta-data xml) to datacagenodes/trees, + * which are shown in datacage widgets. + */ +public class Converter +{ + private static final Logger logger = Logger.getLogger(Converter.class); + + + public interface NodeConverter + { + DataCageNode convert(Element node, Converter converter); + + } // interface NodeConverter + + public static class NameConverter implements NodeConverter { + public DataCageNode convert(Element node, Converter converter) { + //System.err.println("NameConverter called"); + DataCageNode out = new DataCageNode( + node.getAttribute("name"), + toAttrList(node.getAttributes())); + converter.convertChildren(out, node); + return out; + } + } // class NameConverter + + public static class I18NConverter implements NodeConverter { + public DataCageNode convert(Element node, Converter converter) { + //System.err.println("I18NConverter called"); + + String name = node.getLocalName(); + String desc = node.hasAttribute("description") + ? node.getAttribute("description") + : "${" + name + "}"; + + DataCageNode out = + new DataCageNode(name, desc, toAttrList(node.getAttributes())); + + converter.convertChildren(out, node); + return out; + } + } // I18NConverter + + private static Map<String, NodeConverter> converters = new HashMap<String, NodeConverter>(); + + public static final NodeConverter NAME_CONVERTER = new NameConverter(); + public static final NodeConverter I18N_CONVERTER = new I18NConverter(); + + static { + converters.put("river", NAME_CONVERTER); + converters.put("gauge", NAME_CONVERTER); + converters.put("historical", NAME_CONVERTER); + converters.put("column", NAME_CONVERTER); + } + + + /** Trivial constructor. */ + public Converter() { + } + + + public DataCageTree convert(Document document) { + logger.debug("convert called"); + + if (logger.isDebugEnabled()) { + logger.debug(XMLUtils.toString(document)); + } + + ArrayList<DataCageNode> roots = new ArrayList<DataCageNode>(); + NodeList nodes = document.getChildNodes(); + for (int i = 0, N = nodes.getLength(); i < N; ++i) { + Node node = nodes.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element ele = (Element)node; + roots.add(convertElement(ele)); + } + } + return roots.isEmpty() + ? new DataCageTree() + : new DataCageTree(roots.get(0)); + } + + protected void convertChildren(DataCageNode parent, Element sub) { + //System.err.println("convertChildren called"); + NodeList children = sub.getChildNodes(); + for (int i = 0, N = children.getLength(); i < N; ++i) { + Node child = children.item(i); + if (child.getNodeType() == Node.ELEMENT_NODE) { + Element childele = (Element)child; + parent.addChild(convertElement(childele)); + + if (childele.hasAttribute("description")) + logger.debug("nwd: " + childele.getAttribute("description")); + } + } // for all children + } + + private DataCageNode convertElement(Element element) { + String name = element.getLocalName(); + + logger.debug("search for name: " + name); + + NodeConverter converter = converters.get(name); + if (converter == null) { + converter = I18N_CONVERTER; + } + return converter.convert(element, this); + + } + + + /** + * Creates key/value pairs from Nodes Attributes. + */ + public static AttrList toAttrList(NamedNodeMap nodeMap) { + if (nodeMap == null) { + return null; + } + int N = nodeMap.getLength(); + + if (N == 0) { + return null; + } + + AttrList result = new AttrList(N); + + for (int i = 0; i < N; ++i) { + Node node = nodeMap.item(i); + if (node.getNodeType() == Node.ATTRIBUTE_NODE) { + Attr attr = (Attr)node; + String key = attr.getName(); + String value = attr.getValue(); + result.add(key, value); + } + } + + return result; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/DoubleUtils.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,81 @@ +package de.intevation.flys.client.shared; + + +public final class DoubleUtils { + + public static final String DEFAULT_DELIM = " "; + + + private DoubleUtils() { + } + + + public static Double getDouble(String value) { + try { + return Double.valueOf(value); + } + catch (NumberFormatException nfe) { + // do nothing + } + + return null; + } + + + public static double[] getMinMax(String value) { + return getMinMax(value, DEFAULT_DELIM); + } + + + public static double[] getMinMax(String value, String delim) { + if (value == null) { + return null; + } + + String[] values = value.split(delim); + + int len = values != null ? values.length : 0; + double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + + for (int i = 0; i < len; i++) { + Double d = getDouble(values[i]); + + if (d != null) { + mm[0] = mm[0] < d ? mm[0] : d; + mm[1] = mm[1] > d ? mm[1] : d; + } + } + + return mm[0] != Double.MAX_VALUE && mm[1] != -Double.MAX_VALUE + ? mm + : null; + } + + /** toIndex is not inclusive, fromIndex is. */ + static void fill(double[] array, int fromIndex, int toIndex, double val) { + for (int i = fromIndex; i < toIndex; i++) { + array[i] = val; + } + } + + /** @see java.util.Arrays.copyOf */ + public static double[] copyOf(double[] toCopy, int newLen) { + double[] nArray = new double[newLen]; + + if (toCopy == null) { + fill(nArray, 0, nArray.length, 0d); + return nArray; + } + + int goTo = (newLen < toCopy.length) + ? newLen + : toCopy.length; + + for (int i = 0; i < goTo; i++) { + nArray[i] = toCopy[i]; + } + fill (nArray, goTo, nArray.length, 0d); + return nArray; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/FieldVerifier.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,42 @@ +package de.intevation.flys.client.shared; + +/** + * <p> + * FieldVerifier validates that the name the user enters is valid. + * </p> + * <p> + * This class is in the <code>shared</code> package because we use it in both + * the client code and on the server. On the client, we verify that the name is + * valid before sending an RPC request so the user doesn't have to wait for a + * network round trip to get feedback. On the server, we verify that the name is + * correct to ensure that the input is correct regardless of where the RPC + * originates. + * </p> + * <p> + * When creating a class that is used on both the client and the server, be sure + * that all code is translatable and does not use native JavaScript. Code that + * is note translatable (such as code that interacts with a database or the file + * system) cannot be compiled into client side JavaScript. Code that uses native + * JavaScript (such as Widgets) cannot be run on the server. + * </p> + */ +public class FieldVerifier { + + /** + * Verifies that the specified name is valid for our service. + * + * In this example, we only require that the name is at least four + * characters. In your application, you can use more complex checks to ensure + * that usernames, passwords, email addresses, URLs, and other fields have the + * proper syntax. + * + * @param name the name to validate + * @return true if valid, false if invalid + */ + public static boolean isValidName(String name) { + if (name == null) { + return false; + } + return name.length() > 3; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/MapUtils.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,43 @@ +package de.intevation.flys.client.shared; + +import java.util.Date; + + +public class MapUtils { + + public static final String GET_LEGEND_GRAPHIC_TEMPLATE = + "${SERVER}SERVICE=WMS&VERSION=1.1.1&layer=${LAYER}" + + "&REQUEST=getLegendGraphic&FORMAT=image/png"; + + + private MapUtils() { + } + + public static String getLegendGraphicUrl(String server, String layer) { + return getLegendGraphicUrl(server, layer, -1); + } + + public static String getLegendGraphicUrl(String server, String layer, int dpi) { + if (server == null || layer == null) { + return null; + } + + if (server.contains("osm.intevation.de")) { + // GetLegend is not implemented at osm.intevation.de + // This avoids an error in the print log + return null; + } + server = server.indexOf("?") >= 0 ? server : server + "?"; + + String url = GET_LEGEND_GRAPHIC_TEMPLATE; + url = url.replace("${SERVER}", server); + url = url.replace("${LAYER}", layer); + url = url + "×tamp=" + new Date().getTime(); + if (dpi != -1) { + url+="&legend_options=dpi:" + dpi; + } + + return url; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/Transform2D.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,129 @@ +package de.intevation.flys.client.shared; + +import java.io.Serializable; +import java.util.Date; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; +import com.google.gwt.i18n.client.NumberFormat; + + +/** + * This object supports a linear transformation to transform xy coordinates into + * an other coordinate system based on scale and translation values. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class Transform2D implements Serializable { + + protected String xType; + protected String yType; + + protected double sx; + protected double sy; + + protected double tx; + protected double ty; + + + public Transform2D() { + } + + + /** + * Creates a new transformation with scale and translation factors. + * + * @param sx The scale factor for the x axis. + * @param sy The scale factor for the y axis. + * @param tx The translation factor for the x axis. + * @param ty The translation factor for the y axis. + */ + public Transform2D(double sx, double sy, double tx, double ty) { + this(sx, sy, tx, ty, "number", "number"); + } + + + public Transform2D( + double sx, double sy, + double tx, double ty, + String xType, + String yType + ) { + this.xType = xType; + this.yType = yType; + + this.sx = sx; + this.sy = sy; + this.tx = tx; + this.ty = ty; + } + + + /** + * Transforms the pixel x and y into a new coordinate system based on the + * scale and translation values specified in the constructor. + */ + public double[] transform(double x, double y) { + double resX = sx * x + tx; + double resY = sy * y + ty; + + return new double[] { resX, resY }; + } + + + public String[] format(Number[] xy) { + String x = null; + String y = null; + + if (xType.equals("date")) { + x = formatDate(xy[0].longValue()); + } + else { + x = formatNumber(xy[0].doubleValue()); + } + + if (yType.equals("date")) { + y = formatDate(xy[1].longValue()); + } + else { + y = formatNumber(xy[1].doubleValue()); + } + + return new String[] { x, y }; + } + + + protected String formatDate(long time) { + Date date = new Date(time); + DateTimeFormat df = getDateTimeFormat(); + + return df.format(date); + } + + + protected String formatNumber(double number) { + NumberFormat nf = getNumberFormat(); + + return nf.format(number); + } + + + public DateTimeFormat getDateTimeFormat() { + return DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT); + } + + + public NumberFormat getNumberFormat() { + return NumberFormat.getDecimalFormat(); + } + + + public void dumpGWT() { + GWT.log("SX = " + sx); + GWT.log("SY = " + sy); + GWT.log("TX = " + tx); + GWT.log("TY = " + ty); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/exceptions/AuthenticationException.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,23 @@ +package de.intevation.flys.client.shared.exceptions; + +import java.io.Serializable; + + +/** + * This exception class is used if an error occured while user authentication. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class AuthenticationException +extends Exception +implements Serializable +{ + public AuthenticationException() { + } + + + public AuthenticationException(String msg) { + super(msg); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/exceptions/ServerException.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.shared.exceptions; + +import java.io.Serializable; + + +public class ServerException +extends Exception +implements Serializable +{ + public ServerException() { + } + + + public ServerException(String msg) { + super(msg); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Artifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,70 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.List; + + +/** + * This class represents an artifact for the client. It contains the necessary + * information for the client and the communication with the artifact server. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Artifact extends Serializable { + + /** + * Returns the UUID of the artifact. + * + * @return the UUID. + */ + public String getUuid(); + + + /** + * Returns the hash of the artifact. + * + * @return the hash. + */ + public String getHash(); + + + /** + * Returns the name of the artifact. + * This happens to be the factory name, too. + * + * @return the name. + */ + public String getName(); + + /** + * Returns the ArtifactDescription. + * + * @return the artifact description. + */ + public ArtifactDescription getArtifactDescription(); + + + /** + * Returns true, if the Artifact is in Background mode. + * + * @return true, if the artifact is in background mode. + */ + public boolean isInBackground(); + + + /** + * Return a list of background messages. + * + * @return a list of background messages. + */ + public List<CalculationMessage> getBackgroundMessages(); + + + /** + * Sets a new ArtifactDescription. + * + * @param artifactDescription The new artifact description. + */ + public void setArtifactDescription(ArtifactDescription artifactDescription); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ArtifactDescription.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,98 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * The artifact description describes a state of an artifact. There are + * operations defined that return former inserted data, possible input values + * and output targets that are available in the current state of the artifact. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface ArtifactDescription extends Serializable { + + /** + * Returns the data that have been inserted in former states of the + * artifact. + * + * @return the old data of former states. + */ + public DataList[] getOldData(); + + + /** + * Returns the data with all its options that might be inserted in the + * current state of the artifact. + * + * @return the current data. + */ + public DataList getCurrentData(); + + + /** + * Returns the current state as string. + * + * @return the current state. + */ + public String getCurrentState(); + + + /** + * Returns the reachable states as string. + * + * @return the reachable states. + */ + public String[] getReachableStates(); + + + /** + * Returns the name of the selected river. + * + * @return the selected river. + */ + public String getRiver(); + + + /** + * Returns the selected min and max kilomter if existing otherwise null. + * + * @return an array of [min-km, max-km] if existing otherwise null. + */ + public double[] getKMRange(); + + + /** + * Returns the selected reference gauge (which needs to be a data named + * 'reference_gauge'. + * + * @return the selected reference gauge (which needs to be a data named + * 'reference_gauge'. + */ + public String getReferenceGauge(); + + + /** + * Returns the string value of a data object with name <i>dataName</i>. + * + * @return the string value of a data object with name <i>dataName</i>. + */ + public String getDataValueAsString(String dataName); + + + /** + * Returns the available output modes. + * + * @return the available output modes. + */ + public OutputMode[] getOutputModes(); + + + /** + * Returns the recommended artifacts suggested by the server. + * + * @return the recommended artifacts. + */ + public Recommendation[] getRecommendations(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ArtifactFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,64 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.HashMap; +import java.util.Map; +import java.util.List; + +public class ArtifactFilter +implements Serializable +{ + protected String factoryName; + + protected Map<String, OutFilter> outFilters; + + public ArtifactFilter() { + outFilters = new HashMap<String, OutFilter>(); + } + + public ArtifactFilter(String factoryName) { + this(); + this.factoryName = factoryName; + } + + public String getFactoryName() { + return factoryName; + } + + public void setFactoryName(String factoryName) { + this.factoryName = factoryName; + } + + public void add(String out, String name, String num) { + if (out == null) { + out = ToLoad.uniqueKey(outFilters); + } + + OutFilter outFilter = outFilters.get(out); + + if (outFilter == null) { + outFilter = new OutFilter(out); + outFilters.put(out, outFilter); + } + outFilter.add(name, num); + } + + public String collectIds() { + StringBuilder sb = new StringBuilder(); + for (OutFilter outFilter: outFilters.values()) { + outFilter.collectIds(sb); + } + return sb.toString(); + } + + public Recommendation.Filter toFilter() { + Recommendation.Filter rf = new Recommendation.Filter(); + for (Map.Entry<String, OutFilter> entry: outFilters.entrySet()) { + List<Recommendation.Facet> facets = entry.getValue().toFacets(); + rf.add(entry.getKey(), facets); + } + return rf; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,37 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; +import java.util.ArrayList; + +import java.io.Serializable; + +public class AttrList implements Serializable +{ + protected List<String> keyValues; + + public AttrList() { + this(5); + } + + public AttrList(int size) { + keyValues = new ArrayList<String>(size*2); + } + + public int size() { + return keyValues != null ? keyValues.size()/2 : null; + } + + public String getKey(int index) { + return keyValues.get(index*2); + } + + public String getValue(int index) { + return keyValues.get(index*2 + 1); + } + + public void add(String key, String value) { + keyValues.add(key); + keyValues.add(value); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/AttributedTheme.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,197 @@ +package de.intevation.flys.client.shared.model; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class AttributedTheme implements Theme { + + protected Map<String, String> attributes; + + /** CollectionItem associated with this facet/themes artifact. */ + protected CollectionItem collectionItem; + + public AttributedTheme() { + this.attributes = new HashMap<String, String>(); + } + + + public Set<String> getKeys() { + return attributes.keySet(); + } + + + public void addAttr(String name, String value) { + if (name != null && value != null) { + attributes.put(name, value); + } + } + + + public String getAttr(String name) { + return attributes.get(name); + } + + + public Integer getAttrAsInt(String name) { + String attr = getAttr(name); + + if (attr != null && attr.length() > 0) { + try { + return Integer.parseInt(attr); + } + catch (NumberFormatException nfe) { + } + } + + return null; + } + + + public boolean getAttrAsBoolean(String name) { + String attr = getAttr(name); + + if (attr != null) { + try { + int num = Integer.valueOf(attr); + return num > 0; + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + return Boolean.valueOf(attr); + } + + + @Override + public int getPosition() { + Integer pos = getAttrAsInt("pos"); + + return pos != null ? pos.intValue() : -1; + } + + + @Override + public void setPosition(int pos) { + addAttr("pos", String.valueOf(pos)); + } + + + @Override + public int getIndex() { + Integer idx = getAttrAsInt("index"); + + return idx != null ? idx.intValue() : -1; + } + + + @Override + public int getActive() { + return getAttrAsInt("active"); + } + + + @Override + public void setActive(int active) { + addAttr("active", String.valueOf(active)); + } + + + @Override + public String getArtifact() { + return getAttr("artifact"); + } + + + @Override + public String getFacet() { + return getAttr("facet"); + } + + + @Override + public String getDescription() { + return getAttr("description"); + } + + + @Override + public void setDescription(String description) { + if (description != null && description.length() > 0) { + addAttr("description", description); + } + } + + + @Override + public int getVisible() { + return getAttrAsInt("visible"); + } + + + @Override + public void setVisible(int visible) { + addAttr("visible", String.valueOf(visible)); + } + + + @Override + public boolean equals(Object o) { + if (!(o instanceof AttributedTheme)) { + return false; + } + + AttributedTheme other = (AttributedTheme) o; + + if (other.getPosition() != getPosition()) { + return false; + } + + if (!other.getArtifact().equals(getArtifact())) { + return false; + } + + if (other.getActive() != getActive()) { + return false; + } + + if (!other.getFacet().equals(getFacet())) { + return false; + } + + if (!other.getDescription().equals(getDescription())) { + return false; + } + + if (other.getIndex() != getIndex()) { + return false; + } + + if (other.getVisible() != getVisible()) { + return false; + } + + return true; + } + + + /** Get the CollectionItem representing the facets artifact. */ + @Override + public CollectionItem getCollectionItem() { + return collectionItem; + } + + + /** Set the CollectionItem representing the facets artifact. */ + @Override + public void setCollectionItem(CollectionItem ci) { + this.collectionItem = ci; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Axis.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Axis extends Serializable { + + int getPos(); + + Number getFrom(); + + Number getTo(); + + Number getMin(); + + Number getMax(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/BBox.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,74 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public class BBox implements Serializable { + + public double lowerX; + public double upperX; + public double lowerY; + public double upperY; + + + public BBox() { + } + + + public BBox(double lowerX, double lowerY, double upperX, double upperY) { + this.lowerX = lowerX; + this.lowerY = lowerY; + this.upperX = upperX; + this.upperY = upperY; + } + + + public double getLowerX() { + return lowerX; + } + + + public double getLowerY() { + return lowerY; + } + + + public double getUpperX() { + return upperX; + } + + + public double getUpperY() { + return upperY; + } + + + public String toString() { + return + "(" + lowerX + "," + lowerY + ")" + + "(" + upperX + "," + upperY + ")"; + } + + + public static BBox getBBoxFromString(String bbox) { + String[] coords = bbox != null ? bbox.split(" ") : null; + + if (coords == null || coords.length < 4) { + return null; + } + + try { + return new BBox( + Double.parseDouble(coords[0]), + Double.parseDouble(coords[1]), + Double.parseDouble(coords[2]), + Double.parseDouble(coords[3])); + } + catch (NumberFormatException nfe) { + // do nothing here + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/BooleanProperty.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,53 @@ +package de.intevation.flys.client.shared.model; + +import java.util.HashMap; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class BooleanProperty extends PropertySetting { + + /** + * Create a new BooleanProperty for settings. + */ + public BooleanProperty() { + this.attributes = new HashMap<String, String>(); + } + + + /** + * Create a new BooleanProperty. + * @param name The attribute name. + * @param value The current value. + */ + public BooleanProperty( + String name, + Boolean value) + { + this.name = name; + this.value = value.toString(); + this.attributes = new HashMap<String, String>(); + } + + + @Override + public Boolean getValue() { + return Boolean.valueOf(this.value); + } + + + public void setValue(Boolean value) { + this.value = value.toString(); + } + + + public Object clone() { + BooleanProperty clone = new BooleanProperty(this.getName(), + this.getValue()); + for(String s: this.getAttributeList()) { + clone.setAttribute(s, this.getAttribute(s)); + } + return clone; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/CalculationMessage.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,37 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public class CalculationMessage implements Serializable { + + protected int steps; + protected int currentStep; + protected String message; + + + public CalculationMessage() { + } + + + public CalculationMessage(int steps, int currentStep, String message) { + this.steps = steps; + this.currentStep = currentStep; + this.message = message; + } + + + public int getSteps() { + return steps; + } + + + public int getCurrentStep() { + return currentStep; + } + + + public String getMessage() { + return message; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Capabilities.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,95 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +public class Capabilities implements Serializable { + + protected String title; + protected String onlineResource; + protected String fees; + protected String accessConstraints; + + protected ContactInformation contactInformation; + + protected List<WMSLayer> layers; + + + public Capabilities() { + layers = new ArrayList<WMSLayer>(); + } + + + /** + * @param fees + * @param accessConstraints + * @param layers + */ + public Capabilities( + String title, + String onlineResource, + ContactInformation contactInformation, + String fees, + String accessConstraints, + List<WMSLayer> layers + ) { + this.title = title; + this.onlineResource = onlineResource; + this.contactInformation = contactInformation; + this.fees = fees; + this.accessConstraints = accessConstraints; + this.layers = layers; + } + + + public String getTitle() { + return title; + } + + + public String getOnlineResource() { + return onlineResource; + } + + + public ContactInformation getContactInformation() { + return contactInformation; + } + + + public String getFees() { + return fees; + } + + + public String getAccessConstraints() { + return accessConstraints; + } + + + public List<WMSLayer> getLayers() { + return layers; + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("--- Capabilities ---\n"); + sb.append("Title:.............. " + title + "\n"); + sb.append("Online Resource:.... " + onlineResource + "\n"); + sb.append("Contact Information: " + contactInformation + "\n"); + sb.append("Fees:............... " + fees + "\n"); + sb.append("Access Constraints:. " + accessConstraints + "\n"); + sb.append("Layers: "); + + for (WMSLayer layer: layers) { + sb.append(" - " + layer + "\n"); + } + + return sb.toString(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ChartArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + + +/** + * The Chart implementation of an Artifact. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class ChartArtifact extends DefaultArtifact { + + /** The name of this artifact: 'new_chart'.*/ + public static final String NAME = "new_chart"; + + + public ChartArtifact() { + } + + + public ChartArtifact(String uuid, String hash) { + super(uuid, hash); + } + + + public ChartArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ChartInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,98 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import com.google.gwt.core.client.GWT; + +import de.intevation.flys.client.shared.Transform2D; + + +/** + * Give information about chart dimension and transform of chart<->pixel + * space. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartInfo implements Serializable { + + protected Axis[] xAxes; + protected Axis[] yAxes; + + protected Transform2D[] transformer; + + + public ChartInfo() { + } + + + public ChartInfo(Axis[] xAxes, Axis[] yAxes, Transform2D[] transformer) { + this.xAxes = xAxes; + this.yAxes = yAxes; + this.transformer = transformer; + } + + + public Transform2D getTransformer(int pos) { + if (pos >= 0 && pos < transformer.length) { + return transformer[pos]; + } + + return null; + } + + + public int getTransformerCount() { + return transformer.length; + } + + + public int getXAxisCount() { + return xAxes.length; + } + + + public int getYAxisCount() { + return yAxes.length; + } + + + public Axis getXAxis(int pos) { + if (pos >= 0 && pos < xAxes.length) { + return xAxes[pos]; + } + + return null; + } + + + public Axis getYAxis(int pos) { + if (pos >= 0 && pos < yAxes.length) { + return yAxes[pos]; + } + + return null; + } + + + public void dumpGWT() { + StringBuilder sb = new StringBuilder(); + + Axis x = getXAxis(0); + + GWT.log("X axis:"); + GWT.log("... from " + x.getFrom() + " to " + x.getTo()); + GWT.log("... min " + x.getMin() + " max " + x.getMax()); + + for (int i = 0, count = getYAxisCount(); i < count; i++) { + Axis y = getYAxis(i); + + GWT.log("Y axis " + i + ":"); + GWT.log("... from " + y.getFrom() + " to " + y.getTo()); + GWT.log("... min " + y.getMin() + " max " + y.getMax()); + } + + for (Transform2D t: transformer) { + t.dumpGWT(); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ChartMode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,50 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; +import de.intevation.flys.client.client.ui.chart.ChartOutputTab; +import de.intevation.flys.client.client.ui.chart.NaviChartOutputTab; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartMode extends DefaultOutputMode { + + public ChartMode() { + } + + + public ChartMode(String name, String desc, String mimeType) { + super(name, desc, mimeType); + } + + + public ChartMode( + String name, + String descrition, + String mimeType, + List<Facet> facets, + String type) + { + super(name, descrition, mimeType, facets); + this.type = type; + } + + + /** Create output tab. Some outs feel better inside a specialized one. */ + @Override + public OutputTab createOutputTab(String t, Collection c, CollectionView p) { + if (this.getName().equals("fix_wq_curve") || + this.getName().equals("extreme_wq_curve") || + this.getName().equals("fix_deltawt_curve") || + this.getName().equals("fix_derivate_curve") || + this.getName().equals("fix_vollmer_wq_curve")){ + return new NaviChartOutputTab(t, c, this, p); + } + return new ChartOutputTab(t, c, this, p); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Collection.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,68 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.Map; + + +/** + * The artifact collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Collection extends Serializable { + + public String identifier(); + + public String getName(); + + public void setName(String name); + + public Date getCreationTime(); + + /** TODO never called, trivial implementation. Can be removed? */ + public Date getLastAccess(); + + public long getTTL(); + + public void setTTL(long ttl); + + public void addItem(CollectionItem item); + + public int getItemLength(); + + public CollectionItem getItem(int idx); + + public CollectionItem getItem(String uuid); + + public Map<String, OutputMode> getOutputModes(); + + public ThemeList getThemeList(String outName); + + public Settings getSettings(String outName); + + public void setSettings(Map<String, Settings> settings); + + public void addSettings(String name, Settings settings); + + /** Sets mapping outputname to ThemeList. */ + public void setThemeLists(Map<String, ThemeList> map); + + public List<Recommendation> getRecommendations(); + + public void addRecommendation(Recommendation recommendation); + + public void addRecommendations(List<Recommendation> recommendations); + + public boolean loadedRecommendation(Recommendation recommendation); + + public boolean hasItems(); + + /** + * Returns the name which should be displayed in the client gui + * @return String display name + */ + public String getDisplayName(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/CollectionItem.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,57 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + + +/** + * The CollectionItem interface that provides methods to get information about + * artifacts and its output modes. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface CollectionItem extends Serializable { + + /** + * Returns the identifier of the wrapped artifact. + * + * @return the identifier of the wrapped artifact. + */ + String identifier(); + + + /** + * Returns the hash of the wrapped artifact. + * + * @return the hash of the wrapped artifact. + */ + String hash(); + + + /** + * Returns the output modes of the wrapped artifact. + * + * @return the output modes of the wrapped artifact. + */ + List<OutputMode> getOutputModes(); + + + /** + * Returns the facets of the wrapped artifact for a specific output mode. + * + * @param outputmode The name of an output mode that is supported by this + * item. + * + * @return the facets of the wrapped artifact for a specific output mode. + */ + List<Facet> getFacets(String outputmode); + + + /** + * Returns data key/value map. + * @return key/value data map + */ + Map<String, String> getData(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/CollectionItemAttribute.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,106 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.List; +import java.util.ArrayList; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class CollectionItemAttribute implements Serializable { + + /** The list of styles. */ + protected List<Style> styles; + + /** The artifact. */ + protected String artifact; + + + /** + * Creates a new CollectionItem Attribute. + */ + public CollectionItemAttribute() { + styles = new ArrayList<Style>(); + } + + + /** + * Append a new Style. + * @param style The style. + */ + public void appendStyle (Style style) { + this.styles.add(style); + } + + + /** + * Remove a style from the attributes. + * @param name The style name. + */ + public void removeStyle (String name) { + for (int i = 0; i < styles.size(); i++) { + if (styles.get(i).getName().equals(name)) { + styles.remove(i); + } + } + } + + + /** + * Get a style from the collection item. + * @param facet The facet this style belongs to. + * @param index The style index. + * + * @return The selected style or 'null'. + */ + public Style getStyle(String facet, int index) { + for (int i = 0; i < styles.size(); i++) { + Style tmp = styles.get(i); + if (tmp.getFacet().equals(facet) && + tmp.getIndex() == index) { + return tmp; + } + } + return null; + } + + + /** + * Get the style at a postion. + * @param i The position index. + * + * @return The selected style. + */ + public Style getStyle(int i) { + return styles.get(i); + } + + + /** + * Get the number of styles. + * @return The number of styles. + */ + public int getNumStyles() { + return styles.size(); + } + + + /** + * Set the current artifact. + * @param The artifact uuid. + */ + public void setArtifact(String artifact) { + this.artifact = artifact; + } + + + /** + * Get the associated artifact. + * @return The artifact. + */ + public String getArtifact () { + return this.artifact; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/CollectionRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,110 @@ +package de.intevation.flys.client.shared.model; + +import java.util.Date; + +import com.google.gwt.safehtml.shared.SafeHtml; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + + +/** + * The CollectionRecord is a wrapper to put Collection objects into a ListGrid. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CollectionRecord extends ListGridRecord { + + /** The artifact collection. */ + protected Collection collection; + + + /** + * The default constructor. + * + * @param collection The artifact collection. + */ + public CollectionRecord(Collection collection) { + this.collection = collection; + + setCreationTime(collection.getCreationTime()); + + String name = collection.getName(); + setName(name != null && name.length() > 0 + ? name + : collection.identifier()); + + setTTL(collection.getTTL()); + } + + + /** + * Sets the creation time. + * + * @param creationTime The creation time. + */ + public void setCreationTime(Date creationTime) { + setAttribute("creationTime", creationTime); + } + + + /** + * Returns the date of the creation. + * + * @return the creation time. + */ + public Date getCreationTime() { + return getAttributeAsDate("creationTime"); + } + + + /** + * Returns the name of the collection. + * + * @return the name of the collection. + */ + public void setName(String name) { + SafeHtmlBuilder b = new SafeHtmlBuilder(); + b.appendEscaped(name); + + SafeHtml html = b.toSafeHtml(); + + setAttribute("name", html.asString()); + } + + + /** + * Returns the name of the collection or the uuid if no name is specified. + * + * @return the name of the collection. + */ + public String getName() { + return getAttributeAsString("name"); + } + + + public void setTTL(long ttl) { + if (ttl == 0) { + setAttribute("ttl", "star_gold"); + } + else { + setAttribute("ttl", "star_silver"); + } + } + + + public String getTTL() { + return getAttribute("ttl"); + } + + + /** + * Returns the collection objects itself. + * + * @return the collection object. + */ + public Collection getCollection() { + return collection; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ContactInformation.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,90 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public class ContactInformation implements Serializable { + + protected String person; + protected String organization; + protected String address; + protected String city; + protected String postcode; + protected String phone; + protected String email; + + + public ContactInformation() { + } + + + public void setPerson(String person) { + this.person = person; + } + + + public String getPerson() { + return person; + } + + + public void setOrganization(String organization) { + this.organization = organization; + } + + + public String getOrganization() { + return organization; + } + + + public void setAddress(String address) { + this.address = address; + } + + + public String getAddress() { + return address; + } + + + public void setCity(String city) { + this.city = city; + } + + + public String getCity() { + return city; + } + + + public void setPostcode(String postcode) { + this.postcode = postcode; + } + + + public String getPostcode() { + return postcode; + } + + + public void setPhone(String phone) { + this.phone = phone; + } + + + public String getPhone() { + return phone; + } + + + public void setEmail(String email) { + this.email = email; + } + + + public String getEmail() { + return email; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Data.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,62 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * A Data object represents the necessary data of a single state of the + * artifact. It might provide several DataItems or just a single DataItem. The + * <code>type</code> makes it possible to validate the input in the client. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Data extends Serializable { + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel(); + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription(); + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType(); + + + /** + * Returns the DataItems provided by this Data object. + * + * @return the DataItems. + */ + public DataItem[] getItems(); + + + /** + * Returns the default value of this data object. + * + * @return the default value. + */ + public DataItem getDefault(); + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageNode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,59 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; +import java.util.ArrayList; + +import java.io.Serializable; + +public class DataCageNode implements Serializable +{ + protected String name; + protected String description; + protected List<DataCageNode> children; + protected AttrList attrs; + + public DataCageNode() { + } + + public DataCageNode(String name) { + this(name, null); + } + + public DataCageNode(String name, AttrList attrs) { + this(name, name, attrs); + } + + public DataCageNode(String name, String description, AttrList attrs) { + this.name = name; + this.description = description; + this.attrs = attrs; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public void setName(String name) { + this.name = name; + } + + public void addChild(DataCageNode child) { + if (children == null) { + children = new ArrayList<DataCageNode>(); + } + children.add(child); + } + + public List<DataCageNode> getChildren() { + return children; + } + + public AttrList getAttributes() { + return attrs; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,24 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +public class DataCageTree implements Serializable +{ + protected DataCageNode root; + + public DataCageTree() { + } + + public DataCageTree(DataCageNode root) { + this.root = root; + } + + public void setRoot(DataCageNode root) { + this.root = root; + } + + public DataCageNode getRoot() { + return root; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DataItem.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,37 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * A DataItem represents a concrete item that might be selected, chosen or + * inserted by the user. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface DataItem extends Serializable { + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel(); + + + /** + * Returns the description of the item. + * + * @return the description; + */ + public String getDescription(); + + + /** + * Returns the value of the item. + * + * @return the value. + */ + public String getStringValue(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DataList.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,213 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DataList implements Serializable, Cloneable { + + /** The list of Data objects managed by this list. */ + protected List<Data> data; + + /** The name of the state that this list belongs to. */ + protected String state; + + /** The name of a UIProvider that is recommended to render this DataList. */ + protected String uiprovider; + + /** The label that should be used to label data objects. */ + protected String label; + + /** The help text (URL) that should be displayed for this data object. */ + protected String helpText; + + + /** + * The default constructor that creates a new DataList without Data objects + * and no UIProvider. + */ + public DataList() { + data = new ArrayList<Data>(); + } + + + /** + * Constructor. + * + * @param state The name of the state that this list belongs to. + * @param size The initial size of the list. + */ + public DataList(String state, int size) { + this.state = state; + this.data = new ArrayList<Data>(size); + } + + + /** + * A constructor that creates a new DataList without Data objects and no + * UIProvider. Size defines the initial size of the list. + * + * @param state The name of the state that this list belongs to. + * @param size The initial size of the list. + * @param uiprovider The UIProvider that should be used to render this list. + */ + public DataList(String state, int size, String uiprovider) { + this(state, size); + this.uiprovider = uiprovider; + } + + + /** + * A constructor that creates a new DataList without Data objects and no + * UIProvider. Size defines the initial size of the list. + * + * @param state The name of the state that this list belongs to. + * @param size The initial size of the list. + * @param uiprovider The UIProvider that should be used to render this list. + * @param label The label. + */ + public DataList(String state, int size, String uiprovider, String label) { + this(state, size, uiprovider); + this.label = label; + } + + + /** + * A constructor that creates a new DataList without Data objects and no + * UIProvider. Size defines the initial size of the list. + * + * @param state The name of the state that this list belongs to. + * @param size The initial size of the list. + * @param uiprovider The UIProvider that should be used to render this list. + * @param label The label. + * @param helpText The help text (should be an URL). + */ + public DataList( + String state, + int size, + String uiprovider, + String label, + String helpText + ) { + this(state, size, uiprovider, label); + this.helpText = helpText; + } + + + /** + * Adds a new Data object to the list. + * + * @param obj The Data object. + */ + public void add(Data obj) { + if (obj != null) { + data.add(obj); + } + } + + + /** + * Adds a new Data objects to the list. + * + * @param obj The Data object. + */ + public void add(Data[] obj) { + if (obj != null) { + for (Data o: obj) { + data.add(o); + } + } + } + + + /** + * Returns the Data element at position <i>idx</i>. + * + * @param idx The position of an element that should be returned. + * + * @return the Data element at position <i>idx</i>. + */ + public Data get(int idx) { + if (idx < size()) { + return data.get(idx); + } + + return null; + } + + + /** + * Returns the whole list of Data objects. + * + * @return the whole list of Data objects. + */ + public List<Data> getAll() { + return data; + } + + /** + * Returns the number of Data objects in the list. + * + * @param the number of Data objects in the list. + */ + public int size() { + return data.size(); + } + + + /** + * Returns the name of the state that this list belongs to. + * + * @return the name of the state that this list belongs to. + */ + public String getState() { + return state; + } + + + /** + * Returns the label for this list. + * + * @return the label of this list. + */ + public String getLabel() { + return label; + } + + + /** + * Retrieves the name of a UIProvider or null if no one is recommended. + * + * @return the name of a UIProvider or null if no one is recommended. + */ + public String getUIProvider() { + return uiprovider; + } + + + /** + * Returns the help text which should be an URL. + * + * @return the help text. + */ + public String getHelpText() { + return helpText; + } + + + public Object clone() { + DataList clone = new DataList( + this.state, + this.data.size(), + this.uiprovider, + this.label, + this.helpText); + clone.data = (List<Data>) ((ArrayList<Data>)data).clone(); + + return clone; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DateAxis.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,64 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DateAxis implements Axis { + + public static final String TYPE = "date"; + + + protected int pos; + + protected long from; + protected long to; + + protected long min; + protected long max; + + + public DateAxis() { + } + + + public DateAxis(int pos, long from, long to, long min, long max) { + this.pos = pos; + this.from = from; + this.to = to; + this.min = min; + this.max = max; + } + + + @Override + public int getPos() { + return pos; + } + + + @Override + public Number getFrom() { + return from; + } + + + @Override + public Number getTo() { + return to; + } + + + @Override + public Number getMin() { + return min; + } + + + @Override + public Number getMax() { + return max; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,94 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + + +/** + * The default implementation of an artifact that might be used in the client. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultArtifact implements Artifact { + + /** The artifact's uuid. */ + protected String uuid; + + /** The artifacts hash value. */ + protected String hash; + + /** Determines if the artifact is in background mode.*/ + protected boolean inBackground; + + protected List<CalculationMessage> messages; + + /** The current artifact description. */ + protected ArtifactDescription artifactDescription; + + /** + * This constructor should not be used to create new instances of this + * class. An empty artifact without uuid and hash will be the result of + * this constructor call. + */ + public DefaultArtifact() { + } + + + public DefaultArtifact(String uuid, String hash) { + this(uuid, hash, false, null); + } + + + /** + * This constructor creates a new artifact instance with a uuid and a hash. + * + * @param uuid The artifact's uuid. + * @param hash The artifact's hash. + */ + public DefaultArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + this.uuid = uuid; + this.hash = hash; + this.inBackground = inBackground; + this.messages = messages; + } + + + public String getUuid() { + return uuid; + } + + + public String getHash() { + return hash; + } + + + public String getName() { + return "default"; + } + + + public boolean isInBackground() { + return inBackground; + } + + + public List<CalculationMessage> getBackgroundMessages() { + return messages; + } + + + public ArtifactDescription getArtifactDescription() { + return artifactDescription; + } + + + public void setArtifactDescription(ArtifactDescription description) { + this.artifactDescription = description; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultArtifactDescription.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,183 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +import de.intevation.flys.client.shared.DoubleUtils; + + +/** + * The default implementation of an {@link ArtifactDescription}. This class just + * implements constructors to create new instances and the necessary methods of + * the interface. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultArtifactDescription implements ArtifactDescription { + + /** Data that have been inserted in former states.*/ + protected DataList[] oldData; + + /** The Data that is allowed to be inserted in the current state.*/ + protected DataList currentData; + + /** The current state name.*/ + protected String currentState; + + /** The names of reachable states.*/ + protected String[] reachableStates; + + /** The output modes of this state.*/ + protected OutputMode[] outputModes; + + /** A list of recommendations suggested by the server.*/ + protected Recommendation[] recommendations; + + + public DefaultArtifactDescription() { + } + + + /** + * The default constructor. + * + * @param old The data that have been inserted in former states. + * @param current The data that might be inserted in the current state. + * @param state The name of the current state. + * @param reachableStates The names of the reachable states. + */ + public DefaultArtifactDescription( + DataList[] old, + DataList current, + String state, + String[] reachableStates) + { + this.oldData = old; + this.currentData = current; + this.currentState = state; + this.reachableStates = reachableStates; + } + + + /** + * The default constructor. + * + * @param old The data that have been inserted in former states. + * @param current The data that might be inserted in the current state. + * @param state The name of the current state. + * @param reachableStates The names of the reachable states. + * @param outputModes The available output modes of this artifact. + */ + public DefaultArtifactDescription( + DataList[] old, + DataList current, + String state, + String[] reachableStates, + OutputMode[] outputModes, + Recommendation[] recommendations) + { + this(old, current, state, reachableStates); + this.outputModes = outputModes; + this.recommendations = recommendations; + } + + + public DataList[] getOldData() { + return oldData; + } + + + public DataList getCurrentData() { + return currentData; + } + + + public String getCurrentState() { + return currentState; + } + + + public String[] getReachableStates() { + return reachableStates; + } + + + public OutputMode[] getOutputModes() { + return outputModes; + } + + + public Recommendation[] getRecommendations() { + return recommendations; + } + + + public String getRiver() { + return getDataValueAsString("river"); + } + + + /** Get [min,max] of data items. */ + public double[] getKMRange() { + Double[] mm = new Double[2]; + + for (DataList list: oldData) { + List<Data> dataList = list.getAll(); + + for (Data data: dataList) { + String dataName = data.getLabel(); + DataItem item = data.getItems()[0]; + + if (dataName.equals("ld_from") || dataName.equals("from")) { + Double d = DoubleUtils.getDouble(item.getStringValue()); + + if (d != null) { + mm[0] = d; + } + } + else if (dataName.equals("ld_to") || dataName.equals("to")) { + Double d = DoubleUtils.getDouble(item.getStringValue()); + + if (d != null) { + mm[1] = d; + } + } + else if (dataName.equals("ld_locations")) { + return DoubleUtils.getMinMax(item.getStringValue()); + } + } + + if (mm[0] != null && mm[1] != null) { + return new double[] { mm[0], mm[1] }; + } + } + + return null; + } + + + public String getReferenceGauge() { + return getDataValueAsString("reference_gauge"); + } + + + public String getDataValueAsString(String name) { + if (oldData == null) { + return null; + } + for (DataList list: oldData) { + List<Data> dataList = list.getAll(); + + for (Data d: dataList) { + String dataName = d.getLabel(); + DataItem item = d.getItems()[0]; + + if (dataName.equals(name)) { + return item.getStringValue(); + } + } + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultCollection.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,312 @@ +package de.intevation.flys.client.shared.model; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * The default implementation of a {@link Collection}. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultCollection implements Collection { + + /** The uuid of the collection. */ + protected String uuid; + + /** The name of the collection. */ + protected String name; + + /** The creation time of this collection. */ + protected Date creation; + + /** + * The time to live of the collection. + * If this value is 0, it will never die. + */ + protected long ttl; + + /** The list of artifacts that are managed by this Collection.*/ + protected List<CollectionItem> items; + + protected List<Recommendation> recommendations; + + /** + * ThemeList by outputmode name. + */ + protected Map<String, ThemeList> themeLists; + + /** + * Settings by outputmode name. + */ + protected Map<String, Settings> settings; + + /** + * Constructor without arguments is necessary for GWT. + */ + public DefaultCollection() { + } + + + public DefaultCollection(String uuid, long ttl, String name) { + this.uuid = uuid; + this.ttl = ttl; + this.name = name; + this.items = new ArrayList<CollectionItem>(); + this.themeLists = new HashMap<String, ThemeList>(); + this.recommendations = new ArrayList<Recommendation>(); + this.settings = new HashMap<String, Settings>(); + } + + + /** + * Creates a new DefaultCollection with a UUID. + * + * @param uuid The UUID. + */ + public DefaultCollection( + String uuid, + long ttl, + String name, + List<Recommendation> recs + ) { + this(uuid, ttl, name); + + this.recommendations = recs; + } + + + public DefaultCollection( + String uuid, + long ttl, + String name, + List<Recommendation> recommendations, + Map<String, ThemeList> themeLists) + { + this(uuid, ttl, name, recommendations); + this.themeLists = themeLists; + } + + + public DefaultCollection( + String uuid, + long ttl, + String name, + List<Recommendation> recommendations, + Map<String, ThemeList> themeLists, + Map<String, Settings> settings) + { + this(uuid, ttl, name, recommendations); + this.themeLists = themeLists; + this.settings = settings; + } + + + /** + * Creates a new DefaultCollection with uuid and name. + * + * @param uuid The identifier of this collection. + * @param name The name of this collection. + * @param creation The creation time. + */ + public DefaultCollection(String uuid, long ttl, String name, Date creation){ + this(uuid, ttl, name); + + this.creation = creation; + } + + + public String identifier() { + return uuid; + } + + + public Date getCreationTime() { + return creation; + } + + + /** + * Returns now. + * TODO candidate for removal? + */ + public Date getLastAccess() { + return new Date(); + } + + + public long getTTL() { + return ttl; + } + + + public void setTTL(long ttl) { + this.ttl = ttl; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public void addItem(CollectionItem item) { + if (item != null) { + items.add(item); + } + } + + + public int getItemLength() { + return items.size(); + } + + + /** Returns item at index (0-based), or null if out of range. */ + public CollectionItem getItem(int idx) { + if (idx >= getItemLength()) { + return null; + } + + return items.get(idx); + } + + + /** + * Get item whose identifier is the given string. + * @param uuid identifier of collection item (artifacts uuid). + * @return CollectionItem whose identifier is given String, null if not found. + */ + public CollectionItem getItem(String uuid) { + int size = getItemLength(); + for (int i = 0; i < size; i++) { + CollectionItem item = getItem(i); + if (item.identifier().equals(uuid)) { + return item; + } + } + return null; + } + + + public Map<String, OutputMode> getOutputModes() { + Map<String, OutputMode> modes = new HashMap<String, OutputMode>(); + + for (CollectionItem item: items) { + List<OutputMode> itemModes = item.getOutputModes(); + + if (itemModes != null) { + for (OutputMode itemMode: itemModes) { + String name = itemMode.getName(); + if (!modes.containsKey(name)) { + // we dont want duplicated OutputModes in our result. + modes.put(name, itemMode); + } + } + } + } + + return modes; + } + + + /** + * Returns ThemeList for given output name. + */ + public ThemeList getThemeList(String outName) { + if (themeLists != null) { + return themeLists.get(outName); + } + + return null; + } + + + /** + * Returns Settings for given output name. + */ + public Settings getSettings(String outName) { + if (settings != null) { + return settings.get(outName); + } + + return null; + } + + + public void setSettings(Map<String, Settings> settings) { + this.settings = settings; + } + + + public void addSettings(String outname, Settings settings) { + if (this.settings == null) { + this.settings = new HashMap<String, Settings>(); + } + this.settings.put(outname, settings); + } + + + /** Set the outputname to themelist map. */ + public void setThemeLists(Map<String, ThemeList> map) { + this.themeLists = map; + } + + + public List<Recommendation> getRecommendations() { + return recommendations; + } + + + public void addRecommendation(Recommendation recommendation) { + recommendations.add(recommendation); + } + + + public void addRecommendations(List<Recommendation> recommendations) { + this.recommendations.addAll(recommendations); + } + + + public boolean loadedRecommendation(Recommendation recommendation) { + String factory = recommendation.getFactory(); + String dbids = recommendation.getIDs(); + + for (Recommendation in: recommendations) { + String inFactory = in.getFactory(); + String inDbids = in.getIDs(); + + if (factory.equals(inFactory) && dbids.equals(inDbids)) { + return true; + } + } + + return false; + } + + + @Override + public boolean hasItems() { + return items.isEmpty(); + } + + /** + * Returns the name of the collection or uuid if no name is set + */ + @Override + public String getDisplayName() { + if (this.name != null) { + return this.name; + } + return this.uuid; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultCollectionItem.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,90 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; +import java.util.Map; + + +/** + * The default implementation of a CollectionItem (artifact). + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultCollectionItem implements CollectionItem { + + /** The identifier that specifies the artifact related to this item. */ + protected String identifier; + + /** The hash that specifies the artifact related to this item. */ + protected String hash; + + /** The list of output modes supported by the artifact of this item. */ + protected List<OutputMode> outputModes; + + /** The map of datanames to data values. */ + protected Map<String, String> data; + + + /** + * An empty constructor. + */ + public DefaultCollectionItem() { + } + + + /** + * The default constructor to create a new CollectionItem related to an + * artifact with output modes. + * + * @param identifier The identifier of an artifact. + * @param outputModes The output modes supported by this item. + */ + public DefaultCollectionItem( + String identifier, + String hash, + List<OutputMode> modes, + Map<String,String> data + ) { + this.identifier = identifier; + this.hash = hash; + this.outputModes = modes; + this.data = data; + } + + + + public String identifier() { + return identifier; + } + + + public String hash() { + return hash; + } + + + public List<OutputMode> getOutputModes() { + return outputModes; + } + + + public List<Facet> getFacets(String outputmode) { + for (OutputMode mode: outputModes) { + if (outputmode.equals(mode.getName())) { + // TODO Return facets, but facets are not implemented for + // OutputModes yet! + } + } + + return null; + } + + + /** + * Returns artifact data. + * @return key/value data map + */ + public Map<String, String> getData() { + return this.data; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,135 @@ +package de.intevation.flys.client.shared.model; + +/** + * The default implementation of a {@link Data} item. This class just implements + * constructors to create instances and the necessary methods of the interface. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultData implements Data { + + /** The label of this Data object. */ + protected String label; + + /** The description. */ + protected String description; + + /** The type. */ + protected String type; + + /** The DataItems. */ + protected DataItem[] items; + + /** The default DataItem. */ + protected DataItem defaultItem; + + + public DefaultData() { + } + + + /** + * The default constructor to create new DefaultData objects. + * + * @param label The label. + * @param description The description. + * @param type The type. + * @param items The DataItems. + */ + public DefaultData( + String label, + String description, + String type, + DataItem[] items) + { + this(label, description, type, items, null); + } + + + /** + * The constructor to create new DefaultData objects with a default value. + * + * @param label The label. + * @param description The description. + * @param type The type. + * @param items The DataItems. + * @param defaultItem The default DataItem. + */ + public DefaultData( + String label, + String description, + String type, + DataItem[] items, + DataItem defaultItem) + { + this.label = label; + this.description = description; + this.type = type; + this.items = items; + this.defaultItem = defaultItem; + } + + + public String getLabel() { + return label; + } + + + public String getDescription() { + return description; + } + + + public String getType() { + return type; + } + + + public DataItem[] getItems() { + return items; + } + + + public DataItem getDefault() { + return defaultItem; + } + + + /** Conveniently create simplistic data. */ + public static DefaultData createSimpleStringData( + String name, + String value + ) { + DefaultDataItem d = new DefaultDataItem(name, name, value); + return new DefaultData(name, null, null, new DataItem[] {d}); + } + + /** Conveniently create simplistic data array. */ + public static Data[] createSimpleStringDataArray( + String name, + String value + ) { + DefaultDataItem d = new DefaultDataItem(name, name, value); + return new Data[] + { new DefaultData(name, null, null, new DataItem[] {d})}; + } + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = ""; + boolean first = true; + for (int i = 0; i < items.length; i++) { + if (!first) { + data += ";"; + } + data += items[i].getStringValue(); + first = false; + } + return data; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultDataItem.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,54 @@ +package de.intevation.flys.client.shared.model; + + +/** + * The default implementation of a {@link DataItem}. This class just implements + * constructors to create instances and the necessary methods of the interface. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultDataItem implements DataItem { + + /** The label. */ + protected String label; + + /** The description. */ + protected String description; + + /** The value. */ + protected String value; + + + public DefaultDataItem() { + } + + + /** + * The default constructor to create new instances. + * + * @param label The label. + * @param description The description. + * @param value The value. + */ + public DefaultDataItem(String label, String description, String value) { + this.label = label; + this.description = description; + this.value = value; + } + + + public String getLabel() { + return label; + } + + + public String getDescription() { + return description; + } + + + public String getStringValue() { + return value; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultFacet.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,60 @@ +package de.intevation.flys.client.shared.model; + + +/** + * The default implementation of a Facet. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultFacet implements Facet { + + /** The name of the facet.*/ + protected String name; + + /** The description of the facet.*/ + protected String description; + + /** The index of the facet.*/ + protected int index; + + + /** + * An empty constructor. + */ + public DefaultFacet() { + } + + + /** + * The default constructor to create new DefaultFacets. + * + * @param name The name of the facet. + */ + public DefaultFacet(String name) { + this.name = name; + } + + + public DefaultFacet(String name, int index, String description) { + this(name); + + this.index = index; + this.description = description; + } + + + public String getName() { + return name; + } + + + public String getDescription() { + return description; + } + + + public int getIndex() { + return index; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultGaugeInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,151 @@ +package de.intevation.flys.client.shared.model; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class DefaultGaugeInfo implements GaugeInfo { + + private String name; + private Double start; + private Double end; + private Double aeo; + private Double datum; + private Double minq; + private Double maxq; + private Double minw; + private Double maxw; + private boolean kmup; + private Double station; + private String wstunit; + private Long officialnumber; + private String rivername; + + public DefaultGaugeInfo() { + } + + public DefaultGaugeInfo( + String rivername, + String name, + boolean kmup, + Double station, + Double start, + Double end, + Double datum, + Double aeo, + Double minq, + Double maxq, + Double minw, + Double maxw, + String wstunit, + Long official) + { + this.rivername = rivername; + this.name = name; + this.kmup = kmup; + this.station = station; + this.start = start; + this.end = end; + this.datum = datum; + this.aeo = aeo; + this.minq = minq; + this.maxq = maxq; + this.minw = minw; + this.maxw = maxw; + this.wstunit = wstunit; + this.officialnumber = official; + } + /** + * Returns the name of the gauge + */ + public String getName() { + return this.name; + } + + /** + * Returns the start KM of the gauge or null if not available + */ + public Double getKmStart() { + return this.start; + } + + /** + * Returns the end KM of the gauge or null if not available + */ + public Double getKmEnd() { + return this.end; + } + + /** + * Returns the mimimum Q value at this gauge or null if not available + */ + public Double getMinQ() { + return this.minq; + } + + /** + * Returns the maximum Q value at this gauge or null if not available + */ + public Double getMaxQ() { + return this.maxq; + } + + /** + * Returns the mimimum W value at this gauge or null if not available + */ + public Double getMinW() { + return this.minw; + } + + /** + * Returns the maximim W value at this gauge or null if not available + */ + public Double getMaxW() { + return this.maxw; + } + + /** + * Returns the datum value or null if not available + */ + public Double getDatum() { + return this.datum; + } + + /** + * Returns the aeo value or null if not available + */ + public Double getAeo() { + return this.aeo; + } + + public boolean isKmUp() { + return this.kmup; + } + + /** + * Returns the station km of the gauge or null if not available + */ + public Double getStation() { + return this.station; + } + + /** + * Returns the wst unit as a String + */ + public String getWstUnit() { + return this.wstunit; + } + + /** + * Returns the official number of this gauge + */ + public Long getOfficialNumber() { + return this.officialnumber; + } + + /** + * Returns the river to which this gauge belongs + */ + public String getRiverName() { + return this.rivername; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultMeasurementStation.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,159 @@ +package de.intevation.flys.client.shared.model; + +import java.util.Date; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class DefaultMeasurementStation implements MeasurementStation { + + private String name; + private Double start; + private Double end; + private Double station; + private String rivername; + private String measurementtype; + private String riverside; + private Integer id; + private boolean kmup; + private String moperator; + private Date starttime; + private Date stoptime; + private String gaugename; + + public DefaultMeasurementStation() { + } + + public DefaultMeasurementStation( + String rivername, + String name, + Integer id, + Double station, + Double start, + Double end, + boolean kmup, + String riverside, + String measurementtype, + String moperator, + Date starttime, + Date stoptime, + String gaugename) + { + this.rivername = rivername; + this.name = name; + this.station = station; + this.start = start; + this.end = end; + this.riverside = riverside; + this.measurementtype = measurementtype; + this.id = id; + this.kmup = kmup; + this.moperator = moperator; + this.starttime = starttime; + this.stoptime = stoptime; + this.gaugename = gaugename; + } + + /** + * Returns the name of the measurement station + */ + @Override + public String getName() { + return this.name; + } + + /** + * Returns the start KM of the measurement station or null if not available + */ + @Override + public Double getKmStart() { + return this.start; + } + + /** + * Returns the end KM of the measurement station or null if not available + */ + @Override + public Double getKmEnd() { + return this.end; + } + + /** + * Returns the river to which this measurement station belongs + */ + @Override + public String getRiverName() { + return this.rivername; + } + + /** + * Returns the type of the measurement station + */ + @Override + public String getMeasurementType() { + return this.measurementtype; + } + + /** + * Returns the station km of this measurement station + */ + @Override + public Double getStation() { + return this.station; + } + + + /** + * Returns the side of the river where this measurement station belongs + */ + @Override + public String getRiverSide() { + return this.riverside; + } + + /** + * Returns the ID of the measurement station + */ + @Override + public Integer getID() { + return this.id; + } + + @Override + public boolean isKmUp() { + return this.kmup; + } + + /** + * Returns the operator of the measurement station + */ + @Override + public String getOperator() { + return this.moperator; + } + + /** + * Returns the start time of the observation at this measurement station + */ + @Override + public Date getStartTime() { + return this.starttime; + } + + /** + * Returns the end time of the observation at this measurement station + */ + @Override + public Date getStopTime() { + return this.stoptime; + } + + /** + * Returns the name of the gauge in reference to this measurement station + */ + @Override + public String getGaugeName() { + return this.gaugename; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultModule.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,39 @@ +package de.intevation.flys.client.shared.model; + +public class DefaultModule implements Module { + + private String name; + private String localname; + private boolean selected = false; + + public DefaultModule() { + } + + public DefaultModule(String name, String localname, boolean selected) { + this.name = name; + this.localname = localname; + this.selected = selected; + } + + /** + * Returns the name of the module + */ + public String getName() { + return this.name; + } + + /** + * Returns the localized name of the module + */ + public String getLocalizedName() { + return this.localname; + } + + /** + * Returns true if the module should be selected + */ + public boolean isSelected() { + return this.selected; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultOutputMode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,153 @@ +package de.intevation.flys.client.shared.model; + +import java.util.ArrayList; +import java.util.List; + +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; + + +/** + * The default implementation of an Output. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultOutputMode implements OutputMode { + + /** The name of this mode.*/ + protected String name; + + /** The description of this mode.*/ + protected String description; + + /** The mime-type of this mode.*/ + protected String mimeType; + + /** The type that this output mode represents.*/ + protected String type; + + /** The list of available facets of this export mode.*/ + protected List<Facet> facets; + + + /** A convinience constructor.*/ + public DefaultOutputMode() { + facets = new ArrayList<Facet>(); + } + + + /** + * The default constructor. + * + * @param name The name of this mode. + * @param description The description of this mode. + * @param mimeType The mime-type of this mode. + */ + public DefaultOutputMode(String name, String description, String mimeType) { + this.name = name; + this.description = description; + this.mimeType = mimeType; + } + + + public DefaultOutputMode( + String name, + String description, + String mimeType, + String type) + { + this(name, description, mimeType); + + this.type = type; + } + + + public DefaultOutputMode( + String name, + String description, + String mimeType, + List<Facet> facets) + { + this(name, description, mimeType); + this.type = ""; + this.facets = facets; + } + + + public String getName() { + return name; + } + + + public String getDescription() { + return description; + } + + + public String getMimeType() { + return mimeType; + } + + + public String getType() { + return type; + } + + + /** + * Adds a new facet to this export. + * + * @param facet The new facet. + */ + public void addFacet(Facet facet) { + facets.add(facet); + } + + + /** + * Returns the number of facets supported by this export. + * + * @return the number of facets. + */ + public int getFacetCount() { + return facets.size(); + } + + + /** + * Returns the facet at a given position. + * + * @param idx The position of a facet. + * + * @return a facet. + */ + public Facet getFacet(int idx) { + if (idx < getFacetCount()) { + return facets.get(idx); + } + + return null; + } + + + public Facet getFacet(String name) { + for (Facet facet: facets) { + if (name.equals(facet.getName())) { + return facet; + } + } + + return null; + } + + + public List<Facet> getFacets() { + return facets; + } + + + public OutputTab createOutputTab(String t, Collection c, CollectionView p) { + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultRiver.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,50 @@ +package de.intevation.flys.client.shared.model; + + +/** + * The simpliest default implementation of a River that just stores a name. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultRiver implements River { + + /** The name of the river.*/ + protected String name; + + /** + * The default constructor that creates empty river objects. + */ + public DefaultRiver() { + } + + + /** + * This constructor should be used to create new rivers. + * + * @param name The name of the river. + */ + public DefaultRiver(String name) { + this.name = name; + } + + + /** + * Sets the name of the river. + * + * @param name The name of the river. + */ + public void setName(String name) { + this.name = name; + } + + + /** + * Returns the name of the river. + * + * @return the name of the river. + */ + public String getName() { + return name; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultRiverInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,122 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ + +public class DefaultRiverInfo implements RiverInfo { + + private String name; + private boolean kmup; + private Double start; + private Double end; + private String wstunit; + private Double minq; + private Double maxq; + private Long officialnumber; + + private List<GaugeInfo> gaugeinfo; + private List<MeasurementStation> mstations; + + public DefaultRiverInfo() { + } + + public DefaultRiverInfo( + String name, + boolean kmup, + Double start, + Double end, + String wstunit, + Double minq, + Double maxq, + Long official) + { + this.name = name; + this.kmup = kmup; + this.start = start; + this.end = end; + this.wstunit = wstunit; + this.minq = minq; + this.maxq = maxq; + this.officialnumber = official; + } + + public boolean isKmUp() { + return this.kmup; + } + + /** + * Start KM of the river + */ + public Double getKmStart() { + return this.start; + } + + /** + * End KM of the river + */ + public Double getKmEnd() { + return this.end; + } + + /** + * Returns the name of the river + */ + public String getName() { + return this.name; + } + + /** + * Returns the name of the WST unit + */ + public String getWstUnit() { + return this.wstunit; + } + + /** + * Return all gauge info of the river or null if they aren't available. + */ + public List<GaugeInfo> getGauges() { + return this.gaugeinfo; + } + + /** + * Returns the min q value of the river + */ + public Double getMinQ() { + return this.minq; + } + + /** + * Returns the max q value of the river + */ + public Double getMaxQ() { + return maxq; + } + + /** + * Returns the official number of the river + */ + public Long getOfficialNumber() { + return this.officialnumber; + } + + /** + * Returns the MeasurementStations on this river or null if they aren't + * available. + */ + @Override + public List<MeasurementStation> getMeasurementStations() { + return this.mstations; + } + + public void setGauges(List<GaugeInfo> gauges) { + this.gaugeinfo = gauges; + } + + public void setMeasurementStations(List<MeasurementStation> mstations) { + this.mstations = mstations; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultTheme.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,155 @@ +package de.intevation.flys.client.shared.model; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultTheme implements Theme { + + protected int position; + + protected int index; + + protected int active; + + protected int visible; + + protected String artifact; + + protected String facet; + + protected String description; + + /** CollectionItem associated with this facet/themes artifact. */ + protected CollectionItem collectionItem; + + + public DefaultTheme() { + } + + + public DefaultTheme( + int pos, + int index, + int active, + int visible, + String art, + String facet, + String description) + { + this.position = pos; + this.index = index; + this.active = active; + this.visible = visible; + this.artifact = art; + this.facet = facet; + this.description = description; + this.collectionItem = null; + } + + + public int getPosition() { + return position; + } + + + public void setPosition(int pos) { + this.position = pos; + } + + + public int getIndex() { + return index; + } + + + public int getActive() { + return active; + } + + + public void setActive(int active) { + this.active = active; + } + + + public String getArtifact() { + return artifact; + } + + + public String getFacet() { + return facet; + } + + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public int getVisible() { + return visible; + } + + + public void setVisible(int visible) { + this.visible = visible; + } + + + public boolean equals(Object o) { + if (!(o instanceof DefaultTheme)) { + return false; + } + + DefaultTheme other = (DefaultTheme) o; + + if (other.position != position) { + return false; + } + + if (!other.artifact.equals(artifact)) { + return false; + } + + if (other.active != active) { + return false; + } + + if (!other.facet.equals(facet)) { + return false; + } + + if (!other.description.equals(description)) { + return false; + } + + if (other.index != index) { + return false; + } + + if (other.visible != visible) { + return false; + } + + return true; + } + + /** Get the CollectionItem representing the facets artifact. */ + @Override + public CollectionItem getCollectionItem() { + return collectionItem; + } + + /** Set the CollectionItem representing the facets artifact. */ + @Override + public void setCollectionItem(CollectionItem ci) { + this.collectionItem = ci; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultUser.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.flys.client.shared.model; + + +/** + * Trivial implementation of a user. Useful to be subclassed. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultUser +implements User +{ + /** The identifier of the user.*/ + protected String identifier; + + /** The name of the user.*/ + protected String name; + + + /** + * The default constructor. + */ + public DefaultUser() { + } + + + /** + * A constructor that creates a new user. + * + * @param identifier The uuid of the user. + * @param name The name of the user. + */ + public DefaultUser(String identifier, String name) { + this.identifier = identifier; + this.name = name; + } + + + /** + * Returns the identifier of this user. + * + * @return the identifier of this user. + */ + public String identifier() { + return identifier; + } + + + /** + * Returns the name of the user. + * + * @return the name of the user. + */ + public String getName() { + return name; + } + + + /** + * Set the identifier of the user. + * + * @param identifier The new identifier. + */ + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + + /** + * Set the name of the user. + * + * @param name The name for this user. + */ + public void setName(String name) { + this.name = name; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DischargeInfoObject.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface DischargeInfoObject extends Serializable { + + String getDescription(); + + Integer getStartYear(); + + Integer getEndYear(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DischargeInfoObjectImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,44 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DischargeInfoObjectImpl implements DischargeInfoObject { + + protected String description; + + protected Integer startYear; + + protected Integer endYear; + + + public DischargeInfoObjectImpl() { + } + + + public DischargeInfoObjectImpl( + String description, + Integer startYear, + Integer endYear + ) { + this.description = description; + this.startYear = startYear; + this.endYear = endYear; + } + + public String getDescription() { + return description; + } + + + public Integer getStartYear() { + return startYear; + } + + + public Integer getEndYear() { + return endYear; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DistanceInfoObject.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,23 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface DistanceInfoObject extends Serializable { + + String getDescription(); + + Double getFrom(); + + Double getTo(); + + String getRiverside(); + + Double getBottom(); + + Double getTop(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DistanceInfoObjectImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,69 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DistanceInfoObjectImpl implements DistanceInfoObject { + + protected String description; + + protected Double from; + + protected Double to; + + protected String riverside; + + protected Double bottom; + + protected Double top; + + + public DistanceInfoObjectImpl() { + } + + + public DistanceInfoObjectImpl( + String description, + Double from, + Double to, + String riverside, + Double bottom, + Double top + ) { + this.description = description; + this.from = from; + this.to = to; + this.riverside = riverside; + this.bottom = bottom; + this.top = top; + } + + public String getDescription() { + return description; + } + + + public Double getFrom() { + return from; + } + + + public Double getTo() { + return to; + } + + + public String getRiverside() { + return riverside; + } + + public Double getBottom() { + return bottom; + } + + public Double getTop() { + return top; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DistanceInfoRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,107 @@ +package de.intevation.flys.client.shared.model; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + + +/** + * The DistanceInfoRecord is a wrapper to put DistanceInfo objects into + * a ListGrid. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DistanceInfoRecord extends ListGridRecord { + + /** The artifact collection. */ + protected DistanceInfoObject distanceInfo; + + + /** + * The default constructor. + * + * @param info The distance info object. + */ + public DistanceInfoRecord(DistanceInfoObject info) { + this.distanceInfo = info; + + setDescription(info.getDescription()); + setFrom(info.getFrom()); + if (info.getTo() != null) + setTo(info.getTo()); + else + setTo(info.getFrom()); + setRiverside(info.getRiverside()); + setBottom(info.getBottom()); + setTop(info.getTop()); + } + + + /** + * Sets the creation time. + * + * @param creationTime The creation time. + */ + public void setDescription(String description) { + setAttribute("description", description); + } + + + /** + * Returns the description. + * + * @return the description. + */ + public String getDescription() { + return getAttributeAsString("description"); + } + + + public void setFrom(double from) { + setAttribute("from", from); + } + + + public double getFrom() { + return getAttributeAsDouble("from"); + } + + public void setTo(double to) { + setAttribute("to", to); + } + + + public double getTo() { + return getAttributeAsDouble("to"); + } + + + public void setRiverside(String side) { + setAttribute("riverside", side); + } + + + public String getRiverside() { + return getAttributeAsString("riverside"); + } + + public void setBottom(Double bottom) { + setAttribute("bottom", bottom != null ? bottom.toString() : "-"); + } + + public String getBottom() { + return getAttributeAsString("bottom"); + } + + public void setTop(Double top) { + setAttribute("top", top != null ? top.toString() : "-"); + } + + public String getTop() { + return getAttributeAsString("top"); + } + + + public DistanceInfoObject getDistanceInfo() { + return distanceInfo; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DoubleArrayData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,126 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DoubleArrayData implements Data { + + public static final String TYPE = "doublearray"; + + + protected String label; + protected String description; + + protected double[] values; + + + public DoubleArrayData() { + } + + + public DoubleArrayData(String label, String description, double[] values) { + this.label = label; + this.description = description; + this.values = values; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return TYPE; + } + + + /** + * Returns a DataItem which value is a string that consists of the double + * values separated by a ';'. + * + * @return the DataItem. + */ + public DataItem[] getItems() { + if (values == null || values.length == 0) { + return new DataItem[0]; + } + + StringBuilder sb = new StringBuilder(); + boolean first = true; + + for (double value: values) { + if (first) { + sb.append(String.valueOf(value)); + } + else { + sb.append(";" + String.valueOf(value)); + } + } + + String value = sb.toString(); + DataItem item = new DefaultDataItem(value, value, value); + + return new DataItem[] { item }; + } + + + /** + * Returns the values as array. + * + * @return the values as array. + */ + public double[] getValues() { + return values; + } + + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = ""; + boolean first = true; + for (int i = 0; i < values.length; i++) { + if (!first) { + data += ";"; + } + data += String.valueOf(values[i]); + first = false; + } + return data; + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DoubleProperty.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,86 @@ +package de.intevation.flys.client.shared.model; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +import java.util.HashMap; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DoubleProperty extends PropertySetting { + + /** + * Create a new DoubleProperty for settings. + */ + public DoubleProperty() { + this.attributes = new HashMap<String, String>(); + } + + + /** + * Create a new DoubleProperty. + * @param name The attribute name. + * @param value The current value. + */ + public DoubleProperty( + String name, + Double value) + { + this.name = name; + this.value = value.toString(); + this.attributes = new HashMap<String, String>(); + } + + @Override + public Double getValue() { + try { + Double value = Double.valueOf(this.value); + GWT.log("returning: " + value); + return value; + } + catch(NumberFormatException nfe) { + //Should never happen, if property is used correctly. + return null; + } + } + + + public void setValueFromUI(String value) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d; + try { + d = nf.parse(value); + GWT.log("setting " + value + " as " + d); + this.value = Double.toString(d); + } + catch(NumberFormatException nfe) {} + } + + public void setValue(Double value) { + this.value = value.toString(); + } + + + public String toUIString() { + double dv; + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + dv = Double.parseDouble(this.value); + } + catch (NumberFormatException nfe) { + return null; + } + return nf.format(dv); + } + + @Override + public Object clone() { + DoubleProperty clone = new DoubleProperty(this.getName(), + this.getValue()); + for(String s: this.getAttributeList()) { + clone.setAttribute(s, this.getAttribute(s)); + } + return clone; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/DoubleRangeData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,133 @@ +package de.intevation.flys.client.shared.model; + + +public class DoubleRangeData implements RangeData { + + public static final String TYPE = "doublerange"; + + + protected String label; + protected String description; + + protected double lower; + protected double upper; + + protected Double defLower; + protected Double defUpper; + + + public DoubleRangeData() { + } + + + public DoubleRangeData(String label, String desc, double lower, double upper) { + this(label, desc, lower, upper, null, null); + } + + + public DoubleRangeData( + String label, + String desc, + double lower, + double upper, + Double defLower, + Double defUpper + ) { + this.label = label; + this.description = desc; + this.lower = lower; + this.upper = upper; + this.defLower = defLower; + this.defUpper = defUpper; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return "doublerange"; + } + + + /** + * Returns a DataItem which value is a string that consists of the min and + * max value separated by a ';'. + * + * @return the DataItem. + */ + public DataItem[] getItems() { + String theMin = String.valueOf(lower); + String theMax = String.valueOf(upper); + + String label = theMin + " - " + theMax; + String value = theMin + ";" + theMax; + + DataItem item = new DefaultDataItem(label, label, value); + + return new DataItem[] { item }; + } + + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } + + + public Object getLower() { + return lower; + } + + + public Object getUpper() { + return upper; + } + + + public Object getDefaultLower() { + return defLower; + } + + + public Object getDefaultUpper() { + return defUpper; + } + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = lower + ";" + upper; + return data; + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ExportMode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,33 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + + +/** + * An derived OutputMode that marks an OutputMode as an export. An export mode + * should at least support one (or more) facet which specify the type of export + * (e.g. CSV, WST). + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ExportMode extends DefaultOutputMode { + + public ExportMode() { + } + + + public ExportMode(String name, String desc, String mimeType) { + super(name, desc, mimeType); + } + + + public ExportMode( + String name, + String descrition, + String mimeType, + List<Facet> facets) + { + super(name, descrition, mimeType, facets); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Facet.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,34 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * The interface that provides methods to retrieve information about a Facet. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Facet extends Serializable { + + /** + * Returns the name of a facet. + * + * @return the name of a facet. + */ + String getName(); + + /** + * Returns the index of this facet. + * + * @return the index. + */ + int getIndex(); + + /** + * Returns the description of this facet. + * + * @return the description. + */ + String getDescription(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/FacetFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,63 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +public class FacetFilter +implements Serializable +{ + protected String name; + protected String ids; + + public FacetFilter() { + } + + public FacetFilter(String name, String ids) { + this.name = name; + this.ids = ids; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getIds() { + return ids; + } + + public void setIds(String ids) { + this.ids = ids; + } + + protected static boolean equals(String a, String b) { + if (a == null && b == null) return true; + if (a == null && b != null) return false; + if (a != null && b == null) return false; + return a.equals(b); + } + + public boolean equals(Object other) { + if (!(other instanceof FacetFilter)) { + return false; + } + FacetFilter o = (FacetFilter)other; + return equals(o.name, name) && equals(o.ids, ids); + } + + public void collectIds(StringBuilder sb) { + if (ids != null) { + if (sb.length() > 0) { + sb.append(' '); + } + sb.append(ids); + } + } + + public Recommendation.Facet toFacet() { + return new Recommendation.Facet(name, ids); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/FacetRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,49 @@ +package de.intevation.flys.client.shared.model; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + +/** + * ListGridRecord for Facets. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FacetRecord extends ListGridRecord { + + /** Underlying theme. */ + protected Theme theme; + + + public FacetRecord(Theme theme) { + this.theme = theme; + + setActive(theme.getActive() == 1); + setName(theme.getDescription()); + } + + + public Theme getTheme() { + return theme; + } + + + public void setName(String description) { + // TODO Add a setter method setName() to Facet + // facet.setName(name); + setAttribute("name", description); + } + + + public String getName() { + return getAttribute("name"); + } + + + public boolean getActive() { + return getAttributeAsBoolean("active"); + } + + + public void setActive(boolean active) { + setAttribute("active", active); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/FeatureInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,50 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.HashMap; +import java.util.Map; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FeatureInfo implements Serializable { + + protected String layername; + + protected Map<String, String> attrs; + + + public FeatureInfo() { + } + + + public FeatureInfo(String layername) { + this.layername = layername; + this.attrs = new HashMap<String, String>(); + } + + + public void setLayername(String layername) { + this.layername = layername; + } + + + public String getLayername() { + return layername; + } + + + public void addAttr(String key, String value) { + if (key != null && key.length() > 0) { + attrs.put(key, value); + } + } + + + public Map<String, String> getAttrs() { + return attrs; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/FeatureInfoResponse.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,35 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a> + */ +public class FeatureInfoResponse implements Serializable { + + // Wrapper class to transport the response of a feature info call + + protected String featureInfoHTML; + + protected List<FeatureInfo> features; + + public FeatureInfoResponse() { + } + + public FeatureInfoResponse(List<FeatureInfo> features, String featureInfoHTML) { + this.featureInfoHTML = featureInfoHTML; + this.features = features; + } + + public List<FeatureInfo> getFeatures() { + return features; + } + + public String getFeatureInfoHTML() { + return featureInfoHTML; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/FixAnalysisArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,151 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +import com.google.gwt.core.client.GWT; + + +/** + * The Fixanalysis implementation of an Artifact (client side). + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixAnalysisArtifact extends DefaultArtifact { + + /** The name of this artifact: 'fixanalysis'.*/ + public static final String NAME = "fixanalysis"; + + protected FixFilter filter; + + + public FixAnalysisArtifact() { + this.filter = null; + } + + + public FixAnalysisArtifact(String uuid, String hash) { + super(uuid, hash); + this.filter = null; + } + + + public FixAnalysisArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } + + + public FixFilter getFilter () { + return createFilter(); + } + + + protected FixFilter createFilter() { + if (this.filter == null) { + this.filter = new FixFilter(); + } + DataList[] old = artifactDescription.getOldData(); + + String river = artifactDescription.getDataValueAsString("river"); + if (river != null) { + this.filter.setRiver(river); + } + + String from = artifactDescription.getDataValueAsString("ld_from"); + if (from != null) { + try { + double fkm = Double.parseDouble(from); + this.filter.setFromKm(fkm); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse from km."); + } + } + + String to = artifactDescription.getDataValueAsString("ld_to"); + if (to != null) { + try { + double tkm = Double.parseDouble(to); + this.filter.setToKm(tkm); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse to km"); + } + } + + String start = artifactDescription.getDataValueAsString("start"); + if (start != null) { + try { + long s = Long.parseLong(start); + this.filter.setFromDate(s); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse start date"); + } + } + + String end = artifactDescription.getDataValueAsString("end"); + if (end != null) { + try { + long e = Long.parseLong(end); + this.filter.setToDate(e); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse end date"); + } + } + + String q1 = artifactDescription.getDataValueAsString("q1"); + if (q1 != null) { + try { + int q1i = Integer.parseInt(q1); + this.filter.setFromClass(q1i); + } + catch(NumberFormatException nfe) { + GWT.log("Could not parse start class"); + } + } + + String q2 = artifactDescription.getDataValueAsString("q2"); + if (q2 != null) { + try { + int q2i = Integer.parseInt(q2); + this.filter.setToClass(q2i); + } + catch(NumberFormatException nfe) { + GWT.log("could not parse end class"); + } + } + + for (DataList list: old) { + List<Data> items = list.getAll(); + String state = list.getState(); + if(state.equals("state.fix.eventselect")) { + Data de = getData(items, "events"); + IntegerArrayData iad = (IntegerArrayData) de; + this.filter.setEvents(iad.getValues()); + } + } + + return this.filter; + } + + protected Data getData(List<Data> data, String name) { + for (Data d: data) { + if (name.equals(d.getLabel())) { + return d; + } + } + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/FixFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,106 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +/** Probably something like *Access, but from client side. */ +public class FixFilter implements Serializable{ + + protected String river; + protected double fromKm; + protected double toKm; + protected double currentKm; + protected int fromClass; + protected int toClass; + protected long fromDate; + protected long toDate; + protected boolean hasDate; + protected int[] events; + + public FixFilter() { + this.river = ""; + this.fromKm = -Double.MAX_VALUE; + this.toKm = -1; + this.currentKm = -1; + this.fromClass = -1; + this.toClass = -1; + this.fromDate = -1; + this.toDate = -1; + this.hasDate = false; + this.events = new int[0]; + } + + public void setRiver(String river) { + this.river = river; + } + + public void setFromKm(double from) { + this.fromKm = from; + } + + public void setToKm(double to) { + this.toKm = to; + } + + public void setCurrentKm(double km) { + this.currentKm = km; + } + + public void setFromClass(int from) { + this.fromClass = from; + } + + public void setToClass(int to) { + this.toClass = to; + } + + public void setFromDate(long from) { + this.hasDate = true; + this.fromDate = from; + } + + public void setToDate(long to) { + this.hasDate = true; + this.toDate = to; + } + + public void setEvents(int[] ev) { + this.events = ev; + } + + public String getRiver() { + return this.river; + } + + public double getFromKm() { + return this.fromKm; + } + + public double getToKm() { + return this.toKm; + } + + public double getCurrentKm() { + return this.currentKm; + } + + public int getFromClass() { + return this.fromClass; + } + + public int getToClass() { + return this.toClass; + } + + public long getFromDate() { + return this.fromDate; + } + + public long getToDate() { + return this.toDate; + } + + public int[] getEvents() { + return this.events; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,136 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.List; +import java.util.ArrayList; + +public class FixingsOverviewInfo implements Serializable { + + protected List<FixEvent> events; + protected String river; + protected double from; + protected double to; + protected int rid; + protected String html; + + protected FixingsOverviewInfo() {} + + public FixingsOverviewInfo( + int rid, + String river, + double from, + double to, + List<FixEvent> events, + String html + ) { + this.rid = rid; + this.river = river; + this.from = from; + this.to = to; + this.events = new ArrayList<FixEvent>(events); + this.html = html; + } + + public int getRId() { + return this.rid; + } + + public String getRiver() { + return this.river; + } + + public double getFrom() { + return this.from; + } + + public double getTo() { + return this.to; + } + + public List<FixEvent> getEvents() { + return this.events; + } + + public FixEvent getEventByCId(String cid) { + for (int i = 0; i < events.size(); i++) { + if (events.get(i).getCId().equals(cid)) { + return events.get(i); + } + } + return null; + } + + public String getHTML() { + return this.html; + } + + + public static class FixEvent implements Serializable { + protected String cid; + protected String date; + protected String description; + protected List<Sector> sectors; + + protected FixEvent () {} + + public FixEvent( + String cid, + String date, + String description, + List<Sector> sectors + ) { + this.cid = cid; + this.date = date; + this.description = description; + this.sectors = new ArrayList<Sector>(sectors); + } + + public String getCId() { + return this.cid; + } + + public String getDate() { + return this.date; + } + + public String getDescription() { + return this.description; + } + + public List<Sector> getSectors() { + return this.sectors; + } + } + + public static class Sector implements Serializable { + protected int cls; + protected double from; + protected double to; + + protected Sector () {} + + public Sector( + int cls, + double from, + double to + ) { + this.cls = cls; + this.from = from; + this.to = to; + } + + public int getCls() { + return this.cls; + } + + public double getFrom() { + return this.from; + } + + public double getTo() { + return this.to; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Gauge.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public interface Gauge extends Serializable { + + String getName(); + + double getLower(); + + double getUpper(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/GaugeDischargeCurveArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,39 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +/** + * The GaugeDischargeCurveArtifact implementation of an Artifact. + * + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class GaugeDischargeCurveArtifact extends DefaultArtifact { + + /** The name of this artifact */ + public static final String NAME = "gauge_discharge_curve"; + + + public GaugeDischargeCurveArtifact() { + } + + + public GaugeDischargeCurveArtifact(String uuid, String hash) { + super(uuid, hash); + } + + + public GaugeDischargeCurveArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/GaugeImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,51 @@ +package de.intevation.flys.client.shared.model; + + +public class GaugeImpl implements Gauge { + + private String name; + + private double lower; + private double upper; + + + public GaugeImpl() { + } + + + public GaugeImpl(String name, double lower, double upper) { + this.name = name; + this.lower = lower; + this.upper = upper; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getName() { + return name; + } + + + public void setLower(double lower) { + this.lower = lower; + } + + + public double getLower() { + return lower; + } + + + public void setUpper(double upper) { + this.upper = upper; + } + + + public double getUpper() { + return upper; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/GaugeInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,76 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public interface GaugeInfo extends Serializable { + + /** + * Returns the name of the gauge. + */ + String getName(); + + /** + * Returns the start KM of the gauge or null if not available. + */ + Double getKmStart(); + + /** + * Returns the end KM of the gauge or null if not available. + */ + Double getKmEnd(); + + /** + * Returns the mimimum Q value at this gauge or null if not available. + */ + Double getMinQ(); + + /** + * Returns the maximum Q value at this gauge or null if not available. + */ + Double getMaxQ(); + + /** + * Returns the mimimum W value at this gauge or null if not available. + */ + Double getMinW(); + + /** + * Returns the maximim W value at this gauge or null if not available. + */ + Double getMaxW(); + + /** + * Returns the datum value or null if not available. + */ + Double getDatum(); + + /** + * Returns the aeo value or null if not available. + */ + Double getAeo(); + + boolean isKmUp(); + + /** + * Returns the station km of the gauge or null if not available. + */ + Double getStation(); + + /** + * Returns the wst unit as a String. + */ + String getWstUnit(); + + /** + * Returns the official number of this gauge. + */ + Long getOfficialNumber(); + + /** + * Returns the river to which this gauge belongs. + */ + String getRiverName(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/IntDataItem.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,57 @@ +package de.intevation.flys.client.shared.model; + + +/** + * The integer implementation of a {@link DataItem}. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class IntDataItem implements DataItem { + + /** The label. */ + protected String label; + + /** The description. */ + protected String description; + + /** The value. */ + protected int value; + + + public IntDataItem() { + } + + + /** + * The default constructor to create new instances. + * + * @param label The label. + * @param description The description. + * @param value The value. + */ + public IntDataItem(String label, String description, int value) { + this.label = label; + this.description = description; + this.value = value; + } + + + public String getLabel() { + return label; + } + + + public String getDescription() { + return description; + } + + + public String getStringValue() { + return String.valueOf(value); + } + + public int getValue() { + return value; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/IntegerArrayData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,110 @@ +package de.intevation.flys.client.shared.model; + + +public class IntegerArrayData implements Data { + + public static final String TYPE = "intarray"; + + + protected String label; + protected String description; + + protected IntDataItem[] values; + + + public IntegerArrayData() { + } + + + public IntegerArrayData( + String label, + String description, + IntDataItem[] values + ) { + this.label = label; + this.description = description; + this.values = values; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return "intarray"; + } + + + /** + * Returns a DataItem which value is a string that consists of the integer + * values separated by a ';'. + * + * @return the DataItem. + */ + public DataItem[] getItems() { + return values; + } + + + /** + * Returns the values as array. + * + * @return the values as array. + */ + public int[] getValues() { + int[] data = new int[values.length]; + for (int i = 0; i < values.length; i++) { + data[i] = values[i].getValue(); + } + return data; + } + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = ""; + boolean first = true; + for (int i = 0; i < values.length; i++) { + if (!first) { + data += ";"; + } + data += values[i].getStringValue(); + first = false; + } + return data; + } + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/IntegerData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class IntegerData extends DefaultData { + + public static final String TYPE = "integer"; + + + public IntegerData() { + super(); + } + + + public IntegerData(String name, String description, DataItem[] items) { + super(name, description, TYPE, items); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/IntegerOptionsData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,93 @@ +package de.intevation.flys.client.shared.model; + + +/** Data matching to labelled integer(s). */ +public class IntegerOptionsData implements Data { + + public static final String TYPE = "intoptions"; + + protected String label; + protected String description; + + public DataItem[] opts; + + + public IntegerOptionsData() { + } + + + public IntegerOptionsData(String label, String desc, DataItem[] opts) { + this.label = label; + this.description = desc; + this.opts = opts; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return TYPE; + } + + + /** + * Returns the data items which represent the allowed options for this Data. + * + * @return the allowed options as DataItem array. + */ + public DataItem[] getItems() { + return opts; + } + + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = ""; + boolean first = true; + for (int i = 0; i < opts.length; i++) { + if (!first) { + data += ";"; + } + data += opts[i].getStringValue(); + first = false; + } + return data; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/IntegerProperty.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,57 @@ +package de.intevation.flys.client.shared.model; + +import java.util.HashMap; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class IntegerProperty extends PropertySetting { + + /** + * Create a new IntegerProperty for settings. + */ + public IntegerProperty() { + this.attributes = new HashMap<String, String>(); + } + + + /** + * Create a new IntegerProperty. + * @param name The attribute name. + * @param value The current value. + */ + public IntegerProperty( + String name, + Integer value) + { + this.name = name; + this.value = value.toString(); + this.attributes = new HashMap<String, String>(); + } + + + @Override + public Integer getValue() { + try { + return Integer.valueOf(this.value); + } + catch(NumberFormatException nfe) { + return null; + } + } + + + public void setValue(Integer value) { + this.value = value.toString(); + } + + public Object clone() { + IntegerProperty clone = new IntegerProperty(this.getName(), + this.getValue()); + for(String s: this.getAttributeList()) { + clone.setAttribute(s, this.getAttribute(s)); + } + return clone; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/IntegerRangeData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,144 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class IntegerRangeData implements RangeData { + + public static final String TYPE = "intrange"; + + + protected String label; + protected String description; + + protected int lower; + protected int upper; + + protected Integer defLower; + protected Integer defUpper; + + + public IntegerRangeData() { + } + + + public IntegerRangeData(String label, String desc, int lower, int upper) { + this(label, desc, lower, upper, null, null); + } + + + /** + * @param label + * @param desc + * @param lower + * @param upper + * @param defLower + * @param defUpper + */ + public IntegerRangeData( + String label, + String desc, + int lower, + int upper, + Integer defLower, + Integer defUpper + ) { + this.label = label; + this.description = desc; + this.lower = lower; + this.upper = upper; + this.defLower = defLower; + this.defUpper = defUpper; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return "intrange"; + } + + + /** + * Returns a DataItem which value is a string that consists of the min and + * max value separated by a ';'. + * + * @return the DataItem. + */ + public DataItem[] getItems() { + String theMin = String.valueOf(lower); + String theMax = String.valueOf(upper); + + String label = theMin + " - " + theMax; + String value = theMin + ";" + theMax; + + DataItem item = new DefaultDataItem(label, label, value); + + return new DataItem[] { item }; + } + + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } + + + public Object getLower() { + return lower; + } + + + public Object getUpper() { + return upper; + } + + + public Object getDefaultLower() { + return defLower; + } + + + public Object getDefaultUpper() { + return defUpper; + } + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = lower + ";" + upper; + return data; + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/LongRangeData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,144 @@ +package de.intevation.flys.client.shared.model; + + +/** + * Long Range (e.g. storing dates). + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class LongRangeData implements RangeData { + + public static final String TYPE = "longrange"; + + protected String label; + protected String description; + + protected long lower; + protected long upper; + + protected Long defLower; + protected Long defUpper; + + + public LongRangeData() { + } + + + public LongRangeData(String label, String desc, long lower, long upper) { + this(label, desc, lower, upper, null, null); + } + + + /** + * @param label + * @param desc + * @param lower + * @param upper + * @param defLower + * @param defUpper + */ + public LongRangeData( + String label, + String desc, + long lower, + long upper, + Long defLower, + Long defUpper + ) { + this.label = label; + this.description = desc; + this.lower = lower; + this.upper = upper; + this.defLower = defLower; + this.defUpper = defUpper; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return "longrange"; + } + + + /** + * Returns a DataItem which value is a string that consists of the min and + * max value separated by a ';'. + * + * @return the DataItem. + */ + public DataItem[] getItems() { + String theMin = String.valueOf(lower); + String theMax = String.valueOf(upper); + + String label = theMin + " - " + theMax; + String value = theMin + ";" + theMax; + + DataItem item = new DefaultDataItem(label, label, value); + + return new DataItem[] { item }; + } + + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } + + + public Object getLower() { + return lower; + } + + + public Object getUpper() { + return upper; + } + + + public Object getDefaultLower() { + return defLower; + } + + + public Object getDefaultUpper() { + return defUpper; + } + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = lower + ";" + upper; + return data; + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/MINFOArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + + +/** + * The WINFO implementation of an Artifact. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MINFOArtifact extends DefaultArtifact { + + /** The name of this artifact: 'minfo'.*/ + public static final String NAME = "minfo"; + + + public MINFOArtifact() { + } + + + public MINFOArtifact(String uuid, String hash) { + super(uuid, hash); + } + + + public MINFOArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/MapArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + + +/** + * The MAP implementation of an Artifact. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class MapArtifact extends DefaultArtifact { + + /** The name of this artifact: 'map'.*/ + public static final String NAME = "new_map"; + + + public MapArtifact() { + } + + + public MapArtifact(String uuid, String hash) { + super(uuid, hash); + } + + + public MapArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/MapConfig.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,62 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + + +public class MapConfig implements Serializable { + + public static final String ATTR_SRID = "srid"; + public static final String ATTR_MAX_EXTENT = "max_extent"; + public static final String ATTR_INITIAL_EXTENT = "initial_extent"; + + + protected Map<String, String> attributes; + + + public MapConfig() { + attributes = new HashMap<String, String>(); + } + + + public void setAttribute(String key, String value) { + attributes.put(key, value); + } + + + public String getAttribute(String key) { + return attributes.get(key); + } + + + public void setSrid(String srid) { + setAttribute(ATTR_SRID, srid); + } + + + public String getSrid() { + return getAttribute(ATTR_SRID); + } + + + public void setMaxExtent(String maxExtent) { + setAttribute(ATTR_MAX_EXTENT, maxExtent); + } + + + public String getMaxExtent() { + return getAttribute(ATTR_MAX_EXTENT); + } + + + public void setInitialExtent(String initialExtent) { + setAttribute(ATTR_INITIAL_EXTENT, initialExtent); + } + + + public String getInitialExtent() { + return getAttribute(ATTR_INITIAL_EXTENT); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/MapInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,81 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public class MapInfo implements Serializable { + + private static final long serialVersionUID = 6691651180549280493L; + + protected String river; + protected int srid; + protected BBox bbox; + protected String wmsUrl; + protected String wmsLayers; + protected String backgroundWmsUrl; + protected String backgroundWmsLayers; + + + public MapInfo() { + } + + + public MapInfo( + String river, + int srid, + BBox bbox, + String wmsUrl, + String wmsLayers, + String backgroundWmsUrl, + String backgroundWmsLayers) + { + this.river = river; + this.srid = srid; + this.bbox = bbox; + this.wmsUrl = wmsUrl; + this.wmsLayers = wmsLayers; + this.backgroundWmsUrl = backgroundWmsUrl; + this.backgroundWmsLayers = backgroundWmsLayers; + } + + + public String getRiver() { + return river; + } + + + public int getSrid() { + return srid; + } + + + public String getProjection() { + return "EPSG:" + srid; + } + + + public BBox getBBox() { + return bbox; + } + + + public String getWmsUrl() { + return wmsUrl; + } + + + public String getWmsLayers() { + return this.wmsLayers; + } + + + public String getBackgroundWmsUrl() { + return backgroundWmsUrl; + } + + + public String getBackgroundWmsLayers() { + return backgroundWmsLayers; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/MapMode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,41 @@ +package de.intevation.flys.client.shared.model; + +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; +import de.intevation.flys.client.client.ui.map.MapOutputTab; + +import java.util.List; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class MapMode extends DefaultOutputMode { + + /** + * Default constructor required for serialization. + */ + public MapMode() { + } + + public MapMode(String name, String desc, String mimeType) { + super(name, desc, mimeType); + } + + + public MapMode( + String name, + String descrition, + String mimeType, + List<Facet> facets) + { + super(name, descrition, mimeType, facets); + } + + + @Override + public OutputTab createOutputTab(String t, Collection c, CollectionView p) { + return new MapOutputTab(t, c, this, p); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/MeasurementStation.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,73 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public interface MeasurementStation extends Serializable { + + /** + * Returns the name of the measurement station + */ + String getName(); + + /** + * Returns the start KM of the measurement station or null if not available + */ + Double getKmStart(); + + /** + * Returns the end KM of the measurement station or null if not available + */ + Double getKmEnd(); + + boolean isKmUp(); + + /** + * Returns the station km of the measurement station or null if not + * available + */ + Double getStation(); + + /** + * Returns the river to which this measurement station belongs + */ + String getRiverName(); + + /** + * Returns the side of the river which this measurement station belongs + */ + String getRiverSide(); + + /** + * Returns the type of the measurement station + */ + String getMeasurementType(); + + /** + * Returns the ID of the measurement station + */ + Integer getID(); + + /** + * Returns the operator of the measurement station + */ + String getOperator(); + + /** + * Returns the start time of the observation at this measurement station + */ + Date getStartTime(); + + /** + * Returns the end time of the observation at this measurement station + */ + Date getStopTime(); + + /** + * Returns the name of the gauge in reference to this measurement station + */ + String getGaugeName(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Module.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +public interface Module extends Serializable { + + String getName(); + + String getLocalizedName(); + + boolean isSelected(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/NumberAxis.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,60 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class NumberAxis implements Axis { + + protected int pos; + + protected double from; + protected double to; + + protected double min; + protected double max; + + + public NumberAxis() { + } + + + public NumberAxis(int pos, double from, double to, double min, double max) { + this.pos = pos; + this.from = from; + this.to = to; + this.min = min; + this.max = max; + } + + + @Override + public int getPos() { + return pos; + } + + + @Override + public Number getFrom() { + return from; + } + + + @Override + public Number getTo() { + return to; + } + + + @Override + public Number getMin() { + return min; + } + + + @Override + public Number getMax() { + return max; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/OutFilter.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,62 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.ArrayList; +import java.util.List; + +public class OutFilter +implements Serializable +{ + protected String out; + + protected List<FacetFilter> facetFilters; + + public OutFilter() { + facetFilters = new ArrayList<FacetFilter>(); + } + + public OutFilter(String out) { + this(); + this.out = out; + } + + public String getOut() { + return out; + } + + public void setOut(String out) { + this.out = out; + } + + public void add(String name, String num) { + FacetFilter facetFilter = new FacetFilter(name, num); + if (!facetFilters.contains(facetFilter)) { + facetFilters.add(facetFilter); + } + } + + public List<FacetFilter> getFacetFilters() { + return facetFilters; + } + + public void setFacetFilters(List<FacetFilter> facetFilters) { + this.facetFilters = facetFilters; + } + + public void collectIds(StringBuilder sb) { + for (FacetFilter facetFilter: facetFilters) { + facetFilter.collectIds(sb); + } + } + + public List<Recommendation.Facet> toFacets() { + List<Recommendation.Facet> facets = + new ArrayList<Recommendation.Facet>(facetFilters.size()); + for (FacetFilter facetFilter: facetFilters) { + facets.add(facetFilter.toFacet()); + } + return facets; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/OutputMode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,105 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.List; + +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; + + +/** + * This interface describes an output mode of an artifact. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface OutputMode extends Serializable { + + /** + * Retrieves the name of this mode. + * + * @return the name of this mode. + */ + String getName(); + + + /** + * Retrieves the description of this mode. + * + * @return the description of this mode. + */ + String getDescription(); + + + /** + * Retrieves the mime-type of this mode. + * + * + * @return the mime-type of this mode. + */ + String getMimeType(); + + + /** + * Returns the type of this mode. + * + * @return the type of this mode. + */ + String getType(); + + + /** + * Adds a new facet to this mode. + * + * @param facet The new facet. + */ + void addFacet(Facet facet); + + + /** + * Returns the number of facets supported by this mode. + * + * @return the number of facets. + */ + int getFacetCount(); + + + /** + * Returns the facet at a given position. + * + * @param idx The position of a facet. + * + * @return a facet. + */ + Facet getFacet(int idx); + + + /** + * Returns a facet based on its name. + * + * @param name The name of the facet. + * + * @return a facet or null if no such facet is available. + */ + Facet getFacet(String name); + + + /** + * Returns all facets of this mode. + * + * @return all facets. + */ + List<Facet> getFacets(); + + + /** + * Returns an OutputTab that is used to render the output mode. + * + * @param t The title. + * @param c The Collection. + * @param p The parent CollectionView. + * + * @return an OutputTab. + */ + OutputTab createOutputTab(String t, Collection c, CollectionView p); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/OutputSettings.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,74 @@ +package de.intevation.flys.client.shared.model; + +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class OutputSettings implements Settings, Cloneable { + + /** The output name. */ + protected String name; + + /** The categories and settings container. */ + protected HashMap<String, List<Property> > categories; + + + public OutputSettings() { + this.categories = new HashMap<String, List<Property> >(); + } + + + public OutputSettings(String name) { + this.name = name; + this.categories = new HashMap<String, List<Property> >(); + } + + + /** Set output name. */ + public void setName(String name) { + this.name = name; + } + + + /** Get output name. */ + public String getName() { + return this.name; + } + + + public void setSettings(String category, List<Property> settings) { + if (this.categories == null) { + this.categories = new HashMap<String, List<Property> >(); + } + this.categories.put(category, settings); + } + + + public List<Property> getSettings(String category) { + return categories.get(category); + } + + + public List<String> getCategories() { + ArrayList<String> list = new ArrayList<String>(categories.keySet()); + return list; + } + + + public Object clone() { + OutputSettings clone = new OutputSettings(this.getName()); + for (String s: this.getCategories()) { + ArrayList cloneList = new ArrayList<Property>(); + for(Property p: this.getSettings(s)) { + cloneList.add((Property)p.clone()); + } + clone.setSettings(s, cloneList); + } + return clone; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/OverviewMode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,45 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; +import de.intevation.flys.client.client.ui.chart.OverviewOutputTab; + + +/** + * Output mode for chart overviews. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class OverviewMode +extends +DefaultOutputMode { + + public OverviewMode() { + } + + + public OverviewMode(String name, String desc, String mimeType) { + super(name, desc, mimeType); + } + + + public OverviewMode( + String name, + String descrition, + String mimeType, + List<Facet> facets, + String type) + { + super(name, descrition, mimeType, facets); + this.type = type; + } + + + @Override + public OutputTab createOutputTab(String t, Collection c, CollectionView p) { + return new OverviewOutputTab(t, c, this, p); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Property.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +/** + * This interface describes a Property of an output mode. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface Property extends Serializable { + + String getName(); + + void setName(String name); + + Object clone(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/PropertyGroup.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,80 @@ +package de.intevation.flys.client.shared.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * A group of properties. + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class PropertyGroup implements Property, Cloneable { + + /** The group name */ + protected String name; + + protected List<Property> properties; + + public PropertyGroup() { + } + + public PropertyGroup(String name) { + this.name = name; + } + + public PropertyGroup(String name, List<Property> properties) { + this.name = name; + this.properties = properties; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public List<Property> getProperties() { + return this.properties; + } + + public void setProperties(List<Property> properties) { + this.properties = properties; + } + + public Property getPropertyByName(String name) { + for (int i = 0; i < properties.size(); i++) { + if (properties.get(i).getName().equals(name)) { + return properties.get(i); + } + } + return null; + } + + @Override + public Object clone() { + PropertyGroup clone = new PropertyGroup(this.getName()); + List<Property> cloneList = new ArrayList<Property>(); + for(Property p: properties) { + cloneList.add((Property)p.clone()); + } + clone.setProperties(cloneList); + return clone; + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder(); + + for(Property p : properties) { + buf.append(p.getName()); + buf.append("="); + if(p instanceof PropertySetting) { + buf.append(((PropertySetting)p).getValue().toString()); + } + buf.append(" "); + } + + return buf.toString(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/PropertySetting.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,81 @@ +package de.intevation.flys.client.shared.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class PropertySetting implements Property, Cloneable { + + /**The settings name.*/ + protected String name; + + /** The default value.*/ + protected String value; + + /** Additional attributes.*/ + protected HashMap<String, String> attributes; + + /** + * Create a new StyleSetting for theme attribution. + */ + public PropertySetting() { + this.attributes = new HashMap<String, String>(); + } + + + /** + * Create a new PropertySet. + * @param name The attribute name. + * @param value The current value. + */ + public PropertySetting( + String name, + String value) + { + this.name = name; + this.value = value; + this.attributes = new HashMap<String, String>(); + } + + public void setName(String name) { + this.name = name; + } + + public void setValue(String value) { + this.value = value; + } + + public void setAttribute(String k, String v) { + attributes.put(k, v); + } + + public String getName() { + return this.name; + } + + public Object getValue() { + return this.value; + } + + public String getAttribute(String key) { + return attributes.get(key); + } + + public List<String> getAttributeList() { + return new ArrayList<String>(attributes.keySet()); + } + + @Override + public Object clone() { + PropertySetting clone = new PropertySetting(this.getName(), + this.getValue().toString()); + for(String s: this.getAttributeList()) { + clone.setAttribute(s, this.getAttribute(s)); + } + return clone; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/RangeData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface RangeData extends Data { + + Object getLower(); + + Object getUpper(); + + Object getDefaultLower(); + + Object getDefaultUpper(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Recommendation.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,219 @@ +package de.intevation.flys.client.shared.model; + + +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +import java.io.Serializable; + +/** + * Information bundle to let client create/clone an artifact with facets. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class Recommendation implements Serializable { + + /** Index and name of a facet. */ + public static class Facet implements Serializable { + + /** Facet name. */ + protected String name; + + /** Facet index. */ + protected String index; + + public Facet() { + } + + public Facet(String name, String index) { + this.name = name; + this.index = index; + } + + public String getName() { + return name; + } + + public String getIndex() { + return index; + } + + + @Override + public int hashCode() { + int hash = 0; + if (getName() != null) { + hash += getName().hashCode(); + } + if (getIndex() != null) { + hash += getIndex().hashCode(); + } + return hash; + } + + + @Override + public boolean equals(Object other) { + if (!(other instanceof Facet) || other == null) { + return false; + } + Facet facet = (Facet) other; + return (same(facet.getIndex(), this.getIndex())) + && (same(facet.getName(), this.getName())); + } + } // class Facet + + + /** Mapping of outnames to Facet-Lists. */ + public static class Filter implements Serializable { + + protected Map<String, List<Facet>> outs; + + public Filter() { + outs = new HashMap<String, List<Facet>>(); + } + + public void add(String out, List<Facet> facets) { + outs.put(out, facets); + } + + public Map<String, List<Facet>> getOuts() { + return outs; + } + + + @Override + public int hashCode() { + if (getOuts() != null) { + return getOuts().hashCode(); + } + return 0; + } + + + @Override + public boolean equals(Object other) { + if (!(other instanceof Filter) || other == null) { + return false; + } + Filter filter = (Filter) other; + return Recommendation.same(filter.getOuts(), this.getOuts()); + } + } // class Filter + + /** Factory to speak to when creating/cloning. */ + protected String factory; + /** Sometimes database ids, sometimes other freeform text. */ + protected String ids; + /** Artifacts uuid that should serve as master artifact. */ + protected String masterArtifact; + /** Optional facet filter. */ + protected Filter filter; + protected String displayName = null; + + public Recommendation() { + } + + public Recommendation(String factory, String ids) { + this(factory, ids, null, null); + } + + public Recommendation( + String factory, + String ids, + String masterArtifact, + Filter filter + ) { + this.factory = factory; + this.ids = ids; + this.masterArtifact = masterArtifact; + this.filter = filter; + } + + public String getFactory() { + return factory; + } + + public void setFactory(String factory) { + this.factory = factory; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return this.displayName; + } + + public String getIDs() { + return ids; + } + + public String getMasterArtifact() { + return masterArtifact; + } + + public void setMasterArtifact(String masterArtifact) { + this.masterArtifact = masterArtifact; + } + + public Filter getFilter() { + return filter; + } + + public void setFilter(Filter filter) { + this.filter = filter; + } + + + @Override + public int hashCode() { + int hash = 0; + hash += (getFactory() != null) + ? getFactory().hashCode() + : 0; + hash += (getIDs() != null) + ? getIDs().hashCode() + : 0; + hash += (getFilter() != null) + ? getFilter().hashCode() + : 0; + hash += (getMasterArtifact() != null) + ? getMasterArtifact().hashCode() + : 0; + return hash; + } + + + /** + * Null-pointer guarded equals. + * Two null's are assumed equal (returns true); + * @param a Object to compare against parameter b. + * @param b Object to compare against parameter a. + * @return true if either a and b are null or a.equals(b) returns true. + */ + protected static boolean same(Object a, Object b) { + // Do null-check. + if (a == null) { + return b == null; + } else if (b == null) { + return false; + } + return a.equals(b); + } + + + @Override + public boolean equals(Object other) { + if (!(other instanceof Recommendation) || other == null) { + return false; + } + Recommendation rec = (Recommendation) other; + return (same(this.getFactory(), rec.getFactory())) + && (same(this.getIDs(), rec.getIDs())) + && (same(this.getFilter(), rec.getFilter())) + && (same(this.getMasterArtifact(), rec.getMasterArtifact())); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ReportMode.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,39 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +public class ReportMode +extends DefaultOutputMode +{ + public ReportMode() { + } + + + public ReportMode(String name, String desc, String mimeType) { + super(name, desc, mimeType); + } + + + public ReportMode( + String name, + String description, + String mimeType, + List<Facet> facets + ) { + super(name, description, mimeType, facets); + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (Facet f: facets) { + if (first) first = false; + else sb.append(", "); + sb.append("(name = '").append(f.getName()) + .append("', index = ").append(f.getIndex()) + .append(", desc = '").append(f.getDescription()).append("')"); + } + return sb.toString(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/River.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,12 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface River extends Serializable { + + String getName(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/RiverInfo.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,61 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.List; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ + +public interface RiverInfo extends Serializable { + + boolean isKmUp(); + + /** + * Start KM of the river + */ + Double getKmStart(); + + /** + * End KM of the river + */ + Double getKmEnd(); + + /** + * Returns the name of the river + */ + String getName(); + + /** + * Returns the name of the WST unit + */ + String getWstUnit(); + + /** + * Return all gauge info of the river + */ + List<GaugeInfo> getGauges(); + + /** + * Returns the min q value of the river + */ + Double getMinQ(); + + /** + * Returns the max q value of the river + */ + Double getMaxQ(); + + /** + * Returns the official number of the river + */ + Long getOfficialNumber(); + + /** + * Returns the MeasurementStations on this river or null if they aren't + * available. + */ + List<MeasurementStation> getMeasurementStations(); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/SedimentLoadInfoObject.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,15 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface SedimentLoadInfoObject extends Serializable { + + String getDescription(); + + String getDate(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/SedimentLoadInfoObjectImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,31 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class SedimentLoadInfoObjectImpl implements SedimentLoadInfoObject { + + protected String description; + protected String dateString; + + public SedimentLoadInfoObjectImpl() { + } + + public SedimentLoadInfoObjectImpl( + String description, + String dateString + ) { + this.description = description; + this.dateString = dateString; + } + + public String getDescription() { + return description; + } + + public String getDate() { + return this.dateString; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/SedimentLoadInfoRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,32 @@ +package de.intevation.flys.client.shared.model; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + + +public class SedimentLoadInfoRecord +extends ListGridRecord +{ + protected SedimentLoadInfoObject sedimentLoadInfo; + + public SedimentLoadInfoRecord(SedimentLoadInfoObject info) { + this.sedimentLoadInfo = info; + setDescription(info.getDescription()); + setDate(info.getDate()); + } + + public void setDescription(String description) { + setAttribute("description", description); + } + + public void setDate(String date) { + setAttribute("date", date); + } + + public String getDescription() { + return getAttribute("description"); + } + + public String getDate() { + return getAttribute("date"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Settings.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,25 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.List; + +/** + * This interface describes an output settings of an artifact. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface Settings extends Serializable { + + /** The output name */ + String getName(); + + /** */ + List<String> getCategories(); + + /** */ + void setSettings(String category, List<Property> settings); + + /** */ + List<Property> getSettings(String category); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/StaticSQRelationArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,36 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + + +public class StaticSQRelationArtifact +extends DefaultArtifact +{ + + /** The name of this artifact */ + public static final String NAME = "static_sqrelation"; + + + + public StaticSQRelationArtifact() { + } + + public StaticSQRelationArtifact(String uuid, String hash) { + super(uuid, hash); + } + + + public StaticSQRelationArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/StringData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StringData extends DefaultData { + + public static final String TYPE = "string"; + + + public StringData() { + super(); + } + + + public StringData(String name, String description, DataItem[] items) { + super(name, description, TYPE, items); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/StringOptionsData.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,91 @@ +package de.intevation.flys.client.shared.model; + + +public class StringOptionsData implements Data { + + public static final String TYPE = "options"; + + protected String label; + protected String description; + + public DataItem[] opts; + + + public StringOptionsData() { + } + + + public StringOptionsData(String label, String desc, DataItem[] opts) { + this.label = label; + this.description = desc; + this.opts = opts; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return TYPE; + } + + + /** + * Returns the data items which represent the allowed options for this Data. + * + * @return the allowed options as DataItem array. + */ + public DataItem[] getItems() { + return opts; + } + + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } + + + /** + * Returns the values as colon separated string. + * + * @return colon separated string. + */ + public String getStringValue() { + String data = ""; + boolean first = true; + for (int i = 0; i < opts.length; i++) { + if (!first) { + data += ";"; + } + data += opts[i].getStringValue(); + first = false; + } + return data; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/StringProperty.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,49 @@ +package de.intevation.flys.client.shared.model; + +import java.util.HashMap; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class StringProperty extends PropertySetting { + + /** + * Create a new StringProperty for settings. + */ + public StringProperty() { + this.attributes = new HashMap<String, String>(); + } + + + /** + * Create a new StringProperty. + * @param name The attribute name. + * @param value The current value. + */ + public StringProperty( + String name, + String value) + { + this.name = name; + this.value = value; + this.attributes = new HashMap<String, String>(); + } + + + @Override + public String getValue() { + return this.value; + } + + + public Object clone() { + StringProperty clone = new StringProperty(this.getName(), + this.getValue()); + for(String s: this.getAttributeList()) { + clone.setAttribute(s, this.getAttribute(s)); + } + return clone; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Style.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,110 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.List; +import java.util.ArrayList; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class Style implements Serializable { + + /** The theme name. */ + protected String name; + + /** The facet. */ + protected String facet; + + /** The theme index. */ + protected int index; + + /** List of theme attribute settings. */ + protected List<StyleSetting> settings; + + + /** + * Create a new style for theme attribution. + */ + public Style() { + settings = new ArrayList<StyleSetting>(); + } + + + /** + * Append a new style setting. + * @param setting A theme attribution setting. + */ + public void appendStyleSetting(StyleSetting setting) { + settings.add(setting); + } + + public void setName(String name) { + this.name = name; + } + + public void setFacet(String facet) { + this.facet = facet; + } + + public void setIndex(int index) { + this.index = index; + } + + public String getName() { + return this.name; + } + + public String getFacet() { + return this.facet; + } + + public int getIndex() { + return this.index; + } + + + /** + * Getter for a theme attribution setting. + * @return The style setting. + */ + public StyleSetting getSetting(String name) { + for (int i = 0; i < settings.size (); i++) { + if (settings.get(i).getName().equals(name)) { + return settings.get(i); + } + } + return null; + } + + + /** + * Getter for number of settings. + * @return The size of the settings list. + */ + public int getNumSettings () { + return settings.size(); + } + + + /** + * Getter for style settings. + * + * @return The list of style settings. + */ + public List<StyleSetting> getSettings() { + return this.settings; + } + + + /** + * Getter for style setting. + * @param i The index in the settings list. + * + * @return The style setting at the given index. + */ + public StyleSetting getSetting(int i) { + return this.settings.get(i); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/StyleSetting.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,106 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class StyleSetting implements Serializable { + + /**The settings name.*/ + protected String name; + + /** The default value.*/ + protected String defaultValue; + + /**The display name*/ + protected String displayName; + + /**Hints.*/ + protected String hints; + + /**The type*/ + protected String type; + + /** Determines, if the property should be visible in UI or not.*/ + protected boolean hidden; + + + /** + * Create a new StyleSetting for theme attribution. + */ + public StyleSetting() { + } + + + /** + * Create a new StyleSetting for theme attribution. + * @param name The attribute name. + * @param defaultValue The current value. + * @param displayName The name to show in a dialog. + * @param hints Hints. + * @param type The attribute type. + */ + public StyleSetting( + String name, + String defaultValue, + String displayName, + String hints, + String type, + boolean hidden) + { + this.name = name; + this.defaultValue = defaultValue; + this.displayName = displayName; + this.hints = hints; + this.type = type; + this.hidden = hidden; + } + + public void setName(String name) { + this.name = name; + } + + public void setDefaultValue(String value) { + this.defaultValue = value; + } + + public void setDisplayName(String name) { + this.displayName = name; + } + + public void setHints(String hints) { + this.hints = hints; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return this.name; + } + + public String getDefaultValue() { + return this.defaultValue; + } + + public String getDisplayName() { + return this.displayName; + } + + public String getHints() { + return this.hints; + } + + public String getType() { + return this.type; + } + + public boolean isHidden() { + return hidden; + } +} + +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/Theme.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,48 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * A 'Theme' is something displayed in a Chart. It can be activated or + * deactivated to show/hide in the resultant visual representation in the + * chart. + * + * A Theme maps more or less directly to a Facet of an Artifact in a + * Collection (certain attributes are added at Collection-Level). + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Theme extends Serializable { + + int getPosition(); + + void setPosition(int pos); + + int getIndex(); + + int getActive(); + + void setActive(int active); + + int getVisible(); + + void setVisible(int visible); + + String getArtifact(); + + String getFacet(); + + String getDescription(); + + void setDescription(String description); + + boolean equals(Object o); + + /** Get the CollectionItem representing the facets artifact. */ + CollectionItem getCollectionItem(); + + /** Set the CollectionItem representing the facets artifact. */ + void setCollectionItem(CollectionItem ci); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ThemeList.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,183 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + + +/** + * Data Model for list of themes (shown facets). + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ThemeList implements Serializable { + + public List<Theme> themes; + + + public ThemeList() { + } + + + public ThemeList(List<Theme> themes) { + this.themes = themes; + } + + + public List<Theme> getThemes() { + return themes; + } + + + public List<Theme> getActiveThemes() { + List<Theme> active = new ArrayList<Theme>(); + List<Theme> all = getThemes(); + + if (all == null || all.isEmpty()) { + return active; + } + + for (Theme theme: all) { + if (theme.getActive() == 1) { + active.add(theme); + } + } + + return active; + } + + + public int getThemeCount() { + return themes.size(); + } + + + /** + * Returns (first) theme of which the artifact has given uuid, null if none + * found. + * @param uuid Artifacts identifier for which to search theme. + * @return theme of which getArtifact() equals given uuid. + */ + public Theme getTheme(String uuid) { + for (Theme theme: themes) { + if (theme.getArtifact().equals(uuid)) { + return theme; + } + } + return null; + } + + + /** + * Returns a theme at a specific position. <b>NOTE: Themes start at position + * 1. So, take care in loops, that might start at index 0!</b> + * + * @param pos The position of the desired theme. + * + * @return a theme. + */ + public Theme getThemeAt(int pos) { + for (Theme theme: themes) { + if (theme.getPosition() == pos) { + return theme; + } + } + + return null; + } + + + public void removeTheme(Theme theme) { + if (theme != null) { + themes.remove(theme); + } + } + + + public void addTheme(Theme theme) { + if (theme != null) { + themes.add(theme); + } + } + + + /** + * Modifies the order of themes in this list and the position of the + * <i>theme</i> itself. + * + * @param theme The theme which position has to be modified. + * @param newPos The new position. + */ + public void setThemePosition(Theme theme, int newPos) { + int count = getThemeCount(); + int oldPos = theme.getPosition(); + + if (newPos == oldPos || newPos > count || newPos < 1) { + return; + } + + boolean moveUp = newPos < oldPos; + + for (Theme aTheme: themes) { + int tmpPos = aTheme.getPosition(); + + if (theme.equals(aTheme)) { + theme.setPosition(newPos); + } + else if (tmpPos >= newPos && tmpPos < oldPos && moveUp) { + aTheme.setPosition(tmpPos+1); + } + else if (tmpPos <= newPos && tmpPos > oldPos && !moveUp) { + aTheme.setPosition(tmpPos-1); + } + } + } + + + /** + * Create a map from index to description of facets that have a given name. + * Only visible facets are taken into account. + * @param facetName name to match against facets whose info to put in map. + * @return mapping of index to description + */ + public LinkedHashMap<String, String> toMapIndexDescription(String facetName) { + int count = getThemeCount(); + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + for (int i = 0; i <= count; i++) { + Theme theme = getThemeAt(i + 1); + + if (theme == null || theme.getVisible() == 0) { + continue; + } + + if (theme.getFacet().equals(facetName)) { + valueMap.put(String.valueOf(theme.getIndex()), + theme.getDescription()); + } + } + return valueMap; + } + + + public LinkedHashMap<String, String> + toMapArtifactUUIDDescription(String facetName + ) { + int count = getThemeCount(); + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + for (int i = 0; i <= count; i++) { + Theme theme = getThemeAt(i + 1); + + if (theme == null || theme.getVisible() == 0) { + continue; + } + + if (theme.getFacet().equals(facetName)) { + valueMap.put(theme.getArtifact(), + theme.getDescription()); + } + } + return valueMap; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ToLoad.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,119 @@ +package de.intevation.flys.client.shared.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +import java.io.Serializable; + +public class ToLoad implements Serializable +{ + + public class StringPair { + public String first; + public String second; + public StringPair(String first, String second) { + this.first = first; + this.second = second; + } + public int hashCode() { + return first.hashCode() + second.hashCode(); + } + public boolean equals(StringPair other) { + return (this.second.equals(other.second)) && (this.first.equals(other.first)); + } + } + public static final String SYNTHETIC_KEY = "key-"; + + protected Map<String, Map<StringPair, ArtifactFilter>> artifacts; + + public ToLoad() { + artifacts = new HashMap<String, Map<StringPair, ArtifactFilter>>(); + } + + public static final String uniqueKey(Map<?, ?> map) { + int idx = map.size(); + + String key = SYNTHETIC_KEY + idx; + while (map.containsKey(key)) { + key = SYNTHETIC_KEY + ++idx; + } + return key; + } + + public void add( + String artifactName, + String factory, + String out, + String name, + String ids, + String displayName + ) { + if (artifactName == null) { + artifactName = uniqueKey(artifacts); + } + + Map<StringPair, ArtifactFilter> artifact = artifacts.get(artifactName); + + if (artifact == null) { + artifact = new HashMap<StringPair, ArtifactFilter>(); + artifacts.put(artifactName, artifact); + } + + ArtifactFilter filter = artifact.get(factory); + if (filter == null) { + filter = new ArtifactFilter(factory); + artifact.put(new StringPair(factory, displayName), filter); + } + + filter.add(out, name, ids); + } + + public boolean isEmpty() { + return artifacts.isEmpty(); + } + + public List<Recommendation> toRecommendations() { + List<Recommendation> recommendations = new ArrayList<Recommendation>(); + + for (Map.Entry<String, Map<StringPair, ArtifactFilter>> all: + artifacts.entrySet() + ) { + String masterArtifact = all.getKey(); + + if (masterArtifact.startsWith(SYNTHETIC_KEY)) { // system data + masterArtifact = null; + } + + for (Map.Entry<StringPair, ArtifactFilter> entry: + all.getValue().entrySet() + ) { + StringPair pair = entry.getKey(); + String factory = pair.first; + ArtifactFilter artifactFilter = entry.getValue(); + + String ids; + Recommendation.Filter filter; + + if (masterArtifact == null) { // system data + ids = artifactFilter.collectIds(); + filter = null; + } + else { // user specific + ids = null; + filter = artifactFilter.toFilter(); + } + + Recommendation recommendation = new Recommendation( + factory, ids, masterArtifact, filter); + recommendation.setDisplayName(pair.second); + + recommendations.add(recommendation); + } + } + + return recommendations; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/User.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public interface User +extends Serializable +{ + String identifier(); + + String getName(); + + void setName(String name); + + void setIdentifier(String identifier); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/WINFOArtifact.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + + +/** + * The WINFO implementation of an Artifact. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WINFOArtifact extends DefaultArtifact { + + /** The name of this artifact: 'winfo'.*/ + public static final String NAME = "winfo"; + + + public WINFOArtifact() { + } + + + public WINFOArtifact(String uuid, String hash) { + super(uuid, hash); + } + + + public WINFOArtifact( + String uuid, + String hash, + boolean inBackground, + List<CalculationMessage> messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/WMSLayer.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,87 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +public class WMSLayer implements Serializable { + + protected String server; + protected String name; + protected String title; + + protected List<String> srs; + protected List<WMSLayer> layers; + + + public WMSLayer() { + layers = new ArrayList<WMSLayer>(); + } + + + /** + * @param server + * @param title + * @param name + * @param layers + */ + public WMSLayer( + String server, + String title, + String name, + List<String> srs, + List<WMSLayer> layers + ) { + this.server = server; + this.title = title; + this.name = name; + this.srs = srs; + this.layers = layers; + } + + + public String getServer() { + return server; + } + + + public String getName() { + return name; + } + + + public String getTitle() { + return title; + } + + + public List<String> getSrs() { + return srs; + } + + + public List<WMSLayer> getLayers() { + return layers; + } + + + public boolean supportsSrs(String srs) { + if (this.srs == null || this.srs.size() == 0) { + return true; + } + + if (!srs.startsWith("EPSG:")) { + srs = "EPSG:" + srs; + } + + return this.srs.contains(srs); + } + + + @Override + public String toString() { + return "WMS Layer: " + title + " (" + name + ") " + server; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/WQDataItem.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,38 @@ +package de.intevation.flys.client.shared.model; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WQDataItem extends DefaultDataItem { + + protected double[] qRange; + protected double[] wRange; + + public WQDataItem() { + } + + + public WQDataItem( + String label, + String description, + String value, + double[] qRange, + double[] wRange) + { + super(label, description, value); + + this.qRange = qRange; + this.wRange = wRange; + } + + + public double[] getQRange() { + return qRange; + } + + + public double[] getWRange() { + return wRange; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/WQInfoObject.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,17 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface WQInfoObject extends Serializable { + + String getName(); + + String getType(); + + Double getValue(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/WQInfoObjectImpl.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,45 @@ +package de.intevation.flys.client.shared.model; + + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class WQInfoObjectImpl implements WQInfoObject { + + protected String name; + + protected String type; + + protected Double value; + + + public WQInfoObjectImpl() { + } + + + public WQInfoObjectImpl( + String name, + String type, + Double value) + { + this.name = name; + this.type = type; + this.value = value; + } + + + public String getName() { + return name; + } + + + public String getType() { + return type; + } + + + public Double getValue() { + return value; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/WQInfoRecord.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,68 @@ +package de.intevation.flys.client.shared.model; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + + +/** + * The WQInfoRecord is a wrapper to put WQ Info objects into + * a ListGrid. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class WQInfoRecord extends ListGridRecord { + + /** The artifact collection. */ + protected WQInfoObject wqInfo; + + + /** + * The default constructor. + * + * @param info The wq info object. + */ + public WQInfoRecord(WQInfoObject info) { + this.wqInfo = info; + + setName(info.getName()); + setType(info.getType()); + if (info.getValue() != null) + setValue(info.getValue()); + else + setValue(info.getValue()); + } + + + public void setName(String name) { + setAttribute("name", name); + } + + + public String getName() { + return getAttributeAsString("name"); + } + + + public void setType(String type) { + setAttribute("type", type); + } + + + public String getType() { + return getAttributeAsString("type"); + } + + public void setValue(double value) { + setAttribute("value", value); + } + + + public double getValue() { + return getAttributeAsDouble("value"); + } + + + public WQInfoObject getWQInfo() { + return wqInfo; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/org/dive4elements/river/client/shared/model/ZoomObj.java Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,30 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public class ZoomObj implements Serializable { + + protected Number a; + protected Number b; + protected Number c; + protected Number d; + + + public ZoomObj() { + } + + + public ZoomObj(Number a, Number b, Number c, Number d) { + this.a = a; + this.b = b; + this.c = c; + this.d = d; + } + + + public Number[] getZoom() { + return new Number[] { a, b, c, d }; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/test/java/de/intevation/flys/client/FLYSJUnit.gwt.xml Thu Apr 25 12:26:40 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module> - <!-- Inherit our applications main module. --> - <inherits name='de.intevation.flys.client.FLYS'/> - - <!-- Specify the path to any remote services. --> - <!-- - <servlet path="/flys/greet" class="de.intevation.flys.client.server.GreetingServiceImpl" /> - --> - -</module>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/test/java/org/dive4elements/river/client/FLYSJUnit.gwt.xml Thu Apr 25 12:31:32 2013 +0200 @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module> + <!-- Inherit our applications main module. --> + <inherits name='de.intevation.flys.client.FLYS'/> + + <!-- Specify the path to any remote services. --> + <!-- + <servlet path="/flys/greet" class="de.intevation.flys.client.server.GreetingServiceImpl" /> + --> + +</module>