Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 81795 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/bugzilla/adapters/BugzillaAttachmentAdapter.java (-82 / +82 lines)
Lines 1-82 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.adapters;
12
package org.eclipse.team.bugzilla.adapters;
13
13
14
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.swt.custom.StyledText;
15
import org.eclipse.swt.custom.StyledText;
16
import org.eclipse.swt.graphics.FontData;
16
import org.eclipse.swt.graphics.FontData;
17
import org.eclipse.team.bugzilla.BugzillaImages;
17
import org.eclipse.team.bugzilla.BugzillaImages;
18
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
18
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
19
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
19
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
20
import org.eclipse.team.bugzilla.model.BugzillaAttachment;
20
import org.eclipse.team.bugzilla.model.BugzillaAttachment;
21
import org.eclipse.team.bugzilla.view.BugzillaModelPresenter;
21
import org.eclipse.team.bugzilla.view.BugzillaModelPresenter;
22
import org.eclipse.team.bugzilla.view.IPresentableAdapter;
22
import org.eclipse.team.bugzilla.view.IPresentableAdapter;
23
23
24
/**
24
/**
25
 * 
25
 * 
26
 */
26
 */
27
public class BugzillaAttachmentAdapter extends ModelElementAdapter implements IPresentableAdapter, IWebContentAdapter {
27
public class BugzillaAttachmentAdapter extends ModelElementAdapter implements IPresentableAdapter, IWebContentAdapter {
28
28
29
    public BugzillaAttachmentAdapter() {
29
    public BugzillaAttachmentAdapter() {
30
        super();
30
        super();
31
    }
31
    }
32
32
33
    public void present(Object presentable, StyledText styledText) {
33
    public void present(Object presentable, StyledText styledText) {
34
34
35
        if (!(presentable instanceof BugzillaAttachment)) 
35
        if (!(presentable instanceof BugzillaAttachment)) 
36
            return;
36
            return;
37
        
37
        
38
        new BugzillaModelPresenter().present((BugzillaAttachment)presentable, styledText);
38
        new BugzillaModelPresenter().present((BugzillaAttachment)presentable, styledText);
39
    }
39
    }
40
40
41
    protected ImageDescriptor doGetImageDescriptor(Object object) {
41
    protected ImageDescriptor doGetImageDescriptor(Object object) {
42
        final BugzillaAttachment attachment= (BugzillaAttachment)object;
42
        final BugzillaAttachment attachment= (BugzillaAttachment)object;
43
        return attachment.getData() != null ? BugzillaImages.ATTACHMENT: BugzillaImages.INCOMPLETE_ATTACHMENT;
43
        return attachment.getData() != null ? BugzillaImages.ATTACHMENT: BugzillaImages.INCOMPLETE_ATTACHMENT;
44
    }
44
    }
45
45
46
    public String getLabel(Object o) {
46
    public String getLabel(Object o) {
47
        final BugzillaAttachment attachment= (BugzillaAttachment)o;
47
        final BugzillaAttachment attachment= (BugzillaAttachment)o;
48
        return attachment.isRefreshing() ? getRefreshingLabel("attachment " + attachment.getID()) : getStandardLabel(attachment); 
48
        return attachment.isRefreshing() ? getRefreshingLabel("attachment " + attachment.getID()) : getStandardLabel(attachment); 
49
    }
49
    }
50
50
51
    /**
51
    /**
52
     * @param attachment
52
     * @param attachment
53
     * @return
53
     * @return String
54
     */
54
     */
55
    private String getStandardLabel(final BugzillaAttachment attachment) {
55
    private String getStandardLabel(final BugzillaAttachment attachment) {
56
        final StringBuffer label= new StringBuffer();
56
        final StringBuffer label= new StringBuffer();
57
        
57
        
58
        if (attachment.getDescription().getBoolean(AttachmentDescription.OBSOLETE)) 
58
        if (attachment.getDescription().getBoolean(AttachmentDescription.OBSOLETE)) 
59
            label.append("[OBSOLETE]  ");
59
            label.append("[OBSOLETE]  ");
60
        
60
        
61
        label.append("[").append(attachment.getDescription().getString(AttachmentDescription.ID)).append("]  ");
61
        label.append("[").append(attachment.getDescription().getString(AttachmentDescription.ID)).append("]  ");
62
        
62
        
63
        if (attachment.hasLocalContent())
63
        if (attachment.hasLocalContent())
64
            label.append(attachment.getDescription().getString(AttachmentDescription.DESCRIPTION));
64
            label.append(attachment.getDescription().getString(AttachmentDescription.DESCRIPTION));
65
        
65
        
66
        return label.toString();
66
        return label.toString();
67
    }
67
    }
68
68
69
    public String getURL(Object o) {
69
    public String getURL(Object o) {
70
        return null;
70
        return null;
71
    }
71
    }
72
    
72
    
73
    /* (non-Javadoc)
73
    /* (non-Javadoc)
74
     * @see org.eclipse.team.bugzilla.adapters.ModelElementAdapter#getFont(java.lang.Object)
74
     * @see org.eclipse.team.bugzilla.adapters.ModelElementAdapter#getFont(java.lang.Object)
75
     */
75
     */
76
    public FontData getFont(Object element) {
76
    public FontData getFont(Object element) {
77
        final BugzillaAttachment attachment= (BugzillaAttachment)element;
77
        final BugzillaAttachment attachment= (BugzillaAttachment)element;
78
        if (attachment.isRefreshing())
78
        if (attachment.isRefreshing())
79
            return getRefreshingFont();
79
            return getRefreshingFont();
80
        return super.getFont(element);
80
        return super.getFont(element);
81
    }
81
    }
82
}
82
}
(-)src/org/eclipse/team/bugzilla/adapters/BugzillaFolderAdapter.java (-35 / +31 lines)
Lines 1-35 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.adapters;
12
package org.eclipse.team.bugzilla.adapters;
13
13
14
import org.eclipse.swt.custom.StyledText;
14
15
import org.eclipse.team.bugzilla.model.BugzillaFolder;
15
/**
16
import org.eclipse.team.bugzilla.view.BugzillaModelPresenter;
16
 * 
17
import org.eclipse.team.bugzilla.view.IPresentableAdapter;
17
 */
18
18
public class BugzillaFolderAdapter extends ContainerAdapter /*implements IPresentableAdapter*/ {
19
/**
19
   
20
 * 
20
    public BugzillaFolderAdapter() {
21
 */
21
    }
22
public class BugzillaFolderAdapter extends ContainerAdapter /*implements IPresentableAdapter*/ {
22
    /*
23
   
23
    public void present(Object presentable, StyledText styledText) {
24
    public BugzillaFolderAdapter() {
24
    	
25
    }
25
    	if (!(presentable instanceof BugzillaFolder)) 
26
    /*
26
            return;
27
    public void present(Object presentable, StyledText styledText) {
27
    	
28
    	
28
        new BugzillaModelPresenter().present((BugzillaFolder)presentable, styledText);
29
    	if (!(presentable instanceof BugzillaFolder)) 
29
     }
30
            return;
30
     */
31
    	
31
}
32
        new BugzillaModelPresenter().present((BugzillaFolder)presentable, styledText);
33
     }
34
     */
35
}
(-)src/org/eclipse/team/bugzilla/adapters/BugzillaQueryAdapter.java (-80 / +80 lines)
Lines 1-80 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.bugzilla.adapters;
11
package org.eclipse.team.bugzilla.adapters;
12
12
13
import org.eclipse.jface.resource.ImageDescriptor;
13
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.swt.custom.StyledText;
14
import org.eclipse.swt.custom.StyledText;
15
import org.eclipse.swt.graphics.FontData;
15
import org.eclipse.swt.graphics.FontData;
16
import org.eclipse.team.bugzilla.BugzillaImages;
16
import org.eclipse.team.bugzilla.BugzillaImages;
17
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
17
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
18
import org.eclipse.team.bugzilla.model.BugzillaQuery;
18
import org.eclipse.team.bugzilla.model.BugzillaQuery;
19
import org.eclipse.team.bugzilla.view.BugzillaModelPresenter;
19
import org.eclipse.team.bugzilla.view.BugzillaModelPresenter;
20
import org.eclipse.team.bugzilla.view.IPresentableAdapter;
20
import org.eclipse.team.bugzilla.view.IPresentableAdapter;
21
21
22
public class BugzillaQueryAdapter extends ContainerAdapter implements IWebContentAdapter, IPresentableAdapter {
22
public class BugzillaQueryAdapter extends ContainerAdapter implements IWebContentAdapter, IPresentableAdapter {
23
23
24
    /* (non-Javadoc)
24
    /* (non-Javadoc)
25
     * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
25
     * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
26
     */
26
     */
27
    protected ImageDescriptor doGetImageDescriptor(Object object) {
27
    protected ImageDescriptor doGetImageDescriptor(Object object) {
28
        return BugzillaImages.QUERY;
28
        return BugzillaImages.QUERY;
29
    }
29
    }
30
30
31
    /* (non-Javadoc)
31
    /* (non-Javadoc)
32
     * @see org.eclipse.team.bugzilla.browser.IWebContentAdapter#getURL(java.lang.Object)
32
     * @see org.eclipse.team.bugzilla.browser.IWebContentAdapter#getURL(java.lang.Object)
33
     */
33
     */
34
    public String getURL(Object o) {
34
    public String getURL(Object o) {
35
        if (o instanceof BugzillaQuery) {
35
        if (o instanceof BugzillaQuery) {
36
            return ((BugzillaQuery)o).getQueryUrl().toUrlString();
36
            return ((BugzillaQuery)o).getQueryUrl().toUrlString();
37
        }
37
        }
38
        return null;
38
        return null;
39
    }
39
    }
40
    
40
    
41
    /* (non-Javadoc)
41
    /* (non-Javadoc)
42
     * @see org.eclipse.team.bugzilla.adapters.ContainerAdapter#getLabel(java.lang.Object)
42
     * @see org.eclipse.team.bugzilla.adapters.ContainerAdapter#getLabel(java.lang.Object)
43
     */
43
     */
44
    public String getLabel(Object o) {
44
    public String getLabel(Object o) {
45
       final BugzillaQuery query= (BugzillaQuery)o;
45
       final BugzillaQuery query= (BugzillaQuery)o;
46
       return query.isRefreshing() ? getRefreshingLabel("query " + query.getName()) : getStandardLabel(query);
46
       return query.isRefreshing() ? getRefreshingLabel("query " + query.getName()) : getStandardLabel(query);
47
    }
47
    }
48
48
49
    /**
49
    /**
50
     * @param query
50
     * @param query
51
     * @return
51
     * @return String
52
     */
52
     */
53
    private String getStandardLabel(final BugzillaQuery query) {
53
    private String getStandardLabel(final BugzillaQuery query) {
54
        final StringBuffer label= new StringBuffer();
54
        final StringBuffer label= new StringBuffer();
55
           if (query.hasLocalContent()) {
55
           if (query.hasLocalContent()) {
56
               label.append("(");
56
               label.append("(");
57
               final int size= query.getChildren().length;
57
               final int size= query.getChildren().length;
58
               label.append(size).append(size == 1 ? " result" : " results").append(") ");
58
               label.append(size).append(size == 1 ? " result" : " results").append(") ");
59
           }
59
           }
60
           return label.append(query.getName()).toString();
60
           return label.append(query.getName()).toString();
61
    }
61
    }
62
    
62
    
63
    /* (non-Javadoc)
63
    /* (non-Javadoc)
64
     * @see org.eclipse.team.bugzilla.adapters.ModelElementAdapter#getFont(java.lang.Object)
64
     * @see org.eclipse.team.bugzilla.adapters.ModelElementAdapter#getFont(java.lang.Object)
65
     */
65
     */
66
    public FontData getFont(Object element) {
66
    public FontData getFont(Object element) {
67
        final BugzillaQuery query= (BugzillaQuery)element;
67
        final BugzillaQuery query= (BugzillaQuery)element;
68
        if (query.isRefreshing())
68
        if (query.isRefreshing())
69
            return getRefreshingFont();
69
            return getRefreshingFont();
70
        return super.getFont(element);
70
        return super.getFont(element);
71
    }
71
    }
72
    
72
    
73
    public void present(Object presentable, StyledText styledText) {
73
    public void present(Object presentable, StyledText styledText) {
74
    	
74
    	
75
    	if (!(presentable instanceof BugzillaQuery)) 
75
    	if (!(presentable instanceof BugzillaQuery)) 
76
            return;
76
            return;
77
    	
77
    	
78
    	new BugzillaModelPresenter().present((BugzillaQuery)presentable, styledText);
78
    	new BugzillaModelPresenter().present((BugzillaQuery)presentable, styledText);
79
     }
79
     }
80
}
80
}
(-)src/org/eclipse/team/bugzilla/adapters/BugzillaReportAdapter.java (-137 / +136 lines)
Lines 1-137 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.adapters;
12
package org.eclipse.team.bugzilla.adapters;
13
13
14
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.swt.custom.StyledText;
15
import org.eclipse.swt.custom.StyledText;
16
import org.eclipse.swt.graphics.FontData;
16
import org.eclipse.swt.graphics.FontData;
17
import org.eclipse.swt.graphics.RGB;
17
import org.eclipse.swt.graphics.RGB;
18
import org.eclipse.team.bugzilla.BugzillaImages;
18
import org.eclipse.team.bugzilla.BugzillaImages;
19
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
19
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
20
import org.eclipse.team.bugzilla.datatypes.ReportData;
20
import org.eclipse.team.bugzilla.datatypes.ReportData;
21
import org.eclipse.team.bugzilla.model.BugzillaProvider;
21
import org.eclipse.team.bugzilla.model.BugzillaProvider;
22
import org.eclipse.team.bugzilla.model.BugzillaReport;
22
import org.eclipse.team.bugzilla.model.BugzillaReport;
23
import org.eclipse.team.bugzilla.operations.CachedOperations;
23
import org.eclipse.team.bugzilla.operations.CachedOperations;
24
import org.eclipse.team.bugzilla.view.BugzillaModelPresenter;
24
import org.eclipse.team.bugzilla.view.BugzillaModelPresenter;
25
import org.eclipse.team.bugzilla.view.IPresentableAdapter;
25
import org.eclipse.team.bugzilla.view.IPresentableAdapter;
26
26
27
/**
27
/**
28
 * 
28
 * 
29
 */
29
 */
30
public class BugzillaReportAdapter extends ModelElementAdapter implements IPresentableAdapter, IWebContentAdapter {
30
public class BugzillaReportAdapter extends ModelElementAdapter implements IPresentableAdapter, IWebContentAdapter {
31
31
32
32
33
    public void present(Object presentable, StyledText styledText) {
33
    public void present(Object presentable, StyledText styledText) {
34
34
35
        if (!(presentable instanceof BugzillaReport)) 
35
        if (!(presentable instanceof BugzillaReport)) 
36
            return;
36
            return;
37
        
37
        
38
        new BugzillaModelPresenter().present((BugzillaReport)presentable, styledText);
38
        new BugzillaModelPresenter().present((BugzillaReport)presentable, styledText);
39
    }
39
    }
40
40
41
    public Object[] getChildren(Object o) {
41
    public Object[] getChildren(Object o) {
42
        return ((BugzillaReport)o).getComments().toArray();
42
        return ((BugzillaReport)o).getComments().toArray();
43
    }
43
    }
44
44
45
    protected ImageDescriptor doGetImageDescriptor(Object object) {
45
    protected ImageDescriptor doGetImageDescriptor(Object object) {
46
        final BugzillaReport report= (BugzillaReport)object;
46
        final BugzillaReport report= (BugzillaReport)object;
47
        final ReportData data= report.getReportData();
47
        final ReportData data= report.getReportData();
48
        return data != null ? BugzillaImages.BUG : BugzillaImages.INCOMPLETE_BUG;
48
        return data != null ? BugzillaImages.BUG : BugzillaImages.INCOMPLETE_BUG;
49
    }
49
    }
50
50
51
    public String getLabel(Object o) {
51
    public String getLabel(Object o) {
52
        final BugzillaReport report= (BugzillaReport)o;
52
        final BugzillaReport report= (BugzillaReport)o;
53
        return report.isRefreshing() ? getRefreshingLabel("bug " + report.getID()) : getStandardLabel(report);
53
        return report.isRefreshing() ? getRefreshingLabel("bug " + report.getID()) : getStandardLabel(report);
54
    }
54
    }
55
    
55
    
56
    /**
56
    /**
57
     * @param report
57
     * @param report
58
     * @param name
58
     * @return String
59
     * @return
59
     */
60
     */
60
    private String getStandardLabel(final BugzillaReport report) {
61
    private String getStandardLabel(final BugzillaReport report) {
61
        final StringBuffer name= new StringBuffer();
62
        final StringBuffer name= new StringBuffer();
62
        name.append(report.getID());
63
        name.append(report.getID());
63
        
64
        
64
        final ReportData data= report.getReportData();
65
        final ReportData data= report.getReportData();
65
        
66
        
66
        if (data != null) {
67
        if (data != null) {
67
            final String priority= data.getString(ReportData.PRIORITY);
68
            final String priority= data.getString(ReportData.PRIORITY);
68
            final String status= data.getString(ReportData.STATUS);
69
            final String status= data.getString(ReportData.STATUS);
69
            final String milestone= data.getString(ReportData.TARGETMILESTONE);
70
            final String milestone= data.getString(ReportData.TARGETMILESTONE);
70
            final String title= data.getString(ReportData.TITLE);
71
            final String title= data.getString(ReportData.TITLE);
71
            
72
            
72
            name.append(" [");
73
            name.append(" [");
73
            if (priority != null) name.append(priority);
74
            if (priority != null) name.append(priority);
74
            if (status != null) name.append(" ").append(status);
75
            if (status != null) name.append(" ").append(status);
75
            if (milestone != null) name.append(" ").append(milestone);
76
            if (milestone != null) name.append(" ").append(milestone);
76
            name.append("]");
77
            name.append("]");
77
            if (title != null) name.append(" ").append(title);
78
            if (title != null) name.append(" ").append(title);
78
        }
79
        }
79
        return name.toString();
80
        return name.toString();
80
    }
81
    }
81
82
82
    public String getURL(Object o) {
83
    public String getURL(Object o) {
83
        final BugzillaReport report= (BugzillaReport)o;
84
        final BugzillaReport report= (BugzillaReport)o;
84
        final BugzillaProvider provider= (BugzillaProvider)report.getProvider();
85
        final BugzillaProvider provider= (BugzillaProvider)report.getProvider();
85
        final CachedOperations operations= provider.getOperations();
86
        final CachedOperations operations= provider.getOperations();
86
        if (operations.isCached()) {
87
        if (operations.isCached()) {
87
            return operations.getOperations().getReportURL(provider.getConfiguration(), report.getID());
88
            return operations.getOperations().getReportURL(provider.getConfiguration(), report.getID());
88
        }
89
        }
89
        return null;
90
        return null;
90
    }
91
    }
91
92
92
    /* (non-Javadoc)
93
    /* (non-Javadoc)
93
     * @see org.eclipse.ui.model.IWorkbenchAdapter2#getForeground(java.lang.Object)
94
     * @see org.eclipse.ui.model.IWorkbenchAdapter2#getForeground(java.lang.Object)
94
     */
95
     */
95
    public RGB getForeground(Object element) {
96
    public RGB getForeground(Object element) {
96
        final ReportData data= ((BugzillaReport)element).getReportData();
97
        final ReportData data= ((BugzillaReport)element).getReportData();
97
        
98
        
98
        if (data == null)
99
        if (data == null)
99
            return super.getForeground(element);
100
            return super.getForeground(element);
100
        
101
        
101
        final String severity= data.getString(ReportData.SEVERITY);
102
        final String severity= data.getString(ReportData.SEVERITY);
102
        
103
        
103
        if ("blocker".equals(severity) || "critical".equals(severity)) {
104
        if ("blocker".equals(severity) || "critical".equals(severity)) {
104
            return RED;
105
            return RED;
105
        }
106
        }
106
        return super.getForeground(element);
107
        return super.getForeground(element);
107
    }
108
    }
108
109
109
    /* (non-Javadoc)
110
    /* (non-Javadoc)
110
     * @see org.eclipse.ui.model.IWorkbenchAdapter2#getFont(java.lang.Object)
111
     * @see org.eclipse.ui.model.IWorkbenchAdapter2#getFont(java.lang.Object)
111
     */
112
     */
112
    public FontData getFont(Object element) {
113
    public FontData getFont(Object element) {
113
        
114
        
114
        final BugzillaReport report= (BugzillaReport)element;
115
        final BugzillaReport report= (BugzillaReport)element;
115
        if (report.isRefreshing())
116
        if (report.isRefreshing())
116
            return getRefreshingFont();
117
            return getRefreshingFont();
117
        
118
        
118
        final ReportData data= report.getReportData();
119
        final ReportData data= report.getReportData();
119
        
120
        
120
        if (data == null)
121
        if (data == null)
121
            return super.getFont(element);
122
            return super.getFont(element);
122
123
123
        final String severity= data.getString(ReportData.SEVERITY);
124
        final String severity= data.getString(ReportData.SEVERITY);
124
        
125
        
125
        if ("enhancement".equals(severity)) {
126
        if ("enhancement".equals(severity)) {
126
            return ITALIC_FONT;
127
            return ITALIC_FONT;
127
        }
128
        }
128
        
129
        
129
        if ("blocker".equals(severity)) {
130
        if ("blocker".equals(severity)) {
130
            return BOLD_FONT;
131
            return BOLD_FONT;
131
        }
132
        }
132
        
133
        
133
        return super.getFont(element);
134
        return super.getFont(element);
134
    }
135
    }
135
    
136
    
136
}
137
}
(-)src/org/eclipse/team/bugzilla/datatypes/BugzillaConfiguration.java (-68 / +62 lines)
Lines 1-68 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.bugzilla.datatypes;
11
package org.eclipse.team.bugzilla.datatypes;
12
12
13
import org.eclipse.team.bugzilla.BugzillaFactory;
13
import org.eclipse.team.bugzilla.BugzillaFactory;
14
14
15
15
16
16
17
public class BugzillaConfiguration {
17
public class BugzillaConfiguration {
18
    
18
    
19
    private String fName;
19
    private String fName;
20
    private String fBaseURL;
20
    private String fBaseURL;
21
    private String fCookie;
21
    private String fCookie;
22
    private int version;
22
    private int version;
23
    
23
    
24
    public BugzillaConfiguration(String name, String baseURL) {
24
    public BugzillaConfiguration(String name, String baseURL) {
25
        fName= name;
25
        fName= name;
26
        fBaseURL= baseURL;
26
        fBaseURL= baseURL;
27
        version = BugzillaFactory.VERSION_UNKNOWN;
27
        version = BugzillaFactory.VERSION_UNKNOWN;
28
    }
28
    }
29
    
29
    
30
    public void setBaseURL(String baseURL) {
30
    public void setBaseURL(String baseURL) {
31
        fBaseURL = baseURL;
31
        fBaseURL = baseURL;
32
    }
32
    }
33
    
33
    
34
    public String getBaseURL() {
34
    public String getBaseURL() {
35
        return fBaseURL;
35
        return fBaseURL;
36
    }
36
    }
37
    
37
    
38
    public String getName() {
38
    public String getName() {
39
        return fName;
39
        return fName;
40
    }
40
    }
41
    
41
    
42
    public void setName(String name) {
42
    public void setName(String name) {
43
        fName = name;
43
        fName = name;
44
    }
44
    }
45
45
46
    /**
46
    public void setLoginCookie(String cookie) {
47
     * @param cookie
47
        this.fCookie = cookie;
48
     */
48
    }
49
    public void setLoginCookie(String cookie) {
49
50
        this.fCookie = cookie;
50
    public String getLoginCookie() {
51
    }
51
        return fCookie;
52
52
    }
53
    /**
53
    
54
     * @return
54
    
55
     */
55
	public int getVersion() {
56
    public String getLoginCookie() {
56
		return version;
57
        return fCookie;
57
	}
58
    }
58
	
59
    
59
	public void setVersion(int version) {
60
    
60
		this.version = version;
61
	public int getVersion() {
61
	}
62
		return version;
62
}
63
	}
