Example usage for org.apache.wicket AttributeModifier VALUELESS_ATTRIBUTE_REMOVE

List of usage examples for org.apache.wicket AttributeModifier VALUELESS_ATTRIBUTE_REMOVE

Introduction

In this page you can find the example usage for org.apache.wicket AttributeModifier VALUELESS_ATTRIBUTE_REMOVE.

Prototype

MarkerValue VALUELESS_ATTRIBUTE_REMOVE

To view the source code for org.apache.wicket AttributeModifier VALUELESS_ATTRIBUTE_REMOVE.

Click Source Link

Document

Marker value to have an attribute without a value removed.

Usage

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

License:Open Source License

/**
 * @param id/*  w w w  .j  a  v  a  2 s  .c om*/
 */
public WebDataField(final IApplication application, final AbstractRuntimeField<IFieldComponent> scriptable,
        String id, final IComponent enclosingComponent) {
    super(id);
    this.horizontalAlignment = ISupportTextSetup.LEFT;
    this.application = application;
    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    eventExecutor = new WebEventExecutor(this, useAJAX) {
        @Override
        protected Object getSource(Object display) {
            return enclosingComponent != null ? enclosingComponent : super.getSource(display);
        }
    };
    setOutputMarkupPlaceholderTag(true);
    setVersioned(false);

    add(new AttributeModifier("readonly", true, new Model<String>() //$NON-NLS-1$
    {
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return (editable ? AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE
                    : AttributeModifier.VALUELESS_ATTRIBUTE_ADD);
        }
    }));

    add(new AttributeModifier("placeholder", true, new Model<String>() //$NON-NLS-1$
    {
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return application.getI18NMessageIfPrefixed(scriptable.getPlaceholderText());
        }
    }) {
        @Override
        public boolean isEnabled(Component component) {
            return super.isEnabled(component) && scriptable.getPlaceholderText() != null;
        }
    });
    add(new SimpleAttributeModifier("autocomplete", "off"));

    focusIfInvalidAttributeModifier = new FocusIfInvalidAttributeModifier(this);
    add(focusIfInvalidAttributeModifier);
    add(StyleAttributeModifierModel.INSTANCE);
    add(TooltipAttributeModifier.INSTANCE);
    add(new ConsumeEnterAttributeModifier(this, eventExecutor));
    add(new FilterBackspaceKeyAttributeModifier(new Model<String>() {
        private static final long serialVersionUID = 1332637522687352873L;

        @Override
        public String getObject() {
            return editable ? null : FilterBackspaceKeyAttributeModifier.SCRIPT;
        }
    }));
    this.scriptable = scriptable;
}

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

License:Open Source License

public WebDataTextArea(final IApplication application, final AbstractRuntimeField<IFieldComponent> scriptable,
        String id) {//from  w  w  w . j a v  a2s  .c  om
    super(id);
    this.application = application;
    setVersioned(false);

    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    eventExecutor = new WebEventExecutor(this, useAJAX);
    setOutputMarkupPlaceholderTag(true);

    add(new AttributeModifier("readonly", true, new Model<String>() //$NON-NLS-1$
    {
        @Override
        public String getObject() {
            return (editable ? AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE
                    : AttributeModifier.VALUELESS_ATTRIBUTE_ADD);
        }
    }));

    add(new AttributeModifier("placeholder", true, new Model<String>() //$NON-NLS-1$
    {
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return application.getI18NMessageIfPrefixed(scriptable.getPlaceholderText());
        }
    }) {
        @Override
        public boolean isEnabled(Component component) {
            return super.isEnabled(component) && scriptable.getPlaceholderText() != null;
        }
    });

    add(new AjaxEventBehavior("onselect") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            setSelectedText(getComponent().getRequest().getParameter("st"));
        }

        @Override
        public CharSequence getCallbackUrl(final boolean onlyTargetActivePage) {
            CharSequence callbackURL = super.getCallbackUrl(onlyTargetActivePage);
            return callbackURL.toString() + "&st=' + Servoy.Utils.getSelectedText('" + getMarkupId() + "') + '";
        }

        @Override
        protected String findIndicatorId() {
            return null; // main page defines it and the timer shouldn't show it
        }
    });

    add(StyleAttributeModifierModel.INSTANCE);
    add(TooltipAttributeModifier.INSTANCE);
    add(new FilterBackspaceKeyAttributeModifier(new Model<String>() {
        private static final long serialVersionUID = 1332637522687352873L;

        @Override
        public String getObject() {
            return editable ? null : FilterBackspaceKeyAttributeModifier.SCRIPT;
        }
    }));
    this.scriptable = scriptable;
    add(new ScrollBehavior(this));
}

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

