List of usage examples for org.apache.wicket.markup.html.list ListView getModelObject
@SuppressWarnings("unchecked") public final List<T> getModelObject()
From source file:com.evolveum.midpoint.web.component.objectdetails.FocusProjectionsTabPanel.java
License:Apache License
private void initLayout(final PageBase page) { final WebMarkupContainer shadows = new WebMarkupContainer(ID_SHADOWS); shadows.setOutputMarkupId(true);//from ww w . j a v a 2s . co m add(shadows); InlineMenu accountMenu = new InlineMenu(ID_SHADOW_MENU, new Model((Serializable) createShadowMenu())); shadows.add(accountMenu); final ListView<FocusSubwrapperDto<ShadowType>> projectionList = new ListView<FocusSubwrapperDto<ShadowType>>( ID_SHADOW_LIST, projectionModel) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<FocusSubwrapperDto<ShadowType>> item) { PackageResourceReference packageRef; final FocusSubwrapperDto<ShadowType> dto = item.getModelObject(); final PropertyModel<ObjectWrapper<F>> objectWrapperModel = new PropertyModel<ObjectWrapper<F>>( item.getModel(), "object"); final Panel shadowPanel; if (dto.isLoadedOK()) { packageRef = new PackageResourceReference(ImgResources.class, ImgResources.HDD_PRISM); shadowPanel = new PrismObjectPanel<F>(ID_SHADOW, new PropertyModel<ObjectWrapper<F>>(item.getModel(), "object"), packageRef, getMainForm(), getPageBase()); } else { shadowPanel = new SimpleErrorPanel<ShadowType>(ID_SHADOW, item.getModel()) { private static final long serialVersionUID = 1L; @Override public void onShowMorePerformed(AjaxRequestTarget target) { OperationResult fetchResult = dto.getResult(); if (fetchResult != null) { showResult(fetchResult); target.add(page.getFeedbackPanel()); } } }; } shadowPanel.setOutputMarkupId(true); shadowPanel.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { FocusSubwrapperDto<ShadowType> shadowWrapperDto = item.getModelObject(); ObjectWrapper<ShadowType> shadowWrapper = shadowWrapperDto.getObject(); return !shadowWrapper.isMinimalized(); } }); item.add(shadowPanel); CheckTableHeader<F> shadowHeader = new CheckTableHeader<F>(ID_SHADOW_HEADER, objectWrapperModel) { private static final long serialVersionUID = 1L; @Override protected void onClickPerformed(AjaxRequestTarget target) { super.onClickPerformed(target); onExpandCollapse(target, item.getModel()); target.add(shadows); } }; if (item.getModel().getObject().getStatus().equals(UserDtoStatus.DELETE)) { shadowHeader.add(new AttributeModifier("class", "box-header with-border delete")); } item.add(shadowHeader); } }; AjaxCheckBox accountCheckAll = new AjaxCheckBox(ID_SHADOW_CHECK_ALL, new Model()) { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { for (FocusSubwrapperDto<ShadowType> dto : projectionList.getModelObject()) { if (dto.isLoadedOK()) { ObjectWrapper<ShadowType> accModel = dto.getObject(); accModel.setSelected(getModelObject()); } } target.add(shadows); } }; shadows.add(accountCheckAll); shadows.add(projectionList); }
From source file:com.evolveum.midpoint.web.page.admin.BaseFocusPanel.java
License:Apache License
private void initShadows(final WebMarkupContainer accounts) { InlineMenu accountMenu = new InlineMenu(ID_SHADOW_MENU, new Model((Serializable) createShadowMenu())); accounts.add(accountMenu);/* w w w . j a v a 2 s . c o m*/ final ListView<FocusProjectionDto> accountList = new ListView<FocusProjectionDto>(ID_SHADOW_LIST, shadowModel) { @Override protected void populateItem(final ListItem<FocusProjectionDto> item) { PackageResourceReference packageRef; final FocusProjectionDto dto = item.getModelObject(); Panel panel; if (dto.isLoadedOK()) { packageRef = new PackageResourceReference(ImgResources.class, ImgResources.HDD_PRISM); panel = new PrismObjectPanel<F>("shadow", new PropertyModel<ObjectWrapper<F>>(item.getModel(), "object"), packageRef, (Form) page.get(ID_MAIN_FORM), page) { @Override protected Component createHeader(String id, IModel<ObjectWrapper<F>> model) { return new CheckTableHeader(id, (IModel) model) { @Override protected List<InlineMenuItem> createMenuItems() { return createDefaultMenuItems(getModel()); } }; } }; } else { panel = new SimpleErrorPanel("shadow", item.getModel()) { @Override public void onShowMorePerformed(AjaxRequestTarget target) { OperationResult fetchResult = dto.getResult(); if (fetchResult != null) { showResult(fetchResult); target.add(getPageBase().getFeedbackPanel()); } } }; } panel.setOutputMarkupId(true); item.add(panel); } }; AjaxCheckBox accountCheckAll = new AjaxCheckBox(ID_SHADOW_CHECK_ALL, new Model()) { @Override protected void onUpdate(AjaxRequestTarget target) { for (FocusProjectionDto dto : accountList.getModelObject()) { if (dto.isLoadedOK()) { ObjectWrapper accModel = dto.getObject(); accModel.setSelected(getModelObject()); } } target.add(accounts); } }; accounts.add(accountCheckAll); accounts.add(accountList); }
From source file:com.evolveum.midpoint.web.page.admin.BaseFocusPanel.java
License:Apache License
private void initOrgs(final WebMarkupContainer orgs) { InlineMenu orgtMenu = new InlineMenu(ID_ORG_MENU, new Model((Serializable) createOrgMenu())); orgs.add(orgtMenu);/*from www . j a va 2 s .c om*/ final ListView<FocusProjectionDto> orgList = new ListView<FocusProjectionDto>(ID_ORG_LIST, orgModel) { @Override protected void populateItem(final ListItem<FocusProjectionDto> item) { PackageResourceReference packageRef; final FocusProjectionDto dto = item.getModelObject(); Panel panel; if (dto.isLoadedOK()) { packageRef = new PackageResourceReference(ImgResources.class, ImgResources.HDD_PRISM); panel = new PrismObjectPanel<F>("org", new PropertyModel<ObjectWrapper<F>>(item.getModel(), "object"), packageRef, (Form) page.get(ID_MAIN_FORM), page) { @Override protected Component createHeader(String id, IModel<ObjectWrapper<F>> model) { return new CheckTableHeader(id, (IModel) model) { @Override protected List<InlineMenuItem> createMenuItems() { return createDefaultMenuItems(getModel()); } }; } }; } else { panel = new SimpleErrorPanel("org", item.getModel()) { @Override public void onShowMorePerformed(AjaxRequestTarget target) { OperationResult fetchResult = dto.getResult(); if (fetchResult != null) { showResult(fetchResult); target.add(getPageBase().getFeedbackPanel()); } } }; } panel.setOutputMarkupId(true); item.add(panel); } }; AjaxCheckBox orgCheckAll = new AjaxCheckBox(ID_ORG_CHECK_ALL, new Model()) { @Override protected void onUpdate(AjaxRequestTarget target) { for (FocusProjectionDto dto : orgList.getModelObject()) { if (dto.isLoadedOK()) { ObjectWrapper orgModel = dto.getObject(); orgModel.setSelected(getModelObject()); } } target.add(orgs); } }; orgs.add(orgCheckAll); orgs.add(orgList); }
From source file:com.evolveum.midpoint.web.page.admin.reports.PageAuditLogDetails.java
License:Apache License
private void initEventPanel(WebMarkupContainer eventPanel) { WebMarkupContainer eventDetailsPanel = new WebMarkupContainer(ID_EVENT_DETAILS_PANEL); eventDetailsPanel.setOutputMarkupId(true); eventPanel.addOrReplace(eventDetailsPanel); final Label identifier = new Label(ID_PARAMETERS_EVENT_IDENTIFIER, new PropertyModel(recordModel, ID_PARAMETERS_EVENT_IDENTIFIER)); identifier.setOutputMarkupId(true);/*ww w . j a va 2 s . c o m*/ eventDetailsPanel.add(identifier); final Label timestamp = new Label(ID_PARAMETERS_TIMESTAMP, new PropertyModel(recordModel, ID_PARAMETERS_TIMESTAMP)); timestamp.setOutputMarkupId(true); eventDetailsPanel.add(timestamp); final Label sessionIdentifier = new Label(ID_PARAMETERS_SESSION_IDENTIFIER, new PropertyModel(recordModel, ID_PARAMETERS_SESSION_IDENTIFIER)); sessionIdentifier.setOutputMarkupId(true); eventDetailsPanel.add(sessionIdentifier); final Label taskIdentifier = new Label(ID_PARAMETERS_TASK_IDENTIFIER, new PropertyModel(recordModel, ID_PARAMETERS_TASK_IDENTIFIER)); taskIdentifier.setOutputMarkupId(true); eventDetailsPanel.add(taskIdentifier); final Label taskOID = new Label(ID_PARAMETERS_TASK_OID, new PropertyModel(recordModel, ID_PARAMETERS_TASK_OID)); taskOID.setOutputMarkupId(true); eventDetailsPanel.add(taskOID); final Label hostIdentifier = new Label(ID_PARAMETERS_HOST_IDENTIFIER, new PropertyModel(recordModel, ID_PARAMETERS_HOST_IDENTIFIER)); hostIdentifier.setOutputMarkupId(true); eventDetailsPanel.add(hostIdentifier); final Label nodeIdentifier = new Label(ID_PARAMETERS_NODE_IDENTIFIER, new PropertyModel(recordModel, ID_PARAMETERS_NODE_IDENTIFIER)); nodeIdentifier.setOutputMarkupId(true); eventDetailsPanel.add(nodeIdentifier); final Label remoteHostAddress = new Label(ID_PARAMETERS_REMOTE_HOST_ADDRESS, new PropertyModel(recordModel, ID_PARAMETERS_REMOTE_HOST_ADDRESS)); remoteHostAddress.setOutputMarkupId(true); eventDetailsPanel.add(remoteHostAddress); final Label initiatorRef = new Label(ID_PARAMETERS_EVENT_INITIATOR, new Model<>(WebModelServiceUtils.resolveReferenceName(recordModel.getObject().getInitiatorRef(), this, createSimpleTask(ID_PARAMETERS_EVENT_INITIATOR), new OperationResult(ID_PARAMETERS_EVENT_INITIATOR)))); initiatorRef.setOutputMarkupId(true); eventDetailsPanel.add(initiatorRef); final Label attorneyRef = new Label(ID_PARAMETERS_EVENT_ATTORNEY, new Model<>(WebModelServiceUtils.resolveReferenceName(recordModel.getObject().getAttorneyRef(), this, createSimpleTask(ID_PARAMETERS_EVENT_ATTORNEY), new OperationResult(ID_PARAMETERS_EVENT_ATTORNEY)))); attorneyRef.setOutputMarkupId(true); eventDetailsPanel.add(attorneyRef); final Label targetRef = new Label(ID_PARAMETERS_EVENT_TARGET, new Model<>(WebModelServiceUtils.resolveReferenceName(recordModel.getObject().getTargetRef(), this, createSimpleTask(ID_PARAMETERS_EVENT_TARGET), new OperationResult(ID_PARAMETERS_EVENT_TARGET)))); targetRef.setOutputMarkupId(true); eventDetailsPanel.add(targetRef); IModel<String> targetOwnerRefModel = new IModel<String>() { @Override public String getObject() { return WebModelServiceUtils.resolveReferenceName(recordModel.getObject().getTargetOwnerRef(), PageAuditLogDetails.this, createSimpleTask(OPERATION_RESOLVE_REFERENCE_NAME), new OperationResult(OPERATION_RESOLVE_REFERENCE_NAME)); } @Override public void setObject(String s) { } @Override public void detach() { } }; final Label targetOwnerRef = new Label(ID_PARAMETERS_EVENT_TARGET_OWNER, targetOwnerRefModel); targetOwnerRef.setOutputMarkupId(true); eventDetailsPanel.add(targetOwnerRef); final Label eventType = new Label(ID_PARAMETERS_EVENT_TYPE, new PropertyModel(recordModel, ID_PARAMETERS_EVENT_TYPE)); eventType.setOutputMarkupId(true); eventDetailsPanel.add(eventType); final Label eventStage = new Label(ID_PARAMETERS_EVENT_STAGE, new PropertyModel(recordModel, ID_PARAMETERS_EVENT_STAGE)); eventStage.setOutputMarkupId(true); eventDetailsPanel.add(eventStage); final Label channel = new Label(ID_PARAMETERS_CHANNEL, new PropertyModel(recordModel, ID_PARAMETERS_CHANNEL)); channel.setOutputMarkupId(true); eventDetailsPanel.add(channel); final Label eventOutcome = new Label(ID_PARAMETERS_EVENT_OUTCOME, new PropertyModel(recordModel, ID_PARAMETERS_EVENT_OUTCOME)); eventOutcome.setOutputMarkupId(true); eventDetailsPanel.add(eventOutcome); final Label eventResult = new Label(ID_PARAMETERS_EVENT_RESULT, new PropertyModel(recordModel, ID_PARAMETERS_EVENT_RESULT)); eventResult.setOutputMarkupId(true); eventDetailsPanel.add(eventResult); final Label parameter = new Label(ID_PARAMETERS_PARAMETER, new PropertyModel(recordModel, ID_PARAMETERS_PARAMETER)); parameter.setOutputMarkupId(true); eventDetailsPanel.add(parameter); final Label message = new Label(ID_PARAMETERS_MESSAGE, new PropertyModel(recordModel, ID_PARAMETERS_MESSAGE)); message.setOutputMarkupId(true); eventDetailsPanel.add(message); ListView<AuditEventRecordItemValueDto> additionalItemsList = new ListView<AuditEventRecordItemValueDto>( ID_ADDITIONAL_ITEM_LINE, new IModel<List<AuditEventRecordItemValueDto>>() { @Override public List<AuditEventRecordItemValueDto> getObject() { List<AuditEventRecordItemValueDto> rv = new ArrayList<>(); for (AuditEventRecordItemType item : getSortedItems()) { String currentName = getDisplayName(item.getName()); if (item instanceof AuditEventRecordPropertyType) { for (String value : ((AuditEventRecordPropertyType) item).getValue()) { rv.add(new AuditEventRecordItemValueDto(currentName, value)); currentName = null; } } else if (item instanceof AuditEventRecordReferenceType) { for (AuditEventRecordReferenceValueType value : ((AuditEventRecordReferenceType) item) .getValue()) { rv.add(new AuditEventRecordItemValueDto(currentName, value.getTargetName() != null ? value.getTargetName().getOrig() : value.getOid())); currentName = null; } } else { // should not occur } } return rv; } // TODO take locale into account when sorting private List<AuditEventRecordItemType> getSortedItems() { AuditEventRecordType record = recordModel.getObject(); List<AuditEventRecordItemType> rv = new ArrayList<>(); rv.addAll(record.getProperty()); rv.addAll(record.getReference()); rv.sort((a, b) -> { // explicitly enumerated are shown first; others are sorted by display name int index_a = EXTENSION_ITEMS_ORDER.indexOf(a.getName()); int index_b = EXTENSION_ITEMS_ORDER.indexOf(b.getName()); if (index_a != -1 && index_b != -1) { return Integer.compare(index_a, index_b); } else if (index_a != -1) { return -1; } else if (index_b != -1) { return 1; } String name_a = getDisplayName(a.getName()); String name_b = getDisplayName(b.getName()); return String.CASE_INSENSITIVE_ORDER.compare(name_a, name_b); }); return rv; } private String getDisplayName(String nameKey) { // null should not occur so we don't try to be nice when displaying it return nameKey != null ? createStringResource(nameKey).getString() : "(null)"; } }) { @Override protected void populateItem(ListItem<AuditEventRecordItemValueDto> item) { item.add(new Label(ID_ITEM_NAME, new PropertyModel<String>(item.getModel(), AuditEventRecordItemValueDto.F_NAME))); item.add(new Label(ID_ITEM_VALUE, new PropertyModel<String>(item.getModel(), AuditEventRecordItemValueDto.F_VALUE))); } }; WebMarkupContainer additionalItemsContainer = new WebMarkupContainer(ID_ADDITIONAL_ITEMS); additionalItemsContainer.add(additionalItemsList); additionalItemsContainer.add(new VisibleBehaviour(() -> !additionalItemsList.getModelObject().isEmpty())); eventDetailsPanel.add(additionalItemsContainer); }
From source file:com.evolveum.midpoint.web.page.admin.users.PageUser.java
License:Apache License
private void initAccounts(final WebMarkupContainer accounts) { InlineMenu accountMenu = new InlineMenu(ID_ACCOUNT_MENU, new Model((Serializable) createAccountsMenu())); accounts.add(accountMenu);//from w w w.jav a 2 s.co m final ListView<UserAccountDto> accountList = new ListView<UserAccountDto>(ID_ACCOUNT_LIST, accountsModel) { @Override protected void populateItem(final ListItem<UserAccountDto> item) { PackageResourceReference packageRef; final UserAccountDto dto = item.getModelObject(); Panel panel; if (dto.isLoadedOK()) { packageRef = new PackageResourceReference(ImgResources.class, ImgResources.HDD_PRISM); panel = new PrismObjectPanel("account", new PropertyModel<ObjectWrapper>(item.getModel(), "object"), packageRef, (Form) PageUser.this.get(ID_MAIN_FORM)) { @Override protected Component createHeader(String id, IModel<ObjectWrapper> model) { return new CheckTableHeader(id, model) { @Override protected List<InlineMenuItem> createMenuItems() { return createDefaultMenuItems(getModel()); } }; } }; } else { panel = new SimpleErrorPanel("account", item.getModel()) { @Override public void onShowMorePerformed(AjaxRequestTarget target) { OperationResult fetchResult = dto.getResult(); if (fetchResult != null) { showResult(fetchResult); target.add(getPageBase().getFeedbackPanel()); } } }; } panel.setOutputMarkupId(true); item.add(panel); } }; AjaxCheckBox accountCheckAll = new AjaxCheckBox(ID_ACCOUNT_CHECK_ALL, new Model()) { @Override protected void onUpdate(AjaxRequestTarget target) { for (UserAccountDto dto : accountList.getModelObject()) { if (dto.isLoadedOK()) { ObjectWrapper accModel = dto.getObject(); accModel.setSelected(getModelObject()); } } target.add(accounts); } }; accounts.add(accountCheckAll); accounts.add(accountList); }
From source file:com.evolveum.midpoint.web.page.admin.users.PageUser.java
License:Apache License
private void initAssignments(final WebMarkupContainer assignments) { InlineMenu accountMenu = new InlineMenu(ID_ASSIGNMENT_MENU, new Model((Serializable) createAssignmentsMenu())); assignments.add(accountMenu);//from ww w . ja v a 2 s . c om final ListView<AssignmentEditorDto> assignmentList = new ListView<AssignmentEditorDto>(ID_ASSIGNMENT_LIST, assignmentsModel) { @Override protected void populateItem(final ListItem<AssignmentEditorDto> item) { AssignmentEditorPanel assignmentEditor = new AssignmentEditorPanel(ID_ASSIGNMENT_EDITOR, item.getModel()); item.add(assignmentEditor); } }; assignmentList.setOutputMarkupId(true); assignments.add(assignmentList); AjaxCheckBox assignmentCheckAll = new AjaxCheckBox(ID_ASSIGNMENT_CHECK_ALL, new Model()) { @Override protected void onUpdate(AjaxRequestTarget target) { for (AssignmentEditorDto item : assignmentList.getModelObject()) { item.setSelected(this.getModelObject()); } target.add(assignments); } }; assignments.add(assignmentCheckAll); }
From source file:com.tysanclan.site.projectewok.pages.forum.ForumThreadSplitPage.java
License:Open Source License
public ForumThreadSplitPage(ForumThread thread) { super("Split thread: " + thread.getTitle()); TysanSession sess = (TysanSession) Session.get(); User u = sess != null ? sess.getUser() : null; List<ForumPost> posts = forumService.filterPosts(u, false, thread.getPosts()); ForumPost firstPost = posts.get(0);//from www . j a v a 2s . c om List<ForumPost> filtered = new ArrayList<ForumPost>(posts.size() - 1); for (ForumPost post : posts) { if (!firstPost.equals(post)) { filtered.add(post); } } final ListView<PostSelectionPair> postselection = new ListView<PostSelectionPair>("postselection", new PostSelectionPairModel(posts)) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<PostSelectionPair> item) { IModel<PostSelectionPair> model = item.getModel(); item.add(new CheckBox("checkbox", new PropertyModel<Boolean>(model, "selected"))); item.add(new PostPanel("postpanel", model.getObject().getPost())); } }; final TextField<String> titleField = new TextField<String>("title", new Model<String>("")); final ForumPostEditorPanel editor = new ForumPostEditorPanel("editor", ""); Form<ForumThread> form = new Form<ForumThread>("splitform", ModelMaker.wrap(thread)) { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { ForumThread t = getModelObject(); TysanSession session = (TysanSession) Session.get(); User user = session != null ? session.getUser() : null; List<PostSelectionPair> pairsLIst = postselection.getModelObject(); List<ForumPost> postList = new LinkedList<ForumPost>(); for (PostSelectionPair pair : pairsLIst) { if (pair.getSelected() == true) { postList.add(pair.getPost()); } } if (titleField.getModelObject() == null || titleField.getModelObject().trim().isEmpty()) { error("Title may not be empty!"); } else if (editor.getEditorContent().trim().isEmpty()) { error("Thread opening may not be empty"); } else if (postList.isEmpty()) { error("You must select at least 1 post to move to the new thread"); } else { if (forumService.isModerator(user, t.getForum())) { ForumThread result = forumService.splitThread(t, postList, titleField.getModelObject(), editor.getEditorContent(), user); if (result == null) { error("Could not split thread: permission denied!"); } } else { error("Could not split thread: permission denied!"); } setResponsePage(new ForumThreadPage(t.getId(), 1, false)); } } }; form.add(editor); form.add(titleField); form.add(postselection); form.add(new PostPanel("threadstart", firstPost, false)); form.add(new ThreadLink("no", thread)); add(form); }
From source file:com.tysanclan.site.projectewok.pages.member.CalendarPage.java
License:Open Source License
/** * /*from ww w . j a v a 2 s. c o m*/ */ public CalendarPage() { super("Calendar"); add(new OtterSniperPanel("otterSniperPanel", 2)); WebMarkupContainer container = new WebMarkupContainer("container"); container.setOutputMarkupId(true); Date currTime = DateUtil.getMidnightCalendarInstance().getTime(); InlineDatePicker calendar = new InlineDatePicker("calendar", currTime) { /** * */ private static final long serialVersionUID = 1L; @Override protected void onDateSelected(Date date, AjaxRequestTarget target) { TimeZone tz = DateUtil.NEW_YORK; if (getUser().getTimezone() != null) { tz = TimeZone.getTimeZone(getUser().getTimezone()); } Calendar cal = Calendar.getInstance(tz); cal.setTime(date); Component oldEventView = getEventViewComponent(); Component oldTitle = getTitleComponent(); ListView<Event> eventView = createListView(cal.getTime()); getContainer().setVisible(!eventView.getModelObject().isEmpty()); Label newTitle = new Label("title", "Events for " + new SimpleDateFormat("EEEE d MMMM yyyy", Locale.US).format(date)); oldEventView.replaceWith(eventView); oldTitle.replaceWith(newTitle); Component component = get("schedule:description").setVisible(true); if (target != null) { target.appendJavaScript( "tinyMCE.execCommand('mceRemoveControl', false, '" + component.getMarkupId() + "')"); target.add(getContainer()); target.appendJavaScript( "tinyMCE.execCommand('mceAddControl', false, '" + component.getMarkupId() + "')"); } } }; container.add(calendar); add(container); ListView<Event> eventView = createListView(currTime); container.add(eventView); container.setVisible(!eventView.getModelObject().isEmpty()); container.add(new Label("title", "Events for " + new SimpleDateFormat("EEEE d MMMM yyyy", Locale.US).format(currTime))); Form<Event> scheduleEventForm = new Form<Event>("schedule") { private static final long serialVersionUID = 1L; @SpringBean private EventService eventService; @SuppressWarnings("unchecked") @Override protected void onSubmit() { TextField<String> titleComponent = (TextField<String>) get("title"); TextArea<String> descriptionComponent = (TextArea<String>) get("description"); DatePickerPanel dateComponent = (DatePickerPanel) get("dateselect"); DropDownChoice<Integer> hourComponent = (DropDownChoice<Integer>) get("hourselect"); DropDownChoice<Integer> minuteComponent = (DropDownChoice<Integer>) get("minuteselect"); String title = titleComponent.getModelObject(); String description = descriptionComponent.getModelObject(); Date selectedDate = dateComponent.getSelectedDate(); if (selectedDate == null) { error("No date selected"); return; } TimeZone tz = DateUtil.NEW_YORK; if (getUser().getTimezone() != null) { tz = TimeZone.getTimeZone(getUser().getTimezone()); } Calendar cal = Calendar.getInstance(tz); cal.setTime(DateUtil.getMidnightDate(selectedDate)); cal.add(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.HOUR_OF_DAY, hourComponent.getModelObject()); cal.add(Calendar.MINUTE, minuteComponent.getModelObject()); Event event = eventService.scheduleEvent(getUser(), cal.getTime(), title, description); if (event != null) { setResponsePage(new CalendarPage()); } } }; scheduleEventForm.add(new TextField<String>("title", new Model<String>("")).setRequired(true)); TextArea<String> descriptionEditor = new BBCodeTextArea("description", ""); descriptionEditor.setRequired(true); scheduleEventForm.add(descriptionEditor); DatePickerPanel datePanel = new DatePickerPanel("dateselect"); scheduleEventForm.add(datePanel); scheduleEventForm.add(new DropDownChoice<Integer>("hourselect", new Model<Integer>(0), DateUtil.getHours(), DateUtil.getTwoDigitRenderer()).setNullValid(false).setRequired(true)); scheduleEventForm.add(new DropDownChoice<Integer>("minuteselect", new Model<Integer>(0), DateUtil.getMinutes(), DateUtil.getTwoDigitRenderer()).setNullValid(false).setRequired(true)); TimeZone tz = DateUtil.NEW_YORK; if (getUser().getTimezone() != null) { tz = TimeZone.getTimeZone(getUser().getTimezone()); } scheduleEventForm.add(new Label("timezone", tz.getDisplayName(false, TimeZone.LONG, Locale.US))); add(scheduleEventForm); }
From source file:org.apache.syncope.client.console.pages.ConnectorModalPage.java
License:Apache License
public ConnectorModalPage(final PageReference pageRef, final ModalWindow window, final ConnInstanceTO connInstanceTO) { super();/*from w ww . j a v a 2 s . c o m*/ this.add(new Label("new", connInstanceTO.getKey() == 0 ? new ResourceModel("new") : new Model<>(StringUtils.EMPTY))); this.add(new Label("key", connInstanceTO.getKey() == 0 ? StringUtils.EMPTY : connInstanceTO.getKey())); // general data setup selectedCapabilities = new ArrayList<>( connInstanceTO.getKey() == 0 ? EnumSet.noneOf(ConnectorCapability.class) : connInstanceTO.getCapabilities()); mapConnBundleTOs = new HashMap<>(); for (ConnBundleTO connBundleTO : restClient.getAllBundles()) { // by location if (!mapConnBundleTOs.containsKey(connBundleTO.getLocation())) { mapConnBundleTOs.put(connBundleTO.getLocation(), new HashMap<String, Map<String, ConnBundleTO>>()); } final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs .get(connBundleTO.getLocation()); // by name if (!byLocation.containsKey(connBundleTO.getBundleName())) { byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>()); } final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName()); // by version if (!byName.containsKey(connBundleTO.getVersion())) { byName.put(connBundleTO.getVersion(), connBundleTO); } } bundleTO = getSelectedBundleTO(connInstanceTO); properties = fillProperties(bundleTO, connInstanceTO); // form - first tab final Form<ConnInstanceTO> connectorForm = new Form<>(FORM); connectorForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorForm.setOutputMarkupId(true); add(connectorForm); propertiesContainer = new WebMarkupContainer("container"); propertiesContainer.setOutputMarkupId(true); connectorForm.add(propertiesContainer); final Form<ConnInstanceTO> connectorPropForm = new Form<>("connectorPropForm"); connectorPropForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorPropForm.setOutputMarkupId(true); propertiesContainer.add(connectorPropForm); final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name", new PropertyModel<String>(connInstanceTO, "displayName")); displayName.setOutputMarkupId(true); displayName.addRequiredLabel(); connectorForm.add(displayName); final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<>("location", "location", new Model<>(bundleTO == null ? null : bundleTO.getLocation())); ((DropDownChoice<String>) location.getField()).setNullValid(true); location.setStyleSheet("long_dynamicsize"); location.setChoices(new ArrayList<>(mapConnBundleTOs.keySet())); location.setRequired(true); location.addRequiredLabel(); location.setOutputMarkupId(true); location.setEnabled(connInstanceTO.getKey() == 0); location.getField().setOutputMarkupId(true); connectorForm.add(location); final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<>("connectorName", "connectorName", new Model<>(bundleTO == null ? null : bundleTO.getBundleName())); ((DropDownChoice<String>) connectorName.getField()).setNullValid(true); connectorName.setStyleSheet("long_dynamicsize"); connectorName.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet())); connectorName.setRequired(true); connectorName.addRequiredLabel(); connectorName.setEnabled(connInstanceTO.getLocation() != null); connectorName.setOutputMarkupId(true); connectorName.setEnabled(connInstanceTO.getKey() == 0); connectorName.getField().setOutputMarkupId(true); connectorForm.add(connectorName); final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<>("version", "version", new Model<>(bundleTO == null ? null : bundleTO.getVersion())); version.setStyleSheet("long_dynamicsize"); version.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()) .get(connInstanceTO.getBundleName()).keySet())); version.setRequired(true); version.addRequiredLabel(); version.setEnabled(connInstanceTO.getBundleName() != null); version.setOutputMarkupId(true); version.addRequiredLabel(); version.getField().setOutputMarkupId(true); connectorForm.add(version); final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<>("connRequestTimeout", "connRequestTimeout", Integer.class, new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null); connRequestTimeout.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(connRequestTimeout); if (connInstanceTO.getPoolConf() == null) { connInstanceTO.setPoolConf(new ConnPoolConfTO()); } final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<>("poolMaxObjects", "poolMaxObjects", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null); poolMaxObjects.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxObjects); final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<>("poolMinIdle", "poolMinIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null); poolMinIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMinIdle); final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<>("poolMaxIdle", "poolMaxIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null); poolMaxIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxIdle); final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<>("poolMaxWait", "poolMaxWait", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null); poolMaxWait.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMaxWait); final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<>("poolMinEvictableIdleTime", "poolMinEvictableIdleTime", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null); poolMinEvictableIdleTime.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMinEvictableIdleTime); // form - first tab - onchange() location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) location.getField()).setNullValid(false); connInstanceTO.setLocation(location.getModelObject()); target.add(location); connectorName.setChoices(new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()).keySet())); connectorName.setEnabled(true); connectorName.getField().setModelValue(null); target.add(connectorName); version.setChoices(new ArrayList<String>()); version.getField().setModelValue(null); version.setEnabled(false); target.add(version); properties.clear(); target.add(propertiesContainer); } }); connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) connectorName.getField()).setNullValid(false); connInstanceTO.setBundleName(connectorName.getModelObject()); target.add(connectorName); List<String> versions = new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()) .get(connectorName.getModelObject()).keySet()); version.setChoices(versions); version.setEnabled(true); if (versions.size() == 1) { selectVersion(target, connInstanceTO, version, versions.get(0)); version.getField().setModelObject(versions.get(0)); } else { version.getField().setModelValue(null); properties.clear(); target.add(propertiesContainer); } target.add(version); } }); version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { selectVersion(target, connInstanceTO, version, version.getModelObject()); } }); // form - second tab (properties) final ListView<ConnConfProperty> connPropView = new ConnConfPropertyListView("connectorProperties", new PropertyModel<List<ConnConfProperty>>(this, "properties"), true, connInstanceTO.getConfiguration()); connPropView.setOutputMarkupId(true); connectorPropForm.add(connPropView); final AjaxButton check = new IndicatingAjaxButton("check", new ResourceModel("check")) { private static final long serialVersionUID = -7978723352517770644L; @Override public void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); // ensure that connector bundle information is in sync conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.setConnectorName(bundleTO.getConnectorName()); if (restClient.check(conn)) { info(getString("success_connection")); } else { error(getString("error_connection")); } feedbackPanel.refresh(target); } }; connectorPropForm.add(check); // form - third tab (capabilities) final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<ConnectorCapability> load() { return Arrays.asList(ConnectorCapability.values()); } }; CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<>( "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"), capabilities); capabilitiesPalette.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(AjaxRequestTarget target) { } }); connectorForm.add(capabilitiesPalette); // form - submit / cancel buttons final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<>(getString(SUBMIT))) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); conn.setConnectorName(bundleTO.getConnectorName()); conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.getConfiguration().clear(); conn.getConfiguration().addAll(connPropView.getModelObject()); // Set the model object's capabilities to capabilitiesPalette's converted Set conn.getCapabilities().clear(); conn.getCapabilities() .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class) : EnumSet.copyOf(selectedCapabilities)); // Reset pool configuration if all fields are null if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null && conn.getPoolConf().getMinIdle() == null) { conn.setPoolConf(null); } try { if (connInstanceTO.getKey() == 0) { restClient.create(conn); } else { restClient.update(conn); } ((Resources) pageRef.getPage()).setModalResult(true); window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); ((Resources) pageRef.getPage()).setModalResult(false); LOG.error("While creating or updating connector {}", conn, e); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; String roles = connInstanceTO.getKey() == 0 ? xmlRolesReader.getEntitlement("Connectors", "create") : xmlRolesReader.getEntitlement("Connectors", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles); connectorForm.add(submit); final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); connectorForm.add(cancel); }
From source file:org.apache.syncope.client.console.pages.LogViewer.java
License:Apache License
public LogViewer() { final WebMarkupContainer viewer = new WebMarkupContainer("viewer"); viewer.setOutputMarkupId(true);//from w w w. j ava 2s .c o m add(viewer); final AjaxDropDownChoicePanel<String> appenders = new AjaxDropDownChoicePanel<>("appenders", "Appender", new Model<String>(), false); MetaDataRoleAuthorizationStrategy.authorize(appenders, ENABLE, StandardEntitlement.LOG_READ); appenders.setChoices(restClient.listMemoryAppenders()); viewer.add(appenders); final WebMarkupContainer stContainer = new WebMarkupContainer("stContainer"); stContainer.setOutputMarkupId(true); viewer.add(stContainer); final Model<Long> lastTimeInMillis = Model.of(0L); final IModel<List<LogStatementTO>> statementViewModel = new ListModel<>(new ArrayList<LogStatementTO>()); final ListView<LogStatementTO> statementView = new ListView<LogStatementTO>("statements", statementViewModel) { private static final long serialVersionUID = -9180479401817023838L; @Override protected void populateItem(final ListItem<LogStatementTO> item) { LogStatementPanel panel = new LogStatementPanel("statement", item.getModelObject()); panel.setOutputMarkupId(true); item.add(panel); } }; statementView.setOutputMarkupId(true); stContainer.add(statementView); stContainer.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(10)) { private static final long serialVersionUID = 7298597675929755960L; @Override protected void onPostProcessTarget(final AjaxRequestTarget target) { // save scroll position target.prependJavaScript( String.format("window.scrollTop = $('#%s').scrollTop();", stContainer.getMarkupId())); List<LogStatementTO> recentLogStatements = appenders.getModelObject() == null ? new ArrayList<LogStatementTO>() : restClient.getLastLogStatements(appenders.getModelObject(), lastTimeInMillis.getObject()); if (!recentLogStatements.isEmpty()) { lastTimeInMillis .setObject(recentLogStatements.get(recentLogStatements.size() - 1).getTimeMillis()); int currentSize = statementView.getModelObject().size(); int recentSize = recentLogStatements.size(); List<LogStatementTO> newModelObject = SetUniqueList.<LogStatementTO>setUniqueList( new ArrayList<LogStatementTO>(MAX_STATEMENTS_PER_APPENDER)); if (currentSize <= MAX_STATEMENTS_PER_APPENDER - recentSize) { newModelObject.addAll(statementView.getModelObject()); } else { newModelObject.addAll(statementView.getModelObject() .subList(currentSize - (MAX_STATEMENTS_PER_APPENDER - recentSize), currentSize)); } newModelObject.addAll(recentLogStatements); statementViewModel.setObject(newModelObject); target.add(stContainer); } // restore scroll position - might not work perfectly if items were removed from the top target.appendJavaScript( String.format("$('#%s').scrollTop(window.scrollTop);", stContainer.getMarkupId())); } }); appenders.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { List<LogStatementTO> lastStatements = appenders.getModelObject() == null ? new ArrayList<LogStatementTO>() : restClient.getLastLogStatements(appenders.getModelObject(), 0); statementViewModel.setObject(lastStatements); target.add(stContainer); lastTimeInMillis.setObject(0L); } }); }