Search in sources :

Example 1 with XSDFeature

use of org.eclipse.xsd.XSDFeature in project webtools.sourceediting by eclipse.

the class XSDFacetSection method widgetSelected.

public void widgetSelected(SelectionEvent e) {
    if (e.widget == collapseWhitespaceButton) {
        CompoundCommand compoundCommand = new CompoundCommand();
        XSDSimpleTypeDefinition anonymousSimpleType = null;
        if (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
            if (input instanceof XSDFeature) {
                anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType((XSDFeature) input, xsdSimpleTypeDefinition);
                if (anonymousSimpleType == null) {
                    anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
                    anonymousSimpleType.setBaseTypeDefinition(xsdSimpleTypeDefinition);
                    ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CONSTRAIN_LENGTH, (XSDFeature) input);
                    changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
                    compoundCommand.add(changeToAnonymousCommand);
                }
                UpdateXSDWhiteSpaceFacetCommand whiteSpaceCommand = new UpdateXSDWhiteSpaceFacetCommand(Messages._UI_ACTION_COLLAPSE_WHITESPACE, anonymousSimpleType, collapseWhitespaceButton.getSelection());
                compoundCommand.add(whiteSpaceCommand);
                getCommandStack().execute(compoundCommand);
            }
            setInput(getPart(), getSelection());
        } else {
            UpdateXSDWhiteSpaceFacetCommand whiteSpaceCommand = new UpdateXSDWhiteSpaceFacetCommand(Messages._UI_ACTION_COLLAPSE_WHITESPACE, xsdSimpleTypeDefinition, collapseWhitespaceButton.getSelection());
            getCommandStack().execute(whiteSpaceCommand);
        }
    } else if (e.widget == minimumInclusiveCheckbox) {
        String minValue = minLengthText.getText().trim();
        if (minValue.length() == 0)
            minValue = null;
        UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
        updateCommand.setMin(minValue);
        if (minValue != null)
            getCommandStack().execute(updateCommand);
    } else if (e.widget == maximumInclusiveCheckbox) {
        String maxValue = maxLengthText.getText().trim();
        if (maxValue.length() == 0)
            maxValue = null;
        UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
        updateCommand.setMax(maxValue);
        if (maxValue != null)
            getCommandStack().execute(updateCommand);
    } else if (e.widget == useEnumerationsButton) {
        constraintsWidget.addButton.setEnabled(true);
        if (isListenerEnabled()) {
            constraintsWidget.setConstraintKind(SpecificConstraintsWidget.ENUMERATION);
            constraintKind = constraintsWidget.getConstraintKind();
        }
    } else if (e.widget == usePatternsButton) {
        constraintsWidget.addButton.setEnabled(false);
        if (isListenerEnabled()) {
            constraintsWidget.setConstraintKind(SpecificConstraintsWidget.PATTERN);
            constraintKind = constraintsWidget.getConstraintKind();
        }
    }
}
Also used : UpdateXSDWhiteSpaceFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateXSDWhiteSpaceFacetCommand) XSDFeature(org.eclipse.xsd.XSDFeature) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ChangeToLocalSimpleTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand) UpdateNumericBoundsFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNumericBoundsFacetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with XSDFeature

use of org.eclipse.xsd.XSDFeature in project webtools.sourceediting by eclipse.

the class XSDFacetSection method doHandleEvent.

