Search in sources :

Example 26 with UpdateUnit

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

Aggregations

UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)26 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)13 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 ModuleInfo (org.openide.modules.ModuleInfo)5 Module (org.netbeans.Module)4 DummyModuleInfo (org.netbeans.modules.autoupdate.updateprovider.DummyModuleInfo)4 IOException (java.io.IOException)3 TreeSet (java.util.TreeSet)3 UpdateUnitProvider (org.netbeans.api.autoupdate.UpdateUnitProvider)3 File (java.io.File)2 JarFile (java.util.jar.JarFile)2 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)2 OperationException (org.netbeans.api.autoupdate.OperationException)2 OperationSupport (org.netbeans.api.autoupdate.OperationSupport)2 ProgressHandle (org.netbeans.api.progress.ProgressHandle)2 Dialog (java.awt.Dialog)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 TreeMap (java.util.TreeMap)1