Java Code Examples for org.apache.wicket.ajax.AjaxRequestTarget

The following are top voted examples for showing how to use org.apache.wicket.ajax.AjaxRequestTarget. 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: TestFormBehavior.java   Source Code and License 7 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
	String feedbackHtml;
	TestResult result = test();
	if (result.isSuccessful()) {
		feedbackHtml = String.format(
				"<div class='test-feedback alert alert-success'>%s</div>", 
				HtmlEscape.escapeHtml5(result.getMessage()));					
	} else {
		feedbackHtml = String.format(
				"<div class='test-feedback alert alert-danger'>%s</div>", 
				HtmlEscape.escapeHtml5(result.getMessage()));					
	} 
	feedbackHtml = StringUtils.replace(feedbackHtml, "\n", "<br>");
	target.appendJavaScript(String.format("var $button = $('#%s');"
			+ "$button.removeAttr('disabled');"
			+ "$button.val($button[0].prevValue);"
			+ "$button.html($button[0].prevHtml);"
			+ "$button.closest('form').append('%s');"
			+ "$button.removeClass('ajax-indicator');", 
			getComponent().getMarkupId(), JavaScriptEscape.escapeJavaScript(feedbackHtml)));
}
 
Example 2
Project: gitplex-mit   File: ProjectBlobPage.java   Source Code and License 6 votes vote down vote up
@Override
public void onModeChange(AjaxRequestTarget target, Mode mode) {
	/*
	 * User might be changing blob name when adding a file, and onModeChange will be called. 
	 * In this case, we only need to re-create blob content
	 */
	if (mode != Mode.ADD || state.mode != Mode.ADD) {
		state.mode = mode;
		pushState(target);
		if (state.mode == Mode.VIEW || state.mode == Mode.EDIT || state.mode == Mode.ADD) {
			newBlobNavigator(target);
			newBlobOperations(target);
		}
	}			
	newBlobContent(target);
	resizeWindow(target);
}
 
Example 3
Project: gitplex-mit   File: RevisionSelector.java   Source Code and License 6 votes vote down vote up
private void selectRevision(AjaxRequestTarget target, String revision) {
	try {
		if (projectModel.getObject().getRevCommit(revision, false) != null) {
			onSelect(target, revision);
		} else {
			feedbackMessage = "Can not find commit of revision " + revision + "";
			target.add(feedback);
		}
	} catch (Exception e) {
		// revision selector might be closed in onSelect handler
		if (findPage() != null) {
			feedbackMessage = Throwables.getRootCause(e).getMessage();
			target.add(feedback);
		} else {
			Throwables.propagate(e);
		}
	}
}
 
Example 4
Project: gitplex-mit   File: AffinalRevisionPicker.java   Source Code and License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	add(new ProjectPicker("projectPicker", new AffinalProjectsModel(projectId), projectId) {

		@Override
		protected void onSelect(AjaxRequestTarget target, Project project) {
			projectId = project.getId();
			revision = project.getDefaultBranch();
			newRevisionPicker(target);
			AffinalRevisionPicker.this.onSelect(target, project, revision);
		}
		
	});
	newRevisionPicker(null);
	
	setOutputMarkupId(true);
}
 
Example 5
Project: gitplex-mit   File: ReviewerChoice.java   Source Code and License 6 votes vote down vote up
@Override
protected void onSelect(AjaxRequestTarget target, UserFacade user) {
	PullRequest request = requestModel.getObject();
	ReviewInvitation invitation = null;
	for(ReviewInvitation each: request.getReviewInvitations()) {
		if (each.getUser().equals(user)) {
			invitation = each;
			break;
		}
	}
	if (invitation == null) {
		invitation = new ReviewInvitation();
		invitation.setRequest(request);
		invitation.setUser(GitPlex.getInstance(UserManager.class).load(user.getId()));
		request.getReviewInvitations().add(invitation);
	}
	invitation.setType(ReviewInvitation.Type.MANUAL);
	invitation.setDate(new Date());

	request.clearQualityStatus();
	
	if (!request.isNew())
		GitPlex.getInstance(ReviewInvitationManager.class).invite(invitation);
}
 
Example 6
Project: gitplex-mit   File: AjaxActionTab.java   Source Code and License 6 votes vote down vote up
@Override
public Component render(String componentId) {
	return new ActionTabLink(componentId, this) {

		@Override
		protected WebMarkupContainer newLink(String id, ActionTab tab) {
			return new AjaxLink<Void>("link") {

				@Override
				public void onClick(AjaxRequestTarget target) {
					selectTab(this);
				}
				
			};
		}
		
	};
}
 
