Skip to content
Snippets Groups Projects
Commit 28004ede authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

PROBPLUGIN-11: Fixed

parent 16931c3a
Branches
No related tags found
No related merge requests found
......@@ -6,6 +6,10 @@
package de.bmotionstudio.gef.editor.action;
import java.util.Iterator;
import java.util.List;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.ISharedImages;
......@@ -14,6 +18,7 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import de.bmotionstudio.gef.editor.command.PasteCommand;
import de.bmotionstudio.gef.editor.model.BControl;
public class PasteAction extends SelectionAction {
......@@ -38,19 +43,37 @@ public class PasteAction extends SelectionAction {
setEnabled(false);
}
private PasteCommand createPasteCommand() {
return new PasteCommand();
private PasteCommand createPasteCommand(List<Object> selectedObjects) {
PasteCommand cmd = new PasteCommand();
Iterator<Object> it = selectedObjects.iterator();
while (it.hasNext()) {
Object nextElement = it.next();
if (nextElement instanceof EditPart) {
EditPart ep = (EditPart) nextElement;
BControl node = (BControl) ep.getModel();
if (!cmd.isContainer(node))
return null;
cmd.addElement(node);
}
}
return cmd;
}
@SuppressWarnings("unchecked")
@Override
protected boolean calculateEnabled() {
Command command = createPasteCommand();
Command command = createPasteCommand(getSelectedObjects());
return command != null && command.canExecute();
}
@SuppressWarnings("unchecked")
@Override
public void run() {
PasteCommand command = createPasteCommand();
PasteCommand command = createPasteCommand(getSelectedObjects());
if (command != null && command.canExecute())
execute(command);
}
......
......@@ -9,6 +9,7 @@ package de.bmotionstudio.gef.editor.command;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.ui.actions.Clipboard;
......@@ -23,6 +24,8 @@ public class PasteCommand extends Command {
private HashMap<BControl, BControl> list = new HashMap<BControl, BControl>();
private List<BControl> parentControls = new ArrayList<BControl>();
@Override
public boolean canExecute() {
cHelper = (CopyPasteHelper) Clipboard.getDefault().getContents();
......@@ -34,22 +37,39 @@ public class PasteCommand extends Command {
Iterator<?> it = myList.iterator();
while (it.hasNext()) {
BControl node = (BControl) it.next();
if (isPastableNode(node)) {
if (isPastableControl(node)) {
list.put(node, null);
}
}
return true;
}
public boolean addElement(BControl control) {
if (!parentControls.contains(control)) {
return parentControls.add(control);
}
return false;
}
public boolean isContainer(BControl control) {
return control.canHaveChildren();
}
@Override
public void execute() {
if (!canExecute())
return;
for (BControl parent : parentControls) {
Iterator<BControl> it = list.keySet().iterator();
while (it.hasNext()) {
BControl control = (BControl) it.next();
control.setParent(parent);
try {
BControl clone = (BControl) control.clone();
clone.setParent(parent);
int x = Integer.valueOf(Integer.valueOf(clone
.getAttributeValue(AttributeConstants.ATTRIBUTE_X)
.toString()));
......@@ -67,6 +87,9 @@ public class PasteCommand extends Command {
}
}
redo();
}
}
@Override
......@@ -74,7 +97,7 @@ public class PasteCommand extends Command {
Iterator<BControl> it = list.values().iterator();
while (it.hasNext()) {
BControl control = it.next();
if (isPastableNode(control)) {
if (isPastableControl(control)) {
control.getParent().addChild(control);
}
}
......@@ -90,13 +113,13 @@ public class PasteCommand extends Command {
Iterator<BControl> it = list.values().iterator();
while (it.hasNext()) {
BControl bcontrol = it.next();
if (isPastableNode(bcontrol)) {
if (isPastableControl(bcontrol)) {
bcontrol.getParent().removeChild(bcontrol);
}
}
}
public boolean isPastableNode(BControl control) {
public boolean isPastableControl(BControl control) {
if (control instanceof Visualization)
return false;
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment