List of usage examples for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel
AbstractReadOnlyModel
From source file:ontopoly.components.CreateOrCopyInstanceFunctionBoxPanel.java
License:Apache License
public CreateOrCopyInstanceFunctionBoxPanel(String id, final TopicModel<Topic> topicModel, final TopicTypeModel topicTypeModel) { super(id);//from ww w . ja va 2 s. c o m add(new Label("title", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return new ResourceModel("create.new").getObject() + " " + topicTypeModel.getTopicType().getName(); } })); Button createButton = new Button("createButton", new ResourceModel("create")); createButton.add(new AjaxFormComponentUpdatingBehavior("onclick") { @Override protected void onUpdate(AjaxRequestTarget target) { Topic instance = topicModel.getTopic(); TopicMap topicMap = instance.getTopicMap(); TopicType topicType = topicTypeModel.getTopicType(); Topic newInstance = topicType.createInstance(null); Map<String, String> pageParametersMap = new HashMap<String, String>(); pageParametersMap.put("topicMapId", topicMap.getId()); pageParametersMap.put("topicId", newInstance.getId()); if (newInstance.isOntologyTopic()) pageParametersMap.put("ontology", "true"); setResponsePage(InstancePage.class, new PageParameters(pageParametersMap)); } }); add(createButton); Button copyButton = new Button("copyButton", new ResourceModel("copy")) { @Override public boolean isEnabled() { // only display copy button for non-ontology topics return !topicModel.getTopic().isOntologyTopic() || ((OntopolySession) Session.get()).isAdministrationEnabled(); } }; copyButton.add(new AjaxFormComponentUpdatingBehavior("onclick") { @Override protected void onUpdate(AjaxRequestTarget target) { // FIXME: perhaps we should not copy the names as this is somewhat confusing Topic instance = topicModel.getTopic(); TopicMap topicMap = instance.getTopicMap(); Topic newInstance = instance.copyCharacteristics(); Map<String, String> pageParametersMap = new HashMap<String, String>(); pageParametersMap.put("topicMapId", topicMap.getId()); pageParametersMap.put("topicId", newInstance.getId()); if (newInstance.isOntologyTopic()) pageParametersMap.put("ontology", "true"); setResponsePage(InstancePage.class, new PageParameters(pageParametersMap)); } }); add(copyButton); }
From source file:ontopoly.components.FieldInstanceCreatePlayerPanel.java
License:Apache License
public FieldInstanceCreatePlayerPanel(String id, FieldInstanceModel _fieldInstanceModel, FieldsViewModel fieldsViewModel, RoleFieldModel _roleFieldModel, AbstractFieldInstancePanel fieldInstancePanel, int createAction) { super(id);// w ww .ja va 2s. c o m this.fieldInstanceModel = _fieldInstanceModel; this.fieldsViewModel = fieldsViewModel; this.roleFieldModel = _roleFieldModel; this.fieldInstancePanel = fieldInstancePanel; this.createAction = createAction; RoleField associationField = roleFieldModel.getRoleField(); Collection<TopicType> allowedValueTypes = associationField .getAllowedPlayerTypes(_fieldInstanceModel.getFieldInstance().getInstance()); if (allowedValueTypes.isEmpty()) { setVisible(false); OntopolyImageLink button = new OntopolyImageLink("button", "create.gif", new ResourceModel("icon.create.player")) { @Override public void onClick(AjaxRequestTarget target) { } }; add(button); add(new Label("createMenu")); add(new Label("createModal")); } else if (allowedValueTypes.size() == 1) { this.topicTypeModel = new TopicTypeModel((TopicType) allowedValueTypes.iterator().next()); OntopolyImageLink button = new OntopolyImageLink("button", "create.gif", new ResourceModel("icon.create.player")) { @Override public void onClick(AjaxRequestTarget target) { FieldInstanceCreatePlayerPanel.this.onClick(target, topicTypeModel.getTopicType()); } }; add(button); add(new Label("createMenu").setVisible(false)); add(new Label("createModal").setVisible(false)); } else { final String menuId = id + "_" + associationField.getId() + "_" + _fieldInstanceModel.getFieldInstance().getInstance().getId(); Link<Object> button = new Link<Object>("button") { { add(new Image("image", new AbstractReadOnlyModel<ResourceReference>() { @Override public ResourceReference getObject() { return new ResourceReference(ImageResource.class, "create.gif"); } })); } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("onclick", "menuItemPopup(this)"); tag.put("id", "main" + menuId); tag.put("href", "#"); } @Override public void onClick() { } }; add(button); add(new ContextMenuPanel<TopicType>("createMenu", menuId) { @Override protected ListView<TopicType> createListView(final String menuId, final String menuItemId) { return new ListView<TopicType>(menuId, new PlayerTypesModel(fieldInstanceModel, roleFieldModel)) { @Override public void populateItem(final ListItem<TopicType> item) { AjaxLink<Object> createLink = new AjaxLink<Object>(menuItemId) { @Override public void onClick(AjaxRequestTarget target) { FieldInstanceCreatePlayerPanel.this.onClick(target, item.getModelObject()); } }; createLink.add(new Label("label", item.getModelObject().getName())); item.add(createLink); } }; } }); add(new Label("createModal").setVisible(false)); } }
From source file:ontopoly.components.FieldInstanceImageField.java
License:Apache License
public FieldInstanceImageField(String id, FieldValueModel _fieldValueModel, boolean readonly) { super(id);//from w w w . ja va 2 s . com this.fieldValueModel = _fieldValueModel; image = new Image("image"); image.add(new AttributeModifier("src", true, new AbstractReadOnlyModel<String>() { @Override public final String getObject() { TopicMap topicMap = fieldValueModel.getFieldInstanceModel().getFieldInstance().getInstance() .getTopicMap(); Object o = fieldValueModel.getFieldValue(); return getRequest().getRelativePathPrefixToContextRoot() + "occurrenceImages?topicMapId=" + topicMap.getId() + "&occurrenceId=" + ((o instanceof OccurrenceIF ? ((OccurrenceIF) o).getObjectId() : "unknown")); } })); upload = new UploadPanel("upload", this); add(image); add(upload); if (fieldValueModel.isExistingValue()) { upload.setVisible(false); } else { image.setVisible(false); if (readonly) upload.setVisible(false); } }
From source file:ontopoly.components.FieldInstanceURIField.java
License:Apache License
public FieldInstanceURIField(String id, FieldValueModel _fieldValueModel) { super(id);//from w w w . j a v a2 s. co m this.fieldValueModel = _fieldValueModel; if (!fieldValueModel.isExistingValue()) { this.oldValue = null; } else { Object value = fieldValueModel.getObject(); if (value instanceof OccurrenceIF) { OccurrenceIF occ = (OccurrenceIF) value; this.oldValue = occ.getValue(); } else if (value instanceof LocatorIF) { LocatorIF identity = (LocatorIF) value; this.oldValue = identity.getAddress(); } else { throw new RuntimeException("Unsupported field value: " + value); } } this.textField = new TextField<String>("input", new Model<String>(oldValue)) { @Override public boolean isEnabled() { return FieldInstanceURIField.this.isEnabled(); } @Override protected void onComponentTag(ComponentTag tag) { tag.setName("input"); tag.put("type", "text"); tag.put("size", cols); super.onComponentTag(tag); } @Override protected void onModelChanged() { super.onModelChanged(); String newValue = getModelObject(); if (ObjectUtils.equals(newValue, oldValue)) return; AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); FieldInstance fieldInstance = fieldValueModel.getFieldInstanceModel().getFieldInstance(); if (fieldValueModel.isExistingValue() && oldValue != null) fieldInstance.removeValue(oldValue, page.getListener()); if (newValue != null && !newValue.equals("")) { fieldInstance.addValue(newValue, page.getListener()); fieldValueModel.setExistingValue(newValue); } oldValue = newValue; } }; if (fieldValueModel.getFieldInstanceModel().getFieldType() == FieldDefinition.FIELD_TYPE_IDENTITY) { textField.add(new IdentityValidator(this, fieldValueModel.getFieldInstanceModel())); } else { textField.add(new URIValidator(this, fieldValueModel.getFieldInstanceModel())); } add(textField); this.button = new ExternalLink("button", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return textField.getModelObject(); } }) { @Override public boolean isVisible() { return textField.getModelObject() != null; } }; button.setOutputMarkupId(true); button.setPopupSettings( new PopupSettings(PopupSettings.LOCATION_BAR | PopupSettings.MENU_BAR | PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS | PopupSettings.STATUS_BAR | PopupSettings.TOOL_BAR)); button.add(new OntopolyImage("icon", "goto.gif")); add(button); // validate field using registered validators ExternalValidation.validate(textField, oldValue); }
From source file:ontopoly.components.OntopolyImageLink.java
License:Apache License
public OntopolyImageLink(String id, String image, IModel<String> titleModel) { super(id);/*from w w w .java2 s . c o m*/ this.image = image; this.titleModel = titleModel; // this.setRenderBodyOnly(true); add(new Image("image", new AbstractReadOnlyModel<ResourceReference>() { @Override public ResourceReference getObject() { return new ResourceReference(ImageResource.class, getImage()); } })); }
From source file:ontopoly.pages.AssociationTypesPage.java
License:Apache License
@Override protected Component createTreePanel(String id) { // create a tree final TreeModel treeModel = TreeModels.createAssociationTypesTreeModel(getTopicMapModel().getTopicMap(), isAdministrationEnabled());/* w w w . ja va 2s. c om*/ IModel<TreeModel> treeModelModel = new AbstractReadOnlyModel<TreeModel>() { @Override public TreeModel getObject() { return treeModel; } }; return createTreePanel("tree", treeModelModel); }
From source file:ontopoly.pages.EmbeddedHierarchicalInstancePage.java
License:Apache License
protected IModel<TreeModel> createTreeModel(final TopicModel<Topic> hierarchyTopicModel, final TopicModel<Topic> currentNodeModel) { final TreeModel treeModel; Topic hierarchyTopic = hierarchyTopicModel.getTopic(); Topic currentNode = currentNodeModel.getTopic(); // find hierarchy definition query for topic String query = (hierarchyTopic == null ? null : getDefinitionQuery(hierarchyTopic)); if (query != null) { Map<String, TopicIF> params = new HashMap<String, TopicIF>(2); params.put("hierarchyTopic", hierarchyTopic.getTopicIF()); params.put("currentNode", currentNode.getTopicIF()); treeModel = TreeModels.createQueryTreeModel(currentNode.getTopicMap(), query, params); } else if (currentNode.isTopicType()) { // if no definition query found, then show topic in instance hierarchy treeModel = TreeModels.createTopicTypesTreeModel(currentNode.getTopicMap(), isAnnotationEnabled(), isAdministrationEnabled()); } else {/*from w ww . ja v a 2 s. co m*/ treeModel = TreeModels.createInstancesTreeModel(OntopolyUtils.getDefaultTopicType(currentNode), isAdministrationEnabled()); } return new AbstractReadOnlyModel<TreeModel>() { @Override public TreeModel getObject() { return treeModel; } }; }
From source file:ontopoly.pages.InstancesPage.java
License:Apache License
public InstancesPage(PageParameters parameters) { super(parameters); this.topicTypeModel = new TopicTypeModel(parameters.getString("topicMapId"), parameters.getString("topicId")); // Adding part containing title and help link createTitle();//from w ww . j a va2 s . c o m // Add form Form<Object> form = new Form<Object>("form"); add(form); form.setOutputMarkupId(true); // Add list of instances TopicType topicType = topicTypeModel.getTopicType(); if (topicType.isLargeInstanceSet()) { form.add(new InstanceSearchPanel("instancesPanel", topicTypeModel)); } else if (topicType.hasHierarchy()) { // create a tree final TreeModel treeModel = TreeModels.createInstancesTreeModel(topicTypeModel.getTopicType(), isAdministrationEnabled()); IModel<TreeModel> treeModelModel = new AbstractReadOnlyModel<TreeModel>() { @Override public TreeModel getObject() { return treeModel; } }; Panel treePanel = new TreePanel("instancesPanel", treeModelModel) { @Override protected Component populateNode(String id, TreeNode treeNode) { DefaultMutableTreeNode mTreeNode = (DefaultMutableTreeNode) treeNode; final TopicNode node = (TopicNode) mTreeNode.getUserObject(); // create link with label return new LinkPanel(id) { @Override protected Label newLabel(String id) { Topic topic = node.getTopic(); final boolean isSystemTopic = topic.isSystemTopic(); return new Label(id, new Model<String>(getLabel(topic))) { @Override protected void onComponentTag(final ComponentTag tag) { if (isSystemTopic) tag.put("class", "italic"); super.onComponentTag(tag); } }; } @Override protected Link<Page> newLink(String id) { PageParameters params = new PageParameters(); params.put("topicMapId", node.getTopicMapId()); params.put("topicId", node.getTopicId()); params.put("topicTypeId", topicTypeModel.getTopicType().getId()); return new BookmarkablePageLink<Page>(id, InstancePage.class, params); } }; } }; treePanel.setOutputMarkupId(true); form.add(treePanel); } else { // just make a list form.add(new TopicListPanel("instancesPanel", new AbstractReadOnlyModel<List<Topic>>() { // short time cache because getObject is called for each object in the list transient private List<Topic> instances = null; @Override public List<Topic> getObject() { if (instances == null) { instances = topicTypeModel.getTopicType().getInstances(); } return instances; } })); } // Function boxes createFunctionBoxes(form, "functionBoxes"); // initialize parent components initParentComponents(); }
From source file:ontopoly.pages.InstanceTypesPage.java
License:Apache License
public InstanceTypesPage(PageParameters parameters) { super(parameters); // Adding part containing title and help link createTitle();//from w w w.ja va2s . co m // create a tree final TreeModel treeModel = TreeModels.createTopicTypesTreeModel(getTopicMapModel().getTopicMap(), isAnnotationEnabled(), isAdministrationEnabled()); IModel<TreeModel> treeModelModel = new AbstractReadOnlyModel<TreeModel>() { @Override public TreeModel getObject() { return treeModel; } }; Panel treePanel = new TreePanel("tree", treeModelModel) { @Override protected Component populateNode(String id, TreeNode treeNode) { DefaultMutableTreeNode mTreeNode = (DefaultMutableTreeNode) treeNode; final TopicNode node = (TopicNode) mTreeNode.getUserObject(); // create link with label return new LinkPanel(id) { @Override protected Label newLabel(String id) { Topic topic = node.getTopic(); final boolean isSystemTopic = topic.isSystemTopic(); return new Label(id, new Model<String>(getLabel(topic))) { @Override protected void onComponentTag(final ComponentTag tag) { if (isSystemTopic) tag.put("class", "italic"); super.onComponentTag(tag); } }; } @Override protected Link<Page> newLink(String id) { Map<String, String> pageParametersMap = new HashMap<String, String>(2); pageParametersMap.put("topicMapId", node.getTopicMapId()); pageParametersMap.put("topicId", node.getTopicId()); return new BookmarkablePageLink<Page>(id, InstancesPage.class, new PageParameters(pageParametersMap)); } }; } }; treePanel.setOutputMarkupId(true); add(treePanel); // initialize parent components initParentComponents(); }