Example 7
Project: gitplex-mit   File: SourceViewPanel.java   Source Code and License 6 votes vote down vote up
@Override
protected WebMarkupContainer newOptions(String id) {
	sourceFormat = new SourceFormatPanel(id, null, new OptionChangeCallback() {
		
		@Override
		public void onOptioneChange(AjaxRequestTarget target) {
			String script = String.format("gitplex.server.sourceView.onTabSizeChange(%s);", sourceFormat.getTabSize());
			target.appendJavaScript(script);
		}
		
	}, new OptionChangeCallback() {

		@Override
		public void onOptioneChange(AjaxRequestTarget target) {
			String script = String.format("gitplex.server.sourceView.onLineWrapModeChange('%s');", sourceFormat.getLineWrapMode());
			target.appendJavaScript(script);
		}
		
	});
	return sourceFormat;
}
 
Example 8
Project: gitplex-mit   File: ProjectBlobPage.java   Source Code and License 6 votes vote down vote up
@Override
protected void onPopState(AjaxRequestTarget target, Serializable data) {
	super.onPopState(target, data);

	State popState = (State) data;
	if (!popState.blobIdent.revision.equals(state.blobIdent.revision)) {
		state = popState;
		newSearchResult(target, null);
		onResolvedRevisionChange(target);
	} else {
		state = popState;
		newBlobNavigator(target);
		newBlobOperations(target);
		newBlobContent(target);
		resizeWindow(target);
	}
}
 
Example 9
Project: gitplex-mit   File: SelectToAddChoice.java   Source Code and License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	setOutputMarkupId(true);
	
	add(new AjaxFormComponentUpdatingBehavior("change") {

		@Override
		protected void onUpdate(AjaxRequestTarget target) {
			if (selection != null) {
				onSelect(target, selection);
				selection = null;
			}
			String script = String.format("$('#%s').select2('data', null);", getMarkupId());
			target.appendJavaScript(script);
		}
				
	});
}
 
Example 10
Project: gitplex-mit   File: AbstractSelect2Choice.java   Source Code and License 6 votes vote down vote up
@Override
public void onEvent(IEvent<?> event) {
	super.onEvent(event);

	if (event.getPayload() instanceof AjaxRequestTarget) {

		AjaxRequestTarget target = (AjaxRequestTarget) event.getPayload();

		if (target.getComponents().contains(this)) {

			// if this component is being repainted by ajax, directly, we
			// must destroy Select2 so it removes
			// its elements from DOM

			target.prependJavaScript(JQuery.execute("$('#%s').select2('destroy');", getJquerySafeMarkupId()));
		}
	}
}
 
Example 11
Project: gitplex-mit   File: ProjectBlobPage.java   Source Code and License 6 votes vote down vote up
private void newBlobContent(@Nullable AjaxRequestTarget target) {
	PrioritizedComponentRenderer mostPrioritizedRenderer = null;
	for (BlobRendererContribution contribution: GitPlex.getExtensions(BlobRendererContribution.class)) {
		PrioritizedComponentRenderer renderer = contribution.getRenderer(this);
		if (renderer != null) {
			if (mostPrioritizedRenderer == null || mostPrioritizedRenderer.getPriority() > renderer.getPriority())
				mostPrioritizedRenderer = renderer;
		}
	}
	Component blobContent = Preconditions.checkNotNull(mostPrioritizedRenderer).render(BLOB_CONTENT_ID);
	if (target != null) {
		replace(blobContent);
		target.add(blobContent);
	} else {
		add(blobContent);
	}
}
 
Example 12
Project: gitplex-mit   File: CodeCommentPanel.java   Source Code and License 6 votes vote down vote up
private WebMarkupContainer newAddReplyContainer() {
	WebMarkupContainer addReplyContainer = new Fragment("addReply", "addReplyFrag", this) {

		@Override
		protected void onConfigure() {
			super.onConfigure();
			setVisible(SecurityUtils.getUser() != null);
		}
		
	};
	addReplyContainer.setOutputMarkupId(true);
	addReplyContainer.add(new AjaxLink<Void>("reply") {

		@Override
		public void onClick(AjaxRequestTarget target) {
			onAddReply(target, false, null);
		}
		
	});
	return addReplyContainer;
}
 
Example 13
Project: gitplex-mit   File: SourceEditPanel.java   Source Code and License 5 votes vote down vote up
@Override
protected WebMarkupContainer newEditOptions(String componentId) {
	sourceFormat = new SourceFormatPanel(componentId, new OptionChangeCallback() {

		@Override
		public void onOptioneChange(AjaxRequestTarget target) {
			String script = String.format("gitplex.server.sourceEdit.onIndentTypeChange('%s', '%s');", 
					sourceFormComponent.getMarkupId(), sourceFormat.getIndentType());
			target.appendJavaScript(script);
		}
		
	}, new OptionChangeCallback() {

		@Override
		public void onOptioneChange(AjaxRequestTarget target) {
			String script = String.format("gitplex.server.sourceEdit.onTabSizeChange('%s', %s);", 
					sourceFormComponent.getMarkupId(), sourceFormat.getTabSize());
			target.appendJavaScript(script);
		}
		
	}, new OptionChangeCallback() {
		
		@Override
		public void onOptioneChange(AjaxRequestTarget target) {
			String script = String.format("gitplex.server.sourceEdit.onLineWrapModeChange('%s', '%s');", 
					sourceFormComponent.getMarkupId(), sourceFormat.getLineWrapMode());
			target.appendJavaScript(script);
		}
		
	});	
	return sourceFormat;
}
 
Example 14
Project: gitplex-mit   File: TestFormBehavior.java   Source Code and License 5 votes vote down vote up
public void requestTest(AjaxRequestTarget target) {
	target.appendJavaScript(String.format("var $button = $('#%s');"
			+ "$button.attr('disabled', 'disabled');"
			+ "$button[0].prevValue = $button.val();"
			+ "$button[0].prevHtml = $button.html();"
			+ "$button.val($button.val() + ' in progress...');"
			+ "$button.html($button.html() + ' in progress...');"
			+ "$button.addClass('ajax-indicator');"
			+ "$button.closest('form').children('.test-feedback').remove();", 
			getComponent().getMarkupId()));
	target.appendJavaScript(getCallbackScript());
}
 
Example 15
Project: gitplex-mit   File: ProjectBranchesPage.java   Source Code and License 5 votes vote down vote up
@Override
protected void onPopState(AjaxRequestTarget target, Serializable data) {
	super.onPopState(target, data);
	baseBranch = (String) data;
	target.add(baseChoice);
	target.add(branchesContainer);
	target.add(noBranchesContainer);
	target.add(pagingNavigator);
}
 
Example 16
Project: gitplex-mit   File: RunTaskBehavior.java   Source Code and License 5 votes vote down vote up
public void requestRun(AjaxRequestTarget target) {
	target.appendJavaScript(String.format(""
			+ "var $button = $('#%s');"
			+ "if ($button.length != 0) {"
			+ "$button.attr('disabled', 'disabled');"
			+ "$button[0].prevValue = $button.val();"
			+ "$button[0].prevHtml = $button.html();"
			+ "$button.val($button.val() + ' in progress...');"
			+ "$button.html($button.html() + ' in progress...');"
			+ "}",
			getComponent().getMarkupId()));
	target.appendJavaScript(getCallbackScript());
}
 
Example 17
Project: gitplex-mit   File: InfiniteScrollBehavior.java   Source Code and License 5 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
	IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
	int page = params.getParameterValue("page").toInt();
	target.prependJavaScript(String.format("$('#%s .loading-indicator').remove();", 
			getComponent().getMarkupId()));
	
	appendPage(target, page);

	target.appendJavaScript(String.format("gitplex.infiniteScroll.check('%s');", 
			getComponent().getMarkupId()));
}
 
Example 18
Project: gitplex-mit   File: CommitDetailPage.java   Source Code and License 5 votes vote down vote up
@Override
protected void onPopState(AjaxRequestTarget target, Serializable data) {
	super.onPopState(target, data);
	
	state = (State) data;
	newRevisionDiff(target);
}
 
Example 19
Project: gitplex-mit   File: InputChangeBehavior.java   Source Code and License 5 votes vote down vote up
@Override
protected void onUpdate(AjaxRequestTarget target) {
	FormComponent<?> component = (FormComponent<?>) getComponent();

	// IE triggers "input" event when the focused on the search input even if nothing is 
	// input into search box yet. To work around this issue, we compare search string 
	// against previous value to only update the branches table if there is an actual 
	// change.
	String newInput = component.getInput();
	if (!Objects.equals(newInput, input)) {
		input = newInput;
		onInputChange(target);
	}
}
 
Example 20
Project: gitplex-mit   File: OnTypingDoneBehavior.java   Source Code and License 5 votes vote down vote up
@Override
protected void onUpdate(AjaxRequestTarget target) {
	// IE triggers "input" event when the focused on the search input even if nothing is 
	// input into search box yet. To work around this issue, we compare search string 
	// against previous value to only update the branches table if there is an actual 
	// change.
	String newInput = ((FormComponent<?>)getComponent()).getInput();
	if (!Objects.equals(newInput, input)) {
		input = newInput;
		onTypingDone(target);
	}
}
 
Example 21
Project: gitplex-mit   File: ConcreteListPropertyEditor.java   Source Code and License 5 votes vote down vote up
private WebMarkupContainer addRow(final RepeatingView rows, Serializable element) {
	final WebMarkupContainer row = new WebMarkupContainer(rows.newChildId());
	row.setOutputMarkupId(true);
	rows.add(row);
	
	RepeatingView columns = new RepeatingView("properties");
	row.add(columns);
	
	for (PropertyContext<Serializable> propertyContext: propertyContexts) {
		WebMarkupContainer column = new WebMarkupContainer(columns.newChildId());
		column.add(AttributeAppender.append("class", " " + propertyContext.getPropertyName()));
		columns.add(column);
		
		Serializable propertyValue = (Serializable) propertyContext.getPropertyValue(element);
		PropertyEditor<?> propertyEditor = propertyContext.renderForEdit("propertyEditor", Model.of(propertyValue));
		column.add(propertyEditor);
		column.add(new FencedFeedbackPanel("feedback", propertyEditor));
	}
	
	row.add(new AjaxButton("deleteElement") {

		@Override
		protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
			super.onSubmit(target, form);
			
			target.appendJavaScript($(row).chain("remove").get());
			rows.remove(row);

			if (rows.size() == 0) {
				WebMarkupContainer table = (WebMarkupContainer) ConcreteListPropertyEditor.this.get("listEditor");
				target.add(table.get("noElementsRow"));
			}
			send(ConcreteListPropertyEditor.this, Broadcast.BUBBLE, new EditorChanged(target));								
		}

	}.setDefaultFormProcessing(false));
	
	return row;
}
 
