Skip to content

Commit f9612bc

Browse files
author
Federico Fissore
committed
Updatable boards support and libraries notification
1 parent b68cf12 commit f9612bc

File tree

11 files changed

+522
-35
lines changed

11 files changed

+522
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cc.arduino;
2+
3+
import processing.app.Base;
4+
5+
import javax.swing.event.HyperlinkEvent;
6+
import javax.swing.event.HyperlinkListener;
7+
import java.net.URL;
8+
9+
public class UpdatableBoardsLibsFakeURLsHandler implements HyperlinkListener {
10+
11+
private static final String BOARDSMANAGER = "boardsmanager";
12+
private static final String LIBRARYMANAGER = "librarymanager";
13+
14+
private final Base base;
15+
16+
public UpdatableBoardsLibsFakeURLsHandler(Base base) {
17+
this.base = base;
18+
}
19+
20+
@Override
21+
public void hyperlinkUpdate(HyperlinkEvent event) {
22+
if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
23+
return;
24+
}
25+
26+
URL url = event.getURL();
27+
28+
if (BOARDSMANAGER.equals(url.getHost())) {
29+
try {
30+
base.openBoardsManager("", "DropdownUpdatableCoresItem");
31+
} catch (Exception e) {
32+
e.printStackTrace();
33+
}
34+
return;
35+
}
36+
37+
if (LIBRARYMANAGER.equals(url.getHost())) {
38+
base.openLibraryManager("DropdownUpdatableLibrariesItem");
39+
return;
40+
}
41+
42+
throw new IllegalArgumentException(url.getHost() + " is invalid");
43+
}
44+
45+
}

app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ private void builtInPackageIsNewerCheck() throws InterruptedException {
9292
assert base.hasActiveEditor();
9393
int chosenOption = JOptionPane.showConfirmDialog(base.getActiveEditor(), I18n.format(tr("The IDE includes an updated {0} package, but you're using an older one.\nDo you want to upgrade {0}?"), installedBuiltIn.getName()), I18n.format(tr("A newer {0} package is available"), installedBuiltIn.getName()), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
9494
if (chosenOption == JOptionPane.YES_OPTION) {
95-
Action openBoardsManager = base.getOpenBoardsManager();
96-
Event event = new Event(base.getActiveEditor(), ActionEvent.ACTION_PERFORMED, installedBuiltIn.getName());
97-
event.getPayload().put("filterText", installedBuiltIn.getName());
98-
openBoardsManager.actionPerformed(event);
95+
try {
96+
base.openBoardsManager(installedBuiltIn.getName(), "");
97+
} catch (Exception e) {
98+
e.printStackTrace();
99+
}
99100
}
100101
});
101102
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package cc.arduino.contributions;
2+
3+
import cc.arduino.contributions.libraries.LibrariesIndexer;
4+
import cc.arduino.contributions.libraries.LibraryInstaller;
5+
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
6+
import cc.arduino.contributions.packages.ContributionInstaller;
7+
import cc.arduino.contributions.packages.ContributionsIndexer;
8+
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
9+
import cc.arduino.view.NotificationPopup;
10+
import processing.app.Base;
11+
import processing.app.I18n;
12+
13+
import javax.swing.*;
14+
import javax.swing.event.HyperlinkListener;
15+
import java.util.TimerTask;
16+
17+
import static processing.app.I18n._;
18+
19+
public class ContributionsSelfCheck extends TimerTask {
20+
21+
private final Base base;
22+
private final HyperlinkListener hyperlinkListener;
23+
private final ContributionsIndexer contributionsIndexer;
24+
private final ContributionInstaller contributionInstaller;
25+
private final LibrariesIndexer librariesIndexer;
26+
private final LibraryInstaller libraryInstaller;
27+
28+
public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, ContributionsIndexer contributionsIndexer, ContributionInstaller contributionInstaller, LibrariesIndexer librariesIndexer, LibraryInstaller libraryInstaller) {
29+
this.base = base;
30+
this.hyperlinkListener = hyperlinkListener;
31+
this.contributionsIndexer = contributionsIndexer;
32+
this.contributionInstaller = contributionInstaller;
33+
this.librariesIndexer = librariesIndexer;
34+
this.libraryInstaller = libraryInstaller;
35+
}
36+
37+
@Override
38+
public void run() {
39+
updateContributionIndex();
40+
updateLibrariesIndex();
41+
42+
long updatablePlatforms = contributionsIndexer.getPackages().stream()
43+
.flatMap(pack -> pack.getPlatforms().stream())
44+
.filter(new UpdatablePlatformPredicate(contributionsIndexer)).count();
45+
46+
long updatableLibraries = librariesIndexer.getInstalledLibraries().stream()
47+
.filter(new UpdatableLibraryPredicate(librariesIndexer))
48+
.count();
49+
50+
if (updatableLibraries <= 0 && updatablePlatforms <= 0) {
51+
return;
52+
}
53+
54+
String text;
55+
if (updatableLibraries > 0 && updatablePlatforms <= 0) {
56+
text = I18n.format(_("Some {0}libraries{1} may be updated"), "<a href=\"http://librarymanager\">", "</a>");
57+
} else if (updatableLibraries <= 0 && updatablePlatforms > 0) {
58+
text = I18n.format(_("Some {0}boards{1} may be updated"), "<a href=\"http://boardsmanager\">", "</a>");
59+
} else {
60+
text = I18n.format(_("Some {0}boards{1} and some {2}libraries{3} may be updated"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
61+
}
62+
63+
SwingUtilities.invokeLater(() -> {
64+
new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), text).setVisible(true);
65+
});
66+
}
67+
68+
private void updateLibrariesIndex() {
69+
try {
70+
libraryInstaller.updateIndex();
71+
} catch (Exception e) {
72+
// ignore
73+
}
74+
}
75+
76+
private void updateContributionIndex() {
77+
try {
78+
contributionInstaller.updateIndex();
79+
} catch (Exception e) {
80+
// ignore
81+
}
82+
}
83+
}

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void actionPerformed(ActionEvent event) {
125125
@Override
126126
public void updateIndexFilter(String[] filters, Predicate<ContributedLibrary>... additionalFilters) {
127127
if (additionalFilters.length == 1) {
128-
additionalFilters = new Predicate[] { additionalFilters[0], typeFilter };
128+
additionalFilters = new Predicate[]{additionalFilters[0], typeFilter};
129129
}
130130
super.updateIndexFilter(filters, additionalFilters);
131131
}
@@ -191,18 +191,14 @@ public void onProgress(Progress progress) {
191191
};
192192
}
193193

