Changeset 5494


Ignore:
Timestamp:
07/28/14 14:06:51 (10 years ago)
Author:
Twan Goosen
Message:

Implemented basic moving of references within collection. Refs #597

Location:
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/wizard/CreateVirtualCollectionWizard$ResourcesStep$ActionsPanel.html

    r932 r5494  
    88  <a wicket:id="edit" href="#" class="edit"><span>[edit]</span></a>
    99  <a wicket:id="delete" href="#" class="delete"><span>[delete]</span></a>
     10  <a wicket:id="move" href="#" class="move"><span>[move]</span></a>
     11  <a wicket:id="target" href="#" class="target"><span>[insert before]</span></a>
    1012</wicket:panel>
    1113</body>
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/wizard/CreateVirtualCollectionWizard$ResourcesStep.html

    r906 r5494  
    1010<div style="display: none" wicket:id="deleteResourceDialog"></div>
    1111<div style="display: none" wicket:id="addResourcesDialog"></div>
    12 <div class="fieldset">
     12<div wicket:id="resourcesContainer" class="fieldset">
    1313  <label class="required">Resources<br /><a wicket:id="add" href="#" class="add"><span>[add]</span></a><br /><a wicket:id="addMore" href="#" class="addMore"><span>[add more]</span></a></label>
    1414  <table wicket:id="resourcesTable" class="resourcesTable"></table>
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/wizard/CreateVirtualCollectionWizard.java

    r5490 r5494  
    1111import java.util.List;
    1212import org.apache.wicket.Component;
     13import org.apache.wicket.Session;
    1314import org.apache.wicket.ajax.AjaxRequestTarget;
    1415import org.apache.wicket.ajax.markup.html.AjaxLink;
     
    141142                            new EnumChoiceRenderer<VirtualCollection.Reproducibility>(this));
    142143            add(reproducibilityChoice);
    143                 final TextArea<String> reproducibilityNoticeArea
     144            final TextArea<String> reproducibilityNoticeArea
    144145                    = new TextArea<String>("reproducibilityNotice");
    145146            add(reproducibilityNoticeArea);
    146147
    147148            final KeywordsList keywordList
    148                     = new KeywordsList("keywordsList", 
     149                    = new KeywordsList("keywordsList",
    149150                            new PropertyModel<List<String>>(vc, "keywords"));
    150151            add(keywordList);
     
    168169            add(addKeywordDialog);
    169170
    170             deleteKeywordDialog =
    171                 new DeleteKeywordDialog("deleteKeywordDialog", keywordList);
     171            deleteKeywordDialog
     172                    = new DeleteKeywordDialog("deleteKeywordDialog", keywordList);
    172173            add(deleteKeywordDialog);
    173174        }
     
    198199
    199200    private final class CreatorsStep extends DynamicWizardStep {
     201
    200202        private final class ActionsPanel extends Panel {
     203
    201204            public ActionsPanel(String id, final IModel<Creator> model) {
    202205                super(id, model);
    203206                setRenderBodyOnly(true);
    204                 final AjaxLink<Creator> editLink =
    205                     new AjaxLink<Creator>("edit") {
     207                final AjaxLink<Creator> editLink
     208                        = new AjaxLink<Creator>("edit") {
    206209                            @Override
    207210                            public void onClick(AjaxRequestTarget target) {
     
    210213                        };
    211214                add(editLink);
    212                 final AjaxLink<Creator> deleteLink =
    213                     new AjaxLink<Creator>("delete") {
     215                final AjaxLink<Creator> deleteLink
     216                        = new AjaxLink<Creator>("delete") {
    214217                            @Override
    215218                            public void onClick(AjaxRequestTarget target) {
     
    222225
    223226        private final class DeleteCreatorDialog extends ConfirmationDialog {
     227
    224228            private IModel<Creator> creator;
    225229
     
    264268                                    return new VolatileEntityModel<Creator>(creator);
    265269                                }
     270
    266271                                @Override
    267272                                public int size() {
     
    349354
    350355    private final class ResourcesStep extends DynamicWizardStep {
     356
     357        private final WebMarkupContainer resourcesContainer;
     358
    351359        private final class ActionsPanel extends Panel {
     360
    352361            public ActionsPanel(String id, final IModel<Resource> model) {
    353362                super(id, model);
    354363                setRenderBodyOnly(true);
    355                 final AjaxLink<Resource> editLink =
    356                     new AjaxLink<Resource>("edit") {
     364                final AjaxLink<Resource> editLink
     365                        = new AjaxLink<Resource>("edit") {
    357366                            @Override
    358367                            public void onClick(AjaxRequestTarget target) {
    359368                                editResourceDialog.show(target, model);
    360369                            }
     370
     371                            @Override
     372                            protected void onConfigure() {
     373                                // only allow when not moving
     374                                setVisible(movingResource.getObject() == null);
     375                            }
    361376                        };
    362377                add(editLink);
    363                 final AjaxLink<Resource> deleteLink =
    364                     new AjaxLink<Resource>("delete") {
     378                final AjaxLink<Resource> deleteLink
     379                        = new AjaxLink<Resource>("delete") {
    365380                            @Override
    366381                            public void onClick(AjaxRequestTarget target) {
    367382                                deleteResourceDialog.showResource(target, model);
    368383                            }
     384
     385                            @Override
     386                            protected void onConfigure() {
     387                                // only allow when not moving
     388                                setVisible(movingResource.getObject() == null);
     389                            }
    369390                        };
    370391                add(deleteLink);
     392                final AjaxLink<Resource> moveLink
     393                        = new AjaxLink<Resource>("move") {
     394
     395                            @Override
     396                            public void onClick(AjaxRequestTarget target) {
     397                                movingResource.setObject(model.getObject());
     398                                target.addComponent(resourcesContainer);
     399                            }
     400
     401                            @Override
     402                            protected void onConfigure() {
     403                                // only allow to start moving when not moving
     404                                setVisible(movingResource.getObject() == null);
     405                            }
     406
     407                        };
     408                add(moveLink);
     409                final AjaxLink<Resource> targetLink
     410                        = new AjaxLink<Resource>("target") {
     411
     412                            @Override
     413                            public void onClick(AjaxRequestTarget target) {
     414                                final List<Resource> resources = vc.getObject().getResources();
     415                                final Resource toMove = movingResource.getObject();
     416                                try {
     417                                    if (resources.remove(toMove)) {
     418                                        final int targetIndex = resources.indexOf(model.getObject());
     419                                        if (targetIndex >= 0) {
     420                                            resources.add(targetIndex, toMove);
     421                                            return;
     422                                        }
     423                                    }
     424                                    Session.get().warn("Could not move reference");
     425
     426                                } finally {
     427                                    movingResource.setObject(null);
     428                                    target.addComponent(resourcesContainer);
     429                                }
     430                            }
     431
     432                            @Override
     433                            protected void onConfigure() {
     434                                final Resource toMove = movingResource.getObject();
     435                                // only allow to drop when moving
     436                                setVisible(toMove != null
     437                                        && !toMove.equals(model.getObject())
     438                                );
     439                            }
     440
     441                        };
     442                add(targetLink);
    371443            }
    372444        } // class CreateVirtualCollectionWizard.ResourcesStep.ActionsPanel
    373445
    374446        private final class DeleteResourceDialog extends ConfirmationDialog {
     447
    375448            private IModel<Resource> resource;
    376449
     
    399472        private final DeleteResourceDialog deleteResourceDialog;
    400473
     474        private IModel<Resource> movingResource = new Model<>();
     475
    401476        public ResourcesStep(IDynamicWizardStep previousStep) {
    402477            super(previousStep, "Resources", null, vc);
    403             final DataTable<Resource> resourcesTable =
    404                 new AjaxFallbackDefaultDataTable<Resource>("resourcesTable",
     478            resourcesContainer = new WebMarkupContainer("resourcesContainer");
     479            resourcesContainer.setOutputMarkupId(true);
     480            add(resourcesContainer);
     481            final DataTable<Resource> resourcesTable
     482                    = new AjaxFallbackDefaultDataTable<Resource>("resourcesTable",
    405483                            createColumns(),
    406484                            new SortableDataProvider<Resource>() {
     
    423501                            64);
    424502            resourcesTable.setOutputMarkupId(true);
    425             add(resourcesTable);
     503            resourcesContainer.add(resourcesTable);
    426504
    427505            editResourceDialog = new EditResourceDialog("editResourceDialog") {
     
    449527            add(deleteResourceDialog);
    450528
    451             final AddResourcesDialog addResourcesDialog =
    452                 new AddResourcesDialog("addResourcesDialog") {
     529            final AddResourcesDialog addResourcesDialog
     530                    = new AddResourcesDialog("addResourcesDialog") {
    453531                        @Override
    454532                        public void onSubmit(AjaxRequestTarget target,
     
    465543            add(addResourcesDialog);
    466544
    467             add(new AjaxLink<Object>("add") {
     545            resourcesContainer.add(new AjaxLink<Object>("add") {
    468546                @Override
    469547                public void onClick(AjaxRequestTarget target) {
     
    472550            });
    473551
    474             add(new AjaxLink<Object>("addMore") {
     552            resourcesContainer.add(new AjaxLink<Object>("addMore") {
    475553                @Override
    476554                public void onClick(AjaxRequestTarget target) {
     
    529607                },
    530608                new PropertyColumn<Resource>(
    531                     new Model<String>("Reference"), "ref") {
    532 
    533                         @Override
    534                         public void populateItem(Item<ICellPopulator<Resource>> item, String componentId, IModel<Resource> rowModel) {
    535                             item.add(new ReferenceLinkPanel(componentId, rowModel));
    536                         }
    537                        
    538                     },
     609                new Model<String>("Reference"), "ref") {
     610
     611                    @Override
     612                    public void populateItem(Item<ICellPopulator<Resource>> item, String componentId, IModel<Resource> rowModel) {
     613                        item.add(new ReferenceLinkPanel(componentId, rowModel));
     614                    }
     615
     616                },
    539617                new HeaderlessColumn<Resource>() {
    540618                    @Override
     
    556634
    557635    private final class GeneratedByStep extends DynamicWizardStep {
     636
    558637        public GeneratedByStep(IDynamicWizardStep previousStep) {
    559638            super(previousStep, "Intensional Collection Query", null, vc);
    560639            setDefaultModel(new CompoundPropertyModel<VirtualCollection>(vc));
    561             final TextArea<String> descriptionArea =
    562                 new TextArea<String>("generatedBy.description");
     640            final TextArea<String> descriptionArea
     641                    = new TextArea<String>("generatedBy.description");
    563642            descriptionArea.setRequired(true);
    564643            add(descriptionArea);
    565             final TextField<String> uriField =
    566                 new TextField<String>("generatedBy.uri");
     644            final TextField<String> uriField
     645                    = new TextField<String>("generatedBy.uri");
    567646            uriField.add(new StringValidator.MaximumLengthValidator(255));
    568647            uriField.add(new UrlValidator(UrlValidator.NO_FRAGMENTS));
    569648            add(uriField);
    570             final TextField<String> queryProfileField =
    571                 new TextField<String>("generatedBy.query.profile");
     649            final TextField<String> queryProfileField
     650                    = new TextField<String>("generatedBy.query.profile");
    572651            add(queryProfileField);
    573             final TextArea<String> queryValueArea =
    574                 new TextArea<String>("generatedBy.query.value");
     652            final TextArea<String> queryValueArea
     653                    = new TextArea<String>("generatedBy.query.value");
    575654            add(queryValueArea);
    576655
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/model/VirtualCollection.java

    r5446 r5494  
    3030import javax.persistence.OneToOne;
    3131import javax.persistence.OrderBy;
     32import javax.persistence.OrderColumn;
    3233import javax.persistence.Table;
    3334import javax.persistence.Temporal;
     
    159160               fetch = FetchType.LAZY,
    160161               orphanRemoval = true)
    161     @JoinColumn(name = "vc_id", nullable = false)
    162     @OrderBy("id")
     162    @JoinColumn(name = "vc_id", nullable = false)   
     163    @OrderColumn(nullable = false)
    163164    private List<Resource> resources;
    164165
Note: See TracChangeset for help on using the changeset viewer.