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();
}
}
}
}
}
}
}
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;
}
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);
}
}
}
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;
}
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;
}
Aggregations