1 package org.hibernate.eclipse.mapper.views.contentoutline; 2 3 import java.util.Collection ; 4 import java.util.Iterator ; 5 6 import org.eclipse.jface.viewers.StructuredViewer; 7 import org.eclipse.swt.widgets.Display; 8 import org.eclipse.ui.PlatformUI; 9 import org.eclipse.ui.views.properties.PropertySheetPage; 10 import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; 11 import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; 12 import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; 13 import org.eclipse.wst.xml.ui.internal.XMLUIMessages; 14 import org.eclipse.wst.xml.ui.internal.contentoutline.BufferedOutlineUpdater; 15 import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeAdapter; 16 import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeAdapterFactory; 17 import org.eclipse.wst.xml.ui.internal.contentoutline.RefreshPropertySheetJob; 18 import org.w3c.dom.NamedNodeMap ; 19 import org.w3c.dom.Node ; 20 21 22 27 public class JFaceNodeAdapterForXML extends JFaceNodeAdapter { 28 final static Class ADAPTER_KEY = IJFaceNodeAdapter.class; 29 protected BufferedOutlineUpdater fUpdater; 30 protected INodeAdapterFactory adapterFactory; 31 32 public JFaceNodeAdapterForXML(INodeAdapterFactory adapterFactory) { 33 super(adapterFactory); 34 this.adapterFactory = adapterFactory; 35 } 36 37 38 39 42 public String getLabelText(Object object) { 43 String result = getNodeName(object); 44 Node node = (Node ) object; 45 NamedNodeMap attributes = node.getAttributes(); 46 if(attributes!=null) { 47 Node firstAttribute = attributes.item(0); 48 if(firstAttribute!=null) { 49 return result + " " + firstAttribute.getNodeName() + "=\"" + firstAttribute.getNodeValue() + "\""; 50 } 51 } 52 53 return result; 54 } 55 56 private String getNodeName(Object object) { 57 Node node = (Node ) object; 58 String nodeName = node.getNodeName(); 59 return nodeName; 60 } 61 62 public Object getParent(Object object) { 63 64 Node node = (Node ) object; 65 return node.getParentNode(); 66 } 67 68 public boolean hasChildren(Object object) { 69 return super.hasChildren(object); 70 } 71 72 76 public boolean isAdapterForType(Object type) { 77 return type.equals(ADAPTER_KEY); 78 } 79 80 81 private BufferedOutlineUpdater getOutlineUpdater() { 82 if (fUpdater == null) 83 fUpdater = new BufferedOutlineUpdater(); 84 return fUpdater; 85 } 86 87 88 Display getDisplay() { 89 90 if (PlatformUI.isWorkbenchRunning()) 95 return PlatformUI.getWorkbench().getDisplay(); 96 else 97 return null; 98 } 99 100 104 public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { 105 106 Collection listeners = ((JFaceNodeAdapterFactory) adapterFactory).getListeners(); 114 Iterator iterator = listeners.iterator(); 115 116 while (iterator.hasNext()) { 117 Object listener = iterator.next(); 118 if (notifier instanceof Node && (listener instanceof StructuredViewer) && (eventType == INodeNotifier.STRUCTURE_CHANGED || (eventType == INodeNotifier.CHANGE ))) { 119 120 122 StructuredViewer structuredViewer = (StructuredViewer) listener; 124 if (structuredViewer.getControl() != null ) 129 getOutlineUpdater().processNode(structuredViewer, (Node ) notifier); 130 } else if ((listener instanceof PropertySheetPage) && ((eventType == INodeNotifier.CHANGE) || (eventType == INodeNotifier.STRUCTURE_CHANGED))) { 131 PropertySheetPage propertySheetPage = (PropertySheetPage) listener; 132 if (propertySheetPage.getControl() != null ) { 136 RefreshPropertySheetJob refreshPropertySheetJob = new RefreshPropertySheetJob(getDisplay(), XMLUIMessages.JFaceNodeAdapter_1, propertySheetPage); refreshPropertySheetJob.schedule(); 138 } 139 } 140 } 141 } 142 } 143 | Popular Tags |