Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c641474c1e12bd65b374a3b1146f861840392e8f (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
/*
 * Copyright (c) 2015 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.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.explorer.repositories.CDORepository;
import org.eclipse.emf.cdo.explorer.ui.DeleteElementsDialog;
import org.eclipse.emf.cdo.internal.explorer.AbstractElement;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Eike Stepper
 */
public class RepositoryDeleteHandler extends AbstractRepositoryHandler
{
  private List<CDOCheckout> checkouts;

  private boolean deleteCheckoutContents;

  private boolean deleteContents;

  public RepositoryDeleteHandler()
  {
    super(null, null);
  }

  @Override
  protected void preRun(ExecutionEvent event) throws Exception
  {
    checkouts = new ArrayList<CDOCheckout>();
    deleteCheckoutContents = false;
    deleteContents = false;

    Shell shell = HandlerUtil.getActiveShell(event);
    AbstractElement[] repositories = AbstractElement.collect(elements);

    for (CDORepository repository : elements)
    {
      checkouts.addAll(Arrays.asList(repository.getCheckouts()));
    }

    int size = checkouts.size();
    if (size != 0)
    {
      String plural = size == 1 ? "" : "s";
      String message = size == 1 ? "is 1" : "are " + size;

      if (MessageDialog.openQuestion(shell, "Existing Checkouts", "There " + message + " existing checkout" + plural
          + ".\n\n" + "Are you sure you want to delete the checkout" + plural + ", too?"))
      {
        DeleteElementsDialog dialog = new DeleteElementsDialog(shell, checkouts.toArray(new AbstractElement[size]));
        if (dialog.open() == DeleteElementsDialog.OK)
        {
          deleteCheckoutContents = dialog.isDeleteContents();
        }
        else
        {
          cancel();
          return;
        }
      }
      else
      {
        cancel();
        return;
      }
    }

    DeleteElementsDialog dialog = new DeleteElementsDialog(shell, repositories);
    if (dialog.open() == DeleteElementsDialog.OK)
    {
      deleteContents = dialog.isDeleteContents();
    }
    else
    {
      cancel();
    }
  }

  @Override
  protected void doExecute(IProgressMonitor monitor) throws Exception
  {
    for (CDOCheckout checkout : checkouts)
    {
      checkout.delete(deleteCheckoutContents);
    }

    checkouts = null;

    for (CDORepository repository : elements)
    {
      repository.delete(deleteContents);
    }
  }
}

Back to the top