1 /*******************************************************************************
2 * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org
.eclipse
.egit
.ui
.internal
.actions
;
11 import java
.util
.Collection
;
12 import java
.util
.List
;
14 import org
.eclipse
.core
.resources
.IFile
;
15 import org
.eclipse
.core
.resources
.IResource
;
16 import org
.eclipse
.egit
.core
.op
.AddToIndexOperation
;
17 import org
.eclipse
.egit
.core
.op
.IEGitOperation
;
18 import org
.eclipse
.egit
.ui
.UIText
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.swt
.widgets
.Display
;
23 * An action to add files to a Git index.
25 * @see AddToIndexOperation
27 public class AddToIndexAction
extends AbstractResourceOperationAction
{
28 private AddToIndexOperation operation
= null;
30 protected IEGitOperation
createOperation(final List
<IResource
> sel
) {
34 operation
= new AddToIndexOperation(sel
);
40 protected void postOperation() {
41 Collection
<IFile
> notAddedFiles
= operation
.getNotAddedFiles();
42 if (notAddedFiles
.size()==0)
44 final String title
= UIText
.AddToIndexAction_addingFilesFailed
;
45 String message
= UIText
.AddToIndexAction_indexesWithUnmergedEntries
;
46 message
+= "\n\n"; //$NON-NLS-1$
47 message
+= getFileList(notAddedFiles
);
48 final String fMessage
= message
;
49 Display
.getDefault().asyncExec(new Runnable() {
51 MessageDialog
.openWarning(wp
.getSite().getShell(), title
, fMessage
);
57 private static String
getFileList(Collection
<IFile
> notAddedFiles
) {
58 String result
= ""; //$NON-NLS-1$
59 for (IFile file
: notAddedFiles
) {
60 result
+= file
.getName();
61 result
+= "\n"; //$NON-NLS-1$
67 protected String
getJobName() {
68 return UIText
.AddToIndexAction_addingFiles
;