194-
public LibrariesIndexer getIndexer() {
195-
return indexer;
194+
public void selectDropdownItemByClassName(String dropdownItem) {
195+
selectDropdownItemByClassName(typeChooser, dropdownItem);
196196
}
197197

198198
public void setProgress(Progress progress) {
199199
progressBar.setValue(progress);
200200
}
201201

202-
/*
203-
* Installer methods follows
204-
*/
205-
206202
private LibraryInstaller installer;
207203
private Thread installerThread = null;
208204

app/src/cc/arduino/contributions/ui/InstallerJDialog.java

+13
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ public void setFilterText(String filterText) {
276276
filterField.setText(filterText);
277277
}
278278

279+
public void selectDropdownItemByClassName(String dropdownItem) {
280+
selectDropdownItemByClassName(categoryChooser, dropdownItem);
281+
}
282+
283+
public void selectDropdownItemByClassName(JComboBox combo, String dropdownItem) {
284+
for (int i = 0; i < combo.getItemCount(); i++) {
285+
if (dropdownItem.equals(combo.getItemAt(i).getClass().getSimpleName())) {
286+
combo.setSelectedIndex(i);
287+
return;
288+
}
289+
}
290+
}
291+
279292
/**
280293
* Action performed when the Cancel button is pressed.
281294
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
4+
<Properties>
5+
<Property name="defaultCloseOperation" type="int" value="2"/>
6+
<Property name="alwaysOnTop" type="boolean" value="true"/>
7+
<Property name="focusable" type="boolean" value="false"/>
8+
<Property name="focusableWindowState" type="boolean" value="false"/>
9+
<Property name="undecorated" type="boolean" value="true"/>
10+
<Property name="resizable" type="boolean" value="false"/>
11+
</Properties>
12+
<SyntheticProperties>
13+
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
14+
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
15+
</SyntheticProperties>
16+
<AuxValues>
17+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
18+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
19+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
20+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
21+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
22+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
23+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
24+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
25+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
26+
</AuxValues>
27+
28+
<Layout>
29+
<DimensionLayout dim="0">
30+
<Group type="103" groupAlignment="0" attributes="0">
31+
<Group type="102" attributes="0">
32+
<EmptySpace max="-2" attributes="0"/>
33+
<Component id="jLabel1" min="-2" pref="48" max="-2" attributes="0"/>
34+
<EmptySpace max="-2" attributes="0"/>
35+
<Group type="103" groupAlignment="0" attributes="0">
36+
<Group type="102" attributes="0">
37+
<Component id="text" min="-2" pref="264" max="-2" attributes="0"/>
38+
<EmptySpace max="32767" attributes="0"/>
39+
</Group>
40+
<Group type="102" alignment="0" attributes="0">
41+
<Component id="title" max="32767" attributes="0"/>
42+
<EmptySpace min="-2" pref="24" max="-2" attributes="0"/>
43+
<Component id="closeButton" min="-2" max="-2" attributes="0"/>
44+
</Group>
45+
</Group>
46+
</Group>
47+
</Group>
48+
</DimensionLayout>
49+
<DimensionLayout dim="1">
50+
<Group type="103" groupAlignment="0" attributes="0">
51+
<Group type="102" attributes="0">
52+
<Group type="103" groupAlignment="0" attributes="0">
53+
<Group type="102" attributes="0">
54+
<Group type="103" groupAlignment="0" attributes="0">
55+
<Group type="102" attributes="0">
56+
<EmptySpace max="-2" attributes="0"/>
57+
<Component id="title" min="-2" max="-2" attributes="0"/>
58+
</Group>
59+
<Component id="closeButton" alignment="0" min="-2" max="-2" attributes="0"/>
60+
</Group>
61+
<EmptySpace max="-2" attributes="0"/>
62+
<Component id="text" min="-2" pref="42" max="-2" attributes="0"/>
63+
</Group>
64+
<Group type="102" alignment="0" attributes="0">
65+
<EmptySpace max="-2" attributes="0"/>
66+
<Component id="jLabel1" min="-2" pref="48" max="-2" attributes="0"/>
67+
</Group>
68+
</Group>
69+
<EmptySpace max="32767" attributes="0"/>
70+
</Group>
71+
</Group>
72+
</DimensionLayout>
73+
</Layout>
74+
<SubComponents>
75+
<Component class="javax.swing.JLabel" name="title">
76+
<Properties>
77+
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
78+
<FontInfo relative="true">
79+
<Font bold="true" component="title" property="font" relativeSize="true" size="0"/>
80+
</FontInfo>
81+
</Property>
82+
</Properties>
83+
</Component>
84+
<Component class="javax.swing.JLabel" name="jLabel1">
85+
<Properties>
86+
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
87+
<Connection code="new ImageIcon(Paths.get(BaseNoGui.getContentFile(&quot;lib&quot;).getAbsolutePath(), &quot;arduino_small.png&quot;).toFile().getAbsolutePath())" type="code"/>
88+
</Property>
89+
</Properties>
90+
<AuxValues>
91+
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
92+
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
93+
</AuxValues>
94+
</Component>
95+
<Component class="javax.swing.JEditorPane" name="text">
96+
<Properties>
97+
<Property name="editable" type="boolean" value="false"/>
98+
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
99+
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
100+
<LineBorder roundedCorners="true" thickness="0"/>
101+
</Border>
102+
</Property>
103+
<Property name="contentType" type="java.lang.String" value="text/html" noResource="true"/>
104+
<Property name="opaque" type="boolean" value="false"/>
105+
</Properties>
106+
</Component>
107+
<Component class="javax.swing.JButton" name="closeButton">
108+
<Properties>
109+
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
110+
<Connection code="new ImageIcon(Paths.get(BaseNoGui.getContentFile(&quot;lib&quot;).getAbsolutePath(), &quot;theme&quot;, &quot;close.png&quot;).toFile().getAbsolutePath())" type="code"/>
111+
</Property>
112+
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
113+
<Border info="null"/>
114+
</Property>
115+
<Property name="borderPainted" type="boolean" value="false"/>
116+
<Property name="hideActionText" type="boolean" value="true"/>
117+
</Properties>
118+
<Events>
119+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="closeButtonActionPerformed"/>
120+
</Events>
121+
</Component>
122+
</SubComponents>
123+
</Form>

0 commit comments

Comments
 (0)