Search in sources :

Example 1 with ProblemPanel

use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.

the class InstallStep method notifyWritePermissionProblem.

@Messages({ "# {0} - plugin_name", "inBackground_WritePermission=You don''t have permission to install plugin {0} into the installation directory.", "inBackground_WritePermission_Details=details", "cancel=Cancel", "install=Install anyway" })
private void notifyWritePermissionProblem(final OperationException ex, final UpdateElement culprit) {
    // lack of privileges for writing
    ActionListener onMouseClickAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ProblemPanel problem = new ProblemPanel(ex, culprit, false);
            problem.showWriteProblemDialog();
        }
    };
    String title = inBackground_WritePermission(culprit.getDisplayName());
    String description = inBackground_WritePermission_Details();
    NotificationDisplayer.getDefault().notify(title, // NOI18N
    ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/error.png", false), description, onMouseClickAction, NotificationDisplayer.Priority.HIGH, NotificationDisplayer.Category.ERROR);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ProblemPanel(org.netbeans.modules.autoupdate.ui.ProblemPanel) Messages(org.openide.util.NbBundle.Messages)

Example 2 with ProblemPanel

use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.

the class InstallStep method notifyNetworkProblem.

private void notifyNetworkProblem(final OperationException ex) {
    // Some network problem found
    ActionListener onMouseClickAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ProblemPanel problem = new ProblemPanel(ex, false);
            problem.showNetworkProblemDialog();
        }
    };
    String title = getBundle("InstallSupport_InBackground_NetworkError");
    String description = getBundle("InstallSupport_InBackground_NetworkError_Details");
    NotificationDisplayer.getDefault().notify(title, ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/error.png", false), description, onMouseClickAction, NotificationDisplayer.Priority.HIGH, NotificationDisplayer.Category.ERROR);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ProblemPanel(org.netbeans.modules.autoupdate.ui.ProblemPanel)

Example 3 with ProblemPanel

use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.

the class InstallStep method handleValidation.

private Installer handleValidation(Validator v, final InstallSupport support) {
    if (canceled) {
        log.fine("Quit handleValidation() because an previous installation was canceled.");
        return null;
    }
    component.setHeadAndContent(getBundle(HEAD_VERIFY), getBundle(CONTENT_VERIFY));
    ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"));
    JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
    JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
    JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
    if (runInBackground()) {
        systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"), new Cancellable() {

            @Override
            public boolean cancel() {
                handleCancel();
                return true;
            }
        });
        handle = systemHandle;
    } else {
        spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"), new Cancellable() {

            @Override
            public boolean cancel() {
                handleCancel();
                return true;
            }
        });
        totalUnits = model.getInstallContainer().listAll().size();
        processedUnits = 0;
        if (indeterminateProgress) {
            detailLabel.addPropertyChangeListener(TEXT_PROPERTY, new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    assert TEXT_PROPERTY.equals(evt.getPropertyName()) : "Listens onlo on " + TEXT_PROPERTY + " but was " + evt;
                    if (evt.getOldValue() != evt.getNewValue()) {
                        processedUnits++;
                        if (indeterminateProgress && spareHandleStarted) {
                            if (processedUnits < totalUnits - 1) {
                                totalUnits = totalUnits - processedUnits;
                                spareHandle.switchToDeterminate(totalUnits);
                                indeterminateProgress = false;
                            }
                        }
                        if (!indeterminateProgress) {
                            spareHandle.progress(((JLabel) evt.getSource()).getText(), processedUnits < totalUnits - 1 ? processedUnits : totalUnits - 1);
                        }
                    }
                }
            });
        }
    }
    handle.setInitialDelay(0);
    panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
    if (spareHandle != null && spareHandleStarted) {
        spareHandle.finish();
    }
    Installer tmpInst;
    try {
        tmpInst = support.doValidate(v, handle);
        if (tmpInst == null)
            return null;
    } catch (OperationException ex) {
        log.log(Level.INFO, ex.getMessage(), ex);
        ProblemPanel problem = new ProblemPanel(ex, detailLabel.getText(), false);
        if (ex.getErrorType() == OperationException.ERROR_TYPE.MODIFIED) {
            problem.showModifiedProblemDialog(detailLabel.getText());
        } else {
            problem.showNetworkProblemDialog();
        }
        handleCancel();
        return null;
    }
    final Installer inst = tmpInst;
    List<UpdateElement> signedVerified = new ArrayList<UpdateElement>();
    List<UpdateElement> signedUnverified = new ArrayList<UpdateElement>();
    List<UpdateElement> unsigned = new ArrayList<UpdateElement>();
    List<UpdateElement> modified = new ArrayList<UpdateElement>();
    int trustedCount = 0;
    Map<Object, String> certs = new HashMap<>();
    for (UpdateElement el : model.getAllUpdateElements()) {
        boolean writeCert = false;
        if (support.isContentModified(inst, el)) {
            modified.add(el);
            continue;
        } else if (support.isTrusted(inst, el)) {
            trustedCount++;
            continue;
        } else if (support.isSignedVerified(inst, el)) {
            signedVerified.add(el);
            writeCert = true;
        } else if (support.isSignedUnverified(inst, el)) {
            signedUnverified.add(el);
            writeCert = true;
        } else {
            unsigned.add(el);
        }
        if (writeCert) {
            String cert = support.getCertificate(inst, el);
            if (cert != null && cert.length() > 0) {
                certs.put(el.getDisplayName(), cert);
            }
        }
    }
    if (signedVerified.size() > 0 || signedUnverified.size() > 0 || unsigned.size() > 0 || modified.size() > 0 && !runInBackground()) {
        int total = trustedCount + signedVerified.size() + signedUnverified.size() + unsigned.size();
        final ValidationWarningPanel p = new ValidationWarningPanel(signedVerified, signedUnverified, unsigned, modified, total);
        final boolean verifyCertificate = (!signedVerified.isEmpty() || !signedUnverified.isEmpty()) && !certs.isEmpty();
        JButton[] options;
        JButton[] closeOptions;
        final JButton cancel = model.getCancelButton(wd);
        DialogDescriptor dd = new DialogDescriptor(p, verifyCertificate ? getBundle("ValidationWarningPanel_VerifyCertificate_Title") : getBundle("ValidationWarningPanel_Title"));
        JButton canContinue = new JButton();
        canContinue.setDefaultCapable(false);
        if (modified.isEmpty()) {
            final JButton showDetails = new JButton();
            Mnemonics.setLocalizedText(showDetails, getBundle("ValidationWarningPanel_ShowDetailsButton"));
            final Map<Object, String> certsMap = certs;
            showDetails.setEnabled(false);
            p.addSelectionListener(new TreeSelectionListener() {

                @Override
                public void valueChanged(TreeSelectionEvent e) {
                    if (e.getNewLeadSelectionPath().getPathCount() == 3 && certsMap.containsKey(p.getSelectedNode())) {
                        showDetails.setEnabled(true);
                    } else {
                        showDetails.setEnabled(false);
                    }
                }
            });
            showDetails.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (showDetails.equals(e.getSource())) {
                        Object node = p.getSelectedNode();
                        if (certsMap.containsKey(node)) {
                            JTextArea ta = new JTextArea(certsMap.get(node));
                            ta.setEditable(false);
                            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(ta));
                        }
                    }
                }
            });
            Mnemonics.setLocalizedText(canContinue, getBundle("ValidationWarningPanel_ContinueButton"));
            if (verifyCertificate) {
                dd.setAdditionalOptions(new JButton[] { showDetails });
            }
            options = new JButton[] { canContinue, cancel };
            closeOptions = new JButton[] { canContinue, cancel };
        } else {
            options = new JButton[] { cancel };
            closeOptions = new JButton[] { cancel };
        }
        dd.setOptions(options);
        dd.setClosingOptions(closeOptions);
        dd.setMessageType(NotifyDescriptor.WARNING_MESSAGE);
        final Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
        JDialog jdlg = (JDialog) dlg;
        jdlg.getRootPane().setDefaultButton(cancel);
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    dlg.setVisible(true);
                }
            });
        } catch (InterruptedException ex) {
            log.log(Level.INFO, ex.getLocalizedMessage(), ex);
            return null;
        } catch (InvocationTargetException ex) {
            log.log(Level.INFO, ex.getLocalizedMessage(), ex);
            return null;
        }
        if (!canContinue.equals(dd.getValue())) {
            if (!cancel.equals(dd.getValue())) {
                cancel.doClick();
            }
            return null;
        }
        assert canContinue.equals(dd.getValue());
    }
    panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
    return inst;
}
Also used : JTextArea(javax.swing.JTextArea) PropertyChangeListener(java.beans.PropertyChangeListener) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) Installer(org.netbeans.api.autoupdate.InstallSupport.Installer) HashMap(java.util.HashMap) Cancellable(org.openide.util.Cancellable) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) ProblemPanel(org.netbeans.modules.autoupdate.ui.ProblemPanel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) JDialog(javax.swing.JDialog) Dialog(java.awt.Dialog) OperationException(org.netbeans.api.autoupdate.OperationException) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProgressHandle(org.netbeans.api.progress.ProgressHandle) ActionListener(java.awt.event.ActionListener) DialogDescriptor(org.openide.DialogDescriptor) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) JDialog(javax.swing.JDialog)

