@Override public Object getObject() { return hostingButton.isEnabled() ? "default-button" : "default-button default-button-disabled"; } }
/** * Calculates enabled state of the component taking its hierarchy into account. A component is * enabled iff it is itself enabled ({@link #isEnabled()} and {@link #isEnableAllowed()} both * return <code>true</code>), and all of its parents are enabled. * * @return <code>true</code> if this component is enabled</code> */ public final boolean isEnabledInHierarchy() { Boolean state = getMetaData(ENABLED_IN_HIERARCHY_CACHE_KEY); if (state == null) { Component parent = getParent(); if (parent != null && !parent.isEnabledInHierarchy()) { state = false; } else { state = isEnabled() && isEnableAllowed(); } setMetaData(ENABLED_IN_HIERARCHY_CACHE_KEY, state); } return state; } }
/** * @see Behavior#isEnabled(org.apache.wicket.Component) */ @Override public boolean isEnabled(final Component component) { return super.isEnabled(component) && component.isEnabled() && component.isEnableAllowed(); }
/** * Calculates enabled state of the component taking its hierarchy into account. A component is * enabled iff it is itself enabled ({@link #isEnabled()} and {@link #isEnableAllowed()} both * return <code>true</code>), and all of its parents are enabled. * * @return <code>true</code> if this component is enabled</code> */ public boolean isEnabledInHierarchy() { if (getRequestFlag(RFLAG_ENABLED_IN_HIERARCHY_SET)) { return getRequestFlag(RFLAG_ENABLED_IN_HIERARCHY_VALUE); } final boolean state; Component parent = getParent(); if (parent != null && !parent.isEnabledInHierarchy()) { state = false; } else { state = isEnabled() && isEnableAllowed(); } setRequestFlag(RFLAG_ENABLED_IN_HIERARCHY_SET, true); setRequestFlag(RFLAG_ENABLED_IN_HIERARCHY_VALUE, state); return state; }
/** * {@inheritDoc} */ @Override public boolean isEnabled(final Component component) { return super.isEnabled(component) && component.isEnabled() && component.isEnableAllowed(); } }
@Override public void component(final Component component, final IVisit<Void> visit) { final ComponentData object = new ComponentData(); // anonymous class? Get the parent's class name String name = component.getClass().getName(); if (name.indexOf("$") > 0) { name = component.getClass().getSuperclass().getName(); } // remove the path component name = Strings.lastPathComponent(name, Component.PATH_SEPARATOR); object.path = component.getPageRelativePath(); object.type = name; object.isVisible = component.isVisible(); object.isEnabled = component.isEnabled(); try { object.value = component.getDefaultModelObjectAsString(); } catch (Exception e) { object.value = e.getMessage(); } data.add(object); } });
private void updateButton(AjaxRequestTarget target, String buttonId, boolean state) { Component c = get(buttonId); // rendering the button ONLY if the state was changed if (c.isEnabled() != state) { c.setEnabled(state); if (target != null) { target.add(c); } } }
protected final void onComponentTag(final ComponentTag tag) { // call to super intentionally ommitted. // only add the event handler when the component is enabled. Component myComponent = getComponent(); if (myComponent.isEnabled() && myComponent.isEnableAllowed()) { List<String>eventScripts = new LinkedList<String>(); eventScripts.add(getEventHandler().toString()); addAdditionalJavaScript (eventScripts); tag.put(super.getEvent(), StringUtils.join(eventScripts, ";")); } }
/** * @see org.apache.wicket.ajax.AjaxEventBehavior#onComponentTag(org.apache.wicket.markup.ComponentTag) */ protected void onComponentTag(ComponentTag tag) { if (getComponent().isEnabled() && getComponent().isEnableAllowed()) { super.onComponentTag(tag); } } }
@Override protected final void onComponentTag(final ComponentTag tag) { // call to super intentionally ommitted. // only add the event handler when the component is enabled. Component myComponent = getComponent(); if (myComponent.isEnabled() && myComponent.isEnableAllowed()) { List<String> eventScripts = new LinkedList<String>(); eventScripts.add(getEventHandler().toString()); addAdditionalJavaScript(eventScripts); tag.put(super.getEvent(), StringUtils.join(eventScripts, ";")); } }
@Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); if (!getParent().get(childId).isEnabled()) { Attributes.addClass(tag, "disabled"); } } }
/** * {@inheritDoc} */ @Override public void bind(Component component) { super.bind(component); getClassNameModel().setObject(classNames(component.isEnabled())); }
/** * * @see org.apache.wicket.behavior.AbstractAjaxBehavior#onComponentTag(org.apache.wicket.markup.ComponentTag) */ protected void onComponentTag(final ComponentTag tag) { super.onComponentTag(tag); // only add the event handler when the component is enabled. if (getComponent().isEnabled()) { tag.put(event, getEventHandler()); } }
/** * Checks whether a widget has been disabled * * @param form Wicket form * @param path Wicket path of widget */ protected void assertDisabled(Form form, String path) { assertFalse(form.get(path).isEnabled()); }
/** * Checks whether a widget has been enabled * * @param form Wicket form * @param path Wicket path of widget */ protected void assertEnabled(Form form, String path) { assertTrue(form.get(path).isEnabled()); }
public void testStyleEditPageGlobal() throws Exception { loginAsCite(); tester.startPage(StyleEditPage.class, new PageParameters(StyleEditPage.NAME+"=point")); tester.assertRenderedPage(StyleEditPage.class); //assert all form components disabled except for cancel assertFalse(tester.getComponentFromLastRenderedPage("form:name").isEnabled()); assertFalse(tester.getComponentFromLastRenderedPage("form:workspace").isEnabled()); assertFalse(tester.getComponentFromLastRenderedPage("form:copy").isEnabled()); assertTrue(tester.getComponentFromLastRenderedPage("cancel").isEnabled()); } }
/** * helper method that adds all necessary css styles to given component tag. * * @param component the component to which given tag belongs, needed because of enabled state * @param tag the component tag * @param classNameProviders all css class names to add */ public static void onComponentTag(final Component component, final ComponentTag tag, final ICssClassNameProvider... classNameProviders) { Args.notNull(classNameProviders, "classNameProviders"); final CssClassNames.Builder builder = CssClassNames.newBuilder().add( "btn", (component.isEnabled() ? "" : "btn-disabled")); for (final ICssClassNameProvider provider : classNameProviders) { builder.add(provider.cssClassName()); } Attributes.addClass(tag, builder.asString()); }
@Test public void testDownload() throws Exception { assertFalse(tester.getComponentFromLastRenderedPage("download").isEnabled()); // select resource tester.executeAjaxEvent( "treeview:rootView:/:children:temp:children:temp/dir:children:temp/dir/something:selectableLabel", "click"); assertTrue(tester.getComponentFromLastRenderedPage("download").isEnabled()); // rename resource tester.clickLink("download"); assertTrue(Arrays.equals(DATA.getBytes(), tester.getLastResponse().getBinaryContent())); }
@Override public void onComponentTag(Component component, ComponentTag tag) { super.onComponentTag(component, tag); // HACK issue #79: wicket changes tag name if component wasn't enabled if (!component.isEnabled()) { if (component instanceof AbstractLink) { tag.setName("a"); } else if (component instanceof Button) { tag.setName("button"); } else { if (tag.getAttribute("value") != null) { tag.setName("input"); } else { tag.setName("button"); } } tag.put("disabled", "disabled"); } Components.assertTag(component, tag, "a", "button", "input"); } }
@Test public void testEdit() throws Exception { assertFalse(tester.getComponentFromLastRenderedPage("edit").isEnabled()); // select resource tester.executeAjaxEvent( "treeview:rootView:/:children:temp:children:temp/dir:children:temp/dir/something:selectableLabel", "click"); assertTrue(tester.getComponentFromLastRenderedPage("edit").isEnabled()); // new file tester.clickLink("edit"); tester.assertComponent("dialog:dialog:content:form:userPanel", PanelEdit.class); formTester = tester.newFormTester("dialog:dialog:content:form"); assertEquals(DATA, formTester.getTextComponentValue("userPanel:contents")); formTester.setValue("userPanel:contents", DATA2); formTester.submit("submit"); assertNull(tester.getComponentFromLastRenderedPage("dialog:dialog:content:form:userPanel")); try (InputStream is = resourceBrowser.store().get(PATH_RES).in()) { assertEquals(DATA2 + System.lineSeparator(), IOUtils.toString(is)); } } }