@Before public void setUp() { MockitoAnnotations.initMocks(this); when(dataObject.getSource()).thenReturn(source); doReturn("AccountName").when(gitHubUser).getName(); doReturn("AccountLogin").when(gitHubUser).getLogin(); when(gitHubAuthenticatorRegistry.getAuthenticator(eq("github"))) .thenReturn(gitHubAuthenticator); presenter = spy( new GithubImporterPagePresenter( view, gitHubAuthenticatorRegistry, gitHubClientService, dtoFactory, appContext, locale, oAuthServiceClient, notificationManager)); doReturn(Collections.singletonList(gitHubUser)) .when(presenter) .toOrgList(nullable(JsArrayMixed.class)); doReturn(Collections.emptyList()).when(presenter).toRepoList(nullable(JsArrayMixed.class)); presenter.setUpdateDelegate(updateDelegate); presenter.init(dataObject); }
private void draw() { JsArrayMixed dataArray = JsonUtils.unsafeEval("[['Mon',20,28,38,45],['Tue',31,38,55,66],['Wed',50,55,77,80],['Thu',77,77,66,50],['Fri',68,66,22,15]]"); // Prepare the data DataTable dataTable = ChartHelper.arrayToDataTable(dataArray, true); // Set options CandlestickChartOptions options = CandlestickChartOptions.create(); BackgroundColor bgColor = BackgroundColor.create(); bgColor.setStroke("#2196f3"); bgColor.setFill("#90caf9"); bgColor.setStrokeWidth(2); options.setLegend(Legend.create(LegendPosition.NONE)); options.setFallingColor(bgColor); options.setRisingColor(bgColor); // Draw the chart chart.draw(dataTable, options); }
private void draw() { JsArrayMixed dataArray = JsonUtils .unsafeEval("[['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua Guinea', 'Rwanda', 'Average'],['2004/05', 165, 938, 522, 998, 450, 614.6],['2005/06', 135, 1120, 599, 1268, 288, 682],['2006/07', 157, 1167, 587, 807, 397, 623],['2007/08', 139, 1110, 615, 968, 215, 609.4],['2008/09', 136, 691, 629, 1026, 366, 569.6]]"); // Prepare the data DataTable dataTable = ChartHelper.arrayToDataTable(dataArray); // Set options ComboChartOptions options = ComboChartOptions.create(); options.setFontName("Tahoma"); options.setTitle("Monthly Coffee Production by Country"); options.setHAxis(HAxis.create("Cups")); options.setVAxis(VAxis.create("Month")); options.setSeriesType(SeriesType.BARS); ComboChartSeries series = ComboChartSeries.create(); series.setType(SeriesType.LINE); options.setSeries(5, series); // Draw the chart chart.draw(dataTable, options); }
public List<Record> getAsMap() { ArrayList<Record> res = new ArrayList<com.gbourquet.yaph.client.utils.Record>(); String[] columns = new String[columnsIdx.size()]; for (Entry<String, Integer> e : columnsIdx.entrySet()) columns[e.getValue()] = e.getKey(); for (int r = 0; r < size(); r++) { HashMap<String, String> rowObject = new HashMap<String, String>(); JsArrayMixed row = rows.get(r); for (int c = 0; c < row.length(); c++) rowObject.put(columns[c], row.getString(c)); Record record = new Record(); record.setProperties(rowObject); res.add(record); } return res; }
@Override public HandlerRegistration addViewPortChangeHandler(ViewPortChangeHandler handler) { if (!viewPortHandlerAdded) { viewPortHandlerAdded = true; this.codeMirror.on(this.editorOverlay, VIEWPORT_CHANGE, new EventHandlers.EventHandlerMixedParameters() { @Override public void onEvent(final JsArrayMixed param) { final int from = Double.valueOf(param.getNumber(0)).intValue(); final int to = Double.valueOf(param.getNumber(1)).intValue(); fireViewPortChangeEvent(from, to); } }); } return addHandler(handler, ViewPortChangeEvent.TYPE); }
@Override public HandlerRegistration addGutterClickHandler(GutterClickHandler handler) { if (!gutterClickHandlerAdded) { gutterClickHandlerAdded = true; this.editorOverlay.on(GUTTER_CLICK, new EventHandlers.EventHandlerMixedParameters() { @Override public void onEvent(final JsArrayMixed params) { // param 0 is codemirror instance final int line = Double.valueOf(params.getNumber(1)).intValue(); final String gutterId = params.getString(2); // param 3 is click event final JsMouseEvent event = params.getObject(3).cast(); fireGutterClickEvent(line, gutterId, event); } }); } return addHandler(handler, GutterClickEvent.TYPE); }
public void showCompletionProposals() { if (! editorWidget.getEditorOverlay().hasShowHint()) { // no support for hints return; } final CMHintFunctionOverlay hintAuto = CMHintFunctionOverlay.createFromName(editorWidget.getCodeMirror(), "auto"); final CMHintResultsOverlay result = hintAuto.apply(editorWidget.getEditorOverlay()); if (result != null) { final List<String> proposals = new ArrayList<>(); final JsArrayMixed list = result.getList(); int nonStrings = 0; //jsarray aren't iterable for (int i = 0; i < list.length(); i++) { if (result.isString(i)) { proposals.add(result.getCompletionItemAsString(i)); } else { nonStrings++; } } LOG.info("CM Completion returned " + list.length() + " items, of which " + nonStrings + " were not strings."); showCompletionProposals(proposals, result.getFrom(), result.getTo()); } }
public JsArrayMixed toJso(List<Object> args) { JsArrayMixed result = (JsArrayMixed) JavaScriptObject.createArray(); for (Object o : args) { if (o == null) { result.push((JavaScriptObject) null); } else if (o instanceof String) { result.push((String) o); } else if (o instanceof Date) { result.push(JsDate.create(((Date) o).getTime())); } else if (o instanceof Double) { result.push(((Double) o).doubleValue()); } else { throw new IllegalArgumentException("Don't know how to handle " + o); } } return result; }
protected void test(String json, String sql, JsArrayMixed args, String msg) throws Throwable { RootPanel.get().getElement().setAttribute("id", "rqb"); try { if (json != null) { conf = (JsConfiguration) JsonUtils.unsafeEval(json); addHandlers(conf); } builder = RedQueryBuilder.configure(conf, sql, args); assertTrue(builder != null); if (msg != null) { fail("Was expecting the error message: " + msg); } } catch (Throwable th) { if (msg != null) { assertEquals(msg, th.getMessage()); } else { throw th; } } }
public final native JsArrayMixed getArray(Object id) /*-{ var r = this[id]; if (Object.prototype.toString.call(r) == '[object Array]') { return r; } return null; }-*/;
/** * @see #all(ArrayOf) * @deprecated use {@link PromiseProvider#all2(Promise[])} */ @Deprecated public static final JsPromise<JsArrayMixed> all(final Promise<?>... promises) { final JsArrayOf<Promise<?>> promisesArray = JavaScriptObject.createArray().cast(); for (final Promise<?> promise : promises) { promisesArray.push(promise); } return all(promisesArray); }
/** {@inheritDoc} */ @Override public Promise<JsArrayMixed> all(Promise<?>... promises) { final JsArrayOf<Promise<?>> promisesArray = JavaScriptObject.createArray().cast(); for (final Promise<?> promise : promises) { promisesArray.push(promise); } return all(promisesArray); }
protected List<GitHubUser> toOrgList(JsArrayMixed arg) { List<GitHubUser> organizations = dtoFactory.createListDtoFromJson(arg.getObject(1).toString(), GitHubUser.class); organizations.add(dtoFactory.createDtoFromJson(arg.getObject(0).toString(), GitHubUser.class)); return organizations; }
@Override public void add(int index, JavaScriptObject element) { JsArrayMixed args = JavaScriptObject.createArray().cast(); args.push(index); args.push(0); args.push(element); splice.apply(data, args); }
@Override public JavaScriptObject remove(int index) { JavaScriptObject res = data.<JsArrayMixed> cast().getObject(index); if(res != null){ JsArrayMixed args = JavaScriptObject.createArray().cast(); args.push(index); args.push(1); splice.apply(data, args); } return res; }
private void showCompletionProposals(final List<String> proposals, final CMPositionOverlay from, final CMPositionOverlay to) { if (! editorWidget.getEditorOverlay().hasShowHint() || proposals == null || proposals.isEmpty()) { // no support for hints or no proposals return; } final CMHintOptionsOverlay hintOptions = createDefaultHintOptions(); final CMHintFunctionOverlay hintFunction = CMHintFunctionOverlay.createFromHintFunction(new HintFunction() { @Override public CMHintResultsOverlay getHints(final CMEditorOverlay editor, final CMHintOptionsOverlay options) { final CMHintResultsOverlay result = CMHintResultsOverlay.create(); final JsArrayMixed list = result.getList(); for (final String proposal: proposals) { final CMCompletionObjectOverlay completionObject = JavaScriptObject.createObject().cast(); completionObject.setText(proposal); final CMRenderFunctionOverlay renderFunc = createRenderHintFunc(proposal); completionObject.setRender(renderFunc); list.push(completionObject); } result.setFrom(from); result.setTo(to); return result; } }); hintOptions.setHint(hintFunction); editorWidget.getEditorOverlay().showHint(hintOptions); }
private Object get(JsArrayMixed args, int i) { if (isNull(args, i)) { return i; } else if (isDate(args, i)) { return getDate(args, i); } else if (isString(args, i)) { return args.getString(i); } else if (isNumber(args, i)) { return args.getNumber(i); } throw new RuntimeException("Unable to handle value " + debugString(args, i)); }
public List<Object> toList(JsArrayMixed args) { List<Object> result = new ArrayList<Object>(); if (args != null) { for (int i = 0; i < args.length(); i++) { result.add(get(args, i)); } } return result; }
@JsExport("$wnd.redQueryBuilder") static CommandBuilder configure(JsConfiguration config, String sql, JsArrayMixed args) throws Exception { if (config == null) { throw new IllegalArgumentException("Config is null."); } RedQueryBuilder rqb = new RedQueryBuilder(); return rqb.install(config, sql, JsList.get().toList(args)); }
public void testJsList() throws Throwable { JsDate dateIn = JsDate.create(); dateIn.setUTCFullYear(1914); dateIn.setUTCMonth(4); dateIn.setUTCDate(15); dateIn.setUTCHours(22); dateIn.setUTCMinutes(13); JsArrayMixed mixed = (JsArrayMixed) JsArrayMixed.createArray(); mixed.push(dateIn); mixed.push(new Double(123.12d)); mixed.push("123"); mixed.push("false"); List<Object> list = JsList.get().toList(mixed); Date dateOut = (Date) list.get(0); Date dateOutUtc = new Date(dateOut.getTime() + 60 * 1000 * dateOut.getTimezoneOffset()); assertEquals(14, dateOutUtc.getYear()); assertEquals(4, dateOutUtc.getMonth()); assertEquals(15, dateOutUtc.getDate()); assertEquals(22, dateOutUtc.getHours()); assertEquals(13, dateOutUtc.getMinutes()); assertEquals(new Double(123.12d), list.get(1)); assertEquals("123", list.get(2)); assertEquals("false", list.get(3)); }
public void testNextJavaScriptObjectNoRootArray() { // safeEval JsonReader reader = newJsonReader( " {\"name\":\"wrapper\",\"jso\": [\"Bob\",\"Morane\", true, null, 145] } " ); reader.beginObject(); assertEquals( "name", reader.nextName() ); assertEquals( "wrapper", reader.nextString() ); assertEquals( "jso", reader.nextName() ); JsArrayMixed array = reader.nextJavaScriptObject( true ).cast(); assertEquals( 5, array.length() ); assertEquals( "Bob", array.getString( 0 ) ); assertEquals( "Morane", array.getString( 1 ) ); assertTrue( array.getBoolean( 2 ) ); assertNull( array.getObject( 3 ) ); assertEquals( 145d, array.getNumber( 4 ) ); reader.endObject(); assertEquals( JsonToken.END_DOCUMENT, reader.peek() ); // unsafeEval reader = newJsonReader( " {\"jso\": [\"Bob\",\"Morane\", true, 145] ,\"name\":\"wrapper\" } " ); reader.beginObject(); assertEquals( "jso", reader.nextName() ); array = reader.nextJavaScriptObject( false ).cast(); assertEquals( 4, array.length() ); assertEquals( "Bob", array.getString( 0 ) ); assertEquals( "Morane", array.getString( 1 ) ); assertTrue( array.getBoolean( 2 ) ); assertEquals( 145d, array.getNumber( 3 ) ); assertEquals( "name", reader.nextName() ); assertEquals( "wrapper", reader.nextString() ); reader.endObject(); assertEquals( JsonToken.END_DOCUMENT, reader.peek() ); }
private void testExtent() { JsArrayMixed result = Arrays.extent(Array.fromDoubles(6.0, 1456.5, 42, 5.0)); assertEquals(5.0, result.getNumber(0)); assertEquals(1456.5, result.getNumber(1)); // TODO: extent with ObjectAccessor }
/** * Creates a new toolbar group. * * @param name * @param buttons * @return */ static final JsArrayMixed newToolbarGroup(String name, ToolbarButton... buttons) { JsArrayString arr = JavaScriptObject.createArray().cast(); for (ToolbarButton button : buttons) { arr.push(button.getId()); } return getToolbarGroup(name, arr); }
/** * Builds the toolbar. * * @param toolbarGroups * @return */ static final native JsArrayMixed buildToolbar(JsArrayMixed... toolbarGroups) /*-{ var arr = []; for (var i = 0; i < toolbarGroups.length; i++) { arr.push(toolbarGroups[i]); } return arr; }-*/;
private native JsArrayMixed makectx() /*-{ return []; }-*/;
/** {@inheritDoc} */ @Override public native Promise<JsArrayMixed> all(ArrayOf<Promise<?>> promises) /*-{ return Promise.all(promises); }-*/;
/** * Deletes the given resources and its descendants in the standard manner from file system. Method * requires a confirmation from the user before resource will be removed. * * @param needConfirmation true if confirmation is need * @param resources the resources to delete * @return the {@link Promise} with void if removal has successfully completed * @see #delete(Resource...) */ public Promise<Void> delete(boolean needConfirmation, Resource... resources) { checkArgument(resources != null, "Null resource occurred"); checkArgument(resources.length > 0, "No resources were provided to remove"); final Resource[] filtered = filterDescendants(resources); if (!needConfirmation) { Promise<?>[] deleteAll = new Promise<?>[resources.length]; for (int i = 0; i < resources.length; i++) { deleteAll[i] = resources[i].delete(); } return promiseProvider .all(deleteAll) .then( new Function<JsArrayMixed, Void>() { @Override public Void apply(JsArrayMixed arg) throws FunctionException { return null; } }); } List<Resource> projectsList = newArrayList(); for (Resource resource : filtered) { if (resource.getResourceType() == PROJECT) { projectsList.add(resource); } } Resource[] projects = projectsList.toArray(new Resource[projectsList.size()]); if (projectsList.isEmpty()) { // if no project were found in nodes list return promptUserToDelete(filtered); } else if (projects.length < filtered.length) { // inform user that we can't delete mixed list of the nodes return promiseProvider.reject( JsPromiseError.create(localization.mixedProjectDeleteMessage())); } else { // delete only project nodes return promptUserToDelete(projects); } }
private ConfirmCallback onConfirm( final Resource[] resources, final AsyncCallback<Void> callback) { return new ConfirmCallback() { @Override public void accepted() { if (resources == null) { // sometimes we may occur NPE here while reading length callback.onFailure(new IllegalStateException()); return; } Promise<?>[] deleteAll = new Promise<?>[resources.length]; for (int i = 0; i < resources.length; i++) { final Resource resource = resources[i]; deleteAll[i] = resource .delete() .catchError( new Operation<PromiseError>() { @Override public void apply(PromiseError error) throws OperationException { notificationManager.notify( "Failed to delete '" + resource.getName() + "'", error.getMessage(), FAIL, StatusNotification.DisplayMode.FLOAT_MODE); } }); } promiseProvider .all(deleteAll) .then( new Operation<JsArrayMixed>() { @Override public void apply(JsArrayMixed arg) throws OperationException { callback.onSuccess(null); } }); } }; }
protected void onSuccessRequest(JsArrayMixed arg) { onListLoaded(toOrgList(arg), toRepoList(arg)); showProcessing(false); }
protected List<GitHubRepository> toRepoList(JsArrayMixed arg) { return dtoFactory.createListDtoFromJson(arg.getObject(2).toString(), GitHubRepository.class); }
@Override public boolean add(JavaScriptObject e) { data.<JsArrayMixed> cast().push(e); return true; }
@Override public void clear() { data.<JsArrayMixed> cast().setLength(0); }
private native String getString0(JsArrayMixed jso, int index) /*-{ var value = jso[index]; return (value==null||value==undefined) ? null : value; }-*/;
public final native JsArrayMixed getList() /*-{ return this.list; }-*/;
public final native void setList(JsArrayMixed list) /*-{ this.list = list; }-*/;
@Override public void addGutterItem(final int line, final String gutterId, final Element element, final LineNumberingChangeCallback lineCallback) { // condition reversed from the other methods here if (GUTTER_MAP.isProtectedLogical(gutterId)) { return; } this.editorOverlay.setGutterMarker(line, GUTTER_MAP.logicalToCm(gutterId), element); this.codeMirror.on(editorOverlay, EventTypes.CHANGE, new EventHandlerMixedParameters() { @Override public void onEvent(final JsArrayMixed params) { // 0->editor, 1->event object final CMChangeEventOverlay event = params.getObject(1); final JsArrayString newText = event.getText(); final CMPositionOverlay from = event.getFrom(); final CMPositionOverlay to = event.getTo(); // if the first character of the line is not included, the (potential) line // numbering change only starts at the following line. int changeStart = from.getLine() + 1; int removedCount = 0; if (from.getLine() != to.getLine()) { // no lines were removed // don't count first line yet removedCount = Math.abs(from.getLine() - to.getLine()) - 1; if (from.getCharacter() == 0) { // start of first line is included, 'to' is on another line, so the line is deleted removedCount = removedCount + 1; changeStart = changeStart - 1; } // if 'to' is at the end of the line, the line is _not_ removed, just emptied } // else no lines were removed final int addedCount = newText.length() - 1; // only call back if there is a change in the lines if (removedCount > 0 || addedCount > 0) { LOG.fine("Line change from l." + changeStart + " removed " + removedCount + " added " + addedCount); lineCallback.onLineNumberingChange(changeStart, removedCount, addedCount); } } }); }
public void showCompletionProposals(final List<CompletionProposal> proposals, final AdditionalInfoCallback additionalInfoCallback) { if (! editorWidget.getEditorOverlay().hasShowHint() || proposals == null || proposals.isEmpty()) { // no support for hints or no proposals return; } final CMHintOptionsOverlay hintOptions = createDefaultHintOptions(); final CMHintFunctionOverlay hintFunction = CMHintFunctionOverlay.createFromHintFunction(new HintFunction() { @Override public CMHintResultsOverlay getHints(final CMEditorOverlay editor, final CMHintOptionsOverlay options) { final CMHintResultsOverlay result = CMHintResultsOverlay.create(); final JsArrayMixed list = result.getList(); for (final CompletionProposal proposal: proposals) { final CMHintApplyOverlay hintApply = createApplyHintFunc(proposal); final CMRenderFunctionOverlay renderFunc = createRenderHintFunc(proposal, additionalInfoCallback); final CMCompletionObjectOverlay completionObject = JavaScriptObject.createObject().cast(); completionObject.setHint(hintApply); completionObject.setRender(renderFunc); setAdditionalInfo(completionObject, proposal.getAdditionalProposalInfo()); list.push(completionObject); } result.setFrom(editor.getDoc().getCursor()); setupShowAdditionalInfo(result, additionalInfoCallback); return result; } }); hintOptions.setHint(hintFunction); editorWidget.getEditorOverlay().showHint(hintOptions); }
public void showCompletionProposals(final CompletionsSource completionsSource, final AdditionalInfoCallback additionalInfoCallback) { if (! editorWidget.getEditorOverlay().hasShowHint()) { // no support for hints return; } if (completionsSource == null) { showCompletionProposals(); } final CMHintOptionsOverlay hintOptions = createDefaultHintOptions(); final CMHintFunctionOverlay hintFunction = CMHintFunctionOverlay.createFromAsyncHintFunction(new AsyncHintFunction() { @Override public void getHints(final CMEditorOverlay editor, final CMHintCallback callback, final CMHintOptionsOverlay options) { completionsSource.computeCompletions(new CompletionReadyCallback() { @Override public void onCompletionReady(final List<CompletionProposal> proposals) { final CMHintResultsOverlay result = CMHintResultsOverlay.create(); final JsArrayMixed list = result.getList(); for (final CompletionProposal proposal: proposals) { final CMHintApplyOverlay hintApply = createApplyHintFunc(proposal); final CMRenderFunctionOverlay renderFunc = createRenderHintFunc(proposal, additionalInfoCallback); final CMCompletionObjectOverlay completionObject = JavaScriptObject.createObject().cast(); completionObject.setHint(hintApply); completionObject.setRender(renderFunc); setAdditionalInfo(completionObject, proposal.getAdditionalProposalInfo()); list.push(completionObject); } result.setFrom(editor.getDoc().getCursor()); setupShowAdditionalInfo(result, additionalInfoCallback); callback.call(result); } }); } }); // set the async hint function and trigger the delayed display of hints hintOptions.setHint(hintFunction); editorWidget.getEditorOverlay().showHint(hintOptions); }
private void setupShowAdditionalInfo(final CMHintResultsOverlay data, final AdditionalInfoCallback additionalInfoCallback) { if (additionalInfoCallback != null) { final CodeMirrorOverlay codeMirror = editorWidget.getCodeMirror(); final Element bodyElement = Elements.getBody(); codeMirror.on(data, EventTypes.COMPLETION_SELECT, new EventHandlers.EventHandlerMixedParameters() { @Override public void onEvent(final JsArrayMixed param) { // param 0 -> completion object (string or object) final CMCompletionObjectOverlay completionObject = param.getObject(0); // param 1 -> DOM node in the menu final JsElement itemElement = param.getObject(1); final ClientRect itemRect = itemElement.getBoundingClientRect(); Element popup = itemElement; while (popup.getParentElement() != null && ! popup.getParentElement().equals(bodyElement)) { popup = popup.getParentElement(); } final ClientRect popupRect = popup.getBoundingClientRect(); final float pixelX = Math.max(itemRect.getRight(), popupRect.getRight()); final float pixelY = itemRect.getTop(); final Element info = getAdditionalInfo(completionObject); // there can be only one // remove any other body child with the additional info marker removeStaleInfoPopups(ADDITIONAL_INFO_MARKER); // Don't show anything if there is no additional info if (info == null) { return; } final Element infoDisplayElement = additionalInfoCallback.onAdditionalInfoNeeded(pixelX, pixelY, info); // set the additional info marker on the popup element infoDisplayElement.getClassList().add(ADDITIONAL_INFO_MARKER); } }); // close the additional info along with the completion popup codeMirror.on(data, EventTypes.COMPLETION_CLOSE, new EventHandlers.EventHandlerNoParameters() { @Override public void onEvent() { delayedRemoveStaleInfoPopups(ADDITIONAL_INFO_MARKER); } }); } }