001package gwt.material.design.addins.client.fileuploader;
002
003/*
004 * #%L
005 * GwtMaterial
006 * %%
007 * Copyright (C) 2015 - 2016 GwtMaterialDesign
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024import com.google.gwt.dom.client.Document;
025import com.google.gwt.dom.client.Style;
026import gwt.material.design.client.base.MaterialWidget;
027import gwt.material.design.client.constants.ButtonType;
028import gwt.material.design.client.constants.IconType;
029import gwt.material.design.client.constants.ProgressType;
030import gwt.material.design.client.constants.WavesType;
031import gwt.material.design.client.ui.*;
032import gwt.material.design.client.ui.html.Span;
033
034public class MaterialUploadCollection extends MaterialCollection {
035
036    private MaterialCollectionItem item = new MaterialCollectionItem();
037    private MaterialWidget dropInfo = new MaterialWidget(Document.get().createDivElement());
038    private MaterialWidget nameWrapper = new MaterialWidget(Document.get().createDivElement());
039    private MaterialWidget errorWrapper = new MaterialWidget(Document.get().createDivElement());
040    private Span name = new Span();
041    private Span size = new Span();
042    private Span errorMessage = new Span();
043    private MaterialCollectionSecondary secondaryAction = new MaterialCollectionSecondary();
044    private MaterialButton btnClear = new MaterialButton(ButtonType.FLOATING);
045    private MaterialIcon previewIcon = new MaterialIcon(IconType.INSERT_DRIVE_FILE);
046
047    private MaterialProgress progress = new MaterialProgress();
048
049    public MaterialUploadCollection() {
050        // Element property
051        setStyleName("previews");
052        addStyleName("card");
053
054        // Collection Item property that contain the upload info, progress bar and action panel
055        item.setId("zdrop-template");
056        item.addStyleName("clearhack valign-wrapper item-template");
057        add(item);
058
059        // Upload Information
060        dropInfo.addStyleName("left pv zdrop-info");
061        dropInfo.setDataAttribute("data-dz-thumbnail", "");
062        item.add(dropInfo);
063
064        // Upload Information - Upload Name info
065        nameWrapper.add(name);
066        name.setTruncate(true);
067        name.setWidth("200px");
068        name.setDataAttribute("data-dz-name", "");
069        nameWrapper.add(size);
070        size.setDataAttribute("data-dz-size", "");
071        dropInfo.add(nameWrapper);
072
073        previewIcon.setFloat(Style.Float.LEFT);
074        previewIcon.addStyleName("preview-icon");
075        dropInfo.add(previewIcon);
076
077        // Upload Information - Progress bar indication of upload queues
078        progress.setType(ProgressType.DETERMINATE);
079        progress.getWidget(0).getElement().setAttribute("data-dz-uploadprogress", "");
080        progress.setPercent(0);
081        dropInfo.add(progress);
082
083        // Upload Information - Error message
084        errorWrapper.setStyleName("dz-error-message");
085        errorMessage.setDataAttribute("data-dz-errormessage", "");
086        errorMessage.setId("error-message");
087        errorWrapper.add(errorMessage);
088        dropInfo.add(errorWrapper);
089
090        // Secondary Action Panel
091        btnClear.setId("dz-remove");
092        btnClear.setBackgroundColor("transparent");
093        btnClear.setShadow(0);
094        btnClear.setCircle(true);
095        btnClear.setTextColor("white");
096        btnClear.addStyleName("ph");
097        btnClear.setIconType(IconType.CLEAR);
098        btnClear.setDataAttribute("data-dz-remove", "");
099        secondaryAction.add(btnClear);
100        item.add(secondaryAction);
101    }
102
103    public MaterialCollectionItem getItem() {
104        return item;
105    }
106}