use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLPropertySheetConfiguration method getInputSelection.
public ISelection getInputSelection(IWorkbenchPart selectingPart, ISelection selection) {
if (fSelectedNotifiers != null) {
for (int i = 0; i < fSelectedNotifiers.length; i++) {
fSelectedNotifiers[i].removeAdapter(fRefreshAdapter);
}
fSelectedNotifiers = null;
}
for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) {
fSelectedCMDocumentManagers[i].removeListener(fCMDocumentManagerListener);
}
ISelection preferredSelection = selection;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSel = (IStructuredSelection) selection;
/*
* On Attr nodes, select the owner Element. On Text nodes, select
* the parent Element.
*/
Object[] selectedObjects = new Object[structuredSel.size()];
System.arraycopy(structuredSel.toArray(), 0, selectedObjects, 0, selectedObjects.length);
for (int i = 0; i < selectedObjects.length; i++) {
Object inode = selectedObjects[i];
if (inode instanceof Node) {
Node node = (Node) inode;
// replace Attribute Node with its owner
Node parentNode = node.getParentNode();
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
Element ownerElement = ((Attr) node).getOwnerElement();
selectedObjects[i] = ownerElement;
} else // replace Text Node with its parent
if (((node.getNodeType() == Node.TEXT_NODE) || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && (parentNode != null)) {
selectedObjects[i] = parentNode;
}
}
}
if (selectedObjects.length > 0) {
Set managers = new HashSet(1);
Set selectedNotifiers = new HashSet(1);
for (int i = 0; i < selectedObjects.length; i++) {
if (selectedObjects[i] instanceof Node) {
ModelQuery query = ModelQueryUtil.getModelQuery(((Node) selectedObjects[i]).getOwnerDocument());
if (query != null) {
CMDocumentManager mgr = query.getCMDocumentManager();
if (mgr != null) {
managers.add(mgr);
mgr.addListener(fCMDocumentManagerListener);
}
}
}
/*
* Add UI refresh adapters and remember notifiers for
* later removal
*/
if (selectedObjects[i] instanceof INodeNotifier) {
selectedNotifiers.add(selectedObjects[i]);
((INodeNotifier) selectedObjects[i]).addAdapter(fRefreshAdapter);
}
}
fSelectedCMDocumentManagers = (CMDocumentManager[]) managers.toArray(new CMDocumentManager[managers.size()]);
fSelectedNotifiers = (INodeNotifier[]) selectedNotifiers.toArray(new INodeNotifier[selectedNotifiers.size()]);
}
preferredSelection = new StructuredSelection(selectedObjects);
}
return preferredSelection;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLTableTreeContentProvider method inputChanged.
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// remove our listeners to the old state
if (oldInput != null) {
Document domDoc = (Document) oldInput;
ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
if (mq != null) {
documentManager = mq.getCMDocumentManager();
if (documentManager != null) {
documentManager.removeListener(this);
}
}
}
if ((oldInput != null) && (oldInput instanceof IDOMNode)) {
IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) oldInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
if (factory != null) {
factory.removeListener(viewer);
}
}
if (viewer instanceof StructuredViewer) {
fViewer = null;
} else {
fViewer = (StructuredViewer) viewer;
}
if ((newInput != null) && (newInput instanceof IDOMNode)) {
IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) newInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
if (factory != null) {
factory.addListener(viewer);
}
}
if (newInput != null) {
Document domDoc = (Document) newInput;
ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
if (mq != null) {
documentManager = mq.getCMDocumentManager();
if (documentManager != null) {
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
documentManager.addListener(this);
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLTableTreePropertyDescriptorFactory method createAttributePropertyDescriptor.
public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) {
IPropertyDescriptor result = null;
String attributeName = attr.getName();
ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument());
CMAttributeDeclaration ad = null;
if (mq != null) {
ad = mq.getCMAttributeDeclaration(attr);
}
if (ad != null) {
result = createPropertyDescriptorHelper(attributeName, attr.getOwnerElement(), ad);
}
if (result == null) {
result = new TextPropertyDescriptor(attributeName, attributeName);
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLTableTreePropertyDescriptorFactory method createPropertyDescriptorHelper.
protected IPropertyDescriptor createPropertyDescriptorHelper(String name, Element element, CMNode cmNode) {
IPropertyDescriptor result = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
String[] valuesArray = null;
if (mq != null) {
valuesArray = mq.getPossibleDataTypeValues(element, cmNode);
}
if ((valuesArray != null) && (valuesArray.length > 0)) {
result = new EnumeratedStringPropertyDescriptor(name, name, valuesArray);
} else {
result = createDefaultPropertyDescriptor(name);
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class ElementImpl method getDeclaration.
/**
*/
protected CMElementDeclaration getDeclaration() {
Document document = getOwnerDocument();
if (document == null)
return null;
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
if (modelQuery == null)
return null;
return modelQuery.getCMElementDeclaration(this);
}
Aggregations