提交 1f362f1d 编写于 作者: S Serge Rider

New project wizard redesign

上级 707ef0f5
......@@ -2257,7 +2257,7 @@
class="org.jkiss.dbeaver.tools.project.ProjectCreateWizard"
icon="icons/project.png"
id="org.jkiss.dbeaver.core.wizard.new.project"
name="Project">
name="Database Project">
<description>
DBeaver Project
</description>
......@@ -2267,7 +2267,7 @@
class="org.jkiss.dbeaver.ui.dialogs.connection.NewConnectionWizard"
icon="icons/database.png"
id="org.jkiss.dbeaver.core.wizard.new.connection"
name="Connection">
name="Database Connection">
<description>
Database connection
</description>
......
......@@ -781,18 +781,6 @@ public class CoreMessages extends NLS {
public static String dialog_new_connection_wizard_title;
public static String dialog_project_create_settings_description;
public static String dialog_project_create_settings_group_general;
public static String dialog_project_create_settings_label_description;
public static String dialog_project_create_settings_label_name;
public static String dialog_project_create_settings_name;
public static String dialog_project_create_settings_title;
public static String dialog_project_create_wizard_error_already_exists;
public static String dialog_project_create_wizard_error_cannot_create;
......
......@@ -465,12 +465,6 @@ dialog_new_connection_wizard_monitor_load_data_sources=Load data sources
dialog_new_connection_wizard_start_description=Create new connection. If you don't see your database in the list\nthen you can create new database driver in the driver manager.
dialog_new_connection_wizard_start_title=Select new connection type
dialog_new_connection_wizard_title=Create new connection
dialog_project_create_settings_description=Set project settings.
dialog_project_create_settings_group_general=General
dialog_project_create_settings_label_description=Description
dialog_project_create_settings_label_name=Name
dialog_project_create_settings_name=Create new project
dialog_project_create_settings_title=Create new project
dialog_project_create_wizard_error_already_exists=Project "{0}" already exists
dialog_project_create_wizard_error_cannot_create=Create error
dialog_project_create_wizard_error_cannot_create_message=Cannot create project
......
......@@ -24,10 +24,13 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverCore;
......@@ -43,15 +46,17 @@ import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
public class ProjectCreateWizard extends Wizard implements INewWizard {
public class ProjectCreateWizard extends BasicNewProjectResourceWizard implements INewWizard {
private ProjectCreateData data = new ProjectCreateData();
private WizardPrefPage projectSettingsPage;
public ProjectCreateWizard() {
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
super.init(workbench, selection);
setWindowTitle(CoreMessages.dialog_project_create_wizard_title);
setNeedsProgressMonitor(true);
}
......@@ -59,60 +64,62 @@ public class ProjectCreateWizard extends Wizard implements INewWizard {
@Override
public void addPages() {
super.addPages();
addPage(new ProjectCreateWizardPageSettings(data));
final PrefPageProjectSettings projectSettingsPref = new PrefPageProjectSettings();
WizardPrefPage projectSettingsPage = new WizardPrefPage(projectSettingsPref, "Resources", "Project resources");
projectSettingsPage = new WizardPrefPage(projectSettingsPref, "Resources", "Project resources");
addPage(projectSettingsPage);
}
@Override
@Override
public IWizardPage getNextPage(IWizardPage page) {
if (page instanceof WizardNewProjectCreationPage) {
return projectSettingsPage;
}
return super.getNextPage(page);
}
@Override
public boolean performFinish() {
try {
DBeaverUI.run(getContainer(), true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
createProject(monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
if (super.performFinish()) {
try {
DBeaverUI.run(getContainer(), true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
createProject(monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
}
});
}
catch (InterruptedException ex) {
return false;
}
catch (InvocationTargetException ex) {
UIUtils.showErrorDialog(
getShell(),
CoreMessages.dialog_project_create_wizard_error_cannot_create,
CoreMessages.dialog_project_create_wizard_error_cannot_create_message,
ex.getTargetException());
});
} catch (InterruptedException ex) {
return false;
} catch (InvocationTargetException ex) {
UIUtils.showErrorDialog(
getShell(),
CoreMessages.dialog_project_create_wizard_error_cannot_create,
CoreMessages.dialog_project_create_wizard_error_cannot_create_message,
ex.getTargetException());
return false;
}
return true;
} else {
return false;
}
return true;
}
private void createProject(DBRProgressMonitor monitor) throws DBException, CoreException
{
IWorkspace workspace = DBeaverCore.getInstance().getWorkspace();
IProject project = workspace.getRoot().getProject(data.getName());
if (project.exists()) {
throw new DBException(NLS.bind(CoreMessages.dialog_project_create_wizard_error_already_exists, data.getName()));
}
final IProgressMonitor nestedMonitor = RuntimeUtils.getNestedMonitor(monitor);
final IProject project = getNewProject();
final IProjectDescription description = workspace.newProjectDescription(project.getName());
final IProjectDescription description = project.getDescription();
if (!CommonUtils.isEmpty(data.getDescription())) {
description.setComment(data.getDescription());
}
description.setLocation(new Path(data.getPath().getAbsolutePath()));
description.setNatureIds(new String[] {DBeaverNature.NATURE_ID});
project.setDescription(description, nestedMonitor);
final IProgressMonitor nestedMonitor = RuntimeUtils.getNestedMonitor(monitor);
if (!project.exists()) {
project.create(description, nestedMonitor);
project.open(nestedMonitor);
} else {
if (!project.isOpen()) {
project.open(nestedMonitor);
}
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.tools.project;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.internal.Workbench;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.TextWithOpenFolder;
import org.jkiss.utils.CommonUtils;
import java.io.File;
class ProjectCreateWizardPageSettings extends WizardPage {
public static final String DEFAULT_PROJECT_NAME = "Project";
private ProjectCreateData createData;
private Text projectNameText;
protected ProjectCreateWizardPageSettings(ProjectCreateData importData)
{
super(CoreMessages.dialog_project_create_settings_name);
this.createData = importData;
setTitle(CoreMessages.dialog_project_create_settings_title);
setDescription(CoreMessages.dialog_project_create_settings_description);
}
@Override
public boolean isPageComplete()
{
return !CommonUtils.isEmpty(createData.getName());
}
@Override
public void createControl(Composite parent)
{
Composite placeholder = UIUtils.createPlaceholder(parent, 1);
Composite configGroup = UIUtils.createControlGroup(placeholder, CoreMessages.dialog_project_create_settings_group_general, 2, GridData.FILL_HORIZONTAL, 0);
projectNameText = UIUtils.createLabelText(configGroup, CoreMessages.dialog_project_create_settings_label_name, DEFAULT_PROJECT_NAME);
createData.setName(DEFAULT_PROJECT_NAME);
final Text projectDescriptionText = UIUtils.createLabelText(configGroup, CoreMessages.dialog_project_create_settings_label_description, null); //$NON-NLS-2$
projectDescriptionText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e)
{
createData.setDescription(projectDescriptionText.getText());
}
});
UIUtils.createControlLabel(configGroup, "Project path");
final TextWithOpenFolder projectPathText = new TextWithOpenFolder(configGroup, "Project path");
projectPathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final File projectParentDir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
final File projectHome = new File(projectParentDir, DEFAULT_PROJECT_NAME);
createData.setPath(projectHome);
projectPathText.setText(projectHome.getAbsolutePath());
projectPathText.getTextControl().addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
createData.setPath(new File(projectPathText.getText()));
updateState();
}
});
projectNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
final String projectName = projectNameText.getText();
createData.setName(projectName);
if (!CommonUtils.isEmptyTrimmed(projectName)) {
final File oldProjectPath = new File(projectPathText.getText());
final File newProjectPath = new File(oldProjectPath.getParent(), createData.getName());
createData.setPath(newProjectPath);
projectPathText.setText(newProjectPath.getAbsolutePath());
}
updateState();
}
});
setControl(placeholder);
}
private void updateState()
{
if (createData.getPath().exists()) {
setErrorMessage("Path '" + createData.getPath().getAbsolutePath() + "' exists (import).");
} else {
setErrorMessage(null);
}
getContainer().updateButtons();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册