KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > ChangeSetLabelDecorator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.synchronize;
12
13 import org.eclipse.jface.resource.JFaceResources;
14 import org.eclipse.jface.viewers.*;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.graphics.*;
18 import org.eclipse.team.internal.core.subscribers.*;
19 import org.eclipse.team.internal.ui.TeamUIMessages;
20 import org.eclipse.team.internal.ui.TeamUIPlugin;
21 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
22 import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
23
24 /**
25  * Label decorator that decorates the default active change set.
26  */

27 public class ChangeSetLabelDecorator extends LabelProvider implements ILabelDecorator, IFontDecorator{
28
29     private Font boldFont;
30     private ActiveChangeSetManager collector;
31
32     public ChangeSetLabelDecorator(ISynchronizePageConfiguration configuration) {
33         ISynchronizeParticipant participant = configuration.getParticipant();
34         if (participant instanceof IChangeSetProvider) {
35             this.collector = ((IChangeSetProvider)participant).getChangeSetCapability().getActiveChangeSetManager();
36         }
37     }
38     
39     public String JavaDoc decorateText(String JavaDoc input, Object JavaDoc element) {
40         String JavaDoc text = input;
41         if (element instanceof ChangeSetDiffNode) {
42             ChangeSet set = ((ChangeSetDiffNode)element).getSet();
43             if (set instanceof ActiveChangeSet && isDefaultActiveSet((ActiveChangeSet)set)) {
44                 text = NLS.bind(TeamUIMessages.CommitSetDiffNode_0, new String JavaDoc[] { text });
45             }
46         }
47         return text;
48     }
49
50     public void dispose() {
51         if(boldFont != null) {
52             boldFont.dispose();
53         }
54     }
55
56     public Font decorateFont(Object JavaDoc element) {
57         if (element instanceof ChangeSetDiffNode) {
58             ChangeSet set = ((ChangeSetDiffNode)element).getSet();
59             if (set instanceof ActiveChangeSet && isDefaultActiveSet((ActiveChangeSet)set)) {
60                 if (boldFont == null) {
61                     Font defaultFont = JFaceResources.getDefaultFont();
62                     FontData[] data = defaultFont.getFontData();
63                     for (int i = 0; i < data.length; i++) {
64                         data[i].setStyle(SWT.BOLD);
65                     }
66                     boldFont = new Font(TeamUIPlugin.getStandardDisplay(), data);
67                 }
68                 return boldFont;
69             }
70         }
71         return null;
72     }
73
74     private boolean isDefaultActiveSet(ActiveChangeSet set) {
75         return collector.isDefault(set);
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(org.eclipse.swt.graphics.Image, java.lang.Object)
80      */

81     public Image decorateImage(Image image, Object JavaDoc element) {
82         return image;
83     }
84     
85 }
86
Popular Tags