KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > ui > action > CreateChildAction


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2005 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.3 2005/06/08 06:20:52 nickb Exp $
16  */

17 package org.eclipse.emf.edit.ui.action;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.ui.IEditorPart;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 import org.eclipse.emf.common.command.Command;
27 import org.eclipse.emf.common.command.UnexecutableCommand;
28 import org.eclipse.emf.edit.command.CreateChildCommand;
29 import org.eclipse.emf.edit.domain.EditingDomain;
30
31
32 /**
33  * A child creation action is implemented by creating a {@link
34  * CreateChildCommand}.
35  */

36 public class CreateChildAction extends StaticSelectionCommandAction
37 {
38   /**
39    * This describes the child to be created.
40    */

41   protected Object JavaDoc descriptor;
42
43   /**
44    * This constructs an instance of an action that creates a child
45    * specified by <code>descriptor</code> for the single object in the
46    * <code>selection</code>.
47    * @since 2.1.0
48    */

49   public CreateChildAction(IWorkbenchPart workbenchPart, ISelection selection,
50                            Object JavaDoc descriptor)
51   {
52     super(workbenchPart);
53     this.descriptor = descriptor;
54     configureAction(selection);
55   }
56
57   /**
58    * This constructor is simply retained for binary compatibility. It just
59    * calls the {@link #CreateChildAction(IWorkbenchPart, ISelection, Object)
60    * new form}.
61    */

62   public CreateChildAction(IEditorPart editorPart, ISelection selection,
63                            Object JavaDoc descriptor)
64   {
65     this((IWorkbenchPart)editorPart, selection, descriptor);
66   }
67
68   /**
69    * This creates the command for {@link
70    * StaticSelectionCommandAction#createActionCommand}.
71    */

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