1 /*******************************************************************************
2 * Copyright (c) 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
.tmf
.ui
.project
.model
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
21 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
22 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
23 import org
.eclipse
.core
.runtime
.IPath
;
26 * <b><u>TmfProjectModelElement</u></b>
29 public abstract class TmfProjectModelElement
implements ITmfProjectModelElement
, IResourceChangeListener
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 private final String fName
;
36 protected final IResource fResource
;
37 protected final URI fLocation
;
38 protected final IPath fPath
;
39 private final ITmfProjectModelElement fParent
;
40 protected final List
<ITmfProjectModelElement
> fChildren
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 protected TmfProjectModelElement(String name
, IResource resource
, ITmfProjectModelElement parent
) {
49 fPath
= resource
.getFullPath();
50 fLocation
= resource
.getLocationURI();
52 fChildren
= new ArrayList
<ITmfProjectModelElement
>();
53 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this);
56 // ------------------------------------------------------------------------
57 // ITmfProjectModelElement
58 // ------------------------------------------------------------------------
61 public String
getName() {
66 public IResource
getResource() {
71 public IPath
getPath() {
76 public URI
getLocation() {
81 public ITmfProjectModelElement
getParent() {
86 public boolean hasChildren() {
87 return fChildren
.size() > 0;
91 public List
<ITmfProjectModelElement
> getChildren() {
96 public void addChild(ITmfProjectModelElement child
) {
101 public void removeChild(ITmfProjectModelElement child
) {
102 fChildren
.remove(child
);
107 public void refresh() {
108 // Do nothing by default: sub-classes override this on an "as-needed"
112 // ------------------------------------------------------------------------
113 // IResourceChangeListener
114 // ------------------------------------------------------------------------
117 public void resourceChanged(IResourceChangeEvent event
) {
118 // Do nothing by default: sub-classes override this on an "as-needed"
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
127 public int hashCode() {
128 final int prime
= 31;
130 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
131 result
= prime
* result
+ ((fName
== null) ?
0 : fName
.hashCode());
132 result
= prime
* result
+ ((fPath
== null) ?
0 : fPath
.hashCode());
137 public boolean equals(Object other
) {
142 if (!(other
instanceof TmfProjectModelElement
))
144 TmfProjectModelElement element
= (TmfProjectModelElement
) other
;
145 return element
.fName
.equals(fName
) && element
.fLocation
.equals(fLocation
);