KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > DiffNodeWorkbenchAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.team.internal.ui.synchronize;
12
13 import org.eclipse.compare.structuremergeviewer.DiffNode;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.team.ui.synchronize.ISynchronizeModelElement;
16 import org.eclipse.ui.model.IWorkbenchAdapter;
17
18 public class DiffNodeWorkbenchAdapter implements IWorkbenchAdapter {
19
20     /* (non-Javadoc)
21      * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
22      */

23     public Object JavaDoc[] getChildren(Object JavaDoc o) {
24         DiffNode node = getDiffNode(o);
25         return node != null ? node.getChildren() : new Object JavaDoc[0];
26     }
27
28     /* (non-Javadoc)
29      * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
30      */

31     public ImageDescriptor getImageDescriptor(Object JavaDoc o) {
32         DiffNode node = getDiffNode(o);
33         if(node instanceof ISynchronizeModelElement) {
34             return ((ISynchronizeModelElement)node).getImageDescriptor(o);
35         }
36         return null;
37     }
38
39     /* (non-Javadoc)
40      * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
41      */

42     public String JavaDoc getLabel(Object JavaDoc o) {
43         DiffNode node = getDiffNode(o);
44         return node != null ? node.getName() : ""; //$NON-NLS-1$
45
}
46
47     /* (non-Javadoc)
48      * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
49      */

50     public Object JavaDoc getParent(Object JavaDoc o) {
51         DiffNode node = getDiffNode(o);
52         return node != null ? node.getParent() : null;
53     }
54     
55     /*
56      * Return a diff node if the input object is a diff node or null otherwise.
57      */

58     private DiffNode getDiffNode(Object JavaDoc element) {
59         if(element instanceof DiffNode) {
60             return (DiffNode)element;
61         }
62         return null;
63     }
64 }
65
Popular Tags