Search in sources :

Example 1 with OperationContainer

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

the class LazyOperationDescriptionStep method checkRealUpdates.

@SuppressWarnings("unchecked")
private void checkRealUpdates() {
    final Collection<String> problems = new ArrayList<String>();
    checkRealUpdatesTask = Installer.RP.post(new Runnable() {

        @Override
        public void run() {
            final Collection<UpdateElement> updateElementsForStore = new HashSet<UpdateElement>();
            final Collection<UpdateElement> updates = AutoupdateCheckScheduler.checkUpdateElements(operationType, problems, forceReload, updateElementsForStore);
            hasUpdates = updates != null && !updates.isEmpty();
            if (hasUpdates) {
                assert wd != null : "WizardDescriptor must found!";
                OperationContainer oc = OperationType.UPDATE == operationType ? OperationContainer.createForUpdate() : OperationContainer.createForInstall();
                boolean allOk = true;
                InstallUnitWizardModel model = new InstallUnitWizardModel(operationType, oc);
                for (UpdateElement el : updates) {
                    UpdateUnit uu = el.getUpdateUnit();
                    if (UpdateManager.TYPE.CUSTOM_HANDLED_COMPONENT == uu.getType()) {
                        allOk &= model.getCustomHandledContainer().canBeAdded(uu, el);
                    } else {
                        allOk &= oc.canBeAdded(uu, el);
                    }
                }
                hasUpdates = hasUpdates && allOk;
                if (allOk) {
                    for (UpdateElement el : updates) {
                        UpdateUnit uu = el.getUpdateUnit();
                        if (UpdateManager.TYPE.CUSTOM_HANDLED_COMPONENT == uu.getType()) {
                            model.getCustomHandledContainer().add(el);
                        } else {
                            oc.add(el);
                        }
                    }
                    model.getBaseContainer().listAll();
                    final WizardDescriptor.Iterator<WizardDescriptor> panels = new InstallUnitWizardIterator(model, true);
                    // call InstallUnitWizardIterator.compactPanels outside AWT
                    ((InstallUnitWizardIterator) panels).hasNext();
                    SwingUtilities.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            wd.setPanelsAndSettings(panels, wd);
                            fireChange();
                            LazyUnit.storeUpdateElements(operationType, updateElementsForStore);
                        }
                    });
                }
            }
        }
    });
    class TLAndR implements TaskListener, Runnable {

        @Override
        public void taskFinished(Task task) {
            task.removeTaskListener(this);
            if (!hasUpdates) {
                installModel = Collections.EMPTY_SET;
                new InstallUnitWizardModel(null, null).modifyOptionsForDoClose(wd);
                canClose = true;
                LazyUnit.storeLazyUnits(operationType, installModel);
                EventQueue.invokeLater(this);
            }
        }

        @Override
        public void run() {
            JPanel body;
            if (problems == null || problems.isEmpty()) {
                body = new OperationDescriptionPanel(// NOI18N
                getBundle("LazyOperationDescriptionStep_NoUpdates_Title"), // NOI18N
                getBundle("LazyOperationDescriptionStep_NoUpdates"), "", "", false);
            } else {
                body = new OperationDescriptionPanel(// NOI18N
                getBundle("LazyOperationDescriptionStep_NoUpdatesWithProblems_Title"), // NOI18N
                getBundle("LazyOperationDescriptionStep_NoUpdatesWithProblems"), "", "", false);
            }
            component.setBody(body);
            component.setWaitingState(false);
            fireChange();
        }
    }
    checkRealUpdatesTask.addTaskListener(new TLAndR());
}
Also used : JPanel(javax.swing.JPanel) Task(org.openide.util.Task) UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ArrayList(java.util.ArrayList) WizardDescriptor(org.openide.WizardDescriptor) OperationContainer(org.netbeans.api.autoupdate.OperationContainer) TaskListener(org.openide.util.TaskListener) HashSet(java.util.HashSet)

Example 2 with OperationContainer

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

the class OperationWizardModel method addRequiredElements.

private void addRequiredElements(Set<UpdateElement> elems) {
    OperationContainer baseContainer = getBaseContainer();
    OperationContainer customContainer = getCustomHandledContainer();
    OperationContainer installContainer = getInstallContainer();
    for (UpdateElement el : elems) {
        if (el == null || el.getUpdateUnit() == null) {
            Logger.getLogger(OperationWizardModel.class.getName()).log(Level.INFO, "UpdateElement " + el + " cannot be null" + (el == null ? "" : " or UpdateUnit " + el.getUpdateUnit() + " cannot be null"));
            continue;
        }
        if (UpdateManager.TYPE.CUSTOM_HANDLED_COMPONENT == el.getUpdateUnit().getType()) {
            customContainer.add(el);
        } else if (baseContainer.canBeAdded(el.getUpdateUnit(), el)) {
            baseContainer.add(el);
        } else if (installContainer != null && installContainer.canBeAdded(el.getUpdateUnit(), el)) {
            installContainer.add(el);
        }
    }
}
Also used : OperationContainer(org.netbeans.api.autoupdate.OperationContainer) UpdateElement(org.netbeans.api.autoupdate.UpdateElement)

Aggregations

OperationContainer (org.netbeans.api.autoupdate.OperationContainer)2 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JPanel (javax.swing.JPanel)1 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)1 WizardDescriptor (org.openide.WizardDescriptor)1 Task (org.openide.util.Task)1 TaskListener (org.openide.util.TaskListener)1