X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/633669253249bdd90fc1dd0f78bfcdcfb674c320..6433a00d9394dc98725123bef5e75d21b3c7444f:/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java diff --git a/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java b/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java index bb3313a..e4fcc48 100644 --- a/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java +++ b/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 GRNET S.A. All rights reserved. + * Copyright 2011-2012 GRNET S.A. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following @@ -35,91 +35,194 @@ package gr.grnet.pithos.web.client.foldertree; -import com.google.gwt.cell.client.AbstractCell; +import gr.grnet.pithos.web.client.FolderContextMenu; +import gr.grnet.pithos.web.client.Pithos; +import gr.grnet.pithos.web.client.PithosDisclosurePanel; +import gr.grnet.pithos.web.client.TreeView; + import com.google.gwt.core.client.GWT; -import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.resources.client.ImageResource; import com.google.gwt.resources.client.ImageResource.ImageOptions; +import com.google.gwt.resources.client.ImageResource.RepeatStyle; import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.cellview.client.CellTree; import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.ui.AbstractImagePrototype; +import com.google.gwt.user.cellview.client.TreeNode; +import com.google.gwt.user.client.Command; 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.user.client.ui.Tree; -import gr.grnet.pithos.web.client.FolderContextMenu; +import com.google.gwt.user.client.ui.VerticalPanel; + +public class FolderTreeView extends Composite implements TreeView { + + public boolean isFolderOpen(Folder folder) { + TreeNode root = ((CellTree) getWidget()).getRootTreeNode(); + return isFolderOpen(root, folder); + } + + private boolean isFolderOpen(TreeNode node, Folder folder) { + for (int i=0; i{0}") + @Template("{0}") public SafeHtml nameSpan(String name); - } - - static class FolderCell extends AbstractCell { - @Override - public void render(Context context, Folder folder, SafeHtmlBuilder safeHtmlBuilder) { - String html = AbstractImagePrototype.create(images.folderYellow()).getHTML(); - safeHtmlBuilder.appendHtmlConstant(html); - safeHtmlBuilder.append(Templates.INSTANCE.nameSpan(folder.getName())); - } + @Template("{0}") + public SafeHtml imageSpan(String name); } + interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources { + @Override + @Source("gr/grnet/pithos/resources/home22.png") + ImageResource icon(); + } private FolderTreeViewModel model; + + private CellTree tree; + + private HTML usedBytes; + + private HTML totalBytes; + + private HTML usedPercent; public FolderTreeView(FolderTreeViewModel viewModel) { this.model = viewModel; + + PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "My Files", true); + + VerticalPanel content = new VerticalPanel(); + /* * Create the tree using the model. We use null as the default * value of the root node. The default value will be passed to * CustomTreeModel#getNodeInfo(); */ CellTree.Resources res = GWT.create(BasicResources.class); - CellTree tree = new CellTree(model, null, res); - + tree = new CellTree(model, null, res); tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); - - sinkEvents(Event.ONCONTEXTMENU); - sinkEvents(Event.ONMOUSEUP); - initWidget(tree); + content.add(tree); + + HorizontalPanel statistics = new HorizontalPanel(); + statistics.addStyleName(Pithos.resources.pithosCss().statistics()); + statistics.add(new HTML("Used: ")); + usedBytes = new HTML(); + statistics.add(usedBytes); + statistics.add(new HTML(" of ")); + totalBytes = new HTML(); + statistics.add(totalBytes); + statistics.add(new HTML(" (")); + usedPercent = new HTML(); + statistics.add(usedPercent); + statistics.add(new HTML(")")); + content.add(statistics); + content.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_CENTER); + + panel.setContent(content); + initWidget(panel); } - public Folder getSelection() { + + @Override + public Folder getSelection() { return model.getSelection(); } + + public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) { + model.updateFolder(folder, showfiles, callback, openParent); + } + + public void showStatistics(AccountResource account) { + usedBytes.setHTML(String.valueOf(account.getFileSizeAsString())); + totalBytes.setHTML(String.valueOf(account.getQuotaAsString())); + NumberFormat nf = NumberFormat.getPercentFormat(); + usedPercent.setHTML(nf.format(account.getUsedPercentage())); + } }