use of org.apache.wicket.Component in project gitblit by gitblit.
the class TicketPage method createMergePanel.
/**
* Adds a merge panel for the patchset to the markup container. The panel
* may just a message if the patchset can not be merged.
*
* @param c
* @param user
* @param repository
*/
protected Component createMergePanel(UserModel user, RepositoryModel repository) {
Patchset patchset = ticket.getCurrentPatchset();
if (patchset == null) {
// no patchset to merge
return new Label("mergePanel");
}
boolean allowMerge;
if (repository.requireApproval) {
// repository requires approval
allowMerge = ticket.isOpen() && ticket.isApproved(patchset);
} else {
// vetoes are binding
allowMerge = ticket.isOpen() && !ticket.isVetoed(patchset);
}
MergeStatus mergeStatus = JGitUtils.canMerge(getRepository(), patchset.tip, ticket.mergeTo, repository.mergeType);
if (allowMerge) {
if (MergeStatus.MERGEABLE == mergeStatus) {
// patchset can be cleanly merged to integration branch OR has already been merged
Fragment mergePanel = new Fragment("mergePanel", "mergeableFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetMergeable"), ticket.mergeTo)));
if (user.canPush(repository)) {
// user can merge locally
SimpleAjaxLink<String> mergeButton = new SimpleAjaxLink<String>("mergeButton", Model.of(getString("gb.merge"))) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
// ensure the patchset is still current AND not vetoed
Patchset patchset = ticket.getCurrentPatchset();
final TicketModel refreshedTicket = app().tickets().getTicket(getRepositoryModel(), ticket.number);
if (patchset.equals(refreshedTicket.getCurrentPatchset())) {
// patchset is current, check for recent veto
if (!refreshedTicket.isVetoed(patchset)) {
// patchset is not vetoed
// execute the merge using the ticket service
app().tickets().exec(new Runnable() {
@Override
public void run() {
PatchsetReceivePack rp = new PatchsetReceivePack(app().gitblit(), getRepository(), getRepositoryModel(), GitBlitWebSession.get().getUser());
MergeStatus result = rp.merge(refreshedTicket);
if (MergeStatus.MERGED == result) {
// notify participants and watchers
rp.sendAll();
} else {
// merge failure
String msg = MessageFormat.format("Failed to merge ticket {0,number,0}: {1}", ticket.number, result.name());
logger.error(msg);
GitBlitWebSession.get().cacheErrorMessage(msg);
}
}
});
} else {
// vetoed patchset
String msg = MessageFormat.format("Can not merge ticket {0,number,0}, patchset {1,number,0} has been vetoed!", ticket.number, patchset.number);
GitBlitWebSession.get().cacheErrorMessage(msg);
logger.error(msg);
}
} else {
// not current patchset
String msg = MessageFormat.format("Can not merge ticket {0,number,0}, the patchset has been updated!", ticket.number);
GitBlitWebSession.get().cacheErrorMessage(msg);
logger.error(msg);
}
redirectTo(TicketsPage.class, getPageParameters());
}
};
mergePanel.add(mergeButton);
Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetMergeableMore");
mergePanel.add(instructions);
} else {
mergePanel.add(new Label("mergeButton").setVisible(false));
mergePanel.add(new Label("mergeMore").setVisible(false));
}
return mergePanel;
} else if (MergeStatus.ALREADY_MERGED == mergeStatus) {
// patchset already merged
Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
return mergePanel;
} else if (MergeStatus.MISSING_INTEGRATION_BRANCH == mergeStatus) {
// target/integration branch is missing
Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.missingIntegrationBranchMore"), ticket.mergeTo)));
return mergePanel;
} else {
// patchset can not be cleanly merged
Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
if (user.canPush(repository)) {
// user can merge locally
Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetNotMergeableMore");
mergePanel.add(instructions);
} else {
mergePanel.add(new Label("mergeMore").setVisible(false));
}
return mergePanel;
}
} else {
// merge not allowed
if (MergeStatus.ALREADY_MERGED == mergeStatus) {
// patchset already merged
Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
return mergePanel;
} else if (ticket.isVetoed(patchset)) {
// patchset has been vetoed
Fragment mergePanel = new Fragment("mergePanel", "vetoedFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
return mergePanel;
} else if (repository.requireApproval) {
// patchset has been not been approved for merge
Fragment mergePanel = new Fragment("mergePanel", "notApprovedFragment", this);
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotApproved"), ticket.mergeTo)));
mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.patchsetNotApprovedMore"), ticket.mergeTo)));
return mergePanel;
} else {
// other case
return new Label("mergePanel");
}
}
}
use of org.apache.wicket.Component in project gitblit by gitblit.
the class MyDashboardPage method setup.
private void setup(PageParameters params) {
setupPage("", "");
// check to see if we should display a login message
boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
String messageSource = app().settings().getString(Keys.web.loginMessage, "gitblit");
String message = readMarkdown(messageSource, "login.mkd");
Component repositoriesMessage = new Label("repositoriesMessage", message);
add(repositoriesMessage.setEscapeModelStrings(false));
add(new Label("activity").setVisible(false));
add(new Label("repositoryTabs").setVisible(false));
return;
}
// Load the markdown welcome message
String messageSource = app().settings().getString(Keys.web.repositoriesMessage, "gitblit");
String message = readMarkdown(messageSource, "welcome.mkd");
Component repositoriesMessage = new Label("repositoriesMessage", message).setEscapeModelStrings(false).setVisible(message.length() > 0);
add(repositoriesMessage);
UserModel user = GitBlitWebSession.get().getUser();
if (user == null) {
user = UserModel.ANONYMOUS;
}
// parameters
int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
if (daysBack < 1) {
daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
}
if (maxDaysBack > 0 && daysBack > maxDaysBack) {
daysBack = maxDaysBack;
}
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, -1 * daysBack);
Date minimumDate = c.getTime();
// build repo lists
List<RepositoryModel> starred = new ArrayList<RepositoryModel>();
List<RepositoryModel> owned = new ArrayList<RepositoryModel>();
List<RepositoryModel> active = new ArrayList<RepositoryModel>();
for (RepositoryModel model : getRepositoryModels()) {
if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
owned.add(model);
}
if (user.getPreferences().isStarredRepository(model.name)) {
starred.add(model);
}
if (model.isShowActivity() && model.lastChange.after(minimumDate)) {
active.add(model);
}
}
Comparator<RepositoryModel> lastUpdateSort = new Comparator<RepositoryModel>() {
@Override
public int compare(RepositoryModel o1, RepositoryModel o2) {
return o2.lastChange.compareTo(o1.lastChange);
}
};
Collections.sort(owned, lastUpdateSort);
Collections.sort(starred, lastUpdateSort);
Collections.sort(active, lastUpdateSort);
String activityTitle;
Set<RepositoryModel> feed = new HashSet<RepositoryModel>();
feed.addAll(starred);
feed.addAll(owned);
if (feed.isEmpty()) {
// no starred or owned, go with recent activity
activityTitle = getString("gb.recentActivity");
feed.addAll(active);
} else if (starred.isEmpty()) {
// no starred, owned repos feed
activityTitle = getString("gb.owned");
} else if (owned.isEmpty()) {
// no owned, starred repos feed
activityTitle = getString("gb.starred");
} else {
// starred and owned repositories
activityTitle = getString("gb.starredAndOwned");
}
addActivity(user, feed, activityTitle, daysBack);
Fragment repositoryTabs;
if (UserModel.ANONYMOUS.equals(user)) {
repositoryTabs = new Fragment("repositoryTabs", "anonymousTabsFragment", this);
} else {
repositoryTabs = new Fragment("repositoryTabs", "authenticatedTabsFragment", this);
}
add(repositoryTabs);
// projects list
List<ProjectModel> projects = app().projects().getProjectModels(getRepositoryModels(), false);
repositoryTabs.add(new FilterableProjectList("projects", projects));
// active repository list
if (active.isEmpty()) {
repositoryTabs.add(new Label("active").setVisible(false));
} else {
FilterableRepositoryList repoList = new FilterableRepositoryList("active", active);
repoList.setTitle(getString("gb.activeRepositories"), "icon-time");
repositoryTabs.add(repoList);
}
// starred repository list
if (ArrayUtils.isEmpty(starred)) {
repositoryTabs.add(new Label("starred").setVisible(false));
} else {
FilterableRepositoryList repoList = new FilterableRepositoryList("starred", starred);
repoList.setTitle(getString("gb.starredRepositories"), "icon-star");
repositoryTabs.add(repoList);
}
// owned repository list
if (ArrayUtils.isEmpty(owned)) {
repositoryTabs.add(new Label("owned").setVisible(false));
} else {
FilterableRepositoryList repoList = new FilterableRepositoryList("owned", owned);
repoList.setTitle(getString("gb.myRepositories"), "icon-user");
repoList.setAllowCreate(user.canCreate() || user.canAdmin());
repositoryTabs.add(repoList);
}
}
use of org.apache.wicket.Component in project gitblit by gitblit.
the class SessionlessForm method onComponentTagBody.
/**
* Append an additional hidden input tag that forces Wicket to correctly
* determine the destination page class even after a session expiration or
* a server restart.
*
* @param markupStream
* The markup stream
* @param openTag
* The open tag for the body
*/
@Override
protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) {
// render the hidden bookmarkable page field
AppendingStringBuffer buffer = new AppendingStringBuffer(HIDDEN_DIV_START);
buffer.append("<input type=\"hidden\" name=\"").append(WebRequestCodingStrategy.BOOKMARKABLE_PAGE_PARAMETER_NAME).append("\" value=\":").append(pageClass.getName()).append("\" />");
// do not collide with any child wicket:id of the form.
if (pageParameters != null) {
for (String key : pageParameters.keySet()) {
Component c = get(key);
if (c != null) {
// this form has a field id which matches the
// parameter name, skip embedding a hidden value
log.warn(MessageFormat.format("Skipping page parameter \"{0}\" from sessionless form hidden fields because it collides with a form child wicket:id", key));
continue;
}
String value = pageParameters.getString(key);
buffer.append("<input type=\"hidden\" name=\"").append(recode(key)).append("\" value=\"").append(recode(value)).append("\" />");
}
}
buffer.append("</div>");
getResponse().write(buffer);
super.onComponentTagBody(markupStream, openTag);
}
use of org.apache.wicket.Component in project midpoint by Evolveum.
the class PrismValuePanel method removeValue.
private void removeValue(AjaxRequestTarget target) {
ValueWrapper wrapper = valueWrapperModel.getObject();
ItemWrapper propertyWrapper = wrapper.getItem();
LOGGER.debug("Removing value of {}", propertyWrapper);
List<ValueWrapper> values = propertyWrapper.getValues();
Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
switch(wrapper.getStatus()) {
case ADDED:
values.remove(wrapper);
break;
case DELETED:
error("Couldn't delete already deleted item: " + wrapper.toString());
target.add(((PageBase) getPage()).getFeedbackPanel());
case NOT_CHANGED:
if (inputPanel instanceof AssociationValueChoicePanel) {
((PropertyWrapper) propertyWrapper).setStatus(ValueStatus.DELETED);
}
wrapper.setStatus(ValueStatus.DELETED);
break;
}
// wrapper.getItem().getContainer().
int count = countUsableValues(propertyWrapper);
if (count == 0 && !hasEmptyPlaceholder(propertyWrapper)) {
if (inputPanel instanceof ValueChoosePanel) {
values.add(new ValueWrapper(propertyWrapper, new PrismReferenceValue(null), ValueStatus.ADDED));
} else if (inputPanel instanceof AssociationValueChoicePanel) {
Item item = propertyWrapper.getItem();
ItemPath path = item.getPath();
if (path != null) {
}
// values.add(new ValueWrapper(propertyWrapper, new PrismPropertyValue(null), ValueStatus.ADDED));
} else {
values.add(new ValueWrapper(propertyWrapper, new PrismPropertyValue(null), ValueStatus.ADDED));
}
}
ListView parent = findParent(ListView.class);
target.add(parent.getParent());
}
use of org.apache.wicket.Component in project midpoint by Evolveum.
the class PrismValuePanel method isAddButtonVisible.
private boolean isAddButtonVisible() {
Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
ValueWrapper valueWrapper = valueWrapperModel.getObject();
if (valueWrapper.isReadonly()) {
return false;
}
ItemWrapper propertyWrapper = valueWrapper.getItem();
Item property = propertyWrapper.getItem();
ItemDefinition definition = property.getDefinition();
int max = definition.getMaxOccurs();
List<ValueWrapper> usableValues = getUsableValues(propertyWrapper);
if (usableValues.indexOf(valueWrapper) != usableValues.size() - 1) {
return false;
}
if (max == -1) {
return true;
}
if (countNonDeletedValues(propertyWrapper) >= max) {
return false;
}
if (propertyWrapper.getContainer() == null) {
// TODO
return true;
}
return isAccessible(definition, getContainerStatus(propertyWrapper));
}
Aggregations