Example usage for org.apache.wicket.markup.html.image NonCachingImage NonCachingImage

List of usage examples for org.apache.wicket.markup.html.image NonCachingImage NonCachingImage

Introduction

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

Prototype

public NonCachingImage(String id, String string) 

Source Link

Document

Construct.

Usage

From source file:au.org.theark.study.web.component.managestudy.form.DetailForm.java

License:Open Source License

private void initStudyLogo() {
    // Set maximum logo image size to 100K
    setMaxSize(Bytes.kilobytes(Constants.STUDY_LOGO_FILESIZE_KB));

    if (containerForm.getModelObject().getStudy() != null
            && containerForm.getModelObject().getStudy().getStudyLogoBlob() != null) {
        final java.sql.Blob studyLogoBlob = containerForm.getModelObject().getStudy().getStudyLogoBlob();

        if (studyLogoBlob != null) {
            BlobImageResource blobImageResource = new BlobImageResource() {
                private static final long serialVersionUID = 1L;

                @Override/*  w w w .  j av  a 2 s .c o m*/
                protected Blob getBlob() {
                    return studyLogoBlob;
                }
            };

            studyLogoImage = new NonCachingImage("study.studyLogoImage", blobImageResource);
        }
    } else {
        studyLogoImage = new NonCachingImage("study.studyLogoImage", NO_STUDY_LOGO);
    }

    studyLogoImage.setVisible(true);
    studyLogoImage.setOutputMarkupPlaceholderTag(true);
    studyCrudVO.getDetailPanelFormContainer().addOrReplace(studyLogoImage);
}

From source file:com.apachecon.memories.service.UserFile.java

License:Apache License

private Image createImage(String id, boolean small) {
    File f = small ? thumb : file;

    IResource resource = new ResourceStreamResource(new FileResourceStream(f));
    return new NonCachingImage(id, resource);
}

From source file:com.doculibre.constellio.wicket.panels.admin.collection.CollectionListPanel.java

License:Open Source License

@Override
protected List<IColumn> getDataColumns() {
    List<IColumn> dataColumns = super.getDataColumns();

    IColumn descriptionColumn = new PropertyColumn(new StringResourceModel("description", this, null),
            "description") {
        @Override/*from  www .java  2  s . co  m*/
        protected IModel createLabelModel(final IModel embeddedModel) {
            return new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    RecordCollection collection = (RecordCollection) embeddedModel.getObject();
                    return collection.getDescription(getLocale());
                }
            };
        }

    };
    dataColumns.add(descriptionColumn);
    // Move up
    dataColumns.add(new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ImgLinkHolder(componentId) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            RecordCollectionServices collectionServices = ConstellioSpringUtils
                                    .getRecordCollectionServices();
                            RecordCollection collection = (RecordCollection) rowModel.getObject();
                            List<RecordCollection> collections = collectionServices.list();
                            int index = collections.indexOf(collection);
                            // Cannot move higher!
                            if (index > 0) {
                                RecordCollection previousCollection = collections.get(index - 1);
                                Integer previousPosition = previousCollection.getPosition();
                                Integer currentPosition = collection.getPosition();
                                collection.setPosition(previousPosition);
                                previousCollection.setPosition(currentPosition);

                                EntityManager entityManager = ConstellioPersistenceContext
                                        .getCurrentEntityManager();
                                if (!entityManager.getTransaction().isActive()) {
                                    entityManager.getTransaction().begin();
                                }
                                collectionServices.makePersistent(collection, false);
                                collectionServices.makePersistent(previousCollection, false);
                                entityManager.getTransaction().commit();
                                entityManager.clear();

                                target.addComponent(findParent(CollectionListPanel.class));
                            }
                        }
                    };
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/up.png"));
                }
            });
        }
    });

    // Move down
    dataColumns.add(new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ImgLinkHolder(componentId) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            RecordCollectionServices collectionServices = ConstellioSpringUtils
                                    .getRecordCollectionServices();
                            RecordCollection collection = (RecordCollection) rowModel.getObject();
                            List<RecordCollection> collections = collectionServices.list();
                            int index = collections.indexOf(collection);
                            // Cannot move lower!
                            if (index < collections.size() - 1) {
                                RecordCollection nextCollection = collections.get(index + 1);
                                Integer nextPosition = nextCollection.getPosition();
                                Integer currentPosition = collection.getPosition();
                                collection.setPosition(nextPosition);
                                nextCollection.setPosition(currentPosition);

                                EntityManager entityManager = ConstellioPersistenceContext
                                        .getCurrentEntityManager();
                                if (!entityManager.getTransaction().isActive()) {
                                    entityManager.getTransaction().begin();
                                }
                                collectionServices.makePersistent(collection, false);
                                collectionServices.makePersistent(nextCollection, false);
                                entityManager.getTransaction().commit();
                                entityManager.clear();

                                target.addComponent(findParent(CollectionListPanel.class));
                            }
                        }
                    };
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/down.png"));
                }
            });
        }
    });

    IColumn searchColumn = new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new LinkHolder(componentId) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    RecordCollection collection = (RecordCollection) rowModel.getObject();
                    SimpleSearch simpleSearch = new SimpleSearch();
                    simpleSearch.setCollectionName(collection.getName());
                    PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
                    return new BookmarkablePageLink(id, pageFactoryPlugin.getSearchFormPage(),
                            SearchFormPage.getParameters(simpleSearch));
                }

                @Override
                protected IModel getLabelModel() {
                    return new StringResourceModel("search", null);
                }
            });
        }
    };
    dataColumns.add(searchColumn);
    return dataColumns;
}

