Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6b994bd85d98c11971a90aa0313c7f9bd2d70ed1 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Copyright (c) 2010-2012, 2015 Eike Stepper (Loehne, 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:
 *    Martin Fluegge - initial API and implementation
 */
package org.eclipse.emf.cdo.dawn.editors.impl;

import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
import org.eclipse.emf.cdo.dawn.editors.IDawnEditorSupport;
import org.eclipse.emf.cdo.dawn.notifications.BasicDawnListener;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.transaction.CDOTransactionHandlerBase;
import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
import org.eclipse.emf.cdo.view.CDOView;

import java.util.List;

/**
 * @author Martin Fluegge
 */
public abstract class DawnAbstractEditorSupport implements IDawnEditorSupport
{
  private final IDawnEditor editor;

  private CDOView view;

  private boolean dirty;

  public CDOView getView()
  {
    return view;
  }

  public void setView(CDOView view)
  {
    this.view = view;
  }

  public DawnAbstractEditorSupport(IDawnEditor editor)
  {
    this.editor = editor;
  }

  public void setDirty(boolean dirty)
  {
    this.dirty = dirty;
  }

  public boolean isDirty()
  {
    return dirty;
  }

  public IDawnEditor getEditor()
  {
    return editor;
  }

  /**
   * This method registeres the listeners for the DawnEditorSupport. Concrete implementaions can influence the
   * registered listeneres by implementing the methods
   * <ul>
   * <li>getBasicHandler()</li>
   * <li>getLockingHandler()</li>
   * </ul>
   * If one of these methods returns null the specific handler will not be registered and activated.
   *
   * @see #getBasicHandler()
   * @see #getLockingHandler()
   * @since 2.0
   */
  public void registerListeners()
  {
    BasicDawnListener listener = getBasicHandler();
    CDOView view = getView();

    if (listener != null)
    {
      view.addListener(listener);
    }

    BasicDawnListener lockingHandler = getLockingHandler();
    if (lockingHandler != null)
    {
      view.addListener(lockingHandler);
      view.options().setLockNotificationEnabled(true);
    }

    if (view instanceof CDOTransaction)
    {
      CDOTransaction transaction = (CDOTransaction)view;
      CDOTransactionHandlerBase transactionHandler = getTransactionHandler();
      if (transactionHandler != null)
      {
        transaction.addTransactionHandler(transactionHandler);
      }
      transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.CDO);
      transaction.options().setAutoReleaseLocksEnabled(false);
    }
  }

  /**
   * Subclasses must implement this method to deliver a IDawnListener that implements the behavior for Session
   * invalidations. If the method returns null, the handler will not be registered.
   *
   * @since 2.0
   */
  protected abstract BasicDawnListener getBasicHandler();

  /**
   * Subclasses must implement this method to deliver a IDawnListener that implements the behavior for remote locking
   * notifications. If the method returns null, the handler will not be registered.
   *
   * @since 2.0
   */
  protected abstract BasicDawnListener getLockingHandler();

  /**
   * Subclasses must implement this method to deliver a CDOTransactionHandlerBase that implements the behavior for
   * remote changes notifications. If the method returns null, the handler will not be registered.
   *
   * @since 2.0
   */
  protected abstract CDOTransactionHandlerBase getTransactionHandler();

  /**
   * @since 1.0
   */
  public void rollback()
  {
    CDOView view = getEditor().getView();

    if (view != null && view instanceof CDOTransaction)
    {
      ((CDOTransaction)view).rollback();
    }
  }

  /**
   * @since 2.0
   */
  public void lockObjects(List<Object> objectsToBeLocked)
  {
    for (Object objectToBeLocked : objectsToBeLocked)
    {
      lockObject(objectToBeLocked);
    }
  }

  /**
   * @since 2.0
   */
  public void unlockObjects(List<Object> objectsToBeLocked)
  {
    for (Object objectToBeUnlocked : objectsToBeLocked)
    {
      unlockObject(objectToBeUnlocked);
    }
  }
}

Back to the top