Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-10-19 10:45:42 +0000
committerEike Stepper2010-10-19 10:45:42 +0000
commit919ffcd833862ea1216c00d318030662f8c0cc29 (patch)
treeb4a7121657ab11026aea6c38b1653ddc707f7c7d /plugins/org.eclipse.emf.cdo.ui.workspace
parentcd3cf8d6d462c75aedc127c7dc24c0f05be3fe7d (diff)
downloadcdo-919ffcd833862ea1216c00d318030662f8c0cc29.tar.gz
cdo-919ffcd833862ea1216c00d318030662f8c0cc29.tar.xz
cdo-919ffcd833862ea1216c00d318030662f8c0cc29.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')
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.workspace/META-INF/MANIFEST.MF7
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutAction.java95
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutDialog.java80
3 files changed, 175 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui.workspace/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.ui.workspace/META-INF/MANIFEST.MF
index a4090f9d58..e6d95ed4a0 100644
--- a/plugins/org.eclipse.emf.cdo.ui.workspace/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.ui.workspace/META-INF/MANIFEST.MF
@@ -10,7 +10,12 @@ Bundle-Activator: org.eclipse.emf.cdo.ui.internal.workspace.bundle.OM$Activator
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.cdo.workspace;bundle-version="[4.0.0,5.0.0)",
- org.eclipse.emf.cdo.ui.location;bundle-version="[4.0.0,5.0.0)"
+ org.eclipse.emf.cdo.ui.location;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.emf.cdo.server.db;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.net4j.db.h2;bundle-version="[4.0.0,5.0.0)"
+Import-Package: org.h2;version="[1.1.0,1.2.0)",
+ org.h2.jdbcx;version="[1.1.0,1.2.0)"
Export-Package: org.eclipse.emf.cdo.ui.internal.workspace;version="4.0.0";x-internal:=true,
org.eclipse.emf.cdo.ui.internal.workspace.bundle;version="4.0.0";x-internal:=true
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 7391f715af..e7d37bc234 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
@@ -11,35 +11,118 @@
*/
package org.eclipse.emf.cdo.ui.internal.workspace;
+import org.eclipse.emf.cdo.location.ICheckoutSource;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
+import org.eclipse.emf.cdo.server.db.IDBStore;
+import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
+import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory;
+import org.eclipse.emf.cdo.ui.internal.workspace.bundle.OM;
+import org.eclipse.emf.cdo.workspace.CDOWorkspaceBase;
+import org.eclipse.emf.cdo.workspace.CDOWorkspaceUtil;
+
+import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBAdapter;
+import org.eclipse.net4j.db.IDBConnectionProvider;
+import org.eclipse.net4j.db.h2.H2Adapter;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.swt.widgets.Shell;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
+import org.h2.jdbcx.JdbcDataSource;
+
+import javax.sql.DataSource;
+
+import java.io.File;
+
/**
* @author Eike Stepper
*/
public class CheckoutAction implements IObjectActionDelegate
{
- private Shell shell;
+ private IWorkbenchPart part;
+
+ private ISelection selection;
public CheckoutAction()
{
}
- public void setActivePart(IAction action, IWorkbenchPart targetPart)
+ public void setActivePart(IAction action, IWorkbenchPart part)
{
- shell = targetPart.getSite().getShell();
+ this.part = part;
}
public void selectionChanged(IAction action, ISelection selection)
{
+ this.selection = selection;
}
public void run(IAction action)
{
- MessageDialog.openInformation(shell, "CDO Model Repository Client UI Workspace", "Checkout... was executed.");
+ if (selection instanceof IStructuredSelection)
+ {
+ final Object element = ((IStructuredSelection)selection).getFirstElement();
+ if (element instanceof ICheckoutSource)
+ {
+ CheckoutDialog dialog = new CheckoutDialog(part.getSite().getShell());
+ if (dialog.open() == CheckoutDialog.OK)
+ {
+ final String projectName = dialog.getProjectName();
+ new Job("Checking out...")
+ {
+ @Override
+ protected IStatus run(IProgressMonitor monitor)
+ {
+ try
+ {
+ CheckoutAction.this.run((ICheckoutSource)element, projectName, monitor);
+ return Status.OK_STATUS;
+ }
+ catch (Exception ex)
+ {
+ return new Status(IStatus.ERROR, OM.BUNDLE_ID, "Problem during check out: " + ex.getLocalizedMessage(),
+ ex);
+ }
+ }
+ }.schedule();
+ }
+ }
+ }
+ }
+
+ protected void run(ICheckoutSource checkoutSource, String projectName, IProgressMonitor monitor)
+ {
+ IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(false);
+ IDBAdapter dbAdapter = createLocalAdapter(projectName);
+ IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(createLocalDataSource(projectName));
+ IDBStore local = CDODBUtil.createStore(mappingStrategy, dbAdapter, dbConnectionProvider);
+
+ CDOWorkspaceBase base = createWorkspaceBase(projectName);
+ CDOSessionConfigurationFactory remote = checkoutSource.getRepositoryLocation();
+ CDOWorkspaceUtil.checkout(local, base, remote, checkoutSource.getBranchPath(), checkoutSource.getTimeStamp());
+ }
+
+ protected IDBAdapter createLocalAdapter(String projectName)
+ {
+ return new H2Adapter();
+ }
+
+ protected DataSource createLocalDataSource(String projectName)
+ {
+ JdbcDataSource dataSource = new JdbcDataSource();
+ dataSource.setURL("jdbc:h2:_database/repo1");
+ return dataSource;
+ }
+
+ protected CDOWorkspaceBase createWorkspaceBase(String projectName)
+ {
+ return CDOWorkspaceUtil.createFolderWorkspaceBase(new File(projectName));
}
}
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
new file mode 100644
index 0000000000..f541e9685b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui.workspace/src/org/eclipse/emf/cdo/ui/internal/workspace/CheckoutDialog.java
@@ -0,0 +1,80 @@
+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.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author Eike Stepper
+ */
+public class CheckoutDialog extends TitleAreaDialog
+{
+ private Text projectNameText;
+
+ private String projectName;
+
+ public CheckoutDialog(Shell parentShell)
+ {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL | SWT.MAX | SWT.TITLE | SWT.RESIZE);
+ }
+
+ public String getProjectName()
+ {
+ return projectName;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ super.configureShell(newShell);
+ newShell.setText("Check out");
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ setTitle("Check out");
+ // setTitleImage(SharedIcons.getImage(SharedIcons.WIZBAN_PACKAGE_MANAGER));
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(1, false));
+
+ // Group group1 = new Group(composite, SWT.NONE);
+ // group1.setLayout(new GridLayout(1, false));
+ // group1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
+ // group1.setText("Connection");
+ // connectorWizard = new ElementWizardComposite.WithRadios(group1, SWT.NONE, "org.eclipse.net4j.connectors",
+ // "Type:");
+ // connectorWizard.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+
+ Group group2 = new Group(composite, SWT.NONE);
+ group2.setLayout(new GridLayout(1, false));
+ group2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
+ group2.setText("Repository");
+ projectNameText = new Text(group2, SWT.BORDER);
+ projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ return composite;
+ }
+
+ protected IManagedContainer getContainer()
+ {
+ return IPluginContainer.INSTANCE;
+ }
+
+ @Override
+ protected void okPressed()
+ {
+ projectName = projectNameText.getText();
+ super.okPressed();
+ }
+}

Back to the top