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