Search in sources :

Example 76 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project hale by halestudio.

the class StatusPage method addControls.

@Override
protected void addControls(boolean loggedIn) {
    super.addControls(loggedIn);
    final String workspaceId = getPageParameters().get(PARAMETER_WORKSPACE).toOptionalString();
    if (workspaceId == null || workspaceId.isEmpty()) {
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace ID not specified.");
    }
    try {
        workspaces.getWorkspaceFolder(workspaceId);
    } catch (FileNotFoundException e) {
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace does not exist.");
    }
    final IModel<TransformationWorkspace> workspace = new LoadableDetachableModel<TransformationWorkspace>() {

        private static final long serialVersionUID = 2600444242247550094L;

        @Override
        protected TransformationWorkspace load() {
            return new TransformationWorkspace(workspaceId);
        }
    };
    // job panel
    final Serializable family = AbstractTransformationJob.createFamily(workspaceId);
    final JobPanel jobs = new JobPanel("jobs", family, true);
    add(jobs);
    // status
    final Label status = new Label("status", new LoadableDetachableModel<String>() {

        private static final long serialVersionUID = -4351763182104835300L;

        @Override
        protected String load() {
            if (workspace.getObject().isTransformationFinished()) {
                if (workspace.getObject().isTransformationSuccessful()) {
                    return "Transformation completed.";
                } else {
                    return "Transformation failed.";
                }
            } else {
                if (Job.getJobManager().find(family).length > 0) {
                    return "Transformation is running:";
                } else {
                    return "No transformation running.";
                }
            }
        }
    });
    status.setOutputMarkupId(true);
    add(status);
    // result
    final WebMarkupContainer result = new WebMarkupContainer("result");
    result.setOutputMarkupId(true);
    add(result);
    final WebMarkupContainer update = new WebMarkupContainer("update") {

        private static final long serialVersionUID = -2591480922683644827L;

        @Override
        public boolean isVisible() {
            return workspace.getObject().isTransformationFinished();
        }
    };
    result.add(update);
    // result : report
    File reportFile = workspace.getObject().getReportFile();
    DownloadLink report = new DownloadLink("log", reportFile, reportFile.getName());
    update.add(report);
    // result : file list
    IModel<? extends List<File>> resultFilesModel = new LoadableDetachableModel<List<File>>() {

        private static final long serialVersionUID = -7971872898614031331L;

        @Override
        protected List<File> load() {
            return Arrays.asList(workspace.getObject().getTargetFolder().listFiles());
        }
    };
    final ListView<File> fileList = new ListView<File>("file", resultFilesModel) {

        private static final long serialVersionUID = -8045643864251639540L;

        @Override
        protected void populateItem(ListItem<File> item) {
            // download link
            DownloadLink download = new DownloadLink("download", item.getModelObject(), item.getModelObject().getName());
            item.add(download);
            // file name
            download.add(new Label("name", item.getModelObject().getName()));
        }
    };
    update.add(fileList);
    // leaseEnd
    String leaseEnd;
    try {
        leaseEnd = workspaces.getLeaseEnd(workspaceId).toString(DateTimeFormat.mediumDateTime());
    } catch (IOException e) {
        leaseEnd = "unknown";
    }
    add(new Label("leaseEnd", leaseEnd));
    boolean transformationFinished = workspace.getObject().isTransformationFinished();
    if (transformationFinished) {
        // disable job timer
        jobs.getTimer().stopOnNextUpdate();
    } else {
        // timer
        add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1500)) {

            private static final long serialVersionUID = -3726349470723024150L;

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                if (workspace.getObject().isTransformationFinished()) {
                    // update status and result
                    target.add(status);
                    target.add(result);
                    // stop timers
                    stop(target);
                    jobs.getTimer().stopOnNextUpdate();
                }
            }
        });
    }
}
Also used : TransformationWorkspace(eu.esdihumboldt.hale.common.headless.transform.TransformationWorkspace) DownloadLink(org.apache.wicket.markup.html.link.DownloadLink) Serializable(java.io.Serializable) AbortWithHttpErrorCodeException(org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException) FileNotFoundException(java.io.FileNotFoundException) Label(org.apache.wicket.markup.html.basic.Label) IOException(java.io.IOException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) AbstractAjaxTimerBehavior(org.apache.wicket.ajax.AbstractAjaxTimerBehavior) ListItem(org.apache.wicket.markup.html.list.ListItem) JobPanel(eu.esdihumboldt.hale.server.webapp.components.JobPanel) File(java.io.File)

Example 77 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project webanno by webanno.

the class AnnotationPreferencesDialogContent method createLayerContainer.

