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 // ------------------------------------------------------------------------
59 public String
getName() {
60 return fProject
.getName();
64 public void refreshChildren() {
66 if (!(fIsOpen
&& fIsLTTngProject
))
70 IResource
[] resources
= fProject
.members();
71 for (IResource resource
: resources
) {
72 if (resource
.getType() == IResource
.FOLDER
) {
73 String name
= resource
.getName();
74 if (name
.equals(TRACE_FOLDER_NAME
) && !isIncluded(true, name
, fChildren
)) {
75 fTracesFolder
= new LTTngTraceFolderNode(this, (IFolder
) resource
);
76 fChildren
.add(fTracesFolder
);
78 if (name
.equals(EXPER_FOLDER_NAME
) && !isIncluded(false, name
, fChildren
)) {
79 fExperimentsFolder
= new LTTngExperimentFolderNode(this, (IFolder
) resource
);
80 fChildren
.add(fExperimentsFolder
);
84 List
<ILTTngProjectTreeNode
> toRemove
= new ArrayList
<ILTTngProjectTreeNode
>();
85 for (ILTTngProjectTreeNode node
: fChildren
) {
86 if (exists(node
.getName(), resources
)) {
87 node
.refreshChildren();
93 for (ILTTngProjectTreeNode node
: toRemove
) {
94 fChildren
.remove(node
);
97 } catch (CoreException e
) {
101 private boolean isIncluded(boolean isTraces
, String name
, List
<ILTTngProjectTreeNode
> list
) {
102 boolean found
= false;
103 for (ILTTngProjectTreeNode node
: list
) {
104 if (node
instanceof LTTngTraceFolderNode
&& isTraces
) {
105 found
|= node
.getName().equals(name
);
107 if (node
instanceof LTTngExperimentFolderNode
&& !isTraces
) {
108 found
|= node
.getName().equals(name
);
114 private boolean exists(String name
, IResource
[] resources
) {
115 for (IResource resource
: resources
) {
116 if (resource
.getName().equals(name
))
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
126 public void openProject() {
131 } catch (CoreException e
) {
136 public void closeProject() {
138 fProject
.close(null);
141 } catch (CoreException e
) {
146 private boolean isLTTngProject(IProject project
) {
147 boolean result
= false;
148 if (project
!= null && project
.isAccessible()) {
150 result
= project
.hasNature(LTTngProjectNature
.ID
);
151 } catch (CoreException e
) {
157 public void updateState() {
158 fIsOpen
= (fProject
!= null) ? fProject
.isAccessible() : false;
159 fIsLTTngProject
= isLTTngProject(fProject
);
162 // ------------------------------------------------------------------------
164 // ------------------------------------------------------------------------
169 public boolean isLTTngProject() {
170 return fIsLTTngProject
;
176 public boolean isOpen() {
183 public IProject
getProject() {
190 public LTTngTraceFolderNode
getTracesFolder() {
191 return fTracesFolder
;
197 public LTTngExperimentFolderNode
getExperimentsFolder() {
198 return fExperimentsFolder
;