001 /*
002 * $Id: McvPluginManager.java,v 1.11 2012/02/19 17:35:53 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030
031 package edu.wisc.ssec.mcidasv;
032
033 import java.io.File;
034 import java.util.ArrayList;
035 import java.util.List;
036
037 import javax.swing.JLabel;
038
039 import org.slf4j.Logger;
040 import org.slf4j.LoggerFactory;
041
042 import edu.wisc.ssec.mcidasv.servermanager.LocalEntryEditor;
043
044 import ucar.unidata.idv.IntegratedDataViewer;
045 import ucar.unidata.idv.PluginManager;
046 import ucar.unidata.util.GuiUtils;
047 import ucar.unidata.util.IOUtil;
048 import ucar.unidata.util.LogUtil;
049 import ucar.unidata.util.ResourceCollection;
050
051 public class McvPluginManager extends PluginManager {
052
053 private static final Logger logger = LoggerFactory.getLogger(LocalEntryEditor.class);
054
055 public McvPluginManager(IntegratedDataViewer idv) {
056 super(idv);
057 }
058
059 @Override protected void loadPlugins() throws Exception {
060 ResourceCollection rc = getResourceManager().getResources(
061 getResourceManager().RSC_PLUGINS);
062
063 for (int i = 0; i < rc.size(); i++) {
064 String path = rc.get(i).toString();
065 if (!rc.isWritable(i))
066 continue;
067
068 logger.debug("loadPlugins: path={}", path);
069 File pluginDir = new File(path);
070 File[] plugins = pluginDir.listFiles();
071 if (plugins == null)
072 continue;
073
074 for (File plugin : plugins) {
075 String current = plugin.getName();
076 if (current.startsWith(".tmp.") || current.endsWith(".deletethis"))
077 continue;
078
079 if (current.startsWith("http%3A%2F%2Fwww.unidata")) {
080 String newName = "http%3A%2F%2Fwww.ssec.wisc.edu%2Fmcidas%2Fsoftware%2Fv%2Fresources%2Fplugins%2F"+IOUtil.getFileTail(decode(current));
081 logger.debug(" current={}", current);
082 logger.debug(" newName={}\n",newName);
083 File checkExisting = new File(plugin.getParent(), newName);
084 if (checkExisting.exists())
085 logger.debug(" newName already exists...");
086 else
087 logger.debug(" rename plugin...");
088 }
089 }
090 }
091 super.loadPlugins();
092 }
093
094 /**
095 * McIDAS-V overrides {@link PluginManager#removePlugin(File)} so that the
096 * user is given an update on their plugin situation.
097 */
098 @Override public void removePlugin(File file) {
099 super.removePlugin(file);
100 LogUtil.userMessage("You must restart McIDAS-V to complete the removal of this plugin.");
101 }
102
103 /**
104 * Do not give the option to restart. Simply note that a restart is necessary at some point in the future.
105 */
106 protected void notifyUser() {
107 LogUtil.userMessage("You must restart McIDAS-V to complete the installation of this plugin.");
108 return;
109 }
110 }