fi.hip.sicx.vaadin.GUIComponent.java Source code

Java tutorial

Introduction

Here is the source code for fi.hip.sicx.vaadin.GUIComponent.java

Source

/*
 * Copyright (C) 2012 Helsinki Institute of Physics, University of Helsinki
 * All rights reserved. See the copyright.txt in the distribution for a full 
 * listing of individual contributors.
 *    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 fi.hip.sicx.vaadin;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

import org.joni.test.meta.ACLItem;
import org.joni.test.meta.MetaDataAPI;
import org.joni.test.meta.MetaFile;
import org.joni.test.meta.MetaFileImpl;
import org.joni.test.meta.SLA;
import org.joni.test.meta.StripeLocation;
import org.joni.test.meta.UserInfo;

import com.eaio.uuid.UUID;
import com.github.wolfie.refresher.Refresher;
import com.github.wolfie.refresher.Refresher.RefreshListener;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.FilesystemContainer;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.MouseEvents;
import com.vaadin.event.MouseEvents.ClickListener;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
//import com.vaadin.ui.ProgressIndicator;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.TableDragMode;
import com.vaadin.ui.Table.TableTransferable;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.Notification;
import com.vaadin.ui.themes.BaseTheme;

import fi.hip.sicx.sla.SLAManager;
import fi.hip.sicx.store.MetaHandler;

/**
 * GUIComponent class.
 *
 * @author Seppo Heikkila <seppo.heikkila@cern.ch>
 * @author Joakim Koskela <jookos@gmail.com>
 * @author Joni Hahkala <joni.hahkala@cern.ch>
 */
public class GUIComponent extends CustomComponent implements SICXUploaderObserver {

    /**
    * 
    */
    private static final long serialVersionUID = -1837020052619399795L;

    @AutoGenerated
    private AbsoluteLayout mainLayout;

    @AutoGenerated
    private VerticalSplitPanel consoleSplit;

    @AutoGenerated
    private TextArea consoleWindow;

    @AutoGenerated
    private HorizontalSplitPanel HorizontalSplitPanel;

    @AutoGenerated
    private VerticalLayout verticalU;

    @AutoGenerated
    private Table servert;

    @AutoGenerated
    private TextField addressU;

    @AutoGenerated
    private HorizontalLayout buttonsU;

    @AutoGenerated
    private Label labelU;

    @AutoGenerated
    private HorizontalLayout horizontalLayout_1;

    @AutoGenerated
    private ComboBox SLAselector;

    @AutoGenerated
    private Embedded helpU;

    @AutoGenerated
    private Embedded deleteU;

    @AutoGenerated
    private Embedded newfolderU;

    @AutoGenerated
    private Embedded reloadR;

    @AutoGenerated
    private VerticalLayout verticalL;

    @AutoGenerated
    private Table localt;

    @AutoGenerated
    private TextField addressL;

    @AutoGenerated
    private HorizontalLayout buttonsL;

    @AutoGenerated
    private Label labelL;

    @AutoGenerated
    private HorizontalLayout buttonsonlyL;

    @AutoGenerated
    private Embedded helpL;

    @AutoGenerated
    private Embedded deleteL;

    @AutoGenerated
    private Embedded newfolderL;

    @AutoGenerated
    private Embedded reloadL;

    @AutoGenerated
    private Button logoff;

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /** The SLA manager instance used here */
    private SLAManager slaManager = null;

    /** the root entry (directory) for the current remotet listing */
    private MetaFile currentRemoteRoot = null;

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    /**
     * The constructor should first build the main layout, set the composition root and then do any custom
     * initialization.
     * 
     * The constructor will not be automatically regenerated by the visual editor.
     */
    public GUIComponent() {
        buildMainLayout();
        setCompositionRoot(mainLayout);
        // setTheme("contacts");

        localt.addContainerProperty("Name", String.class, "");
        localt.addContainerProperty("Size", String.class, "");

        //consoleSplit.setSplitPosition(, unit, reverse)
        consoleSplit.setSplitPosition(20, UNITS_PIXELS, true);
        //consoleSplit.setSplitPosition(23, UNITS_EM, true);
        consoleWindow.setWordwrap(true);
        //consoleWindow.setValue("TIME: message");

        guicomponent = this;
        reloadL.addListener(new ClickListener() {
            private static final long serialVersionUID = -373224176129978341L;

            public void click(MouseEvents.ClickEvent event) {
                generateLocalTable(addressL.getValue().toString());
                //FilesystemContainer lfs = new FilesystemContainer(new File());
                //localt.setContainerDataSource(lfs);
                localt.setSelectable(true);
                localt.setImmediate(true);
                localt.setDragMode(TableDragMode.ROW);
                localt.setVisibleColumns(new Object[] { "Name", "Size" });

                // refresh.setCaption("Upload2");
                guicomponent.notifyUser("Local directory refreshed successfully.",
                        Notification.TYPE_TRAY_NOTIFICATION);

                //databaseResult  = "done";
            }
        });

        reloadR.addListener(new ClickListener() {
            private static final long serialVersionUID = -3332391167664810694L;

            public void click(MouseEvents.ClickEvent event) {
                // we need a fresh instance of the MetaFile, as this one
                // might have obsolete cached values!
                //MetaFile loc = new MetaFileImpl();
                if (currentRemoteRoot != null) {
                    //loc.setName(currentRemoteRoot);
                    //loc.setName(addressU.getValue().toString());
                    //initiateList(loc, false);
                    initiateList(currentRemoteRoot, null, false);
                } else {
                    //loc.setName("");
                    initiateList(null, null, false);
                }
                slaManager.init();
            }
        });

        newfolderU.addListener(new ClickListener() {
            private static final long serialVersionUID = -5005613038853764246L;

            public void click(MouseEvents.ClickEvent event) {

                SLA sla = getSelectedSLA();
                if (sla == null)
                    return;

                // note: this will block the UI thread, this should
                // probably be done in the sicx uploader!
                try {
                    MetaDataAPI meta = MetaHandler.getInstance().getService();
                    UserInfo user = meta.getUserInfo();
                    MetaFile root = currentRemoteRoot;
                    if (root == null || !root.isDirectory())
                        root = meta.getFile(user.getRoots().get(0));

                    MetaFile mf = new MetaFileImpl();
                    mf.setParent(root.getId());
                    mf.setDirectory(true);
                    mf.setName("folder_" + System.currentTimeMillis());
                    // mf.setLength(); // ?
                    mf.addACLItem(new ACLItem(user.getName(), true, true));
                    mf.setSLA(sla);
                    meta.putFile(mf);

                    String sumFieldText = "<font color=\"green\">100%</font>";
                    Label sumField = new Label(sumFieldText, Label.CONTENT_XHTML);
                    // todo: refresh
                    servert.addItem(new Object[] { mf.getName(), "0", sla.getSLA(), sumField }, mf);
                    guicomponent.notifyUser("New folder \"" + mf.getName() + "\" created.",
                            Notification.TYPE_TRAY_NOTIFICATION);
                } catch (IOException ex) {
                    guicomponent.notifyUser("Error connecting to the meta service.",
                            Notification.TYPE_ERROR_MESSAGE);
                }
            }
        });

        newfolderL.addListener(new ClickListener() {
            private static final long serialVersionUID = -5687108712228863320L;

            public void click(MouseEvents.ClickEvent event) {
                guicomponent.notifyUser(
                        "Error: directory not created to local disk. Reason: local disk is read only.",
                        Notification.TYPE_ERROR_MESSAGE);
            }
        });

        helpU.addListener(new ClickListener() {
            private static final long serialVersionUID = 5380444803250921905L;

            public void click(MouseEvents.ClickEvent event) {
                //servert.getValue().getClass().e .equals() "Object);
                MetaFile mfile = (MetaFile) servert.getValue();
                if (mfile != null) {
                    openFileInfoWindow();
                    addToFileInfoWindow("Filename", mfile.getName());
                    addToFileInfoWindow("SLA", mfile.getSLA().getSLA());
                    addToFileInfoWindow("File size (bytes)", String.format("%d", mfile.getLength()));
                    addToFileInfoWindow("Date", "Mon Jun 4 13:07:55 EEST 2012");
                    int keyLength = 128;
                    //String algorithm = "AES";
                    String cipher = "AES/CBC/PKCS5Padding";
                    addToFileInfoWindow("Encryption algorithm", cipher);
                    addToFileInfoWindow("Encryption key length (bits)", String.format("%d", keyLength));
                    addToFileInfoWindow("Encryption keys parts distributed in Hydra", String.format("%d", 3));

                    //                   addToFileInfoWindow("Encryption key 1", String.format("%d", keyLength));
                    addToFileInfoWindow("Stripes", String.format("%d", mfile.getStripes().size()));
                    addToFileInfoWindow("Stripes required to construct the file",
                            String.format("%d", mfile.getMinStripes()));
                    addToFileInfoWindow("Stripe size (bytes)", String.format("%d",
                            (int) (Math.ceil(
                                    (mfile.getLength() + 256.0) / (mfile.getBlockSize() * mfile.getMinStripes()))
                                    * mfile.getBlockSize())));
                    int count = 1;
                    for (StripeLocation s : mfile.getStripes()) {
                        String tp = String.format("Stripe %d URI", count);
                        addToFileInfoWindow(tp, s.getURI().toString());

                        tp = String.format("Stripe %d details", count);
                        //String country = "London/UK/Europe (Eucalyptus Community Cloud)";
                        String country = "No details available";
                        if (s.getURI().toString().startsWith("webdav")) {
                            //country = "Osaka/Japan/Asia (Greenqloud)";
                            country = "OwnCloud supported external storage";
                        } else if (s.getURI().toString().startsWith("jclouds")) {
                            country = "jClouds supported storage";
                        }
                        addToFileInfoWindow(tp, country);
                        count += 1;
                    }
                } else {
                    return;
                }
                guicomponent.notifyUser("Info requested from SICX file '" + mfile.getName() + "'.",
                        Notification.TYPE_TRAY_NOTIFICATION);
            }
        });

        deleteL.addListener(new ClickListener() {
            private static final long serialVersionUID = -3253683774985376259L;

            public void click(MouseEvents.ClickEvent event) {
                //servert.getValue().getClass().e .equals() "Object);
                String filename;
                if (localt.getValue() != null) {
                    filename = localt.getItem(localt.getValue()).getItemProperty("Name").getValue().toString();
                } else {
                    System.out.println("Nothing selected.");
                    return;
                }
                String filewithpath = addressL.getValue() + "/" + filename;
                File delme = new File(filewithpath);
                if (delme.exists()) {
                    if (delme.delete()) {
                        generateLocalTable(addressL.getValue().toString());
                        guicomponent.notifyUser("Local file '" + filewithpath + "' deleted.",
                                Notification.TYPE_TRAY_NOTIFICATION);
                        return;
                    }
                }
                guicomponent.notifyUser(
                        "Delete of file '" + filewithpath + "' failed, check local file permissions.",
                        Notification.TYPE_ERROR_MESSAGE);
            }
        });

        deleteU.addListener(new ClickListener() {
            private static final long serialVersionUID = 5721272940113116072L;

            public void click(MouseEvents.ClickEvent event) {
                //servert.getValue().getClass().e .equals() "Object);
                MetaFile mfile = (MetaFile) servert.getValue();
                int tid = getFreeUploaderIndex();
                if (tid != -1 && mfile != null) {
                    sicx_uploader[tid] = new SICXUploader((GUIComponent) component, "delete", mfile);
                    sicx_uploader[tid].start();
                } else {
                    return;
                }
                guicomponent.notifyUser("Deleting file '" + mfile.getName() + "' from the cloud.",
                        Notification.TYPE_TRAY_NOTIFICATION);
            }
        });

        addressL.addListener(new TextChangeListener() {
            private static final long serialVersionUID = 1048639156493298177L;

            public void textChange(TextChangeEvent event) {
                // jk: quickfix for the address-entry thing (enter to change), should be fixed.
                if (!event.getText().endsWith("\n"))
                    return;

                String localPath = event.getText().trim();
                addressL.setValue(localPath);
                if (localPath.endsWith("Desktop") || localPath.endsWith("sicx") || localPath.endsWith("test")) {
                    File target = new File(localPath);
                    if (target.exists()) {
                        generateLocalTable(localPath);
                        //FilesystemContainer lfs = new FilesystemContainer(new File(localPath));
                        //localt.setContainerDataSource(lfs);
                        localt.setSelectable(true);
                        localt.setImmediate(true);
                        localt.setDragMode(TableDragMode.ROW);
                        localt.setVisibleColumns(new Object[] { "Name", "Size" });
                        LocalProperties.getInstance().setProperty("folder.local", localPath);
                    } else {
                        System.out.println("Path '" + localPath + "' does not exist.");
                        guicomponent.notifyUser("Path does not exist.", Notification.TYPE_ERROR_MESSAGE);
                    }
                } else {
                    guicomponent.notifyUser(
                            "For privacy reasons, you can only switch to \"test\", \"sicx\" or \"Desktop\" directories in this SICX test.",
                            Notification.TYPE_ERROR_MESSAGE);
                }
            }
        });

        addressU.addListener(new TextChangeListener() {
            // what's this? // private static final long serialVersionUID = 1048639156493298177L;

            /**
            * 
            */
            private static final long serialVersionUID = 1743722720538963217L;

            public void textChange(TextChangeEvent event) {
                // jk: quickfix for the address-entry thing (enter to change), should be fixed.
                if (!event.getText().endsWith("\n"))
                    return;

                String localPath = event.getText().trim();
                if (localPath == null || localPath.isEmpty()) {
                    localPath = "/";
                }
                addressU.setValue(localPath);
                //MetaFile target = new MetaFileImpl();
                //target.setName(localPath);
                //target.
                initiateList(null, localPath, false);
            }
        });

        helpL.addListener(new ClickListener() {
            /**
            * 
            */
            private static final long serialVersionUID = -7237156098333148153L;

            public void click(MouseEvents.ClickEvent event) {
                guicomponent.notifyUser("Click the item you want to get help about.",
                        Notification.TYPE_TRAY_NOTIFICATION);

            }
        });

        // jk: default working directory. go through a couple of alternatives
        String LocalPath = LocalProperties.getInstance().getProperty("folder.local");
        if (LocalPath == null || !(new File(LocalPath).exists())) {
            String[] pathAlternatives = new String[] {
                    System.getProperty("user.home") + System.getProperty("file.separator") + "sicx",
                    System.getProperty("user.home") + System.getProperty("file.separator") + "Desktop",
                    System.getProperty("user.home") };

            // default if nothing else works:
            LocalPath = System.getProperty("user.dir");
            for (String p : pathAlternatives) {
                if (new File(p).exists()) {
                    LocalPath = p;
                    break;
                }
            }
        }
        addressL.setValue(LocalPath);
        generateLocalTable(LocalPath);
        localt.setSelectable(true);
        //localt.setMultiSelect(true);
        localt.setImmediate(true);
        localt.setDragMode(TableDragMode.ROW);
        //localt.setDragMode(TableDragMode.MULTIROW); //TableDragMode.ROW);
        localt.setVisibleColumns(new Object[] { "Name", "Size" });
        localt.setSortAscending(true);
        localt.setSortDisabled(false);

        servert.addContainerProperty("Name", String.class, "");
        servert.addContainerProperty("Size", String.class, "");
        servert.addContainerProperty("SLA", String.class, "");
        // servert.addContainerProperty("Availability", String.class, "");
        servert.addContainerProperty("Availability", Label.class, null);
        // servert.setContainerDataSource(localt.getContainerDataSource());
        // servert.setPropertyDataSource(localt.getPropertyDataSource());
        // servert.removeAllItems();
        servert.setDragMode(TableDragMode.ROW);
        //servert.setDragMode(TableDragMode.MULTIROW); // .ROW);
        servert.setSelectable(true);
        //servert.setMultiSelect(true);
        servert.setImmediate(true);

        servert.addListener(new ItemClickEvent.ItemClickListener() {
            /**
            * 
            */
            private static final long serialVersionUID = 6217401940389968651L;

            public void itemClick(ItemClickEvent event) {
                if (event.isDoubleClick()) {
                    MetaFile mf = (MetaFile) event.getItemId();
                    if (mf != null && mf.isDirectory()) {
                        System.out.println("Dir***********: " + mf.getName());
                        if (mf.getName().equals("..")) {
                            if (currentRemoteRoot == null) {
                                System.out.println("Error: root was null.");
                            } else {
                                initiateList(currentRemoteRoot, null, true);
                            }
                        } else {
                            initiateList(mf, null, false);
                        }
                    }
                }
            }
        });

        slaManager = SLAManager.getInstance();
        slaManager.init();
        String[] slanames = slaManager.getAvailableSLANames();
        for (String sn : slanames) {
            SLAselector.addItem(sn);
            if (sn.equals(slaManager.getDefaultSLAName()))
                SLAselector.select(sn);
        }

        /*
        SLAselector.addItem("SLA-public");
        Item defsel = SLAselector.addItem("SLA-free");
        SLAselector.select("SLA-free");
        */
        SLAselector.setInputPrompt("Select SLA");

        // The Refresher polls automatically                                                                                                                                                                  
        refresher = new Refresher();
        refresher.setRefreshInterval(250);
        refresher.addListener(new DatabaseListener());
        mainLayout.addComponent(refresher);

        // Initiate list of uploaders
        component = this;
        sicx_uploader = new SICXUploader[MAX_NUMBER_OF_CONCURRENT_UPLOADS];

        // Logout buttons
        logoff.setStyleName(BaseTheme.BUTTON_LINK);
        logoff.setDescription("Logged in as John User");
        logoff.addListener(new Button.ClickListener() {
            /**
            * 
            */
            private static final long serialVersionUID = 7493665381081434662L;

            public void buttonClick(ClickEvent event) {
                openLoginWindow();
            }
        });

        localt.setDropHandler(new DropHandler() {

            /**
            * 
            */
            private static final long serialVersionUID = 7218229410915466702L;

            public AcceptCriterion getAcceptCriterion() {
                return AcceptAll.get();
            }

            public void drop(DragAndDropEvent dropEvent) {
                // Get transfered object
                TableTransferable dt = (TableTransferable) dropEvent.getTransferable();
                Table source = dt.getSourceComponent();
                if (source != servert)
                    return;

                MetaFile mfile = (MetaFile) dt.getItemId();
                //System.out.println("MetafileGUI: " + mfile.getName());

                File file = new File(addressL.getValue() + System.getProperty("file.separator") + mfile.getName());

                int tid = getFreeUploaderIndex();
                if (tid != -1) {
                    // jk: this could actually have an SLA associated with it; download from fast / slow / place..
                    sicx_uploader[tid] = new SICXUploader((GUIComponent) component, "download", mfile, file);
                    sicx_uploader[tid].start();
                    localt.addItem(new Object[] { file.getName(), "Downloading..." },
                            sicx_uploader[tid].getTargetFile());
                } else {
                    guicomponent.notifyUser(
                            "Maximum number of concurrent uploads achieved. Solution: wait for some time.",
                            Notification.TYPE_ERROR_MESSAGE);
                    return;
                }

                guicomponent.notifyUser("File " + mfile.getName() + " is being downloaded.",
                        Notification.TYPE_TRAY_NOTIFICATION);
                //databaseResult  = "done";
            }
        });

        servert.setDropHandler(new DropHandler() {

            private static final long serialVersionUID = 6099711806439056603L;

            public AcceptCriterion getAcceptCriterion() {

                return AcceptAll.get();
                //return new AcceptOnlyFromSpecificTableCriterion(localt);
                /* jk: didn't work out the way i wanted..
                return new ClientSideCriterion() {
                public boolean accept(DragAndDropEvent dropEvent) {
                    TableTransferable dt = (TableTransferable)dropEvent.getTransferable();
                    Table source = dt.getSourceComponent();
                    return (source == localt);
                }
                    
                public void paint(PaintTarget target) throws PaintException {
                    target.startTag("-ac");
                    target.addAttribute("name", "AcceptFromLocaltOnlyCriterion");
                    target.endTag("-ac");
                }
                };
                */
            }

            public void drop(DragAndDropEvent dropEvent) {

                // Get transfered object
                TableTransferable dt = (TableTransferable) dropEvent.getTransferable();
                Table source = dt.getSourceComponent();
                if (source != localt)
                    return;

                File file = (File) dt.getItemId();
                SLA sla = getSelectedSLA();
                if (sla == null)
                    return;

                // Check if file is already transferred
                for (Iterator<?> ii = servert.getItemIds().iterator(); ii.hasNext();) {
                    if (servert.getItem(ii.next()).getItemProperty("Name").getValue().equals(file.getName())) {
                        guicomponent.notifyUser("Another file with the same name exists already.",
                                Notification.TYPE_ERROR_MESSAGE);
                        return;
                    }
                }

                //                Double rand = new Double(Math.random() * 100);
                //                String sumFieldText;
                //                if (rand < 50) {
                //                    sumFieldText = "<font color=\"red\">" + String.format("%.0f", rand * 1.9) + "%</font>";
                //                } else {
                //                    sumFieldText = "<font color=\"green\">100%</font>";
                //                }

                // jk: here we should create a meta entry, some sort of 'in progress' flag and use the 
                // normal refresh to update the list! Or not, as that would be heavy. Instead, create some sort
                // of local in-mem list that keeps track of what is current in progress. Adds those to the 
                // servert list, refreshing them periodically.

                // todo: we need to get the metafile entry created for this to be able to display it in the list!
                int tid = getFreeUploaderIndex();
                if (tid != -1) {
                    sicx_uploader[tid] = new SICXUploader((GUIComponent) component, "upload", currentRemoteRoot,
                            file, sla, null);
                    //                        Label sumField = new Label(sumFieldText, Label.CONTENT_XHTML);
                    // todo: refresh
                    servert.addItem(new Object[] { file.getName(), file.length(), sla.getSLA(), "Uploading.." },
                            sicx_uploader[tid].getTargetFile());
                    sicx_uploader[tid].start();
                    guicomponent.notifyUser("File " + file.getName() + " is being uploaded.",
                            Notification.TYPE_TRAY_NOTIFICATION);
                } else {
                    guicomponent.notifyUser(
                            "Maximum number of concurrent uploads achieved. Solution: wait for some time.",
                            Notification.TYPE_ERROR_MESSAGE);
                }

            }
        });

        // TODO add user code here
        localt.addListener(new Property.ValueChangeListener() {

            /**
            * 
            */
            private static final long serialVersionUID = 5726026778085555596L;

            public void valueChange(ValueChangeEvent event) {
                // TODO Auto-generated method stub
                // servert.setContainerDataSource(localt.getContainerDataSource());
                // setImmediate(true);
                // servert.setPropertyDataSource(localt.getPropertyDataSource());
                // servert.addContainerProperty("Name", String.class, "");
                // servert.addItem(new Object[] { "Sepi"}, 0);
                // refresh.setCaption("Upload selected");
            }
        });

        this.msg_prev = "First!";
    }

