Search in sources :

Example 1 with UpdateAttributeValueCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand in project webtools.sourceediting by eclipse.

the class XSDSubstitutionGroupEditManager method modifyComponentReference.

public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
    XSDElementDeclaration concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adapter = (Adapter) referencingObject;
        if (adapter.getTarget() instanceof XSDElementDeclaration) {
            concreteComponent = (XSDElementDeclaration) adapter.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDElementDeclaration) referencingObject;
    }
    if (concreteComponent != null) {
        if (component.isNew()) {
            XSDElementDeclaration elementDec = null;
            if (component.getMetaName() == IXSDSearchConstants.ELEMENT_META_NAME) {
                AddXSDElementCommand command = new AddXSDElementCommand(Messages._UI_ACTION_ADD_ELEMENT, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                elementDec = (XSDElementDeclaration) command.getAddedComponent();
            }
            if (elementDec != null) {
                Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, elementDec.getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
                command.execute();
            }
        } else {
            Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, ((XSDElementDeclaration) component.getObject()).getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
            command.execute();
        }
        XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
    }
}
Also used : AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) Command(org.eclipse.gef.commands.Command) AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Adapter(org.eclipse.emf.common.notify.Adapter)

Example 2 with UpdateAttributeValueCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand in project webtools.sourceediting by eclipse.

the class XSDSchemaAdvancedSection method doWidgetSelected.

public void doWidgetSelected(SelectionEvent e) {
    if (xsdSchema != null) {
        if (e.widget == elementFormCombo && elementFormCombo != null) {
            String valueElementForm = elementFormCombo.getText();
            UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE, valueElementForm, Messages._UI_LABEL_ELEMENTFORMDEFAULT);
            command.setDeleteIfEmpty(true);
            getCommandStack().execute(command);
        }
        if (e.widget == attributeFormCombo && attributeFormCombo != null) {
            String valueAttributeForm = attributeFormCombo.getText();
            UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE, valueAttributeForm, Messages._UI_LABEL_ATTRIBUTEFORMDEFAULT);
            command.setDeleteIfEmpty(true);
            getCommandStack().execute(command);
        }
        if (e.widget == blockDefaultCombo && blockDefaultCombo != null) {
            String valueBlockDefault = blockDefaultCombo.getText();
            UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), XSDConstants.BLOCKDEFAULT_ATTRIBUTE, valueBlockDefault, Messages._UI_LABEL_BLOCKDEFAULT);
            command.setDeleteIfEmpty(true);
            getCommandStack().execute(command);
        }
        if (e.widget == finalDefaultCombo && finalDefaultCombo != null) {
            String finalBlockDefault = finalDefaultCombo.getText();
            UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), XSDConstants.FINALDEFAULT_ATTRIBUTE, finalBlockDefault, Messages._UI_LABEL_FINALDEFAULT);
            command.setDeleteIfEmpty(true);
            getCommandStack().execute(command);
        }
    }
}
Also used : UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand)

Example 3 with UpdateAttributeValueCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand 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);
    }
}
Also used : UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration)

Example 4 with UpdateAttributeValueCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand 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);
    }
}
Also used : IComponentDialog(org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart)

Example 5 with UpdateAttributeValueCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand in project webtools.sourceediting by eclipse.

the class XSDAttributeDeclarationSection method doHandleEvent.

protected void doHandleEvent(Event event) {
    if (event.type == SWT.Traverse) {
        if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
            isTraversing = true;
            return;
        }
    }
    super.doHandleEvent(event);
    if (event.widget == nameText) {
        if (!nameText.getEditable())
            return;
        String newValue = nameText.getText().trim();
        if (input instanceof XSDAttributeDeclaration) {
            XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
            if (!validateSection())
                return;
            Command command = null;
            // Make sure an actual name change has taken place
            String oldName = namedComponent.getName();
            if (!newValue.equals(oldName)) {
                command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue);
            }
            if (command != null && getCommandStack() != null) {
                getCommandStack().execute(command);
            }
            if (isAttributeReference) {
                XSDAttributeDeclaration attrRef = (XSDAttributeDeclaration) input;
                String qname = attrRef.getResolvedAttributeDeclaration().getQName();
                attrRef.getElement().setAttribute(XSDConstants.REF_ATTRIBUTE, qname);
            // TypesHelper helper = new TypesHelper(xsdSchema);
            // List items = new ArrayList();
            // items = helper.getGlobalElements();
            // items.add(0, "");
            // componentNameCombo.setItems((String [])items.toArray(new String[0]));
            // 
            // refreshRefCombo();
            }
        }
    } else if (event.widget == defaultOrFixedText) {
        XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
        String newValue = defaultOrFixedText.getText();
        Element element = xsdAttribute.getElement();
        if (element != null) {
            if (newValue.length() == 0) {
                PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_VALUE) {

                    protected void doExecuteSteps() {
                        element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE);
                        element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                    }
                };
                getCommandStack().execute(command);
            } else {
                UpdateAttributeValueCommand command = null;
                if (fixedButton.getSelection()) {
                    command = new UpdateAttributeValueCommand(element, XSDConstants.FIXED_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FIXED) {

                        protected void doPostProcessing() {
                            element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                        }
                    };
                } else {
                    command = new UpdateAttributeValueCommand(element, XSDConstants.DEFAULT_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_DEFAULT) {

                        protected void doPostProcessing() {
                            element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE);
                        }
                    };
                }
                command.setDeleteIfEmpty(true);
                getCommandStack().execute(command);
            }
        }
    }
}
Also used : UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) BaseCommand(org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) Command(org.eclipse.gef.commands.Command) Element(org.w3c.dom.Element) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Aggregations

UpdateAttributeValueCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand)7 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)3 Command (org.eclipse.gef.commands.Command)2 Adapter (org.eclipse.emf.common.notify.Adapter)1 IEditorPart (org.eclipse.ui.IEditorPart)1 ComponentSpecification (org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification)1 ComponentReferenceEditManager (org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager)1 IComponentDialog (org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog)1 AddXSDElementCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand)1 BaseCommand (org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand)1 UpdateNameCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand)1 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)1 Element (org.w3c.dom.Element)1