Java Code Examples for org.apache.wicket.model.Model#ofMap()

The following examples show how to use org.apache.wicket.model.Model#ofMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobSingleChoiceEditor.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	Map<String, String> choices = new LinkedHashMap<>();
	for (String jobName: Project.get().getJobNames())
		choices.put(jobName, jobName);
	
	String selection = getModelObject();
	if (!choices.containsKey(selection))
		selection = null;
	
	input = new JobSingleChoice("input", Model.of(selection), Model.ofMap(choices)) {
		
		@Override
		protected void onInitialize() {
			super.onInitialize();
			getSettings().configurePlaceholder(descriptor);
		}
		
	};
	input.setRequired(descriptor.isPropertyRequired());
       input.setLabel(Model.of(getDescriptor().getDisplayName()));
       
       add(input);
}
 
Example 2
Source File: JobMultiChoiceEditor.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	Map<String, String> choices = new LinkedHashMap<>();
	for (String jobName: Project.get().getJobNames())
		choices.put(jobName, jobName);
	
   	List<String> selections = new ArrayList<>();
	if (getModelObject() != null) {
		for (String selection: getModelObject()) {
			if (choices.containsKey(selection))
				selections.add(selection);
		}
	}
	
	input = new JobMultiChoice("input", Model.of(selections), Model.ofMap(choices)) {

		@Override
		protected void onInitialize() {
			super.onInitialize();
			getSettings().configurePlaceholder(descriptor);
		}
		
	};
	input.setRequired(descriptor.isPropertyRequired());
	
       input.setLabel(Model.of(getDescriptor().getDisplayName()));
       
       add(input);
}
 
Example 3
Source File: BranchSingleChoiceEditor.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
   	
	Map<String, String> choices = new LinkedHashMap<>();
	if (Project.get() != null) {
		for (RefInfo ref: Project.get().getBranchRefInfos()) {
			String branch = GitUtils.ref2branch(ref.getRef().getName());
			choices.put(branch, branch);
		}
	}
	
	String selection = getModelObject();
	if (!choices.containsKey(selection))
		selection = null;

   	input = new BranchSingleChoice("input", Model.of(selection), Model.ofMap(choices)) {
   		
		@Override
		protected void onInitialize() {
			super.onInitialize();
			getSettings().configurePlaceholder(descriptor);
		}
		
   	};
   	
       // add this to control allowClear flag of select2
   	input.setRequired(descriptor.isPropertyRequired());
       input.setLabel(Model.of(getDescriptor().getDisplayName()));
	input.add(new AjaxFormComponentUpdatingBehavior("change"){

		@Override
		protected void onUpdate(AjaxRequestTarget target) {
			onPropertyUpdating(target);
		}
		
	});
	
       add(input);
}
 
Example 4
Source File: RoleMultiChoiceEditor.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	Map<String, String> roleNames = new LinkedHashMap<>();
	for (Role role: OneDev.getInstance(RoleManager.class).query())
		roleNames.put(role.getName(), role.getName());
	
	Collection<String> selections = new ArrayList<>();
	if (getModelObject() != null)
		selections.addAll(getModelObject());
	
	selections.retainAll(roleNames.keySet());
	
	input = new StringMultiChoice("input", Model.of(selections), Model.ofMap(roleNames)) {

		@Override
		protected void onInitialize() {
			super.onInitialize();
			getSettings().configurePlaceholder(descriptor);
		}
		
	};
       input.setConvertEmptyInputStringToNull(true);
       
       input.setRequired(descriptor.isPropertyRequired());
       input.setLabel(Model.of(getDescriptor().getDisplayName()));
       
	input.add(new AjaxFormComponentUpdatingBehavior("change"){

		@Override
		protected void onUpdate(AjaxRequestTarget target) {
			onPropertyUpdating(target);
		}
		
	});
	
       add(input);
}
 
