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
179
180
181
182
183
184
185
186
|
/*******************************************************************************
* 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.xsd.ui.internal.properties;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDConstants;
public class NotationPropertySource
extends BasePropertySource
implements IPropertySource
{
/**
*
*/
public NotationPropertySource()
{
super();
}
/**
* @param viewer
* @param xsdSchema
*/
public NotationPropertySource(Viewer viewer, XSDSchema xsdSchema)
{
super(viewer, xsdSchema);
}
/**
* @param xsdSchema
*/
public NotationPropertySource(XSDSchema xsdSchema)
{
super(xsdSchema);
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
*/
public Object getEditableValue()
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
*/
public IPropertyDescriptor[] getPropertyDescriptors()
{
List list = new ArrayList();
// Create a descriptor and set a category
// Removed for tabbed properties
// PropertyDescriptor nameDescriptor =
// new TextPropertyDescriptor(
// XSDConstants.NAME_ATTRIBUTE,
// XSDConstants.NAME_ATTRIBUTE);
// list.add(nameDescriptor);
PropertyDescriptor publicDescriptor =
new TextPropertyDescriptor(
XSDConstants.PUBLIC_ATTRIBUTE,
XSDConstants.PUBLIC_ATTRIBUTE);
list.add(publicDescriptor);
PropertyDescriptor systemDescriptor =
new TextPropertyDescriptor(
XSDConstants.SYSTEM_ATTRIBUTE,
XSDConstants.SYSTEM_ATTRIBUTE);
list.add(systemDescriptor);
IPropertyDescriptor[] result = new IPropertyDescriptor[list.size()];
list.toArray(result);
return result;
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
*/
public Object getPropertyValue(Object id)
{
Object result = null;
if (id instanceof String)
{
result = element.getAttribute((String) id);
}
if (result == null)
{
result = "";
}
return result;
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
*/
public boolean isPropertySet(Object id)
{
return false;
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
*/
public void resetPropertyValue(Object id)
{
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
*/
public void setPropertyValue(Object id, Object value)
{
if (value == null)
{
value = "";
}
if (value instanceof String)
{
String newValue = (String)value;
if (((String)id).equals(XSDConstants.NAME_ATTRIBUTE))
{
if (validateName(newValue))
{
beginRecording(XSDEditorPlugin.getXSDString("_UI_NOTATION_NAME_CHANGE"), element);
if (newValue.length() > 0)
{
element.setAttribute(XSDConstants.NAME_ATTRIBUTE, newValue);
}
else
{
element.setAttribute(XSDConstants.NAME_ATTRIBUTE, "");
}
endRecording(element);
}
}
else if (((String)id).equals(XSDConstants.PUBLIC_ATTRIBUTE))
{
beginRecording(XSDEditorPlugin.getXSDString("_UI_NOTATION_PUBLIC_CHANGE"), element);
if (newValue.length() > 0)
{
element.setAttribute(XSDConstants.PUBLIC_ATTRIBUTE, newValue);
}
else
{
element.setAttribute(XSDConstants.PUBLIC_ATTRIBUTE, "");
}
endRecording(element);
}
else if (((String)id).equals(XSDConstants.SYSTEM_ATTRIBUTE))
{
beginRecording(XSDEditorPlugin.getXSDString("_UI_NOTATION_SYSTEM_CHANGE"), element);
if (newValue.length() > 0)
{
element.setAttribute(XSDConstants.SYSTEM_ATTRIBUTE, newValue);
}
else
{
element.removeAttribute(XSDConstants.SYSTEM_ATTRIBUTE);
}
endRecording(element);
}
}
Runnable delayedUpdate = new Runnable()
{
public void run()
{
if (viewer != null)
viewer.refresh();
}
};
Display.getCurrent().asyncExec(delayedUpdate);
}
}
|