mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
improve building blocks
This commit is contained in:
@@ -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<IDIYComponent<?>>(componentSlot));
|
||||
}
|
||||
// Select the new component
|
||||
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
||||
// selectedComponents);
|
||||
@@ -2071,13 +2075,18 @@ public class Presenter implements IPlugInPort {
|
||||
Collection<IDIYComponent<?>> components = blocks.get(blockName);
|
||||
if (components == null)
|
||||
throw new InvalidBlockException();
|
||||
// clone components
|
||||
List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>();
|
||||
for (IDIYComponent<?> c : components)
|
||||
try {
|
||||
clones.add(c.clone());
|
||||
IDIYComponent<?> clone = c.clone();
|
||||
clone.setName(instantiationManager.createUniqueName(ComponentProcessor.getInstance()
|
||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) 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();
|
||||
|
||||
@@ -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<Template> templates = plugInPort.getTemplatesFor(componentType.getCategory(), componentType.getName());
|
||||
@@ -317,6 +326,8 @@ public class TreePanel extends JPanel {
|
||||
popup.add(item);
|
||||
}
|
||||
}
|
||||
} else if (selectedNode.isLeaf()) {
|
||||
popup.add(new DeleteBlockAction(plugInPort, payload.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,4 +557,25 @@ public class TreePanel extends JPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DeleteBlockAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private String blockName;
|
||||
|
||||
public DeleteBlockAction(IPlugInPort plugInPort, String blockName) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
this.blockName = blockName;
|
||||
putValue(AbstractAction.NAME, "Delete Building Block");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info(getValue(AbstractAction.NAME) + " triggered");
|
||||
plugInPort.deleteBlock(blockName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user