Skip to main content
summaryrefslogtreecommitdiffstats
blob: af7c1788dec34660c06e62edd7cba81c49a42405 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*******************************************************************************
 * Copyright (c) 2007, 2010 Wind River Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.dsf.ui.viewmodel.properties;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;

/**
 * Class used by the PropertiesBasedLabelProvider to generate store 
 * label attributes related to a single column.  Each column info is 
 * configured with an array of attributes (there are currently four
 * types of attributes: text, image, font, and color), which are 
 * evaluated in order to generate the label.  
 * <p/>
 * Clients are not intended to extend this class.
 * 
 * @see PropertiesBasedLabelProvider
 * 
 * @since 1.0
 */
@ThreadSafe
public class LabelColumnInfo  {
    /** 
     * Calculated list of property names that need to be retrieved to 
     * generate the label for this column.
     */
    private String[] fPropertyNames;
    
    /**
     * Array of label attribute objects.   
     */
    private LabelAttribute[] fLabelAttributes;

    /**
     * Creates the column info object with given array of attributes.
     * @param attributeInfos Attributes for the label.
     */
    public LabelColumnInfo(LabelAttribute[] attributes)
    {
        fLabelAttributes = attributes;

        List<String> names = new LinkedList<String>();
        for (LabelAttribute attr : attributes) {
            for (String name : attr.getPropertyNames()) {
                names.add(name);
            }
        }

        fPropertyNames = names.toArray(new String[names.size()]);
    }
        
    /**
     * Returns the property names that need to be retrieved in order
     * to generate the label for this column.
     */
    public String[] getPropertyNames() { return fPropertyNames; }
    
    /**
     * Returns the list of configured label attributes for this column.
     */
    public LabelAttribute[] getLabelAttributes() { return fLabelAttributes; }

    /**
     * Returns the list of configured label attributes for this column.
     * 
     * @since 2.1
     */
    protected void setLabelAttributes(LabelAttribute[] attributes) { 
    	fLabelAttributes = attributes;

        List<String> names = new LinkedList<String>();
        for (LabelAttribute attr : attributes) {
            for (String name : attr.getPropertyNames()) {
                names.add(name);
            }
        }

        fPropertyNames = names.toArray(new String[names.size()]);
    }    

    /**
     * Inserts an attribute in front of all the other existing attributes.
     * 
     * @since 2.1
     */
    public void insertAttribute(LabelAttribute attribute) {
    	LabelAttribute[] newAttributeList = new LabelAttribute[fLabelAttributes.length+1];
    	
    	for ( int idx = 0 ; idx < fLabelAttributes.length; idx ++ ) {
    		newAttributeList[ idx + 1 ] = fLabelAttributes[ idx ];
    	}
    	
    	newAttributeList[ 0 ] = attribute;
    	
    	setLabelAttributes( newAttributeList );
    }
    
    /**
     * Updates the label parameters for this column based on the provided
     * properties.  The label information is written to the givne label
     * update under the given column index.   
     * 
     * @param update Update to write to.
     * @param columnIndex Column to write label information under.
     * @param status Result of the properties update
     * @param properties Map of properties to use to generate the label.
     * 
     * @since 2.0
     */
    public void updateColumn(ILabelUpdate update, int columnIndex, IStatus status, Map<String,Object> properties) {
        boolean textSet = false;
        boolean imageSet = false;
        boolean fontSet = false;
        boolean foregroundSet = false;
        boolean backgroundSet = false;
        
        LabelAttribute[] labelAttributes = getLabelAttributes();
        for (LabelAttribute info : labelAttributes) {
            
            if (!(info instanceof LabelText && textSet) &&
                !(info instanceof LabelImage && imageSet) &&
                !(info instanceof LabelFont && fontSet) &&
                !(info instanceof LabelForeground && foregroundSet) &&
                !(info instanceof LabelBackground && backgroundSet) &&
                info.isEnabled(status, properties))
            {
                info.updateAttribute(update, columnIndex, status, properties);
                textSet = textSet || info instanceof LabelText;
                imageSet = imageSet || info instanceof LabelImage;
                fontSet = fontSet || info instanceof LabelFont;
                foregroundSet = foregroundSet || info instanceof LabelForeground;
                backgroundSet = backgroundSet || info instanceof LabelBackground;
            }
        }
    }
}

Back to the top