Favorites on building blocks show up as "null"

This commit is contained in:
bancika
2020-09-18 17:05:49 +02:00
parent 0fa15650c3
commit 5638d560a4
@@ -40,6 +40,7 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigListener; import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.common.Favorite; import org.diylc.common.Favorite;
import org.diylc.common.Favorite.FavoriteType;
import org.diylc.common.IBlockProcessor.InvalidBlockException; import org.diylc.common.IBlockProcessor.InvalidBlockException;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
@@ -108,7 +109,7 @@ public class CustomTreeModel implements TreeModel {
this.visibleLeaves.clear(); this.visibleLeaves.clear();
fireTreeStructureChanged(new Object[] { root }); fireTreeStructureChanged(new Object[] {root});
} }
private List<TreeNode> getLeavesFor(String category) { private List<TreeNode> getLeavesFor(String category) {
@@ -118,6 +119,7 @@ public class CustomTreeModel implements TreeModel {
if (FAVORITES.equals(category)) { if (FAVORITES.equals(category)) {
for (Favorite fav : this.favorites) { for (Favorite fav : this.favorites) {
if (fav.getType() == FavoriteType.Component) {
ComponentType type = this.typesByClass.get(fav.getName()); ComponentType type = this.typesByClass.get(fav.getName());
if (this.searchText == null || type.getName().toLowerCase().contains(this.searchText)) { if (this.searchText == null || type.getName().toLowerCase().contains(this.searchText)) {
visibleTypes.add(new TreeNode(type, new MouseAdapter() { visibleTypes.add(new TreeNode(type, new MouseAdapter() {
@@ -128,6 +130,28 @@ public class CustomTreeModel implements TreeModel {
} }
})); }));
} }
} else {
// block
if (this.searchText == null || fav.getName().toLowerCase().contains(this.searchText)) {
visibleTypes.add(new TreeNode(fav.getName(), new MouseAdapter() {
long previousActionTime = 0;
@Override
public void mouseClicked(MouseEvent e) {
if (e == null || SwingUtilities.isLeftMouseButton(e)
&& System.currentTimeMillis() - previousActionTime > 100) {
previousActionTime = System.currentTimeMillis();
try {
plugInPort.loadBlock(fav.getName());
} catch (InvalidBlockException e1) {
e1.printStackTrace();
}
}
}
}, true));
}
}
} }
} }
@@ -155,7 +179,8 @@ public class CustomTreeModel implements TreeModel {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (e == null || SwingUtilities.isLeftMouseButton(e) && System.currentTimeMillis() - previousActionTime > 100) { if (e == null || SwingUtilities.isLeftMouseButton(e)
&& System.currentTimeMillis() - previousActionTime > 100) {
previousActionTime = System.currentTimeMillis(); previousActionTime = System.currentTimeMillis();
try { try {
plugInPort.loadBlock(block); plugInPort.loadBlock(block);
@@ -315,7 +340,7 @@ public class CustomTreeModel implements TreeModel {
LOG.info("Detected favorites change"); LOG.info("Detected favorites change");
CustomTreeModel.this.favorites = new ArrayList<Favorite>(newFavorites); CustomTreeModel.this.favorites = new ArrayList<Favorite>(newFavorites);
CustomTreeModel.this.visibleLeaves.remove(FAVORITES); CustomTreeModel.this.visibleLeaves.remove(FAVORITES);
fireTreeStructureChanged(new Object[] { root, CustomTreeModel.this.favoritesNode }); fireTreeStructureChanged(new Object[] {root, CustomTreeModel.this.favoritesNode});
} else } else
LOG.info("Detected no favorites change"); LOG.info("Detected no favorites change");
} }
@@ -334,7 +359,7 @@ public class CustomTreeModel implements TreeModel {
LOG.info("Detected recent component change"); LOG.info("Detected recent component change");
CustomTreeModel.this.recentComponents = new ArrayList<String>(newComponents); CustomTreeModel.this.recentComponents = new ArrayList<String>(newComponents);
CustomTreeModel.this.visibleLeaves.remove(RECENTLY_USED); CustomTreeModel.this.visibleLeaves.remove(RECENTLY_USED);
fireTreeStructureChanged(new Object[] { root, CustomTreeModel.this.recentNode }); fireTreeStructureChanged(new Object[] {root, CustomTreeModel.this.recentNode});
} else } else
LOG.info("Detected no recent component change"); LOG.info("Detected no recent component change");
} }
@@ -356,7 +381,7 @@ public class CustomTreeModel implements TreeModel {
LOG.info("Detected block change"); LOG.info("Detected block change");
CustomTreeModel.this.blocks = blockNames; CustomTreeModel.this.blocks = blockNames;
CustomTreeModel.this.visibleLeaves.remove(BUILDING_BLOCKS); CustomTreeModel.this.visibleLeaves.remove(BUILDING_BLOCKS);
fireTreeStructureChanged(new Object[] { root, CustomTreeModel.this.blocksNode}); fireTreeStructureChanged(new Object[] {root, CustomTreeModel.this.blocksNode});
} else } else
LOG.info("Detected no block change"); LOG.info("Detected no block change");
} else } else