Eclipseplugins
DbAndBinaryHandler.java
1 package com.proalpha.pds.gitutils.external;
2 
3 import java.util.Collections;
4 import java.util.List;
5 
6 import org.eclipse.core.commands.AbstractHandler;
7 import org.eclipse.core.commands.ExecutionEvent;
8 import org.eclipse.core.commands.ExecutionException;
9 import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.jface.viewers.ISelection;
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.jface.wizard.WizardDialog;
14 import org.eclipse.jgit.api.Git;
15 import org.eclipse.jgit.api.Status;
16 import org.eclipse.jgit.api.errors.GitAPIException;
17 import org.eclipse.jgit.errors.NoWorkTreeException;
18 import org.eclipse.jgit.lib.Repository;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.handlers.HandlerUtil;
22 
23 import com.proalpha.pds.gitutils.Activator;
24 
25 public class DbAndBinaryHandler extends AbstractHandler {
26 
27  @Override
28  public Object execute(ExecutionEvent event) throws ExecutionException {
29 
30  // initialize repository
31  RepositoryTreeNode<?> treenode = (RepositoryTreeNode<?>) getSelectedNodes(event).get(0);
32  Repository repository = treenode.getRepository();
33 
34  try (Git git = new Git(repository)) {
35  Status status = git.status().call();
36 
37  if (!status.isClean()) {
38  MessageDialog.openError(Display.getCurrent().getActiveShell(), "Repository Status" ,
39  "Repository is not clean. Operations are permitted! Clean your repository and try again.");
40  return null;
41  }
42  } catch (NoWorkTreeException | GitAPIException e) {
43  Activator.logToConsole(String.format("Error in Method getStagedFiles: %s", e.getMessage()));
44  }
45 
46  DBAndBinaryWizard dbwiz = new DBAndBinaryWizard(repository);
47  WizardDialog wiz = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dbwiz);
48  wiz.open();
49  return null;
50  }
51 
52  public <T> List<T> getSelectedNodes(ExecutionEvent event) throws ExecutionException {
53  ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
54  if (selection instanceof IStructuredSelection)
55  return ((IStructuredSelection) selection).toList();
56  else
57  return Collections.emptyList();
58  }
59 
60 }