Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-05-19 06:46:49 +0000
committerpfullbright2011-05-19 06:46:49 +0000
commit488c8ed168b822790fb4eac1fb8aaed93462bfe5 (patch)
treecbecd8dd7ad086798e66c1655013948b4447de99
parent8c72031a256669e8b9cccde8b1e28e43c778c011 (diff)
downloadwebtools.dali-488c8ed168b822790fb4eac1fb8aaed93462bfe5.tar.gz
webtools.dali-488c8ed168b822790fb4eac1fb8aaed93462bfe5.tar.xz
webtools.dali-488c8ed168b822790fb4eac1fb8aaed93462bfe5.zip
bug 345486
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java8
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java8
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java6
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java78
4 files changed, 76 insertions, 24 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java
index fd97f2fba3..18c1435b9e 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java
@@ -56,9 +56,7 @@ public class XsdComplexTypeDefinition
new FilteringIterable<XSDAttributeUse>(getXSDComponent().getAttributeUses()) {
@Override
protected boolean accept(XSDAttributeUse attrUse) {
- String otherNamespace = attrUse.getAttributeDeclaration().getTargetNamespace();
- return StringTools.stringsAreEqual(namespace, otherNamespace)
- || (StringTools.stringIsEmpty(namespace) && (StringTools.stringIsEmpty(otherNamespace)));
+ return XsdUtil.namespaceEquals(attrUse.getAttributeDeclaration(), namespace);
}
}) {
@Override
@@ -96,9 +94,7 @@ public class XsdComplexTypeDefinition
new FilteringIterable<XSDElementDeclaration>(getXSDElementDeclarations()) {
@Override
protected boolean accept(XSDElementDeclaration element) {
- String otherNamespace = element.getTargetNamespace();
- return StringTools.stringsAreEqual(namespace, otherNamespace)
- || (StringTools.stringIsEmpty(namespace) && (StringTools.stringIsEmpty(otherNamespace)));
+ return XsdUtil.namespaceEquals(element, namespace);
}
}) {
@Override
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java
index fa4a829fe5..c198baea58 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java
@@ -85,7 +85,7 @@ public class XsdSchema
public XsdTypeDefinition getTypeDefinition(String namespace, String name) {
for (XSDTypeDefinition typeDefinition : getXSDTypeDefinitions(namespace)) {
- if (typeDefinition.getTargetNamespace().equals(namespace) && typeDefinition.getName().equals(name)) {
+ if (XsdUtil.namespaceEquals(typeDefinition, namespace) && typeDefinition.getName().equals(name)) {
return (XsdTypeDefinition) XsdUtil.getAdapter(typeDefinition);
}
}
@@ -112,7 +112,7 @@ public class XsdSchema
return new FilteringIterable<XSDTypeDefinition>(getDeclaredXSDTypeDefinitions()) {
@Override
protected boolean accept(XSDTypeDefinition o) {
- return namespace.equals(o.getTargetNamespace());
+ return XsdUtil.namespaceEquals(o, namespace);
}
};
}
@@ -146,7 +146,7 @@ public class XsdSchema
new FilteringIterable<XSDElementDeclaration>(getXSDElementDeclarations()) {
@Override
protected boolean accept(XSDElementDeclaration o) {
- return o.getTargetNamespace().equals(namespace);
+ return XsdUtil.namespaceEquals(o, namespace);
}
}) {
@Override
@@ -158,7 +158,7 @@ public class XsdSchema
public XsdElementDeclaration getElementDeclaration(String namespace, String name) {
for (XSDElementDeclaration elementDeclaration : getXSDElementDeclarations()) {
- if (elementDeclaration.getTargetNamespace().equals(namespace) && elementDeclaration.getName().equals(name)) {
+ if (XsdUtil.namespaceEquals(elementDeclaration, namespace) && elementDeclaration.getName().equals(name)) {
return (XsdElementDeclaration) XsdUtil.getAdapter(elementDeclaration);
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java
index fb6519770c..f790428baf 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java
@@ -34,6 +34,7 @@ import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDModelGroupDefinition;
+import org.eclipse.xsd.XSDNamedComponent;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDSchemaContent;
@@ -51,6 +52,11 @@ public class XsdUtil {
static final XsdAdapterFactoryImpl adapterFactory = new XsdAdapterFactoryImpl();
+ public static boolean namespaceEquals(XSDNamedComponent comp, String namespace) {
+ String xsdNamespace = comp.getTargetNamespace();
+ return (xsdNamespace == null) ? StringTools.stringIsEmpty(namespace) : xsdNamespace.equals(namespace);
+ }
+
public static String getResolvedUri(String namespace, String location) {
String resolvedUri = null;
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
index eedc507131..5667c41aa4 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
@@ -26,6 +26,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
@@ -83,7 +84,6 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.PropertyPage;
-import org.eclipse.wst.common.uriresolver.internal.URI;
import org.eclipse.wst.xsd.contentmodel.internal.XSDImpl;
import org.eclipse.xsd.XSDSchema;
@@ -557,6 +557,30 @@ public class JaxbSchemasPropertiesPage
extends AbstractModel
implements Comparable<Schema> {
+ static String locationDisplayString(String location) {
+ if (location == null) {
+ return "";
+ }
+
+ URI uri = URI.createURI(location);
+ if (uri.isPlatformResource()) {
+ return uri.toPlatformString(false);
+ }
+
+ return location;
+ }
+
+ static String namespaceDisplayString(String namespace) {
+ if ("".equals(namespace)) {
+ return JptJaxbUiMessages.SchemasPage_noNamespaceText;
+ }
+ else if (null == namespace) {
+ return "";
+ }
+
+ return namespace;
+ }
+
Schema(String namespace, String location) {
super();
this.namespace = namespace;
@@ -581,10 +605,18 @@ public class JaxbSchemasPropertiesPage
firePropertyChanged(NAMESPACE_PROPERTY, old, namespace);
}
+ String namespaceDisplayString() {
+ return namespaceDisplayString(this.namespace);
+ }
+
String getLocation() {
return this.location;
}
+ String locationDisplayString() {
+ return locationDisplayString(getLocation());
+ }
+
void setLocation(String location) {
String old = this.location;
this.location = location;
@@ -658,9 +690,9 @@ public class JaxbSchemasPropertiesPage
public String getColumnText(Object element, int columnIndex) {
switch (columnIndex) {
case SchemaColumnAdapter.NAMESPACE_COLUMN :
- return ((Schema) element).getNamespace();
+ return ((Schema) element).namespaceDisplayString();
case SchemaColumnAdapter.LOCATION_COLUMN :
- return ((Schema) element).getLocation();
+ return ((Schema) element).locationDisplayString();
default :
return null;
}
@@ -696,8 +728,8 @@ public class JaxbSchemasPropertiesPage
this.mode = (this.currentSchema == null) ? Mode.ADD : Mode.EDIT;
if (this.mode == Mode.ADD) {
this.defaultMessage = JptJaxbUiMessages.SchemasPage_addSchemaMessage;
- this.location.setValue("");
- this.namespace.setValue("");
+ this.location.setValue(null);
+ this.namespace.setValue(null);
}
else {
this.defaultMessage = JptJaxbUiMessages.SchemasPage_editSchemaMessage;
@@ -739,14 +771,14 @@ public class JaxbSchemasPropertiesPage
locationLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
final Text locationText = new Text(composite, SWT.SINGLE | SWT.BORDER);
- locationText.setText(this.location.getValue());
+ locationText.setText(locationDisplayString());
locationText.setEditable(false);
locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
this.location.addPropertyChangeListener(
PropertyValueModel.VALUE,
new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent event) {
- locationText.setText((String) event.getNewValue());
+ locationText.setText(locationDisplayString());
}
});
@@ -769,17 +801,14 @@ public class JaxbSchemasPropertiesPage
namespaceLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
final Text namespaceText = new Text(composite, SWT.SINGLE | SWT.BORDER);
- namespaceText.setText(this.namespace.getValue());
+ namespaceText.setText(namespaceDisplayString());
namespaceText.setEditable(false);
namespaceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
this.namespace.addPropertyChangeListener(
PropertyValueModel.VALUE,
new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent event) {
- String newValue = (String) event.getNewValue();
- String display = (StringTools.stringIsEmpty(newValue)) ?
- JptJaxbUiMessages.SchemasPage_noNamespaceText : newValue;
- namespaceText.setText(display);
+ namespaceText.setText(namespaceDisplayString());
}
});
@@ -789,6 +818,14 @@ public class JaxbSchemasPropertiesPage
}
@Override
+ public void create() {
+ super.create();
+
+ // disable ok button until user does something and then validation takes over
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ }
+
+ @Override
protected boolean isResizable() {
return true;
}
@@ -807,7 +844,12 @@ public class JaxbSchemasPropertiesPage
String resolvedUri = XsdUtil.getResolvedUri(null, location);
XSDSchema schema = XSDImpl.buildXSDModel(resolvedUri);
- String newNamespace = (schema == null) ? null : schema.getTargetNamespace();
+ String newNamespace =
+ (schema == null) ?
+ null
+ : ((schema.getTargetNamespace()) == null ?
+ ""
+ : schema.getTargetNamespace());
this.namespace.setValue(newNamespace);
this.resolvedSchema = schema;
@@ -818,10 +860,18 @@ public class JaxbSchemasPropertiesPage
return this.namespace.getValue();
}
+ protected String namespaceDisplayString() {
+ return Schema.namespaceDisplayString(getNamespace());
+ }
+
public String getLocation() {
return this.location.getValue();
}
+ protected String locationDisplayString() {
+ return Schema.locationDisplayString(getLocation());
+ }
+
private void validate() {
if (this.resolvedSchema == null) {
setErrorMessage(JptJaxbUiMessages.SchemasPage_schemaUnresolvedMessage);
@@ -896,7 +946,7 @@ public class JaxbSchemasPropertiesPage
protected void okPressed() {
IFile file = this.locationPanel.getFile();
if (file != null) {
- this.location = URI.createPlatformResourceURI(file.getFullPath().toString()).toString();
+ this.location = URI.createPlatformResourceURI(file.getFullPath().toString(), false).toString();
}
else {
this.location = this.locationPanel.getXMLCatalogId();

Back to the top