Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b00a472e828dbe0d12e5ae57ee0cd58bf0155868 (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
/*******************************************************************************
 * 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.nodes;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.index.IndexedArtifact;
import org.eclipse.m2e.core.internal.index.nexus.IndexedArtifactGroup;
import org.eclipse.m2e.core.internal.index.nexus.NexusIndexManager;

import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

/**
 * IndexedArtifactGroupNode
 *
 * @author dyocum
 */
public class IndexedArtifactGroupNode implements IMavenRepositoryNode, IArtifactNode {

  private IndexedArtifactGroup indexedArtifactGroup;
  private Object[] kids = null;
  public IndexedArtifactGroupNode(IndexedArtifactGroup group){
    this.indexedArtifactGroup = group;
  }
  /* (non-Javadoc)
   * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#getChildren()
   */
  public Object[] getChildren() {
    NexusIndexManager indexManager = (NexusIndexManager) MavenPlugin.getIndexManager();
    
    IndexedArtifactGroup resolvedGroup = indexManager.resolveGroup(indexedArtifactGroup);
    //IndexedArtifactGroup resolvedGroup = indexedArtifactGroup;
    ArrayList<Object> results = new ArrayList<Object>();
    Collection<IndexedArtifactGroup> groups = resolvedGroup.getNodes().values();
    for(IndexedArtifactGroup group : groups){
     IndexedArtifactGroupNode node = new IndexedArtifactGroupNode(group); 
     results.add(node);
    }
    
    Collection<IndexedArtifact> artifacts = resolvedGroup.getFiles().values(); // IndexedArtifact
    for(IndexedArtifact artifact : artifacts){
      IndexedArtifactNode artifactNode = new IndexedArtifactNode(artifact);
      results.add(artifactNode);
    }
    kids = results.toArray(new Object[results.size()]);
    return kids;
  }

  /* (non-Javadoc)
   * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#getName()
   */
  public String getName() {
    String prefix = indexedArtifactGroup.getPrefix();
    int n = prefix.lastIndexOf('.');
    return n < 0 ? prefix : prefix.substring(n + 1);
  }

  /* (non-Javadoc)
   * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#hasChildren()
   */
  public boolean hasChildren() {
//    if(kids == null){
//      kids = getChildren();
//    }
//    return kids != null && kids.length > 0;
    return true;
  }
  /* (non-Javadoc)
   * @see org.eclipse.m2e.ui.internal.views.nodes.IMavenRepositoryNode#getImage()
   */
  public Image getImage() {
    return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
  }
  /* (non-Javadoc)
   * @see org.eclipse.m2e.ui.internal.views.nodes.IArtifactNode#getDocumentKey()
   */
  public String getDocumentKey() {
    return indexedArtifactGroup.getPrefix();
  }
  /* (non-Javadoc)
   * @see org.eclipse.m2e.ui.internal.views.nodes.IMavenRepositoryNode#isUpdating()
   */
  public boolean isUpdating() {
    // TODO Auto-generated method isUpdating
    return false;
  }

}

Back to the top