summaryrefslogtreecommitdiff
path: root/src/com/google/gct/testing/TwoPanelTree.java
blob: 1f2966b6b2a7458677772d59fe405e7bdffa3c19 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.gct.testing;

import com.google.common.base.Function;
import com.google.gct.testing.dimension.CloudConfigurationDimension;
import com.google.gct.testing.dimension.CloudTestingType;
import com.google.gct.testing.dimension.CloudTestingTypeGroup;
import com.intellij.openapi.ui.Splitter;
import com.intellij.ui.CheckboxTree;
import com.intellij.ui.CheckboxTreeBase.CheckPolicy;
import com.intellij.ui.CheckboxTreeBase.NodeState;
import com.intellij.ui.CheckedTreeNode;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.JBList;
import com.intellij.util.containers.HashMap;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import static com.android.tools.idea.run.CloudConfiguration.Kind.SINGLE_DEVICE;
import static com.intellij.ui.SimpleTextAttributes.REGULAR_ATTRIBUTES;
import static com.intellij.ui.SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
import static javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION;


@SuppressWarnings("ALL")
public class TwoPanelTree extends MouseAdapter implements ListSelectionListener, KeyListener {

  private final DefaultListModel listModel;
  // Main Panel which contains everything
  private final JPanel myPanel;
  // Contains a list of the roots
  private final JPanel leftPanel;
  // Contains the tree view
  private final JPanel rightPanel;
  // Contains the left and right panels
  private final Splitter mySplitter;
  // Panel to contain the splitter to display the border.
  private final JPanel mySplitterPanel;
  // Contains controls
  private final JPanel topPanel;
  // Contains additional information
  private final JPanel bottomPanel;

  // Trees
  private Map<CloudConfigurationDimension,CheckboxTree> treeMap;
  private JBList list;

  // The configuration which we need to keep in sync with this view
  private CloudConfigurationImpl configuration;

  // Listeners
  List<TwoPanelTreeSelectionListener> listeners = new LinkedList<TwoPanelTreeSelectionListener>();
  private JLabel myConfigurationCountLabel = new JLabel();

  public TwoPanelTree(CloudConfigurationImpl configuration) {
    this.configuration = configuration;
    myPanel = new JPanel(new BorderLayout());
    myPanel.setPreferredSize(new Dimension(520, 240));
    mySplitterPanel = new JPanel(new BorderLayout());
    mySplitterPanel.setBorder(BorderFactory.createLineBorder(UIUtil.getBorderColor()));
    mySplitter = new Splitter(false);
    mySplitter.getDivider().setBorder(BorderFactory.createLineBorder(UIUtil.getBorderColor()));
    mySplitter.setProportion(0.3f);
    leftPanel = new JPanel(new BorderLayout());
    rightPanel = new JPanel(new BorderLayout());

    FlowLayout flowLayout = new FlowLayout(FlowLayout.RIGHT);
    flowLayout.setHgap(15);
    flowLayout.setVgap(10);
    topPanel = new JPanel(flowLayout);
    bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    listModel = new DefaultListModel();

    init();
  }

  public void init() {
    myPanel.add(topPanel, BorderLayout.NORTH);
    if (configuration.getKind() != SINGLE_DEVICE) {
      populateTopPanel();
      bottomPanel.setBackground(UIUtil.getListBackground());
      myPanel.add(bottomPanel, BorderLayout.SOUTH);
      populateBottomPanel();
    }

    mySplitter.setFirstComponent(leftPanel);
    JScrollPane scrollPane = new JScrollPane(rightPanel);
    scrollPane.setBorder(null);
    mySplitter.setSecondComponent(scrollPane);
    mySplitterPanel.add(mySplitter, BorderLayout.CENTER);
    myPanel.add(mySplitterPanel, BorderLayout.CENTER);

    treeMap = new HashMap<CloudConfigurationDimension, CheckboxTree>();
    list = new JBList();

    // Add the dimensions
    for (CloudConfigurationDimension dimension : configuration.getDimensions()) {
      addDimension(dimension);
    }

    leftPanel.add(list, BorderLayout.CENTER);
    list.setModel(listModel);
    list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    list.setCellRenderer(new EnhancedCellRenderer());

    list.addListSelectionListener(this);

    // Make an inital selection
    list.setSelectedIndex(0);
  }

