1 /*******************************************************************************
2 * Copyright (c) 2010 SAP AG.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Mathias Kinzler (SAP AG) - initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.clone
;
14 import java
.io
.IOException
;
15 import java
.util
.List
;
18 import org
.eclipse
.egit
.ui
.Activator
;
19 import org
.eclipse
.egit
.ui
.UIText
;
20 import org
.eclipse
.egit
.ui
.internal
.repository
.RepositoriesView
;
21 import org
.eclipse
.egit
.ui
.internal
.repository
.RepositoriesViewContentProvider
;
22 import org
.eclipse
.egit
.ui
.internal
.repository
.RepositoriesViewLabelProvider
;
23 import org
.eclipse
.egit
.ui
.internal
.repository
.RepositorySearchDialog
;
24 import org
.eclipse
.egit
.ui
.internal
.repository
.tree
.RepositoryNode
;
25 import org
.eclipse
.egit
.ui
.internal
.repository
.tree
.RepositoryTreeNode
;
26 import org
.eclipse
.jface
.dialogs
.Dialog
;
27 import org
.eclipse
.jface
.layout
.GridDataFactory
;
28 import org
.eclipse
.jface
.layout
.GridLayoutFactory
;
29 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
30 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
31 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
32 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
33 import org
.eclipse
.jface
.viewers
.TableViewer
;
34 import org
.eclipse
.jface
.window
.Window
;
35 import org
.eclipse
.jface
.wizard
.WizardDialog
;
36 import org
.eclipse
.jface
.wizard
.WizardPage
;
37 import org
.eclipse
.jgit
.lib
.Repository
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.events
.SelectionAdapter
;
40 import org
.eclipse
.swt
.events
.SelectionEvent
;
41 import org
.eclipse
.swt
.widgets
.Button
;
42 import org
.eclipse
.swt
.widgets
.Composite
;
45 * Select a repository, add or clone
47 public class GitSelectRepositoryPage
extends WizardPage
{
49 private TableViewer tv
;
51 private Button addRepo
;
53 private Button cloneRepo
;
58 public GitSelectRepositoryPage() {
59 super(GitSelectRepositoryPage
.class.getName());
60 setTitle(UIText
.GitSelectRepositoryPage_PageTitle
);
61 setMessage(UIText
.GitSelectRepositoryPage_PageMessage
);
65 * @return the repository
67 public Repository
getRepository() {
68 Object obj
= ((IStructuredSelection
) tv
.getSelection())
72 return ((RepositoryTreeNode
) obj
).getRepository();
75 public void createControl(Composite parent
) {
76 Composite main
= new Composite(parent
, SWT
.NONE
);
78 GridLayoutFactory
.fillDefaults().numColumns(2).margins(0, 0).applyTo(
81 GridDataFactory
.fillDefaults().grab(true, true).applyTo(main
);
83 tv
= new TableViewer(main
, SWT
.SINGLE
| SWT
.H_SCROLL
| SWT
.V_SCROLL
85 tv
.setContentProvider(new RepositoriesViewContentProvider());
86 GridDataFactory
.fillDefaults().grab(true, true).applyTo(tv
.getTable());
87 new RepositoriesViewLabelProvider(tv
);
89 Composite tb
= new Composite(main
, SWT
.NONE
);
90 GridLayoutFactory
.fillDefaults().numColumns(1).applyTo(tb
);
91 GridDataFactory
.fillDefaults().grab(false, true).applyTo(tb
);
93 cloneRepo
= new Button(tb
, SWT
.PUSH
);
94 cloneRepo
.setText(UIText
.GitSelectRepositoryPage_CloneButton
);
95 cloneRepo
.setToolTipText(UIText
.GitSelectRepositoryPage_CloneTooltip
);
97 GridDataFactory
.fillDefaults().grab(false, false).align(SWT
.FILL
,
98 SWT
.BEGINNING
).applyTo(cloneRepo
);
100 cloneRepo
.addSelectionListener(new SelectionAdapter() {
103 public void widgetSelected(SelectionEvent e
) {
104 List
<String
> dirsBefore
= RepositoriesView
.getDirs();
105 WizardDialog dlg
= new WizardDialog(getShell(),
106 new GitCloneWizard());
108 if (dlg
.open() == Window
.OK
) {
110 tv
.setInput(RepositoriesView
111 .getRepositoriesFromDirs(null));
112 List
<String
> dirsAfter
= RepositoriesView
.getDirs();
113 if (!dirsBefore
.containsAll(dirsAfter
)) {
114 for (String dir
: dirsAfter
) {
115 if (!dirsBefore
.contains(dir
)) {
117 RepositoryNode node
= new RepositoryNode(
118 null, new Repository(new File(
121 .setSelection(new StructuredSelection(
123 } catch (IOException e1
) {
124 Activator
.handleError(e1
.getMessage(),
131 } catch (InterruptedException e1
) {
139 addRepo
= new Button(tb
, SWT
.PUSH
);
140 GridDataFactory
.fillDefaults().grab(true, false).align(SWT
.FILL
,
141 SWT
.BEGINNING
).applyTo(addRepo
);
142 addRepo
.setText(UIText
.GitSelectRepositoryPage_AddButton
);
143 addRepo
.setToolTipText(UIText
.GitSelectRepositoryPage_AddTooltip
);
144 addRepo
.addSelectionListener(new SelectionAdapter() {
147 public void widgetSelected(SelectionEvent e
) {
148 RepositorySearchDialog dlg
= new RepositorySearchDialog(
149 getShell(), RepositoriesView
.getDirs());
150 if (dlg
.open() == Window
.OK
&& dlg
.getDirectories().size() > 0) {
152 Set
<String
> dirs
= dlg
.getDirectories();
153 for (String dir
: dirs
)
154 RepositoriesView
.addDir(new File(dir
));
156 tv
.setInput(RepositoriesView
157 .getRepositoriesFromDirs(null));
159 } catch (InterruptedException e1
) {
167 tv
.addSelectionChangedListener(new ISelectionChangedListener() {
169 public void selectionChanged(SelectionChangedEvent event
) {
175 tv
.setInput(RepositoriesView
.getRepositoriesFromDirs(null));
176 } catch (InterruptedException e
) {
180 // we need to select at least a repository to become complete
181 setPageComplete(false);
182 Dialog
.applyDialogFont(main
);
187 private void checkPage() {
188 setErrorMessage(null);
190 if (((List
) tv
.getInput()).isEmpty()) {
191 setErrorMessage(UIText
.GitSelectRepositoryPage_NoRepoFoundMessage
);
195 if (tv
.getSelection().isEmpty()) {
196 setErrorMessage(UIText
.GitSelectRepositoryPage_PleaseSelectMessage
);
200 setPageComplete(getErrorMessage() == null);