Search in sources :

Example 6 with UpdateNameCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand 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

Command (org.eclipse.gef.commands.Command)6 UpdateNameCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand)6 XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)4 BaseCommand (org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand)1 UpdateAttributeValueCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand)1 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 Element (org.w3c.dom.Element)1