1 /* 2 * HomePluginController.java 05 janv 2012 3 * 4 * Sweet Home 3D, Copyright (c) 2006-2012 Emmanuel PUYBARET / eTeks <info@eteks.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 package com.eteks.sweethome3d.plugin; 21 22 import java.util.Collections; 23 import java.util.List; 24 25 import com.eteks.sweethome3d.model.Home; 26 import com.eteks.sweethome3d.model.HomeApplication; 27 import com.eteks.sweethome3d.model.RecorderException; 28 import com.eteks.sweethome3d.viewcontroller.ContentManager; 29 import com.eteks.sweethome3d.viewcontroller.HomeController; 30 import com.eteks.sweethome3d.viewcontroller.ViewFactory; 31 32 /** 33 * A MVC controller for the home view able to manage plug-ins. 34 * @author Emmanuel Puybaret 35 */ 36 public class HomePluginController extends HomeController { 37 private final Home home; 38 private final HomeApplication application; 39 private final PluginManager pluginManager; 40 41 /** 42 * Creates the controller of home view. 43 * @param home the home edited by this controller and its view. 44 * @param application the instance of current application. 45 * @param viewFactory a factory able to create views. 46 * @param contentManager the content manager of the application. 47 * @param pluginManager the plug-in manager of the application. 48 */ HomePluginController(Home home, HomeApplication application, ViewFactory viewFactory, ContentManager contentManager, PluginManager pluginManager)49 public HomePluginController(Home home, 50 HomeApplication application, 51 ViewFactory viewFactory, 52 ContentManager contentManager, 53 PluginManager pluginManager) { 54 super(home, application, viewFactory, contentManager); 55 this.home = home; 56 this.application = application; 57 this.pluginManager = pluginManager; 58 } 59 60 /** 61 * Returns the plug-ins available with this controller. 62 */ getPlugins()63 public List<Plugin> getPlugins() { 64 if (this.application != null && this.pluginManager != null) { 65 // Retrieve home plug-ins 66 return this.pluginManager.getPlugins( 67 this.application, this.home, this.application.getUserPreferences(), this, getUndoableEditSupport()); 68 } else { 69 List<Plugin> plugins = Collections.emptyList(); 70 return plugins; 71 } 72 } 73 74 /** 75 * Imports the plugin at the given location. 76 */ importPlugin(String pluginLocation)77 public void importPlugin(String pluginLocation) { 78 if (this.pluginManager != null) { 79 try { 80 if (!this.pluginManager.pluginExists(pluginLocation) 81 || getView().confirmReplacePlugin(pluginLocation)) { 82 this.pluginManager.addPlugin(pluginLocation); 83 getView().showMessage(this.application.getUserPreferences().getLocalizedString(HomeController.class, 84 "importedPluginMessage")); 85 } 86 } catch (RecorderException ex) { 87 String message = this.application.getUserPreferences().getLocalizedString(HomeController.class, 88 "importPluginError", pluginLocation); 89 getView().showError(message); 90 } 91 } 92 } 93 } 94