64
	
65
	public void setVersion(int version) {
66
		this.version = version;
67
	}
68
}
(-)src/org/eclipse/team/bugzilla/datatypes/CommentData.java (-70 / +67 lines)
Lines 1-70 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.datatypes;
12
package org.eclipse.team.bugzilla.datatypes;
13
13
14
import java.util.Collection;
14
import java.util.Collection;
15
import java.util.LinkedHashSet;
15
import java.util.LinkedHashSet;
16
16
17
17
18
18
19
public class CommentData extends Data implements Comparable {
19
public class CommentData extends Data implements Comparable {
20
    
20
    
21
    public final static String AUTHOR= "0";
21
    public final static String AUTHOR= "0";
22
    public final static String DATE= "1";
22
    public final static String DATE= "1";
23
    public final static String TEXT= "2";
23
    public final static String TEXT= "2";
24
    
24
    
25
    private final static LinkedHashSet sSet;
25
    private final static LinkedHashSet sSet;
26
    
26
    
27
    static {
27
    static {
28
        sSet= new LinkedHashSet();
28
        sSet= new LinkedHashSet();
29
        sSet.add(AUTHOR);
29
        sSet.add(AUTHOR);
30
        sSet.add(DATE);
30
        sSet.add(DATE);
31
        sSet.add(TEXT);
31
        sSet.add(TEXT);
32
    }
32
    }
33
    
33
    
34
    public AttachmentDescription attachmentDesc;
34
    public AttachmentDescription attachmentDesc;
35
    
35
    
36
    public CommentData() {
36
    public CommentData() {
37
        attachmentDesc= null;
37
        attachmentDesc= null;
38
    }
38
    }
39
    
39
    
40
    public String toString() {
40
    public String toString() {
41
        final StringBuffer buffer= new StringBuffer();
41
        final StringBuffer buffer= new StringBuffer();
42
        final String nl= System.getProperty("line.separator"); //$NON-NLS-1$
42
        final String nl= System.getProperty("line.separator"); //$NON-NLS-1$
43
        buffer.append("Author: ").append(getString(AUTHOR)).append(nl); //$NON-NLS-1$
43
        buffer.append("Author: ").append(getString(AUTHOR)).append(nl); //$NON-NLS-1$
44
        buffer.append("Date: ").append(getString(DATE)).append(nl); //$NON-NLS-1$
44
        buffer.append("Date: ").append(getString(DATE)).append(nl); //$NON-NLS-1$
45
        buffer.append("Text: ").append(getString(TEXT)).append(nl); //$NON-NLS-1$
45
        buffer.append("Text: ").append(getString(TEXT)).append(nl); //$NON-NLS-1$
46
        return buffer.toString();
46
        return buffer.toString();
47
    }
47
    }
48
48
49
    public int compareTo(Object o) {
49
    public int compareTo(Object o) {
50
        return getDate(DATE).compareTo(((CommentData)o).getDate(DATE));
50
        return getDate(DATE).compareTo(((CommentData)o).getDate(DATE));
51
    }
51
    }
52
52
53
    public boolean equals(Object obj) {
53
    public boolean equals(Object obj) {
54
        if (!(obj instanceof CommentData))
54
        if (!(obj instanceof CommentData))
55
            return false;
55
            return false;
56
        final CommentData other = (CommentData)obj;
56
        final CommentData other = (CommentData)obj;
57
        return getString(TEXT).equals(other.getString(TEXT)) && getString(AUTHOR).equals(other.getString(AUTHOR)) && getDate(DATE).equals(other.getDate(DATE)); 
57
        return getString(TEXT).equals(other.getString(TEXT)) && getString(AUTHOR).equals(other.getString(AUTHOR)) && getDate(DATE).equals(other.getDate(DATE)); 
58
    }
58
    }
59
59
60
    protected Collection getKeys() {
60
    protected Collection getKeys() {
61
        return sSet;
61
        return sSet;
62
    }
62
    }
63
63
64
    /**
64
    public String getId() {
65
     * @return
65
        return getDate(DATE).toString();
66
     */
66
    }
67
    public String getId() {
67
}
68
        return getDate(DATE).toString();
69
    }
70
}
(-)src/org/eclipse/team/bugzilla/datatypes/Data.java (-99 / +99 lines)
Lines 1-99 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.datatypes;
12
package org.eclipse.team.bugzilla.datatypes;
13
13
14
import java.text.DateFormat;
14
import java.text.DateFormat;
15
import java.text.ParseException;
15
import java.text.ParseException;
16
import java.text.SimpleDateFormat;
16
import java.text.SimpleDateFormat;
17
import java.util.Collection;
17
import java.util.Collection;
18
import java.util.Date;
18
import java.util.Date;
19
import java.util.HashMap;
19
import java.util.HashMap;
20
20
21
/**
21
/**
22
 * 
22
 * 
23
 */
23
 */
24
public abstract class Data {
24
public abstract class Data {
25
    
25
    
26
    private final static DateFormat sDateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm"); //$NON-NLS-1$
26
    private final static DateFormat sDateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm"); //$NON-NLS-1$
27
    
27
    
28
    private final HashMap fValues;
28
    private final HashMap fValues;
29
    private final HashMap fChangedValues;
29
    private final HashMap fChangedValues;
30
30
31
    public Data() {
31
    public Data() {
32
        fValues= new HashMap();
32
        fValues= new HashMap();
33
        fChangedValues= new HashMap();
33
        fChangedValues= new HashMap();
34
    }
34
    }
35
35
36
    public void set(String key, String value) {
36
    public void set(String key, String value) {
37
        if (!getKeys().contains(key))
37
        if (!getKeys().contains(key))
38
            return;
38
            return;
39
        
39
        
40
        final String oldValue= (String)fValues.get(key);
40
        final String oldValue= (String)fValues.get(key);
41
        if (oldValue == null) {
41
        if (oldValue == null) {
42
            fValues.put(key, value);
42
            fValues.put(key, value);
43
            fChangedValues.remove(key);
43
            fChangedValues.remove(key);
44
        } else if (!oldValue.equals(value)) {
44
        } else if (!oldValue.equals(value)) {
45
            fChangedValues.put(key, value);
45
            fChangedValues.put(key, value);
46
        }
46
        }
47
    }
47
    }
48
48
49
    public void set(String key, Date date) {
49
    public void set(String key, Date date) {
50
        set(key, sDateFormat.format(date));
50
        set(key, sDateFormat.format(date));
51
    }
51
    }
52
    
52
    
53
    public void set(String key, boolean state) {
53
    public void set(String key, boolean state) {
54
        set(key, Boolean.valueOf(state).toString());
54
        set(key, Boolean.valueOf(state).toString());
55
    }
55
    }
56
    
56
    
57
    public String getString(String key) {
57
    public String getString(String key) {
58
        if (fChangedValues.containsKey(key))
58
        if (fChangedValues.containsKey(key))
59
            return (String)fChangedValues.get(key);
59
            return (String)fChangedValues.get(key);
60
        return (String)fValues.get(key);
60
        return (String)fValues.get(key);
61
    }
61
    }
62
    
62
    
63
    public Date getDate(String key) {
63
    public Date getDate(String key) {
64
        try {
64
        try {
65
            return sDateFormat.parse((String)fValues.get(key));
65
            return sDateFormat.parse((String)fValues.get(key));
66
        } catch (ParseException e) {
66
        } catch (ParseException e) {
67
            return null; // should not happen!
67
            return null; // should not happen!
68
        }
68
        }
69
    }
69
    }
70
    
70
    
71
    public boolean getBoolean(String key) {
71
    public boolean getBoolean(String key) {
72
        return Boolean.valueOf(getString(key)).booleanValue();
72
        return Boolean.valueOf(getString(key)).booleanValue();
73
    }
73
    }
74
    
74
    
75
    public boolean hasChanged(String key) {
75
    public boolean hasChanged(String key) {
76
        return fChangedValues.containsKey(key);        
76
        return fChangedValues.containsKey(key);        
77
    }
77
    }
78
    
78
    
79
    public boolean exists(String key) {
79
    public boolean exists(String key) {
80
        return fValues.containsKey(key);
80
        return fValues.containsKey(key);
81
    }
81
    }
82
    
82
    
83
    public void commitChanged() {
83
    public void commitChanged() {
84
        fValues.putAll(fChangedValues);
84
        fValues.putAll(fChangedValues);
85
    }
85
    }
86
    
86
    
87
    public void commitChanged(String key) {
87
    public void commitChanged(String key) {
88
        if (fChangedValues.containsKey(key)) {
88
        if (fChangedValues.containsKey(key)) {
89
            fValues.put(key, fChangedValues.get(key));
89
            fValues.put(key, fChangedValues.get(key));
90
        }
90
        }
91
    }
91
    }
92
    
92
    
93
    /**
93
    /**
94
     * Clients must implement this to define the set of keys which are allowed. Iteration and lookup 
94
     * Clients must implement this to define the set of keys which are allowed. Iteration and lookup 
95
     * should be fast, so a LinkedHashSet may be a good choice. 
95
     * should be fast, so a LinkedHashSet may be a good choice. 
96
     * @return
96
     * @return Collection
97
     */
97
     */
98
    protected abstract Collection getKeys();
98
    protected abstract Collection getKeys();
99
}
99
}
(-)src/org/eclipse/team/bugzilla/datatypes/DataCache.java (-274 / +270 lines)
Lines 1-274 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.bugzilla.datatypes;
11
package org.eclipse.team.bugzilla.datatypes;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collections;
15
import java.util.Collections;
16
import java.util.HashMap;
16
import java.util.HashMap;
17
import java.util.HashSet;
17
import java.util.HashSet;
18
import java.util.Iterator;
18
import java.util.Iterator;
19
import java.util.List;
19
import java.util.List;
20
import java.util.Map;
20
import java.util.Map;
21
import java.util.Set;
21
import java.util.Set;
22
22
23
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.ISafeRunnable;
24
import org.eclipse.core.runtime.ISafeRunnable;
25
import org.eclipse.core.runtime.MultiStatus;
25
import org.eclipse.core.runtime.MultiStatus;
26
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.jface.util.ListenerList;
27
import org.eclipse.jface.util.ListenerList;
28
import org.eclipse.team.bugs.extension.BugsException;
28
import org.eclipse.team.bugs.extension.BugsException;
29
import org.eclipse.team.bugzilla.BugzillaException;
29
import org.eclipse.team.bugzilla.BugzillaException;
30
import org.eclipse.team.bugzilla.BugzillaPlugin;
30
import org.eclipse.team.bugzilla.BugzillaPlugin;
31
import org.eclipse.team.bugzilla.model.BugzillaProvider;
31
import org.eclipse.team.bugzilla.model.BugzillaProvider;
32
import org.eclipse.team.bugzilla.model.BugzillaQueryOptions;
32
import org.eclipse.team.bugzilla.model.BugzillaQueryOptions;
33
import org.eclipse.team.bugzilla.model.IRemoteModel;
33
import org.eclipse.team.bugzilla.model.IRemoteModel;
34
import org.eclipse.team.bugzilla.operations.RefreshOperation;
34
import org.eclipse.team.bugzilla.operations.RefreshOperation;
35
35
36
/**
36
/**
37
 * Caches any data fetched from a bugzilla server
37
 * Caches any data fetched from a bugzilla server
38
 */
38
 */
39
public class DataCache {
39
public class DataCache {
40
    
40
    
41
    protected final BugzillaProvider fProvider; 
41
    protected final BugzillaProvider fProvider; 
42
    private final Map fReports;
42
    private final Map fReports;
43
    private final Map fAttachments;
43
    private final Map fAttachments;
44
    private final Map fQueries;
44
    private final Map fQueries;
45
    
45
    
46
    private final Set fReportErrors;
46
    private final Set fReportErrors;
47
    private final Set fAttachmentErrors;
47
    private final Set fAttachmentErrors;
48
    private final Set fQueryErrors;
48
    private final Set fQueryErrors;
49
    
49
    
50
    private final BugzillaQueryOptions queryOptions;
50
    private final BugzillaQueryOptions queryOptions;
51
    
51
    
52
    private ListenerList fListeners = new ListenerList();
52
    private ListenerList fListeners = new ListenerList();
53
    
53
    
54
    public DataCache(BugzillaProvider provider) {
54
    public DataCache(BugzillaProvider provider) {
55
        fProvider = provider;
55
        fProvider = provider;
56
        
56
        
57
        fReports= Collections.synchronizedMap(new HashMap());
57
        fReports= Collections.synchronizedMap(new HashMap());
58
        fAttachments= Collections.synchronizedMap(new HashMap());
58
        fAttachments= Collections.synchronizedMap(new HashMap());
59
        fQueries= Collections.synchronizedMap(new HashMap());
59
        fQueries= Collections.synchronizedMap(new HashMap());
60
        
60
        
61
        fReportErrors= Collections.synchronizedSet(new HashSet());
61
        fReportErrors= Collections.synchronizedSet(new HashSet());
62
        fAttachmentErrors = Collections.synchronizedSet(new HashSet());
62
        fAttachmentErrors = Collections.synchronizedSet(new HashSet());
63
        fQueryErrors= Collections.synchronizedSet(new HashSet());
63
        fQueryErrors= Collections.synchronizedSet(new HashSet());
64
        
64
        
65
        /* TODO: jpound - cache query options */
65
        /* TODO: jpound - cache query options */
66
        queryOptions = new BugzillaQueryOptions(provider.getBaseURL());
66
        queryOptions = new BugzillaQueryOptions(provider.getBaseURL());
67
    }
67
    }
68
68
69
    /**
69
    /**
70
     * Return the cached report data for the given bug id.
70
     * Return the cached report data for the given bug id.
71
     * If no data is cached, <code>null</code> is returned.
71
     * If no data is cached, <code>null</code> is returned.
72
     * @param id the bug id
72
     * @param id the bug id
73
     * @return the cached ReportData or <code>null</code>
73
     * @return the cached ReportData or <code>null</code>
74
     */
74
     */
75
    public ReportData getReport(String id) {
75
    public ReportData getReport(String id) {
76
        return (ReportData)fReports.get(id);
76
        return (ReportData)fReports.get(id);
77
    }
77
    }
78
78
79
    /**
79
    /**
80
     * Return the cached attachment for the given id.
80
     * Return the cached attachment for the given id.
81
     * If no attachment is cached, <code>null</code> is returned.
81
     * If no attachment is cached, <code>null</code> is returned.
82
     * @param desc the attachment id
82
     * @param desc the attachment id
83
     * @return the cached attachment or <code>null</code>
83
     * @return the cached attachment or <code>null</code>
84
     */
84
     */
85
    public AttachmentData getAttachment(AttachmentDescription desc) {
85
    public AttachmentData getAttachment(AttachmentDescription desc) {
86
        return (AttachmentData)fAttachments.get(desc);
86
        return (AttachmentData)fAttachments.get(desc);
87
    }
87
    }
88
    
88
    
89
    public void refreshReports(String[] reportIds, IProgressMonitor monitor) throws BugzillaException {
89
    public void refreshReports(String[] reportIds, IProgressMonitor monitor) throws BugzillaException {
90
        List errors = new ArrayList();
90
        List errors = new ArrayList();
91
        for (int i = 0; i < reportIds.length; i++) {
91
        for (int i = 0; i < reportIds.length; i++) {
92
            String id = reportIds[i];
92
            String id = reportIds[i];
93
            try {
93
            try {
94
                ReportData data = fProvider.getOperations().getReportData(monitor, id);
94
                ReportData data = fProvider.getOperations().getReportData(monitor, id);
95
                add(data);
95
                add(data);
96
                fReportErrors.remove(id);
96
                fReportErrors.remove(id);
97
            } catch (BugzillaException e) {
97
            } catch (BugzillaException e) {
98
                errors.add(e);
98
                errors.add(e);
99
                fReportErrors.add(id);
99
                fReportErrors.add(id);
100
            }
100
            }
101
        }
101
        }
102
        fireReportDataChanged(reportIds);
102
        fireReportDataChanged(reportIds);
103
        handleErrors(errors);
103
        handleErrors(errors);
104
    }
104
    }
105
    
105
    
106
    private void handleErrors(List errors) throws BugzillaException {
106
    private void handleErrors(List errors) throws BugzillaException {
107
        if (errors.size() == 1) {
107
        if (errors.size() == 1) {
108
            throw (BugzillaException)errors.get(0);
108
            throw (BugzillaException)errors.get(0);
109
        } else if (!errors.isEmpty()) {
109
        } else if (!errors.isEmpty()) {
110
            MultiStatus status = new MultiStatus(BugzillaPlugin.ID, 0, "Errors occured during refresh", null);
110
            MultiStatus status = new MultiStatus(BugzillaPlugin.ID, 0, "Errors occured during refresh", null);
111
            for (Iterator iter = errors.iterator(); iter.hasNext();) {
111
            for (Iterator iter = errors.iterator(); iter.hasNext();) {
112
                BugsException e = (BugsException) iter.next();
112
                BugsException e = (BugsException) iter.next();
113
                status.add(e.getStatus());
113
                status.add(e.getStatus());
114
                throw new BugzillaException(status);
114
                throw new BugzillaException(status);
115
            }
115
            }
116
        }
116
        }
117
        
117
        
118
    }
118
    }
119
119
120
    public void refreshAttachments(AttachmentDescription[] descs, IProgressMonitor monitor) throws BugzillaException {
120
    public void refreshAttachments(AttachmentDescription[] descs, IProgressMonitor monitor) throws BugzillaException {
121
        List errors = new ArrayList();
121
        List errors = new ArrayList();
122
        for (int i = 0; i < descs.length; i++) {
122
        for (int i = 0; i < descs.length; i++) {
123
            AttachmentDescription desc = descs[i];
123
            AttachmentDescription desc = descs[i];
124
            try {
124
            try {
125
                AttachmentData data = fProvider.getOperations().getAttachment(monitor, desc);
125
                AttachmentData data = fProvider.getOperations().getAttachment(monitor, desc);
126
                add(desc, data);
126
                add(desc, data);
127
                fAttachmentErrors.remove(desc);
127
                fAttachmentErrors.remove(desc);
128
            } catch (BugzillaException e) {
128
            } catch (BugzillaException e) {
129
                errors.add(e);
129
                errors.add(e);
130
                fAttachmentErrors.add(desc);
130
                fAttachmentErrors.add(desc);
131
            }
131
            }
132
        }
132
        }
133
        fireAttachmentDataChanged(descs);
133
        fireAttachmentDataChanged(descs);
134
        handleErrors(errors);
134
        handleErrors(errors);
135
    }
135
    }
136
    
136
    
137
    private void add(AttachmentDescription desc, AttachmentData data) {
137
    private void add(AttachmentDescription desc, AttachmentData data) {
138
        fAttachments.put(desc, data);     
138
        fAttachments.put(desc, data);     
139
    }
139
    }
140
140
141
    private void fireAttachmentDataChanged(final AttachmentDescription[] descs) {
141
    private void fireAttachmentDataChanged(final AttachmentDescription[] descs) {
142
        Object[] allListeners = fListeners.getListeners();
142
        Object[] allListeners = fListeners.getListeners();
143
        for (int i = 0; i < allListeners.length; i++) {
143
        for (int i = 0; i < allListeners.length; i++) {
144
            final IBugRefreshListener listener = (IBugRefreshListener)allListeners[i];
144
            final IBugRefreshListener listener = (IBugRefreshListener)allListeners[i];
145
            Platform.run(new ISafeRunnable() {
145
            Platform.run(new ISafeRunnable() {
146
                public void handleException(Throwable exception) {
146
                public void handleException(Throwable exception) {
147
                }
147
                }
148
                public void run() throws Exception {
148
                public void run() throws Exception {
149
                    listener.attachmentsChanged(fProvider, descs);
149
                    listener.attachmentsChanged(fProvider, descs);
150
                }
150
                }
151
            });
151
            });
152
        }
152
        }
153
    }
153
    }
154
154
155
    private void fireReportDataChanged(final String[] reportIds) {
155
    private void fireReportDataChanged(final String[] reportIds) {
156
        Object[] allListeners = fListeners.getListeners();
156
        Object[] allListeners = fListeners.getListeners();
157
        for (int i = 0; i < allListeners.length; i++) {
157
        for (int i = 0; i < allListeners.length; i++) {
158
            final IBugRefreshListener listener = (IBugRefreshListener)allListeners[i];
158
            final IBugRefreshListener listener = (IBugRefreshListener)allListeners[i];
159
            Platform.run(new ISafeRunnable() {
159
            Platform.run(new ISafeRunnable() {
160
                public void handleException(Throwable exception) {
160
                public void handleException(Throwable exception) {
161
                    // Logged by Core
161
                    // Logged by Core
162
                }
162
                }
163
                public void run() throws Exception {
163
                public void run() throws Exception {
164
                    listener.reportDataChange(fProvider, reportIds);
164
                    listener.reportDataChange(fProvider, reportIds);
165
                }
165
                }
166
            });
166
            });
167
        }
167
        }
168
    }
168
    }
169
169
170
    private void add(ReportData data) {
170
    private void add(ReportData data) {
171
        fReports.put(data.getString(ReportData.ID), data);
171
        fReports.put(data.getString(ReportData.ID), data);
172
    }
172
    }
173
    
173
    
174
	public void addRefreshListener(IBugRefreshListener listener) {
174
	public void addRefreshListener(IBugRefreshListener listener) {
175
		fListeners.add(listener);
175
		fListeners.add(listener);
176
	}
176
	}
177
177
178
	public void removeRefreshListener(IBugRefreshListener listener) {
178
	public void removeRefreshListener(IBugRefreshListener listener) {
179
		fListeners.remove(listener);
179
		fListeners.remove(listener);
180
	}
180
	}
181
181
182
    /**
182
    /**
183
     * @param datas
183
     * @param datas
184
     * @param monitor
184
     * @param monitor
185
     */
185
     */
186
    public void refreshQuery(QueryURL[] datas, IProgressMonitor monitor) throws BugzillaException {
186
    public void refreshQuery(QueryURL[] datas, IProgressMonitor monitor) throws BugzillaException {
187
        List errors = new ArrayList();
187
        List errors = new ArrayList();
188
        for (int i = 0; i < datas.length; i++) {
188
        for (int i = 0; i < datas.length; i++) {
189
            QueryURL url = datas[i];
189
            QueryURL url = datas[i];
190
            try {
190
            try {
191
                QueryData data = fProvider.getOperations().getQueryData(monitor, url);
191
                QueryData data = fProvider.getOperations().getQueryData(monitor, url);
192
                if (data == null) {
192
                if (data == null) {
193
                	return;
193
                	return;
194
                }
194
                }
195
                add(url, data);
195
                add(url, data);
196
                fQueryErrors.remove(url);
196
                fQueryErrors.remove(url);
197
            } catch (BugzillaException e) {
197
            } catch (BugzillaException e) {
198
                errors.add(e);
198
                errors.add(e);
199
                fQueryErrors.add(url);
199
                fQueryErrors.add(url);
200
            }
200
            }
201
        }
201
        }
202
        fireQueryChanged(datas);
202
        fireQueryChanged(datas);
203
        handleErrors(errors);
203
        handleErrors(errors);
204
    }
204
    }
205
205
206
    private void fireQueryChanged(final QueryURL[] datas) {
206
    private void fireQueryChanged(final QueryURL[] datas) {
207
        Object[] allListeners = fListeners.getListeners();
207
        Object[] allListeners = fListeners.getListeners();
208
        for (int i = 0; i < allListeners.length; i++) {
208
        for (int i = 0; i < allListeners.length; i++) {
209
            final IBugRefreshListener listener = (IBugRefreshListener)allListeners[i];
209
            final IBugRefreshListener listener = (IBugRefreshListener)allListeners[i];
210
            Platform.run(new ISafeRunnable() {
210
            Platform.run(new ISafeRunnable() {
211
                public void handleException(Throwable exception) {
211
                public void handleException(Throwable exception) {
212
                    // Logged by Core
212
                    // Logged by Core
213
                }
213
                }
214
                public void run() throws Exception {
214
                public void run() throws Exception {
215
                    listener.queryChange(fProvider, datas);
215
                    listener.queryChange(fProvider, datas);
216
                }
216
                }
217
            });
217
            });
218
        }
218
        }
219
    }
219
    }
220
220
221
    private void add(QueryURL url, QueryData data) {
221
    private void add(QueryURL url, QueryData data) {
222
        fQueries.put(url, data);
222
        fQueries.put(url, data);
223
        ReportData[] datas = data.getReportDatas();
223
        ReportData[] datas = data.getReportDatas();
224
        for (int i = 0; i < datas.length; i++) {
224
        for (int i = 0; i < datas.length; i++) {
225
            ReportData report = datas[i];
225
            ReportData report = datas[i];
226
            if (getReport(report.getString(ReportData.ID)) == null) {
226
            if (getReport(report.getString(ReportData.ID)) == null) {
227
                add(report);
227
                add(report);
228
            }
228
            }
229
        }
229
        }
230
    }
230
    }
231
231
232
    /**
232
    public QueryData getQueryData(QueryURL queryUrl) {
233
     * @param queryUrl
233
        return (QueryData)fQueries.get(queryUrl);
234
     * @return
234
    }
235
     */
235
    
236
    public QueryData getQueryData(QueryURL queryUrl) {
236
    public boolean hadErrorsForReport(String id) {
237
        return (QueryData)fQueries.get(queryUrl);
237
        return fReportErrors.contains(id);
238
    }
238
    }
239
    
239
    
240
    public boolean hadErrorsForReport(String id) {
240
    public boolean hadErrorsForQuery(QueryURL url) {
241
        return fReportErrors.contains(id);
241
        return fQueryErrors.contains(url);
242
    }
242
    }
243
    
243
    
244
    public boolean hadErrorsForQuery(QueryURL url) {
244
    public boolean hadErrorsForAttachment(AttachmentDescription desc) {
245
        return fQueryErrors.contains(url);
245
        return fAttachmentErrors.contains(desc);
246
    }
246
    }
247
    
247
    
248
    public boolean hadErrorsForAttachment(AttachmentDescription desc) {
248
    /**
249
        return fAttachmentErrors.contains(desc);
249
     * 
250
    }
250
     * @return The query options for this bugzilla database.
251
    
251
     */
252
    /**
252
    public BugzillaQueryOptions getQueryOptions() {
253
     * 
253
    	return queryOptions;
254
     * @return The query options for this bugzilla database.
254
    }
255
     */
255
256
    public BugzillaQueryOptions getQueryOptions() {
256
	/**
257
    	return queryOptions;
257
	 * 
258
    }
258
	 */
259
259
	public void refreshQueryOptions() {
260
	/**
260
		try {
261
	 * 
261
			new RefreshOperation(null, new IRemoteModel[] { getQueryOptions() }).run();
262
	 */
262
		} catch (InvocationTargetException e) {
263
	public void refreshQueryOptions() {
263
			System.err.println("InvocationTargetException");
264
		try {
264
			//handleError(e);
265
			new RefreshOperation(null, new IRemoteModel[] { getQueryOptions() }).run();
265
		} catch (InterruptedException e) {
266
		} catch (InvocationTargetException e) {
266
			System.err.println("InterruptedException");
267
			System.err.println("InvocationTargetException");
267
			// Ignore
268
			//handleError(e);
268
		}
269
		} catch (InterruptedException e) {
269
	}
270
			System.err.println("InterruptedException");
270
}
271
			// Ignore
272
		}
273
	}
274
}
(-)src/org/eclipse/team/bugzilla/datatypes/QueryURL.java (-207 / +204 lines)
Lines 1-207 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.bugzilla.datatypes;
11
package org.eclipse.team.bugzilla.datatypes;
12
12
13
import java.io.UnsupportedEncodingException;
13
import java.io.UnsupportedEncodingException;
14
import java.net.URLDecoder;
14
import java.net.URLDecoder;
15
import java.net.URLEncoder;
15
import java.net.URLEncoder;
16
import java.util.Iterator;
16
import java.util.Iterator;
17
import java.util.LinkedList;
17
import java.util.LinkedList;
18
import java.util.List;
18
import java.util.List;
19
import java.util.Set;
19
import java.util.Set;
20
20
21
import org.eclipse.team.bugzilla.Util;
21
import org.eclipse.team.bugzilla.Util;
22
22
23
23
24
/**
24
/**
25
 * Wrapper for a bugzilla query URL
25
 * Wrapper for a bugzilla query URL
26
 */
26
 */
27
public class QueryURL extends BugzillaTransactionURL {
27
public class QueryURL extends BugzillaTransactionURL {
28
	
28
	
29
	public QueryURL(String baseUrl) {
29
	public QueryURL(String baseUrl) {
30
		super(baseUrl);
30
		super(baseUrl);
31
		
31
		
32
		script = "buglist.cgi?";
32
		script = "buglist.cgi?";
33
		
33
		
34
		// initiallize default parameter settings
34
		// initiallize default parameter settings
35
		addTransactionParam("format", "rdf");
35
		addTransactionParam("format", "rdf");
36
		addTransactionParam("search", "Search");
36
		addTransactionParam("search", "Search");
37
	}
37
	}
38
	
38
	
39
	
39
	
40
	/* (non-Javadoc)
40
	/* (non-Javadoc)
41
	 * @see java.lang.Object#equals(java.lang.Object)
41
	 * @see java.lang.Object#equals(java.lang.Object)
42
	 */
42
	 */
43
	public boolean equals(Object obj) {
43
	public boolean equals(Object obj) {
44
		if (obj instanceof QueryURL) {
44
		if (obj instanceof QueryURL) {
45
			return toUrlString().equals(((QueryURL)obj).toUrlString());
45
			return toUrlString().equals(((QueryURL)obj).toUrlString());
46
		}
46
		}
47
		return super.equals(obj);
47
		return super.equals(obj);
48
	}
48
	}
49
	
49
	
50
	/* (non-Javadoc)
50
	/* (non-Javadoc)
51
	 * @see java.lang.Object#hashCode()
51
	 * @see java.lang.Object#hashCode()
52
	 */
52
	 */
53
	public int hashCode() {
53
	public int hashCode() {
54
		return toUrlString().hashCode();
54
		return toUrlString().hashCode();
55
	}
55
	}
56
	
56
	
57
	// generate the query string (.cgi) from the parameter set
57
	// generate the query string (.cgi) from the parameter set
58
	protected String generateTransactionString() {
58
	protected String generateTransactionString() {
59
		
59
		
60
		if (url.equals("")) {
60
		if (url.equals("")) {
61
			System.err.println("BugzillaAction: No URL defined for action");
61
			System.err.println("BugzillaAction: No URL defined for action");
62
			return url;
62
			return url;
63
		}
63
		}
64
		/* A QueryURL object is being created from an already existing query url */
64
		/* A QueryURL object is being created from an already existing query url */
65
		int index;
65
		int index;
66
		if ( (index = url.indexOf(script)) >= 0) {
66
		if ( (index = url.indexOf(script)) >= 0) {
67
			transUrl = url;
67
			transUrl = url;
68
			if (transUrl.endsWith("/")) {
68
			if (transUrl.endsWith("/")) {
69
				transUrl = transUrl.substring(0, transUrl.lastIndexOf("/"));
69
				transUrl = transUrl.substring(0, transUrl.lastIndexOf("/"));
70
			}
70
			}
71
			url = url.substring(0, index);
71
			url = url.substring(0, index);
72
			return transUrl;
72
			return transUrl;
73
		}
73
		}
74
		
74
		
75
		transUrl = url + script;
75
		transUrl = url + script;
76
		Iterator fieldIter = ((Set)params.keySet()).iterator();
76
		Iterator fieldIter = ((Set)params.keySet()).iterator();
77
		
77
		
78
		try {
78
		try {
79
			while (fieldIter.hasNext()) {
79
			while (fieldIter.hasNext()) {
80
				String field = (String)fieldIter.next();
80
				String field = (String)fieldIter.next();
81
				Iterator paramIter = ((List)params.get(field)).iterator();
81
				Iterator paramIter = ((List)params.get(field)).iterator();
82
				
82
				
83
				while(paramIter.hasNext()) {
83
				while(paramIter.hasNext()) {
84
					String value = URLEncoder.encode((String)paramIter.next(), "UTF-8");
84
					String value = URLEncoder.encode((String)paramIter.next(), "UTF-8");
85
					transUrl += "&" + field + "=" + value;
85
					transUrl += "&" + field + "=" + value;
86
				}
86
				}
87
			}
87
			}
88
		} catch (UnsupportedEncodingException e) {
88
		} catch (UnsupportedEncodingException e) {
89
			e.printStackTrace();
89
			e.printStackTrace();
90
		}
90
		}
91
		
91
		
92
		return transUrl;
92
		return transUrl;
93
	}
93
	}
94
	
94
	
95
	// add the specified 'param' to the list mapped to by 'field'
95
	// add the specified 'param' to the list mapped to by 'field'
96
	public void addTransactionParam(String field, String param) {
96
	public void addTransactionParam(String field, String param) {
97
		if (param == null) {
97
		if (param == null) {
98
			return;
98
			return;
99
		}
99
		}
100
100
101
		List parameters = (List)params.get(field);
101
		List parameters = (List)params.get(field);
102
		
102
		
103
		if(parameters == null) {
103
		if(parameters == null) {
104
			parameters = new LinkedList();
104
			parameters = new LinkedList();
105
			params.put(field, parameters);
105
			params.put(field, parameters);
106
		}
106
		}
107
		
107
		
108
		parameters.add(param.trim());
108
		parameters.add(param.trim());
109
	}
109
	}
110
	
110
	
111
	// set param fields. These fields can map to ONLY 1 value.
111
	// set param fields. These fields can map to ONLY 1 value.
112
	public void setFormatType(String type) {
112
	public void setFormatType(String type) {
113
		params.put("format", null);     	 	// clear any previous value
113
		params.put("format", null);     	 	// clear any previous value
114
		addTransactionParam("format", type); 	// set the new value (only one value allowed for this type)
114
		addTransactionParam("format", type); 	// set the new value (only one value allowed for this type)
115
	}
115
	}
116
	
116
	
117
	public void setSearchType(String type) {
117
	public void setSearchType(String type) {
118
		params.put("search", null);     		// clear any previous value
118
		params.put("search", null);     		// clear any previous value
119
		addTransactionParam("search", type); 	// set the new value (only one value allowed for this type)
119
		addTransactionParam("search", type); 	// set the new value (only one value allowed for this type)
120
	}
120
	}
121
	
121
	
122
	public void setShorDescType(String type) {
122
	public void setShorDescType(String type) {
123
		params.put("short_desc_type", null);     		// clear any previous value
123
		params.put("short_desc_type", null);     		// clear any previous value
124
		addTransactionParam("short_desc_type", type); 	// set the new value (only one value allowed for this type)
124
		addTransactionParam("short_desc_type", type); 	// set the new value (only one value allowed for this type)
125
	}
125
	}
126
	
126
	
127
	public void setLongDescType(String type) { 
127
	public void setLongDescType(String type) { 
128
		params.put("long_desc_type", null);     		// clear any previous value
128
		params.put("long_desc_type", null);     		// clear any previous value
129
		addTransactionParam("long_desc_type", type); 	// set the new value (only one value allowed for this type)
129
		addTransactionParam("long_desc_type", type); 	// set the new value (only one value allowed for this type)
130
	}
130
	}
131
	
131
	
132
	public String getFormatType() {
132
	public String getFormatType() {
133
		return (String)((List)params.get("format")).get(0);
133
		return (String)((List)params.get("format")).get(0);
134
	}
134
	}
135
	
135
	
136
	/**
136
	public String toUrlString() {
137
	 * @return
137
		return (transUrl.equals("")) ? generateTransactionString() : transUrl;
138
	 */
138
	}
139
	public String toUrlString() {
139
	
140
		return (transUrl.equals("")) ? generateTransactionString() : transUrl;
140
	/**
141
	}
141
	 * Return the url that will execute the query and return XML
142
	
142
	 * @param configuration the configuration which identifies the bugzilla server
143
	/**
143
	 * @return the URL that executes this query
144
	 * Return the url that will execute the query and return XML
144
	 */
145
	 * @param configuration the configuration which identifies the bugzilla server
145
	public final String getUrl(BugzillaConfiguration configuration) {
146
	 * @return the URL that executes this query
146
		return getUrlString(configuration);
147
	 */
147
	}
148
	public final String getUrl(BugzillaConfiguration configuration) {
148
	
149
		return getUrlString(configuration);
149
	/**
150
	}
150
	 * Build the string that is the URL to perform the query
151
	
151
	 * @param configuration the configuration which identifies the bugzilla server
152
	/**
152
	 * @return a String that is a valid URL
153
	 * Build the string that is the URL to perform the query
153
	 */
154
	 * @param configuration the configuration which identifies the bugzilla server
154
	protected String getUrlString(BugzillaConfiguration configuration) {
155
	 * @return a String that is a valid URL
155
		String urlString = Util.appendPath(configuration.getBaseURL(), toUrlString());
156
	 */
156
		return urlString;
157
	protected String getUrlString(BugzillaConfiguration configuration) {
157
	}
158
		String urlString = Util.appendPath(configuration.getBaseURL(), toUrlString());
158
	
159
		return urlString;
159
	/**
160
	}
160
	 * Returns the base url of the bugzilla database
161
	
161
	 * @return The base url of the bugzilla database
162
	/**
162
	 */
163
	 * Returns the base url of the bugzilla database
163
	public String getBaseUrl() {
164
	 * @return The base url of the bugzilla database
164
		return url;
165
	 */
165
	}
166
	public String getBaseUrl() {
166
	
167
		return url;
167
	/**
168
	}
168
	 * Return whether the query is a named query which requires
169
	
169
	 * a login.
170
	/**
170
	 * @return whether the query is a named query
171
	 * Return whether the query is a named query which requires
171
	 */
172
	 * a login.
172
	public boolean isNamedQuery() {
173
	 * @return whether the query is a named query
173
		return transUrl.indexOf("cmdtype=runnamed") != -1;
174
	 */
174
	}
175
	public boolean isNamedQuery() {
175
	
176
		return transUrl.indexOf("cmdtype=runnamed") != -1;
176
	/**
177
	}
177
	 * @return login cookie
178
	
178
	 */
179
	/**
179
	public String getLoginCookie() {
180
	 * @return
180
		// TODO Auto-generated method stub
181
	 */
181
		return null;
182
	public String getLoginCookie() {
182
	}
183
		// TODO Auto-generated method stub
183
	
184
		return null;
184
	/**
185
	}
185
	 * Return an appropriate name for the query
186
	
186
	 * @return an appropriate name for the query
187
	/**
187
	 */
188
	 * Return an appropriate name for the query
188
	public String getName() {
189
	 * @return an appropriate name for the query
189
		if (isNamedQuery()) {
190
	 */
190
			String key = "namedcmd="; //$NON-NLS-1$
191
	public String getName() {
191
			int start = transUrl.indexOf(key);
192
		if (isNamedQuery()) {
192
			if (start != -1) {
193
			String key = "namedcmd="; //$NON-NLS-1$
193
				start += key.length();
194
			int start = transUrl.indexOf(key);
194
			}
195
			if (start != -1) {
195
			String name = transUrl.substring(start);
196
				start += key.length();
196
			try {
197
			}
197
				return URLDecoder.decode(name, "UTF-8"); //$NON-NLS-1$
198
			String name = transUrl.substring(start);
198
			} catch (UnsupportedEncodingException e) {
199
			try {
199
				// Ignore
200
				return URLDecoder.decode(name, "UTF-8"); //$NON-NLS-1$
200
			}
201
			} catch (UnsupportedEncodingException e) {
201
		}
202
				// Ignore
202
		return transUrl;
203
			}
203
	}
204
		}
204
}
205
		return transUrl;
206
	}
207
}
(-)src/org/eclipse/team/bugzilla/dialogs/AddQueryDialog.java (-4 / +1 lines)
Lines 801-808 Link Here
801
	}
801
	}
802
	
802
	
803
	/**
803
	/**
804
	 * @param searchGroup
804
	 * @param group
805
	 * @return
806
	 */
805
	 */
807
	private Combo createSearchTypeCombo(Composite group) {
806
	private Combo createSearchTypeCombo(Composite group) {
808
		Combo combo = new Combo(group, SWT.READ_ONLY);
807
		Combo combo = new Combo(group, SWT.READ_ONLY);
Lines 839-847 Link Here
839
	}
838
	}
840
	
839
	
841
	/**
840
	/**
842
	 * 
843
	 * @param group
841
	 * @param group
844
	 * @return
845
	 */
842
	 */
846
	private List createList(Composite group) {
843
	private List createList(Composite group) {
847
		GridData smallVertData = new GridData(SWT.FILL, SWT.FILL, true, true);
844
		GridData smallVertData = new GridData(SWT.FILL, SWT.FILL, true, true);
(-)src/org/eclipse/team/bugzilla/model/BugzillaContainer.java (-169 / +169 lines)
Lines 1-169 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.model;
12
package org.eclipse.team.bugzilla.model;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Iterator;
15
import java.util.Iterator;
16
import java.util.LinkedHashMap;
16
import java.util.LinkedHashMap;
17
import java.util.List;
17
import java.util.List;
18
import java.util.Map;
18
import java.util.Map;
19
19
20
import org.eclipse.team.bugzilla.BugzillaException;
20
import org.eclipse.team.bugzilla.BugzillaException;
21
21
22
/**
22
/**
23
 * A generic model element container
23
 * A generic model element container
24
 */
24
 */
25
public abstract class BugzillaContainer extends BugzillaModel {
25
public abstract class BugzillaContainer extends BugzillaModel {
26
26
27
    private Map fChildren;
27
    private Map fChildren;
28
    
28
    
29
    public BugzillaContainer() {
29
    public BugzillaContainer() {
30
        super();
30
        super();
31
        fChildren= new LinkedHashMap();
31
        fChildren= new LinkedHashMap();
32
    }
32
    }
33
33
34
    public BugzillaModel[] getChildren() {
34
    public BugzillaModel[] getChildren() {
35
        return (BugzillaModel[]) fChildren.values().toArray(new BugzillaModel[fChildren.size()]);
35
        return (BugzillaModel[]) fChildren.values().toArray(new BugzillaModel[fChildren.size()]);
36
    }
36
    }
37
    
37
    
38
    /**
38
    /**
39
     * Add a child to this container and set the child's path correctly. If this
39
     * Add a child to this container and set the child's path correctly. If this
40
     * container already contains a child with the same ID, the existing child
40
     * container already contains a child with the same ID, the existing child
41
     * is removed and replaced by the new one. This method assumes that
41
     * is removed and replaced by the new one. This method assumes that
42
     * <code>isReadOnly()</code> has been checked before, if applicable, and
42
     * <code>isReadOnly()</code> has been checked before, if applicable, and
43
     * thus inserts new children regardless of this property. A <code>childAdded</code> event
43
     * thus inserts new children regardless of this property. A <code>childAdded</code> event
44
     * is fired after the child has been inserted.
44
     * is fired after the child has been inserted.
45
     * 
45
     * 
46
     * @param child The child to be added.
46
     * @param children The children to be added.
47
     */
47
     */
48
    public void addChildren(BugzillaModel [] children) {
48
    public void addChildren(BugzillaModel [] children) {
49
        
49
        
50
        if (children.length == 0)
50
        if (children.length == 0)
51
            return;
51
            return;
52
        
52
        
53
        final List existing= new ArrayList();
53
        final List existing= new ArrayList();
54
        for (int i = 0; i < children.length; i++) {
54
        for (int i = 0; i < children.length; i++) {
55
            final BugzillaModel child= children[i];
55
            final BugzillaModel child= children[i];
56
            if (contains(child)) {
56
            if (contains(child)) {
57
                existing.add(fChildren.get(child.getID()));
57
                existing.add(fChildren.get(child.getID()));
58
            }
58
            }
59
        }
59
        }
60
        removeChildren((BugzillaModel [])existing.toArray(new BugzillaModel [existing.size()]));
60
        removeChildren((BugzillaModel [])existing.toArray(new BugzillaModel [existing.size()]));
61
        
61
        
62
        for (int i = 0; i < children.length; i++) {
62
        for (int i = 0; i < children.length; i++) {
63
            final BugzillaModel child= children[i];
63
            final BugzillaModel child= children[i];
64
            child.setParent(this);
64
            child.setParent(this);
65
            fChildren.put(child.getID(), child);
65
            fChildren.put(child.getID(), child);
66
        }
66
        }
67
        fireChildrenAdded(children);
67
        fireChildrenAdded(children);
68
    }
68
    }
69
    
69
    
70
    public boolean contains(String id) {
70
    public boolean contains(String id) {
71
        return fChildren.containsKey(id);
71
        return fChildren.containsKey(id);
72
    }
72
    }
73
    
73
    
74
    public boolean contains(BugzillaModel child) {
74
    public boolean contains(BugzillaModel child) {
75
        return contains(child.getID()) && getChild(child.getID()) == child;
75
        return contains(child.getID()) && getChild(child.getID()) == child;
76
    }
76
    }
77
77
78
    /**
78
    /**
79
     * Remove a child from this container. The child's parent is set to null
79
     * Remove a child from this container. The child's parent is set to null
80
     * and a <code>childRemoved</code> event is fired.
80
     * and a <code>childRemoved</code> event is fired.
81
     * @param child The child to be removed.
81
     * @param children The childrem to be removed.
82
     */
82
     */
83
    public void removeChildren(BugzillaModel [] children) {
83
    public void removeChildren(BugzillaModel [] children) {
84
        
84
        
85
        if (children.length == 0)
85
        if (children.length == 0)
86
            return;
86
            return;
87
        
87
        
88
        final List removed= new ArrayList();
88
        final List removed= new ArrayList();
89
        for (int i = 0; i < children.length; i++) {
89
        for (int i = 0; i < children.length; i++) {
90
            final BugzillaModel child = children[i];
90
            final BugzillaModel child = children[i];
91
            if (!contains(child)) 
91
            if (!contains(child)) 
92
                continue;
92
                continue;
93
            fChildren.remove(child.getID());
93
            fChildren.remove(child.getID());
94
            child.setParent(null);
94
            child.setParent(null);
95
            removed.add(child);
95
            removed.add(child);
96
        }
96
        }
97
        fireChildrenRemoved((BugzillaModel [])removed.toArray(new BugzillaModel [removed.size()]));
97
        fireChildrenRemoved((BugzillaModel [])removed.toArray(new BugzillaModel [removed.size()]));
98
    }
98
    }
99
    
99
    
100
    public void setRefreshing(boolean refreshing) {
100
    public void setRefreshing(boolean refreshing) {
101
        if (isRefreshing() == refreshing) 
101
        if (isRefreshing() == refreshing) 
102
            return;
102
            return;
103
        super.setRefreshing(refreshing);
103
        super.setRefreshing(refreshing);
104
        setChildrenRefreshing(refreshing);
104
        setChildrenRefreshing(refreshing);
105
    }
105
    }
106
    
106
    
107
    /**
107
    /**
108
     * @param refreshing
108
     * @param refreshing
109
     */
109
     */
110
    protected void setChildrenRefreshing(boolean refreshing) {
110
    protected void setChildrenRefreshing(boolean refreshing) {
111
        for (final Iterator iter = fChildren.values().iterator(); iter.hasNext();) {
111
        for (final Iterator iter = fChildren.values().iterator(); iter.hasNext();) {
112
            ((BugzillaModel)iter.next()).setRefreshing(refreshing);
112
            ((BugzillaModel)iter.next()).setRefreshing(refreshing);
113
        }
113
        }
114
    }
114
    }
115
115
116
    public boolean hasParent(Object candiate) {
116
    public boolean hasParent(Object candiate) {
117
        
117
        
118
        final BugzillaContainer parent= (BugzillaContainer)getParent();
118
        final BugzillaContainer parent= (BugzillaContainer)getParent();
119
        if (parent == null)
119
        if (parent == null)
120
            return false;
120
            return false;
121
                
121
                
122
        return this == candiate || parent.hasParent(candiate);
122
        return this == candiate || parent.hasParent(candiate);
123
    }
123
    }
124
    
124
    
125
    public void accept(IBugzillaModelVisitor visitor) throws BugzillaException {
125
    public void accept(IBugzillaModelVisitor visitor) throws BugzillaException {
126
        if (visitor.visit(this)) {
126
        if (visitor.visit(this)) {
127
            BugzillaModel[] children = getChildren();
127
            BugzillaModel[] children = getChildren();
128
            for (int i = 0; i < children.length; i++) {
128
            for (int i = 0; i < children.length; i++) {
129
                BugzillaModel model = children[i];
129
                BugzillaModel model = children[i];
130
                model.accept(visitor);
130
                model.accept(visitor);
131
            }
131
            }
132
        }
132
        }
133
    }
133
    }
134
134
135
    /**
135
    /**
136
     * Get the name of the container as it would appear in any lists or trees.
136
     * Get the name of the container as it would appear in any lists or trees.
137
     * This name is used to ensure a unique name within a parent container.
137
     * This name is used to ensure a unique name within a parent container.
138
     * @return the name of the container
138
     * @return the name of the container
139
     */
139
     */
140
    public abstract String getName();
140
    public abstract String getName();
141
  
141
  
142
    /**
142
    /**
143
     * Return the child with the given id or <code>null</code>
143
     * Return the child with the given id or <code>null</code>
144
     * if one does not exist.
144
     * if one does not exist.
145
     * @param id the id of a child
145
     * @param id the id of a child
146
     * @return the child with the given id or <code>null</code>
146
     * @return the child with the given id or <code>null</code>
147
     */
147
     */
148
    public BugzillaModel getChild(String id) {
148
    public BugzillaModel getChild(String id) {
149
        return (BugzillaModel)fChildren.get(id);
149
        return (BugzillaModel)fChildren.get(id);
150
    }
150
    }
151
    
151
    
152
    /* (non-Javadoc)
152
    /* (non-Javadoc)
153
     * @see org.eclipse.team.bugzilla.model.BugzillaModel#resetPath()
153
     * @see org.eclipse.team.bugzilla.model.BugzillaModel#resetPath()
154
     */
154
     */
155
    protected void resetPath() {
155
    protected void resetPath() {
156
        super.resetPath();
156
        super.resetPath();
157
        for (Iterator iter = fChildren.values().iterator(); iter.hasNext();) {
157
        for (Iterator iter = fChildren.values().iterator(); iter.hasNext();) {
158
            final BugzillaModel child = (BugzillaModel) iter.next();
158
            final BugzillaModel child = (BugzillaModel) iter.next();
159
            child.resetPath();
159
            child.resetPath();
160
        }
160
        }
161
    }
161
    }
162
    
162
    
163
    /**
163
    /**
164
     * This method indicates whether a user should be able to add or delete any children
164
     * This method indicates whether a user should be able to add or delete any children
165
     * of this container.
165
     * of this container.
166
     * @return True if a user can modify the children, false otherwise.
166
     * @return True if a user can modify the children, false otherwise.
167
     */
167
     */
168
    public abstract boolean canModifyChildren();
168
    public abstract boolean canModifyChildren();
169
}
169
}
(-)src/org/eclipse/team/bugzilla/model/BugzillaQueryOptions.java (-2 / +2 lines)
Lines 187-197 Link Here
187
		
187
		
188
		private static final String URL_SUFFIX_QUERY = "query.cgi?format=advanced";
188
		private static final String URL_SUFFIX_QUERY = "query.cgi?format=advanced";
189
		private static final String URL_SUFFIX_KEYWORDS = "describekeywords.cgi?";
189
		private static final String URL_SUFFIX_KEYWORDS = "describekeywords.cgi?";
190
		private BugzillaQueryOptions queryOption;
190
		//private BugzillaQueryOptions queryOption;
191
		
191
		
192
		public BugzillaQueryOptionParser(BugzillaQueryOptions qo, String queryPage) { 
192
		public BugzillaQueryOptionParser(BugzillaQueryOptions qo, String queryPage) { 
193
			setUrl(queryPage); 
193
			setUrl(queryPage); 
194
			queryOption = qo;
194
			//queryOption = qo;
195
		}
195
		}
196
		
196
		
197
		public void setUrl(String queryPage) { 
197
		public void setUrl(String queryPage) { 
(-)src/org/eclipse/team/bugzilla/model/IRemoteModel.java (-40 / +39 lines)
Lines 1-40 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.model;
12
package org.eclipse.team.bugzilla.model;
13
13
14
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.team.bugs.model.IGenericModel;
15
import org.eclipse.team.bugs.model.IGenericModel;
16
import org.eclipse.team.bugzilla.BugzillaException;
16
import org.eclipse.team.bugzilla.BugzillaException;
17
17
18
18
19
/**
19
/**
20
 * An interface for elements which have remote content.
20
 * An interface for elements which have remote content.
21
 */
21
 */
22
public interface IRemoteModel extends IGenericModel {
22
public interface IRemoteModel extends IGenericModel {
23
    
23
    
24
    /**
24
    /**
25
     * Re-fetch data from the BTS.
25
     * Re-fetch data from the BTS.
26
     * 
26
     * 
27
     * @param monitor a progress monitor
27
     * @param monitor a progress monitor
28
     */
28
     */
29
	public void refresh(IProgressMonitor monitor) throws BugzillaException;
29
	public void refresh(IProgressMonitor monitor) throws BugzillaException;
30
30
31
	/**
31
	/**
32
	 * Update this element with the new data.
32
	 * Update this element with the new data.
33
	 * @param state the new data
33
	 */
34
	 */
34
	public void update();
35
	public void update();
35
	
36
	
36
	
37
	
37
	public boolean needsRefresh();
38
	public boolean needsRefresh();
38
39
39
}
40
}
(-)src/org/eclipse/team/bugzilla/operations/BugzillaOperations.java (-161 / +160 lines)
Lines 1-162 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.bugzilla.operations;
11
package org.eclipse.team.bugzilla.operations;
12
12
13
import java.io.BufferedReader;
13
import java.io.BufferedReader;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.InputStream;
15
import java.io.InputStreamReader;
16
import java.io.InputStreamReader;
16
import java.net.MalformedURLException;
17
import java.net.MalformedURLException;
17
import java.net.URL;
18
import java.net.URL;
18
import java.net.URLConnection;
19
import java.net.URLConnection;
19
import java.util.regex.Matcher;
20
import java.util.regex.Matcher;
20
import java.util.regex.Pattern;
21
import java.util.regex.Pattern;
21
22
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.team.bugzilla.BugzillaException;
25
import org.eclipse.team.bugzilla.BugzillaException;
25
import org.eclipse.team.bugzilla.BugzillaFactory;
26
import org.eclipse.team.bugzilla.BugzillaFactory;
26
import org.eclipse.team.bugzilla.datatypes.AttachmentData;
27
import org.eclipse.team.bugzilla.datatypes.AttachmentData;
27
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
28
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
28
import org.eclipse.team.bugzilla.datatypes.BugzillaConfiguration;
29
import org.eclipse.team.bugzilla.datatypes.BugzillaConfiguration;
29
import org.eclipse.team.bugzilla.datatypes.QueryData;
30
import org.eclipse.team.bugzilla.datatypes.QueryData;
30
import org.eclipse.team.bugzilla.datatypes.QueryURL;
31
import org.eclipse.team.bugzilla.datatypes.QueryURL;
31
import org.eclipse.team.bugzilla.datatypes.ReportData;
32
import org.eclipse.team.bugzilla.datatypes.ReportData;
32
import org.eclipse.team.bugzilla.xml.Parser;
33
import org.eclipse.team.bugzilla.xml.Parser;
33
import org.eclipse.team.bugzilla.xml.VersionHandler;
34
import org.eclipse.team.bugzilla.xml.VersionHandler;
34
35
35
36
36
public abstract class BugzillaOperations {
37
public abstract class BugzillaOperations {
37
38
38
	protected static String bugScript; /* TODO: jpound - part of redirect workaround for gcj */
39
	protected static String bugScript; /* TODO: jpound - part of redirect workaround for gcj */
39
	//TODO:private static final String BAD_XML_HEADER = "<?xml version=\"1.0\" ?>";
40
	//TODO:private static final String BAD_XML_HEADER = "<?xml version=\"1.0\" ?>";
40
    public static BugzillaOperations getOperations(IProgressMonitor monitor, BugzillaConfiguration configuration) throws BugzillaException {
41
    public static BugzillaOperations getOperations(IProgressMonitor monitor, BugzillaConfiguration configuration) throws BugzillaException {
41
		int version = configuration.getVersion();
42
		int version = configuration.getVersion();
42
    	if (version < 0) {
43
    	if (version < 0) {
43
    		version = getVersion(monitor, configuration);
44
    		version = getVersion(monitor, configuration);
44
    		configuration.setVersion(version);
45
    		configuration.setVersion(version);
45
    	}
46
    	}
46
		return create(version);
47
		return create(version);
47
	}
48
	}
48
       
49
       
49
    public static BugzillaOperations create(int version) {
50
    public static BugzillaOperations create(int version) {
50
        switch (version) {
51
        switch (version) {
51
        case BugzillaFactory.VERSION_2_16:
52
        case BugzillaFactory.VERSION_2_16:
52
        	return new BugzillaOperations_2_16();
53
        	return new BugzillaOperations_2_16();
53
        case BugzillaFactory.VERSION_2_18:
54
        case BugzillaFactory.VERSION_2_18:
54
        	return new BugzillaOperations_2_18();
55
        	return new BugzillaOperations_2_18();
55
            
56
            
56
        }
57
        }
57
        return null;
58
        return null;
58
    }
59
    }
59
	
60
	
60
    public static int getVersion(IProgressMonitor monitor, BugzillaConfiguration configuration) throws BugzillaException {
61
    public static int getVersion(IProgressMonitor monitor, BugzillaConfiguration configuration) throws BugzillaException {
61
        // find the version by requesting an invalid bug.
62
        // find the version by requesting an invalid bug.
62
		String url = configuration.getBaseURL();
63
		String url = configuration.getBaseURL();
63
		if (!url.endsWith("/")) {
64
		if (!url.endsWith("/")) {
64
			url += "/";
65
			url += "/";
65
		}
66
		}
66
		try {
67
		try {
67
			final HTTPConnection connection= new HTTPConnection(url + "xml.cgi?id=1");
68
			final HTTPConnection connection= new HTTPConnection(url + "xml.cgi?id=1");
68
			final String xml= connection.getString(monitor);
69
			final String xml= connection.getString(monitor);
69
			final Parser parser= new Parser(false, false);
70
			final Parser parser= new Parser(false, false);
70
			final VersionHandler handler= new VersionHandler();
71
			final VersionHandler handler= new VersionHandler();
71
			parser.parse(xml, handler);
72
			parser.parse(xml, handler);
72
			bugScript = "xml.cgi?id=";
73
			bugScript = "xml.cgi?id=";
73
			return handler.getVersion();
74
			return handler.getVersion();
74
		} catch (Exception e) {
75
		} catch (Exception e) {
75
			/* FIXME: jpound - work around for gcj not handling the xml.cgi redirect in bugilla 2.18 */
76
			/* FIXME: jpound - work around for gcj not handling the xml.cgi redirect in bugilla 2.18 */
76
			bugScript = "show_bug.cgi?ctype=xml&id=";
77
			bugScript = "show_bug.cgi?ctype=xml&id=";
77
			final HTTPConnection connection= new HTTPConnection(url + bugScript + "1");
78
			final HTTPConnection connection= new HTTPConnection(url + bugScript + "1");
78
			final String xml= connection.getString(monitor);
79
			final String xml= connection.getString(monitor);
79
			final Parser parser= new Parser(false, false);
80
			final Parser parser= new Parser(false, false);
80
			final VersionHandler handler= new VersionHandler();
81
			final VersionHandler handler= new VersionHandler();
81
			parser.parse(xml, handler);
82
			parser.parse(xml, handler);
82
			return handler.getVersion();
83
			return handler.getVersion();
83
		}
84
		}
84
    }
85
    }
85
	
86
	
86
	public static ImageDescriptor getBugzillaIcon(String url) {
87
	public static ImageDescriptor getBugzillaIcon(String url) {
87
		try {
88
		try {
88
			BufferedReader read = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
89
			BufferedReader read = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
89
			String line;
90
			String line;
90
			String image;
91
			String image;
91
			url = url.endsWith("/") ? url : url + "/";	
92
			url = url.endsWith("/") ? url : url + "/";	
92
			Pattern iconFlag = Pattern.compile(".*rel=\".*icon\".*");
93
			Pattern iconFlag = Pattern.compile(".*rel=\".*icon\".*");
93
			
94
			
94
			while ((line = read.readLine()) != null) {
95
			while ((line = read.readLine()) != null) {
95
				
96
				
96
				Matcher m = iconFlag.matcher(line);
97
				Matcher m = iconFlag.matcher(line);
97
				if (m.matches()) {
98
				if (m.matches()) {
98
					image = parseUrl(read, line, url);
99
					image = parseUrl(read, line, url);
99
					read.close();
100
					read.close();
100
					return (image == null) ? null : ImageDescriptor.createFromURL(new URL(image));
101
					return (image == null) ? null : ImageDescriptor.createFromURL(new URL(image));
101
				}
102
				}
102
			}
103
			}
103
			read.close();
104
			read.close();
104
			/* Attempt to find the default icon */
105
			/* Attempt to find the default icon */
105
			URL base = new URL(url);
106
			URL base = new URL(url);
106
			URL iconUrl = new URL(base.getProtocol() + "://" + base.getHost() + "/" + "favicon.ico");
107
			URL iconUrl = new URL(base.getProtocol() + "://" + base.getHost() + "/" + "favicon.ico");
107
			
108
			
108
			URLConnection con = iconUrl.openConnection();
109
			URLConnection con = iconUrl.openConnection();
109
			int len = con.getContentLength();
110
			int len = con.getContentLength();
110
			
111
			
111
			if (len <= 0) {
112
			if (len <= 0) {
112
				return null;
113
				return null;
113
			}
114
			}
114
			
115
			
115
			
116
			
116
			ImageDescriptor defaultIcon = ImageDescriptor.createFromURL(new URL(iconUrl.toString()));
117
			ImageDescriptor defaultIcon = ImageDescriptor.createFromURL(new URL(iconUrl.toString()));
117
			
118
			
118
			if (defaultIcon.getImageData() != null) {
119
			if (defaultIcon.getImageData() != null) {
119
				return defaultIcon;
120
				return defaultIcon;
120
			}
121
			}
121
			
122
			
122
		} catch (MalformedURLException e) {
123
		} catch (MalformedURLException e) {
123
			System.err.println("BugzillaOperations: Malformed URL when fetching icon");
124
			System.err.println("BugzillaOperations: Malformed URL when fetching icon");
124
		} catch (IOException e) {
125
		} catch (IOException e) {
125
			System.err.println("BugzillaOperations: IOException exception when fetching icon");
126
			System.err.println("BugzillaOperations: IOException exception when fetching icon");
126
		}
127
		}
127
		return null;
128
		return null;
128
	}
129
	}
129
	
130
	
130
	private static String parseUrl(BufferedReader read, String line, String url) throws IOException {
131
	private static String parseUrl(BufferedReader read, String line, String url) throws IOException {
131
		String hrefFlag = "href=\"";
132
		String hrefFlag = "href=\"";
132
		int index;
133
		int index;
133
		do {
134
		do {
134
			if ((index = line.indexOf(hrefFlag)) >= 0) {
135
			if ((index = line.indexOf(hrefFlag)) >= 0) {
135
				/* keep breaking off begining part of string to get icon url */
136
				/* keep breaking off begining part of string to get icon url */
136
				line = line.substring(index + hrefFlag.length());
137
				line = line.substring(index + hrefFlag.length());
137
				url += line.substring(0, line.indexOf("\""));
138
				url += line.substring(0, line.indexOf("\""));
138
				
139
				
139
				return url;
140
				return url;
140
			}
141
			}
141
		} while ((line = read.readLine()) != null);
142
		} while ((line = read.readLine()) != null);
142
		
143
		
143
		return null;
144
		return null;
144
	}
145
	}
145
        
146
        
146
    public abstract ReportData getReportData(IProgressMonitor monitor, BugzillaConfiguration configuration, String id) throws BugzillaException;
147
    public abstract ReportData getReportData(IProgressMonitor monitor, BugzillaConfiguration configuration, String id) throws BugzillaException;
147
    
148
    
148
    public abstract QueryData getQueryData(IProgressMonitor monitor, BugzillaConfiguration configuration, QueryURL queryURL) throws BugzillaException;
149
    public abstract QueryData getQueryData(IProgressMonitor monitor, BugzillaConfiguration configuration, QueryURL queryURL) throws BugzillaException;
149
150
150
	public abstract AttachmentData getAttachment(IProgressMonitor monitor, BugzillaConfiguration configuration, AttachmentDescription desc) throws BugzillaException;
151
	public abstract AttachmentData getAttachment(IProgressMonitor monitor, BugzillaConfiguration configuration, AttachmentDescription desc) throws BugzillaException;
151
	
152
	
152
	public abstract String getReportURL(BugzillaConfiguration configuration, String reportID);
153
	public abstract String getReportURL(BugzillaConfiguration configuration, String reportID);
153
154
154
	public abstract String getCommentURL(BugzillaConfiguration configuration, String reportID, int commentNbr);
155
	public abstract String getCommentURL(BugzillaConfiguration configuration, String reportID, int commentNbr);
155
	
156
	
156
	public abstract String getAttachmentURL(BugzillaConfiguration configuration, String attachmentID);
157
	public abstract String getAttachmentURL(BugzillaConfiguration configuration, String attachmentID);
157
	
158
	
158
	public abstract String getReportIDFromURL(BugzillaConfiguration configuration, String url);
159
	public abstract String getReportIDFromURL(BugzillaConfiguration configuration, String url);
159
	
160
	
160
	public abstract String getQueryURL(BugzillaConfiguration configuration, String url);
161
	public abstract String getQueryURL(BugzillaConfiguration configuration, String url);
162
}
161
}
(-)src/org/eclipse/team/bugzilla/operations/BugzillaOperations_2_16.java (-213 / +212 lines)
Lines 1-213 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.operations;
12
package org.eclipse.team.bugzilla.operations;
13
13
14
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.team.bugs.extension.BugsException;
15
import org.eclipse.team.bugzilla.BugzillaException;
16
import org.eclipse.team.bugzilla.BugzillaException;
16
import org.eclipse.team.bugzilla.datatypes.AttachmentData;
17
import org.eclipse.team.bugzilla.datatypes.AttachmentData;
17
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
18
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
18
import org.eclipse.team.bugzilla.datatypes.BugzillaConfiguration;
19
import org.eclipse.team.bugzilla.datatypes.BugzillaConfiguration;
19
import org.eclipse.team.bugzilla.datatypes.QueryData;
20
import org.eclipse.team.bugzilla.datatypes.QueryData;
20
import org.eclipse.team.bugzilla.datatypes.QueryURL;
21
import org.eclipse.team.bugzilla.datatypes.QueryURL;
21
import org.eclipse.team.bugzilla.datatypes.ReportData;
22
import org.eclipse.team.bugzilla.datatypes.ReportData;
22
import org.eclipse.team.bugzilla.xml.Parser;
23
import org.eclipse.team.bugzilla.xml.Parser;
23
import org.eclipse.team.bugzilla.xml.QueryHandler;
24
import org.eclipse.team.bugzilla.xml.QueryHandler;
24
import org.eclipse.team.bugzilla.xml.ReportHandler;
25
import org.eclipse.team.bugzilla.xml.ReportHandler;
25
import org.eclipse.team.bugzilla.xml.ReportHandler_2_16;
26
import org.eclipse.team.bugzilla.xml.ReportHandler_2_16;
26
27
27
/**
28
/**
28
 * 
29
 * 
29
 */
30
 */
30
public class BugzillaOperations_2_16 extends BugzillaOperations {
31
public class BugzillaOperations_2_16 extends BugzillaOperations {
31
    
32
    
32
    private final static class Reader {
33
    private final static class Reader {
33
        
34
        
34
        private final String fSource;
35
        private final String fSource;
35
        private int fIndex;
36
        private int fIndex;
36
        
37
        
37
        public Reader(String source) {
38
        public Reader(String source) {
38
            fSource= source;
39
            fSource= source;
39
            fIndex= 0;
40
            fIndex= 0;
40
        }
41
        }
41
        
42
        
42
        public char read() {
43
        public char read() {
43
            return fSource.charAt(fIndex++);
44
            return fSource.charAt(fIndex++);
44
        }
45
        }
45
        
46
        
46
        public boolean isFinished() {
47
        public boolean isFinished() {
47
            return fIndex == fSource.length();
48
            return fIndex == fSource.length();
48
        }
49
        }
49
        
50
        
50
        public void consume(String string) throws BugzillaException {
51
        public void consume(String string) throws BugzillaException {
51
            if (!fSource.startsWith(string, fIndex)) {
52
            if (!fSource.startsWith(string, fIndex)) {
52
                throw new BugzillaException(BugzillaException.XML_ERROR, "Parse error consuming " + string);
53
                throw new BugzillaException(BugzillaException.XML_ERROR, "Parse error consuming " + string);
53
            }
54
            }
54
            fIndex += string.length();
55
            fIndex += string.length();
55
        }
56
        }
56
    }
57
    }
57
    
58
    
58
    public ReportData getReportData(IProgressMonitor monitor, BugzillaConfiguration configuration, String id) throws BugzillaException {
59
    public ReportData getReportData(IProgressMonitor monitor, BugzillaConfiguration configuration, String id) throws BugzillaException {
59
        
60
        
60
        monitor.subTask("Fetching report data");
61
        monitor.subTask("Fetching report data");
61
        try {
62
        try {
62
			String url = configuration.getBaseURL();
63
			String url = configuration.getBaseURL();
63
			if (!url.endsWith("/")) {
64
			if (!url.endsWith("/")) {
64
				url += "/";
65
				url += "/";
65
			}
66
			}
66
            url += bugScript + id.trim(); //$NON-NLS-1$
67
            url += bugScript + id.trim(); //$NON-NLS-1$
67
            final HTTPConnection connection= new HTTPConnection(url);
68
            final HTTPConnection connection= new HTTPConnection(url);
68
            final String xml= connection.getString(monitor);
69
            final String xml= connection.getString(monitor);
69
            final ReportHandler handler= new ReportHandler_2_16();
70
            final ReportHandler handler= new ReportHandler_2_16();
70
            new Parser(false, false).parse(xml, handler);
71
            new Parser(false, false).parse(xml, handler);
71
            return handler.getReportData();
72
            return handler.getReportData();
72
        } finally {
73
        } finally {
73
            monitor.done();
74
            monitor.done();
74
        }
75
        }
75
    }
76
    }
76
    
77
    
77
    public AttachmentData getAttachment(IProgressMonitor monitor, BugzillaConfiguration configuration, AttachmentDescription desc) throws BugzillaException {
78
    public AttachmentData getAttachment(IProgressMonitor monitor, BugzillaConfiguration configuration, AttachmentDescription desc) throws BugzillaException {
78
        
79
        
79
        monitor.subTask("Fetching attachment data");
80
        monitor.subTask("Fetching attachment data");
80
        try {
81
        try {
81
            final String id= desc.getString(AttachmentDescription.ID).trim();
82
            final String id= desc.getString(AttachmentDescription.ID).trim();
82
            final String url= getAttachmentURL(configuration, id);
83
            final String url= getAttachmentURL(configuration, id);
83
            final HTTPConnection connection= new HTTPConnection(url);
84
            final HTTPConnection connection= new HTTPConnection(url);
84
            final AttachmentData attachment= new AttachmentData();
85
            final AttachmentData attachment= new AttachmentData();
85
            attachment.data= connection.getBytes(monitor);
86
            attachment.data= connection.getBytes(monitor);
86
            parse(connection.getContentType(), attachment);
87
            parse(connection.getContentType(), attachment);
87
            return attachment;
88
            return attachment;
88
        } finally {
89
        } finally {
89
            monitor.done();
90
            monitor.done();
90
        }
91
        }
91
    }
92
    }
92
    
93
    
93
    private void parse(String contentType, AttachmentData data) throws BugzillaException {
94
    private void parse(String contentType, AttachmentData data) throws BugzillaException {
94
        
95
        
95
        /**
96
        /**
96
         * The format we parse is like:
97
         * The format we parse is like:
97
         *   text/plain; name="bug36204-1.txt"; charset=ISO-8859-1
98
         *   text/plain; name="bug36204-1.txt"; charset=ISO-8859-1
98
         * or
99
         * or
99
         *   image/jpeg; name="text_editor_bug.jpg"
100
         *   image/jpeg; name="text_editor_bug.jpg"
100
         *
101
         *
101
         */
102
         */
102
        final StringBuffer mimeType= new StringBuffer();
103
        final StringBuffer mimeType= new StringBuffer();
103
        final StringBuffer filename= new StringBuffer();
104
        final StringBuffer filename= new StringBuffer();
104
        final StringBuffer charset= new StringBuffer();
105
        final StringBuffer charset= new StringBuffer();
105
        
106
        
106
        final Reader reader= new Reader(contentType);
107
        final Reader reader= new Reader(contentType);
107
        
108
        
108
        /**
109
        /**
109
         * Read the MIME type.
110
         * Read the MIME type.
110
         */
111
         */
111
        char ch;
112
        char ch;
112
        while ((ch= reader.read()) != ';') {
113
        while ((ch= reader.read()) != ';') {
113
            mimeType.append(ch);
114
            mimeType.append(ch);
114
        }
115
        }
115
        
116
        
116
        reader.consume(" name=\"");
117
        reader.consume(" name=\"");
117
        
118
        
118
        /**
119
        /**
119
         * Read the file name
120
         * Read the file name
120
         */
121
         */
121
        while ((ch= reader.read()) != '"') {
122
        while ((ch= reader.read()) != '"') {
122
            filename.append(ch);
123
            filename.append(ch);
123
        }
124
        }
124
        
125
        
125
        /**
126
        /**
126
         * Read the encoding if specified.
127
         * Read the encoding if specified.
127
         */
128
         */
128
        if (!reader.isFinished()) {
129
        if (!reader.isFinished()) {
129
            reader.consume("; charset=");
130
            reader.consume("; charset=");
130
            
131
            
131
            while (!reader.isFinished()) {
132
            while (!reader.isFinished()) {
132
                charset.append(reader.read());
133
                charset.append(reader.read());
133
            }
134
            }
134
        }
135
        }
135
        data.set(AttachmentData.FILENAME, filename.toString());
136
        data.set(AttachmentData.FILENAME, filename.toString());
136
        data.set(AttachmentData.MIMETYPE, mimeType.toString());
137
        data.set(AttachmentData.MIMETYPE, mimeType.toString());
137
        data.set(AttachmentData.ENCODING, charset.toString());
138
        data.set(AttachmentData.ENCODING, charset.toString());
138
    }
139
    }
139
    
140
    
140
    public String getReportURL(BugzillaConfiguration configuration, String reportID) {
141
    public String getReportURL(BugzillaConfiguration configuration, String reportID) {
141
        return configuration.getBaseURL() + "/show_bug.cgi?id=" + reportID.trim();
142
        return configuration.getBaseURL() + "/show_bug.cgi?id=" + reportID.trim();
142
    }
143
    }
143
    
144
    
144
    public String getCommentURL(BugzillaConfiguration configuration, String reportID, int commentNbr) {
145
    public String getCommentURL(BugzillaConfiguration configuration, String reportID, int commentNbr) {
145
        return getReportURL(configuration, reportID) + "#c" + commentNbr;
146
        return getReportURL(configuration, reportID) + "#c" + commentNbr;
146
    }
147
    }
147
    
148
    
148
    public String getAttachmentURL(BugzillaConfiguration configuration, String attachmentID) {
149
    public String getAttachmentURL(BugzillaConfiguration configuration, String attachmentID) {
149
        return configuration.getBaseURL() + "/attachment.cgi?id=" + attachmentID; //$NON-NLS-1$
150
        return configuration.getBaseURL() + "/attachment.cgi?id=" + attachmentID; //$NON-NLS-1$
150
    }
151
    }
151
    
152
    
152
    public String getReportIDFromURL(BugzillaConfiguration configuration, String url) {
153
    public String getReportIDFromURL(BugzillaConfiguration configuration, String url) {
153
        if (!url.startsWith(configuration.getBaseURL() + "/show_bug.cgi?id="))
154
        if (!url.startsWith(configuration.getBaseURL() + "/show_bug.cgi?id="))
154
            return null;
155
            return null;
155
        
156
        
156
        final int hashIndex = url.indexOf("#");
157
        final int hashIndex = url.indexOf("#");
157
        final int equalsIndex = url.indexOf("=");
158
        final int equalsIndex = url.indexOf("=");
158
        try {
159
        try {
159
            if(hashIndex == -1)
160
            if(hashIndex == -1)
160
                return url.substring(equalsIndex + 1);
161
                return url.substring(equalsIndex + 1);
161
            return url.substring(equalsIndex + 1, hashIndex);
162
            return url.substring(equalsIndex + 1, hashIndex);
162
        } catch (ArrayIndexOutOfBoundsException e) {
163
        } catch (ArrayIndexOutOfBoundsException e) {
163
            return null;
164
            return null;
164
        }
165
        }
165
    }
166
    }
166
    
167
    
167
    
168
    
168
    public String getQueryURL(BugzillaConfiguration configuration, String url) {
169
    public String getQueryURL(BugzillaConfiguration configuration, String url) {
169
        if (!url.startsWith(configuration.getBaseURL() + "/buglist.cgi?"))
170
        if (!url.startsWith(configuration.getBaseURL() + "/buglist.cgi?"))
170
            return null;
171
            return null;
171
        
172
        
172
        if (url.indexOf("regetlastlist") != -1)
173
        if (url.indexOf("regetlastlist") != -1)
173
            return null;
174
            return null;
174
        return url;
175
        return url;
175
    }
176
    }
176
177
177
    /**
178
    /**
178
     * Fetch the query data for the given query from the server identified by the supplied
179
     * Fetch the query data for the given query from the server identified by the supplied
179
     * configuration. This method uses the query handler returned from <code>getQueryHandler</code>
180
     * configuration. This method uses the query handler returned from <code>getQueryHandler</code>
180
     * to perform the parsing.
181
     * to perform the parsing.
181
     * @param monitor a progress monitor
182
     * @param monitor a progress monitor
182
     * @param configuration the configuration which identified the bugzilla server
183
     * @param configuration the configuration which identified the bugzilla server
183
     * @param queryURL the query to be fetched
184
     * @param queryURL the query to be fetched
184
     * @return the data retrieved for the given query
185
     * @return the data retrieved for the given query
185
     * @throws BugzillaException
186
     * @throws BugsException
186
     */
187
     */
187
    public QueryData getQueryData(IProgressMonitor monitor, BugzillaConfiguration configuration, QueryURL queryURL) throws BugzillaException {
188
    public QueryData getQueryData(IProgressMonitor monitor, BugzillaConfiguration configuration, QueryURL queryURL) throws BugzillaException {
188
        final QueryHandler handler= new QueryHandler();
189
        final QueryHandler handler= new QueryHandler();
189
    
190
    
190
        String url= queryURL.getUrl(configuration); //$NON-NLS-1$
191
        String url= queryURL.getUrl(configuration); //$NON-NLS-1$
191
        // catch query data triggered by the browser (non-xml)
192
        // catch query data triggered by the browser (non-xml)
192
        // this also prevents queries from being added to the history
193
        // this also prevents queries from being added to the history
193
        if (url.indexOf("format=rdf") < 0) {
194
        if (url.indexOf("format=rdf") < 0) {
194
        	return null;
195
        	return null;
195
        }
196
        }
196
        final String loginCookie = configuration.getLoginCookie();
197
        final String loginCookie = configuration.getLoginCookie();
197
        if (queryURL.isNamedQuery() && loginCookie == null) {
198
        if (queryURL.isNamedQuery() && loginCookie == null) {
198
            throw new BugzillaException(BugzillaException.REQUIRES_LOGIN, "Please login to Bugzilla.");
199
            throw new BugzillaException(BugzillaException.REQUIRES_LOGIN, "Please login to Bugzilla.");
199
        }
200
        }
200
        final HTTPConnection connection= new HTTPConnection(url, loginCookie);
201
        final HTTPConnection connection= new HTTPConnection(url, loginCookie);
201
        final String xml= connection.getString(monitor);
202
        final String xml= connection.getString(monitor);
202
        if (isLoginFailure(xml)) {
203
        if (isLoginFailure(xml)) {
203
            throw new BugzillaException(BugzillaException.REQUIRES_LOGIN, "Bugzilla user authentication failed.");
204
            throw new BugzillaException(BugzillaException.REQUIRES_LOGIN, "Bugzilla user authentication failed.");
204
        }
205
        }
205
        new Parser(false, false).parse(xml, handler);
206
        new Parser(false, false).parse(xml, handler);
206
        return handler.getQueryData();
207
        return handler.getQueryData();
207
    }
208
    }
208
209
209
    public boolean isLoginFailure(String xml) {
210
    public boolean isLoginFailure(String xml) {
210
        return xml.indexOf("<html>") != -1 && xml.indexOf("Login") != -1; //$NON-NLS-1$ //$NON-NLS-2$
211
        return xml.indexOf("<html>") != -1 && xml.indexOf("Login") != -1; //$NON-NLS-1$ //$NON-NLS-2$
211
    }
212
    }
212
}
213
}
(-)src/org/eclipse/team/bugzilla/persistence/PersistenceManager.java (-252 / +251 lines)
Lines 1-252 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.persistence;
12
package org.eclipse.team.bugzilla.persistence;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.Map;
16
import java.util.Map;
17
17
18
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.preferences.InstanceScope;
19
import org.eclipse.core.runtime.preferences.InstanceScope;
20
import org.eclipse.team.bugs.extension.BugsException;
20
import org.eclipse.team.bugs.extension.BugsException;
21
import org.eclipse.team.bugs.model.IBugProvider;
21
import org.eclipse.team.bugs.model.IBugProvider;
22
import org.eclipse.team.bugs.model.IGenericModel;
22
import org.eclipse.team.bugs.model.IGenericModel;
23
import org.eclipse.team.bugs.model.IProviderListener;
23
import org.eclipse.team.bugs.model.IProviderListener;
24
import org.eclipse.team.bugzilla.BugzillaException;
24
import org.eclipse.team.bugzilla.BugzillaException;
25
import org.eclipse.team.bugzilla.BugzillaPlugin;
25
import org.eclipse.team.bugzilla.BugzillaPlugin;
26
import org.eclipse.team.bugzilla.adapters.BugzillaAdapterFactory;
26
import org.eclipse.team.bugzilla.adapters.BugzillaAdapterFactory;
27
import org.eclipse.team.bugzilla.model.BugzillaContainer;
27
import org.eclipse.team.bugzilla.model.BugzillaContainer;
28
import org.eclipse.team.bugzilla.model.BugzillaFolder;
28
import org.eclipse.team.bugzilla.model.BugzillaFolder;
29
import org.eclipse.team.bugzilla.model.BugzillaHistoryFolder;
29
import org.eclipse.team.bugzilla.model.BugzillaHistoryFolder;
30
import org.eclipse.team.bugzilla.model.BugzillaModel;
30
import org.eclipse.team.bugzilla.model.BugzillaModel;
31
import org.eclipse.team.bugzilla.model.BugzillaProvider;
31
import org.eclipse.team.bugzilla.model.BugzillaProvider;
32
import org.eclipse.team.bugzilla.model.BugzillaQuery;
32
import org.eclipse.team.bugzilla.model.BugzillaQuery;
33
import org.eclipse.team.bugzilla.model.BugzillaReport;
33
import org.eclipse.team.bugzilla.model.BugzillaReport;
34
import org.osgi.service.prefs.BackingStoreException;
34
import org.osgi.service.prefs.BackingStoreException;
35
import org.osgi.service.prefs.Preferences;
35
import org.osgi.service.prefs.Preferences;
36
36
37
/**
37
/**
38
 * 
38
 * 
39
 */
39
 */
40
public class PersistenceManager {
40
public class PersistenceManager {
41
    
41
    
42
    /*
42
    /*
43
     * The preference node in the instance scope where the providers are persisted
43
     * The preference node in the instance scope where the providers are persisted
44
     */
44
     */
45
    private static final String PROVIDER_STORE_ID = "providers";  //$NON-NLS-1$
45
    private static final String PROVIDER_STORE_ID = "providers";  //$NON-NLS-1$
46
    
46
    
47
    protected static final BugzillaModel [] EMPTY_ARRAY= new BugzillaModel[0];
47
    protected static final BugzillaModel [] EMPTY_ARRAY= new BugzillaModel[0];
48
    
48
    
49
    /**
49
    /**
50
     * The key for the model type preference.
50
     * The key for the model type preference.
51
     */
51
     */
52
    public final static String MODEL_TYPE= "org.eclipse.team.bugzilla.modelType"; //$NON-NLS-1$
52
    public final static String MODEL_TYPE= "org.eclipse.team.bugzilla.modelType"; //$NON-NLS-1$
53
    
53
    
54
    public final static String ELEMENT_ID = "org.eclipse.team.bugzilla.elementId"; //$NON-NLS-1$
54
    public final static String ELEMENT_ID = "org.eclipse.team.bugzilla.elementId"; //$NON-NLS-1$
55
55
56
    /**
56
    /**
57
     * IDs for the different persistent model types.
57
     * IDs for the different persistent model types.
58
     */
58
     */
59
    public final static String PROVIDER= "provider"; //$NON-NLS-1$
59
    public final static String PROVIDER= "provider"; //$NON-NLS-1$
60
    public final static String FOLDER= "folder"; //$NON-NLS-1$
60
    public final static String FOLDER= "folder"; //$NON-NLS-1$
61
    public final static String HISTORY= "history"; //$NON-NLS-1$
61
    public final static String HISTORY= "history"; //$NON-NLS-1$
62
    public final static String REPORT= "report"; //$NON-NLS-1$
62
    public final static String REPORT= "report"; //$NON-NLS-1$
63
    public final static String QUERY= "query"; //$NON-NLS-1$
63
    public final static String QUERY= "query"; //$NON-NLS-1$
64
64
65
    private final static Map type2classMap;
65
    private final static Map type2classMap;
66
66
67
    /*
67
    /*
68
     * Listener that is registered with each provider to update 
68
     * Listener that is registered with each provider to update 
69
     * the store when the model changes
69
     * the store when the model changes
70
     */
70
     */
71
    private static IProviderListener listener = new IProviderListener() {
71
    private static IProviderListener listener = new IProviderListener() {
72
        /* (non-Javadoc)
72
        /* (non-Javadoc)
73
         * @see org.eclipse.team.bugs.model.IProviderListener#modelAdded(org.eclipse.team.bugs.model.IGenericModel, org.eclipse.team.bugs.model.IGenericModel)
73
         * @see org.eclipse.team.bugs.model.IProviderListener#modelAdded(org.eclipse.team.bugs.model.IGenericModel, org.eclipse.team.bugs.model.IGenericModel)
74
         */
74
         */
75
        public void elementsAdded(IGenericModel parent, IGenericModel[] children) {
75
        public void elementsAdded(IGenericModel parent, IGenericModel[] children) {
76
            elementsChanged(children);
76
            elementsChanged(children);
77
        }
77
        }
78
78
79
        /* (non-Javadoc)
79
        /* (non-Javadoc)
80
         * @see org.eclipse.team.bugs.model.IProviderListener#modelChanged(org.eclipse.team.bugs.model.IGenericModel)
80
         * @see org.eclipse.team.bugs.model.IProviderListener#modelChanged(org.eclipse.team.bugs.model.IGenericModel)
81
         */
81
         */
82
        public void elementsChanged(IGenericModel[] elements) {
82
        public void elementsChanged(IGenericModel[] elements) {
83
            for (int i = 0; i < elements.length; i++) {
83
            for (int i = 0; i < elements.length; i++) {
84
                final BugzillaModel model = (BugzillaModel)elements[i];
84
                final BugzillaModel model = (BugzillaModel)elements[i];
85
                final IPersistenceAdapter adapter = getPersistenceAdapter(elements[i]);
85
                final IPersistenceAdapter adapter = getPersistenceAdapter(elements[i]);
86
                if (adapter != null)
86
                if (adapter != null)
87
                    adapter.storeElement(model, false);
87
                    adapter.storeElement(model, false);
88
            }
88
            }
89
            final BugzillaProvider provider= ((BugzillaModel)elements[0]).getBugzillaProvider();
89
            final BugzillaProvider provider= ((BugzillaModel)elements[0]).getBugzillaProvider();
90
            try {
90
            try {
91
                AbstractPersistenceAdapter.getPreferences(provider).flush();
91
                AbstractPersistenceAdapter.getPreferences(provider).flush();
92
            } catch (BackingStoreException e) {
92
            } catch (BackingStoreException e) {
93
                BugzillaPlugin.log(BugzillaException.asBugsException(e));
93
                BugzillaPlugin.log(BugzillaException.asBugsException(e));
94
            }
94
            }
95
        }
95
        }
96
96
97
        /* (non-Javadoc)
97
        /* (non-Javadoc)
98
         * @see org.eclipse.team.bugs.model.IProviderListener#modelRemoved(org.eclipse.team.bugs.model.IGenericModel, org.eclipse.team.bugs.model.IGenericModel)
98
         * @see org.eclipse.team.bugs.model.IProviderListener#modelRemoved(org.eclipse.team.bugs.model.IGenericModel, org.eclipse.team.bugs.model.IGenericModel)
99
         */
99
         */
100
        public void elementsRemoved(IGenericModel parent, IGenericModel[] children) {
100
        public void elementsRemoved(IGenericModel parent, IGenericModel[] children) {
101
            for (int i = 0; i < children.length; i++) {
101
            for (int i = 0; i < children.length; i++) {
102
                final BugzillaModel model = (BugzillaModel)children[i];
102
                final BugzillaModel model = (BugzillaModel)children[i];
103
                final IPersistenceAdapter adapter = getPersistenceAdapter(parent);
103
                final IPersistenceAdapter adapter = getPersistenceAdapter(parent);
104
                if (adapter != null)
104
                if (adapter != null)
105
                    adapter.purgeChild((BugzillaModel)parent, model, false);
105
                    adapter.purgeChild((BugzillaModel)parent, model, false);
106
            }
106
            }
107
            try {
107
            try {
108
                AbstractPersistenceAdapter.getPreferences(parent).flush();
108
                AbstractPersistenceAdapter.getPreferences(parent).flush();
109
            } catch (BackingStoreException e) {
109
            } catch (BackingStoreException e) {
110
                BugzillaPlugin.log(BugzillaException.asBugsException(e));
110
                BugzillaPlugin.log(BugzillaException.asBugsException(e));
111
            }
111
            }
112
        }
112
        }
113
    };
113
    };
114
114
115
    
115
    
116
    static {
116
    static {
117
        type2classMap = new HashMap();
117
        type2classMap = new HashMap();
118
        type2classMap.put(PROVIDER, BugzillaProvider.class);
118
        type2classMap.put(PROVIDER, BugzillaProvider.class);
119
        type2classMap.put(FOLDER, BugzillaFolder.class);
119
        type2classMap.put(FOLDER, BugzillaFolder.class);
120
        type2classMap.put(HISTORY, BugzillaHistoryFolder.class);
120
        type2classMap.put(HISTORY, BugzillaHistoryFolder.class);
121
        type2classMap.put(REPORT, BugzillaReport.class);
121
        type2classMap.put(REPORT, BugzillaReport.class);
122
        type2classMap.put(QUERY, BugzillaQuery.class);
122
        type2classMap.put(QUERY, BugzillaQuery.class);
123
    }
123
    }
124
    
124
    
125
    /**
125
    /**
126
     * Return the root preferences node whose children are providers
126
     * Return the root preferences node whose children are providers
127
     * @return the root preferences node whose children are providers
127
     * @return the root preferences node whose children are providers
128
     */
128
     */
129
    /* package */ static Preferences getRootNode() {
129
    /* package */ static Preferences getRootNode() {
130
        return new InstanceScope().getNode(BugzillaPlugin.ID).node(PROVIDER_STORE_ID);
130
        return new InstanceScope().getNode(BugzillaPlugin.ID).node(PROVIDER_STORE_ID);
131
    }
131
    }
132
    
132
    
133
    /**
133
    /**
134
     * Restore the providers from the preference store and return the restored providers
134
     * Restore the providers from the preference store and return the restored providers
135
     * @return the restored providers
135
     * @return the restored providers
136
     */
136
     */
137
    public static IBugProvider[] restoreProviders() {
137
    public static IBugProvider[] restoreProviders() {
138
        BugzillaModel[] providers = restoreChildren(null /* no parent */, getRootNode());
138
        BugzillaModel[] providers = restoreChildren(null /* no parent */, getRootNode());
139
        IBugProvider[] result = new IBugProvider[providers.length];
139
        IBugProvider[] result = new IBugProvider[providers.length];
140
        System.arraycopy(providers, 0, result, 0, providers.length);
140
        System.arraycopy(providers, 0, result, 0, providers.length);
141
        return result;
141
        return result;
142
    }
142
    }
143
    
143
    
144
    /**
144
    /**
145
     * Return the persistence adapter for the given element 
145
     * Return the persistence adapter for the given element 
146
     * or <code>null</code> if there isn't one.
146
     * or <code>null</code> if there isn't one.
147
     * @param element the element
147
     * @param element the element
148
     * @return the persistence adapter for the given element 
148
     * @return the persistence adapter for the given element 
149
     * or <code>null</code>
149
     * or <code>null</code>
150
     */
150
     */
151
    public static IPersistenceAdapter getPersistenceAdapter(Object element) {
151
    public static IPersistenceAdapter getPersistenceAdapter(Object element) {
152
        if (element instanceof IAdaptable) {
152
        if (element instanceof IAdaptable) {
153
	        Object adapter = ((IAdaptable)element).getAdapter(IPersistenceAdapter.class);
153
	        Object adapter = ((IAdaptable)element).getAdapter(IPersistenceAdapter.class);
154
	        if (adapter instanceof IPersistenceAdapter)
154
	        if (adapter instanceof IPersistenceAdapter)
155
	            return (IPersistenceAdapter)adapter;
155
	            return (IPersistenceAdapter)adapter;
156
        }
156
        }
157
        return null;
157
        return null;
158
    }
158
    }
159
    
159
    
160
    /*
160
    /*
161
     * Method used by persistence adapters to restore a bugzilla model
161
     * Method used by persistence adapters to restore a bugzilla model
162
     */
162
     */
163
    /* package */ static BugzillaModel restoreChild(BugzillaContainer parent, Preferences node) {
163
    /* package */ static BugzillaModel restoreChild(BugzillaContainer parent, Preferences node) {
164
        final String type= node.get(MODEL_TYPE, ""); //$NON-NLS-1$
164
        final String type= node.get(MODEL_TYPE, ""); //$NON-NLS-1$
165
        final String id = node.get(ELEMENT_ID, ""); //$NON-NLS-1$
165
        final String id = node.get(ELEMENT_ID, ""); //$NON-NLS-1$
166
        IPersistenceAdapter adapter = getPersistenceAdapter(type);
166
        IPersistenceAdapter adapter = getPersistenceAdapter(type);
167
        if (adapter != null) {
167
        if (adapter != null) {
168
            try {
168
            try {
169
                BugzillaModel element = adapter.restoreElement(parent, node, id);
169
                BugzillaModel element = adapter.restoreElement(parent, node, id);
170
	            return element;
170
	            return element;
171
            } catch (BugzillaException e) {
171
            } catch (BugzillaException e) {
172
                BugzillaPlugin.log(e);
172
                BugzillaPlugin.log(e);
173
            }
173
            }
174
        }
174
        }
175
        return null;
175
        return null;
176
    }
176
    }
177
    
177
    
178
    /**
178
    /**
179
     * Restore the childen of the given element.
179
     * Restore the childen of the given element.
180
     * @param parent the element
180
     * @param parent the element
181
     * @param node the node for the element that may contain child nodes
181
     * @param node the node for the element that may contain child nodes
182
     * representing children of the element
182
     * representing children of the element
183
     * @return the restored children
183
     * @return the restored children
184
     */
184
     */
185
    /* package */ static final BugzillaModel[] restoreChildren(BugzillaContainer parent, Preferences node) {
185
    /* package */ static final BugzillaModel[] restoreChildren(BugzillaContainer parent, Preferences node) {
186
        final String [] childrenNames;
186
        final String [] childrenNames;
187
        try {
187
        try {
188
            childrenNames= node.childrenNames();
188
            childrenNames= node.childrenNames();
189
        } catch (BackingStoreException e) {
189
        } catch (BackingStoreException e) {
190
            BugzillaPlugin.log(BugsException.asBugsException(e));
190
            BugzillaPlugin.log(BugsException.asBugsException(e));
191
            return EMPTY_ARRAY;
191
            return EMPTY_ARRAY;
192
        }
192
        }
193
        final ArrayList children= new ArrayList();
193
        final ArrayList children= new ArrayList();
194
        for (int i = 0; i < childrenNames.length; i++) {
194
        for (int i = 0; i < childrenNames.length; i++) {
195
            final String childName= childrenNames[i];
195
            final String childName= childrenNames[i];
196
            final Preferences childNode= node.node(childName);
196
            final Preferences childNode= node.node(childName);
197
            final BugzillaModel child= restoreChild(parent, childNode);
197
            final BugzillaModel child= restoreChild(parent, childNode);
198
            if (child != null)
198
            if (child != null)
199
                children.add(child);
199
                children.add(child);
200
        }
200
        }
201
        return (BugzillaModel[]) children.toArray(new BugzillaModel[children.size()]);
201
        return (BugzillaModel[]) children.toArray(new BugzillaModel[children.size()]);
202
    }
202
    }
203
    
203
    
204
    private static IPersistenceAdapter getPersistenceAdapter(String type) {
204
    private static IPersistenceAdapter getPersistenceAdapter(String type) {
205
        Class typeClass = (Class)type2classMap.get(type);
205
        Class typeClass = (Class)type2classMap.get(type);
206
        if (typeClass != null) {
206
        if (typeClass != null) {
207
            Object adapter = BugzillaAdapterFactory.getPersistenceAdapter(typeClass);
207
            Object adapter = BugzillaAdapterFactory.getPersistenceAdapter(typeClass);
208
            if (adapter instanceof IPersistenceAdapter)
208
            if (adapter instanceof IPersistenceAdapter)
209
                return (IPersistenceAdapter)adapter;
209
                return (IPersistenceAdapter)adapter;
210
        }
210
        }
211
        return null;
211
        return null;
212
    }
212
    }
213
213
214
    /**
214
    /**
215
     * The provider has been added so persist it's state
215
     * The provider has been added so persist it's state
216
     * @param provider
216
     * @param provider
217
     */
217
     */
218
    public static void providerAdded(BugzillaProvider provider) {
218
    public static void providerAdded(BugzillaProvider provider) {
219
        IPersistenceAdapter adapter = getPersistenceAdapter(provider);
219
        IPersistenceAdapter adapter = getPersistenceAdapter(provider);
220
        if (adapter != null) {
220
        if (adapter != null) {
221
            adapter.storeElement(provider, true /* flush to disk */);
221
            adapter.storeElement(provider, true /* flush to disk */);
222
        }
222
        }
223
        provider.getEventHandler().addProviderListener(listener );
223
        provider.getEventHandler().addProviderListener(listener );
224
    }
224
    }
225
225
226
    /**
226
    /**
227
     * The provider has been removed so purge any persisted state
227
     * The provider has been removed so purge any persisted state
228
     * @param provider
228
     * @param provider
229
     */
229
     */
230
    public static void providerRemoved(BugzillaProvider provider) {
230
    public static void providerRemoved(BugzillaProvider provider) {
231
        IPersistenceAdapter adapter = getPersistenceAdapter(provider);
231
        IPersistenceAdapter adapter = getPersistenceAdapter(provider);
232
        if (adapter != null) {
232
        if (adapter != null) {
233
            adapter.purgeChild(null, provider, true /* flush to disk */);
233
            adapter.purgeChild(null, provider, true /* flush to disk */);
234
        }
234
        }
235
        provider.getEventHandler().removeProviderListener(listener);
235
        provider.getEventHandler().removeProviderListener(listener);
236
    }
236
    }
237
237
238
    /**
238
    /**
239
     * @param container
239
     * @param container
240
     * @return
240
     */
241
     */
241
    public static Preferences getPreferenceNode(BugzillaContainer container) {
242
    public static Preferences getPreferenceNode(BugzillaContainer container) {
242
        return AbstractPersistenceAdapter.getPreferences(container);
243
        return AbstractPersistenceAdapter.getPreferences(container);
243
    }
244
    }
244
    
245
    
245
    /*
246
    /*
246
     * Do not allow instantiation
247
     * Do not allow instantiation
247
     */
248
     */
248
    private PersistenceManager() {
249
    private PersistenceManager() {
249
    }
250
    }
250
251
251
}
252
}
(-)src/org/eclipse/team/bugzilla/tools/IBugzillaSelectionProvider.java (-28 / +25 lines)
Lines 1-28 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.tools;
12
package org.eclipse.team.bugzilla.tools;
13
13
14
/**
14
/**
15
 * 
15
 * 
16
 */
16
 */
17
public interface IBugzillaSelectionProvider {
17
public interface IBugzillaSelectionProvider {
18
18
19
    /**
19
    BugzillaSelection getSelection();
20
     * @return
20
    
21
     */
21
    void addListener(IBugzillaSelectionListener listener);
22
    BugzillaSelection getSelection();
22
    
23
    
23
    void removeListener(IBugzillaSelectionListener listener);
24
    void addListener(IBugzillaSelectionListener listener);
24
25
    
25
}
26
    void removeListener(IBugzillaSelectionListener listener);
27
28
}
(-)src/org/eclipse/team/bugzilla/view/ActionManager.java (-103 / +103 lines)
Lines 1-103 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.view;
12
package org.eclipse.team.bugzilla.view;
13
13
14
import org.eclipse.jface.action.*;
14
import org.eclipse.jface.action.*;
15
import org.eclipse.swt.custom.StyledText;
15
import org.eclipse.swt.custom.StyledText;
16
import org.eclipse.swt.events.FocusAdapter;
16
import org.eclipse.swt.events.FocusAdapter;
17
import org.eclipse.swt.events.FocusEvent;
17
import org.eclipse.swt.events.FocusEvent;
18
import org.eclipse.team.bugs.extension.IViewerProxy;
18
import org.eclipse.team.bugs.extension.IViewerProxy;
19
import org.eclipse.team.bugzilla.actions.*;
19
import org.eclipse.team.bugzilla.actions.*;
20
import org.eclipse.team.bugzilla.tools.IBugzillaSelectionProvider;
20
import org.eclipse.team.bugzilla.tools.IBugzillaSelectionProvider;
21
import org.eclipse.ui.IWorkbenchActionConstants;
21
import org.eclipse.ui.IWorkbenchActionConstants;
22
import org.eclipse.ui.actions.ActionFactory;
22
import org.eclipse.ui.actions.ActionFactory;
23
23
24
/**
24
/**
25
 * 
25
 * 
26
 */
26
 */
27
class ActionManager extends FocusAdapter {
27
class ActionManager extends FocusAdapter {
28
    
28
    
29
    private final BugzillaDeleteAction fDeleteAction;
29
    private final BugzillaDeleteAction fDeleteAction;
30
    private final BugzillaCopyAction fCopyAction;
30
    private final BugzillaCopyAction fCopyAction;
31
    private final BugzillaPasteAction fPasteAction;
31
    private final BugzillaPasteAction fPasteAction;
32
    private final BugzillaMoveAction fMoveAction;
32
    private final BugzillaMoveAction fMoveAction;
33
    private final BugzillaRenameAction fRenameAction;
33
    private final BugzillaRenameAction fRenameAction;
34
    private final RefreshAction fRefreshAction;
34
    private final RefreshAction fRefreshAction;
35
35
36
    private final ShowInBrowserAction fShowInBrowserAction;
36
    private final ShowInBrowserAction fShowInBrowserAction;
37
    private final ClearHistoryAction fClearHistoryAction;
37
    private final ClearHistoryAction fClearHistoryAction;
38
    
38
    
39
    private final TextSelectAllAction fTextSelectAllAction;
39
    private final TextSelectAllAction fTextSelectAllAction;
40
    
40
    
41
    private final BugzillaViewExtension fExtension;
41
    //private final BugzillaViewExtension fExtension;
42
    
42
    
43
    public ActionManager(BugzillaViewExtension extension) {
43
    public ActionManager(BugzillaViewExtension extension) {
44
        
44
        
45
        fExtension= extension;
45
        //fExtension= extension;
46
        final IViewerProxy proxy= extension.getProxy();
46
        final IViewerProxy proxy= extension.getProxy();
47
        final IBugzillaSelectionProvider provider = extension.getBugzillaSelectionProvider();
47
        final IBugzillaSelectionProvider provider = extension.getBugzillaSelectionProvider();
48
        fDeleteAction= new BugzillaDeleteAction(proxy, provider);
48
        fDeleteAction= new BugzillaDeleteAction(proxy, provider);
49
        fPasteAction= new BugzillaPasteAction(proxy, provider);
49
        fPasteAction= new BugzillaPasteAction(proxy, provider);
50
        fCopyAction= new BugzillaCopyAction(proxy, extension, fPasteAction);
50
        fCopyAction= new BugzillaCopyAction(proxy, extension, fPasteAction);
51
        fMoveAction= new BugzillaMoveAction(proxy, provider);
51
        fMoveAction= new BugzillaMoveAction(proxy, provider);
52
        fRenameAction= new BugzillaRenameAction(proxy, provider);
52
        fRenameAction= new BugzillaRenameAction(proxy, provider);
53
        fClearHistoryAction= new ClearHistoryAction(proxy, provider);
53
        fClearHistoryAction= new ClearHistoryAction(proxy, provider);
54
        fShowInBrowserAction= new ShowInBrowserAction(proxy, provider);
54
        fShowInBrowserAction= new ShowInBrowserAction(proxy, provider);
55
        fRefreshAction= new RefreshAction(proxy, provider);
55
        fRefreshAction= new RefreshAction(proxy, provider);
56
        fTextSelectAllAction= new TextSelectAllAction(extension);
56
        fTextSelectAllAction= new TextSelectAllAction(extension);
57
        
57
        
58
        proxy.registerGlobalAction(ActionFactory.DELETE.getId(), fDeleteAction);
58
        proxy.registerGlobalAction(ActionFactory.DELETE.getId(), fDeleteAction);
59
        proxy.registerGlobalAction(ActionFactory.COPY.getId(), fCopyAction);
59
        proxy.registerGlobalAction(ActionFactory.COPY.getId(), fCopyAction);
60
        proxy.registerGlobalAction(ActionFactory.PASTE.getId(), fPasteAction);
60
        proxy.registerGlobalAction(ActionFactory.PASTE.getId(), fPasteAction);
61
        proxy.registerGlobalAction(ActionFactory.MOVE.getId(), fMoveAction);
61
        proxy.registerGlobalAction(ActionFactory.MOVE.getId(), fMoveAction);
62
        proxy.registerGlobalAction(ActionFactory.RENAME.getId(), fRenameAction);
62
        proxy.registerGlobalAction(ActionFactory.RENAME.getId(), fRenameAction);
63
        proxy.registerGlobalAction(ActionFactory.REFRESH.getId(), fRefreshAction);
63
        proxy.registerGlobalAction(ActionFactory.REFRESH.getId(), fRefreshAction);
64
        proxy.registerGlobalAction(ActionFactory.SELECT_ALL.getId(), fTextSelectAllAction);
64
        proxy.registerGlobalAction(ActionFactory.SELECT_ALL.getId(), fTextSelectAllAction);
65
    }
65
    }
66
    
66
    
67
    public void fillContextMenu(IMenuManager menu) {
67
    public void fillContextMenu(IMenuManager menu) {
68
        if (fShowInBrowserAction.isEnabled())
68
        if (fShowInBrowserAction.isEnabled())
69
            menu.add(fShowInBrowserAction);
69
            menu.add(fShowInBrowserAction);
70
        if (fClearHistoryAction.isEnabled())
70
        if (fClearHistoryAction.isEnabled())
71
            menu.add(fClearHistoryAction);
71
            menu.add(fClearHistoryAction);
72
    }
72
    }
73
73
74
    public void updateActionEnablements() {
74
    public void updateActionEnablements() {
75
        fShowInBrowserAction.setEnablement();
75
        fShowInBrowserAction.setEnablement();
76
        fDeleteAction.setEnablement();
76
        fDeleteAction.setEnablement();
77
        fCopyAction.setEnablement();
77
        fCopyAction.setEnablement();
78
        fPasteAction.setEnablement();
78
        fPasteAction.setEnablement();
79
        fMoveAction.setEnablement();
79
        fMoveAction.setEnablement();
80
        fRefreshAction.setEnablement();
80
        fRefreshAction.setEnablement();
81
        fRenameAction.setEnablement();
81
        fRenameAction.setEnablement();
82
        fClearHistoryAction.setEnablement();
82
        fClearHistoryAction.setEnablement();
83
        fTextSelectAllAction.setEnablement();
83
        fTextSelectAllAction.setEnablement();
84
    }
84
    }
85
    
85
    
86
    /* (non-Javadoc)
86
    /* (non-Javadoc)
87
     * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent)
87
     * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent)
88
     */
88
     */
89
    public void focusGained(FocusEvent e) {
89
    public void focusGained(FocusEvent e) {
90
        updateActionEnablements();
90
        updateActionEnablements();
91
    }
91
    }
92
92
93
    /**
93
    /**
94
     * @param styledText
94
     * @param styledText
95
     */
95
     */
96
    public void createTextContextMenu(StyledText styledText) {
96
    public void createTextContextMenu(StyledText styledText) {
97
        final MenuManager menu= new MenuManager(null);
97
        final MenuManager menu= new MenuManager(null);
98
        menu.add(fCopyAction);
98
        menu.add(fCopyAction);
99
        menu.add(fTextSelectAllAction);
99
        menu.add(fTextSelectAllAction);
100
        menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
100
        menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
101
        styledText.setMenu(menu.createContextMenu(styledText));
101
        styledText.setMenu(menu.createContextMenu(styledText));
102
    }
102
    }
103
}
103
}
(-)src/org/eclipse/team/bugzilla/view/BugzillaModelPresenter.java (-337 / +336 lines)
Lines 1-337 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.view;
12
package org.eclipse.team.bugzilla.view;
13
13
14
import java.io.UnsupportedEncodingException;
14
import java.io.UnsupportedEncodingException;
15
import java.net.URLDecoder;
15
import java.net.URLDecoder;
16
import java.text.DateFormat;
16
import java.text.DateFormat;
17
import java.util.Date;
17
import java.util.Date;
18
import java.util.HashMap;
18
import java.util.HashMap;
19
import java.util.Iterator;
19
import java.util.Iterator;
20
20
21
import org.eclipse.jface.text.TextPresentation;
21
import org.eclipse.jface.text.TextPresentation;
22
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.custom.BusyIndicator;
23
import org.eclipse.swt.custom.BusyIndicator;
24
import org.eclipse.swt.custom.StyleRange;
24
import org.eclipse.swt.custom.StyleRange;
25
import org.eclipse.swt.custom.StyledText;
25
import org.eclipse.swt.custom.StyledText;
26
import org.eclipse.team.bugzilla.datatypes.AttachmentData;
26
import org.eclipse.team.bugzilla.datatypes.AttachmentData;
27
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
27
import org.eclipse.team.bugzilla.datatypes.AttachmentDescription;
28
import org.eclipse.team.bugzilla.datatypes.CommentData;
28
import org.eclipse.team.bugzilla.datatypes.CommentData;
29
import org.eclipse.team.bugzilla.datatypes.ReportData;
29
import org.eclipse.team.bugzilla.datatypes.ReportData;
30
import org.eclipse.team.bugzilla.model.BugzillaAttachment;
30
import org.eclipse.team.bugzilla.model.BugzillaAttachment;
31
import org.eclipse.team.bugzilla.model.BugzillaComment;
31
import org.eclipse.team.bugzilla.model.BugzillaComment;
32
import org.eclipse.team.bugzilla.model.BugzillaFolder;
32
import org.eclipse.team.bugzilla.model.BugzillaModel;
33
import org.eclipse.team.bugzilla.model.BugzillaModel;
33
import org.eclipse.team.bugzilla.model.BugzillaQuery;
34
import org.eclipse.team.bugzilla.model.BugzillaQuery;
34
import org.eclipse.team.bugzilla.model.BugzillaReport;
35
import org.eclipse.team.bugzilla.model.BugzillaReport;
35
36
36
public class BugzillaModelPresenter {
37
public class BugzillaModelPresenter {
37
    
38
    
38
    protected TextPresentation fPresentation;
39
    protected TextPresentation fPresentation;
39
    protected StringBuffer fBuffer;
40
    protected StringBuffer fBuffer;
40
    protected StyledText fStyledText;
41
    protected StyledText fStyledText;
41
42
42
    public BugzillaModelPresenter() {
43
    public BugzillaModelPresenter() {
43
        fStyledText= null;
44
        fStyledText= null;
44
        fPresentation= null;
45
        fPresentation= null;
45
        fBuffer= null;
46
        fBuffer= null;
46
    }
47
    }
47
    
48
    
48
    private void begin(StyledText styledText) {
49
    private void begin(StyledText styledText) {
49
        fPresentation= new TextPresentation();
50
        fPresentation= new TextPresentation();
50
        fBuffer= new StringBuffer();
51
        fBuffer= new StringBuffer();
51
        fStyledText= styledText;
52
        fStyledText= styledText;
52
        
53
        
53
    }
54
    }
54
    
55
    
55
    private void end(final boolean wordWrap) {
56
    private void end(final boolean wordWrap) {
56
        BusyIndicator.showWhile(fStyledText.getDisplay(), new Runnable() {
57
        BusyIndicator.showWhile(fStyledText.getDisplay(), new Runnable() {
57
            public void run() {
58
            public void run() {
58
                fStyledText.setRedraw(false);
59
                fStyledText.setRedraw(false);
59
                fStyledText.setText("");
60
                fStyledText.setText("");
60
                fStyledText.setWordWrap(wordWrap);
61
                fStyledText.setWordWrap(wordWrap);
61
                fStyledText.setText(fBuffer.toString());
62
                fStyledText.setText(fBuffer.toString());
62
                TextPresentation.applyTextPresentation(fPresentation, fStyledText);
63
                TextPresentation.applyTextPresentation(fPresentation, fStyledText);
63
                fStyledText.setRedraw(true);
64
                fStyledText.setRedraw(true);
64
            }
65
            }
65
        });
66
        });
66
67
67
        fBuffer= null;
68
        fBuffer= null;
68
        fPresentation= null;
69
        fPresentation= null;
69
        fStyledText= null;
70
        fStyledText= null;
70
    }
71
    }
71
    
72
    
72
//    public void present(BugzillaProvider provider, StyledText styledText) {
73
//    public void present(BugzillaProvider provider, StyledText styledText) {
73
//        begin(styledText);
74
//        begin(styledText);
74
//        end(true);
75
//        end(true);
75
//    }
76
//    }
76
77
77
    public void present(BugzillaQuery query, StyledText styledText) {
78
    public void present(BugzillaQuery query, StyledText styledText) {
78
        begin(styledText);
79
        begin(styledText);
79
        append(query);
80
        append(query);
80
        end(true);        
81
        end(true);        
81
    }
82
    }
82
    
83
    
83
    public void present(BugzillaReport report, StyledText styledText) {
84
    public void present(BugzillaReport report, StyledText styledText) {
84
        begin(styledText);
85
        begin(styledText);
85
        append(report);
86
        append(report);
86
        end(true);        
87
        end(true);        
87
    }
88
    }
88
    
89
    
89
    public void present(BugzillaComment comment, StyledText styledText) {
90
    public void present(BugzillaComment comment, StyledText styledText) {
90
        begin(styledText);
91
        begin(styledText);
91
        append(comment);
92
        append(comment);
92
        end(true);
93
        end(true);
93
    }
94
    }
94
    
95
    
95
    public void present(BugzillaAttachment bugzillaAttachment, StyledText styledText) {
96
    public void present(BugzillaAttachment bugzillaAttachment, StyledText styledText) {
96
        
97
        
97
        final AttachmentData attachment= bugzillaAttachment.getData();
98
        final AttachmentData attachment= bugzillaAttachment.getData();
98
        
99
        
99
        boolean wordWrap= false;
100
        boolean wordWrap= false;
100
        begin(styledText);
101
        begin(styledText);
101
        
102
        
102
        if (attachment != null) { 
103
        if (attachment != null) { 
103
            final String data= bugzillaAttachment.getDataAsString();
104
            final String data= bugzillaAttachment.getDataAsString();
104
            final String mimeType= bugzillaAttachment.getData().getString(AttachmentData.MIMETYPE);
105
            final String mimeType= bugzillaAttachment.getData().getString(AttachmentData.MIMETYPE);
105
            if (mimeType.startsWith("text/")) {
106
            if (mimeType.startsWith("text/")) {
106
                append(data);
107
                append(data);
107
                wordWrap= false;
108
                wordWrap= false;
108
            } else {
109
            } else {
109
                append(attachment.getString(AttachmentData.FILENAME)).space().append("[").append(mimeType).append("]");
110
                append(attachment.getString(AttachmentData.FILENAME)).space().append("[").append(mimeType).append("]");
110
                wordWrap= true;
111
                wordWrap= true;
111
            }
112
            }
112
        }
113
        }
113
        end(wordWrap);
114
        end(wordWrap);
114
    }
115
    }
115
    
116
    
116
//	/**
117
	/**
117
//	 * @param folder
118
	 * @param folder
118
//	 * @param styledText
119
	 * @param styledText
119
//	 */
120
	 */
120
//	public void present(BugzillaFolder folder, StyledText styledText) {
121
//	public void present(BugzillaFolder folder, StyledText styledText) {
121
//		begin(styledText);
122
//		begin(styledText);
122
//		append(folder);
123
//		append(folder);
123
//		end(true);
124
//		end(true);
124
//	}
125
//	}
125
    
126
    
126
//    /**
127
//    /**
127
//	 * @param folder
128
//	 * @param folder
128
//	 */
129
//	 */
129
//	private void append(BugzillaFolder folder) {
130
//	private void append(BugzillaFolder folder) {
130
//		/* TODO: jpound - implement folder presentation */
131
//		/* TODO: jpound - implement folder presentation */
131
//		bold(folder.getName()).endl().endl();
132
//		bold(folder.getName()).endl().endl();
132
//		
133
//		
133
//		BugzillaModel[] children = folder.getChildren();
134
//		BugzillaModel[] children = folder.getChildren();
134
//		int numQueries = 0;
135
//		int numQueries = 0;
135
//		int numBugs = 0;
136
//		int numBugs = 0;
136
//		if (children != null) {
137
//		if (children != null) {
137
//			for (int i = 0; i < children.length; i++) {
138
//			for (int i = 0; i < children.length; i++) {
138
//				if (children[i] instanceof BugzillaQuery) {
139
//				if (children[i] instanceof BugzillaQuery) {
139
//					numQueries++;
140
//					numQueries++;
140
//				}
141
//				}
141
//				else {
142
//				else {
142
//					numBugs++;
143
//					numBugs++;
143
//				}
144
//				}
144
//			}
145
//			}
145
//		}
146
//		}
146
//		else {
147
//		else {
147
//			italic("Empty Folder");
148
//			italic("Empty Folder");
148
//			return;
149
//			return;
149
//		}
150
//		}
150
//				
151
//				
151
//		if (numQueries > 0) {
152
//		if (numQueries > 0) {
152
//			append("Queries:\t" + numQueries).endl();
153
//			append("Queries:\t" + numQueries).endl();
153
//		}
154
//		}
154
//		if (numBugs > 0) {
155
//		if (numBugs > 0) {
155
//			append("Bugs:\t\t" + numBugs);
156
//			append("Bugs:\t\t" + numBugs);
156
//		}
157
//		}
157
//	}
158
//	}
158
159
159
	private BugzillaModelPresenter append(BugzillaQuery query) {
160
	private BugzillaModelPresenter append(BugzillaQuery query) {
160
        
161
        
161
    	String queryUrl = query.getQueryUrl().toUrlString();
162
    	String queryUrl = query.getQueryUrl().toUrlString();
162
        String summary = null;
163
        String summary = null;
163
        String comment = null;
164
        String comment = null;
164
        
165
        
165
        int summaryIndex = queryUrl.indexOf("short_desc=");
166
        int summaryIndex = queryUrl.indexOf("short_desc=");
166
        if (summaryIndex >= 0) {
167
        if (summaryIndex >= 0) {
167
        	summary = queryUrl.substring(summaryIndex, queryUrl.length());
168
        	summary = queryUrl.substring(summaryIndex, queryUrl.length());
168
        	int ampIndex = summary.indexOf('&');
169
        	int ampIndex = summary.indexOf('&');
169
        	if (ampIndex < 0) {
170
        	if (ampIndex < 0) {
170
        		ampIndex = summary.length();
171
        		ampIndex = summary.length();
171
        	}
172
        	}
172
        	try {
173
        	try {
173
				summary = URLDecoder.decode(summary.substring(summary.indexOf('=') + 1, ampIndex), "UTF-8");
174
				summary = URLDecoder.decode(summary.substring(summary.indexOf('=') + 1, ampIndex), "UTF-8");
174
			} catch (UnsupportedEncodingException e) {
175
			} catch (UnsupportedEncodingException e) {
175
				e.printStackTrace();
176
				e.printStackTrace();
176
			}
177
			}
177
        }
178
        }
178
        
179
        
179
        int commentIndex = queryUrl.indexOf("long_desc=");
180
        int commentIndex = queryUrl.indexOf("long_desc=");
180
        if (commentIndex >= 0) {
181
        if (commentIndex >= 0) {
181
        	comment = queryUrl.substring(commentIndex,  queryUrl.length());
182
        	comment = queryUrl.substring(commentIndex,  queryUrl.length());
182
        	int ampIndex = comment.indexOf('&');
183
        	int ampIndex = comment.indexOf('&');
183
        	if (ampIndex < 0) {
184
        	if (ampIndex < 0) {
184
        		ampIndex = comment.length();
185
        		ampIndex = comment.length();
185
        	}
186
        	}
186
        	try {
187
        	try {
187
				comment = URLDecoder.decode(comment.substring(comment.indexOf('=') + 1, ampIndex), "UTF-8");
188
				comment = URLDecoder.decode(comment.substring(comment.indexOf('=') + 1, ampIndex), "UTF-8");
188
			} catch (UnsupportedEncodingException e) {
189
			} catch (UnsupportedEncodingException e) {
189
				e.printStackTrace();
190
				e.printStackTrace();
190
			}
191
			}
191
        }
192
        }
192
        
193
        
193
        BugzillaModel[] children = query.getChildren();
194
        BugzillaModel[] children = query.getChildren();
194
        HashMap bugFreqs = new HashMap(7); // 7 bugzilla status'
195
        HashMap bugFreqs = new HashMap(7); // 7 bugzilla status'
195
        int criticalBugs = 0;
196
        int criticalBugs = 0;
196
        
197
        
197
        for (int i = 0; i < children.length; i++) {
198
        for (int i = 0; i < children.length; i++) {
198
        	ReportData reportData = ((BugzillaReport)children[i]).getReportData();
199
        	ReportData reportData = ((BugzillaReport)children[i]).getReportData();
199
        	if (reportData == null) {
200
        	if (reportData == null) {
200
        		return this;
201
        		return this;
201
        	}
202
        	}
202
        	String status = reportData.getString(ReportData.STATUS);
203
        	String status = reportData.getString(ReportData.STATUS);
203
        	
204
        	
204
        	if (reportData.getString(ReportData.SEVERITY).equals("critical")) {
205
        	if (reportData.getString(ReportData.SEVERITY).equals("critical")) {
205
        		criticalBugs++;
206
        		criticalBugs++;
206
        	}
207
        	}
207
        	
208
        	
208
        	Integer count = (Integer)bugFreqs.get(status);
209
        	Integer count = (Integer)bugFreqs.get(status);
209
        	if (count == null) {
210
        	if (count == null) {
210
        		bugFreqs.put(status, new Integer(1));
211
        		bugFreqs.put(status, new Integer(1));
211
        	}
212
        	}
212
        	else {
213
        	else {
213
        		bugFreqs.put(status, new Integer(count.intValue() + 1));
214
        		bugFreqs.put(status, new Integer(count.intValue() + 1));
214
        	}
215
        	}
215
        }
216
        }
216
        
217
        
217
        bold("Query from " + query.getQueryUrl().getBaseUrl()).endl();
218
        bold("Query from " + query.getQueryUrl().getBaseUrl()).endl();
218
        if (summary != null && !summary.equals("")) {
219
        if (summary != null && !summary.equals("")) {
219
        	append("Summary:\t\t").italic(summary).endl();
220
        	append("Summary:\t\t").italic(summary).endl();
220
        }
221
        }
221
        if (comment != null && !comment.equals("")) {
222
        if (comment != null && !comment.equals("")) {
222
        	append("Comment:\t\t").italic(comment).endl();
223
        	append("Comment:\t\t").italic(comment).endl();
223
        }
224
        }
224
        endl();
225
        endl();
225
        
226
        
226
        append("Total Bugs:\t" + children.length).endl();
227
        append("Total Bugs:\t" + children.length).endl();
227
        Iterator iter = bugFreqs.keySet().iterator();
228
        Iterator iter = bugFreqs.keySet().iterator();
228
        while (iter.hasNext()) {
229
        while (iter.hasNext()) {
229
        	String status = (String)iter.next(); 
230
        	String status = (String)iter.next(); 
230
        	String tab = "\t";
231
        	String tab = "\t";
231
        	int statusLength;
232
        	int statusLength;
232
        	if ( (statusLength = status.length()) < 8) {
233
        	if ( (statusLength = status.length()) < 8) {
233
        		tab += "\t";
234
        		tab += "\t";
234
        		if (statusLength < 4) {
235
        		if (statusLength < 4) {
235
        			tab += "\t";
236
        			tab += "\t";
236
        		}
237
        		}
237
        	}
238
        	}
238
        	append(status + tab + bugFreqs.get(status)).endl();
239
        	append(status + tab + bugFreqs.get(status)).endl();
239
        }
240
        }
240
        endl();
241
        endl();
241
        if (criticalBugs > 0) {
242
        if (criticalBugs > 0) {
242
        	append("This query contains").bold(" "+criticalBugs).append(" critical " + ((criticalBugs > 1) ? "bugs" : "bug"));
243
        	append("This query contains").bold(" "+criticalBugs).append(" critical " + ((criticalBugs > 1) ? "bugs" : "bug"));
243
        }
244
        }
244
        
245
        
245
        return this;
246
        return this;
246
    }
247
    }
247
    
248
    
248
    private BugzillaModelPresenter append(BugzillaComment bugzillaComment) {
249
    private BugzillaModelPresenter append(BugzillaComment bugzillaComment) {
249
        final CommentData comment= bugzillaComment.getCommentData();
250
        final CommentData comment= bugzillaComment.getCommentData();
250
        if (comment == null)
251
        if (comment == null)
251
            return this;
252
            return this;
252
        bold(comment.getString(CommentData.AUTHOR)).append(" - ").append(comment.getDate(CommentData.DATE)).endl(2);
253
        bold(comment.getString(CommentData.AUTHOR)).append(" - ").append(comment.getDate(CommentData.DATE)).endl(2);
253
254
254
        if (comment.attachmentDesc != null && comment.attachmentDesc.getBoolean(AttachmentDescription.OBSOLETE))
255
        if (comment.attachmentDesc != null && comment.attachmentDesc.getBoolean(AttachmentDescription.OBSOLETE))
255
            append("*** This attachment is obsolete ***").endl(2);
256
            append("*** This attachment is obsolete ***").endl(2);
256
        append(comment.getString(CommentData.TEXT));
257
        append(comment.getString(CommentData.TEXT));
257
        return this;
258
        return this;
258
    }
259
    }
259
260
260
    private BugzillaModelPresenter append(BugzillaReport bugzillaReport) {
261
    private BugzillaModelPresenter append(BugzillaReport bugzillaReport) {
261
        
262
        
262
        if (!bugzillaReport.hasLocalContent())
263
        if (!bugzillaReport.hasLocalContent())
263
            return this;
264
            return this;
264
265
265
        final ReportData report= bugzillaReport.getReportData();
266
        final ReportData report= bugzillaReport.getReportData();
266
        
267
        
267
        bold("[").bold(report.getString(ReportData.ID)).bold("]").space().bold(report.getString(ReportData.TITLE)).endl(2);
268
        bold("[").bold(report.getString(ReportData.ID)).bold("]").space().bold(report.getString(ReportData.TITLE)).endl(2);
268
269
269
        append("Assigned To: ").append(report.getString(ReportData.ASSIGNEDTO)).endl();
270
        append("Assigned To: ").append(report.getString(ReportData.ASSIGNEDTO)).endl();
270
        append("Severity: ").append(report.getString(ReportData.SEVERITY)).endl();
271
        append("Severity: ").append(report.getString(ReportData.SEVERITY)).endl();
271
        append("Priority: ").append(report.getString(ReportData.PRIORITY)).endl();
272
        append("Priority: ").append(report.getString(ReportData.PRIORITY)).endl();
272
        append("Target Milestone: ").append(report.getString(ReportData.TARGETMILESTONE)).endl();
273
        append("Target Milestone: ").append(report.getString(ReportData.TARGETMILESTONE)).endl();
273
        endl();
274
        endl();
274
        append("Operating System: ").append(report.getString(ReportData.OPERATINGSYSTEM)).endl();
275
        append("Operating System: ").append(report.getString(ReportData.OPERATINGSYSTEM)).endl();
275
        append("Platform: ").append(report.getString(ReportData.PLATFORM)).endl();
276
        append("Platform: ").append(report.getString(ReportData.PLATFORM)).endl();
276
        
277
        
277
        endl();
278
        endl();
278
        
279
        
279
        /* append first comment
280
        /* append first comment
280
        final Iterator iter= bugzillaReport.getComments().iterator();
281
        final Iterator iter= bugzillaReport.getComments().iterator();
281
        if (iter.hasNext()) {
282
        if (iter.hasNext()) {
282
            append((BugzillaComment)iter.next());
283
            append((BugzillaComment)iter.next());
283
        }
284
        }
284
        */
285
        */
285
        return this;
286
        return this;
286
    }
287
    }
287
288
288
    private BugzillaModelPresenter append(String suffix) {
289
    private BugzillaModelPresenter append(String suffix) {
289
        fBuffer.append(suffix);
290
        fBuffer.append(suffix);
290
        return this;
291
        return this;
291
    }
292
    }
292
    
293
    
293
    private BugzillaModelPresenter bold(String suffix) {
294
    private BugzillaModelPresenter bold(String suffix) {
294
        final int offset= fBuffer.length();
295
        final int offset= fBuffer.length();
295
        final int length= suffix.length();
296
        final int length= suffix.length();
296
        fBuffer.append(suffix);
297
        fBuffer.append(suffix);
297
        fPresentation.addStyleRange(new StyleRange(offset, length, null, null, SWT.BOLD));
298
        fPresentation.addStyleRange(new StyleRange(offset, length, null, null, SWT.BOLD));
298
        return this;
299
        return this;
299
    }
300
    }
300
    
301
    
301
    private BugzillaModelPresenter italic(String suffix) {
302
    private BugzillaModelPresenter italic(String suffix) {
302
        final int offset= fBuffer.length();
303
        final int offset= fBuffer.length();
303
        final int length= suffix.length();
304
        final int length= suffix.length();
304
        fBuffer.append(suffix);
305
        fBuffer.append(suffix);
305
        fPresentation.addStyleRange(new StyleRange(offset, length, null, null, SWT.ITALIC));
306
        fPresentation.addStyleRange(new StyleRange(offset, length, null, null, SWT.ITALIC));
306
        return this;
307
        return this;
307
    }
308
    }
308
    
309
    
309
    private BugzillaModelPresenter endl() {
310
    private BugzillaModelPresenter endl() {
310
        fBuffer.append("\n");
311
        fBuffer.append("\n");
311
        return this;
312
        return this;
312
    }
313
    }
313
    
314
    
314
    private BugzillaModelPresenter endl(int n) {
315
    private BugzillaModelPresenter endl(int n) {
315
        for (int i= 0; i < n; ++i)
316
        for (int i= 0; i < n; ++i)
316
            fBuffer.append("\n");
317
            fBuffer.append("\n");
317
        return this;
318
        return this;
318
    }
319
    }
319
    
320
    
320
    private BugzillaModelPresenter space() {
321
    private BugzillaModelPresenter space() {
321
        fBuffer.append(" ");
322
        fBuffer.append(" ");
322
        return this;
323
        return this;
323
    }
324
    }
324
    
325
    
325
//    private BugzillaModelPresenter space(int n) {
326
//    private BugzillaModelPresenter space(int n) {
326
//        for (int i= 0; i < n; i++)
327
//        for (int i= 0; i < n; i++)
327
//            fBuffer.append(" ");
328
//            fBuffer.append(" ");
328
//        return this;
329
//        return this;
329
//    }
330
//    }
330
    
331
    
331
    private BugzillaModelPresenter append(Date date) {
332
    private BugzillaModelPresenter append(Date date) {
332
        fBuffer.append(DateFormat.getDateTimeInstance().format(date));
333
        fBuffer.append(DateFormat.getDateTimeInstance().format(date));
333
        return this;
334
        return this;
334
    }
335
    }
335
336
336
}
337
}
(-)src/org/eclipse/team/bugzilla/view/TextPane.java (-186 / +185 lines)
Lines 1-187 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.team.bugzilla.view;
12
package org.eclipse.team.bugzilla.view;
13
13
14
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.jface.viewers.IOpenListener;
15
import org.eclipse.jface.viewers.IOpenListener;
16
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.jface.viewers.OpenEvent;
17
import org.eclipse.jface.viewers.OpenEvent;
18
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.browser.LocationListener;
20
import org.eclipse.swt.browser.LocationListener;
21
import org.eclipse.swt.custom.SashForm;
21
import org.eclipse.swt.custom.SashForm;
22
import org.eclipse.swt.custom.StyledText;
22
import org.eclipse.swt.custom.StyledText;
23
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.team.bugs.model.IGenericModel;
25
import org.eclipse.team.bugs.model.IGenericModel;
26
import org.eclipse.team.bugs.model.IProviderListener;
26
import org.eclipse.team.bugs.model.IProviderListener;
27
import org.eclipse.team.bugzilla.browser.BugzillaBrowser;
27
import org.eclipse.team.bugzilla.browser.BugzillaBrowser;
28
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
28
import org.eclipse.team.bugzilla.browser.IWebContentAdapter;
29
import org.eclipse.team.bugzilla.model.BugzillaModel;
29
import org.eclipse.team.bugzilla.model.BugzillaModel;
30
import org.eclipse.team.bugzilla.model.BugzillaProvider;
30
import org.eclipse.team.bugzilla.model.BugzillaProvider;
31
import org.eclipse.team.bugzilla.tools.BugzillaSelection;
31
import org.eclipse.team.bugzilla.tools.BugzillaSelection;
32
import org.eclipse.team.bugzilla.tools.IBugzillaSelectionListener;
32
import org.eclipse.team.bugzilla.tools.IBugzillaSelectionListener;
33
import org.eclipse.ui.IWorkbenchPart;
33
import org.eclipse.ui.IWorkbenchPart;
34
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.PlatformUI;
35
import org.eclipse.ui.part.PageBook;
35
import org.eclipse.ui.part.PageBook;
36
36
37
public class TextPane implements IBugzillaSelectionListener, IProviderListener, IOpenListener {
37
public class TextPane implements IBugzillaSelectionListener, IProviderListener, IOpenListener {
38
    
38
    
39
    private StyledText fStyledText;
39
    private StyledText fStyledText;
40
    //private Control fEmptyControl;
40
    //private Control fEmptyControl;
41
    private PageBook fPageBook;
41
    private PageBook fPageBook;
42
    private SashForm sashForm = null;
42
    private SashForm sashForm = null;
43
    private int[] userWeights = {2, 1};
43
    private int[] userWeights = {2, 1};
44
    
44
    
45
    private BugzillaSelection fSelection;
45
    private BugzillaSelection fSelection;
46
    
46
    
47
    private final DelayedRefreshPresenter fDelayedRefresh;
47
    private final DelayedRefreshPresenter fDelayedRefresh;
48
    private BugzillaViewExtension fExtension;
48
    private BugzillaViewExtension fExtension;
49
    
49
    
50
    public TextPane(BugzillaViewExtension extension, Composite parent) {
50
    public TextPane(BugzillaViewExtension extension, Composite parent) {
51
        fExtension= extension;
51
        fExtension= extension;
52
        fDelayedRefresh= new DelayedRefreshPresenter();
52
        fDelayedRefresh= new DelayedRefreshPresenter();
53
        
53
        
54
        fPageBook= new PageBook(parent, SWT.NONE);
54
        fPageBook= new PageBook(parent, SWT.NONE);
55
        //fEmptyControl= new Composite(fPageBook, SWT.NONE);
55
        //fEmptyControl= new Composite(fPageBook, SWT.NONE);
56
        fStyledText= new StyledText(fPageBook, SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
56
        fStyledText= new StyledText(fPageBook, SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
57
        fSelection= new BugzillaSelection(StructuredSelection.EMPTY);
57
        fSelection= new BugzillaSelection(StructuredSelection.EMPTY);
58
        
58
        
59
        final ActionManager manager= fExtension.getActionManager();
59
        final ActionManager manager= fExtension.getActionManager();
60
        manager.createTextContextMenu(fStyledText);
60
        manager.createTextContextMenu(fStyledText);
61
        
61
        
62
        if (parent.getParent() instanceof SashForm) {
62
        if (parent.getParent() instanceof SashForm) {
63
        	sashForm = (SashForm)parent.getParent();
63
        	sashForm = (SashForm)parent.getParent();
64
        	hideView();
64
        	hideView();
65
        }
65
        }
66
    }
66
    }
67
67
68
    public void selectionChanged(BugzillaSelection selection) {
68
    public void selectionChanged(BugzillaSelection selection) {
69
        fSelection= selection;
69
        fSelection= selection;
70
70
71
        final BugzillaModel element= fSelection.getOnlyElement();
71
        final BugzillaModel element= fSelection.getOnlyElement();
72
        fDelayedRefresh.refresh(element);
72
        fDelayedRefresh.refresh(element);
73
        
73
        
74
        if (element != null) {
74
        if (element != null) {
75
            present(element);
75
            present(element);
76
        }
76
        }
77
        else {
77
        else {
78
        	hideView();
78
        	hideView();
79
        }
79
        }
80
    }
80
    }
81
81
82
82
83
    public void elementsAdded(IGenericModel parent, IGenericModel[] children) {
83
    public void elementsAdded(IGenericModel parent, IGenericModel[] children) {
84
    }
84
    }
85
85
86
    public void elementsChanged(IGenericModel[] elements) {
86
    public void elementsChanged(IGenericModel[] elements) {
87
        /**
87
        /**
88
         * We only update the styled text if the model has just refreshed
88
         * We only update the styled text if the model has just refreshed
89
         * and is currently selected.
89
         * and is currently selected.
90
         */
90
         */
91
        final BugzillaModel selected= fSelection.getOnlyElement();
91
        final BugzillaModel selected= fSelection.getOnlyElement();
92
        if (selected == null)
92
        if (selected == null)
93
            return;
93
            return;
94
        
94
        
95
        for (int i = 0; i < elements.length; i++) {
95
        for (int i = 0; i < elements.length; i++) {
96
            if (selected == elements[i] && !selected.isRefreshing()) {
96
            if (selected == elements[i] && !selected.isRefreshing()) {
97
                present(selected);
97
                present(selected);
98
            }
98
            }
99
        }
99
        }
100
    }
100
    }
101
101
102
    public void elementsRemoved(IGenericModel parent, IGenericModel[] children) {
102
    public void elementsRemoved(IGenericModel parent, IGenericModel[] children) {
103
    }
103
    }
104
    
104
    
105
    private void present(BugzillaModel element) {
105
    private void present(BugzillaModel element) {
106
    	
106
    	
107
    	final IPresentableAdapter adapter= getPresentableAdapter(element);
107
    	final IPresentableAdapter adapter= getPresentableAdapter(element);
108
        if (adapter == null) {
108
        if (adapter == null) {
109
        	hideView();
109
        	hideView();
110
        	return;
110
        	return;
111
        }
111
        }
112
                
112
                
113
        adapter.present(element, fStyledText);
113
        adapter.present(element, fStyledText);
114
        //final boolean hasText= fStyledText.getText().trim().length() != 0;
114
        //final boolean hasText= fStyledText.getText().trim().length() != 0;
115
        fPageBook.showPage(fStyledText);
115
        fPageBook.showPage(fStyledText);
116
        
116
        
117
        if (sashForm.getWeights()[1] == 0) {
117
        if (sashForm.getWeights()[1] == 0) {
118
        	showView();
118
        	showView();
119
        }
119
        }
120
    }
120
    }
121
    
121
    
122
    private void showView() {
122
    private void showView() {
123
    	if (sashForm == null) {
123
    	if (sashForm == null) {
124
    		return;
124
    		return;
125
    	}
125
    	}
126
    	sashForm.setWeights(userWeights);
126
    	sashForm.setWeights(userWeights);
127
    }
127
    }
128
    
128
    
129
    private void hideView() {
129
    private void hideView() {
130
    	if (sashForm == null) {
130
    	if (sashForm == null) {
131
    		return;
131
    		return;
132
    	}
132
    	}
133
    	int current[];
133
    	if  ((sashForm.getWeights())[1] != 0) {
134
    	if  ((current = sashForm.getWeights())[1] != 0) {
134
    		userWeights = sashForm.getWeights();
135
    		userWeights = sashForm.getWeights();
135
    	}
136
    	}
136
    	sashForm.setWeights(new int[] {1, 0});
137
    	sashForm.setWeights(new int[] {1, 0});
137
    }
138
    }
138
    
139
    
139
    private IPresentableAdapter getPresentableAdapter(Object o) {
140
    private IPresentableAdapter getPresentableAdapter(Object o) {
140
        if (o instanceof IAdaptable) {
141
        if (o instanceof IAdaptable) {
141
            return (IPresentableAdapter)((IAdaptable)o).getAdapter(IPresentableAdapter.class);
142
            return (IPresentableAdapter)((IAdaptable)o).getAdapter(IPresentableAdapter.class);
142
        }
143
        }
143
        return null;
144
        return null;
144
    }
145
    }
145
146
146
    public void open(OpenEvent event) {
147
    public void open(OpenEvent event) {
147
        if (!(event.getSelection() instanceof IStructuredSelection))
148
        if (!(event.getSelection() instanceof IStructuredSelection))
148
            return;
149
            return;
149
        
150
        
150
        final IStructuredSelection selection= (IStructuredSelection)event.getSelection();
151
        final IStructuredSelection selection= (IStructuredSelection)event.getSelection();
151
        
152
        
152
        if (!(selection.getFirstElement() instanceof BugzillaModel))
153
        if (!(selection.getFirstElement() instanceof BugzillaModel))
153
            return;
154
            return;
154
        
155
        
155
        final BugzillaModel model= (BugzillaModel)selection.getFirstElement();
156
        final BugzillaModel model= (BugzillaModel)selection.getFirstElement();
156
        
157
        
157
        final IWebContentAdapter adapter= (IWebContentAdapter)model.getAdapter(IWebContentAdapter.class);
158
        final IWebContentAdapter adapter= (IWebContentAdapter)model.getAdapter(IWebContentAdapter.class);
158
        if (adapter == null)
159
        if (adapter == null)
159
            return;
160
            return;
160
        
161
        
161
        final LocationListener listener= (BugzillaProvider)model.getProvider();
162
        final LocationListener listener= (BugzillaProvider)model.getProvider();
162
        
163
        
163
        final String url= adapter.getURL(model);
164
        final String url= adapter.getURL(model);
164
        if (url != null) {
165
        if (url != null) {
165
            final IWorkbenchPart part= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
166
            final IWorkbenchPart part= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
166
            BugzillaBrowser.open(part, listener, url.replaceAll("format=rdf", ""));
167
            BugzillaBrowser.open(part, listener, url.replaceAll("format=rdf", ""));
167
        }
168
        }
168
        
169
        
169
    }
170
    }
170
171
171
//    public String getSelection() {
172
//    public String getSelection() {
172
//        return fStyledText.getSelectionText();
173
//        return fStyledText.getSelectionText();
173
//    }
174
//    }
174
//
175
//
175
//    public boolean hasFocus() {
176
//    public boolean hasFocus() {
176
//        return fStyledText.isFocusControl();
177
//        return fStyledText.isFocusControl();
177
//    }
178
//    }
178
    
179
    
179
    public StyledText getStyledText() {
180
    public StyledText getStyledText() {
180
        return fStyledText;
181
        return fStyledText;
181
    }
182
    }
182
    
183
    
183
    public Control getControl() {
184
    public Control getControl() {
184
        return fPageBook;
185
        return fPageBook;
185
    }
186
    }
187
}
186
}

Return to bug 81795