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.RestoreParams;
026
027/**
028 *
029 * @author kulikov
030 */
031public class RestoreControl extends VLayout {
032
033    private final AdminView adminView;
034    private final RestoreDialog restoreDialog = new RestoreDialog(this);
035    
036    public RestoreControl(final AdminView adminView) {
037        super();
038        this.adminView = adminView;
039        
040        setStyleName("admin-control");
041
042        Label label = new Label("Restore");
043        label.setIcon("icons/documents.png");
044        label.setStyleName("button-label");
045        label.setHeight(25);
046        label.addClickHandler(new ClickHandler() {
047            @Override
048            public void onClick(ClickEvent event) {
049                restoreDialog.showModal();
050            }
051        });
052
053        Canvas text = new Canvas();
054        text.setAutoHeight();
055        text.setContents("Once you have a complete backup on disk, you can "
056                + "then restore a repository back to the state captured "
057                + "within the backup. To do that, simply start a repository "
058                + "(or perhaps a new instance of a repository with a "
059                + "different configuration) and, before it’s used by "
060                + "any applications, load into the new repository all of " + "the content in the backup. ");
061
062        addMember(label);
063        addMember(text);
064    }
065    
066    public void restore(String name, RestoreParams params) {
067        adminView.jcrService().restore(adminView.repository(), name, params, new AsyncCallback() {
068
069            @Override
070            public void onFailure(Throwable caught) {
071                SC.say(caught.getMessage());
072            }
073
074            @Override
075            public void onSuccess(Object result) {
076            }
077        });
078    }
079}