protected void doHandleEvent(Event event) {
    super.doHandleEvent(event);
    Command command = null;
    boolean doUpdateMax = false, doUpdateMin = false;
    boolean doSetInput = false;
    String minValue = minLengthText.getText().trim();
    String maxValue = maxLengthText.getText().trim();
    XSDLengthFacet lengthFacet = xsdSimpleTypeDefinition.getLengthFacet();
    XSDMinLengthFacet minLengthFacet = xsdSimpleTypeDefinition.getMinLengthFacet();
    XSDMaxLengthFacet maxLengthFacet = xsdSimpleTypeDefinition.getMaxLengthFacet();
    XSDMinInclusiveFacet minInclusiveFacet = xsdSimpleTypeDefinition.getMinInclusiveFacet();
    XSDMinExclusiveFacet minExclusiveFacet = xsdSimpleTypeDefinition.getMinExclusiveFacet();
    XSDMaxInclusiveFacet maxInclusiveFacet = xsdSimpleTypeDefinition.getMaxInclusiveFacet();
    XSDMaxExclusiveFacet maxExclusiveFacet = xsdSimpleTypeDefinition.getMaxExclusiveFacet();
    String currentMinInclusive = null, currentMinExclusive = null, currentMaxInclusive = null, currentMaxExclusive = null;
    if (minInclusiveFacet != null) {
        currentMinInclusive = minInclusiveFacet.getLexicalValue();
    }
    if (minExclusiveFacet != null) {
        currentMinExclusive = minExclusiveFacet.getLexicalValue();
    }
    if (maxInclusiveFacet != null) {
        currentMaxInclusive = maxInclusiveFacet.getLexicalValue();
    }
    if (maxExclusiveFacet != null) {
        currentMaxExclusive = maxExclusiveFacet.getLexicalValue();
    }
    String currentLength = null, currentMin = null, currentMax = null;
    if (lengthFacet != null) {
        currentLength = lengthFacet.getLexicalValue();
    }
    if (minLengthFacet != null) {
        currentMin = minLengthFacet.getLexicalValue();
    }
    if (maxLengthFacet != null) {
        currentMax = maxLengthFacet.getLexicalValue();
    }
    if (event.widget == minLengthText) {
        try {
            if (minValue.length() > 0) {
                if (!isNumericBaseType) {
                    Number big = new BigInteger(minValue);
                    big.toString();
                    if (minLengthFacet != null) {
                        if (minValue.equals(currentMin) || minValue.equals(currentLength))
                            return;
                    } else {
                        if (maxValue != null && minValue.equals(maxValue) && lengthFacet != null) {
                            return;
                        }
                    }
                } else {
                    if (// $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) {
                        BigDecimal bigDecimal = new BigDecimal(minValue);
                        bigDecimal.toString();
                        if ((currentMinInclusive != null && minValue.equals(currentMinInclusive)) || (currentMinExclusive != null && minValue.equals(currentMinExclusive))) {
                            return;
                        }
                    } else {
                        Number big = new BigInteger(minValue);
                        big.toString();
                    }
                    minimumInclusiveCheckbox.setEnabled(true);
                }
            } else {
                if (!isNumericBaseType) {
                    if (currentMin == null && currentLength == null)
                        return;
                } else {
                    if (currentMinInclusive == null && minimumInclusiveCheckbox.getSelection()) {
                        return;
                    } else if (currentMinExclusive == null && !minimumInclusiveCheckbox.getSelection()) {
                        return;
                    }
                }
                minimumInclusiveCheckbox.setEnabled(false);
                minValue = null;
            }
            doUpdateMin = true;
        } catch (NumberFormatException e) {
            // TODO show error message
            doUpdateMin = false;
        }
    }
    if (event.widget == maxLengthText) {
        try {
            if (maxValue.length() > 0) {
                if (!isNumericBaseType) {
                    Number big = new BigInteger(maxValue);
                    big.toString();
                    if (maxLengthFacet != null) {
                        if (maxValue.equals(currentMax) || maxValue.equals(currentLength))
                            return;
                    } else {
                        if (minValue != null && maxValue.equals(minValue) && lengthFacet != null) {
                            return;
                        }
                    }
                } else {
                    if (// $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || // $NON-NLS-1$
                    xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) {
                        BigDecimal bigDecimal = new BigDecimal(maxValue);
                        bigDecimal.toString();
                    } else {
                        Number big = new BigInteger(maxValue);
                        big.toString();
                    }
                    maximumInclusiveCheckbox.setEnabled(true);
                }
            } else {
                if (!isNumericBaseType) {
                    if (currentMax == null && currentLength == null)
                        return;
                } else {
                    if (currentMaxInclusive == null && maximumInclusiveCheckbox.getSelection()) {
                        return;
                    } else if (currentMaxExclusive == null && !maximumInclusiveCheckbox.getSelection()) {
                        return;
                    }
                    maximumInclusiveCheckbox.setEnabled(false);
                }
                maxValue = null;
            }
            doUpdateMax = true;
        } catch (NumberFormatException e) {
            doUpdateMax = false;
        // TODO show error message
        }
    }
    if (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace()) && (doUpdateMax || doUpdateMin)) {
        XSDSimpleTypeDefinition anonymousSimpleType = null;
        CompoundCommand compoundCommand = new CompoundCommand();
        ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = null;
        if (input instanceof XSDFeature) {
            anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType((XSDFeature) input, xsdSimpleTypeDefinition);
            if (anonymousSimpleType == null) {
                anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
                anonymousSimpleType.setBaseTypeDefinition(xsdSimpleTypeDefinition);
                changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CONSTRAIN_LENGTH, (XSDFeature) input);
                changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType);
                compoundCommand.add(changeToAnonymousCommand);
                doSetInput = true;
            }
            if (!isNumericBaseType) {
                // $NON-NLS-1$
                UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", anonymousSimpleType);
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                compoundCommand.add(updateCommand);
            } else {
                UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, anonymousSimpleType, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                compoundCommand.add(updateCommand);
            }
            command = compoundCommand;
            getCommandStack().execute(command);
        } else if (input instanceof XSDSimpleTypeDefinition) {
            if (!isNumericBaseType) {
                // $NON-NLS-1$
                UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition);
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                command = updateCommand;
            } else {
                UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
                if (doUpdateMax) {
                    updateCommand.setMax(maxValue);
                }
                if (doUpdateMin) {
                    updateCommand.setMin(minValue);
                }
                command = updateCommand;
            }
            getCommandStack().execute(command);
        }
    } else {
        if (!isNumericBaseType) {
            // $NON-NLS-1$
            UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition);
            if (doUpdateMax) {
                updateCommand.setMax(maxValue);
            }
            if (doUpdateMin) {
                updateCommand.setMin(minValue);
            }
            getCommandStack().execute(updateCommand);
        } else {
            UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection());
            if (doUpdateMax) {
                updateCommand.setMax(maxValue);
            }
            if (doUpdateMin) {
                updateCommand.setMin(minValue);
            }
            getCommandStack().execute(updateCommand);
        }
    }
    refresh();
    if (doSetInput)
        setInput(getPart(), getSelection());
}
Also used : UpdateStringLengthFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateStringLengthFacetCommand) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) UpdateNumericBoundsFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNumericBoundsFacetCommand) BigDecimal(java.math.BigDecimal) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDFeature(org.eclipse.xsd.XSDFeature) UpdateStringLengthFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateStringLengthFacetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeToLocalSimpleTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand) UpdateNumericBoundsFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNumericBoundsFacetCommand) UpdateXSDWhiteSpaceFacetCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateXSDWhiteSpaceFacetCommand) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) ChangeToLocalSimpleTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand) BigInteger(java.math.BigInteger) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet)