  private void populateBottomPanel() {
    bottomPanel.setBorder(BorderFactory.createLineBorder(UIUtil.getBorderColor(), 1));
    updateConfigurationCountLabel();
    bottomPanel.add(myConfigurationCountLabel);
  }

  double linearGrowth = 0.05;
  double logGrowth = 0.02;
  Random rand = new Random(42);

  // TODO: This blows off for a reasonably big number of combinations (e.g., >15K).
  private double computeCoverage(int combinations) {
    if (combinations == 0) {
      return 0;
    }
    double growthFactor = 1d / combinations * 0.1;
    double prevValue = computeCoverage(combinations - 1);
    return prevValue + (1d - prevValue) * growthFactor;
  }

  private void updateConfigurationCountLabel() {
    int numberOfConfigurations = configuration.getDeviceConfigurationCount();
    //double coverage = computeCoverage(configuration.countCombinationsCollapsingOrientation()) * 100d;
    //TODO: Put back the covered % after it is not fake (or it is needed for demo purposes).
    //myConfigurationCountLabel.setText("<html>Tests will run on <b>" + numberOfConfigurations + " configurations</b> and cover <b>" +
    //                                  (int) Math.ceil(coverage) + "%</b> of current users.</html>");
    myConfigurationCountLabel.setText("<html>Tests will run on <b>" + numberOfConfigurations + " configurations</b>.</html>");
    if (numberOfConfigurations < 1) {
      myConfigurationCountLabel.setForeground(JBColor.RED);
    } else {
      myConfigurationCountLabel.setForeground(UIUtil.getActiveTextColor());
    }
  }

  private void populateTopPanel() {
    Component add = topPanel.add(makeTextButton("Select all", new MouseAdapter() {
      public void mouseClicked(final MouseEvent e) {
        if (getSelectedDimension().isEditable()) {
          getSelectedDimension().enableAll();
          updateCurrentCheckboxTree(new Function<CheckedTreeNode, Void>() {
            @Override
            public Void apply(CheckedTreeNode treeNode) {
              treeNode.setChecked(true);
              return null;
            }
          });
        }
      }
    }));
    topPanel.add(makeTextButton("Select none", new MouseAdapter() {
      public void mouseClicked(final MouseEvent e) {
        if (getSelectedDimension().isEditable()) {
          getSelectedDimension().disableAll();
          updateCurrentCheckboxTree(new Function<CheckedTreeNode, Void>() {
            @Override
            public Void apply(CheckedTreeNode treeNode) {
              treeNode.setChecked(false);
              return null;
            }
          });
        }
      }
    }));
  }

  private void updateCurrentCheckboxTree(Function<CheckedTreeNode, Void> updateFunction) {
    CloudConfigurationDimension selectedDimension = getSelectedDimension();
    CheckboxTree currentCheckboxTree = treeMap.get(selectedDimension);
    CheckedTreeNode rootNode = (CheckedTreeNode) currentCheckboxTree.getModel().getRoot();
    updateNode(rootNode, updateFunction);
    updateUI(currentCheckboxTree);
    selectedDimension.dimensionChanged();
    updateConfigurationCountLabel();
    list.updateUI();
  }

  private void updateNode(CheckedTreeNode node, Function<CheckedTreeNode, Void> updateFunction) {
    for (int childIndex = 0; childIndex < node.getChildCount(); childIndex++) {
      CheckedTreeNode child = (CheckedTreeNode)node.getChildAt(childIndex);
      updateFunction.apply(child);
      updateNode(child, updateFunction);
    }
  }

  private void updateUI(CheckboxTree checkboxTree) {
    checkboxTree.updateUI();
    BasicTreeUI ui = (BasicTreeUI) checkboxTree.getUI();
  }

