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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 4 votes vote down vote up
public ReviewerProvider(IModel<PullRequest> requestModel) {
	this.requestModel = requestModel;
}
 
Example 41
Project: gitplex-mit   File: ResolveConflictInstructionPanel.java   Source Code and License 4 votes vote down vote up
public ResolveConflictInstructionPanel(String id, IModel<PullRequest> model) {
	super(id, model);
}
 
Example 42
Project: gitplex-mit   File: PageTab.java   Source Code and License 4 votes vote down vote up
public PageTab(IModel<String> titleModel, Class<? extends Page> mainPageClass, 
		Class<? extends Page> additionalPageClass) {
	this(titleModel, mainPageClass, asList(additionalPageClass));
}
 
Example 43
Project: karate   File: FeaturePanel.java   Source Code and License 4 votes vote down vote up
public FeaturePanel(String id, String sessionId) {
    super(id);
    FeatureModel model = new FeatureModel(sessionId);
    setDefaultModel(new CompoundPropertyModel(model));
    add(new Label("feature", new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return model.getObject().getEnv().featureName;
        }            
    }));
    add(new AjaxEditableLabel("env", new IModel<String>() {
        @Override
        public String getObject() {
            return model.getObject().getEnv().env;
        }

        @Override
        public void setObject(String object) {
            service.updateSessionEnv(sessionId, object);
        }

        @Override
        public void detach() {
        }
    }));
    add(new BookmarkablePageLink("home", HomePage.class));
    add(new IndicatingAjaxLink("export") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            KarateSession session =  service.getSession(sessionId);
            FeatureWrapper featureWrapper = session.getFeature();
            FeaturePanel.this.setResponsePage(new HomePage(featureWrapper.getText()));
        }
    });
    ListView<FeatureSection> listView = new ListView<FeatureSection>("sections") {
        @Override
        protected void populateItem(ListItem<FeatureSection> li) {
            FeatureSection section = li.getModelObject();
            FeatureSectionModel sectionModel = new FeatureSectionModel(sessionId, section);
            li.add(new FeatureSectionPanel("section", sectionModel));
        }
    };
    add(listView);
}
 
Example 44
Project: gitplex-mit   File: ProjectTab.java   Source Code and License 4 votes vote down vote up
public ProjectTab(IModel<String> titleModel, String iconClass, int count, 
		Class<? extends ProjectPage> mainPageClass) {
	super(titleModel, mainPageClass);
	this.iconClass = iconClass;
	this.count = count;
}
 
Example 45
Project: gitplex-mit   File: UpdateChangesLink.java   Source Code and License 4 votes vote down vote up
public IModel<?> getBody() {
	return Model.of("<i class='fa fa-ext fa-file-diff'></i>");
}
 
Example 46
Project: gitplex-mit   File: BranchPicker.java   Source Code and License 4 votes vote down vote up
@Override
public IModel<?> getBody() {
	return Model.of(String.format("<i class='fa fa-code-fork'></i> <span>%s</span> <i class='fa fa-caret-down'></i>", 
			HtmlEscape.escapeHtml5(branch)));
}
 
Example 47
Project: gitplex-mit   File: CommentedPanel.java   Source Code and License 4 votes vote down vote up
public CommentedPanel(String id, IModel<PullRequestComment> model) {
	super(id, model);
}
 
Example 48
Project: gitplex-mit   File: BranchPatternAssistBehavior.java   Source Code and License 4 votes vote down vote up
public BranchPatternAssistBehavior(IModel<Project> projectModel) {
	this.projectModel = projectModel;
}
 
Example 49
Project: gitplex-mit   File: NewUserPage.java   Source Code and License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	BeanEditor<?> editor = BeanContext.editBean("editor", user);
	
	Form<?> form = new Form<Void>("form") {

		@Override
		protected void onSubmit() {
			super.onSubmit();
			
			UserManager userManager = GitPlex.getInstance(UserManager.class);
			User userWithSameName = userManager.findByName(user.getName());
			if (userWithSameName != null) {
				editor.getErrorContext(new PathSegment.Property("name"))
						.addError("This name has already been used by another user.");
			} 
			User userWithSameEmail = userManager.findByEmail(user.getEmail());
			if (userWithSameEmail != null) {
				editor.getErrorContext(new PathSegment.Property("email"))
						.addError("This email has already been used by another user.");
			} 
			if (!editor.hasErrors(true)){
				user.setPassword(AppLoader.getInstance(PasswordService.class).encryptPassword(user.getPassword()));
				userManager.save(user, null);
				Session.get().success("New user created");
				if (continueToAdd) {
					user = new User();
					replace(BeanContext.editBean("editor", user));
				} else {
					setResponsePage(UserMembershipsPage.class, UserMembershipsPage.paramsOf(user));
				}
			}
		}
		
	};
	form.add(editor);
	form.add(new CheckBox("continueToAdd", new IModel<Boolean>() {

		@Override
		public void detach() {
		}

		@Override
		public Boolean getObject() {
			return continueToAdd;
		}

		@Override
		public void setObject(Boolean object) {
			continueToAdd = object;
		}
		
	}));
	add(form);
}
 
