diff options
author | mkersten | 2005-11-13 19:46:12 +0000 |
---|---|---|
committer | mkersten | 2005-11-13 19:46:12 +0000 |
commit | 2cc92963032a083f8c92fd86ae1feed0bd9dfac5 (patch) | |
tree | c693f0dfe920011fb5bb464ad1558ab190c85f2d | |
parent | dbd27cd944dfb3b7287e658455c56d7b2df37037 (diff) | |
download | org.eclipse.mylyn.tasks-2cc92963032a083f8c92fd86ae1feed0bd9dfac5.tar.gz org.eclipse.mylyn.tasks-2cc92963032a083f8c92fd86ae1feed0bd9dfac5.tar.xz org.eclipse.mylyn.tasks-2cc92963032a083f8c92fd86ae1feed0bd9dfac5.zip |
robutstness
-rw-r--r-- | org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/BugzillaStructureBridge.java | 363 |
1 files changed, 182 insertions, 181 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/BugzillaStructureBridge.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/BugzillaStructureBridge.java index 31e968583..424dae2f7 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/BugzillaStructureBridge.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/BugzillaStructureBridge.java @@ -16,8 +16,8 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.mylar.bugzilla.core.BugReport; import org.eclipse.mylar.bugzilla.core.BugzillaRepository; import org.eclipse.mylar.bugzilla.core.BugzillaTools; @@ -33,7 +33,6 @@ import org.eclipse.mylar.core.IMylarStructureBridge; import org.eclipse.mylar.core.internal.DegreeOfSeparation; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.progress.IProgressService; import org.eclipse.ui.views.markers.internal.ProblemMarker; @@ -43,197 +42,199 @@ import org.eclipse.ui.views.markers.internal.ProblemMarker; */ public class BugzillaStructureBridge implements IMylarStructureBridge { - public final static String CONTENT_TYPE = "bugzilla"; - - public List<AbstractRelationProvider> providers; - - public String getContentType() { - return CONTENT_TYPE; - } - - public BugzillaStructureBridge() { - super(); + public final static String CONTENT_TYPE = "bugzilla"; + + public List<AbstractRelationProvider> providers; + + public String getContentType() { + return CONTENT_TYPE; + } + + public BugzillaStructureBridge() { + super(); providers = new ArrayList<AbstractRelationProvider>(); -// providers.add(MylarBugsPlugin.getReferenceProvider()); - } - - /** - * Handle format: <server-name:port>;<bug-id>;<comment#> - * - * Use: BugzillaTools ??? - */ - public String getHandleIdentifier(Object object) { - if(object instanceof BugzillaOutlineNode){ - BugzillaOutlineNode n = (BugzillaOutlineNode)object; - return BugzillaTools.getHandle(n); - } - else if(object instanceof BugzillaReportSelection){ - BugzillaReportSelection n = (BugzillaReportSelection)object; - return BugzillaTools.getHandle(n); - } - return null; - } - - private BugReport result; - - public Object getObjectForHandle(final String handle) { - result = null; - - String [] parts = handle.split(";"); - if (parts.length >= 2){ - String server = parts[0]; - final int id = Integer.parseInt(parts[1]); - - String bugHandle = server + ";" + id; - - int commentNumber = -1; - if(parts.length == 3){ - commentNumber = Integer.parseInt(parts[2]); - } - - // get the bugzillaOutlineNode for the element - IEditorPart editorPart = null; - try{ - editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); - }catch(NullPointerException e){ - // do nothing, this just means that there is no active page - } - if(editorPart != null && editorPart instanceof AbstractBugEditor){ - AbstractBugEditor abe = ((AbstractBugEditor)editorPart); - BugzillaOutlineNode node = abe.getModel(); - return findNode(node, commentNumber); - } - - BugzillaReportNode reportNode = MylarBugsPlugin.getReferenceProvider().getCached(handle); - - // try to get from the cache, if it doesn't exist, startup an operation to get it - result = MylarBugsPlugin.getDefault().getCache().getFromCache(bugHandle); - if(result == null && reportNode != null){ - return reportNode; - } else if(result == null && reportNode == null){ - WorkspaceModifyOperation op = new WorkspaceModifyOperation() { - protected void execute(IProgressMonitor monitor) throws CoreException { - monitor.beginTask("Downloading Bug# " + id, IProgressMonitor.UNKNOWN); - try { - result = BugzillaRepository.getInstance().getCurrentBug(id); - }catch(Exception e){ - result = null; - } - }}; - - // Use the progess service to execute the runnable - IProgressService service = PlatformUI.getWorkbench().getProgressService(); - try { - service.run(false, false, op); - } catch (InvocationTargetException e) { - // Operation was canceled - } catch (InterruptedException e) { - // Handle the wrapped exception - } - - if(result != null) - MylarBugsPlugin.getDefault().getCache().cache(bugHandle, result); - } - - BugzillaOutlineNode node = BugzillaOutlineNode.parseBugReport(result); - return findNode(node, commentNumber); - } - else{ - return null; - } - } - - private BugzillaOutlineNode findNode(BugzillaOutlineNode startNode, int commentNumber){ - - if(commentNumber == -1){ - return startNode; - }else if(startNode.getComment() != null && startNode.getComment().getNumber() == commentNumber -1){ - return startNode; - } else if(startNode.isCommentHeader() && commentNumber == 1){ - return startNode; - }else if(startNode.isDescription() && commentNumber == 0){ - return startNode; - } - - BugzillaOutlineNode[] children = startNode.getChildren(); - for(int i = 0; i < children.length; i++){ - BugzillaOutlineNode n = findNode(children[i], commentNumber); - if(n != null) - return n; - } - return null; - } - - public String getParentHandle(String handle) { - - //check so that we don't need to try to get the parent if we are already at the bug report - if(!handle.matches(".*;.*;.*")) - return null; - - BugzillaOutlineNode bon = (BugzillaOutlineNode)getObjectForHandle(handle); - if(bon != null && bon.getParent() != null) - return BugzillaTools.getHandle(bon.getParent()); - else - return null; -// String [] parts = handle.split(";"); -// if (parts.length == 1){ -// return null; -// }else if (parts.length > 2) { -// String newHandle = ""; -// for(int i = 0; i < parts.length - 1; i++) -// newHandle += parts[i] + ";"; -// return newHandle.substring(0, newHandle.length() - 1); -//// return handle.substring(0, handle.lastIndexOf(";")); -// } -// return null; - } - - public String getName(Object object) { - if(object instanceof BugzillaOutlineNode){ - BugzillaOutlineNode b = (BugzillaOutlineNode)object; - return BugzillaTools.getName(b); - } else if (object instanceof BugzillaReportNode){ - BugzillaSearchHit hit = ((BugzillaReportNode)object).getHit(); - return hit.getServer() + ": Bug#: " + hit.getId() + ": " + hit.getDescription(); - } - return ""; - } - - public boolean canBeLandmark(String handle) { - return false; - } - - public boolean acceptsObject(Object object) { - return object instanceof BugzillaOutlineNode || object instanceof BugzillaReportSelection; - } - - public boolean canFilter(Object element) { - return true; - } - - public boolean isDocument(String handle) { - return (handle.indexOf(';') == handle.lastIndexOf(';') && handle.indexOf(";") != -1); - } - - public String getHandleForMarker(ProblemMarker marker) { - return null; - } + // providers.add(MylarBugsPlugin.getReferenceProvider()); + } + + /** + * Handle format: <server-name:port>;<bug-id>;<comment#> + * + * Use: BugzillaTools ??? + */ + public String getHandleIdentifier(Object object) { + if (object instanceof BugzillaOutlineNode) { + BugzillaOutlineNode n = (BugzillaOutlineNode) object; + return BugzillaTools.getHandle(n); + } else if (object instanceof BugzillaReportSelection) { + BugzillaReportSelection n = (BugzillaReportSelection) object; + return BugzillaTools.getHandle(n); + } + return null; + } + + private BugReport result; + + /** + * TODO: this will not return a non-cached handle + */ + public Object getObjectForHandle(final String handle) { + result = null; + + String[] parts = handle.split(";"); + if (parts.length >= 2) { + String server = parts[0]; + final int id = Integer.parseInt(parts[1]); + + final String bugHandle = server + ";" + id; + + int commentNumber = -1; + if (parts.length == 3) { + commentNumber = Integer.parseInt(parts[2]); + } + + // get the bugzillaOutlineNode for the element + IEditorPart editorPart = null; + try { + editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + } catch (NullPointerException e) { + // do nothing, this just means that there is no active page + } + if (editorPart != null && editorPart instanceof AbstractBugEditor) { + AbstractBugEditor abe = ((AbstractBugEditor) editorPart); + BugzillaOutlineNode node = abe.getModel(); + return findNode(node, commentNumber); + } + + BugzillaReportNode reportNode = MylarBugsPlugin.getReferenceProvider().getCached(handle); + + // try to get from the cache, if it doesn't exist, startup an + // operation to get it + result = MylarBugsPlugin.getDefault().getCache().getFromCache(bugHandle); + if (result == null && reportNode != null) { + return reportNode; + } else if (result == null && reportNode == null) { + IRunnableWithProgress op = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) { + monitor.beginTask("Downloading Bug# " + id, IProgressMonitor.UNKNOWN); + try { + result = BugzillaRepository.getInstance().getCurrentBug(id); + if (result != null) { + MylarBugsPlugin.getDefault().getCache().cache(bugHandle, result); + } + } catch (Exception e) { + result = null; + } + } + }; + + IProgressService service = PlatformUI.getWorkbench().getProgressService(); + try { + service.run(false, false, op); + } catch (InvocationTargetException e) { + // Operation was canceled + } catch (InterruptedException e) { + // Handle the wrapped exception + } + return null; + } +// BugzillaOutlineNode node = BugzillaOutlineNode.parseBugReport(result); +// return findNode(node, commentNumber); + } + return null; + } + + private BugzillaOutlineNode findNode(BugzillaOutlineNode startNode, int commentNumber) { + + if (commentNumber == -1) { + return startNode; + } else if (startNode.getComment() != null && startNode.getComment().getNumber() == commentNumber - 1) { + return startNode; + } else if (startNode.isCommentHeader() && commentNumber == 1) { + return startNode; + } else if (startNode.isDescription() && commentNumber == 0) { + return startNode; + } + + BugzillaOutlineNode[] children = startNode.getChildren(); + for (int i = 0; i < children.length; i++) { + BugzillaOutlineNode n = findNode(children[i], commentNumber); + if (n != null) + return n; + } + return null; + } + + public String getParentHandle(String handle) { + + // check so that we don't need to try to get the parent if we are + // already at the bug report + if (!handle.matches(".*;.*;.*")) + return null; + + BugzillaOutlineNode bon = (BugzillaOutlineNode) getObjectForHandle(handle); + if (bon != null && bon.getParent() != null) + return BugzillaTools.getHandle(bon.getParent()); + else + return null; + // String [] parts = handle.split(";"); + // if (parts.length == 1){ + // return null; + // }else if (parts.length > 2) { + // String newHandle = ""; + // for(int i = 0; i < parts.length - 1; i++) + // newHandle += parts[i] + ";"; + // return newHandle.substring(0, newHandle.length() - 1); + // // return handle.substring(0, handle.lastIndexOf(";")); + // } + // return null; + } + + public String getName(Object object) { + if (object instanceof BugzillaOutlineNode) { + BugzillaOutlineNode b = (BugzillaOutlineNode) object; + return BugzillaTools.getName(b); + } else if (object instanceof BugzillaReportNode) { + BugzillaSearchHit hit = ((BugzillaReportNode) object).getHit(); + return hit.getServer() + ": Bug#: " + hit.getId() + ": " + hit.getDescription(); + } + return ""; + } + + public boolean canBeLandmark(String handle) { + return false; + } + + public boolean acceptsObject(Object object) { + return object instanceof BugzillaOutlineNode || object instanceof BugzillaReportSelection; + } + + public boolean canFilter(Object element) { + return true; + } + + public boolean isDocument(String handle) { + return (handle.indexOf(';') == handle.lastIndexOf(';') && handle.indexOf(";") != -1); + } + + public String getHandleForMarker(ProblemMarker marker) { + return null; + } public IProject getProjectForObject(Object object) { // bugzilla objects do not yet sit in a project return null; } - public String getContentType(String elementHandle) { - return getContentType(); - } + public String getContentType(String elementHandle) { + return getContentType(); + } public List<AbstractRelationProvider> getRelationshipProviders() { return providers; } - + public List<IDegreeOfSeparation> getDegreesOfSeparation() { - List <IDegreeOfSeparation> separations = new ArrayList<IDegreeOfSeparation>(); + List<IDegreeOfSeparation> separations = new ArrayList<IDegreeOfSeparation>(); separations.add(new DegreeOfSeparation("disabled", 0)); separations.add(new DegreeOfSeparation("local, fully qualified matches", 1)); separations.add(new DegreeOfSeparation("local, unqualified matches", 2)); |