Example 22
Project: gitplex-mit   File: MarkdownEditor.java   Source Code and License 5 votes vote down vote up
public void insertUrl(AjaxRequestTarget target, boolean isImage, String url, 
		@Nullable String name, String replaceMessage) {
	String script = String.format("gitplex.server.markdown.insertUrl('%s', %s, '%s', %s, %s);",
			container.getMarkupId(), isImage, StringEscapeUtils.escapeEcmaScript(url), 
			name!=null?"'"+StringEscapeUtils.escapeEcmaScript(name)+"'":"undefined", 
			replaceMessage!=null?"'"+replaceMessage+"'":"undefined");
	target.appendJavaScript(script);
}
 
Example 23
Project: gitplex-mit   File: RequestChangesPage.java   Source Code and License 5 votes vote down vote up
@Override
public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
	if (comment != null) {
		state.commentId = comment.getId();
		state.mark = comment.getCommentPos();
	} else {
		state.commentId = null;
		state.mark = null;
	}
	onRegionChange();
	pushState(target);
}
 
Example 24
Project: gitplex-mit   File: RequestChangesPage.java   Source Code and License 5 votes vote down vote up
@Override
protected void onPopState(AjaxRequestTarget target, Serializable data) {
	super.onPopState(target, data);

	state = (State) data;
	newRevisionDiff(target);
	onRegionChange();
}
 
Example 25
Project: gitplex-mit   File: CommitDetailPage.java   Source Code and License 5 votes vote down vote up
@Override
public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
	if (comment != null) {
		state.commentId = comment.getId();
		state.mark = comment.getCommentPos();
	} else {
		state.commentId = null;
		state.mark = null;
	}
	pushState(target);
}
 
Example 26
Project: gitplex-mit   File: FloatingPanel.java   Source Code and License 5 votes vote down vote up
public FloatingPanel(AjaxRequestTarget target, AlignTarget alignTarget, AlignPlacement placement) {
	super(((BasePage)target.getPage()).getRootComponents().newChildId());
	
	BasePage page = (BasePage) target.getPage(); 
	page.getRootComponents().add(this);
	target.prependJavaScript(String.format("$('body').append(\"<div id='%s'></div>\");", getMarkupId()));
	target.add(this);

	this.alignTarget = alignTarget;
	this.placement = placement;
}
 
Example 27
Project: gitplex-mit   File: FloatingPanel.java   Source Code and License 5 votes vote down vote up
public final void close() {
	AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
	if (target != null) {
		String script = String.format("gitplex.server.floating.close($('#%s'), false);", getMarkupId(true));
		target.appendJavaScript(script);
	} 
	if (getParent() != null)
		remove();
	onClosed();
}
 
Example 28
Project: gitplex-mit   File: ModalPanel.java   Source Code and License 5 votes vote down vote up
public ModalPanel(AjaxRequestTarget target, Size size) {
	super(((BasePage)target.getPage()).getRootComponents().newChildId());
	
	this.size = size;
	
	BasePage page = (BasePage) target.getPage(); 
	page.getRootComponents().add(this);
	target.prependJavaScript(String.format("$('body').append(\"<div id='%s'></div>\");", getMarkupId()));
	target.add(this);
}
 
Example 29
Project: gitplex-mit   File: ModalPanel.java   Source Code and License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	WebMarkupContainer dialog = new WebMarkupContainer("dialog");
	add(dialog);
	
	dialog.add(newContent(CONTENT_ID));
	
	if (size == Size.LARGE)
		dialog.add(AttributeAppender.append("class", "modal-lg"));
	else if (size == Size.SMALL)
		dialog.add(AttributeAppender.append("class", "modal-sm"));
	
	add(new AbstractPostAjaxBehavior() {
		
		@Override
		protected void respond(AjaxRequestTarget target) {
			ModalPanel.this.remove();
			onClosed();
		}
		
		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			super.renderHead(component, response);

			response.render(JavaScriptHeaderItem.forReference(new ModalResourceReference()));
			
			String script = String.format("gitplex.server.modal.onDomReady('%s', %s);", 
					getMarkupId(true), getCallbackFunction());
			response.render(OnDomReadyHeaderItem.forScript(script));
		}

	});
	
	setOutputMarkupId(true);
}
 
