Skip to content

Commit

Permalink
Added start view preference.
Browse files Browse the repository at this point in the history
  • Loading branch information
gWestenberger committed Apr 5, 2016
1 parent 11ce9b0 commit eb84a4d
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 46 deletions.
102 changes: 60 additions & 42 deletions src-modules/org/opencms/workplace/commons/CmsPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.opencms.security.CmsPasswordInfo;
import org.opencms.site.CmsSite;
import org.opencms.synchronize.CmsSynchronizeSettings;
import org.opencms.util.CmsMacroResolver;
import org.opencms.util.CmsStringUtil;
import org.opencms.widgets.CmsCalendarWidget;
import org.opencms.workplace.CmsTabDialog;
Expand Down Expand Up @@ -539,6 +540,63 @@ public static SelectOptions getSiteSelectOptionsStatic(CmsObject cms, String wpS
return selectOptions;
}

/**
* Gets the select options for the view selector.<p>
*
* @param cms the CMS context
* @param value the current value
* @return the select options
*/
public static SelectOptions getViewSelectOptions(CmsObject cms, String value) {

Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);

List<String> options = new ArrayList<String>();
List<String> values = new ArrayList<String>();
int selectedIndex = 0;

// loop through the vectors and fill the result vectors
List<CmsWorkplaceView> list = new ArrayList<CmsWorkplaceView>(OpenCms.getWorkplaceManager().getViews());
CmsWorkplaceView directEditView = new CmsWorkplaceView(
Messages.get().getBundle(locale).key(Messages.GUI_LABEL_DIRECT_EDIT_VIEW_0),
CmsWorkplace.VIEW_DIRECT_EDIT,
Float.valueOf(100));
list.add(directEditView);

Iterator<CmsWorkplaceView> i = list.iterator();
int count = -1;
while (i.hasNext()) {
count++;
CmsWorkplaceView view = i.next();

boolean visible = true;

try {
cms.readResource(view.getUri());
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
visible = false;
}

if (visible) {
CmsMacroResolver resolver = new CmsMacroResolver();
resolver.setCmsObject(cms);
resolver.setMessages(OpenCms.getWorkplaceManager().getMessages(locale));
String localizedKey = resolver.resolveMacros(view.getKey());
options.add(localizedKey);
values.add(view.getUri());
if (view.getUri().equals(value)) {
selectedIndex = count;
}
}
}
SelectOptions optionBean = new SelectOptions(options, values, selectedIndex);
return optionBean;
}

