Java Code Examples for org.apache.wicket.Component#replaceWith()

The following examples show how to use org.apache.wicket.Component#replaceWith() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommitListPanel.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private Component replaceItem(AjaxRequestTarget target, int index) {
	Component item = commitsView.get(index);
	Component newItem = newCommitItem(item.getId(), index);
	item.replaceWith(newItem);
	target.add(newItem);
	return newItem;
}
 
Example 2
Source File: MyNamePronunciationDisplay.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public MyNamePronunciationDisplay(final String id, final UserProfile userProfile) {
    super(id);

    log.debug("MyNamePronunciationDisplay()");

    final Component thisPanel = this;
    this.userProfile = userProfile;

    //heading
    add(new Label("heading", new ResourceModel("heading.name.pronunciation")));

    addPhoneticPronunciation();
    addNameRecord();

    AjaxFallbackLink editButton = new AjaxFallbackLink("editButton", new ResourceModel("button.edit")) {
        public void onClick(AjaxRequestTarget target) {
            Component newPanel = new MyNamePronunciationEdit(id, userProfile);
            newPanel.setOutputMarkupId(true);
            thisPanel.replaceWith(newPanel);
            if(target != null) {
                target.add(newPanel);
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }
        }
    };
    editButton.add(new Label("editButtonLabel", new ResourceModel("button.edit")));
    editButton.setOutputMarkupId(true);
    if(userProfile.isLocked() && !sakaiProxy.isSuperUser()) {
        editButton.setVisible(false);
    }
    add(editButton);

    //no fields message
    Label noFieldsMessage = new Label("noFieldsMessage", new ResourceModel("text.no.fields"));
    add(noFieldsMessage);
    if(visibleFieldCount > 0) {
        noFieldsMessage.setVisible(false);
    }
}
 
Example 3
Source File: MyNamePronunciationDisplay.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public MyNamePronunciationDisplay(final String id, final UserProfile userProfile) {
    super(id);

    log.debug("MyNamePronunciationDisplay()");

    final Component thisPanel = this;
    this.userProfile = userProfile;

    //heading
    add(new Label("heading", new ResourceModel("heading.name.pronunciation")));

    addPhoneticPronunciation();
    addNameRecord();

    AjaxFallbackLink editButton = new AjaxFallbackLink("editButton", new ResourceModel("button.edit")) {
        public void onClick(AjaxRequestTarget target) {
            Component newPanel = new MyNamePronunciationEdit(id, userProfile);
            newPanel.setOutputMarkupId(true);
            thisPanel.replaceWith(newPanel);
            if(target != null) {
                target.add(newPanel);
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }
        }
    };
    editButton.add(new Label("editButtonLabel", new ResourceModel("button.edit")));
    editButton.setOutputMarkupId(true);
    if(userProfile.isLocked() && !sakaiProxy.isSuperUser()) {
        editButton.setVisible(false);
    }
    add(editButton);

    //no fields message
    Label noFieldsMessage = new Label("noFieldsMessage", new ResourceModel("text.no.fields"));
    add(noFieldsMessage);
    if(visibleFieldCount > 0) {
        noFieldsMessage.setVisible(false);
    }
}
 
Example 4
Source File: WicketProtector.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
	public void onInitialize(Component component) {
		if(component instanceof AbstractMetaPanel) {
			final AtomicInteger deep = new AtomicInteger(0);
			component.visitParents(AbstractMetaPanel.class, (c, v) -> deep.incrementAndGet());
			if(deep.get()>=MAX_INCLUSION) {
				component.replaceWith(new EmptyPanel(component.getId()));
//				LOG.error("Due to very deep inclusion the following component was replaced by empty panel: "+component);
			}
		}
	}
 
Example 5
Source File: BeanEditor.java    From onedev with MIT License 4 votes vote down vote up
@Override
public void onEvent(IEvent<?> event) {
	super.onEvent(event);
	
	if (event.getPayload() instanceof PropertyUpdating) {
		event.stop();
		PropertyUpdating propertyUpdating = (PropertyUpdating) event.getPayload();
		for (Component groupContainer: groupsView) {
			RepeatingView propertiesView = (RepeatingView) groupContainer.get("content").get("properties");
			for (Component propertyContainer: propertiesView) {
				@SuppressWarnings("unchecked")
				PropertyContext<Serializable> propertyContext = 
						(PropertyContext<Serializable>) propertyContainer.getDefaultModelObject(); 
				Set<String> checkedPropertyNames = new HashSet<>();
				if (hasTransitiveDependency(propertyContext.getPropertyName(), 
						propertyUpdating.getPropertyName(), checkedPropertyNames)) {
					/*
					 * Create new property container instead of simply refreshing it as some dependent 
					 * properties may only take effect when re-create the property container. For instance
					 * If default value of an issue field depends on input value of another issue field  
					 */
					PropertyContainer newPropertyContainer = 
							newPropertyContainer(propertyContainer.getId(), propertyContext);
					propertyContainer.replaceWith(newPropertyContainer);
					componentContexts.put(propertyContext.getPropertyName(), 
							new ComponentContext(newPropertyContainer));
					propertyUpdating.getHandler().add(newPropertyContainer);
					String script = String.format("$('#%s').addClass('no-autofocus');", 
							newPropertyContainer.getMarkupId());
					propertyUpdating.getHandler().appendJavaScript(script);
				}
			}
		}				
		
		convertInput();
		clearErrors();
		/**
		 * Bump up event even if some properties are invalid as we may need to do something with 
		 * partial properties of the bean. For instance to update issue description template
		 */
		send(this, Broadcast.BUBBLE, new BeanUpdating(propertyUpdating.getHandler()));
	}		
}