License:Open Source License

@SuppressWarnings("nls")
private void init(WebClient sc) {
    setStatelessHint(false);//from  w w  w. j  av a  2 s  . co  m
    client = sc;
    webForms = new ArrayList<IFormUIInternal<?>>();

    title = new Label("title", new Model<String>("Servoy Web Client")); //$NON-NLS-1$ //$NON-NLS-2$
    title.setOutputMarkupId(true);
    add(title);

    useAJAX = Utils.getAsBoolean(client.getRuntimeProperties().get("useAJAX")); //$NON-NLS-1$
    int dataNotifyFrequency = Utils
            .getAsInteger(sc.getSettings().getProperty("servoy.webclient.datanotify.frequency", "5")); //$NON-NLS-1$  //$NON-NLS-2$
    if (dataNotifyFrequency > 0 && useAJAX) {
        add(new AbstractAjaxTimerBehavior(Duration.seconds(dataNotifyFrequency)) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                if (isServoyEnabled() && !client.getFlattenedSolution().isInDesign(null)
                        && String.valueOf(MainPage.this.getCurrentVersionNumber())
                                .equals(RequestCycle.get().getRequest().getParameter("pvs"))) {
                    WebEventExecutor.generateResponse(target, MainPage.this);
                }
            }

            @Override
            public void renderHead(IHeaderResponse response) {
                if (isServoyEnabled()) {
                    super.renderHead(response);

                    String jsTimerScript = getJsTimeoutCall(getUpdateInterval());
                    response.renderJavascript("function restartTimer() {" + jsTimerScript + "}", //$NON-NLS-1$//$NON-NLS-2$
                            "restartTimer"); //$NON-NLS-1$
                }
            }

            @Override
            protected CharSequence getPreconditionScript() {
                return "onAjaxCall(); if(Servoy.DD.isDragging) Servoy.DD.isRestartTimerNeeded=true; return !Servoy.DD.isDragging && !Servoy.redirectingOnSolutionClose;"; //$NON-NLS-1$
            }

            @Override
            protected CharSequence getFailureScript() {
                return "onAjaxError();restartTimer();"; //$NON-NLS-1$
            }

            @Override
            protected CharSequence getCallbackScript() {
                // if it is not enabled then just return an empty function. so that the timer stops.
                if (isServoyEnabled()) {
                    return generateCallbackScript("wicketAjaxGet('" + //$NON-NLS-1$
                    getCallbackUrl(onlyTargetActivePage()) + "&ignoremp=true&pvs=" //$NON-NLS-1$
                            + MainPage.this.getCurrentVersionNumber() + "'");
                }
                return "Servoy.Utils.nop()";
            }

            @Override
            public CharSequence getCallbackUrl(boolean onlyTargetActivePage) {
                if (getComponent() == null) {
                    throw new IllegalArgumentException(
                            "Behavior must be bound to a component to create the URL"); //$NON-NLS-1$
                }
                return getComponent().urlFor(this, AlwaysLastPageVersionRequestListenerInterface.INTERFACE);
            }

            @Override
            protected String findIndicatorId() {
                return null; // main page defines it and the timer shouldnt show it
            }

            /*
             * this can't be isEnabled(component) of the behavior itself because IE8 will constant call this on closed (modal)windows. So then this is
             * marked as disabled and an AbortException is thrown what our code sees as a server error and will constantly restart the timer.
             */
            private boolean isServoyEnabled() {
                return ((getController() != null && getController().isFormVisible()) || closingAsWindow);
            }

        });

    }
    add(new TriggerOrientationChangeAjaxBehavior());
    add(new TriggerResizeAjaxBehavior());

    add(new AbstractServoyLastVersionAjaxBehavior() {
        @Override
        protected void execute(AjaxRequestTarget target) {
            for (ServoyDivDialog divDialog : divDialogs.getOrderedByOpenSequence()) {
                if (!divDialog.isShown()) {
                    // this means a refresh was probably triggered and we must re-show these... because we do not keep closed dialogs in divDialogs
                    int x = divDialog.getX();
                    int y = divDialog.getY();
                    int w = divDialog.getWidth();
                    int h = divDialog.getHeight();
                    divDialog.show(target, null);
                    divDialog.setBounds(target, x, y, w, h, null);
                }
            }
            WebEventExecutor.generateResponse(target, MainPage.this);
        }

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            response.renderOnDomReadyJavascript(getCallbackScript(true).toString());
        }

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

    body = new WebMarkupContainer("servoy_page") //$NON-NLS-1$
    {
        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
         */
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.putAll(bodyAttributes);
        }
    };
    body.add(new AttributeModifier("dir", true, new AbstractReadOnlyModel<String>() //$NON-NLS-1$
    {

        @Override
        public String getObject() {
            String value = AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE;
            Locale l = client.getLocale();
            Solution solution = client.getSolution();

            if (solution != null && l != null) {
                value = OrientationApplier.getHTMLContainerOrientation(l, solution.getTextOrientation());
            }
            return value;
        }
    }));

    add(body);
    pageContributor = new PageContributor(client, "contribution");
    body.add(pageContributor);

    Label loadingIndicator = new Label("loading_indicator", sc.getI18NMessage("servoy.general.loading"));
    loadingIndicator.add(new SimpleAttributeModifier("style", "display:none;"));

    body.add(loadingIndicator);
    divDialogsParent = new WebMarkupContainer(DIV_DIALOGS_REPEATER_PARENT_ID);
    divDialogsParent.setOutputMarkupPlaceholderTag(true);
    divDialogsParent.setVisible(false);
    body.add(divDialogsParent);

    if (useAJAX) {
        add(new TriggerUpdateAjaxBehavior()); // for when another page needs to trigger an ajax update on this page using js (see media upload)

        divDialogRepeater = new RepeatingView(DIV_DIALOG_REPEATER_ID);
        divDialogsParent.add(divDialogRepeater);

        fileUploadWindow = new ServoyDivDialog(FILE_UPLOAD_DIALOG_ID);
        body.add(fileUploadWindow);
        fileUploadWindow.setModal(true);
        fileUploadWindow.setPageMapName(null);
        fileUploadWindow.setCookieName("dialog_fileupload");
        fileUploadWindow.setResizable(true);
        fileUploadWindow.setInitialHeight(150);
        fileUploadWindow.setInitialWidth(400);
        fileUploadWindow.setMinimalHeight(130);
        fileUploadWindow.setMinimalWidth(400);
        fileUploadWindow.setUseInitialHeight(true); // no effect, can be removed
        fileUploadWindow.setPageCreator(new ModalWindow.PageCreator() {
            private static final long serialVersionUID = 1L;

            public Page createPage() {
                return new MediaUploadPage(PageMap.forName(FILE_UPLOAD_PAGEMAP), mediaUploadCallback,
                        mediaUploadMultiSelect, getController().getApplication());
            }
        });
        fileUploadWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
            private static final long serialVersionUID = 1L;

            public void onClose(AjaxRequestTarget target) {
                divDialogs.remove(FILE_UPLOAD_PAGEMAP);
                fileUploadWindow.setPageMapName(null);
                fileUploadWindow.remove(fileUploadWindow.getContentId());
                restoreFocusedComponentInParentIfNeeded();
                WebEventExecutor.generateResponse(target, findPage());
            }
        });
    } else {
        divDialogsParent.add(new Label("divdialogs"));
        body.add(new Label("fileuploaddialog")); //$NON-NLS-1$
    }

    IModel<String> styleHrefModel = new AbstractReadOnlyModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            if (main != null) {
                return getRequest().getRelativePathPrefixToContextRoot() + "servoy-webclient/templates/" + //$NON-NLS-1$
                client.getClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR)
                        + "/servoy_web_client_default.css"; //$NON-NLS-1$
            }
            return null;
        }
    };
    Label main_form_style = new Label("main_form_style"); //$NON-NLS-1$
    main_form_style.add(new AttributeModifier("href", true, styleHrefModel)); //$NON-NLS-1$
    add(main_form_style);

    IModel<List<IFormUIInternal<?>>> loopModel = new AbstractReadOnlyModel<List<IFormUIInternal<?>>>() {
        private static final long serialVersionUID = 1L;

        @Override
        public List<IFormUIInternal<?>> getObject() {
            return webForms;
        }
    };

    listview = new ListView<IFormUIInternal<?>>("forms", loopModel) //$NON-NLS-1$
    {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<IFormUIInternal<?>> item) {
            final WebForm form = (WebForm) item.getModelObject();
            tempRemoveMainForm = true;
            try {
                if (form.getParent() != null) {
                    form.remove(); // TODO isn't this already done by item.add(form) below in wicket's impl?
                }
                item.add(form);
            } finally {
                tempRemoveMainForm = false;
            }

            IFormLayoutProvider layoutProvider = FormLayoutProviderFactory.getFormLayoutProvider(client,
                    client.getSolution(), form.getController().getForm(), form.getController().getName());

            TextualStyle styleToReturn = null;

            if ((navigator != null) && (form == navigator.getFormUI())) {
                styleToReturn = layoutProvider.getLayoutForForm(navigator.getForm().getSize().width, true,
                        false);
            } else if (form == main) {
                int customNavWidth = 0;
                if (navigator != null)
                    customNavWidth = navigator.getForm().getSize().width;
                styleToReturn = layoutProvider.getLayoutForForm(customNavWidth, false, false);
            }
            if (styleToReturn != null) {
                form.add(new StyleAppendingModifier(styleToReturn) {
                    @Override
                    public boolean isEnabled(Component component) {
                        // Laurian: looks like bogus condition, shouldn't this be || as in WebForm ?
                        return (component.findParent(WebTabPanel.class) == null)
                                && (component.findParent(WebSplitPane.class) == null);
                    }
                });
            }
            TabIndexHelper.setUpTabIndexAttributeModifier(item, ISupportWebTabSeq.SKIP);
        }

        @Override
        protected ListItem<IFormUIInternal<?>> newItem(final int index) {
            return new ListItem<IFormUIInternal<?>>(index, getListItemModel(getModel(), index)) {
                @Override
                public void remove(Component component) {
                    super.remove(component);
                    // for example when a form is shown in a popup form (window plugin) it must know that it's main page changed
                    if (!tempRemoveMainForm && component instanceof WebForm) {
                        WebForm formUI = ((WebForm) component);
                        if (MainPage.this == formUI.getMainPage()) {
                            // if the form is visible and it will be now removed from the mainpage
                            // then call notifyVisble false on it to let the form know it will hide
                            // we can't do much if that is blocked by an onhide here.
                            // (could be triggered by a browser back button)
                            if (formUI.getController().isFormVisible()) {
                                List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
                                formUI.getController().notifyVisible(false, invokeLaterRunnables);
                                Utils.invokeLater(client, invokeLaterRunnables);
                            }
                            formUI.setMainPage(null);
                        }
                    }
                }
            };
        }

        /**
         * @see org.apache.wicket.markup.html.list.ListView#onBeforeRender()
         */
        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            // now first initialize all the tabs so that data from
            // tab x doesn't change anymore (so that it could alter data in tab y)
            // don't know if this still does anything because we need to do it
            // in the onBeforeRender of WebTabPanel itself, else tableviews don't have there models yet..
            visitChildren(WebTabPanel.class, new IVisitor<WebTabPanel>() {
                public Object component(WebTabPanel wtp) {
                    wtp.initalizeFirstTab();
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });

            addWebAnchoringInfoIfNeeded();
        }
    };
    listview.setReuseItems(true);
    // if versioning is disabled then table views can go wrong (don't rollback on a submit)
    //listview.setVersioned(false);

    Form form = new ServoyForm("servoy_dataform"); //$NON-NLS-1$

    form.add(new SimpleAttributeModifier("autocomplete", "off")); //$NON-NLS-1$ //$NON-NLS-2$
    if (useAJAX)
        form.add(new SimpleAttributeModifier("onsubmit", "return false;")); //$NON-NLS-1$ //$NON-NLS-2$

    form.add(listview);
    WebMarkupContainer defaultButton = new WebMarkupContainer("defaultsubmitbutton", new Model()); //$NON-NLS-1$
    defaultButton.setVisible(!useAJAX);
    form.add(defaultButton);

    StylePropertyChangeMarkupContainer container = new StylePropertyChangeMarkupContainer("externaldivsparent");
    form.add(container);
    PageContributorRepeatingView repeatingView = new PageContributorRepeatingView("externaldivs", container);
    container.add(repeatingView);
    pageContributor.addRepeatingView(repeatingView);

    body.add(form);
}

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