From source file:com.doculibre.constellio.wicket.panels.admin.connector.ConnectorListPanel.java

License:Open Source License

@Override
protected List<IColumn> getDataColumns() {
    List<IColumn> dataColumns = super.getDataColumns();
    dataColumns.add(0, new HeaderlessColumn() {
        @Override//  www .  j a v  a 2 s.c o m
        public void populateItem(Item cellItem, String componentId, IModel rowModel) {
            ConnectorInstance connectorInstance = (ConnectorInstance) rowModel.getObject();
            final ReloadableEntityModel<ConnectorInstance> connectorInstanceModel = new ReloadableEntityModel<ConnectorInstance>(
                    connectorInstance);
            cellItem.add(new ImgHolder(componentId) {
                @Override
                protected Image newImg(String id) {
                    ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                    ConnectorType connectorType = connectorInstance.getConnectorType();
                    ResourceReference imageResourceReference = new ResourceReference(
                            "connectorType_" + connectorType.getId()) {
                        @Override
                        protected Resource newResource() {
                            ConnectorInstance connectorInstance = (ConnectorInstance) connectorInstanceModel
                                    .getObject();
                            ConnectorType connectorType = connectorInstance.getConnectorType();
                            Resource imageResource;
                            byte[] iconBytes = connectorType.getIconFileContent();
                            // Convert resource path to absolute path relative to base package
                            if (iconBytes != null) {
                                imageResource = new ByteArrayResource("image", iconBytes);
                            } else {
                                imageResource = PackageResource.get(ConnectorListPanel.class,
                                        "default_icon.gif");
                            }
                            return imageResource;
                        }
                    };
                    return new NonCachingImage(id, imageResourceReference);
                }

                @Override
                public void detachModels() {
                    connectorInstanceModel.detach();
                    super.detachModels();
                }
            });
        }
    });
    return dataColumns;
}

From source file:com.doculibre.constellio.wicket.panels.admin.crud.CRUDPanel.java

License:Open Source License

protected IColumn getEditLinkColumn() {
    return new HeaderlessColumn() {
        @Override/*from   ww w. java  2s. co m*/
        public void populateItem(Item cellItem, String componentId, final IModel rowItemModel) {
            Item rowItem = (Item) cellItem.findParent(Item.class);
            final int rowIndex = getFirstRowItemAbsoluteIndex() + rowItem.getIndex();
            cellItem.add(new ModalImgLinkHolder(componentId) {
                @Override
                public WebMarkupContainer newLink(String id) {
                    if (isUseModalsAddEdit()) {
                        return new AjaxLink(id) {
                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                ModalWindow editModal = getModalWindow();
                                editModal.setInitialHeight(MODAL_HEIGHT);
                                editModal.setInitialWidth(MODAL_WIDTH);
                                String editMsg = getLocalizer().getString("edit", CRUDPanel.this);
                                editModal.setTitle(editMsg);

                                WebMarkupContainer editContent = createEditContent(editModal.getContentId(),
                                        rowItemModel, rowIndex);
                                editModal.setContent(editContent);
                                editModal.show(target);
                            }

                            @Override
                            public boolean isVisible() {
                                return super.isVisible() && isEditLink(rowItemModel, rowIndex);
                            }
                        };
                    } else {
                        return new Link(id) {
                            @Override
                            public void onClick() {
                                WebMarkupContainer editContent = createEditContent(CRUDPanel.this.getId(),
                                        rowItemModel, rowIndex);
                                CRUDPanel.this.replaceWith(editContent);
                            }

                            @Override
                            public boolean isVisible() {
                                return super.isVisible() && isEditLink(rowItemModel, rowIndex);
                            }
                        };
                    }
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/ico_crayon.png"));
                }
            });
        }

        @Override
        public String getCssClass() {
            return "aligncenter width50px";
        }
    };
}

From source file:com.doculibre.constellio.wicket.panels.admin.crud.CRUDPanel.java

License:Open Source License

protected IColumn getDeleteLinkColumn() {
    return new HeaderlessColumn() {
        @Override/*from  w w  w . jav  a 2  s. c om*/
        public void populateItem(Item cellItem, String componentId, final IModel rowItemModel) {
            Item rowItem = (Item) cellItem.findParent(Item.class);
            final int rowIndex = getFirstRowItemAbsoluteIndex() + rowItem.getIndex();
            cellItem.add(new ImgLinkHolder(componentId) {
                @Override
                public WebMarkupContainer newLink(String id) {
                    return createDeleteLink(id, rowItemModel, rowIndex);
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/ico_poubelle.png"));
                }
            });
        }

        @Override
        public String getCssClass() {
            return "aligncenter width50px";
        }
    };
}

From source file:com.doculibre.constellio.wicket.panels.admin.facets.FacetListPanel.java

License:Open Source License

@Override
protected List<IColumn> getDataColumns() {
    List<IColumn> dataColumns = super.getDataColumns();

    dataColumns.add(new HeaderlessColumn() {
        @Override// w  ww .ja v a2  s  .c om
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ModalLinkHolder(componentId,
                    new StringResourceModel("labelledValues", FacetListPanel.this, null)) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            ModalWindow labelledValuesModal = getModalWindow();
                            CollectionFacet facet = (CollectionFacet) rowModel.getObject();
                            EditFacetLabelledValuesPanel editLabelledValuesModal = new EditFacetLabelledValuesPanel(
                                    labelledValuesModal.getContentId(), facet);
                            labelledValuesModal.setContent(editLabelledValuesModal);
                            labelledValuesModal.show(target);
                        }

                        @Override
                        public boolean isVisible() {
                            CollectionFacet facet = (CollectionFacet) rowModel.getObject();
                            return facet.isFieldFacet();
                        }
                    };
                }
            });
        }
    });

    dataColumns.add(new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ModalLinkHolder(componentId,
                    new StringResourceModel("queries", FacetListPanel.this, null)) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            ModalWindow queriesModal = getModalWindow();
                            CollectionFacet facet = (CollectionFacet) rowModel.getObject();
                            EditFacetLabelledValuesPanel editQueriesPanel = new EditFacetLabelledValuesPanel(
                                    queriesModal.getContentId(), facet);
                            queriesModal.setContent(editQueriesPanel);
                            queriesModal.show(target);
                        }

                        @Override
                        public boolean isVisible() {
                            CollectionFacet facet = (CollectionFacet) rowModel.getObject();
                            return facet.isQueryFacet();
                        }
                    };
                }
            });
        }
    });

    // Move up
    dataColumns.add(new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ImgLinkHolder(componentId) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            FacetServices facetServices = ConstellioSpringUtils.getFacetServices();
                            CollectionFacet facet = (CollectionFacet) rowModel.getObject();
                            RecordCollection collection = facet.getRecordCollection();

                            List<CollectionFacet> collectionFacets = collection.getCollectionFacets();
                            int index = collectionFacets.indexOf(facet);
                            // Cannot move higher!
                            if (index > 0) {
                                CollectionFacet previousFacet = collectionFacets.set(index - 1, facet);
                                collectionFacets.set(index, previousFacet);
                                EntityManager entityManager = ConstellioPersistenceContext
                                        .getCurrentEntityManager();
                                if (!entityManager.getTransaction().isActive()) {
                                    entityManager.getTransaction().begin();
                                }
                                facetServices.makePersistent(facet);
                                facetServices.makePersistent(previousFacet);
                                entityManager.getTransaction().commit();
                                entityManager.clear();

                                target.addComponent(findParent(AdminCollectionPanel.class));
                            }
                        }
                    };
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/up.png"));
                }
            });
        }
    });

    // Move down
    dataColumns.add(new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ImgLinkHolder(componentId) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            FacetServices facetServices = ConstellioSpringUtils.getFacetServices();
                            CollectionFacet facet = (CollectionFacet) rowModel.getObject();
                            RecordCollection collection = facet.getRecordCollection();

                            List<CollectionFacet> collectionFacets = collection.getCollectionFacets();
                            int index = collectionFacets.indexOf(facet);
                            // Cannot move lower!
                            if (index < collectionFacets.size() - 1) {
                                CollectionFacet previousFacet = collectionFacets.set(index + 1, facet);
                                collectionFacets.set(index, previousFacet);
                                EntityManager entityManager = ConstellioPersistenceContext
                                        .getCurrentEntityManager();
                                if (!entityManager.getTransaction().isActive()) {
                                    entityManager.getTransaction().begin();
                                }
                                facetServices.makePersistent(facet);
                                facetServices.makePersistent(previousFacet);
                                entityManager.getTransaction().commit();
                                entityManager.clear();

                                target.addComponent(findParent(AdminCollectionPanel.class));
                            }
                        }
                    };
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/down.png"));
                }
            });
        }
    });

    return dataColumns;
}

