1 /** 2 * This file Copyright (c) 2010-2012 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.ui.admincentral.app.content; 35 36 import info.magnolia.ui.admincentral.app.content.location.ItemLocation; 37 import info.magnolia.ui.admincentral.workbench.ItemWorkbenchPresenter; 38 import info.magnolia.ui.framework.app.AbstractSubApp; 39 import info.magnolia.ui.framework.app.SubAppContext; 40 import info.magnolia.ui.framework.location.Location; 41 import info.magnolia.ui.framework.view.View; 42 43 import javax.inject.Inject; 44 45 /** 46 * Abstract class providing a sensible implementation for services shared by all item subApps. 47 * Implementers of this class represent a tab for viewing and editing items typically opened from an {@link AbstractContentSubApp}. 48 * Subclasses can augment the default behavior and perform additional tasks by overriding the following methods: 49 * <ul> 50 * <li>{@link #onSubAppStart()} 51 * <li>{@link #locationChanged(Location)} 52 * </ul> 53 * 54 * Currently lacking listeners for {@link info.magnolia.ui.admincentral.event.ContentChangedEvent}. 55 * Currently lacking handling of locationChanged. Related to MGNLUI-154 56 * 57 * @see ItemWorkbenchPresenter 58 * @see WorkbenchSubAppView 59 * @see ItemLocation 60 */ 61 public class AbstractItemSubApp extends AbstractSubApp { 62 63 private final ItemWorkbenchPresenter workbench; 64 65 private String caption; 66 67 @Inject 68 protected AbstractItemSubApp(final SubAppContext subAppContext, final WorkbenchSubAppView view, ItemWorkbenchPresenter workbench) { 69 super(subAppContext, view); 70 this.workbench = workbench; 71 } 72 73 /** 74 * Performs some routine tasks needed by all item subApps before the view is displayed. 75 * The tasks are: 76 * <ul> 77 * <li>setting the current location 78 * <li>setting the workbench view 79 * <li>calling {@link #onSubAppStart()} a hook-up method subclasses can override to perform additional work. 80 * </ul> 81 */ 82 @Override 83 public View start(final Location location) { 84 ItemLocation l = ItemLocation.wrap(location); 85 super.start(l); 86 this.caption = l.getNodePath(); 87 getView().setWorkbenchView(workbench.start(l.getNodePath(), l.getViewType())); 88 return getView(); 89 } 90 91 /** 92 * Wraps the current DefaultLocation in a ItemLocation. Providing getter and setters for used parameters. 93 */ 94 @Override 95 public ItemLocation getCurrentLocation() { 96 return ItemLocation.wrap(super.getCurrentLocation()); 97 } 98 99 @Override 100 public WorkbenchSubAppView getView() { 101 return (WorkbenchSubAppView) super.getView(); 102 } 103 104 @Override 105 public boolean supportsLocation(Location location) { 106 ItemLocation itemLocation = ItemLocation.wrap(location); 107 String currentPath = getCurrentLocation().getNodePath(); 108 return currentPath.equals(itemLocation.getNodePath()); 109 } 110 111 @Override 112 public void locationChanged(Location location) { 113 ItemLocation itemLocation = ItemLocation.wrap(location); 114 //getView().setWorkbenchView(workbench.start(itemLocation.getNodePath())); 115 super.locationChanged(location); 116 } 117 118 private boolean hasLocationChanged(ItemLocation location) { 119 return getCurrentLocation().getViewType() != location.getViewType(); 120 } 121 122 @Override 123 public String getCaption() { 124 return caption; 125 } 126 127 }