use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method createUniqueElementName.
public static String createUniqueElementName(String prefix, List elements) {
ArrayList usedNames = new ArrayList();
for (Iterator i = elements.iterator(); i.hasNext(); ) {
usedNames.add(getDisplayName((XSDNamedComponent) i.next()));
}
int i = 1;
String testName = prefix;
while (usedNames.contains(testName)) {
testName = prefix + i++;
}
return testName;
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class TopLevelComponentEditPart method doEditName.
public void doEditName(boolean addFromDesign) {
if (!addFromDesign)
return;
// removeFeedback();
Object object = ((XSDBaseAdapter) getModel()).getTarget();
if (object instanceof XSDNamedComponent) {
Point p = label.getLocation();
TopLevelNameDirectEditManager manager = new TopLevelNameDirectEditManager(TopLevelComponentEditPart.this, new TopLevelComponentLabelCellEditorLocator(TopLevelComponentEditPart.this, p), (XSDNamedComponent) object);
NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
adtDirectEditPolicy.setUpdateCommand(wrapper);
manager.show();
}
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class OpenOnSelectionHelper method openOnGlobalReference.
public XSDNamedComponent openOnGlobalReference(XSDConcreteComponent comp) {
XSDSchema schema = xsdSchema;
String name = null;
String namespace = null;
if (comp instanceof XSDNamedComponent) {
name = ((XSDNamedComponent) comp).getName();
namespace = ((XSDNamedComponent) comp).getTargetNamespace();
}
if (name == null) {
// For Anonymous types, just show the element
if (comp instanceof XSDTypeDefinition) {
XSDTypeDefinition type = (XSDTypeDefinition) comp;
comp = type.getContainer();
if (comp instanceof XSDNamedComponent) {
name = ((XSDNamedComponent) comp).getName();
namespace = ((XSDNamedComponent) comp).getTargetNamespace();
}
}
}
if (schema == null || name == null) {
return null;
}
List objects = null;
if (comp instanceof XSDElementDeclaration) {
objects = schema.getElementDeclarations();
} else if (comp instanceof XSDTypeDefinition) {
objects = schema.getTypeDefinitions();
} else if (comp instanceof XSDAttributeGroupDefinition) {
objects = schema.getAttributeGroupDefinitions();
} else if (comp instanceof XSDIdentityConstraintDefinition) {
objects = schema.getIdentityConstraintDefinitions();
} else if (comp instanceof XSDModelGroupDefinition) {
objects = schema.getModelGroupDefinitions();
} else if (comp instanceof XSDAttributeDeclaration) {
objects = schema.getAttributeDeclarations();
}
if (objects != null) {
if (namespace != null) {
// First, look for a namespace and name match
for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
String targetNamespace = namedComp.getTargetNamespace();
if (namedComp.getName().equals(name) && targetNamespace != null && targetNamespace.equals(namespace)) {
revealObject(namedComp);
return namedComp;
}
}
}
// Next, look for just a name match
for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
if (namedComp.getName().equals(name)) {
revealObject(namedComp);
return namedComp;
}
}
}
return null;
}
use of org.eclipse.xsd.XSDNamedComponent 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.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class FindReferencesAction method run.
public void run() {
String pattern = "";
XSDNamedComponent component = getXSDNamedComponent();
IFile file = getCurrentFile();
if (file != null && component != null) {
QualifiedName metaName = determineMetaName(component);
QualifiedName elementQName = new QualifiedName(component.getTargetNamespace(), component.getName());
SearchScope scope = new WorkspaceSearchScope();
String scopeDescription = "Workspace";
XSDSearchQuery searchQuery = new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(searchQuery);
}
}
Aggregations