KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > ecore > genmodel > action > CreateChildAction


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: CreateChildAction.java,v 1.2 2005/06/08 06:17:51 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.action;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.ui.IEditorPart;
25
26 import org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelEditPlugin;
27 import org.eclipse.emf.common.command.Command;
28 import org.eclipse.emf.common.command.UnexecutableCommand;
29 import org.eclipse.emf.edit.command.CommandParameter;
30 import org.eclipse.emf.edit.command.CreateChildCommand;
31 import org.eclipse.emf.edit.domain.EditingDomain;
32 import org.eclipse.emf.edit.ui.action.StaticSelectionCommandAction;
33 import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
34
35
36 /**
37  * This performs child creation by delegating to a {@link CreateChildCommand}.
38  */

39 public class CreateChildAction extends StaticSelectionCommandAction
40 {
41   /**
42    * This is the descriptor for the child to be created.
43    */

44   protected CommandParameter newChildDescriptor;
45
46   /**
47    * This constructs an instance of an action that creates a child
48    * descripted by newChildDescriptor.
49    */

50   public CreateChildAction(IEditorPart editorPart, ISelection selection, CommandParameter newChildDescriptor)
51   {
52     super(editorPart);
53     this.newChildDescriptor = newChildDescriptor;
54     configureAction(selection);
55   }
56
57   /**
58    * This returns the image that is used if the command does not provide an
59    * override.
60    */

61   protected ImageDescriptor getDefaultImageDescriptor()
62   {
63     return ExtendedImageRegistry.INSTANCE.getImageDescriptor(GenModelEditPlugin.INSTANCE.getImage("CreateChild"));
64   }
65
66   /**
67    * This creates the command that creates the child and adds it under the
68    * single selected object, specified in collection.
69    */

70   protected Command createActionCommand(EditingDomain editingDomain, Collection JavaDoc collection)
71   {
72     if (collection.size() == 1)
73     {
74       return CreateChildCommand.create(editingDomain, collection.iterator().next(), newChildDescriptor, collection);
75     }
76     else
77     {
78       return UnexecutableCommand.INSTANCE;
79     }
80   }
81 }
82
Popular Tags