use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class XSDBaseAction method calculateEnabled.
protected boolean calculateEnabled() {
if (getWorkbenchPart() instanceof IEditorPart) {
IEditorPart owningEditor = (IEditorPart) getWorkbenchPart();
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
XSDSchema xsdSchema = null;
if (selection instanceof XSDConcreteComponent) {
xsdSchema = ((XSDConcreteComponent) selection).getSchema();
}
if (xsdSchema != null && xsdSchema == owningEditor.getAdapter(XSDSchema.class)) {
return true;
}
}
return false;
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class AddXSDEnumerationFacetAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
int index = -1;
AddEnumerationsCommand command = null;
XSDSimpleTypeDefinition st = null;
if (selection instanceof XSDSimpleTypeDefinition) {
st = (XSDSimpleTypeDefinition) selection;
command = new AddEnumerationsCommand(getText(), st);
} else if (selection instanceof XSDEnumerationFacet) {
st = ((XSDEnumerationFacet) selection).getSimpleTypeDefinition();
index = st.getFacetContents().indexOf(selection);
doDirectEdit = true;
command = new AddEnumerationsCommand(getText(), st, getId(), index);
} else if (// Support for Complex Type's simple Content with enumerations
selection instanceof XSDComplexTypeDefinition) {
st = (XSDSimpleTypeDefinition) ((XSDComplexTypeDefinition) selection).getContent();
command = new AddEnumerationsCommand(getText(), st);
} else // null
{
return;
}
List enumList = st.getEnumerationFacets();
// $NON-NLS-1$
String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList);
command.setValue(newName);
getCommandStack().execute(command);
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class DeleteXSDConcreteComponentAction method run.
public void run() {
for (Iterator i = ((IStructuredSelection) getSelection()).iterator(); i.hasNext(); ) {
Object selection = i.next();
boolean doReselect = false;
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
if (selection instanceof XSDConcreteComponent) {
XSDConcreteComponent xsdComponent = (XSDConcreteComponent) selection;
XSDSchema model = xsdComponent.getSchema();
doReselect = xsdComponent.eContainer() instanceof XSDSchema;
DeleteCommand command = new DeleteCommand(getText(), xsdComponent);
getCommandStack().execute(command);
if (model != null && doReselect) {
Adapter adapter = XSDAdapterFactory.getInstance().adapt(model);
if (adapter != null)
provider.setSelection(new StructuredSelection(adapter));
}
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class SetBaseTypeAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
boolean complexType = selection instanceof XSDComplexTypeDefinition;
boolean simpleType = selection instanceof XSDSimpleTypeDefinition;
if (complexType || simpleType) {
if (getWorkbenchPart() instanceof IEditorPart) {
IEditorPart editor = (IEditorPart) getWorkbenchPart();
ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class);
ComponentSpecification newValue;
IComponentDialog dialog = null;
dialog = manager.getBrowseDialog();
if (dialog != null) {
if (simpleType) {
((XSDSearchListDialogDelegate) dialog).showComplexTypes(false);
}
if (dialog.createAndOpen() == Window.OK) {
newValue = dialog.getSelectedComponent();
manager.modifyComponentReference(selection, newValue);
}
}
}
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class SetTypeAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
Object target = ((XSDBaseAdapter) selection).getTarget();
if (target instanceof XSDConcreteComponent) {
command = new SetTypeCommand(Messages._UI_ACTION_SET_TYPE, getId(), (XSDConcreteComponent) target);
command.setAdapter((XSDBaseAdapter) selection);
getCommandStack().execute(command);
}
}
}
Aggregations