use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class XSDAttributeGroupDefinitionSection method doWidgetSelected.
public void doWidgetSelected(SelectionEvent e) {
if (e.widget == refCombo) {
String newValue = refCombo.getText();
if (input instanceof XSDNamedComponent) {
XSDNamedComponent namedComponent = (XSDNamedComponent) input;
Element element = namedComponent.getElement();
if (namedComponent instanceof XSDAttributeGroupDefinition) {
element.setAttribute(XSDConstants.REF_ATTRIBUTE, newValue);
XSDDirectivesManager.removeUnusedXSDImports(namedComponent.getSchema());
}
}
}
super.doWidgetSelected(e);
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class XSDAttributeGroupDefinitionSection method refresh.
public void refresh() {
super.refresh();
if (isReadOnly) {
composite.setEnabled(false);
} else {
composite.setEnabled(true);
}
setListenerEnabled(false);
XSDNamedComponent namedComponent = (XSDNamedComponent) input;
if (isReference) {
Element element = namedComponent.getElement();
if (element != null) {
String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE);
if (attrValue == null) {
// $NON-NLS-1$
attrValue = "";
}
refCombo.setText(attrValue);
}
} else {
// refresh name
// $NON-NLS-1$
nameText.setText("");
String name = namedComponent.getName();
if (name != null) {
nameText.setText(name);
}
}
setListenerEnabled(true);
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class XSDComplexTypeSection method doHandleEvent.
public 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 XSDNamedComponent) {
XSDNamedComponent namedComponent = (XSDNamedComponent) input;
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);
}
// doReferentialIntegrityCheck(namedComponent, newValue);
}
}
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class XSDSectionLabelProvider method getText.
/**
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object object) {
if (object == null || object.equals(StructuredSelection.EMPTY)) {
return org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NO_ITEMS_SELECTED;
}
String result = null;
boolean isReference = false;
Object selected = null;
if (object instanceof StructuredSelection) {
selected = ((StructuredSelection) object).getFirstElement();
if (selected instanceof XSDConcreteComponent) {
if (selected instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) selected;
if (xsdElementDeclaration.isElementDeclarationReference()) {
isReference = true;
}
} else if (selected instanceof XSDAttributeDeclaration) {
if (((XSDAttributeDeclaration) selected).isAttributeDeclarationReference()) {
isReference = true;
}
} else if (selected instanceof XSDModelGroupDefinition) {
if (((XSDModelGroupDefinition) selected).isModelGroupDefinitionReference()) {
isReference = true;
}
}
StringBuffer sb = new StringBuffer();
Element element = ((XSDConcreteComponent) selected).getElement();
if (element != null) {
sb.append(((XSDConcreteComponent) selected).getElement().getLocalName());
if (isReference) {
// $NON-NLS-1$
sb.append(" ref");
// This string is not easily translatable to other languages.
// For now, make it english-only since we use the element tag as the title anyway
// sb.append(Messages.UI_PAGE_HEADING_REFERENCE);
}
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow != null) {
IWorkbenchPage page = workbenchWindow.getActivePage();
if (page != null) {
IEditorPart editorPart = page.getActiveEditor();
XSDSchema xsdSchema = ((XSDConcreteComponent) selected).getSchema();
IEditorInput editorInput = editorPart.getEditorInput();
boolean isReadOnly = false;
if (!(editorInput instanceof IFileEditorInput || editorInput instanceof FileStoreEditorInput)) {
isReadOnly = true;
}
if (editorPart != null && xsdSchema != editorPart.getAdapter(XSDSchema.class) || isReadOnly) {
// $NON-NLS-1$ //$NON-NLS-2$
sb.append(" (" + Messages.UI_LABEL_READ_ONLY + ")");
}
}
}
return sb.toString();
} else {
// an appropriate name
if ((XSDConcreteComponent) selected instanceof XSDNamedComponent) {
return ((XSDNamedComponent) selected).getName();
} else if ((XSDConcreteComponent) selected instanceof XSDSchema) {
return XSDConstants.SCHEMA_ELEMENT_TAG;
}
// $NON-NLS-1$ //$NON-NLS-2$
return "(" + Messages.UI_LABEL_READ_ONLY + ")";
}
}
if (object instanceof Element) {
return ((Element) object).getLocalName();
}
}
return result;
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class FindReferencesAction method getXSDNamedComponent.
protected XSDNamedComponent getXSDNamedComponent() {
if (editor != null) {
ISelectionProvider provider = (ISelectionProvider) editor.getAdapter(ISelectionProvider.class);
ISelectionMapper mapper = (ISelectionMapper) editor.getAdapter(ISelectionMapper.class);
if (provider != null) {
ISelection selection = provider.getSelection();
if (mapper != null) {
selection = mapper.mapSelection(selection);
}
if (selection != null && selection instanceof IStructuredSelection) {
IStructuredSelection s = (IStructuredSelection) selection;
Object o = s.getFirstElement();
if (o != null && o instanceof XSDNamedComponent) {
return (XSDNamedComponent) o;
}
}
}
}
// our expectation
return null;
}
Aggregations