Java Code Examples for org.apache.wicket.model.IModel

The following are top voted examples for showing how to use org.apache.wicket.model.IModel. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gitplex-mit   File: QuickSearchPanel.java   View source code 6 votes vote down vote up
public QuickSearchPanel(String id, IModel<Project> projectModel, IModel<String> revisionModel) {
	super(id);
	
	this.projectModel = projectModel;
	this.revisionModel = revisionModel;
	
	Project project = projectModel.getObject();
	for (String blobPath: getRecentOpened()) {
		try {
			RevTree revTree = project.getRevCommit(revisionModel.getObject()).getTree();
			TreeWalk treeWalk = TreeWalk.forPath(project.getRepository(), blobPath, revTree);
			if (treeWalk != null && treeWalk.getRawMode(0) != FileMode.TREE.getBits()) {
				symbolHits.add(new FileHit(blobPath, null));
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
 
Example 2
Project: gitplex-mit   File: ProjectListPage.java   View source code 6 votes vote down vote up
@Override
protected List<ComponentRenderer> getBreadcrumbs() {
	List<ComponentRenderer> breadcrumbs = super.getBreadcrumbs();
	
	breadcrumbs.add(new ComponentRenderer() {

		@Override
		public Component render(String componentId) {
			return new ViewStateAwarePageLink<Void>(componentId, ProjectListPage.class) {

				@Override
				public IModel<?> getBody() {
					return Model.of("Projects");
				}
				
			};
		}
		
	});

	return breadcrumbs;
}
 
Example 3
Project: gitplex-mit   File: AdvancedSearchPanel.java   View source code 6 votes vote down vote up
public AdvancedSearchPanel(String id, IModel<Project> projectModel, IModel<String> revisionModel) {
	super(id);
	
	this.projectModel = projectModel;
	this.revisionModel = revisionModel;
	
	WebRequest request = (WebRequest) RequestCycle.get().getRequest();
	Cookie cookie = request.getCookie(COOKIE_SEARCH_TYPE);
	if (cookie != null) {
		try {
			option = (SearchOption) Class.forName(cookie.getValue()).newInstance();
		} catch (Exception e) {
			logger.debug("Error restoring search option from cookie", e);
		}
	}
}
 
Example 4
Project: gitplex-mit   File: SelectToAddChoice.java   View source code 6 votes vote down vote up
public SelectToAddChoice(String id, ChoiceProvider<T> choiceProvider) {
	super(id);
	
	setModel(new IModel<T>() {

		@Override
		public void detach() {
		}

		@Override
		public T getObject() {
			return selection;
		}

		@Override
		public void setObject(T object) {
			selection = object;
		}
		
	});

	setProvider(choiceProvider);
}
 
Example 5
Project: gitplex-mit   File: CommitMessageLabel.java   View source code 6 votes vote down vote up
public CommitMessageLabel(String id, IModel<Project> projectModel, IModel<String> messageModel) {
	super(id, new LoadableDetachableModel<String>() {

		@Override
		protected String load() {
			String message = HtmlEscape.escapeHtml5(messageModel.getObject());
			for (CommitMessageTransformer transformer: GitPlex.getExtensions(CommitMessageTransformer.class)) {
				message = transformer.transform(projectModel.getObject(), message);
			}
			return message;
		}

		@Override
		protected void onDetach() {
			projectModel.detach();
			messageModel.detach();
			super.onDetach();
		}
		
	});
}
 
Example 6
Project: gitplex-mit   File: GroupListPage.java   View source code 6 votes vote down vote up
@Override
protected List<ComponentRenderer> getBreadcrumbs() {
	List<ComponentRenderer> breadcrumbs = super.getBreadcrumbs();
	
	breadcrumbs.add(new ComponentRenderer() {

		@Override
		public Component render(String componentId) {
			return new ViewStateAwarePageLink<Void>(componentId, GroupListPage.class) {

				@Override
				public IModel<?> getBody() {
					return Model.of("Groups");
				}
				
			};
		}
		
	});

	return breadcrumbs;
}
 
Example 7
Project: gitplex-mit   File: LayoutPage.java   View source code 6 votes vote down vote up
protected List<ComponentRenderer> getBreadcrumbs() {
	List<ComponentRenderer> breadcrumbs = new ArrayList<>();
	
	breadcrumbs.add(new ComponentRenderer() {
		
		@Override
		public Component render(String componentId) {
			return new ViewStateAwarePageLink<Void>(componentId, DashboardPage.class) {

				@Override
				public IModel<?> getBody() {
					return Model.of("Home");
				}
				
			};
		}
	});
	
	return breadcrumbs;
}
 
Example 8
Project: gitplex-mit   File: BeanContext.java   View source code 6 votes vote down vote up
public IModel<T> wrapAsSelfUpdating(final IModel<T> model) {
	return new IModel<T>() {

		@Override
		public void detach() {
			model.detach();
		}

		@Override
		public T getObject() {
			return model.getObject();
		}

		@Override
		public void setObject(T object) {
			copyProperties(object, getObject());
		}
		
	};
}
 
Example 9
Project: gitplex-mit   File: BeanContext.java   View source code 6 votes vote down vote up
public static BeanEditor<Serializable> editBean(String componentId, final Serializable bean, 
		Set<String> excludeProperties) {
	IModel<Serializable> beanModel = new IModel<Serializable>() {

		@Override
		public void detach() {
		}

		@Override
		public Serializable getObject() {
			return bean;
		}

		@Override
		public void setObject(Serializable object) {
			throw new IllegalStateException();
		}
		
	};
	EditSupportRegistry registry = AppLoader.getInstance(EditSupportRegistry.class);
	Class<?> beanClass = ClassUtils.unproxy(beanModel.getObject().getClass());
	BeanContext<Serializable> editContext = registry.getBeanEditContext(beanClass, excludeProperties);
	beanModel = editContext.wrapAsSelfUpdating(beanModel);
	return editContext.renderForEdit(componentId, beanModel);
}
 
Example 10
Project: gitplex-mit   File: AdministrationPage.java   View source code 6 votes vote down vote up
@Override
protected List<ComponentRenderer> getBreadcrumbs() {
	List<ComponentRenderer> breadcrumbs = super.getBreadcrumbs();
	
	breadcrumbs.add(new ComponentRenderer() {

		@Override
		public Component render(String componentId) {
			return new ViewStateAwarePageLink<Void>(componentId, SystemSettingPage.class) {

				@Override
				public IModel<?> getBody() {
					return Model.of("Administration");
				}
				
			};
		}
		
	});
	
	return breadcrumbs;
}
 
Example 11
Project: gitplex-mit   File: PolymorphicListPropertyEditor.java   View source code 6 votes vote down vote up
public PolymorphicListPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<Serializable>> model) {
	super(id, propertyDescriptor, model);
	
	implementations = new ArrayList<>();
	Class<?> baseClass = EditableUtils.getElementClass(propertyDescriptor.getPropertyGetter().getGenericReturnType());
	Preconditions.checkNotNull(baseClass);
	
	ImplementationRegistry registry = AppLoader.getInstance(ImplementationRegistry.class);
	implementations.addAll(registry.getImplementations(baseClass));

	Preconditions.checkArgument(
			!implementations.isEmpty(), 
			"Can not find implementations for '" + baseClass + "'.");
	
	EditableUtils.sortAnnotatedElements(implementations);

	Method propertyGetter = propertyDescriptor.getPropertyGetter();
	if (propertyGetter.getAnnotation(Horizontal.class) != null)
		horizontal = true;
	else if (propertyGetter.getAnnotation(Vertical.class) != null)
		horizontal = false;
	else 
		horizontal = true;
}
 
Example 12
Project: gitplex-mit   File: RevisionDiffPanel.java   View source code 6 votes vote down vote up
private @Nullable IModel<Boolean> getBlobBlameModel(BlobChange change) {
	if (blameModel != null) {
		return new IModel<Boolean>() {

			@Override
			public void detach() {
			}

			@Override
			public Boolean getObject() {
				return change.getPath().equals(blameModel.getObject());
			}

			@Override
			public void setObject(Boolean object) {
				if (object)
					blameModel.setObject(change.getPath());
				else
					blameModel.setObject(null);
			}
			
		};
	} else {
		return null;
	}
}
 
Example 13
Project: gitplex-mit   File: PolymorphicPropertyEditor.java   View source code 6 votes vote down vote up
public PolymorphicPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<Serializable> propertyModel) {
	super(id, propertyDescriptor, propertyModel);
	
	Class<?> baseClass = propertyDescriptor.getPropertyClass();
	ImplementationRegistry registry = AppLoader.getInstance(ImplementationRegistry.class);
	implementations.addAll(registry.getImplementations(baseClass));
	
	Preconditions.checkArgument(
			!implementations.isEmpty(), 
			"Can not find implementations for '" + baseClass + "'.");
	
	EditableUtils.sortAnnotatedElements(implementations);
	
	Method propertyGetter = propertyDescriptor.getPropertyGetter();
	if (propertyGetter.getAnnotation(Vertical.class) != null)
		vertical = true;
	else if (propertyGetter.getAnnotation(Horizontal.class) != null)
		vertical = false;
	else 
		vertical = true;
}
 
Example 14
Project: gitplex-mit   File: MarkdownEditor.java   View source code 6 votes vote down vote up
/**
 * @param id 
 * 			component id of the editor
 * @param model
 * 			markdown model of the editor
 * @param compactMode
 * 			editor in compact mode occupies horizontal space and is suitable 
 * 			to be used in places such as comment aside the code
 */
public MarkdownEditor(String id, IModel<String> model, boolean compactMode) {
	super(id, model);
	this.compactMode = compactMode;
	
	String cookieKey;
	if (compactMode)
		cookieKey = "markdownEditor.compactMode.split";
	else
		cookieKey = "markdownEditor.normalMode.split";
	
	WebRequest request = (WebRequest) RequestCycle.get().getRequest();
	Cookie cookie = request.getCookie(cookieKey);
	if (cookie!=null && "true".equals(cookie.getValue())) {
		initialSplit = true;
	} else {
		initialSplit = !compactMode;
	}
}
 
Example 15
Project: gitplex-mit   File: UserListPage.java   View source code 6 votes vote down vote up
@Override
protected List<ComponentRenderer> getBreadcrumbs() {
	List<ComponentRenderer> breadcrumbs = super.getBreadcrumbs();
	
	breadcrumbs.add(new ComponentRenderer() {

		@Override
		public Component render(String componentId) {
			return new ViewStateAwarePageLink<Void>(componentId, UserListPage.class) {

				@Override
				public IModel<?> getBody() {
					return Model.of("Users");
				}
				
			};
		}
		
	});

	return breadcrumbs;
}
 
Example 16
Project: gitplex-mit   File: RevisionPicker.java   View source code 6 votes vote down vote up
@Override
public IModel<?> getBody() {
	String iconClass;
	ProjectAndRevision repoAndRevision = new ProjectAndRevision(projectModel.getObject(), revision);
	String label = repoAndRevision.getBranch();
	if (label != null) {
		iconClass = "fa fa-code-fork";
	} else {
		label = repoAndRevision.getTag();
		if (label != null) {
			iconClass = "fa fa-tag";
		} else {
			label = revision;
			if (GitUtils.isHash(label))
				label = GitUtils.abbreviateSHA(label);
			iconClass = "fa fa-ext fa-commit";
		}
	} 
	
	return Model.of(String.format("<i class='%s'></i> <span>%s</span> <i class='fa fa-caret-down'></i>", iconClass, label));
}
 
Example 17
Project: gitplex-mit   File: CommitMessageTransformPage.java   View source code 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	Form<?> form = new Form<Void>("commitMessageTransformSetting") {

		@Override
		protected void onSubmit() {
			super.onSubmit();
			GitPlex.getInstance(ProjectManager.class).save(getProject());
			Session.get().success("Commit message transform setting is updated");
		}
		
	};
	form.add(new ReflectionPropertyEditor("editor", new PropertyDescriptor(Project.class, "commitMessageTransformSetting"), new IModel<Serializable>() {

		@Override
		public void detach() {
		}

		@Override
		public Serializable getObject() {
			return getProject().getCommitMessageTransformSetting();
		}

		@Override
		public void setObject(Serializable object) {
			getProject().setCommitMessageTransformSetting((CommitMessageTransformSetting) object);
		}

	}));

	add(form);
}
 
Example 18
Project: hippo   File: CoverageDatesValidator.java   View source code 5 votes vote down vote up
@Override
public Set<Violation> validate(final IFieldValidator fieldValidator,
                               final JcrNodeModel documentModel,
                               final IModel coverageDateFieldModel) throws ValidationException {

    final Set<Violation> violations = new HashSet<>();

    // get dates
    final Calendar start = getDateValue(documentModel, HIPPO_COVERAGE_START_PROPERTY_NAME);
    final Calendar end = getDateValue(documentModel, HIPPO_COVERAGE_END_PROPERTY_NAME);
    final Calendar nominal = getDateValue(documentModel, HIPPO_NOMINAL_DATE_PROPERTY_NAME);

    // coverageEnd but no coverageStart
    if (!isHippoEmptyDate(end) && isHippoEmptyDate(start)) {
        violations.add(fieldValidator.newValueViolation(documentModel, getTranslation("no-start-provided")));
    }

    // coverageStart but no coverageEnd
    if (!isHippoEmptyDate(start) && isHippoEmptyDate(end)) {
        violations.add(fieldValidator.newValueViolation(documentModel, getTranslation("no-end-provided")));
    }

    if (!isHippoEmptyDate(start) && !isHippoEmptyDate(end)) {

        // coverageEnd is before coverageStart
        if (end.before(start)) {
            violations.add(fieldValidator.newValueViolation(documentModel, getTranslation("end-before-start")));
        }

        // coverage dates CANNOT BE AFTER nominal publication date
        if (!isHippoEmptyDate(nominal)
            && (start.after(nominal) || end.after(nominal))) {
            violations.add(fieldValidator.newValueViolation(documentModel, getTranslation("dates-after-nominal")));
        }
    }

    return violations;
}
 
Example 19
Project: hippo   File: BlankStaticDropdownSelectionFieldValidator.java   View source code 5 votes vote down vote up
private String extractSelectedValue(final IModel fieldModel) throws ValidationException {
    try {
        return ((JcrPropertyValueModel) fieldModel).getValue().getString();
    } catch (final RepositoryException repositoryException) {
        throw new ValidationException("Failed to read field's value.", repositoryException);
    }
}
 
Example 20
Project: hippo   File: BlankStaticDropdownSelectionFieldValidator.java   View source code 5 votes vote down vote up
private IModel<String> getViolationMessageTemplate() {
    return new ResourceBundleModel(
        VALIDATORS_TRANSLATION_KEY,
        VIOLATION_MESSAGE_TEMPLATE_KEY,
        Session.get().getLocale()
    );
}
 
Example 21
Project: hippo   File: TextLengthValidator.java   View source code 5 votes vote down vote up
@Override
public Set<Violation> validate(IFieldValidator fieldValidator,
                               JcrNodeModel model, IModel childModel)
    throws ValidationException {
    Set<Violation> violations = new HashSet<>();
    String value = (String) childModel.getObject();
    if (value.length() > maxLength) {
        violations.add(fieldValidator.newValueViolation(childModel, getTranslation()));
    }
    return violations;
}
 
Example 22
Project: gitplex-mit   File: ProjectTab.java   View source code 5 votes vote down vote up
public ProjectTab(IModel<String> titleModel, String iconClass, int count, 
		Class<? extends ProjectPage> mainPageClass, 
		Class<? extends ProjectPage> additionalPageClass1, 
		Class<? extends ProjectPage> additionalPageClass2,
		Class<? extends ProjectPage> additionalPageClass3) {
	super(titleModel, mainPageClass, additionalPageClass1, 
			additionalPageClass2, additionalPageClass3);
	this.iconClass = iconClass;
	this.count = count;
}
 
Example 23
Project: hippo   File: BlankAttachmentFieldValidator.java   View source code 5 votes vote down vote up
private String extractFileName(final IModel fileUploadField) throws ValidationException {
    try {
        return ((JcrNodeModel)fileUploadField).getNode().getProperty(HIPPO_FILENAME_PROPERTY_NAME).getString();
    } catch (final RepositoryException repositoryException) {
        throw new ValidationException("Failed to read attachement's name.", repositoryException);
    }
}
 
Example 24
Project: hippo   File: BlankStaticDropdownSelectionFieldValidatorTest.java   View source code 5 votes vote down vote up
@Test
public void reportsValidationViolation_forBlankFieldValue() throws Exception {

    // given
    final Violation expectedViolation = new Violation(Collections.emptySet(), violationMessageTranslationModel);

    final String blankFieldValue = "";
    final Value valueObject = mock(Value.class);
    given(valueObject.getString()).willReturn(blankFieldValue);
    given(fieldModel.getValue()).willReturn(valueObject);

    given(fieldValidator.newValueViolation(eq(fieldModel), isA(IModel.class)))
        .willReturn(expectedViolation);

    // when
    final Set<Violation> actualViolations =
        blankStaticDropdownSelectionFieldValidator.validate(fieldValidator, documentNodeModel, fieldModel);

    // then
    then(valueObject).should().getString();

    assertThat("Exactly one violation has been reported.", actualViolations, hasSize(1));

    final Violation actualViolation = actualViolations.iterator().next();
    assertThat("Violation is not null", actualViolation, notNullValue());
    assertThat("Correct violation has been reported.", actualViolation.getMessage(),
        is(violationMessageTranslationModel));
}
 
Example 25
Project: hippo   File: CoverageDatesValidatorTest.java   View source code 5 votes vote down vote up
@Test
public void reportsError_whenEndDateButNoStartDate() throws Exception {

    final Violation expectedViolation = new Violation(Collections.emptySet(), violationMessageTranslationModel);

    // Given
    final Property coverageStartProperty = mock(Property.class);
    given(coverageStartProperty.getDate()).willReturn(generateHippoDateEmpty());
    given(documentNode.getProperty(HIPPO_COVERAGE_START_PROPERTY_NAME)).willReturn(coverageStartProperty);

    final Property coverageEndProperty = mock(Property.class);
    given(coverageEndProperty.getDate()).willReturn(generateHippoDateTodayAddDays(-7));
    given(documentNode.getProperty(HIPPO_COVERAGE_END_PROPERTY_NAME)).willReturn(coverageEndProperty);

    final Property nominalDateProperty = mock(Property.class);
    given(nominalDateProperty.getDate()).willReturn(generateHippoDateEmpty());
    given(documentNode.getProperty(HIPPO_NOMINAL_DATE_PROPERTY_NAME)).willReturn(nominalDateProperty);

    given(documentNodeModel.getNode()).willReturn(documentNode);


    given(fieldValidator.newValueViolation(eq(documentNodeModel), isA(IModel.class)))
        .willReturn(expectedViolation);

    // when
    final Set<Violation> actualValidationViolations =
        coverageDatesValidator.validate(fieldValidator, documentNodeModel, fieldModel);

    // then
    then(documentNode).should().getProperty(HIPPO_COVERAGE_START_PROPERTY_NAME);
    then(documentNode).should().getProperty(HIPPO_COVERAGE_END_PROPERTY_NAME);
    then(documentNode).should().getProperty(HIPPO_NOMINAL_DATE_PROPERTY_NAME);

    assertThat("Exactly one violation has been reported", actualValidationViolations, hasSize(1));

    final Violation actualViolation = actualValidationViolations.iterator().next();
    assertThat("Violation is not null", actualViolation, notNullValue());
    assertThat("Correct violation has been reported.",actualViolation.getMessage(),
        is(violationMessageTranslationModel));
}
 
Example 26
Project: hippo   File: CoverageDatesValidatorTest.java   View source code 5 votes vote down vote up
@Test
public void reportsError_whenStartDateButNoEndDate() throws Exception {

    final Violation expectedViolation = new Violation(Collections.emptySet(), violationMessageTranslationModel);

    // Given
    final Property coverageStartProperty = mock(Property.class);
    given(coverageStartProperty.getDate()).willReturn(generateHippoDateTodayAddDays(-7));
    given(documentNode.getProperty(HIPPO_COVERAGE_START_PROPERTY_NAME)).willReturn(coverageStartProperty);

    final Property coverageEndProperty = mock(Property.class);
    given(coverageEndProperty.getDate()).willReturn(generateHippoDateEmpty());
    given(documentNode.getProperty(HIPPO_COVERAGE_END_PROPERTY_NAME)).willReturn(coverageEndProperty);

    final Property nominalDateProperty = mock(Property.class);
    given(nominalDateProperty.getDate()).willReturn(generateHippoDateEmpty());
    given(documentNode.getProperty(HIPPO_NOMINAL_DATE_PROPERTY_NAME)).willReturn(nominalDateProperty);


    given(documentNodeModel.getNode()).willReturn(documentNode);

    given(fieldValidator.newValueViolation(eq(documentNodeModel), isA(IModel.class)))
        .willReturn(expectedViolation);

    // when
    final Set<Violation> actualValidationViolations =
        coverageDatesValidator.validate(fieldValidator, documentNodeModel, fieldModel);

    // then
    then(documentNode).should().getProperty(HIPPO_COVERAGE_START_PROPERTY_NAME);
    then(documentNode).should().getProperty(HIPPO_COVERAGE_END_PROPERTY_NAME);
    then(documentNode).should().getProperty(HIPPO_NOMINAL_DATE_PROPERTY_NAME);

    assertThat("Exactly one violation has been reported", actualValidationViolations, hasSize(1));

    final Violation actualViolation = actualValidationViolations.iterator().next();
    assertThat("Violation is not null", actualViolation, notNullValue());
    assertThat("Correct violation has been reported.",actualViolation.getMessage(),
        is(violationMessageTranslationModel));
}
 
Example 27
Project: hippo   File: CoverageDatesValidatorTest.java   View source code 5 votes vote down vote up
@Test
public void reportsError_whenCoverageDatesGreaterThanNominalDate() throws Exception {

    final Violation expectedViolation = new Violation(Collections.emptySet(), violationMessageTranslationModel);

    // Given
    final Property coverageStartProperty = mock(Property.class);
    given(coverageStartProperty.getDate()).willReturn(generateHippoDateTodayAddDays(7));
    given(documentNode.getProperty(HIPPO_COVERAGE_START_PROPERTY_NAME)).willReturn(coverageStartProperty);

    final Property coverageEndProperty = mock(Property.class);
    given(coverageEndProperty.getDate()).willReturn(generateHippoDateTodayAddDays(7));
    given(documentNode.getProperty(HIPPO_COVERAGE_END_PROPERTY_NAME)).willReturn(coverageEndProperty);

    final Property nominalDateProperty = mock(Property.class);
    given(nominalDateProperty.getDate()).willReturn(generateHippoDateTodayAddDays(2));
    given(documentNode.getProperty(HIPPO_NOMINAL_DATE_PROPERTY_NAME)).willReturn(nominalDateProperty);


    given(documentNodeModel.getNode()).willReturn(documentNode);

    given(fieldValidator.newValueViolation(eq(documentNodeModel), isA(IModel.class)))
        .willReturn(expectedViolation);

    // when
    final Set<Violation> actualValidationViolations =
        coverageDatesValidator.validate(fieldValidator, documentNodeModel, fieldModel);

    // then
    then(documentNode).should().getProperty(HIPPO_COVERAGE_START_PROPERTY_NAME);
    then(documentNode).should().getProperty(HIPPO_COVERAGE_END_PROPERTY_NAME);
    then(documentNode).should().getProperty(HIPPO_NOMINAL_DATE_PROPERTY_NAME);

    assertThat("Exactly one violation has been reported", actualValidationViolations, hasSize(1));

    final Violation actualViolation = actualValidationViolations.iterator().next();
    assertThat("Violation is not null", actualViolation, notNullValue());
    assertThat("Correct violation has been reported.",actualViolation.getMessage(),
        is(violationMessageTranslationModel));
}
 
Example 28
Project: hippo   File: BlankRelatedLinkFieldValidatorTest.java   View source code 5 votes vote down vote up
@Test
public void reportsValidationViolation_forBlankRelatedLinkUrlFieldValue() throws Exception {

    // given
    final Violation expectedViolation = new Violation(Collections.emptySet(), violationMessageTranslationModel);

    final Node relatedLinkNode = mock(Node.class);
    given(relatedLinkNodeModel.getNode()).willReturn(relatedLinkNode);

    final Property relatedLinkUrlProperty = mock(Property.class);
    given(relatedLinkUrlProperty.getString()).willReturn("");

    given(relatedLinkNode.getProperty(HIPPO_RELATED_LINK_URL_PROPERTY_NAME)).willReturn(relatedLinkUrlProperty);

    given(fieldValidator.newValueViolation(eq(relatedLinkNodeModel), isA(IModel.class)))
        .willReturn(expectedViolation);

    // when
    final Set<Violation> actualValidationViolations =
        blankRelatedLinkFieldValidator.validate(fieldValidator, documentNodeModel,relatedLinkNodeModel);

    // then
    then(relatedLinkNode).should().getProperty(HIPPO_RELATED_LINK_URL_PROPERTY_NAME);

    assertThat("Exactly one violation has been reported", actualValidationViolations, hasSize(1));

    final Violation actualViolation = actualValidationViolations.iterator().next();
    assertThat("Violation is not null", actualViolation, notNullValue());
    assertThat("Correct violation has been reported.",actualViolation.getMessage(),
        is(violationMessageTranslationModel));
}
 
Example 29
Project: ansible-docker-talk   File: NewPersonForm.java   View source code 5 votes vote down vote up
public NewPersonForm(String id, IModel<Person> model) {
    super(id, model);
    add(new TextField<String>("firstName"));
    add(new TextField<String>("lastName"));
     add(new TextField<String>("jobTitle"));
    add(new Button("submitButton"));

}
 
Example 30
Project: gitplex-mit   File: ExpandableCommitMessagePanel.java   View source code 5 votes vote down vote up
public ExpandableCommitMessagePanel(String id, IModel<Project> projectModel, 
		IModel<RevCommit> commitModel, IModel<List<Pattern>> patternsModel) {
	super(id);
	
	this.projectModel = projectModel;
	this.commitModel = commitModel;
	this.patternsModel = patternsModel;
}
 
Example 31
Project: gitplex-mit   File: ReflectionBeanEditor.java   View source code 5 votes vote down vote up
public ReflectionBeanEditor(String id, BeanDescriptor beanDescriptor, IModel<Serializable> model) {
	super(id, beanDescriptor, model);

	for (PropertyDescriptor propertyDescriptor: beanDescriptor.getPropertyDescriptors()) {
		propertyContexts.add(PropertyContext.of(propertyDescriptor));
	}
	
	Class<?> beanClass = beanDescriptor.getBeanClass();
	if (beanClass.getAnnotation(Vertical.class) != null)
		vertical = true;
	else if (beanClass.getAnnotation(Horizontal.class) != null)
		vertical = false;
	else 
		vertical = true;
}
 
Example 32
Project: gitplex-mit   File: BlobDiffPanel.java   View source code 5 votes vote down vote up
public BlobDiffPanel(String id, IModel<Project> projectModel, IModel<PullRequest> requestModel, 
		BlobChange change, DiffViewMode diffMode, @Nullable IModel<Boolean> blameModel, 
		@Nullable BlobCommentSupport markSupport) {
	super(id);
	
	this.projectModel = projectModel;
	this.requestModel = requestModel;
	this.change = change;
	this.blameModel = blameModel;
	this.diffMode = diffMode;
	this.markSupport = markSupport;
}
 
Example 33
Project: gitplex-mit   File: PropertyContext.java   View source code 5 votes vote down vote up
public static Component viewModel(String componentId, final IModel<Serializable> beanModel, String propertyName) {
	final PropertyContext<Serializable> editContext = of(beanModel.getObject().getClass(), propertyName);
	return editContext.renderForView(componentId, new LoadableDetachableModel<Serializable>() {

		@Override
		protected Serializable load() {
			return (Serializable) editContext.getPropertyValue(beanModel.getObject());
		}
		
	});
}
 
Example 34
Project: gitplex-mit   File: BeanEditor.java   View source code 5 votes vote down vote up
public BeanEditor(String id, BeanDescriptor beanDescriptor, IModel<T> model) {
	super(id, model);
	
	this.beanDescriptor = beanDescriptor;
	
	for (PropertyDescriptor propertyDescriptor: beanDescriptor.getPropertyDescriptors())
		propertyNames.add(propertyDescriptor.getPropertyName());
}
 
Example 35
Project: gitplex-mit   File: FileChoiceEditor.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public FileChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
	super(id, propertyDescriptor, propertyModel);
	
	FileChoice fileChoice = propertyDescriptor.getPropertyGetter().getAnnotation(FileChoice.class);
	Preconditions.checkNotNull(fileChoice);
	for (String each: (List<String>)ReflectionUtils
			.invokeStaticMethod(propertyDescriptor.getBeanClass(), fileChoice.value())) {
		choices.add(each);
	}
}
 
