Search in sources :

Example 1 with UpdateUnitProvider

use of org.netbeans.api.autoupdate.UpdateUnitProvider 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 UpdateUnitProvider

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

the class SettingsTableModel method remove.

public void remove(int rowIndex) {
    UpdateUnitProvider unitProvider = getUpdateUnitProvider(rowIndex);
    if (unitProvider != null) {
        UpdateUnitProviderFactory.getDefault().remove(unitProvider);
    }
    getSettingsTab().setNeedRefresh();
}
Also used : UpdateUnitProvider(org.netbeans.api.autoupdate.UpdateUnitProvider)

Example 3 with UpdateUnitProvider

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

the class SettingsTableModel method setValueAt.

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    final UpdateUnitProvider unitProvider = getUpdateUnitProvider(rowIndex);
    switch(columnIndex) {
        case 0:
            boolean oldValue = unitProvider.isEnabled();
            boolean newValue = ((Boolean) aValue).booleanValue();
            if (oldValue != newValue) {
                unitProvider.setEnable(newValue);
                if (newValue) {
                    // was not enabled and will be -> add it to model and read its content
                    getSettingsTab().refreshProvider(unitProvider, false);
                } else {
                    // was enabled -> remove from model and refresh
                    // getSettingsTab ().setNeedRefresh ();
                    getSettingsTab().refreshProvider(unitProvider, false);
                }
            }
            break;
    }
}
Also used : UpdateUnitProvider(org.netbeans.api.autoupdate.UpdateUnitProvider)

Example 4 with UpdateUnitProvider

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

the class SettingsTableModel method add.

public void add(String name, String displayName, URL url, boolean state) {
    final UpdateUnitProvider uup = UpdateUnitProviderFactory.getDefault().create(name, displayName, url);
    uup.setEnable(state);
}
Also used : UpdateUnitProvider(org.netbeans.api.autoupdate.UpdateUnitProvider)

Example 5 with UpdateUnitProvider

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

the class SettingsTableModel method refreshModel.

void refreshModel() {
    Set<String> oldValue = originalProviders;
    Set<String> newValue = new HashSet<String>();
    final List<UpdateUnitProvider> forRefresh = new ArrayList<UpdateUnitProvider>();
    List<UpdateUnitProvider> providers = UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(false);
    for (UpdateUnitProvider p : providers) {
        if (oldValue != null && !oldValue.contains(p.getName())) {
            // new one provider
            if (p.isEnabled()) {
                forRefresh.add(p);
            }
        }
        newValue.add(p.getName());
    }
    if (!forRefresh.isEmpty()) {
        getSettingsTab().setWaitingState(true);
        Utilities.startAsWorkerThread(new Runnable() {

            @Override
            public void run() {
                try {
                    Utilities.presentRefreshProviders(forRefresh, getSettingsTab().getPluginManager(), true);
                    getSettingsTab().getPluginManager().updateUnitsChanged();
                } finally {
                    getSettingsTab().setWaitingState(false);
                }
            }
        });
    }
    // check removed providers
    if (oldValue != null && !oldValue.isEmpty() && !newValue.containsAll(oldValue)) {
        getSettingsTab().setNeedRefresh();
    }
    updateProviders = new ArrayList<UpdateUnitProvider>();
    for (UpdateUnitProvider p : providers) {
        if (p.getDisplayName() != null) {
            updateProviders.add(p);
        }
    }
    originalProviders = newValue;
    sortAlphabetically(updateProviders);
    fireTableDataChanged();
}
Also used : ArrayList(java.util.ArrayList) UpdateUnitProvider(org.netbeans.api.autoupdate.UpdateUnitProvider) HashSet(java.util.HashSet)

Aggregations

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