Skip to main content
summaryrefslogtreecommitdiffstats
blob: 71399a20e94ea420fd032b7ba94853136d184d1d (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2004 - 2005 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
/*
 * Created on Apr 6, 2005
  */
package org.eclipse.mylar.bugzilla;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.mylar.bugzilla.ui.BugzillaOpenStructure;
import org.eclipse.mylar.bugzilla.ui.ViewBugzillaAction;
import org.eclipse.mylar.bugzilla.ui.editor.AbstractBugEditor;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlinePage;
import org.eclipse.mylar.bugzilla.ui.tasks.BugzillaTask;
import org.eclipse.mylar.bugzilla.ui.tasks.BugzillaTaskEditor;
import org.eclipse.mylar.core.IMylarContextNode;
import org.eclipse.mylar.tasks.ITask;
import org.eclipse.mylar.tasks.MylarTasksPlugin;
import org.eclipse.mylar.tasks.search.BugzillaReferencesProvider;
import org.eclipse.mylar.ui.IMylarUiBridge;
import org.eclipse.mylar.ui.MylarImages;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Workbench;

public class BugzillaUiBridge implements IMylarUiBridge {

    protected BugzillaNodeLabelProvider labelProvider = new BugzillaNodeLabelProvider();
    
    public void open(IMylarContextNode node) {
        String handle = node.getElementHandle();
        String bugHandle = handle;
        String server =handle.substring(0, handle.indexOf(";"));
               
        handle = handle.substring(handle.indexOf(";") + 1);
        int next = handle.indexOf(";");
        
        int bugId;
        int commentNumer = -1;
        if(next == -1){
            bugId = Integer.parseInt(handle);
        }
        else{
            bugId = Integer.parseInt(handle.substring(0, handle.indexOf(";")));
            commentNumer = Integer.parseInt(handle.substring(handle.indexOf(";") + 1));
            bugHandle = bugHandle.substring(0, next);
        }
                
        List<BugzillaOpenStructure> l = new ArrayList<BugzillaOpenStructure>(1);
        l.add(new BugzillaOpenStructure(server, bugId, commentNumer));
        
        ITask task= MylarTasksPlugin.getTaskListManager().getTaskForHandle(bugHandle);
        if (task != null && task instanceof BugzillaTask) {
            BugzillaTask bugzillaTask = (BugzillaTask)task;
            bugzillaTask.openTask(commentNumer);
        } else {
            // open the bug in the editor
            ViewBugzillaAction viewBugs = new ViewBugzillaAction("Display bugs in editor", l);
            viewBugs.schedule();
        }
    }
    
    public ILabelProvider getLabelProvider() {
        return labelProvider;
    }

    public void close(IMylarContextNode node) {
        IWorkbenchPage page = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage();
        if (page != null) {
            IEditorReference[] references = page.getEditorReferences();
            for (int i = 0; i < references.length; i++) {
                IEditorPart part = references[i].getEditor(false);
                if (part != null) {
                    if (part instanceof AbstractBugEditor) {
                        ((AbstractBugEditor)part).close();
                    } else if(part instanceof BugzillaTaskEditor){
                        ((BugzillaTaskEditor)part).close();
                    }
                }
            }
        }
    }

    public boolean acceptsEditor(IEditorPart editorPart) {
        return editorPart instanceof AbstractBugEditor;
    }

    public List<TreeViewer> getTreeViewers(IEditorPart editor) {
        ArrayList<TreeViewer> outlines = new ArrayList<TreeViewer>(1);
        TreeViewer outline = getOutlineTreeViewer(editor);
        if (outline != null) {
            outlines.add(outline);
            return outlines;
        } else {
            return Collections.emptyList();
        }
    }
    
    protected TreeViewer getOutlineTreeViewer(IEditorPart editor) {
        if(editor instanceof AbstractBugEditor){
            AbstractBugEditor abe = (AbstractBugEditor)editor;
            BugzillaOutlinePage outline = abe.getOutline();
            if(outline != null) return outline.getOutlineTreeViewer();
        }
        return null;        
    }

    public void refreshOutline(Object element, boolean updateLabels) {
    	IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        TreeViewer treeViewer = getOutlineTreeViewer(editorPart);
        if (treeViewer != null) {
        	treeViewer.refresh(true);

            treeViewer.expandAll();
        }
    }

    public ImageDescriptor getIconForRelationship(String relationshipHandle) {
        return MylarImages.EDGE_REF_BUGZILLA; 
        
    }

    public String getNameForRelationship(String relationshipHandle) {
        return BugzillaReferencesProvider.NAME;        
    }
}

Back to the top