~piastucki/bzr-eclipse/history-view-enhancements

« back to all changes in this revision

Viewing changes to src/org/vcs/bazaar/eclipse/team/DecoratorStatus.java

  • Committer: Guillermo Gonzalez
  • Date: 2007-03-14 12:15:50 UTC
  • Revision ID: guillo.gonzo@gmail.com-20070314121550-tltk3b6f3zblf0dh
Initial commit with the new code layout.
Now starts the real work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * org.vcs.bazaar.eclipse (c) Vectrace 2006-jun-08
3
 
 * Created by zingo
4
 
 */
5
 
package org.vcs.bazaar.eclipse.team;
6
 
 
7
 
import org.eclipse.core.resources.IProject;
8
 
import org.eclipse.core.resources.IResource;
9
 
import org.eclipse.jface.viewers.IDecoration;
10
 
import org.eclipse.jface.viewers.ILabelProviderListener;
11
 
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
12
 
import org.eclipse.jface.viewers.LabelProvider;
13
 
import org.eclipse.team.core.RepositoryProvider;
14
 
import org.eclipse.ui.IWorkbench;
15
 
import org.eclipse.ui.PlatformUI;
16
 
 
17
 
/**
18
 
 * @author zingo
19
 
 * 
20
 
 */
21
 
public class DecoratorStatus extends LabelProvider implements
22
 
                ILightweightLabelDecorator {
23
 
 
24
 
        /**
25
 
         * 
26
 
         */
27
 
        public DecoratorStatus() {
28
 
                super();
29
 
                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.DecoratorStatus()");
30
 
        }
31
 
 
32
 
        public static void refresh() {
33
 
                IWorkbench workbench = PlatformUI.getWorkbench();
34
 
                String decoratorId = DecoratorStatus.class.getName();
35
 
                workbench.getDecoratorManager().update(decoratorId);
36
 
        }
37
 
 
38
 
        /*
39
 
         * (non-Javadoc)
40
 
         * 
41
 
         * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
42
 
         *      org.eclipse.jface.viewers.IDecoration)
43
 
         */
44
 
 
45
 
        public void decorate(Object element, IDecoration decoration) {
46
 
                IResource objectResource;
47
 
                IProject objectProject;
48
 
                RepositoryProvider RepoProvider;
49
 
 
50
 
                objectResource = (IResource) element;
51
 
                if (objectResource == null) {
52
 
                        return;
53
 
                }
54
 
 
55
 
                objectProject = objectResource.getProject();
56
 
                if (RepositoryProvider.isShared(objectProject)) {
57
 
                        // A Shared Project
58
 
                        RepoProvider = RepositoryProvider.getProvider(objectProject);
59
 
                        if (!(RepoProvider instanceof BazaarTeamProvider)) {
60
 
                                // Resource not unsing this plugin
61
 
                                return;
62
 
                        }
63
 
                } else {
64
 
                        // Not a Shared Project
65
 
                        return;
66
 
                }
67
 
 
68
 
                // Decorating a Project
69
 
                if (objectResource.getType() == IResource.PROJECT) {
70
 
                        // decoration.addSuffix( "{PROJECT}" );
71
 
                }
72
 
 
73
 
                // Decorating a Folder
74
 
                if (objectResource.getType() == IResource.FOLDER) {
75
 
                        // Folders should not be decorated..
76
 
                        // decoration.addSuffix( "{FOLDER}" );
77
 
                }
78
 
 
79
 
                if (objectResource.getType() == IResource.FILE) {
80
 
                        // Only files are decorated
81
 
                        // decoration.addPrefix("{nofile->}" );
82
 
 
83
 
                        IProject proj;
84
 
                        String Repository;
85
 
                        String FullPath;
86
 
                        proj = objectResource.getProject();
87
 
                        Repository = BazaarUtilities.getRepositoryPath(proj);
88
 
                        if (Repository == null) {
89
 
                                Repository = "."; // never leave this empty add a . to point
90
 
                                                                        // to current path
91
 
                        }
92
 
                        // Setup and run command
93
 
                        // System.out.println("hg --cwd " + Repository + " status");
94
 
 
95
 
                        FullPath = (objectResource.getLocation()).toString();
96
 
                        if (FullPath.indexOf(".bzr") == -1) // Do not decorate the stuff
97
 
                                                                                                // inder .hg
98
 
                        {
99
 
                                String launchCmd[] = { BazaarUtilities.getBzrExecutable(), "status", FullPath };
100
 
                                String output = BazaarUtilities.ExecuteCommand(launchCmd, false);
101
 
                                if (output != null) {
102
 
                                        if (output.length() != 0) {
103
 
                                                // decoration.addSuffix( "{" + output.substring(0,1) +
104
 
                                                // "}" );
105
 
                                                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.decorate("
106
 
                                                // + element.toString() + ", "+ output.substring(0,1) +
107
 
                                                // ")");
108
 
                                                decoration.addOverlay(DecoratorImages.getImageDescriptor(output));
109
 
                                        } else {
110
 
                                                // Managed and unchanged (No output from status)
111
 
                                                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.decorate("
112
 
                                                // + element.toString() + ", No output (managed?))");
113
 
                                                decoration.addOverlay(DecoratorImages.managedDescriptor);
114
 
                                        }
115
 
                                }
116
 
                        }
117
 
                }
118
 
 
119
 
                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.decorate(" +
120
 
                // element.toString() + ", "+ decoration.toString() + ")");
121
 
        }
122
 
 
123
 
        /*
124
 
         * (non-Javadoc)
125
 
         * 
126
 
         * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
127
 
         */
128
 
        public void addListener(ILabelProviderListener listener) {
129
 
                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.addListener()");
130
 
 
131
 
        }
132
 
 
133
 
        /*
134
 
         * (non-Javadoc)
135
 
         * 
136
 
         * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
137
 
         */
138
 
        public void dispose() {
139
 
                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.dispose()");
140
 
 
141
 
        }
142
 
 
143
 
        /*
144
 
         * (non-Javadoc)
145
 
         * 
146
 
         * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
147
 
         *      java.lang.String)
148
 
         */
149
 
        public boolean isLabelProperty(Object element, String property) {
150
 
                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.isLabelProperty()");
151
 
                return false;
152
 
        }
153
 
 
154
 
        /*
155
 
         * (non-Javadoc)
156
 
         * 
157
 
         * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
158
 
         */
159
 
        public void removeListener(ILabelProviderListener listener) {
160
 
                // System.out.println("BazaarEclipsePlugin:DecoratorStatus.removeListener()");
161
 
 
162
 
        }
163
 
 
164
 
}