kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
kchong | 2be71b3 | 2006-04-11 16:32:03 +0000 | [diff] [blame] | 11 | package org.eclipse.wst.xsd.ui.internal.common.actions; |
kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 12 | |
| 13 | import org.eclipse.emf.common.notify.Adapter; |
| 14 | import org.eclipse.jface.viewers.IStructuredSelection; |
kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 15 | import org.eclipse.ui.IWorkbenchPart; |
kchong | 2be71b3 | 2006-04-11 16:32:03 +0000 | [diff] [blame] | 16 | import org.eclipse.wst.xsd.ui.internal.adapters.XSDAdapterFactory; |
| 17 | import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; |
| 18 | import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDModelGroupDefinitionCommand; |
kchong | 62c89ad | 2006-04-19 16:40:50 +0000 | [diff] [blame] | 19 | import org.eclipse.wst.xsd.ui.internal.common.util.Messages; |
kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 20 | import org.eclipse.xsd.XSDConcreteComponent; |
| 21 | |
| 22 | public class AddXSDModelGroupDefinitionAction extends XSDBaseAction |
| 23 | { |
kchong | 62c89ad | 2006-04-19 16:40:50 +0000 | [diff] [blame] | 24 | public static final String MODELGROUPDEFINITION_ID = "AddXSDModelGroupDefinitionAction"; //$NON-NLS-1$ |
| 25 | public static final String MODELGROUPDEFINITIONREF_ID = "AddXSDModelGroupDefinitionRefAction"; //$NON-NLS-1$ |
kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 26 | boolean isReference; |
| 27 | |
| 28 | public AddXSDModelGroupDefinitionAction(IWorkbenchPart part, boolean isReference) |
| 29 | { |
| 30 | super(part); |
| 31 | this.isReference = isReference; |
| 32 | if (isReference) |
| 33 | { |
kchong | 62c89ad | 2006-04-19 16:40:50 +0000 | [diff] [blame] | 34 | setText(Messages._UI_ACTION_ADD_GROUP_REF); |
kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 35 | setId(MODELGROUPDEFINITION_ID); |
| 36 | } |
| 37 | else |
| 38 | { |
kchong | 62c89ad | 2006-04-19 16:40:50 +0000 | [diff] [blame] | 39 | setText(Messages._UI_ACTION_ADD_GROUP); |
kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 40 | 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); |
kchong | f9510bf | 2006-09-05 21:28:47 +0000 | [diff] [blame] | 56 | |
| 57 | addedComponent = command.getAddedComponent(); |
| 58 | Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); |
kchong | 572e8ac | 2006-05-13 18:02:58 +0000 | [diff] [blame] | 59 | selectAddedComponent(adapter); |
kchong | 38cbf17 | 2006-03-29 03:38:21 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |