$search
00001 package org.ros.model.ros.diagram; 00002 00003 import java.lang.annotation.Target; 00004 import java.util.Iterator; 00005 import java.util.List; 00006 00007 import org.eclipse.core.commands.ExecutionException; 00008 import org.eclipse.core.commands.operations.OperationHistoryFactory; 00009 import org.eclipse.core.runtime.IProgressMonitor; 00010 import org.eclipse.core.runtime.IStatus; 00011 import org.eclipse.core.runtime.IAdaptable; 00012 import org.eclipse.core.runtime.Status; 00013 import org.eclipse.emf.common.util.URI; 00014 import org.eclipse.emf.ecore.EObject; 00015 import org.eclipse.emf.ecore.EReference; 00016 import org.eclipse.emf.ecore.resource.Resource; 00017 import org.eclipse.emf.ecore.resource.ResourceSet; 00018 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; 00019 import org.eclipse.emf.transaction.TransactionalEditingDomain; 00020 import org.eclipse.emf.workspace.AbstractEMFOperation; 00021 import org.eclipse.gef.EditPartViewer; 00022 import org.eclipse.gef.commands.Command; 00023 import org.eclipse.gef.commands.CompoundCommand; 00024 import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; 00025 import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; 00026 import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; 00027 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DiagramDragDropEditPolicy; 00028 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; 00029 import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; 00030 import org.eclipse.gmf.runtime.diagram.ui.render.editparts.RenderedDiagramRootEditPart; 00031 import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; 00032 import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor; 00033 import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; 00034 import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; 00035 import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; 00036 import org.eclipse.gmf.runtime.emf.type.core.IElementType; 00037 import org.eclipse.gmf.runtime.emf.type.core.IHintedType; 00038 import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; 00039 import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; 00040 import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest; 00041 import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; 00042 00043 import org.eclipse.gmf.runtime.notation.Node; 00044 import org.eclipse.gmf.runtime.notation.View; 00045 import org.eclipse.gmf.runtime.notation.impl.NodeImpl; 00046 import org.eclipse.ui.PlatformUI; 00047 import org.ros.model.ros.RosFactory; 00048 import org.ros.model.ros.RosPackage; 00049 import org.ros.model.ros.diagram.part.RosDiagramEditorPlugin; 00050 import org.ros.model.ros.diagram.providers.RosElementTypes; 00051 import org.ros.model.ros.impl.RosPackageImpl; 00052 import org.eclipse.emf.edit.command.AddCommand; 00053 import org.eclipse.emf.edit.command.SetCommand; 00054 00055 public class DropObjectEditPolicy extends DragDropEditPolicy { 00056 00057 00058 /*@Override 00059 protected Command createViewsAndArrangeCommand( 00060 DropObjectsRequest dropRequest, List viewDescriptors) { 00061 CompoundCommand cm = new CompoundCommand(); 00062 Iterator elements = dropRequest.getObjects().iterator(); 00063 00064 final DiagramEditor editor = (DiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 00065 00066 00067 while (elements.hasNext()) { 00068 Object obj = elements.next(); 00069 00070 if (obj instanceof EObject) { 00071 //Command cmd = getDropElementCommand((EObject)obj, dropRequest); 00072 00073 //creates the sketch element and set the image encoded as Base64 00074 //final org.ros.model.ros.Package pack = (org.ros.model.ros.Package) obj; 00075 */ 00076 00077 /*SetRequest reqSet = new SetRequest(((IGraphicalEditPart) getHost()).getEditingDomain(), (EObject)obj, RosPackage.eINSTANCE.getPackage_Name(), "Test14"); 00078 SetValueCommand operation = new SetValueCommand(reqSet); 00079 SetCommand setPoolNameCommand = new SetCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), 00080 (EObject)obj, RosPackage.eINSTANCE.getPackage_Name(), "Test14"); 00081 //cmd2 = new ICommandProxy(operation); 00082 if (setPoolNameCommand != null) 00083 cm.add(setPoolNameCommand);*/ 00084 /* Command c = new Command(){ 00085 @Override 00086 public void execute() { 00087 AbstractEMFOperation emfOp = new AbstractEMFOperation(editor.getEditingDomain(), "Location setting") { 00088 00089 @Override 00090 protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { 00091 NodeImpl n = (NodeImpl)getHost().getParent().getModel(); 00092 org.ros.model.ros.Architecture p = (org.ros.model.ros.Architecture) n.basicGetElement(); 00093 p.getPackages().add(pack); 00094 00095 return Status.OK_STATUS; 00096 } 00097 }; 00098 00099 try { 00100 OperationHistoryFactory.getOperationHistory().execute(emfOp, null, null); 00101 } catch (ExecutionException e) {} 00102 } 00103 }; 00104 cm.add(c); 00105 if (cmd != null) 00106 cm.add(cmd); 00107 00108 } 00109 } 00110 return cm; 00111 } 00112 00113 */ 00114 protected Command getDropObjectsCommand(DropObjectsRequest request) { 00115 00116 CompoundCommand command = null; 00117 //System.out.println("blub"); 00118 final DiagramEditor editor = (DiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 00119 00120 command = new CompoundCommand(); 00121 00122 final org.ros.model.ros.Package pack = RosFactory.eINSTANCE.createPackage(); 00123 pack.eSet(RosPackage.Literals.PACKAGE__NAME, "bubi_was_here");//Base64.encodeFromFile(f.getPath())); 00124 00125 CreateElementRequest cer = new CreateElementRequest(RosElementTypes.Package_2001); 00126 cer.setContainer(((View) getHost().getModel()).getElement()); 00127 cer.setNewElement(pack); 00128 ViewAndElementDescriptor viewDescriptor2 = new ViewAndElementDescriptor( 00129 new CreateElementRequestAdapter(cer), Node.class, 00130 ((IHintedType) RosElementTypes.Package_2001).getSemanticHint(), 00131 RosDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT); 00132 00133 CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor( 00134 new EObjectAdapter(pack), Node.class, ((IHintedType)RosElementTypes.Package_2001).getSemanticHint(), true, 00135 editor.getDiagramEditPart().getDiagramPreferencesHint()); 00136 00137 viewDescriptor.setPersisted(true); 00138 viewDescriptor2.setPersisted(true); 00139 00140 00141 00142 CreateViewRequest createRequest = new CreateViewRequest(viewDescriptor); 00143 CreateViewAndElementRequest createRequest2 = new CreateViewAndElementRequest(viewDescriptor2); 00144 createRequest.setLocation(request.getLocation()); 00145 createRequest2.setLocation(request.getLocation()); 00146 00147 AddCommand ac = new AddCommand(editor.getEditingDomain(), pack.eContents(), getHost().getParent().getModel()); 00148 00149 Command c = new Command(){ 00150 @Override 00151 public void execute() { 00152 AbstractEMFOperation emfOp = new AbstractEMFOperation(editor.getEditingDomain(), "Location setting") { 00153 00154 @Override 00155 protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { 00156 System.out.println("blublub"); 00157 System.out.println(getHost().toString()); 00158 System.out.println(getHost().getParent().toString()); 00159 System.out.println(getHost().getModel().toString()); 00160 System.out.println(((org.ros.model.ros.impl.PackageImpl)getHost().getParent().getModel()).toString()); 00161 org.ros.model.ros.impl.PackageImpl n = (org.ros.model.ros.impl.PackageImpl)getHost().getParent().getModel(); 00162 System.out.println("blublub2"); 00163 //org.ros.model.ros.Architecture p = (org.ros.model.ros.Architecture) n.basicGetElement(); 00164 System.out.println("blublub3"); 00165 //p.getPackages().add(pack); 00166 System.out.println("blublub4"); 00167 return Status.OK_STATUS; 00168 } 00169 }; 00170 00171 try { 00172 OperationHistoryFactory.getOperationHistory().execute(emfOp, null, null); 00173 } catch (ExecutionException e) {System.out.println(e.getMessage());} 00174 } 00175 }; 00176 //command.add(ac); 00177 //command.add(getHost().getCommand(createRequest)); 00178 command.add(getHost().getCommand(createRequest2)); 00179 00180 return command; 00181 00182 00183 /*IElementType type = RosElementTypes.Package_2001; 00184 CreateElementRequest cer = new CreateElementRequest(RosElementTypes.Package_2001); 00185 CreateElementRequest cer2 = new CreateElementRequest(type); 00186 cer.setContainer(((View) getHost().getModel()).getElement()); 00187 00188 00189 org.ros.model.ros.Package pack = (org.ros.model.ros.Package) element; 00190 00191 System.out.println("Package: " + pack.getName()); 00192 cer.setNewElement(pack); 00193 00194 ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor( 00195 new CreateElementRequestAdapter(cer), Node.class, 00196 ((IHintedType) type).getSemanticHint(), 00197 RosDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT); 00198 00199 CreateViewAndElementRequest req = new CreateViewAndElementRequest( 00200 viewDescriptor); 00201 req.setLocation(request.getLocation()); 00202 Command c = getHost().getCommand(req); 00203 return c; */ 00204 } 00205 00206 }