diff options
author | Eike Stepper | 2010-10-19 11:53:39 +0000 |
---|---|---|
committer | Eike Stepper | 2010-10-19 11:53:39 +0000 |
commit | 94773cab992996031aa6ee6e6770ef881754ab33 (patch) | |
tree | 010db1c49e2ce6a35e160ea6da8c9a421f9e64d8 /plugins/org.eclipse.emf.cdo.ui.workspace | |
parent | 919ffcd833862ea1216c00d318030662f8c0cc29 (diff) | |
download | cdo-94773cab992996031aa6ee6e6770ef881754ab33.tar.gz cdo-94773cab992996031aa6ee6e6770ef881754ab33.tar.xz cdo-94773cab992996031aa6ee6e6770ef881754ab33.zip |
[327405] Provide an offline CDOWorkspace with Checkout/Update/Commit workflows
https://bugs.eclipse.org/bugs/show_bug.cgi?id=327405
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.ui.workspace')
2 files changed, 84 insertions, 15 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutAction.java b/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutAction.java index e7d37bc234..61ac8b9faf 100644 --- a/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutAction.java +++ b/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutAction.java @@ -25,13 +25,20 @@ import org.eclipse.net4j.db.IDBAdapter; import org.eclipse.net4j.db.IDBConnectionProvider; import org.eclipse.net4j.db.h2.H2Adapter; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; @@ -71,10 +78,17 @@ public class CheckoutAction implements IObjectActionDelegate final Object element = ((IStructuredSelection)selection).getFirstElement(); if (element instanceof ICheckoutSource) { - CheckoutDialog dialog = new CheckoutDialog(part.getSite().getShell()); + final ICheckoutSource checkoutSource = (ICheckoutSource)element; + String projectNameDefault = checkoutSource.getRepositoryLocation().getRepositoryName(); + + Shell shell = part.getSite().getShell(); + CheckoutDialog dialog = new CheckoutDialog(shell, projectNameDefault); + if (dialog.open() == CheckoutDialog.OK) { - final String projectName = dialog.getProjectName(); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + final IProject project = root.getProject(dialog.getProjectName()); + new Job("Checking out...") { @Override @@ -82,13 +96,18 @@ public class CheckoutAction implements IObjectActionDelegate { try { - CheckoutAction.this.run((ICheckoutSource)element, projectName, monitor); + CheckoutAction.this.run(checkoutSource, project, monitor); return Status.OK_STATUS; } + catch (CoreException ex) + { + ex.printStackTrace(); + return ex.getStatus(); + } catch (Exception ex) { - return new Status(IStatus.ERROR, OM.BUNDLE_ID, "Problem during check out: " + ex.getLocalizedMessage(), - ex); + ex.printStackTrace(); + return new Status(IStatus.ERROR, OM.BUNDLE_ID, ex.getLocalizedMessage(), ex); } } }.schedule(); @@ -97,32 +116,45 @@ public class CheckoutAction implements IObjectActionDelegate } } - protected void run(ICheckoutSource checkoutSource, String projectName, IProgressMonitor monitor) + protected void run(ICheckoutSource checkoutSource, IProject project, IProgressMonitor monitor) throws Exception { + project.create(new NullProgressMonitor()); + project.open(new NullProgressMonitor()); + + IFolder cdoFolder = project.getFolder(".cdo"); + cdoFolder.create(true, true, new NullProgressMonitor()); + cdoFolder.setTeamPrivateMember(true); + + IFolder baseFolder = cdoFolder.getFolder("base"); + baseFolder.create(true, true, new NullProgressMonitor()); + + IFolder localFolder = cdoFolder.getFolder("local"); + localFolder.create(true, true, new NullProgressMonitor()); + IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(false); - IDBAdapter dbAdapter = createLocalAdapter(projectName); - IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(createLocalDataSource(projectName)); + IDBAdapter dbAdapter = createLocalAdapter(); + IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(createLocalDataSource(localFolder)); IDBStore local = CDODBUtil.createStore(mappingStrategy, dbAdapter, dbConnectionProvider); - CDOWorkspaceBase base = createWorkspaceBase(projectName); + CDOWorkspaceBase base = createWorkspaceBase(baseFolder); CDOSessionConfigurationFactory remote = checkoutSource.getRepositoryLocation(); CDOWorkspaceUtil.checkout(local, base, remote, checkoutSource.getBranchPath(), checkoutSource.getTimeStamp()); } - protected IDBAdapter createLocalAdapter(String projectName) + protected IDBAdapter createLocalAdapter() { return new H2Adapter(); } - protected DataSource createLocalDataSource(String projectName) + protected DataSource createLocalDataSource(IFolder folder) { JdbcDataSource dataSource = new JdbcDataSource(); - dataSource.setURL("jdbc:h2:_database/repo1"); + dataSource.setURL("jdbc:h2:" + folder.getLocation().toString().replace('\\', '/')); return dataSource; } - protected CDOWorkspaceBase createWorkspaceBase(String projectName) + protected CDOWorkspaceBase createWorkspaceBase(IFolder folder) { - return CDOWorkspaceUtil.createFolderWorkspaceBase(new File(projectName)); + return CDOWorkspaceUtil.createFolderWorkspaceBase(new File(folder.getLocation().toString())); } } diff --git a/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutDialog.java b/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutDialog.java index f541e9685b..d4ddc9e18a 100644 --- a/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutDialog.java +++ b/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutDialog.java @@ -3,8 +3,13 @@ package org.eclipse.emf.cdo.ui.internal.workspace; import org.eclipse.net4j.util.container.IManagedContainer; import org.eclipse.net4j.util.container.IPluginContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.dialogs.TitleAreaDialog; 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; @@ -13,6 +18,8 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import java.io.File; + /** * @author Eike Stepper */ @@ -22,10 +29,11 @@ public class CheckoutDialog extends TitleAreaDialog private String projectName; - public CheckoutDialog(Shell parentShell) + public CheckoutDialog(Shell parentShell, String projectName) { super(parentShell); setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL | SWT.MAX | SWT.TITLE | SWT.RESIZE); + this.projectName = projectName; } public String getProjectName() @@ -62,7 +70,36 @@ public class CheckoutDialog extends TitleAreaDialog group2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); group2.setText("Repository"); projectNameText = new Text(group2, SWT.BORDER); + projectNameText.setText(projectName == null ? "" : projectName); projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + projectNameText.addModifyListener(new ModifyListener() + { + public void modifyText(ModifyEvent e) + { + String projectName = projectNameText.getText(); + if (!Path.EMPTY.isValidSegment(projectName)) + { + setErrorMessage("Invalid project name."); + return; + } + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (project.exists()) + { + setErrorMessage("Project name exists."); + return; + } + + if (new File(project.getLocation().toString()).exists()) + { + setErrorMessage("Project location exists."); + return; + } + + setErrorMessage(null); + } + }); + return composite; } |