blob: a0873fc8cb1c5abb0df070431b2ed30f6c51513f [file] [log] [blame]
kchongee4b4cf2007-05-02 17:49:40 +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 *******************************************************************************/
csalterce820002006-01-10 07:53:46 +000011package org.eclipse.wst.xsd.ui.internal.refactor.actions;
12
kchong38cbf172006-03-29 03:38:21 +000013
14import org.eclipse.jface.viewers.ISelection;
csalterce820002006-01-10 07:53:46 +000015import org.eclipse.swt.widgets.Menu;
csalterce820002006-01-10 07:53:46 +000016import org.eclipse.ui.IEditorPart;
csalterce820002006-01-10 07:53:46 +000017import org.eclipse.ui.IWorkbenchPartSite;
kchong2be71b32006-04-11 16:32:03 +000018import org.eclipse.wst.xsd.ui.internal.editor.ISelectionMapper;
kchong38cbf172006-03-29 03:38:21 +000019import org.eclipse.wst.xsd.ui.internal.refactor.actions.XSDRefactorActionGroup;
csalterce820002006-01-10 07:53:46 +000020import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorActionGroup;
21import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorGroupActionDelegate;
22import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorGroupSubMenu;
csalterce820002006-01-10 07:53:46 +000023import org.eclipse.xsd.XSDSchema;
csalterce820002006-01-10 07:53:46 +000024
25public class XSDRefactorGroupActionDelegate extends RefactorGroupActionDelegate {
26
27 public XSDRefactorGroupActionDelegate() {
28 super();
29 }
30
31 /**
32 * Fills the menu with applicable refactor sub-menues
33 * @param menu The menu to fill
34 */
35 protected void fillMenu(Menu menu) {
36 if (fSelection == null) {
37 return;
38 }
39 if (workbenchPart != null) {
40 IWorkbenchPartSite site = workbenchPart.getSite();
41 if (site == null)
42 return;
43
44 IEditorPart editor = site.getPage().getActiveEditor();
kchong38cbf172006-03-29 03:38:21 +000045 if (editor != null) {
46 XSDSchema schema = (XSDSchema)editor.getAdapter(XSDSchema.class);
47 ISelectionMapper mapper = (ISelectionMapper)editor.getAdapter(ISelectionMapper.class);
48 if (schema != null)
49 {
50 ISelection selection = mapper != null ? mapper.mapSelection(fSelection) : fSelection;
51 RefactorActionGroup refactorMenuGroup = new XSDRefactorActionGroup(selection, schema);
csalterce820002006-01-10 07:53:46 +000052 RefactorGroupSubMenu subMenu = new RefactorGroupSubMenu(refactorMenuGroup);
53 subMenu.fill(menu, -1);
kchong38cbf172006-03-29 03:38:21 +000054 }
csalterce820002006-01-10 07:53:46 +000055 }
56
57 }
58
59 }
csalterce820002006-01-10 07:53:46 +000060}