Example usage for org.apache.wicket Component isEnabled

List of usage examples for org.apache.wicket Component isEnabled

Introduction

In this page you can find the example usage for org.apache.wicket Component isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Gets whether this component is enabled.

Usage

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

/**
 * Create the DataType dropdown. When the datatype is changed, the offsets will be recalculated and updated.
 *//*from  w  ww  .  j av a  2 s. c  o m*/
private DropDownChoice<BinaryDataType> getDataTypeDropdown() {
    DropDownChoice<BinaryDataType> dropDown = new DropDownChoice<BinaryDataType>("dataType",
            BinaryDataType.getOptions(), new EnumChoiceRenderer<BinaryDataType>(this)) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (hasErrorMessage()) {
                String style = "background-color:#ffff00;";
                String oldStyle = tag.getAttribute("style");
                tag.put("style", style + oldStyle);
            }
        }
    };

    dropDown.setRequired(true);

    // When the datatype is changed, the offsets are recalculated and displayed
    dropDown.add(new OnChangeAjaxBehavior() {
        @SuppressWarnings("unchecked")
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // Recalculate and display the offsets
            updateOffsets(target);

            // Disable input fields when DataType is a special type.
            // Current state is determined by the enabled state of TextField("id")
            DropDownChoice<BinaryDataType> choice = (DropDownChoice<BinaryDataType>) getComponent();
            MarkupContainer parent = choice.getParent();
            Component idTextField = parent.get("id");
            BinaryDataType dataType = choice.getConvertedInput();
            if (dataType.isSpecial() && idTextField.isEnabled()) {
                // DataType changed to special type
                // Store current values
                ((TextField<Integer>) idTextField).getRawInput();
                idTextField.replaceWith(getSpecialIdTextField().setEnabled(false));
                target.add(parent.get("id"));
                target.add(parent.get("alias").setVisible(false));
            } else if (!idTextField.isEnabled()) {
                idTextField.replaceWith(getIdTextField());
                target.add(parent.get("id").setEnabled(true));
                target.add(parent.get("alias").setVisible(true));
            }
            target.add(parent.get("size").setEnabled(dataType.isArrayAllowed()));
            target.add(parent.get("tagLengthType").setEnabled(dataType.supportsVariableLength()));
            if (!dataType.supportsVariableLength()) {
                EditorListItem<TagConfig> listItem = getComponent().findParent(EditorListItem.class);
                if (listItem != null) {
                    listItem.getModelObject().setTagLengthType(TagLengthType.FIXED_LENGTH);
                }
            }
        }
    });

    dropDown.add(new UniqueListItemValidator<BinaryDataType>(dropDown) {
        @Override
        public String getValue(IValidatable<BinaryDataType> validatable) {
            return String.valueOf(validatable.getValue().name());
        }
    }.setMessageKey("dataType.SpecialTypesValidator")
            .setFilterList(new String[] { BinaryDataType.MessageAge.name() }));

    return dropDown;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.WritebackConfigUI.java

License:Apache License

private CheckBox getUsePrefixCheckBox() {
    CheckBox checkbox = new CheckBox("usePrefix");

    checkbox.add(new OnChangeAjaxBehavior() {
        @Override/*  w  ww  .  j  av a  2 s .c  o  m*/
        protected void onUpdate(AjaxRequestTarget target) {
            boolean value = ((CheckBox) getComponent()).getConvertedInput();

            Component prefixTextField = getComponent().getParent().get("prefix");
            if (value && !prefixTextField.isEnabled()) {
                prefixTextField.setEnabled(true);
            } else {
                prefixTextField.setEnabled(false);
            }
            target.add(prefixTextField);
        }
    });

    return checkbox;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.WritebackConfigUI.java

License:Apache License

private CheckBox getSendInitialValueCheckBox() {
    CheckBox checkbox = new CheckBox("sendInitialValue");

    // When the datatype is changed, the offsets are recalculated and
    // displayed/*  w w  w. j  av a 2s .c om*/
    checkbox.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            boolean value = ((CheckBox) getComponent()).getConvertedInput();

            Component initialValueTextField = getComponent().getParent().get("initialValue");
            Component initialIdTextField = getComponent().getParent().get("initialId");

            if (value && !initialValueTextField.isEnabled()) {
                initialValueTextField.setEnabled(true);
                initialIdTextField.setEnabled(true);
            } else {
                initialValueTextField.setEnabled(false);
                initialIdTextField.setEnabled(false);
            }
            target.add(initialValueTextField);
            target.add(initialIdTextField);
        }
    });

    return checkbox;
}

