001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.web.client.admin;
017
018import com.google.gwt.user.client.rpc.AsyncCallback;
019import com.smartgwt.client.util.SC;
020import com.smartgwt.client.widgets.Canvas;
021import com.smartgwt.client.widgets.Label;
022import com.smartgwt.client.widgets.events.ClickEvent;
023import com.smartgwt.client.widgets.events.ClickHandler;
024import com.smartgwt.client.widgets.layout.VLayout;
025import org.modeshape.web.shared.BackupParams;
026
027/**
028 *
029 * @author kulikov
030 */
031public class BackupControl extends VLayout {
032
033    private final BackupDialog backupDialog = new BackupDialog(this);
034    private final AdminView adminView;
035
036    public BackupControl(AdminView adminView) {
037        super();
038        this.adminView = adminView;
039
040        setStyleName("admin-control");
041
042        Label label = new Label("Backup");
043        label.setIcon("icons/data.png");
044        label.setStyleName("button-label");
045        label.setHeight(25);
046        label.addClickHandler(new ClickHandler() {
047            @Override
048            public void onClick(ClickEvent event) {
049                backupDialog.showModal();
050            }
051        });
052
053        Canvas text = new Canvas();
054        text.setAutoHeight();
055        text.setContents("Create backups of an entire repository (even when " + "the repository is in use)"
056                + "This works regardless of where the repository content " + "is persisted.");
057
058        addMember(label);
059        addMember(text);
060    }
061
062    protected void backup(String name, BackupParams params) {
063        adminView.jcrService().backup(adminView.repository(), name, params, new AsyncCallback<Object>() {
064            @Override
065            public void onFailure(Throwable caught) {
066                SC.say(caught.getMessage());
067            }
068
069            @Override
070            public void onSuccess(Object result) {
071                SC.say("Complete");
072            }
073        });
074    }
075}