--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.clone;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Allows to import a directory in the local file system as "General" project
+ * <p>
+ * Asks the user to provide a project name and shows the directory to be shared.
+ * <p>
+ * Original source : {@link GitCreateGeneralProjectPage}
+ * </p>
+ */
+public class RtGitCreateGeneralProjectPage extends WizardPage {
+
+ private File myDirectory;
+
+ private Text projectText;
+
+ private Text directoryText;
+
+ private IProject[] wsProjects;
+
+ private boolean defaultLocation;
+
+ /**
+ * Creates a new project creation wizard page.
+ * @param path the path to a directory in the local file system
+ */
+ public RtGitCreateGeneralProjectPage(String path) {
+ super(RtGitCreateGeneralProjectPage.class.getName());
+ myDirectory = new File(path);
+ setPageComplete(false);
+ setTitle(UIText.WizardProjectsImportPage_ImportProjectsTitle);
+ setDescription(UIText.WizardProjectsImportPage_ImportProjectsDescription);
+ // check for default location: is workspace location parent of path?
+ IPath parent = new Path(path).removeLastSegments(1);
+ if (ResourcesPlugin.getWorkspace().getRoot().getLocation().equals(parent))
+ defaultLocation = true;
+ else
+ defaultLocation = false;
+ }
+
+ /**
+ * The path must be initialized using setPath()
+ */
+ public RtGitCreateGeneralProjectPage() {
+ super(RtGitCreateGeneralProjectPage.class.getName());
+ setPageComplete(false);
+ setTitle(UIText.WizardProjectsImportPage_ImportProjectsTitle);
+ setDescription(UIText.WizardProjectsImportPage_ImportProjectsDescription);
+ }
+
+ /**
+ * @param path
+ */
+ public void setPath(String path) {
+ if (path != null)
+ myDirectory = new File(path);
+ else
+ myDirectory = null;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+
+ initializeDialogUnits(parent);
+
+ Composite workArea = new Composite(parent, SWT.NONE);
+ setControl(workArea);
+
+ workArea.setLayout(new GridLayout(2, false));
+ workArea.setLayoutData(new GridData(GridData.FILL_BOTH
+ | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
+
+ new Label(workArea, SWT.NONE)
+ .setText(UIText.GitCreateGeneralProjectPage_ProjectNameLabel);
+ projectText = new Text(workArea, SWT.BORDER);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(projectText);
+ if (defaultLocation)
+ projectText.setEnabled(false);
+ else
+ projectText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ checkPage();
+ }
+ });
+
+ new Label(workArea, SWT.NONE)
+ .setText(UIText.GitCreateGeneralProjectPage_DirLabel);
+ directoryText = new Text(workArea, SWT.BORDER);
+ directoryText.setEnabled(false);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(directoryText);
+
+ Dialog.applyDialogFont(workArea);
+
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ if (visible) {
+ projectText.setText(myDirectory.getName());
+ directoryText.setText(myDirectory.getPath());
+ checkPage();
+ }
+ super.setVisible(visible);
+ }
+
+ /**
+ * @return the project name
+ */
+ public String getProjectName() {
+ return projectText.getText();
+ }
+
+ /**
+ * @return true if the project has default location
+ */
+ public boolean isDefaultLocation() {
+ return defaultLocation;
+ }
+
+ private void checkPage() {
+ String projectName = projectText.getText();
+ setErrorMessage(null);
+ try {
+ // make sure the directory exists
+ if (!myDirectory.exists()) {
+ setErrorMessage(NLS.bind(
+ UIText.GitCreateGeneralProjectPage_DirNotExistMessage,
+ myDirectory.getPath()));
+ return;
+ }
+ // make sure we don't have a file
+ if (!myDirectory.isDirectory()) {
+ setErrorMessage(NLS.bind(
+ UIText.GitCreateGeneralProjectPage_FileNotDirMessage,
+ myDirectory.getPath()));
+ return;
+ }
+ /* Tizen */
+ // make sure there is not already a .project file
+ // if (myDirectory.list(new FilenameFilter() {
+ //
+ // @Override
+ // public boolean accept(File dir, String name) {
+ // if (name.equals(".project")) //$NON-NLS-1$
+ // return true;
+ // return false;
+ // }
+ // }).length > 0) {
+ // setErrorMessage(NLS
+ // .bind(
+ // UIText.GitCreateGeneralProjectPage_FileExistsInDirMessage,
+ // ".project", myDirectory.getPath())); //$NON-NLS-1$
+ // return;
+ // }
+ /* ===== */
+ // project name empty
+ if (projectName.length() == 0) {
+ setErrorMessage(UIText.GitCreateGeneralProjectPage_EnterProjectNameMessage);
+ return;
+ }
+ // project name valid (no strange chars...)
+ IStatus result = ResourcesPlugin.getWorkspace().validateName(
+ projectName, IResource.PROJECT);
+ if (!result.isOK()) {
+ setErrorMessage(result.getMessage());
+ return;
+ }
+ // project already exists
+ if (isProjectInWorkspace(projectName)) {
+ setErrorMessage(NLS
+ .bind(
+ UIText.GitCreateGeneralProjectPage_PorjectAlreadyExistsMessage,
+ projectName));
+ return;
+ }
+ if (!defaultLocation) {
+ IProject newProject = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+ IStatus locationResult = ResourcesPlugin.getWorkspace()
+ .validateProjectLocation(newProject,
+ new Path(myDirectory.getPath()));
+ if (!locationResult.isOK()) {
+ setErrorMessage(locationResult.getMessage());
+ return;
+ }
+ }
+ } finally {
+ setPageComplete(getErrorMessage() == null);
+ }
+
+ }
+
+ private IProject[] getProjectsInWorkspace() {
+ if (wsProjects == null) {
+ wsProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ }
+ return wsProjects;
+ }
+
+ private boolean isProjectInWorkspace(String projectName) {
+ if (projectName == null) {
+ return false;
+ }
+ IProject[] workspaceProjects = getProjectsInWorkspace();
+ for (int i = 0; i < workspaceProjects.length; i++) {
+ if (projectName.equals(workspaceProjects[i].getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
}
};
- private GitCreateGeneralProjectPage createGeneralProjectPage = new GitCreateGeneralProjectPage() {
+ private RtGitCreateGeneralProjectPage createGeneralProjectPage = new RtGitCreateGeneralProjectPage() {
@Override
public void setVisible(boolean visible) {
if (visible)
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
importProjects(monitor);
+ /* Tizen */
// Add CDT nature to current project
IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
IProject project = null;
}
}
- /* Tizen */
if (project != null) {
try {
RtProjectNature.makeRtProject(project, monitor);
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
/**
* Asks the user to select a wizard and what to do with the imported projects (automatic/manual/no share)
/** */
public static final int GENERAL_WIZARD = 2;
+ /* Tizen */
+ public static final String GitImportWithDirectoriesPage_PageMessage = "You may select a directory to determine the import scope";
+ public static final String GitImportWithDirectoriesPage_PageTitle = "Select a directory to use for importing projects";
+ public static final String GitImportWithDirectoriesPage_selectFolder = "The resources under the \"%s\" directory will be imported as a new project";
+ /* ===== */
+
+
// TODO check if we need/can support Import... wizard
// see also remarks in GitCreateProjectViaWizardWizard
private final String PREF_WIZ = getName() + "WizardSel"; //$NON-NLS-1$
- private Button importExisting;
-
- private Button newProjectWizard;
-
- private Button generalWizard;
+ /* Tizen */
+ // private Button importExisting;
+ //
+ // private Button newProjectWizard;
+ //
+ // private Button generalWizard;
+ /* ===== */
private TreeViewer tv;
private final String initialPath;
- private int wizardSelection = EXISTING_PROJECTS_WIZARD;
+ /* Tizen */
+ // private int wizardSelection = EXISTING_PROJECTS_WIZARD;
+ private int wizardSelection = GENERAL_WIZARD;
+ /* ===== */
/**
* Default constructor
*/
public RtGitSelectWizardPage() {
super(RtGitSelectWizardPage.class.getName());
- setTitle(UIText.GitImportWithDirectoriesPage_PageTitle);
- setMessage(UIText.GitImportWithDirectoriesPage_PageMessage);
+ /* Tizen */
+ // setTitle(UIText.GitImportWithDirectoriesPage_PageTitle);
+ // setMessage(UIText.GitImportWithDirectoriesPage_PageMessage);
+ setTitle(GitImportWithDirectoriesPage_PageTitle);
+ setMessage(GitImportWithDirectoriesPage_PageMessage);
+ /* ===== */
initialRepository = null;
initialPath = null;
}
*/
public RtGitSelectWizardPage(Repository repository, String path) {
super(RtGitSelectWizardPage.class.getName());
- setTitle(UIText.GitImportWithDirectoriesPage_PageTitle);
- setMessage(UIText.GitImportWithDirectoriesPage_PageMessage);
+ /* Tizen */
+ // setTitle(UIText.GitImportWithDirectoriesPage_PageTitle);
+ // setMessage(UIText.GitImportWithDirectoriesPage_PageMessage);
+ setTitle(GitImportWithDirectoriesPage_PageTitle);
+ setMessage(GitImportWithDirectoriesPage_PageMessage);
+ /* ===== */
initialRepository = repository;
initialPath = path;
}
main.setLayout(new GridLayout(1, false));
- SelectionListener sl = new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- tv.getTree().setEnabled(!newProjectWizard.getSelection());
- if (importExisting.getSelection())
- wizardSelection = EXISTING_PROJECTS_WIZARD;
- else if (newProjectWizard.getSelection())
- wizardSelection = NEW_WIZARD;
- else if (generalWizard.getSelection())
- wizardSelection = GENERAL_WIZARD;
- else
- wizardSelection = EXISTING_PROJECTS_WIZARD;
- checkPage();
- }
- };
-
- Group wizardType = new Group(main, SWT.SHADOW_ETCHED_IN);
- GridDataFactory.fillDefaults().grab(true, false).applyTo(wizardType);
- wizardType.setText(UIText.GitSelectWizardPage_ProjectCreationHeader);
- wizardType.setLayout(new GridLayout(1, false));
-
- importExisting = new Button(wizardType, SWT.RADIO);
- importExisting.setText(UIText.GitSelectWizardPage_ImportExistingButton);
- importExisting.addSelectionListener(sl);
-
- newProjectWizard = new Button(wizardType, SWT.RADIO);
- newProjectWizard.setText(UIText.GitSelectWizardPage_UseNewProjectsWizardButton);
- newProjectWizard.addSelectionListener(sl);
/* Tizen */
- // Modified for disable
- newProjectWizard.setEnabled(false);
+ // SelectionListener sl = new SelectionAdapter() {
+ // @Override
+ // public void widgetSelected(SelectionEvent e) {
+ // tv.getTree().setEnabled(!newProjectWizard.getSelection());
+ // if (importExisting.getSelection())
+ // wizardSelection = EXISTING_PROJECTS_WIZARD;
+ // else if (newProjectWizard.getSelection())
+ // wizardSelection = NEW_WIZARD;
+ // else if (generalWizard.getSelection())
+ // wizardSelection = GENERAL_WIZARD;
+ // else
+ // wizardSelection = EXISTING_PROJECTS_WIZARD;
+ // checkPage();
+ // }
+ // };
+ //
+ // Group wizardType = new Group(main, SWT.SHADOW_ETCHED_IN);
+ // GridDataFactory.fillDefaults().grab(true, false).applyTo(wizardType);
+ // wizardType.setText(UIText.GitSelectWizardPage_ProjectCreationHeader);
+ // wizardType.setLayout(new GridLayout(1, false));
+ //
+ // importExisting = new Button(wizardType, SWT.RADIO);
+ // importExisting.setText(UIText.GitSelectWizardPage_ImportExistingButton);
+ // importExisting.addSelectionListener(sl);
+ //
+ // newProjectWizard = new Button(wizardType, SWT.RADIO);
+ // newProjectWizard.setText(UIText.GitSelectWizardPage_UseNewProjectsWizardButton);
+ // newProjectWizard.addSelectionListener(sl);
+ // // Modified for disable
+ // newProjectWizard.setEnabled(false);
+ //
+ // generalWizard = new Button(wizardType, SWT.RADIO);
+ // generalWizard.setText(UIText.GitSelectWizardPage_ImportAsGeneralButton);
+ // generalWizard.addSelectionListener(sl);
+ //
+ // IDialogSettings settings = Activator.getDefault().getDialogSettings();
+ // try {
+ // wizardSelection = settings.getInt(PREF_WIZ);
+ // } catch (NumberFormatException e) {
+ // wizardSelection = EXISTING_PROJECTS_WIZARD;
+ // }
+ // switch (wizardSelection) {
+ // case EXISTING_PROJECTS_WIZARD:
+ // importExisting.setSelection(true);
+ // break;
+ // case GENERAL_WIZARD:
+ // generalWizard.setSelection(true);
+ // break;
+ // case NEW_WIZARD:
+ // newProjectWizard.setSelection(true);
+ // break;
+ //
+ // }
/* ===== */
- generalWizard = new Button(wizardType, SWT.RADIO);
- generalWizard.setText(UIText.GitSelectWizardPage_ImportAsGeneralButton);
- generalWizard.addSelectionListener(sl);
-
- IDialogSettings settings = Activator.getDefault().getDialogSettings();
- try {
- wizardSelection = settings.getInt(PREF_WIZ);
- } catch (NumberFormatException e) {
- wizardSelection = EXISTING_PROJECTS_WIZARD;
- }
- switch (wizardSelection) {
- case EXISTING_PROJECTS_WIZARD:
- importExisting.setSelection(true);
- break;
- case GENERAL_WIZARD:
- generalWizard.setSelection(true);
- break;
- case NEW_WIZARD:
- newProjectWizard.setSelection(true);
- break;
-
- }
-
tv = new TreeViewer(main, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
RepositoriesViewContentProvider cp = new RepositoriesViewContentProvider();
tv.setContentProvider(cp);
}
}
}
- tv.getTree().setEnabled(!newProjectWizard.getSelection());
+ /* Tizen */
+ // tv.getTree().setEnabled(!newProjectWizard.getSelection());
+ /* ===== */
Dialog.applyDialogFont(main);
setControl(main);
setErrorMessage(null);
- if (newProjectWizard.getSelection()) {
- setPageComplete(true);
- return;
- }
+ /* Tizen */
+ // if (newProjectWizard.getSelection()) {
+ // setPageComplete(true);
+ // return;
+ // }
+ /* ===== */
IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
try {
setErrorMessage(UIText.GitImportWithDirectoriesPage_SelectFolderMessage);
return;
}
+
+ /* Tizen */
+ // normal case
+ setMessage(String.format(GitImportWithDirectoriesPage_selectFolder, node.getPath()));
+ /* ===== */
} finally {
setPageComplete(getErrorMessage() == null);
}
newNatures[prevNatures.length] = natureId;
description.setNatureIds(newNatures);
project.setDescription(description, monitor);
- }
-
- catch (CoreException e) {
- CCorePlugin.log(e);
- }
-
- finally {
+ } catch (CoreException e) {
+ throw (e);
+ } finally {
monitor.done();
}
}