Example 4 with ProblemPanel

use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.

the class InstallStep method tryPerformDownload.

private boolean tryPerformDownload(final InstallSupport support) {
    validator = null;
    JLabel detailLabel = null;
    try {
        ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"));
        JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
        JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
        detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
        if (runInBackground()) {
            systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"), new Cancellable() {

                @Override
                public boolean cancel() {
                    return handleCancel();
                }
            });
            handle = systemHandle;
        } else {
            spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"), new Cancellable() {

                @Override
                public boolean cancel() {
                    return handleCancel();
                }
            });
            totalUnits = model.getInstallContainer().listAll().size();
            processedUnits = 0;
            detailLabel.addPropertyChangeListener(TEXT_PROPERTY, new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    assert TEXT_PROPERTY.equals(evt.getPropertyName()) : "Listens onlo on " + TEXT_PROPERTY + " but was " + evt;
                    if (evt.getOldValue() != evt.getNewValue()) {
                        processedUnits++;
                        if (indeterminateProgress && spareHandleStarted) {
                            if (processedUnits < totalUnits - 1) {
                                totalUnits = totalUnits - processedUnits;
                                spareHandle.switchToDeterminate(totalUnits);
                                indeterminateProgress = false;
                            }
                        }
                        if (!indeterminateProgress && spareHandleStarted) {
                            spareHandle.progress(((JLabel) evt.getSource()).getText(), processedUnits < totalUnits - 1 ? processedUnits : totalUnits - 1);
                        }
                    }
                }
            });
        }
        handle.setInitialDelay(0);
        panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
        validator = support.doDownload(handle, Utilities.isGlobalInstallation(), userdirAsFallback);
        if (validator == null) {
            handleCancel();
            return true;
        }
        panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
        if (spareHandle != null && spareHandleStarted) {
            spareHandle.finish();
            spareHandleStarted = false;
        }
    } catch (OperationException ex) {
        log.log(Level.INFO, ex.getMessage(), ex);
        if (OperationException.ERROR_TYPE.PROXY == ex.getErrorType()) {
            if (runInBackground()) {
                handleCancel();
                notifyNetworkProblem(ex);
            } else {
                JButton tryAgain = new JButton();
                // NOI18N
                Mnemonics.setLocalizedText(tryAgain, getBundle("InstallStep_NetworkProblem_Continue"));
                ProblemPanel problem = new ProblemPanel(// NOI18N
                getBundle("InstallStep_NetworkProblem_Text", ex.getLocalizedMessage()), new JButton[] { tryAgain, model.getCancelButton(wd) });
                Object ret = problem.showNetworkProblemDialog();
                if (tryAgain.equals(ret)) {
                    // try again
                    return false;
                } else if (DialogDescriptor.CLOSED_OPTION.equals(ret)) {
                    model.getCancelButton(wd).doClick();
                }
            }
        } else if (OperationException.ERROR_TYPE.WRITE_PERMISSION == ex.getErrorType()) {
            if (runInBackground()) {
                UpdateElement culprit = findCulprit(ex.getMessage());
                handleCancel();
                notifyWritePermissionProblem(ex, culprit);
            } else {
                JButton cancel = new JButton();
                Mnemonics.setLocalizedText(cancel, cancel());
                JButton install = new JButton();
                Mnemonics.setLocalizedText(install, install());
                UpdateElement culprit = findCulprit(ex.getMessage());
                ProblemPanel problem = new ProblemPanel(ex, culprit, false);
                Object ret = problem.showWriteProblemDialog();
                if (install.equals(ret)) {
                    // install anyway
                    userdirAsFallback = true;
                    return false;
                } else {
                    model.getCancelButton(wd).doClick();
                }
            }
        } else {
            // general problem, show more
            String pluginName = detailLabel == null || detailLabel.getText().length() == 0 ? getBundle("InstallStep_DownloadProblem_SomePlugins") : detailLabel.getText();
            String message = getBundle("InstallStep_DownloadProblem", pluginName, ex.getLocalizedMessage());
            Exceptions.attachLocalizedMessage(ex, message);
            log.log(Level.SEVERE, null, ex);
            handleCancel();
        }
    }
    return true;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) Cancellable(org.openide.util.Cancellable) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) ProblemPanel(org.netbeans.modules.autoupdate.ui.ProblemPanel) ProgressHandle(org.netbeans.api.progress.ProgressHandle) OperationException(org.netbeans.api.autoupdate.OperationException)

Aggregations

ProblemPanel (org.netbeans.modules.autoupdate.ui.ProblemPanel)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 JButton (javax.swing.JButton)2 JComponent (javax.swing.JComponent)2 JLabel (javax.swing.JLabel)2 OperationException (org.netbeans.api.autoupdate.OperationException)2 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)2 ProgressHandle (org.netbeans.api.progress.ProgressHandle)2 Cancellable (org.openide.util.Cancellable)2 Dialog (java.awt.Dialog)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JDialog (javax.swing.JDialog)1 JTextArea (javax.swing.JTextArea)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1