diff options
7 files changed, 178 insertions, 45 deletions
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ViewerUtil.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ViewerUtil.java index f98b546d32..db73b369c1 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ViewerUtil.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ViewerUtil.java @@ -10,6 +10,7 @@ */ package org.eclipse.emf.cdo.explorer.ui; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Control; @@ -80,6 +81,12 @@ public final class ViewerUtil public static void refresh(final StructuredViewer viewer, final Object element, boolean async) { + refresh(viewer, element, true, false); + } + + public static void refresh(final StructuredViewer viewer, final Object element, boolean async, + final boolean setSelectionBack) + { if (viewer != null) { Control control = viewer.getControl(); @@ -91,6 +98,12 @@ public final class ViewerUtil { if (!viewer.getControl().isDisposed()) { + ISelection selection = null; + if (setSelectionBack) + { + selection = viewer.getSelection(); + } + if (element == null) { viewer.refresh(); @@ -107,6 +120,11 @@ public final class ViewerUtil { viewer.refresh(element); } + + if (selection != null) + { + viewer.setSelection(selection); + } } } }; diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java index 61be75c116..75b0a2e395 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java @@ -499,7 +499,8 @@ public class CDOCheckoutContentProvider extends AdapterFactoryContentProvider im } // The viewer must be refreshed synchronously so that the loaded children don't get garbage collected. - ViewerUtil.refresh(viewer, originalObject, false); + // Set the selection again to trigger, e.g., a History page update. + ViewerUtil.refresh(viewer, originalObject, false, true); synchronized (LOADING_OBJECTS) { diff --git a/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java b/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java index b7746e3192..34bb521edc 100644 --- a/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java +++ b/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java @@ -20,14 +20,16 @@ import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite; import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite.Input; +import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite.Input.IllegalInputException; import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite.LabelProvider; +import org.eclipse.net4j.util.AdapterUtil; import org.eclipse.net4j.util.event.IListener; import org.eclipse.net4j.util.lifecycle.ILifecycle; import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.ui.widgets.StackComposite; -import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; @@ -35,6 +37,8 @@ import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; import org.eclipse.team.ui.history.HistoryPage; import org.eclipse.ui.IActionBars; @@ -47,6 +51,10 @@ public class CDOHistoryPage extends HistoryPage { private static final String POPUP_ID = "org.eclipse.emf.cdo.ui.team.historyPageContributions"; + private StackComposite stackComposite; + + private Control offlineControl; + private CommitHistoryComposite commitHistoryComposite; private boolean commitOnDoubleClick; @@ -86,15 +94,22 @@ public class CDOHistoryPage extends HistoryPage } @Override - public CommitHistoryComposite getControl() + public Control getControl() { - return commitHistoryComposite; + return stackComposite; } @Override public void createControl(Composite parent) { - commitHistoryComposite = new CommitHistoryComposite(parent, SWT.NONE) + stackComposite = new StackComposite(parent, SWT.NONE); + + Label label = new Label(stackComposite, SWT.NONE); + label.setText("The selected session belongs to an offline workspace.\nThe remote history cannot be provided."); + label.setForeground(label.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE)); + offlineControl = label; + + commitHistoryComposite = new CommitHistoryComposite(stackComposite, SWT.NONE) { @Override protected void doubleClicked(CDOCommitInfo commitInfo) @@ -149,6 +164,8 @@ public class CDOHistoryPage extends HistoryPage } }; + stackComposite.setTopControl(commitHistoryComposite); + IPageSite site = getSite(); TableViewer tableViewer = commitHistoryComposite.getTableViewer(); @@ -174,9 +191,10 @@ public class CDOHistoryPage extends HistoryPage commitHistoryComposite.refreshLayout(); } - public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Object getAdapter(Class adapter) { - return Platform.getAdapterManager().getAdapter(this, adapter); + return AdapterUtil.adapt(this, adapter, false); } public boolean isValidInput(Object object) @@ -200,6 +218,17 @@ public class CDOHistoryPage extends HistoryPage { input = new CommitHistoryComposite.Input(object); input.addListener(inputListener); + input.activate(); + + if (input.isOffline()) + { + stackComposite.setTopControl(offlineControl); + } + else + { + stackComposite.setTopControl(commitHistoryComposite); + } + return true; } catch (Exception ex) @@ -270,7 +299,7 @@ public class CDOHistoryPage extends HistoryPage new CommitHistoryComposite.Input(object); return true; } - catch (IllegalStateException ex) + catch (IllegalInputException ex) { return false; } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java index 215cd90655..81af27dd4a 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectBranchPointDialog.java @@ -186,7 +186,7 @@ public class SelectBranchPointDialog extends TitleAreaDialog implements Validati protected void createCommitsTab(Composite parent) { - CommitHistoryComposite control = new CommitHistoryComposite(parent, SWT.NONE) + CommitHistoryComposite control = new CommitHistoryComposite(parent, SWT.BORDER) { @Override protected void commitInfoChanged(CDOCommitInfo newCommitInfo) diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java index 85774a4423..ad68025bbb 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java @@ -81,6 +81,8 @@ public class CommitHistoryComposite extends Composite } }; + private int viewerStyle; + private TableViewer tableViewer; private LabelProvider labelProvider; @@ -89,9 +91,11 @@ public class CommitHistoryComposite extends Composite private Input input; - public CommitHistoryComposite(Composite parent, int style) + public CommitHistoryComposite(Composite parent, int viewerStyle) { - super(parent, style); + super(parent, SWT.NONE); + this.viewerStyle = viewerStyle; + setLayout(new FillLayout(SWT.HORIZONTAL)); tableViewer = createTableViewer(); @@ -116,6 +120,14 @@ public class CommitHistoryComposite extends Composite netRenderer = new NetRenderer(tableViewer); } + /** + * @since 4.4 + */ + public final int getViewerStyle() + { + return viewerStyle; + } + public final TableViewer getTableViewer() { return tableViewer; @@ -203,7 +215,7 @@ public class CommitHistoryComposite extends Composite protected TableViewer createTableViewer() { - return new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); + return new TableViewer(this, getViewerStyle() | SWT.FULL_SELECTION | SWT.MULTI); } protected ContentProvider createContentProvider() @@ -305,17 +317,17 @@ public class CommitHistoryComposite extends Composite private final CDOObject object; - public Input(Object delegate) + private final boolean offline; + + public Input(Object delegate) throws IllegalInputException { CDOSession sessionAdapter = AdapterUtil.adapt(delegate, CDOSession.class); if (sessionAdapter != null) { session = sessionAdapter; - assertNotWorkspace(); - + offline = determineOffline(); branch = null; object = null; - session.addListener(lifecycleListener); return; } @@ -325,10 +337,8 @@ public class CommitHistoryComposite extends Composite branch = branchAdapter; session = (CDOSession)((CDOSessionProtocol)((InternalCDOBranchManager)branch.getBranchManager()) .getBranchLoader()).getSession(); - assertNotWorkspace(); - + offline = determineOffline(); object = null; - session.addListener(lifecycleListener); return; } @@ -337,11 +347,9 @@ public class CommitHistoryComposite extends Composite { CDOView view = viewAdapter; session = view.getSession(); - assertNotWorkspace(); - - branch = view.getBranch(); + offline = determineOffline(); + branch = offline ? null : view.getBranch(); object = null; - view.addListener(lifecycleListener); return; } @@ -355,32 +363,23 @@ public class CommitHistoryComposite extends Composite if (view != null && cdoObject.cdoState() != CDOState.NEW) { session = view.getSession(); - branch = view.getBranch(); - object = cdoObject; - view.addListener(lifecycleListener); + offline = determineOffline(); + branch = offline ? null : view.getBranch(); + object = offline ? null : cdoObject; return; } } } - throw new IllegalStateException("Illegal input: " + delegate); - } - - private void assertNotWorkspace() - { - IRegistry<String, Object> properties = session.properties(); - if (properties.containsKey("org.eclipse.emf.cdo.workspace.CDOWorkspace")) - { - throw new IllegalStateException("Offline input: " + session); - } + throw new IllegalInputException("Illegal input: " + delegate); } public Input(CDOSession session, CDOBranch branch, CDOObject object) { this.session = session; - this.branch = branch; - this.object = object; - EventUtil.addListener(getLifecycle(), lifecycleListener); + offline = determineOffline(); + this.branch = offline ? null : branch; + this.object = offline ? null : object; } public final CDOSession getSession() @@ -398,6 +397,14 @@ public class CommitHistoryComposite extends Composite return object; } + /** + * @since 4.4 + */ + public final boolean isOffline() + { + return offline; + } + @Override public int hashCode() { @@ -458,22 +465,25 @@ public class CommitHistoryComposite extends Composite @Override public String toString() { - String str = "Repostory: " + session.getRepositoryInfo().getName(); - if (branch != null) + if (offline) { - str += ", Branch: " + branch.getPathName(); + return "Offline: " + session; } + String string = "Repository: " + session.getRepositoryInfo().getName() + ", Branch: " + + (branch != null ? branch.getPathName() : CDOBranch.MAIN_BRANCH_NAME); + if (object != null) { - str += ", Object: " + object; + string += ", Object: " + object; } - return str; + return string; } public void activate() throws LifecycleException { + EventUtil.addListener(getLifecycle(), lifecycleListener); } public Exception deactivate() @@ -496,6 +506,11 @@ public class CommitHistoryComposite extends Composite protected final Object getLifecycle() { + if (offline) + { + return null; + } + if (object != null) { return object.cdoView(); @@ -503,6 +518,26 @@ public class CommitHistoryComposite extends Composite return session; } + + private boolean determineOffline() + { + IRegistry<String, Object> properties = session.properties(); + return properties.containsKey("org.eclipse.emf.cdo.workspace.CDOWorkspace"); + } + + /** + * @author Eike Stepper + * @since 4.4 + */ + public static class IllegalInputException extends Exception + { + private static final long serialVersionUID = 1L; + + public IllegalInputException(String message) + { + super(message); + } + } } /** diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/StackComposite.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/StackComposite.java new file mode 100644 index 0000000000..c75494f1d0 --- /dev/null +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/StackComposite.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007-2009, 2011, 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.util.ui.widgets; + +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * @author Eike Stepper + * @since 3.5 + */ +public class StackComposite extends Composite +{ + private final StackLayout layout = new StackLayout(); + + public StackComposite(Composite parent, int style) + { + super(parent, style); + setLayout(layout); + } + + public Control getTopControl() + { + return layout.topControl; + } + + public void setTopControl(Control topControl) + { + if (layout.topControl != topControl) + { + layout.topControl = topControl; + layout(); + } + } + + @Override + protected void checkSubclass() + { + // Do nothing. + } +} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/lifecycle/LifecycleUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/lifecycle/LifecycleUtil.java index 733740504b..761d41598d 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/lifecycle/LifecycleUtil.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/lifecycle/LifecycleUtil.java @@ -64,7 +64,7 @@ public final class LifecycleUtil return ((ILifecycle)object).getLifecycleState(); } - return LifecycleState.ACTIVE; + return object != null ? LifecycleState.ACTIVE : LifecycleState.INACTIVE; } /** |