mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Categories and filter search on installer
This commit is contained in:
parent
353a35942c
commit
cf058c37ba
@ -117,16 +117,48 @@ public class ContributionIndexTableModel extends AbstractTableModel {
|
|||||||
|
|
||||||
private Class<?>[] columnTypes = { ContributedPlatform.class };
|
private Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||||
|
|
||||||
public void updateIndex(ContributionsIndex index) {
|
private ContributionsIndex index;
|
||||||
|
|
||||||
|
public void setIndex(ContributionsIndex _index) {
|
||||||
|
index = _index;
|
||||||
|
updateIndexFilter(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateIndexFilter(String category, String filters[]) {
|
||||||
contributions.clear();
|
contributions.clear();
|
||||||
for (ContributedPackage pack : index.getPackages()) {
|
for (ContributedPackage pack : index.getPackages()) {
|
||||||
for (ContributedPlatform platform : pack.getPlatforms()) {
|
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||||
|
if (category != null) {
|
||||||
|
if (!platform.getCategory().equals(category))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!stringContainsAll(platform.getName(), filters))
|
||||||
|
continue;
|
||||||
addContribution(platform);
|
addContribution(platform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if <b>string</b> contains all the substrings in <b>set</b>. The
|
||||||
|
* compare is case insensitive.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* @param set
|
||||||
|
* @return <b>true<b> if all the strings in <b>set</b> are contained in
|
||||||
|
* <b>string</b>.
|
||||||
|
*/
|
||||||
|
private boolean stringContainsAll(String string, String set[]) {
|
||||||
|
if (set == null)
|
||||||
|
return true;
|
||||||
|
for (String s : set) {
|
||||||
|
if (!string.toLowerCase().contains(s.toLowerCase()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void addContribution(ContributedPlatform platform) {
|
private void addContribution(ContributedPlatform platform) {
|
||||||
for (ContributedPlatformReleases contribution : contributions) {
|
for (ContributedPlatformReleases contribution : contributions) {
|
||||||
if (!contribution.shouldContain(platform))
|
if (!contribution.shouldContain(platform))
|
||||||
@ -194,4 +226,5 @@ public class ContributionIndexTableModel extends AbstractTableModel {
|
|||||||
public void update() {
|
public void update() {
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,6 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
|
|
||||||
private ContributionManagerUIListener listener = null;
|
private ContributionManagerUIListener listener = null;
|
||||||
|
|
||||||
private String category;
|
|
||||||
private JLabel categoryLabel;
|
private JLabel categoryLabel;
|
||||||
private JComboBox categoryChooser;
|
private JComboBox categoryChooser;
|
||||||
private Component categoryStrut1;
|
private Component categoryStrut1;
|
||||||
@ -89,6 +88,10 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
|
|
||||||
private ContributedPlatformTableCell cellEditor;
|
private ContributedPlatformTableCell cellEditor;
|
||||||
|
|
||||||
|
// Currently selected category and filters
|
||||||
|
private String category;
|
||||||
|
private String[] filters;
|
||||||
|
|
||||||
public ContributionManagerUI(Frame parent) {
|
public ContributionManagerUI(Frame parent) {
|
||||||
super(parent, "Boards Manager", Dialog.ModalityType.APPLICATION_MODAL);
|
super(parent, "Boards Manager", Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
setResizable(true);
|
setResizable(true);
|
||||||
@ -108,13 +111,24 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
categoryChooser.addActionListener(new ActionListener() {
|
categoryChooser.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
notifyCategoryChange();
|
String selected = (String) categoryChooser.getSelectedItem();
|
||||||
|
if (category == null || !category.equals(selected)) {
|
||||||
|
category = selected;
|
||||||
|
cellEditor.stopCellEditing();
|
||||||
|
contribModel.updateIndexFilter(category, filters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setCategories(new ArrayList<String>());
|
setCategories(new ArrayList<String>());
|
||||||
|
|
||||||
filterField = new FilterJTextField(_("Filter your search..."));
|
filterField = new FilterJTextField(_("Filter your search...")) {
|
||||||
|
@Override
|
||||||
|
protected void onFilter(String[] _filters) {
|
||||||
|
filters = _filters;
|
||||||
|
contribModel.updateIndexFilter(category, filters);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||||
@ -266,18 +280,9 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
categoryStrut3.setVisible(show);
|
categoryStrut3.setVisible(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void notifyCategoryChange() {
|
public void setContributions(ContributionsIndex index) {
|
||||||
if (listener == null)
|
contribModel.setIndex(index);
|
||||||
return;
|
setCategories(index.getCategories());
|
||||||
String selected = (String) categoryChooser.getSelectedItem();
|
|
||||||
if (category == null || !category.equals(selected)) {
|
|
||||||
category = selected;
|
|
||||||
listener.onCategoryChange(category);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addContributions(ContributionsIndex index) {
|
|
||||||
contribModel.updateIndex(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgressVisible(boolean visible) {
|
public void setProgressVisible(boolean visible) {
|
||||||
|
@ -32,8 +32,6 @@ import cc.arduino.packages.contributions.ContributedPlatform;
|
|||||||
|
|
||||||
public interface ContributionManagerUIListener {
|
public interface ContributionManagerUIListener {
|
||||||
|
|
||||||
void onCategoryChange(String category);
|
|
||||||
|
|
||||||
void onInstall(ContributedPlatform selected);
|
void onInstall(ContributedPlatform selected);
|
||||||
|
|
||||||
void onRemove(ContributedPlatform selected);
|
void onRemove(ContributedPlatform selected);
|
||||||
|
@ -1,12 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
package cc.arduino.packages.contributions.ui;
|
package cc.arduino.packages.contributions.ui;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@ -16,15 +41,14 @@ import javax.swing.event.DocumentListener;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FilterJTextField extends JTextField {
|
public class FilterJTextField extends JTextField {
|
||||||
private String filterHint;
|
private String filterHint;
|
||||||
boolean showingHint;
|
|
||||||
List<String> filters;
|
private boolean showingHint;
|
||||||
|
|
||||||
public FilterJTextField(String hint) {
|
public FilterJTextField(String hint) {
|
||||||
super(hint);
|
super(hint);
|
||||||
filterHint = hint;
|
filterHint = hint;
|
||||||
|
|
||||||
showingHint = true;
|
showingHint = true;
|
||||||
filters = new ArrayList<String>();
|
|
||||||
updateStyle();
|
updateStyle();
|
||||||
|
|
||||||
addFocusListener(new FocusListener() {
|
addFocusListener(new FocusListener() {
|
||||||
@ -59,18 +83,17 @@ public class FilterJTextField extends JTextField {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyFilter() {
|
private void applyFilter() {
|
||||||
String filter = getFilterText();
|
String filter = showingHint ? "" : getText();
|
||||||
filter = filter.toLowerCase();
|
filter = filter.toLowerCase();
|
||||||
|
|
||||||
// Replace anything but 0-9, a-z, or : with a space
|
// Replace anything but 0-9, a-z, or : with a space
|
||||||
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
||||||
filters = Arrays.asList(filter.split(" "));
|
onFilter(filter.split(" "));
|
||||||
// filterLibraries(category, filters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFilterText() {
|
protected void onFilter(String[] strings) {
|
||||||
return showingHint ? "" : getText();
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStyle() {
|
public void updateStyle() {
|
||||||
|
@ -1122,11 +1122,6 @@ public class Base {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
managerUI.setListener(new ContributionManagerUIListener() {
|
managerUI.setListener(new ContributionManagerUIListener() {
|
||||||
@Override
|
|
||||||
public void onCategoryChange(String category) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
System.out.println("Selected " + category);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdatePressed() {
|
public void onUpdatePressed() {
|
||||||
@ -1185,9 +1180,7 @@ public class Base {
|
|||||||
task.start();
|
task.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
managerUI.setCategories(Arrays.asList("Arduino", "Arduino Certified",
|
managerUI.setContributions(BaseNoGui.indexer.getIndex());
|
||||||
"Arduino@Heart"));
|
|
||||||
managerUI.addContributions(BaseNoGui.indexer.getIndex());
|
|
||||||
managerUI.setVisible(true);
|
managerUI.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user