KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > provider > ViewerNotification


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: ViewerNotification.java,v 1.4 2005/06/08 06:17:05 nickb Exp $
16  */

17 package org.eclipse.emf.edit.provider;
18
19
20 import org.eclipse.emf.common.notify.Notification;
21 import org.eclipse.emf.common.notify.NotificationWrapper;
22
23
24 /**
25  * A simple implementation of <code>IViewerNotification</code> that decorates an ordinary {@link
26  * org.eclipse.emf.common.notify.Notification}.
27  */

28 public class ViewerNotification extends NotificationWrapper implements IViewerNotification
29 {
30   /**
31    * Wraps the given notification to make the given element be operated on by the viewer that receives it. If the
32    * notification is an {@link IViewerNotification}, it is {@link #ViewerNotification(IViewerNotification, Object)
33    * wrapped} in a <code>ViewerNotification</code>, with that element. Otherwise, it is wrapped in a {@link
34    * org.eclipse.emf.common.notify.NotificationWrapper} that returns the element as its <code>notifier</code>.
35    */

36   public static Notification wrapNotification(Notification notification, Object JavaDoc element)
37   {
38     if (notification instanceof IViewerNotification)
39     {
40       return new ViewerNotification((IViewerNotification)notification, element);
41     }
42     return new NotificationWrapper(element, notification);
43   }
44
45   /**
46    * The element to update or from which to refresh. The whole viewer is indicated by the null value.
47    * @see #getElement
48    */

49   protected Object JavaDoc element;
50
51   /**
52    * Whether the content under the element should be structurally refreshed.
53    * @see #isContentRefresh
54    */

55   protected boolean contentRefresh;
56
57   /**
58    * Whether the label and icon for the element should be updated.
59    * @see #isLabelUpdate
60    */

61   protected boolean labelUpdate;
62
63   /**
64    * Creates a notification to fully refresh a viewer.
65    */

66   public ViewerNotification(Notification decoratedNotification)
67   {
68     this(decoratedNotification, null, true, true);
69   }
70
71   /**
72    * Creates a notification to refresh the content under and update the label for the given element.
73    */

74   public ViewerNotification(Notification decoratedNotification, Object JavaDoc element)
75   {
76     this(decoratedNotification, element, true, true);
77   }
78
79   /**
80    * Creates a notification to optionally refresh the content under and update the label for the given element.
81    */

82   public ViewerNotification(Notification decoratedNotification, Object JavaDoc element, boolean contentRefresh, boolean labelUpdate)
83   {
84     super(decoratedNotification);
85     this.element = element;
86     this.contentRefresh = contentRefresh;
87     this.labelUpdate = labelUpdate;
88   }
89
90   /**
91    * Wraps an existing viewer notification to specify a different element.
92    */

93   public ViewerNotification(IViewerNotification viewerNotification, Object JavaDoc element)
94   {
95     this(viewerNotification, element, viewerNotification.isContentRefresh(), viewerNotification.isLabelUpdate());
96   }
97   
98   /**
99    * Returns the element to update or from which to refresh.
100    */

101   public Object JavaDoc getElement()
102   {
103     return element;
104   }
105
106   /**
107    * Returns whether the content under the element should be structurally refreshed.
108    */

109   public boolean isContentRefresh()
110   {
111     return contentRefresh;
112   }
113
114   /**
115    * Returns whether the label and icon for the element should be updated.
116    */

117   public boolean isLabelUpdate()
118   {
119     return labelUpdate;
120   }
121 }
122
Popular Tags