mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
improve building blocks
This commit is contained in:
@@ -458,6 +458,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
addComponent(component, true);
|
addComponent(component, true);
|
||||||
newSelection.add(component);
|
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
|
// Select the new component
|
||||||
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
||||||
// selectedComponents);
|
// selectedComponents);
|
||||||
@@ -2071,13 +2075,18 @@ public class Presenter implements IPlugInPort {
|
|||||||
Collection<IDIYComponent<?>> components = blocks.get(blockName);
|
Collection<IDIYComponent<?>> components = blocks.get(blockName);
|
||||||
if (components == null)
|
if (components == null)
|
||||||
throw new InvalidBlockException();
|
throw new InvalidBlockException();
|
||||||
|
// clone components
|
||||||
List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>();
|
List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>();
|
||||||
for (IDIYComponent<?> c : components)
|
for (IDIYComponent<?> c : components)
|
||||||
try {
|
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) {
|
} catch (CloneNotSupportedException e) {
|
||||||
LOG.error("Could not clone component: " + c);
|
LOG.error("Could not clone component: " + c);
|
||||||
}
|
}
|
||||||
|
// paste them to the project
|
||||||
pasteComponents(clones);
|
pasteComponents(clones);
|
||||||
} else
|
} else
|
||||||
throw new InvalidBlockException();
|
throw new InvalidBlockException();
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
|||||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||||
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
|
import javax.swing.tree.TreeSelectionModel;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
@@ -265,6 +266,7 @@ public class TreePanel extends JPanel {
|
|||||||
tree = new JTree(getTreeModel());
|
tree = new JTree(getTreeModel());
|
||||||
tree.setRootVisible(false);
|
tree.setRootVisible(false);
|
||||||
tree.setCellRenderer(new ComponentCellRenderer());
|
tree.setCellRenderer(new ComponentCellRenderer());
|
||||||
|
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||||
tree.setRowHeight(0);
|
tree.setRowHeight(0);
|
||||||
ToolTipManager.sharedInstance().registerComponent(tree);
|
ToolTipManager.sharedInstance().registerComponent(tree);
|
||||||
|
|
||||||
@@ -301,9 +303,16 @@ public class TreePanel extends JPanel {
|
|||||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||||
popup.removeAll();
|
popup.removeAll();
|
||||||
|
|
||||||
popup.add(new SelectAllAction(plugInPort));
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
|
||||||
ComponentType componentType = plugInPort.getNewComponentTypeSlot();
|
|
||||||
|
if (selectedNode == null || selectedNode.getUserObject() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Payload payload = (Payload) selectedNode.getUserObject();
|
||||||
|
|
||||||
|
ComponentType componentType = payload.getComponentType();
|
||||||
if (componentType != null) {
|
if (componentType != null) {
|
||||||
|
popup.add(new SelectAllAction(plugInPort));
|
||||||
popup.add(new JSeparator());
|
popup.add(new JSeparator());
|
||||||
|
|
||||||
List<Template> templates = plugInPort.getTemplatesFor(componentType.getCategory(), componentType.getName());
|
List<Template> templates = plugInPort.getTemplatesFor(componentType.getCategory(), componentType.getName());
|
||||||
@@ -317,6 +326,8 @@ public class TreePanel extends JPanel {
|
|||||||
popup.add(item);
|
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