blob: f07fd6a7e1d52ad76937eea073cbe67f605efe57 (
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
|
/*
* Copyright (c) 2004-2014 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:
* Eike Stepper - initial API and implementation
*/
package org.eclipse.emf.cdo.internal.ui.views;
import org.eclipse.emf.cdo.CDOElement;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.ui.widgets.TimeSlider;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.util.AdapterUtil;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;
import java.util.Iterator;
/**
* @author Eike Stepper
*/
public class CDOTimeMachineView extends ViewPart implements ISelectionListener
{
public final static String ID = "org.eclipse.emf.cdo.ui.CDOTimeMachineView"; //$NON-NLS-1$
private TimeSlider timeSlider;
public CDOTimeMachineView()
{
}
@Override
public void createPartControl(Composite parent)
{
timeSlider = new TimeSlider(parent, SWT.NONE);
IWorkbenchPage page = getSite().getPage();
selectionChanged(null, page.getSelection());
page.addSelectionListener(this);
}
@Override
public void dispose()
{
getSite().getPage().removeSelectionListener(this);
timeSlider.disconnect();
super.dispose();
}
@Override
public void setFocus()
{
timeSlider.setFocus();
}
public void selectionChanged(IWorkbenchPart part, ISelection selection)
{
CDOView view = getView(selection);
if (view != null)
{
timeSlider.connect(view, null);
}
}
private CDOView getView(ISelection selection)
{
if (selection instanceof IStructuredSelection)
{
IStructuredSelection ssel = (IStructuredSelection)selection;
for (Iterator<?> it = ssel.iterator(); it.hasNext();)
{
Object element = it.next();
if (element instanceof CDOElement)
{
element = ((CDOElement)element).getDelegate();
}
if (element instanceof EObject)
{
EObject eObject = (EObject)element;
CDOObject cdoObject = CDOUtil.getCDOObject(eObject);
if (cdoObject != null)
{
CDOView view = cdoObject.cdoView();
if (view != null && view.isReadOnly())
{
return view;
}
}
}
else
{
CDOView view = AdapterUtil.adapt(element, CDOView.class);
if (view != null && view.isReadOnly())
{
return view;
}
}
}
}
return null;
}
// protected String formatTimeSliderLabel(long timeStamp)
// {
// CDOBranchPoint branchPoint = CDOBranchUtil.normalizeBranchPoint(view.getBranch(), timeStamp);
// return branchPoint.getBranch().getPathName() + " [" + CDOCommonUtil.formatTimeStamp(timeStamp) + "]";
// }
}
|