Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.ui')
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/plugin.properties1
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/plugin.xml9
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java144
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java119
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOInvalidRootAgent.java110
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java23
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java150
8 files changed, 443 insertions, 116 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.properties b/plugins/org.eclipse.emf.cdo.ui/plugin.properties
index c59f3650dc..fff9e26267 100644
--- a/plugins/org.eclipse.emf.cdo.ui/plugin.properties
+++ b/plugins/org.eclipse.emf.cdo.ui/plugin.properties
@@ -62,6 +62,7 @@ category.name.0 = CDO
view.name.0 = CDO Sessions
view.name.1 = CDO Watch List
view.name.2 = CDO Collaboration
+view.name.3 = CDO Time Machine
editor.name.0 = CDO Editor
page.name.0 = CDO
page.name.1 = User Interface
diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.ui/plugin.xml
index ce96905f34..8aaf9da46b 100644
--- a/plugins/org.eclipse.emf.cdo.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.ui/plugin.xml
@@ -58,10 +58,17 @@
<view
category="org.eclipse.emf.cdo"
class="org.eclipse.emf.cdo.internal.ui.views.CDORemoteSessionsView"
- icon="platform:/plugin/org.eclipse.emf.cdo.ui.shared/icons/full/view16/watch_list.gif"
+ icon="platform:/plugin/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_remote_sessions.gif"
id="org.eclipse.emf.cdo.ui.CDORemoteSessionsView"
name="%view.name.2">
</view>
+ <view
+ category="org.eclipse.emf.cdo"
+ class="org.eclipse.emf.cdo.internal.ui.views.CDOTimeMachineView"
+ icon="platform:/plugin/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_time_machine.gif"
+ id="org.eclipse.emf.cdo.ui.CDOTimeMachineView"
+ name="%view.name.3">
+ </view>
</extension>
<extension
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
index aee38dbee4..5c4221dbdb 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
@@ -14,7 +14,6 @@ package org.eclipse.emf.cdo.internal.ui.editor;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
@@ -30,20 +29,18 @@ import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.ui.CDOEditorInput;
import org.eclipse.emf.cdo.ui.CDOEventHandler;
import org.eclipse.emf.cdo.ui.CDOLabelProvider;
+import org.eclipse.emf.cdo.ui.CDOInvalidRootAgent;
import org.eclipse.emf.cdo.ui.shared.SharedIcons;
import org.eclipse.emf.cdo.ui.widgets.TimeSlider;
import org.eclipse.emf.cdo.util.CDOURIUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.ValidationException;
import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent;
import org.eclipse.emf.internal.cdo.view.CDOStateMachine;
import org.eclipse.net4j.util.AdapterUtil;
import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.actions.LongRunningAction;
import org.eclipse.net4j.util.ui.actions.SafeAction;
@@ -212,17 +209,17 @@ public class CDOEditor extends MultiPageEditorPart
/**
* @ADDED
*/
- protected static final Object EMPTY_INPUT = new Object();
+ protected CDOView view;
/**
* @ADDED
*/
- protected CDOView view;
+ protected Object viewerInput;
/**
* @ADDED
*/
- protected Object viewerInput;
+ protected CDOInvalidRootAgent invalidRootAgent;
/**
* @ADDED
@@ -472,59 +469,6 @@ public class CDOEditor extends MultiPageEditorPart
}
};
- protected IListener viewTargetListener = new IListener()
- {
- protected CDOID inputID;
-
- public void notifyEvent(IEvent event)
- {
- if (event instanceof CDOViewTargetChangedEvent)
- {
- final CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event;
- getSite().getShell().getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- Object input = selectionViewer.getInput();
- if (input == EMPTY_INPUT)
- {
- if (inputID != null)
- {
- try
- {
- CDOObject object = view.getObject(inputID);
- selectionViewer.setInput(object);
- inputID = null;
- }
- catch (Exception ex)
- {
- // Ignore
- }
- }
- }
- else if (input instanceof EObject)
- {
- CDOObject object = CDOUtil.getCDOObject((EObject)input);
- if (object.cdoInvalid())
- {
- if (e.getBranchPoint().getTimeStamp() == e.getOldBranchPoint().getTimeStamp())
- {
- inputID = null;
- closeEditor();
- }
- else
- {
- inputID = object.cdoID();
- selectionViewer.setInput(EMPTY_INPUT);
- }
- }
- }
- }
- });
- }
- }
- };
-
/**
* Handles activation of the editor or it's associated views.
* <!-- begin-user-doc --> <!-- end-user-doc -->
@@ -999,7 +943,31 @@ public class CDOEditor extends MultiPageEditorPart
{
CDOEditorInput editorInput = (CDOEditorInput)getEditorInput();
view = editorInput.getView();
- view.addListener(viewTargetListener);
+
+ // If the view can be switched to historical times let an InvalidRootAgent handle detached inputs.
+ if (view.isReadOnly())
+ {
+ invalidRootAgent = new CDOInvalidRootAgent(view)
+ {
+ @Override
+ protected Object getRootFromUI()
+ {
+ return selectionViewer.getInput();
+ }
+
+ @Override
+ protected void setRootToUI(Object root)
+ {
+ selectionViewer.setInput(root);
+ }
+
+ @Override
+ protected void closeUI()
+ {
+ closeEditor();
+ }
+ };
+ }
CommandStack commandStack;
@@ -1213,7 +1181,7 @@ public class CDOEditor extends MultiPageEditorPart
final boolean timeSliderAllowed = view.isReadOnly() && view.getSession().getRepositoryInfo().isSupportingAudits();
if (timeSliderAllowed)
{
- IAction toolbarToggleAction = new Action()
+ final IAction toolbarToggleAction = new Action()
{
private Group group;
@@ -1254,11 +1222,59 @@ public class CDOEditor extends MultiPageEditorPart
}
};
+ final String id = "time-slider-" + System.currentTimeMillis();
+ toolbarToggleAction.setId(id);
toolbarToggleAction.setEnabled(true);
toolbarToggleAction.setChecked(false);
toolbarToggleAction.setImageDescriptor(SharedIcons.getDescriptor(SharedIcons.ETOOL_SLIDER));
toolbarToggleAction.setToolTipText(Messages.getString("CDOEditor.1")); //$NON-NLS-1$
- getActionBars().getToolBarManager().add(toolbarToggleAction);
+
+ getSite().getPage().addPartListener(new IPartListener()
+ {
+ private IToolBarManager toolBarManager = getActionBars().getToolBarManager();
+
+ public void partActivated(IWorkbenchPart part)
+ {
+ showToggleAction(part, true);
+ }
+
+ public void partDeactivated(IWorkbenchPart part)
+ {
+ showToggleAction(part, false);
+ }
+
+ private void showToggleAction(IWorkbenchPart part, boolean show)
+ {
+ if (part == CDOEditor.this)
+ {
+ if (show)
+ {
+ toolBarManager.add(toolbarToggleAction);
+ }
+ else
+ {
+ toolBarManager.remove(id);
+ }
+
+ toolBarManager.update(true);
+ }
+ }
+
+ public void partClosed(IWorkbenchPart part)
+ {
+ // Do nothing.
+ }
+
+ public void partOpened(IWorkbenchPart part)
+ {
+ // Do nothing.
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part)
+ {
+ // Do nothing.
+ }
+ });
}
selectionViewer = new TreeViewer(tree)
@@ -2290,7 +2306,7 @@ public class CDOEditor extends MultiPageEditorPart
public void dispose()
{
updateProblemIndication = false;
- view.removeListener(viewTargetListener);
+ invalidRootAgent.dispose();
if (!view.isClosed())
{
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java
new file mode 100644
index 0000000000..d0bdd867f6
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java
@@ -0,0 +1,119 @@
+/*
+ * 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;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOInvalidRootAgent.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOInvalidRootAgent.java
new file mode 100644
index 0000000000..eea70e6990
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOInvalidRootAgent.java
@@ -0,0 +1,110 @@
+/*
+ * 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.ui;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent;
+
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.spi.cdo.InternalCDOObject;
+
+/**
+ * @author Eike Stepper
+ * @since 4.4
+ */
+public abstract class CDOInvalidRootAgent implements IListener
+{
+ private static final Object EMPTY_INPUT = new Object();
+
+ private final CDOView view;
+
+ private CDOID inputID;
+
+ public CDOInvalidRootAgent(CDOView view)
+ {
+ this.view = view;
+ view.addListener(this);
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof CDOViewTargetChangedEvent)
+ {
+ final CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event;
+ UIUtil.getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ Object input = getRootFromUI();
+ if (inputID != null)
+ {
+ try
+ {
+ InternalCDOObject object = (InternalCDOObject)view.getObject(inputID);
+ if (!object.cdoInvalid())
+ {
+ setRootToUI(object.cdoInternalInstance());
+ inputID = null;
+ }
+ }
+ catch (Exception ex)
+ {
+ // Ignore
+ }
+ }
+ else if (input instanceof EObject)
+ {
+ CDOObject object = CDOUtil.getCDOObject((EObject)input);
+ if (object.cdoInvalid())
+ {
+ if (e.getBranchPoint().getTimeStamp() == e.getOldBranchPoint().getTimeStamp())
+ {
+ inputID = null;
+ closeUI();
+ }
+ else
+ {
+ inputID = object.cdoID();
+ Object emptyRoot = createEmptyRoot(object);
+ setRootToUI(emptyRoot);
+ }
+ }
+ }
+ }
+ });
+ }
+ }
+
+ public void dispose()
+ {
+ view.removeListener(this);
+ }
+
+ protected Object createEmptyRoot(CDOObject invalidRoot)
+ {
+ return EMPTY_INPUT;
+ }
+
+ protected abstract Object getRootFromUI();
+
+ protected abstract void setRootToUI(Object root);
+
+ protected void closeUI()
+ {
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java
index 966a761dbc..f8d09046c2 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java
@@ -254,7 +254,8 @@ public class ComposeBranchPointComposite extends Composite
timeStampGroup.setLayout(new GridLayout(1, false));
timeStampGroup.setText("Time Stamp:");
- SelectTimeStampComposite timeStampComposite = new SelectTimeStampComposite(timeStampGroup, SWT.NONE)
+ SelectTimeStampComposite timeStampComposite = new SelectTimeStampComposite(timeStampGroup, SWT.NONE,
+ branchPoint.getBranch(), branchPoint.getTimeStamp())
{
@Override
protected void timeStampChanged(long timeStamp)
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java
index d210d8d21a..11208b4f9d 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java
@@ -52,7 +52,7 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar
private CDOBranch branch;
- private long timeStamp = CDOBranchPoint.INVALID_DATE;
+ private long timeStamp;
private Composite pointGroup;
@@ -73,7 +73,7 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar
*/
public SelectTimeStampComposite(Composite parent, int style)
{
- this(parent, style, null, CDOBranchPoint.UNSPECIFIED_DATE);
+ this(parent, style, null, CDOBranchPoint.INVALID_DATE);
}
public SelectTimeStampComposite(Composite parent, int style, CDOBranch branch, long timeStamp)
@@ -123,7 +123,7 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar
timeText = new Text(pointGroup, SWT.BORDER);
timeText.setLayoutData(createTimeGridData());
- timeText.setText(CDOCommonUtil.formatTimeStamp());
+ timeText.setText(CDOCommonUtil.formatTimeStamp(timeStamp));
timeText.addModifyListener(new ModifyListener()
{
public void modifyText(ModifyEvent e)
@@ -174,8 +174,9 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar
new Label(pointGroup, SWT.NONE);
new Label(pointGroup, SWT.NONE);
+ this.timeStamp = timeStamp;
setBranch(branch);
- setTimeStamp(timeStamp);
+ // setTimeStamp(timeStamp);
}
public ValidationContext getValidationContext()
@@ -222,13 +223,13 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar
else
{
selectRadio(timeRadio);
- String text = CDOCommonUtil
- .formatTimeStamp(timeStamp == CDOBranchPoint.INVALID_DATE || timeStamp == CDOBranchPoint.UNSPECIFIED_DATE
- ? System.currentTimeMillis() : timeStamp);
- if (!timeText.getText().equals(text))
- {
- timeText.setText(text);
- }
+ // String text = CDOCommonUtil
+ // .formatTimeStamp(timeStamp == CDOBranchPoint.INVALID_DATE || timeStamp == CDOBranchPoint.UNSPECIFIED_DATE
+ // ? System.currentTimeMillis() : timeStamp);
+ // if (!timeText.getText().equals(text))
+ // {
+ // timeText.setText(text);
+ // }
}
if (oldTimeStamp != timeStamp)
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java
index 203b2fc926..615cb9852a 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java
@@ -11,10 +11,12 @@
package org.eclipse.emf.cdo.ui.widgets;
import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.branch.CDOBranchPointRange;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOStaleReferencePolicy;
import org.eclipse.emf.cdo.view.CDOView;
@@ -22,6 +24,8 @@ import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent.Kind;
import org.eclipse.emf.ecore.EObject;
@@ -31,6 +35,7 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Scale;
import java.util.HashSet;
@@ -83,8 +88,11 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener
long timeStamp = startTimeStamp + Math.round(stepSize * value);
setTimeStamp(timeStamp);
- viewer.refresh();
- setExpandedStates();
+ if (viewer != null)
+ {
+ viewer.refresh();
+ setExpandedStates();
+ }
}
protected void setExpandedStates()
@@ -128,10 +136,28 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener
if (this.timeStamp != timeStamp)
{
this.timeStamp = timeStamp;
- int newSelection = (int)((timeStamp - startTimeStamp) / stepSize);
- if (getSelection() != newSelection)
+ final int newSelection = (int)((timeStamp - startTimeStamp) / stepSize);
+
+ Display display = getDisplay();
+ if (display == Display.getCurrent())
+ {
+ if (getSelection() != newSelection)
+ {
+ setSelection(newSelection);
+ }
+ }
+ else
{
- setSelection(newSelection);
+ display.asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ if (getSelection() != newSelection)
+ {
+ setSelection(newSelection);
+ }
+ }
+ });
}
timeStampChanged(timeStamp);
@@ -140,54 +166,89 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener
public void connect(CDOView view, TreeViewer viewer)
{
- disconnect();
-
- this.view = view;
- this.viewer = viewer;
-
- for (Object element : viewer.getExpandedElements())
+ if (this.view != view)
{
- CDOID id = getID(element);
- if (id != null)
+ disconnect();
+
+ if (view != null)
{
- expandedIDs.add(id);
- }
- }
+ this.view = view;
+ this.viewer = viewer;
- viewer.addTreeListener(this);
+ CDOBranchPointRange lifetime = null;
- CDOObject input = CDOUtil.getCDOObject((EObject)viewer.getInput());
- CDOBranchPointRange lifetime = CDOUtil.getLifetime(input);
+ if (this.viewer != null)
+ {
+ for (Object element : viewer.getExpandedElements())
+ {
+ CDOID id = getID(element);
+ if (id != null)
+ {
+ expandedIDs.add(id);
+ }
+ }
- startTimeStamp = lifetime.getStartPoint().getTimeStamp();
- endTimeStamp = lifetime.getEndPoint().getTimeStamp();
- if (endTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE)
- {
- CDOSession session = view.getSession();
- endTimeStamp = session.getLastUpdateTime();
- }
+ this.viewer.addTreeListener(this);
+
+ Object input = viewer.getInput();
+ if (input instanceof EObject)
+ {
+ lifetime = CDOUtil.getLifetime(CDOUtil.getCDOObject((EObject)input));
+ }
+ }
+
+ if (lifetime == null)
+ {
+ CDOSession session = view.getSession();
+ CDOBranch branch = view.getBranch();
+
+ CDOBranchPoint firstPoint = branch.getPoint(session.getRepositoryInfo().getCreationTime());
+ CDOBranchPoint lastPoint = branch.getHead();
+ lifetime = CDOBranchUtil.createRange(firstPoint, lastPoint);
+ }
- absoluteTimeWindowLength = endTimeStamp - startTimeStamp;
- stepSize = absoluteTimeWindowLength / FACTOR;
+ startTimeStamp = lifetime.getStartPoint().getTimeStamp();
+ endTimeStamp = lifetime.getEndPoint().getTimeStamp();
+ if (endTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE)
+ {
+ CDOSession session = view.getSession();
+ endTimeStamp = session.getLastUpdateTime();
+ }
+
+ absoluteTimeWindowLength = endTimeStamp - startTimeStamp;
+ stepSize = absoluteTimeWindowLength / FACTOR;
- setTimeStamp(view.getTimeStamp());
+ setTimeStamp(view.getTimeStamp());
- staleReferencePolicy = new CDOStaleReferencePolicy.DynamicProxy.Enhanced(view);
- view.addListener(this);
+ staleReferencePolicy = new CDOStaleReferencePolicy.DynamicProxy.Enhanced(view);
+ view.addListener(this);
+ setEnabled(true);
+ }
+ else
+ {
+ setEnabled(false);
+ }
+ }
}
public void disconnect()
{
- if (staleReferencePolicy != null)
+ if (view != null)
{
- view.removeListener(this);
- staleReferencePolicy.dispose();
- staleReferencePolicy = null;
+ if (staleReferencePolicy != null)
+ {
+ view.removeListener(this);
+ staleReferencePolicy.dispose();
+ staleReferencePolicy = null;
- expandedIDs.clear();
- viewer.removeTreeListener(this);
+ if (viewer != null)
+ {
+ expandedIDs.clear();
+ viewer.removeTreeListener(this);
+ viewer = null;
+ }
+ }
- viewer = null;
view = null;
}
}
@@ -199,6 +260,14 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener
CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event;
setTimeStamp(e.getBranchPoint().getTimeStamp());
}
+ else if (event instanceof ILifecycleEvent)
+ {
+ ILifecycleEvent e = (ILifecycleEvent)event;
+ if (e.getKind() == Kind.ABOUT_TO_DEACTIVATE)
+ {
+ disconnect();
+ }
+ }
}
public void treeExpanded(TreeExpansionEvent event)
@@ -228,7 +297,10 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener
protected void timeStampChanged(long timeStamp)
{
- view.setTimeStamp(timeStamp);
+ if (view != null)
+ {
+ view.setTimeStamp(timeStamp);
+ }
}
@Override

Back to the top