1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.resources
.IFolder
;
19 import org
.eclipse
.core
.resources
.IProject
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.core
.runtime
.CoreException
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.LTTngProjectNature
;
25 * <b><u>LTTngProjectNode</u></b>
27 * TODO: Implement me. Please.
29 public class LTTngProjectNode
extends LTTngProjectTreeNode
{
31 public static final String TRACE_FOLDER_NAME
= "Traces";
32 public static final String EXPER_FOLDER_NAME
= "Experiments";
34 private final IProject fProject
;
35 private boolean fIsLTTngProject
;
36 private boolean fIsOpen
;
37 private LTTngTraceFolderNode fTracesFolder
;
38 private LTTngExperimentFolderNode fExperimentsFolder
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 public LTTngProjectNode(IProject project
) {
48 public LTTngProjectNode(ILTTngProjectTreeNode parent
, IProject project
) {
54 // ------------------------------------------------------------------------
55 // LTTngProjectTreeNode
56 // ------------------------------------------------------------------------
58 public String
getName() {
59 return fProject
.getName();
63 public void refreshChildren() {
65 if (!(fIsOpen
&& fIsLTTngProject
))
69 IResource
[] resources
= fProject
.members();
70 for (IResource resource
: resources
) {
71 if (resource
.getType() == IResource
.FOLDER
) {
72 String name
= resource
.getName();
73 if (name
.equals(TRACE_FOLDER_NAME
) && !isIncluded(true, name
, fChildren
)) {
74 fTracesFolder
= new LTTngTraceFolderNode(this, (IFolder
) resource
);
75 fChildren
.add(fTracesFolder
);
77 if (name
.equals(EXPER_FOLDER_NAME
) && !isIncluded(false, name
, fChildren
)) {
78 fExperimentsFolder
= new LTTngExperimentFolderNode(this, (IFolder
) resource
);
79 fChildren
.add(fExperimentsFolder
);
83 List
<ILTTngProjectTreeNode
> toRemove
= new ArrayList
<ILTTngProjectTreeNode
>();
84 for (ILTTngProjectTreeNode node
: fChildren
) {
85 if (exists(node
.getName(), resources
)) {
86 node
.refreshChildren();
92 for (ILTTngProjectTreeNode node
: toRemove
) {
93 fChildren
.remove(node
);
96 } catch (CoreException e
) {
100 private boolean isIncluded(boolean isTraces
, String name
, List
<ILTTngProjectTreeNode
> list
) {
101 boolean found
= false;
102 for (ILTTngProjectTreeNode node
: list
) {
103 if (node
instanceof LTTngTraceFolderNode
&& isTraces
) {
104 found
|= node
.getName().equals(name
);
106 if (node
instanceof LTTngExperimentFolderNode
&& !isTraces
) {
107 found
|= node
.getName().equals(name
);
113 private boolean exists(String name
, IResource
[] resources
) {
114 for (IResource resource
: resources
) {
115 if (resource
.getName().equals(name
))
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
125 public void openProject() {
130 } catch (CoreException e
) {
135 public void closeProject() {
137 fProject
.close(null);
140 } catch (CoreException e
) {
145 private boolean isLTTngProject(IProject project
) {
146 boolean result
= false;
147 if (project
!= null && project
.isAccessible()) {
149 result
= project
.hasNature(LTTngProjectNature
.ID
);
150 } catch (CoreException e
) {
156 public void updateState() {
157 fIsOpen
= (fProject
!= null) ? fProject
.isAccessible() : false;
158 fIsLTTngProject
= isLTTngProject(fProject
);
161 // ------------------------------------------------------------------------
163 // ------------------------------------------------------------------------
168 public boolean isLTTngProject() {
169 return fIsLTTngProject
;
175 public boolean isOpen() {
182 public IProject
getProject() {
189 public LTTngTraceFolderNode
getTracesFolder() {
190 return fTracesFolder
;
196 public LTTngExperimentFolderNode
getExperimentsFolder() {
197 return fExperimentsFolder
;