Search in sources :

Example 31 with XSDSimpleTypeDefinition

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

the class XSDSimpleTypeEditPart method performRequest.

public void performRequest(Request request) {
    if (request.getType() == RequestConstants.REQ_OPEN) {
        Object model = getModel();
        if (request instanceof LocationRequest) {
            LocationRequest locationRequest = (LocationRequest) request;
            Point p = locationRequest.getLocation();
            if (getStructureFigure().hitTestHeader(p)) {
                // 
                if (model instanceof XSDSimpleTypeDefinitionAdapter) {
                    XSDSimpleTypeDefinitionAdapter adapter = (XSDSimpleTypeDefinitionAdapter) model;
                    XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) adapter.getTarget();
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
                    Object schema = editorPart.getAdapter(XSDSchema.class);
                    ActionRegistry registry = getEditorActionRegistry(editorPart);
                    if (registry != null) {
                        if (schema == st.getSchema()) {
                            IAction action = registry.getAction(SetInputToGraphView.ID);
                            action.run();
                        } else {
                            IAction action = registry.getAction(OpenInNewEditor.ID);
                            action.run();
                        }
                    }
                }
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) LocationRequest(org.eclipse.gef.requests.LocationRequest) IAction(org.eclipse.jface.action.IAction) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Point(org.eclipse.draw2d.geometry.Point) IEditorPart(org.eclipse.ui.IEditorPart) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry)

Example 32 with XSDSimpleTypeDefinition

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

the class XSDSchemaAdapter method getSimpleTypes.

public List getSimpleTypes(XSDSchema schema, boolean showFromIncludes) {
    List allTypes = schema.getTypeDefinitions();
    List list = new ArrayList();
    for (Iterator i = allTypes.iterator(); i.hasNext(); ) {
        XSDTypeDefinition td = (XSDTypeDefinition) i.next();
        if (td instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) td;
            if (shouldShowComponent(st, schema, showFromIncludes)) {
                list.add(st);
            }
        }
    }
    List adapterList = new ArrayList();
    populateAdapterList(list, adapterList);
    return adapterList;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 33 with XSDSimpleTypeDefinition

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

the class EnumerationsSection method widgetSelected.

public void widgetSelected(SelectionEvent e) {
    XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input;
    if (e.widget == addButton) {
        List enumList = st.getEnumerationFacets();
        // $NON-NLS-1$
        String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList);
        AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, (XSDSimpleTypeDefinition) input);
        command.setValue(newName);
        getCommandStack().execute(command);
        enumerationsTable.refresh();
        int newItemIndex = enumerationsTable.getTable().getItemCount() - 1;
        enumerationsTable.editElement(enumerationsTable.getElementAt(newItemIndex), 0);
    } else if (e.widget == addManyButton) {
        Display display = Display.getCurrent();
        // if it is null, get the default one
        display = display == null ? Display.getDefault() : display;
        Shell parentShell = display.getActiveShell();
        EnumerationsDialog dialog = new EnumerationsDialog(parentShell);
        dialog.setBlockOnOpen(true);
        int result = dialog.open();
        if (result == Window.OK) {
            String text = dialog.getText();
            String delimiter = dialog.getDelimiter();
            StringTokenizer tokenizer = new StringTokenizer(text, delimiter);
            CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_ADD_ENUMERATIONS);
            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();
                if (dialog.isPreserveWhitespace() == false) {
                    token = token.trim();
                }
                AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATIONS, (XSDSimpleTypeDefinition) input);
                command.setValue(token);
                compoundCommand.add(command);
            }
            getCommandStack().execute(compoundCommand);
        }
        enumerationsTable.refresh();
    } else if (e.widget == deleteButton) {
        StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection();
        if (selection != null) {
            Iterator i = selection.iterator();
            CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_DELETE_ENUMERATION);
            while (i.hasNext()) {
                Object obj = i.next();
                if (obj != null) {
                    if (obj instanceof XSDEnumerationFacet) {
                        XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) obj;
                        DeleteCommand deleteCommand = new DeleteCommand(Messages._UI_ACTION_DELETE_ENUMERATION, enumFacet);
                        compoundCommand.add(deleteCommand);
                    }
                }
            }
            getCommandStack().execute(compoundCommand);
            enumerationsTable.refresh();
        }
    } else if (e.widget == enumerationsTable.getTable()) {
        StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection();
        if (selection.getFirstElement() != null) {
            deleteButton.setEnabled(true);
        } else {
            deleteButton.setEnabled(false);
        }
    }
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) AddEnumerationsCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteCommand(org.eclipse.wst.xsd.ui.internal.common.commands.DeleteCommand) Shell(org.eclipse.swt.widgets.Shell) StringTokenizer(com.ibm.icu.util.StringTokenizer) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EnumerationsDialog(org.eclipse.wst.xsd.ui.internal.widgets.EnumerationsDialog) Display(org.eclipse.swt.widgets.Display)

Example 34 with XSDSimpleTypeDefinition

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

the class AddXSDElementCommand method createXSDElementDeclaration.

protected XSDParticle createXSDElementDeclaration() {
    // $NON-NLS-1$
    XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
    XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    XSDConcreteComponent comp = xsdModelGroup.getContainer();
    ArrayList usedAttributeNames = new ArrayList();
    XSDCommonUIUtils.resetVisitedGroupsStack();
    usedAttributeNames.addAll(XSDCommonUIUtils.getChildElements(xsdModelGroup));
    while (comp != null) {
        if (comp instanceof XSDModelGroupDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDModelGroupDefinition) comp));
            break;
        } else if (comp instanceof XSDComplexTypeDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDComplexTypeDefinition) comp));
            usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes((XSDComplexTypeDefinition) comp));
            break;
        }
        comp = comp.getContainer();
    }
    element.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewElement" : nameToAdd, // $NON-NLS-1$
    usedAttributeNames));
    element.setTypeDefinition(type);
    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
    particle.setContent(element);
    addedXSDConcreteComponent = element;
    return particle;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 35 with XSDSimpleTypeDefinition

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

the class AddXSDEnumerationFacetAction method calculateEnabled.

protected boolean calculateEnabled() {
    boolean parentResult = super.calculateEnabled();
    boolean endResult = true;
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDComplexTypeDefinitionAdapter) {
        XSDComplexTypeDefinition definition = ((XSDComplexTypeDefinitionAdapter) selection).getXSDComplexTypeDefinition();
        XSDTypeDefinition baseType = definition.getBaseType();
        if (baseType instanceof XSDSimpleTypeDefinition)
            endResult = false;
    }
    endResult = endResult & parentResult;
    return endResult;
}
Also used : XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)106 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)53 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)47 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)46 XSDParticle (org.eclipse.xsd.XSDParticle)34 ArrayList (java.util.ArrayList)33 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 Iterator (java.util.Iterator)24 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 XSDSchema (org.eclipse.xsd.XSDSchema)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)16 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)15 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)15 XSDFactory (org.eclipse.xsd.XSDFactory)15 EList (org.eclipse.emf.common.util.EList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)11