/*******************************************************************************
* Copyright (c) 2010-2015 Henshin developers. All rights reserved.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* TU Berlin, University of Luxembourg, SES S.A.
*******************************************************************************/
package de.tub.tfs.henshin.tggeditor.editpolicies.graphical;
import org.eclipse.emf.henshin.model.Attribute;
import org.eclipse.emf.henshin.model.Mapping;
import org.eclipse.emf.henshin.model.Node;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import de.tub.tfs.henshin.tggeditor.commands.create.CreateAttributeCommand;
import de.tub.tfs.henshin.tggeditor.commands.create.rule.MarkCommand;
import de.tub.tfs.henshin.tggeditor.commands.create.rule.MarkUnspecifiedCommand;
public class NodeLayoutEditPolicy extends LayoutEditPolicy {
protected EditPolicy createChildEditPolicy(EditPart child) {
return new NonResizableEditPolicy();
}
@Override
protected Command getCreateCommand(CreateRequest request) {
Command command = null;
if (request.getNewObject() instanceof Attribute) {
Node node = (Node) getHost().getModel();
if (node.getType() != null) {
if ((node.getType().getEAllAttributes().size()
- node.getAttributes().size() > 0))
command = new CreateAttributeCommand(node,"New Attribute");
}
}
if (request.getNewObject() instanceof Mapping) {
Node rhsnode = (Node) getTargetEditPart(request).getModel();
Mapping newMapping = (Mapping) request.getNewObject();
command = new MarkUnspecifiedCommand(newMapping, rhsnode);
}
return command;
}
@Override
protected Command getMoveChildrenCommand(Request request) {
return null;
}
}