List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setContent
public ModalWindow setContent(final Component component)
From source file:nl.knaw.dans.dccd.web.search.pages.AdvSearchPage.java
License:Apache License
private void initTaxonSelection(final AdvancedSearchForm form, final AdvSearchData data) { // With plain text input: //add(new TextField("elementTaxon", new SearchFieldModel(data, "elementTaxon"))); // With autocomplete: //add(new TridasVocabularyAutoCompleteSelector("elementTaxon", // new SearchFieldModel(data, "elementTaxon"), // "element.taxon")); // With ComboBox: final DropDown elemTaxonComboBox = new DropDown("elementTaxon", new SearchFieldModel(data, "elementTaxon"), new DropDownDataSource<String>() { private static final long serialVersionUID = 1L; public String getName() { return "element.taxon"; }//from w ww.j a v a 2 s . c o m public List<String> getValues() { // Use current language to get terms for that language String langCode = getSession().getLocale().getLanguage(); return DccdVocabularyService.getService().getTerms("element.taxon", langCode); } public String getDescriptionForValue(String t) { return t; } }, false); elemTaxonComboBox.setCharacterWidth(25); elemTaxonComboBox.setOutputMarkupId(true); //form.add(elemTaxonComboBox); // FIX Container is needed to workaround visural-wicket ISSUE 67 final WebMarkupContainer taxonContainer = new WebMarkupContainer("elementTaxonContainer"); taxonContainer.setOutputMarkupId(true); form.add(taxonContainer); taxonContainer.add(elemTaxonComboBox); //TEST adding the window with the table //Problem, the TaxonSelectPanel wants a real TridasTaxon final ModalWindow modalSelectDialog; form.add(modalSelectDialog = new ModalWindow("taxonSelectPanel")); final TaxonSelectPanel taxonSelectPanel = new TaxonSelectPanel(modalSelectDialog.getContentId(), new Model(null)) { private static final long serialVersionUID = 1L; @Override protected void onSelectionChanged(AjaxRequestTarget target) { String taxonString = getSelectionAsString(); LOGGER.debug("Selected taxon: " + taxonString); data.elementTaxon.setValue(taxonString); //target.addComponent(elemTaxonComboBox); // FIX workaround visural-wicket ISSUE 67 by updating the container target.addComponent(taxonContainer); } }; modalSelectDialog.setContent(taxonSelectPanel); //modalSelectDialog.setTitle(ProjectPermissionSettingsPage.this.getString("userAddDialogTitle")); modalSelectDialog.setCookieName("taxonSelectPanelWindow"); modalSelectDialog.setInitialWidth(400); modalSelectDialog.setInitialHeight(160); modalSelectDialog.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { private static final long serialVersionUID = 1L; public boolean onCloseButtonClicked(AjaxRequestTarget target) { return true; } }); //button to show the dialog AjaxLink taxonSelectButton = new IndicatingAjaxLink("taxonSelectButton") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { //LOGGER.debug("term=" + data.elementTaxon.getValue()); //taxonSelectPanel.selectTerm(elemTaxonComboBox.getValue()); modalSelectDialog.show(target); } }; form.add(taxonSelectButton); }
From source file:nl.mpi.lamus.web.components.ButtonPanel.java
License:Open Source License
private ModalWindow createConfirmationModalWindow(WorkspaceSubmissionType submissionType) { String id;/* ww w.j a v a 2s. co m*/ String title; String cookieName; String confirmationInfoText = null; String confirmationText; if (WorkspaceSubmissionType.SUBMIT_WORKSPACE.equals(submissionType)) { id = "modalConfirmSubmit"; title = "Submit Workspace"; cookieName = "modal-confirm-submit"; confirmationInfoText = getLocalizer().getString("submit_workspace_info", this); confirmationText = getLocalizer().getString("submit_workspace_confirm", this); } else if (WorkspaceSubmissionType.DELETE_WORKSPACE.equals(submissionType)) { id = "modalConfirmDelete"; title = "Delete Workspace"; cookieName = "modal-confirm-delete"; confirmationText = getLocalizer().getString("delete_workspace_confirm", this); } else { throw new UnsupportedOperationException("Submission type not supported"); } final ConfirmationOptions options = new ConfirmationOptions(false, false, submissionType, confirmationInfoText, confirmationText); ModalWindow modalConfirm = new ModalWindow(id); modalConfirm.setContent(new ConfirmPanel(modalConfirm.getContentId(), modalConfirm, options)); modalConfirm.setTitle(title); modalConfirm.setCookieName(cookieName); modalConfirm.setWindowClosedCallback((new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget art) { if (options.isConfirmed()) { if (WorkspaceSubmissionType.SUBMIT_WORKSPACE.equals(options.getWorkspaceSubmissionType())) { onSubmitConfirm(art, options.isKeepUnlinkedFiles()); } else if (WorkspaceSubmissionType.DELETE_WORKSPACE .equals(options.getWorkspaceSubmissionType())) { onDeleteConfirm(art, options.isKeepUnlinkedFiles()); } else { throw new UnsupportedOperationException("Confirmation type not supported"); } } else { onCancel(art); } } })); return modalConfirm; }
From source file:nl.mpi.lamus.web.pages.LamusPage.java
License:Open Source License
private ModalWindow createAboutModalWindow() { ModalWindow modalAbout = new ModalWindow("modalAbout"); modalAbout.setContent(new AboutPanel(modalAbout.getContentId())); modalAbout.setTitle("About LAMUS 2"); modalAbout.setCookieName("modal-about"); modalAbout.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override/*from w ww. java2 s . c o m*/ public boolean onCloseButtonClicked(AjaxRequestTarget art) { return true; } }); modalAbout.setWindowClosedCallback((new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget art) { } })); return modalAbout; }
From source file:ontopoly.components.DeleteTopicFunctionBoxPanel.java
License:Apache License
public DeleteTopicFunctionBoxPanel(String id) { super(id);//from ww w . ja v a2 s .c o m add(new Label("title", new ResourceModel("delete.this.topic"))); final ModalWindow deleteModal = new ModalWindow("deleteModal"); ModalConfirmPage modalDeletePanel = new ModalConfirmPage(deleteModal.getContentId()) { @Override protected void onCloseCancel(AjaxRequestTarget target) { // close modal deleteModal.close(target); } @Override protected void onCloseOk(AjaxRequestTarget target) { // close modal deleteModal.close(target); // notify listeners Topic instance = (Topic) getTopicModel().getObject(); onDeleteConfirmed(instance); // remove dependent objects AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); Collection<Topic> dependentObjects = instance.getDependentObjects(); Iterator<Topic> diter = dependentObjects.iterator(); while (diter.hasNext()) { Topic dtopic = diter.next(); dtopic.remove(page); } // remove topic instance.remove(page); } @Override protected Component getTitleComponent(String id) { return new Label(id, new ResourceModel("delete.confirm")); } @Override protected Component getMessageComponent(String id) { return new Label(id, new ResourceModel("delete.message.topic")); } }; deleteModal.setContent(modalDeletePanel); deleteModal.setTitle(new ResourceModel("ModalWindow.title.delete.topic").getObject().toString()); deleteModal.setCookieName("deleteModal"); add(deleteModal); Button createButton = new Button("deleteButton"); createButton.add(new AjaxFormComponentUpdatingBehavior("onclick") { @Override protected void onUpdate(AjaxRequestTarget target) { WicketHacks.disableWindowUnloadConfirmation(target); deleteModal.show(target); } }); add(createButton); }
From source file:ontopoly.components.DeleteTopicMapFunctionBoxPanel.java
License:Apache License
public DeleteTopicMapFunctionBoxPanel(String id) { super(id);/*from w w w.jav a 2s.c om*/ add(new Label("title", new ResourceModel("delete.this.topic.map"))); final ModalWindow deleteModal = new ModalWindow("deleteModal"); ModalConfirmPage modalDeletePanel = new ModalConfirmPage(deleteModal.getContentId()) { @Override protected void onCloseCancel(AjaxRequestTarget target) { // close modal deleteModal.close(target); } @Override protected void onCloseOk(AjaxRequestTarget target) { // close modal deleteModal.close(target); // notify listeners TopicMap topicMap = getTopicMapModel().getTopicMap(); onDeleteConfirmed(topicMap); // delete topic map OntopolyContext.getOntopolyRepository().deleteTopicMap(topicMap.getId()); } @Override protected Component getTitleComponent(String id) { return new Label(id, new ResourceModel("delete.confirm")); } @Override protected Component getMessageComponent(String id) { return new Label(id, new ResourceModel("delete.message.topicmap")); } }; deleteModal.setContent(modalDeletePanel); deleteModal.setTitle(new ResourceModel("ModalWindow.title.delete.topicmap").getObject().toString()); deleteModal.setCookieName("deleteModal"); add(deleteModal); Button createButton = new Button("deleteButton"); createButton.add(new AjaxFormComponentUpdatingBehavior("onclick") { @Override protected void onUpdate(AjaxRequestTarget target) { WicketHacks.disableWindowUnloadConfirmation(target); deleteModal.show(target); } }); add(createButton); }
From source file:ontopoly.components.FieldInstanceAssociationBinaryPanel.java
License:Apache License
protected FieldInstanceAssociationBinaryPanel(String id, final FieldInstanceModel fieldInstanceModel, final FieldsViewModel fieldsViewModel, final boolean readonlyField, final boolean embedded, final boolean traversable) { super(id, fieldInstanceModel); FieldInstance fieldInstance = fieldInstanceModel.getFieldInstance(); FieldAssignment fieldAssignment = fieldInstance.getFieldAssignment(); RoleField roleField = (RoleField) fieldAssignment.getFieldDefinition(); this.roleFieldModel = new RoleFieldModel(roleField); add(new FieldDefinitionLabel("fieldLabel", new FieldDefinitionModel(roleField))); // set up container this.fieldValuesContainer = new WebMarkupContainer("fieldValuesContainer"); fieldValuesContainer.setOutputMarkupId(true); add(fieldValuesContainer);/*from w w w .j ava 2s .c om*/ // add feedback panel this.feedbackPanel = new FeedbackPanel("feedback", new AbstractFieldInstancePanelFeedbackMessageFilter()); feedbackPanel.setOutputMarkupId(true); fieldValuesContainer.add(feedbackPanel); this.confirmDeletePanel = new ConfirmDeletePanel("confirm", fieldValuesContainer) { @Override protected void onDeleteTopic(AjaxRequestTarget target) { super.onDeleteTopic(target); FieldInstanceAssociationBinaryPanel.this.onUpdate(target); } }; confirmDeletePanel.setOutputMarkupId(true); fieldValuesContainer.add(confirmDeletePanel); RoleField ofield = (RoleField) roleField.getFieldsForOtherRoles().iterator().next(); this.ofieldModel = new RoleFieldModel(ofield); this.topicModel = new TopicModel<Topic>(fieldInstance.getInstance()); InterfaceControl interfaceControl = ofield.getInterfaceControl(); WebMarkupContainer fieldValuesList = new WebMarkupContainer("fieldValuesList"); fieldValuesContainer.add(fieldValuesList); final String fieldDefinitionId = roleField.getId(); EditMode editMode = roleField.getEditMode(); final boolean ownedvalues = editMode.isOwnedValues(); final boolean allowAdd = !(ownedvalues || editMode.isNewValuesOnly() || editMode.isNoEdit()); final boolean allowCreate = !(editMode.isExistingValuesOnly() || editMode.isNoEdit()); final boolean allowRemove = !editMode.isNoEdit(); final boolean sortable = roleField.isSortable(); // add field values component(s) // TODO: consider moving ordering logic into object model if (sortable) { // HACK: retrieving values ourselves so that we can get them ordered this.fieldValuesModel = new FieldValuesModel(fieldInstanceModel) { @Override protected List<RoleField.ValueIF> getValues(FieldInstance fieldInstance) { Topic instance = fieldInstance.getInstance(); RoleField roleField = (RoleField) fieldInstance.getFieldAssignment().getFieldDefinition(); return roleField.getOrderedValues(instance, ofieldModel.getRoleField()); } }; } else { Comparator<Object> comparator = new RoleFieldValueComparator(topicModel, ofieldModel); this.fieldValuesModel = new FieldValuesModel(fieldInstanceModel, comparator); } this.listView = new ListView<FieldValueModel>("fieldValues", fieldValuesModel) { @Override protected void onBeforeRender() { validateCardinality(); super.onBeforeRender(); } public void populateItem(final ListItem<FieldValueModel> item) { FieldValueModel fieldValueModel = item.getModelObject(); // get topic Topic oplayer = null; if (fieldValueModel.isExistingValue()) { RoleField.ValueIF valueIf = (RoleField.ValueIF) fieldValueModel.getObject(); RoleField ofield = ofieldModel.getRoleField(); oplayer = valueIf.getPlayer(ofield, fieldInstanceModel.getFieldInstance().getInstance()); } final String topicMapId = (oplayer == null ? null : oplayer.getTopicMap().getId()); final String topicId = (oplayer == null ? null : oplayer.getId()); // acquire lock for embedded topic final boolean isLockedByOther; if (embedded && fieldValueModel.isExistingValue()) { OntopolySession session = (OntopolySession) Session.get(); String lockerId = session.getLockerId(getRequest()); LockManager.Lock lock = session.lock(oplayer, lockerId); isLockedByOther = !lock.ownedBy(lockerId); } else { isLockedByOther = false; } final boolean readonly = readonlyField || isLockedByOther; boolean itemSortable = !readonly && sortable && fieldValueModel.isExistingValue(); if (itemSortable) { item.add(new DroppableBehavior(fieldDefinitionId) { @Override protected MarkupContainer getDropContainer() { return listView; } @Override protected void onDrop(Component component, AjaxRequestTarget target) { FieldValueModel fvm_dg = (FieldValueModel) component.getDefaultModelObject(); FieldValueModel fvm_do = (FieldValueModel) getComponent().getDefaultModelObject(); RoleField.ValueIF rfv_dg = (RoleField.ValueIF) fvm_dg.getFieldValue(); RoleField.ValueIF rfv_do = (RoleField.ValueIF) fvm_do.getFieldValue(); Topic topic = topicModel.getTopic(); RoleField rfield = roleFieldModel.getRoleField(); RoleField ofield = ofieldModel.getRoleField(); rfield.moveAfter(topic, ofield, rfv_dg, rfv_do); getModel().detach(); // FIXME: better if we could just tweak model directly without detaching listView.removeAll(); target.addComponent(fieldValuesContainer); } }); item.add(new DraggableBehavior(fieldDefinitionId)); } item.setOutputMarkupId(true); WebMarkupContainer fieldIconContainer = new WebMarkupContainer("fieldIconContainer"); fieldIconContainer .add(new OntopolyImage("fieldIcon", "dnd.gif", new ResourceModel("icon.dnd.reorder"))); fieldIconContainer.setVisible(itemSortable); item.add(fieldIconContainer); final WebMarkupContainer fieldValueButtons = new WebMarkupContainer("fieldValueButtons"); fieldValueButtons.setOutputMarkupId(true); item.add(fieldValueButtons); FieldInstanceRemoveButton removeButton = new FieldInstanceRemoveButton("remove", "remove-value.gif", fieldValueModel) { @Override public boolean isVisible() { boolean visible = !readonly && fieldValueModel.isExistingValue() && allowRemove; // && !isValueProtected; if (visible) { // filter by player AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); RoleField.ValueIF value = (RoleField.ValueIF) fieldValueModel.getObject(); Topic[] players = value.getPlayers(); for (int i = 0; i < players.length; i++) { if (!page.filterTopic(players[i])) return false; } } return visible; } @Override public void onClick(AjaxRequestTarget target) { // FIXME: could reuse some of these variable from above FieldInstance fieldInstance = fieldValueModel.getFieldInstanceModel().getFieldInstance(); Object value = fieldValueModel.getObject(); Topic currentTopic = fieldInstance.getInstance(); RoleField currentField = (RoleField) fieldInstance.getFieldAssignment() .getFieldDefinition(); RoleField selectedField = ofieldModel.getRoleField(); RoleField.ValueIF valueIf = (RoleField.ValueIF) value; Topic selectedTopic = valueIf.getPlayer(selectedField, fieldInstance.getInstance()); // check with page to see if add is allowed boolean changesMade = false; AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); if (page.isRemoveAllowed(currentTopic, currentField, selectedTopic, selectedField)) { if (ownedvalues) { // don't remove system topics if (!selectedTopic.isSystemTopic()) { FieldInstanceAssociationBinaryPanel.this.confirmDeletePanel .setTopic(selectedTopic); changesMade = true; } } else { fieldInstance.removeValue(value, page.getListener()); changesMade = true; } } // notify association panel so that it can update itself if (changesMade) FieldInstanceAssociationBinaryPanel.this.onUpdate(target); } }; fieldValueButtons.add(removeButton); // embedded goto button OntopolyImageLink gotoButton = new OntopolyImageLink("goto", "goto.gif", new ResourceModel("icon.goto.topic")) { @Override public boolean isVisible() { FieldValueModel fieldValueModel = item.getModelObject(); return embedded && fieldValueModel.isExistingValue(); } @Override public void onClick(AjaxRequestTarget target) { // navigate to topic PageParameters pageParameters = new PageParameters(); pageParameters.put("topicMapId", topicMapId); pageParameters.put("topicId", topicId); setResponsePage(getPage().getClass(), pageParameters); setRedirect(true); } }; fieldValueButtons.add(gotoButton); // embedded lock button OntopolyImageLink lockButton = new OntopolyImageLink("lock", "lock.gif", new ResourceModel("icon.topic.locked")) { @Override public boolean isVisible() { return embedded && isLockedByOther; } @Override public void onClick(AjaxRequestTarget target) { } }; fieldValueButtons.add(lockButton); // binary // ISSUE: should not really pass in readonly-parameter here as it is only relevant if page is readonly FieldInstanceAssociationBinaryField binaryField = new FieldInstanceAssociationBinaryField( "fieldValue", ofieldModel, fieldValueModel, fieldsViewModel, readonly, embedded, traversable, allowAdd) { @Override protected void performNewSelection(FieldValueModel fieldValueModel, RoleField selectedField, Topic selectedTopic) { RoleField.ValueIF value = FieldInstanceAssociationBinaryPanel.this .performNewSelection(selectedField, selectedTopic); fieldValueModel.setExistingValue(value); } }; if (binaryField.getUpdateableComponent() != null) binaryField.getUpdateableComponent().add(new FieldUpdatingBehaviour(true)); item.add(binaryField); addNewFieldValueCssClass(item, fieldValuesModel, fieldValueModel); } }; listView.setReuseItems(true); fieldValuesList.add(listView); // figure out which buttons to show this.fieldInstanceButtons = new WebMarkupContainer("fieldInstanceButtons"); fieldInstanceButtons.setOutputMarkupId(true); add(fieldInstanceButtons); if (readonlyField || !allowAdd) { // unused components fieldInstanceButtons.add(new Label("add", new Model<String>("unused")).setVisible(false)); fieldInstanceButtons.add(new Label("find", new Model<String>("unused")).setVisible(false)); fieldInstanceButtons.add(new Label("findModal", new Model<String>("unused")).setVisible(false)); // add/find button } else if (interfaceControl.isDropDownList() || interfaceControl.isAutoComplete()) { // "add" button OntopolyImageLink addButton = new OntopolyImageLink("add", "add.gif") { @Override public void onClick(AjaxRequestTarget target) { boolean showExtraField = !fieldValuesModel.getShowExtraField(); fieldValuesModel.setShowExtraField(showExtraField, true); listView.removeAll(); updateDependentComponents(target); } @Override public boolean isVisible() { if (readonlyField) return false; else return fieldValuesModel.containsExisting(); } @Override public String getImage() { return fieldValuesModel.getShowExtraField() ? "remove.gif" : "add.gif"; } @Override public IModel<String> getTitleModel() { return new ResourceModel( fieldValuesModel.getShowExtraField() ? "icon.remove.hide-field" : "icon.add.add-value"); } }; fieldInstanceButtons.add(addButton); // unused components fieldInstanceButtons.add(new Label("find", new Model<String>("unused")).setVisible(false)); fieldInstanceButtons.add(new Label("findModal", new Model<String>("unused")).setVisible(false)); } else if (interfaceControl.isSearchDialog() || interfaceControl.isBrowseDialog()) { // "search"/"browse" button final ModalWindow findModal = new ModalWindow("findModal"); fieldInstanceButtons.add(findModal); int activeTab = (interfaceControl.isSearchDialog() ? ModalFindPage.ACTIVE_TAB_SEARCH : ModalFindPage.ACTIVE_TAB_BROWSE); findModal .setContent(new ModalFindPage<String>(findModal.getContentId(), fieldInstanceModel, activeTab) { @Override protected void onSelectionConfirmed(AjaxRequestTarget target, Collection<String> selected) { FieldInstance fieldInstance = fieldInstanceModel.getFieldInstance(); RoleField currentField = (RoleField) fieldInstance.getFieldAssignment() .getFieldDefinition(); RoleField selectedField = (RoleField) currentField.getFieldsForOtherRoles().iterator() .next(); // check with page to see if add is allowed if (ObjectUtils.different(currentField, selectedField) || // if assoc type is symmetric currentField == selectedField, // but we're still OK to go ahead, so checking for that // (this is issue 457) currentField.getAssociationType().isSymmetric()) { Topic currentTopic = fieldInstance.getInstance(); TopicMap topicMap = currentTopic.getTopicMap(); boolean changesMade = false; Iterator<String> iter = selected.iterator(); while (iter.hasNext()) { String objectId = (String) iter.next(); AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); Topic selectedTopic = topicMap.getTopicById(objectId); if (page.isAddAllowed(currentTopic, currentField, selectedTopic, selectedField)) { performNewSelection(selectedField, selectedTopic); changesMade = true; } } // notify association panel so that it can update itself if (changesMade) FieldInstanceAssociationBinaryPanel.this.onUpdate(target); } } @Override protected void onCloseCancel(AjaxRequestTarget target) { findModal.close(target); } @Override protected void onCloseOk(AjaxRequestTarget target) { findModal.close(target); } }); findModal.setTitle(new ResourceModel("ModalWindow.title.find.topic").getObject().toString()); findModal.setCookieName("findModal"); OntopolyImageLink findButton = new OntopolyImageLink("find", "search.gif", new ResourceModel("find.topic")) { @Override public void onClick(AjaxRequestTarget target) { findModal.show(target); } }; fieldInstanceButtons.add(findButton); // unused components fieldInstanceButtons.add(new Label("add", new Model<String>("unused")).setVisible(false)); } else { throw new RuntimeException("Unsupported interface control: " + interfaceControl); } // create button if (readonlyField || !allowCreate) { fieldInstanceButtons.add(new Label("create").setVisible(false)); } else { CreateAction ca = roleField.getCreateAction(); int createAction; if (embedded || ca.isNone()) createAction = FieldInstanceCreatePlayerPanel.CREATE_ACTION_NONE; else if (ca.isNavigate()) createAction = FieldInstanceCreatePlayerPanel.CREATE_ACTION_NAVIGATE; else createAction = FieldInstanceCreatePlayerPanel.CREATE_ACTION_POPUP; FieldInstanceCreatePlayerPanel createPanel = new FieldInstanceCreatePlayerPanel("create", fieldInstanceModel, fieldsViewModel, new RoleFieldModel(ofield), this, createAction) { @Override protected void performNewSelection(RoleFieldModel ofieldModel, Topic selectedTopic) { FieldInstanceAssociationBinaryPanel.this.performNewSelection(ofieldModel.getRoleField(), selectedTopic); } }; createPanel.setOutputMarkupId(true); fieldInstanceButtons.add(createPanel); } }
From source file:ontopoly.components.FieldInstanceAssociationNaryField.java
License:Apache License
public FieldInstanceAssociationNaryField(String id, FieldInstanceAssociationNaryPanel _parentPanel, RoleFieldModel roleFieldModel, List<RoleFieldModel> otherRoleFieldModels, FieldValueModel _fieldValueModel, FieldsViewModel fieldsViewModel, final boolean readonly, boolean traversable, final int arity) { super(id);//w w w. ja v a 2s . c o m this.fieldValueModel = _fieldValueModel; this.parentPanel = _parentPanel; this.arity = arity; FieldInstanceModel fieldInstanceModel = fieldValueModel.getFieldInstanceModel(); // register current player this.currentFieldModel = roleFieldModel; this.currentTopicModel = new TopicModel<Topic>(fieldInstanceModel.getFieldInstance().getInstance()); selectedPlayers.put(roleFieldModel, currentTopicModel); RoleField.ValueIF fieldValue = (RoleField.ValueIF) fieldValueModel.getFieldValue(); RepeatingView rv = new RepeatingView("roles"); rv.setVisible(!readonly || fieldValueModel.isExistingValue()); add(rv); Iterator<RoleFieldModel> oiter = otherRoleFieldModels.iterator(); while (oiter.hasNext()) { final RoleFieldModel ofieldModel = oiter.next(); RoleField ofield = ofieldModel.getRoleField(); final WebMarkupContainer parent = new WebMarkupContainer(rv.newChildId()) { @Override public boolean isVisible() { // hide if read-only and not complete if (readonly && selectedPlayers.size() != arity) return false; else return true; } }; parent.setOutputMarkupId(true); rv.add(parent); parent.add(new Label("label", new Model<String>(ofield.getRoleType().getName()))); //! parent.add(new Label("label", new Model(ofield.getFieldName()))); // register other player Topic topic = (fieldValue == null ? null : fieldValue.getPlayer(ofield, fieldInstanceModel.getFieldInstance().getInstance())); final TopicModel<Topic> topicModel = new TopicModel<Topic>(topic); // NOTE: should not use same model as selected model as the model would then be updated immediately selectedPlayers.put(ofieldModel, new TopicModel<Topic>(topic)); TopicLink<Topic> playerLink = new TopicLink<Topic>("player", topicModel); playerLink.setEnabled(traversable); playerLink.setVisible(topic != null); parent.add(playerLink); EditMode editMode = ofield.getEditMode(); final boolean allowAdd = !editMode.isNewValuesOnly(); final boolean allowCreate = !editMode.isExistingValuesOnly(); if (readonly || fieldValueModel.isExistingValue() || !allowAdd) { // unused components parent.add(new Label("select").setVisible(false)); parent.add(new Label("find").setVisible(false)); parent.add(new Label("findModal").setVisible(false)); } else { InterfaceControl interfaceControl = ofield.getInterfaceControl(); if (interfaceControl.isAutoComplete()) { final AssociationFieldAutoCompleteTextField autoCompleteField = new AssociationFieldAutoCompleteTextField( "select", new TopicModel<Topic>(null), ofieldModel) { @Override protected void filterPlayers(List<Topic> players) { AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); page.filterTopics(players); } @Override protected void onTopicSelected(Topic topic) { topicModel.setObject(topic); boolean changesMade = onNewSelection(ofieldModel, topic); // replace ourselves with a topic link if (changesMade) parent.replace(new TopicLink<Topic>("select", new TopicModel<Topic>(topic))); } }; autoCompleteField.getTextField().add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { if (needsUpdate) FieldInstanceAssociationNaryField.this.onUpdate(target); else target.addComponent(parent); } }); autoCompleteField.setOutputMarkupId(true); parent.add(autoCompleteField); // unused components parent.add(new Label("find").setVisible(false)); parent.add(new Label("findModal").setVisible(false)); } else if (interfaceControl.isDropDownList()) { PossiblePlayersModel choicesModel = new PossiblePlayersModel(fieldInstanceModel, ofieldModel) { @Override protected void filterPlayers(Collection<Topic> players) { AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); page.filterTopics(players); } }; TopicDropDownChoice<Topic> choice = new TopicDropDownChoice<Topic>("select", topicModel, choicesModel) { @Override protected void onModelChanged() { super.onModelChanged(); onNewSelection(ofieldModel, getModel().getObject()); } }; choice.setOutputMarkupId(true); choice.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { FieldInstanceAssociationNaryField.this.onUpdate(target); } @Override protected void onError(AjaxRequestTarget target, RuntimeException e) { FieldInstanceAssociationNaryField.this.onError(target, e); } }); parent.add(choice); // unused components parent.add(new Label("find").setVisible(false)); parent.add(new Label("findModal").setVisible(false)); } else if (interfaceControl.isSearchDialog() || interfaceControl.isBrowseDialog()) { // unused components parent.add(new TopicLink<Topic>("select", topicModel)); // "search"/"browse" button final ModalWindow findModal = new ModalWindow("findModal"); parent.add(findModal); int activeTab = (interfaceControl.isSearchDialog() ? ModalFindPage.ACTIVE_TAB_SEARCH : ModalFindPage.ACTIVE_TAB_BROWSE); findModal.setContent( new ModalFindPage<String>(findModal.getContentId(), fieldInstanceModel, activeTab) { @Override protected boolean isMaxOneCardinality() { return true; } @Override protected void onSelectionConfirmed(AjaxRequestTarget target, Collection<String> selected) { if (!selected.isEmpty()) { String topicId = selected.iterator().next(); TopicMap topicMap = fieldValueModel.getFieldInstanceModel() .getFieldInstance().getInstance().getTopicMap(); Topic topic = topicMap.getTopicById(topicId); topicModel.setObject(topic); onNewSelection(ofieldModel, topic); if (needsUpdate) FieldInstanceAssociationNaryField.this.onUpdate(target); else target.addComponent(parent); } } @Override protected void onCloseCancel(AjaxRequestTarget target) { findModal.close(target); } @Override protected void onCloseOk(AjaxRequestTarget target) { findModal.close(target); } }); findModal.setTitle(new ResourceModel("ModalWindow.title.find.topic").getObject().toString()); findModal.setCookieName("findModal"); OntopolyImageLink findButton = new OntopolyImageLink("find", "search.gif", new ResourceModel("icon.search.find-topic")) { @Override public boolean isVisible() { return !readonly; } @Override public void onClick(AjaxRequestTarget target) { findModal.show(target); } }; parent.add(findButton); } else { throw new RuntimeException("Unsupported interface control: " + interfaceControl); } } // create button if (readonly || fieldValueModel.isExistingValue() || !allowCreate) { parent.add(new Label("create").setVisible(false)); } else { // always use popup window int createAction = FieldInstanceCreatePlayerPanel.CREATE_ACTION_POPUP; FieldInstanceCreatePlayerPanel createPanel = new FieldInstanceCreatePlayerPanel("create", fieldInstanceModel, fieldsViewModel, ofieldModel, parentPanel, createAction) { @Override protected Topic createInstance(TopicType topicType) { Topic currentTopic = currentTopicModel.getTopic(); RoleField currentField = currentFieldModel.getRoleField(); RoleField createField = ofieldModel.getRoleField(); Topic createdTopic = null; // check with page to see if add is allowed AbstractOntopolyPage page = (AbstractOntopolyPage) getPage(); if (page.isCreateAllowed(currentTopic, currentField, topicType, createField)) { // create a new topic instance createdTopic = topicType.createInstance(null); topicModel.setObject(createdTopic); performNewSelection(ofieldModel, createdTopic); } return createdTopic; } @Override protected void performNewSelection(RoleFieldModel ofieldModel, Topic selectedTopic) { FieldInstanceAssociationNaryField.this.performNewSelection(ofieldModel, selectedTopic); } @Override protected void hideInstancePage(AjaxRequestTarget target) { if (needsUpdate) FieldInstanceAssociationNaryField.this.onUpdate(target); else target.addComponent(parent); } }; createPanel.setOutputMarkupId(true); parent.add(createPanel); } } }
From source file:ontopoly.components.FieldInstanceCreatePlayerPanel.java
License:Apache License
protected void showInstancePage(AjaxRequestTarget target, Topic topic, TopicType topicType, Component c) { // open modal window final ModalWindow createModal = new ModalWindow("createModal"); TopicModel<Topic> topicModel = new TopicModel<Topic>(topic); TopicTypeModel topicTypeModel = new TopicTypeModel(topicType); createModal.setContent( new ModalInstancePage(createModal.getContentId(), topicModel, topicTypeModel, fieldsViewModel) { @Override/*from ww w . jav a2s. com*/ protected void onCloseOk(AjaxRequestTarget target) { // close modal and update parent createModal.close(target); FieldInstanceCreatePlayerPanel.this.hideInstancePage(target); } }); createModal.setTitle(new ResourceModel("ModalWindow.title.edit.new").getObject().toString() + topicType.getName() + "..."); createModal.setCookieName("createModal"); createModal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { public boolean onCloseButtonClicked(AjaxRequestTarget target) { // modal already closed, now update parent FieldInstanceCreatePlayerPanel.this.hideInstancePage(target); return true; } }); replace(createModal); createModal.show(target); target.addComponent(this); }
From source file:ontopoly.components.FieldInstanceOccurrencePanel.java
License:Apache License
public FieldInstanceOccurrencePanel(String id, final FieldInstanceModel fieldInstanceModel, final boolean readonly) { super(id, fieldInstanceModel); FieldInstance fieldInstance = fieldInstanceModel.getFieldInstance(); FieldAssignment fieldAssignment = fieldInstance.getFieldAssignment(); FieldDefinition fieldDefinition = fieldAssignment.getFieldDefinition(); add(new FieldDefinitionLabel("fieldLabel", new FieldDefinitionModel(fieldDefinition))); // set up container this.fieldValuesContainer = new WebMarkupContainer("fieldValuesContainer"); fieldValuesContainer.setOutputMarkupId(true); add(fieldValuesContainer);//from ww w. j a va2s . c o m // add feedback panel this.feedbackPanel = new FeedbackPanel("feedback", new AbstractFieldInstancePanelFeedbackMessageFilter()); feedbackPanel.setOutputMarkupId(true); fieldValuesContainer.add(feedbackPanel); // add field values component(s) this.fieldValuesModel = new FieldValuesModel(fieldInstanceModel, OccurrenceComparator.INSTANCE); this.listView = new ListView<FieldValueModel>("fieldValues", fieldValuesModel) { @Override protected void onBeforeRender() { validateCardinality(); super.onBeforeRender(); } @Override public void populateItem(final ListItem<FieldValueModel> item) { final FieldValueModel fieldValueModel = item.getModelObject(); FieldInstanceModel fieldInstanceModel = fieldValueModel.getFieldInstanceModel(); FieldInstance fieldInstance = fieldInstanceModel.getFieldInstance(); // TODO: make sure non-existing value field gets focus if last // edit happened there WebMarkupContainer fieldValueButtons = new WebMarkupContainer("fieldValueButtons"); fieldValueButtons.setOutputMarkupId(true); item.add(fieldValueButtons); // remove button FieldInstanceRemoveButton removeButton = new FieldInstanceRemoveButton("remove", "remove-value.gif", fieldValueModel) { @Override public boolean isVisible() { Cardinality cardinality = fieldValuesModel.getFieldInstanceModel().getFieldInstance() .getFieldAssignment().getCardinality(); if (fieldValuesModel.size() == 1 && cardinality.isMinOne()) return false; else return !readonly && fieldValueModel.isExistingValue(); } @Override public void onClick(AjaxRequestTarget target) { super.onClick(target); listView.removeAll(); updateDependentComponents(target); } }; fieldValueButtons.add(removeButton); // we know what kind of field this is, so we can just cast to it directly OccurrenceField of = (OccurrenceField) fieldInstance.getFieldAssignment().getFieldDefinition(); DataType dataType = of.getDataType(); if (readonly) { if (dataType.isImage()) { item.add(new FieldInstanceImageField("fieldValue", fieldValueModel, readonly)); } else { item.add(new Label("fieldValue", new LoadableDetachableModel<String>() { @Override protected String load() { OccurrenceIF occ = (OccurrenceIF) fieldValueModel.getObject(); return (occ == null ? null : occ.getValue()); } })); } } else { final FieldUpdatingBehaviour fuBehaviour = new FieldUpdatingBehaviour(true); if (dataType.isDate()) { FieldInstanceDateField occField = new FieldInstanceDateField("fieldValue", fieldValueModel); occField.add(fuBehaviour); item.add(occField); } else if (dataType.isDateTime()) { FieldInstanceDateTimeField occField = new FieldInstanceDateTimeField("fieldValue", fieldValueModel); occField.add(fuBehaviour); item.add(occField); } else if (dataType.isURI()) { FieldInstanceURIField occField = new FieldInstanceURIField("fieldValue", fieldValueModel); occField.setOutputMarkupId(true); occField.getTextField().add(fuBehaviour); item.add(occField); } else if (dataType.isNumber()) { FieldInstanceNumberField occField = new FieldInstanceNumberField("fieldValue", fieldValueModel); occField.add(fuBehaviour); item.add(occField); } else if (dataType.isHTML()) { FieldInstanceHTMLArea occField = new FieldInstanceHTMLArea("fieldValue", fieldValueModel); occField.getTextArea().add(fuBehaviour); item.add(occField); } else if (dataType.isImage()) { FieldInstanceImageField occField = new FieldInstanceImageField("fieldValue", fieldValueModel, readonly) { @Override public void callOnUpdate(AjaxRequestTarget target) { fuBehaviour.onUpdate(target); } }; item.add(occField); } else { int height = of.getHeight(); if (height > 1) { FieldInstanceTextArea occField = new FieldInstanceTextArea("fieldValue", fieldValueModel); occField.setCols(of.getWidth()); occField.setRows(height); occField.add(fuBehaviour); item.add(occField); } else { FieldInstanceTextField occField = new FieldInstanceTextField("fieldValue", fieldValueModel); occField.setCols(of.getWidth()); occField.add(fuBehaviour); item.add(occField); } } } addNewFieldValueCssClass(item, fieldValuesModel, fieldValueModel); } }; listView.setReuseItems(true); fieldValuesContainer.add(listView); this.fieldInstanceButtons = new WebMarkupContainer("fieldInstanceButtons"); fieldInstanceButtons.setOutputMarkupId(true); add(fieldInstanceButtons); OntopolyImageLink addButton = new OntopolyImageLink("add", "add.gif") { @Override public void onClick(AjaxRequestTarget target) { boolean showExtraField = !fieldValuesModel.getShowExtraField(); fieldValuesModel.setShowExtraField(showExtraField, true); listView.removeAll(); updateDependentComponents(target); } @Override public boolean isVisible() { if (readonly) return false; Cardinality cardinality = fieldValuesModel.getFieldInstanceModel().getFieldInstance() .getFieldAssignment().getCardinality(); return !cardinality.isMaxOne() && fieldValuesModel.containsExisting(); } @Override public String getImage() { return fieldValuesModel.getShowExtraField() ? "remove.gif" : "add.gif"; } @Override public IModel<String> getTitleModel() { return new ResourceModel( fieldValuesModel.getShowExtraField() ? "icon.remove.hide-field" : "icon.add.add-value"); } }; fieldInstanceButtons.add(addButton); final ModalWindow geoPicker = new ModalWindow("geoPickerDialog"); fieldInstanceButtons.add(geoPicker); geoPicker.setContent(new ModalGeoPickerPage(geoPicker, fieldInstance.getInstance())); geoPicker.setTitle(new ResourceModel("ModalWindow.title.geopicker").getObject().toString()); geoPicker.setCookieName("geoPicker"); OccurrenceField of = (OccurrenceField) fieldInstance.getFieldAssignment().getFieldDefinition(); OccurrenceType ot = of.getOccurrenceType(); boolean haspsi = ot.getTopicIF().getSubjectIdentifiers().contains(PSI.ON_LATITUDE); fieldInstanceButtons.add(new GeoPickerButton(!readonly && haspsi, geoPicker)); if (!readonly && haspsi) add(JavascriptPackageResource.getHeaderContribution("http://maps.google.com/maps/api/js?sensor=false")); Cardinality cardinality = fieldAssignment.getCardinality(); if (cardinality.isMaxOne()) addButton.setVisible(false); }
From source file:org.alienlabs.hatchetharry.view.page.HomePage.java
License:Open Source License
private ModalWindow generateAboutLink(final String id, final ModalWindow window) { window.setInitialWidth(450);/*w w w . j a v a 2 s . c om*/ window.setInitialHeight(700); window.setTitle("About HatchetHarry"); window.setContent(new AboutModalWindow(window.getContentId(), window)); window.setCssClassName(ModalWindow.CSS_CLASS_GRAY); window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT); this.add(window); final AjaxLink<Void> aboutLink = new AjaxLink<Void>(id) { private static final long serialVersionUID = 8140325977385015896L; @Override public void onClick(final AjaxRequestTarget target) { target.prependJavaScript(BattlefieldService.HIDE_MENUS); target.appendJavaScript("Wicket.Window.unloadConfirmation = false;"); window.show(target); } }; aboutLink.setOutputMarkupId(true); window.setOutputMarkupId(true); this.add(aboutLink); return window; }