/** * gets the redirect URL as workaround for opening a new window or refreshing a window (Noscript * version) */ private String getWindowOpener() { String result = ""; IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); WebForm activeForm = FormManager.getActive(); WebForm[] allForms = FormManager.getAll(); boolean finished = false; for (int i = 0; !finished && i < allForms.length; i++) { WebForm form = allForms[i]; IFormAdapter formAdapter = WebFormUtil.getFormAdapter(form); if (stateInfo.isExpired()) { if (!formAdapter.getWindowOpenerBuffer().equals("")) { result = formAdapter.getWindowOpenerBuffer(); finished = true; } } else { if (WebComponentControl.openInNewWindow(form) || WebComponentControl.refreshWindow(form)) { result = "<meta http-equiv=\"refresh\" content=\"0; url=" + RenderUtil.createEncodedFormGetURL(form) + "\">"; formAdapter.addWindowOpenerBuffer(result); NoscriptFormStack.getInstance().push(activeForm); finished = true; } else { formAdapter.addWindowOpenerBuffer(""); } } } return result; }
public static PhaseId get() { PhaseId result = null; IServiceStore serviceStore = ContextProvider.getServiceStore(); if (serviceStore != null) { result = (PhaseId) serviceStore.getAttribute(ATTR_CURRENT_PHASE); } return result; }
public void testDataEventCheckBox() throws Exception { WebForm form = W4TFixture.getEmptyWebFormInstance(); W4TFixture.fakeBrowser(new Default(true)); final WebDataEvent[] dataEvent = new WebDataEvent[1]; WebDataListener dataListener = new WebDataListener() { public void webValueChanged(final WebDataEvent evt) { dataEvent[0] = evt; } }; WebCheckBox checkBox = new WebCheckBox(); form.add(checkBox, WebBorderLayout.NORTH); assertEquals(UNCHECKED, checkBox.getValue()); checkBox.addWebDataListener(dataListener); checkBox.setValue(CHECKED); assertNull(dataEvent[0]); checkBox.removeWebDataListener(dataListener); checkBox.setValue(UNCHECKED); dataEvent[0] = null; checkBox.addWebDataListener(dataListener); String id = checkBox.getUniqueID(); W4TFixture.fakeRequestParam(id, CHECKED); W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, UNCHECKED); getLifeCycleAdapter(form).readData(); IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); String key = EventQueueFilter.ATTRIBUTE_KEY; EventQueueFilter eqv = (EventQueueFilter) stateInfo.getAttribute(key); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNotNull(dataEvent[0]); assertSame(checkBox, dataEvent[0].getSource()); assertSame(UNCHECKED, dataEvent[0].getOldValue()); assertSame(CHECKED, dataEvent[0].getNewValue()); assertEquals(CHECKED, checkBox.getValue()); dataEvent[0] = null; W4TFixture.fakeRequestParam(checkBox.getUniqueID(), null); W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, CHECKED); getLifeCycleAdapter(form).readData(); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNotNull(dataEvent[0]); assertSame(checkBox, dataEvent[0].getSource()); assertSame(CHECKED, dataEvent[0].getOldValue()); assertSame(UNCHECKED, dataEvent[0].getNewValue()); assertEquals(UNCHECKED, checkBox.getValue()); W4TFixture.fakeRequestParam(WebCheckBoxRenderer.PREFIX + id, UNCHECKED); dataEvent[0] = null; getLifeCycleAdapter(form).readData(); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNull(dataEvent[0]); assertEquals(UNCHECKED, checkBox.getValue()); }
/** * Returns the id of the currently active theme. * * @return the id of the current theme, never <code>null</code> */ public static String getCurrentThemeId() { ThemeManager manager = ThemeManager.getInstance(); ISessionStore session = ContextProvider.getSession(); // 1) try URL parameter String result = ContextProvider.getRequest().getParameter(THEME_URL_PARM); if (result != null && manager.hasTheme(result)) { // TODO [rh] a method named get... should be constant, i.e. shouldn't // have side-effects like altering session attributes session.setAttribute(CURR_THEME_ATTR, result); } // 2) try session attribute else { result = (String) session.getAttribute(CURR_THEME_ATTR); } // 3) use default if (result == null) { result = ThemeManager.DEFAULT_THEME_ID; } return result; }
private static void processWidgetDefaultSelectedEvent(final Tree tree) { HttpServletRequest request = ContextProvider.getRequest(); String eventName = JSConst.EVENT_WIDGET_DEFAULT_SELECTED; if (WidgetLCAUtil.wasEventSent(tree, eventName)) { String itemId = request.getParameter(eventName + ".item"); Item treeItem = (Item) WidgetUtil.find(tree, itemId); int eventType = SelectionEvent.WIDGET_DEFAULT_SELECTED; SelectionEvent event = new SelectionEvent(tree, treeItem, eventType); event.stateMask = EventLCAUtil.readStateMask(JSConst.EVENT_WIDGET_SELECTED_MODIFIER); event.processEvent(); } }
private static void processWidgetSelectedEvent(final Tree tree) { HttpServletRequest request = ContextProvider.getRequest(); String eventName = JSConst.EVENT_WIDGET_SELECTED; if (WidgetLCAUtil.wasEventSent(tree, eventName)) { Rectangle bounds = new Rectangle(0, 0, 0, 0); String itemId = request.getParameter(eventName + ".item"); Item treeItem = (Item) WidgetUtil.find(tree, itemId); String detailStr = request.getParameter(eventName + ".detail"); int detail = "check".equals(detailStr) ? SWT.CHECK : SWT.NONE; int eventType = SelectionEvent.WIDGET_SELECTED; int stateMask = EventLCAUtil.readStateMask(JSConst.EVENT_WIDGET_SELECTED_MODIFIER); SelectionEvent event = new SelectionEvent(tree, treeItem, eventType, bounds, stateMask, null, true, detail); event.processEvent(); } }
// TODO [rh] is this safe for multiple shells? private static void processActivate(final Shell shell) { HttpServletRequest request = ContextProvider.getRequest(); String widgetId = request.getParameter(JSConst.EVENT_WIDGET_ACTIVATED); if (widgetId != null) { Widget widget = WidgetUtil.find(shell, widgetId); if (widget != null) { setActiveControl(shell, widget); } } else { String activeControlId = WidgetLCAUtil.readPropertyValue(shell, "activeControl"); Widget widget = WidgetUtil.find(shell, activeControlId); if (widget != null) { setActiveControl(shell, widget); } } }
public void testDataEventTriggering() throws Exception { WebForm form = W4TFixture.getEmptyWebFormInstance(); W4TFixture.fakeBrowser(new Default(true)); final WebDataEvent[] dataEvent = new WebDataEvent[1]; WebDataListener dataListener = new WebDataListener() { public void webValueChanged(final WebDataEvent evt) { dataEvent[0] = evt; } }; WebText text = new WebText(); form.add(text, WebBorderLayout.NORTH); text.setValue(OLD_VALUE); assertEquals(OLD_VALUE, text.getValue()); text.addWebDataListener(dataListener); text.setValue(NEW_VALUE); assertNull(dataEvent[0]); text.removeWebDataListener(dataListener); text.setValue(OLD_VALUE); dataEvent[0] = null; text.addWebDataListener(dataListener); W4TFixture.fakeRequestParam(text.getUniqueID(), NEW_VALUE); getLifeCycleAdapter(form).readData(); IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); String key = EventQueueFilter.ATTRIBUTE_KEY; EventQueueFilter eqv = (EventQueueFilter) stateInfo.getAttribute(key); eqv.filter(); EventQueue.getEventQueue().fireEvents(); assertNotNull(dataEvent[0]); assertSame(text, dataEvent[0].getSource()); assertSame(OLD_VALUE, dataEvent[0].getOldValue()); assertSame(NEW_VALUE, dataEvent[0].getNewValue()); assertEquals(NEW_VALUE, text.getValue()); }
/** * Sets the current theme to the theme identified by the given id. * * @param themeId the id of the theme to activate * @throws IllegalArgumentException if no theme with the given id is registered */ public static void setCurrentThemeId(final String themeId) { if (!ThemeManager.getInstance().hasTheme(themeId)) { throw new IllegalArgumentException("Illegal theme id: " + themeId); } ContextProvider.getSession().setAttribute(CURR_THEME_ATTR, themeId); }
public void readData(final WebComponent component) { // initialize the event queue filter used in noscript mode IServiceStateInfo stateInfo = ContextProvider.getStateInfo(); EventQueueFilter filter = new EventQueueFilter_Script(); stateInfo.setAttribute(EventQueueFilter.ATTRIBUTE_KEY, filter); }
private static void fakeServletPath(String string) { TestRequest request = (TestRequest) ContextProvider.getRequest(); request.setServletPath(string); }
static void set(PhaseId phaseId) { IServiceStore serviceStore = ContextProvider.getServiceStore(); serviceStore.setAttribute(ATTR_CURRENT_PHASE, phaseId); }