Example 3 with XSDFeature

use of org.eclipse.xsd.XSDFeature in project webtools.sourceediting by eclipse.

the class XSDFacetSection method createContents.

protected void createContents(Composite parent) {
    TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
    composite = factory.createFlatFormComposite(parent);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginTop = 0;
    gridLayout.marginBottom = 0;
    gridLayout.numColumns = 1;
    composite.setLayout(gridLayout);
    // $NON-NLS-1$
    title = factory.createCLabel(composite, "");
    FontData fontData = composite.getFont().getFontData()[0];
    title.setFont(JFaceResources.getFontRegistry().getBold(fontData.getName()));
    // $NON-NLS-1$ //$NON-NLS-2$
    title.setText(titleString + (isReadOnly ? " - " + Messages._UI_LABEL_READONLY : ""));
    Composite facetComposite = factory.createComposite(composite, SWT.FLAT);
    GridData data = new GridData();
    gridLayout = new GridLayout();
    gridLayout.marginTop = 0;
    gridLayout.marginBottom = 0;
    gridLayout.numColumns = 2;
    facetComposite.setLayout(gridLayout);
    data.grabExcessVerticalSpace = true;
    data.grabExcessHorizontalSpace = true;
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    facetComposite.setLayoutData(data);
    data = new GridData();
    data.grabExcessVerticalSpace = true;
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    simpleTypeModifierGroup = getWidgetFactory().createGroup(facetComposite, simpleTypeModifierGroupTitle);
    GridLayout groupGrid = new GridLayout();
    groupGrid.marginTop = 0;
    groupGrid.marginBottom = 0;
    groupGrid.numColumns = 1;
    simpleTypeModifierGroup.setLayoutData(data);
    simpleTypeModifierGroup.setLayout(groupGrid);
    Composite simpleTypeModifierComposite = getWidgetFactory().createFlatFormComposite(simpleTypeModifierGroup);
    data = new GridData();
    data.grabExcessVerticalSpace = true;
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    GridLayout grid = new GridLayout();
    grid.marginTop = 0;
    grid.marginBottom = 0;
    grid.numColumns = 3;
    simpleTypeModifierComposite.setLayout(grid);
    simpleTypeModifierComposite.setLayoutData(data);
    if (hasMaxMinFacets) {
        boolean isLinux = java.io.File.separator.equals("/");
        minLengthLabel = factory.createLabel(simpleTypeModifierComposite, minLengthString);
        // $NON-NLS-1$
        minLengthText = factory.createText(simpleTypeModifierComposite, "");
        if (isLinux) {
            minLengthText.addListener(SWT.Modify, customListener);
            minLengthText.addListener(SWT.KeyDown, customListener);
            minLengthText.addListener(SWT.FocusOut, customListener);
        } else
            applyAllListeners(minLengthText);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(minLengthText, XSDEditorCSHelpIds.CONSTRAINTS_TAB__MINIMUM_LENGTH);
        GridData minGridData = new GridData();
        minGridData.widthHint = 100;
        minLengthText.setLayoutData(minGridData);
        minimumInclusiveCheckbox = factory.createButton(simpleTypeModifierComposite, Messages._UI_LABEL_INCLUSIVE, SWT.CHECK);
        minimumInclusiveCheckbox.addSelectionListener(this);
        maxLengthLabel = factory.createLabel(simpleTypeModifierComposite, maxLengthString);
        // $NON-NLS-1$
        maxLengthText = factory.createText(simpleTypeModifierComposite, "");
        if (isLinux) {
            maxLengthText.addListener(SWT.Modify, customListener);
            maxLengthText.addListener(SWT.KeyDown, customListener);
            maxLengthText.addListener(SWT.FocusOut, customListener);
        } else
            applyAllListeners(maxLengthText);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(maxLengthText, XSDEditorCSHelpIds.CONSTRAINTS_TAB__MAXIMUM_LENGTH);
        GridData maxGridData = new GridData();
        maxGridData.widthHint = 100;
        maxLengthText.setLayoutData(maxGridData);
        maximumInclusiveCheckbox = factory.createButton(simpleTypeModifierComposite, Messages._UI_LABEL_INCLUSIVE, SWT.CHECK);
        maximumInclusiveCheckbox.addSelectionListener(this);
        minimumInclusiveCheckbox.setVisible(isNumericBaseType);
        maximumInclusiveCheckbox.setVisible(isNumericBaseType);
    }
    collapseWhitespaceButton = factory.createButton(simpleTypeModifierComposite, Messages._UI_LABEL_COLLAPSE_WHITESPACE, SWT.CHECK);
    collapseWhitespaceButton.addSelectionListener(this);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(collapseWhitespaceButton, XSDEditorCSHelpIds.CONSTRAINTS_TAB__COLLAPSE_WHITESPACE);
    Group specificValueConstraintsGroup = factory.createGroup(facetComposite, Messages._UI_LABEL_SPECIFIC_CONSTRAINT_VALUES);
    gridLayout = new GridLayout();
    gridLayout.marginTop = 0;
    gridLayout.marginBottom = 0;
    gridLayout.numColumns = 2;
    specificValueConstraintsGroup.setLayout(gridLayout);
    data = new GridData();
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    specificValueConstraintsGroup.setLayoutData(data);
    Composite compositeForButtons = factory.createFlatFormComposite(specificValueConstraintsGroup);
    gridLayout = new GridLayout();
    gridLayout.marginTop = 0;
    gridLayout.verticalSpacing = 1;
    gridLayout.marginBottom = 0;
    gridLayout.numColumns = 1;
    compositeForButtons.setLayout(gridLayout);
    data = new GridData();
    data.verticalAlignment = GridData.BEGINNING;
    compositeForButtons.setLayoutData(data);
    factory.createCLabel(compositeForButtons, Messages._UI_LABEL_RESTRICT_VALUES_BY);
    // useDefinedValuesButton = factory.createButton(compositeForButtons, "Only permit certain values", SWT.CHECK);
    // useDefinedValuesButton.addSelectionListener(this);
    Composite compositeForRadioButtons = factory.createFlatFormComposite(compositeForButtons);
    gridLayout = new GridLayout();
    gridLayout.marginTop = 0;
    gridLayout.marginLeft = 0;
    gridLayout.marginBottom = 0;
    gridLayout.numColumns = 1;
    compositeForRadioButtons.setLayout(gridLayout);
    useEnumerationsButton = factory.createButton(compositeForRadioButtons, Messages._UI_LABEL_ENUMERATIONS, SWT.RADIO);
    useEnumerationsButton.addSelectionListener(this);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(useEnumerationsButton, XSDEditorCSHelpIds.CONSTRAINTS_TAB__ENUMERATIONS);
    usePatternsButton = factory.createButton(compositeForRadioButtons, Messages._UI_LABEL_PATTERNS, SWT.RADIO);
    usePatternsButton.addSelectionListener(this);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(usePatternsButton, XSDEditorCSHelpIds.CONSTRAINTS_TAB__PATTERNS);
    constraintsWidget = new SpecificConstraintsWidget(specificValueConstraintsGroup, factory, (input instanceof XSDFeature) ? (XSDFeature) input : null, xsdSimpleTypeDefinition, this, constraintKind);
    data = new GridData();
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    constraintsWidget.getControl().setLayoutData(data);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(constraintsWidget.getControl(), XSDEditorCSHelpIds.CONSTRAINTS_TAB__NO_LABEL);
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) XSDFeature(org.eclipse.xsd.XSDFeature) FontData(org.eclipse.swt.graphics.FontData) GridData(org.eclipse.swt.layout.GridData) TabbedPropertySheetWidgetFactory(org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory)

