blob: f04dfe25283a87fc4936d01a1a6260ad3a47a37a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.actions;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager;
import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog;
import org.eclipse.wst.xsd.ui.internal.common.util.Messages;
import org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager;
import org.eclipse.xsd.XSDComplexTypeDefinition;
public class SetBaseTypeAction extends XSDBaseAction
{
public static String ID = "org.eclipse.wst.xsd.ui.internal.common.actions.setBaseType"; //$NON-NLS-1$
public SetBaseTypeAction(IWorkbenchPart part)
{
super(part);
setText(Messages._UI_ACTION_SET_BASE_TYPE + "..."); //$NON-NLS-1$
setId(ID);
}
public void run()
{
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter)
{
selection = ((XSDBaseAdapter) selection).getTarget();
if (selection instanceof XSDComplexTypeDefinition)
{
XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) selection;
if (getWorkbenchPart() instanceof IEditorPart)
{
IEditorPart editor = (IEditorPart)getWorkbenchPart();
ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class);
ComponentSpecification newValue;
IComponentDialog dialog= null;
dialog = manager.getBrowseDialog();
if (dialog != null)
{
if (dialog.createAndOpen() == Window.OK)
{
newValue = dialog.getSelectedComponent();
manager.modifyComponentReference(ct, newValue);
}
}
}
}
}
}
}