Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f2aa8d876be95bb773d53f90e4d9f00589d053d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (c) 2014, 2015 Eike Stepper (Loehne, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.oomph.launches;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.DecorationOverlayIcon;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.swt.graphics.Image;

/**
 * @author Eike Stepper
 */
public class LaunchConfigLabelDecorator extends BaseLabelProvider implements ILabelDecorator // , IColorDecorator
{
  // private static final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED);
  //
  // private static final Color GRAY = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);

  private static final ImageDescriptor LOCAL_OVERLAY = Activator.getImageDescriptor("local_ovr");

  private static final ImageDescriptor EXAMPLE_OVERLAY = Activator.getImageDescriptor("example_ovr");

  private final ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());

  public LaunchConfigLabelDecorator()
  {
  }

  @Override
  public void dispose()
  {
    resourceManager.dispose();
    super.dispose();
  }

  public Image decorateImage(Image image, Object element)
  {
    if (image != null)
    {
      if (isLocal(element))
      {
        DecorationOverlayIcon icon = new DecorationOverlayIcon(image, LOCAL_OVERLAY, IDecoration.TOP_LEFT);
        return (Image)resourceManager.get(icon);
      }

      if (isExampleCopy(element))
      {
        DecorationOverlayIcon icon = new DecorationOverlayIcon(image, EXAMPLE_OVERLAY, IDecoration.TOP_LEFT);
        return (Image)resourceManager.get(icon);
      }
    }

    return null;
  }

  public String decorateText(String text, Object element)
  {
    if (isLocal(element))
    {
      return "* " + text + " [local]";
    }

    if (isExampleCopy(element))
    {
      return "~ " + text + " [example]";
    }

    return null;
  }

  // public Color decorateForeground(Object element)
  // {
  // if (isLocal(element))
  // {
  // return RED;
  // }
  //
  // if (isExampleCopy(element))
  // {
  // return GRAY;
  // }
  //
  // return null;
  // }
  //
  // public Color decorateBackground(Object element)
  // {
  // return null;
  // }

  private boolean isLocal(Object element)
  {
    if (element instanceof ILaunchConfiguration)
    {
      ILaunchConfiguration configuration = (ILaunchConfiguration)element;
      return configuration.isLocal();
    }

    return false;
  }

  private boolean isExampleCopy(Object element)
  {
    if (element instanceof ILaunchConfiguration)
    {
      ILaunchConfiguration configuration = (ILaunchConfiguration)element;
      IFile file = configuration.getFile();
      if (file != null)
      {
        IPath path = file.getFullPath();
        String[] segments = path.segments();
        return segments.length == 4 && segments[1].equals("examples");
      }
    }

    return false;
  }
}

Back to the top