List of usage examples for org.apache.wicket Application get
public static Application get()
From source file:com.googlecode.wicket.jquery.ui.calendar.CalendarModelBehavior.java
License:Apache License
/** * Gets the new {@link IRequestHandler} that will respond the list of {@link CalendarEvent} in a json format * * @return the {@link IRequestHandler}//from w w w . j ava 2 s . com */ private IRequestHandler newRequestHandler() { return new IRequestHandler() { @Override public void respond(final IRequestCycle requestCycle) { WebResponse response = (WebResponse) requestCycle.getResponse(); final String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding(); response.setContentType("text/json; charset=" + encoding); response.disableCaching(); if (model != null) { List<? extends CalendarEvent> list = model.getObject(); // calls load() if (list != null) { StringBuilder builder = new StringBuilder("[ "); int count = 0; for (CalendarEvent event : list) { if (model instanceof ICalendarVisitor) { event.accept((ICalendarVisitor) model); //last chance to set options } if (count++ > 0) { builder.append(", "); } builder.append(event.toString()); } builder.append(" ]"); LOG.debug(builder.toString()); response.write(builder); } } } @Override public void detach(final IRequestCycle requestCycle) { } }; }
From source file:com.googlecode.wicket.jquery.ui.form.autocomplete.AutoCompleteSourceBehavior.java
License:Apache License
/** * Gets a new {@link IRequestHandler} that will call {@link #getChoices(String)} and will build be JSON response corresponding to the specified 'input' argument. * @param input user input//from w ww .ja va2s .c om * @return a new {@link IRequestHandler} */ private IRequestHandler newRequestHandler(final String input) { return new IRequestHandler() { @Override public void respond(final IRequestCycle requestCycle) { WebResponse response = (WebResponse) requestCycle.getResponse(); final String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding(); response.setContentType("text/json; charset=" + encoding); response.disableCaching(); List<T> choices = AutoCompleteSourceBehavior.this.getChoices(input); List<String> properties = AutoCompleteSourceBehavior.this.getProperties(); if (choices != null) { StringBuilder builder = new StringBuilder("[ "); int index = 0; for (T choice : choices) { if (index++ > 0) { builder.append(", "); } builder.append("{ "); builder.append(Options.QUOTE).append("id").append(Options.QUOTE).append(": ") .append(Options.QUOTE).append(Integer.toString(index)) .append(Options.QUOTE); /* id is a reserved word */ builder.append(", "); builder.append(Options.QUOTE).append("value").append(Options.QUOTE).append(": ") .append(Options.QUOTE).append(renderer.getText(choice)) .append(Options.QUOTE); /* value is a reserved word */ if (properties != null) { for (String property : properties) { builder.append(", "); builder.append(Options.QUOTE).append(property).append(Options.QUOTE).append(": ") .append(Options.QUOTE).append(renderer.getText(choice, property)) .append(Options.QUOTE); } } builder.append(" }"); } builder.append(" ]"); response.write(builder); } } @Override public void detach(final IRequestCycle requestCycle) { } }; }
From source file:com.googlecode.wicket.jquery.ui.kendo.datatable.DataSourceBehavior.java
License:Apache License
/** * Gets the new {@link IRequestHandler} that will respond the data in a json format * * @param first the first row number/*from w w w . ja v a 2s . c om*/ * @param count the count of rows * @return a new {@link IRequestHandler} */ private IRequestHandler newRequestHandler(final int first, final int count) { return new IRequestHandler() { @Override public void respond(final IRequestCycle requestCycle) { WebResponse response = (WebResponse) requestCycle.getResponse(); final String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding(); response.setContentType("text/json; charset=" + encoding); response.disableCaching(); final long size = provider.size(); final Iterator<? extends T> iterator = provider.iterator(first, count); // builds JSON result // StringBuilder builder = new StringBuilder(); builder.append("{ "); builder.append(Options.QUOTE).append("__count").append(Options.QUOTE).append(": ").append(size) .append(", "); builder.append(Options.QUOTE).append("results").append(Options.QUOTE).append(": "); builder.append("[ "); for (int index = 0; iterator.hasNext(); index++) { if (index > 0) { builder.append(", "); } builder.append(DataSourceBehavior.this.newJsonRow(iterator.next())); } builder.append(" ] }"); response.write(builder); } @Override public void detach(final IRequestCycle requestCycle) { } }; }
From source file:com.googlecode.wicket.jquery.ui.kendo.KendoAbstractBehavior.java
License:Apache License
/** * Gets the {@link IKendoUILibrarySettings} * * @return null if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link IKendoUILibrarySettings} *//*from w w w . j a va 2s . co m*/ private static IKendoUILibrarySettings getLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof IKendoUILibrarySettings)) { return (IKendoUILibrarySettings) Application.get().getJavaScriptLibrarySettings(); } return KendoUILibrarySettings.get(); }
From source file:com.googlecode.wicket.jquery.ui.plugins.emoticons.EmoticonsBehavior.java
License:Apache License
/** * Gets the {@link IEmoticonsLibrarySettings} * * @return Default {@link IEmoticonsLibrarySettings} if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link IEmoticonsLibrarySettings} *//*from www. ja va 2 s . com*/ private static IEmoticonsLibrarySettings getLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof IEmoticonsLibrarySettings)) { return (IEmoticonsLibrarySettings) Application.get().getJavaScriptLibrarySettings(); } return EmoticonsLibrarySettings.get(); }
From source file:com.googlecode.wicket.jquery.ui.plugins.fixedheadertable.FixedHeaderTableBehavior.java
License:Apache License
/** * Gets the {@link IFixedHeaderTableLibrarySettings} * * @return null if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link IFixedHeaderTableLibrarySettings} *///from w ww. j a v a2 s. c o m private static IFixedHeaderTableLibrarySettings getLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof IFixedHeaderTableLibrarySettings)) { return (IFixedHeaderTableLibrarySettings) Application.get().getJavaScriptLibrarySettings(); } return FixedHeaderTableLibrarySettings.get(); }
From source file:com.googlecode.wicket.jquery.ui.plugins.sfmenu.SfMenuBehavior.java
License:Apache License
/** * Gets the {@link ISuperfishLibrarySettings} * * @return Default internal {@link ISuperfishLibrarySettings} if {@link Application}'s {@link IJavaScriptLibrarySettings} is not an instance of {@link ISuperfishLibrarySettings} *//*w w w. j av a 2 s.co m*/ private static ISuperfishLibrarySettings getLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof ISuperfishLibrarySettings)) { return (ISuperfishLibrarySettings) Application.get().getJavaScriptLibrarySettings(); } return SuperfishLibrarySettings.get(); }
From source file:com.googlecode.wicket.jquery.ui.plugins.whiteboard.WhiteboardBehavior.java
License:Apache License
protected void respond(final AjaxRequestTarget target) { RequestCycle cycle = RequestCycle.get(); WebRequest webRequest = (WebRequest) cycle.getRequest(); if (webRequest.getQueryParameters().getParameterValue("editedElement").toString() != null) { String editedElement = webRequest.getQueryParameters().getParameterValue("editedElement").toString(); try {/*from ww w. ja va 2s .co m*/ if (snapShot == null && snapShotCreation == null) { snapShot = new ArrayList<Element>(); snapShotCreation = new ArrayList<Boolean>(); } //Mapping JSON String to Objects and Adding to the Element List JSONObject jsonEditedElement = new JSONObject(editedElement); Element element = getElementObject(jsonEditedElement); if (elementMap.containsKey(element.getId()) && !elementMap.isEmpty()) { snapShot.add(elementMap.get(element.getId())); snapShotCreation.add(false); } else { snapShot.add(element); snapShotCreation.add(true); } if (!"PointFree".equals(element.getType())) { if (undoSnapshots.size() == 20) { undoSnapshots.pollFirst(); undoSnapshotCreationList.pollFirst(); } if ("PencilCurve".equals(element.getType())) { ArrayList<Element> lastElementSnapshot = undoSnapshots.getLast(); Element lastSnapshotElement = lastElementSnapshot.get(lastElementSnapshot.size() - 1); if ((lastSnapshotElement instanceof PencilCurve) && (lastSnapshotElement.getId() == element.getId())) { ArrayList<Boolean> lastCreationSnapshot = undoSnapshotCreationList.getLast(); for (int i = 0; i < snapShot.size(); i++) { lastElementSnapshot.add(snapShot.get(i)); lastCreationSnapshot.add(snapShotCreation.get(i)); } } else { undoSnapshots.addLast(snapShot); undoSnapshotCreationList.addLast(snapShotCreation); } } else { undoSnapshots.addLast(snapShot); undoSnapshotCreationList.addLast(snapShotCreation); } snapShot = null; snapShotCreation = null; } // Synchronizing newly added element between whiteboards if (element != null) { elementMap.put(element.getId(), element); IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONObject jsonObject = new JSONObject(editedElement); c.sendMessage(getAddElementMessage(jsonObject).toString()); } catch (Exception e) { e.printStackTrace(); } } } } catch (JSONException e) { e.printStackTrace(); } } else if (webRequest.getQueryParameters().getParameterValue("undo").toString() != null) { if (!undoSnapshots.isEmpty()) { ArrayList<Boolean> undoCreationList = undoSnapshotCreationList.pollLast(); ArrayList<Element> undoElement = undoSnapshots.pollLast(); String deleteList = ""; JSONArray changeList = new JSONArray(); IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (int i = 0; i < undoElement.size(); i++) { if (undoCreationList.get(i)) { elementMap.remove(undoElement.get(i).getId()); if ("".equals(deleteList)) { deleteList = "" + undoElement.get(i).getId(); } else { deleteList += "," + undoElement.get(i).getId(); } } else { elementMap.put(undoElement.get(i).getId(), undoElement.get(i)); changeList.put(undoElement.get(i).getJSON()); } } for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { c.sendMessage(getUndoMessage(changeList, deleteList).toString()); } catch (Exception e) { e.printStackTrace(); } } } } else if (webRequest.getQueryParameters().getParameterValue("eraseAll").toString() != null) { elementMap.clear(); IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); c.sendMessage(getWhiteboardMessage(jsonArray).toString()); } catch (Exception e) { e.printStackTrace(); } } } else if (webRequest.getQueryParameters().getParameterValue("save").toString() != null) { JSONArray elementArray = new JSONArray(); for (int elementID : elementMap.keySet()) { elementArray.put(elementMap.get(elementID).getJSON()); } DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); Date date = new Date(); File whiteboardFile = new File("Whiteboard_" + dateFormat.format(date) + ".json"); FileWriter writer = null; try { whiteboardFile.createNewFile(); System.out.println(whiteboardFile.getAbsolutePath()); writer = new FileWriter(whiteboardFile); writer.write(elementArray.toString()); writer.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } else if (webRequest.getQueryParameters().getParameterValue("clipArt").toString() != null) { IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); jsonArray.put("http://icons.iconarchive.com/icons/femfoyou/angry-birds/64/angry-bird-icon.png"); jsonArray.put( "http://icons.iconarchive.com/icons/femfoyou/angry-birds/64/angry-bird-yellow-icon.png"); c.sendMessage(getClipArtListMessage(jsonArray).toString()); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:com.googlecode.wicket.jquery.ui.plugins.whiteboard.WhiteboardBehavior.java
License:Apache License
public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); initReferences(response);/*from w w w . ja v a 2 s. c om*/ String callbackUrl = getCallbackUrl().toString(); String whiteboardInitializeScript = "" + "callbackUrl='" + callbackUrl + "';\n" + "whiteboard = bay.whiteboard.Create();\n" + "elementCollection=whiteboard.getMainCollection();\n" + "whiteboard.getMainCollection().onChange = function(element){\n" + "changedElement=this.getJson(element);\n" + "Wicket.Ajax.get({u:'" + callbackUrl + "',ep:{editedElement:changedElement}});\n};\n" + "whiteboard.render(document.getElementById('" + whiteboardId + "'));\n" + "whiteboard.setBoundaries(0, 0, 0, 0);\n"; //Clearing the whiteboard for first client IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()).getConnectionRegistry(); // if(reg.getConnections(Application.get()).size()==0){ // elementMap.clear(); // } //Loading existing content for clients join after first one if (!elementMap.isEmpty()) { Map<Integer, Element> sortedElementList = new TreeMap<Integer, Element>(elementMap); JSONArray jsonArray = new JSONArray(); for (Element e : sortedElementList.values()) { jsonArray.put(e.getJSON()); } whiteboardInitializeScript += "elementCollection.parseJson('" + jsonArray.toString() + "');"; } response.render(OnDomReadyHeaderItem.forScript(whiteboardInitializeScript)); }
From source file:com.googlecode.wicket.jquery.ui.plugins.whiteboard.WhiteboardBehavior.java
License:Apache License
private static IWhiteboardLibrarySettings getLibrarySettings() { if (Application.exists() && (Application.get().getJavaScriptLibrarySettings() instanceof IWhiteboardLibrarySettings)) { return (IWhiteboardLibrarySettings) Application.get().getJavaScriptLibrarySettings(); }//from ww w . ja va 2 s . com return null; }