    GUIComponent guicomponent;
    String msg_prev;

    private void notifyUser(String msg, int type) {
        if (type == Notification.TYPE_TRAY_NOTIFICATION) {
            Calendar cal = Calendar.getInstance();
            String dateFormat = "yyyy.MM.dd hh:mm:ss";
            SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
            String timestamp = sdf.format(cal.getTime());

            if (!this.msg_prev.equals(msg)) {
                consoleWindow.setValue(timestamp + ": " + msg + "\n" + consoleWindow.getValue());
                this.msg_prev = msg; // Avoid duplicate prints
            }
            //getWindow().showNotification("Info:", "new folder \"" + mf.getName() + "\" created.",
            //        Notification.TYPE_TRAY_NOTIFICATION);
        } else if (type == Notification.TYPE_ERROR_MESSAGE) {
            if (!this.msg_prev.equals(msg)) {
                getWindow().showNotification(msg, Notification.TYPE_TRAY_NOTIFICATION);
                notifyUser(msg, Notification.TYPE_TRAY_NOTIFICATION);
                this.msg_prev = msg; // Avoid duplicate prints
            }
        }
    }

    private Window subwindow;

    /**
     * Opens a window for user login.
     * 
     * @return true if all ok, else false
     */
    public boolean openLoginWindow() {
        // Login window
        subwindow = new Window("SICX login");
        subwindow.setContent(new LoginWindow(this, subwindow));
        subwindow.setResizable(false);
        subwindow.setClosable(false);
        subwindow.setDraggable(false);
        subwindow.setModal(true);
        subwindow.setReadOnly(true);
        getWindow().addWindow(subwindow);

        return true;
    }

