diff --git a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java index d9edb514..2fb1d3b7 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java @@ -458,6 +458,10 @@ public class Presenter implements IPlugInPort { addComponent(component, true); newSelection.add(component); } + // group components if there's more than one, e.g. building blocks + if (componentSlot.size() > 1) { + this.currentProject.getGroups().add(new HashSet>(componentSlot)); + } // Select the new component // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // selectedComponents); @@ -2071,13 +2075,18 @@ public class Presenter implements IPlugInPort { Collection> components = blocks.get(blockName); if (components == null) throw new InvalidBlockException(); + // clone components List> clones = new ArrayList>(); for (IDIYComponent c : components) try { - clones.add(c.clone()); + IDIYComponent clone = c.clone(); + clone.setName(instantiationManager.createUniqueName(ComponentProcessor.getInstance() + .extractComponentTypeFrom((Class>) clone.getClass()), currentProject)); + clones.add(clone); } catch (CloneNotSupportedException e) { LOG.error("Could not clone component: " + c); } + // paste them to the project pasteComponents(clones); } else throw new InvalidBlockException(); diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java index c6f823aa..88afa44a 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java @@ -40,6 +40,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; import org.apache.log4j.Logger; import org.diylc.appframework.miscutils.ConfigurationManager; @@ -265,6 +266,7 @@ public class TreePanel extends JPanel { tree = new JTree(getTreeModel()); tree.setRootVisible(false); tree.setCellRenderer(new ComponentCellRenderer()); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setRowHeight(0); ToolTipManager.sharedInstance().registerComponent(tree); @@ -301,9 +303,16 @@ public class TreePanel extends JPanel { public void popupMenuWillBecomeVisible(PopupMenuEvent e) { popup.removeAll(); - popup.add(new SelectAllAction(plugInPort)); - ComponentType componentType = plugInPort.getNewComponentTypeSlot(); + DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); + + if (selectedNode == null || selectedNode.getUserObject() == null) + return; + + Payload payload = (Payload) selectedNode.getUserObject(); + + ComponentType componentType = payload.getComponentType(); if (componentType != null) { + popup.add(new SelectAllAction(plugInPort)); popup.add(new JSeparator()); List