de.tudarmstadt.ukp.experiments.inviedit.client.gui.InViEditMenuBar.java Source code

Java tutorial

Introduction

Here is the source code for de.tudarmstadt.ukp.experiments.inviedit.client.gui.InViEditMenuBar.java

Source

/*******************************************************************************
 * Copyright 2016
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universitt Darmstadt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package de.tudarmstadt.ukp.experiments.inviedit.client.gui;

import com.google.gwt.user.client.Window;
import com.smartgwt.client.util.BooleanCallback;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.toolbar.ToolStrip;

import de.tudarmstadt.ukp.experiments.inviedit.client.ckeditor.versioncontrol.VersionManagement;
import de.tudarmstadt.ukp.experiments.inviedit.shared.util.Function;

/**
 * Menubar for the application.
 */
public class InViEditMenuBar extends ToolStrip {

    protected VersionManagement versionManagement;
    private Button saveButton;
    private Button loadButton;

    public InViEditMenuBar(final VersionManagement versionManagement, boolean showLoad, boolean showSave,
            final String logOutURL) {
        this.versionManagement = versionManagement;

        if (showSave) {
            saveButton = new Button();
            saveButton.setTitle("Speichern");
            saveButton.setHeight100();
            saveButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    versionManagement.save();
                }
            });
            addMember(saveButton);
        }

        if (showLoad) {
            loadButton = new Button();
            loadButton.setTitle("Laden");
            loadButton.setHeight100();
            loadButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    versionManagement.load();
                }
            });
            addMember(loadButton);
        }

        if (logOutURL != null) {
            Button logOutButton = new Button();
            logOutButton.setTitle("Abmelden");
            logOutButton.setHeight100();
            logOutButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    MainLayout.writeToJsConsole("Initializing SAVE");
                    versionManagement.save(new Function() {
                        @Override
                        public void execute() {
                            MainLayout.writeToJsConsole("SAVE successful");
                            SC.say("Ihre Eingaben wurden gespeichert und das System wird nun beendet. Sie knnen sich bei Bedarf spter erneut anmelden.",
                                    new BooleanCallback() {
                                        @Override
                                        public void execute(Boolean value) {
                                            Window.open(logOutURL, "_self", "");
                                        }
                                    });
                        }
                    }, true);
                }
            });
            this.addMember(logOutButton);
        }
    }

}