Example 30
Project: gitplex-mit   File: ProjectBlobPage.java   Source Code and License 5 votes vote down vote up
@Override
public void onSelect(AjaxRequestTarget target, BlobIdent blobIdent, @Nullable TokenPosition tokenPos) {
	state.mark = TextRange.of(tokenPos);
	if (!blobIdent.revision.equals(state.blobIdent.revision)) {
		state.blobIdent = blobIdent;
		state.mode = Mode.VIEW;
		state.commentId = null;
		state.requestId = null;
		newSearchResult(target, null);
		onResolvedRevisionChange(target);
	} else {
		if (!Objects.equal(state.blobIdent.path, blobIdent.path) 
				|| state.mark != null && !(get(BLOB_CONTENT_ID) instanceof Markable)) {
			state.blobIdent.path = blobIdent.path;
			state.blobIdent.mode = blobIdent.mode;
			state.mode = Mode.VIEW;
			state.commentId = null;
			newBlobNavigator(target);
			newBlobOperations(target);
			newBlobContent(target);
			resizeWindow(target);
			GitPlex.getInstance(WebSocketManager.class).onRegionChange(this);
		} else if (state.mark != null) {
			// This logic is added for performance reason, we do not want to 
			// reload the file if go to different mark positions in same file
			((Markable)get(BLOB_CONTENT_ID)).mark(target, state.mark);
		}
	}
	pushState(target);
}
 
Example 31
Project: gitplex-mit   File: RequestChangesPage.java   Source Code and License 5 votes vote down vote up
@Override
public void onAddComment(AjaxRequestTarget target, MarkPos mark) {
	state.commentId = null;
	state.mark = mark;
	pushState(target);
	onRegionChange();
}
 
Example 32
Project: gitplex-mit   File: SourceViewPanel.java   Source Code and License 5 votes vote down vote up
private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
	clearComment(target);
	String script = String.format("gitplex.server.sourceView.onCommentDeleted(%s);", 
			getJsonOfComment(comment));
	target.appendJavaScript(script);
	context.onCommentOpened(target, null);
}
 
Example 33
Project: gitplex-mit   File: ConfirmDeleteProjectModal.java   Source Code and License 5 votes vote down vote up
@Override
protected void doDelete(AjaxRequestTarget target) {
	Project project = getProject();
	
	GitPlex.getInstance(ProjectManager.class).delete(project);
	getSession().success("Repository has been deleted");
	
	onDeleted(target);
}
 
Example 34
Project: gitplex-mit   File: RevisionComparePage.java   Source Code and License 5 votes vote down vote up
@Override
protected void onPopState(AjaxRequestTarget target, Serializable data) {
	super.onPopState(target, data);
	
	state = (State) data;
	GitPlex.getInstance(WebSocketManager.class).onRegionChange(this);
	
	newTabPanel(target);
	target.add(tabbable);
}
 
Example 35
Project: gitplex-mit   File: CodeCommentPanel.java   Source Code and License 5 votes vote down vote up
private void onStatusChanged(AjaxRequestTarget target, Fragment fragment, CodeCommentStatusChange statusChange) {
	WebMarkupContainer activityContainer = newActivityContainer(activitiesView.newChildId(), statusChange);
	activitiesView.add(activityContainer);

	String script = String.format("$('#%s .add-reply').before('<div id=\"%s\"></div>');", 
			CodeCommentPanel.this.getMarkupId(), activityContainer.getMarkupId());
	target.prependJavaScript(script);
	target.add(activityContainer);

	WebMarkupContainer addReplyContainer = newAddReplyContainer();
	fragment.replaceWith(addReplyContainer);
	target.add(addReplyContainer);
}
 
Example 36
Project: gitplex-mit   File: CodeCommentPanel.java   Source Code and License 5 votes vote down vote up
private void onReplyAdded(AjaxRequestTarget target, Fragment fragment, @Nullable CodeCommentReply reply) {
	if (reply != null) {
		WebMarkupContainer activityContainer = newActivityContainer(activitiesView.newChildId(), reply);
		activitiesView.add(activityContainer);

		String script = String.format("$('#%s .add-reply').before('<div id=\"%s\"></div>');", 
				CodeCommentPanel.this.getMarkupId(), activityContainer.getMarkupId());
		target.prependJavaScript(script);
		target.add(activityContainer);
	}
	
	WebMarkupContainer addReplyContainer = newAddReplyContainer();
	fragment.replaceWith(addReplyContainer);
	target.add(addReplyContainer);
}
 
Example 37
Project: gitplex-mit   File: ProjectPicker.java   Source Code and License 5 votes vote down vote up
@Override
protected Component newContent(String id, FloatingPanel dropdown) {
	return new ProjectSelector(id, projectsModel, currentProjectId) {

		@Override
		protected void onSelect(AjaxRequestTarget target, Project project) {
			dropdown.close();
			target.add(ProjectPicker.this);
			ProjectPicker.this.onSelect(target, project);
		}

	};
}
 
