Example usage for org.apache.wicket.markup.html.list ListItem ListItem

List of usage examples for org.apache.wicket.markup.html.list ListItem ListItem

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.list ListItem ListItem.

Prototype

public ListItem(final String id, final int index) 

Source Link

Document

Constructor

Usage

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  2s  .c  o 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:org.apache.syncope.client.console.wicket.markup.html.list.AltListView.java

License:Apache License

@Override
protected ListItem<T> newItem(final int index, final IModel<T> itemModel) {
    return new ListItem<T>(index, itemModel) {

        private static final long serialVersionUID = 5473483270932376694L;

        @Override//from   w w w  .  j  a  v a  2s .c o  m
        protected void onComponentTag(final ComponentTag tag) {
            if (index % 2 == 0) {
                tag.append("class", "alt", " ");
            }

            super.onComponentTag(tag);
        }
    };
}

From source file:org.jabylon.rest.ui.wicket.components.ListEditor.java

License:Open Source License

public void addItem(T value) {
    items.add(value);
    ListItem<T> item = new ListItem<T>(newChildId(), items.size() - 1);
    add(item);
    onPopulateItem(item);
}

From source file:org.jabylon.rest.ui.wicket.components.ListEditor.java

License:Open Source License

protected void onBeforeRender() {
    if (!hasBeenRendered()) {
        @SuppressWarnings("unchecked")
        List<T> list = (List<T>) getDefaultModelObject();
        items = new ArrayList<T>(list);
        for (int i = 0; i < items.size(); i++) {
            ListItem<T> li = new ListItem<T>(newChildId(), i);
            add(li);//from   w ww  .j  a v  a2s .c  om
            onPopulateItem(li);
        }
    }
    super.onBeforeRender();
}