private static String getTag(OgemaWidget widget) { return "<div class=\"ogema-widget\" id=\"" + widget.getId() + "\"></div>"; }
@Override default String getId(T object) { return object instanceof OgemaWidget ? ((OgemaWidget) object).getId() : String.valueOf(object); }
@SuppressWarnings("unchecked") public final <T extends WidgetData> T getWidgetData(OgemaWidget widget) { String widgetId = widget.getId(); T opt = (T) widgets.get(widgetId); if (opt != null) return opt; opt = ((OgemaWidgetBase<T>) widget).createNewSession(); widgets.putIfAbsent(widgetId, opt); return (T) widgets.get(widgetId); }
void removeTriggerAction(OgemaWidget target, String triggeringAction, String triggeredAction, Object[] args) { String widgetID2 = target.getId(); for(int i=globalConnectElements.size()-1; i>=0; i--) { Map<String,Object> cnObj = globalConnectElements.get(i); if(id.equals(cnObj.get("widgetID1")) && widgetID2.equals(cnObj.get("widgetID2")) && triggeringAction.equals(cnObj.get("triggeringAction")) && triggeredAction.equals(cnObj.get("triggeredAction"))) { globalConnectElements.remove(cnObj); break; } } } @Override
default JSONObject serialize(Object item) { final JSONObject json = new JSONObject(); final int type = item instanceof OgemaWidget ? 2 : item instanceof HtmlItem ? 1 : 0; json.put("type", type); final String content = type == 2 ? ((OgemaWidget) item).getId() : type == 1 ? ((HtmlItem) item).getHtml() : StringEscapeUtils.escapeHtml4(String.valueOf(item)); json.put("content", content); return json; }
private static final JSONObject mapToJsonHeader(Map.Entry<String,Object> header) { final JSONObject json = new JSONObject(); final Object val = header.getValue(); final String value = val instanceof OgemaWidget ? ((OgemaWidget) val).getId() : val.toString(); json.put("type", val instanceof OgemaWidget ? ContentType.OGEMA_WIDGET.getType() : ContentType.TEXT.getType()); json.put("content", value); json.put("row", DynamicTable.HEADER_ROW_ID); json.put("col", header.getKey()); return json; }
final OgemaWidget parent, final OgemaHttpRequest req) { if (a instanceof FloatArrayResource) { final ValueInputField<Float> in= new ValueInputField<Float>(parent, parent.getId() + "_" + i, Float.class, req) { final ValueInputField<Integer> in= new ValueInputField<Integer>(parent, parent.getId() + "_" + i, Integer.class, req) { final Checkbox2 in= new Checkbox2(parent, parent.getId() + "_" + i, req) { final ValueInputField<Long> in= new ValueInputField<Long>(parent, parent.getId() + "_" + i, Long.class, req) {
private void printPageWidgets(WidgetPage<?> page) { System.out.println("Widgets for page " + page.getFullUrl()); List<OgemaWidget> widgets = widgetAdminService.getPageWidgets(page); for (OgemaWidget w: widgets ) { // TODO print widget type System.out.printf(" Id: %-20s type: %-30s\n", w.getId() + ",", w.getClass() ); } System.out.println(); }
void triggerAction(OgemaWidget target, String triggeringAction, String triggeredAction, Object[] args, int level) { Map<String,Object> cncObj = new LinkedHashMap<String, Object>(); String widgetID2 = target.getId(); cncObj.put("widgetID1", id); cncObj.put("widgetID2", widgetID2); cncObj.put("triggeringAction", triggeringAction); cncObj.put("triggeredAction", triggeredAction); if (args != null) { cncObj.put("args", args); } cncObj.put("level", level); globalConnectElements.add(cncObj); page.app.getWidgetService().update(this); }
void removeTriggerAction(OgemaWidget target) { String widgetID2 = target.getId(); writeLock(); try { final Iterator<Map<String,Object>> it = connectElements.iterator(); while (it.hasNext()) { final String w2 = (String) it.next().get("widgetID2"); if (widgetID2.equals(w2)) { it.remove(); break; } } } finally { writeUnlock(); } }
/** * Remove the subwidget from the items list, and destroy it * @param widget * @return */ public boolean removeItem(OgemaWidget widget) { if (widget == null) return false; boolean result = items.remove(widget); widget.destroyWidget(); removeCSSItems("#" + widget.getId() + ".ogema-widget"); return result; }
void triggerAction(OgemaWidget target, String triggeringAction, String triggeredAction, Object[] args, int level) { String widgetID2 = target.getId(); Map<String,Object> cncObj = new LinkedHashMap<String, Object>(); cncObj.put("widgetID1", id); cncObj.put("widgetID2", widgetID2); cncObj.put("triggeringAction", triggeringAction); cncObj.put("triggeredAction", triggeredAction); cncObj.put("level", level); if (args != null) { cncObj.put("args", args); } writeLock(); try { connectElements.add(cncObj); } finally { writeUnlock(); } }
public OgemaWidget removeItem(int position) throws IndexOutOfBoundsException { OgemaWidget w = items.remove(position); if (w != null) { w.destroyWidget(); removeCSSItems("#" + w.getId() + ".ogema-widget"); } return w; }
/** * Set the "flex-grow" property for an item. This specifies how leftover whitespace is distributed to * the items; if item1 has flex-grow = 2 and item2 has flex-grow = 1, then item1 will receive twice as much * whitespace as item2. * * @param value * a positive integer * @param item * a widget that has been previously added as a sub-item to the Flexbox * ({@link #addItem(OgemaWidget)}). * @throws IllegalArgumentException * if the item has not been added yet, or the value is negative */ public void setFlexGrow(int value, OgemaWidget item) throws IllegalArgumentException { if (value < 0) throw new IllegalArgumentException("Value must be positive, got " + value); if (item == null) { final Map<String,String> css = Collections.singletonMap("flex-grow", String.valueOf(value)); addCssItem(">div:last-child", css); return; } Objects.requireNonNull(item); if (!items.contains(item)) throw new IllegalArgumentException("Item " + item + " must be added to items list before the flex grow property can be set"); final Map<String,String> css = Collections.singletonMap("flex-grow", String.valueOf(value)); addCssItem("#" + item.getId() + ".ogema-widget", css); }
html.append(getTag(innerWidgets.get(i))); } catch(NullPointerException e) { throw new IllegalStateException("Widget "+appendWidget.getId()+" not initialized correctly!");
private static JSONObject toJson(final String itemId, String colId, final Object o) { final JSONObject json = new JSONObject(); if (o instanceof OgemaWidget) { json.put("type", ContentType.OGEMA_WIDGET.getType()); json.put("content", ((OgemaWidget) o).getId()); } else if (o instanceof String) { json.put("type", ContentType.TEXT.getType()); json.put("content", o); } else { json.put("type", ContentType.EMPTY.getType()); json.put("content", ""); } if (itemId != null) json.put("row", itemId); if (colId != null) json.put("col", colId); return json; }
public void removeSessionWidget(String sessionId, OgemaWidget w) { Session session = sessionManagement.getSession(sessionId); if (session != null) { session.removeWidget(w.getId()); } }
/** * Set a minimum margin for one of the items. * * @param direction * either null for all four, or one of "left", "right", "top", "bottom". * @param size * a CSS size specifier, like "10px" * @param item * a widget that has been previously added as a sub-item to the Flexbox * ({@link #addItem(OgemaWidget)}). * @throws IllegalArgumentException * if the item has not been added yet, or the direction parameter is invalid. */ public void setMargin(String direction, String size, OgemaWidget item) throws IllegalArgumentException { Objects.requireNonNull(item); Objects.requireNonNull(size); if (!items.contains(item)) throw new IllegalArgumentException("Item " + item + " must be added to items list before a margin can be set"); checkDirectionString(direction); Map<String,String> css = new HashMap<String, String>(); String prop = "margin"; if (direction != null && !direction.isEmpty()) prop += "-" + direction; css.put(prop, size); addCssItem("#" + item.getId() + ".ogema-widget", css); }
protected void init() { dependentWidgets = widget.getPage().registerWidgetGroup(widget.getId() + "__dependentWidgets", new ArrayList<OgemaWidget>()); // widget.triggerAction(dependentWidgets, TriggeringAction.POST_REQUEST, TriggeredAction.GET_REQUEST); widget.triggerAction(dependentWidgets, TriggeringAction.GET_REQUEST, TriggeredAction.GET_REQUEST); // XXX why? }
public void removeWidget(OgemaWidget widget) { String widgetId = widget.getId(); WidgetPage<?> page = widget.getPage(); // String boundPagePath = ((WidgetPageBase<?>) page).getServletBase(); // System.out.println(" session mgt removing widget " + widgetId); // String id = getId(boundPagePath,widgetId); // WidgetSessionData<? extends WidgetData> opt = options.remove(id); for (Session session : sessions.asMap().values()) { if (!session.getPage().getPage().equals(page)) continue; session.removeWidget(widgetId); } }