Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.ui;
import org.opencms.ade.galleries.CmsSiteSelectorOptionBuilder;
import org.opencms.ade.galleries.shared.CmsSiteSelectorOption;
import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsGroup;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsUser;
import org.opencms.file.types.A_CmsResourceTypeFolderBase;
import org.opencms.file.types.CmsResourceTypeXmlContent;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsMessages;
import org.opencms.i18n.I_CmsMessageBundle;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsOrganizationalUnit;
import org.opencms.security.CmsRole;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.ui.apps.CmsAppWorkplaceUi;
import org.opencms.ui.apps.Messages;
import org.opencms.ui.apps.user.CmsOUHandler;
import org.opencms.ui.components.OpenCmsTheme;
import org.opencms.ui.contextmenu.CmsContextMenu;
import org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsMacroResolver;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceMessages;
import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
import org.opencms.workplace.explorer.CmsResourceUtil;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.logging.Log;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.FontIcon;
import com.vaadin.server.Resource;
import com.vaadin.server.VaadinService;
import com.vaadin.shared.MouseEventDetails.MouseButton;
import com.vaadin.shared.Version;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.HasComponents;
import com.vaadin.ui.JavaScript;
import com.vaadin.ui.Panel;
import com.vaadin.ui.SingleComponentContainer;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
import com.vaadin.ui.declarative.Design;
import com.vaadin.ui.themes.ValoTheme;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.Container.Filter;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.event.ItemClickEvent;
import com.vaadin.v7.shared.ui.combobox.FilteringMode;
import com.vaadin.v7.ui.AbstractField;
import com.vaadin.v7.ui.ComboBox;
import com.vaadin.v7.ui.Label;
import com.vaadin.v7.ui.OptionGroup;
import com.vaadin.v7.ui.Table;
import com.vaadin.v7.ui.VerticalLayout;
/**
* Vaadin utility functions.
*
*/
@SuppressWarnings("deprecation")
public final class CmsVaadinUtils {
/**
* Helper class for building option groups.
*/
public static class OptionGroupBuilder {
/** The option group being built. */
private OptionGroup m_optionGroup = new OptionGroup();
/**
* Adds an option.
*
* @param key the option key
* @param text the option text
*
* @return this instance
*/
public OptionGroupBuilder add(String key, String text) {
m_optionGroup.addItem(key);
m_optionGroup.setItemCaption(key, text);
return this;
}
/**
* Returns the option group.
*
* @return the option group
*/
public OptionGroup build() {
return m_optionGroup;
}
/**
* Adds horizontal style to option group.
*
* @return this instance
*/
public OptionGroupBuilder horizontal() {
m_optionGroup.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
return this;
}
}
/** Container property ids. */
public static enum PropertyId {
/** The caption id. */
caption,
/** The icon id. */
icon,
/** The is folder id. */
isFolder,
/** The is XML content id. */
isXmlContent
}
/** Container filter for the resource type container to show not folder types only. */
public static final Filter FILTER_NO_FOLDERS = new Filter() {
private static final long serialVersionUID = 1L;
public boolean appliesToProperty(Object propertyId) {
return PropertyId.isFolder.equals(propertyId);
}
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
return !((Boolean)item.getItemProperty(PropertyId.isFolder).getValue()).booleanValue();
}
};
/** Container filter for the resource type container to show XML content types only. */
public static final Filter FILTER_XML_CONTENTS = new Filter() {
private static final long serialVersionUID = 1L;
public boolean appliesToProperty(Object propertyId) {
return PropertyId.isXmlContent.equals(propertyId);
}
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
return ((Boolean)item.getItemProperty(PropertyId.isXmlContent).getValue()).booleanValue();
}
};
/** The combo box label item property id. */
public static final String PROPERTY_LABEL = "label";
/** The combo box value item property id. */
public static final String PROPERTY_VALUE = "value";
/** The Vaadin bootstrap script, with some macros to be dynamically replaced later. */
protected static final String BOOTSTRAP_SCRIPT = "vaadin.initApplication(\"%(elementId)\", {\n"
+ " \"browserDetailsUrl\": \"%(vaadinServlet)\",\n"
+ " \"serviceUrl\": \"%(vaadinServlet)\",\n"
+ " \"widgetset\": \"org.opencms.ui.WidgetSet\",\n"
+ " \"theme\": \"opencms\",\n"
+ " \"versionInfo\": {\"vaadinVersion\": \"%(vaadinVersion)\"},\n"
+ " \"vaadinDir\": \"%(vaadinDir)\",\n"
+ " \"heartbeatInterval\": 30,\n"
+ " \"debug\": false,\n"
+ " \"standalone\": false,\n"
+ " \"authErrMsg\": {\n"
+ " \"message\": \"Take note of any unsaved data, \"+\n"
+ " \"and click here<\\/u> to continue.\",\n"
+ " \"caption\": \"Authentication problem\"\n"
+ " },\n"
+ " \"comErrMsg\": {\n"
+ " \"message\": \"Take note of any unsaved data, \"+\n"
+ " \"and click here<\\/u> to continue.\",\n"
+ " \"caption\": \"Communication problem\"\n"
+ " },\n"
+ " \"sessExpMsg\": {\n"
+ " \"message\": \"Take note of any unsaved data, \"+\n"
+ " \"and click here<\\/u> to continue.\",\n"
+ " \"caption\": \"Session Expired\"\n"
+ " }\n"
+ " });";
/** The logger of this class. */
private static final Log LOG = CmsLog.getLog(CmsVaadinUtils.class);
/**
* Hidden default constructor for utility class.
*/
private CmsVaadinUtils() {
}
/**
* Builds a container for use in combo boxes from a map of key/value pairs, where the keys are options and the values are captions.
*
* @param captionProperty the property name to use for captions
* @param map the map
* @return the new container
*/
public static IndexedContainer buildContainerFromMap(String captionProperty, Map map) {
IndexedContainer container = new IndexedContainer();
for (Map.Entry entry : map.entrySet()) {
container.addItem(entry.getKey()).getItemProperty(captionProperty).setValue(entry.getValue());
}
return container;
}
/**
* Centers the parent window of given component.
*
* @param component Component as child of window
*/
public static void centerWindow(Component component) {
Window window = getWindow(component);
if (window != null) {
window.center();
}
}
/**
* Closes the window containing the given component.
*
* @param component a component
*/
public static void closeWindow(Component component) {
Window window = getWindow(component);
if (window != null) {
window.close();
}
}
/**
* Creates a click listener which calls a Runnable when activated.
*
* @param action the Runnable to execute on a click
*
* @return the click listener
*/
public static Button.ClickListener createClickListener(final Runnable action) {
return new Button.ClickListener() {
/** Serial version id. */
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
action.run();
}
};
}
/**
* Simple context menu handler for multi-select tables.
*
* @param table the table
* @param menu the table's context menu
* @param event the click event
* @param entries the context menu entries
*/
@SuppressWarnings("unchecked")
public static void defaultHandleContextMenuForMultiselect(
Table table,
CmsContextMenu menu,
ItemClickEvent event,
List>> entries) {
if (!event.isCtrlKey() && !event.isShiftKey()) {
if (event.getButton().equals(MouseButton.RIGHT)) {
Collection oldValue = ((Collection)table.getValue());
if (oldValue.isEmpty() || !oldValue.contains(event.getItemId())) {
table.setValue(new HashSet