List of usage examples for com.google.gwt.core.client JavaScriptObject createArray
public static native JavaScriptObject createArray() ;
From source file:com.gwtmobile.persistence.client.EntityInternal.java
License:Apache License
public void index(String[] columns, boolean unique) { JsArrayString jsArray = (JsArrayString) JavaScriptObject.createArray(); for (int i = 0; i < columns.length; i++) { String col = columns[i];//from www . j a va2 s .c o m jsArray.set(i, col); } index(jsArray, false, getNativeObject()); }
From source file:com.gwtmobile.persistence.client.Persistence.java
License:Apache License
@SuppressWarnings("unchecked") public static void dumpToJson(Transaction transaction, Entity<?>[] entities, ScalarCallback<String> callback) { JsArray<JavaScriptObject> entitiesArray = null; if (entities != null) { entitiesArray = (JsArray<JavaScriptObject>) JavaScriptObject.createArray(); for (int i = 0; i < entities.length; i++) { EntityInternal<?> entity = (EntityInternal<?>) entities[i]; entitiesArray.set(i, entity.getNativeObject()); }// w ww .ja va 2 s .c om } dumpToJsonNative(transaction, entitiesArray, callback); }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
/** * Called whenever an update is received from the server */// w w w . j a va2 s .com public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { VConsole.log("Enter [updateFromUIDL]"); // This call should be made first. // It handles sizes, captions, tooltips, etc. automatically. if (client.updateComponent(this, uidl, true)) { // If client.updateComponent returns true there has been no changes // and we // do not need to update anything. return; } // Save reference to server connection object to be able to send // user interaction later this.client = client; // Save the client side identifier (paintable id) for the widget uidlId = uidl.getId(); // Create chart only once along with chart options // Chart options are set only once. if (chart == null) { // Chart options GwtInvientChartsConfig options = getInvientChartOptions( uidl.getChildUIDL(ChartUIDLIndex.OPTIONS.ordinal())); // Chart events updateOptionsWithEvents(options, uidl.getChildUIDL(ChartUIDLIndex.EVENTS.ordinal())); // Chart data JsArray<GwtSeriesDataOptions> chartData = getChartData( uidl.getChildUIDL(ChartUIDLIndex.DATA.ordinal())); options.setSeriesInstanceOptions(chartData); VConsole.log("Going to create a chart."); createChart(options); } else { resetRedrawChart(); if (uidl.getBooleanAttribute("reloadChartSeries")) { // Get all series and add them to chart JsArray<GwtSeriesDataOptions> chartData = getChartData( uidl.getChildUIDL(ChartUIDLIndex.DATA.ordinal())); int seriesCount = chart.getSeries().length(); VConsole.log("# of series the chart has " + seriesCount); VConsole.log("Going to remove all series of the chart."); for (int ind = seriesCount - 1; ind >= 0; ind--) { setRedrawChart(); chart.getSeries().get(ind).remove(false); } VConsole.log("Goint to add series to the chart."); for (int ind = 0; ind < chartData.length(); ind++) { setRedrawChart(); chart.addSeries(chartData.get(ind), false); } } else { VConsole.log("Going to update chart data."); UIDL chartDataUIDL = uidl.getChildUIDL(ChartUIDLIndex.DATA.ordinal()); UIDL chartDataUpdatesUIDL = uidl.getChildUIDL(ChartUIDLIndex.DATA_UPDATES.ordinal()); updateChartData(chartDataUpdatesUIDL, chartDataUIDL); } // Options UIDL UIDL optionsUIDL = uidl.getChildUIDL(ChartUIDLIndex.OPTIONS.ordinal()); // Update chart title & subtitle setChartTitleAndSubtitle(optionsUIDL); // Size setChartSize(optionsUIDL); VConsole.log("Getting x-axis options..."); JsArray<GwtXAxisOptions> uidlXAxesOptionsArr = getXAxisOptions( optionsUIDL.getChildUIDL(ChartOptionsUIDLIndex.X_AXES.ordinal())); JsArray<GwtXAxisOptions> chartXAxesOptionsArr = JavaScriptObject.createArray().cast(); JsArray<GwtAxis> chartXAxesArr = chart.getXAxes(); if (chart.getOptions().hasXAxesOptions()) { chartXAxesOptionsArr = chart.getOptions().getXAxesOptions(); updateXAxisCategories(chartXAxesArr, chartXAxesOptionsArr, uidlXAxesOptionsArr); } updateAxesPlotBandsAndPlotLines(chartXAxesArr, chartXAxesOptionsArr, uidlXAxesOptionsArr); VConsole.log("Getting y-axis options..."); JsArray<GwtYAxisOptions> uidlYAxesOptionsArr = getYAxisOptions( optionsUIDL.getChildUIDL(ChartOptionsUIDLIndex.Y_AXES.ordinal())); JsArray<GwtYAxisOptions> chartYAxesOptionsArr = JavaScriptObject.createArray().cast(); if (chart.getOptions().hasYAxesOptions()) { chartYAxesOptionsArr = chart.getOptions().getYAxesOptions(); } JsArray<GwtAxis> chartYAxesArr = chart.getYAxes(); updateAxesPlotBandsAndPlotLines(chartYAxesArr, chartYAxesOptionsArr, uidlYAxesOptionsArr); // Update axis extremes if (chart.getOptions().hasXAxesOptions() || chart.getOptions().hasYAxesOptions()) { updateAxisExtremes(chart.getXAxes(), chartXAxesOptionsArr, uidlXAxesOptionsArr); updateAxisExtremes(chart.getYAxes(), chartYAxesOptionsArr, uidlYAxesOptionsArr); } if (isRedrawChart()) { VConsole.log("Going to redraw the chart."); chart.redraw(); } } // Get SVG if required and send it to server handleChartSVG(uidl); handlePrint(uidl); VConsole.log("Exit [updateFromUIDL]"); }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
private void updatePlotLines(GwtAxis chartAxis, GwtAxisBaseOptions chartAxisOptions, GwtAxisBaseOptions uidlAxisOptions) { VConsole.log("Enter [updatePlotLines]"); // Update chartAxisPlotBands whenever a plotline is added or removed as // the library // does not update chart options by itself. JsArray<GwtPlotLines> chartAxisPlotLines = chartAxisOptions.getPlotLines(); JsArray<GwtPlotLines> uidlAxisPlotLines = uidlAxisOptions.getPlotLines(); if (uidlAxisPlotLines == null && chartAxisPlotLines == null) { VConsole.log("No plotlines found."); VConsole.log("Exit [updatePlotLines]"); return;/*ww w . j a v a 2 s . co m*/ } if (uidlAxisPlotLines == null) { uidlAxisPlotLines = JavaScriptObject.createArray().cast(); } if (chartAxisPlotLines == null) { chartAxisPlotLines = JavaScriptObject.createArray().cast(); } JsArray<GwtPlotLines> updatedChartAxisPlotLines = JavaScriptObject.createArray().cast(); int numOfChartAxisPlotLines = chartAxisPlotLines.length(); int numOfUIDLAxisPlotLines = uidlAxisPlotLines.length(); boolean updatedAxisPlotLines = false; for (int indOuter = 0; indOuter < numOfChartAxisPlotLines; indOuter++) { GwtPlotLines chartPlotLine = chartAxisPlotLines.get(indOuter); String plotLineId = chartPlotLine.getId(); boolean found = false; for (int indInner = 0; indInner < numOfUIDLAxisPlotLines; indInner++) { GwtPlotLines uidlPlotLine = uidlAxisPlotLines.get(indInner); if (uidlPlotLine != null && uidlPlotLine.getId().equals(plotLineId)) { if (uidlPlotLine.getValue() == chartPlotLine.getValue()) { // PlotLine exists and value is same so no action should // be taken except marking UIDL PlotLine to null. // Setting UIDL PlotLine // to null ensures that remaining PlotLines in UIDL can // be added // safely to the chart. uidlAxisPlotLines.set(indInner, null); updatedChartAxisPlotLines.push(chartPlotLine); found = true; } break; } } if (!found) { // remove plot line as it is not found in UIDL received from the // server updatedAxisPlotLines = true; chartAxis.removePlotLine(plotLineId); } } // Add all remaining plot lines in UIDL to the chart for (int ind = 0; ind < numOfUIDLAxisPlotLines; ind++) { GwtPlotLines uidlPlotLine = uidlAxisPlotLines.get(ind); if (uidlPlotLine != null) { updatedAxisPlotLines = true; chartAxis.addPlotLine(uidlPlotLine); updatedChartAxisPlotLines.push(uidlPlotLine); } } // Update chart axis plotlines if (updatedAxisPlotLines) { setRedrawChart(); chartAxisOptions.setPlotLines(updatedChartAxisPlotLines); } VConsole.log("Exit [updatePlotLines]"); }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
private void updatePlotBands(GwtAxis chartAxis, GwtAxisBaseOptions chartAxisOptions, GwtAxisBaseOptions uidlAxisOptions) { VConsole.log("Enter [updatePlotBands]"); // Update chartAxisPlotBands whenever a plotband is added or removed as // the library // does not update chart options by itself. JsArray<GwtPlotBands> chartAxisPlotBands = chartAxisOptions.getPlotBands(); JsArray<GwtPlotBands> uidlAxisPlotBands = uidlAxisOptions.getPlotBands(); if (uidlAxisPlotBands == null && chartAxisPlotBands == null) { VConsole.log("No plotbands found."); VConsole.log("Exit [updatePlotBands]"); return;/* w w w . java2 s .c o m*/ } if (uidlAxisPlotBands == null) { uidlAxisPlotBands = JavaScriptObject.createArray().cast(); } if (chartAxisPlotBands == null) { chartAxisPlotBands = JavaScriptObject.createArray().cast(); } JsArray<GwtPlotBands> updatedChartAxisPlotBands = JavaScriptObject.createArray().cast(); int numOfChartAxisPlotBands = chartAxisPlotBands.length(); int numOfUIDLAxisPlotBands = uidlAxisPlotBands.length(); boolean updatedAxisPlotBands = false; for (int indOuter = 0; indOuter < numOfChartAxisPlotBands; indOuter++) { GwtPlotBands chartPlotBand = chartAxisPlotBands.get(indOuter); String plotBandId = chartPlotBand.getId(); boolean found = false; for (int indInner = 0; indInner < numOfUIDLAxisPlotBands; indInner++) { GwtPlotBands uidlPlotBand = uidlAxisPlotBands.get(indInner); if (uidlPlotBand != null && uidlPlotBand.getId().equals(plotBandId)) { if (chartPlotBand.getFrom() == uidlPlotBand.getFrom() && chartPlotBand.getTo() == uidlPlotBand.getTo()) { VConsole.log("Plotband id " + plotBandId + " exists in chart as well as in UIDL from the server."); // PlotBand exists and from/to values are same so // nothing to be done. // The UIDL plotband is set to null so that remaining // plotbands // can be safely added to the chart uidlAxisPlotBands.set(indInner, null); updatedChartAxisPlotBands.push(chartPlotBand); VConsole.log("Plotband id " + plotBandId + " exists in both."); found = true; } break; } } if (!found) { // remove plot band as it is not found in UIDL received from the // server VConsole.log("Plotband id " + plotBandId + " removed."); updatedAxisPlotBands = true; chartAxis.removePlotBand(plotBandId); } } // Add all remaining plot bands in UIDL to the chart for (int ind = 0; ind < numOfUIDLAxisPlotBands; ind++) { GwtPlotBands uidlPlotBand = uidlAxisPlotBands.get(ind); if (uidlPlotBand != null) { updatedAxisPlotBands = true; VConsole.log("Plotband id " + uidlPlotBand.getId() + " added with from : " + uidlPlotBand.getFrom() + " and to: " + uidlPlotBand.getTo()); chartAxis.addPlotBand(uidlPlotBand); updatedChartAxisPlotBands.push(uidlPlotBand); } } // Update chart axis plotbands if (updatedAxisPlotBands) { setRedrawChart(); chartAxisOptions.setPlotBands(updatedChartAxisPlotBands); } VConsole.log("Exit [updatePlotBands]"); }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
private void updateChartData(UIDL uidlChartDataUpdates, UIDL uidlChartData) { VConsole.log("Enter [updateChartData]"); JsArrayString seriesToAdd = JavaScriptObject.createArray().cast(); JsArrayString seriesToUpdate = JavaScriptObject.createArray().cast(); List<UIDL> seriesToUpdateList = new ArrayList<UIDL>(); for (int ind = 0; ind < uidlChartDataUpdates.getChildCount(); ind++) { UIDL seriesUpdateUIDL = uidlChartDataUpdates.getChildUIDL(ind); String seriesName = seriesUpdateUIDL.getStringAttribute("seriesName"); String operation = seriesUpdateUIDL.getStringAttribute("operation"); VConsole.log("Series name : " + seriesName + ", operation : " + operation); if (seriesName != null && seriesName.length() > 0 && operation != null && operation.length() > 0) { if (SeriesCURType.REMOVE.getName().equals(operation)) { GwtSeries series = chart.getSeries(seriesName); if (series != null) { VConsole.log("Removing series : " + seriesName); setRedrawChart();//from w w w.j av a2 s .c o m series.remove(false); } } else if (SeriesCURType.ADD.getName().equals(operation)) { seriesToAdd.push(seriesName); } else if (SeriesCURType.UPDATE.getName().equals(operation)) { VConsole.log("Will update series : " + seriesName); seriesToUpdateList.add(seriesUpdateUIDL); seriesToUpdate.push(seriesName); } } } if (seriesToAdd.length() > 0) { setRedrawChart(); JsArray<GwtSeriesDataOptions> uidlChartDataArr = getChartData(uidlChartData, seriesToAdd); for (int ind = 0; ind < uidlChartDataArr.length(); ind++) { VConsole.log("Adding series " + uidlChartDataArr.get(ind).getName()); chart.addSeries(uidlChartDataArr.get(ind), false); } } if (seriesToUpdateList.size() > 0) { setRedrawChart(); JsArray<GwtSeriesDataOptions> uidlChartDataArr = getChartData(uidlChartData, seriesToUpdate); for (int ind = 0; ind < seriesToUpdateList.size(); ind++) { UIDL uidlSeriesToUpdate = seriesToUpdateList.get(ind); GwtSeriesDataOptions uidlSeriesDataOptions = uidlChartDataArr.get(ind); GwtSeries chartSeries = chart.getSeries(uidlSeriesDataOptions.getName()); GwtSeriesGeneralOptions chartSeriesOptions = chartSeries.getSeriesGeneralOptions(); GwtSeriesGeneralOptions uidlSeriesOptions = uidlSeriesDataOptions.getSeriesOptions(); // Update visibility boolean isVisible = (uidlSeriesOptions != null ? uidlSeriesOptions.isVisible() : true); chartSeriesOptions.setVisible(isVisible); if (chartSeriesOptions.isVisible() == true && chartSeries.isVisible() == false) { chartSeries.show(); } if (chartSeriesOptions.isVisible() == false && chartSeries.isVisible() == true) { chartSeries.hide(); } // Update points if (uidlSeriesToUpdate.getBooleanAttribute("isReloadPoints")) { // update all points VConsole.log("Reloading points for series : " + uidlSeriesToUpdate.getStringAttribute("name")); chartSeries.setDataAsPointOptions(uidlSeriesDataOptions.getDataAsPointOptions(), false); } else { UIDL uidlPointsAdded = uidlSeriesToUpdate.getChildUIDL(0); UIDL uidlPointsRemoved = uidlSeriesToUpdate.getChildUIDL(1); updateSeriesData(chartSeries, uidlPointsAdded, uidlPointsRemoved); } } } VConsole.log("Exit [updateChartData]"); }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
private JsArray<GwtSeriesDataOptions> getChartData(UIDL uidl, JsArrayString namesOfSeriesToAdd) { VConsole.log("Enter [getChartData]"); JsArray<GwtSeriesDataOptions> seriesDataArr = JavaScriptObject.createArray().cast(); // Process each series data for (int cnt = 0; cnt < uidl.getChildCount(); cnt++) { GwtSeriesDataOptions seriesData = GwtSeriesDataOptions.create(); UIDL seriesUIDL = uidl.getChildUIDL(cnt); String seriesName = seriesUIDL.getStringAttribute("name"); if (seriesName != null && namesOfSeriesToAdd != null) { if (!doesArrayContainSeriesName(namesOfSeriesToAdd, seriesName)) { continue; }//from w w w . jav a2 s . c o m } // From charts series data retrieve only those series data // whose names are specified in the second argument if (seriesUIDL.hasAttribute("name")) { // Setting name automatically sets series id which can later be // used to retrieve using chart.get(id); seriesData.setName(seriesName); } if (seriesUIDL.hasAttribute("stack")) { seriesData.setStack(seriesUIDL.getStringAttribute("stack")); } // FIXME - fallback on chart options type if series doesn't have a // type String seriesType = "line"; if (seriesUIDL.hasAttribute("type")) { seriesType = seriesUIDL.getStringAttribute("type"); seriesData.setType(seriesType); } if (seriesUIDL.hasAttribute("xAxis")) { seriesData.setXAxis(seriesUIDL.getIntAttribute("xAxis")); } if (seriesUIDL.hasAttribute("yAxis")) { seriesData.setYAxis(seriesUIDL.getIntAttribute("yAxis")); } // Get data/points seriesData.setDataAsPointOptions(getSeriesPoints(seriesUIDL.getChildUIDL(1))); // Get series options GwtSeriesGeneralOptions seriesOptions = getSeriesOptions(seriesType, seriesUIDL.getChildUIDL(0)); if (seriesOptions != null) { seriesData.setSeriesOptions(seriesOptions); } seriesDataArr.push(seriesData); } VConsole.log("Exit [getChartData]"); return seriesDataArr; }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
private JsArray<GwtPointOptions> getSeriesPoints(UIDL pointsUIDL) { VConsole.log("Enter [getSeriesPoints]"); JsArray<GwtPointOptions> pointsArr = JavaScriptObject.createArray().cast(); for (int cnt = 0; cnt < pointsUIDL.getChildCount(); cnt++) { UIDL pointUIDL = pointsUIDL.getChildUIDL(cnt); GwtPointOptions pointOptions = GwtPointOptions.create(); // If a point doesn't have any attributes then // consider it as a null since a user might want to represent // no activity graph if (pointUIDL.getAttributeNames().size() == 0) { pointOptions.setNullY();/*from w w w . j a va 2 s .c o m*/ } else { if (pointUIDL.hasAttribute("id")) { pointOptions.setId(pointUIDL.getStringAttribute("id")); } if (pointUIDL.hasAttribute("name")) { pointOptions.setName(pointUIDL.getStringAttribute("name")); } if (pointUIDL.hasAttribute("color")) { pointOptions.setColor(pointUIDL.getStringAttribute("color")); } if (pointUIDL.hasAttribute("sliced")) { pointOptions.setSliced(pointUIDL.getBooleanAttribute("sliced")); } if (pointUIDL.hasAttribute("selected")) { pointOptions.setSelected(pointUIDL.getBooleanAttribute("selected")); } if (pointUIDL.hasAttribute("x")) { pointOptions.setX(pointUIDL.getIntAttribute("x")); } else { pointOptions.setNullX(); } if (pointUIDL.hasAttribute("y")) { pointOptions.setY(pointUIDL.getIntAttribute("y")); } else { pointOptions.setNullY(); } if (pointUIDL.hasAttribute("isShift")) { pointOptions.setShift(pointUIDL.getBooleanAttribute("isShift")); } GwtMarker markerOptions = getMarkerOptions(pointUIDL.getChildUIDL(0)); if (markerOptions != null) { pointOptions.setMarker(markerOptions); } } pointsArr.push(pointOptions); } VConsole.log("Exit [getSeriesPoints]"); return pointsArr; }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
private GwtChartLabels getChartLabels(UIDL uidl) { VConsole.log("Enter [getChartLabels]"); VConsole.log("Tag name -> " + uidl.getTag()); if ((uidl.getAttributeNames().size() == 0 && uidl.getChildCount() == 0) || (uidl.getAttributeNames().size() > 0 && uidl.getChildCount() == 0)) { VConsole.log("Exit [getChartLabels]"); return null; }/* w ww . ja v a 2 s . com*/ UIDL labelItemsUIDL = uidl.getChildUIDL(0); if (labelItemsUIDL.getChildCount() == 0) { VConsole.log("Exit [getChartLabels]"); return null; } GwtChartLabels labels = GwtChartLabels.create(); if (uidl.hasAttribute("style")) { labels.setStyle(uidl.getStringAttribute("style")); } JsArray<GwtChartLabelItem> chartLabelItemsArr = JavaScriptObject.createArray().cast(); for (int cnt = 0; cnt < labelItemsUIDL.getChildCount(); cnt++) { UIDL labelItemUIDL = labelItemsUIDL.getChildUIDL(cnt); if (labelItemUIDL.hasAttribute("html") || labelItemUIDL.hasAttribute("style")) { GwtChartLabelItem labelItem = GwtChartLabelItem.create(); if (labelItemUIDL.hasAttribute("html")) { labelItem.setHtml(labelItemUIDL.getStringAttribute("html")); } // if (labelItemUIDL.hasAttribute("style")) { labelItem.setStyle(labelItemUIDL.getStringAttribute("style")); } chartLabelItemsArr.push(labelItem); } } labels.setItems(chartLabelItemsArr); VConsole.log("Exit [getChartLabels]"); return labels; }
From source file:com.invient.vaadin.charts.widgetset.client.ui.VInvientCharts.java
License:Apache License
private JsArray<GwtPlotBands> getPlotBands(UIDL plotBandsUIDL) { JsArray<GwtPlotBands> plotBandsArr = JavaScriptObject.createArray().cast(); for (int cnt = 0; cnt < plotBandsUIDL.getChildCount(); cnt++) { UIDL plotBandUIDL = plotBandsUIDL.getChildUIDL(cnt); if (plotBandUIDL.getAttributeNames().size() == 0 && plotBandUIDL.getChildCount() == 0) { continue; }//from w ww . j ava 2s . co m GwtPlotBands plotBands = GwtPlotBands.create(); if (plotBandUIDL.hasAttribute("color")) { plotBands.setColor(plotBandUIDL.getStringAttribute("color")); } if (plotBandUIDL.hasAttribute("id")) { plotBands.setId(plotBandUIDL.getStringAttribute("id")); } if (plotBandUIDL.hasAttribute("zIndex")) { plotBands.setZIndex(plotBandUIDL.getIntAttribute("zIndex")); } // label GwtPlotLabel label = getPlotLabel(plotBandUIDL.getChildUIDL(0)); if (label != null) { plotBands.setLabel(label); } // from/to value UIDL valueUIDL = plotBandUIDL.getChildUIDL(1); if (valueUIDL.hasAttribute("valueType")) { String valueType = valueUIDL.getStringAttribute("valueType"); if (valueType.equals("number")) { plotBands.setFrom(valueUIDL.getDoubleAttribute("from")); plotBands.setTo(valueUIDL.getDoubleAttribute("to")); } else { // date // from UIDL fromUIDL = valueUIDL.getChildUIDL(0); int fromYear = fromUIDL.getIntAttribute("year"); int fromMonth = fromUIDL.getIntAttribute("month"); int fromDay = fromUIDL.getIntAttribute("day"); plotBands.setFrom("Date.UTC(" + fromYear + ", " + fromMonth + "," + fromDay + ")"); // to UIDL toUIDL = valueUIDL.getChildUIDL(1); int toYear = toUIDL.getIntAttribute("year"); int toMonth = toUIDL.getIntAttribute("month"); int toDay = toUIDL.getIntAttribute("day"); plotBands.setTo("Date.UTC(" + toYear + ", " + toMonth + "," + toDay + ")"); } } // plotBandsArr.push(plotBands); } return plotBandsArr; }