2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / model / LTTngProjectRoot.java
CommitLineData
6e512b93
ASL
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
13package org.eclipse.linuxtools.lttng.ui.views.project.model;
14
15import java.util.ArrayList;
16import java.util.List;
17
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IWorkspaceRoot;
20import org.eclipse.core.resources.ResourcesPlugin;
21import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView;
22
23/**
24 * <b><u>LTTngProjectRoot</u></b>
25 * <p>
26 * TODO: Implement me. Please.
27 */
28public 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
d4011df2 51 @Override
6e512b93
ASL
52 public String getName() {
53 return null;
54 }
55
56 @Override
57 public void refreshChildren() {
58 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
59 IProject[] projects = root.getProjects();
60 for (IProject project : projects) {
61 LTTngProjectNode node = find(project.getName());
62 if (node == null) {
63 node = new LTTngProjectNode(this, project);
64 fChildren.add(node);
65 } else {
66 node.updateState();
67 }
68 }
69 List<ILTTngProjectTreeNode> toRemove = new ArrayList<ILTTngProjectTreeNode>();
70 for (ILTTngProjectTreeNode node : fChildren) {
71 if (exists(node.getName(), projects)) {
72 node.refreshChildren();
73 }
74 else {
75 toRemove.add(node);
76 }
77 }
78 for (ILTTngProjectTreeNode node : toRemove) {
79 fChildren.remove(node);
80 }
81 }
82
83 private LTTngProjectNode find(String name) {
84 for (ILTTngProjectTreeNode node : fChildren) {
85 if (node instanceof LTTngProjectNode && node.getName().equals(name)) {
86 return (LTTngProjectNode) node;
87 }
88 }
89 return null;
90 }
91
92 private boolean exists(String name, IProject[] projects) {
93 for (IProject project : projects) {
94 if (project.getName().equals(name))
95 return true;
96 }
97 return false;
98 }
99
100}
This page took 0.028924 seconds and 5 git commands to generate.