Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 Anyware Technologies 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: Anyware Technologies - initial API and implementation $Id: ArrangeRelatedNodesCommand.java,v 1.6 2009/01/29 10:02:08 jlescot Exp $
 
 package org.eclipse.emf.ecoretools.diagram.edit.commands;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.eclipse.core.runtime.IAdaptable;
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.gmf.runtime.common.core.command.CommandResult;
 import  org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
 import  org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
 import  org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
 import  org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
 import  org.eclipse.gmf.runtime.notation.View;

Restores the missing nodes of outgoing or incoming links for the selected parts
creation : 15 avr. 2008

Author(s):
Gilles Cannenterre
 
 
 	public ArrangeRelatedNodesCommand(DiagramEditPart diagramEditPartList<?> selection) {
 		super(diagramEditPartselection);
 	}

See also:
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor , org.eclipse.core.runtime.IAdaptable )
 
 	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable infothrows ExecutionException {
 		List<View> views = new ArrayList<View>();
 		for (Object object : ) {
 			if (object instanceof IAdaptable) {
 				IAdaptable ad = (IAdaptable) object;
 				View view = (View) ad.getAdapter(View.class);
 				if (view != null) {
 					views.add(view);
 				}
 			} else if (object instanceof View) {
 				views.add((View) object);
 			}
 
 		}
 
 		return CommandResult.newOKCommandResult();
 	}

Arranges related missing nodes for graphicalEditPart

Parameters:
graphicalEditPart
 
 	protected void arrangeRelatedNodes(List<View> notationViews) {
 		Map<EObject, View> domain2NotationMap = new HashMap<EObject, View>();
 
 		// Collect all related link from semantic model
 		List<View> relatedNodes = new ArrayList<View>();
 		relatedNodes.addAll(notationViews);
 
 		for (View notationView : notationViews) {
 			Collection<? extends EcoreLinkDescriptorlinkDescriptors = collectPartRelatedLinks(notationViewdomain2NotationMap);
 			relatedNodes.addAll(getRelatedMissingNodes(linkDescriptorsdomain2NotationMap));
 		}
 
 		List<EObjectAdapter> adapters = new ArrayList<EObjectAdapter>();
 		for (View view : relatedNodes) {
 			if (view.eContainer() != ) {
 				continue;
 			}
 			adapters.add(new EObjectAdapter(view));
 		}
 
 		if (adapters.size() > 1) {
			// perform a layout of the container
			DeferredLayoutCommand cmd = new DeferredLayoutCommand(.getEditingDomain(), adapters);
			if (cmd != null && cmd.canExecute()) {
				EReferenceUtils.executeCommand(new ICommandProxy(cmd), );
			}
		}
	}

Gets related nodes corresponding to linkDescriptions

Parameters:
part
linkDescriptors
domain2NotationMap
Returns:
views
	protected List<View> getRelatedMissingNodes(Collection<? extends EcoreLinkDescriptorlinkDescriptorsMap<EObject, View> domain2NotationMap) {
		// map diagram
		mapModel(domain2NotationMap);
		List<View> relatedNodes = new ArrayList<View>();
		for (EcoreLinkDescriptor nextLinkDescriptor : linkDescriptors) {
			View sourceView = domain2NotationMap.get(nextLinkDescriptor.getSource());
			View targetView = domain2NotationMap.get(nextLinkDescriptor.getDestination());
			if (sourceView != null && false == relatedNodes.contains(sourceView)) {
				relatedNodes.add(sourceView);
			}
			if (targetView != null && false == relatedNodes.contains(targetView)) {
				relatedNodes.add(targetView);
			}
		}
		return relatedNodes;
	}
New to GrepCode? Check out our FAQ X