Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d17f61ab0015d55ecaa9671bbf550d10d0853007 (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
/*
 * Copyright (c) 2015, 2016 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:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.explorer.ui.checkouts.actions;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.explorer.ui.bundle.OM;
import org.eclipse.emf.cdo.internal.ui.actions.CreateBranchAction;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IWorkbenchPage;

/**
 * @author Eike Stepper
 */
public class SwitchToActionProvider extends AbstractBranchPointActionProvider
{
  private static final String ID = SwitchToActionProvider.class.getName();

  public SwitchToActionProvider()
  {
    super(ID, "Switch To");
  }

  @Override
  protected void fillSubMenu(IWorkbenchPage page, IMenuManager subMenu, CDOCheckout checkout)
  {
    if (CDOCheckout.TYPE_ONLINE_TRANSACTIONAL.equals(checkout.getType()))
    {
      subMenu.add(new SwitchToNewBranchAction(page, checkout));
    }

    super.fillSubMenu(page, subMenu, checkout);
  }

  @Override
  protected void fillHistorizedAction(IWorkbenchPage page, IMenuManager subMenu, CDOCheckout checkout, CDOBranchPoint branchPoint)
  {
    if (checkout.isReadOnly() || branchPoint.getTimeStamp() == CDOBranchPoint.UNSPECIFIED_DATE)
    {
      super.fillHistorizedAction(page, subMenu, checkout, branchPoint);
    }
  }

  @Override
  protected void fillOtherBranchAction(IWorkbenchPage page, IMenuManager subMenu, CDOCheckout checkout)
  {
    if (!checkout.isReadOnly())
    {
      super.fillOtherBranchAction(page, subMenu, checkout);
    }
  }

  @Override
  protected void fillOtherBranchPointAction(IWorkbenchPage page, IMenuManager subMenu, CDOCheckout checkout)
  {
    if (checkout.isReadOnly())
    {
      super.fillOtherBranchPointAction(page, subMenu, checkout);
    }
  }

  @Override
  protected void fillCommitAction(IWorkbenchPage page, IMenuManager subMenu, CDOCheckout checkout)
  {
    if (checkout.isReadOnly())
    {
      super.fillCommitAction(page, subMenu, checkout);
    }
  }

  @Override
  protected void fillOtherCheckoutAction(IWorkbenchPage page, IMenuManager subMenu, CDOCheckout checkout, CDOCheckout otherCheckout)
  {
    if (checkout.isReadOnly() == otherCheckout.isReadOnly())
    {
      super.fillOtherCheckoutAction(page, subMenu, checkout, otherCheckout);
    }
  }

  @Override
  protected String getHistorizedBranchPointToolTip(boolean allowTimeStamp)
  {
    return allowTimeStamp ? "Switch to this branch point" : "Switch to this branch";
  }

  @Override
  protected String getOtherBranchPointToolTip(boolean allowTimeStamp)
  {
    return allowTimeStamp ? "Select a branch point and switch to it" : "Select a branch and switch to it";
  }

  @Override
  protected String getCommitBranchPointToolTip()
  {
    return "Select a commit and switch to it";
  }

  @Override
  protected String getOtherCheckoutToolTip()
  {
    return "Switch to the branch point of this checkout";
  }

  @Override
  protected void execute(CDOCheckout checkout, CDOBranchPoint branchPoint) throws Exception
  {
    switchTo(checkout, branchPoint);
  }

  public static void switchTo(CDOCheckout checkout, CDOBranchPoint branchPoint)
  {
    checkout.setBranchPoint(branchPoint);
  }

  /**
   * @author Eike Stepper
   */
  private static class SwitchToNewBranchAction extends CreateBranchAction
  {
    private static final String ID = OM.BUNDLE_ID + ".SwitchToNewBranchAction"; //$NON-NLS-1$

    private final CDOCheckout checkout;

    public SwitchToNewBranchAction(IWorkbenchPage page, CDOCheckout checkout)
    {
      super(page, checkout.getView());
      this.checkout = checkout;
      setId(ID);

      setText("New Branch...");
      setImageDescriptor(OM.getImageDescriptor("icons/branch.gif"));
      setToolTipText("Create a new branch and switch this checkout to it");
    }

    @Override
    protected void doRun(IProgressMonitor progressMonitor) throws Exception
    {
      super.doRun(progressMonitor);

      CDOBranchPoint base = getBase();
      CDOBranch newBranch = base.getBranch().getBranch(getName());
      checkout.setBranchPoint(newBranch.getHead());
    }
  }
}

Back to the top