KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > model > NamedModelObject


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.ui.model;
12
13 import java.io.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.jface.resource.*;
17 import org.eclipse.ui.model.*;
18
19 public class NamedModelObject extends UIModelObject
20                             implements IWorkbenchAdapter, Serializable {
21
22     private static final long serialVersionUID = 1L;
23     private String JavaDoc name;
24     transient private NamedModelObject parent;
25     
26     public static final String JavaDoc P_NAME="p_name"; //$NON-NLS-1$
27

28     public NamedModelObject() {
29     }
30     
31     public NamedModelObject(String JavaDoc name) {
32         this.name = name;
33     }
34     
35     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
36         if (adapter.equals(IWorkbenchAdapter.class)) {
37             return this;
38         }
39         return super.getAdapter(adapter);
40     }
41     
42     public String JavaDoc getName() {
43         return name;
44     }
45     
46     public IPath getPath() {
47         Object JavaDoc parent = getParent(null);
48         if (parent!=null && parent instanceof NamedModelObject)
49             return ((NamedModelObject)parent).getPath().append(getName());
50         else
51             return new Path(getName());
52     }
53     
54     public String JavaDoc toString() {
55         return getName();
56     }
57     
58     public void setName(String JavaDoc name) {
59         this.name = name;
60         notifyObjectChanged(P_NAME);
61     }
62     
63     /**
64      * @see IWorkbenchAdapter#getChildren(Object)
65      */

66     public Object JavaDoc[] getChildren(Object JavaDoc parent) {
67         return null;
68     }
69
70
71     /**
72      * @see IWorkbenchAdapter#getImageDescriptor(Object)
73      */

74     public ImageDescriptor getImageDescriptor(Object JavaDoc obj) {
75         return null;
76     }
77
78
79     /**
80      * @see IWorkbenchAdapter#getLabel(Object)
81      */

82     public String JavaDoc getLabel(Object JavaDoc obj) {
83         return getName();
84     }
85
86
87     /**
88      * @see IWorkbenchAdapter#getParent(Object)
89      */

90     public Object JavaDoc getParent(Object JavaDoc arg0) {
91         return parent;
92     }
93     public void setParent(NamedModelObject parent) {
94         this.parent = parent;
95     }
96 }
97
Popular Tags