|
1 | 1 | package io.sloeber.ui;
|
2 | 2 |
|
| 3 | +import org.eclipse.cdt.core.model.CoreModel; |
| 4 | +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
| 5 | +import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
3 | 6 | import org.eclipse.core.resources.IProject;
|
4 | 7 | import org.eclipse.jface.viewers.ILabelDecorator;
|
5 | 8 | import org.eclipse.jface.viewers.ILabelProviderListener;
|
6 | 9 | import org.eclipse.swt.graphics.Image;
|
7 | 10 |
|
| 11 | +import io.sloeber.core.api.BoardDescriptor; |
8 | 12 | import io.sloeber.core.api.Sketch;
|
9 | 13 |
|
10 | 14 | public class ExplorerLabelDecorator implements ILabelDecorator {
|
11 | 15 |
|
12 |
| - @Override |
13 |
| - public void addListener(ILabelProviderListener listener) { |
14 |
| - // nothing to do here |
| 16 | + @Override |
| 17 | + public void addListener(ILabelProviderListener listener) { |
| 18 | + // nothing to do here |
15 | 19 |
|
16 |
| - } |
| 20 | + } |
17 | 21 |
|
18 |
| - @Override |
19 |
| - public void dispose() { |
20 |
| - // nothing to do here |
| 22 | + @Override |
| 23 | + public void dispose() { |
| 24 | + // nothing to do here |
21 | 25 |
|
22 |
| - } |
| 26 | + } |
23 | 27 |
|
24 |
| - @Override |
25 |
| - public boolean isLabelProperty(Object element, String property) { |
26 |
| - return false; |
27 |
| - } |
| 28 | + @Override |
| 29 | + public boolean isLabelProperty(Object element, String property) { |
| 30 | + return false; |
| 31 | + } |
28 | 32 |
|
29 |
| - @Override |
30 |
| - public void removeListener(ILabelProviderListener listener) { |
31 |
| - // nothing to do here |
| 33 | + @Override |
| 34 | + public void removeListener(ILabelProviderListener listener) { |
| 35 | + // nothing to do here |
32 | 36 |
|
33 |
| - } |
| 37 | + } |
34 | 38 |
|
35 |
| - @Override |
36 |
| - public Image decorateImage(Image image, Object element) { |
37 |
| - return null; |
38 |
| - } |
| 39 | + @Override |
| 40 | + public Image decorateImage(Image image, Object element) { |
| 41 | + return null; |
| 42 | + } |
39 | 43 |
|
40 |
| - @Override |
41 |
| - public String decorateText(String text, Object element) { |
42 |
| - IProject proj = (IProject) element; |
43 |
| - if (proj.isOpen()) { |
44 |
| - if (Sketch.isSketch(proj)) { |
45 |
| - String boardName = Sketch.getBoardName(proj); |
46 |
| - String portName = Sketch.getComport(proj); |
47 |
| - if (portName.isEmpty()) { |
48 |
| - portName = "no port"; //$NON-NLS-1$ |
49 |
| - } |
50 |
| - if (boardName.isEmpty()) { |
51 |
| - boardName = "no Board"; //$NON-NLS-1$ |
| 44 | + @Override |
| 45 | + public String decorateText(String text, Object element) { |
| 46 | + IProject proj = (IProject) element; |
| 47 | + if (proj.isOpen()) { |
| 48 | + if (Sketch.isSketch(proj)) { |
| 49 | + ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(proj); |
| 50 | + ICConfigurationDescription configurationDescription = prjDesc.getActiveConfiguration(); |
| 51 | + BoardDescriptor boardDescriptor = BoardDescriptor.makeBoardDescriptor(configurationDescription); |
| 52 | + String boardName = boardDescriptor.getBoardName(); |
| 53 | + String portName = boardDescriptor.getUploadPort(); |
| 54 | + if (portName.isEmpty()) { |
| 55 | + portName = "no port"; //$NON-NLS-1$ |
| 56 | + } |
| 57 | + if (boardName.isEmpty()) { |
| 58 | + boardName = "no Board"; //$NON-NLS-1$ |
| 59 | + } |
| 60 | + return text + ' ' + boardName + ' ' + ':' + portName; |
| 61 | + } |
52 | 62 | }
|
53 |
| - return text + ' ' + boardName + ' ' + ':' + portName; |
54 |
| - } |
55 |
| - } |
56 | 63 |
|
57 |
| - return null; |
58 |
| - } |
| 64 | + return null; |
| 65 | + } |
59 | 66 |
|
60 | 67 | }
|
0 commit comments