Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1a7ebb5581983e926c08ed696aa294b8d7c5b1b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*****************************************************************************
 * Copyright (c) 2010 CEA LIST.
 *
 *    
 * 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:
 *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.diagramqueryresult;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
import org.eclipse.gmf.runtime.diagram.ui.services.layout.LayoutType;
import org.eclipse.gmt.modisco.infra.query.runtime.ModelQueryResult;
import org.eclipse.gmt.modisco.infra.query.ui.views.queryExecution.QueryResultDisplayer;
import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
import org.eclipse.papyrus.core.utils.DiResourceSet;
import org.eclipse.papyrus.core.utils.EditorUtils;
import org.eclipse.papyrus.diagram.clazz.CreateClassDiagramCommand;
import org.eclipse.papyrus.diagram.clazz.UmlClassDiagramForMultiEditor;
import org.eclipse.papyrus.diagram.clazz.part.UMLDiagramEditor;
import org.eclipse.papyrus.diagram.common.command.wrappers.GEFtoEMFCommandWrapper;
import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Element;


public class DiagramQueryResultDisplayer implements QueryResultDisplayer {
	
	/** The diagram editor. */
	protected UMLDiagramEditor diagramEditor=null;
	
	/** The clazzdiagramedit part. */
	protected DiagramEditPart clazzdiagrameditPart;



	/** The papyrus editor. */
	protected PapyrusMultiDiagramEditor papyrusEditor;

	public DiagramQueryResultDisplayer() {
		// TODO Auto-generated constructor stub
	}

	public void displayQueryResult(List<ModelQueryResult> result) {
		while( !(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()instanceof IMultiDiagramEditor)){}
		IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		DiResourceSet diResourceSet=EditorUtils.getDiResourceSet();
		papyrusEditor=((PapyrusMultiDiagramEditor)editorPart);
		CreateClassDiagramCommand command= new CreateClassDiagramCommand();
		command.createDiagram(diResourceSet, null, "result");

		Iterator<ModelQueryResult> resultIterator= result.iterator();
		while(resultIterator.hasNext()) {
			ModelQueryResult modelQueryResult = (ModelQueryResult)resultIterator.next();

			if(modelQueryResult.getValue() instanceof Collection){
				Iterator iter= ((Collection)modelQueryResult.getValue()).iterator();
				int i=0;
				while(iter.hasNext()) {
					Object object = (Object)iter.next();
					
					if( object instanceof Element){
						DropObjectsRequest dropObjectsRequest= new DropObjectsRequest();
						ArrayList list = new ArrayList();
						list.add((Element)object);
						dropObjectsRequest.setObjects(list);
						dropObjectsRequest.setLocation(new Point(20,100*i));
						Command commandDrop= getDiagramEditPart().getCommand(dropObjectsRequest);
						diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(commandDrop);
						i++;
					}
				}
			}
		}
		List operationSet = getDiagramEditPart().getChildren();
		ArrangeRequest aRequest =  new ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL, LayoutType.DEFAULT);
		//aRequest.setType(ActionIds.ACTION_ARRANGE_ALL);
		ArrayList toarrange= new ArrayList();
		toarrange.add(getDiagramEditPart());
		aRequest.setPartsToArrange(toarrange);
		Command commandArrangeAll = getDiagramEditPart().getCommand(aRequest);
		//getDiagramEditPart().getEditingDomain().getCommandStack().execute(new GEFtoEMFCommandWrapper(commandArrangeAll));
		
	


	}

	/**
	 * Gets the diagram edit part.
	 * 
	 * @return the diagram edit part
	 */
	protected DiagramEditPart getDiagramEditPart(){
			diagramEditor= (UmlClassDiagramForMultiEditor)papyrusEditor.getActiveEditor();
			clazzdiagrameditPart = (DiagramEditPart)diagramEditor.getGraphicalViewer().getEditPartRegistry().get(diagramEditor.getDiagram());
		return clazzdiagrameditPart;
	}

}

Back to the top