private ListView<AnnotationLayer> createLayerContainer() {
    return new ListView<AnnotationLayer>("annotationLayers") {

        private static final long serialVersionUID = -4040731191748923013L;

        @Override
        protected void populateItem(ListItem<AnnotationLayer> item) {
            // add checkbox
            // get initial state
            AnnotationPreference pref = stateModel.getObject().getPreferences();
            List<Long> hiddenLayerIds = pref.getHiddenAnnotationLayerIds();
            boolean isPreferredToShow = !hiddenLayerIds.contains(item.getModelObject().getId());
            CheckBox layer_cb = new CheckBox("annotationLayerActive", Model.of(isPreferredToShow));
            layer_cb.add(new AjaxEventBehavior("change") {

                private static final long serialVersionUID = 8378489004897115519L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    // check state & live update preferences
                    List<Long> hiddenLayerIds = stateModel.getObject().getPreferences().getHiddenAnnotationLayerIds();
                    // get and switch state of checkbox
                    boolean isPreferredToShow = layer_cb.getModelObject();
                    layer_cb.setModelObject(!isPreferredToShow);
                    // live update preferences
                    if (isPreferredToShow) {
                        // prefer to deactivate layer
                        hiddenLayerIds.add(item.getModelObject().getId());
                    } else {
                        // prefer to activate layer
                        hiddenLayerIds.remove(item.getModelObject().getId());
                    }
                }
            });
            item.add(layer_cb);
            // add coloring strategy combobox
            ChoiceRenderer<ColoringStrategyType> choiceRenderer = new ChoiceRenderer<>("descriptiveName");
            List<ColoringStrategyType> choices = new ArrayList<ColoringStrategyType>(EnumSet.allOf(ColoringStrategyType.class));
            Model<ColoringStrategyType> initialSelected = Model.of(form.getModelObject().colorPerLayer.get(item.getModelObject().getId()));
            DropDownChoice<ColoringStrategyType> layer_color = new DropDownChoice<ColoringStrategyType>("layercoloring", initialSelected, choices, choiceRenderer);
            layer_color.add(new AjaxFormComponentUpdatingBehavior("change") {

                private static final long serialVersionUID = 1060397773470276585L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    AnnotationLayer current_layer = item.getModelObject();
                    ColoringStrategyType selectedColor = layer_color.getModelObject();
                    form.getModelObject().colorPerLayer.put(current_layer.getId(), selectedColor);
                }
            });
            item.add(layer_color);
            // add label
            Label lbl = new Label("annotationLayerDesc", item.getModelObject().getUiName());
            item.add(lbl);
        }
    };
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy.ColoringStrategyType)

Example 78 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project syncope by apache.

the class LogsITCase method searchLog.

private Component searchLog(final String property, final String searchPath, final String key) {
    Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
    Component result = component.getPage().visitChildren(ListItem.class, (final ListItem<LoggerTO> object, final IVisit<Component> visit) -> {
        try {
            if (object.getModelObject() instanceof LoggerTO && PropertyResolver.getPropertyGetter(property, object.getModelObject()).invoke(object.getModelObject()).equals(key)) {
                visit.stop(object);
            }
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            LOG.error("Error invoke method", ex);
        }
    });
    return result;
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) IVisit(org.apache.wicket.util.visit.IVisit) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 79 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project ocvn by devgateway.

the class FileInputBootstrapFormComponentWrapper method addAlreadyUploadedFilesComponent.

/**
 * already uploaded files section
 */
private void addAlreadyUploadedFilesComponent() {
    alreadyUploadedFiles = new WebMarkupContainer("alreadyUploadedFiles") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            setVisibilityAllowed(isVisibleAlreadyUploadedFiles());
        }
    };
    alreadyUploadedFiles.setOutputMarkupPlaceholderTag(true);
    alreadyUploadedFiles.setOutputMarkupId(true);
    add(alreadyUploadedFiles);
    alreadyUploadedFiles.add(new Label("uploadedFilesTitle", new StringResourceModel("uploadedFilesTitle", this, null)));
    AbstractReadOnlyModel<List<FileMetadata>> alreadyUploadedFilesModel = new AbstractReadOnlyModel<List<FileMetadata>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<FileMetadata> getObject() {
            List<FileMetadata> fileObject = new ArrayList<>();
            // get only the already uploaded files
            for (FileMetadata file : filesModel) {
                if (!file.isNew()) {
                    fileObject.add(file);
                }
            }
            return fileObject;
        }
    };
    ListView<FileMetadata> list = new ListView<FileMetadata>("list", alreadyUploadedFilesModel) {

        private static final long serialVersionUID = 1L;

        private List<IndicatingAjaxLink<Void>> deleteButtons = new ArrayList<>();

        @Override
        protected void populateItem(final ListItem<FileMetadata> item) {
            // make file name clickable
            Link<FileMetadata> downloadLink = new Link<FileMetadata>("downloadLink", item.getModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    final FileMetadata modelObject = getModelObject();
                    AbstractResourceStreamWriter rstream = new AbstractResourceStreamWriter() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void write(final OutputStream output) throws IOException {
                            output.write(modelObject.getContent().getBytes());
                        }

                        @Override
                        public String getContentType() {
                            return modelObject.getContentType();
                        }
                    };
                    ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(rstream, modelObject.getName());
                    handler.setContentDisposition(ContentDisposition.ATTACHMENT);
                    getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
                }
            };
            downloadLink.add(new Label("downloadText", item.getModelObject().getName()));
            downloadLink.add(new TooltipBehavior(new StringResourceModel("downloadUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            item.add(downloadLink);
            Link<FileMetadata> download = new CustomDownloadLink("download", item.getModel());
            item.add(download);
            IndicatingAjaxLink<Void> delete = new IndicatingAjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                public void onClick(final AjaxRequestTarget target) {
                    filesModel.remove(item.getModelObject());
                    FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
                    target.add(alreadyUploadedFiles);
                }
            };
            delete.add(new IconBehavior(GlyphIconType.remove));
            delete.add(new TooltipBehavior(new StringResourceModel("removeUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            delete.setVisible(true);
            item.add(delete);
            deleteButtons.add(delete);
            // only to admins
            if (visibleOnlyToAdmin) {
                MetaDataRoleAuthorizationStrategy.authorize(delete, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
            }
            if (disableDeleteButton) {
                delete.setVisibilityAllowed(false);
            }
        }

        @Override
        public void onEvent(final IEvent<?> event) {
            /*
                 * disable 'delete' buttons based on the form state
                 */
            if (event.getPayload() instanceof EditingDisabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(false);
                }
            }
            if (event.getPayload() instanceof EditingEnabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(true);
                }
            }
        }
    };
    alreadyUploadedFiles.add(list);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IEvent(org.apache.wicket.event.IEvent) OutputStream(java.io.OutputStream) Label(org.apache.wicket.markup.html.basic.Label) FileMetadata(org.devgateway.toolkit.persistence.dao.FileMetadata) ArrayList(java.util.ArrayList) AbstractResourceStreamWriter(org.apache.wicket.util.resource.AbstractResourceStreamWriter) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) IconBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) TooltipBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ArrayList(java.util.ArrayList) List(java.util.List) EditingDisabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent) StringResourceModel(org.apache.wicket.model.StringResourceModel) EditingEnabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingEnabledEvent) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListItem(org.apache.wicket.markup.html.list.ListItem) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) Link(org.apache.wicket.markup.html.link.Link) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)

Example 80 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project wicket by apache.

the class ComponentQueueingTest method repeater2.

/**
 * repeater
 */
@Test
public void repeater2() {
    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='a'><p wicket:id='lv'><p wicket:id='b'><p wicket:id='c'></p></p></p></p>");
    MarkupContainer a = new A();
    LV l = new LV(3) {

        @Override
        protected void populateItem(ListItem<Integer> item) {
            item.queue(new B(), new C());
        }
    };
    p.queue(a, l);
    tester.startPage(p);
    assertThat(l.size(), is(3));
    for (Component item : l) {
        assertThat(p, hasPath(new Path(a, l, item, new B(), new C())));
    }
}
Also used : WicketMatchers.hasPath(org.apache.wicket.queueing.WicketMatchers.hasPath) MarkupContainer(org.apache.wicket.MarkupContainer) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) TransparentWebMarkupContainer(org.apache.wicket.markup.html.TransparentWebMarkupContainer) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) Test(org.junit.Test)

Aggregations

ListItem (org.apache.wicket.markup.html.list.ListItem)131 ListView (org.apache.wicket.markup.html.list.ListView)107 Label (org.apache.wicket.markup.html.basic.Label)82 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)73 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)72 IModel (org.apache.wicket.model.IModel)44 List (java.util.List)42 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)40 ArrayList (java.util.ArrayList)38 PropertyModel (org.apache.wicket.model.PropertyModel)28 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)23 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)23 TextField (org.apache.wicket.markup.html.form.TextField)17 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)14 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)14 QName (javax.xml.namespace.QName)13 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)13 Model (org.apache.wicket.model.Model)12 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)11 AttributeModifier (org.apache.wicket.AttributeModifier)11