}
// those left in knownViewChildren are subject to removal - they are our diagram elements we didn't find match to,
// or those we have potential matches to, and thus need to be recreated, preserving size/location information.
orphaned.addAll(knownViewChildren);
//
CompositeTransactionalCommand boundsCommand = new CompositeTransactionalCommand(
host().getEditingDomain(),
DiagramUIMessages.SetLocationCommand_Label_Resize);
ArrayList<CreateViewRequest.ViewDescriptor> viewDescriptors = new ArrayList<CreateViewRequest.ViewDescriptor>(
childDescriptors.size());
for (DispelNodeDescriptor next : childDescriptors) {
String hint = DispelVisualIDRegistry.getType(next.getVisualID());
IAdaptable elementAdapter = new CanonicalElementAdapter(
next.getModelElement(), hint);
CreateViewRequest.ViewDescriptor descriptor = new CreateViewRequest.ViewDescriptor(
elementAdapter, Node.class, hint, ViewUtil.APPEND, false,
host().getDiagramPreferencesHint());
viewDescriptors.add(descriptor);
LinkedList<View> possibleMatches = potentialViews.get(next);
if (possibleMatches != null) {
// from potential matches, leave those that were not eventually used for some other NodeDescriptor (i.e. those left as orphaned)
possibleMatches.retainAll(knownViewChildren);
}
if (possibleMatches != null && !possibleMatches.isEmpty()) {
View originalView = possibleMatches.getFirst();
knownViewChildren.remove(originalView); // remove not to copy properties of the same view again and again
// add command to copy properties
if (originalView instanceof Node) {
if (((Node) originalView).getLayoutConstraint() instanceof Bounds) {
Bounds b = (Bounds) ((Node) originalView)
.getLayoutConstraint();
boundsCommand.add(new SetBoundsCommand(boundsCommand
.getEditingDomain(), boundsCommand.getLabel(),
descriptor, new Rectangle(b.getX(), b.getY(), b
.getWidth(), b.getHeight())));
} else if (((Node) originalView).getLayoutConstraint() instanceof Location) {
Location l = (Location) ((Node) originalView)
.getLayoutConstraint();
boundsCommand.add(new SetBoundsCommand(boundsCommand
.getEditingDomain(), boundsCommand.getLabel(),
descriptor, new Point(l.getX(), l.getY())));
} else if (((Node) originalView).getLayoutConstraint() instanceof Size) {
Size s = (Size) ((Node) originalView)
.getLayoutConstraint();
boundsCommand.add(new SetBoundsCommand(boundsCommand
.getEditingDomain(), boundsCommand.getLabel(),
descriptor, new Dimension(s.getWidth(), s
.getHeight())));
}
}
}
}
boolean changed = deleteViews(orphaned.iterator());
//
CreateViewRequest request = getCreateViewRequest(viewDescriptors);
Command cmd = getCreateViewCommand(request);
if (cmd != null && cmd.canExecute()) {
SetViewMutabilityCommand.makeMutable(
new EObjectAdapter(host().getNotationView())).execute();
executeCommand(cmd);
if (boundsCommand.canExecute()) {
executeCommand(new ICommandProxy(boundsCommand.reduce()));
}
@SuppressWarnings("unchecked")
List<IAdaptable> nl = (List<IAdaptable>) request.getNewObject();
createdViews.addAll(nl);
}