Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9605e067f5a0a7ec1db4fc97841c7bb01f9c976f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (c) 2009-2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Simon McDuff - initial API and implementation
 *    Eike Stepper - maintenance
 */
package org.eclipse.emf.cdo.view;

import org.eclipse.emf.cdo.CDOAdapter;

import org.eclipse.emf.internal.cdo.messages.Messages;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.ecore.EObject;

/**
 * A policy that allows to specify valid {@link Adapter} / {@link EObject} combinations.
 *
 * @author Simon McDuff
 * @see CDOView.Options#addChangeSubscriptionPolicy(CDOAdapterPolicy)
 * @see CDOView.Options#setStrongReferencePolicy(CDOAdapterPolicy)
 * @since 2.0
 */
public interface CDOAdapterPolicy
{
  /**
   * A default adapter policy that never triggers any special behaviour.
   */
  public static final CDOAdapterPolicy NONE = new CDOAdapterPolicy()
  {
    /**
     * Always returns <code>false</code>.
     */
    public boolean isValid(EObject eObject, Adapter adapter)
    {
      return false;
    }

    @Override
    public String toString()
    {
      return Messages.getString("CDOAdapterPolicy.1"); //$NON-NLS-1$
    }
  };

  /**
   * A default adapter policy that only triggers special behaviour if the adapter under test implements
   * {@link CDOAdapter}.
   */
  public static final CDOAdapterPolicy CDO = new CDOAdapterPolicy()
  {
    /**
     * Returns <code>true</code> if the given adapter implements {@link CDOAdapter}.
     */
    public boolean isValid(EObject eObject, Adapter adapter)
    {
      return adapter instanceof CDOAdapter;
    }

    @Override
    public String toString()
    {
      return Messages.getString("CDOAdapterPolicy.0"); //$NON-NLS-1$
    }
  };

  /**
   * A default adapter policy that always triggers special behaviour.
   */
  public static final CDOAdapterPolicy ALL = new CDOAdapterPolicy()
  {
    /**
     * Always returns <code>true</code>.
     */
    public boolean isValid(EObject eObject, Adapter adapter)
    {
      return true;
    }

    @Override
    public String toString()
    {
      return Messages.getString("CDOAdapterPolicy.2"); //$NON-NLS-1$
    }
  };

  /**
   * Returns <code>true</code> if the given adapter on the given object should trigger a certain operation or behaviour,
   * <code>false</code> otherwise.
   *
   * @see CDOView.Options#addChangeSubscriptionPolicy(CDOAdapterPolicy)
   * @see CDOView.Options#setStrongReferencePolicy(CDOAdapterPolicy)
   */
  public boolean isValid(EObject eObject, Adapter adapter);
}

Back to the top