blob: d49a367a5872ac445ec0f6bef1a0b08f2267be38 [file] [log] [blame]
kchong38cbf172006-03-29 03:38:21 +00001/*******************************************************************************
2 * Copyright (c) 2001, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
kchong2be71b32006-04-11 16:32:03 +000011package org.eclipse.wst.xsd.ui.internal.common.actions;
kchong38cbf172006-03-29 03:38:21 +000012
13import org.eclipse.emf.common.notify.Adapter;
14import org.eclipse.jface.viewers.IStructuredSelection;
kchong38cbf172006-03-29 03:38:21 +000015import org.eclipse.ui.IWorkbenchPart;
kchong2be71b32006-04-11 16:32:03 +000016import org.eclipse.wst.xsd.ui.internal.adapters.XSDAdapterFactory;
17import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
18import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDModelGroupDefinitionCommand;
kchong62c89ad2006-04-19 16:40:50 +000019import org.eclipse.wst.xsd.ui.internal.common.util.Messages;
kchong38cbf172006-03-29 03:38:21 +000020import org.eclipse.xsd.XSDConcreteComponent;
21
22public class AddXSDModelGroupDefinitionAction extends XSDBaseAction
23{
kchong62c89ad2006-04-19 16:40:50 +000024 public static final String MODELGROUPDEFINITION_ID = "AddXSDModelGroupDefinitionAction"; //$NON-NLS-1$
25 public static final String MODELGROUPDEFINITIONREF_ID = "AddXSDModelGroupDefinitionRefAction"; //$NON-NLS-1$
kchong38cbf172006-03-29 03:38:21 +000026 boolean isReference;
27
28 public AddXSDModelGroupDefinitionAction(IWorkbenchPart part, boolean isReference)
29 {
30 super(part);
31 this.isReference = isReference;
32 if (isReference)
33 {
kchong62c89ad2006-04-19 16:40:50 +000034 setText(Messages._UI_ACTION_ADD_GROUP_REF);
kchong38cbf172006-03-29 03:38:21 +000035 setId(MODELGROUPDEFINITION_ID);
36 }
37 else
38 {
kchong62c89ad2006-04-19 16:40:50 +000039 setText(Messages._UI_ACTION_ADD_GROUP);
kchong38cbf172006-03-29 03:38:21 +000040 setId(MODELGROUPDEFINITIONREF_ID);
41 }
42 }
43
44 public void run()
45 {
46 Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
47 XSDConcreteComponent xsdConcreteComponent = null;
48 if (selection instanceof XSDBaseAdapter)
49 {
50 xsdConcreteComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget();
51 }
52 if (xsdConcreteComponent != null)
53 {
54 AddXSDModelGroupDefinitionCommand command = new AddXSDModelGroupDefinitionCommand(getText(), xsdConcreteComponent, isReference);
55 getCommandStack().execute(command);
kchongf9510bf2006-09-05 21:28:47 +000056
57 addedComponent = command.getAddedComponent();
58 Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
kchong572e8ac2006-05-13 18:02:58 +000059 selectAddedComponent(adapter);
kchong38cbf172006-03-29 03:38:21 +000060 }
61 }
62}