blob: e2f287c108836e3a216bd729fdac083cf0e34bd6 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/*******************************************************************************
* Copyright (c) 2001, 2004 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.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.wst.wsdl.WSDLElement;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.commands.WSDLElementCommand;
import org.eclipse.wst.wsdl.ui.internal.widgets.NewComponentDialog;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML;
import org.w3c.dom.Node;
public abstract class WSDLElementAction extends Action
{
protected WSDLElementCommand modelCommand;
private IEditorPart editorPart;
public WSDLElementAction
(WSDLElementCommand command,
String undoDescription,
String label,
ImageDescriptor image)
{
super(label,image);
modelCommand = command;
}
public void setEditorPart(IEditorPart editorPart)
{
this.editorPart = editorPart;
}
/*
private String getUndoDescription()
{
return undoDescription;
}
*/
abstract protected WSDLElement getOwner();
abstract protected boolean showDialog();
public void run()
{
boolean ok = showDialog();
if (ok)
{
preRun();
modelCommand.run();
format();
selectObject();
postRun();
}
}
protected void preRun()
{
}
protected void postRun()
{
}
/*
private void beginRecording()
{
Node node = null;
if (getOwner() != null)
node = getOwner().getElement();
if (node instanceof IDOMNode)
{
((IDOMNode)node).getModel().beginRecording(this, getUndoDescription());
}
}
private void endRecording()
{
Node node = null;
if (getOwner() != null)
node = getOwner().getElement();
if (node instanceof IDOMNode)
{
((IDOMNode)node).getModel().endRecording(this);
}
}
*/
protected WSDLElement getWSDLElement()
{
return modelCommand.getWSDLElement();
}
private void format()
{
Node parentNode = null;
if (getOwner() != null)
parentNode = getOwner().getElement();
if (parentNode instanceof IDOMNode)
{
// format selected node
FormatProcessorXML formatProcessorXML = new FormatProcessorXML();
formatProcessorXML.formatNode((IDOMNode)parentNode);
}
}
private void selectObject()
{
if (editorPart != null && getOwner() != null)
{
Object object = getWSDLElement();
if (object != null)
{
ISelectionProvider selectionProvider = (ISelectionProvider)editorPart.getAdapter(ISelectionProvider.class);
if (selectionProvider != null)
{
selectionProvider.setSelection(new StructuredSelection(object));
}
}
}
}
protected String showDialogHelper(String title, String defaultName)
{
String result = defaultName;
NewComponentDialog dialog = new NewComponentDialog(WSDLEditorPlugin.getShell(), title, defaultName);
int rc = dialog.createAndOpen();
if (rc == IDialogConstants.OK_ID)
{
result = dialog.getName();
}
else
{
result = null;
}
return result;
}
}
|