1 2 3 4 5 6 7 | <extension id="marker" name="XM Message" point="org.eclipse.core.resources.markers"> <super type="org.eclipse.core.resources.problemmarker"/> <super type="org.eclipse.core.resources.textmarker"/> <persistent value="true"/> </extension> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | package org.ananas.xm.eclipse; import java.text.MessageFormat; import org.eclipse.ui.IWorkbench; import org.ananas.xm.core.Filename; import org.ananas.xm.core.Location; import org.ananas.xm.core.Messenger; import org.eclipse.ui.IWorkbenchPage; import org.ananas.xm.core.XMException; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.ui.views.markers.MarkerViewUtil; public class MessengerTaskList implements Messenger, EclipseConstants { private IProject project = null; private IWorkbench workbench = null; private boolean noMarkerSoFar = true; private static class ShowMarkerView implements Runnable { private IWorkbench workbench; private IMarker marker; public ShowMarkerView(IWorkbench workbench,IMarker marker) { this.workbench = workbench; this.marker = marker; } public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if(window == null) { IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); if(windows != null && windows.length > 0) window = windows[0]; else return; } IWorkbenchPage page = window.getActivePage(); if(page != null) MarkerViewUtil.showMarker(page,marker,true); } } public MessengerTaskList(IWorkbench workbench,IProject project) { if(null == project || null == workbench) throw new NullPointerException("null argument in TaskListMessenger constructor"); this.project = project; this.workbench = workbench; } protected void addMarker(String msg,Location location, int severity,int priority) throws XMException { IResource resource = null; if(null == location || location.equals(Location.UNKNOWN)) resource = project; else resource = (IResource)location.getFilename().asPlatformSpecific(); try { IMarker marker = resource.createMarker(MARKER_ID); if(null != location && Location.UNKNOWN_POSITION != location.getLine()) marker.setAttribute(IMarker.LINE_NUMBER,location.getLine()); if(null != msg) marker.setAttribute(IMarker.MESSAGE,msg); marker.setAttribute(IMarker.SEVERITY,severity); marker.setAttribute(IMarker.PRIORITY,priority); if(noMarkerSoFar) showMarkerView(marker); else noMarkerSoFar = false; } catch(CoreException e) { throw new XMException(e,location); } } public void error(XMException x) throws XMException { addMarker(x.getMessage(),x.getLocation(), IMarker.SEVERITY_ERROR,IMarker.PRIORITY_NORMAL); } public void fatal(XMException x) throws XMException { addMarker(x.getMessage(),x.getLocation(), IMarker.SEVERITY_ERROR,IMarker.PRIORITY_HIGH); } public void warning(XMException x) throws XMException { addMarker(x.getMessage(),x.getLocation(), IMarker.SEVERITY_WARNING,IMarker.PRIORITY_LOW); } public boolean progress(Filename sourceFile,Filename resultFile) { return true; } public void info(String msg,Location location) throws XMException { addMarker(msg,location,IMarker.SEVERITY_INFO,IMarker.PRIORITY_NORMAL); } public void info(String pattern,Object[] arguments,Location location) throws XMException { info(MessageFormat.format(pattern,arguments),location); } public void begin(String source,String target) throws XMException { try { project.deleteMarkers(MARKER_ID,true,IResource.DEPTH_INFINITE); noMarkerSoFar = true; } catch(CoreException e) { throw new XMException(e); } } public void end() { } protected void showMarkerView(IMarker marker) { Display display = Display.getCurrent(); if(display == null) display = Display.getDefault(); ShowMarkerView showMarkerView = new ShowMarkerView(workbench,marker); display.syncExec(showMarkerView); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |