Search in sources :

Example 66 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class AddOnInstallerPanel method createInstallActionListener.

private ActionListener createInstallActionListener() {
    return new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final Controller controller = Controller.getCurrentController();
            try {
                LogUtils.info("installing add-on from " + urlField.getText());
                controller.getViewController().setWaitingCursor(true);
                final URL url = toURL(urlField.getText());
                setStatusInfo(getText("status.installing"));
                final ModeController modeController = controller.getModeController(MModeController.MODENAME);
                final MFileManager fileManager = (MFileManager) MFileManager.getController(modeController);
                MapModel newMap = new MMapModel();
                if (!fileManager.loadCatchExceptions(url, newMap)) {
                    LogUtils.warn("can not load " + url);
                    return;
                }
                controller.getModeController().getMapController().fireMapCreated(newMap);
                AddOnProperties addOn = (AddOnProperties) ScriptingEngine.executeScript(newMap.getRootNode(), getInstallScriptSource(), ScriptingPermissions.getPermissiveScriptingPermissions());
                if (addOn != null) {
                    setStatusInfo(getText("status.success", addOn.getName()));
                    AddOnsController.getController().registerInstalledAddOn(addOn);
                    final ManageAddOnsPanel managementPanel = addOn.isTheme() ? manageThemesPanel : manageAddOnsPanel;
                    managementPanel.getTableModel().addAddOn(addOn);
                    urlField.setText("");
                    ((JTabbedPane) getParent()).setSelectedComponent(managementPanel);
                    selectLastAddOn(managementPanel);
                }
            } catch (Exception ex) {
                UITools.errorMessage(getText("error", ex.toString()));
            } finally {
                controller.getViewController().setWaitingCursor(false);
            }
        }

        private String getInstallScriptSource() throws IOException {
            final ResourceController resourceController = ResourceController.getResourceController();
            final File scriptDir = new File(resourceController.getInstallationBaseDir(), "scripts");
            final File installScript = new File(scriptDir, "installScriptAddOn.groovy");
            if (!installScript.exists())
                throw new RuntimeException("internal error: installer not found at " + installScript);
            return FileUtils.slurpFile(installScript);
        }

        private URL toURL(String urlText) throws MalformedURLException {
            try {
                return new URL(urlText);
            } catch (Exception e2) {
                return new File(urlText).toURI().toURL();
            }
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) JTabbedPane(javax.swing.JTabbedPane) MFileManager(org.freeplane.features.url.mindmapmode.MFileManager) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) MapModel(org.freeplane.features.map.MapModel) AddOnsController(org.freeplane.main.addons.AddOnsController) ResourceController(org.freeplane.core.resources.ResourceController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) URL(java.net.URL) AddOnProperties(org.freeplane.main.addons.AddOnProperties) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ActionListener(java.awt.event.ActionListener) ResourceController(org.freeplane.core.resources.ResourceController) File(java.io.File)

Example 67 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class ConvertibleTest method convertible.

private Convertible convertible(String text) {
    final MapModel mapModel = Controller.getCurrentModeController().getMapController().newModel();
    NodeModel nodeModel = new NodeModel(mapModel);
    return new TestConvertible(nodeModel, text);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MapModel(org.freeplane.features.map.MapModel)

Example 68 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class ControllerProxy method getOpenMaps.

public List<Map> getOpenMaps() {
    Collection<MapModel> mapModels = getMapViewManager().getMaps().values();
    ArrayList<Map> mapProxies = new ArrayList<Map>(mapModels.size());
    for (MapModel mapModel : mapModels) {
        mapProxies.add(new MapProxy(mapModel, scriptContext));
    }
    return mapProxies;
}
Also used : ArrayList(java.util.ArrayList) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) MapModel(org.freeplane.features.map.MapModel) Map(org.freeplane.plugin.script.proxy.Proxy.Map)

Example 69 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class ControllerProxy method newMapFromTemplate.

public Map newMapFromTemplate(File templateFile) {
    final MapModel oldMap = Controller.getCurrentController().getMap();
    final MMapIO mapIO = (MMapIO) Controller.getCurrentModeController().getExtension(MapIO.class);
    final MapModel newMap = mapIO.newMapFromTemplate(templateFile);
    restartTransaction(oldMap, newMap);
    return new MapProxy(newMap, scriptContext);
}
Also used : MMapIO(org.freeplane.features.mapio.mindmapmode.MMapIO) MapIO(org.freeplane.features.mapio.MapIO) MMapIO(org.freeplane.features.mapio.mindmapmode.MMapIO) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) MapModel(org.freeplane.features.map.MapModel)

Example 70 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class ControllerProxy method undo.

public void undo() {
    final MapModel map = Controller.getCurrentController().getMap();
    final IUndoHandler undoHandler = (IUndoHandler) map.getExtension(IUndoHandler.class);
    undoHandler.undo();
}
Also used : IUndoHandler(org.freeplane.core.undo.IUndoHandler) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) MapModel(org.freeplane.features.map.MapModel)

Aggregations

MapModel (org.freeplane.features.map.MapModel)143 NodeModel (org.freeplane.features.map.NodeModel)47 ModeController (org.freeplane.features.mode.ModeController)35 Controller (org.freeplane.features.mode.Controller)31 IActor (org.freeplane.core.undo.IActor)27 MMapModel (org.freeplane.features.map.mindmapmode.MMapModel)16 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)16 IUndoHandler (org.freeplane.core.undo.IUndoHandler)15 AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)14 IStyle (org.freeplane.features.styles.IStyle)14 File (java.io.File)13 MMapController (org.freeplane.features.map.mindmapmode.MMapController)13 URL (java.net.URL)12 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)11 MapStyleModel (org.freeplane.features.styles.MapStyleModel)10 IMapViewManager (org.freeplane.features.ui.IMapViewManager)10 MapController (org.freeplane.features.map.MapController)9 URI (java.net.URI)8 ResourceController (org.freeplane.core.resources.ResourceController)8 IOException (java.io.IOException)7