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.apps.resourcetypes; 029 030import org.opencms.loader.CmsLoaderException; 031import org.opencms.main.OpenCms; 032import org.opencms.ui.A_CmsUI; 033import org.opencms.ui.CmsVaadinUtils; 034import org.opencms.ui.FontOpenCms; 035import org.opencms.ui.apps.A_CmsWorkplaceApp; 036import org.opencms.ui.apps.I_CmsAppUIContext; 037import org.opencms.ui.apps.Messages; 038import org.opencms.ui.components.CmsBasicDialog; 039import org.opencms.ui.components.CmsBasicDialog.DialogWidth; 040import org.opencms.ui.components.CmsToolBar; 041import org.opencms.util.CmsStringUtil; 042 043import java.util.LinkedHashMap; 044import java.util.List; 045 046import com.vaadin.ui.Button; 047import com.vaadin.ui.Button.ClickEvent; 048import com.vaadin.ui.Button.ClickListener; 049import com.vaadin.ui.Component; 050import com.vaadin.ui.UI; 051import com.vaadin.ui.Window; 052import com.vaadin.ui.themes.ValoTheme; 053import com.vaadin.v7.event.FieldEvents.TextChangeEvent; 054import com.vaadin.v7.event.FieldEvents.TextChangeListener; 055import com.vaadin.v7.ui.TextField; 056 057/** 058 * App to manage the resource types.<p> 059 */ 060public class CmsResourceTypeApp extends A_CmsWorkplaceApp { 061 062 /** Filter for the table.*/ 063 private TextField m_resourcetypeTableFilter; 064 065 /** Table holding available resource types.*/ 066 private CmsResourceTypesTable m_table; 067 068 /** Is the given resource type id free? 069 * @param id to be checked 070 * @return boolean 071 */ 072 public static boolean isResourceTypeIdFree(int id) { 073 074 try { 075 OpenCms.getResourceManager().getResourceType(id); 076 } catch (CmsLoaderException e) { 077 return true; 078 } 079 return false; 080 } 081 082 /** 083 * Is resource type name free.<p> 084 * 085 * @param name to be checked 086 * @return boolean 087 */ 088 public static boolean isResourceTypeNameFree(String name) { 089 090 try { 091 OpenCms.getResourceManager().getResourceType(name); 092 } catch (CmsLoaderException e) { 093 return true; 094 } 095 return false; 096 } 097 098 /** 099 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#initUI(org.opencms.ui.apps.I_CmsAppUIContext) 100 */ 101 @Override 102 public void initUI(I_CmsAppUIContext context) { 103 104 context.addPublishButton(changes -> {}); 105 super.initUI(context); 106 } 107 108 /** 109 * Reloads the table.<p> 110 */ 111 public void reload() { 112 113 m_table.init(); 114 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(m_resourcetypeTableFilter.getValue())) { 115 m_table.filterTable(m_resourcetypeTableFilter.getValue()); 116 } 117 } 118 119 /** 120 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getBreadCrumbForState(java.lang.String) 121 */ 122 @Override 123 protected LinkedHashMap<String, String> getBreadCrumbForState(String state) { 124 125 return null; 126 } 127 128 /** 129 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getComponentForState(java.lang.String) 130 */ 131 @Override 132 protected Component getComponentForState(String state) { 133 134 addToolbarButtons(); 135 136 m_table = new CmsResourceTypesTable(this); 137 m_resourcetypeTableFilter = new TextField(); 138 m_resourcetypeTableFilter.setIcon(FontOpenCms.FILTER); 139 m_resourcetypeTableFilter.setInputPrompt( 140 Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_FILTER_0)); 141 m_resourcetypeTableFilter.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON); 142 m_resourcetypeTableFilter.setWidth("200px"); 143 m_resourcetypeTableFilter.addTextChangeListener(new TextChangeListener() { 144 145 private static final long serialVersionUID = 1L; 146 147 public void textChange(TextChangeEvent event) { 148 149 m_table.filterTable(event.getText()); 150 } 151 }); 152 m_infoLayout.addComponent(m_resourcetypeTableFilter); 153 m_rootLayout.setMainHeightFull(true); 154 return m_table; 155 } 156 157 /** 158 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getSubNavEntries(java.lang.String) 159 */ 160 @Override 161 protected List<NavEntry> getSubNavEntries(String state) { 162 163 return null; 164 } 165 166 /** 167 * Adds the buttons to the toolbar.<p> 168 */ 169 private void addToolbarButtons() { 170 171 Button add = CmsToolBar.createButton( 172 FontOpenCms.WAND, 173 CmsVaadinUtils.getMessageText(Messages.GUI_RESOURCETYPE_CREATE_NEW_TYPE_0)); 174 add.addClickListener(new ClickListener() { 175 176 private static final long serialVersionUID = 1L; 177 178 public void buttonClick(ClickEvent event) { 179 180 Window window = CmsBasicDialog.prepareWindow(DialogWidth.max); 181 CmsNewResourceTypeDialog dialog = new CmsNewResourceTypeDialog(window, CmsResourceTypeApp.this); 182 CmsMoveResourceTypeDialog moduleDialog = new CmsMoveResourceTypeDialog(dialog); 183 window.setContent(moduleDialog); 184 window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_RESOURCETYPE_CREATE_NEW_TYPE_0)); 185 A_CmsUI.get().addWindow(window); 186 } 187 }); 188 m_uiContext.addToolbarButton(add); 189 190 } 191}