  private JLabel makeTextButton(final String text, MouseAdapter mouseAdapter) {
    JLabel label = new JLabel(text);
    label.setForeground(JBColor.BLUE);
    label.setFont(new Font("Sans", Font.PLAIN, 11));
    label.setCursor(new Cursor(Cursor.HAND_CURSOR));

    label.addMouseListener(mouseAdapter);
    return label;
  }

  public void addDimension(CloudConfigurationDimension dimension) {

    // Add this dimension as a list item.
    listModel.addElement(dimension);

    CheckedTreeNode rootNode = new CheckedTreeNode(dimension); // Not really necessary since parent not visible
    CheckPolicy radioButtonsCheckPolicy = new CheckPolicy(false, false, false, false);
    // Create a new tree with root node for this dimension.
    CheckboxTree tree = configuration.getKind() == SINGLE_DEVICE
                        ? new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer(){}, rootNode, radioButtonsCheckPolicy)
                        : new CheckboxTree();
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    tree.setModel(treeModel);

    // Tweak tree appearence
    tree.setRootVisible(false);
    updateUI(tree);

    tree.getSelectionModel().setSelectionMode(SINGLE_TREE_SELECTION);

    // Add each supported type to the tree.
    List<? extends CloudTestingTypeGroup> supportedGroups = dimension.getSupportedGroups();
    for (CloudTestingTypeGroup group : supportedGroups) {
      List<CloudTestingType> types = group.getTypes();
      if (types.size() == 1 && !dimension.shouldBeAlwaysGrouped()) {
        addChildNode(rootNode, types.get(0), dimension);
      } else {
        CheckedTreeNode groupNode = new CheckedTreeNode(group);
        rootNode.add(groupNode);
        groupNode.setEnabled(dimension.isEditable());
        for (CloudTestingType type : types) {
          addChildNode(groupNode, type, dimension);
        }
      }
    }

    // Record the tree.
    treeMap.put(dimension, tree);

    tree.setCellRenderer(configuration.getKind() == SINGLE_DEVICE ? new RadioButtonRenderer() : new CheckBoxRenderer());

    treeModel.reload();