Example 4 with XSDFeature

use of org.eclipse.xsd.XSDFeature in project webtools.sourceediting by eclipse.

the class XSDFacetSection method updateInput.

private void updateInput() {
    previousPrimitiveType = currentPrimitiveType;
    if (input instanceof XSDFeature) {
        xsdFeature = (XSDFeature) input;
        typeDefinition = xsdFeature.getResolvedFeature().getType();
        XSDTypeDefinition anonymousTypeDefinition = null;
        if (xsdFeature instanceof XSDElementDeclaration) {
            xsdElementDeclaration = (XSDElementDeclaration) xsdFeature;
            anonymousTypeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getAnonymousTypeDefinition();
        } else if (xsdFeature instanceof XSDAttributeDeclaration) {
            xsdAttributeDeclaration = (XSDAttributeDeclaration) xsdFeature;
            anonymousTypeDefinition = xsdAttributeDeclaration.getResolvedAttributeDeclaration().getAnonymousTypeDefinition();
        }
        if (typeDefinition instanceof XSDSimpleTypeDefinition) {
            xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) typeDefinition;
        }
        if (anonymousTypeDefinition instanceof XSDSimpleTypeDefinition) {
            xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) anonymousTypeDefinition;
        }
        if (xsdSimpleTypeDefinition != null) {
            if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
                XSDSimpleTypeDefinition basePrimitiveType = xsdSimpleTypeDefinition.getBaseTypeDefinition();
                String basePrimitiveTypeString = basePrimitiveType != null ? basePrimitiveType.getName() : "";
                currentPrimitiveType = basePrimitiveType;
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString;
            } else {
                currentPrimitiveType = xsdSimpleTypeDefinition;
                titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName());
            }
        }
    } else if (input instanceof XSDSimpleTypeDefinition) {
        xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) input;
        currentPrimitiveType = xsdSimpleTypeDefinition;
        // $NON-NLS-1$ //$NON-NLS-2$
        titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName();
    }
}
Also used : XSDFeature(org.eclipse.xsd.XSDFeature) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 5 with XSDFeature

