001package gwt.material.design.addins.client.docviewer; 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 gwt.material.design.client.base.MaterialWidget; 026 027//@formatter:off 028/** 029 * A document viewer for your word, excel, powerpoint, pdf and other <a href='http://wiki.mobileread.com/wiki/Google_Docs_Viewer'></a> supported 030 * file types </a>. <br/> 031 * Note that this viewer only work with public files. 032 * 033 * <h3>XML Namespace Declaration</h3> 034 * <pre> 035 * {@code 036 * xmlns:ma='urn:import:gwt.material.design.addins.client' 037 * } 038 * </pre> 039 * 040 * <h3>UiBinder Usage:</h3> 041 * <pre> 042 * {@code 043 * <ma:docviewer.MaterialDocViewer url="http://infolab.stanford.edu/pub/papers/google.pdf" embedded="true"/> 044 * } 045 * </pre> 046 * 047 * @author kevzlou7979 048 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#docviewer">Doc Viewer</a> 049 */ 050//@formatter:on 051public class MaterialDocViewer extends MaterialWidget { 052 053 private String url; 054 private boolean embedded = true; 055 056 public MaterialDocViewer() { 057 super(Document.get().createIFrameElement()); 058 } 059 060 @Override 061 protected void onLoad() { 062 super.onLoad(); 063 getElement().setAttribute("src", "http://docs.google.com/gview?url=" + url + "&embedded=" + embedded); 064 } 065 066 /** 067 * Get the url of the Iframe component 068 * @return 069 */ 070 public String getUrl() { 071 return url; 072 } 073 074 /** 075 * Set the url of the public document 076 * @param url 077 */ 078 public void setUrl(String url) { 079 this.url = url; 080 } 081 082 /** 083 * Check whether the iframe is embedded or not 084 * @return 085 */ 086 public boolean isEmbedded() { 087 return embedded; 088 } 089 090 /** 091 * Set the emebedded value of the iframe 092 * @param embedded 093 */ 094 public void setEmbedded(boolean embedded) { 095 this.embedded = embedded; 096 } 097}