blob: eb6424aa4a29723612a7c28a468dee91ce4a1fed (
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*******************************************************************************
* 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.edit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.common.core.search.SearchMatch;
import org.eclipse.wst.common.core.search.pattern.QualifiedName;
import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification;
import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentDescriptionProvider;
import org.eclipse.wst.wsdl.Binding;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Message;
import org.eclipse.wst.wsdl.PortType;
import org.eclipse.wst.wsdl.WSDLElement;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.search.IWSDLSearchConstants;
public class WSDLComponentDescriptionProvider extends LabelProvider implements IComponentDescriptionProvider {
private static final Image BINDING_IMAGE = WSDLEditorPlugin.getInstance().getImage("icons/binding_obj.gif"); //$NON-NLS-1$
private static final Image PORTTYPE_IMAGE = WSDLEditorPlugin.getInstance().getImage("icons/porttype_obj.gif"); //$NON-NLS-1$
private static final Image MESSAGE_IMAGE = WSDLEditorPlugin.getInstance().getImage("icons/message_obj.gif"); //$NON-NLS-1$
public boolean isApplicable(Object component) {
return true;
}
public String getQualifier(Object component) {
String result = null;
if (component instanceof ComponentSpecification)
{
result = ((ComponentSpecification)component).getQualifier();
}
else if (component instanceof WSDLElement)
{
result = ((WSDLElement) component).getEnclosingDefinition().getTargetNamespace();
}
else if (component instanceof SearchMatch)
{
QualifiedName qualifiedName = getQualifiedNameForSearchMatch((SearchMatch)component);
if (qualifiedName != null)
{
result = qualifiedName.getNamespace();
}
}
return result;
}
public String getName(Object component) {
String result = null;
if (component instanceof ComponentSpecification)
{
result = ((ComponentSpecification)component).getName();
}
else if (component instanceof WSDLElement)
{
result = ((WSDLElement)component).getElement().getAttribute("name"); //$NON-NLS-1$
}
else if (component instanceof SearchMatch)
{
QualifiedName qualifiedName = getQualifiedNameForSearchMatch((SearchMatch)component);
if (qualifiedName != null)
{
result = qualifiedName.getLocalName();
}
}
return result;
}
public Image getFileIcon(Object component) {
return WSDLEditorPlugin.getInstance().getImage("icons/wsdl_file_obj.gif"); //$NON-NLS-1$
}
public IFile getFile(Object component) {
IFile result = null;
if (component instanceof ComponentSpecification)
{
result = ((ComponentSpecification)component).getFile();
}
else if (component instanceof SearchMatch)
{
result = ((SearchMatch)component).getFile();
}
else if (component instanceof WSDLElement)
{
WSDLElement concreteComponent = (WSDLElement) component;
Definition definition = concreteComponent.getEnclosingDefinition();
if (definition != null)
{
// TODO (cs) revisit and test more
//
String location = definition.getLocation();
String platformResource = "platform:/resource"; //$NON-NLS-1$
if (location != null && location.startsWith(platformResource))
{
Path path = new Path(location.substring(platformResource.length()));
result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}
}
}
return result;
}
public ILabelProvider getLabelProvider() {
return this;
}
public String getText(Object element) {
String result = ""; //$NON-NLS-1$
String name = getName(element);
if (name != null) {
result += name;
}
return result;
}
public Image getImage(Object component)
{
Image result = null;
if (component instanceof ComponentSpecification)
{
QualifiedName qualifiedName = ((ComponentSpecification) component).getMetaName();
if ( qualifiedName != null ){
if ( qualifiedName.equals(IWSDLSearchConstants.BINDING_META_NAME))
result = BINDING_IMAGE;
else if ( qualifiedName.equals(IWSDLSearchConstants.PORT_TYPE_META_NAME))
result = PORTTYPE_IMAGE;
else if ( qualifiedName.equals(IWSDLSearchConstants.MESSAGE_META_NAME))
result = MESSAGE_IMAGE;
}
}
else if (component instanceof SearchMatch)
{
SearchMatch searchMatch = (SearchMatch)component;
QualifiedName qualifiedName = (QualifiedName)searchMatch.map.get("metaName"); //$NON-NLS-1$
if ( qualifiedName != null ){
if ( qualifiedName.equals(IWSDLSearchConstants.BINDING_META_NAME))
result = BINDING_IMAGE;
else if ( qualifiedName.equals(IWSDLSearchConstants.PORT_TYPE_META_NAME))
result = PORTTYPE_IMAGE;
else if ( qualifiedName.equals(IWSDLSearchConstants.MESSAGE_META_NAME))
result = MESSAGE_IMAGE;
}
}
else if (component instanceof Binding)
result = BINDING_IMAGE;
else if (component instanceof PortType)
result = PORTTYPE_IMAGE;
else if (component instanceof Message)
result = MESSAGE_IMAGE;
return result;
}
private QualifiedName getQualifiedNameForSearchMatch(SearchMatch match) {
QualifiedName qualifiedName = null;
Object o = match.map.get("name"); //$NON-NLS-1$
if (o != null && o instanceof QualifiedName)
{
qualifiedName = (QualifiedName)o;
}
return qualifiedName;
}
}
|