(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / model / LTTngProjectRoot.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.ui.views.project.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.resources.IWorkspaceRoot;
20 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView;
22
23 /**
24 * <b><u>LTTngProjectRoot</u></b>
25 * <p>
26 * TODO: Implement me. Please.
27 */
28 public class LTTngProjectRoot extends LTTngProjectTreeNode {
29
30 private final ProjectView fView;
31
32 // ------------------------------------------------------------------------
33 // Constructors
34 // ------------------------------------------------------------------------
35
36 public LTTngProjectRoot(ProjectView view) {
37 super(null);
38 fView = view;
39 refreshChildren();
40 }
41
42 @Override
43 public void refresh() {
44 fView.refresh();
45 }
46
47 // ------------------------------------------------------------------------
48 // LTTngProjectTreeNode
49 // ------------------------------------------------------------------------
50
51 public String getName() {
52 return null;
53 }
54
55 @Override
56 public void refreshChildren() {
57 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
58 IProject[] projects = root.getProjects();
59 for (IProject project : projects) {
60 LTTngProjectNode node = find(project.getName());
61 if (node == null) {
62 node = new LTTngProjectNode(this, project);
63 fChildren.add(node);
64 } else {
65 node.updateState();
66 }
67 }
68 List<ILTTngProjectTreeNode> toRemove = new ArrayList<ILTTngProjectTreeNode>();
69 for (ILTTngProjectTreeNode node : fChildren) {
70 if (exists(node.getName(), projects)) {
71 node.refreshChildren();
72 }
73 else {
74 toRemove.add(node);
75 }
76 }
77 for (ILTTngProjectTreeNode node : toRemove) {
78 fChildren.remove(node);
79 }
80 }
81
82 private LTTngProjectNode find(String name) {
83 for (ILTTngProjectTreeNode node : fChildren) {
84 if (node instanceof LTTngProjectNode && node.getName().equals(name)) {
85 return (LTTngProjectNode) node;
86 }
87 }
88 return null;
89 }
90
91 private boolean exists(String name, IProject[] projects) {
92 for (IProject project : projects) {
93 if (project.getName().equals(name))
94 return true;
95 }
96 return false;
97 }
98
99 }
This page took 0.0327 seconds and 5 git commands to generate.