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

The following examples show how to use org.apache.wicket.model.Model. These examples are extracted from open source projects. 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
public ConfirmEmailHtmlNotificationDemoPage(PageParameters parameters) {
	super(parameters);
	
	User user = userService.getByUserName(ConsoleNotificationIndexPage.DEFAULT_USERNAME);
	EmailAddress emailAddress = null;
	if (user != null) {
		emailAddress = Iterables.getFirst(user.getAdditionalEmails(), null);
	}
	if (user == null || emailAddress == null) {
		LOGGER.error("There is no user or email address available");
		Session.get().error(getString("console.notifications.noDataAvailable"));
		
		throw new RestartResponseException(ConsoleNotificationIndexPage.class);
	}

	if (emailAddress.getEmailHash() == null) {
		emailAddress.setEmailHash(userService.getHash(user, emailAddress.getEmail()));
	}
	
	add(new ConfirmEmailHtmlNotificationPanel("htmlPanel", Model.of(emailAddress)));
}
 
Example 2
Source Project: onedev   Source File: ProjectQueryEditor.java    License: MIT License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
   	
   	input = new TextField<String>("input", getModel());
       input.add(new ProjectQueryBehavior());
       
	input.setLabel(Model.of(getDescriptor().getDisplayName()));
       
       add(input);
	input.add(new OnTypingDoneBehavior() {

		@Override
		protected void onTypingDone(AjaxRequestTarget target) {
			onPropertyUpdating(target);
		}
		
	});
}
 
Example 3
@Test
public void testNullNotAvailable() {
	inputBoolean = true;
	BooleanDropDown dropDown = new BooleanDropDown("id", Model.of(inputBoolean));
	dropDown.setOutputMarkupId(true);
	getTester().getSession().setLocale(Locale.ENGLISH);
	startFormComponentTestWithMarkup(dropDown, "select", createFormPageMarkup("id"));

	TagTester selectTag = getTester().getTagById(dropDown.getMarkupId());
	TagTester firstOption = selectTag.getChild("option");
	TagTester trueOption = selectTag.getChild("value", "true");
	TagTester falseOption = selectTag.getChild("value", "false");
	
	assertNotEquals(firstOption.getValue(), "Choose");
	assertEquals(trueOption.getAttribute("selected"), "selected");
	assertNull(falseOption.getAttribute("selected"));
}
 
Example 4
@Test
public void testRenderComponent(){
	WicketTester tester = createTester();
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
		}
	};
	paginator.setTotalResults(Model.of(100));
	tester.startComponentInPage(paginator);
	tester.assertDisabled("paginator:first:link");
	tester.assertDisabled("paginator:previous:link");
	tester.assertEnabled("paginator:next:link");
	tester.assertEnabled("paginator:last:link");
}
 
Example 5
Source Project: sakai   Source File: SakaiNavigatorLabel.java    License: Educational Community License v2.0 6 votes vote down vote up
private SakaiNavigatorLabel(final String id, final PageableComponent table) {
	super(id);
	Model model = new Model(new LabelModelObject(table)); 
	setDefaultModel(
			new StringResourceModel(
					"pager_textStatus", 
					this, 
					model,
					"Viewing {0} - {1} of {2} {3}",
					new Object[] {
						new PropertyModel(model, "from"),
						new PropertyModel(model, "to"),
						new PropertyModel(model, "of"),
						new ResourceModel("pager_textItem"),
					})
	);
}
 
Example 6
Source Project: nextreports-server   Source File: AnalysisTablePanel.java    License: Apache License 2.0 6 votes vote down vote up
private List<IColumn<AnalysisRow, String>> getPropertyColumns(List<String> header) {
List<IColumn<AnalysisRow, String>> columns = new ArrayList<IColumn<AnalysisRow, String>>();
int columnCount = header.size();		

for (int i = 0; i < columnCount; i++) {
	final int j = i;
	columns.add(new PropertyColumn<AnalysisRow, String>(new Model<String>(header.get(i)), header.get(i), "cellValues." + i) {
		public void populateItem(Item cellItem, String componentId, IModel rowModel) {
			setCellStyle(cellItem, rowModel, j);
			super.populateItem(cellItem, componentId, rowModel);
		}
	});
}		
// critical case when someone deleted the database folder
if (columns.size() == 0) {
	columns.add(new PropertyColumn<AnalysisRow, String>(new Model<String>(""), ""));
}
return columns;
  }
 
Example 7
Source Project: syncope   Source File: SchemasPanel.java    License: Apache License 2.0 6 votes vote down vote up
private List<ITab> buildTabList() {
    List<ITab> tabs = new ArrayList<>();

    for (final SchemaType schemaType : SchemaType.values()) {
        tabs.add(new AbstractTab(new Model<>(schemaType.name())) {

            private static final long serialVersionUID = 1037272333056449378L;

            @Override
            public Panel getPanel(final String panelId) {
                return new SchemaTypePanel(panelId, schemaType, pageRef);
            }
        });
    }

    return tabs;
}
 
Example 8
Source Project: wicket-orientdb   Source File: TestModels.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOQueryModelContextVariables()
{
	IModel<String> nameModel = Model.of();
	OQueryModel<ODocument> queryModel = new OQueryModel<ODocument>("select from ClassA where name = $name");
	queryModel.setContextVariable("name", nameModel);
	nameModel.setObject("doc1");
	assertEquals(1, queryModel.size());
	assertEquals("doc1", queryModel.getObject().get(0).field("name"));
	queryModel.detach();
	
	nameModel.setObject("doc2");
	assertEquals(1, queryModel.size());
	assertEquals("doc2", queryModel.getObject().get(0).field("name"));
	queryModel.detach();
	
	nameModel.setObject("doc3");
	assertEquals(1, queryModel.size());
	assertEquals("doc3", queryModel.getObject().get(0).field("name"));
	queryModel.detach();
}
 
Example 9
Source Project: syncope   Source File: FieldPanel.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public FieldPanel<T> setNewModel(final Attributable attributableTO, final String schema) {
    field.setModel(new Model() {

        private static final long serialVersionUID = -4214654722524358000L;

        @Override
        public Serializable getObject() {
            return (!attributableTO.getPlainAttr(schema).get().getValues().isEmpty())
                    ? attributableTO.getPlainAttr(schema).get().getValues().get(0)
                    : null;
        }

        @Override
        public void setObject(final Serializable object) {
            attributableTO.getPlainAttr(schema).get().getValues().clear();
            if (object != null) {
                attributableTO.getPlainAttr(schema).get().getValues().add(object.toString());
            }
        }
    });
    
    return this;
}
 
Example 10
private WebMarkupContainer createTreeRow(final T node)
{
  final WebMarkupContainer row = new WebMarkupContainer(rowRepeater.newChildId(), new Model<TreeTableNode>(node));
  row.setOutputMarkupId(true);
  row.add(AttributeModifier.replace("class", "even"));
  if (clickRows == true) {
    WicketUtils.addRowClick(row);
  }
  rowRepeater.add(row);
  final RepeatingView colBodyRepeater = new RepeatingView("cols");
  row.add(colBodyRepeater);
  final String cssStyle = getCssStyle(node);

  // Column: browse icons
  final TreeIconsActionPanel< ? extends TreeTableNode> treeIconsActionPanel = createTreeIconsActionPanel(node);
  addColumn(row, treeIconsActionPanel, cssStyle);
  treeIconsActionPanel.init(this, node);
  treeIconsActionPanel.add(AttributeModifier.append("style", new Model<String>("white-space: nowrap;")));

  addColumns(colBodyRepeater, cssStyle, node);
  return row;
}
 
Example 11
Source Project: sakai   Source File: ViewGradeLogAction.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) {
	final String assignmentId = params.get("assignmentId").asText();
	final String studentUuid = params.get("studentId").asText();

	final Map<String, Object> model = new HashMap<>();
	model.put("assignmentId", Long.valueOf(assignmentId));
	model.put("studentUuid", studentUuid);

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

	window.setAssignmentToReturnFocusTo(assignmentId);
	window.setStudentToReturnFocusTo(studentUuid);
	window.setContent(new GradeLogPanel(window.getContentId(), Model.ofMap(model), window));
	window.show(target);

	return new EmptyOkResponse();
}
 
Example 12
@Test
public void testStartingNull() {
	inputBoolean = null;
	BooleanDropDown dropDown = new BooleanDropDown("id", Model.of(inputBoolean));
	dropDown.setOutputMarkupId(true);
	getTester().getSession().setLocale(Locale.ENGLISH);
	startFormComponentTestWithMarkup(dropDown, "select", createFormPageMarkup("id"));

	TagTester selectTag = getTester().getTagById(dropDown.getMarkupId());
	TagTester firstOption = selectTag.getChild("option");
	TagTester trueOption = selectTag.getChild("value", "true");
	TagTester falseOption = selectTag.getChild("value", "false");
	
	assertEquals(firstOption.getValue(), "Choose");
	assertEquals(firstOption.getAttribute("selected"), "selected");
	assertEquals(trueOption.getValue(), "Yes");
	assertEquals(falseOption.getValue(), "No");
}
 
Example 13
Source Project: syncope   Source File: ConnObjectPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get panel for attribute value (not remote status).
 *
 * @param id component id to be replaced with the fragment content.
 * @param attrTO remote attribute.
 * @return fragment.
 */
private static Panel getValuePanel(final String id, final String schemaName, final Attr attrTO) {
    Panel field;
    if (attrTO == null) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<>());
    } else if (CollectionUtils.isEmpty(attrTO.getValues())) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<>());
    } else if (ConnIdSpecialName.PASSWORD.equals(schemaName)) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<>("********"));
    } else if (attrTO.getValues().size() == 1) {
        field = new AjaxTextFieldPanel(id, schemaName, new Model<>(attrTO.getValues().get(0)));
    } else {
        field = new MultiFieldPanel.Builder<>(new ListModel<>(attrTO.getValues())).build(
                id,
                schemaName,
                new AjaxTextFieldPanel("panel", schemaName, new Model<>()));
    }

    field.setEnabled(false);
    return field;
}
 
Example 14
Source Project: artifact-listener   Source File: FooterPanel.java    License: Apache License 2.0 6 votes vote down vote up
public FooterPanel(String id) {
	super(id);
	add(new Label("smile", new StringResourceModel("footer.links.smile", Model.of(ExternalLinks.get(configurer)))).setEscapeModelStrings(false));
	add(new BookmarkablePageLink<Void>("aboutLink", AboutPage.class));
	WebMarkupContainer gitHubProjectContainer = new WebMarkupContainer("gitHubProjectContainer") {
		private static final long serialVersionUID = 1L;
		
		@Override
		protected void onConfigure() {
			super.onConfigure();
			setVisible(StringUtils.hasText(ExternalLinks.get(configurer).getGitHubProject()));
		}
	};
	add(gitHubProjectContainer);
	gitHubProjectContainer.add(new Label("gitHubProject", new StringResourceModel("footer.links.gitHubProject", Model.of(ExternalLinks.get(configurer)))).setEscapeModelStrings(false));
	
	add(new Label("twitter", new StringResourceModel("footer.links.twitter", Model.of(ExternalLinks.get(configurer)))).setEscapeModelStrings(false));
	
	add(new ObfuscatedEmailLink("contactUsLink", Model.of(configurer.getLinkContactUs())));

	add(new ExternalLink("smileLink", configurer.getLinkSmile()));
}
 
Example 15
Source Project: syncope   Source File: AuditHistoryDetails.java    License: Apache License 2.0 6 votes vote down vote up
private Model<String> toJSON(final AuditEntry auditEntry, final Class<T> reference) {
    try {
        String content = auditEntry.getBefore() == null
                ? MAPPER.readTree(auditEntry.getOutput()).get("entity").toPrettyString()
                : auditEntry.getBefore();

        T entity = MAPPER.readValue(content, reference);
        if (entity instanceof UserTO) {
            UserTO userTO = (UserTO) entity;
            userTO.setPassword(null);
            userTO.setSecurityAnswer(null);
        }

        return Model.of(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(entity));
    } catch (Exception e) {
        LOG.error("While (de)serializing entity {}", auditEntry, e);
        throw new WicketRuntimeException(e);
    }
}
 
Example 16
/**
 * @see org.apache.wicket.Component#onInitialize()
 */
@Override
protected void onInitialize()
{
  super.onInitialize();
  statusChoiceRenderer = new LabelValueChoiceRenderer<TeamAttendeeStatus>(this, TeamAttendeeStatus.values());
  mainContainer = new WebMarkupContainer("main");
  add(mainContainer.setOutputMarkupId(true));
  attendeesRepeater = new RepeatingView("liRepeater");
  mainContainer.add(attendeesRepeater);
  rebuildAttendees();
  final WebMarkupContainer item = new WebMarkupContainer("liAddNewAttendee");
  mainContainer.add(item);
  item.add(new AttendeeEditableLabel("editableLabel", Model.of(new TeamEventAttendeeDO()), true));
  item.add(new Label("status", "invisible").setVisible(false));
  attendeesRepeater.setVisible(true);
}
 
Example 17
Source Project: nextreports-server   Source File: SearchEntityPanel.java    License: Apache License 2.0 6 votes vote down vote up
protected List<IColumn<Entity, String>> createTableColumns() {
    List<IColumn<Entity, String>> columns = new ArrayList<IColumn<Entity, String>>();
    columns.add(new EntityNameColumn());
    columns.add(new ActionsColumn());

    if (sectionManager.getSelectedSection() instanceof ReportSection) {
        columns.add(new TypeColumn());
    }

    //columns.add(new EntityPathColumn());

    if (sectionManager.getSelectedSection() instanceof SchedulerSection) {
        columns.add(new ActivePropertyColumn());
        columns.add(new BooleanImagePropertyColumn<Entity>(new Model<String>(getString("ActionContributor.Search.entityRun")), "isRunning", "isRunning"));
        columns.add(new NextRunDateColumn<Entity>());
    }

    columns.add(new CreatedByColumn());
    columns.add(new CreationDateColumn());
    return columns;
}
 
Example 18
Source Project: ontopia   Source File: DateFormatValidator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onValidate(IValidatable<String> validatable) {
  final String value = validatable.getValue();
  if (value == null) return;
  try {
    DateFormat df = createDateFormat();
    df.parse(value);
  } catch (ParseException e) {
    String message = Application.get().getResourceSettings().getLocalizer().getString(resourceKey(), (Component)null, 
          new Model<Serializable>(new Serializable() {
            @SuppressWarnings("unused")
            public String getValue() {
              return value;
            }
          }));
    component.error(AbstractFieldInstancePanel.createErrorMessage(fieldInstanceModel, new Model<String>(message)));
  }
}
 
Example 19
Source Project: sakai   Source File: StudentVisitsWidget.java    License: Educational Community License v2.0 6 votes vote down vote up
private Fragment getLazyLoadedMiniStats(String markupId) {
    Fragment ministatFragment = new Fragment(markupId, "ministatFragment", this);
    int miniStatsCount = widgetMiniStats != null ? widgetMiniStats.size() : 0;
    Loop miniStatsLoop = new Loop("widgetRow", miniStatsCount) {
        private static final long serialVersionUID = 1L;
        @Override
        protected void populateItem(LoopItem item) {
            int index = item.getIndex();
            WidgetMiniStat ms = widgetMiniStats.get(index);

            Label widgetValue = new Label("widgetValue", Model.of(ms.getValue()));
            Label widgetLabel = new Label("widgetLabel", Model.of(ms.getLabel()));
            WebMarkupContainer widgetIcon = new WebMarkupContainer("widgetIcon");
            widgetIcon.add(new AttributeAppender("class", " " + ms.getSecondValue()));

            item.add(widgetValue);
            item.add(widgetLabel);
            item.add(widgetIcon);
        }
    };
    ministatFragment.add(miniStatsLoop);
    return ministatFragment;
}
 