    private Window fileinfowindow;

    /**
     * Opens a window for user login.
     * 
     * @return true if all ok, else false
     */
    public boolean openFileInfoWindow() {
        // Login window
        fileinfowindow = new Window("SICX file information");
        fileinfowindow.setContent(new FileInfoWindow(this, fileinfowindow));
        //fileinfowindow.setResizable(false);
        fileinfowindow.setClosable(true);
        fileinfowindow.setDraggable(true);
        //fileinfowindow.setModal(false);
        //fileinfowindow.setReadOnly(true);
        fileinfowindow.setWidth(500, UNITS_PIXELS);
        fileinfowindow.setHeight(400, UNITS_PIXELS);
        getWindow().addWindow(fileinfowindow);

        return true;
    }

    private boolean addToFileInfoWindow(String v1, String v2) {
        FileInfoWindow fin = (FileInfoWindow) fileinfowindow.getContent();
        return fin.addValue(v1, v2);
    }

    //private Window statuswindow;
    /**
     * Opens a window for user login.
     * 
     * @return true if all ok, else false
     *
    public boolean openStatusMessageWindow() {
       // Login window
       this.statuswindow = new Window("Status message");
       this.statuswindow.setContent(new StatusWindow()); //this, subwindow));
       this.statuswindow.setResizable(false);
       this.statuswindow.setClosable(false);
       this.statuswindow.setBorder(Window.BORDER_NONE);
       this.statuswindow.setDraggable(false);
       this.statuswindow.setImmediate(true);
       this.statuswindow.setWidth("300px");
       this.statuswindow.setHeight("100px");
       //this.statuswindow.set
       //subwindow.setModal(true);
       //this.statuswindow.setReadOnly(true);
       getWindow().addWindow(this.statuswindow);
           
       return true;
    }
    public boolean repositionStatusWindow() {
       System.out.println("WIDTH: " + (int)(this.statuswindow.getWidth()));
         //.getWidth()));
       System.out.println("HEIGHT: " + (int)(this.statuswindow.getHeight()));
       //this.statuswindow.setPositionX(100); //(int)(getWindow().getWidth()-this.statuswindow.getWidth()));
       //this.statuswindow.setPositionY(100); //(int)(getWindow().getHeight()-this.statuswindow.getHeight()));       
       this.statuswindow.setPositionX((int)(getWindow().getWidth()-this.statuswindow.getWidth()));
       this.statuswindow.setPositionY((int)(getWindow().getHeight()-this.statuswindow.getHeight()));
       return true;
    }*/

