1 24 package org.riotfamily.pages.riot.command; 25 26 import java.util.Locale ; 27 28 import org.riotfamily.pages.Page; 29 import org.riotfamily.pages.PageValidationUtils; 30 import org.riotfamily.pages.dao.PageDao; 31 import org.riotfamily.riot.list.command.CommandContext; 32 import org.riotfamily.riot.list.command.CommandResult; 33 import org.riotfamily.riot.list.command.core.EditCommand; 34 import org.riotfamily.riot.list.command.result.ShowListResult; 35 36 public class EditPageCommand extends EditCommand { 37 38 public static final String ACTION_TRANSLATE = "translate"; 39 40 private PageDao pageDao; 41 42 43 public EditPageCommand(PageDao pageDao) { 44 this.pageDao = pageDao; 45 } 46 47 protected String getAction(CommandContext context) { 48 return PageCommandUtils.isTranslated(context) 49 ? super.getAction(context) 50 : ACTION_TRANSLATE; 51 } 52 53 protected boolean isEnabled(CommandContext context, String action) { 54 if (action == ACTION_TRANSLATE) { 55 Page page = PageCommandUtils.getPage(context); 56 Locale locale = PageCommandUtils.getParentLocale(context); 57 return PageValidationUtils.isTranslatable(page, locale); 58 } 59 return true; 60 } 61 62 protected String getItemStyleClass(CommandContext context, String action) { 63 StringBuffer styleClasses = new StringBuffer (); 64 if (action == ACTION_TRANSLATE) { 65 appendStyleClass(styleClasses, "foreign-page"); 66 } 67 68 if (PageCommandUtils.isSystemPage(context)) { 69 appendStyleClass(styleClasses, "system-page"); 70 } 71 if (PageCommandUtils.isHiddenNode(context)) { 72 appendStyleClass(styleClasses, "hidden-node"); 73 } 74 if (PageCommandUtils.isHiddenPage(context)) { 75 appendStyleClass(styleClasses, "hidden-page"); 76 } 77 if (PageCommandUtils.isFolder(context)) { 78 appendStyleClass(styleClasses, "folder"); 79 } 80 return styleClasses.toString(); 81 } 82 83 private void appendStyleClass(StringBuffer buffer, String styleClass) { 84 if (buffer.length() > 0) { 85 buffer.append(" "); 86 } 87 buffer.append(styleClass); 88 } 89 90 public CommandResult execute(CommandContext context) { 91 if (PageCommandUtils.isTranslated(context)) { 92 return super.execute(context); 93 } 94 Page page = PageCommandUtils.getPage(context); 95 Locale locale = PageCommandUtils.getParentLocale(context); 96 pageDao.addTranslation(page, locale); 97 return new ShowListResult(context); 98 } 99 100 } 101 | Popular Tags |