/*
- * Copyright (c) 2011 Greek Research and Technology Network
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
*/
package gr.grnet.pithos.web.client;
-import gr.grnet.pithos.web.client.rest.GetCommand;
-import gr.grnet.pithos.web.client.rest.RestException;
-import gr.grnet.pithos.web.client.rest.resource.QuotaHolder;
-import gr.grnet.pithos.web.client.rest.resource.UserResource;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.i18n.client.DateTimeFormat;
-import com.google.gwt.resources.client.ClientBundle;
-import com.google.gwt.resources.client.ImageResource;
-import com.google.gwt.user.client.DeferredCommand;
-import com.google.gwt.user.client.IncrementalCommand;
-import com.google.gwt.user.client.ui.AbstractImagePrototype;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.HasHorizontalAlignment;
-import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.i18n.client.Dictionary;
+import com.google.gwt.user.client.ui.*;
/**
* The panel that displays a status bar with quota information.
*/
public class StatusPanel extends Composite {
- public static final boolean DONE = false;
- private HTML fileCountLabel = new HTML("");
- private HTML fileSizeLabel = new HTML("");
- private HTML quotaIcon = new HTML("");
- private HTML quotaLabel = new HTML("");
- private HTML lastLoginLabel = new HTML("");
- private HTML currentLoginLabel = new HTML("");
- private HTML currentlyShowingLabel = new HTML("");
-
- /**
- * An image bundle for this widget's images.
- */
- public interface Images extends ClientBundle {
-
- @Source("gr/grnet/pithos/resources/windowlist.png")
- ImageResource totalFiles();
-
- @Source("gr/grnet/pithos/resources/database.png")
- ImageResource totalSize();
-
- @Source("gr/grnet/pithos/resources/redled.png")
- ImageResource redSize();
-
- @Source("gr/grnet/pithos/resources/greenled.png")
- ImageResource greenSize();
-
- @Source("gr/grnet/pithos/resources/yellowled.png")
- ImageResource yellowSize();
-
- @Source("gr/grnet/pithos/resources/xclock.png")
- ImageResource lastLogin();
- }
-
- private final Images images;
-
- /**
- * The constructor of the status panel.
- *
- * @param theImages the supplied images
- */
- public StatusPanel(Images theImages) {
- images = theImages;
- HorizontalPanel outer = new HorizontalPanel();
- outer.setWidth("100%");
- outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
-
- HorizontalPanel left = new HorizontalPanel();
- left.setSpacing(8);
- HorizontalPanel middle = new HorizontalPanel();
- middle.setSpacing(8);
- HorizontalPanel right = new HorizontalPanel();
- right.setSpacing(8);
- outer.add(left);
- outer.add(middle);
- outer.add(right);
- left.add(new HTML("<b>Totals:</b> "));
- left.add(AbstractImagePrototype.create(images.totalFiles()).createImage());
- left.add(fileCountLabel);
- left.add(AbstractImagePrototype.create(images.totalSize()).createImage());
- left.add(fileSizeLabel);
- quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
- left.add(quotaIcon);
- left.add(quotaLabel);
- middle.add(AbstractImagePrototype.create(images.lastLogin()).createImage());
- middle.add(new HTML("<b>Last login:</b> "));
- middle.add(lastLoginLabel);
- middle.add(new HTML("<b>\u0387 Current session login:</b> "));
- middle.add(currentLoginLabel);
- right.add(currentlyShowingLabel);
- outer.setStyleName("statusbar-inner");
- left.setStyleName("statusbar-inner");
- middle.setStyleName("statusbar-inner");
- right.setStyleName("statusbar-inner");
- outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT);
-
- initWidget(outer);
-
- // Initialize and display the quota information.
- DeferredCommand.addCommand(new IncrementalCommand() {
- @Override
- public boolean execute() {
- GSS app = GSS.get();
- UserResource user = app.getCurrentUserResource();
- if (user == null || app.getTreeView().getMyFolders() == null)
- return !DONE;
- displayStats(user);
- return DONE;
- }
- });
- }
-
- /**
- * Refresh the widget with the provided statistics.
- */
- private void displayStats(UserResource user) {
- QuotaHolder stats = user.getQuota();
- if (stats.getFileCount() == 1)
- fileCountLabel.setHTML("1 file");
- else
- fileCountLabel.setHTML(stats.getFileCount() + " files");
- fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
- long pc = stats.percentOfFreeSpace();
- if(pc<10) {
- quotaIcon.setHTML(AbstractImagePrototype.create(images.redSize()).getHTML());
- quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
- } else if(pc<20) {
- quotaIcon.setHTML(AbstractImagePrototype.create(images.yellowSize()).getHTML());
- quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
- } else {
- quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
- quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
- }
- final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
- lastLoginLabel.setHTML(formatter.format(user.getLastLogin()));
- currentLoginLabel.setHTML(formatter.format(user.getCurrentLogin()));
- }
-
- /**
- * Requests updated quota information from the server and refreshes
- * the display.
- */
- public void updateStats() {
- final GSS app = GSS.get();
- UserResource user = app.getCurrentUserResource();
- GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri(), null){
- @Override
- public void onComplete() {
- displayStats(getResult());
- }
-
- @Override
- public void onError(Throwable t) {
- if(t instanceof RestException)
- app.displayError("Unable to fetch quota:" +
- ((RestException)t).getHttpStatusText());
- else
- app.displayError("System error fetching quota:" +
- t.getMessage());
- GWT.log("ERR", t);
- }
- };
- DeferredCommand.addCommand(uc);
- }
-
- /**
- * Displays the statistics for the current folder.
- *
- * @param text the statistics to display
- */
- public void updateCurrentlyShowing(String text) {
- if (text == null)
- currentlyShowingLabel.setText("");
- else
- currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);
- }
+ /**
+ * The constructor of the status panel.
+ */
+ public StatusPanel() {
+ Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
+ final String COMPANY_URL = otherProperties.get("COMPANY_URL");
+ final String COPYRIGHT_MESSAGE = otherProperties.get("COPYRIGHT_MESSAGE");
+ final String SYNNEFO_VERSION = otherProperties.get("SYNNEFO_VERSION");
+
+ HorizontalPanel outer = new HorizontalPanel();
+ outer.setWidth("100%");
+ outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
+
+ VerticalPanel inner = new VerticalPanel();
+ inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
+ HorizontalPanel firstLine = new HorizontalPanel();
+ firstLine.setSpacing(8);
+ firstLine.add(new HTML("<a class='grnet-sign' href='" + COMPANY_URL + "'>" + COPYRIGHT_MESSAGE + "</a>"));
+ inner.add(firstLine);
+
+ HorizontalPanel secondLine = new HorizontalPanel();
+ secondLine.add(new HTML(
+ "<div class='software'>" +
+ "Powered by <a href='http://synnefo.orgs'>Synnefo</a>" +
+ "<span class='version'> v" + SYNNEFO_VERSION + "</span>" +
+ "</div>"));
+// secondLine.addStyleName("software");
+ inner.add(secondLine);
+ outer.add(inner);
+ outer.addStyleName("pithos-statusbar");
+
+ initWidget(outer);
+ }
}