use of org.eclipse.xsd.XSDFeature in project webtools.sourceediting by eclipse.

the class OpenInNewEditor method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = null;
    IEditorInput editorInput = null;
    if (workbenchWindow != null) {
        page = workbenchWindow.getActivePage();
        IEditorPart activeEditor = page.getActiveEditor();
        if (activeEditor != null) {
            editorInput = activeEditor.getEditorInput();
        }
    }
    if (selection instanceof XSDBaseAdapter) {
        XSDBaseAdapter xsdAdapter = (XSDBaseAdapter) selection;
        XSDConcreteComponent fComponent = (XSDConcreteComponent) xsdAdapter.getTarget();
        XSDSchema schema = fComponent.getSchema();
        boolean isReference = false;
        if (fComponent instanceof XSDFeature) {
            isReference = ((XSDFeature) fComponent).isFeatureReference();
            fComponent = ((XSDFeature) fComponent).getResolvedFeature();
        }
        String schemaLocation = null;
        IPath schemaPath = null;
        IFile schemaFile = null;
        // Special case any imports/includes
        if (selection instanceof XSDSchemaDirectiveAdapter) {
            XSDSchemaDirective dir = (XSDSchemaDirective) ((XSDSchemaDirectiveAdapter) selection).getTarget();
            // force load of imported schema
            if (dir instanceof XSDImportImpl) {
                ((XSDImportImpl) dir).importSchema();
            }
            if (dir.getResolvedSchema() != null) {
                schemaLocation = URIHelper.removePlatformResourceProtocol(dir.getResolvedSchema().getSchemaLocation());
                schemaPath = new Path(schemaLocation);
                schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
                schema = dir.getResolvedSchema();
                fComponent = dir.getResolvedSchema();
            }
        } else // Handle any other external components
        if (fComponent.getSchema() != null && fComponent.eContainer() instanceof XSDSchema || fComponent.eContainer() instanceof XSDRedefine || isReference) {
            schemaLocation = URIHelper.removePlatformResourceProtocol(fComponent.getSchema().getSchemaLocation());
            schemaPath = new Path(schemaLocation);
            schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
            try {
                XSDSchema xsdSchema = (XSDSchema) getWorkbenchPart().getAdapter(XSDSchema.class);
                if (fComponent.getSchema() == xsdSchema) {
                    IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
                    if (editorPart instanceof InternalXSDMultiPageEditor) {
                        ((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(fComponent);
                    }
                    return;
                }
            } catch (Exception e) {
            }
        }
        // If the schemaFile exists in the workspace
        if (page != null && schemaFile != null && schemaFile.exists()) {
            try {
                // Get the current editor's schema
                XSDSchema xsdSchema = (XSDSchema) getWorkbenchPart().getAdapter(XSDSchema.class);
                IEditorPart editorPart = null;
                // are in the same resource file....hence multiple schemas in the same file.
                if (xsdSchema != null && fComponent.getRootContainer().eResource() == xsdSchema.eResource() && xsdSchema != schema) {
                    String editorName = null;
                    XSDFileEditorInput xsdFileEditorInput = new XSDFileEditorInput(schemaFile, fComponent.getSchema());
                    // Try to use the same editor name as the current one
                    if (editorInput != null) {
                        editorName = editorInput.getName();
                        xsdFileEditorInput.setEditorName(editorName);
                    }
                    editorPart = getExistingEditorForInlineSchema(page, schemaFile, schema);
                    if (editorPart == null) {
                        editorPart = page.openEditor(xsdFileEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
                    }
                } else {
                    editorPart = page.openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.EDITOR_ID);
                }
                if (editorPart instanceof InternalXSDMultiPageEditor) {
                    ((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(fComponent);
                }
            } catch (Exception e) {
            }
        } else {
            // open the xsd externally
            if (schemaLocation != null)
                openExternalFiles(page, schemaLocation, fComponent);
        }
    }
}
Also used : XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) IPath(org.eclipse.core.runtime.IPath) InternalXSDMultiPageEditor(org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDImportImpl(org.eclipse.xsd.impl.XSDImportImpl) XSDFeature(org.eclipse.xsd.XSDFeature) XSDFileEditorInput(org.eclipse.wst.xsd.ui.internal.editor.XSDFileEditorInput) XSDFileEditorInput(org.eclipse.wst.xsd.ui.internal.editor.XSDFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ADTReadOnlyFileEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IEditorInput(org.eclipse.ui.IEditorInput) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDFeature (org.eclipse.xsd.XSDFeature)6 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 ChangeToLocalSimpleTypeCommand (org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand)2 UpdateNumericBoundsFacetCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNumericBoundsFacetCommand)2 UpdateXSDWhiteSpaceFacetCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateXSDWhiteSpaceFacetCommand)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 EList (org.eclipse.emf.common.util.EList)1 Command (org.eclipse.gef.commands.Command)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 FontData (org.eclipse.swt.graphics.FontData)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1