Skip to content

Commit e9f5639

Browse files
cmagliefacchinm
authored andcommitted
Added library dependencies install dialog
1 parent ec96eae commit e9f5639

File tree

3 files changed

+190
-6
lines changed

3 files changed

+190
-6
lines changed

Diff for: app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
211211
}
212212
}
213213

214+
// TODO Make this a method of Theme
214215
private JTextPane makeNewDescription() {
215216
if (getComponentCount() > 0) {
216217
remove(0);

Diff for: app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import cc.arduino.contributions.libraries.ContributedLibrary;
5252
import cc.arduino.contributions.libraries.LibraryInstaller;
5353
import cc.arduino.contributions.libraries.LibraryTypeComparator;
54+
import cc.arduino.contributions.libraries.ui.MultiLibraryInstallDialog.Result;
5455
import cc.arduino.contributions.ui.DropdownAllItem;
5556
import cc.arduino.contributions.ui.DropdownItem;
5657
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
@@ -223,18 +224,23 @@ protected void onUpdatePressed() {
223224

224225
public void onInstallPressed(final ContributedLibrary lib) {
225226
List<ContributedLibrary> deps = BaseNoGui.librariesIndexer.getIndex().resolveDependeciesOf(lib);
226-
final boolean installDeps;
227-
if (deps.size() > 1) {
228-
System.out.println("The library requires dependencies!");
229-
installDeps = true;
227+
boolean depsInstalled = deps.stream().allMatch(l -> l.isInstalled() || l.getName().equals(lib.getName()));
228+
Result installDeps;
229+
if (!depsInstalled) {
230+
MultiLibraryInstallDialog dialog;
231+
dialog = new MultiLibraryInstallDialog(this, lib, deps);
232+
dialog.setVisible(true);
233+
installDeps = dialog.getInstallDepsResult();
234+
if (installDeps == Result.CANCEL)
235+
return;
230236
} else {
231-
installDeps = false;
237+
installDeps = Result.NONE;
232238
}
233239
clearErrorMessage();
234240
installerThread = new Thread(() -> {
235241
try {
236242
setProgressVisible(true, tr("Installing..."));
237-
if (installDeps) {
243+
if (installDeps == Result.ALL) {
238244
installer.install(deps, this::setProgress);
239245
} else {
240246
installer.install(lib, this::setProgress);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2017 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.contributions.libraries.ui;
31+
32+
import static processing.app.I18n.format;
33+
import static processing.app.I18n.tr;
34+
35+
import java.awt.BorderLayout;
36+
import java.awt.Container;
37+
import java.awt.Insets;
38+
import java.awt.Window;
39+
import java.awt.event.WindowEvent;
40+
import java.util.List;
41+
42+
import javax.swing.Box;
43+
import javax.swing.BoxLayout;
44+
import javax.swing.JButton;
45+
import javax.swing.JDialog;
46+
import javax.swing.JPanel;
47+
import javax.swing.JTextPane;
48+
import javax.swing.WindowConstants;
49+
import javax.swing.border.EmptyBorder;
50+
import javax.swing.text.Document;
51+
import javax.swing.text.html.HTMLDocument;
52+
import javax.swing.text.html.StyleSheet;
53+
54+
import cc.arduino.contributions.libraries.ContributedLibrary;
55+
import cc.arduino.contributions.libraries.UnavailableContributedLibrary;
56+
import processing.app.Base;
57+
import processing.app.Theme;
58+
59+
public class MultiLibraryInstallDialog extends JDialog {
60+
61+
enum Result {
62+
ALL, NONE, CANCEL
63+
}
64+
65+
Result result = Result.CANCEL;
66+
67+
public MultiLibraryInstallDialog(Window parent, ContributedLibrary lib,
68+
List<ContributedLibrary> dependencies) {
69+
super(parent, format(tr("Dependencies for library {0}:{1}"), lib.getName(),
70+
lib.getParsedVersion()),
71+
ModalityType.APPLICATION_MODAL);
72+
Container pane = getContentPane();
73+
pane.setLayout(new BorderLayout());
74+
75+
pane.add(Box.createHorizontalStrut(10), BorderLayout.WEST);
76+
pane.add(Box.createHorizontalStrut(10), BorderLayout.EAST);
77+
78+
{
79+
JButton cancel = new JButton(tr("Cancel"));
80+
cancel.addActionListener(ev -> {
81+
result = Result.CANCEL;
82+
setVisible(false);
83+
});
84+
85+
JButton all = new JButton(tr("Install all"));
86+
all.addActionListener(ev -> {
87+
result = Result.ALL;
88+
setVisible(false);
89+
});
90+
91+
JButton none = new JButton(format(tr("Install '{0}' only"), lib.getName()));
92+
none.addActionListener(ev -> {
93+
result = Result.NONE;
94+
setVisible(false);
95+
});
96+
97+
Box buttonsBox = Box.createHorizontalBox();
98+
buttonsBox.add(all);
99+
buttonsBox.add(Box.createHorizontalStrut(5));
100+
buttonsBox.add(none);
101+
buttonsBox.add(Box.createHorizontalStrut(5));
102+
buttonsBox.add(cancel);
103+
104+
JPanel buttonsPanel = new JPanel();
105+
buttonsPanel.setBorder(new EmptyBorder(7, 10, 7, 10));
106+
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.Y_AXIS));
107+
buttonsPanel.add(buttonsBox);
108+
109+
pane.add(buttonsPanel, BorderLayout.SOUTH);
110+
}
111+
112+
{
113+
String libName = format("<b>{0}:{1}</b>", lib.getName(),
114+
lib.getParsedVersion());
115+
String desc = format(tr("The library {0} needs some other library<br />dependencies currently not installed:"),
116+
libName);
117+
desc += "<br/><br/>";
118+
for (ContributedLibrary l : dependencies) {
119+
if (l.getName().equals(lib.getName()))
120+
continue;
121+
if (l.isInstalled())
122+
continue;
123+
if (l instanceof UnavailableContributedLibrary)
124+
continue;
125+
desc += format("- <b>{0}</b><br/>", l.getName());
126+
}
127+
desc += "<br/>";
128+
desc += tr("Would you like to install also all the missing dependencies?");
129+
130+
JTextPane textArea = makeNewDescription();
131+
textArea.setContentType("text/html");
132+
textArea.setText(desc);
133+
134+
JPanel libsList = new JPanel();
135+
libsList.setLayout(new BoxLayout(libsList, BoxLayout.Y_AXIS));
136+
libsList.add(textArea);
137+
libsList.setBorder(new EmptyBorder(7, 7, 7, 7));
138+
pane.add(libsList, BorderLayout.NORTH);
139+
}
140+
141+
pack();
142+
setResizable(false);
143+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
144+
145+
WindowEvent closing = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
146+
Base.registerWindowCloseKeys(getRootPane(), e -> dispatchEvent(closing));
147+
}
148+
149+
// TODO Make this a method of Theme
150+
private JTextPane makeNewDescription() {
151+
JTextPane description = new JTextPane();
152+
description.setInheritsPopupMenu(true);
153+
Insets margin = description.getMargin();
154+
margin.bottom = 0;
155+
description.setMargin(margin);
156+
description.setContentType("text/html");
157+
Document doc = description.getDocument();
158+
if (doc instanceof HTMLDocument) {
159+
HTMLDocument html = (HTMLDocument) doc;
160+
StyleSheet s = html.getStyleSheet();
161+
s.addRule("body { margin: 0; padding: 0;"
162+
+ "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;"
163+
+ "color: black;" + "font-size: " + 15 * Theme.getScale() / 100
164+
+ "; }");
165+
}
166+
description.setOpaque(false);
167+
description.setBorder(new EmptyBorder(4, 7, 7, 7));
168+
description.setHighlighter(null);
169+
description.setEditable(false);
170+
add(description, 0);
171+
return description;
172+
}
173+
174+
public Result getInstallDepsResult() {
175+
return result;
176+
}
177+
}

0 commit comments

Comments
 (0)