From source file:com.doculibre.constellio.wicket.panels.admin.searchResultField.SearchResultFieldListPanel.java

License:Open Source License

@Override
protected List<IColumn> getDataColumns() {
    List<IColumn> dataColumns = super.getDataColumns();

    // Move up//from   w ww.  j  a  v a2  s.  c  om
    dataColumns.add(new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ImgLinkHolder(componentId) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            SearchResultFieldServices searchResultFieldServices = ConstellioSpringUtils
                                    .getSearchResultFieldServices();
                            SearchResultField searchResultField = (SearchResultField) rowModel.getObject();
                            RecordCollection collection = searchResultField.getRecordCollection();

                            List<SearchResultField> searchResultFields = collection.getSearchResultFields();
                            int index = searchResultFields.indexOf(searchResultField);
                            // Cannot move higher!
                            if (index > 0) {
                                SearchResultField previousSearchResultField = searchResultFields.set(index - 1,
                                        searchResultField);
                                searchResultFields.set(index, previousSearchResultField);
                                EntityManager entityManager = ConstellioPersistenceContext
                                        .getCurrentEntityManager();
                                if (!entityManager.getTransaction().isActive()) {
                                    entityManager.getTransaction().begin();
                                }
                                searchResultFieldServices.makePersistent(searchResultField);
                                searchResultFieldServices.makePersistent(previousSearchResultField);
                                entityManager.getTransaction().commit();
                                entityManager.clear();

                                target.addComponent(findParent(AdminSearchResultFieldsPanel.class));
                            }
                        }
                    };
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/up.png"));
                }
            });
        }
    });

    // Move down
    dataColumns.add(new HeaderlessColumn() {
        @Override
        public void populateItem(Item cellItem, String componentId, final IModel rowModel) {
            cellItem.add(new ImgLinkHolder(componentId) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    return new AjaxLink(id) {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            SearchResultFieldServices searchResultFieldServices = ConstellioSpringUtils
                                    .getSearchResultFieldServices();
                            SearchResultField searchResultField = (SearchResultField) rowModel.getObject();
                            RecordCollection collection = searchResultField.getRecordCollection();

                            List<SearchResultField> searchResultFields = collection.getSearchResultFields();
                            int index = searchResultFields.indexOf(searchResultField);
                            // Cannot move lower!
                            if (index < searchResultFields.size() - 1) {
                                SearchResultField previousSearchResultField = searchResultFields.set(index + 1,
                                        searchResultField);
                                searchResultFields.set(index, previousSearchResultField);
                                EntityManager entityManager = ConstellioPersistenceContext
                                        .getCurrentEntityManager();
                                if (!entityManager.getTransaction().isActive()) {
                                    entityManager.getTransaction().begin();
                                }
                                searchResultFieldServices.makePersistent(searchResultField);
                                searchResultFieldServices.makePersistent(previousSearchResultField);
                                entityManager.getTransaction().commit();
                                entityManager.clear();

                                target.addComponent(findParent(AdminSearchResultFieldsPanel.class));
                            }
                        }
                    };
                }

                @Override
                protected Component newImg(String id) {
                    return new NonCachingImage(id,
                            new ResourceReference(BaseConstellioPage.class, "images/down.png"));
                }
            });
        }
    });

    return dataColumns;
}