Example 38
Project: gitplex-mit   File: RevisionDiffPanel.java   Source Code and License 5 votes vote down vote up
private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
	clearComment(target);
	SourceAware sourceAware = getSourceAware(comment.getCommentPos().getPath());
	if (sourceAware != null)
		sourceAware.onCommentDeleted(target, comment);
	((CommentSupport)markSupport).onCommentOpened(target, null);
	target.appendJavaScript("gitplex.server.revisionDiff.reposition();");
	MarkPos mark = getMark();
	if (mark != null) {
		sourceAware = getSourceAware(mark.getPath());
		if (sourceAware != null) {
			sourceAware.mark(target, mark);
		}
	}
}
 
Example 39
Project: gitplex-mit   File: BlobDiffPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
	Component content = get(CONTENT_ID);
	if (content instanceof SourceAware) {
		SourceAware sourceAware = (SourceAware) content;
		sourceAware.onCommentDeleted(target, comment);
	}
}
 
Example 40
Project: gitplex-mit   File: SearchResultPanel.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void onActiveIndexChange(AjaxRequestTarget target) {
	Component hitsContainer = blobsView.get(activeBlobIndex).get(HITS_ID);
	if (!hitsContainer.isVisibilityAllowed()) {
		hitsContainer.setVisibilityAllowed(true);
		target.add(hitsContainer);
		target.add(blobsView.get(activeBlobIndex).get(EXPAND_LINK_ID));
	} 

	String activeLinkId = getMarkupId() + "-" + activeBlobIndex; 
	if (activeHitIndex != -1)
		activeLinkId += "-" + activeHitIndex;

	String script = String.format(""
			+ "$('#%s').find('.selectable').removeClass('active');"
			+ "$('#%s').addClass('active');"
			+ "$('#%s>.search-result>.body').scrollIntoView('a.selectable.active', 25, 25);", 
			getMarkupId(), activeLinkId, getMarkupId());
	target.appendJavaScript(script);
	
	target.add(prevMatchLink);
	target.add(nextMatchLink);
	
	MatchedBlob activeBlob = blobs.get(activeBlobIndex);
	
	QueryHit hit;
	if (activeHitIndex != -1)
		hit = activeBlob.getHits().get(activeHitIndex);
	else 
		hit = new FileHit(activeBlob.getBlobPath(), null);
	
	BlobIdent selected = new BlobIdent(context.getBlobIdent().revision, hit.getBlobPath(), 
			FileMode.REGULAR_FILE.getBits());
	context.onSelect(target, selected, hit.getTokenPos());
}
 
Example 41
Project: gitplex-mit   File: BlobDiffPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void onCommentAdded(AjaxRequestTarget target, CodeComment comment) {
	Component content = get(CONTENT_ID);
	if (content instanceof SourceAware) {
		SourceAware sourceAware = (SourceAware) content;
		sourceAware.onCommentAdded(target, comment);
	}
}
 
Example 42
Project: gitplex-mit   File: BlobDiffPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void onUnblame(AjaxRequestTarget target) {
	Component content = get(CONTENT_ID);
	if (content instanceof SourceAware) {
		SourceAware sourceAware = (SourceAware) content;
		sourceAware.onUnblame(target);
	}
}
 
Example 43
Project: gitplex-mit   File: TextDiffPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
	String script = String.format("gitplex.server.textDiff.onCommentDeleted($('#%s'), %s);", 
			getMarkupId(), getJsonOfComment(comment));
	target.appendJavaScript(script);
	mark(target, null);
}
 
Example 44
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 45
Project: gitplex-mit   File: ProjectBranchesPage.java   Source Code and License 4 votes vote down vote up
private void pushState(AjaxRequestTarget target) {
	PageParameters params = paramsOf(getProject(), baseBranch);
	CharSequence url = RequestCycle.get().urlFor(ProjectBranchesPage.class, params);
	pushState(target, url.toString(), baseBranch);
}
 