    // add listeners
    tree.addMouseListener(this);
    tree.addKeyListener(this);
  }

  public JPanel getPanel() {
    return myPanel;
  }

  private void addChildNode(CheckedTreeNode parentNode, CloudTestingType type, CloudConfigurationDimension dimension) {
    CheckedTreeNode newNode = new CheckedTreeNode(type);
    parentNode.add(newNode);
    newNode.setChecked(dimension.getEnabledTypes().contains(type));
    newNode.setEnabled(dimension.isEditable());
  }

  @Override
  public void valueChanged(ListSelectionEvent e) {
    // Switch to the tree corresponding to the selected dimension
    rightPanel.removeAll();
    CheckboxTree currentTree = treeMap.get(getSelectedDimension());
    rightPanel.add(currentTree, BorderLayout.CENTER);
    rightPanel.updateUI();
    for (TwoPanelTreeSelectionListener listener : listeners) {
      listener.dimensionSelectionChanged(new TwoPanelTreeDimensionSelectionEvent(getSelectedDimension()));
    }
  }

  private CloudConfigurationDimension getSelectedDimension() {
    return (CloudConfigurationDimension) list.getModel().getElementAt(list.getSelectedIndex());
  }

  public void addSelectionListener(TwoPanelTreeSelectionListener treeSelectionListener) {
    listeners.add(treeSelectionListener);
  }

  @Override
  public void mouseClicked(MouseEvent e) {
    updateState();
  }

  @Override
  public void keyTyped(KeyEvent e) {
    updateState();
  }

  @Override
  public void keyPressed(KeyEvent e) {
    updateState();
  }

  @Override
  public void keyReleased(KeyEvent e) {
    updateState();
  }

  private void updateState() {
    CheckboxTree currentTree = treeMap.get(getSelectedDimension());

    if (currentTree == null || currentTree.getSelectionPath() == null) {
      return;
    }

    if (configuration.getKind() == SINGLE_DEVICE) {
      updateRadioButtonTreeState(currentTree);
    } else {
      updateCheckBoxTreeState(currentTree);
    }

    updateConfigurationCountLabel();
    list.updateUI();
  }

  private void updateCheckBoxTreeState(CheckboxTree currentTree) {
    CloudConfigurationDimension currentDimension = getSelectedDimension();
    CheckedTreeNode selectedNode = (CheckedTreeNode) currentTree.getSelectionPath().getLastPathComponent();
    Object userObject = selectedNode.getUserObject();
    if (userObject instanceof CloudTestingType) {
      CloudTestingType clickedType = (CloudTestingType)userObject;
      if (selectedNode.isEnabled()) {
        currentDimension.setEnabled(clickedType, selectedNode.isChecked());
        currentDimension.dimensionChanged();
      }
      for (TwoPanelTreeSelectionListener listener : listeners) {
        listener.typeSelectionChanged(new TwoPanelTreeTypeSelectionEvent(currentDimension, clickedType));
      }
    } else {
      CloudTestingTypeGroup clickedGroup = (CloudTestingTypeGroup) userObject;
      if (selectedNode.isEnabled()) {
        for (int childIndex = 0; childIndex < selectedNode.getChildCount(); childIndex++) {
          CheckedTreeNode child = (CheckedTreeNode)selectedNode.getChildAt(childIndex);
          currentDimension.setEnabled((CloudTestingType) child.getUserObject(), child.isChecked());
        }
        currentDimension.dimensionChanged();
      }
      for (TwoPanelTreeSelectionListener listener : listeners) {
        listener.groupSelectionChanged(new TwoPanelTreeTypeGroupSelectionEvent(currentDimension, clickedGroup));
      }
    }
  }

  private void updateRadioButtonTreeState(CheckboxTree currentTree) {
    CloudConfigurationDimension currentDimension = getSelectedDimension();
    CheckedTreeNode selectedNode = (CheckedTreeNode) currentTree.getSelectionPath().getLastPathComponent();
    Object userObject = selectedNode.getUserObject();
    if (userObject instanceof CloudTestingType) {
      CloudTestingType clickedType = (CloudTestingType)userObject;
      if (selectedNode.isEnabled() && (selectedNode.isChecked() || !isAnythingChecked(currentTree))) {
        uncheckAll(currentTree);
        selectedNode.setChecked(true);
        currentDimension.disableAll();
        currentDimension.enable(clickedType);
        currentDimension.dimensionChanged();
      }
      for (TwoPanelTreeSelectionListener listener : listeners) {
        listener.typeSelectionChanged(new TwoPanelTreeTypeSelectionEvent(currentDimension, clickedType));
      }
    } else {
      CloudTestingTypeGroup clickedGroup = (CloudTestingTypeGroup) userObject;
      for (TwoPanelTreeSelectionListener listener : listeners) {
        listener.groupSelectionChanged(new TwoPanelTreeTypeGroupSelectionEvent(currentDimension, clickedGroup));
      }
    }
  }

  private void uncheckAll(CheckboxTree currentTree) {
    TreeNode root = (TreeNode)currentTree.getModel().getRoot();
    for (int i = 0; i < root.getChildCount(); i++) {
      CheckedTreeNode firstLevelChild = (CheckedTreeNode)root.getChildAt(i);
      firstLevelChild.setChecked(false);
      if (!firstLevelChild.isLeaf()) {
        for (int j = 0; j < firstLevelChild.getChildCount(); j++) {
          ((CheckedTreeNode)firstLevelChild.getChildAt(j)).setChecked(false);
        }
      }
    }
  }

  private boolean isAnythingChecked(CheckboxTree currentTree) {
    TreeNode root = (TreeNode)currentTree.getModel().getRoot();
    for (int i = 0; i < root.getChildCount(); i++) {
      CheckedTreeNode firstLevelChild = (CheckedTreeNode)root.getChildAt(i);
      if (firstLevelChild.isChecked()) {
        return true;
      }
      if (!firstLevelChild.isLeaf()) {
        for (int j = 0; j < firstLevelChild.getChildCount(); j++) {
          if (((CheckedTreeNode)firstLevelChild.getChildAt(j)).isChecked()) {
            return true;
          }
        }
      }
    }
    return false;
  }

  private static class CheckBoxRenderer extends CheckboxTree.CheckboxTreeCellRenderer {
    @Override
    public void customizeRenderer(final JTree tree, Object value, final boolean selected, final boolean expanded, final boolean leaf,
                                  final int row, final boolean hasFocus) {

      if (value instanceof DefaultMutableTreeNode) {
        Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
        if (userObject instanceof CloudTestingType) {
          CloudTestingType cloudTestingType = (CloudTestingType)userObject;
          getTextRenderer().append(cloudTestingType.getConfigurationDialogDisplayName(),
                                   ((CheckedTreeNode) value).isChecked() ? REGULAR_BOLD_ATTRIBUTES : REGULAR_ATTRIBUTES);
          updateTreeState(tree, (CheckedTreeNode)value, cloudTestingType);
        } else if (userObject instanceof CloudTestingTypeGroup) {
          CloudTestingTypeGroup group = (CloudTestingTypeGroup)userObject;
          getTextRenderer().append(group.getName(),
                                   hasCheckedChildren((CheckedTreeNode) value) ? REGULAR_BOLD_ATTRIBUTES : REGULAR_ATTRIBUTES);
          CloudTestingType type = (CloudTestingType) ((CheckedTreeNode) ((DefaultMutableTreeNode)value).getChildAt(0)).getUserObject();
          updateTreeState(tree, (CheckedTreeNode)value, type);
        }
      }
    }

    private boolean hasCheckedChildren(CheckedTreeNode node) {
      for (int i = 0; i < node.getChildCount(); i++) {
        if (((CheckedTreeNode)node.getChildAt(i)).isChecked()) {
          return true;
        }
      }
      return false;
    }

    private void updateTreeState(JTree tree, CheckedTreeNode node, CloudTestingType cloudTestingType) {
      if (node.isEnabled()) {
        //getTextRenderer().setForeground(Color.BLACK);
      } else {
        //getTextRenderer().setForeground(Color.LIGHT_GRAY);
        CloudConfigurationDimension dimension = (CloudConfigurationDimension)((CheckedTreeNode) tree.getModel().getRoot()).getUserObject();
        boolean isChecked = dimension.getEnabledTypes().contains(cloudTestingType);
        node.setChecked(isChecked);
        for (int childIndex = 0; childIndex < node.getChildCount(); childIndex++) {
          ((CheckedTreeNode) node.getChildAt(childIndex)).setChecked(isChecked);
        }
      }
    }
  }

  private static class RadioButtonRenderer extends JPanel implements TreeCellRenderer {
    private final ColoredTreeCellRenderer myTextRenderer;
    public final JRadioButton myRadioButton;
    private final boolean myUsePartialStatusForParentNodes;

    public RadioButtonRenderer() {
      this(true);
    }

    public RadioButtonRenderer(boolean opaque) {
      this(opaque, true);
    }

    public RadioButtonRenderer(boolean opaque, final boolean usePartialStatusForParentNodes) {
      super(new BorderLayout());
      myUsePartialStatusForParentNodes = usePartialStatusForParentNodes;
      myRadioButton = new JRadioButton();
      myTextRenderer = new ColoredTreeCellRenderer() {
        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row,
                                          boolean hasFocus) {}
      };
      myTextRenderer.setOpaque(opaque);
      add(myRadioButton, BorderLayout.WEST);
      add(myTextRenderer, BorderLayout.CENTER);
    }

    public void updateTreeState(JTree tree, CheckedTreeNode node, CloudTestingType cloudTestingType) {
      if (node.isEnabled()) {
        //getTextRenderer().setForeground(Color.BLACK);
      } else {
        //getTextRenderer().setForeground(Color.LIGHT_GRAY);
        CloudConfigurationDimension dimension = (CloudConfigurationDimension)((CheckedTreeNode) tree.getModel().getRoot()).getUserObject();
        boolean isChecked = dimension.getEnabledTypes().contains(cloudTestingType);
        node.setChecked(isChecked);
      }
    }

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row,
                                                  boolean hasFocus) {

      invalidate();
      if (value instanceof CheckedTreeNode) {
        CheckedTreeNode node = (CheckedTreeNode)value;

        NodeState state = getNodeStatus(node);
        myRadioButton.setVisible(leaf);

        myRadioButton.setSelected(state != NodeState.CLEAR);
        myRadioButton.setEnabled(node.isEnabled() && state != NodeState.PARTIAL);
        myRadioButton.setOpaque(false);
        myRadioButton.setBackground(null);
        setBackground(null);
      } else {
        myRadioButton.setVisible(false);
      }

      myTextRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

      if (UIUtil.isUnderGTKLookAndFeel()) {
        final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
        UIUtil.changeBackGround(this, background);
      }
      else if (UIUtil.isUnderNimbusLookAndFeel()) {
        UIUtil.changeBackGround(this, UIUtil.TRANSPARENT_COLOR);
      }

      revalidate();

      if (value instanceof DefaultMutableTreeNode) {
        Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
        if (userObject instanceof CloudTestingType) {
          CloudTestingType googleCloudTestingType = (CloudTestingType)userObject;

          myTextRenderer.append(googleCloudTestingType.getConfigurationDialogDisplayName(),
                                myRadioButton.isSelected() ? REGULAR_BOLD_ATTRIBUTES : REGULAR_ATTRIBUTES);
          updateTreeState(tree, (CheckedTreeNode)value, googleCloudTestingType);
        } else if (userObject instanceof CloudTestingTypeGroup) {
          CloudTestingTypeGroup group = (CloudTestingTypeGroup)userObject;
          myTextRenderer.append(group.getName(), myRadioButton.isSelected() ? REGULAR_BOLD_ATTRIBUTES : REGULAR_ATTRIBUTES);
          CloudTestingType type = (CloudTestingType)((CheckedTreeNode)((DefaultMutableTreeNode)value).getChildAt(0)).getUserObject();
          updateTreeState(tree, (CheckedTreeNode)value, type);
        }
      }
      return this;
    }

    private NodeState getNodeStatus(final CheckedTreeNode node) {
      final boolean checked = node.isChecked();
      if (node.getChildCount() == 0 || !myUsePartialStatusForParentNodes) return checked ? NodeState.FULL : NodeState.CLEAR;

      NodeState result = null;

      for (int i = 0; i < node.getChildCount(); i++) {
        TreeNode child = node.getChildAt(i);
        NodeState childStatus = child instanceof CheckedTreeNode ? getNodeStatus((CheckedTreeNode)child) :
                                checked ? NodeState.FULL : NodeState.CLEAR;
        if (childStatus == NodeState.PARTIAL) return NodeState.PARTIAL;
        if (result == null) {
          result = childStatus;
        } else if (result != childStatus) {
          return NodeState.PARTIAL;
        }
      }
      return result == null ? NodeState.CLEAR : result;
    }
  }


  private static class EnhancedCellRenderer implements ListCellRenderer {
    protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();

    public Component getListCellRendererComponent(JList list, Object value, int index,
                                                  boolean isSelected, boolean cellHasFocus) {

      JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
                                                                              isSelected, cellHasFocus);
      CloudConfigurationDimension dimension = (CloudConfigurationDimension) value;

      renderer.setIcon(dimension.getIcon());
      renderer.setText(dimension.getDisplayName() +
                       " (" + dimension.getEnabledTypes().size() + "/" + dimension.getSupportedDomain().size() + ")");

      if (dimension.getEnabledTypes().size() < 1) {
        renderer.setForeground(JBColor.RED);
        renderer.setFont(renderer.getFont().deriveFont(Font.BOLD));
      }

      return renderer;
    }
  }
}