Changeset 806


Ignore:
Timestamp:
10/21/10 09:42:58 (14 years ago)
Author:
oschonef
Message:
  • further work on GUI
Location:
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/wizard
Files:
5 added
3 edited

Legend:

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

    r805 r806  
    77<wicket:panel>
    88<!--  FIXME: use proper CSS, not table! -->
    9 <!--
    109<div style="display: none" wicket:id="editResourceDialog"></div>
    1110<div style="display: none" wicket:id="deleteResourceDialog"></div>
     11<div style="display: none" wicket:id="addResourcesDialog"></div>
    1212<table>
    1313  <tr style="vertical-align: top">
    14     <td>Creators</td>
    15     <td><table wicket:id="creatorsTable"></table></td>
     14    <td>Resources</td>
     15    <td><table wicket:id="resourcesTable"></table></td>
    1616  </tr>
    1717  <tr>
    18     <td colspan="2"><a href="#" wicket:id="add">add creator</a></td>
     18    <td colspan="2">
     19      <a href="#" wicket:id="add">add resource</a>
     20      <a href="#" wicket:id="addMore">add more resource</a>
     21    </td>
    1922  </tr>
    2023</table>
    21 -->
    2224</wicket:panel>
    2325</body>
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/wizard/CreateVirtualCollectionWizard.java

    r805 r806  
    3030import eu.clarin.cmdi.virtualcollectionregistry.gui.pages.HomePage;
    3131import eu.clarin.cmdi.virtualcollectionregistry.model.Creator;
     32import eu.clarin.cmdi.virtualcollectionregistry.model.Resource;
    3233import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection;
     34import eu.clarin.cmdi.virtualcollectionregistry.model.Resource.Type;
    3335
    3436@SuppressWarnings("serial")
     
    121123                            public Iterator<? extends Creator> iterator(
    122124                                    int first, int count) {
    123                                 return vc.getCreators().iterator();
     125                                // XXX: hack
     126                                Iterator<Creator> i =
     127                                    vc.getCreators().iterator();
     128                                while (first-- > 0) {
     129                                    i.next();
     130                                }
     131                                return i;
    124132                            }
    125133
     
    150158            add(editCreatorDialog);
    151159
     160            deleteCreatorDialog =
     161                new DeleteCreatorDialog("deleteCreatorDialog",
     162                        creatorsTable);
     163            add(deleteCreatorDialog);
     164
    152165            add(new AjaxLink<Object>("add") {
    153166                @Override
     
    157170                }
    158171            });
    159             deleteCreatorDialog =
    160                 new DeleteCreatorDialog("deleteCreatorDialog",
    161                         creatorsTable);
    162             add(deleteCreatorDialog);
    163172        }
    164173
     
    186195    } // class CreateVirtualCollectionWizard.CreatorsStep
    187196
    188 //    private final class ResourcesStep extends WizardStep {
    189 //        public ResourcesStep() {
    190 //            super("Resources", "Yada yada yada ...");
    191 //        }
    192 //    }// class CreateVirtualCollectionWizard.CreatorsStep
     197    private final class ResourcesStep extends WizardStep {
     198        private final class ActionsPanel extends Panel {
     199            public ActionsPanel(String id, final IModel<Resource> model) {
     200                super(id, model);
     201                final AjaxLink<Resource> editLink =
     202                    new AjaxLink<Resource>("edit") {
     203                    @Override
     204                    public void onClick(AjaxRequestTarget target) {
     205                        final Resource resource = model.getObject();
     206                        if (resource != null) {
     207                            editResourceDialog.setResource(resource);
     208                            editResourceDialog.show(target);
     209                        }
     210                    }
     211                };
     212                add(editLink);
     213                final AjaxLink<Resource> removeLink =
     214                    new AjaxLink<Resource>("remove") {
     215                    @Override
     216                    public void onClick(AjaxRequestTarget target) {
     217                        final Resource resource = model.getObject();
     218                        if (resource != null) {
     219                            deleteResourceDialog.setResource(resource);
     220                            deleteResourceDialog.show(target);
     221                        }
     222                    }
     223                };
     224                add(removeLink);
     225            }
     226        } // class CreateVirtualCollectionWizard.ResourcesStep.ActionsPanel
     227
     228        private final class DeleteResourceDialog extends ConfirmationDialog {
     229            private final transient DataTable<Resource> resourcesTable;
     230            private Resource resource;
     231
     232            public DeleteResourceDialog(String id,
     233                    DataTable<Resource> resourcesTable) {
     234                super(id, new Model<String>(""));
     235                this.resourcesTable = resourcesTable;
     236            }
     237
     238            public void setResource(Resource resource) {
     239                this.resource = resource;
     240                setMessage(new StringResourceModel("resources.deleteconfirm",
     241                        new Model<Resource>(resource)));
     242            }
     243
     244            @Override
     245            public void onConfirm(AjaxRequestTarget target) {
     246                if (resource != null) {
     247                    vc.getResources().remove(resource);
     248                    target.addComponent(resourcesTable);
     249                }
     250            }
     251
     252            @Override
     253            public void onCancel(AjaxRequestTarget target) {
     254            }
     255        } // class CreateVirtualCollectionWizard.CreatorsStep.DeleteConfirmDialog
     256
     257        private final EditResourceDialog editResourceDialog;
     258        private final DeleteResourceDialog deleteResourceDialog;
     259       
     260        public ResourcesStep() {
     261            super("Resources", "Yada yada yada ...");
     262            final DataTable<Resource> resourcesTable =
     263                new AjaxFallbackDefaultDataTable<Resource>("resourcesTable",
     264                        createColumns(),
     265                        new SortableDataProvider<Resource>() {
     266                            @Override
     267                            public Iterator<? extends Resource> iterator(
     268                                    int first, int count) {
     269                                // XXX: hack
     270                                Iterator<Resource> i =
     271                                    vc.getResources().iterator();
     272                                while (first-- > 0) {
     273                                    i.next();
     274                                }
     275                                return i;
     276                            }
     277
     278                            @Override
     279                            public IModel<Resource> model(Resource resource) {
     280                                return new Model<Resource>(resource);
     281                            }
     282
     283                            @Override
     284                            public int size() {
     285                                return vc.getResources().size();
     286                            }
     287                        },                   
     288                        8);
     289            add(resourcesTable);
     290           
     291            editResourceDialog = new EditResourceDialog("editResourceDialog") {
     292                @Override
     293                public void onSubmit(AjaxRequestTarget target, Resource resource) {
     294                    if (resource != null) {
     295                        if (!vc.getResources().contains(resource)) {
     296                            vc.getResources().add(resource);
     297                        }
     298                        target.addComponent(resourcesTable);
     299                    }
     300                }
     301            };
     302            add(editResourceDialog);
     303
     304            deleteResourceDialog =
     305                new DeleteResourceDialog("deleteResourceDialog",
     306                        resourcesTable);
     307            add(deleteResourceDialog);
     308
     309            final AddResourcesDialog addResourcesDialog =
     310                new AddResourcesDialog("addResourcesDialog") {
     311                    @Override
     312                    public void onSubmit(AjaxRequestTarget target,
     313                            Resource[] resources) {
     314                        for (Resource resource : resources) {
     315                            if (!vc.getResources().contains(resource)) {
     316                                vc.getResources().add(resource);
     317                            }
     318                        }
     319                        target.addComponent(resourcesTable);
     320                    }
     321               
     322            };
     323            add(addResourcesDialog);
     324
     325            add(new AjaxLink<Object>("add") {
     326                @Override
     327                public void onClick(AjaxRequestTarget target) {
     328                    editResourceDialog.setResource(new Resource());
     329                    editResourceDialog.show(target);
     330                }
     331            });
     332
     333            add(new AjaxLink<Object>("addMore") {
     334                @Override
     335                public void onClick(AjaxRequestTarget target) {
     336                    addResourcesDialog.show(target);
     337                }
     338            });
     339        }
     340
     341        @SuppressWarnings("unchecked")
     342        private IColumn<Resource>[] createColumns() {
     343            final IColumn<?>[] columns = new IColumn<?>[] {
     344                    new PropertyColumn<Resource>(
     345                            new Model<String>("Type"), "type"),
     346                    new PropertyColumn<Resource>(
     347                            new Model<String>("Reference"), "ref"),
     348                    new HeaderlessColumn<Resource>() {
     349                        @Override
     350                        public void populateItem(
     351                                Item<ICellPopulator<Resource>> cellItem,
     352                                String compontentId,
     353                                IModel<Resource> model) {
     354                            cellItem.add(new ActionsPanel(compontentId, model));
     355                        }
     356                    }
     357            };
     358            return (IColumn<Resource>[]) columns;
     359        }
     360    } // class CreateVirtualCollectionWizard.CreatorsStep
    193361
    194362    private final VirtualCollection vc = new VirtualCollection();
     
    196364    public CreateVirtualCollectionWizard(String id) {
    197365        super(id);
     366        vc.getResources().add(new Resource(Type.METADATA, "http://some/where1"));
     367        vc.getResources().add(new Resource(Type.METADATA, "http://some/where2"));
     368        vc.getResources().add(new Resource(Type.METADATA, "http://some/where3"));
     369        vc.getResources().add(new Resource(Type.METADATA, "http://some/where4"));
    198370        setDefaultModel(new CompoundPropertyModel<VirtualCollection>(this));
    199371        WizardModel model = new WizardModel();
    200372        model.add(new GeneralStep());
    201373        model.add(new CreatorsStep());
    202         // model.add(new ResourcesStep());
     374        model.add(new ResourcesStep());
    203375        init(model);
    204376    }
     
    215387        System.err.println("Desc: " + vc.getDescription());
    216388        for (Creator c : vc.getCreators()) {
    217             System.err.println(c.getName() + ", " + c.getEMail());
     389            System.err.println("C: " + c.getName() + ", " + c.getEMail());
     390        }
     391        for (Resource r : vc.getResources()) {
     392            System.err.println("R: " + r.getType() + ", " + r.getRef());
    218393        }
    219394    }
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/wizard/CreateVirtualCollectionWizard.properties

    r805 r806  
    11Type.EXTENSIONAL: Extensional
    22Type.INTENSIONAL: Intensional
     3Type.METADATA: Metadata
     4Type.RESOURCE: Resource
    35creators.deleteconfirm: Do you really want to delete "${name}"?
     6resources.deleteconfirm: Do you really want to delete "${ref}"?
Note: See TracChangeset for help on using the changeset viewer.