-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
PluginsGroup.java
91 lines (78 loc) · 2.45 KB
/
PluginsGroup.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.plugins.newui;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.components.labels.LinkLabel;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author Alexander Lobas
*/
public class PluginsGroup {
protected final String myTitlePrefix;
public String title;
public JLabel titleLabel;
public LinkLabel<Object> rightAction;
public List<JComponent> rightActions;
public final List<IdeaPluginDescriptor> descriptors = new ArrayList<>();
public UIPluginGroup ui;
public Runnable clearCallback;
public PluginsGroup(@NotNull @Nls String title) {
myTitlePrefix = title;
this.title = title;
}
public void clear() {
ui = null;
descriptors.clear();
titleLabel = null;
rightAction = null;
rightActions = null;
if (clearCallback != null) {
clearCallback.run();
clearCallback = null;
}
}
public void addRightAction(@NotNull JComponent component) {
if (rightActions == null) {
rightActions = new ArrayList<>();
}
rightActions.add(component);
}
public void titleWithCount() {
title = myTitlePrefix + " (" + descriptors.size() + ")";
updateTitle();
}
public void titleWithEnabled(@NotNull MyPluginModel pluginModel) {
int enabled = 0;
for (IdeaPluginDescriptor descriptor : descriptors) {
if (pluginModel.isEnabled(descriptor)) {
enabled++;
}
}
titleWithCount(enabled);
}
public void titleWithCount(int enabled) {
title = myTitlePrefix + " (" + enabled + " of " + descriptors.size() + " enabled)";
updateTitle();
}
protected void updateTitle() {
if (titleLabel != null) {
titleLabel.setText(title);
}
}
public int addWithIndex(@NotNull IdeaPluginDescriptor descriptor) {
descriptors.add(descriptor);
sortByName();
return descriptors.indexOf(descriptor);
}
public void sortByName() {
sortByName(descriptors);
}
public static void sortByName(@NotNull List<? extends IdeaPluginDescriptor> descriptors) {
ContainerUtil.sort(descriptors, (o1, o2) -> StringUtil.compare(o1.getName(), o2.getName(), true));
}
}