KickJava   Java API By Example, From Geeks To Geeks.

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


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.team.internal.ui.synchronize;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.jface.viewers.StructuredViewer;
15 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
16 import org.eclipse.ui.IActionBars;
17
18 /**
19  * Abstract superclass for viewer advisors
20  */

21 public abstract class AbstractViewerAdvisor {
22
23     private ISynchronizePageConfiguration configuration;
24     private StructuredViewer viewer;
25     
26     public AbstractViewerAdvisor(ISynchronizePageConfiguration configuration) {
27         this.configuration = configuration;
28         configuration.setProperty(SynchronizePageConfiguration.P_ADVISOR, this);
29     }
30
31     public ISynchronizePageConfiguration getConfiguration() {
32         return configuration;
33     }
34
35     /**
36      * Install a viewer to be configured with this advisor. An advisor can only be installed with
37      * one viewer at a time. When this method completes the viewer is considered initialized and
38      * can be shown to the user.
39      * @param viewer the viewer being installed
40      */

41     protected void initializeViewer(final StructuredViewer viewer) {
42         Assert.isTrue(this.viewer == null, "Can only be initialized once."); //$NON-NLS-1$
43
Assert.isTrue(validateViewer(viewer));
44         this.viewer = viewer;
45     }
46     
47     /**
48      * Subclasses can validate that the viewer being initialized with this advisor
49      * is of the correct type.
50      *
51      * @param viewer the viewer to validate
52      * @return <code>true</code> if the viewer is valid, <code>false</code> otherwise.
53      */

54     protected boolean validateViewer(StructuredViewer viewer) {
55         return true;
56     }
57
58     /**
59      * Returns the viewer configured by this advisor.
60      *
61      * @return the viewer configured by this advisor.
62      */

63     public StructuredViewer getViewer() {
64         return viewer;
65     }
66
67     public abstract void setActionBars(IActionBars actionBars);
68 }
69
Popular Tags