use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class FindReferencesInWorkingSetAction method run.
public void run() {
IWorkingSet[] workingSets = queryWorkingSets();
if (workingSets == null || workingSets.length == 0)
// The user chooses nothing, no point to continue.
return;
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());
// Create a scope from the selected working sets
WorkingSetSearchScope scope = new WorkingSetSearchScope();
for (int i = 0; i < workingSets.length; i++) {
IAdaptable[] elements = workingSets[i].getElements();
scope.addAWorkingSetToScope(elements);
}
String scopeDescription = "Working Set";
XSDSearchQuery searchQuery = new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(searchQuery);
}
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class XSDModelGroupDefinitionSection method doWidgetSelected.
public void doWidgetSelected(SelectionEvent e) {
if (e.widget == componentNameCombo) {
String newValue = componentNameCombo.getText();
if (input instanceof XSDNamedComponent) {
XSDNamedComponent namedComponent = (XSDNamedComponent) input;
Element element = namedComponent.getElement();
if (namedComponent instanceof XSDModelGroupDefinition) {
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 XSDModelGroupDefinitionSection 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 = "";
}
componentNameCombo.setText(attrValue);
// refresh min max
if (minCombo != null && maxCombo != null) {
refreshMinMax();
}
}
} 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 RenameComponentAction method canEnable.
protected boolean canEnable(XSDConcreteComponent selectedObject) {
selectedComponent = null;
if (selectedObject instanceof XSDNamedComponent) {
selectedComponent = (XSDNamedComponent) selectedObject;
// if it's element reference, then this action is not appropriate
if (selectedComponent instanceof XSDElementDeclaration) {
XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
if (element.isElementDeclarationReference()) {
selectedComponent = null;
}
}
if (selectedComponent instanceof XSDTypeDefinition) {
XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent;
XSDConcreteComponent parent = type.getContainer();
if (parent instanceof XSDElementDeclaration) {
XSDElementDeclaration element = (XSDElementDeclaration) parent;
if (element.getAnonymousTypeDefinition().equals(type)) {
selectedComponent = null;
}
} else if (parent instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
if (element.getAnonymousTypeDefinition().equals(type)) {
selectedComponent = null;
}
}
}
}
return canRun();
}
use of org.eclipse.xsd.XSDNamedComponent in project webtools.sourceediting by eclipse.
the class XSDDirectivesManager method doCrossReferencer.
/**
* This determines the list of referenced components and hence the used schemas from which
* we can determine what are the unused directives
*
* @param schema
* @param unusedImportList
* @param usedSchemas
*/
protected void doCrossReferencer(XSDSchema schema, List usedSchemas, Map xsdNamedComponentUsage) {
// Calculate additional unused imports that may have the same
// namespace that did not get added in the initial pass
Iterator iterator = xsdNamedComponentUsage.keySet().iterator();
// First determine the used schemas from the cross referencer
while (iterator.hasNext()) {
XSDNamedComponent namedComponent = (XSDNamedComponent) iterator.next();
XSDSchema namedComponentSchema = namedComponent.getSchema();
// want to check the external references
if (namedComponentSchema == schema) {
continue;
}
Collection collection = (Collection) xsdNamedComponentUsage.get(namedComponent);
Iterator iterator2 = collection.iterator();
while (iterator2.hasNext()) {
Setting setting = (Setting) iterator2.next();
Object obj = setting.getEObject();
if (isComponentUsed(obj, schema, namedComponentSchema)) {
if (!usedSchemas.contains(namedComponentSchema))
usedSchemas.add(namedComponentSchema);
}
}
}
}
Aggregations