From source file:com.cubeia.backoffice.web.util.ConfirmOnclickAttributeModifier.java

License:Open Source License

@Override
public boolean isEnabled(Component component) {
    return super.isEnabled(component) && component.isEnabled();
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.java

License:Open Source License

private void enableChildrenInContainer(MarkupContainer container, final boolean b) {
    container.visitChildren(new IVisitor<Component>() {
        public Object component(Component component) {
            if (component.isEnabled() != b) {
                if (component instanceof IComponent) {
                    if (b) {
                        // component may be disabled by scripting, do not enable it
                        return CONTINUE_TRAVERSAL;
                    }/*from w  w w  .  j a  v a2s. c  om*/
                    ((IComponent) component).setComponentEnabled(b);
                } else {
                    component.setEnabled(b);
                }
            }
            return CONTINUE_TRAVERSAL;
        }
    });
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.java

License:Open Source License

/**
 * @param component2//from  ww w  .j  a va  2  s . c o  m
 * @param response
 */
@SuppressWarnings("nls")
public static void generateDragAttach(Component component, IHeaderResponse response) {
    DraggableBehavior draggableBehavior = null;
    Component behaviorComponent = component;

    if ((behaviorComponent instanceof IComponent) && !(behaviorComponent instanceof IFormDataDragNDrop)) {
        behaviorComponent = (Component) component.findParent(IFormDataDragNDrop.class);
    }
    if (behaviorComponent != null) {
        Iterator<IBehavior> behaviors = behaviorComponent.getBehaviors().iterator();
        Object behavior;
        while (behaviors.hasNext()) {
            behavior = behaviors.next();
            if (behavior instanceof DraggableBehavior) {
                draggableBehavior = (DraggableBehavior) behavior;
                break;
            }
        }
    }

    if (draggableBehavior == null)
        return;

    boolean bUseProxy = draggableBehavior.isUseProxy();
    boolean bResizeProxyFrame = draggableBehavior.isResizeProxyFrame();
    boolean bXConstraint = draggableBehavior.isXConstraint();
    boolean bYConstraint = draggableBehavior.isYConstraint();
    CharSequence dragUrl = draggableBehavior.getCallbackUrl();

    String jsCode = null;

    if (behaviorComponent instanceof IFormDataDragNDrop) {
        final StringBuilder sbAttachDrag = new StringBuilder(100);
        sbAttachDrag.append("Servoy.DD.attachDrag([");
        final StringBuilder sbAttachDrop = new StringBuilder(100);
        sbAttachDrop.append("Servoy.DD.attachDrop([");

        final boolean hasDragEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm()
                .getOnDragMethodID() > 0
                || ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm()
                        .getOnDragOverMethodID() > 0;
        final boolean hasDropEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm()
                .getOnDropMethodID() > 0;

        if (component instanceof WebDataRenderer || component instanceof WebCellBasedView) {
            if (hasDragEvent)
                sbAttachDrag.append('\'').append(component.getMarkupId()).append("',");
            if (hasDropEvent)
                sbAttachDrop.append('\'').append(component.getMarkupId()).append("',");

            if (component instanceof WebDataRenderer) {
                Iterator<? extends Component> dataRendererIte = ((WebDataRenderer) component).iterator();

                Object dataRendererChild;
                while (dataRendererIte.hasNext()) {
                    dataRendererChild = dataRendererIte.next();
                    if (dataRendererChild instanceof IWebFormContainer)
                        continue;
                    if (dataRendererChild instanceof WrapperContainer)
                        dataRendererChild = ((WrapperContainer) dataRendererChild).getDelegate();
                    if (dataRendererChild instanceof IComponent
                            && ((IComponent) dataRendererChild).isEnabled()) {
                        updateDragAttachOutput(dataRendererChild, sbAttachDrag, sbAttachDrop, hasDragEvent,
                                hasDropEvent);
                    }
                }
            } else if (component instanceof WebCellBasedView) {
                ListView<IRecordInternal> table = ((WebCellBasedView) component).getTable();
                table.visitChildren(new IVisitor<Component>() {
                    public Object component(Component comp) {
                        if (comp instanceof IComponent && comp.isEnabled()) {
                            updateDragAttachOutput(comp, sbAttachDrag, sbAttachDrop, hasDragEvent,
                                    hasDropEvent);
                        }
                        return null;
                    }
                });
            }
        } else if (component != null && component.isEnabled()) {
            updateDragAttachOutput(component, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
        }

        if (sbAttachDrag.length() > 25) {
            sbAttachDrag.setLength(sbAttachDrag.length() - 1);
            sbAttachDrag.append("],'");
            sbAttachDrag.append(dragUrl);
            sbAttachDrag.append("', ");
            sbAttachDrag.append(bUseProxy);
            sbAttachDrag.append(", ");
            sbAttachDrag.append(bResizeProxyFrame);
            sbAttachDrag.append(", ");
            sbAttachDrag.append(bXConstraint);
            sbAttachDrag.append(", ");
            sbAttachDrag.append(bYConstraint);
            sbAttachDrag.append(");");

            jsCode = sbAttachDrag.toString();
        }

        if (sbAttachDrop.length() > 25) {
            sbAttachDrop.setLength(sbAttachDrop.length() - 1);
            sbAttachDrop.append("],'");
            sbAttachDrop.append(dragUrl);
            sbAttachDrop.append("');");

            if (jsCode != null)
                jsCode += '\n' + sbAttachDrop.toString();
            else
                jsCode = sbAttachDrop.toString();
        }

        if (jsCode != null) {
            if (response == null) {
                jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode)
                        .append("</script>\n")).toString();
                Response cyleResponse = RequestCycle.get().getResponse();
                cyleResponse.write(jsCode);
            } else
                response.renderOnDomReadyJavascript(jsCode);
        }
    } else
    //default handling
    {
        jsCode = "Servoy.DD.attachDrag(['" + component.getMarkupId() + "'],'" + dragUrl + "', " + bUseProxy
                + ", " + bResizeProxyFrame + ", " + bXConstraint + ", " + bYConstraint + ")";
        if (response == null) {
            jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode)
                    .append("</script>\n")).toString();
            Response cyleResponse = RequestCycle.get().getResponse();

            cyleResponse.write(jsCode);
        } else
            response.renderOnDomReadyJavascript(jsCode);
    }
}

