Skip to main content
summaryrefslogtreecommitdiffstats
blob: f5b727e3e6cba581e730dbc444db3a05d9c115fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
 * Copyright (c) 2001, 2006 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.wsdl.ui.internal.asd.actions;

import java.util.List;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.ui.internal.Messages;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.adapters.basic.W11Description;
import org.eclipse.wst.wsdl.ui.internal.adapters.commands.W11EditNamespacesCommand;
import org.eclipse.wst.wsdl.ui.internal.asd.ASDEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.asd.facade.IDescription;
import org.eclipse.wst.wsdl.ui.internal.asd.outline.ICategoryAdapter;
import org.eclipse.wst.wsdl.ui.internal.dialogs.EditNamespacesDialog;

public class ASDEditNamespacesAction extends BaseSelectionAction {
	public static String ID = "ASDEditNamespacesAction";  //$NON-NLS-1$
	
	private IDescription description;
	
	public ASDEditNamespacesAction(IWorkbenchPart part, IDescription description) {
		super(part);
		setId(ID);
		String text = Messages._UI_EDIT_NAMESPACES; //$NON-NLS-1$
		setText(text);
		
		this.description = description;
	}
	
	public void run() {
		Object o = description;
		if (getSelectedObjects().size() > 0) {
			if (o instanceof ICategoryAdapter) {
				o = ((ICategoryAdapter) o).getOwnerDescription();
			}
		}
		
		if (o instanceof IDescription) {
			// TODO: The code below is not generic.  We need to revisit this to ensure it is
			// generic.  IDescription needs a getNamespacesInfo() and getEditNamespacesCommand()...
			IDescription description = (IDescription) o;
			W11Description w11Description = (W11Description) o;
			Definition definition = (Definition) w11Description.getTarget();
			
			IPath path = new Path(definition.getDocumentBaseURI());
			List namespaceInfoList = w11Description.getNamespacesInfo();
			String tns = description.getTargetNamespace();
			EditNamespacesDialog dialog = new EditNamespacesDialog(WSDLEditorPlugin.getShell(), path, Messages._UI_EDIT_NAMESPACES_DIALOG_TITLE, tns, namespaceInfoList); //$NON-NLS-1$
			int rc = dialog.createAndOpen();
			if (rc == IDialogConstants.OK_ID) {
				List newInfoList = dialog.getNamespaceInfoList();
				W11EditNamespacesCommand command = (W11EditNamespacesCommand) w11Description.getEditNamespacesCommand();
				command.setNamespacesInfo(newInfoList);
				command.setTargetNamespace(dialog.getTargetNamespace());
				CommandStack stack = (CommandStack) ASDEditorPlugin.getActiveEditor().getAdapter(CommandStack.class);
			    stack.execute(command);
		    }
		}
	}
}

Back to the top