Example 46
Project: gitplex-mit   File: BlobViewPanel.java   Source Code and License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	add(new Label("lines", new AbstractReadOnlyModel<String>() {

		@Override
		public String getObject() {
			return context.getProject().getBlob(context.getBlobIdent()).getText().getLines().size() + " lines";
		}
		
	}) {

		@Override
		protected void onConfigure() {
			super.onConfigure();
			
			setVisible(context.getProject().getBlob(context.getBlobIdent()).getText() != null);
		}
		
	});
	
	add(new Label("charset", new AbstractReadOnlyModel<String>() {

		@Override
		public String getObject() {
			return context.getProject().getBlob(context.getBlobIdent()).getText().getCharset().displayName();
		}
		
	}) {

		@Override
		protected void onConfigure() {
			super.onConfigure();
			
			setVisible(context.getProject().getBlob(context.getBlobIdent()).getText() != null);
		}
		
	});
	
	add(new Label("size", FileUtils.byteCountToDisplaySize(context.getProject().getBlob(context.getBlobIdent()).getSize())));
	
	add(newOptions("options"));
	
	add(new ResourceLink<Void>("raw", new RawBlobResourceReference(), 
			RawBlobResource.paramsOf(context.getProject(), context.getBlobIdent())));
	add(new CheckBox("blame", Model.of(context.getMode() == Mode.BLAME)) {
		
		@Override
		protected void onConfigure() {
			super.onConfigure();
			setVisible(context.getProject().getBlob(context.getBlobIdent()).getText() != null);
		}

	}.add(new OnChangeAjaxBehavior() {
		
		@Override
		protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
			super.updateAjaxAttributes(attributes);
			attributes.setMethod(Method.POST);
			attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());
			attributes.getAjaxCallListeners().add(new TrackViewStateListener(true));
		}
		
		@Override
		protected void onUpdate(AjaxRequestTarget target) {
			if (context.getMode() == Mode.BLAME)
				context.onModeChange(target, Mode.VIEW);
			else
				context.onModeChange(target, Mode.BLAME);
		}
		
	}));

	add(newAdditionalActions("extraActions"));
	newChangeActions(null);
	
	setOutputMarkupId(true);
}
 
Example 47
Project: gitplex-mit   File: DropBehavior.java   Source Code and License 4 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
	IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
	String dragData = params.getParameterValue("dragData").toString();
	onDropped(target, dragData);
}
 
Example 48
Project: gitplex-mit   File: ReflectionPropertyEditor.java   Source Code and License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	if (getPropertyDescriptor().isPropertyRequired()) {
		add(new WebMarkupContainer("enable").setVisible(false));
	} else {
		add(new CheckBox("enable", new IModel<Boolean>() {
			
			@Override
			public void detach() {
				
			}

			@Override
			public Boolean getObject() {
				return ReflectionPropertyEditor.this.get(BEAN_EDITOR_ID).isVisible();
			}

			@Override
			public void setObject(Boolean object) {
				Component beanEditor = ReflectionPropertyEditor.this.get(BEAN_EDITOR_ID);
				if (beanEditor instanceof BeanEditor || !object) {
					beanEditor.setVisible(object);
				} else {
					ReflectionPropertyEditor.this.replace(newBeanEditor(newProperty()));
				}
			}
			
		}).add(new AjaxFormComponentUpdatingBehavior("click"){

			@Override
			protected void onUpdate(AjaxRequestTarget target) {
				send(ReflectionPropertyEditor.this, Broadcast.BUBBLE, new EditorChanged(target));								
				target.add(ReflectionPropertyEditor.this.get(BEAN_EDITOR_ID));
			}
			
		}));
		
	}

	Serializable propertyValue = getModelObject();
	
	if (getPropertyDescriptor().isPropertyRequired() && propertyValue == null) {
		propertyValue = newProperty();
	}
	add(newBeanEditor(propertyValue));
}
 
Example 49
Project: gitplex-mit   File: PolymorphicListPropertyEditor.java   Source Code and License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	if (getPropertyDescriptor().isPropertyRequired()) {
		add(new WebMarkupContainer("enable").setVisible(false));
	} else {
		add(new CheckBox("enable", new IModel<Boolean>() {
			
			@Override
			public void detach() {
				
			}

			@Override
			public Boolean getObject() {
				return PolymorphicListPropertyEditor.this.get("listEditor").isVisible();
			}

			@Override
			public void setObject(Boolean object) {
				PolymorphicListPropertyEditor.this.get("listEditor").setVisible(object);
			}
			
		}).add(new AjaxFormComponentUpdatingBehavior("change") {
			
			@Override
			protected void onUpdate(AjaxRequestTarget target) {
				send(PolymorphicListPropertyEditor.this, Broadcast.BUBBLE, new EditorChanged(target));								
				target.add(PolymorphicListPropertyEditor.this.get("listEditor"));
			}
			
		}));
		
	}
	
	List<Serializable> list = getModelObject();
	if (list == null && getPropertyDescriptor().isPropertyRequired())
		list = newList(); 
	add(newListEditor(list));
}
 
Example 50
Project: gitplex-mit   File: ConcreteListPropertyEditor.java   Source Code and License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	if (getPropertyDescriptor().isPropertyRequired()) {
		add(new WebMarkupContainer("enable").setVisible(false));
	} else {
		add(new CheckBox("enable", new IModel<Boolean>() {
			
			@Override
			public void detach() {
				
			}

			@Override
			public Boolean getObject() {
				return ConcreteListPropertyEditor.this.get("listEditor").isVisible();
			}

			@Override
			public void setObject(Boolean object) {
				ConcreteListPropertyEditor.this.get("listEditor").setVisible(object);
			}
			
		}).add(new AjaxFormComponentUpdatingBehavior("click") {
			
			@Override
			protected void onUpdate(AjaxRequestTarget target) {
				send(ConcreteListPropertyEditor.this, Broadcast.BUBBLE, new EditorChanged(target));								
				target.add(ConcreteListPropertyEditor.this.get("listEditor"));
			}
			
		}));
		
	}
	
	List<Serializable> list = getModelObject();
	if (list == null && getPropertyDescriptor().isPropertyRequired())
		list = newList(); 
	add(newListEditor(list));
}
 