Example 36
Project: gitplex-mit   File: ExpandableCommitMessagePanel.java   View source code 5 votes vote down vote up
public ExpandableCommitMessagePanel(String id, IModel<Project> projectModel, IModel<RevCommit> commitModel) {
	this(id, projectModel, commitModel, new LoadableDetachableModel<List<Pattern>>() {

		@Override
		protected List<Pattern> load() {
			return new ArrayList<>();
		}
		
	});
}
 
Example 37
Project: gitplex-mit   File: RevisionPicker.java   View source code 5 votes vote down vote up
public RevisionPicker(String id, IModel<Project> projectModel, String revision, boolean canCreateRef) {
	super(id);
	
	this.projectModel = projectModel;
	this.revision = revision;
	this.canCreateRef = canCreateRef;
}
 
Example 38
Project: gitplex-mit   File: EntityDataProvider.java   View source code 5 votes vote down vote up
@Override
public IModel<T> model(AbstractEntity entity) {
	Long entityId = entity.getId();
	return new LoadableDetachableModel<T>() {

		@Override
		protected T load() {
			return AppLoader.getInstance(Dao.class).load(entityType, entityId);
		}
		
	};
}
 
Example 39
Project: gitplex-mit   File: PageTab.java   View source code 5 votes vote down vote up
public PageTab(IModel<String> titleModel, Class<? extends Page> mainPageClass, 
		Class<? extends Page> additionalPageClass1, 
		Class<? extends Page> additionalPageClass2,
		Class<? extends Page> additionalPageClass3, 
		Class<? extends Page> additionalPageClass4, 
		Class<? extends Page> additionalPageClass5) {
	this(titleModel, mainPageClass, asList(additionalPageClass1, 
			additionalPageClass2, additionalPageClass3, additionalPageClass4, additionalPageClass5));
}
 
Example 40
Project: gitplex-mit   File: ReviewerProvider.java   View source code 4 votes vote down vote up
public ReviewerProvider(IModel<PullRequest> requestModel) {
	this.requestModel = requestModel;
}