diff options
author | Eike Stepper | 2012-11-09 10:45:57 +0000 |
---|---|---|
committer | Eike Stepper | 2012-11-09 10:45:57 +0000 |
commit | 573add2b3bcb0ec6a799a665bdf91d07874e1ca8 (patch) | |
tree | ab1cb16f28a868cc1643a77e3013b1b2ae06f0ea /plugins/org.eclipse.emf.cdo.examples.installer/examples | |
parent | 04628d303137cf12dd59cfd42c5db379e5726fd3 (diff) | |
download | cdo-573add2b3bcb0ec6a799a665bdf91d07874e1ca8.tar.gz cdo-573add2b3bcb0ec6a799a665bdf91d07874e1ca8.tar.xz cdo-573add2b3bcb0ec6a799a665bdf91d07874e1ca8.zip |
[393911] Create a complete offline and fail-over example suite
https://bugs.eclipse.org/bugs/show_bug.cgi?id=393911
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.examples.installer/examples')
9 files changed, 256 insertions, 32 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Browser.gif b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Browser.gif Binary files differnew file mode 100644 index 0000000000..3929e0f633 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Browser.gif diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Commit.gif b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Commit.gif Binary files differnew file mode 100644 index 0000000000..499dd0ca60 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Commit.gif diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Merge.gif b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Merge.gif Binary files differnew file mode 100644 index 0000000000..8c37ac8d43 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/icons/Merge.gif diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/client1-repo1/node.properties b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/client1-repo1/node.properties index e87f5168d1..8cb540c3b5 100644 --- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/client1-repo1/node.properties +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/client1-repo1/node.properties @@ -1,6 +1,7 @@ #Node Settings -#Thu Nov 08 11:39:20 CET 2012 +#Fri Nov 09 11:15:39 CET 2012 Name=client1-repo1 +BrowserPort=7778 Type=Client -branch=-1 +Branch=MAIN Server=repo1 diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/repo1/node.properties b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/repo1/node.properties index b7d492446d..5b2be3fc4f 100644 --- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/repo1/node.properties +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/nodes/repo1/node.properties @@ -3,3 +3,4 @@ Name=repo1 Type=NormalRepository Port=2036 +BrowserPort=7777 diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/ClientView.java b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/ClientView.java index 85749e4a6a..baa8e5063c 100644 --- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/ClientView.java +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/ClientView.java @@ -10,17 +10,32 @@ */ package org.eclipse.emf.cdo.examples.client.offline; +import org.eclipse.emf.cdo.common.CDOCommonRepository.State; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.eresource.CDOResourceLeaf; +import org.eclipse.emf.cdo.server.IRepository; import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.ui.CDOEditorUtil; import org.eclipse.emf.cdo.ui.CDOItemProvider; +import org.eclipse.emf.cdo.util.CommitException; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.net4j.util.container.ContainerEventAdapter; +import org.eclipse.net4j.util.container.IContainer; import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.ui.UIUtil; -import org.eclipse.net4j.util.ui.views.ContainerItemProvider; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.emf.spi.cdo.DefaultCDOMerger; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; +import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ITreeSelection; @@ -29,7 +44,10 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.wb.swt.ExampleResourceManager; + +import java.lang.reflect.InvocationTargetException; /** * @author Eike Stepper @@ -42,6 +60,10 @@ public class ClientView extends AbstractView<CDOSession> private TreeViewer treeViewer; + private CommitAction commitAction = new CommitAction(); + + private MergeAction mergeAction = new MergeAction(); + public ClientView() { super(CDOSession.class); @@ -66,6 +88,42 @@ public class ClientView extends AbstractView<CDOSession> hookDoubleClick(); hookContextMenu(); + updateEnablement(); + + IRepository repository = Application.NODE.getObject(IRepository.class); + repository.addListener(new IListener() + { + public void notifyEvent(IEvent event) + { + updateEnablement(); + } + }); + + final IListener transactionListener = new IListener() + { + public void notifyEvent(IEvent event) + { + updateEnablement(); + } + }; + + CDOTransaction transaction = Application.NODE.getObject(CDOTransaction.class); + if (transaction != null) + { + transaction.addListener(transactionListener); + } + else + { + session.addListener(new ContainerEventAdapter<CDOView>() + { + @Override + protected void onAdded(IContainer<CDOView> container, CDOView view) + { + updateEnablement(); + view.addListener(transactionListener); + } + }); + } } protected void hookDoubleClick() @@ -76,16 +134,10 @@ public class ClientView extends AbstractView<CDOSession> { ITreeSelection selection = (ITreeSelection)treeViewer.getSelection(); Object object = selection.getFirstElement(); - if (object instanceof ContainerItemProvider.ErrorElement) + if (object instanceof CDOResourceLeaf) { - try - { - UIUtil.getActiveWorkbenchPage().showView(UIUtil.ERROR_LOG_ID); - } - catch (PartInitException ex) - { - ex.printStackTrace(); - } + CDOResourceLeaf resource = (CDOResourceLeaf)object; + CDOEditorUtil.openEditor(getSite().getPage(), resource); } else if (object != null && treeViewer.isExpandable(object)) { @@ -102,6 +154,22 @@ public class ClientView extends AbstractView<CDOSession> }); } + @Override + protected void initializeToolBar(IToolBarManager toolbarManager) + { + super.initializeToolBar(toolbarManager); + toolbarManager.add(commitAction); + toolbarManager.add(mergeAction); + } + + protected void updateEnablement() + { + CDOTransaction transaction = Application.NODE.getObject(CDOTransaction.class); + commitAction.setEnabled(transaction != null && transaction.isDirty()); + mergeAction.setEnabled(transaction != null && transaction.getBranch().isLocal() + && Application.NODE.getObject(IRepository.class).getState() == State.ONLINE); + } + protected void hookContextMenu() { MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ @@ -138,4 +206,67 @@ public class ClientView extends AbstractView<CDOSession> itemProvider.dispose(); super.dispose(); } + + /** + * @author Eike Stepper + */ + public static class CommitAction extends Action + { + public CommitAction() + { + super("Commit", ExampleResourceManager.getPluginImageDescriptor(Application.PLUGIN_ID, "icons/Commit.gif")); + } + + @Override + public void run() + { + try + { + PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() + { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException + { + CDOTransaction transaction = Application.NODE.getObject(CDOTransaction.class); + + try + { + transaction.commit(monitor); + } + catch (CommitException ex) + { + ex.printStackTrace(); + transaction.rollback(); + } + } + }); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + + /** + * @author Eike Stepper + */ + public static class MergeAction extends Action + { + public MergeAction() + { + super("Merge", ExampleResourceManager.getPluginImageDescriptor(Application.PLUGIN_ID, "icons/Merge.gif")); + } + + @Override + public void run() + { + CDOTransaction transaction = Application.NODE.getObject(CDOTransaction.class); + + CDOBranch offlineBranch = transaction.getBranch(); + CDOBranch baseBranch = offlineBranch.getBase().getBranch(); + + transaction.setBranch(baseBranch); + transaction.merge(offlineBranch.getHead(), new DefaultCDOMerger.PerFeature.ManyValued()); + } + } } diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/NormalRepositoryView.java b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/NormalRepositoryView.java index 70daafc1fc..b56e9b3bc1 100644 --- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/NormalRepositoryView.java +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/NormalRepositoryView.java @@ -10,19 +10,25 @@ */ package org.eclipse.emf.cdo.examples.client.offline; +import org.eclipse.emf.cdo.server.CDOServerBrowser; import org.eclipse.emf.cdo.server.IRepository; import org.eclipse.net4j.util.event.IEvent; import org.eclipse.net4j.util.ui.views.ContainerItemProvider; import org.eclipse.net4j.util.ui.views.ItemProvider; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; import org.eclipse.wb.swt.ExampleResourceManager; +import java.net.URL; + /** * @author Eike Stepper */ @@ -66,12 +72,41 @@ public class NormalRepositoryView extends AbstractView<IRepository> treeViewer.setContentProvider(itemProvider); treeViewer.setInput(repository); - new RepositoryDetails(sash, repository); + new RepositoryDetails(sash, repository, treeViewer.getControl()); sash.setWeights(new int[] { 1, 1 }); } @Override + protected void initializeToolBar(IToolBarManager toolbarManager) + { + super.initializeToolBar(toolbarManager); + toolbarManager.add(new Action("Browser", ExampleResourceManager.getPluginImageDescriptor(Application.PLUGIN_ID, + "icons/Browser.gif")) + { + @Override + public void run() + { + CDOServerBrowser browser = Application.NODE.getObject(CDOServerBrowser.class); + if (browser != null) + { + int port = browser.getPort(); + + try + { + PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser() + .openURL(new URL("http://localhost:" + port)); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + }); + } + + @Override public void setFocus() { treeViewer.getTree().setFocus(); diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/RepositoryDetails.java b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/RepositoryDetails.java index c64a51e248..2a5dc7ab06 100644 --- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/RepositoryDetails.java +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/RepositoryDetails.java @@ -10,15 +10,20 @@ */ package org.eclipse.emf.cdo.examples.client.offline; +import org.eclipse.emf.cdo.examples.client.offline.nodes.NodeType; import org.eclipse.emf.cdo.server.IRepository; import org.eclipse.net4j.util.event.IEvent; import org.eclipse.net4j.util.event.IListener; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; @@ -33,13 +38,13 @@ public class RepositoryDetails extends Composite private Text name; - private Text uuid; - private Text type; private Text state; - public RepositoryDetails(Composite parent, IRepository repository) + private Button connected; + + public RepositoryDetails(Composite parent, IRepository repository, final Control enablementControl) { super(parent, SWT.NONE); this.repository = repository; @@ -64,15 +69,6 @@ public class RepositoryDetails extends Composite name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); name.setText(repository.getName()); - Label lblUuid = new Label(this, SWT.NONE); - lblUuid.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblUuid.setText("UUID:"); - - uuid = new Text(this, SWT.BORDER); - uuid.setEditable(false); - uuid.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - uuid.setText(repository.getUUID()); - Label lblType = new Label(this, SWT.NONE); lblType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblType.setText("Type:"); @@ -89,6 +85,29 @@ public class RepositoryDetails extends Composite state.setEditable(false); state.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + NodeType nodeType = Application.NODE.getType(); + if (nodeType instanceof NodeType.Server && !(nodeType instanceof NodeType.FailoverMonitor)) + { + final NodeType.Server server = (NodeType.Server)nodeType; + + new Label(this, SWT.NONE); + + connected = new Button(this, SWT.CHECK); + connected.setText("Connected to Network"); + connected.setSelection(true); + connected.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent e) + { + boolean on = connected.getSelection(); + enablementControl.setEnabled(on); + + server.setConnectedToNetwork(Application.NODE, on); + } + }); + } + updateUI(); repository.addListener(new IListener() { diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java index 1820dc0df6..b23b9433b3 100644 --- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java +++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java @@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; import org.eclipse.emf.cdo.examples.client.offline.Application; import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration; import org.eclipse.emf.cdo.net4j.CDONet4jUtil; +import org.eclipse.emf.cdo.server.CDOServerBrowser; import org.eclipse.emf.cdo.server.CDOServerUtil; import org.eclipse.emf.cdo.server.IRepository; import org.eclipse.emf.cdo.server.IRepositorySynchronizer; @@ -95,7 +96,9 @@ public abstract class NodeType extends SetContainer<Node> implements IElement public static final String MONITOR_PROPERTY = "Monitor"; - public static final String BRANCH_PROPERTY = "branch"; + public static final String BRANCH_PROPERTY = "Branch"; + + public static final String BROWSER_PROPERTY = "BrowserPort"; private static final String REPOSITORY_NAME = "repository"; @@ -220,10 +223,21 @@ public abstract class NodeType extends SetContainer<Node> implements IElement IAcceptor acceptor = createAcceptor(node); node.setObject(IAcceptor.class, acceptor); + + String browserPort = node.getSetting(BROWSER_PROPERTY); + if (browserPort != null && browserPort.length() != 0) + { + CDOServerBrowser browser = (CDOServerBrowser)IPluginContainer.INSTANCE.getElement( + "org.eclipse.emf.cdo.server.browsers", "default", browserPort); + node.setObject(CDOServerBrowser.class, browser); + } } public void stop(Node node) { + CDOServerBrowser browser = node.getObject(CDOServerBrowser.class); + LifecycleUtil.deactivate(browser); + IAcceptor acceptor = node.getObject(IAcceptor.class); LifecycleUtil.deactivate(acceptor); @@ -515,6 +529,7 @@ public abstract class NodeType extends SetContainer<Node> implements IElement { super(manager); addProperty(new Property.Selection(this, SERVER_PROPERTY, Server.class)); + addProperty(new Property.Entry(this, BROWSER_PROPERTY)); } @Override @@ -610,8 +625,14 @@ public abstract class NodeType extends SetContainer<Node> implements IElement { CDOSession session = node.getObject(CDOSession.class); - int branchID = Integer.parseInt(node.getSettings().getProperty(BRANCH_PROPERTY, "0")); - CDOBranch branch = session.getBranchManager().getBranch(branchID); + String branchPath = node.getSettings().getProperty(BRANCH_PROPERTY, CDOBranch.MAIN_BRANCH_NAME); + CDOBranch branch = session.getBranchManager().getBranch(branchPath); + if (branch == null) + { + branch = session.getBranchManager().getMainBranch(); + node.getSettings().setProperty(BRANCH_PROPERTY, branch.getPathName()); + getManager().saveNode(node); + } CDOTransaction transaction = session.openTransaction(branch); transaction.addListener(new IListener() @@ -621,8 +642,8 @@ public abstract class NodeType extends SetContainer<Node> implements IElement if (event instanceof CDOViewTargetChangedEvent) { CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event; - int branchID = e.getBranchPoint().getBranch().getID(); - node.getSettings().setProperty(BRANCH_PROPERTY, Integer.toString(branchID)); + String branchPath = e.getBranchPoint().getBranch().getPathName(); + node.getSettings().setProperty(BRANCH_PROPERTY, branchPath); getManager().saveNode(node); } } @@ -655,6 +676,20 @@ public abstract class NodeType extends SetContainer<Node> implements IElement super.configureWindow(configurer); configurer.setInitialSize(new Point(600, 500)); } + + public void setConnectedToNetwork(Node node, boolean on) + { + if (on) + { + IAcceptor acceptor = createAcceptor(node); + node.setObject(IAcceptor.class, acceptor); + } + else + { + IAcceptor acceptor = node.getObject(IAcceptor.class); + LifecycleUtil.deactivate(acceptor); + } + } } /** @@ -682,6 +717,7 @@ public abstract class NodeType extends SetContainer<Node> implements IElement public NormalRepository(NodeManager manager) { super(manager); + addProperty(new Property.Entry(this, BROWSER_PROPERTY)); } @Override @@ -700,6 +736,7 @@ public abstract class NodeType extends SetContainer<Node> implements IElement { super(manager); addProperty(new Property.Selection(this, MONITOR_PROPERTY, FailoverMonitor.class)); + addProperty(new Property.Entry(this, BROWSER_PROPERTY)); } @Override |