From source file:com.servoy.j2db.server.headlessclient.WebClientsApplication.java

License:Open Source License

/**
 * @see wicket.protocol.http.WebApplication#init()
 *//* w  ww .  j  av  a 2s.  c  om*/
@Override
protected void init() {
    if (ApplicationServerRegistry.get() == null)
        return; // TODO this is a workaround to allow mobile test client that only starts Tomcat not to give exceptions (please remove if mobile test client initialises a full app. server in the future)

    getResourceSettings().setResourceWatcher(new ServoyModificationWatcher(Duration.seconds(5)));
    //      getResourceSettings().setResourcePollFrequency(Duration.seconds(5));
    getResourceSettings().setAddLastModifiedTimeToResourceReferenceUrl(true);
    getResourceSettings().setDefaultCacheDuration((int) Duration.days(365).seconds());
    getMarkupSettings().setCompressWhitespace(true);
    getMarkupSettings().setMarkupCache(new ServoyMarkupCache(this));
    // getMarkupSettings().setStripWicketTags(true);
    getResourceSettings().setResourceStreamLocator(new ServoyResourceStreamLocator(this));
    getResourceSettings().setPackageResourceGuard(new ServoyPackageResourceGuard());
    // getResourceSettings().setResourceFinder(createResourceFinder());
    getResourceSettings().setThrowExceptionOnMissingResource(false);
    getApplicationSettings().setPageExpiredErrorPage(ServoyExpiredPage.class);
    getApplicationSettings().setClassResolver(new ServoyClassResolver());
    getSessionSettings().setMaxPageMaps(15);
    //      getRequestCycleSettings().setGatherExtendedBrowserInfo(true);

    getSecuritySettings().setCryptFactory(new CachingKeyInSessionSunJceCryptFactory());

    Settings settings = Settings.getInstance();
    getDebugSettings().setOutputComponentPath(
            Utils.getAsBoolean(settings.getProperty("servoy.webclient.debug.wicketpath", "false"))); //$NON-NLS-1$ //$NON-NLS-2$
    if (Utils.getAsBoolean(settings.getProperty("servoy.webclient.nice.urls", "false"))) //$NON-NLS-1$ //$NON-NLS-2$
    {
        mount(new HybridUrlCodingStrategy("/solutions", SolutionLoader.class)); //$NON-NLS-1$
        mount(new HybridUrlCodingStrategy("/application", MainPage.class)); //$NON-NLS-1$
        mount(new HybridUrlCodingStrategy("/ss", SolutionLoader.class) //$NON-NLS-1$
        {
            /**
             * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget)
             */
            @Override
            public boolean matches(IRequestTarget requestTarget) {
                return false;
            }
        });
    } else {
        mountBookmarkablePage("/solutions", SolutionLoader.class); //$NON-NLS-1$
        mount(new BookmarkablePageRequestTargetUrlCodingStrategy("/ss", SolutionLoader.class, null) //$NON-NLS-1$
        {
            /**
             * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget)
             */
            @Override
            public boolean matches(IRequestTarget requestTarget) {
                return false;
            }
        });
    }

    long maxSize = Utils.getAsLong(settings.getProperty("servoy.webclient.maxuploadsize", "0"), false); //$NON-NLS-1$ //$NON-NLS-2$
    if (maxSize > 0) {
        getApplicationSettings().setDefaultMaximumUploadSize(Bytes.kilobytes(maxSize));
    }

    getSharedResources().putClassAlias(IApplication.class, "application"); //$NON-NLS-1$
    getSharedResources().putClassAlias(PageContributor.class, "pc"); //$NON-NLS-1$
    getSharedResources().putClassAlias(MaskBehavior.class, "mask"); //$NON-NLS-1$
    getSharedResources().putClassAlias(Application.class, "servoy"); //$NON-NLS-1$
    getSharedResources().putClassAlias(org.wicketstuff.calendar.markup.html.form.DatePicker.class,
            "datepicker"); //$NON-NLS-1$
    getSharedResources().putClassAlias(YUILoader.class, "yui"); //$NON-NLS-1$
    getSharedResources().putClassAlias(JQueryLoader.class, "jquery"); //$NON-NLS-1$
    getSharedResources().putClassAlias(TinyMCELoader.class, "tinymce"); //$NON-NLS-1$
    getSharedResources().putClassAlias(org.apache.wicket.markup.html.WicketEventReference.class, "wicketevent"); //$NON-NLS-1$
    getSharedResources().putClassAlias(org.apache.wicket.ajax.WicketAjaxReference.class, "wicketajax"); //$NON-NLS-1$
    getSharedResources().putClassAlias(MainPage.class, "servoyjs"); //$NON-NLS-1$
    getSharedResources().putClassAlias(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.class,
            "modalwindow"); //$NON-NLS-1$

    PackageResource.bind(this, IApplication.class, "images/open_project.gif"); //$NON-NLS-1$
    PackageResource.bind(this, IApplication.class, "images/save.gif"); //$NON-NLS-1$

    mountSharedResource("/formcss", "servoy/formcss"); //$NON-NLS-1$//$NON-NLS-2$

    sharedMediaResource = new SharedMediaResource();
    getSharedResources().add("media", sharedMediaResource); //$NON-NLS-1$

    mount(new SharedResourceRequestTargetUrlCodingStrategy("mediafolder", "servoy/media") //$NON-NLS-1$ //$NON-NLS-2$
    {
        @Override
        protected void appendParameters(AppendingStringBuffer url, Map<String, ?> parameters) {
            if (parameters != null && parameters.size() > 0) {
                Object solutionName = parameters.get("s"); //$NON-NLS-1$
                if (solutionName != null)
                    appendPathParameter(url, null, solutionName.toString());
                Object resourceId = parameters.get("id"); //$NON-NLS-1$
                if (resourceId != null)
                    appendPathParameter(url, null, resourceId.toString());

                StringBuilder queryParams = new StringBuilder();
                for (Entry<?, ?> entry1 : parameters.entrySet()) {
                    Object value = ((Entry<?, ?>) entry1).getValue();
                    if (value != null) {
                        Object key = ((Entry<?, ?>) entry1).getKey();
                        if (!"s".equals(key) && !"id".equals(key)) //$NON-NLS-1$ //$NON-NLS-2$
                        {
                            if (value instanceof String[]) {
                                String[] values = (String[]) value;
                                for (String value1 : values) {
                                    if (queryParams.length() > 0)
                                        queryParams.append("&"); //$NON-NLS-1$
                                    queryParams.append(key).append("=").append(value1);//$NON-NLS-1$
                                }
                            } else {
                                if (queryParams.length() > 0)
                                    queryParams.append("&"); //$NON-NLS-1$
                                queryParams.append(key).append("=").append(value);//$NON-NLS-1$
                            }
                        }
                    }
                }
                if (queryParams.length() > 0) {
                    url.append("?").append(queryParams);//$NON-NLS-1$
                }
            }
        }

        @Override
        protected void appendPathParameter(AppendingStringBuffer url, String key, String value) {
            String escapedValue = value;
            String[] values = escapedValue.split("/");//$NON-NLS-1$
            if (values.length > 1) {
                StringBuilder sb = new StringBuilder(escapedValue.length());
                for (String str : values) {
                    sb.append(urlEncodePathComponent(str));
                    sb.append('/');
                }
                sb.setLength(sb.length() - 1);
                escapedValue = sb.toString();
            } else {
                escapedValue = urlEncodePathComponent(escapedValue);
            }

            if (!Strings.isEmpty(escapedValue)) {
                if (!url.endsWith("/"))//$NON-NLS-1$
                {
                    url.append("/");//$NON-NLS-1$
                }
                if (key != null)
                    url.append(urlEncodePathComponent(key)).append("/");//$NON-NLS-1$
                url.append(escapedValue);
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#decodeParameters(java.lang.String, java.util.Map)
         */
        @Override
        protected ValueMap decodeParameters(String urlFragment, Map<String, ?> urlParameters) {
            ValueMap map = new ValueMap();
            final String[] pairs = urlFragment.split("/"); //$NON-NLS-1$
            if (pairs.length > 1) {
                map.add("s", pairs[1]); //$NON-NLS-1$
                StringBuffer sb = new StringBuffer();
                for (int i = 2; i < pairs.length; i++) {
                    sb.append(pairs[i]);
                    sb.append("/"); //$NON-NLS-1$
                }
                sb.setLength(sb.length() - 1);
                map.add("id", sb.toString()); //$NON-NLS-1$
            }
            if (urlParameters != null) {
                map.putAll(urlParameters);
            }
            return map;
        }
    });

    getSharedResources().add("resources", new ServeResources()); //$NON-NLS-1$

    getSharedResources().add("formcss", new FormCssResource(this)); //$NON-NLS-1$

    if (settings.getProperty("servoy.webclient.error.page", null) != null) //$NON-NLS-1$
    {
        getApplicationSettings().setInternalErrorPage(ServoyErrorPage.class);
    }
    if (settings.getProperty("servoy.webclient.pageexpired.page", null) != null) //$NON-NLS-1$
    {
        getApplicationSettings().setPageExpiredErrorPage(ServoyPageExpiredPage.class);
    }

    addPreComponentOnBeforeRenderListener(new IComponentOnBeforeRenderListener() {
        public void onBeforeRender(Component component) {
            if (component instanceof IServoyAwareBean) {
                IModel model = component.getInnermostModel();
                WebForm webForm = component.findParent(WebForm.class);
                if (model instanceof RecordItemModel && webForm != null) {
                    IRecord record = (IRecord) ((RecordItemModel) model).getObject();
                    FormScope fs = webForm.getController().getFormScope();

                    if (record != null && fs != null) {
                        ((IServoyAwareBean) component).setSelectedRecord(new ServoyBeanState(record, fs));
                    }
                }
            } else {
                if (!component.isEnabled()) {
                    boolean hasOnRender = (component instanceof IFieldComponent
                            && ((IFieldComponent) component)
                                    .getScriptObject() instanceof ISupportOnRenderCallback
                            && ((ISupportOnRenderCallback) ((IFieldComponent) component).getScriptObject())
                                    .getRenderEventExecutor().hasRenderCallback());
                    if (!hasOnRender) {
                        // onrender may change the enable state
                        return;
                    }
                }
                Component targetComponent = null;
                boolean hasFocus = false, hasBlur = false;
                if (component instanceof IFieldComponent
                        && ((IFieldComponent) component).getEventExecutor() != null) {
                    targetComponent = component;
                    if (component instanceof WebBaseSelectBox) {
                        Component[] cs = ((WebBaseSelectBox) component).getFocusChildren();
                        if (cs != null && cs.length == 1)
                            targetComponent = cs[0];
                    }
                    if (component instanceof WebDataHtmlArea)
                        hasFocus = true;

                    // always install a focus handler when in a table view to detect change of selectedIndex and test for record validation
                    if (((IFieldComponent) component).getEventExecutor().hasEnterCmds()
                            || component.findParent(WebCellBasedView.class) != null
                            || (((IFieldComponent) component)
                                    .getScriptObject() instanceof ISupportOnRenderCallback
                                    && ((ISupportOnRenderCallback) ((IFieldComponent) component)
                                            .getScriptObject()).getRenderEventExecutor().hasRenderCallback())) {
                        hasFocus = true;
                    }
                    // Always trigger event on focus lost:
                    // 1) check for new selected index, record validation may have failed preventing a index changed
                    // 2) prevent focus gained to be called when field validation failed
                    // 3) general ondata change
                    hasBlur = true;
                } else if (component instanceof WebBaseLabel) {
                    targetComponent = component;
                    hasFocus = true;
                }

                if (targetComponent != null) {
                    MainPage mainPage = targetComponent.findParent(MainPage.class);
                    if (mainPage.isUsingAjax()) {
                        AbstractAjaxBehavior eventCallback = mainPage.getPageContributor().getEventCallback();
                        if (eventCallback != null) {
                            String callback = eventCallback.getCallbackUrl().toString();
                            if (component instanceof WebDataRadioChoice
                                    || component instanceof WebDataCheckBoxChoice
                                    || component instanceof WebDataLookupField
                                    || component instanceof WebDataComboBox
                                    || component instanceof WebDataListBox
                                    || component instanceof WebDataHtmlArea) {
                                // is updated via ServoyChoiceComponentUpdatingBehavior or ServoyFormComponentUpdatingBehavior, this is just for events
                                callback += "&nopostdata=true";
                            }
                            for (IBehavior behavior : targetComponent.getBehaviors()) {
                                if (behavior instanceof EventCallbackModifier) {
                                    targetComponent.remove(behavior);
                                }
                            }
                            if (hasFocus) {
                                StringBuilder js = new StringBuilder();
                                js.append("eventCallback(this,'focus','").append(callback).append("',event)"); //$NON-NLS-1$ //$NON-NLS-2$
                                targetComponent.add(new EventCallbackModifier("onfocus", true, //$NON-NLS-1$
                                        new Model<String>(js.toString())));
                                targetComponent.add(new EventCallbackModifier("onmousedown", true, //$NON-NLS-1$
                                        new Model<String>("focusMousedownCallback(event)"))); //$NON-NLS-1$
                            }
                            if (hasBlur) {
                                boolean blockRequest = false;
                                // if component has ondatachange, check for blockrequest
                                if (component instanceof ISupportEventExecutor
                                        && ((ISupportEventExecutor) component).getEventExecutor()
                                                .hasChangeCmd()) {
                                    WebClientSession webClientSession = WebClientSession.get();
                                    blockRequest = webClientSession != null && webClientSession.blockRequest();
                                }

                                StringBuilder js = new StringBuilder();
                                js.append("postEventCallback(this,'blur','").append(callback) //$NON-NLS-1$
                                        .append("',event," + blockRequest + ")"); //$NON-NLS-1$
                                targetComponent.add(new EventCallbackModifier("onblur", true, //$NON-NLS-1$
                                        new Model<String>(js.toString())));
                            }
                        }
                    }
                }
            }
        }
    });
}

From source file:com.userweave.application.UserWeaveAuthorizationStrategy.java

License:Open Source License

public boolean isActionAuthorized(Component component, Action action) {
    if (action.equals(Component.RENDER)) {
        Class<? extends Component> c = component.getClass();
        AdminOnly adminOnly = c.getAnnotation(AdminOnly.class);

        if (adminOnly != null) {
            return UserWeaveSession.get().isAdmin();
        }//www. ja v a2 s .c  o  m

        /**
         * To set the state of an AuthOnlyTextComponent
         * may be stupid here, but there is currently
         * no other option.
         */
        if (component instanceof IAuthOnly) {
            IAuthOnly comp = (IAuthOnly) component;

            User user = UserWeaveSession.get().getUser();

            AuthorizeAction authAction = comp.getClass().getAnnotation(AuthorizeAction.class);

            boolean auth = false;

            if (authAction == null) {
                // if no annotation is given, admins and participants
                // have access
                auth = user.hasRole(Role.PROJECT_ADMIN) || user.hasRole(Role.PROJECT_PARTICIPANT);
            } else {
                // evaluate annotation roles
                auth = user.hasAnyRole(new Roles(authAction.roles()));
            }

            comp.setIsAuthorized(auth || user.isAdmin());

            return true;
        }
    }

    if (action.equals(Component.ENABLE)) {
        AuthorizeAction authAction = component.getClass().getAnnotation(AuthorizeAction.class);

        if (authAction != null) {
            User user = UserWeaveSession.get().getUser();

            boolean isEnabled = user.hasAnyRole(new Roles(authAction.roles()));

            if (!isEnabled) {
                if (component instanceof IToolTipComponent) {
                    ((IToolTipComponent) component).setToolTipType(ToolTipType.RIGHTS);
                }
            }

            return isEnabled && component.isEnabled();
        }

        return true;
    }

    return true;
}

From source file:dk.teachus.frontend.components.ConfirmClickBehavior.java

License:Apache License

@Override
public boolean isEnabled(Component component) {
    return component.isEnabled() && Strings.isEmpty(confirmScript) == false;
}

From source file:jp.xet.uncommons.wicket.behavior.DynamicDisabledClassAppender.java

License:Apache License

@Override
public void onComponentTag(Component component, ComponentTag tag) {
    super.onComponentTag(component, tag);
    if (component.isEnabled() == false) {
        tag.append("class", "disabled", " ");
    }//from   w w  w . ja  v a 2  s. com
}