/**
* Performs the change password action.<p>
*
Expand Down Expand Up @@ -1073,48 +1131,8 @@ public String buildSelectUpload(String htmlAttributes) {
*/
public String buildSelectView(String htmlAttributes) {

List<String> options = new ArrayList<String>();
List<String> values = new ArrayList<String>();
int selectedIndex = 0;

// loop through the vectors and fill the result vectors
List<CmsWorkplaceView> list = new ArrayList<CmsWorkplaceView>(OpenCms.getWorkplaceManager().getViews());
CmsWorkplaceView directEditView = new CmsWorkplaceView(
Messages.get().getBundle(getLocale()).key(Messages.GUI_LABEL_DIRECT_EDIT_VIEW_0),
CmsWorkplace.VIEW_DIRECT_EDIT,
Float.valueOf(100));
list.add(directEditView);

Iterator<CmsWorkplaceView> i = list.iterator();
int count = -1;
while (i.hasNext()) {
count++;
CmsWorkplaceView view = i.next();

boolean visible = true;

try {
getCms().readResource(view.getUri());
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
visible = false;
}

if (visible) {
String localizedKey = resolveMacros(view.getKey());
options.add(localizedKey);
values.add(view.getUri());
if (view.getUri().equals(getParamTabWpView())) {
selectedIndex = count;
}
}
}
return

buildSelect(htmlAttributes, options, values, selectedIndex);
SelectOptions optionBean = getViewSelectOptions(getCms(), getParamTabWpView());
return buildSelect(htmlAttributes, optionBean);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH (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.configuration.preferences;

import org.opencms.file.CmsObject;
import org.opencms.workplace.commons.CmsPreferences;
import org.opencms.xml.content.CmsXmlContentProperty;

/**
* Preference for the start site.<p>
*/
public class CmsStartViewPreference extends CmsBuiltinPreference {

/** The nice name. */
private static final String NICE_NAME = "%(key."
+ org.opencms.workplace.commons.Messages.GUI_PREF_STARTUP_VIEW_0
+ ")";

/**
* Creates a new instance.<p>
*
* @param name the preference name
*/
public CmsStartViewPreference(String name) {

super(name);
}

/**
* @see org.opencms.configuration.preferences.CmsBuiltinPreference#getPropertyDefinition(org.opencms.file.CmsObject)
*/
@Override
public CmsXmlContentProperty getPropertyDefinition() {

CmsXmlContentProperty prop = new CmsXmlContentProperty(
getName(), //name
"string", //type
null, //widget
null, //widgetconfig
null, //regex
null, //ruletype
null, //default
NICE_NAME, //nicename
null, //description
null, //error
null//preferfolder
);
return prop;
}

/**
* @see org.opencms.configuration.preferences.CmsBuiltinPreference#getPropertyDefinition(org.opencms.file.CmsObject)
*/
@Override
public CmsXmlContentProperty getPropertyDefinition(CmsObject cms) {

String options = CmsPreferences.getViewSelectOptions(cms, null).toClientSelectWidgetConfiguration();
CmsXmlContentProperty prop = new CmsXmlContentProperty(
getName(), //name
"string", //type
"select_notnull", //widget
options, //widgetconfig
null, //regex
null, //ruletype
null, //default
NICE_NAME, //nicename
null, //description
null, //error
null//preferfolder
);
return prop;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ public String getStartSite() {
*
* @return the start view
*/
@PrefMetadata(type = CmsStartViewPreference.class)
public String getStartView() {

return m_settings.getStartView();
Expand Down
2 changes: 1 addition & 1 deletion test/org/opencms/configuration/opencms-workplace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@
<preference name="showUploadTypeDialog" value="true"
widget="checkbox" />
<preference name="startView"
value="/system/workplace/views/explorer/directEdit.jsp" />
value="/system/workplace/views/explorer/directEdit.jsp" nice-name="%(key.GUI_PREF_STARTUP_VIEW_0)" />
<preference name="uploadVariant" value="gwt" widget="select"
widget-config="basic:%(key.GUI_PREF_USE_UPLOAD_BASIC_0)|gwt:%(key.GUI_PREF_USE_UPLOAD_GWT_0)" />
<preference name="workplaceReportType" value="extended" />
Expand Down
6 changes: 3 additions & 3 deletions webapp/WEB-INF/config/opencms-workplace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,9 @@
<preference name="startSite" value="/sites/default/"
nice-name="%(key.GUI_PREF_STARTUP_SITE_0)" />
<preference name="startFolder" value="/"
nice-name="%(key.GUI_PREF_STARTUP_FOLDER_0)" />
nice-name="%(key.GUI_PREF_STARTUP_FOLDER_0)" />
<preference name="startView"
value="/system/workplace/views/explorer/explorer_fs.jsp" />
<preference name="timeWarp" value="0"
nice-name="%(key.GUI_LABEL_TIMEWARP_0)" widget="datebox" />
</preference-tab>
Expand Down Expand Up @@ -1727,8 +1729,6 @@
widget="checkbox" />
<preference name="showUploadTypeDialog" value="true"
widget="checkbox" />
<preference name="startView"
value="/system/workplace/views/explorer/explorer_fs.jsp" />
<preference name="uploadVariant" value="gwt" widget="select"
widget-config="basic:%(key.GUI_PREF_USE_UPLOAD_BASIC_0)|gwt:%(key.GUI_PREF_USE_UPLOAD_GWT_0)" />
<preference name="workplaceReportType" value="extended" />
Expand Down

0 comments on commit eb84a4d

Please sign in to comment.