1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2011 Ericsson, MontaVista Software
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 * Yufen Kuo (ykuo@mvista.com) - bug 354541: implement IAdaptable Project->Properties action is enabled when project is selected.
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.model
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import org
.eclipse
.core
.resources
.IFolder
;
20 import org
.eclipse
.core
.resources
.IProject
;
21 import org
.eclipse
.core
.resources
.IResource
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.core
.runtime
.IAdaptable
;
24 import org
.eclipse
.core
.runtime
.Platform
;
25 import org
.eclipse
.linuxtools
.lttng
.core
.LTTngProjectNature
;
28 * <b><u>LTTngProjectNode</u></b>
30 * TODO: Implement me. Please.
32 public class LTTngProjectNode
extends LTTngProjectTreeNode
implements IAdaptable
{
34 public static final String TRACE_FOLDER_NAME
= "Traces"; //$NON-NLS-1$
35 public static final String EXPER_FOLDER_NAME
= "Experiments"; //$NON-NLS-1$
37 private final IProject fProject
;
38 private boolean fIsLTTngProject
;
39 private boolean fIsOpen
;
40 private LTTngTraceFolderNode fTracesFolder
;
41 private LTTngExperimentFolderNode fExperimentsFolder
;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 public LTTngProjectNode(IProject project
) {
51 public LTTngProjectNode(ILTTngProjectTreeNode parent
, IProject project
) {
57 // ------------------------------------------------------------------------
58 // LTTngProjectTreeNode
59 // ------------------------------------------------------------------------
62 public String
getName() {
63 return fProject
.getName();
67 public void refreshChildren() {
69 if (!(fIsOpen
&& fIsLTTngProject
))
73 IResource
[] resources
= fProject
.members();
74 for (IResource resource
: resources
) {
75 if (resource
.getType() == IResource
.FOLDER
) {
76 String name
= resource
.getName();
77 if (name
.equals(TRACE_FOLDER_NAME
) && !isIncluded(true, name
, fChildren
)) {
78 fTracesFolder
= new LTTngTraceFolderNode(this, (IFolder
) resource
);
79 fChildren
.add(fTracesFolder
);
81 if (name
.equals(EXPER_FOLDER_NAME
) && !isIncluded(false, name
, fChildren
)) {
82 fExperimentsFolder
= new LTTngExperimentFolderNode(this, (IFolder
) resource
);
83 fChildren
.add(fExperimentsFolder
);
87 List
<ILTTngProjectTreeNode
> toRemove
= new ArrayList
<ILTTngProjectTreeNode
>();
88 for (ILTTngProjectTreeNode node
: fChildren
) {
89 if (exists(node
.getName(), resources
)) {
90 node
.refreshChildren();
96 for (ILTTngProjectTreeNode node
: toRemove
) {
97 fChildren
.remove(node
);
100 } catch (CoreException e
) {
104 private boolean isIncluded(boolean isTraces
, String name
, List
<ILTTngProjectTreeNode
> list
) {
105 boolean found
= false;
106 for (ILTTngProjectTreeNode node
: list
) {
107 if (node
instanceof LTTngTraceFolderNode
&& isTraces
) {
108 found
|= node
.getName().equals(name
);
110 if (node
instanceof LTTngExperimentFolderNode
&& !isTraces
) {
111 found
|= node
.getName().equals(name
);
117 private boolean exists(String name
, IResource
[] resources
) {
118 for (IResource resource
: resources
) {
119 if (resource
.getName().equals(name
))
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
129 public void openProject() {
134 } catch (CoreException e
) {
139 public void closeProject() {
141 fProject
.close(null);
144 } catch (CoreException e
) {
149 private boolean isLTTngProject(IProject project
) {
150 boolean result
= false;
151 if (project
!= null && project
.isAccessible()) {
153 result
= project
.hasNature(LTTngProjectNature
.ID
);
154 } catch (CoreException e
) {
160 public void updateState() {
161 fIsOpen
= (fProject
!= null) ? fProject
.isAccessible() : false;
162 fIsLTTngProject
= isLTTngProject(fProject
);
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
172 public boolean isLTTngProject() {
173 return fIsLTTngProject
;
179 public boolean isOpen() {
186 public IProject
getProject() {
193 public LTTngTraceFolderNode
getTracesFolder() {
194 return fTracesFolder
;
200 public LTTngExperimentFolderNode
getExperimentsFolder() {
201 return fExperimentsFolder
;
205 * Returns the adapter
207 @SuppressWarnings("rawtypes")
208 public Object
getAdapter(Class adapter
) {
209 if (adapter
== IResource
.class) {
212 // Defer to the platform
213 return Platform
.getAdapterManager().getAdapter(this, adapter
);