001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.dialogs.history.diff; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.history.CmsHistoryResourceHandler; 032import org.opencms.gwt.shared.CmsHistoryResourceBean; 033import org.opencms.main.OpenCms; 034import org.opencms.ui.A_CmsUI; 035import org.opencms.ui.CmsVaadinUtils; 036import org.opencms.ui.Messages; 037import org.opencms.ui.dialogs.history.CmsHistoryRow; 038import org.opencms.workplace.comparison.CmsHistoryListUtil; 039 040import com.google.common.base.Optional; 041import com.vaadin.ui.Alignment; 042import com.vaadin.ui.Button; 043import com.vaadin.ui.Button.ClickEvent; 044import com.vaadin.ui.Button.ClickListener; 045import com.vaadin.ui.Component; 046import com.vaadin.v7.ui.HorizontalLayout; 047import com.vaadin.ui.Panel; 048import com.vaadin.v7.ui.VerticalLayout; 049import com.vaadin.ui.themes.ValoTheme; 050 051/** 052 * Provides buttons for showing the two versions being compared.<p> 053 * 054 */ 055public class CmsShowVersionButtons implements I_CmsDiffProvider { 056 057 /** 058 * Creates a 'show version' button.<p> 059 * 060 * @param cms the CMS context to use 061 * @param version the version 062 * 063 * @return the new button 064 */ 065 public Button createButton(final CmsObject cms, final CmsHistoryResourceBean version) { 066 067 String label = CmsVaadinUtils.getMessageText( 068 Messages.GUI_HISTORY_DIALOG_SHOW_VERSION_BUTTON_1, 069 CmsHistoryRow.formatVersion(version)); 070 Button result = new Button(label); 071 result.addClickListener(new ClickListener() { 072 073 private static final long serialVersionUID = 1L; 074 075 public void buttonClick(ClickEvent event) { 076 077 String v1Param = version.getVersion().getVersionNumber() != null 078 ? "" + version.getVersion().getVersionNumber() 079 : "" + CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION; 080 String link = CmsHistoryListUtil.getHistoryLink(cms, version.getStructureId(), v1Param); 081 link = OpenCms.getLinkManager().substituteLinkForUnknownTarget(cms, link); 082 A_CmsUI.get().openPageOrWarn(link, "_blank"); 083 } 084 085 }); 086 return result; 087 } 088 089 /** 090 * @see org.opencms.ui.dialogs.history.diff.I_CmsDiffProvider#diff(org.opencms.file.CmsObject, org.opencms.gwt.shared.CmsHistoryResourceBean, org.opencms.gwt.shared.CmsHistoryResourceBean) 091 */ 092 public Optional<Component> diff(CmsObject cms, CmsHistoryResourceBean v1, CmsHistoryResourceBean v2) { 093 094 Panel panel = new Panel(""); 095 panel.addStyleName(ValoTheme.PANEL_BORDERLESS); 096 HorizontalLayout hl = new HorizontalLayout(); 097 panel.setContent(hl); 098 hl.addComponent(createButton(cms, v1)); 099 hl.addComponent(createButton(cms, v2)); 100 VerticalLayout outerContainer = new VerticalLayout(); 101 outerContainer.addComponent(hl); 102 outerContainer.setComponentAlignment(hl, Alignment.MIDDLE_RIGHT); 103 outerContainer.setMargin(true); 104 hl.setSpacing(true); 105 return Optional.fromNullable((Component)outerContainer); 106 } 107 108}