    /**
     * Give authentication certificate and try if it works.
     * 
     * @param cert Certificate for authentication
     * @return true if certificate worked, otherwise false
     */
    public boolean doAuthentication(File cert, String username) {
        if (cert == null || !cert.exists()) {
            // Inform that login was ok
            guicomponent.notifyUser(
                    "User '" + username + "' login failed - please check your username and password.",
                    Notification.TYPE_TRAY_NOTIFICATION);
            return false;
        } else {
            // Inform that login was ok
            guicomponent.notifyUser("User '" + username + "' logged in.", Notification.TYPE_TRAY_NOTIFICATION);

            // Initialise meta connection
            MetaHandler meta = MetaHandler.getInstance();
            try {
                System.out.println("Initing metadata");
                meta.init();
            } catch (Exception ex) {
                System.out.println("Fail with exception " + ex);
                ex.printStackTrace();
            }

            // List user files from the cloud (open one of the root dirs as default if exists)
            MetaDataAPI metapi = MetaHandler.getInstance().getService();
            UserInfo ui = metapi.getUserInfo();
            if (ui == null) {
                System.out.println("User (you) does not exist in the system.");
                return true;
            }
            MetaFile entry = null;
            for (UUID uuid : ui.getRoots()) {
                try {
                    entry = metapi.getFile(uuid);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            if (entry != null) {
                System.out.println("Using initial directory: '" + entry.getName() + "'.");
                initiateList(entry, null, false);
            } else {
                initiateList(null, null, false);
            }

            return true;
        }
    }

    /**
     * Refreshes the remote listing
     */
    private boolean initiateList(MetaFile root, String path, boolean parent) {

        int tid = getFreeUploaderIndex();
        if (tid != -1) {
            sicx_uploader[tid] = new SICXUploader((GUIComponent) component, (parent ? "parentlist" : "list"), root,
                    null, null, path);
            sicx_uploader[tid].start();
            if (getWindow() != null)
                guicomponent.notifyUser("SICX storage content is being refreshed.",
                        Notification.TYPE_TRAY_NOTIFICATION);
            return true;
        } else {
            if (getWindow() != null)
                guicomponent.notifyUser(
                        "Maximum number of concurrent uploads achieved. Solution: wait for some time.",
                        Notification.TYPE_ERROR_MESSAGE);
            return false;
        }
    }

    /**
     * Returns the currently selected SLA. Reports errors and returns
     * null.
     */
    private SLA getSelectedSLA() {

        String slaname = "fail";
        if (SLAselector.getValue() == SLAselector.getNullSelectionItemId()) {
            guicomponent.notifyUser("Please choose SLA from drop-down box.", Notification.TYPE_ERROR_MESSAGE);
            SLAselector.setRequired(true);
            return null;
        } else {
            SLAselector.setRequired(false);
            slaname = SLAselector.getValue().toString();
        }

        SLA sla = slaManager.getSLAByName(slaname);
        if (sla == null) {
            guicomponent.notifyUser("Please update your SLA drop-down box.", Notification.TYPE_ERROR_MESSAGE);
        }
        return sla;
    }

    public class AcceptOnlyFromSpecificTableCriterion implements AcceptCriterion {
        //extends ClientSideCriterion {

        /**
        * 
        */
        private static final long serialVersionUID = 800540714264657698L;
        private Table source;

        public AcceptOnlyFromSpecificTableCriterion(Table source) {
            //super();
            this.source = source;
        }

        public boolean isClientSideVerifiable() {
            System.out.println("is client side??");
            return false;
        }

        public boolean accept(DragAndDropEvent dropEvent) {
            System.out.println("accept??: ");
            TableTransferable dt = (TableTransferable) dropEvent.getTransferable();
            Table source = dt.getSourceComponent();
            System.out.println("accept??: " + source + " / " + this.source);
            return (source == this.source);
        }

        public void paint(PaintTarget target) throws PaintException {
            System.out.println("painting..??");
            target.startTag("-ac");
            target.addAttribute("name", getClass().getCanonicalName());
            target.endTag("-ac");
        }

        public void paintResponse(PaintTarget target) throws PaintException {
            System.out.println("paint response..??");
        }
    }

    public void generateLocalTable(String LocalPath) {

        FilesystemContainer lfs = new FilesystemContainer(new File(LocalPath));

        // jk: ok, i get this now. we need to separate the
        // filesystemcontainer from what is being displayed as the
        // filesystemcontainer-one would not allow us to add custom
        // things there that aren't part of the folder.

        // localt.setContainerDataSource(lfs);

        Table t = new Table();
        t.setContainerDataSource(lfs);
        localt.removeAllItems();

        for (Iterator<?> ii = t.getItemIds().iterator(); ii.hasNext();) {
            File f = (File) ii.next();
            String bfilename = f.getName();
            String bsize = "" + f.length();
            System.out.println("Eclipse: " + bfilename + " " + bsize);
            localt.addItem(new Object[] { bfilename, bsize }, f);
        }
    }

    /**
     * Gets a next free uploader thread, if there is one.
     * 
     * @return index of the thread in thread pool
     */
    public int getFreeUploaderIndex() {
        for (int i = 0; i < sicx_uploader.length; i++) {
            if (sicx_uploader[i] == null || sicx_uploader[i].isFinished()) {
                System.out.println("Thread " + i + " offered for use.");
                return i;
            }
        }
        System.out.println("Maximum number of parallell processes achieved.");
        return -1;
    }

    //private String databaseResult = null;
    /**
     * This class is used to call the status updated methods of background processes.
     * Refresher should call this with the interval specified.
     */
    public class DatabaseListener implements RefreshListener {
        private static final long serialVersionUID = -8765221895426102605L;

        /**
         * This function updates the upload progresses - if necessary.
         */
        @Override
        public void refresh(final Refresher source) {
            for (int i = 0; MAX_NUMBER_OF_CONCURRENT_UPLOADS > i; i++) {
                if (sicx_uploader[i] != null && sicx_uploader[i].isAlive() && !sicx_uploader[i].isFinished()
                        && (sicx_uploader[i].getRequestType().equals("download")
                                || sicx_uploader[i].getRequestType().equals("upload"))) {
                    sicx_uploader[i].updateProgress();
                }
            }
        }
    }

    public GUIComponent component;

    private static int MAX_NUMBER_OF_CONCURRENT_UPLOADS = 10;
    private SICXUploader[] sicx_uploader;
    //    private ProgressIndicator pi1;
    final Refresher refresher;

    private String getUploadProgressString(SICXUploader.UploaderState state, int progress, String operation,
            int availability) {

        String sumFieldText;
        switch (state) {
        default:
        case QUEUED:
        case IDLE:
        case INITIALIZING: {
            sumFieldText = "Preparing, " + progress + " % done";
            break;
        }
        case ACTIVE: {
            if (operation.equals("upload")) {
                sumFieldText = "Uploading, " + progress + " % done";
            } else if (operation.equals("download")) {
                sumFieldText = "Downloading, " + progress + " % done";
            } else {
                sumFieldText = "Now " + progress + " % done";
            }
            break;
        }
        case COMPLETE: {
            sumFieldText = "<font color=\"green\">" + availability + "%</font>";
            break;
        }
        case ERROR: {
            sumFieldText = "<font color=\"red\">File store failed</font>";
            break;
        }
        }

        return sumFieldText;
    }

    private String getAvailabilityString(int progress, int maxavailability) {

        // todo: different levels? is it necessary?
        if (progress >= maxavailability)
            return "<font color=\"green\">" + progress + "%</font>";
        else if (progress >= 100)
            return "<font color=\"orange\">" + progress + "%</font>";
        else if (progress > 0)
            return "<font color=\"red\">" + progress + "%</font>";
        else if (progress == 0)
            return "<font color=\"red\">0%</font>";
        else
            return "<font color=\"gray\"><i>Checking..</i></font>";
    }

    public synchronized void processed(SICXUploader sicxup) {

        SICXUploader.UploaderState state = sicxup.getUploadStatus();
        if (sicxup.getRequestType().equals("upload")) {
            Item item = servert.getItem(sicxup.getTargetFile());
            if (item != null) {
                String sumFieldText = getUploadProgressString(state, sicxup.getProgress(), "upload",
                        sicxup.getMaxAvailabilityPercentage());
                Label sumField = new Label(sumFieldText, Label.CONTENT_XHTML);
                item.getItemProperty("Availability").setValue(sumField);
                //System.out.println("upload processed called.");
                //String filename = source.getItem(sourceItemId).getItemProperty("Name").getValue().toString();
                if (state == SICXUploader.UploaderState.COMPLETE) {
                    guicomponent.notifyUser("File '" + sicxup.getFile().getName() + "' upload completed.",
                            Notification.TYPE_TRAY_NOTIFICATION);
                }
            }
        } else if (sicxup.getRequestType().equals("download")) {

            // todo: progress indication etc.. 
            if (state == SICXUploader.UploaderState.COMPLETE) {
                generateLocalTable(addressL.getValue().toString());
                //FilesystemContainer lfs = new FilesystemContainer(new File(addressL.getValue().toString()));
                //localt.setContainerDataSource(lfs);
                localt.setSelectable(true);
                localt.setImmediate(true);
                localt.setDragMode(TableDragMode.ROW);
                localt.setVisibleColumns(new Object[] { "Name", "Size" });
                guicomponent.notifyUser("File '" + sicxup.getFile().getName() + "' download completed.",
                        Notification.TYPE_TRAY_NOTIFICATION);
            } else {
                Item item = localt.getItem(sicxup.getTargetFile());
                if (item != null) {
                    String sumFieldText = getUploadProgressString(state, sicxup.getProgress(), "download", 100);
                    Label sumField = new Label(sumFieldText, Label.CONTENT_XHTML);
                    item.getItemProperty("Size").setValue(sumField);
                }
            }

        } else if (sicxup.getRequestType().equals("delete")) {
            if (state == SICXUploader.UploaderState.COMPLETE) {
                servert.removeItem(sicxup.getMetaFile());
                guicomponent.notifyUser("File '" + sicxup.getMetaFile().getName() + "' deleted.",
                        Notification.TYPE_TRAY_NOTIFICATION);
            }
        } else if (sicxup.getRequestType().equals("list") || sicxup.getRequestType().equals("parentlist")) {

            if (state == SICXUploader.UploaderState.INTERMEDIATE_RESULT) {
                // if metafile is null, then we have the listing
                MetaFile mf = sicxup.getTargetFile();
                if (mf == null) {
                    servert.removeAllItems();
                    List<MetaFile> listOfFiles = sicxup.getListOfFiles();
                    currentRemoteRoot = sicxup.getCurrentRoot();
                    //addressU.setInputPrompt(sicxup.getCurrentRootName());
                    addressU.setValue(sicxup.getCurrentRootName());

                    if (currentRemoteRoot != null) {
                        //&& currentRemoteRoot.getParent() != null) {
                        MetaFile dummy = new MetaFileImpl();
                        dummy.setName("..");
                        dummy.setDirectory(true);
                        servert.addItem(new Object[] { dummy.getName(), "", "", "" }, dummy);
                    }

                    for (MetaFile f : listOfFiles) {
                        // Label sumField = new Label("<font color=\"green\">100%</font>", Label.CONTENT_XHTML);
                        String avstr = getAvailabilityString(-1, sicxup.getMaxAvailabilityPercentage());
                        if (f.isDirectory())
                            avstr = "";
                        Label sumField = new Label(avstr, Label.CONTENT_XHTML);
                        SLA sla = f.getSLA();
                        servert.addItem(new Object[] { f.getName(), "" + f.getLength(),
                                (sla == null ? "N/A" : sla.getSLA()), sumField }, f);
                    }

                    // add the currently in-progress uploads:
                    for (SICXUploader su : sicx_uploader) {
                        if (su == null || su.isFinished() || !su.getRequestType().equals("upload"))
                            continue;

                        String sumFieldText = getUploadProgressString(sicxup.getUploadStatus(),
                                sicxup.getProgress(), "list", sicxup.getProgress());
                        Label sumField = new Label(sumFieldText, Label.CONTENT_XHTML);
                        servert.addItem(
                                new Object[] { sicxup.getFile().getName(), sicxup.getFile().length(),
                                        sicxup.getTargetFile().getSLA().getSLA(), sumField },
                                sicxup.getTargetFile());
                    }

                    guicomponent.notifyUser("File list refreshed, fetching availability..",
                            Notification.TYPE_TRAY_NOTIFICATION);
                } else {
                    Item item = servert.getItem(mf);
                    if (item != null) {
                        Label sumField = new Label(
                                getAvailabilityString(sicxup.getProgress(), sicxup.getMaxAvailabilityPercentage()),
                                Label.CONTENT_XHTML);
                        item.getItemProperty("Availability").setValue(sumField);
                    }
                }
                System.out.println("Listing done.");
                //databaseResult = "listing done";

            } else if (state == SICXUploader.UploaderState.COMPLETE) {
                guicomponent.notifyUser("File list refreshed successfully.", Notification.TYPE_TRAY_NOTIFICATION);

            } else if (state == SICXUploader.UploaderState.ERROR) {
                guicomponent.notifyUser("Unable to retrieve the list of files!",
                        Notification.TYPE_TRAY_NOTIFICATION);
            } else if (state == SICXUploader.UploaderState.ERROR_PATH) {
                guicomponent.notifyUser("The cloud path given was Invalid. Please check your spelling.",
                        Notification.TYPE_ERROR_MESSAGE);
            }
        }
    }

    @AutoGenerated
    private AbsoluteLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new AbsoluteLayout();
        mainLayout.setImmediate(false);
        mainLayout.setWidth("100%");
        mainLayout.setHeight("100%");
        mainLayout.setMargin(false);

        // top-level component properties
        setWidth("100.0%");
        setHeight("100.0%");

        // logoff
        logoff = new Button();
        logoff.setStyleName("BaseTheme.BUTTON_LINK");
        logoff.setCaption("logout");
        logoff.setImmediate(true);
        logoff.setWidth("-1px");
        logoff.setHeight("-1px");
        mainLayout.addComponent(logoff, "top:1.0px;right:5.0px;");

        // consoleSplit
        consoleSplit = buildConsoleSplit();
        mainLayout.addComponent(consoleSplit, "top:10.0px;right:10.0px;bottom:10.0px;left:10.0px;");

        return mainLayout;
    }

    @AutoGenerated
    private VerticalSplitPanel buildConsoleSplit() {
        // common part: create layout
        consoleSplit = new VerticalSplitPanel();
        consoleSplit.setImmediate(false);
        consoleSplit.setWidth("100.0%");
        consoleSplit.setHeight("100.0%");
        consoleSplit.setMargin(false);

        // HorizontalSplitPanel
        HorizontalSplitPanel = buildHorizontalSplitPanel();
        consoleSplit.addComponent(HorizontalSplitPanel);

        // consoleWindow
        consoleWindow = new TextArea();
        consoleWindow.setImmediate(false);
        consoleWindow.setWidth("100.0%");
        consoleWindow.setHeight("100.0%");
        consoleSplit.addComponent(consoleWindow);

        return consoleSplit;
    }

    @AutoGenerated
    private HorizontalSplitPanel buildHorizontalSplitPanel() {
        // common part: create layout
        HorizontalSplitPanel = new HorizontalSplitPanel();
        HorizontalSplitPanel.setImmediate(false);
        HorizontalSplitPanel.setWidth("100.0%");
        HorizontalSplitPanel.setHeight("100.0%");
        HorizontalSplitPanel.setMargin(false);

        // verticalL
        verticalL = buildVerticalL();
        HorizontalSplitPanel.addComponent(verticalL);

        // verticalU
        verticalU = buildVerticalU();
        HorizontalSplitPanel.addComponent(verticalU);

        return HorizontalSplitPanel;
    }

    @AutoGenerated
    private VerticalLayout buildVerticalL() {
        // common part: create layout
        verticalL = new VerticalLayout();
        verticalL.setImmediate(false);
        verticalL.setWidth("100.0%");
        verticalL.setHeight("100.0%");
        verticalL.setMargin(false);

        // buttonsL
        buttonsL = buildButtonsL();
        verticalL.addComponent(buttonsL);
        verticalL.setComponentAlignment(buttonsL, new Alignment(33));

        // addressL
        addressL = new TextField();
        addressL.setImmediate(false);
        addressL.setWidth("100.0%");
        addressL.setHeight("23px");
        addressL.setInputPrompt("C:/upload");
        //      addressL.setSecret(false);
        verticalL.addComponent(addressL);

        // localt
        localt = new Table();
        localt.setImmediate(false);
        localt.setWidth("100.0%");
        localt.setHeight("100.0%");
        verticalL.addComponent(localt);
        verticalL.setExpandRatio(localt, 1.0f);

        return verticalL;
    }

    @AutoGenerated
    private HorizontalLayout buildButtonsL() {
        // common part: create layout
        buttonsL = new HorizontalLayout();
        buttonsL.setImmediate(false);
        buttonsL.setWidth("100.0%");
        buttonsL.setHeight("30px");
        buttonsL.setMargin(false);

        // buttonsonlyL
        buttonsonlyL = buildButtonsonlyL();
        buttonsL.addComponent(buttonsonlyL);
        buttonsL.setComponentAlignment(buttonsonlyL, new Alignment(33));

        // labelL
        labelL = new Label();
        labelL.setImmediate(false);
        labelL.setWidth("-1px");
        labelL.setHeight("-1px");
        labelL.setValue("Local folder");
        buttonsL.addComponent(labelL);

        return buttonsL;
    }

    @AutoGenerated
    private HorizontalLayout buildButtonsonlyL() {
        // common part: create layout
        buttonsonlyL = new HorizontalLayout();
        buttonsonlyL.setImmediate(false);
        buttonsonlyL.setWidth("-1px");
        buttonsonlyL.setHeight("-1px");
        buttonsonlyL.setMargin(false);

        // reloadL
        reloadL = new Embedded();
        reloadL.setImmediate(false);
        reloadL.setWidth("-1px");
        reloadL.setHeight("-1px");
        reloadL.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/reload.png"));
        reloadL.setType(1);
        reloadL.setMimeType("image/png");
        buttonsonlyL.addComponent(reloadL);

        // newfolderL
        newfolderL = new Embedded();
        newfolderL.setImmediate(false);
        newfolderL.setWidth("-1px");
        newfolderL.setHeight("-1px");
        newfolderL.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/folder-add.png"));
        newfolderL.setType(1);
        newfolderL.setMimeType("image/png");
        buttonsonlyL.addComponent(newfolderL);

        // deleteL
        deleteL = new Embedded();
        deleteL.setImmediate(false);
        deleteL.setWidth("-1px");
        deleteL.setHeight("-1px");
        deleteL.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/trash.png"));
        deleteL.setType(1);
        deleteL.setMimeType("image/png");
        buttonsonlyL.addComponent(deleteL);

        // helpL
        helpL = new Embedded();
        helpL.setImmediate(false);
        helpL.setWidth("-1px");
        helpL.setHeight("-1px");
        helpL.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/help.png"));
        helpL.setType(1);
        helpL.setMimeType("image/png");
        buttonsonlyL.addComponent(helpL);

        return buttonsonlyL;
    }

    @AutoGenerated
    private VerticalLayout buildVerticalU() {
        // common part: create layout
        verticalU = new VerticalLayout();
        verticalU.setImmediate(false);
        verticalU.setWidth("100.0%");
        verticalU.setHeight("100.0%");
        verticalU.setMargin(false);

        // buttonsU
        buttonsU = buildButtonsU();
        verticalU.addComponent(buttonsU);
        verticalU.setComponentAlignment(buttonsU, new Alignment(33));

        // addressU
        addressU = new TextField();
        addressU.setImmediate(false);
        addressU.setWidth("100.0%");
        addressU.setHeight("23px");
        addressU.setInputPrompt("/private");
        //      addressU.setSecret(false);
        verticalU.addComponent(addressU);

        // servert
        servert = new Table();
        servert.setImmediate(false);
        servert.setWidth("100.0%");
        servert.setHeight("100.0%");
        verticalU.addComponent(servert);
        verticalU.setExpandRatio(servert, 1.0f);

        return verticalU;
    }

    @AutoGenerated
    private HorizontalLayout buildButtonsU() {
        // common part: create layout
        buttonsU = new HorizontalLayout();
        buttonsU.setImmediate(false);
        buttonsU.setWidth("100.0%");
        buttonsU.setHeight("30px");
        buttonsU.setMargin(false);

        // horizontalLayout_1
        horizontalLayout_1 = buildHorizontalLayout_1();
        buttonsU.addComponent(horizontalLayout_1);
        buttonsU.setComponentAlignment(horizontalLayout_1, new Alignment(33));

        // labelU
        labelU = new Label();
        labelU.setImmediate(false);
        labelU.setWidth("-1px");
        labelU.setHeight("-1px");
        labelU.setValue("SICX remote folder");
        buttonsU.addComponent(labelU);

        return buttonsU;
    }

    @AutoGenerated
    private HorizontalLayout buildHorizontalLayout_1() {
        // common part: create layout
        horizontalLayout_1 = new HorizontalLayout();
        horizontalLayout_1.setImmediate(false);
        horizontalLayout_1.setWidth("-1px");
        horizontalLayout_1.setHeight("-1px");
        horizontalLayout_1.setMargin(false);

        // reloadR
        reloadR = new Embedded();
        reloadR.setImmediate(false);
        reloadR.setWidth("-1px");
        reloadR.setHeight("-1px");
        reloadR.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/reload.png"));
        reloadR.setType(1);
        reloadR.setMimeType("image/png");
        horizontalLayout_1.addComponent(reloadR);

        // newfolderU
        newfolderU = new Embedded();
        newfolderU.setImmediate(false);
        newfolderU.setWidth("-1px");
        newfolderU.setHeight("-1px");
        newfolderU.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/folder-add.png"));
        newfolderU.setType(1);
        newfolderU.setMimeType("image/png");
        horizontalLayout_1.addComponent(newfolderU);

        // deleteU
        deleteU = new Embedded();
        deleteU.setImmediate(false);
        deleteU.setWidth("-1px");
        deleteU.setHeight("-1px");
        deleteU.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/trash.png"));
        deleteU.setType(1);
        deleteU.setMimeType("image/png");
        horizontalLayout_1.addComponent(deleteU);

        // helpU
        helpU = new Embedded();
        helpU.setImmediate(false);
        helpU.setWidth("-1px");
        helpU.setHeight("-1px");
        helpU.setSource(
                new ExternalResource("http://demo.vaadin.com/sampler/VAADIN/themes/runo/icons/32/help.png"));
        helpU.setType(1);
        helpU.setMimeType("image/png");
        horizontalLayout_1.addComponent(helpU);

        // SLAselector
        SLAselector = new ComboBox();
        SLAselector.setImmediate(false);
        SLAselector.setWidth("100px");
        SLAselector.setHeight("-1px");
        horizontalLayout_1.addComponent(SLAselector);

        return horizontalLayout_1;
    }

}