use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationAdvancedSection method doHandleEvent.
public void doHandleEvent(Event e) {
if (e.widget == substGroupCombo) {
if (e.type == SWT.Traverse) {
if (e.detail == SWT.TRAVERSE_ARROW_NEXT || e.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
isTraversing = true;
return;
}
}
XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
String value = substGroupCombo.getText();
String oldValue = eleDec.getElement().getAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE);
if (oldValue == null)
oldValue = EMPTY;
if (value.equals(oldValue))
return;
UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
command.setDeleteIfEmpty(true);
getCommandStack().execute(command);
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationAdvancedSection method handleWidgetSelection.
private void handleWidgetSelection(SelectionEvent e) {
if (e.widget == blockCombo) {
XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
String value = blockCombo.getText();
UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.BLOCK_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_BLOCK);
command.setDeleteIfEmpty(true);
getCommandStack().execute(command);
} else if (e.widget == finalCombo) {
XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
String value = finalCombo.getText();
UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.FINAL_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_FINAL);
command.setDeleteIfEmpty(true);
getCommandStack().execute(command);
} else if (e.widget == abstractCombo) {
XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
String value = abstractCombo.getText();
UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.ABSTRACT_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_ABSTRACT);
command.setDeleteIfEmpty(true);
getCommandStack().execute(command);
} else if (e.widget == substGroupCombo) {
IEditorPart editor = getActiveEditor();
if (editor == null)
return;
ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDSubstitutionGroupEditManager.class);
String selection = substGroupCombo.getText();
ComponentSpecification newValue;
IComponentDialog dialog = null;
if (selection.equals(Messages._UI_COMBO_BROWSE)) {
dialog = manager.getBrowseDialog();
} else if (selection.equals(Messages._UI_COMBO_NEW)) {
dialog = manager.getNewDialog();
}
if (dialog != null) {
if (dialog.createAndOpen() == Window.OK) {
newValue = dialog.getSelectedComponent();
manager.modifyComponentReference(input, newValue);
} else {
substGroupCombo.setText("");
}
} else // use the value from selected quickPick item
{
newValue = getComponentSpecFromQuickPickForValue(selection, manager);
if (newValue != null)
manager.modifyComponentReference(input, newValue);
}
} else if (e.widget == nillableCombo) {
XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
String value = nillableCombo.getText();
UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.NILLABLE_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NILLABLE);
command.setDeleteIfEmpty(true);
getCommandStack().execute(command);
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationAdvancedSection method refresh.
public void refresh() {
super.refresh();
fillSubstitutionGroupCombo();
setListenerEnabled(false);
try {
if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
composite.setEnabled(!isReadOnly);
if (// global element
eleDec.getContainer() instanceof XSDSchema) {
abstractCombo.setEnabled(true);
finalCombo.setEnabled(true);
substGroupCombo.setEnabled(true);
nillableCombo.setEnabled(true);
} else {
abstractCombo.setEnabled(false);
finalCombo.setEnabled(false);
substGroupCombo.setEnabled(false);
// Nillable when used in a local element declaration can't be set on
// on elements that use @ref.
nillableCombo.setEnabled(!eleDec.isElementDeclarationReference());
}
Element element = eleDec.getElement();
if (element.hasAttribute(XSDConstants.BLOCK_ATTRIBUTE)) {
String blockAttValue = element.getAttribute(XSDConstants.BLOCK_ATTRIBUTE);
blockCombo.setText(blockAttValue);
} else {
blockCombo.setText(EMPTY);
}
// should show the value dynamically
if (element.hasAttribute(XSDConstants.NILLABLE_ATTRIBUTE)) {
String attrValue = element.getAttribute(XSDConstants.NILLABLE_ATTRIBUTE);
nillableCombo.setText(attrValue);
} else {
nillableCombo.setText(EMPTY);
}
if (element.hasAttribute(XSDConstants.FINAL_ATTRIBUTE)) {
String finalAttValue = element.getAttribute(XSDConstants.FINAL_ATTRIBUTE);
finalCombo.setText(finalAttValue);
} else {
finalCombo.setText(EMPTY);
}
if (element.hasAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)) {
abstractCombo.setText(element.getAttribute(XSDConstants.ABSTRACT_ATTRIBUTE));
} else
abstractCombo.setText(EMPTY);
if (element.hasAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
substGroupCombo.setText(element.getAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE));
} else {
substGroupCombo.setText(EMPTY);
}
}
} catch (Exception e) {
}
setListenerEnabled(true);
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method getInputXSDAnnotation.
public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
XSDAnnotation xsdAnnotation = null;
XSDFactory factory = XSDFactory.eINSTANCE;
if (input instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDNotationDeclaration) {
XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDXPathDefinition) {
XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroup) {
XSDModelGroup xsdComp = (XSDModelGroup) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDWildcard) {
XSDWildcard xsdComp = (XSDWildcard) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDSchema) {
XSDSchema xsdComp = (XSDSchema) input;
List list = xsdComp.getAnnotations();
if (list.size() > 0) {
xsdAnnotation = (XSDAnnotation) list.get(0);
} else {
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
if (xsdComp.getContents() != null) {
xsdComp.getContents().add(0, xsdAnnotation);
}
}
}
return xsdAnnotation;
} else if (input instanceof XSDFacet) {
XSDFacet xsdComp = (XSDFacet) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDTypeDefinition) {
XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDInclude) {
XSDInclude xsdComp = (XSDInclude) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDImport) {
XSDImport xsdComp = (XSDImport) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDRedefine) {
XSDRedefine xsdComp = (XSDRedefine) input;
List contents = xsdComp.getContents();
for (int i = 0; i < contents.size(); i++) {
Object content = contents.get(i);
if (content instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) content;
break;
}
}
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
contents.add(0, xsdAnnotation);
}
return xsdAnnotation;
} else if (input instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) input;
}
if (createIfNotExist) {
formatAnnotation(xsdAnnotation);
}
return xsdAnnotation;
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupCommand method getOwner.
private XSDConcreteComponent getOwner() {
XSDConcreteComponent owner = null;
if (parent instanceof XSDElementDeclaration) {
XSDElementDeclaration ed = (XSDElementDeclaration) parent;
if (ed.getTypeDefinition() != null) {
if (ed.getAnonymousTypeDefinition() == null) {
ed.setTypeDefinition(null);
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = ed.getTypeDefinition();
} else {
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = td;
}
} else if (ed.getAnonymousTypeDefinition() == null) {
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = td;
} else if (ed.getAnonymousTypeDefinition() instanceof XSDComplexTypeDefinition) {
owner = ed.getAnonymousTypeDefinition();
} else if (ed.getAnonymousTypeDefinition() instanceof XSDSimpleTypeDefinition) {
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = td;
}
} else if (parent instanceof XSDModelGroup) {
newModelGroup = createModelGroup();
((XSDModelGroup) parent).getContents().add(newModelGroup.getContainer());
} else if (parent instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) parent;
owner = parent;
if (ct.getContent() instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) ct.getContent();
if (particle.getContent() instanceof XSDModelGroup) {
owner = null;
newModelGroup = createModelGroup();
XSDModelGroup newParent = (XSDModelGroup) particle.getContent();
newParent.getContents().add(newModelGroup.getContainer());
}
}
} else if (parent instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition modelGroupDefinition = (XSDModelGroupDefinition) parent;
owner = null;
newModelGroup = createModelGroup();
if (modelGroupDefinition.getModelGroup() != null) {
XSDModelGroup newParent = modelGroupDefinition.getModelGroup();
newParent.getContents().add(newModelGroup.getContainer());
} else {
modelGroupDefinition.setModelGroup(newModelGroup);
}
}
return owner;
}
Aggregations