01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10: * for the specific language governing rights and limitations under the
11: * License.
12: *
13: * The Original Code is Riot.
14: *
15: * The Initial Developer of the Original Code is
16: * Neteye GmbH.
17: * Portions created by the Initial Developer are Copyright (C) 2007
18: * the Initial Developer. All Rights Reserved.
19: *
20: * Contributor(s):
21: * Felix Gnass [fgnass at neteye dot de]
22: *
23: * ***** END LICENSE BLOCK ***** */
24: package org.riotfamily.pages.riot.command;
25:
26: import org.riotfamily.pages.dao.PageDao;
27: import org.riotfamily.pages.dao.PageValidationUtils;
28: import org.riotfamily.pages.model.Page;
29: import org.riotfamily.pages.model.PageNode;
30: import org.riotfamily.pages.model.Site;
31: import org.riotfamily.riot.list.command.CommandContext;
32: import org.riotfamily.riot.list.command.core.Clipboard;
33: import org.riotfamily.riot.list.command.core.PasteCommand;
34:
35: public class PastePageCommand extends PasteCommand {
36:
37: private PageDao pageDao;
38:
39: public PastePageCommand(PageDao pageDao) {
40: this .pageDao = pageDao;
41: }
42:
43: protected boolean isEnabled(CommandContext context, String action) {
44: boolean enabled = super .isEnabled(context, action);
45: Clipboard cb = Clipboard.get(context);
46: Object obj = cb.getObject();
47: if (obj instanceof Page) {
48: Page page = (Page) obj;
49: enabled &= isValidChild(context.getParent(), page);
50:
51: //REVISIT
52: // Only allow pasting into the same site
53: Site site = PageCommandUtils.getParentSite(context);
54: if (site != null) {
55: enabled &= page.getSite().equals(site);
56: }
57: }
58: return enabled;
59: }
60:
61: private boolean isValidChild(Object parent, Page page) {
62: PageNode parentNode;
63: if (parent instanceof Page) {
64: parentNode = ((Page) parent).getNode();
65: } else {
66: parentNode = pageDao.getRootNode();
67: }
68: return PageValidationUtils.isValidChild(parentNode, page);
69: }
70:
71: }
|