private Component deleteLink(String id, final JcrPropertyModel model) throws RepositoryException { Component result = null; if (model.getProperty().getDefinition().isProtected()) { result = new Label(id, "(protected)"); } else { result = new AjaxLink(id, model) { private static final long serialVersionUID = 1L; @Override protected void onComponentTag(final ComponentTag tag) { super.onComponentTag(tag); tag.put("class", "property-value-remove"); } @Override public void onClick(AjaxRequestTarget target) { try { Property prop = model.getProperty(); prop.remove(); } catch (RepositoryException e) { log.error(e.getMessage()); } NodeEditor editor = findParent(NodeEditor.class); target.add(editor); } }; } return result; }
@Override protected void populateItem(Item item) { JcrPropertyModel model = (JcrPropertyModel) item.getModel(); try { item.add(deleteLink("delete", model)); JcrName propName = new JcrName(model.getProperty().getName()); item.add(new Label("name", propName.getName())); item.add(new Label("type", PropertyType.nameFromValue(model.getProperty().getType()))); item.add(new PropertyValueEditor("values", model)); if (model.getProperty().getDefinition().isMultiple() && !model.getProperty().getDefinition().isProtected()) { item.add(addLink("add", model)); } else { item.add(new Label("add", "")); } } catch (RepositoryException e) { log.error(e.getMessage()); } }