Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f65adaf6f86a28894a70ad79172057431a5d66af (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
/*******************************************************************************
 * Copyright (c) 2008-2010 Sonatype, Inc.
 * 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:
 *      Sonatype, Inc. - initial API and implementation
 *******************************************************************************/

package org.eclipse.m2e.core.ui.internal.views;

import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.m2e.core.ui.internal.util.M2EUIUtils;
import org.eclipse.m2e.core.ui.internal.views.nodes.IMavenRepositoryNode;
import org.eclipse.m2e.core.ui.internal.views.nodes.RepositoryNode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

/**
 * RepositoryViewLabelProvider
 *
 * @author dyocum
 */
public class RepositoryViewLabelProvider extends LabelProvider implements IColorProvider, IFontProvider {

  private Font italicFont;
  public RepositoryViewLabelProvider(Font treeFont){
    int size = 0;
    FontData[] data = treeFont.getFontData();
    if(data == null){
      size = 12;
    } else {
      for(int i=0;i<data.length;i++){
        size = Math.max(size, data[i].getHeight());
      }
    }
    italicFont = M2EUIUtils.deriveFont(treeFont, SWT.ITALIC, size);
  }
  
  
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
   */
  public void dispose() {
    italicFont.dispose();
    super.dispose();
  }


  public String getText(Object obj) {
    if(obj instanceof IMavenRepositoryNode){
      return ((IMavenRepositoryNode)obj).getName();
    }
    return obj.toString();
  }

  public Image getImage(Object obj) {
    if(obj instanceof IMavenRepositoryNode){
      return ((IMavenRepositoryNode)obj).getImage();
    }
    return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
  }

  public Color getBackground(Object element) {
    return null;
  }

  public Color getForeground(Object element) {
    if(element instanceof RepositoryNode){
      if(((RepositoryNode)element).isEnabledIndex()){
        return Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
      }
      return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
    } 
    return Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
  }

  public Font getFont(Object element) {
    if(element instanceof IMavenRepositoryNode){
      boolean updating = ((IMavenRepositoryNode)element).isUpdating();
      return updating ? italicFont : null;
    }
    return null;
  }

}

Back to the top