Search in sources :

Example 6 with OperationException

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

the class PluginManager method install.

/**
 * Open standard dialog for installing modules including declared dependencies.
 * Shows it to the user, asks for confirmation, license acceptance, etc.
 * The whole operation requires AWT dispatch thread access (to show the dialog)
 * and blocks (until the user clicks through), so either call from AWT dispatch
 * thread directly, or be sure you hold no locks and block no progress of other
 * threads to avoid deadlocks.
 *
 * @param codenamebases the codenamebases of modules to install; must contain at least
 *             one codenamebase
 * @param alternativeOptions alternative options possibly displayed in error
 *             dialog user may choose if it is not possible to install the plugin;
 *             if chosen the option is return value of this method
 * @return <code>null</code> if all the requested modules have been successfully
 *             installed and/or activated, otherwise it returns the options user has
 *             selected in problem dialog, typically {@link NotifyDescriptor#DEFAULT_OPTION}
 *             (on esc), {@link NotifyDescriptor#CANCEL_OPTION} or
 *             any of <code>alternativeOptions</code>.
 * @throws IllegalArgumentException if the <code>codenamebases</code> is empty
 * @since 1.35
 */
@CheckForNull
public static Object install(@NonNull Set<String> codenamebases, @NonNull Object... alternativeOptions) {
    Parameters.notNull("cnb", codenamebases);
    Parameters.notNull("alternativeOptions", alternativeOptions);
    if (codenamebases.isEmpty()) {
        throw new IllegalArgumentException("No plugins to install");
    }
    try {
        return new ModuleInstallerSupport(alternativeOptions).installPlugins(null, codenamebases);
    } catch (OperationException ex) {
        Logger.getLogger(PluginManager.class.getName()).log(Level.WARNING, null, ex);
    }
    return NotifyDescriptor.DEFAULT_OPTION;
}
Also used : ModuleInstallerSupport(org.netbeans.modules.autoupdate.ui.ModuleInstallerSupport) OperationException(org.netbeans.api.autoupdate.OperationException) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Example 7 with OperationException

use of org.netbeans.api.autoupdate.OperationException 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 8 with OperationException

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

the class UninstallStep method handleAction.

@NbBundle.Messages({ "UninstallStep_NullSupport_NullElements=Not found any elements for that operation.", "# {0} - invalid elements", "UninstallStep_NullSupport_InvalidElements=Found invalid element(s) {0} for that operation.", "UninstallStep_ProgressName_Uninstall=Uninstalling plugins", "UninstallStep_ProgressName_Activate=Activating plugins", "UninstallStep_ProgressName_Deactivate=Deactivating plugins", "UninstallStep_Done=Done.", "# {0} - A error message", "UninstallStep_Failed=Failed. {0}" })
private Restarter handleAction() throws OperationException {
    assert model.getBaseContainer() != null : "getBaseContainers() returns not null container.";
    support = (OperationSupport) model.getBaseContainer().getSupport();
    assert support != null : "OperationSupport cannot be null because OperationContainer " + "contains elements: " + model.getBaseContainer().listAll() + " and invalid elements " + model.getBaseContainer().listInvalid();
    if (support == null) {
        err.log(Level.WARNING, "OperationSupport cannot be null because OperationContainer contains elements: " + "{0} and invalid elements {1}", new Object[] { model.getBaseContainer().listAll(), model.getBaseContainer().listInvalid() });
        if (!model.getBaseContainer().listInvalid().isEmpty()) {
            // cannot continue if there are invalid elements
            throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL, UninstallStep_NullSupport_InvalidElements(model.getBaseContainer().listInvalid()));
        } else if (model.getBaseContainer().listAll().isEmpty()) {
            // it's weird, there must be any elemets for uninstall
            throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL, UninstallStep_NullSupport_NullElements());
        }
        throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL, "OperationSupport cannot be null because OperationContainer " + "contains elements: " + model.getBaseContainer().listAll() + " and invalid elements " + model.getBaseContainer().listInvalid());
    }
    ProgressHandle handle = null;
    switch(model.getOperation()) {
        case UNINSTALL:
            handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Uninstall());
            break;
        case ENABLE:
            handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Activate());
            break;
        case DISABLE:
            handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Deactivate());
            break;
        default:
            assert false : "Unknown OperationType " + model.getOperation();
    }
    JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
    JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
    JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
    model.modifyOptionsForDisabledCancel(wd);
    panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
    Restarter r = null;
    try {
        r = support.doOperation(handle);
        panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(UninstallStep_Done()));
    } catch (OperationException ex) {
        err.log(Level.INFO, ex.getMessage(), ex);
        panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(UninstallStep_Failed(ex.getLocalizedMessage())));
        throw ex;
    }
    return r;
}
Also used : Restarter(org.netbeans.api.autoupdate.OperationSupport.Restarter) ProgressHandle(org.netbeans.api.progress.ProgressHandle) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 9 with OperationException

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

the class UninstallStep method doAction.

private void doAction() {
    // proceed operation
    Restarter r;
    try {
        if ((r = handleAction()) != null) {
            presentActionNeedsRestart(r);
        } else {
            presentActionDone();
        }
    } catch (OperationException ex) {
        presentActionFailed(ex);
    }
    fireChange();
}
Also used : Restarter(org.netbeans.api.autoupdate.OperationSupport.Restarter) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 10 with OperationException

use of org.netbeans.api.autoupdate.OperationException 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)13 JLabel (javax.swing.JLabel)6 ProgressHandle (org.netbeans.api.progress.ProgressHandle)6 JComponent (javax.swing.JComponent)5 Restarter (org.netbeans.api.autoupdate.OperationSupport.Restarter)4 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3 ArrayList (java.util.ArrayList)3 OperationSupport (org.netbeans.api.autoupdate.OperationSupport)3 Dialog (java.awt.Dialog)2 File (java.io.File)2 JarFile (java.util.jar.JarFile)2 JButton (javax.swing.JButton)2 CheckForNull (org.netbeans.api.annotations.common.CheckForNull)2 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)2 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)2 ModuleInstallerSupport (org.netbeans.modules.autoupdate.ui.ModuleInstallerSupport)2 ProblemPanel (org.netbeans.modules.autoupdate.ui.ProblemPanel)2 DialogDescriptor (org.openide.DialogDescriptor)2