/** * The contents of this file are subject to the license and copyright * detailed in the LICENSE file at the root of the source * tree and available online at * * https://github.com/keeps/roda */ package org.roda.wui.client.planning; import java.util.List; import org.roda.core.data.v2.formats.Format; import org.roda.wui.client.browse.BrowserService; import org.roda.wui.client.common.UserLogin; import org.roda.wui.client.common.utils.AsyncCallbackUtils; import org.roda.wui.client.common.utils.JavascriptUtils; import org.roda.wui.client.management.MemberManagement; import org.roda.wui.common.client.HistoryResolver; import org.roda.wui.common.client.tools.HistoryUtils; import org.roda.wui.common.client.tools.ListUtils; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; public class CreateFormat extends Composite { public static final HistoryResolver RESOLVER = new HistoryResolver() { @Override public void resolve(List<String> historyTokens, final AsyncCallback<Widget> callback) { CreateFormat createFormat = new CreateFormat(new Format()); callback.onSuccess(createFormat); } @Override public void isCurrentUserPermitted(AsyncCallback<Boolean> callback) { UserLogin.getInstance().checkRoles(new HistoryResolver[] {MemberManagement.RESOLVER}, false, callback); } @Override public List<String> getHistoryPath() { return ListUtils.concat(FormatRegister.RESOLVER.getHistoryPath(), getHistoryToken()); } @Override public String getHistoryToken() { return "create_format"; } }; interface MyUiBinder extends UiBinder<Widget, CreateFormat> { } private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class); private Format format; @UiField Button buttonApply; @UiField Button buttonCancel; @UiField(provided = true) FormatDataPanel formatDataPanel; /** * Create a new panel to create a user * * @param user * the user to create */ public CreateFormat(Format format) { this.format = format; this.formatDataPanel = new FormatDataPanel(true, false, format); initWidget(uiBinder.createAndBindUi(this)); } @Override protected void onLoad() { super.onLoad(); JavascriptUtils.stickSidebar(); } @UiHandler("buttonApply") void buttonApplyHandler(ClickEvent e) { if (formatDataPanel.isValid()) { format = formatDataPanel.getFormat(); BrowserService.Util.getInstance().createFormat(format, new AsyncCallback<Format>() { @Override public void onFailure(Throwable caught) { AsyncCallbackUtils.defaultFailureTreatment(caught); } @Override public void onSuccess(Format result) { HistoryUtils.newHistory(FormatRegister.RESOLVER, result.getId()); } }); } } @UiHandler("buttonCancel") void buttonCancelHandler(ClickEvent e) { cancel(); } private void cancel() { HistoryUtils.newHistory(FormatRegister.RESOLVER); } }