Search in sources :

Example 1 with OperationSupport

use of org.netbeans.api.autoupdate.OperationSupport in project netbeans-rcp-lite by outersky.

the class ModuleInstallerSupport method installPlugins.

public Object installPlugins(final String displayName, Set<String> cnbs) throws OperationException {
    Collection<UpdateUnit> units = findModules(cnbs);
    if (units == null) {
        final String searchMessage = displayName != null ? searching_handle_single(displayName) : searching_handle();
        final String resolveTitle = displayName != null ? resolve_title_single(displayName) : resolve_title();
        final ProgressHandle handle = ProgressHandleFactory.createHandle(searchMessage);
        initButtons();
        final DialogDescriptor searching = new DialogDescriptor(searchingPanel(new JLabel(searchMessage), ProgressHandleFactory.createProgressComponent(handle)), resolveTitle, true, null);
        handle.setInitialDelay(0);
        handle.start();
        searching.setOptions(new Object[] { NotifyDescriptor.CANCEL_OPTION });
        searching.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
        final Dialog dlg = DialogDisplayer.getDefault().createDialog(searching);
        RP.post(new Runnable() {

            @Override
            public void run() {
                // May be first start, when no update lists have yet been downloaded.
                try {
                    for (UpdateUnitProvider p : UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(true)) {
                        p.refresh(handle, true);
                    }
                    // close searching
                    dlg.dispose();
                } catch (IOException ex) {
                    LOG.log(Level.FINE, ex.getMessage(), ex);
                    if (!dlg.isVisible()) {
                        LOG.fine("dialog not visible => do nothing");
                        return;
                    }
                    DialogDescriptor networkProblem = new DialogDescriptor(// message
                    problemPanel(resolveTitle, networkproblem_message()), // title
                    networkproblem_header(), // modal
                    true, null);
                    networkProblem.setOptions(new Object[] { tryAgain, proxySettings, NotifyDescriptor.CANCEL_OPTION });
                    networkProblem.setAdditionalOptions(closingOptions);
                    networkProblem.setClosingOptions(fullClosingOptions);
                    networkProblem.setMessageType(NotifyDescriptor.WARNING_MESSAGE);
                    Dialog networkProblemDialog = DialogDisplayer.getDefault().createDialog(networkProblem);
                    networkProblemDialog.setVisible(true);
                    Object answer = networkProblem.getValue();
                    if (NotifyDescriptor.CANCEL_OPTION.equals(answer) || Arrays.asList(closingOptions).contains(answer) || answer.equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
                    {
                        LOG.fine("cancel network problem dialog");
                        searching.setValue(answer);
                        dlg.dispose();
                    } else if (tryAgain.equals(answer)) {
                        LOG.fine("try again searching");
                        RP.post(this);
                    } else {
                        assert false : "Unknown " + answer;
                    }
                }
            }
        });
        dlg.setVisible(true);
        handle.finish();
        if (NotifyDescriptor.CANCEL_OPTION.equals(searching.getValue()) || searching.getValue().equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
        {
            LOG.log(Level.FINE, "user canceled searching for {0}", cnbs);
            return showNoDownloadDialog(displayName, cnbs);
        } else if (Arrays.asList(closingOptions).contains(searching.getValue())) {
            return searching.getValue();
        }
        units = findModules(cnbs);
        if (units == null) {
            LOG.log(Level.FINE, "could not find {0} on any update site", cnbs);
            return showNoDownloadDialog(displayName, cnbs);
        }
    }
    List<UpdateUnit> toHandle = new ArrayList<UpdateUnit>(units);
    OperationContainer<OperationSupport> oc = null;
    for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
        UpdateUnit unit = it.next();
        // check if module installed
        if (unit.getInstalled() != null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine(unit.getInstalled() + " already installed. Is active? " + unit.getInstalled().isEnabled());
            }
            if (unit.getInstalled().isEnabled()) {
                it.remove();
                continue;
            } else {
                if (oc == null) {
                    oc = OperationContainer.createForEnable();
                }
                if (!oc.canBeAdded(unit, unit.getInstalled())) {
                    throw new OperationException(OperationException.ERROR_TYPE.ENABLE, "could not add " + unit.getInstalled() + " for activation");
                }
                for (UpdateElement req : oc.add(unit.getInstalled()).getRequiredElements()) {
                    oc.add(req);
                }
                it.remove();
                continue;
            }
        }
    }
    if (oc != null) {
        ProgressHandle activeHandle = ProgressHandleFactory.createHandle(displayName != null ? active_handle_single(displayName) : active_handle());
        Restarter restarter = oc.getSupport().doOperation(activeHandle);
        assert restarter == null : "No Restater need to make units active";
    }
    if (toHandle.isEmpty()) {
        return null;
    }
    OperationContainer<InstallSupport> ocInstall = OperationContainer.createForInstall();
    for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
        UpdateUnit unit = it.next();
        List<UpdateElement> updates = unit.getAvailableUpdates();
        if (updates.isEmpty()) {
            throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "no updates for " + unit);
        }
        UpdateElement element = updates.get(0);
        if (!ocInstall.canBeAdded(unit, element)) {
            throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "could not add " + element + " to updates");
        }
        for (UpdateElement req : ocInstall.add(element).getRequiredElements()) {
            ocInstall.add(req);
        }
        it.remove();
    }
    assert toHandle.isEmpty() : "These unit were not handled " + toHandle;
    if (!PluginManager.openInstallWizard(ocInstall)) {
        LOG.fine("user canceled PM");
        return showNoDownloadDialog(displayName, cnbs);
    }
    return null;
}
Also used : InstallSupport(org.netbeans.api.autoupdate.InstallSupport) UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) IOException(java.io.IOException) OperationSupport(org.netbeans.api.autoupdate.OperationSupport) UpdateUnitProvider(org.netbeans.api.autoupdate.UpdateUnitProvider) Restarter(org.netbeans.api.autoupdate.OperationSupport.Restarter) ProgressHandle(org.netbeans.api.progress.ProgressHandle) Dialog(java.awt.Dialog) DialogDescriptor(org.openide.DialogDescriptor) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 2 with OperationSupport

