1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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
.tmf
.ui
.project
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.HashMap
;
18 import java
.util
.List
;
21 import org
.eclipse
.core
.resources
.IFolder
;
22 import org
.eclipse
.core
.resources
.IResource
;
23 import org
.eclipse
.core
.runtime
.CoreException
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.properties
.ReadOnlyTextPropertyDescriptor
;
25 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
26 import org
.eclipse
.ui
.views
.properties
.IPropertySource2
;
29 * Implementation of trace folder model element representing the trace folder in the project.
32 * @author Francois Chouinard
34 public class TmfTraceFolder
extends TmfProjectModelElement
implements IPropertySource2
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 * The name of the trace folder
42 public static final String TRACE_FOLDER_NAME
= "Traces"; //$NON-NLS-1$
44 // Property View stuff
45 private static final String sfInfoCategory
= "Info"; //$NON-NLS-1$
46 private static final String sfName
= "name"; //$NON-NLS-1$
47 private static final String sfPath
= "path"; //$NON-NLS-1$
48 private static final String sfLocation
= "location"; //$NON-NLS-1$
50 private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor
= new ReadOnlyTextPropertyDescriptor(sfName
, sfName
);
51 private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor
= new ReadOnlyTextPropertyDescriptor(sfPath
, sfPath
);
52 private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor
= new ReadOnlyTextPropertyDescriptor(sfLocation
,
55 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
,
56 sfLocationDescriptor
};
59 sfNameDescriptor
.setCategory(sfInfoCategory
);
60 sfPathDescriptor
.setCategory(sfInfoCategory
);
61 sfLocationDescriptor
.setCategory(sfInfoCategory
);
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 * Creates trace folder model element under the project.
70 * @param name The name of trace folder.
71 * @param resource The folder resource.
72 * @param parent The parent element (project).
74 public TmfTraceFolder(String name
, IFolder resource
, TmfProjectElement parent
) {
75 super(name
, resource
, parent
);
76 parent
.addChild(this);
79 // ------------------------------------------------------------------------
80 // TmfProjectModelElement
81 // ------------------------------------------------------------------------
84 public IFolder
getResource() {
85 return (IFolder
) fResource
;
89 public TmfProjectElement
getProject() {
90 return (TmfProjectElement
) getParent();
94 void refreshChildren() {
95 IFolder folder
= getResource();
97 // Get the children from the model
98 Map
<String
, ITmfProjectModelElement
> childrenMap
= new HashMap
<>();
99 for (ITmfProjectModelElement element
: getChildren()) {
100 childrenMap
.put(element
.getResource().getName(), element
);
104 IResource
[] members
= folder
.members();
105 for (IResource resource
: members
) {
106 String name
= resource
.getName();
107 ITmfProjectModelElement element
= childrenMap
.get(name
);
108 if (element
instanceof TmfTraceElement
) {
109 childrenMap
.remove(name
);
111 element
= new TmfTraceElement(name
, resource
, this);
113 ((TmfTraceElement
) element
).refreshChildren();
115 } catch (CoreException e
) {
118 // Cleanup dangling children from the model
119 for (ITmfProjectModelElement danglingChild
: childrenMap
.values()) {
120 removeChild(danglingChild
);
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
129 * Returns a list of trace model elements under the traces folder.
130 * @return list of trace model elements
132 public List
<TmfTraceElement
> getTraces() {
133 List
<ITmfProjectModelElement
> children
= getChildren();
134 List
<TmfTraceElement
> traces
= new ArrayList
<>();
135 for (ITmfProjectModelElement child
: children
) {
136 if (child
instanceof TmfTraceElement
) {
137 traces
.add((TmfTraceElement
) child
);
143 // ------------------------------------------------------------------------
145 // ------------------------------------------------------------------------
148 public Object
getEditableValue() {
153 public IPropertyDescriptor
[] getPropertyDescriptors() {
154 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
158 public Object
getPropertyValue(Object id
) {
160 if (sfName
.equals(id
)) {
164 if (sfPath
.equals(id
)) {
165 return getPath().toString();
168 if (sfLocation
.equals(id
)) {
169 return getLocation().toString();
176 public void resetPropertyValue(Object id
) {
180 public void setPropertyValue(Object id
, Object value
) {
184 public boolean isPropertyResettable(Object id
) {
189 public boolean isPropertySet(Object id
) {