Example 20
Source Project: Orienteer   Source File: GraphVerticesWidget.java    License: Apache License 2.0 5 votes vote down vote up
private List<IColumn<ODocument, String>> createColumns(OClass commonParent, IModel<DisplayMode> modeModel) {
	OProperty nameProperty = oClassIntrospector.getNameProperty(commonParent);
    List<IColumn<ODocument, String>> columns = oClassIntrospector.getColumnsFor(commonParent, true, modeModel);
    columns.add(new ODocumentClassColumn(new OClassModel(commonParent)));
    columns.add(new ODocumentDescriptionColumn(
    		new StringResourceModel("property.direction", this, Model.of()),
    		new DirectionLocalizer()));
    return columns;
}
 
Example 21
/**
 * @param displayModelString For creation of new Model<String>.
 * @param sortProperty
 * @param propertyExpression
 * @param cellItemListener
 */
public CellItemListenerPropertyColumn(final String displayModelString, final String sortProperty, final String propertyExpression,
    final CellItemListener<T> cellItemListener)
{
  super(new Model<String>(displayModelString), sortProperty, propertyExpression);
  this.cellItemListener = cellItemListener;
}
 
Example 22
Source Project: nextreports-server   Source File: TypeColumn.java    License: Apache License 2.0 5 votes vote down vote up
public void populateItem(Item<ICellPopulator<Entity>> item, String componentId, IModel<Entity> rowModel) {
    String type = rowModel.getObject().getClass().getSimpleName();
    Entity entity = rowModel.getObject(); 
    if (entity instanceof Report) {
        type = ((Report) entity).getType() + " " + new StringResourceModel(type, null).getString();
    } else if (entity instanceof DataSource) {
    	type = ((DataSource) entity).getVendor();
    } else if ((entity instanceof Folder) || (entity instanceof Chart)) {
    	type = new StringResourceModel(type, null).getString();
    }
    item.add(new Label(componentId, new Model<String>(type)));
}
 
Example 23
Source Project: Orienteer   Source File: AbstractODocumentAliasMapper.java    License: Apache License 2.0 5 votes vote down vote up
protected void applyFilters(PageParameters parameters, OQueryModel<ODocument> queryModel) {
    IModel<Boolean> joining = Model.of(true);
    for (INamedParameters.NamedPair pair : parameters.getAllNamed()) {
        String param = pair.getValue();
        if (!Strings.isNullOrEmpty(param) && !Objects.equals(pair.getKey(), parameter)) {
            IFilterCriteriaManager manager = new FilterCriteriaManager(pair.getKey());
            manager.addFilterCriteria(manager.createEqualsFilterCriteria(Model.of(param), joining));
            queryModel.addFilterCriteriaManager(pair.getKey(), manager);
        }
    }
}
 
