use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class CreateElementAction method run.
/*
* @see IAction#run()
*/
public void run() {
beginRecording(getDescription());
final Element child = createAndAddNewChildElement();
endRecording();
if (selectionProvider != null) {
final XSDConcreteComponent comp = xsdSchema.getCorrespondingComponent(child);
// selectionProvider.setSelection(new StructuredSelection(comp));
Runnable runnable = new Runnable() {
public void run() {
if (comp instanceof XSDAttributeDeclaration) {
if (((XSDAttributeDeclaration) comp).getContainer() instanceof XSDAttributeUse) {
if (comp.getContainer().getContainer() instanceof XSDAttributeGroupDefinition) {
selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
} else if (comp.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
if (XSDDOMHelper.inputEquals(child, XSDConstants.ATTRIBUTE_ELEMENT_TAG, true)) {
selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
if (comp instanceof XSDNamedComponent) {
if (sourceContext instanceof AbstractEditPartViewer) {
// AbstractEditPartViewer viewer = (AbstractEditPartViewer)sourceContext;
// Object obj = viewer.getSelectedEditParts().get(0);
// if (obj instanceof GraphicalEditPart)
// {
// if (obj instanceof ElementDeclarationEditPart)
// {
// XSDElementDeclaration elem = ((ElementDeclarationEditPart)obj).getXSDElementDeclaration();
// if (!elem.isElementDeclarationReference())
// {
// ((ElementDeclarationEditPart)obj).doEditName();
// }
// }
// else if (obj instanceof ModelGroupDefinitionEditPart)
// {
// XSDModelGroupDefinition group = ((ModelGroupDefinitionEditPart)obj).getXSDModelGroupDefinition();
// if (!group.isModelGroupDefinitionReference())
// {
// ((ModelGroupDefinitionEditPart)obj).doEditName();
// }
// }
// else if (obj instanceof ComplexTypeDefinitionEditPart)
// {
// XSDComplexTypeDefinition ct = ((ComplexTypeDefinitionEditPart)obj).getXSDComplexTypeDefinition();
// if (ct.getName() != null)
// {
// ((ComplexTypeDefinitionEditPart)obj).doEditName();
// }
// }
// else if (obj instanceof TopLevelComponentEditPart)
// {
// ((TopLevelComponentEditPart)obj).doEditName();
// }
// }
}
}
}
};
Display.getDefault().timerExec(50, runnable);
}
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGlobalCommand method run.
public void run() {
XSDConcreteComponent model = getModelObject();
XSDConcreteComponent parent = model.getContainer();
XSDTypeDefinition globalTypeDef = null;
if (model instanceof XSDComplexTypeDefinition) {
if (parent instanceof XSDElementDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDComplexTypeDefinition) model.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
}
} else if (model instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) model;
if (parent instanceof XSDElementDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
formatChild(globalTypeDef.getElement());
} else if (parent instanceof XSDAttributeDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDAttributeDeclaration) parent).setTypeDefinition((XSDSimpleTypeDefinition) globalTypeDef);
}
}
formatChild(globalTypeDef.getElement());
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypsGlobalEnablementTester method canEnable.
protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) {
if (selectedObject == null) {
return false;
}
XSDSchema selectedComponentSchema = null;
boolean enable = false;
selectedComponentSchema = selectedObject.getSchema();
if (selectedComponentSchema != null && selectedComponentSchema == schema) {
enable = true;
}
if (enable && selectedObject instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) selectedObject;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
return true;
}
} else if (enable && selectedObject instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) selectedObject;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
return true;
} else if (parent instanceof XSDAttributeDeclaration) {
return true;
}
}
return false;
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGobalHandler method doExecute.
public Object doExecute(ISelection selection, XSDSchema schema) {
if (selection != null) {
Object selectedObject = ((StructuredSelection) selection).getFirstElement();
if (selectedObject instanceof XSDBaseAdapter) {
selectedObject = ((XSDBaseAdapter) selectedObject).getTarget();
}
XSDConcreteComponent concreteComp = null;
if (selectedObject instanceof Node) {
Node node = (Node) selectedObject;
concreteComp = schema.getCorrespondingComponent(node);
} else if (selectedObject instanceof XSDConcreteComponent) {
concreteComp = ((XSDConcreteComponent) selectedObject);
}
if (concreteComp != null) {
if (concreteComp instanceof XSDComplexTypeDefinition) {
isComplexType = true;
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) concreteComp;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
parentName = ((XSDElementDeclaration) parent).getName();
run(selection, schema, typeDef);
} else if (concreteComp instanceof XSDSimpleTypeDefinition) {
isComplexType = false;
XSDSimpleTypeDefinition simpleTypeDef = (XSDSimpleTypeDefinition) concreteComp;
XSDConcreteComponent parentComp = simpleTypeDef.getContainer();
if (parentComp instanceof XSDElementDeclaration) {
parentName = ((XSDElementDeclaration) parent).getName();
} else if (parent instanceof XSDAttributeDeclaration) {
parentName = ((XSDAttributeDeclaration) parent).getName();
}
run(selection, schema, simpleTypeDef);
}
}
}
}
return null;
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project tmdm-studio-se by Talend.
the class XSDTreeLabelProvider method getImage.
@Override
public Image getImage(Object obj) {
if (obj instanceof XSDElementDeclaration) {
// top declaration
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
// check if concept or "just" element
boolean isConcept = false;
EList l = decl.getIdentityConstraintDefinitions();
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
isConcept = true;
break;
}
}
// display approprite image
if (isConcept) {
return ImageCache.getCreatedImage(EImage.CONCEPT.getPath());
} else {
return ImageCache.getCreatedImage(EImage.ELEMENT_ONLY.getPath());
/*
* if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) return
* PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_FOLDER); else
* return ImageCache.getCreatedImage( "icons/elements_obj_+.gif");
*/
}
}
if (obj instanceof XSDParticle) {
XSDParticle xsdParticle = (XSDParticle) obj;
XSDTerm xsdTerm = xsdParticle.getTerm();
if (xsdTerm instanceof XSDElementDeclaration) {
// get Type of Parent Group
List<Object> realKeyInfos = Util.getRealKeyInfos(entity, xsdParticle);
if (realKeyInfos != null && realKeyInfos.size() > 0) {
return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
}
if (XSDUtil.hasFKInfo((XSDElementDeclaration) xsdTerm)) {
return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
}
XSDConcreteComponent xsdConcreteComponent = xsdParticle.getContainer();
if (xsdConcreteComponent instanceof XSDModelGroup) {
return ImageCache.getCreatedImage(EImage.SCHEMAELEMENT.getPath());
}
/*
* if(((XSDElementDeclaration) xsdTerm).getAnonymousTypeDefinition() instanceof
* XSDComplexTypeDefinition) return ImageCache.getCreatedImage( EImage.COMPLEXTYPE.getPath()); else
* return ImageCache.getCreatedImage( EImage.SIMPLETYPE.getPath());
*/
} else if (xsdTerm instanceof XSDModelGroup) {
int type = ((XSDModelGroup) xsdTerm).getCompositor().getValue();
switch(type) {
case XSDCompositor.ALL:
return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
case XSDCompositor.CHOICE:
return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
case XSDCompositor.SEQUENCE:
return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
}
} else if (xsdTerm instanceof XSDWildcard) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/wildcard.gif");
} else {
log.info(Messages.bind(Messages.XSDTreeLabelProvider_27, xsdTerm.getClass().getName()));
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/error.gif");
}
}
if (obj instanceof XSDSimpleTypeDefinition) {
return ImageCache.getCreatedImage(EImage.SIMPLETYPE.getPath());
}
if (obj instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) obj;
XSDComplexTypeContent ctc = ctd.getContent();
if (ctc instanceof XSDParticle) {
if (((XSDParticle) ctc).getTerm() instanceof XSDModelGroup) {
int type = ((XSDModelGroup) ((XSDParticle) ctc).getTerm()).getCompositor().getValue();
switch(type) {
case XSDCompositor.ALL:
return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
case XSDCompositor.CHOICE:
return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
case XSDCompositor.SEQUENCE:
return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
}
}
} else {
// simple Type!!!
log.info(Messages.bind(Messages.XSDTreeLabelProvider_28, ctc.getClass().getName()));
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/error.gif");
}
}
if (obj instanceof XSDModelGroup) {
int type = ((XSDModelGroup) obj).getCompositor().getValue();
switch(type) {
case XSDCompositor.ALL:
return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
case XSDCompositor.CHOICE:
return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
case XSDCompositor.SEQUENCE:
return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
}
}
if (obj instanceof XSDFacet) {
return ImageCache.getCreatedImage(EImage.FACET.getPath());
}
if (obj instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition identity = (XSDIdentityConstraintDefinition) obj;
if (identity.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
return ImageCache.getCreatedImage(EImage.KEYS.getPath());
}
return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
}
if (obj instanceof XSDXPathDefinition) {
XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/field.gif");
}
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/selector.gif");
}
if (obj instanceof XSDAttributeGroupDefinition) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/attribute_group.gif");
}
if (obj instanceof XSDAttributeUse) {
XSDAttributeUse att = (XSDAttributeUse) obj;
if ("xmlns".equals(att.getAttributeDeclaration().getTargetNamespace())) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
}
if (att.getUse().equals(XSDAttributeUseCategory.REQUIRED_LITERAL)) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/attribute_mandatory.gif");
} else {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/attribute.gif");
}
}
if (obj instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration attributeDec = (XSDAttributeDeclaration) obj;
if (// $NON-NLS-1$
"xmlns".equals(attributeDec.getTargetNamespace())) {
return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
} else {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/attribute.gif");
}
}
if (obj instanceof XSDAnnotation) {
return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
}
if (obj instanceof Element) {
try {
Element e = (Element) obj;
if (e.getLocalName().equals("documentation")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
} else if (e.getLocalName().equals("appinfo")) {
// $NON-NLS-1$
// $NON-NLS-1$
String source = e.getAttribute("source");
if (source != null) {
if (source.startsWith("X_Label_")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.LABEL.getPath());
} else if (source.equals("X_ForeignKey")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
} else if (source.equals("X_Visible_Rule")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.ROUTINE.getPath());
} else if (source.equals("X_Default_Value_Rule")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.ROUTINE.getPath());
} else if (source.equals("X_ForeignKeyInfo")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
} else if (source.equals("X_ForeignKeyInfoFormat")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
// fix bug 0013194 by rhou.
} else if (source.equals("X_FKIntegrity")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
} else if (source.equals("X_FKIntegrity_Override")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
} else if (source.equals("X_Retrieve_FKinfos")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
} else if (source.equals("X_SourceSystem")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SOURCESYSTEM.getPath());
} else if (source.equals("X_TargetSystem")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.TARGETSYSTEM.getPath());
} else if (source.startsWith("X_Description_")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
} else if (source.equals("X_Write")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Deny_Create")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Deny_LogicalDelete")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Deny_PhysicalDelete")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Lookup_Field")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.BROWSE.getPath());
} else if (source.equals("X_Hide")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Schematron")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.ROUTINE.getPath());
} else if (source.equals("X_Workflow")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.WORKFLOW_PROCESS.getPath());
} else if (source.equals("X_AutoExpand")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.DEFAULT.getPath());
}
if (source.equals("X_ForeignKey_Filter")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.FILTER_PS.getPath());
} else if (source.startsWith("X_Display_Format_")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.THIN_MIN_VIEW.getPath());
} else {
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
}
} else {
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
}
} else {
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/small_warn.gif");
// return PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_ELEMENT);
}
Aggregations