Example 5
Source File: RoleSingleChoiceEditor.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	Map<String, String> roleNames = new LinkedHashMap<>();
	for (Role role: OneDev.getInstance(RoleManager.class).query())
		roleNames.put(role.getName(), role.getName());
	
	String selection = getModelObject();
	if (!roleNames.containsKey(selection))
		selection = null;
	
   	input = new StringSingleChoice("input", Model.of(selection), Model.ofMap(roleNames)) {

		@Override
		protected void onInitialize() {
			super.onInitialize();
			getSettings().configurePlaceholder(descriptor);
		}
   		
   	};
       
       // add this to control allowClear flag of select2
   	input.setRequired(descriptor.isPropertyRequired());
       input.setLabel(Model.of(getDescriptor().getDisplayName()));
       
	input.add(new AjaxFormComponentUpdatingBehavior("change"){

		@Override
		protected void onUpdate(AjaxRequestTarget target) {
			onPropertyUpdating(target);
		}
		
	});
	add(input);
}
 
Example 6
Source File: CourseGradeStatisticsPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get the course grade data for the site and wrap it
 *
 * @param siteId siteId to get data for
 * @return
 */
private IModel<Map<String, Object>> getData(final String siteId) {
	final Map<String, Object> data = new HashMap<>();
	data.put("courseGradeMap", this.businessService.getCourseGrades(siteId));

	final GradebookInformation info = this.businessService.getGradebookSettings(siteId);
	data.put("gradingSchemaName", info.getGradeScale());
	data.put("bottomPercents", info.getSelectedGradingScaleBottomPercents());

	return Model.ofMap(data);
}
 
Example 7
Source File: SettingsGradingSchemaPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get the stats data we need for {@link CourseGradeStatistics}
 *
 * @return Model of data
 */
private IModel<Map<String, Object>> getStatsData() {
	final Map<String, Object> data = new HashMap<>();
	data.put("courseGradeMap", this.courseGradeMap);
	data.put("gradingSchemaName", this.gradingSchemaName);
	data.put("bottomPercents", getBottomPercents());
	return Model.ofMap(data);
}
 
Example 8
Source File: AssignmentStatisticsPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get the grade data for the assignment and wrap it
 *
 * @param assignment assignment to get data for
 * @return
 */
private IModel<Map<String, Object>> getData(final Assignment assignment) {
	final Map<String, Object> data = new HashMap<>();
	data.put("gradeInfo", this.businessService.buildGradeMatrix(Arrays.asList(assignment)));
	data.put("assignmentId", assignment.getId());
	return Model.ofMap(data);
}
 
Example 9
Source File: CourseGradeStatisticsPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get the course grade data for the site and wrap it
 *
 * @param siteId siteId to get data for
 * @return
 */
private IModel<Map<String, Object>> getData(final String siteId) {
	final Map<String, Object> data = new HashMap<>();
	data.put("courseGradeMap", this.businessService.getCourseGrades(siteId));

	final GradebookInformation info = this.businessService.getGradebookSettings(siteId);
	data.put("gradingSchemaName", info.getGradeScale());
	data.put("bottomPercents", info.getSelectedGradingScaleBottomPercents());

	return Model.ofMap(data);
}
 
Example 10
Source File: SettingsGradingSchemaPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get the stats data we need for {@link CourseGradeStatistics}
 *
 * @return Model of data
 */
private IModel<Map<String, Object>> getStatsData() {
	final Map<String, Object> data = new HashMap<>();
	data.put("courseGradeMap", this.courseGradeMap);
	data.put("gradingSchemaName", this.gradingSchemaName);
	data.put("bottomPercents", getBottomPercents());
	return Model.ofMap(data);
}
 
Example 11
Source File: AssignmentStatisticsPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get the grade data for the assignment and wrap it
 *
 * @param assignment assignment to get data for
 * @return
 */
private IModel<Map<String, Object>> getData(final Assignment assignment) {
	final Map<String, Object> data = new HashMap<>();
	data.put("gradeInfo", this.businessService.buildGradeMatrix(Arrays.asList(assignment)));
	data.put("assignmentId", assignment.getId());
	return Model.ofMap(data);
}
 