Example 50
Project: gitplex-mit   File: TagPatternAssistBehavior.java   Source Code and License 4 votes vote down vote up
public TagPatternAssistBehavior(IModel<Project> projectModel) {
	this.projectModel = projectModel;
}
 
Example 51
Project: gitplex-mit   File: ViewStateAwareAjaxLink.java   Source Code and License 4 votes vote down vote up
public ViewStateAwareAjaxLink(String id, IModel<T> model, boolean carryOver) {
	super(id, model);
	this.carryOver = carryOver;
}
 
Example 52
Project: gitplex-mit   File: DatetimePicker.java   Source Code and License 4 votes vote down vote up
public DatetimePicker(String id, IModel<Date> model, DatetimePickerConfig config) {
	super(id, model, config);
}
 
Example 53
Project: gitplex-mit   File: CommitQueryBehavior.java   Source Code and License 4 votes vote down vote up
public CommitQueryBehavior(IModel<Project> projectModel) {
	super(CommitQueryParser.class, "query");
	this.projectModel = projectModel;
}
 
Example 54
Project: gitplex-mit   File: TagPatternEditor.java   Source Code and License 4 votes vote down vote up
public TagPatternEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
	super(id, propertyDescriptor, propertyModel);
}
 
Example 55
Project: gitplex-mit   File: SinceChangesLink.java   Source Code and License 4 votes vote down vote up
public SinceChangesLink(String id, IModel<PullRequest> requestModel, Date sinceDate) {
	super(id, RequestChangesPage.class);
	this.requestModel = requestModel;
	this.sinceDate = sinceDate;
}
 
Example 56
Project: gitplex-mit   File: NullableBooleanPropertyEditor.java   Source Code and License 4 votes vote down vote up
public NullableBooleanPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<Boolean> propertyModel) {
	super(id, propertyDescriptor, propertyModel);
}
 
Example 57
Project: gitplex-mit   File: StringPropertyEditor.java   Source Code and License 4 votes vote down vote up
public StringPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
	super(id, propertyDescriptor, propertyModel);
}
 
Example 58
Project: gitplex-mit   File: UpdatedPanel.java   Source Code and License 4 votes vote down vote up
public UpdatedPanel(String id, IModel<PullRequestUpdate> model) {
	super(id, model);
}
 
Example 59
Project: gitplex-mit   File: CreateTagLink.java   Source Code and License 4 votes vote down vote up
public CreateTagLink(String id, IModel<Project> projectModel, String revision) {
	super(id);
	
	this.projectModel = projectModel;
	this.revision = revision;
}
 
Example 60
Project: gitplex-mit   File: PrivilegeSourcePanel.java   Source Code and License 4 votes vote down vote up
@Override
public void onInitialize() {
	super.onInitialize();
	
	User user = userModel.getObject();
	Project project = projectModel.getObject();
	add(new Label("user", user.getDisplayName()));
	add(new Label("project", project.getName()));
	add(new Label("privilege", privilege.name()));
	
	add(new WebMarkupContainer("userIsRoot").setVisible(user.isRoot()));
	add(new WebMarkupContainer("projectIsPublic")
			.setVisible(privilege == ProjectPrivilege.READ && project.isPublicRead()));
	add(new ListView<Group>("groups", new LoadableDetachableModel<List<Group>>() {

		@Override
		protected List<Group> load() {
			List<Group> groups = new ArrayList<>();
			for (Membership membership: user.getMemberships()) {
				if (membership.getGroup().isAdministrator()) {
					groups.add(membership.getGroup());
				} else {
					for (GroupAuthorization authorization: membership.getGroup().getAuthorizations()) {
						if (authorization.getProject().equals(project) 
								&& authorization.getPrivilege() == privilege) {
							groups.add(membership.getGroup());
							break;
						}
					}
				}
			}
			return groups;
		}
		
	}) {

		@Override
		protected void populateItem(ListItem<Group> item) {
			Group group = item.getModelObject();
			if (group.isAdministrator()) {
				item.add(new BookmarkablePageLink<Void>("group", GroupProfilePage.class, 
						GroupAuthorizationsPage.paramsOf(group)) {

					@Override
					public IModel<?> getBody() {
						return Model.of(item.getModelObject().getName());
					}
					
				});
			} else {
				item.add(new BookmarkablePageLink<Void>("group", GroupAuthorizationsPage.class, 
						GroupAuthorizationsPage.paramsOf(group)) {

					@Override
					public IModel<?> getBody() {
						return Model.of(item.getModelObject().getName());
					}
					
				});
			}
		}

	});
}