Example 24
Source Project: webanno   Source File: KeyBindingsConfigurationPanel.java    License: Apache License 2.0 5 votes vote down vote up
public KeyBindingsConfigurationPanel(String aId, IModel<AnnotationFeature> aModel,
        IModel<List<KeyBinding>> aKeyBindings)
{
    super(aId, aModel);
    
    keyBindings = aKeyBindings;
    
    Form<KeyBinding> keyBindingForm = new Form<>("keyBindingForm",
            CompoundPropertyModel.of(new KeyBinding()));
    add(keyBindingForm);

    keyBindingsContainer = new WebMarkupContainer("keyBindingsContainer");
    keyBindingsContainer.setOutputMarkupPlaceholderTag(true);
    keyBindingForm.add(keyBindingsContainer);

    // We cannot make the key-combo field a required one here because then we'd get a message
    // about keyCombo not being set when saving the entire feature details form!
    keyBindingsContainer.add(new TextField<String>("keyCombo")
            .add(new KeyComboValidator()));
    keyBindingsContainer.add(new LambdaAjaxSubmitLink<>("addKeyBinding", this::addKeyBinding));
    
    AnnotationFeature feature = aModel.getObject();
    FeatureSupport<?> fs = featureSupportRegistry.getFeatureSupport(feature);
    featureState = Model.of(new FeatureState(VID.NONE_ID, feature, null));
    if (feature.getTagset() != null) {
        featureState.getObject().tagset = schemaService.listTags(feature.getTagset());
    }
    // We are adding only the focus component here because we do not want to display the label
    // which usually goes along with the feature editor. This assumes that there is a sensible
    // focus component... might not be the case for some multi-component editors.
    editor = fs.createEditor("value", this, null, null, featureState);
    editor.addFeatureUpdateBehavior();
    editor.getLabelComponent().setVisible(false);
    keyBindingsContainer.add(editor);
    
    keyBindingsContainer.add(createKeyBindingsList("keyBindings", keyBindings));
}
 
Example 25
Source Project: sakai   Source File: ComposeNewMessage.java    License: Educational Community License v2.0 5 votes vote down vote up
@Override
protected void onEvent(AjaxRequestTarget target) {
	if(StringUtils.isBlank(toField.getValue())) {
      		formFeedback.setDefaultModel(new ResourceModel("error.message.required.to"));
      		formFeedback.add(new AttributeModifier("class", true, new Model<String>("alertMessage")));
      	} else {
      		formFeedback.setVisible(false);
      	}
  		target.add(formFeedback);

	
}
 
Example 26
public JFreeChartImage(final String id, final JFreeChart chart, final JFreeChartImageType imageType, final int width, final int height)
{
  super(id, new Model<JFreeChart>(chart));
  this.width = width;
  this.height = height;
  this.imageType = imageType;
}
 
Example 27
@Test
public void testMessageParameters(){
	IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "b");
	
	Validatable<Object> validatable = new Validatable<Object>("a");
	validator.validate(validatable);
	
	assertEquals(1, validatable.getErrors().size());
	assertEquals("Size", getError(validatable).getKeys().get(0));
	
	assertEquals(2, getError(validatable).getVariables().size());
	assertEquals(2, getError(validatable).getVariables().get("min"));
	assertEquals(4, getError(validatable).getVariables().get("max"));
}
 
Example 28
@Test
public void testInitialization() {
	inputBoolean = true;
	BooleanDropDown dropDown = new BooleanDropDown("id", Model.of(inputBoolean));
	dropDown.setOutputMarkupId(true);
	getTester().getSession().setLocale(Locale.ENGLISH);
	startFormComponentTestWithMarkup(dropDown, "select", createFormPageMarkup("id"));

	getTester().assertComponent(dropDown.getPageRelativePath(), BooleanDropDown.class);
	getTester().assertModelValue(dropDown.getPageRelativePath(), true);
}
 
Example 29
Source Project: yes-cart   Source File: WishListView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct wish list to show for given user.
 *
 * @param id component id.
 *
 * @param customerEmail customer email
 * @param wishListType wishlist type
 * @param wishListTag tags
 */
public WishListView(final String id,
                    final Model<String> customerEmail,
                    final Model<String> wishListType,
                    final Model<String> wishListTag) {
    super(id, true);
    this.customerEmail = customerEmail;
    this.wishListType = wishListType;
    this.wishListTag = wishListTag;
}
 
Example 30
Source Project: sakai   Source File: AjaxLazyLoadImage.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
 * @param markupId
 *            The components markupid.
 * @return The component to show while the real component is being created.
 */
public Component getLoadingComponent(String markupId) {
	Label indicator = new Label(markupId, "<img src=\"" + RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null) + "\"/>");
	indicator.setEscapeModelStrings(false);
	indicator.add(new AttributeModifier("title", new Model("...")));
	return indicator;
}