KickJava   Java API By Example, From Geeks To Geeks.

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


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: CreateSiblingAction.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 sibling creation action is implemented by creating a {@link
34  * CreateChildCommand}.
35  */

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

41   protected Object JavaDoc descriptor;
42
43   /**
44    * This constructs an instance of an action that creates a sibling
45    * specified by <code>descriptor</code>.
46    * @since 2.1.0
47    */

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

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

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