use of org.netbeans.api.autoupdate.OperationSupport in project netbeans-rcp-lite by outersky.

the class CustomHandleStep method handleOperation.

private boolean handleOperation() {
    final OperationSupport support = model.getCustomHandledContainer().getSupport();
    assert support != null;
    passed = false;
    Runnable performOperation = new Runnable() {

        public void run() {
            try {
                final ProgressHandle handle = ProgressHandleFactory.createHandle(isInstall ? getBundle("CustomHandleStep_Install_InstallingPlugins") : getBundle("CustomHandleStep_Uninstall_UninstallingPlugins"));
                JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
                JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
                JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
                handle.setInitialDelay(0);
                panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
                restarter = support.doOperation(handle);
                passed = true;
                panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("CustomHandleStep_Done")));
            } catch (OperationException ex) {
                log.log(Level.INFO, ex.getMessage(), ex);
                passed = false;
                errorMessage = ex.getLocalizedMessage();
            }
        }
    };
    performOperation.run();
    return passed;
}
Also used : ProgressHandle(org.netbeans.api.progress.ProgressHandle) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) OperationSupport(org.netbeans.api.autoupdate.OperationSupport) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 3 with OperationSupport

use of org.netbeans.api.autoupdate.OperationSupport in project constellation by constellation-app.

the class DeveloperOptionsPanel method masterResetButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void masterResetButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_masterResetButtonActionPerformed
    Collection<UpdateElement> toUninstall = new ArrayList<>();
    for (UpdateUnit unit : UpdateManager.getDefault().getUpdateUnits()) {
        String codeName = unit.getCodeName();
        if (!"au.gov.asd.tac.constellation.autoupdate".equals(codeName) && !codeName.startsWith("org.netbeans.") && !codeName.startsWith("org.openide.") && !codeName.startsWith("org.jdesktop.")) {
            UpdateElement element = unit.getInstalled();
            if (element != null) {
                toUninstall.add(element);
            }
        }
    }
    OperationContainer<OperationSupport> operationContainer = OperationContainer.createForUninstall();
    operationContainer.add(toUninstall);
    OperationSupport operationSupport = operationContainer.getSupport();
    try {
        operationSupport.doOperation(null);
    } catch (final OperationException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ArrayList(java.util.ArrayList) OperationSupport(org.netbeans.api.autoupdate.OperationSupport) OperationException(org.netbeans.api.autoupdate.OperationException)

Aggregations

OperationException (org.netbeans.api.autoupdate.OperationException)3 OperationSupport (org.netbeans.api.autoupdate.OperationSupport)3 ArrayList (java.util.ArrayList)2 JLabel (javax.swing.JLabel)2 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)2 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)2 ProgressHandle (org.netbeans.api.progress.ProgressHandle)2 Dialog (java.awt.Dialog)1 IOException (java.io.IOException)1 JComponent (javax.swing.JComponent)1 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)1 Restarter (org.netbeans.api.autoupdate.OperationSupport.Restarter)1 UpdateUnitProvider (org.netbeans.api.autoupdate.UpdateUnitProvider)1 DialogDescriptor (org.openide.DialogDescriptor)1