/** * The MIME-type for this {@link Resource}. */ private static String provideMimeType(SFrame frame) { return "text/html; charset=" + frame.getSession().getCharacterEncoding(); }
/** * {@inheritDoc} */ @Override public boolean stop() { if (super.stop()) { controllerFrame.getSession().exit(); return true; } return false; }
@Override public void processLowLevelEvent(String name, String... values) { focusComponent = null; if (values.length == 1 && name.endsWith("_focus")) { String eventId = values[0]; List listeners = getSession().getDispatcher().getLowLevelEventListener(eventId); for (int i = 0; i < listeners.size() && focusComponent == null; i++) { Object listener = listeners.get(i); if (listener instanceof SComponent) { this.focusComponent = (SComponent)listener; } } } /* * When there is a debug Cookie, * change the debug headers in the CG according to the value of the * cookie. */ if (name.endsWith("_debug")) { log.info("input "+name+ Arrays.toString(values)); String newLogLevel = (values.length == 1) ? values[0] != null ? values[0] : "off" : "off"; logLevel = newLogLevel; } }
/** * {@inheritDoc} */ @Override public boolean stop() { if (super.stop()) { controllerFrame.getSession().exit(); return true; } return false; }
/** * This button allows you to programattically react on Back buttons pressed in the browser itselfs. * This is a convenience method in contrast to {@link #addInvalidLowLevelEventListener(SInvalidLowLevelEventListener)}. * While the listener throws an event on every detected component receiving an invalid * request, this button is only activated if * <ul> * <li>Maximum once per request * <li>Only if some time passed by to avoid double-clicks to be recognized as back button clicks. * </ul> * <b>Note:</b> To work correctly you should set use GET posting * {@link SForm#setPostMethod(boolean)} and use {@link SFrame#setNoCaching(boolean)} for * no caching. This will advise the browser to reload every back page. * * @param defaultBackButton A button to trigger upon detected invalid epochs. */ public void setBackButton(SButton defaultBackButton) { if (backbuttonRequestListener == null) { backbuttonRequestListener = new LastRequestListener(); getSession().addRequestListener(backbuttonRequestListener); } this.backButton = defaultBackButton; }
/** * Create a code resource for the specified frame. * <p>The MIME-type for this frame will be <code>text/html; charset=<i>current encoding</i></code> */ public ReloadResource(final SFrame f) { super(f, "html", provideMimeType(f)); // update session encoding if manually updated in the session. changeListener = evt -> mimeType = provideMimeType(f); f.getSession().addPropertyChangeListener(changeListener); }
/** * Creates a new SFrame */ public SFrame() { getSession().addPropertyChangeListener("lookAndFeel", this); getSession().addPropertyChangeListener("request.url", this); this.visible = false; // Frames are invisible originally. setUpdateEnabled(true); Map<String, Object> updateCursor = new HashMap<>(); SIcon cursorImage = new SResourceIcon("org/wings/icons/AjaxActivityCursor.gif"); updateCursor.put("enabled", true); updateCursor.put("image", cursorImage.getURL().toString()); updateCursor.put("width", cursorImage.getIconWidth()); updateCursor.put("height", cursorImage.getIconHeight()); updateCursor.put("dx", 15); updateCursor.put("dy", 0); setUpdateCursor(updateCursor); Map<String, Object> autoAdjustLayout = new HashMap<>(); autoAdjustLayout.put("enabled", true); autoAdjustLayout.put("delay", 250); setAutoAdjustLayout(autoAdjustLayout); addStyle("yui-skin-sam"); }
/** * Shows or hide this frame. This means it gets (un)registered at the session. * * @see org.wings.session.Session#getFrames() */ @Override public void setVisible(boolean visible) { if (visible != isVisible()) { if (visible) { List newHeaders = new ArrayList(SessionHeaders.getInstance().getHeaders()); for (Object oldHeaders : headers) { if (!newHeaders.contains(oldHeaders)) { newHeaders.add(oldHeaders); } } headers = newHeaders; getSession().addFrame(this); register(); } else { getSession().removeFrame(this); unregister(); } super.setVisible(visible); setRecursivelyVisible(visible); } }
private static void writeGlobalInitScript(Device out, SFrame frame) throws IOException { Map<String, Object> initConfig = new HashMap<>(); initConfig.put("eventEpoch", frame.getEventEpoch()); initConfig.put("reloadResource", frame.getDynamicResource(ReloadResource.class).getURL().toString()); initConfig.put("updateResource", frame.getDynamicResource(UpdateResource.class).getURL().toString()); initConfig.put("updateEnabled", frame.isUpdateEnabled()); initConfig.put("updateCursor", Utils.mapToJsObject(frame.getUpdateCursor())); initConfig.put("autoAdjustLayout", Utils.mapToJsObject(frame.getAutoAdjustLayout())); initConfig.put("cometEnabled", frame.getSession().getComet() != null && frame.getSession().getComet().isCometEnabled()); final String logLevel = SFrame.getLogLevel(); if (logLevel != null && !logLevel.isEmpty()) { initConfig.put("loglevel", logLevel); } out.print("wingS.global.init("); Utils.mapToJsObject(initConfig).write(out); out.print(");"); }
/** * Returns the base URL for a request to the WingsServlet. This URL * is used to assemble an URL that trigger events. In order to be used * for this purpose, you've to add your parameters here. */ @Override public final RequestURL getRequestURL() { // first time we are called, and we didn't get any change yet if (requestURL == null) { requestURL = (RequestURL) getSession().getProperty("request.url"); } RequestURL result = null; if (requestURL != null) { result = (RequestURL) requestURL.clone(); result.setEventEpoch(epochCache); result.setResource(getTargetResource()); } return result; }
public InputMapRequestListener(SFrame frame) { this.frame = frame; frame.putClientProperty("InputMapRequestListener", this); frame.getSession().addRequestListener(e -> { if (e.getType() == SRequestEvent.DELIVER_START && InputMapRequestListener.this.frame.getDynamicResources().contains(e.getRequestedResource().getObject())) { boolean changeDetected = false; Set<SComponent> components = InputMapRequestListener.this.frame.getGlobalInputMapComponents(); for (SComponent component : components) { boolean visible = component.isRecursivelyVisible(); if (!Boolean.valueOf(visible).equals(component.getClientProperty("visible"))) { component.putClientProperty("visible", visible); changeDetected |= true; } } for (SComponent component : components) { if (checkForChange(component, SComponent.WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT)) { changeDetected |= true; } if (checkForChange(component, SComponent.WHEN_IN_FOCUSED_FRAME)) { changeDetected |= true; } } if (changeDetected) { String script = strokes(components); InputMapRequestListener.this.frame.getSession().getScriptManager().addScriptListener(new JavaScriptListener(null, null, script)); } } }); }
try { final SFrame frame = getFrame(); final ReloadManager reloadManager = frame.getSession().getReloadManager(); final ScriptManager scriptManager = frame.getSession().getScriptManager();
protected static void handleScripts(Device device, SComponent component) throws IOException { final SFrame frame = (SFrame) component; final ScriptManager scriptManager = frame.getSession().getScriptManager(); final SToolTipManager tooltipManager = SToolTipManager.sharedInstance(); // hand script listeners of frame to script manager scriptManager.addScriptListeners(frame.getScriptListeners()); device.print("<script type=\"text/javascript\">\n"); // print all scripts writeGlobalInitScript(device, frame); device.print("\n"); writeTooltipInitScript(device, tooltipManager); device.print("\n"); ScriptListener[] scriptListeners = scriptManager.getScriptListeners(); for (ScriptListener scriptListener : scriptListeners) { if (scriptListener.getScript() != null) { device.print(scriptListener.getScript()).print("\n"); } } scriptManager.clearScriptListeners(); device.print("</script>\n"); }
Set menues = frame.getSession().getMenuManager().getMenues(frame); for (Object menue : menues) { SComponent menuItem = (SComponent) menue; DragAndDropManager dndManager = frame.getSession().getDragAndDropManager(); dndManager.getCG().write(device, dndManager);
Set<SComponent> menues = frame.getSession().getMenuManager().getMenues(frame); for (SComponent menuItem : menues) { menuItem.putClientProperty("popup", Boolean.TRUE); DragAndDropManager dndManager = frame.getSession().getDragAndDropManager(); dndManager.getCG().write(device, dndManager); if(frame.getSession().hasSDragAndDropManager()) { SDragAndDropManager sDndManager = frame.getSession().getSDragAndDropManager(); sDndManager.getCG().write(device, sDndManager); SCursor cursor = frame.getSession().getCursor(); if(cursor != null) { CursorCG cg = (CursorCG)cursor.getCG();