Example 12
Source File: BranchMultiChoiceEditor.java    From onedev with MIT License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	Map<String, String> choices = new LinkedHashMap<>();
	if (Project.get() != null) {
		for (RefInfo ref: Project.get().getBranchRefInfos()) {
			String branch = GitUtils.ref2branch(ref.getRef().getName());
			choices.put(branch, branch);
		}
	}

   	Collection<String> selections = new ArrayList<>();
	if (getModelObject() != null) {
		for (String selection: getModelObject()) {
			if (choices.containsKey(selection))
				selections.add(selection);
		}
	}
	
	input = new BranchMultiChoice("input", Model.of(selections), Model.ofMap(choices)) {

		@Override
		protected void onInitialize() {
			super.onInitialize();
			getSettings().configurePlaceholder(descriptor);
		}
		
	};
       input.setLabel(Model.of(getDescriptor().getDisplayName()));
       
       input.setRequired(descriptor.isPropertyRequired());
       
	input.add(new AjaxFormComponentUpdatingBehavior("change"){

		@Override
		protected void onUpdate(AjaxRequestTarget target) {
			onPropertyUpdating(target);
		}
		
	});
	
       add(input);
}
 
Example 13
Source File: ViewGradeSummaryAction.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) {
	final String studentUuid = params.get("studentId").asText();

	final GradebookUiSettings settings = ((GradebookPage) target.getPage()).getUiSettings();

	final GbUser student = businessService.getUser(studentUuid);

	final Map<String, Object> model = new HashMap<>();
	model.put("studentUuid", studentUuid);
	model.put("groupedByCategoryByDefault", settings.isCategoriesEnabled());

	final GradebookPage gradebookPage = (GradebookPage) target.getPage();
	final GbModalWindow window = gradebookPage.getStudentGradeSummaryWindow();

	final Component content = new StudentGradeSummaryPanel(window.getContentId(), Model.ofMap(model), window);

	if (window.isShown() && window.isVisible()) {
		window.replace(content);
		content.setVisible(true);
		target.add(content);
	} else {
		window.setContent(content);
		window.show(target);
	}

	window.setStudentToReturnFocusTo(studentUuid);
	content.setOutputMarkupId(true);

	final String modalTitle = (new StringResourceModel("heading.studentsummary",
			null, new Object[] { student.getDisplayName(), student.getDisplayId() })).getString();

	window.setTitle(modalTitle);
	window.show(target);

	target.appendJavaScript(String.format(
			"new GradebookGradeSummary($(\"#%s\"), false, \"%s\");",
			content.getMarkupId(), modalTitle));

	return new EmptyOkResponse();
}
 
Example 14
Source File: ViewGradeSummaryAction.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) {
	final String studentUuid = params.get("studentId").asText();

	final GradebookUiSettings settings = ((GradebookPage) target.getPage()).getUiSettings();

	final GbUser student = businessService.getUser(studentUuid);

	final Map<String, Object> model = new HashMap<>();
	model.put("studentUuid", studentUuid);
	model.put("groupedByCategoryByDefault", settings.isCategoriesEnabled());

	final GradebookPage gradebookPage = (GradebookPage) target.getPage();
	final GbModalWindow window = gradebookPage.getStudentGradeSummaryWindow();

	final Component content = new StudentGradeSummaryPanel(window.getContentId(), Model.ofMap(model), window);

	if (window.isShown() && window.isVisible()) {
		window.replace(content);
		content.setVisible(true);
		target.add(content);
	} else {
		window.setContent(content);
		window.show(target);
	}

	window.setStudentToReturnFocusTo(studentUuid);
	content.setOutputMarkupId(true);

	final String modalTitle = (new StringResourceModel("heading.studentsummary",
			null, new Object[] { student.getDisplayName(), student.getDisplayId() })).getString();

	window.setTitle(modalTitle);
	window.show(target);

	target.appendJavaScript(String.format(
			"new GradebookGradeSummary($(\"#%s\"), false, \"%s\");",
			content.getMarkupId(), modalTitle));

	return new EmptyOkResponse();
}