Example 51
Project: gitplex-mit   File: ProjectCommitsPage.java   Source Code and License 4 votes vote down vote up
private void pushState(AjaxRequestTarget target) {
	PageParameters params = paramsOf(getProject(), state);
	CharSequence url = RequestCycle.get().urlFor(ProjectCommitsPage.class, params);
	pushState(target, url.toString(), state);
}
 
Example 52
Project: gitplex-mit   File: DropdownLink.java   Source Code and License 4 votes vote down vote up
@Override
public void onClick(AjaxRequestTarget target) {
	// if dropdown has not been created, or has been removed from page 
	// when the same page instance is refreshed 
	if (dropdown == null || dropdown.getParent() == null) { 
		AlignTarget alignFloatingWith;
		if (alignTargetMouse) {
			int mouseX = RequestCycle.get().getRequest().getPostParameters()
					.getParameterValue("mouseX").toInt();
			int mouseY = RequestCycle.get().getRequest().getPostParameters()
					.getParameterValue("mouseY").toInt();
			alignFloatingWith = RectTarget.ofMouse(mouseX, mouseY);
		} else { 
			alignFloatingWith =  new ComponentTarget(this);
		} 
		
		dropdown = new FloatingPanel(target, alignFloatingWith, placement) {

			@Override
			protected void onInitialize() {
				super.onInitialize();
				DropdownLink.this.onInitialize(this);
			}

			@Override
			protected Component newContent(String id) {
				return DropdownLink.this.newContent(id, this);
			}

			@Override
			protected void onClosed() {
				super.onClosed();

				AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
				if (target != null) {
					String script = String.format("$('#%s').removeClass('dropdown-open');", 
							DropdownLink.this.getMarkupId(true));
					target.appendJavaScript(script);
				}
				
				dropdown = null;
			}

		};
		String script = String.format(""
				+ "$('#%s').addClass('dropdown-open');"
				+ "$('#%s').data('trigger', $('#%s'));", 
				getMarkupId(), dropdown.getMarkupId(), getMarkupId());
		target.appendJavaScript(script);
	} else {
		dropdown.close();
	}
}
 
Example 53
Project: gitplex-mit   File: AjaxActionTab.java   Source Code and License 4 votes vote down vote up
@Override
protected final void onSelect(Component tabLink) {
	AjaxRequestTarget target = (AjaxRequestTarget) RequestCycle.get().getRequestHandlerScheduledAfterCurrent();
	target.add(Preconditions.checkNotNull(tabLink.findParent(Tabbable.class)));
	onSelect(target, tabLink);
}
 
Example 54
Project: gitplex-mit   File: ProjectBlobPage.java   Source Code and License 4 votes vote down vote up
private void pushState(AjaxRequestTarget target) {
	PageParameters params = paramsOf(getProject(), state);
	CharSequence url = RequestCycle.get().urlFor(ProjectBlobPage.class, params);
	pushState(target, url.toString(), state);
}
 
Example 55
Project: gitplex-mit   File: ModalPanel.java   Source Code and License 4 votes vote down vote up
public ModalPanel(AjaxRequestTarget target) {
	this(target, Size.MEDIUM);
}
 
Example 56
Project: gitplex-mit   File: BaseErrorPage.java   Source Code and License 4 votes vote down vote up
@Override
protected void onPopState(AjaxRequestTarget target, Serializable data) {
	super.onPopState(target, data);
	target.appendJavaScript("location.reload();");
}
 
Example 57
Project: gitplex-mit   File: CommitDetailPage.java   Source Code and License 4 votes vote down vote up
@Override
public void onAddComment(AjaxRequestTarget target, MarkPos mark) {
	state.commentId = null;
	state.mark = mark;
	pushState(target);
}
 
Example 58
Project: gitplex-mit   File: CodeCommentPanel.java   Source Code and License 4 votes vote down vote up
public void onChangeStatus(AjaxRequestTarget target) {
	onAddReply(target, true, "Leave a note");
}
 
Example 59
Project: gitplex-mit   File: RevisionDiffPanel.java   Source Code and License 4 votes vote down vote up
private void clearComment(AjaxRequestTarget target) {
	commentContainer.replace(new WebMarkupContainer(BODY_ID));
	commentContainer.setVisible(false);
	target.add(commentContainer);
}
 
Example 60
Project: gitplex-mit   File: SourceViewPanel.java   Source Code and License 4 votes vote down vote up
private void clearComment(AjaxRequestTarget target) {
	commentContainer.replace(new WebMarkupContainer(BODY_ID));
	commentContainer.setVisible(false);
	target.add(commentContainer);
}