License:Open Source License

private String getOrientation() {
    String orientation = OrientationApplier.getHTMLContainerOrientation(application.getLocale(),
            application.getSolution().getTextOrientation());
    if (orientation.equals(AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE))
        orientation = "ltr"; //$NON-NLS-1$
    return orientation;
}

From source file:com.servoy.j2db.util.OrientationApplier.java

License:Open Source License

/**
 * Calculates & returns the value for the "dir" attribute that must be added to HTML tags for the
 * given orientation/locale value pair. If no such attribute must be added,
 * returns {@link AttributeModifier#VALUELESS_ATTRIBUTE_REMOVE}.
 * @param l the locale (needed if the orientation is {@link Solution#TEXT_ORIENTATION_LOCALE_SPECIFIC}).
 * @param orientation the orientation to set. One of the constants defined in {@link Solution}.
 * @return the value for the "dir" attribute that must be added to HTML tags for the
 * given orientation/locale value pair ("ltr", "rtl"). If no such attribute must be added, returns {@link AttributeModifier#VALUELESS_ATTRIBUTE_REMOVE}.
 *//* ww  w .  ja va2s  . c om*/
public static String getHTMLContainerOrientation(Locale l, int orientation) {
    String value = AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE;

    switch (orientation) {
    // case Solution.TEXT_ORIENTATION_DEFAULT: attribute must not be present - so no change
    case Solution.TEXT_ORIENTATION_LEFT_TO_RIGHT:
        value = LTR;
        break;
    case Solution.TEXT_ORIENTATION_RIGHT_TO_LEFT:
        value = RTL;
        break;
    case Solution.TEXT_ORIENTATION_LOCALE_SPECIFIC:
        value = (ComponentOrientation.getOrientation(l).isLeftToRight()) ? LTR : RTL;
        break;
    }
    return value;
}

From source file:org.eknet.wicket.commons.components.buttons.ExtendedButton.java

License:Apache License

public ExtendedButton setCssClass(@Nullable String cssClass) {
    if (cssClass != null) {
        innerButton.add(new AttributeModifier("class", cssClass));
    } else {/*from   w w  w.ja  va2s . c  om*/
        innerButton.add(new AttributeModifier("class", AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE));
    }
    return this;
}