Search in sources :

Example 1 with AddOnProperties

use of org.freeplane.main.addons.AddOnProperties in project freeplane by freeplane.

the class UpdateCheckAction method checkForAddonsUpdates.

// looking for new versions of add-ons
// and store the latest version as a property
private void checkForAddonsUpdates() {
    // loop on add-ons
    List<AddOnProperties> installedAddOns = AddOnsController.getController().getInstalledAddOns();
    LogUtils.info("checking for updates of " + installedAddOns.size() + " add-ons");
    for (AddOnProperties addOnProperties : installedAddOns) {
        FreeplaneVersion addOnLocalVersion = toFreeplaneVersion(addOnProperties.getVersion());
        // get the update-url for this add-on
        // append the current add-on version for
        // - statistics (appending a freeplane installation unique id would enable building add-on usage statistics)
        // - handling special cases ? (maybe we could send the freeplane version too)
        final URL updateUrl = addOnProperties.getUpdateUrl();
        if (updateUrl != null) {
            final String addOnUpdateRequest = updateUrl + "?v=" + addOnLocalVersion.toString();
            final HttpVersionClient versionClient = new HttpVersionClient(addOnUpdateRequest, addOnLocalVersion);
            final boolean connectSuccesfull;
            final FreeplaneVersion latestVersion = versionClient.getRemoteVersion();
            connectSuccesfull = versionClient.isSuccessful();
            if (connectSuccesfull) {
                addOnProperties.setLatestVersion(latestVersion.toString());
                if (versionClient.getRemoteVersionDownloadUrl() != null) {
                    addOnProperties.setLatestVersionDownloadUrl(versionClient.getRemoteVersionDownloadUrl());
                }
                if (versionClient.getRemoteVersionChangelogUrl() != null) {
                    addOnProperties.setLatestVersionChangelogUrl(versionClient.getRemoteVersionChangelogUrl());
                }
            }
        }
    }
}
Also used : FreeplaneVersion(org.freeplane.core.util.FreeplaneVersion) AddOnProperties(org.freeplane.main.addons.AddOnProperties) URL(java.net.URL)

Example 2 with AddOnProperties

use of org.freeplane.main.addons.AddOnProperties in project freeplane by freeplane.

the class UpdateCheckAction method showUpdateDialog.

private int showUpdateDialog(final String info, final FreeplaneVersion freeplaneLatestVersion, final String history, String language) {
    // dialog layout
    // - messagePane (verticalBox)
    // |- gridPane (GridBagLayout)
    // Components | Installed version | Latestversion | Changelog button | Got to download button
    // 
    // |- preferences label
    // |- checkbox for automatic update
    final Box messagePane = Box.createVerticalBox();
    final JLabel emptyLabel = new JLabel("");
    // grid setup
    final JPanel gridPane = new JPanel(new GridBagLayout());
    gridPane.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    final Border paddingBorder = BorderFactory.createEmptyBorder(0, 10, 10, 0);
    gridPane.setBorder(BorderFactory.createCompoundBorder(paddingBorder, paddingBorder));
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    int gridRow = 0;
    c.weightx = 0.5;
    // table headers
    final JLabel componentHeader = new JLabel(TextUtils.getText("updater.component"), SwingConstants.CENTER);
    final JLabel installedVersionHeader = new JLabel(TextUtils.getText("updater.version.installed"), SwingConstants.CENTER);
    final JLabel latestVersionHeader = new JLabel(TextUtils.getText("updater.version.latest"), SwingConstants.CENTER);
    final Font boldFont = new Font(componentHeader.getFont().getName(), Font.BOLD, componentHeader.getFont().getSize());
    componentHeader.setFont(boldFont);
    installedVersionHeader.setFont(boldFont);
    latestVersionHeader.setFont(boldFont);
    componentHeader.setBorder(paddingBorder);
    installedVersionHeader.setBorder(paddingBorder);
    latestVersionHeader.setBorder(paddingBorder);
    // adding headers
    c.gridy = 0;
    c.gridx = 0;
    gridPane.add(componentHeader, c);
    c.gridx = 1;
    gridPane.add(installedVersionHeader, c);
    c.gridx = 2;
    gridPane.add(latestVersionHeader, c);
    c.gridx = 3;
    gridPane.add(emptyLabel, c);
    c.gridx = 4;
    gridPane.add(emptyLabel, c);
    // first row : freeplane
    c.gridy = 1;
    final JLabel freeplaneLabel = new JLabel("Freeplane");
    final FreeplaneVersion freeplaneLocalVersion = FreeplaneVersion.getVersion();
    final JLabel freeplaneInstalledVersionLabel = new JLabel(freeplaneLocalVersion.toString(), SwingConstants.CENTER);
    final JLabel freeplaneLatestVersionLabel;
    JButton updateButton;
    JButton changelogButton;
    final String translatedWebUpdate = getWebUpdateUrl(language);
    changelogButton = new JButton(TextUtils.getText("updater.viewChangelog"));
    changelogButton.addActionListener(openUrlListener);
    changelogButton.setActionCommand(translatedWebUpdate);
    updateButton = new JButton(TextUtils.getText("updater.goToDownload"));
    updateButton.addActionListener(openUrlListener);
    updateButton.setActionCommand("http://freeplane.sourceforge.net");
    Boolean needsUpdate = Boolean.FALSE;
    if (freeplaneLatestVersion != null) {
        if (freeplaneLocalVersion.compareTo(freeplaneLatestVersion) < 0) {
            needsUpdate = Boolean.TRUE;
        } else {
            needsUpdate = Boolean.FALSE;
        }
        freeplaneLatestVersionLabel = new JLabel(freeplaneLatestVersion.toString(), SwingConstants.CENTER);
    } else {
        freeplaneLatestVersionLabel = new JLabel(TextUtils.getText("updater.version.unknown"), SwingConstants.CENTER);
        freeplaneLatestVersionLabel.setToolTipText(TextUtils.getText(info));
    }
    changelogButton.setEnabled(needsUpdate);
    updateButton.setEnabled(needsUpdate);
    c.gridx = 0;
    gridPane.add(freeplaneLabel, c);
    c.gridx = 1;
    gridPane.add(freeplaneInstalledVersionLabel, c);
    c.gridx = 2;
    gridPane.add(freeplaneLatestVersionLabel, c);
    c.gridx = 3;
    gridPane.add(changelogButton, c);
    c.gridx = 4;
    gridPane.add(updateButton, c);
    final List<AddOnProperties> installedAddOns = AddOnsController.getController().getInstalledAddOns();
    gridRow = 3;
    for (AddOnProperties addOnProperties : installedAddOns) {
        FreeplaneVersion addOnLocalVersion = toFreeplaneVersion(addOnProperties.getVersion());
        FreeplaneVersion addOnLatestVersion = toFreeplaneVersion(addOnProperties.getLatestVersion());
        final JLabel addOnInstalledVersionLabel = new JLabel(addOnLocalVersion.toString(), SwingConstants.CENTER);
        final JLabel addOnLatestVersionLabel;
        needsUpdate = Boolean.FALSE;
        if (addOnLatestVersion != null) {
            if (addOnLocalVersion.compareTo(addOnLatestVersion) < 0) {
                needsUpdate = Boolean.TRUE;
            }
            addOnLatestVersionLabel = new JLabel(addOnLatestVersion.toString(), SwingConstants.CENTER);
        } else {
            addOnLatestVersionLabel = new JLabel(TextUtils.getText("updater.version.unknown"), SwingConstants.CENTER);
            if (addOnProperties.getUpdateUrl() != null) {
                addOnLatestVersionLabel.setToolTipText(TextUtils.getText("updater.version.unreachable") + " " + addOnProperties.getUpdateUrl());
            } else {
                addOnLatestVersionLabel.setToolTipText(TextUtils.getText("updater.version.noUpdateUrl"));
            }
        }
        final JLabel addOnLabel = new JLabel(TextUtils.getText("addons." + addOnProperties.getName()));
        c.gridx = 0;
        c.gridy = gridRow;
        gridPane.add(addOnLabel, c);
        c.gridx = 1;
        c.gridy = gridRow;
        gridPane.add(addOnInstalledVersionLabel, c);
        c.gridx = 2;
        c.gridy = gridRow;
        gridPane.add(addOnLatestVersionLabel, c);
        c.gridx = 3;
        c.gridy = gridRow;
        changelogButton = new JButton(TextUtils.getText("updater.viewChangelog"));
        changelogButton.addActionListener(openUrlListener);
        if (addOnProperties.getLatestVersionChangelogUrl() != null) {
            changelogButton.setActionCommand(addOnProperties.getLatestVersionChangelogUrl().toString());
        } else if (addOnProperties.getUpdateUrl() != null) {
            changelogButton.setActionCommand(String.valueOf(addOnProperties.getUpdateUrl()));
        }
        gridPane.add(changelogButton, c);
        changelogButton.setEnabled(needsUpdate);
        c.gridx = 4;
        c.gridy = gridRow;
        updateButton = new JButton(TextUtils.getText("updater.goToDownload"));
        updateButton.addActionListener(openUrlListener);
        if (addOnProperties.getLatestVersionDownloadUrl() != null) {
            updateButton.setActionCommand(addOnProperties.getLatestVersionDownloadUrl().toString());
        } else if (addOnProperties.getHomepage() != null) {
            updateButton.setActionCommand(addOnProperties.getHomepage().toString());
        }
        gridPane.add(updateButton, c);
        updateButton.setEnabled(needsUpdate);
        gridRow++;
    }
    messagePane.add(gridPane);
    if (!history.isEmpty()) {
        final JTextArea text = new JTextArea(history);
        text.setRows(10);
        final JScrollPane scrollPane = new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setBorder(BorderFactory.createEtchedBorder());
        messagePane.add(scrollPane);
    }
    final JLabel confLabel = new JLabel(TextUtils.getText("preferences"));
    confLabel.setFont(boldFont);
    messagePane.add(confLabel);
    final JCheckBox updateAutomatically = new JCheckBox(TextUtils.getText("OptionPanel.check_updates_automatically"), ResourceController.getResourceController().getBooleanProperty(CHECK_UPDATES_AUTOMATICALLY));
    updateAutomatically.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    messagePane.add(updateAutomatically);
    final Object[] options;
    options = new Object[] { TextUtils.getText("simplyhtml.closeBtnName") };
    final int choice = JOptionPane.showOptionDialog(UITools.getMenuComponent(), messagePane, TextUtils.getText("updatecheckdialog"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
    ResourceController.getResourceController().setProperty(CHECK_UPDATES_AUTOMATICALLY, Boolean.toString(updateAutomatically.isSelected()));
    return choice;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Font(java.awt.Font) AddOnProperties(org.freeplane.main.addons.AddOnProperties) JCheckBox(javax.swing.JCheckBox) FreeplaneVersion(org.freeplane.core.util.FreeplaneVersion) Border(javax.swing.border.Border)

Example 3 with AddOnProperties

use of org.freeplane.main.addons.AddOnProperties 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 4 with AddOnProperties

use of org.freeplane.main.addons.AddOnProperties in project freeplane by freeplane.

the class AddonRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (value instanceof AddOnProperties) {
        AddOnProperties addOn = (AddOnProperties) value;
        final String description = addOn.getDescription();
        final String shortDescription = HtmlUtils.toXMLEscapedText(shorten(HtmlUtils.htmlToPlain(description), 120));
        String text = "<html><body><b><font size='+1'>" + addOn.getTranslatedName() + " " + addOn.getVersion().replaceAll("^v", "") + createAuthorText(addOn.getAuthor()) + "</font></b><br>" + shortDescription + "</body></html>";
        value = text;
        setToolTipText(description);
    }
    final Component tableCellRendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    return tableCellRendererComponent;
}
Also used : Component(java.awt.Component) AddOnProperties(org.freeplane.main.addons.AddOnProperties)

Example 5 with AddOnProperties

use of org.freeplane.main.addons.AddOnProperties in project freeplane by freeplane.

the class ButtonsInCellRenderer method setButtonsVisible.

protected void setButtonsVisible(JTable table, int row) {
    final ManageAddOnsPanel.AddOnTableModel model = (ManageAddOnsPanel.AddOnTableModel) table.getModel();
    final AddOnProperties addOn = model.getAddOnAt(row);
    for (JButton btn : buttons) {
        final boolean supportsOperation = addOn.supportsOperation(btn.getName());
        btn.setVisible(supportsOperation);
    }
}
Also used : JButton(javax.swing.JButton) AddOnProperties(org.freeplane.main.addons.AddOnProperties)

Aggregations

AddOnProperties (org.freeplane.main.addons.AddOnProperties)9 ActionEvent (java.awt.event.ActionEvent)5 AbstractAction (javax.swing.AbstractAction)4 URL (java.net.URL)2 JButton (javax.swing.JButton)2 FreeplaneVersion (org.freeplane.core.util.FreeplaneVersion)2 Component (java.awt.Component)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 Box (javax.swing.Box)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1