blob: de9c97920c57c3f4b3c8521a23b57944a1cf513d (
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
|
/*
* Copyright (c) 2004 - 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:
* Martin Fluegge - initial API and implementation
*/
package org.eclipse.emf.cdo.dawn.gmf.synchronize;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
import org.eclipse.gmf.runtime.notation.View;
/**
* @author Martin Fluegge
*/
public class DawnConflictHelper
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnConflictHelper.class);
public static boolean handleConflictedView(CDOObject cdoObject, View view, DiagramDocumentEditor editor)
{
boolean cdoConflict = cdoObject.cdoConflict();
if (cdoConflict && view != null)
{
if (TRACER.isEnabled())
{
TRACER.format("Object ({0}) is in state conflict!", cdoObject); //$NON-NLS-1$
}
EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, editor);
int typeConflictLocallyDeleted = evaluateConflictType(cdoObject);
DawnAppearancer.setEditPartConflicted(editPart, typeConflictLocallyDeleted);
}
return cdoConflict;
}
private static int evaluateConflictType(CDOObject cdoObject)
{
if (cdoObject.cdoState() == CDOState.DIRTY)
{
return DawnAppearancer.TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED;
}
return DawnAppearancer.TYPE_CONFLICT_REMOTELY_DELETED;
}
public static void rollback(final DiagramDocumentEditor editor)
{
CDOView view = ((IDawnEditor)editor).getView();
if (view != null && view instanceof CDOTransaction)
{
((CDOTransaction)view).rollback();
}
editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain())
{
@Override
public void doExecute()
{
DawnAppearancer.setEditPartDefaultAllChildren(editor.getDiagramEditPart());
DawnDiagramUpdater.refreshEditPart(editor.getDiagramEditPart());
}
});
}
/**
* TODO this method should decide whether the object is conflicted or not using special Policies
*
* @param object
* @return whether the object is conflicted
*/
public static boolean isConflicted(EObject object)
{
CDOObject cdoObject = CDOUtil.getCDOObject(object);
if (cdoObject.cdoConflict())
{
return true;
}
if (object instanceof View)
{
CDOObject element = CDOUtil.getCDOObject(((View)object).getElement());
if (element.cdoConflict())
{
return true;
}
}
return false;
}
}
|