From source file:com.doculibre.constellio.wicket.panels.admin.solrConfig.SolrConfigPanel.java

License:Open Source License

private ListView getPropertiesListView(List<PropertyRow> propertyRows) {
    return new ListView("properties", propertyRows) {

        @Override/*from   w w w . j  a  v a2  s  .c om*/
        protected void populateItem(final ListItem item) {

            final PropertyRow propertyRow = (PropertyRow) item.getModelObject();
            item.setOutputMarkupId(true);
            item.add(new Label("property",
                    new StringResourceModel(propertyRow.getMessageKey(), SolrConfigPanel.this, null)));
            IModel stateModel = new LoadableDetachableModel() {

                protected Object load() {
                    SolrConfig config = solrConfigModel.getObject();
                    boolean isSet = PropertyResolver.getValue(propertyRow.getProperty(), config) != null;
                    return new StringResourceModel(isSet ? "yes" : "no", SolrConfigPanel.this, null)
                            .getObject();
                }

            };
            item.add(new Label("state", stateModel));
            AjaxLink defaultValueLink = new AjaxLink("defaultValue") {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    SolrConfig config = solrConfigModel.getObject();
                    PropertyResolver.setValue(propertyRow.getProperty(), config, null, null);
                    target.addComponent(item);
                    save();
                }

                @Override
                public boolean isVisible() {
                    SolrConfig config = solrConfigModel.getObject();
                    return PropertyResolver.getValue(propertyRow.getProperty(), config) != null;
                }
            };
            item.add(defaultValueLink);
            IModel titleLabelModel = new LoadableDetachableModel() {

                @Override
                protected Object load() {
                    boolean isServerConfig = solrConfigModel.getObject().getRecordCollection() == null;
                    String resourceKey = isServerConfig ? "defaultValue" : "defaultServerValue";
                    return new StringResourceModel(resourceKey, SolrConfigPanel.this, null).getObject();
                }
            };
            defaultValueLink.add(new Label("label", titleLabelModel));

            if (propertyRow.isModalEdit()) {
                item.add(new ModalImgLinkHolder("editComponent") {
                    @Override
                    public WebMarkupContainer newLink(String id) {
                        return new AjaxLink(id) {
                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                ModalWindow editModal = getModalWindow();
                                editModal.setInitialHeight(MODAL_HEIGHT);
                                editModal.setInitialWidth(MODAL_WIDTH);
                                String editMsg = getLocalizer().getString("edit", SolrConfigPanel.this);
                                editModal.setTitle(editMsg);

                                WebMarkupContainer editContent = propertyRow
                                        .getEditLinkPanel(editModal.getContentId());
                                editModal.setContent(editContent);
                                editModal.show(target);
                                target.addComponent(item);
                            }
                        };
                    }

                    @Override
                    protected Component newImg(String id) {
                        return new NonCachingImage(id,
                                new ResourceReference(BaseConstellioPage.class, "images/ico_crayon.png"));
                    }
                });
            } else if (propertyRow.getType().equals(Boolean.class)) {
                final IModel valueModel = propertyRow.createModel();
                item.add(new CheckBoxHolder("editComponent") {

                    @Override
                    protected WebMarkupContainer newInput(String id) {
                        return new AjaxCheckBox(id, valueModel) {

                            @Override
                            protected void onUpdate(AjaxRequestTarget target) {
                                save();
                                target.addComponent(item);
                            }

                            @Override
                            public void detachModels() {
                                super.detachModels();
                                valueModel.detach();
                            }

                        };
                    }
                });
            } else {
                final IModel valueModel = propertyRow.createModel();
                item.add(new AjaxEditableLabel("editComponent", valueModel) {

                    @Override
                    protected void onSubmit(AjaxRequestTarget target) {
                        super.onSubmit(target);
                        save();
                        target.addComponent(item);
                    }

                    @Override
                    public void detachModels() {
                        super.detachModels();
                        valueModel.detach();
                    }

                });
            }

        }

    };
}

From source file:com.doculibre.constellio.wicket.panels.elevate.ElevatePanel.java

License:Open Source License

