KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > action > AddRootTopAction


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: AddRootTopAction.java,v 1.3 2005/06/08 06:23:57 nickb Exp $
16  */

17 package org.eclipse.emf.mapping.action;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 import org.eclipse.emf.edit.command.AddCommand;
27 import org.eclipse.emf.edit.ui.action.CommandAction;
28 import org.eclipse.emf.mapping.MappingPackage;
29 import org.eclipse.emf.mapping.MappingRoot;
30 import org.eclipse.emf.mapping.domain.MappingDomain;
31
32
33 /**
34  * This adds new root inputs to the mapping domain's root mapping.
35  */

36 public class AddRootTopAction extends CommandAction
37 {
38   /**
39    * This method should be overriden with a domain-specific implementation
40    * that returns the inputs to be added, e.g., by querying the user with a dialog.
41    */

42   protected Collection JavaDoc getTopsToAdd()
43   {
44     return null;
45   }
46
47   /**
48    * This action ignores the selection.
49    */

50   public void selectionChanged(IAction action, ISelection selection)
51   {
52   }
53
54   public void run(IAction action)
55   {
56     Collection JavaDoc additions = getTopsToAdd();
57     MappingRoot mappingRoot = ((MappingDomain)editingDomain).getMappingRoot();
58     command = AddCommand.create
59       (editingDomain,
60        mappingRoot,
61        mappingRoot.isTopToBottom() ?
62          //mappingRoot.ePackageMapping().getMapping_Inputs() :
63
//mappingRoot.ePackageMapping().getMapping_Outputs(),
64
MappingPackage.eINSTANCE.getMapping_Inputs() :
65          MappingPackage.eINSTANCE.getMapping_Outputs(),
66        additions);
67
68     super.run(action);
69   }
70
71   public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart)
72   {
73     super.setActiveWorkbenchPart(workbenchPart);
74     action.setEnabled(true);
75   }
76 }
77
Popular Tags