PackageCreateCommand.java
Go to the documentation of this file.
00001 package org.ros.model.ros.diagram.edit.commands;
00002 
00003 import org.eclipse.core.commands.ExecutionException;
00004 import org.eclipse.core.resources.IFolder;
00005 import org.eclipse.core.resources.IProject;
00006 import org.eclipse.core.resources.IResource;
00007 import org.eclipse.core.resources.ResourcesPlugin;
00008 import org.eclipse.core.runtime.CoreException;
00009 import org.eclipse.core.runtime.IAdaptable;
00010 import org.eclipse.core.runtime.IProgressMonitor;
00011 import org.eclipse.emf.common.util.URI;
00012 import org.eclipse.emf.ecore.EObject;
00013 import org.eclipse.emf.ecore.resource.Resource;
00014 import org.eclipse.emf.ecore.resource.ResourceSet;
00015 import org.eclipse.gmf.runtime.common.core.command.CommandResult;
00016 import org.eclipse.gmf.runtime.common.core.command.ICommand;
00017 import org.eclipse.gmf.runtime.emf.type.core.IElementType;
00018 import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
00019 import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
00020 import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
00021 import org.eclipse.gmf.runtime.notation.View;
00022 import org.eclipse.jface.dialogs.MessageDialog;
00023 import org.eclipse.swt.SWT;
00024 import org.eclipse.ui.PartInitException;
00025 import org.eclipse.ui.PlatformUI;
00026 import org.ros.model.ros.Architecture;
00027 import org.ros.model.ros.Package;
00028 import org.ros.model.ros.RosFactory;
00029 import org.ros.model.ros.diagram.WSFileDialog;
00030 
00034 public class PackageCreateCommand extends EditElementCommand {
00035 
00039         public PackageCreateCommand(CreateElementRequest req) {
00040                 super(req.getLabel(), null, req);
00041         }
00042 
00047         protected EObject getElementToEdit() {
00048                 EObject container = ((CreateElementRequest) getRequest())
00049                                 .getContainer();
00050                 if (container instanceof View) {
00051                         container = ((View) container).getElement();
00052                 }
00053                 return container;
00054         }
00055 
00059         public boolean canExecute() {
00060                 return true;
00061 
00062         }
00063 
00064         protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
00065                         IAdaptable info) throws ExecutionException {
00066 
00067                 //IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("Tatiana");
00068                 //IFolder filters = project.getFolder("filters");
00069 
00070                 WSFileDialog dialog = new WSFileDialog(PlatformUI.getWorkbench()
00071                                 .getActiveWorkbenchWindow().getShell(), SWT.SINGLE,
00072                                 "Choose a filter to create new replayable", ResourcesPlugin
00073                                                 .getWorkspace().getRoot(), true, new String[] {
00074                                                 "ros_package", "ros_coordinator" }, null);
00075                 int result = dialog.open();
00076                 if (result == WSFileDialog.OK) {
00077                         IResource resource = dialog.getSingleResult();
00078                         System.out.println(" ######## Selected File "
00079                                         + resource.getFullPath());
00080                         ResourceSet resourceSet = getEditingDomain().getResourceSet();
00081                         Resource res = resourceSet.getResource(
00082                                         URI.createURI("platform:/resource/"
00083                                                         + resource.getFullPath()), true);
00084                         if (res.getContents().size() > 1) {
00085                                 for (int i = 0; i < res.getContents().size(); i++)
00086                                         System.out.println("Contents:"
00087                                                         + res.getContents().get(i).toString());
00088                         }
00089                         Package newElement = (Package) res.getContents().get(0);
00090                         Architecture owner = (Architecture) getElementToEdit();
00091                         owner.getPackages().add(newElement);
00092 
00093                         System.out.println("Adding new Element to Architecture: "
00094                                         + newElement.toString());
00095 
00096                         doConfigure(newElement, monitor, info);
00097 
00098                         ((CreateElementRequest) getRequest()).setNewElement(newElement);
00099                         return CommandResult.newOKCommandResult(newElement);
00100                 } else
00101                         return null;
00102 
00103         }
00104 
00108         protected void doConfigure(Package newElement, IProgressMonitor monitor,
00109                         IAdaptable info) throws ExecutionException {
00110                 IElementType elementType = ((CreateElementRequest) getRequest())
00111                                 .getElementType();
00112                 ConfigureRequest configureRequest = new ConfigureRequest(
00113                                 getEditingDomain(), newElement, elementType);
00114                 configureRequest.setClientContext(((CreateElementRequest) getRequest())
00115                                 .getClientContext());
00116                 configureRequest.addParameters(getRequest().getParameters());
00117                 ICommand configureCommand = elementType
00118                                 .getEditCommand(configureRequest);
00119                 if (configureCommand != null && configureCommand.canExecute()) {
00120                         configureCommand.execute(monitor, info);
00121                 }
00122         }
00123 
00124 }


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:34