public ElevatePanel(String id, Record record, final SimpleSearch simpleSearch) {
    super(id);/*from  w w  w. j  ava  2  s .  com*/
    this.recordModel = new RecordModel(record);

    // Query without facets
    collectionName = simpleSearch.getCollectionName();

    Link elevateLink = new Link("elevateLink") {
        @Override
        public void onClick() {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
            if (!entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().begin();
            }
            Record record = recordModel.getObject();
            elevateServices.elevate(record, simpleSearch);
            entityManager.getTransaction().commit();

            PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
            RequestCycle.get().setResponsePage(pageFactoryPlugin.getSearchResultsPage(),
                    SearchResultsPage.getParameters(simpleSearch));
        }
    };
    add(elevateLink);
    elevateLink.add(new WebMarkupContainer("elevateImg") {
        @Override
        public boolean isVisible() {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            Record record = recordModel.getObject();
            return !elevateServices.isElevated(record, simpleSearch);
        }
    });
    elevateLink.add(new WebMarkupContainer("elevatedImg") {
        @Override
        public boolean isVisible() {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            Record record = recordModel.getObject();
            return elevateServices.isElevated(record, simpleSearch);
        }
    });

    add(new ModalImgLinkHolder("elevatedQueriesLinkHolder") {
        @Override
        protected WebMarkupContainer newLink(String id) {
            return new AjaxLink(id) {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Record record = recordModel.getObject();
                    ModalWindow elevatedQueriesModal = getModalWindow();
                    elevatedQueriesModal.setContent(new EditRecordElevatedQueriesPanel(
                            elevatedQueriesModal.getContentId(), record, simpleSearch));
                    elevatedQueriesModal.show(target);
                }
            };
        }

        @Override
        protected Component newImg(String id) {
            Image image = new NonCachingImage(id,
                    new ResourceReference(BaseConstellioPage.class, "images/ico_plus.gif"));
            return image;
        }

        @Override
        protected IModel getAltModel() {
            return new StringResourceModel("elevation", this, null);
        }
    });

    add(new Link("restoreLink") {
        @Override
        public void onClick() {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            String collectionName = simpleSearch.getCollectionName();
            RecordCollection collection = collectionServices.get(collectionName);

            SolrServer solrServer = SolrCoreContext.getSolrServer(collection);
            try {
                ConstellioPersistenceUtils.beginTransaction();
                Record record = recordModel.getObject();
                elevateServices.cancelElevation(record, simpleSearch);
                try {
                    solrServer.commit();
                } catch (Throwable t) {
                    try {
                        solrServer.rollback();
                    } catch (Exception e) {
                        throw new RuntimeException(t);
                    }
                }
            } finally {
                ConstellioPersistenceUtils.finishTransaction(false);
            }

            PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
            RequestCycle.get().setResponsePage(pageFactoryPlugin.getSearchResultsPage(),
                    SearchResultsPage.getParameters(simpleSearch));
        }

        @Override
        public boolean isVisible() {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            Record record = recordModel.getObject();
            return elevateServices.isElevated(record, simpleSearch);
        }
    });

    add(new Link("excludeLink") {
        @Override
        public void onClick() {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            RecordCollection collection = collectionServices.get(collectionName);

            SolrServer solrServer = SolrCoreContext.getSolrServer(collection);
            try {
                ConstellioPersistenceUtils.beginTransaction();
                Record record = recordModel.getObject();
                elevateServices.exclude(record, collection, simpleSearch);
                try {
                    solrServer.commit();
                } catch (Throwable t) {
                    try {
                        solrServer.rollback();
                    } catch (Exception e) {
                        throw new RuntimeException(t);
                    }
                }
            } finally {
                ConstellioPersistenceUtils.finishTransaction(false);
            }
            recordModel.detach();
            int attempts = 0;
            while (!recordModel.getObject().isExcludedEffective()) {
                recordModel.detach();
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new WicketRuntimeException(e);
                }
                attempts++;
                if (attempts > 10) {
                    // Give up waiting after one second
                    break;
                }
            }
            PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
            RequestCycle.get().setResponsePage(pageFactoryPlugin.getSearchResultsPage(),
                    SearchResultsPage.getParameters(simpleSearch));
        }

        @Override
        public boolean isVisible() {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            Record record = recordModel.getObject();
            return !elevateServices.isElevated(record, simpleSearch);
        }
    });
}