Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 344e2c6323b55083213c955ecc6503b1311d0d30 (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
/*
 * Copyright (c) 2015, 2016 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.explorer.ui.handlers;

import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.explorer.repositories.CDORepository;
import org.eclipse.emf.cdo.explorer.repositories.CDORepositoryElement;
import org.eclipse.emf.cdo.explorer.ui.checkouts.wizards.CheckoutWizard;
import org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutImpl;

import org.eclipse.net4j.util.AdapterUtil;
import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.ui.handlers.AbstractBaseHandler;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.IProgressMonitor;

import java.util.Properties;

/**
 * @author Eike Stepper
 */
public class RepositoryCheckoutHandlerQuick extends AbstractBaseHandler<CDORepositoryElement>
{
  public RepositoryCheckoutHandlerQuick()
  {
    super(CDORepositoryElement.class, false);
  }

  @Override
  protected void doExecute(ExecutionEvent event, IProgressMonitor monitor) throws Exception
  {
    checkout(elements.get(0), CDOCheckout.TYPE_ONLINE_TRANSACTIONAL);
  }

  public static CDOCheckout checkout(CDORepositoryElement repositoryElement, String type)
  {
    CDORepository repository = repositoryElement.getRepository();
    String readOnly = (CDOCheckout.TYPE_ONLINE_HISTORICAL.equals(type) ? Boolean.TRUE : Boolean.FALSE).toString();
    String label = StringUtil.capAll(type.replace('-', ' ')) + " Checkout";

    Properties properties = new Properties();
    properties.setProperty(CDOCheckoutImpl.PROP_TYPE, type);
    properties.setProperty(CDOCheckoutImpl.PROP_LABEL, CDOExplorerUtil.getCheckoutManager().getUniqueLabel(label));
    properties.setProperty(CDOCheckoutImpl.PROP_REPOSITORY, repository.getID());
    properties.setProperty(CDOCheckoutImpl.PROP_BRANCH_ID, Integer.toString(repositoryElement.getBranchID()));
    properties.setProperty(CDOCheckoutImpl.PROP_TIME_STAMP, Long.toString(repositoryElement.getTimeStamp()));
    properties.setProperty(CDOCheckoutImpl.PROP_READ_ONLY, readOnly);
    properties.setProperty(CDOCheckoutImpl.PROP_ROOT_ID, CDOCheckoutImpl.getCDOIDString(repositoryElement.getObjectID()));

    CDOCheckout checkout = CDOExplorerUtil.getCheckoutManager().addCheckout(properties);
    checkout.open();

    CheckoutWizard.showInProjectExplorer(checkout);
    return checkout;
  }

  public static CDOCheckout checkout(CDORepository repository, String type)
  {
    CDORepositoryElement repositoryElement = AdapterUtil.adapt(repository, CDORepositoryElement.class);
    return checkout(repositoryElement, type);
  }
}

Back to the top