OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 149
Line 16... Line 16...
16
import org.openconcerto.ui.JLabelBold;
16
import org.openconcerto.ui.JLabelBold;
17
import org.openconcerto.ui.VFlowLayout;
17
import org.openconcerto.ui.VFlowLayout;
18
 
18
 
19
import java.util.ArrayList;
19
import java.util.ArrayList;
20
import java.util.Collections;
20
import java.util.Collections;
-
 
21
import java.util.HashMap;
21
import java.util.List;
22
import java.util.List;
-
 
23
import java.util.Map;
-
 
24
import java.util.Set;
22
 
25
 
23
import javax.swing.JLabel;
26
import javax.swing.JLabel;
24
import javax.swing.JPanel;
27
import javax.swing.JPanel;
25
 
28
 
26
public class DepSolverResultPanel extends JPanel {
29
public class DepSolverResultPanel extends JPanel {
27
 
30
 
28
    public DepSolverResultPanel(DepSolverResultMM depSolverResult) {
31
    public DepSolverResultPanel(DepSolverResultMM depSolverResult) {
29
        this.setLayout(new VFlowLayout());
32
        this.setLayout(new VFlowLayout());
30
        final List<ModuleReference> lInstall = new ArrayList<ModuleReference>(depSolverResult.getReferencesToInstall());
-
 
31
        Collections.sort(lInstall, ModuleReference.COMP_ID_ASC_VERSION_DESC);
-
 
32
        if (lInstall.size() > 0) {
-
 
33
            if (lInstall.size() == 1) {
-
 
34
                this.add(new JLabelBold("Installation du module " + ModulePanel.format(lInstall.get(0))));
-
 
35
            } else {
-
 
36
                this.add(new JLabelBold("Modules à installer :"));
-
 
37
                for (ModuleReference moduleReference : lInstall) {
-
 
38
                    this.add(new JLabel("- " + ModulePanel.format(moduleReference)));
-
 
39
                }
-
 
40
            }
-
 
41
 
33
 
-
 
34
        final Set<String> idsToInstall = depSolverResult.getIDsToInstall();
-
 
35
        final Map<String, ModuleVersion> versionsToUpgrade = new HashMap<>();
-
 
36
        final List<ModuleReference> lRemove = new ArrayList<>();
-
 
37
        for (final ModuleReference ref : depSolverResult.getReferencesToRemove()) {
-
 
38
            if (idsToInstall.contains(ref.getID()))
-
 
39
                versionsToUpgrade.put(ref.getID(), ref.getVersion());
-
 
40
            else
-
 
41
                lRemove.add(ref);
42
        }
42
        }
-
 
43
        final List<ModuleReference> lInstall = new ArrayList<>();
-
 
44
        final List<ModuleReference> lUpgrade = new ArrayList<>();
-
 
45
        for (final ModuleReference ref : depSolverResult.getReferencesToInstall()) {
-
 
46
            (versionsToUpgrade.containsKey(ref.getID()) ? lUpgrade : lInstall).add(ref);
-
 
47
        }
43
 
48
 
44
        final List<ModuleReference> lRemove = new ArrayList<ModuleReference>(depSolverResult.getReferencesToRemove());
49
        addLabels(lUpgrade, versionsToUpgrade, "Mise à jour du module ", "Modules à mettre à jour :");
-
 
50
        addLabels(lInstall, null, "Installation du module ", "Modules à installer :");
45
        Collections.sort(lRemove, ModuleReference.COMP_ID_ASC_VERSION_DESC);
51
        addLabels(lRemove, null, "Désinstallation du module ", "Modules à désinstaller :");
-
 
52
    }
-
 
53
 
-
 
54
    private void addLabels(final List<ModuleReference> l, final Map<String, ModuleVersion> oldVersions, final String single, final String multi) {
46
        if (lRemove.size() > 0) {
55
        if (l.isEmpty())
-
 
56
            return;
47
            if (lRemove.size() == 1) {
57
        if (l.size() == 1) {
48
                this.add(new JLabelBold("Désinstallation du module " + ModulePanel.format(lInstall.get(0))));
58
            this.add(new JLabelBold(single + getVersionString(l.get(0), oldVersions)));
49
            } else {
59
        } else {
50
                this.add(new JLabelBold("Modules à désinstaller :"));
60
            this.add(new JLabelBold(multi));
-
 
61
            Collections.sort(l, ModuleReference.COMP_ID_ASC_VERSION_DESC);
51
                for (ModuleReference moduleReference : lRemove) {
62
            for (ModuleReference moduleReference : l) {
52
                    this.add(new JLabel("- " + ModulePanel.format(moduleReference)));
63
                this.add(new JLabel("- " + getVersionString(moduleReference, oldVersions)));
53
                }
64
            }
54
            }
65
        }
55
 
-
 
56
        }
66
    }
57
 
67
 
-
 
68
    static private final String getVersionString(final ModuleReference ref, final Map<String, ModuleVersion> oldVersions) {
-
 
69
        if (oldVersions == null)
-
 
70
            return ModulePanel.format(ref);
-
 
71
        return ref.getID() + " (" + oldVersions.get(ref.getID()) + " -> " + ref.getVersion() + ")";
58
    }
72
    }
59
 
-
 
60
}
73
}